Skip to content

Commit

Permalink
refactor(transformer): use Browserslist::Version (#7028)
Browse files Browse the repository at this point in the history
  • Loading branch information
Boshen committed Oct 30, 2024
1 parent 76947e2 commit 6284f84
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 139 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ nonmax = "0.5.5"
num-bigint = "0.4.6"
num-traits = "0.2.19"
once_cell = "1.20.2"
oxc-browserslist = "1.0.3"
oxc-browserslist = "1.1.0"
oxc_resolver = "2.0.0"
petgraph = "0.6.5"
phf = "0.11.2"
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_transformer/src/env/data/babel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::sync::OnceLock;

use rustc_hash::FxHashMap;

use crate::env::targets::{version::Version, Targets};
use crate::env::{Targets, Version};

/// Reference: <https://github.com/swc-project/swc/blob/ea14fc8e5996dcd736b8deb4cc99262d07dfff44/crates/swc_ecma_preset_env/src/transform_data.rs#L194-L218>
fn features() -> &'static FxHashMap<String, Targets> {
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_transformer/src/env/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ mod targets;

pub use data::can_enable_plugin;
pub use options::EnvOptions;
pub use targets::Targets;
pub use targets::{Targets, Version};
13 changes: 6 additions & 7 deletions crates/oxc_transformer/src/env/targets/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,16 @@
//!
//! This file is copied from <https://github.com/swc-project/swc/blob/ea14fc8e5996dcd736b8deb4cc99262d07dfff44/crates/preset_env_base/src/lib.rs>
use std::{ops::Deref, str::FromStr};
use std::ops::Deref;

use oxc_diagnostics::Error;
use rustc_hash::FxHashMap;
use serde::Deserialize;

pub mod query;
pub mod version;

pub use browserslist::Version;
pub use query::Query;
pub use version::Version;

/// A map of browser names to data for feature support in browser.
///
Expand Down Expand Up @@ -150,13 +149,13 @@ impl TryFrom<BabelTargets> for Targets {
let BabelTargetsValue::String(v) = v else {
return Err(Error::msg(format!("{v:?} is not a string for {k}.")));
};
match Version::from_str(&v) {
match Version::parse(&v) {
Ok(v) => {
new_map.insert(k, v);
}
Err(()) => {
Err(err) => {
return Err(oxc_diagnostics::Error::msg(format!(
"Failed to parse `{v}` for `{k}`"
"Failed to parse `{v}` for `{k}`\n{err:?}"
)))
}
}
Expand All @@ -169,7 +168,7 @@ impl TryFrom<BabelTargets> for Targets {

#[cfg(test)]
mod tests {
use crate::env::{targets::version::Version, Targets};
use crate::env::{targets::Version, Targets};

#[test]
fn should_enable_android_falls_back_to_chrome() {
Expand Down
125 changes: 0 additions & 125 deletions crates/oxc_transformer/src/env/targets/version.rs

This file was deleted.

0 comments on commit 6284f84

Please sign in to comment.