fix: disallow computed async/get/set keyword (#13531)

This commit is contained in:
Huáng Jùnliàng 2021-07-06 18:25:57 -04:00 committed by GitHub
parent bc1b9537b0
commit bfd2f8f4b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 15 additions and 7 deletions

View File

@ -1442,11 +1442,9 @@ export default class StatementParser extends ExpressionParser {
return;
}
const containsEsc = this.state.containsEsc;
const isContextual = this.match(tt.name) && !this.state.containsEsc;
const isPrivate = this.match(tt.privateName);
const key = this.parseClassElementName(member);
// Check the key is not a computed expression or string literal.
const isSimple = key.type === "Identifier";
const maybeQuestionTokenStart = this.state.start;
this.parsePostMemberNameModifiers(publicMember);
@ -1491,9 +1489,8 @@ export default class StatementParser extends ExpressionParser {
this.pushClassProperty(classBody, publicProp);
}
} else if (
isSimple &&
isContextual &&
key.name === "async" &&
!containsEsc &&
!this.isLineTerminator()
) {
// an async method
@ -1532,9 +1529,8 @@ export default class StatementParser extends ExpressionParser {
);
}
} else if (
isSimple &&
isContextual &&
(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.

View File

@ -0,0 +1,3 @@
class A {
[async] a() {}
}

View File

@ -0,0 +1,3 @@
{
"throws": "Unexpected token (2:10)"
}

View File

@ -0,0 +1,3 @@
class A {
[get] a() {}
}

View File

@ -0,0 +1,3 @@
{
"throws": "Unexpected token (2:8)"
}