@@ -7136,6 +7136,28 @@ namespace ts {
7136
7136
), symbol.declarations && filter(symbol.declarations, d => isClassDeclaration(d) || isClassExpression(d))[0]), modifierFlags);
7137
7137
}
7138
7138
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
+
7139
7161
function serializeAsAlias(symbol: Symbol, localName: string, modifierFlags: ModifierFlags) {
7140
7162
// synthesize an alias, eg `export { symbolName as Name }`
7141
7163
// need to mark the alias `symbol` points at
@@ -7146,7 +7168,9 @@ namespace ts {
7146
7168
if (!target) {
7147
7169
return;
7148
7170
}
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);
7150
7174
if (verbatimTargetName === InternalSymbolName.ExportEquals && (getESModuleInterop(compilerOptions) || compilerOptions.allowSyntheticDefaultImports)) {
7151
7175
// target refers to an `export=` symbol that was hoisted into a synthetic default - rename here to match
7152
7176
verbatimTargetName = InternalSymbolName.Default;
0 commit comments