From 7a97b8195d48dfa4e50febdaa71e0ad1c24c4967 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Fri, 18 Nov 2022 15:13:56 +0900 Subject: [PATCH 01/25] Move one test --- .../tests/arrow/issue-233/input.js | 1 + .../tests/es2015_arrow.rs | 35 ++++++++++++------- 2 files changed, 23 insertions(+), 13 deletions(-) create mode 100644 crates/swc_ecma_transforms_compat/tests/arrow/issue-233/input.js diff --git a/crates/swc_ecma_transforms_compat/tests/arrow/issue-233/input.js b/crates/swc_ecma_transforms_compat/tests/arrow/issue-233/input.js new file mode 100644 index 000000000000..0b6de017d2f6 --- /dev/null +++ b/crates/swc_ecma_transforms_compat/tests/arrow/issue-233/input.js @@ -0,0 +1 @@ +const foo = () => ({ x, ...y }) => y \ No newline at end of file diff --git a/crates/swc_ecma_transforms_compat/tests/es2015_arrow.rs b/crates/swc_ecma_transforms_compat/tests/es2015_arrow.rs index 0df02227c067..b3fd543c9b87 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2015_arrow.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2015_arrow.rs @@ -1,7 +1,9 @@ +use std::path::PathBuf; + use swc_common::{chain, Mark}; use swc_ecma_transforms_base::resolver; use swc_ecma_transforms_compat::es2015::arrow; -use swc_ecma_transforms_testing::{compare_stdout, test}; +use swc_ecma_transforms_testing::{compare_stdout, test, test_fixture}; use swc_ecma_visit::Fold; fn tr() -> impl Fold { @@ -10,18 +12,6 @@ fn tr() -> impl Fold { chain!(resolver(unresolved, global, false), arrow(unresolved)) } -test!( - ::swc_ecma_parser::Syntax::default(), - |_| arrow(Mark::new()), - issue_233, - "const foo = () => ({ x, ...y }) => y", - "const foo = function() { - return function({ x , ...y }) { - return y; - }; -};" -); - test!( ::swc_ecma_parser::Syntax::default(), |_| arrow(Mark::new()), @@ -532,3 +522,22 @@ test!( }; }" ); + +#[testing::fixture("tests/arrow/**/input.js")] +fn fixture(input: PathBuf) { + let output = input.with_file_name("output.js"); + + test_fixture( + Default::default(), + &|_| { + let unresolved_mark = Mark::new(); + chain!( + resolver(unresolved_mark, Mark::new(), false), + arrow(unresolved_mark) + ) + }, + &input, + &output, + Default::default(), + ); +} From b052cfe1bb9f262a9b439fd615a419f6aa273b28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Fri, 18 Nov 2022 15:16:24 +0900 Subject: [PATCH 02/25] Move tests --- .../tests/arrow/basic/input.js | 1 + .../tests/arrow/destructuring/input.js | 1 + .../tests/es2015_arrow.rs | 20 ------------------- 3 files changed, 2 insertions(+), 20 deletions(-) create mode 100644 crates/swc_ecma_transforms_compat/tests/arrow/basic/input.js create mode 100644 crates/swc_ecma_transforms_compat/tests/arrow/destructuring/input.js diff --git a/crates/swc_ecma_transforms_compat/tests/arrow/basic/input.js b/crates/swc_ecma_transforms_compat/tests/arrow/basic/input.js new file mode 100644 index 000000000000..2f0f282ff646 --- /dev/null +++ b/crates/swc_ecma_transforms_compat/tests/arrow/basic/input.js @@ -0,0 +1 @@ +let echo = (bar) => bar \ No newline at end of file diff --git a/crates/swc_ecma_transforms_compat/tests/arrow/destructuring/input.js b/crates/swc_ecma_transforms_compat/tests/arrow/destructuring/input.js new file mode 100644 index 000000000000..955854cf72b6 --- /dev/null +++ b/crates/swc_ecma_transforms_compat/tests/arrow/destructuring/input.js @@ -0,0 +1 @@ +let foo = ({ bar }) => undefined; \ No newline at end of file diff --git a/crates/swc_ecma_transforms_compat/tests/es2015_arrow.rs b/crates/swc_ecma_transforms_compat/tests/es2015_arrow.rs index b3fd543c9b87..a398ac0adce4 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2015_arrow.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2015_arrow.rs @@ -12,26 +12,6 @@ fn tr() -> impl Fold { chain!(resolver(unresolved, global, false), arrow(unresolved)) } -test!( - ::swc_ecma_parser::Syntax::default(), - |_| arrow(Mark::new()), - destructuring, - r#"let foo = ({bar}) => undefined;"#, - r#"let foo = function ({bar}) { - return undefined; -}"# -); - -test!( - ::swc_ecma_parser::Syntax::default(), - |_| arrow(Mark::new()), - basic, - r#"let echo = (bar) => bar"#, - r#"let echo = function(bar) { - return bar; - }"# -); - test!( ::swc_ecma_parser::Syntax::default(), |_| arrow(Mark::new()), From 0a3101bc1d86de3251e4d2dd678dae4217bc5829 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Fri, 18 Nov 2022 15:19:14 +0900 Subject: [PATCH 03/25] Move tests --- .../tests/arrow/empty-arguments/input.js | 1 + .../swc_ecma_transforms_compat/tests/es2015_arrow.rs | 10 ---------- 2 files changed, 1 insertion(+), 10 deletions(-) create mode 100644 crates/swc_ecma_transforms_compat/tests/arrow/empty-arguments/input.js diff --git a/crates/swc_ecma_transforms_compat/tests/arrow/empty-arguments/input.js b/crates/swc_ecma_transforms_compat/tests/arrow/empty-arguments/input.js new file mode 100644 index 000000000000..801aca71571b --- /dev/null +++ b/crates/swc_ecma_transforms_compat/tests/arrow/empty-arguments/input.js @@ -0,0 +1 @@ +var t = () => 5 + 5; \ No newline at end of file diff --git a/crates/swc_ecma_transforms_compat/tests/es2015_arrow.rs b/crates/swc_ecma_transforms_compat/tests/es2015_arrow.rs index a398ac0adce4..364feef2db09 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2015_arrow.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2015_arrow.rs @@ -12,16 +12,6 @@ fn tr() -> impl Fold { chain!(resolver(unresolved, global, false), arrow(unresolved)) } -test!( - ::swc_ecma_parser::Syntax::default(), - |_| arrow(Mark::new()), - empty_arguments, - r#"var t = () => 5 + 5;"#, - r#"var t = function () { - return 5 + 5; -};"# -); - test!( ::swc_ecma_parser::Syntax::default(), |_| arrow(Mark::new()), From 312b90e0548a19658130aeb7152a338563665448 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Fri, 18 Nov 2022 15:42:46 +0900 Subject: [PATCH 04/25] Move tests --- .../tests/arrow/expression/input.js | 1 + .../swc_ecma_transforms_compat/tests/es2015_arrow.rs | 10 ---------- 2 files changed, 1 insertion(+), 10 deletions(-) create mode 100644 crates/swc_ecma_transforms_compat/tests/arrow/expression/input.js diff --git a/crates/swc_ecma_transforms_compat/tests/arrow/expression/input.js b/crates/swc_ecma_transforms_compat/tests/arrow/expression/input.js new file mode 100644 index 000000000000..126c6c136401 --- /dev/null +++ b/crates/swc_ecma_transforms_compat/tests/arrow/expression/input.js @@ -0,0 +1 @@ +arr.map(x => x * x); \ No newline at end of file diff --git a/crates/swc_ecma_transforms_compat/tests/es2015_arrow.rs b/crates/swc_ecma_transforms_compat/tests/es2015_arrow.rs index 364feef2db09..779d3ca536f7 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2015_arrow.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2015_arrow.rs @@ -12,16 +12,6 @@ fn tr() -> impl Fold { chain!(resolver(unresolved, global, false), arrow(unresolved)) } -test!( - ::swc_ecma_parser::Syntax::default(), - |_| arrow(Mark::new()), - expression, - r#"arr.map(x => x * x);"#, - r#"arr.map(function (x) { - return x * x; -});"# -); - test!( ::swc_ecma_parser::Syntax::default(), |_| arrow(Mark::new()), From f8e5fc16538d074dc73440d1fe4b4e7f72bc0bc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Fri, 18 Nov 2022 15:43:28 +0900 Subject: [PATCH 05/25] Move tests --- .../tests/arrow/inside-call/input.js | 1 + .../tests/arrow/multiple-arguments/input.js | 1 + .../tests/es2015_arrow.rs | 54 ------------------- 3 files changed, 2 insertions(+), 54 deletions(-) create mode 100644 crates/swc_ecma_transforms_compat/tests/arrow/inside-call/input.js create mode 100644 crates/swc_ecma_transforms_compat/tests/arrow/multiple-arguments/input.js diff --git a/crates/swc_ecma_transforms_compat/tests/arrow/inside-call/input.js b/crates/swc_ecma_transforms_compat/tests/arrow/inside-call/input.js new file mode 100644 index 000000000000..74cf708f7606 --- /dev/null +++ b/crates/swc_ecma_transforms_compat/tests/arrow/inside-call/input.js @@ -0,0 +1 @@ +arr.map(i => i + 1); \ No newline at end of file diff --git a/crates/swc_ecma_transforms_compat/tests/arrow/multiple-arguments/input.js b/crates/swc_ecma_transforms_compat/tests/arrow/multiple-arguments/input.js new file mode 100644 index 000000000000..4c408ad1f24a --- /dev/null +++ b/crates/swc_ecma_transforms_compat/tests/arrow/multiple-arguments/input.js @@ -0,0 +1 @@ +var t = (i, x) => i * x; \ No newline at end of file diff --git a/crates/swc_ecma_transforms_compat/tests/es2015_arrow.rs b/crates/swc_ecma_transforms_compat/tests/es2015_arrow.rs index 779d3ca536f7..65d334865bd5 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2015_arrow.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2015_arrow.rs @@ -12,60 +12,6 @@ fn tr() -> impl Fold { chain!(resolver(unresolved, global, false), arrow(unresolved)) } -test!( - ::swc_ecma_parser::Syntax::default(), - |_| arrow(Mark::new()), - inside_call, - r#"arr.map(i => i + 1);"#, - r#"arr.map(function (i) { - return i + 1; -});"# -); - -test!( - ::swc_ecma_parser::Syntax::default(), - |_| arrow(Mark::new()), - multiple_arguments, - r#"var t = (i, x) => i * x;"#, - r#"var t = function (i, x) { - return i * x; -};"# -); - -// test!(::swc_ecma_parser::Syntax::default(), -// |_| arrow(Mark::new()), -// nested, -// r#"module.exports = { -// init: function () { -// return new Promise((resolve, reject) => { -// MongoClient.connect(config.mongodb, (err, db) => { -// if (err) { -// return reject(err); -// } -// this.db = db; -// resolve(this); -// }); -// }); -// } -// };"#, -// r#"module.exports = { -// init: function () { -// var _this = this; - -// return new Promise(function (resolve, reject) { -// MongoClient.connect(config.mongodb, function (err, db) { -// if (err) { -// return reject(err); -// } - -// _this.db = db; -// resolve(_this); -// }); -// }); -// } -// };"# -// ); - test!( ::swc_ecma_parser::Syntax::default(), |_| arrow(Mark::new()), From e8a4c4aa97f4e13c51cd1f7c5afe1c2a5c1b8e00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Fri, 18 Nov 2022 15:48:44 +0900 Subject: [PATCH 06/25] Move tests --- .../tests/arrow/arguments/input.js | 3 + .../tests/arrow/issue-413/input.js | 3 + .../tests/arrow/paren-insertion/input.js | 1 + .../tests/arrow/single-argument/input.js | 1 + .../tests/arrow/statement/input.js | 5 ++ .../tests/es2015_arrow.rs | 69 ------------------- 6 files changed, 13 insertions(+), 69 deletions(-) create mode 100644 crates/swc_ecma_transforms_compat/tests/arrow/arguments/input.js create mode 100644 crates/swc_ecma_transforms_compat/tests/arrow/issue-413/input.js create mode 100644 crates/swc_ecma_transforms_compat/tests/arrow/paren-insertion/input.js create mode 100644 crates/swc_ecma_transforms_compat/tests/arrow/single-argument/input.js create mode 100644 crates/swc_ecma_transforms_compat/tests/arrow/statement/input.js diff --git a/crates/swc_ecma_transforms_compat/tests/arrow/arguments/input.js b/crates/swc_ecma_transforms_compat/tests/arrow/arguments/input.js new file mode 100644 index 000000000000..3ed23c3b639d --- /dev/null +++ b/crates/swc_ecma_transforms_compat/tests/arrow/arguments/input.js @@ -0,0 +1,3 @@ +function test() { + return () => arguments[0]; +} \ No newline at end of file diff --git a/crates/swc_ecma_transforms_compat/tests/arrow/issue-413/input.js b/crates/swc_ecma_transforms_compat/tests/arrow/issue-413/input.js new file mode 100644 index 000000000000..41f466e759e1 --- /dev/null +++ b/crates/swc_ecma_transforms_compat/tests/arrow/issue-413/input.js @@ -0,0 +1,3 @@ +export const getBadgeBorderRadius = (text, color) => { + return (text && style) || {} +} \ No newline at end of file diff --git a/crates/swc_ecma_transforms_compat/tests/arrow/paren-insertion/input.js b/crates/swc_ecma_transforms_compat/tests/arrow/paren-insertion/input.js new file mode 100644 index 000000000000..f0b4aba4b4b7 --- /dev/null +++ b/crates/swc_ecma_transforms_compat/tests/arrow/paren-insertion/input.js @@ -0,0 +1 @@ +var t = i => i * 5; \ No newline at end of file diff --git a/crates/swc_ecma_transforms_compat/tests/arrow/single-argument/input.js b/crates/swc_ecma_transforms_compat/tests/arrow/single-argument/input.js new file mode 100644 index 000000000000..d6eda13c89fe --- /dev/null +++ b/crates/swc_ecma_transforms_compat/tests/arrow/single-argument/input.js @@ -0,0 +1 @@ +var t = (i) => i * 5; \ No newline at end of file diff --git a/crates/swc_ecma_transforms_compat/tests/arrow/statement/input.js b/crates/swc_ecma_transforms_compat/tests/arrow/statement/input.js new file mode 100644 index 000000000000..fc21a6527577 --- /dev/null +++ b/crates/swc_ecma_transforms_compat/tests/arrow/statement/input.js @@ -0,0 +1,5 @@ +nums.forEach(v => { + if (v % 5 === 0) { + fives.push(v); + } +}); \ No newline at end of file diff --git a/crates/swc_ecma_transforms_compat/tests/es2015_arrow.rs b/crates/swc_ecma_transforms_compat/tests/es2015_arrow.rs index 65d334865bd5..256fa8a861e1 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2015_arrow.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2015_arrow.rs @@ -12,75 +12,6 @@ fn tr() -> impl Fold { chain!(resolver(unresolved, global, false), arrow(unresolved)) } -test!( - ::swc_ecma_parser::Syntax::default(), - |_| arrow(Mark::new()), - paren_insertion, - r#"var t = i => i * 5;"#, - r#"var t = function (i) { - return i * 5; -};"# -); - -test!( - ::swc_ecma_parser::Syntax::default(), - |_| arrow(Mark::new()), - single_argument, - r#"var t = (i) => i * 5;"#, - r#"var t = function (i) { - return i * 5; -};"# -); - -test!( - ::swc_ecma_parser::Syntax::default(), - |_| arrow(Mark::new()), - statement, - r#"nums.forEach(v => { - if (v % 5 === 0) { - fives.push(v); - } -});"#, - r#"nums.forEach(function (v) { - if (v % 5 === 0) { - fives.push(v); - } -});"# -); - -test!( - ::swc_ecma_parser::Syntax::default(), - |_| arrow(Mark::new()), - issue_413, - r#" -export const getBadgeBorderRadius = (text, color) => { - return (text && style) || {} -}"#, - r#" -export const getBadgeBorderRadius = function(text, color) { - return text && style || { - }; -}; -"# -); - -test!( - ::swc_ecma_parser::Syntax::default(), - |_| tr(), - arguments, - r#" -function test() { - return () => arguments[0]; -}"#, - r#" - function test() { - var _arguments = arguments; - return function() { - return _arguments[0]; - } - }"# -); - compare_stdout!( ::swc_ecma_parser::Syntax::default(), |_| tr(), From 72303976b4d9830b5ce54ebc426780592dad7c3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Fri, 18 Nov 2022 15:49:15 +0900 Subject: [PATCH 07/25] Update test refs --- .../tests/arrow/arguments/output.js | 6 ++++++ .../swc_ecma_transforms_compat/tests/arrow/basic/output.js | 3 +++ .../tests/arrow/destructuring/output.js | 3 +++ .../tests/arrow/empty-arguments/output.js | 3 +++ .../tests/arrow/expression/output.js | 3 +++ .../tests/arrow/inside-call/output.js | 3 +++ .../tests/arrow/issue-233/output.js | 5 +++++ .../tests/arrow/issue-413/output.js | 3 +++ .../tests/arrow/multiple-arguments/output.js | 3 +++ .../tests/arrow/paren-insertion/output.js | 3 +++ .../tests/arrow/single-argument/output.js | 3 +++ .../tests/arrow/statement/output.js | 5 +++++ 12 files changed, 43 insertions(+) create mode 100644 crates/swc_ecma_transforms_compat/tests/arrow/arguments/output.js create mode 100644 crates/swc_ecma_transforms_compat/tests/arrow/basic/output.js create mode 100644 crates/swc_ecma_transforms_compat/tests/arrow/destructuring/output.js create mode 100644 crates/swc_ecma_transforms_compat/tests/arrow/empty-arguments/output.js create mode 100644 crates/swc_ecma_transforms_compat/tests/arrow/expression/output.js create mode 100644 crates/swc_ecma_transforms_compat/tests/arrow/inside-call/output.js create mode 100644 crates/swc_ecma_transforms_compat/tests/arrow/issue-233/output.js create mode 100644 crates/swc_ecma_transforms_compat/tests/arrow/issue-413/output.js create mode 100644 crates/swc_ecma_transforms_compat/tests/arrow/multiple-arguments/output.js create mode 100644 crates/swc_ecma_transforms_compat/tests/arrow/paren-insertion/output.js create mode 100644 crates/swc_ecma_transforms_compat/tests/arrow/single-argument/output.js create mode 100644 crates/swc_ecma_transforms_compat/tests/arrow/statement/output.js diff --git a/crates/swc_ecma_transforms_compat/tests/arrow/arguments/output.js b/crates/swc_ecma_transforms_compat/tests/arrow/arguments/output.js new file mode 100644 index 000000000000..6e382cbb7320 --- /dev/null +++ b/crates/swc_ecma_transforms_compat/tests/arrow/arguments/output.js @@ -0,0 +1,6 @@ +function test() { + var _arguments = arguments; + return function() { + return _arguments[0]; + }; +} diff --git a/crates/swc_ecma_transforms_compat/tests/arrow/basic/output.js b/crates/swc_ecma_transforms_compat/tests/arrow/basic/output.js new file mode 100644 index 000000000000..63235f7dbf85 --- /dev/null +++ b/crates/swc_ecma_transforms_compat/tests/arrow/basic/output.js @@ -0,0 +1,3 @@ +let echo = function(bar) { + return bar; +}; diff --git a/crates/swc_ecma_transforms_compat/tests/arrow/destructuring/output.js b/crates/swc_ecma_transforms_compat/tests/arrow/destructuring/output.js new file mode 100644 index 000000000000..75699c25cac5 --- /dev/null +++ b/crates/swc_ecma_transforms_compat/tests/arrow/destructuring/output.js @@ -0,0 +1,3 @@ +let foo = function({ bar }) { + return undefined; +}; diff --git a/crates/swc_ecma_transforms_compat/tests/arrow/empty-arguments/output.js b/crates/swc_ecma_transforms_compat/tests/arrow/empty-arguments/output.js new file mode 100644 index 000000000000..1aad3c29058d --- /dev/null +++ b/crates/swc_ecma_transforms_compat/tests/arrow/empty-arguments/output.js @@ -0,0 +1,3 @@ +var t = function() { + return 5 + 5; +}; diff --git a/crates/swc_ecma_transforms_compat/tests/arrow/expression/output.js b/crates/swc_ecma_transforms_compat/tests/arrow/expression/output.js new file mode 100644 index 000000000000..85f87d989ff3 --- /dev/null +++ b/crates/swc_ecma_transforms_compat/tests/arrow/expression/output.js @@ -0,0 +1,3 @@ +arr.map(function(x) { + return x * x; +}); diff --git a/crates/swc_ecma_transforms_compat/tests/arrow/inside-call/output.js b/crates/swc_ecma_transforms_compat/tests/arrow/inside-call/output.js new file mode 100644 index 000000000000..af30eb2ba358 --- /dev/null +++ b/crates/swc_ecma_transforms_compat/tests/arrow/inside-call/output.js @@ -0,0 +1,3 @@ +arr.map(function(i) { + return i + 1; +}); diff --git a/crates/swc_ecma_transforms_compat/tests/arrow/issue-233/output.js b/crates/swc_ecma_transforms_compat/tests/arrow/issue-233/output.js new file mode 100644 index 000000000000..ebefea790833 --- /dev/null +++ b/crates/swc_ecma_transforms_compat/tests/arrow/issue-233/output.js @@ -0,0 +1,5 @@ +const foo = function() { + return function({ x , ...y }) { + return y; + }; +}; diff --git a/crates/swc_ecma_transforms_compat/tests/arrow/issue-413/output.js b/crates/swc_ecma_transforms_compat/tests/arrow/issue-413/output.js new file mode 100644 index 000000000000..b281a498f5dd --- /dev/null +++ b/crates/swc_ecma_transforms_compat/tests/arrow/issue-413/output.js @@ -0,0 +1,3 @@ +export const getBadgeBorderRadius = function(text, color) { + return text && style || {}; +}; diff --git a/crates/swc_ecma_transforms_compat/tests/arrow/multiple-arguments/output.js b/crates/swc_ecma_transforms_compat/tests/arrow/multiple-arguments/output.js new file mode 100644 index 000000000000..80dfef4ea6f6 --- /dev/null +++ b/crates/swc_ecma_transforms_compat/tests/arrow/multiple-arguments/output.js @@ -0,0 +1,3 @@ +var t = function(i, x) { + return i * x; +}; diff --git a/crates/swc_ecma_transforms_compat/tests/arrow/paren-insertion/output.js b/crates/swc_ecma_transforms_compat/tests/arrow/paren-insertion/output.js new file mode 100644 index 000000000000..8c6195e0d3c7 --- /dev/null +++ b/crates/swc_ecma_transforms_compat/tests/arrow/paren-insertion/output.js @@ -0,0 +1,3 @@ +var t = function(i) { + return i * 5; +}; diff --git a/crates/swc_ecma_transforms_compat/tests/arrow/single-argument/output.js b/crates/swc_ecma_transforms_compat/tests/arrow/single-argument/output.js new file mode 100644 index 000000000000..8c6195e0d3c7 --- /dev/null +++ b/crates/swc_ecma_transforms_compat/tests/arrow/single-argument/output.js @@ -0,0 +1,3 @@ +var t = function(i) { + return i * 5; +}; diff --git a/crates/swc_ecma_transforms_compat/tests/arrow/statement/output.js b/crates/swc_ecma_transforms_compat/tests/arrow/statement/output.js new file mode 100644 index 000000000000..f055880460d2 --- /dev/null +++ b/crates/swc_ecma_transforms_compat/tests/arrow/statement/output.js @@ -0,0 +1,5 @@ +nums.forEach(function(v) { + if (v % 5 === 0) { + fives.push(v); + } +}); From 4d5f86e4fde029fb1c27458445002ca939ca6552 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Fri, 18 Nov 2022 15:54:01 +0900 Subject: [PATCH 08/25] Move tests --- .../tests/arrow/chrome-46/input.js | 3 ++ .../tests/arrow/method-captured/input.js | 7 +++ .../tests/es2015_arrow.rs | 49 ------------------- 3 files changed, 10 insertions(+), 49 deletions(-) create mode 100644 crates/swc_ecma_transforms_compat/tests/arrow/chrome-46/input.js create mode 100644 crates/swc_ecma_transforms_compat/tests/arrow/method-captured/input.js diff --git a/crates/swc_ecma_transforms_compat/tests/arrow/chrome-46/input.js b/crates/swc_ecma_transforms_compat/tests/arrow/chrome-46/input.js new file mode 100644 index 000000000000..bce42792e998 --- /dev/null +++ b/crates/swc_ecma_transforms_compat/tests/arrow/chrome-46/input.js @@ -0,0 +1,3 @@ +function foo() { + const a = (a) => new.target +} \ No newline at end of file diff --git a/crates/swc_ecma_transforms_compat/tests/arrow/method-captured/input.js b/crates/swc_ecma_transforms_compat/tests/arrow/method-captured/input.js new file mode 100644 index 000000000000..b26d2dd5981e --- /dev/null +++ b/crates/swc_ecma_transforms_compat/tests/arrow/method-captured/input.js @@ -0,0 +1,7 @@ +const a = () => ({ + [this](a = this) { this; arguments }, +}) +const b = () => class { + static [this]() { } + [arguments]() { } +} \ No newline at end of file diff --git a/crates/swc_ecma_transforms_compat/tests/es2015_arrow.rs b/crates/swc_ecma_transforms_compat/tests/es2015_arrow.rs index 256fa8a861e1..ad5100f423df 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2015_arrow.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2015_arrow.rs @@ -311,55 +311,6 @@ const a = function () { "# ); -test!( - ::swc_ecma_parser::Syntax::default(), - |_| arrow(Mark::new()), - method_computed, - r#" -const a = () => ({ - [this](a = this) { this;arguments }, -}) -const b = () => class { - static [this]() {} - [arguments]() {} -} -"#, - r#" -var _this = this; -const a = function () { - return { - [_this](a = this) { - this; - arguments; - } - }; -}; -const b = function() { - return class { - static [this]() {} - [arguments]() { - } - }; -}; -"# -); - -test!( - ::swc_ecma_parser::Syntax::default(), - |_| arrow(Mark::new()), - chrome_46, - "function foo() { - const a = (a) => new.target - }", - "function foo() { - var _newtarget = new.target; - - const a = function (a) { - return _newtarget; - }; - }" -); - #[testing::fixture("tests/arrow/**/input.js")] fn fixture(input: PathBuf) { let output = input.with_file_name("output.js"); From 2baa2172f991a2af4de3447c75d82496071ba888 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Fri, 18 Nov 2022 15:54:49 +0900 Subject: [PATCH 09/25] Move tests --- .../tests/arrow/getter-setter/input.js | 5 ++ .../tests/arrow/this-in-params/input.js | 3 ++ .../tests/es2015_arrow.rs | 51 ------------------- 3 files changed, 8 insertions(+), 51 deletions(-) create mode 100644 crates/swc_ecma_transforms_compat/tests/arrow/getter-setter/input.js create mode 100644 crates/swc_ecma_transforms_compat/tests/arrow/this-in-params/input.js diff --git a/crates/swc_ecma_transforms_compat/tests/arrow/getter-setter/input.js b/crates/swc_ecma_transforms_compat/tests/arrow/getter-setter/input.js new file mode 100644 index 000000000000..c7f11d22484b --- /dev/null +++ b/crates/swc_ecma_transforms_compat/tests/arrow/getter-setter/input.js @@ -0,0 +1,5 @@ +const a = () => ({ + get this() { this; arguments }, + set arguments(a = this) { this; arguments }, + get [this]() { this; arguments }, +}) \ No newline at end of file diff --git a/crates/swc_ecma_transforms_compat/tests/arrow/this-in-params/input.js b/crates/swc_ecma_transforms_compat/tests/arrow/this-in-params/input.js new file mode 100644 index 000000000000..54f9bc7592b9 --- /dev/null +++ b/crates/swc_ecma_transforms_compat/tests/arrow/this-in-params/input.js @@ -0,0 +1,3 @@ +export const getBadgeBorderRadius = (text = this, color = arguments) => { + return (text && style) || {} +} \ No newline at end of file diff --git a/crates/swc_ecma_transforms_compat/tests/es2015_arrow.rs b/crates/swc_ecma_transforms_compat/tests/es2015_arrow.rs index ad5100f423df..8ddb77188594 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2015_arrow.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2015_arrow.rs @@ -260,57 +260,6 @@ var a = { "# ); -test!( - ::swc_ecma_parser::Syntax::default(), - |_| tr(), - this_in_params, - r#" -export const getBadgeBorderRadius = (text = this, color = arguments) => { - return (text && style) || {} -}"#, - r#" -var _this = this, _arguments = arguments; -export const getBadgeBorderRadius = function(text = _this, color = _arguments) { - return text && style || { - }; -}; -"# -); - -test!( - ::swc_ecma_parser::Syntax::default(), - |_| arrow(Mark::new()), - getter_setter, - r#" -const a = () => ({ - get this() { this;arguments }, - set arguments(a = this) { this;arguments }, - get [this]() { this;arguments }, -}) -"#, - r#" -var _this = this; -const a = function () { - return { - get this() { - this; - arguments; - }, - - set arguments(a = this) { - this; - arguments; - }, - - get [_this] () { - this; - arguments; - } - }; -}; -"# -); - #[testing::fixture("tests/arrow/**/input.js")] fn fixture(input: PathBuf) { let output = input.with_file_name("output.js"); From 49994e1e8ab2c0d2141fcb57d92069fde6d66768 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Fri, 18 Nov 2022 15:55:35 +0900 Subject: [PATCH 10/25] Move tests --- .../tests/arrow/arguments-fn-expr/input.js | 5 +++ .../tests/arrow/arguments-member/input.js | 5 +++ .../tests/es2015_arrow.rs | 36 ------------------- 3 files changed, 10 insertions(+), 36 deletions(-) create mode 100644 crates/swc_ecma_transforms_compat/tests/arrow/arguments-fn-expr/input.js create mode 100644 crates/swc_ecma_transforms_compat/tests/arrow/arguments-member/input.js diff --git a/crates/swc_ecma_transforms_compat/tests/arrow/arguments-fn-expr/input.js b/crates/swc_ecma_transforms_compat/tests/arrow/arguments-fn-expr/input.js new file mode 100644 index 000000000000..33bc51ece156 --- /dev/null +++ b/crates/swc_ecma_transforms_compat/tests/arrow/arguments-fn-expr/input.js @@ -0,0 +1,5 @@ +function test() { + return function () { + return arguments[0]; + }; +} \ No newline at end of file diff --git a/crates/swc_ecma_transforms_compat/tests/arrow/arguments-member/input.js b/crates/swc_ecma_transforms_compat/tests/arrow/arguments-member/input.js new file mode 100644 index 000000000000..95a359b78d93 --- /dev/null +++ b/crates/swc_ecma_transforms_compat/tests/arrow/arguments-member/input.js @@ -0,0 +1,5 @@ +function test() { + return (foo) => { + return foo.arguments; + } +} \ No newline at end of file diff --git a/crates/swc_ecma_transforms_compat/tests/es2015_arrow.rs b/crates/swc_ecma_transforms_compat/tests/es2015_arrow.rs index 8ddb77188594..f02fd5d5e743 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2015_arrow.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2015_arrow.rs @@ -52,42 +52,6 @@ compare_stdout!( " ); -test!( - ::swc_ecma_parser::Syntax::default(), - |_| arrow(Mark::new()), - arguments_member, - r#" - function test() { - return (foo) => { - return foo.arguments; - } - }"#, - r#" - function test() { - return function(foo) { - return foo.arguments; - }; - }"# -); - -test!( - ::swc_ecma_parser::Syntax::default(), - |_| arrow(Mark::new()), - arguments_fn_expr, - r#" - function test() { - return function() { - return arguments[0]; - }; - }"#, - r#" - function test() { - return function() { - return arguments[0]; - }; - }"# -); - test!( ::swc_ecma_parser::Syntax::default(), |_| arrow(Mark::new()), From 71d8029d10fc9dafe101c81a28f49e697ef0c50a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Fri, 18 Nov 2022 15:56:58 +0900 Subject: [PATCH 11/25] Move tests --- .../tests/arrow/computed-props/input.js | 3 + .../tests/arrow/fixture-this/input.js | 16 +++ .../tests/arrow/issue-2212-1/input.js | 1 + .../tests/arrow/issue-2212-2/input.js | 3 + .../tests/es2015_arrow.rs | 107 ------------------ 5 files changed, 23 insertions(+), 107 deletions(-) create mode 100644 crates/swc_ecma_transforms_compat/tests/arrow/computed-props/input.js create mode 100644 crates/swc_ecma_transforms_compat/tests/arrow/fixture-this/input.js create mode 100644 crates/swc_ecma_transforms_compat/tests/arrow/issue-2212-1/input.js create mode 100644 crates/swc_ecma_transforms_compat/tests/arrow/issue-2212-2/input.js diff --git a/crates/swc_ecma_transforms_compat/tests/arrow/computed-props/input.js b/crates/swc_ecma_transforms_compat/tests/arrow/computed-props/input.js new file mode 100644 index 000000000000..acf561f4e419 --- /dev/null +++ b/crates/swc_ecma_transforms_compat/tests/arrow/computed-props/input.js @@ -0,0 +1,3 @@ +var a = { + [(() => this)()]: 123 +} \ No newline at end of file diff --git a/crates/swc_ecma_transforms_compat/tests/arrow/fixture-this/input.js b/crates/swc_ecma_transforms_compat/tests/arrow/fixture-this/input.js new file mode 100644 index 000000000000..8136b60c5d29 --- /dev/null +++ b/crates/swc_ecma_transforms_compat/tests/arrow/fixture-this/input.js @@ -0,0 +1,16 @@ +function b() { + var t = x => this.x + x; +} + +class Foo extends (function () { }) { + constructor() { + var foo = () => this; + + if (true) { + console.log(super(), foo()); + } else { + super(); + console.log(foo()); + } + } +} \ No newline at end of file diff --git a/crates/swc_ecma_transforms_compat/tests/arrow/issue-2212-1/input.js b/crates/swc_ecma_transforms_compat/tests/arrow/issue-2212-1/input.js new file mode 100644 index 000000000000..fc8a6cd666f2 --- /dev/null +++ b/crates/swc_ecma_transforms_compat/tests/arrow/issue-2212-1/input.js @@ -0,0 +1 @@ +const foo = () => this \ No newline at end of file diff --git a/crates/swc_ecma_transforms_compat/tests/arrow/issue-2212-2/input.js b/crates/swc_ecma_transforms_compat/tests/arrow/issue-2212-2/input.js new file mode 100644 index 000000000000..6448cb07d95b --- /dev/null +++ b/crates/swc_ecma_transforms_compat/tests/arrow/issue-2212-2/input.js @@ -0,0 +1,3 @@ +const foo = function () { + () => () => () => this +} \ No newline at end of file diff --git a/crates/swc_ecma_transforms_compat/tests/es2015_arrow.rs b/crates/swc_ecma_transforms_compat/tests/es2015_arrow.rs index f02fd5d5e743..8929feb70940 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2015_arrow.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2015_arrow.rs @@ -52,93 +52,6 @@ compare_stdout!( " ); -test!( - ::swc_ecma_parser::Syntax::default(), - |_| arrow(Mark::new()), - issue_2212_1, - "const foo = () => this", - " - var _this = this; - const foo = function() { - return _this; - }; - " -); - -test!( - ::swc_ecma_parser::Syntax::default(), - |_| arrow(Mark::new()), - issue_2212_2, - " - const foo = function (){ - () => () => () => this - } - ", - " - const foo = function() { - var _this = this; - (function() { - return function() { - return function() { - return _this; - }; - }; - }); - }; - " -); - -test!( - ::swc_ecma_parser::Syntax::default(), - |_| arrow(Mark::new()), - fixture_this, - r#" -function b() { - var t = x => this.x + x; -} - -class Foo extends (function(){}) { - constructor(){ - var foo = () => this; - - if (true){ - console.log(super(), foo()); - } else { - super(); - console.log(foo()); - } - } -} -"#, - r#" -function b() { - var _this = this; - - var t = function (x) { - return _this.x + x; - }; -} - -class Foo extends function () {} { - constructor() { - var _this; - - var foo = function () { - return _this; - }; - - if (true) { - console.log((super(), _this = this), foo()); - } else { - super(), _this = this; - console.log(foo()); - } - } - -} -"# -); - test!( ::swc_ecma_parser::Syntax::default(), |_| tr(), @@ -204,26 +117,6 @@ let bar1 = function () { "# ); -test!( - ::swc_ecma_parser::Syntax::default(), - |_| arrow(Mark::new()), - computed_props, - r#" -var a = { - [(() => this)()]: 123 -} -"#, - r#" -var _this = this; - -var a = { - [function () { - return _this; - }()]: 123 -}; -"# -); - #[testing::fixture("tests/arrow/**/input.js")] fn fixture(input: PathBuf) { let output = input.with_file_name("output.js"); From 0afae3ebc6518ba7d58a29682747939908ec3f57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Fri, 18 Nov 2022 15:57:45 +0900 Subject: [PATCH 12/25] Move tests --- .../tests/arrow/fixture-arguments/input.js | 9 +++ .../tests/arrow/two-arrow/imput.js | 4 ++ .../tests/es2015_arrow.rs | 65 ------------------- 3 files changed, 13 insertions(+), 65 deletions(-) create mode 100644 crates/swc_ecma_transforms_compat/tests/arrow/fixture-arguments/input.js create mode 100644 crates/swc_ecma_transforms_compat/tests/arrow/two-arrow/imput.js diff --git a/crates/swc_ecma_transforms_compat/tests/arrow/fixture-arguments/input.js b/crates/swc_ecma_transforms_compat/tests/arrow/fixture-arguments/input.js new file mode 100644 index 000000000000..6682461393f6 --- /dev/null +++ b/crates/swc_ecma_transforms_compat/tests/arrow/fixture-arguments/input.js @@ -0,0 +1,9 @@ +function fn() { + var foo = () => { + return arguments; + }; +} + +var bar = () => arguments; + +var baz = () => () => arguments; \ No newline at end of file diff --git a/crates/swc_ecma_transforms_compat/tests/arrow/two-arrow/imput.js b/crates/swc_ecma_transforms_compat/tests/arrow/two-arrow/imput.js new file mode 100644 index 000000000000..976ec5169d3f --- /dev/null +++ b/crates/swc_ecma_transforms_compat/tests/arrow/two-arrow/imput.js @@ -0,0 +1,4 @@ +let foo = () => this; +let bar = () => this; +let foo1 = () => arguments; +let bar1 = () => arguments; \ No newline at end of file diff --git a/crates/swc_ecma_transforms_compat/tests/es2015_arrow.rs b/crates/swc_ecma_transforms_compat/tests/es2015_arrow.rs index 8929feb70940..edf525180c39 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2015_arrow.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2015_arrow.rs @@ -52,71 +52,6 @@ compare_stdout!( " ); -test!( - ::swc_ecma_parser::Syntax::default(), - |_| tr(), - fixture_arguments, - r#" -function fn() { - var foo = () => { - return arguments; - }; -} - -var bar = () => arguments; - -var baz = () => () => arguments; -"#, - r#" -var _arguments = arguments; - -function fn() { - var _arguments = arguments; - - var foo = function () { - return _arguments; - }; -} - -var bar = function () { - return _arguments; -}; - -var baz = function () { - return function () { - return _arguments; - }; -}; -"# -); - -test!( - ::swc_ecma_parser::Syntax::default(), - |_| tr(), - two_arrow, - r#" -let foo = () => this; -let bar = () => this; -let foo1 = () => arguments; -let bar1 = () => arguments; -"#, - r#" -var _this = this, _arguments = arguments; -let foo = function () { - return _this; -} -let bar = function () { - return _this; -} -let foo1 = function () { - return _arguments; -} -let bar1 = function () { - return _arguments; -} -"# -); - #[testing::fixture("tests/arrow/**/input.js")] fn fixture(input: PathBuf) { let output = input.with_file_name("output.js"); From 3bf8e4b4ac1bcb5ac7bfdba28874ccbe44b4869f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Fri, 18 Nov 2022 15:57:58 +0900 Subject: [PATCH 13/25] Update test refs --- .../tests/arrow/arguments-fn-expr/output.js | 5 +++++ .../tests/arrow/arguments-member/output.js | 5 +++++ .../tests/arrow/chrome-46/output.js | 6 ++++++ .../tests/arrow/computed-props/output.js | 6 ++++++ .../tests/arrow/fixture-arguments/output.js | 15 ++++++++++++++ .../tests/arrow/fixture-this/output.js | 20 +++++++++++++++++++ .../tests/arrow/getter-setter/output.js | 17 ++++++++++++++++ .../tests/arrow/issue-2212-1/output.js | 4 ++++ .../tests/arrow/issue-2212-2/output.js | 10 ++++++++++ .../tests/arrow/method-captured/output.js | 15 ++++++++++++++ .../tests/arrow/this-in-params/output.js | 4 ++++ 11 files changed, 107 insertions(+) create mode 100644 crates/swc_ecma_transforms_compat/tests/arrow/arguments-fn-expr/output.js create mode 100644 crates/swc_ecma_transforms_compat/tests/arrow/arguments-member/output.js create mode 100644 crates/swc_ecma_transforms_compat/tests/arrow/chrome-46/output.js create mode 100644 crates/swc_ecma_transforms_compat/tests/arrow/computed-props/output.js create mode 100644 crates/swc_ecma_transforms_compat/tests/arrow/fixture-arguments/output.js create mode 100644 crates/swc_ecma_transforms_compat/tests/arrow/fixture-this/output.js create mode 100644 crates/swc_ecma_transforms_compat/tests/arrow/getter-setter/output.js create mode 100644 crates/swc_ecma_transforms_compat/tests/arrow/issue-2212-1/output.js create mode 100644 crates/swc_ecma_transforms_compat/tests/arrow/issue-2212-2/output.js create mode 100644 crates/swc_ecma_transforms_compat/tests/arrow/method-captured/output.js create mode 100644 crates/swc_ecma_transforms_compat/tests/arrow/this-in-params/output.js diff --git a/crates/swc_ecma_transforms_compat/tests/arrow/arguments-fn-expr/output.js b/crates/swc_ecma_transforms_compat/tests/arrow/arguments-fn-expr/output.js new file mode 100644 index 000000000000..58710ad951fa --- /dev/null +++ b/crates/swc_ecma_transforms_compat/tests/arrow/arguments-fn-expr/output.js @@ -0,0 +1,5 @@ +function test() { + return function() { + return arguments[0]; + }; +} diff --git a/crates/swc_ecma_transforms_compat/tests/arrow/arguments-member/output.js b/crates/swc_ecma_transforms_compat/tests/arrow/arguments-member/output.js new file mode 100644 index 000000000000..2324ee8e6a41 --- /dev/null +++ b/crates/swc_ecma_transforms_compat/tests/arrow/arguments-member/output.js @@ -0,0 +1,5 @@ +function test() { + return function(foo) { + return foo.arguments; + }; +} diff --git a/crates/swc_ecma_transforms_compat/tests/arrow/chrome-46/output.js b/crates/swc_ecma_transforms_compat/tests/arrow/chrome-46/output.js new file mode 100644 index 000000000000..22c41df1da7c --- /dev/null +++ b/crates/swc_ecma_transforms_compat/tests/arrow/chrome-46/output.js @@ -0,0 +1,6 @@ +function foo() { + var _newtarget = new.target; + const a = function(a) { + return _newtarget; + }; +} diff --git a/crates/swc_ecma_transforms_compat/tests/arrow/computed-props/output.js b/crates/swc_ecma_transforms_compat/tests/arrow/computed-props/output.js new file mode 100644 index 000000000000..3279d0cce111 --- /dev/null +++ b/crates/swc_ecma_transforms_compat/tests/arrow/computed-props/output.js @@ -0,0 +1,6 @@ +var _this = this; +var a = { + [function() { + return _this; + }()]: 123 +}; diff --git a/crates/swc_ecma_transforms_compat/tests/arrow/fixture-arguments/output.js b/crates/swc_ecma_transforms_compat/tests/arrow/fixture-arguments/output.js new file mode 100644 index 000000000000..eb7fd52a4384 --- /dev/null +++ b/crates/swc_ecma_transforms_compat/tests/arrow/fixture-arguments/output.js @@ -0,0 +1,15 @@ +var _arguments = arguments; +function fn() { + var _arguments = arguments; + var foo = function() { + return _arguments; + }; +} +var bar = function() { + return _arguments; +}; +var baz = function() { + return function() { + return _arguments; + }; +}; diff --git a/crates/swc_ecma_transforms_compat/tests/arrow/fixture-this/output.js b/crates/swc_ecma_transforms_compat/tests/arrow/fixture-this/output.js new file mode 100644 index 000000000000..fe4f41c291c2 --- /dev/null +++ b/crates/swc_ecma_transforms_compat/tests/arrow/fixture-this/output.js @@ -0,0 +1,20 @@ +function b() { + var _this = this; + var t = function(x) { + return _this.x + x; + }; +} +class Foo extends function() {} { + constructor(){ + var _this; + var foo = function() { + return _this; + }; + if (true) { + console.log((super(), _this = this), foo()); + } else { + super(), _this = this; + console.log(foo()); + } + } +} diff --git a/crates/swc_ecma_transforms_compat/tests/arrow/getter-setter/output.js b/crates/swc_ecma_transforms_compat/tests/arrow/getter-setter/output.js new file mode 100644 index 000000000000..7022a56c94c2 --- /dev/null +++ b/crates/swc_ecma_transforms_compat/tests/arrow/getter-setter/output.js @@ -0,0 +1,17 @@ +var _this = this; +const a1 = function() { + return { + get this () { + this; + arguments; + }, + set arguments (a = this){ + this; + arguments; + }, + get [_this] () { + this; + arguments; + } + }; +}; diff --git a/crates/swc_ecma_transforms_compat/tests/arrow/issue-2212-1/output.js b/crates/swc_ecma_transforms_compat/tests/arrow/issue-2212-1/output.js new file mode 100644 index 000000000000..471f59ad0ab2 --- /dev/null +++ b/crates/swc_ecma_transforms_compat/tests/arrow/issue-2212-1/output.js @@ -0,0 +1,4 @@ +var _this = this; +const foo = function() { + return _this; +}; diff --git a/crates/swc_ecma_transforms_compat/tests/arrow/issue-2212-2/output.js b/crates/swc_ecma_transforms_compat/tests/arrow/issue-2212-2/output.js new file mode 100644 index 000000000000..f170e04b2193 --- /dev/null +++ b/crates/swc_ecma_transforms_compat/tests/arrow/issue-2212-2/output.js @@ -0,0 +1,10 @@ +const foo = function() { + var _this = this; + (function() { + return function() { + return function() { + return _this; + }; + }; + }); +}; diff --git a/crates/swc_ecma_transforms_compat/tests/arrow/method-captured/output.js b/crates/swc_ecma_transforms_compat/tests/arrow/method-captured/output.js new file mode 100644 index 000000000000..f12198eb00b4 --- /dev/null +++ b/crates/swc_ecma_transforms_compat/tests/arrow/method-captured/output.js @@ -0,0 +1,15 @@ +var _this = this; +const a = function() { + return { + [_this] (a = this) { + this; + arguments; + } + }; +}; +const b = function() { + return class { + static [this]() {} + [arguments]() {} + }; +}; diff --git a/crates/swc_ecma_transforms_compat/tests/arrow/this-in-params/output.js b/crates/swc_ecma_transforms_compat/tests/arrow/this-in-params/output.js new file mode 100644 index 000000000000..111a4a627cdd --- /dev/null +++ b/crates/swc_ecma_transforms_compat/tests/arrow/this-in-params/output.js @@ -0,0 +1,4 @@ +var _this = this, _arguments = arguments; +export const getBadgeBorderRadius = function(text = _this, color = _arguments) { + return text && style || {}; +}; From 45c8261e97c7f5ab2e8b722112d621da8e0b60aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Fri, 18 Nov 2022 15:58:42 +0900 Subject: [PATCH 14/25] Update test refs --- .../tests/arrow/two-arrow/{imput.js => input.js} | 0 .../tests/arrow/two-arrow/output.js | 13 +++++++++++++ 2 files changed, 13 insertions(+) rename crates/swc_ecma_transforms_compat/tests/arrow/two-arrow/{imput.js => input.js} (100%) create mode 100644 crates/swc_ecma_transforms_compat/tests/arrow/two-arrow/output.js diff --git a/crates/swc_ecma_transforms_compat/tests/arrow/two-arrow/imput.js b/crates/swc_ecma_transforms_compat/tests/arrow/two-arrow/input.js similarity index 100% rename from crates/swc_ecma_transforms_compat/tests/arrow/two-arrow/imput.js rename to crates/swc_ecma_transforms_compat/tests/arrow/two-arrow/input.js diff --git a/crates/swc_ecma_transforms_compat/tests/arrow/two-arrow/output.js b/crates/swc_ecma_transforms_compat/tests/arrow/two-arrow/output.js new file mode 100644 index 000000000000..7326ff079875 --- /dev/null +++ b/crates/swc_ecma_transforms_compat/tests/arrow/two-arrow/output.js @@ -0,0 +1,13 @@ +var _this = this, _arguments = arguments; +let foo = function() { + return _this; +}; +let bar = function() { + return _this; +}; +let foo1 = function() { + return _arguments; +}; +let bar1 = function() { + return _arguments; +}; From 4598f72447072c603b50347ccc428ef1f7531f36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Fri, 18 Nov 2022 16:09:55 +0900 Subject: [PATCH 15/25] Typo --- crates/swc_ecma_transforms_compat/tests/es2015_classes.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/swc_ecma_transforms_compat/tests/es2015_classes.rs b/crates/swc_ecma_transforms_compat/tests/es2015_classes.rs index 7c527c43c57e..eb1fa6b68c77 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2015_classes.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2015_classes.rs @@ -5319,7 +5319,7 @@ const obj = new Obj(); expect(() => { obj.call(); - // Asser that this throws, but that it's not + // Assert that this throws, but that it's not // a gobbledygook error that is thrown }).toThrowError(TypeError) From 384dfa2d2c9eb4e41faab6dad186d6f8d693ad0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Fri, 18 Nov 2022 16:18:23 +0900 Subject: [PATCH 16/25] Move tests --- .../tests/es2015_new_target.rs | 36 ------------------- .../tests/new-target/edge-12/input.js | 3 ++ .../tests/new-target/issue-4193/input.js | 9 +++++ 3 files changed, 12 insertions(+), 36 deletions(-) create mode 100644 crates/swc_ecma_transforms_compat/tests/new-target/edge-12/input.js create mode 100644 crates/swc_ecma_transforms_compat/tests/new-target/issue-4193/input.js diff --git a/crates/swc_ecma_transforms_compat/tests/es2015_new_target.rs b/crates/swc_ecma_transforms_compat/tests/es2015_new_target.rs index 5a165b66d889..2c43d5f21465 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2015_new_target.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2015_new_target.rs @@ -107,42 +107,6 @@ fn fixture(input: PathBuf) { ) } -test!( - ::swc_ecma_parser::Syntax::default(), - |_| new_target(), - edge_12, - r#"function foo() { - const a = () => new.target - }"#, - r#"function foo() { - const a = () => this instanceof foo ? this.constructor : void 0 - }"# -); - -test!( - ::swc_ecma_parser::Syntax::default(), - |_| new_target(), - issue_4193, - r#"const v0 = Symbol("Context#bar"); - module.exports = { - get bar() { - if (new.target === "foo") { - return; - } - return new Proxy(this, v0); - } - };"#, - r#"const v0 = Symbol("Context#bar"); - module.exports = { - get bar() { - if (void 0 === "foo") { - return; - } - return new Proxy(this, v0); - } - };"# -); - test!( ::swc_ecma_parser::Syntax::default(), |_| new_target(), diff --git a/crates/swc_ecma_transforms_compat/tests/new-target/edge-12/input.js b/crates/swc_ecma_transforms_compat/tests/new-target/edge-12/input.js new file mode 100644 index 000000000000..0916684d717b --- /dev/null +++ b/crates/swc_ecma_transforms_compat/tests/new-target/edge-12/input.js @@ -0,0 +1,3 @@ +function foo() { + const a = () => new.target +} \ No newline at end of file diff --git a/crates/swc_ecma_transforms_compat/tests/new-target/issue-4193/input.js b/crates/swc_ecma_transforms_compat/tests/new-target/issue-4193/input.js new file mode 100644 index 000000000000..7523652edf99 --- /dev/null +++ b/crates/swc_ecma_transforms_compat/tests/new-target/issue-4193/input.js @@ -0,0 +1,9 @@ +const v0 = Symbol("Context#bar"); +module.exports = { + get bar() { + if (new.target === "foo") { + return; + } + return new Proxy(this, v0); + } +}; \ No newline at end of file From 0c57070998f4fa2d8977d99d08633689b3ec65a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Fri, 18 Nov 2022 16:18:45 +0900 Subject: [PATCH 17/25] Update test refs --- .../tests/new-target/edge-12/output.js | 3 +++ .../tests/new-target/issue-4193/output.js | 9 +++++++++ 2 files changed, 12 insertions(+) create mode 100644 crates/swc_ecma_transforms_compat/tests/new-target/edge-12/output.js create mode 100644 crates/swc_ecma_transforms_compat/tests/new-target/issue-4193/output.js diff --git a/crates/swc_ecma_transforms_compat/tests/new-target/edge-12/output.js b/crates/swc_ecma_transforms_compat/tests/new-target/edge-12/output.js new file mode 100644 index 000000000000..14816e55bd58 --- /dev/null +++ b/crates/swc_ecma_transforms_compat/tests/new-target/edge-12/output.js @@ -0,0 +1,3 @@ +function foo() { + const a = ()=>this instanceof foo ? this.constructor : void 0; +} diff --git a/crates/swc_ecma_transforms_compat/tests/new-target/issue-4193/output.js b/crates/swc_ecma_transforms_compat/tests/new-target/issue-4193/output.js new file mode 100644 index 000000000000..15513ac4ca6f --- /dev/null +++ b/crates/swc_ecma_transforms_compat/tests/new-target/issue-4193/output.js @@ -0,0 +1,9 @@ +const v0 = Symbol("Context#bar"); +module.exports = { + get bar () { + if (void 0 === "foo") { + return; + } + return new Proxy(this, v0); + } +}; From 9714002ff260cf01958831719713a52bf8844a14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Fri, 18 Nov 2022 16:19:36 +0900 Subject: [PATCH 18/25] Move tests --- .../tests/es2015_new_target.rs | 27 ------------------- .../tests/new-target/edge-13/input.js | 9 +++++++ .../tests/new-target/edge-13/output.js | 8 ++++++ 3 files changed, 17 insertions(+), 27 deletions(-) create mode 100644 crates/swc_ecma_transforms_compat/tests/new-target/edge-13/input.js create mode 100644 crates/swc_ecma_transforms_compat/tests/new-target/edge-13/output.js diff --git a/crates/swc_ecma_transforms_compat/tests/es2015_new_target.rs b/crates/swc_ecma_transforms_compat/tests/es2015_new_target.rs index 2c43d5f21465..057b8e033f54 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2015_new_target.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2015_new_target.rs @@ -107,33 +107,6 @@ fn fixture(input: PathBuf) { ) } -test!( - ::swc_ecma_parser::Syntax::default(), - |_| new_target(), - edge_13, - r#" -class A { - foo() { - return () => new.target - } - - constructor() { - () => new.target - } -} -"#, - r#" -class A { - foo() { - return ()=>void 0; - } - constructor(){ - ()=>this.constructor; - } -} -"# -); - test!( ::swc_ecma_parser::Syntax::default(), |t| chain!( diff --git a/crates/swc_ecma_transforms_compat/tests/new-target/edge-13/input.js b/crates/swc_ecma_transforms_compat/tests/new-target/edge-13/input.js new file mode 100644 index 000000000000..cc73e4d1a4cd --- /dev/null +++ b/crates/swc_ecma_transforms_compat/tests/new-target/edge-13/input.js @@ -0,0 +1,9 @@ +class A { + foo() { + return () => new.target + } + + constructor() { + () => new.target + } +} \ No newline at end of file diff --git a/crates/swc_ecma_transforms_compat/tests/new-target/edge-13/output.js b/crates/swc_ecma_transforms_compat/tests/new-target/edge-13/output.js new file mode 100644 index 000000000000..73976d3fcd96 --- /dev/null +++ b/crates/swc_ecma_transforms_compat/tests/new-target/edge-13/output.js @@ -0,0 +1,8 @@ +class A { + foo() { + return ()=>void 0; + } + constructor(){ + ()=>this.constructor; + } +} From 94986e305adbc552a0e5f7da27a8ab2aaf61d2cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Fri, 18 Nov 2022 16:22:37 +0900 Subject: [PATCH 19/25] WIP: Rename files --- .../{es2015_block_scoping.rs => todo_es2015_block_scoping.rs} | 0 .../tests/{es2015_classes.rs => todo_es2015_classes.rs} | 0 .../{es2015_computed_props.rs => todo_es2015_computed_props.rs} | 0 .../{es2015_destructuring.rs => todo_es2015_destructuring.rs} | 0 .../{es2015_duplicated_keys.rs => todo_es2015_duplicated_keys.rs} | 0 .../tests/{es2015_for_of.rs => todo_es2015_for_of.rs} | 0 .../tests/{es2015_generator.rs => todo_es2015_generator.rs} | 0 .../tests/{es2015_object_super.rs => todo_es2015_object_super.rs} | 0 .../tests/{es2015_parameters.rs => todo_es2015_parameters.rs} | 0 .../tests/{es2015_spread.rs => todo_es2015_spread.rs} | 0 ...2015_template_literals.rs => todo_es2015_template_literals.rs} | 0 ...17_async_to_generator.rs => todo_es2017_async_to_generator.rs} | 0 ...18_object_rest_spread.rs => todo_es2018_object_rest_spread.rs} | 0 ...20_nullish_coalescing.rs => todo_es2020_nullish_coalescing.rs} | 0 ...2020_optional_chaining.rs => todo_es2020_optional_chaining.rs} | 0 ...21_logcal_assignments.rs => todo_es2021_logcal_assignments.rs} | 0 ...es2022_class_properties.rs => todo_es2022_class_properties.rs} | 0 17 files changed, 0 insertions(+), 0 deletions(-) rename crates/swc_ecma_transforms_compat/tests/{es2015_block_scoping.rs => todo_es2015_block_scoping.rs} (100%) rename crates/swc_ecma_transforms_compat/tests/{es2015_classes.rs => todo_es2015_classes.rs} (100%) rename crates/swc_ecma_transforms_compat/tests/{es2015_computed_props.rs => todo_es2015_computed_props.rs} (100%) rename crates/swc_ecma_transforms_compat/tests/{es2015_destructuring.rs => todo_es2015_destructuring.rs} (100%) rename crates/swc_ecma_transforms_compat/tests/{es2015_duplicated_keys.rs => todo_es2015_duplicated_keys.rs} (100%) rename crates/swc_ecma_transforms_compat/tests/{es2015_for_of.rs => todo_es2015_for_of.rs} (100%) rename crates/swc_ecma_transforms_compat/tests/{es2015_generator.rs => todo_es2015_generator.rs} (100%) rename crates/swc_ecma_transforms_compat/tests/{es2015_object_super.rs => todo_es2015_object_super.rs} (100%) rename crates/swc_ecma_transforms_compat/tests/{es2015_parameters.rs => todo_es2015_parameters.rs} (100%) rename crates/swc_ecma_transforms_compat/tests/{es2015_spread.rs => todo_es2015_spread.rs} (100%) rename crates/swc_ecma_transforms_compat/tests/{es2015_template_literals.rs => todo_es2015_template_literals.rs} (100%) rename crates/swc_ecma_transforms_compat/tests/{es2017_async_to_generator.rs => todo_es2017_async_to_generator.rs} (100%) rename crates/swc_ecma_transforms_compat/tests/{es2018_object_rest_spread.rs => todo_es2018_object_rest_spread.rs} (100%) rename crates/swc_ecma_transforms_compat/tests/{es2020_nullish_coalescing.rs => todo_es2020_nullish_coalescing.rs} (100%) rename crates/swc_ecma_transforms_compat/tests/{es2020_optional_chaining.rs => todo_es2020_optional_chaining.rs} (100%) rename crates/swc_ecma_transforms_compat/tests/{es2021_logcal_assignments.rs => todo_es2021_logcal_assignments.rs} (100%) rename crates/swc_ecma_transforms_compat/tests/{es2022_class_properties.rs => todo_es2022_class_properties.rs} (100%) diff --git a/crates/swc_ecma_transforms_compat/tests/es2015_block_scoping.rs b/crates/swc_ecma_transforms_compat/tests/todo_es2015_block_scoping.rs similarity index 100% rename from crates/swc_ecma_transforms_compat/tests/es2015_block_scoping.rs rename to crates/swc_ecma_transforms_compat/tests/todo_es2015_block_scoping.rs diff --git a/crates/swc_ecma_transforms_compat/tests/es2015_classes.rs b/crates/swc_ecma_transforms_compat/tests/todo_es2015_classes.rs similarity index 100% rename from crates/swc_ecma_transforms_compat/tests/es2015_classes.rs rename to crates/swc_ecma_transforms_compat/tests/todo_es2015_classes.rs diff --git a/crates/swc_ecma_transforms_compat/tests/es2015_computed_props.rs b/crates/swc_ecma_transforms_compat/tests/todo_es2015_computed_props.rs similarity index 100% rename from crates/swc_ecma_transforms_compat/tests/es2015_computed_props.rs rename to crates/swc_ecma_transforms_compat/tests/todo_es2015_computed_props.rs diff --git a/crates/swc_ecma_transforms_compat/tests/es2015_destructuring.rs b/crates/swc_ecma_transforms_compat/tests/todo_es2015_destructuring.rs similarity index 100% rename from crates/swc_ecma_transforms_compat/tests/es2015_destructuring.rs rename to crates/swc_ecma_transforms_compat/tests/todo_es2015_destructuring.rs diff --git a/crates/swc_ecma_transforms_compat/tests/es2015_duplicated_keys.rs b/crates/swc_ecma_transforms_compat/tests/todo_es2015_duplicated_keys.rs similarity index 100% rename from crates/swc_ecma_transforms_compat/tests/es2015_duplicated_keys.rs rename to crates/swc_ecma_transforms_compat/tests/todo_es2015_duplicated_keys.rs diff --git a/crates/swc_ecma_transforms_compat/tests/es2015_for_of.rs b/crates/swc_ecma_transforms_compat/tests/todo_es2015_for_of.rs similarity index 100% rename from crates/swc_ecma_transforms_compat/tests/es2015_for_of.rs rename to crates/swc_ecma_transforms_compat/tests/todo_es2015_for_of.rs diff --git a/crates/swc_ecma_transforms_compat/tests/es2015_generator.rs b/crates/swc_ecma_transforms_compat/tests/todo_es2015_generator.rs similarity index 100% rename from crates/swc_ecma_transforms_compat/tests/es2015_generator.rs rename to crates/swc_ecma_transforms_compat/tests/todo_es2015_generator.rs diff --git a/crates/swc_ecma_transforms_compat/tests/es2015_object_super.rs b/crates/swc_ecma_transforms_compat/tests/todo_es2015_object_super.rs similarity index 100% rename from crates/swc_ecma_transforms_compat/tests/es2015_object_super.rs rename to crates/swc_ecma_transforms_compat/tests/todo_es2015_object_super.rs diff --git a/crates/swc_ecma_transforms_compat/tests/es2015_parameters.rs b/crates/swc_ecma_transforms_compat/tests/todo_es2015_parameters.rs similarity index 100% rename from crates/swc_ecma_transforms_compat/tests/es2015_parameters.rs rename to crates/swc_ecma_transforms_compat/tests/todo_es2015_parameters.rs diff --git a/crates/swc_ecma_transforms_compat/tests/es2015_spread.rs b/crates/swc_ecma_transforms_compat/tests/todo_es2015_spread.rs similarity index 100% rename from crates/swc_ecma_transforms_compat/tests/es2015_spread.rs rename to crates/swc_ecma_transforms_compat/tests/todo_es2015_spread.rs diff --git a/crates/swc_ecma_transforms_compat/tests/es2015_template_literals.rs b/crates/swc_ecma_transforms_compat/tests/todo_es2015_template_literals.rs similarity index 100% rename from crates/swc_ecma_transforms_compat/tests/es2015_template_literals.rs rename to crates/swc_ecma_transforms_compat/tests/todo_es2015_template_literals.rs diff --git a/crates/swc_ecma_transforms_compat/tests/es2017_async_to_generator.rs b/crates/swc_ecma_transforms_compat/tests/todo_es2017_async_to_generator.rs similarity index 100% rename from crates/swc_ecma_transforms_compat/tests/es2017_async_to_generator.rs rename to crates/swc_ecma_transforms_compat/tests/todo_es2017_async_to_generator.rs diff --git a/crates/swc_ecma_transforms_compat/tests/es2018_object_rest_spread.rs b/crates/swc_ecma_transforms_compat/tests/todo_es2018_object_rest_spread.rs similarity index 100% rename from crates/swc_ecma_transforms_compat/tests/es2018_object_rest_spread.rs rename to crates/swc_ecma_transforms_compat/tests/todo_es2018_object_rest_spread.rs diff --git a/crates/swc_ecma_transforms_compat/tests/es2020_nullish_coalescing.rs b/crates/swc_ecma_transforms_compat/tests/todo_es2020_nullish_coalescing.rs similarity index 100% rename from crates/swc_ecma_transforms_compat/tests/es2020_nullish_coalescing.rs rename to crates/swc_ecma_transforms_compat/tests/todo_es2020_nullish_coalescing.rs diff --git a/crates/swc_ecma_transforms_compat/tests/es2020_optional_chaining.rs b/crates/swc_ecma_transforms_compat/tests/todo_es2020_optional_chaining.rs similarity index 100% rename from crates/swc_ecma_transforms_compat/tests/es2020_optional_chaining.rs rename to crates/swc_ecma_transforms_compat/tests/todo_es2020_optional_chaining.rs diff --git a/crates/swc_ecma_transforms_compat/tests/es2021_logcal_assignments.rs b/crates/swc_ecma_transforms_compat/tests/todo_es2021_logcal_assignments.rs similarity index 100% rename from crates/swc_ecma_transforms_compat/tests/es2021_logcal_assignments.rs rename to crates/swc_ecma_transforms_compat/tests/todo_es2021_logcal_assignments.rs diff --git a/crates/swc_ecma_transforms_compat/tests/es2022_class_properties.rs b/crates/swc_ecma_transforms_compat/tests/todo_es2022_class_properties.rs similarity index 100% rename from crates/swc_ecma_transforms_compat/tests/es2022_class_properties.rs rename to crates/swc_ecma_transforms_compat/tests/todo_es2022_class_properties.rs From 7f937a201024af6900ecd910202717f8a1eb728a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Fri, 18 Nov 2022 16:22:50 +0900 Subject: [PATCH 20/25] Rename function --- crates/swc_ecma_transforms_compat/tests/todo_es2015_for_of.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/swc_ecma_transforms_compat/tests/todo_es2015_for_of.rs b/crates/swc_ecma_transforms_compat/tests/todo_es2015_for_of.rs index d7b0572b8945..bbd1306e28d1 100644 --- a/crates/swc_ecma_transforms_compat/tests/todo_es2015_for_of.rs +++ b/crates/swc_ecma_transforms_compat/tests/todo_es2015_for_of.rs @@ -609,7 +609,7 @@ if (true) loop: for(let _i = 0, _iter = []; _i < _iter.length; _i++){ ); #[testing::fixture("tests/for-of/**/exec.js")] -fn fixture(input: PathBuf) { +fn exec(input: PathBuf) { let input = read_to_string(&input).unwrap(); compare_stdout( @@ -630,7 +630,7 @@ fn fixture(input: PathBuf) { } #[testing::fixture("tests/for-of/**/exec.js")] -fn fixture_es2015(input: PathBuf) { +fn exec_es2015(input: PathBuf) { let input = read_to_string(&input).unwrap(); compare_stdout( From e7cbd4f73edcaa303052bf0c96599a0dabecc44e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Fri, 18 Nov 2022 16:25:37 +0900 Subject: [PATCH 21/25] Enable fixture for for-of --- .../tests/todo_es2015_for_of.rs | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/crates/swc_ecma_transforms_compat/tests/todo_es2015_for_of.rs b/crates/swc_ecma_transforms_compat/tests/todo_es2015_for_of.rs index bbd1306e28d1..9f878ec75c0b 100644 --- a/crates/swc_ecma_transforms_compat/tests/todo_es2015_for_of.rs +++ b/crates/swc_ecma_transforms_compat/tests/todo_es2015_for_of.rs @@ -7,7 +7,9 @@ use swc_ecma_transforms_compat::es2015::{ self, for_of::{for_of, Config}, }; -use swc_ecma_transforms_testing::{compare_stdout, test, test_exec}; +use swc_ecma_transforms_testing::{ + compare_stdout, test, test_exec, test_fixture, FixtureTestConfig, +}; fn syntax() -> Syntax { Default::default() @@ -629,6 +631,31 @@ fn exec(input: PathBuf) { ); } +#[testing::fixture("tests/for-of/**/input.js")] +fn fixture(input: PathBuf) { + let output = input.with_extension("output.js"); + + test_fixture( + Syntax::default(), + &|_| { + let top_level_mark = Mark::new(); + + chain!( + resolver(Mark::new(), top_level_mark, false), + for_of(Config { + assume_array: false, + ..Default::default() + }) + ) + }, + &input, + &output, + FixtureTestConfig { + ..Default::default() + }, + ); +} + #[testing::fixture("tests/for-of/**/exec.js")] fn exec_es2015(input: PathBuf) { let input = read_to_string(&input).unwrap(); From ae5b539d64d6c96e86f19d4af04c52a52eeee976 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Fri, 18 Nov 2022 16:26:32 +0900 Subject: [PATCH 22/25] Move tests --- .../tests/for-of/spec-identifier/input.js | 2 + .../tests/for-of/spec-ignore-cases/input.js | 6 ++ .../tests/todo_es2015_for_of.rs | 69 ------------------- 3 files changed, 8 insertions(+), 69 deletions(-) create mode 100644 crates/swc_ecma_transforms_compat/tests/for-of/spec-identifier/input.js create mode 100644 crates/swc_ecma_transforms_compat/tests/for-of/spec-ignore-cases/input.js diff --git a/crates/swc_ecma_transforms_compat/tests/for-of/spec-identifier/input.js b/crates/swc_ecma_transforms_compat/tests/for-of/spec-identifier/input.js new file mode 100644 index 000000000000..f7a368a40d3c --- /dev/null +++ b/crates/swc_ecma_transforms_compat/tests/for-of/spec-identifier/input.js @@ -0,0 +1,2 @@ +for (i of arr) { +} \ No newline at end of file diff --git a/crates/swc_ecma_transforms_compat/tests/for-of/spec-ignore-cases/input.js b/crates/swc_ecma_transforms_compat/tests/for-of/spec-ignore-cases/input.js new file mode 100644 index 000000000000..ef2f644919c5 --- /dev/null +++ b/crates/swc_ecma_transforms_compat/tests/for-of/spec-ignore-cases/input.js @@ -0,0 +1,6 @@ +for (var i of foo) { + switch (i) { + case 1: + break; + } +} \ No newline at end of file diff --git a/crates/swc_ecma_transforms_compat/tests/todo_es2015_for_of.rs b/crates/swc_ecma_transforms_compat/tests/todo_es2015_for_of.rs index 9f878ec75c0b..ae097630e803 100644 --- a/crates/swc_ecma_transforms_compat/tests/todo_es2015_for_of.rs +++ b/crates/swc_ecma_transforms_compat/tests/todo_es2015_for_of.rs @@ -15,75 +15,6 @@ fn syntax() -> Syntax { Default::default() } -test!( - syntax(), - |_| for_of(Default::default()), - spec_identifier, - r#"for (i of arr) { -}"#, - r#"var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined; - -try { - for (var _iterator = arr[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = - _iterator.next()).done); _iteratorNormalCompletion = true) { - i = _step.value; - } -} catch (err) { - _didIteratorError = true; - _iteratorError = err; -} finally { - try { - if (!_iteratorNormalCompletion && _iterator.return != null) { - _iterator.return(); - } - } finally { - if (_didIteratorError) { - throw _iteratorError; - } - } -}"#, - ok_if_code_eq -); - -test!( - syntax(), - |_| for_of(Default::default()), - spec_ignore_cases, - r#"for (var i of foo) { - switch (i) { - case 1: - break; - } -}"#, - r#"var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined; - -try { - for (var _iterator = foo[Symbol.iterator](), _step; !(_iteratorNormalCompletion = - (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { - var i = _step.value; - - switch (i) { - case 1: - break; - } - } -} catch (err) { - _didIteratorError = true; - _iteratorError = err; -} finally { - try { - if (!_iteratorNormalCompletion && _iterator.return != null) { - _iterator.return(); - } - } finally { - if (_didIteratorError) { - throw _iteratorError; - } - } -}"#, - ok_if_code_eq -); - test!( syntax(), |_| for_of(Default::default()), From 0d77166ca9a82cdb4273640fa4f5d67ec8e58cde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Mon, 28 Nov 2022 12:15:43 +0900 Subject: [PATCH 23/25] Rename back --- .../{todo_es2015_block_scoping.rs => es2015_block_scoping.rs} | 0 .../tests/{todo_es2015_classes.rs => es2015_classes.rs} | 0 .../{todo_es2015_computed_props.rs => es2015_computed_props.rs} | 0 .../{todo_es2015_destructuring.rs => es2015_destructuring.rs} | 0 .../{todo_es2015_duplicated_keys.rs => es2015_duplicated_keys.rs} | 0 .../tests/{todo_es2015_for_of.rs => es2015_for_of.rs} | 0 .../tests/{todo_es2015_generator.rs => es2015_generator.rs} | 0 .../tests/{todo_es2015_object_super.rs => es2015_object_super.rs} | 0 .../tests/{todo_es2015_parameters.rs => es2015_parameters.rs} | 0 .../tests/{todo_es2015_spread.rs => es2015_spread.rs} | 0 ...do_es2015_template_literals.rs => es2015_template_literals.rs} | 0 ..._es2017_async_to_generator.rs => es2017_async_to_generator.rs} | 0 ..._es2018_object_rest_spread.rs => es2018_object_rest_spread.rs} | 0 ..._es2020_nullish_coalescing.rs => es2020_nullish_coalescing.rs} | 0 ...do_es2020_optional_chaining.rs => es2020_optional_chaining.rs} | 0 ..._es2021_logcal_assignments.rs => es2021_logcal_assignments.rs} | 0 ...todo_es2022_class_properties.rs => es2022_class_properties.rs} | 0 17 files changed, 0 insertions(+), 0 deletions(-) rename crates/swc_ecma_transforms_compat/tests/{todo_es2015_block_scoping.rs => es2015_block_scoping.rs} (100%) rename crates/swc_ecma_transforms_compat/tests/{todo_es2015_classes.rs => es2015_classes.rs} (100%) rename crates/swc_ecma_transforms_compat/tests/{todo_es2015_computed_props.rs => es2015_computed_props.rs} (100%) rename crates/swc_ecma_transforms_compat/tests/{todo_es2015_destructuring.rs => es2015_destructuring.rs} (100%) rename crates/swc_ecma_transforms_compat/tests/{todo_es2015_duplicated_keys.rs => es2015_duplicated_keys.rs} (100%) rename crates/swc_ecma_transforms_compat/tests/{todo_es2015_for_of.rs => es2015_for_of.rs} (100%) rename crates/swc_ecma_transforms_compat/tests/{todo_es2015_generator.rs => es2015_generator.rs} (100%) rename crates/swc_ecma_transforms_compat/tests/{todo_es2015_object_super.rs => es2015_object_super.rs} (100%) rename crates/swc_ecma_transforms_compat/tests/{todo_es2015_parameters.rs => es2015_parameters.rs} (100%) rename crates/swc_ecma_transforms_compat/tests/{todo_es2015_spread.rs => es2015_spread.rs} (100%) rename crates/swc_ecma_transforms_compat/tests/{todo_es2015_template_literals.rs => es2015_template_literals.rs} (100%) rename crates/swc_ecma_transforms_compat/tests/{todo_es2017_async_to_generator.rs => es2017_async_to_generator.rs} (100%) rename crates/swc_ecma_transforms_compat/tests/{todo_es2018_object_rest_spread.rs => es2018_object_rest_spread.rs} (100%) rename crates/swc_ecma_transforms_compat/tests/{todo_es2020_nullish_coalescing.rs => es2020_nullish_coalescing.rs} (100%) rename crates/swc_ecma_transforms_compat/tests/{todo_es2020_optional_chaining.rs => es2020_optional_chaining.rs} (100%) rename crates/swc_ecma_transforms_compat/tests/{todo_es2021_logcal_assignments.rs => es2021_logcal_assignments.rs} (100%) rename crates/swc_ecma_transforms_compat/tests/{todo_es2022_class_properties.rs => es2022_class_properties.rs} (100%) diff --git a/crates/swc_ecma_transforms_compat/tests/todo_es2015_block_scoping.rs b/crates/swc_ecma_transforms_compat/tests/es2015_block_scoping.rs similarity index 100% rename from crates/swc_ecma_transforms_compat/tests/todo_es2015_block_scoping.rs rename to crates/swc_ecma_transforms_compat/tests/es2015_block_scoping.rs diff --git a/crates/swc_ecma_transforms_compat/tests/todo_es2015_classes.rs b/crates/swc_ecma_transforms_compat/tests/es2015_classes.rs similarity index 100% rename from crates/swc_ecma_transforms_compat/tests/todo_es2015_classes.rs rename to crates/swc_ecma_transforms_compat/tests/es2015_classes.rs diff --git a/crates/swc_ecma_transforms_compat/tests/todo_es2015_computed_props.rs b/crates/swc_ecma_transforms_compat/tests/es2015_computed_props.rs similarity index 100% rename from crates/swc_ecma_transforms_compat/tests/todo_es2015_computed_props.rs rename to crates/swc_ecma_transforms_compat/tests/es2015_computed_props.rs diff --git a/crates/swc_ecma_transforms_compat/tests/todo_es2015_destructuring.rs b/crates/swc_ecma_transforms_compat/tests/es2015_destructuring.rs similarity index 100% rename from crates/swc_ecma_transforms_compat/tests/todo_es2015_destructuring.rs rename to crates/swc_ecma_transforms_compat/tests/es2015_destructuring.rs diff --git a/crates/swc_ecma_transforms_compat/tests/todo_es2015_duplicated_keys.rs b/crates/swc_ecma_transforms_compat/tests/es2015_duplicated_keys.rs similarity index 100% rename from crates/swc_ecma_transforms_compat/tests/todo_es2015_duplicated_keys.rs rename to crates/swc_ecma_transforms_compat/tests/es2015_duplicated_keys.rs diff --git a/crates/swc_ecma_transforms_compat/tests/todo_es2015_for_of.rs b/crates/swc_ecma_transforms_compat/tests/es2015_for_of.rs similarity index 100% rename from crates/swc_ecma_transforms_compat/tests/todo_es2015_for_of.rs rename to crates/swc_ecma_transforms_compat/tests/es2015_for_of.rs diff --git a/crates/swc_ecma_transforms_compat/tests/todo_es2015_generator.rs b/crates/swc_ecma_transforms_compat/tests/es2015_generator.rs similarity index 100% rename from crates/swc_ecma_transforms_compat/tests/todo_es2015_generator.rs rename to crates/swc_ecma_transforms_compat/tests/es2015_generator.rs diff --git a/crates/swc_ecma_transforms_compat/tests/todo_es2015_object_super.rs b/crates/swc_ecma_transforms_compat/tests/es2015_object_super.rs similarity index 100% rename from crates/swc_ecma_transforms_compat/tests/todo_es2015_object_super.rs rename to crates/swc_ecma_transforms_compat/tests/es2015_object_super.rs diff --git a/crates/swc_ecma_transforms_compat/tests/todo_es2015_parameters.rs b/crates/swc_ecma_transforms_compat/tests/es2015_parameters.rs similarity index 100% rename from crates/swc_ecma_transforms_compat/tests/todo_es2015_parameters.rs rename to crates/swc_ecma_transforms_compat/tests/es2015_parameters.rs diff --git a/crates/swc_ecma_transforms_compat/tests/todo_es2015_spread.rs b/crates/swc_ecma_transforms_compat/tests/es2015_spread.rs similarity index 100% rename from crates/swc_ecma_transforms_compat/tests/todo_es2015_spread.rs rename to crates/swc_ecma_transforms_compat/tests/es2015_spread.rs diff --git a/crates/swc_ecma_transforms_compat/tests/todo_es2015_template_literals.rs b/crates/swc_ecma_transforms_compat/tests/es2015_template_literals.rs similarity index 100% rename from crates/swc_ecma_transforms_compat/tests/todo_es2015_template_literals.rs rename to crates/swc_ecma_transforms_compat/tests/es2015_template_literals.rs diff --git a/crates/swc_ecma_transforms_compat/tests/todo_es2017_async_to_generator.rs b/crates/swc_ecma_transforms_compat/tests/es2017_async_to_generator.rs similarity index 100% rename from crates/swc_ecma_transforms_compat/tests/todo_es2017_async_to_generator.rs rename to crates/swc_ecma_transforms_compat/tests/es2017_async_to_generator.rs diff --git a/crates/swc_ecma_transforms_compat/tests/todo_es2018_object_rest_spread.rs b/crates/swc_ecma_transforms_compat/tests/es2018_object_rest_spread.rs similarity index 100% rename from crates/swc_ecma_transforms_compat/tests/todo_es2018_object_rest_spread.rs rename to crates/swc_ecma_transforms_compat/tests/es2018_object_rest_spread.rs diff --git a/crates/swc_ecma_transforms_compat/tests/todo_es2020_nullish_coalescing.rs b/crates/swc_ecma_transforms_compat/tests/es2020_nullish_coalescing.rs similarity index 100% rename from crates/swc_ecma_transforms_compat/tests/todo_es2020_nullish_coalescing.rs rename to crates/swc_ecma_transforms_compat/tests/es2020_nullish_coalescing.rs diff --git a/crates/swc_ecma_transforms_compat/tests/todo_es2020_optional_chaining.rs b/crates/swc_ecma_transforms_compat/tests/es2020_optional_chaining.rs similarity index 100% rename from crates/swc_ecma_transforms_compat/tests/todo_es2020_optional_chaining.rs rename to crates/swc_ecma_transforms_compat/tests/es2020_optional_chaining.rs diff --git a/crates/swc_ecma_transforms_compat/tests/todo_es2021_logcal_assignments.rs b/crates/swc_ecma_transforms_compat/tests/es2021_logcal_assignments.rs similarity index 100% rename from crates/swc_ecma_transforms_compat/tests/todo_es2021_logcal_assignments.rs rename to crates/swc_ecma_transforms_compat/tests/es2021_logcal_assignments.rs diff --git a/crates/swc_ecma_transforms_compat/tests/todo_es2022_class_properties.rs b/crates/swc_ecma_transforms_compat/tests/es2022_class_properties.rs similarity index 100% rename from crates/swc_ecma_transforms_compat/tests/todo_es2022_class_properties.rs rename to crates/swc_ecma_transforms_compat/tests/es2022_class_properties.rs From 86a2458fe5733731474b22059b7c0ea1ccc89a2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Mon, 28 Nov 2022 12:18:14 +0900 Subject: [PATCH 24/25] Fix path --- crates/swc_ecma_transforms_compat/tests/es2015_for_of.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/swc_ecma_transforms_compat/tests/es2015_for_of.rs b/crates/swc_ecma_transforms_compat/tests/es2015_for_of.rs index ae097630e803..dc062423e0f6 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2015_for_of.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2015_for_of.rs @@ -564,7 +564,7 @@ fn exec(input: PathBuf) { #[testing::fixture("tests/for-of/**/input.js")] fn fixture(input: PathBuf) { - let output = input.with_extension("output.js"); + let output = input.with_file_name("output.js"); test_fixture( Syntax::default(), From 4a0ecf298f7649587c70a0fd0b53b213c653c467 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Mon, 28 Nov 2022 12:18:23 +0900 Subject: [PATCH 25/25] Update test refs --- .../tests/for-of/spec-identifier/output.js | 19 +++++++++++++++ .../tests/for-of/spec-ignore-cases/output.js | 23 +++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 crates/swc_ecma_transforms_compat/tests/for-of/spec-identifier/output.js create mode 100644 crates/swc_ecma_transforms_compat/tests/for-of/spec-ignore-cases/output.js diff --git a/crates/swc_ecma_transforms_compat/tests/for-of/spec-identifier/output.js b/crates/swc_ecma_transforms_compat/tests/for-of/spec-identifier/output.js new file mode 100644 index 000000000000..7dd8bf4c7633 --- /dev/null +++ b/crates/swc_ecma_transforms_compat/tests/for-of/spec-identifier/output.js @@ -0,0 +1,19 @@ +var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined; +try { + for(var _iterator = arr[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){ + i = _step.value; + } +} catch (err) { + _didIteratorError = true; + _iteratorError = err; +} finally{ + try { + if (!_iteratorNormalCompletion && _iterator.return != null) { + _iterator.return(); + } + } finally{ + if (_didIteratorError) { + throw _iteratorError; + } + } +} diff --git a/crates/swc_ecma_transforms_compat/tests/for-of/spec-ignore-cases/output.js b/crates/swc_ecma_transforms_compat/tests/for-of/spec-ignore-cases/output.js new file mode 100644 index 000000000000..28086ba0bc5e --- /dev/null +++ b/crates/swc_ecma_transforms_compat/tests/for-of/spec-ignore-cases/output.js @@ -0,0 +1,23 @@ +var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined; +try { + for(var _iterator = foo[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){ + var i = _step.value; + switch(i){ + case 1: + break; + } + } +} catch (err) { + _didIteratorError = true; + _iteratorError = err; +} finally{ + try { + if (!_iteratorNormalCompletion && _iterator.return != null) { + _iterator.return(); + } + } finally{ + if (_didIteratorError) { + throw _iteratorError; + } + } +}