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

**Related issue:**

 - Closes https://github.com/swc-project/swc/issues/6279.

Co-authored-by: Justin Ridgewell <justin@ridgewell.name>
This commit is contained in:
Donny/강동윤 2022-10-29 09:02:32 +09:00 committed by GitHub
parent 5480a52d83
commit 4eab2ed2fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 55 additions and 0 deletions

View File

@ -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,

View File

@ -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)
"###,
);
}

View File

@ -0,0 +1,7 @@
function run(str, r) {
let m
while (m = r.exec(str)) {
console.log(m)
}
}
run('abcda', /a/g)

View File

@ -0,0 +1,4 @@
!function(str, r) {
let m;
for(; m = r.exec(str);)console.log(m);
}('abcda', /a/g);

View File

@ -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)

View File

@ -0,0 +1,4 @@
!function(str, r) {
let m;
for(; m = r.exec(str);)console.log(m);
}('abcda', /a/g);