fix(parser): parse for (using of = ...) as using declaration#18142
fix(parser): parse for (using of = ...) as using declaration#18142graphite-app[bot] merged 1 commit intomainfrom
for (using of = ...) as using declaration#18142Conversation
Merge activity
|
There was a problem hiding this comment.
Pull request overview
This PR fixes a parser bug where for (using of = ...) was incorrectly treated as a for-of loop instead of a using declaration with of as the binding identifier. The fix uses a lookahead to check the token after of to distinguish between the two cases.
Changes:
- Modified lookahead logic in for statement parsing to handle
ofas a binding identifier in using declarations - Improved test coverage with previously failing test262 and Babel test cases now passing
Reviewed changes
Copilot reviewed 1 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| crates/oxc_parser/src/js/statement.rs | Updated lookahead logic for using declarations to check tokens after of |
| tasks/coverage/snapshots/parser_test262.snap | Improved parsing success rate with using-for-statement.js now passing |
| tasks/coverage/snapshots/parser_babel.snap | Multiple using declaration tests now parse correctly |
| tasks/coverage/snapshots/parser_typescript.snap | TypeScript using declaration test now parses correctly |
| tasks/coverage/snapshots/semantic_test262.snap | Semantic analysis passes for newly parsed test |
| tasks/coverage/snapshots/semantic_babel.snap | Semantic analysis updated for newly parsed tests |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
CodSpeed Performance ReportMerging this PR will not alter performanceComparing Summary
Footnotes
|
## Summary - Fix parsing of `for (using of = null;;)` as a using declaration where `of` is the binding identifier - Previously, the parser incorrectly treated `of` as the keyword starting a for-of loop The fix uses a lookahead to check if the token after `of` is `=`, `;`, or `:`, matching TypeScript's parser behavior. ## Test plan - `cargo coverage -- parser` - conformance tests pass - `cargo test -p oxc_parser` - unit tests pass 🤖 Generated with [Claude Code](https://claude.ai/code)
bad5823 to
c98e5b7
Compare
Summary
for (using of = null;;)as a using declaration whereofis the binding identifierofas the keyword starting a for-of loopThe fix uses a lookahead to check if the token after
ofis=,;, or:, matching TypeScript's parser behavior.Test plan
cargo coverage -- parser- conformance tests passcargo test -p oxc_parser- unit tests pass🤖 Generated with Claude Code