Print parens around type assertion as LHS in assignment, fixes #2521 (#2525)

master
Lucas Azzola 2017-07-20 23:16:15 +10:00 committed by GitHub
parent 1c9962df67
commit 4a0e9475df
5 changed files with 16 additions and 0 deletions

View File

@ -304,6 +304,13 @@ FastPath.prototype.needsParens = function(options) {
case "MemberExpression":
return name === "object" && parent.object === node;
case "AssignmentExpression":
return (
parent.left === node &&
(node.type === "TSTypeAssertionExpression" ||
node.type === "TSAsExpression")
);
case "BinaryExpression":
case "LogicalExpression": {
if (!node.operator && node.type !== "TSTypeAssertionExpression") {

View File

@ -21,6 +21,8 @@ const state = JSON.stringify({
next: window.location.href,
nonce,
} as State);
(foo.bar as Baz) = [bar];
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
const name = (description as DescriptionObject).name || (description as string);
this.isTabActionBar((e.target || e.srcElement) as HTMLElement);
@ -47,4 +49,6 @@ const state = JSON.stringify({
nonce
} as State);
(foo.bar as Baz) = [bar];
`;

View File

@ -18,3 +18,5 @@ const state = JSON.stringify({
next: window.location.href,
nonce,
} as State);
(foo.bar as Baz) = [bar];

View File

@ -51,6 +51,7 @@ exports[`parenthesis.ts 1`] = `
<x>a && [];
true || <x>a;
<x>a + <x>b;
(<x>a) = 1;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<DocumentHighlightKind>(a ? b : c);
<any>(() => {});
@ -59,5 +60,6 @@ true || <x>a;
<x>a && [];
true || <x>a;
<x>a + <x>b;
(<x>a) = 1;
`;

View File

@ -5,3 +5,4 @@
<x>a && [];
true || <x>a;
<x>a + <x>b;
(<x>a) = 1;