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

Using "loose" option in env preset results in invalid Set.concat() call #7958

Closed
joeporpeglia opened this issue May 17, 2018 · 3 comments
Closed
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Comments

@joeporpeglia
Copy link

Bug Report

Current Behavior
Using a spread operator on a Set as described in the MDN docs while setting "loose": true for @babel/preset-env transpiles to the following:

var set = new Set([1, 2, 3, 4]);
set.concat().map(function (v) {
  return console.log(v);
});

Input Code

  • REPL or Repo link if applicable:
const set = new Set([1,2,3,4]);
[...set].map(v => console.log(v));

Expected behavior/code
I would expect some sort of conversion from Set to Array before calling concat, similar to the approach with loose mode disabled.

Babel Configuration (.babelrc, package.json, cli command)

{
  "presets": [
    ["@babel/env", {
      "targets": {
        "browsers": [
          ">2%",
          "last 1 Edge version",
          "last 2 Safari version",
          "last 1 Firefox version"
        ]
      },
      "loose": true
    }]
  ]
}

Environment

  • Babel version(s): v7.0.0-beta.47
  • Node/npm version: Node 8 / npm 5
  • OS:OSX 10.12.6
  • Monorepo: no
  • How you are using Babel: cli and loader

Possible Solution
With loose mode enabled it seems like the spread transform assumes all sets are transpiled to arrays. I don't think that's always the case though, depending on the browser's being targeted. I don't have a solution to propose, but hopefully these details can help.

Additional context/Screenshots
none

@babel-bot
Copy link
Collaborator

Hey @joeporpeglia! We really appreciate you taking the time to report an issue. The collaborators
on this project attempt to help as many people as possible, but we're a limited number of volunteers,
so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack
community that typically always has someone willing to help. You can sign-up here
for an invite.

@loganfsmyth
Copy link
Member

That is the expected behavior of loose, since the goal of loose is to simplify the assumptions that Babel makes about spec compliance. I would not recommend loose unless you've looked through all the plugins you're using to see if the limitations it imposes are actually something you'd want.

https://www.npmjs.com/package/@babel/plugin-transform-spread#options

In loose mode, all iterables are assumed to be arrays.

@joeporpeglia
Copy link
Author

Ah I should've checked the docs for the plugins included by env. Thanks for the help @loganfsmyth!

@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Aug 20, 2018
@lock lock bot locked as resolved and limited conversation to collaborators Aug 20, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Projects
None yet
Development

No branches or pull requests

3 participants