Skip to content

Commit

Permalink
fix: transform name capturing regex once (#10395)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
JLHwung authored and nicolo-ribaudo committed Sep 5, 2019
1 parent 29734b9 commit 2e7bea4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
Expand Up @@ -12,7 +12,7 @@ export default function({ types: t }, options) {
visitor: {
RegExpLiteral(path) {
const node = path.node;
if (node.pattern.indexOf("(?<") === -1) {
if (!/\(\?<(?![=!])/.test(node.pattern)) {
// Return early if there are no named groups.
// The .indexOf check may have false positives (e.g. /\(?</); in
// this case we parse the regex and regexp-tree won't transform it.
Expand Down
@@ -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"
}

0 comments on commit 2e7bea4

Please sign in to comment.