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

enhance booleans #5365

Merged
merged 1 commit into from Feb 21, 2022
Merged

enhance booleans #5365

merged 1 commit into from Feb 21, 2022

Conversation

alexlamsl
Copy link
Collaborator

No description provided.

@alexlamsl alexlamsl merged commit dd3b81d into mishoo:master Feb 21, 2022
@alexlamsl alexlamsl deleted the booleans branch February 21, 2022 03:02
@alexlamsl
Copy link
Collaborator Author

@kzc uglify-js has come a long way − I've found an old TODO (back when fromString: true was a thing):

function foo(x) {
    if (x) {
        return bar(1);
        var a = not_called(1);
    } else {
        return bar(2);
        var b = not_called(2);
    }
    var c = bar(3);
    function bar(x) { return 7 - x; }
    function nope() {}
    return b || c;
}

with current master this gives:

$ uglifyjs todo.js -bc
function foo(x) {
    return x ? 6 : 5;
}

@kzc
Copy link
Contributor

kzc commented Feb 21, 2022

Wow - in a single pass no less!

reduce_vars is doing most of the heavy lifting. I though inline played a role in this example - but not the case:

$ uglify-js todo.js -bc inline=0,collapse_vars=0
function foo(x) {
    return x ? 6 : 5;
}
$ uglify-js todo.js -bc inline=0,collapse_vars=0,evaluate=0
function foo(x) {
    return x ? bar(1) : bar(2);
    function bar(x) {
        return 7 - x;
    }
}

Must be evaluate doing the call inlining.

@alexlamsl
Copy link
Collaborator Author

inline can do something here:

$ uglify-js todo.js -bc evaluate=0
function foo(x) {
    return x ? 7 - 1 : 7 - 2;
}

evaluate steals the spotlight because the results are constants, but if you replace that 7 with say A then inline will shine through 😉

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

Successfully merging this pull request may close these issues.

None yet

2 participants