Skip to content

Commit

Permalink
fix(es/minifier): Don't inline regex for IIFEs (#6283)
Browse files Browse the repository at this point in the history
**Related issue:**

 - Closes #6279.

Co-authored-by: Justin Ridgewell <justin@ridgewell.name>
  • Loading branch information
kdy1 and jridgewell committed Oct 29, 2022
1 parent 5480a52 commit 4eab2ed
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 0 deletions.
1 change: 1 addition & 0 deletions crates/swc_ecma_minifier/src/compress/optimize/iife.rs
Expand Up @@ -200,6 +200,7 @@ where

if let Some(arg) = arg {
match &**arg {
Expr::Lit(Lit::Regex(..)) => continue,
Expr::Lit(Lit::Str(s)) if s.value.len() > 3 => continue,
Expr::Lit(..) => {}
_ => continue,
Expand Down
31 changes: 31 additions & 0 deletions crates/swc_ecma_minifier/tests/exec.rs
Expand Up @@ -10327,3 +10327,34 @@ fn issue_6217_1() {
false,
);
}

#[test]
fn issue_6279_1() {
run_default_exec_test(
r###"
function run(str, r) {
let m
while(m = r.exec(str)) {
console.log(m)
}
}
run('abcda', /a/g)
"###,
);
}

#[test]
fn issue_6279_2() {
run_default_exec_test(
r###"
const r = new RegExp('a', 'g');
function run(str, r) {
let m
while (m = r.exec(str)) {
console.log(m)
}
}
run('abcda', r)
"###,
);
}
7 changes: 7 additions & 0 deletions crates/swc_ecma_minifier/tests/fixture/issues/6279/1/input.js
@@ -0,0 +1,7 @@
function run(str, r) {
let m
while (m = r.exec(str)) {
console.log(m)
}
}
run('abcda', /a/g)
@@ -0,0 +1,4 @@
!function(str, r) {
let m;
for(; m = r.exec(str);)console.log(m);
}('abcda', /a/g);
8 changes: 8 additions & 0 deletions crates/swc_ecma_minifier/tests/fixture/issues/6279/2/input.js
@@ -0,0 +1,8 @@
const r = new RegExp('a', 'g');
function run(str, r) {
let m
while (m = r.exec(str)) {
console.log(m)
}
}
run('abcda', r)
@@ -0,0 +1,4 @@
!function(str, r) {
let m;
for(; m = r.exec(str);)console.log(m);
}('abcda', /a/g);

1 comment on commit 4eab2ed

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: 4eab2ed Previous: 244b0af Ratio
es/full/bugs-1 357027 ns/iter (± 36382) 379746 ns/iter (± 34815) 0.94
es/full/minify/libraries/antd 1822176677 ns/iter (± 12780498) 1917007793 ns/iter (± 61747902) 0.95
es/full/minify/libraries/d3 407193008 ns/iter (± 6441771) 438675633 ns/iter (± 93823906) 0.93
es/full/minify/libraries/echarts 1536015044 ns/iter (± 17592898) 1598880581 ns/iter (± 76288343) 0.96
es/full/minify/libraries/jquery 101900818 ns/iter (± 1670739) 112824853 ns/iter (± 3622829) 0.90
es/full/minify/libraries/lodash 119727178 ns/iter (± 4067255) 128822271 ns/iter (± 5297865) 0.93
es/full/minify/libraries/moment 57229767 ns/iter (± 847143) 65857880 ns/iter (± 4042870) 0.87
es/full/minify/libraries/react 19451227 ns/iter (± 360642) 20263735 ns/iter (± 906821) 0.96
es/full/minify/libraries/terser 295598359 ns/iter (± 8343699) 381711869 ns/iter (± 46215732) 0.77
es/full/minify/libraries/three 546846146 ns/iter (± 16036182) 668138508 ns/iter (± 134363702) 0.82
es/full/minify/libraries/typescript 3334542431 ns/iter (± 27866776) 4029384803 ns/iter (± 632741919) 0.83
es/full/minify/libraries/victory 798174381 ns/iter (± 3908514) 945692815 ns/iter (± 110554423) 0.84
es/full/minify/libraries/vue 148193859 ns/iter (± 2519141) 194450820 ns/iter (± 6896740) 0.76
es/full/codegen/es3 33821 ns/iter (± 479) 38783 ns/iter (± 14798) 0.87
es/full/codegen/es5 33938 ns/iter (± 508) 38610 ns/iter (± 4292) 0.88
es/full/codegen/es2015 33910 ns/iter (± 611) 36017 ns/iter (± 3284) 0.94
es/full/codegen/es2016 33821 ns/iter (± 684) 36659 ns/iter (± 7598) 0.92
es/full/codegen/es2017 33898 ns/iter (± 713) 36057 ns/iter (± 138691) 0.94
es/full/codegen/es2018 33884 ns/iter (± 918) 37054 ns/iter (± 8426) 0.91
es/full/codegen/es2019 33846 ns/iter (± 476) 35643 ns/iter (± 2189) 0.95
es/full/codegen/es2020 33958 ns/iter (± 569) 36208 ns/iter (± 4466) 0.94
es/full/all/es3 187297186 ns/iter (± 5117678) 253949255 ns/iter (± 42093371) 0.74
es/full/all/es5 177931751 ns/iter (± 3109096) 261283391 ns/iter (± 69178786) 0.68
es/full/all/es2015 142598673 ns/iter (± 2632108) 202696809 ns/iter (± 22266420) 0.70
es/full/all/es2016 141160728 ns/iter (± 3413724) 201557766 ns/iter (± 67587285) 0.70
es/full/all/es2017 141045852 ns/iter (± 3087148) 194487727 ns/iter (± 54424808) 0.73
es/full/all/es2018 139349694 ns/iter (± 2482481) 196565290 ns/iter (± 50287166) 0.71
es/full/all/es2019 139030456 ns/iter (± 3091370) 188730145 ns/iter (± 44587291) 0.74
es/full/all/es2020 134050799 ns/iter (± 2880427) 183392020 ns/iter (± 82509494) 0.73
es/full/parser 710978 ns/iter (± 18759) 848082 ns/iter (± 245263) 0.84
es/full/base/fixer 26585 ns/iter (± 1026) 27567 ns/iter (± 1702) 0.96
es/full/base/resolver_and_hygiene 91937 ns/iter (± 4978) 95065 ns/iter (± 5640) 0.97
serialization of ast node 207 ns/iter (± 3) 216 ns/iter (± 10) 0.96
serialization of serde 208 ns/iter (± 4) 220 ns/iter (± 7) 0.95

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.