[babel 8] Replace lodash/escapeRegExp with escape-string-regexp (#12677)

Co-authored-by: James Addison <jay@jp-hosting.net>
This commit is contained in:
Henry Zhu
2021-01-23 16:21:34 -05:00
committed by GitHub
parent 568679e301
commit 464a02ffe1
7 changed files with 41 additions and 4 deletions

View File

@@ -54,6 +54,7 @@
"@babel/types": "workspace:^7.12.10",
"convert-source-map": "^1.7.0",
"debug": "^4.1.0",
"escape-string-regexp": "condition:BABEL_8_BREAKING ? ^4.0.0 : ",
"gensync": "^1.0.0-beta.1",
"json5": "^2.1.2",
"lodash": "^4.17.19",

View File

@@ -1,6 +1,9 @@
// @flow
import path from "path";
import escapeRegExp from "lodash/escapeRegExp";
const escapeRegExp = process.env.BABEL_8_BREAKING
? require("escape-string-regexp")
: require("lodash/escapeRegExp");
const sep = `\\${path.sep}`;
const endSep = `(?:${sep}|$)`;
@@ -39,11 +42,13 @@ export default function pathToPattern(
// *.ext matches a wildcard with an extension.
if (part.indexOf("*.") === 0) {
return (
// $FlowIgnore
substitution + escapeRegExp(part.slice(1)) + (last ? endSep : sep)
);
}
// Otherwise match the pattern text.
// $FlowIgnore
return escapeRegExp(part) + (last ? endSep : sep);
}),
].join(""),