-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Fix very slow jsdoc search in chained special assignments #23115
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
Conversation
@@ -1807,7 +1807,6 @@ namespace ts { | |||
if (parent && |
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.
Instead of checking if parent
is defined over and over again, maybe you should bail out if parent
isn't defined?
That might be an improvement. I think it’s likely to lead to deep nesting. And the current order is reflected in the output order of discovered jsdoc tags, so changing it might change the resolution when conflicting tags occur.
I’ll try it, but I’ll put it in a separate, non-bug fix PR if it’s an improvement.
|
@DanielRosenwasser here's what I got from de-duping the repeated parent checks. If you like it I can put it in a separate PR after this one: if (parent) {
if(parent.kind === SyntaxKind.PropertyAssignment ||
parent.kind === SyntaxKind.PropertyDeclaration ||
getNestedModuleDeclaration(parent) ||
isBinaryExpression(node) && getSpecialPropertyAssignmentKind(node) ||
isBinaryExpression(parent) && getSpecialPropertyAssignmentKind(parent) ||
node.kind === SyntaxKind.PropertyAccessExpression && parent.kind === SyntaxKind.ExpressionStatement) {
getJSDocCommentsAndTagsWorker(parent);
}
if (parent.parent) {
// Try to recognize this pattern when node is initializer of variable declaration and JSDoc comments are on containing variable statement.
// /**
// * @param {number} name
// * @returns {number}
// */
// var x = function(name) { return name.length; }
if (getSingleVariableOfVariableStatement(parent.parent) === node || getSourceOfAssignment(parent.parent)) {
getJSDocCommentsAndTagsWorker(parent.parent);
}
if (parent.parent.parent) {
if (getSingleInitializerOfVariableStatementOrPropertyDeclaration(parent.parent.parent) === node || getSourceOfDefaultedAssignment(parent.parent.parent)) {
getJSDocCommentsAndTagsWorker(parent.parent.parent);
}
}
}
} Note that I removed the initial indent that comes from context, so the lines are actually longer than this in the editor. |
@sandersn Since this always ends in a call to |
@Andy-MS I tried this -- is it what you were proposing? function getJSDocCommentsAndTagsHost(node: Node) {
return node.parent
? node.parent.parent
? node.parent.parent.parent ? node.parent.parent.parent : node.parent.parent
: node.parent
: undefined;
}
function getJSDocCommentsAndTagsWorker(node: Node): void {
const host = getJSDocCommentsAndTagsHost(node);
if (host &&
(host.kind === SyntaxKind.PropertyAssignment ||
host.kind === SyntaxKind.PropertyDeclaration ||
getNestedModuleDeclaration(host) ||
getSingleVariableOfVariableStatement(host) === node ||
getSourceOfAssignment(host) ||
getSingleInitializerOfVariableStatementOrPropertyDeclaration(host) === node ||
getSourceOfDefaultedAssignment(host) ||
isBinaryExpression(node) && getSpecialPropertyAssignmentKind(node) !== SpecialPropertyAssignmentKind.None ||
isBinaryExpression(host) && getSpecialPropertyAssignmentKind(host) !== SpecialPropertyAssignmentKind.None ||
node.kind === SyntaxKind.PropertyAccessExpression && host.kind === SyntaxKind.ExpressionStatement)) {
getJSDocCommentsAndTagsWorker(host);
}
// ...... This doesn't work as-is, but might be close. |
Working on it. |
Never mind, the function needs to recurse on itself up to three times, my suggesstion would only work if it only needed to recurse once. |
Fixes #23111
The fix is to only recur once per parent instead of twice. This means moving the chained-assignment check in a slightly less obvious place.