Remove some lodash/cloneDeep calls (#13032)

This commit is contained in:
Justin Ridgewell 2021-03-25 13:01:19 -04:00 committed by GitHub
parent 0233e3c8eb
commit 73dcd06293
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 35 additions and 15 deletions

View File

@ -43,7 +43,8 @@
"./lib/transform-file.js": "./lib/transform-file-browser.js", "./lib/transform-file.js": "./lib/transform-file-browser.js",
"./src/config/files/index.js": "./src/config/files/index-browser.js", "./src/config/files/index.js": "./src/config/files/index-browser.js",
"./src/config/resolve-targets.js": "./src/config/resolve-targets-browser.js", "./src/config/resolve-targets.js": "./src/config/resolve-targets-browser.js",
"./src/transform-file.js": "./src/transform-file-browser.js" "./src/transform-file.js": "./src/transform-file-browser.js",
"./src/transformation/util/clone-deep.js": "./src/transformation/util/clone-deep-browser.js"
}, },
"dependencies": { "dependencies": {
"@babel/code-frame": "workspace:^7.12.13", "@babel/code-frame": "workspace:^7.12.13",

View File

@ -3,13 +3,13 @@
import fs from "fs"; import fs from "fs";
import path from "path"; import path from "path";
import buildDebug from "debug"; import buildDebug from "debug";
import cloneDeep from "lodash/cloneDeep";
import type { Handler } from "gensync"; import type { Handler } from "gensync";
import * as t from "@babel/types"; import * as t from "@babel/types";
import type { PluginPasses } from "../config"; import type { PluginPasses } from "../config";
import convertSourceMap, { typeof Converter } from "convert-source-map"; import convertSourceMap, { typeof Converter } from "convert-source-map";
import File from "./file/file"; import File from "./file/file";
import parser from "../parser"; import parser from "../parser";
import cloneDeep from "./util/clone-deep";
const debug = buildDebug("babel:transform:file"); const debug = buildDebug("babel:transform:file");
const LARGE_INPUT_SOURCEMAP_THRESHOLD = 1_000_000; const LARGE_INPUT_SOURCEMAP_THRESHOLD = 1_000_000;
@ -35,8 +35,7 @@ export default function* normalizeFile(
throw new Error("AST root must be a Program or File node"); throw new Error("AST root must be a Program or File node");
} }
const { cloneInputAst } = options; if (options.cloneInputAst) {
if (cloneInputAst) {
ast = cloneDeep(ast); ast = cloneDeep(ast);
} }
} else { } else {

View File

@ -0,0 +1,19 @@
const serialized = "$$ babel internal serialized type" + Math.random();
function serialize(key, value) {
if (typeof value !== "bigint") return value;
return {
[serialized]: "BigInt",
value: value.toString(),
};
}
function revive(key, value) {
if (!value || typeof value !== "object") return value;
if (value[serialized] !== "BigInt") return value;
return BigInt(value.value);
}
export default function (value) {
return JSON.parse(JSON.stringify(value, serialize), revive);
}

View File

@ -0,0 +1,9 @@
import v8 from "v8";
import cloneDeep from "./clone-deep-browser";
export default function (value) {
if (v8.deserialize && v8.serialize) {
return v8.deserialize(v8.serialize(value));
}
return cloneDeep(value);
}

View File

@ -15,11 +15,9 @@
"homepage": "https://babel.dev/docs/en/next/babel-helper-fixtures", "homepage": "https://babel.dev/docs/en/next/babel-helper-fixtures",
"main": "lib/index.js", "main": "lib/index.js",
"dependencies": { "dependencies": {
"lodash": "^4.17.19",
"semver": "condition:BABEL_8_BREAKING ? ^7.3.4 : ^6.3.0" "semver": "condition:BABEL_8_BREAKING ? ^7.3.4 : ^6.3.0"
}, },
"devDependencies": { "devDependencies": {
"@types/lodash": "^4.14.150",
"@types/semver": "^7.3.4" "@types/semver": "^7.3.4"
} }
} }

View File

@ -1,4 +1,3 @@
import cloneDeep from "lodash/cloneDeep";
import semver from "semver"; import semver from "semver";
import path from "path"; import path from "path";
import fs from "fs"; import fs from "fs";
@ -121,7 +120,7 @@ function pushTask(taskName, taskDir, suite, suiteName) {
execLocAlias = suiteName + "/" + taskName; execLocAlias = suiteName + "/" + taskName;
} }
const taskOpts = cloneDeep(suite.options); const taskOpts = JSON.parse(JSON.stringify(suite.options));
const taskOptsLoc = tryResolve(taskDir + "/options"); const taskOptsLoc = tryResolve(taskDir + "/options");
if (taskOptsLoc) Object.assign(taskOpts, require(taskOptsLoc)); if (taskOptsLoc) Object.assign(taskOpts, require(taskOptsLoc));

View File

@ -23,8 +23,7 @@
"@babel/parser": "workspace:^7.13.0", "@babel/parser": "workspace:^7.13.0",
"@babel/types": "workspace:^7.13.0", "@babel/types": "workspace:^7.13.0",
"debug": "^4.1.0", "debug": "^4.1.0",
"globals": "condition:BABEL_8_BREAKING ? ^13.5.0 : ^11.1.0", "globals": "condition:BABEL_8_BREAKING ? ^13.5.0 : ^11.1.0"
"lodash": "^4.17.19"
}, },
"devDependencies": { "devDependencies": {
"@babel/helper-plugin-test-runner": "workspace:*" "@babel/helper-plugin-test-runner": "workspace:*"

View File

@ -1,4 +1,3 @@
import cloneDeep from "lodash/cloneDeep";
import traverse from "../lib"; import traverse from "../lib";
import { parse } from "@babel/parser"; import { parse } from "@babel/parser";
import * as t from "@babel/types"; import * as t from "@babel/types";
@ -17,7 +16,7 @@ describe("traverse", function () {
type: "StringLiteral", type: "StringLiteral",
value: "foo", value: "foo",
}; };
const ast2 = cloneDeep(program); const ast2 = JSON.parse(JSON.stringify(program));
traverse(ast2, { traverse(ast2, {
enter: function (path) { enter: function (path) {

View File

@ -542,9 +542,7 @@ __metadata:
version: 0.0.0-use.local version: 0.0.0-use.local
resolution: "@babel/helper-fixtures@workspace:packages/babel-helper-fixtures" resolution: "@babel/helper-fixtures@workspace:packages/babel-helper-fixtures"
dependencies: dependencies:
"@types/lodash": ^4.14.150
"@types/semver": ^7.3.4 "@types/semver": ^7.3.4
lodash: ^4.17.19
semver: "condition:BABEL_8_BREAKING ? ^7.3.4 : ^6.3.0" semver: "condition:BABEL_8_BREAKING ? ^7.3.4 : ^6.3.0"
languageName: unknown languageName: unknown
linkType: soft linkType: soft
@ -3470,7 +3468,6 @@ __metadata:
"@babel/types": "workspace:^7.13.0" "@babel/types": "workspace:^7.13.0"
debug: ^4.1.0 debug: ^4.1.0
globals: "condition:BABEL_8_BREAKING ? ^13.5.0 : ^11.1.0" globals: "condition:BABEL_8_BREAKING ? ^13.5.0 : ^11.1.0"
lodash: ^4.17.19
languageName: unknown languageName: unknown
linkType: soft linkType: soft