Files
test-repo/tests/async/async.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

53 lines
1.1 KiB
JavaScript

// @flow
// "For async functions, a Promise<T> is returned,
// and the type of return expressions must be T."
//
async function f0(): Promise<number> {
return 1;
}
async function f1(): Promise<bool> {
return 1; // error, number != bool
}
// await: (p: Promise<T> | T) => T
//
async function f2(p: Promise<number>): Promise<number> {
var x: number = await p;
var y: number = await 1;
return x + y;
}
async function f3(p: Promise<number>): Promise<number> {
return await p;
}
// TODO: this is one of those bad generic errors, currently:
// "inconsistent use of library definitions" with two core.js locs
async function f4(p: Promise<number>): Promise<bool> {
return await p; // error, number != bool
}
// async arrow functions
//
var f5: () => Promise<number> = async () => await 1;
// async methods
//
class C {
async m() { return 1; }
async mt<T>(a: T): Promise<T> { return a; }
static async m(a): void { await a; } // error, void != Promise<void>
static async mt<T>(a: T): Promise<T> { return a; }
}
// async function props
var obj = { f: async () => await 1 };
var objf : () => Promise<number> = obj.f;