From 64b6c9f52ee683e201498c9d7a73ef565b1dd91e Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Tue, 6 Oct 2015 12:02:55 -0700 Subject: [PATCH 1/3] Fix emit for ES6 export default class with static initializers. Fixes #5136. --- src/compiler/emitter.ts | 6 ++++-- ...portDefaultClassWithStaticPropertyAssignmentsInES6.js | 9 +++++++++ ...efaultClassWithStaticPropertyAssignmentsInES6.symbols | 5 +++++ ...tDefaultClassWithStaticPropertyAssignmentsInES6.types | 6 ++++++ ...portDefaultClassWithStaticPropertyAssignmentsInES6.ts | 4 ++++ 5 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 tests/baselines/reference/exportDefaultClassWithStaticPropertyAssignmentsInES6.js create mode 100644 tests/baselines/reference/exportDefaultClassWithStaticPropertyAssignmentsInES6.symbols create mode 100644 tests/baselines/reference/exportDefaultClassWithStaticPropertyAssignmentsInES6.types create mode 100644 tests/cases/conformance/es6/classDeclaration/exportDefaultClassWithStaticPropertyAssignmentsInES6.ts diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 71187b20960..6f228aeb120 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -4785,8 +4785,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi // emit name if // - node has a name - // - this is default export and target is not ES6 (for ES6 `export default` does not need to be compiled downlevel) - if ((node.name || (node.flags & NodeFlags.Default && languageVersion < ScriptTarget.ES6)) && !thisNodeIsDecorated) { + // - this is default export and target is not ES6 (for ES6 `export default` does not need to be compiled downlevel) + // - this is default export with static initializers + if ((node.name || (node.flags & NodeFlags.Default && (languageVersion < ScriptTarget.ES6 + || staticProperties.length > 0))) && !thisNodeIsDecorated) { write(" "); emitDeclarationName(node); } diff --git a/tests/baselines/reference/exportDefaultClassWithStaticPropertyAssignmentsInES6.js b/tests/baselines/reference/exportDefaultClassWithStaticPropertyAssignmentsInES6.js new file mode 100644 index 00000000000..3acb89b8696 --- /dev/null +++ b/tests/baselines/reference/exportDefaultClassWithStaticPropertyAssignmentsInES6.js @@ -0,0 +1,9 @@ +//// [exportDefaultClassWithStaticPropertyAssignmentsInES6.ts] +export default class { + static z: string = "Foo"; +} + +//// [exportDefaultClassWithStaticPropertyAssignmentsInES6.js] +export default class default_1 { +} +default_1.z = "Foo"; diff --git a/tests/baselines/reference/exportDefaultClassWithStaticPropertyAssignmentsInES6.symbols b/tests/baselines/reference/exportDefaultClassWithStaticPropertyAssignmentsInES6.symbols new file mode 100644 index 00000000000..6d08eb93d92 --- /dev/null +++ b/tests/baselines/reference/exportDefaultClassWithStaticPropertyAssignmentsInES6.symbols @@ -0,0 +1,5 @@ +=== tests/cases/conformance/es6/classDeclaration/exportDefaultClassWithStaticPropertyAssignmentsInES6.ts === +export default class { + static z: string = "Foo"; +>z : Symbol(default.z, Decl(exportDefaultClassWithStaticPropertyAssignmentsInES6.ts, 0, 22)) +} diff --git a/tests/baselines/reference/exportDefaultClassWithStaticPropertyAssignmentsInES6.types b/tests/baselines/reference/exportDefaultClassWithStaticPropertyAssignmentsInES6.types new file mode 100644 index 00000000000..657e0301f83 --- /dev/null +++ b/tests/baselines/reference/exportDefaultClassWithStaticPropertyAssignmentsInES6.types @@ -0,0 +1,6 @@ +=== tests/cases/conformance/es6/classDeclaration/exportDefaultClassWithStaticPropertyAssignmentsInES6.ts === +export default class { + static z: string = "Foo"; +>z : string +>"Foo" : string +} diff --git a/tests/cases/conformance/es6/classDeclaration/exportDefaultClassWithStaticPropertyAssignmentsInES6.ts b/tests/cases/conformance/es6/classDeclaration/exportDefaultClassWithStaticPropertyAssignmentsInES6.ts new file mode 100644 index 00000000000..485fbdb011d --- /dev/null +++ b/tests/cases/conformance/es6/classDeclaration/exportDefaultClassWithStaticPropertyAssignmentsInES6.ts @@ -0,0 +1,4 @@ +// @target:es6 +export default class { + static z: string = "Foo"; +} \ No newline at end of file From ab73b4f1037099d91da126c56da8be709a1559d5 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Tue, 6 Oct 2015 12:37:10 -0700 Subject: [PATCH 2/3] Fix linter warnings. --- src/compiler/emitter.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 6f228aeb120..c00c7e50076 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -4787,7 +4787,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi // - node has a name // - this is default export and target is not ES6 (for ES6 `export default` does not need to be compiled downlevel) // - this is default export with static initializers - if ((node.name || (node.flags & NodeFlags.Default && (languageVersion < ScriptTarget.ES6 + if ((node.name || (node.flags & NodeFlags.Default && (languageVersion < ScriptTarget.ES6 || staticProperties.length > 0))) && !thisNodeIsDecorated) { write(" "); emitDeclarationName(node); @@ -5647,8 +5647,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi } /* - * Some bundlers (SystemJS builder) sometimes want to rename dependencies. - * Here we check if alternative name was provided for a given moduleName and return it if possible. + * Some bundlers (SystemJS builder) sometimes want to rename dependencies. + * Here we check if alternative name was provided for a given moduleName and return it if possible. */ function tryRenameExternalModule(moduleName: LiteralExpression): string { if (currentSourceFile.renamedDependencies && hasProperty(currentSourceFile.renamedDependencies, moduleName.text)) { @@ -7076,7 +7076,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi return shouldEmitEnumDeclaration(node); } - // If the node is emitted in specialized fashion, dont emit comments as this node will handle + // If the node is emitted in specialized fashion, dont emit comments as this node will handle // emitting comments when emitting itself Debug.assert(!isSpecializedCommentHandling(node)); From f52b7cc2c5c31decb76c6221c81bda16b6b98c8b Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Tue, 6 Oct 2015 15:41:47 -0700 Subject: [PATCH 3/3] Removed unnecessary check --- src/compiler/emitter.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index c00c7e50076..312ea42eefb 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -4785,10 +4785,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi // emit name if // - node has a name - // - this is default export and target is not ES6 (for ES6 `export default` does not need to be compiled downlevel) // - this is default export with static initializers - if ((node.name || (node.flags & NodeFlags.Default && (languageVersion < ScriptTarget.ES6 - || staticProperties.length > 0))) && !thisNodeIsDecorated) { + if ((node.name || (node.flags & NodeFlags.Default && staticProperties.length > 0)) && !thisNodeIsDecorated) { write(" "); emitDeclarationName(node); }