Skip to content

Commit 2b45bd2

Browse files
committed
fix(transformer): Put paramater data in the same order as the reflected version.
Previously it would be [@Inject(#thing), Thing], but it should be [Thing, @Inject(#thing)].
1 parent 7986e7c commit 2b45bd2

File tree

3 files changed

+13
-15
lines changed

3 files changed

+13
-15
lines changed

modules/angular2/src/transform/directive_processor/rewriter.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,7 @@ class CreateNgDepsVisitor extends Object with SimpleAstVisitor<Object> {
243243
writer.print('..registerFunction(');
244244
node.name.accept(this);
245245
writer.print(''', {'parameters': const [''');
246-
var parameters = node.childEntities
247-
.firstWhere((child) => child is FunctionExpression).parameters;
248-
parameters.accept(_paramsVisitor);
246+
node.functionExpression.parameters.accept(_paramsVisitor);
249247
writer.print('''], 'annotations': ''');
250248
node.metadata.accept(_metaVisitor);
251249
writer.print('})');

modules/angular2/src/transform/directive_processor/visitors.dart

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,9 @@ class _CtorTransformVisitor extends ToSourceVisitor {
4646
/// `_withParameterNames` is true, this method outputs `node`'s identifier.
4747
Object _visitNormalFormalParameter(
4848
NodeList<Annotation> metadata, TypeName type, SimpleIdentifier name) {
49-
if (_withParameterAnnotations && metadata != null) {
50-
assert(_withParameterTypes);
51-
for (var i = 0, iLen = metadata.length; i < iLen; ++i) {
52-
if (i != 0) {
53-
writer.print(', ');
54-
}
55-
metadata[i].accept(this);
56-
}
57-
writer.print(type != null && metadata.isNotEmpty ? ', ' : '');
58-
}
5949
var needCompileTimeConstants = !_withParameterNames;
60-
if (_withParameterTypes && type != null) {
50+
var needType = _withParameterTypes && type != null;
51+
if (needType) {
6152
_visitNodeWithSuffix(type.name, ' ');
6253
if (!needCompileTimeConstants) {
6354
// Types with arguments are not compile-time constants.
@@ -67,6 +58,15 @@ class _CtorTransformVisitor extends ToSourceVisitor {
6758
if (_withParameterNames) {
6859
_visitNode(name);
6960
}
61+
if (_withParameterAnnotations && metadata != null) {
62+
assert(_withParameterTypes);
63+
for (var i = 0, iLen = metadata.length; i < iLen; ++i) {
64+
if (i != 0 || needType) {
65+
writer.print(', ');
66+
}
67+
metadata[i].accept(this);
68+
}
69+
}
7070
return null;
7171
}
7272

modules/angular2/test/transform/directive_processor/parameter_metadata/expected/soup.ng_deps.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ void initReflector(reflector) {
1111
..registerType(SoupComponent, {
1212
'factory':
1313
(String description, salt) => new SoupComponent(description, salt),
14-
'parameters': const [const [Tasty, String], const [const Inject(Salt)]],
14+
'parameters': const [const [String, Tasty], const [const Inject(Salt)]],
1515
'annotations': const [const Component(selector: '[soup]')]
1616
});
1717
}

0 commit comments

Comments
 (0)