- 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.
56 lines
1.1 KiB
JavaScript
56 lines
1.1 KiB
JavaScript
/* @flow */
|
||
|
||
function foo(text: string | number): string {
|
||
switch (typeof text) {
|
||
case 'string':
|
||
return text;
|
||
case 'number':
|
||
return text; // error, should return string
|
||
default:
|
||
return 'wat';
|
||
}
|
||
}
|
||
|
||
function bar(text: string | number): string {
|
||
switch (typeof text) {
|
||
case 'string':
|
||
return text[0];
|
||
default:
|
||
return (text++) + '';
|
||
}
|
||
}
|
||
|
||
function baz1(text: string | number): string {
|
||
switch (typeof text) {
|
||
case 'number':
|
||
case 'string':
|
||
return text[0]; // error, [0] on number
|
||
default:
|
||
return 'wat';
|
||
}
|
||
}
|
||
|
||
function baz2(text: string | number): string {
|
||
switch (typeof text) {
|
||
case 'string':
|
||
case 'number':
|
||
return text[0]; // error, [0] on number
|
||
default:
|
||
return 'wat';
|
||
}
|
||
}
|
||
|
||
function corge(text: string | number | Array<string>): string {
|
||
switch (typeof text) {
|
||
case 'object':
|
||
return text[0];
|
||
case 'string':
|
||
case 'number':
|
||
// using ++ since it isn't valid on arrays or strings.
|
||
// should only error for string since Array was filtered out.
|
||
return (text++) + '';
|
||
default:
|
||
return 'wat';
|
||
}
|
||
}
|