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 import 'dart:async'; | 5 import 'dart:async'; |
6 | 6 |
7 import 'package:barback/barback.dart'; | 7 import 'package:barback/barback.dart'; |
8 import 'package:source_span/source_span.dart'; | 8 import 'package:source_span/source_span.dart'; |
9 | 9 |
10 import '../utils.dart'; | 10 import '../utils.dart'; |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 String serialize() => path == null ? package : '$package/$path'; | 73 String serialize() => path == null ? package : '$package/$path'; |
74 | 74 |
75 String toString() => serialize(); | 75 String toString() => serialize(); |
76 | 76 |
77 /// Returns the asset id for the library identified by this transformer id. | 77 /// Returns the asset id for the library identified by this transformer id. |
78 /// | 78 /// |
79 /// If `path` is null, this will determine which library to load. Unlike | 79 /// If `path` is null, this will determine which library to load. Unlike |
80 /// [getAssetId], this doesn't take generated assets into account; it's used | 80 /// [getAssetId], this doesn't take generated assets into account; it's used |
81 /// to determine transformers' dependencies, which requires looking at files | 81 /// to determine transformers' dependencies, which requires looking at files |
82 /// on disk. | 82 /// on disk. |
83 Future<AssetId> getAssetId(Barback barback) { | 83 Future<AssetId> getAssetId(Barback barback) async { |
84 if (path != null) { | 84 if (path != null) { |
85 return new Future.value(new AssetId(package, 'lib/$path.dart')); | 85 return new AssetId(package, 'lib/$path.dart'); |
86 } | 86 } |
87 | 87 |
88 var transformerAsset = new AssetId(package, 'lib/transformer.dart'); | 88 var transformerAsset = new AssetId(package, 'lib/transformer.dart'); |
89 return barback.getAssetById(transformerAsset).then((_) => transformerAsset) | 89 try { |
90 .catchError((e) => new AssetId(package, 'lib/$package.dart'), | 90 await barback.getAssetById(transformerAsset); |
91 test: (e) => e is AssetNotFoundException); | 91 return transformerAsset; |
| 92 } on AssetNotFoundException catch (_) { |
| 93 return new AssetId(package, 'lib/$package.dart'); |
| 94 } |
92 } | 95 } |
93 } | 96 } |
OLD | NEW |