Skip to content

Commit a9be530

Browse files
committed
change enum emit
1 parent 6023434 commit a9be530

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

src/compiler/emitter.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6206,9 +6206,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
62066206

62076207
if (!shouldHoistDeclarationInSystemJsModule(node)) {
62086208
// do not emit var if variable was already hoisted
6209-
if (!(node.flags & NodeFlags.Export) || isES6ExportedDeclaration(node)) {
6209+
6210+
const isES6ExportedEnum = isES6ExportedDeclaration(node);
6211+
if (!(node.flags & NodeFlags.Export) || (isES6ExportedEnum && isFirstDeclarationOfKind(node, node.symbol && node.symbol.declarations, SyntaxKind.ModuleDeclaration))) {
62106212
emitStart(node);
6211-
if (isES6ExportedDeclaration(node)) {
6213+
if (isES6ExportedEnum) {
62126214
write("export ");
62136215
}
62146216
write("var ");
@@ -6307,6 +6309,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
63076309
return languageVersion === ScriptTarget.ES6 && !!(resolver.getNodeCheckFlags(node) & NodeCheckFlags.LexicalModuleMergesWithClass);
63086310
}
63096311

6312+
function isFirstDeclarationOfKind(node: Declaration, declarations: Declaration[], kind: SyntaxKind) {
6313+
return !forEach(declarations, declaration => declaration.kind === kind && declaration.pos < node.pos);
6314+
}
6315+
63106316
function emitModuleDeclaration(node: ModuleDeclaration) {
63116317
// Emit only if this module is non-ambient.
63126318
const shouldEmit = shouldEmitModuleDeclaration(node);
@@ -6319,7 +6325,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
63196325

63206326
if (emitVarForModule) {
63216327
const isES6ExportedNamespace = isES6ExportedDeclaration(node);
6322-
if ((!isES6ExportedNamespace) || !forEach(node.symbol && node.symbol.declarations, declaration => declaration.kind === SyntaxKind.ModuleDeclaration && declaration.pos < node.pos)) {
6328+
if ((!isES6ExportedNamespace) || isFirstDeclarationOfKind(node, node.symbol && node.symbol.declarations, SyntaxKind.ModuleDeclaration)) {
63236329
emitStart(node);
63246330
if (isES6ExportedNamespace) {
63256331
write("export ");

0 commit comments

Comments
 (0)