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
This commit is contained in:
parent
6ac07a1647
commit
6b39bafab6
@ -8,7 +8,6 @@ import through from "through2";
|
||||
import chalk from "chalk";
|
||||
import newer from "gulp-newer";
|
||||
import babel from "gulp-babel";
|
||||
import camelCase from "lodash/camelCase.js";
|
||||
import fancyLog from "fancy-log";
|
||||
import filter from "gulp-filter";
|
||||
import revertPath from "gulp-revert-path";
|
||||
@ -162,7 +161,9 @@ function generateStandalone() {
|
||||
let allList = "";
|
||||
|
||||
for (const plugin of pluginConfig) {
|
||||
const camelPlugin = camelCase(plugin);
|
||||
const camelPlugin = plugin.replace(/-[a-z]/g, c =>
|
||||
c[1].toUpperCase()
|
||||
);
|
||||
imports += `import ${camelPlugin} from "@babel/plugin-${plugin}";`;
|
||||
list += `${camelPlugin},`;
|
||||
allList += `"${plugin}": ${camelPlugin},`;
|
||||
|
||||
@ -22,18 +22,6 @@ declare module "json5" {
|
||||
};
|
||||
}
|
||||
|
||||
declare module "lodash/clone" {
|
||||
declare export default <T>(obj: T) => T;
|
||||
}
|
||||
|
||||
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>;
|
||||
|
||||
@ -3,8 +3,6 @@ import * as helper from "@babel/helper-fixtures";
|
||||
import rimraf from "rimraf";
|
||||
import { sync as makeDirSync } from "make-dir";
|
||||
import child from "child_process";
|
||||
import escapeRegExp from "lodash/escapeRegExp";
|
||||
import merge from "lodash/merge";
|
||||
import path from "path";
|
||||
import fs from "fs";
|
||||
import { fileURLToPath } from "url";
|
||||
@ -58,6 +56,10 @@ const saveInFiles = function (files) {
|
||||
});
|
||||
};
|
||||
|
||||
function escapeRegExp(string) {
|
||||
return string.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&");
|
||||
}
|
||||
|
||||
const normalizeOutput = function (str, cwd) {
|
||||
let result = str
|
||||
.replace(/\(\d+ms\)/g, "(123ms)")
|
||||
@ -218,7 +220,7 @@ fs.readdirSync(fixtureLoc).forEach(function (binName) {
|
||||
|
||||
const testLoc = path.join(suiteLoc, testName);
|
||||
|
||||
const opts = {
|
||||
let opts = {
|
||||
args: [],
|
||||
};
|
||||
|
||||
@ -244,7 +246,7 @@ fs.readdirSync(fixtureLoc).forEach(function (binName) {
|
||||
|
||||
delete taskOpts.os;
|
||||
}
|
||||
merge(opts, taskOpts);
|
||||
opts = { args: [], ...taskOpts };
|
||||
}
|
||||
|
||||
["stdout", "stdin", "stderr"].forEach(function (key) {
|
||||
|
||||
@ -58,10 +58,8 @@
|
||||
"@babel/types": "workspace:^7.13.13",
|
||||
"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.2",
|
||||
"json5": "^2.1.2",
|
||||
"lodash": "^4.17.19",
|
||||
"semver": "condition:BABEL_8_BREAKING ? ^7.3.4 : ^6.3.0",
|
||||
"source-map": "^0.5.0"
|
||||
},
|
||||
|
||||
@ -1,5 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
module.exports = process.env.BABEL_8_BREAKING
|
||||
? require("escape-string-regexp")
|
||||
: require("lodash/escapeRegExp");
|
||||
@ -1,9 +1,6 @@
|
||||
// @flow
|
||||
import path from "path";
|
||||
|
||||
// $FlowIgnore
|
||||
import escapeRegExp from "./helpers/escape-regexp.cjs";
|
||||
|
||||
const sep = `\\${path.sep}`;
|
||||
const endSep = `(?:${sep}|$)`;
|
||||
|
||||
@ -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
|
||||
|
||||
@ -2,7 +2,6 @@ import fs from "fs";
|
||||
import os from "os";
|
||||
import path from "path";
|
||||
import { fileURLToPath } from "url";
|
||||
import escapeRegExp from "lodash/escapeRegExp";
|
||||
import * as babel from "../lib";
|
||||
import getTargets from "@babel/helper-compilation-targets";
|
||||
|
||||
@ -63,6 +62,10 @@ function pairs(items) {
|
||||
return pairs;
|
||||
}
|
||||
|
||||
function escapeRegExp(string) {
|
||||
return string.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&");
|
||||
}
|
||||
|
||||
async function getTemp(name) {
|
||||
const cwd = await pfs.mkdtemp(os.tmpdir() + path.sep + name);
|
||||
const tmp = name => path.join(cwd, name);
|
||||
|
||||
@ -19,8 +19,6 @@
|
||||
"@babel/core": "workspace:^7.13.10",
|
||||
"@babel/helper-fixtures": "workspace:^7.13.10",
|
||||
"babel-check-duplicated-nodes": "^1.0.0",
|
||||
"escape-string-regexp": "condition:BABEL_8_BREAKING ? ^4.0.0 : ",
|
||||
"lodash": "^4.17.19",
|
||||
"quick-lru": "5.1.0",
|
||||
"regenerator-runtime": "^0.13.7",
|
||||
"source-map": "^0.5.0"
|
||||
|
||||
@ -1,5 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
module.exports = process.env.BABEL_8_BREAKING
|
||||
? require("escape-string-regexp")
|
||||
: require("lodash/escapeRegExp");
|
||||
@ -8,14 +8,11 @@ import {
|
||||
import sourceMap from "source-map";
|
||||
import { codeFrameColumns } from "@babel/code-frame";
|
||||
import * as helpers from "./helpers";
|
||||
import merge from "lodash/merge";
|
||||
import assert from "assert";
|
||||
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";
|
||||
@ -202,19 +199,17 @@ function run(task) {
|
||||
|
||||
// todo(flow->ts) add proper return type (added any, because empty object is inferred)
|
||||
function getOpts(self): any {
|
||||
const newOpts = merge(
|
||||
{
|
||||
ast: true,
|
||||
cwd: path.dirname(self.loc),
|
||||
filename: self.loc,
|
||||
filenameRelative: self.filename,
|
||||
sourceFileName: self.filename,
|
||||
sourceType: "script",
|
||||
babelrc: false,
|
||||
inputSourceMap: task.inputSourceMap || undefined,
|
||||
},
|
||||
opts,
|
||||
);
|
||||
const newOpts = {
|
||||
ast: true,
|
||||
cwd: path.dirname(self.loc),
|
||||
filename: self.loc,
|
||||
filenameRelative: self.filename,
|
||||
sourceFileName: self.filename,
|
||||
sourceType: "script",
|
||||
babelrc: false,
|
||||
inputSourceMap: task.inputSourceMap || undefined,
|
||||
...opts,
|
||||
};
|
||||
|
||||
return resolveOptionPluginOrPreset(newOpts, optionsDir);
|
||||
}
|
||||
@ -345,6 +340,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)),
|
||||
|
||||
@ -17,7 +17,6 @@
|
||||
"./lib/nodeWrapper.js": "./lib/browser.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"escape-string-regexp": "condition:BABEL_8_BREAKING ? ^4.0.0 : ",
|
||||
"find-cache-dir": "condition:BABEL_8_BREAKING ? ^3.3.1 : ^2.0.0",
|
||||
"lodash": "^4.17.19",
|
||||
"make-dir": "^2.1.0",
|
||||
|
||||
@ -1,5 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
module.exports = process.env.BABEL_8_BREAKING
|
||||
? require("escape-string-regexp")
|
||||
: require("lodash/escapeRegExp");
|
||||
@ -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 = {};
|
||||
@ -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 = {
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
import loClone from "lodash/clone";
|
||||
import { NODE_FIELDS, BUILDER_KEYS } from "../definitions";
|
||||
import validate from "../validators/validate";
|
||||
import type * as t from "..";
|
||||
@ -23,7 +22,9 @@ export default function builder<T extends t.Node>(
|
||||
|
||||
let arg;
|
||||
if (i < countArgs) arg = args[i];
|
||||
if (arg === undefined) arg = loClone(field.default);
|
||||
if (arg === undefined) {
|
||||
arg = Array.isArray(field.default) ? [] : field.default;
|
||||
}
|
||||
|
||||
node[key] = arg;
|
||||
i++;
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
import isPlainObject from "lodash/isPlainObject";
|
||||
import isRegExp from "lodash/isRegExp";
|
||||
import isValidIdentifier from "../validators/isValidIdentifier";
|
||||
import {
|
||||
identifier,
|
||||
@ -33,6 +32,10 @@ export default valueToNode as {
|
||||
(value: unknown): t.Expression;
|
||||
};
|
||||
|
||||
function isRegExp(value): value is RegExp {
|
||||
return Object.prototype.toString.call(value) === "[object RegExp]";
|
||||
}
|
||||
|
||||
function valueToNode(value: unknown): t.Expression {
|
||||
// undefined
|
||||
if (value === undefined) {
|
||||
|
||||
@ -279,8 +279,16 @@ export default function defineType(
|
||||
const keys = Object.getOwnPropertyNames(inherits.fields);
|
||||
for (const key of keys) {
|
||||
const field = inherits.fields[key];
|
||||
const def = field.default;
|
||||
if (
|
||||
Array.isArray(def) ? def.length > 0 : def && typeof def === "object"
|
||||
) {
|
||||
throw new Error(
|
||||
"field defaults can only be primitives or empty arrays currently",
|
||||
);
|
||||
}
|
||||
fields[key] = {
|
||||
default: field.default,
|
||||
default: Array.isArray(def) ? [] : def,
|
||||
optional: field.optional,
|
||||
validate: field.validate,
|
||||
};
|
||||
|
||||
21
yarn.lock
21
yarn.lock
@ -213,10 +213,8 @@ __metadata:
|
||||
"@babel/types": "workspace:^7.13.13"
|
||||
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.2
|
||||
json5: ^2.1.2
|
||||
lodash: ^4.17.19
|
||||
semver: "condition:BABEL_8_BREAKING ? ^7.3.4 : ^6.3.0"
|
||||
source-map: ^0.5.0
|
||||
languageName: unknown
|
||||
@ -820,8 +818,6 @@ __metadata:
|
||||
"@babel/helper-fixtures": "workspace:^7.13.10"
|
||||
"@types/jest": ^25.2.2
|
||||
babel-check-duplicated-nodes: ^1.0.0
|
||||
escape-string-regexp: "condition:BABEL_8_BREAKING ? ^4.0.0 : "
|
||||
lodash: ^4.17.19
|
||||
quick-lru: 5.1.0
|
||||
regenerator-runtime: ^0.13.7
|
||||
source-map: ^0.5.0
|
||||
@ -3257,7 +3253,6 @@ __metadata:
|
||||
"@babel/core": "workspace:*"
|
||||
"@babel/plugin-transform-modules-commonjs": "workspace:*"
|
||||
browserify: ^16.5.2
|
||||
escape-string-regexp: "condition:BABEL_8_BREAKING ? ^4.0.0 : "
|
||||
find-cache-dir: "condition:BABEL_8_BREAKING ? ^3.3.1 : ^2.0.0"
|
||||
lodash: ^4.17.19
|
||||
make-dir: ^2.1.0
|
||||
@ -7429,22 +7424,6 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"escape-string-regexp-BABEL_8_BREAKING-true@npm:escape-string-regexp@^4.0.0":
|
||||
version: 4.0.0
|
||||
resolution: "escape-string-regexp@npm:4.0.0"
|
||||
checksum: c747be8d5ff7873127e3e0cffe7d2206a37208077fa9c30a3c1bb4f26bebd081c8c24d5fba7a99449f9d20670bea3dc5e1b6098b0f074b099bd38766271a272f
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"escape-string-regexp@condition:BABEL_8_BREAKING ? ^4.0.0 : ":
|
||||
version: 0.0.0-condition-d458a5
|
||||
resolution: "escape-string-regexp@condition:BABEL_8_BREAKING?^4.0.0:#d458a5"
|
||||
dependencies:
|
||||
escape-string-regexp-BABEL_8_BREAKING-true: "npm:escape-string-regexp@^4.0.0"
|
||||
checksum: a67cb3a0fc219d92f2c6f0964e302cc079b0ce38bf2bd19257d26865c600bec42befed4dc88aec2bfbe9e62f757ce4bec80a408937bf48c5c779e13d9b238c01
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"escape-string-regexp@npm:^1.0.2, escape-string-regexp@npm:^1.0.5":
|
||||
version: 1.0.5
|
||||
resolution: "escape-string-regexp@npm:1.0.5"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user