OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 /// Transformer that replaces the default mirror-based implementation of smoke, | 5 /// Transformer that replaces the default mirror-based implementation of smoke, |
6 /// so that during deploy smoke doesn't include any dependency on dart:mirrors. | 6 /// so that during deploy smoke doesn't include any dependency on dart:mirrors. |
7 library smoke.src.default_transformer; | 7 library smoke.src.default_transformer; |
8 | 8 |
9 import 'dart:async'; | 9 import 'dart:async'; |
10 import 'package:barback/barback.dart'; | 10 import 'package:barback/barback.dart'; |
11 | 11 |
12 /// Replaces the default mirror-based implementation of smoke in | 12 /// Replaces the default mirror-based implementation of smoke in |
13 /// `pacakge:smoke/implementation.dart`, so that during deploy smoke doesn't | 13 /// `pacakge:smoke/implementation.dart`, so that during deploy smoke doesn't |
14 /// include any dependency on dart:mirrors. | 14 /// include any dependency on dart:mirrors. |
15 // TODO(sigmund): include tests that run this transformation automatically. | 15 // TODO(sigmund): include tests that run this transformation automatically. |
16 class DefaultTransformer extends Transformer { | 16 class DefaultTransformer extends Transformer { |
17 DefaultTransformer.asPlugin(); | 17 DefaultTransformer.asPlugin(); |
18 | 18 |
19 /// Only apply to `lib/src/implementation.dart`. | 19 /// Only apply to `lib/src/implementation.dart`. |
20 Future<bool> isPrimary(Asset input) => new Future.value( | 20 Future<bool> isPrimary(AssetId id) => new Future.value( |
21 input.id.package == 'smoke' && | 21 id.package == 'smoke' && id.path == 'lib/src/implementation.dart'); |
22 input.id.path == 'lib/src/implementation.dart'); | |
23 | 22 |
24 Future apply(Transform transform) { | 23 Future apply(Transform transform) { |
25 var id = transform.primaryInput.id; | 24 var id = transform.primaryInput.id; |
26 return transform.primaryInput.readAsString().then((code) { | 25 return transform.primaryInput.readAsString().then((code) { |
27 // Note: this rewrite is highly-coupled with how implementation.dart is | 26 // Note: this rewrite is highly-coupled with how implementation.dart is |
28 // written. Make sure both are updated in sync. | 27 // written. Make sure both are updated in sync. |
29 transform.addOutput(new Asset.fromString(id, code | 28 transform.addOutput(new Asset.fromString(id, code |
30 .replaceAll(new RegExp('new Reflective[^;]*;'), | 29 .replaceAll(new RegExp('new Reflective[^;]*;'), |
31 'throwNotConfiguredError();') | 30 'throwNotConfiguredError();') |
32 .replaceAll("import 'package:smoke/mirrors.dart';", ''))); | 31 .replaceAll("import 'package:smoke/mirrors.dart';", ''))); |
33 }); | 32 }); |
34 } | 33 } |
35 } | 34 } |
36 | 35 |
37 /** Transformer phases which should be applied to the smoke package. */ | 36 /** Transformer phases which should be applied to the smoke package. */ |
38 List<List<Transformer>> get phasesForSmoke => | 37 List<List<Transformer>> get phasesForSmoke => |
39 [[new DefaultTransformer.asPlugin()]]; | 38 [[new DefaultTransformer.asPlugin()]]; |
OLD | NEW |