Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle multiple named groups in wrapRegExp replace() (#15090)
Previously, the [Symbol.replace] implementation in BabelRegExp assumed that the groups object property values were only numbers. With the duplicate named capturing groups plugin, they can be arrays of numbers as well. In the case of a duplicate named capturing group, the replacement pattern $<name> can be replaced by the concatenation of the pattern indices that have that name: e.g., $1$2.
- Loading branch information
Showing
3 changed files
with
8 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
...l-plugin-proposal-duplicate-named-capturing-groups-regex/test/fixtures/runtime/replace.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".replace(regexp, "[$<named>]")).toEqual("[a]"); | ||
expect("b".replace(regexp, "[$<named>]")).toEqual("[b]"); | ||
expect("c".replace(regexp, "[$<named>]")).toEqual("[]"); |