refactor: replace regexp-tree by regexpu (#10430)
This commit is contained in:
parent
0ef4972295
commit
87dc201411
@ -11,10 +11,14 @@
|
|||||||
"regexp",
|
"regexp",
|
||||||
"regular expressions"
|
"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",
|
"bugs": "https://github.com/babel/babel/issues",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"regexp-tree": "^0.1.13"
|
"regexpu-core": "^4.6.0"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@babel/core": "^7.0.0"
|
"@babel/core": "^7.0.0"
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import regexpTree from "regexp-tree";
|
import rewritePattern from "regexpu-core";
|
||||||
|
|
||||||
export default function({ types: t }, options) {
|
export default function({ types: t }, options) {
|
||||||
const { runtime = true } = options;
|
const { runtime = true } = options;
|
||||||
@ -19,16 +19,18 @@ export default function({ types: t }, options) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = regexpTree.compatTranspile(node.extra.raw, [
|
const namedCapturingGroups = {};
|
||||||
"namedCapturingGroups",
|
const result = rewritePattern(node.pattern, node.flags, {
|
||||||
]);
|
namedGroup: true,
|
||||||
const { namedCapturingGroups } = result.getExtra();
|
//todo: consider refactor `lookbehind` true as modular plugin
|
||||||
|
lookbehind: true,
|
||||||
|
onNamedGroup(name, index) {
|
||||||
|
namedCapturingGroups[name] = index;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
if (
|
if (Object.keys(namedCapturingGroups).length > 0) {
|
||||||
namedCapturingGroups &&
|
node.pattern = result;
|
||||||
Object.keys(namedCapturingGroups).length > 0
|
|
||||||
) {
|
|
||||||
node.pattern = result.getSource();
|
|
||||||
|
|
||||||
if (runtime && !isRegExpTest(path)) {
|
if (runtime && !isRegExpTest(path)) {
|
||||||
path.replaceWith(
|
path.replaceWith(
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
{
|
{
|
||||||
"throws": "invalid group Unicode name \"\\u{41}\", use `u` flag."
|
"throws": "Invalid escape sequence at position 3"
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user