From 5a68a360b46fd1c1f53927068c78b12442386295 Mon Sep 17 00:00:00 2001 From: Pig Fang Date: Mon, 29 Nov 2021 18:29:49 +0800 Subject: [PATCH] fix(es/preset-env): Enable "mobile to desktop" (#2907) --- crates/swc_ecma_preset_env/src/lib.rs | 20 ++++++++------ .../corejs2/entry-chromeandroid/output.mjs | 10 +++++++ .../corejs3/entry-chromeandroid/output.mjs | 26 +++++++++++++++++++ 3 files changed, 48 insertions(+), 8 deletions(-) diff --git a/crates/swc_ecma_preset_env/src/lib.rs b/crates/swc_ecma_preset_env/src/lib.rs index 56301fd4769..3fb4b297416 100644 --- a/crates/swc_ecma_preset_env/src/lib.rs +++ b/crates/swc_ecma_preset_env/src/lib.rs @@ -590,14 +590,18 @@ impl Query { where T: AsRef, { - let distribs = - browserslist::resolve(s, browserslist::Opts::new().ignore_unknown_versions(true)) - .with_context(|| { - format!( - "failed to resolve browserslist query: {:?}", - s.iter().map(|v| v.as_ref()).collect::>() - ) - })?; + let distribs = browserslist::resolve( + s, + browserslist::Opts::new() + .mobile_to_desktop(true) + .ignore_unknown_versions(true), + ) + .with_context(|| { + format!( + "failed to resolve browserslist query: {:?}", + s.iter().map(|v| v.as_ref()).collect::>() + ) + })?; let versions = BrowserData::parse_versions(distribs).expect("failed to parse browser version"); diff --git a/crates/swc_ecma_preset_env/tests/fixtures/corejs2/entry-chromeandroid/output.mjs b/crates/swc_ecma_preset_env/tests/fixtures/corejs2/entry-chromeandroid/output.mjs index 1561fb9a482..1e62a6e45d7 100644 --- a/crates/swc_ecma_preset_env/tests/fixtures/corejs2/entry-chromeandroid/output.mjs +++ b/crates/swc_ecma_preset_env/tests/fixtures/corejs2/entry-chromeandroid/output.mjs @@ -1,3 +1,13 @@ +import "core-js/modules/es6.array.sort"; +import "core-js/modules/es7.array.flat-map"; +import "core-js/modules/es7.object.define-getter"; +import "core-js/modules/es7.object.define-setter"; +import "core-js/modules/es7.object.lookup-getter"; +import "core-js/modules/es7.object.lookup-setter"; +import "core-js/modules/es7.promise.finally"; +import "core-js/modules/es7.string.trim-left"; +import "core-js/modules/es7.string.trim-right"; +import "core-js/modules/es7.symbol.async-iterator"; import "core-js/modules/web.dom.iterable"; import "core-js/modules/web.immediate"; import "core-js/modules/web.timers"; diff --git a/crates/swc_ecma_preset_env/tests/fixtures/corejs3/entry-chromeandroid/output.mjs b/crates/swc_ecma_preset_env/tests/fixtures/corejs3/entry-chromeandroid/output.mjs index 65a4c905d86..dcd445945e0 100644 --- a/crates/swc_ecma_preset_env/tests/fixtures/corejs3/entry-chromeandroid/output.mjs +++ b/crates/swc_ecma_preset_env/tests/fixtures/corejs3/entry-chromeandroid/output.mjs @@ -1,2 +1,28 @@ +import "core-js/modules/es.array.flat"; +import "core-js/modules/es.array.flat-map"; +import "core-js/modules/es.array.iterator"; +import "core-js/modules/es.array.reduce"; +import "core-js/modules/es.array.reduce-right"; +import "core-js/modules/es.array.sort"; +import "core-js/modules/es.array.unscopables.flat"; +import "core-js/modules/es.array.unscopables.flat-map"; +import "core-js/modules/es.math.hypot"; +import "core-js/modules/es.object.define-getter"; +import "core-js/modules/es.object.define-setter"; +import "core-js/modules/es.object.from-entries"; +import "core-js/modules/es.object.lookup-getter"; +import "core-js/modules/es.object.lookup-setter"; +import "core-js/modules/es.promise"; +import "core-js/modules/es.promise.finally"; +import "core-js/modules/es.string.replace"; +import "core-js/modules/es.string.trim-end"; +import "core-js/modules/es.string.trim-start"; +import "core-js/modules/es.symbol.async-iterator"; +import "core-js/modules/es.symbol.description"; +import "core-js/modules/web.dom-collections.iterator"; import "core-js/modules/web.immediate"; +import "core-js/modules/web.queue-microtask"; +import "core-js/modules/web.url"; +import "core-js/modules/web.url-search-params"; +import "core-js/modules/web.url.to-json"; 1 ** 2;