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

Issue with Spread Operator Inside JSON #1927

Open
FlameWolf opened this Issue Apr 13, 2018 · 3 comments

Comments

Projects
None yet
4 participants
@FlameWolf

FlameWolf commented Apr 13, 2018

When trying to parse a JSON expression containing a spread operator, we get an error, even though the code is valid.

Steps to reproduce

Try to validate the below code:

var x = {
	a: "asdf",
	b: "qwerty",
	...(1 > 0 ? { c: "zxcv" } : ""),
	d: 1234
};

Expected output

A message saying "Code is syntactically valid."

Actual output

Error: Line 4: Unexpected token ...

@dbryan0516

This comment has been minimized.

dbryan0516 commented Aug 13, 2018

Closed #1949 and moved here

Steps to reproduce

When using recast to parse, it fails on a spread syntax object.

query = {
      ...query, // FAILS here, line 477
      $or: [
        {_id: { $in: req.jwt.var}},
        {owner: req.jwt.var2}
      ]
    };

Expected output

Program completes parsing normally.

Actual output

gitdir\node_modules\esprima\dist\esprima.js:1995
                throw this.unexpectedTokenError(token, message);
                ^
Error: Line 477: Unexpected token ...
    at ErrorHandler.constructError (gitdir\node_modules\esprima\dist\esprima.js:5012:22)
    at ErrorHandler.createError (gitdir\node_modules\esprima\dist\esprima.js:5028:27)
    at Parser.unexpectedTokenError (gitdir\node_modules\esprima\dist\esprima.js:1985:39)
    at Parser.throwUnexpectedToken (gitdir\node_modules\esprima\dist\esprima.js:1995:21)
    at Parser.parseObjectPropertyKey (gitdir\node_modules\esprima\dist\esprima.js:2499:33)
    at Parser.parseObjectProperty (gitdir\node_modules\esprima\dist\esprima.js:2534:25)
    at Parser.parseObjectInitializer (gitdir\node_modules\esprima\dist\esprima.js:2602:35)
    at Parser.inheritCoverGrammar (gitdir\node_modules\esprima\dist\esprima.js:2285:37)
    at Parser.parsePrimaryExpression (gitdir\node_modules\esprima\dist\esprima.js:2354:38)
    at Parser.inheritCoverGrammar (gitdir\node_modules\esprima\dist\esprima.js:2285:37)

Commenting out that line (477), and it ran successfully

@AlekseyChepurko

This comment has been minimized.

AlekseyChepurko commented Sep 24, 2018

Hi there ! Is there any chance this to be fixed ?:) according to the test/fixtures/es2018/spread-property it should work but does not for me

@dorellang

This comment has been minimized.

dorellang commented Nov 5, 2018

Apparently this feature is supported in master, but not in the latest official release. It would be great it were on the official release too. I am writing a JavaScript visualization platform and some projects fail because of this :S

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