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

Add array spread support #385

Merged
merged 1 commit into from
Mar 12, 2020
Merged

Conversation

nicolo-ribaudo
Copy link
Contributor

There are some browsers that support array spread but don't support generators.

Why did we never realize it?

The browsers versions that support array spread and the versions that supports generators are close:

"transform-spread": {
  "chrome": "46",
  "edge": "13",
  "firefox": "36",
  "safari": "10",
  "node": "5",
  "ios": "10",
  "samsung": "5",
  "opera": "33",
  "electron": "0.36"
},
"transform-regenerator": {
  "chrome": "50",
  "edge": "13",
  "firefox": "53",
  "safari": "10",
  "node": "6",
  "ios": "10",
  "samsung": "5",
  "opera": "37",
  "electron": "1.1"
},

Probably no one ever used a browsers query in preset-env that included transform-regenerator but not transform-spread.

Why did we found this bug now?

create-react-app defaults to >0.2%, not dead, not op_mini all for browsers support. Some users additionally exclude IE 11 and Safari 5.1, since they are really old and force the inclusion of a lot of different transforms.
Due to some recent changes in the usage data on caniuse/browserslist (an old browser felt below 0.2%, or it become "dead"), this currently matches these browsers:

  • Chrome 49
  • Edge 17
  • Firefox 70
  • Opera 63
  • Safari 11.1

These browsers need transform-regenerator (because of Chrome 49), but they don't need transform-spread.

Alternative solution

We could force transform-spread when using transform-regenerator in preset-env, but I'd avoid forcing an unnecessary transform if possible.


Fixes babel/babel#11212

Copy link
Collaborator

@benjamn benjamn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very glad to see we can handle ...spread syntax without having to compile it to ES5. Thanks @nicolo-ribaudo!

@@ -165,11 +165,10 @@ enqueue(convert, [
"./test/class.es5.js"
]);

function convertWithSpread(es6File, es5File, callback) {
function convertWithParamsTransform(es6File, es5File, callback) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really appreciate your attention to detail, such as taking the time to update the test harness so it doesn't accidentally rely on the @babel/plugin-transform-spread transform.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[@babel/types] - spreadOperator from an array seems to have a bug with 7.8.7
3 participants