Skip to content

Commit 8f04f91

Browse files
authored
Add diagnostic info to getNameForExportedSymbol crash (microsoft#39790)
* Add diagnostic info to getNameForExportedSymbol crash * Add JS indicator
1 parent 79e2ed2 commit 8f04f91

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/services/utilities.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2867,11 +2867,23 @@ namespace ts {
28672867
if (symbol.escapedName === InternalSymbolName.ExportEquals || symbol.escapedName === InternalSymbolName.Default) {
28682868
// Name of "export default foo;" is "foo". Name of "export default 0" is the filename converted to camelCase.
28692869
return firstDefined(symbol.declarations, d => isExportAssignment(d) && isIdentifier(d.expression) ? d.expression.text : undefined)
2870-
|| codefix.moduleSymbolToValidIdentifier(Debug.checkDefined(symbol.parent), scriptTarget);
2870+
|| codefix.moduleSymbolToValidIdentifier(getSymbolParentOrFail(symbol), scriptTarget);
28712871
}
28722872
return symbol.name;
28732873
}
28742874

2875+
function getSymbolParentOrFail(symbol: Symbol) {
2876+
return Debug.checkDefined(
2877+
symbol.parent,
2878+
`Symbol parent was undefined. Flags: ${Debug.formatSymbolFlags(symbol.flags)}. ` +
2879+
`Declarations: ${symbol.declarations?.map(d => {
2880+
const kind = Debug.formatSyntaxKind(d.kind);
2881+
const inJS = isInJSFile(d);
2882+
const { expression } = d as any;
2883+
return (inJS ? "[JS]" : "") + kind + (expression ? ` (expression: ${Debug.formatSyntaxKind(expression.kind)})` : "");
2884+
}).join(", ")}.`);
2885+
}
2886+
28752887
/**
28762888
* Useful to check whether a string contains another string at a specific index
28772889
* without allocating another string or traversing the entire contents of the outer string.

0 commit comments

Comments
 (0)