diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 01ca11ecb4b..935321338f4 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -1891,7 +1891,10 @@ module ts { } // If this node is in external module, check if this is export assigned - if (getContainerOfModuleElementDeclaration(node).flags & NodeFlags.ExternalModule) { + var moduleDeclaration = getContainerOfModuleElementDeclaration(node); + if ((moduleDeclaration.flags & NodeFlags.ExternalModule) || // Source file with external module flag + // Ambient external module declaration + (moduleDeclaration.kind === SyntaxKind.ModuleDeclaration && (moduleDeclaration).name.kind === SyntaxKind.StringLiteral)) { return resolver.isReferencedInExportAssignment(node); } @@ -2083,6 +2086,7 @@ module ts { } function emitVariableDeclaration(node: VariableDeclaration) { + // If we are emitting property it isnt moduleElement and doesnt need canEmitModuleElement check if (node.kind !== SyntaxKind.VariableDeclaration || canEmitModuleElementDeclaration(node)) { emitSourceTextOfNode(node.name); // If optional property emit ? diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 004c22a3b96..d3e942be2fe 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -275,7 +275,8 @@ module ts { export function getContainerOfModuleElementDeclaration(node: Declaration) { // If the declaration is var declaration, then the parent is variable statement but we actually want the module - return node.kind === SyntaxKind.VariableDeclaration ? node.parent.parent : node.parent; + var container = node.kind === SyntaxKind.VariableDeclaration ? node.parent.parent : node.parent; + return container.kind == SyntaxKind.ModuleBlock ? container.parent : container; } enum ParsingContext { diff --git a/tests/baselines/reference/missingImportAfterModuleImport.js b/tests/baselines/reference/missingImportAfterModuleImport.js index 665e5cdfcf8..9b7089bb161 100644 --- a/tests/baselines/reference/missingImportAfterModuleImport.js +++ b/tests/baselines/reference/missingImportAfterModuleImport.js @@ -35,6 +35,11 @@ module.exports = MainModule; //// [missingImportAfterModuleImport_0.d.ts] declare module "SubModule" { + class SubModule { + static StaticVar; + InstanceVar; + constructor (); + } export = SubModule; } //// [missingImportAfterModuleImport_1.d.ts]