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

Import per-function lodash modules #11789

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
5 changes: 4 additions & 1 deletion packages/babel-cli/package.json
Expand Up @@ -27,7 +27,10 @@
"convert-source-map": "^1.1.0",
"fs-readdir-recursive": "^1.1.0",
"glob": "^7.0.0",
"lodash": "^4.17.13",
"lodash.debounce": "^4.0.8",
"lodash.defaults": "^4.2.0",
"lodash.includes": "^4.3.0",
"lodash.uniq": "^4.5.0",
"make-dir": "^2.1.0",
"slash": "^2.0.0",
"source-map": "^0.5.0"
Expand Down
4 changes: 2 additions & 2 deletions packages/babel-cli/src/babel/dir.js
@@ -1,7 +1,7 @@
// @flow

import defaults from "lodash/defaults";
import debounce from "lodash/debounce";
import defaults from "lodash.defaults";
import debounce from "lodash.debounce";
import { sync as makeDirSync } from "make-dir";
import slash from "slash";
import path from "path";
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-cli/src/babel/file.js
@@ -1,7 +1,7 @@
// @flow

import convertSourceMap from "convert-source-map";
import defaults from "lodash/defaults";
import defaults from "lodash.defaults";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be able to remove defaults, yeah?

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly! - we'd want to be careful about the argument ordering to the spread operator:

> var defaults = {'option': 'valueFromDefault'};
> var cliArgs = {'option': 'commandLineArgument'};
> {...defaults, ...cliArgs}
{ option: 'commandLineArgument' }
> {...cliArgs, ...defaults}
{ option: 'valueFromDefault' }

Also a subtle difference is that lodash.defaults mutates the first argument and returns it as a value, whereas the spread operator returns a new shallow clone; that's probably fine and safe in most cases, but worth being careful about.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In our case the mutation isn't a problem, since the first object is always defined inline in the call.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okie doke, thanks - #11797 contains an attempt to clean up the use of lodash.defaults from the codebase (including this callsite).

import sourceMap from "source-map";
import slash from "slash";
import { sync as makeDirSync } from "make-dir";
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-cli/src/babel/options.js
Expand Up @@ -4,7 +4,7 @@ import fs from "fs";

import commander from "commander";
import { version } from "@babel/core";
import uniq from "lodash/uniq";
import uniq from "lodash.uniq";
jayaddison marked this conversation as resolved.
Show resolved Hide resolved
import glob from "glob";

import pkg from "../../package.json";
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-cli/src/babel/util.js
Expand Up @@ -2,7 +2,7 @@

import readdirRecursive from "fs-readdir-recursive";
import * as babel from "@babel/core";
import includes from "lodash/includes";
import includes from "lodash.includes";
jayaddison marked this conversation as resolved.
Show resolved Hide resolved
import path from "path";
import fs from "fs";

Expand Down
4 changes: 3 additions & 1 deletion packages/babel-core/package.json
Expand Up @@ -55,7 +55,9 @@
"debug": "^4.1.0",
"gensync": "^1.0.0-beta.1",
"json5": "^2.1.2",
"lodash": "^4.17.13",
"lodash.clonedeep": "^4.5.0",
"lodash.escaperegexp": "^4.1.2",
"lodash.sortby": "^4.7.0",
"resolve": "^1.3.2",
"semver": "^5.4.1",
"source-map": "^0.5.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-core/src/config/pattern-to-regex.js
@@ -1,6 +1,6 @@
// @flow
import path from "path";
import escapeRegExp from "lodash/escapeRegExp";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be possible to replace lodash/escapeRegExp with a function provided by the MDN docs, although I don't know whether it'd make sense to replicate that per-babel-package or whether it should go into a utility/common package if so.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we instead consider replacing it with escape-string-regexp. That module is well tested, not being deprecated and gets 19 million weekly downloads (it's not below scrutiny).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah sorry for missing that, I guess this suggestion would only apply to babel 8 then.

import escapeRegExp from "lodash.escaperegexp";

const sep = `\\${path.sep}`;
const endSep = `(?:${sep}|$)`;
Expand Down
@@ -1,6 +1,6 @@
// @flow

import sortBy from "lodash/sortBy";
import sortBy from "lodash.sortby";

import loadConfig, { type Plugin } from "../config";

Expand Down
2 changes: 1 addition & 1 deletion packages/babel-core/src/transformation/normalize-file.js
Expand Up @@ -3,7 +3,7 @@
import fs from "fs";
import path from "path";
import buildDebug from "debug";
import cloneDeep from "lodash/cloneDeep";
import cloneDeep from "lodash.clonedeep";
import type { Handler } from "gensync";
import * as t from "@babel/types";
import type { PluginPasses } from "../config";
Expand Down
3 changes: 2 additions & 1 deletion packages/babel-generator/package.json
Expand Up @@ -20,7 +20,8 @@
"dependencies": {
"@babel/types": "^7.10.4",
"jsesc": "^2.5.1",
"lodash": "^4.17.13",
"lodash.isinteger": "^4.0.4",
"lodash.repeat": "^4.1.0",
"source-map": "^0.5.0"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions packages/babel-generator/src/printer.js
@@ -1,5 +1,5 @@
import isInteger from "lodash/isInteger";
import repeat from "lodash/repeat";
import isInteger from "lodash.isinteger";
import repeat from "lodash.repeat";
import Buffer from "./buffer";
import * as n from "./node";
import * as t from "@babel/types";
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-helper-define-map/package.json
Expand Up @@ -15,6 +15,6 @@
"dependencies": {
"@babel/helper-function-name": "^7.10.4",
"@babel/types": "^7.10.4",
"lodash": "^4.17.13"
"lodash.has": "^4.5.2"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lodash.has is similar to lodash.get, and lodash.get appears in You-Dont-Need-Lodash-Underscore.

That said, the YDNLU native JavaScript replacement is relatively complex (9 lines of non-trivial code including regular expressions) and generates an error when key paths do not exist. On balance it may make sense to maintain readability for now, although that's just my two cents and I'd welcome feedback.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep it, since we are using it with a deep path.

}
}
2 changes: 1 addition & 1 deletion packages/babel-helper-define-map/src/index.js
@@ -1,5 +1,5 @@
import nameFunction from "@babel/helper-function-name";
import has from "lodash/has";
import has from "lodash.has";
import * as t from "@babel/types";

function toKind(node: Object) {
Expand Down
4 changes: 3 additions & 1 deletion packages/babel-helper-fixtures/package.json
Expand Up @@ -14,7 +14,9 @@
},
"main": "lib/index.js",
"dependencies": {
"lodash": "^4.17.13",
"lodash.assignin": "^4.2.0",
"lodash.clone": "^4.5.0",
"lodash.clonedeep": "^4.5.0",
"semver": "^5.3.0"
}
}
6 changes: 3 additions & 3 deletions packages/babel-helper-fixtures/src/index.js
@@ -1,6 +1,6 @@
import cloneDeep from "lodash/cloneDeep";
import clone from "lodash/clone";
import extend from "lodash/extend";
import cloneDeep from "lodash.clonedeep";
import clone from "lodash.clone";
jayaddison marked this conversation as resolved.
Show resolved Hide resolved
import extend from "lodash.assignin";
jayaddison marked this conversation as resolved.
Show resolved Hide resolved
import semver from "semver";
import path from "path";
import fs from "fs";
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-helper-module-transforms/package.json
Expand Up @@ -21,6 +21,6 @@
"@babel/helper-split-export-declaration": "^7.10.4",
"@babel/template": "^7.10.4",
"@babel/types": "^7.10.4",
"lodash": "^4.17.13"
"lodash.chunk": "^4.2.0"
}
}
2 changes: 1 addition & 1 deletion packages/babel-helper-module-transforms/src/index.js
@@ -1,7 +1,7 @@
import assert from "assert";
import * as t from "@babel/types";
import template from "@babel/template";
import chunk from "lodash/chunk";
import chunk from "lodash.chunk";

import { isModule } from "@babel/helper-module-imports";

Expand Down
2 changes: 1 addition & 1 deletion packages/babel-helper-regex/package.json
Expand Up @@ -13,6 +13,6 @@
},
"main": "lib/index.js",
"dependencies": {
"lodash": "^4.17.13"
"lodash.pull": "^4.1.0"
}
}
2 changes: 1 addition & 1 deletion packages/babel-helper-regex/src/index.js
@@ -1,4 +1,4 @@
import pull from "lodash/pull";
import pull from "lodash.pull";

export function is(node: Object, flag: string): boolean {
return node.type === "RegExpLiteral" && node.flags.indexOf(flag) >= 0;
Expand Down
Expand Up @@ -22,7 +22,11 @@
"babel-check-duplicated-nodes": "^1.0.0",
"jest": "^24.8.0",
"jest-diff": "^24.8.0",
"lodash": "^4.17.13",
"lodash.assignin": "^4.2.0",
"lodash.defaults": "^4.2.0",
"lodash.escaperegexp": "^4.1.2",
"lodash.includes": "^4.3.0",
"lodash.merge": "^4.6.2",
"resolve": "^1.3.2",
"source-map": "^0.5.0"
}
Expand Down
10 changes: 5 additions & 5 deletions packages/babel-helper-transform-fixture-test-runner/src/index.js
Expand Up @@ -4,12 +4,12 @@ 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 includes from "lodash/includes";
import escapeRegExp from "lodash/escapeRegExp";
import defaults from "lodash.defaults";
import includes from "lodash.includes";
import escapeRegExp from "lodash.escaperegexp";
import * as helpers from "./helpers";
import extend from "lodash/extend";
import merge from "lodash/merge";
import extend from "lodash.assignin";
import merge from "lodash.merge";
import resolve from "resolve";
import assert from "assert";
import fs from "fs";
Expand Down
1 change: 0 additions & 1 deletion packages/babel-node/package.json
Expand Up @@ -26,7 +26,6 @@
"@babel/register": "^7.10.4",
"commander": "^4.0.1",
"core-js": "^3.2.1",
"lodash": "^4.17.13",
"node-environment-flags": "^1.0.5",
"regenerator-runtime": "^0.13.4",
"resolve": "^1.13.1",
Expand Down
3 changes: 2 additions & 1 deletion packages/babel-plugin-transform-block-scoping/package.json
Expand Up @@ -14,7 +14,8 @@
"main": "lib/index.js",
"dependencies": {
"@babel/helper-plugin-utils": "^7.10.4",
"lodash": "^4.17.13"
"lodash.assignin": "^4.2.0",
"lodash.values": "^4.3.0"
jayaddison marked this conversation as resolved.
Show resolved Hide resolved
},
"keywords": [
"babel-plugin"
Expand Down
4 changes: 2 additions & 2 deletions packages/babel-plugin-transform-block-scoping/src/index.js
Expand Up @@ -2,8 +2,8 @@ import { declare } from "@babel/helper-plugin-utils";
import type NodePath from "@babel/traverse";
import type Scope from "@babel/traverse";
import { visitor as tdzVisitor } from "./tdz";
import values from "lodash/values";
import extend from "lodash/extend";
import values from "lodash.values";
import extend from "lodash.assignin";
import { traverse, template, types as t } from "@babel/core";

const DONE = new WeakSet();
Expand Down
Expand Up @@ -17,7 +17,7 @@
],
"dependencies": {
"@babel/helper-plugin-utils": "^7.10.4",
"lodash": "^4.17.13"
"lodash.pull": "^4.1.0"
},
"peerDependencies": {
"@babel/core": "^7.0.0-0"
Expand Down
@@ -1,5 +1,5 @@
import { declare } from "@babel/helper-plugin-utils";
import pull from "lodash/pull";
import pull from "lodash.pull";
import { types as t } from "@babel/core";

export default declare(api => {
Expand Down
3 changes: 2 additions & 1 deletion packages/babel-register/package.json
Expand Up @@ -18,7 +18,8 @@
},
"dependencies": {
"find-cache-dir": "^2.0.0",
"lodash": "^4.17.13",
"lodash.clonedeep": "^4.5.0",
"lodash.escaperegexp": "^4.1.2",
"make-dir": "^2.1.0",
"pirates": "^4.0.0",
"source-map-support": "^0.5.16"
Expand Down
4 changes: 2 additions & 2 deletions packages/babel-register/src/node.js
@@ -1,7 +1,7 @@
import deepClone from "lodash/cloneDeep";
import deepClone from "lodash.clonedeep";
import sourceMapSupport from "source-map-support";
import * as registerCache from "./cache";
import escapeRegExp from "lodash/escapeRegExp";
import escapeRegExp from "lodash.escaperegexp";
import * as babel from "@babel/core";
import { OptionManager, DEFAULT_EXTENSIONS } from "@babel/core";
import { addHook } from "pirates";
Expand Down
5 changes: 4 additions & 1 deletion packages/babel-traverse/package.json
Expand Up @@ -23,7 +23,10 @@
"@babel/types": "^7.10.4",
"debug": "^4.1.0",
"globals": "^11.1.0",
"lodash": "^4.17.13"
"lodash.clone": "^4.5.0",
"lodash.defaults": "^4.2.0",
"lodash.includes": "^4.3.0",
"lodash.repeat": "^4.1.0"
},
"devDependencies": {
"@babel/helper-plugin-test-runner": "^7.10.4"
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-traverse/src/index.js
@@ -1,6 +1,6 @@
import TraversalContext from "./context";
import * as visitors from "./visitors";
import includes from "lodash/includes";
import includes from "lodash.includes";
import * as t from "@babel/types";
import * as cache from "./cache";

Expand Down
2 changes: 1 addition & 1 deletion packages/babel-traverse/src/path/introspection.js
@@ -1,7 +1,7 @@
// This file contains methods responsible for introspecting the current path for certain values.

import type NodePath from "./index";
import includes from "lodash/includes";
import includes from "lodash.includes";
import * as t from "@babel/types";

/**
Expand Down
6 changes: 3 additions & 3 deletions packages/babel-traverse/src/scope/index.js
@@ -1,9 +1,9 @@
import includes from "lodash/includes";
import repeat from "lodash/repeat";
import includes from "lodash.includes";
import repeat from "lodash.repeat";
import Renamer from "./lib/renamer";
import type NodePath from "../path";
import traverse from "../index";
import defaults from "lodash/defaults";
import defaults from "lodash.defaults";
import Binding from "./binding";
import globals from "globals";
import * as t from "@babel/types";
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-traverse/src/visitors.js
@@ -1,6 +1,6 @@
import * as virtualTypes from "./path/lib/virtual-types";
import * as t from "@babel/types";
import clone from "lodash/clone";
import clone from "lodash.clone";

/**
* explode() will take a visitor object with all of the various shorthands
Expand Down
5 changes: 4 additions & 1 deletion packages/babel-types/package.json
Expand Up @@ -17,7 +17,10 @@
"types": "lib/index.d.ts",
"dependencies": {
"@babel/helper-validator-identifier": "^7.10.4",
"lodash": "^4.17.13",
"lodash.clone": "^4.5.0",
"lodash.isplainobject": "^4.0.6",
"lodash.isregexp": "^4.0.1",
"lodash.uniq": "^4.5.0",
"to-fast-properties": "^2.0.0"
jayaddison marked this conversation as resolved.
Show resolved Hide resolved
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-types/src/builders/builder.js
@@ -1,5 +1,5 @@
// @flow
import loClone from "lodash/clone";
import loClone from "lodash.clone";
jayaddison marked this conversation as resolved.
Show resolved Hide resolved
import { NODE_FIELDS, BUILDER_KEYS } from "../definitions";
import validate from "../validators/validate";

Expand Down
4 changes: 2 additions & 2 deletions packages/babel-types/src/converters/valueToNode.js
@@ -1,6 +1,6 @@
// @flow
import isPlainObject from "lodash/isPlainObject";
import isRegExp from "lodash/isRegExp";
import isPlainObject from "lodash.isplainobject";
import isRegExp from "lodash.isregexp";
import isValidIdentifier from "../validators/isValidIdentifier";
import {
identifier,
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-types/src/utils/inherit.js
@@ -1,5 +1,5 @@
// @flow
import uniq from "lodash/uniq";
import uniq from "lodash.uniq";

export default function inherit(
key: string,
Expand Down