- This brings in the flow test suite that contains a ton of JavaScript parsing edge cases - This creates snapshot tests using the pretty printer for all of them - If uncomment `RUN_AST_TESTS` line in `tests/run_specs.js`, it checks ast(pretty_print(x)) == ast(x). Right now, "178 failed, 197 passed, 375 of 377 total". So half of the tests are not passing, most of them are crashes and many of the rest are subtle issues.
53 lines
972 B
JavaScript
53 lines
972 B
JavaScript
/* @flow */
|
|
|
|
function foo(x: ?bool) {
|
|
if (!x) {
|
|
x++; // should error for null, void and bool (false)
|
|
}
|
|
}
|
|
|
|
function bar(x: ?number) {
|
|
if (!x) {
|
|
x[0]; // should error for null, void and number (0)
|
|
}
|
|
}
|
|
|
|
function baz (x: ?number) {
|
|
if (x === null || x === undefined) {
|
|
return;
|
|
}
|
|
|
|
if (!x) {
|
|
x[0]; // should error for number (0)
|
|
}
|
|
}
|
|
|
|
class TestClass {}
|
|
|
|
let tests = [
|
|
function() {
|
|
var y = true;
|
|
while (y) {
|
|
y = !y;
|
|
}
|
|
},
|
|
function(x: Function) {
|
|
(!x: false); // ok, functions are always truthy
|
|
},
|
|
function(x: Object) {
|
|
(!x: false); // ok, objects are always truthy
|
|
},
|
|
function(x: string) {
|
|
(!x: false); // error, strings are not always truthy
|
|
},
|
|
function(x: number) {
|
|
(!x: false); // error, numbers are not always truthy
|
|
},
|
|
function(x: boolean) {
|
|
(!x: false); // error, bools are not always truthy
|
|
},
|
|
function(x: TestClass) {
|
|
(!x: false); // ok, classes are always truthy
|
|
},
|
|
];
|