- 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.
36 lines
1000 B
JavaScript
36 lines
1000 B
JavaScript
// @flow
|
|
|
|
function test(a: string, b: number): number {
|
|
return this.length; // expect []/"" this
|
|
}
|
|
|
|
// args flow correctly into params
|
|
test.call("", "", 0);
|
|
|
|
// wrong this is an error
|
|
test.call(0, "", 0); // error: lookup `length` on Number
|
|
|
|
// not enough arguments is an error (via incompatible RestT)
|
|
test.call("", ""); // error: string ~> number
|
|
|
|
// mistyped arguments is an error
|
|
test.call("", "", ""); // error: string ~> number (2nd arg)
|
|
test.call("", 0, 0); // error: number ~> string (1st arg)
|
|
|
|
// resolve args array from tvar
|
|
function f(args) { test.call("", args[0], args[1]) }
|
|
f(["", 0]); // OK
|
|
f(["", ""]); // error: string ~> number (2nd arg)
|
|
f([0, 0]); // error: number ~> string (1st arg)
|
|
|
|
// expect 3 errors:
|
|
// - lookup length on Number (0 used as `this`)
|
|
// - number !~> string (param a)
|
|
// - string !~> number (param b)
|
|
(test.apply.call(test, 0, [0, 'foo']): number);
|
|
|
|
// args are optional
|
|
function test2(): number { return 0; }
|
|
(test2.call(): number);
|
|
(test2.call(""): number);
|