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
feat: Support regexp modifiers proposal #15226
Merged
+182
−25
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
8846944
feat
liuxingbaoyu e496c1a
Apply suggestions from code review
liuxingbaoyu 85f60e8
rebase
liuxingbaoyu d54234a
fix tests
liuxingbaoyu 3b0a584
Update regexpu-core
nicolo-ribaudo 15b6022
`yarn dedupe`
nicolo-ribaudo 6cabb8b
Disable tests on Node.js 6
nicolo-ribaudo 44aa177
Reorganize tests to have at least one running on Node.js 6
nicolo-ribaudo 2a8d361
fix rebase
liuxingbaoyu b9bfc5d
improve type
liuxingbaoyu File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line of code was copied from another plugin, I'm not sure what it does.😞
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This plugin doesn't technically require
@babel/core
7.19.0, but hopefully this will encourage people to upgrade 😉