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

Unexpected token when parsing a member expression after a property initializer in an object pattern #10989

Open
JLHwung opened this issue Jan 12, 2020 · 7 comments
Assignees

Comments

@JLHwung
Copy link
Contributor

@JLHwung JLHwung commented Jan 12, 2020

Bug Report

  • I would like to work on a fix!

Current Behavior
A clear and concise description of the behavior.

The following snippet will throw SyntaxError: Unexpected token, expected ","
Input Code

  • REPL or Repo link if applicable: REPL
({ a = 42, b: {}.d } = {})

Expected behavior/code
It should parse successfully.

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

Environment
REPL

Possible Solution
We may reset refExpressionErrors.shortAssign when parsing Assignment Expression after eating tt.colon in parseObjectProperty.

: this.parseMaybeAssign(false, refExpressionErrors);

@babel-bot

This comment has been minimized.

Copy link
Collaborator

@babel-bot babel-bot commented Jan 12, 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."

@vedantroy

This comment has been minimized.

Copy link

@vedantroy vedantroy commented Jan 12, 2020

I would like to take this up. I've made a fork and I'm working on fixing the issue. What are next steps?

@JLHwung

This comment has been minimized.

Copy link
Contributor Author

@JLHwung JLHwung commented Jan 12, 2020

@vedantroy Sure. If it's the first time you are contributing Babel, follow these steps: (you need to have make and yarn available on your machine).

  1. Run yarn && make bootstrap
  2. Wait
  3. Run make watch (or make build whenever you change a file)
  4. Add a test (only input.js; output.js will be automatically generated)
  5. Update the code!
  6. yarn jest babel-parser to run the tests
    • If some test outputs don't match but the new results are correct, you can delete the bad output.js files and run the tests again
  7. If it is working, run make test to run all the tests
  8. Run git push and open a PR!

Note that the possible solution is based on my recent refactor branch: https://github.com/JLHwung/babel/tree/fix-6705 I suggest you work from this branch as the code is a little bit different than the master branch.

⚠️The solution is still pretty rough, and and in some situations you may find that it doesn't work at all. Welcome to discuss the solution on the #development Slack channel.

@vedantroy

This comment has been minimized.

Copy link

@vedantroy vedantroy commented Jan 17, 2020

@JLHwung It seems like fix-6705 has been merged into master. I assume this means I can just work with the master branch, correct?

@JLHwung

This comment has been minimized.

Copy link
Contributor Author

@JLHwung JLHwung commented Jan 17, 2020

@vedantroy Correct!

@vedantroy

This comment has been minimized.

Copy link

@vedantroy vedantroy commented Jan 17, 2020

@JLHwung While messing with the presented test case, I found that {a = 3} = {} works in the Chrome DevTools console, but fails in babel. Could this also be considered a bug? If so, I should probably try and fix that first, since it seems like a simpler case of the above bug.

Valid_Code

@nicolo-ribaudo

This comment has been minimized.

Copy link
Member

@nicolo-ribaudo nicolo-ribaudo commented Jan 17, 2020

It's because chrome parses it as an expression. If you use @babel/parser's parseExpression it will work, or you have to wrap it in parentheses: ({ a = 3 } = {}).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.