From f7d1b31124fd0882c3e8ff4b2f8bc8d06f2ecfb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Wed, 30 Nov 2022 14:11:51 +0900 Subject: [PATCH 01/19] Remove `to` --- .../tests/strip.rs | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/crates/swc_ecma_transforms_typescript/tests/strip.rs b/crates/swc_ecma_transforms_typescript/tests/strip.rs index 6974d86f6045..9c111e9e4071 100644 --- a/crates/swc_ecma_transforms_typescript/tests/strip.rs +++ b/crates/swc_ecma_transforms_typescript/tests/strip.rs @@ -49,22 +49,6 @@ fn properties(t: &Tester, loose: bool) -> impl Fold { ) } -macro_rules! to { - ($name:ident, $from:expr, $to:expr) => { - test!( - Syntax::Typescript(TsConfig { - decorators: true, - ..Default::default() - }), - |t| chain!(tr(), properties(t, true)), - $name, - $from, - $to, - ok_if_code_eq - ); - }; -} - macro_rules! test_with_config { ($name:ident, $config:expr, $from:expr, $to:expr) => { test!( From c5fd8dae0e2ea35cfad792ce73bb1994b80c83c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Wed, 30 Nov 2022 14:24:08 +0900 Subject: [PATCH 02/19] Migrate one --- .../tests/fixture/constructor-1/input.ts | 3 +++ crates/swc_ecma_transforms_typescript/tests/strip.rs | 12 ------------ 2 files changed, 3 insertions(+), 12 deletions(-) create mode 100644 crates/swc_ecma_transforms_typescript/tests/fixture/constructor-1/input.ts diff --git a/crates/swc_ecma_transforms_typescript/tests/fixture/constructor-1/input.ts b/crates/swc_ecma_transforms_typescript/tests/fixture/constructor-1/input.ts new file mode 100644 index 000000000000..c8676c0c8ac7 --- /dev/null +++ b/crates/swc_ecma_transforms_typescript/tests/fixture/constructor-1/input.ts @@ -0,0 +1,3 @@ +class Foo { + constructor(public readonly foo) { } +} \ No newline at end of file diff --git a/crates/swc_ecma_transforms_typescript/tests/strip.rs b/crates/swc_ecma_transforms_typescript/tests/strip.rs index 9c111e9e4071..1e8c05b38b0e 100644 --- a/crates/swc_ecma_transforms_typescript/tests/strip.rs +++ b/crates/swc_ecma_transforms_typescript/tests/strip.rs @@ -93,18 +93,6 @@ test!( }" ); -to!( - constructor_01, - "class Foo { - constructor(public readonly foo) {} -}", - "class Foo { - constructor(foo) { - this.foo = foo; - } -}" -); - to!( constructor_02, "class Foo { From dc26fab17369eb2af0619a1a27027f97e775369e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Wed, 30 Nov 2022 14:24:31 +0900 Subject: [PATCH 03/19] Migrate one --- .../tests/fixture/constructor-2/input.ts | 5 +++++ .../swc_ecma_transforms_typescript/tests/strip.rs | 15 --------------- 2 files changed, 5 insertions(+), 15 deletions(-) create mode 100644 crates/swc_ecma_transforms_typescript/tests/fixture/constructor-2/input.ts diff --git a/crates/swc_ecma_transforms_typescript/tests/fixture/constructor-2/input.ts b/crates/swc_ecma_transforms_typescript/tests/fixture/constructor-2/input.ts new file mode 100644 index 000000000000..5d7d8ea11fe7 --- /dev/null +++ b/crates/swc_ecma_transforms_typescript/tests/fixture/constructor-2/input.ts @@ -0,0 +1,5 @@ +class Foo { + constructor(readonly foo) { + this.bar = 1; + } +} \ No newline at end of file diff --git a/crates/swc_ecma_transforms_typescript/tests/strip.rs b/crates/swc_ecma_transforms_typescript/tests/strip.rs index 1e8c05b38b0e..18ab478919d8 100644 --- a/crates/swc_ecma_transforms_typescript/tests/strip.rs +++ b/crates/swc_ecma_transforms_typescript/tests/strip.rs @@ -93,21 +93,6 @@ test!( }" ); -to!( - constructor_02, - "class Foo { - constructor(readonly foo) { - this.bar = 1; - } -}", - "class Foo { - constructor(foo) { - this.foo = foo; - this.bar = 1; - } -}" -); - to!( private_method_overload_and_abstract, "class test { From 8aee2f0329e562cc71db093a20d2339727fbf475 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Wed, 30 Nov 2022 14:27:36 +0900 Subject: [PATCH 04/19] Migrate one --- .../input.ts | 7 +++++++ .../tests/strip.rs | 19 ------------------- 2 files changed, 7 insertions(+), 19 deletions(-) create mode 100644 crates/swc_ecma_transforms_typescript/tests/fixture/private-method-overload-and-abstract/input.ts diff --git a/crates/swc_ecma_transforms_typescript/tests/fixture/private-method-overload-and-abstract/input.ts b/crates/swc_ecma_transforms_typescript/tests/fixture/private-method-overload-and-abstract/input.ts new file mode 100644 index 000000000000..f5d8a79ed11c --- /dev/null +++ b/crates/swc_ecma_transforms_typescript/tests/fixture/private-method-overload-and-abstract/input.ts @@ -0,0 +1,7 @@ +class test { + #test(); + #test() { + } + + abstract #test(); +} \ No newline at end of file diff --git a/crates/swc_ecma_transforms_typescript/tests/strip.rs b/crates/swc_ecma_transforms_typescript/tests/strip.rs index 18ab478919d8..c97993081bde 100644 --- a/crates/swc_ecma_transforms_typescript/tests/strip.rs +++ b/crates/swc_ecma_transforms_typescript/tests/strip.rs @@ -93,25 +93,6 @@ test!( }" ); -to!( - private_method_overload_and_abstract, - "class test { - #test(); - #test() { - } - - abstract #test(); -}", - "var _test = new WeakSet(); - class test { - constructor(){ - _classPrivateMethodInit(this, _test); - } - } - function test1() {} -" -); - to!(export_import, "export import A = B", "export var A = B;"); to!(export_equals, "export = Foo", "module.exports = Foo;"); From f36b7f3418e9d2da82b348622a19c511f6cbf05b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Wed, 30 Nov 2022 14:28:04 +0900 Subject: [PATCH 05/19] Migrate one --- .../tests/fixture/export-import/input.ts | 1 + crates/swc_ecma_transforms_typescript/tests/strip.rs | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) create mode 100644 crates/swc_ecma_transforms_typescript/tests/fixture/export-import/input.ts diff --git a/crates/swc_ecma_transforms_typescript/tests/fixture/export-import/input.ts b/crates/swc_ecma_transforms_typescript/tests/fixture/export-import/input.ts new file mode 100644 index 000000000000..7c8ea12e279d --- /dev/null +++ b/crates/swc_ecma_transforms_typescript/tests/fixture/export-import/input.ts @@ -0,0 +1 @@ +export import A = B \ No newline at end of file diff --git a/crates/swc_ecma_transforms_typescript/tests/strip.rs b/crates/swc_ecma_transforms_typescript/tests/strip.rs index c97993081bde..9e613076bbe6 100644 --- a/crates/swc_ecma_transforms_typescript/tests/strip.rs +++ b/crates/swc_ecma_transforms_typescript/tests/strip.rs @@ -93,8 +93,6 @@ test!( }" ); -to!(export_import, "export import A = B", "export var A = B;"); - to!(export_equals, "export = Foo", "module.exports = Foo;"); to!( From a07c2f473c7c06969a9d6f113a3949f26dccf676 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Wed, 30 Nov 2022 14:33:31 +0900 Subject: [PATCH 06/19] Migrate one --- .../tests/fixture/export-equals/input.ts | 1 + crates/swc_ecma_transforms_typescript/tests/strip.rs | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) create mode 100644 crates/swc_ecma_transforms_typescript/tests/fixture/export-equals/input.ts diff --git a/crates/swc_ecma_transforms_typescript/tests/fixture/export-equals/input.ts b/crates/swc_ecma_transforms_typescript/tests/fixture/export-equals/input.ts new file mode 100644 index 000000000000..b45d9ab808f3 --- /dev/null +++ b/crates/swc_ecma_transforms_typescript/tests/fixture/export-equals/input.ts @@ -0,0 +1 @@ +export = Foo \ No newline at end of file diff --git a/crates/swc_ecma_transforms_typescript/tests/strip.rs b/crates/swc_ecma_transforms_typescript/tests/strip.rs index 9e613076bbe6..e7941ce6b2de 100644 --- a/crates/swc_ecma_transforms_typescript/tests/strip.rs +++ b/crates/swc_ecma_transforms_typescript/tests/strip.rs @@ -93,8 +93,6 @@ test!( }" ); -to!(export_equals, "export = Foo", "module.exports = Foo;"); - to!( issue_196_01, "export type Link = { key: string; text: string };", From f5fe62969fdb7b8c56a1d87b92c9afbe1a461f2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Wed, 30 Nov 2022 14:35:47 +0900 Subject: [PATCH 07/19] Migrate one --- .../tests/fixture/issue-196/1/input.ts | 1 + .../tests/fixture/issue-196/2/input.ts | 2 ++ .../tests/fixture/issue-196/3/input.ts | 3 +++ .../tests/strip.rs | 22 ------------------- 4 files changed, 6 insertions(+), 22 deletions(-) create mode 100644 crates/swc_ecma_transforms_typescript/tests/fixture/issue-196/1/input.ts create mode 100644 crates/swc_ecma_transforms_typescript/tests/fixture/issue-196/2/input.ts create mode 100644 crates/swc_ecma_transforms_typescript/tests/fixture/issue-196/3/input.ts diff --git a/crates/swc_ecma_transforms_typescript/tests/fixture/issue-196/1/input.ts b/crates/swc_ecma_transforms_typescript/tests/fixture/issue-196/1/input.ts new file mode 100644 index 000000000000..159619d198a8 --- /dev/null +++ b/crates/swc_ecma_transforms_typescript/tests/fixture/issue-196/1/input.ts @@ -0,0 +1 @@ +export type Link = { key: string; text: string }; \ No newline at end of file diff --git a/crates/swc_ecma_transforms_typescript/tests/fixture/issue-196/2/input.ts b/crates/swc_ecma_transforms_typescript/tests/fixture/issue-196/2/input.ts new file mode 100644 index 000000000000..637fb531c84a --- /dev/null +++ b/crates/swc_ecma_transforms_typescript/tests/fixture/issue-196/2/input.ts @@ -0,0 +1,2 @@ +type Link = { key: string; text: string }; +export { Link } \ No newline at end of file diff --git a/crates/swc_ecma_transforms_typescript/tests/fixture/issue-196/3/input.ts b/crates/swc_ecma_transforms_typescript/tests/fixture/issue-196/3/input.ts new file mode 100644 index 000000000000..2a6ddccb00ec --- /dev/null +++ b/crates/swc_ecma_transforms_typescript/tests/fixture/issue-196/3/input.ts @@ -0,0 +1,3 @@ +type Link = { key: string; text: string }; +const Link = 'Boo'; +export { Link } \ No newline at end of file diff --git a/crates/swc_ecma_transforms_typescript/tests/strip.rs b/crates/swc_ecma_transforms_typescript/tests/strip.rs index e7941ce6b2de..f76ad96d094e 100644 --- a/crates/swc_ecma_transforms_typescript/tests/strip.rs +++ b/crates/swc_ecma_transforms_typescript/tests/strip.rs @@ -93,28 +93,6 @@ test!( }" ); -to!( - issue_196_01, - "export type Link = { key: string; text: string };", - "" -); - -to!( - issue_196_02, - "type Link = { key: string; text: string }; -export { Link };", - "" -); - -to!( - issue_196_03, - "type Link = { key: string; text: string }; -const Link = 'Boo'; -export { Link };", - "const Link = 'Boo'; -export { Link };" -); - // TODO: Test function / variable hoisting to!( From 3de47b54f85646492f7d7a0a432026f0a4afb3b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Wed, 30 Nov 2022 14:36:09 +0900 Subject: [PATCH 08/19] Revert --- .../tests/strip.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/crates/swc_ecma_transforms_typescript/tests/strip.rs b/crates/swc_ecma_transforms_typescript/tests/strip.rs index f76ad96d094e..16cc2bd52e75 100644 --- a/crates/swc_ecma_transforms_typescript/tests/strip.rs +++ b/crates/swc_ecma_transforms_typescript/tests/strip.rs @@ -49,6 +49,22 @@ fn properties(t: &Tester, loose: bool) -> impl Fold { ) } +macro_rules! to { + ($name:ident, $from:expr, $to:expr) => { + test!( + Syntax::Typescript(TsConfig { + decorators: true, + ..Default::default() + }), + |t| chain!(tr(), properties(t, true)), + $name, + $from, + $to, + ok_if_code_eq + ); + }; +} + macro_rules! test_with_config { ($name:ident, $config:expr, $from:expr, $to:expr) => { test!( From a4c0a1f2b55f5dd81505fb8edd53880dec610654 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Wed, 30 Nov 2022 14:38:03 +0900 Subject: [PATCH 09/19] Update test refs --- .../tests/fixture/constructor-1/output.js | 5 +++++ .../tests/fixture/constructor-2/output.js | 6 ++++++ .../tests/fixture/export-equals/output.js | 1 + .../tests/fixture/export-import/output.js | 1 + .../tests/fixture/issue-196/3/output.js | 2 ++ .../fixture/private-method-overload-and-abstract/output.js | 7 +++++++ 6 files changed, 22 insertions(+) create mode 100644 crates/swc_ecma_transforms_typescript/tests/fixture/constructor-1/output.js create mode 100644 crates/swc_ecma_transforms_typescript/tests/fixture/constructor-2/output.js create mode 100644 crates/swc_ecma_transforms_typescript/tests/fixture/export-equals/output.js create mode 100644 crates/swc_ecma_transforms_typescript/tests/fixture/export-import/output.js create mode 100644 crates/swc_ecma_transforms_typescript/tests/fixture/issue-196/3/output.js create mode 100644 crates/swc_ecma_transforms_typescript/tests/fixture/private-method-overload-and-abstract/output.js diff --git a/crates/swc_ecma_transforms_typescript/tests/fixture/constructor-1/output.js b/crates/swc_ecma_transforms_typescript/tests/fixture/constructor-1/output.js new file mode 100644 index 000000000000..8fa300f54ada --- /dev/null +++ b/crates/swc_ecma_transforms_typescript/tests/fixture/constructor-1/output.js @@ -0,0 +1,5 @@ +class Foo { + constructor(foo){ + this.foo = foo; + } +} diff --git a/crates/swc_ecma_transforms_typescript/tests/fixture/constructor-2/output.js b/crates/swc_ecma_transforms_typescript/tests/fixture/constructor-2/output.js new file mode 100644 index 000000000000..c65882df2d5a --- /dev/null +++ b/crates/swc_ecma_transforms_typescript/tests/fixture/constructor-2/output.js @@ -0,0 +1,6 @@ +class Foo { + constructor(foo){ + this.foo = foo; + this.bar = 1; + } +} diff --git a/crates/swc_ecma_transforms_typescript/tests/fixture/export-equals/output.js b/crates/swc_ecma_transforms_typescript/tests/fixture/export-equals/output.js new file mode 100644 index 000000000000..20f0003732fd --- /dev/null +++ b/crates/swc_ecma_transforms_typescript/tests/fixture/export-equals/output.js @@ -0,0 +1 @@ +module.exports = Foo; diff --git a/crates/swc_ecma_transforms_typescript/tests/fixture/export-import/output.js b/crates/swc_ecma_transforms_typescript/tests/fixture/export-import/output.js new file mode 100644 index 000000000000..a731c4b372a1 --- /dev/null +++ b/crates/swc_ecma_transforms_typescript/tests/fixture/export-import/output.js @@ -0,0 +1 @@ +export var A = B; diff --git a/crates/swc_ecma_transforms_typescript/tests/fixture/issue-196/3/output.js b/crates/swc_ecma_transforms_typescript/tests/fixture/issue-196/3/output.js new file mode 100644 index 000000000000..2ab0492c2492 --- /dev/null +++ b/crates/swc_ecma_transforms_typescript/tests/fixture/issue-196/3/output.js @@ -0,0 +1,2 @@ +const Link = 'Boo'; +export { Link }; diff --git a/crates/swc_ecma_transforms_typescript/tests/fixture/private-method-overload-and-abstract/output.js b/crates/swc_ecma_transforms_typescript/tests/fixture/private-method-overload-and-abstract/output.js new file mode 100644 index 000000000000..13c3af24fba3 --- /dev/null +++ b/crates/swc_ecma_transforms_typescript/tests/fixture/private-method-overload-and-abstract/output.js @@ -0,0 +1,7 @@ +var _test = /*#__PURE__*/ new WeakSet(); +class test { + constructor(){ + _classPrivateMethodInit(this, _test); + } +} +function test1() {} From 5ef35017e94b52e599c8554acd264399d8fe2957 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Wed, 30 Nov 2022 14:40:28 +0900 Subject: [PATCH 10/19] Remove again --- .../tests/strip.rs | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/crates/swc_ecma_transforms_typescript/tests/strip.rs b/crates/swc_ecma_transforms_typescript/tests/strip.rs index 16cc2bd52e75..f76ad96d094e 100644 --- a/crates/swc_ecma_transforms_typescript/tests/strip.rs +++ b/crates/swc_ecma_transforms_typescript/tests/strip.rs @@ -49,22 +49,6 @@ fn properties(t: &Tester, loose: bool) -> impl Fold { ) } -macro_rules! to { - ($name:ident, $from:expr, $to:expr) => { - test!( - Syntax::Typescript(TsConfig { - decorators: true, - ..Default::default() - }), - |t| chain!(tr(), properties(t, true)), - $name, - $from, - $to, - ok_if_code_eq - ); - }; -} - macro_rules! test_with_config { ($name:ident, $config:expr, $from:expr, $to:expr) => { test!( From bcaa0b1962662505e0b71e785d00a75382fae6f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Wed, 30 Nov 2022 14:44:35 +0900 Subject: [PATCH 11/19] Migrate --- .../tests/fixture/issue-179/1/input.ts | 2 ++ .../tests/fixture/issue-179/2/input.ts | 2 ++ .../swc_ecma_transforms_typescript/tests/strip.rs | 15 --------------- 3 files changed, 4 insertions(+), 15 deletions(-) create mode 100644 crates/swc_ecma_transforms_typescript/tests/fixture/issue-179/1/input.ts create mode 100644 crates/swc_ecma_transforms_typescript/tests/fixture/issue-179/2/input.ts diff --git a/crates/swc_ecma_transforms_typescript/tests/fixture/issue-179/1/input.ts b/crates/swc_ecma_transforms_typescript/tests/fixture/issue-179/1/input.ts new file mode 100644 index 000000000000..8978b783057a --- /dev/null +++ b/crates/swc_ecma_transforms_typescript/tests/fixture/issue-179/1/input.ts @@ -0,0 +1,2 @@ +import { Types } from 'other'; +const a: Types.foo = {}; \ No newline at end of file diff --git a/crates/swc_ecma_transforms_typescript/tests/fixture/issue-179/2/input.ts b/crates/swc_ecma_transforms_typescript/tests/fixture/issue-179/2/input.ts new file mode 100644 index 000000000000..3d1abef76fb8 --- /dev/null +++ b/crates/swc_ecma_transforms_typescript/tests/fixture/issue-179/2/input.ts @@ -0,0 +1,2 @@ +import { Types } from 'other'; +const a: Types = Types.foo; \ No newline at end of file diff --git a/crates/swc_ecma_transforms_typescript/tests/strip.rs b/crates/swc_ecma_transforms_typescript/tests/strip.rs index f76ad96d094e..99bff62e2bc4 100644 --- a/crates/swc_ecma_transforms_typescript/tests/strip.rs +++ b/crates/swc_ecma_transforms_typescript/tests/strip.rs @@ -95,21 +95,6 @@ test!( // TODO: Test function / variable hoisting -to!( - issue_179_01, - "import {Types} from 'other'; -const a: Types.foo = {};", - "const a = {};" -); - -to!( - issue_179_02, - "import {Types} from 'other'; -const a: Types = Types.foo;", - "import {Types} from 'other'; -const a = Types.foo;" -); - to!( issue_236, "function foo(this: any, $scope: angular.IScope){}", From 3592e55139d3c4c9e4197573e09bf3f8a9fd30c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Wed, 30 Nov 2022 14:45:42 +0900 Subject: [PATCH 12/19] Migrate --- .../tests/fixture/issue-236/input.ts | 1 + .../tests/fixture/issue-357/input.ts | 23 +++++++++ .../tests/strip.rs | 47 ------------------- 3 files changed, 24 insertions(+), 47 deletions(-) create mode 100644 crates/swc_ecma_transforms_typescript/tests/fixture/issue-236/input.ts create mode 100644 crates/swc_ecma_transforms_typescript/tests/fixture/issue-357/input.ts diff --git a/crates/swc_ecma_transforms_typescript/tests/fixture/issue-236/input.ts b/crates/swc_ecma_transforms_typescript/tests/fixture/issue-236/input.ts new file mode 100644 index 000000000000..332ba4ba9a34 --- /dev/null +++ b/crates/swc_ecma_transforms_typescript/tests/fixture/issue-236/input.ts @@ -0,0 +1 @@ +function foo(this: any, $scope: angular.IScope) { } \ No newline at end of file diff --git a/crates/swc_ecma_transforms_typescript/tests/fixture/issue-357/input.ts b/crates/swc_ecma_transforms_typescript/tests/fixture/issue-357/input.ts new file mode 100644 index 000000000000..3b8b6c098543 --- /dev/null +++ b/crates/swc_ecma_transforms_typescript/tests/fixture/issue-357/input.ts @@ -0,0 +1,23 @@ +export function addProp( + obj: T, + prop: K, + value: V +): T & { [x in K]: V }; +export function addProp( + prop: K, + value: V +): (obj: T) => T & { [x in K]: V }; + +export function addProp(arg1: any, arg2: any, arg3?: any): any { + if (arguments.length === 2) { + return (object: any) => _addProp(object, arg1, arg2); + } + return _addProp(arg1, arg2, arg3); +} + +function _addProp(obj: any, prop: string, value: any) { + return { + ...obj, + [prop]: value, + }; +} \ No newline at end of file diff --git a/crates/swc_ecma_transforms_typescript/tests/strip.rs b/crates/swc_ecma_transforms_typescript/tests/strip.rs index 99bff62e2bc4..2108f74f04c3 100644 --- a/crates/swc_ecma_transforms_typescript/tests/strip.rs +++ b/crates/swc_ecma_transforms_typescript/tests/strip.rs @@ -95,53 +95,6 @@ test!( // TODO: Test function / variable hoisting -to!( - issue_236, - "function foo(this: any, $scope: angular.IScope){}", - "function foo($scope){}" -); - -to!( - issue_357, - "export function addProp( - obj: T, - prop: K, - value: V -): T & { [x in K]: V }; -export function addProp( - prop: K, - value: V -): (obj: T) => T & { [x in K]: V }; - -export function addProp(arg1: any, arg2: any, arg3?: any): any { - if (arguments.length === 2) { - return (object: any) => _addProp(object, arg1, arg2); - } - return _addProp(arg1, arg2, arg3); -} - -function _addProp(obj: any, prop: string, value: any) { - return { - ...obj, - [prop]: value, - }; -}", - "export function addProp(arg1, arg2, arg3) { - if (arguments.length === 2) { - return (object) => _addProp(object, arg1, arg2); - } - return _addProp(arg1, arg2, arg3); -} - -function _addProp(obj, prop, value) { - return { - ...obj, - [prop]: value, - }; -} -" -); - to!( issue_366_01, " From d7d9a19bd25aa946f6c72270b1d6e935747dc621 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Wed, 30 Nov 2022 14:49:25 +0900 Subject: [PATCH 13/19] Migrate --- .../tests/fixture/issue-392/1/input.ts | 2 ++ crates/swc_ecma_transforms_typescript/tests/strip.rs | 10 ---------- 2 files changed, 2 insertions(+), 10 deletions(-) create mode 100644 crates/swc_ecma_transforms_typescript/tests/fixture/issue-392/1/input.ts diff --git a/crates/swc_ecma_transforms_typescript/tests/fixture/issue-392/1/input.ts b/crates/swc_ecma_transforms_typescript/tests/fixture/issue-392/1/input.ts new file mode 100644 index 000000000000..1e656b499714 --- /dev/null +++ b/crates/swc_ecma_transforms_typescript/tests/fixture/issue-392/1/input.ts @@ -0,0 +1,2 @@ +import { PlainObject } from 'simplytyped'; +const dict: PlainObject = {}; diff --git a/crates/swc_ecma_transforms_typescript/tests/strip.rs b/crates/swc_ecma_transforms_typescript/tests/strip.rs index 2108f74f04c3..d96a4a642755 100644 --- a/crates/swc_ecma_transforms_typescript/tests/strip.rs +++ b/crates/swc_ecma_transforms_typescript/tests/strip.rs @@ -115,16 +115,6 @@ function enter(foo: string): number; "" ); -to!( - issue_392_1, - " -import { PlainObject } from 'simplytyped'; -const dict: PlainObject = {}; -", - " -const dict = {};" -); - test!( ::swc_ecma_parser::Syntax::Typescript(Default::default()), |_| tr(), From df101446948f16e9b7422c24e68097c898ee0ce5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Wed, 30 Nov 2022 14:50:00 +0900 Subject: [PATCH 14/19] Migrate --- .../tests/fixture/issue-366/1/input.ts | 5 +++++ .../tests/fixture/issue-366/2/input.ts | 2 ++ .../tests/strip.rs | 20 ------------------- 3 files changed, 7 insertions(+), 20 deletions(-) create mode 100644 crates/swc_ecma_transforms_typescript/tests/fixture/issue-366/1/input.ts create mode 100644 crates/swc_ecma_transforms_typescript/tests/fixture/issue-366/2/input.ts diff --git a/crates/swc_ecma_transforms_typescript/tests/fixture/issue-366/1/input.ts b/crates/swc_ecma_transforms_typescript/tests/fixture/issue-366/1/input.ts new file mode 100644 index 000000000000..43d6132ac7a6 --- /dev/null +++ b/crates/swc_ecma_transforms_typescript/tests/fixture/issue-366/1/input.ts @@ -0,0 +1,5 @@ +class App { + public enter?(): void; + public leave?(): void; + public destroy?(): void; +} \ No newline at end of file diff --git a/crates/swc_ecma_transforms_typescript/tests/fixture/issue-366/2/input.ts b/crates/swc_ecma_transforms_typescript/tests/fixture/issue-366/2/input.ts new file mode 100644 index 000000000000..25d05fc68efb --- /dev/null +++ b/crates/swc_ecma_transforms_typescript/tests/fixture/issue-366/2/input.ts @@ -0,0 +1,2 @@ +function enter(): string; +function enter(foo: string): number; \ No newline at end of file diff --git a/crates/swc_ecma_transforms_typescript/tests/strip.rs b/crates/swc_ecma_transforms_typescript/tests/strip.rs index d96a4a642755..6fef8ae45cb0 100644 --- a/crates/swc_ecma_transforms_typescript/tests/strip.rs +++ b/crates/swc_ecma_transforms_typescript/tests/strip.rs @@ -95,26 +95,6 @@ test!( // TODO: Test function / variable hoisting -to!( - issue_366_01, - " -class App { - public enter?(): void; - public leave?(): void; - public destroy?(): void; -}", - "class App {}" -); - -to!( - issue_366_02, - " -function enter(): string; -function enter(foo: string): number; -", - "" -); - test!( ::swc_ecma_parser::Syntax::Typescript(Default::default()), |_| tr(), From 136e7ad6c01388dda0224f98f792b7fa79e32be3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Wed, 30 Nov 2022 14:50:22 +0900 Subject: [PATCH 15/19] Revert "Remove again" This reverts commit 5ef35017e94b52e599c8554acd264399d8fe2957. --- .../tests/strip.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/crates/swc_ecma_transforms_typescript/tests/strip.rs b/crates/swc_ecma_transforms_typescript/tests/strip.rs index 6fef8ae45cb0..f5688d372cb9 100644 --- a/crates/swc_ecma_transforms_typescript/tests/strip.rs +++ b/crates/swc_ecma_transforms_typescript/tests/strip.rs @@ -49,6 +49,22 @@ fn properties(t: &Tester, loose: bool) -> impl Fold { ) } +macro_rules! to { + ($name:ident, $from:expr, $to:expr) => { + test!( + Syntax::Typescript(TsConfig { + decorators: true, + ..Default::default() + }), + |t| chain!(tr(), properties(t, true)), + $name, + $from, + $to, + ok_if_code_eq + ); + }; +} + macro_rules! test_with_config { ($name:ident, $config:expr, $from:expr, $to:expr) => { test!( From ab0a497ecb5599a2f80f5cc4b1b49ad4a37e7ba2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Wed, 30 Nov 2022 14:50:45 +0900 Subject: [PATCH 16/19] Update test refs --- .../tests/fixture/issue-179/1/output.js | 1 + .../tests/fixture/issue-179/2/output.js | 2 ++ .../tests/fixture/issue-236/output.js | 1 + .../tests/fixture/issue-357/output.js | 12 ++++++++++++ .../tests/fixture/issue-366/1/output.js | 2 ++ .../tests/fixture/issue-392/1/output.js | 1 + 6 files changed, 19 insertions(+) create mode 100644 crates/swc_ecma_transforms_typescript/tests/fixture/issue-179/1/output.js create mode 100644 crates/swc_ecma_transforms_typescript/tests/fixture/issue-179/2/output.js create mode 100644 crates/swc_ecma_transforms_typescript/tests/fixture/issue-236/output.js create mode 100644 crates/swc_ecma_transforms_typescript/tests/fixture/issue-357/output.js create mode 100644 crates/swc_ecma_transforms_typescript/tests/fixture/issue-366/1/output.js create mode 100644 crates/swc_ecma_transforms_typescript/tests/fixture/issue-392/1/output.js diff --git a/crates/swc_ecma_transforms_typescript/tests/fixture/issue-179/1/output.js b/crates/swc_ecma_transforms_typescript/tests/fixture/issue-179/1/output.js new file mode 100644 index 000000000000..673c2e1d089e --- /dev/null +++ b/crates/swc_ecma_transforms_typescript/tests/fixture/issue-179/1/output.js @@ -0,0 +1 @@ +const a = {}; diff --git a/crates/swc_ecma_transforms_typescript/tests/fixture/issue-179/2/output.js b/crates/swc_ecma_transforms_typescript/tests/fixture/issue-179/2/output.js new file mode 100644 index 000000000000..930c29db8557 --- /dev/null +++ b/crates/swc_ecma_transforms_typescript/tests/fixture/issue-179/2/output.js @@ -0,0 +1,2 @@ +import { Types } from 'other'; +const a = Types.foo; diff --git a/crates/swc_ecma_transforms_typescript/tests/fixture/issue-236/output.js b/crates/swc_ecma_transforms_typescript/tests/fixture/issue-236/output.js new file mode 100644 index 000000000000..3931cf2162fe --- /dev/null +++ b/crates/swc_ecma_transforms_typescript/tests/fixture/issue-236/output.js @@ -0,0 +1 @@ +function foo($scope) {} diff --git a/crates/swc_ecma_transforms_typescript/tests/fixture/issue-357/output.js b/crates/swc_ecma_transforms_typescript/tests/fixture/issue-357/output.js new file mode 100644 index 000000000000..c79df1df1677 --- /dev/null +++ b/crates/swc_ecma_transforms_typescript/tests/fixture/issue-357/output.js @@ -0,0 +1,12 @@ +export function addProp(arg1, arg2, arg3) { + if (arguments.length === 2) { + return (object)=>_addProp(object, arg1, arg2); + } + return _addProp(arg1, arg2, arg3); +} +function _addProp(obj, prop, value) { + return { + ...obj, + [prop]: value + }; +} diff --git a/crates/swc_ecma_transforms_typescript/tests/fixture/issue-366/1/output.js b/crates/swc_ecma_transforms_typescript/tests/fixture/issue-366/1/output.js new file mode 100644 index 000000000000..035df9ba8d0e --- /dev/null +++ b/crates/swc_ecma_transforms_typescript/tests/fixture/issue-366/1/output.js @@ -0,0 +1,2 @@ +class App { +} diff --git a/crates/swc_ecma_transforms_typescript/tests/fixture/issue-392/1/output.js b/crates/swc_ecma_transforms_typescript/tests/fixture/issue-392/1/output.js new file mode 100644 index 000000000000..1866bccd302c --- /dev/null +++ b/crates/swc_ecma_transforms_typescript/tests/fixture/issue-392/1/output.js @@ -0,0 +1 @@ +const dict = {}; From a85b0f2b2f776b5b5c07c0c9884eb4505d074d96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Wed, 30 Nov 2022 15:13:20 +0900 Subject: [PATCH 17/19] upgrade --- .github/workflows/CI.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 59e4cb50cfda..0c7bfe13ed50 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -2,7 +2,7 @@ name: CI on: pull_request: - types: ['opened', 'reopened', 'synchronize'] + types: ["opened", "reopened", "synchronize"] push: branches: - main @@ -170,7 +170,7 @@ jobs: run: | echo '[patch.crates-io]' >> bindings/Cargo.toml ./scripts/cargo/patch-section.sh >> bindings/Cargo.toml - cd bindings && cargo update + cd bindings && cargo upgrade swc_core && cargo update - name: Install wasm-pack run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh @@ -733,7 +733,7 @@ jobs: echo '[patch.crates-io]' >> bindings/Cargo.toml ./scripts/cargo/patch-section.sh ./scripts/cargo/patch-section.sh >> bindings/Cargo.toml - cd bindings && cargo update + cd bindings && cargo upgrade swc_core && cargo update - name: Cache uses: actions/cache@v3 @@ -795,7 +795,7 @@ jobs: run: | echo '[patch.crates-io]' >> bindings/Cargo.toml ./scripts/cargo/patch-section.sh >> bindings/Cargo.toml - cd bindings && cargo update + cd bindings && cargo upgrade swc_core && cargo update - name: Prepare run: | From 65f9df7a3bf224411b0e795e424d4776d1ba2e0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Wed, 30 Nov 2022 15:16:47 +0900 Subject: [PATCH 18/19] --workspace --- .github/workflows/CI.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 0c7bfe13ed50..4ba56967bfbb 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -170,7 +170,7 @@ jobs: run: | echo '[patch.crates-io]' >> bindings/Cargo.toml ./scripts/cargo/patch-section.sh >> bindings/Cargo.toml - cd bindings && cargo upgrade swc_core && cargo update + cd bindings && cargo upgrade --workspace swc_core && cargo update - name: Install wasm-pack run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh @@ -733,7 +733,7 @@ jobs: echo '[patch.crates-io]' >> bindings/Cargo.toml ./scripts/cargo/patch-section.sh ./scripts/cargo/patch-section.sh >> bindings/Cargo.toml - cd bindings && cargo upgrade swc_core && cargo update + cd bindings && cargo upgrade --workspace swc_core && cargo update - name: Cache uses: actions/cache@v3 @@ -795,7 +795,7 @@ jobs: run: | echo '[patch.crates-io]' >> bindings/Cargo.toml ./scripts/cargo/patch-section.sh >> bindings/Cargo.toml - cd bindings && cargo upgrade swc_core && cargo update + cd bindings && cargo upgrade --workspace swc_core && cargo update - name: Prepare run: | From 32951aee231a0041b0af40691954754de8eb8276 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Wed, 30 Nov 2022 15:49:58 +0900 Subject: [PATCH 19/19] Fix --- .github/workflows/CI.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 4ba56967bfbb..e0ba47449269 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -170,7 +170,7 @@ jobs: run: | echo '[patch.crates-io]' >> bindings/Cargo.toml ./scripts/cargo/patch-section.sh >> bindings/Cargo.toml - cd bindings && cargo upgrade --workspace swc_core && cargo update + cd bindings && cargo update - name: Install wasm-pack run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh @@ -733,7 +733,7 @@ jobs: echo '[patch.crates-io]' >> bindings/Cargo.toml ./scripts/cargo/patch-section.sh ./scripts/cargo/patch-section.sh >> bindings/Cargo.toml - cd bindings && cargo upgrade --workspace swc_core && cargo update + cd bindings && cargo update - name: Cache uses: actions/cache@v3 @@ -795,7 +795,7 @@ jobs: run: | echo '[patch.crates-io]' >> bindings/Cargo.toml ./scripts/cargo/patch-section.sh >> bindings/Cargo.toml - cd bindings && cargo upgrade --workspace swc_core && cargo update + cd bindings && cargo update - name: Prepare run: |