Chromium Code Reviews| 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 barback.transform; | 5 library barback.transform; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'package:source_maps/span.dart' show Span; | |
|
nweiz
2013/08/08 23:34:57
Style nit: blank line between core library imports
Siggi Cherem (dart-lang)
2013/08/09 00:29:54
Done.
Funny, I usually like using show if the lis
Jennifer Messerly
2013/08/09 05:44:03
Moreover, it's the only style (along with "as") wh
Bob Nystrom
2013/08/09 15:42:38
Since this is a "package:" import, that doesn't wo
| |
| 8 | 9 |
| 9 import 'asset.dart'; | 10 import 'asset.dart'; |
| 10 import 'asset_id.dart'; | 11 import 'asset_id.dart'; |
| 11 import 'asset_node.dart'; | 12 import 'asset_node.dart'; |
| 12 import 'asset_set.dart'; | 13 import 'asset_set.dart'; |
| 13 import 'errors.dart'; | 14 import 'errors.dart'; |
| 14 import 'transform_node.dart'; | 15 import 'transform_node.dart'; |
| 15 import 'utils.dart'; | 16 import 'utils.dart'; |
| 16 | 17 |
| 17 /// Creates a [Transform] by forwarding to the private constructor. | 18 /// Creates a [Transform] by forwarding to the private constructor. |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 38 /// | 39 /// |
| 39 /// While a transformation can use multiple input assets, one must be a | 40 /// While a transformation can use multiple input assets, one must be a |
| 40 /// special "primary" asset. This will be the "entrypoint" or "main" input | 41 /// special "primary" asset. This will be the "entrypoint" or "main" input |
| 41 /// file for a transformation. | 42 /// file for a transformation. |
| 42 /// | 43 /// |
| 43 /// For example, with a dart2js transform, the primary input would be the | 44 /// For example, with a dart2js transform, the primary input would be the |
| 44 /// entrypoint Dart file. All of the other Dart files that that imports | 45 /// entrypoint Dart file. All of the other Dart files that that imports |
| 45 /// would be secondary inputs. | 46 /// would be secondary inputs. |
| 46 AssetId get primaryId => _node.primary.id; | 47 AssetId get primaryId => _node.primary.id; |
| 47 | 48 |
| 49 Log get log => _log; | |
|
Bob Nystrom
2013/08/08 22:47:09
Document:
"A logger so that the [Transformer] can
Siggi Cherem (dart-lang)
2013/08/08 23:10:41
Done.
| |
| 50 | |
| 48 /// Gets the asset for the primary input. | 51 /// Gets the asset for the primary input. |
| 49 Future<Asset> get primaryInput => getInput(primaryId); | 52 Future<Asset> get primaryInput => getInput(primaryId); |
| 50 | 53 |
| 51 Transform._(this._node, this._outputs); | 54 Transform._(this._node, this._outputs); |
| 52 | 55 |
| 53 /// Gets the asset for for an input [id]. | 56 /// Gets the asset for for an input [id]. |
| 54 /// | 57 /// |
| 55 /// If an input with that ID cannot be found, throws an | 58 /// If an input with that ID cannot be found, throws an |
| 56 /// [AssetNotFoundException]. | 59 /// [AssetNotFoundException]. |
| 57 Future<Asset> getInput(AssetId id) => _node.getInput(id); | 60 Future<Asset> getInput(AssetId id) => _node.getInput(id); |
| 58 | 61 |
| 59 /// Stores [output] as the output created by this transformation. | 62 /// Stores [output] as the output created by this transformation. |
| 60 /// | 63 /// |
| 61 /// A transformation can output as many assets as it wants. | 64 /// A transformation can output as many assets as it wants. |
| 62 void addOutput(Asset output) { | 65 void addOutput(Asset output) { |
| 63 // TODO(rnystrom): This should immediately throw if an output with that ID | 66 // TODO(rnystrom): This should immediately throw if an output with that ID |
| 64 // has already been created by this transformer. | 67 // has already been created by this transformer. |
| 65 _outputs.add(output); | 68 _outputs.add(output); |
| 66 } | 69 } |
| 67 } | 70 } |
| 71 | |
| 72 final Log _log = new Log(true); | |
|
Bob Nystrom
2013/08/08 22:47:09
Add a TODO to create a separate one for each Trans
Siggi Cherem (dart-lang)
2013/08/08 23:10:41
Done.
| |
| 73 | |
| 74 /// Log object used to report warnings and errors encountered while running a | |
|
Bob Nystrom
2013/08/08 22:47:09
Add a TODO to move this into its own file.
Siggi Cherem (dart-lang)
2013/08/08 23:10:41
Done. I'm happy to move it out too (if we know wha
nweiz
2013/08/08 23:34:57
Or just move it now.
Siggi Cherem (dart-lang)
2013/08/09 00:29:54
now that it's just TransformLogger, it feels like
nweiz
2013/08/09 00:53:48
I'd still prefer it to be separate.
Siggi Cherem (dart-lang)
2013/08/09 01:17:30
Done.
| |
| 75 /// transform. | |
| 76 class Log { | |
| 77 | |
| 78 bool _shouldPrint; | |
| 79 | |
| 80 Log(this._shouldPrint); | |
| 81 | |
| 82 /// Logs a warning message. If present, [span] indicates the location in an | |
|
Bob Nystrom
2013/08/08 22:47:09
"an asset that generated" -> "the input asset that
Siggi Cherem (dart-lang)
2013/08/08 23:10:41
Done.
nweiz
2013/08/08 23:34:57
Style nit: the first paragraph of a doc comment sh
Siggi Cherem (dart-lang)
2013/08/09 00:29:54
Done.
| |
| 83 /// asset that generated the warning. | |
| 84 void warning(String message, [Span span]) { | |
| 85 _printMessage('warning', message, span); | |
| 86 } | |
| 87 | |
| 88 /// Logs an error message. If present, [span] indicates the location in an | |
| 89 /// asset that generated the error. | |
|
Bob Nystrom
2013/08/08 22:47:09
Ditto above change here.
Siggi Cherem (dart-lang)
2013/08/08 23:10:41
Done.
| |
| 90 void error(String message, [Span span]) { | |
|
nweiz
2013/08/08 23:34:57
Add a TODO to clarify when an error message should
Siggi Cherem (dart-lang)
2013/08/09 00:29:54
Done.
| |
| 91 _printMessage('error', message, span); | |
| 92 } | |
| 93 | |
| 94 // TODO(sigmund,rnystrom): do something better than printing. | |
| 95 _printMessage(String prefix, String message, Span span) { | |
| 96 if (!_shouldPrint) return; | |
| 97 var sb = new StringBuffer()..write(prefix)..write(' '); | |
|
Bob Nystrom
2013/08/08 22:47:09
sb -> buffer
Siggi Cherem (dart-lang)
2013/08/08 23:10:41
Done. We all have different preferences on this on
| |
| 98 if (span == null) { | |
| 99 sb.write(message); | |
| 100 } else { | |
| 101 sb.write(span.getLocationMessage(message)); | |
| 102 } | |
| 103 print(sb.toString()); | |
|
nweiz
2013/08/08 23:34:57
Is it worth the extra complexity here to use a Str
Siggi Cherem (dart-lang)
2013/08/09 00:29:54
good point. I used to have color printing and remv
| |
| 104 } | |
| 105 } | |
| OLD | NEW |