Skip to content

Commit

Permalink
add support for regexp test after do while loop with semicolon
Browse files Browse the repository at this point in the history
  • Loading branch information
Laura van Luyn committed Nov 23, 2023
1 parent f56fd5c commit 702d4d9
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 3 deletions.
2 changes: 1 addition & 1 deletion dist/meriyah.umd.js
Original file line number Diff line number Diff line change
Expand Up @@ -5392,7 +5392,7 @@
consume(parser, context | 32768, 67174411);
const test = parseExpressions(parser, context, 0, 1, parser.tokenPos, parser.linePos, parser.colPos);
consume(parser, context | 32768, 16);
consumeOpt(parser, context, 1074790417);
consumeOpt(parser, context | 32768, 1074790417);
return finishNode(parser, context, start, line, column, {
type: 'DoWhileStatement',
body,
Expand Down
4 changes: 2 additions & 2 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,7 @@ export function parseBlock(

consume(parser, context | Context.AllowRegExp, Token.RightBrace);

const blockNode = <ESTree.BlockStatement> finishNode(parser, context, start, line, column, {
const blockNode = <ESTree.BlockStatement>finishNode(parser, context, start, line, column, {
type: 'BlockStatement',
body
});
Expand Down Expand Up @@ -1882,7 +1882,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
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,55 @@ while(y)
}
]
}
],
[
'do { } while (a); /^.*$/.test("")',
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: 'Literal',
value: ''
}
]
}
}
]
}
]
]);
});

0 comments on commit 702d4d9

Please sign in to comment.