refactor(es/preset-env): Avoid unnecessary unwrap (#2943)

This commit is contained in:
Pig Fang 2021-12-02 16:03:28 +08:00 committed by GitHub
parent e8225a66a0
commit 3302d1733a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -455,14 +455,15 @@ impl BrowserData<Option<Version>> {
_ => {}
}
let version = if version.contains("-") {
version.split('-').next().unwrap().parse().unwrap()
} else {
version.parse().unwrap()
};
let version = version
.split_once('-')
.map(|(version, _)| version)
.unwrap_or(version)
.parse()
.unwrap();
// lowest version
if data[&browser].is_none() || data[&browser].unwrap() > version {
if data[&browser].map(|v| v > version).unwrap_or(true) {
for (k, v) in data.iter_mut() {
if browser == k {
*v = Some(version);