1 parent
dc52a71923
commit
eeae443b43
7 files changed
+119
-23
No files matched your search
+15
-19
@@ -959,21 +959,20 @@ function genericPrintNoParens(path, options, print) {
|
||||
]);
|
||||
case "IfStatement":
|
||||
const con = adjustClause(path.call(print, "consequent"), options);
|
||||
|
||||
parts = [
|
||||
const opening = group(concat([
|
||||
"if (",
|
||||
group(
|
||||
concat([
|
||||
indent(
|
||||
options.tabWidth,
|
||||
concat([softline, path.call(print, "test")])
|
||||
),
|
||||
softline
|
||||
])
|
||||
),
|
||||
group(concat([
|
||||
indent(
|
||||
options.tabWidth,
|
||||
concat([softline, path.call(print, "test")])
|
||||
),
|
||||
softline
|
||||
])),
|
||||
")",
|
||||
con
|
||||
];
|
||||
]));
|
||||
|
||||
parts.push(opening);
|
||||
|
||||
if (n.alternate) {
|
||||
const hasBraces = isCurlyBracket(con);
|
||||
@@ -982,22 +981,19 @@ function genericPrintNoParens(path, options, print) {
|
||||
if (hasBraces && !isEmpty) {
|
||||
parts.push(" else");
|
||||
} else {
|
||||
// We use `conditionalGroup` to suppress break propagation.
|
||||
// This allows us to provide a hardline without forcing the
|
||||
// entire `if` clause to break up.
|
||||
parts.push(conditionalGroup([concat([hardline, "else"])]));
|
||||
parts.push(hardline, "else");
|
||||
}
|
||||
|
||||
parts.push(
|
||||
adjustClause(
|
||||
group(adjustClause(
|
||||
path.call(print, "alternate"),
|
||||
options,
|
||||
n.alternate.type === "IfStatement"
|
||||
)
|
||||
))
|
||||
);
|
||||
}
|
||||
|
||||
return group(concat(parts));
|
||||
return concat(parts);
|
||||
case "ForStatement": {
|
||||
const body = adjustClause(path.call(print, "body"), options);
|
||||
|
||||
|
||||
@@ -2506,8 +2506,7 @@ type Breakfast = Apple | Orange | Broccoli | Carrot;
|
||||
function bar(x: Breakfast) {
|
||||
if (x.kind === \\"Fruit\\") {
|
||||
(x.taste: \\"Good\\");
|
||||
} else // error, Apple.taste = Bad
|
||||
(x.raw: \\"No\\"); // error, Carrot.raw = Maybe
|
||||
} else (x.raw: \\"No\\"); // error, Apple.taste = Bad // error, Carrot.raw = Maybe
|
||||
}
|
||||
|
||||
function qux(x: Breakfast) {
|
||||
|
||||
@@ -19,8 +19,7 @@ function foo(x: ?string): $NonMaybeType<?string> {
|
||||
function foo(x: ?string): $NonMaybeType<?string> {
|
||||
if (x != null) {
|
||||
return x;
|
||||
} else
|
||||
return 0; // this should be an error
|
||||
} else return 0; // this should be an error
|
||||
}
|
||||
|
||||
//(foo(): string); // should not be necessary to expose the error above
|
||||
|
||||
+84
@@ -1,5 +1,89 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`else.js 1`] = `
|
||||
"// Both functions below should be formatted exactly the same
|
||||
|
||||
function f() {
|
||||
if (position)
|
||||
return {name: pair};
|
||||
else
|
||||
return {name: pair.substring(0, position), value: pair.substring(position + 1)};
|
||||
}
|
||||
|
||||
function f() {
|
||||
if (position)
|
||||
return {name: pair};
|
||||
else
|
||||
return {
|
||||
name: pair.substring(0, position),
|
||||
value: pair.substring(position + 1)
|
||||
};
|
||||
}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// Both functions below should be formatted exactly the same
|
||||
|
||||
function f() {
|
||||
if (position) return { name: pair };
|
||||
else
|
||||
return {
|
||||
name: pair.substring(0, position),
|
||||
value: pair.substring(position + 1)
|
||||
};
|
||||
}
|
||||
|
||||
function f() {
|
||||
if (position) return { name: pair };
|
||||
else
|
||||
return {
|
||||
name: pair.substring(0, position),
|
||||
value: pair.substring(position + 1)
|
||||
};
|
||||
}
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`else.js 2`] = `
|
||||
"// Both functions below should be formatted exactly the same
|
||||
|
||||
function f() {
|
||||
if (position)
|
||||
return {name: pair};
|
||||
else
|
||||
return {name: pair.substring(0, position), value: pair.substring(position + 1)};
|
||||
}
|
||||
|
||||
function f() {
|
||||
if (position)
|
||||
return {name: pair};
|
||||
else
|
||||
return {
|
||||
name: pair.substring(0, position),
|
||||
value: pair.substring(position + 1)
|
||||
};
|
||||
}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// Both functions below should be formatted exactly the same
|
||||
|
||||
function f() {
|
||||
if (position) return { name: pair };
|
||||
else
|
||||
return {
|
||||
name: pair.substring(0, position),
|
||||
value: pair.substring(position + 1)
|
||||
};
|
||||
}
|
||||
|
||||
function f() {
|
||||
if (position) return { name: pair };
|
||||
else
|
||||
return {
|
||||
name: pair.substring(0, position),
|
||||
value: pair.substring(position + 1)
|
||||
};
|
||||
}
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`if_comments.js 1`] = `
|
||||
"async function f() {
|
||||
if (untrackedChoice === 0) /* Cancel */ {
|
||||
@@ -0,0 +1,18 @@
|
||||
// Both functions below should be formatted exactly the same
|
||||
|
||||
function f() {
|
||||
if (position)
|
||||
return {name: pair};
|
||||
else
|
||||
return {name: pair.substring(0, position), value: pair.substring(position + 1)};
|
||||
}
|
||||
|
||||
function f() {
|
||||
if (position)
|
||||
return {name: pair};
|
||||
else
|
||||
return {
|
||||
name: pair.substring(0, position),
|
||||
value: pair.substring(position + 1)
|
||||
};
|
||||
}
|
||||
File renamed without changes.
File renamed without changes.
Reference in new issue
Block a user