fix(es/parser): Reject invalid object rest assignment targets#11555
fix(es/parser): Reject invalid object rest assignment targets#11555
Conversation
🦋 Changeset detectedLatest commit: 8019ac8 The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2746209633
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if !expr.is_valid_simple_assignment_target( | ||
| self.ctx().contains(Context::Strict), | ||
| ) { | ||
| self.emit_err(span, SyntaxError::NotSimpleAssign); | ||
| expr.into() |
There was a problem hiding this comment.
Keep TS1048 for object rest initializers
In the PatType::AssignElement branch for object rest reparsing, invalid targets now emit NotSimpleAssign and return expr.into() directly, which skips the existing Pat::Assign check that reports TS1048. As a result, inputs like ({...a=1}={}) are no longer diagnosed as “A rest parameter cannot have an initializer” (the behavior covered by tests/errors/rest-initializer), so this change regresses parser diagnostics for rest-initializer cases while fixing issue #11543.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Pull request overview
This PR fixes a parser bug where invalid object rest assignment targets like ({...{}} = {}) were incorrectly accepted. The parser now properly rejects non-assignable expressions used as object rest targets in assignment destructuring contexts.
Changes:
- Added validation to reject invalid object rest assignment targets (object literals, array literals, etc.)
- Reports "Cannot assign to this" error for invalid cases
- Added regression test for issue #11543
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| crates/swc_ecma_parser/src/parser/pat.rs | Added validation check for PatType::AssignElement in object rest patterns to ensure the target is a valid simple assignment target |
| crates/swc_ecma_parser/tests/errors/issue-11543/input.js | Test input with invalid object rest assignment ({...{}} = {}) |
| crates/swc_ecma_parser/tests/errors/issue-11543/input.js.swc-stderr | Expected error output showing "Cannot assign to this" error |
| .changeset/chilled-apples-impress.md | Changeset documenting the parser fix for release notes |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Binary Sizes
Commit: a11603a |
PR Review: fix(es/parser): Reject invalid object rest assignment targetsSummaryThis PR addresses issue #11543 where Code QualityGood:
Observation on Potential Issues
Test Coverage
PerformanceNo concerns. The change adds a single SecurityNo concerns. This is a parser validation tightening — it rejects previously-accepted invalid syntax. VerdictThe fix is correct, well-scoped, and consistent with existing patterns in the codebase. The main suggestion is to consider additional test cases for broader coverage of the new validation path. |
Summary
Cannot assign to thisfor cases like({...{}} = {})Testing
UPDATE=1 cargo test -p swc_ecma_parser --features verify --test errors -- --ignored issue_11543cargo test -p swc_ecma_parser --features verify --test errors -- --ignored issue_11543 arrow_function_binding_rest_property rest_not_lastFixes #11543