-
Notifications
You must be signed in to change notification settings - Fork 44
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
feat(lexer): support new RegExp Indices flag "d" #217
Conversation
Not behind |
@@ -171,21 +173,19 @@ describe('Lexer - Regular expressions', () => { | |||
t.throws(() => scanSingleToken(state, context, 0)); | |||
}); | |||
} | |||
fail('fails on /i/ii', '/ ', Context.AllowRegExp); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are lots of wrong message in this section. And there are many duplicated tests on /i/yy
and /i/ss
.
I overlooked the validation result is used. parser.tokenValue = validate(parser, pattern, flags); So the tokenValue is wrong for regex with 'd' flag. Not sure what's the best solution. It might need a try catch to fall back to removing "d", so that at least for Nodejs v18, the tokenValue is correct. |
a straightforward way is to do a check in the entry, something like: var isDsupported = true;
try {new Regexp('.', 'd');}catch(e){isDsupported = false;} we may also want to check others like btw, I don't think it's a good resolution to just replace them to '', as they may be misused as normal values. e.g. |
Is this stored as RegExpLiteral value? It should be null per ESTree spec https://github.com/estree/estree/blob/master/es5.md#regexpliteral |
Oh, sorry. I got it now. |
What about try {
return new RegExp(pattern, flags);
} catch (e) {
try {
// Fallback to only validate patterns on systems
// where some flags are not supported.
new RegExp(pattern);
return null;
} catch (e) {
report(parser, Errors.UnterminatedRegExp);
}
} |
it will allow unknown/dulp flags, e.g. |
Validation happens after the duplication check and the unknown check. |
Related to #214