I find it weird to put `{}` together. So I figured I would change it to have an empty line and ask for feedback :)

Beware: most of the test cases are not representative of real code, you almost never define blocks with no content in practice.
90 lines
1.7 KiB
Plaintext
90 lines
1.7 KiB
Plaintext
exports[`test maybe.js 1`] = `
|
|
"// @flow
|
|
|
|
// unwrapping nested maybes should work
|
|
((\'foo\': ?(?string)): ?string); // ok
|
|
((123: ?(?number)): ?string); // error (only num ~> string)
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
// @flow
|
|
|
|
// unwrapping nested maybes should work
|
|
((\"foo\": ??string): ?string);
|
|
// ok
|
|
((123: ??number): ?string); // error (only num ~> string)
|
|
"
|
|
`;
|
|
|
|
exports[`test nullable.js 1`] = `
|
|
"function foo():string { return null; }
|
|
|
|
function bar():?string { return null; }
|
|
|
|
function qux(x:string) { }
|
|
|
|
function corge(x:number) { }
|
|
|
|
var x = bar(); // x: ?string
|
|
if (x != null) qux(x); // x: ?string | null
|
|
if (x != null) corge(x); // x: ?string | null
|
|
|
|
function grault() { x = null; }
|
|
if (x != null) {
|
|
grault(); qux(x);
|
|
}
|
|
|
|
var array_of_nullable: Array<?number> = [null, 3];
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
function foo(): string {
|
|
return null;
|
|
}
|
|
|
|
function bar(): ?string {
|
|
return null;
|
|
}
|
|
|
|
function qux(x: string) {
|
|
}
|
|
|
|
function corge(x: number) {
|
|
}
|
|
|
|
var x = bar();
|
|
// x: ?string
|
|
if (x != null) qux(x);
|
|
// x: ?string | null
|
|
if (x != null) corge(x);
|
|
// x: ?string | null
|
|
function grault() {
|
|
x = null;
|
|
}
|
|
if (x != null) {
|
|
grault();
|
|
qux(x);
|
|
}
|
|
|
|
var array_of_nullable: Array<?number> = [ null, 3 ];
|
|
"
|
|
`;
|
|
|
|
exports[`test simple_nullable.js 1`] = `
|
|
"function foo(x:?string) {}
|
|
function bar(x:?number) {}
|
|
foo(\'hmm\');
|
|
bar(\'hmm\');
|
|
|
|
function fn(data: ?{}) {}
|
|
fn({some: \'literal\'});
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
function foo(x: ?string) {
|
|
}
|
|
function bar(x: ?number) {
|
|
}
|
|
foo(\"hmm\");
|
|
bar(\"hmm\");
|
|
|
|
function fn(data: ?{}) {
|
|
}
|
|
fn({ some: \"literal\" });
|
|
"
|
|
`;
|