| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library pub.dart2js_transformer; | 5 library pub.dart2js_transformer; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:convert'; | 8 import 'dart:convert'; |
| 9 | 9 |
| 10 import 'package:analyzer/analyzer.dart'; | 10 import 'package:analyzer/analyzer.dart'; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 | 52 |
| 53 throw new FormatException("Unrecognized dart2js " | 53 throw new FormatException("Unrecognized dart2js " |
| 54 "${pluralize('option', invalidOptions.length)} " | 54 "${pluralize('option', invalidOptions.length)} " |
| 55 "${toSentence(invalidOptions.map((option) => '"$option"'))}."); | 55 "${toSentence(invalidOptions.map((option) => '"$option"'))}."); |
| 56 } | 56 } |
| 57 | 57 |
| 58 Dart2JSTransformer(AssetEnvironment environment, BarbackMode mode) | 58 Dart2JSTransformer(AssetEnvironment environment, BarbackMode mode) |
| 59 : this.withSettings(environment, new BarbackSettings({}, mode)); | 59 : this.withSettings(environment, new BarbackSettings({}, mode)); |
| 60 | 60 |
| 61 /// Only ".dart" entrypoint files within a buildable directory are processed. | 61 /// Only ".dart" entrypoint files within a buildable directory are processed. |
| 62 Future<bool> isPrimary(AssetId id) { | 62 bool isPrimary(AssetId id) { |
| 63 if (id.extension != ".dart") return new Future.value(false); | 63 if (id.extension != ".dart") return false; |
| 64 | 64 |
| 65 // These should only contain libraries. For efficiency's sake, we don't | 65 // These should only contain libraries. For efficiency's sake, we don't |
| 66 // look for entrypoints in there. | 66 // look for entrypoints in there. |
| 67 return new Future.value(!["asset/", "lib/"].any(id.path.startsWith)); | 67 return !["asset/", "lib/"].any(id.path.startsWith); |
| 68 } | 68 } |
| 69 | 69 |
| 70 Future apply(Transform transform) { | 70 Future apply(Transform transform) { |
| 71 // TODO(nweiz): If/when barback starts reporting what assets were modified, | 71 // TODO(nweiz): If/when barback starts reporting what assets were modified, |
| 72 // don't re-run the entrypoint detection logic unless the primary input was | 72 // don't re-run the entrypoint detection logic unless the primary input was |
| 73 // actually modified. See issue 16817. | 73 // actually modified. See issue 16817. |
| 74 return _isEntrypoint(transform.primaryInput).then((isEntrypoint) { | 74 return _isEntrypoint(transform.primaryInput).then((isEntrypoint) { |
| 75 if (!isEntrypoint) return null; | 75 if (!isEntrypoint) return null; |
| 76 | 76 |
| 77 // Wait for any ongoing apply to finish first. | 77 // Wait for any ongoing apply to finish first. |
| 78 return _pool.withResource(() { | 78 return _pool.withResource(() { |
| 79 transform.logger.info("Compiling ${transform.primaryInput.id}..."); | 79 transform.logger.info("Compiling ${transform.primaryInput.id}..."); |
| 80 var stopwatch = new Stopwatch()..start(); | 80 var stopwatch = new Stopwatch()..start(); |
| 81 return _doCompilation(transform).then((_) { | 81 return _doCompilation(transform).then((_) { |
| 82 stopwatch.stop(); | 82 stopwatch.stop(); |
| 83 transform.logger.info("Took ${stopwatch.elapsed} to compile " | 83 transform.logger.info("Took ${stopwatch.elapsed} to compile " |
| 84 "${transform.primaryInput.id}."); | 84 "${transform.primaryInput.id}."); |
| 85 }); | 85 }); |
| 86 }); | 86 }); |
| 87 }); | 87 }); |
| 88 } | 88 } |
| 89 | 89 |
| 90 Future declareOutputs(DeclaringTransform transform) { | 90 void declareOutputs(DeclaringTransform transform) { |
| 91 var primaryId = transform.primaryId; | 91 var primaryId = transform.primaryId; |
| 92 transform.declareOutput(primaryId.addExtension(".js")); | 92 transform.declareOutput(primaryId.addExtension(".js")); |
| 93 transform.declareOutput(primaryId.addExtension(".precompiled.js")); | 93 transform.declareOutput(primaryId.addExtension(".precompiled.js")); |
| 94 if (_generateSourceMaps) { | 94 if (_generateSourceMaps) { |
| 95 transform.declareOutput(primaryId.addExtension(".js.map")); | 95 transform.declareOutput(primaryId.addExtension(".js.map")); |
| 96 } | 96 } |
| 97 return new Future.value(); | |
| 98 } | 97 } |
| 99 | 98 |
| 100 /// Returns whether or not [asset] might be an entrypoint. | 99 /// Returns whether or not [asset] might be an entrypoint. |
| 101 Future<bool> _isEntrypoint(Asset asset) { | 100 Future<bool> _isEntrypoint(Asset asset) { |
| 102 return asset.readAsString().then((code) { | 101 return asset.readAsString().then((code) { |
| 103 try { | 102 try { |
| 104 var name = asset.id.path; | 103 var name = asset.id.path; |
| 105 if (asset.id.package != _environment.rootPackage.name) { | 104 if (asset.id.package != _environment.rootPackage.name) { |
| 106 name += " in ${asset.id.package}"; | 105 name += " in ${asset.id.package}"; |
| 107 } | 106 } |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 } | 399 } |
| 401 } | 400 } |
| 402 | 401 |
| 403 /// An [EventSink] that discards all data. Provided to dart2js when we don't | 402 /// An [EventSink] that discards all data. Provided to dart2js when we don't |
| 404 /// want an actual output. | 403 /// want an actual output. |
| 405 class NullSink<T> implements EventSink<T> { | 404 class NullSink<T> implements EventSink<T> { |
| 406 void add(T event) {} | 405 void add(T event) {} |
| 407 void addError(errorEvent, [StackTrace stackTrace]) {} | 406 void addError(errorEvent, [StackTrace stackTrace]) {} |
| 408 void close() {} | 407 void close() {} |
| 409 } | 408 } |
| OLD | NEW |