diff --git a/src/fast-path.js b/src/fast-path.js index 7d6b82a1..255f2cc1 100644 --- a/src/fast-path.js +++ b/src/fast-path.js @@ -305,7 +305,7 @@ FastPath.prototype.needsParens = function(options) { case "BinaryExpression": case "LogicalExpression": { - if (!node.operator) { + if (!node.operator && node.type !== "TSTypeAssertionExpression") { return true; } diff --git a/tests/typescript_cast/__snapshots__/jsfmt.spec.js.snap b/tests/typescript_cast/__snapshots__/jsfmt.spec.js.snap index d2810f32..d7636493 100644 --- a/tests/typescript_cast/__snapshots__/jsfmt.spec.js.snap +++ b/tests/typescript_cast/__snapshots__/jsfmt.spec.js.snap @@ -3,8 +3,18 @@ exports[`parenthesis.ts 1`] = ` (a ? b : c); (() => {}); + +a || {}; +a && []; +true || a; +a + b; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ (a ? b : c); (() => {}); +a || {}; +a && []; +true || a; +a + b; + `; diff --git a/tests/typescript_cast/parenthesis.ts b/tests/typescript_cast/parenthesis.ts index fd356da4..38808d55 100644 --- a/tests/typescript_cast/parenthesis.ts +++ b/tests/typescript_cast/parenthesis.ts @@ -1,2 +1,7 @@ (a ? b : c); (() => {}); + +a || {}; +a && []; +true || a; +a + b;