Skip to content

Commit 0e46086

Browse files
author
Andy
authored
In getSpecialPropertyExport, add debug failure when symbol parent is not a module (#21347)
* In getSpecialPropertyExport, add debug failure when symbol parent is not a module * Fix lint
1 parent dbcfcc0 commit 0e46086

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/services/importTracker.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,11 +510,32 @@ namespace ts.FindAllReferences {
510510
return undefined;
511511
}
512512

513-
const sym = useLhsSymbol ? checker.getSymbolAtLocation((node.left as ts.PropertyAccessExpression).name) : symbol;
513+
const sym = useLhsSymbol ? checker.getSymbolAtLocation(cast(node.left, isPropertyAccessExpression).name) : symbol;
514+
// Better detection for GH#20803
515+
if (sym && !(checker.getMergedSymbol(sym.parent).flags & SymbolFlags.Module)) {
516+
Debug.fail(`Special property assignment kind does not have a module as its parent. Assignment is ${showSymbol(sym)}, parent is ${showSymbol(sym.parent)}`);
517+
}
514518
return sym && exportInfo(sym, kind);
515519
}
516520
}
517521

522+
function showSymbol(s: Symbol): string {
523+
const decls = s.declarations.map(d => (ts as any).SyntaxKind[d.kind]).join(",");
524+
const flags = showFlags(s.flags, (ts as any).SymbolFlags);
525+
return `{ declarations: ${decls}, flags: ${flags} }`;
526+
}
527+
528+
function showFlags(f: number, flags: any) {
529+
const out = [];
530+
for (let pow = 0; pow <= 30; pow++) {
531+
const n = 1 << pow;
532+
if (f & n) {
533+
out.push(flags[n]);
534+
}
535+
}
536+
return out.join("|");
537+
}
538+
518539
function getImport(): ImportedSymbol | undefined {
519540
const isImport = isNodeImport(node);
520541
if (!isImport) return undefined;

0 commit comments

Comments
 (0)