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

fix(es/minifier): Don't inline regex for IIFEs #6283

Merged
merged 15 commits into from
Oct 29, 2022
1 change: 1 addition & 0 deletions crates/swc_ecma_minifier/src/compress/optimize/iife.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ where

if let Some(arg) = arg {
match &**arg {
Expr::Lit(Lit::Regex(..)) => continue,
kdy1 marked this conversation as resolved.
Show resolved Hide resolved
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
Original file line number Diff line number Diff line change
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)
"###,
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
function run(str, r) {
let m
while (m = r.exec(str)) {
console.log(m)
}
}
run('abcda', /a/g)
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
!function(str, r) {
let m;
for(; m = r.exec(str);)console.log(m);
}('abcda', /a/g);
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
!function(str, r) {
let m;
for(; m = r.exec(str);)console.log(m);
}('abcda', /a/g);