jquery / jquery/esprima

Support class fields

Open
#1,971 3 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

Support for class fields (currently stage-3 proposal) is missing.

The class fields proposal is currently in Stage 3, and has a working implementation in Chrome, as well as being implemented in some other AST parsers (like babel).

I don't know at what stage features are normally added to esprima, but stage 3 looks like a solid stage to me.

Steps to reproduce

Parsing a class with a field just gives an Unexpected token error on the =-sign (expects a function with parentheses).

esprima.parse(`
class MyClass {
    myField = 1;
    #myPrivateField = 2;
}
`)
Expected output

Babel calls it a ClassProperty, with an key and value.

            {
              "type": "ClassProperty",
              "start": 15,
              "end": 28,
              "loc": { ... },
              "computed": false,
              "key": {
                "type": "Identifier",
                "start": 15,
                "end": 22,
                "loc": { ... },
                "name": "myField"
              },
              "static": false,
              "value": {
                "type": "Literal",
                "start": 25,
                "end": 28,
                "loc": { ... },
                "value": "1",
                "rawValue": "1",
                "raw": "'1'"
              }
            },

Private fields (starting wit #) are called a PrivateClassProperty.

Relevant references

https://github.com/tc39/proposal-class-fields

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

The issue provides a JavaScript class-fields example, expected ClassProperty and PrivateClassProperty AST shapes, and a reference to the TC39 proposal, but names no repository files, tests, or entry points. Start by locating the parser and existing class-member AST tests, then compare their conventions with the requested output. Done means the supplied public and private field examples parse into the expected AST structures.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.