Skip to content

Commit 64b6c9f

Browse files
committed
Fix emit for ES6 export default class with static initializers. Fixes microsoft#5136.
1 parent e7c2003 commit 64b6c9f

5 files changed

Lines changed: 28 additions & 2 deletions

src/compiler/emitter.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4785,8 +4785,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
47854785

47864786
// emit name if
47874787
// - node has a name
4788-
// - this is default export and target is not ES6 (for ES6 `export default` does not need to be compiled downlevel)
4789-
if ((node.name || (node.flags & NodeFlags.Default && languageVersion < ScriptTarget.ES6)) && !thisNodeIsDecorated) {
4788+
// - this is default export and target is not ES6 (for ES6 `export default` does not need to be compiled downlevel)
4789+
// - this is default export with static initializers
4790+
if ((node.name || (node.flags & NodeFlags.Default && (languageVersion < ScriptTarget.ES6
4791+
|| staticProperties.length > 0))) && !thisNodeIsDecorated) {
47904792
write(" ");
47914793
emitDeclarationName(node);
47924794
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//// [exportDefaultClassWithStaticPropertyAssignmentsInES6.ts]
2+
export default class {
3+
static z: string = "Foo";
4+
}
5+
6+
//// [exportDefaultClassWithStaticPropertyAssignmentsInES6.js]
7+
export default class default_1 {
8+
}
9+
default_1.z = "Foo";
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
=== tests/cases/conformance/es6/classDeclaration/exportDefaultClassWithStaticPropertyAssignmentsInES6.ts ===
2+
export default class {
3+
static z: string = "Foo";
4+
>z : Symbol(default.z, Decl(exportDefaultClassWithStaticPropertyAssignmentsInES6.ts, 0, 22))
5+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
=== tests/cases/conformance/es6/classDeclaration/exportDefaultClassWithStaticPropertyAssignmentsInES6.ts ===
2+
export default class {
3+
static z: string = "Foo";
4+
>z : string
5+
>"Foo" : string
6+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// @target:es6
2+
export default class {
3+
static z: string = "Foo";
4+
}

0 commit comments

Comments
 (0)