var -> let
This commit is contained in:
parent
0708edb927
commit
c99a179401
@ -9,7 +9,7 @@ import * as babel from "babel-core";
|
|||||||
import vm from "vm";
|
import vm from "vm";
|
||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
|
|
||||||
var program = new commander.Command("babel-node");
|
let program = new commander.Command("babel-node");
|
||||||
|
|
||||||
program.option("-e, --eval [script]", "Evaluate script");
|
program.option("-e, --eval [script]", "Evaluate script");
|
||||||
program.option("-p, --print [code]", "Evaluate script and print result");
|
program.option("-p, --print [code]", "Evaluate script and print result");
|
||||||
@ -18,7 +18,7 @@ program.option("-x, --extensions [extensions]", "List of extensions to hook into
|
|||||||
program.option("-w, --plugins [string]", "TODO", util.list);
|
program.option("-w, --plugins [string]", "TODO", util.list);
|
||||||
program.option("-b, --presets [string]", "TODO", util.list);
|
program.option("-b, --presets [string]", "TODO", util.list);
|
||||||
|
|
||||||
var pkg = require("../package.json");
|
let pkg = require("../package.json");
|
||||||
program.version(pkg.version);
|
program.version(pkg.version);
|
||||||
program.usage("[options] [ -e script | script.js ] [arguments]");
|
program.usage("[options] [ -e script | script.js ] [arguments]");
|
||||||
program.parse(process.argv);
|
program.parse(process.argv);
|
||||||
@ -35,7 +35,7 @@ babel.register({
|
|||||||
|
|
||||||
//
|
//
|
||||||
|
|
||||||
var replPlugin = new babel.Plugin("repl", {
|
let replPlugin = new babel.Plugin("repl", {
|
||||||
visitor: {
|
visitor: {
|
||||||
ModuleDeclaration() {
|
ModuleDeclaration() {
|
||||||
throw this.errorWithNode("Modules aren't supported in the REPL");
|
throw this.errorWithNode("Modules aren't supported in the REPL");
|
||||||
@ -51,7 +51,7 @@ var replPlugin = new babel.Plugin("repl", {
|
|||||||
|
|
||||||
//
|
//
|
||||||
|
|
||||||
var _eval = function (code, filename) {
|
let _eval = function (code, filename) {
|
||||||
code = code.trim();
|
code = code.trim();
|
||||||
if (!code) return undefined;
|
if (!code) return undefined;
|
||||||
|
|
||||||
@ -70,13 +70,13 @@ var _eval = function (code, filename) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (program.eval || program.print) {
|
if (program.eval || program.print) {
|
||||||
var code = program.eval;
|
let code = program.eval;
|
||||||
if (!code || code === true) code = program.print;
|
if (!code || code === true) code = program.print;
|
||||||
|
|
||||||
global.__filename = "[eval]";
|
global.__filename = "[eval]";
|
||||||
global.__dirname = process.cwd();
|
global.__dirname = process.cwd();
|
||||||
|
|
||||||
var module = new Module(global.__filename);
|
let module = new Module(global.__filename);
|
||||||
module.filename = global.__filename;
|
module.filename = global.__filename;
|
||||||
module.paths = Module._nodeModulePaths(global.__dirname);
|
module.paths = Module._nodeModulePaths(global.__dirname);
|
||||||
|
|
||||||
@ -84,18 +84,18 @@ if (program.eval || program.print) {
|
|||||||
global.module = module;
|
global.module = module;
|
||||||
global.require = module.require.bind(module);
|
global.require = module.require.bind(module);
|
||||||
|
|
||||||
var result = _eval(code, global.__filename);
|
let result = _eval(code, global.__filename);
|
||||||
if (program.print) {
|
if (program.print) {
|
||||||
var output = _.isString(result) ? result : inspect(result);
|
let output = _.isString(result) ? result : inspect(result);
|
||||||
process.stdout.write(output + "\n");
|
process.stdout.write(output + "\n");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (program.args.length) {
|
if (program.args.length) {
|
||||||
// slice all arguments up to the first filename since they're babel args that we handle
|
// slice all arguments up to the first filename since they're babel args that we handle
|
||||||
var args = process.argv.slice(2);
|
let args = process.argv.slice(2);
|
||||||
|
|
||||||
var i = 0;
|
let i = 0;
|
||||||
var ignoreNext = false;
|
let ignoreNext = false;
|
||||||
_.each(args, function (arg, i2) {
|
_.each(args, function (arg, i2) {
|
||||||
if (ignoreNext) {
|
if (ignoreNext) {
|
||||||
ignoreNext = false;
|
ignoreNext = false;
|
||||||
@ -103,7 +103,7 @@ if (program.eval || program.print) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (arg[0] === "-") {
|
if (arg[0] === "-") {
|
||||||
var parsedArg = program[arg.slice(2)];
|
let parsedArg = program[arg.slice(2)];
|
||||||
if (parsedArg && parsedArg !== true) {
|
if (parsedArg && parsedArg !== true) {
|
||||||
ignoreNext = true;
|
ignoreNext = true;
|
||||||
}
|
}
|
||||||
@ -115,7 +115,7 @@ if (program.eval || program.print) {
|
|||||||
args = args.slice(i);
|
args = args.slice(i);
|
||||||
|
|
||||||
// make the filename absolute
|
// make the filename absolute
|
||||||
var filename = args[0];
|
let filename = args[0];
|
||||||
if (!pathIsAbsolute(filename)) args[0] = path.join(process.cwd(), filename);
|
if (!pathIsAbsolute(filename)) args[0] = path.join(process.cwd(), filename);
|
||||||
|
|
||||||
// add back on node and concat the sliced args
|
// add back on node and concat the sliced args
|
||||||
@ -139,8 +139,8 @@ function replStart() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function replEval(code, context, filename, callback) {
|
function replEval(code, context, filename, callback) {
|
||||||
var err;
|
let err;
|
||||||
var result;
|
let result;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (code[0] === "(" && code[code.length - 1] === ")") {
|
if (code[0] === "(" && code[code.length - 1] === ")") {
|
||||||
|
|||||||
@ -3,16 +3,16 @@
|
|||||||
* when found, before invoking the "real" _babel-node(1) executable.
|
* when found, before invoking the "real" _babel-node(1) executable.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var getV8Flags = require("v8flags");
|
let getV8Flags = require("v8flags");
|
||||||
var path = require("path");
|
let path = require("path");
|
||||||
|
|
||||||
var args = [path.join(__dirname, "_babel-node")];
|
let args = [path.join(__dirname, "_babel-node")];
|
||||||
|
|
||||||
var babelArgs = process.argv.slice(2);
|
let babelArgs = process.argv.slice(2);
|
||||||
var userArgs;
|
let userArgs;
|
||||||
|
|
||||||
// separate node arguments from script arguments
|
// separate node arguments from script arguments
|
||||||
var argSeparator = babelArgs.indexOf("--");
|
let argSeparator = babelArgs.indexOf("--");
|
||||||
if (argSeparator > -1) {
|
if (argSeparator > -1) {
|
||||||
userArgs = babelArgs.slice(argSeparator); // including the --
|
userArgs = babelArgs.slice(argSeparator); // including the --
|
||||||
babelArgs = babelArgs.slice(0, argSeparator);
|
babelArgs = babelArgs.slice(0, argSeparator);
|
||||||
@ -20,7 +20,7 @@ if (argSeparator > -1) {
|
|||||||
|
|
||||||
getV8Flags(function (v8Flags) {
|
getV8Flags(function (v8Flags) {
|
||||||
babelArgs.forEach(function(arg){
|
babelArgs.forEach(function(arg){
|
||||||
var flag = arg.split("=")[0];
|
let flag = arg.split("=")[0];
|
||||||
|
|
||||||
switch (flag) {
|
switch (flag) {
|
||||||
case "-d":
|
case "-d":
|
||||||
@ -54,13 +54,13 @@ getV8Flags(function (v8Flags) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
var kexec = require("kexec");
|
let kexec = require("kexec");
|
||||||
kexec(process.argv[0], args);
|
kexec(process.argv[0], args);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (err.code !== "MODULE_NOT_FOUND") throw err;
|
if (err.code !== "MODULE_NOT_FOUND") throw err;
|
||||||
|
|
||||||
var child_process = require("child_process");
|
let child_process = require("child_process");
|
||||||
var proc = child_process.spawn(process.argv[0], args, { stdio: "inherit" });
|
let proc = child_process.spawn(process.argv[0], args, { stdio: "inherit" });
|
||||||
proc.on("exit", function (code, signal) {
|
proc.on("exit", function (code, signal) {
|
||||||
process.on("exit", function () {
|
process.on("exit", function () {
|
||||||
if (signal) {
|
if (signal) {
|
||||||
|
|||||||
@ -7,7 +7,7 @@ import fs from "fs";
|
|||||||
function spawn(cmd, args, callback) {
|
function spawn(cmd, args, callback) {
|
||||||
console.log(">", cmd, args);
|
console.log(">", cmd, args);
|
||||||
|
|
||||||
var spawn = child.spawn(cmd, args, { stdio: "inherit" });
|
let spawn = child.spawn(cmd, args, { stdio: "inherit" });
|
||||||
|
|
||||||
spawn.on("exit", function (code) {
|
spawn.on("exit", function (code) {
|
||||||
if (code === 0) {
|
if (code === 0) {
|
||||||
@ -21,7 +21,7 @@ function spawn(cmd, args, callback) {
|
|||||||
|
|
||||||
function spawnMultiple(cmds) {
|
function spawnMultiple(cmds) {
|
||||||
function next() {
|
function next() {
|
||||||
var cmd = cmds.shift();
|
let cmd = cmds.shift();
|
||||||
if (cmd) {
|
if (cmd) {
|
||||||
spawn(cmd.command, cmd.args, next);
|
spawn(cmd.command, cmd.args, next);
|
||||||
} else {
|
} else {
|
||||||
@ -33,7 +33,7 @@ function spawnMultiple(cmds) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function template(name, data = {}) {
|
function template(name, data = {}) {
|
||||||
var source = fs.readFileSync(path.join(__dirname, "templates", name), "utf8");
|
let source = fs.readFileSync(path.join(__dirname, "templates", name), "utf8");
|
||||||
source = source.replace(/[A-Z_]+/g, function (key) {
|
source = source.replace(/[A-Z_]+/g, function (key) {
|
||||||
return data[key] === undefined ? key : data[key];
|
return data[key] === undefined ? key : data[key];
|
||||||
});
|
});
|
||||||
@ -53,23 +53,23 @@ function execMaybe(cmd) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var rl = readline.createInterface({
|
let rl = readline.createInterface({
|
||||||
input: process.stdin,
|
input: process.stdin,
|
||||||
output: process.stdout
|
output: process.stdout
|
||||||
});
|
});
|
||||||
|
|
||||||
var BABEL_PLUGIN_PREFIX = "babel-plugin-";
|
let BABEL_PLUGIN_PREFIX = "babel-plugin-";
|
||||||
|
|
||||||
var cmds = {
|
let cmds = {
|
||||||
init: function () {
|
init: function () {
|
||||||
var name = path.basename(process.cwd());
|
let name = path.basename(process.cwd());
|
||||||
|
|
||||||
if (name.indexOf(BABEL_PLUGIN_PREFIX) === 0) {
|
if (name.indexOf(BABEL_PLUGIN_PREFIX) === 0) {
|
||||||
name = name.slice(BABEL_PLUGIN_PREFIX.length);
|
name = name.slice(BABEL_PLUGIN_PREFIX.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
rl.question("Description (optional): ", function (description) {
|
rl.question("Description (optional): ", function (description) {
|
||||||
var remote = execMaybe("git config --get remote.origin.url").trim().match(/git@github.com:(.*?).git/);
|
let remote = execMaybe("git config --get remote.origin.url").trim().match(/git@github.com:(.*?).git/);
|
||||||
if (remote) {
|
if (remote) {
|
||||||
build(description, remote[1]);
|
build(description, remote[1]);
|
||||||
} else {
|
} else {
|
||||||
@ -82,7 +82,7 @@ var cmds = {
|
|||||||
function build(description, repo) {
|
function build(description, repo) {
|
||||||
rl.close();
|
rl.close();
|
||||||
|
|
||||||
var templateData = {
|
let templateData = {
|
||||||
DESCRIPTION: description,
|
DESCRIPTION: description,
|
||||||
FULL_NAME: BABEL_PLUGIN_PREFIX + name,
|
FULL_NAME: BABEL_PLUGIN_PREFIX + name,
|
||||||
NAME: name
|
NAME: name
|
||||||
@ -133,7 +133,7 @@ var cmds = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
publish: function () {
|
publish: function () {
|
||||||
var pkg = require(process.cwd() + "/package.json");
|
let pkg = require(process.cwd() + "/package.json");
|
||||||
console.log("Current version:", pkg.version);
|
console.log("Current version:", pkg.version);
|
||||||
|
|
||||||
rl.question("New version (enter nothing for patch): ", function (newVersion) {
|
rl.question("New version (enter nothing for patch): ", function (newVersion) {
|
||||||
@ -153,7 +153,7 @@ var cmds = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var cmd = cmds[process.argv[2]];
|
let cmd = cmds[process.argv[2]];
|
||||||
if (cmd) {
|
if (cmd) {
|
||||||
cmd();
|
cmd();
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -1,27 +1,27 @@
|
|||||||
var outputFileSync = require("output-file-sync");
|
let outputFileSync = require("output-file-sync");
|
||||||
var pathExists = require("path-exists");
|
let pathExists = require("path-exists");
|
||||||
var chokidar = require("chokidar");
|
let chokidar = require("chokidar");
|
||||||
var slash = require("slash");
|
let slash = require("slash");
|
||||||
var path = require("path");
|
let path = require("path");
|
||||||
var util = require("./util");
|
let util = require("./util");
|
||||||
var fs = require("fs");
|
let fs = require("fs");
|
||||||
var _ = require("lodash");
|
let _ = require("lodash");
|
||||||
|
|
||||||
module.exports = function (commander, filenames) {
|
module.exports = function (commander, filenames) {
|
||||||
function write(src, relative) {
|
function write(src, relative) {
|
||||||
// remove extension and then append back on .js
|
// remove extension and then append back on .js
|
||||||
relative = relative.replace(/\.(\w*?)$/, "") + ".js";
|
relative = relative.replace(/\.(\w*?)$/, "") + ".js";
|
||||||
|
|
||||||
var dest = path.join(commander.outDir, relative);
|
let dest = path.join(commander.outDir, relative);
|
||||||
|
|
||||||
var data = util.compile(src, {
|
let data = util.compile(src, {
|
||||||
sourceFileName: slash(path.relative(dest + "/..", src)),
|
sourceFileName: slash(path.relative(dest + "/..", src)),
|
||||||
sourceMapTarget: path.basename(relative)
|
sourceMapTarget: path.basename(relative)
|
||||||
});
|
});
|
||||||
if (!commander.copyFiles && data.ignored) return;
|
if (!commander.copyFiles && data.ignored) return;
|
||||||
|
|
||||||
if (data.map && commander.sourceMaps && commander.sourceMaps !== "inline") {
|
if (data.map && commander.sourceMaps && commander.sourceMaps !== "inline") {
|
||||||
var mapLoc = dest + ".map";
|
let mapLoc = dest + ".map";
|
||||||
data.code = util.addSourceMappingUrl(data.code, mapLoc);
|
data.code = util.addSourceMappingUrl(data.code, mapLoc);
|
||||||
outputFileSync(mapLoc, JSON.stringify(data.map));
|
outputFileSync(mapLoc, JSON.stringify(data.map));
|
||||||
}
|
}
|
||||||
@ -44,13 +44,13 @@ module.exports = function (commander, filenames) {
|
|||||||
function handle(filename) {
|
function handle(filename) {
|
||||||
if (!pathExists.sync(filename)) return;
|
if (!pathExists.sync(filename)) return;
|
||||||
|
|
||||||
var stat = fs.statSync(filename);
|
let stat = fs.statSync(filename);
|
||||||
|
|
||||||
if (stat.isDirectory(filename)) {
|
if (stat.isDirectory(filename)) {
|
||||||
var dirname = filename;
|
let dirname = filename;
|
||||||
|
|
||||||
_.each(util.readdir(dirname), function (filename) {
|
_.each(util.readdir(dirname), function (filename) {
|
||||||
var src = path.join(dirname, filename);
|
let src = path.join(dirname, filename);
|
||||||
handleFile(src, filename);
|
handleFile(src, filename);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@ -62,14 +62,14 @@ module.exports = function (commander, filenames) {
|
|||||||
|
|
||||||
if (commander.watch) {
|
if (commander.watch) {
|
||||||
_.each(filenames, function (dirname) {
|
_.each(filenames, function (dirname) {
|
||||||
var watcher = chokidar.watch(dirname, {
|
let watcher = chokidar.watch(dirname, {
|
||||||
persistent: true,
|
persistent: true,
|
||||||
ignoreInitial: true
|
ignoreInitial: true
|
||||||
});
|
});
|
||||||
|
|
||||||
_.each(["add", "change"], function (type) {
|
_.each(["add", "change"], function (type) {
|
||||||
watcher.on(type, function (filename) {
|
watcher.on(type, function (filename) {
|
||||||
var relative = path.relative(dirname, filename) || filename;
|
let relative = path.relative(dirname, filename) || filename;
|
||||||
try {
|
try {
|
||||||
handleFile(filename, relative);
|
handleFile(filename, relative);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
@ -1,37 +1,37 @@
|
|||||||
var convertSourceMap = require("convert-source-map");
|
let convertSourceMap = require("convert-source-map");
|
||||||
var pathExists = require("path-exists");
|
let pathExists = require("path-exists");
|
||||||
var sourceMap = require("source-map");
|
let sourceMap = require("source-map");
|
||||||
var chokidar = require("chokidar");
|
let chokidar = require("chokidar");
|
||||||
var slash = require("slash");
|
let slash = require("slash");
|
||||||
var path = require("path");
|
let path = require("path");
|
||||||
var util = require("./util");
|
let util = require("./util");
|
||||||
var fs = require("fs");
|
let fs = require("fs");
|
||||||
var _ = require("lodash");
|
let _ = require("lodash");
|
||||||
|
|
||||||
module.exports = function (commander, filenames, opts) {
|
module.exports = function (commander, filenames, opts) {
|
||||||
if (commander.sourceMaps === "inline") {
|
if (commander.sourceMaps === "inline") {
|
||||||
opts.sourceMaps = true;
|
opts.sourceMaps = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
var results = [];
|
let results = [];
|
||||||
|
|
||||||
var buildResult = function () {
|
let buildResult = function () {
|
||||||
var map = new sourceMap.SourceMapGenerator({
|
let map = new sourceMap.SourceMapGenerator({
|
||||||
file: path.basename(commander.outFile) || "stdout",
|
file: path.basename(commander.outFile) || "stdout",
|
||||||
sourceRoot: opts.sourceRoot
|
sourceRoot: opts.sourceRoot
|
||||||
});
|
});
|
||||||
|
|
||||||
var code = "";
|
let code = "";
|
||||||
var offset = 0;
|
let offset = 0;
|
||||||
|
|
||||||
_.each(results, function (result) {
|
_.each(results, function (result) {
|
||||||
var filename = result.filename;
|
let filename = result.filename;
|
||||||
code += result.code + "\n";
|
code += result.code + "\n";
|
||||||
|
|
||||||
if (result.map) {
|
if (result.map) {
|
||||||
var consumer = new sourceMap.SourceMapConsumer(result.map);
|
let consumer = new sourceMap.SourceMapConsumer(result.map);
|
||||||
|
|
||||||
var sourceFilename = filename;
|
let sourceFilename = filename;
|
||||||
if (commander.outFile) {
|
if (commander.outFile) {
|
||||||
sourceFilename = path.relative(path.dirname(commander.outFile), sourceFilename);
|
sourceFilename = path.relative(path.dirname(commander.outFile), sourceFilename);
|
||||||
}
|
}
|
||||||
@ -64,12 +64,12 @@ module.exports = function (commander, filenames, opts) {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
var output = function () {
|
let output = function () {
|
||||||
var result = buildResult();
|
let result = buildResult();
|
||||||
|
|
||||||
if (commander.outFile) {
|
if (commander.outFile) {
|
||||||
if (commander.sourceMaps && commander.sourceMaps !== "inline") {
|
if (commander.sourceMaps && commander.sourceMaps !== "inline") {
|
||||||
var mapLoc = commander.outFile + ".map";
|
let mapLoc = commander.outFile + ".map";
|
||||||
result.code = util.addSourceMappingUrl(result.code, mapLoc);
|
result.code = util.addSourceMappingUrl(result.code, mapLoc);
|
||||||
fs.writeFileSync(mapLoc, JSON.stringify(result.map));
|
fs.writeFileSync(mapLoc, JSON.stringify(result.map));
|
||||||
}
|
}
|
||||||
@ -80,13 +80,13 @@ module.exports = function (commander, filenames, opts) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var stdin = function () {
|
let stdin = function () {
|
||||||
var code = "";
|
let code = "";
|
||||||
|
|
||||||
process.stdin.setEncoding("utf8");
|
process.stdin.setEncoding("utf8");
|
||||||
|
|
||||||
process.stdin.on("readable", function () {
|
process.stdin.on("readable", function () {
|
||||||
var chunk = process.stdin.read();
|
let chunk = process.stdin.read();
|
||||||
if (chunk !== null) code += chunk;
|
if (chunk !== null) code += chunk;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -96,16 +96,16 @@ module.exports = function (commander, filenames, opts) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
var walk = function () {
|
let walk = function () {
|
||||||
var _filenames = [];
|
let _filenames = [];
|
||||||
results = [];
|
results = [];
|
||||||
|
|
||||||
_.each(filenames, function (filename) {
|
_.each(filenames, function (filename) {
|
||||||
if (!pathExists.sync(filename)) return;
|
if (!pathExists.sync(filename)) return;
|
||||||
|
|
||||||
var stat = fs.statSync(filename);
|
let stat = fs.statSync(filename);
|
||||||
if (stat.isDirectory()) {
|
if (stat.isDirectory()) {
|
||||||
var dirname = filename;
|
let dirname = filename;
|
||||||
|
|
||||||
_.each(util.readdirFilter(filename), function (filename) {
|
_.each(util.readdirFilter(filename), function (filename) {
|
||||||
_filenames.push(path.join(dirname, filename));
|
_filenames.push(path.join(dirname, filename));
|
||||||
@ -118,7 +118,7 @@ module.exports = function (commander, filenames, opts) {
|
|||||||
_.each(_filenames, function (filename) {
|
_.each(_filenames, function (filename) {
|
||||||
if (util.shouldIgnore(filename)) return;
|
if (util.shouldIgnore(filename)) return;
|
||||||
|
|
||||||
var data = util.compile(filename);
|
let data = util.compile(filename);
|
||||||
if (data.ignored) return;
|
if (data.ignored) return;
|
||||||
results.push(data);
|
results.push(data);
|
||||||
});
|
});
|
||||||
@ -126,7 +126,7 @@ module.exports = function (commander, filenames, opts) {
|
|||||||
output();
|
output();
|
||||||
};
|
};
|
||||||
|
|
||||||
var files = function () {
|
let files = function () {
|
||||||
walk();
|
walk();
|
||||||
|
|
||||||
if (commander.watch) {
|
if (commander.watch) {
|
||||||
|
|||||||
@ -2,19 +2,19 @@
|
|||||||
|
|
||||||
require("babel-core");
|
require("babel-core");
|
||||||
|
|
||||||
var pathExists = require("path-exists");
|
let pathExists = require("path-exists");
|
||||||
var commander = require("commander");
|
let commander = require("commander");
|
||||||
var kebabCase = require("lodash/string/kebabCase");
|
let kebabCase = require("lodash/string/kebabCase");
|
||||||
var options = require("babel-core").options;
|
let options = require("babel-core").options;
|
||||||
var util = require("babel-core").util;
|
let util = require("babel-core").util;
|
||||||
var uniq = require("lodash/array/uniq");
|
let uniq = require("lodash/array/uniq");
|
||||||
var each = require("lodash/collection/each");
|
let each = require("lodash/collection/each");
|
||||||
var glob = require("glob");
|
let glob = require("glob");
|
||||||
|
|
||||||
each(options, function (option, key) {
|
each(options, function (option, key) {
|
||||||
if (option.hidden) return;
|
if (option.hidden) return;
|
||||||
|
|
||||||
var arg = kebabCase(key);
|
let arg = kebabCase(key);
|
||||||
|
|
||||||
if (option.type !== "boolean") {
|
if (option.type !== "boolean") {
|
||||||
arg += " [" + (option.type || "string") + "]";
|
arg += " [" + (option.type || "string") + "]";
|
||||||
@ -30,7 +30,7 @@ each(options, function (option, key) {
|
|||||||
arg = "-" + option.shorthand + ", " + arg;
|
arg = "-" + option.shorthand + ", " + arg;
|
||||||
}
|
}
|
||||||
|
|
||||||
var desc = [];
|
let desc = [];
|
||||||
if (option.deprecated) desc.push("[DEPRECATED] " + option.deprecated);
|
if (option.deprecated) desc.push("[DEPRECATED] " + option.deprecated);
|
||||||
if (option.description) desc.push(option.description);
|
if (option.description) desc.push(option.description);
|
||||||
|
|
||||||
@ -44,7 +44,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("-D, --copy-files", "When compiling a directory copy over non-compilable files");
|
||||||
commander.option("-q, --quiet", "Don't log anything");
|
commander.option("-q, --quiet", "Don't log anything");
|
||||||
|
|
||||||
var pkg = require("../../package.json");
|
let pkg = require("../../package.json");
|
||||||
commander.version(pkg.version + " (babel-core " + require("babel-core").version + ")");
|
commander.version(pkg.version + " (babel-core " + require("babel-core").version + ")");
|
||||||
commander.usage("[options] <files ...>");
|
commander.usage("[options] <files ...>");
|
||||||
commander.parse(process.argv);
|
commander.parse(process.argv);
|
||||||
@ -57,10 +57,10 @@ if (commander.extensions) {
|
|||||||
|
|
||||||
//
|
//
|
||||||
|
|
||||||
var errors = [];
|
let errors = [];
|
||||||
|
|
||||||
var filenames = commander.args.reduce(function (globbed, input) {
|
let filenames = commander.args.reduce(function (globbed, input) {
|
||||||
var files = glob.sync(input);
|
let files = glob.sync(input);
|
||||||
if (!files.length) files = [input];
|
if (!files.length) files = [input];
|
||||||
return globbed.concat(files);
|
return globbed.concat(files);
|
||||||
}, []);
|
}, []);
|
||||||
@ -98,7 +98,7 @@ if (errors.length) {
|
|||||||
|
|
||||||
//
|
//
|
||||||
|
|
||||||
var opts = exports.opts = {};
|
let opts = exports.opts = {};
|
||||||
|
|
||||||
each(options, function (opt, key) {
|
each(options, function (opt, key) {
|
||||||
if (commander[key] !== undefined) {
|
if (commander[key] !== undefined) {
|
||||||
@ -112,7 +112,7 @@ if (opts.only) {
|
|||||||
opts.only = util.arrayify(opts.only, util.regexify);
|
opts.only = util.arrayify(opts.only, util.regexify);
|
||||||
}
|
}
|
||||||
|
|
||||||
var fn;
|
let fn;
|
||||||
|
|
||||||
if (commander.outDir) {
|
if (commander.outDir) {
|
||||||
fn = require("./dir");
|
fn = require("./dir");
|
||||||
|
|||||||
@ -1,11 +1,11 @@
|
|||||||
var commander = require("commander");
|
let commander = require("commander");
|
||||||
var readdir = require("fs-readdir-recursive");
|
let readdir = require("fs-readdir-recursive");
|
||||||
var index = require("./index");
|
let index = require("./index");
|
||||||
var babel = require("babel-core");
|
let babel = require("babel-core");
|
||||||
var util = require("babel-core").util;
|
let util = require("babel-core").util;
|
||||||
var path = require("path");
|
let path = require("path");
|
||||||
var fs = require("fs");
|
let fs = require("fs");
|
||||||
var _ = require("lodash");
|
let _ = require("lodash");
|
||||||
|
|
||||||
exports.readdirFilter = function (filename) {
|
exports.readdirFilter = function (filename) {
|
||||||
return readdir(filename).filter(function (filename) {
|
return readdir(filename).filter(function (filename) {
|
||||||
@ -35,7 +35,7 @@ exports.transform = function (filename, code, opts) {
|
|||||||
opts.ignore = null;
|
opts.ignore = null;
|
||||||
opts.only = null;
|
opts.only = null;
|
||||||
|
|
||||||
var result = babel.transform(code, opts);
|
let result = babel.transform(code, opts);
|
||||||
result.filename = filename;
|
result.filename = filename;
|
||||||
result.actual = code;
|
result.actual = code;
|
||||||
return result;
|
return result;
|
||||||
@ -43,7 +43,7 @@ exports.transform = function (filename, code, opts) {
|
|||||||
|
|
||||||
exports.compile = function (filename, opts) {
|
exports.compile = function (filename, opts) {
|
||||||
try {
|
try {
|
||||||
var code = fs.readFileSync(filename, "utf8");
|
let code = fs.readFileSync(filename, "utf8");
|
||||||
return exports.transform(filename, code, opts);
|
return exports.transform(filename, code, opts);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (commander.watch) {
|
if (commander.watch) {
|
||||||
|
|||||||
@ -10,16 +10,16 @@ export function run(code, opts = {}) {
|
|||||||
export function load(url, callback, opts = {}, hold) {
|
export function load(url, callback, opts = {}, hold) {
|
||||||
opts.filename = opts.filename || url;
|
opts.filename = opts.filename || url;
|
||||||
|
|
||||||
var xhr = global.ActiveXObject ? new global.ActiveXObject("Microsoft.XMLHTTP") : new global.XMLHttpRequest();
|
let xhr = global.ActiveXObject ? new global.ActiveXObject("Microsoft.XMLHTTP") : new global.XMLHttpRequest();
|
||||||
xhr.open("GET", url, true);
|
xhr.open("GET", url, true);
|
||||||
if ("overrideMimeType" in xhr) xhr.overrideMimeType("text/plain");
|
if ("overrideMimeType" in xhr) xhr.overrideMimeType("text/plain");
|
||||||
|
|
||||||
xhr.onreadystatechange = function () {
|
xhr.onreadystatechange = function () {
|
||||||
if (xhr.readyState !== 4) return;
|
if (xhr.readyState !== 4) return;
|
||||||
|
|
||||||
var status = xhr.status;
|
let status = xhr.status;
|
||||||
if (status === 0 || status === 200) {
|
if (status === 0 || status === 200) {
|
||||||
var param = [xhr.responseText, opts];
|
let param = [xhr.responseText, opts];
|
||||||
if (!hold) run(param);
|
if (!hold) run(param);
|
||||||
if (callback) callback(param);
|
if (callback) callback(param);
|
||||||
} else {
|
} else {
|
||||||
@ -31,16 +31,16 @@ export function load(url, callback, opts = {}, hold) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function runScripts() {
|
function runScripts() {
|
||||||
var scripts = [];
|
let scripts = [];
|
||||||
var types = ["text/ecmascript-6", "text/6to5", "text/babel", "module"];
|
let types = ["text/ecmascript-6", "text/6to5", "text/babel", "module"];
|
||||||
var index = 0;
|
let index = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transform and execute script. Ensures correct load order.
|
* Transform and execute script. Ensures correct load order.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function exec() {
|
function exec() {
|
||||||
var param = scripts[index];
|
let param = scripts[index];
|
||||||
if (param instanceof Array) {
|
if (param instanceof Array) {
|
||||||
run(param);
|
run(param);
|
||||||
index++;
|
index++;
|
||||||
@ -53,7 +53,7 @@ function runScripts() {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
function run(script, i) {
|
function run(script, i) {
|
||||||
var opts = {};
|
let opts = {};
|
||||||
|
|
||||||
if (script.src) {
|
if (script.src) {
|
||||||
load(script.src, function (param) {
|
load(script.src, function (param) {
|
||||||
@ -68,10 +68,10 @@ function runScripts() {
|
|||||||
|
|
||||||
// Collect scripts with Babel `types`.
|
// Collect scripts with Babel `types`.
|
||||||
|
|
||||||
var _scripts = global.document.getElementsByTagName("script");
|
let _scripts = global.document.getElementsByTagName("script");
|
||||||
|
|
||||||
for (var i = 0; i < _scripts.length; ++i) {
|
for (let i = 0; i < _scripts.length; ++i) {
|
||||||
var _script = _scripts[i];
|
let _script = _scripts[i];
|
||||||
if (types.indexOf(_script.type) >= 0) scripts.push(_script);
|
if (types.indexOf(_script.type) >= 0) scripts.push(_script);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -20,7 +20,7 @@ import * as t from "babel-types";
|
|||||||
export { t as types };
|
export { t as types };
|
||||||
|
|
||||||
export function register(opts?: Object) {
|
export function register(opts?: Object) {
|
||||||
var callback = require("./register/node-polyfill");
|
let callback = require("./register/node-polyfill");
|
||||||
if (opts != null) callback(opts);
|
if (opts != null) callback(opts);
|
||||||
return callback;
|
return callback;
|
||||||
}
|
}
|
||||||
@ -36,7 +36,7 @@ export function transformFile(filename: string, opts?: Object, callback: Functio
|
|||||||
fs.readFile(filename, function (err, code) {
|
fs.readFile(filename, function (err, code) {
|
||||||
if (err) return callback(err);
|
if (err) return callback(err);
|
||||||
|
|
||||||
var result;
|
let result;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
result = transform(code, opts);
|
result = transform(code, opts);
|
||||||
@ -63,7 +63,7 @@ export function parse(code, opts = {}) {
|
|||||||
};
|
};
|
||||||
opts.features = {};
|
opts.features = {};
|
||||||
|
|
||||||
var ast = babylon.parse(code, opts);
|
let ast = babylon.parse(code, opts);
|
||||||
|
|
||||||
if (opts.onToken) {
|
if (opts.onToken) {
|
||||||
opts.onToken.push(...ast.tokens);
|
opts.onToken.push(...ast.tokens);
|
||||||
|
|||||||
@ -4,7 +4,7 @@ import homeOrTmp from "home-or-tmp";
|
|||||||
import pathExists from "path-exists";
|
import pathExists from "path-exists";
|
||||||
|
|
||||||
const FILENAME = process.env.BABEL_CACHE_PATH || path.join(homeOrTmp, ".babel.json");
|
const FILENAME = process.env.BABEL_CACHE_PATH || path.join(homeOrTmp, ".babel.json");
|
||||||
var data = {};
|
let data = {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write stringified cache to disk.
|
* Write stringified cache to disk.
|
||||||
|
|||||||
@ -15,7 +15,7 @@ import path from "path";
|
|||||||
sourceMapSupport.install({
|
sourceMapSupport.install({
|
||||||
handleUncaughtExceptions: false,
|
handleUncaughtExceptions: false,
|
||||||
retrieveSourceMap(source) {
|
retrieveSourceMap(source) {
|
||||||
var map = maps && maps[source];
|
let map = maps && maps[source];
|
||||||
if (map) {
|
if (map) {
|
||||||
return {
|
return {
|
||||||
url: null,
|
url: null,
|
||||||
@ -32,27 +32,27 @@ sourceMapSupport.install({
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
registerCache.load();
|
registerCache.load();
|
||||||
var cache = registerCache.get();
|
let cache = registerCache.get();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Store options.
|
* Store options.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var transformOpts = {};
|
let transformOpts = {};
|
||||||
|
|
||||||
var ignore;
|
let ignore;
|
||||||
var only;
|
let only;
|
||||||
|
|
||||||
var oldHandlers = {};
|
let oldHandlers = {};
|
||||||
var maps = {};
|
let maps = {};
|
||||||
|
|
||||||
var cwd = process.cwd();
|
let cwd = process.cwd();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get path from `filename` relative to the current working directory.
|
* Get path from `filename` relative to the current working directory.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var getRelativePath = function (filename){
|
let getRelativePath = function (filename){
|
||||||
return path.relative(cwd, filename);
|
return path.relative(cwd, filename);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -60,7 +60,7 @@ var getRelativePath = function (filename){
|
|||||||
* Get last modified time for a `filename`.
|
* Get last modified time for a `filename`.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var mtime = function (filename) {
|
let mtime = function (filename) {
|
||||||
return +fs.statSync(filename).mtime;
|
return +fs.statSync(filename).mtime;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -68,22 +68,22 @@ var mtime = function (filename) {
|
|||||||
* Compile a `filename` with optional `opts`.
|
* Compile a `filename` with optional `opts`.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var compile = function (filename, opts = {}) {
|
let compile = function (filename, opts = {}) {
|
||||||
var result;
|
let result;
|
||||||
|
|
||||||
opts.filename = filename;
|
opts.filename = filename;
|
||||||
|
|
||||||
var optsManager = new OptionManager;
|
let optsManager = new OptionManager;
|
||||||
optsManager.mergeOptions(transformOpts);
|
optsManager.mergeOptions(transformOpts);
|
||||||
opts = optsManager.init(opts);
|
opts = optsManager.init(opts);
|
||||||
|
|
||||||
var cacheKey = `${JSON.stringify(opts)}:${babel.version}`;
|
let cacheKey = `${JSON.stringify(opts)}:${babel.version}`;
|
||||||
|
|
||||||
var env = process.env.BABEL_ENV || process.env.NODE_ENV;
|
let env = process.env.BABEL_ENV || process.env.NODE_ENV;
|
||||||
if (env) cacheKey += `:${env}`;
|
if (env) cacheKey += `:${env}`;
|
||||||
|
|
||||||
if (cache) {
|
if (cache) {
|
||||||
var cached = cache[cacheKey];
|
let cached = cache[cacheKey];
|
||||||
if (cached && cached.mtime === mtime(filename)) {
|
if (cached && cached.mtime === mtime(filename)) {
|
||||||
result = cached;
|
result = cached;
|
||||||
}
|
}
|
||||||
@ -110,7 +110,7 @@ var compile = function (filename, opts = {}) {
|
|||||||
* Test if a `filename` should be ignored by Babel.
|
* Test if a `filename` should be ignored by Babel.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var shouldIgnore = function (filename) {
|
let shouldIgnore = function (filename) {
|
||||||
if (!ignore && !only) {
|
if (!ignore && !only) {
|
||||||
return getRelativePath(filename).split(path.sep).indexOf("node_modules") >= 0;
|
return getRelativePath(filename).split(path.sep).indexOf("node_modules") >= 0;
|
||||||
} else {
|
} else {
|
||||||
@ -122,17 +122,17 @@ var shouldIgnore = function (filename) {
|
|||||||
* Monkey patch istanbul if it is running so that it works properly.
|
* Monkey patch istanbul if it is running so that it works properly.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var istanbulMonkey = {};
|
let istanbulMonkey = {};
|
||||||
|
|
||||||
if (process.env.running_under_istanbul) {
|
if (process.env.running_under_istanbul) {
|
||||||
// we need to monkey patch fs.readFileSync so we can hook into
|
// we need to monkey patch fs.readFileSync so we can hook into
|
||||||
// what istanbul gets, it's extremely dirty but it's the only way
|
// what istanbul gets, it's extremely dirty but it's the only way
|
||||||
var _readFileSync = fs.readFileSync;
|
let _readFileSync = fs.readFileSync;
|
||||||
|
|
||||||
fs.readFileSync = function (filename) {
|
fs.readFileSync = function (filename) {
|
||||||
if (istanbulMonkey[filename]) {
|
if (istanbulMonkey[filename]) {
|
||||||
delete istanbulMonkey[filename];
|
delete istanbulMonkey[filename];
|
||||||
var code = compile(filename, {
|
let code = compile(filename, {
|
||||||
auxiliaryCommentBefore: "istanbul ignore next"
|
auxiliaryCommentBefore: "istanbul ignore next"
|
||||||
});
|
});
|
||||||
istanbulMonkey[filename] = true;
|
istanbulMonkey[filename] = true;
|
||||||
@ -147,7 +147,7 @@ if (process.env.running_under_istanbul) {
|
|||||||
* Replacement for the loader for istanbul.
|
* Replacement for the loader for istanbul.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var istanbulLoader = function (m, filename, old) {
|
let istanbulLoader = function (m, filename, old) {
|
||||||
istanbulMonkey[filename] = true;
|
istanbulMonkey[filename] = true;
|
||||||
old(m, filename);
|
old(m, filename);
|
||||||
};
|
};
|
||||||
@ -156,7 +156,7 @@ var istanbulLoader = function (m, filename, old) {
|
|||||||
* Default loader.
|
* Default loader.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var normalLoader = function (m, filename) {
|
let normalLoader = function (m, filename) {
|
||||||
m._compile(compile(filename), filename);
|
m._compile(compile(filename), filename);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -164,10 +164,10 @@ var normalLoader = function (m, filename) {
|
|||||||
* Register a loader for an extension.
|
* Register a loader for an extension.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var registerExtension = function (ext) {
|
let registerExtension = function (ext) {
|
||||||
var old = oldHandlers[ext] || oldHandlers[".js"] || require.extensions[".js"];
|
let old = oldHandlers[ext] || oldHandlers[".js"] || require.extensions[".js"];
|
||||||
|
|
||||||
var loader = normalLoader;
|
let loader = normalLoader;
|
||||||
if (process.env.running_under_istanbul) loader = istanbulLoader;
|
if (process.env.running_under_istanbul) loader = istanbulLoader;
|
||||||
|
|
||||||
require.extensions[ext] = function (m, filename) {
|
require.extensions[ext] = function (m, filename) {
|
||||||
@ -183,7 +183,7 @@ var registerExtension = function (ext) {
|
|||||||
* Register loader for given extensions.
|
* Register loader for given extensions.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var hookExtensions = function (_exts) {
|
let hookExtensions = function (_exts) {
|
||||||
each(oldHandlers, function (old, ext) {
|
each(oldHandlers, function (old, ext) {
|
||||||
if (old === undefined) {
|
if (old === undefined) {
|
||||||
delete require.extensions[ext];
|
delete require.extensions[ext];
|
||||||
|
|||||||
@ -9,8 +9,8 @@ export default function (dest, src) {
|
|||||||
|
|
||||||
return merge(dest, src, function (a, b) {
|
return merge(dest, src, function (a, b) {
|
||||||
if (b && Array.isArray(a)) {
|
if (b && Array.isArray(a)) {
|
||||||
var c = a.slice(0);
|
let c = a.slice(0);
|
||||||
for (var v of b) {
|
for (let v of b) {
|
||||||
if (a.indexOf(v) < 0) {
|
if (a.indexOf(v) < 0) {
|
||||||
c.push(v);
|
c.push(v);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,7 +5,7 @@ import * as babylon from "babylon";
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
export default function (code, opts = {}) {
|
export default function (code, opts = {}) {
|
||||||
var parseOpts = {
|
let parseOpts = {
|
||||||
allowImportExportEverywhere: opts.looseModules,
|
allowImportExportEverywhere: opts.looseModules,
|
||||||
allowReturnOutsideFunction: opts.looseModules,
|
allowReturnOutsideFunction: opts.looseModules,
|
||||||
strictMode: opts.strictMode,
|
strictMode: opts.strictMode,
|
||||||
|
|||||||
@ -11,11 +11,11 @@ export default class Store {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get(key: string): any {
|
get(key: string): any {
|
||||||
var data = this.data[key];
|
let data = this.data[key];
|
||||||
if (data) {
|
if (data) {
|
||||||
return data;
|
return data;
|
||||||
} else {
|
} else {
|
||||||
var dynamic = this.dynamicData[key];
|
let dynamic = this.dynamicData[key];
|
||||||
if (dynamic) {
|
if (dynamic) {
|
||||||
return this.set(key, dynamic());
|
return this.set(key, dynamic());
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,9 +6,9 @@ import each from "lodash/collection/each";
|
|||||||
import * as t from "babel-types";
|
import * as t from "babel-types";
|
||||||
|
|
||||||
function buildGlobal(namespace, builder) {
|
function buildGlobal(namespace, builder) {
|
||||||
var body = [];
|
let body = [];
|
||||||
var container = t.functionExpression(null, [t.identifier("global")], t.blockStatement(body));
|
let container = t.functionExpression(null, [t.identifier("global")], t.blockStatement(body));
|
||||||
var tree = t.program([t.expressionStatement(t.callExpression(container, [util.template("helper-self-global")]))]);
|
let tree = t.program([t.expressionStatement(t.callExpression(container, [util.template("helper-self-global")]))]);
|
||||||
|
|
||||||
body.push(t.variableDeclaration("var", [
|
body.push(t.variableDeclaration("var", [
|
||||||
t.variableDeclarator(
|
t.variableDeclarator(
|
||||||
@ -23,14 +23,14 @@ function buildGlobal(namespace, builder) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function buildUmd(namespace, builder) {
|
function buildUmd(namespace, builder) {
|
||||||
var body = [];
|
let body = [];
|
||||||
body.push(t.variableDeclaration("var", [
|
body.push(t.variableDeclaration("var", [
|
||||||
t.variableDeclarator(namespace, t.identifier("global"))
|
t.variableDeclarator(namespace, t.identifier("global"))
|
||||||
]));
|
]));
|
||||||
|
|
||||||
builder(body);
|
builder(body);
|
||||||
|
|
||||||
var container = util.template("umd-commonjs-strict", {
|
let container = util.template("umd-commonjs-strict", {
|
||||||
FACTORY_PARAMETERS: t.identifier("global"),
|
FACTORY_PARAMETERS: t.identifier("global"),
|
||||||
BROWSER_ARGUMENTS: t.assignmentExpression("=", t.memberExpression(t.identifier("root"), namespace), t.objectExpression({})),
|
BROWSER_ARGUMENTS: t.assignmentExpression("=", t.memberExpression(t.identifier("root"), namespace), t.objectExpression({})),
|
||||||
COMMON_ARGUMENTS: t.identifier("exports"),
|
COMMON_ARGUMENTS: t.identifier("exports"),
|
||||||
@ -42,7 +42,7 @@ function buildUmd(namespace, builder) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function buildVar(namespace, builder) {
|
function buildVar(namespace, builder) {
|
||||||
var body = [];
|
let body = [];
|
||||||
body.push(t.variableDeclaration("var", [
|
body.push(t.variableDeclaration("var", [
|
||||||
t.variableDeclarator(namespace, t.objectExpression({}))
|
t.variableDeclarator(namespace, t.objectExpression({}))
|
||||||
]));
|
]));
|
||||||
@ -54,7 +54,7 @@ function buildHelpers(body, namespace, whitelist) {
|
|||||||
each(File.helpers, function (name) {
|
each(File.helpers, function (name) {
|
||||||
if (whitelist && whitelist.indexOf(name) === -1) return;
|
if (whitelist && whitelist.indexOf(name) === -1) return;
|
||||||
|
|
||||||
var key = t.identifier(t.toIdentifier(name));
|
let key = t.identifier(t.toIdentifier(name));
|
||||||
body.push(t.expressionStatement(
|
body.push(t.expressionStatement(
|
||||||
t.assignmentExpression("=", t.memberExpression(namespace, key), util.template("helper-" + name))
|
t.assignmentExpression("=", t.memberExpression(namespace, key), util.template("helper-" + name))
|
||||||
));
|
));
|
||||||
@ -62,15 +62,15 @@ function buildHelpers(body, namespace, whitelist) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function (whitelist, outputType = "global") {
|
export default function (whitelist, outputType = "global") {
|
||||||
var namespace = t.identifier("babelHelpers");
|
let namespace = t.identifier("babelHelpers");
|
||||||
|
|
||||||
var builder = function (body) {
|
let builder = function (body) {
|
||||||
return buildHelpers(body, namespace, whitelist);
|
return buildHelpers(body, namespace, whitelist);
|
||||||
};
|
};
|
||||||
|
|
||||||
var tree;
|
let tree;
|
||||||
|
|
||||||
var build = {
|
let build = {
|
||||||
global: buildGlobal,
|
global: buildGlobal,
|
||||||
umd: buildUmd,
|
umd: buildUmd,
|
||||||
var: buildVar
|
var: buildVar
|
||||||
|
|||||||
@ -21,9 +21,9 @@ import * as util from "../../util";
|
|||||||
import path from "path";
|
import path from "path";
|
||||||
import * as t from "babel-types";
|
import * as t from "babel-types";
|
||||||
|
|
||||||
var errorVisitor = {
|
let errorVisitor = {
|
||||||
enter(path, state) {
|
enter(path, state) {
|
||||||
var loc = path.node.loc;
|
let loc = path.node.loc;
|
||||||
if (loc) {
|
if (loc) {
|
||||||
state.loc = loc;
|
state.loc = loc;
|
||||||
path.stop();
|
path.stop();
|
||||||
@ -155,16 +155,16 @@ export default class File extends Store {
|
|||||||
}
|
}
|
||||||
|
|
||||||
buildTransformers() {
|
buildTransformers() {
|
||||||
var file = this;
|
let file = this;
|
||||||
|
|
||||||
var transformers = this.transformers = {};
|
let transformers = this.transformers = {};
|
||||||
|
|
||||||
var secondaryStack = [];
|
let secondaryStack = [];
|
||||||
var stack = [];
|
let stack = [];
|
||||||
|
|
||||||
// build internal transformers
|
// build internal transformers
|
||||||
for (var key in this.pipeline.transformers) {
|
for (let key in this.pipeline.transformers) {
|
||||||
var transformer = this.pipeline.transformers[key];
|
let transformer = this.pipeline.transformers[key];
|
||||||
let pass = transformers[key] = transformer.buildPass(file);
|
let pass = transformers[key] = transformer.buildPass(file);
|
||||||
|
|
||||||
if (pass.canTransform()) {
|
if (pass.canTransform()) {
|
||||||
@ -181,15 +181,15 @@ export default class File extends Store {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// init plugins!
|
// init plugins!
|
||||||
var beforePlugins = [];
|
let beforePlugins = [];
|
||||||
var afterPlugins = [];
|
let afterPlugins = [];
|
||||||
var pluginManager = new PluginManager({
|
let pluginManager = new PluginManager({
|
||||||
file: this,
|
file: this,
|
||||||
transformers: this.transformers,
|
transformers: this.transformers,
|
||||||
before: beforePlugins,
|
before: beforePlugins,
|
||||||
after: afterPlugins
|
after: afterPlugins
|
||||||
});
|
});
|
||||||
for (var i = 0; i < file.opts.plugins.length; i++) {
|
for (let i = 0; i < file.opts.plugins.length; i++) {
|
||||||
pluginManager.add(file.opts.plugins[i]);
|
pluginManager.add(file.opts.plugins[i]);
|
||||||
}
|
}
|
||||||
stack = beforePlugins.concat(stack, afterPlugins);
|
stack = beforePlugins.concat(stack, afterPlugins);
|
||||||
@ -199,7 +199,7 @@ export default class File extends Store {
|
|||||||
|
|
||||||
// build dependency graph
|
// build dependency graph
|
||||||
for (let pass of (stack: Array)) {
|
for (let pass of (stack: Array)) {
|
||||||
for (var dep of (pass.plugin.dependencies: Array)) {
|
for (let dep of (pass.plugin.dependencies: Array)) {
|
||||||
this.transformerDependencies[dep] = pass.key;
|
this.transformerDependencies[dep] = pass.key;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -209,14 +209,14 @@ export default class File extends Store {
|
|||||||
}
|
}
|
||||||
|
|
||||||
collapseStack(_stack) {
|
collapseStack(_stack) {
|
||||||
var stack = [];
|
let stack = [];
|
||||||
var ignore = [];
|
let ignore = [];
|
||||||
|
|
||||||
for (let pass of (_stack: Array)) {
|
for (let pass of (_stack: Array)) {
|
||||||
// been merged
|
// been merged
|
||||||
if (ignore.indexOf(pass) >= 0) continue;
|
if (ignore.indexOf(pass) >= 0) continue;
|
||||||
|
|
||||||
var group = pass.plugin.metadata.group;
|
let group = pass.plugin.metadata.group;
|
||||||
|
|
||||||
// can't merge
|
// can't merge
|
||||||
if (!pass.canTransform() || !group) {
|
if (!pass.canTransform() || !group) {
|
||||||
@ -224,7 +224,7 @@ export default class File extends Store {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
var mergeStack = [];
|
let mergeStack = [];
|
||||||
for (let pass of (_stack: Array)) {
|
for (let pass of (_stack: Array)) {
|
||||||
if (pass.plugin.metadata.group === group) {
|
if (pass.plugin.metadata.group === group) {
|
||||||
mergeStack.push(pass);
|
mergeStack.push(pass);
|
||||||
@ -236,12 +236,12 @@ export default class File extends Store {
|
|||||||
shuffle;
|
shuffle;
|
||||||
//mergeStack = shuffle(mergeStack);
|
//mergeStack = shuffle(mergeStack);
|
||||||
|
|
||||||
var visitors = [];
|
let visitors = [];
|
||||||
for (let pass of (mergeStack: Array)) {
|
for (let pass of (mergeStack: Array)) {
|
||||||
visitors.push(pass.plugin.visitor);
|
visitors.push(pass.plugin.visitor);
|
||||||
}
|
}
|
||||||
var visitor = traverse.visitors.merge(visitors);
|
let visitor = traverse.visitors.merge(visitors);
|
||||||
var mergePlugin = new Plugin(group, { visitor });
|
let mergePlugin = new Plugin(group, { visitor });
|
||||||
stack.push(mergePlugin.buildPass(this));
|
stack.push(mergePlugin.buildPass(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -257,11 +257,11 @@ export default class File extends Store {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get(key: string): any {
|
get(key: string): any {
|
||||||
var data = this.data[key];
|
let data = this.data[key];
|
||||||
if (data) {
|
if (data) {
|
||||||
return data;
|
return data;
|
||||||
} else {
|
} else {
|
||||||
var dynamic = this.dynamicData[key];
|
let dynamic = this.dynamicData[key];
|
||||||
if (dynamic) {
|
if (dynamic) {
|
||||||
return this.set(key, dynamic());
|
return this.set(key, dynamic());
|
||||||
}
|
}
|
||||||
@ -269,25 +269,25 @@ export default class File extends Store {
|
|||||||
}
|
}
|
||||||
|
|
||||||
resolveModuleSource(source: string): string {
|
resolveModuleSource(source: string): string {
|
||||||
var resolveModuleSource = this.opts.resolveModuleSource;
|
let resolveModuleSource = this.opts.resolveModuleSource;
|
||||||
if (resolveModuleSource) source = resolveModuleSource(source, this.opts.filename);
|
if (resolveModuleSource) source = resolveModuleSource(source, this.opts.filename);
|
||||||
return source;
|
return source;
|
||||||
}
|
}
|
||||||
|
|
||||||
addImport(source: string, name?: string, type?: string): Object {
|
addImport(source: string, name?: string, type?: string): Object {
|
||||||
name = name || source;
|
name = name || source;
|
||||||
var id = this.dynamicImportIds[name];
|
let id = this.dynamicImportIds[name];
|
||||||
|
|
||||||
if (!id) {
|
if (!id) {
|
||||||
source = this.resolveModuleSource(source);
|
source = this.resolveModuleSource(source);
|
||||||
id = this.dynamicImportIds[name] = this.scope.generateUidIdentifier(name);
|
id = this.dynamicImportIds[name] = this.scope.generateUidIdentifier(name);
|
||||||
|
|
||||||
var specifiers = [t.importDefaultSpecifier(id)];
|
let specifiers = [t.importDefaultSpecifier(id)];
|
||||||
var declar = t.importDeclaration(specifiers, t.stringLiteral(source));
|
let declar = t.importDeclaration(specifiers, t.stringLiteral(source));
|
||||||
declar._blockHoist = 3;
|
declar._blockHoist = 3;
|
||||||
|
|
||||||
if (type) {
|
if (type) {
|
||||||
var modules = this.dynamicImportTypes[type] = this.dynamicImportTypes[type] || [];
|
let modules = this.dynamicImportTypes[type] = this.dynamicImportTypes[type] || [];
|
||||||
modules.push(declar);
|
modules.push(declar);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -303,7 +303,7 @@ export default class File extends Store {
|
|||||||
}
|
}
|
||||||
|
|
||||||
attachAuxiliaryComment(node: Object): Object {
|
attachAuxiliaryComment(node: Object): Object {
|
||||||
var beforeComment = this.opts.auxiliaryCommentBefore;
|
let beforeComment = this.opts.auxiliaryCommentBefore;
|
||||||
if (beforeComment) {
|
if (beforeComment) {
|
||||||
node.leadingComments = node.leadingComments || [];
|
node.leadingComments = node.leadingComments || [];
|
||||||
node.leadingComments.push({
|
node.leadingComments.push({
|
||||||
@ -312,7 +312,7 @@ export default class File extends Store {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
var afterComment = this.opts.auxiliaryCommentAfter;
|
let afterComment = this.opts.auxiliaryCommentAfter;
|
||||||
if (afterComment) {
|
if (afterComment) {
|
||||||
node.trailingComments = node.trailingComments || [];
|
node.trailingComments = node.trailingComments || [];
|
||||||
node.trailingComments.push({
|
node.trailingComments.push({
|
||||||
@ -325,31 +325,31 @@ export default class File extends Store {
|
|||||||
}
|
}
|
||||||
|
|
||||||
addHelper(name: string): Object {
|
addHelper(name: string): Object {
|
||||||
var isSolo = includes(File.soloHelpers, name);
|
let isSolo = includes(File.soloHelpers, name);
|
||||||
|
|
||||||
if (!isSolo && !includes(File.helpers, name)) {
|
if (!isSolo && !includes(File.helpers, name)) {
|
||||||
throw new ReferenceError(`Unknown helper ${name}`);
|
throw new ReferenceError(`Unknown helper ${name}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
var declar = this.declarations[name];
|
let declar = this.declarations[name];
|
||||||
if (declar) return declar;
|
if (declar) return declar;
|
||||||
|
|
||||||
this.usedHelpers[name] = true;
|
this.usedHelpers[name] = true;
|
||||||
|
|
||||||
if (!isSolo) {
|
if (!isSolo) {
|
||||||
var generator = this.get("helperGenerator");
|
let generator = this.get("helperGenerator");
|
||||||
var runtime = this.get("helpersNamespace");
|
let runtime = this.get("helpersNamespace");
|
||||||
if (generator) {
|
if (generator) {
|
||||||
return generator(name);
|
return generator(name);
|
||||||
} else if (runtime) {
|
} else if (runtime) {
|
||||||
var id = t.identifier(t.toIdentifier(name));
|
let id = t.identifier(t.toIdentifier(name));
|
||||||
return t.memberExpression(runtime, id);
|
return t.memberExpression(runtime, id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var ref = util.template("helper-" + name);
|
let ref = util.template("helper-" + name);
|
||||||
|
|
||||||
var uid = this.declarations[name] = this.scope.generateUidIdentifier(name);
|
let uid = this.declarations[name] = this.scope.generateUidIdentifier(name);
|
||||||
|
|
||||||
if (t.isFunctionExpression(ref) && !ref.id) {
|
if (t.isFunctionExpression(ref) && !ref.id) {
|
||||||
ref.body._compact = true;
|
ref.body._compact = true;
|
||||||
@ -373,18 +373,18 @@ export default class File extends Store {
|
|||||||
addTemplateObject(helperName: string, strings: Array, raw: Array): Object {
|
addTemplateObject(helperName: string, strings: Array, raw: Array): Object {
|
||||||
// Generate a unique name based on the string literals so we dedupe
|
// Generate a unique name based on the string literals so we dedupe
|
||||||
// identical strings used in the program.
|
// identical strings used in the program.
|
||||||
var stringIds = raw.elements.map(function(string) {
|
let stringIds = raw.elements.map(function(string) {
|
||||||
return string.value;
|
return string.value;
|
||||||
});
|
});
|
||||||
var name = `${helperName}_${raw.elements.length}_${stringIds.join(",")}`;
|
let name = `${helperName}_${raw.elements.length}_${stringIds.join(",")}`;
|
||||||
|
|
||||||
var declar = this.declarations[name];
|
let declar = this.declarations[name];
|
||||||
if (declar) return declar;
|
if (declar) return declar;
|
||||||
|
|
||||||
var uid = this.declarations[name] = this.scope.generateUidIdentifier("templateObject");
|
let uid = this.declarations[name] = this.scope.generateUidIdentifier("templateObject");
|
||||||
|
|
||||||
var helperId = this.addHelper(helperName);
|
let helperId = this.addHelper(helperName);
|
||||||
var init = t.callExpression(helperId, [strings, raw]);
|
let init = t.callExpression(helperId, [strings, raw]);
|
||||||
init._compact = true;
|
init._compact = true;
|
||||||
this.scope.push({
|
this.scope.push({
|
||||||
id: uid,
|
id: uid,
|
||||||
@ -395,9 +395,9 @@ export default class File extends Store {
|
|||||||
}
|
}
|
||||||
|
|
||||||
buildCodeFrameError(node, msg, Error = SyntaxError) {
|
buildCodeFrameError(node, msg, Error = SyntaxError) {
|
||||||
var loc = node && (node.loc || node._loc);
|
let loc = node && (node.loc || node._loc);
|
||||||
|
|
||||||
var err = new Error(msg);
|
let err = new Error(msg);
|
||||||
|
|
||||||
if (loc) {
|
if (loc) {
|
||||||
err.loc = loc.start;
|
err.loc = loc.start;
|
||||||
@ -417,19 +417,19 @@ export default class File extends Store {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mergeSourceMap(map: Object) {
|
mergeSourceMap(map: Object) {
|
||||||
var opts = this.opts;
|
let opts = this.opts;
|
||||||
|
|
||||||
var inputMap = opts.inputSourceMap;
|
let inputMap = opts.inputSourceMap;
|
||||||
|
|
||||||
if (inputMap) {
|
if (inputMap) {
|
||||||
map.sources[0] = inputMap.file;
|
map.sources[0] = inputMap.file;
|
||||||
|
|
||||||
var inputMapConsumer = new sourceMap.SourceMapConsumer(inputMap);
|
let inputMapConsumer = new sourceMap.SourceMapConsumer(inputMap);
|
||||||
var outputMapConsumer = new sourceMap.SourceMapConsumer(map);
|
let outputMapConsumer = new sourceMap.SourceMapConsumer(map);
|
||||||
var outputMapGenerator = sourceMap.SourceMapGenerator.fromSourceMap(outputMapConsumer);
|
let outputMapGenerator = sourceMap.SourceMapGenerator.fromSourceMap(outputMapConsumer);
|
||||||
outputMapGenerator.applySourceMap(inputMapConsumer);
|
outputMapGenerator.applySourceMap(inputMapConsumer);
|
||||||
|
|
||||||
var mergedMap = outputMapGenerator.toJSON();
|
let mergedMap = outputMapGenerator.toJSON();
|
||||||
mergedMap.sources = inputMap.sources;
|
mergedMap.sources = inputMap.sources;
|
||||||
mergedMap.file = inputMap.file;
|
mergedMap.file = inputMap.file;
|
||||||
return mergedMap;
|
return mergedMap;
|
||||||
@ -443,10 +443,10 @@ export default class File extends Store {
|
|||||||
this.log.deprecate("Custom module formatters are deprecated and will be removed in the next major. Please use Babel plugins instead.");
|
this.log.deprecate("Custom module formatters are deprecated and will be removed in the next major. Please use Babel plugins instead.");
|
||||||
}
|
}
|
||||||
|
|
||||||
var ModuleFormatter = isFunction(type) ? type : moduleFormatters[type];
|
let ModuleFormatter = isFunction(type) ? type : moduleFormatters[type];
|
||||||
|
|
||||||
if (!ModuleFormatter) {
|
if (!ModuleFormatter) {
|
||||||
var loc = resolve.relative(type);
|
let loc = resolve.relative(type);
|
||||||
if (loc) ModuleFormatter = require(loc);
|
if (loc) ModuleFormatter = require(loc);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -458,11 +458,11 @@ export default class File extends Store {
|
|||||||
}
|
}
|
||||||
|
|
||||||
parse(code: string) {
|
parse(code: string) {
|
||||||
var opts = this.opts;
|
let opts = this.opts;
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
||||||
var parseOpts = {
|
let parseOpts = {
|
||||||
highlightCode: opts.highlightCode,
|
highlightCode: opts.highlightCode,
|
||||||
nonStandard: opts.nonStandard,
|
nonStandard: opts.nonStandard,
|
||||||
sourceType: opts.sourceType,
|
sourceType: opts.sourceType,
|
||||||
@ -470,9 +470,9 @@ export default class File extends Store {
|
|||||||
plugins: {}
|
plugins: {}
|
||||||
};
|
};
|
||||||
|
|
||||||
var features = parseOpts.features = {};
|
let features = parseOpts.features = {};
|
||||||
for (var key in this.transformers) {
|
for (let key in this.transformers) {
|
||||||
var transformer = this.transformers[key];
|
let transformer = this.transformers[key];
|
||||||
features[key] = transformer.canRun();
|
features[key] = transformer.canRun();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -480,7 +480,7 @@ export default class File extends Store {
|
|||||||
parseOpts.strictMode = features.strict;
|
parseOpts.strictMode = features.strict;
|
||||||
|
|
||||||
this.log.debug("Parse start");
|
this.log.debug("Parse start");
|
||||||
var ast = parse(code, parseOpts);
|
let ast = parse(code, parseOpts);
|
||||||
this.log.debug("Parse stop");
|
this.log.debug("Parse stop");
|
||||||
return ast;
|
return ast;
|
||||||
}
|
}
|
||||||
@ -503,7 +503,7 @@ export default class File extends Store {
|
|||||||
this.log.debug("End set AST");
|
this.log.debug("End set AST");
|
||||||
|
|
||||||
this.log.debug("Start module formatter init");
|
this.log.debug("Start module formatter init");
|
||||||
var modFormatter = this.moduleFormatter = this.getModuleFormatter(this.opts.modules);
|
let modFormatter = this.moduleFormatter = this.getModuleFormatter(this.opts.modules);
|
||||||
if (modFormatter.init && this.transformers["es6.modules"].canTransform()) {
|
if (modFormatter.init && this.transformers["es6.modules"].canTransform()) {
|
||||||
modFormatter.init();
|
modFormatter.init();
|
||||||
}
|
}
|
||||||
@ -512,7 +512,7 @@ export default class File extends Store {
|
|||||||
|
|
||||||
transform() {
|
transform() {
|
||||||
this.call("pre");
|
this.call("pre");
|
||||||
for (var pass of (this.transformerStack: Array)) {
|
for (let pass of (this.transformerStack: Array)) {
|
||||||
pass.transform();
|
pass.transform();
|
||||||
}
|
}
|
||||||
this.call("post");
|
this.call("post");
|
||||||
@ -536,9 +536,9 @@ export default class File extends Store {
|
|||||||
err._babel = true;
|
err._babel = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
var message = err.message = `${this.opts.filename}: ${err.message}`;
|
let message = err.message = `${this.opts.filename}: ${err.message}`;
|
||||||
|
|
||||||
var loc = err.loc;
|
let loc = err.loc;
|
||||||
if (loc) {
|
if (loc) {
|
||||||
err.codeFrame = codeFrame(code, loc.line, loc.column + 1, this.opts);
|
err.codeFrame = codeFrame(code, loc.line, loc.column + 1, this.opts);
|
||||||
message += "\n" + err.codeFrame;
|
message += "\n" + err.codeFrame;
|
||||||
@ -551,7 +551,7 @@ export default class File extends Store {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (err.stack) {
|
if (err.stack) {
|
||||||
var newStack = err.stack.replace(err.message, message);
|
let newStack = err.stack.replace(err.message, message);
|
||||||
try {
|
try {
|
||||||
err.stack = newStack;
|
err.stack = newStack;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -571,27 +571,27 @@ export default class File extends Store {
|
|||||||
|
|
||||||
parseCode() {
|
parseCode() {
|
||||||
this.parseShebang();
|
this.parseShebang();
|
||||||
var ast = this.parse(this.code);
|
let ast = this.parse(this.code);
|
||||||
this.addAst(ast);
|
this.addAst(ast);
|
||||||
}
|
}
|
||||||
|
|
||||||
shouldIgnore() {
|
shouldIgnore() {
|
||||||
var opts = this.opts;
|
let opts = this.opts;
|
||||||
return util.shouldIgnore(opts.filename, opts.ignore, opts.only);
|
return util.shouldIgnore(opts.filename, opts.ignore, opts.only);
|
||||||
}
|
}
|
||||||
|
|
||||||
call(key: string) {
|
call(key: string) {
|
||||||
for (var pass of (this.uncollapsedTransformerStack: Array)) {
|
for (let pass of (this.uncollapsedTransformerStack: Array)) {
|
||||||
var fn = pass.plugin[key];
|
let fn = pass.plugin[key];
|
||||||
if (fn) fn.call(pass, this);
|
if (fn) fn.call(pass, this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
parseInputSourceMap(code: string) {
|
parseInputSourceMap(code: string) {
|
||||||
var opts = this.opts;
|
let opts = this.opts;
|
||||||
|
|
||||||
if (opts.inputSourceMap !== false) {
|
if (opts.inputSourceMap !== false) {
|
||||||
var inputMap = convertSourceMap.fromSource(code);
|
let inputMap = convertSourceMap.fromSource(code);
|
||||||
if (inputMap) {
|
if (inputMap) {
|
||||||
opts.inputSourceMap = inputMap.toObject();
|
opts.inputSourceMap = inputMap.toObject();
|
||||||
code = convertSourceMap.removeComments(code);
|
code = convertSourceMap.removeComments(code);
|
||||||
@ -602,7 +602,7 @@ export default class File extends Store {
|
|||||||
}
|
}
|
||||||
|
|
||||||
parseShebang() {
|
parseShebang() {
|
||||||
var shebangMatch = shebangRegex.exec(this.code);
|
let shebangMatch = shebangRegex.exec(this.code);
|
||||||
if (shebangMatch) {
|
if (shebangMatch) {
|
||||||
this.shebang = shebangMatch[0];
|
this.shebang = shebangMatch[0];
|
||||||
this.code = this.code.replace(shebangRegex, "");
|
this.code = this.code.replace(shebangRegex, "");
|
||||||
@ -610,7 +610,7 @@ export default class File extends Store {
|
|||||||
}
|
}
|
||||||
|
|
||||||
makeResult({ code, map = null, ast, ignored }) {
|
makeResult({ code, map = null, ast, ignored }) {
|
||||||
var result = {
|
let result = {
|
||||||
metadata: null,
|
metadata: null,
|
||||||
ignored: !!ignored,
|
ignored: !!ignored,
|
||||||
code: null,
|
code: null,
|
||||||
@ -635,15 +635,15 @@ export default class File extends Store {
|
|||||||
}
|
}
|
||||||
|
|
||||||
generate() {
|
generate() {
|
||||||
var opts = this.opts;
|
let opts = this.opts;
|
||||||
var ast = this.ast;
|
let ast = this.ast;
|
||||||
|
|
||||||
var result = { ast };
|
let result = { ast };
|
||||||
if (!opts.code) return this.makeResult(result);
|
if (!opts.code) return this.makeResult(result);
|
||||||
|
|
||||||
this.log.debug("Generation start");
|
this.log.debug("Generation start");
|
||||||
|
|
||||||
var _result = generate(ast, opts, this.code);
|
let _result = generate(ast, opts, this.code);
|
||||||
result.code = _result.code;
|
result.code = _result.code;
|
||||||
result.map = _result.map;
|
result.map = _result.map;
|
||||||
|
|
||||||
|
|||||||
@ -1,10 +1,10 @@
|
|||||||
import type File from "./index";
|
import type File from "./index";
|
||||||
import buildDebug from "debug/node";
|
import buildDebug from "debug/node";
|
||||||
|
|
||||||
var verboseDebug = buildDebug("babel:verbose");
|
let verboseDebug = buildDebug("babel:verbose");
|
||||||
var generalDebug = buildDebug("babel");
|
let generalDebug = buildDebug("babel");
|
||||||
|
|
||||||
var seenDeprecatedMessages = [];
|
let seenDeprecatedMessages = [];
|
||||||
|
|
||||||
export default class Logger {
|
export default class Logger {
|
||||||
constructor(file: File, filename: string) {
|
constructor(file: File, filename: string) {
|
||||||
@ -13,7 +13,7 @@ export default class Logger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_buildMessage(msg: string): string {
|
_buildMessage(msg: string): string {
|
||||||
var parts = `[BABEL] ${this.filename}`;
|
let parts = `[BABEL] ${this.filename}`;
|
||||||
if (msg) parts += `: ${msg}`;
|
if (msg) parts += `: ${msg}`;
|
||||||
return parts;
|
return parts;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,8 +8,8 @@ export { config };
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
export function validateOption(key, val, pipeline) {
|
export function validateOption(key, val, pipeline) {
|
||||||
var opt = config[key];
|
let opt = config[key];
|
||||||
var parser = opt && parsers[opt.type];
|
let parser = opt && parsers[opt.type];
|
||||||
if (parser && parser.validate) {
|
if (parser && parser.validate) {
|
||||||
return parser.validate(key, val, pipeline);
|
return parser.validate(key, val, pipeline);
|
||||||
} else {
|
} else {
|
||||||
@ -22,14 +22,14 @@ export function validateOption(key, val, pipeline) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
export function normaliseOptions(options = {}) {
|
export function normaliseOptions(options = {}) {
|
||||||
for (var key in options) {
|
for (let key in options) {
|
||||||
var val = options[key];
|
let val = options[key];
|
||||||
if (val == null) continue;
|
if (val == null) continue;
|
||||||
|
|
||||||
var opt = config[key];
|
let opt = config[key];
|
||||||
if (!opt) continue;
|
if (!opt) continue;
|
||||||
|
|
||||||
var parser = parsers[opt.type];
|
let parser = parsers[opt.type];
|
||||||
if (parser) val = parser(val);
|
if (parser) val = parser(val);
|
||||||
|
|
||||||
options[key] = val;
|
options[key] = val;
|
||||||
|
|||||||
@ -12,15 +12,15 @@ import config from "./config";
|
|||||||
import path from "path";
|
import path from "path";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
|
|
||||||
var existsCache = {};
|
let existsCache = {};
|
||||||
var jsonCache = {};
|
let jsonCache = {};
|
||||||
|
|
||||||
const BABELIGNORE_FILENAME = ".babelignore";
|
const BABELIGNORE_FILENAME = ".babelignore";
|
||||||
const BABELRC_FILENAME = ".babelrc";
|
const BABELRC_FILENAME = ".babelrc";
|
||||||
const PACKAGE_FILENAME = "package.json";
|
const PACKAGE_FILENAME = "package.json";
|
||||||
|
|
||||||
function exists(filename) {
|
function exists(filename) {
|
||||||
var cached = existsCache[filename];
|
let cached = existsCache[filename];
|
||||||
if (cached != null) {
|
if (cached != null) {
|
||||||
return cached;
|
return cached;
|
||||||
} else {
|
} else {
|
||||||
@ -39,14 +39,14 @@ export default class OptionManager {
|
|||||||
static memoisedPlugins = [];
|
static memoisedPlugins = [];
|
||||||
|
|
||||||
static memoisePluginContainer(fn, loc, i) {
|
static memoisePluginContainer(fn, loc, i) {
|
||||||
for (var cache of (OptionManager.memoisedPlugins: Array)) {
|
for (let cache of (OptionManager.memoisedPlugins: Array)) {
|
||||||
if (cache.container === fn) return cache.plugin;
|
if (cache.container === fn) return cache.plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
var obj = fn(context);
|
let obj = fn(context);
|
||||||
|
|
||||||
if (typeof obj === "object") {
|
if (typeof obj === "object") {
|
||||||
var plugin = new Plugin(obj);
|
let plugin = new Plugin(obj);
|
||||||
OptionManager.memoisedPlugins.push({
|
OptionManager.memoisedPlugins.push({
|
||||||
container: fn,
|
container: fn,
|
||||||
plugin: plugin
|
plugin: plugin
|
||||||
@ -58,10 +58,10 @@ export default class OptionManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static createBareOptions() {
|
static createBareOptions() {
|
||||||
var opts = {};
|
let opts = {};
|
||||||
|
|
||||||
for (var key in config) {
|
for (let key in config) {
|
||||||
var opt = config[key];
|
let opt = config[key];
|
||||||
opts[key] = clone(opt.default);
|
opts[key] = clone(opt.default);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,7 +70,7 @@ export default class OptionManager {
|
|||||||
|
|
||||||
static normalisePlugins(loc, dirname, plugins) {
|
static normalisePlugins(loc, dirname, plugins) {
|
||||||
return plugins.map(function (val, i) {
|
return plugins.map(function (val, i) {
|
||||||
var plugin, options;
|
let plugin, options;
|
||||||
|
|
||||||
// destructure plugins
|
// destructure plugins
|
||||||
if (Array.isArray(val)) {
|
if (Array.isArray(val)) {
|
||||||
@ -81,7 +81,7 @@ export default class OptionManager {
|
|||||||
|
|
||||||
// allow plugins to be specified as strings
|
// allow plugins to be specified as strings
|
||||||
if (typeof plugin === "string") {
|
if (typeof plugin === "string") {
|
||||||
var pluginLoc = resolve(`babel-plugin-${plugin}`, dirname) || resolve(plugin, dirname);
|
let pluginLoc = resolve(`babel-plugin-${plugin}`, dirname) || resolve(plugin, dirname);
|
||||||
if (pluginLoc) {
|
if (pluginLoc) {
|
||||||
plugin = require(pluginLoc);
|
plugin = require(pluginLoc);
|
||||||
} else {
|
} else {
|
||||||
@ -106,8 +106,8 @@ export default class OptionManager {
|
|||||||
addConfig(loc, key?, json=json5) {
|
addConfig(loc, key?, json=json5) {
|
||||||
if (this.resolvedConfigs.indexOf(loc) >= 0) return;
|
if (this.resolvedConfigs.indexOf(loc) >= 0) return;
|
||||||
|
|
||||||
var content = fs.readFileSync(loc, "utf8");
|
let content = fs.readFileSync(loc, "utf8");
|
||||||
var opts;
|
let opts;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
opts = jsonCache[content] = jsonCache[content] || json.parse(content);
|
opts = jsonCache[content] = jsonCache[content] || json.parse(content);
|
||||||
@ -163,8 +163,8 @@ export default class OptionManager {
|
|||||||
delete opts.presets;
|
delete opts.presets;
|
||||||
}
|
}
|
||||||
|
|
||||||
var envOpts;
|
let envOpts;
|
||||||
var envKey = process.env.BABEL_ENV || process.env.NODE_ENV || "development";
|
let envKey = process.env.BABEL_ENV || process.env.NODE_ENV || "development";
|
||||||
if (opts.env) {
|
if (opts.env) {
|
||||||
envOpts = opts.env[envKey];
|
envOpts = opts.env[envKey];
|
||||||
delete opts.env;
|
delete opts.env;
|
||||||
@ -178,11 +178,11 @@ export default class OptionManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mergePresets(presets: Array, dirname) {
|
mergePresets(presets: Array, dirname) {
|
||||||
for (var val of presets) {
|
for (let val of presets) {
|
||||||
if (typeof val === "string") {
|
if (typeof val === "string") {
|
||||||
var presetLoc = resolve(`babel-preset-${val}`, dirname) || resolve(val, dirname);
|
let presetLoc = resolve(`babel-preset-${val}`, dirname) || resolve(val, dirname);
|
||||||
if (presetLoc) {
|
if (presetLoc) {
|
||||||
var presetOpts = require(presetLoc);
|
let presetOpts = require(presetLoc);
|
||||||
this.mergeOptions(presetOpts, presetLoc, presetLoc, path.dirname(presetLoc));
|
this.mergeOptions(presetOpts, presetLoc, presetLoc, path.dirname(presetLoc));
|
||||||
} else {
|
} else {
|
||||||
throw new Error("todo");
|
throw new Error("todo");
|
||||||
@ -196,8 +196,8 @@ export default class OptionManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
addIgnoreConfig(loc) {
|
addIgnoreConfig(loc) {
|
||||||
var file = fs.readFileSync(loc, "utf8");
|
let file = fs.readFileSync(loc, "utf8");
|
||||||
var lines = file.split("\n");
|
let lines = file.split("\n");
|
||||||
|
|
||||||
lines = lines.map(function (line) {
|
lines = lines.map(function (line) {
|
||||||
return line.replace(/#(.*?)$/, "").trim();
|
return line.replace(/#(.*?)$/, "").trim();
|
||||||
@ -213,18 +213,18 @@ export default class OptionManager {
|
|||||||
loc = path.join(process.cwd(), loc);
|
loc = path.join(process.cwd(), loc);
|
||||||
}
|
}
|
||||||
|
|
||||||
var foundConfig = false;
|
let foundConfig = false;
|
||||||
var foundIgnore = false;
|
let foundIgnore = false;
|
||||||
|
|
||||||
while (loc !== (loc = path.dirname(loc))) {
|
while (loc !== (loc = path.dirname(loc))) {
|
||||||
if (!foundConfig) {
|
if (!foundConfig) {
|
||||||
var configLoc = path.join(loc, BABELRC_FILENAME);
|
let configLoc = path.join(loc, BABELRC_FILENAME);
|
||||||
if (exists(configLoc)) {
|
if (exists(configLoc)) {
|
||||||
this.addConfig(configLoc);
|
this.addConfig(configLoc);
|
||||||
foundConfig = true;
|
foundConfig = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
var pkgLoc = path.join(loc, PACKAGE_FILENAME);
|
let pkgLoc = path.join(loc, PACKAGE_FILENAME);
|
||||||
if (exists(pkgLoc)) {
|
if (exists(pkgLoc)) {
|
||||||
this.addConfig(pkgLoc, "babel", JSON);
|
this.addConfig(pkgLoc, "babel", JSON);
|
||||||
foundConfig = true;
|
foundConfig = true;
|
||||||
@ -232,7 +232,7 @@ export default class OptionManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!foundIgnore) {
|
if (!foundIgnore) {
|
||||||
var ignoreLoc = path.join(loc, BABELIGNORE_FILENAME);
|
let ignoreLoc = path.join(loc, BABELIGNORE_FILENAME);
|
||||||
if (exists(ignoreLoc)) {
|
if (exists(ignoreLoc)) {
|
||||||
this.addIgnoreConfig(ignoreLoc);
|
this.addIgnoreConfig(ignoreLoc);
|
||||||
foundIgnore = true;
|
foundIgnore = true;
|
||||||
@ -244,11 +244,11 @@ export default class OptionManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
normaliseOptions() {
|
normaliseOptions() {
|
||||||
var opts = this.options;
|
let opts = this.options;
|
||||||
|
|
||||||
for (let key in config) {
|
for (let key in config) {
|
||||||
var option = config[key];
|
let option = config[key];
|
||||||
var val = opts[key];
|
let val = opts[key];
|
||||||
|
|
||||||
// optional
|
// optional
|
||||||
if (!val && option.optional) continue;
|
if (!val && option.optional) continue;
|
||||||
|
|||||||
@ -5,7 +5,7 @@ export function number(val) {
|
|||||||
return +val;
|
return +val;
|
||||||
}
|
}
|
||||||
|
|
||||||
export var filename = slash;
|
export let filename = slash;
|
||||||
|
|
||||||
export function boolean(val) {
|
export function boolean(val) {
|
||||||
return !!val;
|
return !!val;
|
||||||
|
|||||||
@ -2,13 +2,13 @@ import explode from "./explode-assignable-expression";
|
|||||||
import * as t from "babel-types";
|
import * as t from "babel-types";
|
||||||
|
|
||||||
export default function (opts) {
|
export default function (opts) {
|
||||||
var exports = {};
|
let exports = {};
|
||||||
|
|
||||||
var isAssignment = function (node) {
|
let isAssignment = function (node) {
|
||||||
return node.operator === opts.operator + "=";
|
return node.operator === opts.operator + "=";
|
||||||
};
|
};
|
||||||
|
|
||||||
var buildAssignment = function (left, right) {
|
let buildAssignment = function (left, right) {
|
||||||
return t.assignmentExpression("=", left, right);
|
return t.assignmentExpression("=", left, right);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -16,11 +16,11 @@ export default function (opts) {
|
|||||||
// hit the `AssignmentExpression` one below
|
// hit the `AssignmentExpression` one below
|
||||||
if (path.isCompletionRecord()) return;
|
if (path.isCompletionRecord()) return;
|
||||||
|
|
||||||
var expr = path.node.expression;
|
let expr = path.node.expression;
|
||||||
if (!isAssignment(expr)) return;
|
if (!isAssignment(expr)) return;
|
||||||
|
|
||||||
var nodes = [];
|
let nodes = [];
|
||||||
var exploded = explode(expr.left, nodes, file, path.scope, true);
|
let exploded = explode(expr.left, nodes, file, path.scope, true);
|
||||||
|
|
||||||
nodes.push(t.expressionStatement(
|
nodes.push(t.expressionStatement(
|
||||||
buildAssignment(exploded.ref, opts.build(exploded.uid, expr.right))
|
buildAssignment(exploded.ref, opts.build(exploded.uid, expr.right))
|
||||||
@ -32,8 +32,8 @@ export default function (opts) {
|
|||||||
exports.AssignmentExpression = function ({ node, scope }, file) {
|
exports.AssignmentExpression = function ({ node, scope }, file) {
|
||||||
if (!isAssignment(node)) return;
|
if (!isAssignment(node)) return;
|
||||||
|
|
||||||
var nodes = [];
|
let nodes = [];
|
||||||
var exploded = explode(node.left, nodes, file, scope);
|
let exploded = explode(node.left, nodes, file, scope);
|
||||||
nodes.push(buildAssignment(exploded.ref, opts.build(exploded.uid, node.right)));
|
nodes.push(buildAssignment(exploded.ref, opts.build(exploded.uid, node.right)));
|
||||||
return nodes;
|
return nodes;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,10 +1,10 @@
|
|||||||
import * as t from "babel-types";
|
import * as t from "babel-types";
|
||||||
|
|
||||||
export default function build(node, buildBody) {
|
export default function build(node, buildBody) {
|
||||||
var self = node.blocks.shift();
|
let self = node.blocks.shift();
|
||||||
if (!self) return;
|
if (!self) return;
|
||||||
|
|
||||||
var child = build(node, buildBody);
|
let child = build(node, buildBody);
|
||||||
if (!child) {
|
if (!child) {
|
||||||
// last item
|
// last item
|
||||||
child = buildBody();
|
child = buildBody();
|
||||||
|
|||||||
@ -2,7 +2,7 @@ import explode from "./explode-assignable-expression";
|
|||||||
import * as t from "babel-types";
|
import * as t from "babel-types";
|
||||||
|
|
||||||
export default function (exports, opts) {
|
export default function (exports, opts) {
|
||||||
var buildAssignment = function (left, right) {
|
let buildAssignment = function (left, right) {
|
||||||
return t.assignmentExpression("=", left, right);
|
return t.assignmentExpression("=", left, right);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -10,12 +10,12 @@ export default function (exports, opts) {
|
|||||||
// hit the `AssignmentExpression` one below
|
// hit the `AssignmentExpression` one below
|
||||||
if (path.isCompletionRecord()) return;
|
if (path.isCompletionRecord()) return;
|
||||||
|
|
||||||
var expr = path.node.expression;
|
let expr = path.node.expression;
|
||||||
if (!opts.is(expr, file)) return;
|
if (!opts.is(expr, file)) return;
|
||||||
|
|
||||||
var nodes = [];
|
let nodes = [];
|
||||||
|
|
||||||
var exploded = explode(expr.left, nodes, file, path.scope);
|
let exploded = explode(expr.left, nodes, file, path.scope);
|
||||||
|
|
||||||
nodes.push(t.ifStatement(
|
nodes.push(t.ifStatement(
|
||||||
opts.build(exploded.uid, file),
|
opts.build(exploded.uid, file),
|
||||||
@ -26,11 +26,11 @@ export default function (exports, opts) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
exports.AssignmentExpression = function (path, file) {
|
exports.AssignmentExpression = function (path, file) {
|
||||||
var node = path.node;
|
let node = path.node;
|
||||||
if (!opts.is(node, file)) return;
|
if (!opts.is(node, file)) return;
|
||||||
|
|
||||||
var nodes = [];
|
let nodes = [];
|
||||||
var exploded = explode(node.left, nodes, file, path.scope);
|
let exploded = explode(node.left, nodes, file, path.scope);
|
||||||
|
|
||||||
nodes.push(t.logicalExpression(
|
nodes.push(t.logicalExpression(
|
||||||
"&&",
|
"&&",
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
// Based upon the excellent jsx-transpiler by Ingvar Stepanyan (RReverser)
|
// Based upon the excellent jsx-transpiler by Inglet Stepanyan (RReverser)
|
||||||
// https://github.com/RReverser/jsx-transpiler
|
// https://github.com/RReverser/jsx-transpiler
|
||||||
|
|
||||||
// jsx
|
// jsx
|
||||||
@ -10,7 +10,7 @@ import { react } from "babel-types";
|
|||||||
import * as t from "babel-types";
|
import * as t from "babel-types";
|
||||||
|
|
||||||
export default function (opts) {
|
export default function (opts) {
|
||||||
var visitor = {};
|
let visitor = {};
|
||||||
|
|
||||||
visitor.JSXIdentifier = function (node) {
|
visitor.JSXIdentifier = function (node) {
|
||||||
if (node.name === "this" && this.isReferenced()) {
|
if (node.name === "this" && this.isReferenced()) {
|
||||||
@ -39,14 +39,14 @@ export default function (opts) {
|
|||||||
|
|
||||||
visitor.JSXAttribute = {
|
visitor.JSXAttribute = {
|
||||||
enter(node) {
|
enter(node) {
|
||||||
var value = node.value;
|
let value = node.value;
|
||||||
if (t.isLiteral(value) && isString(value.value)) {
|
if (t.isLiteral(value) && isString(value.value)) {
|
||||||
value.value = value.value.replace(/\n\s+/g, " ");
|
value.value = value.value.replace(/\n\s+/g, " ");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
exit(node) {
|
exit(node) {
|
||||||
var value = node.value || t.booleanLiteral(true);
|
let value = node.value || t.booleanLiteral(true);
|
||||||
return t.inherits(t.property("init", node.name, value), node);
|
return t.inherits(t.property("init", node.name, value), node);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -55,17 +55,17 @@ export default function (opts) {
|
|||||||
exit(node, parent, scope, file) {
|
exit(node, parent, scope, file) {
|
||||||
parent.children = react.buildChildren(parent);
|
parent.children = react.buildChildren(parent);
|
||||||
|
|
||||||
var tagExpr = node.name;
|
let tagExpr = node.name;
|
||||||
var args = [];
|
let args = [];
|
||||||
|
|
||||||
var tagName;
|
let tagName;
|
||||||
if (t.isIdentifier(tagExpr)) {
|
if (t.isIdentifier(tagExpr)) {
|
||||||
tagName = tagExpr.name;
|
tagName = tagExpr.name;
|
||||||
} else if (t.isLiteral(tagExpr)) {
|
} else if (t.isLiteral(tagExpr)) {
|
||||||
tagName = tagExpr.value;
|
tagName = tagExpr.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
var state = {
|
let state = {
|
||||||
tagExpr: tagExpr,
|
tagExpr: tagExpr,
|
||||||
tagName: tagName,
|
tagName: tagName,
|
||||||
args: args
|
args: args
|
||||||
@ -75,7 +75,7 @@ export default function (opts) {
|
|||||||
opts.pre(state, file);
|
opts.pre(state, file);
|
||||||
}
|
}
|
||||||
|
|
||||||
var attribs = node.attributes;
|
let attribs = node.attributes;
|
||||||
if (attribs.length) {
|
if (attribs.length) {
|
||||||
attribs = buildJSXOpeningElementAttributes(attribs, file);
|
attribs = buildJSXOpeningElementAttributes(attribs, file);
|
||||||
} else {
|
} else {
|
||||||
@ -99,11 +99,11 @@ export default function (opts) {
|
|||||||
* all prior attributes to an array for later processing.
|
* all prior attributes to an array for later processing.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var buildJSXOpeningElementAttributes = function (attribs, file) {
|
let buildJSXOpeningElementAttributes = function (attribs, file) {
|
||||||
var _props = [];
|
let _props = [];
|
||||||
var objs = [];
|
let objs = [];
|
||||||
|
|
||||||
var pushProps = function () {
|
let pushProps = function () {
|
||||||
if (!_props.length) return;
|
if (!_props.length) return;
|
||||||
|
|
||||||
objs.push(t.objectExpression(_props));
|
objs.push(t.objectExpression(_props));
|
||||||
@ -111,7 +111,7 @@ export default function (opts) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
while (attribs.length) {
|
while (attribs.length) {
|
||||||
var prop = attribs.shift();
|
let prop = attribs.shift();
|
||||||
if (t.isJSXSpreadAttribute(prop)) {
|
if (t.isJSXSpreadAttribute(prop)) {
|
||||||
pushProps();
|
pushProps();
|
||||||
objs.push(prop.argument);
|
objs.push(prop.argument);
|
||||||
@ -143,7 +143,7 @@ export default function (opts) {
|
|||||||
|
|
||||||
visitor.JSXElement = {
|
visitor.JSXElement = {
|
||||||
exit(node) {
|
exit(node) {
|
||||||
var callExpr = node.openingElement;
|
let callExpr = node.openingElement;
|
||||||
|
|
||||||
callExpr.arguments = callExpr.arguments.concat(node.children);
|
callExpr.arguments = callExpr.arguments.concat(node.children);
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import * as t from "babel-types";
|
import * as t from "babel-types";
|
||||||
|
|
||||||
var visitor = {
|
let visitor = {
|
||||||
enter(path, state) {
|
enter(path, state) {
|
||||||
if (path.isThisExpression() || path.isReferencedIdentifier({ name: "arguments" })) {
|
if (path.isThisExpression() || path.isReferencedIdentifier({ name: "arguments" })) {
|
||||||
state.found = true;
|
state.found = true;
|
||||||
@ -14,19 +14,19 @@ var visitor = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export default function (node, scope) {
|
export default function (node, scope) {
|
||||||
var container = t.functionExpression(null, [], node.body, node.generator, node.async);
|
let container = t.functionExpression(null, [], node.body, node.generator, node.async);
|
||||||
|
|
||||||
var callee = container;
|
let callee = container;
|
||||||
var args = [];
|
let args = [];
|
||||||
|
|
||||||
var state = { found: false };
|
let state = { found: false };
|
||||||
scope.traverse(node, visitor, state);
|
scope.traverse(node, visitor, state);
|
||||||
if (state.found) {
|
if (state.found) {
|
||||||
callee = t.memberExpression(container, t.identifier("apply"));
|
callee = t.memberExpression(container, t.identifier("apply"));
|
||||||
args = [t.thisExpression(), t.identifier("arguments")];
|
args = [t.thisExpression(), t.identifier("arguments")];
|
||||||
}
|
}
|
||||||
|
|
||||||
var call = t.callExpression(callee, args);
|
let call = t.callExpression(callee, args);
|
||||||
if (node.generator) call = t.yieldExpression(call, true);
|
if (node.generator) call = t.yieldExpression(call, true);
|
||||||
|
|
||||||
return t.returnStatement(call);
|
return t.returnStatement(call);
|
||||||
|
|||||||
@ -3,11 +3,11 @@ import has from "lodash/object/has";
|
|||||||
import * as t from "babel-types";
|
import * as t from "babel-types";
|
||||||
|
|
||||||
export function push(mutatorMap, node, kind, file) {
|
export function push(mutatorMap, node, kind, file) {
|
||||||
var alias = t.toKeyAlias(node);
|
let alias = t.toKeyAlias(node);
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
||||||
var map = {};
|
let map = {};
|
||||||
if (has(mutatorMap, alias)) map = mutatorMap[alias];
|
if (has(mutatorMap, alias)) map = mutatorMap[alias];
|
||||||
mutatorMap[alias] = map;
|
mutatorMap[alias] = map;
|
||||||
|
|
||||||
@ -23,7 +23,7 @@ export function push(mutatorMap, node, kind, file) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (node.decorators) {
|
if (node.decorators) {
|
||||||
var decorators = map.decorators = map.decorators || t.arrayExpression([]);
|
let decorators = map.decorators = map.decorators || t.arrayExpression([]);
|
||||||
decorators.elements = decorators.elements.concat(node.decorators.map(dec => dec.expression).reverse());
|
decorators.elements = decorators.elements.concat(node.decorators.map(dec => dec.expression).reverse());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,7 +44,7 @@ export function push(mutatorMap, node, kind, file) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function hasComputed(mutatorMap) {
|
export function hasComputed(mutatorMap) {
|
||||||
for (var key in mutatorMap) {
|
for (let key in mutatorMap) {
|
||||||
if (mutatorMap[key]._computed) {
|
if (mutatorMap[key]._computed) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -53,11 +53,11 @@ export function hasComputed(mutatorMap) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function toComputedObjectFromClass(obj) {
|
export function toComputedObjectFromClass(obj) {
|
||||||
var objExpr = t.arrayExpression([]);
|
let objExpr = t.arrayExpression([]);
|
||||||
|
|
||||||
for (var i = 0; i < obj.properties.length; i++) {
|
for (let i = 0; i < obj.properties.length; i++) {
|
||||||
var prop = obj.properties[i];
|
let prop = obj.properties[i];
|
||||||
var val = prop.value;
|
let val = prop.value;
|
||||||
val.properties.unshift(t.property("init", t.identifier("key"), t.toComputedKey(prop)));
|
val.properties.unshift(t.property("init", t.identifier("key"), t.toComputedKey(prop)));
|
||||||
objExpr.elements.push(val);
|
objExpr.elements.push(val);
|
||||||
}
|
}
|
||||||
@ -66,20 +66,20 @@ export function toComputedObjectFromClass(obj) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function toClassObject(mutatorMap) {
|
export function toClassObject(mutatorMap) {
|
||||||
var objExpr = t.objectExpression([]);
|
let objExpr = t.objectExpression([]);
|
||||||
|
|
||||||
each(mutatorMap, function (map) {
|
each(mutatorMap, function (map) {
|
||||||
var mapNode = t.objectExpression([]);
|
let mapNode = t.objectExpression([]);
|
||||||
|
|
||||||
var propNode = t.property("init", map._key, mapNode, map._computed);
|
let propNode = t.property("init", map._key, mapNode, map._computed);
|
||||||
|
|
||||||
each(map, function (node, key) {
|
each(map, function (node, key) {
|
||||||
if (key[0] === "_") return;
|
if (key[0] === "_") return;
|
||||||
|
|
||||||
var inheritNode = node;
|
let inheritNode = node;
|
||||||
if (t.isMethodDefinition(node) || t.isClassProperty(node)) node = node.value;
|
if (t.isMethodDefinition(node) || t.isClassProperty(node)) node = node.value;
|
||||||
|
|
||||||
var prop = t.property("init", t.identifier(key), node);
|
let prop = t.property("init", t.identifier(key), node);
|
||||||
t.inheritsComments(prop, inheritNode);
|
t.inheritsComments(prop, inheritNode);
|
||||||
t.removeComments(inheritNode);
|
t.removeComments(inheritNode);
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import * as t from "babel-types";
|
import * as t from "babel-types";
|
||||||
|
|
||||||
var getObjRef = function (node, nodes, file, scope) {
|
let getObjRef = function (node, nodes, file, scope) {
|
||||||
var ref;
|
let ref;
|
||||||
if (t.isIdentifier(node)) {
|
if (t.isIdentifier(node)) {
|
||||||
if (scope.hasBinding(node.name)) {
|
if (scope.hasBinding(node.name)) {
|
||||||
// this variable is declared in scope so we can be 100% sure
|
// this variable is declared in scope so we can be 100% sure
|
||||||
@ -26,19 +26,19 @@ var getObjRef = function (node, nodes, file, scope) {
|
|||||||
throw new Error(`We can't explode this node type ${node.type}`);
|
throw new Error(`We can't explode this node type ${node.type}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
var temp = scope.generateUidIdentifierBasedOnNode(ref);
|
let temp = scope.generateUidIdentifierBasedOnNode(ref);
|
||||||
nodes.push(t.variableDeclaration("var", [
|
nodes.push(t.variableDeclaration("var", [
|
||||||
t.variableDeclarator(temp, ref)
|
t.variableDeclarator(temp, ref)
|
||||||
]));
|
]));
|
||||||
return temp;
|
return temp;
|
||||||
};
|
};
|
||||||
|
|
||||||
var getPropRef = function (node, nodes, file, scope) {
|
let getPropRef = function (node, nodes, file, scope) {
|
||||||
var prop = node.property;
|
let prop = node.property;
|
||||||
var key = t.toComputedKey(node, prop);
|
let key = t.toComputedKey(node, prop);
|
||||||
if (t.isLiteral(key)) return key;
|
if (t.isLiteral(key)) return key;
|
||||||
|
|
||||||
var temp = scope.generateUidIdentifierBasedOnNode(prop);
|
let temp = scope.generateUidIdentifierBasedOnNode(prop);
|
||||||
nodes.push(t.variableDeclaration("var", [
|
nodes.push(t.variableDeclaration("var", [
|
||||||
t.variableDeclarator(temp, prop)
|
t.variableDeclarator(temp, prop)
|
||||||
]));
|
]));
|
||||||
@ -46,21 +46,21 @@ var getPropRef = function (node, nodes, file, scope) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export default function (node, nodes, file, scope, allowedSingleIdent) {
|
export default function (node, nodes, file, scope, allowedSingleIdent) {
|
||||||
var obj;
|
let obj;
|
||||||
if (t.isIdentifier(node) && allowedSingleIdent) {
|
if (t.isIdentifier(node) && allowedSingleIdent) {
|
||||||
obj = node;
|
obj = node;
|
||||||
} else {
|
} else {
|
||||||
obj = getObjRef(node, nodes, file, scope);
|
obj = getObjRef(node, nodes, file, scope);
|
||||||
}
|
}
|
||||||
|
|
||||||
var ref, uid;
|
let ref, uid;
|
||||||
|
|
||||||
if (t.isIdentifier(node)) {
|
if (t.isIdentifier(node)) {
|
||||||
ref = node;
|
ref = node;
|
||||||
uid = obj;
|
uid = obj;
|
||||||
} else {
|
} else {
|
||||||
var prop = getPropRef(node, nodes, file, scope);
|
let prop = getPropRef(node, nodes, file, scope);
|
||||||
var computed = node.computed || t.isLiteral(prop);
|
let computed = node.computed || t.isLiteral(prop);
|
||||||
uid = ref = t.memberExpression(obj, prop, computed);
|
uid = ref = t.memberExpression(obj, prop, computed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
import * as t from "babel-types";
|
import * as t from "babel-types";
|
||||||
|
|
||||||
export default function (node) {
|
export default function (node) {
|
||||||
for (var i = 0; i < node.params.length; i++) {
|
for (let i = 0; i < node.params.length; i++) {
|
||||||
var param = node.params[i];
|
let param = node.params[i];
|
||||||
if (t.isAssignmentPattern(param) || t.isRestElement(param)) {
|
if (t.isAssignmentPattern(param) || t.isRestElement(param)) {
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,15 +1,15 @@
|
|||||||
import * as t from "babel-types";
|
import * as t from "babel-types";
|
||||||
|
|
||||||
export default function (decorators, scope) {
|
export default function (decorators, scope) {
|
||||||
for (var i = 0; i < decorators.length; i++) {
|
for (let i = 0; i < decorators.length; i++) {
|
||||||
var decorator = decorators[i];
|
let decorator = decorators[i];
|
||||||
var expression = decorator.expression;
|
let expression = decorator.expression;
|
||||||
if (!t.isMemberExpression(expression)) continue;
|
if (!t.isMemberExpression(expression)) continue;
|
||||||
|
|
||||||
var temp = scope.maybeGenerateMemoised(expression.object);
|
let temp = scope.maybeGenerateMemoised(expression.object);
|
||||||
var ref;
|
let ref;
|
||||||
|
|
||||||
var nodes = [];
|
let nodes = [];
|
||||||
|
|
||||||
if (temp) {
|
if (temp) {
|
||||||
ref = temp;
|
ref = temp;
|
||||||
|
|||||||
@ -2,14 +2,14 @@ import getFunctionArity from "./get-function-arity";
|
|||||||
import * as util from "../../util";
|
import * as util from "../../util";
|
||||||
import * as t from "babel-types";
|
import * as t from "babel-types";
|
||||||
|
|
||||||
var visitor = {
|
let visitor = {
|
||||||
"ReferencedIdentifier|BindingIdentifier"(path, state) {
|
"ReferencedIdentifier|BindingIdentifier"(path, state) {
|
||||||
// check if this node matches our function id
|
// check if this node matches our function id
|
||||||
if (path.node.name !== state.name) return;
|
if (path.node.name !== state.name) return;
|
||||||
|
|
||||||
// check that we don't have a local variable declared as that removes the need
|
// check that we don't have a local variable declared as that removes the need
|
||||||
// for the wrapper
|
// for the wrapper
|
||||||
var localDeclar = path.scope.getBindingIdentifier(state.name);
|
let localDeclar = path.scope.getBindingIdentifier(state.name);
|
||||||
if (localDeclar !== state.outerDeclar) return;
|
if (localDeclar !== state.outerDeclar) return;
|
||||||
|
|
||||||
state.selfReference = true;
|
state.selfReference = true;
|
||||||
@ -24,9 +24,9 @@ function wrap(state, method, id, scope) {
|
|||||||
scope.rename(id.name);
|
scope.rename(id.name);
|
||||||
} else {
|
} else {
|
||||||
// need to add a wrapper since we can't change the references
|
// need to add a wrapper since we can't change the references
|
||||||
var templateName = "property-method-assignment-wrapper";
|
let templateName = "property-method-assignment-wrapper";
|
||||||
if (method.generator) templateName += "-generator";
|
if (method.generator) templateName += "-generator";
|
||||||
var template = util.template(templateName, {
|
let template = util.template(templateName, {
|
||||||
FUNCTION: method,
|
FUNCTION: method,
|
||||||
FUNCTION_ID: id,
|
FUNCTION_ID: id,
|
||||||
FUNCTION_KEY: scope.generateUidIdentifier(id.name)
|
FUNCTION_KEY: scope.generateUidIdentifier(id.name)
|
||||||
@ -35,8 +35,8 @@ function wrap(state, method, id, scope) {
|
|||||||
|
|
||||||
// shim in dummy params to retain function arity, if you try to read the
|
// 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
|
// source then you'll get the original since it's proxied so it's all good
|
||||||
var params = template.callee.body.body[0].params;
|
let params = template.callee.body.body[0].params;
|
||||||
for (var i = 0, len = getFunctionArity(method); i < len; i++) {
|
for (let i = 0, len = getFunctionArity(method); i < len; i++) {
|
||||||
params.push(scope.generateUidIdentifier("x"));
|
params.push(scope.generateUidIdentifier("x"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,7 +49,7 @@ function wrap(state, method, id, scope) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function visit(node, name, scope) {
|
function visit(node, name, scope) {
|
||||||
var state = {
|
let state = {
|
||||||
selfAssignment: false,
|
selfAssignment: false,
|
||||||
selfReference: false,
|
selfReference: false,
|
||||||
outerDeclar: scope.getBindingIdentifier(name),
|
outerDeclar: scope.getBindingIdentifier(name),
|
||||||
@ -60,13 +60,13 @@ function visit(node, name, scope) {
|
|||||||
// check to see if we have a local binding of the id we're setting inside of
|
// 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
|
// the function, this is important as there are caveats associated
|
||||||
|
|
||||||
var binding = scope.getOwnBinding(name);
|
let binding = scope.getOwnBinding(name);
|
||||||
|
|
||||||
if (binding) {
|
if (binding) {
|
||||||
if (binding.kind === "param") {
|
if (binding.kind === "param") {
|
||||||
// safari will blow up in strict mode with code like:
|
// safari will blow up in strict mode with code like:
|
||||||
//
|
//
|
||||||
// var t = function t(t) {};
|
// let t = function t(t) {};
|
||||||
//
|
//
|
||||||
// with the error:
|
// with the error:
|
||||||
//
|
//
|
||||||
@ -80,8 +80,8 @@ function visit(node, name, scope) {
|
|||||||
} else {
|
} else {
|
||||||
// otherwise it's defined somewhere in scope like:
|
// otherwise it's defined somewhere in scope like:
|
||||||
//
|
//
|
||||||
// var t = function () {
|
// let t = function () {
|
||||||
// var t = 2;
|
// let t = 2;
|
||||||
// };
|
// };
|
||||||
//
|
//
|
||||||
// so we can safely just set the id and move along as it shadows the
|
// so we can safely just set the id and move along as it shadows the
|
||||||
@ -95,19 +95,19 @@ function visit(node, name, scope) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function custom(node, id, scope) {
|
export function custom(node, id, scope) {
|
||||||
var state = visit(node, id.name, scope);
|
let state = visit(node, id.name, scope);
|
||||||
return wrap(state, node, id, scope);
|
return wrap(state, node, id, scope);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function property(node, file, scope) {
|
export function property(node, file, scope) {
|
||||||
var key = t.toComputedKey(node, node.key);
|
let key = t.toComputedKey(node, node.key);
|
||||||
if (!t.isLiteral(key)) return; // we can't set a function id with this
|
if (!t.isLiteral(key)) return; // we can't set a function id with this
|
||||||
|
|
||||||
var name = t.toBindingIdentifierName(key.value);
|
let name = t.toBindingIdentifierName(key.value);
|
||||||
var id = t.identifier(name);
|
let id = t.identifier(name);
|
||||||
|
|
||||||
var method = node.value;
|
let method = node.value;
|
||||||
var state = visit(method, name, scope);
|
let state = visit(method, name, scope);
|
||||||
node.value = wrap(state, method, id, scope) || method;
|
node.value = wrap(state, method, id, scope) || method;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,16 +115,16 @@ export function bare(node, parent, scope) {
|
|||||||
// has an `id` so we don't need to infer one
|
// has an `id` so we don't need to infer one
|
||||||
if (node.id) return;
|
if (node.id) return;
|
||||||
|
|
||||||
var id;
|
let id;
|
||||||
if (t.isProperty(parent) && parent.kind === "init" && (!parent.computed || t.isLiteral(parent.key))) {
|
if (t.isProperty(parent) && parent.kind === "init" && (!parent.computed || t.isLiteral(parent.key))) {
|
||||||
// { foo() {} };
|
// { foo() {} };
|
||||||
id = parent.key;
|
id = parent.key;
|
||||||
} else if (t.isVariableDeclarator(parent)) {
|
} else if (t.isVariableDeclarator(parent)) {
|
||||||
// var foo = function () {};
|
// let foo = function () {};
|
||||||
id = parent.id;
|
id = parent.id;
|
||||||
|
|
||||||
if (t.isIdentifier(id)) {
|
if (t.isIdentifier(id)) {
|
||||||
var binding = scope.parent.getBinding(id.name);
|
let binding = scope.parent.getBinding(id.name);
|
||||||
if (binding && binding.constant && scope.getBinding(id.name) === binding) {
|
if (binding && binding.constant && scope.getBinding(id.name) === binding) {
|
||||||
// always going to reference this method
|
// always going to reference this method
|
||||||
node.id = id;
|
node.id = id;
|
||||||
@ -135,7 +135,7 @@ export function bare(node, parent, scope) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var name;
|
let name;
|
||||||
if (t.isLiteral(id)) {
|
if (t.isLiteral(id)) {
|
||||||
name = id.value;
|
name = id.value;
|
||||||
} else if (t.isIdentifier(id)) {
|
} else if (t.isIdentifier(id)) {
|
||||||
@ -147,6 +147,6 @@ export function bare(node, parent, scope) {
|
|||||||
name = t.toBindingIdentifierName(name);
|
name = t.toBindingIdentifierName(name);
|
||||||
id = t.identifier(name);
|
id = t.identifier(name);
|
||||||
|
|
||||||
var state = visit(node, name, scope);
|
let state = visit(node, name, scope);
|
||||||
return wrap(state, node, id, scope);
|
return wrap(state, node, id, scope);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,7 +6,7 @@ export function is(node, flag) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function pullFlag(node, flag) {
|
export function pullFlag(node, flag) {
|
||||||
var flags = node.flags.split("");
|
let flags = node.flags.split("");
|
||||||
if (node.flags.indexOf(flag) < 0) return;
|
if (node.flags.indexOf(flag) < 0) return;
|
||||||
pull(flags, flag);
|
pull(flags, flag);
|
||||||
node.flags = flags.join("");
|
node.flags = flags.join("");
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import * as t from "babel-types";
|
import * as t from "babel-types";
|
||||||
|
|
||||||
var awaitVisitor = {
|
let awaitVisitor = {
|
||||||
Function(path) {
|
Function(path) {
|
||||||
path.skip();
|
path.skip();
|
||||||
},
|
},
|
||||||
@ -16,9 +16,9 @@ var awaitVisitor = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var referenceVisitor = {
|
let referenceVisitor = {
|
||||||
ReferencedIdentifier({ node, scope }, state) {
|
ReferencedIdentifier({ node, scope }, state) {
|
||||||
var name = state.id.name;
|
let name = state.id.name;
|
||||||
if (node.name === name && scope.bindingIdentifierEquals(name, state.id)) {
|
if (node.name === name && scope.bindingIdentifierEquals(name, state.id)) {
|
||||||
return state.ref = state.ref || scope.generateUidIdentifier(name);
|
return state.ref = state.ref || scope.generateUidIdentifier(name);
|
||||||
}
|
}
|
||||||
@ -26,20 +26,20 @@ var referenceVisitor = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export default function (path, callId) {
|
export default function (path, callId) {
|
||||||
var node = path.node;
|
let node = path.node;
|
||||||
|
|
||||||
node.async = false;
|
node.async = false;
|
||||||
node.generator = true;
|
node.generator = true;
|
||||||
|
|
||||||
path.traverse(awaitVisitor, state);
|
path.traverse(awaitVisitor, state);
|
||||||
|
|
||||||
var call = t.callExpression(callId, [node]);
|
let call = t.callExpression(callId, [node]);
|
||||||
|
|
||||||
var id = node.id;
|
let id = node.id;
|
||||||
node.id = null;
|
node.id = null;
|
||||||
|
|
||||||
if (t.isFunctionDeclaration(node)) {
|
if (t.isFunctionDeclaration(node)) {
|
||||||
var declar = t.variableDeclaration("let", [
|
let declar = t.variableDeclaration("let", [
|
||||||
t.variableDeclarator(id, call)
|
t.variableDeclarator(id, call)
|
||||||
]);
|
]);
|
||||||
declar._blockHoist = true;
|
declar._blockHoist = true;
|
||||||
@ -48,7 +48,7 @@ export default function (path, callId) {
|
|||||||
node.type = "FunctionExpression";
|
node.type = "FunctionExpression";
|
||||||
|
|
||||||
if (id) {
|
if (id) {
|
||||||
var state = { id };
|
let state = { id };
|
||||||
path.traverse(referenceVisitor, state);
|
path.traverse(referenceVisitor, state);
|
||||||
|
|
||||||
if (state.ref) {
|
if (state.ref) {
|
||||||
|
|||||||
@ -13,10 +13,10 @@ function isMemberExpressionSuper(node) {
|
|||||||
return t.isMemberExpression(node) && t.isSuper(node.object);
|
return t.isMemberExpression(node) && t.isSuper(node.object);
|
||||||
}
|
}
|
||||||
|
|
||||||
var visitor = {
|
let visitor = {
|
||||||
enter(path, state) {
|
enter(path, state) {
|
||||||
var topLevel = state.topLevel;
|
let topLevel = state.topLevel;
|
||||||
var self = state.self;
|
let self = state.self;
|
||||||
|
|
||||||
if (path.isFunction() && !path.isArrowFunctionExpression()) {
|
if (path.isFunction() && !path.isArrowFunctionExpression()) {
|
||||||
// we need to call traverseLevel again so we're context aware
|
// we need to call traverseLevel again so we're context aware
|
||||||
@ -29,15 +29,15 @@ var visitor = {
|
|||||||
return path.skip();
|
return path.skip();
|
||||||
}
|
}
|
||||||
|
|
||||||
var getThisReference = topLevel ?
|
let getThisReference = topLevel ?
|
||||||
// top level so `this` is the instance
|
// top level so `this` is the instance
|
||||||
t.thisExpression :
|
t.thisExpression :
|
||||||
// not in the top level so we need to create a reference
|
// not in the top level so we need to create a reference
|
||||||
self.getThisReference.bind(self);
|
self.getThisReference.bind(self);
|
||||||
|
|
||||||
var callback = self.specHandle;
|
let callback = self.specHandle;
|
||||||
if (self.isLoose) callback = self.looseHandle;
|
if (self.isLoose) callback = self.looseHandle;
|
||||||
var result = callback.call(self, path, getThisReference);
|
let result = callback.call(self, path, getThisReference);
|
||||||
if (result) path.hasSuper = true;
|
if (result) path.hasSuper = true;
|
||||||
if (result === true) return;
|
if (result === true) return;
|
||||||
return result;
|
return result;
|
||||||
@ -119,7 +119,7 @@ export default class ReplaceSupers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
traverseLevel(path: NodePath, topLevel: boolean) {
|
traverseLevel(path: NodePath, topLevel: boolean) {
|
||||||
var state = { self: this, topLevel: topLevel };
|
let state = { self: this, topLevel: topLevel };
|
||||||
path.traverse(visitor, state);
|
path.traverse(visitor, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -127,7 +127,7 @@ export default class ReplaceSupers {
|
|||||||
if (this.topLevelThisReference) {
|
if (this.topLevelThisReference) {
|
||||||
return this.topLevelThisReference;
|
return this.topLevelThisReference;
|
||||||
} else {
|
} else {
|
||||||
var ref = this.topLevelThisReference = this.scope.generateUidIdentifier("this");
|
let ref = this.topLevelThisReference = this.scope.generateUidIdentifier("this");
|
||||||
this.methodNode.value.body.body.unshift(t.variableDeclaration("var", [
|
this.methodNode.value.body.body.unshift(t.variableDeclaration("var", [
|
||||||
t.variableDeclarator(this.topLevelThisReference, t.thisExpression())
|
t.variableDeclarator(this.topLevelThisReference, t.thisExpression())
|
||||||
]));
|
]));
|
||||||
@ -136,9 +136,9 @@ export default class ReplaceSupers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getLooseSuperProperty(id: Object, parent: Object) {
|
getLooseSuperProperty(id: Object, parent: Object) {
|
||||||
var methodNode = this.methodNode;
|
let methodNode = this.methodNode;
|
||||||
var methodName = methodNode.key;
|
let methodName = methodNode.key;
|
||||||
var superRef = this.superRef || t.identifier("Function");
|
let superRef = this.superRef || t.identifier("Function");
|
||||||
|
|
||||||
if (parent.property === id) {
|
if (parent.property === id) {
|
||||||
return;
|
return;
|
||||||
@ -175,11 +175,11 @@ export default class ReplaceSupers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
looseHandle(path: NodePath, getThisReference: Function) {
|
looseHandle(path: NodePath, getThisReference: Function) {
|
||||||
var node = path.node;
|
let node = path.node;
|
||||||
if (path.isSuper()) {
|
if (path.isSuper()) {
|
||||||
return this.getLooseSuperProperty(node, path.parent);
|
return this.getLooseSuperProperty(node, path.parent);
|
||||||
} else if (path.isCallExpression()) {
|
} else if (path.isCallExpression()) {
|
||||||
var callee = node.callee;
|
let callee = node.callee;
|
||||||
if (!t.isMemberExpression(callee)) return;
|
if (!t.isMemberExpression(callee)) return;
|
||||||
if (!t.isSuper(callee.object)) return;
|
if (!t.isSuper(callee.object)) return;
|
||||||
|
|
||||||
@ -195,7 +195,7 @@ export default class ReplaceSupers {
|
|||||||
// super.name = "val"; -> _set(Object.getPrototypeOf(objectRef.prototype), "name", this);
|
// super.name = "val"; -> _set(Object.getPrototypeOf(objectRef.prototype), "name", this);
|
||||||
return this.setSuperProperty(node.left.property, node.right, node.left.computed, getThisReference());
|
return this.setSuperProperty(node.left.property, node.right, node.left.computed, getThisReference());
|
||||||
} else {
|
} else {
|
||||||
// super.age += 2; -> var _ref = super.age; super.age = _ref + 2;
|
// super.age += 2; -> let _ref = super.age; super.age = _ref + 2;
|
||||||
ref = ref || path.scope.generateUidIdentifier("ref");
|
ref = ref || path.scope.generateUidIdentifier("ref");
|
||||||
return [
|
return [
|
||||||
t.variableDeclaration("var", [
|
t.variableDeclaration("var", [
|
||||||
@ -209,21 +209,21 @@ export default class ReplaceSupers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
specHandle(path: NodePath, getThisReference: Function) {
|
specHandle(path: NodePath, getThisReference: Function) {
|
||||||
var methodNode = this.methodNode;
|
let methodNode = this.methodNode;
|
||||||
var property;
|
let property;
|
||||||
var computed;
|
let computed;
|
||||||
var args;
|
let args;
|
||||||
var thisReference;
|
let thisReference;
|
||||||
|
|
||||||
var parent = path.parent;
|
let parent = path.parent;
|
||||||
var node = path.node;
|
let node = path.node;
|
||||||
|
|
||||||
if (isIllegalBareSuper(node, parent)) {
|
if (isIllegalBareSuper(node, parent)) {
|
||||||
throw path.buildCodeFrameError(messages.get("classesIllegalBareSuper"));
|
throw path.buildCodeFrameError(messages.get("classesIllegalBareSuper"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (t.isCallExpression(node)) {
|
if (t.isCallExpression(node)) {
|
||||||
var callee = node.callee;
|
let callee = node.callee;
|
||||||
if (t.isSuper(callee)) {
|
if (t.isSuper(callee)) {
|
||||||
// super(); -> _get(Object.getPrototypeOf(objectRef), "MethodName", this).call(this);
|
// super(); -> _get(Object.getPrototypeOf(objectRef), "MethodName", this).call(this);
|
||||||
property = methodNode.key;
|
property = methodNode.key;
|
||||||
@ -234,7 +234,7 @@ export default class ReplaceSupers {
|
|||||||
// - https://esdiscuss.org/topic/super-call-in-methods
|
// - https://esdiscuss.org/topic/super-call-in-methods
|
||||||
// - https://twitter.com/wycats/status/544553184396836864
|
// - https://twitter.com/wycats/status/544553184396836864
|
||||||
if (methodNode.key.name !== "constructor" || !this.inClass) {
|
if (methodNode.key.name !== "constructor" || !this.inClass) {
|
||||||
var methodName = methodNode.key.name || "METHOD_NAME";
|
let methodName = methodNode.key.name || "METHOD_NAME";
|
||||||
throw this.file.buildCodeFrameError(node, messages.get("classesIllegalSuperCall", methodName));
|
throw this.file.buildCodeFrameError(node, messages.get("classesIllegalSuperCall", methodName));
|
||||||
}
|
}
|
||||||
} else if (isMemberExpressionSuper(callee)) {
|
} else if (isMemberExpressionSuper(callee)) {
|
||||||
@ -248,13 +248,13 @@ export default class ReplaceSupers {
|
|||||||
property = node.property;
|
property = node.property;
|
||||||
computed = node.computed;
|
computed = node.computed;
|
||||||
} else if (t.isUpdateExpression(node) && isMemberExpressionSuper(node.argument)) {
|
} else if (t.isUpdateExpression(node) && isMemberExpressionSuper(node.argument)) {
|
||||||
var binary = t.binaryExpression(node.operator[0], node.argument, t.numberLiteral(1));
|
let binary = t.binaryExpression(node.operator[0], node.argument, t.numberLiteral(1));
|
||||||
if (node.prefix) {
|
if (node.prefix) {
|
||||||
// ++super.foo; -> super.foo += 1;
|
// ++super.foo; -> super.foo += 1;
|
||||||
return this.specHandleAssignmentExpression(null, path, binary, getThisReference);
|
return this.specHandleAssignmentExpression(null, path, binary, getThisReference);
|
||||||
} else {
|
} else {
|
||||||
// super.foo++; -> var _ref = super.foo; super.foo = _ref + 1;
|
// super.foo++; -> let _ref = super.foo; super.foo = _ref + 1;
|
||||||
var ref = path.scope.generateUidIdentifier("ref");
|
let ref = path.scope.generateUidIdentifier("ref");
|
||||||
return this.specHandleAssignmentExpression(ref, path, binary, getThisReference).concat(t.expressionStatement(ref));
|
return this.specHandleAssignmentExpression(ref, path, binary, getThisReference).concat(t.expressionStatement(ref));
|
||||||
}
|
}
|
||||||
} else if (t.isAssignmentExpression(node) && isMemberExpressionSuper(node.left)) {
|
} else if (t.isAssignmentExpression(node) && isMemberExpressionSuper(node.left)) {
|
||||||
@ -264,7 +264,7 @@ export default class ReplaceSupers {
|
|||||||
if (!property) return;
|
if (!property) return;
|
||||||
|
|
||||||
thisReference = getThisReference();
|
thisReference = getThisReference();
|
||||||
var superProperty = this.getSuperProperty(property, computed, thisReference);
|
let superProperty = this.getSuperProperty(property, computed, thisReference);
|
||||||
if (args) {
|
if (args) {
|
||||||
if (args.length === 1 && t.isSpreadElement(args[0])) {
|
if (args.length === 1 && t.isSpreadElement(args[0])) {
|
||||||
// super(...arguments);
|
// super(...arguments);
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import Pipeline from "./pipeline";
|
import Pipeline from "./pipeline";
|
||||||
|
|
||||||
var pipeline = new Pipeline;
|
let pipeline = new Pipeline;
|
||||||
var transform = pipeline.transform.bind(pipeline);
|
let transform = pipeline.transform.bind(pipeline);
|
||||||
transform.fromAst = pipeline.transformFromAst.bind(pipeline);
|
transform.fromAst = pipeline.transformFromAst.bind(pipeline);
|
||||||
transform.lint = pipeline.lint.bind(pipeline);
|
transform.lint = pipeline.lint.bind(pipeline);
|
||||||
transform.pipeline = pipeline;
|
transform.pipeline = pipeline;
|
||||||
|
|||||||
@ -16,9 +16,9 @@ export default new Plugin({
|
|||||||
visitor: {
|
visitor: {
|
||||||
Block: {
|
Block: {
|
||||||
exit({ node }) {
|
exit({ node }) {
|
||||||
var hasChange = false;
|
let hasChange = false;
|
||||||
for (var i = 0; i < node.body.length; i++) {
|
for (let i = 0; i < node.body.length; i++) {
|
||||||
var bodyNode = node.body[i];
|
let bodyNode = node.body[i];
|
||||||
if (bodyNode && bodyNode._blockHoist != null) {
|
if (bodyNode && bodyNode._blockHoist != null) {
|
||||||
hasChange = true;
|
hasChange = true;
|
||||||
break;
|
break;
|
||||||
@ -27,7 +27,7 @@ export default new Plugin({
|
|||||||
if (!hasChange) return;
|
if (!hasChange) return;
|
||||||
|
|
||||||
node.body = sortBy(node.body, function(bodyNode){
|
node.body = sortBy(node.body, function(bodyNode){
|
||||||
var priority = bodyNode && bodyNode._blockHoist;
|
let priority = bodyNode && bodyNode._blockHoist;
|
||||||
if (priority == null) priority = 1;
|
if (priority == null) priority = 1;
|
||||||
if (priority === true) priority = 2;
|
if (priority === true) priority = 2;
|
||||||
|
|
||||||
|
|||||||
@ -25,13 +25,13 @@ function shouldShadow(path, shadowPath) {
|
|||||||
|
|
||||||
function remap(path, key, create) {
|
function remap(path, key, create) {
|
||||||
// ensure that we're shadowed
|
// ensure that we're shadowed
|
||||||
var shadowPath = path.inShadow(key);
|
let shadowPath = path.inShadow(key);
|
||||||
if (!shouldShadow(path, shadowPath)) return;
|
if (!shouldShadow(path, shadowPath)) return;
|
||||||
|
|
||||||
var shadowFunction = path.node._shadowedFunctionLiteral;
|
let shadowFunction = path.node._shadowedFunctionLiteral;
|
||||||
var currentFunction;
|
let currentFunction;
|
||||||
|
|
||||||
var fnPath = path.findParent(function (path) {
|
let fnPath = path.findParent(function (path) {
|
||||||
if (path.isProgram() || path.isFunction()) {
|
if (path.isProgram() || path.isFunction()) {
|
||||||
// catch current function in case this is the shadowed one and we can ignore it
|
// catch current function in case this is the shadowed one and we can ignore it
|
||||||
currentFunction = currentFunction || path;
|
currentFunction = currentFunction || path;
|
||||||
@ -53,11 +53,11 @@ function remap(path, key, create) {
|
|||||||
// no point in realiasing if we're in this function
|
// no point in realiasing if we're in this function
|
||||||
if (fnPath === currentFunction) return;
|
if (fnPath === currentFunction) return;
|
||||||
|
|
||||||
var cached = fnPath.getData(key);
|
let cached = fnPath.getData(key);
|
||||||
if (cached) return cached;
|
if (cached) return cached;
|
||||||
|
|
||||||
var init = create();
|
let init = create();
|
||||||
var id = path.scope.generateUidIdentifier(key);
|
let id = path.scope.generateUidIdentifier(key);
|
||||||
|
|
||||||
fnPath.setData(key, id);
|
fnPath.setData(key, id);
|
||||||
fnPath.scope.push({ id, init });
|
fnPath.scope.push({ id, init });
|
||||||
|
|||||||
@ -32,10 +32,10 @@ export default class DefaultFormatter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
addScope(path) {
|
addScope(path) {
|
||||||
var source = path.node.source && path.node.source.value;
|
let source = path.node.source && path.node.source.value;
|
||||||
if (!source) return;
|
if (!source) return;
|
||||||
|
|
||||||
var existingScope = this.sourceScopes[source];
|
let existingScope = this.sourceScopes[source];
|
||||||
if (existingScope && existingScope !== path.scope) {
|
if (existingScope && existingScope !== path.scope) {
|
||||||
throw path.buildCodeFrameError(messages.get("modulesDuplicateDeclarations"));
|
throw path.buildCodeFrameError(messages.get("modulesDuplicateDeclarations"));
|
||||||
}
|
}
|
||||||
@ -44,7 +44,7 @@ export default class DefaultFormatter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
isModuleType(node, type) {
|
isModuleType(node, type) {
|
||||||
var modules = this.file.dynamicImportTypes[type];
|
let modules = this.file.dynamicImportTypes[type];
|
||||||
return modules && modules.indexOf(node) >= 0;
|
return modules && modules.indexOf(node) >= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,8 +57,8 @@ export default class DefaultFormatter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getMetadata() {
|
getMetadata() {
|
||||||
var has = false;
|
let has = false;
|
||||||
for (var node of (this.file.ast.program.body: Array)) {
|
for (let node of (this.file.ast.program.body: Array)) {
|
||||||
if (t.isModuleDeclaration(node)) {
|
if (t.isModuleDeclaration(node)) {
|
||||||
has = true;
|
has = true;
|
||||||
break;
|
break;
|
||||||
@ -76,9 +76,9 @@ export default class DefaultFormatter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
remapExportAssignment(node, exported) {
|
remapExportAssignment(node, exported) {
|
||||||
var assign = node;
|
let assign = node;
|
||||||
|
|
||||||
for (var i = 0; i < exported.length; i++) {
|
for (let i = 0; i < exported.length; i++) {
|
||||||
assign = t.assignmentExpression(
|
assign = t.assignmentExpression(
|
||||||
"=",
|
"=",
|
||||||
t.memberExpression(t.identifier("exports"), exported[i]),
|
t.memberExpression(t.identifier("exports"), exported[i]),
|
||||||
@ -90,7 +90,7 @@ export default class DefaultFormatter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_addExport(name, exported) {
|
_addExport(name, exported) {
|
||||||
var info = this.localExports[name] = this.localExports[name] || {
|
let info = this.localExports[name] = this.localExports[name] || {
|
||||||
binding: this.scope.getBindingIdentifier(name),
|
binding: this.scope.getBindingIdentifier(name),
|
||||||
exported: []
|
exported: []
|
||||||
};
|
};
|
||||||
@ -100,21 +100,21 @@ export default class DefaultFormatter {
|
|||||||
getExport(node, scope) {
|
getExport(node, scope) {
|
||||||
if (!t.isIdentifier(node)) return;
|
if (!t.isIdentifier(node)) return;
|
||||||
|
|
||||||
var local = this.localExports[node.name];
|
let local = this.localExports[node.name];
|
||||||
if (local && local.binding === scope.getBindingIdentifier(node.name)) {
|
if (local && local.binding === scope.getBindingIdentifier(node.name)) {
|
||||||
return local.exported;
|
return local.exported;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getModuleName() {
|
getModuleName() {
|
||||||
var opts = this.file.opts;
|
let opts = this.file.opts;
|
||||||
// moduleId is n/a if a `getModuleId()` is provided
|
// moduleId is n/a if a `getModuleId()` is provided
|
||||||
if (opts.moduleId != null && !opts.getModuleId) {
|
if (opts.moduleId != null && !opts.getModuleId) {
|
||||||
return opts.moduleId;
|
return opts.moduleId;
|
||||||
}
|
}
|
||||||
|
|
||||||
var filenameRelative = opts.filenameRelative;
|
let filenameRelative = opts.filenameRelative;
|
||||||
var moduleName = "";
|
let moduleName = "";
|
||||||
|
|
||||||
if (opts.moduleRoot != null) {
|
if (opts.moduleRoot != null) {
|
||||||
moduleName = opts.moduleRoot + "/";
|
moduleName = opts.moduleRoot + "/";
|
||||||
@ -126,7 +126,7 @@ export default class DefaultFormatter {
|
|||||||
|
|
||||||
if (opts.sourceRoot != null) {
|
if (opts.sourceRoot != null) {
|
||||||
// remove sourceRoot from filename
|
// remove sourceRoot from filename
|
||||||
var sourceRootRegEx = new RegExp("^" + opts.sourceRoot + "\/?");
|
let sourceRootRegEx = new RegExp("^" + opts.sourceRoot + "\/?");
|
||||||
filenameRelative = filenameRelative.replace(sourceRootRegEx, "");
|
filenameRelative = filenameRelative.replace(sourceRootRegEx, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -168,8 +168,8 @@ export default class DefaultFormatter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getExternalReference(node, nodes) {
|
getExternalReference(node, nodes) {
|
||||||
var ids = this.ids;
|
let ids = this.ids;
|
||||||
var id = node.source.value;
|
let id = node.source.value;
|
||||||
|
|
||||||
if (ids[id]) {
|
if (ids[id]) {
|
||||||
return ids[id];
|
return ids[id];
|
||||||
@ -185,7 +185,7 @@ export default class DefaultFormatter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
exportAllDeclaration(node, nodes) {
|
exportAllDeclaration(node, nodes) {
|
||||||
var ref = this.getExternalReference(node, nodes);
|
let ref = this.getExternalReference(node, nodes);
|
||||||
nodes.push(this.buildExportsWildcard(ref, node));
|
nodes.push(this.buildExportsWildcard(ref, node));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -195,7 +195,7 @@ export default class DefaultFormatter {
|
|||||||
|
|
||||||
exportSpecifier(specifier, node, nodes) {
|
exportSpecifier(specifier, node, nodes) {
|
||||||
if (node.source) {
|
if (node.source) {
|
||||||
var ref = this.getExternalReference(node, nodes);
|
let ref = this.getExternalReference(node, nodes);
|
||||||
|
|
||||||
if (specifier.local.name === "default" && !this.noInteropRequireExport) {
|
if (specifier.local.name === "default" && !this.noInteropRequireExport) {
|
||||||
// importing a default so we need to normalize it
|
// importing a default so we need to normalize it
|
||||||
@ -244,28 +244,28 @@ export default class DefaultFormatter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
exportDeclaration(node, nodes) {
|
exportDeclaration(node, nodes) {
|
||||||
var declar = node.declaration;
|
let declar = node.declaration;
|
||||||
|
|
||||||
var id = declar.id;
|
let id = declar.id;
|
||||||
|
|
||||||
if (t.isExportDefaultDeclaration(node)) {
|
if (t.isExportDefaultDeclaration(node)) {
|
||||||
id = t.identifier("default");
|
id = t.identifier("default");
|
||||||
}
|
}
|
||||||
|
|
||||||
var assign;
|
let assign;
|
||||||
|
|
||||||
if (t.isVariableDeclaration(declar)) {
|
if (t.isVariableDeclaration(declar)) {
|
||||||
for (var i = 0; i < declar.declarations.length; i++) {
|
for (let i = 0; i < declar.declarations.length; i++) {
|
||||||
var decl = declar.declarations[i];
|
let decl = declar.declarations[i];
|
||||||
|
|
||||||
decl.init = this.buildExportsAssignment(decl.id, decl.init, node).expression;
|
decl.init = this.buildExportsAssignment(decl.id, decl.init, node).expression;
|
||||||
|
|
||||||
var newDeclar = t.variableDeclaration(declar.kind, [decl]);
|
let newDeclar = t.variableDeclaration(declar.kind, [decl]);
|
||||||
if (i === 0) t.inherits(newDeclar, declar);
|
if (i === 0) t.inherits(newDeclar, declar);
|
||||||
nodes.push(newDeclar);
|
nodes.push(newDeclar);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
var ref = declar;
|
let ref = declar;
|
||||||
|
|
||||||
if (t.isFunctionDeclaration(declar) || t.isClassDeclaration(declar)) {
|
if (t.isFunctionDeclaration(declar) || t.isClassDeclaration(declar)) {
|
||||||
ref = declar.id;
|
ref = declar.id;
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import * as util from "../../util";
|
import * as util from "../../util";
|
||||||
|
|
||||||
export default function (Parent) {
|
export default function (Parent) {
|
||||||
var Constructor = function () {
|
let Constructor = function () {
|
||||||
this.noInteropRequireImport = true;
|
this.noInteropRequireImport = true;
|
||||||
this.noInteropRequireExport = true;
|
this.noInteropRequireExport = true;
|
||||||
Parent.apply(this, arguments);
|
Parent.apply(this, arguments);
|
||||||
|
|||||||
@ -11,8 +11,8 @@ export default class AMDFormatter extends DefaultFormatter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
buildDependencyLiterals() {
|
buildDependencyLiterals() {
|
||||||
var names = [];
|
let names = [];
|
||||||
for (var name in this.ids) {
|
for (let name in this.ids) {
|
||||||
names.push(t.stringLiteral(name));
|
names.push(t.stringLiteral(name));
|
||||||
}
|
}
|
||||||
return names;
|
return names;
|
||||||
@ -25,28 +25,28 @@ export default class AMDFormatter extends DefaultFormatter {
|
|||||||
transform(program) {
|
transform(program) {
|
||||||
CommonFormatter.prototype.transform.apply(this, arguments);
|
CommonFormatter.prototype.transform.apply(this, arguments);
|
||||||
|
|
||||||
var body = program.body;
|
let body = program.body;
|
||||||
|
|
||||||
// build an array of module names
|
// build an array of module names
|
||||||
|
|
||||||
var names = [t.stringLiteral("exports")];
|
let names = [t.stringLiteral("exports")];
|
||||||
if (this.passModuleArg) names.push(t.stringLiteral("module"));
|
if (this.passModuleArg) names.push(t.stringLiteral("module"));
|
||||||
names = names.concat(this.buildDependencyLiterals());
|
names = names.concat(this.buildDependencyLiterals());
|
||||||
names = t.arrayExpression(names);
|
names = t.arrayExpression(names);
|
||||||
|
|
||||||
// build up define container
|
// build up define container
|
||||||
|
|
||||||
var params = values(this.ids);
|
let params = values(this.ids);
|
||||||
if (this.passModuleArg) params.unshift(t.identifier("module"));
|
if (this.passModuleArg) params.unshift(t.identifier("module"));
|
||||||
params.unshift(t.identifier("exports"));
|
params.unshift(t.identifier("exports"));
|
||||||
|
|
||||||
var container = t.functionExpression(null, params, t.blockStatement(body));
|
let container = t.functionExpression(null, params, t.blockStatement(body));
|
||||||
|
|
||||||
var defineArgs = [names, container];
|
let defineArgs = [names, container];
|
||||||
var moduleName = this.getModuleName();
|
let moduleName = this.getModuleName();
|
||||||
if (moduleName) defineArgs.unshift(t.stringLiteral(moduleName));
|
if (moduleName) defineArgs.unshift(t.stringLiteral(moduleName));
|
||||||
|
|
||||||
var call = t.callExpression(t.identifier("define"), defineArgs);
|
let call = t.callExpression(t.identifier("define"), defineArgs);
|
||||||
|
|
||||||
program.body = [t.expressionStatement(call)];
|
program.body = [t.expressionStatement(call)];
|
||||||
}
|
}
|
||||||
@ -73,8 +73,8 @@ export default class AMDFormatter extends DefaultFormatter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
importSpecifier(specifier, node, nodes, scope) {
|
importSpecifier(specifier, node, nodes, scope) {
|
||||||
var key = node.source.value;
|
let key = node.source.value;
|
||||||
var ref = this.getExternalReference(node);
|
let ref = this.getExternalReference(node);
|
||||||
|
|
||||||
if (t.isImportNamespaceSpecifier(specifier) || t.isImportDefaultSpecifier(specifier)) {
|
if (t.isImportNamespaceSpecifier(specifier) || t.isImportDefaultSpecifier(specifier)) {
|
||||||
this.defaultIds[key] = specifier.local;
|
this.defaultIds[key] = specifier.local;
|
||||||
@ -90,14 +90,14 @@ export default class AMDFormatter extends DefaultFormatter {
|
|||||||
// import * as bar from "foo";
|
// import * as bar from "foo";
|
||||||
} else if (!includes(this.file.dynamicImported, node) && t.isSpecifierDefault(specifier) && !this.noInteropRequireImport) {
|
} else if (!includes(this.file.dynamicImported, node) && t.isSpecifierDefault(specifier) && !this.noInteropRequireImport) {
|
||||||
// import foo from "foo";
|
// import foo from "foo";
|
||||||
var uid = scope.generateUidIdentifier(specifier.local.name);
|
let uid = scope.generateUidIdentifier(specifier.local.name);
|
||||||
nodes.push(t.variableDeclaration("var", [
|
nodes.push(t.variableDeclaration("var", [
|
||||||
t.variableDeclarator(uid, t.callExpression(this.file.addHelper("interop-require-default"), [ref]))
|
t.variableDeclarator(uid, t.callExpression(this.file.addHelper("interop-require-default"), [ref]))
|
||||||
]));
|
]));
|
||||||
ref = t.memberExpression(uid, t.identifier("default"));
|
ref = t.memberExpression(uid, t.identifier("default"));
|
||||||
} else {
|
} else {
|
||||||
// import { foo } from "foo";
|
// import { foo } from "foo";
|
||||||
var imported = specifier.imported;
|
let imported = specifier.imported;
|
||||||
if (t.isSpecifierDefault(specifier)) imported = t.identifier("default");
|
if (t.isSpecifierDefault(specifier)) imported = t.identifier("default");
|
||||||
ref = t.memberExpression(ref, imported);
|
ref = t.memberExpression(ref, imported);
|
||||||
}
|
}
|
||||||
@ -124,8 +124,8 @@ export default class AMDFormatter extends DefaultFormatter {
|
|||||||
if (this.doDefaultExportInterop(node)) {
|
if (this.doDefaultExportInterop(node)) {
|
||||||
this.passModuleArg = true;
|
this.passModuleArg = true;
|
||||||
|
|
||||||
var declar = node.declaration;
|
let declar = node.declaration;
|
||||||
var assign = util.template("exports-default-assign", {
|
let assign = util.template("exports-default-assign", {
|
||||||
VALUE: this._pushStatement(declar, nodes)
|
VALUE: this._pushStatement(declar, nodes)
|
||||||
}, true);
|
}, true);
|
||||||
|
|
||||||
|
|||||||
@ -8,16 +8,16 @@ export default class CommonJSFormatter extends DefaultFormatter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_setup(conditional) {
|
_setup(conditional) {
|
||||||
var file = this.file;
|
let file = this.file;
|
||||||
var scope = file.scope;
|
let scope = file.scope;
|
||||||
|
|
||||||
scope.rename("module");
|
scope.rename("module");
|
||||||
scope.rename("exports");
|
scope.rename("exports");
|
||||||
|
|
||||||
if (!this.noInteropRequireImport && conditional) {
|
if (!this.noInteropRequireImport && conditional) {
|
||||||
var templateName = "exports-module-declaration";
|
let templateName = "exports-module-declaration";
|
||||||
if (this.file.isLoose("es6.modules")) templateName += "-loose";
|
if (this.file.isLoose("es6.modules")) templateName += "-loose";
|
||||||
var declar = util.template(templateName, true);
|
let declar = util.template(templateName, true);
|
||||||
declar._blockHoist = 3;
|
declar._blockHoist = 3;
|
||||||
file.path.unshiftContainer("body", [declar]);
|
file.path.unshiftContainer("body", [declar]);
|
||||||
}
|
}
|
||||||
@ -38,9 +38,9 @@ export default class CommonJSFormatter extends DefaultFormatter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
importSpecifier(specifier, node, nodes, scope) {
|
importSpecifier(specifier, node, nodes, scope) {
|
||||||
var variableName = specifier.local;
|
let variableName = specifier.local;
|
||||||
|
|
||||||
var ref = this.getExternalReference(node, nodes);
|
let ref = this.getExternalReference(node, nodes);
|
||||||
|
|
||||||
// import foo from "foo";
|
// import foo from "foo";
|
||||||
if (t.isSpecifierDefault(specifier)) {
|
if (t.isSpecifierDefault(specifier)) {
|
||||||
@ -51,7 +51,7 @@ export default class CommonJSFormatter extends DefaultFormatter {
|
|||||||
} else if (this.noInteropRequireImport) {
|
} else if (this.noInteropRequireImport) {
|
||||||
this.remaps.add(scope, variableName.name, t.memberExpression(ref, t.identifier("default")));
|
this.remaps.add(scope, variableName.name, t.memberExpression(ref, t.identifier("default")));
|
||||||
} else {
|
} else {
|
||||||
var uid = this.scope.generateUidIdentifierBasedOnNode(node, "import");
|
let uid = this.scope.generateUidIdentifierBasedOnNode(node, "import");
|
||||||
|
|
||||||
nodes.push(t.variableDeclaration("var", [
|
nodes.push(t.variableDeclaration("var", [
|
||||||
t.variableDeclarator(uid, t.callExpression(this.file.addHelper("interop-require-default"), [ref]))
|
t.variableDeclarator(uid, t.callExpression(this.file.addHelper("interop-require-default"), [ref]))
|
||||||
@ -101,8 +101,8 @@ export default class CommonJSFormatter extends DefaultFormatter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_getExternalReference(node, nodes) {
|
_getExternalReference(node, nodes) {
|
||||||
var call = t.callExpression(t.identifier("require"), [node.source]);
|
let call = t.callExpression(t.identifier("require"), [node.source]);
|
||||||
var uid;
|
let uid;
|
||||||
|
|
||||||
if (this.isModuleType(node, "absolute")) {
|
if (this.isModuleType(node, "absolute")) {
|
||||||
// absolute module reference
|
// absolute module reference
|
||||||
@ -114,7 +114,7 @@ export default class CommonJSFormatter extends DefaultFormatter {
|
|||||||
|
|
||||||
uid = uid || node.specifiers[0].local;
|
uid = uid || node.specifiers[0].local;
|
||||||
|
|
||||||
var declar = t.variableDeclaration("var", [
|
let declar = t.variableDeclaration("var", [
|
||||||
t.variableDeclarator(uid, call)
|
t.variableDeclarator(uid, call)
|
||||||
]);
|
]);
|
||||||
nodes.push(declar);
|
nodes.push(declar);
|
||||||
|
|||||||
@ -3,7 +3,7 @@ import * as t from "babel-types";
|
|||||||
|
|
||||||
export default class IgnoreFormatter extends DefaultFormatter {
|
export default class IgnoreFormatter extends DefaultFormatter {
|
||||||
exportDeclaration(node, nodes) {
|
exportDeclaration(node, nodes) {
|
||||||
var declar = t.toStatement(node.declaration, true);
|
let declar = t.toStatement(node.declaration, true);
|
||||||
if (declar) nodes.push(t.inherits(declar, node));
|
if (declar) nodes.push(t.inherits(declar, node));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import extend from "lodash/object/extend";
|
import extend from "lodash/object/extend";
|
||||||
import * as t from "babel-types";
|
import * as t from "babel-types";
|
||||||
|
|
||||||
export var ModuleDeclaration = {
|
export let ModuleDeclaration = {
|
||||||
enter(node, parent, scope, formatter) {
|
enter(node, parent, scope, formatter) {
|
||||||
if (node.source) {
|
if (node.source) {
|
||||||
node.source.value = formatter.file.resolveModuleSource(node.source.value);
|
node.source.value = formatter.file.resolveModuleSource(node.source.value);
|
||||||
@ -10,23 +10,23 @@ export var ModuleDeclaration = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export var ImportDeclaration = {
|
export let ImportDeclaration = {
|
||||||
exit(node, parent, scope, formatter) {
|
exit(node, parent, scope, formatter) {
|
||||||
formatter.hasLocalImports = true;
|
formatter.hasLocalImports = true;
|
||||||
|
|
||||||
var specifiers = [];
|
let specifiers = [];
|
||||||
var imported = [];
|
let imported = [];
|
||||||
formatter.metadata.imports.push({
|
formatter.metadata.imports.push({
|
||||||
source: node.source.value,
|
source: node.source.value,
|
||||||
imported,
|
imported,
|
||||||
specifiers
|
specifiers
|
||||||
});
|
});
|
||||||
|
|
||||||
for (var specifier of (this.get("specifiers"): Array)) {
|
for (let specifier of (this.get("specifiers"): Array)) {
|
||||||
var ids = specifier.getBindingIdentifiers();
|
let ids = specifier.getBindingIdentifiers();
|
||||||
extend(formatter.localImports, ids);
|
extend(formatter.localImports, ids);
|
||||||
|
|
||||||
var local = specifier.node.local.name;
|
let local = specifier.node.local.name;
|
||||||
|
|
||||||
if (specifier.isImportDefaultSpecifier()) {
|
if (specifier.isImportDefaultSpecifier()) {
|
||||||
imported.push("default");
|
imported.push("default");
|
||||||
@ -38,7 +38,7 @@ export var ImportDeclaration = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (specifier.isImportSpecifier()) {
|
if (specifier.isImportSpecifier()) {
|
||||||
var importedName = specifier.node.imported.name;
|
let importedName = specifier.node.imported.name;
|
||||||
imported.push(importedName);
|
imported.push(importedName);
|
||||||
specifiers.push({
|
specifiers.push({
|
||||||
kind: "named",
|
kind: "named",
|
||||||
@ -61,17 +61,17 @@ export var ImportDeclaration = {
|
|||||||
export function ExportDeclaration(node, parent, scope, formatter) {
|
export function ExportDeclaration(node, parent, scope, formatter) {
|
||||||
formatter.hasLocalExports = true;
|
formatter.hasLocalExports = true;
|
||||||
|
|
||||||
var source = node.source ? node.source.value : null;
|
let source = node.source ? node.source.value : null;
|
||||||
var exports = formatter.metadata.exports;
|
let exports = formatter.metadata.exports;
|
||||||
|
|
||||||
// export function foo() {}
|
// export function foo() {}
|
||||||
// export var foo = "bar";
|
// export let foo = "bar";
|
||||||
var declar = this.get("declaration");
|
let declar = this.get("declaration");
|
||||||
if (declar.isStatement()) {
|
if (declar.isStatement()) {
|
||||||
var bindings = declar.getBindingIdentifiers();
|
let bindings = declar.getBindingIdentifiers();
|
||||||
|
|
||||||
for (var name in bindings) {
|
for (let name in bindings) {
|
||||||
var binding = bindings[name];
|
let binding = bindings[name];
|
||||||
formatter._addExport(name, binding);
|
formatter._addExport(name, binding);
|
||||||
|
|
||||||
exports.exported.push(name);
|
exports.exported.push(name);
|
||||||
@ -84,8 +84,8 @@ export function ExportDeclaration(node, parent, scope, formatter) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (this.isExportNamedDeclaration() && node.specifiers) {
|
if (this.isExportNamedDeclaration() && node.specifiers) {
|
||||||
for (var specifier of (node.specifiers: Array)) {
|
for (let specifier of (node.specifiers: Array)) {
|
||||||
var exported = specifier.exported.name;
|
let exported = specifier.exported.name;
|
||||||
exports.exported.push(exported);
|
exports.exported.push(exported);
|
||||||
|
|
||||||
// export foo from "bar";
|
// export foo from "bar";
|
||||||
@ -107,7 +107,7 @@ export function ExportDeclaration(node, parent, scope, formatter) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
var local = specifier.local;
|
let local = specifier.local;
|
||||||
if (!local) continue;
|
if (!local) continue;
|
||||||
|
|
||||||
formatter._addExport(local.name, specifier.exported);
|
formatter._addExport(local.name, specifier.exported);
|
||||||
@ -144,7 +144,7 @@ export function ExportDeclaration(node, parent, scope, formatter) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!t.isExportDefaultDeclaration(node) && !declar.isTypeAlias()) {
|
if (!t.isExportDefaultDeclaration(node) && !declar.isTypeAlias()) {
|
||||||
var onlyDefault = node.specifiers && node.specifiers.length === 1 && t.isSpecifierDefault(node.specifiers[0]);
|
let onlyDefault = node.specifiers && node.specifiers.length === 1 && t.isSpecifierDefault(node.specifiers[0]);
|
||||||
if (!onlyDefault) {
|
if (!onlyDefault) {
|
||||||
formatter.hasNonDefaultExports = true;
|
formatter.hasNonDefaultExports = true;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import * as t from "babel-types";
|
import * as t from "babel-types";
|
||||||
|
|
||||||
var remapVisitor = {
|
let remapVisitor = {
|
||||||
enter(node) {
|
enter(node) {
|
||||||
if (node._skipModulesRemap) {
|
if (node._skipModulesRemap) {
|
||||||
return this.skip();
|
return this.skip();
|
||||||
@ -8,9 +8,9 @@ var remapVisitor = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
ReferencedIdentifier(node, parent, scope, remaps) {
|
ReferencedIdentifier(node, parent, scope, remaps) {
|
||||||
var { formatter } = remaps;
|
let { formatter } = remaps;
|
||||||
|
|
||||||
var remap = remaps.get(scope, node.name);
|
let remap = remaps.get(scope, node.name);
|
||||||
if (!remap || node === remap) return;
|
if (!remap || node === remap) return;
|
||||||
|
|
||||||
if (!scope.hasBinding(node.name) ||
|
if (!scope.hasBinding(node.name) ||
|
||||||
@ -26,7 +26,7 @@ var remapVisitor = {
|
|||||||
AssignmentExpression: {
|
AssignmentExpression: {
|
||||||
exit(node, parent, scope, { formatter }) {
|
exit(node, parent, scope, { formatter }) {
|
||||||
if (!node._ignoreModulesRemap) {
|
if (!node._ignoreModulesRemap) {
|
||||||
var exported = formatter.getExport(node.left, scope);
|
let exported = formatter.getExport(node.left, scope);
|
||||||
if (exported) {
|
if (exported) {
|
||||||
return formatter.remapExportAssignment(node, exported);
|
return formatter.remapExportAssignment(node, exported);
|
||||||
}
|
}
|
||||||
@ -35,26 +35,26 @@ var remapVisitor = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
UpdateExpression(node, parent, scope, { formatter }) {
|
UpdateExpression(node, parent, scope, { formatter }) {
|
||||||
var exported = formatter.getExport(node.argument, scope);
|
let exported = formatter.getExport(node.argument, scope);
|
||||||
if (!exported) return;
|
if (!exported) return;
|
||||||
|
|
||||||
this.skip();
|
this.skip();
|
||||||
|
|
||||||
// expand to long file assignment expression
|
// expand to long file assignment expression
|
||||||
var assign = t.assignmentExpression(node.operator[0] + "=", node.argument, t.numberLiteral(1));
|
let assign = t.assignmentExpression(node.operator[0] + "=", node.argument, t.numberLiteral(1));
|
||||||
|
|
||||||
// remap this assignment expression
|
// remap this assignment expression
|
||||||
var remapped = formatter.remapExportAssignment(assign, exported);
|
let remapped = formatter.remapExportAssignment(assign, exported);
|
||||||
|
|
||||||
// we don't need to change the result
|
// we don't need to change the result
|
||||||
if (t.isExpressionStatement(parent) || node.prefix) {
|
if (t.isExpressionStatement(parent) || node.prefix) {
|
||||||
return remapped;
|
return remapped;
|
||||||
}
|
}
|
||||||
|
|
||||||
var nodes = [];
|
let nodes = [];
|
||||||
nodes.push(remapped);
|
nodes.push(remapped);
|
||||||
|
|
||||||
var operator;
|
let operator;
|
||||||
if (node.operator === "--") {
|
if (node.operator === "--") {
|
||||||
operator = "+";
|
operator = "+";
|
||||||
} else { // "++"
|
} else { // "++"
|
||||||
@ -112,7 +112,7 @@ export default class Remaps {
|
|||||||
|
|
||||||
clearAll() {
|
clearAll() {
|
||||||
if (this.all) {
|
if (this.all) {
|
||||||
for (var remap of (this.all: Array)) {
|
for (let remap of (this.all: Array)) {
|
||||||
remap.scope.removeData(this._getKey(remap.name));
|
remap.scope.removeData(this._getKey(remap.name));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,7 +5,7 @@ import last from "lodash/array/last";
|
|||||||
import map from "lodash/collection/map";
|
import map from "lodash/collection/map";
|
||||||
import * as t from "babel-types";
|
import * as t from "babel-types";
|
||||||
|
|
||||||
var hoistVariablesVisitor = {
|
let hoistVariablesVisitor = {
|
||||||
Function(path) {
|
Function(path) {
|
||||||
// nothing inside is accessible
|
// nothing inside is accessible
|
||||||
path.skip();
|
path.skip();
|
||||||
@ -20,19 +20,19 @@ var hoistVariablesVisitor = {
|
|||||||
// ignore block hoisted nodes as these can be left in
|
// ignore block hoisted nodes as these can be left in
|
||||||
if (state.formatter._canHoist(node)) return;
|
if (state.formatter._canHoist(node)) return;
|
||||||
|
|
||||||
var nodes = [];
|
let nodes = [];
|
||||||
|
|
||||||
for (var i = 0; i < node.declarations.length; i++) {
|
for (let i = 0; i < node.declarations.length; i++) {
|
||||||
var declar = node.declarations[i];
|
let declar = node.declarations[i];
|
||||||
state.hoistDeclarators.push(t.variableDeclarator(declar.id));
|
state.hoistDeclarators.push(t.variableDeclarator(declar.id));
|
||||||
if (declar.init) {
|
if (declar.init) {
|
||||||
// no initializer so we can just hoist it as-is
|
// no initializer so we can just hoist it as-is
|
||||||
var assign = t.expressionStatement(t.assignmentExpression("=", declar.id, declar.init));
|
let assign = t.expressionStatement(t.assignmentExpression("=", declar.id, declar.init));
|
||||||
nodes.push(assign);
|
nodes.push(assign);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// for (var i in test)
|
// for (let i in test)
|
||||||
if (t.isFor(parent) && parent.left === node) {
|
if (t.isFor(parent) && parent.left === node) {
|
||||||
return node.declarations[0].id;
|
return node.declarations[0].id;
|
||||||
}
|
}
|
||||||
@ -41,7 +41,7 @@ var hoistVariablesVisitor = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var hoistFunctionsVisitor = {
|
let hoistFunctionsVisitor = {
|
||||||
Function(path) {
|
Function(path) {
|
||||||
path.skip();
|
path.skip();
|
||||||
},
|
},
|
||||||
@ -54,13 +54,13 @@ var hoistFunctionsVisitor = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var runnerSettersVisitor = {
|
let runnerSettersVisitor = {
|
||||||
enter(path, state) {
|
enter(path, state) {
|
||||||
var { node } = path;
|
let { node } = path;
|
||||||
|
|
||||||
if (node._importSource === state.source) {
|
if (node._importSource === state.source) {
|
||||||
if (t.isVariableDeclaration(node)) {
|
if (t.isVariableDeclaration(node)) {
|
||||||
for (var declar of (node.declarations: Array)) {
|
for (let declar of (node.declarations: Array)) {
|
||||||
state.hoistDeclarators.push(t.variableDeclarator(declar.id));
|
state.hoistDeclarators.push(t.variableDeclarator(declar.id));
|
||||||
state.nodes.push(t.expressionStatement(
|
state.nodes.push(t.expressionStatement(
|
||||||
t.assignmentExpression("=", declar.id, declar.init)
|
t.assignmentExpression("=", declar.id, declar.init)
|
||||||
@ -93,16 +93,16 @@ export default class SystemFormatter extends AMDFormatter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
buildExportsWildcard(objectIdentifier, node) {
|
buildExportsWildcard(objectIdentifier, node) {
|
||||||
var leftIdentifier = this.scope.generateUidIdentifier("key");
|
let leftIdentifier = this.scope.generateUidIdentifier("key");
|
||||||
var valIdentifier = t.memberExpression(objectIdentifier, leftIdentifier, true);
|
let valIdentifier = t.memberExpression(objectIdentifier, leftIdentifier, true);
|
||||||
|
|
||||||
var left = t.variableDeclaration("var", [
|
let left = t.variableDeclaration("var", [
|
||||||
t.variableDeclarator(leftIdentifier)
|
t.variableDeclarator(leftIdentifier)
|
||||||
]);
|
]);
|
||||||
|
|
||||||
var right = objectIdentifier;
|
let right = objectIdentifier;
|
||||||
|
|
||||||
var block = t.blockStatement([
|
let block = t.blockStatement([
|
||||||
t.ifStatement(
|
t.ifStatement(
|
||||||
t.binaryExpression("!==", leftIdentifier, t.stringLiteral("default")),
|
t.binaryExpression("!==", leftIdentifier, t.stringLiteral("default")),
|
||||||
t.expressionStatement(this._buildExportCall(leftIdentifier, valIdentifier))
|
t.expressionStatement(this._buildExportCall(leftIdentifier, valIdentifier))
|
||||||
@ -113,7 +113,7 @@ export default class SystemFormatter extends AMDFormatter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
buildExportsAssignment(id, init, node) {
|
buildExportsAssignment(id, init, node) {
|
||||||
var call = this._buildExportCall(t.stringLiteral(id.name), init, true);
|
let call = this._buildExportCall(t.stringLiteral(id.name), init, true);
|
||||||
return this._addImportSource(call, node);
|
return this._addImportSource(call, node);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,9 +122,9 @@ export default class SystemFormatter extends AMDFormatter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
remapExportAssignment(node, exported) {
|
remapExportAssignment(node, exported) {
|
||||||
var assign = node;
|
let assign = node;
|
||||||
|
|
||||||
for (var i = 0; i < exported.length; i++) {
|
for (let i = 0; i < exported.length; i++) {
|
||||||
assign = this._buildExportCall(t.stringLiteral(exported[i].name), assign);
|
assign = this._buildExportCall(t.stringLiteral(exported[i].name), assign);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,7 +132,7 @@ export default class SystemFormatter extends AMDFormatter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_buildExportCall(id, init, isStatement) {
|
_buildExportCall(id, init, isStatement) {
|
||||||
var call = t.callExpression(this.exportIdentifier, [id, init]);
|
let call = t.callExpression(this.exportIdentifier, [id, init]);
|
||||||
if (isStatement) {
|
if (isStatement) {
|
||||||
return t.expressionStatement(call);
|
return t.expressionStatement(call);
|
||||||
} else {
|
} else {
|
||||||
@ -143,7 +143,7 @@ export default class SystemFormatter extends AMDFormatter {
|
|||||||
importSpecifier(specifier, node, nodes) {
|
importSpecifier(specifier, node, nodes) {
|
||||||
AMDFormatter.prototype.importSpecifier.apply(this, arguments);
|
AMDFormatter.prototype.importSpecifier.apply(this, arguments);
|
||||||
|
|
||||||
for (var remap of (this.remaps.getAll(): Array)) {
|
for (let remap of (this.remaps.getAll(): Array)) {
|
||||||
nodes.push(t.variableDeclaration("var", [
|
nodes.push(t.variableDeclaration("var", [
|
||||||
t.variableDeclarator(t.identifier(remap.name), remap.node)
|
t.variableDeclarator(t.identifier(remap.name), remap.node)
|
||||||
]));
|
]));
|
||||||
@ -155,10 +155,10 @@ export default class SystemFormatter extends AMDFormatter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_buildRunnerSetters(block, hoistDeclarators) {
|
_buildRunnerSetters(block, hoistDeclarators) {
|
||||||
var scope = this.file.scope;
|
let scope = this.file.scope;
|
||||||
|
|
||||||
return t.arrayExpression(map(this.ids, function (uid, source) {
|
return t.arrayExpression(map(this.ids, function (uid, source) {
|
||||||
var state = {
|
let state = {
|
||||||
hoistDeclarators: hoistDeclarators,
|
hoistDeclarators: hoistDeclarators,
|
||||||
source: source,
|
source: source,
|
||||||
nodes: []
|
nodes: []
|
||||||
@ -177,16 +177,16 @@ export default class SystemFormatter extends AMDFormatter {
|
|||||||
transform(program) {
|
transform(program) {
|
||||||
DefaultFormatter.prototype.transform.apply(this, arguments);
|
DefaultFormatter.prototype.transform.apply(this, arguments);
|
||||||
|
|
||||||
var hoistDeclarators = [];
|
let hoistDeclarators = [];
|
||||||
var moduleName = this.getModuleName();
|
let moduleName = this.getModuleName();
|
||||||
var moduleNameLiteral = t.stringLiteral(moduleName);
|
let moduleNameLiteral = t.stringLiteral(moduleName);
|
||||||
|
|
||||||
var block = t.blockStatement(program.body);
|
let block = t.blockStatement(program.body);
|
||||||
|
|
||||||
var setterListNode = this._buildRunnerSetters(block, hoistDeclarators);
|
let setterListNode = this._buildRunnerSetters(block, hoistDeclarators);
|
||||||
this._setters = setterListNode;
|
this._setters = setterListNode;
|
||||||
|
|
||||||
var runner = util.template("system", {
|
let runner = util.template("system", {
|
||||||
MODULE_DEPENDENCIES: t.arrayExpression(this.buildDependencyLiterals()),
|
MODULE_DEPENDENCIES: t.arrayExpression(this.buildDependencyLiterals()),
|
||||||
EXPORT_IDENTIFIER: this.exportIdentifier,
|
EXPORT_IDENTIFIER: this.exportIdentifier,
|
||||||
MODULE_NAME: moduleNameLiteral,
|
MODULE_NAME: moduleNameLiteral,
|
||||||
@ -194,10 +194,10 @@ export default class SystemFormatter extends AMDFormatter {
|
|||||||
EXECUTE: t.functionExpression(null, [], block)
|
EXECUTE: t.functionExpression(null, [], block)
|
||||||
}, true);
|
}, true);
|
||||||
|
|
||||||
var handlerBody = runner.expression.arguments[2].body.body;
|
let handlerBody = runner.expression.arguments[2].body.body;
|
||||||
if (!moduleName) runner.expression.arguments.shift();
|
if (!moduleName) runner.expression.arguments.shift();
|
||||||
|
|
||||||
var returnStatement = handlerBody.pop();
|
let returnStatement = handlerBody.pop();
|
||||||
|
|
||||||
// hoist up all variable declarations
|
// hoist up all variable declarations
|
||||||
this.file.scope.traverse(block, hoistVariablesVisitor, {
|
this.file.scope.traverse(block, hoistVariablesVisitor, {
|
||||||
@ -206,7 +206,7 @@ export default class SystemFormatter extends AMDFormatter {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (hoistDeclarators.length) {
|
if (hoistDeclarators.length) {
|
||||||
var hoistDeclar = t.variableDeclaration("var", hoistDeclarators);
|
let hoistDeclar = t.variableDeclaration("var", hoistDeclarators);
|
||||||
hoistDeclar._blockHoist = true;
|
hoistDeclar._blockHoist = true;
|
||||||
handlerBody.unshift(hoistDeclar);
|
handlerBody.unshift(hoistDeclar);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,38 +9,38 @@ export default class UMDFormatter extends AMDFormatter {
|
|||||||
transform(program) {
|
transform(program) {
|
||||||
DefaultFormatter.prototype.transform.apply(this, arguments);
|
DefaultFormatter.prototype.transform.apply(this, arguments);
|
||||||
|
|
||||||
var body = program.body;
|
let body = program.body;
|
||||||
|
|
||||||
// build an array of module names
|
// build an array of module names
|
||||||
|
|
||||||
var names = [];
|
let names = [];
|
||||||
for (let name in this.ids) {
|
for (let name in this.ids) {
|
||||||
names.push(t.stringLiteral(name));
|
names.push(t.stringLiteral(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
// factory
|
// factory
|
||||||
|
|
||||||
var ids = values(this.ids);
|
let ids = values(this.ids);
|
||||||
var args = [t.identifier("exports")];
|
let args = [t.identifier("exports")];
|
||||||
if (this.passModuleArg) args.push(t.identifier("module"));
|
if (this.passModuleArg) args.push(t.identifier("module"));
|
||||||
args = args.concat(ids);
|
args = args.concat(ids);
|
||||||
|
|
||||||
var factory = t.functionExpression(null, args, t.blockStatement(body));
|
let factory = t.functionExpression(null, args, t.blockStatement(body));
|
||||||
|
|
||||||
// amd
|
// amd
|
||||||
|
|
||||||
var defineArgs = [t.stringLiteral("exports")];
|
let defineArgs = [t.stringLiteral("exports")];
|
||||||
if (this.passModuleArg) defineArgs.push(t.stringLiteral("module"));
|
if (this.passModuleArg) defineArgs.push(t.stringLiteral("module"));
|
||||||
defineArgs = defineArgs.concat(names);
|
defineArgs = defineArgs.concat(names);
|
||||||
defineArgs = [t.arrayExpression(defineArgs)];
|
defineArgs = [t.arrayExpression(defineArgs)];
|
||||||
|
|
||||||
// common
|
// common
|
||||||
|
|
||||||
var testExports = util.template("test-exports");
|
let testExports = util.template("test-exports");
|
||||||
var testModule = util.template("test-module");
|
let testModule = util.template("test-module");
|
||||||
var commonTests = this.passModuleArg ? t.logicalExpression("&&", testExports, testModule) : testExports;
|
let commonTests = this.passModuleArg ? t.logicalExpression("&&", testExports, testModule) : testExports;
|
||||||
|
|
||||||
var commonArgs = [t.identifier("exports")];
|
let commonArgs = [t.identifier("exports")];
|
||||||
if (this.passModuleArg) commonArgs.push(t.identifier("module"));
|
if (this.passModuleArg) commonArgs.push(t.identifier("module"));
|
||||||
commonArgs = commonArgs.concat(names.map(function (name) {
|
commonArgs = commonArgs.concat(names.map(function (name) {
|
||||||
return t.callExpression(t.identifier("require"), [name]);
|
return t.callExpression(t.identifier("require"), [name]);
|
||||||
@ -48,25 +48,25 @@ export default class UMDFormatter extends AMDFormatter {
|
|||||||
|
|
||||||
// globals
|
// globals
|
||||||
|
|
||||||
var browserArgs = [];
|
let browserArgs = [];
|
||||||
if (this.passModuleArg) browserArgs.push(t.identifier("mod"));
|
if (this.passModuleArg) browserArgs.push(t.identifier("mod"));
|
||||||
|
|
||||||
for (let name in this.ids) {
|
for (let name in this.ids) {
|
||||||
var id = this.defaultIds[name] || t.identifier(t.toIdentifier(path.basename(name, path.extname(name))));
|
let id = this.defaultIds[name] || t.identifier(t.toIdentifier(path.basename(name, path.extname(name))));
|
||||||
browserArgs.push(t.memberExpression(t.identifier("global"), id));
|
browserArgs.push(t.memberExpression(t.identifier("global"), id));
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
||||||
var moduleName = this.getModuleName();
|
let moduleName = this.getModuleName();
|
||||||
if (moduleName) defineArgs.unshift(t.stringLiteral(moduleName));
|
if (moduleName) defineArgs.unshift(t.stringLiteral(moduleName));
|
||||||
|
|
||||||
//
|
//
|
||||||
var globalArg = this.file.opts.basename;
|
let globalArg = this.file.opts.basename;
|
||||||
if (moduleName) globalArg = moduleName;
|
if (moduleName) globalArg = moduleName;
|
||||||
globalArg = t.identifier(t.toIdentifier(globalArg));
|
globalArg = t.identifier(t.toIdentifier(globalArg));
|
||||||
|
|
||||||
var runner = util.template("umd-runner-body", {
|
let runner = util.template("umd-runner-body", {
|
||||||
AMD_ARGUMENTS: defineArgs,
|
AMD_ARGUMENTS: defineArgs,
|
||||||
COMMON_TEST: commonTests,
|
COMMON_TEST: commonTests,
|
||||||
COMMON_ARGUMENTS: commonArgs,
|
COMMON_ARGUMENTS: commonArgs,
|
||||||
|
|||||||
@ -9,7 +9,7 @@ export default class Pipeline {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pretransform(code: string, opts?: Object) {
|
pretransform(code: string, opts?: Object) {
|
||||||
var file = new File(opts, this);
|
let file = new File(opts, this);
|
||||||
return file.wrap(code, function () {
|
return file.wrap(code, function () {
|
||||||
file.addCode(code);
|
file.addCode(code);
|
||||||
file.parseCode(code);
|
file.parseCode(code);
|
||||||
@ -18,7 +18,7 @@ export default class Pipeline {
|
|||||||
}
|
}
|
||||||
|
|
||||||
transform(code: string, opts?: Object) {
|
transform(code: string, opts?: Object) {
|
||||||
var file = new File(opts, this);
|
let file = new File(opts, this);
|
||||||
return file.wrap(code, function () {
|
return file.wrap(code, function () {
|
||||||
file.addCode(code);
|
file.addCode(code);
|
||||||
file.parseCode(code);
|
file.parseCode(code);
|
||||||
@ -29,7 +29,7 @@ export default class Pipeline {
|
|||||||
transformFromAst(ast, code, opts) {
|
transformFromAst(ast, code, opts) {
|
||||||
ast = normalizeAst(ast);
|
ast = normalizeAst(ast);
|
||||||
|
|
||||||
var file = new File(opts, this);
|
let file = new File(opts, this);
|
||||||
return file.wrap(code, function () {
|
return file.wrap(code, function () {
|
||||||
file.addCode(code);
|
file.addCode(code);
|
||||||
file.addAst(ast);
|
file.addAst(ast);
|
||||||
|
|||||||
@ -10,7 +10,7 @@ export default class PluginPass {
|
|||||||
}
|
}
|
||||||
|
|
||||||
transform() {
|
transform() {
|
||||||
var file = this.file;
|
let file = this.file;
|
||||||
file.log.debug(`Start transformer ${this.key}`);
|
file.log.debug(`Start transformer ${this.key}`);
|
||||||
traverse(file.ast, this.plugin.visitor, file.scope, file);
|
traverse(file.ast, this.plugin.visitor, file.scope, file);
|
||||||
file.log.debug(`Finish transformer ${this.key}`);
|
file.log.debug(`Finish transformer ${this.key}`);
|
||||||
|
|||||||
@ -8,7 +8,7 @@ export default class Plugin {
|
|||||||
plugin = this.raw = assign({}, plugin);
|
plugin = this.raw = assign({}, plugin);
|
||||||
|
|
||||||
function take(key) {
|
function take(key) {
|
||||||
var val = plugin[key];
|
let val = plugin[key];
|
||||||
delete plugin[key];
|
delete plugin[key];
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,7 +8,7 @@ import * as t from "babel-types";
|
|||||||
* **In**
|
* **In**
|
||||||
*
|
*
|
||||||
* ```javascript
|
* ```javascript
|
||||||
* var foo = {
|
* let foo = {
|
||||||
* get bar() {
|
* get bar() {
|
||||||
* return "bar";
|
* return "bar";
|
||||||
* }
|
* }
|
||||||
@ -18,7 +18,7 @@ import * as t from "babel-types";
|
|||||||
* **Out**
|
* **Out**
|
||||||
*
|
*
|
||||||
* ```javascript
|
* ```javascript
|
||||||
* var foo = Object.defineProperties({}, {
|
* let foo = Object.defineProperties({}, {
|
||||||
* bar: {
|
* bar: {
|
||||||
* get: function () {
|
* get: function () {
|
||||||
* return "bar";
|
* return "bar";
|
||||||
@ -30,7 +30,7 @@ import * as t from "babel-types";
|
|||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export var visitor = {
|
export let visitor = {
|
||||||
/**
|
/**
|
||||||
* Look for getters and setters on an object.
|
* Look for getters and setters on an object.
|
||||||
* Filter them out and wrap the object with an `Object.defineProperties` that
|
* Filter them out and wrap the object with an `Object.defineProperties` that
|
||||||
@ -38,8 +38,8 @@ export var visitor = {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
ObjectExpression(node, parent, scope, file) {
|
ObjectExpression(node, parent, scope, file) {
|
||||||
var hasAny = false;
|
let hasAny = false;
|
||||||
for (var prop of (node.properties: Array)) {
|
for (let prop of (node.properties: Array)) {
|
||||||
if (prop.kind === "get" || prop.kind === "set") {
|
if (prop.kind === "get" || prop.kind === "set") {
|
||||||
hasAny = true;
|
hasAny = true;
|
||||||
break;
|
break;
|
||||||
@ -47,7 +47,7 @@ export var visitor = {
|
|||||||
}
|
}
|
||||||
if (!hasAny) return;
|
if (!hasAny) return;
|
||||||
|
|
||||||
var mutatorMap = {};
|
let mutatorMap = {};
|
||||||
|
|
||||||
node.properties = node.properties.filter(function (prop) {
|
node.properties = node.properties.filter(function (prop) {
|
||||||
if (prop.kind === "get" || prop.kind === "set") {
|
if (prop.kind === "get" || prop.kind === "set") {
|
||||||
|
|||||||
@ -15,8 +15,8 @@ function isLet(node, parent) {
|
|||||||
|
|
||||||
// https://github.com/babel/babel/issues/255
|
// https://github.com/babel/babel/issues/255
|
||||||
if (isLetInitable(node, parent)) {
|
if (isLetInitable(node, parent)) {
|
||||||
for (var i = 0; i < node.declarations.length; i++) {
|
for (let i = 0; i < node.declarations.length; i++) {
|
||||||
var declar = node.declarations[i];
|
let declar = node.declarations[i];
|
||||||
declar.init = declar.init || scope.buildUndefinedNode();
|
declar.init = declar.init || scope.buildUndefinedNode();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -35,26 +35,26 @@ function isVar(node, parent, scope) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function standardizeLets(declars) {
|
function standardizeLets(declars) {
|
||||||
for (var declar of (declars: Array)) {
|
for (let declar of (declars: Array)) {
|
||||||
delete declar._let;
|
delete declar._let;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export var metadata = {
|
export let metadata = {
|
||||||
group: "builtin-advanced"
|
group: "builtin-advanced"
|
||||||
};
|
};
|
||||||
|
|
||||||
export var visitor = {
|
export let visitor = {
|
||||||
VariableDeclaration(node, parent, scope, file) {
|
VariableDeclaration(node, parent, scope, file) {
|
||||||
if (!isLet(node, parent, scope)) return;
|
if (!isLet(node, parent, scope)) return;
|
||||||
|
|
||||||
if (isLetInitable(node) && node._tdzThis) {
|
if (isLetInitable(node) && node._tdzThis) {
|
||||||
var nodes = [node];
|
let nodes = [node];
|
||||||
|
|
||||||
for (var i = 0; i < node.declarations.length; i++) {
|
for (let i = 0; i < node.declarations.length; i++) {
|
||||||
var decl = node.declarations[i];
|
let decl = node.declarations[i];
|
||||||
if (decl.init) {
|
if (decl.init) {
|
||||||
var assign = t.assignmentExpression("=", decl.id, decl.init);
|
let assign = t.assignmentExpression("=", decl.id, decl.init);
|
||||||
assign._ignoreBlockScopingTDZ = true;
|
assign._ignoreBlockScopingTDZ = true;
|
||||||
nodes.push(t.expressionStatement(assign));
|
nodes.push(t.expressionStatement(assign));
|
||||||
}
|
}
|
||||||
@ -74,29 +74,29 @@ export var visitor = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
Loop(node, parent, scope, file) {
|
Loop(node, parent, scope, file) {
|
||||||
var init = node.left || node.init;
|
let init = node.left || node.init;
|
||||||
if (isLet(init, node, scope)) {
|
if (isLet(init, node, scope)) {
|
||||||
t.ensureBlock(node);
|
t.ensureBlock(node);
|
||||||
node.body._letDeclarators = [init];
|
node.body._letDeclarators = [init];
|
||||||
}
|
}
|
||||||
|
|
||||||
var blockScoping = new BlockScoping(this, this.get("body"), parent, scope, file);
|
let blockScoping = new BlockScoping(this, this.get("body"), parent, scope, file);
|
||||||
return blockScoping.run();
|
return blockScoping.run();
|
||||||
},
|
},
|
||||||
|
|
||||||
"BlockStatement|Program"(block, parent, scope, file) {
|
"BlockStatement|Program"(block, parent, scope, file) {
|
||||||
if (!t.isLoop(parent)) {
|
if (!t.isLoop(parent)) {
|
||||||
var blockScoping = new BlockScoping(null, this, parent, scope, file);
|
let blockScoping = new BlockScoping(null, this, parent, scope, file);
|
||||||
blockScoping.run();
|
blockScoping.run();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
function replace(node, parent, scope, remaps) {
|
function replace(node, parent, scope, remaps) {
|
||||||
var remap = remaps[node.name];
|
let remap = remaps[node.name];
|
||||||
if (!remap) return;
|
if (!remap) return;
|
||||||
|
|
||||||
var ownBinding = scope.getBindingIdentifier(node.name);
|
let ownBinding = scope.getBindingIdentifier(node.name);
|
||||||
if (ownBinding === remap.binding) {
|
if (ownBinding === remap.binding) {
|
||||||
node.name = remap.uid;
|
node.name = remap.uid;
|
||||||
} else {
|
} else {
|
||||||
@ -106,12 +106,12 @@ function replace(node, parent, scope, remaps) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var replaceVisitor = {
|
let replaceVisitor = {
|
||||||
ReferencedIdentifier: replace,
|
ReferencedIdentifier: replace,
|
||||||
|
|
||||||
AssignmentExpression(node, parent, scope, remaps) {
|
AssignmentExpression(node, parent, scope, remaps) {
|
||||||
var ids = this.getBindingIdentifiers();
|
let ids = this.getBindingIdentifiers();
|
||||||
for (var name in ids) {
|
for (let name in ids) {
|
||||||
replace(ids[name], node, scope, remaps);
|
replace(ids[name], node, scope, remaps);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -123,8 +123,8 @@ function traverseReplace(node, parent, scope, remaps) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (t.isAssignmentExpression(node)) {
|
if (t.isAssignmentExpression(node)) {
|
||||||
var ids = t.getBindingIdentifiers(node);
|
let ids = t.getBindingIdentifiers(node);
|
||||||
for (var name in ids) {
|
for (let name in ids) {
|
||||||
replace(ids[name], parent, scope, remaps);
|
replace(ids[name], parent, scope, remaps);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -132,34 +132,34 @@ function traverseReplace(node, parent, scope, remaps) {
|
|||||||
scope.traverse(node, replaceVisitor, remaps);
|
scope.traverse(node, replaceVisitor, remaps);
|
||||||
}
|
}
|
||||||
|
|
||||||
var letReferenceBlockVisitor = traverse.visitors.merge([{
|
let letReferenceBlockVisitor = traverse.visitors.merge([{
|
||||||
Function(node, parent, scope, state) {
|
Function(node, parent, scope, state) {
|
||||||
this.traverse(letReferenceFunctionVisitor, state);
|
this.traverse(letReferenceFunctionVisitor, state);
|
||||||
return this.skip();
|
return this.skip();
|
||||||
}
|
}
|
||||||
}, tdzVisitor]);
|
}, tdzVisitor]);
|
||||||
|
|
||||||
var letReferenceFunctionVisitor = traverse.visitors.merge([{
|
let letReferenceFunctionVisitor = traverse.visitors.merge([{
|
||||||
ReferencedIdentifier(node, parent, scope, state) {
|
ReferencedIdentifier(node, parent, scope, state) {
|
||||||
var ref = state.letReferences[node.name];
|
let ref = state.letReferences[node.name];
|
||||||
|
|
||||||
// not a part of our scope
|
// not a part of our scope
|
||||||
if (!ref) return;
|
if (!ref) return;
|
||||||
|
|
||||||
// this scope has a variable with the same name so it couldn't belong
|
// this scope has a variable with the same name so it couldn't belong
|
||||||
// to our let scope
|
// to our let scope
|
||||||
var localBinding = scope.getBindingIdentifier(node.name);
|
let localBinding = scope.getBindingIdentifier(node.name);
|
||||||
if (localBinding && localBinding !== ref) return;
|
if (localBinding && localBinding !== ref) return;
|
||||||
|
|
||||||
state.closurify = true;
|
state.closurify = true;
|
||||||
}
|
}
|
||||||
}, tdzVisitor]);
|
}, tdzVisitor]);
|
||||||
|
|
||||||
var hoistVarDeclarationsVisitor = {
|
let hoistVarDeclarationsVisitor = {
|
||||||
enter(node, parent, scope, self) {
|
enter(node, parent, scope, self) {
|
||||||
if (this.isForStatement()) {
|
if (this.isForStatement()) {
|
||||||
if (isVar(node.init, node, scope)) {
|
if (isVar(node.init, node, scope)) {
|
||||||
var nodes = self.pushDeclar(node.init);
|
let nodes = self.pushDeclar(node.init);
|
||||||
if (nodes.length === 1) {
|
if (nodes.length === 1) {
|
||||||
node.init = nodes[0];
|
node.init = nodes[0];
|
||||||
} else {
|
} else {
|
||||||
@ -179,17 +179,17 @@ var hoistVarDeclarationsVisitor = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var loopLabelVisitor = {
|
let loopLabelVisitor = {
|
||||||
LabeledStatement(node, parent, scope, state) {
|
LabeledStatement(node, parent, scope, state) {
|
||||||
state.innerLabels.push(node.label.name);
|
state.innerLabels.push(node.label.name);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var continuationVisitor = {
|
let continuationVisitor = {
|
||||||
enter(node, parent, scope, state) {
|
enter(node, parent, scope, state) {
|
||||||
if (this.isAssignmentExpression() || this.isUpdateExpression()) {
|
if (this.isAssignmentExpression() || this.isUpdateExpression()) {
|
||||||
var bindings = this.getBindingIdentifiers();
|
let bindings = this.getBindingIdentifiers();
|
||||||
for (var name in bindings) {
|
for (let name in bindings) {
|
||||||
if (state.outsideReferences[name] !== scope.getBindingIdentifier(name)) continue;
|
if (state.outsideReferences[name] !== scope.getBindingIdentifier(name)) continue;
|
||||||
state.reassignments[name] = true;
|
state.reassignments[name] = true;
|
||||||
}
|
}
|
||||||
@ -205,9 +205,9 @@ function loopNodeTo(node) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var loopVisitor = {
|
let loopVisitor = {
|
||||||
Loop(node, parent, scope, state) {
|
Loop(node, parent, scope, state) {
|
||||||
var oldIgnoreLabeless = state.ignoreLabeless;
|
let oldIgnoreLabeless = state.ignoreLabeless;
|
||||||
state.ignoreLabeless = true;
|
state.ignoreLabeless = true;
|
||||||
this.traverse(loopVisitor, state);
|
this.traverse(loopVisitor, state);
|
||||||
state.ignoreLabeless = oldIgnoreLabeless;
|
state.ignoreLabeless = oldIgnoreLabeless;
|
||||||
@ -219,7 +219,7 @@ var loopVisitor = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
SwitchCase(node, parent, scope, state) {
|
SwitchCase(node, parent, scope, state) {
|
||||||
var oldInSwitchCase = state.inSwitchCase;
|
let oldInSwitchCase = state.inSwitchCase;
|
||||||
state.inSwitchCase = true;
|
state.inSwitchCase = true;
|
||||||
this.traverse(loopVisitor, state);
|
this.traverse(loopVisitor, state);
|
||||||
state.inSwitchCase = oldInSwitchCase;
|
state.inSwitchCase = oldInSwitchCase;
|
||||||
@ -227,8 +227,8 @@ var loopVisitor = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
"BreakStatement|ContinueStatement|ReturnStatement"(node, parent, scope, state) {
|
"BreakStatement|ContinueStatement|ReturnStatement"(node, parent, scope, state) {
|
||||||
var replace;
|
let replace;
|
||||||
var loopText = loopNodeTo(node);
|
let loopText = loopNodeTo(node);
|
||||||
|
|
||||||
if (loopText) {
|
if (loopText) {
|
||||||
if (node.label) {
|
if (node.label) {
|
||||||
@ -297,11 +297,11 @@ class BlockScoping {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
run() {
|
run() {
|
||||||
var block = this.block;
|
let block = this.block;
|
||||||
if (block._letDone) return;
|
if (block._letDone) return;
|
||||||
block._letDone = true;
|
block._letDone = true;
|
||||||
|
|
||||||
var needsClosure = this.getLetReferences();
|
let needsClosure = this.getLetReferences();
|
||||||
|
|
||||||
// this is a block within a `Function/Program` so we can safely leave it be
|
// this is a block within a `Function/Program` so we can safely leave it be
|
||||||
if (t.isFunction(this.parent) || t.isProgram(this.block)) return;
|
if (t.isFunction(this.parent) || t.isProgram(this.block)) return;
|
||||||
@ -321,24 +321,24 @@ class BlockScoping {
|
|||||||
}
|
}
|
||||||
|
|
||||||
remap() {
|
remap() {
|
||||||
var hasRemaps = false;
|
let hasRemaps = false;
|
||||||
var letRefs = this.letReferences;
|
let letRefs = this.letReferences;
|
||||||
var scope = this.scope;
|
let scope = this.scope;
|
||||||
|
|
||||||
// alright, so since we aren't wrapping this block in a closure
|
// alright, so since we aren't wrapping this block in a closure
|
||||||
// we have to check if any of our let variables collide with
|
// we have to check if any of our let variables collide with
|
||||||
// those in upper scopes and then if they do, generate a uid
|
// those in upper scopes and then if they do, generate a uid
|
||||||
// for them and replace all references with it
|
// for them and replace all references with it
|
||||||
var remaps = Object.create(null);
|
let remaps = Object.create(null);
|
||||||
|
|
||||||
for (var key in letRefs) {
|
for (let key in letRefs) {
|
||||||
// just an Identifier node we collected in `getLetReferences`
|
// just an Identifier node we collected in `getLetReferences`
|
||||||
// this is the defining identifier of a declaration
|
// this is the defining identifier of a declaration
|
||||||
var ref = letRefs[key];
|
let ref = letRefs[key];
|
||||||
|
|
||||||
// todo: could skip this if the colliding binding is in another function
|
// todo: could skip this if the colliding binding is in another function
|
||||||
if (scope.parentHasBinding(key) || scope.hasGlobal(key)) {
|
if (scope.parentHasBinding(key) || scope.hasGlobal(key)) {
|
||||||
var uid = scope.generateUidIdentifier(ref.name).name;
|
let uid = scope.generateUidIdentifier(ref.name).name;
|
||||||
ref.name = uid;
|
ref.name = uid;
|
||||||
|
|
||||||
hasRemaps = true;
|
hasRemaps = true;
|
||||||
@ -353,7 +353,7 @@ class BlockScoping {
|
|||||||
|
|
||||||
//
|
//
|
||||||
|
|
||||||
var loop = this.loop;
|
let loop = this.loop;
|
||||||
if (loop) {
|
if (loop) {
|
||||||
traverseReplace(loop.right, loop, scope, remaps);
|
traverseReplace(loop.right, loop, scope, remaps);
|
||||||
traverseReplace(loop.test, loop, scope, remaps);
|
traverseReplace(loop.test, loop, scope, remaps);
|
||||||
@ -364,14 +364,14 @@ class BlockScoping {
|
|||||||
}
|
}
|
||||||
|
|
||||||
wrapClosure() {
|
wrapClosure() {
|
||||||
var block = this.block;
|
let block = this.block;
|
||||||
|
|
||||||
var outsideRefs = this.outsideLetReferences;
|
let outsideRefs = this.outsideLetReferences;
|
||||||
|
|
||||||
// remap loop heads with colliding variables
|
// remap loop heads with colliding variables
|
||||||
if (this.loop) {
|
if (this.loop) {
|
||||||
for (var name in outsideRefs) {
|
for (let name in outsideRefs) {
|
||||||
var id = outsideRefs[name];
|
let id = outsideRefs[name];
|
||||||
|
|
||||||
if (this.scope.hasGlobal(id.name) || this.scope.parentHasBinding(id.name)) {
|
if (this.scope.hasGlobal(id.name) || this.scope.parentHasBinding(id.name)) {
|
||||||
delete outsideRefs[id.name];
|
delete outsideRefs[id.name];
|
||||||
@ -389,15 +389,15 @@ class BlockScoping {
|
|||||||
// `break`s, `continue`s, `return`s etc
|
// `break`s, `continue`s, `return`s etc
|
||||||
this.has = this.checkLoop();
|
this.has = this.checkLoop();
|
||||||
|
|
||||||
// hoist var references to retain scope
|
// hoist let references to retain scope
|
||||||
this.hoistVarDeclarations();
|
this.hoistVarDeclarations();
|
||||||
|
|
||||||
// turn outsideLetReferences into an array
|
// turn outsideLetReferences into an array
|
||||||
var params = values(outsideRefs);
|
let params = values(outsideRefs);
|
||||||
var args = values(outsideRefs);
|
let args = values(outsideRefs);
|
||||||
|
|
||||||
// build the closure that we're going to wrap the block with
|
// build the closure that we're going to wrap the block with
|
||||||
var fn = t.functionExpression(null, params, t.blockStatement(block.body));
|
let fn = t.functionExpression(null, params, t.blockStatement(block.body));
|
||||||
fn.shadow = true;
|
fn.shadow = true;
|
||||||
|
|
||||||
// continuation
|
// continuation
|
||||||
@ -406,7 +406,7 @@ class BlockScoping {
|
|||||||
// replace the current block body with the one we're going to build
|
// replace the current block body with the one we're going to build
|
||||||
block.body = this.body;
|
block.body = this.body;
|
||||||
|
|
||||||
var ref = fn;
|
let ref = fn;
|
||||||
|
|
||||||
if (this.loop) {
|
if (this.loop) {
|
||||||
ref = this.scope.generateUidIdentifier("loop");
|
ref = this.scope.generateUidIdentifier("loop");
|
||||||
@ -416,18 +416,18 @@ class BlockScoping {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// build a call and a unique id that we can assign the return value to
|
// build a call and a unique id that we can assign the return value to
|
||||||
var call = t.callExpression(ref, args);
|
let call = t.callExpression(ref, args);
|
||||||
var ret = this.scope.generateUidIdentifier("ret");
|
let ret = this.scope.generateUidIdentifier("ret");
|
||||||
|
|
||||||
// handle generators
|
// handle generators
|
||||||
var hasYield = traverse.hasType(fn.body, this.scope, "YieldExpression", t.FUNCTION_TYPES);
|
let hasYield = traverse.hasType(fn.body, this.scope, "YieldExpression", t.FUNCTION_TYPES);
|
||||||
if (hasYield) {
|
if (hasYield) {
|
||||||
fn.generator = true;
|
fn.generator = true;
|
||||||
call = t.yieldExpression(call, true);
|
call = t.yieldExpression(call, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// handlers async functions
|
// handlers async functions
|
||||||
var hasAsync = traverse.hasType(fn.body, this.scope, "AwaitExpression", t.FUNCTION_TYPES);
|
let hasAsync = traverse.hasType(fn.body, this.scope, "AwaitExpression", t.FUNCTION_TYPES);
|
||||||
if (hasAsync) {
|
if (hasAsync) {
|
||||||
fn.async = true;
|
fn.async = true;
|
||||||
call = t.awaitExpression(call);
|
call = t.awaitExpression(call);
|
||||||
@ -441,7 +441,7 @@ class BlockScoping {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
buildClosure(ret: { type: "Identifier" }, call: { type: "CallExpression" }) {
|
buildClosure(ret: { type: "Identifier" }, call: { type: "CallExpression" }) {
|
||||||
var has = this.has;
|
let has = this.has;
|
||||||
if (has.hasReturn || has.hasBreakContinue) {
|
if (has.hasReturn || has.hasBreakContinue) {
|
||||||
this.buildHas(ret, call);
|
this.buildHas(ret, call);
|
||||||
} else {
|
} else {
|
||||||
@ -458,18 +458,18 @@ class BlockScoping {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
addContinuations(fn) {
|
addContinuations(fn) {
|
||||||
var state = {
|
let state = {
|
||||||
reassignments: {},
|
reassignments: {},
|
||||||
outsideReferences: this.outsideLetReferences
|
outsideReferences: this.outsideLetReferences
|
||||||
};
|
};
|
||||||
|
|
||||||
this.scope.traverse(fn, continuationVisitor, state);
|
this.scope.traverse(fn, continuationVisitor, state);
|
||||||
|
|
||||||
for (var i = 0; i < fn.params.length; i++) {
|
for (let i = 0; i < fn.params.length; i++) {
|
||||||
var param = fn.params[i];
|
let param = fn.params[i];
|
||||||
if (!state.reassignments[param.name]) continue;
|
if (!state.reassignments[param.name]) continue;
|
||||||
|
|
||||||
var newParam = this.scope.generateUidIdentifier(param.name);
|
let newParam = this.scope.generateUidIdentifier(param.name);
|
||||||
fn.params[i] = newParam;
|
fn.params[i] = newParam;
|
||||||
|
|
||||||
this.scope.rename(param.name, newParam.name, fn);
|
this.scope.rename(param.name, newParam.name, fn);
|
||||||
@ -480,9 +480,9 @@ class BlockScoping {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getLetReferences() {
|
getLetReferences() {
|
||||||
var block = this.block;
|
let block = this.block;
|
||||||
|
|
||||||
var declarators = block._letDeclarators || [];
|
let declarators = block._letDeclarators || [];
|
||||||
|
|
||||||
//
|
//
|
||||||
for (let i = 0; i < declarators.length; i++) {
|
for (let i = 0; i < declarators.length; i++) {
|
||||||
@ -503,7 +503,7 @@ class BlockScoping {
|
|||||||
//
|
//
|
||||||
for (let i = 0; i < declarators.length; i++) {
|
for (let i = 0; i < declarators.length; i++) {
|
||||||
let declar = declarators[i];
|
let declar = declarators[i];
|
||||||
var keys = t.getBindingIdentifiers(declar);
|
let keys = t.getBindingIdentifiers(declar);
|
||||||
extend(this.letReferences, keys);
|
extend(this.letReferences, keys);
|
||||||
this.hasLetReferences = true;
|
this.hasLetReferences = true;
|
||||||
}
|
}
|
||||||
@ -511,10 +511,10 @@ class BlockScoping {
|
|||||||
// no let references so we can just quit
|
// no let references so we can just quit
|
||||||
if (!this.hasLetReferences) return;
|
if (!this.hasLetReferences) return;
|
||||||
|
|
||||||
// set let references to plain var references
|
// set let references to plain let references
|
||||||
standardizeLets(declarators);
|
standardizeLets(declarators);
|
||||||
|
|
||||||
var state = {
|
let state = {
|
||||||
letReferences: this.letReferences,
|
letReferences: this.letReferences,
|
||||||
closurify: false,
|
closurify: false,
|
||||||
file: this.file
|
file: this.file
|
||||||
@ -535,7 +535,7 @@ class BlockScoping {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
checkLoop(): Object {
|
checkLoop(): Object {
|
||||||
var state = {
|
let state = {
|
||||||
hasBreakContinue: false,
|
hasBreakContinue: false,
|
||||||
ignoreLabeless: false,
|
ignoreLabeless: false,
|
||||||
inSwitchCase: false,
|
inSwitchCase: false,
|
||||||
@ -552,7 +552,7 @@ class BlockScoping {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hoist all var declarations in this block to before it so they retain scope
|
* Hoist all let declarations in this block to before it so they retain scope
|
||||||
* once we wrap everything in a closure.
|
* once we wrap everything in a closure.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -566,21 +566,21 @@ class BlockScoping {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
pushDeclar(node: { type: "VariableDeclaration" }): Array<Object> {
|
pushDeclar(node: { type: "VariableDeclaration" }): Array<Object> {
|
||||||
var declars = [];
|
let declars = [];
|
||||||
var names = t.getBindingIdentifiers(node);
|
let names = t.getBindingIdentifiers(node);
|
||||||
for (var name in names) {
|
for (let name in names) {
|
||||||
declars.push(t.variableDeclarator(names[name]));
|
declars.push(t.variableDeclarator(names[name]));
|
||||||
}
|
}
|
||||||
|
|
||||||
this.body.push(t.variableDeclaration(node.kind, declars));
|
this.body.push(t.variableDeclaration(node.kind, declars));
|
||||||
|
|
||||||
var replace = [];
|
let replace = [];
|
||||||
|
|
||||||
for (var i = 0; i < node.declarations.length; i++) {
|
for (let i = 0; i < node.declarations.length; i++) {
|
||||||
var declar = node.declarations[i];
|
let declar = node.declarations[i];
|
||||||
if (!declar.init) continue;
|
if (!declar.init) continue;
|
||||||
|
|
||||||
var expr = t.assignmentExpression("=", declar.id, declar.init);
|
let expr = t.assignmentExpression("=", declar.id, declar.init);
|
||||||
replace.push(t.inherits(expr, declar));
|
replace.push(t.inherits(expr, declar));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -588,15 +588,15 @@ class BlockScoping {
|
|||||||
}
|
}
|
||||||
|
|
||||||
buildHas(ret: { type: "Identifier" }, call: { type: "CallExpression" }) {
|
buildHas(ret: { type: "Identifier" }, call: { type: "CallExpression" }) {
|
||||||
var body = this.body;
|
let body = this.body;
|
||||||
|
|
||||||
body.push(t.variableDeclaration("var", [
|
body.push(t.variableDeclaration("var", [
|
||||||
t.variableDeclarator(ret, call)
|
t.variableDeclarator(ret, call)
|
||||||
]));
|
]));
|
||||||
|
|
||||||
var retCheck;
|
let retCheck;
|
||||||
var has = this.has;
|
let has = this.has;
|
||||||
var cases = [];
|
let cases = [];
|
||||||
|
|
||||||
if (has.hasReturn) {
|
if (has.hasReturn) {
|
||||||
// typeof ret === "object"
|
// typeof ret === "object"
|
||||||
@ -606,7 +606,7 @@ class BlockScoping {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (has.hasBreakContinue) {
|
if (has.hasBreakContinue) {
|
||||||
for (var key in has.map) {
|
for (let key in has.map) {
|
||||||
cases.push(t.switchCase(t.stringLiteral(key), [has.map[key]]));
|
cases.push(t.switchCase(t.stringLiteral(key), [has.map[key]]));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -615,15 +615,15 @@ class BlockScoping {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (cases.length === 1) {
|
if (cases.length === 1) {
|
||||||
var single = cases[0];
|
let single = cases[0];
|
||||||
body.push(this.file.attachAuxiliaryComment(t.ifStatement(
|
body.push(this.file.attachAuxiliaryComment(t.ifStatement(
|
||||||
t.binaryExpression("===", ret, single.test),
|
t.binaryExpression("===", ret, single.test),
|
||||||
single.consequent[0]
|
single.consequent[0]
|
||||||
)));
|
)));
|
||||||
} else {
|
} else {
|
||||||
// https://github.com/babel/babel/issues/998
|
// https://github.com/babel/babel/issues/998
|
||||||
for (var i = 0; i < cases.length; i++) {
|
for (let i = 0; i < cases.length; i++) {
|
||||||
var caseConsequent = cases[i].consequent[0];
|
let caseConsequent = cases[i].consequent[0];
|
||||||
if (t.isBreakStatement(caseConsequent) && !caseConsequent.label) {
|
if (t.isBreakStatement(caseConsequent) && !caseConsequent.label) {
|
||||||
caseConsequent.label = this.loopLabel = this.loopLabel || this.file.scope.generateUidIdentifier("loop");
|
caseConsequent.label = this.loopLabel = this.loopLabel || this.file.scope.generateUidIdentifier("loop");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import * as t from "babel-types";
|
import * as t from "babel-types";
|
||||||
|
|
||||||
function getTDZStatus(refPath, bindingPath) {
|
function getTDZStatus(refPath, bindingPath) {
|
||||||
var executionStatus = bindingPath._guessExecutionStatusRelativeTo(refPath);
|
let executionStatus = bindingPath._guessExecutionStatusRelativeTo(refPath);
|
||||||
|
|
||||||
if (executionStatus === "before") {
|
if (executionStatus === "before") {
|
||||||
return "inside";
|
return "inside";
|
||||||
@ -20,25 +20,25 @@ function buildTDZAssert(node, file) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function isReference(node, scope, state) {
|
function isReference(node, scope, state) {
|
||||||
var declared = state.letReferences[node.name];
|
let declared = state.letReferences[node.name];
|
||||||
if (!declared) return false;
|
if (!declared) return false;
|
||||||
|
|
||||||
// declared node is different in this scope
|
// declared node is different in this scope
|
||||||
return scope.getBindingIdentifier(node.name) === declared;
|
return scope.getBindingIdentifier(node.name) === declared;
|
||||||
}
|
}
|
||||||
|
|
||||||
export var visitor = {
|
export let visitor = {
|
||||||
ReferencedIdentifier(node, parent, scope, state) {
|
ReferencedIdentifier(node, parent, scope, state) {
|
||||||
if (t.isFor(parent, { left: node })) return;
|
if (t.isFor(parent, { left: node })) return;
|
||||||
if (!isReference(node, scope, state)) return;
|
if (!isReference(node, scope, state)) return;
|
||||||
|
|
||||||
var bindingPath = scope.getBinding(node.name).path;
|
let bindingPath = scope.getBinding(node.name).path;
|
||||||
|
|
||||||
var status = getTDZStatus(this, bindingPath);
|
let status = getTDZStatus(this, bindingPath);
|
||||||
if (status === "inside") return;
|
if (status === "inside") return;
|
||||||
|
|
||||||
if (status === "maybe") {
|
if (status === "maybe") {
|
||||||
var assert = buildTDZAssert(node, state.file);
|
let assert = buildTDZAssert(node, state.file);
|
||||||
|
|
||||||
// add tdzThis to parent variable declarator so it's exploded
|
// add tdzThis to parent variable declarator so it's exploded
|
||||||
bindingPath.parent._tdzThis = true;
|
bindingPath.parent._tdzThis = true;
|
||||||
@ -65,11 +65,11 @@ export var visitor = {
|
|||||||
exit(node, parent, scope, state) {
|
exit(node, parent, scope, state) {
|
||||||
if (node._ignoreBlockScopingTDZ) return;
|
if (node._ignoreBlockScopingTDZ) return;
|
||||||
|
|
||||||
var nodes = [];
|
let nodes = [];
|
||||||
var ids = this.getBindingIdentifiers();
|
let ids = this.getBindingIdentifiers();
|
||||||
|
|
||||||
for (var name in ids) {
|
for (let name in ids) {
|
||||||
var id = ids[name];
|
let id = ids[name];
|
||||||
|
|
||||||
if (isReference(id, scope, state)) {
|
if (isReference(id, scope, state)) {
|
||||||
nodes.push(buildTDZAssert(id, state.file));
|
nodes.push(buildTDZAssert(id, state.file));
|
||||||
|
|||||||
@ -3,7 +3,7 @@ import VanillaTransformer from "./vanilla";
|
|||||||
import * as t from "babel-types";
|
import * as t from "babel-types";
|
||||||
import { bare } from "../../../helpers/name-method";
|
import { bare } from "../../../helpers/name-method";
|
||||||
|
|
||||||
export var visitor = {
|
export let visitor = {
|
||||||
ClassDeclaration(node) {
|
ClassDeclaration(node) {
|
||||||
return t.variableDeclaration("var", [
|
return t.variableDeclaration("var", [
|
||||||
t.variableDeclarator(node.id, t.toExpression(node))
|
t.variableDeclarator(node.id, t.toExpression(node))
|
||||||
@ -11,7 +11,7 @@ export var visitor = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
ClassExpression(node, parent, scope, file) {
|
ClassExpression(node, parent, scope, file) {
|
||||||
var inferred = bare(node, parent, scope);
|
let inferred = bare(node, parent, scope);
|
||||||
if (inferred) return inferred;
|
if (inferred) return inferred;
|
||||||
|
|
||||||
if (file.isLoose("es6.classes")) {
|
if (file.isLoose("es6.classes")) {
|
||||||
|
|||||||
@ -11,11 +11,11 @@ export default class LooseClassTransformer extends VanillaTransformer {
|
|||||||
if (!node.decorators) {
|
if (!node.decorators) {
|
||||||
// use assignments instead of define properties for loose classes
|
// use assignments instead of define properties for loose classes
|
||||||
|
|
||||||
var classRef = this.classRef;
|
let classRef = this.classRef;
|
||||||
if (!node.static) classRef = t.memberExpression(classRef, t.identifier("prototype"));
|
if (!node.static) classRef = t.memberExpression(classRef, t.identifier("prototype"));
|
||||||
var methodName = t.memberExpression(classRef, node.key, node.computed || t.isLiteral(node.key));
|
let methodName = t.memberExpression(classRef, node.key, node.computed || t.isLiteral(node.key));
|
||||||
|
|
||||||
var expr = t.expressionStatement(t.assignmentExpression("=", methodName, node.value));
|
let expr = t.expressionStatement(t.assignmentExpression("=", methodName, node.value));
|
||||||
t.inheritsComments(expr, node);
|
t.inheritsComments(expr, node);
|
||||||
this.body.push(expr);
|
this.body.push(expr);
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@ -10,7 +10,7 @@ import * as t from "babel-types";
|
|||||||
|
|
||||||
const PROPERTY_COLLISION_METHOD_NAME = "__initializeProperties";
|
const PROPERTY_COLLISION_METHOD_NAME = "__initializeProperties";
|
||||||
|
|
||||||
var collectPropertyReferencesVisitor = {
|
let collectPropertyReferencesVisitor = {
|
||||||
Identifier: {
|
Identifier: {
|
||||||
enter(node, parent, scope, state) {
|
enter(node, parent, scope, state) {
|
||||||
if (this.parentPath.isClassProperty({ key: node })) {
|
if (this.parentPath.isClassProperty({ key: node })) {
|
||||||
@ -24,7 +24,7 @@ var collectPropertyReferencesVisitor = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var verifyConstructorVisitor = {
|
let verifyConstructorVisitor = {
|
||||||
MethodDefinition() {
|
MethodDefinition() {
|
||||||
this.skip();
|
this.skip();
|
||||||
},
|
},
|
||||||
@ -54,7 +54,7 @@ var verifyConstructorVisitor = {
|
|||||||
if (state.isDerived && !state.hasBareSuper) {
|
if (state.isDerived && !state.hasBareSuper) {
|
||||||
if (this.inShadow()) {
|
if (this.inShadow()) {
|
||||||
// https://github.com/babel/babel/issues/1920
|
// https://github.com/babel/babel/issues/1920
|
||||||
var thisAlias = state.constructorPath.getData("this");
|
let thisAlias = state.constructorPath.getData("this");
|
||||||
|
|
||||||
if (!thisAlias) {
|
if (!thisAlias) {
|
||||||
thisAlias = state.constructorPath.setData(
|
thisAlias = state.constructorPath.setData(
|
||||||
@ -111,19 +111,19 @@ export default class ClassTransformer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
run() {
|
run() {
|
||||||
var superName = this.superName;
|
let superName = this.superName;
|
||||||
var file = this.file;
|
let file = this.file;
|
||||||
var body = this.body;
|
let body = this.body;
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
||||||
var constructorBody = this.constructorBody = t.blockStatement([]);
|
let constructorBody = this.constructorBody = t.blockStatement([]);
|
||||||
this.constructor = this.buildConstructor();
|
this.constructor = this.buildConstructor();
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
||||||
var closureParams = [];
|
let closureParams = [];
|
||||||
var closureArgs = [];
|
let closureArgs = [];
|
||||||
|
|
||||||
//
|
//
|
||||||
if (this.isDerived) {
|
if (this.isDerived) {
|
||||||
@ -136,7 +136,7 @@ export default class ClassTransformer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
var decorators = this.node.decorators;
|
let decorators = this.node.decorators;
|
||||||
if (decorators) {
|
if (decorators) {
|
||||||
// this is so super calls and the decorators have access to the raw function
|
// this is so super calls and the decorators have access to the raw function
|
||||||
this.directRef = this.scope.generateUidIdentifier(this.classRef);
|
this.directRef = this.scope.generateUidIdentifier(this.classRef);
|
||||||
@ -166,19 +166,19 @@ export default class ClassTransformer {
|
|||||||
//
|
//
|
||||||
body.push(t.returnStatement(this.classRef));
|
body.push(t.returnStatement(this.classRef));
|
||||||
|
|
||||||
var container = t.functionExpression(null, closureParams, t.blockStatement(body));
|
let container = t.functionExpression(null, closureParams, t.blockStatement(body));
|
||||||
container.shadow = true;
|
container.shadow = true;
|
||||||
return t.callExpression(container, closureArgs);
|
return t.callExpression(container, closureArgs);
|
||||||
}
|
}
|
||||||
|
|
||||||
buildConstructor() {
|
buildConstructor() {
|
||||||
var func = t.functionDeclaration(this.classRef, [], this.constructorBody);
|
let func = t.functionDeclaration(this.classRef, [], this.constructorBody);
|
||||||
t.inherits(func, this.node);
|
t.inherits(func, this.node);
|
||||||
return func;
|
return func;
|
||||||
}
|
}
|
||||||
|
|
||||||
pushToMap(node, enumerable, kind = "value") {
|
pushToMap(node, enumerable, kind = "value") {
|
||||||
var mutatorMap;
|
let mutatorMap;
|
||||||
if (node.static) {
|
if (node.static) {
|
||||||
this.hasStaticDescriptors = true;
|
this.hasStaticDescriptors = true;
|
||||||
mutatorMap = this.staticMutatorMap;
|
mutatorMap = this.staticMutatorMap;
|
||||||
@ -187,7 +187,7 @@ export default class ClassTransformer {
|
|||||||
mutatorMap = this.instanceMutatorMap;
|
mutatorMap = this.instanceMutatorMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
var map = defineMap.push(mutatorMap, node, kind, this.file);
|
let map = defineMap.push(mutatorMap, node, kind, this.file);
|
||||||
|
|
||||||
if (enumerable) {
|
if (enumerable) {
|
||||||
map.enumerable = t.booleanLiteral(true);
|
map.enumerable = t.booleanLiteral(true);
|
||||||
@ -204,15 +204,15 @@ export default class ClassTransformer {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
constructorMeMaybe() {
|
constructorMeMaybe() {
|
||||||
var hasConstructor = false;
|
let hasConstructor = false;
|
||||||
var paths = this.path.get("body.body");
|
let paths = this.path.get("body.body");
|
||||||
for (var path of (paths: Array)) {
|
for (let path of (paths: Array)) {
|
||||||
hasConstructor = path.equals("kind", "constructor");
|
hasConstructor = path.equals("kind", "constructor");
|
||||||
if (hasConstructor) break;
|
if (hasConstructor) break;
|
||||||
}
|
}
|
||||||
if (hasConstructor) return;
|
if (hasConstructor) return;
|
||||||
|
|
||||||
var constructor;
|
let constructor;
|
||||||
if (this.isDerived) {
|
if (this.isDerived) {
|
||||||
constructor = util.template("class-derived-default-constructor");
|
constructor = util.template("class-derived-default-constructor");
|
||||||
} else {
|
} else {
|
||||||
@ -232,7 +232,7 @@ export default class ClassTransformer {
|
|||||||
this.placePropertyInitializers();
|
this.placePropertyInitializers();
|
||||||
|
|
||||||
if (this.userConstructor) {
|
if (this.userConstructor) {
|
||||||
var constructorBody = this.constructorBody;
|
let constructorBody = this.constructorBody;
|
||||||
constructorBody.body = constructorBody.body.concat(this.userConstructor.body.body);
|
constructorBody.body = constructorBody.body.concat(this.userConstructor.body.body);
|
||||||
t.inherits(this.constructor, this.userConstructor);
|
t.inherits(this.constructor, this.userConstructor);
|
||||||
t.inherits(constructorBody, this.userConstructor.body);
|
t.inherits(constructorBody, this.userConstructor.body);
|
||||||
@ -242,20 +242,20 @@ export default class ClassTransformer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pushBody() {
|
pushBody() {
|
||||||
var classBodyPaths = this.path.get("body.body");
|
let classBodyPaths = this.path.get("body.body");
|
||||||
|
|
||||||
for (var path of (classBodyPaths: Array)) {
|
for (let path of (classBodyPaths: Array)) {
|
||||||
var node = path.node;
|
let node = path.node;
|
||||||
|
|
||||||
if (node.decorators) {
|
if (node.decorators) {
|
||||||
memoiseDecorators(node.decorators, this.scope);
|
memoiseDecorators(node.decorators, this.scope);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (t.isMethodDefinition(node)) {
|
if (t.isMethodDefinition(node)) {
|
||||||
var isConstructor = node.kind === "constructor";
|
let isConstructor = node.kind === "constructor";
|
||||||
if (isConstructor) this.verifyConstructor(path);
|
if (isConstructor) this.verifyConstructor(path);
|
||||||
|
|
||||||
var replaceSupers = new ReplaceSupers({
|
let replaceSupers = new ReplaceSupers({
|
||||||
methodPath: path,
|
methodPath: path,
|
||||||
methodNode: node,
|
methodNode: node,
|
||||||
objectRef: this.directRef,
|
objectRef: this.directRef,
|
||||||
@ -290,11 +290,11 @@ export default class ClassTransformer {
|
|||||||
pushDescriptors() {
|
pushDescriptors() {
|
||||||
this.pushInherits();
|
this.pushInherits();
|
||||||
|
|
||||||
var body = this.body;
|
let body = this.body;
|
||||||
|
|
||||||
var instanceProps;
|
let instanceProps;
|
||||||
var staticProps;
|
let staticProps;
|
||||||
var classHelper = "create-class";
|
let classHelper = "create-class";
|
||||||
if (this.hasDecorators) classHelper = "create-decorated-class";
|
if (this.hasDecorators) classHelper = "create-decorated-class";
|
||||||
|
|
||||||
if (this.hasInstanceDescriptors) {
|
if (this.hasInstanceDescriptors) {
|
||||||
@ -309,10 +309,10 @@ export default class ClassTransformer {
|
|||||||
if (instanceProps) instanceProps = defineMap.toComputedObjectFromClass(instanceProps);
|
if (instanceProps) instanceProps = defineMap.toComputedObjectFromClass(instanceProps);
|
||||||
if (staticProps) staticProps = defineMap.toComputedObjectFromClass(staticProps);
|
if (staticProps) staticProps = defineMap.toComputedObjectFromClass(staticProps);
|
||||||
|
|
||||||
var nullNode = t.nullLiteral();
|
let nullNode = t.nullLiteral();
|
||||||
|
|
||||||
// (Constructor, instanceDescriptors, staticDescriptors, instanceInitializers, staticInitializers)
|
// (Constructor, instanceDescriptors, staticDescriptors, instanceInitializers, staticInitializers)
|
||||||
var args = [this.classRef, nullNode, nullNode, nullNode, nullNode];
|
let args = [this.classRef, nullNode, nullNode, nullNode, nullNode];
|
||||||
|
|
||||||
if (instanceProps) args[1] = instanceProps;
|
if (instanceProps) args[1] = instanceProps;
|
||||||
if (staticProps) args[2] = staticProps;
|
if (staticProps) args[2] = staticProps;
|
||||||
@ -327,7 +327,7 @@ export default class ClassTransformer {
|
|||||||
body.unshift(this.buildObjectAssignment(this.staticInitializersId));
|
body.unshift(this.buildObjectAssignment(this.staticInitializersId));
|
||||||
}
|
}
|
||||||
|
|
||||||
var lastNonNullIndex = 0;
|
let lastNonNullIndex = 0;
|
||||||
for (let i = 0; i < args.length; i++) {
|
for (let i = 0; i < args.length; i++) {
|
||||||
if (args[i] !== nullNode) lastNonNullIndex = i;
|
if (args[i] !== nullNode) lastNonNullIndex = i;
|
||||||
}
|
}
|
||||||
@ -349,11 +349,11 @@ export default class ClassTransformer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
placePropertyInitializers() {
|
placePropertyInitializers() {
|
||||||
var body = this.instancePropBody;
|
let body = this.instancePropBody;
|
||||||
if (!body.length) return;
|
if (!body.length) return;
|
||||||
|
|
||||||
if (this.hasPropertyCollision()) {
|
if (this.hasPropertyCollision()) {
|
||||||
var call = t.expressionStatement(t.callExpression(
|
let call = t.expressionStatement(t.callExpression(
|
||||||
t.memberExpression(t.thisExpression(), t.identifier(PROPERTY_COLLISION_METHOD_NAME)),
|
t.memberExpression(t.thisExpression(), t.identifier(PROPERTY_COLLISION_METHOD_NAME)),
|
||||||
[]
|
[]
|
||||||
));
|
));
|
||||||
@ -379,7 +379,7 @@ export default class ClassTransformer {
|
|||||||
|
|
||||||
hasPropertyCollision(): boolean {
|
hasPropertyCollision(): boolean {
|
||||||
if (this.userConstructorPath) {
|
if (this.userConstructorPath) {
|
||||||
for (var name in this.instancePropRefs) {
|
for (let name in this.instancePropRefs) {
|
||||||
if (this.userConstructorPath.scope.hasOwnBinding(name)) {
|
if (this.userConstructorPath.scope.hasOwnBinding(name)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -390,7 +390,7 @@ export default class ClassTransformer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
verifyConstructor(path: NodePath) {
|
verifyConstructor(path: NodePath) {
|
||||||
var state = {
|
let state = {
|
||||||
constructorPath: path.get("value"),
|
constructorPath: path.get("value"),
|
||||||
hasBareSuper: false,
|
hasBareSuper: false,
|
||||||
bareSuper: null,
|
bareSuper: null,
|
||||||
@ -400,7 +400,7 @@ export default class ClassTransformer {
|
|||||||
|
|
||||||
state.constructorPath.traverse(verifyConstructorVisitor, state);
|
state.constructorPath.traverse(verifyConstructorVisitor, state);
|
||||||
|
|
||||||
var thisAlias = state.constructorPath.getData("this");
|
let thisAlias = state.constructorPath.getData("this");
|
||||||
if (thisAlias && state.bareSuper) {
|
if (thisAlias && state.bareSuper) {
|
||||||
state.bareSuper.insertAfter(t.variableDeclaration("var", [
|
state.bareSuper.insertAfter(t.variableDeclaration("var", [
|
||||||
t.variableDeclarator(thisAlias, t.thisExpression())
|
t.variableDeclarator(thisAlias, t.thisExpression())
|
||||||
@ -442,7 +442,7 @@ export default class ClassTransformer {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (node.decorators) {
|
if (node.decorators) {
|
||||||
var body = [];
|
let body = [];
|
||||||
if (node.value) {
|
if (node.value) {
|
||||||
body.push(t.returnStatement(node.value));
|
body.push(t.returnStatement(node.value));
|
||||||
node.value = t.functionExpression(null, [], t.blockStatement(body));
|
node.value = t.functionExpression(null, [], t.blockStatement(body));
|
||||||
@ -451,8 +451,8 @@ export default class ClassTransformer {
|
|||||||
}
|
}
|
||||||
this.pushToMap(node, true, "initializer");
|
this.pushToMap(node, true, "initializer");
|
||||||
|
|
||||||
var initializers;
|
let initializers;
|
||||||
var target;
|
let target;
|
||||||
if (node.static) {
|
if (node.static) {
|
||||||
initializers = this.staticInitializersId = this.staticInitializersId || this.scope.generateUidIdentifier("staticInitializers");
|
initializers = this.staticInitializersId = this.staticInitializersId || this.scope.generateUidIdentifier("staticInitializers");
|
||||||
body = this.staticPropBody;
|
body = this.staticPropBody;
|
||||||
@ -492,13 +492,13 @@ export default class ClassTransformer {
|
|||||||
|
|
||||||
pushConstructor(method: { type: "MethodDefinition" }, path: NodePath) {
|
pushConstructor(method: { type: "MethodDefinition" }, path: NodePath) {
|
||||||
// https://github.com/babel/babel/issues/1077
|
// https://github.com/babel/babel/issues/1077
|
||||||
var fnPath = path.get("value");
|
let fnPath = path.get("value");
|
||||||
if (fnPath.scope.hasOwnBinding(this.classRef.name)) {
|
if (fnPath.scope.hasOwnBinding(this.classRef.name)) {
|
||||||
fnPath.scope.rename(this.classRef.name);
|
fnPath.scope.rename(this.classRef.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
var construct = this.constructor;
|
let construct = this.constructor;
|
||||||
var fn = method.value;
|
let fn = method.value;
|
||||||
|
|
||||||
this.userConstructorPath = fnPath;
|
this.userConstructorPath = fnPath;
|
||||||
this.userConstructor = fn;
|
this.userConstructor = fn;
|
||||||
@ -550,7 +550,7 @@ export default class ClassTransformer {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
pushDecorators() {
|
pushDecorators() {
|
||||||
var decorators = this.node.decorators;
|
let decorators = this.node.decorators;
|
||||||
if (!decorators) return;
|
if (!decorators) return;
|
||||||
|
|
||||||
this.body.push(t.variableDeclaration("var", [
|
this.body.push(t.variableDeclaration("var", [
|
||||||
@ -560,8 +560,8 @@ export default class ClassTransformer {
|
|||||||
// reverse the decorators so we execute them in the right order
|
// reverse the decorators so we execute them in the right order
|
||||||
decorators = decorators.reverse();
|
decorators = decorators.reverse();
|
||||||
|
|
||||||
for (var decorator of (decorators: Array)) {
|
for (let decorator of (decorators: Array)) {
|
||||||
var decoratorNode = util.template("class-decorator", {
|
let decoratorNode = util.template("class-decorator", {
|
||||||
DECORATOR: decorator.expression,
|
DECORATOR: decorator.expression,
|
||||||
CLASS_REF: this.classRef
|
CLASS_REF: this.classRef
|
||||||
}, true);
|
}, true);
|
||||||
|
|||||||
@ -2,19 +2,19 @@ import * as messages from "babel-messages";
|
|||||||
import * as util from "../../../util";
|
import * as util from "../../../util";
|
||||||
import * as t from "babel-types";
|
import * as t from "babel-types";
|
||||||
|
|
||||||
export var visitor = {
|
export let visitor = {
|
||||||
ForOfStatement(node, parent, scope, file) {
|
ForOfStatement(node, parent, scope, file) {
|
||||||
if (this.get("right").isArrayExpression()) {
|
if (this.get("right").isArrayExpression()) {
|
||||||
return _ForOfStatementArray.call(this, node, scope, file);
|
return _ForOfStatementArray.call(this, node, scope, file);
|
||||||
}
|
}
|
||||||
|
|
||||||
var callback = spec;
|
let callback = spec;
|
||||||
if (file.isLoose("es6.forOf")) callback = loose;
|
if (file.isLoose("es6.forOf")) callback = loose;
|
||||||
|
|
||||||
var build = callback(node, parent, scope, file);
|
let build = callback(node, parent, scope, file);
|
||||||
var declar = build.declar;
|
let declar = build.declar;
|
||||||
var loop = build.loop;
|
let loop = build.loop;
|
||||||
var block = loop.body;
|
let block = loop.body;
|
||||||
|
|
||||||
// ensure that it's a block so we can take all its statements
|
// ensure that it's a block so we can take all its statements
|
||||||
this.ensureBlock();
|
this.ensureBlock();
|
||||||
@ -40,20 +40,20 @@ export var visitor = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export function _ForOfStatementArray(node, scope) {
|
export function _ForOfStatementArray(node, scope) {
|
||||||
var nodes = [];
|
let nodes = [];
|
||||||
var right = node.right;
|
let right = node.right;
|
||||||
|
|
||||||
if (!t.isIdentifier(right) || !scope.hasBinding(right.name)) {
|
if (!t.isIdentifier(right) || !scope.hasBinding(right.name)) {
|
||||||
var uid = scope.generateUidIdentifier("arr");
|
let uid = scope.generateUidIdentifier("arr");
|
||||||
nodes.push(t.variableDeclaration("var", [
|
nodes.push(t.variableDeclaration("var", [
|
||||||
t.variableDeclarator(uid, right)
|
t.variableDeclarator(uid, right)
|
||||||
]));
|
]));
|
||||||
right = uid;
|
right = uid;
|
||||||
}
|
}
|
||||||
|
|
||||||
var iterationKey = scope.generateUidIdentifier("i");
|
let iterationKey = scope.generateUidIdentifier("i");
|
||||||
|
|
||||||
var loop = util.template("for-of-array", {
|
let loop = util.template("for-of-array", {
|
||||||
BODY: node.body,
|
BODY: node.body,
|
||||||
KEY: iterationKey,
|
KEY: iterationKey,
|
||||||
ARR: right
|
ARR: right
|
||||||
@ -62,9 +62,9 @@ export function _ForOfStatementArray(node, scope) {
|
|||||||
t.inherits(loop, node);
|
t.inherits(loop, node);
|
||||||
t.ensureBlock(loop);
|
t.ensureBlock(loop);
|
||||||
|
|
||||||
var iterationValue = t.memberExpression(right, iterationKey, true);
|
let iterationValue = t.memberExpression(right, iterationKey, true);
|
||||||
|
|
||||||
var left = node.left;
|
let left = node.left;
|
||||||
if (t.isVariableDeclaration(left)) {
|
if (t.isVariableDeclaration(left)) {
|
||||||
left.declarations[0].init = iterationValue;
|
left.declarations[0].init = iterationValue;
|
||||||
loop.body.body.unshift(left);
|
loop.body.body.unshift(left);
|
||||||
@ -81,15 +81,15 @@ export function _ForOfStatementArray(node, scope) {
|
|||||||
return nodes;
|
return nodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
var loose = function (node, parent, scope, file) {
|
let loose = function (node, parent, scope, file) {
|
||||||
var left = node.left;
|
let left = node.left;
|
||||||
var declar, id;
|
let declar, id;
|
||||||
|
|
||||||
if (t.isIdentifier(left) || t.isPattern(left) || t.isMemberExpression(left)) {
|
if (t.isIdentifier(left) || t.isPattern(left) || t.isMemberExpression(left)) {
|
||||||
// for (i of test), for ({ i } of test)
|
// for (i of test), for ({ i } of test)
|
||||||
id = left;
|
id = left;
|
||||||
} else if (t.isVariableDeclaration(left)) {
|
} else if (t.isVariableDeclaration(left)) {
|
||||||
// for (var i of test)
|
// for (let i of test)
|
||||||
id = scope.generateUidIdentifier("ref");
|
id = scope.generateUidIdentifier("ref");
|
||||||
declar = t.variableDeclaration(left.kind, [
|
declar = t.variableDeclaration(left.kind, [
|
||||||
t.variableDeclarator(left.declarations[0].id, id)
|
t.variableDeclarator(left.declarations[0].id, id)
|
||||||
@ -98,10 +98,10 @@ var loose = function (node, parent, scope, file) {
|
|||||||
throw file.errorWithNode(left, messages.get("unknownForHead", left.type));
|
throw file.errorWithNode(left, messages.get("unknownForHead", left.type));
|
||||||
}
|
}
|
||||||
|
|
||||||
var iteratorKey = scope.generateUidIdentifier("iterator");
|
let iteratorKey = scope.generateUidIdentifier("iterator");
|
||||||
var isArrayKey = scope.generateUidIdentifier("isArray");
|
let isArrayKey = scope.generateUidIdentifier("isArray");
|
||||||
|
|
||||||
var loop = util.template("for-of-loose", {
|
let loop = util.template("for-of-loose", {
|
||||||
LOOP_OBJECT: iteratorKey,
|
LOOP_OBJECT: iteratorKey,
|
||||||
IS_ARRAY: isArrayKey,
|
IS_ARRAY: isArrayKey,
|
||||||
OBJECT: node.right,
|
OBJECT: node.right,
|
||||||
@ -124,18 +124,18 @@ var loose = function (node, parent, scope, file) {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
var spec = function (node, parent, scope, file) {
|
let spec = function (node, parent, scope, file) {
|
||||||
var left = node.left;
|
let left = node.left;
|
||||||
var declar;
|
let declar;
|
||||||
|
|
||||||
var stepKey = scope.generateUidIdentifier("step");
|
let stepKey = scope.generateUidIdentifier("step");
|
||||||
var stepValue = t.memberExpression(stepKey, t.identifier("value"));
|
let stepValue = t.memberExpression(stepKey, t.identifier("value"));
|
||||||
|
|
||||||
if (t.isIdentifier(left) || t.isPattern(left) || t.isMemberExpression(left)) {
|
if (t.isIdentifier(left) || t.isPattern(left) || t.isMemberExpression(left)) {
|
||||||
// for (i of test), for ({ i } of test)
|
// for (i of test), for ({ i } of test)
|
||||||
declar = t.expressionStatement(t.assignmentExpression("=", left, stepValue));
|
declar = t.expressionStatement(t.assignmentExpression("=", left, stepValue));
|
||||||
} else if (t.isVariableDeclaration(left)) {
|
} else if (t.isVariableDeclaration(left)) {
|
||||||
// for (var i of test)
|
// for (let i of test)
|
||||||
declar = t.variableDeclaration(left.kind, [
|
declar = t.variableDeclaration(left.kind, [
|
||||||
t.variableDeclarator(left.declarations[0].id, stepValue)
|
t.variableDeclarator(left.declarations[0].id, stepValue)
|
||||||
]);
|
]);
|
||||||
@ -145,9 +145,9 @@ var spec = function (node, parent, scope, file) {
|
|||||||
|
|
||||||
//
|
//
|
||||||
|
|
||||||
var iteratorKey = scope.generateUidIdentifier("iterator");
|
let iteratorKey = scope.generateUidIdentifier("iterator");
|
||||||
|
|
||||||
var template = util.template("for-of", {
|
let template = util.template("for-of", {
|
||||||
ITERATOR_HAD_ERROR_KEY: scope.generateUidIdentifier("didIteratorError"),
|
ITERATOR_HAD_ERROR_KEY: scope.generateUidIdentifier("didIteratorError"),
|
||||||
ITERATOR_COMPLETION: scope.generateUidIdentifier("iteratorNormalCompletion"),
|
ITERATOR_COMPLETION: scope.generateUidIdentifier("iteratorNormalCompletion"),
|
||||||
ITERATOR_ERROR_KEY: scope.generateUidIdentifier("iteratorError"),
|
ITERATOR_ERROR_KEY: scope.generateUidIdentifier("iteratorError"),
|
||||||
@ -157,10 +157,10 @@ var spec = function (node, parent, scope, file) {
|
|||||||
BODY: null
|
BODY: null
|
||||||
});
|
});
|
||||||
|
|
||||||
var isLabeledParent = t.isLabeledStatement(parent);
|
let isLabeledParent = t.isLabeledStatement(parent);
|
||||||
|
|
||||||
var tryBody = template[3].block.body;
|
let tryBody = template[3].block.body;
|
||||||
var loop = tryBody[0];
|
let loop = tryBody[0];
|
||||||
|
|
||||||
if (isLabeledParent) {
|
if (isLabeledParent) {
|
||||||
tryBody[0] = t.labeledStatement(parent.label, loop);
|
tryBody[0] = t.labeledStatement(parent.label, loop);
|
||||||
|
|||||||
@ -8,19 +8,19 @@ function keepBlockHoist(node, nodes) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export var metadata = {
|
export let metadata = {
|
||||||
group: "builtin-modules"
|
group: "builtin-modules"
|
||||||
};
|
};
|
||||||
|
|
||||||
export var visitor = {
|
export let visitor = {
|
||||||
ImportDeclaration(node, parent, scope, file) {
|
ImportDeclaration(node, parent, scope, file) {
|
||||||
// flow type
|
// flow type
|
||||||
if (node.importKind === "type" || node.importKind === "typeof") return;
|
if (node.importKind === "type" || node.importKind === "typeof") return;
|
||||||
|
|
||||||
var nodes = [];
|
let nodes = [];
|
||||||
|
|
||||||
if (node.specifiers.length) {
|
if (node.specifiers.length) {
|
||||||
for (var specifier of (node.specifiers: Array)) {
|
for (let specifier of (node.specifiers: Array)) {
|
||||||
file.moduleFormatter.importSpecifier(specifier, node, nodes, scope);
|
file.moduleFormatter.importSpecifier(specifier, node, nodes, scope);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -36,14 +36,14 @@ export var visitor = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
ExportAllDeclaration(node, parent, scope, file) {
|
ExportAllDeclaration(node, parent, scope, file) {
|
||||||
var nodes = [];
|
let nodes = [];
|
||||||
file.moduleFormatter.exportAllDeclaration(node, nodes, scope);
|
file.moduleFormatter.exportAllDeclaration(node, nodes, scope);
|
||||||
keepBlockHoist(node, nodes);
|
keepBlockHoist(node, nodes);
|
||||||
return nodes;
|
return nodes;
|
||||||
},
|
},
|
||||||
|
|
||||||
ExportDefaultDeclaration(node, parent, scope, file) {
|
ExportDefaultDeclaration(node, parent, scope, file) {
|
||||||
var nodes = [];
|
let nodes = [];
|
||||||
file.moduleFormatter.exportDeclaration(node, nodes, scope);
|
file.moduleFormatter.exportDeclaration(node, nodes, scope);
|
||||||
keepBlockHoist(node, nodes);
|
keepBlockHoist(node, nodes);
|
||||||
return nodes;
|
return nodes;
|
||||||
@ -53,13 +53,13 @@ export var visitor = {
|
|||||||
// flow type
|
// flow type
|
||||||
if (this.get("declaration").isTypeAlias()) return;
|
if (this.get("declaration").isTypeAlias()) return;
|
||||||
|
|
||||||
var nodes = [];
|
let nodes = [];
|
||||||
|
|
||||||
if (node.declaration) {
|
if (node.declaration) {
|
||||||
// make sure variable exports have an initializer
|
// make sure variable exports have an initializer
|
||||||
// this is done here to avoid duplicating it in the module formatters
|
// this is done here to avoid duplicating it in the module formatters
|
||||||
if (t.isVariableDeclaration(node.declaration)) {
|
if (t.isVariableDeclaration(node.declaration)) {
|
||||||
var declar = node.declaration.declarations[0];
|
let declar = node.declaration.declarations[0];
|
||||||
declar.init = declar.init || scope.buildUndefinedNode();
|
declar.init = declar.init || scope.buildUndefinedNode();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -5,7 +5,7 @@ function Property(path, node, scope, getObjectRef, file) {
|
|||||||
if (!node.method && node.kind === "init") return;
|
if (!node.method && node.kind === "init") return;
|
||||||
if (!t.isFunction(node.value)) return;
|
if (!t.isFunction(node.value)) return;
|
||||||
|
|
||||||
var replaceSupers = new ReplaceSupers({
|
let replaceSupers = new ReplaceSupers({
|
||||||
getObjectRef: getObjectRef,
|
getObjectRef: getObjectRef,
|
||||||
methodNode: node,
|
methodNode: node,
|
||||||
methodPath: path,
|
methodPath: path,
|
||||||
@ -17,13 +17,13 @@ function Property(path, node, scope, getObjectRef, file) {
|
|||||||
replaceSupers.replace();
|
replaceSupers.replace();
|
||||||
}
|
}
|
||||||
|
|
||||||
export var visitor = {
|
export let visitor = {
|
||||||
ObjectExpression(node, parent, scope, file) {
|
ObjectExpression(node, parent, scope, file) {
|
||||||
var objectRef;
|
let objectRef;
|
||||||
var getObjectRef = () => objectRef = objectRef || scope.generateUidIdentifier("obj");
|
let getObjectRef = () => objectRef = objectRef || scope.generateUidIdentifier("obj");
|
||||||
|
|
||||||
var propPaths = this.get("properties");
|
let propPaths = this.get("properties");
|
||||||
for (var i = 0; i < node.properties.length; i++) {
|
for (let i = 0; i < node.properties.length; i++) {
|
||||||
Property(propPaths[i], node.properties[i], scope, getObjectRef, file);
|
Property(propPaths[i], node.properties[i], scope, getObjectRef, file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -3,14 +3,14 @@ import getFunctionArity from "../../../helpers/get-function-arity";
|
|||||||
import * as util from "../../../../util";
|
import * as util from "../../../../util";
|
||||||
import * as t from "babel-types";
|
import * as t from "babel-types";
|
||||||
|
|
||||||
var hasDefaults = function (node) {
|
let hasDefaults = function (node) {
|
||||||
for (var i = 0; i < node.params.length; i++) {
|
for (let i = 0; i < node.params.length; i++) {
|
||||||
if (!t.isIdentifier(node.params[i])) return true;
|
if (!t.isIdentifier(node.params[i])) return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
var iifeVisitor = {
|
let iifeVisitor = {
|
||||||
ReferencedIdentifier(node, parent, scope, state) {
|
ReferencedIdentifier(node, parent, scope, state) {
|
||||||
if (node.name !== "eval") {
|
if (node.name !== "eval") {
|
||||||
if (!state.scope.hasOwnBinding(node.name)) return;
|
if (!state.scope.hasOwnBinding(node.name)) return;
|
||||||
@ -22,27 +22,27 @@ var iifeVisitor = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export var visitor = {
|
export let visitor = {
|
||||||
Function(node, parent, scope, file) {
|
Function(node, parent, scope, file) {
|
||||||
if (!hasDefaults(node)) return;
|
if (!hasDefaults(node)) return;
|
||||||
|
|
||||||
// ensure it's a block, useful for arrow functions
|
// ensure it's a block, useful for arrow functions
|
||||||
this.ensureBlock();
|
this.ensureBlock();
|
||||||
|
|
||||||
var state = {
|
let state = {
|
||||||
iife: false,
|
iife: false,
|
||||||
scope: scope
|
scope: scope
|
||||||
};
|
};
|
||||||
|
|
||||||
var body = [];
|
let body = [];
|
||||||
|
|
||||||
//
|
//
|
||||||
var argsIdentifier = t.identifier("arguments");
|
let argsIdentifier = t.identifier("arguments");
|
||||||
argsIdentifier._shadowedFunctionLiteral = this;
|
argsIdentifier._shadowedFunctionLiteral = this;
|
||||||
|
|
||||||
// push a default parameter definition
|
// push a default parameter definition
|
||||||
function pushDefNode(left, right, i) {
|
function pushDefNode(left, right, i) {
|
||||||
var defNode;
|
let defNode;
|
||||||
if (exceedsLastNonDefault(i) || t.isPattern(left) || file.transformers["es6.spec.blockScoping"].canTransform()) {
|
if (exceedsLastNonDefault(i) || t.isPattern(left) || file.transformers["es6.spec.blockScoping"].canTransform()) {
|
||||||
defNode = util.template("default-parameter", {
|
defNode = util.template("default-parameter", {
|
||||||
VARIABLE_NAME: left,
|
VARIABLE_NAME: left,
|
||||||
@ -66,12 +66,12 @@ export var visitor = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
var lastNonDefaultParam = getFunctionArity(node);
|
let lastNonDefaultParam = getFunctionArity(node);
|
||||||
|
|
||||||
//
|
//
|
||||||
var params = this.get("params");
|
let params = this.get("params");
|
||||||
for (var i = 0; i < params.length; i++) {
|
for (let i = 0; i < params.length; i++) {
|
||||||
var param = params[i];
|
let param = params[i];
|
||||||
|
|
||||||
if (!param.isAssignmentPattern()) {
|
if (!param.isAssignmentPattern()) {
|
||||||
if (!param.isIdentifier()) {
|
if (!param.isIdentifier()) {
|
||||||
@ -85,11 +85,11 @@ export var visitor = {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
var left = param.get("left");
|
let left = param.get("left");
|
||||||
var right = param.get("right");
|
let right = param.get("right");
|
||||||
|
|
||||||
if (exceedsLastNonDefault(i) || left.isPattern()) {
|
if (exceedsLastNonDefault(i) || left.isPattern()) {
|
||||||
var placeholder = scope.generateUidIdentifier("x");
|
let placeholder = scope.generateUidIdentifier("x");
|
||||||
placeholder._isDefaultPlaceholder = true;
|
placeholder._isDefaultPlaceholder = true;
|
||||||
node.params[i] = placeholder;
|
node.params[i] = placeholder;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -0,0 +1,23 @@
|
|||||||
|
import * as t from "babel-types";
|
||||||
|
|
||||||
|
export let visitor = {
|
||||||
|
Function(path) {
|
||||||
|
let params: Array = path.get("params");
|
||||||
|
let body = path.get("body");
|
||||||
|
|
||||||
|
for (let i = 0; i < params.length; i++) {
|
||||||
|
let param = params[i];
|
||||||
|
if (param.isArrayPattern() || param.isObjectPattern()) {
|
||||||
|
let uid = path.scope.generateUidIdentifierBasedOnNode(param.node);
|
||||||
|
|
||||||
|
let declar = t.variableDeclaration("let", [
|
||||||
|
t.variableDeclarator(param.node, uid)
|
||||||
|
]);
|
||||||
|
declar._blockHoist = params.length - i;
|
||||||
|
body.unshiftContainer("body", declar);
|
||||||
|
|
||||||
|
param.replaceWith(uid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
@ -3,8 +3,8 @@ import { visitors } from "babel-traverse";
|
|||||||
import * as def from "./default";
|
import * as def from "./default";
|
||||||
import * as rest from "./rest";
|
import * as rest from "./rest";
|
||||||
|
|
||||||
export var metadata = {
|
export let metadata = {
|
||||||
group: "builtin-advanced"
|
group: "builtin-advanced"
|
||||||
};
|
};
|
||||||
|
|
||||||
export var visitor = visitors.merge([rest.visitor, def.visitor]);
|
export let visitor = visitors.merge([rest.visitor, def.visitor]);
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import * as util from "../../../../util";
|
import * as util from "../../../../util";
|
||||||
import * as t from "babel-types";
|
import * as t from "babel-types";
|
||||||
|
|
||||||
var memberExpressionOptimisationVisitor = {
|
let memberExpressionOptimisationVisitor = {
|
||||||
Scope(node, parent, scope, state) {
|
Scope(node, parent, scope, state) {
|
||||||
// check if this scope has a local binding that will shadow the rest parameter
|
// check if this scope has a local binding that will shadow the rest parameter
|
||||||
if (!scope.bindingIdentifierEquals(state.name, state.outerBinding)) {
|
if (!scope.bindingIdentifierEquals(state.name, state.outerBinding)) {
|
||||||
@ -17,7 +17,7 @@ var memberExpressionOptimisationVisitor = {
|
|||||||
Function(node, parent, scope, state) {
|
Function(node, parent, scope, state) {
|
||||||
// skip over functions as whatever `arguments` we reference inside will refer
|
// skip over functions as whatever `arguments` we reference inside will refer
|
||||||
// to the wrong function
|
// to the wrong function
|
||||||
var oldNoOptimise = state.noOptimise;
|
let oldNoOptimise = state.noOptimise;
|
||||||
state.noOptimise = true;
|
state.noOptimise = true;
|
||||||
this.traverse(memberExpressionOptimisationVisitor, state);
|
this.traverse(memberExpressionOptimisationVisitor, state);
|
||||||
state.noOptimise = oldNoOptimise;
|
state.noOptimise = oldNoOptimise;
|
||||||
@ -39,7 +39,7 @@ var memberExpressionOptimisationVisitor = {
|
|||||||
if (this.parentPath.isMemberExpression({ computed: true, object: node })) {
|
if (this.parentPath.isMemberExpression({ computed: true, object: node })) {
|
||||||
// if we know that this member expression is referencing a number then we can safely
|
// if we know that this member expression is referencing a number then we can safely
|
||||||
// optimise it
|
// optimise it
|
||||||
var prop = this.parentPath.get("property");
|
let prop = this.parentPath.get("property");
|
||||||
if (prop.isBaseType("number")) {
|
if (prop.isBaseType("number")) {
|
||||||
state.candidates.push(this);
|
state.candidates.push(this);
|
||||||
return;
|
return;
|
||||||
@ -48,7 +48,7 @@ var memberExpressionOptimisationVisitor = {
|
|||||||
|
|
||||||
// optimise single spread args in calls
|
// optimise single spread args in calls
|
||||||
if (this.parentPath.isSpreadElement() && state.offset === 0) {
|
if (this.parentPath.isSpreadElement() && state.offset === 0) {
|
||||||
var call = this.parentPath.parentPath;
|
let call = this.parentPath.parentPath;
|
||||||
if (call.isCallExpression() && call.node.arguments.length === 1) {
|
if (call.isCallExpression() && call.node.arguments.length === 1) {
|
||||||
state.candidates.push(this);
|
state.candidates.push(this);
|
||||||
return;
|
return;
|
||||||
@ -75,8 +75,8 @@ var memberExpressionOptimisationVisitor = {
|
|||||||
function optimiseMemberExpression(parent, offset) {
|
function optimiseMemberExpression(parent, offset) {
|
||||||
if (offset === 0) return;
|
if (offset === 0) return;
|
||||||
|
|
||||||
var newExpr;
|
let newExpr;
|
||||||
var prop = parent.property;
|
let prop = parent.property;
|
||||||
|
|
||||||
if (t.isLiteral(prop)) {
|
if (t.isLiteral(prop)) {
|
||||||
prop.value += offset;
|
prop.value += offset;
|
||||||
@ -91,32 +91,32 @@ function hasRest(node) {
|
|||||||
return t.isRestElement(node.params[node.params.length - 1]);
|
return t.isRestElement(node.params[node.params.length - 1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
export var visitor = {
|
export let visitor = {
|
||||||
Function(node, parent, scope) {
|
Function(node, parent, scope) {
|
||||||
if (!hasRest(node)) return;
|
if (!hasRest(node)) return;
|
||||||
|
|
||||||
var restParam = node.params.pop();
|
let restParam = node.params.pop();
|
||||||
var rest = restParam.argument;
|
let rest = restParam.argument;
|
||||||
|
|
||||||
var argsId = t.identifier("arguments");
|
let argsId = t.identifier("arguments");
|
||||||
|
|
||||||
// otherwise `arguments` will be remapped in arrow functions
|
// otherwise `arguments` will be remapped in arrow functions
|
||||||
argsId._shadowedFunctionLiteral = this;
|
argsId._shadowedFunctionLiteral = this;
|
||||||
|
|
||||||
// support patterns
|
// support patterns
|
||||||
if (t.isPattern(rest)) {
|
if (t.isPattern(rest)) {
|
||||||
var pattern = rest;
|
let pattern = rest;
|
||||||
rest = scope.generateUidIdentifier("ref");
|
rest = scope.generateUidIdentifier("ref");
|
||||||
|
|
||||||
var declar = t.variableDeclaration("let", pattern.elements.map(function (elem, index) {
|
let declar = t.variableDeclaration("let", pattern.elements.map(function (elem, index) {
|
||||||
var accessExpr = t.memberExpression(rest, t.numberLiteral(index), true);
|
let accessExpr = t.memberExpression(rest, t.numberLiteral(index), true);
|
||||||
return t.variableDeclarator(elem, accessExpr);
|
return t.variableDeclarator(elem, accessExpr);
|
||||||
}));
|
}));
|
||||||
node.body.body.unshift(declar);
|
node.body.body.unshift(declar);
|
||||||
}
|
}
|
||||||
|
|
||||||
// check and optimise for extremely common cases
|
// check and optimise for extremely common cases
|
||||||
var state = {
|
let state = {
|
||||||
references: [],
|
references: [],
|
||||||
offset: node.params.length,
|
offset: node.params.length,
|
||||||
|
|
||||||
@ -138,7 +138,7 @@ export var visitor = {
|
|||||||
if (!state.deopted && !state.references.length) {
|
if (!state.deopted && !state.references.length) {
|
||||||
// we only have shorthands and there are no other references
|
// we only have shorthands and there are no other references
|
||||||
if (state.candidates.length) {
|
if (state.candidates.length) {
|
||||||
for (var candidate of (state.candidates: Array)) {
|
for (let candidate of (state.candidates: Array)) {
|
||||||
candidate.replaceWith(argsId);
|
candidate.replaceWith(argsId);
|
||||||
if (candidate.parentPath.isMemberExpression()) {
|
if (candidate.parentPath.isMemberExpression()) {
|
||||||
optimiseMemberExpression(candidate.parent, state.offset);
|
optimiseMemberExpression(candidate.parent, state.offset);
|
||||||
@ -155,12 +155,12 @@ export var visitor = {
|
|||||||
|
|
||||||
//
|
//
|
||||||
|
|
||||||
var start = t.numberLiteral(node.params.length);
|
let start = t.numberLiteral(node.params.length);
|
||||||
var key = scope.generateUidIdentifier("key");
|
let key = scope.generateUidIdentifier("key");
|
||||||
var len = scope.generateUidIdentifier("len");
|
let len = scope.generateUidIdentifier("len");
|
||||||
|
|
||||||
var arrKey = key;
|
let arrKey = key;
|
||||||
var arrLen = len;
|
let arrLen = len;
|
||||||
if (node.params.length) {
|
if (node.params.length) {
|
||||||
// this method has additional params, so we need to subtract
|
// this method has additional params, so we need to subtract
|
||||||
// the index of the current argument position from the
|
// the index of the current argument position from the
|
||||||
@ -180,7 +180,7 @@ export var visitor = {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
var loop = util.template("rest", {
|
let loop = util.template("rest", {
|
||||||
ARRAY_TYPE: restParam.typeAnnotation,
|
ARRAY_TYPE: restParam.typeAnnotation,
|
||||||
ARGUMENTS: argsId,
|
ARGUMENTS: argsId,
|
||||||
ARRAY_KEY: arrKey,
|
ARRAY_KEY: arrKey,
|
||||||
@ -198,10 +198,10 @@ export var visitor = {
|
|||||||
// perform allocation at the lowest common ancestor of all references
|
// perform allocation at the lowest common ancestor of all references
|
||||||
loop._blockHoist = 1;
|
loop._blockHoist = 1;
|
||||||
|
|
||||||
var target = this.getEarliestCommonAncestorFrom(state.references).getStatementParent();
|
let target = this.getEarliestCommonAncestorFrom(state.references).getStatementParent();
|
||||||
|
|
||||||
// don't perform the allocation inside a loop
|
// don't perform the allocation inside a loop
|
||||||
var highestLoop;
|
let highestLoop;
|
||||||
target.findParent(function (path) {
|
target.findParent(function (path) {
|
||||||
if (path.isLoop()) {
|
if (path.isLoop()) {
|
||||||
highestLoop = path;
|
highestLoop = path;
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import * as regex from "../../helpers/regex";
|
import * as regex from "../../helpers/regex";
|
||||||
import * as t from "babel-types";
|
import * as t from "babel-types";
|
||||||
|
|
||||||
export var visitor = {
|
export let visitor = {
|
||||||
RegexLiteral(node) {
|
RegexLiteral(node) {
|
||||||
if (!regex.is(node, "y")) return;
|
if (!regex.is(node, "y")) return;
|
||||||
return t.newExpression(t.identifier("RegExp"), [
|
return t.newExpression(t.identifier("RegExp"), [
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import rewritePattern from "regexpu/rewrite-pattern";
|
import rewritePattern from "regexpu/rewrite-pattern";
|
||||||
import * as regex from "../../helpers/regex";
|
import * as regex from "../../helpers/regex";
|
||||||
|
|
||||||
export var visitor = {
|
export let visitor = {
|
||||||
RegexLiteral(node) {
|
RegexLiteral(node) {
|
||||||
if (!regex.is(node, "u")) return;
|
if (!regex.is(node, "u")) return;
|
||||||
node.regex.pattern = rewritePattern(node.pattern, node.flags);
|
node.regex.pattern = rewritePattern(node.pattern, node.flags);
|
||||||
|
|||||||
@ -1,16 +1,16 @@
|
|||||||
import * as t from "babel-types";
|
import * as t from "babel-types";
|
||||||
|
|
||||||
export var metadata = {
|
export let metadata = {
|
||||||
group: "builtin-pre",
|
group: "builtin-pre",
|
||||||
optional: true
|
optional: true
|
||||||
};
|
};
|
||||||
|
|
||||||
export var visitor = {
|
export let visitor = {
|
||||||
ArrowFunctionExpression(node, parent, scope, file) {
|
ArrowFunctionExpression(node, parent, scope, file) {
|
||||||
if (node.shadow) return;
|
if (node.shadow) return;
|
||||||
node.shadow = { this: false };
|
node.shadow = { this: false };
|
||||||
|
|
||||||
var boundThis = t.thisExpression();
|
let boundThis = t.thisExpression();
|
||||||
boundThis._forceShadow = this;
|
boundThis._forceShadow = this;
|
||||||
|
|
||||||
// make sure that arrow function won't be instantiated
|
// make sure that arrow function won't be instantiated
|
||||||
|
|||||||
@ -1,13 +1,13 @@
|
|||||||
import * as t from "babel-types";
|
import * as t from "babel-types";
|
||||||
|
|
||||||
export var metadata = {
|
export let metadata = {
|
||||||
group: "builtin-pre",
|
group: "builtin-pre",
|
||||||
optional: true
|
optional: true
|
||||||
};
|
};
|
||||||
|
|
||||||
export var visitor = {
|
export let visitor = {
|
||||||
Program() {
|
Program() {
|
||||||
var id = this.scope.generateUidIdentifier("null");
|
let id = this.scope.generateUidIdentifier("null");
|
||||||
this.unshiftContainer("body", [
|
this.unshiftContainer("body", [
|
||||||
t.variableDeclaration("var", [
|
t.variableDeclaration("var", [
|
||||||
t.variableDeclarator(id, t.nullLiteral())
|
t.variableDeclarator(id, t.nullLiteral())
|
||||||
|
|||||||
@ -1,24 +1,24 @@
|
|||||||
import * as t from "babel-types";
|
import * as t from "babel-types";
|
||||||
|
|
||||||
export var metadata = {
|
export let metadata = {
|
||||||
optional: true
|
optional: true
|
||||||
};
|
};
|
||||||
|
|
||||||
export var visitor = {
|
export let visitor = {
|
||||||
UnaryExpression(node, parent, scope, file) {
|
UnaryExpression(node, parent, scope, file) {
|
||||||
if (node._ignoreSpecSymbols) return;
|
if (node._ignoreSpecSymbols) return;
|
||||||
|
|
||||||
if (this.parentPath.isBinaryExpression() && t.EQUALITY_BINARY_OPERATORS.indexOf(parent.operator) >= 0) {
|
if (this.parentPath.isBinaryExpression() && t.EQUALITY_BINARY_OPERATORS.indexOf(parent.operator) >= 0) {
|
||||||
// optimise `typeof foo === "string"` since we can determine that they'll never need to handle symbols
|
// optimise `typeof foo === "string"` since we can determine that they'll never need to handle symbols
|
||||||
var opposite = this.getOpposite();
|
let opposite = this.getOpposite();
|
||||||
if (opposite.isLiteral() && opposite.node.value !== "symbol" && opposite.node.value !== "object") return;
|
if (opposite.isLiteral() && opposite.node.value !== "symbol" && opposite.node.value !== "object") return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (node.operator === "typeof") {
|
if (node.operator === "typeof") {
|
||||||
var call = t.callExpression(file.addHelper("typeof"), [node.argument]);
|
let call = t.callExpression(file.addHelper("typeof"), [node.argument]);
|
||||||
if (this.get("argument").isIdentifier()) {
|
if (this.get("argument").isIdentifier()) {
|
||||||
var undefLiteral = t.stringLiteral("undefined");
|
let undefLiteral = t.stringLiteral("undefined");
|
||||||
var unary = t.unaryExpression("typeof", node.argument);
|
let unary = t.unaryExpression("typeof", node.argument);
|
||||||
unary._ignoreSpecSymbols = true;
|
unary._ignoreSpecSymbols = true;
|
||||||
return t.conditionalExpression(
|
return t.conditionalExpression(
|
||||||
t.binaryExpression("===", unary, undefLiteral),
|
t.binaryExpression("===", unary, undefLiteral),
|
||||||
|
|||||||
@ -1,15 +1,15 @@
|
|||||||
import * as t from "babel-types";
|
import * as t from "babel-types";
|
||||||
|
|
||||||
export var metadata = {
|
export let metadata = {
|
||||||
optional: true,
|
optional: true,
|
||||||
group: "builtin-pre"
|
group: "builtin-pre"
|
||||||
};
|
};
|
||||||
|
|
||||||
export var visitor = {
|
export let visitor = {
|
||||||
TemplateLiteral(node, parent) {
|
TemplateLiteral(node, parent) {
|
||||||
if (t.isTaggedTemplateExpression(parent)) return;
|
if (t.isTaggedTemplateExpression(parent)) return;
|
||||||
|
|
||||||
for (var i = 0; i < node.expressions.length; i++) {
|
for (let i = 0; i < node.expressions.length; i++) {
|
||||||
node.expressions[i] = t.callExpression(t.identifier("String"), [node.expressions[i]]);
|
node.expressions[i] = t.callExpression(t.identifier("String"), [node.expressions[i]]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,14 +5,14 @@ import * as util from "../../../util";
|
|||||||
import map from "lodash/collection/map";
|
import map from "lodash/collection/map";
|
||||||
import * as t from "babel-types";
|
import * as t from "babel-types";
|
||||||
|
|
||||||
export var metadata = {
|
export let metadata = {
|
||||||
group: "builtin-trailing"
|
group: "builtin-trailing"
|
||||||
};
|
};
|
||||||
|
|
||||||
export var visitor = {
|
export let visitor = {
|
||||||
Function(node, parent, scope, file) {
|
Function(node, parent, scope, file) {
|
||||||
if (node.generator || node.async) return;
|
if (node.generator || node.async) return;
|
||||||
var tailCall = new TailCallTransformer(this, scope, file);
|
let tailCall = new TailCallTransformer(this, scope, file);
|
||||||
tailCall.run();
|
tailCall.run();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -21,7 +21,7 @@ function returnBlock(expr) {
|
|||||||
return t.blockStatement([t.returnStatement(expr)]);
|
return t.blockStatement([t.returnStatement(expr)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
var visitor = {
|
let visitor = {
|
||||||
enter(node, parent) {
|
enter(node, parent) {
|
||||||
if (t.isTryStatement(parent)) {
|
if (t.isTryStatement(parent)) {
|
||||||
if (node === parent.block) {
|
if (node === parent.block) {
|
||||||
@ -101,14 +101,14 @@ class TailCallTransformer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getParams() {
|
getParams() {
|
||||||
var params = this.params;
|
let params = this.params;
|
||||||
|
|
||||||
if (!params) {
|
if (!params) {
|
||||||
params = this.node.params;
|
params = this.node.params;
|
||||||
this.paramDecls = [];
|
this.paramDecls = [];
|
||||||
|
|
||||||
for (var i = 0; i < params.length; i++) {
|
for (let i = 0; i < params.length; i++) {
|
||||||
var param = params[i];
|
let param = params[i];
|
||||||
if (!param._isDefaultPlaceholder) {
|
if (!param._isDefaultPlaceholder) {
|
||||||
this.paramDecls.push(t.variableDeclarator(
|
this.paramDecls.push(t.variableDeclarator(
|
||||||
param,
|
param,
|
||||||
@ -124,16 +124,16 @@ class TailCallTransformer {
|
|||||||
hasDeopt() {
|
hasDeopt() {
|
||||||
// check if the ownerId has been reassigned, if it has then it's not safe to
|
// check if the ownerId has been reassigned, if it has then it's not safe to
|
||||||
// perform optimisations
|
// perform optimisations
|
||||||
var ownerIdInfo = this.scope.getBinding(this.ownerId.name);
|
let ownerIdInfo = this.scope.getBinding(this.ownerId.name);
|
||||||
return ownerIdInfo && !ownerIdInfo.constant;
|
return ownerIdInfo && !ownerIdInfo.constant;
|
||||||
}
|
}
|
||||||
|
|
||||||
run() {
|
run() {
|
||||||
var node = this.node;
|
let node = this.node;
|
||||||
|
|
||||||
// only tail recursion can be optimized as for now, so we can skip anonymous
|
// only tail recursion can be optimized as for now, so we can skip anonymous
|
||||||
// functions entirely
|
// functions entirely
|
||||||
var ownerId = this.ownerId;
|
let ownerId = this.ownerId;
|
||||||
if (!ownerId) return;
|
if (!ownerId) return;
|
||||||
|
|
||||||
// traverse the function and look for tail recursion
|
// traverse the function and look for tail recursion
|
||||||
@ -150,10 +150,10 @@ class TailCallTransformer {
|
|||||||
|
|
||||||
//
|
//
|
||||||
|
|
||||||
var body = this.path.ensureBlock().body;
|
let body = this.path.ensureBlock().body;
|
||||||
|
|
||||||
for (var i = 0; i < body.length; i++) {
|
for (let i = 0; i < body.length; i++) {
|
||||||
var bodyNode = body[i];
|
let bodyNode = body[i];
|
||||||
if (!t.isFunctionDeclaration(bodyNode)) continue;
|
if (!t.isFunctionDeclaration(bodyNode)) continue;
|
||||||
|
|
||||||
bodyNode = body[i] = t.variableDeclaration("var", [
|
bodyNode = body[i] = t.variableDeclaration("var", [
|
||||||
@ -163,22 +163,22 @@ class TailCallTransformer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (this.vars.length > 0) {
|
if (this.vars.length > 0) {
|
||||||
var declarations = flatten(map(this.vars, function (decl) {
|
let declarations = flatten(map(this.vars, function (decl) {
|
||||||
return decl.declarations;
|
return decl.declarations;
|
||||||
}));
|
}));
|
||||||
|
|
||||||
var assignment = reduceRight(declarations, function (expr, decl) {
|
let assignment = reduceRight(declarations, function (expr, decl) {
|
||||||
return t.assignmentExpression("=", decl.id, expr);
|
return t.assignmentExpression("=", decl.id, expr);
|
||||||
}, this.scope.buildUndefinedNode());
|
}, this.scope.buildUndefinedNode());
|
||||||
|
|
||||||
var statement = t.expressionStatement(assignment);
|
let statement = t.expressionStatement(assignment);
|
||||||
statement._blockHoist = Infinity;
|
statement._blockHoist = Infinity;
|
||||||
body.unshift(statement);
|
body.unshift(statement);
|
||||||
}
|
}
|
||||||
|
|
||||||
var paramDecls = this.paramDecls;
|
let paramDecls = this.paramDecls;
|
||||||
if (paramDecls.length > 0) {
|
if (paramDecls.length > 0) {
|
||||||
var paramDecl = t.variableDeclaration("var", paramDecls);
|
let paramDecl = t.variableDeclaration("var", paramDecls);
|
||||||
paramDecl._blockHoist = Infinity;
|
paramDecl._blockHoist = Infinity;
|
||||||
body.unshift(paramDecl);
|
body.unshift(paramDecl);
|
||||||
}
|
}
|
||||||
@ -193,10 +193,10 @@ class TailCallTransformer {
|
|||||||
BLOCK: node.body
|
BLOCK: node.body
|
||||||
});
|
});
|
||||||
|
|
||||||
var topVars = [];
|
let topVars = [];
|
||||||
|
|
||||||
if (this.needsThis) {
|
if (this.needsThis) {
|
||||||
for (var path of (this.thisPaths: Array)) {
|
for (let path of (this.thisPaths: Array)) {
|
||||||
path.replaceWith(this.getThisId());
|
path.replaceWith(this.getThisId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -208,7 +208,7 @@ class TailCallTransformer {
|
|||||||
path.replaceWith(this.argumentsId);
|
path.replaceWith(this.argumentsId);
|
||||||
}
|
}
|
||||||
|
|
||||||
var decl = t.variableDeclarator(this.argumentsId);
|
let decl = t.variableDeclarator(this.argumentsId);
|
||||||
if (this.argumentsId) {
|
if (this.argumentsId) {
|
||||||
decl.init = t.identifier("arguments");
|
decl.init = t.identifier("arguments");
|
||||||
decl.init._shadowedFunctionLiteral = this.path;
|
decl.init._shadowedFunctionLiteral = this.path;
|
||||||
@ -216,7 +216,7 @@ class TailCallTransformer {
|
|||||||
topVars.push(decl);
|
topVars.push(decl);
|
||||||
}
|
}
|
||||||
|
|
||||||
var leftId = this.leftId;
|
let leftId = this.leftId;
|
||||||
if (leftId) {
|
if (leftId) {
|
||||||
topVars.push(t.variableDeclarator(leftId));
|
topVars.push(t.variableDeclarator(leftId));
|
||||||
}
|
}
|
||||||
@ -229,13 +229,13 @@ class TailCallTransformer {
|
|||||||
subTransform(node) {
|
subTransform(node) {
|
||||||
if (!node) return;
|
if (!node) return;
|
||||||
|
|
||||||
var handler = this[`subTransform${node.type}`];
|
let handler = this[`subTransform${node.type}`];
|
||||||
if (handler) return handler.call(this, node);
|
if (handler) return handler.call(this, node);
|
||||||
}
|
}
|
||||||
|
|
||||||
subTransformConditionalExpression(node) {
|
subTransformConditionalExpression(node) {
|
||||||
var callConsequent = this.subTransform(node.consequent);
|
let callConsequent = this.subTransform(node.consequent);
|
||||||
var callAlternate = this.subTransform(node.alternate);
|
let callAlternate = this.subTransform(node.alternate);
|
||||||
if (!callConsequent && !callAlternate) {
|
if (!callConsequent && !callAlternate) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -255,12 +255,12 @@ class TailCallTransformer {
|
|||||||
|
|
||||||
subTransformLogicalExpression(node) {
|
subTransformLogicalExpression(node) {
|
||||||
// only call in right-value of can be optimized
|
// only call in right-value of can be optimized
|
||||||
var callRight = this.subTransform(node.right);
|
let callRight = this.subTransform(node.right);
|
||||||
if (!callRight) return;
|
if (!callRight) return;
|
||||||
|
|
||||||
// cache left value as it might have side-effects
|
// cache left value as it might have side-effects
|
||||||
var leftId = this.getLeftId();
|
let leftId = this.getLeftId();
|
||||||
var testExpr = t.assignmentExpression(
|
let testExpr = t.assignmentExpression(
|
||||||
"=",
|
"=",
|
||||||
leftId,
|
leftId,
|
||||||
node.left
|
node.left
|
||||||
@ -274,10 +274,10 @@ class TailCallTransformer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
subTransformSequenceExpression(node) {
|
subTransformSequenceExpression(node) {
|
||||||
var seq = node.expressions;
|
let seq = node.expressions;
|
||||||
|
|
||||||
// only last element can be optimized
|
// only last element can be optimized
|
||||||
var lastCall = this.subTransform(seq[seq.length - 1]);
|
let lastCall = this.subTransform(seq[seq.length - 1]);
|
||||||
if (!lastCall) {
|
if (!lastCall) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -292,8 +292,8 @@ class TailCallTransformer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
subTransformCallExpression(node) {
|
subTransformCallExpression(node) {
|
||||||
var callee = node.callee;
|
let callee = node.callee;
|
||||||
var thisBinding, args;
|
let thisBinding, args;
|
||||||
|
|
||||||
if (t.isMemberExpression(callee, { computed: false }) && t.isIdentifier(callee.property)) {
|
if (t.isMemberExpression(callee, { computed: false }) && t.isIdentifier(callee.property)) {
|
||||||
switch (callee.property.name) {
|
switch (callee.property.name) {
|
||||||
@ -323,7 +323,7 @@ class TailCallTransformer {
|
|||||||
|
|
||||||
if (this.hasDeopt()) return;
|
if (this.hasDeopt()) return;
|
||||||
|
|
||||||
var body = [];
|
let body = [];
|
||||||
|
|
||||||
if (this.needsThis && !t.isThisExpression(thisBinding)) {
|
if (this.needsThis && !t.isThisExpression(thisBinding)) {
|
||||||
body.push(t.expressionStatement(t.assignmentExpression(
|
body.push(t.expressionStatement(t.assignmentExpression(
|
||||||
@ -337,8 +337,8 @@ class TailCallTransformer {
|
|||||||
args = t.arrayExpression(node.arguments);
|
args = t.arrayExpression(node.arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
var argumentsId = this.getArgumentsId();
|
let argumentsId = this.getArgumentsId();
|
||||||
var params = this.getParams();
|
let params = this.getParams();
|
||||||
|
|
||||||
if (this.needsArguments) {
|
if (this.needsArguments) {
|
||||||
body.push(t.expressionStatement(t.assignmentExpression(
|
body.push(t.expressionStatement(t.assignmentExpression(
|
||||||
@ -349,7 +349,7 @@ class TailCallTransformer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (t.isArrayExpression(args)) {
|
if (t.isArrayExpression(args)) {
|
||||||
var elems = args.elements;
|
let elems = args.elements;
|
||||||
|
|
||||||
// pad out the args so all the function args are reset - https://github.com/babel/babel/issues/1938
|
// pad out the args so all the function args are reset - https://github.com/babel/babel/issues/1938
|
||||||
while (elems.length < params.length) {
|
while (elems.length < params.length) {
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
export var metadata = {
|
export let metadata = {
|
||||||
stage: 2
|
stage: 2
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
export var metadata = {
|
export let metadata = {
|
||||||
stage: 0,
|
stage: 0,
|
||||||
dependencies: ["es6.classes"]
|
dependencies: ["es6.classes"]
|
||||||
};
|
};
|
||||||
|
|||||||
@ -3,21 +3,21 @@ import traverse from "babel-traverse";
|
|||||||
import * as util from "../../../util";
|
import * as util from "../../../util";
|
||||||
import * as t from "babel-types";
|
import * as t from "babel-types";
|
||||||
|
|
||||||
export var metadata = {
|
export let metadata = {
|
||||||
stage: 0
|
stage: 0
|
||||||
};
|
};
|
||||||
|
|
||||||
export var visitor = {
|
export let visitor = {
|
||||||
ComprehensionExpression(node, parent, scope) {
|
ComprehensionExpression(node, parent, scope) {
|
||||||
var callback = array;
|
let callback = array;
|
||||||
if (node.generator) callback = generator;
|
if (node.generator) callback = generator;
|
||||||
return callback(node, parent, scope);
|
return callback(node, parent, scope);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
function generator(node) {
|
function generator(node) {
|
||||||
var body = [];
|
let body = [];
|
||||||
var container = t.functionExpression(null, [], t.blockStatement(body), true);
|
let container = t.functionExpression(null, [], t.blockStatement(body), true);
|
||||||
container.shadow = true;
|
container.shadow = true;
|
||||||
|
|
||||||
body.push(buildComprehension(node, function () {
|
body.push(buildComprehension(node, function () {
|
||||||
@ -28,22 +28,22 @@ function generator(node) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function array(node, parent, scope) {
|
function array(node, parent, scope) {
|
||||||
var uid = scope.generateUidIdentifierBasedOnNode(parent);
|
let uid = scope.generateUidIdentifierBasedOnNode(parent);
|
||||||
|
|
||||||
var container = util.template("array-comprehension-container", {
|
let container = util.template("array-comprehension-container", {
|
||||||
KEY: uid
|
KEY: uid
|
||||||
});
|
});
|
||||||
container.callee.shadow = true;
|
container.callee.shadow = true;
|
||||||
|
|
||||||
var block = container.callee.body;
|
let block = container.callee.body;
|
||||||
var body = block.body;
|
let body = block.body;
|
||||||
|
|
||||||
if (traverse.hasType(node, scope, "YieldExpression", t.FUNCTION_TYPES)) {
|
if (traverse.hasType(node, scope, "YieldExpression", t.FUNCTION_TYPES)) {
|
||||||
container.callee.generator = true;
|
container.callee.generator = true;
|
||||||
container = t.yieldExpression(container, true);
|
container = t.yieldExpression(container, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
var returnStatement = body.pop();
|
let returnStatement = body.pop();
|
||||||
|
|
||||||
body.push(buildComprehension(node, function () {
|
body.push(buildComprehension(node, function () {
|
||||||
return util.template("array-push", {
|
return util.template("array-push", {
|
||||||
|
|||||||
@ -2,15 +2,15 @@ import memoiseDecorators from "../../helpers/memoise-decorators";
|
|||||||
import * as defineMap from "../../helpers/define-map";
|
import * as defineMap from "../../helpers/define-map";
|
||||||
import * as t from "babel-types";
|
import * as t from "babel-types";
|
||||||
|
|
||||||
export var metadata = {
|
export let metadata = {
|
||||||
dependencies: ["es6.classes"],
|
dependencies: ["es6.classes"],
|
||||||
optional: true,
|
optional: true,
|
||||||
stage: 1
|
stage: 1
|
||||||
};
|
};
|
||||||
|
|
||||||
export var visitor = {
|
export let visitor = {
|
||||||
ObjectExpression(node, parent, scope, file) {
|
ObjectExpression(node, parent, scope, file) {
|
||||||
var hasDecorators = false;
|
let hasDecorators = false;
|
||||||
for (let i = 0; i < node.properties.length; i++) {
|
for (let i = 0; i < node.properties.length; i++) {
|
||||||
let prop = node.properties[i];
|
let prop = node.properties[i];
|
||||||
if (prop.decorators) {
|
if (prop.decorators) {
|
||||||
@ -20,7 +20,7 @@ export var visitor = {
|
|||||||
}
|
}
|
||||||
if (!hasDecorators) return;
|
if (!hasDecorators) return;
|
||||||
|
|
||||||
var mutatorMap = {};
|
let mutatorMap = {};
|
||||||
|
|
||||||
for (let i = 0; i < node.properties.length; i++) {
|
for (let i = 0; i < node.properties.length; i++) {
|
||||||
let prop = node.properties[i];
|
let prop = node.properties[i];
|
||||||
@ -37,7 +37,7 @@ export var visitor = {
|
|||||||
defineMap.push(mutatorMap, prop, "initializer", file);
|
defineMap.push(mutatorMap, prop, "initializer", file);
|
||||||
}
|
}
|
||||||
|
|
||||||
var obj = defineMap.toClassObject(mutatorMap);
|
let obj = defineMap.toClassObject(mutatorMap);
|
||||||
obj = defineMap.toComputedObjectFromClass(obj);
|
obj = defineMap.toComputedObjectFromClass(obj);
|
||||||
return t.callExpression(file.addHelper("create-decorated-object"), [obj]);
|
return t.callExpression(file.addHelper("create-decorated-object"), [obj]);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,13 +1,13 @@
|
|||||||
import * as t from "babel-types";
|
import * as t from "babel-types";
|
||||||
|
|
||||||
export var metadata = {
|
export let metadata = {
|
||||||
optional: true,
|
optional: true,
|
||||||
stage: 0
|
stage: 0
|
||||||
};
|
};
|
||||||
|
|
||||||
export var visitor = {
|
export let visitor = {
|
||||||
DoExpression(node) {
|
DoExpression(node) {
|
||||||
var body = node.body.body;
|
let body = node.body.body;
|
||||||
if (body.length) {
|
if (body.length) {
|
||||||
return body;
|
return body;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -3,11 +3,11 @@
|
|||||||
import build from "../../helpers/build-binary-assignment-operator-transformer";
|
import build from "../../helpers/build-binary-assignment-operator-transformer";
|
||||||
import * as t from "babel-types";
|
import * as t from "babel-types";
|
||||||
|
|
||||||
export var metadata = {
|
export let metadata = {
|
||||||
stage: 2
|
stage: 2
|
||||||
};
|
};
|
||||||
|
|
||||||
export var visitor = build({
|
export let visitor = build({
|
||||||
operator: "**",
|
operator: "**",
|
||||||
|
|
||||||
build(left, right) {
|
build(left, right) {
|
||||||
|
|||||||
@ -2,18 +2,18 @@
|
|||||||
|
|
||||||
import * as t from "babel-types";
|
import * as t from "babel-types";
|
||||||
|
|
||||||
export var metadata = {
|
export let metadata = {
|
||||||
stage: 1
|
stage: 1
|
||||||
};
|
};
|
||||||
|
|
||||||
function build(node, nodes, scope) {
|
function build(node, nodes, scope) {
|
||||||
var first = node.specifiers[0];
|
let first = node.specifiers[0];
|
||||||
if (!t.isExportNamespaceSpecifier(first) && !t.isExportDefaultSpecifier(first)) return;
|
if (!t.isExportNamespaceSpecifier(first) && !t.isExportDefaultSpecifier(first)) return;
|
||||||
|
|
||||||
var specifier = node.specifiers.shift();
|
let specifier = node.specifiers.shift();
|
||||||
var uid = scope.generateUidIdentifier(specifier.exported.name);
|
let uid = scope.generateUidIdentifier(specifier.exported.name);
|
||||||
|
|
||||||
var newSpecifier;
|
let newSpecifier;
|
||||||
if (t.isExportNamespaceSpecifier(specifier)) {
|
if (t.isExportNamespaceSpecifier(specifier)) {
|
||||||
newSpecifier = t.importNamespaceSpecifier(uid);
|
newSpecifier = t.importNamespaceSpecifier(uid);
|
||||||
} else {
|
} else {
|
||||||
@ -26,9 +26,9 @@ function build(node, nodes, scope) {
|
|||||||
build(node, nodes, scope);
|
build(node, nodes, scope);
|
||||||
}
|
}
|
||||||
|
|
||||||
export var visitor = {
|
export let visitor = {
|
||||||
ExportNamedDeclaration(node, parent, scope) {
|
ExportNamedDeclaration(node, parent, scope) {
|
||||||
var nodes = [];
|
let nodes = [];
|
||||||
build(node, nodes, scope);
|
build(node, nodes, scope);
|
||||||
if (!nodes.length) return;
|
if (!nodes.length) return;
|
||||||
|
|
||||||
|
|||||||
@ -2,13 +2,13 @@
|
|||||||
|
|
||||||
import * as t from "babel-types";
|
import * as t from "babel-types";
|
||||||
|
|
||||||
export var metadata = {
|
export let metadata = {
|
||||||
optional: true,
|
optional: true,
|
||||||
stage: 0
|
stage: 0
|
||||||
};
|
};
|
||||||
|
|
||||||
function getTempId(scope) {
|
function getTempId(scope) {
|
||||||
var id = scope.path.getData("functionBind");
|
let id = scope.path.getData("functionBind");
|
||||||
if (id) return id;
|
if (id) return id;
|
||||||
|
|
||||||
id = scope.generateDeclaredUidIdentifier("context");
|
id = scope.generateDeclaredUidIdentifier("context");
|
||||||
@ -16,15 +16,15 @@ function getTempId(scope) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getStaticContext(bind, scope) {
|
function getStaticContext(bind, scope) {
|
||||||
var object = bind.object || bind.callee.object;
|
let object = bind.object || bind.callee.object;
|
||||||
return scope.isStatic(object) && object;
|
return scope.isStatic(object) && object;
|
||||||
}
|
}
|
||||||
|
|
||||||
function inferBindContext(bind, scope) {
|
function inferBindContext(bind, scope) {
|
||||||
var staticContext = getStaticContext(bind, scope);
|
let staticContext = getStaticContext(bind, scope);
|
||||||
if (staticContext) return staticContext;
|
if (staticContext) return staticContext;
|
||||||
|
|
||||||
var tempId = getTempId(scope);
|
let tempId = getTempId(scope);
|
||||||
if (bind.object) {
|
if (bind.object) {
|
||||||
bind.callee = t.sequenceExpression([
|
bind.callee = t.sequenceExpression([
|
||||||
t.assignmentExpression("=", tempId, bind.object),
|
t.assignmentExpression("=", tempId, bind.object),
|
||||||
@ -36,18 +36,18 @@ function inferBindContext(bind, scope) {
|
|||||||
return tempId;
|
return tempId;
|
||||||
}
|
}
|
||||||
|
|
||||||
export var visitor = {
|
export let visitor = {
|
||||||
CallExpression(node, parent, scope) {
|
CallExpression(node, parent, scope) {
|
||||||
var bind = node.callee;
|
let bind = node.callee;
|
||||||
if (!t.isBindExpression(bind)) return;
|
if (!t.isBindExpression(bind)) return;
|
||||||
|
|
||||||
var context = inferBindContext(bind, scope);
|
let context = inferBindContext(bind, scope);
|
||||||
node.callee = t.memberExpression(bind.callee, t.identifier("call"));
|
node.callee = t.memberExpression(bind.callee, t.identifier("call"));
|
||||||
node.arguments.unshift(context);
|
node.arguments.unshift(context);
|
||||||
},
|
},
|
||||||
|
|
||||||
BindExpression(node, parent, scope) {
|
BindExpression(node, parent, scope) {
|
||||||
var context = inferBindContext(node, scope);
|
let context = inferBindContext(node, scope);
|
||||||
return t.callExpression(t.memberExpression(node.callee, t.identifier("bind")), [context]);
|
return t.callExpression(t.memberExpression(node.callee, t.identifier("bind")), [context]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@ -2,13 +2,13 @@
|
|||||||
|
|
||||||
import * as t from "babel-types";
|
import * as t from "babel-types";
|
||||||
|
|
||||||
export var metadata = {
|
export let metadata = {
|
||||||
stage: 2,
|
stage: 2,
|
||||||
dependencies: ["es6.destructuring"]
|
dependencies: ["es6.destructuring"]
|
||||||
};
|
};
|
||||||
|
|
||||||
var hasSpread = function (node) {
|
let hasSpread = function (node) {
|
||||||
for (var i = 0; i < node.properties.length; i++) {
|
for (let i = 0; i < node.properties.length; i++) {
|
||||||
if (t.isSpreadProperty(node.properties[i])) {
|
if (t.isSpreadProperty(node.properties[i])) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -16,21 +16,21 @@ var hasSpread = function (node) {
|
|||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
export var visitor = {
|
export let visitor = {
|
||||||
ObjectExpression(node, parent, scope, file) {
|
ObjectExpression(node, parent, scope, file) {
|
||||||
if (!hasSpread(node)) return;
|
if (!hasSpread(node)) return;
|
||||||
|
|
||||||
var args = [];
|
let args = [];
|
||||||
var props = [];
|
let props = [];
|
||||||
|
|
||||||
var push = function () {
|
let push = function () {
|
||||||
if (!props.length) return;
|
if (!props.length) return;
|
||||||
args.push(t.objectExpression(props));
|
args.push(t.objectExpression(props));
|
||||||
props = [];
|
props = [];
|
||||||
};
|
};
|
||||||
|
|
||||||
for (var i = 0; i < node.properties.length; i++) {
|
for (let i = 0; i < node.properties.length; i++) {
|
||||||
var prop = node.properties[i];
|
let prop = node.properties[i];
|
||||||
if (t.isSpreadProperty(prop)) {
|
if (t.isSpreadProperty(prop)) {
|
||||||
push();
|
push();
|
||||||
args.push(prop.argument);
|
args.push(prop.argument);
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
export var metadata = {
|
export let metadata = {
|
||||||
stage: 1
|
stage: 1
|
||||||
};
|
};
|
||||||
|
|||||||
@ -5,17 +5,17 @@ export function internal(transformer) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function blacklist(transformer, opts) {
|
export function blacklist(transformer, opts) {
|
||||||
var blacklist = opts.blacklist;
|
let blacklist = opts.blacklist;
|
||||||
if (blacklist.length && includes(blacklist, transformer.key)) return false;
|
if (blacklist.length && includes(blacklist, transformer.key)) return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function whitelist(transformer, opts) {
|
export function whitelist(transformer, opts) {
|
||||||
var whitelist = opts.whitelist;
|
let whitelist = opts.whitelist;
|
||||||
if (whitelist) return includes(whitelist, transformer.key);
|
if (whitelist) return includes(whitelist, transformer.key);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function stage(transformer, opts) {
|
export function stage(transformer, opts) {
|
||||||
var stage = transformer.metadata.stage;
|
let stage = transformer.metadata.stage;
|
||||||
if (stage != null && stage >= opts.stage) return true;
|
if (stage != null && stage >= opts.stage) return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,14 +1,14 @@
|
|||||||
import * as t from "babel-types";
|
import * as t from "babel-types";
|
||||||
|
|
||||||
export var metadata = {
|
export let metadata = {
|
||||||
group: "builtin-pre"
|
group: "builtin-pre"
|
||||||
};
|
};
|
||||||
|
|
||||||
export var visitor = {
|
export let visitor = {
|
||||||
Block: {
|
Block: {
|
||||||
exit(node) {
|
exit(node) {
|
||||||
for (var i = 0; i < node.body.length; i++) {
|
for (let i = 0; i < node.body.length; i++) {
|
||||||
var bodyNode = node.body[i];
|
let bodyNode = node.body[i];
|
||||||
if (t.isExpressionStatement(bodyNode) && t.isLiteral(bodyNode.expression)) {
|
if (t.isExpressionStatement(bodyNode) && t.isLiteral(bodyNode.expression)) {
|
||||||
bodyNode._blockHoist = Infinity;
|
bodyNode._blockHoist = Infinity;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -1,12 +1,12 @@
|
|||||||
export var metadata = {
|
export let metadata = {
|
||||||
group: "builtin-modules"
|
group: "builtin-modules"
|
||||||
};
|
};
|
||||||
|
|
||||||
export var visitor = {
|
export let visitor = {
|
||||||
Program: {
|
Program: {
|
||||||
exit(program, parent, scope, file) {
|
exit(program, parent, scope, file) {
|
||||||
// ensure that these are at the top, just like normal imports
|
// ensure that these are at the top, just like normal imports
|
||||||
for (var node of (file.dynamicImports: Array)) {
|
for (let node of (file.dynamicImports: Array)) {
|
||||||
node._blockHoist = 3;
|
node._blockHoist = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -7,7 +7,7 @@
|
|||||||
import * as t from "babel-types";
|
import * as t from "babel-types";
|
||||||
|
|
||||||
function getDeclar(node) {
|
function getDeclar(node) {
|
||||||
var declar = node.declaration;
|
let declar = node.declaration;
|
||||||
t.inheritsComments(declar, node);
|
t.inheritsComments(declar, node);
|
||||||
t.removeComments(node);
|
t.removeComments(node);
|
||||||
declar._ignoreUserWhitespace = true;
|
declar._ignoreUserWhitespace = true;
|
||||||
@ -19,18 +19,18 @@ function buildExportSpecifier(id) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function cloneIdentifier({ name, loc }) {
|
function cloneIdentifier({ name, loc }) {
|
||||||
var id = t.identifier(name);
|
let id = t.identifier(name);
|
||||||
id._loc = loc;
|
id._loc = loc;
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
export var metadata = {
|
export let metadata = {
|
||||||
group: "builtin-pre"
|
group: "builtin-pre"
|
||||||
};
|
};
|
||||||
|
|
||||||
export var visitor = {
|
export let visitor = {
|
||||||
ExportDefaultDeclaration(node, parent, scope) {
|
ExportDefaultDeclaration(node, parent, scope) {
|
||||||
var declar = node.declaration;
|
let declar = node.declaration;
|
||||||
|
|
||||||
if (t.isClassDeclaration(declar)) {
|
if (t.isClassDeclaration(declar)) {
|
||||||
// export default class Foo {};
|
// export default class Foo {};
|
||||||
@ -39,7 +39,7 @@ export var visitor = {
|
|||||||
return nodes;
|
return nodes;
|
||||||
} else if (t.isClassExpression(declar)) {
|
} else if (t.isClassExpression(declar)) {
|
||||||
// export default class {};
|
// export default class {};
|
||||||
var temp = scope.generateUidIdentifier("default");
|
let temp = scope.generateUidIdentifier("default");
|
||||||
node.declaration = t.variableDeclaration("var", [
|
node.declaration = t.variableDeclaration("var", [
|
||||||
t.variableDeclarator(temp, declar)
|
t.variableDeclarator(temp, declar)
|
||||||
]);
|
]);
|
||||||
@ -58,7 +58,7 @@ export var visitor = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
ExportNamedDeclaration(node) {
|
ExportNamedDeclaration(node) {
|
||||||
var declar = node.declaration;
|
let declar = node.declaration;
|
||||||
|
|
||||||
if (t.isClassDeclaration(declar)) {
|
if (t.isClassDeclaration(declar)) {
|
||||||
// export class Foo {}
|
// export class Foo {}
|
||||||
@ -69,14 +69,14 @@ export var visitor = {
|
|||||||
return nodes;
|
return nodes;
|
||||||
} else if (t.isFunctionDeclaration(declar)) {
|
} else if (t.isFunctionDeclaration(declar)) {
|
||||||
// export function Foo() {}
|
// export function Foo() {}
|
||||||
var newExport = t.exportNamedDeclaration(null, [buildExportSpecifier(declar.id)]);
|
let newExport = t.exportNamedDeclaration(null, [buildExportSpecifier(declar.id)]);
|
||||||
newExport._blockHoist = 2;
|
newExport._blockHoist = 2;
|
||||||
return [getDeclar(node), newExport];
|
return [getDeclar(node), newExport];
|
||||||
} else if (t.isVariableDeclaration(declar)) {
|
} else if (t.isVariableDeclaration(declar)) {
|
||||||
// export var foo = "bar";
|
// export let foo = "bar";
|
||||||
var specifiers = [];
|
let specifiers = [];
|
||||||
var bindings = this.get("declaration").getBindingIdentifiers();
|
let bindings = this.get("declaration").getBindingIdentifiers();
|
||||||
for (var key in bindings) {
|
for (let key in bindings) {
|
||||||
specifiers.push(buildExportSpecifier(bindings[key]));
|
specifiers.push(buildExportSpecifier(bindings[key]));
|
||||||
}
|
}
|
||||||
return [declar, t.exportNamedDeclaration(null, specifiers)];
|
return [declar, t.exportNamedDeclaration(null, specifiers)];
|
||||||
@ -85,11 +85,11 @@ export var visitor = {
|
|||||||
|
|
||||||
Program: {
|
Program: {
|
||||||
enter(node) {
|
enter(node) {
|
||||||
var imports = [];
|
let imports = [];
|
||||||
var rest = [];
|
let rest = [];
|
||||||
|
|
||||||
for (var i = 0; i < node.body.length; i++) {
|
for (let i = 0; i < node.body.length; i++) {
|
||||||
var bodyNode = node.body[i];
|
let bodyNode = node.body[i];
|
||||||
if (t.isImportDeclaration(bodyNode)) {
|
if (t.isImportDeclaration(bodyNode)) {
|
||||||
imports.push(bodyNode);
|
imports.push(bodyNode);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -1,22 +1,22 @@
|
|||||||
import * as messages from "babel-messages";
|
import * as messages from "babel-messages";
|
||||||
import * as t from "babel-types";
|
import * as t from "babel-types";
|
||||||
|
|
||||||
export var metadata = {
|
export let metadata = {
|
||||||
group: "builtin-pre"
|
group: "builtin-pre"
|
||||||
};
|
};
|
||||||
|
|
||||||
export var visitor = {
|
export let visitor = {
|
||||||
ForXStatement(node, parent, scope, file) {
|
ForXStatement(node, parent, scope, file) {
|
||||||
var left = node.left;
|
let left = node.left;
|
||||||
if (t.isVariableDeclaration(left)) {
|
if (t.isVariableDeclaration(left)) {
|
||||||
var declar = left.declarations[0];
|
let declar = left.declarations[0];
|
||||||
if (declar.init) throw file.errorWithNode(declar, messages.get("noAssignmentsInForHead"));
|
if (declar.init) throw file.errorWithNode(declar, messages.get("noAssignmentsInForHead"));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
Property(node, parent, scope, file) {
|
Property(node, parent, scope, file) {
|
||||||
if (node.kind === "set") {
|
if (node.kind === "set") {
|
||||||
var first = node.value.params[0];
|
let first = node.value.params[0];
|
||||||
if (t.isRestElement(first)) {
|
if (t.isRestElement(first)) {
|
||||||
throw file.errorWithNode(first, messages.get("settersNoRest"));
|
throw file.errorWithNode(first, messages.get("settersNoRest"));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,10 +1,10 @@
|
|||||||
import { _ForOfStatementArray } from "../es6/for-of";
|
import { _ForOfStatementArray } from "../es6/for-of";
|
||||||
|
|
||||||
export var metadata = {
|
export let metadata = {
|
||||||
optional: true
|
optional: true
|
||||||
};
|
};
|
||||||
|
|
||||||
export var visitor = {
|
export let visitor = {
|
||||||
ForOfStatement(node, parent, scope, file) {
|
ForOfStatement(node, parent, scope, file) {
|
||||||
if (this.get("right").isGenericType("Array")) {
|
if (this.get("right").isGenericType("Array")) {
|
||||||
return _ForOfStatementArray.call(this, node, scope, file);
|
return _ForOfStatementArray.call(this, node, scope, file);
|
||||||
|
|||||||
@ -1,11 +1,11 @@
|
|||||||
import * as t from "babel-types";
|
import * as t from "babel-types";
|
||||||
|
|
||||||
export var metadata = {
|
export let metadata = {
|
||||||
optional: true,
|
optional: true,
|
||||||
group: "builtin-trailing"
|
group: "builtin-trailing"
|
||||||
};
|
};
|
||||||
|
|
||||||
export var visitor = {
|
export let visitor = {
|
||||||
Program(node, parent, scope, file){
|
Program(node, parent, scope, file){
|
||||||
if (file.moduleFormatter._setters){
|
if (file.moduleFormatter._setters){
|
||||||
scope.traverse(file.moduleFormatter._setters, optimizeSettersVisitor, {
|
scope.traverse(file.moduleFormatter._setters, optimizeSettersVisitor, {
|
||||||
@ -24,7 +24,7 @@ export var visitor = {
|
|||||||
* TODO: Ideally this would be optimized during construction of the setters, but the current
|
* TODO: Ideally this would be optimized during construction of the setters, but the current
|
||||||
* architecture of the module formatters make that difficult.
|
* architecture of the module formatters make that difficult.
|
||||||
*/
|
*/
|
||||||
var optimizeSettersVisitor = {
|
let optimizeSettersVisitor = {
|
||||||
FunctionExpression: {
|
FunctionExpression: {
|
||||||
enter: (node, parent, scope, state) => {
|
enter: (node, parent, scope, state) => {
|
||||||
state.hasExports = false;
|
state.hasExports = false;
|
||||||
@ -44,7 +44,7 @@ var optimizeSettersVisitor = {
|
|||||||
if (!t.isIdentifier(node.callee, {name: state.exportFunctionIdentifier.name})) return;
|
if (!t.isIdentifier(node.callee, {name: state.exportFunctionIdentifier.name})) return;
|
||||||
|
|
||||||
state.hasExports = true;
|
state.hasExports = true;
|
||||||
var memberNode = t.memberExpression(t.cloneDeep(state.exportObjectIdentifier), node.arguments[0], true);
|
let memberNode = t.memberExpression(t.cloneDeep(state.exportObjectIdentifier), node.arguments[0], true);
|
||||||
return t.assignmentExpression("=", memberNode, node.arguments[1]);
|
return t.assignmentExpression("=", memberNode, node.arguments[1]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,13 +1,13 @@
|
|||||||
import { react } from "babel-types";
|
import { react } from "babel-types";
|
||||||
import * as t from "babel-types";
|
import * as t from "babel-types";
|
||||||
|
|
||||||
export var metadata = {
|
export let metadata = {
|
||||||
optional: true
|
optional: true
|
||||||
};
|
};
|
||||||
|
|
||||||
function hasRefOrSpread(attrs) {
|
function hasRefOrSpread(attrs) {
|
||||||
for (var i = 0; i < attrs.length; i++) {
|
for (let i = 0; i < attrs.length; i++) {
|
||||||
var attr = attrs[i];
|
let attr = attrs[i];
|
||||||
if (t.isJSXSpreadAttribute(attr)) return true;
|
if (t.isJSXSpreadAttribute(attr)) return true;
|
||||||
if (isJSXAttributeOfName(attr, "ref")) return true;
|
if (isJSXAttributeOfName(attr, "ref")) return true;
|
||||||
}
|
}
|
||||||
@ -17,18 +17,18 @@ function hasRefOrSpread(attrs) {
|
|||||||
function isJSXAttributeOfName(attr, name) {
|
function isJSXAttributeOfName(attr, name) {
|
||||||
return t.isJSXAttribute(attr) && t.isJSXIdentifier(attr.name, { name: name });
|
return t.isJSXAttribute(attr) && t.isJSXIdentifier(attr.name, { name: name });
|
||||||
}
|
}
|
||||||
export var visitor = {
|
export let visitor = {
|
||||||
JSXElement(node, parent, scope, file) {
|
JSXElement(node, parent, scope, file) {
|
||||||
// filter
|
// filter
|
||||||
var open = node.openingElement;
|
let open = node.openingElement;
|
||||||
if (hasRefOrSpread(open.attributes)) return;
|
if (hasRefOrSpread(open.attributes)) return;
|
||||||
|
|
||||||
// init
|
// init
|
||||||
var isComponent = true;
|
let isComponent = true;
|
||||||
var props = t.objectExpression([]);
|
let props = t.objectExpression([]);
|
||||||
var obj = t.objectExpression([]);
|
let obj = t.objectExpression([]);
|
||||||
var key = t.nullLiteral();
|
let key = t.nullLiteral();
|
||||||
var type = open.name;
|
let type = open.name;
|
||||||
|
|
||||||
if (t.isJSXIdentifier(type) && react.isCompatTag(type.name)) {
|
if (t.isJSXIdentifier(type) && react.isCompatTag(type.name)) {
|
||||||
type = t.stringLiteral(type.name);
|
type = t.stringLiteral(type.name);
|
||||||
@ -48,14 +48,14 @@ export var visitor = {
|
|||||||
pushElemProp("ref", t.nullLiteral());
|
pushElemProp("ref", t.nullLiteral());
|
||||||
|
|
||||||
if (node.children.length) {
|
if (node.children.length) {
|
||||||
var children = react.buildChildren(node);
|
let children = react.buildChildren(node);
|
||||||
children = children.length === 1 ? children[0] : t.arrayExpression(children);
|
children = children.length === 1 ? children[0] : t.arrayExpression(children);
|
||||||
pushProp(props.properties, t.identifier("children"), children);
|
pushProp(props.properties, t.identifier("children"), children);
|
||||||
}
|
}
|
||||||
|
|
||||||
// props
|
// props
|
||||||
for (var i = 0; i < open.attributes.length; i++) {
|
for (let i = 0; i < open.attributes.length; i++) {
|
||||||
var attr = open.attributes[i];
|
let attr = open.attributes[i];
|
||||||
if (isJSXAttributeOfName(attr, "key")) {
|
if (isJSXAttributeOfName(attr, "key")) {
|
||||||
key = attr.value;
|
key = attr.value;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -2,12 +2,12 @@ import remapAsyncToGenerator from "../../helpers/remap-async-to-generator";
|
|||||||
|
|
||||||
export { manipulateOptions } from "./bluebird-coroutines";
|
export { manipulateOptions } from "./bluebird-coroutines";
|
||||||
|
|
||||||
export var metadata = {
|
export let metadata = {
|
||||||
optional: true,
|
optional: true,
|
||||||
dependencies: ["es7.asyncFunctions", "es6.classes"]
|
dependencies: ["es7.asyncFunctions", "es6.classes"]
|
||||||
};
|
};
|
||||||
|
|
||||||
export var visitor = {
|
export let visitor = {
|
||||||
Function(node, parent, scope, file) {
|
Function(node, parent, scope, file) {
|
||||||
if (!node.async || node.generator) return;
|
if (!node.async || node.generator) return;
|
||||||
|
|
||||||
|
|||||||
@ -5,12 +5,12 @@ export function manipulateOptions(opts) {
|
|||||||
opts.blacklist.push("regenerator");
|
opts.blacklist.push("regenerator");
|
||||||
}
|
}
|
||||||
|
|
||||||
export var metadata = {
|
export let metadata = {
|
||||||
optional: true,
|
optional: true,
|
||||||
dependencies: ["es7.asyncFunctions", "es6.classes"]
|
dependencies: ["es7.asyncFunctions", "es6.classes"]
|
||||||
};
|
};
|
||||||
|
|
||||||
export var visitor = {
|
export let visitor = {
|
||||||
Function(node, parent, scope, file) {
|
Function(node, parent, scope, file) {
|
||||||
if (!node.async || node.generator) return;
|
if (!node.async || node.generator) return;
|
||||||
|
|
||||||
|
|||||||
@ -5,12 +5,12 @@ export function manipulateOptions(opts) {
|
|||||||
opts.blacklist.push("react");
|
opts.blacklist.push("react");
|
||||||
}
|
}
|
||||||
|
|
||||||
export var metadata = {
|
export let metadata = {
|
||||||
optional: true,
|
optional: true,
|
||||||
group: "builtin-advanced"
|
group: "builtin-advanced"
|
||||||
};
|
};
|
||||||
|
|
||||||
export var visitor = require("../../helpers/build-react-transformer")({
|
export let visitor = require("../../helpers/build-react-transformer")({
|
||||||
pre(state) {
|
pre(state) {
|
||||||
state.callee = state.tagExpr;
|
state.callee = state.tagExpr;
|
||||||
},
|
},
|
||||||
|
|||||||
@ -1,16 +1,16 @@
|
|||||||
import { react } from "babel-types";
|
import { react } from "babel-types";
|
||||||
import * as t from "babel-types";
|
import * as t from "babel-types";
|
||||||
|
|
||||||
var JSX_ANNOTATION_REGEX = /^\*\s*@jsx\s+([^\s]+)/;
|
let JSX_ANNOTATION_REGEX = /^\*\s*@jsx\s+([^\s]+)/;
|
||||||
|
|
||||||
export var metadata = {
|
export let metadata = {
|
||||||
group: "builtin-advanced"
|
group: "builtin-advanced"
|
||||||
};
|
};
|
||||||
|
|
||||||
export var visitor = require("../../helpers/build-react-transformer")({
|
export let visitor = require("../../helpers/build-react-transformer")({
|
||||||
pre(state) {
|
pre(state) {
|
||||||
var tagName = state.tagName;
|
let tagName = state.tagName;
|
||||||
var args = state.args;
|
let args = state.args;
|
||||||
if (react.isCompatTag(tagName)) {
|
if (react.isCompatTag(tagName)) {
|
||||||
args.push(t.stringLiteral(tagName));
|
args.push(t.stringLiteral(tagName));
|
||||||
} else {
|
} else {
|
||||||
@ -24,11 +24,11 @@ export var visitor = require("../../helpers/build-react-transformer")({
|
|||||||
});
|
});
|
||||||
|
|
||||||
visitor.Program = function (node, parent, scope, file) {
|
visitor.Program = function (node, parent, scope, file) {
|
||||||
var id = file.opts.jsxPragma;
|
let id = file.opts.jsxPragma;
|
||||||
|
|
||||||
for (var i = 0; i < file.ast.comments.length; i++) {
|
for (let i = 0; i < file.ast.comments.length; i++) {
|
||||||
var comment = file.ast.comments[i];
|
let comment = file.ast.comments[i];
|
||||||
var matches = JSX_ANNOTATION_REGEX.exec(comment.value);
|
let matches = JSX_ANNOTATION_REGEX.exec(comment.value);
|
||||||
if (matches) {
|
if (matches) {
|
||||||
id = matches[1];
|
id = matches[1];
|
||||||
if (id === "React.DOM") {
|
if (id === "React.DOM") {
|
||||||
|
|||||||
@ -7,11 +7,11 @@ import * as t from "babel-types";
|
|||||||
// the version that Regenerator depends on. See for example #1958.
|
// the version that Regenerator depends on. See for example #1958.
|
||||||
const NodePath = regenerator.types.NodePath;
|
const NodePath = regenerator.types.NodePath;
|
||||||
|
|
||||||
export var metadata = {
|
export let metadata = {
|
||||||
group: "builtin-advanced"
|
group: "builtin-advanced"
|
||||||
};
|
};
|
||||||
|
|
||||||
export var visitor = {
|
export let visitor = {
|
||||||
Function: {
|
Function: {
|
||||||
exit(node) {
|
exit(node) {
|
||||||
if (node.async || node.generator) {
|
if (node.async || node.generator) {
|
||||||
@ -33,17 +33,17 @@ export var visitor = {
|
|||||||
// complicated by having to include intermediate objects like blockStatement.body
|
// complicated by having to include intermediate objects like blockStatement.body
|
||||||
// arrays, in addition to Node objects.
|
// arrays, in addition to Node objects.
|
||||||
function convertNodePath(path) {
|
function convertNodePath(path) {
|
||||||
var programNode;
|
let programNode;
|
||||||
var keysAlongPath = [];
|
let keysAlongPath = [];
|
||||||
|
|
||||||
while (path) {
|
while (path) {
|
||||||
var pp = path.parentPath;
|
let pp = path.parentPath;
|
||||||
var parentNode = pp && pp.node;
|
let parentNode = pp && pp.node;
|
||||||
if (parentNode) {
|
if (parentNode) {
|
||||||
keysAlongPath.push(path.key);
|
keysAlongPath.push(path.key);
|
||||||
|
|
||||||
if (parentNode !== path.container) {
|
if (parentNode !== path.container) {
|
||||||
var found = Object.keys(parentNode).some(listKey => {
|
let found = Object.keys(parentNode).some(listKey => {
|
||||||
if (parentNode[listKey] === path.container) {
|
if (parentNode[listKey] === path.container) {
|
||||||
keysAlongPath.push(listKey);
|
keysAlongPath.push(listKey);
|
||||||
return true;
|
return true;
|
||||||
@ -68,7 +68,7 @@ function convertNodePath(path) {
|
|||||||
throw new Error("Failed to find root Program node");
|
throw new Error("Failed to find root Program node");
|
||||||
}
|
}
|
||||||
|
|
||||||
var nodePath = new NodePath(programNode);
|
let nodePath = new NodePath(programNode);
|
||||||
|
|
||||||
while (keysAlongPath.length > 0) {
|
while (keysAlongPath.length > 0) {
|
||||||
nodePath = nodePath.get(keysAlongPath.pop());
|
nodePath = nodePath.get(keysAlongPath.pop());
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import * as t from "babel-types";
|
import * as t from "babel-types";
|
||||||
|
|
||||||
export var metadata = {
|
export let metadata = {
|
||||||
group: "builtin-pre"
|
group: "builtin-pre"
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -16,12 +16,12 @@ function isUseStrict(node) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export var visitor = {
|
export let visitor = {
|
||||||
Program: {
|
Program: {
|
||||||
enter(program) {
|
enter(program) {
|
||||||
var first = program.body[0];
|
let first = program.body[0];
|
||||||
|
|
||||||
var directive;
|
let directive;
|
||||||
if (t.isExpressionStatement(first) && isUseStrict(first.expression)) {
|
if (t.isExpressionStatement(first) && isUseStrict(first.expression)) {
|
||||||
directive = first;
|
directive = first;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -1,12 +1,12 @@
|
|||||||
import { bare } from "../../helpers/name-method";
|
import { bare } from "../../helpers/name-method";
|
||||||
|
|
||||||
export var metadata = {
|
export let metadata = {
|
||||||
group: "builtin-basic"
|
group: "builtin-basic"
|
||||||
};
|
};
|
||||||
|
|
||||||
// visit Property functions first - https://github.com/babel/babel/issues/1860
|
// visit Property functions first - https://github.com/babel/babel/issues/1860
|
||||||
|
|
||||||
export var visitor = {
|
export let visitor = {
|
||||||
"ArrowFunctionExpression|FunctionExpression": {
|
"ArrowFunctionExpression|FunctionExpression": {
|
||||||
exit() {
|
exit() {
|
||||||
if (!this.parentPath.isProperty()) {
|
if (!this.parentPath.isProperty()) {
|
||||||
@ -16,11 +16,11 @@ export var visitor = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
ObjectExpression() {
|
ObjectExpression() {
|
||||||
var props = this.get("properties");
|
let props = this.get("properties");
|
||||||
for (var prop of (props: Array)) {
|
for (let prop of (props: Array)) {
|
||||||
var value = prop.get("value");
|
let value = prop.get("value");
|
||||||
if (value.isFunction()) {
|
if (value.isFunction()) {
|
||||||
var newNode = bare(value.node, prop.node, value.scope);
|
let newNode = bare(value.node, prop.node, value.scope);
|
||||||
if (newNode) value.replaceWith(newNode);
|
if (newNode) value.replaceWith(newNode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -24,8 +24,8 @@ export { inherits, inspect } from "util";
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
export function canCompile(filename: string, altExts?: Array<string>) {
|
export function canCompile(filename: string, altExts?: Array<string>) {
|
||||||
var exts = altExts || canCompile.EXTENSIONS;
|
let exts = altExts || canCompile.EXTENSIONS;
|
||||||
var ext = path.extname(filename);
|
let ext = path.extname(filename);
|
||||||
return contains(exts, ext);
|
return contains(exts, ext);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,7 +68,7 @@ export function regexify(val: any): RegExp {
|
|||||||
if (startsWith(val, "./") || startsWith(val, "*/")) val = val.slice(2);
|
if (startsWith(val, "./") || startsWith(val, "*/")) val = val.slice(2);
|
||||||
if (startsWith(val, "**/")) val = val.slice(3);
|
if (startsWith(val, "**/")) val = val.slice(3);
|
||||||
|
|
||||||
var regex = minimatch.makeRe(val, { nocase: true });
|
let regex = minimatch.makeRe(val, { nocase: true });
|
||||||
return new RegExp(regex.source.slice(1, -1), "i");
|
return new RegExp(regex.source.slice(1, -1), "i");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,7 +142,7 @@ function _shouldIgnore(pattern, filename) {
|
|||||||
* A visitor for Babel templates, replaces placeholder references.
|
* A visitor for Babel templates, replaces placeholder references.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var templateVisitor = {
|
let templateVisitor = {
|
||||||
/**
|
/**
|
||||||
* 360 NoScope PWNd
|
* 360 NoScope PWNd
|
||||||
*/
|
*/
|
||||||
@ -169,7 +169,7 @@ var templateVisitor = {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
export function template(name: string, nodes?: Array<Object>, keepExpression?: boolean): Object {
|
export function template(name: string, nodes?: Array<Object>, keepExpression?: boolean): Object {
|
||||||
var ast = exports.templates[name];
|
let ast = exports.templates[name];
|
||||||
if (!ast) throw new ReferenceError(`unknown template ${name}`);
|
if (!ast) throw new ReferenceError(`unknown template ${name}`);
|
||||||
|
|
||||||
if (nodes === true) {
|
if (nodes === true) {
|
||||||
@ -185,7 +185,7 @@ export function template(name: string, nodes?: Array<Object>, keepExpression?: b
|
|||||||
|
|
||||||
if (ast.body.length > 1) return ast.body;
|
if (ast.body.length > 1) return ast.body;
|
||||||
|
|
||||||
var node = ast.body[0];
|
let node = ast.body[0];
|
||||||
|
|
||||||
if (!keepExpression && t.isExpressionStatement(node)) {
|
if (!keepExpression && t.isExpressionStatement(node)) {
|
||||||
return node.expression;
|
return node.expression;
|
||||||
@ -200,7 +200,7 @@ export function template(name: string, nodes?: Array<Object>, keepExpression?: b
|
|||||||
|
|
||||||
export function parseTemplate(loc: string, code: string): Object {
|
export function parseTemplate(loc: string, code: string): Object {
|
||||||
try {
|
try {
|
||||||
var ast = parse(code, { filename: loc, looseModules: true }).program;
|
let ast = parse(code, { filename: loc, looseModules: true }).program;
|
||||||
ast = traverse.removeProperties(ast);
|
ast = traverse.removeProperties(ast);
|
||||||
return ast;
|
return ast;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@ -214,19 +214,19 @@ export function parseTemplate(loc: string, code: string): Object {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
function loadTemplates(): Object {
|
function loadTemplates(): Object {
|
||||||
var templates = {};
|
let templates = {};
|
||||||
|
|
||||||
var templatesLoc = path.join(__dirname, "transformation/templates");
|
let templatesLoc = path.join(__dirname, "transformation/templates");
|
||||||
if (!pathExists.sync(templatesLoc)) {
|
if (!pathExists.sync(templatesLoc)) {
|
||||||
throw new ReferenceError(messages.get("missingTemplatesDirectory"));
|
throw new ReferenceError(messages.get("missingTemplatesDirectory"));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var name of (fs.readdirSync(templatesLoc): Array)) {
|
for (let name of (fs.readdirSync(templatesLoc): Array)) {
|
||||||
if (name[0] === ".") continue;
|
if (name[0] === ".") continue;
|
||||||
|
|
||||||
var key = path.basename(name, path.extname(name));
|
let key = path.basename(name, path.extname(name));
|
||||||
var loc = path.join(templatesLoc, name);
|
let loc = path.join(templatesLoc, name);
|
||||||
var code = fs.readFileSync(loc, "utf8");
|
let code = fs.readFileSync(loc, "utf8");
|
||||||
|
|
||||||
templates[key] = parseTemplate(loc, code);
|
templates[key] = parseTemplate(loc, code);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -210,12 +210,12 @@ export default class Buffer {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
_removeSpacesAfterLastNewline() {
|
_removeSpacesAfterLastNewline() {
|
||||||
var lastNewlineIndex = this.buf.lastIndexOf("\n");
|
let lastNewlineIndex = this.buf.lastIndexOf("\n");
|
||||||
if (lastNewlineIndex === -1) {
|
if (lastNewlineIndex === -1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var index = this.buf.length - 1;
|
let index = this.buf.length - 1;
|
||||||
while (index > lastNewlineIndex) {
|
while (index > lastNewlineIndex) {
|
||||||
if (this.buf[index] !== " ") {
|
if (this.buf[index] !== " ") {
|
||||||
break;
|
break;
|
||||||
@ -236,7 +236,7 @@ export default class Buffer {
|
|||||||
push(str, noIndent) {
|
push(str, noIndent) {
|
||||||
if (!this.format.compact && this._indent && !noIndent && str !== "\n") {
|
if (!this.format.compact && this._indent && !noIndent && str !== "\n") {
|
||||||
// we have an indent level and we aren't pushing a newline
|
// we have an indent level and we aren't pushing a newline
|
||||||
var indent = this.getIndent();
|
let indent = this.getIndent();
|
||||||
|
|
||||||
// replace all newlines with newlines with the indentation
|
// replace all newlines with newlines with the indentation
|
||||||
str = str.replace(/\n/g, `\n${indent}`);
|
str = str.replace(/\n/g, `\n${indent}`);
|
||||||
@ -254,10 +254,10 @@ export default class Buffer {
|
|||||||
|
|
||||||
_push(str) {
|
_push(str) {
|
||||||
// see startTerminatorless() instance method
|
// see startTerminatorless() instance method
|
||||||
var parenPushNewlineState = this.parenPushNewlineState;
|
let parenPushNewlineState = this.parenPushNewlineState;
|
||||||
if (parenPushNewlineState) {
|
if (parenPushNewlineState) {
|
||||||
for (var i = 0; i < str.length; i++) {
|
for (let i = 0; i < str.length; i++) {
|
||||||
var cha = str[i];
|
let cha = str[i];
|
||||||
|
|
||||||
// we can ignore spaces since they wont interupt a terminatorless separator
|
// we can ignore spaces since they wont interupt a terminatorless separator
|
||||||
if (cha === " ") continue;
|
if (cha === " ") continue;
|
||||||
@ -299,8 +299,8 @@ export default class Buffer {
|
|||||||
isLast(cha) {
|
isLast(cha) {
|
||||||
if (this.format.compact) return false;
|
if (this.format.compact) return false;
|
||||||
|
|
||||||
var buf = this.buf;
|
let buf = this.buf;
|
||||||
var last = buf[buf.length - 1];
|
let last = buf[buf.length - 1];
|
||||||
|
|
||||||
if (Array.isArray(cha)) {
|
if (Array.isArray(cha)) {
|
||||||
return includes(cha, last);
|
return includes(cha, last);
|
||||||
|
|||||||
@ -5,8 +5,8 @@ import * as t from "babel-types";
|
|||||||
const SCIENTIFIC_NOTATION = /e/i;
|
const SCIENTIFIC_NOTATION = /e/i;
|
||||||
|
|
||||||
export function UnaryExpression(node, print) {
|
export function UnaryExpression(node, print) {
|
||||||
var needsSpace = /[a-z]$/.test(node.operator);
|
let needsSpace = /[a-z]$/.test(node.operator);
|
||||||
var arg = node.argument;
|
let arg = node.argument;
|
||||||
|
|
||||||
if (t.isUpdateExpression(arg) || t.isUnaryExpression(arg)) {
|
if (t.isUpdateExpression(arg) || t.isUnaryExpression(arg)) {
|
||||||
needsSpace = true;
|
needsSpace = true;
|
||||||
@ -86,9 +86,9 @@ export function CallExpression(node, print) {
|
|||||||
|
|
||||||
this.push("(");
|
this.push("(");
|
||||||
|
|
||||||
var isPrettyCall = node._prettyCall && !this.format.retainLines && !this.format.compact;
|
let isPrettyCall = node._prettyCall && !this.format.retainLines && !this.format.compact;
|
||||||
|
|
||||||
var separator;
|
let separator;
|
||||||
if (isPrettyCall) {
|
if (isPrettyCall) {
|
||||||
separator = ",\n";
|
separator = ",\n";
|
||||||
this.newline();
|
this.newline();
|
||||||
@ -115,15 +115,15 @@ function buildYieldAwait(keyword) {
|
|||||||
|
|
||||||
if (node.argument) {
|
if (node.argument) {
|
||||||
this.push(" ");
|
this.push(" ");
|
||||||
var terminatorState = this.startTerminatorless();
|
let terminatorState = this.startTerminatorless();
|
||||||
print.plain(node.argument);
|
print.plain(node.argument);
|
||||||
this.endTerminatorless(terminatorState);
|
this.endTerminatorless(terminatorState);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export var YieldExpression = buildYieldAwait("yield");
|
export let YieldExpression = buildYieldAwait("yield");
|
||||||
export var AwaitExpression = buildYieldAwait("await");
|
export let AwaitExpression = buildYieldAwait("await");
|
||||||
|
|
||||||
export function EmptyStatement() {
|
export function EmptyStatement() {
|
||||||
this.semicolon();
|
this.semicolon();
|
||||||
@ -144,7 +144,7 @@ export function AssignmentExpression(node, print) {
|
|||||||
// todo: add cases where the spaces can be dropped when in compact mode
|
// todo: add cases where the spaces can be dropped when in compact mode
|
||||||
print.plain(node.left);
|
print.plain(node.left);
|
||||||
|
|
||||||
var spaces = node.operator === "in" || node.operator === "instanceof";
|
let spaces = node.operator === "in" || node.operator === "instanceof";
|
||||||
spaces = true; // todo: https://github.com/babel/babel/issues/1835
|
spaces = true; // todo: https://github.com/babel/babel/issues/1835
|
||||||
this.space(spaces);
|
this.space(spaces);
|
||||||
|
|
||||||
@ -175,14 +175,14 @@ export {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export function MemberExpression(node, print) {
|
export function MemberExpression(node, print) {
|
||||||
var obj = node.object;
|
let obj = node.object;
|
||||||
print.plain(obj);
|
print.plain(obj);
|
||||||
|
|
||||||
if (!node.computed && t.isMemberExpression(node.property)) {
|
if (!node.computed && t.isMemberExpression(node.property)) {
|
||||||
throw new TypeError("Got a MemberExpression for MemberExpression property");
|
throw new TypeError("Got a MemberExpression for MemberExpression property");
|
||||||
}
|
}
|
||||||
|
|
||||||
var computed = node.computed;
|
let computed = node.computed;
|
||||||
if (t.isLiteral(node.property) && isNumber(node.property.value)) {
|
if (t.isLiteral(node.property) && isNumber(node.property.value)) {
|
||||||
computed = true;
|
computed = true;
|
||||||
}
|
}
|
||||||
@ -193,7 +193,7 @@ export function MemberExpression(node, print) {
|
|||||||
this.push("]");
|
this.push("]");
|
||||||
} else {
|
} else {
|
||||||
if (t.isLiteral(node.object)) {
|
if (t.isLiteral(node.object)) {
|
||||||
var val = this._Literal(node.object);
|
let val = this._Literal(node.object);
|
||||||
if (isInteger(+val) && !SCIENTIFIC_NOTATION.test(val) && !this.endsWith(".")) {
|
if (isInteger(+val) && !SCIENTIFIC_NOTATION.test(val) && !this.endsWith(".")) {
|
||||||
this.push(".");
|
this.push(".");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -38,7 +38,7 @@ export function DeclareModule(node, print) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function DeclareVariable(node, print) {
|
export function DeclareVariable(node, print) {
|
||||||
this.push("declare var ");
|
this.push("declare let ");
|
||||||
print.plain(node.id);
|
print.plain(node.id);
|
||||||
print.plain(node.id.typeAnnotation);
|
print.plain(node.id.typeAnnotation);
|
||||||
this.semicolon();
|
this.semicolon();
|
||||||
@ -174,7 +174,7 @@ export { TypeParameterInstantiation as TypeParameterDeclaration };
|
|||||||
|
|
||||||
export function ObjectTypeAnnotation(node, print) {
|
export function ObjectTypeAnnotation(node, print) {
|
||||||
this.push("{");
|
this.push("{");
|
||||||
var props = node.properties.concat(node.callProperties, node.indexers);
|
let props = node.properties.concat(node.callProperties, node.indexers);
|
||||||
|
|
||||||
if (props.length) {
|
if (props.length) {
|
||||||
this.space();
|
this.space();
|
||||||
|
|||||||
@ -39,12 +39,12 @@ export function JSXText(node) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function JSXElement(node, print) {
|
export function JSXElement(node, print) {
|
||||||
var open = node.openingElement;
|
let open = node.openingElement;
|
||||||
print.plain(open);
|
print.plain(open);
|
||||||
if (open.selfClosing) return;
|
if (open.selfClosing) return;
|
||||||
|
|
||||||
this.indent();
|
this.indent();
|
||||||
for (var child of (node.children: Array)) {
|
for (let child of (node.children: Array)) {
|
||||||
print.plain(child);
|
print.plain(child);
|
||||||
}
|
}
|
||||||
this.dedent();
|
this.dedent();
|
||||||
|
|||||||
@ -17,9 +17,9 @@ export function _params(node, print) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function _method(node, print) {
|
export function _method(node, print) {
|
||||||
var value = node.value;
|
let value = node.value;
|
||||||
var kind = node.kind;
|
let kind = node.kind;
|
||||||
var key = node.key;
|
let key = node.key;
|
||||||
|
|
||||||
if (kind === "method" || kind === "init") {
|
if (kind === "method" || kind === "init") {
|
||||||
if (value.generator) {
|
if (value.generator) {
|
||||||
|
|||||||
@ -51,10 +51,10 @@ export function ExportDefaultDeclaration(node, print) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function ExportDeclaration(node, print) {
|
function ExportDeclaration(node, print) {
|
||||||
var specifiers = node.specifiers;
|
let specifiers = node.specifiers;
|
||||||
|
|
||||||
if (node.declaration) {
|
if (node.declaration) {
|
||||||
var declar = node.declaration;
|
let declar = node.declaration;
|
||||||
print.plain(declar);
|
print.plain(declar);
|
||||||
if (t.isStatement(declar) || t.isFunction(declar) || t.isClass(declar)) return;
|
if (t.isStatement(declar) || t.isFunction(declar) || t.isClass(declar)) return;
|
||||||
} else {
|
} else {
|
||||||
@ -62,8 +62,8 @@ function ExportDeclaration(node, print) {
|
|||||||
this.push("type ");
|
this.push("type ");
|
||||||
}
|
}
|
||||||
|
|
||||||
var first = specifiers[0];
|
let first = specifiers[0];
|
||||||
var hasSpecial = false;
|
let hasSpecial = false;
|
||||||
if (t.isExportDefaultSpecifier(first) || t.isExportNamespaceSpecifier(first)) {
|
if (t.isExportDefaultSpecifier(first) || t.isExportNamespaceSpecifier(first)) {
|
||||||
hasSpecial = true;
|
hasSpecial = true;
|
||||||
print.plain(specifiers.shift());
|
print.plain(specifiers.shift());
|
||||||
@ -98,9 +98,9 @@ export function ImportDeclaration(node, print) {
|
|||||||
this.push(node.importKind + " ");
|
this.push(node.importKind + " ");
|
||||||
}
|
}
|
||||||
|
|
||||||
var specfiers = node.specifiers;
|
let specfiers = node.specifiers;
|
||||||
if (specfiers && specfiers.length) {
|
if (specfiers && specfiers.length) {
|
||||||
var first = node.specifiers[0];
|
let first = node.specifiers[0];
|
||||||
if (t.isImportDefaultSpecifier(first) || t.isImportNamespaceSpecifier(first)) {
|
if (t.isImportDefaultSpecifier(first) || t.isImportNamespaceSpecifier(first)) {
|
||||||
print.plain(node.specifiers.shift());
|
print.plain(node.specifiers.shift());
|
||||||
if (node.specifiers.length) {
|
if (node.specifiers.length) {
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user