Skip to content
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

feat(es/minifier): Drop redundant function parameters #9636

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

levi-nz
Copy link
Contributor

@levi-nz levi-nz commented Oct 12, 2024

Description:
Trailing parameters in functions/arrow expressions can be dropped if they're not referenced inside the function body without introducing side effects. e.g. function f(a, b, c) {f(a);} -> function f(a) {f(a);}.

This simply iterates (reverse) through the parameters and once it encounters a parameter that is used, it stops and drops the ones it found. If no referenced parameters are found then all parameters can be dropped.

BREAKING CHANGE:

Related issue (if exists):

@levi-nz levi-nz requested a review from a team as a code owner October 12, 2024 06:27
Copy link

changeset-bot bot commented Oct 12, 2024

⚠️ No Changeset found

Latest commit: 35f8e22

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

@levi-nz levi-nz requested a review from a team as a code owner October 12, 2024 06:37
@levi-nz
Copy link
Contributor Author

levi-nz commented Oct 12, 2024

This might break TypeScript interfaces, will have to test

@levi-nz levi-nz marked this pull request as draft October 12, 2024 07:42
Copy link

codspeed-hq bot commented Oct 12, 2024

CodSpeed Performance Report

Merging #9636 will not alter performance

Comparing levi-nz:optimize-function-parameters (35f8e22) with main (f2be26e)

Summary

✅ 194 untouched benchmarks

Copy link
Member

@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.

I think this should check for option about function.length

@levi-nz
Copy link
Contributor Author

levi-nz commented Oct 14, 2024

I think this should check for option about function.length

I think this should be a config option if that's what you're referring to, but I'm not sure what you're referring to regarding function.length

@magic-akari
Copy link
Member

I think this should check for option about function.length

I think this should be a config option if that's what you're referring to, but I'm not sure what you're referring to regarding function.length

It's the keep_fargs option in Terser.

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.

3 participants