Skip to content

Commit

Permalink
fix: fix infinite loop on broken class body
Browse files Browse the repository at this point in the history
closes #143
  • Loading branch information
3cp committed Oct 28, 2020
1 parent ba98f66 commit 22eb9f8
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8166,7 +8166,7 @@ export function parseClassBody(
parser.flags = (parser.flags | Flags.HasConstructor) ^ Flags.HasConstructor;

const body: (ESTree.MethodDefinition | ESTree.FieldDefinition)[] = [];
let decorators: ESTree.Decorator[] = [];
let decorators: ESTree.Decorator[];

while (parser.token !== Token.RightBrace) {
let length = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export const enum Token {
RightBrace = 15 | IsAutoSemicolon | IsClassField, // }
RightParen = 16, // )
Semicolon = 17 | IsAutoSemicolon | IsClassField, // ;
Comma = 18 | IsClassField, // ,
Comma = 18, // ,
LeftBracket = 19 | IsExpressionStart | IsPatternStart | IsMemberOrCallExpression, // [
RightBracket = 20, // ]
Colon = 21, // :
Expand Down
4 changes: 3 additions & 1 deletion test/parser/next/public-fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ describe('Next - Public fields', () => {
[
'class C { #m = function() { return "bar"; }; Child = class extends C { access() { return super.#m; } method() { return super.#m(); } } }',
Context.OptionsWebCompat | Context.OptionsNext
]
],
['class A { a, b }', Context.None],
['class A { a, b }', Context.OptionsNext]
]);

for (const arg of [
Expand Down

0 comments on commit 22eb9f8

Please sign in to comment.