From d4deb18975a7898c741fe76707822bb25d72f3f4 Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Fri, 14 Nov 2014 00:52:36 +1100 Subject: [PATCH] support async functions in generator and move MethodDefinition to class generator --- lib/6to5/generation/generators/classes.js | 8 ++++++++ lib/6to5/generation/generators/methods.js | 13 +++++-------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/lib/6to5/generation/generators/classes.js b/lib/6to5/generation/generators/classes.js index 80bf6b784a..f7df307f62 100644 --- a/lib/6to5/generation/generators/classes.js +++ b/lib/6to5/generation/generators/classes.js @@ -30,3 +30,11 @@ exports.ClassBody = function (node, print) { this.rightBrace(); } }; + +exports.MethodDefinition = function (node, print) { + if (node.static) { + this.push("static "); + } + + this._method(node, print); +}; diff --git a/lib/6to5/generation/generators/methods.js b/lib/6to5/generation/generators/methods.js index 0e858e78eb..e147b20a06 100644 --- a/lib/6to5/generation/generators/methods.js +++ b/lib/6to5/generation/generators/methods.js @@ -41,6 +41,8 @@ exports._method = function (node, print) { this.push(kind + " "); } + if (value.async) this.push("async "); + if (node.computed) { this.push("["); print(key); @@ -54,16 +56,9 @@ exports._method = function (node, print) { print(value.body); }; -exports.MethodDefinition = function (node, print) { - if (node.static) { - this.push("static "); - } - - this._method(node, print); -}; - exports.FunctionDeclaration = exports.FunctionExpression = function (node, print) { + if (node.async) this.push("async "); this.push("function"); if (node.generator) this.push("*"); this.space(); @@ -74,6 +69,8 @@ exports.FunctionExpression = function (node, print) { }; exports.ArrowFunctionExpression = function (node, print) { + if (node.async) this.push("async "); + if (node.params.length === 1 && !node.defaults.length && !node.rest && t.isIdentifier(node.params[0])) { print(node.params[0]); } else {