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:
@@ -0,0 +1,30 @@
|
||||
library angular2.test.transform.directive_processor.all_tests;
|
||||
|
||||
import 'dart:io';
|
||||
import 'package:barback/barback.dart';
|
||||
import 'package:angular2/src/transform/directive_processor/rewriter.dart';
|
||||
import 'package:angular2/src/transform/common/formatter.dart';
|
||||
import 'package:code_transformers/tests.dart';
|
||||
import 'package:dart_style/dart_style.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
import 'package:unittest/unittest.dart';
|
||||
import 'package:unittest/vm_config.dart';
|
||||
|
||||
import '../common/read_file.dart';
|
||||
|
||||
var formatter = new DartFormatter();
|
||||
|
||||
void allTests() {
|
||||
test('should preserve parameter annotations as const instances', () {
|
||||
var inputPath = 'parameter_metadata/soup.dart';
|
||||
var expected = _readFile('parameter_metadata/expected/soup.ngDeps.dart');
|
||||
var output =
|
||||
formatter.format(createNgDeps(_readFile(inputPath), inputPath));
|
||||
expect(output, equals(expected));
|
||||
});
|
||||
}
|
||||
|
||||
var pathBase = 'directive_processor';
|
||||
|
||||
/// Smooths over differences in CWD between IDEs and running tests in Travis.
|
||||
String _readFile(String path) => readFile('$pathBase/$path');
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
library dinner.soup;
|
||||
|
||||
import 'soup.dart';
|
||||
import 'package:angular2/src/core/annotations/annotations.dart';
|
||||
|
||||
bool _visited = false;
|
||||
void setupReflection(reflector) {
|
||||
if (_visited) return;
|
||||
_visited = true;
|
||||
reflector
|
||||
..registerType(SoupComponent, {
|
||||
"factory":
|
||||
(String description, salt) => new SoupComponent(description, salt),
|
||||
"parameters": const [const [Tasty, String], const [const Inject(Salt)]],
|
||||
"annotations": const [const Component(selector: '[soup]')]
|
||||
});
|
||||
} // {"version":1,"importOffset":104,"registerOffset":451,"imports":["package:angular2/src/core/annotations/annotations.dart"]}
|
||||
@@ -0,0 +1,8 @@
|
||||
library dinner.soup;
|
||||
|
||||
import 'package:angular2/src/core/annotations/annotations.dart';
|
||||
|
||||
@Component(selector: '[soup]')
|
||||
class SoupComponent {
|
||||
SoupComponent(@Tasty String description, @Inject(Salt) salt);
|
||||
}
|
||||
Reference in New Issue
Block a user