question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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.

https://github.com/babel/babel/blob/bfb82e778fea5b766e18066a68f79ae3fbbab9bc/packages/babel-parser/src/parser/expression.js#L1732

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
nicolo-ribaudocommented, 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 } = {}).

1reaction
vedantroycommented, 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?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Eslint - `Parsing error: unexpected token =` error for assigned ...
You're using class field (a.k.a. property initializer) syntax, which is not part of ECMAScript 2015 (ES6), nor ES2016 or 2017, ...
Read more >
SyntaxError: Unexpected token - JavaScript - MDN Web Docs
The JavaScript exceptions "unexpected token" occur when a specific language construct was expected, but something else was provided.
Read more >
https://opensource.apple.com/source/JavaScriptCore...
do { updateErrorMessage(shouldPrintToken, __VA_ARGS__); return 0; } ... "There must be at least one bound property in an object deconstruction pattern"); auto ...
Read more >
acorn.mjs - Communardo
These carry several kinds of properties to help the // parser use them properly ... If found, consume it, otherwise, // raise an...
Read more >
LWC1503: Parsing error: Unexpected token
Thanks, Vijay. ... Hi Vijay, Here recordId and objectApiName is a variable and you are using it as a string value, also use...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found