From 6ad0735033b405c04e53c1e3c7ec56db4b8fcf93 Mon Sep 17 00:00:00 2001 From: magic-akari Date: Thu, 14 Nov 2024 11:42:10 +0800 Subject: [PATCH] refactor(es/compat): Use special span instead of passing `static_blocks_mark` (#9725) **Description:** Let's make an assumption in the code: the use of dummy span as a private class field name is generated by us, it is there simply because it is necessary to maintain the order of side effect execution, its name is not referenced elsewhere, so we can safely remove its name. This is a breaking change for Rust users. --- .changeset/smart-cherries-sleep.md | 6 + crates/swc/src/builder.rs | 1 - crates/swc_common/src/syntax_pos.rs | 20 ++++ .../src/class_properties/mod.rs | 18 +-- crates/swc_ecma_compat_es2022/src/lib.rs | 2 +- .../src/static_blocks.rs | 27 +---- crates/swc_ecma_preset_env/src/lib.rs | 9 +- .../tests/es2015_new_target.rs | 1 - .../tests/es2022_private_in_object.rs | 2 - .../tests/es2022_static_blocks.rs | 4 +- .../src/decorator_impl.rs | 2 +- .../tests/decorators.rs | 8 +- .../private/output.js | 51 ++++---- .../public/output.js | 37 +++--- .../static-private/output.js | 57 +++++---- .../static-public/output.js | 43 ++++--- .../output.js | 26 ++-- .../output.js | 26 ++-- .../expressions-static-blocks/output.js | 112 +++++------------- .../expressions/output.js | 112 +++++------------- .../inheritance/output.js | 28 ++--- .../initializers/output.js | 52 ++++---- .../replacement-with-expr/output.js | 14 +-- .../replacement/output.js | 24 ++-- .../computed-keys-same-ast/output.js | 27 ++--- .../computed-keys-same-value/output.js | 27 ++--- .../methods-with-same-key/output.js | 27 ++--- .../private/output.js | 51 ++++---- .../public/output.js | 37 +++--- .../static-private/output.js | 51 ++++---- .../static-public/output.js | 37 +++--- .../private/output.js | 23 ++-- .../public/output.js | 27 ++--- .../static-private/output.js | 29 ++--- .../static-public/output.js | 33 +++--- .../private/output.js | 39 +++--- .../public/output.js | 47 ++++---- .../static-private/output.js | 45 ++++--- .../static-public/output.js | 53 ++++----- .../private/output.js | 23 ++-- .../public/output.js | 27 ++--- .../static-private/output.js | 29 ++--- .../static-public/output.js | 33 +++--- .../output.js | 17 ++- .../valid-expression-formats/output.js | 63 +++++----- .../private/output.js | 23 ++-- .../public/output.js | 27 ++--- .../static-private/output.js | 29 ++--- .../static-public/output.js | 33 +++--- .../tests/strip.rs | 4 +- 50 files changed, 638 insertions(+), 905 deletions(-) create mode 100644 .changeset/smart-cherries-sleep.md diff --git a/.changeset/smart-cherries-sleep.md b/.changeset/smart-cherries-sleep.md new file mode 100644 index 000000000000..558d1e24a9bd --- /dev/null +++ b/.changeset/smart-cherries-sleep.md @@ -0,0 +1,6 @@ +--- +swc_common: patch +swc_ecma_compat_es2022: major +--- + +refactor(es/compat): Use dummy span instead of passing `static_blocks_mark` diff --git a/crates/swc/src/builder.rs b/crates/swc/src/builder.rs index 0b06b2961eaa..3fcf1ea05eec 100644 --- a/crates/swc/src/builder.rs +++ b/crates/swc/src/builder.rs @@ -215,7 +215,6 @@ impl<'a, 'b, P: Pass> PassBuilder<'a, 'b, P> { constant_super: assumptions.constant_super, set_public_fields: assumptions.set_public_class_fields, no_document_all: assumptions.no_document_all, - static_blocks_mark: Mark::new(), pure_getter: assumptions.pure_getters, }, }, diff --git a/crates/swc_common/src/syntax_pos.rs b/crates/swc_common/src/syntax_pos.rs index 4ab1870cb6d2..2799633663d9 100644 --- a/crates/swc_common/src/syntax_pos.rs +++ b/crates/swc_common/src/syntax_pos.rs @@ -85,11 +85,18 @@ pub const DUMMY_SP: Span = Span { hi: BytePos::DUMMY, }; +/// PURE span, will emit `/* #__PURE__ */` comment in codegen. pub const PURE_SP: Span = Span { lo: BytePos::PURE, hi: BytePos::PURE, }; +/// Used for some special cases. e.g. mark the generated AST. +pub const PLACEHOLDER_SP: Span = Span { + lo: BytePos::PLACEHOLDER, + hi: BytePos::PLACEHOLDER, +}; + pub struct Globals { hygiene_data: Mutex, #[allow(unused)] @@ -408,6 +415,11 @@ impl Span { self.lo.is_pure() } + #[inline] + pub fn is_placeholder(self) -> bool { + self.lo.is_placeholder() + } + /// Returns `true` if this is a dummy span with any hygienic context. #[inline] pub fn is_dummy_ignoring_cmt(self) -> bool { @@ -1032,6 +1044,10 @@ impl BytePos { /// Dummy position. This is reserved for synthesized spans. pub const DUMMY: Self = BytePos(0); const MIN_RESERVED: Self = BytePos(DUMMY_RESERVE); + /// Placeholders, commonly used where names are required, but the names are + /// not referenced elsewhere. + pub const PLACEHOLDER: Self = BytePos(u32::MAX - 2); + /// Reserved for PURE comments. e.g. `/* #__PURE__ */` pub const PURE: Self = BytePos(u32::MAX - 1); /// Synthesized, but should be stored in a source map. pub const SYNTHESIZED: Self = BytePos(u32::MAX); @@ -1050,6 +1066,10 @@ impl BytePos { self.0 == Self::PURE.0 } + pub const fn is_placeholder(self) -> bool { + self.0 == Self::PLACEHOLDER.0 + } + /// Returns `true`` if this is explicitly synthesized or has relevant input /// source so can have a comment. pub const fn can_have_comment(self) -> bool { diff --git a/crates/swc_ecma_compat_es2022/src/class_properties/mod.rs b/crates/swc_ecma_compat_es2022/src/class_properties/mod.rs index 04204fd3247a..256abdbe23f7 100644 --- a/crates/swc_ecma_compat_es2022/src/class_properties/mod.rs +++ b/crates/swc_ecma_compat_es2022/src/class_properties/mod.rs @@ -49,27 +49,13 @@ pub fn class_properties(config: Config, unresolved_mark: Mark) -> impl Pass { }) } -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Default, Clone, Copy)] pub struct Config { pub private_as_properties: bool, pub set_public_fields: bool, pub constant_super: bool, pub no_document_all: bool, pub pure_getter: bool, - 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, - pure_getter: false, - static_blocks_mark: Mark::new(), - } - } } struct ClassProperties { @@ -734,7 +720,7 @@ impl ClassProperties { let value = prop.value.unwrap_or_else(|| Expr::undefined(prop_span)); - if prop.is_static && prop.ctxt.has_mark(self.c.static_blocks_mark) { + if prop.is_static && prop.key.span.is_placeholder() { let init = MemberInit::StaticBlock(value); extra_inits.push(init); continue; diff --git a/crates/swc_ecma_compat_es2022/src/lib.rs b/crates/swc_ecma_compat_es2022/src/lib.rs index 6c8178140edc..a2d1f1291ab8 100644 --- a/crates/swc_ecma_compat_es2022/src/lib.rs +++ b/crates/swc_ecma_compat_es2022/src/lib.rs @@ -26,7 +26,7 @@ pub fn es2022(config: Config, unresolved_mark: Mark) -> impl Pass { unicode_regex: false, unicode_sets_regex: false, }), - static_blocks(config.class_properties.static_blocks_mark), + static_blocks(), class_properties(config.class_properties, unresolved_mark), private_in_object(), ) diff --git a/crates/swc_ecma_compat_es2022/src/static_blocks.rs b/crates/swc_ecma_compat_es2022/src/static_blocks.rs index f7c41dc3a94e..f0ddef1d472b 100644 --- a/crates/swc_ecma_compat_es2022/src/static_blocks.rs +++ b/crates/swc_ecma_compat_es2022/src/static_blocks.rs @@ -1,16 +1,14 @@ use swc_atoms::JsWord; -use swc_common::{collections::AHashSet, util::take::Take, Mark, SyntaxContext, DUMMY_SP}; +use swc_common::{collections::AHashSet, source_map::PLACEHOLDER_SP, util::take::Take}; use swc_ecma_ast::*; use swc_ecma_utils::ExprFactory; use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, VisitMut, VisitMutWith}; use swc_trace_macro::swc_trace; -struct ClassStaticBlock { - static_block_mark: Mark, -} +struct ClassStaticBlock; -pub fn static_blocks(static_block_mark: Mark) -> impl Pass { - visit_mut_pass(ClassStaticBlock { static_block_mark }) +pub fn static_blocks() -> impl Pass { + visit_mut_pass(ClassStaticBlock) } #[swc_trace] @@ -31,17 +29,11 @@ impl ClassStaticBlock { static_block.body.stmts = stmts; let expr = CallExpr { - span: DUMMY_SP, callee: ArrowExpr { - span: DUMMY_SP, - params: Vec::new(), - is_async: false, - is_generator: false, body: Box::new(BlockStmtOrExpr::BlockStmt(static_block.body)), ..Default::default() } .as_callee(), - args: Vec::new(), ..Default::default() } .into(); @@ -52,19 +44,12 @@ impl ClassStaticBlock { PrivateProp { span, is_static: true, - is_optional: false, - is_override: false, - readonly: false, - type_ann: None, - decorators: Vec::new(), - accessibility: None, key: PrivateName { - span: DUMMY_SP, + span: PLACEHOLDER_SP, name: private_id, }, value, - definite: false, - ctxt: SyntaxContext::empty().apply_mark(self.static_block_mark), + ..Default::default() } } } diff --git a/crates/swc_ecma_preset_env/src/lib.rs b/crates/swc_ecma_preset_env/src/lib.rs index 591efc200a1b..8db8e15570e2 100644 --- a/crates/swc_ecma_preset_env/src/lib.rs +++ b/crates/swc_ecma_preset_env/src/lib.rs @@ -133,12 +133,8 @@ where // ES2022 // static block needs to be placed before class property // because it transforms into private static property - let static_blocks_mark = Mark::new(); - let pass = add!( - pass, - ClassStaticBlock, - es2022::static_blocks(static_blocks_mark) - ); + + let pass = add!(pass, ClassStaticBlock, es2022::static_blocks()); let pass = add!( pass, ClassProperties, @@ -148,7 +144,6 @@ where set_public_fields: loose || assumptions.set_public_class_fields, constant_super: loose || assumptions.constant_super, no_document_all: loose || assumptions.no_document_all, - static_blocks_mark, pure_getter: loose || assumptions.pure_getters, }, unresolved_mark 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 c2d2ae4f235a..6c2b7181bdb7 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2015_new_target.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2015_new_target.rs @@ -46,7 +46,6 @@ fn get_passes(_: &Tester, plugins: &[PluginConfig]) -> Box { set_public_fields: loose, private_as_properties: loose, no_document_all: loose, - static_blocks_mark: Mark::new(), pure_getter: loose, }, unresolved_mark, 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 14e69c5afe86..078a884f5b0a 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 @@ -64,7 +64,6 @@ fn fixture(input: PathBuf) { no_document_all: loose, private_as_properties: loose, pure_getter: loose, - static_blocks_mark: Mark::new(), }, unresolved_mark, ), @@ -84,7 +83,6 @@ fn fixture(input: PathBuf) { no_document_all: loose, private_as_properties: loose, pure_getter: loose, - static_blocks_mark: Mark::new(), }, unresolved_mark, ), 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 749a0857a322..02f05e2d6643 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2022_static_blocks.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2022_static_blocks.rs @@ -22,13 +22,13 @@ fn fixture(input: PathBuf) { let pass: Box = if input.to_string_lossy().contains("class-properties") { Box::new(( resolver(unresolved_mark, top_level_mark, false), - static_blocks(config.static_blocks_mark), + static_blocks(), class_properties(config, unresolved_mark), )) } else { Box::new(( resolver(unresolved_mark, top_level_mark, false), - static_blocks(config.static_blocks_mark), + static_blocks(), )) }; pass diff --git a/crates/swc_ecma_transforms_proposal/src/decorator_impl.rs b/crates/swc_ecma_transforms_proposal/src/decorator_impl.rs index 0b76e405a7d9..970da4fd8142 100644 --- a/crates/swc_ecma_transforms_proposal/src/decorator_impl.rs +++ b/crates/swc_ecma_transforms_proposal/src/decorator_impl.rs @@ -278,7 +278,7 @@ impl DecoratorPass { } }, _ => { - let key_ident = private_ident!("_computedKey"); + let key_ident = private_ident!(name.span(), "_computedKey"); self.extra_vars.push(VarDeclarator { span: DUMMY_SP, name: key_ident.clone().into(), diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators.rs b/crates/swc_ecma_transforms_proposal/tests/decorators.rs index 3306680b1f33..2c0645e37664 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators.rs +++ b/crates/swc_ecma_transforms_proposal/tests/decorators.rs @@ -133,9 +133,7 @@ fn create_pass(comments: Rc, input: &Path) -> Box match &**name { "proposal-class-properties" => { - add!(swc_ecma_transforms_compat::es2022::static_blocks( - static_block_mark - )); + add!(swc_ecma_transforms_compat::es2022::static_blocks()); add!(swc_ecma_transforms_compat::es2022::class_properties( Default::default(), unresolved_mark @@ -152,9 +150,7 @@ fn create_pass(comments: Rc, input: &Path) -> Box { - add!(swc_ecma_transforms_compat::es2022::static_blocks( - static_block_mark - )); + add!(swc_ecma_transforms_compat::es2022::static_blocks()); continue; } _ => {} diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-accessors--to-es2015/private/output.js b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-accessors--to-es2015/private/output.js index 5400bca18c94..21a4d803d1e4 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-accessors--to-es2015/private/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-accessors--to-es2015/private/output.js @@ -21,33 +21,30 @@ class Foo { }); } } -var __ = { - writable: true, - value: { e: [_init_a, _get___a, _set___a, _init_b, _get___b, _set___b, _initProto] } = _apply_decs_2203_r(Foo, [ - [ - dec, - 1, - "a", - function() { - return _class_private_field_get(this, ___a_1); - }, - function(_v) { - _class_private_field_set(this, ___a_1, _v); - } - ], - [ - dec, - 1, - "b", - function() { - return _class_private_field_get(this, ___b_2); - }, - function(_v) { - _class_private_field_set(this, ___b_2, _v); - } - ] - ], []) -}; +({ e: [_init_a, _get___a, _set___a, _init_b, _get___b, _set___b, _initProto] } = _apply_decs_2203_r(Foo, [ + [ + dec, + 1, + "a", + function() { + return _class_private_field_get(this, ___a_1); + }, + function(_v) { + _class_private_field_set(this, ___a_1, _v); + } + ], + [ + dec, + 1, + "b", + function() { + return _class_private_field_get(this, ___b_2); + }, + function(_v) { + _class_private_field_set(this, ___b_2, _v); + } + ] +], [])); function get_a() { return _get___a(this); } diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-accessors--to-es2015/public/output.js b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-accessors--to-es2015/public/output.js index cae042c86d56..715a41222e22 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-accessors--to-es2015/public/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-accessors--to-es2015/public/output.js @@ -37,23 +37,20 @@ class Foo { }); } } -var __ = { - writable: true, - value: { e: [_init_a, _init_b, _init_computedKey, _initProto] } = _apply_decs_2203_r(Foo, [ - [ - dec, - 1, - "a" - ], - [ - dec, - 1, - "b" - ], - [ - dec, - 1, - _computedKey - ] - ], []) -}; +({ e: [_init_a, _init_b, _init_computedKey, _initProto] } = _apply_decs_2203_r(Foo, [ + [ + dec, + 1, + "a" + ], + [ + dec, + 1, + "b" + ], + [ + dec, + 1, + _computedKey + ] +], [])); diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-accessors--to-es2015/static-private/output.js b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-accessors--to-es2015/static-private/output.js index 8d0d70214860..c75fdb1cda5c 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-accessors--to-es2015/static-private/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-accessors--to-es2015/static-private/output.js @@ -10,36 +10,33 @@ var _b = { get: get_b, set: set_b }; -var __ = { - writable: true, - value: (()=>{ - ({ e: [_init_a, _get___a, _set___a, _init_b, _get___b, _set___b, _initStatic] } = _apply_decs_2203_r(Foo, [ - [ - dec, - 6, - "a", - function() { - return _class_static_private_field_spec_get(this, Foo, ___a_1); - }, - function(_v) { - _class_static_private_field_spec_set(this, Foo, ___a_1, _v); - } - ], - [ - dec, - 6, - "b", - function() { - return _class_static_private_field_spec_get(this, Foo, ___b_2); - }, - function(_v) { - _class_static_private_field_spec_set(this, Foo, ___b_2, _v); - } - ] - ], [])); - _initStatic(Foo); - })() -}; +(()=>{ + ({ e: [_init_a, _get___a, _set___a, _init_b, _get___b, _set___b, _initStatic] } = _apply_decs_2203_r(Foo, [ + [ + dec, + 6, + "a", + function() { + return _class_static_private_field_spec_get(this, Foo, ___a_1); + }, + function(_v) { + _class_static_private_field_spec_set(this, Foo, ___a_1, _v); + } + ], + [ + dec, + 6, + "b", + function() { + return _class_static_private_field_spec_get(this, Foo, ___b_2); + }, + function(_v) { + _class_static_private_field_spec_set(this, Foo, ___b_2, _v); + } + ] + ], [])); + _initStatic(Foo); +})(); var ___a_1 = { writable: true, value: _init_a(Foo) diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-accessors--to-es2015/static-public/output.js b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-accessors--to-es2015/static-public/output.js index 18c875213a6e..d18516ab1ffd 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-accessors--to-es2015/static-public/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-accessors--to-es2015/static-public/output.js @@ -22,29 +22,26 @@ class Foo { _class_static_private_field_spec_set(this, Foo, ____private_computedKey_3, _v); } } -var __ = { - writable: true, - value: (()=>{ - ({ e: [_init_a, _init_b, _init_computedKey, _initStatic] } = _apply_decs_2203_r(Foo, [ - [ - dec, - 6, - "a" - ], - [ - dec, - 6, - "b" - ], - [ - dec, - 6, - _computedKey - ] - ], [])); - _initStatic(Foo); - })() -}; +(()=>{ + ({ e: [_init_a, _init_b, _init_computedKey, _initStatic] } = _apply_decs_2203_r(Foo, [ + [ + dec, + 6, + "a" + ], + [ + dec, + 6, + "b" + ], + [ + dec, + 6, + _computedKey + ] + ], [])); + _initStatic(Foo); +})(); var ____private_a_1 = { writable: true, value: _init_a(Foo) diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-classes--to-es2015/decorator-access-modified-fields/output.js b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-classes--to-es2015/decorator-access-modified-fields/output.js index f39e6de81d9a..586daf414ebf 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-classes--to-es2015/decorator-access-modified-fields/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-classes--to-es2015/decorator-access-modified-fields/output.js @@ -11,19 +11,13 @@ class C { _define_property(this, "m", _init_m(this)); } } -var __ = { - writable: true, - value: { e: [_init_m], c: [_C, _initClass] } = _apply_decs_2203_r(C, [ - [ - memberDec, - 0, - "m" - ] - ], [ - classDec - ]) -}; -var __2 = { - writable: true, - value: _initClass() -}; +({ e: [_init_m], c: [_C, _initClass] } = _apply_decs_2203_r(C, [ + [ + memberDec, + 0, + "m" + ] +], [ + classDec +])); +_initClass(); diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-classes--to-es2015/decorator-access-modified-methods/output.js b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-classes--to-es2015/decorator-access-modified-methods/output.js index 78263f5160e2..65a0a763cf56 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-classes--to-es2015/decorator-access-modified-methods/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-classes--to-es2015/decorator-access-modified-methods/output.js @@ -12,19 +12,13 @@ class C { _initProto(this); } } -var __ = { - writable: true, - value: { e: [_initProto], c: [_C, _initClass] } = _apply_decs_2203_r(C, [ - [ - memberDec, - 2, - "m" - ] - ], [ - classDec - ]) -}; -var __2 = { - writable: true, - value: _initClass() -}; +({ e: [_initProto], c: [_C, _initClass] } = _apply_decs_2203_r(C, [ + [ + memberDec, + 2, + "m" + ] +], [ + classDec +])); +_initClass(); diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-classes--to-es2015/expressions-static-blocks/output.js b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-classes--to-es2015/expressions-static-blocks/output.js index 8a00e7f602c1..e4c767613c34 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-classes--to-es2015/expressions-static-blocks/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-classes--to-es2015/expressions-static-blocks/output.js @@ -1,99 +1,45 @@ -var _A, __, __2, _C, __1, __21, _class, __3, __22, _class1, __4, __23, _G, __5, __24, _class2, __6, __25, _class3, __7, __26, _K, __8, __27; +var _A, _C, _class, _class1, _G, _class2, _class3, _K; var _initClass, _A1, _initClass1, _C1, _initClass2, _class4, _initClass3, _class5, _initClass4, _G1, _initClass5, _class6, _initClass6, _class7, _I, _initClass7, _K1, _L; const dec = ()=>{}; const A = ((_A = class A { -}, __ = { - writable: true, - value: { c: [_A1, _initClass] } = _apply_decs_2203_r(_A, [], [ - dec - ]) -}, __2 = { - writable: true, - value: _initClass() -}, _A), _A1); +}, { c: [_A1, _initClass] } = _apply_decs_2203_r(_A, [], [ + dec +]), _initClass(), _A), _A1); const B = ((_C = class C { -}, __1 = { - writable: true, - value: { c: [_C1, _initClass1] } = _apply_decs_2203_r(_C, [], [ - dec - ]) -}, __21 = { - writable: true, - value: _initClass1() -}, _C), _C1); +}, { c: [_C1, _initClass1] } = _apply_decs_2203_r(_C, [], [ + dec +]), _initClass1(), _C), _C1); const D = ((_class = class { -}, __3 = { - writable: true, - value: { c: [_class4, _initClass2] } = _apply_decs_2203_r(_class, [], [ - dec - ]) -}, __22 = { - writable: true, - value: _initClass2() -}, _class), _class4); +}, { c: [_class4, _initClass2] } = _apply_decs_2203_r(_class, [], [ + dec +]), _initClass2(), _class), _class4); const E = (((_class1 = class { -}, __4 = { - writable: true, - value: { c: [_class5, _initClass3] } = _apply_decs_2203_r(_class1, [], [ - dec - ]) -}, __23 = { - writable: true, - value: _initClass3() -}, _class1), _class5), 123); +}, { c: [_class5, _initClass3] } = _apply_decs_2203_r(_class1, [], [ + dec +]), _initClass3(), _class1), _class5), 123); const F = [ ((_G = class G { - }, __5 = { - writable: true, - value: { c: [_G1, _initClass4] } = _apply_decs_2203_r(_G, [], [ - dec - ]) - }, __24 = { - writable: true, - value: _initClass4() - }, _G), _G1), + }, { c: [_G1, _initClass4] } = _apply_decs_2203_r(_G, [], [ + dec + ]), _initClass4(), _G), _G1), ((_class2 = class { - }, __6 = { - writable: true, - value: { c: [_class6, _initClass5] } = _apply_decs_2203_r(_class2, [], [ - dec - ]) - }, __25 = { - writable: true, - value: _initClass5() - }, _class2), _class6) + }, { c: [_class6, _initClass5] } = _apply_decs_2203_r(_class2, [], [ + dec + ]), _initClass5(), _class2), _class6) ]; const H = ((_class3 = class extends (_I = I) { -}, __7 = { - writable: true, - value: { c: [_class7, _initClass6] } = _apply_decs_2203_r(_class3, [], [ - dec - ], _I) -}, __26 = { - writable: true, - value: _initClass6() -}, _class3), _class7); +}, { c: [_class7, _initClass6] } = _apply_decs_2203_r(_class3, [], [ + dec +], _I), _initClass6(), _class3), _class7); const J = ((_K = class K extends (_L = L) { -}, __8 = { - writable: true, - value: { c: [_K1, _initClass7] } = _apply_decs_2203_r(_K, [], [ - dec - ], _L) -}, __27 = { - writable: true, - value: _initClass7() -}, _K), _K1); +}, { c: [_K1, _initClass7] } = _apply_decs_2203_r(_K, [], [ + dec +], _L), _initClass7(), _K), _K1); function classFactory() { - var _class, __, __2; + var _class; var _initClass, _class1; return _class = class { - }, __ = { - writable: true, - value: { c: [_class1, _initClass] } = _apply_decs_2203_r(_class, [], [ - dec - ]) - }, __2 = { - writable: true, - value: _initClass() - }, _class, _class1; + }, { c: [_class1, _initClass] } = _apply_decs_2203_r(_class, [], [ + dec + ]), _initClass(), _class, _class1; } diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-classes--to-es2015/expressions/output.js b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-classes--to-es2015/expressions/output.js index 8a00e7f602c1..e4c767613c34 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-classes--to-es2015/expressions/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-classes--to-es2015/expressions/output.js @@ -1,99 +1,45 @@ -var _A, __, __2, _C, __1, __21, _class, __3, __22, _class1, __4, __23, _G, __5, __24, _class2, __6, __25, _class3, __7, __26, _K, __8, __27; +var _A, _C, _class, _class1, _G, _class2, _class3, _K; var _initClass, _A1, _initClass1, _C1, _initClass2, _class4, _initClass3, _class5, _initClass4, _G1, _initClass5, _class6, _initClass6, _class7, _I, _initClass7, _K1, _L; const dec = ()=>{}; const A = ((_A = class A { -}, __ = { - writable: true, - value: { c: [_A1, _initClass] } = _apply_decs_2203_r(_A, [], [ - dec - ]) -}, __2 = { - writable: true, - value: _initClass() -}, _A), _A1); +}, { c: [_A1, _initClass] } = _apply_decs_2203_r(_A, [], [ + dec +]), _initClass(), _A), _A1); const B = ((_C = class C { -}, __1 = { - writable: true, - value: { c: [_C1, _initClass1] } = _apply_decs_2203_r(_C, [], [ - dec - ]) -}, __21 = { - writable: true, - value: _initClass1() -}, _C), _C1); +}, { c: [_C1, _initClass1] } = _apply_decs_2203_r(_C, [], [ + dec +]), _initClass1(), _C), _C1); const D = ((_class = class { -}, __3 = { - writable: true, - value: { c: [_class4, _initClass2] } = _apply_decs_2203_r(_class, [], [ - dec - ]) -}, __22 = { - writable: true, - value: _initClass2() -}, _class), _class4); +}, { c: [_class4, _initClass2] } = _apply_decs_2203_r(_class, [], [ + dec +]), _initClass2(), _class), _class4); const E = (((_class1 = class { -}, __4 = { - writable: true, - value: { c: [_class5, _initClass3] } = _apply_decs_2203_r(_class1, [], [ - dec - ]) -}, __23 = { - writable: true, - value: _initClass3() -}, _class1), _class5), 123); +}, { c: [_class5, _initClass3] } = _apply_decs_2203_r(_class1, [], [ + dec +]), _initClass3(), _class1), _class5), 123); const F = [ ((_G = class G { - }, __5 = { - writable: true, - value: { c: [_G1, _initClass4] } = _apply_decs_2203_r(_G, [], [ - dec - ]) - }, __24 = { - writable: true, - value: _initClass4() - }, _G), _G1), + }, { c: [_G1, _initClass4] } = _apply_decs_2203_r(_G, [], [ + dec + ]), _initClass4(), _G), _G1), ((_class2 = class { - }, __6 = { - writable: true, - value: { c: [_class6, _initClass5] } = _apply_decs_2203_r(_class2, [], [ - dec - ]) - }, __25 = { - writable: true, - value: _initClass5() - }, _class2), _class6) + }, { c: [_class6, _initClass5] } = _apply_decs_2203_r(_class2, [], [ + dec + ]), _initClass5(), _class2), _class6) ]; const H = ((_class3 = class extends (_I = I) { -}, __7 = { - writable: true, - value: { c: [_class7, _initClass6] } = _apply_decs_2203_r(_class3, [], [ - dec - ], _I) -}, __26 = { - writable: true, - value: _initClass6() -}, _class3), _class7); +}, { c: [_class7, _initClass6] } = _apply_decs_2203_r(_class3, [], [ + dec +], _I), _initClass6(), _class3), _class7); const J = ((_K = class K extends (_L = L) { -}, __8 = { - writable: true, - value: { c: [_K1, _initClass7] } = _apply_decs_2203_r(_K, [], [ - dec - ], _L) -}, __27 = { - writable: true, - value: _initClass7() -}, _K), _K1); +}, { c: [_K1, _initClass7] } = _apply_decs_2203_r(_K, [], [ + dec +], _L), _initClass7(), _K), _K1); function classFactory() { - var _class, __, __2; + var _class; var _initClass, _class1; return _class = class { - }, __ = { - writable: true, - value: { c: [_class1, _initClass] } = _apply_decs_2203_r(_class, [], [ - dec - ]) - }, __2 = { - writable: true, - value: _initClass() - }, _class, _class1; + }, { c: [_class1, _initClass] } = _apply_decs_2203_r(_class, [], [ + dec + ]), _initClass(), _class, _class1; } diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-classes--to-es2015/inheritance/output.js b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-classes--to-es2015/inheritance/output.js index b06a05668302..88fffde6c675 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-classes--to-es2015/inheritance/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-classes--to-es2015/inheritance/output.js @@ -4,26 +4,14 @@ const dec2 = ()=>{}; let _Bar1; class Bar { } -var __ = { - writable: true, - value: { c: [_Bar1, _initClass] } = _apply_decs_2203_r(Bar, [], [ - dec1 - ]) -}; -var __2 = { - writable: true, - value: _initClass() -}; +({ c: [_Bar1, _initClass] } = _apply_decs_2203_r(Bar, [], [ + dec1 +])); +_initClass(); let _Foo; class Foo extends (_Bar = _Bar1) { } -var __1 = { - writable: true, - value: { c: [_Foo, _initClass1] } = _apply_decs_2203_r(Foo, [], [ - dec2 - ], _Bar) -}; -var __21 = { - writable: true, - value: _initClass1() -}; +({ c: [_Foo, _initClass1] } = _apply_decs_2203_r(Foo, [], [ + dec2 +], _Bar)); +_initClass1(); diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-classes--to-es2015/initializers/output.js b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-classes--to-es2015/initializers/output.js index d543f75ae6a6..9a68040fa982 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-classes--to-es2015/initializers/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-classes--to-es2015/initializers/output.js @@ -1,4 +1,4 @@ -var _class, __, _class1, __1; +var _class, _class1; var _initClass, _initClass1, _Foo; const dec = ()=>{}; let _Foo1; @@ -6,39 +6,27 @@ new (_class = class extends _identity { constructor(){ super(_Foo1), _initClass(); } -}, __ = { - writable: true, - value: (()=>{ - class Foo { - } - var __ = { - writable: true, - value: { c: [_Foo1, _initClass] } = _apply_decs_2203_r(Foo, [], [ - dec - ]) - }; - _define_property(Foo, "field", 123); - })() -}, _class)(); +}, (()=>{ + class Foo { + } + ({ c: [_Foo1, _initClass] } = _apply_decs_2203_r(Foo, [], [ + dec + ])); + _define_property(Foo, "field", 123); +})(), _class)(); let _Bar; new (_class1 = class extends _identity { constructor(){ super(_Bar), _initClass1(); } -}, __1 = { - writable: true, - value: (()=>{ - var _ref; - class Bar extends (_ref = _Foo = _Foo1) { - } - var __ = { - writable: true, - value: { c: [_Bar, _initClass1] } = _apply_decs_2203_r(Bar, [], [ - dec - ], _Foo) - }; - _define_property(Bar, "field", ((()=>{ - Bar.otherField = 456; - })(), 123)); - })() -}, _class1)(); +}, (()=>{ + var _ref; + class Bar extends (_ref = _Foo = _Foo1) { + } + ({ c: [_Bar, _initClass1] } = _apply_decs_2203_r(Bar, [], [ + dec + ], _Foo)); + _define_property(Bar, "field", ((()=>{ + Bar.otherField = 456; + })(), 123)); +})(), _class1)(); diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-classes--to-es2015/replacement-with-expr/output.js b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-classes--to-es2015/replacement-with-expr/output.js index 5245175e5e04..48e8721628fe 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-classes--to-es2015/replacement-with-expr/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-classes--to-es2015/replacement-with-expr/output.js @@ -1,17 +1,11 @@ -var _Bar, __, __2; +var _Bar; var _initClass, _Bar1; const dec = ()=>{}; const Foo = ((_Bar = class Bar { constructor(){ _define_property(this, "bar", new _Bar1()); } -}, __ = { - writable: true, - value: { c: [_Bar1, _initClass] } = _apply_decs_2203_r(_Bar, [], [ - dec - ]) -}, __2 = { - writable: true, - value: _initClass() -}, _Bar), _Bar1); +}, { c: [_Bar1, _initClass] } = _apply_decs_2203_r(_Bar, [], [ + dec +]), _initClass(), _Bar), _Bar1); const foo = new Foo(); diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-classes--to-es2015/replacement/output.js b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-classes--to-es2015/replacement/output.js index e4b8c4baf64b..9664a4b041e1 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-classes--to-es2015/replacement/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-classes--to-es2015/replacement/output.js @@ -1,4 +1,4 @@ -var _class, __; +var _class; var _initClass; const dec = ()=>{}; let _Foo; @@ -6,18 +6,12 @@ new (_class = class extends _identity { constructor(){ super(_Foo), _initClass(); } -}, __ = { - writable: true, - value: (()=>{ - class Foo { - } - var __ = { - writable: true, - value: { c: [_Foo, _initClass] } = _apply_decs_2203_r(Foo, [], [ - dec - ]) - }; - _define_property(Foo, "foo", new _Foo()); - })() -}, _class)(); +}, (()=>{ + class Foo { + } + ({ c: [_Foo, _initClass] } = _apply_decs_2203_r(Foo, [], [ + dec + ])); + _define_property(Foo, "foo", new _Foo()); +})(), _class)(); const foo = new _Foo(); diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-duplicated-keys--to-es2015/computed-keys-same-ast/output.js b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-duplicated-keys--to-es2015/computed-keys-same-ast/output.js index 98d3ec933114..933db1d53079 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-duplicated-keys--to-es2015/computed-keys-same-ast/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-duplicated-keys--to-es2015/computed-keys-same-ast/output.js @@ -13,18 +13,15 @@ class Foo { _initProto(this); } } -var __ = { - writable: true, - value: { e: [_initProto] } = _apply_decs_2203_r(Foo, [ - [ - dec, - 2, - _computedKey - ], - [ - dec, - 2, - _computedKey1 - ] - ], []) -}; +({ e: [_initProto] } = _apply_decs_2203_r(Foo, [ + [ + dec, + 2, + _computedKey + ], + [ + dec, + 2, + _computedKey1 + ] +], [])); diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-duplicated-keys--to-es2015/computed-keys-same-value/output.js b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-duplicated-keys--to-es2015/computed-keys-same-value/output.js index 0d2f43612077..dccc598fd150 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-duplicated-keys--to-es2015/computed-keys-same-value/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-duplicated-keys--to-es2015/computed-keys-same-value/output.js @@ -13,18 +13,15 @@ class Foo { _initProto(this); } } -var __ = { - writable: true, - value: { e: [_initProto] } = _apply_decs_2203_r(Foo, [ - [ - dec, - 2, - _computedKey - ], - [ - dec, - 2, - _computedKey1 - ] - ], []) -}; +({ e: [_initProto] } = _apply_decs_2203_r(Foo, [ + [ + dec, + 2, + _computedKey + ], + [ + dec, + 2, + _computedKey1 + ] +], [])); diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-duplicated-keys--to-es2015/methods-with-same-key/output.js b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-duplicated-keys--to-es2015/methods-with-same-key/output.js index 5ed1082288fa..00f9a88ebbc2 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-duplicated-keys--to-es2015/methods-with-same-key/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-duplicated-keys--to-es2015/methods-with-same-key/output.js @@ -11,18 +11,15 @@ class Foo { _initProto(this); } } -var __ = { - writable: true, - value: { e: [_initProto] } = _apply_decs_2203_r(Foo, [ - [ - dec, - 2, - "a" - ], - [ - dec, - 2, - "a" - ] - ], []) -}; +({ e: [_initProto] } = _apply_decs_2203_r(Foo, [ + [ + dec, + 2, + "a" + ], + [ + dec, + 2, + "a" + ] +], [])); diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-fields--to-es2015/private/output.js b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-fields--to-es2015/private/output.js index b0ccaba05582..2f6115b272b6 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-fields--to-es2015/private/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-fields--to-es2015/private/output.js @@ -13,30 +13,27 @@ class Foo { }); } } -var __ = { - writable: true, - value: { e: [_init_a, _init_b] } = _apply_decs_2203_r(Foo, [ - [ - dec, - 0, - "a", - function() { - return _class_private_field_get(this, _a); - }, - function(value) { - _class_private_field_set(this, _a, value); - } - ], - [ - dec, - 0, - "b", - function() { - return _class_private_field_get(this, _b); - }, - function(value) { - _class_private_field_set(this, _b, value); - } - ] - ], []) -}; +({ e: [_init_a, _init_b] } = _apply_decs_2203_r(Foo, [ + [ + dec, + 0, + "a", + function() { + return _class_private_field_get(this, _a); + }, + function(value) { + _class_private_field_set(this, _a, value); + } + ], + [ + dec, + 0, + "b", + function() { + return _class_private_field_get(this, _b); + }, + function(value) { + _class_private_field_set(this, _b, value); + } + ] +], [])); diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-fields--to-es2015/public/output.js b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-fields--to-es2015/public/output.js index 582703b34fdd..5d97dc59b971 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-fields--to-es2015/public/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-fields--to-es2015/public/output.js @@ -9,23 +9,20 @@ class Foo { _define_property(this, _computedKey1, _init__computedKey(this, 456)); } } -var __ = { - writable: true, - value: { e: [_init_a, _init_b, _init__computedKey] } = _apply_decs_2203_r(Foo, [ - [ - dec, - 0, - "a" - ], - [ - dec, - 0, - "b" - ], - [ - dec, - 0, - _computedKey - ] - ], []) -}; +({ e: [_init_a, _init_b, _init__computedKey] } = _apply_decs_2203_r(Foo, [ + [ + dec, + 0, + "a" + ], + [ + dec, + 0, + "b" + ], + [ + dec, + 0, + _computedKey + ] +], [])); diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-fields--to-es2015/static-private/output.js b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-fields--to-es2015/static-private/output.js index 907f853c71b5..325a7b990a13 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-fields--to-es2015/static-private/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-fields--to-es2015/static-private/output.js @@ -2,33 +2,30 @@ var _init_a, _init_b; const dec = ()=>{}; class Foo { } -var __ = { - writable: true, - value: { e: [_init_a, _init_b] } = _apply_decs_2203_r(Foo, [ - [ - dec, - 5, - "a", - function() { - return _class_static_private_field_spec_get(this, Foo, _a); - }, - function(value) { - _class_static_private_field_spec_set(this, Foo, _a, value); - } - ], - [ - dec, - 5, - "b", - function() { - return _class_static_private_field_spec_get(this, Foo, _b); - }, - function(value) { - _class_static_private_field_spec_set(this, Foo, _b, value); - } - ] - ], []) -}; +({ e: [_init_a, _init_b] } = _apply_decs_2203_r(Foo, [ + [ + dec, + 5, + "a", + function() { + return _class_static_private_field_spec_get(this, Foo, _a); + }, + function(value) { + _class_static_private_field_spec_set(this, Foo, _a, value); + } + ], + [ + dec, + 5, + "b", + function() { + return _class_static_private_field_spec_get(this, Foo, _b); + }, + function(value) { + _class_static_private_field_spec_set(this, Foo, _b, value); + } + ] +], [])); var _a = { writable: true, value: _init_a(Foo) diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-fields--to-es2015/static-public/output.js b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-fields--to-es2015/static-public/output.js index 6feaf3802ffa..7642e44c3821 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-fields--to-es2015/static-public/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-fields--to-es2015/static-public/output.js @@ -3,26 +3,23 @@ const dec = ()=>{}; _computedKey = 'c'; class Foo { } -var __ = { - writable: true, - value: { e: [_init_a, _init_b, _init__computedKey] } = _apply_decs_2203_r(Foo, [ - [ - dec, - 5, - "a" - ], - [ - dec, - 5, - "b" - ], - [ - dec, - 5, - _computedKey - ] - ], []) -}; +({ e: [_init_a, _init_b, _init__computedKey] } = _apply_decs_2203_r(Foo, [ + [ + dec, + 5, + "a" + ], + [ + dec, + 5, + "b" + ], + [ + dec, + 5, + _computedKey + ] +], [])); _define_property(Foo, "a", _init_a(Foo)); _define_property(Foo, "b", _init_b(Foo, 123)); _define_property(Foo, _computedKey, _init__computedKey(Foo, 456)); diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-getters--to-es2015/private/output.js b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-getters--to-es2015/private/output.js index 484aff8f6bc9..676763b985bb 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-getters--to-es2015/private/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-getters--to-es2015/private/output.js @@ -14,19 +14,16 @@ class Foo { _initProto(this); } } -var __ = { - writable: true, - value: { e: [_call_a, _initProto] } = _apply_decs_2203_r(Foo, [ - [ - dec, - 3, - "a", - function() { - return this.value; - } - ] - ], []) -}; +({ e: [_call_a, _initProto] } = _apply_decs_2203_r(Foo, [ + [ + dec, + 3, + "a", + function() { + return this.value; + } + ] +], [])); function get_a() { return _call_a(this); } diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-getters--to-es2015/public/output.js b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-getters--to-es2015/public/output.js index 0e97270edfef..2e5140f683ef 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-getters--to-es2015/public/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-getters--to-es2015/public/output.js @@ -14,18 +14,15 @@ class Foo { _initProto(this); } } -var __ = { - writable: true, - value: { e: [_initProto] } = _apply_decs_2203_r(Foo, [ - [ - dec, - 3, - "a" - ], - [ - dec, - 3, - _computedKey - ] - ], []) -}; +({ e: [_initProto] } = _apply_decs_2203_r(Foo, [ + [ + dec, + 3, + "a" + ], + [ + dec, + 3, + _computedKey + ] +], [])); diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-getters--to-es2015/static-private/output.js b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-getters--to-es2015/static-private/output.js index b18a6fe112e7..5a5d8ceaa9b0 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-getters--to-es2015/static-private/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-getters--to-es2015/static-private/output.js @@ -9,22 +9,19 @@ var _a = { get: get_a, set: void 0 }; -var __ = { - writable: true, - value: (()=>{ - ({ e: [_call_a, _initStatic] } = _apply_decs_2203_r(Foo, [ - [ - dec, - 8, - "a", - function() { - return this.value; - } - ] - ], [])); - _initStatic(Foo); - })() -}; +(()=>{ + ({ e: [_call_a, _initStatic] } = _apply_decs_2203_r(Foo, [ + [ + dec, + 8, + "a", + function() { + return this.value; + } + ] + ], [])); + _initStatic(Foo); +})(); _define_property(Foo, "value", 1); function get_a() { return _call_a(this); diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-getters--to-es2015/static-public/output.js b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-getters--to-es2015/static-public/output.js index fe21cc91b4bb..3881d53e153c 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-getters--to-es2015/static-public/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-getters--to-es2015/static-public/output.js @@ -10,22 +10,19 @@ class Foo { return this.value; } } -var __ = { - writable: true, - value: (()=>{ - ({ e: [_initStatic] } = _apply_decs_2203_r(Foo, [ - [ - dec, - 8, - "a" - ], - [ - dec, - 8, - _computedKey - ] - ], [])); - _initStatic(Foo); - })() -}; +(()=>{ + ({ e: [_initStatic] } = _apply_decs_2203_r(Foo, [ + [ + dec, + 8, + "a" + ], + [ + dec, + 8, + _computedKey + ] + ], [])); + _initStatic(Foo); +})(); _define_property(Foo, "value", 1); diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-getters-and-setters--to-es2015/private/output.js b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-getters-and-setters--to-es2015/private/output.js index 8b26cda988a1..a4058bb38f0d 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-getters-and-setters--to-es2015/private/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-getters-and-setters--to-es2015/private/output.js @@ -17,27 +17,24 @@ class Foo { _initProto(this); } } -var __ = { - writable: true, - value: { e: [_call_a, _call_a1, _initProto] } = _apply_decs_2203_r(Foo, [ - [ - dec, - 3, - "a", - function() { - return this.value; - } - ], - [ - dec, - 4, - "a", - function(v) { - this.value = v; - } - ] - ], []) -}; +({ e: [_call_a, _call_a1, _initProto] } = _apply_decs_2203_r(Foo, [ + [ + dec, + 3, + "a", + function() { + return this.value; + } + ], + [ + dec, + 4, + "a", + function(v) { + this.value = v; + } + ] +], [])); function get_a() { return _call_a(this); } diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-getters-and-setters--to-es2015/public/output.js b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-getters-and-setters--to-es2015/public/output.js index 083d5e6cba97..6087418acd63 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-getters-and-setters--to-es2015/public/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-getters-and-setters--to-es2015/public/output.js @@ -20,28 +20,25 @@ class Foo { _initProto(this); } } -var __ = { - writable: true, - value: { e: [_initProto] } = _apply_decs_2203_r(Foo, [ - [ - dec, - 3, - "a" - ], - [ - dec, - 4, - "a" - ], - [ - dec, - 3, - _computedKey - ], - [ - dec, - 4, - _computedKey1 - ] - ], []) -}; +({ e: [_initProto] } = _apply_decs_2203_r(Foo, [ + [ + dec, + 3, + "a" + ], + [ + dec, + 4, + "a" + ], + [ + dec, + 3, + _computedKey + ], + [ + dec, + 4, + _computedKey1 + ] +], [])); diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-getters-and-setters--to-es2015/static-private/output.js b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-getters-and-setters--to-es2015/static-private/output.js index 0a897a586687..d8e9eb9200a7 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-getters-and-setters--to-es2015/static-private/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-getters-and-setters--to-es2015/static-private/output.js @@ -12,30 +12,27 @@ var _a = { get: get_a, set: set_a }; -var __ = { - writable: true, - value: (()=>{ - ({ e: [_call_a, _call_a1, _initStatic] } = _apply_decs_2203_r(Foo, [ - [ - dec, - 8, - "a", - function() { - return this.value; - } - ], - [ - dec, - 9, - "a", - function(v) { - this.value = v; - } - ] - ], [])); - _initStatic(Foo); - })() -}; +(()=>{ + ({ e: [_call_a, _call_a1, _initStatic] } = _apply_decs_2203_r(Foo, [ + [ + dec, + 8, + "a", + function() { + return this.value; + } + ], + [ + dec, + 9, + "a", + function(v) { + this.value = v; + } + ] + ], [])); + _initStatic(Foo); +})(); _define_property(Foo, "value", 1); function get_a() { return _call_a(this); diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-getters-and-setters--to-es2015/static-public/output.js b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-getters-and-setters--to-es2015/static-public/output.js index 457ddfd8d042..c6db811db8ab 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-getters-and-setters--to-es2015/static-public/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-getters-and-setters--to-es2015/static-public/output.js @@ -16,32 +16,29 @@ class Foo { this.value = v; } } -var __ = { - writable: true, - value: (()=>{ - ({ e: [_initStatic] } = _apply_decs_2203_r(Foo, [ - [ - dec, - 8, - "a" - ], - [ - dec, - 9, - "a" - ], - [ - dec, - 8, - _computedKey - ], - [ - dec, - 9, - _computedKey1 - ] - ], [])); - _initStatic(Foo); - })() -}; +(()=>{ + ({ e: [_initStatic] } = _apply_decs_2203_r(Foo, [ + [ + dec, + 8, + "a" + ], + [ + dec, + 9, + "a" + ], + [ + dec, + 8, + _computedKey + ], + [ + dec, + 9, + _computedKey1 + ] + ], [])); + _initStatic(Foo); +})(); _define_property(Foo, "value", 1); diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-methods--to-es2015/private/output.js b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-methods--to-es2015/private/output.js index 5a9f0b820615..8015fce99f82 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-methods--to-es2015/private/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-methods--to-es2015/private/output.js @@ -14,19 +14,16 @@ class Foo { _initProto(this); } } -var __ = { - writable: true, - value: { e: [_call_a, _initProto] } = _apply_decs_2203_r(Foo, [ - [ - dec, - 2, - "a", - function() { - return this.value; - } - ] - ], []) -}; +({ e: [_call_a, _initProto] } = _apply_decs_2203_r(Foo, [ + [ + dec, + 2, + "a", + function() { + return this.value; + } + ] +], [])); function get_a() { return _call_a; } diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-methods--to-es2015/public/output.js b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-methods--to-es2015/public/output.js index 4c6fee78cf83..ae9b5f0f3373 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-methods--to-es2015/public/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-methods--to-es2015/public/output.js @@ -14,18 +14,15 @@ class Foo { _initProto(this); } } -var __ = { - writable: true, - value: { e: [_initProto] } = _apply_decs_2203_r(Foo, [ - [ - dec, - 2, - "a" - ], - [ - dec, - 2, - _computedKey - ] - ], []) -}; +({ e: [_initProto] } = _apply_decs_2203_r(Foo, [ + [ + dec, + 2, + "a" + ], + [ + dec, + 2, + _computedKey + ] +], [])); diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-methods--to-es2015/static-private/output.js b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-methods--to-es2015/static-private/output.js index 191906b4e117..b3f3afe7936d 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-methods--to-es2015/static-private/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-methods--to-es2015/static-private/output.js @@ -9,22 +9,19 @@ var _a = { get: get_a, set: void 0 }; -var __ = { - writable: true, - value: (()=>{ - ({ e: [_call_a, _initStatic] } = _apply_decs_2203_r(Foo, [ - [ - dec, - 7, - "a", - function() { - return this.value; - } - ] - ], [])); - _initStatic(Foo); - })() -}; +(()=>{ + ({ e: [_call_a, _initStatic] } = _apply_decs_2203_r(Foo, [ + [ + dec, + 7, + "a", + function() { + return this.value; + } + ] + ], [])); + _initStatic(Foo); +})(); _define_property(Foo, "value", 1); function get_a() { return _call_a; diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-methods--to-es2015/static-public/output.js b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-methods--to-es2015/static-public/output.js index edcef531b101..c841d334222f 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-methods--to-es2015/static-public/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-methods--to-es2015/static-public/output.js @@ -10,22 +10,19 @@ class Foo { return this.value; } } -var __ = { - writable: true, - value: (()=>{ - ({ e: [_initStatic] } = _apply_decs_2203_r(Foo, [ - [ - dec, - 7, - "a" - ], - [ - dec, - 7, - _computedKey - ] - ], [])); - _initStatic(Foo); - })() -}; +(()=>{ + ({ e: [_initStatic] } = _apply_decs_2203_r(Foo, [ + [ + dec, + 7, + "a" + ], + [ + dec, + 7, + _computedKey + ] + ], [])); + _initStatic(Foo); +})(); _define_property(Foo, "value", 1); diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-misc--to-es2015/initProto-existing-derived-constructor/output.js b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-misc--to-es2015/initProto-existing-derived-constructor/output.js index 866e6af60f91..ecc80e1cb79e 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-misc--to-es2015/initProto-existing-derived-constructor/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-misc--to-es2015/initProto-existing-derived-constructor/output.js @@ -8,13 +8,10 @@ class A extends B { foo(); } } -var __ = { - writable: true, - value: { e: [_initProto] } = _apply_decs_2203_r(A, [ - [ - deco, - 2, - "method" - ] - ], []) -}; +({ e: [_initProto] } = _apply_decs_2203_r(A, [ + [ + deco, + 2, + "method" + ] +], [])); diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-misc--to-es2015/valid-expression-formats/output.js b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-misc--to-es2015/valid-expression-formats/output.js index c34e4ffa10db..6be25b3af1d7 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-misc--to-es2015/valid-expression-formats/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-misc--to-es2015/valid-expression-formats/output.js @@ -6,23 +6,20 @@ var _a = /*#__PURE__*/ new WeakMap(); class Foo { method() {} makeClass() { - var _Nested, __; + var _Nested; var _dec, _init_bar; _dec = _class_private_field_get(this, _a); return _Nested = class Nested { constructor(){ _define_property(this, "bar", _init_bar(this)); } - }, __ = { - writable: true, - value: { e: [_init_bar] } = _apply_decs_2203_r(_Nested, [ - [ - _dec, - 0, - "bar" - ] - ], []) - }, _Nested; + }, { e: [_init_bar] } = _apply_decs_2203_r(_Nested, [ + [ + _dec, + 0, + "bar" + ] + ], []), _Nested; } constructor(){ _class_private_field_init(this, _a, { @@ -32,29 +29,23 @@ class Foo { _initProto(this); } } -var __ = { - writable: true, - value: { e: [_initProto], c: [_Foo, _initClass] } = _apply_decs_2203_r(Foo, [ +({ e: [_initProto], c: [_Foo, _initClass] } = _apply_decs_2203_r(Foo, [ + [ [ - [ - dec, - _dec4, - _dec5, - _dec6, - _dec7 - ], - 2, - "method" - ] - ], [ - dec, - _dec, - _dec1, - _dec2, - _dec3 - ]) -}; -var __2 = { - writable: true, - value: _initClass() -}; + dec, + _dec4, + _dec5, + _dec6, + _dec7 + ], + 2, + "method" + ] +], [ + dec, + _dec, + _dec1, + _dec2, + _dec3 +])); +_initClass(); diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-setters--to-es2015/private/output.js b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-setters--to-es2015/private/output.js index 0bda2edeb58a..5a8ca1bb289f 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-setters--to-es2015/private/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-setters--to-es2015/private/output.js @@ -14,19 +14,16 @@ class Foo { _initProto(this); } } -var __ = { - writable: true, - value: { e: [_call_a, _initProto] } = _apply_decs_2203_r(Foo, [ - [ - dec, - 4, - "a", - function(v) { - return this.value = v; - } - ] - ], []) -}; +({ e: [_call_a, _initProto] } = _apply_decs_2203_r(Foo, [ + [ + dec, + 4, + "a", + function(v) { + return this.value = v; + } + ] +], [])); function set_a(v) { return _call_a(this, v); } diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-setters--to-es2015/public/output.js b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-setters--to-es2015/public/output.js index 8187fa59f4d8..c5fdd8e6788c 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-setters--to-es2015/public/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-setters--to-es2015/public/output.js @@ -14,18 +14,15 @@ class Foo { _initProto(this); } } -var __ = { - writable: true, - value: { e: [_initProto] } = _apply_decs_2203_r(Foo, [ - [ - dec, - 4, - "a" - ], - [ - dec, - 4, - _computedKey - ] - ], []) -}; +({ e: [_initProto] } = _apply_decs_2203_r(Foo, [ + [ + dec, + 4, + "a" + ], + [ + dec, + 4, + _computedKey + ] +], [])); diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-setters--to-es2015/static-private/output.js b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-setters--to-es2015/static-private/output.js index 63c4c03229eb..5bf26a4cc761 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-setters--to-es2015/static-private/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-setters--to-es2015/static-private/output.js @@ -9,22 +9,19 @@ var _a = { get: void 0, set: set_a }; -var __ = { - writable: true, - value: (()=>{ - ({ e: [_call_a, _initStatic] } = _apply_decs_2203_r(Foo, [ - [ - dec, - 9, - "a", - function(v) { - return this.value = v; - } - ] - ], [])); - _initStatic(Foo); - })() -}; +(()=>{ + ({ e: [_call_a, _initStatic] } = _apply_decs_2203_r(Foo, [ + [ + dec, + 9, + "a", + function(v) { + return this.value = v; + } + ] + ], [])); + _initStatic(Foo); +})(); _define_property(Foo, "value", 1); function set_a(v) { return _call_a(this, v); diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-setters--to-es2015/static-public/output.js b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-setters--to-es2015/static-public/output.js index 1733d6c35fa9..dd3200caf41c 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-setters--to-es2015/static-public/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-setters--to-es2015/static-public/output.js @@ -10,22 +10,19 @@ class Foo { return this.value = v; } } -var __ = { - writable: true, - value: (()=>{ - ({ e: [_initStatic] } = _apply_decs_2203_r(Foo, [ - [ - dec, - 9, - "a" - ], - [ - dec, - 9, - _computedKey - ] - ], [])); - _initStatic(Foo); - })() -}; +(()=>{ + ({ e: [_initStatic] } = _apply_decs_2203_r(Foo, [ + [ + dec, + 9, + "a" + ], + [ + dec, + 9, + _computedKey + ] + ], [])); + _initStatic(Foo); +})(); _define_property(Foo, "value", 1); diff --git a/crates/swc_ecma_transforms_typescript/tests/strip.rs b/crates/swc_ecma_transforms_typescript/tests/strip.rs index 1fbb2d598825..73845810526a 100644 --- a/crates/swc_ecma_transforms_typescript/tests/strip.rs +++ b/crates/swc_ecma_transforms_typescript/tests/strip.rs @@ -83,16 +83,14 @@ fn tsxr(t: &Tester) -> impl Pass { } fn properties(_: &Tester, loose: bool) -> impl Pass { - let static_blocks_mark = Mark::new(); let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); ( resolver(unresolved_mark, top_level_mark, false), - static_blocks(static_blocks_mark), + static_blocks(), class_properties( class_properties::Config { - static_blocks_mark, set_public_fields: loose, ..Default::default() },