Wrap ternaries in Flow typecasts in parens (#3940)

* Wrap TypeCastExpression in parens

* Tests
master
Jed Fox 2018-02-14 11:19:39 +00:00 committed by GitHub
parent 87ed835095
commit 78a4f51662
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 34 additions and 0 deletions

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;

View File

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

View File

@ -0,0 +1,4 @@
let x: string = (foo: string);
// https://github.com/prettier/prettier/issues/3936
const foo = ((1?2:3): number);

View File

@ -0,0 +1 @@
run_spec(__dirname, ["flow", "babylon"]);

View File

@ -0,0 +1,3 @@
foo: string;
bar: number;
(foo.bar: SomeType);