283 lines
4.9 KiB
Plaintext
283 lines
4.9 KiB
Plaintext
![]() |
exports[`test destructuring.js 1`] = `
|
||
|
"// @flow
|
||
|
|
||
|
let [x, y] = [1, 2];
|
||
|
|
||
|
/**
|
||
|
* Test what happens when the destructuring is unevaluated. In this case,
|
||
|
* \`this\` in a function is unbound, so we never actually find out the type of
|
||
|
* \`this.returnsATuple()\` is; thus, we never evaluate \`b\` and so type-at-pos
|
||
|
* returns EmptyT.
|
||
|
*/
|
||
|
export const X = {
|
||
|
returnsATuple: function(): [number, number] {
|
||
|
return [1, 2];
|
||
|
},
|
||
|
|
||
|
test: function() {
|
||
|
let [a, b] = this.returnsATuple();
|
||
|
}
|
||
|
};
|
||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||
|
// @flow
|
||
![]() |
|
||
![]() |
let [x, y] = [1, 2];
|
||
![]() |
|
||
![]() |
/**
|
||
|
* Test what happens when the destructuring is unevaluated. In this case,
|
||
|
* \`this\` in a function is unbound, so we never actually find out the type of
|
||
|
* \`this.returnsATuple()\` is; thus, we never evaluate \`b\` and so type-at-pos
|
||
|
* returns EmptyT.
|
||
|
*/
|
||
|
export const X = {
|
||
![]() |
returnsATuple: function(): [number, number] {
|
||
![]() |
return [1, 2];
|
||
![]() |
},
|
||
|
test: function() {
|
||
![]() |
let [a, b] = this.returnsATuple();
|
||
![]() |
}
|
||
![]() |
};
|
||
|
"
|
||
![]() |
`;
|
||
|
|
||
|
exports[`test function_expressions.js 1`] = `
|
||
|
"// @flow
|
||
|
|
||
|
// TODO: type-at-pos between the ()\'s should be () => void
|
||
|
// class X {
|
||
|
// foo(): void {}
|
||
|
// }
|
||
|
|
||
|
const y = {
|
||
|
bar(): void {}
|
||
|
};
|
||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||
|
// @flow
|
||
![]() |
|
||
![]() |
// TODO: type-at-pos between the ()\'s should be () => void
|
||
|
// class X {
|
||
|
// foo(): void {}
|
||
|
// }
|
||
![]() |
|
||
![]() |
const y = { bar(): void {} };
|
||
![]() |
"
|
||
![]() |
`;
|
||
|
|
||
|
exports[`test generics.js 1`] = `
|
||
|
"// @flow
|
||
|
|
||
|
class C<X> { }
|
||
|
var cn: C<number> = new C;
|
||
|
cn;
|
||
|
|
||
|
function foo() { return C; }
|
||
|
var D = foo();
|
||
|
var dn: D<number> = new C;
|
||
|
dn;
|
||
|
|
||
|
type E<X> = C<X>;
|
||
|
var en: E<number> = new C;
|
||
|
en;
|
||
|
|
||
|
type F<X> = C<void>;
|
||
|
var fn: F<number> = new C;
|
||
|
fn;
|
||
|
|
||
|
type O<X> = { x: X };
|
||
|
var on: O<number> = { x: 0 };
|
||
|
on;
|
||
|
|
||
|
type Mono = C<void>;
|
||
|
var mn: Mono<number> = new C; // error: application of non-poly type
|
||
|
mn;
|
||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||
|
// @flow
|
||
![]() |
|
||
![]() |
class C<X> {}
|
||
![]() |
var cn: C<number> = new C();
|
||
![]() |
cn;
|
||
![]() |
|
||
![]() |
function foo() {
|
||
|
return C;
|
||
|
}
|
||
|
var D = foo();
|
||
![]() |
var dn: D<number> = new C();
|
||
![]() |
dn;
|
||
![]() |
|
||
![]() |
type E<X> = C<X>;
|
||
![]() |
var en: E<number> = new C();
|
||
![]() |
en;
|
||
![]() |
|
||
![]() |
type F<X> = C<void>;
|
||
![]() |
var fn: F<number> = new C();
|
||
![]() |
fn;
|
||
![]() |
|
||
![]() |
type O<X> = { x: X };
|
||
|
var on: O<number> = { x: 0 };
|
||
|
on;
|
||
![]() |
|
||
![]() |
type Mono = C<void>;
|
||
![]() |
var mn: Mono<number> = new C();
|
||
![]() |
// error: application of non-poly type
|
||
![]() |
mn;
|
||
|
"
|
||
![]() |
`;
|
||
|
|
||
|
exports[`test import.js 1`] = `
|
||
|
"// @flow
|
||
|
var num = 42;
|
||
|
function bar() { }
|
||
|
bar();
|
||
|
module.exports = num;
|
||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||
|
// @flow
|
||
|
var num = 42;
|
||
![]() |
function bar() {}
|
||
![]() |
bar();
|
||
![]() |
module.exports = num;
|
||
|
"
|
||
![]() |
`;
|
||
|
|
||
|
exports[`test object_special_cases.js 1`] = `
|
||
|
"/* @flow */
|
||
|
|
||
|
let tests = [
|
||
|
function() {
|
||
|
let x = {};
|
||
|
Object.defineProperty(x, \'foo\', { value: \'\' });
|
||
|
},
|
||
|
];
|
||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||
|
/* @flow */
|
||
![]() |
|
||
![]() |
let tests = [
|
||
|
function() {
|
||
|
let x = {};
|
||
|
Object.defineProperty(x, \"foo\", { value: \"\" });
|
||
|
}
|
||
![]() |
];
|
||
|
"
|
||
![]() |
`;
|
||
|
|
||
|
exports[`test optional.js 1`] = `
|
||
|
"// @flow
|
||
|
|
||
|
function foo(x?: string) {
|
||
|
return x;
|
||
|
}
|
||
|
|
||
|
foo();
|
||
|
|
||
|
function bar(obj: { x?: string }) {
|
||
|
return obj.x;
|
||
|
}
|
||
|
|
||
|
function qux(x?) {
|
||
|
return x;
|
||
|
}
|
||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||
|
// @flow
|
||
![]() |
|
||
![]() |
function foo(x?: string) {
|
||
![]() |
return x;
|
||
|
}
|
||
![]() |
|
||
![]() |
foo();
|
||
![]() |
|
||
![]() |
function bar(obj: { x?: string }) {
|
||
|
return obj.x;
|
||
|
}
|
||
![]() |
|
||
![]() |
function qux(x?) {
|
||
![]() |
return x;
|
||
![]() |
}
|
||
|
"
|
||
![]() |
`;
|
||
|
|
||
|
exports[`test predicates.js 1`] = `
|
||
|
"/* @flow */
|
||
|
|
||
|
let x = 0;
|
||
|
if (x == null) {}
|
||
|
if (x == undefined) {}
|
||
|
if (Array.isArray(x)) {}
|
||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||
|
/* @flow */
|
||
![]() |
|
||
![]() |
let x = 0;
|
||
![]() |
if (x == null) {
|
||
|
}
|
||
|
if (x == undefined) {
|
||
|
}
|
||
|
if (Array.isArray(x)) {
|
||
|
}
|
||
![]() |
"
|
||
![]() |
`;
|
||
|
|
||
|
exports[`test react.js 1`] = `
|
||
|
"import React from \"react\";
|
||
|
React.createElement;
|
||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||
|
import React from \"react\";
|
||
![]() |
React.createElement;
|
||
|
"
|
||
![]() |
`;
|
||
|
|
||
|
exports[`test templates.js 1`] = `
|
||
|
"/* @flow */
|
||
|
\`foo bar\`;
|
||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||
|
/* @flow */
|
||
![]() |
\`foo bar\`;
|
||
|
"
|
||
![]() |
`;
|
||
|
|
||
|
exports[`test test.js 1`] = `
|
||
|
"// @flow
|
||
|
var str = require(\'./import\');
|
||
|
function foo() { }
|
||
|
foo();
|
||
|
str
|
||
|
|
||
|
type Point = [number, string];
|
||
|
const x:Point = [1, \"foo\"];
|
||
|
type MyStr = \"cool\";
|
||
|
const y:MyStr = \"cool\";
|
||
|
type MyBool = true;
|
||
|
const z:MyBool = true;
|
||
|
type MyNum = 42;
|
||
|
const w:MyNum = 42;
|
||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||
|
// @flow
|
||
|
var str = require(\"./import\");
|
||
![]() |
function foo() {}
|
||
![]() |
foo();
|
||
|
str;
|
||
![]() |
|
||
![]() |
type Point = [number, string];
|
||
![]() |
const x: Point = [1, \"foo\"];
|
||
![]() |
type MyStr = \"cool\";
|
||
|
const y: MyStr = \"cool\";
|
||
|
type MyBool = true;
|
||
|
const z: MyBool = true;
|
||
|
type MyNum = 42;
|
||
![]() |
const w: MyNum = 42;
|
||
|
"
|
||
![]() |
`;
|
||
|
|
||
|
exports[`test trycatch.js 1`] = `
|
||
|
"// @flow
|
||
|
|
||
|
try {
|
||
|
throw \"foo\";
|
||
|
} catch (e) {}
|
||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||
|
// @flow
|
||
![]() |
|
||
![]() |
try {
|
||
|
throw \"foo\";
|
||
![]() |
} catch (e) {
|
||
|
}
|
||
![]() |
"
|
||
![]() |
`;
|