fix(parser): replace expect_expression panic with try_into_expression…#4923
Open
tkshsbcue wants to merge 4 commits intoboa-dev:mainfrom
Open
fix(parser): replace expect_expression panic with try_into_expression…#4923tkshsbcue wants to merge 4 commits intoboa-dev:mainfrom
tkshsbcue wants to merge 4 commits intoboa-dev:mainfrom
Conversation
… error handling Made-with: Cursor
Test262 conformance changes
Tested main commit: |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4923 +/- ##
===========================================
+ Coverage 47.24% 57.97% +10.73%
===========================================
Files 476 557 +81
Lines 46892 60931 +14039
===========================================
+ Hits 22154 35325 +13171
- Misses 24738 25606 +868 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Contributor
Author
|
@nekevss i hope you can review my PR |
Made-with: Cursor
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.
fix(parser): replace expect_expression panic with try_into_expression error handling
Summary
Replaces all uses of
expect_expression()withtry_into_expression()in the parser, and removes the panickingexpect_expression()method. When the parser encounters arrow-function parameter list syntax in a context that requires an expression (e.g. conditional operatora ? b : c, call expressionfoo(), optional chaininga?.b), it now returns a recoverable parse error instead of panicking.Motivation
The
FormalParameterListOrExpressiontype represents the grammar ambiguity between(a, b)as a comma expression vs(a, b)as arrow-function parameters. In contexts like the conditional operator (x ? y : z), call expressions (f()), and optional chaining (a?.b), the left-hand side must be an expression—arrow params are invalid. Previously, call sites usedexpect_expression(), which panics with "Unexpected arrow-function arguments" when the parser produced aFormalParameterListinstead of anExpression. This can occur with edge-case input such as(a) ? 1 : 2when(a)is parsed as a single arrow param. For Boa as an embedded engine or in tooling, panics are unacceptable; the host expects a parse error. Thetry_into_expression()method already existed and returnsErr(Error::General { ... })with a helpful message ("invalid arrow-function arguments (parentheses around the arrow-function may help)"). Replacingexpect_expression()withtry_into_expression()?propagates that error instead of panicking, aligning with Boa's stability goals.Changes
lhs.expect_expression()withlhs.try_into_expression()?in conditional expression parsermember.expect_expression()withmember.try_into_expression()?in left-hand side (call expression)lhs.expect_expression()withlhs.try_into_expression()?in left-hand side (optional expression)expect_expression()method fromFormalParameterListOrExpressionto prevent future misuseTechnical Details
core/parser/src/parser/expression/assignment/conditional.rs,core/parser/src/parser/expression/left_hand_side/mod.rs,core/parser/src/parser/expression/fpl_or_exp.rsErr(Error::General { message: "invalid arrow-function arguments (parentheses around the arrow-function may help)", position }). Valid input is unchanged.Testing
cargo test -p boa_parser— all 296 tests passcargo test -p boa_engine --lib— all 921 tests passcargo clippy— no warnings