Merge pull request #5042 from zertosh/no-lodash1
Use native or lodash util module where full "lodash" is required
This commit is contained in:
commit
1ab58d6dae
@ -7,7 +7,6 @@ import repl from "repl";
|
||||
import { util } from "babel-core";
|
||||
import * as babel from "babel-core";
|
||||
import vm from "vm";
|
||||
import _ from "lodash";
|
||||
import "babel-polyfill";
|
||||
import register from "babel-register";
|
||||
|
||||
@ -94,7 +93,7 @@ if (program.eval || program.print) {
|
||||
|
||||
const result = _eval(code, global.__filename);
|
||||
if (program.print) {
|
||||
const output = _.isString(result) ? result : inspect(result);
|
||||
const output = typeof result === "string" ? result : inspect(result);
|
||||
process.stdout.write(output + "\n");
|
||||
}
|
||||
} else {
|
||||
@ -104,7 +103,7 @@ if (program.eval || program.print) {
|
||||
|
||||
let i = 0;
|
||||
let ignoreNext = false;
|
||||
_.each(args, function (arg, i2) {
|
||||
args.forEach(function (arg, i2) {
|
||||
if (ignoreNext) {
|
||||
ignoreNext = false;
|
||||
return;
|
||||
|
||||
@ -3,7 +3,6 @@ const slash = require("slash");
|
||||
const path = require("path");
|
||||
const util = require("./util");
|
||||
const fs = require("fs");
|
||||
const _ = require("lodash");
|
||||
|
||||
module.exports = function (commander, filenames) {
|
||||
function write(src, relative) {
|
||||
@ -51,7 +50,7 @@ module.exports = function (commander, filenames) {
|
||||
if (stat.isDirectory(filename)) {
|
||||
const dirname = filename;
|
||||
|
||||
_.each(util.readdir(dirname), function (filename) {
|
||||
util.readdir(dirname).forEach(function (filename) {
|
||||
const src = path.join(dirname, filename);
|
||||
handleFile(src, filename);
|
||||
});
|
||||
@ -61,19 +60,19 @@ module.exports = function (commander, filenames) {
|
||||
}
|
||||
|
||||
if (!commander.skipInitialBuild) {
|
||||
_.each(filenames, handle);
|
||||
filenames.forEach(handle);
|
||||
}
|
||||
|
||||
if (commander.watch) {
|
||||
const chokidar = util.requireChokidar();
|
||||
|
||||
_.each(filenames, function (dirname) {
|
||||
filenames.forEach(function (dirname) {
|
||||
const watcher = chokidar.watch(dirname, {
|
||||
persistent: true,
|
||||
ignoreInitial: true
|
||||
});
|
||||
|
||||
_.each(["add", "change"], function (type) {
|
||||
["add", "change"].forEach(function (type) {
|
||||
watcher.on(type, function (filename) {
|
||||
const relative = path.relative(dirname, filename) || filename;
|
||||
try {
|
||||
|
||||
@ -4,7 +4,6 @@ const slash = require("slash");
|
||||
const path = require("path");
|
||||
const util = require("./util");
|
||||
const fs = require("fs");
|
||||
const _ = require("lodash");
|
||||
|
||||
module.exports = function (commander, filenames, opts) {
|
||||
if (commander.sourceMaps === "inline") {
|
||||
@ -22,7 +21,7 @@ module.exports = function (commander, filenames, opts) {
|
||||
let code = "";
|
||||
let offset = 0;
|
||||
|
||||
_.each(results, function (result) {
|
||||
results.forEach(function (result) {
|
||||
code += result.code + "\n";
|
||||
|
||||
if (result.map) {
|
||||
@ -107,14 +106,14 @@ module.exports = function (commander, filenames, opts) {
|
||||
const _filenames = [];
|
||||
results = [];
|
||||
|
||||
_.each(filenames, function (filename) {
|
||||
filenames.forEach(function (filename) {
|
||||
if (!fs.existsSync(filename)) return;
|
||||
|
||||
const stat = fs.statSync(filename);
|
||||
if (stat.isDirectory()) {
|
||||
const dirname = filename;
|
||||
|
||||
_.each(util.readdirFilter(filename), function (filename) {
|
||||
util.readdirFilter(filename).forEach(function (filename) {
|
||||
_filenames.push(path.join(dirname, filename));
|
||||
});
|
||||
} else {
|
||||
@ -122,7 +121,7 @@ module.exports = function (commander, filenames, opts) {
|
||||
}
|
||||
});
|
||||
|
||||
_.each(_filenames, function (filename) {
|
||||
_filenames.forEach(function (filename) {
|
||||
if (util.shouldIgnore(filename)) return;
|
||||
|
||||
let sourceFilename = filename;
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
const commander = require("commander");
|
||||
const defaults = require("lodash/defaults");
|
||||
const readdir = require("fs-readdir-recursive");
|
||||
const index = require("./index");
|
||||
const babel = require("babel-core");
|
||||
const util = require("babel-core").util;
|
||||
const path = require("path");
|
||||
const fs = require("fs");
|
||||
const _ = require("lodash");
|
||||
|
||||
export function chmod(src, dest) {
|
||||
fs.chmodSync(dest, fs.statSync(src).mode);
|
||||
@ -34,7 +34,7 @@ export function log(msg) {
|
||||
}
|
||||
|
||||
export function transform(filename, code, opts) {
|
||||
opts = _.defaults(opts || {}, index.opts);
|
||||
opts = defaults(opts || {}, index.opts);
|
||||
opts.filename = filename;
|
||||
|
||||
const result = babel.transform(code, opts);
|
||||
|
||||
@ -1,13 +1,14 @@
|
||||
const includes = require("lodash/includes");
|
||||
const readdir = require("fs-readdir-recursive");
|
||||
const helper = require("babel-helper-fixtures");
|
||||
const assert = require("assert");
|
||||
const rimraf = require("rimraf");
|
||||
const outputFileSync = require("output-file-sync");
|
||||
const child = require("child_process");
|
||||
const merge = require("lodash/merge");
|
||||
const path = require("path");
|
||||
const chai = require("chai");
|
||||
const fs = require("fs");
|
||||
const _ = require("lodash");
|
||||
|
||||
const fixtureLoc = path.join(__dirname, "fixtures");
|
||||
const tmpLoc = path.join(__dirname, "tmp");
|
||||
@ -25,7 +26,7 @@ const pluginLocs = [
|
||||
const readDir = function (loc) {
|
||||
const files = {};
|
||||
if (fs.existsSync(loc)) {
|
||||
_.each(readdir(loc), function (filename) {
|
||||
readdir(loc).forEach(function (filename) {
|
||||
files[filename] = helper.readFile(path.join(loc, filename));
|
||||
});
|
||||
}
|
||||
@ -33,7 +34,8 @@ const readDir = function (loc) {
|
||||
};
|
||||
|
||||
const saveInFiles = function (files) {
|
||||
_.each(files, function (content, filename) {
|
||||
Object.keys(files).forEach(function (filename) {
|
||||
const content = files[filename];
|
||||
outputFileSync(filename, content);
|
||||
});
|
||||
};
|
||||
@ -44,7 +46,7 @@ const assertTest = function (stdout, stderr, opts) {
|
||||
|
||||
if (opts.stderr) {
|
||||
if (opts.stderrContains) {
|
||||
assert.ok(_.includes(stderr, expectStderr), "stderr " + JSON.stringify(stderr) + " didn't contain " + JSON.stringify(expectStderr));
|
||||
assert.ok(includes(stderr, expectStderr), "stderr " + JSON.stringify(stderr) + " didn't contain " + JSON.stringify(expectStderr));
|
||||
} else {
|
||||
chai.expect(stderr).to.equal(expectStderr, "stderr didn't match");
|
||||
}
|
||||
@ -58,7 +60,7 @@ const assertTest = function (stdout, stderr, opts) {
|
||||
|
||||
if (opts.stdout) {
|
||||
if (opts.stdoutContains) {
|
||||
assert.ok(_.includes(stdout, expectStdout), "stdout " + JSON.stringify(stdout) + " didn't contain " + JSON.stringify(expectStdout));
|
||||
assert.ok(includes(stdout, expectStdout), "stdout " + JSON.stringify(stdout) + " didn't contain " + JSON.stringify(expectStdout));
|
||||
} else {
|
||||
chai.expect(stdout).to.equal(expectStdout, "stdout didn't match");
|
||||
}
|
||||
@ -66,7 +68,8 @@ const assertTest = function (stdout, stderr, opts) {
|
||||
throw new Error("stdout:\n" + stdout);
|
||||
}
|
||||
|
||||
_.each(opts.outFiles, function (expect, filename) {
|
||||
Object.keys(opts.outFiles, function (filename) {
|
||||
const expect = opts.outFiles[filename];
|
||||
const actual = helper.readFile(filename);
|
||||
chai.expect(actual).to.equal(expect, "out-file " + filename);
|
||||
});
|
||||
@ -134,12 +137,12 @@ const clear = function () {
|
||||
process.chdir(tmpLoc);
|
||||
};
|
||||
|
||||
_.each(fs.readdirSync(fixtureLoc), function (binName) {
|
||||
fs.readdirSync(fixtureLoc).forEach(function (binName) {
|
||||
if (binName[0] === ".") return;
|
||||
|
||||
const suiteLoc = path.join(fixtureLoc, binName);
|
||||
describe("bin/" + binName, function () {
|
||||
_.each(fs.readdirSync(suiteLoc), function (testName) {
|
||||
fs.readdirSync(suiteLoc).forEach(function (testName) {
|
||||
if (testName[0] === ".") return;
|
||||
|
||||
const testLoc = path.join(suiteLoc, testName);
|
||||
@ -149,9 +152,9 @@ _.each(fs.readdirSync(fixtureLoc), function (binName) {
|
||||
};
|
||||
|
||||
const optionsLoc = path.join(testLoc, "options.json");
|
||||
if (fs.existsSync(optionsLoc)) _.merge(opts, require(optionsLoc));
|
||||
if (fs.existsSync(optionsLoc)) merge(opts, require(optionsLoc));
|
||||
|
||||
_.each(["stdout", "stdin", "stderr"], function (key) {
|
||||
["stdout", "stdin", "stderr"].forEach(function (key) {
|
||||
const loc = path.join(testLoc, key + ".txt");
|
||||
if (fs.existsSync(loc)) {
|
||||
opts[key] = helper.readFile(loc);
|
||||
|
||||
@ -5,17 +5,16 @@ const assert = require("assert");
|
||||
const parse = require("babylon").parse;
|
||||
const chai = require("chai");
|
||||
const t = require("babel-types");
|
||||
const _ = require("lodash");
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
|
||||
describe("generation", function () {
|
||||
it("completeness", function () {
|
||||
_.each(t.VISITOR_KEYS, function (keys, type) {
|
||||
Object.keys(t.VISITOR_KEYS).forEach(function (type) {
|
||||
assert.ok(!!Printer.prototype[type], type + " should exist");
|
||||
});
|
||||
|
||||
_.each(Printer.prototype, function (fn, type) {
|
||||
Object.keys(Printer.prototype).forEach(function (type) {
|
||||
if (!/[A-Z]/.test(type[0])) return;
|
||||
assert.ok(t.VISITOR_KEYS[type], type + " should not exist");
|
||||
});
|
||||
@ -26,7 +25,7 @@ describe("generation", function () {
|
||||
"a.js": "function hi (msg) { console.log(msg); }\n",
|
||||
"b.js": "hi('hello');\n"
|
||||
};
|
||||
const parsed = _.keys(sources).reduce(function (_parsed, filename) {
|
||||
const parsed = Object.keys(sources).reduce(function (_parsed, filename) {
|
||||
_parsed[filename] = parse(sources[filename], { sourceFilename: filename });
|
||||
return _parsed;
|
||||
}, {});
|
||||
@ -297,7 +296,7 @@ const suites = require("babel-helper-fixtures").default(__dirname + "/fixtures")
|
||||
|
||||
suites.forEach(function (testSuite) {
|
||||
describe("generation/" + testSuite.title, function () {
|
||||
_.each(testSuite.tests, function (task) {
|
||||
testSuite.tests.forEach(function (task) {
|
||||
it(task.title, !task.disabled && function () {
|
||||
const expect = task.expect;
|
||||
const actual = task.actual;
|
||||
|
||||
@ -1,7 +1,10 @@
|
||||
import cloneDeep from "lodash/cloneDeep";
|
||||
import trimEnd from "lodash/trimEnd";
|
||||
import resolve from "try-resolve";
|
||||
import clone from "lodash/clone";
|
||||
import merge from "lodash/merge";
|
||||
import path from "path";
|
||||
import fs from "fs";
|
||||
import _ from "lodash";
|
||||
|
||||
function humanize(val, noext) {
|
||||
if (noext) val = path.basename(val, path.extname(val));
|
||||
@ -58,7 +61,7 @@ export default function get(entryLoc): Array<Suite> {
|
||||
if (shouldIgnore(suiteName)) continue;
|
||||
|
||||
const suite = {
|
||||
options: _.clone(rootOpts),
|
||||
options: clone(rootOpts),
|
||||
tests: [],
|
||||
title: humanize(suiteName),
|
||||
filename: entryLoc + "/" + suiteName
|
||||
@ -95,10 +98,10 @@ export default function get(entryLoc): Array<Suite> {
|
||||
expectLocAlias += "on";
|
||||
}
|
||||
|
||||
const taskOpts = _.cloneDeep(suite.options);
|
||||
const taskOpts = cloneDeep(suite.options);
|
||||
|
||||
const taskOptsLoc = resolve(taskDir + "/options");
|
||||
if (taskOptsLoc) _.merge(taskOpts, require(taskOptsLoc));
|
||||
if (taskOptsLoc) merge(taskOpts, require(taskOptsLoc));
|
||||
|
||||
const test = {
|
||||
optionsDir: taskOptsLoc ? path.dirname(taskOptsLoc) : null,
|
||||
@ -162,7 +165,7 @@ export function multiple(entryLoc, ignore?: Array<string>) {
|
||||
|
||||
export function readFile(filename) {
|
||||
if (fs.existsSync(filename)) {
|
||||
let file = _.trimEnd(fs.readFileSync(filename, "utf8"));
|
||||
let file = trimEnd(fs.readFileSync(filename, "utf8"));
|
||||
file = file.replace(/\r\n/g, "\n");
|
||||
return file;
|
||||
} else {
|
||||
|
||||
@ -3,10 +3,13 @@ import { buildExternalHelpers } from "babel-core";
|
||||
import getFixtures from "babel-helper-fixtures";
|
||||
import sourceMap from "source-map";
|
||||
import codeFrame from "babel-code-frame";
|
||||
import defaults from "lodash/defaults";
|
||||
import includes from "lodash/includes";
|
||||
import * as helpers from "./helpers";
|
||||
import extend from "lodash/extend";
|
||||
import merge from "lodash/merge";
|
||||
import assert from "assert";
|
||||
import chai from "chai";
|
||||
import _ from "lodash";
|
||||
import "babel-polyfill";
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
@ -43,7 +46,7 @@ function run(task) {
|
||||
const optionsDir = task.optionsDir;
|
||||
|
||||
function getOpts(self) {
|
||||
const newOpts = _.merge({
|
||||
const newOpts = merge({
|
||||
filename: self.loc,
|
||||
}, opts);
|
||||
|
||||
@ -98,7 +101,7 @@ function run(task) {
|
||||
if (task.sourceMappings) {
|
||||
const consumer = new sourceMap.SourceMapConsumer(result.map);
|
||||
|
||||
_.each(task.sourceMappings, function (mapping) {
|
||||
task.sourceMappings.forEach(function (mapping) {
|
||||
const actual = mapping.original;
|
||||
|
||||
const expect = consumer.originalPositionFor(mapping.generated);
|
||||
@ -138,19 +141,19 @@ export default function (
|
||||
const suites = getFixtures(fixturesLoc);
|
||||
|
||||
for (const testSuite of suites) {
|
||||
if (_.includes(suiteOpts.ignoreSuites, testSuite.title)) continue;
|
||||
if (includes(suiteOpts.ignoreSuites, testSuite.title)) continue;
|
||||
|
||||
describe(name + "/" + testSuite.title, function () {
|
||||
for (const task of testSuite.tests) {
|
||||
if (_.includes(suiteOpts.ignoreTasks, task.title) ||
|
||||
_.includes(suiteOpts.ignoreTasks, testSuite.title + "/" + task.title)) continue;
|
||||
if (includes(suiteOpts.ignoreTasks, task.title) ||
|
||||
includes(suiteOpts.ignoreTasks, testSuite.title + "/" + task.title)) continue;
|
||||
|
||||
it(task.title, !task.disabled && function () {
|
||||
function runTask() {
|
||||
run(task);
|
||||
}
|
||||
|
||||
_.defaults(task.options, {
|
||||
defaults(task.options, {
|
||||
filenameRelative: task.expect.filename,
|
||||
sourceFileName: task.actual.filename,
|
||||
sourceMapTarget: task.expect.filename,
|
||||
@ -159,7 +162,7 @@ export default function (
|
||||
sourceMap: !!(task.sourceMappings || task.sourceMap),
|
||||
});
|
||||
|
||||
_.extend(task.options, taskOpts);
|
||||
extend(task.options, taskOpts);
|
||||
|
||||
if (dynamicOpts) dynamicOpts(task.options, task);
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
const _ = require("lodash");
|
||||
const includes = require("lodash/includes");
|
||||
|
||||
require("babel-helper-transform-fixture-test-runner")(__dirname + "/fixtures/traceur", "traceur", {
|
||||
ignoreSuites: [
|
||||
@ -79,7 +79,7 @@ require("babel-helper-transform-fixture-test-runner")(__dirname + "/fixtures/tra
|
||||
}, {
|
||||
|
||||
}, function (opts, task) {
|
||||
if (_.includes(task.exec.loc, "module.js")) {
|
||||
if (includes(task.exec.loc, "module.js")) {
|
||||
opts.plugins.push("transform-es2015-modules-commonjs");
|
||||
} else {
|
||||
opts.sourceType = "script";
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
var outputFile = require("output-file-sync");
|
||||
var kebabCase = require("lodash/kebabCase");
|
||||
var each = require("lodash/each");
|
||||
var fs = require("fs");
|
||||
var _ = require("lodash");
|
||||
|
||||
var coreDefinitions = require("babel-plugin-transform-runtime").definitions;
|
||||
|
||||
@ -122,7 +122,7 @@ each(helpers.list, function (helperName) {
|
||||
writeFile("helpers/" + helperName + ".js", buildHelper(helperName));
|
||||
|
||||
// compat
|
||||
var helperAlias = _.kebabCase(helperName);
|
||||
var helperAlias = kebabCase(helperName);
|
||||
var content = "module.exports = require(\"./" + helperName + ".js\");";
|
||||
writeFile("helpers/_" + helperAlias + ".js", content);
|
||||
if (helperAlias !== helperName) writeFile("helpers/" + helperAlias + ".js", content);
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
const traverse = require("../lib").default;
|
||||
const assert = require("assert");
|
||||
const _ = require("lodash");
|
||||
const parse = require("babylon").parse;
|
||||
const cloneDeep = require("lodash/cloneDeep");
|
||||
const traverse = require("../lib").default;
|
||||
const assert = require("assert");
|
||||
const parse = require("babylon").parse;
|
||||
|
||||
describe("traverse", function () {
|
||||
const code = `
|
||||
@ -17,7 +17,7 @@ describe("traverse", function () {
|
||||
type: "StringLiteral",
|
||||
value: "foo"
|
||||
};
|
||||
const ast2 = _.cloneDeep(program);
|
||||
const ast2 = cloneDeep(program);
|
||||
|
||||
traverse(ast2, {
|
||||
enter: function (path) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user