Chromium Code Reviews| Index: sdk/lib/_internal/pub/lib/src/barback.dart |
| diff --git a/sdk/lib/_internal/pub/lib/src/barback.dart b/sdk/lib/_internal/pub/lib/src/barback.dart |
| index 053a48e75947ff3820ec7f27aa49f110baddebba..91ed1e33eb025e6d0b0a79a04af6dc45efd55ed8 100644 |
| --- a/sdk/lib/_internal/pub/lib/src/barback.dart |
| +++ b/sdk/lib/_internal/pub/lib/src/barback.dart |
| @@ -57,9 +57,32 @@ class TransformerId { |
| /// The configuration to pass to the transformer. |
| /// |
| - /// This will be an empty map if no configuration was provided. |
| + /// Any pub-specific configuration (i.e. keys starting with "$") will have |
| + /// been stripped out of this and handled separately. This will be an empty |
| + /// map if no configuration was provided. |
| final Map configuration; |
| + /// The primary input inclusions. |
| + /// |
| + /// Each inclusion is an asset path. If this set is non-empty, than *only* |
|
nweiz
2014/02/24 21:42:46
"than" -> "then"
It seems weird to me that this s
Bob Nystrom
2014/02/26 01:09:41
Done.
|
| + /// matching assets are allowed as a primary input by this transformer. If |
| + /// empty, all assets are included. |
| + /// |
| + /// This is processed before [excludes]. If a transformer has both includes |
| + /// and excluded, then the set of included assets is determined, and then |
|
nweiz
2014/02/24 21:42:46
"excluded" -> "excludes"
", and then" -> "and"
Bob Nystrom
2014/02/26 01:09:41
Done.
|
| + /// assets are excluded from that resulting set. |
| + final Set<String> includes; |
| + |
| + /// The primary input exclusions. |
| + /// |
| + /// Any asset whose patch is in this is not allowed as a primary input by |
|
nweiz
2014/02/24 21:42:46
"patch" -> "path"
Bob Nystrom
2014/02/26 01:09:41
Done.
|
| + /// this transformer. |
| + /// |
| + /// This is processed after [includes]. If a transformer has both includes |
| + /// and excluded, then the set of included assets is determined, and then |
|
nweiz
2014/02/24 21:42:46
Same changes as above
Bob Nystrom
2014/02/26 01:09:41
Done.
|
| + /// assets are excluded from that resulting set. |
| + final Set<String> excludes; |
|
nweiz
2014/02/24 21:42:46
I understand why we're not supporting globs yet, b
Bob Nystrom
2014/02/26 01:09:41
I think we should too, but I like smaller, increme
|
| + |
| /// Whether this ID points to a built-in transformer exposed by pub. |
| bool get isBuiltInTransformer => package.startsWith('\$'); |
| @@ -79,11 +102,66 @@ class TransformerId { |
| if (parts.length == 1) { |
| return new TransformerId(parts.single, null, configuration); |
| } |
| + |
| return new TransformerId(parts.first, parts.last, configuration); |
| } |
| - TransformerId(this.package, this.path, Map configuration) |
| - : configuration = configuration == null ? {} : configuration { |
| + factory TransformerId(String package, String path, Map configuration) { |
| + var includes = new Set<String>(); |
| + var excludes = new Set<String>(); |
| + |
| + parseField(key, set) { |
|
nweiz
2014/02/24 21:42:46
I hate functions that add elements to collection a
Bob Nystrom
2014/02/26 01:09:41
Done.
|
| + if (!configuration.containsKey(key)) return; |
| + var field = configuration.remove(key); |
| + |
| + if (field is String) { |
| + set.add(field); |
| + } else if (field is List) { |
| + var nonstrings = field |
| + .where((element) => element is! String) |
| + .map((element) => '"$element"'); |
| + |
| + if (nonstrings.isNotEmpty) { |
| + throw new FormatException( |
| + '"$key" list field may only contain strings, but contained ' |
| + '${toSentence(nonstrings)}.'); |
| + } |
| + |
| + set.addAll(field); |
| + } else { |
| + throw new FormatException( |
| + '"$key" field must be a string or list, but was "$field".'); |
| + } |
| + } |
| + |
| + if (configuration == null) { |
| + configuration = {}; |
| + } else { |
| + // Copy so we don't modify the original map passed in. |
| + configuration = new Map.from(configuration); |
| + |
| + // Pull out the exclusions/inclusions. |
| + parseField("\$include", includes); |
| + parseField("\$exclude", excludes); |
| + |
| + // All other keys starting with "$" are unexpected. |
| + var reservedKeys = configuration.keys |
| + .where((key) => key is String && key.startsWith(r'$')) |
| + .map((key) => '"$key"'); |
| + |
| + if (reservedKeys.isNotEmpty) { |
| + throw new FormatException( |
| + 'Unknown reserved ${pluralize('field', reservedKeys.length)} ' |
| + '${toSentence(reservedKeys)}.'); |
| + } |
| + } |
| + |
| + return new TransformerId._(package, path, configuration, |
| + includes, excludes); |
| + } |
| + |
| + TransformerId._(this.package, this.path, this.configuration, |
| + this.includes, this.excludes) { |
| if (!package.startsWith('\$')) return; |
| if (_BUILT_IN_TRANSFORMERS.contains(package)) return; |
| throw new FormatException('Unsupported built-in transformer $package.'); |