Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: replace regexp-tree by regexpu #10430

Merged
merged 4 commits into from Sep 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -11,10 +11,14 @@
"regexp",
"regular expressions"
],
"repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-named-capturing-groups-regex",
"repository": {
"type": "git",
"url": "https://github.com/babel/babel.git",
"directory": "packages/babel-plugin-transform-named-capturing-groups-regex"
},
"bugs": "https://github.com/babel/babel/issues",
"dependencies": {
"regexp-tree": "^0.1.13"
"regexpu-core": "^4.6.0"
},
"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"
}