-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for the duplicate named capturing groups proposal (#14805)
- Loading branch information
1 parent
eec9574
commit 80c6889
Showing
52 changed files
with
286 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
7 changes: 7 additions & 0 deletions
7
...lper-create-regexp-features-plugin/test/fixtures/runtime/conflict-false-true/options.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"plugins": [ | ||
["transform-named-capturing-groups-regex", { "runtime": true }], | ||
["proposal-duplicate-named-capturing-groups-regex", { "runtime": false }] | ||
], | ||
"throws": "The 'runtime' option must be the same for '@babel/plugin-transform-named-capturing-groups-regex' and '@babel/plugin-proposal-duplicate-named-capturing-groups-regex'." | ||
} |
1 change: 1 addition & 0 deletions
1
...-helper-create-regexp-features-plugin/test/fixtures/runtime/conflict-true-false/input.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/(?<year>\d{4})/ |
7 changes: 7 additions & 0 deletions
7
...lper-create-regexp-features-plugin/test/fixtures/runtime/conflict-true-false/options.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"plugins": [ | ||
["transform-named-capturing-groups-regex", { "runtime": false }], | ||
["proposal-duplicate-named-capturing-groups-regex", { "runtime": true }] | ||
], | ||
"throws": "The 'runtime' option must be the same for '@babel/plugin-transform-named-capturing-groups-regex' and '@babel/plugin-proposal-duplicate-named-capturing-groups-regex'." | ||
} |
1 change: 1 addition & 0 deletions
1
...ime/plugin-transform-named-capturing-groups-regex-runtime-false-not-overwritten/input.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/(?<year>\d{4})/ |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
packages/babel-plugin-proposal-duplicate-named-capturing-groups-regex/.npmignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
src | ||
test | ||
*.log |
19 changes: 19 additions & 0 deletions
19
packages/babel-plugin-proposal-duplicate-named-capturing-groups-regex/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# @babel/plugin-proposal-duplicate-named-capturing-groups-regex | ||
|
||
> Compile regular expressions using duplicate named groups to index-based groups. | ||
See our website [@babel/plugin-proposal-duplicate-named-capturing-groups-regex](https://babeljs.io/docs/en/babel-plugin-proposal-duplicate-named-capturing-groups-regex) for more information. | ||
|
||
## Install | ||
|
||
Using npm: | ||
|
||
```sh | ||
npm install --save-dev @babel/plugin-proposal-duplicate-named-capturing-groups-regex | ||
``` | ||
|
||
or using yarn: | ||
|
||
```sh | ||
yarn add @babel/plugin-proposal-duplicate-named-capturing-groups-regex --dev | ||
``` |
52 changes: 52 additions & 0 deletions
52
packages/babel-plugin-proposal-duplicate-named-capturing-groups-regex/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
{ | ||
"name": "@babel/plugin-proposal-duplicate-named-capturing-groups-regex", | ||
"version": "7.18.6", | ||
"description": "Compile regular expressions using duplicate named groups to index-based groups.", | ||
"homepage": "https://babel.dev/docs/en/next/babel-plugin-proposal-duplicate-named-capturing-groups-regex", | ||
"license": "MIT", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"main": "./lib/index.js", | ||
"keywords": [ | ||
"babel-plugin", | ||
"regex", | ||
"regexp", | ||
"regular expressions" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/babel/babel.git", | ||
"directory": "packages/babel-plugin-proposal-duplicate-named-capturing-groups-regex" | ||
}, | ||
"bugs": "https://github.com/babel/babel/issues", | ||
"dependencies": { | ||
"@babel/helper-create-regexp-features-plugin": "workspace:^", | ||
"@babel/helper-plugin-utils": "workspace:^" | ||
}, | ||
"peerDependencies": { | ||
"@babel/core": "^7.0.0" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "workspace:^", | ||
"@babel/helper-plugin-test-runner": "workspace:^", | ||
"core-js": "^3.22.1" | ||
}, | ||
"engines": { | ||
"node": ">=6.9.0" | ||
}, | ||
"author": "The Babel Team (https://babel.dev/team)", | ||
"conditions": { | ||
"USE_ESM": [ | ||
{ | ||
"type": "module" | ||
}, | ||
null | ||
] | ||
}, | ||
"exports": { | ||
".": "./lib/index.js", | ||
"./package.json": "./package.json" | ||
}, | ||
"type": "commonjs" | ||
} |
20 changes: 20 additions & 0 deletions
20
packages/babel-plugin-proposal-duplicate-named-capturing-groups-regex/src/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* eslint-disable @babel/development/plugin-name */ | ||
import { createRegExpFeaturePlugin } from "@babel/helper-create-regexp-features-plugin"; | ||
import { declare } from "@babel/helper-plugin-utils"; | ||
|
||
export interface Options { | ||
runtime?: boolean; | ||
} | ||
|
||
export default declare((api, options: Options) => { | ||
const { runtime } = options; | ||
if (runtime !== undefined && typeof runtime !== "boolean") { | ||
throw new Error("The 'runtime' option must be boolean"); | ||
} | ||
|
||
return createRegExpFeaturePlugin({ | ||
name: "proposal-duplicate-named-capturing-groups-regex", | ||
feature: "duplicateNamedCaptureGroups", | ||
options: { runtime }, | ||
}); | ||
}); |
1 change: 1 addition & 0 deletions
1
...ugin-proposal-duplicate-named-capturing-groups-regex/test/fixtures/runtime/basic/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/(?:(?<year>\d\d\d\d)|(?<year>\d\d))-(?<month>\d\d)/; |
5 changes: 5 additions & 0 deletions
5
...gin-proposal-duplicate-named-capturing-groups-regex/test/fixtures/runtime/basic/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/*#__PURE__*/ | ||
babelHelpers.wrapRegExp(/(?:(\d\d\d\d)|(\d\d))\x2D(\d\d)/, { | ||
year: [1, 2], | ||
month: 3 | ||
}); |
5 changes: 5 additions & 0 deletions
5
...abel-plugin-proposal-duplicate-named-capturing-groups-regex/test/fixtures/runtime/exec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
let regexp = /(?<named>a)|(?<named>b)|c/; | ||
|
||
expect("a".match(regexp).groups).toEqual({ named: "a" }); | ||
expect("b".match(regexp).groups).toEqual({ named: "b" }); | ||
expect("c".match(regexp).groups).toEqual({ named: undefined }); |
3 changes: 3 additions & 0 deletions
3
...plugin-proposal-duplicate-named-capturing-groups-regex/test/fixtures/runtime/options.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"plugins": ["proposal-duplicate-named-capturing-groups-regex"] | ||
} |
1 change: 1 addition & 0 deletions
1
...lugin-proposal-duplicate-named-capturing-groups-regex/test/fixtures/syntax/basic/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/(?:(?<year>\d\d\d\d)|(?<year>\d\d)) is \k<year>/; |
1 change: 1 addition & 0 deletions
1
...ugin-proposal-duplicate-named-capturing-groups-regex/test/fixtures/syntax/basic/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/(?:(\d\d\d\d)|(\d\d)) is \1\2/; |
5 changes: 5 additions & 0 deletions
5
...-plugin-proposal-duplicate-named-capturing-groups-regex/test/fixtures/syntax/options.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"plugins": [ | ||
["proposal-duplicate-named-capturing-groups-regex", { "runtime": false }] | ||
] | ||
} |
1 change: 1 addition & 0 deletions
1
...te-named-capturing-groups-regex/test/fixtures/syntax/unique-name-not-transformed/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/(?<year>\d\d\d\d) is \k<year>/; |
1 change: 1 addition & 0 deletions
1
...e-named-capturing-groups-regex/test/fixtures/syntax/unique-name-not-transformed/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/(?<year>\d\d\d\d) is \k<year>/; |
1 change: 1 addition & 0 deletions
1
...capturing-groups-regex/test/fixtures/syntax/unique-name-with-named-groups-plugin/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/(?<year>\d\d\d\d) is \k<year>/; |
6 changes: 6 additions & 0 deletions
6
...uring-groups-regex/test/fixtures/syntax/unique-name-with-named-groups-plugin/options.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"plugins": [ | ||
["proposal-duplicate-named-capturing-groups-regex", { "runtime": false }], | ||
["transform-named-capturing-groups-regex", { "runtime": false }] | ||
] | ||
} |
1 change: 1 addition & 0 deletions
1
...apturing-groups-regex/test/fixtures/syntax/unique-name-with-named-groups-plugin/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/(\d\d\d\d) is \1/; |
1 change: 1 addition & 0 deletions
1
...ugin-proposal-duplicate-named-capturing-groups-regex/test/fixtures/wrapper/basic/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"foo".match(/(?<double>.)\k<double>/); |
3 changes: 3 additions & 0 deletions
3
...gin-proposal-duplicate-named-capturing-groups-regex/test/fixtures/wrapper/basic/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
"foo".match( /*#__PURE__*/babelHelpers.wrapRegExp(/(.)\1/, { | ||
double: 1 | ||
})); |
1 change: 1 addition & 0 deletions
1
...te-named-capturing-groups-regex/test/fixtures/wrapper/looks-like-a-group-unicode/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/no-groups-\(?<looks-like-a-group>looks\)\u{10000}/u; |
6 changes: 6 additions & 0 deletions
6
...amed-capturing-groups-regex/test/fixtures/wrapper/looks-like-a-group-unicode/options.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"plugins": [ | ||
"transform-named-capturing-groups-regex", | ||
"transform-unicode-regex" | ||
] | ||
} |
1 change: 1 addition & 0 deletions
1
...e-named-capturing-groups-regex/test/fixtures/wrapper/looks-like-a-group-unicode/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/no\x2Dgroups\x2D\(?<looks\x2Dlike\x2Da\x2Dgroup>looks\)(?:\uD800\uDC00)/; |
1 change: 1 addition & 0 deletions
1
...-duplicate-named-capturing-groups-regex/test/fixtures/wrapper/looks-like-a-group/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/no-groups-\(?<looks-like-a-group>looks\)/; |
1 change: 1 addition & 0 deletions
1
...duplicate-named-capturing-groups-regex/test/fixtures/wrapper/looks-like-a-group/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/no\x2Dgroups\x2D\(?<looks\x2Dlike\x2Da\x2Dgroup>looks\)/; |
1 change: 1 addition & 0 deletions
1
...licate-named-capturing-groups-regex/test/fixtures/wrapper/only-when-named-groups/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"foo".match(/(.)\1/); |
1 change: 1 addition & 0 deletions
1
...icate-named-capturing-groups-regex/test/fixtures/wrapper/only-when-named-groups/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"foo".match(/(.)\1/); |
3 changes: 3 additions & 0 deletions
3
...plugin-proposal-duplicate-named-capturing-groups-regex/test/fixtures/wrapper/options.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"plugins": ["transform-named-capturing-groups-regex"] | ||
} |
1 change: 1 addition & 0 deletions
1
...ed-capturing-groups-regex/test/fixtures/wrapper/skips-anonymous-capturing-groups/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"abba".match(/(.)(?<n>.)\k<n>\1/); |
3 changes: 3 additions & 0 deletions
3
...d-capturing-groups-regex/test/fixtures/wrapper/skips-anonymous-capturing-groups/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
"abba".match( /*#__PURE__*/babelHelpers.wrapRegExp(/(.)(.)\2\1/, { | ||
n: 2 | ||
})); |
1 change: 1 addition & 0 deletions
1
...roposal-duplicate-named-capturing-groups-regex/test/fixtures/wrapper/test-method/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/^(?<x>.)\k<x>$/.test("aa"); |
1 change: 1 addition & 0 deletions
1
...oposal-duplicate-named-capturing-groups-regex/test/fixtures/wrapper/test-method/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/^(.)\1$/.test("aa"); |
3 changes: 3 additions & 0 deletions
3
packages/babel-plugin-proposal-duplicate-named-capturing-groups-regex/test/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import runner from "@babel/helper-plugin-test-runner"; | ||
|
||
runner(import.meta.url); |
1 change: 1 addition & 0 deletions
1
packages/babel-plugin-proposal-duplicate-named-capturing-groups-regex/test/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{ "type": "module" } |
Oops, something went wrong.