mirror of
https://github.com/swc-project/swc.git
synced 2024-12-24 22:22:34 +03:00
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:
parent
5480a52d83
commit
4eab2ed2fc
@ -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,
|
||||
|
@ -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)
|
||||
"###,
|
||||
);
|
||||
}
|
||||
|
@ -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);
|
@ -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);
|
Loading…
Reference in New Issue
Block a user