-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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]] Support y
RegExp flag in ES2015 code
#2999
Conversation
}); | ||
} | ||
if (value.indexOf("y") > -1) { | ||
malformedDesc = "Duplicate RegExp flag"; |
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.
Is this necessary? Duplicate flags produce syntax errors
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.
This is a bit tricky. We're maintaining two variables for the flags: a string
named value
and an array named flags
. The flags
array is eventually used
to create a RegExp instance in order to off-load the difficult work of RegExp
validation to whatever engine happens to be running JSHint itself.
If we include the y
flag in this array, then running JSHint with esversion: 6
would produce different results according to whether the current engine
supported "sticky" RegExps. So instead, this patch "skips" the y
flag when it
is encountered.
This could be an invalid transformation for other flags. For example, /{/
is
valid JavaScript but /{/u
is not. Indiscriminately removing u
would
therefor effect parsing correctness.
As far as I know, the only time the y
flag could impact parsing is if it were
duplicated. (Runtime behavior is another matter, of course.) So this patch
explicitly verifies that the flag is not duplicated (using the separate
value
string mentioned earlier) and otherwise parses y
-containing RegExps
as though they did not have the y
flag at all.
@rwaldron This should be good to go. |
Thanks for the explanation! LGTM |
No description provided.