Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Support regexp modifiers proposal (#15226)
Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>
- Loading branch information
1 parent
c292e68
commit 79e1452
Showing
26 changed files
with
182 additions
and
25 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
src | ||
test | ||
*.log |
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-regexp-modifiers | ||
|
||
> Compile regular expressions using duplicate named groups to index-based groups. | ||
See our website [@babel/plugin-proposal-regexp-modifiers](https://babeljs.io/docs/en/babel-plugin-proposal-regexp-modifiers) for more information. | ||
|
||
## Install | ||
|
||
Using npm: | ||
|
||
```sh | ||
npm install --save-dev @babel/plugin-proposal-regexp-modifiers | ||
``` | ||
|
||
or using yarn: | ||
|
||
```sh | ||
yarn add @babel/plugin-proposal-regexp-modifiers --dev | ||
``` |
50 changes: 50 additions & 0 deletions
50
packages/babel-plugin-proposal-regexp-modifiers/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,50 @@ | ||
{ | ||
"name": "@babel/plugin-proposal-regexp-modifiers", | ||
"version": "7.19.1", | ||
"description": "Compile inline regular expression modifiers", | ||
"homepage": "https://babel.dev/docs/en/next/babel-plugin-proposal-regexp-modifiers", | ||
"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-regexp-modifiers" | ||
}, | ||
"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:^" | ||
}, | ||
"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" | ||
} |
12 changes: 12 additions & 0 deletions
12
packages/babel-plugin-proposal-regexp-modifiers/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,12 @@ | ||
/* eslint-disable @babel/development/plugin-name */ | ||
import { createRegExpFeaturePlugin } from "@babel/helper-create-regexp-features-plugin"; | ||
import { declare } from "@babel/helper-plugin-utils"; | ||
|
||
export default declare(api => { | ||
api.assertVersion("^7.19.0"); | ||
|
||
return createRegExpFeaturePlugin({ | ||
name: "proposal-regexp-modifiers", | ||
feature: "modifiers", | ||
}); | ||
}); |
3 changes: 3 additions & 0 deletions
3
packages/babel-plugin-proposal-regexp-modifiers/test/fixtures/syntax/with-u-flag/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,3 @@ | ||
let regex = /(?ims:^[a-z])/u; | ||
|
||
expect(regex.test("\u017F")).toBeTruthy(); |
2 changes: 2 additions & 0 deletions
2
packages/babel-plugin-proposal-regexp-modifiers/test/fixtures/syntax/with-u-flag/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,2 @@ | ||
/(?ims:^[a-z])/u; | ||
/(?-ims:^[a-z].)(^[a-z].)/uims; |
4 changes: 4 additions & 0 deletions
4
...ages/babel-plugin-proposal-regexp-modifiers/test/fixtures/syntax/with-u-flag/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,4 @@ | ||
{ | ||
"plugins": ["proposal-regexp-modifiers", "transform-unicode-regex"], | ||
"minNodeVersion": "8.0.0" | ||
} |
2 changes: 2 additions & 0 deletions
2
packages/babel-plugin-proposal-regexp-modifiers/test/fixtures/syntax/with-u-flag/output.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
11 changes: 11 additions & 0 deletions
11
...s/babel-plugin-proposal-regexp-modifiers/test/fixtures/syntax/without-u-flag-exec/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,11 @@ | ||
let regex = /(?ims:^[a-z].1$)/ | ||
|
||
expect(regex.test("Ax1")).toBeTruthy(); | ||
expect(regex.test("ax1")).toBeTruthy(); | ||
expect(regex.test("ax2")).toBeFalsy(); | ||
expect(regex.test("1ax1")).toBeFalsy(); | ||
|
||
expect(regex.test("a\r1")).toBeTruthy(); | ||
expect(regex.test("a\r\n1")).toBeFalsy(); | ||
|
||
expect(regex.test("\nax1\n\n\n\n\n\n\n\n\n")).toBeTruthy(); |
4 changes: 4 additions & 0 deletions
4
...el-plugin-proposal-regexp-modifiers/test/fixtures/syntax/without-u-flag-exec/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,4 @@ | ||
{ | ||
"plugins": ["proposal-regexp-modifiers"], | ||
"minNodeVersion": "8.0.0" | ||
} |
2 changes: 2 additions & 0 deletions
2
packages/babel-plugin-proposal-regexp-modifiers/test/fixtures/syntax/without-u-flag/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,2 @@ | ||
/(?ims:^[a-z]1$)/; | ||
/(?-ims:^[a-z].1$)(^[a-z].)/ims; |
3 changes: 3 additions & 0 deletions
3
...s/babel-plugin-proposal-regexp-modifiers/test/fixtures/syntax/without-u-flag/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-regexp-modifiers"] | ||
} |
2 changes: 2 additions & 0 deletions
2
...ages/babel-plugin-proposal-regexp-modifiers/test/fixtures/syntax/without-u-flag/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,2 @@ | ||
/(?:(?:^|(?<=[\n\r\u2028\u2029]))[A-Za-z]1(?:$|(?=[\n\r\u2028\u2029])))/; | ||
/(?:^[a-z].1$)((?:^|(?<=[\n\r\u2028\u2029]))[A-Za-z][\s\S])/; |
3 changes: 3 additions & 0 deletions
3
packages/babel-plugin-proposal-regexp-modifiers/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-regexp-modifiers/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" } |
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
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