From 8f04f91ef55cd7e75acc8167abe2dcc429729af8 Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Tue, 28 Jul 2020 12:53:56 -0700 Subject: [PATCH] Add diagnostic info to getNameForExportedSymbol crash (#39790) * Add diagnostic info to getNameForExportedSymbol crash * Add JS indicator --- src/services/utilities.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/services/utilities.ts b/src/services/utilities.ts index b3a09b1e555..c11c65d076d 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -2867,11 +2867,23 @@ namespace ts { if (symbol.escapedName === InternalSymbolName.ExportEquals || symbol.escapedName === InternalSymbolName.Default) { // Name of "export default foo;" is "foo". Name of "export default 0" is the filename converted to camelCase. return firstDefined(symbol.declarations, d => isExportAssignment(d) && isIdentifier(d.expression) ? d.expression.text : undefined) - || codefix.moduleSymbolToValidIdentifier(Debug.checkDefined(symbol.parent), scriptTarget); + || codefix.moduleSymbolToValidIdentifier(getSymbolParentOrFail(symbol), scriptTarget); } return symbol.name; } + function getSymbolParentOrFail(symbol: Symbol) { + return Debug.checkDefined( + symbol.parent, + `Symbol parent was undefined. Flags: ${Debug.formatSymbolFlags(symbol.flags)}. ` + + `Declarations: ${symbol.declarations?.map(d => { + const kind = Debug.formatSyntaxKind(d.kind); + const inJS = isInJSFile(d); + const { expression } = d as any; + return (inJS ? "[JS]" : "") + kind + (expression ? ` (expression: ${Debug.formatSyntaxKind(expression.kind)})` : ""); + }).join(", ")}.`); + } + /** * Useful to check whether a string contains another string at a specific index * without allocating another string or traversing the entire contents of the outer string.