diff --git a/crates/oxc_transformer/src/compiler_assumptions.rs b/crates/oxc_transformer/src/compiler_assumptions.rs index f37995fa930cd4..4aaa9e99497f89 100644 --- a/crates/oxc_transformer/src/compiler_assumptions.rs +++ b/crates/oxc_transformer/src/compiler_assumptions.rs @@ -85,7 +85,6 @@ pub struct CompilerAssumptions { pub set_computed_properties: bool, #[serde(default)] - #[deprecated = "Not Implemented"] pub set_public_class_fields: bool, #[serde(default)] diff --git a/crates/oxc_transformer/src/es2022/class_properties.rs b/crates/oxc_transformer/src/es2022/class_properties.rs index 34dfdba3b282aa..5720ee0ef01ba6 100644 --- a/crates/oxc_transformer/src/es2022/class_properties.rs +++ b/crates/oxc_transformer/src/es2022/class_properties.rs @@ -69,7 +69,7 @@ use oxc_span::SPAN; use oxc_syntax::{node::NodeId, scope::ScopeFlags, symbol::SymbolFlags}; use oxc_traverse::{Ancestor, BoundIdentifier, Traverse, TraverseCtx}; -use crate::{common::helper_loader::Helper, TransformCtx}; +use crate::{common::helper_loader::Helper, CompilerAssumptions, TransformCtx}; #[derive(Debug, Default, Clone, Copy, Deserialize)] #[serde(default, rename_all = "camelCase")] @@ -79,13 +79,20 @@ pub struct ClassPropertiesOptions { } pub struct ClassProperties<'a, 'ctx> { - options: ClassPropertiesOptions, + set_public_class_fields: bool, ctx: &'ctx TransformCtx<'a>, } impl<'a, 'ctx> ClassProperties<'a, 'ctx> { - pub fn new(options: ClassPropertiesOptions, ctx: &'ctx TransformCtx<'a>) -> Self { - Self { options, ctx } + pub fn new( + options: ClassPropertiesOptions, + assumptions: &CompilerAssumptions, + ctx: &'ctx TransformCtx<'a>, + ) -> Self { + let set_public_class_fields = + options.set_public_class_fields || assumptions.set_public_class_fields; + + Self { set_public_class_fields, ctx } } } @@ -186,7 +193,7 @@ impl<'a, 'ctx> ClassProperties<'a, 'ctx> { }; // Convert to assignment or `_defineProperty` call, depending on `loose` option - let init_expr = if self.options.set_public_class_fields { + let init_expr = if self.set_public_class_fields { // `this.foo = value` let key = match &prop.key { PropertyKey::StaticIdentifier(ident) => ident.as_ref().clone(), diff --git a/crates/oxc_transformer/src/es2022/mod.rs b/crates/oxc_transformer/src/es2022/mod.rs index c0ad06a5fb0838..ea00f47afeee4e 100644 --- a/crates/oxc_transformer/src/es2022/mod.rs +++ b/crates/oxc_transformer/src/es2022/mod.rs @@ -1,7 +1,7 @@ use oxc_ast::ast::*; use oxc_traverse::{Traverse, TraverseCtx}; -use crate::TransformCtx; +use crate::{CompilerAssumptions, TransformCtx}; mod class_properties; mod class_static_block; @@ -21,13 +21,17 @@ pub struct ES2022<'a, 'ctx> { } impl<'a, 'ctx> ES2022<'a, 'ctx> { - pub fn new(options: ES2022Options, ctx: &'ctx TransformCtx<'a>) -> Self { + pub fn new( + options: ES2022Options, + assumptions: &CompilerAssumptions, + ctx: &'ctx TransformCtx<'a>, + ) -> Self { Self { options, class_static_block: ClassStaticBlock::new(), class_properties: options .class_properties - .map(|options| ClassProperties::new(options, ctx)), + .map(|options| ClassProperties::new(options, assumptions, ctx)), } } } diff --git a/crates/oxc_transformer/src/lib.rs b/crates/oxc_transformer/src/lib.rs index dd1141d0a474e2..ba90dafbdc0791 100644 --- a/crates/oxc_transformer/src/lib.rs +++ b/crates/oxc_transformer/src/lib.rs @@ -99,7 +99,7 @@ impl<'a> Transformer<'a> { .is_typescript() .then(|| TypeScript::new(&self.options.typescript, &self.ctx)), x1_jsx: Jsx::new(self.options.jsx, ast_builder, &self.ctx), - x2_es2022: ES2022::new(self.options.env.es2022, &self.ctx), + x2_es2022: ES2022::new(self.options.env.es2022, &self.options.assumptions, &self.ctx), x2_es2021: ES2021::new(self.options.env.es2021, &self.ctx), x2_es2020: ES2020::new(self.options.env.es2020, &self.ctx), x2_es2019: ES2019::new(self.options.env.es2019), diff --git a/tasks/transform_conformance/snapshots/babel.snap.md b/tasks/transform_conformance/snapshots/babel.snap.md index f3ca539a27a229..8664dec2cc606b 100644 --- a/tasks/transform_conformance/snapshots/babel.snap.md +++ b/tasks/transform_conformance/snapshots/babel.snap.md @@ -1,6 +1,6 @@ commit: d20b314c -Passed: 394/1321 +Passed: 398/1321 # All Passed: * babel-plugin-transform-class-static-block @@ -1427,7 +1427,7 @@ x Output mismatch x Output mismatch -# babel-plugin-transform-class-properties (17/243) +# babel-plugin-transform-class-properties (21/243) * assumption-constantSuper/complex-super-class/input.js x Output mismatch @@ -1449,21 +1449,12 @@ x Output mismatch * assumption-setPublicClassFields/constructor-collision/input.js x Output mismatch -* assumption-setPublicClassFields/derived/input.js -x Output mismatch - * assumption-setPublicClassFields/foobar/input.js x Output mismatch -* assumption-setPublicClassFields/instance/input.js -x Output mismatch - * assumption-setPublicClassFields/instance-computed/input.js x Output mismatch -* assumption-setPublicClassFields/instance-undefined/input.js -x Output mismatch - * assumption-setPublicClassFields/length-name-use-define/input.js x Output mismatch @@ -1503,9 +1494,6 @@ x Output mismatch * assumption-setPublicClassFields/static-undefined/input.js x Output mismatch -* assumption-setPublicClassFields/super-call/input.js -x Output mismatch - * assumption-setPublicClassFields/super-expression/input.js x Output mismatch