Skip to content

fix(29648): Error message related to JSDoc for non-JSDoc syntax error#50793

Merged
sandersn merged 11 commits into
microsoft:mainfrom
a-tarasyuk:fix/29648
Dec 30, 2022
Merged

fix(29648): Error message related to JSDoc for non-JSDoc syntax error#50793
sandersn merged 11 commits into
microsoft:mainfrom
a-tarasyuk:fix/29648

Conversation

@a-tarasyuk

Copy link
Copy Markdown
Contributor

Fixes #29648

@DanielRosenwasser @RyanCavanaugh At what stage is it better to handle such errors? At the parser or checker stage?

@typescript-bot typescript-bot added the For Backlog Bug PRs that fix a backlog bug label Sep 15, 2022
Comment thread tests/baselines/reference/decoratorMetadata-jsdoc.errors.txt Outdated
@DanielRosenwasser

Copy link
Copy Markdown
Member

I think that as long as you don't have a complex check, it's generally better to put the error in the parser itself. The caveat is that the parser error should gracefully recover.

@a-tarasyuk a-tarasyuk marked this pull request as ready for review September 20, 2022 13:50

@sandersn sandersn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I've only looked at the tests so far.

Comment thread tests/cases/fourslash/codeFixChangeJSDocSyntax5.ts Outdated
Comment thread tests/cases/fourslash/codeFixChangeJSDocSyntax15.ts
Comment thread tests/cases/fourslash/codeFixChangeJSDocSyntax14.ts
Comment thread tests/cases/conformance/types/tuple/restTupleElements1.ts Outdated
Comment thread tests/baselines/reference/parseInvalidNullableTypes.types Outdated
Comment thread tests/baselines/reference/parseInvalidNullableTypes.types
Comment thread tests/baselines/reference/parseInvalidNullableTypes.errors.txt Outdated
Comment thread tests/baselines/reference/parseInvalidNonNullableTypes.errors.txt
@a-tarasyuk a-tarasyuk marked this pull request as draft October 5, 2022 21:07
@a-tarasyuk a-tarasyuk marked this pull request as ready for review October 6, 2022 09:10
@sandersn sandersn self-assigned this Oct 18, 2022
@a-tarasyuk a-tarasyuk requested review from DanielRosenwasser and sandersn and removed request for DanielRosenwasser October 27, 2022 18:11
Comment thread src/compiler/diagnosticMessages.json Outdated
Comment thread src/compiler/diagnosticMessages.json Outdated
Comment thread src/compiler/parser.ts Outdated
}

function isInvalidConditionalType() {
if (token() === SyntaxKind.QuestionToken && !(contextFlags & NodeFlags.JavaScriptFile)) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is going to incur a lot of speculative parsing, isn't it? Specifically, every conditional type is going to speculatively parseType. Then it'll fail and proceed with normal parsing, which will parseType in the exact same location.
It might be possible to salvage either by (1) stopping the speculation before parseType or (2) making the speculative parse succeed when the type is conditional, and return some parsed portion of the conditional type node. (1) is likely to be lossy, but maybe not as much as dropping the speculation entirely. (2) would require passing the conditional part of the type down into parseType.

If those are too complex, I don't think it's worthwhile -- I reverted this change and it only breaks when the token following ? could be the start of a type: { -- but , and ) are fine. Improving some of the errors is good enough in my opinion.

(Reverting this will require splitting the nullable type test into two parts because syntax errors block semantic errors.)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

? could be the start of a type: {

Yes, this is only related to {, as it can be the start of a block or the start of a type. I've removed this speculative parsing, and updated test.

@a-tarasyuk a-tarasyuk marked this pull request as draft December 21, 2022 19:40
@a-tarasyuk a-tarasyuk marked this pull request as ready for review December 21, 2022 19:58
@a-tarasyuk a-tarasyuk requested a review from sandersn December 21, 2022 20:28
@sandersn sandersn merged commit 44152bc into microsoft:main Dec 30, 2022
@microsoft microsoft locked as resolved and limited conversation to collaborators Oct 22, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

For Backlog Bug PRs that fix a backlog bug

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Error message related to JSDoc for non-JSDoc syntax error

4 participants