Skip to content

Port Fix9685 to master #9788

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
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
15 changes: 8 additions & 7 deletions src/compiler/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -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)) {
Expand All @@ -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.
Expand Down
28 changes: 28 additions & 0 deletions tests/baselines/reference/decoratedClassExportsCommonJS1.js
Original file line number Diff line number Diff line change
@@ -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;
21 changes: 21 additions & 0 deletions tests/baselines/reference/decoratedClassExportsCommonJS1.symbols
Original file line number Diff line number Diff line change
@@ -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))
}
24 changes: 24 additions & 0 deletions tests/baselines/reference/decoratedClassExportsCommonJS1.types
Original file line number Diff line number Diff line change
@@ -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
}
26 changes: 26 additions & 0 deletions tests/baselines/reference/decoratedClassExportsCommonJS2.js
Original file line number Diff line number Diff line change
@@ -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;
17 changes: 17 additions & 0 deletions tests/baselines/reference/decoratedClassExportsCommonJS2.symbols
Original file line number Diff line number Diff line change
@@ -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))

20 changes: 20 additions & 0 deletions tests/baselines/reference/decoratedClassExportsCommonJS2.types
Original file line number Diff line number Diff line change
@@ -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

39 changes: 39 additions & 0 deletions tests/baselines/reference/decoratedClassExportsSystem1.js
Original file line number Diff line number Diff line change
@@ -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);
}
}
});
26 changes: 26 additions & 0 deletions tests/baselines/reference/decoratedClassExportsSystem1.symbols
Original file line number Diff line number Diff line change
@@ -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))
}
29 changes: 29 additions & 0 deletions tests/baselines/reference/decoratedClassExportsSystem1.types
Original file line number Diff line number Diff line change
@@ -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
}
35 changes: 35 additions & 0 deletions tests/baselines/reference/decoratedClassExportsSystem2.js
Original file line number Diff line number Diff line change
@@ -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);
}
}
});
17 changes: 17 additions & 0 deletions tests/baselines/reference/decoratedClassExportsSystem2.symbols
Original file line number Diff line number Diff line change
@@ -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))

20 changes: 20 additions & 0 deletions tests/baselines/reference/decoratedClassExportsSystem2.types
Original file line number Diff line number Diff line change
@@ -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

Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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 { }
Original file line number Diff line number Diff line change
@@ -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;
}
Loading