diff --git a/modules_dart/transform/lib/src/transform/common/names.dart b/modules_dart/transform/lib/src/transform/common/names.dart index bf2675e570..c8b172e203 100644 --- a/modules_dart/transform/lib/src/transform/common/names.dart +++ b/modules_dart/transform/lib/src/transform/common/names.dart @@ -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); diff --git a/modules_dart/transform/lib/src/transform/deferred_rewriter/transformer.dart b/modules_dart/transform/lib/src/transform/deferred_rewriter/transformer.dart index 3d33179dd5..c5dc4fb725 100644 --- a/modules_dart/transform/lib/src/transform/deferred_rewriter/transformer.dart +++ b/modules_dart/transform/lib/src/transform/deferred_rewriter/transformer.dart @@ -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 rewriteDeferredLibraries(AssetReader reader, AssetId id) async { var rewriter = new Rewriter(id, reader);