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

Reduce dependency on lodash functions: includes, uniq, repeat, isinteger #11790

Merged
merged 13 commits into from Jul 6, 2020
Merged
Show file tree
Hide file tree
Changes from 12 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
3 changes: 1 addition & 2 deletions packages/babel-cli/src/babel/options.js
Expand Up @@ -4,7 +4,6 @@ import fs from "fs";

import commander from "commander";
import { version } from "@babel/core";
import uniq from "lodash/uniq";
import glob from "glob";

import pkg from "../../package.json";
Expand Down Expand Up @@ -195,7 +194,7 @@ export default function parseArgv(args: Array<string>): CmdOptions | null {
return globbed.concat(files);
}, []);

filenames = uniq(filenames);
filenames = Array.from(new Set(filenames));

filenames.forEach(function (filename) {
if (!fs.existsSync(filename)) {
Expand Down
3 changes: 1 addition & 2 deletions packages/babel-cli/src/babel/util.js
Expand Up @@ -2,7 +2,6 @@

import readdirRecursive from "fs-readdir-recursive";
import * as babel from "@babel/core";
import includes from "lodash/includes";
import path from "path";
import fs from "fs";

Expand Down Expand Up @@ -47,7 +46,7 @@ export function isCompilableExtension(
): boolean {
const exts = altExts || babel.DEFAULT_EXTENSIONS;
const ext = path.extname(filename);
return includes(exts, ext);
return exts.includes(ext);
}

export function addSourceMappingUrl(code: string, loc: string): string {
Expand Down
1 change: 0 additions & 1 deletion packages/babel-generator/package.json
Expand Up @@ -20,7 +20,6 @@
"dependencies": {
"@babel/types": "^7.10.4",
"jsesc": "^2.5.1",
"lodash": "^4.17.13",
"source-map": "^0.5.0"
},
"devDependencies": {
Expand Down
8 changes: 3 additions & 5 deletions packages/babel-generator/src/printer.js
@@ -1,5 +1,3 @@
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 Expand Up @@ -138,7 +136,7 @@ export default class Printer {
// Integer tokens need special handling because they cannot have '.'s inserted
// immediately after them.
this._endsWithInteger =
isInteger(+str) &&
Number.isInteger(+str) &&
!NON_DECIMAL_LITERAL.test(str) &&
!SCIENTIFIC_NOTATION.test(str) &&
!ZERO_DECIMAL_INTEGER.test(str) &&
Expand Down Expand Up @@ -324,7 +322,7 @@ export default class Printer {
*/

_getIndent(): string {
return repeat(this.format.indent.style, this._indent);
return this.format.indent.style.repeat(this._indent);
}

/**
Expand Down Expand Up @@ -616,7 +614,7 @@ export default class Printer {
this._getIndent().length,
this._buf.getCurrentColumn(),
);
val = val.replace(/\n(?!$)/g, `\n${repeat(" ", indentSize)}`);
val = val.replace(/\n(?!$)/g, `\n${" ".repeat(indentSize)}`);
}

// Avoid creating //* comments
Expand Down
Expand Up @@ -5,7 +5,6 @@ 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 * as helpers from "./helpers";
import extend from "lodash/extend";
Expand Down Expand Up @@ -352,7 +351,7 @@ export default function (
const suites = getFixtures(fixturesLoc);

for (const testSuite of suites) {
if (includes(suiteOpts.ignoreSuites, testSuite.title)) continue;
if (suiteOpts.ignoreSuites?.includes(testSuite.title)) continue;

describe(name + "/" + testSuite.title, function () {
jest.addMatchers({
Expand All @@ -361,8 +360,8 @@ export default function (

for (const task of testSuite.tests) {
if (
includes(suiteOpts.ignoreTasks, task.title) ||
includes(suiteOpts.ignoreTasks, testSuite.title + "/" + task.title)
suiteOpts.ignoreTasks?.includes(task.title) ||
suiteOpts.ignoreTasks?.includes(testSuite.title + "/" + task.title)
) {
continue;
}
Expand Down
3 changes: 1 addition & 2 deletions packages/babel-traverse/src/index.js
@@ -1,6 +1,5 @@
import TraversalContext from "./context";
import * as visitors from "./visitors";
import includes from "lodash/includes";
import * as t from "@babel/types";
import * as cache from "./cache";

Expand Down Expand Up @@ -90,7 +89,7 @@ traverse.hasType = function (
blacklistTypes: Array<string>,
jayaddison marked this conversation as resolved.
Show resolved Hide resolved
): boolean {
// the node we're searching in is blacklisted
if (includes(blacklistTypes, tree.type)) return false;
if (blacklistTypes?.includes(tree.type)) return false;

// the type we're looking for is the same as the passed node
if (tree.type === type) return true;
Expand Down
3 changes: 1 addition & 2 deletions packages/babel-traverse/src/path/introspection.js
@@ -1,7 +1,6 @@
// This file contains methods responsible for introspecting the current path for certain values.

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

/**
Expand Down Expand Up @@ -149,7 +148,7 @@ export function isStatementOrBlock() {
) {
return false;
} else {
return includes(t.STATEMENT_OR_BLOCK_KEYS, this.key);
return t.STATEMENT_OR_BLOCK_KEYS.includes(this.key);
}
}

Expand Down
8 changes: 3 additions & 5 deletions packages/babel-traverse/src/scope/index.js
@@ -1,5 +1,3 @@
import includes from "lodash/includes";
import repeat from "lodash/repeat";
import Renamer from "./lib/renamer";
import type NodePath from "../path";
import traverse from "../index";
Expand Down Expand Up @@ -502,7 +500,7 @@ export default class Scope {
}

dump() {
const sep = repeat("-", 60);
const sep = "-".repeat(60);
console.log(sep);
let scope = this;
do {
Expand Down Expand Up @@ -1038,8 +1036,8 @@ export default class Scope {
if (this.hasOwnBinding(name)) return true;
if (this.parentHasBinding(name, noGlobals)) return true;
if (this.hasUid(name)) return true;
if (!noGlobals && includes(Scope.globals, name)) return true;
if (!noGlobals && includes(Scope.contextVariables, name)) return true;
if (!noGlobals && Scope.globals.includes(name)) return true;
if (!noGlobals && Scope.contextVariables.includes(name)) return true;
return false;
}

Expand Down
6 changes: 3 additions & 3 deletions packages/babel-types/src/utils/inherit.js
@@ -1,12 +1,12 @@
// @flow
import uniq from "lodash/uniq";

export default function inherit(
key: string,
child: Object,
parent: Object,
): void {
if (child && parent) {
child[key] = uniq([].concat(child[key], parent[key]).filter(Boolean));
child[key] = Array.from(
new Set([].concat(child[key], parent[key]).filter(Boolean)),
);
}
}