-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Don't parse duplicate JSDoc for ExpressionStatement starting with ParenthesizedExpression #36289
Conversation
@typescript-bot user test this |
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.
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); |
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.
What other things can token be here? Why is it that only Identifier
leaves the node's kind as unknown?
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.
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 ExpressionStatement
s starting with parentheses. Hence we can leave this as Unknown
and avoid the lookahead to determine whether we are actually dealing with a LabeledStatement
.
The user suite test run you requested has finished and failed. I've opened a PR with the baseline diff from master. |
User tests look fine; I think all the failures are also failures on master. |
Fixes: #36179
Before this change the
ExpressionStatement
and theParenthesizedExpression
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 aDuplicate identifier
error.After this change, we skip parsing JSDoc of ExpressionStatements that start with a ParenthesizedExpression.