fix(parser): correct precedence handling for private-in expression#18169
Merged
graphite-app[bot] merged 1 commit intomainfrom Jan 18, 2026
Merged
fix(parser): correct precedence handling for private-in expression#18169graphite-app[bot] merged 1 commit intomainfrom
graphite-app[bot] merged 1 commit intomainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes incorrect parsing of private-in expressions by adding proper precedence checking. Previously, 1 + #a in b was incorrectly parsed as 1 + (#a in b) instead of the correct (1 + #a) in b.
Changes:
- Extracts private-in parsing logic into a new
parse_private_in_expressionfunction with precedence validation - Adds precedence check to reject private identifiers when the
inoperator's precedence is too low for the current context - Introduces new
unexpected_private_identifierdiagnostic for more precise error reporting
Reviewed changes
Copilot reviewed 2 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| crates/oxc_parser/src/js/expression.rs | Adds parse_private_in_expression function with precedence check and refactors existing inline logic to use it |
| crates/oxc_parser/src/diagnostics.rs | Adds new unexpected_private_identifier error diagnostic |
| tasks/coverage/snapshots/parser_babel.snap | Shows improved test conformance (1648→1649 negative tests passed) and more precise error messages |
| tasks/coverage/snapshots/parser_test262.snap | Updates error messages to be more precise, pointing to specific private identifier issues |
| tasks/coverage/snapshots/parser_typescript.snap | Correctly identifies precedence-related syntax errors in TypeScript test cases |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Merging this PR will not alter performance
Comparing Footnotes
|
52059a9 to
527fc94
Compare
Member
Author
Merge activity
|
…18169) ## Summary - Fix incorrect parsing of `1 + #a in b` which was parsed as `1 + (#a in b)` instead of `(1 + #a) in b` - Add precedence check before parsing `#a in` as `PrivateInExpression` - Report "Unexpected private identifier" error when precedence doesn't allow `in` operator ## Details The parser was greedily parsing `#a in` as a `PrivateInExpression` without checking operator precedence. For example, when parsing the RHS of `+` in `1 + #a in b`, the `in` operator's precedence (`Compare = 13`) is lower than `+`'s precedence (`Add = 15`), so `#a in` should not be parsed as a unit. The fix extracts private-in parsing into `parse_private_in_expression` and adds a check: if `lhs_precedence >= Precedence::Compare`, we reject the private identifier with a syntax error, matching V8 and Babel behavior. ## Test plan - `cargo test -p oxc_parser` passes - Conformance improved: Negative Passed 1648 → 1649 for Babel tests - `invalid-private-followed-by-in-2` test case now correctly reports syntax error 🤖 Generated with [Claude Code](https://claude.com/claude-code)
527fc94 to
2c6966d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
1 + #a in bwhich was parsed as1 + (#a in b)instead of(1 + #a) in b#a inasPrivateInExpressioninoperatorDetails
The parser was greedily parsing
#a inas aPrivateInExpressionwithout checking operator precedence. For example, when parsing the RHS of+in1 + #a in b, theinoperator's precedence (Compare = 13) is lower than+'s precedence (Add = 15), so#a inshould not be parsed as a unit.The fix extracts private-in parsing into
parse_private_in_expressionand adds a check: iflhs_precedence >= Precedence::Compare, we reject the private identifier with a syntax error, matching V8 and Babel behavior.Test plan
cargo test -p oxc_parserpassesinvalid-private-followed-by-in-2test case now correctly reports syntax error🤖 Generated with Claude Code