Skip to content

RegExp named capture groups don't get transpiled #36132

@cascornelissen

Description

@cascornelissen

TypeScript Version:
3.7.2 (3.7.4 and nightly (3.8.0) as well)

Search Terms:
Named capture groups
Named capturing groups
Regex
ES2018.RegExp

Expected behavior:
The named capture group in the regex gets transpiled to the correct target (es5 in our case). Something like what @babel/plugin-transform-named-capturing-groups-regex does?

Actual behavior:
The named capture group ends up in the compiled code while only Chrome currently supports this.

Related Issues:
#31241

Code

const regex = /^(?<name>[A-Za-z]+)/;
const match = regex.exec('MatchThis-NotThis');
console.log(match);

Live Playground
Here

Additional information
I'm not 100% sure if this is something that TypeScript actually should be doing so if that's not the case I'd like to get some details on how to properly transpile this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    In DiscussionNot yet reached consensusSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions