-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
fix(es/compat): Fix parameter default value evaluation order with object rest #11352
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
🦋 Changeset detectedLatest commit: beb5e14 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 |
Binary Sizes
Commit: f006884 |
CodSpeed Performance ReportMerging #11352 will not alter performanceComparing Summary
Footnotes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes parameter default value evaluation order issues when using object rest patterns in function parameters (addresses #9198). The implementation introduces a new ParamCollector struct that transforms complex parameter patterns into simpler temporary parameters, then destructures them in the function body using array destructuring to preserve proper evaluation order.
Key changes:
- Refactored parameter handling to use
ParamCollectorfor collecting and transforming parameters with object rest patterns - Changed temporary variable naming from
_paramto indexed names like_0,_1, etc. - Changed generated variable declarations from
vartoletfor better scoping semantics
Reviewed changes
Copilot reviewed 48 out of 48 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| crates/swc_ecma_compat_es2018/src/object_rest.rs | Core refactoring: added ParamCollector struct and rewrote visit_mut_function, visit_mut_arrow_expr, and visit_mut_constructor to use the new parameter collection approach |
| Multiple test output files | Updated expected outputs reflecting the new transformation strategy with indexed parameter names and let declarations |
| crates/swc/tests/fixture/issues-9xxx/9198/* | New test cases specifically for issue #9198 demonstrating the fix for parameter evaluation order |
| crates/swc/tests/tsc-references/*.js | Updated TypeScript compiler reference outputs to match the new transformation patterns |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
crates/swc/tests/tsc-references/objectRestParameterES5.2.minified.js
Outdated
Show resolved
Hide resolved
crates/swc/tests/tsc-references/objectRestParameterES5.1.normal.js
Outdated
Show resolved
Hide resolved
crates/swc/tests/tsc-references/objectRestParameter.2.minified.js
Outdated
Show resolved
Hide resolved
crates/swc/tests/tsc-references/objectRestParameter.1.normal.js
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 56 out of 56 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
a0c61aa to
fb9aa12
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 56 out of 56 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 56 out of 56 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| let original_pat = match pat { | ||
| Pat::Rest(rest_pat) => mem::replace(&mut *rest_pat.arg, temp.clone().into()), | ||
| Pat::Assign(pat) => { | ||
| let init = AssignPat { | ||
| span: DUMMY_SP, | ||
| left: Box::new(temp.clone().into()), | ||
| right: Expr::undefined(DUMMY_SP), | ||
| }; | ||
| mem::replace(pat, init).into() | ||
| } | ||
| pat => mem::replace(pat, temp.clone().into()), | ||
| }; | ||
|
|
||
| self.collected_pats.push(original_pat); | ||
| self.temp_exprs.push(temp.as_arg()); | ||
| } |
Copilot
AI
Dec 5, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When collecting rest parameters (e.g., ...args), the temp variable is added as a regular array element instead of being spread. For example, in function x1(a, b = a, { c, ...d }, ...{ e }), the generated code uses [_1, _2, _3] but it should be [_1, _2, ..._3] to properly spread the rest parameter.
The issue is in line 1005 where temp.as_arg() is used. For rest parameters, we need to use a spread element instead of a regular argument.
| // 2. Visit pattern | ||
| declarator.name.visit_mut_with(self); |
Copilot
AI
Dec 5, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The comment says "Visit pattern" but this happens after the init has been visited and before the pattern is processed by the lowering logic. This could lead to confusion about when pattern transformations happen. Consider clarifying that this visits any nested patterns within the declarator name, or move this comment to be more specific about what it's doing.
|
Thanks! |
Description:
BREAKING CHANGE:
Related issue (if exists):