Skip to content

Commit

Permalink
fix: disallow computed async/get/set keyword (babel#13531)
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung authored and nicolo-ribaudo committed Jul 30, 2021
1 parent 4ef98e4 commit 812140b
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 7 deletions.
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)"
}

0 comments on commit 812140b

Please sign in to comment.