Skip to content

Commit 9886f88

Browse files
authored
[Release-2.0] Fix 9685: missing decoratedClassAlias emit in self-reference decorated class (#9763)
* Wip * Fix incorrect emit decorated class alias when targeting es6 or higher * Add tests and baselines * Remove unused test file
1 parent 2b8c1f9 commit 9886f88

17 files changed

+356
-7
lines changed

src/compiler/emitter.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2749,7 +2749,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
27492749
* if we should also export the value after its it changed
27502750
* - check if node is a source level declaration to emit it differently,
27512751
* i.e non-exported variable statement 'var x = 1' is hoisted so
2752-
* we we emit variable statement 'var' should be dropped.
2752+
* when we emit variable statement 'var' should be dropped.
27532753
*/
27542754
function isSourceFileLevelDeclarationInSystemJsModule(node: Node, isExported: boolean): boolean {
27552755
if (!node || !isCurrentFileSystemExternalModule()) {
@@ -5503,16 +5503,15 @@ const _super = (function (geti, seti) {
55035503
write("export ");
55045504
}
55055505

5506-
if (!isHoistedDeclarationInSystemModule) {
5507-
write("let ");
5508-
}
55095506
if (decoratedClassAlias !== undefined) {
5510-
write(`${decoratedClassAlias}`);
5507+
write(`let ${decoratedClassAlias}`);
55115508
}
55125509
else {
5510+
if (!isHoistedDeclarationInSystemModule) {
5511+
write("let ");
5512+
}
55135513
emitDeclarationName(node);
55145514
}
5515-
55165515
write(" = ");
55175516
}
55185517
else if (isES6ExportedDeclaration(node)) {
@@ -5530,7 +5529,9 @@ const _super = (function (geti, seti) {
55305529
//
55315530
// We'll emit:
55325531
//
5533-
// (_temp = class C { ... }, _temp.a = 1, _temp.b = 2, _temp)
5532+
// let C_1 = class C{};
5533+
// C_1.a = 1;
5534+
// C_1.b = 2; // so forth and so on
55345535
//
55355536
// This keeps the expression as an expression, while ensuring that the static parts
55365537
// of it have been initialized by the time it is used.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//// [decoratedClassExportsCommonJS1.ts]
2+
declare var Something: any;
3+
@Something({ v: () => Testing123 })
4+
export class Testing123 {
5+
static prop0: string;
6+
static prop1 = Testing123.prop0;
7+
}
8+
9+
//// [decoratedClassExportsCommonJS1.js]
10+
"use strict";
11+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
12+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
13+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
14+
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;
15+
return c > 3 && r && Object.defineProperty(target, key, r), r;
16+
};
17+
var __metadata = (this && this.__metadata) || function (k, v) {
18+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
19+
};
20+
let Testing123_1 = class Testing123 {
21+
};
22+
let Testing123 = Testing123_1;
23+
Testing123.prop1 = Testing123.prop0;
24+
Testing123 = Testing123_1 = __decorate([
25+
Something({ v: () => Testing123 }),
26+
__metadata('design:paramtypes', [])
27+
], Testing123);
28+
exports.Testing123 = Testing123;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
=== tests/cases/conformance/decorators/class/decoratedClassExportsCommonJS1.ts ===
2+
declare var Something: any;
3+
>Something : Symbol(Something, Decl(decoratedClassExportsCommonJS1.ts, 0, 11))
4+
5+
@Something({ v: () => Testing123 })
6+
>Something : Symbol(Something, Decl(decoratedClassExportsCommonJS1.ts, 0, 11))
7+
>v : Symbol(v, Decl(decoratedClassExportsCommonJS1.ts, 1, 12))
8+
>Testing123 : Symbol(Testing123, Decl(decoratedClassExportsCommonJS1.ts, 0, 27))
9+
10+
export class Testing123 {
11+
>Testing123 : Symbol(Testing123, Decl(decoratedClassExportsCommonJS1.ts, 0, 27))
12+
13+
static prop0: string;
14+
>prop0 : Symbol(Testing123.prop0, Decl(decoratedClassExportsCommonJS1.ts, 2, 25))
15+
16+
static prop1 = Testing123.prop0;
17+
>prop1 : Symbol(Testing123.prop1, Decl(decoratedClassExportsCommonJS1.ts, 3, 25))
18+
>Testing123.prop0 : Symbol(Testing123.prop0, Decl(decoratedClassExportsCommonJS1.ts, 2, 25))
19+
>Testing123 : Symbol(Testing123, Decl(decoratedClassExportsCommonJS1.ts, 0, 27))
20+
>prop0 : Symbol(Testing123.prop0, Decl(decoratedClassExportsCommonJS1.ts, 2, 25))
21+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
=== tests/cases/conformance/decorators/class/decoratedClassExportsCommonJS1.ts ===
2+
declare var Something: any;
3+
>Something : any
4+
5+
@Something({ v: () => Testing123 })
6+
>Something({ v: () => Testing123 }) : any
7+
>Something : any
8+
>{ v: () => Testing123 } : { v: () => typeof Testing123; }
9+
>v : () => typeof Testing123
10+
>() => Testing123 : () => typeof Testing123
11+
>Testing123 : typeof Testing123
12+
13+
export class Testing123 {
14+
>Testing123 : Testing123
15+
16+
static prop0: string;
17+
>prop0 : string
18+
19+
static prop1 = Testing123.prop0;
20+
>prop1 : string
21+
>Testing123.prop0 : string
22+
>Testing123 : typeof Testing123
23+
>prop0 : string
24+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//// [a.ts]
2+
3+
declare function forwardRef(x: any): any;
4+
declare var Something: any;
5+
@Something({ v: () => Testing123 })
6+
export class Testing123 { }
7+
8+
//// [a.js]
9+
"use strict";
10+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
11+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
12+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
13+
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;
14+
return c > 3 && r && Object.defineProperty(target, key, r), r;
15+
};
16+
var __metadata = (this && this.__metadata) || function (k, v) {
17+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
18+
};
19+
let Testing123_1 = class Testing123 {
20+
};
21+
let Testing123 = Testing123_1;
22+
Testing123 = Testing123_1 = __decorate([
23+
Something({ v: () => Testing123 }),
24+
__metadata('design:paramtypes', [])
25+
], Testing123);
26+
exports.Testing123 = Testing123;
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
=== tests/cases/conformance/decorators/class/a.ts ===
2+
3+
declare function forwardRef(x: any): any;
4+
>forwardRef : Symbol(forwardRef, Decl(a.ts, 0, 0))
5+
>x : Symbol(x, Decl(a.ts, 1, 28))
6+
7+
declare var Something: any;
8+
>Something : Symbol(Something, Decl(a.ts, 2, 11))
9+
10+
@Something({ v: () => Testing123 })
11+
>Something : Symbol(Something, Decl(a.ts, 2, 11))
12+
>v : Symbol(v, Decl(a.ts, 3, 12))
13+
>Testing123 : Symbol(Testing123, Decl(a.ts, 2, 27))
14+
15+
export class Testing123 { }
16+
>Testing123 : Symbol(Testing123, Decl(a.ts, 2, 27))
17+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
=== tests/cases/conformance/decorators/class/a.ts ===
2+
3+
declare function forwardRef(x: any): any;
4+
>forwardRef : (x: any) => any
5+
>x : any
6+
7+
declare var Something: any;
8+
>Something : any
9+
10+
@Something({ v: () => Testing123 })
11+
>Something({ v: () => Testing123 }) : any
12+
>Something : any
13+
>{ v: () => Testing123 } : { v: () => typeof Testing123; }
14+
>v : () => typeof Testing123
15+
>() => Testing123 : () => typeof Testing123
16+
>Testing123 : typeof Testing123
17+
18+
export class Testing123 { }
19+
>Testing123 : Testing123
20+
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//// [a.ts]
2+
3+
declare function forwardRef(x: any): any;
4+
declare var Something: any;
5+
@Something({ v: () => Testing123 })
6+
export class Testing123 {
7+
static prop0: string;
8+
static prop1 = Testing123.prop0;
9+
}
10+
11+
//// [a.js]
12+
System.register([], function(exports_1, context_1) {
13+
"use strict";
14+
var __moduleName = context_1 && context_1.id;
15+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
16+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
17+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
18+
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;
19+
return c > 3 && r && Object.defineProperty(target, key, r), r;
20+
};
21+
var __metadata = (this && this.__metadata) || function (k, v) {
22+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
23+
};
24+
var Testing123;
25+
return {
26+
setters:[],
27+
execute: function() {
28+
let Testing123_1 = class Testing123 {
29+
};
30+
let Testing123 = Testing123_1;
31+
Testing123.prop1 = Testing123.prop0;
32+
Testing123 = Testing123_1 = __decorate([
33+
Something({ v: () => Testing123 }),
34+
__metadata('design:paramtypes', [])
35+
], Testing123);
36+
exports_1("Testing123", Testing123);
37+
}
38+
}
39+
});
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
=== tests/cases/conformance/decorators/class/a.ts ===
2+
3+
declare function forwardRef(x: any): any;
4+
>forwardRef : Symbol(forwardRef, Decl(a.ts, 0, 0))
5+
>x : Symbol(x, Decl(a.ts, 1, 28))
6+
7+
declare var Something: any;
8+
>Something : Symbol(Something, Decl(a.ts, 2, 11))
9+
10+
@Something({ v: () => Testing123 })
11+
>Something : Symbol(Something, Decl(a.ts, 2, 11))
12+
>v : Symbol(v, Decl(a.ts, 3, 12))
13+
>Testing123 : Symbol(Testing123, Decl(a.ts, 2, 27))
14+
15+
export class Testing123 {
16+
>Testing123 : Symbol(Testing123, Decl(a.ts, 2, 27))
17+
18+
static prop0: string;
19+
>prop0 : Symbol(Testing123.prop0, Decl(a.ts, 4, 25))
20+
21+
static prop1 = Testing123.prop0;
22+
>prop1 : Symbol(Testing123.prop1, Decl(a.ts, 5, 25))
23+
>Testing123.prop0 : Symbol(Testing123.prop0, Decl(a.ts, 4, 25))
24+
>Testing123 : Symbol(Testing123, Decl(a.ts, 2, 27))
25+
>prop0 : Symbol(Testing123.prop0, Decl(a.ts, 4, 25))
26+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
=== tests/cases/conformance/decorators/class/a.ts ===
2+
3+
declare function forwardRef(x: any): any;
4+
>forwardRef : (x: any) => any
5+
>x : any
6+
7+
declare var Something: any;
8+
>Something : any
9+
10+
@Something({ v: () => Testing123 })
11+
>Something({ v: () => Testing123 }) : any
12+
>Something : any
13+
>{ v: () => Testing123 } : { v: () => typeof Testing123; }
14+
>v : () => typeof Testing123
15+
>() => Testing123 : () => typeof Testing123
16+
>Testing123 : typeof Testing123
17+
18+
export class Testing123 {
19+
>Testing123 : Testing123
20+
21+
static prop0: string;
22+
>prop0 : string
23+
24+
static prop1 = Testing123.prop0;
25+
>prop1 : string
26+
>Testing123.prop0 : string
27+
>Testing123 : typeof Testing123
28+
>prop0 : string
29+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//// [a.ts]
2+
3+
declare function forwardRef(x: any): any;
4+
declare var Something: any;
5+
@Something({ v: () => Testing123 })
6+
export class Testing123 { }
7+
8+
//// [a.js]
9+
System.register([], function(exports_1, context_1) {
10+
"use strict";
11+
var __moduleName = context_1 && context_1.id;
12+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
13+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
14+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
15+
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;
16+
return c > 3 && r && Object.defineProperty(target, key, r), r;
17+
};
18+
var __metadata = (this && this.__metadata) || function (k, v) {
19+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
20+
};
21+
var Testing123;
22+
return {
23+
setters:[],
24+
execute: function() {
25+
let Testing123_1 = class Testing123 {
26+
};
27+
let Testing123 = Testing123_1;
28+
Testing123 = Testing123_1 = __decorate([
29+
Something({ v: () => Testing123 }),
30+
__metadata('design:paramtypes', [])
31+
], Testing123);
32+
exports_1("Testing123", Testing123);
33+
}
34+
}
35+
});
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
=== tests/cases/conformance/decorators/class/a.ts ===
2+
3+
declare function forwardRef(x: any): any;
4+
>forwardRef : Symbol(forwardRef, Decl(a.ts, 0, 0))
5+
>x : Symbol(x, Decl(a.ts, 1, 28))
6+
7+
declare var Something: any;
8+
>Something : Symbol(Something, Decl(a.ts, 2, 11))
9+
10+
@Something({ v: () => Testing123 })
11+
>Something : Symbol(Something, Decl(a.ts, 2, 11))
12+
>v : Symbol(v, Decl(a.ts, 3, 12))
13+
>Testing123 : Symbol(Testing123, Decl(a.ts, 2, 27))
14+
15+
export class Testing123 { }
16+
>Testing123 : Symbol(Testing123, Decl(a.ts, 2, 27))
17+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
=== tests/cases/conformance/decorators/class/a.ts ===
2+
3+
declare function forwardRef(x: any): any;
4+
>forwardRef : (x: any) => any
5+
>x : any
6+
7+
declare var Something: any;
8+
>Something : any
9+
10+
@Something({ v: () => Testing123 })
11+
>Something({ v: () => Testing123 }) : any
12+
>Something : any
13+
>{ v: () => Testing123 } : { v: () => typeof Testing123; }
14+
>v : () => typeof Testing123
15+
>() => Testing123 : () => typeof Testing123
16+
>Testing123 : typeof Testing123
17+
18+
export class Testing123 { }
19+
>Testing123 : Testing123
20+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// @target: es6
2+
// @experimentaldecorators: true
3+
// @emitDecoratorMetadata: true
4+
// @module: commonjs
5+
// @filename: a.ts
6+
7+
declare function forwardRef(x: any): any;
8+
declare var Something: any;
9+
@Something({ v: () => Testing123 })
10+
export class Testing123 {
11+
static prop0: string;
12+
static prop1 = Testing123.prop0;
13+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// @target: es6
2+
// @experimentaldecorators: true
3+
// @emitDecoratorMetadata: true
4+
// @module: commonjs
5+
// @filename: a.ts
6+
7+
declare function forwardRef(x: any): any;
8+
declare var Something: any;
9+
@Something({ v: () => Testing123 })
10+
export class Testing123 { }
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// @target: es6
2+
// @experimentaldecorators: true
3+
// @emitDecoratorMetadata: true
4+
// @module: system
5+
// @filename: a.ts
6+
7+
declare function forwardRef(x: any): any;
8+
declare var Something: any;
9+
@Something({ v: () => Testing123 })
10+
export class Testing123 {
11+
static prop0: string;
12+
static prop1 = Testing123.prop0;
13+
}

0 commit comments

Comments
 (0)