Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(638)

Unified Diff: pkg/smoke/lib/src/default_transformer.dart

Issue 169913004: Adding package:smoke. This CL includes the intial APIs, a mirror-based (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: pkg/smoke/lib/src/default_transformer.dart
diff --git a/pkg/smoke/lib/src/default_transformer.dart b/pkg/smoke/lib/src/default_transformer.dart
new file mode 100644
index 0000000000000000000000000000000000000000..742e48747ad39c471bba65666414f8396be098df
--- /dev/null
+++ b/pkg/smoke/lib/src/default_transformer.dart
@@ -0,0 +1,36 @@
+// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+/// Transformer that replaces the default mirror-based implementation of smoke,
+/// so that during deploy smoke doesn't include any dependency on dart:mirrors.
+library smoke.src.default_transformer;
+
+import 'dart:async';
+import 'package:barback/barback.dart';
+
+/// Replaces the default mirror-based implementation of smoke in
+/// `pacakge:smoke/implementation.dart`, so that during deploy smoke doesn't
+/// include any dependency on dart:mirrors.
+// TODO(sigmund): include tests that run this transformation automatically.
+class DefaultTransformer extends Transformer {
+ DefaultTransformer.asPlugin();
+
+ /// Only apply to `lib/src/implementation.dart`.
+ Future<bool> isPrimary(Asset input) => new Future.value(
+ input.id.package == 'smoke' &&
+ input.id.path == 'lib/src/implementation.dart');
+
+ Future apply(Transform transform) {
+ var id = transform.primaryInput.id;
+ return transform.primaryInput.readAsString().then((code) {
+ // Note: this rewrite is highly-coupled with how implementation.dart is
+ // written. Make sure both are updated in sync.
+ transform.addOutput(new Asset.fromString(id, code
+ .replaceAll(new RegExp('new Reflective[^;]*;'),
+ 'throwNotConfiguredError();')
+ .replaceAll("import 'package:smoke/mirrors.dart'';", '')));
Jennifer Messerly 2014/02/20 21:24:47 is there an extra ' here? mirrors.dart''
Siggi Cherem (dart-lang) 2014/02/20 22:19:48 good catch! I had renamed the library and when I f
+ });
+ }
+}
+

Powered by Google App Engine
This is Rietveld 408576698