Reduce dependency on lodash functions: includes, uniq, repeat, isinteger (#11790)
* Replace lodash 'includes' usage with Array.prototype.includes * Replace lodash 'values' usage with Object.values * Replace lodash 'uniq' usage with Array.from(new Set(...)) * Property safety: ensure that ignoreSuites/ignoreTasks are populated prior to access * Property safety: ensure that blacklistTypes is populated prior to access * Revert "Replace lodash 'values' usage with Object.values" This reverts commit 9fd3679d6db03066daee09fad0050e5292a32aa1. * Replace lodash 'repeat' usage with String.prototype.repeat * Replace lodash 'isinteger' usage with Number.isInteger * Remove explicit lodash dependency from babel-generator package * Update packages/babel-helper-transform-fixture-test-runner/src/index.js Co-authored-by: Brian Ng <bng412@gmail.com> * Rely on optional chaining operator as sole boolean check * Handle additional optional chaining operator simplification * Update type signature Co-authored-by: Brian Ng <bng412@gmail.com>
This commit is contained in:
parent
c664fbdd07
commit
3e55270135
@ -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";
|
||||
@ -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)) {
|
||||
|
||||
@ -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";
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -20,7 +20,6 @@
|
||||
"dependencies": {
|
||||
"@babel/types": "^7.10.4",
|
||||
"jsesc": "^2.5.1",
|
||||
"lodash": "^4.17.13",
|
||||
"source-map": "^0.5.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@ -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";
|
||||
@ -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) &&
|
||||
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -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
|
||||
|
||||
@ -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";
|
||||
@ -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({
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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";
|
||||
|
||||
@ -87,10 +86,10 @@ function hasBlacklistedType(path, state) {
|
||||
traverse.hasType = function (
|
||||
tree: Object,
|
||||
type: Object,
|
||||
blacklistTypes: Array<string>,
|
||||
blacklistTypes?: Array<string>,
|
||||
): 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;
|
||||
|
||||
@ -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";
|
||||
|
||||
/**
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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";
|
||||
@ -502,7 +500,7 @@ export default class Scope {
|
||||
}
|
||||
|
||||
dump() {
|
||||
const sep = repeat("-", 60);
|
||||
const sep = "-".repeat(60);
|
||||
console.log(sep);
|
||||
let scope = this;
|
||||
do {
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
||||
@ -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)),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user