microsoft / microsoft/TypeScript

RegExp named capture groups don't get transpiled

Open
#36,132 1 comment 13 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

In Discussion Suggestion
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

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:
https://github.com/microsoft/TypeScript/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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the TypeScript compiler's handling of regular-expression literals and reproduce the issue in the linked Playground, targeting ES5. Compare the requested behavior with the linked Babel transform and related issue #31241; done means named capture groups are handled correctly for the target, or the issue clearly documents why TypeScript will not transform them.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.