From d376bd3c0e2d214b125e0f8b545d2bdf685c43c9 Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Fri, 31 Oct 2014 21:23:31 +1100 Subject: [PATCH] generator: remove redundant async tests --- lib/6to5/generators/methods.js | 57 ++++++++++++++++++++++++---------- 1 file changed, 40 insertions(+), 17 deletions(-) diff --git a/lib/6to5/generators/methods.js b/lib/6to5/generators/methods.js index 2246d685cf..6cff925d95 100644 --- a/lib/6to5/generators/methods.js +++ b/lib/6to5/generators/methods.js @@ -1,24 +1,53 @@ exports._params = function (node, print) { + var self = this; + this.push("("); - this.printJoin(print, node.params, ", "); + + this.printJoin(print, node.params, ", ", { + iterator: function (param, i) { + print(param); + + var def = node.defaults && node.defaults[i]; + if (def) { + self.push(" = "); + print(def); + } + } + }); + + if (node.rest) { + if (node.params.length) { + this.push(", "); + } + + this.push("..."); + print(node.rest); + } + this.push(")"); }; -exports._method = function (kind, key, value, print) { - if (value.async) { - this.push("async "); - } +exports._method = function (node, print) { + var value = node.value; + var kind = node.kind; + var key = node.key; if (!kind || kind === "init") { if (value.generator) { this.push("*"); } } else { - assert.ok(kind === "get" || kind === "set"); this.push(kind + " "); } - print(key); + if (node.computed) { + this.push("["); + print(key); + this.push("]"); + } else { + print(key); + } + this._params(value, print); print(value.body); }; @@ -28,12 +57,7 @@ exports.MethodDefinition = function (node, print) { this.push("static "); } - this._method( - node.kind, - node.key, - node.value, - print - ); + this._method(node, print); }; exports.ReturnStatement = function (node, print) { @@ -42,12 +66,11 @@ exports.ReturnStatement = function (node, print) { this.push(" "); print(node.argument); } - this.push(";"); + this.semicolon(); }; exports.FunctionDeclaration = exports.FunctionExpression = function (node, print) { - if (node.async) this.push("async "); this.push("function"); if (node.generator) this.push("*"); if (node.id) { @@ -61,12 +84,12 @@ exports.FunctionExpression = function (node, print) { }; exports.ArrowFunctionExpression = function (node, print) { - if (node.async) this.push("async "); - if (node.params.length === 1) { + if (node.params.length === 1 && !node.defaults.length && !node.rest && node.params[0].type === "Identifier") { print(node.params[0]); } else { this._params(node, print); } + this.push(" => "); print(node.body); };