Skip to content

Conversation

@magic-akari
Copy link
Member

@changeset-bot
Copy link

changeset-bot bot commented Dec 4, 2025

🦋 Changeset detected

Latest 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

@github-actions
Copy link
Contributor

github-actions bot commented Dec 4, 2025

Binary Sizes

File Size
swc.linux-x64-gnu.node 31M (31824200 bytes)

Commit: f006884

@codspeed-hq
Copy link

codspeed-hq bot commented Dec 4, 2025

CodSpeed Performance Report

Merging #11352 will not alter performance

Comparing magic-akari:fix/issue-9198 (beb5e14) with main (2ebb261)1

Summary

✅ 138 untouched

Footnotes

  1. No successful run was found on main (e4cdc47) during the generation of this report, so 2ebb261 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@magic-akari magic-akari marked this pull request as ready for review December 4, 2025 12:21
@magic-akari magic-akari requested a review from a team as a code owner December 4, 2025 12:21
Copilot AI review requested due to automatic review settings December 4, 2025 12:21
Copilot finished reviewing on behalf of magic-akari December 4, 2025 12:25
Copy link
Contributor

Copilot AI left a 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 ParamCollector for collecting and transforming parameters with object rest patterns
  • Changed temporary variable naming from _param to indexed names like _0, _1, etc.
  • Changed generated variable declarations from var to let for 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.

@magic-akari magic-akari marked this pull request as draft December 4, 2025 13:00
@magic-akari
Copy link
Member Author

@kdy1, I've identified a destructuring evaluation order bug introduced by #11337. Please hold off on publishing a new swc release until this PR is merged.

@magic-akari magic-akari requested a review from Copilot December 5, 2025 04:31
Copilot finished reviewing on behalf of magic-akari December 5, 2025 04:33
Copy link
Contributor

Copilot AI left a 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.

Copy link
Contributor

Copilot AI left a 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.

@magic-akari magic-akari marked this pull request as ready for review December 5, 2025 05:48
Copilot AI review requested due to automatic review settings December 5, 2025 05:48
Copilot finished reviewing on behalf of magic-akari December 5, 2025 05:51
Copy link
Contributor

Copilot AI left a 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.

Comment on lines +991 to +1006
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());
}
Copy link

Copilot AI Dec 5, 2025

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.

Copilot uses AI. Check for mistakes.
Comment on lines +345 to +346
// 2. Visit pattern
declarator.name.visit_mut_with(self);
Copy link

Copilot AI Dec 5, 2025

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.

Copilot uses AI. Check for mistakes.
@kdy1 kdy1 requested a review from a team as a code owner December 5, 2025 10:10
@kdy1 kdy1 merged commit 2ebb261 into swc-project:main Dec 5, 2025
23 checks passed
@kdy1 kdy1 added this to the Planned milestone Dec 5, 2025
@kdy1
Copy link
Member

kdy1 commented Dec 5, 2025

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Function parameter's default value incorrectly captures other destructured parameter using spread operator

2 participants