jquery / jquery/esprima

Fails to parse 'Spread' syntax: Unexpected token ...

Open
#2,034 8 comments 8 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
7.1k
Forks
773
PR merge metrics
No merged PRs in 30d

Description

Steps to reproduce

I'm using the ES2018 syntax in my code, and Esprima is failing to parse the "spread" syntax (...), for creating iterables and concatenating objects.

// Spread syntax:
const obj1 = { key: "value"};
const obj2 = { ...obj1, key2: "value"};

esprima.parse(obj2);
Expected output

I would expect the Spread syntax to be correctly parsed.

Actual output

Here's a demo link to the current issue being faced

Here's the full stack trace:
Unexpected token ...
      at ErrorHandler.constructError (node_modules/esprima/dist/esprima.js:5012:22)
      at ErrorHandler.createError (node_modules/esprima/dist/esprima.js:5028:27)
      at Parser.unexpectedTokenError (node_modules/esprima/dist/esprima.js:1985:39)
      at Parser.throwUnexpectedToken (node_modules/esprima/dist/esprima.js:1995:21)
      at Parser.parseObjectPropertyKey (node_modules/esprima/dist/esprima.js:2499:33)
      at Parser.parseObjectProperty (node_modules/esprima/dist/esprima.js:2534:25)
      at Parser.parseObjectInitializer (node_modules/esprima/dist/esprima.js:2602:35)
      at Parser.inheritCoverGrammar (node_modules/esprima/dist/esprima.js:2285:37)
      at Parser.parsePrimaryExpression (node_modules/esprima/dist/esprima.js:2354:38)
      at Parser.inheritCoverGrammar (node_modules/esprima/dist/esprima.js:2285:37)
      at Parser.parseLeftHandSideExpressionAllowCall (node_modules/esprima/dist/esprima.js:2899:26)
      at Parser.inheritCoverGrammar (node_modules/esprima/dist/esprima.js:2285:37)
      at Parser.parseUpdateExpression (node_modules/esprima/dist/esprima.js:3004:26)
      at Parser.parseUnaryExpression (node_modules/esprima/dist/esprima.js:3048:26)
      at Parser.inheritCoverGrammar (node_modules/esprima/dist/esprima.js:2285:37)
      at Parser.parseExponentiationExpression (node_modules/esprima/dist/esprima.js:3054:26)
      at Parser.inheritCoverGrammar (node_modules/esprima/dist/esprima.js:2285:37)
      at Parser.parseBinaryExpression (node_modules/esprima/dist/esprima.js:3089:26)
      at Parser.inheritCoverGrammar (node_modules/esprima/dist/esprima.js:2285:37)
      at Parser.parseConditionalExpression (node_modules/esprima/dist/esprima.js:3141:26)
      at Parser.parseAssignmentExpression (node_modules/esprima/dist/esprima.js:3250:26)
      at Parser.isolateCoverGrammar (node_modules/esprima/dist/esprima.js:2269:37)
      at Parser.parseLexicalBinding (node_modules/esprima/dist/esprima.js:3425:34)
      at Parser.parseBindingList (node_modules/esprima/dist/esprima.js:3439:27)
      at Parser.parseLexicalDeclaration (node_modules/esprima/dist/esprima.js:3461:34)
      at Parser.parseStatementListItem (node_modules/esprima/dist/esprima.js:3376:39)
      at Parser.parseFunctionSourceElements (node_modules/esprima/dist/esprima.js:4195:29)
      at Parser.parseAssignmentExpression (node_modules/esprima/dist/esprima.js:3286:38)
      at Parser.isolateCoverGrammar (node_modules/esprima/dist/esprima.js:2269:37)
      at Parser.parseArguments (node_modules/esprima/dist/esprima.js:2807:27)
      at Parser.parseLeftHandSideExpressionAllowCall (node_modules/esprima/dist/esprima.js:2913:76)
      at Parser.inheritCoverGrammar (node_modules/esprima/dist/esprima.js:2285:37)
      at Parser.parseUpdateExpression (node_modules/esprima/dist/esprima.js:3004:26)
      at Parser.parseUnaryExpression (node_modules/esprima/dist/esprima.js:3048:26)
      at Parser.inheritCoverGrammar (node_modules/esprima/dist/esprima.js:2285:37)
      at Parser.parseExponentiationExpression (node_modules/esprima/dist/esprima.js:3054:26)
      at Parser.inheritCoverGrammar (node_modules/esprima/dist/esprima.js:2285:37)
      at Parser.parseBinaryExpression (node_modules/esprima/dist/esprima.js:3089:26)
      at Parser.inheritCoverGrammar (node_modules/esprima/dist/esprima.js:2285:37)
      at Parser.parseConditionalExpression (node_modules/esprima/dist/esprima.js:3141:26)
      at Parser.parseAssignmentExpression (node_modules/esprima/dist/esprima.js:3250:26)
      at Parser.isolateCoverGrammar (node_modules/esprima/dist/esprima.js:2269:37)
      at Parser.parseExpression (node_modules/esprima/dist/esprima.js:3341:26)
      at Parser.parseLabelledStatement (node_modules/esprima/dist/esprima.js:3996:26)
      at Parser.parseStatement (node_modules/esprima/dist/esprima.js:4122:97)
      at Parser.parseStatementListItem (node_modules/esprima/dist/esprima.js:3393:31)
      at Parser.parseFunctionSourceElements (node_modules/esprima/dist/esprima.js:4195:29)
      at Parser.parseFunctionExpression (node_modules/esprima/dist/esprima.js:4408:26)
      at Parser.parsePrimaryExpression (node_modules/esprima/dist/esprima.js:2380:38)
      at Parser.inheritCoverGrammar (node_modules/esprima/dist/esprima.js:2285:37)
      at Parser.parseLeftHandSideExpressionAllowCall (node_modules/esprima/dist/esprima.js:2899:26)
      at Parser.inheritCoverGrammar (node_modules/esprima/dist/esprima.js:2285:37)
      at Parser.parseUpdateExpression (node_modules/esprima/dist/esprima.js:3004:26)
      at Parser.parseUnaryExpression (node_modules/esprima/dist/esprima.js:3048:26)
      at Parser.inheritCoverGrammar (node_modules/esprima/dist/esprima.js:2285:37)
      at Parser.parseExponentiationExpression (node_modules/esprima/dist/esprima.js:3054:26)
      at Parser.inheritCoverGrammar (node_modules/esprima/dist/esprima.js:2285:37)
      at Parser.parseBinaryExpression (node_modules/esprima/dist/esprima.js:3089:26)
      at Parser.inheritCoverGrammar (node_modules/esprima/dist/esprima.js:2285:37)
      at Parser.parseConditionalExpression (node_modules/esprima/dist/esprima.js:3141:26)
      at Parser.parseAssignmentExpression (node_modules/esprima/dist/esprima.js:3250:26)
      at Parser.isolateCoverGrammar (node_modules/esprima/dist/esprima.js:2269:37)
      at Parser.parseArguments (node_modules/esprima/dist/esprima.js:2807:27)
      at Parser.parseLeftHandSideExpressionAllowCall (node_modules/esprima/dist/esprima.js:2913:76)
      at Parser.inheritCoverGrammar (node_modules/esprima/dist/esprima.js:2285:37)
      at Parser.parseUpdateExpression (node_modules/esprima/dist/esprima.js:3004:26)
      at Parser.parseUnaryExpression (node_modules/esprima/dist/esprima.js:3048:26)
      at Parser.inheritCoverGrammar (node_modules/esprima/dist/esprima.js:2285:37)
      at Parser.parseExponentiationExpression (node_modules/esprima/dist/esprima.js:3054:26)
      at Parser.inheritCoverGrammar (node_modules/esprima/dist/esprima.js:2285:37)
      at Parser.parseBinaryExpression (node_modules/esprima/dist/esprima.js:3089:26)
      at Parser.inheritCoverGrammar (node_modules/esprima/dist/esprima.js:2285:37)
      at Parser.parseConditionalExpression (node_modules/esprima/dist/esprima.js:3141:26)
      at Parser.parseAssignmentExpression (node_modules/esprima/dist/esprima.js:3250:26)
      at Parser.isolateCoverGrammar (node_modules/esprima/dist/esprima.js:2269:37)
      at Parser.parseExpression (node_modules/esprima/dist/esprima.js:3341:26)
      at Parser.parseLabelledStatement (node_modules/esprima/dist/esprima.js:3996:26)
      at Parser.parseStatement (node_modules/esprima/dist/esprima.js:4122:97)
      at Parser.parseStatementListItem (node_modules/esprima/dist/esprima.js:3393:31)
      at Parser.parseModule (node_modules/esprima/dist/esprima.js:4715:29)
      at parse (node_modules/esprima/dist/esprima.js:122:38)
Relevant references

You can see the Spread syntax here.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the object-spread example with Esprima and inspect the parser path named in the stack trace, starting at node_modules/esprima/dist/esprima.js and its object-initializer handling. Done means the example parses successfully and the resulting AST represents the spread property correctly; add or run a regression test if the repository provides one.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.