Skip to content

Commit d1cdf03

Browse files
committed
Correct the external module check to determine if declaration is part of export assignment
1 parent bb7f7fb commit d1cdf03

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

src/compiler/emitter.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1891,7 +1891,10 @@ module ts {
18911891
}
18921892

18931893
// If this node is in external module, check if this is export assigned
1894-
if (getContainerOfModuleElementDeclaration(node).flags & NodeFlags.ExternalModule) {
1894+
var moduleDeclaration = getContainerOfModuleElementDeclaration(node);
1895+
if ((moduleDeclaration.flags & NodeFlags.ExternalModule) || // Source file with external module flag
1896+
// Ambient external module declaration
1897+
(moduleDeclaration.kind === SyntaxKind.ModuleDeclaration && (<ModuleDeclaration>moduleDeclaration).name.kind === SyntaxKind.StringLiteral)) {
18951898
return resolver.isReferencedInExportAssignment(node);
18961899
}
18971900

@@ -2083,6 +2086,7 @@ module ts {
20832086
}
20842087

20852088
function emitVariableDeclaration(node: VariableDeclaration) {
2089+
// If we are emitting property it isnt moduleElement and doesnt need canEmitModuleElement check
20862090
if (node.kind !== SyntaxKind.VariableDeclaration || canEmitModuleElementDeclaration(node)) {
20872091
emitSourceTextOfNode(node.name);
20882092
// If optional property emit ?

src/compiler/parser.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,8 @@ module ts {
275275

276276
export function getContainerOfModuleElementDeclaration(node: Declaration) {
277277
// If the declaration is var declaration, then the parent is variable statement but we actually want the module
278-
return node.kind === SyntaxKind.VariableDeclaration ? node.parent.parent : node.parent;
278+
var container = node.kind === SyntaxKind.VariableDeclaration ? node.parent.parent : node.parent;
279+
return container.kind == SyntaxKind.ModuleBlock ? container.parent : container;
279280
}
280281

281282
enum ParsingContext {

tests/baselines/reference/missingImportAfterModuleImport.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ module.exports = MainModule;
3535

3636
//// [missingImportAfterModuleImport_0.d.ts]
3737
declare module "SubModule" {
38+
class SubModule {
39+
static StaticVar;
40+
InstanceVar;
41+
constructor ();
42+
}
3843
export = SubModule;
3944
}
4045
//// [missingImportAfterModuleImport_1.d.ts]

0 commit comments

Comments
 (0)