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

Add docs for duplicated-named-capturing-groups-regex #2674

Merged
merged 2 commits into from Sep 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
74 changes: 74 additions & 0 deletions docs/plugin-proposal-duplicated-named-capturing-groups-regex.md
@@ -0,0 +1,74 @@
---
id: babel-plugin-proposal-duplicated-named-capturing-groups-regex
title: @babel/plugin-proposal-duplicated-named-capturing-groups-regex
sidebar_label: duplicated-named-capturing-groups-regex
---

## Examples

**In**

```javascript
var re = /(?<year>\d{4})-(?<month>\d{2})|(?<month>\d{2})-(?<year>\d{4})/;

console.log(re.exec("02-1999").groups.year);
```

**Out**

```javascript
var re = _wrapRegExp(/(\d{4})-(\d{2})|(\d{2})-(\d{4})/, {
year: [1, 4],
month: [2, 3],
});

console.log(re.exec("02-1999").groups.year);
```

## Installation

```sh
npm install --save-dev @babel/plugin-proposal-duplicated-named-capturing-groups-regex
```

## Usage

### With a configuration file (Recommended)

```json
{
"plugins": ["@babel/plugin-proposal-duplicated-named-capturing-groups-regex"]
}
```

### Via CLI

```sh
babel --plugins @babel/plugin-proposal-duplicated-named-capturing-groups-regex script.js
```

### Via Node API

```javascript
require("@babel/core").transformSync("code", {
plugins: ["@babel/plugin-proposal-duplicated-named-capturing-groups-regex"],
});
```

## Options

### `runtime`

`boolean`, defaults to `true`

When this option is disabled, Babel doesn't wrap RegExps with the `_wrapRegExp` helper.
The output only supports internal group references, and not runtime properties:

```js
var stringRe = /(?:(?<quote>")|(?<quote>')).*?\k<quote>/;

stringRe.test("'foo'"); // "true", works
stringRe.exec("'foo'").groups.quote; // undefined
```

> You can read more about configuring plugin options [here](https://babeljs.io/docs/en/plugins#plugin-options)
1 change: 1 addition & 0 deletions docs/plugins-list.md
Expand Up @@ -10,6 +10,7 @@ sidebar_label: Plugins List

- [decorators](plugin-proposal-decorators.md)
- [do-expressions](plugin-proposal-do-expressions.md)
- [duplicated-named-capturing-groups-regex](plugin-proposal-duplicated-named-capturing-groups-regex.md)
- [export-default-from](plugin-proposal-export-default-from.md)
- [export-namespace-from](plugin-proposal-export-namespace-from.md)
- [function-bind](plugin-proposal-function-bind.md)
Expand Down