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

Unified Diff: pkg/polymer/lib/src/build/mirrors_remover.dart

Issue 189213003: Refactoring two pieces of polymer: (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 9 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/polymer/lib/src/build/mirrors_remover.dart
diff --git a/pkg/polymer/lib/src/build/mirrors_remover.dart b/pkg/polymer/lib/src/build/mirrors_remover.dart
new file mode 100644
index 0000000000000000000000000000000000000000..0b91518b18dc70a2889f664f710abb3a88bc6dac
--- /dev/null
+++ b/pkg/polymer/lib/src/build/mirrors_remover.dart
@@ -0,0 +1,45 @@
+// 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 removes uses of mirrors from the polymer runtime, so that
+/// deployed applications are thin and small.
+library polymer.src.build.mirrors_remover;
+
+import 'dart:async';
+import 'package:barback/barback.dart';
+
+/// Removes the code-initialization logic based on mirrors.
+class MirrorsRemover extends Transformer {
+ MirrorsRemover.asPlugin();
+
+ /// Only apply to `lib/polymer.dart`.
+ Future<bool> isPrimary(Asset input) => new Future.value(
+ input.id.package == 'polymer' &&
+ input.id.path == 'lib/polymer.dart');
+
+ Future apply(Transform transform) {
+ var id = transform.primaryInput.id;
+ return transform.primaryInput.readAsString().then((code) {
+ // Note: this rewrite is highly-coupled with how polymer.dart is
+ // written. Make sure both are updated in sync.
+ var start = code.indexOf('@MirrorsUsed');
+ if (start == -1) _error();
+ var end = code.indexOf('show MirrorsUsed;', start);
+ if (end == -1) _error();
+ var sb = new StringBuffer()
+ ..write(code.substring(0, start))
+ ..write(code.susbtring(end)
+ .replaceAll('mirror_loader', 'static_loader')):
Jennifer Messerly 2014/03/06 22:54:17 maybe double check that 'mirror_loader' was found
Siggi Cherem (dart-lang) 2014/03/06 23:09:58 Done.
+
+ transform.addOutput(new Asset.fromString(id, sb.toString()));
+ });
+ }
+}
+
+/** Transformer phases which should be applied to the smoke package. */
+List<List<Transformer>> get phasesForSmoke =>
+ [[new MirrorsRemover.asPlugin()]];
+
+_error() => throw new StateError("Couldn't remove imports to mirrors, maybe "
+ "polymer.dart was modified, but mirrors_remover.dart wasn't.");

Powered by Google App Engine
This is Rietveld 408576698