Files
test-repo/tests/refinements/undef.js
T
Christopher Chedeau cf45afba61 Add testing
- 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.
2016-12-23 19:51:53 +00:00

81 lines
1.3 KiB
JavaScript

/* @flow */
function undef_var(x: ?number) {
if (x !== null && x !== undefined) {
var y = x * 1000;
}
}
function undef_var_rev(x: ?number) {
if (x === null || x === undefined) {
} else {
var y = x * 1000;
}
}
function undef_prop(x: { x: ?number }) {
if (x.x !== null && x.x !== undefined) {
var y = x.x * 1000;
}
}
function undef_prop_rev(x: { x: ?number }) {
if (x.x === null || x.x === undefined) {
} else {
var y = x.x * 1000;
}
}
function undef_var_fail(x: ?number) {
if (x !== undefined) {
var y = x * 1000;
}
}
function undef_var_fail_rev(x: ?number) {
if (x === undefined) {
} else {
var y = x * 1000;
}
}
function undef_prop_fail(x: { x: ?number }) {
if (x.x !== undefined) {
var y = x.x * 1000;
}
}
function undef_prop_fail_rev(x: { x: ?number }) {
if (x.x === undefined) {
} else {
var y = x.x * 1000;
}
}
function undef_unreachable(x: number) {
if (x === undefined) {
var y = x * 1000; // unreachable
}
if (x == undefined) {
var z = x * 1000; // unreachable
}
}
function undef_var_nonstrict(x: ?number, y: ?number) {
if (x != undefined) {
var a = x * 1000;
}
if (y == undefined){
var b = y * 1000; // error
}
}
function undef_bogus_comparison() {
if (100 * undefined) {
return;
}
if (undefined * 100) {
return;
}
}