Add diagnostic info to getNameForExportedSymbol crash (#39790)

* Add diagnostic info to getNameForExportedSymbol crash

* Add JS indicator
This commit is contained in:
Andrew Branch
2020-07-28 12:53:56 -07:00
committed by GitHub
parent 79e2ed2e77
commit 8f04f91ef5

View File

@@ -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.