X Tutup
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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();
Expand All @@ -12,21 +14,17 @@ class ImportVisitor extends SimpleAstVisitor<ImportModel> {
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;
}
}
Expand All @@ -37,20 +35,35 @@ class ExportVisitor extends SimpleAstVisitor<ExportModel> {
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<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
/// either an [ImportModel] or an [ExportModel].
void _populateCombinators(NamespaceDirective node, dynamic model) {
Expand Down
1 change: 1 addition & 0 deletions modules_dart/transform/lib/src/transform/common/names.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class _RewriterVisitor extends Object with RecursiveAstVisitor<Object> {
_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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
X Tutup