From 3dba9bbb98526804398a29b96eddba30379f6246 Mon Sep 17 00:00:00 2001 From: Boshen Date: Fri, 1 Nov 2024 14:54:37 +0800 Subject: [PATCH] refactor(transformer): deserialize `BabelOptions::compiler_assumptions` --- 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 4091a169965602..252d14b5a83a75 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 91074488303aa8..038d1c695c53bb 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(),