@@ -7136,6 +7136,28 @@ namespace ts {
71367136 ), symbol.declarations && filter(symbol.declarations, d => isClassDeclaration(d) || isClassExpression(d))[0]), modifierFlags);
71377137 }
71387138
7139+ function getSomeTargetNameFromDeclarations(declarations: Declaration[] | undefined) {
7140+ return firstDefined(declarations, d => {
7141+ if (isImportSpecifier(d) || isExportSpecifier(d)) {
7142+ return idText(d.propertyName || d.name);
7143+ }
7144+ if (isBinaryExpression(d) || isExportAssignment(d)) {
7145+ const expression = isExportAssignment(d) ? d.expression : d.right;
7146+ if (isPropertyAccessExpression(expression)) {
7147+ return idText(expression.name);
7148+ }
7149+ }
7150+ if (isAliasSymbolDeclaration(d)) {
7151+ // This is... heuristic, at best. But it's probably better than always printing the name of the shorthand ambient module.
7152+ const name = getNameOfDeclaration(d);
7153+ if (name && isIdentifier(name)) {
7154+ return idText(name);
7155+ }
7156+ }
7157+ return undefined;
7158+ });
7159+ }
7160+
71397161 function serializeAsAlias(symbol: Symbol, localName: string, modifierFlags: ModifierFlags) {
71407162 // synthesize an alias, eg `export { symbolName as Name }`
71417163 // need to mark the alias `symbol` points at
@@ -7146,7 +7168,9 @@ namespace ts {
71467168 if (!target) {
71477169 return;
71487170 }
7149- let verbatimTargetName = unescapeLeadingUnderscores(target.escapedName);
7171+ // If `target` refers to a shorthand module symbol, the name we're trying to pull out isn;t recoverable from the target symbol
7172+ // In such a scenario, we must fall back to looking for an alias declaration on `symbol` and pulling the target name from that
7173+ let verbatimTargetName = isShorthandAmbientModuleSymbol(target) && getSomeTargetNameFromDeclarations(symbol.declarations) || unescapeLeadingUnderscores(target.escapedName);
71507174 if (verbatimTargetName === InternalSymbolName.ExportEquals && (getESModuleInterop(compilerOptions) || compilerOptions.allowSyntheticDefaultImports)) {
71517175 // target refers to an `export=` symbol that was hoisted into a synthetic default - rename here to match
71527176 verbatimTargetName = InternalSymbolName.Default;
0 commit comments