swc-project / swc

Rust-based platform for the Web
https://swc.rs
Apache License 2.0
30.12k stars 1.16k forks source link

`Object.getOwnPropertyDescriptor` is not polyfilled in ES5 #8890

Closed Florent-Bouisset closed 3 weeks ago

Florent-Bouisset commented 3 weeks ago

Describe the bug

Hello, I'm not sure this is a bug or if I misunderstood something in how SWC is polyfiling code. I'm trying to bundle and polyfill the following code to es5.

// input.js
const object1 = {
  property1: 42,
};
const descriptors1 = Object.getOwnPropertyDescriptors(object1);

The polyfill output is:

// output.js
var object1 = {
    property1: 42
};
var descriptors1 = Object.getOwnPropertyDescriptors(object1);

I can see const has been successfully changed to var, but the method Object.getOwnPropertyDescriptors has not been polyfilled (it's an es7 feature and is not available in es5).

Thanks for you help

Input code

No response

Config

{
  "jsc": {
    "parser": {
      "syntax": "ecmascript",
      "jsx": false,
    },
    "target": "es5",
    "loose": true,
    "minify": {
      "compress": false,
      "mangle": false
    }
  },
  "module": {
    "type": "umd"
  },
  "minify": false,
  "isModule": false
}

Playground link (or link to the minimal reproduction)

https://play.swc.rs/?version=1.3.100&code=H4sIAAAAAAAAA0WNzQpAQBCA7%2FMUc6RE5ERu7jyDNbTadrbdKW3y7rIp9%2B9HsQ2CvBykpMYBL0B0nh15iXWHbVPA3UNVoWVBxyZu2hhaQSVvpaC8dsI%2BvPKUMuVOMp12%2Firjz2TfJ%2B8BHh1q2VB5AAAA&config=H4sIAAAAAAAAA1VPSQ7DIAy85xXI51576R%2F6CIs4ERGbMEhFUf5eCJC0J3sWz8j7JARsLOEl9rIW4DEwhQsXhrON%2BCkMkDTIMigf4THUjau0oGZq3NEGRAwrxfOMn90P2jmmwsWQuh2MsmrJv4XSGR%2BI%2BT%2B3WtGumgbd2qbeCMbN6RT7IzH7iiCZGW7TKLuCQfF7XLbY4wtDWkJnFQEAAA%3D%3D

SWC Info output

No response

Expected behavior

The code should be polyfilled using the core-js object/get-own-property-descriptorspolyfill.

Actual behavior

No response

Version

1.3.100

Additional context

No response

kdy1 commented 3 weeks ago

Polyfill is injected only in preset-env mode.