Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace lodash 'defaults' usage with ES6 Spread initializer #11797

Merged
merged 15 commits into from Oct 14, 2020
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 4 additions & 10 deletions packages/babel-cli/src/babel/dir.js
@@ -1,6 +1,5 @@
// @flow

import defaults from "lodash/defaults";
import debounce from "lodash/debounce";
import { sync as makeDirSync } from "make-dir";
import slash from "slash";
Expand Down Expand Up @@ -48,15 +47,10 @@ export default async function ({
const dest = getDest(relative, base);

try {
const res = await util.compile(
src,
defaults(
{
sourceFileName: slash(path.relative(dest + "/..", src)),
},
babelOptions,
),
);
const res = await util.compile(src, {
jayaddison marked this conversation as resolved.
Show resolved Hide resolved
...babelOptions,
sourceFileName: slash(path.relative(dest + "/..", src)),
});

if (!res) return FILE_TYPE.IGNORED;

Expand Down
42 changes: 15 additions & 27 deletions packages/babel-cli/src/babel/file.js
@@ -1,7 +1,6 @@
// @flow

import convertSourceMap from "convert-source-map";
import defaults from "lodash/defaults";
import sourceMap from "source-map";
import slash from "slash";
import { sync as makeDirSync } from "make-dir";
Expand Down Expand Up @@ -127,16 +126,10 @@ export default async function ({
async function stdin(): Promise<void> {
const code = await readStdin();

const res = await util.transform(
cliOptions.filename,
code,
defaults(
{
sourceFileName: "stdin",
},
babelOptions,
),
);
const res = await util.transform(cliOptions.filename, code, {
...babelOptions,
sourceFileName: "stdin",
});

output([res]);
}
Expand Down Expand Up @@ -177,22 +170,17 @@ export default async function ({
sourceFilename = slash(sourceFilename);

try {
return await util.compile(
filename,
defaults(
{
sourceFileName: sourceFilename,
// Since we're compiling everything to be merged together,
// "inline" applies to the final output file, but not to the individual
// files being concatenated.
sourceMaps:
babelOptions.sourceMaps === "inline"
? true
: babelOptions.sourceMaps,
},
babelOptions,
),
);
return await util.compile(filename, {
...babelOptions,
sourceFileName: sourceFilename,
// Since we're compiling everything to be merged together,
// "inline" applies to the final output file, but not to the individual
// files being concatenated.
sourceMaps:
babelOptions.sourceMaps === "inline"
? true
: babelOptions.sourceMaps,
});
jayaddison marked this conversation as resolved.
Show resolved Hide resolved
} catch (err) {
if (!cliOptions.watch) {
throw err;
Expand Down
Expand Up @@ -4,7 +4,6 @@ import { buildExternalHelpers } from "@babel/core";
import getFixtures from "@babel/helper-fixtures";
import sourceMap from "source-map";
import { codeFrameColumns } from "@babel/code-frame";
import defaults from "lodash/defaults";
import escapeRegExp from "lodash/escapeRegExp";
import * as helpers from "./helpers";
import extend from "lodash/extend";
Expand Down Expand Up @@ -376,9 +375,10 @@ export default function (
run(task);
}

defaults(task.options, {
task.options = {
sourceMap: !!(task.sourceMappings || task.sourceMap),
});
...task.options,
};
jayaddison marked this conversation as resolved.
Show resolved Hide resolved

extend(task.options, taskOpts);

Expand Down
5 changes: 2 additions & 3 deletions packages/babel-traverse/src/scope/index.js
@@ -1,7 +1,6 @@
import Renamer from "./lib/renamer";
import type NodePath from "../path";
import traverse from "../index";
import defaults from "lodash/defaults";
import Binding from "./binding";
import globals from "globals";
import * as t from "@babel/types";
Expand Down Expand Up @@ -952,11 +951,11 @@ export default class Scope {
*/

getAllBindings(): Object {
const ids = Object.create(null);
let ids = Object.create(null);
jayaddison marked this conversation as resolved.
Show resolved Hide resolved

let scope = this;
do {
defaults(ids, scope.bindings);
ids = { ...scope.bindings, ...ids };
jayaddison marked this conversation as resolved.
Show resolved Hide resolved
scope = scope.parent;
} while (scope);

Expand Down