Wrap ternaries in Flow typecasts in parens (#3940)
* Wrap TypeCastExpression in parens * Testsmaster
parent
87ed835095
commit
78a4f51662
|
@ -560,6 +560,7 @@ FastPath.prototype.needsParens = function(options) {
|
||||||
case "AwaitExpression":
|
case "AwaitExpression":
|
||||||
case "JSXSpreadAttribute":
|
case "JSXSpreadAttribute":
|
||||||
case "TSTypeAssertionExpression":
|
case "TSTypeAssertionExpression":
|
||||||
|
case "TypeCastExpression":
|
||||||
case "TSAsExpression":
|
case "TSAsExpression":
|
||||||
case "TSNonNullExpression":
|
case "TSNonNullExpression":
|
||||||
return true;
|
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);
|
||||||
|
|
||||||
|
`;
|
|
@ -0,0 +1,4 @@
|
||||||
|
let x: string = (foo: string);
|
||||||
|
|
||||||
|
// https://github.com/prettier/prettier/issues/3936
|
||||||
|
const foo = ((1?2:3): number);
|
|
@ -0,0 +1 @@
|
||||||
|
run_spec(__dirname, ["flow", "babylon"]);
|
|
@ -0,0 +1,3 @@
|
||||||
|
foo: string;
|
||||||
|
bar: number;
|
||||||
|
(foo.bar: SomeType);
|
Loading…
Reference in New Issue