mirror of
https://github.com/hanzoai/babel.git
synced 2026-09-24 16:56:45 +00:00
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.
16 lines
315 B
JavaScript
16 lines
315 B
JavaScript
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],
|
|
});
|