From 4dde054bb3d19f58ff0de926d2e1e75831b15085 Mon Sep 17 00:00:00 2001 From: Davy Duperron Date: Mon, 6 Mar 2017 12:44:48 +0100 Subject: [PATCH] Fix binary expression instanceof in arrow function expression (#913) * Add fix for parens of BinaryExpression with instanceof op embedded into ArrowFunctionExpression. * Add new test :rocket:. --- src/fast-path.js | 7 +++++++ tests/arrows/__snapshots__/jsfmt.spec.js.snap | 2 ++ tests/arrows/arrow_function_expression.js | 1 + 3 files changed, 10 insertions(+) diff --git a/src/fast-path.js b/src/fast-path.js index 5d473686..60d02783 100644 --- a/src/fast-path.js +++ b/src/fast-path.js @@ -305,6 +305,13 @@ FPp.needsParens = function(assumeExpressionContext) { return true; } + if ( + node.operator === "instanceof" && + parent.type === "ArrowFunctionExpression" + ) { + return true; + } + case "LogicalExpression": switch (parent.type) { case "CallExpression": diff --git a/tests/arrows/__snapshots__/jsfmt.spec.js.snap b/tests/arrows/__snapshots__/jsfmt.spec.js.snap index 525a6078..b565b0ec 100644 --- a/tests/arrows/__snapshots__/jsfmt.spec.js.snap +++ b/tests/arrows/__snapshots__/jsfmt.spec.js.snap @@ -9,6 +9,7 @@ export default (() => {})(); new (() => {}); if ((() => {}) ? 1 : 0) {} let f = () => ({}()) +let a = () => ({} instanceof a); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ (a => {}).length; typeof (() => {}); @@ -19,6 +20,7 @@ new (() => {})(); if ((() => {}) ? 1 : 0) { } let f = () => ({}()); +let a = () => ({} instanceof a); " `; diff --git a/tests/arrows/arrow_function_expression.js b/tests/arrows/arrow_function_expression.js index 0b6e3bac..71251bea 100644 --- a/tests/arrows/arrow_function_expression.js +++ b/tests/arrows/arrow_function_expression.js @@ -6,3 +6,4 @@ export default (() => {})(); new (() => {}); if ((() => {}) ? 1 : 0) {} let f = () => ({}()) +let a = () => ({} instanceof a);