refactor: remove @babel/helper-regex usage (#12349)

This commit is contained in:
Huáng Jùnliàng 2020-11-18 10:06:59 -05:00 committed by GitHub
parent 6a0e909c13
commit ab5a90ce47
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 16 additions and 9 deletions

View File

@ -19,7 +19,6 @@
],
"dependencies": {
"@babel/helper-annotate-as-pure": "workspace:^7.10.4",
"@babel/helper-regex": "workspace:^7.10.4",
"regexpu-core": "^4.7.1"
},
"peerDependencies": {

View File

@ -10,9 +10,21 @@ import { generateRegexpuOptions } from "./util";
import pkg from "../package.json";
import { types as t } from "@babel/core";
import { pullFlag } from "@babel/helper-regex";
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
// 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

View File

@ -16,8 +16,7 @@
"babel-plugin"
],
"dependencies": {
"@babel/helper-plugin-utils": "workspace:^7.10.4",
"@babel/helper-regex": "workspace:^7.10.4"
"@babel/helper-plugin-utils": "workspace:^7.10.4"
},
"peerDependencies": {
"@babel/core": "^7.0.0-0"

View File

@ -1,5 +1,4 @@
import { declare } from "@babel/helper-plugin-utils";
import * as regex from "@babel/helper-regex";
import { types as t } from "@babel/core";
export default declare(api => {
@ -11,7 +10,7 @@ export default declare(api => {
visitor: {
RegExpLiteral(path) {
const { node } = path;
if (!regex.is(node, "y")) return;
if (!node.flags.includes("y")) return;
path.replaceWith(
t.newExpression(t.identifier("RegExp"), [

View File

@ -409,7 +409,6 @@ __metadata:
"@babel/core": "workspace:*"
"@babel/helper-annotate-as-pure": "workspace:^7.10.4"
"@babel/helper-plugin-test-runner": "workspace:*"
"@babel/helper-regex": "workspace:^7.10.4"
regexpu-core: ^4.7.1
peerDependencies:
"@babel/core": ^7.0.0
@ -646,7 +645,7 @@ __metadata:
languageName: node
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
resolution: "@babel/helper-regex@workspace:packages/babel-helper-regex"
dependencies:
@ -2748,7 +2747,6 @@ __metadata:
"@babel/core": "workspace:*"
"@babel/helper-plugin-test-runner": "workspace:*"
"@babel/helper-plugin-utils": "workspace:^7.10.4"
"@babel/helper-regex": "workspace:^7.10.4"
peerDependencies:
"@babel/core": ^7.0.0-0
languageName: unknown