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

Named capturing groups cause crashes on the unicode regexp transform #10367

Jessidhia opened this issue Aug 26, 2019 · 2 comments · May be fixed by #10447


Copy link

commented Aug 26, 2019

Bug Report

Current Behavior
Adding the u flag to a regexp with a named capturing group causes babel to crash if any transform related to unicode regexps is also enabled. This happens even when the named capturing group transform is enabled in preset-env, likely due to plugin execution order.

Input Code

void /(?<test>foo)/u

Expected behavior/code

void _wrapRegExp(/(foo)/, {
  test: 1

Babel Configuration (.babelrc, package.json, cli command)

  "presets": [


  • Babel version(s): 7.4.3
  • Node/npm version: 12.6.0
  • OS: macOS 10.14
  • Monorepo: yes
  • How you are using Babel: loader

Possible Solution
The named capturing group transform could run before the other transforms; or regexpu should get support for parsing and preserving named capturing groups

Additional context/Screenshots
While writing a reproduction to this I also found an emit bug when babel helpers are injected and the first statement is a regexp literal. Not related, just a coincidence.


This comment has been minimized.

Copy link
Member Author

commented Aug 26, 2019

Even making the named capture plugin run first doesn't help here; there's something weird with the unicode parsing in regexp-tree as well.

This actual regexp breaks on it: /(?<name>[^+]+?)(?:\..+)?$/u

invalid Unicode escape \.
    at Object.lexRules (.../node_modules/regexp-tree/dist/parser/generated/regexp-tree.js:442:11)
    at Object.getNextToken (.../node_modules/regexp-tree/dist/parser/generated/regexp-tree.js:580:32)
    at Object.parse (.../node_modules/regexp-tree/dist/parser/generated/regexp-tree.js:809:27)
    at Object.regexpTreeParser.parse (.../node_modules/regexp-tree/dist/parser/index.js:22:10)
    at Object.transform (.../node_modules/regexp-tree/dist/transform/index.js:129:20)
    at .../node_modules/regexp-tree/dist/compat-transpiler/index.js:36:27
    at Array.forEach (<anonymous>)
    at Object.transform (.../node_modules/regexp-tree/dist/compat-transpiler/index.js:28:22)
    at Object.compatTranspile (.../node_modules/regexp-tree/dist/regexp-tree.js:148:29)
    at PluginPass.RegExpLiteral (.../node_modules/@babel/plugin-transform-named-capturing-groups-regex/lib/index.js:41:46)

Changing the \.. to \\.. or just .. gets rid of the crash, but it's not the same regexp.


This comment has been minimized.

Copy link

commented Aug 26, 2019

This actual regexp breaks on it: /(?<name>[^+]+?)(?:\..+)?$/u

It is an upstream issue: DmitrySoshnikov/regexp-tree#187

On this issue we should track the plugin ordering in env preset.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
2 participants
You can’t perform that action at this time.