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

Support class fields #1971

Open
sanderd17 opened this issue May 7, 2019 · 0 comments

Comments

Projects
None yet
1 participant
@sanderd17
Copy link

commented May 7, 2019

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

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