Skip to content

Commit

Permalink
refactor: remove @babel/helper-regex usage (#12349)
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed Nov 18, 2020
1 parent 6a0e909 commit ab5a90c
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 9 deletions.
Expand Up @@ -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": {
Expand Down
14 changes: 13 additions & 1 deletion packages/babel-helper-create-regexp-features-plugin/src/index.js
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions packages/babel-plugin-transform-sticky-regex/package.json
Expand Up @@ -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"
Expand Down
3 changes: 1 addition & 2 deletions packages/babel-plugin-transform-sticky-regex/src/index.js
@@ -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 => {
Expand All @@ -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"), [
Expand Down
4 changes: 1 addition & 3 deletions yarn.lock
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit ab5a90c

Please sign in to comment.