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

fix(lexer): fix wrong error when using regex flag s together with m or y #211

Merged
merged 1 commit into from Mar 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/lexer/regexp.ts
Expand Up @@ -59,13 +59,13 @@ export function scanRegularExpression(parser: ParserState, context: Context): To
const bodyEnd = parser.index - 1;

const enum RegexFlags {
Empty = 0b00000,
IgnoreCase = 0b00001,
Global = 0b00010,
Multiline = 0b00100,
Unicode = 0b10000,
Sticky = 0b01000,
DotAll = 0b1100
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got no idea why the previous bit-mask for DotAll 0b1100 is an union of Sticky 0b01000 and Multiline 0b00100.
It doesn't make any sense.

Empty = 0b000000,
IgnoreCase = 0b000001,
Global = 0b000010,
Multiline = 0b000100,
Unicode = 0b010000,
Sticky = 0b001000,
DotAll = 0b100000
}

let mask = RegexFlags.Empty;
Expand Down
7 changes: 7 additions & 0 deletions test/lexer/regexp.ts
Expand Up @@ -133,6 +133,13 @@ describe('Lexer - Regular expressions', () => {
[Context.AllowRegExp, '/a(?!b(?!c)d)e/', 'a(?!b(?!c)d)e', ''],
[Context.AllowRegExp, '/[^a-z]{4}/', '[^a-z]{4}', ''],
[Context.AllowRegExp, '/1?1/mig', '1?1', 'mig'],
[Context.AllowRegExp, '/.*/sm', '.*', 'sm'],
[Context.AllowRegExp, '/.*/ms', '.*', 'ms'],
[Context.AllowRegExp, '/.*/sy', '.*', 'sy'],
[Context.AllowRegExp, '/.*/ys', '.*', 'ys'],
[Context.AllowRegExp, '/.*/s', '.*', 's'],
[Context.AllowRegExp, '/.*/m', '.*', 'm'],
[Context.AllowRegExp, '/.*/y', '.*', 'y'],
[Context.AllowRegExp, '/\\%([0-9]*)\\[(\\^)?(\\]?[^\\]]*)\\]/', '\\%([0-9]*)\\[(\\^)?(\\]?[^\\]]*)\\]', '']
];

Expand Down