perf(dart/transform) Restructure transform to independent phases

Update summary:
- Removes the need for resolution, gaining transform speed at the cost
  of some precision and ability to detect errors
- Generates type registrations in the package alongside their declarations
- Ensures that line numbers do not change in transformed user code
This commit is contained in:
Tim Blasi
2015-02-27 14:42:21 -08:00
parent 08bd3a4443
commit d0aceef4e0
52 changed files with 1530 additions and 318 deletions

View File

@ -1,4 +1,4 @@
library angular2.test;
library angular2.test.transform;
import 'dart:io';
import 'package:barback/barback.dart';
@ -8,31 +8,30 @@ import 'package:dart_style/dart_style.dart';
import 'package:unittest/unittest.dart';
import 'package:unittest/vm_config.dart';
import 'reflection_remover_files/expected/index.dart'
as reflection_remover_output;
main() {
useVMConfiguration();
// TODO(kegluneq): Add a test for generating multiple annotations.
group('Annotation tests:', _runTests);
group('Integration tests:', _integrationTests);
}
var formatter = new DartFormatter();
var transform = new AngularTransformer(new TransformerOptions('web/index.dart',
reflectionEntryPoint: 'web/index.dart',
newEntryPoint: 'web/index.bootstrap.dart'));
var transform = new AngularTransformerGroup(new TransformerOptions(
'web/index.dart', reflectionEntryPoint: 'web/index.dart'));
class TestConfig {
class IntegrationTestConfig {
final String name;
final Map<String, String> assetPathToInputPath;
final Map<String, String> assetPathToExpectedOutputPath;
TestConfig(this.name,
IntegrationTestConfig(this.name,
{Map<String, String> inputs, Map<String, String> outputs})
: this.assetPathToInputPath = inputs,
this.assetPathToExpectedOutputPath = outputs;
}
void _runTests() {
void _integrationTests() {
/*
* Each test has its own directory for inputs & an `expected` directory for
* expected outputs.
@ -43,52 +42,53 @@ void _runTests() {
var commonInputs = {
'angular2|lib/src/core/annotations/annotations.dart':
'../../lib/src/core/annotations/annotations.dart',
'angular2|lib/src/core/application.dart': 'common.dart',
'angular2|lib/src/core/application.dart': 'common/application.dart',
'angular2|lib/src/reflection/reflection_capabilities.dart':
'reflection_capabilities.dart'
'common/reflection_capabilities.dart'
};
var tests = [
new TestConfig('Simple',
new IntegrationTestConfig('Simple',
inputs: {
'a|web/index.dart': 'simple_annotation_files/index.dart',
'a|web/bar.dart': 'simple_annotation_files/bar.dart'
},
outputs: {
'a|web/index.bootstrap.dart':
'simple_annotation_files/expected/index.bootstrap.dart',
'a|web/index.dart': 'simple_annotation_files/expected/index.dart',
'a|web/bar.ngDeps.dart':
'simple_annotation_files/expected/bar.ngDeps.dart',
'a|web/index.ngDeps.dart':
'simple_annotation_files/expected/index.ngDeps.dart'
}),
new TestConfig('Two injected dependencies',
new IntegrationTestConfig('Reflection Remover',
inputs: {'a|web/index.dart': 'reflection_remover_files/index.dart'},
outputs: {'a|web/index.dart': reflection_remover_output.code}),
new IntegrationTestConfig('Two injected dependencies',
inputs: {
'a|web/index.dart': 'two_deps_files/index.dart',
'a|web/foo.dart': 'two_deps_files/foo.dart',
'a|web/bar.dart': 'two_deps_files/bar.dart'
},
outputs: {
'a|web/index.bootstrap.dart':
'two_deps_files/expected/index.bootstrap.dart'
'a|web/bar.ngDeps.dart': 'two_deps_files/expected/bar.ngDeps.dart'
}),
new TestConfig('List of types',
new IntegrationTestConfig('List of types',
inputs: {
'a|web/index.dart': 'list_of_types_files/index.dart',
'a|web/foo.dart': 'list_of_types_files/foo.dart',
'a|web/bar.dart': 'list_of_types_files/bar.dart'
},
outputs: {
'a|web/index.bootstrap.dart':
'list_of_types_files/expected/index.bootstrap.dart'
'a|web/bar.ngDeps.dart': 'list_of_types_files/expected/bar.ngDeps.dart'
}),
new TestConfig('Component with synthetic Constructor',
new IntegrationTestConfig('Component with synthetic Constructor',
inputs: {
'a|web/index.dart': 'synthetic_ctor_files/index.dart',
'a|web/bar.dart': 'synthetic_ctor_files/bar.dart'
},
outputs: {
'a|web/index.bootstrap.dart':
'synthetic_ctor_files/expected/index.bootstrap.dart'
'a|web/bar.ngDeps.dart': 'synthetic_ctor_files/expected/bar.ngDeps.dart'
}),
new TestConfig('Component with two annotations',
new IntegrationTestConfig('Component with two annotations',
inputs: {
'a|web/index.dart': 'two_annotations_files/index.dart',
'a|web/bar.dart': 'two_annotations_files/bar.dart',
@ -96,17 +96,25 @@ void _runTests() {
'../../lib/src/core/annotations/template.dart'
},
outputs: {
'a|web/index.bootstrap.dart':
'two_annotations_files/expected/index.bootstrap.dart'
'a|web/bar.ngDeps.dart': 'two_annotations_files/expected/bar.ngDeps.dart'
}),
new TestConfig('Basic `bind`',
new IntegrationTestConfig('Basic `bind`',
inputs: {
'a|web/index.dart': 'basic_bind_files/index.dart',
'a|web/bar.dart': 'basic_bind_files/bar.dart'
},
outputs: {
'a|web/index.bootstrap.dart':
'basic_bind_files/expected/index.bootstrap.dart'
'a|web/bar.ngDeps.dart': 'basic_bind_files/expected/bar.ngDeps.dart'
}),
new IntegrationTestConfig('Chained dependencies',
inputs: {
'a|web/index.dart': 'chained_deps_files/index.dart',
'a|web/foo.dart': 'chained_deps_files/foo.dart',
'a|web/bar.dart': 'chained_deps_files/bar.dart'
},
outputs: {
'a|web/bar.ngDeps.dart': 'chained_deps_files/expected/bar.ngDeps.dart',
'a|web/foo.ngDeps.dart': 'chained_deps_files/expected/foo.ngDeps.dart'
})
];
@ -118,8 +126,8 @@ void _runTests() {
config.assetPathToInputPath
..addAll(commonInputs)
..forEach((key, value) {
config.assetPathToInputPath[
key] = cache.putIfAbsent(value, () => _readFile(value));
config.assetPathToInputPath[key] =
cache.putIfAbsent(value, () => _readFile(value));
});
config.assetPathToExpectedOutputPath.forEach((key, value) {
config.assetPathToExpectedOutputPath[key] = cache.putIfAbsent(value, () {
@ -133,7 +141,7 @@ void _runTests() {
}
}
/// Smoothes over differences in CWD between IDEs and running tests in Travis.
/// Smooths over differences in CWD between IDEs and running tests in Travis.
String _readFile(String path) {
for (var myPath in [path, 'test/transform/${path}']) {
var file = new File(myPath);
@ -141,5 +149,5 @@ String _readFile(String path) {
return file.readAsStringSync();
}
}
return null;
return path;
}