diff --git a/lib/6to5/transformation/transformers/let-scoping.js b/lib/6to5/transformation/transformers/let-scoping.js index 9ccd879620..7998e9e362 100644 --- a/lib/6to5/transformation/transformers/let-scoping.js +++ b/lib/6to5/transformation/transformers/let-scoping.js @@ -128,6 +128,12 @@ LetScoping.prototype.run = function () { var call = t.callExpression(fn, params); var ret = t.identifier(this.file.generateUid("ret", this.scope)); + var hasYield = traverse.hasType(fn.body, "YieldExpression", t.FUNCTION_TYPES); + if (hasYield) { + fn.generator = true; + call = t.yieldExpression(call, true); + } + this.build(ret, call); }; @@ -245,28 +251,34 @@ LetScoping.prototype.checkFor = function () { hasBreak: false, }; - if (this.forParent) { - traverse(this.block, function (node) { - var replace; + var forParent = this.forParent; - if (t.isFunction(node) || t.isFor(node)) { - return false; - } else if (t.isBreakStatement(node) && !node.label) { + traverse(this.block, function (node) { + var replace; + + if (t.isFunction(node) || t.isFor(node)) { + return false; + } + + if (forParent && !node.label) { + if (t.isBreakStatement(node)) { has.hasBreak = true; replace = t.returnStatement(t.literal("break")); - } else if (t.isContinueStatement(node) && !node.label) { + } else if (t.isContinueStatement(node)) { has.hasContinue = true; replace = t.returnStatement(t.literal("continue")); - } else if (t.isReturnStatement(node)) { - has.hasReturn = true; - replace = t.returnStatement(t.objectExpression([ - t.property("init", t.identifier("v"), node.argument || t.identifier("undefined")) - ])); } + } - if (replace) return t.inherits(replace, node); - }); - } + if (t.isReturnStatement(node)) { + has.hasReturn = true; + replace = t.returnStatement(t.objectExpression([ + t.property("init", t.identifier("v"), node.argument || t.identifier("undefined")) + ])); + } + + if (replace) return t.inherits(replace, node); + }); return has; }; diff --git a/lib/6to5/types/builder-keys.json b/lib/6to5/types/builder-keys.json index cf85a639df..79003df3ff 100644 --- a/lib/6to5/types/builder-keys.json +++ b/lib/6to5/types/builder-keys.json @@ -21,5 +21,6 @@ "SequenceExpression": ["expressions"], "UnaryExpression": ["operator", "argument", "prefix"], "VariableDeclaration": ["kind", "declarations"], - "VariableDeclarator": ["id", "init"] + "VariableDeclarator": ["id", "init"], + "YieldExpression": ["argument", "delegate"] }