feat(dart/transform): Do not re-process generated files

In the `DeferredRewriter` phase, do not process files which were
generated by the transformer, since these will never need to be
rewritten.
This commit is contained in:
Tim Blasi 2015-11-12 11:21:01 -08:00
parent 3f4628c0b0
commit 8f91ff84c7
2 changed files with 17 additions and 1 deletions

View File

@ -30,6 +30,20 @@ const ALL_EXTENSIONS = const [
'.dart'
];
/// Whether `uri` was created by a transform phase.
///
/// This may return false positives for problematic inputs.
/// This just tests file extensions known to be created by the transformer, so
/// any files named like transformer outputs will be reported as generated.
bool isGenerated(String uri) {
return const [
DEPS_EXTENSION,
NON_SHIMMED_STYLESHEET_EXTENSION,
SHIMMED_STYLESHEET_EXTENSION,
TEMPLATE_EXTENSION,
].any((ext) => uri.endsWith(ext));
}
/// Returns `uri` with its extension updated to [META_EXTENSION].
String toMetaExtension(String uri) =>
_toExtension(uri, ALL_EXTENSIONS, META_EXTENSION);

View File

@ -21,7 +21,7 @@ class DeferredRewriter extends Transformer {
@override
bool isPrimary(AssetId id) =>
id.extension.endsWith('dart') && !id.path.endsWith(DEPS_EXTENSION);
id.extension.endsWith('dart') && _isNotGenerated(id);
@override
Future apply(Transform transform) async {
@ -36,6 +36,8 @@ class DeferredRewriter extends Transformer {
}
}
bool _isNotGenerated(AssetId id) => !isGenerated(id.path);
// Visible for testing
Future<String> rewriteDeferredLibraries(AssetReader reader, AssetId id) async {
var rewriter = new Rewriter(id, reader);