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]] Support y RegExp flag in ES2015 code #2999

Merged
merged 1 commit into from
Aug 15, 2016

Conversation

jugglinmike
Copy link
Member

No description provided.

@coveralls
Copy link

coveralls commented Aug 3, 2016

Coverage Status

Coverage increased (+0.004%) to 97.677% when pulling 5ecade2 on jugglinmike:2986-regexp-sticky into d800e44 on jshint:master.

});
}
if (value.indexOf("y") > -1) {
malformedDesc = "Duplicate RegExp flag";
Copy link
Member

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

Copy link
Member Author

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.

@jugglinmike
Copy link
Member Author

@rwaldron This should be good to go.

@rwaldron
Copy link
Member

Thanks for the explanation!

LGTM

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 this pull request may close these issues.

None yet

3 participants