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: inline @babel/helper-regex usage #12349

Merged
merged 1 commit into from Nov 18, 2020
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 @@ -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 @@ -644,7 +643,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 @@ -2746,7 +2745,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