mirror of
https://github.com/hanzoai/babel.git
synced 2026-10-30 14:46:06 +00:00
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.
6 lines
216 B
JavaScript
6 lines
216 B
JavaScript
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("[]");
|