Skip to content

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

@Jessidhia

Description

@Jessidhia

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": [
    "env"
  ]
}

Environment

  • 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Has PRarea: plugin orderingoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions