Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unnecessary rest parameter transformation when targeting recent Safari versions #3268

Closed
cecchi opened this issue Jan 14, 2022 · 3 comments
Closed
Labels

Comments

@cecchi
Copy link

cecchi commented Jan 14, 2022

Describe the bug

Safari has supported rest parameters since version 10. When targeting recent versions of Safari (e.g. "Safari >= 15"), SWC transforms rest parameters using a for loop.

Input code

function foo(...args) {
  console.log(args)
}

foo(1,2,3)

Config

{
  "jsc": {
    "parser": {
      "syntax": "ecmascript",
      "jsx": false
    },
    "target": "es5",
    "loose": false,
    "minify": {
      "compress": false,
      "mangle": false
    }
  },
  "module": {
    "type": "es6"
  },
  "minify": false,
  "isModule": true,
  "env": {
    "targets": "Safari >= 15"
  }
}

Playground link

https://play.swc.rs/?version=1.2.129&code=H4sIAAAAAAAAA0srzUsuyczPU0jLz9fQ09NLLEov1lSo5lJQSM7PK87PSdXLyU%2FXAIty1XJxgVQZ6hjpGGsCAMQsaGQ5AAAA&config=H4sIAAAAAAAAA0WOPQrDMAxGrxI0Z%2BmQDoH2Bp16AuHKwSX%2BQXJKg%2FHdK5uUbJK%2B9z1U4C0G5gIJWYjbJHvI%2BIUZyHgUwy5lGBXTk8VVqI6QkRfKDZFJszVGoSMdwbvg7N5MJvrEJHJGGJb1T1YV%2Bfja2qFA3hN14RXq6Th6Th4HmHnTncKnd%2FobqocnWmQ33G%2FDZYJaf9Mhm07WAAAA

Expected behavior

The code should be untransformed:

function foo(...args) {
    console.log(args);
}
foo(1, 2, 3);

Actual behavior

function foo() {
    for(let _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
        args[_key] = arguments[_key];
    }
    console.log(args);
}
foo(1, 2, 3);

Version

1.2.129

Additional context

No response

@cecchi cecchi added the C-bug label Jan 14, 2022
@RiESAEX
Copy link
Contributor

RiESAEX commented Jan 15, 2022

because there is a bug in safari 14.
You can add bugfixes: true to env
https://bugs.webkit.org/show_bug.cgi?id=220517
babel/babel#13916

@kdy1
Copy link
Member

kdy1 commented Jan 15, 2022

@RiESAEX Thank you!

@swc-bot
Copy link
Collaborator

swc-bot commented Oct 19, 2022

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@swc-project swc-project locked as resolved and limited conversation to collaborators Oct 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests

4 participants