Skip to content

Commit 8940795

Browse files
committed
fix(transformer): prepare transformers for full template compilation
1 parent 41c9f32 commit 8940795

2 files changed

Lines changed: 38 additions & 12 deletions

File tree

modules/angular2/src/router/router.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -359,8 +359,8 @@ export class Router {
359359
if (componentInstruction.reuse) {
360360
next = this._outlet.reuse(componentInstruction);
361361
} else {
362-
next =
363-
this.deactivate(instruction).then((_) => this._outlet.activate(componentInstruction));
362+
let outlet = this._outlet;
363+
next = this.deactivate(instruction).then((_) => outlet.activate(componentInstruction));
364364
}
365365
if (isPresent(instruction.child)) {
366366
next = next.then((_) => {
@@ -412,7 +412,8 @@ export class Router {
412412
next = this._childRouter.deactivate(childInstruction);
413413
}
414414
if (isPresent(this._outlet)) {
415-
next = next.then((_) => this._outlet.deactivate(componentInstruction));
415+
let outlet = this._outlet;
416+
next = next.then((_) => outlet.deactivate(componentInstruction));
416417
}
417418

418419
// TODO: handle aux routes

modules_dart/transform/lib/src/transform/directive_metadata_linker/ng_meta_linker.dart

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ class _Linker {
113113
if (ngMeta.needsResolution) {
114114
final resolver = new _NgMetaIdentifierResolver(
115115
assetId, reader, ngMetas, resolvedIdentifiers, errorOnMissingIdentifiers);
116-
return resolver.resolveNgMeta(ngMeta);
116+
return resolver.resolveNgMeta(ngMeta, assetId);
117117
} else {
118118
return null;
119119
}
@@ -177,8 +177,8 @@ class _NgMetaIdentifierResolver {
177177

178178
_NgMetaIdentifierResolver(this.entryPoint, this.reader, this.ngMetas, this.resolvedIdentifiers, this.errorOnMissingIdentifiers);
179179

180-
Future resolveNgMeta(NgMeta ngMeta) async {
181-
final ngMetaMap = await _extractNgMetaMap(ngMeta);
180+
Future resolveNgMeta(NgMeta ngMeta, AssetId assetId) async {
181+
final ngMetaMap = await _extractNgMetaMap(ngMeta, assetId);
182182
ngMeta.identifiers.forEach((_, meta) {
183183
if (meta is CompileIdentifierMetadata && meta.value != null) {
184184
meta.value = _resolveProviders(ngMetaMap, meta.value, "root");
@@ -375,14 +375,16 @@ class _NgMetaIdentifierResolver {
375375
name: id.name, moduleUrl: resolvedIdentifiers[id.name]);
376376

377377
// these are so common that we special case them in the transformer
378-
} else if (id.name == "Window" || id.name == "Document") {
378+
} else if (id.name == "Window" || id.name == "Document" || id.name == "Storage") {
379379
return new CompileIdentifierMetadata(name: id.name, moduleUrl: 'dart:html');
380+
} else if (id.name == "Random") {
381+
return new CompileIdentifierMetadata(name: id.name, moduleUrl: 'dart:math');
380382
} else if (id.name == "Profiler") {
381383
return new CompileIdentifierMetadata(name: id.name, moduleUrl: 'asset:perf_api/lib/perf_api.dart');
382384
} else if (id.name == "Logger") {
383385
return new CompileIdentifierMetadata(name: id.name, moduleUrl: 'asset:logging/lib/logging.dart');
384386
} else if (id.name == "Clock") {
385-
return new CompileIdentifierMetadata(name: id.name, moduleUrl: 'asset:quiver/lib/src/time/clock.dart');
387+
return new CompileIdentifierMetadata(name: id.name, moduleUrl: 'asset:quiver/lib/time.dart');
386388
} else if (id.name == "Log") {
387389
return new CompileIdentifierMetadata(name: id.name, moduleUrl: 'asset:angular2/lib/src/testing/utils.dart');
388390
} else if (id.name == "TestComponentBuilder") {
@@ -421,7 +423,7 @@ class _NgMetaIdentifierResolver {
421423

422424
/// Walks all the imports and creates a map from prefixes to
423425
/// all the symbols available through those prefixes
424-
Future<Map<String, NgMeta>> _extractNgMetaMap(NgMeta ngMeta) async {
426+
Future<Map<String, NgMeta>> _extractNgMetaMap(NgMeta ngMeta, AssetId assetId) async {
425427
final res = {"": new NgMeta.empty()};
426428
res[""].addAll(ngMeta);
427429

@@ -442,11 +444,34 @@ class _NgMetaIdentifierResolver {
442444
if (newMeta != null) {
443445
res[import.prefix].addAll(newMeta);
444446
} else {
445-
final summaryAsset =
446-
fromUri(_urlResolver.resolve(assetUri, toSummaryExtension(import.uri)));
447+
final summaryUri = _urlResolver.resolve(
448+
assetUri, toSummaryExtension(import.uri));
449+
final summaryAsset = fromUri(summaryUri);
447450
final summary = await _readNgMeta(reader, summaryAsset, {});
448451
if (summary != null) {
449-
res[import.prefix].addAll(summary);
452+
453+
// We get here if we are in an import/export cycle. To resolve this
454+
// we load the summaries directly. This is sufficient for resolving
455+
// which module the symbol is defined in, which is the purpose of the
456+
// map we are building.
457+
final prefixRes = res[import.prefix];
458+
prefixRes.addAll(summary);
459+
if (summary.ngDeps != null &&
460+
summary.ngDeps.exports != null) {
461+
462+
463+
// Re-exporting one level of exports is usually sufficient.
464+
// Consider a recursively exporting exports.
465+
for (var export in summary.ngDeps.exports) {
466+
final exportAsset = fromUri(
467+
_urlResolver.resolve(
468+
summaryUri, toSummaryExtension(export.uri)));
469+
final exportSummary = await _readNgMeta(reader, exportAsset, {});
470+
if (exportSummary != null) {
471+
prefixRes.addAll(exportSummary);
472+
}
473+
}
474+
}
450475
}
451476
}
452477
}

0 commit comments

Comments
 (0)