Replace lodash 'defaults' usage with ES6 Spread initializer (#11797)
Co-authored-by: Corey Farrell <git@cfware.com>
This commit is contained in:
parent
136e6301cb
commit
94b5f92e39
@ -1,6 +1,5 @@
|
|||||||
// @flow
|
// @flow
|
||||||
|
|
||||||
import defaults from "lodash/defaults";
|
|
||||||
import debounce from "lodash/debounce";
|
import debounce from "lodash/debounce";
|
||||||
import { sync as makeDirSync } from "make-dir";
|
import { sync as makeDirSync } from "make-dir";
|
||||||
import slash from "slash";
|
import slash from "slash";
|
||||||
@ -48,15 +47,10 @@ export default async function ({
|
|||||||
const dest = getDest(relative, base);
|
const dest = getDest(relative, base);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await util.compile(
|
const res = await util.compile(src, {
|
||||||
src,
|
...babelOptions,
|
||||||
defaults(
|
sourceFileName: slash(path.relative(dest + "/..", src)),
|
||||||
{
|
});
|
||||||
sourceFileName: slash(path.relative(dest + "/..", src)),
|
|
||||||
},
|
|
||||||
babelOptions,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!res) return FILE_TYPE.IGNORED;
|
if (!res) return FILE_TYPE.IGNORED;
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
// @flow
|
// @flow
|
||||||
|
|
||||||
import convertSourceMap from "convert-source-map";
|
import convertSourceMap from "convert-source-map";
|
||||||
import defaults from "lodash/defaults";
|
|
||||||
import sourceMap from "source-map";
|
import sourceMap from "source-map";
|
||||||
import slash from "slash";
|
import slash from "slash";
|
||||||
import { sync as makeDirSync } from "make-dir";
|
import { sync as makeDirSync } from "make-dir";
|
||||||
@ -127,16 +126,10 @@ export default async function ({
|
|||||||
async function stdin(): Promise<void> {
|
async function stdin(): Promise<void> {
|
||||||
const code = await readStdin();
|
const code = await readStdin();
|
||||||
|
|
||||||
const res = await util.transform(
|
const res = await util.transform(cliOptions.filename, code, {
|
||||||
cliOptions.filename,
|
...babelOptions,
|
||||||
code,
|
sourceFileName: "stdin",
|
||||||
defaults(
|
});
|
||||||
{
|
|
||||||
sourceFileName: "stdin",
|
|
||||||
},
|
|
||||||
babelOptions,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
output([res]);
|
output([res]);
|
||||||
}
|
}
|
||||||
@ -177,22 +170,17 @@ export default async function ({
|
|||||||
sourceFilename = slash(sourceFilename);
|
sourceFilename = slash(sourceFilename);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return await util.compile(
|
return await util.compile(filename, {
|
||||||
filename,
|
...babelOptions,
|
||||||
defaults(
|
sourceFileName: sourceFilename,
|
||||||
{
|
// Since we're compiling everything to be merged together,
|
||||||
sourceFileName: sourceFilename,
|
// "inline" applies to the final output file, but not to the individual
|
||||||
// Since we're compiling everything to be merged together,
|
// files being concatenated.
|
||||||
// "inline" applies to the final output file, but not to the individual
|
sourceMaps:
|
||||||
// files being concatenated.
|
babelOptions.sourceMaps === "inline"
|
||||||
sourceMaps:
|
? true
|
||||||
babelOptions.sourceMaps === "inline"
|
: babelOptions.sourceMaps,
|
||||||
? true
|
});
|
||||||
: babelOptions.sourceMaps,
|
|
||||||
},
|
|
||||||
babelOptions,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (!cliOptions.watch) {
|
if (!cliOptions.watch) {
|
||||||
throw err;
|
throw err;
|
||||||
|
|||||||
@ -15,7 +15,6 @@ config <CWD>/.babelrc
|
|||||||
|
|
||||||
programmatic options from @babel/cli
|
programmatic options from @babel/cli
|
||||||
{
|
{
|
||||||
"sourceFileName": "src/foo.js",
|
|
||||||
"presets": [
|
"presets": [
|
||||||
"<ROOTDIR>//packages//babel-preset-react"
|
"<ROOTDIR>//packages//babel-preset-react"
|
||||||
],
|
],
|
||||||
@ -24,6 +23,7 @@ programmatic options from @babel/cli
|
|||||||
"<ROOTDIR>//packages//babel-plugin-transform-strict-mode",
|
"<ROOTDIR>//packages//babel-plugin-transform-strict-mode",
|
||||||
"<ROOTDIR>//packages//babel-plugin-transform-modules-commonjs"
|
"<ROOTDIR>//packages//babel-plugin-transform-modules-commonjs"
|
||||||
],
|
],
|
||||||
|
"sourceFileName": "src/foo.js",
|
||||||
"caller": {
|
"caller": {
|
||||||
"name": "@babel/cli"
|
"name": "@babel/cli"
|
||||||
},
|
},
|
||||||
|
|||||||
@ -15,7 +15,6 @@ config <CWD>/.babelrc
|
|||||||
|
|
||||||
programmatic options from @babel/cli
|
programmatic options from @babel/cli
|
||||||
{
|
{
|
||||||
"sourceFileName": "src/foo.js",
|
|
||||||
"presets": [
|
"presets": [
|
||||||
"<ROOTDIR>/packages/babel-preset-react"
|
"<ROOTDIR>/packages/babel-preset-react"
|
||||||
],
|
],
|
||||||
@ -24,6 +23,7 @@ programmatic options from @babel/cli
|
|||||||
"<ROOTDIR>/packages/babel-plugin-transform-strict-mode",
|
"<ROOTDIR>/packages/babel-plugin-transform-strict-mode",
|
||||||
"<ROOTDIR>/packages/babel-plugin-transform-modules-commonjs"
|
"<ROOTDIR>/packages/babel-plugin-transform-modules-commonjs"
|
||||||
],
|
],
|
||||||
|
"sourceFileName": "src/foo.js",
|
||||||
"caller": {
|
"caller": {
|
||||||
"name": "@babel/cli"
|
"name": "@babel/cli"
|
||||||
},
|
},
|
||||||
|
|||||||
@ -15,7 +15,6 @@ config <CWD>/.babelrc
|
|||||||
|
|
||||||
programmatic options from @babel/cli
|
programmatic options from @babel/cli
|
||||||
{
|
{
|
||||||
"sourceFileName": "../src/foo.js",
|
|
||||||
"presets": [
|
"presets": [
|
||||||
"<ROOTDIR>//packages//babel-preset-react"
|
"<ROOTDIR>//packages//babel-preset-react"
|
||||||
],
|
],
|
||||||
@ -24,6 +23,7 @@ programmatic options from @babel/cli
|
|||||||
"<ROOTDIR>//packages//babel-plugin-transform-strict-mode",
|
"<ROOTDIR>//packages//babel-plugin-transform-strict-mode",
|
||||||
"<ROOTDIR>//packages//babel-plugin-transform-modules-commonjs"
|
"<ROOTDIR>//packages//babel-plugin-transform-modules-commonjs"
|
||||||
],
|
],
|
||||||
|
"sourceFileName": "../src/foo.js",
|
||||||
"caller": {
|
"caller": {
|
||||||
"name": "@babel/cli"
|
"name": "@babel/cli"
|
||||||
},
|
},
|
||||||
|
|||||||
@ -110,7 +110,6 @@ config <CWD>/.babelrc
|
|||||||
|
|
||||||
programmatic options from @babel/cli
|
programmatic options from @babel/cli
|
||||||
{
|
{
|
||||||
"sourceFileName": "./src/index.js",
|
|
||||||
"presets": [
|
"presets": [
|
||||||
"<ROOTDIR>/packages/babel-preset-react"
|
"<ROOTDIR>/packages/babel-preset-react"
|
||||||
],
|
],
|
||||||
@ -120,6 +119,7 @@ programmatic options from @babel/cli
|
|||||||
"<ROOTDIR>/packages/babel-plugin-transform-modules-commonjs"
|
"<ROOTDIR>/packages/babel-plugin-transform-modules-commonjs"
|
||||||
],
|
],
|
||||||
"configFile": "./my-config.js",
|
"configFile": "./my-config.js",
|
||||||
|
"sourceFileName": "./src/index.js",
|
||||||
"caller": {
|
"caller": {
|
||||||
"name": "@babel/cli"
|
"name": "@babel/cli"
|
||||||
},
|
},
|
||||||
|
|||||||
@ -4,7 +4,6 @@ import { buildExternalHelpers } from "@babel/core";
|
|||||||
import getFixtures from "@babel/helper-fixtures";
|
import getFixtures from "@babel/helper-fixtures";
|
||||||
import sourceMap from "source-map";
|
import sourceMap from "source-map";
|
||||||
import { codeFrameColumns } from "@babel/code-frame";
|
import { codeFrameColumns } from "@babel/code-frame";
|
||||||
import defaults from "lodash/defaults";
|
|
||||||
import escapeRegExp from "lodash/escapeRegExp";
|
import escapeRegExp from "lodash/escapeRegExp";
|
||||||
import * as helpers from "./helpers";
|
import * as helpers from "./helpers";
|
||||||
import merge from "lodash/merge";
|
import merge from "lodash/merge";
|
||||||
@ -442,9 +441,11 @@ export default function (
|
|||||||
run(task);
|
run(task);
|
||||||
}
|
}
|
||||||
|
|
||||||
defaults(task.options, {
|
if ("sourceMap" in task.options === false) {
|
||||||
sourceMap: !!(task.sourceMappings || task.sourceMap),
|
task.options.sourceMap = !!(
|
||||||
});
|
task.sourceMappings || task.sourceMap
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
Object.assign(task.options, taskOpts);
|
Object.assign(task.options, taskOpts);
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
import Renamer from "./lib/renamer";
|
import Renamer from "./lib/renamer";
|
||||||
import type NodePath from "../path";
|
import type NodePath from "../path";
|
||||||
import traverse from "../index";
|
import traverse from "../index";
|
||||||
import defaults from "lodash/defaults";
|
|
||||||
import Binding from "./binding";
|
import Binding from "./binding";
|
||||||
import globals from "globals";
|
import globals from "globals";
|
||||||
import * as t from "@babel/types";
|
import * as t from "@babel/types";
|
||||||
@ -956,7 +955,11 @@ export default class Scope {
|
|||||||
|
|
||||||
let scope = this;
|
let scope = this;
|
||||||
do {
|
do {
|
||||||
defaults(ids, scope.bindings);
|
for (const key of Object.keys(scope.bindings)) {
|
||||||
|
if (key in ids === false) {
|
||||||
|
ids[key] = scope.bindings[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
scope = scope.parent;
|
scope = scope.parent;
|
||||||
} while (scope);
|
} while (scope);
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user