Do not add duplicate jsdoc for assignment used as a declaration's initializer #24973
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #24963
A BinaryExpression used as a declaration's initializer incorrectly gets duplicated jsdoc, which hits the assert I added to prevent such cases. The reason is that the BinaryExpression case gets hit twice: once when the node is the arrow function and the BinaryExpression is the parent, and again when the node itself is a BinaryExpression. That's because the check for assignments happens both for
node
andnode.parent
, but recurs tonode.parent
both times. The fix is to recur tonode.parent.parent
whennode.parent
is a BinaryExpression.Unfortunately, putting the
isBinaryExpression(node.parent)
check in the logical place also ends up recurring twice, albeit with no results the second time, which causes exponential search behaviour for deeply chained assignments likeexports.x = exports.y = ... = {}
. The check was previously in the logical place, but I moved it to fix that bug (#23115).I think getJSDocCommentsAndWorker needs a serious overhaul. For now I am just fixing the bug, but I think it might be possible to do something like a simple walk up the parent chain looking for applicable (for some definition of applicable) jsdoc, stopping at some point like ExpressionStatement.