Files
test-repo/tests/switch/trailing_cases.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.1 KiB
JavaScript

/**
* trailing cases are allowed - spot checks that we handle them as usual
* @flow
*/
function f1(i) {
var x;
switch (i) {
case 0:
x = 0;
break;
case 1:
x = 1;
break;
default:
x = -1;
break;
case 2:
x = "2";
break;
}
var y:number = x; // error, number | string ~/> number
}
function f2(i) {
var x;
switch (i) {
case 0:
case 1:
default:
x = 1;
break;
case 2:
// does not fall through default
}
var y:number = x; // error, number | uninitialized ~/> number
}
function f3(i) {
var x;
switch (i) {
case 0:
case 1:
default:
// falls through to subsequent cases
case 2:
x = 1;
}
var y:number = x; // no error
}
function foo(x): number {
switch (x) {
case 0:
default: throw new Error('hi');
case 1: return 1;
}
}
function bar(x) {
switch (x) {
default: return;
case 0: break;
}
1;
}
function baz(x): number {
switch (x) {
case 0: break;
default: throw new Error('hi');
case 1: return 1;
}
return 2;
}