Chromium Code Reviews| Index: pkg/code_transformers/lib/src/resolvers.dart |
| diff --git a/pkg/code_transformers/lib/src/resolvers.dart b/pkg/code_transformers/lib/src/resolvers.dart |
| index 077ea5b25ba3dbeda554332b37672773c1c8f3d5..95ea4318cc6f42474d9f025a37f45dcc5341ab10 100644 |
| --- a/pkg/code_transformers/lib/src/resolvers.dart |
| +++ b/pkg/code_transformers/lib/src/resolvers.dart |
| @@ -5,8 +5,9 @@ |
| library code_transformers.src.resolvers; |
| import 'dart:async'; |
| -import 'package:barback/barback.dart' show AssetId, Transformer, Transform; |
| +import 'package:barback/barback.dart'; |
| +import 'entry_point.dart'; |
| import 'resolver.dart'; |
| import 'resolver_impl.dart'; |
| @@ -47,6 +48,24 @@ abstract class ResolverTransformer implements Transformer { |
| /// The cache of resolvers- must be set from subclass. |
| Resolvers resolvers; |
| + /// By default only process prossible entry point assets. |
| + /// |
| + /// This is only a preliminary check based on the asset ID. |
| + Future<bool> isPrimary(asset_or_id) { |
|
Siggi Cherem (dart-lang)
2014/04/11 17:01:02
nit, I think we would write it as assetOrId
|
| + // asset_or_id is to handle the transition from Asset to AssetID between |
| + // pub 1.3 and 1.4. Once support for 1.3 is dropped this should only |
| + // support AssetId. |
| + var id = asset_or_id is AssetId ? asset_or_id : asset_or_id.id; |
| + return new Future.value(isPossibleDartEntryId(id)); |
| + } |
| + |
| + /// Check to see if this should apply with the resolver on the provided asset. |
| + /// |
| + /// By default this will only apply on possible Dart entry points (see |
| + /// [isPossibleDartEntry]). |
| + Future<bool> shouldApplyResolver(Asset asset) => isPossibleDartEntry(asset); |
| + |
| + |
| /// This provides a default implementation of `Transformer.apply` that will |
| /// get and release resolvers automatically. Internally this: |
| /// * Gets a resolver associated with the transform primary input. |
| @@ -56,7 +75,11 @@ abstract class ResolverTransformer implements Transformer { |
| /// |
| /// Use [applyToEntryPoints] instead if you need to override the entry points |
| /// to run the resolver on. |
| - Future apply(Transform transform) => applyToEntryPoints(transform); |
| + Future apply(Transform transform) => |
| + shouldApplyResolver(transform.primaryInput).then((result) { |
| + if (result) return applyToEntryPoints(transform); |
| + }); |
| + |
| /// Helper function to make it easy to write an `Transformer.apply` method |
| /// that automatically gets and releases the resolver. This is typically used |