Chromium Code Reviews| 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."); |