Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4406,7 +4406,7 @@ namespace ts {
type = getWidenedTypeForVariableLikeDeclaration(declaration, /*reportErrors*/ true);
}
else {
Debug.fail("Unhandled declaration kind! " + (ts as any).SyntaxKind[declaration.kind]);
Debug.fail("Unhandled declaration kind! " + Debug.showSyntaxKind(declaration));
}

if (!popTypeResolution()) {
Expand Down Expand Up @@ -20682,7 +20682,7 @@ namespace ts {
case SyntaxKind.ImportSpecifier: // https://github.com/Microsoft/TypeScript/pull/7591
return DeclarationSpaces.ExportValue;
default:
Debug.fail((ts as any).SyntaxKind[d.kind]);
Debug.fail(Debug.showSyntaxKind(d));
}
}
}
Expand Down
21 changes: 20 additions & 1 deletion src/compiler/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1466,7 +1466,7 @@ namespace ts {
if (value !== undefined && test(value)) return value;

if (value && typeof (value as any).kind === "number") {
Debug.fail(`Invalid cast. The supplied ${(ts as any).SyntaxKind[(value as any).kind]} did not pass the test '${Debug.getFunctionName(test)}'.`);
Debug.fail(`Invalid cast. The supplied ${Debug.showSyntaxKind(value as any as Node)} did not pass the test '${Debug.getFunctionName(test)}'.`);
}
else {
Debug.fail(`Invalid cast. The supplied value did not pass the test '${Debug.getFunctionName(test)}'.`);
Expand Down Expand Up @@ -2925,6 +2925,25 @@ namespace ts {
return match ? match[1] : "";
}
}

export function showSymbol(symbol: Symbol): string {
return `{ flags: ${showFlags(symbol.flags, (ts as any).SymbolFlags)}; declarations: ${map(symbol.declarations, showSyntaxKind)} }`;
}

function showFlags(flags: number, flagsEnum: { [flag: number]: string }): string {
const out = [];
for (let pow = 0; pow <= 30; pow++) {
const n = 1 << pow;
if (flags & n) {
out.push(flagsEnum[n]);
}
}
return out.join("|");
}

export function showSyntaxKind(node: Node): string {
return (ts as any).SyntaxKind[node.kind];
}
}

/** Remove an item from an array, moving everything to its right one space left. */
Expand Down
12 changes: 9 additions & 3 deletions src/services/findAllReferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -416,10 +416,16 @@ namespace ts.FindAllReferences.Core {
}

// If the symbol is declared as part of a declaration like `{ type: "a" } | { type: "b" }`, use the property on the union type to get more references.
return firstDefined(symbol.declarations, decl =>
isTypeLiteralNode(decl.parent) && isUnionTypeNode(decl.parent.parent)
return firstDefined(symbol.declarations, decl => {
if (!decl.parent) {
// Assertions for GH#21814. We should be handling SourceFile symbols in `getReferencedSymbolsForModule` instead of getting here.
Debug.assert(decl.kind === SyntaxKind.SourceFile);
Debug.fail(`Unexpected symbol at ${Debug.showSyntaxKind(node)}: ${Debug.showSymbol(symbol)}`);
}
return isTypeLiteralNode(decl.parent) && isUnionTypeNode(decl.parent.parent)
? checker.getPropertyOfType(checker.getTypeFromTypeNode(decl.parent.parent), symbol.name)
: undefined) || symbol;
: undefined;
}) || symbol;
}

/**
Expand Down
19 changes: 1 addition & 18 deletions src/services/importTracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -517,29 +517,12 @@ namespace ts.FindAllReferences {
const sym = useLhsSymbol ? checker.getSymbolAtLocation(cast(node.left, isPropertyAccessExpression).name) : symbol;
// Better detection for GH#20803
if (sym && !(checker.getMergedSymbol(sym.parent).flags & SymbolFlags.Module)) {
Debug.fail(`Special property assignment kind does not have a module as its parent. Assignment is ${showSymbol(sym)}, parent is ${showSymbol(sym.parent)}`);
Debug.fail(`Special property assignment kind does not have a module as its parent. Assignment is ${Debug.showSymbol(sym)}, parent is ${Debug.showSymbol(sym.parent)}`);
}
return sym && exportInfo(sym, kind);
}
}

function showSymbol(s: Symbol): string {
const decls = s.declarations.map(d => (ts as any).SyntaxKind[d.kind]).join(",");
const flags = showFlags(s.flags, (ts as any).SymbolFlags);
return `{ declarations: ${decls}, flags: ${flags} }`;
}

function showFlags(f: number, flags: any) {
const out = [];
for (let pow = 0; pow <= 30; pow++) {
const n = 1 << pow;
if (f & n) {
out.push(flags[n]);
}
}
return out.join("|");
}

function getImport(): ImportedSymbol | undefined {
const isImport = isNodeImport(node);
if (!isImport) return undefined;
Expand Down