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

Babel loose config option causes issues with spread transform #1000

Open
AshleyGrant opened this issue Dec 10, 2018 · 1 comment
Open

Babel loose config option causes issues with spread transform #1000

AshleyGrant opened this issue Dec 10, 2018 · 1 comment

Comments

@AshleyGrant
Copy link
Contributor

I'm submitting a bug report
I'm submitting a feature request

  • Library Version:
    1.0.0-beta7

Please tell us about your environment:

  • Operating System:
    all

  • Node Version:
    6.2.0

  • NPM Version:
    8.11.3
  • Browser:
    all

  • Language:
    ESNext

  • Loader/bundler:
    all

Current behavior:
Babel config specifies loose: true. This causes issues when using the spread (...) operator with a Set object. Specifically, the code:

this.foo = [...new Set([1, 2, 3])];

is transpiled to

this.foo = new Set([1, 2, 3]).concat();

This is a problem, as Set objects do not have a concat method. This transpilation is a consequence of having loose: true in .babelrc.js, per this issue: babel/babel#7958 . As mentioned in the linked issue, this is the expected behavior when using loose: true, and is not a bug in Babel or the spread transformer.

Simply setting loose: false will fix this issue.

This issue was originally reported on StackOverflow here: https://stackoverflow.com/questions/53696962/aurelia-not-transpiling-set-and-spread-operator-correctly

  • What is the expected behavior?
    Spread operator to be transpiled correctly with Set objects.

  • What is the motivation / use case for changing the behavior?
    Make transpilation work correctly.

@3cp
Copy link
Member

3cp commented Dec 10, 2018

I questioned loose mode before in #866 but didn't have any interesting code that broke with loose mode.

Alternatively this.foo = Array.from(new Set([1,2,3])); (still compact and readable) can avoid the loose mode issue.

I would side with changing user code than pay the price (performance and size) of strict mode.

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

No branches or pull requests

2 participants