feat(parser): improve error message for using declarations with export#15266
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. |
There was a problem hiding this comment.
Pull Request Overview
This PR improves error messaging for exported using declarations in TypeScript/JavaScript. Instead of reporting a generic "Unexpected token" error when export using or export await using is encountered, it now provides a specific error message explaining that using declarations cannot be exported directly, along with helpful guidance on how to properly export them.
- Replaced generic "Unexpected token" errors with specific "Using declarations cannot be exported directly" error messages
- Added helpful error messages suggesting to split the export and declaration into separate statements
- Made
is_using_declaration()function public to enable reuse across modules
Reviewed Changes
Copilot reviewed 3 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
crates/oxc_parser/src/diagnostics.rs |
Added new using_declaration_cannot_be_exported diagnostic function with helpful message |
crates/oxc_parser/src/ts/statement.rs |
Added handling for export using and export await using cases to emit the new specific error |
crates/oxc_parser/src/js/statement.rs |
Changed visibility of is_using_declaration() from private to public |
tasks/coverage/snapshots/parser_typescript.snap |
Updated test snapshots with improved error messages |
tasks/coverage/snapshots/parser_babel.snap |
Updated test snapshots with improved error messages |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
CodSpeed Performance ReportMerging #15266 will not alter performanceComparing Summary
|
Merge activity
|
…rt` (#15266) Add a better error message for `export using x = something` and `export await using x = something`.
d3e8f21 to
e62d14a
Compare

Add a better error message for
export using x = somethingandexport await using x = something.