Files
Philip ChimentoandGitHub 5b176b94f8 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.
2022-10-29 08:32:24 +02:00

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("[]");