Skip to content

Commit 4d3c74f

Browse files
committed
Merge pull request microsoft#5137 from Microsoft/fixExportDefaultClassStatics
Fix emit for ES6 export default class with static initializers.
2 parents 4795acf + f52b7cc commit 4d3c74f

5 files changed

Lines changed: 29 additions & 5 deletions

src/compiler/emitter.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4785,8 +4785,8 @@ 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 with static initializers
4789+
if ((node.name || (node.flags & NodeFlags.Default && staticProperties.length > 0)) && !thisNodeIsDecorated) {
47904790
write(" ");
47914791
emitDeclarationName(node);
47924792
}
@@ -5645,8 +5645,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
56455645
}
56465646

56475647
/*
5648-
* Some bundlers (SystemJS builder) sometimes want to rename dependencies.
5649-
* Here we check if alternative name was provided for a given moduleName and return it if possible.
5648+
* Some bundlers (SystemJS builder) sometimes want to rename dependencies.
5649+
* Here we check if alternative name was provided for a given moduleName and return it if possible.
56505650
*/
56515651
function tryRenameExternalModule(moduleName: LiteralExpression): string {
56525652
if (currentSourceFile.renamedDependencies && hasProperty(currentSourceFile.renamedDependencies, moduleName.text)) {
@@ -7074,7 +7074,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
70747074
return shouldEmitEnumDeclaration(<EnumDeclaration>node);
70757075
}
70767076

7077-
// If the node is emitted in specialized fashion, dont emit comments as this node will handle
7077+
// If the node is emitted in specialized fashion, dont emit comments as this node will handle
70787078
// emitting comments when emitting itself
70797079
Debug.assert(!isSpecializedCommentHandling(node));
70807080

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)