Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicate regular expression flag #202

Closed
julianjensen opened this issue Feb 15, 2022 · 3 comments · Fixed by #211
Closed

Duplicate regular expression flag #202

julianjensen opened this issue Feb 15, 2022 · 3 comments · Fixed by #211
Assignees

Comments

@julianjensen
Copy link

julianjensen commented Feb 15, 2022

The parser throws an error when using the s and m flags together in a regular expression. A very simple example that causes the crash is this:

import { parse } from 'meriyah';

parse( String.raw`const done = src.replace( /.*/ms, '' );` );

This is using version 4.2.0 of meriyah. It works fine with either the s or m flag by themselves or in combination with other flags. They just can't both be used at the same time. Using both at the same time is syntactically and semantically legal and, occasionally useful.

Edited to add error message:

file:///home/.../project/node_modules/meriyah/dist/meriyah.esm.js:181
    throw new ParseError(parser.index, parser.line, parser.column, type, ...params);
          ^

ParseError [SyntaxError]: [1:31]: Duplicate regular expression flag 's'
    at report (file:///home/.../project/node_modules/meriyah/dist/meriyah.esm.js:181:11)
    at scanRegularExpression (file:///home/.../project/node_modules/meriyah/dist/meriyah.esm.js:876:21)
    at scanSingleToken (file:///home/.../project/node_modules/meriyah/dist/meriyah.esm.js:1929:36)
    at nextToken (file:///home/.../project/node_modules/meriyah/dist/meriyah.esm.js:1710:20)
    at parseArguments (file:///home/.../project/node_modules/meriyah/dist/meriyah.esm.js:6502:5)
    at parseMemberOrUpdateExpression (file:///home/.../project/node_modules/meriyah/dist/meriyah.esm.js:6167:30)
    at parseMemberOrUpdateExpression (file:///home/.../project/node_modules/meriyah/dist/meriyah.esm.js:6199:16)
    at parseExpression (file:///home/.../project/node_modules/meriyah/dist/meriyah.esm.js:5803:12)
    at parseVariableDeclaration (file:///home/.../project/node_modules/meriyah/dist/meriyah.esm.js:5349:16)
    at parseVariableDeclarationList (file:///home/.../project/node_modules/meriyah/dist/meriyah.esm.js:5333:19) {
  index: 31,
  line: 1,
  column: 31,
  description: "[1:31]: Duplicate regular expression flag 's'",
  loc: { line: 1, column: 31 }
}
@julianjensen
Copy link
Author

julianjensen commented Feb 15, 2022

The problem may arise from the lexer when it scans the regular expression flags. I see this:

      case Chars.LowerS:
        if (mask & RegexFlags.DotAll) report(parser, Errors.DuplicateRegExpFlag, 's');
        mask |= RegexFlags.DotAll;
        break;

There is no RegexFlags entry for the s flag and the DotAll covers the m flag. This would appear to cause an error when the s flag is used with the Multiline or Sticky flags. I think the s needs its own bit flag for this check. In other words, change the DotAll from 0b1100 to 0b100000 which would appear more correct. Maybe this was just a typo?

@3cp
Copy link
Member

3cp commented Mar 18, 2022

Thanks very much for the finding.
I got no idea why it was like that, it doesn't make any sense.

@3cp 3cp closed this as completed in #211 Mar 23, 2022
@3cp
Copy link
Member

3cp commented Mar 31, 2022

Released v4.2.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants