diff --git a/lib/6to5/transformers/computed-property-names.js b/lib/6to5/transformers/computed-property-names.js index 00dd77cbeb..174c83f2c4 100644 --- a/lib/6to5/transformers/computed-property-names.js +++ b/lib/6to5/transformers/computed-property-names.js @@ -13,7 +13,7 @@ exports.ObjectExpression = function (node, parent, opts, generateUid) { if (prop.computed) { hasComputed = true; computed.unshift(prop); - if (!hasThis) hasThis = traverse.hasType(prop, "ThisExpression"); + hasThis = hasThis || traverse.hasType(prop, "ThisExpression"); return false; } else { return true; diff --git a/lib/6to5/traverse/index.js b/lib/6to5/traverse/index.js index 6f125ea95e..2f68495064 100644 --- a/lib/6to5/traverse/index.js +++ b/lib/6to5/traverse/index.js @@ -29,7 +29,7 @@ var traverse = module.exports = function (parent, callbacks, blacklistTypes) { if (!node) return; // type is blacklisted - if (blacklistTypes.indexOf(node.type) >= 0) return; + if (_.contains(blacklistTypes, node.type)) return; // enter var result = callbacks.enter(node, parent, obj, key); @@ -40,6 +40,7 @@ var traverse = module.exports = function (parent, callbacks, blacklistTypes) { // replace node if (result != null) node = obj[key] = result; + // traverse node traverse(node, callbacks, blacklistTypes); // exit @@ -71,16 +72,18 @@ traverse.FUNCTION_TYPES = ["ArrowFunctionExpression", "FunctionDeclaration", "Fu traverse.Delete = {}; traverse.hasType = function (tree, type, blacklistTypes) { - if (tree.type === type) return true; + blacklistTypes = [].concat(blacklistTypes || []); var has = false; - blacklistTypes = blacklistTypes || []; if (_.isArray(tree)) { return !!_.find(tree, function (node) { return traverse.hasType(node, type, blacklistTypes); }); } else { + if (_.contains(blacklistTypes, tree.type)) return false; + if (tree.type === type) return true; + traverse(tree, function (node) { if (node.type === type) { has = true; diff --git a/test/fixtures/syntax/block-binding/return-ignore-siblings/actual.js b/test/fixtures/syntax/block-binding/return-ignore-siblings/actual.js new file mode 100644 index 0000000000..ac8d9a28f1 --- /dev/null +++ b/test/fixtures/syntax/block-binding/return-ignore-siblings/actual.js @@ -0,0 +1,6 @@ +let _message = message(); +console.log( _message ); + +function message () { + return 'hello'; +} diff --git a/test/fixtures/syntax/block-binding/return-ignore-siblings/expected.js b/test/fixtures/syntax/block-binding/return-ignore-siblings/expected.js new file mode 100644 index 0000000000..3598b1a684 --- /dev/null +++ b/test/fixtures/syntax/block-binding/return-ignore-siblings/expected.js @@ -0,0 +1,8 @@ +(function () { + var _message = message(); + console.log(_message); + + function message () { + return 'hello'; + } +})();