From 3302d1733acd5adf4f53ce8c2aef678990f584f2 Mon Sep 17 00:00:00 2001 From: Pig Fang Date: Thu, 2 Dec 2021 16:03:28 +0800 Subject: [PATCH] refactor(es/preset-env): Avoid unnecessary `unwrap` (#2943) --- crates/swc_ecma_preset_env/src/lib.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/crates/swc_ecma_preset_env/src/lib.rs b/crates/swc_ecma_preset_env/src/lib.rs index 7669e14a5ae..6d9b6178bdc 100644 --- a/crates/swc_ecma_preset_env/src/lib.rs +++ b/crates/swc_ecma_preset_env/src/lib.rs @@ -455,14 +455,15 @@ impl BrowserData> { _ => {} } - 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);