use the mallet operator this is actually amazing i think i'm going to cry

This commit is contained in:
Sebastian McKenzie 2015-02-25 23:34:04 +11:00
parent 5b9878451a
commit 25232d3141
19 changed files with 38 additions and 38 deletions

View File

@ -5,14 +5,14 @@ transform.version = require("../../../package").version;
transform.transform = transform;
transform.run = function (code, opts) {
opts = opts || {};
opts ||= {};
opts.sourceMap = "inline";
return new Function(transform(code, opts).code)();
};
transform.load = function (url, callback, opts, hold) {
opts = opts || {};
opts.filename = opts.filename || url;
opts ||= {};
opts.filename ||= url;
var xhr = global.ActiveXObject ? new global.ActiveXObject("Microsoft.XMLHTTP") : new global.XMLHttpRequest();
xhr.open("GET", url, true);

View File

@ -50,7 +50,7 @@ exports.transformFile = function (filename, opts, callback) {
};
exports.transformFileSync = function (filename, opts) {
opts = opts || {};
opts ||= {};
opts.filename = filename;
return transform(fs.readFileSync(filename), opts);
};

View File

@ -136,7 +136,7 @@ hookExtensions(util.canCompile.EXTENSIONS);
module.exports = function (opts) {
// normalize options
opts = opts || {};
opts ||= {};
if (opts.only != null) onlyRegex = util.regexify(opts.only);
if (opts.ignore != null) ignoreRegex = util.regexify(opts.ignore);

View File

@ -12,7 +12,7 @@ function exists(filename) {
module.exports = function (loc, opts) {
var rel = ".babelrc";
opts = opts || {};
opts ||= {};
function find(start, rel) {
var file = path.join(start, rel);

View File

@ -78,7 +78,7 @@ Buffer.prototype.newline = function (i, removeLast) {
return;
}
removeLast = removeLast || false;
removeLast ||= false;
if (isNumber(i)) {
i = Math.min(2, i);

View File

@ -18,7 +18,7 @@ var n = require("./node");
var t = require("../types");
function CodeGenerator(ast, opts, code) {
opts = opts || {};
opts ||= {};
this.comments = ast.comments || [];
this.tokens = ast.tokens || [];
@ -108,7 +108,7 @@ CodeGenerator.prototype.buildPrint = function (parent) {
};
print.sequence = (nodes, opts) => {
opts = opts || {};
opts ||= {};
opts.statement = true;
return this.printJoin(print, nodes, opts);
};
@ -118,8 +118,8 @@ CodeGenerator.prototype.buildPrint = function (parent) {
};
print.list = function (items, opts) {
opts = opts || {};
opts.separator = opts.separator || ", ";
opts ||= {};
opts.separator ||= ", ";
print.join(items, opts);
};
@ -146,7 +146,7 @@ CodeGenerator.prototype.print = function (node, parent, opts) {
this.format.concise = true;
}
opts = opts || {};
opts ||= {};
var newline = (leading) => {
if (!opts.statement && !n.isUserWhitespacable(node, parent)) {
@ -216,7 +216,7 @@ CodeGenerator.prototype.print = function (node, parent, opts) {
CodeGenerator.prototype.printJoin = function (print, nodes, opts) {
if (!nodes || !nodes.length) return;
opts = opts || {};
opts ||= {};
var len = nodes.length;

View File

@ -4,7 +4,7 @@ var map = require("lodash/collection/map");
var t = require("../../types");
var crawl = function (node, state) {
state = state || {};
state ||= {};
if (t.isMemberExpression(node)) {
crawl(node.object, state);
@ -18,7 +18,7 @@ var crawl = function (node, state) {
} else if (t.isFunction(node)) {
state.hasFunction = true;
} else if (t.isIdentifier(node)) {
state.hasHelper = state.hasHelper || isHelper(node.callee);
state.hasHelper ||= isHelper(node.callee);
}
return state;

View File

@ -286,7 +286,7 @@ File.prototype.get = function (key) {
};
File.prototype.addImport = function (source, name, noDefault) {
name = name || source;
name ||= source;
var id = this.dynamicImportIds[name];
if (!id) {
@ -312,7 +312,7 @@ File.prototype.isConsequenceExpressionStatement = function (node) {
File.prototype.attachAuxiliaryComment = function (node) {
var comment = this.opts.auxiliaryComment;
if (comment) {
node.leadingComments = node.leadingComments || [];
node.leadingComments ||= [];
node.leadingComments.push({
type: "Line",
value: " " + comment
@ -353,7 +353,7 @@ File.prototype.logDeopt = function () {
};
File.prototype.errorWithNode = function (node, msg, Error) {
Error = Error || SyntaxError;
Error ||= SyntaxError;
var loc = node.loc.start;
var err = new Error("Line " + loc.line + ": " + msg);
@ -429,7 +429,7 @@ var checkNode = function (stack, node, scope) {
File.prototype.checkNode = function (node, scope) {
var stack = this.transformerStack;
scope = scope || this.scope;
scope ||= this.scope;
checkNode(stack, node, scope);

View File

@ -58,7 +58,7 @@ var rawTransformers = require("./transformers");
each(rawTransformers, function (transformer, key) {
var namespace = key.split(".")[0];
transform.namespaces[namespace] = transform.namespaces[namespace] || [];
transform.namespaces[namespace] ||= [];
transform.namespaces[namespace].push(key);
transform.transformerNamespaces[key] = namespace;

View File

@ -33,7 +33,7 @@ DefaultFormatter.prototype.doDefaultExportInterop = function (node) {
DefaultFormatter.prototype.bumpImportOccurences = function (node) {
var source = node.source.value;
var occurs = this.localImportOccurences;
occurs[source] = occurs[source] || 0;
occurs[source] ||= 0;
occurs[source] += node.specifiers.length;
};

View File

@ -33,7 +33,7 @@ function Transformer(key, transformer, opts) {
this.optional = !!take("optional");
this.handlers = this.normalize(transformer);
this.opts = opts || {};
this.opts ||= {};
this.key = key;
}

View File

@ -18,7 +18,7 @@ var isLet = function (node, parent) {
if (isLetInitable(node, parent)) {
for (var i = 0; i < node.declarations.length; i++) {
var declar = node.declarations[i];
declar.init = declar.init || t.identifier("undefined");
declar.init ||= t.identifier("undefined");
}
}

View File

@ -201,7 +201,7 @@ ClassTransformer.prototype.buildBody = function () {
}
if (instanceProps || staticProps) {
staticProps = staticProps || t.literal(null);
staticProps ||= t.literal(null);
var args = [className, staticProps];
if (instanceProps) args.push(instanceProps);

View File

@ -467,7 +467,7 @@ exports.VariableDeclaration = function (node, parent, scope, file) {
for (i = 0; i < nodes.length; i++) {
node = nodes[i];
declar = declar || t.variableDeclaration(node.kind, []);
declar ||= t.variableDeclaration(node.kind, []);
if (!t.isVariableDeclaration(node) && declar.kind !== node.kind) {
throw file.errorWithNode(node, messages.get("invalidParentForThisNode"));

View File

@ -23,23 +23,23 @@ function TailCallTransformer(node, scope, file) {
}
TailCallTransformer.prototype.getArgumentsId = function () {
return this.argumentsId = this.argumentsId || this.scope.generateUidIdentifier("arguments");
return this.argumentsId ||= this.scope.generateUidIdentifier("arguments");
};
TailCallTransformer.prototype.getThisId = function () {
return this.thisId = this.thisId || this.scope.generateUidIdentifier("this");
return this.thisId ||= this.scope.generateUidIdentifier("this");
};
TailCallTransformer.prototype.getLeftId = function () {
return this.leftId = this.leftId || this.scope.generateUidIdentifier("left");
return this.leftId ||= this.scope.generateUidIdentifier("left");
};
TailCallTransformer.prototype.getFunctionId = function () {
return this.functionId = this.functionId || this.scope.generateUidIdentifier("function");
return this.functionId ||= this.scope.generateUidIdentifier("function");
};
TailCallTransformer.prototype.getAgainId = function () {
return this.againId = this.againId || this.scope.generateUidIdentifier("again");
return this.againId ||= this.scope.generateUidIdentifier("again");
};
TailCallTransformer.prototype.getParams = function () {

View File

@ -46,10 +46,10 @@ var go = function (getBody, node, scope) {
var state = {
getArgumentsId() {
return argumentsId = argumentsId || scope.generateUidIdentifier("arguments");
return argumentsId ||= scope.generateUidIdentifier("arguments");
},
getThisId() {
return thisId = thisId || scope.generateUidIdentifier("this");
return thisId ||= scope.generateUidIdentifier("this");
}
};
@ -60,7 +60,7 @@ var go = function (getBody, node, scope) {
var body;
var pushDeclaration = function (id, init) {
body = body || getBody();
body ||= getBody();
body.unshift(t.variableDeclaration("var", [
t.variableDeclarator(id, init)
]));

View File

@ -20,7 +20,7 @@ exports.Program = function (node, parent, scope, file) {
if (declar.init) {
node.body.unshift(file.attachAuxiliaryComment(t.variableDeclaration(kind, [declarNode])));
} else {
kinds[kind] = kinds[kind] || [];
kinds[kind] ||= [];
kinds[kind].push(declarNode);
}
}

View File

@ -170,7 +170,7 @@ Scope.prototype.checkBlockScopedCollisions = function (kind, name, id) {
};
Scope.prototype.rename = function (oldName, newName) {
newName = newName || this.generateUidIdentifier(oldName).name;
newName ||= this.generateUidIdentifier(oldName).name;
var info = this.getBindingInfo(oldName);
if (!info) return;
@ -530,7 +530,7 @@ Scope.prototype.push = function (opts) {
}
if (t.isBlockStatement(block) || t.isProgram(block)) {
block._declarations = block._declarations || {};
block._declarations ||= {};
block._declarations[opts.key] = {
kind: opts.kind,
id: opts.id,

View File

@ -22,7 +22,7 @@ function registerType(type, skipAliasCheck) {
};
t["assert" + type] = function (node, opts) {
opts = opts || {};
opts ||= {};
if (!is(node, opts)) {
throw new Error("Expected type " + JSON.stringify(type) + " with option " + JSON.stringify(opts));
}
@ -405,7 +405,7 @@ t.toIdentifier = function (name) {
*/
t.ensureBlock = function (node, key) {
key = key || "body";
key ||= "body";
return node[key] = t.toBlock(node[key], node);
};