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:
Huáng Jùnliàng 2019-09-05 11:35:57 -04:00 committed by Nicolò Ribaudo
parent 29734b924a
commit 2e7bea4a6a
3 changed files with 11 additions and 1 deletions

View File

@ -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.

View File

@ -0,0 +1,7 @@
const regex = /(?<=a)(?<a>[a])/
const result = regex.exec("aa");
expect(result.groups).toEqual({
a: "a"
});

View File

@ -0,0 +1,3 @@
{
"minNodeVersion": "8.0.0"
}