From 45ef3eb2becc663e756a3da557df5a03fb40fd84 Mon Sep 17 00:00:00 2001 From: Boshen <1430279+Boshen@users.noreply.github.com> Date: Tue, 26 Nov 2024 06:10:35 +0000 Subject: [PATCH] chore(transformer): disable class properties transform from the target API (#7487) --- crates/oxc_transformer/src/options/mod.rs | 4 +++- crates/oxc_transformer/tests/integrations/es_target.rs | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/crates/oxc_transformer/src/options/mod.rs b/crates/oxc_transformer/src/options/mod.rs index 076fcdb4f441d..aa2963c035d49 100644 --- a/crates/oxc_transformer/src/options/mod.rs +++ b/crates/oxc_transformer/src/options/mod.rs @@ -122,7 +122,9 @@ impl From for TransformOptions { fn from(target: ESTarget) -> Self { let mut engine_targets = EngineTargets::default(); engine_targets.insert(Engine::Es, target.version()); - Self { env: EnvOptions::from(engine_targets), ..Self::default() } + let mut env = EnvOptions::from(engine_targets); + env.es2022.class_properties = None; + Self { env, ..Self::default() } } } diff --git a/crates/oxc_transformer/tests/integrations/es_target.rs b/crates/oxc_transformer/tests/integrations/es_target.rs index 29cf0d1aa5726..2463ed0ff4741 100644 --- a/crates/oxc_transformer/tests/integrations/es_target.rs +++ b/crates/oxc_transformer/tests/integrations/es_target.rs @@ -51,6 +51,13 @@ fn es_target() { } } +#[test] +fn no_class_properties() { + let code = "class Foo { #a; }"; + let options = TransformOptions::from(ESTarget::from_str("es2015").unwrap()); + assert_eq!(test(code, &options), Ok(codegen(code, SourceType::mjs()))); +} + #[test] fn target_list_pass() { // https://vite.dev/config/build-options.html#build-target