Skip to content

Commit

Permalink
inline escapeRegExp instead of using any dep
Browse files Browse the repository at this point in the history
  • Loading branch information
hzoo committed Mar 26, 2021
1 parent 16d8300 commit 0cad852
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 25 deletions.
4 changes: 0 additions & 4 deletions lib/third-party-libs.js.flow
Expand Up @@ -30,10 +30,6 @@ declare module "lodash/merge" {
declare export default <T: Object>(T, Object) => T;
}

declare module "lodash/escapeRegExp" {
declare export default (toEscape?: string) => string;
}

declare module "semver" {
declare class SemVer {
build: Array<string>;
Expand Down
5 changes: 0 additions & 5 deletions packages/babel-core/src/config/helpers/escape-regexp.cjs

This file was deleted.

7 changes: 4 additions & 3 deletions packages/babel-core/src/config/pattern-to-regex.js
@@ -1,9 +1,6 @@
// @flow
import path from "path";

// $FlowIgnore
import escapeRegExp from "./helpers/escape-regexp.cjs";

const sep = `\\${path.sep}`;
const endSep = `(?:${sep}|$)`;

Expand All @@ -15,6 +12,10 @@ const starPatLast = `(?:${substitution}${endSep})`;
const starStarPat = `${starPat}*?`;
const starStarPatLast = `${starPat}*?${starPatLast}?`;

function escapeRegExp(string) {
return string.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&");
}

/**
* Implement basic pattern matching that will allow users to do the simple
* tests with * and **. If users want full complex pattern matching, then can
Expand Down

This file was deleted.

Expand Up @@ -14,8 +14,6 @@ import fs from "fs";
import path from "path";
import vm from "vm";
import QuickLRU from "quick-lru";
// @ts-ignore
import escapeRegExp from "./escape-regexp.cjs";
import { fileURLToPath } from "url";

import { createRequire } from "module";
Expand Down Expand Up @@ -345,6 +343,10 @@ function validateFile(actualCode, expectedLoc, expectedCode) {
}
}

function escapeRegExp(string) {
return string.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&");
}

function normalizeOutput(code, normalizePathSeparator?) {
const projectRoot = path.resolve(
path.dirname(fileURLToPath(import.meta.url)),
Expand Down
5 changes: 0 additions & 5 deletions packages/babel-register/src/escape-regexp.cjs

This file was deleted.

5 changes: 4 additions & 1 deletion packages/babel-register/src/node.js
Expand Up @@ -7,7 +7,6 @@ import { addHook } from "pirates";
import fs from "fs";
import path from "path";
import Module from "module";
import escapeRegExp from "./escape-regexp.cjs";

const maps = {};
let transformOpts = {};
Expand Down Expand Up @@ -109,6 +108,10 @@ export function revert() {
if (piratesRevert) piratesRevert();
}

function escapeRegExp(string) {
return string.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&");
}

export default function register(opts?: Object = {}) {
// Clone to avoid mutating the arguments object with the 'delete's below.
opts = {
Expand Down

0 comments on commit 0cad852

Please sign in to comment.