Fix binary expression instanceof in arrow function expression (#913)

* Add fix for parens of BinaryExpression with instanceof op embedded into ArrowFunctionExpression.

* Add new test 🚀.
master
Davy Duperron 2017-03-06 12:44:48 +01:00 committed by Christopher Chedeau
parent b91d6384a6
commit 4dde054bb3
3 changed files with 10 additions and 0 deletions

View File

@ -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":

View File

@ -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);
"
`;

View File

@ -6,3 +6,4 @@ export default (() => {})();
new (() => {});
if ((() => {}) ? 1 : 0) {}
let f = () => ({}())
let a = () => ({} instanceof a);