fix(dart/transform): Fix issue with deferred in .ng_deps

Fix an issue in the linking step which prevents libraries from being
imported as `deferred`.
This commit is contained in:
Tim Blasi 2015-10-19 13:49:24 -07:00
parent 9d0d33f95a
commit 6be95ae88a
7 changed files with 50 additions and 20 deletions

View File

@ -65,7 +65,9 @@ bool _isNotDartDirective(dynamic model) => !isDartCoreUri(model.uri);
/// associated `.ng_deps.json` file, if one exists.
Future<Map<String, String>> _processNgImports(NgDepsModel model,
AssetReader reader, AssetId assetId, UrlResolver resolver) async {
final importsAndExports = new List.from(model.imports)..addAll(model.exports);
final importsAndExports =
new List.from(model.imports.where((i) => !i.isDeferred))
..addAll(model.exports);
final retVal = <String, String>{};
final assetUri = toAssetUri(assetId);
return Future

View File

@ -164,6 +164,24 @@ void allTests() {
expect(linkedImport.isNgDeps).toBeTrue();
expect(linkedImport.prefix.startsWith('i')).toBeTrue();
});
it('should not chain `deferred` libraries.', () async {
fooNgMeta.ngDeps
..libraryUri = 'test.foo'
..imports.add(new ImportModel()
..uri = 'bar.dart'
..isDeferred = true
..prefix = 'dep');
barNgMeta.ngDeps.libraryUri = 'test.bar';
updateReader();
var linked = (await _testLink(reader, fooAssetId)).ngDeps;
expect(linked).toBeNotNull();
var linkedImport = linked.imports.firstWhere(
(i) => i.uri.endsWith('bar.ng_deps.dart'),
orElse: () => null);
expect(linkedImport).toBeNull();
});
});
}

View File

@ -179,6 +179,7 @@ void allTests() {
void _testDeferredRewriter() {
var inputs = {
'a|web/bar.dart': 'deferred_files/bar.dart',
'a|web/dep.dart': 'deferred_files/dep.dart',
'a|web/index.dart': 'deferred_files/index.dart'
};
inputs.addAll(commonInputs);
@ -186,7 +187,7 @@ void _testDeferredRewriter() {
var outputs = {
'a|web/bar.ng_deps.dart':
_readFile('deferred_files/expected/bar.ng_deps.dart'),
'a|web/bar.dart': _readFile('deferred_files/expected/bar.dart'),
'a|web/bar.dart': deferredOuts.barContents,
'a|web/index.dart': deferredOuts.indexContents
};
testPhases(

View File

@ -2,7 +2,7 @@ library bar;
import 'package:angular2/src/core/metadata.dart';
import 'deps/my_dep.dart' deferred as dep;
import 'dep.dart' deferred as dep;
@Component(selector: '[soup]')
@View(template: '')

View File

@ -0,0 +1,6 @@
library dep;
import 'package:angular2/src/core/metadata.dart';
@Injectable()
void doImmediateThing() {}

View File

@ -1,17 +0,0 @@
library bar;
import 'package:angular2/src/core/metadata.dart';
import 'deps/my_dep.dart' deferred as dep;
@Component(selector: '[soup]')
@View(template: '')
class MyComponent {
void doDeferredThing() {
dep.loadLibrary().then((_) {
dep.doImmediateThing();
});
}
}
void execImmediate() {}

View File

@ -16,3 +16,23 @@ void main() {
});
}
''';
const barContents = '''
library bar;
import 'package:angular2/src/core/metadata.dart';
import 'dep.ng_deps.dart' deferred as dep;
@Component(selector: '[soup]')
@View(template: '')
class MyComponent {
void doDeferredThing() {
dep.loadLibrary().then((_) {dep.initReflector();}).then((_) {
dep.doImmediateThing();
});
}
}
void execImmediate() {}
''';