mirror of
https://github.com/swc-project/swc.git
synced 2024-11-28 11:13:43 +03:00
feat(es/preset-env): Make android targets fall back to chrome (#1597)
This commit is contained in:
parent
731dc68c92
commit
a24266d986
@ -163,21 +163,41 @@ pub fn should_enable(target: Versions, feature: Versions, default: bool) -> bool
|
||||
return default;
|
||||
}
|
||||
|
||||
target
|
||||
.iter()
|
||||
.zip(feature.iter())
|
||||
.any(|((_, target_version), (_, f))| {
|
||||
if target_version.is_none() {
|
||||
return false;
|
||||
}
|
||||
target.iter().zip(feature.iter()).any(
|
||||
|((target_name, maybe_target_version), (_, maybe_feature_version))| {
|
||||
maybe_target_version.map_or(false, |target_version| {
|
||||
let feature_or_fallback_version =
|
||||
maybe_feature_version.or_else(|| match target_name {
|
||||
// Fall back to Chrome versions if Android browser data
|
||||
// is missing from the feature data. It appears the
|
||||
// Android browser has aligned its versioning with Chrome.
|
||||
"android" => feature.chrome,
|
||||
_ => None,
|
||||
});
|
||||
|
||||
if f.is_none() {
|
||||
return true;
|
||||
}
|
||||
|
||||
let f = f.as_ref().unwrap();
|
||||
let target = target_version.unwrap();
|
||||
|
||||
*f > target
|
||||
})
|
||||
feature_or_fallback_version.map_or(true, |v| v > target_version)
|
||||
})
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::BrowserData;
|
||||
|
||||
#[test]
|
||||
fn should_enable_android_falls_back_to_chrome() {
|
||||
assert!(!should_enable(
|
||||
BrowserData {
|
||||
android: Some("51.0.0".parse().unwrap()),
|
||||
..Default::default()
|
||||
},
|
||||
BrowserData {
|
||||
chrome: Some("51.0.0".parse().unwrap()),
|
||||
..Default::default()
|
||||
},
|
||||
false
|
||||
));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user