Remove parens for type assertions in binary expressions, fixes #2416 (#2419)

master
Lucas Azzola 2017-07-07 21:02:43 +10:00 committed by Christopher Chedeau
parent 19cd7d3227
commit 8bbbc3a6f3
3 changed files with 16 additions and 1 deletions

View File

@ -305,7 +305,7 @@ FastPath.prototype.needsParens = function(options) {
case "BinaryExpression":
case "LogicalExpression": {
if (!node.operator) {
if (!node.operator && node.type !== "TSTypeAssertionExpression") {
return true;
}

View File

@ -3,8 +3,18 @@
exports[`parenthesis.ts 1`] = `
<DocumentHighlightKind>(a ? b : c);
<any>(() => {});
<x>a || {};
<x>a && [];
true || <x>a;
<x>a + <x>b;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<DocumentHighlightKind>(a ? b : c);
<any>(() => {});
<x>a || {};
<x>a && [];
true || <x>a;
<x>a + <x>b;
`;

View File

@ -1,2 +1,7 @@
<DocumentHighlightKind>(a ? b : c);
<any>(() => {});
<x>a || {};
<x>a && [];
true || <x>a;
<x>a + <x>b;