Add placeholders
This commit is contained in:
parent
e572d25640
commit
4809747304
@ -3,16 +3,28 @@
|
||||
require("./node");
|
||||
var transform = module.exports = require("../transformation");
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
transform.options = require("../transformation/file/options");
|
||||
transform.version = require("../../../package").version;
|
||||
|
||||
transform.transform = transform;
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
transform.run = function (code, opts = {}) {
|
||||
opts.sourceMaps = "inline";
|
||||
return new Function(transform(code, opts).code)();
|
||||
};
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
transform.load = function (url, callback, opts = {}, hold) {
|
||||
opts.filename = opts.filename || url;
|
||||
|
||||
@ -20,6 +32,10 @@ transform.load = function (url, callback, opts = {}, hold) {
|
||||
xhr.open("GET", url, true);
|
||||
if ("overrideMimeType" in xhr) xhr.overrideMimeType("text/plain");
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
xhr.onreadystatechange = function () {
|
||||
if (xhr.readyState !== 4) return;
|
||||
|
||||
@ -36,11 +52,19 @@ transform.load = function (url, callback, opts = {}, hold) {
|
||||
xhr.send(null);
|
||||
};
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
var runScripts = function () {
|
||||
var scripts = [];
|
||||
var types = ["text/ecmascript-6", "text/6to5", "text/babel", "module"];
|
||||
var index = 0;
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
var exec = function () {
|
||||
var param = scripts[index];
|
||||
if (param instanceof Array) {
|
||||
@ -50,6 +74,10 @@ var runScripts = function () {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
var run = function (script, i) {
|
||||
var opts = {};
|
||||
|
||||
@ -78,6 +106,10 @@ var runScripts = function () {
|
||||
exec();
|
||||
};
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
if (global.addEventListener) {
|
||||
global.addEventListener("DOMContentLoaded", runScripts, false);
|
||||
} else if (global.attachEvent) {
|
||||
|
||||
@ -19,16 +19,28 @@ export { version } from "../../../package";
|
||||
import * as t from "../types";
|
||||
export { t as types };
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function register(opts?: Object) {
|
||||
var callback = require("./register/node-polyfill");
|
||||
if (opts != null) callback(opts);
|
||||
return callback;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function polyfill() {
|
||||
require("../polyfill");
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function transformFile(filename: string, opts?: Object, callback: Function) {
|
||||
if (isFunction(opts)) {
|
||||
callback = opts;
|
||||
@ -52,11 +64,19 @@ export function transformFile(filename: string, opts?: Object, callback: Functio
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function transformFileSync(filename: string, opts?: Object = {}) {
|
||||
opts.filename = filename;
|
||||
return transform(fs.readFileSync(filename, "utf8"), opts);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function parse(code, opts = {}) {
|
||||
opts.allowHashBang = true;
|
||||
opts.sourceType = "module";
|
||||
|
||||
@ -6,10 +6,18 @@ import pathExists from "path-exists";
|
||||
const FILENAME = process.env.BABEL_CACHE_PATH || path.join(homeOrTmp, ".babel.json");
|
||||
var data = {};
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function save() {
|
||||
fs.writeFileSync(FILENAME, JSON.stringify(data, null, " "));
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function load() {
|
||||
if (process.env.BABEL_DISABLE_CACHE) return;
|
||||
|
||||
@ -25,6 +33,10 @@ export function load() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function get() {
|
||||
return data;
|
||||
}
|
||||
|
||||
@ -8,6 +8,10 @@ import * as util from "../../util";
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
sourceMapSupport.install({
|
||||
handleUncaughtExceptions: false,
|
||||
retrieveSourceMap(source) {
|
||||
@ -23,12 +27,16 @@ sourceMapSupport.install({
|
||||
}
|
||||
});
|
||||
|
||||
//
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
registerCache.load();
|
||||
var cache = registerCache.get();
|
||||
|
||||
//
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
var transformOpts = {};
|
||||
|
||||
@ -40,14 +48,26 @@ var maps = {};
|
||||
|
||||
var cwd = process.cwd();
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
var getRelativePath = function (filename){
|
||||
return path.relative(cwd, filename);
|
||||
};
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
var mtime = function (filename) {
|
||||
return +fs.statSync(filename).mtime;
|
||||
};
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
var compile = function (filename, opts = {}) {
|
||||
var result;
|
||||
|
||||
@ -84,6 +104,10 @@ var compile = function (filename, opts = {}) {
|
||||
return result.code;
|
||||
};
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
var shouldIgnore = function (filename) {
|
||||
if (!ignore && !only) {
|
||||
return getRelativePath(filename).split(path.sep).indexOf("node_modules") >= 0;
|
||||
@ -92,6 +116,10 @@ var shouldIgnore = function (filename) {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
var istanbulMonkey = {};
|
||||
|
||||
if (process.env.running_under_istanbul) {
|
||||
@ -113,15 +141,27 @@ if (process.env.running_under_istanbul) {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
var istanbulLoader = function (m, filename, old) {
|
||||
istanbulMonkey[filename] = true;
|
||||
old(m, filename);
|
||||
};
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
var normalLoader = function (m, filename) {
|
||||
m._compile(compile(filename), filename);
|
||||
};
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
var registerExtension = function (ext) {
|
||||
var old = oldHandlers[ext] || oldHandlers[".js"] || require.extensions[".js"];
|
||||
|
||||
@ -137,6 +177,10 @@ var registerExtension = function (ext) {
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
var hookExtensions = function (_exts) {
|
||||
each(oldHandlers, function (old, ext) {
|
||||
if (old === undefined) {
|
||||
@ -154,8 +198,16 @@ var hookExtensions = function (_exts) {
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
hookExtensions(util.canCompile.EXTENSIONS);
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export default function (opts = {}) {
|
||||
if (opts.only != null) only = util.arrayify(opts.only, util.regexify);
|
||||
if (opts.ignore != null) ignore = util.arrayify(opts.ignore, util.regexify);
|
||||
|
||||
@ -4,6 +4,10 @@ import isBoolean from "lodash/lang/isBoolean";
|
||||
import includes from "lodash/collection/includes";
|
||||
import isNumber from "lodash/lang/isNumber";
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export default class Buffer {
|
||||
constructor(position, format) {
|
||||
this.position = position;
|
||||
@ -12,10 +16,18 @@ export default class Buffer {
|
||||
this.buf = "";
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
get() {
|
||||
return trimRight(this.buf);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
getIndent() {
|
||||
if (this.format.compact || this.format.concise) {
|
||||
return "";
|
||||
@ -24,36 +36,68 @@ export default class Buffer {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
indentSize() {
|
||||
return this.getIndent().length;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
indent() {
|
||||
this._indent++;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
dedent() {
|
||||
this._indent--;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
semicolon() {
|
||||
this.push(";");
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
ensureSemicolon() {
|
||||
if (!this.isLast(";")) this.semicolon();
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
rightBrace() {
|
||||
this.newline(true);
|
||||
this.push("}");
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
keyword(name) {
|
||||
this.push(name);
|
||||
this.space();
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
space(force?) {
|
||||
if (!force && this.format.compact) return;
|
||||
|
||||
@ -62,6 +106,10 @@ export default class Buffer {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
removeLast(cha) {
|
||||
if (this.format.compact) return;
|
||||
if (!this.isLast(cha)) return;
|
||||
@ -70,6 +118,10 @@ export default class Buffer {
|
||||
this.position.unshift(cha);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
newline(i, removeLast) {
|
||||
if (this.format.compact || this.format.retainLines) return;
|
||||
|
||||
@ -100,6 +152,10 @@ export default class Buffer {
|
||||
this._newline(removeLast);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
_newline(removeLast) {
|
||||
// never allow more than two lines
|
||||
if (this.endsWith("\n\n")) return;
|
||||
@ -136,6 +192,10 @@ export default class Buffer {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
push(str, noIndent) {
|
||||
if (!this.format.compact && this._indent && !noIndent && str !== "\n") {
|
||||
// we have an indent level and we aren't pushing a newline
|
||||
@ -151,11 +211,19 @@ export default class Buffer {
|
||||
this._push(str);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
_push(str) {
|
||||
this.position.push(str);
|
||||
this.buf += str;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
endsWith(str, buf = this.buf) {
|
||||
if (str.length === 1) {
|
||||
return buf[buf.length - 1] === str;
|
||||
@ -164,6 +232,10 @@ export default class Buffer {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
isLast(cha) {
|
||||
if (this.format.compact) return false;
|
||||
|
||||
|
||||
@ -1,11 +1,23 @@
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function File(node, print) {
|
||||
print.plain(node.program);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function Program(node, print) {
|
||||
print.sequence(node.body);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function BlockStatement(node, print) {
|
||||
if (node.body.length === 0) {
|
||||
this.push("{}");
|
||||
@ -18,6 +30,10 @@ export function BlockStatement(node, print) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function Noop() {
|
||||
|
||||
}
|
||||
|
||||
@ -1,3 +1,7 @@
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function ClassDeclaration(node, print) {
|
||||
print.list(node.decorators, { separator: "" });
|
||||
this.push("class");
|
||||
@ -24,8 +28,16 @@ export function ClassDeclaration(node, print) {
|
||||
print.plain(node.body);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export { ClassDeclaration as ClassExpression };
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function ClassBody(node, print) {
|
||||
if (node.body.length === 0) {
|
||||
this.push("{}");
|
||||
@ -41,6 +53,9 @@ export function ClassBody(node, print) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function ClassProperty(node, print) {
|
||||
print.list(node.decorators, { separator: "" });
|
||||
@ -57,6 +72,10 @@ export function ClassProperty(node, print) {
|
||||
this.semicolon();
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function MethodDefinition(node, print) {
|
||||
print.list(node.decorators, { separator: "" });
|
||||
|
||||
|
||||
@ -1,3 +1,7 @@
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function ComprehensionBlock(node, print) {
|
||||
this.keyword("for");
|
||||
this.push("(");
|
||||
@ -7,6 +11,10 @@ export function ComprehensionBlock(node, print) {
|
||||
this.push(")");
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function ComprehensionExpression(node, print) {
|
||||
this.push(node.generator ? "(" : "[");
|
||||
|
||||
|
||||
@ -1,6 +1,10 @@
|
||||
import isNumber from "lodash/lang/isNumber";
|
||||
import * as t from "../../types";
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function UnaryExpression(node, print) {
|
||||
var needsSpace = /[a-z]$/.test(node.operator);
|
||||
var arg = node.argument;
|
||||
@ -18,18 +22,30 @@ export function UnaryExpression(node, print) {
|
||||
print.plain(node.argument);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function DoExpression(node, print) {
|
||||
this.push("do");
|
||||
this.space();
|
||||
print.plain(node.body);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function ParenthesizedExpression(node, print) {
|
||||
this.push("(");
|
||||
print.plain(node.expression);
|
||||
this.push(")");
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function UpdateExpression(node, print) {
|
||||
if (node.prefix) {
|
||||
this.push(node.operator);
|
||||
@ -40,6 +56,10 @@ export function UpdateExpression(node, print) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function ConditionalExpression(node, print) {
|
||||
print.plain(node.test);
|
||||
this.space();
|
||||
@ -52,6 +72,10 @@ export function ConditionalExpression(node, print) {
|
||||
print.plain(node.alternate);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function NewExpression(node, print) {
|
||||
this.push("new ");
|
||||
print.plain(node.callee);
|
||||
@ -60,24 +84,44 @@ export function NewExpression(node, print) {
|
||||
this.push(")");
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function SequenceExpression(node, print) {
|
||||
print.list(node.expressions);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function ThisExpression() {
|
||||
this.push("this");
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function Super() {
|
||||
this.push("super");
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function Decorator(node, print) {
|
||||
this.push("@");
|
||||
print.plain(node.expression);
|
||||
this.newline();
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function CallExpression(node, print) {
|
||||
print.plain(node.callee);
|
||||
|
||||
@ -102,6 +146,10 @@ export function CallExpression(node, print) {
|
||||
this.push(")");
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
var buildYieldAwait = function (keyword) {
|
||||
return function (node, print) {
|
||||
this.push(keyword);
|
||||
@ -117,24 +165,44 @@ var buildYieldAwait = function (keyword) {
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export var YieldExpression = buildYieldAwait("yield");
|
||||
export var AwaitExpression = buildYieldAwait("await");
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function EmptyStatement() {
|
||||
this.semicolon();
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function ExpressionStatement(node, print) {
|
||||
print.plain(node.expression);
|
||||
this.semicolon();
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function AssignmentPattern(node, print) {
|
||||
print.plain(node.left);
|
||||
this.push(" = ");
|
||||
print.plain(node.right);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function AssignmentExpression(node, print) {
|
||||
// todo: add cases where the spaces can be dropped when in compact mode
|
||||
print.plain(node.left);
|
||||
@ -158,17 +226,29 @@ export function AssignmentExpression(node, print) {
|
||||
print.plain(node.right);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function BindExpression(node, print) {
|
||||
print.plain(node.object);
|
||||
this.push("::");
|
||||
print.plain(node.callee);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export {
|
||||
AssignmentExpression as BinaryExpression,
|
||||
AssignmentExpression as LogicalExpression
|
||||
};
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function MemberExpression(node, print) {
|
||||
var obj = node.object;
|
||||
print.plain(obj);
|
||||
@ -192,6 +272,10 @@ export function MemberExpression(node, print) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function MetaProperty(node, print) {
|
||||
print.plain(node.meta);
|
||||
this.push(".");
|
||||
|
||||
@ -1,24 +1,44 @@
|
||||
import * as t from "../../types";
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function AnyTypeAnnotation() {
|
||||
this.push("any");
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function ArrayTypeAnnotation(node, print) {
|
||||
print.plain(node.elementType);
|
||||
this.push("[");
|
||||
this.push("]");
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function BooleanTypeAnnotation(node) {
|
||||
this.push("bool");
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function DeclareClass(node, print) {
|
||||
this.push("declare class ");
|
||||
this._interfaceish(node, print);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function DeclareFunction(node, print) {
|
||||
this.push("declare function ");
|
||||
print.plain(node.id);
|
||||
@ -26,6 +46,10 @@ export function DeclareFunction(node, print) {
|
||||
this.semicolon();
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function DeclareModule(node, print) {
|
||||
this.push("declare module ");
|
||||
print.plain(node.id);
|
||||
@ -33,6 +57,10 @@ export function DeclareModule(node, print) {
|
||||
print.plain(node.body);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function DeclareVariable(node, print) {
|
||||
this.push("declare var ");
|
||||
print.plain(node.id);
|
||||
@ -40,6 +68,10 @@ export function DeclareVariable(node, print) {
|
||||
this.semicolon();
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function FunctionTypeAnnotation(node, print, parent) {
|
||||
print.plain(node.typeParameters);
|
||||
this.push("(");
|
||||
@ -68,6 +100,10 @@ export function FunctionTypeAnnotation(node, print, parent) {
|
||||
print.plain(node.returnType);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function FunctionTypeParam(node, print) {
|
||||
print.plain(node.name);
|
||||
if (node.optional) this.push("?");
|
||||
@ -76,13 +112,25 @@ export function FunctionTypeParam(node, print) {
|
||||
print.plain(node.typeAnnotation);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function InterfaceExtends(node, print) {
|
||||
print.plain(node.id);
|
||||
print.plain(node.typeParameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export { InterfaceExtends as ClassImplements, InterfaceExtends as GenericTypeAnnotation };
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function _interfaceish(node, print) {
|
||||
print.plain(node.id);
|
||||
print.plain(node.typeParameters);
|
||||
@ -94,47 +142,87 @@ export function _interfaceish(node, print) {
|
||||
print.plain(node.body);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function InterfaceDeclaration(node, print) {
|
||||
this.push("interface ");
|
||||
this._interfaceish(node, print);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function IntersectionTypeAnnotation(node, print) {
|
||||
print.join(node.types, { separator: " & " });
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function MixedTypeAnnotation() {
|
||||
this.push("mixed");
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function NullableTypeAnnotation(node, print) {
|
||||
this.push("?");
|
||||
print.plain(node.typeAnnotation);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function NumberTypeAnnotation() {
|
||||
this.push("number");
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function StringLiteralTypeAnnotation(node) {
|
||||
this._stringLiteral(node.value);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function StringTypeAnnotation() {
|
||||
this.push("string");
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function TupleTypeAnnotation(node, print) {
|
||||
this.push("[");
|
||||
print.join(node.types, { separator: ", " });
|
||||
this.push("]");
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function TypeofTypeAnnotation(node, print) {
|
||||
this.push("typeof ");
|
||||
print.plain(node.argument);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function TypeAlias(node, print) {
|
||||
this.push("type ");
|
||||
print.plain(node.id);
|
||||
@ -146,6 +234,10 @@ export function TypeAlias(node, print) {
|
||||
this.semicolon();
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function TypeAnnotation(node, print) {
|
||||
this.push(":");
|
||||
this.space();
|
||||
@ -153,14 +245,26 @@ export function TypeAnnotation(node, print) {
|
||||
print.plain(node.typeAnnotation);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function TypeParameterInstantiation(node, print) {
|
||||
this.push("<");
|
||||
print.join(node.params, { separator: ", " });
|
||||
this.push(">");
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export { TypeParameterInstantiation as TypeParameterDeclaration };
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function ObjectTypeAnnotation(node, print) {
|
||||
this.push("{");
|
||||
var props = node.properties.concat(node.callProperties, node.indexers);
|
||||
@ -185,11 +289,19 @@ export function ObjectTypeAnnotation(node, print) {
|
||||
this.push("}");
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function ObjectTypeCallProperty(node, print) {
|
||||
if (node.static) this.push("static ");
|
||||
print.plain(node.value);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function ObjectTypeIndexer(node, print) {
|
||||
if (node.static) this.push("static ");
|
||||
this.push("[");
|
||||
@ -203,6 +315,10 @@ export function ObjectTypeIndexer(node, print) {
|
||||
print.plain(node.value);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function ObjectTypeProperty(node, print) {
|
||||
if (node.static) this.push("static ");
|
||||
print.plain(node.key);
|
||||
@ -214,16 +330,28 @@ export function ObjectTypeProperty(node, print) {
|
||||
print.plain(node.value);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function QualifiedTypeIdentifier(node, print) {
|
||||
print.plain(node.qualification);
|
||||
this.push(".");
|
||||
print.plain(node.id);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function UnionTypeAnnotation(node, print) {
|
||||
print.join(node.types, { separator: " | " });
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function TypeCastExpression(node, print) {
|
||||
this.push("(");
|
||||
print.plain(node.expression);
|
||||
@ -231,6 +359,10 @@ export function TypeCastExpression(node, print) {
|
||||
this.push(")");
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function VoidTypeAnnotation(node) {
|
||||
this.push("void");
|
||||
}
|
||||
|
||||
@ -1,5 +1,9 @@
|
||||
import * as t from "../../types";
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function JSXAttribute(node, print) {
|
||||
print.plain(node.name);
|
||||
if (node.value) {
|
||||
@ -8,34 +12,58 @@ export function JSXAttribute(node, print) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function JSXIdentifier(node) {
|
||||
this.push(node.name);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function JSXNamespacedName(node, print) {
|
||||
print.plain(node.namespace);
|
||||
this.push(":");
|
||||
print.plain(node.name);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function JSXMemberExpression(node, print) {
|
||||
print.plain(node.object);
|
||||
this.push(".");
|
||||
print.plain(node.property);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function JSXSpreadAttribute(node, print) {
|
||||
this.push("{...");
|
||||
print.plain(node.argument);
|
||||
this.push("}");
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function JSXExpressionContainer(node, print) {
|
||||
this.push("{");
|
||||
print.plain(node.expression);
|
||||
this.push("}");
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function JSXElement(node, print) {
|
||||
var open = node.openingElement;
|
||||
print.plain(open);
|
||||
@ -54,6 +82,10 @@ export function JSXElement(node, print) {
|
||||
print.plain(node.closingElement);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function JSXOpeningElement(node, print) {
|
||||
this.push("<");
|
||||
print.plain(node.name);
|
||||
@ -64,10 +96,18 @@ export function JSXOpeningElement(node, print) {
|
||||
this.push(node.selfClosing ? " />" : ">");
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function JSXClosingElement(node, print) {
|
||||
this.push("</");
|
||||
print.plain(node.name);
|
||||
this.push(">");
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function JSXEmptyExpression() {}
|
||||
|
||||
@ -1,5 +1,9 @@
|
||||
import * as t from "../../types";
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function _params(node, print) {
|
||||
print.plain(node.typeParameters);
|
||||
this.push("(");
|
||||
@ -16,6 +20,10 @@ export function _params(node, print) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function _method(node, print) {
|
||||
var value = node.value;
|
||||
var kind = node.kind;
|
||||
@ -46,6 +54,10 @@ export function _method(node, print) {
|
||||
print.plain(value.body);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function FunctionExpression(node, print) {
|
||||
if (node.async) this.push("async ");
|
||||
this.push("function");
|
||||
@ -63,8 +75,16 @@ export function FunctionExpression(node, print) {
|
||||
print.plain(node.body);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export { FunctionExpression as FunctionDeclaration };
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function ArrowFunctionExpression(node, print) {
|
||||
if (node.async) this.push("async ");
|
||||
|
||||
|
||||
@ -1,5 +1,9 @@
|
||||
import * as t from "../../types";
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function ImportSpecifier(node, print) {
|
||||
print.plain(node.imported);
|
||||
if (node.local && node.local.name !== node.imported.name) {
|
||||
@ -8,14 +12,26 @@ export function ImportSpecifier(node, print) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function ImportDefaultSpecifier(node, print) {
|
||||
print.plain(node.local);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function ExportDefaultSpecifier(node, print) {
|
||||
print.plain(node.exported);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function ExportSpecifier(node, print) {
|
||||
print.plain(node.local);
|
||||
if (node.exported && node.local.name !== node.exported.name) {
|
||||
@ -24,11 +40,19 @@ export function ExportSpecifier(node, print) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function ExportNamespaceSpecifier(node, print) {
|
||||
this.push("* as ");
|
||||
print.plain(node.exported);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function ExportAllDeclaration(node, print) {
|
||||
this.push("export *");
|
||||
if (node.exported) {
|
||||
@ -40,16 +64,28 @@ export function ExportAllDeclaration(node, print) {
|
||||
this.semicolon();
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function ExportNamedDeclaration(node, print) {
|
||||
this.push("export ");
|
||||
ExportDeclaration.call(this, node, print);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function ExportDefaultDeclaration(node, print) {
|
||||
this.push("export default ");
|
||||
ExportDeclaration.call(this, node, print);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
function ExportDeclaration(node, print) {
|
||||
var specifiers = node.specifiers;
|
||||
|
||||
@ -87,6 +123,10 @@ function ExportDeclaration(node, print) {
|
||||
this.ensureSemicolon();
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function ImportDeclaration(node, print) {
|
||||
this.push("import ");
|
||||
|
||||
@ -119,6 +159,10 @@ export function ImportDeclaration(node, print) {
|
||||
this.semicolon();
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function ImportNamespaceSpecifier(node, print) {
|
||||
this.push("* as ");
|
||||
print.plain(node.local);
|
||||
|
||||
@ -1,6 +1,10 @@
|
||||
import repeating from "repeating";
|
||||
import * as t from "../../types";
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function WithStatement(node, print) {
|
||||
this.keyword("with");
|
||||
this.push("(");
|
||||
@ -9,6 +13,10 @@ export function WithStatement(node, print) {
|
||||
print.block(node.body);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function IfStatement(node, print) {
|
||||
this.keyword("if");
|
||||
this.push("(");
|
||||
@ -25,6 +33,10 @@ export function IfStatement(node, print) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function ForStatement(node, print) {
|
||||
this.keyword("for");
|
||||
this.push("(");
|
||||
@ -47,6 +59,10 @@ export function ForStatement(node, print) {
|
||||
print.block(node.body);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function WhileStatement(node, print) {
|
||||
this.keyword("while");
|
||||
this.push("(");
|
||||
@ -55,6 +71,10 @@ export function WhileStatement(node, print) {
|
||||
print.block(node.body);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
var buildForXStatement = function (op) {
|
||||
return function (node, print) {
|
||||
this.keyword("for");
|
||||
@ -67,9 +87,17 @@ var buildForXStatement = function (op) {
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export var ForInStatement = buildForXStatement("in");
|
||||
export var ForOfStatement = buildForXStatement("of");
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function DoWhileStatement(node, print) {
|
||||
this.push("do ");
|
||||
print.plain(node.body);
|
||||
@ -80,6 +108,10 @@ export function DoWhileStatement(node, print) {
|
||||
this.push(");");
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
var buildLabelStatement = function (prefix, key) {
|
||||
return function (node, print) {
|
||||
this.push(prefix);
|
||||
@ -94,16 +126,28 @@ var buildLabelStatement = function (prefix, key) {
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export var ContinueStatement = buildLabelStatement("continue");
|
||||
export var ReturnStatement = buildLabelStatement("return", "argument");
|
||||
export var BreakStatement = buildLabelStatement("break");
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function LabeledStatement(node, print) {
|
||||
print.plain(node.label);
|
||||
this.push(": ");
|
||||
print.plain(node.body);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function TryStatement(node, print) {
|
||||
this.keyword("try");
|
||||
print.plain(node.block);
|
||||
@ -125,6 +169,10 @@ export function TryStatement(node, print) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function CatchClause(node, print) {
|
||||
this.keyword("catch");
|
||||
this.push("(");
|
||||
@ -133,12 +181,20 @@ export function CatchClause(node, print) {
|
||||
print.plain(node.body);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function ThrowStatement(node, print) {
|
||||
this.push("throw ");
|
||||
print.plain(node.argument);
|
||||
this.semicolon();
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function SwitchStatement(node, print) {
|
||||
this.keyword("switch");
|
||||
this.push("(");
|
||||
@ -157,6 +213,10 @@ export function SwitchStatement(node, print) {
|
||||
this.push("}");
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function SwitchCase(node, print) {
|
||||
if (node.test) {
|
||||
this.push("case ");
|
||||
@ -172,10 +232,18 @@ export function SwitchCase(node, print) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function DebuggerStatement() {
|
||||
this.push("debugger;");
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function VariableDeclaration(node, print, parent) {
|
||||
this.push(node.kind + " ");
|
||||
|
||||
@ -219,6 +287,10 @@ export function VariableDeclaration(node, print, parent) {
|
||||
this.semicolon();
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function VariableDeclarator(node, print) {
|
||||
print.plain(node.id);
|
||||
print.plain(node.id.typeAnnotation);
|
||||
|
||||
@ -1,12 +1,24 @@
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function TaggedTemplateExpression(node, print) {
|
||||
print.plain(node.tag);
|
||||
print.plain(node.quasi);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function TemplateElement(node) {
|
||||
this._push(node.value.raw);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function TemplateLiteral(node, print) {
|
||||
this.push("`");
|
||||
|
||||
|
||||
@ -3,17 +3,33 @@
|
||||
import isInteger from "is-integer";
|
||||
import * as t from "../../types";
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function Identifier(node) {
|
||||
this.push(node.name);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function RestElement(node, print) {
|
||||
this.push("...");
|
||||
print.plain(node.argument);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export { RestElement as SpreadElement, RestElement as SpreadProperty };
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function ObjectExpression(node, print) {
|
||||
var props = node.properties;
|
||||
|
||||
@ -30,8 +46,16 @@ export function ObjectExpression(node, print) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export { ObjectExpression as ObjectPattern };
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function Property(node, print) {
|
||||
print.list(node.decorators, { separator: "" });
|
||||
|
||||
@ -66,6 +90,10 @@ export function Property(node, print) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function ArrayExpression(node, print) {
|
||||
var elems = node.elements;
|
||||
var len = elems.length;
|
||||
@ -91,10 +119,22 @@ export function ArrayExpression(node, print) {
|
||||
this.push("]");
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export { ArrayExpression as ArrayPattern };
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
const SCIENTIFIC_NOTATION = /e/i;
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function Literal(node, print, parent) {
|
||||
var val = node.value;
|
||||
var type = typeof val;
|
||||
@ -125,6 +165,10 @@ export function Literal(node, print, parent) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function _stringLiteral(val) {
|
||||
val = JSON.stringify(val);
|
||||
|
||||
|
||||
@ -11,6 +11,10 @@ import each from "lodash/collection/each";
|
||||
import n from "./node";
|
||||
import * as t from "../types";
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
class CodeGenerator {
|
||||
constructor(ast, opts, code) {
|
||||
opts = opts || {};
|
||||
@ -27,6 +31,10 @@ class CodeGenerator {
|
||||
this.buffer = new Buffer(this.position, this.format);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
static normalizeOptions(code, opts, tokens) {
|
||||
var style = " ";
|
||||
if (code) {
|
||||
@ -57,6 +65,9 @@ class CodeGenerator {
|
||||
return format;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
static findCommonStringDelimiter(code, tokens) {
|
||||
var occurences = {
|
||||
single: 0,
|
||||
@ -86,6 +97,10 @@ class CodeGenerator {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
static generators = {
|
||||
templateLiterals: require("./generators/template-literals"),
|
||||
comprehensions: require("./generators/comprehensions"),
|
||||
@ -100,6 +115,10 @@ class CodeGenerator {
|
||||
jsx: require("./generators/jsx")
|
||||
};
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
generate() {
|
||||
var ast = this.ast;
|
||||
|
||||
@ -119,10 +138,18 @@ class CodeGenerator {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
buildPrint(parent) {
|
||||
return new NodePrinter(this, parent);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
catchUp(node, parent, leftParenPrinted) {
|
||||
// catch up to this nodes newline if we're behind
|
||||
if (node.loc && this.format.retainLines && this.buffer.buf) {
|
||||
@ -139,6 +166,10 @@ class CodeGenerator {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
_printNewline(leading, node, parent, opts) {
|
||||
if (!opts.statement && !n.isUserWhitespacable(node, parent)) {
|
||||
return;
|
||||
@ -169,6 +200,10 @@ class CodeGenerator {
|
||||
this.newline(lines);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
print(node, parent, opts = {}) {
|
||||
if (!node) return;
|
||||
|
||||
@ -218,6 +253,10 @@ class CodeGenerator {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
printJoin(print, nodes, opts = {}) {
|
||||
if (!nodes || !nodes.length) return;
|
||||
|
||||
@ -247,6 +286,10 @@ class CodeGenerator {
|
||||
if (opts.indent) this.dedent();
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
printAndIndentOnComments(print, node) {
|
||||
var indent = !!node.leadingComments;
|
||||
if (indent) this.indent();
|
||||
@ -254,6 +297,10 @@ class CodeGenerator {
|
||||
if (indent) this.dedent();
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
printBlock(print, node) {
|
||||
if (t.isEmptyStatement(node)) {
|
||||
this.semicolon();
|
||||
@ -263,6 +310,10 @@ class CodeGenerator {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
generateComment(comment) {
|
||||
var val = comment.value;
|
||||
if (comment.type === "CommentLine") {
|
||||
@ -273,14 +324,26 @@ class CodeGenerator {
|
||||
return val;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
printTrailingComments(node, parent) {
|
||||
this._printComments(this.getComments("trailingComments", node, parent));
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
printLeadingComments(node, parent) {
|
||||
this._printComments(this.getComments("leadingComments", node, parent));
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
getComments(key, node, parent) {
|
||||
if (t.isExpressionStatement(parent)) {
|
||||
return [];
|
||||
@ -300,10 +363,18 @@ class CodeGenerator {
|
||||
return comments;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
_getComments(key, node) {
|
||||
return (node && node[key]) || [];
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
_printComments(comments) {
|
||||
if (this.format.compact) return;
|
||||
if (!this.format.comments) return;
|
||||
@ -371,16 +442,28 @@ class CodeGenerator {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
each(Buffer.prototype, function (fn, key) {
|
||||
CodeGenerator.prototype[key] = function () {
|
||||
return fn.apply(this.buffer, arguments);
|
||||
};
|
||||
});
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
each(CodeGenerator.generators, function (generator) {
|
||||
extend(CodeGenerator.prototype, generator);
|
||||
});
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
module.exports = function (ast, opts, code) {
|
||||
var gen = new CodeGenerator(ast, opts, code);
|
||||
return gen.generate();
|
||||
|
||||
@ -4,6 +4,10 @@ import each from "lodash/collection/each";
|
||||
import some from "lodash/collection/some";
|
||||
import * as t from "../../types";
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
var find = function (obj, node, parent) {
|
||||
if (!obj) return;
|
||||
var result;
|
||||
@ -22,16 +26,28 @@ var find = function (obj, node, parent) {
|
||||
return result;
|
||||
};
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export default class Node {
|
||||
constructor(node, parent) {
|
||||
this.parent = parent;
|
||||
this.node = node;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
static isUserWhitespacable(node) {
|
||||
return t.isUserWhitespacable(node);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
static needsWhitespace(node, parent, type) {
|
||||
if (!node) return 0;
|
||||
|
||||
@ -54,14 +70,26 @@ export default class Node {
|
||||
return (linesInfo && linesInfo[type]) || 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
static needsWhitespaceBefore(node, parent) {
|
||||
return Node.needsWhitespace(node, parent, "before");
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
static needsWhitespaceAfter(node, parent) {
|
||||
return Node.needsWhitespace(node, parent, "after");
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
static needsParens(node, parent) {
|
||||
if (!parent) return false;
|
||||
|
||||
@ -77,6 +105,10 @@ export default class Node {
|
||||
return find(parens, node, parent);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
static needsParensNoLineTerminator(node, parent) {
|
||||
if (!parent) return false;
|
||||
|
||||
@ -89,6 +121,10 @@ export default class Node {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
each(Node, function (fn, key) {
|
||||
Node.prototype[key] = function () {
|
||||
// Avoid leaking arguments to prevent deoptimization
|
||||
|
||||
@ -21,12 +21,24 @@ each([
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function NullableTypeAnnotation(node, parent) {
|
||||
return t.isArrayTypeAnnotation(parent);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export { NullableTypeAnnotation as FunctionTypeAnnotation };
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function UpdateExpression(node, parent) {
|
||||
if (t.isMemberExpression(parent) && parent.object === node) {
|
||||
// (foo++).test()
|
||||
@ -34,6 +46,10 @@ export function UpdateExpression(node, parent) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function ObjectExpression(node, parent) {
|
||||
if (t.isExpressionStatement(parent)) {
|
||||
// ({ foo: "bar" });
|
||||
@ -48,6 +64,10 @@ export function ObjectExpression(node, parent) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function Binary(node, parent) {
|
||||
if ((t.isCallExpression(parent) || t.isNewExpression(parent)) && parent.callee === node) {
|
||||
return true;
|
||||
@ -78,6 +98,10 @@ export function Binary(node, parent) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function BinaryExpression(node, parent) {
|
||||
if (node.operator === "in") {
|
||||
// var i = (1 in []);
|
||||
@ -92,6 +116,10 @@ export function BinaryExpression(node, parent) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function SequenceExpression(node, parent) {
|
||||
if (t.isForStatement(parent)) {
|
||||
// Although parentheses wouldn't hurt around sequence
|
||||
@ -110,6 +138,10 @@ export function SequenceExpression(node, parent) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function YieldExpression(node, parent) {
|
||||
return t.isBinary(parent) ||
|
||||
t.isUnaryLike(parent) ||
|
||||
@ -120,14 +152,26 @@ export function YieldExpression(node, parent) {
|
||||
t.isYieldExpression(parent);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function ClassExpression(node, parent) {
|
||||
return t.isExpressionStatement(parent);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function UnaryLike(node, parent) {
|
||||
return t.isMemberExpression(parent) && parent.object === node;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function FunctionExpression(node, parent) {
|
||||
// function () {};
|
||||
if (t.isExpressionStatement(parent)) {
|
||||
@ -145,6 +189,10 @@ export function FunctionExpression(node, parent) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function ConditionalExpression(node, parent) {
|
||||
if (t.isUnaryLike(parent)) {
|
||||
return true;
|
||||
@ -171,6 +219,10 @@ export function ConditionalExpression(node, parent) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function AssignmentExpression(node) {
|
||||
if (t.isObjectPattern(node.left)) {
|
||||
return true;
|
||||
|
||||
@ -1,22 +1,42 @@
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export default class NodePrinter {
|
||||
constructor(generator, parent) {
|
||||
this.generator = generator;
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
plain(node, opts) {
|
||||
return this.generator.print(node, this.parent, opts);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
sequence(nodes, opts = {}) {
|
||||
opts.statement = true;
|
||||
return this.generator.printJoin(this, nodes, opts);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
join(nodes, opts) {
|
||||
return this.generator.printJoin(this, nodes, opts);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
list(items, opts = {}) {
|
||||
if (opts.separator == null) {
|
||||
opts.separator = ",";
|
||||
@ -26,10 +46,18 @@ export default class NodePrinter {
|
||||
return this.join(items, opts);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
block(node) {
|
||||
return this.generator.printBlock(this, node);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
indentOnComments(node) {
|
||||
return this.generator.printAndIndentOnComments(this, node);
|
||||
}
|
||||
|
||||
@ -3,6 +3,10 @@ import each from "lodash/collection/each";
|
||||
import map from "lodash/collection/map";
|
||||
import * as t from "../../types";
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
function crawl(node, state = {}) {
|
||||
if (t.isMemberExpression(node)) {
|
||||
crawl(node.object, state);
|
||||
@ -22,6 +26,10 @@ function crawl(node, state = {}) {
|
||||
return state;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
function isHelper(node) {
|
||||
if (t.isMemberExpression(node)) {
|
||||
return isHelper(node.object) || isHelper(node.property);
|
||||
@ -36,12 +44,25 @@ function isHelper(node) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
function isType(node) {
|
||||
return t.isLiteral(node) || t.isObjectExpression(node) || t.isArrayExpression(node) ||
|
||||
t.isIdentifier(node) || t.isMemberExpression(node);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
exports.nodes = {
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
AssignmentExpression(node) {
|
||||
var state = crawl(node.right);
|
||||
if ((state.hasCall && state.hasHelper) || state.hasFunction) {
|
||||
@ -52,12 +73,20 @@ exports.nodes = {
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
SwitchCase(node, parent) {
|
||||
return {
|
||||
before: node.consequent.length || parent.cases[0] === node
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
LogicalExpression(node) {
|
||||
if (t.isFunction(node.left) || t.isFunction(node.right)) {
|
||||
return {
|
||||
@ -66,6 +95,10 @@ exports.nodes = {
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
Literal(node) {
|
||||
if (node.value === "use strict") {
|
||||
return {
|
||||
@ -74,6 +107,10 @@ exports.nodes = {
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
CallExpression(node) {
|
||||
if (t.isFunction(node.callee) || isHelper(node)) {
|
||||
return {
|
||||
@ -83,6 +120,10 @@ exports.nodes = {
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
VariableDeclaration(node) {
|
||||
for (var i = 0; i < node.declarations.length; i++) {
|
||||
var declar = node.declarations[i];
|
||||
@ -102,6 +143,10 @@ exports.nodes = {
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
IfStatement(node) {
|
||||
if (t.isBlockStatement(node.consequent)) {
|
||||
return {
|
||||
@ -112,6 +157,10 @@ exports.nodes = {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
exports.nodes.Property =
|
||||
exports.nodes.SpreadProperty = function (node, parent) {
|
||||
if (parent.properties[0] === node) {
|
||||
@ -121,20 +170,41 @@ exports.nodes.SpreadProperty = function (node, parent) {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
exports.list = {
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
VariableDeclaration(node) {
|
||||
return map(node.declarations, "init");
|
||||
},
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
ArrayExpression(node) {
|
||||
return node.elements;
|
||||
},
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
ObjectExpression(node) {
|
||||
return node.properties;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
each({
|
||||
Function: true,
|
||||
Class: true,
|
||||
|
||||
@ -1,9 +1,17 @@
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export default class Position {
|
||||
constructor() {
|
||||
this.line = 1;
|
||||
this.column = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
push(str) {
|
||||
for (var i = 0; i < str.length; i++) {
|
||||
if (str[i] === "\n") {
|
||||
@ -15,6 +23,10 @@ export default class Position {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
unshift(str) {
|
||||
for (var i = 0; i < str.length; i++) {
|
||||
if (str[i] === "\n") {
|
||||
|
||||
@ -1,6 +1,10 @@
|
||||
import sourceMap from "source-map";
|
||||
import * as t from "../types";
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export default class SourceMap {
|
||||
constructor(position, opts, code) {
|
||||
this.position = position;
|
||||
@ -18,6 +22,10 @@ export default class SourceMap {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
get() {
|
||||
var map = this.map;
|
||||
if (map) {
|
||||
@ -27,6 +35,10 @@ export default class SourceMap {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
mark(node, type) {
|
||||
var loc = node.loc;
|
||||
if (!loc) return; // no location info
|
||||
|
||||
@ -18,6 +18,10 @@ function getLookupIndex(i, base, max) {
|
||||
return i;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export default class Whitespace {
|
||||
constructor(tokens) {
|
||||
this.tokens = tokens;
|
||||
@ -34,6 +38,10 @@ export default class Whitespace {
|
||||
this._lastFoundIndex = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
getNewlinesBefore(node) {
|
||||
var startToken;
|
||||
var endToken;
|
||||
@ -57,6 +65,10 @@ export default class Whitespace {
|
||||
return this.getNewlinesBetween(startToken, endToken);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
getNewlinesAfter(node) {
|
||||
var startToken;
|
||||
var endToken;
|
||||
@ -91,6 +103,10 @@ export default class Whitespace {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
getNewlinesBetween(startToken, endToken) {
|
||||
if (!endToken || !endToken.loc) return 0;
|
||||
|
||||
|
||||
@ -4,6 +4,10 @@ import jsTokens from "js-tokens";
|
||||
import esutils from "esutils";
|
||||
import chalk from "chalk";
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
var defs = {
|
||||
string: chalk.red,
|
||||
punctuator: chalk.bold,
|
||||
@ -17,8 +21,16 @@ var defs = {
|
||||
invalid: chalk.inverse
|
||||
};
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
const NEWLINE = /\r\n|[\n\r\u2028\u2029]/;
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
function getTokenType(match) {
|
||||
var token = jsTokens.matchToToken(match);
|
||||
if (token.type === "name" && esutils.keyword.isReservedWordES6(token.value)) {
|
||||
@ -42,6 +54,10 @@ function getTokenType(match) {
|
||||
return token.type;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
function highlight(text) {
|
||||
return text.replace(jsTokens, function (...args) {
|
||||
var type = getTokenType(args);
|
||||
@ -54,6 +70,10 @@ function highlight(text) {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export default function (lines: number, lineNumber: number, colNumber: number, opts = {}): string {
|
||||
colNumber = Math.max(colNumber, 0);
|
||||
|
||||
|
||||
@ -1,5 +1,9 @@
|
||||
import merge from "lodash/object/merge";
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export default function (dest, src) {
|
||||
if (!dest || !src) return;
|
||||
|
||||
|
||||
@ -1,5 +1,9 @@
|
||||
import * as t from "../types";
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export default function (ast, comments, tokens) {
|
||||
if (ast && ast.type === "Program") {
|
||||
return t.file(ast, comments || [], tokens || []);
|
||||
|
||||
@ -1,3 +1,7 @@
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export default function () {
|
||||
return Object.create(null);
|
||||
}
|
||||
|
||||
@ -2,6 +2,10 @@ import normalizeAst from "./normalize-ast";
|
||||
import estraverse from "estraverse";
|
||||
import * as acorn from "../../acorn";
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export default function (code, opts = {}) {
|
||||
var commentsAndTokens = [];
|
||||
var comments = [];
|
||||
|
||||
@ -1,5 +1,10 @@
|
||||
import * as util from "util";
|
||||
|
||||
/**
|
||||
* Mapping of messages to be used in Babel.
|
||||
* Messages can include $0-style placeholders.
|
||||
*/
|
||||
|
||||
export const MESSAGES = {
|
||||
tailCallReassignmentDeopt: "Function reference has been reassigned, so it will probably be dereferenced, therefore we can't optimise this with confidence",
|
||||
JSXNamespacedTags: "Namespace tags are not supported. ReactJSX is not XML.",
|
||||
@ -50,18 +55,28 @@ export const MESSAGES = {
|
||||
`
|
||||
};
|
||||
|
||||
export function get(key: String, ...args) {
|
||||
/**
|
||||
* Get a message with $0 placeholders replaced by arguments.
|
||||
*/
|
||||
|
||||
export function get(key: string, ...args): string {
|
||||
var msg = MESSAGES[key];
|
||||
if (!msg) throw new ReferenceError(`Unknown message ${JSON.stringify(key)}`);
|
||||
|
||||
// stringify args
|
||||
args = parseArgs(args);
|
||||
|
||||
// replace $0 placeholders with args
|
||||
return msg.replace(/\$(\d+)/g, function (str, i) {
|
||||
return args[--i];
|
||||
});
|
||||
}
|
||||
|
||||
export function parseArgs(args: Array<any>) {
|
||||
/**
|
||||
* Stingify arguments to be used inside messages.
|
||||
*/
|
||||
|
||||
export function parseArgs(args: Array<any>): Array<string> {
|
||||
return args.map(function (val) {
|
||||
if (val != null && val.inspect) {
|
||||
return val.inspect();
|
||||
|
||||
@ -5,6 +5,10 @@ import File from "../transformation/file";
|
||||
import each from "lodash/collection/each";
|
||||
import * as t from "../types";
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
function buildGlobal(namespace, builder) {
|
||||
var body = [];
|
||||
var container = t.functionExpression(null, [t.identifier("global")], t.blockStatement(body));
|
||||
@ -22,6 +26,10 @@ function buildGlobal(namespace, builder) {
|
||||
return tree;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
function buildUmd(namespace, builder) {
|
||||
var body = [];
|
||||
body.push(t.variableDeclaration("var", [
|
||||
@ -41,6 +49,10 @@ function buildUmd(namespace, builder) {
|
||||
return t.program([container]);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
function buildVar(namespace, builder) {
|
||||
var body = [];
|
||||
body.push(t.variableDeclaration("var", [
|
||||
@ -50,6 +62,10 @@ function buildVar(namespace, builder) {
|
||||
return t.program(body);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
function buildHelpers(body, namespace, whitelist) {
|
||||
each(File.helpers, function (name) {
|
||||
if (whitelist && whitelist.indexOf(name) === -1) return;
|
||||
@ -61,6 +77,10 @@ function buildHelpers(body, namespace, whitelist) {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export default function (whitelist, outputType = "global") {
|
||||
var namespace = t.identifier("babelHelpers");
|
||||
|
||||
|
||||
@ -2,6 +2,10 @@ import path from "path";
|
||||
|
||||
var root = path.resolve(__dirname, "../../../");
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export default function (module) {
|
||||
if (module.parent && module.parent.filename.indexOf(root) !== 0) {
|
||||
throw new Error("Don't hotlink internal Babel files.");
|
||||
|
||||
@ -19,6 +19,10 @@ import * as util from "../../util";
|
||||
import path from "path";
|
||||
import * as t from "../../types";
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export default class File {
|
||||
constructor(opts = {}, pipeline) {
|
||||
this.transformerDependencies = {};
|
||||
@ -52,6 +56,10 @@ export default class File {
|
||||
this.hub = new Hub(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
static helpers = [
|
||||
"inherits",
|
||||
"defaults",
|
||||
@ -89,8 +97,17 @@ export default class File {
|
||||
"interop-require"
|
||||
];
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
static soloHelpers = [];
|
||||
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
initOptions(opts) {
|
||||
opts = new OptionManager(this.log, this.pipeline).init(opts);
|
||||
|
||||
@ -134,10 +151,18 @@ export default class File {
|
||||
return opts;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
isLoose(key: string) {
|
||||
return includes(this.opts.loose, key);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
buildTransformers() {
|
||||
var file = this;
|
||||
|
||||
@ -192,6 +217,10 @@ export default class File {
|
||||
this.transformerStack = this.collapseStack(stack);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
collapseStack(_stack) {
|
||||
var stack = [];
|
||||
var ignore = [];
|
||||
@ -228,14 +257,26 @@ export default class File {
|
||||
return stack;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
set(key: string, val): any {
|
||||
return this.data[key] = val;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
setDynamic(key: string, fn: Function) {
|
||||
this.dynamicData[key] = fn;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
get(key: string): any {
|
||||
var data = this.data[key];
|
||||
if (data) {
|
||||
@ -248,12 +289,20 @@ export default class File {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
resolveModuleSource(source: string): string {
|
||||
var resolveModuleSource = this.opts.resolveModuleSource;
|
||||
if (resolveModuleSource) source = resolveModuleSource(source, this.opts.filename);
|
||||
return source;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
addImport(source: string, name?: string, type?: string): Object {
|
||||
name = name || source;
|
||||
var id = this.dynamicImportIds[name];
|
||||
@ -282,6 +331,10 @@ export default class File {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
attachAuxiliaryComment(node: Object): Object {
|
||||
var beforeComment = this.opts.auxiliaryCommentBefore;
|
||||
if (beforeComment) {
|
||||
@ -304,6 +357,10 @@ export default class File {
|
||||
return node;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
addHelper(name: string): Object {
|
||||
var isSolo = includes(File.soloHelpers, name);
|
||||
|
||||
@ -350,6 +407,10 @@ export default class File {
|
||||
return uid;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
errorWithNode(node, msg, Error = SyntaxError) {
|
||||
var err;
|
||||
if (node && node.loc) {
|
||||
@ -363,6 +424,10 @@ export default class File {
|
||||
return err;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
mergeSourceMap(map: Object) {
|
||||
var opts = this.opts;
|
||||
|
||||
@ -385,6 +450,9 @@ export default class File {
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
getModuleFormatter(type: string) {
|
||||
if (isFunction(type) || !moduleFormatters[type]) {
|
||||
@ -405,6 +473,10 @@ export default class File {
|
||||
return new ModuleFormatter(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
parse(code: string) {
|
||||
var opts = this.opts;
|
||||
|
||||
@ -433,6 +505,10 @@ export default class File {
|
||||
return tree;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
_addAst(ast) {
|
||||
this.path = NodePath.get({
|
||||
hub: this.hub,
|
||||
@ -445,6 +521,10 @@ export default class File {
|
||||
this.ast = ast;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
addAst(ast) {
|
||||
this.log.debug("Start set AST");
|
||||
this._addAst(ast);
|
||||
@ -458,6 +538,10 @@ export default class File {
|
||||
this.log.debug("End module formatter init");
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
transform() {
|
||||
this.call("pre");
|
||||
for (var pass of (this.transformerStack: Array)) {
|
||||
@ -468,6 +552,10 @@ export default class File {
|
||||
return this.generate();
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
wrap(code, callback) {
|
||||
code = code + "";
|
||||
|
||||
@ -505,22 +593,38 @@ export default class File {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
addCode(code: string) {
|
||||
code = (code || "") + "";
|
||||
code = this.parseInputSourceMap(code);
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
parseCode() {
|
||||
this.parseShebang();
|
||||
this.addAst(this.parse(this.code));
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
shouldIgnore() {
|
||||
var opts = this.opts;
|
||||
return util.shouldIgnore(opts.filename, opts.ignore, opts.only);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
call(key: string) {
|
||||
for (var pass of (this.uncollapsedTransformerStack: Array)) {
|
||||
var fn = pass.plugin[key];
|
||||
@ -528,6 +632,10 @@ export default class File {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
parseInputSourceMap(code: string) {
|
||||
var opts = this.opts;
|
||||
|
||||
@ -542,6 +650,10 @@ export default class File {
|
||||
return code;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
parseShebang() {
|
||||
var shebangMatch = shebangRegex.exec(this.code);
|
||||
if (shebangMatch) {
|
||||
@ -550,6 +662,10 @@ export default class File {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
makeResult({ code, map = null, ast, ignored }) {
|
||||
var result = {
|
||||
metadata: null,
|
||||
@ -575,6 +691,10 @@ export default class File {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
generate() {
|
||||
var opts = this.opts;
|
||||
var ast = this.ast;
|
||||
|
||||
@ -6,26 +6,46 @@ var generalDebug = buildDebug("babel");
|
||||
|
||||
var seenDeprecatedMessages = [];
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export default class Logger {
|
||||
constructor(file: File, filename: string) {
|
||||
this.filename = filename;
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
_buildMessage(msg: string): string {
|
||||
var parts = `[BABEL] ${this.filename}`;
|
||||
if (msg) parts += `: ${msg}`;
|
||||
return parts;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
warn(msg) {
|
||||
console.warn(this._buildMessage(msg));
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
error(msg: string, Constructor = Error) {
|
||||
throw new Constructor(this._buildMessage(msg));
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
deprecate(msg) {
|
||||
if (this.file.opts.suppressDeprecationMessages) return;
|
||||
|
||||
@ -40,14 +60,26 @@ export default class Logger {
|
||||
console.error(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
verbose(msg: string) {
|
||||
if (verboseDebug.enabled) verboseDebug(this._buildMessage(msg));
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
debug(msg: string) {
|
||||
if (generalDebug.enabled) generalDebug(this._buildMessage(msg));
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
deopt(node: Object, msg: string) {
|
||||
this.debug(msg);
|
||||
}
|
||||
|
||||
@ -3,6 +3,10 @@ import config from "./config";
|
||||
|
||||
export { config };
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function validateOption(key, val, pipeline) {
|
||||
var opt = config[key];
|
||||
var parser = opt && parsers[opt.type];
|
||||
@ -13,6 +17,10 @@ export function validateOption(key, val, pipeline) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function normaliseOptions(options = {}) {
|
||||
for (var key in options) {
|
||||
var val = options[key];
|
||||
|
||||
@ -31,7 +31,7 @@ export default class OptionManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
static createBareOptions() {
|
||||
@ -46,7 +46,7 @@ export default class OptionManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
addConfig(loc) {
|
||||
@ -67,7 +67,7 @@ export default class OptionManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
mergeOptions(opts, alias = "foreign") {
|
||||
@ -90,7 +90,7 @@ export default class OptionManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
findConfigs(loc) {
|
||||
@ -109,7 +109,7 @@ export default class OptionManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
normaliseOptions() {
|
||||
@ -142,7 +142,7 @@ export default class OptionManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
init(opts) {
|
||||
|
||||
@ -1,10 +1,18 @@
|
||||
import slash from "slash";
|
||||
import * as util from "../../../util";
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function transformerList(val) {
|
||||
return util.arrayify(val);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
transformerList.validate = function (key, val, pipeline) {
|
||||
if (val.indexOf("all") >= 0 || val.indexOf(true) >= 0) {
|
||||
val = Object.keys(pipeline.transformers);
|
||||
@ -13,20 +21,40 @@ transformerList.validate = function (key, val, pipeline) {
|
||||
return pipeline._ensureTransformerNames(key, val);
|
||||
};
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function number(val) {
|
||||
return +val;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export var filename = slash;
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function boolean(val) {
|
||||
return !!val;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function booleanString(val) {
|
||||
return util.booleanify(val);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function list(val) {
|
||||
return util.list(val);
|
||||
}
|
||||
|
||||
@ -5,6 +5,10 @@ import * as messages from "../../messages";
|
||||
import traverse from "../../traversal";
|
||||
import parse from "../../helpers/parse";
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
var context = {
|
||||
messages,
|
||||
Transformer,
|
||||
@ -16,9 +20,22 @@ var context = {
|
||||
|
||||
import * as util from "../../util";
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export default class PluginManager {
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
static memoisedPlugins = [];
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
static memoisePluginContainer(fn) {
|
||||
for (var i = 0; i < PluginManager.memoisedPlugins.length; i++) {
|
||||
var plugin = PluginManager.memoisedPlugins[i];
|
||||
@ -33,8 +50,16 @@ export default class PluginManager {
|
||||
return transformer;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
static positions = ["before", "after"];
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
constructor({ file, transformers, before, after } = { transformers: {}, before: [], after: [] }) {
|
||||
this.transformers = transformers;
|
||||
this.file = file;
|
||||
@ -42,6 +67,10 @@ export default class PluginManager {
|
||||
this.after = after;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
subnormaliseString(name, position) {
|
||||
// this is a plugin in the form of "foobar" or "foobar:after"
|
||||
// where the optional colon is the delimiter for plugin position in the transformer stack
|
||||
@ -61,6 +90,10 @@ export default class PluginManager {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
validate(name, plugin) {
|
||||
// validate transformer key
|
||||
var key = plugin.key;
|
||||
@ -77,6 +110,10 @@ export default class PluginManager {
|
||||
plugin.metadata.plugin = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
add(name) {
|
||||
var position;
|
||||
var plugin;
|
||||
|
||||
@ -1,17 +1,33 @@
|
||||
import explode from "./explode-assignable-expression";
|
||||
import * as t from "../../types";
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export default function (opts) {
|
||||
var exports = {};
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
var isAssignment = function (node) {
|
||||
return node.operator === opts.operator + "=";
|
||||
};
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
var buildAssignment = function (left, right) {
|
||||
return t.assignmentExpression("=", left, right);
|
||||
};
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
exports.ExpressionStatement = function (node, parent, scope, file) {
|
||||
// hit the `AssignmentExpression` one below
|
||||
if (this.isCompletionRecord()) return;
|
||||
@ -29,6 +45,10 @@ export default function (opts) {
|
||||
return nodes;
|
||||
};
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
exports.AssignmentExpression = function (node, parent, scope, file) {
|
||||
if (!isAssignment(node)) return;
|
||||
|
||||
@ -38,6 +58,10 @@ export default function (opts) {
|
||||
return nodes;
|
||||
};
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
exports.BinaryExpression = function (node) {
|
||||
if (node.operator !== opts.operator) return;
|
||||
return opts.build(node.left, node.right);
|
||||
|
||||
@ -1,5 +1,9 @@
|
||||
import * as t from "../../types";
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export default function build(node, buildBody) {
|
||||
var self = node.blocks.shift();
|
||||
if (!self) return;
|
||||
|
||||
@ -1,11 +1,24 @@
|
||||
import explode from "./explode-assignable-expression";
|
||||
import * as t from "../../types";
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export default function (exports, opts) {
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
var buildAssignment = function (left, right) {
|
||||
return t.assignmentExpression("=", left, right);
|
||||
};
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
exports.ExpressionStatement = function (node, parent, scope, file) {
|
||||
// hit the `AssignmentExpression` one below
|
||||
if (this.isCompletionRecord()) return;
|
||||
@ -25,6 +38,10 @@ export default function (exports, opts) {
|
||||
return nodes;
|
||||
};
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
exports.AssignmentExpression = function (node, parent, scope, file) {
|
||||
if (!opts.is(node, file)) return;
|
||||
|
||||
|
||||
@ -9,9 +9,17 @@ import esutils from "esutils";
|
||||
import * as react from "./react";
|
||||
import * as t from "../../types";
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export default function (opts) {
|
||||
var visitor = {};
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
visitor.JSXIdentifier = function (node) {
|
||||
if (node.name === "this" && this.isReferenced()) {
|
||||
return t.thisExpression();
|
||||
@ -22,10 +30,18 @@ export default function (opts) {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
visitor.JSXNamespacedName = function () {
|
||||
throw this.errorWithNode(messages.get("JSXNamespacedTags"));
|
||||
};
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
visitor.JSXMemberExpression = {
|
||||
exit(node) {
|
||||
node.computed = t.isLiteral(node.property);
|
||||
@ -33,10 +49,18 @@ export default function (opts) {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
visitor.JSXExpressionContainer = function (node) {
|
||||
return node.expression;
|
||||
};
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
visitor.JSXAttribute = {
|
||||
enter(node) {
|
||||
var value = node.value;
|
||||
@ -51,6 +75,10 @@ export default function (opts) {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
visitor.JSXOpeningElement = {
|
||||
exit(node, parent, scope, file) {
|
||||
parent.children = react.buildChildren(parent);
|
||||
@ -141,6 +169,10 @@ export default function (opts) {
|
||||
return attribs;
|
||||
};
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
visitor.JSXElement = {
|
||||
exit(node) {
|
||||
var callExpr = node.openingElement;
|
||||
|
||||
@ -1,6 +1,15 @@
|
||||
import * as t from "../../types";
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
var visitor = {
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
enter(node, parent, scope, state) {
|
||||
if (this.isThisExpression() || this.isReferencedIdentifier({ name: "arguments" })) {
|
||||
state.found = true;
|
||||
@ -8,11 +17,19 @@ var visitor = {
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
Function() {
|
||||
this.skip();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export default function (node, scope) {
|
||||
var container = t.functionExpression(null, [], node.body, node.generator, node.async);
|
||||
|
||||
|
||||
@ -2,6 +2,10 @@ import each from "lodash/collection/each";
|
||||
import has from "lodash/object/has";
|
||||
import * as t from "../../types";
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function push(mutatorMap, node, kind, file) {
|
||||
var alias = t.toKeyAlias(node);
|
||||
|
||||
@ -43,6 +47,10 @@ export function push(mutatorMap, node, kind, file) {
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function hasComputed(mutatorMap) {
|
||||
for (var key in mutatorMap) {
|
||||
if (mutatorMap[key]._computed) {
|
||||
@ -52,6 +60,10 @@ export function hasComputed(mutatorMap) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function toComputedObjectFromClass(obj) {
|
||||
var objExpr = t.arrayExpression([]);
|
||||
|
||||
@ -65,6 +77,10 @@ export function toComputedObjectFromClass(obj) {
|
||||
return objExpr;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function toClassObject(mutatorMap) {
|
||||
var objExpr = t.objectExpression([]);
|
||||
|
||||
@ -92,6 +108,10 @@ export function toClassObject(mutatorMap) {
|
||||
return objExpr;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function toDefineObject(mutatorMap) {
|
||||
each(mutatorMap, function (map) {
|
||||
if (map.value) map.writable = t.literal(true);
|
||||
|
||||
@ -1,5 +1,9 @@
|
||||
import * as t from "../../types";
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
var getObjRef = function (node, nodes, file, scope) {
|
||||
var ref;
|
||||
if (t.isIdentifier(node)) {
|
||||
@ -33,6 +37,10 @@ var getObjRef = function (node, nodes, file, scope) {
|
||||
return temp;
|
||||
};
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
var getPropRef = function (node, nodes, file, scope) {
|
||||
var prop = node.property;
|
||||
var key = t.toComputedKey(node, prop);
|
||||
@ -45,6 +53,10 @@ var getPropRef = function (node, nodes, file, scope) {
|
||||
return temp;
|
||||
};
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export default function (node, nodes, file, scope, allowedSingleIdent) {
|
||||
var obj;
|
||||
if (t.isIdentifier(node) && allowedSingleIdent) {
|
||||
|
||||
@ -1,5 +1,9 @@
|
||||
import * as t from "../../types";
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export default function (node) {
|
||||
var lastNonDefault = 0;
|
||||
for (var i = 0; i < node.params.length; i++) {
|
||||
|
||||
@ -1,5 +1,9 @@
|
||||
import * as t from "../../types";
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export default function (decorators, scope) {
|
||||
for (var i = 0; i < decorators.length; i++) {
|
||||
var decorator = decorators[i];
|
||||
|
||||
@ -2,6 +2,10 @@ import getFunctionArity from "./get-function-arity";
|
||||
import * as util from "../../util";
|
||||
import * as t from "../../types";
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
function visitIdentifier(context, node, scope, state) {
|
||||
// check if this node matches our function id
|
||||
if (node.name !== state.name) return;
|
||||
@ -15,16 +19,33 @@ function visitIdentifier(context, node, scope, state) {
|
||||
context.stop();
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
var visitor = {
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
ReferencedIdentifier(node, parent, scope, state) {
|
||||
visitIdentifier(this, node, scope, state);
|
||||
},
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
BindingIdentifier(node, parent, scope, state) {
|
||||
visitIdentifier(this, node, scope, state);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
var wrap = function (state, method, id, scope) {
|
||||
if (state.selfReference) {
|
||||
if (scope.hasBinding(id.name) && !scope.hasGlobal(id.name)) {
|
||||
@ -56,6 +77,10 @@ var wrap = function (state, method, id, scope) {
|
||||
scope.getProgramParent().references[id.name] = true;
|
||||
};
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
var visit = function (node, name, scope) {
|
||||
var state = {
|
||||
selfAssignment: false,
|
||||
@ -102,11 +127,19 @@ var visit = function (node, name, scope) {
|
||||
return state;
|
||||
};
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function custom(node, id, scope) {
|
||||
var state = visit(node, id.name, scope);
|
||||
return wrap(state, node, id, scope);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function property(node, file, scope) {
|
||||
var key = t.toComputedKey(node, node.key);
|
||||
if (!t.isLiteral(key)) return; // we can't set a function id with this
|
||||
@ -119,6 +152,10 @@ export function property(node, file, scope) {
|
||||
node.value = wrap(state, method, id, scope) || method;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function bare(node, parent, scope) {
|
||||
// has an `id` so we don't need to infer one
|
||||
if (node.id) return;
|
||||
|
||||
12
src/babel/transformation/helpers/react.js
vendored
12
src/babel/transformation/helpers/react.js
vendored
@ -2,10 +2,18 @@ import * as t from "../../types";
|
||||
|
||||
export var isReactComponent = t.buildMatchMemberExpression("React.Component");
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function isCompatTag(tagName) {
|
||||
return tagName && /^[a-z]|\-/.test(tagName);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
function cleanJSXElementLiteralChild(child, args) {
|
||||
var lines = child.value.split(/\r\n|\n|\r/);
|
||||
|
||||
@ -51,6 +59,10 @@ function cleanJSXElementLiteralChild(child, args) {
|
||||
if (str) args.push(t.literal(str));
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function buildChildren(node) {
|
||||
var elems = [];
|
||||
|
||||
|
||||
@ -1,10 +1,18 @@
|
||||
import pull from "lodash/array/pull";
|
||||
import * as t from "../../types";
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function is(node, flag) {
|
||||
return t.isLiteral(node) && node.regex && node.regex.flags.indexOf(flag) >= 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function pullFlag(node, flag) {
|
||||
var flags = node.regex.flags.split("");
|
||||
if (node.regex.flags.indexOf(flag) < 0) return;
|
||||
|
||||
@ -1,10 +1,23 @@
|
||||
import * as t from "../../types";
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
var awaitVisitor = {
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
Function() {
|
||||
this.skip();
|
||||
},
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
AwaitExpression(node) {
|
||||
node.type = "YieldExpression";
|
||||
|
||||
@ -16,7 +29,16 @@ var awaitVisitor = {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
var referenceVisitor = {
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
ReferencedIdentifier(node, parent, scope, state) {
|
||||
var name = state.id.name;
|
||||
if (node.name === name && scope.bindingIdentifierEquals(name, state.id)) {
|
||||
@ -25,6 +47,10 @@ var referenceVisitor = {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export default function (path, callId) {
|
||||
var node = path.node;
|
||||
|
||||
|
||||
@ -2,6 +2,10 @@ import type NodePath from "../../traversal/path";
|
||||
import * as messages from "../../messages";
|
||||
import * as t from "../../types";
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
function isIllegalBareSuper(node, parent) {
|
||||
if (!t.isSuper(node)) return false;
|
||||
if (t.isMemberExpression(parent, { computed: false })) return false;
|
||||
@ -9,11 +13,24 @@ function isIllegalBareSuper(node, parent) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
function isMemberExpressionSuper(node) {
|
||||
return t.isMemberExpression(node) && t.isSuper(node.object);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
var visitor = {
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
enter(node, parent, scope, state) {
|
||||
var topLevel = state.topLevel;
|
||||
var self = state.self;
|
||||
@ -44,12 +61,11 @@ var visitor = {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export default class ReplaceSupers {
|
||||
|
||||
/**
|
||||
* Description
|
||||
*/
|
||||
|
||||
constructor(opts: Object, inClass?: boolean = false) {
|
||||
this.topLevelThisReference = opts.topLevelThisReference;
|
||||
this.methodPath = opts.methodPath;
|
||||
@ -64,6 +80,10 @@ export default class ReplaceSupers {
|
||||
this.opts = opts;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
getObjectRef() {
|
||||
return this.opts.objectRef || this.opts.getObjectRef();
|
||||
}
|
||||
@ -120,7 +140,7 @@ export default class ReplaceSupers {
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
replace() {
|
||||
@ -128,7 +148,7 @@ export default class ReplaceSupers {
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
traverseLevel(path: NodePath, topLevel: boolean) {
|
||||
@ -137,7 +157,7 @@ export default class ReplaceSupers {
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
getThisReference() {
|
||||
@ -153,7 +173,7 @@ export default class ReplaceSupers {
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
getLooseSuperProperty(id: Object, parent: Object) {
|
||||
@ -196,7 +216,7 @@ export default class ReplaceSupers {
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
looseHandle(path: NodePath, getThisReference: Function) {
|
||||
@ -216,7 +236,7 @@ export default class ReplaceSupers {
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
specHandleAssignmentExpression(ref, path, node, getThisReference) {
|
||||
@ -238,7 +258,7 @@ export default class ReplaceSupers {
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
specHandle(path: NodePath, getThisReference: Function) {
|
||||
|
||||
@ -1,8 +1,14 @@
|
||||
import Pipeline from "./pipeline";
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
var pipeline = new Pipeline;
|
||||
|
||||
//
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
import transformers from "./transformers";
|
||||
|
||||
@ -17,17 +23,23 @@ for (var key in transformers) {
|
||||
|
||||
pipeline.addTransformers(transformers);
|
||||
|
||||
//
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
import deprecated from "./transformers/deprecated";
|
||||
pipeline.addDeprecated(deprecated);
|
||||
|
||||
//
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
import aliases from "./transformers/aliases";
|
||||
pipeline.addAliases(aliases);
|
||||
|
||||
//
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
import * as filters from "./transformers/filters";
|
||||
pipeline.addFilter(filters.internal);
|
||||
@ -36,7 +48,9 @@ pipeline.addFilter(filters.whitelist);
|
||||
pipeline.addFilter(filters.stage);
|
||||
pipeline.addFilter(filters.optional);
|
||||
|
||||
//
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
var transform = pipeline.transform.bind(pipeline);
|
||||
transform.fromAst = pipeline.transformFromAst.bind(pipeline);
|
||||
|
||||
@ -5,7 +5,16 @@ import object from "../../helpers/object";
|
||||
import * as util from "../../util";
|
||||
import * as t from "../../types";
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
var metadataVisitor = {
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
ModuleDeclaration: {
|
||||
enter(node, parent, scope, formatter) {
|
||||
if (node.source) {
|
||||
@ -15,6 +24,10 @@ var metadataVisitor = {
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
ImportDeclaration: {
|
||||
exit(node, parent, scope, formatter) {
|
||||
formatter.hasLocalImports = true;
|
||||
@ -63,6 +76,10 @@ var metadataVisitor = {
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
ExportDeclaration(node, parent, scope, formatter) {
|
||||
formatter.hasLocalExports = true;
|
||||
|
||||
@ -156,6 +173,10 @@ var metadataVisitor = {
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
Scope(node, parent, scope, formatter) {
|
||||
if (!formatter.isLoose()) {
|
||||
this.skip();
|
||||
@ -163,6 +184,10 @@ var metadataVisitor = {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export default class DefaultFormatter {
|
||||
constructor(file) {
|
||||
// object containg all module sources with the scope that they're contained in
|
||||
@ -190,6 +215,10 @@ export default class DefaultFormatter {
|
||||
this.getMetadata();
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
addScope(path) {
|
||||
var source = path.node.source && path.node.source.value;
|
||||
if (!source) return;
|
||||
@ -202,19 +231,35 @@ export default class DefaultFormatter {
|
||||
this.sourceScopes[source] = path.scope;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
isModuleType(node, type) {
|
||||
var modules = this.file.dynamicImportTypes[type];
|
||||
return modules && modules.indexOf(node) >= 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
transform() {
|
||||
this.remapAssignments();
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
doDefaultExportInterop(node) {
|
||||
return (t.isExportDefaultDeclaration(node) || t.isSpecifierDefault(node)) && !this.noInteropRequireExport && !this.hasNonDefaultExports;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
getMetadata() {
|
||||
var has = false;
|
||||
for (var node of (this.file.ast.program.body: Array)) {
|
||||
@ -228,12 +273,20 @@ export default class DefaultFormatter {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
remapAssignments() {
|
||||
if (this.hasLocalExports || this.hasLocalImports) {
|
||||
this.remaps.run();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
remapExportAssignment(node, exported) {
|
||||
var assign = node;
|
||||
|
||||
@ -248,6 +301,10 @@ export default class DefaultFormatter {
|
||||
return assign;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
_addExport(name, exported) {
|
||||
var info = this.localExports[name] = this.localExports[name] || {
|
||||
binding: this.scope.getBindingIdentifier(name),
|
||||
@ -256,6 +313,10 @@ export default class DefaultFormatter {
|
||||
info.exported.push(exported);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
getExport(node, scope) {
|
||||
if (!t.isIdentifier(node)) return;
|
||||
|
||||
@ -265,6 +326,10 @@ export default class DefaultFormatter {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
getModuleName() {
|
||||
var opts = this.file.opts;
|
||||
// moduleId is n/a if a `getModuleId()` is provided
|
||||
@ -307,6 +372,10 @@ export default class DefaultFormatter {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
_pushStatement(ref, nodes) {
|
||||
if (t.isClass(ref) || t.isFunction(ref)) {
|
||||
if (ref.id) {
|
||||
@ -318,6 +387,10 @@ export default class DefaultFormatter {
|
||||
return ref;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
_hoistExport(declar, assign, priority) {
|
||||
if (t.isFunctionDeclaration(declar)) {
|
||||
assign._blockHoist = priority || 2;
|
||||
@ -326,6 +399,10 @@ export default class DefaultFormatter {
|
||||
return assign;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
getExternalReference(node, nodes) {
|
||||
var ids = this.ids;
|
||||
var id = node.source.value;
|
||||
@ -337,21 +414,37 @@ export default class DefaultFormatter {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
checkExportIdentifier(node) {
|
||||
if (t.isIdentifier(node, { name: "__esModule" })) {
|
||||
throw this.file.errorWithNode(node, messages.get("modulesIllegalExportName", node.name));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
exportAllDeclaration(node, nodes) {
|
||||
var ref = this.getExternalReference(node, nodes);
|
||||
nodes.push(this.buildExportsWildcard(ref, node));
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
isLoose() {
|
||||
return this.file.isLoose("es6.modules");
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
exportSpecifier(specifier, node, nodes) {
|
||||
if (node.source) {
|
||||
var ref = this.getExternalReference(node, nodes);
|
||||
@ -376,6 +469,10 @@ export default class DefaultFormatter {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
buildExportsWildcard(objectIdentifier) {
|
||||
return t.expressionStatement(t.callExpression(this.file.addHelper("defaults"), [
|
||||
t.identifier("exports"),
|
||||
@ -383,6 +480,10 @@ export default class DefaultFormatter {
|
||||
]));
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
buildExportsFromAssignment(id, init) {
|
||||
this.checkExportIdentifier(id);
|
||||
return util.template("exports-from-assign", {
|
||||
@ -391,6 +492,10 @@ export default class DefaultFormatter {
|
||||
}, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
buildExportsAssignment(id, init) {
|
||||
this.checkExportIdentifier(id);
|
||||
return util.template("exports-assign", {
|
||||
@ -399,6 +504,10 @@ export default class DefaultFormatter {
|
||||
}, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
exportDeclaration(node, nodes) {
|
||||
var declar = node.declaration;
|
||||
|
||||
|
||||
@ -1,5 +1,9 @@
|
||||
import * as util from "../../util";
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export default function (Parent) {
|
||||
var Constructor = function () {
|
||||
this.noInteropRequireImport = true;
|
||||
|
||||
@ -1,3 +1,8 @@
|
||||
import AMDFormatter from "./amd";
|
||||
import buildStrict from "./_strict";
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export default buildStrict(AMDFormatter);
|
||||
|
||||
@ -5,11 +5,24 @@ import values from "lodash/object/values";
|
||||
import * as util from "../../util";
|
||||
import * as t from "../../types";
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export default class AMDFormatter extends DefaultFormatter {
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
setup() {
|
||||
CommonFormatter.prototype._setup.call(this, this.hasNonDefaultExports);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
buildDependencyLiterals() {
|
||||
var names = [];
|
||||
for (var name in this.ids) {
|
||||
@ -64,14 +77,26 @@ export default class AMDFormatter extends DefaultFormatter {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
_getExternalReference(node) {
|
||||
return this.scope.generateUidIdentifier(node.source.value);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
importDeclaration(node) {
|
||||
this.getExternalReference(node);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
importSpecifier(specifier, node, nodes, scope) {
|
||||
var key = node.source.value;
|
||||
var ref = this.getExternalReference(node);
|
||||
@ -105,6 +130,10 @@ export default class AMDFormatter extends DefaultFormatter {
|
||||
this.remaps.add(scope, specifier.local.name, ref);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
exportSpecifier(specifier, node, nodes) {
|
||||
if (this.doDefaultExportInterop(specifier)) {
|
||||
this.passModuleArg = true;
|
||||
@ -120,6 +149,10 @@ export default class AMDFormatter extends DefaultFormatter {
|
||||
CommonFormatter.prototype.exportSpecifier.apply(this, arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
exportDeclaration(node, nodes) {
|
||||
if (this.doDefaultExportInterop(node)) {
|
||||
this.passModuleArg = true;
|
||||
|
||||
@ -1,3 +1,8 @@
|
||||
import CommonFormatter from "./common";
|
||||
import buildStrict from "./_strict";
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export default buildStrict(CommonFormatter);
|
||||
|
||||
@ -2,11 +2,24 @@ import DefaultFormatter from "./_default";
|
||||
import * as util from "../../util";
|
||||
import * as t from "../../types";
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export default class CommonJSFormatter extends DefaultFormatter {
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
setup() {
|
||||
this._setup(this.hasLocalExports);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
_setup(conditional) {
|
||||
var file = this.file;
|
||||
var scope = file.scope;
|
||||
@ -23,6 +36,10 @@ export default class CommonJSFormatter extends DefaultFormatter {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
transform(program) {
|
||||
DefaultFormatter.prototype.transform.apply(this, arguments);
|
||||
|
||||
@ -37,6 +54,10 @@ export default class CommonJSFormatter extends DefaultFormatter {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
importSpecifier(specifier, node, nodes, scope) {
|
||||
var variableName = specifier.local;
|
||||
|
||||
@ -76,6 +97,10 @@ export default class CommonJSFormatter extends DefaultFormatter {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
importDeclaration(node, nodes) {
|
||||
// import "foo";
|
||||
nodes.push(util.template("require", {
|
||||
@ -83,6 +108,10 @@ export default class CommonJSFormatter extends DefaultFormatter {
|
||||
}, true));
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
exportSpecifier(specifier) {
|
||||
if (this.doDefaultExportInterop(specifier)) {
|
||||
this.hasDefaultOnlyExport = true;
|
||||
@ -91,6 +120,10 @@ export default class CommonJSFormatter extends DefaultFormatter {
|
||||
DefaultFormatter.prototype.exportSpecifier.apply(this, arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
exportDeclaration(node) {
|
||||
if (this.doDefaultExportInterop(node)) {
|
||||
this.hasDefaultOnlyExport = true;
|
||||
@ -99,6 +132,10 @@ export default class CommonJSFormatter extends DefaultFormatter {
|
||||
DefaultFormatter.prototype.exportDeclaration.apply(this, arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
_getExternalReference(node, nodes) {
|
||||
var call = t.callExpression(t.identifier("require"), [node.source]);
|
||||
var uid;
|
||||
|
||||
@ -1,12 +1,25 @@
|
||||
import DefaultFormatter from "./_default";
|
||||
import * as t from "../../types";
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export default class IgnoreFormatter extends DefaultFormatter {
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
exportDeclaration(node, nodes) {
|
||||
var declar = t.toStatement(node.declaration, true);
|
||||
if (declar) nodes.push(t.inherits(declar, node));
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
exportAllDeclaration() {}
|
||||
importDeclaration() {}
|
||||
importSpecifier() {}
|
||||
|
||||
@ -1,3 +1,7 @@
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export default {
|
||||
commonStrict: require("./common-strict"),
|
||||
amdStrict: require("./amd-strict"),
|
||||
|
||||
@ -1,12 +1,25 @@
|
||||
import * as t from "../../../types";
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
var remapVisitor = {
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
enter(node) {
|
||||
if (node._skipModulesRemap) {
|
||||
return this.skip();
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
ReferencedIdentifier(node, parent, scope, remaps) {
|
||||
var { formatter } = remaps;
|
||||
|
||||
@ -23,6 +36,10 @@ var remapVisitor = {
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
AssignmentExpression: {
|
||||
exit(node, parent, scope, { formatter }) {
|
||||
if (!node._ignoreModulesRemap) {
|
||||
@ -34,6 +51,10 @@ var remapVisitor = {
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
UpdateExpression(node, parent, scope, { formatter }) {
|
||||
var exported = formatter.getExport(node.argument, scope);
|
||||
if (!exported) return;
|
||||
@ -65,24 +86,45 @@ var remapVisitor = {
|
||||
return t.sequenceExpression(nodes);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export default class Remaps {
|
||||
constructor(file, formatter) {
|
||||
this.formatter = formatter;
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
run() {
|
||||
this.file.path.traverse(remapVisitor, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
_getKey(name) {
|
||||
return `${name}:moduleRemap`;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
get(scope, name) {
|
||||
return scope.getData(this._getKey(name));
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
add(scope, name, val) {
|
||||
if (this.all) {
|
||||
this.all.push({
|
||||
@ -95,6 +137,10 @@ export default class Remaps {
|
||||
return scope.setData(this._getKey(name), val);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
remove(scope, name) {
|
||||
return scope.removeData(this._getKey(name));
|
||||
}
|
||||
@ -109,6 +155,10 @@ export default class Remaps {
|
||||
return this.all;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
clearAll() {
|
||||
if (this.all) {
|
||||
for (var remap of (this.all: Array)) {
|
||||
|
||||
@ -5,12 +5,25 @@ import last from "lodash/array/last";
|
||||
import map from "lodash/collection/map";
|
||||
import * as t from "../../types";
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
var hoistVariablesVisitor = {
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
Function() {
|
||||
// nothing inside is accessible
|
||||
this.skip();
|
||||
},
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
VariableDeclaration(node, parent, scope, state) {
|
||||
if (node.kind !== "var" && !t.isProgram(parent)) { // let, const
|
||||
// can't be accessed
|
||||
@ -41,11 +54,24 @@ var hoistVariablesVisitor = {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
var hoistFunctionsVisitor = {
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
Function() {
|
||||
this.skip();
|
||||
},
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
enter(node, parent, scope, state) {
|
||||
if (t.isFunctionDeclaration(node) || state.formatter._canHoist(node)) {
|
||||
state.handlerBody.push(node);
|
||||
@ -54,7 +80,16 @@ var hoistFunctionsVisitor = {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
var runnerSettersVisitor = {
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
enter(node, parent, scope, state) {
|
||||
if (node._importSource === state.source) {
|
||||
if (t.isVariableDeclaration(node)) {
|
||||
@ -73,6 +108,10 @@ var runnerSettersVisitor = {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export default class SystemFormatter extends AMDFormatter {
|
||||
constructor(file) {
|
||||
super(file);
|
||||
@ -85,11 +124,19 @@ export default class SystemFormatter extends AMDFormatter {
|
||||
this.remaps.clearAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
_addImportSource(node, exportNode) {
|
||||
if (node) node._importSource = exportNode.source && exportNode.source.value;
|
||||
return node;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
buildExportsWildcard(objectIdentifier, node) {
|
||||
var leftIdentifier = this.scope.generateUidIdentifier("key");
|
||||
var valIdentifier = t.memberExpression(objectIdentifier, leftIdentifier, true);
|
||||
@ -107,15 +154,27 @@ export default class SystemFormatter extends AMDFormatter {
|
||||
return this._addImportSource(t.forInStatement(left, right, block), node);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
buildExportsAssignment(id, init, node) {
|
||||
var call = this._buildExportCall(t.literal(id.name), init, true);
|
||||
return this._addImportSource(call, node);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
buildExportsFromAssignment() {
|
||||
return this.buildExportsAssignment(...arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
remapExportAssignment(node, exported) {
|
||||
var assign = node;
|
||||
|
||||
@ -126,6 +185,10 @@ export default class SystemFormatter extends AMDFormatter {
|
||||
return assign;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
_buildExportCall(id, init, isStatement) {
|
||||
var call = t.callExpression(this.exportIdentifier, [id, init]);
|
||||
if (isStatement) {
|
||||
@ -135,6 +198,10 @@ export default class SystemFormatter extends AMDFormatter {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
importSpecifier(specifier, node, nodes) {
|
||||
AMDFormatter.prototype.importSpecifier.apply(this, arguments);
|
||||
|
||||
@ -149,6 +216,10 @@ export default class SystemFormatter extends AMDFormatter {
|
||||
this._addImportSource(last(nodes), node);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
_buildRunnerSetters(block, hoistDeclarators) {
|
||||
var scope = this.file.scope;
|
||||
|
||||
@ -165,10 +236,18 @@ export default class SystemFormatter extends AMDFormatter {
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
_canHoist(node) {
|
||||
return node._blockHoist && !this.file.dynamicImports.length;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
transform(program) {
|
||||
DefaultFormatter.prototype.transform.apply(this, arguments);
|
||||
|
||||
|
||||
@ -1,3 +1,8 @@
|
||||
import UMDFormatter from "./umd";
|
||||
import buildStrict from "./_strict";
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export default buildStrict(UMDFormatter);
|
||||
|
||||
@ -5,7 +5,16 @@ import path from "path";
|
||||
import * as util from "../../util";
|
||||
import * as t from "../../types";
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export default class UMDFormatter extends AMDFormatter {
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
transform(program) {
|
||||
DefaultFormatter.prototype.transform.apply(this, arguments);
|
||||
|
||||
|
||||
@ -5,6 +5,10 @@ import assign from "lodash/object/assign";
|
||||
import object from "../helpers/object";
|
||||
import File from "./file";
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export default class Pipeline {
|
||||
constructor() {
|
||||
this.transformers = object();
|
||||
@ -14,6 +18,10 @@ export default class Pipeline {
|
||||
this.filters = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
addTransformers(transformers) {
|
||||
for (var key in transformers) {
|
||||
this.addTransformer(key, transformers[key]);
|
||||
@ -21,6 +29,10 @@ export default class Pipeline {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
addTransformer(key, plugin) {
|
||||
if (this.transformers[key]) throw new Error(); // todo: error
|
||||
|
||||
@ -44,21 +56,37 @@ export default class Pipeline {
|
||||
this.transformers[key] = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
addAliases(names) {
|
||||
assign(this.aliases, names);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
addDeprecated(names) {
|
||||
assign(this.deprecated, names);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
addFilter(filter: Function) {
|
||||
this.filters.push(filter);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
canTransform(plugin, fileOpts) {
|
||||
if (plugin.metadata.plugin) {
|
||||
return true;
|
||||
@ -72,11 +100,19 @@ export default class Pipeline {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
analyze(code: string, opts?: Object = {}) {
|
||||
opts.code = false;
|
||||
return this.transform(code, opts);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
pretransform(code: string, opts?: Object) {
|
||||
var file = new File(opts, this);
|
||||
return file.wrap(code, function () {
|
||||
@ -86,6 +122,10 @@ export default class Pipeline {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
transform(code: string, opts?: Object) {
|
||||
var file = new File(opts, this);
|
||||
return file.wrap(code, function () {
|
||||
@ -95,6 +135,10 @@ export default class Pipeline {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
transformFromAst(ast, code, opts) {
|
||||
ast = normalizeAst(ast);
|
||||
|
||||
@ -106,6 +150,10 @@ export default class Pipeline {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
_ensureTransformerNames(type: string, rawKeys: Array<string>) {
|
||||
var keys = [];
|
||||
|
||||
|
||||
@ -20,11 +20,19 @@ export default class PluginPass {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
canTransform(): boolean {
|
||||
return this.file.transformerDependencies[this.key] ||
|
||||
this.file.pipeline.canTransform(this.plugin, this.file.opts);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
transform() {
|
||||
var file = this.file;
|
||||
file.log.debug(`Start transformer ${this.key}`);
|
||||
|
||||
@ -21,6 +21,10 @@ const VALID_METADATA_PROPERTES = [
|
||||
"secondPass"
|
||||
];
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export default class Plugin {
|
||||
constructor(key: string, plugin: Object) {
|
||||
Plugin.validate(key, plugin);
|
||||
@ -51,6 +55,10 @@ export default class Plugin {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
static validate(name, plugin) {
|
||||
for (let key in plugin) {
|
||||
if (key[0] === "_") continue;
|
||||
@ -68,11 +76,19 @@ export default class Plugin {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
normalize(visitor: Object): Object {
|
||||
traverse.explode(visitor);
|
||||
return visitor;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
buildPass(file: File): PluginPass {
|
||||
// validate Transformer instance
|
||||
if (!(file instanceof File)) {
|
||||
|
||||
@ -1,5 +1,9 @@
|
||||
import Plugin from "./plugin";
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export default class Transformer {
|
||||
constructor(key, obj) {
|
||||
var plugin = {};
|
||||
|
||||
@ -4,7 +4,16 @@ export var metadata = {
|
||||
group: "builtin-trailing"
|
||||
};
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export var visitor = {
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
MemberExpression: {
|
||||
exit(node) {
|
||||
var prop = node.property;
|
||||
|
||||
@ -4,7 +4,16 @@ export var metadata = {
|
||||
group: "builtin-trailing"
|
||||
};
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export var visitor = {
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
Property: {
|
||||
exit(node) {
|
||||
var key = node.key;
|
||||
|
||||
@ -1,7 +1,16 @@
|
||||
import * as defineMap from "../../helpers/define-map";
|
||||
import * as t from "../../../types";
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export var visitor = {
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
ObjectExpression(node, parent, scope, file) {
|
||||
var hasAny = false;
|
||||
for (var prop of (node.properties: Array)) {
|
||||
|
||||
@ -1,4 +1,13 @@
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export var visitor = {
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
ArrowFunctionExpression(node) {
|
||||
this.ensureBlock();
|
||||
node.expression = false;
|
||||
|
||||
@ -8,6 +8,10 @@ import * as t from "../../../types";
|
||||
import values from "lodash/object/values";
|
||||
import extend from "lodash/object/extend";
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
function isLet(node, parent) {
|
||||
if (!t.isVariableDeclaration(node)) return false;
|
||||
if (node._let) return true;
|
||||
@ -26,14 +30,26 @@ function isLet(node, parent) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
function isLetInitable(node, parent) {
|
||||
return !t.isFor(parent) || !t.isFor(parent, { left: node });
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
function isVar(node, parent) {
|
||||
return t.isVariableDeclaration(node, { kind: "var" }) && !isLet(node, parent);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
function standardizeLets(declars) {
|
||||
for (var declar of (declars: Array)) {
|
||||
delete declar._let;
|
||||
@ -44,7 +60,16 @@ export var metadata = {
|
||||
group: "builtin-advanced"
|
||||
};
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export var visitor = {
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
VariableDeclaration(node, parent, scope, file) {
|
||||
if (!isLet(node, parent)) return;
|
||||
|
||||
@ -67,6 +92,10 @@ export var visitor = {
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
Loop(node, parent, scope, file) {
|
||||
var init = node.left || node.init;
|
||||
if (isLet(init, node)) {
|
||||
@ -78,6 +107,10 @@ export var visitor = {
|
||||
return blockScoping.run();
|
||||
},
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
"BlockStatement|Program"(block, parent, scope, file) {
|
||||
if (!t.isLoop(parent)) {
|
||||
var blockScoping = new BlockScoping(null, this, parent, scope, file);
|
||||
@ -86,6 +119,10 @@ export var visitor = {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
function replace(node, parent, scope, remaps) {
|
||||
var remap = remaps[node.name];
|
||||
if (!remap) return;
|
||||
@ -100,9 +137,17 @@ function replace(node, parent, scope, remaps) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
var replaceVisitor = {
|
||||
ReferencedIdentifier: replace,
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
AssignmentExpression(node, parent, scope, remaps) {
|
||||
var ids = this.getBindingIdentifiers();
|
||||
for (var name in ids) {
|
||||
@ -111,6 +156,10 @@ var replaceVisitor = {
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
function traverseReplace(node, parent, scope, remaps) {
|
||||
if (t.isIdentifier(node)) {
|
||||
replace(node, parent, scope, remaps);
|
||||
@ -126,14 +175,32 @@ function traverseReplace(node, parent, scope, remaps) {
|
||||
scope.traverse(node, replaceVisitor, remaps);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
var letReferenceBlockVisitor = {
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
Function(node, parent, scope, state) {
|
||||
this.traverse(letReferenceFunctionVisitor, state);
|
||||
return this.skip();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
var letReferenceFunctionVisitor = {
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
ReferencedIdentifier(node, parent, scope, state) {
|
||||
var ref = state.letReferences[node.name];
|
||||
|
||||
@ -148,6 +215,10 @@ var letReferenceFunctionVisitor = {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
var hoistVarDeclarationsVisitor = {
|
||||
enter(node, parent, scope, self) {
|
||||
if (this.isForStatement()) {
|
||||
@ -172,12 +243,20 @@ var hoistVarDeclarationsVisitor = {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
var loopLabelVisitor = {
|
||||
LabeledStatement(node, parent, scope, state) {
|
||||
state.innerLabels.push(node.label.name);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
var continuationVisitor = {
|
||||
enter(node, parent, scope, state) {
|
||||
if (this.isAssignmentExpression() || this.isUpdateExpression()) {
|
||||
@ -190,6 +269,10 @@ var continuationVisitor = {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
var loopNodeTo = function (node) {
|
||||
if (t.isBreakStatement(node)) {
|
||||
return "break";
|
||||
@ -198,7 +281,16 @@ var loopNodeTo = function (node) {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
var loopVisitor = {
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
Loop(node, parent, scope, state) {
|
||||
var oldIgnoreLabeless = state.ignoreLabeless;
|
||||
state.ignoreLabeless = true;
|
||||
@ -207,10 +299,18 @@ var loopVisitor = {
|
||||
this.skip();
|
||||
},
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
Function() {
|
||||
this.skip();
|
||||
},
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
SwitchCase(node, parent, scope, state) {
|
||||
var oldInSwitchCase = state.inSwitchCase;
|
||||
state.inSwitchCase = true;
|
||||
@ -219,6 +319,10 @@ var loopVisitor = {
|
||||
this.skip();
|
||||
},
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
enter(node, parent, scope, state) {
|
||||
var replace;
|
||||
var loopText = loopNodeTo(node);
|
||||
@ -263,12 +367,11 @@ var loopVisitor = {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
class BlockScoping {
|
||||
|
||||
/**
|
||||
* Description
|
||||
*/
|
||||
|
||||
constructor(loopPath?: NodePath, blockPath: NodePath, parent: Object, scope: Scope, file: File) {
|
||||
this.parent = parent;
|
||||
this.scope = scope;
|
||||
@ -319,7 +422,7 @@ class BlockScoping {
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
remap() {
|
||||
@ -366,7 +469,7 @@ class BlockScoping {
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
wrapClosure() {
|
||||
@ -486,7 +589,7 @@ class BlockScoping {
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
getLetReferences() {
|
||||
@ -599,7 +702,7 @@ class BlockScoping {
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
buildHas(ret: { type: "Identifier" }, call: { type: "CallExpression" }) {
|
||||
|
||||
@ -3,13 +3,26 @@ import VanillaTransformer from "./vanilla";
|
||||
import * as t from "../../../../types";
|
||||
import { bare } from "../../../helpers/name-method";
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export var visitor = {
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
ClassDeclaration(node) {
|
||||
return t.variableDeclaration("let", [
|
||||
t.variableDeclarator(node.id, t.toExpression(node))
|
||||
]);
|
||||
},
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
ClassExpression(node, parent, scope, file) {
|
||||
var inferred = bare(node, parent, scope);
|
||||
if (inferred) return inferred;
|
||||
|
||||
@ -1,12 +1,20 @@
|
||||
import VanillaTransformer from "./vanilla";
|
||||
import * as t from "../../../../types";
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export default class LooseClassTransformer extends VanillaTransformer {
|
||||
constructor() {
|
||||
super(...arguments);
|
||||
this.isLoose = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
_processMethod(node) {
|
||||
if (!node.decorators) {
|
||||
// use assignments instead of define properties for loose classes
|
||||
|
||||
@ -10,7 +10,16 @@ import * as t from "../../../../types";
|
||||
|
||||
const PROPERTY_COLLISION_METHOD_NAME = "__initializeProperties";
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
var collectPropertyReferencesVisitor = {
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
Identifier: {
|
||||
enter(node, parent, scope, state) {
|
||||
if (this.parentPath.isClassProperty({ key: node })) {
|
||||
@ -24,15 +33,32 @@ var collectPropertyReferencesVisitor = {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
var verifyConstructorVisitor = {
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
MethodDefinition() {
|
||||
this.skip();
|
||||
},
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
Property(node) {
|
||||
if (node.method) this.skip();
|
||||
},
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
CallExpression: {
|
||||
exit(node, parent, scope, state) {
|
||||
if (this.get("callee").isSuper()) {
|
||||
@ -46,10 +72,18 @@ var verifyConstructorVisitor = {
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
"FunctionDeclaration|FunctionExpression"() {
|
||||
this.skip();
|
||||
},
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
ThisExpression(node, parent, scope, state) {
|
||||
if (state.isDerived && !state.hasBareSuper) {
|
||||
if (this.inShadow()) {
|
||||
@ -70,6 +104,10 @@ var verifyConstructorVisitor = {
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
Super(node, parent, scope, state) {
|
||||
if (state.isDerived && !state.hasBareSuper && !this.parentPath.isCallExpression({ callee: node })) {
|
||||
throw this.errorWithNode("'super.*' is not allowed before super()");
|
||||
@ -77,12 +115,11 @@ var verifyConstructorVisitor = {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export default class ClassTransformer {
|
||||
|
||||
/**
|
||||
* Description
|
||||
*/
|
||||
|
||||
constructor(path: NodePath, file: File) {
|
||||
this.parent = path.parent;
|
||||
this.scope = path.scope;
|
||||
@ -116,8 +153,7 @@ export default class ClassTransformer {
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
* [Please add a description.]
|
||||
* @returns {Array}
|
||||
*/
|
||||
|
||||
@ -187,7 +223,7 @@ export default class ClassTransformer {
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
buildConstructor() {
|
||||
@ -195,7 +231,7 @@ export default class ClassTransformer {
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
pushToMap(node, enumerable, kind = "value") {
|
||||
@ -220,6 +256,7 @@ export default class ClassTransformer {
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
* https://www.youtube.com/watch?v=fWNaR-rxAic
|
||||
*/
|
||||
|
||||
@ -247,7 +284,7 @@ export default class ClassTransformer {
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
buildBody() {
|
||||
@ -266,7 +303,7 @@ export default class ClassTransformer {
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
pushBody() {
|
||||
@ -308,7 +345,7 @@ export default class ClassTransformer {
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
clearDescriptors() {
|
||||
@ -320,7 +357,7 @@ export default class ClassTransformer {
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
pushDescriptors() {
|
||||
@ -379,7 +416,7 @@ export default class ClassTransformer {
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
buildObjectAssignment(id) {
|
||||
@ -389,7 +426,7 @@ export default class ClassTransformer {
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
placePropertyInitializers() {
|
||||
@ -422,7 +459,7 @@ export default class ClassTransformer {
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
hasPropertyCollision(): boolean {
|
||||
@ -438,7 +475,7 @@ export default class ClassTransformer {
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
verifyConstructor(path: NodePath) {
|
||||
@ -483,12 +520,16 @@ export default class ClassTransformer {
|
||||
this.pushToMap(node);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
_processMethod() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
pushProperty(node: { type: "ClassProperty" }, path: NodePath) {
|
||||
@ -571,6 +612,10 @@ export default class ClassTransformer {
|
||||
this._pushConstructor();
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
_pushConstructor() {
|
||||
if (this.pushedConstructor) return;
|
||||
this.pushedConstructor = true;
|
||||
|
||||
@ -1,6 +1,15 @@
|
||||
import * as messages from "../../../messages";
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export var visitor = {
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
Scope(node, parent, scope) {
|
||||
for (var name in scope.bindings) {
|
||||
var binding = scope.bindings[name];
|
||||
@ -14,6 +23,10 @@ export var visitor = {
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
VariableDeclaration(node) {
|
||||
if (node.kind === "const") node.kind = "let";
|
||||
}
|
||||
|
||||
@ -5,7 +5,16 @@ export var metadata = {
|
||||
group: "builtin-advanced"
|
||||
};
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export var visitor = {
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
ForXStatement(node, parent, scope, file) {
|
||||
var left = node.left;
|
||||
|
||||
@ -54,6 +63,10 @@ export var visitor = {
|
||||
block.body = nodes.concat(block.body);
|
||||
},
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
Function(node, parent, scope, file) {
|
||||
var hasDestructuring = false;
|
||||
for (let pattern of (node.params: Array)) {
|
||||
@ -98,6 +111,10 @@ export var visitor = {
|
||||
block.body = nodes.concat(block.body);
|
||||
},
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
CatchClause(node, parent, scope, file) {
|
||||
var pattern = node.param;
|
||||
if (!t.isPattern(pattern)) return;
|
||||
@ -118,6 +135,10 @@ export var visitor = {
|
||||
node.body.body = nodes.concat(node.body.body);
|
||||
},
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
AssignmentExpression(node, parent, scope, file) {
|
||||
if (!t.isPattern(node.left)) return;
|
||||
|
||||
@ -152,6 +173,10 @@ export var visitor = {
|
||||
return nodes;
|
||||
},
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
VariableDeclaration(node, parent, scope, file) {
|
||||
if (t.isForXStatement(parent)) return;
|
||||
if (!variableDeclarationHasPattern(node)) return;
|
||||
@ -209,6 +234,10 @@ export var visitor = {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
function variableDeclarationHasPattern(node) {
|
||||
for (var i = 0; i < node.declarations.length; i++) {
|
||||
if (t.isPattern(node.declarations[i].id)) {
|
||||
@ -218,6 +247,10 @@ function variableDeclarationHasPattern(node) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
function hasRest(pattern) {
|
||||
for (var i = 0; i < pattern.elements.length; i++) {
|
||||
if (t.isRestElement(pattern.elements[i])) {
|
||||
@ -227,7 +260,16 @@ function hasRest(pattern) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
var arrayUnpackVisitor = {
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
ReferencedIdentifier(node, parent, scope, state) {
|
||||
if (state.bindings[node.name]) {
|
||||
state.deopt = true;
|
||||
@ -236,6 +278,10 @@ var arrayUnpackVisitor = {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
class DestructuringTransformer {
|
||||
constructor(opts) {
|
||||
this.blockHoist = opts.blockHoist;
|
||||
@ -247,6 +293,10 @@ class DestructuringTransformer {
|
||||
this.kind = opts.kind;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
buildVariableAssignment(id, init) {
|
||||
var op = this.operator;
|
||||
if (t.isMemberExpression(id)) op = "=";
|
||||
@ -266,6 +316,10 @@ class DestructuringTransformer {
|
||||
return node;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
buildVariableDeclaration(id, init) {
|
||||
var declar = t.variableDeclaration("var", [
|
||||
t.variableDeclarator(id, init)
|
||||
@ -274,6 +328,10 @@ class DestructuringTransformer {
|
||||
return declar;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
push(id, init) {
|
||||
if (t.isObjectPattern(id)) {
|
||||
this.pushObjectPattern(id, init);
|
||||
@ -286,6 +344,10 @@ class DestructuringTransformer {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
toArray(node, count) {
|
||||
if (this.file.isLoose("es6.destructuring") || (t.isIdentifier(node) && this.arrays[node.name])) {
|
||||
return node;
|
||||
@ -294,6 +356,10 @@ class DestructuringTransformer {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
pushAssignmentPattern(pattern, valueRef) {
|
||||
// we need to assign the current value of the assignment to avoid evaluating
|
||||
// it more than once
|
||||
@ -328,6 +394,10 @@ class DestructuringTransformer {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
pushObjectSpread(pattern, objRef, spreadProp, spreadPropIndex) {
|
||||
// get all the keys that appear in this object before the current spread
|
||||
|
||||
@ -356,6 +426,10 @@ class DestructuringTransformer {
|
||||
this.nodes.push(this.buildVariableAssignment(spreadProp.argument, value));
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
pushObjectProperty(prop, propRef) {
|
||||
if (t.isLiteral(prop.key)) prop.computed = true;
|
||||
|
||||
@ -369,6 +443,10 @@ class DestructuringTransformer {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
pushObjectPattern(pattern, objRef) {
|
||||
// https://github.com/babel/babel/issues/681
|
||||
|
||||
@ -400,6 +478,10 @@ class DestructuringTransformer {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
canUnpackArrayPattern(pattern, arr) {
|
||||
// not an array so there's no way we can deal with this
|
||||
if (!t.isArrayExpression(arr)) return false;
|
||||
@ -426,6 +508,10 @@ class DestructuringTransformer {
|
||||
return !state.deopt;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
pushUnpackedArrayPattern(pattern, arr) {
|
||||
for (var i = 0; i < pattern.elements.length; i++) {
|
||||
var elem = pattern.elements[i];
|
||||
@ -437,6 +523,10 @@ class DestructuringTransformer {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
pushArrayPattern(pattern, arrayRef) {
|
||||
if (!pattern.elements) return;
|
||||
|
||||
@ -500,6 +590,10 @@ class DestructuringTransformer {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
init(pattern, ref) {
|
||||
// trying to destructure a value that we can't evaluate more than once so we
|
||||
// need to save it to a variable
|
||||
|
||||
@ -2,7 +2,16 @@ import * as messages from "../../../messages";
|
||||
import * as util from "../../../util";
|
||||
import * as t from "../../../types";
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export var visitor = {
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
ForOfStatement(node, parent, scope, file) {
|
||||
if (this.get("right").isArrayExpression()) {
|
||||
return _ForOfStatementArray.call(this, node, scope, file);
|
||||
@ -39,6 +48,10 @@ export var visitor = {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export function _ForOfStatementArray(node, scope, file) {
|
||||
var nodes = [];
|
||||
var right = node.right;
|
||||
@ -81,6 +94,10 @@ export function _ForOfStatementArray(node, scope, file) {
|
||||
return nodes;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
var loose = function (node, parent, scope, file) {
|
||||
var left = node.left;
|
||||
var declar, id;
|
||||
@ -124,6 +141,10 @@ var loose = function (node, parent, scope, file) {
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
var spec = function (node, parent, scope, file) {
|
||||
var left = node.left;
|
||||
var declar;
|
||||
|
||||
@ -12,7 +12,16 @@ export var metadata = {
|
||||
group: "builtin-modules"
|
||||
};
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export var visitor = {
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
ImportDeclaration(node, parent, scope, file) {
|
||||
// flow type
|
||||
if (node.importKind === "type" || node.importKind === "typeof") return;
|
||||
@ -35,6 +44,10 @@ export var visitor = {
|
||||
return nodes;
|
||||
},
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
ExportAllDeclaration(node, parent, scope, file) {
|
||||
var nodes = [];
|
||||
file.moduleFormatter.exportAllDeclaration(node, nodes, scope);
|
||||
@ -42,6 +55,10 @@ export var visitor = {
|
||||
return nodes;
|
||||
},
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
ExportDefaultDeclaration(node, parent, scope, file) {
|
||||
var nodes = [];
|
||||
file.moduleFormatter.exportDeclaration(node, nodes, scope);
|
||||
@ -49,6 +66,10 @@ export var visitor = {
|
||||
return nodes;
|
||||
},
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
ExportNamedDeclaration(node, parent, scope, file) {
|
||||
// flow type
|
||||
if (this.get("declaration").isTypeAlias()) return;
|
||||
|
||||
@ -1,6 +1,10 @@
|
||||
import ReplaceSupers from "../../helpers/replace-supers";
|
||||
import * as t from "../../../types";
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
function Property(path, node, scope, getObjectRef, file) {
|
||||
if (!node.method && node.kind === "init") return;
|
||||
if (!t.isFunction(node.value)) return;
|
||||
@ -17,7 +21,16 @@ function Property(path, node, scope, getObjectRef, file) {
|
||||
replaceSupers.replace();
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export var visitor = {
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
ObjectExpression(node, parent, scope, file) {
|
||||
var objectRef;
|
||||
var getObjectRef = () => objectRef = objectRef || scope.generateUidIdentifier("obj");
|
||||
|
||||
@ -3,6 +3,10 @@ import getFunctionArity from "../../../helpers/get-function-arity";
|
||||
import * as util from "../../../../util";
|
||||
import * as t from "../../../../types";
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
var hasDefaults = function (node) {
|
||||
for (var i = 0; i < node.params.length; i++) {
|
||||
if (!t.isIdentifier(node.params[i])) return true;
|
||||
@ -10,7 +14,16 @@ var hasDefaults = function (node) {
|
||||
return false;
|
||||
};
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
var iifeVisitor = {
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
ReferencedIdentifier(node, parent, scope, state) {
|
||||
if (node.name !== "eval") {
|
||||
if (!state.scope.hasOwnBinding(node.name)) return;
|
||||
@ -22,7 +35,16 @@ var iifeVisitor = {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export var visitor = {
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
Function(node, parent, scope, file) {
|
||||
if (!hasDefaults(node)) return;
|
||||
|
||||
|
||||
@ -7,4 +7,8 @@ export var metadata = {
|
||||
group: "builtin-advanced"
|
||||
};
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export var visitor = visitors.merge([rest.visitor, def.visitor]);
|
||||
|
||||
@ -1,7 +1,16 @@
|
||||
import * as util from "../../../../util";
|
||||
import * as t from "../../../../types";
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
var memberExpressionOptimisationVisitor = {
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
Scope(node, parent, scope, state) {
|
||||
// check if this scope has a local binding that will shadow the rest parameter
|
||||
if (!scope.bindingIdentifierEquals(state.name, state.outerBinding)) {
|
||||
@ -9,11 +18,19 @@ var memberExpressionOptimisationVisitor = {
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
Flow() {
|
||||
// don't touch reference in type annotations
|
||||
this.skip();
|
||||
},
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
Function(node, parent, scope, state) {
|
||||
// skip over functions as whatever `arguments` we reference inside will refer
|
||||
// to the wrong function
|
||||
@ -24,6 +41,10 @@ var memberExpressionOptimisationVisitor = {
|
||||
this.skip();
|
||||
},
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
ReferencedIdentifier(node, parent, scope, state) {
|
||||
// we can't guarantee the purity of arguments
|
||||
if (node.name === "arguments") {
|
||||
@ -60,6 +81,10 @@ var memberExpressionOptimisationVisitor = {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
function optimiseMemberExpression(parent, offset) {
|
||||
if (offset === 0) return;
|
||||
|
||||
@ -75,11 +100,24 @@ function optimiseMemberExpression(parent, offset) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
function hasRest(node) {
|
||||
return t.isRestElement(node.params[node.params.length - 1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export var visitor = {
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
Function(node, parent, scope) {
|
||||
if (!hasRest(node)) return;
|
||||
|
||||
|
||||
@ -1,5 +1,9 @@
|
||||
import * as t from "../../../types";
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
function loose(node, body, objId) {
|
||||
for (var prop of (node.properties: Array)) {
|
||||
body.push(t.expressionStatement(
|
||||
@ -12,6 +16,10 @@ function loose(node, body, objId) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
function spec(node, body, objId, initProps, file) {
|
||||
// add a simple assignment for all Symbol member expressions due to symbol polyfill limitations
|
||||
// otherwise use Object.defineProperty
|
||||
@ -45,7 +53,16 @@ function spec(node, body, objId, initProps, file) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export var visitor = {
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
ObjectExpression: {
|
||||
exit(node, parent, scope, file) {
|
||||
var hasComputed = false;
|
||||
|
||||
@ -1,4 +1,13 @@
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export var visitor = {
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
Property(node) {
|
||||
if (node.method) {
|
||||
node.method = false;
|
||||
|
||||
@ -1,7 +1,16 @@
|
||||
import * as regex from "../../helpers/regex";
|
||||
import * as t from "../../../types";
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export var visitor = {
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
Literal(node) {
|
||||
if (!regex.is(node, "y")) return;
|
||||
return t.newExpression(t.identifier("RegExp"), [
|
||||
|
||||
@ -1,7 +1,16 @@
|
||||
import rewritePattern from "regexpu/rewrite-pattern";
|
||||
import * as regex from "../../helpers/regex";
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export var visitor = {
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
Literal(node) {
|
||||
if (!regex.is(node, "u")) return;
|
||||
node.regex.pattern = rewritePattern(node.regex.pattern, node.regex.flags);
|
||||
|
||||
@ -1,5 +1,9 @@
|
||||
import * as t from "../../../types";
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
function buildAssert(node, file) {
|
||||
return t.callExpression(
|
||||
file.addHelper("temporal-assert-defined"),
|
||||
@ -7,6 +11,10 @@ function buildAssert(node, file) {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
function references(node, scope, state) {
|
||||
var declared = state.letRefs[node.name];
|
||||
if (!declared) return false;
|
||||
@ -15,7 +23,16 @@ function references(node, scope, state) {
|
||||
return scope.getBindingIdentifier(node.name) === declared;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
var refVisitor = {
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
ReferencedIdentifier(node, parent, scope, state) {
|
||||
if (t.isFor(parent) && parent.left === node) return;
|
||||
|
||||
@ -33,6 +50,10 @@ var refVisitor = {
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
AssignmentExpression: {
|
||||
exit(node, parent, scope, state) {
|
||||
if (node._ignoreBlockScopingTDZ) return;
|
||||
@ -62,7 +83,16 @@ export var metadata = {
|
||||
group: "builtin-advanced"
|
||||
};
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export var visitor = {
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
"Program|Loop|BlockStatement": {
|
||||
exit(node, parent, scope, file) {
|
||||
var letRefs = node._letReferences;
|
||||
|
||||
@ -4,7 +4,16 @@ export var metadata = {
|
||||
optional: true
|
||||
};
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export var visitor = {
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
UnaryExpression(node, parent, scope, file) {
|
||||
if (node._ignoreSpecSymbols) return;
|
||||
|
||||
@ -25,12 +34,20 @@ export var visitor = {
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
BinaryExpression(node, parent, scope, file) {
|
||||
if (node.operator === "instanceof") {
|
||||
return t.callExpression(file.addHelper("instanceof"), [node.left, node.right]);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
"VariableDeclaration|FunctionDeclaration"(node) {
|
||||
if (node._generated) this.skip();
|
||||
}
|
||||
|
||||
@ -5,7 +5,16 @@ export var metadata = {
|
||||
group: "builtin-pre"
|
||||
};
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export var visitor = {
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
TemplateLiteral(node, parent) {
|
||||
if (t.isTaggedTemplateExpression(parent)) return;
|
||||
|
||||
|
||||
@ -1,5 +1,9 @@
|
||||
import * as t from "../../../types";
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
function getSpreadLiteral(spread, scope) {
|
||||
if (scope.hub.file.isLoose("es6.spread") && !t.isIdentifier(spread.argument, { name: "arguments" })) {
|
||||
return spread.argument;
|
||||
@ -8,6 +12,10 @@ function getSpreadLiteral(spread, scope) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
function hasSpread(nodes) {
|
||||
for (var i = 0; i < nodes.length; i++) {
|
||||
if (t.isSpreadElement(nodes[i])) {
|
||||
@ -17,6 +25,10 @@ function hasSpread(nodes) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
function build(props, scope) {
|
||||
var nodes = [];
|
||||
|
||||
@ -47,7 +59,16 @@ export var metadata = {
|
||||
group: "builtin-advanced"
|
||||
};
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export var visitor = {
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
ArrayExpression(node, parent, scope) {
|
||||
var elements = node.elements;
|
||||
if (!hasSpread(elements)) return;
|
||||
@ -63,6 +84,10 @@ export var visitor = {
|
||||
return t.callExpression(t.memberExpression(first, t.identifier("concat")), nodes);
|
||||
},
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
CallExpression(node, parent, scope) {
|
||||
var args = node.arguments;
|
||||
if (!hasSpread(args)) return;
|
||||
@ -103,6 +128,10 @@ export var visitor = {
|
||||
node.arguments.unshift(contextLiteral);
|
||||
},
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
NewExpression(node, parent, scope, file) {
|
||||
var args = node.arguments;
|
||||
if (!hasSpread(args)) return;
|
||||
|
||||
@ -9,7 +9,16 @@ export var metadata = {
|
||||
group: "builtin-trailing"
|
||||
};
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export var visitor = {
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
Function(node, parent, scope, file) {
|
||||
if (node.generator || node.async) return;
|
||||
var tailCall = new TailCallTransformer(this, scope, file);
|
||||
@ -17,11 +26,24 @@ export var visitor = {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
function returnBlock(expr) {
|
||||
return t.blockStatement([t.returnStatement(expr)]);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
var visitor = {
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
enter(node, parent) {
|
||||
if (t.isTryStatement(parent)) {
|
||||
if (node === parent.block) {
|
||||
@ -32,18 +54,34 @@ var visitor = {
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
ReturnStatement(node, parent, scope, state) {
|
||||
return state.subTransform(node.argument);
|
||||
},
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
Function() {
|
||||
this.skip();
|
||||
},
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
VariableDeclaration(node, parent, scope, state) {
|
||||
state.vars.push(node);
|
||||
},
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
ThisExpression(node, parent, scope, state) {
|
||||
if (!state.isShadowed) {
|
||||
state.needsThis = true;
|
||||
@ -51,6 +89,10 @@ var visitor = {
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
ReferencedIdentifier(node, parent, scope, state) {
|
||||
if (node.name === "arguments" && (!state.isShadowed || node._shadowedFunctionLiteral)) {
|
||||
state.needsArguments = true;
|
||||
@ -59,6 +101,10 @@ var visitor = {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
class TailCallTransformer {
|
||||
constructor(path, scope, file) {
|
||||
this.hasTailRecursion = false;
|
||||
@ -80,26 +126,50 @@ class TailCallTransformer {
|
||||
this.node = path.node;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
getArgumentsId() {
|
||||
return this.argumentsId = this.argumentsId || this.scope.generateUidIdentifier("arguments");
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
getThisId() {
|
||||
return this.thisId = this.thisId || this.scope.generateUidIdentifier("this");
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
getLeftId() {
|
||||
return this.leftId = this.leftId || this.scope.generateUidIdentifier("left");
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
getFunctionId() {
|
||||
return this.functionId = this.functionId || this.scope.generateUidIdentifier("function");
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
getAgainId() {
|
||||
return this.againId = this.againId || this.scope.generateUidIdentifier("again");
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
getParams() {
|
||||
var params = this.params;
|
||||
|
||||
@ -121,6 +191,10 @@ class TailCallTransformer {
|
||||
return this.params = params;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
hasDeopt() {
|
||||
// check if the ownerId has been reassigned, if it has then it's not safe to
|
||||
// perform optimisations
|
||||
@ -128,6 +202,10 @@ class TailCallTransformer {
|
||||
return ownerIdInfo && !ownerIdInfo.constant;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
run() {
|
||||
var node = this.node;
|
||||
|
||||
@ -226,6 +304,10 @@ class TailCallTransformer {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
subTransform(node) {
|
||||
if (!node) return;
|
||||
|
||||
@ -233,6 +315,10 @@ class TailCallTransformer {
|
||||
if (handler) return handler.call(this, node);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
subTransformConditionalExpression(node) {
|
||||
var callConsequent = this.subTransform(node.consequent);
|
||||
var callAlternate = this.subTransform(node.alternate);
|
||||
@ -253,6 +339,10 @@ class TailCallTransformer {
|
||||
return [node];
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
subTransformLogicalExpression(node) {
|
||||
// only call in right-value of can be optimized
|
||||
var callRight = this.subTransform(node.right);
|
||||
@ -273,6 +363,10 @@ class TailCallTransformer {
|
||||
return [t.ifStatement(testExpr, returnBlock(leftId))].concat(callRight);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
subTransformSequenceExpression(node) {
|
||||
var seq = node.expressions;
|
||||
|
||||
@ -291,6 +385,10 @@ class TailCallTransformer {
|
||||
return [t.expressionStatement(node)].concat(lastCall);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
subTransformCallExpression(node) {
|
||||
var callee = node.callee;
|
||||
var thisBinding, args;
|
||||
|
||||
@ -6,16 +6,28 @@ export var metadata = {
|
||||
group: "builtin-pre"
|
||||
};
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
function isString(node) {
|
||||
return t.isLiteral(node) && typeof node.value === "string";
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
function buildBinaryExpression(left, right) {
|
||||
var node = t.binaryExpression("+", left, right);
|
||||
node._templateLiteralProduced = true;
|
||||
return node;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
function crawl(path) {
|
||||
if (path.is("_templateLiteralProduced")) {
|
||||
crawl(path.get("left"));
|
||||
@ -25,7 +37,16 @@ function crawl(path) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export var visitor = {
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
TaggedTemplateExpression(node, parent, scope, file) {
|
||||
var quasi = node.quasi;
|
||||
var args = [];
|
||||
@ -50,6 +71,10 @@ export var visitor = {
|
||||
return t.callExpression(node.tag, args);
|
||||
},
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
TemplateLiteral(node, parent, scope, file) {
|
||||
var nodes = [];
|
||||
|
||||
|
||||
@ -7,7 +7,16 @@ export var metadata = {
|
||||
stage: 0
|
||||
};
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export var visitor = {
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
ComprehensionExpression(node, parent, scope) {
|
||||
var callback = array;
|
||||
if (node.generator) callback = generator;
|
||||
@ -15,6 +24,10 @@ export var visitor = {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
function generator(node) {
|
||||
var body = [];
|
||||
var container = t.functionExpression(null, [], t.blockStatement(body), true);
|
||||
@ -27,6 +40,10 @@ function generator(node) {
|
||||
return t.callExpression(container, []);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
function array(node, parent, scope) {
|
||||
var uid = scope.generateUidIdentifierBasedOnNode(parent);
|
||||
|
||||
|
||||
@ -8,7 +8,16 @@ export var metadata = {
|
||||
stage: 1
|
||||
};
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export var visitor = {
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
ObjectExpression(node, parent, scope, file) {
|
||||
var hasDecorators = false;
|
||||
for (let i = 0; i < node.properties.length; i++) {
|
||||
|
||||
@ -5,7 +5,16 @@ export var metadata = {
|
||||
stage: 0
|
||||
};
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export var visitor = {
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
DoExpression(node) {
|
||||
var body = node.body.body;
|
||||
if (body.length) {
|
||||
|
||||
@ -9,9 +9,17 @@ export var metadata = {
|
||||
|
||||
var MATH_POW = t.memberExpression(t.identifier("Math"), t.identifier("pow"));
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export var visitor = build({
|
||||
operator: "**",
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
build(left, right) {
|
||||
return t.callExpression(MATH_POW, [left, right]);
|
||||
}
|
||||
|
||||
@ -6,6 +6,10 @@ export var metadata = {
|
||||
stage: 1
|
||||
};
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
function build(node, nodes, scope) {
|
||||
var first = node.specifiers[0];
|
||||
if (!t.isExportNamespaceSpecifier(first) && !t.isExportDefaultSpecifier(first)) return;
|
||||
@ -26,7 +30,16 @@ function build(node, nodes, scope) {
|
||||
build(node, nodes, scope);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
export var visitor = {
|
||||
|
||||
/**
|
||||
* [Please add a description.]
|
||||
*/
|
||||
|
||||
ExportNamedDeclaration(node, parent, scope) {
|
||||
var nodes = [];
|
||||
build(node, nodes, scope);
|
||||
|
||||
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