Chromium Code Reviews| Index: sdk/lib/_internal/pub/test/serve/utils.dart |
| diff --git a/sdk/lib/_internal/pub/test/serve/utils.dart b/sdk/lib/_internal/pub/test/serve/utils.dart |
| index 504663808baee9155235e0e6e43b7e30660646cb..137f742c3dff0a55f37497dd08108aded75beb33 100644 |
| --- a/sdk/lib/_internal/pub/test/serve/utils.dart |
| +++ b/sdk/lib/_internal/pub/test/serve/utils.dart |
| @@ -39,6 +39,50 @@ class RewriteTransformer extends Transformer { |
| } |
| """; |
| +/// Returns the text of a Dart file containing a transformer that rewrites other |
| +/// Dart files. |
| +/// |
| +/// The transformer defines a constant String named TOKEN whose value is [id]. |
| +/// It then adds [id] to the TOKEN constant of any Dart file that contains such |
| +/// a constant. This means it will modify other similar transformers. |
|
Bob Nystrom
2013/09/06 18:27:29
This is a brainteaser. How about:
Returns the sou
nweiz
2013/09/09 20:43:38
Done.
|
| +/// |
| +/// If [import] is passed, the primary library of that package will be imported |
| +/// and its TOKEN constant will be added to [id]. |
| +String dartTransformer(String id, {String import}) { |
| + if (import != null) { |
| + id = '$id (imports \${$import.TOKEN})'; |
| + import = 'import "package:$import/$import.dart" as $import;'; |
| + } else { |
| + import = ''; |
| + } |
| + |
| + return """ |
| +import 'dart:async'; |
| + |
| +import 'package:barback/barback.dart'; |
| +$import |
| + |
| +const TOKEN = "$id"; |
| + |
| +final _tokenRegexp = new RegExp(r'^const TOKEN = "(.*?)";\$', multiLine: true); |
|
Bob Nystrom
2013/09/06 18:27:29
Capitalize "Exp" to match the type name.
nweiz
2013/09/09 20:43:38
Done.
|
| + |
| +class DartTransformer extends Transformer { |
| + DartTransformer(); |
| + |
| + String get allowedExtensions => '.dart'; |
| + |
| + Future apply(Transform transform) { |
| + return transform.primaryInput.readAsString().then((contents) { |
| + transform.addOutput(new Asset.fromString(transform.primaryInput.id, |
| + contents.replaceAllMapped(_tokenRegexp, (match) { |
| + return 'const TOKEN = "\${match[1]}, \$TOKEN";'; |
| + }))); |
| + }); |
| + } |
| +} |
| +"""; |
| +} |
| + |
| /// Schedules starting the "pub serve" process. |
| /// |
| /// If [shouldInstallFirst] is `true`, validates that pub install is run first. |