mirror of
https://github.com/angular/angular
synced 2026-05-24 09:28:37 +00:00
Create transformers that allow specifying transformer actions on specific libraries. * angular2/transform/codegen: Generates all necessary code. * angular2/transform/reflection_rewriter: Replaces `bootstrap` calls in application entry points to remove transitive dart:mirrors import, resulting in smaller code size & faster execution. * angular2/transform/deferred_rewriter: Rewrites deferred imports and `loadLibrary` calls to initialize Angular2 and preserve deferred operation. Proper configuration of these three transformers can replace the single angular2 transformer, resulting in significant performance gains for builds of large angular2 apps. Update angular2 itself to declare the codegen transformer, since it has neither deferred imports nor application entry points. Remove the undocumented & unused quick_transformer.
56 lines
2.1 KiB
Dart
56 lines
2.1 KiB
Dart
library angular2.transform.codegen.dart;
|
|
|
|
import 'package:barback/barback.dart';
|
|
import 'package:dart_style/dart_style.dart';
|
|
|
|
import 'package:angular2/src/transform/common/eager_transformer_wrapper.dart';
|
|
import 'package:angular2/src/transform/common/formatter.dart' as formatter;
|
|
import 'package:angular2/src/transform/common/options.dart';
|
|
import 'package:angular2/src/transform/common/options_reader.dart';
|
|
import 'package:angular2/src/transform/directive_metadata_linker/transformer.dart';
|
|
import 'package:angular2/src/transform/directive_processor/transformer.dart';
|
|
import 'package:angular2/src/transform/inliner_for_test/transformer.dart';
|
|
import 'package:angular2/src/transform/stylesheet_compiler/transformer.dart';
|
|
import 'package:angular2/src/transform/template_compiler/transformer.dart';
|
|
|
|
export 'package:angular2/src/transform/common/options.dart';
|
|
|
|
/// Generates code to replace mirror use in Angular 2 apps.
|
|
///
|
|
/// This transformer can be used along with others as a faster alternative to
|
|
/// the single angular2 transformer.
|
|
///
|
|
/// See [the wiki][] for details.
|
|
///
|
|
/// [the wiki]: https://github.com/angular/angular/wiki/Angular-2-Dart-Transformer
|
|
class CodegenTransformer extends TransformerGroup {
|
|
CodegenTransformer._(phases, {bool formatCode: false}) : super(phases) {
|
|
if (formatCode) {
|
|
formatter.init(new DartFormatter());
|
|
}
|
|
}
|
|
|
|
factory CodegenTransformer(TransformerOptions options) {
|
|
var phases;
|
|
if (options.inlineViews) {
|
|
phases = [
|
|
[new InlinerForTest(options)]
|
|
];
|
|
} else {
|
|
phases = [
|
|
[new DirectiveProcessor(options)],
|
|
[new DirectiveMetadataLinker()],
|
|
[new StylesheetCompiler(), new TemplateCompiler(options),],
|
|
];
|
|
}
|
|
if (options.modeName == BarbackMode.RELEASE || !options.lazyTransformers) {
|
|
phases = phases
|
|
.map((phase) => phase.map((t) => new EagerTransformerWrapper(t)));
|
|
}
|
|
return new CodegenTransformer._(phases, formatCode: options.formatCode);
|
|
}
|
|
|
|
factory CodegenTransformer.asPlugin(BarbackSettings settings) {
|
|
return new CodegenTransformer(parseBarbackSettings(settings));
|
|
}
|
|
}
|