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

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

Open
ashwinbaliga opened this issue Nov 26, 2024 · 0 comments
Open

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

ashwinbaliga opened this issue Nov 26, 2024 · 0 comments

Comments

@ashwinbaliga
Copy link

ashwinbaliga commented Nov 26, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant