diff --git a/crates/swc/src/config/mod.rs b/crates/swc/src/config/mod.rs index 96bb7a2521aa..f79927fa0fbd 100644 --- a/crates/swc/src/config/mod.rs +++ b/crates/swc/src/config/mod.rs @@ -42,6 +42,7 @@ use swc_ecma_minifier::option::terser::TerserTopLevelOptions; #[allow(deprecated)] pub use swc_ecma_parser::JscTarget; use swc_ecma_parser::{parse_file_as_expr, Syntax, TsSyntax}; +pub use swc_ecma_transforms::proposals::DecoratorVersion; use swc_ecma_transforms::{ feature::FeatureFlag, hygiene, modules, @@ -676,6 +677,18 @@ impl Options { { Box::new(plugin_transforms) } else { + let decorator_pass: Box = + match transform.decorator_version.unwrap_or_default() { + DecoratorVersion::V202112 => Box::new(decorators(decorators::Config { + legacy: transform.legacy_decorator.into_bool(), + emit_metadata: transform.decorator_metadata.into_bool(), + use_define_for_class_fields: !assumptions.set_public_class_fields, + })), + DecoratorVersion::V202203 => Box::new( + swc_ecma_transforms::proposals::decorator_2022_03::decorator_2022_03(), + ), + }; + Box::new(chain!( lint_to_fold(swc_ecma_lints::rules::all(LintParams { program: &program, @@ -686,23 +699,7 @@ impl Options { source_map: cm.clone(), })), // Decorators may use type information - Optional::new( - match transform.decorator_version.unwrap_or_default() { - DecoratorVersion::V202112 => { - Either::Left(decorators(decorators::Config { - legacy: transform.legacy_decorator.into_bool(), - emit_metadata: transform.decorator_metadata.into_bool(), - use_define_for_class_fields: !assumptions.set_public_class_fields, - })) - } - DecoratorVersion::V202203 => { - Either::Right( - swc_ecma_transforms::proposals::decorator_2022_03::decorator_2022_03(), - ) - } - }, - syntax.decorators() - ), + Optional::new(decorator_pass, syntax.decorators()), Optional::new( explicit_resource_management(), syntax.explicit_resource_management() @@ -1446,17 +1443,6 @@ pub struct TransformConfig { pub decorator_version: Option, } -#[derive(Debug, Default, Clone, Copy, Serialize, Deserialize)] -#[serde(deny_unknown_fields, rename_all = "camelCase")] -pub enum DecoratorVersion { - #[default] - #[serde(rename = "2021-12")] - V202112, - - #[serde(rename = "2022-03")] - V202203, -} - #[derive(Debug, Default, Clone, Serialize, Deserialize, Merge)] #[serde(deny_unknown_fields, rename_all = "camelCase")] pub struct HiddenTransformConfig { diff --git a/crates/swc_ecma_transforms_proposal/src/decorator_2022_03.rs b/crates/swc_ecma_transforms_proposal/src/decorator_2022_03.rs index dcb185e35337..ed8644f1a3a4 100644 --- a/crates/swc_ecma_transforms_proposal/src/decorator_2022_03.rs +++ b/crates/swc_ecma_transforms_proposal/src/decorator_2022_03.rs @@ -13,11 +13,11 @@ use swc_ecma_utils::{ use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; pub fn decorator_2022_03() -> impl VisitMut + Fold { - as_folder(Decorator202203::default()) + as_folder(Decorator2022_03::default()) } #[derive(Default)] -struct Decorator202203 { +struct Decorator2022_03 { /// Variables without initializer. extra_vars: Vec, @@ -35,6 +35,8 @@ struct Decorator202203 { #[derive(Default)] struct ClassState { + private_id_index: u32, + static_lhs: Vec, proto_lhs: Vec, @@ -55,7 +57,7 @@ struct ClassState { super_class: Option, } -impl Decorator202203 { +impl Decorator2022_03 { fn preserve_side_effect_of_decorators( &mut self, decorators: Vec, @@ -463,6 +465,7 @@ impl Decorator202203 { let has_static_member = body.iter().any(|m| match m { ClassMember::Method(m) => m.is_static, ClassMember::PrivateMethod(m) => m.is_static, + ClassMember::AutoAccessor(m) => m.is_static, ClassMember::ClassProp(ClassProp { is_static, .. }) | ClassMember::PrivateProp(PrivateProp { is_static, .. }) => *is_static, ClassMember::StaticBlock(_) => true, @@ -527,7 +530,9 @@ impl Decorator202203 { for m in body.iter_mut() { match m { - ClassMember::ClassProp(..) | ClassMember::PrivateProp(..) => { + ClassMember::ClassProp(..) + | ClassMember::PrivateProp(..) + | ClassMember::AutoAccessor(..) => { replace_ident(m, c.ident.to_id(), &new_class_name); } @@ -568,6 +573,13 @@ impl Decorator202203 { p.is_static = false; } } + + ClassMember::AutoAccessor(p) => { + if p.is_static { + should_move = true; + p.is_static = false; + } + } _ => (), } @@ -753,7 +765,7 @@ impl Decorator202203 { } } -impl VisitMut for Decorator202203 { +impl VisitMut for Decorator2022_03 { noop_visit_mut_type!(); fn visit_mut_class(&mut self, n: &mut Class) { @@ -932,6 +944,8 @@ impl VisitMut for Decorator202203 { for mut m in members.take() { match m { ClassMember::AutoAccessor(mut accessor) => { + accessor.value.visit_mut_with(self); + let name; let init; let field_name_like: JsWord; @@ -947,9 +961,14 @@ impl VisitMut for Decorator202203 { init = private_ident!(format!("_init_{}", k.id.sym)); field_name_like = format!("__{}", k.id.sym).into(); + self.state.private_id_index += 1; PrivateName { span: k.span, - id: Ident::new(format!("__{}", k.id.sym).into(), k.id.span), + id: Ident::new( + format!("__{}_{}", k.id.sym, self.state.private_id_index) + .into(), + k.id.span, + ), } } Key::Public(k) => { @@ -958,10 +977,16 @@ impl VisitMut for Decorator202203 { .replacen("init", "private", 1) .into(); + self.state.private_id_index += 1; + PrivateName { span: init.span.with_ctxt(SyntaxContext::empty()), id: Ident::new( - field_name_like.clone(), + format!( + "{field_name_like}_{}", + self.state.private_id_index + ) + .into(), init.span.with_ctxt(SyntaxContext::empty()), ), } @@ -1310,7 +1335,9 @@ impl VisitMut for Decorator202203 { for mut m in new.take() { match m { - ClassMember::Method(..) | ClassMember::PrivateMethod(..) => {} + ClassMember::Method(..) + | ClassMember::PrivateMethod(..) + | ClassMember::AutoAccessor(..) => {} _ => { if !m.span().is_dummy() { diff --git a/crates/swc_ecma_transforms_proposal/src/lib.rs b/crates/swc_ecma_transforms_proposal/src/lib.rs index 13d35eab0720..6ac2408157cd 100644 --- a/crates/swc_ecma_transforms_proposal/src/lib.rs +++ b/crates/swc_ecma_transforms_proposal/src/lib.rs @@ -1,11 +1,24 @@ #![deny(clippy::all)] #![allow(clippy::vec_box)] +use serde::{Deserialize, Serialize}; + pub use self::{ decorators::decorators, export_default_from::export_default_from, import_assertions::import_assertions, }; +#[derive(Debug, Default, Clone, Copy, Serialize, Deserialize)] +#[serde(deny_unknown_fields, rename_all = "camelCase")] +pub enum DecoratorVersion { + #[default] + #[serde(rename = "2021-12")] + V202112, + + #[serde(rename = "2022-03")] + V202203, +} + pub mod decorator_2022_03; pub mod decorators; pub mod explicit_resource_management; diff --git a/crates/swc_ecma_transforms_proposal/tests/.gitignore b/crates/swc_ecma_transforms_proposal/tests/.gitignore deleted file mode 100644 index bad9e806c541..000000000000 --- a/crates/swc_ecma_transforms_proposal/tests/.gitignore +++ /dev/null @@ -1 +0,0 @@ -run-decorator-tests.js \ No newline at end of file diff --git a/crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Class-decorators-Binding-initialization-class-expression.js b/crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Class-decorators-Binding-initialization-class-expression.js new file mode 100644 index 000000000000..78b001f212f3 --- /dev/null +++ b/crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Class-decorators-Binding-initialization-class-expression.js @@ -0,0 +1,39 @@ +(() => { + let old; + let block; + class Bar { + } + const dec = (cls, ctx) => { + old = cls; + return Bar; + }; + const Foo = + @dec + class Foo { + static { block = Foo; } + method() { return Foo; } + static method() { return Foo; } + field = Foo; + static field = Foo; + get getter() { return Foo; } + static get getter() { return Foo; } + set setter(x) { x.foo = Foo; } + static set setter(x) { x.foo = Foo; } + accessor accessor = Foo; + static accessor accessor = Foo; + }; + const foo = new old; + let obj; + assertEq(() => Foo !== old, true); + assertEq(() => Foo, Bar); + assertEq(() => block, Bar); + assertEq(() => Foo.field, Bar); + assertEq(() => foo.field, Bar); + assertEq(() => old.getter, Bar); + assertEq(() => foo.getter, Bar); + assertEq(() => (obj = { foo: null }, old.setter = obj, obj.foo), Bar); + assertEq(() => (obj = { foo: null }, foo.setter = obj, obj.foo), Bar); + // The specification for accessors is potentially wrong at the moment: https://github.com/tc39/proposal-decorators/issues/529 + // assertEq(() => old.accessor, Bar) + // assertEq(() => foo.accessor, Bar) +})(); diff --git a/crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Class-decorators-Binding-initialization-class-statement.js b/crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Class-decorators-Binding-initialization-class-statement.js new file mode 100644 index 000000000000..5f026ff4ab0a --- /dev/null +++ b/crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Class-decorators-Binding-initialization-class-statement.js @@ -0,0 +1,38 @@ +(() => { + let old; + let block; + class Bar { + } + const dec = (cls, ctx) => { + old = cls; + return Bar; + }; + @dec + class Foo { + static { block = Foo; } + method() { return Foo; } + static method() { return Foo; } + field = Foo; + static field = Foo; + get getter() { return Foo; } + static get getter() { return Foo; } + set setter(x) { x.foo = Foo; } + static set setter(x) { x.foo = Foo; } + accessor accessor = Foo; + static accessor accessor = Foo; + } + const foo = new old; + let obj; + assertEq(() => Foo !== old, true); + assertEq(() => Foo, Bar); + assertEq(() => block, Bar); + assertEq(() => Foo.field, Bar); + assertEq(() => foo.field, Bar); + assertEq(() => old.getter, Bar); + assertEq(() => foo.getter, Bar); + assertEq(() => (obj = { foo: null }, old.setter = obj, obj.foo), Bar); + assertEq(() => (obj = { foo: null }, foo.setter = obj, obj.foo), Bar); + // The specification for accessors is potentially wrong at the moment: https://github.com/tc39/proposal-decorators/issues/529 + // assertEq(() => old.accessor, Bar) + // assertEq(() => foo.accessor, Bar) +})(); diff --git a/crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Decorator-metadata-class-expression.js b/crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Decorator-metadata-class-expression.js index 2ae6a13e71c7..1f3dd5a8dd2b 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Decorator-metadata-class-expression.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Decorator-metadata-class-expression.js @@ -65,4 +65,23 @@ assertEq(() => Object.getPrototypeOf(foo), null); assertEq(() => order(bar), '0,1,2,3,11,12,13,14,4,5,6,7,15,16,17,18,8,19,9,20,10,21'); assertEq(() => Object.getPrototypeOf(bar), foo); + // Test an undecorated class + const FooNoDec = class { + }; + const BarNoDec = class extends FooNoDec { + }; + assertEq(() => FooNoDec[Symbol.metadata], null); + assertEq(() => BarNoDec[Symbol.metadata], null); + // Test a class with no class decorator + const FooOneDec = class { + @dec + x; + }; + const BarOneDec = class extends FooOneDec { + @dec + y; + }; + assertEq(() => JSON.stringify(FooOneDec[Symbol.metadata]), JSON.stringify({ x: 22 })); + assertEq(() => JSON.stringify(BarOneDec[Symbol.metadata]), JSON.stringify({ y: 23 })); + assertEq(() => Object.getPrototypeOf(BarOneDec[Symbol.metadata]), FooOneDec[Symbol.metadata]); })(); diff --git a/crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Decorator-metadata-class-statement.js b/crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Decorator-metadata-class-statement.js index a22966c5cc9e..c4535408ff3b 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Decorator-metadata-class-statement.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Decorator-metadata-class-statement.js @@ -64,4 +64,23 @@ assertEq(() => Object.getPrototypeOf(foo), null); assertEq(() => order(bar), '0,1,2,3,11,12,13,14,4,5,6,7,15,16,17,18,8,19,9,20,10,21'); assertEq(() => Object.getPrototypeOf(bar), foo); + // Test an undecorated class + class FooNoDec { + } + class BarNoDec extends FooNoDec { + } + assertEq(() => FooNoDec[Symbol.metadata], null); + assertEq(() => BarNoDec[Symbol.metadata], null); + // Test a class with no class decorator + class FooOneDec { + @dec + x; + } + class BarOneDec extends FooOneDec { + @dec + y; + } + assertEq(() => JSON.stringify(FooOneDec[Symbol.metadata]), JSON.stringify({ x: 22 })); + assertEq(() => JSON.stringify(BarOneDec[Symbol.metadata]), JSON.stringify({ y: 23 })); + assertEq(() => Object.getPrototypeOf(BarOneDec[Symbol.metadata]), FooOneDec[Symbol.metadata]); })(); diff --git a/crates/swc_ecma_transforms_proposal/tests/decorator_esbuild.rs b/crates/swc_ecma_transforms_proposal/tests/decorator_esbuild.rs deleted file mode 100644 index 435e703cbdf3..000000000000 --- a/crates/swc_ecma_transforms_proposal/tests/decorator_esbuild.rs +++ /dev/null @@ -1,81 +0,0 @@ -use std::{fs, process::Command}; - -use swc_common::Mark; -use swc_ecma_ast::EsVersion; -use swc_ecma_codegen::to_code; -use swc_ecma_parser::parse_file_as_program; -use swc_ecma_transforms_base::{ - fixer::fixer, - helpers::{inject_helpers, Helpers, HELPERS}, - hygiene::hygiene, - resolver, -}; -use swc_ecma_transforms_proposal::decorator_2022_03::decorator_2022_03; -use swc_ecma_visit::VisitMutWith; -use testing::find_executable; - -#[test] -#[ignore = "TODO: Fix this test"] -fn execute() { - testing::run_test(false, |cm, handler| { - let node = find_executable("node").expect("node not found"); - - let fm = cm - .load_file("tests/decorator-tests/decorator-tests.js".as_ref()) - .expect("failed to load file"); - - let code = { - // Transpile with swc - let mut errors = vec![]; - - let program = parse_file_as_program( - &fm, - swc_ecma_parser::Syntax::Es(swc_ecma_parser::EsSyntax { - decorators: true, - auto_accessors: true, - ..Default::default() - }), - EsVersion::EsNext, - None, - &mut errors, - ); - - let mut program = match program { - Ok(v) => v, - Err(e) => { - e.into_diagnostic(handler).emit(); - return Err(()); - } - }; - - for e in errors { - e.into_diagnostic(handler).emit(); - } - HELPERS.set(&Helpers::new(false), || { - let unresolved_mark = Mark::new(); - let top_level_mark = Mark::new(); - program.visit_mut_with(&mut resolver(unresolved_mark, top_level_mark, false)); - - program.visit_mut_with(&mut decorator_2022_03()); - - program.visit_mut_with(&mut inject_helpers(unresolved_mark)); - program.visit_mut_with(&mut hygiene()); - program.visit_mut_with(&mut fixer(None)); - }); - - to_code(&program) - }; - - fs::write("tests/run-decorator-tests.js", code).expect("failed to write file"); - - let status = Command::new(node) - .arg("tests/run-decorator-tests.js") - .status() - .expect("failed to execute process"); - - assert!(status.success()); - - Ok(()) - }) - .unwrap() -} diff --git a/crates/swc_ecma_transforms_proposal/tests/decorator_evanw.rs b/crates/swc_ecma_transforms_proposal/tests/decorator_evanw.rs new file mode 100644 index 000000000000..d077a1c645f4 --- /dev/null +++ b/crates/swc_ecma_transforms_proposal/tests/decorator_evanw.rs @@ -0,0 +1,70 @@ +use std::{fs, path::PathBuf}; + +use swc_ecma_parser::{EsSyntax, Syntax}; +use swc_ecma_transforms_proposal::decorator_2022_03::decorator_2022_03; +use swc_ecma_transforms_testing::exec_tr; +use swc_ecma_visit::as_folder; + +const HELPERS: &str = r###" +function assertEq(callback, expected) { + let details; + try { + let x = callback(); + if (x === expected) + return true; + details = ` Expected: ${prettyPrint(expected)}\n Observed: ${prettyPrint(x)}`; + } + catch (error) { + details = ` Throws: ${error}`; + } + const code = callback.toString().replace(/^\(\) => /, '').replace(/\s+/g, ' '); + console.log(`❌\n Code: ${code}\n${details}\n`); + return false; +} +function assertThrows(callback, expected) { + let details; + try { + let x = callback(); + details = ` Expected: throws instanceof ${expected.name}\n Observed: returns ${prettyPrint(x)}`; + } + catch (error) { + if (error instanceof expected) + return true; + details = ` Expected: throws instanceof ${expected.name}\n Observed: throws ${error}`; + } + const code = callback.toString().replace(/^\(\) => /, '').replace(/\s+/g, ' '); + console.log(`❌\n Code: ${code}\n${details}\n`); + return false; +} +"###; + +// TODO: Unignore tests +#[testing::fixture( + "tests/decorator-evanw-split/*.js", + exclude( + "Decorator-list-evaluation-await-class-statement.js", + "Decorator-list-evaluation-Inner-private-name-class-statement.js", + "Decorator-list-evaluation-Inner-private-name-class-expression.js" + ) +)] +fn fixture(input: PathBuf) { + let code = fs::read_to_string(&input).unwrap(); + + let code = format!( + "{HELPERS} + + + {code}" + ); + + exec_tr( + &input.file_name().unwrap().to_string_lossy(), + Syntax::Es(EsSyntax { + decorators: true, + auto_accessors: true, + ..Default::default() + }), + |_| as_folder(decorator_2022_03()), + &code, + ); +} diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators.rs b/crates/swc_ecma_transforms_proposal/tests/decorators.rs index 1587eee8e30d..e29fa71c9d29 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators.rs +++ b/crates/swc_ecma_transforms_proposal/tests/decorators.rs @@ -9,7 +9,7 @@ use serde::Deserialize; use swc_common::{chain, comments::SingleThreadedComments, Mark}; use swc_ecma_parser::{EsSyntax, Syntax, TsSyntax}; use swc_ecma_transforms_base::{assumptions::Assumptions, resolver}; -use swc_ecma_transforms_proposal::decorator_2022_03::decorator_2022_03; +use swc_ecma_transforms_proposal::{decorator_2022_03::decorator_2022_03, DecoratorVersion}; use swc_ecma_transforms_testing::{test_fixture, FixtureTestConfig}; use swc_ecma_visit::Fold; @@ -82,7 +82,7 @@ fn fixture_inner(input: PathBuf) { } #[derive(Debug, Deserialize)] -#[serde(deny_unknown_fields, rename_all = "camelCase")] +#[serde(rename_all = "camelCase")] struct BabelTestOptions { #[serde(default)] assumptions: Assumptions, @@ -107,36 +107,17 @@ enum BabelPluginEntry { #[derive(Debug, Deserialize)] #[serde(deny_unknown_fields, untagged, rename_all = "camelCase")] enum BabelPluginOption { - Decorator { version: String }, -} - -fn read_options_json(input: &Path) -> BabelTestOptions { - let mut options_path = input.to_path_buf(); - options_path.set_file_name("options.json"); - - if options_path.exists() { - let s = std::fs::read_to_string(&options_path).unwrap(); - println!("Options: {}", s); - return serde_json::from_str(&s).expect("failed to read options.json"); - } - - println!("Reading options from {:?}", options_path); - - // Look for parent directory - - read_options_json(options_path.parent().unwrap()) + Decorator { version: DecoratorVersion }, } fn create_pass(comments: Rc, input: &Path) -> Box { - let options_json = read_options_json(input); + let options_json: BabelTestOptions = + swc_ecma_transforms_testing::parse_options(input.parent().unwrap()); let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - let mut pass: Box = Box::new(chain!( - resolver(unresolved_mark, top_level_mark, false), - decorator_2022_03() - )); + let mut pass: Box = Box::new(resolver(unresolved_mark, top_level_mark, false)); macro_rules! add { ($e:expr) => {{ @@ -178,7 +159,22 @@ fn create_pass(comments: Rc, input: &Path) -> Box {} }, - BabelPluginEntry::WithConfig(name, config) => {} + BabelPluginEntry::WithConfig(name, config) => match &**name { + "proposal-decorators" => match config { + BabelPluginOption::Decorator { version } => match version { + // DecoratorVersion::V202311 => { + // add!(decorator_2023_11()); + // } + DecoratorVersion::V202112 => todo!(), + DecoratorVersion::V202203 => { + add!(decorator_2022_03()); + } + }, + }, + _ => { + panic!("Unknown plugin: {}", name); + } + }, } dbg!(&plugin); 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 92b68d499106..5400bca18c94 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 @@ -1,6 +1,6 @@ var _init_a, _get___a, _set___a, _init_b, _get___b, _set___b, _initProto; const dec = ()=>{}; -var ___a = /*#__PURE__*/ new WeakMap(), _a = /*#__PURE__*/ new WeakMap(), ___b = /*#__PURE__*/ new WeakMap(), _b = /*#__PURE__*/ new WeakMap(); +var ___a_1 = /*#__PURE__*/ new WeakMap(), _a = /*#__PURE__*/ new WeakMap(), ___b_2 = /*#__PURE__*/ new WeakMap(), _b = /*#__PURE__*/ new WeakMap(); class Foo { constructor(){ _class_private_field_init(this, _a, { @@ -11,11 +11,11 @@ class Foo { get: get_b, set: set_b }); - _class_private_field_init(this, ___a, { + _class_private_field_init(this, ___a_1, { writable: true, value: (_initProto(this), _init_a(this)) }); - _class_private_field_init(this, ___b, { + _class_private_field_init(this, ___b_2, { writable: true, value: _init_b(this, 123) }); @@ -29,10 +29,10 @@ var __ = { 1, "a", function() { - return _class_private_field_get(this, ___a); + return _class_private_field_get(this, ___a_1); }, function(_v) { - _class_private_field_set(this, ___a, _v); + _class_private_field_set(this, ___a_1, _v); } ], [ @@ -40,10 +40,10 @@ var __ = { 1, "b", function() { - return _class_private_field_get(this, ___b); + return _class_private_field_get(this, ___b_2); }, function(_v) { - _class_private_field_set(this, ___b, _v); + _class_private_field_set(this, ___b_2, _v); } ] ], []) 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 30e5d2399703..cae042c86d56 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 @@ -1,37 +1,37 @@ var _init_a, _init_b, _computedKey, _init_computedKey, _initProto; const dec = ()=>{}; _computedKey = 'c'; -var ____private_a = /*#__PURE__*/ new WeakMap(), ____private_b = /*#__PURE__*/ new WeakMap(), ____private_computedKey = /*#__PURE__*/ new WeakMap(); +var ____private_a_1 = /*#__PURE__*/ new WeakMap(), ____private_b_2 = /*#__PURE__*/ new WeakMap(), ____private_computedKey_3 = /*#__PURE__*/ new WeakMap(); let _computedKey1 = _computedKey, _computedKey2 = _computedKey; class Foo { get a() { - return _class_private_field_get(this, ____private_a); + return _class_private_field_get(this, ____private_a_1); } set a(_v) { - _class_private_field_set(this, ____private_a, _v); + _class_private_field_set(this, ____private_a_1, _v); } get b() { - return _class_private_field_get(this, ____private_b); + return _class_private_field_get(this, ____private_b_2); } set b(_v) { - _class_private_field_set(this, ____private_b, _v); + _class_private_field_set(this, ____private_b_2, _v); } get [_computedKey1]() { - return _class_private_field_get(this, ____private_computedKey); + return _class_private_field_get(this, ____private_computedKey_3); } set [_computedKey2](_v) { - _class_private_field_set(this, ____private_computedKey, _v); + _class_private_field_set(this, ____private_computedKey_3, _v); } constructor(){ - _class_private_field_init(this, ____private_a, { + _class_private_field_init(this, ____private_a_1, { writable: true, value: (_initProto(this), _init_a(this)) }); - _class_private_field_init(this, ____private_b, { + _class_private_field_init(this, ____private_b_2, { writable: true, value: _init_b(this, 123) }); - _class_private_field_init(this, ____private_computedKey, { + _class_private_field_init(this, ____private_computedKey_3, { writable: true, value: _init_computedKey(this, 456) }); 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 2248ff18bc6c..8d0d70214860 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 @@ -13,16 +13,16 @@ var _b = { var __ = { writable: true, value: (()=>{ - ({ e: [_init_a, _get___a, _set___a, _init_b, _get___b, _set___b, _initStatic] } = _apply_decs_2203_r(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); + return _class_static_private_field_spec_get(this, Foo, ___a_1); }, function(_v) { - _class_static_private_field_spec_set(this, Foo, ___a, _v); + _class_static_private_field_spec_set(this, Foo, ___a_1, _v); } ], [ @@ -30,21 +30,21 @@ var __ = { 6, "b", function() { - return _class_static_private_field_spec_get(this, Foo, ___b); + return _class_static_private_field_spec_get(this, Foo, ___b_2); }, function(_v) { - _class_static_private_field_spec_set(this, Foo, ___b, _v); + _class_static_private_field_spec_set(this, Foo, ___b_2, _v); } ] ], [])); _initStatic(Foo); })() }; -var ___a = { +var ___a_1 = { writable: true, value: _init_a(Foo) }; -var ___b = { +var ___b_2 = { writable: true, value: _init_b(Foo, 123) }; 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 f8bbabd8e5f5..18c875213a6e 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 @@ -4,28 +4,28 @@ _computedKey = 'c'; let _computedKey1 = _computedKey, _computedKey2 = _computedKey; class Foo { static get a() { - return _class_static_private_field_spec_get(this, Foo, ____private_a); + return _class_static_private_field_spec_get(this, Foo, ____private_a_1); } static set a(_v) { - _class_static_private_field_spec_set(this, Foo, ____private_a, _v); + _class_static_private_field_spec_set(this, Foo, ____private_a_1, _v); } static get b() { - return _class_static_private_field_spec_get(this, Foo, ____private_b); + return _class_static_private_field_spec_get(this, Foo, ____private_b_2); } static set b(_v) { - _class_static_private_field_spec_set(this, Foo, ____private_b, _v); + _class_static_private_field_spec_set(this, Foo, ____private_b_2, _v); } static get [_computedKey1]() { - return _class_static_private_field_spec_get(this, Foo, ____private_computedKey); + return _class_static_private_field_spec_get(this, Foo, ____private_computedKey_3); } static set [_computedKey2](_v) { - _class_static_private_field_spec_set(this, Foo, ____private_computedKey, _v); + _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, [ + ({ e: [_init_a, _init_b, _init_computedKey, _initStatic] } = _apply_decs_2203_r(Foo, [ [ dec, 6, @@ -45,15 +45,15 @@ var __ = { _initStatic(Foo); })() }; -var ____private_a = { +var ____private_a_1 = { writable: true, value: _init_a(Foo) }; -var ____private_b = { +var ____private_b_2 = { writable: true, value: _init_b(Foo, 123) }; -var ____private_computedKey = { +var ____private_computedKey_3 = { writable: true, value: _init_computedKey(Foo, 456) }; diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-accessors--to-es2015/undecorated-private/output.js b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-accessors--to-es2015/undecorated-private/output.js index d930579ed222..b3f87147f7ad 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-accessors--to-es2015/undecorated-private/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-accessors--to-es2015/undecorated-private/output.js @@ -1,5 +1,5 @@ const dec = ()=>{}; -var ___a = /*#__PURE__*/ new WeakMap(), _a = /*#__PURE__*/ new WeakMap(), ___b = /*#__PURE__*/ new WeakMap(), _b = /*#__PURE__*/ new WeakMap(); +var ___a_1 = /*#__PURE__*/ new WeakMap(), _a = /*#__PURE__*/ new WeakMap(), ___b_2 = /*#__PURE__*/ new WeakMap(), _b = /*#__PURE__*/ new WeakMap(); class Foo { constructor(){ _class_private_field_init(this, _a, { @@ -10,25 +10,25 @@ class Foo { get: get_b, set: set_b }); - _class_private_field_init(this, ___a, { + _class_private_field_init(this, ___a_1, { writable: true, value: void 0 }); - _class_private_field_init(this, ___b, { + _class_private_field_init(this, ___b_2, { writable: true, value: 123 }); } } function get_a() { - return _class_private_field_get(this, ___a); + return _class_private_field_get(this, ___a_1); } function set_a(_v) { - _class_private_field_set(this, ___a, _v); + _class_private_field_set(this, ___a_1, _v); } function get_b() { - return _class_private_field_get(this, ___b); + return _class_private_field_get(this, ___b_2); } function set_b(_v) { - _class_private_field_set(this, ___b, _v); + _class_private_field_set(this, ___b_2, _v); } diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-accessors--to-es2015/undecorated-public/output.js b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-accessors--to-es2015/undecorated-public/output.js index a52f5519e241..48be83643e9d 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-accessors--to-es2015/undecorated-public/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-accessors--to-es2015/undecorated-public/output.js @@ -1,37 +1,37 @@ var _computedKey; const dec = ()=>{}; _computedKey = 'c'; -var ____private_a = /*#__PURE__*/ new WeakMap(), ____private_b = /*#__PURE__*/ new WeakMap(), ____private_computedKey = /*#__PURE__*/ new WeakMap(); +var ____private_a_1 = /*#__PURE__*/ new WeakMap(), ____private_b_2 = /*#__PURE__*/ new WeakMap(), ____private_computedKey_3 = /*#__PURE__*/ new WeakMap(); let _computedKey1 = _computedKey, _computedKey2 = _computedKey; class Foo { get a() { - return _class_private_field_get(this, ____private_a); + return _class_private_field_get(this, ____private_a_1); } set a(_v) { - _class_private_field_set(this, ____private_a, _v); + _class_private_field_set(this, ____private_a_1, _v); } get b() { - return _class_private_field_get(this, ____private_b); + return _class_private_field_get(this, ____private_b_2); } set b(_v) { - _class_private_field_set(this, ____private_b, _v); + _class_private_field_set(this, ____private_b_2, _v); } get [_computedKey1]() { - return _class_private_field_get(this, ____private_computedKey); + return _class_private_field_get(this, ____private_computedKey_3); } set [_computedKey2](_v) { - _class_private_field_set(this, ____private_computedKey, _v); + _class_private_field_set(this, ____private_computedKey_3, _v); } constructor(){ - _class_private_field_init(this, ____private_a, { + _class_private_field_init(this, ____private_a_1, { writable: true, value: void 0 }); - _class_private_field_init(this, ____private_b, { + _class_private_field_init(this, ____private_b_2, { writable: true, value: 123 }); - _class_private_field_init(this, ____private_computedKey, { + _class_private_field_init(this, ____private_computedKey_3, { writable: true, value: 456 }); diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-accessors--to-es2015/undecorated-static-private/output.js b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-accessors--to-es2015/undecorated-static-private/output.js index 1c968cb2f911..851879232d89 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-accessors--to-es2015/undecorated-static-private/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-accessors--to-es2015/undecorated-static-private/output.js @@ -9,23 +9,23 @@ var _b = { get: get_b, set: set_b }; -var ___a = { +var ___a_1 = { writable: true, value: void 0 }; -var ___b = { +var ___b_2 = { writable: true, value: 123 }; function get_a() { - return _class_static_private_field_spec_get(this, Foo, ___a); + return _class_static_private_field_spec_get(this, Foo, ___a_1); } function set_a(_v) { - _class_static_private_field_spec_set(this, Foo, ___a, _v); + _class_static_private_field_spec_set(this, Foo, ___a_1, _v); } function get_b() { - return _class_static_private_field_spec_get(this, Foo, ___b); + return _class_static_private_field_spec_get(this, Foo, ___b_2); } function set_b(_v) { - _class_static_private_field_spec_set(this, Foo, ___b, _v); + _class_static_private_field_spec_set(this, Foo, ___b_2, _v); } diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-accessors--to-es2015/undecorated-static-public/output.js b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-accessors--to-es2015/undecorated-static-public/output.js index 96e70357c166..20ae182b3e20 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-accessors--to-es2015/undecorated-static-public/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-accessors--to-es2015/undecorated-static-public/output.js @@ -4,33 +4,33 @@ _computedKey = 'c'; let _computedKey1 = _computedKey, _computedKey2 = _computedKey; class Foo { static get a() { - return _class_static_private_field_spec_get(this, Foo, ____private_a); + return _class_static_private_field_spec_get(this, Foo, ____private_a_1); } static set a(_v) { - _class_static_private_field_spec_set(this, Foo, ____private_a, _v); + _class_static_private_field_spec_set(this, Foo, ____private_a_1, _v); } static get b() { - return _class_static_private_field_spec_get(this, Foo, ____private_b); + return _class_static_private_field_spec_get(this, Foo, ____private_b_2); } static set b(_v) { - _class_static_private_field_spec_set(this, Foo, ____private_b, _v); + _class_static_private_field_spec_set(this, Foo, ____private_b_2, _v); } static get [_computedKey1]() { - return _class_static_private_field_spec_get(this, Foo, ____private_computedKey); + return _class_static_private_field_spec_get(this, Foo, ____private_computedKey_3); } static set [_computedKey2](_v) { - _class_static_private_field_spec_set(this, Foo, ____private_computedKey, _v); + _class_static_private_field_spec_set(this, Foo, ____private_computedKey_3, _v); } } -var ____private_a = { +var ____private_a_1 = { writable: true, value: void 0 }; -var ____private_b = { +var ____private_b_2 = { writable: true, value: 123 }; -var ____private_computedKey = { +var ____private_computedKey_3 = { writable: true, value: 456 }; diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-accessors/private/output.js b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-accessors/private/output.js index eb0d14d5cfba..83f084173968 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-accessors/private/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-accessors/private/output.js @@ -2,16 +2,16 @@ var _init_a, _get___a, _set___a, _init_b, _get___b, _set___b, _initProto; const dec = ()=>{}; class Foo { static{ - ({ e: [_init_a, _get___a, _set___a, _init_b, _get___b, _set___b, _initProto] } = _apply_decs_2203_r(this, [ + ({ e: [_init_a, _get___a, _set___a, _init_b, _get___b, _set___b, _initProto] } = _apply_decs_2203_r(this, [ [ dec, 1, "a", function() { - return this.#__a; + return this.#__a_1; }, function(_v) { - this.#__a = _v; + this.#__a_1 = _v; } ], [ @@ -19,22 +19,22 @@ class Foo { 1, "b", function() { - return this.#__b; + return this.#__b_2; }, function(_v) { - this.#__b = _v; + this.#__b_2 = _v; } ] ], [])); } - #__a = (_initProto(this), _init_a(this)); + #__a_1 = (_initProto(this), _init_a(this)); get #a() { return _get___a(this); } set #a(_v) { _set___a(this, _v); } - #__b = _init_b(this, 123); + #__b_2 = _init_b(this, 123); get #b() { return _get___b(this); } diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-accessors/public/output.js b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-accessors/public/output.js index ac0c23e2f39b..190af7b02435 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-accessors/public/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-accessors/public/output.js @@ -3,7 +3,7 @@ const dec = ()=>{}; _computedKey = 'c'; class Foo { static{ - ({ e: [_init_a, _init_b, _init_computedKey, _initProto] } = _apply_decs_2203_r(this, [ + ({ e: [_init_a, _init_b, _init_computedKey, _initProto] } = _apply_decs_2203_r(this, [ [ dec, 1, @@ -21,25 +21,25 @@ class Foo { ] ], [])); } - #___private_a = (_initProto(this), _init_a(this)); + #___private_a_1 = (_initProto(this), _init_a(this)); get a() { - return this.#___private_a; + return this.#___private_a_1; } set a(_v) { - this.#___private_a = _v; + this.#___private_a_1 = _v; } - #___private_b = _init_b(this, 123); + #___private_b_2 = _init_b(this, 123); get b() { - return this.#___private_b; + return this.#___private_b_2; } set b(_v) { - this.#___private_b = _v; + this.#___private_b_2 = _v; } - #___private_computedKey = _init_computedKey(this, 456); + #___private_computedKey_3 = _init_computedKey(this, 456); get [_computedKey]() { - return this.#___private_computedKey; + return this.#___private_computedKey_3; } set [_computedKey](_v) { - this.#___private_computedKey = _v; + this.#___private_computedKey_3 = _v; } } diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-accessors/static-private/output.js b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-accessors/static-private/output.js index 626c310536c7..539ca78fa5df 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-accessors/static-private/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-accessors/static-private/output.js @@ -2,16 +2,16 @@ var _init_a, _get___a, _set___a, _init_b, _get___b, _set___b, _initStatic; const dec = ()=>{}; class Foo { static{ - ({ e: [_init_a, _get___a, _set___a, _init_b, _get___b, _set___b, _initStatic] } = _apply_decs_2203_r(this, [ + ({ e: [_init_a, _get___a, _set___a, _init_b, _get___b, _set___b, _initStatic] } = _apply_decs_2203_r(this, [ [ dec, 6, "a", function() { - return this.#__a; + return this.#__a_1; }, function(_v) { - this.#__a = _v; + this.#__a_1 = _v; } ], [ @@ -19,23 +19,23 @@ class Foo { 6, "b", function() { - return this.#__b; + return this.#__b_2; }, function(_v) { - this.#__b = _v; + this.#__b_2 = _v; } ] ], [])); _initStatic(this); } - static #__a = _init_a(this); + static #__a_1 = _init_a(this); static get #a() { return _get___a(this); } static set #a(_v) { _set___a(this, _v); } - static #__b = _init_b(this, 123); + static #__b_2 = _init_b(this, 123); static get #b() { return _get___b(this); } diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-accessors/static-public/output.js b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-accessors/static-public/output.js index c354b2fb6c8f..9a86c0de98a4 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-accessors/static-public/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-accessors/static-public/output.js @@ -3,7 +3,7 @@ const dec = ()=>{}; _computedKey = 'c'; class Foo { static{ - ({ e: [_init_a, _init_b, _init_computedKey, _initStatic] } = _apply_decs_2203_r(this, [ + ({ e: [_init_a, _init_b, _init_computedKey, _initStatic] } = _apply_decs_2203_r(this, [ [ dec, 6, @@ -22,25 +22,25 @@ class Foo { ], [])); _initStatic(this); } - static #___private_a = _init_a(this); + static #___private_a_1 = _init_a(this); static get a() { - return this.#___private_a; + return this.#___private_a_1; } static set a(_v) { - this.#___private_a = _v; + this.#___private_a_1 = _v; } - static #___private_b = _init_b(this, 123); + static #___private_b_2 = _init_b(this, 123); static get b() { - return this.#___private_b; + return this.#___private_b_2; } static set b(_v) { - this.#___private_b = _v; + this.#___private_b_2 = _v; } - static #___private_computedKey = _init_computedKey(this, 456); + static #___private_computedKey_3 = _init_computedKey(this, 456); static get [_computedKey]() { - return this.#___private_computedKey; + return this.#___private_computedKey_3; } static set [_computedKey](_v) { - this.#___private_computedKey = _v; + this.#___private_computedKey_3 = _v; } } diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-accessors/undecorated-private/output.js b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-accessors/undecorated-private/output.js index c2587dddd548..2c8395a2a48f 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-accessors/undecorated-private/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-accessors/undecorated-private/output.js @@ -1,17 +1,17 @@ const dec = ()=>{}; class Foo { - #__a; + #__a_1; get #a() { - return this.#__a; + return this.#__a_1; } set #a(_v) { - this.#__a = _v; + this.#__a_1 = _v; } - #__b = 123; + #__b_2 = 123; get #b() { - return this.#__b; + return this.#__b_2; } set #b(_v) { - this.#__b = _v; + this.#__b_2 = _v; } } diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-accessors/undecorated-public/output.js b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-accessors/undecorated-public/output.js index f300fbf86fcc..36aa103b4504 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-accessors/undecorated-public/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-accessors/undecorated-public/output.js @@ -2,25 +2,25 @@ var _computedKey; const dec = ()=>{}; _computedKey = 'c'; class Foo { - #___private_a; + #___private_a_1; get a() { - return this.#___private_a; + return this.#___private_a_1; } set a(_v) { - this.#___private_a = _v; + this.#___private_a_1 = _v; } - #___private_b = 123; + #___private_b_2 = 123; get b() { - return this.#___private_b; + return this.#___private_b_2; } set b(_v) { - this.#___private_b = _v; + this.#___private_b_2 = _v; } - #___private_computedKey = 456; + #___private_computedKey_3 = 456; get [_computedKey]() { - return this.#___private_computedKey; + return this.#___private_computedKey_3; } set [_computedKey](_v) { - this.#___private_computedKey = _v; + this.#___private_computedKey_3 = _v; } } diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-accessors/undecorated-static-private/output.js b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-accessors/undecorated-static-private/output.js index 4f5c6332075f..22814517f561 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-accessors/undecorated-static-private/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-accessors/undecorated-static-private/output.js @@ -1,17 +1,17 @@ const dec = ()=>{}; class Foo { - static #__a; + static #__a_1; static get #a() { - return this.#__a; + return this.#__a_1; } static set #a(_v) { - this.#__a = _v; + this.#__a_1 = _v; } - static #__b = 123; + static #__b_2 = 123; static get #b() { - return this.#__b; + return this.#__b_2; } static set #b(_v) { - this.#__b = _v; + this.#__b_2 = _v; } } diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-accessors/undecorated-static-public/output.js b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-accessors/undecorated-static-public/output.js index 8fbd15f7f56a..d7c92f4eea05 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-accessors/undecorated-static-public/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-accessors/undecorated-static-public/output.js @@ -2,25 +2,25 @@ var _computedKey; const dec = ()=>{}; _computedKey = 'c'; class Foo { - static #___private_a; + static #___private_a_1; static get a() { - return this.#___private_a; + return this.#___private_a_1; } static set a(_v) { - this.#___private_a = _v; + this.#___private_a_1 = _v; } - static #___private_b = 123; + static #___private_b_2 = 123; static get b() { - return this.#___private_b; + return this.#___private_b_2; } static set b(_v) { - this.#___private_b = _v; + this.#___private_b_2 = _v; } - static #___private_computedKey = 456; + static #___private_computedKey_3 = 456; static get [_computedKey]() { - return this.#___private_computedKey; + return this.#___private_computedKey_3; } static set [_computedKey](_v) { - this.#___private_computedKey = _v; + this.#___private_computedKey_3 = _v; } } diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-misc/all-decorators/output.js b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-misc/all-decorators/output.js index 57616ec8cc7e..18826e02d768 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-misc/all-decorators/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-misc/all-decorators/output.js @@ -52,10 +52,10 @@ new class extends _identity { 6, "r", function() { - return this.#__r; + return this.#__r_4; }, function(_v) { - this.#__r = _v; + this.#__r_4 = _v; } ], [ @@ -117,10 +117,10 @@ new class extends _identity { 1, "h", function() { - return this.#__h; + return this.#__h_2; }, function(_v) { - this.#__h = _v; + this.#__h_2 = _v; } ], [ @@ -148,12 +148,12 @@ new class extends _identity { b() {} get c() {} set c(v) {} - #___private_d = (_initProto(this), _init_d(this)); + #___private_d_1 = (_initProto(this), _init_d(this)); get d() { - return this.#___private_d; + return this.#___private_d_1; } set d(_v) { - this.#___private_d = _v; + this.#___private_d_1 = _v; } #e = _init_e(this); get #f() { @@ -165,7 +165,7 @@ new class extends _identity { set #g(v) { return _call_g1(this, v); } - #__h = _init_h(this); + #__h_2 = _init_h(this); get #h() { return _get___h(this); } @@ -177,14 +177,14 @@ new class extends _identity { static get k() {} static set l(v) {} static get m() { - return this.#___private_m; + return this.#___private_m_3; } static set m(_v) { - this.#___private_m = _v; + this.#___private_m_3 = _v; } } } - #___private_m = _init_m(this); + #___private_m_3 = _init_m(this); #n = _init_n(this); get #o() { return _call_o; @@ -195,7 +195,7 @@ new class extends _identity { set #q(v) { return _call_q(this, v); } - #__r = _init_r(this); + #__r_4 = _init_r(this); get #r() { return _get___r(this); } diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-misc/private-keys-in-enclosing-class/output.js b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-misc/private-keys-in-enclosing-class/output.js index b26c4cb868b7..0c69c9c3bbf4 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-misc/private-keys-in-enclosing-class/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-misc/private-keys-in-enclosing-class/output.js @@ -2,12 +2,12 @@ const dec = ()=>{}; class A { #A = 1; static B = class B extends A { - #___private_a = 2; + #___private_a_1 = 2; get a() { - return this.#___private_a; + return this.#___private_a_1; } set a(_v) { - this.#___private_a = _v; + this.#___private_a_1 = _v; } getA() { return this.#A; diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-ordering/accessor-simple/1/output.js b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-ordering/accessor-simple/1/output.js index dcfe07775b89..ea145fb98cd3 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-ordering/accessor-simple/1/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-ordering/accessor-simple/1/output.js @@ -1,62 +1,66 @@ var _initClass, _init_b, _init_c, _get___c, _set___c, _call_d, _initProto, _initStatic; let _A; -class A { - static{ - ({ e: [_init_b, _init_c, _get___c, _set___c, _call_d, _initProto, _initStatic], c: [_A, _initClass] } = _apply_decs_2203_r(this, [ - [ - dec3, - 6, - "b" - ], - [ - dec4, - 6, - "c", - function() { - return this.#__c; - }, - function(_v) { - this.#__c = _v; - } - ], - [ - dec2, - 2, - "a" - ], - [ - dec5, - 2, - "d", - function() {} - ] - ], [ - dec1 - ])); - _initStatic(this); - } +new class extends _identity { constructor(){ - _initProto(this); + super(_A), _initClass(); } - a() {} - static #___private_b = _init_b(this); - static get b() { - return this.#___private_b; - } - static set b(_v) { - this.#___private_b = _v; + static{ + class A { + static{ + ({ e: [_init_b, _init_c, _get___c, _set___c, _call_d, _initProto, _initStatic], c: [_A, _initClass] } = _apply_decs_2203_r(this, [ + [ + dec3, + 6, + "b" + ], + [ + dec4, + 6, + "c", + function() { + return this.#__c_2; + }, + function(_v) { + this.#__c_2 = _v; + } + ], + [ + dec2, + 2, + "a" + ], + [ + dec5, + 2, + "d", + function() {} + ] + ], [ + dec1 + ])); + _initStatic(this); + } + constructor(){ + _initProto(this); + } + a() {} + static get b() { + return this.#___private_b_1; + } + static set b(_v) { + this.#___private_b_1 = _v; + } + get #d() { + return _call_d; + } + } } - static #__c = _init_c(this); - static get #c() { + #___private_b_1 = _init_b(this); + #__c_2 = _init_c(this); + get #c() { return _get___c(this); } - static set #c(_v) { + set #c(_v) { _set___c(this, _v); } - get #d() { - return _call_d; - } - static{ - _initClass(); - } -} +}(); diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-ordering/accessor-static-method-initializers/output.js b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-ordering/accessor-static-method-initializers/output.js index 08d17c981c55..82568d548199 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-ordering/accessor-static-method-initializers/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-ordering/accessor-static-method-initializers/output.js @@ -44,10 +44,10 @@ new class extends _identity { 1, "d", function() { - return this.#__d; + return this.#__d_2; }, function(_v) { - this.#__d = _v; + this.#__d_2 = _v; } ] ], [ @@ -56,15 +56,15 @@ new class extends _identity { ])); _initStatic(this); } - #___private_a = (_initProto(this), _init_a(this)); + #___private_a_1 = (_initProto(this), _init_a(this)); get a() { - return this.#___private_a; + return this.#___private_a_1; } set a(_v) { - this.#___private_a = _v; + this.#___private_a_1 = _v; } static b() {} - #__d = _init_d(this); + #__d_2 = _init_d(this); get #d() { return _get___d(this); } diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-ordering/initializers/output.js b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-ordering/initializers/output.js index 3def80d1fb4f..239618fc796d 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-ordering/initializers/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-ordering/initializers/output.js @@ -42,10 +42,10 @@ new class extends _identity { 6, "g", function() { - return this.#__g; + return this.#__g_3; }, function(_v) { - this.#__g = _v; + this.#__g_3 = _v; } ], [ @@ -81,10 +81,10 @@ new class extends _identity { 1, "h", function() { - return this.#__h; + return this.#__h_4; }, function(_v) { - this.#__h = _v; + this.#__h_4 = _v; } ] ], [ @@ -98,20 +98,20 @@ new class extends _identity { get #d() { return _call_d; } - #___private_e = (_initProto(this), _init_e(this)); + #___private_e_1 = (_initProto(this), _init_e(this)); get e() { - return this.#___private_e; + return this.#___private_e_1; } set e(_v) { - this.#___private_e = _v; + this.#___private_e_1 = _v; } static get f() { - return this.#___private_f; + return this.#___private_f_2; } static set f(_v) { - this.#___private_f = _v; + this.#___private_f_2 = _v; } - #__h = _init_h(this); + #__h_4 = _init_h(this); get #h() { return _get___h(this); } @@ -123,8 +123,8 @@ new class extends _identity { get #c() { return _call_c; } - #___private_f = _init_f(this); - #__g = _init_g(this); + #___private_f_2 = _init_f(this); + #__g_3 = _init_g(this); get #g() { return _get___g(this); }