From 0a25f2e359c8a75c5f139b0a13df8d574709e4e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Fri, 28 Oct 2022 12:02:04 +0900 Subject: [PATCH 01/13] Add a test --- crates/swc_ecma_minifier/tests/exec.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/crates/swc_ecma_minifier/tests/exec.rs b/crates/swc_ecma_minifier/tests/exec.rs index 33003e875041..f5e3beef12d5 100644 --- a/crates/swc_ecma_minifier/tests/exec.rs +++ b/crates/swc_ecma_minifier/tests/exec.rs @@ -10327,3 +10327,18 @@ 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) + "###, + ); +} From 8cb47735db6b4c135b3b55f7ca9d6903d3971ef7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Fri, 28 Oct 2022 12:18:22 +0900 Subject: [PATCH 02/13] Add a test --- .../swc_ecma_minifier/tests/fixture/issues/6279/1/input.js | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 crates/swc_ecma_minifier/tests/fixture/issues/6279/1/input.js diff --git a/crates/swc_ecma_minifier/tests/fixture/issues/6279/1/input.js b/crates/swc_ecma_minifier/tests/fixture/issues/6279/1/input.js new file mode 100644 index 000000000000..5d258be97bf2 --- /dev/null +++ b/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) \ No newline at end of file From aaf7ff2c4e59fec405a32d39c10a354d6b9b3791 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Fri, 28 Oct 2022 12:22:20 +0900 Subject: [PATCH 03/13] Fix --- crates/swc_ecma_minifier/src/compress/optimize/iife.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/crates/swc_ecma_minifier/src/compress/optimize/iife.rs b/crates/swc_ecma_minifier/src/compress/optimize/iife.rs index 8e14005626ba..84f27ca4b52a 100644 --- a/crates/swc_ecma_minifier/src/compress/optimize/iife.rs +++ b/crates/swc_ecma_minifier/src/compress/optimize/iife.rs @@ -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, @@ -241,6 +242,7 @@ where } match &*arg.expr { + Expr::Lit(Lit::Regex(..)) => false, Expr::Lit(Lit::Str(s)) if s.value.len() > 3 => true, Expr::Lit(..) => false, _ => true, From 2b29c8185b2001a9c6a1984ddd8ee252307d3c3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Fri, 28 Oct 2022 12:22:54 +0900 Subject: [PATCH 04/13] Update test refs --- .../swc_ecma_minifier/tests/fixture/issues/6279/1/output.js | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 crates/swc_ecma_minifier/tests/fixture/issues/6279/1/output.js diff --git a/crates/swc_ecma_minifier/tests/fixture/issues/6279/1/output.js b/crates/swc_ecma_minifier/tests/fixture/issues/6279/1/output.js new file mode 100644 index 000000000000..40a73827977f --- /dev/null +++ b/crates/swc_ecma_minifier/tests/fixture/issues/6279/1/output.js @@ -0,0 +1,4 @@ +!function(str, r) { + let m; + for(; m = r.exec(str);)console.log(m); +}('abcda', /a/g); From afe9a6da9bc4474463e9c145de4f6a1e63438e38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Fri, 28 Oct 2022 14:08:41 +0900 Subject: [PATCH 05/13] Add a test --- crates/swc_ecma_minifier/tests/exec.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/crates/swc_ecma_minifier/tests/exec.rs b/crates/swc_ecma_minifier/tests/exec.rs index f5e3beef12d5..0b6d5c8772e5 100644 --- a/crates/swc_ecma_minifier/tests/exec.rs +++ b/crates/swc_ecma_minifier/tests/exec.rs @@ -10342,3 +10342,19 @@ fn issue_6279_1() { "###, ); } + +#[test] +fn issue_6279_2() { + run_default_exec_test( + r###" + const r = new Regex('a', 'g'); + function run(str, r) { + let m + while (m = r.exec(str)) { + console.log(m) + } + } + run('abcda', r) + "###, + ); +} From 325477ebc9426c4a4652c1dbc2a69b47eb51a608 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Fri, 28 Oct 2022 14:09:13 +0900 Subject: [PATCH 06/13] Add a test --- .../tests/fixture/issues/6279/2/input.js | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 crates/swc_ecma_minifier/tests/fixture/issues/6279/2/input.js diff --git a/crates/swc_ecma_minifier/tests/fixture/issues/6279/2/input.js b/crates/swc_ecma_minifier/tests/fixture/issues/6279/2/input.js new file mode 100644 index 000000000000..98630fbfbeca --- /dev/null +++ b/crates/swc_ecma_minifier/tests/fixture/issues/6279/2/input.js @@ -0,0 +1,8 @@ +const r = new Regex('a', 'g'); +function run(str, r) { + let m + while (m = r.exec(str)) { + console.log(m) + } +} +run('abcda', r) \ No newline at end of file From 249351907751ae754fbd0366f2b34978f0e1a8bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Fri, 28 Oct 2022 14:10:42 +0900 Subject: [PATCH 07/13] Update test refs --- .../swc_ecma_minifier/tests/fixture/issues/6279/2/output.js | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 crates/swc_ecma_minifier/tests/fixture/issues/6279/2/output.js diff --git a/crates/swc_ecma_minifier/tests/fixture/issues/6279/2/output.js b/crates/swc_ecma_minifier/tests/fixture/issues/6279/2/output.js new file mode 100644 index 000000000000..60bdcf154064 --- /dev/null +++ b/crates/swc_ecma_minifier/tests/fixture/issues/6279/2/output.js @@ -0,0 +1,5 @@ +const r = new Regex('a', 'g'); +!function(str, r) { + let m; + for(; m = r.exec(str);)console.log(m); +}('abcda', r); From d08cb4bcf22fe8a4bd65d02735d3df507ab16bc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Fri, 28 Oct 2022 14:18:46 +0900 Subject: [PATCH 08/13] Revert --- crates/swc_ecma_minifier/src/compress/optimize/iife.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/swc_ecma_minifier/src/compress/optimize/iife.rs b/crates/swc_ecma_minifier/src/compress/optimize/iife.rs index 84f27ca4b52a..220fe9225d49 100644 --- a/crates/swc_ecma_minifier/src/compress/optimize/iife.rs +++ b/crates/swc_ecma_minifier/src/compress/optimize/iife.rs @@ -242,7 +242,6 @@ where } match &*arg.expr { - Expr::Lit(Lit::Regex(..)) => false, Expr::Lit(Lit::Str(s)) if s.value.len() > 3 => true, Expr::Lit(..) => false, _ => true, From 9ff67c633670d2f945cb98f37ed3f4eaf2392066 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Fri, 28 Oct 2022 15:11:52 +0900 Subject: [PATCH 09/13] Typo --- crates/swc_ecma_minifier/tests/exec.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/swc_ecma_minifier/tests/exec.rs b/crates/swc_ecma_minifier/tests/exec.rs index 0b6d5c8772e5..3d068628857e 100644 --- a/crates/swc_ecma_minifier/tests/exec.rs +++ b/crates/swc_ecma_minifier/tests/exec.rs @@ -10347,7 +10347,7 @@ fn issue_6279_1() { fn issue_6279_2() { run_default_exec_test( r###" - const r = new Regex('a', 'g'); + const r = new Regexp('a', 'g'); function run(str, r) { let m while (m = r.exec(str)) { From aae789fa74ca8570fb70605c702d1dcb14e98543 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Sat, 29 Oct 2022 00:56:24 +0900 Subject: [PATCH 10/13] Typo --- crates/swc_ecma_minifier/tests/exec.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/swc_ecma_minifier/tests/exec.rs b/crates/swc_ecma_minifier/tests/exec.rs index 3d068628857e..b5b22be4404a 100644 --- a/crates/swc_ecma_minifier/tests/exec.rs +++ b/crates/swc_ecma_minifier/tests/exec.rs @@ -10347,7 +10347,7 @@ fn issue_6279_1() { fn issue_6279_2() { run_default_exec_test( r###" - const r = new Regexp('a', 'g'); + const r = new RegExp('a', 'g'); function run(str, r) { let m while (m = r.exec(str)) { From 53322f122ee9fefc38287c1842d2f276565b3901 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Sat, 29 Oct 2022 07:33:49 +0900 Subject: [PATCH 11/13] Update crates/swc_ecma_minifier/tests/fixture/issues/6279/2/input.js Co-authored-by: Justin Ridgewell --- crates/swc_ecma_minifier/tests/fixture/issues/6279/2/input.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/swc_ecma_minifier/tests/fixture/issues/6279/2/input.js b/crates/swc_ecma_minifier/tests/fixture/issues/6279/2/input.js index 98630fbfbeca..edea710fec9d 100644 --- a/crates/swc_ecma_minifier/tests/fixture/issues/6279/2/input.js +++ b/crates/swc_ecma_minifier/tests/fixture/issues/6279/2/input.js @@ -1,4 +1,4 @@ -const r = new Regex('a', 'g'); +const r = new RegExp('a', 'g'); function run(str, r) { let m while (m = r.exec(str)) { From 557decb02944ad989127c310321e8ae1068dad0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Sat, 29 Oct 2022 07:33:55 +0900 Subject: [PATCH 12/13] Update crates/swc_ecma_minifier/tests/fixture/issues/6279/2/output.js Co-authored-by: Justin Ridgewell --- crates/swc_ecma_minifier/tests/fixture/issues/6279/2/output.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/swc_ecma_minifier/tests/fixture/issues/6279/2/output.js b/crates/swc_ecma_minifier/tests/fixture/issues/6279/2/output.js index 60bdcf154064..762037ec84ba 100644 --- a/crates/swc_ecma_minifier/tests/fixture/issues/6279/2/output.js +++ b/crates/swc_ecma_minifier/tests/fixture/issues/6279/2/output.js @@ -1,4 +1,4 @@ -const r = new Regex('a', 'g'); +const r = new RegExp('a', 'g'); !function(str, r) { let m; for(; m = r.exec(str);)console.log(m); From 6b2a6cc00bf4ab649a1492c02988ef7ca6e4f893 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Sat, 29 Oct 2022 08:25:54 +0900 Subject: [PATCH 13/13] Update test refs --- crates/swc_ecma_minifier/tests/fixture/issues/6279/2/output.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/crates/swc_ecma_minifier/tests/fixture/issues/6279/2/output.js b/crates/swc_ecma_minifier/tests/fixture/issues/6279/2/output.js index 762037ec84ba..40a73827977f 100644 --- a/crates/swc_ecma_minifier/tests/fixture/issues/6279/2/output.js +++ b/crates/swc_ecma_minifier/tests/fixture/issues/6279/2/output.js @@ -1,5 +1,4 @@ -const r = new RegExp('a', 'g'); !function(str, r) { let m; for(; m = r.exec(str);)console.log(m); -}('abcda', r); +}('abcda', /a/g);