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: transform name capturing regex once #10395

Merged
merged 4 commits into from Sep 5, 2019

Conversation

JLHwung
Copy link
Contributor

@JLHwung JLHwung commented Sep 5, 2019

Q                       A
Fixed Issues? Fixes #10393
Patch: Bug Fix? Yes
Major: Breaking Change?
Minor: New Feature?
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

When runtime && !isRegExpTest(path) is true, a new RegExp node will be inserted to AST and visited later by the transform-named-capturing-groups-regex again. Most of cases when regex consists of only named capturing groups, the transformed regex node will be prevented by indexOf("(?<") early return, however when there is a lookbehind <?=, babylon will recurse infinitely.

Here we revise indexOf("(?<") early return by looking ahead(?< to see if it is a lookbehind pattern.

@JLHwung JLHwung added the PR: Bug Fix 🐛 A type of pull request used for our changelog categories label Sep 5, 2019
@babel-bot
Copy link
Collaborator

babel-bot commented Sep 5, 2019

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/11462/

@nicolo-ribaudo
Copy link
Member

What about using .search(/\?<(?!=/)/) instead of indexOf, to avoid unnecessarily running the regexp transformer?

@JLHwung
Copy link
Contributor Author

JLHwung commented Sep 5, 2019

@nicolo-ribaudo Good idea, I revise your suggested regex to include both positive and negative lookbehind.

@nicolo-ribaudo nicolo-ribaudo merged commit 2e7bea4 into babel:master Sep 5, 2019
@JLHwung JLHwung deleted the fix-10393 branch September 10, 2019 13:39
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue PR: Bug Fix 🐛 A type of pull request used for our changelog categories
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Complex regex causes build to fail
4 participants