Disallow escape sequences in contextual keywords (#9618)

* Disallow escape sequences in async

* Disallow escape sequences in get, set and async in class

* invalid escape tests

* Update whitelist

* tests for async in parens

* Add test for invalid newline between params and arrow

* Move canInsertSemilcolon() into shouldPArseAsyncArrow
This commit is contained in:
Daniel Tschinder
2019-03-05 17:20:36 -08:00
committed by GitHub
parent 349c0d4836
commit 29999007f6
58 changed files with 530 additions and 22 deletions

View File

@@ -1321,6 +1321,7 @@ export default class StatementParser extends ExpressionParser {
return;
}
const containsEsc = this.state.containsEsc;
const key = this.parseClassPropertyName(member);
const isPrivate = key.type === "PrivateName";
// Check the key is not a computed expression or string literal.
@@ -1371,7 +1372,12 @@ export default class StatementParser extends ExpressionParser {
} else {
this.pushClassProperty(classBody, publicProp);
}
} else if (isSimple && key.name === "async" && !this.isLineTerminator()) {
} else if (
isSimple &&
key.name === "async" &&
!containsEsc &&
!this.isLineTerminator()
) {
// an async method
const isGenerator = this.eat(tt.star);
@@ -1407,6 +1413,7 @@ export default class StatementParser extends ExpressionParser {
} else if (
isSimple &&
(key.name === "get" || key.name === "set") &&
!containsEsc &&
!(this.match(tt.star) && this.isLineTerminator())
) {
// `get\n*` is an uninitialized property named 'get' followed by a generator.