Skip to content

Commit

Permalink
Fix infinite loop when parsing semicolon in ClassElement.
Browse files Browse the repository at this point in the history
Summary:
The `parseClassBody` loop was not calling `advance()` properly when
seeing a `;` as a ClassElement, so add that call.

Reviewed By: dulinriley

Differential Revision: D16341340

fbshipit-source-id: 282a9b8830db0d541c7d2e72dcb09d9a1cd7186c
  • Loading branch information
avp authored and facebook-github-bot committed Jul 17, 2019
1 parent 69ef0a3 commit f4733a6
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/Parser/JSParserImpl.cpp
Expand Up @@ -2806,6 +2806,7 @@ Optional<ESTree::ClassBodyNode *> JSParserImpl::parseClassBody(SMLoc startLoc) {
bool isStatic = false;
switch (tok_->getKind()) {
case TokenKind::semi:
advance();
break;

case TokenKind::rw_static:
Expand Down
41 changes: 41 additions & 0 deletions test/Parser/es6/class.js
Expand Up @@ -265,6 +265,47 @@
// CHECK-NEXT: "directive": null
// CHECK-NEXT: },

class SemiClass {
;
foo() {}
;
}
// CHECK-NEXT: {
// CHECK-NEXT: "type": "ClassDeclaration",
// CHECK-NEXT: "id": {
// CHECK-NEXT: "type": "Identifier",
// CHECK-NEXT: "name": "SemiClass",
// CHECK-NEXT: "typeAnnotation": null
// CHECK-NEXT: },
// CHECK-NEXT: "superClass": null,
// CHECK-NEXT: "body": {
// CHECK-NEXT: "type": "ClassBody",
// CHECK-NEXT: "body": [
// CHECK-NEXT: {
// CHECK-NEXT: "type": "MethodDefinition",
// CHECK-NEXT: "key": {
// CHECK-NEXT: "type": "Identifier",
// CHECK-NEXT: "name": "foo",
// CHECK-NEXT: "typeAnnotation": null
// CHECK-NEXT: },
// CHECK-NEXT: "value": {
// CHECK-NEXT: "type": "FunctionExpression",
// CHECK-NEXT: "id": null,
// CHECK-NEXT: "params": [],
// CHECK-NEXT: "body": {
// CHECK-NEXT: "type": "BlockStatement",
// CHECK-NEXT: "body": []
// CHECK-NEXT: },
// CHECK-NEXT: "generator": false
// CHECK-NEXT: },
// CHECK-NEXT: "kind": "method",
// CHECK-NEXT: "computed": false,
// CHECK-NEXT: "static": false
// CHECK-NEXT: }
// CHECK-NEXT: ]
// CHECK-NEXT: }
// CHECK-NEXT: },

class DeclClass {
foo() {}
}
Expand Down

0 comments on commit f4733a6

Please sign in to comment.