Skip to content

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

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

Merged
merged 1 commit into from
Jun 14, 2018

Conversation

sandersn
Copy link
Member

@sandersn sandersn commented Jun 14, 2018

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.

@sandersn sandersn requested a review from a user June 14, 2018 22:11
@ghost
Copy link

ghost commented Jun 14, 2018

@sandersn think you mean #24963?

@sandersn
Copy link
Member Author

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

@sandersn sandersn merged commit 4db1c13 into master Jun 14, 2018
@sandersn sandersn deleted the fix-duplicate-jsdoc branch June 14, 2018 22:32
@sandersn
Copy link
Member Author

This should be ported to 2.9 as well.

@sandersn
Copy link
Member Author

This is in 2.9 now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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