enable prefer const (#5113)
This commit is contained in:
@@ -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");
|
||||
@@ -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);
|
||||
@@ -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");
|
||||
@@ -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;
|
||||
|
||||
@@ -84,7 +84,7 @@ 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);
|
||||
|
||||
@@ -92,9 +92,9 @@ if (program.eval || program.print) {
|
||||
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 {
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
* 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")];
|
||||
|
||||
@@ -14,7 +14,7 @@ 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);
|
||||
@@ -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) {
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
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)
|
||||
});
|
||||
@@ -20,7 +20,7 @@ module.exports = function (commander, filenames) {
|
||||
|
||||
// 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));
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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 {
|
||||
@@ -65,17 +65,17 @@ 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
|
||||
});
|
||||
|
||||
_.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) {
|
||||
|
||||
@@ -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") {
|
||||
@@ -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
|
||||
});
|
||||
@@ -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);
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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));
|
||||
}
|
||||
@@ -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;
|
||||
});
|
||||
|
||||
@@ -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));
|
||||
@@ -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,
|
||||
});
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
@@ -59,7 +59,7 @@ if (commander.extensions) {
|
||||
|
||||
//
|
||||
|
||||
let errors = [];
|
||||
const errors = [];
|
||||
|
||||
let filenames = commander.args.reduce(function (globbed, input) {
|
||||
let files = glob.sync(input);
|
||||
@@ -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) {
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
let commander = require("commander");
|
||||
let readdir = require("fs-readdir-recursive");
|
||||
let index = require("./index");
|
||||
let babel = require("babel-core");
|
||||
let util = require("babel-core").util;
|
||||
let path = require("path");
|
||||
let fs = require("fs");
|
||||
let _ = require("lodash");
|
||||
const commander = require("commander");
|
||||
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);
|
||||
@@ -19,7 +19,7 @@ export function readdirFilter(filename) {
|
||||
|
||||
export { readdir };
|
||||
|
||||
export let canCompile = util.canCompile;
|
||||
export const canCompile = util.canCompile;
|
||||
|
||||
export function shouldIgnore(loc) {
|
||||
return util.shouldIgnore(loc, index.opts.ignore, index.opts.only);
|
||||
@@ -37,7 +37,7 @@ export function transform(filename, code, opts) {
|
||||
opts = _.defaults(opts || {}, index.opts);
|
||||
opts.filename = filename;
|
||||
|
||||
let result = babel.transform(code, opts);
|
||||
const result = babel.transform(code, opts);
|
||||
result.filename = filename;
|
||||
result.actual = code;
|
||||
return result;
|
||||
@@ -45,7 +45,7 @@ export function transform(filename, code, opts) {
|
||||
|
||||
export function compile(filename, opts) {
|
||||
try {
|
||||
let code = fs.readFileSync(filename, "utf8");
|
||||
const code = fs.readFileSync(filename, "utf8");
|
||||
return transform(filename, code, opts);
|
||||
} catch (err) {
|
||||
if (commander.watch) {
|
||||
|
||||
@@ -1,29 +1,29 @@
|
||||
let readdir = require("fs-readdir-recursive");
|
||||
let helper = require("babel-helper-fixtures");
|
||||
let assert = require("assert");
|
||||
let rimraf = require("rimraf");
|
||||
let outputFileSync = require("output-file-sync");
|
||||
let child = require("child_process");
|
||||
let path = require("path");
|
||||
let chai = require("chai");
|
||||
let fs = require("fs");
|
||||
let _ = require("lodash");
|
||||
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 path = require("path");
|
||||
const chai = require("chai");
|
||||
const fs = require("fs");
|
||||
const _ = require("lodash");
|
||||
|
||||
let fixtureLoc = path.join(__dirname, "fixtures");
|
||||
let tmpLoc = path.join(__dirname, "tmp");
|
||||
const fixtureLoc = path.join(__dirname, "fixtures");
|
||||
const tmpLoc = path.join(__dirname, "tmp");
|
||||
|
||||
let presetLocs = [
|
||||
const presetLocs = [
|
||||
path.join(__dirname, "../../babel-preset-es2015"),
|
||||
path.join(__dirname, "../../babel-preset-react")
|
||||
].join(",");
|
||||
|
||||
let pluginLocs = [
|
||||
const pluginLocs = [
|
||||
path.join(__dirname, "/../../babel-plugin-transform-strict-mode"),
|
||||
path.join(__dirname, "/../../babel-plugin-transform-es2015-modules-commonjs"),
|
||||
].join(",");
|
||||
|
||||
let readDir = function (loc) {
|
||||
let files = {};
|
||||
const readDir = function (loc) {
|
||||
const files = {};
|
||||
if (fs.existsSync(loc)) {
|
||||
_.each(readdir(loc), function (filename) {
|
||||
files[filename] = helper.readFile(path.join(loc, filename));
|
||||
@@ -32,14 +32,14 @@ let readDir = function (loc) {
|
||||
return files;
|
||||
};
|
||||
|
||||
let saveInFiles = function (files) {
|
||||
const saveInFiles = function (files) {
|
||||
_.each(files, function (content, filename) {
|
||||
outputFileSync(filename, content);
|
||||
});
|
||||
};
|
||||
|
||||
let assertTest = function (stdout, stderr, opts) {
|
||||
let expectStderr = opts.stderr.trim();
|
||||
const assertTest = function (stdout, stderr, opts) {
|
||||
const expectStderr = opts.stderr.trim();
|
||||
stderr = stderr.trim();
|
||||
|
||||
if (opts.stderr) {
|
||||
@@ -52,7 +52,7 @@ let assertTest = function (stdout, stderr, opts) {
|
||||
throw new Error("stderr:\n" + stderr);
|
||||
}
|
||||
|
||||
let expectStdout = opts.stdout.trim();
|
||||
const expectStdout = opts.stdout.trim();
|
||||
stdout = stdout.trim();
|
||||
stdout = stdout.replace(/\\/g, "/");
|
||||
|
||||
@@ -67,13 +67,13 @@ let assertTest = function (stdout, stderr, opts) {
|
||||
}
|
||||
|
||||
_.each(opts.outFiles, function (expect, filename) {
|
||||
let actual = helper.readFile(filename);
|
||||
const actual = helper.readFile(filename);
|
||||
chai.expect(actual).to.equal(expect, "out-file " + filename);
|
||||
});
|
||||
};
|
||||
|
||||
let buildTest = function (binName, testName, opts) {
|
||||
let binLoc = path.join(__dirname, "../lib", binName);
|
||||
const buildTest = function (binName, testName, opts) {
|
||||
const binLoc = path.join(__dirname, "../lib", binName);
|
||||
|
||||
return function (callback) {
|
||||
clear();
|
||||
@@ -91,7 +91,7 @@ let buildTest = function (binName, testName, opts) {
|
||||
|
||||
args = args.concat(opts.args);
|
||||
|
||||
let spawn = child.spawn(process.execPath, args);
|
||||
const spawn = child.spawn(process.execPath, args);
|
||||
|
||||
let stderr = "";
|
||||
let stdout = "";
|
||||
@@ -127,7 +127,7 @@ let buildTest = function (binName, testName, opts) {
|
||||
};
|
||||
};
|
||||
|
||||
let clear = function () {
|
||||
const clear = function () {
|
||||
process.chdir(__dirname);
|
||||
if (fs.existsSync(tmpLoc)) rimraf.sync(tmpLoc);
|
||||
fs.mkdirSync(tmpLoc);
|
||||
@@ -137,22 +137,22 @@ let clear = function () {
|
||||
_.each(fs.readdirSync(fixtureLoc), function (binName) {
|
||||
if (binName[0] === ".") return;
|
||||
|
||||
let suiteLoc = path.join(fixtureLoc, binName);
|
||||
const suiteLoc = path.join(fixtureLoc, binName);
|
||||
describe("bin/" + binName, function () {
|
||||
_.each(fs.readdirSync(suiteLoc), function (testName) {
|
||||
if (testName[0] === ".") return;
|
||||
|
||||
let testLoc = path.join(suiteLoc, testName);
|
||||
const testLoc = path.join(suiteLoc, testName);
|
||||
|
||||
let opts = {
|
||||
const opts = {
|
||||
args: []
|
||||
};
|
||||
|
||||
let optionsLoc = path.join(testLoc, "options.json");
|
||||
const optionsLoc = path.join(testLoc, "options.json");
|
||||
if (fs.existsSync(optionsLoc)) _.merge(opts, require(optionsLoc));
|
||||
|
||||
_.each(["stdout", "stdin", "stderr"], function (key) {
|
||||
let loc = path.join(testLoc, key + ".txt");
|
||||
const loc = path.join(testLoc, key + ".txt");
|
||||
if (fs.existsSync(loc)) {
|
||||
opts[key] = helper.readFile(loc);
|
||||
} else {
|
||||
@@ -163,7 +163,7 @@ _.each(fs.readdirSync(fixtureLoc), function (binName) {
|
||||
opts.outFiles = readDir(path.join(testLoc, "out-files"));
|
||||
opts.inFiles = readDir(path.join(testLoc, "in-files"));
|
||||
|
||||
let babelrcLoc = path.join(testLoc, ".babelrc");
|
||||
const babelrcLoc = path.join(testLoc, ".babelrc");
|
||||
if (fs.existsSync(babelrcLoc)) {
|
||||
// copy .babelrc file to tmp directory
|
||||
opts.inFiles[".babelrc"] = helper.readFile(babelrcLoc);
|
||||
|
||||
@@ -46,8 +46,8 @@ const BRACKET = /^[()\[\]{}]$/;
|
||||
*/
|
||||
|
||||
function getTokenType(match) {
|
||||
let [offset, text] = match.slice(-2);
|
||||
let token = matchToToken(match);
|
||||
const [offset, text] = match.slice(-2);
|
||||
const token = matchToToken(match);
|
||||
|
||||
if (token.type === "name") {
|
||||
if (esutils.keyword.isReservedWordES6(token.value)) {
|
||||
@@ -79,8 +79,8 @@ function getTokenType(match) {
|
||||
|
||||
function highlight(defs: Object, text: string) {
|
||||
return text.replace(jsTokens, function (...args) {
|
||||
let type = getTokenType(args);
|
||||
let colorize = defs[type];
|
||||
const type = getTokenType(args);
|
||||
const colorize = defs[type];
|
||||
if (colorize) {
|
||||
return args[0].split(NEWLINE).map((str) => colorize(str)).join("\n");
|
||||
} else {
|
||||
@@ -101,21 +101,21 @@ export default function (
|
||||
): string {
|
||||
colNumber = Math.max(colNumber, 0);
|
||||
|
||||
let highlighted = (opts.highlightCode && Chalk.supportsColor) || opts.forceColor;
|
||||
const highlighted = (opts.highlightCode && Chalk.supportsColor) || opts.forceColor;
|
||||
let chalk = Chalk;
|
||||
if (opts.forceColor) {
|
||||
chalk = new Chalk.constructor({ enabled: true });
|
||||
}
|
||||
let maybeHighlight = (chalkFn, string) => {
|
||||
const maybeHighlight = (chalkFn, string) => {
|
||||
return highlighted ? chalkFn(string) : string;
|
||||
};
|
||||
let defs = getDefs(chalk);
|
||||
const defs = getDefs(chalk);
|
||||
if (highlighted) rawLines = highlight(defs, rawLines);
|
||||
|
||||
let linesAbove = opts.linesAbove || 2;
|
||||
let linesBelow = opts.linesBelow || 3;
|
||||
const linesAbove = opts.linesAbove || 2;
|
||||
const linesBelow = opts.linesBelow || 3;
|
||||
|
||||
let lines = rawLines.split(NEWLINE);
|
||||
const lines = rawLines.split(NEWLINE);
|
||||
let start = Math.max(lineNumber - (linesAbove + 1), 0);
|
||||
let end = Math.min(lines.length, lineNumber + linesBelow);
|
||||
|
||||
@@ -124,16 +124,16 @@ export default function (
|
||||
end = lines.length;
|
||||
}
|
||||
|
||||
let numberMaxWidth = String(end).length;
|
||||
const numberMaxWidth = String(end).length;
|
||||
|
||||
let frame = lines.slice(start, end).map((line, index) => {
|
||||
let number = start + 1 + index;
|
||||
let paddedNumber = ` ${number}`.slice(-numberMaxWidth);
|
||||
let gutter = ` ${paddedNumber} | `;
|
||||
const frame = lines.slice(start, end).map((line, index) => {
|
||||
const number = start + 1 + index;
|
||||
const paddedNumber = ` ${number}`.slice(-numberMaxWidth);
|
||||
const gutter = ` ${paddedNumber} | `;
|
||||
if (number === lineNumber) {
|
||||
let markerLine = "";
|
||||
if (colNumber) {
|
||||
let markerSpacing = line.slice(0, colNumber - 1).replace(/[^\t]/g, " ");
|
||||
const markerSpacing = line.slice(0, colNumber - 1).replace(/[^\t]/g, " ");
|
||||
markerLine = [
|
||||
"\n ",
|
||||
maybeHighlight(defs.gutter, gutter.replace(/\d/g, " ")),
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
let assert = require("assert");
|
||||
let chalk = require("chalk");
|
||||
let codeFrame = require("..");
|
||||
const assert = require("assert");
|
||||
const chalk = require("chalk");
|
||||
const codeFrame = require("..");
|
||||
|
||||
describe("babel-code-frame", function () {
|
||||
it("basic usage", function () {
|
||||
@@ -119,7 +119,7 @@ describe("babel-code-frame", function () {
|
||||
});
|
||||
|
||||
it("opts.linesAbove", function () {
|
||||
let rawLines = [
|
||||
const rawLines = [
|
||||
"/**",
|
||||
" * Sums two numbers.",
|
||||
" *",
|
||||
@@ -143,7 +143,7 @@ describe("babel-code-frame", function () {
|
||||
});
|
||||
|
||||
it("opts.linesBelow", function () {
|
||||
let rawLines = [
|
||||
const rawLines = [
|
||||
"/**",
|
||||
" * Sums two numbers.",
|
||||
" *",
|
||||
@@ -166,7 +166,7 @@ describe("babel-code-frame", function () {
|
||||
});
|
||||
|
||||
it("opts.linesAbove and opts.linesBelow", function () {
|
||||
let rawLines = [
|
||||
const rawLines = [
|
||||
"/**",
|
||||
" * Sums two numbers.",
|
||||
" *",
|
||||
@@ -188,10 +188,10 @@ describe("babel-code-frame", function () {
|
||||
});
|
||||
|
||||
it("opts.forceColor", function() {
|
||||
let marker = chalk.red.bold;
|
||||
let gutter = chalk.grey;
|
||||
const marker = chalk.red.bold;
|
||||
const gutter = chalk.grey;
|
||||
|
||||
let rawLines = [
|
||||
const rawLines = [
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
|
||||
@@ -29,16 +29,16 @@ export function run(code: string, opts: Object = {}): any {
|
||||
export function load(url: string, callback: Function, opts: Object = {}, hold?: boolean) {
|
||||
opts.filename = opts.filename || url;
|
||||
|
||||
let xhr = global.ActiveXObject ? new global.ActiveXObject("Microsoft.XMLHTTP") : new global.XMLHttpRequest();
|
||||
const xhr = global.ActiveXObject ? new global.ActiveXObject("Microsoft.XMLHTTP") : new global.XMLHttpRequest();
|
||||
xhr.open("GET", url, true);
|
||||
if ("overrideMimeType" in xhr) xhr.overrideMimeType("text/plain");
|
||||
|
||||
xhr.onreadystatechange = function () {
|
||||
if (xhr.readyState !== 4) return;
|
||||
|
||||
let status = xhr.status;
|
||||
const status = xhr.status;
|
||||
if (status === 0 || status === 200) {
|
||||
let param = [xhr.responseText, opts];
|
||||
const param = [xhr.responseText, opts];
|
||||
if (!hold) run(param);
|
||||
if (callback) callback(param);
|
||||
} else {
|
||||
@@ -50,8 +50,8 @@ export function load(url: string, callback: Function, opts: Object = {}, hold?:
|
||||
}
|
||||
|
||||
function runScripts() {
|
||||
let scripts: Array<Array<any> | Object> = [];
|
||||
let types = ["text/ecmascript-6", "text/6to5", "text/babel", "module"];
|
||||
const scripts: Array<Array<any> | Object> = [];
|
||||
const types = ["text/ecmascript-6", "text/6to5", "text/babel", "module"];
|
||||
let index = 0;
|
||||
|
||||
/**
|
||||
@@ -59,7 +59,7 @@ function runScripts() {
|
||||
*/
|
||||
|
||||
function exec() {
|
||||
let param = scripts[index];
|
||||
const param = scripts[index];
|
||||
if (param instanceof Array) {
|
||||
run(param, index);
|
||||
index++;
|
||||
@@ -72,7 +72,7 @@ function runScripts() {
|
||||
*/
|
||||
|
||||
function run(script: Object, i: number) {
|
||||
let opts = {};
|
||||
const opts = {};
|
||||
|
||||
if (script.src) {
|
||||
load(script.src, function (param) {
|
||||
@@ -87,10 +87,10 @@ function runScripts() {
|
||||
|
||||
// Collect scripts with Babel `types`.
|
||||
|
||||
let _scripts = global.document.getElementsByTagName("script");
|
||||
const _scripts = global.document.getElementsByTagName("script");
|
||||
|
||||
for (let i = 0; i < _scripts.length; ++i) {
|
||||
let _script = _scripts[i];
|
||||
const _script = _scripts[i];
|
||||
if (types.indexOf(_script.type) >= 0) scripts.push(_script);
|
||||
}
|
||||
|
||||
|
||||
@@ -31,10 +31,10 @@ export function Plugin(alias) {
|
||||
import Pipeline from "../transformation/pipeline";
|
||||
export { Pipeline };
|
||||
|
||||
let pipeline = new Pipeline;
|
||||
export let analyse = pipeline.analyse.bind(pipeline);
|
||||
export let transform = pipeline.transform.bind(pipeline);
|
||||
export let transformFromAst = pipeline.transformFromAst.bind(pipeline);
|
||||
const pipeline = new Pipeline;
|
||||
export const analyse = pipeline.analyse.bind(pipeline);
|
||||
export const transform = pipeline.transform.bind(pipeline);
|
||||
export const transformFromAst = pipeline.transformFromAst.bind(pipeline);
|
||||
|
||||
export function transformFile(filename: string, opts?: Object, callback: Function) {
|
||||
if (isFunction(opts)) {
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
export default function getPossiblePresetNames(presetName: string): Array<string> {
|
||||
let possibleNames = [`babel-preset-${presetName}`, presetName];
|
||||
const possibleNames = [`babel-preset-${presetName}`, presetName];
|
||||
|
||||
// trying to resolve @organization shortcat
|
||||
// @foo/es2015 -> @foo/babel-preset-es2015
|
||||
let matches = presetName.match(/^(@[^/]+)\/(.+)$/);
|
||||
const matches = presetName.match(/^(@[^/]+)\/(.+)$/);
|
||||
if (matches) {
|
||||
let [, orgName, presetPath] = matches;
|
||||
const [, orgName, presetPath] = matches;
|
||||
possibleNames.push(`${orgName}/babel-preset-${presetPath}`);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,9 +5,9 @@ export default function (dest?: Object, src?: Object): ?Object {
|
||||
|
||||
return mergeWith(dest, src, function (a, b) {
|
||||
if (b && Array.isArray(a)) {
|
||||
let newArray = b.slice(0);
|
||||
const newArray = b.slice(0);
|
||||
|
||||
for (let item of a) {
|
||||
for (const item of a) {
|
||||
if (newArray.indexOf(item) < 0) {
|
||||
newArray.push(item);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import Module from "module";
|
||||
import path from "path";
|
||||
|
||||
let relativeModules = {};
|
||||
const relativeModules = {};
|
||||
|
||||
export default function (loc: string, relative: string = process.cwd()): ?string {
|
||||
// we're in the browser, probably
|
||||
@@ -18,7 +18,7 @@ export default function (loc: string, relative: string = process.cwd()): ?string
|
||||
// Node presumes "." is process.cwd(), not our relative path.
|
||||
// Since this fake module is never "loaded", we don't have to worry about mutating
|
||||
// any global Node module cache state here.
|
||||
let filename = path.join(relative, ".babelrc");
|
||||
const filename = path.join(relative, ".babelrc");
|
||||
relativeMod.id = filename;
|
||||
relativeMod.filename = filename;
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ export default class Store extends Map {
|
||||
return super.get(key);
|
||||
} else {
|
||||
if (Object.prototype.hasOwnProperty.call(this.dynamicData, key)) {
|
||||
let val = this.dynamicData[key]();
|
||||
const val = this.dynamicData[key]();
|
||||
this.set(key, val);
|
||||
return val;
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import template from "babel-template";
|
||||
import each from "lodash/each";
|
||||
import * as t from "babel-types";
|
||||
|
||||
let buildUmdWrapper = template(`
|
||||
const buildUmdWrapper = template(`
|
||||
(function (root, factory) {
|
||||
if (typeof define === "function" && define.amd) {
|
||||
define(AMD_ARGUMENTS, factory);
|
||||
@@ -22,9 +22,9 @@ let buildUmdWrapper = template(`
|
||||
`);
|
||||
|
||||
function buildGlobal(namespace, builder) {
|
||||
let body = [];
|
||||
let container = t.functionExpression(null, [t.identifier("global")], t.blockStatement(body));
|
||||
let tree = t.program([t.expressionStatement(t.callExpression(container, [helpers.get("selfGlobal")]))]);
|
||||
const body = [];
|
||||
const container = t.functionExpression(null, [t.identifier("global")], t.blockStatement(body));
|
||||
const tree = t.program([t.expressionStatement(t.callExpression(container, [helpers.get("selfGlobal")]))]);
|
||||
|
||||
body.push(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(
|
||||
@@ -39,7 +39,7 @@ function buildGlobal(namespace, builder) {
|
||||
}
|
||||
|
||||
function buildUmd(namespace, builder) {
|
||||
let body = [];
|
||||
const body = [];
|
||||
body.push(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(namespace, t.identifier("global"))
|
||||
]));
|
||||
@@ -63,7 +63,7 @@ function buildUmd(namespace, builder) {
|
||||
}
|
||||
|
||||
function buildVar(namespace, builder) {
|
||||
let body = [];
|
||||
const body = [];
|
||||
body.push(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(namespace, t.objectExpression([]))
|
||||
]));
|
||||
@@ -76,7 +76,7 @@ function buildHelpers(body, namespace, whitelist) {
|
||||
each(helpers.list, function (name) {
|
||||
if (whitelist && whitelist.indexOf(name) < 0) return;
|
||||
|
||||
let key = t.identifier(name);
|
||||
const key = t.identifier(name);
|
||||
body.push(t.expressionStatement(
|
||||
t.assignmentExpression("=", t.memberExpression(namespace, key), helpers.get(name))
|
||||
));
|
||||
@@ -86,15 +86,15 @@ export default function (
|
||||
whitelist?: Array<string>,
|
||||
outputType: "global" | "umd" | "var" = "global",
|
||||
) {
|
||||
let namespace = t.identifier("babelHelpers");
|
||||
const namespace = t.identifier("babelHelpers");
|
||||
|
||||
let builder = function (body) {
|
||||
const builder = function (body) {
|
||||
return buildHelpers(body, namespace, whitelist);
|
||||
};
|
||||
|
||||
let tree;
|
||||
|
||||
let build = {
|
||||
const build = {
|
||||
global: buildGlobal,
|
||||
umd: buildUmd,
|
||||
var: buildVar,
|
||||
|
||||
@@ -32,9 +32,9 @@ const INTERNAL_PLUGINS = [
|
||||
[shadowFunctionsPlugin]
|
||||
];
|
||||
|
||||
let errorVisitor = {
|
||||
const errorVisitor = {
|
||||
enter(path, state) {
|
||||
let loc = path.node.loc;
|
||||
const loc = path.node.loc;
|
||||
if (loc) {
|
||||
state.loc = loc;
|
||||
path.stop();
|
||||
@@ -69,7 +69,7 @@ export default class File extends Store {
|
||||
// All the "per preset" options are inherited from the main options.
|
||||
this.perPresetOpts = [];
|
||||
this.opts.presets.forEach((presetOpts) => {
|
||||
let perPresetOpts = Object.assign(Object.create(this.opts), presetOpts);
|
||||
const perPresetOpts = Object.assign(Object.create(this.opts), presetOpts);
|
||||
this.perPresetOpts.push(perPresetOpts);
|
||||
this.buildPluginsForOptions(perPresetOpts);
|
||||
});
|
||||
@@ -125,7 +125,7 @@ export default class File extends Store {
|
||||
|
||||
getMetadata() {
|
||||
let has = false;
|
||||
for (let node of (this.ast.program.body: Array<Object>)) {
|
||||
for (const node of (this.ast.program.body: Array<Object>)) {
|
||||
if (t.isModuleDeclaration(node)) {
|
||||
has = true;
|
||||
break;
|
||||
@@ -165,7 +165,7 @@ export default class File extends Store {
|
||||
filenameRelative: opts.filename
|
||||
});
|
||||
|
||||
let basenameRelative = path.basename(opts.filenameRelative);
|
||||
const basenameRelative = path.basename(opts.filenameRelative);
|
||||
|
||||
defaults(opts, {
|
||||
sourceFileName: basenameRelative,
|
||||
@@ -180,13 +180,13 @@ export default class File extends Store {
|
||||
return;
|
||||
}
|
||||
|
||||
let plugins: Array<[PluginPass, Object]> = opts.plugins.concat(INTERNAL_PLUGINS);
|
||||
let currentPluginVisitors = [];
|
||||
let currentPluginPasses = [];
|
||||
const plugins: Array<[PluginPass, Object]> = opts.plugins.concat(INTERNAL_PLUGINS);
|
||||
const currentPluginVisitors = [];
|
||||
const currentPluginPasses = [];
|
||||
|
||||
// init plugins!
|
||||
for (let ref of plugins) {
|
||||
let [plugin, pluginOpts] = ref; // todo: fix - can't embed in loop head because of flow bug
|
||||
for (const ref of plugins) {
|
||||
const [plugin, pluginOpts] = ref; // todo: fix - can't embed in loop head because of flow bug
|
||||
|
||||
currentPluginVisitors.push(plugin.visitor);
|
||||
currentPluginPasses.push(new PluginPass(this, plugin, pluginOpts));
|
||||
@@ -201,7 +201,7 @@ export default class File extends Store {
|
||||
}
|
||||
|
||||
getModuleName(): ?string {
|
||||
let opts = this.opts;
|
||||
const opts = this.opts;
|
||||
if (!opts.moduleIds) {
|
||||
return null;
|
||||
}
|
||||
@@ -224,7 +224,7 @@ export default class File extends Store {
|
||||
|
||||
if (opts.sourceRoot != null) {
|
||||
// remove sourceRoot from filename
|
||||
let sourceRootRegEx = new RegExp("^" + opts.sourceRoot + "\/?");
|
||||
const sourceRootRegEx = new RegExp("^" + opts.sourceRoot + "\/?");
|
||||
filenameRelative = filenameRelative.replace(sourceRootRegEx, "");
|
||||
}
|
||||
|
||||
@@ -245,20 +245,20 @@ export default class File extends Store {
|
||||
}
|
||||
|
||||
resolveModuleSource(source: string): string {
|
||||
let resolveModuleSource = this.opts.resolveModuleSource;
|
||||
const resolveModuleSource = this.opts.resolveModuleSource;
|
||||
if (resolveModuleSource) source = resolveModuleSource(source, this.opts.filename);
|
||||
return source;
|
||||
}
|
||||
|
||||
addImport(source: string, imported: string, name?: string = imported): Object {
|
||||
let alias = `${source}:${imported}`;
|
||||
const alias = `${source}:${imported}`;
|
||||
let id = this.dynamicImportIds[alias];
|
||||
|
||||
if (!id) {
|
||||
source = this.resolveModuleSource(source);
|
||||
id = this.dynamicImportIds[alias] = this.scope.generateUidIdentifier(name);
|
||||
|
||||
let specifiers = [];
|
||||
const specifiers = [];
|
||||
|
||||
if (imported === "*") {
|
||||
specifiers.push(t.importNamespaceSpecifier(id));
|
||||
@@ -268,7 +268,7 @@ export default class File extends Store {
|
||||
specifiers.push(t.importSpecifier(id, t.identifier(imported)));
|
||||
}
|
||||
|
||||
let declar = t.importDeclaration(specifiers, t.stringLiteral(source));
|
||||
const declar = t.importDeclaration(specifiers, t.stringLiteral(source));
|
||||
declar._blockHoist = 3;
|
||||
|
||||
this.path.unshiftContainer("body", declar);
|
||||
@@ -278,7 +278,7 @@ export default class File extends Store {
|
||||
}
|
||||
|
||||
addHelper(name: string): Object {
|
||||
let declar = this.declarations[name];
|
||||
const declar = this.declarations[name];
|
||||
if (declar) return declar;
|
||||
|
||||
if (!this.usedHelpers[name]) {
|
||||
@@ -286,17 +286,17 @@ export default class File extends Store {
|
||||
this.usedHelpers[name] = true;
|
||||
}
|
||||
|
||||
let generator = this.get("helperGenerator");
|
||||
let runtime = this.get("helpersNamespace");
|
||||
const generator = this.get("helperGenerator");
|
||||
const runtime = this.get("helpersNamespace");
|
||||
if (generator) {
|
||||
let res = generator(name);
|
||||
const res = generator(name);
|
||||
if (res) return res;
|
||||
} else if (runtime) {
|
||||
return t.memberExpression(runtime, t.identifier(name));
|
||||
}
|
||||
|
||||
let ref = getHelper(name);
|
||||
let uid = this.declarations[name] = this.scope.generateUidIdentifier(name);
|
||||
const ref = getHelper(name);
|
||||
const uid = this.declarations[name] = this.scope.generateUidIdentifier(name);
|
||||
|
||||
if (t.isFunctionExpression(ref) && !ref.id) {
|
||||
ref.body._compact = true;
|
||||
@@ -323,18 +323,18 @@ export default class File extends Store {
|
||||
): Object {
|
||||
// Generate a unique name based on the string literals so we dedupe
|
||||
// identical strings used in the program.
|
||||
let stringIds = raw.elements.map(function(string) {
|
||||
const stringIds = raw.elements.map(function(string) {
|
||||
return string.value;
|
||||
});
|
||||
let name = `${helperName}_${raw.elements.length}_${stringIds.join(",")}`;
|
||||
const name = `${helperName}_${raw.elements.length}_${stringIds.join(",")}`;
|
||||
|
||||
let declar = this.declarations[name];
|
||||
const declar = this.declarations[name];
|
||||
if (declar) return declar;
|
||||
|
||||
let uid = this.declarations[name] = this.scope.generateUidIdentifier("templateObject");
|
||||
const uid = this.declarations[name] = this.scope.generateUidIdentifier("templateObject");
|
||||
|
||||
let helperId = this.addHelper(helperName);
|
||||
let init = t.callExpression(helperId, [strings, raw]);
|
||||
const helperId = this.addHelper(helperName);
|
||||
const init = t.callExpression(helperId, [strings, raw]);
|
||||
init._compact = true;
|
||||
this.scope.push({
|
||||
id: uid,
|
||||
@@ -345,9 +345,9 @@ export default class File extends Store {
|
||||
}
|
||||
|
||||
buildCodeFrameError(node: Object, msg: string, Error: typeof Error = SyntaxError): Error {
|
||||
let loc = node && (node.loc || node._loc);
|
||||
const loc = node && (node.loc || node._loc);
|
||||
|
||||
let err = new Error(msg);
|
||||
const err = new Error(msg);
|
||||
|
||||
if (loc) {
|
||||
err.loc = loc.start;
|
||||
@@ -367,13 +367,13 @@ export default class File extends Store {
|
||||
}
|
||||
|
||||
mergeSourceMap(map: Object) {
|
||||
let inputMap = this.opts.inputSourceMap;
|
||||
const inputMap = this.opts.inputSourceMap;
|
||||
|
||||
if (inputMap) {
|
||||
let inputMapConsumer = new sourceMap.SourceMapConsumer(inputMap);
|
||||
let outputMapConsumer = new sourceMap.SourceMapConsumer(map);
|
||||
const inputMapConsumer = new sourceMap.SourceMapConsumer(inputMap);
|
||||
const outputMapConsumer = new sourceMap.SourceMapConsumer(map);
|
||||
|
||||
let mergedGenerator = new sourceMap.SourceMapGenerator({
|
||||
const mergedGenerator = new sourceMap.SourceMapGenerator({
|
||||
file: inputMapConsumer.file,
|
||||
sourceRoot: inputMapConsumer.sourceRoot
|
||||
});
|
||||
@@ -402,7 +402,7 @@ export default class File extends Store {
|
||||
}
|
||||
});
|
||||
|
||||
let mergedMap = mergedGenerator.toJSON();
|
||||
const mergedMap = mergedGenerator.toJSON();
|
||||
inputMap.mappings = mergedMap.mappings;
|
||||
return inputMap;
|
||||
} else {
|
||||
@@ -419,8 +419,8 @@ export default class File extends Store {
|
||||
|
||||
if (parserOpts.parser) {
|
||||
if (typeof parserOpts.parser === "string") {
|
||||
let dirname = path.dirname(this.opts.filename) || process.cwd();
|
||||
let parser = resolve(parserOpts.parser, dirname);
|
||||
const dirname = path.dirname(this.opts.filename) || process.cwd();
|
||||
const parser = resolve(parserOpts.parser, dirname);
|
||||
if (parser) {
|
||||
parseCode = require(parser).parse;
|
||||
} else {
|
||||
@@ -439,7 +439,7 @@ export default class File extends Store {
|
||||
}
|
||||
|
||||
this.log.debug("Parse start");
|
||||
let ast = parseCode(code, parserOpts || this.parserOpts);
|
||||
const ast = parseCode(code, parserOpts || this.parserOpts);
|
||||
this.log.debug("Parse stop");
|
||||
return ast;
|
||||
}
|
||||
@@ -472,7 +472,7 @@ export default class File extends Store {
|
||||
this.log.debug("Start transform traverse");
|
||||
|
||||
// merge all plugin visitors into a single visitor
|
||||
let visitor = traverse.visitors.merge(this.pluginVisitors[i], pluginPasses, this.opts.wrapPluginVisitorMethod);
|
||||
const visitor = traverse.visitors.merge(this.pluginVisitors[i], pluginPasses, this.opts.wrapPluginVisitorMethod);
|
||||
traverse(this.ast, visitor, this.scope);
|
||||
|
||||
this.log.debug("End transform traverse");
|
||||
@@ -500,7 +500,7 @@ export default class File extends Store {
|
||||
|
||||
let message = err.message = `${this.opts.filename}: ${err.message}`;
|
||||
|
||||
let loc = err.loc;
|
||||
const loc = err.loc;
|
||||
if (loc) {
|
||||
err.codeFrame = codeFrame(code, loc.line, loc.column + 1, this.opts);
|
||||
message += "\n" + err.codeFrame;
|
||||
@@ -513,7 +513,7 @@ export default class File extends Store {
|
||||
}
|
||||
|
||||
if (err.stack) {
|
||||
let newStack = err.stack.replace(err.message, message);
|
||||
const newStack = err.stack.replace(err.message, message);
|
||||
err.stack = newStack;
|
||||
}
|
||||
|
||||
@@ -529,28 +529,28 @@ export default class File extends Store {
|
||||
|
||||
parseCode() {
|
||||
this.parseShebang();
|
||||
let ast = this.parse(this.code);
|
||||
const ast = this.parse(this.code);
|
||||
this.addAst(ast);
|
||||
}
|
||||
|
||||
shouldIgnore() {
|
||||
let opts = this.opts;
|
||||
const opts = this.opts;
|
||||
return util.shouldIgnore(opts.filename, opts.ignore, opts.only);
|
||||
}
|
||||
|
||||
call(key: "pre" | "post", pluginPasses: Array<PluginPass>) {
|
||||
for (let pass of pluginPasses) {
|
||||
let plugin = pass.plugin;
|
||||
let fn = plugin[key];
|
||||
for (const pass of pluginPasses) {
|
||||
const plugin = pass.plugin;
|
||||
const fn = plugin[key];
|
||||
if (fn) fn.call(pass, this);
|
||||
}
|
||||
}
|
||||
|
||||
parseInputSourceMap(code: string): string {
|
||||
let opts = this.opts;
|
||||
const opts = this.opts;
|
||||
|
||||
if (opts.inputSourceMap !== false) {
|
||||
let inputMap = convertSourceMap.fromSource(code);
|
||||
const inputMap = convertSourceMap.fromSource(code);
|
||||
if (inputMap) {
|
||||
opts.inputSourceMap = inputMap.toObject();
|
||||
code = convertSourceMap.removeComments(code);
|
||||
@@ -561,7 +561,7 @@ export default class File extends Store {
|
||||
}
|
||||
|
||||
parseShebang() {
|
||||
let shebangMatch = shebangRegex.exec(this.code);
|
||||
const shebangMatch = shebangRegex.exec(this.code);
|
||||
if (shebangMatch) {
|
||||
this.shebang = shebangMatch[0];
|
||||
this.code = this.code.replace(shebangRegex, "");
|
||||
@@ -569,7 +569,7 @@ export default class File extends Store {
|
||||
}
|
||||
|
||||
makeResult({ code, map, ast, ignored }: BabelFileResult): BabelFileResult {
|
||||
let result = {
|
||||
const result = {
|
||||
metadata: null,
|
||||
options: this.opts,
|
||||
ignored: !!ignored,
|
||||
@@ -594,10 +594,10 @@ export default class File extends Store {
|
||||
}
|
||||
|
||||
generate(): BabelFileResult {
|
||||
let opts = this.opts;
|
||||
let ast = this.ast;
|
||||
const opts = this.opts;
|
||||
const ast = this.ast;
|
||||
|
||||
let result: BabelFileResult = { ast };
|
||||
const result: BabelFileResult = { ast };
|
||||
if (!opts.code) return this.makeResult(result);
|
||||
|
||||
let gen = generate;
|
||||
@@ -605,8 +605,8 @@ export default class File extends Store {
|
||||
gen = opts.generatorOpts.generator;
|
||||
|
||||
if (typeof gen === "string") {
|
||||
let dirname = path.dirname(this.opts.filename) || process.cwd();
|
||||
let generator = resolve(gen, dirname);
|
||||
const dirname = path.dirname(this.opts.filename) || process.cwd();
|
||||
const generator = resolve(gen, dirname);
|
||||
if (generator) {
|
||||
gen = require(generator).print;
|
||||
} else {
|
||||
@@ -617,7 +617,7 @@ export default class File extends Store {
|
||||
|
||||
this.log.debug("Generation start");
|
||||
|
||||
let _result = gen(ast, opts.generatorOpts ? Object.assign(opts, opts.generatorOpts) : opts, this.code);
|
||||
const _result = gen(ast, opts.generatorOpts ? Object.assign(opts, opts.generatorOpts) : opts, this.code);
|
||||
result.code = _result.code;
|
||||
result.map = _result.map;
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import type File from "./index";
|
||||
import buildDebug from "debug/node";
|
||||
|
||||
let verboseDebug = buildDebug("babel:verbose");
|
||||
let generalDebug = buildDebug("babel");
|
||||
const verboseDebug = buildDebug("babel:verbose");
|
||||
const generalDebug = buildDebug("babel");
|
||||
|
||||
let seenDeprecatedMessages = [];
|
||||
const seenDeprecatedMessages = [];
|
||||
|
||||
export default class Logger {
|
||||
constructor(file: File, filename: string) {
|
||||
|
||||
@@ -1,28 +1,28 @@
|
||||
import * as t from "babel-types";
|
||||
|
||||
export let ModuleDeclaration = {
|
||||
export const ModuleDeclaration = {
|
||||
enter(path, file) {
|
||||
let { node } = path;
|
||||
const { node } = path;
|
||||
if (node.source) {
|
||||
node.source.value = file.resolveModuleSource(node.source.value);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export let ImportDeclaration = {
|
||||
export const ImportDeclaration = {
|
||||
exit(path, file) {
|
||||
let { node } = path;
|
||||
const { node } = path;
|
||||
|
||||
let specifiers = [];
|
||||
let imported = [];
|
||||
const specifiers = [];
|
||||
const imported = [];
|
||||
file.metadata.modules.imports.push({
|
||||
source: node.source.value,
|
||||
imported,
|
||||
specifiers
|
||||
});
|
||||
|
||||
for (let specifier of (path.get("specifiers"): Array<Object>)) {
|
||||
let local = specifier.node.local.name;
|
||||
for (const specifier of (path.get("specifiers"): Array<Object>)) {
|
||||
const local = specifier.node.local.name;
|
||||
|
||||
if (specifier.isImportDefaultSpecifier()) {
|
||||
imported.push("default");
|
||||
@@ -34,7 +34,7 @@ export let ImportDeclaration = {
|
||||
}
|
||||
|
||||
if (specifier.isImportSpecifier()) {
|
||||
let importedName = specifier.node.imported.name;
|
||||
const importedName = specifier.node.imported.name;
|
||||
imported.push(importedName);
|
||||
specifiers.push({
|
||||
kind: "named",
|
||||
@@ -55,18 +55,18 @@ export let ImportDeclaration = {
|
||||
};
|
||||
|
||||
export function ExportDeclaration(path, file) {
|
||||
let { node } = path;
|
||||
const { node } = path;
|
||||
|
||||
let source = node.source ? node.source.value : null;
|
||||
let exports = file.metadata.modules.exports;
|
||||
const source = node.source ? node.source.value : null;
|
||||
const exports = file.metadata.modules.exports;
|
||||
|
||||
// export function foo() {}
|
||||
// export let foo = "bar";
|
||||
let declar = path.get("declaration");
|
||||
const declar = path.get("declaration");
|
||||
if (declar.isStatement()) {
|
||||
let bindings = declar.getBindingIdentifiers();
|
||||
const bindings = declar.getBindingIdentifiers();
|
||||
|
||||
for (let name in bindings) {
|
||||
for (const name in bindings) {
|
||||
exports.exported.push(name);
|
||||
exports.specifiers.push({
|
||||
kind: "local",
|
||||
@@ -77,8 +77,8 @@ export function ExportDeclaration(path, file) {
|
||||
}
|
||||
|
||||
if (path.isExportNamedDeclaration() && node.specifiers) {
|
||||
for (let specifier of (node.specifiers: Array<Object>)) {
|
||||
let exported = specifier.exported.name;
|
||||
for (const specifier of (node.specifiers: Array<Object>)) {
|
||||
const exported = specifier.exported.name;
|
||||
exports.exported.push(exported);
|
||||
|
||||
// export foo from "bar";
|
||||
@@ -100,7 +100,7 @@ export function ExportDeclaration(path, file) {
|
||||
});
|
||||
}
|
||||
|
||||
let local = specifier.local;
|
||||
const local = specifier.local;
|
||||
if (!local) continue;
|
||||
|
||||
// export { foo } from "bar";
|
||||
|
||||
@@ -6,15 +6,15 @@ import isAbsolute from "path-is-absolute";
|
||||
import path from "path";
|
||||
import fs from "fs";
|
||||
|
||||
let existsCache = {};
|
||||
let jsonCache = {};
|
||||
const existsCache = {};
|
||||
const jsonCache = {};
|
||||
|
||||
const BABELIGNORE_FILENAME = ".babelignore";
|
||||
const BABELRC_FILENAME = ".babelrc";
|
||||
const PACKAGE_FILENAME = "package.json";
|
||||
|
||||
function exists(filename) {
|
||||
let cached = existsCache[filename];
|
||||
const cached = existsCache[filename];
|
||||
if (cached == null) {
|
||||
return existsCache[filename] = fs.existsSync(filename);
|
||||
} else {
|
||||
@@ -23,8 +23,8 @@ function exists(filename) {
|
||||
}
|
||||
|
||||
export default function buildConfigChain(opts: Object = {}, log?: Logger) {
|
||||
let filename = opts.filename;
|
||||
let builder = new ConfigChainBuilder(log);
|
||||
const filename = opts.filename;
|
||||
const builder = new ConfigChainBuilder(log);
|
||||
|
||||
// resolve all .babelrc files
|
||||
if (opts.babelrc !== false) {
|
||||
@@ -59,20 +59,20 @@ class ConfigChainBuilder {
|
||||
|
||||
while (loc !== (loc = path.dirname(loc))) {
|
||||
if (!foundConfig) {
|
||||
let configLoc = path.join(loc, BABELRC_FILENAME);
|
||||
const configLoc = path.join(loc, BABELRC_FILENAME);
|
||||
if (exists(configLoc)) {
|
||||
this.addConfig(configLoc);
|
||||
foundConfig = true;
|
||||
}
|
||||
|
||||
let pkgLoc = path.join(loc, PACKAGE_FILENAME);
|
||||
const pkgLoc = path.join(loc, PACKAGE_FILENAME);
|
||||
if (!foundConfig && exists(pkgLoc)) {
|
||||
foundConfig = this.addConfig(pkgLoc, "babel", JSON);
|
||||
}
|
||||
}
|
||||
|
||||
if (!foundIgnore) {
|
||||
let ignoreLoc = path.join(loc, BABELIGNORE_FILENAME);
|
||||
const ignoreLoc = path.join(loc, BABELIGNORE_FILENAME);
|
||||
if (exists(ignoreLoc)) {
|
||||
this.addIgnoreConfig(ignoreLoc);
|
||||
foundIgnore = true;
|
||||
@@ -84,7 +84,7 @@ class ConfigChainBuilder {
|
||||
}
|
||||
|
||||
addIgnoreConfig(loc) {
|
||||
let file = fs.readFileSync(loc, "utf8");
|
||||
const file = fs.readFileSync(loc, "utf8");
|
||||
let lines = file.split("\n");
|
||||
|
||||
lines = lines
|
||||
@@ -107,7 +107,7 @@ class ConfigChainBuilder {
|
||||
|
||||
this.resolvedConfigs.push(loc);
|
||||
|
||||
let content = fs.readFileSync(loc, "utf8");
|
||||
const content = fs.readFileSync(loc, "utf8");
|
||||
let options;
|
||||
|
||||
try {
|
||||
@@ -144,7 +144,7 @@ class ConfigChainBuilder {
|
||||
|
||||
// add extends clause
|
||||
if (options.extends) {
|
||||
let extendsLoc = resolve(options.extends, dirname);
|
||||
const extendsLoc = resolve(options.extends, dirname);
|
||||
if (extendsLoc) {
|
||||
this.addConfig(extendsLoc);
|
||||
} else {
|
||||
@@ -162,7 +162,7 @@ class ConfigChainBuilder {
|
||||
|
||||
// env
|
||||
let envOpts;
|
||||
let envKey = process.env.BABEL_ENV || process.env.NODE_ENV || "development";
|
||||
const envKey = process.env.BABEL_ENV || process.env.NODE_ENV || "development";
|
||||
if (options.env) {
|
||||
envOpts = options.env[envKey];
|
||||
delete options.env;
|
||||
|
||||
@@ -4,7 +4,7 @@ import config from "./config";
|
||||
export { config };
|
||||
|
||||
export function normaliseOptions(options: Object = {}): Object {
|
||||
for (let key in options) {
|
||||
for (const key in options) {
|
||||
let val = options[key];
|
||||
if (val == null) continue;
|
||||
|
||||
@@ -12,7 +12,7 @@ export function normaliseOptions(options: Object = {}): Object {
|
||||
if (opt && opt.alias) opt = config[opt.alias];
|
||||
if (!opt) continue;
|
||||
|
||||
let parser = parsers[opt.type];
|
||||
const parser = parsers[opt.type];
|
||||
if (parser) val = parser(val);
|
||||
|
||||
options[key] = val;
|
||||
|
||||
@@ -53,7 +53,7 @@ export default class OptionManager {
|
||||
}>;
|
||||
|
||||
static memoisePluginContainer(fn, loc, i, alias) {
|
||||
for (let cache of (OptionManager.memoisedPlugins: Array<Object>)) {
|
||||
for (const cache of (OptionManager.memoisedPlugins: Array<Object>)) {
|
||||
if (cache.container === fn) return cache.plugin;
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ export default class OptionManager {
|
||||
}
|
||||
|
||||
if (typeof obj === "object") {
|
||||
let plugin = new Plugin(obj, alias);
|
||||
const plugin = new Plugin(obj, alias);
|
||||
OptionManager.memoisedPlugins.push({
|
||||
container: fn,
|
||||
plugin: plugin
|
||||
@@ -78,10 +78,10 @@ export default class OptionManager {
|
||||
}
|
||||
|
||||
static createBareOptions() {
|
||||
let opts = {};
|
||||
const opts = {};
|
||||
|
||||
for (let key in config) {
|
||||
let opt = config[key];
|
||||
for (const key in config) {
|
||||
const opt = config[key];
|
||||
opts[key] = clone(opt.default);
|
||||
}
|
||||
|
||||
@@ -120,11 +120,11 @@ export default class OptionManager {
|
||||
plugin = val;
|
||||
}
|
||||
|
||||
let alias = typeof plugin === "string" ? plugin : `${loc}$${i}`;
|
||||
const alias = typeof plugin === "string" ? plugin : `${loc}$${i}`;
|
||||
|
||||
// allow plugins to be specified as strings
|
||||
if (typeof plugin === "string") {
|
||||
let pluginLoc = resolvePlugin(plugin, dirname);
|
||||
const pluginLoc = resolvePlugin(plugin, dirname);
|
||||
if (pluginLoc) {
|
||||
plugin = require(pluginLoc);
|
||||
} else {
|
||||
@@ -164,7 +164,7 @@ export default class OptionManager {
|
||||
}
|
||||
|
||||
//
|
||||
let opts = cloneDeepWith(rawOpts, (val) => {
|
||||
const opts = cloneDeepWith(rawOpts, (val) => {
|
||||
if (val instanceof Plugin) {
|
||||
return val;
|
||||
}
|
||||
@@ -174,16 +174,16 @@ export default class OptionManager {
|
||||
dirname = dirname || process.cwd();
|
||||
loc = loc || alias;
|
||||
|
||||
for (let key in opts) {
|
||||
let option = config[key];
|
||||
for (const key in opts) {
|
||||
const option = config[key];
|
||||
|
||||
// check for an unknown option
|
||||
if (!option && this.log) {
|
||||
if (removed[key]) {
|
||||
this.log.error(`Using removed Babel 5 option: ${alias}.${key} - ${removed[key].message}`, ReferenceError);
|
||||
} else {
|
||||
let unknownOptErr = `Unknown option: ${alias}.${key}. Check out http://babeljs.io/docs/usage/options/ for more information about options.`;
|
||||
let presetConfigErr = "A common cause of this error is the presence of a configuration options object without the corresponding preset name. Example:\n\nInvalid:\n `{ presets: [{option: value}] }`\nValid:\n `{ presets: [['presetName', {option: value}]] }`\n\nFor more detailed information on preset configuration, please see http://babeljs.io/docs/plugins/#pluginpresets-options.";
|
||||
const unknownOptErr = `Unknown option: ${alias}.${key}. Check out http://babeljs.io/docs/usage/options/ for more information about options.`;
|
||||
const presetConfigErr = "A common cause of this error is the presence of a configuration options object without the corresponding preset name. Example:\n\nInvalid:\n `{ presets: [{option: value}] }`\nValid:\n `{ presets: [['presetName', {option: value}]] }`\n\nFor more detailed information on preset configuration, please see http://babeljs.io/docs/plugins/#pluginpresets-options.";
|
||||
|
||||
this.log.error(`${unknownOptErr}\n\n${presetConfigErr}`, ReferenceError);
|
||||
}
|
||||
@@ -316,11 +316,11 @@ export default class OptionManager {
|
||||
}
|
||||
|
||||
normaliseOptions() {
|
||||
let opts = this.options;
|
||||
const opts = this.options;
|
||||
|
||||
for (let key in config) {
|
||||
let option = config[key];
|
||||
let val = opts[key];
|
||||
for (const key in config) {
|
||||
const option = config[key];
|
||||
const val = opts[key];
|
||||
|
||||
// optional
|
||||
if (!val && option.optional) continue;
|
||||
@@ -335,7 +335,7 @@ export default class OptionManager {
|
||||
}
|
||||
|
||||
init(opts: Object = {}): Object {
|
||||
for (let config of buildConfigChain(opts, this.log)) {
|
||||
for (const config of buildConfigChain(opts, this.log)) {
|
||||
this.mergeOptions(config);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import slash from "slash";
|
||||
import * as util from "../../../util";
|
||||
|
||||
export let filename = slash;
|
||||
export const filename = slash;
|
||||
|
||||
export function boolean(val: any): boolean {
|
||||
return !!val;
|
||||
|
||||
@@ -20,7 +20,7 @@ export default new Plugin({
|
||||
exit({ node }) {
|
||||
let hasChange = false;
|
||||
for (let i = 0; i < node.body.length; i++) {
|
||||
let bodyNode = node.body[i];
|
||||
const bodyNode = node.body[i];
|
||||
if (bodyNode && bodyNode._blockHoist != null) {
|
||||
hasChange = true;
|
||||
break;
|
||||
|
||||
@@ -41,10 +41,10 @@ function shouldShadow(path, shadowPath) {
|
||||
|
||||
function remap(path, key) {
|
||||
// ensure that we're shadowed
|
||||
let shadowPath = path.inShadow(key);
|
||||
const shadowPath = path.inShadow(key);
|
||||
if (!shouldShadow(path, shadowPath)) return;
|
||||
|
||||
let shadowFunction = path.node._shadowedFunctionLiteral;
|
||||
const shadowFunction = path.node._shadowedFunctionLiteral;
|
||||
|
||||
let currentFunction;
|
||||
let passedShadowFunction = false;
|
||||
@@ -91,15 +91,15 @@ function remap(path, key) {
|
||||
// binding since arrow function syntax already does that.
|
||||
if (!passedShadowFunction) return;
|
||||
|
||||
let cached = fnPath.getData(key);
|
||||
const cached = fnPath.getData(key);
|
||||
if (cached) return path.replaceWith(cached);
|
||||
|
||||
let id = path.scope.generateUidIdentifier(key);
|
||||
const id = path.scope.generateUidIdentifier(key);
|
||||
|
||||
fnPath.setData(key, id);
|
||||
|
||||
let classPath = fnPath.findParent((p) => p.isClass());
|
||||
let hasSuperClass = !!(classPath && classPath.node && classPath.node.superClass);
|
||||
const classPath = fnPath.findParent((p) => p.isClass());
|
||||
const hasSuperClass = !!(classPath && classPath.node && classPath.node.superClass);
|
||||
|
||||
if (key === "this" && fnPath.isMethod({kind: "constructor"}) && hasSuperClass) {
|
||||
fnPath.scope.push({ id });
|
||||
|
||||
@@ -11,7 +11,7 @@ export default class Pipeline {
|
||||
}
|
||||
|
||||
pretransform(code: string, opts?: Object): BabelFileResult {
|
||||
let file = new File(opts, this);
|
||||
const file = new File(opts, this);
|
||||
return file.wrap(code, function () {
|
||||
file.addCode(code);
|
||||
file.parseCode(code);
|
||||
@@ -20,7 +20,7 @@ export default class Pipeline {
|
||||
}
|
||||
|
||||
transform(code: string, opts?: Object): BabelFileResult {
|
||||
let file = new File(opts, this);
|
||||
const file = new File(opts, this);
|
||||
return file.wrap(code, function () {
|
||||
file.addCode(code);
|
||||
file.parseCode(code);
|
||||
@@ -40,7 +40,7 @@ export default class Pipeline {
|
||||
transformFromAst(ast: Object, code: string, opts: Object): BabelFileResult {
|
||||
ast = normalizeAst(ast);
|
||||
|
||||
let file = new File(opts, this);
|
||||
const file = new File(opts, this);
|
||||
return file.wrap(code, function () {
|
||||
file.addCode(code);
|
||||
file.addAst(ast);
|
||||
|
||||
@@ -31,7 +31,7 @@ export default class Plugin extends Store {
|
||||
visitor: Object;
|
||||
|
||||
take(key) {
|
||||
let val = this.raw[key];
|
||||
const val = this.raw[key];
|
||||
delete this.raw[key];
|
||||
return val;
|
||||
}
|
||||
@@ -40,13 +40,13 @@ export default class Plugin extends Store {
|
||||
if (!target[key]) return this[key];
|
||||
if (!this[key]) return target[key];
|
||||
|
||||
let fns: Array<?Function> = [target[key], this[key]];
|
||||
const fns: Array<?Function> = [target[key], this[key]];
|
||||
|
||||
return function (...args) {
|
||||
let val;
|
||||
for (let fn of fns) {
|
||||
for (const fn of fns) {
|
||||
if (fn) {
|
||||
let ret = fn.apply(this, args);
|
||||
const ret = fn.apply(this, args);
|
||||
if (ret != null) val = ret;
|
||||
}
|
||||
}
|
||||
@@ -77,13 +77,13 @@ export default class Plugin extends Store {
|
||||
|
||||
this.maybeInherit(loc);
|
||||
|
||||
for (let key in this.raw) {
|
||||
for (const key in this.raw) {
|
||||
throw new Error(messages.get("pluginInvalidProperty", loc, i, key));
|
||||
}
|
||||
}
|
||||
|
||||
normaliseVisitor(visitor: Object): Object {
|
||||
for (let key of GLOBAL_VISITOR_PROPS) {
|
||||
for (const key of GLOBAL_VISITOR_PROPS) {
|
||||
if (visitor[key]) {
|
||||
throw new Error("Plugins aren't allowed to specify catch-all enter/exit handlers. Please target individual nodes.");
|
||||
}
|
||||
|
||||
@@ -15,8 +15,8 @@ export { inherits, inspect } from "util";
|
||||
*/
|
||||
|
||||
export function canCompile(filename: string, altExts?: Array<string>): boolean {
|
||||
let exts = altExts || canCompile.EXTENSIONS;
|
||||
let ext = path.extname(filename);
|
||||
const exts = altExts || canCompile.EXTENSIONS;
|
||||
const ext = path.extname(filename);
|
||||
return includes(exts, ext);
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ export function regexify(val: any): RegExp {
|
||||
if (startsWith(val, "./") || startsWith(val, "*/")) val = val.slice(2);
|
||||
if (startsWith(val, "**/")) val = val.slice(3);
|
||||
|
||||
let regex = minimatch.makeRe(val, { nocase: true });
|
||||
const regex = minimatch.makeRe(val, { nocase: true });
|
||||
return new RegExp(regex.source.slice(1, -1), "i");
|
||||
}
|
||||
|
||||
@@ -119,12 +119,12 @@ export function shouldIgnore(
|
||||
filename = filename.replace(/\\/g, "/");
|
||||
|
||||
if (only) {
|
||||
for (let pattern of only) {
|
||||
for (const pattern of only) {
|
||||
if (_shouldIgnore(pattern, filename)) return false;
|
||||
}
|
||||
return true;
|
||||
} else if (ignore.length) {
|
||||
for (let pattern of ignore) {
|
||||
for (const pattern of ignore) {
|
||||
if (_shouldIgnore(pattern, filename)) return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
let babel = require("../lib/api/node");
|
||||
let buildExternalHelpers = require("../lib/tools/build-external-helpers");
|
||||
let sourceMap = require("source-map");
|
||||
let assert = require("assert");
|
||||
let Plugin = require("../lib/transformation/plugin");
|
||||
let generator = require("babel-generator").default;
|
||||
const babel = require("../lib/api/node");
|
||||
const buildExternalHelpers = require("../lib/tools/build-external-helpers");
|
||||
const sourceMap = require("source-map");
|
||||
const assert = require("assert");
|
||||
const Plugin = require("../lib/transformation/plugin");
|
||||
const generator = require("babel-generator").default;
|
||||
|
||||
function assertIgnored(result) {
|
||||
assert.ok(result.ignored);
|
||||
@@ -23,7 +23,7 @@ function transformAsync(code, opts) {
|
||||
}
|
||||
|
||||
describe("parser and generator options", function() {
|
||||
let recast = {
|
||||
const recast = {
|
||||
parse: function(code, opts) {
|
||||
return opts.parser.parse(code);
|
||||
},
|
||||
@@ -46,13 +46,13 @@ describe("parser and generator options", function() {
|
||||
}
|
||||
|
||||
it("options", function() {
|
||||
let string = "original;";
|
||||
const string = "original;";
|
||||
assert.deepEqual(newTransform(string).ast, babel.transform(string).ast);
|
||||
assert.equal(newTransform(string).code, string);
|
||||
});
|
||||
|
||||
it("experimental syntax", function() {
|
||||
let experimental = "var a: number = 1;";
|
||||
const experimental = "var a: number = 1;";
|
||||
|
||||
assert.deepEqual(newTransform(experimental).ast, babel.transform(experimental, {
|
||||
parserOpts: {
|
||||
@@ -82,7 +82,7 @@ describe("parser and generator options", function() {
|
||||
});
|
||||
|
||||
it("other options", function() {
|
||||
let experimental = "if (true) {\n import a from 'a';\n}";
|
||||
const experimental = "if (true) {\n import a from 'a';\n}";
|
||||
|
||||
assert.notEqual(newTransform(experimental).ast, babel.transform(experimental, {
|
||||
parserOpts: {
|
||||
@@ -199,7 +199,7 @@ describe("api", function () {
|
||||
new Plugin({
|
||||
visitor: {
|
||||
Function: function(path) {
|
||||
let alias = path.scope.getProgramParent().path.get("body")[0].node;
|
||||
const alias = path.scope.getProgramParent().path.get("body")[0].node;
|
||||
if (!babel.types.isTypeAlias(alias)) return;
|
||||
|
||||
// In case of `passPerPreset` being `false`, the
|
||||
@@ -264,7 +264,7 @@ describe("api", function () {
|
||||
});
|
||||
|
||||
it("source map merging", function () {
|
||||
let result = babel.transform([
|
||||
const result = babel.transform([
|
||||
"function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }",
|
||||
"",
|
||||
"let Foo = function Foo() {",
|
||||
@@ -288,7 +288,7 @@ describe("api", function () {
|
||||
"};"
|
||||
].join("\n"), result.code);
|
||||
|
||||
let consumer = new sourceMap.SourceMapConsumer(result.map);
|
||||
const consumer = new sourceMap.SourceMapConsumer(result.map);
|
||||
|
||||
assert.deepEqual(consumer.originalPositionFor({
|
||||
line: 7,
|
||||
@@ -318,7 +318,7 @@ describe("api", function () {
|
||||
auxiliaryCommentBefore: "before",
|
||||
auxiliaryCommentAfter: "after",
|
||||
plugins: [function (babel) {
|
||||
let t = babel.types;
|
||||
const t = babel.types;
|
||||
return {
|
||||
visitor: {
|
||||
Program: function (path) {
|
||||
@@ -539,8 +539,8 @@ describe("api", function () {
|
||||
});
|
||||
|
||||
describe("env option", function () {
|
||||
let oldBabelEnv = process.env.BABEL_ENV;
|
||||
let oldNodeEnv = process.env.NODE_ENV;
|
||||
const oldBabelEnv = process.env.BABEL_ENV;
|
||||
const oldNodeEnv = process.env.NODE_ENV;
|
||||
|
||||
setup(function () {
|
||||
// Tests need to run with the default and specific values for these. They
|
||||
@@ -555,7 +555,7 @@ describe("api", function () {
|
||||
});
|
||||
|
||||
it("default", function () {
|
||||
let result = babel.transform("foo;", {
|
||||
const result = babel.transform("foo;", {
|
||||
env: {
|
||||
development: { code: false }
|
||||
}
|
||||
@@ -566,7 +566,7 @@ describe("api", function () {
|
||||
|
||||
it("BABEL_ENV", function () {
|
||||
process.env.BABEL_ENV = "foo";
|
||||
let result = babel.transform("foo;", {
|
||||
const result = babel.transform("foo;", {
|
||||
env: {
|
||||
foo: { code: false }
|
||||
}
|
||||
@@ -576,7 +576,7 @@ describe("api", function () {
|
||||
|
||||
it("NODE_ENV", function () {
|
||||
process.env.NODE_ENV = "foo";
|
||||
let result = babel.transform("foo;", {
|
||||
const result = babel.transform("foo;", {
|
||||
env: {
|
||||
foo: { code: false }
|
||||
}
|
||||
@@ -586,8 +586,8 @@ describe("api", function () {
|
||||
});
|
||||
|
||||
it("resolveModuleSource option", function () {
|
||||
let actual = "import foo from \"foo-import-default\";\nimport \"foo-import-bare\";\nexport { foo } from \"foo-export-named\";";
|
||||
let expected = "import foo from \"resolved/foo-import-default\";\nimport \"resolved/foo-import-bare\";\nexport { foo } from \"resolved/foo-export-named\";";
|
||||
const actual = "import foo from \"foo-import-default\";\nimport \"foo-import-bare\";\nexport { foo } from \"foo-export-named\";";
|
||||
const expected = "import foo from \"resolved/foo-import-default\";\nimport \"resolved/foo-import-bare\";\nexport { foo } from \"resolved/foo-export-named\";";
|
||||
|
||||
return transformAsync(actual, {
|
||||
resolveModuleSource: function (originalSource) {
|
||||
@@ -600,25 +600,25 @@ describe("api", function () {
|
||||
|
||||
describe("buildExternalHelpers", function () {
|
||||
it("all", function () {
|
||||
let script = buildExternalHelpers();
|
||||
const script = buildExternalHelpers();
|
||||
assert.ok(script.indexOf("classCallCheck") >= -1);
|
||||
assert.ok(script.indexOf("inherits") >= 0);
|
||||
});
|
||||
|
||||
it("whitelist", function () {
|
||||
let script = buildExternalHelpers(["inherits"]);
|
||||
const script = buildExternalHelpers(["inherits"]);
|
||||
assert.ok(script.indexOf("classCallCheck") === -1);
|
||||
assert.ok(script.indexOf("inherits") >= 0);
|
||||
});
|
||||
|
||||
it("empty whitelist", function () {
|
||||
let script = buildExternalHelpers([]);
|
||||
const script = buildExternalHelpers([]);
|
||||
assert.ok(script.indexOf("classCallCheck") === -1);
|
||||
assert.ok(script.indexOf("inherits") === -1);
|
||||
});
|
||||
|
||||
it("underscored", function () {
|
||||
let script = buildExternalHelpers(["typeof"]);
|
||||
const script = buildExternalHelpers(["typeof"]);
|
||||
assert.ok(script.indexOf("typeof") >= 0);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
let browserify = require("browserify");
|
||||
let assert = require("assert");
|
||||
let path = require("path");
|
||||
let vm = require("vm");
|
||||
const browserify = require("browserify");
|
||||
const assert = require("assert");
|
||||
const path = require("path");
|
||||
const vm = require("vm");
|
||||
|
||||
describe("browserify", function() {
|
||||
it("babel/register may be used without breaking browserify", function(done) {
|
||||
let bundler = browserify(path.join(__dirname, "fixtures/browserify/register.js"));
|
||||
const bundler = browserify(path.join(__dirname, "fixtures/browserify/register.js"));
|
||||
|
||||
bundler.bundle(function(err, bundle) {
|
||||
if (err) return done(err);
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
let assert = require("assert");
|
||||
let path = require("path");
|
||||
let buildConfigChain = require("../lib/transformation/file/options/build-config-chain");
|
||||
const assert = require("assert");
|
||||
const path = require("path");
|
||||
const buildConfigChain = require("../lib/transformation/file/options/build-config-chain");
|
||||
|
||||
function fixture() {
|
||||
let args = [__dirname, "fixtures", "config"];
|
||||
const args = [__dirname, "fixtures", "config"];
|
||||
for (let i = 0; i < arguments.length; i ++) {
|
||||
args.push(arguments[i]);
|
||||
}
|
||||
@@ -28,11 +28,11 @@ describe("buildConfigChain", function () {
|
||||
});
|
||||
|
||||
it("dir1", function () {
|
||||
let chain = buildConfigChain({
|
||||
const chain = buildConfigChain({
|
||||
filename: fixture("dir1", "src.js")
|
||||
});
|
||||
|
||||
let expected = [
|
||||
const expected = [
|
||||
{
|
||||
options: {
|
||||
plugins: [
|
||||
@@ -77,11 +77,11 @@ describe("buildConfigChain", function () {
|
||||
});
|
||||
|
||||
it("dir2", function () {
|
||||
let chain = buildConfigChain({
|
||||
const chain = buildConfigChain({
|
||||
filename: fixture("dir2", "src.js")
|
||||
});
|
||||
|
||||
let expected = [
|
||||
const expected = [
|
||||
{
|
||||
options: {
|
||||
plugins: [
|
||||
@@ -116,11 +116,11 @@ describe("buildConfigChain", function () {
|
||||
});
|
||||
|
||||
it("env - base", function () {
|
||||
let chain = buildConfigChain({
|
||||
const chain = buildConfigChain({
|
||||
filename: fixture("env", "src.js")
|
||||
});
|
||||
|
||||
let expected = [
|
||||
const expected = [
|
||||
{
|
||||
options: {
|
||||
plugins: [
|
||||
@@ -157,11 +157,11 @@ describe("buildConfigChain", function () {
|
||||
it("env - foo", function () {
|
||||
process.env.NODE_ENV = "foo";
|
||||
|
||||
let chain = buildConfigChain({
|
||||
const chain = buildConfigChain({
|
||||
filename: fixture("env", "src.js")
|
||||
});
|
||||
|
||||
let expected = [
|
||||
const expected = [
|
||||
{
|
||||
options: {
|
||||
plugins: [
|
||||
@@ -209,11 +209,11 @@ describe("buildConfigChain", function () {
|
||||
process.env.NODE_ENV = "foo"; // overridden
|
||||
process.env.NODE_ENV = "bar";
|
||||
|
||||
let chain = buildConfigChain({
|
||||
const chain = buildConfigChain({
|
||||
filename: fixture("env", "src.js")
|
||||
});
|
||||
|
||||
let expected = [
|
||||
const expected = [
|
||||
{
|
||||
options: {
|
||||
plugins: [
|
||||
@@ -261,11 +261,11 @@ describe("buildConfigChain", function () {
|
||||
it("env - foo", function () {
|
||||
process.env.NODE_ENV = "foo";
|
||||
|
||||
let chain = buildConfigChain({
|
||||
const chain = buildConfigChain({
|
||||
filename: fixture("pkg", "src.js")
|
||||
});
|
||||
|
||||
let expected = [
|
||||
const expected = [
|
||||
{
|
||||
options: {
|
||||
plugins: ["pkg-plugin"]
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
let traverse = require("babel-traverse").default;
|
||||
let assert = require("assert");
|
||||
let parse = require("babylon").parse;
|
||||
const traverse = require("babel-traverse").default;
|
||||
const assert = require("assert");
|
||||
const parse = require("babylon").parse;
|
||||
|
||||
describe("evaluation", function () {
|
||||
function addTest(code, type, value, notConfident) {
|
||||
it(type + ": " + code, function () {
|
||||
let visitor = {};
|
||||
const visitor = {};
|
||||
|
||||
visitor[type] = function (path) {
|
||||
let evaluate = path.evaluate();
|
||||
const evaluate = path.evaluate();
|
||||
assert.equal(evaluate.confident, !notConfident);
|
||||
assert.deepEqual(evaluate.value, value);
|
||||
};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
let assert = require("assert");
|
||||
let getPossiblePluginNames = require("../lib/helpers/get-possible-plugin-names");
|
||||
const assert = require("assert");
|
||||
const getPossiblePluginNames = require("../lib/helpers/get-possible-plugin-names");
|
||||
|
||||
describe("getPossiblePluginNames", function () {
|
||||
it("adds the babel-plugin prefix", function() {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
let assert = require("assert");
|
||||
let getPossiblePresetNames = require("../lib/helpers/get-possible-preset-names");
|
||||
const assert = require("assert");
|
||||
const getPossiblePresetNames = require("../lib/helpers/get-possible-preset-names");
|
||||
|
||||
describe("getPossiblePresetNames", function () {
|
||||
it("adds the babel-preset prefix", function() {
|
||||
|
||||
@@ -17,7 +17,7 @@ describe("option-manager", () => {
|
||||
it("throws for removed babel 5 options", () => {
|
||||
return assert.throws(
|
||||
() => {
|
||||
let opt = new OptionManager(new Logger(null, "unknown"));
|
||||
const opt = new OptionManager(new Logger(null, "unknown"));
|
||||
opt.init({
|
||||
"randomOption": true
|
||||
});
|
||||
@@ -29,7 +29,7 @@ describe("option-manager", () => {
|
||||
it("throws for removed babel 5 options", () => {
|
||||
return assert.throws(
|
||||
() => {
|
||||
let opt = new OptionManager(new Logger(null, "unknown"));
|
||||
const opt = new OptionManager(new Logger(null, "unknown"));
|
||||
opt.init({
|
||||
"auxiliaryComment": true,
|
||||
"blacklist": true
|
||||
@@ -42,7 +42,7 @@ describe("option-manager", () => {
|
||||
it("throws for resolved but erroring preset", () => {
|
||||
return assert.throws(
|
||||
() => {
|
||||
let opt = new OptionManager(new Logger(null, "unknown"));
|
||||
const opt = new OptionManager(new Logger(null, "unknown"));
|
||||
opt.init({
|
||||
"presets": [path.join(__dirname, "fixtures/option-manager/not-a-preset")]
|
||||
});
|
||||
@@ -54,7 +54,7 @@ describe("option-manager", () => {
|
||||
it("throws for invalid preset configuration", function() {
|
||||
return assert.throws(
|
||||
function () {
|
||||
let opt = new OptionManager(new Logger(null, "unknown"));
|
||||
const opt = new OptionManager(new Logger(null, "unknown"));
|
||||
opt.init({
|
||||
"presets": [{ option: "value" }]
|
||||
});
|
||||
@@ -67,8 +67,8 @@ describe("option-manager", () => {
|
||||
describe("presets", function () {
|
||||
function presetTest(name) {
|
||||
it(name, function () {
|
||||
let opt = new OptionManager(new Logger(null, "unknown"));
|
||||
let options = opt.init({
|
||||
const opt = new OptionManager(new Logger(null, "unknown"));
|
||||
const options = opt.init({
|
||||
"presets": [path.join(__dirname, "fixtures/option-manager/presets", name)]
|
||||
});
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
let transform = require("../lib/api/node").transform;
|
||||
let Plugin = require("../lib/transformation/plugin");
|
||||
let chai = require("chai");
|
||||
const transform = require("../lib/api/node").transform;
|
||||
const Plugin = require("../lib/transformation/plugin");
|
||||
const chai = require("chai");
|
||||
|
||||
describe("traversal path", function () {
|
||||
it("replaceWithSourceString", function () {
|
||||
let expectCode = "function foo() {}";
|
||||
const expectCode = "function foo() {}";
|
||||
|
||||
let actualCode = transform(expectCode, {
|
||||
const actualCode = transform(expectCode, {
|
||||
plugins: [new Plugin({
|
||||
visitor: {
|
||||
FunctionDeclaration: function (path) {
|
||||
@@ -20,9 +20,9 @@ describe("traversal path", function () {
|
||||
});
|
||||
|
||||
it("replaceWith (arrow expression body to block statement body)", function () {
|
||||
let expectCode = "var fn = () => true;";
|
||||
const expectCode = "var fn = () => true;";
|
||||
|
||||
let actualCode = transform(expectCode, {
|
||||
const actualCode = transform(expectCode, {
|
||||
plugins: [new Plugin({
|
||||
visitor: {
|
||||
ArrowFunctionExpression: function (path) {
|
||||
@@ -45,9 +45,9 @@ describe("traversal path", function () {
|
||||
});
|
||||
|
||||
it("replaceWith (arrow block statement body to expression body)", function () {
|
||||
let expectCode = "var fn = () => { return true; }";
|
||||
const expectCode = "var fn = () => { return true; }";
|
||||
|
||||
let actualCode = transform(expectCode, {
|
||||
const actualCode = transform(expectCode, {
|
||||
plugins: [new Plugin({
|
||||
visitor: {
|
||||
ArrowFunctionExpression: function (path) {
|
||||
@@ -64,9 +64,9 @@ describe("traversal path", function () {
|
||||
});
|
||||
|
||||
it("replaceWith (for-in left expression to variable declaration)", function () {
|
||||
let expectCode = "for (KEY in right);";
|
||||
const expectCode = "for (KEY in right);";
|
||||
|
||||
let actualCode = transform(expectCode, {
|
||||
const actualCode = transform(expectCode, {
|
||||
plugins: [new Plugin({
|
||||
visitor: {
|
||||
ForInStatement: function (path) {
|
||||
@@ -90,9 +90,9 @@ describe("traversal path", function () {
|
||||
});
|
||||
|
||||
it("replaceWith (for-in left variable declaration to expression)", function () {
|
||||
let expectCode = "for (var KEY in right);";
|
||||
const expectCode = "for (var KEY in right);";
|
||||
|
||||
let actualCode = transform(expectCode, {
|
||||
const actualCode = transform(expectCode, {
|
||||
plugins: [new Plugin({
|
||||
visitor: {
|
||||
ForInStatement: function (path) {
|
||||
@@ -109,9 +109,9 @@ describe("traversal path", function () {
|
||||
});
|
||||
|
||||
it("replaceWith (for-loop left expression to variable declaration)", function () {
|
||||
let expectCode = "for (KEY;;);";
|
||||
const expectCode = "for (KEY;;);";
|
||||
|
||||
let actualCode = transform(expectCode, {
|
||||
const actualCode = transform(expectCode, {
|
||||
plugins: [new Plugin({
|
||||
visitor: {
|
||||
ForStatement: function (path) {
|
||||
@@ -135,9 +135,9 @@ describe("traversal path", function () {
|
||||
});
|
||||
|
||||
it("replaceWith (for-loop left variable declaration to expression)", function () {
|
||||
let expectCode = "for (var KEY;;);";
|
||||
const expectCode = "for (var KEY;;);";
|
||||
|
||||
let actualCode = transform(expectCode, {
|
||||
const actualCode = transform(expectCode, {
|
||||
plugins: [new Plugin({
|
||||
visitor: {
|
||||
ForStatement: function (path) {
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
let assert = require("assert");
|
||||
let async = require("async");
|
||||
let babel = require("../lib/api/node");
|
||||
let fs = require("fs");
|
||||
let path = require("path");
|
||||
const assert = require("assert");
|
||||
const async = require("async");
|
||||
const babel = require("../lib/api/node");
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
|
||||
// Test that plugins & presets are resolved relative to `filename`.
|
||||
describe("addon resolution", function () {
|
||||
it("addon resolution", function (done) {
|
||||
let fixtures = {};
|
||||
let paths = {};
|
||||
const fixtures = {};
|
||||
const paths = {};
|
||||
|
||||
paths.fixtures = path.join(
|
||||
__dirname,
|
||||
@@ -33,7 +33,7 @@ describe("addon resolution", function () {
|
||||
function fixturesReady (err) {
|
||||
if (err) return done(err);
|
||||
|
||||
let actual = babel.transform(fixtures.actual, {
|
||||
const actual = babel.transform(fixtures.actual, {
|
||||
filename: paths.actual,
|
||||
plugins: ["addons/plugin"],
|
||||
presets: ["addons/preset"],
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
let assert = require("assert");
|
||||
let util = require("../lib/util");
|
||||
let t = require("babel-types");
|
||||
const assert = require("assert");
|
||||
const util = require("../lib/util");
|
||||
const t = require("babel-types");
|
||||
|
||||
describe("util", function () {
|
||||
it("canCompile", function () {
|
||||
@@ -36,7 +36,7 @@ describe("util", function () {
|
||||
assert.deepEqual(util.list(["foo", "bar"]), ["foo", "bar"]);
|
||||
assert.deepEqual(util.list(/foo/), [/foo/]);
|
||||
|
||||
let date = new Date;
|
||||
const date = new Date;
|
||||
assert.deepEqual(util.list(date), [date]);
|
||||
});
|
||||
|
||||
@@ -84,8 +84,8 @@ describe("util", function () {
|
||||
});
|
||||
|
||||
it("shouldIgnore", function () {
|
||||
let reIgnore = /\-reIgnore\.js/;
|
||||
let fnIgnore = function (src) {
|
||||
const reIgnore = /\-reIgnore\.js/;
|
||||
const fnIgnore = function (src) {
|
||||
if (src.indexOf("fnIgnore") > 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -153,7 +153,7 @@ export default class Buffer {
|
||||
source(prop: string, loc: Location): void {
|
||||
if (prop && !loc) return;
|
||||
|
||||
let pos = loc ? loc[prop] : null;
|
||||
const pos = loc ? loc[prop] : null;
|
||||
|
||||
this._sourcePosition.identifierName = loc && loc.identifierName || null;
|
||||
this._sourcePosition.line = pos ? pos.line : null;
|
||||
@@ -169,10 +169,10 @@ export default class Buffer {
|
||||
if (!this._map) return cb();
|
||||
|
||||
// Use the call stack to manage a stack of "source location" data.
|
||||
let originalLine = this._sourcePosition.line;
|
||||
let originalColumn = this._sourcePosition.column;
|
||||
let originalFilename = this._sourcePosition.filename;
|
||||
let originalIdentifierName = this._sourcePosition.identifierName;
|
||||
const originalLine = this._sourcePosition.line;
|
||||
const originalColumn = this._sourcePosition.column;
|
||||
const originalFilename = this._sourcePosition.filename;
|
||||
const originalIdentifierName = this._sourcePosition.identifierName;
|
||||
|
||||
this.source(prop, loc);
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ export function BlockStatement(node: Object) {
|
||||
this.token("{");
|
||||
this.printInnerComments(node);
|
||||
|
||||
let hasDirectives = node.directives && node.directives.length;
|
||||
const hasDirectives = node.directives && node.directives.length;
|
||||
|
||||
if (node.body.length || hasDirectives) {
|
||||
this.newline();
|
||||
|
||||
@@ -94,7 +94,7 @@ export function CallExpression(node: Object) {
|
||||
|
||||
this.token("(");
|
||||
|
||||
let isPrettyCall = node._prettyCall;
|
||||
const isPrettyCall = node._prettyCall;
|
||||
|
||||
let separator;
|
||||
if (isPrettyCall) {
|
||||
@@ -127,15 +127,15 @@ function buildYieldAwait(keyword: string) {
|
||||
|
||||
if (node.argument) {
|
||||
this.space();
|
||||
let terminatorState = this.startTerminatorless();
|
||||
const terminatorState = this.startTerminatorless();
|
||||
this.print(node.argument, node);
|
||||
this.endTerminatorless(terminatorState);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export let YieldExpression = buildYieldAwait("yield");
|
||||
export let AwaitExpression = buildYieldAwait("await");
|
||||
export const YieldExpression = buildYieldAwait("yield");
|
||||
export const AwaitExpression = buildYieldAwait("await");
|
||||
|
||||
export function EmptyStatement() {
|
||||
this.semicolon(true /* force */);
|
||||
@@ -159,7 +159,7 @@ export function AssignmentPattern(node: Object) {
|
||||
export function AssignmentExpression(node: Object, parent: Object) {
|
||||
// Somewhere inside a for statement `init` node but doesn't usually
|
||||
// needs a paren except for `in` expressions: `for (a in b ? a : b;;)`
|
||||
let parens = this.inForStatementInitCounter && node.operator === "in" &&
|
||||
const parens = this.inForStatementInitCounter && node.operator === "in" &&
|
||||
!n.needsParens(node, parent);
|
||||
|
||||
if (parens) {
|
||||
|
||||
@@ -264,7 +264,7 @@ export function ObjectTypeAnnotation(node: Object) {
|
||||
this.token("{");
|
||||
}
|
||||
|
||||
let props = node.properties.concat(node.callProperties, node.indexers);
|
||||
const props = node.properties.concat(node.callProperties, node.indexers);
|
||||
|
||||
if (props.length) {
|
||||
this.space();
|
||||
|
||||
@@ -47,12 +47,12 @@ export function JSXText(node: Object) {
|
||||
}
|
||||
|
||||
export function JSXElement(node: Object) {
|
||||
let open = node.openingElement;
|
||||
const open = node.openingElement;
|
||||
this.print(open, node);
|
||||
if (open.selfClosing) return;
|
||||
|
||||
this.indent();
|
||||
for (let child of (node.children: Array<Object>)) {
|
||||
for (const child of (node.children: Array<Object>)) {
|
||||
this.print(child, node);
|
||||
}
|
||||
this.dedent();
|
||||
|
||||
@@ -17,8 +17,8 @@ export function _params(node: Object) {
|
||||
}
|
||||
|
||||
export function _method(node: Object) {
|
||||
let kind = node.kind;
|
||||
let key = node.key;
|
||||
const kind = node.kind;
|
||||
const key = node.key;
|
||||
|
||||
if (kind === "method" || kind === "init") {
|
||||
if (node.generator) {
|
||||
|
||||
@@ -69,7 +69,7 @@ export function ExportDefaultDeclaration() {
|
||||
|
||||
function ExportDeclaration(node: Object) {
|
||||
if (node.declaration) {
|
||||
let declar = node.declaration;
|
||||
const declar = node.declaration;
|
||||
this.print(declar, node);
|
||||
if (!t.isStatement(declar)) this.semicolon();
|
||||
} else {
|
||||
@@ -78,12 +78,12 @@ function ExportDeclaration(node: Object) {
|
||||
this.space();
|
||||
}
|
||||
|
||||
let specifiers = node.specifiers.slice(0);
|
||||
const specifiers = node.specifiers.slice(0);
|
||||
|
||||
// print "special" specifiers first
|
||||
let hasSpecial = false;
|
||||
while (true) {
|
||||
let first = specifiers[0];
|
||||
const first = specifiers[0];
|
||||
if (t.isExportDefaultSpecifier(first) || t.isExportNamespaceSpecifier(first)) {
|
||||
hasSpecial = true;
|
||||
this.print(specifiers.shift(), node);
|
||||
@@ -126,11 +126,11 @@ export function ImportDeclaration(node: Object) {
|
||||
this.space();
|
||||
}
|
||||
|
||||
let specifiers = node.specifiers.slice(0);
|
||||
const specifiers = node.specifiers.slice(0);
|
||||
if (specifiers && specifiers.length) {
|
||||
// print "special" specifiers first
|
||||
while (true) {
|
||||
let first = specifiers[0];
|
||||
const first = specifiers[0];
|
||||
if (t.isImportDefaultSpecifier(first) || t.isImportNamespaceSpecifier(first)) {
|
||||
this.print(specifiers.shift(), node);
|
||||
if (specifiers.length) {
|
||||
|
||||
@@ -17,7 +17,7 @@ export function IfStatement(node: Object) {
|
||||
this.token(")");
|
||||
this.space();
|
||||
|
||||
let needsBlock = node.alternate && t.isIfStatement(getLastStatement(node.consequent));
|
||||
const needsBlock = node.alternate && t.isIfStatement(getLastStatement(node.consequent));
|
||||
if (needsBlock) {
|
||||
this.token("{");
|
||||
this.newline();
|
||||
@@ -80,7 +80,7 @@ export function WhileStatement(node: Object) {
|
||||
this.printBlock(node);
|
||||
}
|
||||
|
||||
let buildForXStatement = function (op) {
|
||||
const buildForXStatement = function (op) {
|
||||
return function (node: Object) {
|
||||
this.word("for");
|
||||
this.space();
|
||||
@@ -101,9 +101,9 @@ let buildForXStatement = function (op) {
|
||||
};
|
||||
};
|
||||
|
||||
export let ForInStatement = buildForXStatement("in");
|
||||
export let ForOfStatement = buildForXStatement("of");
|
||||
export let ForAwaitStatement = buildForXStatement("await");
|
||||
export const ForInStatement = buildForXStatement("in");
|
||||
export const ForOfStatement = buildForXStatement("of");
|
||||
export const ForAwaitStatement = buildForXStatement("await");
|
||||
|
||||
export function DoWhileStatement(node: Object) {
|
||||
this.word("do");
|
||||
@@ -122,11 +122,11 @@ function buildLabelStatement(prefix, key = "label") {
|
||||
return function (node: Object) {
|
||||
this.word(prefix);
|
||||
|
||||
let label = node[key];
|
||||
const label = node[key];
|
||||
if (label) {
|
||||
this.space();
|
||||
|
||||
let terminatorState = this.startTerminatorless();
|
||||
const terminatorState = this.startTerminatorless();
|
||||
this.print(label, node);
|
||||
this.endTerminatorless(terminatorState);
|
||||
}
|
||||
@@ -135,10 +135,10 @@ function buildLabelStatement(prefix, key = "label") {
|
||||
};
|
||||
}
|
||||
|
||||
export let ContinueStatement = buildLabelStatement("continue");
|
||||
export let ReturnStatement = buildLabelStatement("return", "argument");
|
||||
export let BreakStatement = buildLabelStatement("break");
|
||||
export let ThrowStatement = buildLabelStatement("throw", "argument");
|
||||
export const ContinueStatement = buildLabelStatement("continue");
|
||||
export const ReturnStatement = buildLabelStatement("return", "argument");
|
||||
export const BreakStatement = buildLabelStatement("break");
|
||||
export const ThrowStatement = buildLabelStatement("throw", "argument");
|
||||
|
||||
export function LabeledStatement(node: Object) {
|
||||
this.print(node.label, node);
|
||||
@@ -242,7 +242,7 @@ export function VariableDeclaration(node: Object, parent: Object) {
|
||||
let hasInits = false;
|
||||
// don't add whitespace to loop heads
|
||||
if (!t.isFor(parent)) {
|
||||
for (let declar of (node.declarations: Array<Object>)) {
|
||||
for (const declar of (node.declarations: Array<Object>)) {
|
||||
if (declar.init) {
|
||||
// has an init so let's split it up over multiple lines
|
||||
hasInits = true;
|
||||
|
||||
@@ -7,13 +7,13 @@ export function TemplateElement(node: Object, parent: Object) {
|
||||
const isFirst = parent.quasis[0] === node;
|
||||
const isLast = parent.quasis[parent.quasis.length - 1] === node;
|
||||
|
||||
let value = (isFirst ? "`" : "}") + node.value.raw + (isLast ? "`" : "${");
|
||||
const value = (isFirst ? "`" : "}") + node.value.raw + (isLast ? "`" : "${");
|
||||
|
||||
this.token(value);
|
||||
}
|
||||
|
||||
export function TemplateLiteral(node: Object) {
|
||||
let quasis = node.quasis;
|
||||
const quasis = node.quasis;
|
||||
|
||||
for (let i = 0; i < quasis.length; i++) {
|
||||
this.print(quasis[i], node);
|
||||
|
||||
@@ -32,7 +32,7 @@ export {
|
||||
};
|
||||
|
||||
export function ObjectExpression(node: Object) {
|
||||
let props = node.properties;
|
||||
const props = node.properties;
|
||||
|
||||
this.token("{");
|
||||
this.printInnerComments(node);
|
||||
@@ -84,14 +84,14 @@ export function ObjectProperty(node: Object) {
|
||||
}
|
||||
|
||||
export function ArrayExpression(node: Object) {
|
||||
let elems = node.elements;
|
||||
let len = elems.length;
|
||||
const elems = node.elements;
|
||||
const len = elems.length;
|
||||
|
||||
this.token("[");
|
||||
this.printInnerComments(node);
|
||||
|
||||
for (let i = 0; i < elems.length; i++) {
|
||||
let elem = elems[i];
|
||||
const elem = elems[i];
|
||||
if (elem) {
|
||||
if (i > 0) this.space();
|
||||
this.print(elem, node);
|
||||
@@ -136,7 +136,7 @@ export function NumericLiteral(node: Object) {
|
||||
}
|
||||
|
||||
export function StringLiteral(node: Object, parent: Object) {
|
||||
let raw = this.getPossibleRaw(node);
|
||||
const raw = this.getPossibleRaw(node);
|
||||
if (!this.format.minified && raw != null) {
|
||||
this.token(raw);
|
||||
return;
|
||||
@@ -150,7 +150,7 @@ export function StringLiteral(node: Object, parent: Object) {
|
||||
if (this.format.jsonCompatibleStrings) {
|
||||
opts.json = true;
|
||||
}
|
||||
let val = jsesc(node.value, opts);
|
||||
const val = jsesc(node.value, opts);
|
||||
|
||||
return this.token(val);
|
||||
}
|
||||
|
||||
@@ -14,8 +14,8 @@ class Generator extends Printer {
|
||||
opts = opts || {};
|
||||
|
||||
const tokens = ast.tokens || [];
|
||||
let format = normalizeOptions(code, opts, tokens);
|
||||
let map = opts.sourceMaps ? new SourceMap(opts, code) : null;
|
||||
const format = normalizeOptions(code, opts, tokens);
|
||||
const map = opts.sourceMaps ? new SourceMap(opts, code) : null;
|
||||
super(format, map, tokens);
|
||||
|
||||
this.ast = ast;
|
||||
@@ -44,11 +44,11 @@ class Generator extends Printer {
|
||||
function normalizeOptions(code, opts, tokens): Format {
|
||||
let style = " ";
|
||||
if (code && typeof code === "string") {
|
||||
let indent = detectIndent(code).indent;
|
||||
const indent = detectIndent(code).indent;
|
||||
if (indent && indent !== " ") style = indent;
|
||||
}
|
||||
|
||||
let format = {
|
||||
const format = {
|
||||
auxiliaryCommentBefore: opts.auxiliaryCommentBefore,
|
||||
auxiliaryCommentAfter: opts.auxiliaryCommentAfter,
|
||||
shouldPrintComment: opts.shouldPrintComment,
|
||||
@@ -101,7 +101,7 @@ function findCommonStringDelimiter(code, tokens) {
|
||||
return DEFAULT_STRING_DELIMITER;
|
||||
}
|
||||
|
||||
let occurences = {
|
||||
const occurences = {
|
||||
single: 0,
|
||||
double: 0
|
||||
};
|
||||
@@ -109,10 +109,10 @@ function findCommonStringDelimiter(code, tokens) {
|
||||
let checked = 0;
|
||||
|
||||
for (let i = 0; i < tokens.length; i++) {
|
||||
let token = tokens[i];
|
||||
const token = tokens[i];
|
||||
if (token.type.label !== "string") continue;
|
||||
|
||||
let raw = code.slice(token.start, token.end);
|
||||
const raw = code.slice(token.start, token.end);
|
||||
if (raw[0] === "'") {
|
||||
occurences.single++;
|
||||
} else {
|
||||
@@ -145,6 +145,6 @@ export class CodeGenerator {
|
||||
}
|
||||
|
||||
export default function (ast: Object, opts: Object, code: string): Object {
|
||||
let gen = new Generator(ast, opts, code);
|
||||
const gen = new Generator(ast, opts, code);
|
||||
return gen.generate();
|
||||
}
|
||||
|
||||
@@ -3,22 +3,22 @@ import * as parens from "./parentheses";
|
||||
import * as t from "babel-types";
|
||||
|
||||
function expandAliases(obj) {
|
||||
let newObj = {};
|
||||
const newObj = {};
|
||||
|
||||
function add(type, func) {
|
||||
let fn = newObj[type];
|
||||
const fn = newObj[type];
|
||||
newObj[type] = fn ? function(node, parent, stack) {
|
||||
let result = fn(node, parent, stack);
|
||||
const result = fn(node, parent, stack);
|
||||
|
||||
return result == null ? func(node, parent, stack) : result;
|
||||
} : func;
|
||||
}
|
||||
|
||||
for (let type of Object.keys(obj)) {
|
||||
for (const type of Object.keys(obj)) {
|
||||
|
||||
let aliases = t.FLIPPED_ALIAS_KEYS[type];
|
||||
const aliases = t.FLIPPED_ALIAS_KEYS[type];
|
||||
if (aliases) {
|
||||
for (let alias of aliases) {
|
||||
for (const alias of aliases) {
|
||||
add(alias, obj[type]);
|
||||
}
|
||||
} else {
|
||||
@@ -31,12 +31,12 @@ function expandAliases(obj) {
|
||||
|
||||
// Rather than using `t.is` on each object property, we pre-expand any type aliases
|
||||
// into concrete types so that the 'find' call below can be as fast as possible.
|
||||
let expandedParens = expandAliases(parens);
|
||||
let expandedWhitespaceNodes = expandAliases(whitespace.nodes);
|
||||
let expandedWhitespaceList = expandAliases(whitespace.list);
|
||||
const expandedParens = expandAliases(parens);
|
||||
const expandedWhitespaceNodes = expandAliases(whitespace.nodes);
|
||||
const expandedWhitespaceList = expandAliases(whitespace.list);
|
||||
|
||||
function find(obj, node, parent, printStack) {
|
||||
let fn = obj[node.type];
|
||||
const fn = obj[node.type];
|
||||
return fn ? fn(node, parent, printStack) : null;
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ export function needsWhitespace(node, parent, type) {
|
||||
let linesInfo = find(expandedWhitespaceNodes, node, parent);
|
||||
|
||||
if (!linesInfo) {
|
||||
let items = find(expandedWhitespaceList, node, parent);
|
||||
const items = find(expandedWhitespaceList, node, parent);
|
||||
if (items) {
|
||||
for (let i = 0; i < items.length; i++) {
|
||||
linesInfo = needsWhitespace(items[i], node, type);
|
||||
|
||||
@@ -60,11 +60,11 @@ export function Binary(node: Object, parent: Object): boolean {
|
||||
}
|
||||
|
||||
if (t.isBinary(parent)) {
|
||||
let parentOp = parent.operator;
|
||||
let parentPos = PRECEDENCE[parentOp];
|
||||
const parentOp = parent.operator;
|
||||
const parentPos = PRECEDENCE[parentOp];
|
||||
|
||||
let nodeOp = node.operator;
|
||||
let nodePos = PRECEDENCE[nodeOp];
|
||||
const nodeOp = node.operator;
|
||||
const nodePos = PRECEDENCE[nodeOp];
|
||||
|
||||
if (parentPos > nodePos) {
|
||||
return true;
|
||||
|
||||
@@ -69,7 +69,7 @@ exports.nodes = {
|
||||
*/
|
||||
|
||||
AssignmentExpression(node: Object): ?WhitespaceObject {
|
||||
let state = crawl(node.right);
|
||||
const state = crawl(node.right);
|
||||
if ((state.hasCall && state.hasHelper) || state.hasFunction) {
|
||||
return {
|
||||
before: state.hasFunction,
|
||||
@@ -131,11 +131,11 @@ exports.nodes = {
|
||||
|
||||
VariableDeclaration(node: Object): ?WhitespaceObject {
|
||||
for (let i = 0; i < node.declarations.length; i++) {
|
||||
let declar = node.declarations[i];
|
||||
const declar = node.declarations[i];
|
||||
|
||||
let enabled = isHelper(declar.id) && !isType(declar.init);
|
||||
if (!enabled) {
|
||||
let state = crawl(declar.init);
|
||||
const state = crawl(declar.init);
|
||||
enabled = (isHelper(declar.init) && state.hasCall) || state.hasFunction;
|
||||
}
|
||||
|
||||
|
||||
@@ -238,7 +238,7 @@ export default class Printer {
|
||||
|
||||
_maybeAddParen(str: string): void {
|
||||
// see startTerminatorless() instance method
|
||||
let parenPushNewlineState = this._parenPushNewlineState;
|
||||
const parenPushNewlineState = this._parenPushNewlineState;
|
||||
if (!parenPushNewlineState) return;
|
||||
this._parenPushNewlineState = null;
|
||||
|
||||
@@ -314,19 +314,19 @@ export default class Printer {
|
||||
print(node, parent) {
|
||||
if (!node) return;
|
||||
|
||||
let oldConcise = this.format.concise;
|
||||
const oldConcise = this.format.concise;
|
||||
if (node._compact) {
|
||||
this.format.concise = true;
|
||||
}
|
||||
|
||||
let printMethod = this[node.type];
|
||||
const printMethod = this[node.type];
|
||||
if (!printMethod) {
|
||||
throw new ReferenceError(`unknown node of type ${JSON.stringify(node.type)} with constructor ${JSON.stringify(node && node.constructor.name)}`);
|
||||
}
|
||||
|
||||
this._printStack.push(node);
|
||||
|
||||
let oldInAux = this._insideAux;
|
||||
const oldInAux = this._insideAux;
|
||||
this._insideAux = !node.loc;
|
||||
this._maybeAddAuxComment(this._insideAux && !oldInAux);
|
||||
|
||||
@@ -340,7 +340,7 @@ export default class Printer {
|
||||
|
||||
this._printLeadingComments(node, parent);
|
||||
|
||||
let loc = (t.isProgram(node) || t.isFile(node)) ? null : node.loc;
|
||||
const loc = (t.isProgram(node) || t.isFile(node)) ? null : node.loc;
|
||||
this.withSource("start", loc, () => {
|
||||
this[node.type](node, parent);
|
||||
});
|
||||
@@ -388,7 +388,7 @@ export default class Printer {
|
||||
}
|
||||
|
||||
getPossibleRaw(node) {
|
||||
let extra = node.extra;
|
||||
const extra = node.extra;
|
||||
if (extra && extra.raw != null && extra.rawValue != null && node.value === extra.rawValue) {
|
||||
return extra.raw;
|
||||
}
|
||||
@@ -426,14 +426,14 @@ export default class Printer {
|
||||
}
|
||||
|
||||
printAndIndentOnComments(node, parent) {
|
||||
let indent = !!node.leadingComments;
|
||||
const indent = !!node.leadingComments;
|
||||
if (indent) this.indent();
|
||||
this.print(node, parent);
|
||||
if (indent) this.dedent();
|
||||
}
|
||||
|
||||
printBlock(parent) {
|
||||
let node = parent.body;
|
||||
const node = parent.body;
|
||||
|
||||
if (!t.isEmptyStatement(node)) {
|
||||
this.space();
|
||||
@@ -544,13 +544,13 @@ export default class Printer {
|
||||
|
||||
//
|
||||
if (comment.type === "CommentBlock" && this.format.indent.adjustMultilineComment) {
|
||||
let offset = comment.loc && comment.loc.start.column;
|
||||
const offset = comment.loc && comment.loc.start.column;
|
||||
if (offset) {
|
||||
let newlineRegex = new RegExp("\\n\\s{1," + offset + "}", "g");
|
||||
const newlineRegex = new RegExp("\\n\\s{1," + offset + "}", "g");
|
||||
val = val.replace(newlineRegex, "\n");
|
||||
}
|
||||
|
||||
let indentSize = Math.max(this._getIndent().length, this._buf.getCurrentColumn());
|
||||
const indentSize = Math.max(this._getIndent().length, this._buf.getCurrentColumn());
|
||||
val = val.replace(/\n(?!$)/g, `\n${repeat(" ", indentSize)}`);
|
||||
}
|
||||
|
||||
@@ -567,7 +567,7 @@ export default class Printer {
|
||||
_printComments(comments?: Array<Object>) {
|
||||
if (!comments || !comments.length) return;
|
||||
|
||||
for (let comment of comments) {
|
||||
for (const comment of comments) {
|
||||
this._printComment(comment);
|
||||
}
|
||||
}
|
||||
@@ -578,7 +578,7 @@ function commaSeparator() {
|
||||
this.space();
|
||||
}
|
||||
|
||||
for (let generator of [
|
||||
for (const generator of [
|
||||
require("./generators/template-literals"),
|
||||
require("./generators/expressions"),
|
||||
require("./generators/statements"),
|
||||
|
||||
@@ -15,7 +15,7 @@ export default class Whitespace {
|
||||
getNewlinesBefore(node) {
|
||||
let startToken;
|
||||
let endToken;
|
||||
let tokens = this.tokens;
|
||||
const tokens = this.tokens;
|
||||
|
||||
let index = this._findToken((token) => token.start - node.start, 0, tokens.length);
|
||||
if (index >= 0) {
|
||||
@@ -34,7 +34,7 @@ export default class Whitespace {
|
||||
getNewlinesAfter(node) {
|
||||
let startToken;
|
||||
let endToken;
|
||||
let tokens = this.tokens;
|
||||
const tokens = this.tokens;
|
||||
|
||||
let index = this._findToken((token) => token.end - node.end, 0, tokens.length);
|
||||
if (index >= 0) {
|
||||
@@ -58,8 +58,8 @@ export default class Whitespace {
|
||||
_getNewlinesBetween(startToken, endToken) {
|
||||
if (!endToken || !endToken.loc) return 0;
|
||||
|
||||
let start = startToken ? startToken.loc.end.line : 1;
|
||||
let end = endToken.loc.start.line;
|
||||
const start = startToken ? startToken.loc.end.line : 1;
|
||||
const end = endToken.loc.start.line;
|
||||
let lines = 0;
|
||||
|
||||
for (let line = start; line < end; line++) {
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
let Whitespace = require("../lib/whitespace");
|
||||
let Printer = require("../lib/printer");
|
||||
let generate = require("../lib");
|
||||
let assert = require("assert");
|
||||
let parse = require("babylon").parse;
|
||||
let chai = require("chai");
|
||||
let t = require("babel-types");
|
||||
let _ = require("lodash");
|
||||
let fs = require("fs");
|
||||
let path = require("path");
|
||||
const Whitespace = require("../lib/whitespace");
|
||||
const Printer = require("../lib/printer");
|
||||
const generate = require("../lib");
|
||||
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 () {
|
||||
@@ -22,16 +22,16 @@ describe("generation", function () {
|
||||
});
|
||||
|
||||
it("multiple sources", function () {
|
||||
let sources = {
|
||||
const sources = {
|
||||
"a.js": "function hi (msg) { console.log(msg); }\n",
|
||||
"b.js": "hi('hello');\n"
|
||||
};
|
||||
let parsed = _.keys(sources).reduce(function (_parsed, filename) {
|
||||
const parsed = _.keys(sources).reduce(function (_parsed, filename) {
|
||||
_parsed[filename] = parse(sources[filename], { sourceFilename: filename });
|
||||
return _parsed;
|
||||
}, {});
|
||||
|
||||
let combinedAst = {
|
||||
const combinedAst = {
|
||||
"type": "File",
|
||||
"program": {
|
||||
"type": "Program",
|
||||
@@ -40,7 +40,7 @@ describe("generation", function () {
|
||||
}
|
||||
};
|
||||
|
||||
let generated = generate.default(combinedAst, { sourceMaps: true }, sources);
|
||||
const generated = generate.default(combinedAst, { sourceMaps: true }, sources);
|
||||
|
||||
chai.expect(generated.map).to.deep.equal({
|
||||
version: 3,
|
||||
@@ -128,20 +128,20 @@ describe("generation", function () {
|
||||
});
|
||||
|
||||
it("identifierName", function () {
|
||||
let code = "function foo() { bar; }\n";
|
||||
const code = "function foo() { bar; }\n";
|
||||
|
||||
let ast = parse(code, { filename: "inline" }).program;
|
||||
let fn = ast.body[0];
|
||||
const ast = parse(code, { filename: "inline" }).program;
|
||||
const fn = ast.body[0];
|
||||
|
||||
let id = fn.id;
|
||||
const id = fn.id;
|
||||
id.name += "2";
|
||||
id.loc.identifierName = "foo";
|
||||
|
||||
let id2 = fn.body.body[0].expression;
|
||||
const id2 = fn.body.body[0].expression;
|
||||
id2.name += "2";
|
||||
id2.loc.identiferName = "bar";
|
||||
|
||||
let generated = generate.default(ast, {
|
||||
const generated = generate.default(ast, {
|
||||
filename: "inline",
|
||||
sourceFileName: "inline",
|
||||
sourceMaps: true
|
||||
@@ -189,10 +189,10 @@ describe("generation", function () {
|
||||
});
|
||||
|
||||
it("lazy source map generation", function() {
|
||||
let code = "function hi (msg) { console.log(msg); }\n";
|
||||
const code = "function hi (msg) { console.log(msg); }\n";
|
||||
|
||||
let ast = parse(code, { filename: "a.js" }).program;
|
||||
let generated = generate.default(ast, {
|
||||
const ast = parse(code, { filename: "a.js" }).program;
|
||||
const generated = generate.default(ast, {
|
||||
sourceFileName: "a.js",
|
||||
sourceMaps: true,
|
||||
});
|
||||
@@ -209,12 +209,12 @@ describe("generation", function () {
|
||||
describe("programmatic generation", function() {
|
||||
it("numeric member expression", function() {
|
||||
// Should not generate `0.foo`
|
||||
let mem = t.memberExpression(t.numericLiteral(60702), t.identifier("foo"));
|
||||
const mem = t.memberExpression(t.numericLiteral(60702), t.identifier("foo"));
|
||||
new Function(generate.default(mem).code);
|
||||
});
|
||||
|
||||
it("nested if statements needs block", function() {
|
||||
let ifStatement = t.ifStatement(
|
||||
const ifStatement = t.ifStatement(
|
||||
t.stringLiteral("top cond"),
|
||||
t.whileStatement(
|
||||
t.stringLiteral("while cond"),
|
||||
@@ -226,17 +226,17 @@ describe("programmatic generation", function() {
|
||||
t.expressionStatement(t.stringLiteral("alt"))
|
||||
);
|
||||
|
||||
let ast = parse(generate.default(ifStatement).code);
|
||||
const ast = parse(generate.default(ifStatement).code);
|
||||
assert.equal(ast.program.body[0].consequent.type, "BlockStatement");
|
||||
});
|
||||
|
||||
it("prints directives in block with empty body", function() {
|
||||
let blockStatement = t.blockStatement(
|
||||
const blockStatement = t.blockStatement(
|
||||
[],
|
||||
[t.directive(t.directiveLiteral("use strict"))]
|
||||
);
|
||||
|
||||
let output = generate.default(blockStatement).code;
|
||||
const output = generate.default(blockStatement).code;
|
||||
assert.equal(output, [
|
||||
"{",
|
||||
" \"use strict\";",
|
||||
@@ -245,7 +245,7 @@ describe("programmatic generation", function() {
|
||||
});
|
||||
|
||||
it("flow object indentation", function() {
|
||||
let objectStatement = t.objectTypeAnnotation(
|
||||
const objectStatement = t.objectTypeAnnotation(
|
||||
[
|
||||
t.objectTypeProperty(
|
||||
t.identifier("bar"),
|
||||
@@ -256,7 +256,7 @@ describe("programmatic generation", function() {
|
||||
null
|
||||
);
|
||||
|
||||
let output = generate.default(objectStatement).code;
|
||||
const output = generate.default(objectStatement).code;
|
||||
assert.equal(output, [
|
||||
"{",
|
||||
" bar: string;",
|
||||
@@ -265,7 +265,7 @@ describe("programmatic generation", function() {
|
||||
});
|
||||
|
||||
it("flow object indentation with empty leading ObjectTypeProperty", function() {
|
||||
let objectStatement = t.objectTypeAnnotation(
|
||||
const objectStatement = t.objectTypeAnnotation(
|
||||
[],
|
||||
[
|
||||
t.objectTypeIndexer(
|
||||
@@ -276,7 +276,7 @@ describe("programmatic generation", function() {
|
||||
]
|
||||
);
|
||||
|
||||
let output = generate.default(objectStatement).code;
|
||||
const output = generate.default(objectStatement).code;
|
||||
|
||||
assert.equal(output, [
|
||||
"{",
|
||||
@@ -288,29 +288,29 @@ describe("programmatic generation", function() {
|
||||
|
||||
describe("whitespace", function () {
|
||||
it("empty token list", function () {
|
||||
let w = new Whitespace([]);
|
||||
const w = new Whitespace([]);
|
||||
assert.equal(w.getNewlinesBefore(t.stringLiteral("1")), 0);
|
||||
});
|
||||
});
|
||||
|
||||
let suites = require("babel-helper-fixtures").default(__dirname + "/fixtures");
|
||||
const suites = require("babel-helper-fixtures").default(__dirname + "/fixtures");
|
||||
|
||||
suites.forEach(function (testSuite) {
|
||||
describe("generation/" + testSuite.title, function () {
|
||||
_.each(testSuite.tests, function (task) {
|
||||
it(task.title, !task.disabled && function () {
|
||||
let expect = task.expect;
|
||||
let actual = task.actual;
|
||||
let actualCode = actual.code;
|
||||
const expect = task.expect;
|
||||
const actual = task.actual;
|
||||
const actualCode = actual.code;
|
||||
|
||||
if (actualCode) {
|
||||
let actualAst = parse(actualCode, {
|
||||
const actualAst = parse(actualCode, {
|
||||
filename: actual.loc,
|
||||
plugins: ["*"],
|
||||
strictMode: false,
|
||||
sourceType: "module",
|
||||
});
|
||||
let result = generate.default(actualAst, task.options, actualCode);
|
||||
const result = generate.default(actualAst, task.options, actualCode);
|
||||
|
||||
if (!expect.code && result.code && fs.statSync(path.dirname(expect.loc)).isDirectory() && !process.env.CI) {
|
||||
console.log(`New test file created: ${expect.loc}`);
|
||||
|
||||
@@ -2,15 +2,15 @@ import type { NodePath } from "babel-traverse";
|
||||
import * as t from "babel-types";
|
||||
|
||||
export default function bindifyDecorators(decorators: Array<NodePath>): Array<NodePath> {
|
||||
for (let decoratorPath of decorators) {
|
||||
let decorator = decoratorPath.node;
|
||||
let expression = decorator.expression;
|
||||
for (const decoratorPath of decorators) {
|
||||
const decorator = decoratorPath.node;
|
||||
const expression = decorator.expression;
|
||||
if (!t.isMemberExpression(expression)) continue;
|
||||
|
||||
let temp = decoratorPath.scope.maybeGenerateMemoised(expression.object);
|
||||
const temp = decoratorPath.scope.maybeGenerateMemoised(expression.object);
|
||||
let ref;
|
||||
|
||||
let nodes = [];
|
||||
const nodes = [];
|
||||
|
||||
if (temp) {
|
||||
ref = temp;
|
||||
|
||||
@@ -5,7 +5,7 @@ export default function (opts: {
|
||||
build: Function;
|
||||
operator: string;
|
||||
}): Object {
|
||||
let visitor = {};
|
||||
const visitor = {};
|
||||
|
||||
function isAssignment(node) {
|
||||
return node && node.operator === opts.operator + "=";
|
||||
@@ -19,11 +19,11 @@ export default function (opts: {
|
||||
// hit the `AssignmentExpression` one below
|
||||
if (path.isCompletionRecord()) return;
|
||||
|
||||
let expr = path.node.expression;
|
||||
const expr = path.node.expression;
|
||||
if (!isAssignment(expr)) return;
|
||||
|
||||
let nodes = [];
|
||||
let exploded = explode(expr.left, nodes, file, path.scope, true);
|
||||
const nodes = [];
|
||||
const exploded = explode(expr.left, nodes, file, path.scope, true);
|
||||
|
||||
nodes.push(t.expressionStatement(
|
||||
buildAssignment(exploded.ref, opts.build(exploded.uid, expr.right))
|
||||
@@ -33,17 +33,17 @@ export default function (opts: {
|
||||
};
|
||||
|
||||
visitor.AssignmentExpression = function (path, file) {
|
||||
let { node, scope } = path;
|
||||
const { node, scope } = path;
|
||||
if (!isAssignment(node)) return;
|
||||
|
||||
let nodes = [];
|
||||
let exploded = explode(node.left, nodes, file, scope);
|
||||
const nodes = [];
|
||||
const exploded = explode(node.left, nodes, file, scope);
|
||||
nodes.push(buildAssignment(exploded.ref, opts.build(exploded.uid, node.right)));
|
||||
path.replaceWithMultiple(nodes);
|
||||
};
|
||||
|
||||
visitor.BinaryExpression = function (path) {
|
||||
let { node } = path;
|
||||
const { node } = path;
|
||||
if (node.operator === opts.operator) {
|
||||
path.replaceWith(opts.build(node.left, node.right));
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ export default function (
|
||||
is: Function;
|
||||
},
|
||||
) {
|
||||
let buildAssignment = function (left, right) {
|
||||
const buildAssignment = function (left, right) {
|
||||
return t.assignmentExpression("=", left, right);
|
||||
};
|
||||
|
||||
@@ -16,12 +16,12 @@ export default function (
|
||||
// hit the `AssignmentExpression` one below
|
||||
if (path.isCompletionRecord()) return;
|
||||
|
||||
let expr = path.node.expression;
|
||||
const expr = path.node.expression;
|
||||
if (!opts.is(expr, file)) return;
|
||||
|
||||
let nodes = [];
|
||||
const nodes = [];
|
||||
|
||||
let exploded = explode(expr.left, nodes, file, path.scope);
|
||||
const exploded = explode(expr.left, nodes, file, path.scope);
|
||||
|
||||
nodes.push(t.ifStatement(
|
||||
opts.build(exploded.uid, file),
|
||||
@@ -32,11 +32,11 @@ export default function (
|
||||
};
|
||||
|
||||
exports.AssignmentExpression = function (path, file) {
|
||||
let node = path.node;
|
||||
const node = path.node;
|
||||
if (!opts.is(node, file)) return;
|
||||
|
||||
let nodes = [];
|
||||
let exploded = explode(node.left, nodes, file, path.scope);
|
||||
const nodes = [];
|
||||
const exploded = explode(node.left, nodes, file, path.scope);
|
||||
|
||||
nodes.push(t.logicalExpression(
|
||||
"&&",
|
||||
|
||||
@@ -11,7 +11,7 @@ type ElementState = {
|
||||
};
|
||||
|
||||
export default function (opts) {
|
||||
let visitor = {};
|
||||
const visitor = {};
|
||||
|
||||
visitor.JSXNamespacedName = function (path) {
|
||||
throw path.buildCodeFrameError("Namespace tags are not supported. ReactJSX is not XML.");
|
||||
@@ -19,7 +19,7 @@ export default function (opts) {
|
||||
|
||||
visitor.JSXElement = {
|
||||
exit(path, file) {
|
||||
let callExpr = buildElementCall(path.get("openingElement"), file);
|
||||
const callExpr = buildElementCall(path.get("openingElement"), file);
|
||||
|
||||
callExpr.arguments = callExpr.arguments.concat(path.node.children);
|
||||
|
||||
@@ -61,7 +61,7 @@ export default function (opts) {
|
||||
}
|
||||
|
||||
function convertAttribute(node) {
|
||||
let value = convertAttributeValue(node.value || t.booleanLiteral(true));
|
||||
const value = convertAttributeValue(node.value || t.booleanLiteral(true));
|
||||
|
||||
if (t.isStringLiteral(value) && !t.isJSXExpressionContainer(node.value)) {
|
||||
value.value = value.value.replace(/\n\s+/g, " ");
|
||||
@@ -79,8 +79,8 @@ export default function (opts) {
|
||||
function buildElementCall(path, file) {
|
||||
path.parent.children = t.react.buildChildren(path.parent);
|
||||
|
||||
let tagExpr = convertJSXIdentifier(path.node.name, path.node);
|
||||
let args = [];
|
||||
const tagExpr = convertJSXIdentifier(path.node.name, path.node);
|
||||
const args = [];
|
||||
|
||||
let tagName;
|
||||
if (t.isIdentifier(tagExpr)) {
|
||||
@@ -89,7 +89,7 @@ export default function (opts) {
|
||||
tagName = tagExpr.value;
|
||||
}
|
||||
|
||||
let state: ElementState = {
|
||||
const state: ElementState = {
|
||||
tagExpr: tagExpr,
|
||||
tagName: tagName,
|
||||
args: args
|
||||
@@ -124,9 +124,9 @@ export default function (opts) {
|
||||
|
||||
function buildOpeningElementAttributes(attribs, file) {
|
||||
let _props = [];
|
||||
let objs = [];
|
||||
const objs = [];
|
||||
|
||||
let useBuiltIns = file.opts.useBuiltIns || false;
|
||||
const useBuiltIns = file.opts.useBuiltIns || false;
|
||||
if (typeof useBuiltIns !== "boolean") {
|
||||
throw new Error("transform-react-jsx currently only accepts a boolean option for useBuiltIns (defaults to false)");
|
||||
}
|
||||
@@ -139,7 +139,7 @@ export default function (opts) {
|
||||
}
|
||||
|
||||
while (attribs.length) {
|
||||
let prop = attribs.shift();
|
||||
const prop = attribs.shift();
|
||||
if (t.isJSXSpreadAttribute(prop)) {
|
||||
pushProps();
|
||||
objs.push(prop.argument);
|
||||
|
||||
@@ -2,7 +2,7 @@ import hoistVariables from "babel-helper-hoist-variables";
|
||||
import type { NodePath } from "babel-traverse";
|
||||
import * as t from "babel-types";
|
||||
|
||||
let visitor = {
|
||||
const visitor = {
|
||||
enter(path, state) {
|
||||
if (path.isThisExpression()) {
|
||||
state.foundThis = true;
|
||||
@@ -19,8 +19,8 @@ let visitor = {
|
||||
};
|
||||
|
||||
export default function (path: NodePath, scope = path.scope) {
|
||||
let { node } = path;
|
||||
let container = t.functionExpression(null, [], node.body, node.generator, node.async);
|
||||
const { node } = path;
|
||||
const container = t.functionExpression(null, [], node.body, node.generator, node.async);
|
||||
|
||||
let callee = container;
|
||||
let args = [];
|
||||
@@ -28,7 +28,7 @@ export default function (path: NodePath, scope = path.scope) {
|
||||
// todo: only hoist if necessary
|
||||
hoistVariables(path, (id) => scope.push({ id }));
|
||||
|
||||
let state = {
|
||||
const state = {
|
||||
foundThis: false,
|
||||
foundArguments: false
|
||||
};
|
||||
|
||||
@@ -16,7 +16,7 @@ function toKind(node: Object) {
|
||||
}
|
||||
|
||||
export function push(mutatorMap: Object, node: Object, kind: string, file, scope?): Object {
|
||||
let alias = t.toKeyAlias(node);
|
||||
const alias = t.toKeyAlias(node);
|
||||
|
||||
//
|
||||
|
||||
@@ -36,7 +36,7 @@ export function push(mutatorMap: Object, node: Object, kind: string, file, scope
|
||||
}
|
||||
|
||||
if (node.decorators) {
|
||||
let decorators = map.decorators = map.decorators || t.arrayExpression([]);
|
||||
const decorators = map.decorators = map.decorators || t.arrayExpression([]);
|
||||
decorators.elements = decorators.elements.concat(node.decorators.map((dec) => dec.expression).reverse());
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ export function push(mutatorMap: Object, node: Object, kind: string, file, scope
|
||||
value.returnType = node.returnType;
|
||||
}
|
||||
|
||||
let inheritedKind = toKind(node);
|
||||
const inheritedKind = toKind(node);
|
||||
if (!kind || inheritedKind !== "value") {
|
||||
kind = inheritedKind;
|
||||
}
|
||||
@@ -77,7 +77,7 @@ export function push(mutatorMap: Object, node: Object, kind: string, file, scope
|
||||
}
|
||||
|
||||
export function hasComputed(mutatorMap: Object): boolean {
|
||||
for (let key in mutatorMap) {
|
||||
for (const key in mutatorMap) {
|
||||
if (mutatorMap[key]._computed) {
|
||||
return true;
|
||||
}
|
||||
@@ -86,11 +86,11 @@ export function hasComputed(mutatorMap: Object): boolean {
|
||||
}
|
||||
|
||||
export function toComputedObjectFromClass(obj: Object): Object {
|
||||
let objExpr = t.arrayExpression([]);
|
||||
const objExpr = t.arrayExpression([]);
|
||||
|
||||
for (let i = 0; i < obj.properties.length; i++) {
|
||||
let prop = obj.properties[i];
|
||||
let val = prop.value;
|
||||
const prop = obj.properties[i];
|
||||
const val = prop.value;
|
||||
val.properties.unshift(t.objectProperty(t.identifier("key"), t.toComputedKey(prop)));
|
||||
objExpr.elements.push(val);
|
||||
}
|
||||
@@ -99,20 +99,20 @@ export function toComputedObjectFromClass(obj: Object): Object {
|
||||
}
|
||||
|
||||
export function toClassObject(mutatorMap: Object): Object {
|
||||
let objExpr = t.objectExpression([]);
|
||||
const objExpr = t.objectExpression([]);
|
||||
|
||||
each(mutatorMap, function (map) {
|
||||
let mapNode = t.objectExpression([]);
|
||||
const mapNode = t.objectExpression([]);
|
||||
|
||||
let propNode = t.objectProperty(map._key, mapNode, map._computed);
|
||||
const propNode = t.objectProperty(map._key, mapNode, map._computed);
|
||||
|
||||
each(map, function (node, key) {
|
||||
if (key[0] === "_") return;
|
||||
|
||||
let inheritNode = node;
|
||||
const inheritNode = node;
|
||||
if (t.isClassMethod(node) || t.isClassProperty(node)) node = node.value;
|
||||
|
||||
let prop = t.objectProperty(t.identifier(key), node);
|
||||
const prop = t.objectProperty(t.identifier(key), node);
|
||||
t.inheritsComments(prop, inheritNode);
|
||||
t.removeComments(inheritNode);
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ function getObjRef(node, nodes, file, scope) {
|
||||
throw new Error(`We can't explode this node type ${node.type}`);
|
||||
}
|
||||
|
||||
let temp = scope.generateUidIdentifierBasedOnNode(ref);
|
||||
const temp = scope.generateUidIdentifierBasedOnNode(ref);
|
||||
nodes.push(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(temp, ref)
|
||||
]));
|
||||
@@ -39,11 +39,11 @@ function getObjRef(node, nodes, file, scope) {
|
||||
}
|
||||
|
||||
function getPropRef(node, nodes, file, scope) {
|
||||
let prop = node.property;
|
||||
let key = t.toComputedKey(node, prop);
|
||||
const prop = node.property;
|
||||
const key = t.toComputedKey(node, prop);
|
||||
if (t.isLiteral(key) && t.isPureish(key)) return key;
|
||||
|
||||
let temp = scope.generateUidIdentifierBasedOnNode(prop);
|
||||
const temp = scope.generateUidIdentifierBasedOnNode(prop);
|
||||
nodes.push(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(temp, prop)
|
||||
]));
|
||||
@@ -73,8 +73,8 @@ export default function (
|
||||
ref = node;
|
||||
uid = obj;
|
||||
} else {
|
||||
let prop = getPropRef(node, nodes, file, scope);
|
||||
let computed = node.computed || t.isLiteral(prop);
|
||||
const prop = getPropRef(node, nodes, file, scope);
|
||||
const computed = node.computed || t.isLiteral(prop);
|
||||
uid = ref = t.memberExpression(obj, prop, computed);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,12 +5,12 @@ import * as t from "babel-types";
|
||||
export default function (classPath) {
|
||||
classPath.assertClass();
|
||||
|
||||
let memoisedExpressions = [];
|
||||
const memoisedExpressions = [];
|
||||
|
||||
function maybeMemoise(path) {
|
||||
if (!path.node || path.isPure()) return;
|
||||
|
||||
let uid = classPath.scope.generateDeclaredUidIdentifier();
|
||||
const uid = classPath.scope.generateDeclaredUidIdentifier();
|
||||
memoisedExpressions.push(t.assignmentExpression("=", uid, path.node));
|
||||
path.replaceWith(uid);
|
||||
}
|
||||
@@ -24,7 +24,7 @@ export default function (classPath) {
|
||||
// bind decorators if they're member expressions
|
||||
bindifyDecorators(paths);
|
||||
|
||||
for (let path of paths) {
|
||||
for (const path of paths) {
|
||||
maybeMemoise(path);
|
||||
}
|
||||
}
|
||||
@@ -32,8 +32,8 @@ export default function (classPath) {
|
||||
maybeMemoise(classPath.get("superClass"));
|
||||
memoiseDecorators(classPath.get("decorators"), true);
|
||||
|
||||
let methods: Array<NodePath> = classPath.get("body.body");
|
||||
for (let methodPath of methods) {
|
||||
const methods: Array<NodePath> = classPath.get("body.body");
|
||||
for (const methodPath of methods) {
|
||||
if (methodPath.is("computed")) {
|
||||
maybeMemoise(methodPath.get("key"));
|
||||
}
|
||||
|
||||
@@ -41,23 +41,23 @@ function shouldIgnore(name, blacklist?: Array<string>) {
|
||||
return true;
|
||||
}
|
||||
|
||||
let ext = path.extname(name);
|
||||
let base = path.basename(name, ext);
|
||||
const ext = path.extname(name);
|
||||
const base = path.basename(name, ext);
|
||||
|
||||
return name[0] === "." || ext === ".md" || base === "LICENSE" || base === "options";
|
||||
}
|
||||
|
||||
export default function get(entryLoc): Array<Suite> {
|
||||
let suites = [];
|
||||
const suites = [];
|
||||
|
||||
let rootOpts = {};
|
||||
let rootOptsLoc = resolve(entryLoc + "/options");
|
||||
const rootOptsLoc = resolve(entryLoc + "/options");
|
||||
if (rootOptsLoc) rootOpts = require(rootOptsLoc);
|
||||
|
||||
for (let suiteName of fs.readdirSync(entryLoc)) {
|
||||
for (const suiteName of fs.readdirSync(entryLoc)) {
|
||||
if (shouldIgnore(suiteName)) continue;
|
||||
|
||||
let suite = {
|
||||
const suite = {
|
||||
options: _.clone(rootOpts),
|
||||
tests: [],
|
||||
title: humanize(suiteName),
|
||||
@@ -67,24 +67,24 @@ export default function get(entryLoc): Array<Suite> {
|
||||
assertDirectory(suite.filename);
|
||||
suites.push(suite);
|
||||
|
||||
let suiteOptsLoc = resolve(suite.filename + "/options");
|
||||
const suiteOptsLoc = resolve(suite.filename + "/options");
|
||||
if (suiteOptsLoc) suite.options = require(suiteOptsLoc);
|
||||
|
||||
for (let taskName of fs.readdirSync(suite.filename)) {
|
||||
for (const taskName of fs.readdirSync(suite.filename)) {
|
||||
push(taskName, suite.filename + "/" + taskName);
|
||||
}
|
||||
|
||||
function push(taskName, taskDir) {
|
||||
let actualLocAlias = suiteName + "/" + taskName + "/actual.js";
|
||||
const actualLocAlias = suiteName + "/" + taskName + "/actual.js";
|
||||
let expectLocAlias = suiteName + "/" + taskName + "/expected.js";
|
||||
let execLocAlias = suiteName + "/" + taskName + "/exec.js";
|
||||
const execLocAlias = suiteName + "/" + taskName + "/exec.js";
|
||||
|
||||
let actualLoc = taskDir + "/actual.js";
|
||||
const actualLoc = taskDir + "/actual.js";
|
||||
let expectLoc = taskDir + "/expected.js";
|
||||
let execLoc = taskDir + "/exec.js";
|
||||
|
||||
if (fs.statSync(taskDir).isFile()) {
|
||||
let ext = path.extname(taskDir);
|
||||
const ext = path.extname(taskDir);
|
||||
if (ext !== ".js" && ext !== ".module.js") return;
|
||||
|
||||
execLoc = taskDir;
|
||||
@@ -95,12 +95,12 @@ export default function get(entryLoc): Array<Suite> {
|
||||
expectLocAlias += "on";
|
||||
}
|
||||
|
||||
let taskOpts = _.cloneDeep(suite.options);
|
||||
const taskOpts = _.cloneDeep(suite.options);
|
||||
|
||||
let taskOptsLoc = resolve(taskDir + "/options");
|
||||
const taskOptsLoc = resolve(taskDir + "/options");
|
||||
if (taskOptsLoc) _.merge(taskOpts, require(taskOptsLoc));
|
||||
|
||||
let test = {
|
||||
const test = {
|
||||
optionsDir: taskOptsLoc ? path.dirname(taskOptsLoc) : null,
|
||||
title: humanize(taskName, true),
|
||||
disabled: taskName[0] === ".",
|
||||
@@ -130,12 +130,12 @@ export default function get(entryLoc): Array<Suite> {
|
||||
|
||||
suite.tests.push(test);
|
||||
|
||||
let sourceMappingsLoc = taskDir + "/source-mappings.json";
|
||||
const sourceMappingsLoc = taskDir + "/source-mappings.json";
|
||||
if (fs.existsSync(sourceMappingsLoc)) {
|
||||
test.sourceMappings = JSON.parse(readFile(sourceMappingsLoc));
|
||||
}
|
||||
|
||||
let sourceMapLoc = taskDir + "/source-map.json";
|
||||
const sourceMapLoc = taskDir + "/source-map.json";
|
||||
if (fs.existsSync(sourceMapLoc)) {
|
||||
test.sourceMap = JSON.parse(readFile(sourceMapLoc));
|
||||
}
|
||||
@@ -146,12 +146,12 @@ export default function get(entryLoc): Array<Suite> {
|
||||
}
|
||||
|
||||
export function multiple(entryLoc, ignore?: Array<string>) {
|
||||
let categories = {};
|
||||
const categories = {};
|
||||
|
||||
for (let name of fs.readdirSync(entryLoc)) {
|
||||
for (const name of fs.readdirSync(entryLoc)) {
|
||||
if (shouldIgnore(name, ignore)) continue;
|
||||
|
||||
let loc = path.join(entryLoc, name);
|
||||
const loc = path.join(entryLoc, name);
|
||||
assertDirectory(loc);
|
||||
|
||||
categories[name] = get(loc);
|
||||
|
||||
@@ -4,7 +4,7 @@ import getFunctionArity from "babel-helper-get-function-arity";
|
||||
import template from "babel-template";
|
||||
import * as t from "babel-types";
|
||||
|
||||
let buildPropertyMethodAssignmentWrapper = template(`
|
||||
const buildPropertyMethodAssignmentWrapper = template(`
|
||||
(function (FUNCTION_KEY) {
|
||||
function FUNCTION_ID() {
|
||||
return FUNCTION_KEY.apply(this, arguments);
|
||||
@@ -18,7 +18,7 @@ let buildPropertyMethodAssignmentWrapper = template(`
|
||||
})(FUNCTION)
|
||||
`);
|
||||
|
||||
let buildGeneratorPropertyMethodAssignmentWrapper = template(`
|
||||
const buildGeneratorPropertyMethodAssignmentWrapper = template(`
|
||||
(function (FUNCTION_KEY) {
|
||||
function* FUNCTION_ID() {
|
||||
return yield* FUNCTION_KEY.apply(this, arguments);
|
||||
@@ -32,14 +32,14 @@ let buildGeneratorPropertyMethodAssignmentWrapper = template(`
|
||||
})(FUNCTION)
|
||||
`);
|
||||
|
||||
let visitor = {
|
||||
const visitor = {
|
||||
"ReferencedIdentifier|BindingIdentifier"(path, state) {
|
||||
// check if this node matches our function id
|
||||
if (path.node.name !== state.name) return;
|
||||
|
||||
// check that we don't have a local variable declared as that removes the need
|
||||
// for the wrapper
|
||||
let localDeclar = path.scope.getBindingIdentifier(state.name);
|
||||
const localDeclar = path.scope.getBindingIdentifier(state.name);
|
||||
if (localDeclar !== state.outerDeclar) return;
|
||||
|
||||
state.selfReference = true;
|
||||
@@ -59,7 +59,7 @@ function wrap(state, method, id, scope) {
|
||||
// need to add a wrapper since we can't change the references
|
||||
let build = buildPropertyMethodAssignmentWrapper;
|
||||
if (method.generator) build = buildGeneratorPropertyMethodAssignmentWrapper;
|
||||
let template = build({
|
||||
const template = build({
|
||||
FUNCTION: method,
|
||||
FUNCTION_ID: id,
|
||||
FUNCTION_KEY: scope.generateUidIdentifier(id.name)
|
||||
@@ -68,7 +68,7 @@ function wrap(state, method, id, scope) {
|
||||
|
||||
// shim in dummy params to retain function arity, if you try to read the
|
||||
// source then you'll get the original since it's proxied so it's all good
|
||||
let params = template.callee.body.body[0].params;
|
||||
const params = template.callee.body.body[0].params;
|
||||
for (let i = 0, len = getFunctionArity(method); i < len; i++) {
|
||||
params.push(scope.generateUidIdentifier("x"));
|
||||
}
|
||||
@@ -82,7 +82,7 @@ function wrap(state, method, id, scope) {
|
||||
}
|
||||
|
||||
function visit(node, name, scope) {
|
||||
let state = {
|
||||
const state = {
|
||||
selfAssignment: false,
|
||||
selfReference: false,
|
||||
outerDeclar: scope.getBindingIdentifier(name),
|
||||
@@ -93,7 +93,7 @@ function visit(node, name, scope) {
|
||||
// check to see if we have a local binding of the id we're setting inside of
|
||||
// the function, this is important as there are caveats associated
|
||||
|
||||
let binding = scope.getOwnBinding(name);
|
||||
const binding = scope.getOwnBinding(name);
|
||||
|
||||
if (binding) {
|
||||
if (binding.kind === "param") {
|
||||
@@ -139,7 +139,7 @@ export default function ({ node, parent, scope, id }) {
|
||||
id = parent.id;
|
||||
|
||||
if (t.isIdentifier(id)) {
|
||||
let binding = scope.parent.getBinding(id.name);
|
||||
const binding = scope.parent.getBinding(id.name);
|
||||
if (binding && binding.constant && scope.getBinding(id.name) === binding) {
|
||||
// always going to reference this method
|
||||
node.id = id;
|
||||
@@ -171,6 +171,6 @@ export default function ({ node, parent, scope, id }) {
|
||||
// a local binding.
|
||||
id[t.NOT_LOCAL_BINDING] = true;
|
||||
|
||||
let state = visit(node, name, scope);
|
||||
const state = visit(node, name, scope);
|
||||
return wrap(state, node, id, scope) || node;
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import * as t from "babel-types";
|
||||
|
||||
export default function (node): number {
|
||||
let params: Array<Object> = node.params;
|
||||
const params: Array<Object> = node.params;
|
||||
for (let i = 0; i < params.length; i++) {
|
||||
let param = params[i];
|
||||
const param = params[i];
|
||||
if (t.isAssignmentPattern(param) || t.isRestElement(param)) {
|
||||
return i;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import * as t from "babel-types";
|
||||
|
||||
let visitor = {
|
||||
const visitor = {
|
||||
Scope(path, state) {
|
||||
if (state.kind === "let") path.skip();
|
||||
},
|
||||
@@ -12,12 +12,12 @@ let visitor = {
|
||||
VariableDeclaration(path, state) {
|
||||
if (state.kind && path.node.kind !== state.kind) return;
|
||||
|
||||
let nodes = [];
|
||||
const nodes = [];
|
||||
|
||||
let declarations: Array<Object> = path.get("declarations");
|
||||
const declarations: Array<Object> = path.get("declarations");
|
||||
let firstId;
|
||||
|
||||
for (let declar of declarations) {
|
||||
for (const declar of declarations) {
|
||||
firstId = declar.node.id;
|
||||
|
||||
if (declar.node.init) {
|
||||
@@ -26,7 +26,7 @@ let visitor = {
|
||||
));
|
||||
}
|
||||
|
||||
for (let name in declar.getBindingIdentifiers()) {
|
||||
for (const name in declar.getBindingIdentifiers()) {
|
||||
state.emit(t.identifier(name), name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,6 @@ import testRunner from "babel-helper-transform-fixture-test-runner";
|
||||
import path from "path";
|
||||
|
||||
export default function (loc) {
|
||||
let name = path.basename(path.dirname(loc));
|
||||
const name = path.basename(path.dirname(loc));
|
||||
testRunner(loc + "/fixtures", name);
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ export function is(node: Object, flag: string): boolean {
|
||||
}
|
||||
|
||||
export function pullFlag(node: Object, flag: string) {
|
||||
let flags = node.flags.split("");
|
||||
const flags = node.flags.split("");
|
||||
if (node.flags.indexOf(flag) < 0) return;
|
||||
pull(flags, flag);
|
||||
node.flags = flags.join("");
|
||||
|
||||
@@ -2,7 +2,7 @@ import * as t from "babel-types";
|
||||
import template from "babel-template";
|
||||
import traverse from "babel-traverse";
|
||||
|
||||
let buildForAwait = template(`
|
||||
const buildForAwait = template(`
|
||||
function* wrapper() {
|
||||
var ITERATOR_COMPLETION = true;
|
||||
var ITERATOR_HAD_ERROR_KEY = false;
|
||||
@@ -35,7 +35,7 @@ let buildForAwait = template(`
|
||||
}
|
||||
`);
|
||||
|
||||
let forAwaitVisitor = {
|
||||
const forAwaitVisitor = {
|
||||
noScope: true,
|
||||
|
||||
Identifier(path, replacements) {
|
||||
@@ -45,7 +45,7 @@ let forAwaitVisitor = {
|
||||
},
|
||||
|
||||
CallExpression(path, replacements) {
|
||||
let callee = path.node.callee;
|
||||
const callee = path.node.callee;
|
||||
|
||||
// if no await wrapping is being applied, unwrap the call expression
|
||||
if (t.isIdentifier(callee) && callee.name === "AWAIT" && !replacements.AWAIT) {
|
||||
@@ -55,11 +55,11 @@ let forAwaitVisitor = {
|
||||
};
|
||||
|
||||
export default function (path, helpers) {
|
||||
let { node, scope, parent } = path;
|
||||
const { node, scope, parent } = path;
|
||||
|
||||
let stepKey = scope.generateUidIdentifier("step");
|
||||
let stepValue = scope.generateUidIdentifier("value");
|
||||
let left = node.left;
|
||||
const stepKey = scope.generateUidIdentifier("step");
|
||||
const stepValue = scope.generateUidIdentifier("value");
|
||||
const left = node.left;
|
||||
let declar;
|
||||
|
||||
if (t.isIdentifier(left) || t.isPattern(left) || t.isMemberExpression(left)) {
|
||||
@@ -89,9 +89,9 @@ export default function (path, helpers) {
|
||||
// remove generator function wrapper
|
||||
template = template.body.body;
|
||||
|
||||
let isLabeledParent = t.isLabeledStatement(parent);
|
||||
let tryBody = template[3].block.body;
|
||||
let loop = tryBody[0];
|
||||
const isLabeledParent = t.isLabeledStatement(parent);
|
||||
const tryBody = template[3].block.body;
|
||||
const loop = tryBody[0];
|
||||
|
||||
if (isLabeledParent) {
|
||||
tryBody[0] = t.labeledStatement(parent.label, loop);
|
||||
|
||||
@@ -6,7 +6,7 @@ import template from "babel-template";
|
||||
import * as t from "babel-types";
|
||||
import rewriteForAwait from "./for-await";
|
||||
|
||||
let buildWrapper = template(`
|
||||
const buildWrapper = template(`
|
||||
(() => {
|
||||
var REF = FUNCTION;
|
||||
return function NAME(PARAMS) {
|
||||
@@ -15,7 +15,7 @@ let buildWrapper = template(`
|
||||
})
|
||||
`);
|
||||
|
||||
let namedBuildWrapper = template(`
|
||||
const namedBuildWrapper = template(`
|
||||
(() => {
|
||||
var REF = FUNCTION;
|
||||
function NAME(PARAMS) {
|
||||
@@ -25,7 +25,7 @@ let namedBuildWrapper = template(`
|
||||
})
|
||||
`);
|
||||
|
||||
let awaitVisitor = {
|
||||
const awaitVisitor = {
|
||||
Function(path) {
|
||||
if (path.isArrowFunctionExpression() && !path.node.async) {
|
||||
path.arrowFunctionToShadowed();
|
||||
@@ -42,15 +42,15 @@ let awaitVisitor = {
|
||||
},
|
||||
|
||||
ForAwaitStatement(path, { file, wrapAwait }) {
|
||||
let { node } = path;
|
||||
const { node } = path;
|
||||
|
||||
let build = rewriteForAwait(path, {
|
||||
const build = rewriteForAwait(path, {
|
||||
getAsyncIterator: file.addHelper("asyncIterator"),
|
||||
wrapAwait
|
||||
});
|
||||
|
||||
let { declar, loop } = build;
|
||||
let block = loop.body;
|
||||
const { declar, loop } = build;
|
||||
const block = loop.body;
|
||||
|
||||
// ensure that it's a block so we can take all its statements
|
||||
path.ensureBlock();
|
||||
@@ -77,12 +77,12 @@ let awaitVisitor = {
|
||||
};
|
||||
|
||||
function classOrObjectMethod(path: NodePath, callId: Object) {
|
||||
let node = path.node;
|
||||
let body = node.body;
|
||||
const node = path.node;
|
||||
const body = node.body;
|
||||
|
||||
node.async = false;
|
||||
|
||||
let container = t.functionExpression(null, [], t.blockStatement(body.body), true);
|
||||
const container = t.functionExpression(null, [], t.blockStatement(body.body), true);
|
||||
container.shadow = true;
|
||||
body.body = [
|
||||
t.returnStatement(t.callExpression(
|
||||
@@ -97,9 +97,9 @@ function classOrObjectMethod(path: NodePath, callId: Object) {
|
||||
}
|
||||
|
||||
function plainFunction(path: NodePath, callId: Object) {
|
||||
let node = path.node;
|
||||
let isDeclaration = path.isFunctionDeclaration();
|
||||
let asyncFnId = node.id;
|
||||
const node = path.node;
|
||||
const isDeclaration = path.isFunctionDeclaration();
|
||||
const asyncFnId = node.id;
|
||||
let wrapper = buildWrapper;
|
||||
|
||||
if (path.isArrowFunctionExpression()) {
|
||||
@@ -117,8 +117,8 @@ function plainFunction(path: NodePath, callId: Object) {
|
||||
node.type = "FunctionExpression";
|
||||
}
|
||||
|
||||
let built = t.callExpression(callId, [node]);
|
||||
let container = wrapper({
|
||||
const built = t.callExpression(callId, [node]);
|
||||
const container = wrapper({
|
||||
NAME: asyncFnId,
|
||||
REF: path.scope.generateUidIdentifier("ref"),
|
||||
FUNCTION: built,
|
||||
@@ -137,7 +137,7 @@ function plainFunction(path: NodePath, callId: Object) {
|
||||
}).expression;
|
||||
|
||||
if (isDeclaration) {
|
||||
let declar = t.variableDeclaration("let", [
|
||||
const declar = t.variableDeclaration("let", [
|
||||
t.variableDeclarator(
|
||||
t.identifier(asyncFnId.name),
|
||||
t.callExpression(container, [])
|
||||
@@ -147,7 +147,7 @@ function plainFunction(path: NodePath, callId: Object) {
|
||||
|
||||
path.replaceWith(declar);
|
||||
} else {
|
||||
let retFunction = container.body.body[1].argument;
|
||||
const retFunction = container.body.body[1].argument;
|
||||
if (!asyncFnId) {
|
||||
nameFunction({
|
||||
node: retFunction,
|
||||
|
||||
@@ -6,7 +6,7 @@ import * as messages from "babel-messages";
|
||||
import * as t from "babel-types";
|
||||
|
||||
// ✌️
|
||||
let HARDCORE_THIS_REF = Symbol();
|
||||
const HARDCORE_THIS_REF = Symbol();
|
||||
|
||||
function isIllegalBareSuper(node, parent) {
|
||||
if (!t.isSuper(node)) return false;
|
||||
@@ -46,7 +46,7 @@ function getPrototypeOfExpression(objectRef, isStatic) {
|
||||
);
|
||||
}
|
||||
|
||||
let visitor = {
|
||||
const visitor = {
|
||||
Function(path) {
|
||||
if (!path.inShadow("this")) {
|
||||
path.skip();
|
||||
@@ -69,9 +69,9 @@ let visitor = {
|
||||
let callback = state.specHandle;
|
||||
if (state.isLoose) callback = state.looseHandle;
|
||||
|
||||
let isBareSuper = path.isCallExpression() && path.get("callee").isSuper();
|
||||
const isBareSuper = path.isCallExpression() && path.get("callee").isSuper();
|
||||
|
||||
let result = callback.call(state, path);
|
||||
const result = callback.call(state, path);
|
||||
|
||||
if (result) {
|
||||
state.hasSuper = true;
|
||||
@@ -185,8 +185,8 @@ export default class ReplaceSupers {
|
||||
}
|
||||
|
||||
getLooseSuperProperty(id: Object, parent: Object) {
|
||||
let methodNode = this.methodNode;
|
||||
let superRef = this.superRef || t.identifier("Function");
|
||||
const methodNode = this.methodNode;
|
||||
const superRef = this.superRef || t.identifier("Function");
|
||||
|
||||
if (parent.property === id) {
|
||||
return;
|
||||
@@ -201,11 +201,11 @@ export default class ReplaceSupers {
|
||||
}
|
||||
|
||||
looseHandle(path: NodePath) {
|
||||
let node = path.node;
|
||||
const node = path.node;
|
||||
if (path.isSuper()) {
|
||||
return this.getLooseSuperProperty(node, path.parent);
|
||||
} else if (path.isCallExpression()) {
|
||||
let callee = node.callee;
|
||||
const callee = node.callee;
|
||||
if (!t.isMemberExpression(callee)) return;
|
||||
if (!t.isSuper(callee.object)) return;
|
||||
|
||||
@@ -239,15 +239,15 @@ export default class ReplaceSupers {
|
||||
let computed;
|
||||
let args;
|
||||
|
||||
let parent = path.parent;
|
||||
let node = path.node;
|
||||
const parent = path.parent;
|
||||
const node = path.node;
|
||||
|
||||
if (isIllegalBareSuper(node, parent)) {
|
||||
throw path.buildCodeFrameError(messages.get("classesIllegalBareSuper"));
|
||||
}
|
||||
|
||||
if (t.isCallExpression(node)) {
|
||||
let callee = node.callee;
|
||||
const callee = node.callee;
|
||||
if (t.isSuper(callee)) {
|
||||
return;
|
||||
} else if (isMemberExpressionSuper(callee)) {
|
||||
@@ -261,13 +261,13 @@ export default class ReplaceSupers {
|
||||
property = node.property;
|
||||
computed = node.computed;
|
||||
} else if (t.isUpdateExpression(node) && isMemberExpressionSuper(node.argument)) {
|
||||
let binary = t.binaryExpression(node.operator[0], node.argument, t.numericLiteral(1));
|
||||
const binary = t.binaryExpression(node.operator[0], node.argument, t.numericLiteral(1));
|
||||
if (node.prefix) {
|
||||
// ++super.foo; -> super.foo += 1;
|
||||
return this.specHandleAssignmentExpression(null, path, binary);
|
||||
} else {
|
||||
// super.foo++; -> let _ref = super.foo; super.foo = _ref + 1;
|
||||
let ref = path.scope.generateUidIdentifier("ref");
|
||||
const ref = path.scope.generateUidIdentifier("ref");
|
||||
return this.specHandleAssignmentExpression(ref, path, binary).concat(t.expressionStatement(ref));
|
||||
}
|
||||
} else if (t.isAssignmentExpression(node) && isMemberExpressionSuper(node.left)) {
|
||||
@@ -276,7 +276,7 @@ export default class ReplaceSupers {
|
||||
|
||||
if (!property) return;
|
||||
|
||||
let superProperty = this.getSuperProperty(property, computed);
|
||||
const superProperty = this.getSuperProperty(property, computed);
|
||||
|
||||
if (args) {
|
||||
return this.optimiseCall(superProperty, args);
|
||||
@@ -286,7 +286,7 @@ export default class ReplaceSupers {
|
||||
}
|
||||
|
||||
optimiseCall(callee, args) {
|
||||
let thisNode = t.thisExpression();
|
||||
const thisNode = t.thisExpression();
|
||||
thisNode[HARDCORE_THIS_REF] = true;
|
||||
return optimiseCall(callee, thisNode, args);
|
||||
}
|
||||
|
||||
@@ -16,4 +16,4 @@ export function multiline(arr) {
|
||||
return arr.join("\n");
|
||||
}
|
||||
|
||||
export let assertArrayEquals = assert.deepEqual;
|
||||
export const assertArrayEquals = assert.deepEqual;
|
||||
|
||||
@@ -11,7 +11,7 @@ import "babel-polyfill";
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
|
||||
let babelHelpers = eval(buildExternalHelpers(null, "var"));
|
||||
const babelHelpers = eval(buildExternalHelpers(null, "var"));
|
||||
|
||||
function wrapPackagesArray(type, names, optionsDir) {
|
||||
return (names || []).map(function (val) {
|
||||
@@ -36,14 +36,14 @@ function wrapPackagesArray(type, names, optionsDir) {
|
||||
}
|
||||
|
||||
function run(task) {
|
||||
let actual = task.actual;
|
||||
let expect = task.expect;
|
||||
let exec = task.exec;
|
||||
let opts = task.options;
|
||||
let optionsDir = task.optionsDir;
|
||||
const actual = task.actual;
|
||||
const expect = task.expect;
|
||||
const exec = task.exec;
|
||||
const opts = task.options;
|
||||
const optionsDir = task.optionsDir;
|
||||
|
||||
function getOpts(self) {
|
||||
let newOpts = _.merge({
|
||||
const newOpts = _.merge({
|
||||
filename: self.loc,
|
||||
}, opts);
|
||||
|
||||
@@ -64,8 +64,8 @@ function run(task) {
|
||||
let resultExec;
|
||||
|
||||
if (execCode) {
|
||||
let execOpts = getOpts(exec);
|
||||
let execDirName = path.dirname(exec.loc);
|
||||
const execOpts = getOpts(exec);
|
||||
const execDirName = path.dirname(exec.loc);
|
||||
result = babel.transform(execCode, execOpts);
|
||||
execCode = result.code;
|
||||
|
||||
@@ -79,7 +79,7 @@ function run(task) {
|
||||
}
|
||||
|
||||
let actualCode = actual.code;
|
||||
let expectCode = expect.code;
|
||||
const expectCode = expect.code;
|
||||
if (!execCode || actualCode) {
|
||||
result = babel.transform(actualCode, getOpts(actual));
|
||||
if (!expect.code && result.code && !opts.throws && fs.statSync(path.dirname(expect.loc)).isDirectory() && !process.env.CI) {
|
||||
@@ -96,12 +96,12 @@ function run(task) {
|
||||
}
|
||||
|
||||
if (task.sourceMappings) {
|
||||
let consumer = new sourceMap.SourceMapConsumer(result.map);
|
||||
const consumer = new sourceMap.SourceMapConsumer(result.map);
|
||||
|
||||
_.each(task.sourceMappings, function (mapping) {
|
||||
let actual = mapping.original;
|
||||
const actual = mapping.original;
|
||||
|
||||
let expect = consumer.originalPositionFor(mapping.generated);
|
||||
const expect = consumer.originalPositionFor(mapping.generated);
|
||||
chai.expect({ line: expect.line, column: expect.column }).to.deep.equal(actual);
|
||||
});
|
||||
}
|
||||
@@ -112,7 +112,7 @@ function run(task) {
|
||||
}
|
||||
|
||||
function runExec(opts, execCode, execDirname) {
|
||||
let sandbox = {
|
||||
const sandbox = {
|
||||
...helpers,
|
||||
babelHelpers,
|
||||
assert: chai.assert,
|
||||
@@ -124,7 +124,7 @@ function runExec(opts, execCode, execDirname) {
|
||||
}
|
||||
};
|
||||
|
||||
let fn = new Function(...Object.keys(sandbox), execCode);
|
||||
const fn = new Function(...Object.keys(sandbox), execCode);
|
||||
return fn.apply(null, Object.values(sandbox));
|
||||
}
|
||||
|
||||
@@ -135,13 +135,13 @@ export default function (
|
||||
taskOpts = {},
|
||||
dynamicOpts?: Function,
|
||||
) {
|
||||
let suites = getFixtures(fixturesLoc);
|
||||
const suites = getFixtures(fixturesLoc);
|
||||
|
||||
for (let testSuite of suites) {
|
||||
for (const testSuite of suites) {
|
||||
if (_.includes(suiteOpts.ignoreSuites, testSuite.title)) continue;
|
||||
|
||||
describe(name + "/" + testSuite.title, function () {
|
||||
for (let task of testSuite.tests) {
|
||||
for (const task of testSuite.tests) {
|
||||
if (_.includes(suiteOpts.ignoreTasks, task.title) ||
|
||||
_.includes(suiteOpts.ignoreTasks, testSuite.title + "/" + task.title)) continue;
|
||||
|
||||
@@ -163,7 +163,7 @@ export default function (
|
||||
|
||||
if (dynamicOpts) dynamicOpts(task.options, task);
|
||||
|
||||
let throwMsg = task.options.throws;
|
||||
const throwMsg = task.options.throws;
|
||||
if (throwMsg) {
|
||||
// internal api doesn't have this option but it's best not to pollute
|
||||
// the options object with useless options
|
||||
@@ -174,7 +174,7 @@ export default function (
|
||||
});
|
||||
} else {
|
||||
if (task.exec.code) {
|
||||
let result = run(task);
|
||||
const result = run(task);
|
||||
if (result && typeof result.then === "function") {
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
import template from "babel-template";
|
||||
|
||||
let helpers = {};
|
||||
const helpers = {};
|
||||
export default helpers;
|
||||
|
||||
helpers.typeof = template(`
|
||||
|
||||
@@ -3,13 +3,13 @@
|
||||
import helpers from "./helpers";
|
||||
|
||||
export function get(name) {
|
||||
let fn = helpers[name];
|
||||
const fn = helpers[name];
|
||||
if (!fn) throw new ReferenceError(`Unknown helper ${name}`);
|
||||
|
||||
return fn().expression;
|
||||
}
|
||||
|
||||
export let list = Object.keys(helpers)
|
||||
export const list = Object.keys(helpers)
|
||||
.map((name) => name[0] === "_" ? name.slice(1) : name)
|
||||
.filter((name) => name !== "__esModule");
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ export const MESSAGES = {
|
||||
*/
|
||||
|
||||
export function get(key: string, ...args: Array<any>): string {
|
||||
let msg = MESSAGES[key];
|
||||
const msg = MESSAGES[key];
|
||||
if (!msg) throw new ReferenceError(`Unknown message ${JSON.stringify(key)}`);
|
||||
|
||||
// stringify args
|
||||
|
||||
@@ -2,11 +2,11 @@ export default function ({ messages }) {
|
||||
return {
|
||||
visitor: {
|
||||
Scope({ scope }) {
|
||||
for (let name in scope.bindings) {
|
||||
let binding = scope.bindings[name];
|
||||
for (const name in scope.bindings) {
|
||||
const binding = scope.bindings[name];
|
||||
if (binding.kind !== "const" && binding.kind !== "module") continue;
|
||||
|
||||
for (let violation of (binding.constantViolations: Array)) {
|
||||
for (const violation of (binding.constantViolations: Array)) {
|
||||
throw violation.buildCodeFrameError(messages.get("readOnly", name));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import remapAsyncToGenerator from "babel-helper-remap-async-to-generator";
|
||||
|
||||
export default function ({ types: t }) {
|
||||
let yieldStarVisitor = {
|
||||
const yieldStarVisitor = {
|
||||
Function(path) {
|
||||
path.skip();
|
||||
},
|
||||
|
||||
YieldExpression({ node }, state) {
|
||||
if (!node.delegate) return;
|
||||
let callee = state.addHelper("asyncGeneratorDelegate");
|
||||
const callee = state.addHelper("asyncGeneratorDelegate");
|
||||
node.argument = t.callExpression(callee, [
|
||||
t.callExpression(state.addHelper("asyncIterator"), [node.argument]),
|
||||
t.memberExpression(state.addHelper("asyncGenerator"), t.identifier("await"))
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import template from "babel-template";
|
||||
|
||||
let buildWrapper = template(`
|
||||
const buildWrapper = template(`
|
||||
let CLASS_REF = CLASS;
|
||||
var CALL_REF = CALL;
|
||||
var WRAPPER_REF = function (...args) {
|
||||
@@ -15,12 +15,12 @@ let buildWrapper = template(`
|
||||
`);
|
||||
|
||||
export default function ({ types: t }) {
|
||||
let ALREADY_VISITED = Symbol();
|
||||
const ALREADY_VISITED = Symbol();
|
||||
|
||||
function findConstructorCall(path): ?Object {
|
||||
let methods: Array<Object> = path.get("body.body");
|
||||
const methods: Array<Object> = path.get("body.body");
|
||||
|
||||
for (let method of methods) {
|
||||
for (const method of methods) {
|
||||
if (method.node.kind === "constructorCall") {
|
||||
return method;
|
||||
}
|
||||
@@ -30,8 +30,8 @@ export default function ({ types: t }) {
|
||||
}
|
||||
|
||||
function handleClassWithCall(constructorCall, classPath) {
|
||||
let { node } = classPath;
|
||||
let ref = node.id || classPath.scope.generateUidIdentifier("class");
|
||||
const { node } = classPath;
|
||||
const ref = node.id || classPath.scope.generateUidIdentifier("class");
|
||||
|
||||
if (classPath.parentPath.isExportDefaultDeclaration()) {
|
||||
classPath = classPath.parentPath;
|
||||
@@ -57,7 +57,7 @@ export default function ({ types: t }) {
|
||||
if (path.node[ALREADY_VISITED]) return;
|
||||
path.node[ALREADY_VISITED] = true;
|
||||
|
||||
let constructorCall = findConstructorCall(path);
|
||||
const constructorCall = findConstructorCall(path);
|
||||
|
||||
if (constructorCall) {
|
||||
handleClassWithCall(constructorCall, path);
|
||||
|
||||
@@ -3,7 +3,7 @@ import nameFunction from "babel-helper-function-name";
|
||||
import template from "babel-template";
|
||||
|
||||
export default function ({ types: t }) {
|
||||
let findBareSupers = {
|
||||
const findBareSupers = {
|
||||
Super(path) {
|
||||
if (path.parentPath.isCallExpression({ callee: path.node })) {
|
||||
this.push(path.parentPath);
|
||||
@@ -11,7 +11,7 @@ export default function ({ types: t }) {
|
||||
}
|
||||
};
|
||||
|
||||
let referenceVisitor = {
|
||||
const referenceVisitor = {
|
||||
ReferencedIdentifier(path) {
|
||||
if (this.scope.hasOwnBinding(path.node.name)) {
|
||||
this.collision = true;
|
||||
@@ -45,12 +45,12 @@ export default function ({ types: t }) {
|
||||
visitor: {
|
||||
Class(path, state) {
|
||||
const buildClassProperty = state.opts.spec ? buildClassPropertySpec : buildClassPropertyNonSpec;
|
||||
let isDerived = !!path.node.superClass;
|
||||
const isDerived = !!path.node.superClass;
|
||||
let constructor;
|
||||
let props = [];
|
||||
let body = path.get("body");
|
||||
const props = [];
|
||||
const body = path.get("body");
|
||||
|
||||
for (let path of body.get("body")) {
|
||||
for (const path of body.get("body")) {
|
||||
if (path.isClassProperty()) {
|
||||
props.push(path);
|
||||
} else if (path.isClassMethod({ kind: "constructor" })) {
|
||||
@@ -60,7 +60,7 @@ export default function ({ types: t }) {
|
||||
|
||||
if (!props.length) return;
|
||||
|
||||
let nodes = [];
|
||||
const nodes = [];
|
||||
let ref;
|
||||
|
||||
if (path.isClassExpression() || !path.node.id) {
|
||||
@@ -72,15 +72,15 @@ export default function ({ types: t }) {
|
||||
|
||||
let instanceBody = [];
|
||||
|
||||
for (let prop of props) {
|
||||
let propNode = prop.node;
|
||||
for (const prop of props) {
|
||||
const propNode = prop.node;
|
||||
if (propNode.decorators && propNode.decorators.length > 0) continue;
|
||||
|
||||
// In non-spec mode, all properties without values are ignored.
|
||||
// In spec mode, *static* properties without values are still defined (see below).
|
||||
if (!state.opts.spec && !propNode.value) continue;
|
||||
|
||||
let isStatic = propNode.static;
|
||||
const isStatic = propNode.static;
|
||||
|
||||
if (isStatic) {
|
||||
nodes.push(buildClassProperty(ref, propNode));
|
||||
@@ -92,7 +92,7 @@ export default function ({ types: t }) {
|
||||
|
||||
if (instanceBody.length) {
|
||||
if (!constructor) {
|
||||
let newConstructor = t.classMethod("constructor", t.identifier("constructor"), [], t.blockStatement([]));
|
||||
const newConstructor = t.classMethod("constructor", t.identifier("constructor"), [], t.blockStatement([]));
|
||||
if (isDerived) {
|
||||
newConstructor.params = [t.restElement(t.identifier("args"))];
|
||||
newConstructor.body.body.push(
|
||||
@@ -107,18 +107,18 @@ export default function ({ types: t }) {
|
||||
[constructor] = body.unshiftContainer("body", newConstructor);
|
||||
}
|
||||
|
||||
let collisionState = {
|
||||
const collisionState = {
|
||||
collision: false,
|
||||
scope: constructor.scope
|
||||
};
|
||||
|
||||
for (let prop of props) {
|
||||
for (const prop of props) {
|
||||
prop.traverse(referenceVisitor, collisionState);
|
||||
if (collisionState.collision) break;
|
||||
}
|
||||
|
||||
if (collisionState.collision) {
|
||||
let initialisePropsRef = path.scope.generateUidIdentifier("initialiseProps");
|
||||
const initialisePropsRef = path.scope.generateUidIdentifier("initialiseProps");
|
||||
|
||||
nodes.push(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(
|
||||
@@ -137,9 +137,9 @@ export default function ({ types: t }) {
|
||||
//
|
||||
|
||||
if (isDerived) {
|
||||
let bareSupers = [];
|
||||
const bareSupers = [];
|
||||
constructor.traverse(findBareSupers, bareSupers);
|
||||
for (let bareSuper of bareSupers) {
|
||||
for (const bareSuper of bareSupers) {
|
||||
bareSuper.insertAfter(instanceBody);
|
||||
}
|
||||
} else {
|
||||
@@ -147,7 +147,7 @@ export default function ({ types: t }) {
|
||||
}
|
||||
}
|
||||
|
||||
for (let prop of props) {
|
||||
for (const prop of props) {
|
||||
prop.remove();
|
||||
}
|
||||
|
||||
@@ -169,11 +169,11 @@ export default function ({ types: t }) {
|
||||
path.insertAfter(nodes);
|
||||
},
|
||||
ArrowFunctionExpression(path) {
|
||||
let classExp = path.get("body");
|
||||
const classExp = path.get("body");
|
||||
if (!classExp.isClassExpression()) return;
|
||||
|
||||
let body = classExp.get("body");
|
||||
let members = body.get("body");
|
||||
const body = classExp.get("body");
|
||||
const members = body.get("body");
|
||||
if (members.some((member) => member.isClassProperty())) {
|
||||
path.ensureBlock();
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import template from "babel-template";
|
||||
import explodeClass from "babel-helper-explode-class";
|
||||
|
||||
let buildClassDecorator = template(`
|
||||
const buildClassDecorator = template(`
|
||||
CLASS_REF = DECORATOR(CLASS_REF) || CLASS_REF;
|
||||
`);
|
||||
|
||||
@@ -11,7 +11,7 @@ export default function ({ types: t }) {
|
||||
}
|
||||
|
||||
function transformClass(path, ref, state) {
|
||||
let nodes = [];
|
||||
const nodes = [];
|
||||
|
||||
state;
|
||||
|
||||
@@ -20,7 +20,7 @@ export default function ({ types: t }) {
|
||||
path.node.decorators = null;
|
||||
classDecorators = cleanDecorators(classDecorators);
|
||||
|
||||
for (let decorator of classDecorators) {
|
||||
for (const decorator of classDecorators) {
|
||||
nodes.push(buildClassDecorator({
|
||||
CLASS_REF: ref,
|
||||
DECORATOR: decorator
|
||||
@@ -28,21 +28,21 @@ export default function ({ types: t }) {
|
||||
}
|
||||
}
|
||||
|
||||
let map = Object.create(null);
|
||||
const map = Object.create(null);
|
||||
|
||||
for (let method of path.get("body.body")) {
|
||||
let decorators = method.node.decorators;
|
||||
for (const method of path.get("body.body")) {
|
||||
const decorators = method.node.decorators;
|
||||
if (!decorators) continue;
|
||||
|
||||
let alias = t.toKeyAlias(method.node);
|
||||
const alias = t.toKeyAlias(method.node);
|
||||
map[alias] = map[alias] || [];
|
||||
map[alias].push(method.node);
|
||||
|
||||
method.remove();
|
||||
}
|
||||
|
||||
for (let alias in map) {
|
||||
let items = map[alias];
|
||||
for (const alias in map) {
|
||||
const items = map[alias];
|
||||
|
||||
items;
|
||||
}
|
||||
@@ -54,13 +54,13 @@ export default function ({ types: t }) {
|
||||
if (path.isClass()) {
|
||||
if (path.node.decorators) return true;
|
||||
|
||||
for (let method of (path.node.body.body: Array<Object>)) {
|
||||
for (const method of (path.node.body.body: Array<Object>)) {
|
||||
if (method.decorators) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else if (path.isObjectExpression()) {
|
||||
for (let prop of (path.node.properties: Array<Object>)) {
|
||||
for (const prop of (path.node.properties: Array<Object>)) {
|
||||
if (prop.decorators) {
|
||||
return true;
|
||||
}
|
||||
@@ -97,7 +97,7 @@ The repo url is: https://github.com/loganfsmyth/babel-plugin-transform-decorator
|
||||
|
||||
explodeClass(path);
|
||||
|
||||
let ref = path.scope.generateDeclaredUidIdentifier("ref");
|
||||
const ref = path.scope.generateDeclaredUidIdentifier("ref");
|
||||
let nodes = [];
|
||||
|
||||
nodes.push(t.assignmentExpression("=", ref, path.node));
|
||||
@@ -114,7 +114,7 @@ The repo url is: https://github.com/loganfsmyth/babel-plugin-transform-decorator
|
||||
doError(path);
|
||||
explodeClass(path);
|
||||
|
||||
let ref = path.node.id;
|
||||
const ref = path.node.id;
|
||||
let nodes = [];
|
||||
|
||||
nodes = nodes.concat(transformClass(path, ref, this).map((expr) => t.expressionStatement(expr)));
|
||||
|
||||
@@ -4,7 +4,7 @@ export default function () {
|
||||
|
||||
visitor: {
|
||||
DoExpression(path) {
|
||||
let body = path.node.body.body;
|
||||
const body = path.node.body.body;
|
||||
if (body.length) {
|
||||
path.replaceWithMultiple(body);
|
||||
} else {
|
||||
|
||||
@@ -3,13 +3,13 @@ export default function ({ types: t }) {
|
||||
visitor: {
|
||||
ArrowFunctionExpression(path, state) {
|
||||
if (state.opts.spec) {
|
||||
let { node } = path;
|
||||
const { node } = path;
|
||||
if (node.shadow) return;
|
||||
|
||||
node.shadow = { this: false };
|
||||
node.type = "FunctionExpression";
|
||||
|
||||
let boundThis = t.thisExpression();
|
||||
const boundThis = t.thisExpression();
|
||||
boundThis._forceShadow = path;
|
||||
|
||||
// make sure that arrow function won't be instantiated
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
export default function ({ types: t }) {
|
||||
function statementList(key, path) {
|
||||
let paths: Array = path.get(key);
|
||||
const paths: Array = path.get(key);
|
||||
|
||||
for (let path of paths) {
|
||||
let func = path.node;
|
||||
for (const path of paths) {
|
||||
const func = path.node;
|
||||
if (!path.isFunctionDeclaration()) continue;
|
||||
|
||||
let declar = t.variableDeclaration("let", [
|
||||
const declar = t.variableDeclaration("let", [
|
||||
t.variableDeclarator(func.id, t.toExpression(func))
|
||||
]);
|
||||
|
||||
@@ -23,7 +23,7 @@ export default function ({ types: t }) {
|
||||
return {
|
||||
visitor: {
|
||||
BlockStatement(path) {
|
||||
let { node, parent } = path;
|
||||
const { node, parent } = path;
|
||||
if (t.isFunction(parent, { body: node }) || t.isExportDeclaration(parent)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -14,17 +14,17 @@ export default function () {
|
||||
return {
|
||||
visitor: {
|
||||
VariableDeclaration(path, file) {
|
||||
let { node, parent, scope } = path;
|
||||
const { node, parent, scope } = path;
|
||||
if (!isBlockScoped(node)) return;
|
||||
convertBlockScopedToVar(path, null, parent, scope, true);
|
||||
|
||||
if (node._tdzThis) {
|
||||
let nodes = [node];
|
||||
const nodes = [node];
|
||||
|
||||
for (let i = 0; i < node.declarations.length; i++) {
|
||||
let decl = node.declarations[i];
|
||||
const decl = node.declarations[i];
|
||||
if (decl.init) {
|
||||
let assign = t.assignmentExpression("=", decl.id, decl.init);
|
||||
const assign = t.assignmentExpression("=", decl.id, decl.init);
|
||||
assign._ignoreBlockScopingTDZ = true;
|
||||
nodes.push(t.expressionStatement(assign));
|
||||
}
|
||||
@@ -44,22 +44,22 @@ export default function () {
|
||||
},
|
||||
|
||||
Loop(path, file) {
|
||||
let { node, parent, scope } = path;
|
||||
const { node, parent, scope } = path;
|
||||
t.ensureBlock(node);
|
||||
let blockScoping = new BlockScoping(path, path.get("body"), parent, scope, file);
|
||||
let replace = blockScoping.run();
|
||||
const blockScoping = new BlockScoping(path, path.get("body"), parent, scope, file);
|
||||
const replace = blockScoping.run();
|
||||
if (replace) path.replaceWith(replace);
|
||||
},
|
||||
|
||||
CatchClause(path, file) {
|
||||
let { parent, scope } = path;
|
||||
let blockScoping = new BlockScoping(null, path.get("body"), parent, scope, file);
|
||||
const { parent, scope } = path;
|
||||
const blockScoping = new BlockScoping(null, path.get("body"), parent, scope, file);
|
||||
blockScoping.run();
|
||||
},
|
||||
|
||||
"BlockStatement|SwitchStatement|Program"(path, file) {
|
||||
if (!ignoreBlock(path)) {
|
||||
let blockScoping = new BlockScoping(null, path, path.parent, path.scope, file);
|
||||
const blockScoping = new BlockScoping(null, path, path.parent, path.scope, file);
|
||||
blockScoping.run();
|
||||
}
|
||||
}
|
||||
@@ -71,7 +71,7 @@ function ignoreBlock(path) {
|
||||
return t.isLoop(path.parent) || t.isCatchClause(path.parent);
|
||||
}
|
||||
|
||||
let buildRetCheck = template(`
|
||||
const buildRetCheck = template(`
|
||||
if (typeof RETURN === "object") return RETURN.v;
|
||||
`);
|
||||
|
||||
@@ -89,7 +89,7 @@ function convertBlockScopedToVar(path, node, parent, scope, moveBindingsToParent
|
||||
// https://github.com/babel/babel/issues/255
|
||||
if (!t.isFor(parent)) {
|
||||
for (let i = 0; i < node.declarations.length; i++) {
|
||||
let declar = node.declarations[i];
|
||||
const declar = node.declarations[i];
|
||||
declar.init = declar.init || scope.buildUndefinedNode();
|
||||
}
|
||||
}
|
||||
@@ -101,8 +101,8 @@ function convertBlockScopedToVar(path, node, parent, scope, moveBindingsToParent
|
||||
if (moveBindingsToParent) {
|
||||
const parentScope = scope.getFunctionParent();
|
||||
const ids = path.getBindingIdentifiers();
|
||||
for (let name in ids) {
|
||||
let binding = scope.getOwnBinding(name);
|
||||
for (const name in ids) {
|
||||
const binding = scope.getOwnBinding(name);
|
||||
if (binding) binding.kind = "var";
|
||||
scope.moveBindingTo(name, parentScope);
|
||||
}
|
||||
@@ -113,36 +113,36 @@ function isVar(node) {
|
||||
return t.isVariableDeclaration(node, { kind: "var" }) && !isBlockScoped(node);
|
||||
}
|
||||
|
||||
let letReferenceBlockVisitor = traverse.visitors.merge([{
|
||||
const letReferenceBlockVisitor = traverse.visitors.merge([{
|
||||
Function(path, state) {
|
||||
path.traverse(letReferenceFunctionVisitor, state);
|
||||
return path.skip();
|
||||
}
|
||||
}, tdzVisitor]);
|
||||
|
||||
let letReferenceFunctionVisitor = traverse.visitors.merge([{
|
||||
const letReferenceFunctionVisitor = traverse.visitors.merge([{
|
||||
ReferencedIdentifier(path, state) {
|
||||
let ref = state.letReferences[path.node.name];
|
||||
const ref = state.letReferences[path.node.name];
|
||||
|
||||
// not a part of our scope
|
||||
if (!ref) return;
|
||||
|
||||
// this scope has a variable with the same name so it couldn't belong
|
||||
// to our let scope
|
||||
let localBinding = path.scope.getBindingIdentifier(path.node.name);
|
||||
const localBinding = path.scope.getBindingIdentifier(path.node.name);
|
||||
if (localBinding && localBinding !== ref) return;
|
||||
|
||||
state.closurify = true;
|
||||
}
|
||||
}, tdzVisitor]);
|
||||
|
||||
let hoistVarDeclarationsVisitor = {
|
||||
const hoistVarDeclarationsVisitor = {
|
||||
enter(path, self) {
|
||||
let { node, parent } = path;
|
||||
const { node, parent } = path;
|
||||
|
||||
if (path.isForStatement()) {
|
||||
if (isVar(node.init, node)) {
|
||||
let nodes = self.pushDeclar(node.init);
|
||||
const nodes = self.pushDeclar(node.init);
|
||||
if (nodes.length === 1) {
|
||||
node.init = nodes[0];
|
||||
} else {
|
||||
@@ -162,17 +162,17 @@ let hoistVarDeclarationsVisitor = {
|
||||
}
|
||||
};
|
||||
|
||||
let loopLabelVisitor = {
|
||||
const loopLabelVisitor = {
|
||||
LabeledStatement({ node }, state) {
|
||||
state.innerLabels.push(node.label.name);
|
||||
}
|
||||
};
|
||||
|
||||
let continuationVisitor = {
|
||||
const continuationVisitor = {
|
||||
enter(path, state) {
|
||||
if (path.isAssignmentExpression() || path.isUpdateExpression()) {
|
||||
let bindings = path.getBindingIdentifiers();
|
||||
for (let name in bindings) {
|
||||
const bindings = path.getBindingIdentifiers();
|
||||
for (const name in bindings) {
|
||||
if (state.outsideReferences[name] !== path.scope.getBindingIdentifier(name)) continue;
|
||||
state.reassignments[name] = true;
|
||||
}
|
||||
@@ -188,9 +188,9 @@ function loopNodeTo(node) {
|
||||
}
|
||||
}
|
||||
|
||||
let loopVisitor = {
|
||||
const loopVisitor = {
|
||||
Loop(path, state) {
|
||||
let oldIgnoreLabeless = state.ignoreLabeless;
|
||||
const oldIgnoreLabeless = state.ignoreLabeless;
|
||||
state.ignoreLabeless = true;
|
||||
path.traverse(loopVisitor, state);
|
||||
state.ignoreLabeless = oldIgnoreLabeless;
|
||||
@@ -202,7 +202,7 @@ let loopVisitor = {
|
||||
},
|
||||
|
||||
SwitchCase(path, state) {
|
||||
let oldInSwitchCase = state.inSwitchCase;
|
||||
const oldInSwitchCase = state.inSwitchCase;
|
||||
state.inSwitchCase = true;
|
||||
path.traverse(loopVisitor, state);
|
||||
state.inSwitchCase = oldInSwitchCase;
|
||||
@@ -210,7 +210,7 @@ let loopVisitor = {
|
||||
},
|
||||
|
||||
"BreakStatement|ContinueStatement|ReturnStatement"(path, state) {
|
||||
let { node, parent, scope } = path;
|
||||
const { node, parent, scope } = path;
|
||||
if (node[this.LOOP_IGNORE]) return;
|
||||
|
||||
let replace;
|
||||
@@ -284,11 +284,11 @@ class BlockScoping {
|
||||
*/
|
||||
|
||||
run() {
|
||||
let block = this.block;
|
||||
const block = this.block;
|
||||
if (block._letDone) return;
|
||||
block._letDone = true;
|
||||
|
||||
let needsClosure = this.getLetReferences();
|
||||
const needsClosure = this.getLetReferences();
|
||||
|
||||
// this is a block within a `Function/Program` so we can safely leave it be
|
||||
if (t.isFunction(this.parent) || t.isProgram(this.block)) {
|
||||
@@ -313,12 +313,12 @@ class BlockScoping {
|
||||
}
|
||||
|
||||
updateScopeInfo(wrappedInClosure) {
|
||||
let scope = this.scope;
|
||||
let parentScope = scope.getFunctionParent();
|
||||
let letRefs = this.letReferences;
|
||||
const scope = this.scope;
|
||||
const parentScope = scope.getFunctionParent();
|
||||
const letRefs = this.letReferences;
|
||||
|
||||
for (let key in letRefs) {
|
||||
let ref = letRefs[key];
|
||||
for (const key in letRefs) {
|
||||
const ref = letRefs[key];
|
||||
const binding = scope.getBinding(ref.name);
|
||||
if (!binding) continue;
|
||||
if (binding.kind === "let" || binding.kind === "const") {
|
||||
@@ -334,18 +334,18 @@ class BlockScoping {
|
||||
}
|
||||
|
||||
remap() {
|
||||
let letRefs = this.letReferences;
|
||||
let scope = this.scope;
|
||||
const letRefs = this.letReferences;
|
||||
const scope = this.scope;
|
||||
|
||||
// alright, so since we aren't wrapping this block in a closure
|
||||
// we have to check if any of our let variables collide with
|
||||
// those in upper scopes and then if they do, generate a uid
|
||||
// for them and replace all references with it
|
||||
|
||||
for (let key in letRefs) {
|
||||
for (const key in letRefs) {
|
||||
// just an Identifier node we collected in `getLetReferences`
|
||||
// this is the defining identifier of a declaration
|
||||
let ref = letRefs[key];
|
||||
const ref = letRefs[key];
|
||||
|
||||
// todo: could skip this if the colliding binding is in another function
|
||||
if (scope.parentHasBinding(key) || scope.hasGlobal(key)) {
|
||||
@@ -362,14 +362,14 @@ class BlockScoping {
|
||||
}
|
||||
|
||||
wrapClosure() {
|
||||
let block = this.block;
|
||||
const block = this.block;
|
||||
|
||||
let outsideRefs = this.outsideLetReferences;
|
||||
const outsideRefs = this.outsideLetReferences;
|
||||
|
||||
// remap loop heads with colliding variables
|
||||
if (this.loop) {
|
||||
for (let name in outsideRefs) {
|
||||
let id = outsideRefs[name];
|
||||
for (const name in outsideRefs) {
|
||||
const id = outsideRefs[name];
|
||||
|
||||
if (this.scope.hasGlobal(id.name) || this.scope.parentHasBinding(id.name)) {
|
||||
delete outsideRefs[id.name];
|
||||
@@ -391,13 +391,13 @@ class BlockScoping {
|
||||
this.hoistVarDeclarations();
|
||||
|
||||
// turn outsideLetReferences into an array
|
||||
let params = values(outsideRefs);
|
||||
let args = values(outsideRefs);
|
||||
const params = values(outsideRefs);
|
||||
const args = values(outsideRefs);
|
||||
|
||||
const isSwitch = this.blockPath.isSwitchStatement();
|
||||
|
||||
// build the closure that we're going to wrap the block with, possible wrapping switch(){}
|
||||
let fn = t.functionExpression(null, params, t.blockStatement(isSwitch ? [block] : block.body));
|
||||
const fn = t.functionExpression(null, params, t.blockStatement(isSwitch ? [block] : block.body));
|
||||
fn.shadow = true;
|
||||
|
||||
// continuation
|
||||
@@ -414,17 +414,17 @@ class BlockScoping {
|
||||
|
||||
// build a call and a unique id that we can assign the return value to
|
||||
let call = t.callExpression(ref, args);
|
||||
let ret = this.scope.generateUidIdentifier("ret");
|
||||
const ret = this.scope.generateUidIdentifier("ret");
|
||||
|
||||
// handle generators
|
||||
let hasYield = traverse.hasType(fn.body, this.scope, "YieldExpression", t.FUNCTION_TYPES);
|
||||
const hasYield = traverse.hasType(fn.body, this.scope, "YieldExpression", t.FUNCTION_TYPES);
|
||||
if (hasYield) {
|
||||
fn.generator = true;
|
||||
call = t.yieldExpression(call, true);
|
||||
}
|
||||
|
||||
// handlers async functions
|
||||
let hasAsync = traverse.hasType(fn.body, this.scope, "AwaitExpression", t.FUNCTION_TYPES);
|
||||
const hasAsync = traverse.hasType(fn.body, this.scope, "AwaitExpression", t.FUNCTION_TYPES);
|
||||
if (hasAsync) {
|
||||
fn.async = true;
|
||||
call = t.awaitExpression(call);
|
||||
@@ -442,7 +442,7 @@ class BlockScoping {
|
||||
*/
|
||||
|
||||
buildClosure(ret: { type: "Identifier" }, call: { type: "CallExpression" }) {
|
||||
let has = this.has;
|
||||
const has = this.has;
|
||||
if (has.hasReturn || has.hasBreakContinue) {
|
||||
this.buildHas(ret, call);
|
||||
} else {
|
||||
@@ -459,7 +459,7 @@ class BlockScoping {
|
||||
*/
|
||||
|
||||
addContinuations(fn) {
|
||||
let state = {
|
||||
const state = {
|
||||
reassignments: {},
|
||||
outsideReferences: this.outsideLetReferences
|
||||
};
|
||||
@@ -467,10 +467,10 @@ class BlockScoping {
|
||||
this.scope.traverse(fn, continuationVisitor, state);
|
||||
|
||||
for (let i = 0; i < fn.params.length; i++) {
|
||||
let param = fn.params[i];
|
||||
const param = fn.params[i];
|
||||
if (!state.reassignments[param.name]) continue;
|
||||
|
||||
let newParam = this.scope.generateUidIdentifier(param.name);
|
||||
const newParam = this.scope.generateUidIdentifier(param.name);
|
||||
fn.params[i] = newParam;
|
||||
|
||||
this.scope.rename(param.name, newParam.name, fn);
|
||||
@@ -481,12 +481,12 @@ class BlockScoping {
|
||||
}
|
||||
|
||||
getLetReferences() {
|
||||
let block = this.block;
|
||||
const block = this.block;
|
||||
|
||||
let declarators = [];
|
||||
|
||||
if (this.loop) {
|
||||
let init = this.loop.left || this.loop.init;
|
||||
const init = this.loop.left || this.loop.init;
|
||||
if (isBlockScoped(init)) {
|
||||
declarators.push(init);
|
||||
extend(this.outsideLetReferences, t.getBindingIdentifiers(init));
|
||||
@@ -509,18 +509,18 @@ class BlockScoping {
|
||||
//
|
||||
if (block.body) {
|
||||
for (let i = 0; i < block.body.length; i++) {
|
||||
let declarPath = this.blockPath.get("body")[i];
|
||||
const declarPath = this.blockPath.get("body")[i];
|
||||
addDeclarationsFromChild(declarPath);
|
||||
}
|
||||
}
|
||||
|
||||
if (block.cases) {
|
||||
for (let i = 0; i < block.cases.length; i++) {
|
||||
let consequents = block.cases[i].consequent;
|
||||
const consequents = block.cases[i].consequent;
|
||||
|
||||
for (let j = 0; j < consequents.length; j++) {
|
||||
let declarPath = this.blockPath.get("cases")[i];
|
||||
let declar = consequents[j];
|
||||
const declarPath = this.blockPath.get("cases")[i];
|
||||
const declar = consequents[j];
|
||||
addDeclarationsFromChild(declarPath, declar);
|
||||
}
|
||||
}
|
||||
@@ -528,12 +528,12 @@ class BlockScoping {
|
||||
|
||||
//
|
||||
for (let i = 0; i < declarators.length; i++) {
|
||||
let declar = declarators[i];
|
||||
const declar = declarators[i];
|
||||
// Passing true as the third argument causes t.getBindingIdentifiers
|
||||
// to return only the *outer* binding identifiers of this
|
||||
// declaration, rather than (for example) mistakenly including the
|
||||
// parameters of a function declaration. Fixes #4880.
|
||||
let keys = t.getBindingIdentifiers(declar, false, true);
|
||||
const keys = t.getBindingIdentifiers(declar, false, true);
|
||||
extend(this.letReferences, keys);
|
||||
this.hasLetReferences = true;
|
||||
}
|
||||
@@ -541,7 +541,7 @@ class BlockScoping {
|
||||
// no let references so we can just quit
|
||||
if (!this.hasLetReferences) return;
|
||||
|
||||
let state = {
|
||||
const state = {
|
||||
letReferences: this.letReferences,
|
||||
closurify: false,
|
||||
file: this.file
|
||||
@@ -562,7 +562,7 @@ class BlockScoping {
|
||||
*/
|
||||
|
||||
checkLoop(): Object {
|
||||
let state = {
|
||||
const state = {
|
||||
hasBreakContinue: false,
|
||||
ignoreLabeless: false,
|
||||
inSwitchCase: false,
|
||||
@@ -594,21 +594,21 @@ class BlockScoping {
|
||||
*/
|
||||
|
||||
pushDeclar(node: { type: "VariableDeclaration" }): Array<Object> {
|
||||
let declars = [];
|
||||
let names = t.getBindingIdentifiers(node);
|
||||
for (let name in names) {
|
||||
const declars = [];
|
||||
const names = t.getBindingIdentifiers(node);
|
||||
for (const name in names) {
|
||||
declars.push(t.variableDeclarator(names[name]));
|
||||
}
|
||||
|
||||
this.body.push(t.variableDeclaration(node.kind, declars));
|
||||
|
||||
let replace = [];
|
||||
const replace = [];
|
||||
|
||||
for (let i = 0; i < node.declarations.length; i++) {
|
||||
let declar = node.declarations[i];
|
||||
const declar = node.declarations[i];
|
||||
if (!declar.init) continue;
|
||||
|
||||
let expr = t.assignmentExpression("=", declar.id, declar.init);
|
||||
const expr = t.assignmentExpression("=", declar.id, declar.init);
|
||||
replace.push(t.inherits(expr, declar));
|
||||
}
|
||||
|
||||
@@ -616,15 +616,15 @@ class BlockScoping {
|
||||
}
|
||||
|
||||
buildHas(ret: { type: "Identifier" }, call: { type: "CallExpression" }) {
|
||||
let body = this.body;
|
||||
const body = this.body;
|
||||
|
||||
body.push(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(ret, call)
|
||||
]));
|
||||
|
||||
let retCheck;
|
||||
let has = this.has;
|
||||
let cases = [];
|
||||
const has = this.has;
|
||||
const cases = [];
|
||||
|
||||
if (has.hasReturn) {
|
||||
// typeof ret === "object"
|
||||
@@ -634,7 +634,7 @@ class BlockScoping {
|
||||
}
|
||||
|
||||
if (has.hasBreakContinue) {
|
||||
for (let key in has.map) {
|
||||
for (const key in has.map) {
|
||||
cases.push(t.switchCase(t.stringLiteral(key), [has.map[key]]));
|
||||
}
|
||||
|
||||
@@ -643,7 +643,7 @@ class BlockScoping {
|
||||
}
|
||||
|
||||
if (cases.length === 1) {
|
||||
let single = cases[0];
|
||||
const single = cases[0];
|
||||
body.push(t.ifStatement(
|
||||
t.binaryExpression("===", ret, single.test),
|
||||
single.consequent[0]
|
||||
@@ -652,7 +652,7 @@ class BlockScoping {
|
||||
if (this.loop) {
|
||||
// https://github.com/babel/babel/issues/998
|
||||
for (let i = 0; i < cases.length; i++) {
|
||||
let caseConsequent = cases[i].consequent[0];
|
||||
const caseConsequent = cases[i].consequent[0];
|
||||
if (t.isBreakStatement(caseConsequent) && !caseConsequent.label) {
|
||||
caseConsequent.label = this.loopLabel = this.loopLabel || this.scope.generateUidIdentifier("loop");
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import * as t from "babel-types";
|
||||
|
||||
function getTDZStatus(refPath, bindingPath) {
|
||||
let executionStatus = bindingPath._guessExecutionStatusRelativeTo(refPath);
|
||||
const executionStatus = bindingPath._guessExecutionStatusRelativeTo(refPath);
|
||||
|
||||
if (executionStatus === "before") {
|
||||
return "inside";
|
||||
@@ -20,29 +20,29 @@ function buildTDZAssert(node, file) {
|
||||
}
|
||||
|
||||
function isReference(node, scope, state) {
|
||||
let declared = state.letReferences[node.name];
|
||||
const declared = state.letReferences[node.name];
|
||||
if (!declared) return false;
|
||||
|
||||
// declared node is different in this scope
|
||||
return scope.getBindingIdentifier(node.name) === declared;
|
||||
}
|
||||
|
||||
export let visitor = {
|
||||
export const visitor = {
|
||||
ReferencedIdentifier(path, state) {
|
||||
if (!this.file.opts.tdz) return;
|
||||
|
||||
let { node, parent, scope } = path;
|
||||
const { node, parent, scope } = path;
|
||||
|
||||
if (path.parentPath.isFor({ left: node })) return;
|
||||
if (!isReference(node, scope, state)) return;
|
||||
|
||||
let bindingPath = scope.getBinding(node.name).path;
|
||||
const bindingPath = scope.getBinding(node.name).path;
|
||||
|
||||
let status = getTDZStatus(path, bindingPath);
|
||||
const status = getTDZStatus(path, bindingPath);
|
||||
if (status === "inside") return;
|
||||
|
||||
if (status === "maybe") {
|
||||
let assert = buildTDZAssert(node, state.file);
|
||||
const assert = buildTDZAssert(node, state.file);
|
||||
|
||||
// add tdzThis to parent variable declarator so it's exploded
|
||||
bindingPath.parent._tdzThis = true;
|
||||
@@ -69,14 +69,14 @@ export let visitor = {
|
||||
exit(path, state) {
|
||||
if (!this.file.opts.tdz) return;
|
||||
|
||||
let { node } = path;
|
||||
const { node } = path;
|
||||
if (node._ignoreBlockScopingTDZ) return;
|
||||
|
||||
let nodes = [];
|
||||
let ids = path.getBindingIdentifiers();
|
||||
const nodes = [];
|
||||
const ids = path.getBindingIdentifiers();
|
||||
|
||||
for (let name in ids) {
|
||||
let id = ids[name];
|
||||
for (const name in ids) {
|
||||
const id = ids[name];
|
||||
|
||||
if (isReference(id, path.scope, state)) {
|
||||
nodes.push(buildTDZAssert(id, state.file));
|
||||
|
||||
@@ -4,15 +4,15 @@ import nameFunction from "babel-helper-function-name";
|
||||
|
||||
export default function ({ types: t }) {
|
||||
// todo: investigate traversal requeueing
|
||||
let VISITED = Symbol();
|
||||
const VISITED = Symbol();
|
||||
|
||||
return {
|
||||
visitor: {
|
||||
ExportDefaultDeclaration(path) {
|
||||
if (!path.get("declaration").isClassDeclaration()) return;
|
||||
|
||||
let { node } = path;
|
||||
let ref = node.declaration.id || path.scope.generateUidIdentifier("class");
|
||||
const { node } = path;
|
||||
const ref = node.declaration.id || path.scope.generateUidIdentifier("class");
|
||||
node.declaration.id = ref;
|
||||
|
||||
// Split the class declaration and the export into two separate statements.
|
||||
@@ -21,9 +21,9 @@ export default function ({ types: t }) {
|
||||
},
|
||||
|
||||
ClassDeclaration(path) {
|
||||
let { node } = path;
|
||||
const { node } = path;
|
||||
|
||||
let ref = node.id || path.scope.generateUidIdentifier("class");
|
||||
const ref = node.id || path.scope.generateUidIdentifier("class");
|
||||
|
||||
path.replaceWith(t.variableDeclaration("let", [
|
||||
t.variableDeclarator(ref, t.toExpression(node))
|
||||
@@ -31,10 +31,10 @@ export default function ({ types: t }) {
|
||||
},
|
||||
|
||||
ClassExpression(path, state) {
|
||||
let { node } = path;
|
||||
const { node } = path;
|
||||
if (node[VISITED]) return;
|
||||
|
||||
let inferred = nameFunction(path);
|
||||
const inferred = nameFunction(path);
|
||||
if (inferred && inferred !== node) return path.replaceWith(inferred);
|
||||
|
||||
node[VISITED] = true;
|
||||
|
||||
@@ -2,14 +2,14 @@ import type { Scope } from "babel-traverse";
|
||||
import * as t from "babel-types";
|
||||
|
||||
export default function (decorators: Array<Object>, scope: Scope): Array<Object> {
|
||||
for (let decorator of decorators) {
|
||||
let expression = decorator.expression;
|
||||
for (const decorator of decorators) {
|
||||
const expression = decorator.expression;
|
||||
if (!t.isMemberExpression(expression)) continue;
|
||||
|
||||
let temp = scope.maybeGenerateMemoised(expression.object);
|
||||
const temp = scope.maybeGenerateMemoised(expression.object);
|
||||
let ref;
|
||||
|
||||
let nodes = [];
|
||||
const nodes = [];
|
||||
|
||||
if (temp) {
|
||||
ref = temp;
|
||||
|
||||
@@ -14,11 +14,11 @@ export default class LooseClassTransformer extends VanillaTransformer {
|
||||
|
||||
let classRef = this.classRef;
|
||||
if (!node.static) classRef = t.memberExpression(classRef, t.identifier("prototype"));
|
||||
let methodName = t.memberExpression(classRef, node.key, node.computed || t.isLiteral(node.key));
|
||||
const methodName = t.memberExpression(classRef, node.key, node.computed || t.isLiteral(node.key));
|
||||
|
||||
let func = t.functionExpression(null, node.params, node.body, node.generator, node.async);
|
||||
func.returnType = node.returnType;
|
||||
let key = t.toComputedKey(node, node.key);
|
||||
const key = t.toComputedKey(node, node.key);
|
||||
if (t.isStringLiteral(key)) {
|
||||
func = nameFunction({
|
||||
node: func,
|
||||
@@ -27,7 +27,7 @@ export default class LooseClassTransformer extends VanillaTransformer {
|
||||
});
|
||||
}
|
||||
|
||||
let expr = t.expressionStatement(t.assignmentExpression("=", methodName, func));
|
||||
const expr = t.expressionStatement(t.assignmentExpression("=", methodName, func));
|
||||
t.inheritsComments(expr, node);
|
||||
this.body.push(expr);
|
||||
return true;
|
||||
|
||||
@@ -8,13 +8,13 @@ import * as defineMap from "babel-helper-define-map";
|
||||
import template from "babel-template";
|
||||
import * as t from "babel-types";
|
||||
|
||||
let buildDerivedConstructor = template(`
|
||||
const buildDerivedConstructor = template(`
|
||||
(function () {
|
||||
super(...arguments);
|
||||
})
|
||||
`);
|
||||
|
||||
let noMethodVisitor = {
|
||||
const noMethodVisitor = {
|
||||
"FunctionExpression|FunctionDeclaration"(path) {
|
||||
if (!path.is("shadow")) {
|
||||
path.skip();
|
||||
@@ -26,7 +26,7 @@ let noMethodVisitor = {
|
||||
}
|
||||
};
|
||||
|
||||
let verifyConstructorVisitor = visitors.merge([noMethodVisitor, {
|
||||
const verifyConstructorVisitor = visitors.merge([noMethodVisitor, {
|
||||
Super(path) {
|
||||
if (this.isDerived && !this.hasBareSuper && !path.parentPath.isCallExpression({ callee: path.node })) {
|
||||
throw path.buildCodeFrameError("'super.*' is not allowed before super()");
|
||||
@@ -54,7 +54,7 @@ let verifyConstructorVisitor = visitors.merge([noMethodVisitor, {
|
||||
}
|
||||
}]);
|
||||
|
||||
let findThisesVisitor = visitors.merge([noMethodVisitor, {
|
||||
const findThisesVisitor = visitors.merge([noMethodVisitor, {
|
||||
ThisExpression(path) {
|
||||
this.superThises.push(path);
|
||||
}
|
||||
@@ -96,18 +96,18 @@ export default class ClassTransformer {
|
||||
|
||||
run() {
|
||||
let superName = this.superName;
|
||||
let file = this.file;
|
||||
const file = this.file;
|
||||
let body = this.body;
|
||||
|
||||
//
|
||||
|
||||
let constructorBody = this.constructorBody = t.blockStatement([]);
|
||||
const constructorBody = this.constructorBody = t.blockStatement([]);
|
||||
this.constructor = this.buildConstructor();
|
||||
|
||||
//
|
||||
|
||||
let closureParams = [];
|
||||
let closureArgs = [];
|
||||
const closureParams = [];
|
||||
const closureArgs = [];
|
||||
|
||||
//
|
||||
if (this.isDerived) {
|
||||
@@ -138,13 +138,13 @@ export default class ClassTransformer {
|
||||
//
|
||||
body.push(t.returnStatement(this.classRef));
|
||||
|
||||
let container = t.functionExpression(null, closureParams, t.blockStatement(body));
|
||||
const container = t.functionExpression(null, closureParams, t.blockStatement(body));
|
||||
container.shadow = true;
|
||||
return t.callExpression(container, closureArgs);
|
||||
}
|
||||
|
||||
buildConstructor() {
|
||||
let func = t.functionDeclaration(this.classRef, [], this.constructorBody);
|
||||
const func = t.functionDeclaration(this.classRef, [], this.constructorBody);
|
||||
t.inherits(func, this.node);
|
||||
return func;
|
||||
}
|
||||
@@ -159,7 +159,7 @@ export default class ClassTransformer {
|
||||
mutatorMap = this.instanceMutatorMap;
|
||||
}
|
||||
|
||||
let map = defineMap.push(mutatorMap, node, kind, this.file, scope);
|
||||
const map = defineMap.push(mutatorMap, node, kind, this.file, scope);
|
||||
|
||||
if (enumerable) {
|
||||
map.enumerable = t.booleanLiteral(true);
|
||||
@@ -175,8 +175,8 @@ export default class ClassTransformer {
|
||||
|
||||
constructorMeMaybe() {
|
||||
let hasConstructor = false;
|
||||
let paths = this.path.get("body.body");
|
||||
for (let path of (paths: Array)) {
|
||||
const paths = this.path.get("body.body");
|
||||
for (const path of (paths: Array)) {
|
||||
hasConstructor = path.equals("kind", "constructor");
|
||||
if (hasConstructor) break;
|
||||
}
|
||||
@@ -185,7 +185,7 @@ export default class ClassTransformer {
|
||||
let params, body;
|
||||
|
||||
if (this.isDerived) {
|
||||
let constructor = buildDerivedConstructor().expression;
|
||||
const constructor = buildDerivedConstructor().expression;
|
||||
params = constructor.params;
|
||||
body = constructor.body;
|
||||
} else {
|
||||
@@ -207,7 +207,7 @@ export default class ClassTransformer {
|
||||
this.verifyConstructor();
|
||||
|
||||
if (this.userConstructor) {
|
||||
let constructorBody = this.constructorBody;
|
||||
const constructorBody = this.constructorBody;
|
||||
constructorBody.body = constructorBody.body.concat(this.userConstructor.body.body);
|
||||
t.inherits(this.constructor, this.userConstructor);
|
||||
t.inherits(constructorBody, this.userConstructor.body);
|
||||
@@ -217,10 +217,10 @@ export default class ClassTransformer {
|
||||
}
|
||||
|
||||
pushBody() {
|
||||
let classBodyPaths: Array<Object> = this.path.get("body.body");
|
||||
const classBodyPaths: Array<Object> = this.path.get("body.body");
|
||||
|
||||
for (let path of classBodyPaths) {
|
||||
let node = path.node;
|
||||
for (const path of classBodyPaths) {
|
||||
const node = path.node;
|
||||
|
||||
if (path.isClassProperty()) {
|
||||
throw path.buildCodeFrameError("Missing class properties transform.");
|
||||
@@ -231,7 +231,7 @@ export default class ClassTransformer {
|
||||
}
|
||||
|
||||
if (t.isClassMethod(node)) {
|
||||
let isConstructor = node.kind === "constructor";
|
||||
const isConstructor = node.kind === "constructor";
|
||||
|
||||
if (isConstructor) {
|
||||
path.traverse(verifyConstructorVisitor, this);
|
||||
@@ -241,7 +241,7 @@ export default class ClassTransformer {
|
||||
}
|
||||
}
|
||||
|
||||
let replaceSupers = new ReplaceSupers({
|
||||
const replaceSupers = new ReplaceSupers({
|
||||
forceSuperMemoisation: isConstructor,
|
||||
methodPath: path,
|
||||
methodNode: node,
|
||||
@@ -275,7 +275,7 @@ export default class ClassTransformer {
|
||||
pushDescriptors() {
|
||||
this.pushInherits();
|
||||
|
||||
let body = this.body;
|
||||
const body = this.body;
|
||||
|
||||
let instanceProps;
|
||||
let staticProps;
|
||||
@@ -292,7 +292,7 @@ export default class ClassTransformer {
|
||||
if (instanceProps) instanceProps = defineMap.toComputedObjectFromClass(instanceProps);
|
||||
if (staticProps) staticProps = defineMap.toComputedObjectFromClass(staticProps);
|
||||
|
||||
let nullNode = t.nullLiteral();
|
||||
const nullNode = t.nullLiteral();
|
||||
|
||||
// (Constructor, instanceDescriptors, staticDescriptors, instanceInitializers, staticInitializers)
|
||||
let args = [this.classRef, nullNode, nullNode, nullNode, nullNode];
|
||||
@@ -363,7 +363,7 @@ export default class ClassTransformer {
|
||||
[t.thisExpression(), bareSuperNode]
|
||||
);
|
||||
|
||||
let bareSuperAfter = this.bareSuperAfter.map((fn) => fn(thisRef));
|
||||
const bareSuperAfter = this.bareSuperAfter.map((fn) => fn(thisRef));
|
||||
|
||||
if (bareSuper.parentPath.isExpressionStatement() && bareSuper.parentPath.container === body.node.body && body.node.body.length - 1 === bareSuper.parentPath.key) {
|
||||
// this super call is the last statement in the body so we can just straight up
|
||||
@@ -394,17 +394,17 @@ export default class ClassTransformer {
|
||||
verifyConstructor() {
|
||||
if (!this.isDerived) return;
|
||||
|
||||
let path = this.userConstructorPath;
|
||||
let body = path.get("body");
|
||||
const path = this.userConstructorPath;
|
||||
const body = path.get("body");
|
||||
|
||||
path.traverse(findThisesVisitor, this);
|
||||
|
||||
let guaranteedSuperBeforeFinish = !!this.bareSupers.length;
|
||||
|
||||
let superRef = this.superName || t.identifier("Function");
|
||||
let thisRef = path.scope.generateUidIdentifier("this");
|
||||
const superRef = this.superName || t.identifier("Function");
|
||||
const thisRef = path.scope.generateUidIdentifier("this");
|
||||
|
||||
for (let bareSuper of this.bareSupers) {
|
||||
for (const bareSuper of this.bareSupers) {
|
||||
this.wrapSuperCall(bareSuper, superRef, thisRef, body);
|
||||
|
||||
if (guaranteedSuperBeforeFinish) {
|
||||
@@ -422,25 +422,25 @@ export default class ClassTransformer {
|
||||
}
|
||||
}
|
||||
|
||||
for (let thisPath of this.superThises) {
|
||||
for (const thisPath of this.superThises) {
|
||||
thisPath.replaceWith(thisRef);
|
||||
}
|
||||
|
||||
let wrapReturn = (returnArg) => t.callExpression(
|
||||
const wrapReturn = (returnArg) => t.callExpression(
|
||||
this.file.addHelper("possibleConstructorReturn"),
|
||||
[thisRef].concat(returnArg || [])
|
||||
);
|
||||
|
||||
// if we have a return as the last node in the body then we've already caught that
|
||||
// return
|
||||
let bodyPaths = body.get("body");
|
||||
const bodyPaths = body.get("body");
|
||||
if (bodyPaths.length && !bodyPaths.pop().isReturnStatement()) {
|
||||
body.pushContainer("body", t.returnStatement(guaranteedSuperBeforeFinish ? thisRef : wrapReturn()));
|
||||
}
|
||||
|
||||
for (let returnPath of this.superReturns) {
|
||||
for (const returnPath of this.superReturns) {
|
||||
if (returnPath.node.argument) {
|
||||
let ref = returnPath.scope.generateDeclaredUidIdentifier("ret");
|
||||
const ref = returnPath.scope.generateDeclaredUidIdentifier("ret");
|
||||
returnPath.get("argument").replaceWithMultiple([
|
||||
t.assignmentExpression("=", ref, returnPath.node.argument),
|
||||
wrapReturn(ref)
|
||||
@@ -456,7 +456,7 @@ export default class ClassTransformer {
|
||||
*/
|
||||
|
||||
pushMethod(node: { type: "ClassMethod" }, path?: NodePath) {
|
||||
let scope = path ? path.scope : this.scope;
|
||||
const scope = path ? path.scope : this.scope;
|
||||
|
||||
if (node.kind === "method") {
|
||||
if (this._processMethod(node, scope)) return;
|
||||
@@ -482,7 +482,7 @@ export default class ClassTransformer {
|
||||
path.scope.rename(this.classRef.name);
|
||||
}
|
||||
|
||||
let construct = this.constructor;
|
||||
const construct = this.constructor;
|
||||
|
||||
this.userConstructorPath = path;
|
||||
this.userConstructor = method;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
export default function ({ types: t, template }) {
|
||||
let buildMutatorMapAssign = template(`
|
||||
const buildMutatorMapAssign = template(`
|
||||
MUTATOR_MAP_REF[KEY] = MUTATOR_MAP_REF[KEY] || {};
|
||||
MUTATOR_MAP_REF[KEY].KIND = VALUE;
|
||||
`);
|
||||
@@ -29,7 +29,7 @@ export default function ({ types: t, template }) {
|
||||
function pushMutatorDefine({ objId, body, getMutatorId, scope }, prop) {
|
||||
let key = !prop.computed && t.isIdentifier(prop.key) ? t.stringLiteral(prop.key.name) : prop.key;
|
||||
|
||||
let maybeMemoise = scope.maybeGenerateMemoised(key);
|
||||
const maybeMemoise = scope.maybeGenerateMemoised(key);
|
||||
if (maybeMemoise) {
|
||||
body.push(t.expressionStatement(t.assignmentExpression("=", maybeMemoise, key)));
|
||||
key = maybeMemoise;
|
||||
@@ -44,7 +44,7 @@ export default function ({ types: t, template }) {
|
||||
}
|
||||
|
||||
function loose(info) {
|
||||
for (let prop of info.computedProps) {
|
||||
for (const prop of info.computedProps) {
|
||||
if (prop.kind === "get" || prop.kind === "set") {
|
||||
pushMutatorDefine(info, prop);
|
||||
} else {
|
||||
@@ -54,10 +54,10 @@ export default function ({ types: t, template }) {
|
||||
}
|
||||
|
||||
function spec(info) {
|
||||
let { objId, body, computedProps, state } = info;
|
||||
const { objId, body, computedProps, state } = info;
|
||||
|
||||
for (let prop of computedProps) {
|
||||
let key = t.toComputedKey(prop);
|
||||
for (const prop of computedProps) {
|
||||
const key = t.toComputedKey(prop);
|
||||
|
||||
if (prop.kind === "get" || prop.kind === "set") {
|
||||
pushMutatorDefine(info, prop);
|
||||
@@ -87,9 +87,9 @@ export default function ({ types: t, template }) {
|
||||
visitor: {
|
||||
ObjectExpression: {
|
||||
exit(path, state) {
|
||||
let { node, parent, scope } = path;
|
||||
const { node, parent, scope } = path;
|
||||
let hasComputed = false;
|
||||
for (let prop of (node.properties: Array<Object>)) {
|
||||
for (const prop of (node.properties: Array<Object>)) {
|
||||
hasComputed = prop.computed === true;
|
||||
if (hasComputed) break;
|
||||
}
|
||||
@@ -98,11 +98,11 @@ export default function ({ types: t, template }) {
|
||||
// put all getters/setters into the first object expression as well as all initialisers up
|
||||
// to the first computed property
|
||||
|
||||
let initProps = [];
|
||||
let computedProps = [];
|
||||
const initProps = [];
|
||||
const computedProps = [];
|
||||
let foundComputed = false;
|
||||
|
||||
for (let prop of node.properties) {
|
||||
for (const prop of node.properties) {
|
||||
if (prop.computed) {
|
||||
foundComputed = true;
|
||||
}
|
||||
@@ -114,9 +114,9 @@ export default function ({ types: t, template }) {
|
||||
}
|
||||
}
|
||||
|
||||
let objId = scope.generateUidIdentifierBasedOnNode(parent);
|
||||
let initPropExpression = t.objectExpression(initProps);
|
||||
let body = [];
|
||||
const objId = scope.generateUidIdentifierBasedOnNode(parent);
|
||||
const initPropExpression = t.objectExpression(initProps);
|
||||
const body = [];
|
||||
|
||||
body.push(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(objId, initPropExpression)
|
||||
@@ -127,7 +127,7 @@ export default function ({ types: t, template }) {
|
||||
|
||||
let mutatorRef;
|
||||
|
||||
let getMutatorId = function () {
|
||||
const getMutatorId = function () {
|
||||
if (!mutatorRef) {
|
||||
mutatorRef = scope.generateUidIdentifier("mutatorMap");
|
||||
|
||||
@@ -139,7 +139,7 @@ export default function ({ types: t, template }) {
|
||||
return mutatorRef;
|
||||
};
|
||||
|
||||
let single = callback({
|
||||
const single = callback({
|
||||
scope,
|
||||
objId,
|
||||
body,
|
||||
|
||||
@@ -7,7 +7,7 @@ export default function ({ types: t }) {
|
||||
*/
|
||||
|
||||
function variableDeclarationHasPattern(node) {
|
||||
for (let declar of (node.declarations: Array)) {
|
||||
for (const declar of (node.declarations: Array)) {
|
||||
if (t.isPattern(declar.id)) {
|
||||
return true;
|
||||
}
|
||||
@@ -20,7 +20,7 @@ export default function ({ types: t }) {
|
||||
*/
|
||||
|
||||
function hasRest(pattern) {
|
||||
for (let elem of (pattern.elements: Array)) {
|
||||
for (const elem of (pattern.elements: Array)) {
|
||||
if (t.isRestElement(elem)) {
|
||||
return true;
|
||||
}
|
||||
@@ -28,7 +28,7 @@ export default function ({ types: t }) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let arrayUnpackVisitor = {
|
||||
const arrayUnpackVisitor = {
|
||||
ReferencedIdentifier(path, state) {
|
||||
if (state.bindings[path.node.name]) {
|
||||
state.deopt = true;
|
||||
@@ -68,7 +68,7 @@ export default function ({ types: t }) {
|
||||
}
|
||||
|
||||
buildVariableDeclaration(id, init) {
|
||||
let declar = t.variableDeclaration("var", [
|
||||
const declar = t.variableDeclaration("var", [
|
||||
t.variableDeclarator(id, init)
|
||||
]);
|
||||
declar._blockHoist = this.blockHoist;
|
||||
@@ -99,9 +99,9 @@ export default function ({ types: t }) {
|
||||
// we need to assign the current value of the assignment to avoid evaluating
|
||||
// it more than once
|
||||
|
||||
let tempValueRef = this.scope.generateUidIdentifierBasedOnNode(valueRef);
|
||||
const tempValueRef = this.scope.generateUidIdentifierBasedOnNode(valueRef);
|
||||
|
||||
let declar = t.variableDeclaration("var", [
|
||||
const declar = t.variableDeclaration("var", [
|
||||
t.variableDeclarator(tempValueRef, valueRef)
|
||||
]);
|
||||
declar._blockHoist = this.blockHoist;
|
||||
@@ -109,15 +109,15 @@ export default function ({ types: t }) {
|
||||
|
||||
//
|
||||
|
||||
let tempConditional = t.conditionalExpression(
|
||||
const tempConditional = t.conditionalExpression(
|
||||
t.binaryExpression("===", tempValueRef, t.identifier("undefined")),
|
||||
pattern.right,
|
||||
tempValueRef
|
||||
);
|
||||
|
||||
let left = pattern.left;
|
||||
const left = pattern.left;
|
||||
if (t.isPattern(left)) {
|
||||
let tempValueDefault = t.expressionStatement(
|
||||
const tempValueDefault = t.expressionStatement(
|
||||
t.assignmentExpression("=", tempValueRef, tempConditional)
|
||||
);
|
||||
tempValueDefault._blockHoist = this.blockHoist;
|
||||
@@ -135,7 +135,7 @@ export default function ({ types: t }) {
|
||||
let keys = [];
|
||||
|
||||
for (let i = 0; i < pattern.properties.length; i++) {
|
||||
let prop = pattern.properties[i];
|
||||
const prop = pattern.properties[i];
|
||||
|
||||
// we've exceeded the index of the spread property to all properties to the
|
||||
// right need to be ignored
|
||||
@@ -153,15 +153,15 @@ export default function ({ types: t }) {
|
||||
|
||||
//
|
||||
|
||||
let value = t.callExpression(this.file.addHelper("objectWithoutProperties"), [objRef, keys]);
|
||||
const value = t.callExpression(this.file.addHelper("objectWithoutProperties"), [objRef, keys]);
|
||||
this.nodes.push(this.buildVariableAssignment(spreadProp.argument, value));
|
||||
}
|
||||
|
||||
pushObjectProperty(prop, propRef) {
|
||||
if (t.isLiteral(prop.key)) prop.computed = true;
|
||||
|
||||
let pattern = prop.value;
|
||||
let objRef = t.memberExpression(propRef, prop.key, prop.computed);
|
||||
const pattern = prop.value;
|
||||
const objRef = t.memberExpression(propRef, prop.key, prop.computed);
|
||||
|
||||
if (t.isPattern(pattern)) {
|
||||
this.push(pattern, objRef);
|
||||
@@ -184,7 +184,7 @@ export default function ({ types: t }) {
|
||||
// only evaluated once
|
||||
|
||||
if (pattern.properties.length > 1 && !this.scope.isStatic(objRef)) {
|
||||
let temp = this.scope.generateUidIdentifierBasedOnNode(objRef);
|
||||
const temp = this.scope.generateUidIdentifierBasedOnNode(objRef);
|
||||
this.nodes.push(this.buildVariableDeclaration(temp, objRef));
|
||||
objRef = temp;
|
||||
}
|
||||
@@ -192,7 +192,7 @@ export default function ({ types: t }) {
|
||||
//
|
||||
|
||||
for (let i = 0; i < pattern.properties.length; i++) {
|
||||
let prop = pattern.properties[i];
|
||||
const prop = pattern.properties[i];
|
||||
if (t.isRestProperty(prop)) {
|
||||
this.pushObjectRest(pattern, objRef, prop, i);
|
||||
} else {
|
||||
@@ -210,7 +210,7 @@ export default function ({ types: t }) {
|
||||
if (pattern.elements.length > arr.elements.length) return;
|
||||
if (pattern.elements.length < arr.elements.length && !hasRest(pattern)) return false;
|
||||
|
||||
for (let elem of (pattern.elements: Array)) {
|
||||
for (const elem of (pattern.elements: Array)) {
|
||||
// deopt on holes
|
||||
if (!elem) return false;
|
||||
|
||||
@@ -218,7 +218,7 @@ export default function ({ types: t }) {
|
||||
if (t.isMemberExpression(elem)) return false;
|
||||
}
|
||||
|
||||
for (let elem of (arr.elements: Array)) {
|
||||
for (const elem of (arr.elements: Array)) {
|
||||
// deopt on spread elements
|
||||
if (t.isSpreadElement(elem)) return false;
|
||||
|
||||
@@ -230,15 +230,15 @@ export default function ({ types: t }) {
|
||||
}
|
||||
|
||||
// deopt on reference to left side identifiers
|
||||
let bindings = t.getBindingIdentifiers(pattern);
|
||||
let state = { deopt: false, bindings };
|
||||
const bindings = t.getBindingIdentifiers(pattern);
|
||||
const state = { deopt: false, bindings };
|
||||
this.scope.traverse(arr, arrayUnpackVisitor, state);
|
||||
return !state.deopt;
|
||||
}
|
||||
|
||||
pushUnpackedArrayPattern(pattern, arr) {
|
||||
for (let i = 0; i < pattern.elements.length; i++) {
|
||||
let elem = pattern.elements[i];
|
||||
const elem = pattern.elements[i];
|
||||
if (t.isRestElement(elem)) {
|
||||
this.push(elem.argument, t.arrayExpression(arr.elements.slice(i)));
|
||||
} else {
|
||||
@@ -264,13 +264,13 @@ export default function ({ types: t }) {
|
||||
// if we have a rest then we need all the elements so don't tell
|
||||
// `scope.toArray` to only get a certain amount
|
||||
|
||||
let count = !hasRest(pattern) && pattern.elements.length;
|
||||
const count = !hasRest(pattern) && pattern.elements.length;
|
||||
|
||||
// so we need to ensure that the `arrayRef` is an array, `scope.toArray` will
|
||||
// return a locally bound identifier if it's been inferred to be an array,
|
||||
// otherwise it'll be a call to a helper that will ensure it's one
|
||||
|
||||
let toArray = this.toArray(arrayRef, count);
|
||||
const toArray = this.toArray(arrayRef, count);
|
||||
|
||||
if (t.isIdentifier(toArray)) {
|
||||
// we've been given an identifier so it must have been inferred to be an
|
||||
@@ -315,7 +315,7 @@ export default function ({ types: t }) {
|
||||
// need to save it to a variable
|
||||
|
||||
if (!t.isArrayExpression(ref) && !t.isMemberExpression(ref)) {
|
||||
let memo = this.scope.maybeGenerateMemoised(ref, true);
|
||||
const memo = this.scope.maybeGenerateMemoised(ref, true);
|
||||
if (memo) {
|
||||
this.nodes.push(this.buildVariableDeclaration(memo, ref));
|
||||
ref = memo;
|
||||
@@ -334,14 +334,14 @@ export default function ({ types: t }) {
|
||||
return {
|
||||
visitor: {
|
||||
ExportNamedDeclaration(path) {
|
||||
let declaration = path.get("declaration");
|
||||
const declaration = path.get("declaration");
|
||||
if (!declaration.isVariableDeclaration()) return;
|
||||
if (!variableDeclarationHasPattern(declaration.node)) return;
|
||||
|
||||
let specifiers = [];
|
||||
const specifiers = [];
|
||||
|
||||
for (let name in path.getOuterBindingIdentifiers(path)) {
|
||||
let id = t.identifier(name);
|
||||
for (const name in path.getOuterBindingIdentifiers(path)) {
|
||||
const id = t.identifier(name);
|
||||
specifiers.push(t.exportSpecifier(id, id));
|
||||
}
|
||||
|
||||
@@ -353,13 +353,13 @@ export default function ({ types: t }) {
|
||||
},
|
||||
|
||||
ForXStatement(path, file) {
|
||||
let { node, scope } = path;
|
||||
let left = node.left;
|
||||
const { node, scope } = path;
|
||||
const left = node.left;
|
||||
|
||||
if (t.isPattern(left)) {
|
||||
// for ({ length: k } in { abc: 3 });
|
||||
|
||||
let temp = scope.generateUidIdentifier("ref");
|
||||
const temp = scope.generateUidIdentifier("ref");
|
||||
|
||||
node.left = t.variableDeclaration("var", [
|
||||
t.variableDeclarator(temp)
|
||||
@@ -376,17 +376,17 @@ export default function ({ types: t }) {
|
||||
|
||||
if (!t.isVariableDeclaration(left)) return;
|
||||
|
||||
let pattern = left.declarations[0].id;
|
||||
const pattern = left.declarations[0].id;
|
||||
if (!t.isPattern(pattern)) return;
|
||||
|
||||
let key = scope.generateUidIdentifier("ref");
|
||||
const key = scope.generateUidIdentifier("ref");
|
||||
node.left = t.variableDeclaration(left.kind, [
|
||||
t.variableDeclarator(key, null)
|
||||
]);
|
||||
|
||||
let nodes = [];
|
||||
const nodes = [];
|
||||
|
||||
let destructuring = new DestructuringTransformer({
|
||||
const destructuring = new DestructuringTransformer({
|
||||
kind: left.kind,
|
||||
file: file,
|
||||
scope: scope,
|
||||
@@ -397,20 +397,20 @@ export default function ({ types: t }) {
|
||||
|
||||
path.ensureBlock();
|
||||
|
||||
let block = node.body;
|
||||
const block = node.body;
|
||||
block.body = nodes.concat(block.body);
|
||||
},
|
||||
|
||||
CatchClause({ node, scope }, file) {
|
||||
let pattern = node.param;
|
||||
const pattern = node.param;
|
||||
if (!t.isPattern(pattern)) return;
|
||||
|
||||
let ref = scope.generateUidIdentifier("ref");
|
||||
const ref = scope.generateUidIdentifier("ref");
|
||||
node.param = ref;
|
||||
|
||||
let nodes = [];
|
||||
const nodes = [];
|
||||
|
||||
let destructuring = new DestructuringTransformer({
|
||||
const destructuring = new DestructuringTransformer({
|
||||
kind: "let",
|
||||
file: file,
|
||||
scope: scope,
|
||||
@@ -422,12 +422,12 @@ export default function ({ types: t }) {
|
||||
},
|
||||
|
||||
AssignmentExpression(path, file) {
|
||||
let { node, scope } = path;
|
||||
const { node, scope } = path;
|
||||
if (!t.isPattern(node.left)) return;
|
||||
|
||||
let nodes = [];
|
||||
const nodes = [];
|
||||
|
||||
let destructuring = new DestructuringTransformer({
|
||||
const destructuring = new DestructuringTransformer({
|
||||
operator: node.operator,
|
||||
file: file,
|
||||
scope: scope,
|
||||
@@ -457,21 +457,21 @@ export default function ({ types: t }) {
|
||||
},
|
||||
|
||||
VariableDeclaration(path, file) {
|
||||
let { node, scope, parent } = path;
|
||||
const { node, scope, parent } = path;
|
||||
if (t.isForXStatement(parent)) return;
|
||||
if (!parent || !path.container) return; // i don't know why this is necessary - TODO
|
||||
if (!variableDeclarationHasPattern(node)) return;
|
||||
|
||||
let nodes = [];
|
||||
const nodes = [];
|
||||
let declar;
|
||||
|
||||
for (let i = 0; i < node.declarations.length; i++) {
|
||||
declar = node.declarations[i];
|
||||
|
||||
let patternId = declar.init;
|
||||
let pattern = declar.id;
|
||||
const patternId = declar.init;
|
||||
const pattern = declar.id;
|
||||
|
||||
let destructuring = new DestructuringTransformer({
|
||||
const destructuring = new DestructuringTransformer({
|
||||
blockHoist: node._blockHoist,
|
||||
nodes: nodes,
|
||||
scope: scope,
|
||||
|
||||
@@ -26,27 +26,27 @@ export default function() {
|
||||
const alreadySeenGetters = Object.create(null);
|
||||
const alreadySeenSetters = Object.create(null);
|
||||
|
||||
for (let prop of plainProps) {
|
||||
for (const prop of plainProps) {
|
||||
const name = getName(prop.key);
|
||||
let isDuplicate = false;
|
||||
switch (prop.kind) {
|
||||
case "get":
|
||||
if (alreadySeenData[name] || alreadySeenGetters[name]) {
|
||||
isDuplicate = true;
|
||||
}
|
||||
alreadySeenGetters[name] = true;
|
||||
break;
|
||||
case "set":
|
||||
if (alreadySeenData[name] || alreadySeenSetters[name]) {
|
||||
isDuplicate = true;
|
||||
}
|
||||
alreadySeenSetters[name] = true;
|
||||
break;
|
||||
default:
|
||||
if (alreadySeenData[name] || alreadySeenGetters[name] || alreadySeenSetters[name]) {
|
||||
isDuplicate = true;
|
||||
}
|
||||
alreadySeenData[name] = true;
|
||||
case "get":
|
||||
if (alreadySeenData[name] || alreadySeenGetters[name]) {
|
||||
isDuplicate = true;
|
||||
}
|
||||
alreadySeenGetters[name] = true;
|
||||
break;
|
||||
case "set":
|
||||
if (alreadySeenData[name] || alreadySeenSetters[name]) {
|
||||
isDuplicate = true;
|
||||
}
|
||||
alreadySeenSetters[name] = true;
|
||||
break;
|
||||
default:
|
||||
if (alreadySeenData[name] || alreadySeenGetters[name] || alreadySeenSetters[name]) {
|
||||
isDuplicate = true;
|
||||
}
|
||||
alreadySeenData[name] = true;
|
||||
}
|
||||
|
||||
if (isDuplicate) {
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/* eslint max-len: 0 */
|
||||
|
||||
export default function ({ messages, template, types: t }) {
|
||||
let buildForOfArray = template(`
|
||||
const buildForOfArray = template(`
|
||||
for (var KEY = 0; KEY < ARR.length; KEY++) BODY;
|
||||
`);
|
||||
|
||||
let buildForOfLoose = template(`
|
||||
const buildForOfLoose = template(`
|
||||
for (var LOOP_OBJECT = OBJECT,
|
||||
IS_ARRAY = Array.isArray(LOOP_OBJECT),
|
||||
INDEX = 0,
|
||||
@@ -22,7 +22,7 @@ export default function ({ messages, template, types: t }) {
|
||||
}
|
||||
`);
|
||||
|
||||
let buildForOf = template(`
|
||||
const buildForOf = template(`
|
||||
var ITERATOR_COMPLETION = true;
|
||||
var ITERATOR_HAD_ERROR_KEY = false;
|
||||
var ITERATOR_ERROR_KEY = undefined;
|
||||
@@ -46,19 +46,19 @@ export default function ({ messages, template, types: t }) {
|
||||
`);
|
||||
|
||||
function _ForOfStatementArray(path) {
|
||||
let { node, scope } = path;
|
||||
let nodes = [];
|
||||
const { node, scope } = path;
|
||||
const nodes = [];
|
||||
let right = node.right;
|
||||
|
||||
if (!t.isIdentifier(right) || !scope.hasBinding(right.name)) {
|
||||
let uid = scope.generateUidIdentifier("arr");
|
||||
const uid = scope.generateUidIdentifier("arr");
|
||||
nodes.push(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(uid, right)
|
||||
]));
|
||||
right = uid;
|
||||
}
|
||||
|
||||
let iterationKey = scope.generateUidIdentifier("i");
|
||||
const iterationKey = scope.generateUidIdentifier("i");
|
||||
|
||||
let loop = buildForOfArray({
|
||||
BODY: node.body,
|
||||
@@ -69,9 +69,9 @@ export default function ({ messages, template, types: t }) {
|
||||
t.inherits(loop, node);
|
||||
t.ensureBlock(loop);
|
||||
|
||||
let iterationValue = t.memberExpression(right, iterationKey, true);
|
||||
const iterationValue = t.memberExpression(right, iterationKey, true);
|
||||
|
||||
let left = node.left;
|
||||
const left = node.left;
|
||||
if (t.isVariableDeclaration(left)) {
|
||||
left.declarations[0].init = iterationValue;
|
||||
loop.body.body.unshift(left);
|
||||
@@ -103,11 +103,11 @@ export default function ({ messages, template, types: t }) {
|
||||
let callback = spec;
|
||||
if (state.opts.loose) callback = loose;
|
||||
|
||||
let { node } = path;
|
||||
let build = callback(path, state);
|
||||
let declar = build.declar;
|
||||
let loop = build.loop;
|
||||
let block = loop.body;
|
||||
const { node } = path;
|
||||
const build = callback(path, state);
|
||||
const declar = build.declar;
|
||||
const loop = build.loop;
|
||||
const block = loop.body;
|
||||
|
||||
// ensure that it's a block so we can take all its statements
|
||||
path.ensureBlock();
|
||||
@@ -134,9 +134,9 @@ export default function ({ messages, template, types: t }) {
|
||||
};
|
||||
|
||||
function loose(path, file) {
|
||||
let { node, scope } = path;
|
||||
const { node, scope } = path;
|
||||
|
||||
let left = node.left;
|
||||
const left = node.left;
|
||||
let declar, id;
|
||||
|
||||
if (t.isIdentifier(left) || t.isPattern(left) || t.isMemberExpression(left)) {
|
||||
@@ -152,10 +152,10 @@ export default function ({ messages, template, types: t }) {
|
||||
throw file.buildCodeFrameError(left, messages.get("unknownForHead", left.type));
|
||||
}
|
||||
|
||||
let iteratorKey = scope.generateUidIdentifier("iterator");
|
||||
let isArrayKey = scope.generateUidIdentifier("isArray");
|
||||
const iteratorKey = scope.generateUidIdentifier("iterator");
|
||||
const isArrayKey = scope.generateUidIdentifier("isArray");
|
||||
|
||||
let loop = buildForOfLoose({
|
||||
const loop = buildForOfLoose({
|
||||
LOOP_OBJECT: iteratorKey,
|
||||
IS_ARRAY: isArrayKey,
|
||||
OBJECT: node.right,
|
||||
@@ -179,12 +179,12 @@ export default function ({ messages, template, types: t }) {
|
||||
}
|
||||
|
||||
function spec(path, file) {
|
||||
let { node, scope, parent } = path;
|
||||
let left = node.left;
|
||||
const { node, scope, parent } = path;
|
||||
const left = node.left;
|
||||
let declar;
|
||||
|
||||
let stepKey = scope.generateUidIdentifier("step");
|
||||
let stepValue = t.memberExpression(stepKey, t.identifier("value"));
|
||||
const stepKey = scope.generateUidIdentifier("step");
|
||||
const stepValue = t.memberExpression(stepKey, t.identifier("value"));
|
||||
|
||||
if (t.isIdentifier(left) || t.isPattern(left) || t.isMemberExpression(left)) {
|
||||
// for (i of test), for ({ i } of test)
|
||||
@@ -200,9 +200,9 @@ export default function ({ messages, template, types: t }) {
|
||||
|
||||
//
|
||||
|
||||
let iteratorKey = scope.generateUidIdentifier("iterator");
|
||||
const iteratorKey = scope.generateUidIdentifier("iterator");
|
||||
|
||||
let template = buildForOf({
|
||||
const template = buildForOf({
|
||||
ITERATOR_HAD_ERROR_KEY: scope.generateUidIdentifier("didIteratorError"),
|
||||
ITERATOR_COMPLETION: scope.generateUidIdentifier("iteratorNormalCompletion"),
|
||||
ITERATOR_ERROR_KEY: scope.generateUidIdentifier("iteratorError"),
|
||||
@@ -212,10 +212,10 @@ export default function ({ messages, template, types: t }) {
|
||||
BODY: null
|
||||
});
|
||||
|
||||
let isLabeledParent = t.isLabeledStatement(parent);
|
||||
const isLabeledParent = t.isLabeledStatement(parent);
|
||||
|
||||
let tryBody = template[3].block.body;
|
||||
let loop = tryBody[0];
|
||||
const tryBody = template[3].block.body;
|
||||
const loop = tryBody[0];
|
||||
|
||||
if (isLabeledParent) {
|
||||
tryBody[0] = t.labeledStatement(parent.label, loop);
|
||||
|
||||
@@ -6,16 +6,16 @@ export default function () {
|
||||
"ArrowFunctionExpression|FunctionExpression": {
|
||||
exit(path) {
|
||||
if (path.key !== "value" && !path.parentPath.isObjectProperty()) {
|
||||
let replacement = nameFunction(path);
|
||||
const replacement = nameFunction(path);
|
||||
if (replacement) path.replaceWith(replacement);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
ObjectProperty(path) {
|
||||
let value = path.get("value");
|
||||
const value = path.get("value");
|
||||
if (value.isFunction()) {
|
||||
let newNode = nameFunction(value);
|
||||
const newNode = nameFunction(value);
|
||||
if (newNode) value.replaceWith(newNode);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ export default function ({ types: t }) {
|
||||
return {
|
||||
visitor: {
|
||||
BinaryExpression(path) {
|
||||
let { node } = path;
|
||||
const { node } = path;
|
||||
if (node.operator === "instanceof") {
|
||||
path.replaceWith(t.callExpression(this.addHelper("instanceof"), [node.left, node.right]));
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import template from "babel-template";
|
||||
|
||||
let buildDefine = template(`
|
||||
const buildDefine = template(`
|
||||
define(MODULE_NAME, [SOURCES], FACTORY);
|
||||
`);
|
||||
|
||||
let buildFactory = template(`
|
||||
const buildFactory = template(`
|
||||
(function (PARAMS) {
|
||||
BODY;
|
||||
})
|
||||
@@ -16,16 +16,16 @@ export default function ({ types: t }) {
|
||||
if (!path.get("callee").isIdentifier({ name: "require" })) return false;
|
||||
if (path.scope.getBinding("require")) return false;
|
||||
|
||||
let args = path.get("arguments");
|
||||
const args = path.get("arguments");
|
||||
if (args.length !== 1) return false;
|
||||
|
||||
let arg = args[0];
|
||||
const arg = args[0];
|
||||
if (!arg.isStringLiteral()) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
let amdVisitor = {
|
||||
const amdVisitor = {
|
||||
ReferencedIdentifier({ node, scope }) {
|
||||
if (node.name === "exports" && !scope.getBinding("exports")) {
|
||||
this.hasExports = true;
|
||||
@@ -43,13 +43,13 @@ export default function ({ types: t }) {
|
||||
},
|
||||
|
||||
VariableDeclarator(path) {
|
||||
let id = path.get("id");
|
||||
const id = path.get("id");
|
||||
if (!id.isIdentifier()) return;
|
||||
|
||||
let init = path.get("init");
|
||||
const init = path.get("init");
|
||||
if (!isValidRequireCall(init)) return;
|
||||
|
||||
let source = init.node.arguments[0];
|
||||
const source = init.node.arguments[0];
|
||||
this.sourceNames[source.value] = true;
|
||||
this.sources.push([id.node, source]);
|
||||
|
||||
@@ -80,7 +80,7 @@ export default function ({ types: t }) {
|
||||
|
||||
path.traverse(amdVisitor, this);
|
||||
|
||||
let params = this.sources.map((source) => source[0]);
|
||||
const params = this.sources.map((source) => source[0]);
|
||||
let sources = this.sources.map((source) => source[1]);
|
||||
|
||||
sources = sources.concat(this.bareSources.filter((str) => {
|
||||
@@ -100,8 +100,8 @@ export default function ({ types: t }) {
|
||||
params.unshift(t.identifier("module"));
|
||||
}
|
||||
|
||||
let { node } = path;
|
||||
let factory = buildFactory({
|
||||
const { node } = path;
|
||||
const factory = buildFactory({
|
||||
PARAMS: params,
|
||||
BODY: node.body
|
||||
});
|
||||
|
||||
@@ -4,17 +4,17 @@ import { basename, extname } from "path";
|
||||
import template from "babel-template";
|
||||
import * as t from "babel-types";
|
||||
|
||||
let buildRequire = template(`
|
||||
const buildRequire = template(`
|
||||
require($0);
|
||||
`);
|
||||
|
||||
let buildExportsModuleDeclaration = template(`
|
||||
const buildExportsModuleDeclaration = template(`
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
`);
|
||||
|
||||
let buildExportsFrom = template(`
|
||||
const buildExportsFrom = template(`
|
||||
Object.defineProperty(exports, $0, {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
@@ -23,15 +23,15 @@ let buildExportsFrom = template(`
|
||||
});
|
||||
`);
|
||||
|
||||
let buildLooseExportsModuleDeclaration = template(`
|
||||
const buildLooseExportsModuleDeclaration = template(`
|
||||
exports.__esModule = true;
|
||||
`);
|
||||
|
||||
let buildExportsAssignment = template(`
|
||||
const buildExportsAssignment = template(`
|
||||
exports.$0 = $1;
|
||||
`);
|
||||
|
||||
let buildExportAll = template(`
|
||||
const buildExportAll = template(`
|
||||
Object.keys(OBJECT).forEach(function (key) {
|
||||
if (key === "default" || key === "__esModule") return;
|
||||
Object.defineProperty(exports, key, {
|
||||
@@ -46,12 +46,12 @@ let buildExportAll = template(`
|
||||
const THIS_BREAK_KEYS = ["FunctionExpression", "FunctionDeclaration", "ClassProperty", "ClassMethod", "ObjectMethod"];
|
||||
|
||||
export default function () {
|
||||
let REASSIGN_REMAP_SKIP = Symbol();
|
||||
const REASSIGN_REMAP_SKIP = Symbol();
|
||||
|
||||
let reassignmentVisitor = {
|
||||
const reassignmentVisitor = {
|
||||
ReferencedIdentifier(path) {
|
||||
let name = path.node.name;
|
||||
let remap = this.remaps[name];
|
||||
const name = path.node.name;
|
||||
const remap = this.remaps[name];
|
||||
if (!remap) return;
|
||||
|
||||
// redeclared in this scope
|
||||
@@ -72,11 +72,11 @@ export default function () {
|
||||
let node = path.node;
|
||||
if (node[REASSIGN_REMAP_SKIP]) return;
|
||||
|
||||
let left = path.get("left");
|
||||
const left = path.get("left");
|
||||
if (!left.isIdentifier()) return;
|
||||
|
||||
let name = left.node.name;
|
||||
let exports = this.exports[name];
|
||||
const name = left.node.name;
|
||||
const exports = this.exports[name];
|
||||
if (!exports) return;
|
||||
|
||||
// redeclared in this scope
|
||||
@@ -84,7 +84,7 @@ export default function () {
|
||||
|
||||
node[REASSIGN_REMAP_SKIP] = true;
|
||||
|
||||
for (let reid of exports) {
|
||||
for (const reid of exports) {
|
||||
node = buildExportsAssignment(reid, node).expression;
|
||||
}
|
||||
|
||||
@@ -93,17 +93,17 @@ export default function () {
|
||||
},
|
||||
|
||||
UpdateExpression(path) {
|
||||
let arg = path.get("argument");
|
||||
const arg = path.get("argument");
|
||||
if (!arg.isIdentifier()) return;
|
||||
|
||||
let name = arg.node.name;
|
||||
let exports = this.exports[name];
|
||||
const name = arg.node.name;
|
||||
const exports = this.exports[name];
|
||||
if (!exports) return;
|
||||
|
||||
// redeclared in this scope
|
||||
if (this.scope.getBinding(name) !== path.scope.getBinding(name)) return;
|
||||
|
||||
let node = t.assignmentExpression(path.node.operator[0] + "=", arg.node, t.numericLiteral(1));
|
||||
const node = t.assignmentExpression(path.node.operator[0] + "=", arg.node, t.numericLiteral(1));
|
||||
|
||||
if ((path.parentPath.isExpressionStatement() && !path.isCompletionRecord()) || path.node.prefix) {
|
||||
path.replaceWith(node);
|
||||
@@ -111,7 +111,7 @@ export default function () {
|
||||
return;
|
||||
}
|
||||
|
||||
let nodes = [];
|
||||
const nodes = [];
|
||||
nodes.push(node);
|
||||
|
||||
let operator;
|
||||
@@ -149,9 +149,9 @@ export default function () {
|
||||
exit(path) {
|
||||
this.ranCommonJS = true;
|
||||
|
||||
let strict = !!this.opts.strict;
|
||||
const strict = !!this.opts.strict;
|
||||
|
||||
let { scope } = path;
|
||||
const { scope } = path;
|
||||
|
||||
// rename these commonjs variables if they're declared in the file
|
||||
scope.rename("module");
|
||||
@@ -161,24 +161,24 @@ export default function () {
|
||||
let hasExports = false;
|
||||
let hasImports = false;
|
||||
|
||||
let body: Array<Object> = path.get("body");
|
||||
let imports = Object.create(null);
|
||||
let exports = Object.create(null);
|
||||
const body: Array<Object> = path.get("body");
|
||||
const imports = Object.create(null);
|
||||
const exports = Object.create(null);
|
||||
|
||||
let nonHoistedExportNames = Object.create(null);
|
||||
const nonHoistedExportNames = Object.create(null);
|
||||
|
||||
let topNodes = [];
|
||||
let remaps = Object.create(null);
|
||||
const topNodes = [];
|
||||
const remaps = Object.create(null);
|
||||
|
||||
let requires = Object.create(null);
|
||||
const requires = Object.create(null);
|
||||
|
||||
function addRequire(source, blockHoist) {
|
||||
let cached = requires[source];
|
||||
const cached = requires[source];
|
||||
if (cached) return cached;
|
||||
|
||||
let ref = path.scope.generateUidIdentifier(basename(source, extname(source)));
|
||||
const ref = path.scope.generateUidIdentifier(basename(source, extname(source)));
|
||||
|
||||
let varDecl = t.variableDeclaration("var", [
|
||||
const varDecl = t.variableDeclaration("var", [
|
||||
t.variableDeclarator(ref, buildRequire(
|
||||
t.stringLiteral(source)
|
||||
).expression)
|
||||
@@ -200,17 +200,17 @@ export default function () {
|
||||
}
|
||||
|
||||
function addTo(obj, key, arr) {
|
||||
let existing = obj[key] || [];
|
||||
const existing = obj[key] || [];
|
||||
obj[key] = existing.concat(arr);
|
||||
}
|
||||
|
||||
for (let path of body) {
|
||||
for (const path of body) {
|
||||
if (path.isExportDeclaration()) {
|
||||
hasExports = true;
|
||||
|
||||
let specifiers = [].concat(path.get("declaration"), path.get("specifiers"));
|
||||
for (let specifier of specifiers) {
|
||||
let ids = specifier.getBindingIdentifiers();
|
||||
const specifiers = [].concat(path.get("declaration"), path.get("specifiers"));
|
||||
for (const specifier of specifiers) {
|
||||
const ids = specifier.getBindingIdentifiers();
|
||||
if (ids.__esModule) {
|
||||
throw specifier.buildCodeFrameError("Illegal export \"__esModule\"");
|
||||
}
|
||||
@@ -220,8 +220,8 @@ export default function () {
|
||||
if (path.isImportDeclaration()) {
|
||||
hasImports = true;
|
||||
|
||||
let key = path.node.source.value;
|
||||
let importsEntry = imports[key] || {
|
||||
const key = path.node.source.value;
|
||||
const importsEntry = imports[key] || {
|
||||
specifiers: [],
|
||||
maxBlockHoist: 0,
|
||||
loc: path.node.loc,
|
||||
@@ -240,10 +240,10 @@ export default function () {
|
||||
|
||||
path.remove();
|
||||
} else if (path.isExportDefaultDeclaration()) {
|
||||
let declaration = path.get("declaration");
|
||||
const declaration = path.get("declaration");
|
||||
if (declaration.isFunctionDeclaration()) {
|
||||
let id = declaration.node.id;
|
||||
let defNode = t.identifier("default");
|
||||
const id = declaration.node.id;
|
||||
const defNode = t.identifier("default");
|
||||
if (id) {
|
||||
addTo(exports, id.name, defNode);
|
||||
topNodes.push(buildExportsAssignment(defNode, id));
|
||||
@@ -253,8 +253,8 @@ export default function () {
|
||||
path.remove();
|
||||
}
|
||||
} else if (declaration.isClassDeclaration()) {
|
||||
let id = declaration.node.id;
|
||||
let defNode = t.identifier("default");
|
||||
const id = declaration.node.id;
|
||||
const defNode = t.identifier("default");
|
||||
if (id) {
|
||||
addTo(exports, id.name, defNode);
|
||||
path.replaceWithMultiple([
|
||||
@@ -278,15 +278,15 @@ export default function () {
|
||||
path.parentPath.requeue(path.get("expression.left"));
|
||||
}
|
||||
} else if (path.isExportNamedDeclaration()) {
|
||||
let declaration = path.get("declaration");
|
||||
const declaration = path.get("declaration");
|
||||
if (declaration.node) {
|
||||
if (declaration.isFunctionDeclaration()) {
|
||||
let id = declaration.node.id;
|
||||
const id = declaration.node.id;
|
||||
addTo(exports, id.name, id);
|
||||
topNodes.push(buildExportsAssignment(id, id));
|
||||
path.replaceWith(declaration.node);
|
||||
} else if (declaration.isClassDeclaration()) {
|
||||
let id = declaration.node.id;
|
||||
const id = declaration.node.id;
|
||||
addTo(exports, id.name, id);
|
||||
path.replaceWithMultiple([
|
||||
declaration.node,
|
||||
@@ -294,11 +294,11 @@ export default function () {
|
||||
]);
|
||||
nonHoistedExportNames[id.name] = true;
|
||||
} else if (declaration.isVariableDeclaration()) {
|
||||
let declarators = declaration.get("declarations");
|
||||
for (let decl of declarators) {
|
||||
let id = decl.get("id");
|
||||
const declarators = declaration.get("declarations");
|
||||
for (const decl of declarators) {
|
||||
const id = decl.get("id");
|
||||
|
||||
let init = decl.get("init");
|
||||
const init = decl.get("init");
|
||||
if (!init.node) init.replaceWith(t.identifier("undefined"));
|
||||
|
||||
if (id.isIdentifier()) {
|
||||
@@ -314,13 +314,13 @@ export default function () {
|
||||
continue;
|
||||
}
|
||||
|
||||
let specifiers = path.get("specifiers");
|
||||
let nodes = [];
|
||||
let source = path.node.source;
|
||||
const specifiers = path.get("specifiers");
|
||||
const nodes = [];
|
||||
const source = path.node.source;
|
||||
if (source) {
|
||||
let ref = addRequire(source.value, path.node._blockHoist);
|
||||
const ref = addRequire(source.value, path.node._blockHoist);
|
||||
|
||||
for (let specifier of specifiers) {
|
||||
for (const specifier of specifiers) {
|
||||
if (specifier.isExportNamespaceSpecifier()) {
|
||||
// todo
|
||||
} else if (specifier.isExportDefaultSpecifier()) {
|
||||
@@ -335,7 +335,7 @@ export default function () {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (let specifier of specifiers) {
|
||||
for (const specifier of specifiers) {
|
||||
if (specifier.isExportSpecifier()) {
|
||||
addTo(exports, specifier.node.local.name, specifier.node.exported);
|
||||
nonHoistedExportNames[specifier.node.exported.name] = true;
|
||||
@@ -345,7 +345,7 @@ export default function () {
|
||||
}
|
||||
path.replaceWithMultiple(nodes);
|
||||
} else if (path.isExportAllDeclaration()) {
|
||||
let exportNode = buildExportAll({
|
||||
const exportNode = buildExportAll({
|
||||
OBJECT: addRequire(path.node.source.value, path.node._blockHoist)
|
||||
});
|
||||
exportNode.loc = path.node.loc;
|
||||
@@ -354,15 +354,15 @@ export default function () {
|
||||
}
|
||||
}
|
||||
|
||||
for (let source in imports) {
|
||||
let {specifiers, maxBlockHoist} = imports[source];
|
||||
for (const source in imports) {
|
||||
const {specifiers, maxBlockHoist} = imports[source];
|
||||
if (specifiers.length) {
|
||||
let uid = addRequire(source, maxBlockHoist);
|
||||
const uid = addRequire(source, maxBlockHoist);
|
||||
|
||||
let wildcard;
|
||||
|
||||
for (let i = 0; i < specifiers.length; i++) {
|
||||
let specifier = specifiers[i];
|
||||
const specifier = specifiers[i];
|
||||
if (t.isImportNamespaceSpecifier(specifier)) {
|
||||
if (strict) {
|
||||
remaps[specifier.local.name] = uid;
|
||||
@@ -389,7 +389,7 @@ export default function () {
|
||||
}
|
||||
}
|
||||
|
||||
for (let specifier of specifiers) {
|
||||
for (const specifier of specifiers) {
|
||||
if (t.isImportSpecifier(specifier)) {
|
||||
let target = uid;
|
||||
if (specifier.imported.name === "default") {
|
||||
@@ -419,7 +419,7 @@ export default function () {
|
||||
}
|
||||
} else {
|
||||
// bare import
|
||||
let requireNode = buildRequire(t.stringLiteral(source));
|
||||
const requireNode = buildRequire(t.stringLiteral(source));
|
||||
requireNode.loc = imports[source].loc;
|
||||
topNodes.push(requireNode);
|
||||
}
|
||||
@@ -428,7 +428,7 @@ export default function () {
|
||||
if (hasImports && Object.keys(nonHoistedExportNames).length) {
|
||||
let hoistedExportsNode = t.identifier("undefined");
|
||||
|
||||
for (let name in nonHoistedExportNames) {
|
||||
for (const name in nonHoistedExportNames) {
|
||||
hoistedExportsNode = buildExportsAssignment(t.identifier(name), hoistedExportsNode).expression;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
let assert = require("assert");
|
||||
let babel = require("babel-core");
|
||||
let vm = require("vm");
|
||||
const assert = require("assert");
|
||||
const babel = require("babel-core");
|
||||
const vm = require("vm");
|
||||
|
||||
test("Re-export doesn't overwrite __esModule flag", function () {
|
||||
let code = "export * from \"./dep\";";
|
||||
let depStub = {
|
||||
const depStub = {
|
||||
__esModule: false,
|
||||
};
|
||||
|
||||
let context = {
|
||||
const context = {
|
||||
module: {
|
||||
exports: {}
|
||||
},
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user