fix: disallow computed async/get/set keyword (#13531)
This commit is contained in:
parent
bc1b9537b0
commit
bfd2f8f4b1
@ -1442,11 +1442,9 @@ export default class StatementParser extends ExpressionParser {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const containsEsc = this.state.containsEsc;
|
const isContextual = this.match(tt.name) && !this.state.containsEsc;
|
||||||
const isPrivate = this.match(tt.privateName);
|
const isPrivate = this.match(tt.privateName);
|
||||||
const key = this.parseClassElementName(member);
|
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;
|
const maybeQuestionTokenStart = this.state.start;
|
||||||
|
|
||||||
this.parsePostMemberNameModifiers(publicMember);
|
this.parsePostMemberNameModifiers(publicMember);
|
||||||
@ -1491,9 +1489,8 @@ export default class StatementParser extends ExpressionParser {
|
|||||||
this.pushClassProperty(classBody, publicProp);
|
this.pushClassProperty(classBody, publicProp);
|
||||||
}
|
}
|
||||||
} else if (
|
} else if (
|
||||||
isSimple &&
|
isContextual &&
|
||||||
key.name === "async" &&
|
key.name === "async" &&
|
||||||
!containsEsc &&
|
|
||||||
!this.isLineTerminator()
|
!this.isLineTerminator()
|
||||||
) {
|
) {
|
||||||
// an async method
|
// an async method
|
||||||
@ -1532,9 +1529,8 @@ export default class StatementParser extends ExpressionParser {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else if (
|
} else if (
|
||||||
isSimple &&
|
isContextual &&
|
||||||
(key.name === "get" || key.name === "set") &&
|
(key.name === "get" || key.name === "set") &&
|
||||||
!containsEsc &&
|
|
||||||
!(this.match(tt.star) && this.isLineTerminator())
|
!(this.match(tt.star) && this.isLineTerminator())
|
||||||
) {
|
) {
|
||||||
// `get\n*` is an uninitialized property named 'get' followed by a generator.
|
// `get\n*` is an uninitialized property named 'get' followed by a generator.
|
||||||
|
|||||||
@ -0,0 +1,3 @@
|
|||||||
|
class A {
|
||||||
|
[async] a() {}
|
||||||
|
}
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"throws": "Unexpected token (2:10)"
|
||||||
|
}
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
class A {
|
||||||
|
[get] a() {}
|
||||||
|
}
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"throws": "Unexpected token (2:8)"
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user