Skip to content

Commit

Permalink
enable prefer const (babel#5113)
Browse files Browse the repository at this point in the history
  • Loading branch information
hzoo authored and panagosg7 committed Jan 17, 2017
1 parent de55fba commit 9ca7ed9
Show file tree
Hide file tree
Showing 177 changed files with 1,864 additions and 1,865 deletions.
3 changes: 1 addition & 2 deletions package.json
Expand Up @@ -26,8 +26,7 @@
"codecov": "^1.0.1",
"derequire": "^2.0.2",
"eslint": "^3.9.0",
"eslint-config-babel": "^2.0.1",
"eslint-plugin-babel": "^3.3.0",
"eslint-config-babel": "^5.0.0",
"eslint-plugin-flowtype": "^2.20.0",
"flow-bin": "^0.34.0",
"gulp": "^3.9.0",
Expand Down
18 changes: 9 additions & 9 deletions packages/babel-cli/src/_babel-node.js
Expand Up @@ -11,7 +11,7 @@ import _ from "lodash";
import "babel-polyfill";
import register from "babel-register";

let program = new commander.Command("babel-node");
const program = new commander.Command("babel-node");

program.option("-e, --eval [script]", "Evaluate script");
program.option("-p, --print [code]", "Evaluate script and print result");
Expand All @@ -21,7 +21,7 @@ program.option("-x, --extensions [extensions]", "List of extensions to hook into
program.option("-w, --plugins [string]", "", util.list);
program.option("-b, --presets [string]", "", util.list);

let pkg = require("../package.json");
const pkg = require("../package.json");
program.version(pkg.version);
program.usage("[options] [ -e script | script.js ] [arguments]");
program.parse(process.argv);
Expand All @@ -38,7 +38,7 @@ register({

//

let replPlugin = ({ types: t }) => ({
const replPlugin = ({ types: t }) => ({
visitor: {
ModuleDeclaration(path) {
throw path.buildCodeFrameError("Modules aren't supported in the REPL");
Expand All @@ -62,7 +62,7 @@ let replPlugin = ({ types: t }) => ({

//

let _eval = function (code, filename) {
const _eval = function (code, filename) {
code = code.trim();
if (!code) return undefined;

Expand All @@ -84,17 +84,17 @@ if (program.eval || program.print) {
global.__filename = "[eval]";
global.__dirname = process.cwd();

let module = new Module(global.__filename);
const module = new Module(global.__filename);
module.filename = global.__filename;
module.paths = Module._nodeModulePaths(global.__dirname);

global.exports = module.exports;
global.module = module;
global.require = module.require.bind(module);

let result = _eval(code, global.__filename);
const result = _eval(code, global.__filename);
if (program.print) {
let output = _.isString(result) ? result : inspect(result);
const output = _.isString(result) ? result : inspect(result);
process.stdout.write(output + "\n");
}
} else {
Expand All @@ -111,7 +111,7 @@ if (program.eval || program.print) {
}

if (arg[0] === "-") {
let parsedArg = program[arg.slice(2)];
const parsedArg = program[arg.slice(2)];
if (parsedArg && parsedArg !== true) {
ignoreNext = true;
}
Expand All @@ -123,7 +123,7 @@ if (program.eval || program.print) {
args = args.slice(i);

// make the filename absolute
let filename = args[0];
const filename = args[0];
if (!pathIsAbsolute(filename)) args[0] = path.join(process.cwd(), filename);

// add back on node and concat the sliced args
Expand Down
12 changes: 6 additions & 6 deletions packages/babel-cli/src/babel-node.js
Expand Up @@ -5,16 +5,16 @@
* when found, before invoking the "real" _babel-node(1) executable.
*/

let getV8Flags = require("v8flags");
let path = require("path");
const getV8Flags = require("v8flags");
const path = require("path");

let args = [path.join(__dirname, "_babel-node")];

let babelArgs = process.argv.slice(2);
let userArgs;

// separate node arguments from script arguments
let argSeparator = babelArgs.indexOf("--");
const argSeparator = babelArgs.indexOf("--");
if (argSeparator > -1) {
userArgs = babelArgs.slice(argSeparator); // including the --
babelArgs = babelArgs.slice(0, argSeparator);
Expand Down Expand Up @@ -75,13 +75,13 @@ getV8Flags(function (err, v8Flags) {
}

try {
let kexec = require("kexec");
const kexec = require("kexec");
kexec(process.argv[0], args);
} catch (err) {
if (err.code !== "MODULE_NOT_FOUND") throw err;

let child_process = require("child_process");
let proc = child_process.spawn(process.argv[0], args, { stdio: "inherit" });
const child_process = require("child_process");
const proc = child_process.spawn(process.argv[0], args, { stdio: "inherit" });
proc.on("exit", function (code, signal) {
process.on("exit", function () {
if (signal) {
Expand Down
32 changes: 16 additions & 16 deletions packages/babel-cli/src/babel/dir.js
@@ -1,26 +1,26 @@
let outputFileSync = require("output-file-sync");
let slash = require("slash");
let path = require("path");
let util = require("./util");
let fs = require("fs");
let _ = require("lodash");
const outputFileSync = require("output-file-sync");
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) {
// remove extension and then append back on .js
relative = relative.replace(/\.(\w*?)$/, "") + ".js";

let dest = path.join(commander.outDir, relative);
const dest = path.join(commander.outDir, relative);

let data = util.compile(src, {
const data = util.compile(src, {
sourceFileName: slash(path.relative(dest + "/..", src)),
sourceMapTarget: path.basename(relative)
});
if (!commander.copyFiles && data.ignored) return;

// we've requested explicit sourcemaps to be written to disk
if (data.map && commander.sourceMaps && commander.sourceMaps !== "inline") {
let mapLoc = dest + ".map";
const mapLoc = dest + ".map";
data.code = util.addSourceMappingUrl(data.code, mapLoc);
outputFileSync(mapLoc, JSON.stringify(data.map));
}
Expand All @@ -37,7 +37,7 @@ module.exports = function (commander, filenames) {
if (util.canCompile(filename, commander.extensions)) {
write(src, filename);
} else if (commander.copyFiles) {
let dest = path.join(commander.outDir, filename);
const dest = path.join(commander.outDir, filename);
outputFileSync(dest, fs.readFileSync(src));
util.chmod(src, dest);
}
Expand All @@ -46,13 +46,13 @@ module.exports = function (commander, filenames) {
function handle(filename) {
if (!fs.existsSync(filename)) return;

let stat = fs.statSync(filename);
const stat = fs.statSync(filename);

if (stat.isDirectory(filename)) {
let dirname = filename;
const dirname = filename;

_.each(util.readdir(dirname), function (filename) {
let src = path.join(dirname, filename);
const src = path.join(dirname, filename);
handleFile(src, filename);
});
} else {
Expand All @@ -65,10 +65,10 @@ module.exports = function (commander, filenames) {
}

if (commander.watch) {
let chokidar = util.requireChokidar();
const chokidar = util.requireChokidar();

_.each(filenames, function (dirname) {
let watcher = chokidar.watch(dirname, {
const watcher = chokidar.watch(dirname, {
persistent: true,
ignoreInitial: true,
awaitWriteFinish: {
Expand All @@ -79,7 +79,7 @@ module.exports = function (commander, filenames) {

_.each(["add", "change"], function (type) {
watcher.on(type, function (filename) {
let relative = path.relative(dirname, filename) || filename;
const relative = path.relative(dirname, filename) || filename;
try {
handleFile(filename, relative);
} catch (err) {
Expand Down
48 changes: 24 additions & 24 deletions packages/babel-cli/src/babel/file.js
@@ -1,10 +1,10 @@
let convertSourceMap = require("convert-source-map");
let sourceMap = require("source-map");
let slash = require("slash");
let path = require("path");
let util = require("./util");
let fs = require("fs");
let _ = require("lodash");
const convertSourceMap = require("convert-source-map");
const sourceMap = require("source-map");
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") {
Expand All @@ -13,8 +13,8 @@ module.exports = function (commander, filenames, opts) {

let results = [];

let buildResult = function () {
let map = new sourceMap.SourceMapGenerator({
const buildResult = function () {
const map = new sourceMap.SourceMapGenerator({
file: path.basename(commander.outFile || "") || "stdout",
sourceRoot: opts.sourceRoot
});
Expand All @@ -26,8 +26,8 @@ module.exports = function (commander, filenames, opts) {
code += result.code + "\n";

if (result.map) {
let consumer = new sourceMap.SourceMapConsumer(result.map);
let sources = new Set();
const consumer = new sourceMap.SourceMapConsumer(result.map);
const sources = new Set();

consumer.eachMapping(function (mapping) {
if (mapping.source != null) sources.add(mapping.source);
Expand All @@ -46,7 +46,7 @@ module.exports = function (commander, filenames, opts) {
});

sources.forEach((source) => {
let content = consumer.sourceContentFor(source, true);
const content = consumer.sourceContentFor(source, true);
if (content !== null) {
map.setSourceContent(source, content);
}
Expand All @@ -68,13 +68,13 @@ module.exports = function (commander, filenames, opts) {
};
};

let output = function () {
let result = buildResult();
const output = function () {
const result = buildResult();

if (commander.outFile) {
// we've requested for a sourcemap to be written to disk
if (commander.sourceMaps && commander.sourceMaps !== "inline") {
let mapLoc = commander.outFile + ".map";
const mapLoc = commander.outFile + ".map";
result.code = util.addSourceMappingUrl(result.code, mapLoc);
fs.writeFileSync(mapLoc, JSON.stringify(result.map));
}
Expand All @@ -85,13 +85,13 @@ module.exports = function (commander, filenames, opts) {
}
};

let stdin = function () {
const stdin = function () {
let code = "";

process.stdin.setEncoding("utf8");

process.stdin.on("readable", function () {
let chunk = process.stdin.read();
const chunk = process.stdin.read();
if (chunk !== null) code += chunk;
});

Expand All @@ -103,16 +103,16 @@ module.exports = function (commander, filenames, opts) {
});
};

let walk = function () {
let _filenames = [];
const walk = function () {
const _filenames = [];
results = [];

_.each(filenames, function (filename) {
if (!fs.existsSync(filename)) return;

let stat = fs.statSync(filename);
const stat = fs.statSync(filename);
if (stat.isDirectory()) {
let dirname = filename;
const dirname = filename;

_.each(util.readdirFilter(filename), function (filename) {
_filenames.push(path.join(dirname, filename));
Expand All @@ -131,7 +131,7 @@ module.exports = function (commander, filenames, opts) {
}
sourceFilename = slash(sourceFilename);

let data = util.compile(filename, {
const data = util.compile(filename, {
sourceFileName: sourceFilename,
});

Expand All @@ -142,14 +142,14 @@ module.exports = function (commander, filenames, opts) {
output();
};

let files = function () {
const files = function () {

if (!commander.skipInitialBuild) {
walk();
}

if (commander.watch) {
let chokidar = util.requireChokidar();
const chokidar = util.requireChokidar();
chokidar.watch(filenames, {
persistent: true,
ignoreInitial: true,
Expand Down
24 changes: 12 additions & 12 deletions packages/babel-cli/src/babel/index.js
Expand Up @@ -3,14 +3,14 @@

require("babel-core");

let fs = require("fs");
let commander = require("commander");
let kebabCase = require("lodash/kebabCase");
let options = require("babel-core").options;
let util = require("babel-core").util;
let uniq = require("lodash/uniq");
let each = require("lodash/each");
let glob = require("glob");
const fs = require("fs");
const commander = require("commander");
const kebabCase = require("lodash/kebabCase");
const options = require("babel-core").options;
const util = require("babel-core").util;
const uniq = require("lodash/uniq");
const each = require("lodash/each");
const glob = require("glob");

each(options, function (option, key) {
if (option.hidden) return;
Expand All @@ -31,7 +31,7 @@ each(options, function (option, key) {
arg = "-" + option.shorthand + ", " + arg;
}

let desc = [];
const desc = [];
if (option.deprecated) desc.push("[DEPRECATED] " + option.deprecated);
if (option.description) desc.push(option.description);

Expand All @@ -46,7 +46,7 @@ commander.option("-d, --out-dir [out]", "Compile an input directory of modules i
commander.option("-D, --copy-files", "When compiling a directory copy over non-compilable files");
commander.option("-q, --quiet", "Don't log anything");

let pkg = require("../../package.json");
const pkg = require("../../package.json");
commander.version(pkg.version + " (babel-core " + require("babel-core").version + ")");
commander.usage("[options] <files ...>");
commander.parse(process.argv);
Expand All @@ -59,7 +59,7 @@ if (commander.extensions) {

//

let errors = [];
const errors = [];

let filenames = commander.args.reduce(function (globbed, input) {
let files = glob.sync(input);
Expand Down Expand Up @@ -104,7 +104,7 @@ if (errors.length) {

//

let opts = exports.opts = {};
const opts = exports.opts = {};

each(options, function (opt, key) {
if (commander[key] !== undefined && commander[key] !== opt.default) {
Expand Down

0 comments on commit 9ca7ed9

Please sign in to comment.