From 6847211971f791676de223cbd137d41821555109 Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Wed, 12 Nov 2014 00:46:36 +1100 Subject: [PATCH] fix up aliasFunctions transformer --- .../transformation/transformers/_alias-functions.js | 6 +++--- .../transformers/array-comprehension.js | 11 +++++++++-- .../transformation/transformers/arrow-functions.js | 2 +- .../transformers/computed-property-names.js | 2 +- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/lib/6to5/transformation/transformers/_alias-functions.js b/lib/6to5/transformation/transformers/_alias-functions.js index 2186fe4951..2c66d4d721 100644 --- a/lib/6to5/transformation/transformers/_alias-functions.js +++ b/lib/6to5/transformation/transformers/_alias-functions.js @@ -14,7 +14,7 @@ var go = function (getBody, node, file, scope) { }; // traverse the function and find all alias functions so we can alias - // arguments and this if necessary + // `arguments` and `this` if necessary traverse(node, function (node) { if (!node._aliasFunction) { if (t.isFunction(node)) { @@ -25,9 +25,9 @@ var go = function (getBody, node, file, scope) { } } - // traverse all child nodes of this function and find arguments and this + // traverse all child nodes of this function and find `arguments` and `this` traverse(node, function (node, parent) { - if (t.isFunction(node) && node._aliasFunction !== "arrows") { + if (t.isFunction(node) && !node._aliasFunction) { return false; } diff --git a/lib/6to5/transformation/transformers/array-comprehension.js b/lib/6to5/transformation/transformers/array-comprehension.js index eb8ddb6970..5d5e087088 100644 --- a/lib/6to5/transformation/transformers/array-comprehension.js +++ b/lib/6to5/transformation/transformers/array-comprehension.js @@ -1,5 +1,6 @@ var util = require("../../util"); var t = require("../../types"); +var _ = require("lodash"); var singleArrayExpression = function (node) { var block = node.blocks[0]; @@ -13,7 +14,13 @@ var singleArrayExpression = function (node) { ARRAY: block.right, KEY: block.left }); - result._aliasFunction = true; + + _.each([result.callee.object, result], function (call) { + if (t.isCallExpression(call)) { + call.arguments[0]._aliasFunction = true; + } + }); + return result; }; @@ -23,7 +30,7 @@ var multiple = function (node, file) { var container = util.template("array-comprehension-container", { KEY: uid }); - container._aliasFunction = true; + container.callee.expression._aliasFunction = true; var block = container.callee.expression.body; var body = block.body; diff --git a/lib/6to5/transformation/transformers/arrow-functions.js b/lib/6to5/transformation/transformers/arrow-functions.js index e80db32852..80a45e573b 100644 --- a/lib/6to5/transformation/transformers/arrow-functions.js +++ b/lib/6to5/transformation/transformers/arrow-functions.js @@ -3,7 +3,7 @@ var t = require("../../types"); exports.ArrowFunctionExpression = function (node) { t.ensureBlock(node); - node._aliasFunction = "arrows"; + node._aliasFunction = true; node.expression = false; node.type = "FunctionExpression"; diff --git a/lib/6to5/transformation/transformers/computed-property-names.js b/lib/6to5/transformation/transformers/computed-property-names.js index c66e3e881e..8a8dee808d 100644 --- a/lib/6to5/transformation/transformers/computed-property-names.js +++ b/lib/6to5/transformation/transformers/computed-property-names.js @@ -29,7 +29,7 @@ exports.ObjectExpression = function (node, parent, file) { var containerCallee = container.callee.expression; var containerBody = containerCallee.body.body; - containerCallee._aliasFunction = "arrows"; + containerCallee._aliasFunction = true; _.each(computed, function (prop) { containerBody.unshift(