-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Eliminate (ts as any).SyntaxKind (and similar) in favor of Debug.format functions #49485
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -141,7 +141,7 @@ namespace Utils { | |
const child = (node as any)[childName]; | ||
if (isNodeOrArray(child)) { | ||
assert.isFalse(childNodesAndArrays.indexOf(child) < 0, | ||
"Missing child when forEach'ing over node: " + (ts as any).SyntaxKind[node.kind] + "-" + childName); | ||
"Missing child when forEach'ing over node: " + ts.Debug.formatSyntaxKind(node.kind) + "-" + childName); | ||
} | ||
} | ||
} | ||
|
@@ -169,54 +169,15 @@ namespace Utils { | |
export function sourceFileToJSON(file: ts.Node): string { | ||
return JSON.stringify(file, (_, v) => isNodeOrArray(v) ? serializeNode(v) : v, " "); | ||
|
||
function getKindName(k: number | string): string { | ||
if (ts.isString(k)) { | ||
function getKindName(k: number | string | undefined): string | undefined { | ||
if (k === undefined || ts.isString(k)) { | ||
return k; | ||
} | ||
|
||
// For some markers in SyntaxKind, we should print its original syntax name instead of | ||
// the marker name in tests. | ||
if (k === (ts as any).SyntaxKind.FirstJSDocNode || | ||
k === (ts as any).SyntaxKind.LastJSDocNode || | ||
k === (ts as any).SyntaxKind.FirstJSDocTagNode || | ||
k === (ts as any).SyntaxKind.LastJSDocTagNode) { | ||
for (const kindName in (ts as any).SyntaxKind) { | ||
if ((ts as any).SyntaxKind[kindName] === k) { | ||
return kindName; | ||
} | ||
} | ||
} | ||
Comment on lines
-179
to
-188
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using I still think it's better to not write the same enum-member-to-string code more than once, but it's annoying that a perf fix is required to do it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. #49487 recovers the performance; it's 25% of the test run :( |
||
|
||
return (ts as any).SyntaxKind[k]; | ||
} | ||
|
||
function getFlagName(flags: any, f: number): any { | ||
if (f === 0) { | ||
return 0; | ||
} | ||
|
||
let result = ""; | ||
ts.forEach(Object.getOwnPropertyNames(flags), (v: any) => { | ||
if (isFinite(v)) { | ||
v = +v; | ||
if (f === +v) { | ||
result = flags[v]; | ||
return true; | ||
} | ||
else if ((f & v) > 0) { | ||
if (result.length) { | ||
result += " | "; | ||
} | ||
result += flags[v]; | ||
return false; | ||
} | ||
} | ||
}); | ||
return result; | ||
return ts.Debug.formatSyntaxKind(k); | ||
} | ||
|
||
function getNodeFlagName(f: number) { | ||
return getFlagName((ts as any).NodeFlags, f); | ||
return ts.Debug.formatNodeFlags(f); | ||
} | ||
|
||
function serializeNode(n: ts.Node): any { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've moved this up here because our debug helpers choose the earliest name as the printed name. It was previously defined with the markers, which meant we printed out the deprecated form instead.