From 6d92f36ef2dabc0f6ab03d265510d3eb4c585690 Mon Sep 17 00:00:00 2001 From: Boshen <1430279+Boshen@users.noreply.github.com> Date: Fri, 1 Nov 2024 07:41:01 +0000 Subject: [PATCH] refactor(transformer): deserialize `BabelOptions::compiler_assumptions` (#7048) --- crates/oxc_transformer/src/options/babel/mod.rs | 6 +++--- crates/oxc_transformer/src/options/mod.rs | 10 +--------- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/crates/oxc_transformer/src/options/babel/mod.rs b/crates/oxc_transformer/src/options/babel/mod.rs index 4091a16996560..252d14b5a83a7 100644 --- a/crates/oxc_transformer/src/options/babel/mod.rs +++ b/crates/oxc_transformer/src/options/babel/mod.rs @@ -5,10 +5,10 @@ mod presets; use std::path::{Path, PathBuf}; use serde::{de::DeserializeOwned, Deserialize}; -use serde_json::Value; -pub use env::{BabelEnvOptions, Targets}; +use crate::CompilerAssumptions; +pub use self::env::{BabelEnvOptions, Targets}; use self::{plugins::BabelPlugins, presets::BabelPresets}; /// Babel options @@ -33,7 +33,7 @@ pub struct BabelOptions { pub source_type: Option, #[serde(default)] - pub assumptions: Value, + pub assumptions: CompilerAssumptions, // Test options pub throws: Option, diff --git a/crates/oxc_transformer/src/options/mod.rs b/crates/oxc_transformer/src/options/mod.rs index 91074488303aa..038d1c695c53b 100644 --- a/crates/oxc_transformer/src/options/mod.rs +++ b/crates/oxc_transformer/src/options/mod.rs @@ -75,14 +75,6 @@ impl TryFrom<&BabelOptions> for TransformOptions { errors.extend(options.plugins.errors.iter().map(|err| Error::msg(err.clone()))); errors.extend(options.presets.errors.iter().map(|err| Error::msg(err.clone()))); - let assumptions = if options.assumptions.is_null() { - CompilerAssumptions::default() - } else { - serde_json::from_value::(options.assumptions.clone()) - .map_err(|err| errors.push(Error::msg(err))) - .unwrap_or_default() - }; - let typescript = options .presets .typescript @@ -131,7 +123,7 @@ impl TryFrom<&BabelOptions> for TransformOptions { Ok(Self { cwd: options.cwd.clone().unwrap_or_default(), - assumptions, + assumptions: options.assumptions, typescript, jsx, env: env.unwrap_or_default(),