Skip to content

Commit 6b39baf

Browse files
authored
Remove lodash deps (#13057)
* inline escapeRegExp instead of using any dep * inline camelCase * replace merge with object spread * copy if array instead of using clone * inline isRegExp * review fixes! * remove escape-string-regexp from package.json and in test * add error for field defaults that are not primitives or empty arrays * replace merge with object spread * yarn
1 parent 6ac07a1 commit 6b39baf

17 files changed

Lines changed: 52 additions & 84 deletions

File tree

Gulpfile.mjs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import through from "through2";
88
import chalk from "chalk";
99
import newer from "gulp-newer";
1010
import babel from "gulp-babel";
11-
import camelCase from "lodash/camelCase.js";
1211
import fancyLog from "fancy-log";
1312
import filter from "gulp-filter";
1413
import revertPath from "gulp-revert-path";
@@ -162,7 +161,9 @@ function generateStandalone() {
162161
let allList = "";
163162

164163
for (const plugin of pluginConfig) {
165-
const camelPlugin = camelCase(plugin);
164+
const camelPlugin = plugin.replace(/-[a-z]/g, c =>
165+
c[1].toUpperCase()
166+
);
166167
imports += `import ${camelPlugin} from "@babel/plugin-${plugin}";`;
167168
list += `${camelPlugin},`;
168169
allList += `"${plugin}": ${camelPlugin},`;

lib/third-party-libs.js.flow

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,6 @@ declare module "json5" {
2222
};
2323
}
2424

25-
declare module "lodash/clone" {
26-
declare export default <T>(obj: T) => T;
27-
}
28-
29-
declare module "lodash/merge" {
30-
declare export default <T: Object>(T, Object) => T;
31-
}
32-
33-
declare module "lodash/escapeRegExp" {
34-
declare export default (toEscape?: string) => string;
35-
}
36-
3725
declare module "semver" {
3826
declare class SemVer {
3927
build: Array<string>;

packages/babel-cli/test/index.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ import * as helper from "@babel/helper-fixtures";
33
import rimraf from "rimraf";
44
import { sync as makeDirSync } from "make-dir";
55
import child from "child_process";
6-
import escapeRegExp from "lodash/escapeRegExp";
7-
import merge from "lodash/merge";
86
import path from "path";
97
import fs from "fs";
108
import { fileURLToPath } from "url";
@@ -58,6 +56,10 @@ const saveInFiles = function (files) {
5856
});
5957
};
6058

59+
function escapeRegExp(string) {
60+
return string.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&");
61+
}
62+
6163
const normalizeOutput = function (str, cwd) {
6264
let result = str
6365
.replace(/\(\d+ms\)/g, "(123ms)")
@@ -218,7 +220,7 @@ fs.readdirSync(fixtureLoc).forEach(function (binName) {
218220

219221
const testLoc = path.join(suiteLoc, testName);
220222

221-
const opts = {
223+
let opts = {
222224
args: [],
223225
};
224226

@@ -244,7 +246,7 @@ fs.readdirSync(fixtureLoc).forEach(function (binName) {
244246

245247
delete taskOpts.os;
246248
}
247-
merge(opts, taskOpts);
249+
opts = { args: [], ...taskOpts };
248250
}
249251

250252
["stdout", "stdin", "stderr"].forEach(function (key) {

packages/babel-core/package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,8 @@
5858
"@babel/types": "workspace:^7.13.13",
5959
"convert-source-map": "^1.7.0",
6060
"debug": "^4.1.0",
61-
"escape-string-regexp": "condition:BABEL_8_BREAKING ? ^4.0.0 : ",
6261
"gensync": "^1.0.0-beta.2",
6362
"json5": "^2.1.2",
64-
"lodash": "^4.17.19",
6563
"semver": "condition:BABEL_8_BREAKING ? ^7.3.4 : ^6.3.0",
6664
"source-map": "^0.5.0"
6765
},

packages/babel-core/src/config/helpers/escape-regexp.cjs

Lines changed: 0 additions & 5 deletions
This file was deleted.

packages/babel-core/src/config/pattern-to-regex.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
// @flow
22
import path from "path";
33

4-
// $FlowIgnore
5-
import escapeRegExp from "./helpers/escape-regexp.cjs";
6-
74
const sep = `\\${path.sep}`;
85
const endSep = `(?:${sep}|$)`;
96

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

15+
function escapeRegExp(string) {
16+
return string.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&");
17+
}
18+
1819
/**
1920
* Implement basic pattern matching that will allow users to do the simple
2021
* tests with * and **. If users want full complex pattern matching, then can

packages/babel-core/test/config-chain.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import fs from "fs";
22
import os from "os";
33
import path from "path";
44
import { fileURLToPath } from "url";
5-
import escapeRegExp from "lodash/escapeRegExp";
65
import * as babel from "../lib";
76
import getTargets from "@babel/helper-compilation-targets";
87

@@ -63,6 +62,10 @@ function pairs(items) {
6362
return pairs;
6463
}
6564

65+
function escapeRegExp(string) {
66+
return string.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&");
67+
}
68+
6669
async function getTemp(name) {
6770
const cwd = await pfs.mkdtemp(os.tmpdir() + path.sep + name);
6871
const tmp = name => path.join(cwd, name);

packages/babel-helper-transform-fixture-test-runner/package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
"@babel/core": "workspace:^7.13.10",
2020
"@babel/helper-fixtures": "workspace:^7.13.10",
2121
"babel-check-duplicated-nodes": "^1.0.0",
22-
"escape-string-regexp": "condition:BABEL_8_BREAKING ? ^4.0.0 : ",
23-
"lodash": "^4.17.19",
2422
"quick-lru": "5.1.0",
2523
"regenerator-runtime": "^0.13.7",
2624
"source-map": "^0.5.0"

packages/babel-helper-transform-fixture-test-runner/src/escape-regexp.cjs

Lines changed: 0 additions & 5 deletions
This file was deleted.

packages/babel-helper-transform-fixture-test-runner/src/index.ts

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,11 @@ import {
88
import sourceMap from "source-map";
99
import { codeFrameColumns } from "@babel/code-frame";
1010
import * as helpers from "./helpers";
11-
import merge from "lodash/merge";
1211
import assert from "assert";
1312
import fs from "fs";
1413
import path from "path";
1514
import vm from "vm";
1615
import QuickLRU from "quick-lru";
17-
// @ts-ignore
18-
import escapeRegExp from "./escape-regexp.cjs";
1916
import { fileURLToPath } from "url";
2017

2118
import { createRequire } from "module";
@@ -202,19 +199,17 @@ function run(task) {
202199

203200
// todo(flow->ts) add proper return type (added any, because empty object is inferred)
204201
function getOpts(self): any {
205-
const newOpts = merge(
206-
{
207-
ast: true,
208-
cwd: path.dirname(self.loc),
209-
filename: self.loc,
210-
filenameRelative: self.filename,
211-
sourceFileName: self.filename,
212-
sourceType: "script",
213-
babelrc: false,
214-
inputSourceMap: task.inputSourceMap || undefined,
215-
},
216-
opts,
217-
);
202+
const newOpts = {
203+
ast: true,
204+
cwd: path.dirname(self.loc),
205+
filename: self.loc,
206+
filenameRelative: self.filename,
207+
sourceFileName: self.filename,
208+
sourceType: "script",
209+
babelrc: false,
210+
inputSourceMap: task.inputSourceMap || undefined,
211+
...opts,
212+
};
218213

219214
return resolveOptionPluginOrPreset(newOpts, optionsDir);
220215
}
@@ -345,6 +340,10 @@ function validateFile(actualCode, expectedLoc, expectedCode) {
345340
}
346341
}
347342

343+
function escapeRegExp(string) {
344+
return string.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&");
345+
}
346+
348347
function normalizeOutput(code, normalizePathSeparator?) {
349348
const projectRoot = path.resolve(
350349
path.dirname(fileURLToPath(import.meta.url)),

0 commit comments

Comments
 (0)