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

(es/minifier): proposal of unsafe_Function_length #9919

Open
Le0Developer opened this issue Jan 22, 2025 · 1 comment
Open

(es/minifier): proposal of unsafe_Function_length #9919

Le0Developer opened this issue Jan 22, 2025 · 1 comment

Comments

@Le0Developer
Copy link

Describe the feature

The idea boils down to not preserving the .length property of a function to enable:

  • removing unused arguments from function definition
  • putting variable declarations into the function definition

This would be a unsafe option.

Examples:

// input:
function helloWorld(unused) {
    console.log("Hello, World!")
}

helloWorld();
helloWorld(); // twice so it doesnt inline

// output:
function helloWorld(o){console.log("Hello, World!")}helloWorld(),helloWorld();
//                  ^ unused variable

// could be (saves 1 byte)
function helloWorld(){console.log("Hello, World!")}helloWorld(),helloWorld();
// input:
function foo() {
    var a = console.log.bind(console)
    a("Test 1")
    a("Test 2")
}

foo()
foo()

// output:
function foo(){var o=console.log.bind(console);o("Test 1"),o("Test 2")}foo(),foo();

// could be (saves 3 bytes)
function foo(o){o=console.log.bind(console);o("Test 1"),o("Test 2")}foo(),foo();

Potentially the assignment could also be done via default values, however I am not quite sure how safe this is.
For example:

// could be (saves 2 additional bytes)
function foo(o=console.log.bind(console)){o("Test 1"),o("Test 2")}foo(),foo();

Babel plugin or link to the feature description

No response

Additional context

Playground example

@kdy1
Copy link
Member

kdy1 commented Jan 22, 2025

It seems too risky compared to the gain

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

No branches or pull requests

2 participants