Improve if/else printing and other clauses
This commit is contained in:
1 parent
fc186c8df8
commit
fcd5436b38
20 files changed
+262
-385
No files matched your search
+29
-16
@@ -860,13 +860,6 @@ function genericPrintNoParens(path, options, print) {
|
||||
") ",
|
||||
path.call(print, "body")
|
||||
]);
|
||||
// var con = adjustClause(path.call(print, "consequent"), options),
|
||||
// parts = ["if (", path.call(print, "test"), ")", con];
|
||||
// if (n.alternate)
|
||||
// parts.push(
|
||||
// endsWithBrace(con) ? " else" : "\nelse",
|
||||
// adjustClause(path.call(print, "alternate"), options));
|
||||
// return concat(parts);
|
||||
case "IfStatement":
|
||||
const con = adjustClause(path.call(print, "consequent"), options);
|
||||
|
||||
@@ -884,15 +877,25 @@ function genericPrintNoParens(path, options, print) {
|
||||
];
|
||||
|
||||
if (n.alternate) {
|
||||
const hasBraces = getFirstString(con) === "{";
|
||||
const hasBraces = isCurlyBracket(con);
|
||||
const isEmpty = isEmptyBlock(con);
|
||||
|
||||
parts.push((hasBraces ? " else" : "\nelse"), adjustClause(
|
||||
path.call(print, "alternate"),
|
||||
options
|
||||
));
|
||||
if (hasBraces && !isEmpty) {
|
||||
parts.push(" else");
|
||||
} else {
|
||||
parts.push(concat([hardline, "else"]));
|
||||
}
|
||||
|
||||
parts.push(
|
||||
adjustClause(
|
||||
path.call(print, "alternate"),
|
||||
options,
|
||||
n.alternate.type === "IfStatement"
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return concat(parts);
|
||||
return group(concat(parts));
|
||||
case "ForStatement":
|
||||
// TODO Get the for (;;) case right.
|
||||
return concat([
|
||||
@@ -952,7 +955,7 @@ function genericPrintNoParens(path, options, print) {
|
||||
var clause = adjustClause(path.call(print, "body"), options);
|
||||
var doBody = concat([ "do", clause ]);
|
||||
var parts = [ doBody ];
|
||||
const hasBraces = getFirstString(clause) === "{";
|
||||
const hasBraces = isCurlyBracket(clause);
|
||||
|
||||
if (hasBraces)
|
||||
parts.push(" while");
|
||||
@@ -1898,14 +1901,24 @@ function printClass(path, print) {
|
||||
return parts;
|
||||
}
|
||||
|
||||
function adjustClause(clause, options) {
|
||||
if (getFirstString(clause) === "{") {
|
||||
function adjustClause(clause, options, forceSpace) {
|
||||
if (isCurlyBracket(clause) || forceSpace) {
|
||||
return concat([ " ", clause ]);
|
||||
}
|
||||
|
||||
return indent(options.tabWidth, concat([ hardline, clause ]));
|
||||
}
|
||||
|
||||
function isCurlyBracket(doc) {
|
||||
const str = getFirstString(doc);
|
||||
return str === "{" || str === "{}";
|
||||
}
|
||||
|
||||
function isEmptyBlock(doc) {
|
||||
const str = getFirstString(doc);
|
||||
return str === "{}";
|
||||
}
|
||||
|
||||
function lastNonSpaceCharacter(lines) {
|
||||
var pos = lines.lastPos();
|
||||
do {
|
||||
|
||||
@@ -118,14 +118,11 @@ let tests = [
|
||||
false in [];
|
||||
},
|
||||
function() {
|
||||
if (\"foo\" in 123)
|
||||
{}
|
||||
if (\"foo\" in 123) {}
|
||||
|
||||
if (!\"foo\" in {})
|
||||
{}
|
||||
if (!\"foo\" in {}) {}
|
||||
|
||||
if (!(\"foo\" in {}))
|
||||
{}
|
||||
if (!(\"foo\" in {})) {}
|
||||
},
|
||||
function(x: Object, y: mixed) {
|
||||
\"foo\" in x;
|
||||
|
||||
@@ -705,43 +705,37 @@ function try_scope() {
|
||||
function for_scope_let() {
|
||||
let a: number = 0;
|
||||
|
||||
for (let a = \"\"; ; )
|
||||
{}
|
||||
for (let a = \"\"; ; ) {}
|
||||
}
|
||||
|
||||
function for_scope_var() {
|
||||
var a: number = 0;
|
||||
|
||||
for (var a = \"\"; ; )
|
||||
{}
|
||||
for (var a = \"\"; ; ) {}
|
||||
}
|
||||
|
||||
function for_in_scope_let(o: Object) {
|
||||
let a: number = 0;
|
||||
|
||||
for (let a in o)
|
||||
{}
|
||||
for (let a in o) {}
|
||||
}
|
||||
|
||||
function for_in_scope_var(o: Object) {
|
||||
var a: number = 0;
|
||||
|
||||
for (var a in o)
|
||||
{}
|
||||
for (var a in o) {}
|
||||
}
|
||||
|
||||
function for_of_scope_let(xs: string[]) {
|
||||
let a: number = 0;
|
||||
|
||||
for (let a of xs)
|
||||
{}
|
||||
for (let a of xs) {}
|
||||
}
|
||||
|
||||
function for_of_scope_var(xs: string[]) {
|
||||
var a: number = 0;
|
||||
|
||||
for (var a of xs)
|
||||
{}
|
||||
for (var a of xs) {}
|
||||
}
|
||||
|
||||
function default_param_1() {
|
||||
|
||||
@@ -192,32 +192,23 @@ a.delete(\"xx\");
|
||||
|
||||
a.delete(3);
|
||||
|
||||
for (let x: string of a.keys())
|
||||
{}
|
||||
for (let x: string of a.keys()) {}
|
||||
|
||||
for (let x: number of a.keys())
|
||||
{}
|
||||
for (let x: number of a.keys()) {}
|
||||
|
||||
for (let x: string | File of a.values())
|
||||
{}
|
||||
for (let x: string | File of a.values()) {}
|
||||
|
||||
for (let x: string | File | Blob of a.values())
|
||||
{}
|
||||
for (let x: string | File | Blob of a.values()) {}
|
||||
|
||||
for (let [ x, y ]: [string, string | File] of a.entries())
|
||||
{}
|
||||
for (let [ x, y ]: [string, string | File] of a.entries()) {}
|
||||
|
||||
for (let [ x, y ]: [string, string | File | Blob] of a.entries())
|
||||
{}
|
||||
for (let [ x, y ]: [string, string | File | Blob] of a.entries()) {}
|
||||
|
||||
for (let [ x, y ]: [number, string] of a.entries())
|
||||
{}
|
||||
for (let [ x, y ]: [number, string] of a.entries()) {}
|
||||
|
||||
for (let [ x, y ]: [string, number] of a.entries())
|
||||
{}
|
||||
for (let [ x, y ]: [string, number] of a.entries()) {}
|
||||
|
||||
for (let [ x, y ]: [number, number] of a.entries())
|
||||
{}
|
||||
for (let [ x, y ]: [number, number] of a.entries()) {}
|
||||
"
|
||||
`;
|
||||
|
||||
|
||||
@@ -313,17 +313,15 @@ function h(x: number | string | boolean) {
|
||||
call_me = () => {
|
||||
var y: number = const_x;
|
||||
};
|
||||
} else
|
||||
if (typeof const_x == \"string\") {
|
||||
call_me = () => {
|
||||
var y: string = const_x;
|
||||
};
|
||||
} else
|
||||
if (typeof const_x == \"boolean\") {
|
||||
call_me = () => {
|
||||
var y: boolean = const_x;
|
||||
};
|
||||
}
|
||||
} else if (typeof const_x == \"string\") {
|
||||
call_me = () => {
|
||||
var y: string = const_x;
|
||||
};
|
||||
} else if (typeof const_x == \"boolean\") {
|
||||
call_me = () => {
|
||||
var y: boolean = const_x;
|
||||
};
|
||||
}
|
||||
|
||||
var var_x = x;
|
||||
|
||||
@@ -331,17 +329,15 @@ function h(x: number | string | boolean) {
|
||||
call_me = () => {
|
||||
var y: number = var_x;
|
||||
};
|
||||
} else
|
||||
if (typeof var_x == \"string\") {
|
||||
call_me = () => {
|
||||
var y: string = var_x;
|
||||
};
|
||||
} else
|
||||
if (typeof var_x == \"boolean\") {
|
||||
call_me = () => {
|
||||
var y: boolean = var_x;
|
||||
};
|
||||
}
|
||||
} else if (typeof var_x == \"string\") {
|
||||
call_me = () => {
|
||||
var y: string = var_x;
|
||||
};
|
||||
} else if (typeof var_x == \"boolean\") {
|
||||
call_me = () => {
|
||||
var y: boolean = var_x;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
call_me();
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
exports[`test errors.js 1`] = `
|
||||
"if (typeof define === \'function\' && define.amd) { }
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
if (typeof define === \"function\" && define.amd)
|
||||
{}
|
||||
if (typeof define === \"function\" && define.amd) {}
|
||||
"
|
||||
`;
|
||||
@@ -180,14 +180,11 @@ class GeneratorExamples {
|
||||
*widen_next() {
|
||||
var x = yield 0;
|
||||
|
||||
if (typeof x === \"number\")
|
||||
{}
|
||||
else
|
||||
if (typeof x === \"boolean\")
|
||||
{}
|
||||
else {
|
||||
(x: string);
|
||||
}
|
||||
if (typeof x === \"number\") {}
|
||||
else if (typeof x === \"boolean\") {}
|
||||
else {
|
||||
(x: string);
|
||||
}
|
||||
}
|
||||
*widen_yield() {
|
||||
yield 0;
|
||||
@@ -244,14 +241,11 @@ for (var x of examples.infer_stmt()) {
|
||||
|
||||
var infer_stmt_next = examples.infer_stmt().next(0).value;
|
||||
|
||||
if (typeof infer_stmt_next === \"undefined\")
|
||||
{}
|
||||
else
|
||||
if (typeof infer_stmt_next === \"number\")
|
||||
{}
|
||||
if (typeof infer_stmt_next === \"undefined\") {}
|
||||
else if (typeof infer_stmt_next === \"number\") {}
|
||||
else {
|
||||
(infer_stmt_next: boolean);
|
||||
}
|
||||
(infer_stmt_next: boolean);
|
||||
}
|
||||
|
||||
examples.widen_next().next(0);
|
||||
|
||||
@@ -260,14 +254,11 @@ examples.widen_next().next(\"\");
|
||||
examples.widen_next().next(true);
|
||||
|
||||
for (var x of examples.widen_yield()) {
|
||||
if (typeof x === \"number\")
|
||||
{}
|
||||
else
|
||||
if (typeof x === \"boolean\")
|
||||
{}
|
||||
else {
|
||||
(x: string);
|
||||
}
|
||||
if (typeof x === \"number\") {}
|
||||
else if (typeof x === \"boolean\") {}
|
||||
else {
|
||||
(x: string);
|
||||
}
|
||||
}
|
||||
|
||||
examples.delegate_next_generator().next(\"\");
|
||||
@@ -325,14 +316,11 @@ for (var x of examples.infer_stmt()) {
|
||||
|
||||
var infer_stmt_next = examples.infer_stmt().next(0).value;
|
||||
|
||||
if (typeof infer_stmt_next === \"undefined\")
|
||||
{}
|
||||
else
|
||||
if (typeof infer_stmt_next === \"number\")
|
||||
{}
|
||||
if (typeof infer_stmt_next === \"undefined\") {}
|
||||
else if (typeof infer_stmt_next === \"number\") {}
|
||||
else {
|
||||
(infer_stmt_next: boolean);
|
||||
}
|
||||
(infer_stmt_next: boolean);
|
||||
}
|
||||
"
|
||||
`;
|
||||
|
||||
@@ -525,26 +513,20 @@ for (var x of infer_stmt()) {
|
||||
|
||||
var infer_stmt_next = infer_stmt().next(0).value;
|
||||
|
||||
if (typeof infer_stmt_next === \"undefined\")
|
||||
{}
|
||||
else
|
||||
if (typeof infer_stmt_next === \"number\")
|
||||
{}
|
||||
if (typeof infer_stmt_next === \"undefined\") {}
|
||||
else if (typeof infer_stmt_next === \"number\") {}
|
||||
else {
|
||||
(infer_stmt_next: boolean);
|
||||
}
|
||||
(infer_stmt_next: boolean);
|
||||
}
|
||||
|
||||
function* widen_next() {
|
||||
var x = yield 0;
|
||||
|
||||
if (typeof x === \"number\")
|
||||
{}
|
||||
else
|
||||
if (typeof x === \"boolean\")
|
||||
{}
|
||||
else {
|
||||
(x: string);
|
||||
}
|
||||
if (typeof x === \"number\") {}
|
||||
else if (typeof x === \"boolean\") {}
|
||||
else {
|
||||
(x: string);
|
||||
}
|
||||
}
|
||||
|
||||
widen_next().next(0);
|
||||
@@ -562,14 +544,11 @@ function* widen_yield() {
|
||||
}
|
||||
|
||||
for (var x of widen_yield()) {
|
||||
if (typeof x === \"number\")
|
||||
{}
|
||||
else
|
||||
if (typeof x === \"boolean\")
|
||||
{}
|
||||
else {
|
||||
(x: string);
|
||||
}
|
||||
if (typeof x === \"number\") {}
|
||||
else if (typeof x === \"boolean\") {}
|
||||
else {
|
||||
(x: string);
|
||||
}
|
||||
}
|
||||
|
||||
function* delegate_next_generator() {
|
||||
|
||||
@@ -113,7 +113,7 @@ function consumer1(b) {
|
||||
|
||||
if (g instanceof X2)
|
||||
g.foo = \"1337\";
|
||||
else
|
||||
else
|
||||
g.foo = 1337;
|
||||
}
|
||||
|
||||
@@ -140,7 +140,7 @@ function consumer3(b) {
|
||||
|
||||
if (g.bar instanceof X2)
|
||||
g.bar.foo = \"1337\";
|
||||
else
|
||||
else
|
||||
g.bar.foo = 1337;
|
||||
}
|
||||
|
||||
@@ -167,7 +167,7 @@ function consumer5(b) {
|
||||
|
||||
if (g.baz.bar instanceof X2)
|
||||
g.baz.bar.foo = \"1337\";
|
||||
else
|
||||
else
|
||||
g.baz.bar.foo = 1337;
|
||||
}
|
||||
|
||||
@@ -182,7 +182,7 @@ class C {
|
||||
m() {
|
||||
if (this instanceof D)
|
||||
alert(this.s);
|
||||
else
|
||||
else
|
||||
alert(\"nope\");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,7 +81,6 @@ for (var x in null) {
|
||||
foo(x);
|
||||
}
|
||||
|
||||
for (var y in this)
|
||||
{}
|
||||
for (var y in this) {}
|
||||
"
|
||||
`;
|
||||
@@ -21,7 +21,6 @@ a.delete(\"foobar\");
|
||||
|
||||
var b = undefined;
|
||||
|
||||
if (undefined)
|
||||
{}
|
||||
if (undefined) {}
|
||||
"
|
||||
`;
|
||||
@@ -111,8 +111,7 @@ function goofy() {
|
||||
|
||||
if (typeof x == \"function\") {
|
||||
x();
|
||||
} else
|
||||
{}
|
||||
} else {}
|
||||
}
|
||||
|
||||
function goofy2() {
|
||||
@@ -126,8 +125,7 @@ function goofy2() {
|
||||
|
||||
if (typeof y == \"function\") {
|
||||
y();
|
||||
} else
|
||||
{}
|
||||
} else {}
|
||||
}
|
||||
|
||||
module.exports = true;
|
||||
@@ -252,8 +250,7 @@ class D {
|
||||
}
|
||||
|
||||
function baz(x: D) {
|
||||
if (x instanceof A)
|
||||
{}
|
||||
if (x instanceof A) {}
|
||||
}
|
||||
|
||||
module.exports = \"sigma\";
|
||||
|
||||
@@ -67,15 +67,13 @@ if (m.bind(o)) {
|
||||
class D {
|
||||
m: Function;
|
||||
n() {
|
||||
if (this.m({}))
|
||||
{}
|
||||
if (this.m({})) {}
|
||||
}
|
||||
}
|
||||
declare var m: Function;
|
||||
const x = \"\";
|
||||
|
||||
if (m.bind(this)(x))
|
||||
{}
|
||||
if (m.bind(this)(x)) {}
|
||||
"
|
||||
`;
|
||||
|
||||
@@ -246,8 +244,7 @@ function f(_this: { m: ?Meeting }): string {
|
||||
return \"0\";
|
||||
}
|
||||
|
||||
if (_this.m.es.some(a => a.fbid === 0))
|
||||
{}
|
||||
if (_this.m.es.some(a => a.fbid === 0)) {}
|
||||
|
||||
return \"3\";
|
||||
}
|
||||
|
||||
@@ -95,9 +95,8 @@ var tests = [
|
||||
}
|
||||
},
|
||||
function() {
|
||||
if (x == null)
|
||||
{}
|
||||
else {
|
||||
if (x == null) {}
|
||||
else {
|
||||
var y: string = x;
|
||||
}
|
||||
},
|
||||
@@ -108,22 +107,19 @@ else {
|
||||
var y: string = x;
|
||||
},
|
||||
function() {
|
||||
if (!(x != null))
|
||||
{}
|
||||
else {
|
||||
if (!(x != null)) {}
|
||||
else {
|
||||
var y: string = x;
|
||||
}
|
||||
},
|
||||
function() {
|
||||
if (x != null)
|
||||
{}
|
||||
if (x != null) {}
|
||||
|
||||
var y: string = x;
|
||||
},
|
||||
function() {
|
||||
if (x != null)
|
||||
{}
|
||||
else {
|
||||
if (x != null) {}
|
||||
else {
|
||||
var y: string = x;
|
||||
}
|
||||
},
|
||||
@@ -425,9 +421,8 @@ var tests = [
|
||||
function() {
|
||||
var x: { p: ?string } = { p: \"xxx\" };
|
||||
|
||||
if (x.p == null)
|
||||
{}
|
||||
else {
|
||||
if (x.p == null) {}
|
||||
else {
|
||||
var y: string = x.p;
|
||||
}
|
||||
},
|
||||
@@ -442,9 +437,8 @@ else {
|
||||
function() {
|
||||
var x: { p: ?string } = { p: \"xxx\" };
|
||||
|
||||
if (!(x.p != null))
|
||||
{}
|
||||
else {
|
||||
if (!(x.p != null)) {}
|
||||
else {
|
||||
var y: string = x.p;
|
||||
}
|
||||
},
|
||||
@@ -469,17 +463,15 @@ else {
|
||||
function() {
|
||||
var x: { p: ?string } = { p: \"xxx\" };
|
||||
|
||||
if (x.p != null)
|
||||
{}
|
||||
if (x.p != null) {}
|
||||
|
||||
var y: string = x.p;
|
||||
},
|
||||
function() {
|
||||
var x: { p: ?string } = { p: \"xxx\" };
|
||||
|
||||
if (x.p != null)
|
||||
{}
|
||||
else {
|
||||
if (x.p != null) {}
|
||||
else {
|
||||
var y: string = x.p;
|
||||
}
|
||||
},
|
||||
@@ -512,9 +504,8 @@ else {
|
||||
function() {
|
||||
var x: { y: ?string } = { y: null };
|
||||
|
||||
if (x.y)
|
||||
{}
|
||||
else {
|
||||
if (x.y) {}
|
||||
else {
|
||||
x.y = \"foo\";
|
||||
}
|
||||
|
||||
@@ -554,10 +545,9 @@ else {
|
||||
|
||||
if (typeof x.y == \"number\") {
|
||||
x.y = \"foo\";
|
||||
} else
|
||||
if (typeof x.y == \"boolean\") {
|
||||
x.y = \"bar\";
|
||||
}
|
||||
} else if (typeof x.y == \"boolean\") {
|
||||
x.y = \"bar\";
|
||||
}
|
||||
|
||||
(x.y: boolean);
|
||||
},
|
||||
@@ -613,14 +603,12 @@ else {
|
||||
(x.y: string);
|
||||
},
|
||||
function(x: string) {
|
||||
if (x === \"a\")
|
||||
{}
|
||||
if (x === \"a\") {}
|
||||
|
||||
(x: \"b\");
|
||||
},
|
||||
function(x: mixed) {
|
||||
if (typeof x.bar === \"string\")
|
||||
{}
|
||||
if (typeof x.bar === \"string\") {}
|
||||
|
||||
(x: string & number);
|
||||
},
|
||||
@@ -628,8 +616,7 @@ else {
|
||||
let x: { foo: ?string } = { foo: null };
|
||||
|
||||
if (!x.foo) {
|
||||
if (false)
|
||||
{}
|
||||
if (false) {}
|
||||
|
||||
x.foo = \"foo\";
|
||||
}
|
||||
@@ -640,8 +627,7 @@ else {
|
||||
let x: { foo: ?string } = { foo: null };
|
||||
|
||||
if (!x.foo) {
|
||||
while (false)
|
||||
{}
|
||||
while (false) {}
|
||||
|
||||
x.foo = \"foo\";
|
||||
}
|
||||
@@ -652,8 +638,7 @@ else {
|
||||
let x: { foo: ?string } = { foo: null };
|
||||
|
||||
if (!x.foo) {
|
||||
for (var i = 0; i < 0; i++)
|
||||
{}
|
||||
for (var i = 0; i < 0; i++) {}
|
||||
|
||||
x.foo = \"foo\";
|
||||
}
|
||||
@@ -882,9 +867,8 @@ var paths = [
|
||||
function() {
|
||||
var x: ?string = \"xxx\";
|
||||
|
||||
if (x == null)
|
||||
{}
|
||||
else {
|
||||
if (x == null) {}
|
||||
else {
|
||||
var y: string = x;
|
||||
}
|
||||
},
|
||||
@@ -899,9 +883,8 @@ else {
|
||||
function() {
|
||||
var x: ?string = \"xxx\";
|
||||
|
||||
if (!(x != null))
|
||||
{}
|
||||
else {
|
||||
if (!(x != null)) {}
|
||||
else {
|
||||
var y: string = x;
|
||||
}
|
||||
},
|
||||
@@ -917,17 +900,15 @@ else {
|
||||
function() {
|
||||
var x: ?string = \"xxx\";
|
||||
|
||||
if (x != null)
|
||||
{}
|
||||
if (x != null) {}
|
||||
|
||||
var y: string = x;
|
||||
},
|
||||
function() {
|
||||
var x: ?string = \"xxx\";
|
||||
|
||||
if (x != null)
|
||||
{}
|
||||
else {
|
||||
if (x != null) {}
|
||||
else {
|
||||
var y: string = x;
|
||||
}
|
||||
},
|
||||
@@ -1169,27 +1150,24 @@ var null_tests = [
|
||||
function() {
|
||||
var x: ?string = \"xxx\";
|
||||
|
||||
if (x == null)
|
||||
{}
|
||||
else {
|
||||
if (x == null) {}
|
||||
else {
|
||||
var y: string = x;
|
||||
}
|
||||
},
|
||||
function() {
|
||||
var x: { p: ?string } = { p: \"xxx\" };
|
||||
|
||||
if (x.p == null)
|
||||
{}
|
||||
else {
|
||||
if (x.p == null) {}
|
||||
else {
|
||||
var y: string = x.p;
|
||||
}
|
||||
},
|
||||
function() {
|
||||
var x: { p: { q: ?string } } = { p: { q: \"xxx\" } };
|
||||
|
||||
if (x.p.q == null)
|
||||
{}
|
||||
else {
|
||||
if (x.p.q == null) {}
|
||||
else {
|
||||
var y: string = x.p.q;
|
||||
}
|
||||
},
|
||||
@@ -1217,27 +1195,24 @@ else {
|
||||
function() {
|
||||
var x: ?string = \"xxx\";
|
||||
|
||||
if (x === null)
|
||||
{}
|
||||
else {
|
||||
if (x === null) {}
|
||||
else {
|
||||
var y: string | void = x;
|
||||
}
|
||||
},
|
||||
function() {
|
||||
var x: { p: ?string } = { p: \"xxx\" };
|
||||
|
||||
if (x.p === null)
|
||||
{}
|
||||
else {
|
||||
if (x.p === null) {}
|
||||
else {
|
||||
var y: string | void = x.p;
|
||||
}
|
||||
},
|
||||
function() {
|
||||
var x: { p: { q: ?string } } = { p: { q: \"xxx\" } };
|
||||
|
||||
if (x.p.q === null)
|
||||
{}
|
||||
else {
|
||||
if (x.p.q === null) {}
|
||||
else {
|
||||
var y: string | void = x.p.q;
|
||||
}
|
||||
}
|
||||
@@ -1247,7 +1222,7 @@ class C {
|
||||
ensure0(): string {
|
||||
if (this.p != null)
|
||||
return this.p;
|
||||
else
|
||||
else
|
||||
return \"\";
|
||||
}
|
||||
ensure1(): string {
|
||||
@@ -1259,7 +1234,7 @@ else
|
||||
ensure2(): string | void {
|
||||
if (this.p !== null)
|
||||
return this.p;
|
||||
else
|
||||
else
|
||||
return \"\";
|
||||
}
|
||||
ensure3(): string | void {
|
||||
@@ -1273,13 +1248,13 @@ class D extends C {
|
||||
ensure100(): string {
|
||||
if (super.p != null)
|
||||
return super.p;
|
||||
else
|
||||
else
|
||||
return \"\";
|
||||
}
|
||||
ensure101(): string {
|
||||
if (super.p == null)
|
||||
return \"\";
|
||||
else
|
||||
else
|
||||
return super.p;
|
||||
}
|
||||
ensure103(): string {
|
||||
@@ -1623,27 +1598,24 @@ var null_tests = [
|
||||
function() {
|
||||
var x: ?string = \"xxx\";
|
||||
|
||||
if (typeof x != \"string\")
|
||||
{}
|
||||
else {
|
||||
if (typeof x != \"string\") {}
|
||||
else {
|
||||
var y: string = x;
|
||||
}
|
||||
},
|
||||
function() {
|
||||
var x: { p: ?string } = { p: \"xxx\" };
|
||||
|
||||
if (typeof x.p != \"string\")
|
||||
{}
|
||||
else {
|
||||
if (typeof x.p != \"string\") {}
|
||||
else {
|
||||
var y: string = x.p;
|
||||
}
|
||||
},
|
||||
function() {
|
||||
var x: { p: { q: ?string } } = { p: { q: \"xxx\" } };
|
||||
|
||||
if (typeof x.p.q != \"string\")
|
||||
{}
|
||||
else {
|
||||
if (typeof x.p.q != \"string\") {}
|
||||
else {
|
||||
var y: string = x.p.q;
|
||||
}
|
||||
},
|
||||
@@ -1671,27 +1643,24 @@ else {
|
||||
function() {
|
||||
var x: ?string = \"xxx\";
|
||||
|
||||
if (typeof x !== \"string\")
|
||||
{}
|
||||
else {
|
||||
if (typeof x !== \"string\") {}
|
||||
else {
|
||||
var y: string = x;
|
||||
}
|
||||
},
|
||||
function() {
|
||||
var x: { p: ?string } = { p: \"xxx\" };
|
||||
|
||||
if (typeof x.p !== \"string\")
|
||||
{}
|
||||
else {
|
||||
if (typeof x.p !== \"string\") {}
|
||||
else {
|
||||
var y: string = x.p;
|
||||
}
|
||||
},
|
||||
function() {
|
||||
var x: { p: { q: ?string } } = { p: { q: \"xxx\" } };
|
||||
|
||||
if (typeof x.p.q !== \"string\")
|
||||
{}
|
||||
else {
|
||||
if (typeof x.p.q !== \"string\") {}
|
||||
else {
|
||||
var y: string = x.p.q;
|
||||
}
|
||||
}
|
||||
@@ -1701,25 +1670,25 @@ class A {
|
||||
ensure0(): string {
|
||||
if (typeof this.p == \"string\")
|
||||
return this.p;
|
||||
else
|
||||
else
|
||||
return \"\";
|
||||
}
|
||||
ensure1(): string {
|
||||
if (typeof this.p != \"string\")
|
||||
return \"\";
|
||||
else
|
||||
else
|
||||
return this.p;
|
||||
}
|
||||
ensure2(): string | void {
|
||||
if (typeof this.p === \"string\")
|
||||
return this.p;
|
||||
else
|
||||
else
|
||||
return \"\";
|
||||
}
|
||||
ensure3(): string | void {
|
||||
if (typeof this.p !== \"string\")
|
||||
return \"\";
|
||||
else
|
||||
else
|
||||
return this.p;
|
||||
}
|
||||
}
|
||||
@@ -1845,27 +1814,24 @@ var undef_tests = [
|
||||
function() {
|
||||
var x: ?string = \"xxx\";
|
||||
|
||||
if (x === undefined || x === null)
|
||||
{}
|
||||
else {
|
||||
if (x === undefined || x === null) {}
|
||||
else {
|
||||
var y: string = x;
|
||||
}
|
||||
},
|
||||
function() {
|
||||
var x: { p: ?string } = { p: \"xxx\" };
|
||||
|
||||
if (x.p === undefined || x.p === null)
|
||||
{}
|
||||
else {
|
||||
if (x.p === undefined || x.p === null) {}
|
||||
else {
|
||||
var y: string = x.p;
|
||||
}
|
||||
},
|
||||
function() {
|
||||
var x: { p: { q: ?string } } = { p: { q: \"xxx\" } };
|
||||
|
||||
if (x.p.q === undefined || x.p.q === null)
|
||||
{}
|
||||
else {
|
||||
if (x.p.q === undefined || x.p.q === null) {}
|
||||
else {
|
||||
var y: string = x.p.q;
|
||||
}
|
||||
}
|
||||
@@ -1875,13 +1841,13 @@ class A {
|
||||
ensure0(): string {
|
||||
if (this.p !== undefined && this.p !== null)
|
||||
return this.p;
|
||||
else
|
||||
else
|
||||
return \"\";
|
||||
}
|
||||
ensure1(): string {
|
||||
if (this.p === undefined || this.p === null)
|
||||
return \"\";
|
||||
else
|
||||
else
|
||||
return this.p;
|
||||
}
|
||||
}
|
||||
@@ -2007,27 +1973,24 @@ var void_tests = [
|
||||
function() {
|
||||
var x: ?string = \"xxx\";
|
||||
|
||||
if (x === void 0 || x === null)
|
||||
{}
|
||||
else {
|
||||
if (x === void 0 || x === null) {}
|
||||
else {
|
||||
var y: string = x;
|
||||
}
|
||||
},
|
||||
function() {
|
||||
var x: { p: ?string } = { p: \"xxx\" };
|
||||
|
||||
if (x.p === void 0 || x.p === null)
|
||||
{}
|
||||
else {
|
||||
if (x.p === void 0 || x.p === null) {}
|
||||
else {
|
||||
var y: string = x.p;
|
||||
}
|
||||
},
|
||||
function() {
|
||||
var x: { p: { q: ?string } } = { p: { q: \"xxx\" } };
|
||||
|
||||
if (x.p.q === void 0 || x.p.q === null)
|
||||
{}
|
||||
else {
|
||||
if (x.p.q === void 0 || x.p.q === null) {}
|
||||
else {
|
||||
var y: string = x.p.q;
|
||||
}
|
||||
}
|
||||
@@ -2037,13 +2000,13 @@ class A {
|
||||
ensure0(): string {
|
||||
if (this.p !== void 0 && this.p !== null)
|
||||
return this.p;
|
||||
else
|
||||
else
|
||||
return \"\";
|
||||
}
|
||||
ensure1(): string {
|
||||
if (this.p === void 0 || this.p === null)
|
||||
return \"\";
|
||||
else
|
||||
else
|
||||
return this.p;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -390,29 +390,22 @@ let tests = [
|
||||
// ok
|
||||
let tests = [
|
||||
function(x: string, y: number) {
|
||||
if (x == y)
|
||||
{}
|
||||
if (x == y) {}
|
||||
|
||||
if (x === y)
|
||||
{}
|
||||
if (x === y) {}
|
||||
},
|
||||
function(x: string) {
|
||||
if (x == undefined)
|
||||
{}
|
||||
if (x == undefined) {}
|
||||
|
||||
if (x == void 0)
|
||||
{}
|
||||
if (x == void 0) {}
|
||||
},
|
||||
function(x: string) {
|
||||
if (x == null)
|
||||
{}
|
||||
if (x == null) {}
|
||||
},
|
||||
function(x: { y: \"foo\" } | { y: \"bar\" }) {
|
||||
if (x.y == 123)
|
||||
{}
|
||||
if (x.y == 123) {}
|
||||
|
||||
if (x.y === 123)
|
||||
{}
|
||||
if (x.y === 123) {}
|
||||
}
|
||||
];
|
||||
"
|
||||
@@ -869,30 +862,23 @@ function foo5() {
|
||||
}
|
||||
|
||||
function foo6(o: mixed) {
|
||||
if (o.bar)
|
||||
{}
|
||||
if (o.bar) {}
|
||||
}
|
||||
|
||||
function foo7(o: mixed) {
|
||||
if (typeof o.bar === \"string\")
|
||||
{}
|
||||
if (typeof o.bar === \"string\") {}
|
||||
|
||||
if (o && typeof o.bar === \"string\")
|
||||
{}
|
||||
if (o && typeof o.bar === \"string\") {}
|
||||
|
||||
if (o != null && typeof o.bar === \"string\")
|
||||
{}
|
||||
if (o != null && typeof o.bar === \"string\") {}
|
||||
|
||||
if (o !== null && o !== undefined && typeof o.bar === \"string\")
|
||||
{}
|
||||
if (o !== null && o !== undefined && typeof o.bar === \"string\") {}
|
||||
}
|
||||
|
||||
function foo8(o: { p: mixed }) {
|
||||
if (o.p && o.p.q)
|
||||
{}
|
||||
if (o.p && o.p.q) {}
|
||||
|
||||
if (o.p && o.p.q && o.p.q.r)
|
||||
{}
|
||||
if (o.p && o.p.q && o.p.q.r) {}
|
||||
}
|
||||
"
|
||||
`;
|
||||
@@ -1536,12 +1522,10 @@ let tests = [
|
||||
}
|
||||
},
|
||||
function(num: number, obj: { foo: number }) {
|
||||
if (num === obj.bar)
|
||||
{}
|
||||
if (num === obj.bar) {}
|
||||
},
|
||||
function(num: number, obj: { [key: string]: number }) {
|
||||
if (num === obj.bar)
|
||||
{}
|
||||
if (num === obj.bar) {}
|
||||
},
|
||||
function(n: number): Mode {
|
||||
if (n !== 0 && n !== 1 && n !== 2) {
|
||||
@@ -1553,10 +1537,9 @@ let tests = [
|
||||
function(s: number): ?Mode {
|
||||
if (s === 0) {
|
||||
return s;
|
||||
} else
|
||||
if (s === 3) {
|
||||
return s;
|
||||
}
|
||||
} else if (s === 3) {
|
||||
return s;
|
||||
}
|
||||
},
|
||||
function(mode: Mode) {
|
||||
switch (mode) {
|
||||
@@ -1928,15 +1911,13 @@ function waldo() {
|
||||
|
||||
function global_in_conditional0(x: number) {
|
||||
if (x != 0) {
|
||||
if (BAZ)
|
||||
{}
|
||||
if (BAZ) {}
|
||||
}
|
||||
}
|
||||
|
||||
function global_in_conditional2(x: number) {
|
||||
for (var i = 0; i < 100; i++) {
|
||||
if (BAZ)
|
||||
{}
|
||||
if (BAZ) {}
|
||||
}
|
||||
}
|
||||
"
|
||||
@@ -2166,12 +2147,10 @@ let tests = [
|
||||
}
|
||||
},
|
||||
function(str: string, obj: { foo: string }) {
|
||||
if (str === obj.bar)
|
||||
{}
|
||||
if (str === obj.bar) {}
|
||||
},
|
||||
function(str: string, obj: { [key: string]: string }) {
|
||||
if (str === obj.bar)
|
||||
{}
|
||||
if (str === obj.bar) {}
|
||||
},
|
||||
function(str: string): Mode {
|
||||
var ch = str[0];
|
||||
@@ -2185,10 +2164,9 @@ let tests = [
|
||||
function(s: string): ?Mode {
|
||||
if (s === \"a\") {
|
||||
return s;
|
||||
} else
|
||||
if (s === \"d\") {
|
||||
return s;
|
||||
}
|
||||
} else if (s === \"d\") {
|
||||
return s;
|
||||
}
|
||||
},
|
||||
function(mode: Mode) {
|
||||
switch (mode) {
|
||||
@@ -2800,7 +2778,7 @@ type NonCitizen = { citizen: false, nationality: string };
|
||||
function nationality(x: Citizen | NonCitizen) {
|
||||
if (x.citizen)
|
||||
return \"Shire\";
|
||||
else
|
||||
else
|
||||
return x.nationality;
|
||||
}
|
||||
|
||||
@@ -2811,18 +2789,14 @@ let tests = [
|
||||
}
|
||||
},
|
||||
function test8(x: { foo: { bar: 1 } }) {
|
||||
if (x.foo.bar === 1)
|
||||
{}
|
||||
if (x.foo.bar === 1) {}
|
||||
|
||||
if (x.fooTypo.bar === 1)
|
||||
{}
|
||||
if (x.fooTypo.bar === 1) {}
|
||||
},
|
||||
function(x: A) {
|
||||
if (x.kind === null.toString())
|
||||
{}
|
||||
if (x.kind === null.toString()) {}
|
||||
|
||||
if ({ kind: 1 }.kind === null.toString())
|
||||
{}
|
||||
if ({ kind: 1 }.kind === null.toString()) {}
|
||||
},
|
||||
function(
|
||||
x: Array<string>,
|
||||
@@ -2833,8 +2807,7 @@ let tests = [
|
||||
s: Function,
|
||||
t: () => void
|
||||
) {
|
||||
if (x.length === 0)
|
||||
{}
|
||||
if (x.length === 0) {}
|
||||
|
||||
if (x.legnth === 0) {
|
||||
(x.legnth: number);
|
||||
@@ -2842,8 +2815,7 @@ let tests = [
|
||||
(x.legnth: string);
|
||||
}
|
||||
|
||||
if (y.length === 0)
|
||||
{}
|
||||
if (y.length === 0) {}
|
||||
|
||||
if (y.legnth === 0) {
|
||||
(y.legnth: number);
|
||||
@@ -2851,8 +2823,7 @@ let tests = [
|
||||
(y.legnth: string);
|
||||
}
|
||||
|
||||
if (z.toString === 0)
|
||||
{}
|
||||
if (z.toString === 0) {}
|
||||
|
||||
if (z.toStirng === 0) {
|
||||
(z.toStirng: number);
|
||||
@@ -2860,8 +2831,7 @@ let tests = [
|
||||
(z.toStirng: string);
|
||||
}
|
||||
|
||||
if (q.valueOf === 0)
|
||||
{}
|
||||
if (q.valueOf === 0) {}
|
||||
|
||||
if (q.valeuOf === 0) {
|
||||
(q.valeuOf: number);
|
||||
@@ -2873,15 +2843,13 @@ let tests = [
|
||||
(r.toStirng: empty);
|
||||
}
|
||||
|
||||
if (s.call === 0)
|
||||
{}
|
||||
if (s.call === 0) {}
|
||||
|
||||
if (s.calll === 0) {
|
||||
(t.calll: empty);
|
||||
}
|
||||
|
||||
if (t.call === 0)
|
||||
{}
|
||||
if (t.call === 0) {}
|
||||
|
||||
if (t.calll === 0) {
|
||||
(t.calll: empty);
|
||||
@@ -3276,9 +3244,8 @@ function undef_var(x: ?number) {
|
||||
}
|
||||
|
||||
function undef_var_rev(x: ?number) {
|
||||
if (x === null || x === undefined)
|
||||
{}
|
||||
else {
|
||||
if (x === null || x === undefined) {}
|
||||
else {
|
||||
var y = x * 1000;
|
||||
}
|
||||
}
|
||||
@@ -3290,9 +3257,8 @@ function undef_prop(x: { x: ?number }) {
|
||||
}
|
||||
|
||||
function undef_prop_rev(x: { x: ?number }) {
|
||||
if (x.x === null || x.x === undefined)
|
||||
{}
|
||||
else {
|
||||
if (x.x === null || x.x === undefined) {}
|
||||
else {
|
||||
var y = x.x * 1000;
|
||||
}
|
||||
}
|
||||
@@ -3304,9 +3270,8 @@ function undef_var_fail(x: ?number) {
|
||||
}
|
||||
|
||||
function undef_var_fail_rev(x: ?number) {
|
||||
if (x === undefined)
|
||||
{}
|
||||
else {
|
||||
if (x === undefined) {}
|
||||
else {
|
||||
var y = x * 1000;
|
||||
}
|
||||
}
|
||||
@@ -3318,9 +3283,8 @@ function undef_prop_fail(x: { x: ?number }) {
|
||||
}
|
||||
|
||||
function undef_prop_fail_rev(x: { x: ?number }) {
|
||||
if (x.x === undefined)
|
||||
{}
|
||||
else {
|
||||
if (x.x === undefined) {}
|
||||
else {
|
||||
var y = x.x * 1000;
|
||||
}
|
||||
}
|
||||
@@ -3511,9 +3475,8 @@ function void_var(x: ?number) {
|
||||
}
|
||||
|
||||
function void_var_rev(x: ?number) {
|
||||
if (x === null || x === void 0)
|
||||
{}
|
||||
else {
|
||||
if (x === null || x === void 0) {}
|
||||
else {
|
||||
var y = x * 1000;
|
||||
}
|
||||
}
|
||||
@@ -3525,9 +3488,8 @@ function void_pro(x: { x: ?number }) {
|
||||
}
|
||||
|
||||
function void_pro_rev(x: { x: ?number }) {
|
||||
if (x.x === null || x.x === void 0)
|
||||
{}
|
||||
else {
|
||||
if (x.x === null || x.x === void 0) {}
|
||||
else {
|
||||
var y = x.x * 1000;
|
||||
}
|
||||
}
|
||||
@@ -3539,9 +3501,8 @@ function void_var_fail(x: ?number) {
|
||||
}
|
||||
|
||||
function void_var_fail_rev(x: ?number) {
|
||||
if (x === void 0)
|
||||
{}
|
||||
else {
|
||||
if (x === void 0) {}
|
||||
else {
|
||||
var y = x * 1000;
|
||||
}
|
||||
}
|
||||
@@ -3553,9 +3514,8 @@ function void_pro_fail(x: { x: ?number }) {
|
||||
}
|
||||
|
||||
function void_pro_fail_rev(x: { x: ?number }) {
|
||||
if (x.x === void 0)
|
||||
{}
|
||||
else {
|
||||
if (x.x === void 0) {}
|
||||
else {
|
||||
var y = x.x * 1000;
|
||||
}
|
||||
}
|
||||
@@ -3567,9 +3527,8 @@ function void_var_side_effect(x: ?number) {
|
||||
}
|
||||
|
||||
function void_var_side_effect_rev(x: ?number) {
|
||||
if (x === null || x === void (x * 1000))
|
||||
{}
|
||||
else {
|
||||
if (x === null || x === void (x * 1000)) {}
|
||||
else {
|
||||
var y = x * 1000;
|
||||
}
|
||||
}
|
||||
@@ -3581,9 +3540,8 @@ function void_prop_side_effect(x: { x: ?number }) {
|
||||
}
|
||||
|
||||
function void_prop_side_effect_rev(x: { x: ?number }) {
|
||||
if (x.x === null || x.x === void (x.x * 1000))
|
||||
{}
|
||||
else {
|
||||
if (x.x === null || x.x === void (x.x * 1000)) {}
|
||||
else {
|
||||
var y = x.x * 1000;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -238,7 +238,7 @@ class H extends A {
|
||||
constructor() {
|
||||
if (Math.random() < 0.5)
|
||||
super();
|
||||
else
|
||||
else
|
||||
super();
|
||||
|
||||
this.y;
|
||||
|
||||
@@ -45,12 +45,11 @@ type Foobar = Foo | Bar;
|
||||
function foobar(x: Foobar): string {
|
||||
if (x.type === \"foo\") {
|
||||
return foo(x);
|
||||
} else
|
||||
if (x.type === \"bar\") {
|
||||
return bar(x);
|
||||
} else {
|
||||
return \"unknown\";
|
||||
}
|
||||
} else if (x.type === \"bar\") {
|
||||
return bar(x);
|
||||
} else {
|
||||
return \"unknown\";
|
||||
}
|
||||
}
|
||||
|
||||
function foo(x: Foo): string {
|
||||
|
||||
@@ -572,8 +572,7 @@ function bar(response) {
|
||||
throw new Error(\"...\");
|
||||
}
|
||||
|
||||
if (payload.error)
|
||||
{}
|
||||
if (payload.error) {}
|
||||
}
|
||||
|
||||
function qux() {
|
||||
|
||||
@@ -209,14 +209,11 @@ if (Array.isArray(x)) {}
|
||||
/* @flow */
|
||||
let x = 0;
|
||||
|
||||
if (x == null)
|
||||
{}
|
||||
if (x == null) {}
|
||||
|
||||
if (x == undefined)
|
||||
{}
|
||||
if (x == undefined) {}
|
||||
|
||||
if (Array.isArray(x))
|
||||
{}
|
||||
if (Array.isArray(x)) {}
|
||||
"
|
||||
`;
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ type Obj_Prop_x = $PropertyType<Obj, \"x\">;
|
||||
function foo(o: Obj): $PropertyType<Obj, \"x\"> {
|
||||
if (false)
|
||||
return o.x;
|
||||
else
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
"
|
||||
|
||||
@@ -314,7 +314,7 @@ type X = ({ a: true } & { b: string }) | ({ a: false } & { c: string });
|
||||
function hello(x: X): string {
|
||||
if (x.a === true)
|
||||
return x.b;
|
||||
else
|
||||
else
|
||||
return x.c;
|
||||
}
|
||||
"
|
||||
@@ -1192,7 +1192,7 @@ type Cons = { kind: \"cons\", next: List };
|
||||
function length(list: List) {
|
||||
if (list.kind === \"cons\")
|
||||
return length(list.next) + 1;
|
||||
else
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1548,7 +1548,7 @@ export type T = Success | Error;
|
||||
function foo(x: T) {
|
||||
if (x.type === \"SUCCESS\")
|
||||
return x.result;
|
||||
else
|
||||
else
|
||||
return x.result;
|
||||
}
|
||||
"
|
||||
@@ -1748,14 +1748,14 @@ type X = ({ a: true } & { b: string }) | ({ a: false } & { c: string });
|
||||
function hello1(x: X): string {
|
||||
if (x.a === true)
|
||||
return x.b;
|
||||
else
|
||||
else
|
||||
return x.c;
|
||||
}
|
||||
|
||||
function hello2(x: X): string {
|
||||
if (x.a === false)
|
||||
return x.c;
|
||||
else
|
||||
else
|
||||
return x.b;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user