diff --git a/modules_dart/transform/lib/src/transform/common/code/import_export_code.dart b/modules_dart/transform/lib/src/transform/common/code/import_export_code.dart index 30745b57dd..db212e4e4a 100644 --- a/modules_dart/transform/lib/src/transform/common/code/import_export_code.dart +++ b/modules_dart/transform/lib/src/transform/common/code/import_export_code.dart @@ -1,7 +1,9 @@ library angular2.transform.common.code.import_export_code; import 'package:analyzer/analyzer.dart'; + import 'package:angular2/src/transform/common/mirror_matcher.dart'; +import 'package:angular2/src/transform/common/names.dart'; import 'package:angular2/src/transform/common/model/import_export_model.pb.dart'; const _mirrorMatcher = const MirrorMatcher(); @@ -12,21 +14,17 @@ class ImportVisitor extends SimpleAstVisitor { ImportModel visitImportDirective(ImportDirective node) { if (node.isSynthetic) return null; - /// We skip this, as it transitively imports 'dart:mirrors' + // This transitively imports 'dart:mirrors'. if (_mirrorMatcher.hasReflectionCapabilitiesUri(node)) return null; - String uri = stringLiteralToString(node.uri); - // The bootstrap code also transitively imports 'dart:mirrors' - if (_mirrorMatcher.hasBootstrapUri(node)) { - uri = BOOTSTRAP_STATIC_URI; - } - var model = new ImportModel() - ..uri = uri + final model = new ImportModel() + ..uri = stringLiteralToString(node.uri) ..isDeferred = node.deferredKeyword != null; if (node.prefix != null) { model.prefix = node.prefix.name; } _populateCombinators(node, model); + _updateIfBootstrap(node, model); return model; } } @@ -37,20 +35,35 @@ class ExportVisitor extends SimpleAstVisitor { ExportModel visitExportDirective(ExportDirective node) { if (node.isSynthetic) return null; - /// We skip this, as it transitively imports 'dart:mirrors' + // This transitively imports 'dart:mirrors'. if (_mirrorMatcher.hasReflectionCapabilitiesUri(node)) return null; - String uri = stringLiteralToString(node.uri); - // The bootstrap code also transitively imports 'dart:mirrors' - if (_mirrorMatcher.hasBootstrapUri(node)) { - uri = BOOTSTRAP_STATIC_URI; - } - var model = new ExportModel()..uri = uri; + var model = new ExportModel()..uri = stringLiteralToString(node.uri); _populateCombinators(node, model); + _updateIfBootstrap(node, model); return model; } } +/// Ensures that the bootstrap import is not retained in .ng_deps. +/// +/// If `model` has a combinator referencing `BOOTSTRAP_NAME`, rewrite it to +/// `BOOTSTRAP_STATIC_NAME`. +/// `model` should be an [ImportModel] or an [ExportModel]. +void _updateIfBootstrap(NamespaceDirective node, dynamic model) { + if (_mirrorMatcher.hasBootstrapUri(node)) { + model.uri = BOOTSTRAP_STATIC_URI; + [model.showCombinators, model.hideCombinators] + .forEach((List cList) { + for (var i = 0; i < cList.length; ++i) { + if (cList[i] == BOOTSTRAP_NAME) { + cList[i] = BOOTSTRAP_STATIC_NAME; + } + } + }); + } +} + /// Parses `combinators` in `node` and adds them to `model`, which should be /// either an [ImportModel] or an [ExportModel]. void _populateCombinators(NamespaceDirective node, dynamic model) { diff --git a/modules_dart/transform/lib/src/transform/common/names.dart b/modules_dart/transform/lib/src/transform/common/names.dart index c8b172e203..06c9e53730 100644 --- a/modules_dart/transform/lib/src/transform/common/names.dart +++ b/modules_dart/transform/lib/src/transform/common/names.dart @@ -1,6 +1,7 @@ library angular2.transform.common.names; const BOOTSTRAP_NAME = 'bootstrap'; +const BOOTSTRAP_STATIC_NAME = 'bootstrapStatic'; const SETUP_METHOD_NAME = 'initReflector'; const REFLECTOR_VAR_NAME = 'reflector'; const TRANSFORM_DYNAMIC_MODE = 'transform_dynamic'; diff --git a/modules_dart/transform/lib/src/transform/reflection_remover/rewriter.dart b/modules_dart/transform/lib/src/transform/reflection_remover/rewriter.dart index 70c5b8acb8..ada8511756 100644 --- a/modules_dart/transform/lib/src/transform/reflection_remover/rewriter.dart +++ b/modules_dart/transform/lib/src/transform/reflection_remover/rewriter.dart @@ -140,7 +140,7 @@ class _RewriterVisitor extends Object with RecursiveAstVisitor { _setupAdded ? '' : ', () { ${_getStaticReflectorInitBlock()} }'; // rewrite `bootstrap(...)` to `bootstrapStatic(...)` - buf.write('bootstrapStatic(${args[0]}'); + buf.write('$BOOTSTRAP_STATIC_NAME(${args[0]}'); if (numArgs == 1) { // bootstrap args are positional, so before we pass reflectorInit code // we need to pass `null` for DI bindings. diff --git a/modules_dart/transform/test/transform/integration/simple_annotation_files/expected/index.ng_deps.dart b/modules_dart/transform/test/transform/integration/simple_annotation_files/expected/index.ng_deps.dart index 76d49a6406..a79f7b8496 100644 --- a/modules_dart/transform/test/transform/integration/simple_annotation_files/expected/index.ng_deps.dart +++ b/modules_dart/transform/test/transform/integration/simple_annotation_files/expected/index.ng_deps.dart @@ -2,7 +2,7 @@ library web_foo.ng_deps.dart; import 'index.dart'; import 'package:angular2/src/core/reflection/reflection.dart' as _ngRef; -import 'package:angular2/bootstrap_static.dart'; +import 'package:angular2/bootstrap_static.dart' show bootstrapStatic; import 'package:angular2/src/core/reflection/reflection.dart'; import 'bar.dart'; import 'bar.ng_deps.dart' as i0; diff --git a/modules_dart/transform/test/transform/integration/simple_annotation_files/index.dart b/modules_dart/transform/test/transform/integration/simple_annotation_files/index.dart index 069954df44..120b50dc02 100644 --- a/modules_dart/transform/test/transform/integration/simple_annotation_files/index.dart +++ b/modules_dart/transform/test/transform/integration/simple_annotation_files/index.dart @@ -1,6 +1,6 @@ library web_foo; -import 'package:angular2/bootstrap.dart'; +import 'package:angular2/bootstrap.dart' show bootstrap; import 'package:angular2/src/core/reflection/reflection.dart'; import 'package:angular2/src/core/reflection/reflection_capabilities.dart'; import 'bar.dart';