grammars-v4 icon indicating copy to clipboard operation
grammars-v4 copied to clipboard

[javascript] `await` should be reserved only inside async functions and modules

Open ris58h opened this issue 2 years ago • 0 comments

Code:

var await;

Error:

line 1:4 mismatched input 'await' expecting {'[', '{', 'as', 'from', 'async', NonStrictLet, Identifier}
line 1:9 mismatched input ';' expecting {RegularExpressionLiteral, '[', '(', '{', '++', '--', '+', '-', '~', '!', 'null', BooleanLiteral, DecimalLiteral, HexIntegerLiteral, OctalIntegerLiteral, OctalIntegerLiteral2, BinaryIntegerLiteral, BigHexIntegerLiteral, BigOctalIntegerLiteral, BigBinaryIntegerLiteral, BigDecimalIntegerLiteral, 'typeof', 'new', 'void', 'function', 'this', 'delete', 'as', 'from', 'class', 'super', 'import', 'async', 'await', 'yield', NonStrictLet, Identifier, StringLiteral, BackTick}

Docs:

https://tc39.es/ecma262/multipage/ecmascript-language-lexical-grammar.html#sec-keywords-and-reserved-words

await is reserved only inside async functions and modules.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#reserved_words

The following are only reserved when they are found in module code or async function bodies: await

ris58h avatar Jun 15 '23 08:06 ris58h