merge comprehension transformers

This commit is contained in:
Sebastian McKenzie
2015-01-21 22:40:26 +11:00
parent c51f8c48b6
commit 8558505b65
2 changed files with 17 additions and 27 deletions

View File

@@ -7,7 +7,23 @@ var t = require("../../types");
exports.experimental = true;
var build = function (node, parent, scope, context, file) {
exports.ComprehensionExpression = function (node) {
if (!node.generator) return;
var body = [];
var container = t.functionExpression(null, [], t.blockStatement(body), true);
container._aliasFunction = true;
body.push(buildComprehension(node, function () {
return t.expressionStatement(t.yieldExpression(node.body));
}));
return t.callExpression(container, []);
};
exports.ComprehensionExpression = function (node, parent, scope, context, file) {
if (node.generator) return;
var uid = scope.generateUidBasedOnNode(parent, file);
var container = util.template("array-comprehension-container", {
@@ -35,9 +51,3 @@ var build = function (node, parent, scope, context, file) {
return container;
};
exports.ComprehensionExpression = function (node, parent, scope, context, file) {
if (node.generator) return;
return build(node, parent, scope, context, file);
};

View File

@@ -1,20 +0,0 @@
"use strict";
var buildComprehension = require("../helpers/build-comprehension");
var t = require("../../types");
exports.experimental = true;
exports.ComprehensionExpression = function (node) {
if (!node.generator) return;
var body = [];
var container = t.functionExpression(null, [], t.blockStatement(body), true);
container._aliasFunction = true;
body.push(buildComprehension(node, function () {
return t.expressionStatement(t.yieldExpression(node.body));
}));
return t.callExpression(container, []);
};