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.
The named capturing group transform could run before the other transforms; or regexpu should get support for parsing and preserving named capturing groups
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.
The text was updated successfully, but these errors were encountered:
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 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.