From 2b45bd2a63d4eb5039519a44f879582aa29ee3be Mon Sep 17 00:00:00 2001 From: Jacob MacDonald Date: Wed, 1 Jul 2015 11:05:59 -0700 Subject: [PATCH] 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)]. --- .../directive_processor/rewriter.dart | 4 +--- .../directive_processor/visitors.dart | 22 +++++++++---------- .../expected/soup.ng_deps.dart | 2 +- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/modules/angular2/src/transform/directive_processor/rewriter.dart b/modules/angular2/src/transform/directive_processor/rewriter.dart index 6dc86d81bf..8541ee1859 100644 --- a/modules/angular2/src/transform/directive_processor/rewriter.dart +++ b/modules/angular2/src/transform/directive_processor/rewriter.dart @@ -243,9 +243,7 @@ class CreateNgDepsVisitor extends Object with SimpleAstVisitor { writer.print('..registerFunction('); node.name.accept(this); writer.print(''', {'parameters': const ['''); - var parameters = node.childEntities - .firstWhere((child) => child is FunctionExpression).parameters; - parameters.accept(_paramsVisitor); + node.functionExpression.parameters.accept(_paramsVisitor); writer.print('''], 'annotations': '''); node.metadata.accept(_metaVisitor); writer.print('})'); diff --git a/modules/angular2/src/transform/directive_processor/visitors.dart b/modules/angular2/src/transform/directive_processor/visitors.dart index 6108ac8fdc..3ac58e8699 100644 --- a/modules/angular2/src/transform/directive_processor/visitors.dart +++ b/modules/angular2/src/transform/directive_processor/visitors.dart @@ -46,18 +46,9 @@ class _CtorTransformVisitor extends ToSourceVisitor { /// `_withParameterNames` is true, this method outputs `node`'s identifier. Object _visitNormalFormalParameter( NodeList metadata, TypeName type, SimpleIdentifier name) { - if (_withParameterAnnotations && metadata != null) { - assert(_withParameterTypes); - for (var i = 0, iLen = metadata.length; i < iLen; ++i) { - if (i != 0) { - writer.print(', '); - } - metadata[i].accept(this); - } - writer.print(type != null && metadata.isNotEmpty ? ', ' : ''); - } var needCompileTimeConstants = !_withParameterNames; - if (_withParameterTypes && type != null) { + var needType = _withParameterTypes && type != null; + if (needType) { _visitNodeWithSuffix(type.name, ' '); if (!needCompileTimeConstants) { // Types with arguments are not compile-time constants. @@ -67,6 +58,15 @@ class _CtorTransformVisitor extends ToSourceVisitor { if (_withParameterNames) { _visitNode(name); } + if (_withParameterAnnotations && metadata != null) { + assert(_withParameterTypes); + for (var i = 0, iLen = metadata.length; i < iLen; ++i) { + if (i != 0 || needType) { + writer.print(', '); + } + metadata[i].accept(this); + } + } return null; } diff --git a/modules/angular2/test/transform/directive_processor/parameter_metadata/expected/soup.ng_deps.dart b/modules/angular2/test/transform/directive_processor/parameter_metadata/expected/soup.ng_deps.dart index d2a2ba6495..9aab172039 100644 --- a/modules/angular2/test/transform/directive_processor/parameter_metadata/expected/soup.ng_deps.dart +++ b/modules/angular2/test/transform/directive_processor/parameter_metadata/expected/soup.ng_deps.dart @@ -11,7 +11,7 @@ void initReflector(reflector) { ..registerType(SoupComponent, { 'factory': (String description, salt) => new SoupComponent(description, salt), - 'parameters': const [const [Tasty, String], const [const Inject(Salt)]], + 'parameters': const [const [String, Tasty], const [const Inject(Salt)]], 'annotations': const [const Component(selector: '[soup]')] }); }