Skip to content

Commit

Permalink
refactor: replace regexp-tree by regexpu
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed Sep 11, 2019
1 parent 1b352ca commit a17778b
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 15 deletions.
Expand Up @@ -14,7 +14,7 @@
"repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-named-capturing-groups-regex",
"bugs": "https://github.com/babel/babel/issues",
"dependencies": {
"regexp-tree": "^0.1.13"
"regexpu-core": "^4.5.4"
},
"peerDependencies": {
"@babel/core": "^7.0.0"
Expand Down
@@ -1,4 +1,4 @@
import regexpTree from "regexp-tree";
import rewritePattern from "regexpu-core";

export default function({ types: t }, options) {
const { runtime = true } = options;
Expand All @@ -19,16 +19,18 @@ export default function({ types: t }, options) {
return;
}

const result = regexpTree.compatTranspile(node.extra.raw, [
"namedCapturingGroups",
]);
const { namedCapturingGroups } = result.getExtra();
const namedCapturingGroups = {};
const result = rewritePattern(node.pattern, node.flags, {
namedGroup: true,
//todo: consider refactor `lookbehind` true as modular plugin
lookbehind: true,
onNamedGroup(name, index) {
namedCapturingGroups[name] = index;
},
});

if (
namedCapturingGroups &&
Object.keys(namedCapturingGroups).length > 0
) {
node.pattern = result.getSource();
if (Object.keys(namedCapturingGroups).length > 0) {
node.pattern = result;

if (runtime && !isRegExpTest(path)) {
path.replaceWith(
Expand Down
@@ -1,3 +1,3 @@
{
"throws": "invalid group Unicode name \"\\u{41}\", use `u` flag."
"throws": "Invalid escape sequence at position 3"
}
@@ -1,3 +1,3 @@
"foo".match(babelHelpers.wrapRegExp(/(.)\1/, {
"foo".match(babelHelpers.wrapRegExp(/([\0-\t\x0B\f\x0E-\u2027\u202A-\uFFFF])\1/, {
double: 1
}));
@@ -1,3 +1,3 @@
"abba".match(babelHelpers.wrapRegExp(/(.)(.)\2\1/, {
"abba".match(babelHelpers.wrapRegExp(/([\0-\t\x0B\f\x0E-\u2027\u202A-\uFFFF])([\0-\t\x0B\f\x0E-\u2027\u202A-\uFFFF])\2\1/, {
n: 2
}));
@@ -1 +1 @@
/^(.)\1$/.test("aa");
/^([\0-\t\x0B\f\x0E-\u2027\u202A-\uFFFF])\1$/.test("aa");

0 comments on commit a17778b

Please sign in to comment.