[parser] Report escapes in kws only if they won't be used as i… (#10455)
We can do it by tokenizing escaped keywords as normal identifiers, so that they won't be accidentally used as real keywords.
This commit is contained in:
@@ -2066,6 +2066,11 @@ export default class ExpressionParser extends LValParser {
|
||||
|
||||
if (this.match(tt.name)) {
|
||||
name = this.state.value;
|
||||
|
||||
// An escaped identifier whose value is the same as a keyword
|
||||
if (!liberal && this.state.containsEsc && isKeyword(name)) {
|
||||
this.raise(this.state.pos, `Escape sequence in keyword ${name}`);
|
||||
}
|
||||
} else if (this.state.type.keyword) {
|
||||
name = this.state.type.keyword;
|
||||
|
||||
|
||||
@@ -1326,11 +1326,7 @@ export default class Tokenizer extends LocationParser {
|
||||
|
||||
readWord(): void {
|
||||
const word = this.readWord1();
|
||||
const type = keywordTypes.get(word) || tt.name;
|
||||
|
||||
if (type.keyword && this.state.containsEsc) {
|
||||
this.raise(this.state.pos, `Escape sequence in keyword ${word}`);
|
||||
}
|
||||
const type = (!this.state.containsEsc && keywordTypes.get(word)) || tt.name;
|
||||
|
||||
// Allow @@iterator and @@asyncIterator as a identifier only inside type
|
||||
if (
|
||||
|
||||
Reference in New Issue
Block a user