Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added __param helper for parameter decorators and cleaned up __decora…
…te and __metadata
  • Loading branch information
rbuckton committed Apr 2, 2015
commit 5c440384ba3438dee399ca7ddbb61af27f7f64d4
9 changes: 9 additions & 0 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ module ts {
let stringLiteralTypes: Map<StringLiteralType> = {};
let emitExtends = false;
let emitDecorate = false;
let emitParam = false;

let mergedSymbols: Symbol[] = [];
let symbolLinks: SymbolLinks[] = [];
Expand Down Expand Up @@ -8810,6 +8811,10 @@ module ts {
}

emitDecorate = true;
if (node.kind === SyntaxKind.Parameter) {
emitParam = true;
}

forEach(node.decorators, checkDecorator);
}

Expand Down Expand Up @@ -10823,6 +10828,10 @@ module ts {
links.flags |= NodeCheckFlags.EmitDecorate;
}

if (emitParam) {
links.flags |= NodeCheckFlags.EmitParam;
}

links.flags |= NodeCheckFlags.TypeChecked;
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/compiler/commandLineParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,11 @@ module ts {
shortName: "w",
type: "boolean",
description: Diagnostics.Watch_input_files,
},
{
name: "emitDecoratorMetadata",
type: "boolean",
experimental: true
}
];

Expand Down
351 changes: 194 additions & 157 deletions src/compiler/emitter.ts

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1383,6 +1383,7 @@ module ts {
EnumValuesComputed = 0x00000080,
BlockScopedBindingInLoop = 0x00000100,
EmitDecorate = 0x00000200, // Emit __decorate
EmitParam = 0x00000400, // Emit __param helper for decorators
}

export interface NodeLinks {
Expand Down Expand Up @@ -1608,6 +1609,7 @@ module ts {
version?: boolean;
watch?: boolean;
separateCompilation?: boolean;
emitDecoratorMetadata?: boolean;
/* @internal */ stripInternal?: boolean;
[option: string]: string | number | boolean;
}
Expand Down
12 changes: 12 additions & 0 deletions src/compiler/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,18 @@ module ts {
return false;
}

export function isAccessor(node: Node): boolean {
if (node) {
switch (node.kind) {
case SyntaxKind.GetAccessor:
case SyntaxKind.SetAccessor:
return true;
}
}

return false;
}

export function isFunctionLike(node: Node): boolean {
if (node) {
switch (node.kind) {
Expand Down
2 changes: 2 additions & 0 deletions tests/baselines/reference/APISample_compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -1087,6 +1087,7 @@ declare module "typescript" {
EnumValuesComputed = 128,
BlockScopedBindingInLoop = 256,
EmitDecorate = 512,
EmitParam = 1024,
}
interface NodeLinks {
resolvedType?: Type;
Expand Down Expand Up @@ -1259,6 +1260,7 @@ declare module "typescript" {
version?: boolean;
watch?: boolean;
separateCompilation?: boolean;
emitDecoratorMetadata?: boolean;
[option: string]: string | number | boolean;
}
const enum ModuleKind {
Expand Down
6 changes: 6 additions & 0 deletions tests/baselines/reference/APISample_compile.types
Original file line number Diff line number Diff line change
Expand Up @@ -3529,6 +3529,9 @@ declare module "typescript" {

EmitDecorate = 512,
>EmitDecorate : NodeCheckFlags

EmitParam = 1024,
>EmitParam : NodeCheckFlags
}
interface NodeLinks {
>NodeLinks : NodeLinks
Expand Down Expand Up @@ -4044,6 +4047,9 @@ declare module "typescript" {
separateCompilation?: boolean;
>separateCompilation : boolean

emitDecoratorMetadata?: boolean;
>emitDecoratorMetadata : boolean

[option: string]: string | number | boolean;
>option : string
}
Expand Down
2 changes: 2 additions & 0 deletions tests/baselines/reference/APISample_linter.js
Original file line number Diff line number Diff line change
Expand Up @@ -1118,6 +1118,7 @@ declare module "typescript" {
EnumValuesComputed = 128,
BlockScopedBindingInLoop = 256,
EmitDecorate = 512,
EmitParam = 1024,
}
interface NodeLinks {
resolvedType?: Type;
Expand Down Expand Up @@ -1290,6 +1291,7 @@ declare module "typescript" {
version?: boolean;
watch?: boolean;
separateCompilation?: boolean;
emitDecoratorMetadata?: boolean;
[option: string]: string | number | boolean;
}
const enum ModuleKind {
Expand Down
6 changes: 6 additions & 0 deletions tests/baselines/reference/APISample_linter.types
Original file line number Diff line number Diff line change
Expand Up @@ -3675,6 +3675,9 @@ declare module "typescript" {

EmitDecorate = 512,
>EmitDecorate : NodeCheckFlags

EmitParam = 1024,
>EmitParam : NodeCheckFlags
}
interface NodeLinks {
>NodeLinks : NodeLinks
Expand Down Expand Up @@ -4190,6 +4193,9 @@ declare module "typescript" {
separateCompilation?: boolean;
>separateCompilation : boolean

emitDecoratorMetadata?: boolean;
>emitDecoratorMetadata : boolean

[option: string]: string | number | boolean;
>option : string
}
Expand Down
2 changes: 2 additions & 0 deletions tests/baselines/reference/APISample_transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -1119,6 +1119,7 @@ declare module "typescript" {
EnumValuesComputed = 128,
BlockScopedBindingInLoop = 256,
EmitDecorate = 512,
EmitParam = 1024,
}
interface NodeLinks {
resolvedType?: Type;
Expand Down Expand Up @@ -1291,6 +1292,7 @@ declare module "typescript" {
version?: boolean;
watch?: boolean;
separateCompilation?: boolean;
emitDecoratorMetadata?: boolean;
[option: string]: string | number | boolean;
}
const enum ModuleKind {
Expand Down
6 changes: 6 additions & 0 deletions tests/baselines/reference/APISample_transform.types
Original file line number Diff line number Diff line change
Expand Up @@ -3625,6 +3625,9 @@ declare module "typescript" {

EmitDecorate = 512,
>EmitDecorate : NodeCheckFlags

EmitParam = 1024,
>EmitParam : NodeCheckFlags
}
interface NodeLinks {
>NodeLinks : NodeLinks
Expand Down Expand Up @@ -4140,6 +4143,9 @@ declare module "typescript" {
separateCompilation?: boolean;
>separateCompilation : boolean

emitDecoratorMetadata?: boolean;
>emitDecoratorMetadata : boolean

[option: string]: string | number | boolean;
>option : string
}
Expand Down
2 changes: 2 additions & 0 deletions tests/baselines/reference/APISample_watcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -1156,6 +1156,7 @@ declare module "typescript" {
EnumValuesComputed = 128,
BlockScopedBindingInLoop = 256,
EmitDecorate = 512,
EmitParam = 1024,
}
interface NodeLinks {
resolvedType?: Type;
Expand Down Expand Up @@ -1328,6 +1329,7 @@ declare module "typescript" {
version?: boolean;
watch?: boolean;
separateCompilation?: boolean;
emitDecoratorMetadata?: boolean;
[option: string]: string | number | boolean;
}
const enum ModuleKind {
Expand Down
6 changes: 6 additions & 0 deletions tests/baselines/reference/APISample_watcher.types
Original file line number Diff line number Diff line change
Expand Up @@ -3798,6 +3798,9 @@ declare module "typescript" {

EmitDecorate = 512,
>EmitDecorate : NodeCheckFlags

EmitParam = 1024,
>EmitParam : NodeCheckFlags
}
interface NodeLinks {
>NodeLinks : NodeLinks
Expand Down Expand Up @@ -4313,6 +4316,9 @@ declare module "typescript" {
separateCompilation?: boolean;
>separateCompilation : boolean

emitDecoratorMetadata?: boolean;
>emitDecoratorMetadata : boolean

[option: string]: string | number | boolean;
>option : string
}
Expand Down
21 changes: 8 additions & 13 deletions tests/baselines/reference/decoratorOnClass1.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,18 @@ class C {
}

//// [decoratorOnClass1.js]
var __decorate = this.__decorate || function (decorators, target, key, value) {
var kind = typeof (arguments.length == 2 ? value = target : value);
for (var i = decorators.length - 1; i >= 0; --i) {
var decorator = decorators[i];
switch (kind) {
case "function": value = decorator(value) || value; break;
case "number": decorator(target, key, value); break;
case "undefined": decorator(target, key); break;
case "object": value = decorator(target, key, value) || value; break;
}
var __decorate = this.__decorate || (typeof Reflect === "object" && Reflect.decorate) || function (decorators, target, key, desc) {
switch (arguments.length) {
case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target);
case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0);
case 4: return decorators.reduceRight(function(o, d) { return (d && d(target, key, o)) || o; }, desc);
}
return value;
};
var __metadata = this.__metadata || (typeof Reflect === "object" && Reflect.metadata) || function () { return function() { } };
var C = (function () {
function C() {
}
C = __decorate([dec, __metadata('design:paramtypes', [])], C);
C = __decorate([
dec
], C);
return C;
})();
21 changes: 8 additions & 13 deletions tests/baselines/reference/decoratorOnClass2.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,19 @@ export class C {
}

//// [decoratorOnClass2.js]
var __decorate = this.__decorate || function (decorators, target, key, value) {
var kind = typeof (arguments.length == 2 ? value = target : value);
for (var i = decorators.length - 1; i >= 0; --i) {
var decorator = decorators[i];
switch (kind) {
case "function": value = decorator(value) || value; break;
case "number": decorator(target, key, value); break;
case "undefined": decorator(target, key); break;
case "object": value = decorator(target, key, value) || value; break;
}
var __decorate = this.__decorate || (typeof Reflect === "object" && Reflect.decorate) || function (decorators, target, key, desc) {
switch (arguments.length) {
case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target);
case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0);
case 4: return decorators.reduceRight(function(o, d) { return (d && d(target, key, o)) || o; }, desc);
}
return value;
};
var __metadata = this.__metadata || (typeof Reflect === "object" && Reflect.metadata) || function () { return function() { } };
var C = (function () {
function C() {
}
C = __decorate([dec, __metadata('design:paramtypes', [])], C);
C = __decorate([
dec
], C);
return C;
})();
exports.C = C;
21 changes: 8 additions & 13 deletions tests/baselines/reference/decoratorOnClass3.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,18 @@ class C {
}

//// [decoratorOnClass3.js]
var __decorate = this.__decorate || function (decorators, target, key, value) {
var kind = typeof (arguments.length == 2 ? value = target : value);
for (var i = decorators.length - 1; i >= 0; --i) {
var decorator = decorators[i];
switch (kind) {
case "function": value = decorator(value) || value; break;
case "number": decorator(target, key, value); break;
case "undefined": decorator(target, key); break;
case "object": value = decorator(target, key, value) || value; break;
}
var __decorate = this.__decorate || (typeof Reflect === "object" && Reflect.decorate) || function (decorators, target, key, desc) {
switch (arguments.length) {
case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target);
case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0);
case 4: return decorators.reduceRight(function(o, d) { return (d && d(target, key, o)) || o; }, desc);
}
return value;
};
var __metadata = this.__metadata || (typeof Reflect === "object" && Reflect.metadata) || function () { return function() { } };
var C = (function () {
function C() {
}
C = __decorate([dec, __metadata('design:paramtypes', [])], C);
C = __decorate([
dec
], C);
return C;
})();
21 changes: 8 additions & 13 deletions tests/baselines/reference/decoratorOnClass4.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,18 @@ class C {
}

//// [decoratorOnClass4.js]
var __decorate = this.__decorate || function (decorators, target, key, value) {
var kind = typeof (arguments.length == 2 ? value = target : value);
for (var i = decorators.length - 1; i >= 0; --i) {
var decorator = decorators[i];
switch (kind) {
case "function": value = decorator(value) || value; break;
case "number": decorator(target, key, value); break;
case "undefined": decorator(target, key); break;
case "object": value = decorator(target, key, value) || value; break;
}
var __decorate = this.__decorate || (typeof Reflect === "object" && Reflect.decorate) || function (decorators, target, key, desc) {
switch (arguments.length) {
case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target);
case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0);
case 4: return decorators.reduceRight(function(o, d) { return (d && d(target, key, o)) || o; }, desc);
}
return value;
};
var __metadata = this.__metadata || (typeof Reflect === "object" && Reflect.metadata) || function () { return function() { } };
var C = (function () {
function C() {
}
C = __decorate([dec(), __metadata('design:paramtypes', [])], C);
C = __decorate([
dec()
], C);
return C;
})();
21 changes: 8 additions & 13 deletions tests/baselines/reference/decoratorOnClass5.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,18 @@ class C {
}

//// [decoratorOnClass5.js]
var __decorate = this.__decorate || function (decorators, target, key, value) {
var kind = typeof (arguments.length == 2 ? value = target : value);
for (var i = decorators.length - 1; i >= 0; --i) {
var decorator = decorators[i];
switch (kind) {
case "function": value = decorator(value) || value; break;
case "number": decorator(target, key, value); break;
case "undefined": decorator(target, key); break;
case "object": value = decorator(target, key, value) || value; break;
}
var __decorate = this.__decorate || (typeof Reflect === "object" && Reflect.decorate) || function (decorators, target, key, desc) {
switch (arguments.length) {
case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target);
case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0);
case 4: return decorators.reduceRight(function(o, d) { return (d && d(target, key, o)) || o; }, desc);
}
return value;
};
var __metadata = this.__metadata || (typeof Reflect === "object" && Reflect.metadata) || function () { return function() { } };
var C = (function () {
function C() {
}
C = __decorate([dec(), __metadata('design:paramtypes', [])], C);
C = __decorate([
dec()
], C);
return C;
})();
Loading