diff --git a/crates/oxc_transformer/src/options/babel/env/targets.rs b/crates/oxc_transformer/src/options/babel/env/targets.rs index 5432d93bdf7445..0c53fa56746eb1 100644 --- a/crates/oxc_transformer/src/options/babel/env/targets.rs +++ b/crates/oxc_transformer/src/options/babel/env/targets.rs @@ -60,12 +60,9 @@ impl TryFrom for EngineTargets { if key == "safari" && v == "tp" { continue; } - // TODO: Some keys are not implemented yet. - // : - // 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); diff --git a/crates/oxc_transformer/src/options/engine_targets.rs b/crates/oxc_transformer/src/options/engine_targets.rs index fe1ac2ac3ebd8f..f089e3735f8b29 100644 --- a/crates/oxc_transformer/src/options/engine_targets.rs +++ b/crates/oxc_transformer/src/options/engine_targets.rs @@ -6,20 +6,26 @@ use oxc_diagnostics::Error; use super::{babel::BabelTargets, BrowserslistQuery}; /// A map of engine names to minimum supported versions. +/// +/// #[derive(Debug, Default, Clone, Eq, PartialEq, Deserialize)] #[serde(try_from = "BabelTargets")] pub struct EngineTargets { + android: Option, // not in esbuild chrome: Option, deno: Option, edge: Option, + electron: Option, // not in esbuild firefox: Option, hermes: Option, ie: Option, ios: Option, node: Option, opera: Option, + opera_mobile: Option, // not in esbuild rhino: Option, safari: Option, + samsung: Option, // not in esbuild } impl EngineTargets { @@ -36,6 +42,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; } @@ -45,6 +54,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; } @@ -63,12 +75,18 @@ impl EngineTargets { if let (Some(v1), Some(v2)) = (&self.opera, &targets.opera) { return v1 < v2; } + if let (Some(v1), Some(v2)) = (&self.opera_mobile, &targets.opera_mobile) { + return v1 < v2; + } if let (Some(v1), Some(v2)) = (&self.rhino, &targets.rhino) { return v1 < v2; } 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 } @@ -91,17 +109,21 @@ impl EngineTargets { pub(crate) fn get_version_mut(&mut self, key: &str) -> Result<&mut Option, ()> { 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), "ios" | "ios_saf" => Ok(&mut self.ios), "node" => Ok(&mut self.node), "opera" | "op_mob" => Ok(&mut self.opera), + "opera_mobile" => Ok(&mut self.opera_mobile), "rhino" => Ok(&mut self.rhino), "safari" => Ok(&mut self.safari), + "samsung" => Ok(&mut self.samsung), _ => Err(()), } } diff --git a/tasks/transform_conformance/snapshots/babel_exec.snap.md b/tasks/transform_conformance/snapshots/babel_exec.snap.md index 5f39b203e7c90e..ed82fe2f2758ac 100644 --- a/tasks/transform_conformance/snapshots/babel_exec.snap.md +++ b/tasks/transform_conformance/snapshots/babel_exec.snap.md @@ -257,7 +257,7 @@ AssertionError: expected [Function Object] to be [Function Bar] // Object.is equ ❯ ../../node_modules/.pnpm/@babel+runtime@7.26.0/node_modules/@babel/runtime/helpers/asyncToGenerator.js:14:12 ❯ Bar.test fixtures/babel-preset-env-test-fixtures-plugins-integration-regression-7064-exec.test.js:14:6 ❯ fixtures/babel-preset-env-test-fixtures-plugins-integration-regression-7064-exec.test.js:20:12 - ❯ ../../node_modules/.pnpm/@vitest+runner@2.1.2/node_modules/@vitest/runner/dist/index.js:146:14 + ❯ ../../node_modules/.pnpm/@vitest+runner@2.1.4/node_modules/@vitest/runner/dist/index.js:146:14 This error originated in "fixtures/babel-preset-env-test-fixtures-plugins-integration-regression-7064-exec.test.js" test file. It doesn't mean the error was thrown inside the file itself, but while it was running. The latest test that might've caused the error is "fixtures/babel-preset-env-test-fixtures-plugins-integration-regression-7064-exec.test.js". It might mean one of the following: