From a9be53093c9de71ebb857a0469a97bac59855d87 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Mon, 23 Nov 2015 12:55:29 -0800 Subject: [PATCH] change enum emit --- src/compiler/emitter.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 83d3e24351e..f31885dcd03 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -6206,9 +6206,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi if (!shouldHoistDeclarationInSystemJsModule(node)) { // do not emit var if variable was already hoisted - if (!(node.flags & NodeFlags.Export) || isES6ExportedDeclaration(node)) { + + const isES6ExportedEnum = isES6ExportedDeclaration(node); + if (!(node.flags & NodeFlags.Export) || (isES6ExportedEnum && isFirstDeclarationOfKind(node, node.symbol && node.symbol.declarations, SyntaxKind.ModuleDeclaration))) { emitStart(node); - if (isES6ExportedDeclaration(node)) { + if (isES6ExportedEnum) { write("export "); } write("var "); @@ -6307,6 +6309,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi return languageVersion === ScriptTarget.ES6 && !!(resolver.getNodeCheckFlags(node) & NodeCheckFlags.LexicalModuleMergesWithClass); } + function isFirstDeclarationOfKind(node: Declaration, declarations: Declaration[], kind: SyntaxKind) { + return !forEach(declarations, declaration => declaration.kind === kind && declaration.pos < node.pos); + } + function emitModuleDeclaration(node: ModuleDeclaration) { // Emit only if this module is non-ambient. const shouldEmit = shouldEmitModuleDeclaration(node); @@ -6319,7 +6325,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi if (emitVarForModule) { const isES6ExportedNamespace = isES6ExportedDeclaration(node); - if ((!isES6ExportedNamespace) || !forEach(node.symbol && node.symbol.declarations, declaration => declaration.kind === SyntaxKind.ModuleDeclaration && declaration.pos < node.pos)) { + if ((!isES6ExportedNamespace) || isFirstDeclarationOfKind(node, node.symbol && node.symbol.declarations, SyntaxKind.ModuleDeclaration)) { emitStart(node); if (isES6ExportedNamespace) { write("export ");