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): Handle array literals in sequences #3348

Merged
merged 4 commits into from
Jan 24, 2022

Conversation

kdy1
Copy link
Member

@kdy1 kdy1 commented Jan 24, 2022

Description:

swc_ecma_minifier:

  • sequences: Implement more rule for array literals.

Related issue (if exists):

Bugs

Bug 1 (fixed)

   INFO [SWC_RUN]
var a = {};
(function(global) {
    function fail(o) {
        var result = {};
        function inner() {
            return outer({
                one: o.one,
                two: o.two
            });
        }
        result.inner = function() {
            return inner();
        };
        return result;
    }
    function outer(o) {
        var ret;
        if (o) {
            ret = o.one;
        } else {
            ret = o.two;
        }
        return ret;
    }
    global.fail = fail;
})(a);
var b = a.fail({
    one: "PASS"
});
console.log(b.inner());

PASS

    at crates/swc_ecma_minifier/src/debug.rs:120
    in compress ast
    in minify

   INFO Done in 255.375µs, kind: "perf"
    at crates/swc_timer/src/lib.rs:32
    in analyze
    in optimize with , pass: 0
    in compress ast
    in minify

  DEBUG ===== Start =====
var a = {};
(function(global) {
    function fail(o) {
        var result = {};
        function inner() {
            return outer({
                one: o.one,
                two: o.two
            });
        }
        result.inner = function() {
            return inner();
        };
        return result;
    }
    function outer(o) {
        var ret;
        if (o) {
            ret = o.one;
        } else {
            ret = o.two;
        }
        return ret;
    }
    global.fail = fail;
})(a);
var b = a.fail({
    one: "PASS"
});
console.log(b.inner());

    at crates/swc_ecma_minifier/src/compress/mod.rs:275
    in optimize with , pass: 0
    in compress ast
    in minify

   INFO compress: Running expression simplifier (pass = 0)
    at crates/swc_ecma_minifier/src/compress/mod.rs:282
    in optimize with , pass: 0
    in compress ast
    in minify

   INFO compress: expr_simplifier took 155.683µs (pass = 0)
    at crates/swc_ecma_minifier/src/compress/mod.rs:304
    in optimize with , pass: 0
    in compress ast
    in minify

   INFO compress/pure: Running pure optimizer (pass = 0)
    at crates/swc_ecma_minifier/src/compress/mod.rs:325
    in optimize with , pass: 0
    in compress ast
    in minify

   INFO compress/pure: Pure optimizer took 419.355µs (pass = 0)
    at crates/swc_ecma_minifier/src/compress/mod.rs:339
    in optimize with , pass: 0
    in compress ast
    in minify

   INFO compress: Running optimizer (pass = 0)
    at crates/swc_ecma_minifier/src/compress/mod.rs:355
    in optimize with , pass: 0
    in compress ast
    in minify

  DEBUG inline: Decided to inline function `inner#3` as it's used only once
    at crates/swc_ecma_minifier/src/compress/optimize/inline.rs:529
    in optimize with , pass: 0
    in compress ast
    in minify

  DEBUG inline: Replacing 'inner#3' with an expression
    at crates/swc_ecma_minifier/src/compress/optimize/inline.rs:618
    in optimize with , pass: 0
    in compress ast
    in minify

  DEBUG inline: Inlining an iife
    at crates/swc_ecma_minifier/src/compress/optimize/iife.rs:600
    in optimize with , pass: 0
    in compress ast
    in minify

  DEBUG inline: Inlining a function call
    at crates/swc_ecma_minifier/src/compress/optimize/iife.rs:500
    in optimize with , pass: 0
    in compress ast
    in minify

  DEBUG sequences: Compressing statements as a sequences
    at crates/swc_ecma_minifier/src/compress/optimize/sequences.rs:136
    in optimize with , pass: 0
    in compress ast
    in minify

  DEBUG inline: Decided to inline function `fail#2` as it's used only once
    at crates/swc_ecma_minifier/src/compress/optimize/inline.rs:529
    in optimize with , pass: 0
    in compress ast
    in minify

  DEBUG Merging assignments in cons and alt of if statement
    at crates/swc_ecma_minifier/src/compress/optimize/conditionals.rs:525
    in optimize with , pass: 0
    in compress ast
    in minify

  DEBUG sequences: Inlining sequential expressions (`ret#4`)
    at crates/swc_ecma_minifier/src/compress/optimize/sequences.rs:1421
    in merge_sequential_expr with , b: "ret#4"
    in merge_sequences_in_stmts
    in optimize with , pass: 0
    in compress ast
    in minify

  DEBUG sequences: [Changed] ret#4 = o#4 ? o#4.one : o#4.two
    at crates/swc_ecma_minifier/src/compress/optimize/sequences.rs:1435
    in merge_sequential_expr with , b: "ret#4"
    in merge_sequences_in_stmts
    in optimize with , pass: 0
    in compress ast
    in minify

  DEBUG inline: Replacing 'fail#2' with an expression
    at crates/swc_ecma_minifier/src/compress/optimize/inline.rs:618
    in optimize with , pass: 0
    in compress ast
    in minify

  DEBUG negate_iife: Negating iife
    at crates/swc_ecma_minifier/src/compress/optimize/iife.rs:39
    in optimize with , pass: 0
    in compress ast
    in minify

  DEBUG Dropping [(Atom('fail' type=inline), #2), (Atom('inner' type=inline), #3)]
    at crates/swc_ecma_minifier/src/compress/optimize/util.rs:199
    in optimize with , pass: 0
    in compress ast
    in minify

   INFO compress: Optimizer took 5.266288ms (pass = 0)
    at crates/swc_ecma_minifier/src/compress/mod.rs:375
    in optimize with , pass: 0
    in compress ast
    in minify

   INFO Done in 8.066734ms, kind: "perf"
    at crates/swc_timer/src/lib.rs:32
    in optimize with , pass: 0
    in compress ast
    in minify

   INFO [SWC_RUN]
var a = {};
!function(global) {
    function outer(o) {
        var ret;
        return ret = o ? o.one : o.two;
    }
    global.fail = function fail(o) {
        var result = {};
        return result.inner = function() {
            return outer({
                one: o.one,
                two: o.two
            });
        }, result;
    };
}(a);
var b = a.fail({
    one: "PASS"
});
console.log(b.inner());

PASS

    at crates/swc_ecma_minifier/src/debug.rs:120
    in compress ast
    in minify

   INFO Done in 214.034µs, kind: "perf"
    at crates/swc_timer/src/lib.rs:32
    in analyze
    in optimize with , pass: 1
    in compress ast
    in minify

  DEBUG ===== Start =====
var a = {};
!function(global) {
    function outer(o) {
        var ret;
        return ret = o ? o.one : o.two;
    }
    global.fail = function fail(o) {
        var result = {};
        return result.inner = function() {
            return outer({
                one: o.one,
                two: o.two
            });
        }, result;
    };
}(a);
var b = a.fail({
    one: "PASS"
});
console.log(b.inner());

    at crates/swc_ecma_minifier/src/compress/mod.rs:275
    in optimize with , pass: 1
    in compress ast
    in minify

   INFO compress: Running expression simplifier (pass = 1)
    at crates/swc_ecma_minifier/src/compress/mod.rs:282
    in optimize with , pass: 1
    in compress ast
    in minify

   INFO compress: expr_simplifier took 54.487µs (pass = 1)
    at crates/swc_ecma_minifier/src/compress/mod.rs:304
    in optimize with , pass: 1
    in compress ast
    in minify

   INFO compress/pure: Running pure optimizer (pass = 1)
    at crates/swc_ecma_minifier/src/compress/mod.rs:325
    in optimize with , pass: 1
    in compress ast
    in minify

   INFO compress/pure: Pure optimizer took 384.27µs (pass = 1)
    at crates/swc_ecma_minifier/src/compress/mod.rs:339
    in optimize with , pass: 1
    in compress ast
    in minify

   INFO [SWC_RUN]
var a = {};
!function(global) {
    function outer(o) {
        var ret = o ? o.one : o.two;
        return ret;
    }
    global.fail = function fail(o) {
        var result = {};
        return result.inner = function() {
            return outer({
                one: o.one,
                two: o.two
            });
        }, result;
    };
}(a);
var b = a.fail({
    one: "PASS"
});
console.log(b.inner());

PASS

    at crates/swc_ecma_minifier/src/debug.rs:120
    in optimize with , pass: 1
    in compress ast
    in minify

  DEBUG ===== After pure =====
var a = {};
!function(global) {
    function outer(o) {
        var ret = o ? o.one : o.two;
        return ret;
    }
    global.fail = function fail(o) {
        var result = {};
        return result.inner = function() {
            return outer({
                one: o.one,
                two: o.two
            });
        }, result;
    };
}(a);
var b = a.fail({
    one: "PASS"
});
console.log(b.inner());

    at crates/swc_ecma_minifier/src/compress/mod.rs:349
    in optimize with , pass: 1
    in compress ast
    in minify

   INFO compress: Running optimizer (pass = 1)
    at crates/swc_ecma_minifier/src/compress/mod.rs:355
    in optimize with , pass: 1
    in compress ast
    in minify

  DEBUG inline: Decided to inline function `outer#2` as it's used only once
    at crates/swc_ecma_minifier/src/compress/optimize/inline.rs:529
    in optimize with , pass: 1
    in compress ast
    in minify

  DEBUG Removing ident of an class / function expression
    at crates/swc_ecma_minifier/src/compress/optimize/unused.rs:479
    in optimize with , pass: 1
    in compress ast
    in minify

  DEBUG inline: Replacing 'outer#2' with an expression
    at crates/swc_ecma_minifier/src/compress/optimize/inline.rs:618
    in visit_mut_seq_expr
    in optimize with , pass: 1
    in compress ast
    in minify

  DEBUG inline: Inlining an iife
    at crates/swc_ecma_minifier/src/compress/optimize/iife.rs:600
    in visit_mut_seq_expr
    in optimize with , pass: 1
    in compress ast
    in minify

  DEBUG inline: Inlining a function call
    at crates/swc_ecma_minifier/src/compress/optimize/iife.rs:500
    in visit_mut_seq_expr
    in optimize with , pass: 1
    in compress ast
    in minify

  DEBUG join_vars: Joining variables
    at crates/swc_ecma_minifier/src/compress/optimize/join_vars.rs:56
    in visit_mut_seq_expr
    in optimize with , pass: 1
    in compress ast
    in minify

  DEBUG unused: Dropping assignment to var 'ret#4', which is never used
    at crates/swc_ecma_minifier/src/compress/optimize/unused.rs:437
    in visit_mut_seq_expr
    in visit_mut_seq_expr
    in optimize with , pass: 1
    in compress ast
    in minify

  DEBUG sequences: Inlining sequential expressions (`o#4`)
    at crates/swc_ecma_minifier/src/compress/optimize/sequences.rs:1421
    in merge_sequential_expr with , b: "o#4"
    in merge_sequential_expr with , b: "o#4 ? o#4.one : o#4.two"
    in merge_sequences_in_seq_expr with , seq_expr: "o#4 = {\n    one: o#3.one,\n    two: o#3.two\n}, o#4 ? o#4.one : o#4.two, ret#4"
    in visit_mut_seq_expr
    in visit_mut_seq_expr
    in optimize with , pass: 1
    in compress ast
    in minify

  DEBUG sequences: [Changed] o#4 = {
    one: o#3.one,
    two: o#3.two
}
    at crates/swc_ecma_minifier/src/compress/optimize/sequences.rs:1435
    in merge_sequential_expr with , b: "o#4"
    in merge_sequential_expr with , b: "o#4 ? o#4.one : o#4.two"
    in merge_sequences_in_seq_expr with , seq_expr: "o#4 = {\n    one: o#3.one,\n    two: o#3.two\n}, o#4 ? o#4.one : o#4.two, ret#4"
    in visit_mut_seq_expr
    in visit_mut_seq_expr
    in optimize with , pass: 1
    in compress ast
    in minify

  DEBUG inline: Inlining an iife
    at crates/swc_ecma_minifier/src/compress/optimize/iife.rs:600
    in optimize with , pass: 1
    in compress ast
    in minify

  DEBUG inline: Inlining a function call
    at crates/swc_ecma_minifier/src/compress/optimize/iife.rs:500
    in optimize with , pass: 1
    in compress ast
    in minify

  DEBUG ignore_return_value: Reducing unary (!)
    at crates/swc_ecma_minifier/src/compress/optimize/mod.rs:1053
    in ignore_return_value
    in optimize with , pass: 1
    in compress ast
    in minify

  DEBUG ignore_return_value: Reducing unary (void)
    at crates/swc_ecma_minifier/src/compress/optimize/mod.rs:1053
    in ignore_return_value
    in ignore_return_value
    in ignore_return_value
    in optimize with , pass: 1
    in compress ast
    in minify

  DEBUG join_vars: Joining variables
    at crates/swc_ecma_minifier/src/compress/optimize/join_vars.rs:56
    in optimize with , pass: 1
    in compress ast
    in minify

  DEBUG Dropping [(Atom('outer' type=inline), #2)]
    at crates/swc_ecma_minifier/src/compress/optimize/util.rs:199
    in optimize with , pass: 1
    in compress ast
    in minify

   INFO compress: Optimizer took 5.345692ms (pass = 1)
    at crates/swc_ecma_minifier/src/compress/mod.rs:375
    in optimize with , pass: 1
    in compress ast
    in minify

   INFO Done in 61.536331ms, kind: "perf"
    at crates/swc_timer/src/lib.rs:32
    in optimize with , pass: 1
    in compress ast
    in minify

   INFO [SWC_RUN]
var a = {}, global;
global = a, global.fail = function(o1) {
    var result = {};
    return result.inner = function() {
        var o, ret;
        return (o = {
            one: o1.one,
            two: o1.two
        }) ? o.one : o.two, ret;
    }, result;
};
var b = a.fail({
    one: "PASS"
});
console.log(b.inner());

undefined

@kdy1 kdy1 added this to the v1.2.134 milestone Jan 24, 2022
@kdy1 kdy1 changed the title feat(es/minifier): Implement more rules feat(es/minifier): Implement more rules for sequences Jan 24, 2022
@kdy1 kdy1 changed the title feat(es/minifier): Implement more rules for sequences feat(es/minifier): Handle array literals in sequences Jan 24, 2022
@kdy1 kdy1 force-pushed the minifier-more-tests branch from b062551 to 48bcfe8 Compare January 24, 2022 11:50
@kdy1 kdy1 marked this pull request as ready for review January 24, 2022 12:10
@kdy1 kdy1 merged commit 8007b2d into swc-project:main Jan 24, 2022
@kdy1 kdy1 deleted the minifier-more-tests branch January 24, 2022 12:10
kodiakhq bot pushed a commit to vercel/next.js that referenced this pull request Jan 24, 2022
This PR applies

 - swc-project/swc#3344

Resolves #30237 (comment)

 - swc-project/swc#3348

 - swc-project/swc#3352

This fixes `jsc.experimental.keepImportAssertions`.
@kdy1 kdy1 modified the milestones: v1.2.134, v1.2.135 Jan 25, 2022
natew pushed a commit to natew/next.js that referenced this pull request Feb 16, 2022
This PR applies

 - swc-project/swc#3344

Resolves vercel#30237 (comment)

 - swc-project/swc#3348

 - swc-project/swc#3352

This fixes `jsc.experimental.keepImportAssertions`.
@swc-project swc-project locked as resolved and limited conversation to collaborators Oct 31, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant