Skip to content

"async" identifier is wrongly reported as a parsing error #40

@ashwinbaliga

Description

@ashwinbaliga

Steps to reproduce

Call the following API for the given piece of code:
esprima.parseModule(sourceCode, { loc: true, tolerant: true });

class MyClass {
    async;
    foo() {
    }
}

Expected output

The parsing goes through fine

Actual output

Error
description: "Unexpected token ;"
index: 28
lineNumber: 2
column: 10
stack: "Error: Line 2: Unexpected token ;\n    at ErrorHandler.constructError (http://localhost:8000/esprima-next/esprima-next.js:1482:17)
    at ErrorHandler.createError (http://localhost:8000/esprima-next/esprima-next.js:1495:25)
    at Parser.unexpectedTokenError (http://localhost:8000/esprima-next/esprima-next.js:2890:32)
    at Parser.throwUnexpectedToken (http://localhost:8000/esprima-next/esprima-next.js:2899:16)
    at Parser.parseObjectPropertyKey (http://localhost:8000/esprima-next/esprima-next.js:3403:22)
    at Parser.parseClassElement (http://localhost:8000/esprima-next/esprima-next.js:5696:24)
    at Parser.parseClassElementList (http://localhost:8000/esprima-next/esprima-next.js:5797:24)
    at Parser.parseClassBody (http://localhost:8000/esprima-next/esprima-next.js:5805:30)
    at Parser.parseClassDeclaration (http://localhost:8000/esprima-next/esprima-next.js:5821:28)
    at Parser.parseStatementListItem (http://localhost:8000/esprima-next/esprima-next.js:4405:28)"

Relevant references

"async" is a valid identifier. See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar

Some keywords are reserved, meaning that they cannot be used as an identifier for variable declarations, function declarations, etc. They are often called reserved words. A list of these reserved words is provided below. Not all keywords are reserved — for example, async can be used as an identifier anywhere.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions