Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(transformer): use Browserslist::Version #7028

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

Loading