diff --git a/tools/transpiler/spec/annotations_spec.js b/tools/transpiler/spec/annotations_spec.js index d867fda1f3..d6ff1294a7 100644 --- a/tools/transpiler/spec/annotations_spec.js +++ b/tools/transpiler/spec/annotations_spec.js @@ -1,9 +1,25 @@ import {describe, it, expect} from 'test_lib/test_lib'; -import {Provide, readFirstAnnotation} from './fixtures/annotations'; +import {readFirstAnnotation} from './fixtures/annotations'; +import {CONST} from 'facade/lang'; class Inject {} class Bar {} +class Provide { + @CONST() + constructor(token) { + this.token = token; + } +} + +class AnnotateMe { + @CONST() + constructor({maybe = 'default'} = {}) { + this.maybe = maybe; + } +} + + @Provide('Foo') class Foo { @Inject @@ -13,6 +29,12 @@ class Foo { @Provide(Foo) function baz() {} +@AnnotateMe() +class A {} + +@AnnotateMe({maybe: 'yes'}) +class B {} + function annotatedParams(@Inject(Foo) f, @Inject(Bar) b) {} export function main() { @@ -22,5 +44,10 @@ export function main() { var clazz = readFirstAnnotation(Foo); expect(clazz instanceof Provide).toBe(true); }); + + it('should work with named arguments', function() { + expect(readFirstAnnotation(A).maybe).toBe('default'); + expect(readFirstAnnotation(B).maybe).toBe('yes'); + }); }); -} \ No newline at end of file +} diff --git a/tools/transpiler/spec/fixtures/annotations.dart b/tools/transpiler/spec/fixtures/annotations.dart index e3837f21d6..e66506490b 100644 --- a/tools/transpiler/spec/fixtures/annotations.dart +++ b/tools/transpiler/spec/fixtures/annotations.dart @@ -1,20 +1,5 @@ import 'dart:mirrors'; -// This class is not generated, -// but should be in the future. -// -// Problems: -// - Dart requires annotations to be const (which makes sense). -// Right now, I can't describe that in ES6. -class Provide { - final token; - const Provide(this.token); -} - -class CONST { - const CONST(); -} - // TODO: this api does not yet return an array as we don't have // a nice array wrapper for Dart readFirstAnnotation(clazz) { diff --git a/tools/transpiler/spec/fixtures/annotations.es6 b/tools/transpiler/spec/fixtures/annotations.es6 index e1780d5dbd..15de650d28 100644 --- a/tools/transpiler/spec/fixtures/annotations.es6 +++ b/tools/transpiler/spec/fixtures/annotations.es6 @@ -1,18 +1,3 @@ -// This class is not generated, -// but should be in the future. -// -// Problems: -// - Dart requires annotations to be const (which makes sense). -// Right now, I can't describe that in ES6. -export class Provide { - constructor(token) { - this.token = token; - } -} - -export class CONST { -} - // TODO: this api does not yet return an array as we don't have // a nice array wrapper for Dart export function readFirstAnnotation(clazz) { diff --git a/tools/transpiler/src/codegeneration/NamedParamsTransformer.js b/tools/transpiler/src/codegeneration/NamedParamsTransformer.js index 68e056c491..0d56553071 100644 --- a/tools/transpiler/src/codegeneration/NamedParamsTransformer.js +++ b/tools/transpiler/src/codegeneration/NamedParamsTransformer.js @@ -48,6 +48,12 @@ export class NamedParamsTransformer extends ParseTreeTransformer { return tree; } + transformAnnotation(tree) { + tree = super.transformAnnotation(tree); + if (tree.args) this._handleNamedParams(tree); + return tree; + } + _handleNamedParams(tree) { if (this._isLastArgAnNonEmptyObjectLiteral(tree) && ! this._isLastArgObjectLiteralWithQuotedKeys(tree)) {