Skip to content

Commit

Permalink
Handle non-preserved const enums in debug messages (#21945)
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy authored Feb 15, 2018
1 parent 8518343 commit 1b6aa13
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/compiler/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2927,7 +2927,8 @@ namespace ts {
}

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

function showFlags(flags: number, flagsEnum: { [flag: number]: string }): string {
Expand All @@ -2942,7 +2943,8 @@ namespace ts {
}

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

Expand Down
2 changes: 1 addition & 1 deletion src/services/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ namespace ts {
const textPos = scanner.getTextPos();
if (textPos <= end) {
if (token === SyntaxKind.Identifier) {
Debug.fail(`Did not expect ${(ts as any).SyntaxKind[this.kind]} to have an Identifier in its trivia`);
Debug.fail(`Did not expect ${Debug.showSyntaxKind(this)} to have an Identifier in its trivia`);
}
nodes.push(createNode(token, pos, textPos, this));
}
Expand Down

0 comments on commit 1b6aa13

Please sign in to comment.