diff --git a/crates/oxc_minifier/src/peephole/replace_known_methods.rs b/crates/oxc_minifier/src/peephole/replace_known_methods.rs index d00d4c81626c6..b7e3d40091b57 100644 --- a/crates/oxc_minifier/src/peephole/replace_known_methods.rs +++ b/crates/oxc_minifier/src/peephole/replace_known_methods.rs @@ -127,7 +127,8 @@ impl<'a> PeepholeOptimizations { return; }; - if matches!(ctx.parent(), Ancestor::StaticMemberExpressionObject(_)) { + if matches!(ctx.parent(), Ancestor::StaticMemberExpressionObject(member) if member.property().name == "concat") + { return; } @@ -1389,15 +1390,22 @@ mod test { // array test("x = [1,2].concat(1).concat(2,['abc']).concat('abc')", "x = [1,2,1,2,'abc','abc']"); test("x = [].concat(['abc']).concat(1).concat([2,3])", "x = ['abc',1,2,3]"); + test("x = [].concat(1).concat(2).join(',')", "x = [1,2].join(',')"); test("var x, y; [1].concat(x).concat(y)", "var x, y; [1].concat(x, y)"); test("var y; [1].concat(x).concat(y)", "var y; [1].concat(x, y)"); // x might have a getter that updates y, but that side effect is preserved correctly test("var x; [1].concat(x.a).concat(x)", "var x; [1].concat(x.a, x)"); // x.a might have a getter that updates x, but that side effect is preserved correctly + test_same("x = [].map(a => a + 1).concat(1)"); // string test("x = '1'.concat(1).concat(2,['abc']).concat('abc')", "x = '112abcabc'"); test("x = ''.concat(['abc']).concat(1).concat([2,3])", "x = 'abc12,3'"); test("x = ''.concat(1)", "x = '1'"); + test( + "x = ''.concat('a', ' ').concat('b').split(/[\\s\\n]+/)", + "x = 'a b'.split(/[\\s\\n]+/)", + ); + test_same("x = ''.split().concat(1)"); test("var x, y; v = ''.concat(x).concat(y)", "var x, y; v = `${x}${y}`"); test("var y; v = ''.concat(x).concat(y)", "var y; v = `${x}${y}`"); // x might have a getter that updates y, but that side effect is preserved correctly diff --git a/tasks/minsize/minsize.snap b/tasks/minsize/minsize.snap index 8a97d88657794..247b8873cbe79 100644 --- a/tasks/minsize/minsize.snap +++ b/tasks/minsize/minsize.snap @@ -21,7 +21,7 @@ Original | minified | minified | gzip | gzip | Iterations | Fi 3.20 MB | 1.00 MB | 1.01 MB | 323.10 kB | 331.56 kB | 3 | echarts.js -6.69 MB | 2.22 MB | 2.31 MB | 459.28 kB | 488.28 kB | 4 | antd.js +6.69 MB | 2.22 MB | 2.31 MB | 459.26 kB | 488.28 kB | 4 | antd.js 10.95 MB | 3.34 MB | 3.49 MB | 855.24 kB | 915.50 kB | 4 | typescript.js diff --git a/tasks/track_memory_allocations/allocs_minifier.snap b/tasks/track_memory_allocations/allocs_minifier.snap index eb2118aee7b6c..05780b78fea66 100644 --- a/tasks/track_memory_allocations/allocs_minifier.snap +++ b/tasks/track_memory_allocations/allocs_minifier.snap @@ -2,13 +2,13 @@ File | File size || Sys allocs | Sys reallocs | ------------------------------------------------------------------------------------------------------------------------------------------- checker.ts | 2.92 MB || 84074 | 14190 || 153691 | 29463 | 5.625 MB -cal.com.tsx | 1.06 MB || 40526 | 3033 || 37074 | 4733 | 1.654 MB +cal.com.tsx | 1.06 MB || 40526 | 3033 || 37077 | 4736 | 1.654 MB RadixUIAdoptionSection.jsx | 2.52 kB || 83 | 8 || 30 | 6 | 992 B pdf.mjs | 567.30 kB || 19823 | 2900 || 47400 | 7781 | 1.624 MB -antd.js | 6.69 MB || 99855 | 13518 || 331725 | 70117 | 17.407 MB +antd.js | 6.69 MB || 99862 | 13523 || 331767 | 70119 | 17.415 MB binder.ts | 193.08 kB || 4769 | 974 || 7059 | 834 | 201.192 kB