diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index c43b4ed17d278..c04f6121fde29 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -18398,7 +18398,7 @@ namespace ts { // When resolved as an expression identifier, if the given node references an exported entity, return the declaration // node of the exported entity's container. Otherwise, return undefined. - function getReferencedExportContainer(node: Identifier, prefixLocals?: boolean): SourceFile | ModuleDeclaration | EnumDeclaration { + function getReferencedExportContainer(node: Identifier, prefixLocals?: boolean): SourceFile | ModuleDeclaration | EnumDeclaration | undefined { node = getParseTreeNode(node, isIdentifier); if (node) { // When resolving the export container for the name of a module or enum @@ -18420,10 +18420,11 @@ namespace ts { const parentSymbol = getParentOfSymbol(symbol); if (parentSymbol) { if (parentSymbol.flags & SymbolFlags.ValueModule && parentSymbol.valueDeclaration.kind === SyntaxKind.SourceFile) { + const symbolFile = parentSymbol.valueDeclaration; + const referenceFile = getSourceFileOfNode(node); // If `node` accesses an export and that export isn't in the same file, then symbol is a namespace export, so return undefined. - if (parentSymbol.valueDeclaration === getSourceFileOfNode(node)) { - return parentSymbol.valueDeclaration; - } + const symbolIsUmdExport = symbolFile !== referenceFile; + return symbolIsUmdExport ? undefined : symbolFile; } for (let n = node.parent; n; n = n.parent) { if (isModuleOrEnumDeclaration(n) && getSymbolOfNode(n) === parentSymbol) { @@ -18433,8 +18434,6 @@ namespace ts { } } } - - return undefined; } // When resolved as an expression identifier, if the given node references an import, return the declaration of