bug(transpiler): Support optional arguments in annotations.
Clean-up: move annotaitons out of fixtures/annotations, since we have the @CONST annotation in the transpiler already.
This commit is contained in:
parent
90fd1a9227
commit
4f416694a5
|
@ -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');
|
||||
});
|
||||
});
|
||||
}
|
|
@ -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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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)) {
|
||||
|
|
Loading…
Reference in New Issue