diff --git a/src/babel/api/browser.js b/src/babel/api/browser.js index e9347934dc..715b0b471d 100644 --- a/src/babel/api/browser.js +++ b/src/babel/api/browser.js @@ -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); diff --git a/src/babel/api/node.js b/src/babel/api/node.js index b367d697c4..b6edcb5bf3 100644 --- a/src/babel/api/node.js +++ b/src/babel/api/node.js @@ -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); }; diff --git a/src/babel/api/register/node.js b/src/babel/api/register/node.js index 334f757d62..b89c6544b9 100644 --- a/src/babel/api/register/node.js +++ b/src/babel/api/register/node.js @@ -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); diff --git a/src/babel/api/register/resolve-rc.js b/src/babel/api/register/resolve-rc.js index 3a75faac86..dd6244f736 100644 --- a/src/babel/api/register/resolve-rc.js +++ b/src/babel/api/register/resolve-rc.js @@ -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); diff --git a/src/babel/generation/buffer.js b/src/babel/generation/buffer.js index 385a8c5526..3b2a4522d4 100644 --- a/src/babel/generation/buffer.js +++ b/src/babel/generation/buffer.js @@ -78,7 +78,7 @@ Buffer.prototype.newline = function (i, removeLast) { return; } - removeLast = removeLast || false; + removeLast ||= false; if (isNumber(i)) { i = Math.min(2, i); diff --git a/src/babel/generation/index.js b/src/babel/generation/index.js index 016b051f1a..93babf3dbb 100644 --- a/src/babel/generation/index.js +++ b/src/babel/generation/index.js @@ -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; diff --git a/src/babel/generation/node/whitespace.js b/src/babel/generation/node/whitespace.js index dd3d66cb08..296ba55427 100644 --- a/src/babel/generation/node/whitespace.js +++ b/src/babel/generation/node/whitespace.js @@ -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; diff --git a/src/babel/transformation/file.js b/src/babel/transformation/file.js index 94187c6f33..a2c11bfe31 100644 --- a/src/babel/transformation/file.js +++ b/src/babel/transformation/file.js @@ -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); diff --git a/src/babel/transformation/index.js b/src/babel/transformation/index.js index e5c53f335e..d0af8f05ce 100644 --- a/src/babel/transformation/index.js +++ b/src/babel/transformation/index.js @@ -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; diff --git a/src/babel/transformation/modules/_default.js b/src/babel/transformation/modules/_default.js index 16abf3b269..3c64c498f2 100644 --- a/src/babel/transformation/modules/_default.js +++ b/src/babel/transformation/modules/_default.js @@ -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; }; diff --git a/src/babel/transformation/transformer.js b/src/babel/transformation/transformer.js index aed6f765d2..d06c0f74eb 100644 --- a/src/babel/transformation/transformer.js +++ b/src/babel/transformation/transformer.js @@ -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; } diff --git a/src/babel/transformation/transformers/es6/block-scoping.js b/src/babel/transformation/transformers/es6/block-scoping.js index bcabfcbb86..465f53f562 100644 --- a/src/babel/transformation/transformers/es6/block-scoping.js +++ b/src/babel/transformation/transformers/es6/block-scoping.js @@ -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"); } } diff --git a/src/babel/transformation/transformers/es6/classes.js b/src/babel/transformation/transformers/es6/classes.js index 2623fdb377..6c13608a56 100644 --- a/src/babel/transformation/transformers/es6/classes.js +++ b/src/babel/transformation/transformers/es6/classes.js @@ -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); diff --git a/src/babel/transformation/transformers/es6/destructuring.js b/src/babel/transformation/transformers/es6/destructuring.js index 87db9676eb..2743349afb 100644 --- a/src/babel/transformation/transformers/es6/destructuring.js +++ b/src/babel/transformation/transformers/es6/destructuring.js @@ -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")); diff --git a/src/babel/transformation/transformers/es6/tail-call.js b/src/babel/transformation/transformers/es6/tail-call.js index 87ab030251..e2ff372e1e 100644 --- a/src/babel/transformation/transformers/es6/tail-call.js +++ b/src/babel/transformation/transformers/es6/tail-call.js @@ -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 () { diff --git a/src/babel/transformation/transformers/internal/alias-functions.js b/src/babel/transformation/transformers/internal/alias-functions.js index 97332d9de8..77f299b7ee 100644 --- a/src/babel/transformation/transformers/internal/alias-functions.js +++ b/src/babel/transformation/transformers/internal/alias-functions.js @@ -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) ])); diff --git a/src/babel/transformation/transformers/internal/declarations.js b/src/babel/transformation/transformers/internal/declarations.js index 2237a1ec6f..28119ab9f7 100644 --- a/src/babel/transformation/transformers/internal/declarations.js +++ b/src/babel/transformation/transformers/internal/declarations.js @@ -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); } } diff --git a/src/babel/traversal/scope.js b/src/babel/traversal/scope.js index cfa8475ccc..4d5f3d2dbc 100644 --- a/src/babel/traversal/scope.js +++ b/src/babel/traversal/scope.js @@ -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, diff --git a/src/babel/types/index.js b/src/babel/types/index.js index 6dedf39288..c75a1d0e7b 100644 --- a/src/babel/types/index.js +++ b/src/babel/types/index.js @@ -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); };