fix(dart/transform): Run DeferredRewriter in the correct phase
`DeferredRewriter` depends on the presence of `.ng_deps.dart` files, which do not yet exist in the phase where it was previously run. Update the transformer phases to fix this and add an integration test to prevent regression.
This commit is contained in:
parent
af1119063c
commit
811d4c03bd
|
@ -30,10 +30,11 @@ class AngularTransformerGroup extends TransformerGroup {
|
|||
[new DirectiveProcessor(options)]
|
||||
];
|
||||
phases.addAll([
|
||||
[new DeferredRewriter(options), new DirectiveMetadataLinker()],
|
||||
[new DirectiveMetadataLinker()],
|
||||
[new BindGenerator(options)],
|
||||
[new TemplateCompiler(options)],
|
||||
[new StylesheetCompiler()],
|
||||
[new DeferredRewriter(options)]
|
||||
]);
|
||||
return new AngularTransformerGroup._(phases,
|
||||
formatCode: options.formatCode);
|
||||
|
|
|
@ -6,6 +6,7 @@ import 'package:code_transformers/tests.dart';
|
|||
import 'package:dart_style/dart_style.dart';
|
||||
|
||||
import '../common/read_file.dart';
|
||||
import 'deferred_files/expected/output.dart' as deferredOuts;
|
||||
|
||||
main() {
|
||||
allTests();
|
||||
|
@ -15,6 +16,21 @@ var formatter = new DartFormatter();
|
|||
var transform = new AngularTransformerGroup(
|
||||
new TransformerOptions(['web/index.dart'], formatCode: true));
|
||||
|
||||
// Each test has its own directory for inputs & an `expected` directory for
|
||||
// expected outputs.
|
||||
//
|
||||
// In addition to these declared inputs, we inject a set of common inputs for
|
||||
// every test.
|
||||
const commonInputs = const {
|
||||
'angular2|lib/src/core/metadata.dart': '../../../lib/src/core/metadata.dart',
|
||||
'angular2|lib/src/core/application.dart': '../common/application.dart',
|
||||
'angular2|lib/src/core/reflection/reflection_capabilities.dart':
|
||||
'../common/reflection_capabilities.dart',
|
||||
'angular2|lib/core.dart': '../../../lib/core.dart',
|
||||
'angular2|lib/src/core/di/decorators.dart':
|
||||
'../../../lib/src/core/di/decorators.dart',
|
||||
};
|
||||
|
||||
class IntegrationTestConfig {
|
||||
final String name;
|
||||
final Map<String, String> assetPathToInputPath;
|
||||
|
@ -32,24 +48,6 @@ class IntegrationTestConfig {
|
|||
void allTests() {
|
||||
Html5LibDomAdapter.makeCurrent();
|
||||
|
||||
/*
|
||||
* Each test has its own directory for inputs & an `expected` directory for
|
||||
* expected outputs.
|
||||
*
|
||||
* In addition to these declared inputs, we inject a set of common inputs for
|
||||
* every test.
|
||||
*/
|
||||
var commonInputs = {
|
||||
'angular2|lib/src/core/metadata.dart':
|
||||
'../../../lib/src/core/metadata.dart',
|
||||
'angular2|lib/src/core/application.dart': '../common/application.dart',
|
||||
'angular2|lib/src/core/reflection/reflection_capabilities.dart':
|
||||
'../common/reflection_capabilities.dart',
|
||||
'angular2|lib/core.dart': '../../../lib/core.dart',
|
||||
'angular2|lib/src/core/di/decorators.dart':
|
||||
'../../../lib/src/core/di/decorators.dart',
|
||||
};
|
||||
|
||||
var tests = [
|
||||
new IntegrationTestConfig(
|
||||
'should generate proper code for a Component defining only a selector.',
|
||||
|
@ -162,10 +160,33 @@ void allTests() {
|
|||
config.assetPathToInputPath,
|
||||
config.assetPathToExpectedOutputPath,
|
||||
[]);
|
||||
//,
|
||||
// StringFormatter.noNewlinesOrSurroundingWhitespace);
|
||||
}
|
||||
}
|
||||
|
||||
_testDeferredRewriter();
|
||||
}
|
||||
|
||||
void _testDeferredRewriter() {
|
||||
var inputs = {
|
||||
'a|web/bar.dart': 'deferred_files/bar.dart',
|
||||
'a|web/index.dart': 'deferred_files/index.dart'
|
||||
};
|
||||
inputs.addAll(commonInputs);
|
||||
inputs.keys.forEach((k) => inputs[k] = _readFile(inputs[k]));
|
||||
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/index.dart': deferredOuts.indexContents
|
||||
};
|
||||
testPhases(
|
||||
'should handle deferred imports in input files.',
|
||||
[
|
||||
[transform]
|
||||
],
|
||||
inputs,
|
||||
outputs,
|
||||
[]);
|
||||
}
|
||||
|
||||
/// Smooths over differences in CWD between IDEs and running tests in Travis.
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
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() {}
|
|
@ -0,0 +1,17 @@
|
|||
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() {}
|
|
@ -0,0 +1,24 @@
|
|||
library bar.ng_deps.dart;
|
||||
|
||||
import 'bar.template.dart' as _templates;
|
||||
|
||||
import 'bar.dart';
|
||||
import 'package:angular2/src/core/reflection/reflection.dart' as _ngRef;
|
||||
import 'package:angular2/src/core/metadata.dart';
|
||||
import 'package:angular2/src/core/metadata.ng_deps.dart' as i0;
|
||||
export 'bar.dart';
|
||||
|
||||
var _visited = false;
|
||||
void initReflector() {
|
||||
if (_visited) return;
|
||||
_visited = true;
|
||||
_ngRef.reflector
|
||||
..registerType(
|
||||
MyComponent,
|
||||
new _ngRef.ReflectionInfo(const [
|
||||
const Component(selector: '[soup]'),
|
||||
const View(template: ''),
|
||||
_templates.HostMyComponentTemplate
|
||||
], const [], () => new MyComponent()));
|
||||
i0.initReflector();
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
library angular2.test.transform.integration.deferred;
|
||||
|
||||
// This stored as a constant because we need to be careful to avoid modifying
|
||||
// source lines for files we rewrite.
|
||||
// That is, we expect that modifications we make to input files do not change
|
||||
// line numbers, and storing this expected output as code would allow it to be
|
||||
// formatted, breaking our tests.
|
||||
const indexContents = '''
|
||||
library web_foo;
|
||||
|
||||
import 'index.ng_deps.dart' as ngStaticInit;import 'bar.ng_deps.dart' deferred as bar;
|
||||
|
||||
void main() {
|
||||
bar.loadLibrary().then((_) {bar.initReflector();}).then((_) {
|
||||
bar.execImmediate();
|
||||
});
|
||||
}
|
||||
''';
|
|
@ -0,0 +1,9 @@
|
|||
library web_foo;
|
||||
|
||||
import 'bar.dart' deferred as bar;
|
||||
|
||||
void main() {
|
||||
bar.loadLibrary().then((_) {
|
||||
bar.execImmediate();
|
||||
});
|
||||
}
|
Loading…
Reference in New Issue