File tree Expand file tree Collapse file tree 4 files changed +35
-32
lines changed Expand file tree Collapse file tree 4 files changed +35
-32
lines changed Original file line number Diff line number Diff line change 11import { describe , it , expect } from 'test_lib/test_lib' ;
2- import { Provide , readFirstAnnotation } from './fixtures/annotations' ;
2+ import { readFirstAnnotation } from './fixtures/annotations' ;
3+ import { CONST } from 'facade/lang' ;
34
45class Inject { }
56class Bar { }
67
8+ class Provide {
9+ @CONST ( )
10+ constructor ( token ) {
11+ this . token = token ;
12+ }
13+ }
14+
15+ class AnnotateMe {
16+ @CONST ( )
17+ constructor ( { maybe = 'default' } = { } ) {
18+ this . maybe = maybe ;
19+ }
20+ }
21+
22+
723@Provide ( 'Foo' )
824class Foo {
925 @Inject
@@ -13,6 +29,12 @@ class Foo {
1329@Provide ( Foo )
1430function baz ( ) { }
1531
32+ @AnnotateMe ( )
33+ class A { }
34+
35+ @AnnotateMe ( { maybe : 'yes' } )
36+ class B { }
37+
1638function annotatedParams ( @Inject ( Foo ) f , @Inject ( Bar ) b ) { }
1739
1840export function main ( ) {
@@ -22,5 +44,10 @@ export function main() {
2244 var clazz = readFirstAnnotation ( Foo ) ;
2345 expect ( clazz instanceof Provide ) . toBe ( true ) ;
2446 } ) ;
47+
48+ it ( 'should work with named arguments' , function ( ) {
49+ expect ( readFirstAnnotation ( A ) . maybe ) . toBe ( 'default' ) ;
50+ expect ( readFirstAnnotation ( B ) . maybe ) . toBe ( 'yes' ) ;
51+ } ) ;
2552 } ) ;
26- }
53+ }
Original file line number Diff line number Diff line change 11import 'dart:mirrors' ;
22
3- // This class is not generated,
4- // but should be in the future.
5- //
6- // Problems:
7- // - Dart requires annotations to be const (which makes sense).
8- // Right now, I can't describe that in ES6.
9- class Provide {
10- final token;
11- const Provide (this .token);
12- }
13-
14- class CONST {
15- const CONST ();
16- }
17-
183// TODO: this api does not yet return an array as we don't have
194// a nice array wrapper for Dart
205readFirstAnnotation (clazz) {
Original file line number Diff line number Diff line change 1- // This class is not generated,
2- // but should be in the future.
3- //
4- // Problems:
5- // - Dart requires annotations to be const (which makes sense).
6- // Right now, I can't describe that in ES6.
7- export class Provide {
8- constructor ( token ) {
9- this . token = token ;
10- }
11- }
12-
13- export class CONST {
14- }
15-
161// TODO: this api does not yet return an array as we don't have
172// a nice array wrapper for Dart
183export function readFirstAnnotation ( clazz ) {
Original file line number Diff line number Diff line change @@ -48,6 +48,12 @@ export class NamedParamsTransformer extends ParseTreeTransformer {
4848 return tree ;
4949 }
5050
51+ transformAnnotation ( tree ) {
52+ tree = super . transformAnnotation ( tree ) ;
53+ if ( tree . args ) this . _handleNamedParams ( tree ) ;
54+ return tree ;
55+ }
56+
5157 _handleNamedParams ( tree ) {
5258 if ( this . _isLastArgAnNonEmptyObjectLiteral ( tree ) &&
5359 ! this . _isLastArgObjectLiteralWithQuotedKeys ( tree ) ) {
You can’t perform that action at this time.
0 commit comments