@@ -238,32 +238,35 @@ export class AstSymbolTable {
238238 const isUniqueSymbol : boolean = TypeScriptHelpers . isUniqueSymbolName ( symbolName ) ;
239239
240240 // We will try to obtain the name from a declaration; otherwise we'll fall back to the symbol name.
241- // This handles cases such as "export default class X { }" where the symbol name is "default"
242- // but the declaration name is "X".
243- for ( const declaration of symbol . declarations || [ ] ) {
244- const declarationName : ts . DeclarationName | undefined = ts . getNameOfDeclaration ( declaration ) ;
241+ let unquotedName : string = symbolName ;
245242
246- if ( declarationName && ts . isIdentifier ( declarationName ) ) {
247- // It's an ordinary identifier, so the symbolName is what we want
248- break ;
243+ for ( const declaration of symbol . declarations || [ ] ) {
244+ // Handle cases such as "export default class X { }" where the symbol name is "default"
245+ // but the local name is "X".
246+ const localSymbol : ts . Symbol | undefined = TypeScriptInternals . tryGetLocalSymbol ( declaration ) ;
247+ if ( localSymbol ) {
248+ unquotedName = localSymbol . name ;
249249 }
250250
251251 // If it is a non-well-known symbol, then return the late bound name
252- if ( isUniqueSymbol && declarationName && ts . isComputedPropertyName ( declarationName ) ) {
253- const lateBoundName : string | undefined = TypeScriptHelpers . tryGetLateBoundName ( declarationName ) ;
254- if ( lateBoundName ) {
255- // Here the string may contain an expression such as "[x.y.z]". Names starting with "[" are always
256- // expressions. If a string literal contains those characters, the code below will JSON.stringify() it
257- // to avoid a collision.
258- return lateBoundName ;
252+ if ( isUniqueSymbol ) {
253+ const declarationName : ts . DeclarationName | undefined = ts . getNameOfDeclaration ( declaration ) ;
254+ if ( declarationName && ts . isComputedPropertyName ( declarationName ) ) {
255+ const lateBoundName : string | undefined = TypeScriptHelpers . tryGetLateBoundName ( declarationName ) ;
256+ if ( lateBoundName ) {
257+ // Here the string may contain an expression such as "[x.y.z]". Names starting with "[" are always
258+ // expressions. If a string literal contains those characters, the code below will JSON.stringify() it
259+ // to avoid a collision.
260+ return lateBoundName ;
261+ }
259262 }
260263 }
261264 }
262265
263266 // Otherwise that name may come from a quoted string or pseudonym like `__constructor`.
264267 // If the string is not a safe identifier, then we must add quotes.
265268 // Note that if it was quoted but did not need to be quoted, here we will remove the quotes.
266- if ( ! StringChecks . isSafeUnquotedMemberIdentifier ( symbolName ) ) {
269+ if ( ! StringChecks . isSafeUnquotedMemberIdentifier ( unquotedName ) ) {
267270 // For API Extractor's purposes, a canonical form is more appropriate than trying to reflect whatever
268271 // appeared in the source code. The code is not even guaranteed to be consistent, for example:
269272 //
@@ -272,10 +275,10 @@ export class AstSymbolTable {
272275 // public f1(x: boolean): void;
273276 // public 'f1'(x: string | boolean): void { }
274277 // }
275- return JSON . stringify ( symbolName ) ;
278+ return JSON . stringify ( unquotedName ) ;
276279 }
277280
278- return symbolName ;
281+ return unquotedName ;
279282 }
280283
281284 /**
0 commit comments