-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Contextual keyword tokens being parsed as Keyword
instead of Identifier
#1501
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
Comments
did you mean they should be parsed as keywords? I think currently they are being parsed as an identifier only ! cause in these lines https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/typescript-estree/src/node-utils.ts#L463-L464 , the numbers for contextual keywords comes along token.originalKeywordKind >= SyntaxKind.FirstFutureReservedWord && // 113
token.originalKeywordKind <= SyntaxKind.LastKeyword; // 152 and I think the number range for contextual keyword will be // contextual keywords
token.originalKeywordKind >= SyntaxKind.AbstractKeyword && // 122
token.originalKeywordKind <= SyntaxKind.OfKeyword; // 152 Am I missing something ? |
they are contextual keywords. For example, const of = 1;
// ^^ Identifier
for (const x of y) {}
// ^^ Keyword The parser should pass around the contextual information when constructing the Token so it can determine if the contextual keywords should be a Keyword or Identifier token |
but we cant really do this right ? const await = 1; or as in TS, with types we can evaluate that ? var await: string; // identifier
var await: Promise; // eslint error ? |
Note that types have nothing to do with it - it's purely about the contextual location of the token - where it is syntactically located.
The reason parsers error on it is because you can write some really weird and unpredictable code if it's allowed: const await = 1;
await(await); // what is this supposed to do?!?!?!?!? |
ok. got it. |
I wouldn't worry about fixing it right now. This is very low priority, because there's currently no parsers that get this right.
Most people just use |
Got it . |
I'm going to close this - as much as I would love us to do this we'd be breaking compatibility with other parsers, which could cause unintended rule breakages in the ecosystem for no reason other than "just because it's cleaner". Speaking to other parser owners - they can't do this easily because they don't have contextual information about the tokens when they're being created - which is why they assume |
acornjs/acorn#902
In #1487 we made a change to mark all keywords output as
Keyword
tokens.I've since learned that this was incorrect for some of them.
There are keywords which are classed as "contextual keywords". These keywords are keywords when they're in a their keyword position, and identifiers when they're in an identifier position.
So we need to either:
Identifier
tokens (this is the route that espree/acorn takes)The list of contextual keywords:
https://github.com/microsoft/TypeScript/blob/eeff036519362513cc86a95e260a281a725295f4/src/compiler/types.ts#L255-L285
The text was updated successfully, but these errors were encountered: