From f77ca7b5e2ceeaf06e47413d02255f5f2deb36f2 Mon Sep 17 00:00:00 2001 From: Tim Blasi Date: Wed, 25 Nov 2015 14:55:59 -0800 Subject: [PATCH] feat(dart/transform): Add quick_transformer Add an implementation of the transformer which runs only the phases which replace `Asset`s, rather than generate them. Closes #5484 --- .../lib/src/transform/quick_transformer.dart | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 modules_dart/transform/lib/src/transform/quick_transformer.dart diff --git a/modules_dart/transform/lib/src/transform/quick_transformer.dart b/modules_dart/transform/lib/src/transform/quick_transformer.dart new file mode 100644 index 0000000000..55f9718c12 --- /dev/null +++ b/modules_dart/transform/lib/src/transform/quick_transformer.dart @@ -0,0 +1,68 @@ +library angular2.src.transform.quick_transformer; + +import 'package:barback/barback.dart'; +import 'package:dart_style/dart_style.dart'; + +import 'common/formatter.dart' as formatter; +import 'common/options.dart'; +import 'common/options_reader.dart'; +import 'deferred_rewriter/transformer.dart'; +// import 'directive_metadata_linker/transformer.dart'; +// import 'directive_processor/transformer.dart'; +import 'inliner_for_test/transformer.dart'; +import 'reflection_remover/transformer.dart'; +// import 'stylesheet_compiler/transformer.dart'; +// import 'template_compiler/transformer.dart'; + +export 'common/options.dart'; + +/// Replaces Angular 2 mirror use with generated code. +/// +/// Typical users should not use this implementation and should instead use +/// package:angular2/transformer.dart. +/// +/// This alternative excludes phases that generate new [Asset]s, including only +/// the phases that replace existing [Asset]s. +/// +/// This can be used if all code that would be generated already exists as real +/// files, rather than needing to be generated by [Transformer]s. +class AngularTransformerGroup extends TransformerGroup { + AngularTransformerGroup._(phases, {bool formatCode: false}) : super(phases) { + if (formatCode) { + formatter.init(new DartFormatter()); + } + } + + factory AngularTransformerGroup(TransformerOptions options) { + var phases; + if (options.inlineViews) { + phases = [ + [new InlinerForTest(options)] + ]; + } else { + // Only the phases that replace [Asset]s. + phases = [ + [new ReflectionRemover(options)], + [new DeferredRewriter(options)], + ]; + /* + phases = [ + [new DirectiveProcessor(options)], + [new DirectiveMetadataLinker()], + [new ReflectionRemover(options)], + [ + new DeferredRewriter(options), + new StylesheetCompiler(), + new TemplateCompiler(options) + ], + ]; + */ + } + return new AngularTransformerGroup._(phases, + formatCode: options.formatCode); + } + + factory AngularTransformerGroup.asPlugin(BarbackSettings settings) { + return new AngularTransformerGroup(parseBarbackSettings(settings)); + } +}