| 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:io'; | 8 import 'dart:io'; |
| 9 | 9 |
| 10 import 'package:analyzer/analyzer.dart'; | 10 import 'package:analyzer/analyzer.dart'; |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 var packageRoot = path.join(_graph.entrypoint.root.dir, "packages"); | 72 var packageRoot = path.join(_graph.entrypoint.root.dir, "packages"); |
| 73 | 73 |
| 74 // TODO(rnystrom): Should have more sophisticated error-handling here. | 74 // TODO(rnystrom): Should have more sophisticated error-handling here. |
| 75 // Need to report compile errors to the user in an easily visible way. | 75 // Need to report compile errors to the user in an easily visible way. |
| 76 // Need to make sure paths in errors are mapped to the original source | 76 // Need to make sure paths in errors are mapped to the original source |
| 77 // path so they can understand them. | 77 // path so they can understand them. |
| 78 return dart.compile(entrypoint, | 78 return dart.compile(entrypoint, |
| 79 packageRoot: packageRoot, | 79 packageRoot: packageRoot, |
| 80 inputProvider: provider.readStringFromUri, | 80 inputProvider: provider.readStringFromUri, |
| 81 diagnosticHandler: provider.handleDiagnostic).then((js) { | 81 diagnosticHandler: provider.handleDiagnostic).then((js) { |
| 82 if (js == null) { | |
| 83 // The compile failed and errors should have already been reported | |
| 84 // through the diagnostic handler, so just do nothing here. | |
| 85 return; | |
| 86 } | |
| 87 | |
| 88 var id = transform.primaryInput.id.changeExtension(".dart.js"); | 82 var id = transform.primaryInput.id.changeExtension(".dart.js"); |
| 89 transform.addOutput(new Asset.fromString(id, js)); | 83 transform.addOutput(new Asset.fromString(id, js)); |
| 90 | 84 |
| 91 stopwatch.stop(); | 85 stopwatch.stop(); |
| 92 transform.logger.info("Generated $id (${js.length} characters) in " | 86 transform.logger.info("Generated $id (${js.length} characters) in " |
| 93 "${stopwatch.elapsed}"); | 87 "${stopwatch.elapsed}"); |
| 88 }).catchError((error) { |
| 89 // The compile failed and errors have been reported through the |
| 90 // diagnostic handler, so just do nothing here. |
| 91 if (error is CompilerException) return; |
| 92 throw error; |
| 94 }); | 93 }); |
| 95 }); | 94 }); |
| 96 } | 95 } |
| 97 } | 96 } |
| 98 | 97 |
| 99 /// Defines methods implementig [CompilerInputProvider] and [DiagnosticHandler] | 98 /// Defines methods implementig [CompilerInputProvider] and [DiagnosticHandler] |
| 100 /// for dart2js to use to load files from Barback and report errors. | 99 /// for dart2js to use to load files from Barback and report errors. |
| 101 /// | 100 /// |
| 102 /// Note that most of the implementation of diagnostic handling here was | 101 /// Note that most of the implementation of diagnostic handling here was |
| 103 /// copied from [FormattingDiagnosticHandler] in dart2js. The primary | 102 /// copied from [FormattingDiagnosticHandler] in dart2js. The primary |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 var rootDir = _graph.entrypoint.root.dir; | 237 var rootDir = _graph.entrypoint.root.dir; |
| 239 var sourcePath = path.fromUri(url); | 238 var sourcePath = path.fromUri(url); |
| 240 if (isBeneath(sourcePath, rootDir)) { | 239 if (isBeneath(sourcePath, rootDir)) { |
| 241 var relative = path.relative(sourcePath, from: rootDir); | 240 var relative = path.relative(sourcePath, from: rootDir); |
| 242 return new AssetId(_graph.entrypoint.root.name, relative); | 241 return new AssetId(_graph.entrypoint.root.name, relative); |
| 243 } | 242 } |
| 244 | 243 |
| 245 return null; | 244 return null; |
| 246 } | 245 } |
| 247 } | 246 } |
| OLD | NEW |