From 8c80792fe24be2df99ba5313f4b3665b05d4b046 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Sat, 11 Apr 2015 04:58:39 -0700 Subject: [PATCH] emit publish of exported values in destructuring --- src/compiler/emitter.ts | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 0fe6ec3697f..fcac5c9c2df 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -2588,14 +2588,35 @@ var __param = this.__param || function(index, decorator) { return function (targ } renameNonTopLevelLetAndConst(name); - if (name.parent && (name.parent.kind === SyntaxKind.VariableDeclaration || name.parent.kind === SyntaxKind.BindingElement)) { + + const isVariableDeclarationOrBindingElement = + name.parent && (name.parent.kind === SyntaxKind.VariableDeclaration || name.parent.kind === SyntaxKind.BindingElement); + + let emitPublishOfExportedValue = false; + if (currentFileIsEmittedAsSystemModule() && !nodeIsSynthesized(name)) { + let nodeToCheck = isVariableDeclarationOrBindingElement ? name.parent : resolver.getReferencedValueDeclaration(name); + emitPublishOfExportedValue = nodeToCheck && (getCombinedNodeFlags(nodeToCheck) & NodeFlags.Export) && isSourceFileLevelDeclaration(nodeToCheck); + } + + if (emitPublishOfExportedValue) { + write(`${exportFunctionForFile}("`); + emitNodeWithoutSourceMap(name); + write(`", `); + } + + if (isVariableDeclarationOrBindingElement) { emitModuleMemberName(name.parent); } else { emit(name); } + write(" = "); emit(value); + + if (emitPublishOfExportedValue) { + write(")"); + } } function ensureIdentifier(expr: Expression): Expression {