From 521a0a160c36eba85875817efb274c94dac58b87 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Thu, 12 Nov 2015 19:03:52 -0800 Subject: [PATCH] Fix class exports with varrying module emits while targeting es6 --- src/compiler/emitter.ts | 47 ++++++++++++++++++----------------------- 1 file changed, 20 insertions(+), 27 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index ab9fe35b92..323a5680cc 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -5581,7 +5581,26 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi } // If this is an exported class, but not on the top level (i.e. on an internal // module), export it - if (node.parent.kind !== SyntaxKind.SourceFile) { + if (node.parent.kind === SyntaxKind.SourceFile && (node.flags & NodeFlags.Default)) { + // if this is a top level default export of decorated class, write the export after the declaration. + writeLine(); + if (thisNodeIsDecorated && modulekind === ModuleKind.ES6) { + write("export default "); + emitDeclarationName(node); + write(";"); + } + else if (modulekind === ModuleKind.System) { + write(`${exportFunctionForFile}("default", `); + emitDeclarationName(node); + write(");"); + } + else if (modulekind !== ModuleKind.ES6) { + write(`exports.default = `); + emitDeclarationName(node); + write(";"); + } + } + else if (node.parent.kind !== SyntaxKind.SourceFile || (modulekind !== ModuleKind.ES6 && !(node.flags & NodeFlags.Default))) { writeLine(); emitStart(node); emitModuleMemberName(node); @@ -5590,32 +5609,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi emitEnd(node); write(";"); } - else if (node.parent.kind === SyntaxKind.SourceFile && (node.flags & NodeFlags.Default) && thisNodeIsDecorated) { - // if this is a top level default export of decorated class, write the export after the declaration. - if (modulekind === ModuleKind.ES6) { - writeLine(); - write("export default "); - emitDeclarationName(node); - write(";"); - } - else if (modulekind === ModuleKind.System) { - writeLine(); - write(`${exportFunctionForFile}("default", `); - emitDeclarationName(node); - write(");"); - } - else { - writeLine(); - if (languageVersion === ScriptTarget.ES3) { - write(`exports["default"] = `); - } - else { - write(`exports.default = `); - } - emitDeclarationName(node); - write(";"); - } - } } function emitClassLikeDeclarationBelowES6(node: ClassLikeDeclaration) {