Skip to content

fix: transform name capturing regex once#10395

Merged
nicolo-ribaudo merged 4 commits intobabel:masterfrom
JLHwung:fix-10393
Sep 5, 2019
Merged

fix: transform name capturing regex once#10395
nicolo-ribaudo merged 4 commits intobabel:masterfrom
JLHwung:fix-10393

Conversation

@JLHwung
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member

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

@JLHwung
Copy link
Copy Markdown
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
@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Dec 10, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Dec 10, 2019
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