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

REPL + prettify should not throw on let = 42 #2218

Open
JLHwung opened this issue Mar 26, 2020 · 3 comments · May be fixed by #2219
Open

REPL + prettify should not throw on let = 42 #2218

JLHwung opened this issue Mar 26, 2020 · 3 comments · May be fixed by #2219
Assignees

Comments

@JLHwung
Copy link
Contributor

@JLHwung JLHwung commented Mar 26, 2020

Bug Report

Updates: ( Thanks to @nicolo-ribaudo )

When the Prettify setting of REPL is enabled

let = 42;

should not throw.

=== Below is original issue report ===

  • I would like to work on a fix!

Current Behavior
The transformed result of the following snippet throws syntax error

Unexpected token (2:5)
  1 | var _ref = {};
> 2 | let = _ref["let"];
    |     ^
  3 | _ref;

Input Code

({ let } = {});

Expected behavior/code
It should be transformed correctly with let assigned to undefined

Babel Configuration (babel.config.js, .babelrc, package.json#babel, cli command, .eslintrc)

  • Filename: babel.config.js
{
  "plugins": ["@babel/plugin-transform-destructuring"]
}

Environment: REPL

Possible Solution
Check if id is an identifier named let, if it is, build a variable declaration instead of an assignment expression.

https://github.com/babel/babel/blob/a901bd50b16b76a87e65508d2a94f098f5745c76/packages/babel-plugin-transform-destructuring/src/index.js#L101

@babel-bot

This comment has been minimized.

Copy link

@babel-bot babel-bot commented Mar 26, 2020

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

Copy link
Member

@nicolo-ribaudo nicolo-ribaudo commented Mar 26, 2020

This is a parser bug, since let = 2 should be valid.

@JLHwung JLHwung changed the title `transform-destructuring` output invalid syntax when `let` is used as binding name `let` should be allowed as lhs identifier name of assignment in sloppy mode Mar 26, 2020
@JLHwung JLHwung self-assigned this Mar 26, 2020
@JLHwung JLHwung transferred this issue from babel/babel Mar 26, 2020
@babel-bot

This comment has been minimized.

Copy link

@babel-bot babel-bot commented Mar 26, 2020

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

@JLHwung JLHwung changed the title `let` should be allowed as lhs identifier name of assignment in sloppy mode REPL + prettify should not throw on let = 42 Mar 26, 2020
@JLHwung JLHwung linked a pull request that will close this issue Mar 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

3 participants
You can’t perform that action at this time.