Skip to content

Commit

Permalink
fix(transformer): add android, electron and samsung to `EngineT…
Browse files Browse the repository at this point in the history
…argets`
  • Loading branch information
Boshen committed Nov 5, 2024
1 parent 8340243 commit e627d50
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
9 changes: 3 additions & 6 deletions crates/oxc_transformer/src/options/babel/env/targets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,9 @@ impl TryFrom<BabelTargets> for EngineTargets {
if key == "safari" && v == "tp" {
continue;
}
// TODO: Some keys are not implemented yet.
// <https://babel.dev/docs/options#targets>:
// Supported environments: android, chrome, deno, edge, electron, firefox, ie, ios, node, opera, rhino, safari, samsung.
let Ok(target) = targets.get_version_mut(&key) else {
continue;
};
let target = targets.get_version_mut(&key).map_err(|()| {
oxc_diagnostics::Error::msg(format!("target {key} is not implemented yet."))
})?;
match Version::parse(&v) {
Ok(version) => {
target.replace(version);
Expand Down
15 changes: 15 additions & 0 deletions crates/oxc_transformer/src/options/engine_targets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ use super::{babel::BabelTargets, BrowserslistQuery};
#[derive(Debug, Default, Clone, Eq, PartialEq, Deserialize)]
#[serde(try_from = "BabelTargets")]
pub struct EngineTargets {
android: Option<Version>, // not in esbuild
chrome: Option<Version>,
deno: Option<Version>,
edge: Option<Version>,
electron: Option<Version>, // not in esbuild
firefox: Option<Version>,
hermes: Option<Version>,
ie: Option<Version>,
Expand All @@ -20,6 +22,7 @@ pub struct EngineTargets {
opera: Option<Version>,
rhino: Option<Version>,
safari: Option<Version>,
samsung: Option<Version>, // not in esbuild
}

impl EngineTargets {
Expand All @@ -36,6 +39,9 @@ impl EngineTargets {
}

pub fn should_enable(&self, targets: &EngineTargets) -> bool {
if let (Some(v1), Some(v2)) = (&self.android, &targets.android) {
return v1 < v2;
}
if let (Some(v1), Some(v2)) = (&self.chrome, &targets.chrome) {
return v1 < v2;
}
Expand All @@ -45,6 +51,9 @@ impl EngineTargets {
if let (Some(v1), Some(v2)) = (&self.edge, &targets.edge) {
return v1 < v2;
}
if let (Some(v1), Some(v2)) = (&self.electron, &targets.electron) {
return v1 < v2;
}
if let (Some(v1), Some(v2)) = (&self.firefox, &targets.firefox) {
return v1 < v2;
}
Expand All @@ -69,6 +78,9 @@ impl EngineTargets {
if let (Some(v1), Some(v2)) = (&self.safari, &targets.safari) {
return v1 < v2;
}
if let (Some(v1), Some(v2)) = (&self.samsung, &targets.samsung) {
return v1 < v2;
}
false
}

Expand All @@ -91,9 +103,11 @@ impl EngineTargets {

pub(crate) fn get_version_mut(&mut self, key: &str) -> Result<&mut Option<Version>, ()> {
match key {
"android" => Ok(&mut self.android),
"chrome" | "and_chr" => Ok(&mut self.chrome),
"deno" => Ok(&mut self.deno),
"edge" => Ok(&mut self.edge),
"electron" => Ok(&mut self.electron),
"firefox" | "and_ff" => Ok(&mut self.firefox),
"hermes" => Ok(&mut self.hermes),
"ie" | "ie_mob" => Ok(&mut self.ie),
Expand All @@ -102,6 +116,7 @@ impl EngineTargets {
"opera" | "op_mob" => Ok(&mut self.opera),
"rhino" => Ok(&mut self.rhino),
"safari" => Ok(&mut self.safari),
"samsung" => Ok(&mut self.samsung),
_ => Err(()),
}
}
Expand Down

0 comments on commit e627d50

Please sign in to comment.