Skip to content
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

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 3 additions & 7 deletions packages/babel-parser/src/parser/statement.js
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
@@ -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)"
}