Skip to content

Commit

Permalink
fix(parser): fix regexp expression after do-while with semicolon
Browse files Browse the repository at this point in the history
fix for regexp test after do-while with semicolon
  • Loading branch information
3cp committed Nov 24, 2023
2 parents fb53793 + 4b7935c commit 4f3f631
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/parser.ts
Expand Up @@ -1837,7 +1837,7 @@ export function parseDoWhileStatement(
// The previous token is ) and the inserted semicolon would then be parsed as the terminating semicolon of a do-while statement (13.7.2).
// This cannot be implemented in matchOrInsertSemicolon() because it doesn't know
// this RightRaren is the end of a do-while statement.
consumeOpt(parser, context, Token.Semicolon);
consumeOpt(parser, context | Context.AllowRegExp, Token.Semicolon);
return finishNode(parser, context, start, line, column, {
type: 'DoWhileStatement',
body,
Expand Down
49 changes: 49 additions & 0 deletions test/parser/statements/do-while.ts
Expand Up @@ -718,6 +718,55 @@ while(y)
}
]
}
],
[
'do { } while (a); /^.*$/.test(b)',
Context.OptionsWebCompat,
{
type: 'Program',
sourceType: 'script',
body: [
{
type: 'DoWhileStatement',
body: {
type: 'BlockStatement',
body: []
},
test: {
type: 'Identifier',
name: 'a'
}
},
{
type: 'ExpressionStatement',
expression: {
type: 'CallExpression',
callee: {
type: 'MemberExpression',
object: {
type: 'Literal',
value: /^.*$/,
regex: {
pattern: '^.*$',
flags: ''
}
},
computed: false,
property: {
type: 'Identifier',
name: 'test'
}
},
arguments: [
{
type: 'Identifier',
name: 'b'
}
]
}
}
]
}
]
]);
});

0 comments on commit 4f3f631

Please sign in to comment.