refactor: remove @babel/helper-regex usage (#12349)
This commit is contained in:
parent
6a0e909c13
commit
ab5a90ce47
@ -19,7 +19,6 @@
|
|||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@babel/helper-annotate-as-pure": "workspace:^7.10.4",
|
"@babel/helper-annotate-as-pure": "workspace:^7.10.4",
|
||||||
"@babel/helper-regex": "workspace:^7.10.4",
|
|
||||||
"regexpu-core": "^4.7.1"
|
"regexpu-core": "^4.7.1"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
|
|||||||
@ -10,9 +10,21 @@ import { generateRegexpuOptions } from "./util";
|
|||||||
|
|
||||||
import pkg from "../package.json";
|
import pkg from "../package.json";
|
||||||
import { types as t } from "@babel/core";
|
import { types as t } from "@babel/core";
|
||||||
import { pullFlag } from "@babel/helper-regex";
|
|
||||||
import annotateAsPure from "@babel/helper-annotate-as-pure";
|
import annotateAsPure from "@babel/helper-annotate-as-pure";
|
||||||
|
|
||||||
|
type RegExpFlags = "i" | "g" | "m" | "s" | "u" | "y";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove given flag from given RegExpLiteral node
|
||||||
|
*
|
||||||
|
* @param {RegExpLiteral} node
|
||||||
|
* @param {RegExpFlags} flag
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
|
function pullFlag(node, flag: RegExpFlags): void {
|
||||||
|
node.flags = node.flags.replace(flag, "");
|
||||||
|
}
|
||||||
|
|
||||||
// Note: Versions are represented as an integer. e.g. 7.1.5 is represented
|
// Note: Versions are represented as an integer. e.g. 7.1.5 is represented
|
||||||
// as 70000100005. This method is easier than using a semver-parsing
|
// as 70000100005. This method is easier than using a semver-parsing
|
||||||
// package, but it breaks if we release x.y.z where x, y or z are
|
// package, but it breaks if we release x.y.z where x, y or z are
|
||||||
|
|||||||
@ -16,8 +16,7 @@
|
|||||||
"babel-plugin"
|
"babel-plugin"
|
||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@babel/helper-plugin-utils": "workspace:^7.10.4",
|
"@babel/helper-plugin-utils": "workspace:^7.10.4"
|
||||||
"@babel/helper-regex": "workspace:^7.10.4"
|
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@babel/core": "^7.0.0-0"
|
"@babel/core": "^7.0.0-0"
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
import { declare } from "@babel/helper-plugin-utils";
|
import { declare } from "@babel/helper-plugin-utils";
|
||||||
import * as regex from "@babel/helper-regex";
|
|
||||||
import { types as t } from "@babel/core";
|
import { types as t } from "@babel/core";
|
||||||
|
|
||||||
export default declare(api => {
|
export default declare(api => {
|
||||||
@ -11,7 +10,7 @@ export default declare(api => {
|
|||||||
visitor: {
|
visitor: {
|
||||||
RegExpLiteral(path) {
|
RegExpLiteral(path) {
|
||||||
const { node } = path;
|
const { node } = path;
|
||||||
if (!regex.is(node, "y")) return;
|
if (!node.flags.includes("y")) return;
|
||||||
|
|
||||||
path.replaceWith(
|
path.replaceWith(
|
||||||
t.newExpression(t.identifier("RegExp"), [
|
t.newExpression(t.identifier("RegExp"), [
|
||||||
|
|||||||
@ -409,7 +409,6 @@ __metadata:
|
|||||||
"@babel/core": "workspace:*"
|
"@babel/core": "workspace:*"
|
||||||
"@babel/helper-annotate-as-pure": "workspace:^7.10.4"
|
"@babel/helper-annotate-as-pure": "workspace:^7.10.4"
|
||||||
"@babel/helper-plugin-test-runner": "workspace:*"
|
"@babel/helper-plugin-test-runner": "workspace:*"
|
||||||
"@babel/helper-regex": "workspace:^7.10.4"
|
|
||||||
regexpu-core: ^4.7.1
|
regexpu-core: ^4.7.1
|
||||||
peerDependencies:
|
peerDependencies:
|
||||||
"@babel/core": ^7.0.0
|
"@babel/core": ^7.0.0
|
||||||
@ -646,7 +645,7 @@ __metadata:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
"@babel/helper-regex@workspace:^7.10.4, @babel/helper-regex@workspace:packages/babel-helper-regex":
|
"@babel/helper-regex@workspace:packages/babel-helper-regex":
|
||||||
version: 0.0.0-use.local
|
version: 0.0.0-use.local
|
||||||
resolution: "@babel/helper-regex@workspace:packages/babel-helper-regex"
|
resolution: "@babel/helper-regex@workspace:packages/babel-helper-regex"
|
||||||
dependencies:
|
dependencies:
|
||||||
@ -2748,7 +2747,6 @@ __metadata:
|
|||||||
"@babel/core": "workspace:*"
|
"@babel/core": "workspace:*"
|
||||||
"@babel/helper-plugin-test-runner": "workspace:*"
|
"@babel/helper-plugin-test-runner": "workspace:*"
|
||||||
"@babel/helper-plugin-utils": "workspace:^7.10.4"
|
"@babel/helper-plugin-utils": "workspace:^7.10.4"
|
||||||
"@babel/helper-regex": "workspace:^7.10.4"
|
|
||||||
peerDependencies:
|
peerDependencies:
|
||||||
"@babel/core": ^7.0.0-0
|
"@babel/core": ^7.0.0-0
|
||||||
languageName: unknown
|
languageName: unknown
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user