Skip to content

Commit

Permalink
refactor(transformer): deserialize BabelOptions::compiler_assumptions
Browse files Browse the repository at this point in the history
  • Loading branch information
Boshen committed Nov 1, 2024
1 parent f83a760 commit 3dba9bb
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 12 deletions.
6 changes: 3 additions & 3 deletions crates/oxc_transformer/src/options/babel/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -33,7 +33,7 @@ pub struct BabelOptions {
pub source_type: Option<String>,

#[serde(default)]
pub assumptions: Value,
pub assumptions: CompilerAssumptions,

// Test options
pub throws: Option<String>,
Expand Down
10 changes: 1 addition & 9 deletions crates/oxc_transformer/src/options/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<CompilerAssumptions>(options.assumptions.clone())
.map_err(|err| errors.push(Error::msg(err)))
.unwrap_or_default()
};

let typescript = options
.presets
.typescript
Expand Down Expand Up @@ -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(),
Expand Down

0 comments on commit 3dba9bb

Please sign in to comment.