11library angular2.transform.common.code.import_export_code;
22
33import 'package:analyzer/analyzer.dart' ;
4+
45import 'package:angular2/src/transform/common/mirror_matcher.dart' ;
6+ import 'package:angular2/src/transform/common/names.dart' ;
57import 'package:angular2/src/transform/common/model/import_export_model.pb.dart' ;
68
79const _mirrorMatcher = const MirrorMatcher ();
@@ -12,21 +14,17 @@ class ImportVisitor extends SimpleAstVisitor<ImportModel> {
1214 ImportModel visitImportDirective (ImportDirective node) {
1315 if (node.isSynthetic) return null ;
1416
15- /// We skip this, as it transitively imports 'dart:mirrors'
17+ // This transitively imports 'dart:mirrors'.
1618 if (_mirrorMatcher.hasReflectionCapabilitiesUri (node)) return null ;
17- String uri = stringLiteralToString (node.uri);
18- // The bootstrap code also transitively imports 'dart:mirrors'
19- if (_mirrorMatcher.hasBootstrapUri (node)) {
20- uri = BOOTSTRAP_STATIC_URI ;
21- }
2219
23- var model = new ImportModel ()
24- ..uri = uri
20+ final model = new ImportModel ()
21+ ..uri = stringLiteralToString (node. uri)
2522 ..isDeferred = node.deferredKeyword != null ;
2623 if (node.prefix != null ) {
2724 model.prefix = node.prefix.name;
2825 }
2926 _populateCombinators (node, model);
27+ _updateIfBootstrap (node, model);
3028 return model;
3129 }
3230}
@@ -37,20 +35,35 @@ class ExportVisitor extends SimpleAstVisitor<ExportModel> {
3735 ExportModel visitExportDirective (ExportDirective node) {
3836 if (node.isSynthetic) return null ;
3937
40- /// We skip this, as it transitively imports 'dart:mirrors'
38+ // This transitively imports 'dart:mirrors'.
4139 if (_mirrorMatcher.hasReflectionCapabilitiesUri (node)) return null ;
42- String uri = stringLiteralToString (node.uri);
43- // The bootstrap code also transitively imports 'dart:mirrors'
44- if (_mirrorMatcher.hasBootstrapUri (node)) {
45- uri = BOOTSTRAP_STATIC_URI ;
46- }
4740
48- var model = new ExportModel ()..uri = uri;
41+ var model = new ExportModel ()..uri = stringLiteralToString (node. uri) ;
4942 _populateCombinators (node, model);
43+ _updateIfBootstrap (node, model);
5044 return model;
5145 }
5246}
5347
48+ /// Ensures that the bootstrap import is not retained in .ng_deps.
49+ ///
50+ /// If `model` has a combinator referencing `BOOTSTRAP_NAME` , rewrite it to
51+ /// `BOOTSTRAP_STATIC_NAME` .
52+ /// `model` should be an [ImportModel] or an [ExportModel] .
53+ void _updateIfBootstrap (NamespaceDirective node, dynamic model) {
54+ if (_mirrorMatcher.hasBootstrapUri (node)) {
55+ model.uri = BOOTSTRAP_STATIC_URI ;
56+ [model.showCombinators, model.hideCombinators]
57+ .forEach ((List <String > cList) {
58+ for (var i = 0 ; i < cList.length; ++ i) {
59+ if (cList[i] == BOOTSTRAP_NAME ) {
60+ cList[i] = BOOTSTRAP_STATIC_NAME ;
61+ }
62+ }
63+ });
64+ }
65+ }
66+
5467/// Parses `combinators` in `node` and adds them to `model` , which should be
5568/// either an [ImportModel] or an [ExportModel] .
5669void _populateCombinators (NamespaceDirective node, dynamic model) {
0 commit comments