Skip to content

Commit e195d89

Browse files
committed
Merge pull request #2589 from Microsoft/decorators_types
Experimental support for decorator type metadata. NOTE: Requires a polyfill for `Reflect.metadata` which has not yet been considered by TC39 for ES7.
2 parents e1204a9 + 1bab233 commit e195d89

File tree

59 files changed

+1685
-1103
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+1685
-1103
lines changed

src/compiler/checker.ts

+295-14
Large diffs are not rendered by default.

src/compiler/commandLineParser.ts

+5
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,11 @@ module ts {
156156
shortName: "w",
157157
type: "boolean",
158158
description: Diagnostics.Watch_input_files,
159+
},
160+
{
161+
name: "emitDecoratorMetadata",
162+
type: "boolean",
163+
experimental: true
159164
}
160165
];
161166

src/compiler/emitter.ts

+272-142
Large diffs are not rendered by default.

src/compiler/types.ts

+5
Original file line numberDiff line numberDiff line change
@@ -1255,6 +1255,9 @@ module ts {
12551255
getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number;
12561256
resolvesToSomeValue(location: Node, name: string): boolean;
12571257
getBlockScopedVariableId(node: Identifier): number;
1258+
serializeTypeOfNode(node: Node, getGeneratedNameForNode: (Node: Node) => string): string | string[];
1259+
serializeParameterTypesOfNode(node: Node, getGeneratedNameForNode: (Node: Node) => string): (string | string[])[];
1260+
serializeReturnTypeOfNode(node: Node, getGeneratedNameForNode: (Node: Node) => string): string | string[];
12581261
}
12591262

12601263
export const enum SymbolFlags {
@@ -1380,6 +1383,7 @@ module ts {
13801383
EnumValuesComputed = 0x00000080,
13811384
BlockScopedBindingInLoop = 0x00000100,
13821385
EmitDecorate = 0x00000200, // Emit __decorate
1386+
EmitParam = 0x00000400, // Emit __param helper for decorators
13831387
}
13841388

13851389
export interface NodeLinks {
@@ -1605,6 +1609,7 @@ module ts {
16051609
version?: boolean;
16061610
watch?: boolean;
16071611
separateCompilation?: boolean;
1612+
emitDecoratorMetadata?: boolean;
16081613
/* @internal */ stripInternal?: boolean;
16091614
[option: string]: string | number | boolean;
16101615
}

src/compiler/utilities.ts

+12
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,18 @@ module ts {
449449
return false;
450450
}
451451

452+
export function isAccessor(node: Node): boolean {
453+
if (node) {
454+
switch (node.kind) {
455+
case SyntaxKind.GetAccessor:
456+
case SyntaxKind.SetAccessor:
457+
return true;
458+
}
459+
}
460+
461+
return false;
462+
}
463+
452464
export function isFunctionLike(node: Node): boolean {
453465
if (node) {
454466
switch (node.kind) {

src/lib/es6.d.ts

+18-18
Original file line numberDiff line numberDiff line change
@@ -3513,27 +3513,27 @@ interface ProxyHandler<T> {
35133513

35143514
interface ProxyConstructor {
35153515
revocable<T>(target: T, handler: ProxyHandler<T>): { proxy: T; revoke: () => void; };
3516-
new <T>(target: T, handeler: ProxyHandler<T>): T
3516+
new <T>(target: T, handler: ProxyHandler<T>): T
35173517
}
35183518
declare var Proxy: ProxyConstructor;
35193519

3520-
declare var Reflect: {
3521-
apply(target: Function, thisArgument: any, argumentsList: ArrayLike<any>): any;
3522-
construct(target: Function, argumentsList: ArrayLike<any>): any;
3523-
defineProperty(target: any, propertyKey: PropertyKey, attributes: PropertyDescriptor): boolean;
3524-
deleteProperty(target: any, propertyKey: PropertyKey): boolean;
3525-
enumerate(target: any): IterableIterator<any>;
3526-
get(target: any, propertyKey: PropertyKey, receiver?: any): any;
3527-
getOwnPropertyDescriptor(target: any, propertyKey: PropertyKey): PropertyDescriptor;
3528-
getPrototypeOf(target: any): any;
3529-
has(target: any, propertyKey: string): boolean;
3530-
has(target: any, propertyKey: symbol): boolean;
3531-
isExtensible(target: any): boolean;
3532-
ownKeys(target: any): Array<PropertyKey>;
3533-
preventExtensions(target: any): boolean;
3534-
set(target: any, propertyKey: PropertyKey, value: any, receiver? :any): boolean;
3535-
setPrototypeOf(target: any, proto: any): boolean;
3536-
};
3520+
declare module Reflect {
3521+
function apply(target: Function, thisArgument: any, argumentsList: ArrayLike<any>): any;
3522+
function construct(target: Function, argumentsList: ArrayLike<any>): any;
3523+
function defineProperty(target: any, propertyKey: PropertyKey, attributes: PropertyDescriptor): boolean;
3524+
function deleteProperty(target: any, propertyKey: PropertyKey): boolean;
3525+
function enumerate(target: any): IterableIterator<any>;
3526+
function get(target: any, propertyKey: PropertyKey, receiver?: any): any;
3527+
function getOwnPropertyDescriptor(target: any, propertyKey: PropertyKey): PropertyDescriptor;
3528+
function getPrototypeOf(target: any): any;
3529+
function has(target: any, propertyKey: string): boolean;
3530+
function has(target: any, propertyKey: symbol): boolean;
3531+
function isExtensible(target: any): boolean;
3532+
function ownKeys(target: any): Array<PropertyKey>;
3533+
function preventExtensions(target: any): boolean;
3534+
function set(target: any, propertyKey: PropertyKey, value: any, receiver? :any): boolean;
3535+
function setPrototypeOf(target: any, proto: any): boolean;
3536+
}
35373537

35383538
/**
35393539
* Represents the completion of an asynchronous operation

tests/baselines/reference/APISample_compile.js

+5
Original file line numberDiff line numberDiff line change
@@ -978,6 +978,9 @@ declare module "typescript" {
978978
getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number;
979979
resolvesToSomeValue(location: Node, name: string): boolean;
980980
getBlockScopedVariableId(node: Identifier): number;
981+
serializeTypeOfNode(node: Node, getGeneratedNameForNode: (Node: Node) => string): string | string[];
982+
serializeParameterTypesOfNode(node: Node, getGeneratedNameForNode: (Node: Node) => string): (string | string[])[];
983+
serializeReturnTypeOfNode(node: Node, getGeneratedNameForNode: (Node: Node) => string): string | string[];
981984
}
982985
const enum SymbolFlags {
983986
FunctionScopedVariable = 1,
@@ -1084,6 +1087,7 @@ declare module "typescript" {
10841087
EnumValuesComputed = 128,
10851088
BlockScopedBindingInLoop = 256,
10861089
EmitDecorate = 512,
1090+
EmitParam = 1024,
10871091
}
10881092
interface NodeLinks {
10891093
resolvedType?: Type;
@@ -1256,6 +1260,7 @@ declare module "typescript" {
12561260
version?: boolean;
12571261
watch?: boolean;
12581262
separateCompilation?: boolean;
1263+
emitDecoratorMetadata?: boolean;
12591264
[option: string]: string | number | boolean;
12601265
}
12611266
const enum ModuleKind {

tests/baselines/reference/APISample_compile.types

+30
Original file line numberDiff line numberDiff line change
@@ -3188,6 +3188,30 @@ declare module "typescript" {
31883188
>getBlockScopedVariableId : (node: Identifier) => number
31893189
>node : Identifier
31903190
>Identifier : Identifier
3191+
3192+
serializeTypeOfNode(node: Node, getGeneratedNameForNode: (Node: Node) => string): string | string[];
3193+
>serializeTypeOfNode : (node: Node, getGeneratedNameForNode: (Node: Node) => string) => string | string[]
3194+
>node : Node
3195+
>Node : Node
3196+
>getGeneratedNameForNode : (Node: Node) => string
3197+
>Node : Node
3198+
>Node : Node
3199+
3200+
serializeParameterTypesOfNode(node: Node, getGeneratedNameForNode: (Node: Node) => string): (string | string[])[];
3201+
>serializeParameterTypesOfNode : (node: Node, getGeneratedNameForNode: (Node: Node) => string) => (string | string[])[]
3202+
>node : Node
3203+
>Node : Node
3204+
>getGeneratedNameForNode : (Node: Node) => string
3205+
>Node : Node
3206+
>Node : Node
3207+
3208+
serializeReturnTypeOfNode(node: Node, getGeneratedNameForNode: (Node: Node) => string): string | string[];
3209+
>serializeReturnTypeOfNode : (node: Node, getGeneratedNameForNode: (Node: Node) => string) => string | string[]
3210+
>node : Node
3211+
>Node : Node
3212+
>getGeneratedNameForNode : (Node: Node) => string
3213+
>Node : Node
3214+
>Node : Node
31913215
}
31923216
const enum SymbolFlags {
31933217
>SymbolFlags : SymbolFlags
@@ -3504,6 +3528,9 @@ declare module "typescript" {
35043528

35053529
EmitDecorate = 512,
35063530
>EmitDecorate : NodeCheckFlags
3531+
3532+
EmitParam = 1024,
3533+
>EmitParam : NodeCheckFlags
35073534
}
35083535
interface NodeLinks {
35093536
>NodeLinks : NodeLinks
@@ -4019,6 +4046,9 @@ declare module "typescript" {
40194046
separateCompilation?: boolean;
40204047
>separateCompilation : boolean
40214048

4049+
emitDecoratorMetadata?: boolean;
4050+
>emitDecoratorMetadata : boolean
4051+
40224052
[option: string]: string | number | boolean;
40234053
>option : string
40244054
}

tests/baselines/reference/APISample_linter.js

+5
Original file line numberDiff line numberDiff line change
@@ -1009,6 +1009,9 @@ declare module "typescript" {
10091009
getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number;
10101010
resolvesToSomeValue(location: Node, name: string): boolean;
10111011
getBlockScopedVariableId(node: Identifier): number;
1012+
serializeTypeOfNode(node: Node, getGeneratedNameForNode: (Node: Node) => string): string | string[];
1013+
serializeParameterTypesOfNode(node: Node, getGeneratedNameForNode: (Node: Node) => string): (string | string[])[];
1014+
serializeReturnTypeOfNode(node: Node, getGeneratedNameForNode: (Node: Node) => string): string | string[];
10121015
}
10131016
const enum SymbolFlags {
10141017
FunctionScopedVariable = 1,
@@ -1115,6 +1118,7 @@ declare module "typescript" {
11151118
EnumValuesComputed = 128,
11161119
BlockScopedBindingInLoop = 256,
11171120
EmitDecorate = 512,
1121+
EmitParam = 1024,
11181122
}
11191123
interface NodeLinks {
11201124
resolvedType?: Type;
@@ -1287,6 +1291,7 @@ declare module "typescript" {
12871291
version?: boolean;
12881292
watch?: boolean;
12891293
separateCompilation?: boolean;
1294+
emitDecoratorMetadata?: boolean;
12901295
[option: string]: string | number | boolean;
12911296
}
12921297
const enum ModuleKind {

tests/baselines/reference/APISample_linter.types

+30
Original file line numberDiff line numberDiff line change
@@ -3334,6 +3334,30 @@ declare module "typescript" {
33343334
>getBlockScopedVariableId : (node: Identifier) => number
33353335
>node : Identifier
33363336
>Identifier : Identifier
3337+
3338+
serializeTypeOfNode(node: Node, getGeneratedNameForNode: (Node: Node) => string): string | string[];
3339+
>serializeTypeOfNode : (node: Node, getGeneratedNameForNode: (Node: Node) => string) => string | string[]
3340+
>node : Node
3341+
>Node : Node
3342+
>getGeneratedNameForNode : (Node: Node) => string
3343+
>Node : Node
3344+
>Node : Node
3345+
3346+
serializeParameterTypesOfNode(node: Node, getGeneratedNameForNode: (Node: Node) => string): (string | string[])[];
3347+
>serializeParameterTypesOfNode : (node: Node, getGeneratedNameForNode: (Node: Node) => string) => (string | string[])[]
3348+
>node : Node
3349+
>Node : Node
3350+
>getGeneratedNameForNode : (Node: Node) => string
3351+
>Node : Node
3352+
>Node : Node
3353+
3354+
serializeReturnTypeOfNode(node: Node, getGeneratedNameForNode: (Node: Node) => string): string | string[];
3355+
>serializeReturnTypeOfNode : (node: Node, getGeneratedNameForNode: (Node: Node) => string) => string | string[]
3356+
>node : Node
3357+
>Node : Node
3358+
>getGeneratedNameForNode : (Node: Node) => string
3359+
>Node : Node
3360+
>Node : Node
33373361
}
33383362
const enum SymbolFlags {
33393363
>SymbolFlags : SymbolFlags
@@ -3650,6 +3674,9 @@ declare module "typescript" {
36503674

36513675
EmitDecorate = 512,
36523676
>EmitDecorate : NodeCheckFlags
3677+
3678+
EmitParam = 1024,
3679+
>EmitParam : NodeCheckFlags
36533680
}
36543681
interface NodeLinks {
36553682
>NodeLinks : NodeLinks
@@ -4165,6 +4192,9 @@ declare module "typescript" {
41654192
separateCompilation?: boolean;
41664193
>separateCompilation : boolean
41674194

4195+
emitDecoratorMetadata?: boolean;
4196+
>emitDecoratorMetadata : boolean
4197+
41684198
[option: string]: string | number | boolean;
41694199
>option : string
41704200
}

tests/baselines/reference/APISample_linter.types.pull

+30
Original file line numberDiff line numberDiff line change
@@ -3334,6 +3334,30 @@ declare module "typescript" {
33343334
>getBlockScopedVariableId : (node: Identifier) => number
33353335
>node : Identifier
33363336
>Identifier : Identifier
3337+
3338+
serializeTypeOfNode(node: Node, getGeneratedNameForNode: (Node: Node) => string): string | string[];
3339+
>serializeTypeOfNode : (node: Node, getGeneratedNameForNode: (Node: Node) => string) => string | string[]
3340+
>node : Node
3341+
>Node : Node
3342+
>getGeneratedNameForNode : (Node: Node) => string
3343+
>Node : Node
3344+
>Node : Node
3345+
3346+
serializeParameterTypesOfNode(node: Node, getGeneratedNameForNode: (Node: Node) => string): (string | string[])[];
3347+
>serializeParameterTypesOfNode : (node: Node, getGeneratedNameForNode: (Node: Node) => string) => (string | string[])[]
3348+
>node : Node
3349+
>Node : Node
3350+
>getGeneratedNameForNode : (Node: Node) => string
3351+
>Node : Node
3352+
>Node : Node
3353+
3354+
serializeReturnTypeOfNode(node: Node, getGeneratedNameForNode: (Node: Node) => string): string | string[];
3355+
>serializeReturnTypeOfNode : (node: Node, getGeneratedNameForNode: (Node: Node) => string) => string | string[]
3356+
>node : Node
3357+
>Node : Node
3358+
>getGeneratedNameForNode : (Node: Node) => string
3359+
>Node : Node
3360+
>Node : Node
33373361
}
33383362
const enum SymbolFlags {
33393363
>SymbolFlags : SymbolFlags
@@ -3650,6 +3674,9 @@ declare module "typescript" {
36503674

36513675
EmitDecorate = 512,
36523676
>EmitDecorate : NodeCheckFlags
3677+
3678+
EmitParam = 1024,
3679+
>EmitParam : NodeCheckFlags
36533680
}
36543681
interface NodeLinks {
36553682
>NodeLinks : NodeLinks
@@ -4165,6 +4192,9 @@ declare module "typescript" {
41654192
separateCompilation?: boolean;
41664193
>separateCompilation : boolean
41674194

4195+
emitDecoratorMetadata?: boolean;
4196+
>emitDecoratorMetadata : boolean
4197+
41684198
[option: string]: string | number | boolean;
41694199
>option : string
41704200
}

tests/baselines/reference/APISample_transform.js

+5
Original file line numberDiff line numberDiff line change
@@ -1010,6 +1010,9 @@ declare module "typescript" {
10101010
getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number;
10111011
resolvesToSomeValue(location: Node, name: string): boolean;
10121012
getBlockScopedVariableId(node: Identifier): number;
1013+
serializeTypeOfNode(node: Node, getGeneratedNameForNode: (Node: Node) => string): string | string[];
1014+
serializeParameterTypesOfNode(node: Node, getGeneratedNameForNode: (Node: Node) => string): (string | string[])[];
1015+
serializeReturnTypeOfNode(node: Node, getGeneratedNameForNode: (Node: Node) => string): string | string[];
10131016
}
10141017
const enum SymbolFlags {
10151018
FunctionScopedVariable = 1,
@@ -1116,6 +1119,7 @@ declare module "typescript" {
11161119
EnumValuesComputed = 128,
11171120
BlockScopedBindingInLoop = 256,
11181121
EmitDecorate = 512,
1122+
EmitParam = 1024,
11191123
}
11201124
interface NodeLinks {
11211125
resolvedType?: Type;
@@ -1288,6 +1292,7 @@ declare module "typescript" {
12881292
version?: boolean;
12891293
watch?: boolean;
12901294
separateCompilation?: boolean;
1295+
emitDecoratorMetadata?: boolean;
12911296
[option: string]: string | number | boolean;
12921297
}
12931298
const enum ModuleKind {

tests/baselines/reference/APISample_transform.types

+30
Original file line numberDiff line numberDiff line change
@@ -3284,6 +3284,30 @@ declare module "typescript" {
32843284
>getBlockScopedVariableId : (node: Identifier) => number
32853285
>node : Identifier
32863286
>Identifier : Identifier
3287+
3288+
serializeTypeOfNode(node: Node, getGeneratedNameForNode: (Node: Node) => string): string | string[];
3289+
>serializeTypeOfNode : (node: Node, getGeneratedNameForNode: (Node: Node) => string) => string | string[]
3290+
>node : Node
3291+
>Node : Node
3292+
>getGeneratedNameForNode : (Node: Node) => string
3293+
>Node : Node
3294+
>Node : Node
3295+
3296+
serializeParameterTypesOfNode(node: Node, getGeneratedNameForNode: (Node: Node) => string): (string | string[])[];
3297+
>serializeParameterTypesOfNode : (node: Node, getGeneratedNameForNode: (Node: Node) => string) => (string | string[])[]
3298+
>node : Node
3299+
>Node : Node
3300+
>getGeneratedNameForNode : (Node: Node) => string
3301+
>Node : Node
3302+
>Node : Node
3303+
3304+
serializeReturnTypeOfNode(node: Node, getGeneratedNameForNode: (Node: Node) => string): string | string[];
3305+
>serializeReturnTypeOfNode : (node: Node, getGeneratedNameForNode: (Node: Node) => string) => string | string[]
3306+
>node : Node
3307+
>Node : Node
3308+
>getGeneratedNameForNode : (Node: Node) => string
3309+
>Node : Node
3310+
>Node : Node
32873311
}
32883312
const enum SymbolFlags {
32893313
>SymbolFlags : SymbolFlags
@@ -3600,6 +3624,9 @@ declare module "typescript" {
36003624

36013625
EmitDecorate = 512,
36023626
>EmitDecorate : NodeCheckFlags
3627+
3628+
EmitParam = 1024,
3629+
>EmitParam : NodeCheckFlags
36033630
}
36043631
interface NodeLinks {
36053632
>NodeLinks : NodeLinks
@@ -4115,6 +4142,9 @@ declare module "typescript" {
41154142
separateCompilation?: boolean;
41164143
>separateCompilation : boolean
41174144

4145+
emitDecoratorMetadata?: boolean;
4146+
>emitDecoratorMetadata : boolean
4147+
41184148
[option: string]: string | number | boolean;
41194149
>option : string
41204150
}

0 commit comments

Comments
 (0)