Permit (and test) complex decorators
This commit is contained in:
parent
7879032e88
commit
ddd63e8788
5 changed files with 1916 additions and 263 deletions
|
@ -2069,8 +2069,6 @@ export class Transformer {
|
|||
}
|
||||
|
||||
private getDecoratorSymbol(decorator: ts.Decorator): ts.Symbol {
|
||||
contract.assert(decorator.expression.kind === ts.SyntaxKind.Identifier,
|
||||
"Only simple @decorator annotations are currently supported");
|
||||
return this.checker().getSymbolAtLocation(decorator.expression);
|
||||
}
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load diff
6
cmd/lumijs/tests/output/basic/decors/decors.ts
Normal file
6
cmd/lumijs/tests/output/basic/decors/decors.ts
Normal file
|
@ -0,0 +1,6 @@
|
|||
// Define a bunch of no-op decorators.
|
||||
export function classDecorate(target: Object) {}
|
||||
export function propertyDecorate(target: Object, propertyKey: string) {}
|
||||
export function methodDecorate(target: Object, propertyKey: any, descriptor: any) {}
|
||||
export function parameterDecorate(target: Object, propertyKey: string, parameterIndex: number) {}
|
||||
|
|
@ -1,12 +1,11 @@
|
|||
// First, define a bunch of no-op decorators.
|
||||
function classDecorate(target: Object) {}
|
||||
function propertyDecorate(target: Object, propertyKey: string) {}
|
||||
function methodDecorate(target: Object, propertyKey: any, descriptor: any) {}
|
||||
function parameterDecorate(target: Object, propertyKey: string, parameterIndex: number) {}
|
||||
import {classDecorate, propertyDecorate, methodDecorate, parameterDecorate} from "./decors";
|
||||
import * as decors from "./decors";
|
||||
|
||||
// Now test that each of the cases works and leads to the right attributes in the resulting metadata.
|
||||
// Test that each of the cases works and leads to the right attributes in the resulting metadata.
|
||||
|
||||
// First, using "simple" names.
|
||||
@classDecorate
|
||||
class TestDecorators {
|
||||
class TestSimpleDecorators {
|
||||
@propertyDecorate a: string;
|
||||
@propertyDecorate public b: string;
|
||||
@propertyDecorate public c: string = "test";
|
||||
|
@ -30,4 +29,29 @@ class TestDecorators {
|
|||
mparam2(@parameterDecorate x, y, @parameterDecorate z): void { }
|
||||
}
|
||||
|
||||
// Next, using "qualified" names.
|
||||
@decors.classDecorate
|
||||
class TestQualifiedDecorators {
|
||||
@decors.propertyDecorate a: string;
|
||||
@decors.propertyDecorate public b: string;
|
||||
@decors.propertyDecorate public c: string = "test";
|
||||
|
||||
@decors.methodDecorate
|
||||
m1(): string { return ""; }
|
||||
@decors.methodDecorate
|
||||
public m2(): string { return ""; }
|
||||
@decors.methodDecorate
|
||||
get p1(): string { return ""; }
|
||||
set p1(v: string) {}
|
||||
get p2(): string { return ""; }
|
||||
@decors.methodDecorate
|
||||
set p2(v: string) {}
|
||||
@decors.methodDecorate
|
||||
public get p3() { return "" }
|
||||
public set p3(v: string) {}
|
||||
|
||||
mparam1(@decors.parameterDecorate x, y, @decors.parameterDecorate z): void { }
|
||||
@decors.methodDecorate
|
||||
mparam2(@decors.parameterDecorate x, y, @decors.parameterDecorate z): void { }
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,8 @@
|
|||
"target": "es5"
|
||||
},
|
||||
"files": [
|
||||
"index.ts"
|
||||
"index.ts",
|
||||
"decors.ts"
|
||||
]
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue