-
-
Notifications
You must be signed in to change notification settings - Fork 724
feat(parser): improve diagnostic for unexpected optional declarations #16131
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
feat(parser): improve diagnostic for unexpected optional declarations #16131
Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
CodSpeed Performance ReportMerging #16131 will not alter performanceComparing Summary
Footnotes
|
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.
Pull request overview
This PR enhances parser diagnostics by replacing a generic "Unexpected token" error with a more specific and helpful message when encountering optional declarations (?) in variable declarations where they are not allowed. The improvement provides clear guidance to developers by explaining the issue and suggesting a fix.
- Adds a new diagnostic function
unexpected_optional_declarationwith contextual error messaging - Updates the variable declaration parser to use the improved diagnostic
- Adds helpful suggestion to remove the
?token
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| crates/oxc_parser/src/diagnostics.rs | Adds unexpected_optional_declaration function following established diagnostic patterns with clear error message and help text |
| crates/oxc_parser/src/js/declaration.rs | Updates variable declarator parsing to use the new specific diagnostic instead of generic unexpected_token |
| tasks/coverage/snapshots/parser_misc.snap | Updates test snapshots showing improved error messages for all affected test cases (oxc-2253.ts and oxc-5955-1.ts) |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Merge activity
|
…#16131) Currently we just emit "unexpected token", but we actually have a good amount of context here to provide better help + error message.
dfa63e3 to
db839ae
Compare

Currently we just emit "unexpected token", but we actually have a good amount of context here to provide better help + error message.