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 pub.barback.transformer_id; | 5 library pub.barback.transformer_id; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 | 8 |
9 import 'package:barback/barback.dart'; | 9 import 'package:barback/barback.dart'; |
10 import 'package:source_span/source_span.dart'; | 10 import 'package:source_span/source_span.dart'; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 return new TransformerId(parts.single, null, span); | 55 return new TransformerId(parts.single, null, span); |
56 } | 56 } |
57 | 57 |
58 return new TransformerId(parts.first, parts.last, span); | 58 return new TransformerId(parts.first, parts.last, span); |
59 } | 59 } |
60 | 60 |
61 TransformerId(this.package, this.path, this.span) { | 61 TransformerId(this.package, this.path, this.span) { |
62 if (!package.startsWith('\$')) return; | 62 if (!package.startsWith('\$')) return; |
63 if (_BUILT_IN_TRANSFORMERS.contains(package)) return; | 63 if (_BUILT_IN_TRANSFORMERS.contains(package)) return; |
64 throw new SourceSpanFormatException( | 64 throw new SourceSpanFormatException( |
65 'Unsupported built-in transformer $package.', span); | 65 'Unsupported built-in transformer $package.', |
| 66 span); |
66 } | 67 } |
67 | 68 |
68 bool operator==(other) => | 69 bool operator ==(other) => |
69 other is TransformerId && other.package == package && other.path == path; | 70 other is TransformerId && other.package == package && other.path == path; |
70 | 71 |
71 int get hashCode => package.hashCode ^ path.hashCode; | 72 int get hashCode => package.hashCode ^ path.hashCode; |
72 | 73 |
73 /// Returns a serialized form of [this] that can be passed to | 74 /// Returns a serialized form of [this] that can be passed to |
74 /// [new TransformerId.parse]. | 75 /// [new TransformerId.parse]. |
75 String serialize() => path == null ? package : '$package/$path'; | 76 String serialize() => path == null ? package : '$package/$path'; |
76 | 77 |
77 String toString() => serialize(); | 78 String toString() => serialize(); |
78 | 79 |
79 /// Returns the asset id for the library identified by this transformer id. | 80 /// Returns the asset id for the library identified by this transformer id. |
80 /// | 81 /// |
81 /// If `path` is null, this will determine which library to load. Unlike | 82 /// If `path` is null, this will determine which library to load. Unlike |
82 /// [getAssetId], this doesn't take generated assets into account; it's used | 83 /// [getAssetId], this doesn't take generated assets into account; it's used |
83 /// to determine transformers' dependencies, which requires looking at files | 84 /// to determine transformers' dependencies, which requires looking at files |
84 /// on disk. | 85 /// on disk. |
85 Future<AssetId> getAssetId(Barback barback) { | 86 Future<AssetId> getAssetId(Barback barback) { |
86 if (path != null) { | 87 if (path != null) { |
87 return new Future.value(new AssetId(package, 'lib/$path.dart')); | 88 return new Future.value(new AssetId(package, 'lib/$path.dart')); |
88 } | 89 } |
89 | 90 |
90 var transformerAsset = new AssetId(package, 'lib/transformer.dart'); | 91 var transformerAsset = new AssetId(package, 'lib/transformer.dart'); |
91 return barback.getAssetById(transformerAsset).then((_) => transformerAsset) | 92 return barback.getAssetById( |
92 .catchError((e) => new AssetId(package, 'lib/$package.dart'), | 93 transformerAsset).then( |
93 test: (e) => e is AssetNotFoundException); | 94 (_) => |
| 95 transformerAsset).catchError( |
| 96 (e) => new AssetId(package, 'lib/$package.dart'), |
| 97 test: (e) => e is AssetNotFoundException); |
94 } | 98 } |
95 } | 99 } |
OLD | NEW |