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

Object literal throws parse error #709

Closed
futurist opened this issue Dec 4, 2016 · 3 comments

Comments

@futurist
Copy link

commented Dec 4, 2016

Below code will throw Parse Error:

echo '{a:1, b:2}' | standard --stdin

Throws:

:1:8: Parsing error: Unexpected token :

But it's valid javascript code.

It's important for this issue, since some times a JS file only store data, to feed other JS to read.

@rstacruz

This comment has been minimized.

Copy link
Member

commented Dec 4, 2016

@feross

This comment has been minimized.

Copy link
Member

commented Dec 5, 2016

@rstacruz Nice to know!

@futurist If you're just storing data in a file, you might want to consider using a .json extension instead of .js.

@feross feross closed this Dec 5, 2016

@maxlath

This comment has been minimized.

Copy link

commented Jan 1, 2017

for the record, the same issue seems to arise with object destructuring assignment:

  • valid
var { ids, languages, props, format } = obj
  • invalid
var ids, languages, props, format
{ ids, languages, props, format } = obj // Parsing error: Unexpected token =
  • valid
var ids, languages, props, format
({ ids, languages, props, format }) = obj

@lock lock bot locked as resolved and limited conversation to collaborators May 10, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
4 participants
You can’t perform that action at this time.