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

preset-env with loose mode array deconstruction with es6 Set maybe generate wrong code #8662

Open
HairyRabbit opened this Issue Sep 10, 2018 · 5 comments

Comments

Projects
None yet
3 participants
@HairyRabbit

HairyRabbit commented Sep 10, 2018

Bug Report

Current Behavior
A clear and concise description of the behavior.

Input Code

node -r @babel/register -e "var res = require('@babel/core').transformSync('[...[...new Set(1)], ...[...new Set(2)]]' , { presets: [['@babel/env', { loose: true }]] }); console.log(res.code)"

generate:

"use strict";

new Set(1).concat().concat(new Set(2).concat());

Expected behavior/code
The generate code is not same as babel@6 try

generate code:

"use strict";

[].concat(new Set(1)).concat([].concat(new Set(2)));

Environment

  • Babel version(s): 7
  • Node/npm version: v10.3.0/6.1.0
  • OS: win10
@babel-bot

This comment has been minimized.

Show comment
Hide comment
@babel-bot

babel-bot Sep 10, 2018

Collaborator

Hey @HairyRabbit! 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.

Collaborator

babel-bot commented Sep 10, 2018

Hey @HairyRabbit! 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.

@nicolo-ribaudo

This comment has been minimized.

Show comment
Hide comment
@nicolo-ribaudo

nicolo-ribaudo Sep 10, 2018

Member

They both are wrong. Loose mode assumes that you are only spreading arrays: I suggest either disabling loose mode or wrapping your Sets in Array.from().

Member

nicolo-ribaudo commented Sep 10, 2018

They both are wrong. Loose mode assumes that you are only spreading arrays: I suggest either disabling loose mode or wrapping your Sets in Array.from().

@HairyRabbit

This comment has been minimized.

Show comment
Hide comment
@HairyRabbit

HairyRabbit Sep 10, 2018

:) yea sure, disable loose mode always right, and this behavior was a bug, or a feature?

HairyRabbit commented Sep 10, 2018

:) yea sure, disable loose mode always right, and this behavior was a bug, or a feature?

@nicolo-ribaudo

This comment has been minimized.

Show comment
Hide comment
@nicolo-ribaudo

nicolo-ribaudo Sep 10, 2018

Member

If loose mode was 100% correct it wouldn't be loose 😛
Assuming that everything is an array is a trade-off we must make in order to make the output smaller & faster.

Member

nicolo-ribaudo commented Sep 10, 2018

If loose mode was 100% correct it wouldn't be loose 😛
Assuming that everything is an array is a trade-off we must make in order to make the output smaller & faster.

@HairyRabbit

This comment has been minimized.

Show comment
Hide comment
@HairyRabbit

HairyRabbit Sep 10, 2018

Yeap, I love the pretty code. I think may add more docs about this mode.

HairyRabbit commented Sep 10, 2018

Yeap, I love the pretty code. I think may add more docs about this mode.

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