From bc658143dfc0c6abc6107dd91c534e0a3b2264f1 Mon Sep 17 00:00:00 2001 From: magic-akari Date: Sat, 11 Mar 2023 02:07:28 +0800 Subject: [PATCH 1/4] fix(es/compat): Simplify static blocks in the Class --- crates/swc/src/builder.rs | 3 ++- crates/swc_ecma_preset_env/src/lib.rs | 10 ++++++++-- .../src/es2022/class_properties/member_init.rs | 3 +++ .../src/es2022/class_properties/mod.rs | 7 +++++++ crates/swc_ecma_transforms_compat/src/es2022/mod.rs | 2 +- .../src/es2022/static_blocks.rs | 12 +++++++----- 6 files changed, 28 insertions(+), 9 deletions(-) diff --git a/crates/swc/src/builder.rs b/crates/swc/src/builder.rs index fba86420a296..ad4d02fbe98e 100644 --- a/crates/swc/src/builder.rs +++ b/crates/swc/src/builder.rs @@ -221,7 +221,8 @@ impl<'a, 'b, P: swc_ecma_visit::Fold> PassBuilder<'a, 'b, P> { private_as_properties: assumptions.private_fields_as_properties, constant_super: assumptions.constant_super, set_public_fields: assumptions.set_public_class_fields, - no_document_all: assumptions.no_document_all + no_document_all: assumptions.no_document_all, + static_blocks_mark: Mark::new(), } } ), diff --git a/crates/swc_ecma_preset_env/src/lib.rs b/crates/swc_ecma_preset_env/src/lib.rs index 2ffaa2fefe50..9ac8d7137f2a 100644 --- a/crates/swc_ecma_preset_env/src/lib.rs +++ b/crates/swc_ecma_preset_env/src/lib.rs @@ -121,7 +121,12 @@ where // ES2022 // static block needs to be placed before class property // because it transforms into private static property - let pass = add!(pass, ClassStaticBlock, es2022::static_blocks()); + let static_blocks_mark = Mark::new(); + let pass = add!( + pass, + ClassStaticBlock, + es2022::static_blocks(static_blocks_mark) + ); let pass = add!( pass, ClassProperties, @@ -131,7 +136,8 @@ where private_as_properties: loose || assumptions.private_fields_as_properties, set_public_fields: loose || assumptions.set_public_class_fields, constant_super: loose || assumptions.constant_super, - no_document_all: loose || assumptions.no_document_all + no_document_all: loose || assumptions.no_document_all, + static_blocks_mark, } ) ); diff --git a/crates/swc_ecma_transforms_compat/src/es2022/class_properties/member_init.rs b/crates/swc_ecma_transforms_compat/src/es2022/class_properties/member_init.rs index 816d67daa300..24e8752297fc 100644 --- a/crates/swc_ecma_transforms_compat/src/es2022/class_properties/member_init.rs +++ b/crates/swc_ecma_transforms_compat/src/es2022/class_properties/member_init.rs @@ -13,6 +13,7 @@ pub(super) enum MemberInit { PrivProp(PrivProp), PrivMethod(PrivMethod), PrivAccessor(PrivAccessor), + StaticBlock(Box), } pub(super) struct PubProp { @@ -181,6 +182,7 @@ impl MemberInitRecord { } .into(), ), + MemberInit::StaticBlock(..) => unreachable!(), } } @@ -311,6 +313,7 @@ impl MemberInitRecord { unreachable!() } } + MemberInit::StaticBlock(expr) => value_init.push(expr.into_stmt()), } } diff --git a/crates/swc_ecma_transforms_compat/src/es2022/class_properties/mod.rs b/crates/swc_ecma_transforms_compat/src/es2022/class_properties/mod.rs index 529f51a5b368..c04ba42153a8 100644 --- a/crates/swc_ecma_transforms_compat/src/es2022/class_properties/mod.rs +++ b/crates/swc_ecma_transforms_compat/src/es2022/class_properties/mod.rs @@ -59,6 +59,7 @@ pub struct Config { pub set_public_fields: bool, pub constant_super: bool, pub no_document_all: bool, + pub static_blocks_mark: Mark, } struct ClassProperties { @@ -708,6 +709,12 @@ impl ClassProperties { let value = prop.value.unwrap_or_else(|| undefined(prop_span)); + if prop.is_static && prop.span.has_mark(self.c.static_blocks_mark) { + let init = MemberInit::StaticBlock(value); + extra_inits.push(init); + continue; + } + let init = MemberInit::PrivProp(PrivProp { span: prop_span, name: ident.clone(), diff --git a/crates/swc_ecma_transforms_compat/src/es2022/mod.rs b/crates/swc_ecma_transforms_compat/src/es2022/mod.rs index 13b9fec0857c..063217f3b83f 100644 --- a/crates/swc_ecma_transforms_compat/src/es2022/mod.rs +++ b/crates/swc_ecma_transforms_compat/src/es2022/mod.rs @@ -23,7 +23,7 @@ pub fn es2022(cm: Option, config: Config) -> impl Fold { unicode_property_regex: true, unicode_regex: false, }), - static_blocks(), + static_blocks(config.class_properties.static_blocks_mark), class_properties(cm, config.class_properties), private_in_object(), ) diff --git a/crates/swc_ecma_transforms_compat/src/es2022/static_blocks.rs b/crates/swc_ecma_transforms_compat/src/es2022/static_blocks.rs index 14df20250ecf..d47a7d500ee7 100644 --- a/crates/swc_ecma_transforms_compat/src/es2022/static_blocks.rs +++ b/crates/swc_ecma_transforms_compat/src/es2022/static_blocks.rs @@ -1,15 +1,17 @@ use swc_atoms::JsWord; -use swc_common::{collections::AHashSet, util::take::Take, DUMMY_SP}; +use swc_common::{collections::AHashSet, util::take::Take, Mark, DUMMY_SP}; use swc_ecma_ast::*; use swc_ecma_utils::ExprFactory; use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; use swc_trace_macro::swc_trace; -struct ClassStaticBlock; +struct ClassStaticBlock { + mark: Mark, +} #[tracing::instrument(level = "info", skip_all)] -pub fn static_blocks() -> impl Fold + VisitMut { - as_folder(ClassStaticBlock) +pub fn static_blocks(mark: Mark) -> impl Fold + VisitMut { + as_folder(ClassStaticBlock { mark }) } #[swc_trace] @@ -20,7 +22,7 @@ impl ClassStaticBlock { private_id: JsWord, ) -> PrivateProp { PrivateProp { - span: DUMMY_SP, + span: DUMMY_SP.apply_mark(self.mark), is_static: true, is_optional: false, is_override: false, From fff28810c8584a3d2559d28c859cd1bb85fac115 Mon Sep 17 00:00:00 2001 From: magic-akari Date: Sat, 11 Mar 2023 02:07:41 +0800 Subject: [PATCH 2/4] chore: update test cases --- ...assStaticBlock1(target=es2015).1.normal.js | 11 +- .../classStaticBlock1(target=es5).1.normal.js | 11 +- ...ssStaticBlock10(target=es2015).1.normal.js | 28 +- ...classStaticBlock10(target=es5).1.normal.js | 30 +- ...ssStaticBlock11(target=es2015).1.normal.js | 11 +- .../classStaticBlock12.1.normal.js | 9 +- ...ssStaticBlock13(target=es2015).1.normal.js | 9 +- .../classStaticBlock14.1.normal.js | 30 +- ...ssStaticBlock15(target=es2015).1.normal.js | 30 +- .../classStaticBlock17.1.normal.js | 23 +- ...ssStaticBlock18(target=es2015).1.normal.js | 22 +- ...classStaticBlock18(target=es5).1.normal.js | 26 +- ...assStaticBlock2(target=es2015).1.normal.js | 26 +- .../classStaticBlock2(target=es5).1.normal.js | 26 +- .../classStaticBlock21.1.normal.js | 9 +- ...classStaticBlock24(module=amd).1.normal.js | 9 +- ...StaticBlock24(module=commonjs).1.normal.js | 9 +- ...classStaticBlock24(module=es6).1.normal.js | 9 +- ...ssStaticBlock24(module=system).1.normal.js | 11 +- ...classStaticBlock24(module=umd).1.normal.js | 9 +- .../classStaticBlock27.1.normal.js | 31 +- .../classStaticBlock28.1.normal.js | 9 +- ...assStaticBlock5(target=es2015).1.normal.js | 13 +- .../classStaticBlock5(target=es5).1.normal.js | 13 +- ...assStaticBlock9(target=es2015).1.normal.js | 9 +- .../classStaticBlock9(target=es5).1.normal.js | 9 +- .../classStaticBlockUseBeforeDef3.1.normal.js | 47 +- ...nStaticMembers1(target=es2015).1.normal.js | 376 ++++++---------- ...nStaticMembers1(target=es2021).1.normal.js | 376 ++++++---------- ...erInStaticMembers1(target=es5).1.normal.js | 416 +++++++----------- 30 files changed, 588 insertions(+), 1059 deletions(-) diff --git a/crates/swc/tests/tsc-references/classStaticBlock1(target=es2015).1.normal.js b/crates/swc/tests/tsc-references/classStaticBlock1(target=es2015).1.normal.js index 4cdf93bac9b9..3a8208ffed1a 100644 --- a/crates/swc/tests/tsc-references/classStaticBlock1(target=es2015).1.normal.js +++ b/crates/swc/tests/tsc-references/classStaticBlock1(target=es2015).1.normal.js @@ -2,10 +2,7 @@ const a = 2; class C { } -var __ = { - writable: true, - value: (()=>{ - const a = 1; - a; - })() -}; +(()=>{ + const a = 1; + a; +})(); diff --git a/crates/swc/tests/tsc-references/classStaticBlock1(target=es5).1.normal.js b/crates/swc/tests/tsc-references/classStaticBlock1(target=es5).1.normal.js index 544cb2e2f334..2b619fc3a19d 100644 --- a/crates/swc/tests/tsc-references/classStaticBlock1(target=es5).1.normal.js +++ b/crates/swc/tests/tsc-references/classStaticBlock1(target=es5).1.normal.js @@ -5,10 +5,7 @@ var C = function C() { "use strict"; _class_call_check(this, C); }; -var __ = { - writable: true, - value: function() { - var a = 1; - a; - }() -}; +(function() { + var a = 1; + a; +})(); diff --git a/crates/swc/tests/tsc-references/classStaticBlock10(target=es2015).1.normal.js b/crates/swc/tests/tsc-references/classStaticBlock10(target=es2015).1.normal.js index 8a3534a963aa..e0ff657b113f 100644 --- a/crates/swc/tests/tsc-references/classStaticBlock10(target=es2015).1.normal.js +++ b/crates/swc/tests/tsc-references/classStaticBlock10(target=es2015).1.normal.js @@ -8,24 +8,18 @@ function f() { const b1 = 22; class C1 { } - var __ = { - writable: true, - value: (()=>{ - var a1 = 111; - var a2 = 111; - const b1 = 222; - const b2 = 222; - })() - }; -} -class C2 { -} -var __ = { - writable: true, - value: (()=>{ + (()=>{ var a1 = 111; var a2 = 111; const b1 = 222; const b2 = 222; - })() -}; + })(); +} +class C2 { +} +(()=>{ + var a1 = 111; + var a2 = 111; + const b1 = 222; + const b2 = 222; +})(); diff --git a/crates/swc/tests/tsc-references/classStaticBlock10(target=es5).1.normal.js b/crates/swc/tests/tsc-references/classStaticBlock10(target=es5).1.normal.js index 5515d7d5f102..0b1069fe530a 100644 --- a/crates/swc/tests/tsc-references/classStaticBlock10(target=es5).1.normal.js +++ b/crates/swc/tests/tsc-references/classStaticBlock10(target=es5).1.normal.js @@ -11,26 +11,20 @@ function f() { "use strict"; _class_call_check(this, C1); }; - var __ = { - writable: true, - value: function() { - var a1 = 111; - var a2 = 111; - var b1 = 222; - var b2 = 222; - }() - }; -} -var C2 = function C2() { - "use strict"; - _class_call_check(this, C2); -}; -var __ = { - writable: true, - value: function() { + (function() { var a1 = 111; var a2 = 111; var b1 = 222; var b2 = 222; - }() + })(); +} +var C2 = function C2() { + "use strict"; + _class_call_check(this, C2); }; +(function() { + var a1 = 111; + var a2 = 111; + var b1 = 222; + var b2 = 222; +})(); diff --git a/crates/swc/tests/tsc-references/classStaticBlock11(target=es2015).1.normal.js b/crates/swc/tests/tsc-references/classStaticBlock11(target=es2015).1.normal.js index e660af69a239..1b50754c7fe0 100644 --- a/crates/swc/tests/tsc-references/classStaticBlock11(target=es2015).1.normal.js +++ b/crates/swc/tests/tsc-references/classStaticBlock11(target=es2015).1.normal.js @@ -13,10 +13,7 @@ class C { _class_private_field_set(this, _x, x); } } -var __ = { - writable: true, - value: (()=>{ - // getX has privileged access to #x - getX = (obj)=>_class_private_field_get(obj, _x); - })() -}; +(()=>{ + // getX has privileged access to #x + getX = (obj)=>_class_private_field_get(obj, _x); +})(); diff --git a/crates/swc/tests/tsc-references/classStaticBlock12.1.normal.js b/crates/swc/tests/tsc-references/classStaticBlock12.1.normal.js index b8ef44e33534..561f52a1f824 100644 --- a/crates/swc/tests/tsc-references/classStaticBlock12.1.normal.js +++ b/crates/swc/tests/tsc-references/classStaticBlock12.1.normal.js @@ -6,9 +6,6 @@ var _x = { writable: true, value: 1 }; -var __ = { - writable: true, - value: (()=>{ - _class_static_private_field_spec_get(C, C, _x); - })() -}; +(()=>{ + _class_static_private_field_spec_get(C, C, _x); +})(); diff --git a/crates/swc/tests/tsc-references/classStaticBlock13(target=es2015).1.normal.js b/crates/swc/tests/tsc-references/classStaticBlock13(target=es2015).1.normal.js index 0db34b2f97ca..6bb31f604c46 100644 --- a/crates/swc/tests/tsc-references/classStaticBlock13(target=es2015).1.normal.js +++ b/crates/swc/tests/tsc-references/classStaticBlock13(target=es2015).1.normal.js @@ -9,9 +9,6 @@ var _x = { writable: true, value: 123 }; -var __ = { - writable: true, - value: (()=>{ - console.log(_class_static_private_field_spec_get(C, C, _x)); - })() -}; +(()=>{ + console.log(_class_static_private_field_spec_get(C, C, _x)); +})(); diff --git a/crates/swc/tests/tsc-references/classStaticBlock14.1.normal.js b/crates/swc/tests/tsc-references/classStaticBlock14.1.normal.js index 5e11bace498d..d62cf78882de 100644 --- a/crates/swc/tests/tsc-references/classStaticBlock14.1.normal.js +++ b/crates/swc/tests/tsc-references/classStaticBlock14.1.normal.js @@ -13,27 +13,9 @@ var __5 = { writable: true, value: 1 }; -var __ = { - writable: true, - value: (()=>{})() -}; -var __2 = { - writable: true, - value: (()=>{})() -}; -var __4 = { - writable: true, - value: (()=>{})() -}; -var __6 = { - writable: true, - value: (()=>{})() -}; -var __7 = { - writable: true, - value: (()=>{})() -}; -var __8 = { - writable: true, - value: (()=>{})() -}; +(()=>{})(); +(()=>{})(); +(()=>{})(); +(()=>{})(); +(()=>{})(); +(()=>{})(); diff --git a/crates/swc/tests/tsc-references/classStaticBlock15(target=es2015).1.normal.js b/crates/swc/tests/tsc-references/classStaticBlock15(target=es2015).1.normal.js index a9675f9ddc34..fd03a8c49edd 100644 --- a/crates/swc/tests/tsc-references/classStaticBlock15(target=es2015).1.normal.js +++ b/crates/swc/tests/tsc-references/classStaticBlock15(target=es2015).1.normal.js @@ -14,28 +14,10 @@ var __5 = { writable: true, value: 5 }; -var __ = { - writable: true, - value: (()=>{})() -}; -var __2 = { - writable: true, - value: (()=>{})() -}; -var __4 = { - writable: true, - value: (()=>{})() -}; -var __6 = { - writable: true, - value: (()=>{})() -}; -var __7 = { - writable: true, - value: (()=>{})() -}; -var __8 = { - writable: true, - value: (()=>{})() -}; +(()=>{})(); +(()=>{})(); +(()=>{})(); +(()=>{})(); +(()=>{})(); +(()=>{})(); console.log(_C__1); diff --git a/crates/swc/tests/tsc-references/classStaticBlock17.1.normal.js b/crates/swc/tests/tsc-references/classStaticBlock17.1.normal.js index d05fb921091d..b0dc44a59fc8 100644 --- a/crates/swc/tests/tsc-references/classStaticBlock17.1.normal.js +++ b/crates/swc/tests/tsc-references/classStaticBlock17.1.normal.js @@ -16,19 +16,16 @@ class A { _class_private_field_set(this, _x, v); } } -var __ = { - writable: true, - value: (()=>{ - friendA = { - getX (obj) { - return _class_private_field_get(obj, _x); - }, - setX (obj, value) { - _class_private_field_set(obj, _x, value); - } - }; - })() -}; +(()=>{ + friendA = { + getX (obj) { + return _class_private_field_get(obj, _x); + }, + setX (obj, value) { + _class_private_field_set(obj, _x, value); + } + }; +})(); class B { constructor(a){ const x = friendA.getX(a); // ok diff --git a/crates/swc/tests/tsc-references/classStaticBlock18(target=es2015).1.normal.js b/crates/swc/tests/tsc-references/classStaticBlock18(target=es2015).1.normal.js index 385d2e62e0e6..1b57660e300a 100644 --- a/crates/swc/tests/tsc-references/classStaticBlock18(target=es2015).1.normal.js +++ b/crates/swc/tests/tsc-references/classStaticBlock18(target=es2015).1.normal.js @@ -1,18 +1,12 @@ //// [classStaticBlock18.ts] function foo() { - var _class, __; + var _class; return _class = class { - }, _class.foo = 1, __ = { - writable: true, - value: (()=>{ - var _class, __; - const c = (_class = class { - }, _class.bar = 2, __ = { - writable: true, - value: (()=>{ - // do - })() - }, _class); - })() - }, _class; + }, _class.foo = 1, (()=>{ + var _class; + const c = (_class = class { + }, _class.bar = 2, (()=>{ + // do + })(), _class); + })(), _class; } diff --git a/crates/swc/tests/tsc-references/classStaticBlock18(target=es5).1.normal.js b/crates/swc/tests/tsc-references/classStaticBlock18(target=es5).1.normal.js index bf6c5e32f9a4..a18ceb169209 100644 --- a/crates/swc/tests/tsc-references/classStaticBlock18(target=es5).1.normal.js +++ b/crates/swc/tests/tsc-references/classStaticBlock18(target=es5).1.normal.js @@ -1,23 +1,17 @@ //// [classStaticBlock18.ts] import _class_call_check from "@swc/helpers/src/_class_call_check.mjs"; function foo() { - var _class, __; + var _class; return _class = function _class() { "use strict"; _class_call_check(this, _class); - }, _class.foo = 1, __ = { - writable: true, - value: function() { - var _class, __; - var c = (_class = function _class() { - "use strict"; - _class_call_check(this, _class); - }, _class.bar = 2, __ = { - writable: true, - value: function() { - // do - }() - }, _class); - }() - }, _class; + }, _class.foo = 1, function() { + var _class; + var c = (_class = function _class() { + "use strict"; + _class_call_check(this, _class); + }, _class.bar = 2, function() { + // do + }(), _class); + }(), _class; } diff --git a/crates/swc/tests/tsc-references/classStaticBlock2(target=es2015).1.normal.js b/crates/swc/tests/tsc-references/classStaticBlock2(target=es2015).1.normal.js index 8d12ea9bf704..cc3f216d36f9 100644 --- a/crates/swc/tests/tsc-references/classStaticBlock2(target=es2015).1.normal.js +++ b/crates/swc/tests/tsc-references/classStaticBlock2(target=es2015).1.normal.js @@ -3,19 +3,13 @@ const a = 1; const b = 2; class C { } -var __ = { - writable: true, - value: (()=>{ - const a = 11; - a; - b; - })() -}; -var __1 = { - writable: true, - value: (()=>{ - const a = 11; - a; - b; - })() -}; +(()=>{ + const a = 11; + a; + b; +})(); +(()=>{ + const a = 11; + a; + b; +})(); diff --git a/crates/swc/tests/tsc-references/classStaticBlock2(target=es5).1.normal.js b/crates/swc/tests/tsc-references/classStaticBlock2(target=es5).1.normal.js index a183cc569384..253f77aa2131 100644 --- a/crates/swc/tests/tsc-references/classStaticBlock2(target=es5).1.normal.js +++ b/crates/swc/tests/tsc-references/classStaticBlock2(target=es5).1.normal.js @@ -6,19 +6,13 @@ var C = function C() { "use strict"; _class_call_check(this, C); }; -var __ = { - writable: true, - value: function() { - var a = 11; - a; - b; - }() -}; -var __1 = { - writable: true, - value: function() { - var a = 11; - a; - b; - }() -}; +(function() { + var a = 11; + a; + b; +})(); +(function() { + var a = 11; + a; + b; +})(); diff --git a/crates/swc/tests/tsc-references/classStaticBlock21.1.normal.js b/crates/swc/tests/tsc-references/classStaticBlock21.1.normal.js index f8954bf204e3..a431debd5f55 100644 --- a/crates/swc/tests/tsc-references/classStaticBlock21.1.normal.js +++ b/crates/swc/tests/tsc-references/classStaticBlock21.1.normal.js @@ -4,9 +4,6 @@ var C = function C() { "use strict"; _class_call_check(this, C); }; -var __ = { - writable: true, - value: function() { - // something - }() -}; +(function() { +// something +})(); diff --git a/crates/swc/tests/tsc-references/classStaticBlock24(module=amd).1.normal.js b/crates/swc/tests/tsc-references/classStaticBlock24(module=amd).1.normal.js index c55e91535bfd..69a1749f5c8e 100644 --- a/crates/swc/tests/tsc-references/classStaticBlock24(module=amd).1.normal.js +++ b/crates/swc/tests/tsc-references/classStaticBlock24(module=amd).1.normal.js @@ -19,10 +19,7 @@ define([ "use strict"; _classCallCheck(this, C); }; - var __ = { - writable: true, - value: function() { - C.x = 1; - }() - }; + (function() { + C.x = 1; + })(); }); diff --git a/crates/swc/tests/tsc-references/classStaticBlock24(module=commonjs).1.normal.js b/crates/swc/tests/tsc-references/classStaticBlock24(module=commonjs).1.normal.js index e7fd7e6ac818..b2c7e7f1eb6b 100644 --- a/crates/swc/tests/tsc-references/classStaticBlock24(module=commonjs).1.normal.js +++ b/crates/swc/tests/tsc-references/classStaticBlock24(module=commonjs).1.normal.js @@ -14,9 +14,6 @@ var C = function C() { "use strict"; _classCallCheck(this, C); }; -var __ = { - writable: true, - value: function() { - C.x = 1; - }() -}; +(function() { + C.x = 1; +})(); diff --git a/crates/swc/tests/tsc-references/classStaticBlock24(module=es6).1.normal.js b/crates/swc/tests/tsc-references/classStaticBlock24(module=es6).1.normal.js index 6aa8d62cc0bf..3d226ee93fe7 100644 --- a/crates/swc/tests/tsc-references/classStaticBlock24(module=es6).1.normal.js +++ b/crates/swc/tests/tsc-references/classStaticBlock24(module=es6).1.normal.js @@ -4,9 +4,6 @@ export var C = function C() { "use strict"; _class_call_check(this, C); }; -var __ = { - writable: true, - value: function() { - C.x = 1; - }() -}; +(function() { + C.x = 1; +})(); diff --git a/crates/swc/tests/tsc-references/classStaticBlock24(module=system).1.normal.js b/crates/swc/tests/tsc-references/classStaticBlock24(module=system).1.normal.js index a89655da4c2c..edea98fd0a89 100644 --- a/crates/swc/tests/tsc-references/classStaticBlock24(module=system).1.normal.js +++ b/crates/swc/tests/tsc-references/classStaticBlock24(module=system).1.normal.js @@ -3,7 +3,7 @@ System.register([ "@swc/helpers/src/_class_call_check.mjs" ], function(_export, _context) { "use strict"; - var _class_call_check, C, __; + var _class_call_check, C; return { setters: [ function(_classCallCheck) { @@ -15,12 +15,9 @@ System.register([ "use strict"; _class_call_check(this, C); }); - __ = { - writable: true, - value: function() { - C.x = 1; - }() - }; + (function() { + C.x = 1; + })(); } }; }); diff --git a/crates/swc/tests/tsc-references/classStaticBlock24(module=umd).1.normal.js b/crates/swc/tests/tsc-references/classStaticBlock24(module=umd).1.normal.js index 449484a5feb3..d2a22b27b0f7 100644 --- a/crates/swc/tests/tsc-references/classStaticBlock24(module=umd).1.normal.js +++ b/crates/swc/tests/tsc-references/classStaticBlock24(module=umd).1.normal.js @@ -22,10 +22,7 @@ "use strict"; _classCallCheck(this, C); }; - var __ = { - writable: true, - value: function() { - C.x = 1; - }() - }; + (function() { + C.x = 1; + })(); }); diff --git a/crates/swc/tests/tsc-references/classStaticBlock27.1.normal.js b/crates/swc/tests/tsc-references/classStaticBlock27.1.normal.js index 76c5f51138d1..f285123e77a7 100644 --- a/crates/swc/tests/tsc-references/classStaticBlock27.1.normal.js +++ b/crates/swc/tests/tsc-references/classStaticBlock27.1.normal.js @@ -1,26 +1,17 @@ //// [classStaticBlock27.ts] // https://github.com/microsoft/TypeScript/issues/44872 import _class_call_check from "@swc/helpers/src/_class_call_check.mjs"; -var _Foo, __, __1, __2; +var _Foo; void (_Foo = function Foo() { "use strict"; _class_call_check(this, Foo); -}, _Foo.prop = 1, __ = { - writable: true, - value: function() { - console.log(_Foo.prop); - _Foo.prop++; - }() -}, __1 = { - writable: true, - value: function() { - console.log(_Foo.prop); - _Foo.prop++; - }() -}, __2 = { - writable: true, - value: function() { - console.log(_Foo.prop); - _Foo.prop++; - }() -}, _Foo); +}, _Foo.prop = 1, function() { + console.log(_Foo.prop); + _Foo.prop++; +}(), function() { + console.log(_Foo.prop); + _Foo.prop++; +}(), function() { + console.log(_Foo.prop); + _Foo.prop++; +}(), _Foo); diff --git a/crates/swc/tests/tsc-references/classStaticBlock28.1.normal.js b/crates/swc/tests/tsc-references/classStaticBlock28.1.normal.js index 452f01e8b29d..e65f6a2265a0 100644 --- a/crates/swc/tests/tsc-references/classStaticBlock28.1.normal.js +++ b/crates/swc/tests/tsc-references/classStaticBlock28.1.normal.js @@ -5,10 +5,7 @@ var C = function C() { "use strict"; _class_call_check(this, C); }; -var __ = { - writable: true, - value: function() { - foo = 1; - }() -}; +(function() { + foo = 1; +})(); console.log(foo); diff --git a/crates/swc/tests/tsc-references/classStaticBlock5(target=es2015).1.normal.js b/crates/swc/tests/tsc-references/classStaticBlock5(target=es2015).1.normal.js index 7cb5aca271e8..393451dbf1d7 100644 --- a/crates/swc/tests/tsc-references/classStaticBlock5(target=es2015).1.normal.js +++ b/crates/swc/tests/tsc-references/classStaticBlock5(target=es2015).1.normal.js @@ -9,11 +9,8 @@ class C extends B { } C.b = 3; C.c = _get(_get_prototype_of(C), "a", C); -var __ = { - writable: true, - value: (()=>{ - C.b; - _get(_get_prototype_of(C), "b", C); - _get(_get_prototype_of(C), "a", C); - })() -}; +(()=>{ + C.b; + _get(_get_prototype_of(C), "b", C); + _get(_get_prototype_of(C), "a", C); +})(); diff --git a/crates/swc/tests/tsc-references/classStaticBlock5(target=es5).1.normal.js b/crates/swc/tests/tsc-references/classStaticBlock5(target=es5).1.normal.js index 5094e01844c4..4710e2fbf38b 100644 --- a/crates/swc/tests/tsc-references/classStaticBlock5(target=es5).1.normal.js +++ b/crates/swc/tests/tsc-references/classStaticBlock5(target=es5).1.normal.js @@ -22,11 +22,8 @@ var C = /*#__PURE__*/ function(B) { }(B); C.b = 3; C.c = _get(_get_prototype_of(C), "a", C); -var __ = { - writable: true, - value: function() { - C.b; - _get(_get_prototype_of(C), "b", C); - _get(_get_prototype_of(C), "a", C); - }() -}; +(function() { + C.b; + _get(_get_prototype_of(C), "b", C); + _get(_get_prototype_of(C), "a", C); +})(); diff --git a/crates/swc/tests/tsc-references/classStaticBlock9(target=es2015).1.normal.js b/crates/swc/tests/tsc-references/classStaticBlock9(target=es2015).1.normal.js index 231b3ea2f1ef..2ce848110610 100644 --- a/crates/swc/tests/tsc-references/classStaticBlock9(target=es2015).1.normal.js +++ b/crates/swc/tests/tsc-references/classStaticBlock9(target=es2015).1.normal.js @@ -2,10 +2,7 @@ class A { } A.bar = A.foo + 1; -var __ = { - writable: true, - value: (()=>{ - A.foo + 2; - })() -}; +(()=>{ + A.foo + 2; +})(); A.foo = 1; diff --git a/crates/swc/tests/tsc-references/classStaticBlock9(target=es5).1.normal.js b/crates/swc/tests/tsc-references/classStaticBlock9(target=es5).1.normal.js index b08b4f8eac15..9629f71d268e 100644 --- a/crates/swc/tests/tsc-references/classStaticBlock9(target=es5).1.normal.js +++ b/crates/swc/tests/tsc-references/classStaticBlock9(target=es5).1.normal.js @@ -5,10 +5,7 @@ var A = function A() { _class_call_check(this, A); }; A.bar = A.foo + 1; -var __ = { - writable: true, - value: function() { - A.foo + 2; - }() -}; +(function() { + A.foo + 2; +})(); A.foo = 1; diff --git a/crates/swc/tests/tsc-references/classStaticBlockUseBeforeDef3.1.normal.js b/crates/swc/tests/tsc-references/classStaticBlockUseBeforeDef3.1.normal.js index ee7b4d64845e..13875c33b267 100644 --- a/crates/swc/tests/tsc-references/classStaticBlockUseBeforeDef3.1.normal.js +++ b/crates/swc/tests/tsc-references/classStaticBlockUseBeforeDef3.1.normal.js @@ -10,33 +10,24 @@ var A = /*#__PURE__*/ function() { }; return A; }(); -var __ = { - writable: true, - value: function() { - A.doSomething(); // should not error - }() -}; +(function() { + A.doSomething(); // should not error +})(); var Baz = function Baz() { "use strict"; _class_call_check(this, Baz); }; -var __1 = { - writable: true, - value: function() { - console.log(FOO); // should error - }() -}; +(function() { + console.log(FOO); // should error +})(); var FOO = "FOO"; var Bar = function Bar() { "use strict"; _class_call_check(this, Bar); }; -var __2 = { - writable: true, - value: function() { - console.log(FOO); // should not error - }() -}; +(function() { + console.log(FOO); // should not error +})(); var u = "FOO"; var CFA = /*#__PURE__*/ function() { "use strict"; @@ -46,18 +37,12 @@ var CFA = /*#__PURE__*/ function() { CFA.doSomething = function doSomething() {}; return CFA; }(); -var __3 = { - writable: true, - value: function() { - u = "BAR"; - u; // should be "BAR" - }() -}; +(function() { + u = "BAR"; + u; // should be "BAR" +})(); CFA.t = 1; -var __11 = { - writable: true, - value: function() { - u; // should be "BAR" - }() -}; +(function() { + u; // should be "BAR" +})(); u; // should be "BAR" diff --git a/crates/swc/tests/tsc-references/superInStaticMembers1(target=es2015).1.normal.js b/crates/swc/tests/tsc-references/superInStaticMembers1(target=es2015).1.normal.js index 9ff1bede349d..ae18c26c20b7 100644 --- a/crates/swc/tests/tsc-references/superInStaticMembers1(target=es2015).1.normal.js +++ b/crates/swc/tests/tsc-references/superInStaticMembers1(target=es2015).1.normal.js @@ -65,93 +65,60 @@ C._ = [ _get(_get_prototype_of(C), "w", C).call(C); })() ]; -var __ = { - writable: true, - value: (()=>{ - var { Reflect } = { - Reflect: null - }; // collision (es2015-es2021 only) - _get(_get_prototype_of(C), "w", C).call(C); - })() -}; -var __1 = { - writable: true, - value: (()=>{ - var [Reflect] = [ - null - ]; // collision (es2015-es2021 only) - _get(_get_prototype_of(C), "w", C).call(C); - })() -}; -var __2 = { - writable: true, - value: (()=>{ - var Reflect; // collision (es2015-es2021 only) - _get(_get_prototype_of(C), "w", C).call(C); - })() -}; -var __3 = { - writable: true, - value: (()=>{ - class Reflect { - } // collision (es2015-es2021 only) - _get(_get_prototype_of(C), "w", C).call(C); - })() -}; -var __4 = { - writable: true, - value: (()=>{ - function Reflect() {} // collision (es2015-es2021 only) - _get(_get_prototype_of(C), "w", C).call(C); - })() -}; -var __5 = { - writable: true, - value: (()=>{ - let Reflect// collision (es2015-es2021 only) - ; - (function(Reflect) {})(Reflect || (Reflect = {})); - _get(_get_prototype_of(C), "w", C).call(C); - })() -}; -var __6 = { - writable: true, - value: (()=>{ - let Reflect// collision (es2015-es2021 only) - ; - (function(Reflect) {})(Reflect || (Reflect = {})); - _get(_get_prototype_of(C), "w", C).call(C); - })() -}; -var __7 = { - writable: true, - value: (()=>{ - _get(_get_prototype_of(C), "w", C).call(C); - })() -}; -var __8 = { - writable: true, - value: (()=>{ - _get(_get_prototype_of(C), "w", C).call(C); - })() -}; -var __9 = { - writable: true, - value: (()=>{ - (class Reflect { - } // no collision - ); - _get(_get_prototype_of(C), "w", C).call(C); - })() -}; -var __10 = { - writable: true, - value: (()=>{ - (function Reflect() {} // no collision - ); - _get(_get_prototype_of(C), "w", C).call(C); - })() -}; +(()=>{ + var { Reflect } = { + Reflect: null + }; // collision (es2015-es2021 only) + _get(_get_prototype_of(C), "w", C).call(C); +})(); +(()=>{ + var [Reflect] = [ + null + ]; // collision (es2015-es2021 only) + _get(_get_prototype_of(C), "w", C).call(C); +})(); +(()=>{ + var Reflect; // collision (es2015-es2021 only) + _get(_get_prototype_of(C), "w", C).call(C); +})(); +(()=>{ + class Reflect { + } // collision (es2015-es2021 only) + _get(_get_prototype_of(C), "w", C).call(C); +})(); +(()=>{ + function Reflect() {} // collision (es2015-es2021 only) + _get(_get_prototype_of(C), "w", C).call(C); +})(); +(()=>{ + let Reflect// collision (es2015-es2021 only) + ; + (function(Reflect) {})(Reflect || (Reflect = {})); + _get(_get_prototype_of(C), "w", C).call(C); +})(); +(()=>{ + let Reflect// collision (es2015-es2021 only) + ; + (function(Reflect) {})(Reflect || (Reflect = {})); + _get(_get_prototype_of(C), "w", C).call(C); +})(); +(()=>{ + _get(_get_prototype_of(C), "w", C).call(C); +})(); +(()=>{ + _get(_get_prototype_of(C), "w", C).call(C); +})(); +(()=>{ + (class Reflect { + } // no collision + ); + _get(_get_prototype_of(C), "w", C).call(C); +})(); +(()=>{ + (function Reflect() {} // no collision + ); + _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [varInContainingScopeStaticField1.ts] import _get from "@swc/helpers/src/_get.mjs"; @@ -187,12 +154,9 @@ import _get_prototype_of from "@swc/helpers/src/_get_prototype_of.mjs"; var Reflect = null; // collision (es2015-es2021 only) class C extends B { } -var __ = { - writable: true, - value: (()=>{ - _get(_get_prototype_of(C), "w", C).call(C); - })() -}; +(()=>{ + _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [varInContainingScopeStaticBlock2.ts] import _get from "@swc/helpers/src/_get.mjs"; @@ -202,12 +166,9 @@ var { Reflect } = { }; // collision (es2015-es2021 only) class C extends B { } -var __ = { - writable: true, - value: (()=>{ - _get(_get_prototype_of(C), "w", C).call(C); - })() -}; +(()=>{ + _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [varInContainingScopeStaticBlock3.ts] import _get from "@swc/helpers/src/_get.mjs"; @@ -217,12 +178,9 @@ var [Reflect] = [ ]; // collision (es2015-es2021 only) class C extends B { } -var __ = { - writable: true, - value: (()=>{ - _get(_get_prototype_of(C), "w", C).call(C); - })() -}; +(()=>{ + _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [classDeclInContainingScopeStaticField.ts] import _get from "@swc/helpers/src/_get.mjs"; @@ -240,12 +198,9 @@ class Reflect { } // collision (es2015-es2021 only) class C extends B { } -var __ = { - writable: true, - value: (()=>{ - _get(_get_prototype_of(C), "w", C).call(C); - })() -}; +(()=>{ + _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [funcDeclInContainingScopeStaticField.ts] import _get from "@swc/helpers/src/_get.mjs"; @@ -261,12 +216,9 @@ import _get_prototype_of from "@swc/helpers/src/_get_prototype_of.mjs"; function Reflect() {} // collision (es2015-es2021 only) class C extends B { } -var __ = { - writable: true, - value: (()=>{ - _get(_get_prototype_of(C), "w", C).call(C); - })() -}; +(()=>{ + _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [valueNamespaceInContainingScopeStaticField.ts] import _get from "@swc/helpers/src/_get.mjs"; @@ -280,12 +232,9 @@ import _get from "@swc/helpers/src/_get.mjs"; import _get_prototype_of from "@swc/helpers/src/_get_prototype_of.mjs"; class C extends B { } -var __ = { - writable: true, - value: (()=>{ - _get(_get_prototype_of(C), "w", C).call(C); - })() -}; +(()=>{ + _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [enumInContainingScopeStaticField.ts] import _get from "@swc/helpers/src/_get.mjs"; @@ -305,12 +254,9 @@ var Reflect// collision (es2015-es2021 only) (function(Reflect) {})(Reflect || (Reflect = {})); class C extends B { } -var __ = { - writable: true, - value: (()=>{ - _get(_get_prototype_of(C), "w", C).call(C); - })() -}; +(()=>{ + _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [constEnumInContainingScopeStaticField.ts] import _get from "@swc/helpers/src/_get.mjs"; @@ -330,12 +276,9 @@ var Reflect// collision (es2015-es2021 only) (function(Reflect) {})(Reflect || (Reflect = {})); class C extends B { } -var __ = { - writable: true, - value: (()=>{ - _get(_get_prototype_of(C), "w", C).call(C); - })() -}; +(()=>{ + _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [namespaceImportInContainingScopeStaticField.ts] import _get from "@swc/helpers/src/_get.mjs"; @@ -349,12 +292,9 @@ import _get from "@swc/helpers/src/_get.mjs"; import _get_prototype_of from "@swc/helpers/src/_get_prototype_of.mjs"; class C extends B { } -var __ = { - writable: true, - value: (()=>{ - _get(_get_prototype_of(C), "w", C).call(C); - })() -}; +(()=>{ + _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [namedImportInContainingScopeStaticField.ts] import _get from "@swc/helpers/src/_get.mjs"; @@ -368,12 +308,9 @@ import _get from "@swc/helpers/src/_get.mjs"; import _get_prototype_of from "@swc/helpers/src/_get_prototype_of.mjs"; class C extends B { } -var __ = { - writable: true, - value: (()=>{ - _get(_get_prototype_of(C), "w", C).call(C); - })() -}; +(()=>{ + _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [namedImportOfInterfaceInContainingScopeStaticField.ts] import _get from "@swc/helpers/src/_get.mjs"; @@ -387,12 +324,9 @@ import _get from "@swc/helpers/src/_get.mjs"; import _get_prototype_of from "@swc/helpers/src/_get_prototype_of.mjs"; class C extends B { } -var __ = { - writable: true, - value: (()=>{ - _get(_get_prototype_of(C), "w", C).call(C); - })() -}; +(()=>{ + _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [namedImportOfUninstantiatedNamespaceInContainingScopeStaticField.ts] import _get from "@swc/helpers/src/_get.mjs"; @@ -406,12 +340,9 @@ import _get from "@swc/helpers/src/_get.mjs"; import _get_prototype_of from "@swc/helpers/src/_get_prototype_of.mjs"; class C extends B { } -var __ = { - writable: true, - value: (()=>{ - _get(_get_prototype_of(C), "w", C).call(C); - })() -}; +(()=>{ + _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [namedImportOfConstEnumInContainingScopeStaticField.ts] import _get from "@swc/helpers/src/_get.mjs"; @@ -425,12 +356,9 @@ import _get from "@swc/helpers/src/_get.mjs"; import _get_prototype_of from "@swc/helpers/src/_get_prototype_of.mjs"; class C extends B { } -var __ = { - writable: true, - value: (()=>{ - _get(_get_prototype_of(C), "w", C).call(C); - })() -}; +(()=>{ + _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [typeOnlyNamedImportInContainingScopeStaticField.ts] import _get from "@swc/helpers/src/_get.mjs"; @@ -444,12 +372,9 @@ import _get from "@swc/helpers/src/_get.mjs"; import _get_prototype_of from "@swc/helpers/src/_get_prototype_of.mjs"; class C extends B { } -var __ = { - writable: true, - value: (()=>{ - _get(_get_prototype_of(C), "w", C).call(C); - })() -}; +(()=>{ + _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [defaultImportInContainingScopeStaticField.ts] import _get from "@swc/helpers/src/_get.mjs"; @@ -463,12 +388,9 @@ import _get from "@swc/helpers/src/_get.mjs"; import _get_prototype_of from "@swc/helpers/src/_get_prototype_of.mjs"; class C extends B { } -var __ = { - writable: true, - value: (()=>{ - _get(_get_prototype_of(C), "w", C).call(C); - })() -}; +(()=>{ + _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [typeOnlyDefaultImportInContainingScopeStaticField.ts] import _get from "@swc/helpers/src/_get.mjs"; @@ -482,12 +404,9 @@ import _get from "@swc/helpers/src/_get.mjs"; import _get_prototype_of from "@swc/helpers/src/_get_prototype_of.mjs"; class C extends B { } -var __ = { - writable: true, - value: (()=>{ - _get(_get_prototype_of(C), "w", C).call(C); - })() -}; +(()=>{ + _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [typeInContainingScopeStaticField.ts] import _get from "@swc/helpers/src/_get.mjs"; @@ -501,12 +420,9 @@ import _get from "@swc/helpers/src/_get.mjs"; import _get_prototype_of from "@swc/helpers/src/_get_prototype_of.mjs"; class C extends B { } -var __ = { - writable: true, - value: (()=>{ - _get(_get_prototype_of(C), "w", C).call(C); - })() -}; +(()=>{ + _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [interfaceInContainingScopeStaticField.ts] import _get from "@swc/helpers/src/_get.mjs"; @@ -520,12 +436,9 @@ import _get from "@swc/helpers/src/_get.mjs"; import _get_prototype_of from "@swc/helpers/src/_get_prototype_of.mjs"; class C extends B { } -var __ = { - writable: true, - value: (()=>{ - _get(_get_prototype_of(C), "w", C).call(C); - })() -}; +(()=>{ + _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [uninstantiatedNamespaceInContainingScopeStaticField.ts] import _get from "@swc/helpers/src/_get.mjs"; @@ -539,12 +452,9 @@ import _get from "@swc/helpers/src/_get.mjs"; import _get_prototype_of from "@swc/helpers/src/_get_prototype_of.mjs"; class C extends B { } -var __ = { - writable: true, - value: (()=>{ - _get(_get_prototype_of(C), "w", C).call(C); - })() -}; +(()=>{ + _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [classExprInContainingScopeStaticField.ts] import _get from "@swc/helpers/src/_get.mjs"; @@ -562,45 +472,33 @@ import _get_prototype_of from "@swc/helpers/src/_get_prototype_of.mjs"; }); // no collision class C extends B { } -var __ = { - writable: true, - value: (()=>{ - _get(_get_prototype_of(C), "w", C).call(C); - })() -}; +(()=>{ + _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [inContainingClassExprStaticField.ts] import _get from "@swc/helpers/src/_get.mjs"; import _get_prototype_of from "@swc/helpers/src/_get_prototype_of.mjs"; -var _Reflect, __; +var _Reflect; _Reflect = class Reflect { -}, __ = { - writable: true, - value: (()=>{ - class C extends B { - } - C._ = _get(_get_prototype_of(C), "w", C).call(C); - })() -}, _Reflect; +}, (()=>{ + class C extends B { + } + C._ = _get(_get_prototype_of(C), "w", C).call(C); +})(), _Reflect; export { }; //// [inContainingClassExprStaticBlock.ts] import _get from "@swc/helpers/src/_get.mjs"; import _get_prototype_of from "@swc/helpers/src/_get_prototype_of.mjs"; -var _Reflect, __; +var _Reflect; _Reflect = class Reflect { -}, __ = { - writable: true, - value: (()=>{ - class C extends B { - } - var __ = { - writable: true, - value: (()=>{ - _get(_get_prototype_of(C), "w", C).call(C); - })() - }; - })() -}, _Reflect; +}, (()=>{ + class C extends B { + } + (()=>{ + _get(_get_prototype_of(C), "w", C).call(C); + })(); +})(), _Reflect; export { }; //// [funcExprInContainingScopeStaticField.ts] import _get from "@swc/helpers/src/_get.mjs"; @@ -616,12 +514,9 @@ import _get_prototype_of from "@swc/helpers/src/_get_prototype_of.mjs"; (function Reflect() {}); // no collision class C extends B { } -var __ = { - writable: true, - value: (()=>{ - _get(_get_prototype_of(C), "w", C).call(C); - })() -}; +(()=>{ + _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [inContainingFuncExprStaticField.ts] import _get from "@swc/helpers/src/_get.mjs"; @@ -638,11 +533,8 @@ import _get_prototype_of from "@swc/helpers/src/_get_prototype_of.mjs"; (function Reflect() { class C extends B { } - var __ = { - writable: true, - value: (()=>{ - _get(_get_prototype_of(C), "w", C).call(C); - })() - }; + (()=>{ + _get(_get_prototype_of(C), "w", C).call(C); + })(); }); export { }; diff --git a/crates/swc/tests/tsc-references/superInStaticMembers1(target=es2021).1.normal.js b/crates/swc/tests/tsc-references/superInStaticMembers1(target=es2021).1.normal.js index 9ff1bede349d..ae18c26c20b7 100644 --- a/crates/swc/tests/tsc-references/superInStaticMembers1(target=es2021).1.normal.js +++ b/crates/swc/tests/tsc-references/superInStaticMembers1(target=es2021).1.normal.js @@ -65,93 +65,60 @@ C._ = [ _get(_get_prototype_of(C), "w", C).call(C); })() ]; -var __ = { - writable: true, - value: (()=>{ - var { Reflect } = { - Reflect: null - }; // collision (es2015-es2021 only) - _get(_get_prototype_of(C), "w", C).call(C); - })() -}; -var __1 = { - writable: true, - value: (()=>{ - var [Reflect] = [ - null - ]; // collision (es2015-es2021 only) - _get(_get_prototype_of(C), "w", C).call(C); - })() -}; -var __2 = { - writable: true, - value: (()=>{ - var Reflect; // collision (es2015-es2021 only) - _get(_get_prototype_of(C), "w", C).call(C); - })() -}; -var __3 = { - writable: true, - value: (()=>{ - class Reflect { - } // collision (es2015-es2021 only) - _get(_get_prototype_of(C), "w", C).call(C); - })() -}; -var __4 = { - writable: true, - value: (()=>{ - function Reflect() {} // collision (es2015-es2021 only) - _get(_get_prototype_of(C), "w", C).call(C); - })() -}; -var __5 = { - writable: true, - value: (()=>{ - let Reflect// collision (es2015-es2021 only) - ; - (function(Reflect) {})(Reflect || (Reflect = {})); - _get(_get_prototype_of(C), "w", C).call(C); - })() -}; -var __6 = { - writable: true, - value: (()=>{ - let Reflect// collision (es2015-es2021 only) - ; - (function(Reflect) {})(Reflect || (Reflect = {})); - _get(_get_prototype_of(C), "w", C).call(C); - })() -}; -var __7 = { - writable: true, - value: (()=>{ - _get(_get_prototype_of(C), "w", C).call(C); - })() -}; -var __8 = { - writable: true, - value: (()=>{ - _get(_get_prototype_of(C), "w", C).call(C); - })() -}; -var __9 = { - writable: true, - value: (()=>{ - (class Reflect { - } // no collision - ); - _get(_get_prototype_of(C), "w", C).call(C); - })() -}; -var __10 = { - writable: true, - value: (()=>{ - (function Reflect() {} // no collision - ); - _get(_get_prototype_of(C), "w", C).call(C); - })() -}; +(()=>{ + var { Reflect } = { + Reflect: null + }; // collision (es2015-es2021 only) + _get(_get_prototype_of(C), "w", C).call(C); +})(); +(()=>{ + var [Reflect] = [ + null + ]; // collision (es2015-es2021 only) + _get(_get_prototype_of(C), "w", C).call(C); +})(); +(()=>{ + var Reflect; // collision (es2015-es2021 only) + _get(_get_prototype_of(C), "w", C).call(C); +})(); +(()=>{ + class Reflect { + } // collision (es2015-es2021 only) + _get(_get_prototype_of(C), "w", C).call(C); +})(); +(()=>{ + function Reflect() {} // collision (es2015-es2021 only) + _get(_get_prototype_of(C), "w", C).call(C); +})(); +(()=>{ + let Reflect// collision (es2015-es2021 only) + ; + (function(Reflect) {})(Reflect || (Reflect = {})); + _get(_get_prototype_of(C), "w", C).call(C); +})(); +(()=>{ + let Reflect// collision (es2015-es2021 only) + ; + (function(Reflect) {})(Reflect || (Reflect = {})); + _get(_get_prototype_of(C), "w", C).call(C); +})(); +(()=>{ + _get(_get_prototype_of(C), "w", C).call(C); +})(); +(()=>{ + _get(_get_prototype_of(C), "w", C).call(C); +})(); +(()=>{ + (class Reflect { + } // no collision + ); + _get(_get_prototype_of(C), "w", C).call(C); +})(); +(()=>{ + (function Reflect() {} // no collision + ); + _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [varInContainingScopeStaticField1.ts] import _get from "@swc/helpers/src/_get.mjs"; @@ -187,12 +154,9 @@ import _get_prototype_of from "@swc/helpers/src/_get_prototype_of.mjs"; var Reflect = null; // collision (es2015-es2021 only) class C extends B { } -var __ = { - writable: true, - value: (()=>{ - _get(_get_prototype_of(C), "w", C).call(C); - })() -}; +(()=>{ + _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [varInContainingScopeStaticBlock2.ts] import _get from "@swc/helpers/src/_get.mjs"; @@ -202,12 +166,9 @@ var { Reflect } = { }; // collision (es2015-es2021 only) class C extends B { } -var __ = { - writable: true, - value: (()=>{ - _get(_get_prototype_of(C), "w", C).call(C); - })() -}; +(()=>{ + _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [varInContainingScopeStaticBlock3.ts] import _get from "@swc/helpers/src/_get.mjs"; @@ -217,12 +178,9 @@ var [Reflect] = [ ]; // collision (es2015-es2021 only) class C extends B { } -var __ = { - writable: true, - value: (()=>{ - _get(_get_prototype_of(C), "w", C).call(C); - })() -}; +(()=>{ + _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [classDeclInContainingScopeStaticField.ts] import _get from "@swc/helpers/src/_get.mjs"; @@ -240,12 +198,9 @@ class Reflect { } // collision (es2015-es2021 only) class C extends B { } -var __ = { - writable: true, - value: (()=>{ - _get(_get_prototype_of(C), "w", C).call(C); - })() -}; +(()=>{ + _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [funcDeclInContainingScopeStaticField.ts] import _get from "@swc/helpers/src/_get.mjs"; @@ -261,12 +216,9 @@ import _get_prototype_of from "@swc/helpers/src/_get_prototype_of.mjs"; function Reflect() {} // collision (es2015-es2021 only) class C extends B { } -var __ = { - writable: true, - value: (()=>{ - _get(_get_prototype_of(C), "w", C).call(C); - })() -}; +(()=>{ + _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [valueNamespaceInContainingScopeStaticField.ts] import _get from "@swc/helpers/src/_get.mjs"; @@ -280,12 +232,9 @@ import _get from "@swc/helpers/src/_get.mjs"; import _get_prototype_of from "@swc/helpers/src/_get_prototype_of.mjs"; class C extends B { } -var __ = { - writable: true, - value: (()=>{ - _get(_get_prototype_of(C), "w", C).call(C); - })() -}; +(()=>{ + _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [enumInContainingScopeStaticField.ts] import _get from "@swc/helpers/src/_get.mjs"; @@ -305,12 +254,9 @@ var Reflect// collision (es2015-es2021 only) (function(Reflect) {})(Reflect || (Reflect = {})); class C extends B { } -var __ = { - writable: true, - value: (()=>{ - _get(_get_prototype_of(C), "w", C).call(C); - })() -}; +(()=>{ + _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [constEnumInContainingScopeStaticField.ts] import _get from "@swc/helpers/src/_get.mjs"; @@ -330,12 +276,9 @@ var Reflect// collision (es2015-es2021 only) (function(Reflect) {})(Reflect || (Reflect = {})); class C extends B { } -var __ = { - writable: true, - value: (()=>{ - _get(_get_prototype_of(C), "w", C).call(C); - })() -}; +(()=>{ + _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [namespaceImportInContainingScopeStaticField.ts] import _get from "@swc/helpers/src/_get.mjs"; @@ -349,12 +292,9 @@ import _get from "@swc/helpers/src/_get.mjs"; import _get_prototype_of from "@swc/helpers/src/_get_prototype_of.mjs"; class C extends B { } -var __ = { - writable: true, - value: (()=>{ - _get(_get_prototype_of(C), "w", C).call(C); - })() -}; +(()=>{ + _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [namedImportInContainingScopeStaticField.ts] import _get from "@swc/helpers/src/_get.mjs"; @@ -368,12 +308,9 @@ import _get from "@swc/helpers/src/_get.mjs"; import _get_prototype_of from "@swc/helpers/src/_get_prototype_of.mjs"; class C extends B { } -var __ = { - writable: true, - value: (()=>{ - _get(_get_prototype_of(C), "w", C).call(C); - })() -}; +(()=>{ + _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [namedImportOfInterfaceInContainingScopeStaticField.ts] import _get from "@swc/helpers/src/_get.mjs"; @@ -387,12 +324,9 @@ import _get from "@swc/helpers/src/_get.mjs"; import _get_prototype_of from "@swc/helpers/src/_get_prototype_of.mjs"; class C extends B { } -var __ = { - writable: true, - value: (()=>{ - _get(_get_prototype_of(C), "w", C).call(C); - })() -}; +(()=>{ + _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [namedImportOfUninstantiatedNamespaceInContainingScopeStaticField.ts] import _get from "@swc/helpers/src/_get.mjs"; @@ -406,12 +340,9 @@ import _get from "@swc/helpers/src/_get.mjs"; import _get_prototype_of from "@swc/helpers/src/_get_prototype_of.mjs"; class C extends B { } -var __ = { - writable: true, - value: (()=>{ - _get(_get_prototype_of(C), "w", C).call(C); - })() -}; +(()=>{ + _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [namedImportOfConstEnumInContainingScopeStaticField.ts] import _get from "@swc/helpers/src/_get.mjs"; @@ -425,12 +356,9 @@ import _get from "@swc/helpers/src/_get.mjs"; import _get_prototype_of from "@swc/helpers/src/_get_prototype_of.mjs"; class C extends B { } -var __ = { - writable: true, - value: (()=>{ - _get(_get_prototype_of(C), "w", C).call(C); - })() -}; +(()=>{ + _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [typeOnlyNamedImportInContainingScopeStaticField.ts] import _get from "@swc/helpers/src/_get.mjs"; @@ -444,12 +372,9 @@ import _get from "@swc/helpers/src/_get.mjs"; import _get_prototype_of from "@swc/helpers/src/_get_prototype_of.mjs"; class C extends B { } -var __ = { - writable: true, - value: (()=>{ - _get(_get_prototype_of(C), "w", C).call(C); - })() -}; +(()=>{ + _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [defaultImportInContainingScopeStaticField.ts] import _get from "@swc/helpers/src/_get.mjs"; @@ -463,12 +388,9 @@ import _get from "@swc/helpers/src/_get.mjs"; import _get_prototype_of from "@swc/helpers/src/_get_prototype_of.mjs"; class C extends B { } -var __ = { - writable: true, - value: (()=>{ - _get(_get_prototype_of(C), "w", C).call(C); - })() -}; +(()=>{ + _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [typeOnlyDefaultImportInContainingScopeStaticField.ts] import _get from "@swc/helpers/src/_get.mjs"; @@ -482,12 +404,9 @@ import _get from "@swc/helpers/src/_get.mjs"; import _get_prototype_of from "@swc/helpers/src/_get_prototype_of.mjs"; class C extends B { } -var __ = { - writable: true, - value: (()=>{ - _get(_get_prototype_of(C), "w", C).call(C); - })() -}; +(()=>{ + _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [typeInContainingScopeStaticField.ts] import _get from "@swc/helpers/src/_get.mjs"; @@ -501,12 +420,9 @@ import _get from "@swc/helpers/src/_get.mjs"; import _get_prototype_of from "@swc/helpers/src/_get_prototype_of.mjs"; class C extends B { } -var __ = { - writable: true, - value: (()=>{ - _get(_get_prototype_of(C), "w", C).call(C); - })() -}; +(()=>{ + _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [interfaceInContainingScopeStaticField.ts] import _get from "@swc/helpers/src/_get.mjs"; @@ -520,12 +436,9 @@ import _get from "@swc/helpers/src/_get.mjs"; import _get_prototype_of from "@swc/helpers/src/_get_prototype_of.mjs"; class C extends B { } -var __ = { - writable: true, - value: (()=>{ - _get(_get_prototype_of(C), "w", C).call(C); - })() -}; +(()=>{ + _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [uninstantiatedNamespaceInContainingScopeStaticField.ts] import _get from "@swc/helpers/src/_get.mjs"; @@ -539,12 +452,9 @@ import _get from "@swc/helpers/src/_get.mjs"; import _get_prototype_of from "@swc/helpers/src/_get_prototype_of.mjs"; class C extends B { } -var __ = { - writable: true, - value: (()=>{ - _get(_get_prototype_of(C), "w", C).call(C); - })() -}; +(()=>{ + _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [classExprInContainingScopeStaticField.ts] import _get from "@swc/helpers/src/_get.mjs"; @@ -562,45 +472,33 @@ import _get_prototype_of from "@swc/helpers/src/_get_prototype_of.mjs"; }); // no collision class C extends B { } -var __ = { - writable: true, - value: (()=>{ - _get(_get_prototype_of(C), "w", C).call(C); - })() -}; +(()=>{ + _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [inContainingClassExprStaticField.ts] import _get from "@swc/helpers/src/_get.mjs"; import _get_prototype_of from "@swc/helpers/src/_get_prototype_of.mjs"; -var _Reflect, __; +var _Reflect; _Reflect = class Reflect { -}, __ = { - writable: true, - value: (()=>{ - class C extends B { - } - C._ = _get(_get_prototype_of(C), "w", C).call(C); - })() -}, _Reflect; +}, (()=>{ + class C extends B { + } + C._ = _get(_get_prototype_of(C), "w", C).call(C); +})(), _Reflect; export { }; //// [inContainingClassExprStaticBlock.ts] import _get from "@swc/helpers/src/_get.mjs"; import _get_prototype_of from "@swc/helpers/src/_get_prototype_of.mjs"; -var _Reflect, __; +var _Reflect; _Reflect = class Reflect { -}, __ = { - writable: true, - value: (()=>{ - class C extends B { - } - var __ = { - writable: true, - value: (()=>{ - _get(_get_prototype_of(C), "w", C).call(C); - })() - }; - })() -}, _Reflect; +}, (()=>{ + class C extends B { + } + (()=>{ + _get(_get_prototype_of(C), "w", C).call(C); + })(); +})(), _Reflect; export { }; //// [funcExprInContainingScopeStaticField.ts] import _get from "@swc/helpers/src/_get.mjs"; @@ -616,12 +514,9 @@ import _get_prototype_of from "@swc/helpers/src/_get_prototype_of.mjs"; (function Reflect() {}); // no collision class C extends B { } -var __ = { - writable: true, - value: (()=>{ - _get(_get_prototype_of(C), "w", C).call(C); - })() -}; +(()=>{ + _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [inContainingFuncExprStaticField.ts] import _get from "@swc/helpers/src/_get.mjs"; @@ -638,11 +533,8 @@ import _get_prototype_of from "@swc/helpers/src/_get_prototype_of.mjs"; (function Reflect() { class C extends B { } - var __ = { - writable: true, - value: (()=>{ - _get(_get_prototype_of(C), "w", C).call(C); - })() - }; + (()=>{ + _get(_get_prototype_of(C), "w", C).call(C); + })(); }); export { }; diff --git a/crates/swc/tests/tsc-references/superInStaticMembers1(target=es5).1.normal.js b/crates/swc/tests/tsc-references/superInStaticMembers1(target=es5).1.normal.js index e963a1cdef9c..03a334e3ef75 100644 --- a/crates/swc/tests/tsc-references/superInStaticMembers1(target=es5).1.normal.js +++ b/crates/swc/tests/tsc-references/superInStaticMembers1(target=es5).1.normal.js @@ -86,97 +86,64 @@ C._ = [ _get(_get_prototype_of(C), "w", C).call(C); }() ]; -var __ = { - writable: true, - value: function() { - var Reflect = { - Reflect: null - }.Reflect; // collision (es2015-es2021 only) - _get(_get_prototype_of(C), "w", C).call(C); - }() -}; -var __1 = { - writable: true, - value: function() { - var Reflect = null; // collision (es2015-es2021 only) - _get(_get_prototype_of(C), "w", C).call(C); - }() -}; -var __2 = { - writable: true, - value: function() { - var Reflect; // collision (es2015-es2021 only) - _get(_get_prototype_of(C), "w", C).call(C); - }() -}; -var __3 = { - writable: true, - value: function() { - var Reflect = function Reflect() { - "use strict"; - _class_call_check(this, Reflect); - } // collision (es2015-es2021 only) - ; - _get(_get_prototype_of(C), "w", C).call(C); - }() -}; -var __4 = { - writable: true, - value: function() { - var Reflect = function Reflect() {} // collision (es2015-es2021 only) - ; - _get(_get_prototype_of(C), "w", C).call(C); - }() -}; -var __5 = { - writable: true, - value: function() { - var Reflect// collision (es2015-es2021 only) - ; - (function(Reflect) {})(Reflect || (Reflect = {})); - _get(_get_prototype_of(C), "w", C).call(C); - }() -}; -var __6 = { - writable: true, - value: function() { - var Reflect// collision (es2015-es2021 only) - ; - (function(Reflect) {})(Reflect || (Reflect = {})); - _get(_get_prototype_of(C), "w", C).call(C); - }() -}; -var __7 = { - writable: true, - value: function() { - _get(_get_prototype_of(C), "w", C).call(C); - }() -}; -var __8 = { - writable: true, - value: function() { - _get(_get_prototype_of(C), "w", C).call(C); - }() -}; -var __9 = { - writable: true, - value: function() { - (function Reflect() { - "use strict"; - _class_call_check(this, Reflect); - } // no collision - ); - _get(_get_prototype_of(C), "w", C).call(C); - }() -}; -var __10 = { - writable: true, - value: function() { - (function Reflect() {} // no collision - ); - _get(_get_prototype_of(C), "w", C).call(C); - }() -}; +(function() { + var Reflect = { + Reflect: null + }.Reflect; // collision (es2015-es2021 only) + _get(_get_prototype_of(C), "w", C).call(C); +})(); +(function() { + var Reflect = null; // collision (es2015-es2021 only) + _get(_get_prototype_of(C), "w", C).call(C); +})(); +(function() { + var Reflect; // collision (es2015-es2021 only) + _get(_get_prototype_of(C), "w", C).call(C); +})(); +(function() { + var Reflect = function Reflect() { + "use strict"; + _class_call_check(this, Reflect); + } // collision (es2015-es2021 only) + ; + _get(_get_prototype_of(C), "w", C).call(C); +})(); +(function() { + var Reflect = function Reflect() {} // collision (es2015-es2021 only) + ; + _get(_get_prototype_of(C), "w", C).call(C); +})(); +(function() { + var Reflect// collision (es2015-es2021 only) + ; + (function(Reflect) {})(Reflect || (Reflect = {})); + _get(_get_prototype_of(C), "w", C).call(C); +})(); +(function() { + var Reflect// collision (es2015-es2021 only) + ; + (function(Reflect) {})(Reflect || (Reflect = {})); + _get(_get_prototype_of(C), "w", C).call(C); +})(); +(function() { + _get(_get_prototype_of(C), "w", C).call(C); +})(); +(function() { + _get(_get_prototype_of(C), "w", C).call(C); +})(); +(function() { + (function Reflect() { + "use strict"; + _class_call_check(this, Reflect); + } // no collision + ); + _get(_get_prototype_of(C), "w", C).call(C); +})(); +(function() { + (function Reflect() {} // no collision + ); + _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [varInContainingScopeStaticField1.ts] import _class_call_check from "@swc/helpers/src/_class_call_check.mjs"; @@ -254,12 +221,9 @@ var C = /*#__PURE__*/ function(B1) { } return C; }(B); -var __ = { - writable: true, - value: function() { - _get(_get_prototype_of(C), "w", C).call(C); - }() -}; +(function() { + _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [varInContainingScopeStaticBlock2.ts] import _class_call_check from "@swc/helpers/src/_class_call_check.mjs"; @@ -280,12 +244,9 @@ var C = /*#__PURE__*/ function(B1) { } return C; }(B); -var __ = { - writable: true, - value: function() { - _get(_get_prototype_of(C), "w", C).call(C); - }() -}; +(function() { + _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [varInContainingScopeStaticBlock3.ts] import _class_call_check from "@swc/helpers/src/_class_call_check.mjs"; @@ -304,12 +265,9 @@ var C = /*#__PURE__*/ function(B1) { } return C; }(B); -var __ = { - writable: true, - value: function() { - _get(_get_prototype_of(C), "w", C).call(C); - }() -}; +(function() { + _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [classDeclInContainingScopeStaticField.ts] import _class_call_check from "@swc/helpers/src/_class_call_check.mjs"; @@ -355,12 +313,9 @@ var C = /*#__PURE__*/ function(B1) { } return C; }(B); -var __ = { - writable: true, - value: function() { - _get(_get_prototype_of(C), "w", C).call(C); - }() -}; +(function() { + _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [funcDeclInContainingScopeStaticField.ts] import _class_call_check from "@swc/helpers/src/_class_call_check.mjs"; @@ -398,12 +353,9 @@ var C = /*#__PURE__*/ function(B1) { } return C; }(B); -var __ = { - writable: true, - value: function() { - _get(_get_prototype_of(C), "w", C).call(C); - }() -}; +(function() { + _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [valueNamespaceInContainingScopeStaticField.ts] import _class_call_check from "@swc/helpers/src/_class_call_check.mjs"; @@ -439,12 +391,9 @@ var C = /*#__PURE__*/ function(B1) { } return C; }(B); -var __ = { - writable: true, - value: function() { - _get(_get_prototype_of(C), "w", C).call(C); - }() -}; +(function() { + _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [enumInContainingScopeStaticField.ts] import _class_call_check from "@swc/helpers/src/_class_call_check.mjs"; @@ -486,12 +435,9 @@ var C = /*#__PURE__*/ function(B1) { } return C; }(B); -var __ = { - writable: true, - value: function() { - _get(_get_prototype_of(C), "w", C).call(C); - }() -}; +(function() { + _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [constEnumInContainingScopeStaticField.ts] import _class_call_check from "@swc/helpers/src/_class_call_check.mjs"; @@ -533,12 +479,9 @@ var C = /*#__PURE__*/ function(B1) { } return C; }(B); -var __ = { - writable: true, - value: function() { - _get(_get_prototype_of(C), "w", C).call(C); - }() -}; +(function() { + _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [namespaceImportInContainingScopeStaticField.ts] import _class_call_check from "@swc/helpers/src/_class_call_check.mjs"; @@ -574,12 +517,9 @@ var C = /*#__PURE__*/ function(B1) { } return C; }(B); -var __ = { - writable: true, - value: function() { - _get(_get_prototype_of(C), "w", C).call(C); - }() -}; +(function() { + _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [namedImportInContainingScopeStaticField.ts] import _class_call_check from "@swc/helpers/src/_class_call_check.mjs"; @@ -615,12 +555,9 @@ var C = /*#__PURE__*/ function(B1) { } return C; }(B); -var __ = { - writable: true, - value: function() { - _get(_get_prototype_of(C), "w", C).call(C); - }() -}; +(function() { + _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [namedImportOfInterfaceInContainingScopeStaticField.ts] import _class_call_check from "@swc/helpers/src/_class_call_check.mjs"; @@ -656,12 +593,9 @@ var C = /*#__PURE__*/ function(B1) { } return C; }(B); -var __ = { - writable: true, - value: function() { - _get(_get_prototype_of(C), "w", C).call(C); - }() -}; +(function() { + _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [namedImportOfUninstantiatedNamespaceInContainingScopeStaticField.ts] import _class_call_check from "@swc/helpers/src/_class_call_check.mjs"; @@ -697,12 +631,9 @@ var C = /*#__PURE__*/ function(B1) { } return C; }(B); -var __ = { - writable: true, - value: function() { - _get(_get_prototype_of(C), "w", C).call(C); - }() -}; +(function() { + _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [namedImportOfConstEnumInContainingScopeStaticField.ts] import _class_call_check from "@swc/helpers/src/_class_call_check.mjs"; @@ -738,12 +669,9 @@ var C = /*#__PURE__*/ function(B1) { } return C; }(B); -var __ = { - writable: true, - value: function() { - _get(_get_prototype_of(C), "w", C).call(C); - }() -}; +(function() { + _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [typeOnlyNamedImportInContainingScopeStaticField.ts] import _class_call_check from "@swc/helpers/src/_class_call_check.mjs"; @@ -779,12 +707,9 @@ var C = /*#__PURE__*/ function(B1) { } return C; }(B); -var __ = { - writable: true, - value: function() { - _get(_get_prototype_of(C), "w", C).call(C); - }() -}; +(function() { + _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [defaultImportInContainingScopeStaticField.ts] import _class_call_check from "@swc/helpers/src/_class_call_check.mjs"; @@ -820,12 +745,9 @@ var C = /*#__PURE__*/ function(B1) { } return C; }(B); -var __ = { - writable: true, - value: function() { - _get(_get_prototype_of(C), "w", C).call(C); - }() -}; +(function() { + _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [typeOnlyDefaultImportInContainingScopeStaticField.ts] import _class_call_check from "@swc/helpers/src/_class_call_check.mjs"; @@ -861,12 +783,9 @@ var C = /*#__PURE__*/ function(B1) { } return C; }(B); -var __ = { - writable: true, - value: function() { - _get(_get_prototype_of(C), "w", C).call(C); - }() -}; +(function() { + _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [typeInContainingScopeStaticField.ts] import _class_call_check from "@swc/helpers/src/_class_call_check.mjs"; @@ -902,12 +821,9 @@ var C = /*#__PURE__*/ function(B1) { } return C; }(B); -var __ = { - writable: true, - value: function() { - _get(_get_prototype_of(C), "w", C).call(C); - }() -}; +(function() { + _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [interfaceInContainingScopeStaticField.ts] import _class_call_check from "@swc/helpers/src/_class_call_check.mjs"; @@ -943,12 +859,9 @@ var C = /*#__PURE__*/ function(B1) { } return C; }(B); -var __ = { - writable: true, - value: function() { - _get(_get_prototype_of(C), "w", C).call(C); - }() -}; +(function() { + _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [uninstantiatedNamespaceInContainingScopeStaticField.ts] import _class_call_check from "@swc/helpers/src/_class_call_check.mjs"; @@ -984,12 +897,9 @@ var C = /*#__PURE__*/ function(B1) { } return C; }(B); -var __ = { - writable: true, - value: function() { - _get(_get_prototype_of(C), "w", C).call(C); - }() -}; +(function() { + _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [classExprInContainingScopeStaticField.ts] import _class_call_check from "@swc/helpers/src/_class_call_check.mjs"; @@ -1033,12 +943,9 @@ var C = /*#__PURE__*/ function(B1) { } return C; }(B); -var __ = { - writable: true, - value: function() { - _get(_get_prototype_of(C), "w", C).call(C); - }() -}; +(function() { + _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [inContainingClassExprStaticField.ts] import _class_call_check from "@swc/helpers/src/_class_call_check.mjs"; @@ -1046,26 +953,23 @@ import _get from "@swc/helpers/src/_get.mjs"; import _get_prototype_of from "@swc/helpers/src/_get_prototype_of.mjs"; import _inherits from "@swc/helpers/src/_inherits.mjs"; import _create_super from "@swc/helpers/src/_create_super.mjs"; -var _Reflect, __; +var _Reflect; _Reflect = function Reflect() { "use strict"; _class_call_check(this, Reflect); -}, __ = { - writable: true, - value: function() { - var C = /*#__PURE__*/ function(B1) { - "use strict"; - _inherits(C, B1); - var _super = _create_super(C); - function C() { - _class_call_check(this, C); - return _super.apply(this, arguments); - } - return C; - }(B); - C._ = _get(_get_prototype_of(C), "w", C).call(C); - }() -}, _Reflect; +}, function() { + var C = /*#__PURE__*/ function(B1) { + "use strict"; + _inherits(C, B1); + var _super = _create_super(C); + function C() { + _class_call_check(this, C); + return _super.apply(this, arguments); + } + return C; + }(B); + C._ = _get(_get_prototype_of(C), "w", C).call(C); +}(), _Reflect; export { }; //// [inContainingClassExprStaticBlock.ts] import _class_call_check from "@swc/helpers/src/_class_call_check.mjs"; @@ -1073,31 +977,25 @@ import _get from "@swc/helpers/src/_get.mjs"; import _get_prototype_of from "@swc/helpers/src/_get_prototype_of.mjs"; import _inherits from "@swc/helpers/src/_inherits.mjs"; import _create_super from "@swc/helpers/src/_create_super.mjs"; -var _Reflect, __; +var _Reflect; _Reflect = function Reflect() { "use strict"; _class_call_check(this, Reflect); -}, __ = { - writable: true, - value: function() { - var C = /*#__PURE__*/ function(B1) { - "use strict"; - _inherits(C, B1); - var _super = _create_super(C); - function C() { - _class_call_check(this, C); - return _super.apply(this, arguments); - } - return C; - }(B); - var __ = { - writable: true, - value: function() { - _get(_get_prototype_of(C), "w", C).call(C); - }() - }; - }() -}, _Reflect; +}, function() { + var C = /*#__PURE__*/ function(B1) { + "use strict"; + _inherits(C, B1); + var _super = _create_super(C); + function C() { + _class_call_check(this, C); + return _super.apply(this, arguments); + } + return C; + }(B); + (function() { + _get(_get_prototype_of(C), "w", C).call(C); + })(); +}(), _Reflect; export { }; //// [funcExprInContainingScopeStaticField.ts] import _class_call_check from "@swc/helpers/src/_class_call_check.mjs"; @@ -1135,12 +1033,9 @@ var C = /*#__PURE__*/ function(B1) { } return C; }(B); -var __ = { - writable: true, - value: function() { - _get(_get_prototype_of(C), "w", C).call(C); - }() -}; +(function() { + _get(_get_prototype_of(C), "w", C).call(C); +})(); export { }; //// [inContainingFuncExprStaticField.ts] import _class_call_check from "@swc/helpers/src/_class_call_check.mjs"; @@ -1179,11 +1074,8 @@ import _create_super from "@swc/helpers/src/_create_super.mjs"; } return C; }(B); - var __ = { - writable: true, - value: function() { - _get(_get_prototype_of(C), "w", C).call(C); - }() - }; + (function() { + _get(_get_prototype_of(C), "w", C).call(C); + })(); }); export { }; From e185800734a1bcf8d37af9c8f9310935633b07f8 Mon Sep 17 00:00:00 2001 From: magic-akari Date: Sat, 11 Mar 2023 02:29:32 +0800 Subject: [PATCH 3/4] fix: default config --- .../src/es2022/class_properties/mod.rs | 14 ++++++++- .../tests/es2015_new_target.rs | 3 +- .../tests/es2022_private_in_object.rs | 8 +++-- .../tests/es2022_static_blocks.rs | 10 +++---- .../class-properties/class-binding/output.js | 12 ++++---- .../in-class-heritage/output.js | 29 +++++++------------ .../multiple-static-initializers/output.js | 20 +++++-------- .../class-properties/name-conflict/output.js | 9 ++---- .../class-properties/new-target/output.js | 11 +++---- 9 files changed, 53 insertions(+), 63 deletions(-) diff --git a/crates/swc_ecma_transforms_compat/src/es2022/class_properties/mod.rs b/crates/swc_ecma_transforms_compat/src/es2022/class_properties/mod.rs index c04ba42153a8..25eab987e224 100644 --- a/crates/swc_ecma_transforms_compat/src/es2022/class_properties/mod.rs +++ b/crates/swc_ecma_transforms_compat/src/es2022/class_properties/mod.rs @@ -53,7 +53,7 @@ pub fn class_properties(cm: Option, config: Config) -> impl Fold }) } -#[derive(Debug, Clone, Copy, Default)] +#[derive(Debug, Clone, Copy)] pub struct Config { pub private_as_properties: bool, pub set_public_fields: bool, @@ -62,6 +62,18 @@ pub struct Config { pub static_blocks_mark: Mark, } +impl Default for Config { + fn default() -> Self { + Self { + private_as_properties: false, + set_public_fields: false, + constant_super: false, + no_document_all: false, + static_blocks_mark: Mark::new(), + } + } +} + struct ClassProperties { extra: ClassExtra, c: Config, 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 7acf5ceb02f4..b17707cfb7f6 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2015_new_target.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2015_new_target.rs @@ -43,7 +43,8 @@ fn get_passes(t: &Tester, plugins: &[PluginConfig]) -> Box { constant_super: loose, set_public_fields: loose, private_as_properties: loose, - no_document_all: loose + no_document_all: loose, + static_blocks_mark: Mark::new(), } ) )); diff --git a/crates/swc_ecma_transforms_compat/tests/es2022_private_in_object.rs b/crates/swc_ecma_transforms_compat/tests/es2022_private_in_object.rs index cb19d148a47d..99c3cdec1cda 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2022_private_in_object.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2022_private_in_object.rs @@ -1,7 +1,7 @@ use std::path::PathBuf; use serde::Deserialize; -use swc_common::chain; +use swc_common::{chain, Mark}; use swc_ecma_transforms_base::pass::noop; use swc_ecma_transforms_compat::{ es2015::classes, @@ -59,7 +59,8 @@ fn fixture(input: PathBuf) { set_public_fields: loose, constant_super: loose, no_document_all: loose, - private_as_properties: loose + private_as_properties: loose, + static_blocks_mark: Mark::new(), } ) )); @@ -77,7 +78,8 @@ fn fixture(input: PathBuf) { set_public_fields: loose, constant_super: loose, no_document_all: loose, - private_as_properties: loose + private_as_properties: loose, + static_blocks_mark: Mark::new(), } ) )); diff --git a/crates/swc_ecma_transforms_compat/tests/es2022_static_blocks.rs b/crates/swc_ecma_transforms_compat/tests/es2022_static_blocks.rs index c4224e294e6b..31d8569e878f 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2022_static_blocks.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2022_static_blocks.rs @@ -16,16 +16,14 @@ fn fixture(input: PathBuf) { ..Default::default() }), &|t| { + let config = class_properties::Config::default(); let pass: Box = if input.to_string_lossy().contains("class-properties") { Box::new(chain!( - static_blocks(), - class_properties( - Some(t.comments.clone()), - class_properties::Config::default() - ) + static_blocks(config.static_blocks_mark), + class_properties(Some(t.comments.clone()), config) )) } else { - Box::new(static_blocks()) + Box::new(static_blocks(config.static_blocks_mark)) }; pass }, diff --git a/crates/swc_ecma_transforms_compat/tests/static-blocks/class-properties/class-binding/output.js b/crates/swc_ecma_transforms_compat/tests/static-blocks/class-properties/class-binding/output.js index 0343b6f35463..5227b375fd7d 100644 --- a/crates/swc_ecma_transforms_compat/tests/static-blocks/class-properties/class-binding/output.js +++ b/crates/swc_ecma_transforms_compat/tests/static-blocks/class-properties/class-binding/output.js @@ -1,8 +1,6 @@ -class Foo {} +class Foo { +} _defineProperty(Foo, "bar", 42); -var __ = { - writable: true, - value: (() => { - Foo.foo = Foo.bar; - })(), -}; +(()=>{ + Foo.foo = Foo.bar; +})(); diff --git a/crates/swc_ecma_transforms_compat/tests/static-blocks/class-properties/in-class-heritage/output.js b/crates/swc_ecma_transforms_compat/tests/static-blocks/class-properties/in-class-heritage/output.js index ae51d37ef7b8..5b0be44b6842 100644 --- a/crates/swc_ecma_transforms_compat/tests/static-blocks/class-properties/in-class-heritage/output.js +++ b/crates/swc_ecma_transforms_compat/tests/static-blocks/class-properties/in-class-heritage/output.js @@ -1,21 +1,12 @@ -var _Base, __, _class, __1; +var _Base, _class; class Foo extends (_class = class extends (_Base = class Base { -}, __ = { - writable: true, - value: (()=>{ - _Base.qux = 21; - })() -}, _Base) { -}, __1 = { - writable: true, - value: (()=>{ - _class.bar = 21; - })() -}, _class) { +}, (()=>{ + _Base.qux = 21; +})(), _Base) { +}, (()=>{ + _class.bar = 21; +})(), _class) { } -var __2 = { - writable: true, - value: (()=>{ - Foo.foo = Foo.bar + Foo.qux; - })() -}; +(()=>{ + Foo.foo = Foo.bar + Foo.qux; +})(); diff --git a/crates/swc_ecma_transforms_compat/tests/static-blocks/class-properties/multiple-static-initializers/output.js b/crates/swc_ecma_transforms_compat/tests/static-blocks/class-properties/multiple-static-initializers/output.js index 91d9a0fe52c0..1793f94a7f4b 100644 --- a/crates/swc_ecma_transforms_compat/tests/static-blocks/class-properties/multiple-static-initializers/output.js +++ b/crates/swc_ecma_transforms_compat/tests/static-blocks/class-properties/multiple-static-initializers/output.js @@ -4,17 +4,11 @@ var _bar = { writable: true, value: 21 }; -var __ = { - writable: true, - value: (()=>{ - Foo.foo = _classStaticPrivateFieldSpecGet(Foo, Foo, _bar); - Foo.qux1 = Foo.qux; - })() -}; +(()=>{ + Foo.foo = _classStaticPrivateFieldSpecGet(Foo, Foo, _bar); + Foo.qux1 = Foo.qux; +})(); _defineProperty(Foo, "qux", 21); -var __1 = { - writable: true, - value: (()=>{ - Foo.qux2 = Foo.qux; - })() -}; +(()=>{ + Foo.qux2 = Foo.qux; +})(); diff --git a/crates/swc_ecma_transforms_compat/tests/static-blocks/class-properties/name-conflict/output.js b/crates/swc_ecma_transforms_compat/tests/static-blocks/class-properties/name-conflict/output.js index 495c882c5909..c69025ea2b7e 100644 --- a/crates/swc_ecma_transforms_compat/tests/static-blocks/class-properties/name-conflict/output.js +++ b/crates/swc_ecma_transforms_compat/tests/static-blocks/class-properties/name-conflict/output.js @@ -4,9 +4,6 @@ var __ = { writable: true, value: 42 }; -var __1 = { - writable: true, - value: (()=>{ - Foo.foo = _classStaticPrivateFieldSpecGet(Foo, Foo, __); - })() -}; +(()=>{ + Foo.foo = _classStaticPrivateFieldSpecGet(Foo, Foo, __); +})(); diff --git a/crates/swc_ecma_transforms_compat/tests/static-blocks/class-properties/new-target/output.js b/crates/swc_ecma_transforms_compat/tests/static-blocks/class-properties/new-target/output.js index 50987ba7323a..f206cd2a8f25 100644 --- a/crates/swc_ecma_transforms_compat/tests/static-blocks/class-properties/new-target/output.js +++ b/crates/swc_ecma_transforms_compat/tests/static-blocks/class-properties/new-target/output.js @@ -1,12 +1,9 @@ class Base { constructor(){ - var _class, __; + var _class; this.Foo = (_class = class { - }, __ = { - writable: true, - value: (()=>{ - _class.foo = void 0; - })() - }, _class); + }, (()=>{ + _class.foo = void 0; + })(), _class); } } From 2ba95f3b722da8de10131c1610bbef2ff8633849 Mon Sep 17 00:00:00 2001 From: magic-akari Date: Sat, 11 Mar 2023 02:33:11 +0800 Subject: [PATCH 4/4] chore: update test cases --- .../tests/fixtures/transform/static-block/output.mjs | 10 +++------- .../tests/fixtures/transform/tp-version/output.mjs | 10 +++------- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/crates/swc_ecma_preset_env/tests/fixtures/transform/static-block/output.mjs b/crates/swc_ecma_preset_env/tests/fixtures/transform/static-block/output.mjs index 3c2e005635c8..af3f0938b6a8 100644 --- a/crates/swc_ecma_preset_env/tests/fixtures/transform/static-block/output.mjs +++ b/crates/swc_ecma_preset_env/tests/fixtures/transform/static-block/output.mjs @@ -1,9 +1,5 @@ -var __ = _classPrivateFieldLooseKey("__"); class A { } -Object.defineProperty(A, __, { - writable: true, - value: (()=>{ - A.abc = 123; - })() -}); +(()=>{ + A.abc = 123; +})(); diff --git a/crates/swc_ecma_preset_env/tests/fixtures/transform/tp-version/output.mjs b/crates/swc_ecma_preset_env/tests/fixtures/transform/tp-version/output.mjs index 3c2e005635c8..af3f0938b6a8 100644 --- a/crates/swc_ecma_preset_env/tests/fixtures/transform/tp-version/output.mjs +++ b/crates/swc_ecma_preset_env/tests/fixtures/transform/tp-version/output.mjs @@ -1,9 +1,5 @@ -var __ = _classPrivateFieldLooseKey("__"); class A { } -Object.defineProperty(A, __, { - writable: true, - value: (()=>{ - A.abc = 123; - })() -}); +(()=>{ + A.abc = 123; +})();