From ec3c183668da357104d23dc91008cf23bcae2292 Mon Sep 17 00:00:00 2001 From: Henry Zhu Date: Sun, 28 Feb 2016 21:27:27 -0500 Subject: [PATCH] Fix: Add parens for unary arrow function Fixes T7157 --- packages/babel-generator/src/node/parentheses.js | 4 ++++ .../test/fixtures/parentheses/unary-arrow-function/actual.js | 3 +++ .../fixtures/parentheses/unary-arrow-function/expected.js | 3 +++ 3 files changed, 10 insertions(+) create mode 100644 packages/babel-generator/test/fixtures/parentheses/unary-arrow-function/actual.js create mode 100644 packages/babel-generator/test/fixtures/parentheses/unary-arrow-function/expected.js diff --git a/packages/babel-generator/src/node/parentheses.js b/packages/babel-generator/src/node/parentheses.js index d5d098c66f..0c2bba3c5a 100644 --- a/packages/babel-generator/src/node/parentheses.js +++ b/packages/babel-generator/src/node/parentheses.js @@ -204,6 +204,10 @@ export function ArrowFunctionExpression(node: Object, parent: Object): boolean { return true; } + if (t.isUnaryExpression(parent)) { + return true; + } + return UnaryLike(node, parent); } diff --git a/packages/babel-generator/test/fixtures/parentheses/unary-arrow-function/actual.js b/packages/babel-generator/test/fixtures/parentheses/unary-arrow-function/actual.js new file mode 100644 index 0000000000..a527c3b975 --- /dev/null +++ b/packages/babel-generator/test/fixtures/parentheses/unary-arrow-function/actual.js @@ -0,0 +1,3 @@ +void (() => {}); +typeof (() => {}); +!(() => {}); diff --git a/packages/babel-generator/test/fixtures/parentheses/unary-arrow-function/expected.js b/packages/babel-generator/test/fixtures/parentheses/unary-arrow-function/expected.js new file mode 100644 index 0000000000..a527c3b975 --- /dev/null +++ b/packages/babel-generator/test/fixtures/parentheses/unary-arrow-function/expected.js @@ -0,0 +1,3 @@ +void (() => {}); +typeof (() => {}); +!(() => {});