Keep blank lines from original source
parent
78a9da2ff4
commit
bcd44b4368
1
index.js
1
index.js
|
@ -49,6 +49,7 @@ module.exports = {
|
|||
});
|
||||
}
|
||||
|
||||
opts.originalText = text;
|
||||
ast.tokens = [];
|
||||
|
||||
const printer = new Printer(opts);
|
||||
|
|
|
@ -1600,7 +1600,6 @@ function printStatementSequence(path, options, print) {
|
|||
let inClassBody = namedTypes.ClassBody &&
|
||||
namedTypes.ClassBody.check(path.getParentNode());
|
||||
let printed = [];
|
||||
let prevAddSpacing = false;
|
||||
|
||||
path.map(function(stmtPath, i) {
|
||||
var stmt = stmtPath.getValue();
|
||||
|
@ -1617,23 +1616,16 @@ function printStatementSequence(path, options, print) {
|
|||
return;
|
||||
}
|
||||
|
||||
const addSpacing = shouldAddSpacing(stmt);
|
||||
const stmtPrinted = print(stmtPath);
|
||||
const parts = [];
|
||||
|
||||
if (!prevAddSpacing && addSpacing && !isFirstStatement(stmtPath)) {
|
||||
parts.push(hardline);
|
||||
}
|
||||
|
||||
parts.push(stmtPrinted);
|
||||
|
||||
if (addSpacing && !isLastStatement(stmtPath)) {
|
||||
if (shouldAddSpacing(stmt, options) && !isLastStatement(stmtPath)) {
|
||||
parts.push(hardline);
|
||||
}
|
||||
|
||||
printed.push(concat(parts));
|
||||
|
||||
prevAddSpacing = addSpacing;
|
||||
});
|
||||
|
||||
return join(hardline, printed);
|
||||
|
@ -2073,12 +2065,28 @@ function nodeStr(str, options) {
|
|||
}
|
||||
}
|
||||
|
||||
function shouldAddSpacing(node) {
|
||||
return node.type === "IfStatement" || node.type === "ForStatement" ||
|
||||
node.type === "ForInStatement" ||
|
||||
node.type === "ForOfStatement" ||
|
||||
node.type === "ExpressionStatement" ||
|
||||
node.type === "FunctionDeclaration";
|
||||
function shouldAddSpacing(node, options) {
|
||||
const text = options.originalText;
|
||||
const length = text.length;
|
||||
let cursor = node.end + 1;
|
||||
// Look forward and see if there is a blank line after this code by
|
||||
// scanning up to the next non-indentation character.
|
||||
while(cursor < length) {
|
||||
const c = text.charAt(cursor);
|
||||
// Skip any indentation characters (this will detect lines with
|
||||
// spaces or tabs as blank)
|
||||
if(c !== " " && c !== "\t") {
|
||||
// If the next character is a newline, this line is blank so we
|
||||
// should add a blank line.
|
||||
if(c === "\n" || c === "\r") {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
cursor++;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function isFirstStatement(path) {
|
||||
|
|
1980
src/printer2.js
1980
src/printer2.js
File diff suppressed because it is too large
Load Diff
|
@ -12,7 +12,6 @@ function foo() {
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
function bar() {
|
||||
L:
|
||||
do {
|
||||
|
@ -31,13 +30,10 @@ function foo() {
|
|||
}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
function bar(x: number) {}
|
||||
|
||||
function foo() {
|
||||
var x = null;
|
||||
|
||||
if (x == null)
|
||||
return;
|
||||
|
||||
bar(x);
|
||||
}
|
||||
"
|
||||
|
|
|
@ -73,7 +73,6 @@ function barfoo(n : number | null | void) : ?number { return n; }
|
|||
function foo(str: string, i: number): string {
|
||||
return str;
|
||||
}
|
||||
|
||||
var bar: (str: number, i: number) => string = foo;
|
||||
var qux = function(str: string, i: number): number {
|
||||
return foo(str, i);
|
||||
|
@ -94,11 +93,9 @@ var array_of_tuple: [number, string][] = [ [ 0, \"foo\" ], [ 1, \"bar\" ] ];
|
|||
var array_of_tuple_parens: [number, string][] = array_of_tuple;
|
||||
type ObjType = { \"bar-foo\": string, \"foo-bar\": number };
|
||||
var test_obj: ObjType = { \"bar-foo\": \"23\" };
|
||||
|
||||
function param_anno(n: number): void {
|
||||
n = \"hey\";
|
||||
}
|
||||
|
||||
function param_anno2(
|
||||
batchRequests: Array<{ method: string, path: string, params: ?Object }>
|
||||
): void {
|
||||
|
@ -110,14 +107,11 @@ function param_anno2(
|
|||
};
|
||||
});
|
||||
}
|
||||
|
||||
var toz: null = 3;
|
||||
var zer: null = null;
|
||||
|
||||
function foobar(n: ?number): number | null | void {
|
||||
return n;
|
||||
}
|
||||
|
||||
function barfoo(n: number | null | void): ?number {
|
||||
return n;
|
||||
}
|
||||
|
@ -146,20 +140,15 @@ function foo() {
|
|||
// ok (no confusion across scopes)
|
||||
// looked up above
|
||||
let myClassInstance: MyClass = null;
|
||||
|
||||
function bar(): MyClass {
|
||||
return null;
|
||||
}
|
||||
|
||||
class MyClass {}
|
||||
|
||||
function foo() {
|
||||
let myClassInstance: MyClass = mk();
|
||||
|
||||
function mk() {
|
||||
return new MyClass();
|
||||
}
|
||||
|
||||
class MyClass {}
|
||||
}
|
||||
"
|
||||
|
@ -171,7 +160,6 @@ exports[`test issue-530.js 1`] = `
|
|||
module.exports = foo;
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
function foo(...args: any) {}
|
||||
|
||||
module.exports = foo;
|
||||
"
|
||||
`;
|
||||
|
@ -212,11 +200,9 @@ function bar(y: MyObj): string {
|
|||
* leading to an error.
|
||||
*/
|
||||
type MyObj = Object;
|
||||
|
||||
function foo(x: { [key: string]: mixed }) {
|
||||
bar(x);
|
||||
}
|
||||
|
||||
function bar(y: MyObj): string {
|
||||
return y.foo;
|
||||
}
|
||||
|
@ -228,7 +214,6 @@ exports[`test other.js 1`] = `
|
|||
module.exports = (C: any);
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
class C {}
|
||||
|
||||
module.exports = (C: any);
|
||||
"
|
||||
`;
|
||||
|
@ -266,7 +251,6 @@ declare class Map<K, V> {
|
|||
insertWith(fn: Merge<V>, k: K, v: V): Map<K, V>
|
||||
}
|
||||
declare function foldr<A, B>(fn: (a: A, b: B) => B, b: B, as: A[]): B;
|
||||
|
||||
function insertMany<K, V>(
|
||||
merge: Merge<V>,
|
||||
vs: [K, V][],
|
||||
|
@ -275,10 +259,8 @@ function insertMany<K, V>(
|
|||
function f([ k, v ]: [K, V], m: Map<K, V>): Map<K, V> {
|
||||
return m.insertWith(merge, k, v);
|
||||
}
|
||||
|
||||
return foldr(f, m, vs);
|
||||
}
|
||||
|
||||
class Foo<A> {
|
||||
bar<B>() {
|
||||
return function<C>(a: A, b: B, c: C): void {
|
||||
|
@ -294,7 +276,6 @@ exports[`test test.js 1`] = `
|
|||
((0: C): string);
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
var C = require(\"./other\");
|
||||
|
||||
((0: C): string);
|
||||
"
|
||||
`;
|
||||
|
|
|
@ -13,15 +13,12 @@ var z:string = qux(0);
|
|||
function foo(x: any): any {
|
||||
return x;
|
||||
}
|
||||
|
||||
function bar(x: any): mixed {
|
||||
return x;
|
||||
}
|
||||
|
||||
function qux(x: mixed): any {
|
||||
return x;
|
||||
}
|
||||
|
||||
var x: string = foo(0);
|
||||
var y: string = bar(0);
|
||||
var z: string = qux(0);
|
||||
|
@ -71,19 +68,15 @@ var w:string = baz(0);
|
|||
function foo(x: $FlowFixMe): $FlowFixMe {
|
||||
return x;
|
||||
}
|
||||
|
||||
function bar(x: $FlowFixMe): mixed {
|
||||
return x;
|
||||
}
|
||||
|
||||
function qux(x: $FlowFixMe<number>): $FlowFixMe<number> {
|
||||
return x;
|
||||
}
|
||||
|
||||
function baz(x: $FlowFixMe<nnumber>): $FlowFixMe<number> {
|
||||
return x;
|
||||
}
|
||||
|
||||
var x: string = foo(0);
|
||||
var y: string = bar(0);
|
||||
var z: string = qux(0);
|
||||
|
@ -124,19 +117,15 @@ var w:string = baz(0);
|
|||
function foo(x: $FlowIssue): $FlowIssue {
|
||||
return x;
|
||||
}
|
||||
|
||||
function bar(x: $FlowIssue): mixed {
|
||||
return x;
|
||||
}
|
||||
|
||||
function qux(x: $FlowIssue<number>): $FlowIssue<number> {
|
||||
return x;
|
||||
}
|
||||
|
||||
function baz(x: $FlowIssue<nnumber>): $FlowIssue<number> {
|
||||
return x;
|
||||
}
|
||||
|
||||
var x: string = foo(0);
|
||||
var y: string = bar(0);
|
||||
var z: string = qux(0);
|
||||
|
@ -187,22 +176,17 @@ declare class C {
|
|||
bar(n1: number, n2: number): number,
|
||||
bar(s1: string, s2: string): string
|
||||
}
|
||||
|
||||
function foo(c: C, x: any): string {
|
||||
let y = x.y;
|
||||
return c.bar(0, y);
|
||||
}
|
||||
|
||||
var any_fun1 = require(\"./nonflowfile\");
|
||||
|
||||
function bar1(x: mixed) {
|
||||
if (any_fun1(x)) {
|
||||
(x: boolean);
|
||||
}
|
||||
}
|
||||
|
||||
var any_fun2 = require(\"./anyexportflowfile\");
|
||||
|
||||
function bar2(x: mixed) {
|
||||
if (any_fun2(x)) {
|
||||
(x: boolean);
|
||||
|
@ -232,7 +216,6 @@ function foo(o: ?AsyncRequest) {
|
|||
* annotation - without it, the body of the if will be unreachable
|
||||
*/
|
||||
type AsyncRequest = any;
|
||||
|
||||
function foo(o: ?AsyncRequest) {
|
||||
if (o) {
|
||||
var n: number = o;
|
||||
|
|
|
@ -133,113 +133,71 @@ let tests = [
|
|||
// error, string ~> empty
|
||||
// error, string ~> empty
|
||||
function num(x: number) {}
|
||||
|
||||
function str(x: string) {}
|
||||
|
||||
function foo() {
|
||||
var x = 0;
|
||||
var y = \"...\";
|
||||
var z = {};
|
||||
|
||||
num(x + x);
|
||||
|
||||
num(x + y);
|
||||
|
||||
str(x + y);
|
||||
|
||||
str(x + x);
|
||||
|
||||
str(z + y);
|
||||
}
|
||||
|
||||
function bar0(x: ?number, y: number) {
|
||||
num(x + y);
|
||||
}
|
||||
|
||||
function bar1(x: number, y: ?number) {
|
||||
num(x + y);
|
||||
}
|
||||
|
||||
function bar2(x?: number, y: number) {
|
||||
num(x + y);
|
||||
}
|
||||
|
||||
function bar3(x: number, y?: number) {
|
||||
num(x + y);
|
||||
}
|
||||
|
||||
function bar4(x?: ?number, y: number) {
|
||||
num(x + y);
|
||||
}
|
||||
|
||||
function bar5(x: number, y?: ?number) {
|
||||
num(x + y);
|
||||
}
|
||||
|
||||
num(null + null);
|
||||
|
||||
num(undefined + undefined);
|
||||
|
||||
num(null + 1);
|
||||
|
||||
num(1 + null);
|
||||
|
||||
num(undefined + 1);
|
||||
|
||||
num(1 + undefined);
|
||||
|
||||
num(null + true);
|
||||
|
||||
num(true + null);
|
||||
|
||||
num(undefined + true);
|
||||
|
||||
num(true + undefined);
|
||||
|
||||
str(\"foo\" + true);
|
||||
|
||||
str(true + \"foo\");
|
||||
|
||||
str(\"foo\" + null);
|
||||
|
||||
str(null + \"foo\");
|
||||
|
||||
str(\"foo\" + undefined);
|
||||
|
||||
str(undefined + \"foo\");
|
||||
|
||||
let tests = [
|
||||
function(x: mixed, y: mixed) {
|
||||
x + y;
|
||||
|
||||
x + 0;
|
||||
|
||||
0 + x;
|
||||
|
||||
x + \"\";
|
||||
|
||||
\"\" + x;
|
||||
|
||||
x + {};
|
||||
|
||||
({}) + x;
|
||||
},
|
||||
function() {
|
||||
(1 + {}: number);
|
||||
|
||||
({} + 1: number);
|
||||
|
||||
(\"1\" + {}: string);
|
||||
|
||||
({} + \"1\": string);
|
||||
},
|
||||
function(x: any, y: number, z: string) {
|
||||
(x + y: string);
|
||||
|
||||
(y + x: string);
|
||||
|
||||
(x + z: empty);
|
||||
|
||||
(z + x: empty);
|
||||
}
|
||||
];
|
||||
|
@ -262,17 +220,11 @@ y **= 2; // error
|
|||
/* @flow */
|
||||
// error
|
||||
let x: number = 2 ** 3;
|
||||
|
||||
x **= 4;
|
||||
|
||||
let y: string = \"123\";
|
||||
|
||||
y **= 2;
|
||||
|
||||
1 + 2 ** 3 + 4;
|
||||
|
||||
2 ** 2;
|
||||
|
||||
(-2) ** 2;
|
||||
"
|
||||
`;
|
||||
|
@ -295,19 +247,15 @@ function f<A,B>(a: A, b: B): B {return b + a; } // error
|
|||
function f<A>(a: A): A {
|
||||
return a + a;
|
||||
}
|
||||
|
||||
function f<A, B>(a: A, b: B): A {
|
||||
return a + b;
|
||||
}
|
||||
|
||||
function f<A, B>(a: A, b: B): A {
|
||||
return b + a;
|
||||
}
|
||||
|
||||
function f<A, B>(a: A, b: B): B {
|
||||
return a + b;
|
||||
}
|
||||
|
||||
function f<A, B>(a: A, b: B): B {
|
||||
return b + a;
|
||||
}
|
||||
|
@ -331,17 +279,11 @@ y *= 2; // error
|
|||
/* @flow */
|
||||
// error
|
||||
function num(x: number) {}
|
||||
|
||||
num(null * 1);
|
||||
|
||||
num(1 * null);
|
||||
|
||||
let x: number = 2 * 3;
|
||||
|
||||
x *= 4;
|
||||
|
||||
let y: string = \"123\";
|
||||
|
||||
y *= 2;
|
||||
"
|
||||
`;
|
||||
|
@ -393,47 +335,27 @@ let tests = [
|
|||
// error
|
||||
// error
|
||||
1 < 2;
|
||||
|
||||
1 < \"foo\";
|
||||
|
||||
\"foo\" < 1;
|
||||
|
||||
\"foo\" < \"bar\";
|
||||
|
||||
1 < { foo: 1 };
|
||||
|
||||
({ foo: 1 }) < 1;
|
||||
|
||||
({ foo: 1 }) < { foo: 1 };
|
||||
|
||||
\"foo\" < { foo: 1 };
|
||||
|
||||
({ foo: 1 }) < \"foo\";
|
||||
|
||||
var x = (null: ?number);
|
||||
|
||||
1 < x;
|
||||
|
||||
x < 1;
|
||||
|
||||
null < null;
|
||||
|
||||
undefined < null;
|
||||
|
||||
null < undefined;
|
||||
|
||||
undefined < undefined;
|
||||
|
||||
NaN < 1;
|
||||
|
||||
1 < NaN;
|
||||
|
||||
NaN < NaN;
|
||||
|
||||
let tests = [
|
||||
function(x: any, y: number, z: string) {
|
||||
x > y;
|
||||
|
||||
x > z;
|
||||
}
|
||||
];
|
||||
|
|
|
@ -13,7 +13,6 @@ function filterOutSmall (arr: Array<?number>): Array<?number> {
|
|||
function filterOutVoids<T>(arr: Array<?T>): Array<T> {
|
||||
return arr.filter(Boolean);
|
||||
}
|
||||
|
||||
function filterOutSmall(arr: Array<?number>): Array<?number> {
|
||||
return arr.filter(num => num && num > 10);
|
||||
}
|
||||
|
@ -47,9 +46,7 @@ function filterItems(items: Array<string | number>): Array<string | number> {
|
|||
}
|
||||
}).filter(Boolean);
|
||||
}
|
||||
|
||||
const filteredItems = filterItems([ \"foo\", \"b\", 1, 2 ]);
|
||||
|
||||
console.log(filteredItems);
|
||||
"
|
||||
`;
|
||||
|
|
|
@ -11,11 +11,8 @@ 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 ];
|
||||
"
|
||||
|
|
|
@ -67,11 +67,9 @@ function from_test() {
|
|||
// error, string ~> number
|
||||
// error, string ~> number
|
||||
function foo(x: string) {}
|
||||
|
||||
var a = [ 0 ];
|
||||
var b = a.map(function(x) {
|
||||
foo(x);
|
||||
|
||||
return \"\" + x;
|
||||
});
|
||||
var c: number = a[0];
|
||||
|
@ -88,31 +86,25 @@ var k: Array<number> = h.concat(h);
|
|||
var l: Array<number> = h.concat(1, 2, 3);
|
||||
var m: Array<number | string> = h.concat(\"a\", \"b\", \"c\");
|
||||
var n: Array<number> = h.concat(\"a\", \"b\", \"c\");
|
||||
|
||||
function reduce_test() {
|
||||
[ 0, 1, 2, 3, 4 ].reduce(function(previousValue, currentValue, index, array) {
|
||||
return previousValue + currentValue + array[index];
|
||||
});
|
||||
|
||||
[ 0, 1, 2, 3, 4 ].reduce(
|
||||
function(previousValue, currentValue, index, array) {
|
||||
return previousValue + currentValue + array[index];
|
||||
},
|
||||
10
|
||||
);
|
||||
|
||||
var total = [ 0, 1, 2, 3 ].reduce(function(a, b) {
|
||||
return a + b;
|
||||
});
|
||||
var flattened = [ [ 0, 1 ], [ 2, 3 ], [ 4, 5 ] ].reduce(function(a, b) {
|
||||
return a.concat(b);
|
||||
});
|
||||
|
||||
[ \"\" ].reduce((acc, str) => acc * str.length);
|
||||
|
||||
[ \"\" ].reduceRight((acc, str) => acc * str.length);
|
||||
}
|
||||
|
||||
function from_test() {
|
||||
var a: Array<string> = Array.from([ 1, 2, 3 ], function(val, index) {
|
||||
return index % 2 ? \"foo\" : String(val);
|
||||
|
|
|
@ -43,19 +43,12 @@ module.exports = \"arrays\";
|
|||
// for literals, composite element type is union of individuals
|
||||
// note: test both tuple and non-tuple inferred literals
|
||||
function foo(x: string) {}
|
||||
|
||||
var a = [];
|
||||
|
||||
a[0] = 1;
|
||||
|
||||
a[1] = \"...\";
|
||||
|
||||
foo(a[1]);
|
||||
|
||||
var y;
|
||||
|
||||
a.forEach(x => y = x);
|
||||
|
||||
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 }> = [
|
||||
|
@ -77,7 +70,6 @@ var abig2: Array<{ x: number, y: number }> = [
|
|||
{ x: 0, y: 0, c: 1 },
|
||||
{ x: 0, y: 0, c: \"hey\" }
|
||||
];
|
||||
|
||||
module.exports = \"arrays\";
|
||||
"
|
||||
`;
|
||||
|
@ -96,9 +88,7 @@ arr[day] = 0;
|
|||
// error: number ~> string
|
||||
var arr = [];
|
||||
var day = new Date();
|
||||
|
||||
arr[day] = 0;
|
||||
|
||||
(arr[day]: string);
|
||||
"
|
||||
`;
|
||||
|
|
|
@ -19,9 +19,7 @@ var ident = <T>(x: T): T => x;
|
|||
var add = (x: number, y: number): number => x + y;
|
||||
var bad = (x: number): string => x;
|
||||
var ident = <T>(x: T): T => x;
|
||||
|
||||
(ident(1): number);
|
||||
|
||||
(ident(\"hi\"): number);
|
||||
"
|
||||
`;
|
||||
|
@ -44,9 +42,7 @@ function selectBestEffortImageForWidth(
|
|||
images: Array<Image>
|
||||
): Image {
|
||||
var maxPixelWidth = maxWidth;
|
||||
|
||||
images = images.sort((a, b) => a.width - b.width + \"\");
|
||||
|
||||
return images.find(image => image.width >= maxPixelWidth) ||
|
||||
images[images.length - 1];
|
||||
}
|
||||
|
|
|
@ -71,25 +71,20 @@ var objf : () => Promise<number> = obj.f;
|
|||
async function f0(): Promise<number> {
|
||||
return 1;
|
||||
}
|
||||
|
||||
async function f1(): Promise<boolean> {
|
||||
return 1;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
async function f4(p: Promise<number>): Promise<boolean> {
|
||||
return await p;
|
||||
}
|
||||
|
||||
var f5: () => Promise<number> = async () => await 1;
|
||||
class C {
|
||||
async m() {
|
||||
|
@ -134,7 +129,6 @@ class C {}
|
|||
var P: Promise<Class<C>> = new Promise(function(resolve, reject) {
|
||||
resolve(C);
|
||||
});
|
||||
|
||||
async function foo() {
|
||||
class Bar extends (await P) {}
|
||||
return Bar;
|
||||
|
@ -169,9 +163,7 @@ var async = 3;
|
|||
var y = { async };
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
async function f() {}
|
||||
|
||||
async function ft<T>(a: T) {}
|
||||
|
||||
class C {
|
||||
async m() {}
|
||||
async mt<T>(a: T) {}
|
||||
|
@ -185,9 +177,7 @@ 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 };
|
||||
"
|
||||
|
@ -224,14 +214,11 @@ async function foo3(): Promise<string> {
|
|||
async function foo1(): Promise<string> {
|
||||
return;
|
||||
}
|
||||
|
||||
async function foo2(): Promise<string> {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
async function foo3(): Promise<string> {
|
||||
function bar() {}
|
||||
|
||||
return bar();
|
||||
}
|
||||
"
|
||||
|
@ -324,35 +311,29 @@ function test1() {
|
|||
async function foo() {
|
||||
return 42;
|
||||
}
|
||||
|
||||
async function bar() {
|
||||
var a = await foo();
|
||||
var b: number = a;
|
||||
var c: string = a;
|
||||
}
|
||||
}
|
||||
|
||||
function test2() {
|
||||
async function voidoid1() {
|
||||
console.log(\"HEY\");
|
||||
}
|
||||
|
||||
var voidoid2: () => Promise<void> = voidoid1;
|
||||
var voidoid3: () => void = voidoid1;
|
||||
}
|
||||
|
||||
function test3() {
|
||||
async function voidoid4(): Promise<void> {
|
||||
console.log(\"HEY\");
|
||||
}
|
||||
}
|
||||
|
||||
function test4() {
|
||||
async function voidoid5(): void {
|
||||
console.log(\"HEY\");
|
||||
}
|
||||
}
|
||||
|
||||
function test5() {
|
||||
async function voidoid6(): Promise<number> {
|
||||
console.log(\"HEY\");
|
||||
|
@ -412,11 +393,9 @@ async function baz() {
|
|||
async function foo() {
|
||||
return 42;
|
||||
}
|
||||
|
||||
async function bar() {
|
||||
return foo();
|
||||
}
|
||||
|
||||
async function baz() {
|
||||
var a = await bar();
|
||||
var b: number = a;
|
||||
|
@ -454,11 +433,9 @@ var y = { await };
|
|||
async function f() {
|
||||
await 1;
|
||||
}
|
||||
|
||||
async function ft<T>(a: T) {
|
||||
await 1;
|
||||
}
|
||||
|
||||
class C {
|
||||
async m() {
|
||||
await 1;
|
||||
|
@ -498,9 +475,7 @@ var oz = {
|
|||
}
|
||||
};
|
||||
var x = { await: 5 };
|
||||
|
||||
console.log(x.await);
|
||||
|
||||
var await = 3;
|
||||
var y = { await };
|
||||
"
|
||||
|
|
|
@ -33,31 +33,24 @@ async function* delegate_next() {
|
|||
async function* inner() {
|
||||
var x: void = yield;
|
||||
}
|
||||
|
||||
yield* inner();
|
||||
}
|
||||
|
||||
delegate_next().next(0);
|
||||
|
||||
async function* delegate_yield() {
|
||||
async function* inner() {
|
||||
yield 0;
|
||||
}
|
||||
|
||||
yield* inner();
|
||||
}
|
||||
|
||||
async () => {
|
||||
for await (const x of delegate_yield()) {
|
||||
(x: void);
|
||||
}
|
||||
};
|
||||
|
||||
async function* delegate_return() {
|
||||
async function* inner() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
var x: void = yield* inner();
|
||||
}
|
||||
"
|
||||
|
@ -93,7 +86,6 @@ async function f() {
|
|||
// error: string ~> void
|
||||
interface File { readLine(): Promise<string>, close(): void, EOF: boolean }
|
||||
declare function fileOpen(path: string): Promise<File>;
|
||||
|
||||
async function* readLines(path) {
|
||||
let file: File = await fileOpen(path);
|
||||
try {
|
||||
|
@ -104,7 +96,6 @@ async function* readLines(path) {
|
|||
file.close();
|
||||
}
|
||||
}
|
||||
|
||||
async function f() {
|
||||
for await (const line of readLines(\"/path/to/file\")) {
|
||||
(line: void);
|
||||
|
@ -144,11 +135,9 @@ refuse_return().return(\"string\").then(result => {
|
|||
// yielding or returning internally.
|
||||
// error: number | void ~> string
|
||||
declare var gen: AsyncGenerator<void, string, void>;
|
||||
|
||||
gen.return(0).then(result => {
|
||||
(result.value: void);
|
||||
});
|
||||
|
||||
async function* refuse_return() {
|
||||
try {
|
||||
yield 1;
|
||||
|
@ -156,7 +145,6 @@ async function* refuse_return() {
|
|||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
refuse_return().return(\"string\").then(result => {
|
||||
if (result.done) {
|
||||
(result.value: string);
|
||||
|
@ -208,7 +196,6 @@ async function* catch_return() {
|
|||
return e;
|
||||
}
|
||||
}
|
||||
|
||||
async () => {
|
||||
catch_return().throw(\"\").then(({ value }) => {
|
||||
if (value !== undefined) {
|
||||
|
@ -216,17 +203,14 @@ async () => {
|
|||
}
|
||||
});
|
||||
};
|
||||
|
||||
async function* yield_return() {
|
||||
try {
|
||||
yield 0;
|
||||
|
||||
return;
|
||||
} catch (e) {
|
||||
yield e;
|
||||
}
|
||||
}
|
||||
|
||||
async () => {
|
||||
yield_return().throw(\"\").then(({ value }) => {
|
||||
if (value !== undefined) {
|
||||
|
|
|
@ -19,7 +19,6 @@ declare var mergeInto: $Facebookism$MergeInto;
|
|||
declare var mixin: $Facebookism$Mixin;
|
||||
declare var objectGetPrototypeOf: Object$GetPrototypeOf;
|
||||
declare var objectAssign: Object$Assign;
|
||||
|
||||
m;
|
||||
"
|
||||
`;
|
||||
|
|
|
@ -78,55 +78,39 @@ let tests = [
|
|||
let tests = [
|
||||
function() {
|
||||
\"foo\" in {};
|
||||
|
||||
\"foo\" in { foo: null };
|
||||
|
||||
0 in {};
|
||||
|
||||
0 in { \"0\": null };
|
||||
},
|
||||
function() {
|
||||
\"foo\" in [];
|
||||
|
||||
0 in [];
|
||||
|
||||
\"length\" in [];
|
||||
},
|
||||
function() {
|
||||
\"foo\" in new String(\"bar\");
|
||||
|
||||
\"foo\" in new Number(123);
|
||||
},
|
||||
function() {
|
||||
\"foo\" in 123;
|
||||
|
||||
\"foo\" in \"bar\";
|
||||
|
||||
\"foo\" in void 0;
|
||||
|
||||
\"foo\" in null;
|
||||
},
|
||||
function() {
|
||||
null in {};
|
||||
|
||||
void 0 in {};
|
||||
|
||||
({}) in {};
|
||||
|
||||
[] in {};
|
||||
|
||||
false in [];
|
||||
},
|
||||
function() {
|
||||
if (\"foo\" in 123) {}
|
||||
|
||||
if (!\"foo\" in {}) {}
|
||||
|
||||
if (!(\"foo\" in {})) {}
|
||||
},
|
||||
function(x: Object, y: mixed) {
|
||||
\"foo\" in x;
|
||||
|
||||
\"foo\" in y;
|
||||
}
|
||||
];
|
||||
|
|
|
@ -33,40 +33,23 @@ for (const { baz } of bazzes) {
|
|||
// error: string ~> number
|
||||
// error: string ~> number
|
||||
const x = 0;
|
||||
|
||||
x++;
|
||||
|
||||
x--;
|
||||
|
||||
x += 0;
|
||||
|
||||
x -= 0;
|
||||
|
||||
x /= 0;
|
||||
|
||||
x %= 0;
|
||||
|
||||
x <<= 0;
|
||||
|
||||
x >>= 0;
|
||||
|
||||
x >>>= 0;
|
||||
|
||||
x |= 0;
|
||||
|
||||
x ^= 0;
|
||||
|
||||
x &= 0;
|
||||
|
||||
const { foo } = { foo: \"foo\" };
|
||||
const [ bar ] = [ \"bar\" ];
|
||||
|
||||
(foo: number);
|
||||
|
||||
(bar: number);
|
||||
|
||||
declare var bazzes: { baz: string }[];
|
||||
|
||||
for (const { baz } of bazzes) {
|
||||
(baz: number);
|
||||
}
|
||||
|
@ -328,155 +311,120 @@ function type_type() {
|
|||
type A = number;
|
||||
type A = number;
|
||||
}
|
||||
|
||||
function type_class() {
|
||||
type A = number;
|
||||
class A {}
|
||||
}
|
||||
|
||||
function type_let() {
|
||||
type A = number;
|
||||
let A = 0;
|
||||
}
|
||||
|
||||
function type_const() {
|
||||
type A = number;
|
||||
const A = 0;
|
||||
}
|
||||
|
||||
function type_var() {
|
||||
type A = number;
|
||||
var A = 0;
|
||||
}
|
||||
|
||||
function type_reassign() {
|
||||
type A = number;
|
||||
|
||||
A = 42;
|
||||
}
|
||||
|
||||
function class_type() {
|
||||
class A {}
|
||||
type A = number;
|
||||
}
|
||||
|
||||
function class_class() {
|
||||
class A {}
|
||||
class A {}
|
||||
}
|
||||
|
||||
function class_let() {
|
||||
class A {}
|
||||
let A = 0;
|
||||
}
|
||||
|
||||
function class_const() {
|
||||
class A {}
|
||||
const A = 0;
|
||||
}
|
||||
|
||||
function class_var() {
|
||||
class A {}
|
||||
var A = 0;
|
||||
}
|
||||
|
||||
function let_type() {
|
||||
let A = 0;
|
||||
type A = number;
|
||||
}
|
||||
|
||||
function let_class() {
|
||||
let A = 0;
|
||||
class A {}
|
||||
}
|
||||
|
||||
function let_let() {
|
||||
let A = 0;
|
||||
let A = 0;
|
||||
}
|
||||
|
||||
function let_const() {
|
||||
let A = 0;
|
||||
const A = 0;
|
||||
}
|
||||
|
||||
function let_var() {
|
||||
let A = 0;
|
||||
var A = 0;
|
||||
}
|
||||
|
||||
function const_type() {
|
||||
const A = 0;
|
||||
type A = number;
|
||||
}
|
||||
|
||||
function const_class() {
|
||||
const A = 0;
|
||||
class A {}
|
||||
}
|
||||
|
||||
function const_let() {
|
||||
const A = 0;
|
||||
let A = 0;
|
||||
}
|
||||
|
||||
function const_const() {
|
||||
const A = 0;
|
||||
const A = 0;
|
||||
}
|
||||
|
||||
function const_var() {
|
||||
const A = 0;
|
||||
var A = 0;
|
||||
}
|
||||
|
||||
function const_reassign() {
|
||||
const A = 0;
|
||||
|
||||
A = 42;
|
||||
}
|
||||
|
||||
function var_type() {
|
||||
var A = 0;
|
||||
type A = number;
|
||||
}
|
||||
|
||||
function var_class() {
|
||||
var A = 0;
|
||||
class A {}
|
||||
}
|
||||
|
||||
function var_let() {
|
||||
var A = 0;
|
||||
let A = 0;
|
||||
}
|
||||
|
||||
function var_const() {
|
||||
var A = 0;
|
||||
const A = 0;
|
||||
}
|
||||
|
||||
function var_var() {
|
||||
var A = 0;
|
||||
var A = 0;
|
||||
}
|
||||
|
||||
function function_toplevel() {
|
||||
function a() {}
|
||||
|
||||
function a() {}
|
||||
|
||||
}
|
||||
|
||||
function function_block() {
|
||||
{
|
||||
function a() {}
|
||||
|
||||
function a() {}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function var_shadow_nested_scope() {
|
||||
{
|
||||
let x = 0;
|
||||
|
@ -485,7 +433,6 @@ function var_shadow_nested_scope() {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
function type_shadow_nested_scope() {
|
||||
{
|
||||
let x = 0;
|
||||
|
@ -494,9 +441,7 @@ function type_shadow_nested_scope() {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
function fn_params_name_clash(x, x) {}
|
||||
|
||||
function fn_params_clash_fn_binding(x, y) {
|
||||
let x = 0;
|
||||
var y = 0;
|
||||
|
@ -650,7 +595,6 @@ function block_scope() {
|
|||
var b = \"\";
|
||||
}
|
||||
}
|
||||
|
||||
function switch_scope(x: string) {
|
||||
let a: number = 0;
|
||||
var b: number = 0;
|
||||
|
@ -664,13 +608,10 @@ function switch_scope(x: string) {
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
function switch_scope2(x: number) {
|
||||
switch (x) {
|
||||
case 0:
|
||||
|
||||
a = \"\";
|
||||
|
||||
break;
|
||||
case 1:
|
||||
var b = a;
|
||||
|
@ -679,18 +620,14 @@ function switch_scope2(x: number) {
|
|||
let a = \"\";
|
||||
break;
|
||||
case 3:
|
||||
|
||||
a = \"\";
|
||||
|
||||
break;
|
||||
case 4:
|
||||
var c: string = a;
|
||||
break;
|
||||
}
|
||||
|
||||
a = \"\";
|
||||
}
|
||||
|
||||
function try_scope() {
|
||||
let a: number = 0;
|
||||
try {
|
||||
|
@ -701,57 +638,41 @@ function try_scope() {
|
|||
let a = \"\";
|
||||
}
|
||||
}
|
||||
|
||||
function for_scope_let() {
|
||||
let a: number = 0;
|
||||
|
||||
for (let a = \"\"; ; ) {}
|
||||
}
|
||||
|
||||
function for_scope_var() {
|
||||
var a: number = 0;
|
||||
|
||||
for (var a = \"\"; ; ) {}
|
||||
}
|
||||
|
||||
function for_in_scope_let(o: Object) {
|
||||
let a: number = 0;
|
||||
|
||||
for (let a in o) {}
|
||||
}
|
||||
|
||||
function for_in_scope_var(o: Object) {
|
||||
var a: number = 0;
|
||||
|
||||
for (var a in o) {}
|
||||
}
|
||||
|
||||
function for_of_scope_let(xs: string[]) {
|
||||
let a: number = 0;
|
||||
|
||||
for (let a of xs) {}
|
||||
}
|
||||
|
||||
function for_of_scope_var(xs: string[]) {
|
||||
var a: number = 0;
|
||||
|
||||
for (var a of xs) {}
|
||||
}
|
||||
|
||||
function default_param_1() {
|
||||
function f(x: () => string = f): number {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
function default_param_2() {
|
||||
let a = \"\";
|
||||
|
||||
function f0(x = () => a): number {
|
||||
let a = 0;
|
||||
return x();
|
||||
}
|
||||
|
||||
function f1(x = b): number {
|
||||
let b = 0;
|
||||
return x;
|
||||
|
@ -906,25 +827,19 @@ f(a); // ok, a: number (not ?number)
|
|||
// ok, a: number (not ?number)
|
||||
type T1 = T2;
|
||||
type T2 = number;
|
||||
|
||||
function f0() {
|
||||
var v = x * c;
|
||||
let x = 0;
|
||||
const c = 0;
|
||||
}
|
||||
|
||||
function f1(b) {
|
||||
x = 10;
|
||||
|
||||
let x = 0;
|
||||
|
||||
if (b) {
|
||||
y = 10;
|
||||
|
||||
let y = 0;
|
||||
}
|
||||
}
|
||||
|
||||
function f2() {
|
||||
{
|
||||
var v = x * c;
|
||||
|
@ -932,57 +847,44 @@ function f2() {
|
|||
let x = 0;
|
||||
const c = 0;
|
||||
}
|
||||
|
||||
function f3() {
|
||||
var s: string = foo();
|
||||
{
|
||||
var n: number = foo();
|
||||
|
||||
function foo() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
var s2: string = foo();
|
||||
|
||||
function foo() {
|
||||
return \"\";
|
||||
}
|
||||
}
|
||||
|
||||
function f4() {
|
||||
function g() {
|
||||
return x + c;
|
||||
}
|
||||
|
||||
let x = 0;
|
||||
const c = 0;
|
||||
}
|
||||
|
||||
function f5() {
|
||||
function g() {
|
||||
return x;
|
||||
}
|
||||
|
||||
g();
|
||||
|
||||
let x = 0;
|
||||
const c = 0;
|
||||
}
|
||||
|
||||
var x: C;
|
||||
var y = new C();
|
||||
class C {}
|
||||
var z: C = new C();
|
||||
var a: number;
|
||||
|
||||
function f(n: number) {
|
||||
return n;
|
||||
}
|
||||
|
||||
f(a);
|
||||
|
||||
a = 10;
|
||||
|
||||
f(a);
|
||||
"
|
||||
`;
|
||||
|
|
|
@ -125,89 +125,50 @@ for (let [x, y]: [number, number] of a.entries()) {} // incorrect
|
|||
// incorrect
|
||||
// incorrect
|
||||
const a: FormData = new FormData();
|
||||
|
||||
new FormData(\"\");
|
||||
|
||||
new FormData(document.createElement(\"input\"));
|
||||
|
||||
new FormData(document.createElement(\"form\"));
|
||||
|
||||
const b: boolean = a.has(\"foo\");
|
||||
const c: ?(string | File) = a.get(\"foo\");
|
||||
const d: string = a.get(\"foo\");
|
||||
const e: Blob = a.get(\"foo\");
|
||||
const f: ?(string | File | Blob) = a.get(\"foo\");
|
||||
|
||||
a.get(2);
|
||||
|
||||
const a1: Array<string | File> = a.getAll(\"foo\");
|
||||
const a2: Array<string | File | number> = a.getAll(\"foo\");
|
||||
const a3: Array<string | Blob | File> = a.getAll(\"foo\");
|
||||
|
||||
a.getAll(23);
|
||||
|
||||
a.set(\"foo\", \"bar\");
|
||||
|
||||
a.set(\"foo\", {});
|
||||
|
||||
a.set(2, \"bar\");
|
||||
|
||||
a.set(\"foo\", \"bar\", \"baz\");
|
||||
|
||||
a.set(\"bar\", new File([], \"q\"));
|
||||
|
||||
a.set(\"bar\", new File([], \"q\"), \"x\");
|
||||
|
||||
a.set(\"bar\", new File([], \"q\"), 2);
|
||||
|
||||
a.set(\"bar\", new Blob());
|
||||
|
||||
a.set(\"bar\", new Blob(), \"x\");
|
||||
|
||||
a.set(\"bar\", new Blob(), 2);
|
||||
|
||||
a.append(\"foo\", \"bar\");
|
||||
|
||||
a.append(\"foo\", {});
|
||||
|
||||
a.append(2, \"bar\");
|
||||
|
||||
a.append(\"foo\", \"bar\", \"baz\");
|
||||
|
||||
a.append(\"foo\", \"bar\");
|
||||
|
||||
a.append(\"bar\", new File([], \"q\"));
|
||||
|
||||
a.append(\"bar\", new File([], \"q\"), \"x\");
|
||||
|
||||
a.append(\"bar\", new File([], \"q\"), 2);
|
||||
|
||||
a.append(\"bar\", new Blob());
|
||||
|
||||
a.append(\"bar\", new Blob(), \"x\");
|
||||
|
||||
a.append(\"bar\", new Blob(), 2);
|
||||
|
||||
a.delete(\"xx\");
|
||||
|
||||
a.delete(3);
|
||||
|
||||
for (let x: string of a.keys()) {}
|
||||
|
||||
for (let x: number of a.keys()) {}
|
||||
|
||||
for (let x: string | File of a.values()) {}
|
||||
|
||||
for (let x: string | File | Blob of a.values()) {}
|
||||
|
||||
for (let [ x, y ]: [string, string | File] of a.entries()) {}
|
||||
|
||||
for (let [ x, y ]: [string, string | File | Blob] of a.entries()) {}
|
||||
|
||||
for (let [ x, y ]: [number, string] of a.entries()) {}
|
||||
|
||||
for (let [ x, y ]: [string, number] of a.entries()) {}
|
||||
|
||||
for (let [ x, y ]: [number, number] of a.entries()) {}
|
||||
"
|
||||
`;
|
||||
|
@ -270,39 +231,22 @@ function callback(
|
|||
): void {
|
||||
return;
|
||||
}
|
||||
|
||||
const o: MutationObserver = new MutationObserver(callback);
|
||||
|
||||
new MutationObserver((arr: Array<MutationRecord>) => true);
|
||||
|
||||
new MutationObserver(() => {});
|
||||
|
||||
new MutationObserver();
|
||||
|
||||
new MutationObserver(42);
|
||||
|
||||
new MutationObserver((n: number) => {});
|
||||
|
||||
const div = document.createElement(\"div\");
|
||||
|
||||
o.observe(div, { attributes: true, attributeFilter: [ \"style\" ] });
|
||||
|
||||
o.observe(div, { characterData: true, invalid: true });
|
||||
|
||||
o.observe();
|
||||
|
||||
o.observe(\"invalid\");
|
||||
|
||||
o.observe(div);
|
||||
|
||||
o.observe(div, {});
|
||||
|
||||
o.observe(div, { subtree: true });
|
||||
|
||||
o.observe(div, { attributes: true, attributeFilter: true });
|
||||
|
||||
o.takeRecords();
|
||||
|
||||
o.disconnect();
|
||||
"
|
||||
`;
|
||||
|
|
|
@ -5,9 +5,7 @@ foo(0, \"\");
|
|||
function bar<X:number, Y:X>(x:X, y:Y): number { return y*0; }
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
function foo<X, Y: X>(x: X, y: Y): void {}
|
||||
|
||||
foo(0, \"\");
|
||||
|
||||
function bar<X: number, Y: X>(x: X, y: Y): number {
|
||||
return y * 0;
|
||||
}
|
||||
|
@ -56,7 +54,6 @@ function foo<T: number>(x: T): T {
|
|||
var y: string = x;
|
||||
return x;
|
||||
}
|
||||
|
||||
class C<T: number> {
|
||||
bar<U: number>(x: U): T {
|
||||
return x;
|
||||
|
@ -67,13 +64,10 @@ class C<T: number> {
|
|||
return x;
|
||||
}
|
||||
}
|
||||
|
||||
function example<T: { x: number }>(o: T): T {
|
||||
o.x = 0;
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
var obj1: { x: number, y: string } = example({ x: 0, y: \"\" });
|
||||
var obj2: { x: number } = example({ x: 0 });
|
||||
var c: C<string> = new C();
|
||||
|
|
|
@ -87,27 +87,20 @@ function foo(b) {
|
|||
while (b) {
|
||||
if (x == null) {
|
||||
z = \"\";
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
var y: number = x;
|
||||
}
|
||||
var w: number = z;
|
||||
}
|
||||
|
||||
function bar(b) {
|
||||
var x = b ? null : false;
|
||||
|
||||
if (x == null)
|
||||
return;
|
||||
|
||||
switch (\"\") {
|
||||
case 0:
|
||||
var y: number = x;
|
||||
|
||||
x = \"\";
|
||||
|
||||
case 1:
|
||||
var z: number = x;
|
||||
break;
|
||||
|
@ -115,18 +108,14 @@ function bar(b) {
|
|||
}
|
||||
var w: number = x;
|
||||
}
|
||||
|
||||
function bar2(b) {
|
||||
var x = b ? null : false;
|
||||
|
||||
if (x == null)
|
||||
return;
|
||||
|
||||
switch (\"\") {
|
||||
case 0:
|
||||
{
|
||||
let y: number = x;
|
||||
|
||||
x = \"\";
|
||||
}
|
||||
case 1:
|
||||
|
@ -138,36 +127,27 @@ function bar2(b) {
|
|||
}
|
||||
var w: number = x;
|
||||
}
|
||||
|
||||
function qux(b) {
|
||||
var z = 0;
|
||||
while (b) {
|
||||
var y: number = z;
|
||||
|
||||
if (b) {
|
||||
z = \"\";
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
z = 0;
|
||||
}
|
||||
var w: number = z;
|
||||
}
|
||||
|
||||
function test_const() {
|
||||
let st: string = \"abc\";
|
||||
|
||||
for (let i = 1; i < 100; i++) {
|
||||
const fooRes: ?string = \"HEY\";
|
||||
|
||||
if (!fooRes) {
|
||||
break;
|
||||
}
|
||||
|
||||
st = fooRes;
|
||||
}
|
||||
|
||||
return st;
|
||||
}
|
||||
"
|
||||
|
|
|
@ -4,9 +4,7 @@ exports[`test test.js 1`] = `
|
|||
module.exports = o;
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
var o = Object.freeze({ foo: 0 });
|
||||
|
||||
(o.foo: string);
|
||||
|
||||
module.exports = o;
|
||||
"
|
||||
`;
|
||||
|
@ -16,7 +14,6 @@ exports[`test test2.js 1`] = `
|
|||
(o.foo: string);
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
var o = require(\"./test\");
|
||||
|
||||
(o.foo: string);
|
||||
"
|
||||
`;
|
||||
|
|
|
@ -26,24 +26,19 @@ var b = a.map(function(x) {
|
|||
});
|
||||
var c: string = b[0];
|
||||
var array = [];
|
||||
|
||||
function f() {
|
||||
array = array.map(function() {
|
||||
return \"...\";
|
||||
});
|
||||
|
||||
var x: number = array[0];
|
||||
}
|
||||
|
||||
var Foo = require(\"./genericfoo\");
|
||||
var foo = new Foo();
|
||||
|
||||
function g() {
|
||||
var foo1 = foo.map(function() {
|
||||
return \"...\";
|
||||
});
|
||||
var x: number = foo1.get();
|
||||
|
||||
foo = foo1;
|
||||
}
|
||||
"
|
||||
|
@ -73,7 +68,6 @@ class Foo<T> {
|
|||
return this.x;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Foo;
|
||||
"
|
||||
`;
|
||||
|
|
|
@ -39,23 +39,18 @@ function f(): number {
|
|||
function a(f: { (): string }, g: { (x: number): string }): string {
|
||||
return f() + g(123);
|
||||
}
|
||||
|
||||
function b(f: { (): string }): number {
|
||||
return f();
|
||||
}
|
||||
|
||||
function c(f: { (x: number): number }): number {
|
||||
return f(\"hello\");
|
||||
}
|
||||
|
||||
function d(f: { (x: number): number }): number {
|
||||
return f();
|
||||
}
|
||||
|
||||
function e(f: {}): number {
|
||||
return f();
|
||||
}
|
||||
|
||||
function f(): number {
|
||||
var x = {};
|
||||
return x();
|
||||
|
@ -167,27 +162,21 @@ function g(x: {}): Function {
|
|||
function a(x: { (z: number): string }): (z: number) => string {
|
||||
return x;
|
||||
}
|
||||
|
||||
function b(x: { (z: number): string }): (z: number) => number {
|
||||
return x;
|
||||
}
|
||||
|
||||
function c(x: { (z: number): string }): (z: string) => string {
|
||||
return x;
|
||||
}
|
||||
|
||||
function d(x: { (z: number): string }): () => string {
|
||||
return x;
|
||||
}
|
||||
|
||||
function e(x: {}): () => string {
|
||||
return x;
|
||||
}
|
||||
|
||||
function f(x: { (z: number): string }): Function {
|
||||
return x;
|
||||
}
|
||||
|
||||
function g(x: {}): Function {
|
||||
return x;
|
||||
}
|
||||
|
@ -226,18 +215,15 @@ function e(x: { (): string; (x: number): string }): () => number {
|
|||
function a(f: { (): string, (x: number): string }): string {
|
||||
return f() + f(123);
|
||||
}
|
||||
|
||||
var b: { (): string, (x: number): string } = function(x?: number): string {
|
||||
return \"hi\";
|
||||
};
|
||||
var c: { (): string, (x: number): string } = function(x: number): string {
|
||||
return \"hi\";
|
||||
};
|
||||
|
||||
function d(x: { (): string, (x: number): string }): () => string {
|
||||
return x;
|
||||
}
|
||||
|
||||
function e(x: { (): string, (x: number): string }): () => number {
|
||||
return x;
|
||||
}
|
||||
|
@ -262,9 +248,7 @@ var c : { myProp: number } = f;
|
|||
var a: { someProp: number } = function() {};
|
||||
var b: { apply: Function } = function() {};
|
||||
var f = function() {};
|
||||
|
||||
f.myProp = 123;
|
||||
|
||||
var c: { myProp: number } = f;
|
||||
"
|
||||
`;
|
||||
|
|
|
@ -11,11 +11,9 @@ function f(x) {
|
|||
(f: F);
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
type F = { (x: string): number, p?: string };
|
||||
|
||||
function f(x) {
|
||||
return x.length;
|
||||
}
|
||||
|
||||
(f: F);
|
||||
"
|
||||
`;
|
||||
|
@ -49,27 +47,17 @@ callable.call(null, 0); // error, number ~> string
|
|||
// error, number ~> string
|
||||
// error, number ~> string
|
||||
var x = Boolean(4);
|
||||
|
||||
function foo(fn: (value: any) => boolean) {}
|
||||
|
||||
foo(Boolean);
|
||||
|
||||
var dict: { [k: string]: any } = {};
|
||||
|
||||
dict();
|
||||
|
||||
interface ICall { (x: string): void }
|
||||
declare var icall: ICall;
|
||||
|
||||
icall(0);
|
||||
|
||||
icall.call(null, 0);
|
||||
|
||||
type Callable = { (x: string): void };
|
||||
declare var callable: Callable;
|
||||
|
||||
callable(0);
|
||||
|
||||
callable.call(null, 0);
|
||||
"
|
||||
`;
|
||||
|
|
|
@ -80,25 +80,17 @@ class A {
|
|||
static foo(x: number) {}
|
||||
static bar(y: string) {}
|
||||
}
|
||||
|
||||
A.qux = function(x: string) {};
|
||||
|
||||
class B extends A {
|
||||
static x: string;
|
||||
static foo(x: string) {}
|
||||
static main() {
|
||||
B.x = 0;
|
||||
|
||||
B.x = \"\";
|
||||
|
||||
B.foo(0);
|
||||
|
||||
B.foo(\"\");
|
||||
|
||||
B.y = 0;
|
||||
|
||||
B.bar(0);
|
||||
|
||||
B.qux(0);
|
||||
}
|
||||
static create(): A {
|
||||
|
@ -118,25 +110,19 @@ class C<X> {
|
|||
class D extends C<string> {
|
||||
static main() {
|
||||
D.foo(0);
|
||||
|
||||
D.bar(0);
|
||||
}
|
||||
}
|
||||
var d: C<*> = D.create();
|
||||
|
||||
(new A(): typeof A);
|
||||
|
||||
(B: typeof A);
|
||||
|
||||
class E {
|
||||
static x: number;
|
||||
static foo(): string {
|
||||
this.bar();
|
||||
|
||||
return this.x;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { A: A, B: B, C: C, D: D, E: E };
|
||||
"
|
||||
`;
|
||||
|
|
|
@ -8,7 +8,6 @@ module.exports = { A, B };
|
|||
/* @flow */
|
||||
class A {}
|
||||
class B {}
|
||||
|
||||
module.exports = { A, B };
|
||||
"
|
||||
`;
|
||||
|
@ -66,19 +65,14 @@ foo(new D, { f_: 0 });
|
|||
class C<X> {
|
||||
x: X;
|
||||
}
|
||||
|
||||
function foo<X>(c: C<X>, x: X) {}
|
||||
|
||||
type O = { f: number };
|
||||
|
||||
foo((new C(): C<O>), { f_: 0 });
|
||||
|
||||
class D extends C<O> {
|
||||
bar() {
|
||||
this.x;
|
||||
}
|
||||
}
|
||||
|
||||
foo(new D(), { f_: 0 });
|
||||
"
|
||||
`;
|
||||
|
|
|
@ -14,15 +14,12 @@ function bar(x: Class<B>): B {
|
|||
// OK
|
||||
// error (too few args)
|
||||
class A {}
|
||||
|
||||
function foo(x: Class<A>): A {
|
||||
return new x();
|
||||
}
|
||||
|
||||
class B {
|
||||
constructor(_: any) {}
|
||||
}
|
||||
|
||||
function bar(x: Class<B>): B {
|
||||
return new x();
|
||||
}
|
||||
|
@ -52,15 +49,10 @@ declare function check<X>(cls: $Type<X>, inst: X): void;
|
|||
class A {}
|
||||
class B extends A {}
|
||||
class C {}
|
||||
|
||||
check(B, new A());
|
||||
|
||||
check(A, new B());
|
||||
|
||||
check(C, new A());
|
||||
|
||||
check(C, new B());
|
||||
|
||||
check(B, new C());
|
||||
"
|
||||
`;
|
||||
|
|
|
@ -8,7 +8,6 @@ module.exports = A;
|
|||
class A {
|
||||
foo(x: number): void {}
|
||||
}
|
||||
|
||||
module.exports = A;
|
||||
"
|
||||
`;
|
||||
|
@ -27,9 +26,7 @@ module.exports = B;
|
|||
var A = require(\"./A\");
|
||||
class B extends A {}
|
||||
let b = new B();
|
||||
|
||||
(b.foo: number);
|
||||
|
||||
module.exports = B;
|
||||
"
|
||||
`;
|
||||
|
@ -52,9 +49,7 @@ class C extends B {
|
|||
foo(x: string): void {}
|
||||
}
|
||||
let c = new C();
|
||||
|
||||
(c.foo: number);
|
||||
|
||||
module.exports = C;
|
||||
"
|
||||
`;
|
||||
|
@ -66,7 +61,6 @@ new E().x
|
|||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
class D {}
|
||||
class E {}
|
||||
|
||||
new E().x;
|
||||
"
|
||||
`;
|
||||
|
@ -128,21 +122,13 @@ class TestClass {
|
|||
c: ?string;
|
||||
}
|
||||
var x = new TestClass();
|
||||
|
||||
x.a;
|
||||
|
||||
x.b;
|
||||
|
||||
x.c;
|
||||
|
||||
x.d;
|
||||
|
||||
var y: Foo = x;
|
||||
|
||||
y.b;
|
||||
|
||||
y.d;
|
||||
|
||||
class Test2Superclass {
|
||||
a: number;
|
||||
c: ?number;
|
||||
|
@ -259,15 +245,10 @@ declare var o: {p:number};
|
|||
class C {
|
||||
static p: string;
|
||||
}
|
||||
|
||||
C.p = \"hi\";
|
||||
|
||||
(C: { p: string });
|
||||
|
||||
(C: { p: number });
|
||||
|
||||
declare var o: { p: number };
|
||||
|
||||
(o: Class<C>);
|
||||
"
|
||||
`;
|
||||
|
|
|
@ -105,45 +105,28 @@ function local_meth() {
|
|||
// error
|
||||
// shouldn\'t pollute linear refinement
|
||||
function takes_string(_: string) {}
|
||||
|
||||
var global_x = \"hello\";
|
||||
|
||||
function global_f() {}
|
||||
|
||||
function global_g() {
|
||||
global_x = 42;
|
||||
}
|
||||
|
||||
global_f();
|
||||
|
||||
takes_string(global_x);
|
||||
|
||||
global_g();
|
||||
|
||||
takes_string(global_x);
|
||||
|
||||
global_x = 42;
|
||||
|
||||
function local_func() {
|
||||
var local_x = \"hello\";
|
||||
|
||||
function local_f() {}
|
||||
|
||||
function local_g() {
|
||||
local_x = 42;
|
||||
}
|
||||
|
||||
local_f();
|
||||
|
||||
takes_string(local_x);
|
||||
|
||||
local_g();
|
||||
|
||||
takes_string(local_x);
|
||||
|
||||
local_x = 42;
|
||||
}
|
||||
|
||||
var global_y = \"hello\";
|
||||
var global_o = {
|
||||
f: function() {},
|
||||
|
@ -151,17 +134,11 @@ var global_o = {
|
|||
global_y = 42;
|
||||
}
|
||||
};
|
||||
|
||||
global_o.f();
|
||||
|
||||
takes_string(global_y);
|
||||
|
||||
global_o.g();
|
||||
|
||||
takes_string(global_y);
|
||||
|
||||
global_y = 42;
|
||||
|
||||
function local_meth() {
|
||||
var local_y = \"hello\";
|
||||
var local_o = {
|
||||
|
@ -170,15 +147,10 @@ function local_meth() {
|
|||
local_y = 42;
|
||||
}
|
||||
};
|
||||
|
||||
local_o.f();
|
||||
|
||||
takes_string(local_y);
|
||||
|
||||
local_o.g();
|
||||
|
||||
takes_string(local_y);
|
||||
|
||||
local_y = 42;
|
||||
}
|
||||
"
|
||||
|
@ -206,15 +178,12 @@ function example(b: bool): number {
|
|||
// error, string ~/~> number (return type anno) TODO
|
||||
function example(b: boolean): number {
|
||||
var x = 0;
|
||||
|
||||
function f() {
|
||||
x = \"\";
|
||||
}
|
||||
|
||||
if (b) {
|
||||
f();
|
||||
}
|
||||
|
||||
return x;
|
||||
}
|
||||
"
|
||||
|
@ -285,30 +254,23 @@ call_me();
|
|||
// error
|
||||
// in a galaxy far far away
|
||||
var call_me: () => void = () => {};
|
||||
|
||||
function g(x: ?number) {
|
||||
const const_x = x;
|
||||
|
||||
if (const_x) {
|
||||
call_me = () => {
|
||||
var y: number = const_x;
|
||||
};
|
||||
}
|
||||
|
||||
var var_x = x;
|
||||
|
||||
if (var_x) {
|
||||
call_me = () => {
|
||||
var y: number = var_x;
|
||||
};
|
||||
}
|
||||
|
||||
var_x = null;
|
||||
}
|
||||
|
||||
function h(x: number | string | boolean) {
|
||||
const const_x = x;
|
||||
|
||||
if (typeof const_x == \"number\") {
|
||||
call_me = () => {
|
||||
var y: number = const_x;
|
||||
|
@ -322,9 +284,7 @@ function h(x: number | string | boolean) {
|
|||
var y: boolean = const_x;
|
||||
};
|
||||
}
|
||||
|
||||
var var_x = x;
|
||||
|
||||
if (typeof var_x == \"number\") {
|
||||
call_me = () => {
|
||||
var y: number = var_x;
|
||||
|
@ -339,7 +299,6 @@ function h(x: number | string | boolean) {
|
|||
};
|
||||
}
|
||||
}
|
||||
|
||||
call_me();
|
||||
"
|
||||
`;
|
||||
|
|
|
@ -5,7 +5,6 @@ function f(x:string) { }
|
|||
module.exports = f;
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
function f(x: string) {}
|
||||
|
||||
module.exports = f;
|
||||
"
|
||||
`;
|
||||
|
@ -17,7 +16,6 @@ var f = require(\'./Abs\');
|
|||
f(0);
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
var f = require(\"./Abs\");
|
||||
|
||||
f(0);
|
||||
"
|
||||
`;
|
||||
|
|
|
@ -32,11 +32,8 @@ var ColorIdToNumber = {
|
|||
[ColorId.GREEN]: ColorNumber.GREEN,
|
||||
[ColorId.BLUE]: ColorNumber.BLUE
|
||||
};
|
||||
|
||||
(ColorIdToNumber[ColorId.RED]: \"ffffff\");
|
||||
|
||||
ColorIdToNumber.XXX;
|
||||
|
||||
module.exports = { ColorId, ColorNumber };
|
||||
"
|
||||
`;
|
||||
|
@ -60,9 +57,7 @@ var ColorIdToNumber = {
|
|||
[ColorId.GREEN]: ColorNumber.GREEN,
|
||||
[ColorId.BLUE]: ColorNumber.BLUE
|
||||
};
|
||||
|
||||
(ColorIdToNumber[ColorId.GREEN]: \"ffffff\");
|
||||
|
||||
module.exports = ColorIdToNumber;
|
||||
"
|
||||
`;
|
||||
|
@ -76,7 +71,6 @@ var ColorIdToNumber = require(\'./test2\');
|
|||
// oops
|
||||
var { ColorId } = require(\"./test\");
|
||||
var ColorIdToNumber = require(\"./test2\");
|
||||
|
||||
(ColorIdToNumber[ColorId.BLUE]: \"ffffff\");
|
||||
"
|
||||
`;
|
||||
|
@ -99,7 +93,6 @@ module.exports = {
|
|||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
var hello = require(\"./test4\");
|
||||
var dummy = require(\"./test\");
|
||||
|
||||
module.exports = { ...dummy, [hello]: \"world\", ...dummy };
|
||||
"
|
||||
`;
|
||||
|
@ -110,7 +103,6 @@ exports[`test test6.js 1`] = `
|
|||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// oops
|
||||
var o = require(\"./test5\");
|
||||
|
||||
(o.hello: \"nothing\");
|
||||
"
|
||||
`;
|
||||
|
|
|
@ -32,18 +32,15 @@ function a(): number {
|
|||
var x: ?string = null;
|
||||
return x ? 1 : 0;
|
||||
}
|
||||
|
||||
function b(): number {
|
||||
var x: ?number = null;
|
||||
return x != null ? x : 0;
|
||||
}
|
||||
|
||||
function c(): number {
|
||||
var x = false;
|
||||
var temp = x ? 1 : x;
|
||||
return temp ? temp : 0;
|
||||
}
|
||||
|
||||
function d(): string {
|
||||
var x: ?number = null;
|
||||
return x != null ? x : x != null;
|
||||
|
|
|
@ -4,7 +4,6 @@ exports[`test no_at_flow.js 1`] = `
|
|||
x.length;
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
var x;
|
||||
|
||||
x.length;
|
||||
"
|
||||
`;
|
||||
|
|
|
@ -19,7 +19,6 @@ function foo(x) {
|
|||
var a: number = \"asdf\";
|
||||
return x * 10;
|
||||
}
|
||||
|
||||
foo(\"Hello, world!\");
|
||||
"
|
||||
`;
|
||||
|
|
|
@ -9,9 +9,7 @@ import {name} from \"testproj\";
|
|||
// @flow
|
||||
// Error: Resolve from node_modules first!
|
||||
import {name} from \"testproj\";
|
||||
|
||||
(name: \"node_modules/testproj\");
|
||||
|
||||
(name: \"custom_resolve_dir/testproj\");
|
||||
"
|
||||
`;
|
||||
|
|
|
@ -9,9 +9,7 @@ import {name} from \"testproj2\";
|
|||
// @flow
|
||||
// Error: Resolve from sibling \'custom_resolve_dir\' first!
|
||||
import {name} from \"testproj2\";
|
||||
|
||||
(name: \"node_modules/testproj2\");
|
||||
|
||||
(name: \"subdir/custom_resolve_dir/testproj2\");
|
||||
"
|
||||
`;
|
||||
|
|
|
@ -48,15 +48,12 @@ class A {
|
|||
return \"some string\";
|
||||
}
|
||||
}
|
||||
|
||||
A._sProperty = 48;
|
||||
|
||||
class B extends A {
|
||||
_property1: string;
|
||||
static _sProperty: string;
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this._property1 = \"another string\";
|
||||
}
|
||||
_method1(): string {
|
||||
|
@ -66,7 +63,6 @@ class B extends A {
|
|||
return 23;
|
||||
}
|
||||
}
|
||||
|
||||
B._sProperty = \"B._sProperty string\";
|
||||
"
|
||||
`;
|
||||
|
@ -84,7 +80,6 @@ module.exports = new C;
|
|||
class C {
|
||||
_p: string;
|
||||
}
|
||||
|
||||
module.exports = new C();
|
||||
"
|
||||
`;
|
||||
|
|
|
@ -48,15 +48,12 @@ class A {
|
|||
return \"some string\";
|
||||
}
|
||||
}
|
||||
|
||||
A._sProperty = 48;
|
||||
|
||||
class B extends A {
|
||||
_property1: string;
|
||||
static _sProperty: string;
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this._property1 = \"another string\";
|
||||
}
|
||||
_method1(): string {
|
||||
|
@ -66,7 +63,6 @@ class B extends A {
|
|||
return 23;
|
||||
}
|
||||
}
|
||||
|
||||
B._sProperty = \"B._sProperty string\";
|
||||
"
|
||||
`;
|
||||
|
|
|
@ -52,7 +52,6 @@ function durable_refi(x: ?number) {
|
|||
function cannot_reassign(x: string) {
|
||||
x = \"hey\";
|
||||
}
|
||||
|
||||
function durable_refi(x: ?number) {
|
||||
if (x) {
|
||||
return () => {
|
||||
|
|
|
@ -15,7 +15,6 @@ class C {
|
|||
class D {
|
||||
constructor(): number {}
|
||||
}
|
||||
|
||||
module.exports = C;
|
||||
"
|
||||
`;
|
||||
|
|
|
@ -32,24 +32,19 @@ exports.Foo2 = (Foo: Class<IFoo>);
|
|||
function Foo() {
|
||||
this.x = 0;
|
||||
}
|
||||
|
||||
Foo.y = 0;
|
||||
|
||||
Foo.prototype = {
|
||||
m() {
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
exports.Foo = Foo;
|
||||
|
||||
interface IFooPrototype { m(): number }
|
||||
interface IFoo extends IFooPrototype {
|
||||
static (): void,
|
||||
x: boolean,
|
||||
static y: boolean
|
||||
}
|
||||
|
||||
exports.Foo2 = (Foo: Class<IFoo>);
|
||||
"
|
||||
`;
|
||||
|
|
|
@ -10,9 +10,7 @@ var xxx = 0;
|
|||
xxx
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
require(\"./dummy\");
|
||||
|
||||
var xxx = 0;
|
||||
|
||||
xxx;
|
||||
"
|
||||
`;
|
||||
|
|
|
@ -10,9 +10,7 @@ var xxx = 0;
|
|||
xxx
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
require(\"./dummy\");
|
||||
|
||||
var xxx = 0;
|
||||
|
||||
xxx;
|
||||
"
|
||||
`;
|
||||
|
|
|
@ -51,28 +51,18 @@ let tests = [
|
|||
let tests = [
|
||||
function() {
|
||||
new Boolean();
|
||||
|
||||
new Boolean(0);
|
||||
|
||||
new Boolean(-0);
|
||||
|
||||
new Boolean(null);
|
||||
|
||||
new Boolean(false);
|
||||
|
||||
new Boolean(NaN);
|
||||
|
||||
new Boolean(undefined);
|
||||
|
||||
new Boolean(\"\");
|
||||
},
|
||||
function() {
|
||||
true.toString();
|
||||
|
||||
let x: boolean = false;
|
||||
|
||||
x.toString();
|
||||
|
||||
new Boolean(true).toString();
|
||||
},
|
||||
function() {
|
||||
|
@ -80,19 +70,12 @@ let tests = [
|
|||
},
|
||||
function() {
|
||||
Boolean();
|
||||
|
||||
Boolean(0);
|
||||
|
||||
Boolean(-0);
|
||||
|
||||
Boolean(null);
|
||||
|
||||
Boolean(false);
|
||||
|
||||
Boolean(NaN);
|
||||
|
||||
Boolean(undefined);
|
||||
|
||||
Boolean(\"\");
|
||||
}
|
||||
];
|
||||
|
@ -146,7 +129,6 @@ function* generator(): Iterable<[string, number]> {
|
|||
yield [ \"foo\", 123 ];
|
||||
}
|
||||
}
|
||||
|
||||
let tests = [
|
||||
function() {
|
||||
let w = new Map();
|
||||
|
@ -163,7 +145,6 @@ let tests = [
|
|||
},
|
||||
function(x: Map<string, number>) {
|
||||
(x.get(\"foo\"): boolean);
|
||||
|
||||
x.get(123);
|
||||
}
|
||||
];
|
||||
|
@ -214,33 +195,22 @@ let tests = [
|
|||
let tests = [
|
||||
function() {
|
||||
new RegExp(\"foo\");
|
||||
|
||||
new RegExp(/foo/);
|
||||
|
||||
new RegExp(\"foo\", \"i\");
|
||||
|
||||
new RegExp(\"foo\", \"ig\");
|
||||
|
||||
new RegExp(/foo/, \"i\");
|
||||
|
||||
new RegExp(/foo/g, \"i\");
|
||||
},
|
||||
function() {
|
||||
RegExp(\"foo\");
|
||||
|
||||
RegExp(/foo/);
|
||||
|
||||
RegExp(\"foo\", \"i\");
|
||||
|
||||
RegExp(\"foo\", \"ig\");
|
||||
|
||||
RegExp(/foo/, \"i\");
|
||||
|
||||
RegExp(/foo/g, \"i\");
|
||||
},
|
||||
function() {
|
||||
RegExp(\"foo\", \"z\");
|
||||
|
||||
new RegExp(\"foo\", \"z\");
|
||||
}
|
||||
];
|
||||
|
@ -291,43 +261,29 @@ let ws5 = new WeakSet(numbers()); // error, must be objects
|
|||
let ws = new WeakSet();
|
||||
let obj: Object = {};
|
||||
let dict: { foo: string } = { foo: \"bar\" };
|
||||
|
||||
ws.add(window);
|
||||
|
||||
ws.add(obj);
|
||||
|
||||
ws.add(dict);
|
||||
|
||||
ws.has(window);
|
||||
|
||||
ws.has(obj);
|
||||
|
||||
ws.has(dict);
|
||||
|
||||
ws.delete(window);
|
||||
|
||||
ws.delete(obj);
|
||||
|
||||
ws.delete(dict);
|
||||
|
||||
let ws2 = new WeakSet([ obj, dict ]);
|
||||
let ws3 = new WeakSet([ 1, 2, 3 ]);
|
||||
|
||||
function* generator(): Iterable<{ foo: string }> {
|
||||
while (true) {
|
||||
yield { foo: \"bar\" };
|
||||
}
|
||||
}
|
||||
|
||||
let ws4 = new WeakSet(generator());
|
||||
|
||||
function* numbers(): Iterable<number> {
|
||||
let i = 0;
|
||||
while (true) {
|
||||
yield i++;
|
||||
}
|
||||
}
|
||||
|
||||
let ws5 = new WeakSet(numbers());
|
||||
"
|
||||
`;
|
||||
|
|
|
@ -89,9 +89,7 @@ n.x = [0];
|
|||
type CovArrayVerbose<X, Y: X> = Array<Y>;
|
||||
var b: CovArrayVerbose<number, *> = [];
|
||||
var y: CovArrayVerbose<mixed, *> = b;
|
||||
|
||||
y[0] = \"\";
|
||||
|
||||
class NVerbose<E, I: E> {
|
||||
x: CovArrayVerbose<E, I>;
|
||||
foo(): CovArrayVerbose<mixed, I> {
|
||||
|
@ -99,11 +97,8 @@ class NVerbose<E, I: E> {
|
|||
}
|
||||
}
|
||||
var nv: NVerbose<number, *> = new NVerbose();
|
||||
|
||||
nv.x = [ 0 ];
|
||||
|
||||
(nv.x[0]: string);
|
||||
|
||||
(nv.foo()[0]: string);
|
||||
"
|
||||
`;
|
||||
|
|
|
@ -36,7 +36,6 @@ exports[`test no_pragma.js 1`] = `
|
|||
(x: string);
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
let x = 0;
|
||||
|
||||
(x: string);
|
||||
"
|
||||
`;
|
||||
|
|
|
@ -7,7 +7,6 @@ module.exports = A;
|
|||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
var B = require(\"./B\");
|
||||
class A extends B {}
|
||||
|
||||
module.exports = A;
|
||||
"
|
||||
`;
|
||||
|
@ -21,7 +20,6 @@ module.exports = B;
|
|||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//class B extends A { }
|
||||
var A = require(\"./A\");
|
||||
|
||||
module.exports = B;
|
||||
"
|
||||
`;
|
||||
|
|
|
@ -34,41 +34,23 @@ new Date(2015, 6, 18, 11, 55, 42, 999, \'hahaha\');
|
|||
var d = new Date(0);
|
||||
var x: string = d.getTime();
|
||||
var y: number = d;
|
||||
|
||||
new Date();
|
||||
|
||||
new Date(1234567890);
|
||||
|
||||
new Date(\"2015/06/18\");
|
||||
|
||||
new Date(2015, 6);
|
||||
|
||||
new Date(2015, 6, 18);
|
||||
|
||||
new Date(2015, 6, 18, 11);
|
||||
|
||||
new Date(2015, 6, 18, 11, 55);
|
||||
|
||||
new Date(2015, 6, 18, 11, 55, 42);
|
||||
|
||||
new Date(2015, 6, 18, 11, 55, 42, 999);
|
||||
|
||||
new Date({});
|
||||
|
||||
new Date(2015, \"6\");
|
||||
|
||||
new Date(2015, 6, \"18\");
|
||||
|
||||
new Date(2015, 6, 18, \"11\");
|
||||
|
||||
new Date(2015, 6, 18, 11, \"55\");
|
||||
|
||||
new Date(2015, 6, 18, 11, 55, \"42\");
|
||||
|
||||
new Date(2015, 6, 18, 11, 55, 42, \"999\");
|
||||
|
||||
new Date(\"2015\", 6);
|
||||
|
||||
new Date(2015, 6, 18, 11, 55, 42, 999, \"hahaha\");
|
||||
"
|
||||
`;
|
||||
|
|
|
@ -68,15 +68,10 @@ var ExplicitDifferentName = require(\'ExplicitProvidesModuleDifferentName\');
|
|||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
/* @flow */
|
||||
var Implicit = require(\"ImplicitProvidesModule\");
|
||||
|
||||
(Implicit.fun(): string);
|
||||
|
||||
var ExplicitSameName = require(\"ExplicitProvidesModuleSameName\");
|
||||
|
||||
(ExplicitSameName.fun(): string);
|
||||
|
||||
var ExplicitDifferentName = require(\"ExplicitProvidesModuleDifferentName\");
|
||||
|
||||
(ExplicitDifferentName.fun(): string);
|
||||
"
|
||||
`;
|
||||
|
|
|
@ -20,11 +20,8 @@ var docblock = require(\"qux/docblock\");
|
|||
var min = require(\"d3/min.js\");
|
||||
var corge = require(\"qux/corge\");
|
||||
var unreachable = require(\"annotation\");
|
||||
|
||||
(docblock.fun(): string);
|
||||
|
||||
(min.fun(): string);
|
||||
|
||||
(corge.fun(): string);
|
||||
"
|
||||
`;
|
||||
|
|
|
@ -25,7 +25,6 @@ module.exports.fun = (): Implementation => new Implementation;
|
|||
* @flow
|
||||
*/
|
||||
class Implementation {}
|
||||
|
||||
module.exports.fun = (): Implementation => new Implementation();
|
||||
"
|
||||
`;
|
||||
|
@ -44,7 +43,6 @@ module.exports.fun = (): Implementation => new Implementation;
|
|||
* @flow
|
||||
*/
|
||||
class Implementation {}
|
||||
|
||||
module.exports.fun = (): Implementation => new Implementation();
|
||||
"
|
||||
`;
|
||||
|
@ -63,7 +61,6 @@ module.exports.fun = (): Implementation => new Implementation;
|
|||
* @flow
|
||||
*/
|
||||
class Implementation {}
|
||||
|
||||
module.exports.fun = (): Implementation => new Implementation();
|
||||
"
|
||||
`;
|
||||
|
@ -93,15 +90,10 @@ var ExplicitDifferentName = require(\'ExplicitProvidesModuleDifferentName\');
|
|||
// Error: Either Implementation ~> boolean or Declaration ~> boolean
|
||||
// Error: Either Implementation ~> boolean or Declaration ~> boolean
|
||||
var Implicit = require(\"ImplicitProvidesModule\");
|
||||
|
||||
(Implicit.fun(): boolean);
|
||||
|
||||
var ExplicitSameName = require(\"ExplicitProvidesModuleSameName\");
|
||||
|
||||
(ExplicitSameName.fun(): boolean);
|
||||
|
||||
var ExplicitDifferentName = require(\"ExplicitProvidesModuleDifferentName\");
|
||||
|
||||
(ExplicitDifferentName.fun(): boolean);
|
||||
"
|
||||
`;
|
||||
|
|
|
@ -3,7 +3,6 @@ exports[`test min.js 1`] = `
|
|||
module.exports.fun = (): Implementation => new Implementation;
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
class Implementation {}
|
||||
|
||||
module.exports.fun = (): Implementation => new Implementation();
|
||||
"
|
||||
`;
|
||||
|
|
|
@ -16,11 +16,8 @@ var corge = require(\'qux/corge\');
|
|||
var docblock = require(\"qux/docblock\");
|
||||
var min = require(\"d3/min.js\");
|
||||
var corge = require(\"qux/corge\");
|
||||
|
||||
(docblock.fun(): boolean);
|
||||
|
||||
(min.fun(): boolean);
|
||||
|
||||
(corge.fun(): boolean);
|
||||
"
|
||||
`;
|
||||
|
|
|
@ -70,51 +70,28 @@ var F = require(\'package_with_dir_main\');
|
|||
// Error either Implementation ~> boolean or Declaration ~> boolean
|
||||
// Error either Implementation ~> boolean or Declaration ~> boolean
|
||||
var B1 = require(\"B\");
|
||||
|
||||
(B1.fun(): boolean);
|
||||
|
||||
var B2 = require(\"B.js\");
|
||||
|
||||
(B2.fun(): boolean);
|
||||
|
||||
var C = require(\"package_with_full_main\");
|
||||
|
||||
(C.fun(): boolean);
|
||||
|
||||
var D = require(\"package_with_partial_main\");
|
||||
|
||||
(D.fun(): boolean);
|
||||
|
||||
var E = require(\"package_with_no_package_json\");
|
||||
|
||||
(E.fun(): boolean);
|
||||
|
||||
var F = require(\"package_with_dir_main\");
|
||||
|
||||
(F.fun(): boolean);
|
||||
|
||||
var B1 = require(\"B\");
|
||||
|
||||
(B1.fun(): boolean);
|
||||
|
||||
var B2 = require(\"B.js\");
|
||||
|
||||
(B2.fun(): boolean);
|
||||
|
||||
var C = require(\"package_with_full_main\");
|
||||
|
||||
(C.fun(): boolean);
|
||||
|
||||
var D = require(\"package_with_partial_main\");
|
||||
|
||||
(D.fun(): boolean);
|
||||
|
||||
var E = require(\"package_with_no_package_json\");
|
||||
|
||||
(E.fun(): boolean);
|
||||
|
||||
var F = require(\"package_with_dir_main\");
|
||||
|
||||
(F.fun(): boolean);
|
||||
"
|
||||
`;
|
||||
|
@ -126,7 +103,6 @@ exports[`test test_relative.js 1`] = `
|
|||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// Error: either Implementation ~> boolean or Definition ~> boolean
|
||||
import {foo} from \"./A\";
|
||||
|
||||
(foo(): boolean);
|
||||
"
|
||||
`;
|
||||
|
|
|
@ -50,27 +50,16 @@ var F = require(\'package_with_dir_main\');
|
|||
// Error number ~> string
|
||||
// Error number ~> string
|
||||
var B1 = require(\"B\");
|
||||
|
||||
(B1.fun(): string);
|
||||
|
||||
var B2 = require(\"B.js\");
|
||||
|
||||
(B2.fun(): string);
|
||||
|
||||
var C = require(\"package_with_full_main\");
|
||||
|
||||
(C.fun(): string);
|
||||
|
||||
var D = require(\"package_with_partial_main\");
|
||||
|
||||
(D.fun(): string);
|
||||
|
||||
var E = require(\"package_with_no_package_json\");
|
||||
|
||||
(E.fun(): string);
|
||||
|
||||
var F = require(\"package_with_dir_main\");
|
||||
|
||||
(F.fun(): string);
|
||||
"
|
||||
`;
|
||||
|
@ -97,17 +86,11 @@ var CJS = require(\'./CJS.js\');
|
|||
// Error number ~> string
|
||||
// Error: string ~> number
|
||||
var A1 = require(\"./A\");
|
||||
|
||||
(A1.fun(): string);
|
||||
|
||||
var A2 = require(\"./A.js\");
|
||||
|
||||
(A2.fun(): string);
|
||||
|
||||
var CJS = require(\"./CJS.js\");
|
||||
|
||||
(CJS: string);
|
||||
|
||||
(CJS: number);
|
||||
"
|
||||
`;
|
||||
|
|
|
@ -12,13 +12,9 @@ C.foo(\"\");
|
|||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// error, it\'s a string
|
||||
declare class C { static x: number, static foo(x: number): void }
|
||||
|
||||
C.x = \"\";
|
||||
|
||||
C.foo(\"\");
|
||||
|
||||
(C.name: string);
|
||||
|
||||
(C.name: number);
|
||||
"
|
||||
`;
|
||||
|
|
|
@ -64,7 +64,6 @@ class Test extends Base {
|
|||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Test;
|
||||
"
|
||||
`;
|
||||
|
@ -114,13 +113,9 @@ exports.numberValue5 = 5;
|
|||
* @flow
|
||||
*/
|
||||
exports.numberValue1 = 1;
|
||||
|
||||
exports.numberValue2 = 2;
|
||||
|
||||
exports.numberValue3 = 3;
|
||||
|
||||
exports.numberValue4 = 4;
|
||||
|
||||
exports.numberValue5 = 5;
|
||||
"
|
||||
`;
|
||||
|
@ -493,13 +488,9 @@ exports.stringValue = \"str\";
|
|||
* @flow
|
||||
*/
|
||||
exports.numberValue1 = 42;
|
||||
|
||||
exports.numberValue2 = 42;
|
||||
|
||||
exports.numberValue3 = 42;
|
||||
|
||||
exports.numberValue4 = 42;
|
||||
|
||||
exports.stringValue = \"str\";
|
||||
"
|
||||
`;
|
||||
|
@ -990,33 +981,24 @@ var d2: string = numVal1;
|
|||
import CJS_Clobb_Lit from \"CommonJS_Clobbering_Lit\";
|
||||
var e1: number = CJS_Clobb_Lit.numberValue3;
|
||||
var e2: string = CJS_Clobb_Lit.numberValue3;
|
||||
|
||||
CJS_Clobb_Lit.doesntExist;
|
||||
|
||||
import * as CJS_Clobb_Lit_NS from \"CommonJS_Clobbering_Lit\";
|
||||
var f1: number = CJS_Clobb_Lit_NS.numberValue4;
|
||||
var f2: number = CJS_Clobb_Lit_NS.default.numberValue4;
|
||||
|
||||
CJS_Clobb_Lit_NS.default.default;
|
||||
|
||||
var f3: string = CJS_Clobb_Lit_NS.numberValue4;
|
||||
var f4: string = CJS_Clobb_Lit_NS.default.numberValue5;
|
||||
import {doesntExist2} from \"CommonJS_Clobbering_Class\";
|
||||
import {staticNumber1, baseProp, childProp} from \"CommonJS_Clobbering_Class\";
|
||||
import CJS_Clobb_Class from \"CommonJS_Clobbering_Class\";
|
||||
|
||||
new CJS_Clobb_Class();
|
||||
|
||||
new CJS_Clobb_Class().doesntExist;
|
||||
|
||||
var h1: number = CJS_Clobb_Class.staticNumber2();
|
||||
var h2: string = CJS_Clobb_Class.staticNumber2();
|
||||
var h3: number = new CJS_Clobb_Class().instNumber1();
|
||||
var h4: string = new CJS_Clobb_Class().instNumber1();
|
||||
import * as CJS_Clobb_Class_NS from \"CommonJS_Clobbering_Class\";
|
||||
|
||||
new CJS_Clobb_Class_NS();
|
||||
|
||||
var i1: number = CJS_Clobb_Class_NS.staticNumber3();
|
||||
var i2: number = new CJS_Clobb_Class_NS.default().instNumber2();
|
||||
var i3: string = new CJS_Clobb_Class_NS.default().instNumber2();
|
||||
|
@ -1030,9 +1012,7 @@ var k2: string = numVal3;
|
|||
import * as CJS_Named from \"CommonJS_Named\";
|
||||
var l1: number = CJS_Named.numberValue1;
|
||||
var l2: string = CJS_Named.numberValue1;
|
||||
|
||||
CJS_Named.doesntExist;
|
||||
|
||||
import * as CJS_Named_NS from \"CommonJS_Named\";
|
||||
var m1: number = CJS_Named_NS.numberValue4;
|
||||
var m2: string = CJS_Named_NS.default.numberValue4;
|
||||
|
@ -1082,9 +1062,7 @@ var ab2: string = numberValue2_renamed;
|
|||
import {numberValue1 as numberValue5} from \"ES6_ExportAllFrom_Intermediary1\";
|
||||
var ac1: number = numberValue5;
|
||||
var ac2: string = numberValue5;
|
||||
|
||||
require(\"ES6_Default_AnonFunction2\").doesntExist;
|
||||
|
||||
var ES6_Def_AnonFunc2 = require(\"ES6_Default_AnonFunction2\").default;
|
||||
var ad1: number = ES6_Def_AnonFunc2();
|
||||
var ad2: string = ES6_Def_AnonFunc2();
|
||||
|
|
|
@ -13,11 +13,8 @@ declare function foo<X>(x: X): X;
|
|||
declare function foo(x: number): string;
|
||||
declare function foo(x: string): number;
|
||||
declare function foo<X>(x: X): X;
|
||||
|
||||
(foo(0): string);
|
||||
|
||||
(foo(\"hello\"): number);
|
||||
|
||||
(foo(false): void);
|
||||
"
|
||||
`;
|
||||
|
|
|
@ -36,28 +36,17 @@ import declare_m_e_with_declare_var_e from \"declare_m_e_with_declare_var_e\";
|
|||
// Error: number ~> string
|
||||
// Error: number ~> string
|
||||
import declare_module_exports from \"declare_module_exports\";
|
||||
|
||||
(declare_module_exports: number);
|
||||
|
||||
(declare_module_exports: string);
|
||||
|
||||
import {str} from \"declare_m_e_with_other_value_declares\";
|
||||
import type {str2} from \"declare_m_e_with_other_type_declares\";
|
||||
|
||||
(\"asdf\": str2);
|
||||
|
||||
(42: str2);
|
||||
|
||||
import DEPRECATED__declare_var_exports from \"DEPRECATED__declare_var_exports\";
|
||||
|
||||
(DEPRECATED__declare_var_exports: number);
|
||||
|
||||
(DEPRECATED__declare_var_exports: string);
|
||||
|
||||
import declare_m_e_with_declare_var_e from \"declare_m_e_with_declare_var_e\";
|
||||
|
||||
(declare_m_e_with_declare_var_e: number);
|
||||
|
||||
(declare_m_e_with_declare_var_e: string);
|
||||
"
|
||||
`;
|
||||
|
|
|
@ -54,13 +54,9 @@ import type {toz} from \"ModuleAliasFoo\";
|
|||
var k4: toz = foo(k1);
|
||||
import blah from \"foo\";
|
||||
import type {Foo, Bar, Id} from \"foo\";
|
||||
|
||||
blah(0, 0);
|
||||
|
||||
({ toz: 3 }: Foo);
|
||||
|
||||
(3: Bar);
|
||||
|
||||
(\"lol\": Id<number>);
|
||||
"
|
||||
`;
|
||||
|
|
|
@ -55,13 +55,10 @@ class Variance<+Out, -In> {
|
|||
}
|
||||
class A {}
|
||||
class B extends A {}
|
||||
|
||||
function subtyping(v1: Variance<A, B>, v2: Variance<B, A>) {
|
||||
(v1: Variance<B, A>);
|
||||
|
||||
(v2: Variance<A, B>);
|
||||
}
|
||||
|
||||
class PropVariance<+Out, -In> {
|
||||
inv1: Out;
|
||||
inv2: In;
|
||||
|
|
|
@ -13,9 +13,7 @@ f(x);
|
|||
function f(x) {
|
||||
return 42 / x;
|
||||
}
|
||||
|
||||
var x = null;
|
||||
|
||||
f(x);
|
||||
"
|
||||
`;
|
||||
|
|
|
@ -33,15 +33,11 @@ class A {
|
|||
return callback(this.getX());
|
||||
}
|
||||
}
|
||||
|
||||
function callback(x: string) {
|
||||
return x.length;
|
||||
}
|
||||
|
||||
var a = new A(42);
|
||||
|
||||
a.onLoad(callback);
|
||||
|
||||
module.exports = A;
|
||||
"
|
||||
`;
|
||||
|
|
|
@ -19,11 +19,8 @@ require(\'./F\');
|
|||
require(\'./G\');
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
require(\"./D\");
|
||||
|
||||
require(\"./E\");
|
||||
|
||||
require(\"./F\");
|
||||
|
||||
require(\"./G\");
|
||||
"
|
||||
`;
|
||||
|
|
|
@ -23,15 +23,10 @@ let [ a, ...ys ] = xs;
|
|||
let [ b, ...zs ] = ys;
|
||||
let c = zs[0];
|
||||
let d = zs[1];
|
||||
|
||||
(a: void);
|
||||
|
||||
(b: void);
|
||||
|
||||
(c: void);
|
||||
|
||||
(d: void);
|
||||
|
||||
let [ ...e ] = 0;
|
||||
"
|
||||
`;
|
||||
|
@ -51,16 +46,11 @@ var { [\"key\"]: val3, ...spread } = { key: \"val\" };
|
|||
// ok (gasp!) by existing StrT -> ElemT rule
|
||||
// error (gasp!) in general we don\'t know if a computed prop should be excluded from spread
|
||||
var { [\"key\"]: val1 } = { key: \"val\" };
|
||||
|
||||
(val1: void);
|
||||
|
||||
var key: string = \"key\";
|
||||
var { [key]: val2 } = { key: \"val\" };
|
||||
|
||||
(val2: void);
|
||||
|
||||
var { [\"key\"]: val3, ...spread } = { key: \"val\" };
|
||||
|
||||
(spread.key: void);
|
||||
"
|
||||
`;
|
||||
|
@ -193,75 +183,45 @@ function default_expr_scope({a, b = a}) {}
|
|||
function obj_prop_fun({ p: { q = 0 } = { q: true } } = { p: { q: \"\" } }) {
|
||||
(q: void);
|
||||
}
|
||||
|
||||
obj_prop_fun();
|
||||
|
||||
obj_prop_fun({});
|
||||
|
||||
obj_prop_fun({ p: {} });
|
||||
|
||||
obj_prop_fun({ p: { q: null } });
|
||||
|
||||
function obj_prop_var(o = { p: { q: \"\" } }) {
|
||||
var { p: { q = 0 } = { q: true } } = o;
|
||||
|
||||
(q: void);
|
||||
}
|
||||
|
||||
obj_prop_var();
|
||||
|
||||
obj_prop_var({});
|
||||
|
||||
obj_prop_var({ p: {} });
|
||||
|
||||
obj_prop_var({ p: { q: null } });
|
||||
|
||||
function obj_rest(
|
||||
{ p: { q, ...o } = { q: 0, r: 0 } } = { p: { q: 0, r: \"\" } }
|
||||
) {
|
||||
(o.r: void);
|
||||
}
|
||||
|
||||
obj_rest();
|
||||
|
||||
obj_rest({});
|
||||
|
||||
obj_rest({ p: {} });
|
||||
|
||||
obj_rest({ p: { q: 0, r: null } });
|
||||
|
||||
function obj_prop_annot({ p = true }: { p: string } = { p: 0 }) {
|
||||
(p: void);
|
||||
}
|
||||
|
||||
var { p = true }: { p: string } = { p: 0 };
|
||||
|
||||
(p: void);
|
||||
|
||||
function obj_prop_err({ x: { y } } = null) {}
|
||||
|
||||
function obj_rest_err({ ...o } = 0) {}
|
||||
|
||||
function arr_elem_err([ x ] = null) {}
|
||||
|
||||
function arr_rest_err([ ...a ] = null) {}
|
||||
|
||||
function gen<T>(x: T, { p = x }: { p: T }): T {
|
||||
return p;
|
||||
}
|
||||
|
||||
obj_prop_fun(({}: { p?: { q?: null } }));
|
||||
|
||||
obj_prop_var(({}: { p?: { q?: null } }));
|
||||
|
||||
function obj_prop_opt({ p }: { p?: string } = { p: 0 }) {}
|
||||
|
||||
function obj_prop_maybe({ p }: { p: ?string } = { p: 0 }) {}
|
||||
|
||||
function obj_prop_union({ p }: { p: number | string } = { p: true }) {}
|
||||
|
||||
function obj_prop_union2({ p }: { p: number } | { p: string } = { p: true }) {}
|
||||
|
||||
function default_expr_scope({ a, b = a }) {}
|
||||
"
|
||||
`;
|
||||
|
@ -350,66 +310,41 @@ var cp2_err: string = others.childprop2; // Error: number ~> string
|
|||
declare var a: string;
|
||||
declare var b: string;
|
||||
declare var c: string;
|
||||
|
||||
[ { a1: a, b }, c ] = [ { a1: 0, b: 1 }, 2 ];
|
||||
|
||||
var { m } = { m: 0 };
|
||||
|
||||
({ m } = { m: m });
|
||||
|
||||
var obj;
|
||||
|
||||
({ n: obj.x } = { n: 3 });
|
||||
|
||||
[ obj.x ] = [ \"foo\" ];
|
||||
|
||||
function foo({ p, z: [ r ] }) {
|
||||
a = p;
|
||||
|
||||
b = z;
|
||||
|
||||
c = r;
|
||||
}
|
||||
|
||||
foo({ p: 0, z: [ 1, 2 ] });
|
||||
|
||||
[ a, , b, ...c ] = [ 0, 1, true, 3 ];
|
||||
|
||||
function bar({ x, ...z }) {
|
||||
var o: { x: string, y: number } = z;
|
||||
}
|
||||
|
||||
bar({ x: \"\", y: 0 });
|
||||
|
||||
var spread = { y: \"\" };
|
||||
var extend: { x: number, y: string, z: boolean } = { x: 0, ...spread };
|
||||
|
||||
function qux(_: { a: number }) {}
|
||||
|
||||
qux({ a: \"\" });
|
||||
|
||||
function corge({ b }: { b: string }) {}
|
||||
|
||||
corge({ b: 0 });
|
||||
|
||||
var { n }: { n: number } = { n: \"\" };
|
||||
|
||||
function test() {
|
||||
var { foo } = { bar: 123 };
|
||||
var { bar, baz } = { bar: 123 };
|
||||
}
|
||||
|
||||
function test() {
|
||||
var x = { foo: \"abc\", bar: 123 };
|
||||
var { foo, ...rest } = x;
|
||||
|
||||
(x.baz: string);
|
||||
|
||||
(rest.baz: string);
|
||||
}
|
||||
|
||||
module.exports = corge;
|
||||
|
||||
class Base {
|
||||
baseprop1: number;
|
||||
baseprop2: number;
|
||||
|
@ -463,7 +398,6 @@ exports[`test eager.js 1`] = `
|
|||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// error, property \`x\` can not be accessed on \`null\`
|
||||
var x;
|
||||
|
||||
({ x } = null);
|
||||
"
|
||||
`;
|
||||
|
@ -516,43 +450,27 @@ function arr_rest_pattern<X>([ _, ...a ] : ArrRest<X>) { // a: [X]
|
|||
// a: [X]
|
||||
// a: [X]
|
||||
function obj_pattern<X>({ prop }: { prop: X }) {}
|
||||
|
||||
type Prop<X> = { prop: X };
|
||||
|
||||
function obj_pattern2<X>({ prop }: Prop<X>) {}
|
||||
|
||||
function arr_pattern<X>([ elem ]: X[]) {}
|
||||
|
||||
type Elem<X> = X[];
|
||||
|
||||
function arr_pattern2<X>([ elem ]: Elem<X>) {}
|
||||
|
||||
function tup_pattern<X>([ proj ]: [X]) {}
|
||||
|
||||
type Proj<X> = [X];
|
||||
|
||||
function tup_pattern2<X>([ proj ]: Proj<X>) {}
|
||||
|
||||
function rest_antipattern<T>(...t: T) {}
|
||||
|
||||
function rest_pattern<X>(...r: X[]) {}
|
||||
|
||||
function obj_rest_pattern<X>({ _, ...o }: { _: any, x: X }) {
|
||||
o.x;
|
||||
}
|
||||
|
||||
type ObjRest<X> = { _: any, x: X };
|
||||
|
||||
function obj_rest_pattern<X>({ _, ...o }: ObjRest<X>) {
|
||||
o.x;
|
||||
}
|
||||
|
||||
function arr_rest_pattern<X>([ _, ...a ]: [any, X]) {
|
||||
a[0];
|
||||
}
|
||||
|
||||
type ArrRest<X> = [any, X];
|
||||
|
||||
function arr_rest_pattern<X>([ _, ...a ]: ArrRest<X>) {
|
||||
a[0];
|
||||
}
|
||||
|
@ -588,14 +506,11 @@ var { x: o } = o;
|
|||
let foo = (i: number) => [ i ];
|
||||
const bar = (i: number) => {
|
||||
[ i ] = foo(i);
|
||||
|
||||
return [ i ];
|
||||
};
|
||||
|
||||
foo = (i: number) => {
|
||||
return bar(i);
|
||||
};
|
||||
|
||||
declare var o;
|
||||
var { x: o } = o;
|
||||
"
|
||||
|
@ -611,11 +526,8 @@ var { \"with-dash\": with_dash } = { \"with-dash\": \"motivating example\" };
|
|||
// error: string ~> void
|
||||
// ok
|
||||
var { \"key\": val } = { key: \"val\" };
|
||||
|
||||
(val: void);
|
||||
|
||||
var { \"with-dash\": with_dash } = { \"with-dash\": \"motivating example\" };
|
||||
|
||||
(with_dash: \"motivating example\");
|
||||
"
|
||||
`;
|
||||
|
@ -633,7 +545,6 @@ function bar() {
|
|||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// @flow
|
||||
var { x } = { x: { foo: \"foo\" } };
|
||||
|
||||
function bar() {
|
||||
x.bar;
|
||||
}
|
||||
|
|
|
@ -38,10 +38,8 @@ function foo0(
|
|||
x: Array<{ [key: string]: mixed }>
|
||||
): Array<{ [key: string]: mixed }> {
|
||||
x[0].fooBar = \"foobar\";
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
function foo2(
|
||||
x: { [key: string]: number }
|
||||
): { [key: string]: number, +toString: () => string } {
|
||||
|
@ -504,231 +502,167 @@ class B extends A {}
|
|||
class C extends B {}
|
||||
class X {}
|
||||
class Y {}
|
||||
|
||||
function set_prop_to_string_key(o: { [k: string]: any }) {
|
||||
o.prop = \"ok\";
|
||||
}
|
||||
|
||||
function unsound_dict_has_every_key(o: { [k: string]: X }) {
|
||||
(o.p: X);
|
||||
|
||||
(o[\"p\"]: X);
|
||||
}
|
||||
|
||||
function set_prop_covariant(o: { [k: string]: B }) {
|
||||
o.p = new A();
|
||||
|
||||
o.p = new B();
|
||||
|
||||
o.p = new C();
|
||||
}
|
||||
|
||||
function get_prop_contravariant(o: { [k: string]: B }) {
|
||||
(o.p: A);
|
||||
|
||||
(o.p: B);
|
||||
|
||||
(o.p: C);
|
||||
}
|
||||
|
||||
function add_prop_to_nonstring_key_dot(o: { [k: number]: any }) {
|
||||
o.prop = \"err\";
|
||||
}
|
||||
|
||||
function add_prop_to_nonstring_key_bracket(o: { [k: number]: any }) {
|
||||
o[0] = \"ok\";
|
||||
}
|
||||
|
||||
function mix_with_declared_props(o: { [k: number]: X, p: Y }, x: X, y: Y) {
|
||||
(o[0]: X);
|
||||
|
||||
(o.p: Y);
|
||||
|
||||
o[0] = x;
|
||||
|
||||
o.p = y;
|
||||
}
|
||||
|
||||
function object_prototype(
|
||||
o: { [k: string]: number }
|
||||
): { [k: string]: number, +toString: () => string } {
|
||||
(o.toString(): boolean);
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
function unsound_string_conversion_alias_declared_prop(
|
||||
o: { [k: number]: any, \"0\": X }
|
||||
) {
|
||||
o[0] = \"not-x\";
|
||||
}
|
||||
|
||||
function unification_dict_values_invariant(x: Array<{ [k: string]: B }>) {
|
||||
let a: Array<{ [k: string]: A }> = x;
|
||||
|
||||
a[0].p = new A();
|
||||
|
||||
let b: Array<{ [k: string]: B }> = x;
|
||||
let c: Array<{ [k: string]: C }> = x;
|
||||
|
||||
(x[0].p: C);
|
||||
}
|
||||
|
||||
function subtype_dict_values_invariant(x: { [k: string]: B }) {
|
||||
let a: { [k: string]: A } = x;
|
||||
|
||||
a.p = new A();
|
||||
|
||||
let b: { [k: string]: B } = x;
|
||||
let c: { [k: string]: C } = x;
|
||||
|
||||
(x.p: C);
|
||||
}
|
||||
|
||||
function subtype_dict_values_fresh_exception() {
|
||||
let a: { [k: string]: A } = { a: new A(), b: new B(), c: new C() };
|
||||
let b: { [k: string]: B } = { a: new A(), b: new B(), c: new C() };
|
||||
let c: { [k: string]: C } = { a: new A(), b: new B(), c: new C() };
|
||||
}
|
||||
|
||||
function unification_dict_keys_invariant(x: Array<{ [k: B]: any }>) {
|
||||
let a: Array<{ [k: A]: any }> = x;
|
||||
let b: Array<{ [k: B]: any }> = x;
|
||||
let c: Array<{ [k: C]: any }> = x;
|
||||
}
|
||||
|
||||
function subtype_dict_keys_invariant(x: { [k: B]: any }) {
|
||||
let a: { [k: A]: any } = x;
|
||||
let b: { [k: B]: any } = x;
|
||||
let c: { [k: C]: any } = x;
|
||||
}
|
||||
|
||||
function unification_mix_with_declared_props_invariant_l(
|
||||
x: Array<{ [k: string]: B }>
|
||||
) {
|
||||
let a: Array<{ [k: string]: B, p: A }> = x;
|
||||
|
||||
a[0].p = new A();
|
||||
|
||||
let b: Array<{ [k: string]: B, p: B }> = x;
|
||||
let c: Array<{ [k: string]: B, p: C }> = x;
|
||||
|
||||
(x[0].p: C);
|
||||
}
|
||||
|
||||
function unification_mix_with_declared_props_invariant_r(
|
||||
xa: Array<{ [k: string]: A, p: B }>,
|
||||
xb: Array<{ [k: string]: B, p: B }>,
|
||||
xc: Array<{ [k: string]: C, p: B }>
|
||||
) {
|
||||
let a: Array<{ [k: string]: A }> = xa;
|
||||
|
||||
a[0].p = new A();
|
||||
|
||||
let b: Array<{ [k: string]: B }> = xb;
|
||||
let c: Array<{ [k: string]: C }> = xc;
|
||||
|
||||
(xc[0].p: C);
|
||||
}
|
||||
|
||||
function subtype_mix_with_declared_props_invariant_l(x: { [k: string]: B }) {
|
||||
let a: { [k: string]: B, p: A } = x;
|
||||
|
||||
a.p = new A();
|
||||
|
||||
let b: { [k: string]: B, p: B } = x;
|
||||
let c: { [k: string]: B, p: C } = x;
|
||||
|
||||
(x.p: C);
|
||||
}
|
||||
|
||||
function subtype_mix_with_declared_props_invariant_r(
|
||||
xa: { [k: string]: A, p: B },
|
||||
xb: { [k: string]: B, p: B },
|
||||
xc: { [k: string]: C, p: B }
|
||||
) {
|
||||
let a: { [k: string]: A } = xa;
|
||||
|
||||
a.p = new A();
|
||||
|
||||
let b: { [k: string]: B } = xb;
|
||||
let c: { [k: string]: C } = xc;
|
||||
|
||||
(xc.p: C);
|
||||
}
|
||||
|
||||
function unification_dict_to_obj(
|
||||
x: Array<{ [k: string]: X }>
|
||||
): Array<{ p: X }> {
|
||||
return x;
|
||||
}
|
||||
|
||||
function unification_obj_to_dict(
|
||||
x: Array<{ p: X }>
|
||||
): Array<{ [k: string]: X }> {
|
||||
return x;
|
||||
}
|
||||
|
||||
function subtype_dict_to_obj(x: { [k: string]: B }) {
|
||||
let a: { p: A } = x;
|
||||
|
||||
a.p = new A();
|
||||
|
||||
let b: { p: B } = x;
|
||||
let c: { p: C } = x;
|
||||
|
||||
(x.p: C);
|
||||
}
|
||||
|
||||
function subtype_obj_to_dict(x: { p: B }) {
|
||||
let a: { [k: string]: A } = x;
|
||||
|
||||
a.p = new A();
|
||||
|
||||
let b: { [k: string]: B } = x;
|
||||
let c: { [k: string]: C } = x;
|
||||
|
||||
(x.p: C);
|
||||
}
|
||||
|
||||
function subtype_obj_to_mixed(x: { p: B, x: X }) {
|
||||
let a: { [k: string]: A, x: X } = x;
|
||||
let b: { [k: string]: B, x: X } = x;
|
||||
let c: { [k: string]: C, x: X } = x;
|
||||
}
|
||||
|
||||
function unification_dict_to_mixed(x: Array<{ [k: string]: B }>) {
|
||||
let a: Array<{ [k: string]: B, p: A }> = x;
|
||||
let b: Array<{ [k: string]: B, p: B }> = x;
|
||||
let c: Array<{ [k: string]: B, p: C }> = x;
|
||||
}
|
||||
|
||||
function subtype_dict_to_mixed(x: { [k: string]: B }) {
|
||||
let a: { [k: string]: B, p: A } = x;
|
||||
let b: { [k: string]: B, p: B } = x;
|
||||
let c: { [k: string]: B, p: C } = x;
|
||||
}
|
||||
|
||||
function subtype_dict_to_optional_a(x: { [k: string]: B }) {
|
||||
let a: { p?: A } = x;
|
||||
}
|
||||
|
||||
function subtype_dict_to_optional_b(x: { [k: string]: B }) {
|
||||
let b: { p?: B } = x;
|
||||
}
|
||||
|
||||
function subtype_dict_to_optional_c(x: { [k: string]: B }) {
|
||||
let c: { p?: C } = x;
|
||||
}
|
||||
|
||||
function subtype_optional_a_to_dict(x: { p?: A }): { [k: string]: B } {
|
||||
return x;
|
||||
}
|
||||
|
||||
function subtype_optional_b_to_dict(x: { p?: B }): { [k: string]: B } {
|
||||
return x;
|
||||
}
|
||||
|
||||
function subtype_optional_c_to_dict(x: { p?: C }): { [k: string]: B } {
|
||||
return x;
|
||||
}
|
||||
|
@ -814,52 +748,41 @@ var z: { [key: number]: string } = x;
|
|||
var a: { [key: string]: ?string } = {};
|
||||
var b: { [key: string]: string } = a;
|
||||
var c: { [key: string]: ?string } = b;
|
||||
|
||||
function foo0(
|
||||
x: Array<{ [key: string]: number }>
|
||||
): Array<{ [key: string]: string }> {
|
||||
return x;
|
||||
}
|
||||
|
||||
function foo1(
|
||||
x: Array<{ [key: string]: number }>
|
||||
): Array<{ [key: string]: number, fooBar: string }> {
|
||||
return x;
|
||||
}
|
||||
|
||||
function foo2(
|
||||
x: Array<{ [key: string]: mixed }>
|
||||
): Array<{ [key: string]: mixed, fooBar: string }> {
|
||||
x[0].fooBar = 123;
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
function foo3(x: { [key: string]: number }): { foo: number } {
|
||||
return x;
|
||||
}
|
||||
|
||||
function foo4(
|
||||
x: { [key: string]: number }
|
||||
): { [key: string]: number, foo: string } {
|
||||
return x;
|
||||
}
|
||||
|
||||
function foo5(x: Array<{ [key: string]: number }>): Array<{ foo: number }> {
|
||||
return x;
|
||||
}
|
||||
|
||||
function foo6(x: Array<{ foo: number }>): Array<{ [key: string]: number }> {
|
||||
return x;
|
||||
}
|
||||
|
||||
function foo7(x: { [key: string]: number, bar: string }) {
|
||||
(x.bar: string);
|
||||
}
|
||||
|
||||
function foo8(x: { [key: string]: number }) {
|
||||
(x.foo: string);
|
||||
|
||||
(x.foo: number);
|
||||
}
|
||||
"
|
||||
|
@ -938,7 +861,6 @@ var o: { foo: QueryFunction } = {
|
|||
return params.count;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = o;
|
||||
"
|
||||
`;
|
||||
|
@ -952,7 +874,6 @@ o.foo = function (params) {
|
|||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// error, number ~/~ string
|
||||
var o = require(\"./test\");
|
||||
|
||||
o.foo = function(params) {
|
||||
return params.count;
|
||||
};
|
||||
|
|
|
@ -224,7 +224,6 @@ export function emitExpression(node: TypedNode) : t.Expression {
|
|||
import * as t from \"./jsAst\";
|
||||
const b = t.builders;
|
||||
import type {TypedNode} from \"./ast\";
|
||||
|
||||
function getBinaryOp(
|
||||
op: \"plus\" | \"minus\" | \"divide\" | \"multiply\"
|
||||
): \"+\" | \"-\" | \"*\" | \"/\" {
|
||||
|
@ -241,7 +240,6 @@ function getBinaryOp(
|
|||
throw new Error(\"Invalid binary operator: \" + op);
|
||||
}
|
||||
}
|
||||
|
||||
export function emitExpression(node: TypedNode): t.Expression {
|
||||
switch (node.exprNodeType) {
|
||||
case \"string_literal\":
|
||||
|
|
|
@ -102,7 +102,6 @@ exports[`test use_strict_with_flow.js 1`] = `
|
|||
/* @flow */
|
||||
// error
|
||||
\"use strict\";
|
||||
|
||||
(\"\": void);
|
||||
"
|
||||
`;
|
||||
|
|
|
@ -44,7 +44,6 @@ let tests = [
|
|||
let tests = [
|
||||
function(document: Document) {
|
||||
const event = document.createEvent(\"CustomEvent\");
|
||||
|
||||
event.initCustomEvent(\"butts\", true, false, { nice: 42 });
|
||||
}
|
||||
];
|
||||
|
@ -69,11 +68,8 @@ let tests = [
|
|||
let tests = [
|
||||
function(document: Document) {
|
||||
(document.createElement(\"canvas\"): HTMLCanvasElement);
|
||||
|
||||
(document.createElement(\"link\"): HTMLLinkElement);
|
||||
|
||||
(document.createElement(\"option\"): HTMLOptionElement);
|
||||
|
||||
(document.createElement(\"select\"): HTMLSelectElement);
|
||||
}
|
||||
];
|
||||
|
@ -106,21 +102,13 @@ let tests = [
|
|||
let tests = [
|
||||
function(element: Element) {
|
||||
element.scrollIntoView();
|
||||
|
||||
element.scrollIntoView(false);
|
||||
|
||||
element.scrollIntoView({});
|
||||
|
||||
element.scrollIntoView({ behavior: \"smooth\", block: \"end\" });
|
||||
|
||||
element.scrollIntoView({ block: \"end\" });
|
||||
|
||||
element.scrollIntoView({ behavior: \"smooth\" });
|
||||
|
||||
element.scrollIntoView({ behavior: \"invalid\" });
|
||||
|
||||
element.scrollIntoView({ block: \"invalid\" });
|
||||
|
||||
element.scrollIntoView(1);
|
||||
}
|
||||
];
|
||||
|
@ -173,21 +161,13 @@ let tests = [
|
|||
let tests = [
|
||||
function(element: HTMLElement) {
|
||||
element.scrollIntoView();
|
||||
|
||||
element.scrollIntoView(false);
|
||||
|
||||
element.scrollIntoView({});
|
||||
|
||||
element.scrollIntoView({ behavior: \"smooth\", block: \"end\" });
|
||||
|
||||
element.scrollIntoView({ block: \"end\" });
|
||||
|
||||
element.scrollIntoView({ behavior: \"smooth\" });
|
||||
|
||||
element.scrollIntoView({ behavior: \"invalid\" });
|
||||
|
||||
element.scrollIntoView({ block: \"invalid\" });
|
||||
|
||||
element.scrollIntoView(1);
|
||||
}
|
||||
];
|
||||
|
@ -215,13 +195,9 @@ let tests = [
|
|||
let tests = [
|
||||
function(el: HTMLInputElement) {
|
||||
el.setRangeText(\"foo\");
|
||||
|
||||
el.setRangeText(\"foo\", 123);
|
||||
|
||||
el.setRangeText(\"foo\", 123, 234);
|
||||
|
||||
el.setRangeText(\"foo\", 123, 234, \"select\");
|
||||
|
||||
el.setRangeText(\"foo\", 123, 234, \"bogus\");
|
||||
}
|
||||
];
|
||||
|
@ -326,16 +302,12 @@ let listener: EventListener = function(event: Event): void {};
|
|||
let tests = [
|
||||
function() {
|
||||
let target = new EventTarget();
|
||||
|
||||
(target.attachEvent(\"foo\", listener): void);
|
||||
|
||||
(target.attachEvent && target.attachEvent(\"foo\", listener): void);
|
||||
},
|
||||
function() {
|
||||
let target = new EventTarget();
|
||||
|
||||
(target.detachEvent(\"foo\", listener): void);
|
||||
|
||||
(target.detachEvent && target.detachEvent(\"foo\", listener): void);
|
||||
},
|
||||
function() {
|
||||
|
@ -368,11 +340,8 @@ let tests = [
|
|||
let tests = [
|
||||
function() {
|
||||
let path = new Path2D();
|
||||
|
||||
(path.arcTo(0, 0, 0, 0, 10): void);
|
||||
|
||||
(path.arcTo(0, 0, 0, 0, 10, 20, 5): void);
|
||||
|
||||
(path.arcTo(0, 0, 0, 0, 10, \"20\", 5): void);
|
||||
}
|
||||
];
|
||||
|
@ -726,12 +695,10 @@ let tests = [
|
|||
},
|
||||
function() {
|
||||
document.createNodeIterator(document.body);
|
||||
|
||||
document.createNodeIterator({});
|
||||
},
|
||||
function() {
|
||||
document.createTreeWalker(document.body);
|
||||
|
||||
document.createTreeWalker({});
|
||||
},
|
||||
function() {
|
||||
|
@ -893,17 +860,13 @@ let tests = [
|
|||
-1,
|
||||
node => NodeFilter.FILTER_ACCEPT
|
||||
);
|
||||
|
||||
document.createNodeIterator(document.body, -1, node => \"accept\");
|
||||
|
||||
document.createNodeIterator(document.body, -1, {
|
||||
accept: node => NodeFilter.FILTER_ACCEPT
|
||||
});
|
||||
|
||||
document.createNodeIterator(document.body, -1, {
|
||||
accept: node => \"accept\"
|
||||
});
|
||||
|
||||
document.createNodeIterator(document.body, -1, {});
|
||||
},
|
||||
function() {
|
||||
|
@ -912,15 +875,11 @@ let tests = [
|
|||
-1,
|
||||
node => NodeFilter.FILTER_ACCEPT
|
||||
);
|
||||
|
||||
document.createTreeWalker(document.body, -1, node => \"accept\");
|
||||
|
||||
document.createTreeWalker(document.body, -1, {
|
||||
accept: node => NodeFilter.FILTER_ACCEPT
|
||||
});
|
||||
|
||||
document.createTreeWalker(document.body, -1, { accept: node => \"accept\" });
|
||||
|
||||
document.createTreeWalker(document.body, -1, {});
|
||||
}
|
||||
];
|
||||
|
|
|
@ -7,11 +7,8 @@ module.exports = num;
|
|||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// @flow
|
||||
var num = 42;
|
||||
|
||||
function bar() {}
|
||||
|
||||
bar();
|
||||
|
||||
module.exports = num;
|
||||
"
|
||||
`;
|
||||
|
@ -42,35 +39,25 @@ const idxResult = idx(obj, obj => obj.a.b.c.d);
|
|||
// @flow
|
||||
// test deduping of inferred types
|
||||
var num = require(\"./import\");
|
||||
|
||||
function foo(x) {}
|
||||
|
||||
foo(0);
|
||||
|
||||
var a: string = num;
|
||||
|
||||
function unannotated(x) {
|
||||
return x;
|
||||
}
|
||||
|
||||
const nullToUndefined = val => val === null ? undefined : val;
|
||||
|
||||
function f0(x: ?Object) {
|
||||
return nullToUndefined(x);
|
||||
}
|
||||
|
||||
function f1(x: ?Object) {
|
||||
return nullToUndefined(x);
|
||||
}
|
||||
|
||||
function f2(x: ?string) {
|
||||
return nullToUndefined(x);
|
||||
}
|
||||
|
||||
function f3(x: ?string) {
|
||||
return nullToUndefined(x);
|
||||
}
|
||||
|
||||
declare var idx: $Facebookism$Idx;
|
||||
declare var obj: { a?: { b: ?{ c: null | { d: number } } } };
|
||||
const idxResult = idx(obj, obj => obj.a.b.c.d);
|
||||
|
|
|
@ -39,34 +39,26 @@ class C1 {
|
|||
m() {}
|
||||
m() {}
|
||||
}
|
||||
|
||||
new C1().m();
|
||||
|
||||
class C2 {
|
||||
get m() {
|
||||
return 42;
|
||||
}
|
||||
m() {}
|
||||
}
|
||||
|
||||
new C2().m();
|
||||
|
||||
class C3 {
|
||||
set m(x) {}
|
||||
m() {}
|
||||
}
|
||||
|
||||
new C3().m();
|
||||
|
||||
class C4 {
|
||||
get m() {
|
||||
return 42;
|
||||
}
|
||||
set m(x: number) {}
|
||||
}
|
||||
|
||||
new C4().m = new C4().m - 42;
|
||||
|
||||
class C5 {
|
||||
m() {}
|
||||
get m() {
|
||||
|
@ -74,7 +66,6 @@ class C5 {
|
|||
}
|
||||
set m(x: number) {}
|
||||
}
|
||||
|
||||
new C5().m = new C5().m - 42;
|
||||
"
|
||||
`;
|
||||
|
|
|
@ -23,20 +23,15 @@ var s3 = tag2 \`la la la\`;
|
|||
class A {}
|
||||
var a = new A();
|
||||
var s1 = \`l\${a.x}r\`;
|
||||
|
||||
function tag(strings, ...values) {
|
||||
var x: number = strings[0];
|
||||
return x;
|
||||
}
|
||||
|
||||
var s2 = tag\`l\${42}r\`;
|
||||
|
||||
function tag2(strings, ...values) {
|
||||
return { foo: \"\" };
|
||||
}
|
||||
|
||||
var s3 = tag2\`la la la\`;
|
||||
|
||||
(s3.foo: number);
|
||||
"
|
||||
`;
|
||||
|
|
|
@ -34,24 +34,17 @@ function isActive(
|
|||
): boolean {
|
||||
return ad.state === \"ACTIVE\";
|
||||
}
|
||||
|
||||
isActive({ state: \"PAUSE\" });
|
||||
|
||||
var MyStates = { PAUSED: \"PAUSED\", ACTIVE: \"ACTIVE\", DELETED: \"DELETED\" };
|
||||
|
||||
function isActive2(ad: { state: $Keys<typeof MyStates> }): boolean {
|
||||
return ad.state === MyStates.ACTIVE;
|
||||
}
|
||||
|
||||
isActive2({ state: \"PAUSE\" });
|
||||
|
||||
type Keys = $Keys<{ x: any, y: any }>;
|
||||
type Union = \"x\" | \"y\";
|
||||
|
||||
function keys2union(s: Keys): Union {
|
||||
return s;
|
||||
}
|
||||
|
||||
function union2keys(s: Union): Keys {
|
||||
return s;
|
||||
}
|
||||
|
|
|
@ -16,21 +16,13 @@ var x = (null : ?number);
|
|||
// error
|
||||
// error
|
||||
1 == 1;
|
||||
|
||||
\"foo\" == \"bar\";
|
||||
|
||||
1 == null;
|
||||
|
||||
null == 1;
|
||||
|
||||
1 == \"\";
|
||||
|
||||
\"\" == 1;
|
||||
|
||||
var x = (null: ?number);
|
||||
|
||||
x == 1;
|
||||
|
||||
1 == x;
|
||||
"
|
||||
`;
|
||||
|
|
|
@ -64,7 +64,6 @@ class Test extends Base {
|
|||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Test;
|
||||
"
|
||||
`;
|
||||
|
@ -132,13 +131,9 @@ exports.numberValue5 = 5;
|
|||
* @flow
|
||||
*/
|
||||
exports.numberValue1 = 1;
|
||||
|
||||
exports.numberValue2 = 2;
|
||||
|
||||
exports.numberValue3 = 3;
|
||||
|
||||
exports.numberValue4 = 4;
|
||||
|
||||
exports.numberValue5 = 5;
|
||||
"
|
||||
`;
|
||||
|
@ -244,7 +239,6 @@ export default class Foo {
|
|||
return 42;
|
||||
}
|
||||
}
|
||||
|
||||
new Foo();
|
||||
"
|
||||
`;
|
||||
|
@ -588,13 +582,9 @@ exports.stringValue = \"str\";
|
|||
* @flow
|
||||
*/
|
||||
exports.numberValue1 = 42;
|
||||
|
||||
exports.numberValue2 = 42;
|
||||
|
||||
exports.numberValue3 = 42;
|
||||
|
||||
exports.numberValue4 = 42;
|
||||
|
||||
exports.stringValue = \"str\";
|
||||
"
|
||||
`;
|
||||
|
@ -1100,33 +1090,24 @@ var d2: string = numVal1;
|
|||
import CJS_Clobb_Lit from \"CommonJS_Clobbering_Lit\";
|
||||
var e1: number = CJS_Clobb_Lit.numberValue3;
|
||||
var e2: string = CJS_Clobb_Lit.numberValue3;
|
||||
|
||||
CJS_Clobb_Lit.doesntExist;
|
||||
|
||||
import * as CJS_Clobb_Lit_NS from \"CommonJS_Clobbering_Lit\";
|
||||
var f1: number = CJS_Clobb_Lit_NS.numberValue4;
|
||||
var f2: number = CJS_Clobb_Lit_NS.default.numberValue4;
|
||||
|
||||
CJS_Clobb_Lit_NS.default.default;
|
||||
|
||||
var f3: string = CJS_Clobb_Lit_NS.numberValue4;
|
||||
var f4: string = CJS_Clobb_Lit_NS.default.numberValue5;
|
||||
import {doesntExist2} from \"CommonJS_Clobbering_Class\";
|
||||
import {staticNumber1, baseProp, childProp} from \"CommonJS_Clobbering_Class\";
|
||||
import CJS_Clobb_Class from \"CommonJS_Clobbering_Class\";
|
||||
|
||||
new CJS_Clobb_Class();
|
||||
|
||||
new CJS_Clobb_Class().doesntExist;
|
||||
|
||||
var h1: number = CJS_Clobb_Class.staticNumber2();
|
||||
var h2: string = CJS_Clobb_Class.staticNumber2();
|
||||
var h3: number = new CJS_Clobb_Class().instNumber1();
|
||||
var h4: string = new CJS_Clobb_Class().instNumber1();
|
||||
import * as CJS_Clobb_Class_NS from \"CommonJS_Clobbering_Class\";
|
||||
|
||||
new CJS_Clobb_Class_NS();
|
||||
|
||||
var i1: number = CJS_Clobb_Class_NS.staticNumber3();
|
||||
var i2: number = new CJS_Clobb_Class_NS.default().instNumber2();
|
||||
var i3: string = new CJS_Clobb_Class_NS.default().instNumber2();
|
||||
|
@ -1140,9 +1121,7 @@ var k2: string = numVal3;
|
|||
import * as CJS_Named from \"CommonJS_Named\";
|
||||
var l1: number = CJS_Named.numberValue1;
|
||||
var l2: string = CJS_Named.numberValue1;
|
||||
|
||||
CJS_Named.doesntExist;
|
||||
|
||||
import * as CJS_Named_NS from \"CommonJS_Named\";
|
||||
var m1: number = CJS_Named_NS.numberValue4;
|
||||
var m2: string = CJS_Named_NS.default.numberValue4;
|
||||
|
@ -1201,9 +1180,7 @@ var ab2: string = numberValue2_renamed;
|
|||
import {numberValue1 as numberValue5} from \"ES6_ExportAllFrom_Intermediary1\";
|
||||
var ac1: number = numberValue5;
|
||||
var ac2: string = numberValue5;
|
||||
|
||||
require(\"ES6_Default_AnonFunction2\").doesntExist;
|
||||
|
||||
var ES6_Def_AnonFunc2 = require(\"ES6_Default_AnonFunction2\").default;
|
||||
var ad1: number = ES6_Def_AnonFunc2();
|
||||
var ad2: string = ES6_Def_AnonFunc2();
|
||||
|
@ -1356,48 +1333,27 @@ function testRequires() {
|
|||
// CommonJS module that clobbers module.exports with a frozen object
|
||||
// Error: frozen
|
||||
import * as DefaultA from \"A\";
|
||||
|
||||
DefaultA.numberValue1 = 123;
|
||||
|
||||
import * as ES6_Named1 from \"ES6_Named1\";
|
||||
|
||||
ES6_Named1.varDeclNumber1 = 123;
|
||||
|
||||
import * as CommonJS_Star from \"CommonJS_Clobbering_Lit\";
|
||||
|
||||
CommonJS_Star.numberValue1 = 123;
|
||||
|
||||
CommonJS_Star.default.numberValue1 = 123;
|
||||
|
||||
import CommonJS_Clobbering_Lit from \"CommonJS_Clobbering_Lit\";
|
||||
|
||||
CommonJS_Clobbering_Lit.numberValue1 = 123;
|
||||
|
||||
import * as CommonJS_Frozen_Star from \"CommonJS_Clobbering_Frozen\";
|
||||
|
||||
CommonJS_Frozen_Star.numberValue1 = 123;
|
||||
|
||||
CommonJS_Frozen_Star.default.numberValue1 = 123;
|
||||
|
||||
import CommonJS_Clobbering_Frozen from \"CommonJS_Clobbering_Frozen\";
|
||||
|
||||
CommonJS_Clobbering_Frozen.numberValue1 = 123;
|
||||
|
||||
function testRequires() {
|
||||
var DefaultA = require(\"A\");
|
||||
|
||||
DefaultA.numberValue1 = 123;
|
||||
|
||||
var ES6_Named1 = require(\"ES6_Named1\");
|
||||
|
||||
ES6_Named1.numberValue = 123;
|
||||
|
||||
var CommonJS_Star = require(\"CommonJS_Clobbering_Lit\");
|
||||
|
||||
CommonJS_Star.numberValue1 = 123;
|
||||
|
||||
var CommonJS_Frozen_Star = require(\"CommonJS_Clobbering_Frozen\");
|
||||
|
||||
CommonJS_Frozen_Star.numberValue1 = 123;
|
||||
}
|
||||
"
|
||||
|
|
|
@ -58,63 +58,36 @@ import {exports as nope} from \"ES\"; // Error: Not an export
|
|||
// Error: Not an export
|
||||
import {num1, str1} from \"CJS_Named\";
|
||||
import CJS_Named from \"CJS_Named\";
|
||||
|
||||
(num1: number);
|
||||
|
||||
(num1: string);
|
||||
|
||||
(str1: string);
|
||||
|
||||
(str1: number);
|
||||
|
||||
(CJS_Named: { num1: number, str1: string });
|
||||
|
||||
(CJS_Named: number);
|
||||
|
||||
import {num2} from \"CJS_Clobbered\";
|
||||
import {numExport} from \"CJS_Clobbered\";
|
||||
|
||||
(numExport: number);
|
||||
|
||||
(numExport: string);
|
||||
|
||||
import type {numType} from \"CJS_Clobbered\";
|
||||
|
||||
(42: numType);
|
||||
|
||||
(\"asdf\": numType);
|
||||
|
||||
import {strHidden} from \"ES\";
|
||||
import {str3} from \"ES\";
|
||||
|
||||
(str3: string);
|
||||
|
||||
(str3: number);
|
||||
|
||||
import {num3} from \"ES\";
|
||||
|
||||
(num3: number);
|
||||
|
||||
(num3: string);
|
||||
|
||||
import {C} from \"ES\";
|
||||
import type {C as CType} from \"ES\";
|
||||
|
||||
(new C(): C);
|
||||
|
||||
(42: C);
|
||||
|
||||
(new C(): CType);
|
||||
|
||||
(42: CType);
|
||||
|
||||
import {T} from \"ES\";
|
||||
import type {T as T2} from \"ES\";
|
||||
|
||||
(42: T2);
|
||||
|
||||
(\"asdf\": T2);
|
||||
|
||||
import {exports as nope} from \"ES\";
|
||||
"
|
||||
`;
|
||||
|
|
|
@ -18,15 +18,10 @@ N.z = Q(N.z);
|
|||
// declaration of Q redirects to module M
|
||||
var M = require(\"M\");
|
||||
var N = require(\"N\");
|
||||
|
||||
N.x = M(N.x);
|
||||
|
||||
var P = require(\"./P\");
|
||||
|
||||
N.y = P(N.y);
|
||||
|
||||
var Q = require(\"Q\");
|
||||
|
||||
N.z = Q(N.z);
|
||||
"
|
||||
`;
|
||||
|
|
|
@ -9,7 +9,6 @@ module.exports = {}
|
|||
/* @flow */
|
||||
export type talias4 = number;
|
||||
export interface IFoo { prop: number }
|
||||
|
||||
module.exports = {};
|
||||
"
|
||||
`;
|
||||
|
|
|
@ -3,7 +3,6 @@ exports[`test foo.js 1`] = `
|
|||
imp(1337);
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
var imp = require(\"./bar\");
|
||||
|
||||
imp(1337);
|
||||
"
|
||||
`;
|
||||
|
|
|
@ -7,9 +7,7 @@ var React = require(\'react\');
|
|||
// @flow
|
||||
// Error: ReactElement ~> number
|
||||
var React = require(\"react\");
|
||||
|
||||
(<fbt/>: React.Element<*>);
|
||||
|
||||
(<fbt/>: number);
|
||||
"
|
||||
`;
|
||||
|
|
|
@ -7,7 +7,6 @@ exports[`test main.js 1`] = `
|
|||
// @flow
|
||||
// Error (the libdef in this test marks fbt as number)
|
||||
(<fbt/>: number);
|
||||
|
||||
(<fbt/>: string);
|
||||
"
|
||||
`;
|
||||
|
|
|
@ -3,7 +3,6 @@ exports[`test Bar.js 1`] = `
|
|||
module.exports = Bar;
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
var Bar = { x: 0 };
|
||||
|
||||
module.exports = Bar;
|
||||
"
|
||||
`;
|
||||
|
@ -63,9 +62,7 @@ let tests = [
|
|||
},
|
||||
function(copyProperties: Object$Assign) {
|
||||
let result = {};
|
||||
|
||||
result.baz = false;
|
||||
|
||||
(copyProperties(result, { foo: \"a\" }, {
|
||||
bar: 123
|
||||
}): { foo: string, bar: number, baz: boolean });
|
||||
|
@ -74,17 +71,14 @@ let tests = [
|
|||
const copyProperties = require(\"copyProperties\");
|
||||
let x = { foo: \"a\" };
|
||||
let y = { bar: 123 };
|
||||
|
||||
(copyProperties({}, x, y): { foo: string, bar: number });
|
||||
},
|
||||
function(copyProperties: Object$Assign) {
|
||||
copyProperties();
|
||||
|
||||
(copyProperties({ foo: \"a\" }): { foo: number });
|
||||
},
|
||||
function(copyProperties: Object$Assign) {
|
||||
function x(cb: Function) {}
|
||||
|
||||
x(copyProperties);
|
||||
}
|
||||
];
|
||||
|
@ -112,14 +106,11 @@ let tests = [
|
|||
let tests = [
|
||||
function() {
|
||||
let x: ?string = null;
|
||||
|
||||
invariant(x, \"truthy only\");
|
||||
},
|
||||
function(invariant: Function) {
|
||||
let x: ?string = null;
|
||||
|
||||
invariant(x);
|
||||
|
||||
(x: string);
|
||||
}
|
||||
];
|
||||
|
@ -200,17 +191,13 @@ let tests = [
|
|||
},
|
||||
function(mergeInto: $Facebookism$MergeInto) {
|
||||
let result = {};
|
||||
|
||||
result.baz = false;
|
||||
|
||||
(mergeInto(result, { foo: \"a\" }, { bar: 123 }): void);
|
||||
|
||||
(result: { foo: string, bar: number, baz: boolean });
|
||||
},
|
||||
function() {
|
||||
const mergeInto = require(\"mergeInto\");
|
||||
let result: { foo?: string, bar?: number, baz: boolean } = { baz: false };
|
||||
|
||||
(mergeInto(result, { foo: \"a\" }, { bar: 123 }): void);
|
||||
},
|
||||
function(mergeInto: $Facebookism$MergeInto) {
|
||||
|
@ -218,7 +205,6 @@ let tests = [
|
|||
},
|
||||
function(mergeInto: $Facebookism$MergeInto) {
|
||||
function x(cb: Function) {}
|
||||
|
||||
x(mergeInto);
|
||||
}
|
||||
];
|
||||
|
@ -241,7 +227,6 @@ var mixin = require(\"mixin\");
|
|||
class Foo extends mixin(Bar) {
|
||||
m() {
|
||||
var x: string = this.x;
|
||||
|
||||
this.y = \"\";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -98,31 +98,21 @@ const b = new Headers([ \"Content-Type\", \"image/jpeg\" ]);
|
|||
const c = new Headers({ \"Content-Type\", \"image/jpeg\" });
|
||||
const d = new Headers(c);
|
||||
const e: Headers = new Headers();
|
||||
|
||||
e.append(\"Content-Type\", \"image/jpeg\");
|
||||
|
||||
e.append(\"Content-Type\");
|
||||
|
||||
e.append({ \"Content-Type\", \"image/jpeg\" });
|
||||
|
||||
e.set(\"Content-Type\", \"image/jpeg\");
|
||||
|
||||
e.set(\"Content-Type\");
|
||||
|
||||
e.set({ \"Content-Type\", \"image/jpeg\" });
|
||||
|
||||
const f: Headers = e.append(\"Content-Type\", \"image/jpeg\");
|
||||
const g: string = e.get(\"Content-Type\");
|
||||
const h: number = e.get(\"Content-Type\");
|
||||
|
||||
for (let v of e) {
|
||||
const [ i, j ]: [string, string] = v;
|
||||
}
|
||||
|
||||
for (let v of e.entries()) {
|
||||
const [ i, j ]: [string, string] = v;
|
||||
}
|
||||
|
||||
e.getAll(\"content-type\").forEach((v: string) => {});
|
||||
"
|
||||
`;
|
||||
|
@ -229,13 +219,9 @@ const k: Request = new Request(\"http://example.org\", {
|
|||
cache: \"default\"
|
||||
});
|
||||
var l: boolean = h.bodyUsed;
|
||||
|
||||
h.text().then((t: string) => t);
|
||||
|
||||
h.text().then((t: Buffer) => t);
|
||||
|
||||
h.arrayBuffer().then((ab: ArrayBuffer) => ab);
|
||||
|
||||
h.arrayBuffer().then((ab: Buffer) => ab);
|
||||
"
|
||||
`;
|
||||
|
@ -325,13 +311,9 @@ const i: Response = new Response({
|
|||
});
|
||||
const ok: boolean = h.ok;
|
||||
const status: number = h.status;
|
||||
|
||||
h.text().then((t: string) => t);
|
||||
|
||||
h.text().then((t: Buffer) => t);
|
||||
|
||||
h.arrayBuffer().then((ab: ArrayBuffer) => ab);
|
||||
|
||||
h.arrayBuffer().then((ab: Buffer) => ab);
|
||||
"
|
||||
`;
|
||||
|
@ -389,31 +371,21 @@ const b = new URLSearchParams([ \"key1\", \"value1\" ]);
|
|||
const c = new URLSearchParams({ \"key1\", \"value1\" });
|
||||
const d = new URLSearchParams(c);
|
||||
const e: URLSearchParams = new URLSearchParams();
|
||||
|
||||
e.append(\"key1\", \"value1\");
|
||||
|
||||
e.append(\"key1\");
|
||||
|
||||
e.append({ \"key1\", \"value1\" });
|
||||
|
||||
e.set(\"key1\", \"value1\");
|
||||
|
||||
e.set(\"key1\");
|
||||
|
||||
e.set({ \"key1\", \"value1\" });
|
||||
|
||||
const f: URLSearchParams = e.append(\"key1\", \"value1\");
|
||||
const g: string = e.get(\"key1\");
|
||||
const h: number = e.get(\"key1\");
|
||||
|
||||
for (let v of e) {
|
||||
const [ i, j ]: [string, string] = v;
|
||||
}
|
||||
|
||||
for (let v of e.entries()) {
|
||||
const [ i, j ]: [string, string] = v;
|
||||
}
|
||||
|
||||
e.getAll(\"key1\").forEach((v: string) => {});
|
||||
"
|
||||
`;
|
||||
|
|
|
@ -12,9 +12,7 @@ exports[`test test.js 1`] = `
|
|||
import x from \'./req\';
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
var x = require(\"./req\");
|
||||
|
||||
(x: string);
|
||||
|
||||
import x from \"./req\";
|
||||
"
|
||||
`;
|
||||
|
|
|
@ -34,15 +34,12 @@ module.exports = {fn: fix};
|
|||
function eq(x: number, y: number) {
|
||||
return true;
|
||||
}
|
||||
|
||||
function sub(x: number, y: number) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
function mul(x: number, y: number) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
function fix(fold) {
|
||||
var delta = function(delta) {
|
||||
return fold(function(x) {
|
||||
|
@ -52,23 +49,18 @@ function fix(fold) {
|
|||
};
|
||||
return delta(delta);
|
||||
}
|
||||
|
||||
function mk_factorial() {
|
||||
return fix(function(factorial) {
|
||||
return function(n) {
|
||||
if (eq(n, 1)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return mul(factorial(sub(n, 1)), n);
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
var factorial = mk_factorial();
|
||||
|
||||
factorial(\"...\");
|
||||
|
||||
module.exports = { fn: fix };
|
||||
"
|
||||
`;
|
||||
|
@ -101,30 +93,22 @@ function Y(f) {
|
|||
function g(x) {
|
||||
return f(x(x));
|
||||
}
|
||||
|
||||
g(g);
|
||||
}
|
||||
|
||||
function func1(f) {
|
||||
function fix_f(x: number): number {
|
||||
return f(x);
|
||||
}
|
||||
|
||||
return fix_f;
|
||||
}
|
||||
|
||||
function func2(f) {
|
||||
function fix_f(x: string): string {
|
||||
return f(x);
|
||||
}
|
||||
|
||||
return fix_f;
|
||||
}
|
||||
|
||||
Y(func1);
|
||||
|
||||
Y(func2);
|
||||
|
||||
module.exports = Y;
|
||||
"
|
||||
`;
|
||||
|
|
|
@ -50,38 +50,28 @@ function corge(x: boolean) {
|
|||
/* @flow */
|
||||
function foo(x: boolean) {
|
||||
var max = 10;
|
||||
|
||||
for (var ii = 0; ii < max; ii++) {
|
||||
if (x) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(\"this is still reachable\");
|
||||
}
|
||||
|
||||
function bar(x: boolean) {
|
||||
var max = 0;
|
||||
|
||||
for (var ii = 0; ii < max; ii++) {
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(\"this is still reachable\");
|
||||
}
|
||||
|
||||
function baz(x: boolean) {
|
||||
var max = 0;
|
||||
|
||||
for (var ii = 0; ii < max; ii++) {
|
||||
continue;
|
||||
}
|
||||
|
||||
console.log(\"this is still reachable\");
|
||||
}
|
||||
|
||||
function bliffl(x: boolean) {
|
||||
var max = 10;
|
||||
loop1:
|
||||
|
@ -90,20 +80,15 @@ function bliffl(x: boolean) {
|
|||
for (var jj = 0; jj < max; jj++) {
|
||||
break loop1;
|
||||
}
|
||||
|
||||
console.log(\"this is still reachable\");
|
||||
}
|
||||
|
||||
console.log(\"this is still reachable\");
|
||||
}
|
||||
|
||||
function corge(x: boolean) {
|
||||
var max = 0;
|
||||
|
||||
for (var ii = 0; ii < max; ii++) {
|
||||
break;
|
||||
}
|
||||
|
||||
console.log(\"this is still reachable\");
|
||||
}
|
||||
"
|
||||
|
@ -155,34 +140,26 @@ function corge(x: boolean) {
|
|||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
function foo(x: boolean) {
|
||||
var obj = { a: 1, b: 2 };
|
||||
|
||||
for (var prop in obj) {
|
||||
if (x) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(\"this is still reachable\");
|
||||
}
|
||||
|
||||
function bar(x: boolean) {
|
||||
for (var prop in {}) {
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(\"this is still reachable\");
|
||||
}
|
||||
|
||||
function baz(x: boolean) {
|
||||
for (var prop in {}) {
|
||||
continue;
|
||||
}
|
||||
|
||||
console.log(\"this is still reachable\");
|
||||
}
|
||||
|
||||
function bliffl(x: boolean) {
|
||||
var obj = { a: 1, b: 2 };
|
||||
loop1:
|
||||
|
@ -191,18 +168,14 @@ function bliffl(x: boolean) {
|
|||
for (var prop2 in obj) {
|
||||
break loop1;
|
||||
}
|
||||
|
||||
console.log(\"this is still reachable\");
|
||||
}
|
||||
|
||||
console.log(\"this is still reachable\");
|
||||
}
|
||||
|
||||
function corge(x: boolean) {
|
||||
for (var prop in {}) {
|
||||
break;
|
||||
}
|
||||
|
||||
console.log(\"this is still reachable\");
|
||||
}
|
||||
"
|
||||
|
@ -254,34 +227,26 @@ function corge(x: boolean) {
|
|||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
function foo(x: boolean) {
|
||||
var arr = [ 1, 2, 3 ];
|
||||
|
||||
for (var elem of arr) {
|
||||
if (x) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(\"this is still reachable\");
|
||||
}
|
||||
|
||||
function bar(x: boolean) {
|
||||
for (var elem of []) {
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(\"this is still reachable\");
|
||||
}
|
||||
|
||||
function baz(x: boolean) {
|
||||
for (var elem of []) {
|
||||
continue;
|
||||
}
|
||||
|
||||
console.log(\"this is still reachable\");
|
||||
}
|
||||
|
||||
function bliffl(x: boolean) {
|
||||
var arr = [ 1, 2, 3 ];
|
||||
loop1:
|
||||
|
@ -290,18 +255,14 @@ function bliffl(x: boolean) {
|
|||
for (var elem of arr) {
|
||||
break loop1;
|
||||
}
|
||||
|
||||
console.log(\"this is still reachable\");
|
||||
}
|
||||
|
||||
console.log(\"this is still reachable\");
|
||||
}
|
||||
|
||||
function corge(x: boolean) {
|
||||
for (var elem of []) {
|
||||
break;
|
||||
}
|
||||
|
||||
console.log(\"this is still reachable\");
|
||||
}
|
||||
"
|
||||
|
|
|
@ -69,47 +69,38 @@ function testArray(arr: Array<number>): void {
|
|||
(x: string);
|
||||
}
|
||||
}
|
||||
|
||||
function testIterable1(iterable: Iterable<number>): void {
|
||||
for (var x of iterable) {
|
||||
(x: string);
|
||||
}
|
||||
}
|
||||
|
||||
function testIterable2(iterable: Iterable<*>): void {
|
||||
for (var x of iterable) {
|
||||
(x: string);
|
||||
}
|
||||
}
|
||||
|
||||
function testString(str: string): void {
|
||||
for (var x of str) {
|
||||
(x: number);
|
||||
}
|
||||
}
|
||||
|
||||
function testMap1(map: Map<string, number>): void {
|
||||
for (var elem of map) {
|
||||
(elem: [string, number]);
|
||||
|
||||
(elem: number);
|
||||
}
|
||||
}
|
||||
|
||||
function testMap2(map: Map<*, *>): void {
|
||||
for (var elem of map) {
|
||||
(elem: [number, string]);
|
||||
|
||||
(elem: number);
|
||||
}
|
||||
}
|
||||
|
||||
function testSet1(set: Set<string>): void {
|
||||
for (var x of set) {
|
||||
(x: number);
|
||||
}
|
||||
}
|
||||
|
||||
function testSet2(set: Set<*>): void {
|
||||
for (var x of set) {
|
||||
(x: number);
|
||||
|
|
|
@ -69,39 +69,24 @@ function test2(): number { return 0; }
|
|||
function test(a: string, b: number): number {
|
||||
return this.length;
|
||||
}
|
||||
|
||||
test.apply(\"\", [ \"\", 0 ]);
|
||||
|
||||
test.apply(0, [ \"\", 0 ]);
|
||||
|
||||
test.apply(\"\", [ \"\" ]);
|
||||
|
||||
test.apply(\"\", [ \"\", \"\" ]);
|
||||
|
||||
test.apply(\"\", [ 0, 0 ]);
|
||||
|
||||
function f(args) {
|
||||
test.apply(\"\", args);
|
||||
}
|
||||
|
||||
f([ \"\", 0 ]);
|
||||
|
||||
f([ \"\", \"\" ]);
|
||||
|
||||
f([ 0, 0 ]);
|
||||
|
||||
test.apply(\"\", \"not array\");
|
||||
|
||||
(test.call.apply(test, [ 0, 123, \"foo\" ]): void);
|
||||
|
||||
(test.bind.apply(test, [ 0, 123 ]): (b: number) => number);
|
||||
|
||||
function test2(): number {
|
||||
return 0;
|
||||
}
|
||||
|
||||
(test2.apply(): number);
|
||||
|
||||
(test2.apply(\"\"): number);
|
||||
"
|
||||
`;
|
||||
|
@ -123,9 +108,7 @@ let tests = [
|
|||
let tests = [
|
||||
function(x: (a: string, b: string) => void) {
|
||||
let y = x.bind(x, \"foo\");
|
||||
|
||||
y(\"bar\");
|
||||
|
||||
y(123);
|
||||
}
|
||||
];
|
||||
|
@ -191,35 +174,22 @@ function test2(): number { return 0; }
|
|||
function test(a: string, b: number): number {
|
||||
return this.length;
|
||||
}
|
||||
|
||||
test.call(\"\", \"\", 0);
|
||||
|
||||
test.call(0, \"\", 0);
|
||||
|
||||
test.call(\"\", \"\");
|
||||
|
||||
test.call(\"\", \"\", \"\");
|
||||
|
||||
test.call(\"\", 0, 0);
|
||||
|
||||
function f(args) {
|
||||
test.call(\"\", args[0], args[1]);
|
||||
}
|
||||
|
||||
f([ \"\", 0 ]);
|
||||
|
||||
f([ \"\", \"\" ]);
|
||||
|
||||
f([ 0, 0 ]);
|
||||
|
||||
(test.apply.call(test, 0, [ 0, \"foo\" ]): number);
|
||||
|
||||
function test2(): number {
|
||||
return 0;
|
||||
}
|
||||
|
||||
(test2.call(): number);
|
||||
|
||||
(test2.call(\"\"): number);
|
||||
"
|
||||
`;
|
||||
|
@ -322,74 +292,47 @@ var b: Function = function(a: number, b: number): number {
|
|||
};
|
||||
class C {}
|
||||
var c: Function = C;
|
||||
|
||||
function good(x: Function, MyThing: Function): number {
|
||||
var o: Object = x;
|
||||
|
||||
x.foo = 123;
|
||||
|
||||
x[\"foo\"] = 456;
|
||||
|
||||
x();
|
||||
|
||||
<MyThing/>;
|
||||
|
||||
var { ...something } = x;
|
||||
|
||||
Object.assign(x, { hi: \"there\" });
|
||||
|
||||
Object.keys(x);
|
||||
|
||||
return x.bar + x[\"bar\"] + x.lala();
|
||||
}
|
||||
|
||||
function bad(x: Function, y: Object): void {
|
||||
var a: number = x;
|
||||
var b: string = x;
|
||||
var c: Function = y;
|
||||
}
|
||||
|
||||
let tests = [
|
||||
function(y: () => void, z: Function) {
|
||||
function x() {}
|
||||
|
||||
(x.length: void);
|
||||
|
||||
(y.length: void);
|
||||
|
||||
(z.length: void);
|
||||
|
||||
(x.name: void);
|
||||
|
||||
(y.name: void);
|
||||
|
||||
(z.name: void);
|
||||
},
|
||||
function(y: () => void, z: Function) {
|
||||
function x() {}
|
||||
|
||||
x.length = \"foo\";
|
||||
|
||||
y.length = \"foo\";
|
||||
|
||||
z.length = \"foo\";
|
||||
|
||||
x.name = 123;
|
||||
|
||||
y.name = 123;
|
||||
|
||||
z.name = 123;
|
||||
|
||||
(z.foo: number);
|
||||
|
||||
(z.foo: string);
|
||||
}
|
||||
];
|
||||
var d: Function = () => 1;
|
||||
var e = (d.bind(1): Function)();
|
||||
|
||||
(e: number);
|
||||
|
||||
(e: string);
|
||||
"
|
||||
`;
|
||||
|
@ -421,15 +364,12 @@ function rest_t<U, T: Array<U>>(...xs: T): U {
|
|||
function rest_array<T>(...xs: Array<T>): T {
|
||||
return xs[0];
|
||||
}
|
||||
|
||||
function rest_tuple<T>(...xs: [T]): T {
|
||||
return xs[0];
|
||||
}
|
||||
|
||||
function rest_any(...xs: any): any {
|
||||
return xs[0];
|
||||
}
|
||||
|
||||
function rest_t<U, T: Array<U>>(...xs: T): U {
|
||||
return xs[0];
|
||||
}
|
||||
|
|
|
@ -9,7 +9,6 @@ function foo() {
|
|||
function bar(x) {
|
||||
return x;
|
||||
}
|
||||
|
||||
function foo() {
|
||||
return function bound() {
|
||||
return bar(bound);
|
||||
|
|
|
@ -151,18 +151,14 @@ for (var x of examples.delegate_yield_iterable([])) {
|
|||
class GeneratorExamples {
|
||||
*stmt_yield(): Generator<number, void, void> {
|
||||
yield 0;
|
||||
|
||||
yield \"\";
|
||||
}
|
||||
*stmt_next(): Generator<void, void, number> {
|
||||
var a = yield;
|
||||
|
||||
if (a) {
|
||||
(a: number);
|
||||
}
|
||||
|
||||
var b = yield;
|
||||
|
||||
if (b) {
|
||||
(b: string);
|
||||
}
|
||||
|
@ -179,7 +175,6 @@ class GeneratorExamples {
|
|||
}
|
||||
*widen_next() {
|
||||
var x = yield 0;
|
||||
|
||||
if (typeof x === \"number\") {}
|
||||
else if (typeof x === \"boolean\") {}
|
||||
else {
|
||||
|
@ -188,30 +183,25 @@ class GeneratorExamples {
|
|||
}
|
||||
*widen_yield() {
|
||||
yield 0;
|
||||
|
||||
yield \"\";
|
||||
|
||||
yield true;
|
||||
}
|
||||
*delegate_next_generator() {
|
||||
function* inner() {
|
||||
var x: number = yield;
|
||||
}
|
||||
|
||||
yield* inner();
|
||||
}
|
||||
*delegate_yield_generator() {
|
||||
function* inner() {
|
||||
yield \"\";
|
||||
}
|
||||
|
||||
yield* inner();
|
||||
}
|
||||
*delegate_return_generator() {
|
||||
function* inner() {
|
||||
return \"\";
|
||||
}
|
||||
|
||||
var x: number = yield* inner();
|
||||
}
|
||||
*delegate_next_iterable(xs: Array<number>) {
|
||||
|
@ -234,25 +224,18 @@ class GeneratorExamples {
|
|||
}
|
||||
}
|
||||
var examples = new GeneratorExamples();
|
||||
|
||||
for (var x of examples.infer_stmt()) {
|
||||
(x: string);
|
||||
}
|
||||
|
||||
var infer_stmt_next = examples.infer_stmt().next(0).value;
|
||||
|
||||
if (typeof infer_stmt_next === \"undefined\") {}
|
||||
else if (typeof infer_stmt_next === \"number\") {}
|
||||
else {
|
||||
(infer_stmt_next: boolean);
|
||||
}
|
||||
|
||||
examples.widen_next().next(0);
|
||||
|
||||
examples.widen_next().next(\"\");
|
||||
|
||||
examples.widen_next().next(true);
|
||||
|
||||
for (var x of examples.widen_yield()) {
|
||||
if (typeof x === \"number\") {}
|
||||
else if (typeof x === \"boolean\") {}
|
||||
|
@ -260,15 +243,11 @@ for (var x of examples.widen_yield()) {
|
|||
(x: string);
|
||||
}
|
||||
}
|
||||
|
||||
examples.delegate_next_generator().next(\"\");
|
||||
|
||||
for (var x of examples.delegate_yield_generator()) {
|
||||
(x: number);
|
||||
}
|
||||
|
||||
examples.delegate_next_iterable([]).next(\"\");
|
||||
|
||||
for (var x of examples.delegate_yield_iterable([])) {
|
||||
(x: string);
|
||||
}
|
||||
|
@ -309,13 +288,10 @@ class GeneratorExamples<X> {
|
|||
}
|
||||
}
|
||||
var examples = new GeneratorExamples();
|
||||
|
||||
for (var x of examples.infer_stmt()) {
|
||||
(x: string);
|
||||
}
|
||||
|
||||
var infer_stmt_next = examples.infer_stmt().next(0).value;
|
||||
|
||||
if (typeof infer_stmt_next === \"undefined\") {}
|
||||
else if (typeof infer_stmt_next === \"number\") {}
|
||||
else {
|
||||
|
@ -476,73 +452,53 @@ if (multiple_return_result.done) {
|
|||
// error: number|string ~> void
|
||||
function* stmt_yield(): Generator<number, void, void> {
|
||||
yield 0;
|
||||
|
||||
yield \"\";
|
||||
}
|
||||
|
||||
function* stmt_next(): Generator<void, void, number> {
|
||||
var a = yield;
|
||||
|
||||
if (a) {
|
||||
(a: number);
|
||||
}
|
||||
|
||||
var b = yield;
|
||||
|
||||
if (b) {
|
||||
(b: string);
|
||||
}
|
||||
}
|
||||
|
||||
function* stmt_return_ok(): Generator<void, number, void> {
|
||||
return 0;
|
||||
}
|
||||
|
||||
function* stmt_return_err(): Generator<void, number, void> {
|
||||
return \"\";
|
||||
}
|
||||
|
||||
function* infer_stmt() {
|
||||
var x: boolean = yield 0;
|
||||
return \"\";
|
||||
}
|
||||
|
||||
for (var x of infer_stmt()) {
|
||||
(x: string);
|
||||
}
|
||||
|
||||
var infer_stmt_next = infer_stmt().next(0).value;
|
||||
|
||||
if (typeof infer_stmt_next === \"undefined\") {}
|
||||
else if (typeof infer_stmt_next === \"number\") {}
|
||||
else {
|
||||
(infer_stmt_next: boolean);
|
||||
}
|
||||
|
||||
function* widen_next() {
|
||||
var x = yield 0;
|
||||
|
||||
if (typeof x === \"number\") {}
|
||||
else if (typeof x === \"boolean\") {}
|
||||
else {
|
||||
(x: string);
|
||||
}
|
||||
}
|
||||
|
||||
widen_next().next(0);
|
||||
|
||||
widen_next().next(\"\");
|
||||
|
||||
widen_next().next(true);
|
||||
|
||||
function* widen_yield() {
|
||||
yield 0;
|
||||
|
||||
yield \"\";
|
||||
|
||||
yield true;
|
||||
}
|
||||
|
||||
for (var x of widen_yield()) {
|
||||
if (typeof x === \"number\") {}
|
||||
else if (typeof x === \"boolean\") {}
|
||||
|
@ -550,67 +506,50 @@ for (var x of widen_yield()) {
|
|||
(x: string);
|
||||
}
|
||||
}
|
||||
|
||||
function* delegate_next_generator() {
|
||||
function* inner() {
|
||||
var x: number = yield;
|
||||
}
|
||||
|
||||
yield* inner();
|
||||
}
|
||||
|
||||
delegate_next_generator().next(\"\");
|
||||
|
||||
function* delegate_yield_generator() {
|
||||
function* inner() {
|
||||
yield \"\";
|
||||
}
|
||||
|
||||
yield* inner();
|
||||
}
|
||||
|
||||
for (var x of delegate_yield_generator()) {
|
||||
(x: number);
|
||||
}
|
||||
|
||||
function* delegate_return_generator() {
|
||||
function* inner() {
|
||||
return \"\";
|
||||
}
|
||||
|
||||
var x: number = yield* inner();
|
||||
}
|
||||
|
||||
function* delegate_next_iterable(xs: Array<number>) {
|
||||
yield* xs;
|
||||
}
|
||||
|
||||
delegate_next_iterable([]).next(\"\");
|
||||
|
||||
function* delegate_yield_iterable(xs: Array<number>) {
|
||||
yield* xs;
|
||||
}
|
||||
|
||||
for (var x of delegate_yield_iterable([])) {
|
||||
(x: string);
|
||||
}
|
||||
|
||||
function* delegate_return_iterable(xs: Array<number>) {
|
||||
var x: void = yield* xs;
|
||||
}
|
||||
|
||||
function* generic_yield<Y>(y: Y): Generator<Y, void, void> {
|
||||
yield y;
|
||||
}
|
||||
|
||||
function* generic_return<R>(r: R): Generator<void, R, void> {
|
||||
return r;
|
||||
}
|
||||
|
||||
function* generic_next<N>(): Generator<void, N, N> {
|
||||
return yield undefined;
|
||||
}
|
||||
|
||||
function* multiple_return(b) {
|
||||
if (b) {
|
||||
return 0;
|
||||
|
@ -618,9 +557,7 @@ function* multiple_return(b) {
|
|||
return \"foo\";
|
||||
}
|
||||
}
|
||||
|
||||
let multiple_return_result = multiple_return().next();
|
||||
|
||||
if (multiple_return_result.done) {
|
||||
(multiple_return_result.value: void);
|
||||
}
|
||||
|
@ -658,10 +595,8 @@ if (refuse_return_result.done) {
|
|||
// error: number | void ~> string
|
||||
function test1(gen: Generator<void, string, void>) {
|
||||
var ret = gen.return(0);
|
||||
|
||||
(ret.value: void);
|
||||
}
|
||||
|
||||
function* refuse_return() {
|
||||
try {
|
||||
yield 1;
|
||||
|
@ -669,10 +604,8 @@ function* refuse_return() {
|
|||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
var refuse_return_gen = refuse_return();
|
||||
var refuse_return_result = refuse_return_gen.return(\"string\");
|
||||
|
||||
if (refuse_return_result.done) {
|
||||
(refuse_return_result.value: string);
|
||||
}
|
||||
|
@ -715,25 +648,19 @@ function* catch_return() {
|
|||
return e;
|
||||
}
|
||||
}
|
||||
|
||||
var catch_return_value = catch_return().throw(\"\").value;
|
||||
|
||||
if (catch_return_value !== undefined) {
|
||||
(catch_return_value: string);
|
||||
}
|
||||
|
||||
function* yield_return() {
|
||||
try {
|
||||
yield 0;
|
||||
|
||||
return;
|
||||
} catch (e) {
|
||||
yield e;
|
||||
}
|
||||
}
|
||||
|
||||
var yield_return_value = yield_return().throw(\"\").value;
|
||||
|
||||
if (yield_return_value !== undefined) {
|
||||
(yield_return_value: string);
|
||||
}
|
||||
|
|
|
@ -63,9 +63,7 @@ class D<T> {
|
|||
x: T;
|
||||
m<S>(z: S, u: T, v): S {
|
||||
this.x = u;
|
||||
|
||||
v.u = u;
|
||||
|
||||
return z;
|
||||
}
|
||||
}
|
||||
|
@ -77,7 +75,6 @@ var n: number = o.u;
|
|||
class E<X> extends C<X> {
|
||||
set(x: X): X {
|
||||
this.x = x;
|
||||
|
||||
return this.get();
|
||||
}
|
||||
}
|
||||
|
@ -92,9 +89,7 @@ class H<Z> extends G<Array<Z>> {
|
|||
}
|
||||
}
|
||||
var h1 = new H();
|
||||
|
||||
h1.foo([ \"...\" ]);
|
||||
|
||||
var h2: F<Array<Array<Array<number>>>> = h1;
|
||||
var obj: Object<string, string> = {};
|
||||
var fn: Function<string> = function() {
|
||||
|
|
|
@ -38,7 +38,6 @@ var id = geolocation.watchPosition(
|
|||
}
|
||||
}
|
||||
);
|
||||
|
||||
geolocation.clearWatch(id);
|
||||
"
|
||||
`;
|
||||
|
|
|
@ -19,15 +19,11 @@ lib.bar();
|
|||
// t123456
|
||||
// D123456
|
||||
var lib = require(\"./library\");
|
||||
|
||||
function add(a: number, b: number): number {
|
||||
return a + b;
|
||||
}
|
||||
|
||||
var re = /^keynote (talk){2} (lightning){3,5} (talk){2} closing partytime!!!/;
|
||||
|
||||
add(lib.iTakeAString(42), 7);
|
||||
|
||||
lib.bar();
|
||||
"
|
||||
`;
|
||||
|
@ -47,17 +43,11 @@ things;
|
|||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// @flow
|
||||
import thing from \"./helpers/exports_default.js\";
|
||||
|
||||
thing;
|
||||
|
||||
import {foo, bar as baz} from \"./helpers/exports_named.js\";
|
||||
|
||||
foo;
|
||||
|
||||
baz;
|
||||
|
||||
import * as things from \"./helpers/exports_named.js\";
|
||||
|
||||
things;
|
||||
"
|
||||
`;
|
||||
|
|
|
@ -6,7 +6,6 @@ module.exports = {ParentFoo};
|
|||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// @flow
|
||||
var ParentFoo = { foo: \"bar\" };
|
||||
|
||||
module.exports = { ParentFoo };
|
||||
"
|
||||
`;
|
||||
|
@ -46,25 +45,15 @@ import type {Foo} from \'./types\';
|
|||
// Follows non-destructured property access of \`require(\'Parent\')\`
|
||||
var Parent = require(\"./Parent\");
|
||||
let ParentFoo;
|
||||
|
||||
({ ParentFoo } = Parent);
|
||||
|
||||
ParentFoo;
|
||||
|
||||
let ParentFoo2;
|
||||
|
||||
ParentFoo2 = Parent;
|
||||
|
||||
ParentFoo2;
|
||||
|
||||
let ParentFoo3 = Parent;
|
||||
|
||||
ParentFoo3;
|
||||
|
||||
let foo = require(\"./Parent\").ParentFoo.foo;
|
||||
|
||||
foo;
|
||||
|
||||
import type {Foo} from \"./types\";
|
||||
"
|
||||
`;
|
||||
|
@ -116,9 +105,7 @@ class C extends React.Component {
|
|||
props: { x: string };
|
||||
}
|
||||
let msg = \"hello\";
|
||||
|
||||
<C x={msg}/>;
|
||||
|
||||
<div id={msg}/>;
|
||||
"
|
||||
`;
|
||||
|
|
|
@ -28,7 +28,6 @@ require(\'b\');
|
|||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// @flow
|
||||
require(\"./a.js\");
|
||||
|
||||
require(\"b\");
|
||||
"
|
||||
`;
|
||||
|
|
|
@ -113,18 +113,12 @@ var testGetterNoError1: number = foo.goodGetterNoAnnotation;
|
|||
var testGetterNoError2: number = foo.goodGetterWithAnnotation;
|
||||
var testGetterWithError1: string = foo.goodGetterNoAnnotation;
|
||||
var testGetterWithError2: string = foo.goodGetterWithAnnotation;
|
||||
|
||||
foo.goodSetterNoAnnotation = 123;
|
||||
|
||||
foo.goodSetterWithAnnotation = 123;
|
||||
|
||||
foo.goodSetterNoAnnotation = \"hello\";
|
||||
|
||||
foo.goodSetterWithAnnotation = \"hello\";
|
||||
|
||||
var testSubtypingGetterAndSetter: number = foo.propWithSubtypingGetterAndSetter;
|
||||
var testPropOverridenWithGetter: number = foo.propOverriddenWithGetter;
|
||||
|
||||
foo.propOverriddenWithSetter = 123;
|
||||
"
|
||||
`;
|
||||
|
@ -252,19 +246,12 @@ var testGetterNoError1: number = obj.goodGetterNoAnnotation;
|
|||
var testGetterNoError2: number = obj.goodGetterWithAnnotation;
|
||||
var testGetterWithError1: string = obj.goodGetterNoAnnotation;
|
||||
var testGetterWithError2: string = obj.goodGetterWithAnnotation;
|
||||
|
||||
obj.goodSetterNoAnnotation = 123;
|
||||
|
||||
obj.goodSetterWithAnnotation = 123;
|
||||
|
||||
obj.goodSetterNoAnnotation = \"hello\";
|
||||
|
||||
obj.goodSetterWithAnnotation = \"hello\";
|
||||
|
||||
var testSubtypingGetterAndSetter: number = obj.propWithSubtypingGetterAndSetter;
|
||||
|
||||
obj.exampleOfOrderOfGetterAndSetter = new C();
|
||||
|
||||
var testExampleOrOrderOfGetterAndSetterReordered: number = obj.exampleOfOrderOfGetterAndSetterReordered;
|
||||
"
|
||||
`;
|
||||
|
@ -405,52 +392,42 @@ class Base {
|
|||
this.x = value;
|
||||
}
|
||||
}
|
||||
|
||||
(class extends Base {
|
||||
get x(): B {
|
||||
return b;
|
||||
}
|
||||
});
|
||||
|
||||
(class extends Base {
|
||||
set x(value: B): void {}
|
||||
});
|
||||
|
||||
(class extends Base {
|
||||
get x(): C {
|
||||
return c;
|
||||
}
|
||||
set x(value: A): void {}
|
||||
});
|
||||
|
||||
(class extends Base {
|
||||
set pos(value: B): void {}
|
||||
});
|
||||
|
||||
(class extends Base {
|
||||
get pos(): C {
|
||||
return c;
|
||||
}
|
||||
});
|
||||
|
||||
(class extends Base {
|
||||
get neg(): B {
|
||||
return b;
|
||||
}
|
||||
});
|
||||
|
||||
(class extends Base {
|
||||
set neg(value: A): void {}
|
||||
});
|
||||
|
||||
(class extends Base {
|
||||
get: C;
|
||||
});
|
||||
|
||||
(class extends Base {
|
||||
set: A;
|
||||
});
|
||||
|
||||
(class extends Base {
|
||||
getset: B;
|
||||
});
|
||||
|
|
|
@ -22,11 +22,9 @@ module.exports = foo;
|
|||
\'Required module not found\'.
|
||||
*/
|
||||
var _ = require(\"underscore\");
|
||||
|
||||
function foo(): string {
|
||||
return _.foo();
|
||||
}
|
||||
|
||||
module.exports = foo;
|
||||
"
|
||||
`;
|
||||
|
|
|
@ -21,7 +21,6 @@ class B extends A {
|
|||
}
|
||||
class C extends A {}
|
||||
var a: A = new B();
|
||||
|
||||
a.foo = function(): C {
|
||||
return new C();
|
||||
};
|
||||
|
|
|
@ -23,7 +23,6 @@ class ClassFoo3 {
|
|||
return new ClassFoo3();
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ClassFoo3;
|
||||
"
|
||||
`;
|
||||
|
@ -61,21 +60,15 @@ class ClassFoo4 {
|
|||
}
|
||||
}
|
||||
class ClassFoo5 {}
|
||||
|
||||
function givesAFoo4(): ClassFoo4 {
|
||||
return new ClassFoo4();
|
||||
}
|
||||
|
||||
function givesAFoo5(): ClassFoo5 {
|
||||
return new ClassFoo5();
|
||||
}
|
||||
|
||||
exports.ClassFoo4 = ClassFoo4;
|
||||
|
||||
exports.ClassFoo5 = ClassFoo5;
|
||||
|
||||
exports.foo4Inst = new ClassFoo4();
|
||||
|
||||
exports.foo5Inst = new ClassFoo5();
|
||||
"
|
||||
`;
|
||||
|
@ -301,29 +294,21 @@ import type ClassFoo1 from \"./ExportDefault_Class\";
|
|||
import {foo1Inst} from \"./ExportDefault_Class\";
|
||||
var a1: ClassFoo1 = foo1Inst;
|
||||
var a2: number = foo1Inst;
|
||||
|
||||
new ClassFoo1();
|
||||
|
||||
import type {ClassFoo2} from \"./ExportNamed_Class\";
|
||||
import {foo2Inst} from \"./ExportNamed_Class\";
|
||||
var b1: ClassFoo2 = foo2Inst;
|
||||
var b2: number = foo2Inst;
|
||||
|
||||
new ClassFoo2();
|
||||
|
||||
import type ClassFoo3T from \"./ExportCJSDefault_Class\";
|
||||
import ClassFoo3 from \"./ExportCJSDefault_Class\";
|
||||
var c1: ClassFoo3T = new ClassFoo3();
|
||||
|
||||
new ClassFoo3T();
|
||||
|
||||
import type {ClassFoo4, ClassFoo5} from \"./ExportCJSNamed_Class\";
|
||||
import {foo4Inst, foo5Inst} from \"./ExportCJSNamed_Class\";
|
||||
var d1: ClassFoo4 = foo4Inst;
|
||||
var d2: number = foo4Inst;
|
||||
|
||||
new ClassFoo4();
|
||||
|
||||
var d3: typeof ClassFoo5 = foo5Inst;
|
||||
import type {AliasFoo3} from \"./ExportNamed_Alias\";
|
||||
import {givesAFoo3Obj} from \"./ExportNamed_Alias\";
|
||||
|
@ -332,7 +317,6 @@ var e2: number = givesAFoo3Obj();
|
|||
var e3: typeof AliasFoo3 = givesAFoo3Obj();
|
||||
import type {numValue} from \"./ExportsANumber\";
|
||||
import type ClassFoo6 from \"./issue-359\";
|
||||
|
||||
function foo() {
|
||||
ClassFoo6;
|
||||
}
|
||||
|
|
|
@ -23,7 +23,6 @@ class ClassFoo3 {
|
|||
return new ClassFoo3();
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ClassFoo3;
|
||||
"
|
||||
`;
|
||||
|
@ -51,7 +50,6 @@ exports.ClassFoo4 = ClassFoo4;
|
|||
* @flow
|
||||
*/
|
||||
class ClassFoo4 {}
|
||||
|
||||
exports.ClassFoo4 = ClassFoo4;
|
||||
"
|
||||
`;
|
||||
|
@ -332,16 +330,12 @@ import typeof ClassFoo1T from \"./ExportDefault_Class\";
|
|||
import ClassFoo1 from \"./ExportDefault_Class\";
|
||||
var a1: ClassFoo1T = ClassFoo1;
|
||||
var a2: ClassFoo1T = new ClassFoo1();
|
||||
|
||||
new ClassFoo1T();
|
||||
|
||||
import typeof {ClassFoo2 as ClassFoo2T} from \"./ExportNamed_Class\";
|
||||
import {ClassFoo2} from \"./ExportNamed_Class\";
|
||||
var b1: ClassFoo2T = ClassFoo2;
|
||||
var b2: ClassFoo2T = new ClassFoo2();
|
||||
|
||||
new ClassFoo2T();
|
||||
|
||||
import typeof ClassFoo3T from \"./ExportCJSDefault_Class\";
|
||||
import ClassFoo3 from \"./ExportCJSDefault_Class\";
|
||||
var c1: ClassFoo3T = ClassFoo3;
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue