From 9a4b6ab6262c2fd3c0c9d0765861bb7c8a828dde Mon Sep 17 00:00:00 2001 From: Evan Sebastian Date: Sun, 22 May 2016 22:24:31 +0700 Subject: [PATCH] Detects assignment to internal module export clause, fixes #8738 --- src/compiler/emitter.ts | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index f27557a9136..2ff6ca97bfc 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -2613,6 +2613,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge return isSourceFileLevelDeclarationInSystemJsModule(targetDeclaration, /*isExported*/ true); } + function isNameOfExportedSourceLevelDeclarationInClauseModule(node: Node): boolean { + if (modulekind === ModuleKind.System || node.kind !== SyntaxKind.Identifier || nodeIsSynthesized(node)) { + return false; + } + + return !exportEquals && exportSpecifiers && hasProperty(exportSpecifiers, (node).text); + } + function emitPrefixUnaryExpression(node: PrefixUnaryExpression) { const exportChanged = (node.operator === SyntaxKind.PlusPlusToken || node.operator === SyntaxKind.MinusMinusToken) && isNameOfExportedSourceLevelDeclarationInSystemExternalModule(node.operand); @@ -2783,18 +2791,34 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge emitDestructuring(node, node.parent.kind === SyntaxKind.ExpressionStatement); } else { - const exportChanged = + const externalExportChanged = node.operatorToken.kind >= SyntaxKind.FirstAssignment && node.operatorToken.kind <= SyntaxKind.LastAssignment && isNameOfExportedSourceLevelDeclarationInSystemExternalModule(node.left); - if (exportChanged) { + if (externalExportChanged) { // emit assignment 'x y' as 'exports("x", x y)' write(`${exportFunctionForFile}("`); emitNodeWithoutSourceMap(node.left); write(`", `); } + const internalExportClauseMemberChanged = + node.operatorToken.kind >= SyntaxKind.FirstAssignment && + node.operatorToken.kind <= SyntaxKind.LastAssignment && + isNameOfExportedSourceLevelDeclarationInClauseModule(node.left); + + if (internalExportClauseMemberChanged) { + for (const specifier of exportSpecifiers[(node.left).text]) { + emitStart(specifier.name); + emitContainingModuleName(specifier); + write("."); + emitNodeWithCommentsAndWithoutSourcemap(specifier.name); + emitEnd(specifier.name); + write(" = "); + } + } + if (node.operatorToken.kind === SyntaxKind.AsteriskAsteriskToken || node.operatorToken.kind === SyntaxKind.AsteriskAsteriskEqualsToken) { // Downleveled emit exponentiation operator using Math.pow emitExponentiationOperator(node); @@ -2815,7 +2839,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge decreaseIndentIf(indentedBeforeOperator, indentedAfterOperator); } - if (exportChanged) { + if (externalExportChanged) { write(")"); } }