feat(dart/transform) Register parameter metadata information

Adds any metadata attached to a parameter to the "parameters" value
passed in to `registerType`.

For example:
`MyComponent(@Inject(Foo) foo)` generates
`"parameters": const [const [const Inject(Foo)]]`

Also reorganizes the testing code.

Closes #7
This commit is contained in:
Tim Blasi
2015-03-06 11:10:14 -08:00
parent e1a1dd07e4
commit f4e0f51f5a
41 changed files with 271 additions and 167 deletions
@@ -0,0 +1,21 @@
library angular2.test.transform.reflection_remover;
import 'package:analyzer/analyzer.dart';
import 'package:angular2/src/transform/reflection_remover/codegen.dart';
import 'package:angular2/src/transform/reflection_remover/rewriter.dart';
import 'package:unittest/unittest.dart';
import 'reflection_remover_files/expected/index.dart' as expected;
import '../common/read_file.dart';
void allTests() {
var codegen = new Codegen('web/index.dart', 'web/index.ngDeps.dart');
test('should remove uses of mirrors & insert calls to generated code', () {
var code =
readFile('reflection_remover/reflection_remover_files/index.dart');
var output =
new Rewriter(code, codegen).rewrite(parseCompilationUnit(code));
expect(output, equals(expected.code));
});
}
@@ -0,0 +1,7 @@
Tests that the reflection removal step:
1. Comments out the import of reflection_capabilities.dart
2. Comments out the instantiation of `ReflectionCapabilities`
3. Adds the appropriate import.
4. Adds the call to `setupReflection`
5. Does not change line numbers in the source.
6. Makes minimal changes to source offsets.
@@ -0,0 +1,22 @@
library angular2.test.transform.reflection_remover_files;
// This file is intentionally formatted as a string to avoid having the
// automatic transformer prettify it.
//
// This file represents transformed user code. Because this code will be
// linked to output by a source map, we cannot change line numbers from the
// original code and we therefore add our generated code on the same line as
// those we are removing.
var code = """
library web_foo;
import 'package:angular2/src/core/application.dart';
import 'package:angular2/src/reflection/reflection.dart';
import 'package:angular2/src/reflection/reflection_capabilities.dart';import 'index.ngDeps.dart' as ngStaticInit;
void main() {
reflector.reflectionCapabilities = new ReflectionCapabilities();ngStaticInit.setupReflection(reflector);
bootstrap(MyComponent);
}
""";
@@ -0,0 +1,10 @@
library web_foo;
import 'package:angular2/src/core/application.dart';
import 'package:angular2/src/reflection/reflection.dart';
import 'package:angular2/src/reflection/reflection_capabilities.dart';
void main() {
reflector.reflectionCapabilities = new ReflectionCapabilities();
bootstrap(MyComponent);
}