Skip to content

Commit

Permalink
fix: use null as regex value in environment missing flag "d" support
Browse files Browse the repository at this point in the history
  • Loading branch information
3cp committed May 5, 2022
1 parent b98e3bd commit b174ae6
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/lexer/regexp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,15 @@ export function scanRegularExpression(parser: ParserState, context: Context): To
*/
function validate(parser: ParserState, pattern: string, flags: string): RegExp | null | Token {
try {
// Temporarily allows older version of Nodejs (or browser) to accept the new Indices flag "d".
flags = flags.replace('d', '');
return new RegExp(pattern, flags);
} catch (e) {
report(parser, Errors.UnterminatedRegExp);
try {
// Some JavaScript engine has not supported flag "d".
new RegExp(pattern, flags.replace('d', ''));
// Use null as tokenValue according to ESTree spec
return null;
} catch (e) {
report(parser, Errors.UnterminatedRegExp);
}
}
}

0 comments on commit b174ae6

Please sign in to comment.