Skip to content

Commit 5d6710f

Browse files
committed
Avoid the double symbol for names that are explicitly exported
Fixes microsoft#33575.
1 parent bae111f commit 5d6710f

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/compiler/binder.ts

+15-2
Original file line numberDiff line numberDiff line change
@@ -567,8 +567,10 @@ namespace ts {
567567
// and this case is specially handled. Module augmentations should only be merged with original module definition
568568
// and should never be merged directly with other augmentation, and the latter case would be possible if automatic merge is allowed.
569569
if (isJSDocTypeAlias(node)) Debug.assert(isInJSFile(node)); // We shouldn't add symbols for JSDoc nodes if not in a JS file.
570-
if ((!isAmbientModule(node) && (hasExportModifier || container.flags & NodeFlags.ExportContext)) || isJSDocTypeAlias(node)) {
571-
if (!container.locals || (hasSyntacticModifier(node, ModifierFlags.Default) && !getDeclarationName(node))) {
570+
const declarationName = getDeclarationName(node);
571+
if ((!isAmbientModule(node) && (hasExportModifier || container.flags & NodeFlags.ExportContext))
572+
|| (isJSDocTypeAlias(node) && !isExported(container, declarationName))) {
573+
if (!container.locals || (hasSyntacticModifier(node, ModifierFlags.Default) && !declarationName)) {
572574
return declareSymbol(container.symbol.exports!, container.symbol, node, symbolFlags, symbolExcludes); // No local symbol for an unnamed default!
573575
}
574576
const exportKind = symbolFlags & SymbolFlags.Value ? SymbolFlags.ExportValue : 0;
@@ -583,6 +585,17 @@ namespace ts {
583585
}
584586
}
585587

588+
function isExported(container: Node, name: __String | undefined): boolean {
589+
if (!name) return false;
590+
return arrayFrom(container.symbol.exports!.values()).some(sym =>
591+
sym.declarations.some(decl => {
592+
const expSym = isExportAssignment(decl) ? decl.expression
593+
: isExportSpecifier(decl) ? decl.propertyName
594+
: undefined;
595+
return expSym && isIdentifier(expSym) && expSym.escapedText === name;
596+
}));
597+
}
598+
586599
// All container nodes are kept on a linked list in declaration order. This list is used by
587600
// the getLocalNameOfContainer function in the type checker to validate that the local name
588601
// used for a container is unique.

0 commit comments

Comments
 (0)