Move tests around (#454)

* new_tests

* move_all_clobbered_tests

* remove all the tests that no longer exist

* re-run flow tests

* Move all the flow tests to tests/flow and prettier to tests/

* Move prettier tests to their own folders

* Add jsfmt files

* run prettier snapshot tests
master
Christopher Chedeau 2017-01-24 14:35:37 -08:00 committed by GitHub
parent f6708a5cca
commit 3375cfe605
1851 changed files with 6617 additions and 5468 deletions

View File

@ -6,54 +6,3 @@ exports[`test multiple.js 1`] = `
[...a, ...b];
"
`;
exports[`test multiple.js 2`] = `
"[...a, ...b,];
[...a, ...b];
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[...a, ...b];
[...a, ...b];
"
`;
exports[`test test.js 1`] = `
"var A = [1,2,3];
var B = [...A];
var C = [1,2,3];
B.sort((a, b) => a - b);
C.sort((a, b) => a - b);
var x: Array<string> = [\'1\', \'2\'];
var y: Array<string> = [\'3\', ...x];
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
var A = [1, 2, 3];
var B = [...A];
var C = [1, 2, 3];
B.sort((a, b) => a - b);
C.sort((a, b) => a - b);
var x: Array<string> = [\"1\", \"2\"];
var y: Array<string> = [\"3\", ...x];
"
`;
exports[`test test.js 2`] = `
"var A = [1,2,3];
var B = [...A];
var C = [1,2,3];
B.sort((a, b) => a - b);
C.sort((a, b) => a - b);
var x: Array<string> = [\'1\', \'2\'];
var y: Array<string> = [\'3\', ...x];
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
var A = [1, 2, 3];
var B = [...A];
var C = [1, 2, 3];
B.sort((a, b) => a - b);
C.sort((a, b) => a - b);
var x: Array<string> = [\"1\", \"2\"];
var y: Array<string> = [\"3\", ...x];
"
`;

View File

@ -1,2 +1 @@
run_spec(__dirname);
run_spec(__dirname, {parser: 'babylon'});

View File

@ -1,85 +1,3 @@
exports[`test Arrays.js 1`] = `
"
/* @providesModule Arrays */
function foo(x:string) { }
var a = [];
a[0] = 1;
a[1] = \"...\";
foo(a[1]);
var y;
a.forEach(x => y=x);
// for literals, composite element type is union of individuals
// note: test both tuple and non-tuple inferred literals
var alittle: Array<?number> = [0, 1, 2, 3, null];
var abig: Array<?number> = [0, 1, 2, 3, 4, 5, 6, 8, null];
var abig2: Array<{x:number; y:number}> = [
{x:0, y:0},
{x:0, y:0},
{x:0, y:0},
{x:0, y:0},
{x:0, y:0},
{x:0, y:0},
{x:0, y:0},
{x:0, y:0},
{x:0, y:0},
{x:0, y:0},
{x:0, y:0},
{x:0, y:0},
{x:0, y:0},
{x:0, y:0, a:true},
{x:0, y:0, b:\"hey\"},
{x:0, y:0, c:1},
{x:0, y:0, c:\"hey\"}
];
module.exports = \"arrays\";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/* @providesModule Arrays */
function foo(x: string) {}
var a = [];
a[0] = 1;
a[1] = \"...\";
foo(a[1]);
var y;
a.forEach(x => y = x);
// for literals, composite element type is union of individuals
// note: test both tuple and non-tuple inferred literals
var alittle: Array<?number> = [0, 1, 2, 3, null];
var abig: Array<?number> = [0, 1, 2, 3, 4, 5, 6, 8, null];
var abig2: Array<{ x: number, y: number }> = [
{ x: 0, y: 0 },
{ x: 0, y: 0 },
{ x: 0, y: 0 },
{ x: 0, y: 0 },
{ x: 0, y: 0 },
{ x: 0, y: 0 },
{ x: 0, y: 0 },
{ x: 0, y: 0 },
{ x: 0, y: 0 },
{ x: 0, y: 0 },
{ x: 0, y: 0 },
{ x: 0, y: 0 },
{ x: 0, y: 0 },
{ x: 0, y: 0, a: true },
{ x: 0, y: 0, b: \"hey\" },
{ x: 0, y: 0, c: 1 },
{ x: 0, y: 0, c: \"hey\" }
];
module.exports = \"arrays\";
"
`;
exports[`test last.js 1`] = `
"[,];
[,,];
@ -92,22 +10,3 @@ exports[`test last.js 1`] = `
[, , 1, 1];
"
`;
exports[`test numeric_elem.js 1`] = `
"var arr = [];
var day = new Date;
// Date instances are numeric (see Flow_js.numeric) and thus can index into
// arrays.
arr[day] = 0;
(arr[day]: string); // error: number ~> string
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
var arr = [];
var day = new Date();
// Date instances are numeric (see Flow_js.numeric) and thus can index into
// arrays.
arr[day] = 0;
(arr[day]: string); // error: number ~> string
"
`;

View File

@ -1,31 +1,3 @@
exports[`test advanced_arrows.js 1`] = `
"/**
* @flow
*/
var add = (x: number, y: number): number => x + y;
var bad = (x: number): string => x; // Error!
var ident = <T>(x: T): T => x;
(ident(1): number);
(ident(\"hi\"): number); // Error
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/**
* @flow
*/
var add = (x: number, y: number): number => x + y;
var bad = (x: number): string => x;
// Error!
var ident = <T>(x: T): T => x;
(ident(1): number);
(ident(\"hi\"): number); // Error
"
`;
exports[`test arrow_function_expression.js 1`] = `
"(a => {}).length
typeof (() => {});
@ -46,31 +18,9 @@ if ((() => {}) ? 1 : 0) {
"
`;
exports[`test arrows.js 1`] = `
"function selectBestEffortImageForWidth(
maxWidth: number,
images: Array<Image>
): Image {
var maxPixelWidth = maxWidth;
//images = images.sort(function (a, b) { return a.width - b.width });
images = images.sort((a, b) => (a.width - b.width) + \"\");
return images.find(image => image.width >= maxPixelWidth) ||
images[images.length - 1];
}
a = () => ({} = this);
exports[`test block_like.js 1`] = `
"a = () => ({} = this);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function selectBestEffortImageForWidth(
maxWidth: number,
images: Array<Image>
): Image {
var maxPixelWidth = maxWidth;
//images = images.sort(function (a, b) { return a.width - b.width });
images = images.sort((a, b) => a.width - b.width + \"\");
return images.find(image => image.width >= maxPixelWidth) ||
images[images.length - 1];
}
a = () => ({} = this);
"
`;

View File

@ -0,0 +1 @@
a = () => ({} = this);

View File

@ -1,528 +1,10 @@
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;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// @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<boolean> {
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<boolean> {
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;
"
`;
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;
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// 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;
}
"
`;
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 };
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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 };
"
`;
exports[`test async_promise.js 1`] = `
"async function f(): Promise<number> {
return Promise.resolve(1);
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
async function f(): Promise<number> {
return Promise.resolve(1);
}
"
`;
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();
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// @flow
async function foo1(): Promise<string> {
return;
}
async function foo2(): Promise<string> {
return undefined;
}
async function foo3(): Promise<string> {
function bar() {}
return bar();
}
"
`;
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\");
}
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// @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\");
}
}
"
`;
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_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 };
async function f() { (await f()).length }
"async function f() { (await f()).length }
async function g() {
invariant(
(await driver.navigator.getUrl()).substr(-7)
);
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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 };
}~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
async function f() {
(await f()).length;
}

View File

@ -1,31 +1,6 @@
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 };
async function f() { (await f()).length }
async function g() {
invariant(
(await driver.navigator.getUrl()).substr(-7)
);
}
}

View File

@ -0,0 +1,61 @@
exports[`test test.js 1`] = `
"// It should always break the highest precedence operators first, and
// break them all at the same time.
const x = longVariable + longVariable + longVariable;
const x = longVariable + longVariable + longVariable + longVariable - longVariable + longVariable;
const x = longVariable + longVariable * longVariable + longVariable - longVariable + longVariable;
const x = longVariable + longVariable * longVariable * longVariable / longVariable + longVariable;
const x = longVariable && longVariable && longVariable && longVariable && longVariable && longVariable;
const x = longVariable && longVariable || longVariable && longVariable || longVariable && longVariable;
const x = longVariable * longint && longVariable >> 0 && longVariable + longVariable;
const x = longVariable > longint && longVariable === 0 + longVariable * longVariable;
foo(obj.property * new Class() && obj instanceof Class && longVariable ? number + 5 : false);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// It should always break the highest precedence operators first, and
// break them all at the same time.
const x = longVariable + longVariable + longVariable;
const x = longVariable +
longVariable +
longVariable +
longVariable -
longVariable +
longVariable;
const x = longVariable +
longVariable * longVariable +
longVariable -
longVariable +
longVariable;
const x = longVariable +
longVariable * longVariable * longVariable / longVariable +
longVariable;
const x = longVariable &&
longVariable &&
longVariable &&
longVariable &&
longVariable &&
longVariable;
const x = longVariable && longVariable ||
longVariable && longVariable ||
longVariable && longVariable;
const x = longVariable * longint &&
longVariable >> 0 &&
longVariable + longVariable;
const x = longVariable > longint &&
longVariable === 0 + longVariable * longVariable;
foo(
obj.property * new Class() && obj instanceof Class && longVariable
? number + 5
: false
);
"
`;

View File

@ -1,77 +1,3 @@
exports[`test A.js 1`] = `
"class A {
foo(x:number):void { }
}
module.exports = A;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
class A {
foo(x: number): void {}
}
module.exports = A;
"
`;
exports[`test B.js 1`] = `
"var A = require(\'./A\');
class B extends A { }
let b = new B();
(b.foo: number); // error, number !~> function
module.exports = B;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
var A = require(\"./A\");
class B extends A {}
let b = new B();
(b.foo: number);
// error, number !~> function
module.exports = B;
"
`;
exports[`test C.js 1`] = `
"var B = require(\'./B\');
class C extends B {
foo(x:string):void { }
}
let c = new C();
(c.foo: number); // error, number !~> function
module.exports = C;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
var B = require(\"./B\");
class C extends B {
foo(x: string): void {}
}
let c = new C();
(c.foo: number);
// error, number !~> function
module.exports = C;
"
`;
exports[`test D.js 1`] = `
"class D { }
class E { }
new E().x
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
class D {}
class E {}
new E().x;
"
`;
exports[`test binary.js 1`] = `
"(class {}) + 1;
(class a {}) + 1;
@ -92,176 +18,6 @@ exports[`test call.js 1`] = `
"
`;
exports[`test class_shapes.js 1`] = `
"/* @flow */
type Foo = {
a: string; // exists in TestClass
b: string; // doesn\'t exist
c?: ?string; // exists in TestClass, optional
d?: number; // doesn\'t exist
}
class TestClass {
a: string;
c: ?string;
}
var x = new TestClass();
x.a; // ok
x.b; // error, TestClass has no b
x.c; // ok
x.d; // error, TestClass has no d
var y : Foo = x;
y.b; // error, doesn\'t exist in TestClass
y.d; // ok, it\'s optional
class Test2Superclass {
a: number; // conflicts with cast to Foo
c: ?number; // conflicts with cast to Foo
}
class Test2Class extends Test2Superclass {
b: number; // conflicts with cast to Foo
}
var z = new Test2Class();
var w : Foo = z;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/* @flow */
type Foo = {
a: string,
// exists in TestClass
b: string,
// doesn\'t exist
c?: ?string,
// exists in TestClass, optional
d?: number /* doesn\'t exist*/
};
class TestClass {
a: string;
c: ?string;
}
var x = new TestClass();
x.a;
// ok
x.b;
// error, TestClass has no b
x.c;
// ok
x.d;
// error, TestClass has no d
var y: Foo = x;
y.b;
// error, doesn\'t exist in TestClass
y.d;
// ok, it\'s optional
class Test2Superclass {
a: number;
// conflicts with cast to Foo
c: ?number; // conflicts with cast to Foo
}
class Test2Class extends Test2Superclass {
b: number; // conflicts with cast to Foo
}
var z = new Test2Class();
var w: Foo = z;
"
`;
exports[`test expr.js 1`] = `
"var Bar = class Foo {
static factory(): Foo { // OK: Foo is a type in this scope
return new Foo() // OK: Foo is a runtime binding in this scope
}
};
var bar1: Bar = new Bar() // OK
var bar2: Bar = Bar.factory() // OK
// NB: Don\'t write expected errors using Foo to avoid error collapse hiding an
// unexpected failure in the above code.
var B = class Baz { }
var b = new Baz(); // error: Baz is not a runtime binding in this scope
var C = class Qux { }
var c: Qux = new C(); // error: Qux is not a type in this scope
// OK: anon classes create no binding, but can be bound manually
var Anon = class { }
var anon: Anon = new Anon();
class Alias { }
var _Alias = class Alias {
static factory(): Alias {
return new Alias();
}
}
var alias1: Alias = new _Alias(); // error: bad pun
var alias2: Alias = _Alias.factory(); // error: bad pun
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
var Bar = class Foo {
static factory(): Foo {
// OK: Foo is a type in this scope
return new Foo(); // OK: Foo is a runtime binding in this scope
}
};
var bar1: Bar = new Bar();
// OK
var bar2: Bar = Bar.factory();
// OK
// NB: Don\'t write expected errors using Foo to avoid error collapse hiding an
// unexpected failure in the above code.
var B = class Baz {};
var b = new Baz();
// error: Baz is not a runtime binding in this scope
var C = class Qux {};
var c: Qux = new C();
// error: Qux is not a type in this scope
// OK: anon classes create no binding, but can be bound manually
var Anon = class {};
var anon: Anon = new Anon();
class Alias {}
var _Alias = class Alias {
static factory(): Alias {
return new Alias();
}
};
var alias1: Alias = new _Alias();
// error: bad pun
var alias2: Alias = _Alias.factory(); // error: bad pun
"
`;
exports[`test loc.js 1`] = `
"/* @flow */
type Foo = number
class Foo {} // error, shadows type Foo
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/* @flow */
type Foo = number;
class Foo {} // error, shadows type Foo
"
`;
exports[`test member.js 1`] = `
"(class {})[1];
(class {}).a;
@ -271,39 +27,6 @@ exports[`test member.js 1`] = `
"
`;
exports[`test statics.js 1`] = `
"/* @flow */
class C {
static p: string;
}
C.p = \"hi\";
// Class static fields are compatible with object types
(C: {p:string}); // ok
(C: {p:number}); // errors, string ~> number & vice versa (unify)
declare var o: {p:number};
(o: Class<C>); // error, object type incompatible with class type
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/* @flow */
class C {
static p: string;
}
C.p = \"hi\";
// Class static fields are compatible with object types
(C: { p: string });
// ok
(C: { p: number });
// errors, string ~> number & vice versa (unify)
declare var o: { p: number };
(o: Class<C>); // error, object type incompatible with class type
"
`;
exports[`test ternary.js 1`] = `
"if (1) (class {}) ? 1 : 2;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

View File

@ -8,143 +8,3 @@ class c {
}
"
`;
exports[`test test.js 1`] = `
"var ColorId = {
RED: \'R\',
GREEN: \'G\',
BLUE: \'B\',
};
var ColorNumber = {
RED: \'ff0000\',
GREEN: \'00ff00\',
BLUE: \'0000ff\',
};
var ColorIdToNumber = {
[ColorId.RED]: ColorNumber.RED,
[ColorId.GREEN]: ColorNumber.GREEN,
[ColorId.BLUE]: ColorNumber.BLUE,
};
(ColorIdToNumber[ColorId.RED]: \'ffffff\'); // oops
ColorIdToNumber.XXX; // oops
module.exports = { ColorId, ColorNumber };
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
var ColorId = { RED: \"R\", GREEN: \"G\", BLUE: \"B\" };
var ColorNumber = { RED: \"ff0000\", GREEN: \"00ff00\", BLUE: \"0000ff\" };
var ColorIdToNumber = {
[ColorId.RED]: ColorNumber.RED,
[ColorId.GREEN]: ColorNumber.GREEN,
[ColorId.BLUE]: ColorNumber.BLUE
};
(ColorIdToNumber[ColorId.RED]: \"ffffff\");
// oops
ColorIdToNumber.XXX;
// oops
module.exports = { ColorId, ColorNumber };
"
`;
exports[`test test2.js 1`] = `
"var { ColorId, ColorNumber } = require(\'./test\');
var ColorIdToNumber = {
[ColorId.RED]: ColorNumber.RED,
[ColorId.GREEN]: ColorNumber.GREEN,
[ColorId.BLUE]: ColorNumber.BLUE,
};
(ColorIdToNumber[ColorId.GREEN]: \'ffffff\'); // oops
module.exports = ColorIdToNumber;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
var { ColorId, ColorNumber } = require(\"./test\");
var ColorIdToNumber = {
[ColorId.RED]: ColorNumber.RED,
[ColorId.GREEN]: ColorNumber.GREEN,
[ColorId.BLUE]: ColorNumber.BLUE
};
(ColorIdToNumber[ColorId.GREEN]: \"ffffff\");
// oops
module.exports = ColorIdToNumber;
"
`;
exports[`test test3.js 1`] = `
"var { ColorId } = require(\'./test\');
var ColorIdToNumber = require(\'./test2\');
(ColorIdToNumber[ColorId.BLUE]: \'ffffff\'); // oops
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
var { ColorId } = require(\"./test\");
var ColorIdToNumber = require(\"./test2\");
(ColorIdToNumber[ColorId.BLUE]: \"ffffff\"); // oops
"
`;
exports[`test test4.js 1`] = `
"module.exports = \'hello\';
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
module.exports = \"hello\";
"
`;
exports[`test test5.js 1`] = `
"var hello = require(\'./test4\');
var dummy = require(\'./test\');
module.exports = {
...dummy,
[hello]: \'world\',
...dummy,
};
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
var hello = require(\"./test4\");
var dummy = require(\"./test\");
module.exports = { ...dummy, [hello]: \"world\", ...dummy };
"
`;
exports[`test test6.js 1`] = `
"var o = require(\'./test5\');
(o.hello: \'nothing\'); // oops
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
var o = require(\"./test5\");
(o.hello: \"nothing\"); // oops
"
`;
exports[`test test7.js 1`] = `
"var obj = {x: 0, m() { return this.x }}
var x: string = obj[\'m\'](); // error, number ~> string
var arr = [function() { return this.length }];
var y: string = arr[0](); // error: number ~> string
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
var obj = {
x: 0,
m() {
return this.x;
}
};
var x: string = obj[\"m\"]();
// error, number ~> string
var arr = [
function() {
return this.length;
}
];
var y: string = arr[0](); // error: number ~> string
"
`;

View File

@ -0,0 +1,14 @@
exports[`test test.js 1`] = `
"\"use strict\";
function fn() {
\"use strict\";
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
\"use strict\";
function fn() {
\"use strict\";
}
"
`;

File diff suppressed because it is too large Load Diff

View File

@ -1,34 +1,6 @@
exports[`test P.js 1`] = `
"module.exports = require(\'M\');
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
module.exports = require(\"M\");
"
`;
exports[`test body.js 1`] = `
"export default (class {}[1] = 1);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
export default ((class {})[1] = 1);
"
`;
exports[`test test.js 1`] = `
"var M = require(\'M\');
var N = require(\'N\');
N.x = M(N.x);
var P = require(\'./P\'); // implementation of P redirects to module M
N.y = P(N.y);
var Q = require(\'Q\'); // declaration of Q redirects to module M
N.z = Q(N.z);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
var M = require(\"M\");
var N = require(\"N\");
N.x = M(N.x);
var P = require(\"./P\");
// implementation of P redirects to module M
N.y = P(N.y);
var Q = require(\"Q\");
// declaration of Q redirects to module M
N.z = Q(N.z);
"
`;

View File

@ -0,0 +1,12 @@
exports[`test test.js 1`] = `
"export { value1, value2 as value2_renamed, value3, value4 as value4_renamed, value5 } from \"exports\";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
export {
value1,
value2 as value2_renamed,
value3,
value4 as value4_renamed,
value5
} from \"exports\";
"
`;

View File

@ -0,0 +1,20 @@
exports[`test test.js 1`] = `
"var A = [1,2,3];
var B = [...A];
var C = [1,2,3];
B.sort((a, b) => a - b);
C.sort((a, b) => a - b);
var x: Array<string> = [\'1\', \'2\'];
var y: Array<string> = [\'3\', ...x];
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
var A = [1, 2, 3];
var B = [...A];
var C = [1, 2, 3];
B.sort((a, b) => a - b);
C.sort((a, b) => a - b);
var x: Array<string> = [\"1\", \"2\"];
var y: Array<string> = [\"3\", ...x];
"
`;

View File

@ -0,0 +1,100 @@
exports[`test Arrays.js 1`] = `
"
/* @providesModule Arrays */
function foo(x:string) { }
var a = [];
a[0] = 1;
a[1] = \"...\";
foo(a[1]);
var y;
a.forEach(x => y=x);
// for literals, composite element type is union of individuals
// note: test both tuple and non-tuple inferred literals
var alittle: Array<?number> = [0, 1, 2, 3, null];
var abig: Array<?number> = [0, 1, 2, 3, 4, 5, 6, 8, null];
var abig2: Array<{x:number; y:number}> = [
{x:0, y:0},
{x:0, y:0},
{x:0, y:0},
{x:0, y:0},
{x:0, y:0},
{x:0, y:0},
{x:0, y:0},
{x:0, y:0},
{x:0, y:0},
{x:0, y:0},
{x:0, y:0},
{x:0, y:0},
{x:0, y:0},
{x:0, y:0, a:true},
{x:0, y:0, b:\"hey\"},
{x:0, y:0, c:1},
{x:0, y:0, c:\"hey\"}
];
module.exports = \"arrays\";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/* @providesModule Arrays */
function foo(x: string) {}
var a = [];
a[0] = 1;
a[1] = \"...\";
foo(a[1]);
var y;
a.forEach(x => y = x);
// for literals, composite element type is union of individuals
// note: test both tuple and non-tuple inferred literals
var alittle: Array<?number> = [0, 1, 2, 3, null];
var abig: Array<?number> = [0, 1, 2, 3, 4, 5, 6, 8, null];
var abig2: Array<{ x: number, y: number }> = [
{ x: 0, y: 0 },
{ x: 0, y: 0 },
{ x: 0, y: 0 },
{ x: 0, y: 0 },
{ x: 0, y: 0 },
{ x: 0, y: 0 },
{ x: 0, y: 0 },
{ x: 0, y: 0 },
{ x: 0, y: 0 },
{ x: 0, y: 0 },
{ x: 0, y: 0 },
{ x: 0, y: 0 },
{ x: 0, y: 0 },
{ x: 0, y: 0, a: true },
{ x: 0, y: 0, b: \"hey\" },
{ x: 0, y: 0, c: 1 },
{ x: 0, y: 0, c: \"hey\" }
];
module.exports = \"arrays\";
"
`;
exports[`test numeric_elem.js 1`] = `
"var arr = [];
var day = new Date;
// Date instances are numeric (see Flow_js.numeric) and thus can index into
// arrays.
arr[day] = 0;
(arr[day]: string); // error: number ~> string
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
var arr = [];
var day = new Date();
// Date instances are numeric (see Flow_js.numeric) and thus can index into
// arrays.
arr[day] = 0;
(arr[day]: string); // error: number ~> string
"
`;

View File

@ -0,0 +1,52 @@
exports[`test advanced_arrows.js 1`] = `
"/**
* @flow
*/
var add = (x: number, y: number): number => x + y;
var bad = (x: number): string => x; // Error!
var ident = <T>(x: T): T => x;
(ident(1): number);
(ident(\"hi\"): number); // Error
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/**
* @flow
*/
var add = (x: number, y: number): number => x + y;
var bad = (x: number): string => x;
// Error!
var ident = <T>(x: T): T => x;
(ident(1): number);
(ident(\"hi\"): number); // Error
"
`;
exports[`test arrows.js 1`] = `
"function selectBestEffortImageForWidth(
maxWidth: number,
images: Array<Image>
): Image {
var maxPixelWidth = maxWidth;
//images = images.sort(function (a, b) { return a.width - b.width });
images = images.sort((a, b) => (a.width - b.width) + \"\");
return images.find(image => image.width >= maxPixelWidth) ||
images[images.length - 1];
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function selectBestEffortImageForWidth(
maxWidth: number,
images: Array<Image>
): Image {
var maxPixelWidth = maxWidth;
//images = images.sort(function (a, b) { return a.width - b.width });
images = images.sort((a, b) => a.width - b.width + \"\");
return images.find(image => image.width >= maxPixelWidth) ||
images[images.length - 1];
}
"
`;

View File

@ -8,5 +8,3 @@ function selectBestEffortImageForWidth(
return images.find(image => image.width >= maxPixelWidth) ||
images[images.length - 1];
}
a = () => ({} = this);

View File

@ -0,0 +1,519 @@
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;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// @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<boolean> {
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<boolean> {
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;
"
`;
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;
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// 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;
}
"
`;
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 };
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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 };
"
`;
exports[`test async_promise.js 1`] = `
"async function f(): Promise<number> {
return Promise.resolve(1);
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
async function f(): Promise<number> {
return Promise.resolve(1);
}
"
`;
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();
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// @flow
async function foo1(): Promise<string> {
return;
}
async function foo2(): Promise<string> {
return undefined;
}
async function foo3(): Promise<string> {
function bar() {}
return bar();
}
"
`;
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\");
}
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// @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\");
}
}
"
`;
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_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 };
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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 };
"
`;

View File

@ -0,0 +1,24 @@
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 };

Some files were not shown because too many files have changed in this diff Show More