Skip to content

Don't parse duplicate JSDoc for ExpressionStatement starting with ParenthesizedExpression #36289

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 2 commits into from
Mar 12, 2020

Conversation

ajafff
Copy link
Contributor

@ajafff ajafff commented Jan 18, 2020

Fixes: #36179

Before this change the ExpressionStatement and the ParenthesizedExpression had equal JSDoc as they started at the same position. First of all this doesn't make much sense to have the same information on two different nodes. In addition this caused @typedef to be bound twice causing a Duplicate identifier error.

After this change, we skip parsing JSDoc of ExpressionStatements that start with a ParenthesizedExpression.

@sandersn
Copy link
Member

@typescript-bot user test this

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jan 22, 2020

Heya @sandersn, I've started to run the parallelized community code test suite on this PR at d8222bf. You can monitor the build here. It should now contribute to this PR's status checks.

Copy link
Member

@sandersn sandersn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why the second change is needed. It looks like node.kind would have been set correctly just afterward.

@@ -5391,7 +5391,7 @@ namespace ts {
// Avoiding having to do the lookahead for a labeled statement by just trying to parse
// out an expression, seeing if it is identifier and then seeing if it is followed by
// a colon.
const node = <ExpressionStatement | LabeledStatement>createNodeWithJSDoc(SyntaxKind.Unknown);
const node = <ExpressionStatement | LabeledStatement>createNodeWithJSDoc(token() === SyntaxKind.Identifier ? SyntaxKind.Unknown : SyntaxKind.ExpressionStatement);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What other things can token be here? Why is it that only Identifier leaves the node's kind as unknown?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is necessary so we can correctly handle ExpressionStatement inside createNodeWithJSDoc. You are right, that it would've been set later anyway, but that's too late as the JSDoc would already be attached to the ExpressionStatement node.

Identifier has a special handling here, because it's the only token that could be the start of a LabeledStatement. This change is only about ExpressionStatements starting with parentheses. Hence we can leave this as Unknown and avoid the lookahead to determine whether we are actually dealing with a LabeledStatement.

@typescript-bot
Copy link
Collaborator

The user suite test run you requested has finished and failed. I've opened a PR with the baseline diff from master.

@sandersn
Copy link
Member

User tests look fine; I think all the failures are also failures on master.

@sandersn sandersn added the For Backlog Bug PRs that fix a backlog bug label Feb 3, 2020
@sandersn sandersn merged commit 7bd6209 into microsoft:master Mar 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Backlog Bug PRs that fix a backlog bug
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Incorrect "Duplicate identifier" error in JS file when JSDoc @typedef followed by parenthetical expression
3 participants