diff --git a/lib/6to5/generation/generators/methods.js b/lib/6to5/generation/generators/methods.js index 600de8cfd2..0e858e78eb 100644 --- a/lib/6to5/generation/generators/methods.js +++ b/lib/6to5/generation/generators/methods.js @@ -62,15 +62,6 @@ exports.MethodDefinition = function (node, print) { this._method(node, print); }; -exports.ReturnStatement = function (node, print) { - this.push("return"); - if (node.argument) { - this.space(); - print(node.argument); - } - this.semicolon(); -}; - exports.FunctionDeclaration = exports.FunctionExpression = function (node, print) { this.push("function"); diff --git a/lib/6to5/generation/generators/statements.js b/lib/6to5/generation/generators/statements.js index 375e83ca16..6306c3ef87 100644 --- a/lib/6to5/generation/generators/statements.js +++ b/lib/6to5/generation/generators/statements.js @@ -52,25 +52,20 @@ exports.WhileStatement = function (node, print) { print.block(node.body); }; -exports.ForInStatement = function (node, print) { - this.keyword("for"); - this.push("("); - print(node.left); - this.push(" in "); - print(node.right); - this.push(")"); - print.block(node.body); +var buildForXStatement = function (op) { + return function (node, print) { + this.keyword("for"); + this.push("("); + print(node.left); + this.push(" " + op + " "); + print(node.right); + this.push(")"); + print.block(node.body); + }; }; -exports.ForOfStatement = function (node, print) { - this.keyword("for"); - this.push("("); - print(node.left); - this.push(" of "); - print(node.right); - this.push(")"); - print.block(node.body); -}; +exports.ForInStatement = buildForXStatement("in"); +exports.ForOfStatement = buildForXStatement("of"); exports.DoWhileStatement = function (node, print) { this.keyword("do"); @@ -82,23 +77,23 @@ exports.DoWhileStatement = function (node, print) { this.push(");"); }; -exports.BreakStatement = function (node, print) { - this.push("break"); - if (node.label) { - this.space(); - print(node.label); - } - this.semicolon(); +var buildLabelStatement = function (prefix, key) { + return function (node, print) { + this.push(prefix); + + var label = node[key || "label"]; + if (label) { + this.space(); + print(label); + } + + this.semicolon(); + }; }; -exports.ContinueStatement = function (node, print) { - this.push("continue"); - if (node.label) { - this.space(); - print(node.label); - } - this.semicolon(); -}; +exports.ContinueStatement = buildLabelStatement("continue"); +exports.ReturnStatement = buildLabelStatement("return", "argument"); +exports.BreakStatement = buildLabelStatement("break"); exports.LabeledStatement = function (node, print) { print(node.label);