Skip to content

Conversation

@kdy1
Copy link
Member

@kdy1 kdy1 commented Jan 23, 2026

When a function parameter has a default value and is not used, the minifier can now optimize it away. Previously, Pat::Assign patterns were not being handled due to a TODO comment.

Fixes #9610

Generated with Claude Code

When a function parameter has a default value and is not used, the
minifier can now optimize it away. Previously, `Pat::Assign` patterns
(like `z = "hello"` in `function abc2(a, x, z = defaultMessage)`) were
not being handled due to a TODO comment.

Changes:
1. Implemented handling for `Pat::Assign` in `take_pat_if_unused`:
   - First checks if the default value has side effects using
     `may_have_side_effects` (non-mutating)
   - If no side effects, recursively checks if the left side is unused
   - If unused, removes the entire pattern

2. Added bypass for `pure_getters` check when processing `Pat::Assign`
   patterns without init expressions (function parameters)

3. Added guard in `drop_unused_param` to respect `keep_fargs` option
   for `Pat::Assign` patterns specifically

Fixes #9610

Co-authored-by: Donny/강동윤 <kdy1@users.noreply.github.com>
@kdy1 kdy1 added this to the Planned milestone Jan 23, 2026
@kdy1 kdy1 self-assigned this Jan 23, 2026
@changeset-bot
Copy link

changeset-bot bot commented Jan 23, 2026

⚠️ No Changeset found

Latest commit: 04b8c9c

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copy link
Member Author

@kdy1 kdy1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@claude I think PR requires lots of test cases verifying various input and interactions with other rules. Fix it

@claude
Copy link
Contributor

claude bot commented Jan 23, 2026

Claude finished @kdy1's task —— View job


Added Comprehensive Test Cases for Unused Parameters with Default Values

  • Read the current implementation to understand the changes
  • Read existing test cases to understand test patterns
  • Identify test scenarios for comprehensive coverage
  • Create test fixtures for various scenarios:
    • 9610-keep-fargs - Test interaction with keep_fargs: true
    • 9610-side-effects - Default values with side effects
    • 9610-arrow-functions - Arrow functions with default params
    • 9610-methods - Object and class methods
    • 9610-destructuring - Destructuring patterns with defaults
    • 9610-nested-defaults - Nested default patterns
    • 9610-mixed-params - Mixed used/unused parameters
  • Run tests to generate output files
  • Verify fixture tests pass (8/8 passed)
  • Run execution tests (2116 passed, 1 ignored)
  • Format code
  • Commit and push changes

Test Cases Added

Test Description Verifies
9610-keep-fargs keep_fargs: true preserves unused defaults Option interaction
9610-side-effects Defaults with getSideEffect() and new Date() preserved Side effect handling
9610-arrow-functions Arrow functions with unused defaults Different function types
9610-methods Object/class methods with unused defaults Method handling
9610-destructuring Object/array destructuring with defaults Destructuring patterns
9610-nested-defaults Nested destructuring with defaults Complex patterns
9610-mixed-params Mixed used/unused params with defaults Edge cases

All tests pass: 8 fixture tests + 2116 execution tests.
claude/issue-9610-20260123-0241

@github-actions
Copy link
Contributor

github-actions bot commented Jan 23, 2026

Binary Sizes

File Size
swc.linux-x64-gnu.node 28M (28665032 bytes)

Commit: a578dde

@codspeed-hq
Copy link

codspeed-hq bot commented Jan 23, 2026

CodSpeed Performance Report

Merging this PR will not alter performance

Comparing claude/issue-9610-20260123-0241 (04b8c9c) with main (81daaaa)

Summary

✅ 184 untouched benchmarks
⏩ 1 skipped benchmark1

Footnotes

  1. 1 benchmark was skipped, so the baseline result was used instead. If it was deleted from the codebase, click here and archive it to remove it from the performance reports.

…aults

Add additional test fixtures for issue #9610 covering:
- keep_fargs: true interaction
- Side effects in default values
- Arrow functions with default params
- Object and class methods
- Destructuring patterns with defaults
- Nested default patterns
- Mixed used/unused parameters

Co-authored-by: Donny/강동윤 <kdy1@users.noreply.github.com>
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.

When adding a default value to a function, compress / minify can't optimize the function.

3 participants