-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Description
Describe the bug
When I use a browser version unknown for SWC in the browserslist selector, instead of adding no transipilation and polyfills (this is the default @babel/preset-env behavior), everything is transpilled and polyfilled. That's a bit unfortunate, as the browserslist-rs tool used under the hood recognizes only browsers released before June 2024. browserslist/browserslist-rs#25. I'm afraid changing how to handle defaults it's beyond my Rust knowledge 😅
Input code
async function foo({ ...props }) {
await console.log({ ...props });
}
foo();
Config
{
"minify": false,
"env": {
"targets": ["Chrome > 130"]
},
"jsc": {
"preserveAllComments": true,
"parser": {
"syntax": "ecmascript",
"jsx": true
},
"minify": {
"mangle": false,
"format": {
"asciiOnly": false,
"comments": "some"
},
"compress": {
"defaults": false,
"unused": true,
"dead_code": true,
"toplevel": true
}
},
"loose": false
}
}
Playground link (or link to the minimal reproduction)
SWC Info output
Operating System:
Platform: darwin
Arch: arm64
Machine Type: arm64
Version: Darwin Kernel Version 23.6.0: Mon Jul 29 21:14:30 PDT 2024; root:xnu-10063.141.2~1/RELEASE_ARM64_T6030
CPU: (11 cores)
Models: Apple M3 Pro
Binaries:
Node: 18.19.0
npm: 10.2.3
Yarn: N/A
pnpm: 9.1.2
Relevant Packages:
@swc/core: 1.7.36
@swc/helpers: 0.5.13
@swc/types: 0.1.13
typescript: 5.4.5
next: 12.3.4
SWC Config:
output: N/A
.swcrc path: N/A
Next.js info:
output: N/A
Expected behavior
No polyfills are added, no transpilation is made.
Actual behavior
Some default transpilation rules apply.
Version
1.9.3
Additional context
It's fair to assume that unrecognised version of a known browser is one of the most recent versions and it's not added to the internal database yet (in SWC it's provided by browserslist-rs
if I got it right). If we apply defaults instead, it breaks workflows where browser selectors are updated regularly based on the real application usage. This is exactly my case of a mid-size B2B SaaS app. We keep selectors aligned with what our customers actually use. This approach doesn't work well with SWC, because it transpiles code to some pretty old ECMA Script version. It worked with Babel, as it doesn't apply any transpilation or polyfills for unknown versions.