Skip to content

Do not add duplicate jsdoc for assignment used as a declaration's initializer - #24973

Merged
Nathan Shively-Sanders (sandersn) merged 1 commit into
masterfrom
fix-duplicate-jsdoc
Jun 14, 2018
Merged

Nathan Shively-Sanders (sandersn) merged 1 commit into
masterfrom
fix-duplicate-jsdoc

Conversation

@sandersn

@sandersn Nathan Shively-Sanders (sandersn) commented Jun 14, 2018 •

Copy link
Copy Markdown
Member

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 and node.parent, but recurs to node.parent both times. The fix is to recur to node.parent.parent when node.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 like exports.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.

@ghost

Copy link
Copy Markdown

Nathan Shively-Sanders (@sandersn) think you mean #24963?

@sandersn

Copy link
Copy Markdown
Member Author

Yes, #24963. I blame auto-complete :)

@sandersn

Copy link
Copy Markdown
Member Author

This should be ported to 2.9 as well.

@sandersn

Copy link
Copy Markdown
Member Author

This is in 2.9 now.

@microsoft Microsoft (microsoft) locked as resolved and limited conversation to collaborators Oct 21, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Crash in getJSDocTags on const a = b = () => 0;

1 participant