diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 6adf76903fb01..a801effd49af8 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -2749,7 +2749,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge * if we should also export the value after its it changed * - check if node is a source level declaration to emit it differently, * i.e non-exported variable statement 'var x = 1' is hoisted so - * we we emit variable statement 'var' should be dropped. + * when we emit variable statement 'var' should be dropped. */ function isSourceFileLevelDeclarationInSystemJsModule(node: Node, isExported: boolean): boolean { if (!node || !isCurrentFileSystemExternalModule()) { @@ -5503,16 +5503,15 @@ const _super = (function (geti, seti) { write("export "); } - if (!isHoistedDeclarationInSystemModule) { - write("let "); - } if (decoratedClassAlias !== undefined) { - write(`${decoratedClassAlias}`); + write(`let ${decoratedClassAlias}`); } else { + if (!isHoistedDeclarationInSystemModule) { + write("let "); + } emitDeclarationName(node); } - write(" = "); } else if (isES6ExportedDeclaration(node)) { @@ -5530,7 +5529,9 @@ const _super = (function (geti, seti) { // // We'll emit: // - // (_temp = class C { ... }, _temp.a = 1, _temp.b = 2, _temp) + // let C_1 = class C{}; + // C_1.a = 1; + // C_1.b = 2; // so forth and so on // // This keeps the expression as an expression, while ensuring that the static parts // of it have been initialized by the time it is used. diff --git a/tests/baselines/reference/decoratedClassExportsCommonJS1.js b/tests/baselines/reference/decoratedClassExportsCommonJS1.js new file mode 100644 index 0000000000000..4a04d724f0c95 --- /dev/null +++ b/tests/baselines/reference/decoratedClassExportsCommonJS1.js @@ -0,0 +1,28 @@ +//// [decoratedClassExportsCommonJS1.ts] +declare var Something: any; +@Something({ v: () => Testing123 }) +export class Testing123 { + static prop0: string; + static prop1 = Testing123.prop0; +} + +//// [decoratedClassExportsCommonJS1.js] +"use strict"; +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var __metadata = (this && this.__metadata) || function (k, v) { + if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); +}; +let Testing123_1 = class Testing123 { +}; +let Testing123 = Testing123_1; +Testing123.prop1 = Testing123.prop0; +Testing123 = Testing123_1 = __decorate([ + Something({ v: () => Testing123 }), + __metadata('design:paramtypes', []) +], Testing123); +exports.Testing123 = Testing123; diff --git a/tests/baselines/reference/decoratedClassExportsCommonJS1.symbols b/tests/baselines/reference/decoratedClassExportsCommonJS1.symbols new file mode 100644 index 0000000000000..3381ef7c06ae5 --- /dev/null +++ b/tests/baselines/reference/decoratedClassExportsCommonJS1.symbols @@ -0,0 +1,21 @@ +=== tests/cases/conformance/decorators/class/decoratedClassExportsCommonJS1.ts === +declare var Something: any; +>Something : Symbol(Something, Decl(decoratedClassExportsCommonJS1.ts, 0, 11)) + +@Something({ v: () => Testing123 }) +>Something : Symbol(Something, Decl(decoratedClassExportsCommonJS1.ts, 0, 11)) +>v : Symbol(v, Decl(decoratedClassExportsCommonJS1.ts, 1, 12)) +>Testing123 : Symbol(Testing123, Decl(decoratedClassExportsCommonJS1.ts, 0, 27)) + +export class Testing123 { +>Testing123 : Symbol(Testing123, Decl(decoratedClassExportsCommonJS1.ts, 0, 27)) + + static prop0: string; +>prop0 : Symbol(Testing123.prop0, Decl(decoratedClassExportsCommonJS1.ts, 2, 25)) + + static prop1 = Testing123.prop0; +>prop1 : Symbol(Testing123.prop1, Decl(decoratedClassExportsCommonJS1.ts, 3, 25)) +>Testing123.prop0 : Symbol(Testing123.prop0, Decl(decoratedClassExportsCommonJS1.ts, 2, 25)) +>Testing123 : Symbol(Testing123, Decl(decoratedClassExportsCommonJS1.ts, 0, 27)) +>prop0 : Symbol(Testing123.prop0, Decl(decoratedClassExportsCommonJS1.ts, 2, 25)) +} diff --git a/tests/baselines/reference/decoratedClassExportsCommonJS1.types b/tests/baselines/reference/decoratedClassExportsCommonJS1.types new file mode 100644 index 0000000000000..0142adb654f87 --- /dev/null +++ b/tests/baselines/reference/decoratedClassExportsCommonJS1.types @@ -0,0 +1,24 @@ +=== tests/cases/conformance/decorators/class/decoratedClassExportsCommonJS1.ts === +declare var Something: any; +>Something : any + +@Something({ v: () => Testing123 }) +>Something({ v: () => Testing123 }) : any +>Something : any +>{ v: () => Testing123 } : { v: () => typeof Testing123; } +>v : () => typeof Testing123 +>() => Testing123 : () => typeof Testing123 +>Testing123 : typeof Testing123 + +export class Testing123 { +>Testing123 : Testing123 + + static prop0: string; +>prop0 : string + + static prop1 = Testing123.prop0; +>prop1 : string +>Testing123.prop0 : string +>Testing123 : typeof Testing123 +>prop0 : string +} diff --git a/tests/baselines/reference/decoratedClassExportsCommonJS2.js b/tests/baselines/reference/decoratedClassExportsCommonJS2.js new file mode 100644 index 0000000000000..c5e8eb9aa2981 --- /dev/null +++ b/tests/baselines/reference/decoratedClassExportsCommonJS2.js @@ -0,0 +1,26 @@ +//// [a.ts] + +declare function forwardRef(x: any): any; +declare var Something: any; +@Something({ v: () => Testing123 }) +export class Testing123 { } + +//// [a.js] +"use strict"; +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var __metadata = (this && this.__metadata) || function (k, v) { + if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); +}; +let Testing123_1 = class Testing123 { +}; +let Testing123 = Testing123_1; +Testing123 = Testing123_1 = __decorate([ + Something({ v: () => Testing123 }), + __metadata('design:paramtypes', []) +], Testing123); +exports.Testing123 = Testing123; diff --git a/tests/baselines/reference/decoratedClassExportsCommonJS2.symbols b/tests/baselines/reference/decoratedClassExportsCommonJS2.symbols new file mode 100644 index 0000000000000..8f587c1bff14d --- /dev/null +++ b/tests/baselines/reference/decoratedClassExportsCommonJS2.symbols @@ -0,0 +1,17 @@ +=== tests/cases/conformance/decorators/class/a.ts === + +declare function forwardRef(x: any): any; +>forwardRef : Symbol(forwardRef, Decl(a.ts, 0, 0)) +>x : Symbol(x, Decl(a.ts, 1, 28)) + +declare var Something: any; +>Something : Symbol(Something, Decl(a.ts, 2, 11)) + +@Something({ v: () => Testing123 }) +>Something : Symbol(Something, Decl(a.ts, 2, 11)) +>v : Symbol(v, Decl(a.ts, 3, 12)) +>Testing123 : Symbol(Testing123, Decl(a.ts, 2, 27)) + +export class Testing123 { } +>Testing123 : Symbol(Testing123, Decl(a.ts, 2, 27)) + diff --git a/tests/baselines/reference/decoratedClassExportsCommonJS2.types b/tests/baselines/reference/decoratedClassExportsCommonJS2.types new file mode 100644 index 0000000000000..eba793247de56 --- /dev/null +++ b/tests/baselines/reference/decoratedClassExportsCommonJS2.types @@ -0,0 +1,20 @@ +=== tests/cases/conformance/decorators/class/a.ts === + +declare function forwardRef(x: any): any; +>forwardRef : (x: any) => any +>x : any + +declare var Something: any; +>Something : any + +@Something({ v: () => Testing123 }) +>Something({ v: () => Testing123 }) : any +>Something : any +>{ v: () => Testing123 } : { v: () => typeof Testing123; } +>v : () => typeof Testing123 +>() => Testing123 : () => typeof Testing123 +>Testing123 : typeof Testing123 + +export class Testing123 { } +>Testing123 : Testing123 + diff --git a/tests/baselines/reference/decoratedClassExportsSystem1.js b/tests/baselines/reference/decoratedClassExportsSystem1.js new file mode 100644 index 0000000000000..1730ba4460f11 --- /dev/null +++ b/tests/baselines/reference/decoratedClassExportsSystem1.js @@ -0,0 +1,39 @@ +//// [a.ts] + +declare function forwardRef(x: any): any; +declare var Something: any; +@Something({ v: () => Testing123 }) +export class Testing123 { + static prop0: string; + static prop1 = Testing123.prop0; +} + +//// [a.js] +System.register([], function(exports_1, context_1) { + "use strict"; + var __moduleName = context_1 && context_1.id; + var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; + }; + var __metadata = (this && this.__metadata) || function (k, v) { + if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); + }; + var Testing123; + return { + setters:[], + execute: function() { + let Testing123_1 = class Testing123 { + }; + let Testing123 = Testing123_1; + Testing123.prop1 = Testing123.prop0; + Testing123 = Testing123_1 = __decorate([ + Something({ v: () => Testing123 }), + __metadata('design:paramtypes', []) + ], Testing123); + exports_1("Testing123", Testing123); + } + } +}); diff --git a/tests/baselines/reference/decoratedClassExportsSystem1.symbols b/tests/baselines/reference/decoratedClassExportsSystem1.symbols new file mode 100644 index 0000000000000..559f78624e315 --- /dev/null +++ b/tests/baselines/reference/decoratedClassExportsSystem1.symbols @@ -0,0 +1,26 @@ +=== tests/cases/conformance/decorators/class/a.ts === + +declare function forwardRef(x: any): any; +>forwardRef : Symbol(forwardRef, Decl(a.ts, 0, 0)) +>x : Symbol(x, Decl(a.ts, 1, 28)) + +declare var Something: any; +>Something : Symbol(Something, Decl(a.ts, 2, 11)) + +@Something({ v: () => Testing123 }) +>Something : Symbol(Something, Decl(a.ts, 2, 11)) +>v : Symbol(v, Decl(a.ts, 3, 12)) +>Testing123 : Symbol(Testing123, Decl(a.ts, 2, 27)) + +export class Testing123 { +>Testing123 : Symbol(Testing123, Decl(a.ts, 2, 27)) + + static prop0: string; +>prop0 : Symbol(Testing123.prop0, Decl(a.ts, 4, 25)) + + static prop1 = Testing123.prop0; +>prop1 : Symbol(Testing123.prop1, Decl(a.ts, 5, 25)) +>Testing123.prop0 : Symbol(Testing123.prop0, Decl(a.ts, 4, 25)) +>Testing123 : Symbol(Testing123, Decl(a.ts, 2, 27)) +>prop0 : Symbol(Testing123.prop0, Decl(a.ts, 4, 25)) +} diff --git a/tests/baselines/reference/decoratedClassExportsSystem1.types b/tests/baselines/reference/decoratedClassExportsSystem1.types new file mode 100644 index 0000000000000..1cc69e8b68091 --- /dev/null +++ b/tests/baselines/reference/decoratedClassExportsSystem1.types @@ -0,0 +1,29 @@ +=== tests/cases/conformance/decorators/class/a.ts === + +declare function forwardRef(x: any): any; +>forwardRef : (x: any) => any +>x : any + +declare var Something: any; +>Something : any + +@Something({ v: () => Testing123 }) +>Something({ v: () => Testing123 }) : any +>Something : any +>{ v: () => Testing123 } : { v: () => typeof Testing123; } +>v : () => typeof Testing123 +>() => Testing123 : () => typeof Testing123 +>Testing123 : typeof Testing123 + +export class Testing123 { +>Testing123 : Testing123 + + static prop0: string; +>prop0 : string + + static prop1 = Testing123.prop0; +>prop1 : string +>Testing123.prop0 : string +>Testing123 : typeof Testing123 +>prop0 : string +} diff --git a/tests/baselines/reference/decoratedClassExportsSystem2.js b/tests/baselines/reference/decoratedClassExportsSystem2.js new file mode 100644 index 0000000000000..b4d34de2958d9 --- /dev/null +++ b/tests/baselines/reference/decoratedClassExportsSystem2.js @@ -0,0 +1,35 @@ +//// [a.ts] + +declare function forwardRef(x: any): any; +declare var Something: any; +@Something({ v: () => Testing123 }) +export class Testing123 { } + +//// [a.js] +System.register([], function(exports_1, context_1) { + "use strict"; + var __moduleName = context_1 && context_1.id; + var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; + }; + var __metadata = (this && this.__metadata) || function (k, v) { + if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); + }; + var Testing123; + return { + setters:[], + execute: function() { + let Testing123_1 = class Testing123 { + }; + let Testing123 = Testing123_1; + Testing123 = Testing123_1 = __decorate([ + Something({ v: () => Testing123 }), + __metadata('design:paramtypes', []) + ], Testing123); + exports_1("Testing123", Testing123); + } + } +}); diff --git a/tests/baselines/reference/decoratedClassExportsSystem2.symbols b/tests/baselines/reference/decoratedClassExportsSystem2.symbols new file mode 100644 index 0000000000000..8f587c1bff14d --- /dev/null +++ b/tests/baselines/reference/decoratedClassExportsSystem2.symbols @@ -0,0 +1,17 @@ +=== tests/cases/conformance/decorators/class/a.ts === + +declare function forwardRef(x: any): any; +>forwardRef : Symbol(forwardRef, Decl(a.ts, 0, 0)) +>x : Symbol(x, Decl(a.ts, 1, 28)) + +declare var Something: any; +>Something : Symbol(Something, Decl(a.ts, 2, 11)) + +@Something({ v: () => Testing123 }) +>Something : Symbol(Something, Decl(a.ts, 2, 11)) +>v : Symbol(v, Decl(a.ts, 3, 12)) +>Testing123 : Symbol(Testing123, Decl(a.ts, 2, 27)) + +export class Testing123 { } +>Testing123 : Symbol(Testing123, Decl(a.ts, 2, 27)) + diff --git a/tests/baselines/reference/decoratedClassExportsSystem2.types b/tests/baselines/reference/decoratedClassExportsSystem2.types new file mode 100644 index 0000000000000..eba793247de56 --- /dev/null +++ b/tests/baselines/reference/decoratedClassExportsSystem2.types @@ -0,0 +1,20 @@ +=== tests/cases/conformance/decorators/class/a.ts === + +declare function forwardRef(x: any): any; +>forwardRef : (x: any) => any +>x : any + +declare var Something: any; +>Something : any + +@Something({ v: () => Testing123 }) +>Something({ v: () => Testing123 }) : any +>Something : any +>{ v: () => Testing123 } : { v: () => typeof Testing123; } +>v : () => typeof Testing123 +>() => Testing123 : () => typeof Testing123 +>Testing123 : typeof Testing123 + +export class Testing123 { } +>Testing123 : Testing123 + diff --git a/tests/cases/conformance/decorators/class/decoratedClassExportsCommonJS1.ts b/tests/cases/conformance/decorators/class/decoratedClassExportsCommonJS1.ts new file mode 100644 index 0000000000000..e00adf3d63b7a --- /dev/null +++ b/tests/cases/conformance/decorators/class/decoratedClassExportsCommonJS1.ts @@ -0,0 +1,13 @@ +// @target: es6 +// @experimentaldecorators: true +// @emitDecoratorMetadata: true +// @module: commonjs +// @filename: a.ts + +declare function forwardRef(x: any): any; +declare var Something: any; +@Something({ v: () => Testing123 }) +export class Testing123 { + static prop0: string; + static prop1 = Testing123.prop0; +} \ No newline at end of file diff --git a/tests/cases/conformance/decorators/class/decoratedClassExportsCommonJS2.ts b/tests/cases/conformance/decorators/class/decoratedClassExportsCommonJS2.ts new file mode 100644 index 0000000000000..38f6ce9f27d8d --- /dev/null +++ b/tests/cases/conformance/decorators/class/decoratedClassExportsCommonJS2.ts @@ -0,0 +1,10 @@ +// @target: es6 +// @experimentaldecorators: true +// @emitDecoratorMetadata: true +// @module: commonjs +// @filename: a.ts + +declare function forwardRef(x: any): any; +declare var Something: any; +@Something({ v: () => Testing123 }) +export class Testing123 { } \ No newline at end of file diff --git a/tests/cases/conformance/decorators/class/decoratedClassExportsSystem1.ts b/tests/cases/conformance/decorators/class/decoratedClassExportsSystem1.ts new file mode 100644 index 0000000000000..1e2619ab89ef2 --- /dev/null +++ b/tests/cases/conformance/decorators/class/decoratedClassExportsSystem1.ts @@ -0,0 +1,13 @@ +// @target: es6 +// @experimentaldecorators: true +// @emitDecoratorMetadata: true +// @module: system +// @filename: a.ts + +declare function forwardRef(x: any): any; +declare var Something: any; +@Something({ v: () => Testing123 }) +export class Testing123 { + static prop0: string; + static prop1 = Testing123.prop0; +} \ No newline at end of file diff --git a/tests/cases/conformance/decorators/class/decoratedClassExportsSystem2.ts b/tests/cases/conformance/decorators/class/decoratedClassExportsSystem2.ts new file mode 100644 index 0000000000000..bf7c9a0ca2deb --- /dev/null +++ b/tests/cases/conformance/decorators/class/decoratedClassExportsSystem2.ts @@ -0,0 +1,10 @@ +// @target: es6 +// @experimentaldecorators: true +// @emitDecoratorMetadata: true +// @module: system +// @filename: a.ts + +declare function forwardRef(x: any): any; +declare var Something: any; +@Something({ v: () => Testing123 }) +export class Testing123 { } \ No newline at end of file