Files
test-repo/tests/async/__snapshots__/jsfmt.spec.js.snap
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

472 lines
14 KiB
Plaintext

exports[`test async.js 1`] = `
"// @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;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/src/printer.js:1497
fromString(\", \").join(path.map(print, \"params\")),
^
TypeError: fromString(...).join is not a function
at genericPrintNoParens (/src/printer.js:1497:26)
at genericPrint (/src/printer.js:166:7)
at p (/src/printer.js:111:37)
at exports.printComments (/src/comments.js:327:20)
at printGenerically (/src/printer.js:111:12)
at FastPath.call (/src/fast-path.js:113:16)
at genericPrintNoParens (/src/printer.js:1374:14)
at genericPrint (/src/printer.js:166:7)
at p (/src/printer.js:111:37)
at exports.printComments (/src/comments.js:327:20)
"
`;
exports[`test async_base_class.js 1`] = `
"// This is kind of weird, but it should parse. This works in babel without the
// parens around (await promise). From the es6 and async/await specs I (nmote)
// am not clear on whether it should. In any case it\'s a strange corner case
// that is probably not important to support.
class C {};
var P: Promise<Class<C>> = new Promise(function (resolve, reject) {
resolve(C);
});
async function foo() {
class Bar extends (await P) { }
return Bar;
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/src/printer.js:1497
fromString(\", \").join(path.map(print, \"params\")),
^
TypeError: fromString(...).join is not a function
at genericPrintNoParens (/src/printer.js:1497:26)
at genericPrint (/src/printer.js:166:7)
at p (/src/printer.js:111:37)
at exports.printComments (/src/comments.js:327:20)
at printGenerically (/src/printer.js:111:12)
at FastPath.call (/src/fast-path.js:113:16)
at genericPrintNoParens (/src/printer.js:1374:14)
at genericPrint (/src/printer.js:166:7)
at p (/src/printer.js:111:37)
at exports.printComments (/src/comments.js:327:20)
"
`;
exports[`test async_parse.js 1`] = `
"async function f() {}
async function ft<T>(a: T) {}
class C {
async m() {}
async mt<T>(a: T) {}
static async m(a) {}
static async mt<T>(a: T) {}
}
var e = async function () {};
var et = async function<T> (a: T) {};
var n = new async function() {};
var o = { async m() {} };
var ot = { async m<T>(a: T) {} };
var oz = { async async() {} };
var x = { async : 5 };
console.log(x.async);
var async = 3;
var y = { async };
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/src/printer.js:1497
fromString(\", \").join(path.map(print, \"params\")),
^
TypeError: fromString(...).join is not a function
at genericPrintNoParens (/src/printer.js:1497:26)
at genericPrint (/src/printer.js:166:7)
at p (/src/printer.js:111:37)
at exports.printComments (/src/comments.js:327:20)
at printGenerically (/src/printer.js:111:12)
at FastPath.call (/src/fast-path.js:113:16)
at genericPrintNoParens (/src/printer.js:340:16)
at genericPrint (/src/printer.js:166:7)
at p (/src/printer.js:111:37)
at exports.printComments (/src/comments.js:327:20)
"
`;
exports[`test async_promise.js 1`] = `
"async function f(): Promise<number> {
return Promise.resolve(1);
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/src/printer.js:1497
fromString(\", \").join(path.map(print, \"params\")),
^
TypeError: fromString(...).join is not a function
at genericPrintNoParens (/src/printer.js:1497:26)
at genericPrint (/src/printer.js:166:7)
at p (/src/printer.js:111:37)
at exports.printComments (/src/comments.js:327:20)
at printGenerically (/src/printer.js:111:12)
at FastPath.call (/src/fast-path.js:113:16)
at genericPrintNoParens (/src/printer.js:1374:14)
at genericPrint (/src/printer.js:166:7)
at p (/src/printer.js:111:37)
at exports.printComments (/src/comments.js:327:20)
"
`;
exports[`test async_return_void.js 1`] = `
"// @flow
async function foo1(): Promise<string> {
return;
}
async function foo2(): Promise<string> {
return undefined;
}
async function foo3(): Promise<string> {
function bar() { }
return bar();
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/src/printer.js:1497
fromString(\", \").join(path.map(print, \"params\")),
^
TypeError: fromString(...).join is not a function
at genericPrintNoParens (/src/printer.js:1497:26)
at genericPrint (/src/printer.js:166:7)
at p (/src/printer.js:111:37)
at exports.printComments (/src/comments.js:327:20)
at printGenerically (/src/printer.js:111:12)
at FastPath.call (/src/fast-path.js:113:16)
at genericPrintNoParens (/src/printer.js:1374:14)
at genericPrint (/src/printer.js:166:7)
at p (/src/printer.js:111:37)
at exports.printComments (/src/comments.js:327:20)
"
`;
exports[`test async2.js 1`] = `
"// @flow
// misc basic
function test1() {
async function foo() {
return 42;
}
async function bar() {
var a = await foo();
var b: number = a; // valid
var c: string = a; // Error: number ~> string
}
}
//
// void returns:
//
// inference should produce return type Promise<void>
// in the absence of an explicit return
//
function test2() {
async function voidoid1() {
console.log(\"HEY\");
}
var voidoid2: () => Promise<void> = voidoid1; // ok
var voidoid3: () => void = voidoid1; // error, void != Promise<void>
}
// annotated return type of Promise<void> should work
//
function test3() {
async function voidoid4(): Promise<void> { // ok
console.log(\"HEY\");
}
}
// other annotated return types should fail
// (note: misannotated return types with explicit
// return statements are covered in async.js)
//
function test4() {
async function voidoid5(): void { // error, void != Promise<void>
console.log(\"HEY\");
}
}
function test5() {
async function voidoid6()
: Promise<number> { // error, number != void
console.log(\"HEY\");
}
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/src/printer.js:1348
fromString(\", \").join(path.map(print, \"params\")),
^
TypeError: fromString(...).join is not a function
at genericPrintNoParens (/src/printer.js:1348:26)
at genericPrint (/src/printer.js:166:7)
at p (/src/printer.js:111:37)
at exports.printComments (/src/comments.js:327:20)
at printGenerically (/src/printer.js:111:12)
at FastPath.call (/src/fast-path.js:113:16)
at genericPrintNoParens (/src/printer.js:1254:25)
at genericPrint (/src/printer.js:166:7)
at p (/src/printer.js:111:37)
at exports.printComments (/src/comments.js:327:20)
"
`;
exports[`test async3.js 1`] = `
"// @flow
/**
* test nested-promise unwrapping.
* Note: currently we don\'t do this properly in the underlying
* type of the Promise class, which causes spurious errors to
* be raised here. Once that\'s fixed, the errors here will go
* away.
*/
async function foo() {
return 42;
}
async function bar() {
return foo();
}
async function baz() {
// a should now be typed as number, but is in fact
// Promise<number> until nested-promise unwrap is fixed
var a = await bar();
// TODO this is valid code, but currently gives Promise ~> number error
// due to lack of transitive Promise unwrap.
var b: number = a;
// should be number ~> string error, but currently gives
// Promise ~> string error for the same reason
var c: string = a;
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// @flow
/**
* test nested-promise unwrapping.
* Note: currently we don\'t do this properly in the underlying
* type of the Promise class, which causes spurious errors to
* be raised here. Once that\'s fixed, the errors here will go
* away.
*/
async function foo() {
return 42;
}
async function bar() {
return foo();
}
async function baz() {
// a should now be typed as number, but is in fact
// Promise<number> until nested-promise unwrap is fixed
var a = await bar();
// TODO this is valid code, but currently gives Promise ~> number error
// due to lack of transitive Promise unwrap.
var b: number = a;
// should be number ~> string error, but currently gives
// Promise ~> string error for the same reason
var c: string = a;
}
"
`;
exports[`test await_not_in_async.js 1`] = `
"// note: currently, await-within-async enforcement is a
// done by the parser, which bails after a single error.
function f() {
await 1;
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/node_modules/babylon/lib/index.js:4255
throw err;
^
SyntaxError: await is a reserved word (5:2)
at Parser.pp$5.raise (/node_modules/babylon/lib/index.js:4252:13)
at Parser.pp$3.checkReservedWord (/node_modules/babylon/lib/index.js:4143:10)
at Parser.pp$3.parseIdentifier (/node_modules/babylon/lib/index.js:4121:12)
at Parser.pp$3.parseExprAtom (/node_modules/babylon/lib/index.js:3490:21)
at Parser.parseExprAtom (/node_modules/babylon/lib/index.js:6408:22)
at Parser.pp$3.parseExprSubscripts (/node_modules/babylon/lib/index.js:3337:19)
at Parser.pp$3.parseMaybeUnary (/node_modules/babylon/lib/index.js:3317:19)
at Parser.pp$3.parseExprOps (/node_modules/babylon/lib/index.js:3247:19)
at Parser.pp$3.parseMaybeConditional (/node_modules/babylon/lib/index.js:3224:19)
at Parser.pp$3.parseMaybeAssign (/node_modules/babylon/lib/index.js:3187:19)
"
`;
exports[`test await_not_in_async2.js 1`] = `
"// note: currently, await-within-async enforcement is a
// done by the parser, which bails after a single error.
function f(x) { return x; }
f(await 1);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/node_modules/babylon/lib/index.js:4255
throw err;
^
SyntaxError: await is a reserved word (6:2)
at Parser.pp$5.raise (/node_modules/babylon/lib/index.js:4252:13)
at Parser.pp$3.checkReservedWord (/node_modules/babylon/lib/index.js:4143:10)
at Parser.pp$3.parseIdentifier (/node_modules/babylon/lib/index.js:4121:12)
at Parser.pp$3.parseExprAtom (/node_modules/babylon/lib/index.js:3490:21)
at Parser.parseExprAtom (/node_modules/babylon/lib/index.js:6408:22)
at Parser.pp$3.parseExprSubscripts (/node_modules/babylon/lib/index.js:3337:19)
at Parser.pp$3.parseMaybeUnary (/node_modules/babylon/lib/index.js:3317:19)
at Parser.pp$3.parseExprOps (/node_modules/babylon/lib/index.js:3247:19)
at Parser.pp$3.parseMaybeConditional (/node_modules/babylon/lib/index.js:3224:19)
at Parser.pp$3.parseMaybeAssign (/node_modules/babylon/lib/index.js:3187:19)
"
`;
exports[`test await_not_in_async3.js 1`] = `
"// note: currently, await-within-async enforcement is a
// done by the parser, which bails after a single error.
async function f(x) { return x; }
f(await 1);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/node_modules/babylon/lib/index.js:4255
throw err;
^
SyntaxError: await is a reserved word (6:2)
at Parser.pp$5.raise (/node_modules/babylon/lib/index.js:4252:13)
at Parser.pp$3.checkReservedWord (/node_modules/babylon/lib/index.js:4143:10)
at Parser.pp$3.parseIdentifier (/node_modules/babylon/lib/index.js:4121:12)
at Parser.pp$3.parseExprAtom (/node_modules/babylon/lib/index.js:3490:21)
at Parser.parseExprAtom (/node_modules/babylon/lib/index.js:6408:22)
at Parser.pp$3.parseExprSubscripts (/node_modules/babylon/lib/index.js:3337:19)
at Parser.pp$3.parseMaybeUnary (/node_modules/babylon/lib/index.js:3317:19)
at Parser.pp$3.parseExprOps (/node_modules/babylon/lib/index.js:3247:19)
at Parser.pp$3.parseMaybeConditional (/node_modules/babylon/lib/index.js:3224:19)
at Parser.pp$3.parseMaybeAssign (/node_modules/babylon/lib/index.js:3187:19)
"
`;
exports[`test await_parse.js 1`] = `
"async function f() { await 1; }
async function ft<T>(a: T) { await 1; }
class C {
async m() { await 1; }
async mt<T>(a: T) { await 1; }
static async m(a) { await 1; }
static async mt<T>(a: T) { await 1; }
}
var e = async function () { await 1; };
var et = async function<T> (a: T) { await 1; };
var n = new async function() { await 1; };
var o = { async m() { await 1; } };
var ot = { async m<T>(a: T) { await 1; } };
var oz = { async async(async) { await async; } };
var x = { await : 5 };
console.log(x.await);
var await = 3;
var y = { await };
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/node_modules/babylon/lib/index.js:4255
throw err;
^
SyntaxError: await is a reserved word (23:4)
at Parser.pp$5.raise (/node_modules/babylon/lib/index.js:4252:13)
at Parser.pp$3.checkReservedWord (/node_modules/babylon/lib/index.js:4143:10)
at Parser.pp$2.checkLVal (/node_modules/babylon/lib/index.js:2990:12)
at Parser.checkLVal (/node_modules/babylon/lib/index.js:5446:22)
at Parser.pp$1.parseVarHead (/node_modules/babylon/lib/index.js:2227:8)
at Parser.parseVarHead (/node_modules/babylon/lib/index.js:5611:13)
at Parser.pp$1.parseVar (/node_modules/babylon/lib/index.js:2209:10)
at Parser.pp$1.parseVarStatement (/node_modules/babylon/lib/index.js:2042:8)
at Parser.pp$1.parseStatement (/node_modules/babylon/lib/index.js:1735:19)
at Parser.parseStatement (/node_modules/babylon/lib/index.js:5224:22)
"
`;