fix: transform name capturing regex once (#10395)
* fix: transform name capturing regex once * refactor: early return when pattern contains only lookbehind * chore: simplify test regex * chore: run test on >=8.0.0
This commit is contained in:
parent
29734b924a
commit
2e7bea4a6a
@ -12,7 +12,7 @@ export default function({ types: t }, options) {
|
|||||||
visitor: {
|
visitor: {
|
||||||
RegExpLiteral(path) {
|
RegExpLiteral(path) {
|
||||||
const node = path.node;
|
const node = path.node;
|
||||||
if (node.pattern.indexOf("(?<") === -1) {
|
if (!/\(\?<(?![=!])/.test(node.pattern)) {
|
||||||
// Return early if there are no named groups.
|
// Return early if there are no named groups.
|
||||||
// The .indexOf check may have false positives (e.g. /\(?</); in
|
// The .indexOf check may have false positives (e.g. /\(?</); in
|
||||||
// this case we parse the regex and regexp-tree won't transform it.
|
// this case we parse the regex and regexp-tree won't transform it.
|
||||||
|
|||||||
@ -0,0 +1,7 @@
|
|||||||
|
const regex = /(?<=a)(?<a>[a])/
|
||||||
|
|
||||||
|
const result = regex.exec("aa");
|
||||||
|
|
||||||
|
expect(result.groups).toEqual({
|
||||||
|
a: "a"
|
||||||
|
});
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"minNodeVersion": "8.0.0"
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user