From 622bb2e9628bc4df1324f2fbcf4510b37c33136e Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Fri, 31 Oct 2014 21:22:03 +1100 Subject: [PATCH] types: add more tests for optional paranthesis --- lib/6to5/types.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/6to5/types.js b/lib/6to5/types.js index 6cf4871fe5..f6eee9a4da 100644 --- a/lib/6to5/types.js +++ b/lib/6to5/types.js @@ -13,7 +13,6 @@ exports.aliases = { FunctionExpression: ["Function"] }; - exports.isUnaryLike = function (node) { return _.contains(exports.UNARY_TYPES, node.type); }; @@ -166,17 +165,23 @@ exports.needsParans = function (node, parent) { } } - if (node.type === "FunctionExpression" && parent.type === "CallExpression" && parent.callee === node) { + if (node.type === "FunctionExpression") { + if (parent.type === "MemberExpression" && parent.object === node) { + return true; + } + + if (parent.type === "CallExpression" && parent.callee === node) { + return true; + } + } + + if (node.type === "ObjectPattern" && parent.type === "AssignmentExpression") { return true; } return false; }; -exports.canBeFirstInStatement = function (node) { - return node.type !== "FunctionExpression" && node.type !== "ObjectExpression"; -}; - var PRECEDENCE = {}; _.each([