Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support
indices.groups
when compiling named groups in regexps (#15092)
Add support for indices.groups If a RegExp has the /d flag (hasIndices), match objects should have an extra property .indices with an array of the character indices that each subgroup matched. The indices array itself has a property .groups giving the matched character indices (or undefined) for each named capturing group. This doesn't do anything to enable support for the /d flag, the hasIndices property, or the returned indices object, if the environment does not support it, but it will populate .indices.groups in _wrapRegExp if .indices is present, so that the transform-named-capturing-groups-regex and proposal-duplicate-named-capturing-groups-regex plugins can take advantage of that support if it exists.
- Loading branch information
Showing
6 changed files
with
32 additions
and
2 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
5 changes: 5 additions & 0 deletions
5
...proposal-duplicate-named-capturing-groups-regex/test/fixtures/runtime/has-indices/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/d; | ||
|
||
expect("a".match(regexp).indices.groups).toEqual({ named: [0, 1] }); | ||
expect("b".match(regexp).indices.groups).toEqual({ named: [0, 1] }); | ||
expect("c".match(regexp).indices.groups).toEqual({ named: undefined }); |
3 changes: 3 additions & 0 deletions
3
...sal-duplicate-named-capturing-groups-regex/test/fixtures/runtime/has-indices/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 @@ | ||
{ | ||
"minNodeVersion": "16.0.0" | ||
} |
15 changes: 15 additions & 0 deletions
15
...l-plugin-transform-named-capturing-groups-regex/test/fixtures/runtime/has-indices/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,15 @@ | ||
var re = /(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})/d; | ||
|
||
var result = re.exec("2017-12-23"); | ||
|
||
expect(result.indices.groups).toEqual({ | ||
year: [0, 4], | ||
month: [5, 7], | ||
day: [8, 10], | ||
}); | ||
|
||
expect(result.indices.groups).toEqual({ | ||
year: result.indices[1], | ||
month: result.indices[2], | ||
day: result.indices[3], | ||
}); |
3 changes: 3 additions & 0 deletions
3
...gin-transform-named-capturing-groups-regex/test/fixtures/runtime/has-indices/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 @@ | ||
{ | ||
"minNodeVersion": "16.0.0" | ||
} |