-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
fix(es/minifier): Handle unused parameters with default values #11494
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
base: main
Are you sure you want to change the base?
Conversation
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
left a comment
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.
@claude I think PR requires lots of test cases verifying various input and interactions with other rules. Fix it
|
Claude finished @kdy1's task —— View job Added Comprehensive Test Cases for Unused Parameters with Default Values
Test Cases Added
All tests pass: 8 fixture tests + 2116 execution tests. |
Binary Sizes
Commit: a578dde |
CodSpeed Performance ReportMerging this PR will not alter performanceComparing Summary
Footnotes
|
…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>
When a function parameter has a default value and is not used, the minifier can now optimize it away. Previously,
Pat::Assignpatterns were not being handled due to a TODO comment.Fixes #9610
Generated with Claude Code