Remove some lodash/cloneDeep calls (#13032)
This commit is contained in:
parent
0233e3c8eb
commit
73dcd06293
@ -43,7 +43,8 @@
|
||||
"./lib/transform-file.js": "./lib/transform-file-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/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": {
|
||||
"@babel/code-frame": "workspace:^7.12.13",
|
||||
|
||||
@ -3,13 +3,13 @@
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
import buildDebug from "debug";
|
||||
import cloneDeep from "lodash/cloneDeep";
|
||||
import type { Handler } from "gensync";
|
||||
import * as t from "@babel/types";
|
||||
import type { PluginPasses } from "../config";
|
||||
import convertSourceMap, { typeof Converter } from "convert-source-map";
|
||||
import File from "./file/file";
|
||||
import parser from "../parser";
|
||||
import cloneDeep from "./util/clone-deep";
|
||||
|
||||
const debug = buildDebug("babel:transform:file");
|
||||
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");
|
||||
}
|
||||
|
||||
const { cloneInputAst } = options;
|
||||
if (cloneInputAst) {
|
||||
if (options.cloneInputAst) {
|
||||
ast = cloneDeep(ast);
|
||||
}
|
||||
} else {
|
||||
|
||||
@ -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);
|
||||
}
|
||||
@ -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);
|
||||
}
|
||||
@ -15,11 +15,9 @@
|
||||
"homepage": "https://babel.dev/docs/en/next/babel-helper-fixtures",
|
||||
"main": "lib/index.js",
|
||||
"dependencies": {
|
||||
"lodash": "^4.17.19",
|
||||
"semver": "condition:BABEL_8_BREAKING ? ^7.3.4 : ^6.3.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/lodash": "^4.14.150",
|
||||
"@types/semver": "^7.3.4"
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
import cloneDeep from "lodash/cloneDeep";
|
||||
import semver from "semver";
|
||||
import path from "path";
|
||||
import fs from "fs";
|
||||
@ -121,7 +120,7 @@ function pushTask(taskName, taskDir, suite, suiteName) {
|
||||
execLocAlias = suiteName + "/" + taskName;
|
||||
}
|
||||
|
||||
const taskOpts = cloneDeep(suite.options);
|
||||
const taskOpts = JSON.parse(JSON.stringify(suite.options));
|
||||
|
||||
const taskOptsLoc = tryResolve(taskDir + "/options");
|
||||
if (taskOptsLoc) Object.assign(taskOpts, require(taskOptsLoc));
|
||||
|
||||
@ -23,8 +23,7 @@
|
||||
"@babel/parser": "workspace:^7.13.0",
|
||||
"@babel/types": "workspace:^7.13.0",
|
||||
"debug": "^4.1.0",
|
||||
"globals": "condition:BABEL_8_BREAKING ? ^13.5.0 : ^11.1.0",
|
||||
"lodash": "^4.17.19"
|
||||
"globals": "condition:BABEL_8_BREAKING ? ^13.5.0 : ^11.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/helper-plugin-test-runner": "workspace:*"
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
import cloneDeep from "lodash/cloneDeep";
|
||||
import traverse from "../lib";
|
||||
import { parse } from "@babel/parser";
|
||||
import * as t from "@babel/types";
|
||||
@ -17,7 +16,7 @@ describe("traverse", function () {
|
||||
type: "StringLiteral",
|
||||
value: "foo",
|
||||
};
|
||||
const ast2 = cloneDeep(program);
|
||||
const ast2 = JSON.parse(JSON.stringify(program));
|
||||
|
||||
traverse(ast2, {
|
||||
enter: function (path) {
|
||||
|
||||
@ -542,9 +542,7 @@ __metadata:
|
||||
version: 0.0.0-use.local
|
||||
resolution: "@babel/helper-fixtures@workspace:packages/babel-helper-fixtures"
|
||||
dependencies:
|
||||
"@types/lodash": ^4.14.150
|
||||
"@types/semver": ^7.3.4
|
||||
lodash: ^4.17.19
|
||||
semver: "condition:BABEL_8_BREAKING ? ^7.3.4 : ^6.3.0"
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
@ -3470,7 +3468,6 @@ __metadata:
|
||||
"@babel/types": "workspace:^7.13.0"
|
||||
debug: ^4.1.0
|
||||
globals: "condition:BABEL_8_BREAKING ? ^13.5.0 : ^11.1.0"
|
||||
lodash: ^4.17.19
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user