X Tutup
Skip to content

Commit 0db0252

Browse files
Tim Blasikegluneq
authored andcommitted
fix(dart/transform): Omit bootstrap.dart in ng_deps
Special-case to avoid copying the bootstrap{,_static}.dart import when creating `.ng_deps.dart` files. Closes #5315 Closes #5348
1 parent 3c43a8c commit 0db0252

File tree

5 files changed

+32
-18
lines changed

5 files changed

+32
-18
lines changed

modules_dart/transform/lib/src/transform/common/code/import_export_code.dart

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
library angular2.transform.common.code.import_export_code;
22

33
import 'package:analyzer/analyzer.dart';
4+
45
import 'package:angular2/src/transform/common/mirror_matcher.dart';
6+
import 'package:angular2/src/transform/common/names.dart';
57
import 'package:angular2/src/transform/common/model/import_export_model.pb.dart';
68

79
const _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].
5669
void _populateCombinators(NamespaceDirective node, dynamic model) {

modules_dart/transform/lib/src/transform/common/names.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
library angular2.transform.common.names;
22

33
const BOOTSTRAP_NAME = 'bootstrap';
4+
const BOOTSTRAP_STATIC_NAME = 'bootstrapStatic';
45
const SETUP_METHOD_NAME = 'initReflector';
56
const REFLECTOR_VAR_NAME = 'reflector';
67
const TRANSFORM_DYNAMIC_MODE = 'transform_dynamic';

modules_dart/transform/lib/src/transform/reflection_remover/rewriter.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ class _RewriterVisitor extends Object with RecursiveAstVisitor<Object> {
140140
_setupAdded ? '' : ', () { ${_getStaticReflectorInitBlock()} }';
141141

142142
// rewrite `bootstrap(...)` to `bootstrapStatic(...)`
143-
buf.write('bootstrapStatic(${args[0]}');
143+
buf.write('$BOOTSTRAP_STATIC_NAME(${args[0]}');
144144
if (numArgs == 1) {
145145
// bootstrap args are positional, so before we pass reflectorInit code
146146
// we need to pass `null` for DI bindings.

modules_dart/transform/test/transform/integration/simple_annotation_files/expected/index.ng_deps.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ library web_foo.ng_deps.dart;
22

33
import 'index.dart';
44
import 'package:angular2/src/core/reflection/reflection.dart' as _ngRef;
5-
import 'package:angular2/bootstrap_static.dart';
5+
import 'package:angular2/bootstrap_static.dart' show bootstrapStatic;
66
import 'package:angular2/src/core/reflection/reflection.dart';
77
import 'bar.dart';
88
import 'bar.ng_deps.dart' as i0;

modules_dart/transform/test/transform/integration/simple_annotation_files/index.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
library web_foo;
22

3-
import 'package:angular2/bootstrap.dart';
3+
import 'package:angular2/bootstrap.dart' show bootstrap;
44
import 'package:angular2/src/core/reflection/reflection.dart';
55
import 'package:angular2/src/core/reflection/reflection_capabilities.dart';
66
import 'bar.dart';

0 commit comments

Comments
 (0)
X Tutup