jquery / jquery/esprima

Esprima fails to parse classes that have public fields

Open
#2,109 2 comments 0 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

When trying to parse the example code from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes#public_field_declarations Esprima fails with
Error: Line 3: Unexpected token =

var esprima = require('nightly-esprima'); // installed version 2021.8.30

var program = `
class Rectangle {
    height = 0;
    width;
    constructor(height, width) {
      this.height = height;
      this.width = width;
    }
}
`;

esprima.parseScript(program);

tested using Node.js v14.18.1

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

Start by reproducing the failure with the supplied Node.js example and the esprima.parseScript entry point. Trace how class fields such as height = 0 and width are parsed, then add coverage showing that the example parses successfully without the unexpected-token error.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
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.