From 4b7935cd4b4823213b3e22e7598b6c14d309ab05 Mon Sep 17 00:00:00 2001 From: Laura van Luyn Date: Fri, 24 Nov 2023 10:43:08 +0100 Subject: [PATCH] fix for regexp test after do-while with semicolon --- src/parser.ts | 2 +- test/parser/statements/do-while.ts | 49 ++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/src/parser.ts b/src/parser.ts index 0a693b78..fee4d952 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -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, diff --git a/test/parser/statements/do-while.ts b/test/parser/statements/do-while.ts index 7d233655..eda9fbe5 100644 --- a/test/parser/statements/do-while.ts +++ b/test/parser/statements/do-while.ts @@ -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' + } + ] + } + } + ] + } ] ]); });