Skip to content

When unknown browser version used, all polyfills are added to the bundle #9778

@erykpiast

Description

@erykpiast

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)

https://play.swc.rs/?version=1.9.3&code=H4sIAAAAAAAAA0ssrsxLVkgrzUsuyczPU0jLz9eoVtDT0ysoyi8oVqjVVKjmUlBILE%2FMLFFIzs8rzs9J1cvJT0dVY81Vy8UF0qlpDQAfwt5ETwAAAA%3D%3D&config=H4sIAAAAAAAAA3VRQYrDMAy89xVG5x627K2HQukD9gFLWYyttC6yHSwnNJT8vYpJ3aSwPlkzo7E0fmyUAu%2BCawbYq0YT43aCMPRSP%2BQqRdbpgpkF%2BIXTNUWP6qB2319wFn4s%2Bhubt75NyJh6PBKdovcYSm9OXfGeBDqJoDYIwkPI%2Bi4IoPGaTXJthu2LvfF9NijIONvUuauN1%2BFCuNykwE1MXueF8HVAnnLuJ9Dw2SOcec8OLEvDTI3VVxTTrrxyBouN7qj0fVjOgi50jHYVyYK1qO2fiRb%2FE%2BTYEvZIy0hkqlU0FCPXHKZf2oxPuR%2FOf%2BsBAAA%3D

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.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions