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
This commit is contained in:
parent
3c43a8c549
commit
0db02523d3
@ -1,7 +1,9 @@
|
|||||||
library angular2.transform.common.code.import_export_code;
|
library angular2.transform.common.code.import_export_code;
|
||||||
|
|
||||||
import 'package:analyzer/analyzer.dart';
|
import 'package:analyzer/analyzer.dart';
|
||||||
|
|
||||||
import 'package:angular2/src/transform/common/mirror_matcher.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';
|
import 'package:angular2/src/transform/common/model/import_export_model.pb.dart';
|
||||||
|
|
||||||
const _mirrorMatcher = const MirrorMatcher();
|
const _mirrorMatcher = const MirrorMatcher();
|
||||||
@ -12,21 +14,17 @@ class ImportVisitor extends SimpleAstVisitor<ImportModel> {
|
|||||||
ImportModel visitImportDirective(ImportDirective node) {
|
ImportModel visitImportDirective(ImportDirective node) {
|
||||||
if (node.isSynthetic) return null;
|
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;
|
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()
|
final model = new ImportModel()
|
||||||
..uri = uri
|
..uri = stringLiteralToString(node.uri)
|
||||||
..isDeferred = node.deferredKeyword != null;
|
..isDeferred = node.deferredKeyword != null;
|
||||||
if (node.prefix != null) {
|
if (node.prefix != null) {
|
||||||
model.prefix = node.prefix.name;
|
model.prefix = node.prefix.name;
|
||||||
}
|
}
|
||||||
_populateCombinators(node, model);
|
_populateCombinators(node, model);
|
||||||
|
_updateIfBootstrap(node, model);
|
||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -37,20 +35,35 @@ class ExportVisitor extends SimpleAstVisitor<ExportModel> {
|
|||||||
ExportModel visitExportDirective(ExportDirective node) {
|
ExportModel visitExportDirective(ExportDirective node) {
|
||||||
if (node.isSynthetic) return null;
|
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;
|
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);
|
_populateCombinators(node, model);
|
||||||
|
_updateIfBootstrap(node, model);
|
||||||
return 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<String> 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
|
/// Parses `combinators` in `node` and adds them to `model`, which should be
|
||||||
/// either an [ImportModel] or an [ExportModel].
|
/// either an [ImportModel] or an [ExportModel].
|
||||||
void _populateCombinators(NamespaceDirective node, dynamic model) {
|
void _populateCombinators(NamespaceDirective node, dynamic model) {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
library angular2.transform.common.names;
|
library angular2.transform.common.names;
|
||||||
|
|
||||||
const BOOTSTRAP_NAME = 'bootstrap';
|
const BOOTSTRAP_NAME = 'bootstrap';
|
||||||
|
const BOOTSTRAP_STATIC_NAME = 'bootstrapStatic';
|
||||||
const SETUP_METHOD_NAME = 'initReflector';
|
const SETUP_METHOD_NAME = 'initReflector';
|
||||||
const REFLECTOR_VAR_NAME = 'reflector';
|
const REFLECTOR_VAR_NAME = 'reflector';
|
||||||
const TRANSFORM_DYNAMIC_MODE = 'transform_dynamic';
|
const TRANSFORM_DYNAMIC_MODE = 'transform_dynamic';
|
||||||
|
@ -140,7 +140,7 @@ class _RewriterVisitor extends Object with RecursiveAstVisitor<Object> {
|
|||||||
_setupAdded ? '' : ', () { ${_getStaticReflectorInitBlock()} }';
|
_setupAdded ? '' : ', () { ${_getStaticReflectorInitBlock()} }';
|
||||||
|
|
||||||
// rewrite `bootstrap(...)` to `bootstrapStatic(...)`
|
// rewrite `bootstrap(...)` to `bootstrapStatic(...)`
|
||||||
buf.write('bootstrapStatic(${args[0]}');
|
buf.write('$BOOTSTRAP_STATIC_NAME(${args[0]}');
|
||||||
if (numArgs == 1) {
|
if (numArgs == 1) {
|
||||||
// bootstrap args are positional, so before we pass reflectorInit code
|
// bootstrap args are positional, so before we pass reflectorInit code
|
||||||
// we need to pass `null` for DI bindings.
|
// we need to pass `null` for DI bindings.
|
||||||
|
@ -2,7 +2,7 @@ library web_foo.ng_deps.dart;
|
|||||||
|
|
||||||
import 'index.dart';
|
import 'index.dart';
|
||||||
import 'package:angular2/src/core/reflection/reflection.dart' as _ngRef;
|
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 'package:angular2/src/core/reflection/reflection.dart';
|
||||||
import 'bar.dart';
|
import 'bar.dart';
|
||||||
import 'bar.ng_deps.dart' as i0;
|
import 'bar.ng_deps.dart' as i0;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
library web_foo;
|
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.dart';
|
||||||
import 'package:angular2/src/core/reflection/reflection_capabilities.dart';
|
import 'package:angular2/src/core/reflection/reflection_capabilities.dart';
|
||||||
import 'bar.dart';
|
import 'bar.dart';
|
||||||
|
Loading…
x
Reference in New Issue
Block a user