Wrap ternaries in Flow typecasts in parens (#3940)

* Wrap TypeCastExpression in parens

* Tests
This commit is contained in:
Jed Fox authored and GitHub committed 2018-02-14 11:19:39 +00:00
1 parent 87ed835095
commit 78a4f51662
5 files changed
+34

No files matched your search

+1
View File
@@ -560,6 +560,7 @@ FastPath.prototype.needsParens = function(options) {
case "AwaitExpression":
case "JSXSpreadAttribute":
case "TSTypeAssertionExpression":
case "TypeCastExpression":
case "TSAsExpression":
case "TSNonNullExpression":
return true;
@@ -0,0 +1,25 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`expression.js 1`] = `
let x: string = (foo: string);
// https://github.com/prettier/prettier/issues/3936
const foo = ((1?2:3): number);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
let x: string = (foo: string);
// https://github.com/prettier/prettier/issues/3936
const foo = ((1 ? 2 : 3): number);
`;
exports[`statement.js 1`] = `
foo: string;
bar: number;
(foo.bar: SomeType);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
foo: string;
bar: number;
(foo.bar: SomeType);
`;
+4
View File
@@ -0,0 +1,4 @@
let x: string = (foo: string);
// https://github.com/prettier/prettier/issues/3936
const foo = ((1?2:3): number);
+1
View File
@@ -0,0 +1 @@
run_spec(__dirname, ["flow", "babylon"]);
+3
View File
@@ -0,0 +1,3 @@
foo: string;
bar: number;
(foo.bar: SomeType);