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:
parent
9d0d33f95a
commit
6be95ae88a
|
@ -65,7 +65,9 @@ bool _isNotDartDirective(dynamic model) => !isDartCoreUri(model.uri);
|
||||||
/// associated `.ng_deps.json` file, if one exists.
|
/// associated `.ng_deps.json` file, if one exists.
|
||||||
Future<Map<String, String>> _processNgImports(NgDepsModel model,
|
Future<Map<String, String>> _processNgImports(NgDepsModel model,
|
||||||
AssetReader reader, AssetId assetId, UrlResolver resolver) async {
|
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 retVal = <String, String>{};
|
||||||
final assetUri = toAssetUri(assetId);
|
final assetUri = toAssetUri(assetId);
|
||||||
return Future
|
return Future
|
||||||
|
|
|
@ -164,6 +164,24 @@ void allTests() {
|
||||||
expect(linkedImport.isNgDeps).toBeTrue();
|
expect(linkedImport.isNgDeps).toBeTrue();
|
||||||
expect(linkedImport.prefix.startsWith('i')).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();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -179,6 +179,7 @@ void allTests() {
|
||||||
void _testDeferredRewriter() {
|
void _testDeferredRewriter() {
|
||||||
var inputs = {
|
var inputs = {
|
||||||
'a|web/bar.dart': 'deferred_files/bar.dart',
|
'a|web/bar.dart': 'deferred_files/bar.dart',
|
||||||
|
'a|web/dep.dart': 'deferred_files/dep.dart',
|
||||||
'a|web/index.dart': 'deferred_files/index.dart'
|
'a|web/index.dart': 'deferred_files/index.dart'
|
||||||
};
|
};
|
||||||
inputs.addAll(commonInputs);
|
inputs.addAll(commonInputs);
|
||||||
|
@ -186,7 +187,7 @@ void _testDeferredRewriter() {
|
||||||
var outputs = {
|
var outputs = {
|
||||||
'a|web/bar.ng_deps.dart':
|
'a|web/bar.ng_deps.dart':
|
||||||
_readFile('deferred_files/expected/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
|
'a|web/index.dart': deferredOuts.indexContents
|
||||||
};
|
};
|
||||||
testPhases(
|
testPhases(
|
||||||
|
|
|
@ -2,7 +2,7 @@ library bar;
|
||||||
|
|
||||||
import 'package:angular2/src/core/metadata.dart';
|
import 'package:angular2/src/core/metadata.dart';
|
||||||
|
|
||||||
import 'deps/my_dep.dart' deferred as dep;
|
import 'dep.dart' deferred as dep;
|
||||||
|
|
||||||
@Component(selector: '[soup]')
|
@Component(selector: '[soup]')
|
||||||
@View(template: '')
|
@View(template: '')
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
library dep;
|
||||||
|
|
||||||
|
import 'package:angular2/src/core/metadata.dart';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
void doImmediateThing() {}
|
|
@ -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() {}
|
|
|
@ -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() {}
|
||||||
|
''';
|
||||||
|
|
Loading…
Reference in New Issue