Keep blank lines from original source

master
James Long 2017-01-09 09:44:39 -05:00
parent 78a9da2ff4
commit bcd44b4368
256 changed files with 24 additions and 5601 deletions

View File

@ -49,6 +49,7 @@ module.exports = {
}); });
} }
opts.originalText = text;
ast.tokens = []; ast.tokens = [];
const printer = new Printer(opts); const printer = new Printer(opts);

View File

@ -1600,7 +1600,6 @@ function printStatementSequence(path, options, print) {
let inClassBody = namedTypes.ClassBody && let inClassBody = namedTypes.ClassBody &&
namedTypes.ClassBody.check(path.getParentNode()); namedTypes.ClassBody.check(path.getParentNode());
let printed = []; let printed = [];
let prevAddSpacing = false;
path.map(function(stmtPath, i) { path.map(function(stmtPath, i) {
var stmt = stmtPath.getValue(); var stmt = stmtPath.getValue();
@ -1617,23 +1616,16 @@ function printStatementSequence(path, options, print) {
return; return;
} }
const addSpacing = shouldAddSpacing(stmt);
const stmtPrinted = print(stmtPath); const stmtPrinted = print(stmtPath);
const parts = []; const parts = [];
if (!prevAddSpacing && addSpacing && !isFirstStatement(stmtPath)) {
parts.push(hardline);
}
parts.push(stmtPrinted); parts.push(stmtPrinted);
if (addSpacing && !isLastStatement(stmtPath)) { if (shouldAddSpacing(stmt, options) && !isLastStatement(stmtPath)) {
parts.push(hardline); parts.push(hardline);
} }
printed.push(concat(parts)); printed.push(concat(parts));
prevAddSpacing = addSpacing;
}); });
return join(hardline, printed); return join(hardline, printed);
@ -2073,12 +2065,28 @@ function nodeStr(str, options) {
} }
} }
function shouldAddSpacing(node) { function shouldAddSpacing(node, options) {
return node.type === "IfStatement" || node.type === "ForStatement" || const text = options.originalText;
node.type === "ForInStatement" || const length = text.length;
node.type === "ForOfStatement" || let cursor = node.end + 1;
node.type === "ExpressionStatement" || // Look forward and see if there is a blank line after this code by
node.type === "FunctionDeclaration"; // 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) { function isFirstStatement(path) {

File diff suppressed because it is too large Load Diff

View File

@ -12,7 +12,6 @@ function foo() {
break; break;
} }
} }
function bar() { function bar() {
L: L:
do { do {
@ -31,13 +30,10 @@ function foo() {
} }
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function bar(x: number) {} function bar(x: number) {}
function foo() { function foo() {
var x = null; var x = null;
if (x == null) if (x == null)
return; return;
bar(x); bar(x);
} }
" "

View File

@ -73,7 +73,6 @@ function barfoo(n : number | null | void) : ?number { return n; }
function foo(str: string, i: number): string { function foo(str: string, i: number): string {
return str; return str;
} }
var bar: (str: number, i: number) => string = foo; var bar: (str: number, i: number) => string = foo;
var qux = function(str: string, i: number): number { var qux = function(str: string, i: number): number {
return foo(str, i); 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; var array_of_tuple_parens: [number, string][] = array_of_tuple;
type ObjType = { \"bar-foo\": string, \"foo-bar\": number }; type ObjType = { \"bar-foo\": string, \"foo-bar\": number };
var test_obj: ObjType = { \"bar-foo\": \"23\" }; var test_obj: ObjType = { \"bar-foo\": \"23\" };
function param_anno(n: number): void { function param_anno(n: number): void {
n = \"hey\"; n = \"hey\";
} }
function param_anno2( function param_anno2(
batchRequests: Array<{ method: string, path: string, params: ?Object }> batchRequests: Array<{ method: string, path: string, params: ?Object }>
): void { ): void {
@ -110,14 +107,11 @@ function param_anno2(
}; };
}); });
} }
var toz: null = 3; var toz: null = 3;
var zer: null = null; var zer: null = null;
function foobar(n: ?number): number | null | void { function foobar(n: ?number): number | null | void {
return n; return n;
} }
function barfoo(n: number | null | void): ?number { function barfoo(n: number | null | void): ?number {
return n; return n;
} }
@ -146,20 +140,15 @@ function foo() {
// ok (no confusion across scopes) // ok (no confusion across scopes)
// looked up above // looked up above
let myClassInstance: MyClass = null; let myClassInstance: MyClass = null;
function bar(): MyClass { function bar(): MyClass {
return null; return null;
} }
class MyClass {} class MyClass {}
function foo() { function foo() {
let myClassInstance: MyClass = mk(); let myClassInstance: MyClass = mk();
function mk() { function mk() {
return new MyClass(); return new MyClass();
} }
class MyClass {} class MyClass {}
} }
" "
@ -171,7 +160,6 @@ exports[`test issue-530.js 1`] = `
module.exports = foo; module.exports = foo;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function foo(...args: any) {} function foo(...args: any) {}
module.exports = foo; module.exports = foo;
" "
`; `;
@ -212,11 +200,9 @@ function bar(y: MyObj): string {
* leading to an error. * leading to an error.
*/ */
type MyObj = Object; type MyObj = Object;
function foo(x: { [key: string]: mixed }) { function foo(x: { [key: string]: mixed }) {
bar(x); bar(x);
} }
function bar(y: MyObj): string { function bar(y: MyObj): string {
return y.foo; return y.foo;
} }
@ -228,7 +214,6 @@ exports[`test other.js 1`] = `
module.exports = (C: any); module.exports = (C: any);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
class C {} class C {}
module.exports = (C: any); module.exports = (C: any);
" "
`; `;
@ -266,7 +251,6 @@ declare class Map<K, V> {
insertWith(fn: Merge<V>, k: K, v: V): 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; declare function foldr<A, B>(fn: (a: A, b: B) => B, b: B, as: A[]): B;
function insertMany<K, V>( function insertMany<K, V>(
merge: Merge<V>, merge: Merge<V>,
vs: [K, 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> { function f([ k, v ]: [K, V], m: Map<K, V>): Map<K, V> {
return m.insertWith(merge, k, v); return m.insertWith(merge, k, v);
} }
return foldr(f, m, vs); return foldr(f, m, vs);
} }
class Foo<A> { class Foo<A> {
bar<B>() { bar<B>() {
return function<C>(a: A, b: B, c: C): void { return function<C>(a: A, b: B, c: C): void {
@ -294,7 +276,6 @@ exports[`test test.js 1`] = `
((0: C): string); ((0: C): string);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
var C = require(\"./other\"); var C = require(\"./other\");
((0: C): string); ((0: C): string);
" "
`; `;

View File

@ -13,15 +13,12 @@ var z:string = qux(0);
function foo(x: any): any { function foo(x: any): any {
return x; return x;
} }
function bar(x: any): mixed { function bar(x: any): mixed {
return x; return x;
} }
function qux(x: mixed): any { function qux(x: mixed): any {
return x; return x;
} }
var x: string = foo(0); var x: string = foo(0);
var y: string = bar(0); var y: string = bar(0);
var z: string = qux(0); var z: string = qux(0);
@ -71,19 +68,15 @@ var w:string = baz(0);
function foo(x: $FlowFixMe): $FlowFixMe { function foo(x: $FlowFixMe): $FlowFixMe {
return x; return x;
} }
function bar(x: $FlowFixMe): mixed { function bar(x: $FlowFixMe): mixed {
return x; return x;
} }
function qux(x: $FlowFixMe<number>): $FlowFixMe<number> { function qux(x: $FlowFixMe<number>): $FlowFixMe<number> {
return x; return x;
} }
function baz(x: $FlowFixMe<nnumber>): $FlowFixMe<number> { function baz(x: $FlowFixMe<nnumber>): $FlowFixMe<number> {
return x; return x;
} }
var x: string = foo(0); var x: string = foo(0);
var y: string = bar(0); var y: string = bar(0);
var z: string = qux(0); var z: string = qux(0);
@ -124,19 +117,15 @@ var w:string = baz(0);
function foo(x: $FlowIssue): $FlowIssue { function foo(x: $FlowIssue): $FlowIssue {
return x; return x;
} }
function bar(x: $FlowIssue): mixed { function bar(x: $FlowIssue): mixed {
return x; return x;
} }
function qux(x: $FlowIssue<number>): $FlowIssue<number> { function qux(x: $FlowIssue<number>): $FlowIssue<number> {
return x; return x;
} }
function baz(x: $FlowIssue<nnumber>): $FlowIssue<number> { function baz(x: $FlowIssue<nnumber>): $FlowIssue<number> {
return x; return x;
} }
var x: string = foo(0); var x: string = foo(0);
var y: string = bar(0); var y: string = bar(0);
var z: string = qux(0); var z: string = qux(0);
@ -187,22 +176,17 @@ declare class C {
bar(n1: number, n2: number): number, bar(n1: number, n2: number): number,
bar(s1: string, s2: string): string bar(s1: string, s2: string): string
} }
function foo(c: C, x: any): string { function foo(c: C, x: any): string {
let y = x.y; let y = x.y;
return c.bar(0, y); return c.bar(0, y);
} }
var any_fun1 = require(\"./nonflowfile\"); var any_fun1 = require(\"./nonflowfile\");
function bar1(x: mixed) { function bar1(x: mixed) {
if (any_fun1(x)) { if (any_fun1(x)) {
(x: boolean); (x: boolean);
} }
} }
var any_fun2 = require(\"./anyexportflowfile\"); var any_fun2 = require(\"./anyexportflowfile\");
function bar2(x: mixed) { function bar2(x: mixed) {
if (any_fun2(x)) { if (any_fun2(x)) {
(x: boolean); (x: boolean);
@ -232,7 +216,6 @@ function foo(o: ?AsyncRequest) {
* annotation - without it, the body of the if will be unreachable * annotation - without it, the body of the if will be unreachable
*/ */
type AsyncRequest = any; type AsyncRequest = any;
function foo(o: ?AsyncRequest) { function foo(o: ?AsyncRequest) {
if (o) { if (o) {
var n: number = o; var n: number = o;

View File

@ -133,113 +133,71 @@ let tests = [
// error, string ~> empty // error, string ~> empty
// error, string ~> empty // error, string ~> empty
function num(x: number) {} function num(x: number) {}
function str(x: string) {} function str(x: string) {}
function foo() { function foo() {
var x = 0; var x = 0;
var y = \"...\"; var y = \"...\";
var z = {}; var z = {};
num(x + x); num(x + x);
num(x + y); num(x + y);
str(x + y); str(x + y);
str(x + x); str(x + x);
str(z + y); str(z + y);
} }
function bar0(x: ?number, y: number) { function bar0(x: ?number, y: number) {
num(x + y); num(x + y);
} }
function bar1(x: number, y: ?number) { function bar1(x: number, y: ?number) {
num(x + y); num(x + y);
} }
function bar2(x?: number, y: number) { function bar2(x?: number, y: number) {
num(x + y); num(x + y);
} }
function bar3(x: number, y?: number) { function bar3(x: number, y?: number) {
num(x + y); num(x + y);
} }
function bar4(x?: ?number, y: number) { function bar4(x?: ?number, y: number) {
num(x + y); num(x + y);
} }
function bar5(x: number, y?: ?number) { function bar5(x: number, y?: ?number) {
num(x + y); num(x + y);
} }
num(null + null); num(null + null);
num(undefined + undefined); num(undefined + undefined);
num(null + 1); num(null + 1);
num(1 + null); num(1 + null);
num(undefined + 1); num(undefined + 1);
num(1 + undefined); num(1 + undefined);
num(null + true); num(null + true);
num(true + null); num(true + null);
num(undefined + true); num(undefined + true);
num(true + undefined); num(true + undefined);
str(\"foo\" + true); str(\"foo\" + true);
str(true + \"foo\"); str(true + \"foo\");
str(\"foo\" + null); str(\"foo\" + null);
str(null + \"foo\"); str(null + \"foo\");
str(\"foo\" + undefined); str(\"foo\" + undefined);
str(undefined + \"foo\"); str(undefined + \"foo\");
let tests = [ let tests = [
function(x: mixed, y: mixed) { function(x: mixed, y: mixed) {
x + y; x + y;
x + 0; x + 0;
0 + x; 0 + x;
x + \"\"; x + \"\";
\"\" + x; \"\" + x;
x + {}; x + {};
({}) + x; ({}) + x;
}, },
function() { function() {
(1 + {}: number); (1 + {}: number);
({} + 1: number); ({} + 1: number);
(\"1\" + {}: string); (\"1\" + {}: string);
({} + \"1\": string); ({} + \"1\": string);
}, },
function(x: any, y: number, z: string) { function(x: any, y: number, z: string) {
(x + y: string); (x + y: string);
(y + x: string); (y + x: string);
(x + z: empty); (x + z: empty);
(z + x: empty); (z + x: empty);
} }
]; ];
@ -262,17 +220,11 @@ y **= 2; // error
/* @flow */ /* @flow */
// error // error
let x: number = 2 ** 3; let x: number = 2 ** 3;
x **= 4; x **= 4;
let y: string = \"123\"; let y: string = \"123\";
y **= 2; y **= 2;
1 + 2 ** 3 + 4; 1 + 2 ** 3 + 4;
2 ** 2; 2 ** 2;
(-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 { function f<A>(a: A): A {
return a + a; return a + a;
} }
function f<A, B>(a: A, b: B): A { function f<A, B>(a: A, b: B): A {
return a + b; return a + b;
} }
function f<A, B>(a: A, b: B): A { function f<A, B>(a: A, b: B): A {
return b + a; return b + a;
} }
function f<A, B>(a: A, b: B): B { function f<A, B>(a: A, b: B): B {
return a + b; return a + b;
} }
function f<A, B>(a: A, b: B): B { function f<A, B>(a: A, b: B): B {
return b + a; return b + a;
} }
@ -331,17 +279,11 @@ y *= 2; // error
/* @flow */ /* @flow */
// error // error
function num(x: number) {} function num(x: number) {}
num(null * 1); num(null * 1);
num(1 * null); num(1 * null);
let x: number = 2 * 3; let x: number = 2 * 3;
x *= 4; x *= 4;
let y: string = \"123\"; let y: string = \"123\";
y *= 2; y *= 2;
" "
`; `;
@ -393,47 +335,27 @@ let tests = [
// error // error
// error // error
1 < 2; 1 < 2;
1 < \"foo\"; 1 < \"foo\";
\"foo\" < 1; \"foo\" < 1;
\"foo\" < \"bar\"; \"foo\" < \"bar\";
1 < { foo: 1 }; 1 < { foo: 1 };
({ foo: 1 }) < 1; ({ foo: 1 }) < 1;
({ foo: 1 }) < { foo: 1 }; ({ foo: 1 }) < { foo: 1 };
\"foo\" < { foo: 1 }; \"foo\" < { foo: 1 };
({ foo: 1 }) < \"foo\"; ({ foo: 1 }) < \"foo\";
var x = (null: ?number); var x = (null: ?number);
1 < x; 1 < x;
x < 1; x < 1;
null < null; null < null;
undefined < null; undefined < null;
null < undefined; null < undefined;
undefined < undefined; undefined < undefined;
NaN < 1; NaN < 1;
1 < NaN; 1 < NaN;
NaN < NaN; NaN < NaN;
let tests = [ let tests = [
function(x: any, y: number, z: string) { function(x: any, y: number, z: string) {
x > y; x > y;
x > z; x > z;
} }
]; ];

View File

@ -13,7 +13,6 @@ function filterOutSmall (arr: Array<?number>): Array<?number> {
function filterOutVoids<T>(arr: Array<?T>): Array<T> { function filterOutVoids<T>(arr: Array<?T>): Array<T> {
return arr.filter(Boolean); return arr.filter(Boolean);
} }
function filterOutSmall(arr: Array<?number>): Array<?number> { function filterOutSmall(arr: Array<?number>): Array<?number> {
return arr.filter(num => num && num > 10); return arr.filter(num => num && num > 10);
} }
@ -47,9 +46,7 @@ function filterItems(items: Array<string | number>): Array<string | number> {
} }
}).filter(Boolean); }).filter(Boolean);
} }
const filteredItems = filterItems([ \"foo\", \"b\", 1, 2 ]); const filteredItems = filterItems([ \"foo\", \"b\", 1, 2 ]);
console.log(filteredItems); console.log(filteredItems);
" "
`; `;

View File

@ -11,11 +11,8 @@ var y: Array<string> = [\'3\', ...x];
var A = [ 1, 2, 3 ]; var A = [ 1, 2, 3 ];
var B = [ ...A ]; var B = [ ...A ];
var C = [ 1, 2, 3 ]; var C = [ 1, 2, 3 ];
B.sort((a, b) => a - b); B.sort((a, b) => a - b);
C.sort((a, b) => a - b); C.sort((a, b) => a - b);
var x: Array<string> = [ \"1\", \"2\" ]; var x: Array<string> = [ \"1\", \"2\" ];
var y: Array<string> = [ \"3\", ...x ]; var y: Array<string> = [ \"3\", ...x ];
" "

View File

@ -67,11 +67,9 @@ function from_test() {
// error, string ~> number // error, string ~> number
// error, string ~> number // error, string ~> number
function foo(x: string) {} function foo(x: string) {}
var a = [ 0 ]; var a = [ 0 ];
var b = a.map(function(x) { var b = a.map(function(x) {
foo(x); foo(x);
return \"\" + x; return \"\" + x;
}); });
var c: number = a[0]; 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 l: Array<number> = h.concat(1, 2, 3);
var m: Array<number | string> = h.concat(\"a\", \"b\", \"c\"); var m: Array<number | string> = h.concat(\"a\", \"b\", \"c\");
var n: Array<number> = h.concat(\"a\", \"b\", \"c\"); var n: Array<number> = h.concat(\"a\", \"b\", \"c\");
function reduce_test() { function reduce_test() {
[ 0, 1, 2, 3, 4 ].reduce(function(previousValue, currentValue, index, array) { [ 0, 1, 2, 3, 4 ].reduce(function(previousValue, currentValue, index, array) {
return previousValue + currentValue + array[index]; return previousValue + currentValue + array[index];
}); });
[ 0, 1, 2, 3, 4 ].reduce( [ 0, 1, 2, 3, 4 ].reduce(
function(previousValue, currentValue, index, array) { function(previousValue, currentValue, index, array) {
return previousValue + currentValue + array[index]; return previousValue + currentValue + array[index];
}, },
10 10
); );
var total = [ 0, 1, 2, 3 ].reduce(function(a, b) { var total = [ 0, 1, 2, 3 ].reduce(function(a, b) {
return a + b; return a + b;
}); });
var flattened = [ [ 0, 1 ], [ 2, 3 ], [ 4, 5 ] ].reduce(function(a, b) { var flattened = [ [ 0, 1 ], [ 2, 3 ], [ 4, 5 ] ].reduce(function(a, b) {
return a.concat(b); return a.concat(b);
}); });
[ \"\" ].reduce((acc, str) => acc * str.length); [ \"\" ].reduce((acc, str) => acc * str.length);
[ \"\" ].reduceRight((acc, str) => acc * str.length); [ \"\" ].reduceRight((acc, str) => acc * str.length);
} }
function from_test() { function from_test() {
var a: Array<string> = Array.from([ 1, 2, 3 ], function(val, index) { var a: Array<string> = Array.from([ 1, 2, 3 ], function(val, index) {
return index % 2 ? \"foo\" : String(val); return index % 2 ? \"foo\" : String(val);

View File

@ -43,19 +43,12 @@ module.exports = \"arrays\";
// for literals, composite element type is union of individuals // for literals, composite element type is union of individuals
// note: test both tuple and non-tuple inferred literals // note: test both tuple and non-tuple inferred literals
function foo(x: string) {} function foo(x: string) {}
var a = []; var a = [];
a[0] = 1; a[0] = 1;
a[1] = \"...\"; a[1] = \"...\";
foo(a[1]); foo(a[1]);
var y; var y;
a.forEach(x => y = x); a.forEach(x => y = x);
var alittle: Array<?number> = [ 0, 1, 2, 3, null ]; var alittle: Array<?number> = [ 0, 1, 2, 3, null ];
var abig: Array<?number> = [ 0, 1, 2, 3, 4, 5, 6, 8, null ]; var abig: Array<?number> = [ 0, 1, 2, 3, 4, 5, 6, 8, null ];
var abig2: Array<{ x: number, y: number }> = [ 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: 1 },
{ x: 0, y: 0, c: \"hey\" } { x: 0, y: 0, c: \"hey\" }
]; ];
module.exports = \"arrays\"; module.exports = \"arrays\";
" "
`; `;
@ -96,9 +88,7 @@ arr[day] = 0;
// error: number ~> string // error: number ~> string
var arr = []; var arr = [];
var day = new Date(); var day = new Date();
arr[day] = 0; arr[day] = 0;
(arr[day]: string); (arr[day]: string);
" "
`; `;

View File

@ -19,9 +19,7 @@ var ident = <T>(x: T): T => x;
var add = (x: number, y: number): number => x + y; var add = (x: number, y: number): number => x + y;
var bad = (x: number): string => x; var bad = (x: number): string => x;
var ident = <T>(x: T): T => x; var ident = <T>(x: T): T => x;
(ident(1): number); (ident(1): number);
(ident(\"hi\"): number); (ident(\"hi\"): number);
" "
`; `;
@ -44,9 +42,7 @@ function selectBestEffortImageForWidth(
images: Array<Image> images: Array<Image>
): Image { ): Image {
var maxPixelWidth = maxWidth; var maxPixelWidth = maxWidth;
images = images.sort((a, b) => a.width - b.width + \"\"); images = images.sort((a, b) => a.width - b.width + \"\");
return images.find(image => image.width >= maxPixelWidth) || return images.find(image => image.width >= maxPixelWidth) ||
images[images.length - 1]; images[images.length - 1];
} }

View File

@ -71,25 +71,20 @@ var objf : () => Promise<number> = obj.f;
async function f0(): Promise<number> { async function f0(): Promise<number> {
return 1; return 1;
} }
async function f1(): Promise<boolean> { async function f1(): Promise<boolean> {
return 1; return 1;
} }
async function f2(p: Promise<number>): Promise<number> { async function f2(p: Promise<number>): Promise<number> {
var x: number = await p; var x: number = await p;
var y: number = await 1; var y: number = await 1;
return x + y; return x + y;
} }
async function f3(p: Promise<number>): Promise<number> { async function f3(p: Promise<number>): Promise<number> {
return await p; return await p;
} }
async function f4(p: Promise<number>): Promise<boolean> { async function f4(p: Promise<number>): Promise<boolean> {
return await p; return await p;
} }
var f5: () => Promise<number> = async () => await 1; var f5: () => Promise<number> = async () => await 1;
class C { class C {
async m() { async m() {
@ -134,7 +129,6 @@ class C {}
var P: Promise<Class<C>> = new Promise(function(resolve, reject) { var P: Promise<Class<C>> = new Promise(function(resolve, reject) {
resolve(C); resolve(C);
}); });
async function foo() { async function foo() {
class Bar extends (await P) {} class Bar extends (await P) {}
return Bar; return Bar;
@ -169,9 +163,7 @@ var async = 3;
var y = { async }; var y = { async };
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
async function f() {} async function f() {}
async function ft<T>(a: T) {} async function ft<T>(a: T) {}
class C { class C {
async m() {} async m() {}
async mt<T>(a: T) {} async mt<T>(a: T) {}
@ -185,9 +177,7 @@ var o = { async m() {} };
var ot = { async m<T>(a: T) {} }; var ot = { async m<T>(a: T) {} };
var oz = { async async() {} }; var oz = { async async() {} };
var x = { async: 5 }; var x = { async: 5 };
console.log(x.async); console.log(x.async);
var async = 3; var async = 3;
var y = { async }; var y = { async };
" "
@ -224,14 +214,11 @@ async function foo3(): Promise<string> {
async function foo1(): Promise<string> { async function foo1(): Promise<string> {
return; return;
} }
async function foo2(): Promise<string> { async function foo2(): Promise<string> {
return undefined; return undefined;
} }
async function foo3(): Promise<string> { async function foo3(): Promise<string> {
function bar() {} function bar() {}
return bar(); return bar();
} }
" "
@ -324,35 +311,29 @@ function test1() {
async function foo() { async function foo() {
return 42; return 42;
} }
async function bar() { async function bar() {
var a = await foo(); var a = await foo();
var b: number = a; var b: number = a;
var c: string = a; var c: string = a;
} }
} }
function test2() { function test2() {
async function voidoid1() { async function voidoid1() {
console.log(\"HEY\"); console.log(\"HEY\");
} }
var voidoid2: () => Promise<void> = voidoid1; var voidoid2: () => Promise<void> = voidoid1;
var voidoid3: () => void = voidoid1; var voidoid3: () => void = voidoid1;
} }
function test3() { function test3() {
async function voidoid4(): Promise<void> { async function voidoid4(): Promise<void> {
console.log(\"HEY\"); console.log(\"HEY\");
} }
} }
function test4() { function test4() {
async function voidoid5(): void { async function voidoid5(): void {
console.log(\"HEY\"); console.log(\"HEY\");
} }
} }
function test5() { function test5() {
async function voidoid6(): Promise<number> { async function voidoid6(): Promise<number> {
console.log(\"HEY\"); console.log(\"HEY\");
@ -412,11 +393,9 @@ async function baz() {
async function foo() { async function foo() {
return 42; return 42;
} }
async function bar() { async function bar() {
return foo(); return foo();
} }
async function baz() { async function baz() {
var a = await bar(); var a = await bar();
var b: number = a; var b: number = a;
@ -454,11 +433,9 @@ var y = { await };
async function f() { async function f() {
await 1; await 1;
} }
async function ft<T>(a: T) { async function ft<T>(a: T) {
await 1; await 1;
} }
class C { class C {
async m() { async m() {
await 1; await 1;
@ -498,9 +475,7 @@ var oz = {
} }
}; };
var x = { await: 5 }; var x = { await: 5 };
console.log(x.await); console.log(x.await);
var await = 3; var await = 3;
var y = { await }; var y = { await };
" "

View File

@ -33,31 +33,24 @@ async function* delegate_next() {
async function* inner() { async function* inner() {
var x: void = yield; var x: void = yield;
} }
yield* inner(); yield* inner();
} }
delegate_next().next(0); delegate_next().next(0);
async function* delegate_yield() { async function* delegate_yield() {
async function* inner() { async function* inner() {
yield 0; yield 0;
} }
yield* inner(); yield* inner();
} }
async () => { async () => {
for await (const x of delegate_yield()) { for await (const x of delegate_yield()) {
(x: void); (x: void);
} }
}; };
async function* delegate_return() { async function* delegate_return() {
async function* inner() { async function* inner() {
return 0; return 0;
} }
var x: void = yield* inner(); var x: void = yield* inner();
} }
" "
@ -93,7 +86,6 @@ async function f() {
// error: string ~> void // error: string ~> void
interface File { readLine(): Promise<string>, close(): void, EOF: boolean } interface File { readLine(): Promise<string>, close(): void, EOF: boolean }
declare function fileOpen(path: string): Promise<File>; declare function fileOpen(path: string): Promise<File>;
async function* readLines(path) { async function* readLines(path) {
let file: File = await fileOpen(path); let file: File = await fileOpen(path);
try { try {
@ -104,7 +96,6 @@ async function* readLines(path) {
file.close(); file.close();
} }
} }
async function f() { async function f() {
for await (const line of readLines(\"/path/to/file\")) { for await (const line of readLines(\"/path/to/file\")) {
(line: void); (line: void);
@ -144,11 +135,9 @@ refuse_return().return(\"string\").then(result => {
// yielding or returning internally. // yielding or returning internally.
// error: number | void ~> string // error: number | void ~> string
declare var gen: AsyncGenerator<void, string, void>; declare var gen: AsyncGenerator<void, string, void>;
gen.return(0).then(result => { gen.return(0).then(result => {
(result.value: void); (result.value: void);
}); });
async function* refuse_return() { async function* refuse_return() {
try { try {
yield 1; yield 1;
@ -156,7 +145,6 @@ async function* refuse_return() {
return 0; return 0;
} }
} }
refuse_return().return(\"string\").then(result => { refuse_return().return(\"string\").then(result => {
if (result.done) { if (result.done) {
(result.value: string); (result.value: string);
@ -208,7 +196,6 @@ async function* catch_return() {
return e; return e;
} }
} }
async () => { async () => {
catch_return().throw(\"\").then(({ value }) => { catch_return().throw(\"\").then(({ value }) => {
if (value !== undefined) { if (value !== undefined) {
@ -216,17 +203,14 @@ async () => {
} }
}); });
}; };
async function* yield_return() { async function* yield_return() {
try { try {
yield 0; yield 0;
return; return;
} catch (e) { } catch (e) {
yield e; yield e;
} }
} }
async () => { async () => {
yield_return().throw(\"\").then(({ value }) => { yield_return().throw(\"\").then(({ value }) => {
if (value !== undefined) { if (value !== undefined) {

View File

@ -19,7 +19,6 @@ declare var mergeInto: $Facebookism$MergeInto;
declare var mixin: $Facebookism$Mixin; declare var mixin: $Facebookism$Mixin;
declare var objectGetPrototypeOf: Object$GetPrototypeOf; declare var objectGetPrototypeOf: Object$GetPrototypeOf;
declare var objectAssign: Object$Assign; declare var objectAssign: Object$Assign;
m; m;
" "
`; `;

View File

@ -78,55 +78,39 @@ let tests = [
let tests = [ let tests = [
function() { function() {
\"foo\" in {}; \"foo\" in {};
\"foo\" in { foo: null }; \"foo\" in { foo: null };
0 in {}; 0 in {};
0 in { \"0\": null }; 0 in { \"0\": null };
}, },
function() { function() {
\"foo\" in []; \"foo\" in [];
0 in []; 0 in [];
\"length\" in []; \"length\" in [];
}, },
function() { function() {
\"foo\" in new String(\"bar\"); \"foo\" in new String(\"bar\");
\"foo\" in new Number(123); \"foo\" in new Number(123);
}, },
function() { function() {
\"foo\" in 123; \"foo\" in 123;
\"foo\" in \"bar\"; \"foo\" in \"bar\";
\"foo\" in void 0; \"foo\" in void 0;
\"foo\" in null; \"foo\" in null;
}, },
function() { function() {
null in {}; null in {};
void 0 in {}; void 0 in {};
({}) in {}; ({}) in {};
[] in {}; [] in {};
false in []; false in [];
}, },
function() { function() {
if (\"foo\" in 123) {} if (\"foo\" in 123) {}
if (!\"foo\" in {}) {} if (!\"foo\" in {}) {}
if (!(\"foo\" in {})) {} if (!(\"foo\" in {})) {}
}, },
function(x: Object, y: mixed) { function(x: Object, y: mixed) {
\"foo\" in x; \"foo\" in x;
\"foo\" in y; \"foo\" in y;
} }
]; ];

View File

@ -33,40 +33,23 @@ for (const { baz } of bazzes) {
// error: string ~> number // error: string ~> number
// error: string ~> number // error: string ~> number
const x = 0; const x = 0;
x++; x++;
x--; x--;
x += 0; x += 0;
x -= 0; x -= 0;
x /= 0; x /= 0;
x %= 0; x %= 0;
x <<= 0; x <<= 0;
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 { foo } = { foo: \"foo\" };
const [ bar ] = [ \"bar\" ]; const [ bar ] = [ \"bar\" ];
(foo: number); (foo: number);
(bar: number); (bar: number);
declare var bazzes: { baz: string }[]; declare var bazzes: { baz: string }[];
for (const { baz } of bazzes) { for (const { baz } of bazzes) {
(baz: number); (baz: number);
} }
@ -328,155 +311,120 @@ function type_type() {
type A = number; type A = number;
type A = number; type A = number;
} }
function type_class() { function type_class() {
type A = number; type A = number;
class A {} class A {}
} }
function type_let() { function type_let() {
type A = number; type A = number;
let A = 0; let A = 0;
} }
function type_const() { function type_const() {
type A = number; type A = number;
const A = 0; const A = 0;
} }
function type_var() { function type_var() {
type A = number; type A = number;
var A = 0; var A = 0;
} }
function type_reassign() { function type_reassign() {
type A = number; type A = number;
A = 42; A = 42;
} }
function class_type() { function class_type() {
class A {} class A {}
type A = number; type A = number;
} }
function class_class() { function class_class() {
class A {} class A {}
class A {} class A {}
} }
function class_let() { function class_let() {
class A {} class A {}
let A = 0; let A = 0;
} }
function class_const() { function class_const() {
class A {} class A {}
const A = 0; const A = 0;
} }
function class_var() { function class_var() {
class A {} class A {}
var A = 0; var A = 0;
} }
function let_type() { function let_type() {
let A = 0; let A = 0;
type A = number; type A = number;
} }
function let_class() { function let_class() {
let A = 0; let A = 0;
class A {} class A {}
} }
function let_let() { function let_let() {
let A = 0; let A = 0;
let A = 0; let A = 0;
} }
function let_const() { function let_const() {
let A = 0; let A = 0;
const A = 0; const A = 0;
} }
function let_var() { function let_var() {
let A = 0; let A = 0;
var A = 0; var A = 0;
} }
function const_type() { function const_type() {
const A = 0; const A = 0;
type A = number; type A = number;
} }
function const_class() { function const_class() {
const A = 0; const A = 0;
class A {} class A {}
} }
function const_let() { function const_let() {
const A = 0; const A = 0;
let A = 0; let A = 0;
} }
function const_const() { function const_const() {
const A = 0; const A = 0;
const A = 0; const A = 0;
} }
function const_var() { function const_var() {
const A = 0; const A = 0;
var A = 0; var A = 0;
} }
function const_reassign() { function const_reassign() {
const A = 0; const A = 0;
A = 42; A = 42;
} }
function var_type() { function var_type() {
var A = 0; var A = 0;
type A = number; type A = number;
} }
function var_class() { function var_class() {
var A = 0; var A = 0;
class A {} class A {}
} }
function var_let() { function var_let() {
var A = 0; var A = 0;
let A = 0; let A = 0;
} }
function var_const() { function var_const() {
var A = 0; var A = 0;
const A = 0; const A = 0;
} }
function var_var() { function var_var() {
var A = 0; var A = 0;
var A = 0; var A = 0;
} }
function function_toplevel() { function function_toplevel() {
function a() {} function a() {}
function a() {} function a() {}
} }
function function_block() { function function_block() {
{ {
function a() {} function a() {}
function a() {} function a() {}
} }
} }
function var_shadow_nested_scope() { function var_shadow_nested_scope() {
{ {
let x = 0; let x = 0;
@ -485,7 +433,6 @@ function var_shadow_nested_scope() {
} }
} }
} }
function type_shadow_nested_scope() { function type_shadow_nested_scope() {
{ {
let x = 0; let x = 0;
@ -494,9 +441,7 @@ function type_shadow_nested_scope() {
} }
} }
} }
function fn_params_name_clash(x, x) {} function fn_params_name_clash(x, x) {}
function fn_params_clash_fn_binding(x, y) { function fn_params_clash_fn_binding(x, y) {
let x = 0; let x = 0;
var y = 0; var y = 0;
@ -650,7 +595,6 @@ function block_scope() {
var b = \"\"; var b = \"\";
} }
} }
function switch_scope(x: string) { function switch_scope(x: string) {
let a: number = 0; let a: number = 0;
var b: number = 0; var b: number = 0;
@ -664,13 +608,10 @@ function switch_scope(x: string) {
break; break;
} }
} }
function switch_scope2(x: number) { function switch_scope2(x: number) {
switch (x) { switch (x) {
case 0: case 0:
a = \"\"; a = \"\";
break; break;
case 1: case 1:
var b = a; var b = a;
@ -679,18 +620,14 @@ function switch_scope2(x: number) {
let a = \"\"; let a = \"\";
break; break;
case 3: case 3:
a = \"\"; a = \"\";
break; break;
case 4: case 4:
var c: string = a; var c: string = a;
break; break;
} }
a = \"\"; a = \"\";
} }
function try_scope() { function try_scope() {
let a: number = 0; let a: number = 0;
try { try {
@ -701,57 +638,41 @@ function try_scope() {
let a = \"\"; let a = \"\";
} }
} }
function for_scope_let() { function for_scope_let() {
let a: number = 0; let a: number = 0;
for (let a = \"\"; ; ) {} for (let a = \"\"; ; ) {}
} }
function for_scope_var() { function for_scope_var() {
var a: number = 0; var a: number = 0;
for (var a = \"\"; ; ) {} for (var a = \"\"; ; ) {}
} }
function for_in_scope_let(o: Object) { function for_in_scope_let(o: Object) {
let a: number = 0; let a: number = 0;
for (let a in o) {} for (let a in o) {}
} }
function for_in_scope_var(o: Object) { function for_in_scope_var(o: Object) {
var a: number = 0; var a: number = 0;
for (var a in o) {} for (var a in o) {}
} }
function for_of_scope_let(xs: string[]) { function for_of_scope_let(xs: string[]) {
let a: number = 0; let a: number = 0;
for (let a of xs) {} for (let a of xs) {}
} }
function for_of_scope_var(xs: string[]) { function for_of_scope_var(xs: string[]) {
var a: number = 0; var a: number = 0;
for (var a of xs) {} for (var a of xs) {}
} }
function default_param_1() { function default_param_1() {
function f(x: () => string = f): number { function f(x: () => string = f): number {
return 0; return 0;
} }
} }
function default_param_2() { function default_param_2() {
let a = \"\"; let a = \"\";
function f0(x = () => a): number { function f0(x = () => a): number {
let a = 0; let a = 0;
return x(); return x();
} }
function f1(x = b): number { function f1(x = b): number {
let b = 0; let b = 0;
return x; return x;
@ -906,25 +827,19 @@ f(a); // ok, a: number (not ?number)
// ok, a: number (not ?number) // ok, a: number (not ?number)
type T1 = T2; type T1 = T2;
type T2 = number; type T2 = number;
function f0() { function f0() {
var v = x * c; var v = x * c;
let x = 0; let x = 0;
const c = 0; const c = 0;
} }
function f1(b) { function f1(b) {
x = 10; x = 10;
let x = 0; let x = 0;
if (b) { if (b) {
y = 10; y = 10;
let y = 0; let y = 0;
} }
} }
function f2() { function f2() {
{ {
var v = x * c; var v = x * c;
@ -932,57 +847,44 @@ function f2() {
let x = 0; let x = 0;
const c = 0; const c = 0;
} }
function f3() { function f3() {
var s: string = foo(); var s: string = foo();
{ {
var n: number = foo(); var n: number = foo();
function foo() { function foo() {
return 0; return 0;
} }
} }
var s2: string = foo(); var s2: string = foo();
function foo() { function foo() {
return \"\"; return \"\";
} }
} }
function f4() { function f4() {
function g() { function g() {
return x + c; return x + c;
} }
let x = 0; let x = 0;
const c = 0; const c = 0;
} }
function f5() { function f5() {
function g() { function g() {
return x; return x;
} }
g(); g();
let x = 0; let x = 0;
const c = 0; const c = 0;
} }
var x: C; var x: C;
var y = new C(); var y = new C();
class C {} class C {}
var z: C = new C(); var z: C = new C();
var a: number; var a: number;
function f(n: number) { function f(n: number) {
return n; return n;
} }
f(a); f(a);
a = 10; a = 10;
f(a); f(a);
" "
`; `;

View File

@ -125,89 +125,50 @@ for (let [x, y]: [number, number] of a.entries()) {} // incorrect
// incorrect // incorrect
// incorrect // incorrect
const a: FormData = new FormData(); const a: FormData = new FormData();
new FormData(\"\"); new FormData(\"\");
new FormData(document.createElement(\"input\")); new FormData(document.createElement(\"input\"));
new FormData(document.createElement(\"form\")); new FormData(document.createElement(\"form\"));
const b: boolean = a.has(\"foo\"); const b: boolean = a.has(\"foo\");
const c: ?(string | File) = a.get(\"foo\"); const c: ?(string | File) = a.get(\"foo\");
const d: string = a.get(\"foo\"); const d: string = a.get(\"foo\");
const e: Blob = a.get(\"foo\"); const e: Blob = a.get(\"foo\");
const f: ?(string | File | Blob) = a.get(\"foo\"); const f: ?(string | File | Blob) = a.get(\"foo\");
a.get(2); a.get(2);
const a1: Array<string | File> = a.getAll(\"foo\"); const a1: Array<string | File> = a.getAll(\"foo\");
const a2: Array<string | File | number> = a.getAll(\"foo\"); const a2: Array<string | File | number> = a.getAll(\"foo\");
const a3: Array<string | Blob | File> = a.getAll(\"foo\"); const a3: Array<string | Blob | File> = a.getAll(\"foo\");
a.getAll(23); a.getAll(23);
a.set(\"foo\", \"bar\"); a.set(\"foo\", \"bar\");
a.set(\"foo\", {}); a.set(\"foo\", {});
a.set(2, \"bar\"); a.set(2, \"bar\");
a.set(\"foo\", \"bar\", \"baz\"); a.set(\"foo\", \"bar\", \"baz\");
a.set(\"bar\", new File([], \"q\")); a.set(\"bar\", new File([], \"q\"));
a.set(\"bar\", new File([], \"q\"), \"x\"); a.set(\"bar\", new File([], \"q\"), \"x\");
a.set(\"bar\", new File([], \"q\"), 2); a.set(\"bar\", new File([], \"q\"), 2);
a.set(\"bar\", new Blob()); a.set(\"bar\", new Blob());
a.set(\"bar\", new Blob(), \"x\"); a.set(\"bar\", new Blob(), \"x\");
a.set(\"bar\", new Blob(), 2); a.set(\"bar\", new Blob(), 2);
a.append(\"foo\", \"bar\"); a.append(\"foo\", \"bar\");
a.append(\"foo\", {}); a.append(\"foo\", {});
a.append(2, \"bar\"); a.append(2, \"bar\");
a.append(\"foo\", \"bar\", \"baz\"); a.append(\"foo\", \"bar\", \"baz\");
a.append(\"foo\", \"bar\"); a.append(\"foo\", \"bar\");
a.append(\"bar\", new File([], \"q\")); a.append(\"bar\", new File([], \"q\"));
a.append(\"bar\", new File([], \"q\"), \"x\"); a.append(\"bar\", new File([], \"q\"), \"x\");
a.append(\"bar\", new File([], \"q\"), 2); a.append(\"bar\", new File([], \"q\"), 2);
a.append(\"bar\", new Blob()); a.append(\"bar\", new Blob());
a.append(\"bar\", new Blob(), \"x\"); a.append(\"bar\", new Blob(), \"x\");
a.append(\"bar\", new Blob(), 2); a.append(\"bar\", new Blob(), 2);
a.delete(\"xx\"); a.delete(\"xx\");
a.delete(3); a.delete(3);
for (let x: string of a.keys()) {} for (let x: string of a.keys()) {}
for (let x: number of a.keys()) {} for (let x: number of a.keys()) {}
for (let x: string | File of a.values()) {} for (let x: string | File of a.values()) {}
for (let x: string | File | Blob 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] of a.entries()) {}
for (let [ x, y ]: [string, string | File | Blob] 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 ]: [number, string] of a.entries()) {}
for (let [ x, y ]: [string, number] of a.entries()) {} for (let [ x, y ]: [string, number] of a.entries()) {}
for (let [ x, y ]: [number, number] of a.entries()) {} for (let [ x, y ]: [number, number] of a.entries()) {}
" "
`; `;
@ -270,39 +231,22 @@ function callback(
): void { ): void {
return; return;
} }
const o: MutationObserver = new MutationObserver(callback); const o: MutationObserver = new MutationObserver(callback);
new MutationObserver((arr: Array<MutationRecord>) => true); new MutationObserver((arr: Array<MutationRecord>) => true);
new MutationObserver(() => {}); new MutationObserver(() => {});
new MutationObserver(); new MutationObserver();
new MutationObserver(42); new MutationObserver(42);
new MutationObserver((n: number) => {}); new MutationObserver((n: number) => {});
const div = document.createElement(\"div\"); const div = document.createElement(\"div\");
o.observe(div, { attributes: true, attributeFilter: [ \"style\" ] }); o.observe(div, { attributes: true, attributeFilter: [ \"style\" ] });
o.observe(div, { characterData: true, invalid: true }); o.observe(div, { characterData: true, invalid: true });
o.observe(); o.observe();
o.observe(\"invalid\"); o.observe(\"invalid\");
o.observe(div); o.observe(div);
o.observe(div, {}); o.observe(div, {});
o.observe(div, { subtree: true }); o.observe(div, { subtree: true });
o.observe(div, { attributes: true, attributeFilter: true }); o.observe(div, { attributes: true, attributeFilter: true });
o.takeRecords(); o.takeRecords();
o.disconnect(); o.disconnect();
" "
`; `;

View File

@ -5,9 +5,7 @@ foo(0, \"\");
function bar<X:number, Y:X>(x:X, y:Y): number { return y*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 {} function foo<X, Y: X>(x: X, y: Y): void {}
foo(0, \"\"); foo(0, \"\");
function bar<X: number, Y: X>(x: X, y: Y): number { function bar<X: number, Y: X>(x: X, y: Y): number {
return y * 0; return y * 0;
} }
@ -56,7 +54,6 @@ function foo<T: number>(x: T): T {
var y: string = x; var y: string = x;
return x; return x;
} }
class C<T: number> { class C<T: number> {
bar<U: number>(x: U): T { bar<U: number>(x: U): T {
return x; return x;
@ -67,13 +64,10 @@ class C<T: number> {
return x; return x;
} }
} }
function example<T: { x: number }>(o: T): T { function example<T: { x: number }>(o: T): T {
o.x = 0; o.x = 0;
return o; return o;
} }
var obj1: { x: number, y: string } = example({ x: 0, y: \"\" }); var obj1: { x: number, y: string } = example({ x: 0, y: \"\" });
var obj2: { x: number } = example({ x: 0 }); var obj2: { x: number } = example({ x: 0 });
var c: C<string> = new C(); var c: C<string> = new C();

View File

@ -87,27 +87,20 @@ function foo(b) {
while (b) { while (b) {
if (x == null) { if (x == null) {
z = \"\"; z = \"\";
break; break;
} }
var y: number = x; var y: number = x;
} }
var w: number = z; var w: number = z;
} }
function bar(b) { function bar(b) {
var x = b ? null : false; var x = b ? null : false;
if (x == null) if (x == null)
return; return;
switch (\"\") { switch (\"\") {
case 0: case 0:
var y: number = x; var y: number = x;
x = \"\"; x = \"\";
case 1: case 1:
var z: number = x; var z: number = x;
break; break;
@ -115,18 +108,14 @@ function bar(b) {
} }
var w: number = x; var w: number = x;
} }
function bar2(b) { function bar2(b) {
var x = b ? null : false; var x = b ? null : false;
if (x == null) if (x == null)
return; return;
switch (\"\") { switch (\"\") {
case 0: case 0:
{ {
let y: number = x; let y: number = x;
x = \"\"; x = \"\";
} }
case 1: case 1:
@ -138,36 +127,27 @@ function bar2(b) {
} }
var w: number = x; var w: number = x;
} }
function qux(b) { function qux(b) {
var z = 0; var z = 0;
while (b) { while (b) {
var y: number = z; var y: number = z;
if (b) { if (b) {
z = \"\"; z = \"\";
continue; continue;
} }
z = 0; z = 0;
} }
var w: number = z; var w: number = z;
} }
function test_const() { function test_const() {
let st: string = \"abc\"; let st: string = \"abc\";
for (let i = 1; i < 100; i++) { for (let i = 1; i < 100; i++) {
const fooRes: ?string = \"HEY\"; const fooRes: ?string = \"HEY\";
if (!fooRes) { if (!fooRes) {
break; break;
} }
st = fooRes; st = fooRes;
} }
return st; return st;
} }
" "

View File

@ -4,9 +4,7 @@ exports[`test test.js 1`] = `
module.exports = o; module.exports = o;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
var o = Object.freeze({ foo: 0 }); var o = Object.freeze({ foo: 0 });
(o.foo: string); (o.foo: string);
module.exports = o; module.exports = o;
" "
`; `;
@ -16,7 +14,6 @@ exports[`test test2.js 1`] = `
(o.foo: string); (o.foo: string);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
var o = require(\"./test\"); var o = require(\"./test\");
(o.foo: string); (o.foo: string);
" "
`; `;

View File

@ -26,24 +26,19 @@ var b = a.map(function(x) {
}); });
var c: string = b[0]; var c: string = b[0];
var array = []; var array = [];
function f() { function f() {
array = array.map(function() { array = array.map(function() {
return \"...\"; return \"...\";
}); });
var x: number = array[0]; var x: number = array[0];
} }
var Foo = require(\"./genericfoo\"); var Foo = require(\"./genericfoo\");
var foo = new Foo(); var foo = new Foo();
function g() { function g() {
var foo1 = foo.map(function() { var foo1 = foo.map(function() {
return \"...\"; return \"...\";
}); });
var x: number = foo1.get(); var x: number = foo1.get();
foo = foo1; foo = foo1;
} }
" "
@ -73,7 +68,6 @@ class Foo<T> {
return this.x; return this.x;
} }
} }
module.exports = Foo; module.exports = Foo;
" "
`; `;

View File

@ -39,23 +39,18 @@ function f(): number {
function a(f: { (): string }, g: { (x: number): string }): string { function a(f: { (): string }, g: { (x: number): string }): string {
return f() + g(123); return f() + g(123);
} }
function b(f: { (): string }): number { function b(f: { (): string }): number {
return f(); return f();
} }
function c(f: { (x: number): number }): number { function c(f: { (x: number): number }): number {
return f(\"hello\"); return f(\"hello\");
} }
function d(f: { (x: number): number }): number { function d(f: { (x: number): number }): number {
return f(); return f();
} }
function e(f: {}): number { function e(f: {}): number {
return f(); return f();
} }
function f(): number { function f(): number {
var x = {}; var x = {};
return x(); return x();
@ -167,27 +162,21 @@ function g(x: {}): Function {
function a(x: { (z: number): string }): (z: number) => string { function a(x: { (z: number): string }): (z: number) => string {
return x; return x;
} }
function b(x: { (z: number): string }): (z: number) => number { function b(x: { (z: number): string }): (z: number) => number {
return x; return x;
} }
function c(x: { (z: number): string }): (z: string) => string { function c(x: { (z: number): string }): (z: string) => string {
return x; return x;
} }
function d(x: { (z: number): string }): () => string { function d(x: { (z: number): string }): () => string {
return x; return x;
} }
function e(x: {}): () => string { function e(x: {}): () => string {
return x; return x;
} }
function f(x: { (z: number): string }): Function { function f(x: { (z: number): string }): Function {
return x; return x;
} }
function g(x: {}): Function { function g(x: {}): Function {
return x; return x;
} }
@ -226,18 +215,15 @@ function e(x: { (): string; (x: number): string }): () => number {
function a(f: { (): string, (x: number): string }): string { function a(f: { (): string, (x: number): string }): string {
return f() + f(123); return f() + f(123);
} }
var b: { (): string, (x: number): string } = function(x?: number): string { var b: { (): string, (x: number): string } = function(x?: number): string {
return \"hi\"; return \"hi\";
}; };
var c: { (): string, (x: number): string } = function(x: number): string { var c: { (): string, (x: number): string } = function(x: number): string {
return \"hi\"; return \"hi\";
}; };
function d(x: { (): string, (x: number): string }): () => string { function d(x: { (): string, (x: number): string }): () => string {
return x; return x;
} }
function e(x: { (): string, (x: number): string }): () => number { function e(x: { (): string, (x: number): string }): () => number {
return x; return x;
} }
@ -262,9 +248,7 @@ var c : { myProp: number } = f;
var a: { someProp: number } = function() {}; var a: { someProp: number } = function() {};
var b: { apply: Function } = function() {}; var b: { apply: Function } = function() {};
var f = function() {}; var f = function() {};
f.myProp = 123; f.myProp = 123;
var c: { myProp: number } = f; var c: { myProp: number } = f;
" "
`; `;

View File

@ -11,11 +11,9 @@ function f(x) {
(f: F); (f: F);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
type F = { (x: string): number, p?: string }; type F = { (x: string): number, p?: string };
function f(x) { function f(x) {
return x.length; return x.length;
} }
(f: F); (f: F);
" "
`; `;
@ -49,27 +47,17 @@ callable.call(null, 0); // error, number ~> string
// error, number ~> string // error, number ~> string
// error, number ~> string // error, number ~> string
var x = Boolean(4); var x = Boolean(4);
function foo(fn: (value: any) => boolean) {} function foo(fn: (value: any) => boolean) {}
foo(Boolean); foo(Boolean);
var dict: { [k: string]: any } = {}; var dict: { [k: string]: any } = {};
dict(); dict();
interface ICall { (x: string): void } interface ICall { (x: string): void }
declare var icall: ICall; declare var icall: ICall;
icall(0); icall(0);
icall.call(null, 0); icall.call(null, 0);
type Callable = { (x: string): void }; type Callable = { (x: string): void };
declare var callable: Callable; declare var callable: Callable;
callable(0); callable(0);
callable.call(null, 0); callable.call(null, 0);
" "
`; `;

View File

@ -80,25 +80,17 @@ class A {
static foo(x: number) {} static foo(x: number) {}
static bar(y: string) {} static bar(y: string) {}
} }
A.qux = function(x: string) {}; A.qux = function(x: string) {};
class B extends A { class B extends A {
static x: string; static x: string;
static foo(x: string) {} static foo(x: string) {}
static main() { static main() {
B.x = 0; B.x = 0;
B.x = \"\"; B.x = \"\";
B.foo(0); B.foo(0);
B.foo(\"\"); B.foo(\"\");
B.y = 0; B.y = 0;
B.bar(0); B.bar(0);
B.qux(0); B.qux(0);
} }
static create(): A { static create(): A {
@ -118,25 +110,19 @@ class C<X> {
class D extends C<string> { class D extends C<string> {
static main() { static main() {
D.foo(0); D.foo(0);
D.bar(0); D.bar(0);
} }
} }
var d: C<*> = D.create(); var d: C<*> = D.create();
(new A(): typeof A); (new A(): typeof A);
(B: typeof A); (B: typeof A);
class E { class E {
static x: number; static x: number;
static foo(): string { static foo(): string {
this.bar(); this.bar();
return this.x; return this.x;
} }
} }
module.exports = { A: A, B: B, C: C, D: D, E: E }; module.exports = { A: A, B: B, C: C, D: D, E: E };
" "
`; `;

View File

@ -8,7 +8,6 @@ module.exports = { A, B };
/* @flow */ /* @flow */
class A {} class A {}
class B {} class B {}
module.exports = { A, B }; module.exports = { A, B };
" "
`; `;
@ -66,19 +65,14 @@ foo(new D, { f_: 0 });
class C<X> { class C<X> {
x: X; x: X;
} }
function foo<X>(c: C<X>, x: X) {} function foo<X>(c: C<X>, x: X) {}
type O = { f: number }; type O = { f: number };
foo((new C(): C<O>), { f_: 0 }); foo((new C(): C<O>), { f_: 0 });
class D extends C<O> { class D extends C<O> {
bar() { bar() {
this.x; this.x;
} }
} }
foo(new D(), { f_: 0 }); foo(new D(), { f_: 0 });
" "
`; `;

View File

@ -14,15 +14,12 @@ function bar(x: Class<B>): B {
// OK // OK
// error (too few args) // error (too few args)
class A {} class A {}
function foo(x: Class<A>): A { function foo(x: Class<A>): A {
return new x(); return new x();
} }
class B { class B {
constructor(_: any) {} constructor(_: any) {}
} }
function bar(x: Class<B>): B { function bar(x: Class<B>): B {
return new x(); return new x();
} }
@ -52,15 +49,10 @@ declare function check<X>(cls: $Type<X>, inst: X): void;
class A {} class A {}
class B extends A {} class B extends A {}
class C {} class C {}
check(B, new A()); check(B, new A());
check(A, new B()); check(A, new B());
check(C, new A()); check(C, new A());
check(C, new B()); check(C, new B());
check(B, new C()); check(B, new C());
" "
`; `;

View File

@ -8,7 +8,6 @@ module.exports = A;
class A { class A {
foo(x: number): void {} foo(x: number): void {}
} }
module.exports = A; module.exports = A;
" "
`; `;
@ -27,9 +26,7 @@ module.exports = B;
var A = require(\"./A\"); var A = require(\"./A\");
class B extends A {} class B extends A {}
let b = new B(); let b = new B();
(b.foo: number); (b.foo: number);
module.exports = B; module.exports = B;
" "
`; `;
@ -52,9 +49,7 @@ class C extends B {
foo(x: string): void {} foo(x: string): void {}
} }
let c = new C(); let c = new C();
(c.foo: number); (c.foo: number);
module.exports = C; module.exports = C;
" "
`; `;
@ -66,7 +61,6 @@ new E().x
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
class D {} class D {}
class E {} class E {}
new E().x; new E().x;
" "
`; `;
@ -128,21 +122,13 @@ class TestClass {
c: ?string; c: ?string;
} }
var x = new TestClass(); var x = new TestClass();
x.a; x.a;
x.b; x.b;
x.c; x.c;
x.d; x.d;
var y: Foo = x; var y: Foo = x;
y.b; y.b;
y.d; y.d;
class Test2Superclass { class Test2Superclass {
a: number; a: number;
c: ?number; c: ?number;
@ -259,15 +245,10 @@ declare var o: {p:number};
class C { class C {
static p: string; static p: string;
} }
C.p = \"hi\"; C.p = \"hi\";
(C: { p: string }); (C: { p: string });
(C: { p: number }); (C: { p: number });
declare var o: { p: number }; declare var o: { p: number };
(o: Class<C>); (o: Class<C>);
" "
`; `;

View File

@ -105,45 +105,28 @@ function local_meth() {
// error // error
// shouldn\'t pollute linear refinement // shouldn\'t pollute linear refinement
function takes_string(_: string) {} function takes_string(_: string) {}
var global_x = \"hello\"; var global_x = \"hello\";
function global_f() {} function global_f() {}
function global_g() { function global_g() {
global_x = 42; global_x = 42;
} }
global_f(); global_f();
takes_string(global_x); takes_string(global_x);
global_g(); global_g();
takes_string(global_x); takes_string(global_x);
global_x = 42; global_x = 42;
function local_func() { function local_func() {
var local_x = \"hello\"; var local_x = \"hello\";
function local_f() {} function local_f() {}
function local_g() { function local_g() {
local_x = 42; local_x = 42;
} }
local_f(); local_f();
takes_string(local_x); takes_string(local_x);
local_g(); local_g();
takes_string(local_x); takes_string(local_x);
local_x = 42; local_x = 42;
} }
var global_y = \"hello\"; var global_y = \"hello\";
var global_o = { var global_o = {
f: function() {}, f: function() {},
@ -151,17 +134,11 @@ var global_o = {
global_y = 42; global_y = 42;
} }
}; };
global_o.f(); global_o.f();
takes_string(global_y); takes_string(global_y);
global_o.g(); global_o.g();
takes_string(global_y); takes_string(global_y);
global_y = 42; global_y = 42;
function local_meth() { function local_meth() {
var local_y = \"hello\"; var local_y = \"hello\";
var local_o = { var local_o = {
@ -170,15 +147,10 @@ function local_meth() {
local_y = 42; local_y = 42;
} }
}; };
local_o.f(); local_o.f();
takes_string(local_y); takes_string(local_y);
local_o.g(); local_o.g();
takes_string(local_y); takes_string(local_y);
local_y = 42; local_y = 42;
} }
" "
@ -206,15 +178,12 @@ function example(b: bool): number {
// error, string ~/~> number (return type anno) TODO // error, string ~/~> number (return type anno) TODO
function example(b: boolean): number { function example(b: boolean): number {
var x = 0; var x = 0;
function f() { function f() {
x = \"\"; x = \"\";
} }
if (b) { if (b) {
f(); f();
} }
return x; return x;
} }
" "
@ -285,30 +254,23 @@ call_me();
// error // error
// in a galaxy far far away // in a galaxy far far away
var call_me: () => void = () => {}; var call_me: () => void = () => {};
function g(x: ?number) { function g(x: ?number) {
const const_x = x; const const_x = x;
if (const_x) { if (const_x) {
call_me = () => { call_me = () => {
var y: number = const_x; var y: number = const_x;
}; };
} }
var var_x = x; var var_x = x;
if (var_x) { if (var_x) {
call_me = () => { call_me = () => {
var y: number = var_x; var y: number = var_x;
}; };
} }
var_x = null; var_x = null;
} }
function h(x: number | string | boolean) { function h(x: number | string | boolean) {
const const_x = x; const const_x = x;
if (typeof const_x == \"number\") { if (typeof const_x == \"number\") {
call_me = () => { call_me = () => {
var y: number = const_x; var y: number = const_x;
@ -322,9 +284,7 @@ function h(x: number | string | boolean) {
var y: boolean = const_x; var y: boolean = const_x;
}; };
} }
var var_x = x; var var_x = x;
if (typeof var_x == \"number\") { if (typeof var_x == \"number\") {
call_me = () => { call_me = () => {
var y: number = var_x; var y: number = var_x;
@ -339,7 +299,6 @@ function h(x: number | string | boolean) {
}; };
} }
} }
call_me(); call_me();
" "
`; `;

View File

@ -5,7 +5,6 @@ function f(x:string) { }
module.exports = f; module.exports = f;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function f(x: string) {} function f(x: string) {}
module.exports = f; module.exports = f;
" "
`; `;
@ -17,7 +16,6 @@ var f = require(\'./Abs\');
f(0); f(0);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
var f = require(\"./Abs\"); var f = require(\"./Abs\");
f(0); f(0);
" "
`; `;

View File

@ -32,11 +32,8 @@ var ColorIdToNumber = {
[ColorId.GREEN]: ColorNumber.GREEN, [ColorId.GREEN]: ColorNumber.GREEN,
[ColorId.BLUE]: ColorNumber.BLUE [ColorId.BLUE]: ColorNumber.BLUE
}; };
(ColorIdToNumber[ColorId.RED]: \"ffffff\"); (ColorIdToNumber[ColorId.RED]: \"ffffff\");
ColorIdToNumber.XXX; ColorIdToNumber.XXX;
module.exports = { ColorId, ColorNumber }; module.exports = { ColorId, ColorNumber };
" "
`; `;
@ -60,9 +57,7 @@ var ColorIdToNumber = {
[ColorId.GREEN]: ColorNumber.GREEN, [ColorId.GREEN]: ColorNumber.GREEN,
[ColorId.BLUE]: ColorNumber.BLUE [ColorId.BLUE]: ColorNumber.BLUE
}; };
(ColorIdToNumber[ColorId.GREEN]: \"ffffff\"); (ColorIdToNumber[ColorId.GREEN]: \"ffffff\");
module.exports = ColorIdToNumber; module.exports = ColorIdToNumber;
" "
`; `;
@ -76,7 +71,6 @@ var ColorIdToNumber = require(\'./test2\');
// oops // oops
var { ColorId } = require(\"./test\"); var { ColorId } = require(\"./test\");
var ColorIdToNumber = require(\"./test2\"); var ColorIdToNumber = require(\"./test2\");
(ColorIdToNumber[ColorId.BLUE]: \"ffffff\"); (ColorIdToNumber[ColorId.BLUE]: \"ffffff\");
" "
`; `;
@ -99,7 +93,6 @@ module.exports = {
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
var hello = require(\"./test4\"); var hello = require(\"./test4\");
var dummy = require(\"./test\"); var dummy = require(\"./test\");
module.exports = { ...dummy, [hello]: \"world\", ...dummy }; module.exports = { ...dummy, [hello]: \"world\", ...dummy };
" "
`; `;
@ -110,7 +103,6 @@ exports[`test test6.js 1`] = `
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// oops // oops
var o = require(\"./test5\"); var o = require(\"./test5\");
(o.hello: \"nothing\"); (o.hello: \"nothing\");
" "
`; `;

View File

@ -32,18 +32,15 @@ function a(): number {
var x: ?string = null; var x: ?string = null;
return x ? 1 : 0; return x ? 1 : 0;
} }
function b(): number { function b(): number {
var x: ?number = null; var x: ?number = null;
return x != null ? x : 0; return x != null ? x : 0;
} }
function c(): number { function c(): number {
var x = false; var x = false;
var temp = x ? 1 : x; var temp = x ? 1 : x;
return temp ? temp : 0; return temp ? temp : 0;
} }
function d(): string { function d(): string {
var x: ?number = null; var x: ?number = null;
return x != null ? x : x != null; return x != null ? x : x != null;

View File

@ -4,7 +4,6 @@ exports[`test no_at_flow.js 1`] = `
x.length; x.length;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
var x; var x;
x.length; x.length;
" "
`; `;

View File

@ -19,7 +19,6 @@ function foo(x) {
var a: number = \"asdf\"; var a: number = \"asdf\";
return x * 10; return x * 10;
} }
foo(\"Hello, world!\"); foo(\"Hello, world!\");
" "
`; `;

View File

@ -9,9 +9,7 @@ import {name} from \"testproj\";
// @flow // @flow
// Error: Resolve from node_modules first! // Error: Resolve from node_modules first!
import {name} from \"testproj\"; import {name} from \"testproj\";
(name: \"node_modules/testproj\"); (name: \"node_modules/testproj\");
(name: \"custom_resolve_dir/testproj\"); (name: \"custom_resolve_dir/testproj\");
" "
`; `;

View File

@ -9,9 +9,7 @@ import {name} from \"testproj2\";
// @flow // @flow
// Error: Resolve from sibling \'custom_resolve_dir\' first! // Error: Resolve from sibling \'custom_resolve_dir\' first!
import {name} from \"testproj2\"; import {name} from \"testproj2\";
(name: \"node_modules/testproj2\"); (name: \"node_modules/testproj2\");
(name: \"subdir/custom_resolve_dir/testproj2\"); (name: \"subdir/custom_resolve_dir/testproj2\");
" "
`; `;

View File

@ -48,15 +48,12 @@ class A {
return \"some string\"; return \"some string\";
} }
} }
A._sProperty = 48; A._sProperty = 48;
class B extends A { class B extends A {
_property1: string; _property1: string;
static _sProperty: string; static _sProperty: string;
constructor() { constructor() {
super(); super();
this._property1 = \"another string\"; this._property1 = \"another string\";
} }
_method1(): string { _method1(): string {
@ -66,7 +63,6 @@ class B extends A {
return 23; return 23;
} }
} }
B._sProperty = \"B._sProperty string\"; B._sProperty = \"B._sProperty string\";
" "
`; `;
@ -84,7 +80,6 @@ module.exports = new C;
class C { class C {
_p: string; _p: string;
} }
module.exports = new C(); module.exports = new C();
" "
`; `;

View File

@ -48,15 +48,12 @@ class A {
return \"some string\"; return \"some string\";
} }
} }
A._sProperty = 48; A._sProperty = 48;
class B extends A { class B extends A {
_property1: string; _property1: string;
static _sProperty: string; static _sProperty: string;
constructor() { constructor() {
super(); super();
this._property1 = \"another string\"; this._property1 = \"another string\";
} }
_method1(): string { _method1(): string {
@ -66,7 +63,6 @@ class B extends A {
return 23; return 23;
} }
} }
B._sProperty = \"B._sProperty string\"; B._sProperty = \"B._sProperty string\";
" "
`; `;

View File

@ -52,7 +52,6 @@ function durable_refi(x: ?number) {
function cannot_reassign(x: string) { function cannot_reassign(x: string) {
x = \"hey\"; x = \"hey\";
} }
function durable_refi(x: ?number) { function durable_refi(x: ?number) {
if (x) { if (x) {
return () => { return () => {

View File

@ -15,7 +15,6 @@ class C {
class D { class D {
constructor(): number {} constructor(): number {}
} }
module.exports = C; module.exports = C;
" "
`; `;

View File

@ -32,24 +32,19 @@ exports.Foo2 = (Foo: Class<IFoo>);
function Foo() { function Foo() {
this.x = 0; this.x = 0;
} }
Foo.y = 0; Foo.y = 0;
Foo.prototype = { Foo.prototype = {
m() { m() {
return 0; return 0;
} }
}; };
exports.Foo = Foo; exports.Foo = Foo;
interface IFooPrototype { m(): number } interface IFooPrototype { m(): number }
interface IFoo extends IFooPrototype { interface IFoo extends IFooPrototype {
static (): void, static (): void,
x: boolean, x: boolean,
static y: boolean static y: boolean
} }
exports.Foo2 = (Foo: Class<IFoo>); exports.Foo2 = (Foo: Class<IFoo>);
" "
`; `;

View File

@ -10,9 +10,7 @@ var xxx = 0;
xxx xxx
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
require(\"./dummy\"); require(\"./dummy\");
var xxx = 0; var xxx = 0;
xxx; xxx;
" "
`; `;

View File

@ -10,9 +10,7 @@ var xxx = 0;
xxx xxx
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
require(\"./dummy\"); require(\"./dummy\");
var xxx = 0; var xxx = 0;
xxx; xxx;
" "
`; `;

View File

@ -51,28 +51,18 @@ let tests = [
let tests = [ let tests = [
function() { function() {
new Boolean(); new Boolean();
new Boolean(0); new Boolean(0);
new Boolean(-0); new Boolean(-0);
new Boolean(null); new Boolean(null);
new Boolean(false); new Boolean(false);
new Boolean(NaN); new Boolean(NaN);
new Boolean(undefined); new Boolean(undefined);
new Boolean(\"\"); new Boolean(\"\");
}, },
function() { function() {
true.toString(); true.toString();
let x: boolean = false; let x: boolean = false;
x.toString(); x.toString();
new Boolean(true).toString(); new Boolean(true).toString();
}, },
function() { function() {
@ -80,19 +70,12 @@ let tests = [
}, },
function() { function() {
Boolean(); Boolean();
Boolean(0); Boolean(0);
Boolean(-0); Boolean(-0);
Boolean(null); Boolean(null);
Boolean(false); Boolean(false);
Boolean(NaN); Boolean(NaN);
Boolean(undefined); Boolean(undefined);
Boolean(\"\"); Boolean(\"\");
} }
]; ];
@ -146,7 +129,6 @@ function* generator(): Iterable<[string, number]> {
yield [ \"foo\", 123 ]; yield [ \"foo\", 123 ];
} }
} }
let tests = [ let tests = [
function() { function() {
let w = new Map(); let w = new Map();
@ -163,7 +145,6 @@ let tests = [
}, },
function(x: Map<string, number>) { function(x: Map<string, number>) {
(x.get(\"foo\"): boolean); (x.get(\"foo\"): boolean);
x.get(123); x.get(123);
} }
]; ];
@ -214,33 +195,22 @@ let tests = [
let tests = [ let tests = [
function() { function() {
new RegExp(\"foo\"); new RegExp(\"foo\");
new RegExp(/foo/); new RegExp(/foo/);
new RegExp(\"foo\", \"i\"); new RegExp(\"foo\", \"i\");
new RegExp(\"foo\", \"ig\"); new RegExp(\"foo\", \"ig\");
new RegExp(/foo/, \"i\"); new RegExp(/foo/, \"i\");
new RegExp(/foo/g, \"i\"); new RegExp(/foo/g, \"i\");
}, },
function() { function() {
RegExp(\"foo\"); RegExp(\"foo\");
RegExp(/foo/); RegExp(/foo/);
RegExp(\"foo\", \"i\"); RegExp(\"foo\", \"i\");
RegExp(\"foo\", \"ig\"); RegExp(\"foo\", \"ig\");
RegExp(/foo/, \"i\"); RegExp(/foo/, \"i\");
RegExp(/foo/g, \"i\"); RegExp(/foo/g, \"i\");
}, },
function() { function() {
RegExp(\"foo\", \"z\"); RegExp(\"foo\", \"z\");
new 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 ws = new WeakSet();
let obj: Object = {}; let obj: Object = {};
let dict: { foo: string } = { foo: \"bar\" }; let dict: { foo: string } = { foo: \"bar\" };
ws.add(window); ws.add(window);
ws.add(obj); ws.add(obj);
ws.add(dict); ws.add(dict);
ws.has(window); ws.has(window);
ws.has(obj); ws.has(obj);
ws.has(dict); ws.has(dict);
ws.delete(window); ws.delete(window);
ws.delete(obj); ws.delete(obj);
ws.delete(dict); ws.delete(dict);
let ws2 = new WeakSet([ obj, dict ]); let ws2 = new WeakSet([ obj, dict ]);
let ws3 = new WeakSet([ 1, 2, 3 ]); let ws3 = new WeakSet([ 1, 2, 3 ]);
function* generator(): Iterable<{ foo: string }> { function* generator(): Iterable<{ foo: string }> {
while (true) { while (true) {
yield { foo: \"bar\" }; yield { foo: \"bar\" };
} }
} }
let ws4 = new WeakSet(generator()); let ws4 = new WeakSet(generator());
function* numbers(): Iterable<number> { function* numbers(): Iterable<number> {
let i = 0; let i = 0;
while (true) { while (true) {
yield i++; yield i++;
} }
} }
let ws5 = new WeakSet(numbers()); let ws5 = new WeakSet(numbers());
" "
`; `;

View File

@ -89,9 +89,7 @@ n.x = [0];
type CovArrayVerbose<X, Y: X> = Array<Y>; type CovArrayVerbose<X, Y: X> = Array<Y>;
var b: CovArrayVerbose<number, *> = []; var b: CovArrayVerbose<number, *> = [];
var y: CovArrayVerbose<mixed, *> = b; var y: CovArrayVerbose<mixed, *> = b;
y[0] = \"\"; y[0] = \"\";
class NVerbose<E, I: E> { class NVerbose<E, I: E> {
x: CovArrayVerbose<E, I>; x: CovArrayVerbose<E, I>;
foo(): CovArrayVerbose<mixed, I> { foo(): CovArrayVerbose<mixed, I> {
@ -99,11 +97,8 @@ class NVerbose<E, I: E> {
} }
} }
var nv: NVerbose<number, *> = new NVerbose(); var nv: NVerbose<number, *> = new NVerbose();
nv.x = [ 0 ]; nv.x = [ 0 ];
(nv.x[0]: string); (nv.x[0]: string);
(nv.foo()[0]: string); (nv.foo()[0]: string);
" "
`; `;

View File

@ -36,7 +36,6 @@ exports[`test no_pragma.js 1`] = `
(x: string); (x: string);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
let x = 0; let x = 0;
(x: string); (x: string);
" "
`; `;

View File

@ -7,7 +7,6 @@ module.exports = A;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
var B = require(\"./B\"); var B = require(\"./B\");
class A extends B {} class A extends B {}
module.exports = A; module.exports = A;
" "
`; `;
@ -21,7 +20,6 @@ module.exports = B;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//class B extends A { } //class B extends A { }
var A = require(\"./A\"); var A = require(\"./A\");
module.exports = B; module.exports = B;
" "
`; `;

View File

@ -34,41 +34,23 @@ new Date(2015, 6, 18, 11, 55, 42, 999, \'hahaha\');
var d = new Date(0); var d = new Date(0);
var x: string = d.getTime(); var x: string = d.getTime();
var y: number = d; var y: number = d;
new Date(); new Date();
new Date(1234567890); new Date(1234567890);
new Date(\"2015/06/18\"); new Date(\"2015/06/18\");
new Date(2015, 6); new Date(2015, 6);
new Date(2015, 6, 18); new Date(2015, 6, 18);
new Date(2015, 6, 18, 11); new Date(2015, 6, 18, 11);
new Date(2015, 6, 18, 11, 55); new Date(2015, 6, 18, 11, 55);
new Date(2015, 6, 18, 11, 55, 42); new Date(2015, 6, 18, 11, 55, 42);
new Date(2015, 6, 18, 11, 55, 42, 999); new Date(2015, 6, 18, 11, 55, 42, 999);
new Date({}); new Date({});
new Date(2015, \"6\"); new Date(2015, \"6\");
new Date(2015, 6, \"18\"); new Date(2015, 6, \"18\");
new Date(2015, 6, 18, \"11\"); new Date(2015, 6, 18, \"11\");
new Date(2015, 6, 18, 11, \"55\"); new Date(2015, 6, 18, 11, \"55\");
new Date(2015, 6, 18, 11, 55, \"42\"); new Date(2015, 6, 18, 11, 55, \"42\");
new Date(2015, 6, 18, 11, 55, 42, \"999\"); new Date(2015, 6, 18, 11, 55, 42, \"999\");
new Date(\"2015\", 6); new Date(\"2015\", 6);
new Date(2015, 6, 18, 11, 55, 42, 999, \"hahaha\"); new Date(2015, 6, 18, 11, 55, 42, 999, \"hahaha\");
" "
`; `;

View File

@ -68,15 +68,10 @@ var ExplicitDifferentName = require(\'ExplicitProvidesModuleDifferentName\');
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/* @flow */ /* @flow */
var Implicit = require(\"ImplicitProvidesModule\"); var Implicit = require(\"ImplicitProvidesModule\");
(Implicit.fun(): string); (Implicit.fun(): string);
var ExplicitSameName = require(\"ExplicitProvidesModuleSameName\"); var ExplicitSameName = require(\"ExplicitProvidesModuleSameName\");
(ExplicitSameName.fun(): string); (ExplicitSameName.fun(): string);
var ExplicitDifferentName = require(\"ExplicitProvidesModuleDifferentName\"); var ExplicitDifferentName = require(\"ExplicitProvidesModuleDifferentName\");
(ExplicitDifferentName.fun(): string); (ExplicitDifferentName.fun(): string);
" "
`; `;

View File

@ -20,11 +20,8 @@ var docblock = require(\"qux/docblock\");
var min = require(\"d3/min.js\"); var min = require(\"d3/min.js\");
var corge = require(\"qux/corge\"); var corge = require(\"qux/corge\");
var unreachable = require(\"annotation\"); var unreachable = require(\"annotation\");
(docblock.fun(): string); (docblock.fun(): string);
(min.fun(): string); (min.fun(): string);
(corge.fun(): string); (corge.fun(): string);
" "
`; `;

View File

@ -25,7 +25,6 @@ module.exports.fun = (): Implementation => new Implementation;
* @flow * @flow
*/ */
class Implementation {} class Implementation {}
module.exports.fun = (): Implementation => new Implementation(); module.exports.fun = (): Implementation => new Implementation();
" "
`; `;
@ -44,7 +43,6 @@ module.exports.fun = (): Implementation => new Implementation;
* @flow * @flow
*/ */
class Implementation {} class Implementation {}
module.exports.fun = (): Implementation => new Implementation(); module.exports.fun = (): Implementation => new Implementation();
" "
`; `;
@ -63,7 +61,6 @@ module.exports.fun = (): Implementation => new Implementation;
* @flow * @flow
*/ */
class Implementation {} class Implementation {}
module.exports.fun = (): Implementation => new 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
// Error: Either Implementation ~> boolean or Declaration ~> boolean // Error: Either Implementation ~> boolean or Declaration ~> boolean
var Implicit = require(\"ImplicitProvidesModule\"); var Implicit = require(\"ImplicitProvidesModule\");
(Implicit.fun(): boolean); (Implicit.fun(): boolean);
var ExplicitSameName = require(\"ExplicitProvidesModuleSameName\"); var ExplicitSameName = require(\"ExplicitProvidesModuleSameName\");
(ExplicitSameName.fun(): boolean); (ExplicitSameName.fun(): boolean);
var ExplicitDifferentName = require(\"ExplicitProvidesModuleDifferentName\"); var ExplicitDifferentName = require(\"ExplicitProvidesModuleDifferentName\");
(ExplicitDifferentName.fun(): boolean); (ExplicitDifferentName.fun(): boolean);
" "
`; `;

View File

@ -3,7 +3,6 @@ exports[`test min.js 1`] = `
module.exports.fun = (): Implementation => new Implementation; module.exports.fun = (): Implementation => new Implementation;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
class Implementation {} class Implementation {}
module.exports.fun = (): Implementation => new Implementation(); module.exports.fun = (): Implementation => new Implementation();
" "
`; `;

View File

@ -16,11 +16,8 @@ var corge = require(\'qux/corge\');
var docblock = require(\"qux/docblock\"); var docblock = require(\"qux/docblock\");
var min = require(\"d3/min.js\"); var min = require(\"d3/min.js\");
var corge = require(\"qux/corge\"); var corge = require(\"qux/corge\");
(docblock.fun(): boolean); (docblock.fun(): boolean);
(min.fun(): boolean); (min.fun(): boolean);
(corge.fun(): boolean); (corge.fun(): boolean);
" "
`; `;

View File

@ -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
// Error either Implementation ~> boolean or Declaration ~> boolean // Error either Implementation ~> boolean or Declaration ~> boolean
var B1 = require(\"B\"); var B1 = require(\"B\");
(B1.fun(): boolean); (B1.fun(): boolean);
var B2 = require(\"B.js\"); var B2 = require(\"B.js\");
(B2.fun(): boolean); (B2.fun(): boolean);
var C = require(\"package_with_full_main\"); var C = require(\"package_with_full_main\");
(C.fun(): boolean); (C.fun(): boolean);
var D = require(\"package_with_partial_main\"); var D = require(\"package_with_partial_main\");
(D.fun(): boolean); (D.fun(): boolean);
var E = require(\"package_with_no_package_json\"); var E = require(\"package_with_no_package_json\");
(E.fun(): boolean); (E.fun(): boolean);
var F = require(\"package_with_dir_main\"); var F = require(\"package_with_dir_main\");
(F.fun(): boolean); (F.fun(): boolean);
var B1 = require(\"B\"); var B1 = require(\"B\");
(B1.fun(): boolean); (B1.fun(): boolean);
var B2 = require(\"B.js\"); var B2 = require(\"B.js\");
(B2.fun(): boolean); (B2.fun(): boolean);
var C = require(\"package_with_full_main\"); var C = require(\"package_with_full_main\");
(C.fun(): boolean); (C.fun(): boolean);
var D = require(\"package_with_partial_main\"); var D = require(\"package_with_partial_main\");
(D.fun(): boolean); (D.fun(): boolean);
var E = require(\"package_with_no_package_json\"); var E = require(\"package_with_no_package_json\");
(E.fun(): boolean); (E.fun(): boolean);
var F = require(\"package_with_dir_main\"); var F = require(\"package_with_dir_main\");
(F.fun(): boolean); (F.fun(): boolean);
" "
`; `;
@ -126,7 +103,6 @@ exports[`test test_relative.js 1`] = `
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Error: either Implementation ~> boolean or Definition ~> boolean // Error: either Implementation ~> boolean or Definition ~> boolean
import {foo} from \"./A\"; import {foo} from \"./A\";
(foo(): boolean); (foo(): boolean);
" "
`; `;

View File

@ -50,27 +50,16 @@ var F = require(\'package_with_dir_main\');
// Error number ~> string // Error number ~> string
// Error number ~> string // Error number ~> string
var B1 = require(\"B\"); var B1 = require(\"B\");
(B1.fun(): string); (B1.fun(): string);
var B2 = require(\"B.js\"); var B2 = require(\"B.js\");
(B2.fun(): string); (B2.fun(): string);
var C = require(\"package_with_full_main\"); var C = require(\"package_with_full_main\");
(C.fun(): string); (C.fun(): string);
var D = require(\"package_with_partial_main\"); var D = require(\"package_with_partial_main\");
(D.fun(): string); (D.fun(): string);
var E = require(\"package_with_no_package_json\"); var E = require(\"package_with_no_package_json\");
(E.fun(): string); (E.fun(): string);
var F = require(\"package_with_dir_main\"); var F = require(\"package_with_dir_main\");
(F.fun(): string); (F.fun(): string);
" "
`; `;
@ -97,17 +86,11 @@ var CJS = require(\'./CJS.js\');
// Error number ~> string // Error number ~> string
// Error: string ~> number // Error: string ~> number
var A1 = require(\"./A\"); var A1 = require(\"./A\");
(A1.fun(): string); (A1.fun(): string);
var A2 = require(\"./A.js\"); var A2 = require(\"./A.js\");
(A2.fun(): string); (A2.fun(): string);
var CJS = require(\"./CJS.js\"); var CJS = require(\"./CJS.js\");
(CJS: string); (CJS: string);
(CJS: number); (CJS: number);
" "
`; `;

View File

@ -12,13 +12,9 @@ C.foo(\"\");
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// error, it\'s a string // error, it\'s a string
declare class C { static x: number, static foo(x: number): void } declare class C { static x: number, static foo(x: number): void }
C.x = \"\"; C.x = \"\";
C.foo(\"\"); C.foo(\"\");
(C.name: string); (C.name: string);
(C.name: number); (C.name: number);
" "
`; `;

View File

@ -64,7 +64,6 @@ class Test extends Base {
return 2; return 2;
} }
} }
module.exports = Test; module.exports = Test;
" "
`; `;
@ -114,13 +113,9 @@ exports.numberValue5 = 5;
* @flow * @flow
*/ */
exports.numberValue1 = 1; exports.numberValue1 = 1;
exports.numberValue2 = 2; exports.numberValue2 = 2;
exports.numberValue3 = 3; exports.numberValue3 = 3;
exports.numberValue4 = 4; exports.numberValue4 = 4;
exports.numberValue5 = 5; exports.numberValue5 = 5;
" "
`; `;
@ -493,13 +488,9 @@ exports.stringValue = \"str\";
* @flow * @flow
*/ */
exports.numberValue1 = 42; exports.numberValue1 = 42;
exports.numberValue2 = 42; exports.numberValue2 = 42;
exports.numberValue3 = 42; exports.numberValue3 = 42;
exports.numberValue4 = 42; exports.numberValue4 = 42;
exports.stringValue = \"str\"; exports.stringValue = \"str\";
" "
`; `;
@ -990,33 +981,24 @@ var d2: string = numVal1;
import CJS_Clobb_Lit from \"CommonJS_Clobbering_Lit\"; import CJS_Clobb_Lit from \"CommonJS_Clobbering_Lit\";
var e1: number = CJS_Clobb_Lit.numberValue3; var e1: number = CJS_Clobb_Lit.numberValue3;
var e2: string = CJS_Clobb_Lit.numberValue3; var e2: string = CJS_Clobb_Lit.numberValue3;
CJS_Clobb_Lit.doesntExist; CJS_Clobb_Lit.doesntExist;
import * as CJS_Clobb_Lit_NS from \"CommonJS_Clobbering_Lit\"; import * as CJS_Clobb_Lit_NS from \"CommonJS_Clobbering_Lit\";
var f1: number = CJS_Clobb_Lit_NS.numberValue4; var f1: number = CJS_Clobb_Lit_NS.numberValue4;
var f2: number = CJS_Clobb_Lit_NS.default.numberValue4; var f2: number = CJS_Clobb_Lit_NS.default.numberValue4;
CJS_Clobb_Lit_NS.default.default; CJS_Clobb_Lit_NS.default.default;
var f3: string = CJS_Clobb_Lit_NS.numberValue4; var f3: string = CJS_Clobb_Lit_NS.numberValue4;
var f4: string = CJS_Clobb_Lit_NS.default.numberValue5; var f4: string = CJS_Clobb_Lit_NS.default.numberValue5;
import {doesntExist2} from \"CommonJS_Clobbering_Class\"; import {doesntExist2} from \"CommonJS_Clobbering_Class\";
import {staticNumber1, baseProp, childProp} from \"CommonJS_Clobbering_Class\"; import {staticNumber1, baseProp, childProp} from \"CommonJS_Clobbering_Class\";
import CJS_Clobb_Class from \"CommonJS_Clobbering_Class\"; import CJS_Clobb_Class from \"CommonJS_Clobbering_Class\";
new CJS_Clobb_Class(); new CJS_Clobb_Class();
new CJS_Clobb_Class().doesntExist; new CJS_Clobb_Class().doesntExist;
var h1: number = CJS_Clobb_Class.staticNumber2(); var h1: number = CJS_Clobb_Class.staticNumber2();
var h2: string = CJS_Clobb_Class.staticNumber2(); var h2: string = CJS_Clobb_Class.staticNumber2();
var h3: number = new CJS_Clobb_Class().instNumber1(); var h3: number = new CJS_Clobb_Class().instNumber1();
var h4: string = new CJS_Clobb_Class().instNumber1(); var h4: string = new CJS_Clobb_Class().instNumber1();
import * as CJS_Clobb_Class_NS from \"CommonJS_Clobbering_Class\"; import * as CJS_Clobb_Class_NS from \"CommonJS_Clobbering_Class\";
new CJS_Clobb_Class_NS(); new CJS_Clobb_Class_NS();
var i1: number = CJS_Clobb_Class_NS.staticNumber3(); var i1: number = CJS_Clobb_Class_NS.staticNumber3();
var i2: number = new CJS_Clobb_Class_NS.default().instNumber2(); var i2: number = new CJS_Clobb_Class_NS.default().instNumber2();
var i3: string = 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\"; import * as CJS_Named from \"CommonJS_Named\";
var l1: number = CJS_Named.numberValue1; var l1: number = CJS_Named.numberValue1;
var l2: string = CJS_Named.numberValue1; var l2: string = CJS_Named.numberValue1;
CJS_Named.doesntExist; CJS_Named.doesntExist;
import * as CJS_Named_NS from \"CommonJS_Named\"; import * as CJS_Named_NS from \"CommonJS_Named\";
var m1: number = CJS_Named_NS.numberValue4; var m1: number = CJS_Named_NS.numberValue4;
var m2: string = CJS_Named_NS.default.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\"; import {numberValue1 as numberValue5} from \"ES6_ExportAllFrom_Intermediary1\";
var ac1: number = numberValue5; var ac1: number = numberValue5;
var ac2: string = numberValue5; var ac2: string = numberValue5;
require(\"ES6_Default_AnonFunction2\").doesntExist; require(\"ES6_Default_AnonFunction2\").doesntExist;
var ES6_Def_AnonFunc2 = require(\"ES6_Default_AnonFunction2\").default; var ES6_Def_AnonFunc2 = require(\"ES6_Default_AnonFunction2\").default;
var ad1: number = ES6_Def_AnonFunc2(); var ad1: number = ES6_Def_AnonFunc2();
var ad2: string = ES6_Def_AnonFunc2(); var ad2: string = ES6_Def_AnonFunc2();

View File

@ -13,11 +13,8 @@ declare function foo<X>(x: X): X;
declare function foo(x: number): string; declare function foo(x: number): string;
declare function foo(x: string): number; declare function foo(x: string): number;
declare function foo<X>(x: X): X; declare function foo<X>(x: X): X;
(foo(0): string); (foo(0): string);
(foo(\"hello\"): number); (foo(\"hello\"): number);
(foo(false): void); (foo(false): void);
" "
`; `;

View File

@ -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
// Error: number ~> string // Error: number ~> string
import declare_module_exports from \"declare_module_exports\"; import declare_module_exports from \"declare_module_exports\";
(declare_module_exports: number); (declare_module_exports: number);
(declare_module_exports: string); (declare_module_exports: string);
import {str} from \"declare_m_e_with_other_value_declares\"; import {str} from \"declare_m_e_with_other_value_declares\";
import type {str2} from \"declare_m_e_with_other_type_declares\"; import type {str2} from \"declare_m_e_with_other_type_declares\";
(\"asdf\": str2); (\"asdf\": str2);
(42: str2); (42: str2);
import DEPRECATED__declare_var_exports from \"DEPRECATED__declare_var_exports\"; import DEPRECATED__declare_var_exports from \"DEPRECATED__declare_var_exports\";
(DEPRECATED__declare_var_exports: number); (DEPRECATED__declare_var_exports: number);
(DEPRECATED__declare_var_exports: string); (DEPRECATED__declare_var_exports: string);
import declare_m_e_with_declare_var_e from \"declare_m_e_with_declare_var_e\"; 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: number);
(declare_m_e_with_declare_var_e: string); (declare_m_e_with_declare_var_e: string);
" "
`; `;

View File

@ -54,13 +54,9 @@ import type {toz} from \"ModuleAliasFoo\";
var k4: toz = foo(k1); var k4: toz = foo(k1);
import blah from \"foo\"; import blah from \"foo\";
import type {Foo, Bar, Id} from \"foo\"; import type {Foo, Bar, Id} from \"foo\";
blah(0, 0); blah(0, 0);
({ toz: 3 }: Foo); ({ toz: 3 }: Foo);
(3: Bar); (3: Bar);
(\"lol\": Id<number>); (\"lol\": Id<number>);
" "
`; `;

View File

@ -55,13 +55,10 @@ class Variance<+Out, -In> {
} }
class A {} class A {}
class B extends A {} class B extends A {}
function subtyping(v1: Variance<A, B>, v2: Variance<B, A>) { function subtyping(v1: Variance<A, B>, v2: Variance<B, A>) {
(v1: Variance<B, A>); (v1: Variance<B, A>);
(v2: Variance<A, B>); (v2: Variance<A, B>);
} }
class PropVariance<+Out, -In> { class PropVariance<+Out, -In> {
inv1: Out; inv1: Out;
inv2: In; inv2: In;

View File

@ -13,9 +13,7 @@ f(x);
function f(x) { function f(x) {
return 42 / x; return 42 / x;
} }
var x = null; var x = null;
f(x); f(x);
" "
`; `;

View File

@ -33,15 +33,11 @@ class A {
return callback(this.getX()); return callback(this.getX());
} }
} }
function callback(x: string) { function callback(x: string) {
return x.length; return x.length;
} }
var a = new A(42); var a = new A(42);
a.onLoad(callback); a.onLoad(callback);
module.exports = A; module.exports = A;
" "
`; `;

View File

@ -19,11 +19,8 @@ require(\'./F\');
require(\'./G\'); require(\'./G\');
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
require(\"./D\"); require(\"./D\");
require(\"./E\"); require(\"./E\");
require(\"./F\"); require(\"./F\");
require(\"./G\"); require(\"./G\");
" "
`; `;

View File

@ -23,15 +23,10 @@ let [ a, ...ys ] = xs;
let [ b, ...zs ] = ys; let [ b, ...zs ] = ys;
let c = zs[0]; let c = zs[0];
let d = zs[1]; let d = zs[1];
(a: void); (a: void);
(b: void); (b: void);
(c: void); (c: void);
(d: void); (d: void);
let [ ...e ] = 0; let [ ...e ] = 0;
" "
`; `;
@ -51,16 +46,11 @@ var { [\"key\"]: val3, ...spread } = { key: \"val\" };
// ok (gasp!) by existing StrT -> ElemT rule // ok (gasp!) by existing StrT -> ElemT rule
// error (gasp!) in general we don\'t know if a computed prop should be excluded from spread // error (gasp!) in general we don\'t know if a computed prop should be excluded from spread
var { [\"key\"]: val1 } = { key: \"val\" }; var { [\"key\"]: val1 } = { key: \"val\" };
(val1: void); (val1: void);
var key: string = \"key\"; var key: string = \"key\";
var { [key]: val2 } = { key: \"val\" }; var { [key]: val2 } = { key: \"val\" };
(val2: void); (val2: void);
var { [\"key\"]: val3, ...spread } = { key: \"val\" }; var { [\"key\"]: val3, ...spread } = { key: \"val\" };
(spread.key: void); (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: \"\" } }) { function obj_prop_fun({ p: { q = 0 } = { q: true } } = { p: { q: \"\" } }) {
(q: void); (q: void);
} }
obj_prop_fun(); obj_prop_fun();
obj_prop_fun({}); obj_prop_fun({});
obj_prop_fun({ p: {} }); obj_prop_fun({ p: {} });
obj_prop_fun({ p: { q: null } }); obj_prop_fun({ p: { q: null } });
function obj_prop_var(o = { p: { q: \"\" } }) { function obj_prop_var(o = { p: { q: \"\" } }) {
var { p: { q = 0 } = { q: true } } = o; var { p: { q = 0 } = { q: true } } = o;
(q: void); (q: void);
} }
obj_prop_var(); obj_prop_var();
obj_prop_var({}); obj_prop_var({});
obj_prop_var({ p: {} }); obj_prop_var({ p: {} });
obj_prop_var({ p: { q: null } }); obj_prop_var({ p: { q: null } });
function obj_rest( function obj_rest(
{ p: { q, ...o } = { q: 0, r: 0 } } = { p: { q: 0, r: \"\" } } { p: { q, ...o } = { q: 0, r: 0 } } = { p: { q: 0, r: \"\" } }
) { ) {
(o.r: void); (o.r: void);
} }
obj_rest(); obj_rest();
obj_rest({}); obj_rest({});
obj_rest({ p: {} }); obj_rest({ p: {} });
obj_rest({ p: { q: 0, r: null } }); obj_rest({ p: { q: 0, r: null } });
function obj_prop_annot({ p = true }: { p: string } = { p: 0 }) { function obj_prop_annot({ p = true }: { p: string } = { p: 0 }) {
(p: void); (p: void);
} }
var { p = true }: { p: string } = { p: 0 }; var { p = true }: { p: string } = { p: 0 };
(p: void); (p: void);
function obj_prop_err({ x: { y } } = null) {} function obj_prop_err({ x: { y } } = null) {}
function obj_rest_err({ ...o } = 0) {} function obj_rest_err({ ...o } = 0) {}
function arr_elem_err([ x ] = null) {} function arr_elem_err([ x ] = null) {}
function arr_rest_err([ ...a ] = null) {} function arr_rest_err([ ...a ] = null) {}
function gen<T>(x: T, { p = x }: { p: T }): T { function gen<T>(x: T, { p = x }: { p: T }): T {
return p; return p;
} }
obj_prop_fun(({}: { p?: { q?: null } })); obj_prop_fun(({}: { p?: { q?: null } }));
obj_prop_var(({}: { p?: { q?: null } })); obj_prop_var(({}: { p?: { q?: null } }));
function obj_prop_opt({ p }: { p?: string } = { p: 0 }) {} function obj_prop_opt({ p }: { p?: string } = { p: 0 }) {}
function obj_prop_maybe({ 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_union({ p }: { p: number | string } = { p: true }) {}
function obj_prop_union2({ p }: { p: number } | { p: string } = { p: true }) {} function obj_prop_union2({ p }: { p: number } | { p: string } = { p: true }) {}
function default_expr_scope({ a, b = a }) {} 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 a: string;
declare var b: string; declare var b: string;
declare var c: string; declare var c: string;
[ { a1: a, b }, c ] = [ { a1: 0, b: 1 }, 2 ]; [ { a1: a, b }, c ] = [ { a1: 0, b: 1 }, 2 ];
var { m } = { m: 0 }; var { m } = { m: 0 };
({ m } = { m: m }); ({ m } = { m: m });
var obj; var obj;
({ n: obj.x } = { n: 3 }); ({ n: obj.x } = { n: 3 });
[ obj.x ] = [ \"foo\" ]; [ obj.x ] = [ \"foo\" ];
function foo({ p, z: [ r ] }) { function foo({ p, z: [ r ] }) {
a = p; a = p;
b = z; b = z;
c = r; c = r;
} }
foo({ p: 0, z: [ 1, 2 ] }); foo({ p: 0, z: [ 1, 2 ] });
[ a, , b, ...c ] = [ 0, 1, true, 3 ]; [ a, , b, ...c ] = [ 0, 1, true, 3 ];
function bar({ x, ...z }) { function bar({ x, ...z }) {
var o: { x: string, y: number } = z; var o: { x: string, y: number } = z;
} }
bar({ x: \"\", y: 0 }); bar({ x: \"\", y: 0 });
var spread = { y: \"\" }; var spread = { y: \"\" };
var extend: { x: number, y: string, z: boolean } = { x: 0, ...spread }; var extend: { x: number, y: string, z: boolean } = { x: 0, ...spread };
function qux(_: { a: number }) {} function qux(_: { a: number }) {}
qux({ a: \"\" }); qux({ a: \"\" });
function corge({ b }: { b: string }) {} function corge({ b }: { b: string }) {}
corge({ b: 0 }); corge({ b: 0 });
var { n }: { n: number } = { n: \"\" }; var { n }: { n: number } = { n: \"\" };
function test() { function test() {
var { foo } = { bar: 123 }; var { foo } = { bar: 123 };
var { bar, baz } = { bar: 123 }; var { bar, baz } = { bar: 123 };
} }
function test() { function test() {
var x = { foo: \"abc\", bar: 123 }; var x = { foo: \"abc\", bar: 123 };
var { foo, ...rest } = x; var { foo, ...rest } = x;
(x.baz: string); (x.baz: string);
(rest.baz: string); (rest.baz: string);
} }
module.exports = corge; module.exports = corge;
class Base { class Base {
baseprop1: number; baseprop1: number;
baseprop2: number; baseprop2: number;
@ -463,7 +398,6 @@ exports[`test eager.js 1`] = `
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// error, property \`x\` can not be accessed on \`null\` // error, property \`x\` can not be accessed on \`null\`
var x; var x;
({ x } = null); ({ x } = null);
" "
`; `;
@ -516,43 +450,27 @@ function arr_rest_pattern<X>([ _, ...a ] : ArrRest<X>) { // a: [X]
// a: [X] // a: [X]
// a: [X] // a: [X]
function obj_pattern<X>({ prop }: { prop: X }) {} function obj_pattern<X>({ prop }: { prop: X }) {}
type Prop<X> = { prop: X }; type Prop<X> = { prop: X };
function obj_pattern2<X>({ prop }: Prop<X>) {} function obj_pattern2<X>({ prop }: Prop<X>) {}
function arr_pattern<X>([ elem ]: X[]) {} function arr_pattern<X>([ elem ]: X[]) {}
type Elem<X> = X[]; type Elem<X> = X[];
function arr_pattern2<X>([ elem ]: Elem<X>) {} function arr_pattern2<X>([ elem ]: Elem<X>) {}
function tup_pattern<X>([ proj ]: [X]) {} function tup_pattern<X>([ proj ]: [X]) {}
type Proj<X> = [X]; type Proj<X> = [X];
function tup_pattern2<X>([ proj ]: Proj<X>) {} function tup_pattern2<X>([ proj ]: Proj<X>) {}
function rest_antipattern<T>(...t: T) {} function rest_antipattern<T>(...t: T) {}
function rest_pattern<X>(...r: X[]) {} function rest_pattern<X>(...r: X[]) {}
function obj_rest_pattern<X>({ _, ...o }: { _: any, x: X }) { function obj_rest_pattern<X>({ _, ...o }: { _: any, x: X }) {
o.x; o.x;
} }
type ObjRest<X> = { _: any, x: X }; type ObjRest<X> = { _: any, x: X };
function obj_rest_pattern<X>({ _, ...o }: ObjRest<X>) { function obj_rest_pattern<X>({ _, ...o }: ObjRest<X>) {
o.x; o.x;
} }
function arr_rest_pattern<X>([ _, ...a ]: [any, X]) { function arr_rest_pattern<X>([ _, ...a ]: [any, X]) {
a[0]; a[0];
} }
type ArrRest<X> = [any, X]; type ArrRest<X> = [any, X];
function arr_rest_pattern<X>([ _, ...a ]: ArrRest<X>) { function arr_rest_pattern<X>([ _, ...a ]: ArrRest<X>) {
a[0]; a[0];
} }
@ -588,14 +506,11 @@ var { x: o } = o;
let foo = (i: number) => [ i ]; let foo = (i: number) => [ i ];
const bar = (i: number) => { const bar = (i: number) => {
[ i ] = foo(i); [ i ] = foo(i);
return [ i ]; return [ i ];
}; };
foo = (i: number) => { foo = (i: number) => {
return bar(i); return bar(i);
}; };
declare var o; declare var o;
var { x: o } = o; var { x: o } = o;
" "
@ -611,11 +526,8 @@ var { \"with-dash\": with_dash } = { \"with-dash\": \"motivating example\" };
// error: string ~> void // error: string ~> void
// ok // ok
var { \"key\": val } = { key: \"val\" }; var { \"key\": val } = { key: \"val\" };
(val: void); (val: void);
var { \"with-dash\": with_dash } = { \"with-dash\": \"motivating example\" }; var { \"with-dash\": with_dash } = { \"with-dash\": \"motivating example\" };
(with_dash: \"motivating example\"); (with_dash: \"motivating example\");
" "
`; `;
@ -633,7 +545,6 @@ function bar() {
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// @flow // @flow
var { x } = { x: { foo: \"foo\" } }; var { x } = { x: { foo: \"foo\" } };
function bar() { function bar() {
x.bar; x.bar;
} }

View File

@ -38,10 +38,8 @@ function foo0(
x: Array<{ [key: string]: mixed }> x: Array<{ [key: string]: mixed }>
): Array<{ [key: string]: mixed }> { ): Array<{ [key: string]: mixed }> {
x[0].fooBar = \"foobar\"; x[0].fooBar = \"foobar\";
return x; return x;
} }
function foo2( function foo2(
x: { [key: string]: number } x: { [key: string]: number }
): { [key: string]: number, +toString: () => string } { ): { [key: string]: number, +toString: () => string } {
@ -504,231 +502,167 @@ class B extends A {}
class C extends B {} class C extends B {}
class X {} class X {}
class Y {} class Y {}
function set_prop_to_string_key(o: { [k: string]: any }) { function set_prop_to_string_key(o: { [k: string]: any }) {
o.prop = \"ok\"; o.prop = \"ok\";
} }
function unsound_dict_has_every_key(o: { [k: string]: X }) { function unsound_dict_has_every_key(o: { [k: string]: X }) {
(o.p: X); (o.p: X);
(o[\"p\"]: X); (o[\"p\"]: X);
} }
function set_prop_covariant(o: { [k: string]: B }) { function set_prop_covariant(o: { [k: string]: B }) {
o.p = new A(); o.p = new A();
o.p = new B(); o.p = new B();
o.p = new C(); o.p = new C();
} }
function get_prop_contravariant(o: { [k: string]: B }) { function get_prop_contravariant(o: { [k: string]: B }) {
(o.p: A); (o.p: A);
(o.p: B); (o.p: B);
(o.p: C); (o.p: C);
} }
function add_prop_to_nonstring_key_dot(o: { [k: number]: any }) { function add_prop_to_nonstring_key_dot(o: { [k: number]: any }) {
o.prop = \"err\"; o.prop = \"err\";
} }
function add_prop_to_nonstring_key_bracket(o: { [k: number]: any }) { function add_prop_to_nonstring_key_bracket(o: { [k: number]: any }) {
o[0] = \"ok\"; o[0] = \"ok\";
} }
function mix_with_declared_props(o: { [k: number]: X, p: Y }, x: X, y: Y) { function mix_with_declared_props(o: { [k: number]: X, p: Y }, x: X, y: Y) {
(o[0]: X); (o[0]: X);
(o.p: Y); (o.p: Y);
o[0] = x; o[0] = x;
o.p = y; o.p = y;
} }
function object_prototype( function object_prototype(
o: { [k: string]: number } o: { [k: string]: number }
): { [k: string]: number, +toString: () => string } { ): { [k: string]: number, +toString: () => string } {
(o.toString(): boolean); (o.toString(): boolean);
return o; return o;
} }
function unsound_string_conversion_alias_declared_prop( function unsound_string_conversion_alias_declared_prop(
o: { [k: number]: any, \"0\": X } o: { [k: number]: any, \"0\": X }
) { ) {
o[0] = \"not-x\"; o[0] = \"not-x\";
} }
function unification_dict_values_invariant(x: Array<{ [k: string]: B }>) { function unification_dict_values_invariant(x: Array<{ [k: string]: B }>) {
let a: Array<{ [k: string]: A }> = x; let a: Array<{ [k: string]: A }> = x;
a[0].p = new A(); a[0].p = new A();
let b: Array<{ [k: string]: B }> = x; let b: Array<{ [k: string]: B }> = x;
let c: Array<{ [k: string]: C }> = x; let c: Array<{ [k: string]: C }> = x;
(x[0].p: C); (x[0].p: C);
} }
function subtype_dict_values_invariant(x: { [k: string]: B }) { function subtype_dict_values_invariant(x: { [k: string]: B }) {
let a: { [k: string]: A } = x; let a: { [k: string]: A } = x;
a.p = new A(); a.p = new A();
let b: { [k: string]: B } = x; let b: { [k: string]: B } = x;
let c: { [k: string]: C } = x; let c: { [k: string]: C } = x;
(x.p: C); (x.p: C);
} }
function subtype_dict_values_fresh_exception() { function subtype_dict_values_fresh_exception() {
let a: { [k: string]: A } = { a: new A(), b: new B(), c: new C() }; 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 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() }; let c: { [k: string]: C } = { a: new A(), b: new B(), c: new C() };
} }
function unification_dict_keys_invariant(x: Array<{ [k: B]: any }>) { function unification_dict_keys_invariant(x: Array<{ [k: B]: any }>) {
let a: Array<{ [k: A]: any }> = x; let a: Array<{ [k: A]: any }> = x;
let b: Array<{ [k: B]: any }> = x; let b: Array<{ [k: B]: any }> = x;
let c: Array<{ [k: C]: any }> = x; let c: Array<{ [k: C]: any }> = x;
} }
function subtype_dict_keys_invariant(x: { [k: B]: any }) { function subtype_dict_keys_invariant(x: { [k: B]: any }) {
let a: { [k: A]: any } = x; let a: { [k: A]: any } = x;
let b: { [k: B]: any } = x; let b: { [k: B]: any } = x;
let c: { [k: C]: any } = x; let c: { [k: C]: any } = x;
} }
function unification_mix_with_declared_props_invariant_l( function unification_mix_with_declared_props_invariant_l(
x: Array<{ [k: string]: B }> x: Array<{ [k: string]: B }>
) { ) {
let a: Array<{ [k: string]: B, p: A }> = x; let a: Array<{ [k: string]: B, p: A }> = x;
a[0].p = new A(); a[0].p = new A();
let b: Array<{ [k: string]: B, p: B }> = x; let b: Array<{ [k: string]: B, p: B }> = x;
let c: Array<{ [k: string]: B, p: C }> = x; let c: Array<{ [k: string]: B, p: C }> = x;
(x[0].p: C); (x[0].p: C);
} }
function unification_mix_with_declared_props_invariant_r( function unification_mix_with_declared_props_invariant_r(
xa: Array<{ [k: string]: A, p: B }>, xa: Array<{ [k: string]: A, p: B }>,
xb: Array<{ [k: string]: B, p: B }>, xb: Array<{ [k: string]: B, p: B }>,
xc: Array<{ [k: string]: C, p: B }> xc: Array<{ [k: string]: C, p: B }>
) { ) {
let a: Array<{ [k: string]: A }> = xa; let a: Array<{ [k: string]: A }> = xa;
a[0].p = new A(); a[0].p = new A();
let b: Array<{ [k: string]: B }> = xb; let b: Array<{ [k: string]: B }> = xb;
let c: Array<{ [k: string]: C }> = xc; let c: Array<{ [k: string]: C }> = xc;
(xc[0].p: C); (xc[0].p: C);
} }
function subtype_mix_with_declared_props_invariant_l(x: { [k: string]: B }) { function subtype_mix_with_declared_props_invariant_l(x: { [k: string]: B }) {
let a: { [k: string]: B, p: A } = x; let a: { [k: string]: B, p: A } = x;
a.p = new A(); a.p = new A();
let b: { [k: string]: B, p: B } = x; let b: { [k: string]: B, p: B } = x;
let c: { [k: string]: B, p: C } = x; let c: { [k: string]: B, p: C } = x;
(x.p: C); (x.p: C);
} }
function subtype_mix_with_declared_props_invariant_r( function subtype_mix_with_declared_props_invariant_r(
xa: { [k: string]: A, p: B }, xa: { [k: string]: A, p: B },
xb: { [k: string]: B, p: B }, xb: { [k: string]: B, p: B },
xc: { [k: string]: C, p: B } xc: { [k: string]: C, p: B }
) { ) {
let a: { [k: string]: A } = xa; let a: { [k: string]: A } = xa;
a.p = new A(); a.p = new A();
let b: { [k: string]: B } = xb; let b: { [k: string]: B } = xb;
let c: { [k: string]: C } = xc; let c: { [k: string]: C } = xc;
(xc.p: C); (xc.p: C);
} }
function unification_dict_to_obj( function unification_dict_to_obj(
x: Array<{ [k: string]: X }> x: Array<{ [k: string]: X }>
): Array<{ p: X }> { ): Array<{ p: X }> {
return x; return x;
} }
function unification_obj_to_dict( function unification_obj_to_dict(
x: Array<{ p: X }> x: Array<{ p: X }>
): Array<{ [k: string]: X }> { ): Array<{ [k: string]: X }> {
return x; return x;
} }
function subtype_dict_to_obj(x: { [k: string]: B }) { function subtype_dict_to_obj(x: { [k: string]: B }) {
let a: { p: A } = x; let a: { p: A } = x;
a.p = new A(); a.p = new A();
let b: { p: B } = x; let b: { p: B } = x;
let c: { p: C } = x; let c: { p: C } = x;
(x.p: C); (x.p: C);
} }
function subtype_obj_to_dict(x: { p: B }) { function subtype_obj_to_dict(x: { p: B }) {
let a: { [k: string]: A } = x; let a: { [k: string]: A } = x;
a.p = new A(); a.p = new A();
let b: { [k: string]: B } = x; let b: { [k: string]: B } = x;
let c: { [k: string]: C } = x; let c: { [k: string]: C } = x;
(x.p: C); (x.p: C);
} }
function subtype_obj_to_mixed(x: { p: B, x: X }) { function subtype_obj_to_mixed(x: { p: B, x: X }) {
let a: { [k: string]: A, x: X } = x; let a: { [k: string]: A, x: X } = x;
let b: { [k: string]: B, x: X } = x; let b: { [k: string]: B, x: X } = x;
let c: { [k: string]: C, x: X } = x; let c: { [k: string]: C, x: X } = x;
} }
function unification_dict_to_mixed(x: Array<{ [k: string]: B }>) { function unification_dict_to_mixed(x: Array<{ [k: string]: B }>) {
let a: Array<{ [k: string]: B, p: A }> = x; let a: Array<{ [k: string]: B, p: A }> = x;
let b: Array<{ [k: string]: B, p: B }> = x; let b: Array<{ [k: string]: B, p: B }> = x;
let c: Array<{ [k: string]: B, p: C }> = x; let c: Array<{ [k: string]: B, p: C }> = x;
} }
function subtype_dict_to_mixed(x: { [k: string]: B }) { function subtype_dict_to_mixed(x: { [k: string]: B }) {
let a: { [k: string]: B, p: A } = x; let a: { [k: string]: B, p: A } = x;
let b: { [k: string]: B, p: B } = x; let b: { [k: string]: B, p: B } = x;
let c: { [k: string]: B, p: C } = x; let c: { [k: string]: B, p: C } = x;
} }
function subtype_dict_to_optional_a(x: { [k: string]: B }) { function subtype_dict_to_optional_a(x: { [k: string]: B }) {
let a: { p?: A } = x; let a: { p?: A } = x;
} }
function subtype_dict_to_optional_b(x: { [k: string]: B }) { function subtype_dict_to_optional_b(x: { [k: string]: B }) {
let b: { p?: B } = x; let b: { p?: B } = x;
} }
function subtype_dict_to_optional_c(x: { [k: string]: B }) { function subtype_dict_to_optional_c(x: { [k: string]: B }) {
let c: { p?: C } = x; let c: { p?: C } = x;
} }
function subtype_optional_a_to_dict(x: { p?: A }): { [k: string]: B } { function subtype_optional_a_to_dict(x: { p?: A }): { [k: string]: B } {
return x; return x;
} }
function subtype_optional_b_to_dict(x: { p?: B }): { [k: string]: B } { function subtype_optional_b_to_dict(x: { p?: B }): { [k: string]: B } {
return x; return x;
} }
function subtype_optional_c_to_dict(x: { p?: C }): { [k: string]: B } { function subtype_optional_c_to_dict(x: { p?: C }): { [k: string]: B } {
return x; return x;
} }
@ -814,52 +748,41 @@ var z: { [key: number]: string } = x;
var a: { [key: string]: ?string } = {}; var a: { [key: string]: ?string } = {};
var b: { [key: string]: string } = a; var b: { [key: string]: string } = a;
var c: { [key: string]: ?string } = b; var c: { [key: string]: ?string } = b;
function foo0( function foo0(
x: Array<{ [key: string]: number }> x: Array<{ [key: string]: number }>
): Array<{ [key: string]: string }> { ): Array<{ [key: string]: string }> {
return x; return x;
} }
function foo1( function foo1(
x: Array<{ [key: string]: number }> x: Array<{ [key: string]: number }>
): Array<{ [key: string]: number, fooBar: string }> { ): Array<{ [key: string]: number, fooBar: string }> {
return x; return x;
} }
function foo2( function foo2(
x: Array<{ [key: string]: mixed }> x: Array<{ [key: string]: mixed }>
): Array<{ [key: string]: mixed, fooBar: string }> { ): Array<{ [key: string]: mixed, fooBar: string }> {
x[0].fooBar = 123; x[0].fooBar = 123;
return x; return x;
} }
function foo3(x: { [key: string]: number }): { foo: number } { function foo3(x: { [key: string]: number }): { foo: number } {
return x; return x;
} }
function foo4( function foo4(
x: { [key: string]: number } x: { [key: string]: number }
): { [key: string]: number, foo: string } { ): { [key: string]: number, foo: string } {
return x; return x;
} }
function foo5(x: Array<{ [key: string]: number }>): Array<{ foo: number }> { function foo5(x: Array<{ [key: string]: number }>): Array<{ foo: number }> {
return x; return x;
} }
function foo6(x: Array<{ foo: number }>): Array<{ [key: string]: number }> { function foo6(x: Array<{ foo: number }>): Array<{ [key: string]: number }> {
return x; return x;
} }
function foo7(x: { [key: string]: number, bar: string }) { function foo7(x: { [key: string]: number, bar: string }) {
(x.bar: string); (x.bar: string);
} }
function foo8(x: { [key: string]: number }) { function foo8(x: { [key: string]: number }) {
(x.foo: string); (x.foo: string);
(x.foo: number); (x.foo: number);
} }
" "
@ -938,7 +861,6 @@ var o: { foo: QueryFunction } = {
return params.count; return params.count;
} }
}; };
module.exports = o; module.exports = o;
" "
`; `;
@ -952,7 +874,6 @@ o.foo = function (params) {
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// error, number ~/~ string // error, number ~/~ string
var o = require(\"./test\"); var o = require(\"./test\");
o.foo = function(params) { o.foo = function(params) {
return params.count; return params.count;
}; };

View File

@ -224,7 +224,6 @@ export function emitExpression(node: TypedNode) : t.Expression {
import * as t from \"./jsAst\"; import * as t from \"./jsAst\";
const b = t.builders; const b = t.builders;
import type {TypedNode} from \"./ast\"; import type {TypedNode} from \"./ast\";
function getBinaryOp( function getBinaryOp(
op: \"plus\" | \"minus\" | \"divide\" | \"multiply\" op: \"plus\" | \"minus\" | \"divide\" | \"multiply\"
): \"+\" | \"-\" | \"*\" | \"/\" { ): \"+\" | \"-\" | \"*\" | \"/\" {
@ -241,7 +240,6 @@ function getBinaryOp(
throw new Error(\"Invalid binary operator: \" + op); throw new Error(\"Invalid binary operator: \" + op);
} }
} }
export function emitExpression(node: TypedNode): t.Expression { export function emitExpression(node: TypedNode): t.Expression {
switch (node.exprNodeType) { switch (node.exprNodeType) {
case \"string_literal\": case \"string_literal\":

View File

@ -102,7 +102,6 @@ exports[`test use_strict_with_flow.js 1`] = `
/* @flow */ /* @flow */
// error // error
\"use strict\"; \"use strict\";
(\"\": void); (\"\": void);
" "
`; `;

View File

@ -44,7 +44,6 @@ let tests = [
let tests = [ let tests = [
function(document: Document) { function(document: Document) {
const event = document.createEvent(\"CustomEvent\"); const event = document.createEvent(\"CustomEvent\");
event.initCustomEvent(\"butts\", true, false, { nice: 42 }); event.initCustomEvent(\"butts\", true, false, { nice: 42 });
} }
]; ];
@ -69,11 +68,8 @@ let tests = [
let tests = [ let tests = [
function(document: Document) { function(document: Document) {
(document.createElement(\"canvas\"): HTMLCanvasElement); (document.createElement(\"canvas\"): HTMLCanvasElement);
(document.createElement(\"link\"): HTMLLinkElement); (document.createElement(\"link\"): HTMLLinkElement);
(document.createElement(\"option\"): HTMLOptionElement); (document.createElement(\"option\"): HTMLOptionElement);
(document.createElement(\"select\"): HTMLSelectElement); (document.createElement(\"select\"): HTMLSelectElement);
} }
]; ];
@ -106,21 +102,13 @@ let tests = [
let tests = [ let tests = [
function(element: Element) { function(element: Element) {
element.scrollIntoView(); element.scrollIntoView();
element.scrollIntoView(false); element.scrollIntoView(false);
element.scrollIntoView({}); element.scrollIntoView({});
element.scrollIntoView({ behavior: \"smooth\", block: \"end\" }); element.scrollIntoView({ behavior: \"smooth\", block: \"end\" });
element.scrollIntoView({ block: \"end\" }); element.scrollIntoView({ block: \"end\" });
element.scrollIntoView({ behavior: \"smooth\" }); element.scrollIntoView({ behavior: \"smooth\" });
element.scrollIntoView({ behavior: \"invalid\" }); element.scrollIntoView({ behavior: \"invalid\" });
element.scrollIntoView({ block: \"invalid\" }); element.scrollIntoView({ block: \"invalid\" });
element.scrollIntoView(1); element.scrollIntoView(1);
} }
]; ];
@ -173,21 +161,13 @@ let tests = [
let tests = [ let tests = [
function(element: HTMLElement) { function(element: HTMLElement) {
element.scrollIntoView(); element.scrollIntoView();
element.scrollIntoView(false); element.scrollIntoView(false);
element.scrollIntoView({}); element.scrollIntoView({});
element.scrollIntoView({ behavior: \"smooth\", block: \"end\" }); element.scrollIntoView({ behavior: \"smooth\", block: \"end\" });
element.scrollIntoView({ block: \"end\" }); element.scrollIntoView({ block: \"end\" });
element.scrollIntoView({ behavior: \"smooth\" }); element.scrollIntoView({ behavior: \"smooth\" });
element.scrollIntoView({ behavior: \"invalid\" }); element.scrollIntoView({ behavior: \"invalid\" });
element.scrollIntoView({ block: \"invalid\" }); element.scrollIntoView({ block: \"invalid\" });
element.scrollIntoView(1); element.scrollIntoView(1);
} }
]; ];
@ -215,13 +195,9 @@ let tests = [
let tests = [ let tests = [
function(el: HTMLInputElement) { function(el: HTMLInputElement) {
el.setRangeText(\"foo\"); el.setRangeText(\"foo\");
el.setRangeText(\"foo\", 123); el.setRangeText(\"foo\", 123);
el.setRangeText(\"foo\", 123, 234); el.setRangeText(\"foo\", 123, 234);
el.setRangeText(\"foo\", 123, 234, \"select\"); el.setRangeText(\"foo\", 123, 234, \"select\");
el.setRangeText(\"foo\", 123, 234, \"bogus\"); el.setRangeText(\"foo\", 123, 234, \"bogus\");
} }
]; ];
@ -326,16 +302,12 @@ let listener: EventListener = function(event: Event): void {};
let tests = [ let tests = [
function() { function() {
let target = new EventTarget(); let target = new EventTarget();
(target.attachEvent(\"foo\", listener): void); (target.attachEvent(\"foo\", listener): void);
(target.attachEvent && target.attachEvent(\"foo\", listener): void); (target.attachEvent && target.attachEvent(\"foo\", listener): void);
}, },
function() { function() {
let target = new EventTarget(); let target = new EventTarget();
(target.detachEvent(\"foo\", listener): void); (target.detachEvent(\"foo\", listener): void);
(target.detachEvent && target.detachEvent(\"foo\", listener): void); (target.detachEvent && target.detachEvent(\"foo\", listener): void);
}, },
function() { function() {
@ -368,11 +340,8 @@ let tests = [
let tests = [ let tests = [
function() { function() {
let path = new Path2D(); let path = new Path2D();
(path.arcTo(0, 0, 0, 0, 10): void); (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);
(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() { function() {
document.createNodeIterator(document.body); document.createNodeIterator(document.body);
document.createNodeIterator({}); document.createNodeIterator({});
}, },
function() { function() {
document.createTreeWalker(document.body); document.createTreeWalker(document.body);
document.createTreeWalker({}); document.createTreeWalker({});
}, },
function() { function() {
@ -893,17 +860,13 @@ let tests = [
-1, -1,
node => NodeFilter.FILTER_ACCEPT node => NodeFilter.FILTER_ACCEPT
); );
document.createNodeIterator(document.body, -1, node => \"accept\"); document.createNodeIterator(document.body, -1, node => \"accept\");
document.createNodeIterator(document.body, -1, { document.createNodeIterator(document.body, -1, {
accept: node => NodeFilter.FILTER_ACCEPT accept: node => NodeFilter.FILTER_ACCEPT
}); });
document.createNodeIterator(document.body, -1, { document.createNodeIterator(document.body, -1, {
accept: node => \"accept\" accept: node => \"accept\"
}); });
document.createNodeIterator(document.body, -1, {}); document.createNodeIterator(document.body, -1, {});
}, },
function() { function() {
@ -912,15 +875,11 @@ let tests = [
-1, -1,
node => NodeFilter.FILTER_ACCEPT node => NodeFilter.FILTER_ACCEPT
); );
document.createTreeWalker(document.body, -1, node => \"accept\"); document.createTreeWalker(document.body, -1, node => \"accept\");
document.createTreeWalker(document.body, -1, { document.createTreeWalker(document.body, -1, {
accept: node => NodeFilter.FILTER_ACCEPT accept: node => NodeFilter.FILTER_ACCEPT
}); });
document.createTreeWalker(document.body, -1, { accept: node => \"accept\" }); document.createTreeWalker(document.body, -1, { accept: node => \"accept\" });
document.createTreeWalker(document.body, -1, {}); document.createTreeWalker(document.body, -1, {});
} }
]; ];

View File

@ -7,11 +7,8 @@ module.exports = num;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// @flow // @flow
var num = 42; var num = 42;
function bar() {} function bar() {}
bar(); bar();
module.exports = num; module.exports = num;
" "
`; `;
@ -42,35 +39,25 @@ const idxResult = idx(obj, obj => obj.a.b.c.d);
// @flow // @flow
// test deduping of inferred types // test deduping of inferred types
var num = require(\"./import\"); var num = require(\"./import\");
function foo(x) {} function foo(x) {}
foo(0); foo(0);
var a: string = num; var a: string = num;
function unannotated(x) { function unannotated(x) {
return x; return x;
} }
const nullToUndefined = val => val === null ? undefined : val; const nullToUndefined = val => val === null ? undefined : val;
function f0(x: ?Object) { function f0(x: ?Object) {
return nullToUndefined(x); return nullToUndefined(x);
} }
function f1(x: ?Object) { function f1(x: ?Object) {
return nullToUndefined(x); return nullToUndefined(x);
} }
function f2(x: ?string) { function f2(x: ?string) {
return nullToUndefined(x); return nullToUndefined(x);
} }
function f3(x: ?string) { function f3(x: ?string) {
return nullToUndefined(x); return nullToUndefined(x);
} }
declare var idx: $Facebookism$Idx; declare var idx: $Facebookism$Idx;
declare var obj: { a?: { b: ?{ c: null | { d: number } } } }; declare var obj: { a?: { b: ?{ c: null | { d: number } } } };
const idxResult = idx(obj, obj => obj.a.b.c.d); const idxResult = idx(obj, obj => obj.a.b.c.d);

View File

@ -39,34 +39,26 @@ class C1 {
m() {} m() {}
m() {} m() {}
} }
new C1().m(); new C1().m();
class C2 { class C2 {
get m() { get m() {
return 42; return 42;
} }
m() {} m() {}
} }
new C2().m(); new C2().m();
class C3 { class C3 {
set m(x) {} set m(x) {}
m() {} m() {}
} }
new C3().m(); new C3().m();
class C4 { class C4 {
get m() { get m() {
return 42; return 42;
} }
set m(x: number) {} set m(x: number) {}
} }
new C4().m = new C4().m - 42; new C4().m = new C4().m - 42;
class C5 { class C5 {
m() {} m() {}
get m() { get m() {
@ -74,7 +66,6 @@ class C5 {
} }
set m(x: number) {} set m(x: number) {}
} }
new C5().m = new C5().m - 42; new C5().m = new C5().m - 42;
" "
`; `;

View File

@ -23,20 +23,15 @@ var s3 = tag2 \`la la la\`;
class A {} class A {}
var a = new A(); var a = new A();
var s1 = \`l\${a.x}r\`; var s1 = \`l\${a.x}r\`;
function tag(strings, ...values) { function tag(strings, ...values) {
var x: number = strings[0]; var x: number = strings[0];
return x; return x;
} }
var s2 = tag\`l\${42}r\`; var s2 = tag\`l\${42}r\`;
function tag2(strings, ...values) { function tag2(strings, ...values) {
return { foo: \"\" }; return { foo: \"\" };
} }
var s3 = tag2\`la la la\`; var s3 = tag2\`la la la\`;
(s3.foo: number); (s3.foo: number);
" "
`; `;

View File

@ -34,24 +34,17 @@ function isActive(
): boolean { ): boolean {
return ad.state === \"ACTIVE\"; return ad.state === \"ACTIVE\";
} }
isActive({ state: \"PAUSE\" }); isActive({ state: \"PAUSE\" });
var MyStates = { PAUSED: \"PAUSED\", ACTIVE: \"ACTIVE\", DELETED: \"DELETED\" }; var MyStates = { PAUSED: \"PAUSED\", ACTIVE: \"ACTIVE\", DELETED: \"DELETED\" };
function isActive2(ad: { state: $Keys<typeof MyStates> }): boolean { function isActive2(ad: { state: $Keys<typeof MyStates> }): boolean {
return ad.state === MyStates.ACTIVE; return ad.state === MyStates.ACTIVE;
} }
isActive2({ state: \"PAUSE\" }); isActive2({ state: \"PAUSE\" });
type Keys = $Keys<{ x: any, y: any }>; type Keys = $Keys<{ x: any, y: any }>;
type Union = \"x\" | \"y\"; type Union = \"x\" | \"y\";
function keys2union(s: Keys): Union { function keys2union(s: Keys): Union {
return s; return s;
} }
function union2keys(s: Union): Keys { function union2keys(s: Union): Keys {
return s; return s;
} }

View File

@ -16,21 +16,13 @@ var x = (null : ?number);
// error // error
// error // error
1 == 1; 1 == 1;
\"foo\" == \"bar\"; \"foo\" == \"bar\";
1 == null; 1 == null;
null == 1; null == 1;
1 == \"\"; 1 == \"\";
\"\" == 1; \"\" == 1;
var x = (null: ?number); var x = (null: ?number);
x == 1; x == 1;
1 == x; 1 == x;
" "
`; `;

View File

@ -64,7 +64,6 @@ class Test extends Base {
return 2; return 2;
} }
} }
module.exports = Test; module.exports = Test;
" "
`; `;
@ -132,13 +131,9 @@ exports.numberValue5 = 5;
* @flow * @flow
*/ */
exports.numberValue1 = 1; exports.numberValue1 = 1;
exports.numberValue2 = 2; exports.numberValue2 = 2;
exports.numberValue3 = 3; exports.numberValue3 = 3;
exports.numberValue4 = 4; exports.numberValue4 = 4;
exports.numberValue5 = 5; exports.numberValue5 = 5;
" "
`; `;
@ -244,7 +239,6 @@ export default class Foo {
return 42; return 42;
} }
} }
new Foo(); new Foo();
" "
`; `;
@ -588,13 +582,9 @@ exports.stringValue = \"str\";
* @flow * @flow
*/ */
exports.numberValue1 = 42; exports.numberValue1 = 42;
exports.numberValue2 = 42; exports.numberValue2 = 42;
exports.numberValue3 = 42; exports.numberValue3 = 42;
exports.numberValue4 = 42; exports.numberValue4 = 42;
exports.stringValue = \"str\"; exports.stringValue = \"str\";
" "
`; `;
@ -1100,33 +1090,24 @@ var d2: string = numVal1;
import CJS_Clobb_Lit from \"CommonJS_Clobbering_Lit\"; import CJS_Clobb_Lit from \"CommonJS_Clobbering_Lit\";
var e1: number = CJS_Clobb_Lit.numberValue3; var e1: number = CJS_Clobb_Lit.numberValue3;
var e2: string = CJS_Clobb_Lit.numberValue3; var e2: string = CJS_Clobb_Lit.numberValue3;
CJS_Clobb_Lit.doesntExist; CJS_Clobb_Lit.doesntExist;
import * as CJS_Clobb_Lit_NS from \"CommonJS_Clobbering_Lit\"; import * as CJS_Clobb_Lit_NS from \"CommonJS_Clobbering_Lit\";
var f1: number = CJS_Clobb_Lit_NS.numberValue4; var f1: number = CJS_Clobb_Lit_NS.numberValue4;
var f2: number = CJS_Clobb_Lit_NS.default.numberValue4; var f2: number = CJS_Clobb_Lit_NS.default.numberValue4;
CJS_Clobb_Lit_NS.default.default; CJS_Clobb_Lit_NS.default.default;
var f3: string = CJS_Clobb_Lit_NS.numberValue4; var f3: string = CJS_Clobb_Lit_NS.numberValue4;
var f4: string = CJS_Clobb_Lit_NS.default.numberValue5; var f4: string = CJS_Clobb_Lit_NS.default.numberValue5;
import {doesntExist2} from \"CommonJS_Clobbering_Class\"; import {doesntExist2} from \"CommonJS_Clobbering_Class\";
import {staticNumber1, baseProp, childProp} from \"CommonJS_Clobbering_Class\"; import {staticNumber1, baseProp, childProp} from \"CommonJS_Clobbering_Class\";
import CJS_Clobb_Class from \"CommonJS_Clobbering_Class\"; import CJS_Clobb_Class from \"CommonJS_Clobbering_Class\";
new CJS_Clobb_Class(); new CJS_Clobb_Class();
new CJS_Clobb_Class().doesntExist; new CJS_Clobb_Class().doesntExist;
var h1: number = CJS_Clobb_Class.staticNumber2(); var h1: number = CJS_Clobb_Class.staticNumber2();
var h2: string = CJS_Clobb_Class.staticNumber2(); var h2: string = CJS_Clobb_Class.staticNumber2();
var h3: number = new CJS_Clobb_Class().instNumber1(); var h3: number = new CJS_Clobb_Class().instNumber1();
var h4: string = new CJS_Clobb_Class().instNumber1(); var h4: string = new CJS_Clobb_Class().instNumber1();
import * as CJS_Clobb_Class_NS from \"CommonJS_Clobbering_Class\"; import * as CJS_Clobb_Class_NS from \"CommonJS_Clobbering_Class\";
new CJS_Clobb_Class_NS(); new CJS_Clobb_Class_NS();
var i1: number = CJS_Clobb_Class_NS.staticNumber3(); var i1: number = CJS_Clobb_Class_NS.staticNumber3();
var i2: number = new CJS_Clobb_Class_NS.default().instNumber2(); var i2: number = new CJS_Clobb_Class_NS.default().instNumber2();
var i3: string = 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\"; import * as CJS_Named from \"CommonJS_Named\";
var l1: number = CJS_Named.numberValue1; var l1: number = CJS_Named.numberValue1;
var l2: string = CJS_Named.numberValue1; var l2: string = CJS_Named.numberValue1;
CJS_Named.doesntExist; CJS_Named.doesntExist;
import * as CJS_Named_NS from \"CommonJS_Named\"; import * as CJS_Named_NS from \"CommonJS_Named\";
var m1: number = CJS_Named_NS.numberValue4; var m1: number = CJS_Named_NS.numberValue4;
var m2: string = CJS_Named_NS.default.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\"; import {numberValue1 as numberValue5} from \"ES6_ExportAllFrom_Intermediary1\";
var ac1: number = numberValue5; var ac1: number = numberValue5;
var ac2: string = numberValue5; var ac2: string = numberValue5;
require(\"ES6_Default_AnonFunction2\").doesntExist; require(\"ES6_Default_AnonFunction2\").doesntExist;
var ES6_Def_AnonFunc2 = require(\"ES6_Default_AnonFunction2\").default; var ES6_Def_AnonFunc2 = require(\"ES6_Default_AnonFunction2\").default;
var ad1: number = ES6_Def_AnonFunc2(); var ad1: number = ES6_Def_AnonFunc2();
var ad2: string = 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 // CommonJS module that clobbers module.exports with a frozen object
// Error: frozen // Error: frozen
import * as DefaultA from \"A\"; import * as DefaultA from \"A\";
DefaultA.numberValue1 = 123; DefaultA.numberValue1 = 123;
import * as ES6_Named1 from \"ES6_Named1\"; import * as ES6_Named1 from \"ES6_Named1\";
ES6_Named1.varDeclNumber1 = 123; ES6_Named1.varDeclNumber1 = 123;
import * as CommonJS_Star from \"CommonJS_Clobbering_Lit\"; import * as CommonJS_Star from \"CommonJS_Clobbering_Lit\";
CommonJS_Star.numberValue1 = 123; CommonJS_Star.numberValue1 = 123;
CommonJS_Star.default.numberValue1 = 123; CommonJS_Star.default.numberValue1 = 123;
import CommonJS_Clobbering_Lit from \"CommonJS_Clobbering_Lit\"; import CommonJS_Clobbering_Lit from \"CommonJS_Clobbering_Lit\";
CommonJS_Clobbering_Lit.numberValue1 = 123; CommonJS_Clobbering_Lit.numberValue1 = 123;
import * as CommonJS_Frozen_Star from \"CommonJS_Clobbering_Frozen\"; import * as CommonJS_Frozen_Star from \"CommonJS_Clobbering_Frozen\";
CommonJS_Frozen_Star.numberValue1 = 123; CommonJS_Frozen_Star.numberValue1 = 123;
CommonJS_Frozen_Star.default.numberValue1 = 123; CommonJS_Frozen_Star.default.numberValue1 = 123;
import CommonJS_Clobbering_Frozen from \"CommonJS_Clobbering_Frozen\"; import CommonJS_Clobbering_Frozen from \"CommonJS_Clobbering_Frozen\";
CommonJS_Clobbering_Frozen.numberValue1 = 123; CommonJS_Clobbering_Frozen.numberValue1 = 123;
function testRequires() { function testRequires() {
var DefaultA = require(\"A\"); var DefaultA = require(\"A\");
DefaultA.numberValue1 = 123; DefaultA.numberValue1 = 123;
var ES6_Named1 = require(\"ES6_Named1\"); var ES6_Named1 = require(\"ES6_Named1\");
ES6_Named1.numberValue = 123; ES6_Named1.numberValue = 123;
var CommonJS_Star = require(\"CommonJS_Clobbering_Lit\"); var CommonJS_Star = require(\"CommonJS_Clobbering_Lit\");
CommonJS_Star.numberValue1 = 123; CommonJS_Star.numberValue1 = 123;
var CommonJS_Frozen_Star = require(\"CommonJS_Clobbering_Frozen\"); var CommonJS_Frozen_Star = require(\"CommonJS_Clobbering_Frozen\");
CommonJS_Frozen_Star.numberValue1 = 123; CommonJS_Frozen_Star.numberValue1 = 123;
} }
" "

View File

@ -58,63 +58,36 @@ import {exports as nope} from \"ES\"; // Error: Not an export
// Error: Not an export // Error: Not an export
import {num1, str1} from \"CJS_Named\"; import {num1, str1} from \"CJS_Named\";
import CJS_Named from \"CJS_Named\"; import CJS_Named from \"CJS_Named\";
(num1: number); (num1: number);
(num1: string); (num1: string);
(str1: string); (str1: string);
(str1: number); (str1: number);
(CJS_Named: { num1: number, str1: string }); (CJS_Named: { num1: number, str1: string });
(CJS_Named: number); (CJS_Named: number);
import {num2} from \"CJS_Clobbered\"; import {num2} from \"CJS_Clobbered\";
import {numExport} from \"CJS_Clobbered\"; import {numExport} from \"CJS_Clobbered\";
(numExport: number); (numExport: number);
(numExport: string); (numExport: string);
import type {numType} from \"CJS_Clobbered\"; import type {numType} from \"CJS_Clobbered\";
(42: numType); (42: numType);
(\"asdf\": numType); (\"asdf\": numType);
import {strHidden} from \"ES\"; import {strHidden} from \"ES\";
import {str3} from \"ES\"; import {str3} from \"ES\";
(str3: string); (str3: string);
(str3: number); (str3: number);
import {num3} from \"ES\"; import {num3} from \"ES\";
(num3: number); (num3: number);
(num3: string); (num3: string);
import {C} from \"ES\"; import {C} from \"ES\";
import type {C as CType} from \"ES\"; import type {C as CType} from \"ES\";
(new C(): C); (new C(): C);
(42: C); (42: C);
(new C(): CType); (new C(): CType);
(42: CType); (42: CType);
import {T} from \"ES\"; import {T} from \"ES\";
import type {T as T2} from \"ES\"; import type {T as T2} from \"ES\";
(42: T2); (42: T2);
(\"asdf\": T2); (\"asdf\": T2);
import {exports as nope} from \"ES\"; import {exports as nope} from \"ES\";
" "
`; `;

View File

@ -18,15 +18,10 @@ N.z = Q(N.z);
// declaration of Q redirects to module M // declaration of Q redirects to module M
var M = require(\"M\"); var M = require(\"M\");
var N = require(\"N\"); var N = require(\"N\");
N.x = M(N.x); N.x = M(N.x);
var P = require(\"./P\"); var P = require(\"./P\");
N.y = P(N.y); N.y = P(N.y);
var Q = require(\"Q\"); var Q = require(\"Q\");
N.z = Q(N.z); N.z = Q(N.z);
" "
`; `;

View File

@ -9,7 +9,6 @@ module.exports = {}
/* @flow */ /* @flow */
export type talias4 = number; export type talias4 = number;
export interface IFoo { prop: number } export interface IFoo { prop: number }
module.exports = {}; module.exports = {};
" "
`; `;

View File

@ -3,7 +3,6 @@ exports[`test foo.js 1`] = `
imp(1337); imp(1337);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
var imp = require(\"./bar\"); var imp = require(\"./bar\");
imp(1337); imp(1337);
" "
`; `;

View File

@ -7,9 +7,7 @@ var React = require(\'react\');
// @flow // @flow
// Error: ReactElement ~> number // Error: ReactElement ~> number
var React = require(\"react\"); var React = require(\"react\");
(<fbt/>: React.Element<*>); (<fbt/>: React.Element<*>);
(<fbt/>: number); (<fbt/>: number);
" "
`; `;

View File

@ -7,7 +7,6 @@ exports[`test main.js 1`] = `
// @flow // @flow
// Error (the libdef in this test marks fbt as number) // Error (the libdef in this test marks fbt as number)
(<fbt/>: number); (<fbt/>: number);
(<fbt/>: string); (<fbt/>: string);
" "
`; `;

View File

@ -3,7 +3,6 @@ exports[`test Bar.js 1`] = `
module.exports = Bar; module.exports = Bar;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
var Bar = { x: 0 }; var Bar = { x: 0 };
module.exports = Bar; module.exports = Bar;
" "
`; `;
@ -63,9 +62,7 @@ let tests = [
}, },
function(copyProperties: Object$Assign) { function(copyProperties: Object$Assign) {
let result = {}; let result = {};
result.baz = false; result.baz = false;
(copyProperties(result, { foo: \"a\" }, { (copyProperties(result, { foo: \"a\" }, {
bar: 123 bar: 123
}): { foo: string, bar: number, baz: boolean }); }): { foo: string, bar: number, baz: boolean });
@ -74,17 +71,14 @@ let tests = [
const copyProperties = require(\"copyProperties\"); const copyProperties = require(\"copyProperties\");
let x = { foo: \"a\" }; let x = { foo: \"a\" };
let y = { bar: 123 }; let y = { bar: 123 };
(copyProperties({}, x, y): { foo: string, bar: number }); (copyProperties({}, x, y): { foo: string, bar: number });
}, },
function(copyProperties: Object$Assign) { function(copyProperties: Object$Assign) {
copyProperties(); copyProperties();
(copyProperties({ foo: \"a\" }): { foo: number }); (copyProperties({ foo: \"a\" }): { foo: number });
}, },
function(copyProperties: Object$Assign) { function(copyProperties: Object$Assign) {
function x(cb: Function) {} function x(cb: Function) {}
x(copyProperties); x(copyProperties);
} }
]; ];
@ -112,14 +106,11 @@ let tests = [
let tests = [ let tests = [
function() { function() {
let x: ?string = null; let x: ?string = null;
invariant(x, \"truthy only\"); invariant(x, \"truthy only\");
}, },
function(invariant: Function) { function(invariant: Function) {
let x: ?string = null; let x: ?string = null;
invariant(x); invariant(x);
(x: string); (x: string);
} }
]; ];
@ -200,17 +191,13 @@ let tests = [
}, },
function(mergeInto: $Facebookism$MergeInto) { function(mergeInto: $Facebookism$MergeInto) {
let result = {}; let result = {};
result.baz = false; result.baz = false;
(mergeInto(result, { foo: \"a\" }, { bar: 123 }): void); (mergeInto(result, { foo: \"a\" }, { bar: 123 }): void);
(result: { foo: string, bar: number, baz: boolean }); (result: { foo: string, bar: number, baz: boolean });
}, },
function() { function() {
const mergeInto = require(\"mergeInto\"); const mergeInto = require(\"mergeInto\");
let result: { foo?: string, bar?: number, baz: boolean } = { baz: false }; let result: { foo?: string, bar?: number, baz: boolean } = { baz: false };
(mergeInto(result, { foo: \"a\" }, { bar: 123 }): void); (mergeInto(result, { foo: \"a\" }, { bar: 123 }): void);
}, },
function(mergeInto: $Facebookism$MergeInto) { function(mergeInto: $Facebookism$MergeInto) {
@ -218,7 +205,6 @@ let tests = [
}, },
function(mergeInto: $Facebookism$MergeInto) { function(mergeInto: $Facebookism$MergeInto) {
function x(cb: Function) {} function x(cb: Function) {}
x(mergeInto); x(mergeInto);
} }
]; ];
@ -241,7 +227,6 @@ var mixin = require(\"mixin\");
class Foo extends mixin(Bar) { class Foo extends mixin(Bar) {
m() { m() {
var x: string = this.x; var x: string = this.x;
this.y = \"\"; this.y = \"\";
} }
} }

View File

@ -98,31 +98,21 @@ const b = new Headers([ \"Content-Type\", \"image/jpeg\" ]);
const c = new Headers({ \"Content-Type\", \"image/jpeg\" }); const c = new Headers({ \"Content-Type\", \"image/jpeg\" });
const d = new Headers(c); const d = new Headers(c);
const e: Headers = new Headers(); const e: Headers = new Headers();
e.append(\"Content-Type\", \"image/jpeg\"); e.append(\"Content-Type\", \"image/jpeg\");
e.append(\"Content-Type\"); e.append(\"Content-Type\");
e.append({ \"Content-Type\", \"image/jpeg\" }); e.append({ \"Content-Type\", \"image/jpeg\" });
e.set(\"Content-Type\", \"image/jpeg\"); e.set(\"Content-Type\", \"image/jpeg\");
e.set(\"Content-Type\"); e.set(\"Content-Type\");
e.set({ \"Content-Type\", \"image/jpeg\" }); e.set({ \"Content-Type\", \"image/jpeg\" });
const f: Headers = e.append(\"Content-Type\", \"image/jpeg\"); const f: Headers = e.append(\"Content-Type\", \"image/jpeg\");
const g: string = e.get(\"Content-Type\"); const g: string = e.get(\"Content-Type\");
const h: number = e.get(\"Content-Type\"); const h: number = e.get(\"Content-Type\");
for (let v of e) { for (let v of e) {
const [ i, j ]: [string, string] = v; const [ i, j ]: [string, string] = v;
} }
for (let v of e.entries()) { for (let v of e.entries()) {
const [ i, j ]: [string, string] = v; const [ i, j ]: [string, string] = v;
} }
e.getAll(\"content-type\").forEach((v: string) => {}); e.getAll(\"content-type\").forEach((v: string) => {});
" "
`; `;
@ -229,13 +219,9 @@ const k: Request = new Request(\"http://example.org\", {
cache: \"default\" cache: \"default\"
}); });
var l: boolean = h.bodyUsed; var l: boolean = h.bodyUsed;
h.text().then((t: string) => t); h.text().then((t: string) => t);
h.text().then((t: Buffer) => t); h.text().then((t: Buffer) => t);
h.arrayBuffer().then((ab: ArrayBuffer) => ab); h.arrayBuffer().then((ab: ArrayBuffer) => ab);
h.arrayBuffer().then((ab: Buffer) => ab); h.arrayBuffer().then((ab: Buffer) => ab);
" "
`; `;
@ -325,13 +311,9 @@ const i: Response = new Response({
}); });
const ok: boolean = h.ok; const ok: boolean = h.ok;
const status: number = h.status; const status: number = h.status;
h.text().then((t: string) => t); h.text().then((t: string) => t);
h.text().then((t: Buffer) => t); h.text().then((t: Buffer) => t);
h.arrayBuffer().then((ab: ArrayBuffer) => ab); h.arrayBuffer().then((ab: ArrayBuffer) => ab);
h.arrayBuffer().then((ab: Buffer) => ab); h.arrayBuffer().then((ab: Buffer) => ab);
" "
`; `;
@ -389,31 +371,21 @@ const b = new URLSearchParams([ \"key1\", \"value1\" ]);
const c = new URLSearchParams({ \"key1\", \"value1\" }); const c = new URLSearchParams({ \"key1\", \"value1\" });
const d = new URLSearchParams(c); const d = new URLSearchParams(c);
const e: URLSearchParams = new URLSearchParams(); const e: URLSearchParams = new URLSearchParams();
e.append(\"key1\", \"value1\"); e.append(\"key1\", \"value1\");
e.append(\"key1\"); e.append(\"key1\");
e.append({ \"key1\", \"value1\" }); e.append({ \"key1\", \"value1\" });
e.set(\"key1\", \"value1\"); e.set(\"key1\", \"value1\");
e.set(\"key1\"); e.set(\"key1\");
e.set({ \"key1\", \"value1\" }); e.set({ \"key1\", \"value1\" });
const f: URLSearchParams = e.append(\"key1\", \"value1\"); const f: URLSearchParams = e.append(\"key1\", \"value1\");
const g: string = e.get(\"key1\"); const g: string = e.get(\"key1\");
const h: number = e.get(\"key1\"); const h: number = e.get(\"key1\");
for (let v of e) { for (let v of e) {
const [ i, j ]: [string, string] = v; const [ i, j ]: [string, string] = v;
} }
for (let v of e.entries()) { for (let v of e.entries()) {
const [ i, j ]: [string, string] = v; const [ i, j ]: [string, string] = v;
} }
e.getAll(\"key1\").forEach((v: string) => {}); e.getAll(\"key1\").forEach((v: string) => {});
" "
`; `;

View File

@ -12,9 +12,7 @@ exports[`test test.js 1`] = `
import x from \'./req\'; import x from \'./req\';
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
var x = require(\"./req\"); var x = require(\"./req\");
(x: string); (x: string);
import x from \"./req\"; import x from \"./req\";
" "
`; `;

View File

@ -34,15 +34,12 @@ module.exports = {fn: fix};
function eq(x: number, y: number) { function eq(x: number, y: number) {
return true; return true;
} }
function sub(x: number, y: number) { function sub(x: number, y: number) {
return 0; return 0;
} }
function mul(x: number, y: number) { function mul(x: number, y: number) {
return 0; return 0;
} }
function fix(fold) { function fix(fold) {
var delta = function(delta) { var delta = function(delta) {
return fold(function(x) { return fold(function(x) {
@ -52,23 +49,18 @@ function fix(fold) {
}; };
return delta(delta); return delta(delta);
} }
function mk_factorial() { function mk_factorial() {
return fix(function(factorial) { return fix(function(factorial) {
return function(n) { return function(n) {
if (eq(n, 1)) { if (eq(n, 1)) {
return 1; return 1;
} }
return mul(factorial(sub(n, 1)), n); return mul(factorial(sub(n, 1)), n);
}; };
}); });
} }
var factorial = mk_factorial(); var factorial = mk_factorial();
factorial(\"...\"); factorial(\"...\");
module.exports = { fn: fix }; module.exports = { fn: fix };
" "
`; `;
@ -101,30 +93,22 @@ function Y(f) {
function g(x) { function g(x) {
return f(x(x)); return f(x(x));
} }
g(g); g(g);
} }
function func1(f) { function func1(f) {
function fix_f(x: number): number { function fix_f(x: number): number {
return f(x); return f(x);
} }
return fix_f; return fix_f;
} }
function func2(f) { function func2(f) {
function fix_f(x: string): string { function fix_f(x: string): string {
return f(x); return f(x);
} }
return fix_f; return fix_f;
} }
Y(func1); Y(func1);
Y(func2); Y(func2);
module.exports = Y; module.exports = Y;
" "
`; `;

View File

@ -50,38 +50,28 @@ function corge(x: boolean) {
/* @flow */ /* @flow */
function foo(x: boolean) { function foo(x: boolean) {
var max = 10; var max = 10;
for (var ii = 0; ii < max; ii++) { for (var ii = 0; ii < max; ii++) {
if (x) { if (x) {
continue; continue;
} }
return; return;
} }
console.log(\"this is still reachable\"); console.log(\"this is still reachable\");
} }
function bar(x: boolean) { function bar(x: boolean) {
var max = 0; var max = 0;
for (var ii = 0; ii < max; ii++) { for (var ii = 0; ii < max; ii++) {
return; return;
} }
console.log(\"this is still reachable\"); console.log(\"this is still reachable\");
} }
function baz(x: boolean) { function baz(x: boolean) {
var max = 0; var max = 0;
for (var ii = 0; ii < max; ii++) { for (var ii = 0; ii < max; ii++) {
continue; continue;
} }
console.log(\"this is still reachable\"); console.log(\"this is still reachable\");
} }
function bliffl(x: boolean) { function bliffl(x: boolean) {
var max = 10; var max = 10;
loop1: loop1:
@ -90,20 +80,15 @@ function bliffl(x: boolean) {
for (var jj = 0; jj < max; jj++) { for (var jj = 0; jj < max; jj++) {
break loop1; break loop1;
} }
console.log(\"this is still reachable\"); console.log(\"this is still reachable\");
} }
console.log(\"this is still reachable\"); console.log(\"this is still reachable\");
} }
function corge(x: boolean) { function corge(x: boolean) {
var max = 0; var max = 0;
for (var ii = 0; ii < max; ii++) { for (var ii = 0; ii < max; ii++) {
break; break;
} }
console.log(\"this is still reachable\"); console.log(\"this is still reachable\");
} }
" "
@ -155,34 +140,26 @@ function corge(x: boolean) {
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function foo(x: boolean) { function foo(x: boolean) {
var obj = { a: 1, b: 2 }; var obj = { a: 1, b: 2 };
for (var prop in obj) { for (var prop in obj) {
if (x) { if (x) {
continue; continue;
} }
return; return;
} }
console.log(\"this is still reachable\"); console.log(\"this is still reachable\");
} }
function bar(x: boolean) { function bar(x: boolean) {
for (var prop in {}) { for (var prop in {}) {
return; return;
} }
console.log(\"this is still reachable\"); console.log(\"this is still reachable\");
} }
function baz(x: boolean) { function baz(x: boolean) {
for (var prop in {}) { for (var prop in {}) {
continue; continue;
} }
console.log(\"this is still reachable\"); console.log(\"this is still reachable\");
} }
function bliffl(x: boolean) { function bliffl(x: boolean) {
var obj = { a: 1, b: 2 }; var obj = { a: 1, b: 2 };
loop1: loop1:
@ -191,18 +168,14 @@ function bliffl(x: boolean) {
for (var prop2 in obj) { for (var prop2 in obj) {
break loop1; break loop1;
} }
console.log(\"this is still reachable\"); console.log(\"this is still reachable\");
} }
console.log(\"this is still reachable\"); console.log(\"this is still reachable\");
} }
function corge(x: boolean) { function corge(x: boolean) {
for (var prop in {}) { for (var prop in {}) {
break; break;
} }
console.log(\"this is still reachable\"); console.log(\"this is still reachable\");
} }
" "
@ -254,34 +227,26 @@ function corge(x: boolean) {
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function foo(x: boolean) { function foo(x: boolean) {
var arr = [ 1, 2, 3 ]; var arr = [ 1, 2, 3 ];
for (var elem of arr) { for (var elem of arr) {
if (x) { if (x) {
continue; continue;
} }
return; return;
} }
console.log(\"this is still reachable\"); console.log(\"this is still reachable\");
} }
function bar(x: boolean) { function bar(x: boolean) {
for (var elem of []) { for (var elem of []) {
return; return;
} }
console.log(\"this is still reachable\"); console.log(\"this is still reachable\");
} }
function baz(x: boolean) { function baz(x: boolean) {
for (var elem of []) { for (var elem of []) {
continue; continue;
} }
console.log(\"this is still reachable\"); console.log(\"this is still reachable\");
} }
function bliffl(x: boolean) { function bliffl(x: boolean) {
var arr = [ 1, 2, 3 ]; var arr = [ 1, 2, 3 ];
loop1: loop1:
@ -290,18 +255,14 @@ function bliffl(x: boolean) {
for (var elem of arr) { for (var elem of arr) {
break loop1; break loop1;
} }
console.log(\"this is still reachable\"); console.log(\"this is still reachable\");
} }
console.log(\"this is still reachable\"); console.log(\"this is still reachable\");
} }
function corge(x: boolean) { function corge(x: boolean) {
for (var elem of []) { for (var elem of []) {
break; break;
} }
console.log(\"this is still reachable\"); console.log(\"this is still reachable\");
} }
" "

View File

@ -69,47 +69,38 @@ function testArray(arr: Array<number>): void {
(x: string); (x: string);
} }
} }
function testIterable1(iterable: Iterable<number>): void { function testIterable1(iterable: Iterable<number>): void {
for (var x of iterable) { for (var x of iterable) {
(x: string); (x: string);
} }
} }
function testIterable2(iterable: Iterable<*>): void { function testIterable2(iterable: Iterable<*>): void {
for (var x of iterable) { for (var x of iterable) {
(x: string); (x: string);
} }
} }
function testString(str: string): void { function testString(str: string): void {
for (var x of str) { for (var x of str) {
(x: number); (x: number);
} }
} }
function testMap1(map: Map<string, number>): void { function testMap1(map: Map<string, number>): void {
for (var elem of map) { for (var elem of map) {
(elem: [string, number]); (elem: [string, number]);
(elem: number); (elem: number);
} }
} }
function testMap2(map: Map<*, *>): void { function testMap2(map: Map<*, *>): void {
for (var elem of map) { for (var elem of map) {
(elem: [number, string]); (elem: [number, string]);
(elem: number); (elem: number);
} }
} }
function testSet1(set: Set<string>): void { function testSet1(set: Set<string>): void {
for (var x of set) { for (var x of set) {
(x: number); (x: number);
} }
} }
function testSet2(set: Set<*>): void { function testSet2(set: Set<*>): void {
for (var x of set) { for (var x of set) {
(x: number); (x: number);

View File

@ -69,39 +69,24 @@ function test2(): number { return 0; }
function test(a: string, b: number): number { function test(a: string, b: number): number {
return this.length; return this.length;
} }
test.apply(\"\", [ \"\", 0 ]); test.apply(\"\", [ \"\", 0 ]);
test.apply(0, [ \"\", 0 ]); test.apply(0, [ \"\", 0 ]);
test.apply(\"\", [ \"\" ]); test.apply(\"\", [ \"\" ]);
test.apply(\"\", [ \"\", \"\" ]); test.apply(\"\", [ \"\", \"\" ]);
test.apply(\"\", [ 0, 0 ]); test.apply(\"\", [ 0, 0 ]);
function f(args) { function f(args) {
test.apply(\"\", args); test.apply(\"\", args);
} }
f([ \"\", 0 ]); f([ \"\", 0 ]);
f([ \"\", \"\" ]); f([ \"\", \"\" ]);
f([ 0, 0 ]); f([ 0, 0 ]);
test.apply(\"\", \"not array\"); test.apply(\"\", \"not array\");
(test.call.apply(test, [ 0, 123, \"foo\" ]): void); (test.call.apply(test, [ 0, 123, \"foo\" ]): void);
(test.bind.apply(test, [ 0, 123 ]): (b: number) => number); (test.bind.apply(test, [ 0, 123 ]): (b: number) => number);
function test2(): number { function test2(): number {
return 0; return 0;
} }
(test2.apply(): number); (test2.apply(): number);
(test2.apply(\"\"): number); (test2.apply(\"\"): number);
" "
`; `;
@ -123,9 +108,7 @@ let tests = [
let tests = [ let tests = [
function(x: (a: string, b: string) => void) { function(x: (a: string, b: string) => void) {
let y = x.bind(x, \"foo\"); let y = x.bind(x, \"foo\");
y(\"bar\"); y(\"bar\");
y(123); y(123);
} }
]; ];
@ -191,35 +174,22 @@ function test2(): number { return 0; }
function test(a: string, b: number): number { function test(a: string, b: number): number {
return this.length; return this.length;
} }
test.call(\"\", \"\", 0); test.call(\"\", \"\", 0);
test.call(0, \"\", 0); test.call(0, \"\", 0);
test.call(\"\", \"\"); test.call(\"\", \"\");
test.call(\"\", \"\", \"\"); test.call(\"\", \"\", \"\");
test.call(\"\", 0, 0); test.call(\"\", 0, 0);
function f(args) { function f(args) {
test.call(\"\", args[0], args[1]); test.call(\"\", args[0], args[1]);
} }
f([ \"\", 0 ]); f([ \"\", 0 ]);
f([ \"\", \"\" ]); f([ \"\", \"\" ]);
f([ 0, 0 ]); f([ 0, 0 ]);
(test.apply.call(test, 0, [ 0, \"foo\" ]): number); (test.apply.call(test, 0, [ 0, \"foo\" ]): number);
function test2(): number { function test2(): number {
return 0; return 0;
} }
(test2.call(): number); (test2.call(): number);
(test2.call(\"\"): number); (test2.call(\"\"): number);
" "
`; `;
@ -322,74 +292,47 @@ var b: Function = function(a: number, b: number): number {
}; };
class C {} class C {}
var c: Function = C; var c: Function = C;
function good(x: Function, MyThing: Function): number { function good(x: Function, MyThing: Function): number {
var o: Object = x; var o: Object = x;
x.foo = 123; x.foo = 123;
x[\"foo\"] = 456; x[\"foo\"] = 456;
x(); x();
<MyThing/>; <MyThing/>;
var { ...something } = x; var { ...something } = x;
Object.assign(x, { hi: \"there\" }); Object.assign(x, { hi: \"there\" });
Object.keys(x); Object.keys(x);
return x.bar + x[\"bar\"] + x.lala(); return x.bar + x[\"bar\"] + x.lala();
} }
function bad(x: Function, y: Object): void { function bad(x: Function, y: Object): void {
var a: number = x; var a: number = x;
var b: string = x; var b: string = x;
var c: Function = y; var c: Function = y;
} }
let tests = [ let tests = [
function(y: () => void, z: Function) { function(y: () => void, z: Function) {
function x() {} function x() {}
(x.length: void); (x.length: void);
(y.length: void); (y.length: void);
(z.length: void); (z.length: void);
(x.name: void); (x.name: void);
(y.name: void); (y.name: void);
(z.name: void); (z.name: void);
}, },
function(y: () => void, z: Function) { function(y: () => void, z: Function) {
function x() {} function x() {}
x.length = \"foo\"; x.length = \"foo\";
y.length = \"foo\"; y.length = \"foo\";
z.length = \"foo\"; z.length = \"foo\";
x.name = 123; x.name = 123;
y.name = 123; y.name = 123;
z.name = 123; z.name = 123;
(z.foo: number); (z.foo: number);
(z.foo: string); (z.foo: string);
} }
]; ];
var d: Function = () => 1; var d: Function = () => 1;
var e = (d.bind(1): Function)(); var e = (d.bind(1): Function)();
(e: number); (e: number);
(e: string); (e: string);
" "
`; `;
@ -421,15 +364,12 @@ function rest_t<U, T: Array<U>>(...xs: T): U {
function rest_array<T>(...xs: Array<T>): T { function rest_array<T>(...xs: Array<T>): T {
return xs[0]; return xs[0];
} }
function rest_tuple<T>(...xs: [T]): T { function rest_tuple<T>(...xs: [T]): T {
return xs[0]; return xs[0];
} }
function rest_any(...xs: any): any { function rest_any(...xs: any): any {
return xs[0]; return xs[0];
} }
function rest_t<U, T: Array<U>>(...xs: T): U { function rest_t<U, T: Array<U>>(...xs: T): U {
return xs[0]; return xs[0];
} }

View File

@ -9,7 +9,6 @@ function foo() {
function bar(x) { function bar(x) {
return x; return x;
} }
function foo() { function foo() {
return function bound() { return function bound() {
return bar(bound); return bar(bound);

View File

@ -151,18 +151,14 @@ for (var x of examples.delegate_yield_iterable([])) {
class GeneratorExamples { class GeneratorExamples {
*stmt_yield(): Generator<number, void, void> { *stmt_yield(): Generator<number, void, void> {
yield 0; yield 0;
yield \"\"; yield \"\";
} }
*stmt_next(): Generator<void, void, number> { *stmt_next(): Generator<void, void, number> {
var a = yield; var a = yield;
if (a) { if (a) {
(a: number); (a: number);
} }
var b = yield; var b = yield;
if (b) { if (b) {
(b: string); (b: string);
} }
@ -179,7 +175,6 @@ class GeneratorExamples {
} }
*widen_next() { *widen_next() {
var x = yield 0; var x = yield 0;
if (typeof x === \"number\") {} if (typeof x === \"number\") {}
else if (typeof x === \"boolean\") {} else if (typeof x === \"boolean\") {}
else { else {
@ -188,30 +183,25 @@ class GeneratorExamples {
} }
*widen_yield() { *widen_yield() {
yield 0; yield 0;
yield \"\"; yield \"\";
yield true; yield true;
} }
*delegate_next_generator() { *delegate_next_generator() {
function* inner() { function* inner() {
var x: number = yield; var x: number = yield;
} }
yield* inner(); yield* inner();
} }
*delegate_yield_generator() { *delegate_yield_generator() {
function* inner() { function* inner() {
yield \"\"; yield \"\";
} }
yield* inner(); yield* inner();
} }
*delegate_return_generator() { *delegate_return_generator() {
function* inner() { function* inner() {
return \"\"; return \"\";
} }
var x: number = yield* inner(); var x: number = yield* inner();
} }
*delegate_next_iterable(xs: Array<number>) { *delegate_next_iterable(xs: Array<number>) {
@ -234,25 +224,18 @@ class GeneratorExamples {
} }
} }
var examples = new GeneratorExamples(); var examples = new GeneratorExamples();
for (var x of examples.infer_stmt()) { for (var x of examples.infer_stmt()) {
(x: string); (x: string);
} }
var infer_stmt_next = examples.infer_stmt().next(0).value; var infer_stmt_next = examples.infer_stmt().next(0).value;
if (typeof infer_stmt_next === \"undefined\") {} if (typeof infer_stmt_next === \"undefined\") {}
else if (typeof infer_stmt_next === \"number\") {} else if (typeof infer_stmt_next === \"number\") {}
else { else {
(infer_stmt_next: boolean); (infer_stmt_next: boolean);
} }
examples.widen_next().next(0); examples.widen_next().next(0);
examples.widen_next().next(\"\"); examples.widen_next().next(\"\");
examples.widen_next().next(true); examples.widen_next().next(true);
for (var x of examples.widen_yield()) { for (var x of examples.widen_yield()) {
if (typeof x === \"number\") {} if (typeof x === \"number\") {}
else if (typeof x === \"boolean\") {} else if (typeof x === \"boolean\") {}
@ -260,15 +243,11 @@ for (var x of examples.widen_yield()) {
(x: string); (x: string);
} }
} }
examples.delegate_next_generator().next(\"\"); examples.delegate_next_generator().next(\"\");
for (var x of examples.delegate_yield_generator()) { for (var x of examples.delegate_yield_generator()) {
(x: number); (x: number);
} }
examples.delegate_next_iterable([]).next(\"\"); examples.delegate_next_iterable([]).next(\"\");
for (var x of examples.delegate_yield_iterable([])) { for (var x of examples.delegate_yield_iterable([])) {
(x: string); (x: string);
} }
@ -309,13 +288,10 @@ class GeneratorExamples<X> {
} }
} }
var examples = new GeneratorExamples(); var examples = new GeneratorExamples();
for (var x of examples.infer_stmt()) { for (var x of examples.infer_stmt()) {
(x: string); (x: string);
} }
var infer_stmt_next = examples.infer_stmt().next(0).value; var infer_stmt_next = examples.infer_stmt().next(0).value;
if (typeof infer_stmt_next === \"undefined\") {} if (typeof infer_stmt_next === \"undefined\") {}
else if (typeof infer_stmt_next === \"number\") {} else if (typeof infer_stmt_next === \"number\") {}
else { else {
@ -476,73 +452,53 @@ if (multiple_return_result.done) {
// error: number|string ~> void // error: number|string ~> void
function* stmt_yield(): Generator<number, void, void> { function* stmt_yield(): Generator<number, void, void> {
yield 0; yield 0;
yield \"\"; yield \"\";
} }
function* stmt_next(): Generator<void, void, number> { function* stmt_next(): Generator<void, void, number> {
var a = yield; var a = yield;
if (a) { if (a) {
(a: number); (a: number);
} }
var b = yield; var b = yield;
if (b) { if (b) {
(b: string); (b: string);
} }
} }
function* stmt_return_ok(): Generator<void, number, void> { function* stmt_return_ok(): Generator<void, number, void> {
return 0; return 0;
} }
function* stmt_return_err(): Generator<void, number, void> { function* stmt_return_err(): Generator<void, number, void> {
return \"\"; return \"\";
} }
function* infer_stmt() { function* infer_stmt() {
var x: boolean = yield 0; var x: boolean = yield 0;
return \"\"; return \"\";
} }
for (var x of infer_stmt()) { for (var x of infer_stmt()) {
(x: string); (x: string);
} }
var infer_stmt_next = infer_stmt().next(0).value; var infer_stmt_next = infer_stmt().next(0).value;
if (typeof infer_stmt_next === \"undefined\") {} if (typeof infer_stmt_next === \"undefined\") {}
else if (typeof infer_stmt_next === \"number\") {} else if (typeof infer_stmt_next === \"number\") {}
else { else {
(infer_stmt_next: boolean); (infer_stmt_next: boolean);
} }
function* widen_next() { function* widen_next() {
var x = yield 0; var x = yield 0;
if (typeof x === \"number\") {} if (typeof x === \"number\") {}
else if (typeof x === \"boolean\") {} else if (typeof x === \"boolean\") {}
else { else {
(x: string); (x: string);
} }
} }
widen_next().next(0); widen_next().next(0);
widen_next().next(\"\"); widen_next().next(\"\");
widen_next().next(true); widen_next().next(true);
function* widen_yield() { function* widen_yield() {
yield 0; yield 0;
yield \"\"; yield \"\";
yield true; yield true;
} }
for (var x of widen_yield()) { for (var x of widen_yield()) {
if (typeof x === \"number\") {} if (typeof x === \"number\") {}
else if (typeof x === \"boolean\") {} else if (typeof x === \"boolean\") {}
@ -550,67 +506,50 @@ for (var x of widen_yield()) {
(x: string); (x: string);
} }
} }
function* delegate_next_generator() { function* delegate_next_generator() {
function* inner() { function* inner() {
var x: number = yield; var x: number = yield;
} }
yield* inner(); yield* inner();
} }
delegate_next_generator().next(\"\"); delegate_next_generator().next(\"\");
function* delegate_yield_generator() { function* delegate_yield_generator() {
function* inner() { function* inner() {
yield \"\"; yield \"\";
} }
yield* inner(); yield* inner();
} }
for (var x of delegate_yield_generator()) { for (var x of delegate_yield_generator()) {
(x: number); (x: number);
} }
function* delegate_return_generator() { function* delegate_return_generator() {
function* inner() { function* inner() {
return \"\"; return \"\";
} }
var x: number = yield* inner(); var x: number = yield* inner();
} }
function* delegate_next_iterable(xs: Array<number>) { function* delegate_next_iterable(xs: Array<number>) {
yield* xs; yield* xs;
} }
delegate_next_iterable([]).next(\"\"); delegate_next_iterable([]).next(\"\");
function* delegate_yield_iterable(xs: Array<number>) { function* delegate_yield_iterable(xs: Array<number>) {
yield* xs; yield* xs;
} }
for (var x of delegate_yield_iterable([])) { for (var x of delegate_yield_iterable([])) {
(x: string); (x: string);
} }
function* delegate_return_iterable(xs: Array<number>) { function* delegate_return_iterable(xs: Array<number>) {
var x: void = yield* xs; var x: void = yield* xs;
} }
function* generic_yield<Y>(y: Y): Generator<Y, void, void> { function* generic_yield<Y>(y: Y): Generator<Y, void, void> {
yield y; yield y;
} }
function* generic_return<R>(r: R): Generator<void, R, void> { function* generic_return<R>(r: R): Generator<void, R, void> {
return r; return r;
} }
function* generic_next<N>(): Generator<void, N, N> { function* generic_next<N>(): Generator<void, N, N> {
return yield undefined; return yield undefined;
} }
function* multiple_return(b) { function* multiple_return(b) {
if (b) { if (b) {
return 0; return 0;
@ -618,9 +557,7 @@ function* multiple_return(b) {
return \"foo\"; return \"foo\";
} }
} }
let multiple_return_result = multiple_return().next(); let multiple_return_result = multiple_return().next();
if (multiple_return_result.done) { if (multiple_return_result.done) {
(multiple_return_result.value: void); (multiple_return_result.value: void);
} }
@ -658,10 +595,8 @@ if (refuse_return_result.done) {
// error: number | void ~> string // error: number | void ~> string
function test1(gen: Generator<void, string, void>) { function test1(gen: Generator<void, string, void>) {
var ret = gen.return(0); var ret = gen.return(0);
(ret.value: void); (ret.value: void);
} }
function* refuse_return() { function* refuse_return() {
try { try {
yield 1; yield 1;
@ -669,10 +604,8 @@ function* refuse_return() {
return 0; return 0;
} }
} }
var refuse_return_gen = refuse_return(); var refuse_return_gen = refuse_return();
var refuse_return_result = refuse_return_gen.return(\"string\"); var refuse_return_result = refuse_return_gen.return(\"string\");
if (refuse_return_result.done) { if (refuse_return_result.done) {
(refuse_return_result.value: string); (refuse_return_result.value: string);
} }
@ -715,25 +648,19 @@ function* catch_return() {
return e; return e;
} }
} }
var catch_return_value = catch_return().throw(\"\").value; var catch_return_value = catch_return().throw(\"\").value;
if (catch_return_value !== undefined) { if (catch_return_value !== undefined) {
(catch_return_value: string); (catch_return_value: string);
} }
function* yield_return() { function* yield_return() {
try { try {
yield 0; yield 0;
return; return;
} catch (e) { } catch (e) {
yield e; yield e;
} }
} }
var yield_return_value = yield_return().throw(\"\").value; var yield_return_value = yield_return().throw(\"\").value;
if (yield_return_value !== undefined) { if (yield_return_value !== undefined) {
(yield_return_value: string); (yield_return_value: string);
} }

View File

@ -63,9 +63,7 @@ class D<T> {
x: T; x: T;
m<S>(z: S, u: T, v): S { m<S>(z: S, u: T, v): S {
this.x = u; this.x = u;
v.u = u; v.u = u;
return z; return z;
} }
} }
@ -77,7 +75,6 @@ var n: number = o.u;
class E<X> extends C<X> { class E<X> extends C<X> {
set(x: X): X { set(x: X): X {
this.x = x; this.x = x;
return this.get(); return this.get();
} }
} }
@ -92,9 +89,7 @@ class H<Z> extends G<Array<Z>> {
} }
} }
var h1 = new H(); var h1 = new H();
h1.foo([ \"...\" ]); h1.foo([ \"...\" ]);
var h2: F<Array<Array<Array<number>>>> = h1; var h2: F<Array<Array<Array<number>>>> = h1;
var obj: Object<string, string> = {}; var obj: Object<string, string> = {};
var fn: Function<string> = function() { var fn: Function<string> = function() {

View File

@ -38,7 +38,6 @@ var id = geolocation.watchPosition(
} }
} }
); );
geolocation.clearWatch(id); geolocation.clearWatch(id);
" "
`; `;

View File

@ -19,15 +19,11 @@ lib.bar();
// t123456 // t123456
// D123456 // D123456
var lib = require(\"./library\"); var lib = require(\"./library\");
function add(a: number, b: number): number { function add(a: number, b: number): number {
return a + b; return a + b;
} }
var re = /^keynote (talk){2} (lightning){3,5} (talk){2} closing partytime!!!/; var re = /^keynote (talk){2} (lightning){3,5} (talk){2} closing partytime!!!/;
add(lib.iTakeAString(42), 7); add(lib.iTakeAString(42), 7);
lib.bar(); lib.bar();
" "
`; `;
@ -47,17 +43,11 @@ things;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// @flow // @flow
import thing from \"./helpers/exports_default.js\"; import thing from \"./helpers/exports_default.js\";
thing; thing;
import {foo, bar as baz} from \"./helpers/exports_named.js\"; import {foo, bar as baz} from \"./helpers/exports_named.js\";
foo; foo;
baz; baz;
import * as things from \"./helpers/exports_named.js\"; import * as things from \"./helpers/exports_named.js\";
things; things;
" "
`; `;

View File

@ -6,7 +6,6 @@ module.exports = {ParentFoo};
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// @flow // @flow
var ParentFoo = { foo: \"bar\" }; var ParentFoo = { foo: \"bar\" };
module.exports = { ParentFoo }; module.exports = { ParentFoo };
" "
`; `;
@ -46,25 +45,15 @@ import type {Foo} from \'./types\';
// Follows non-destructured property access of \`require(\'Parent\')\` // Follows non-destructured property access of \`require(\'Parent\')\`
var Parent = require(\"./Parent\"); var Parent = require(\"./Parent\");
let ParentFoo; let ParentFoo;
({ ParentFoo } = Parent); ({ ParentFoo } = Parent);
ParentFoo; ParentFoo;
let ParentFoo2; let ParentFoo2;
ParentFoo2 = Parent; ParentFoo2 = Parent;
ParentFoo2; ParentFoo2;
let ParentFoo3 = Parent; let ParentFoo3 = Parent;
ParentFoo3; ParentFoo3;
let foo = require(\"./Parent\").ParentFoo.foo; let foo = require(\"./Parent\").ParentFoo.foo;
foo; foo;
import type {Foo} from \"./types\"; import type {Foo} from \"./types\";
" "
`; `;
@ -116,9 +105,7 @@ class C extends React.Component {
props: { x: string }; props: { x: string };
} }
let msg = \"hello\"; let msg = \"hello\";
<C x={msg}/>; <C x={msg}/>;
<div id={msg}/>; <div id={msg}/>;
" "
`; `;

View File

@ -28,7 +28,6 @@ require(\'b\');
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// @flow // @flow
require(\"./a.js\"); require(\"./a.js\");
require(\"b\"); require(\"b\");
" "
`; `;

View File

@ -113,18 +113,12 @@ var testGetterNoError1: number = foo.goodGetterNoAnnotation;
var testGetterNoError2: number = foo.goodGetterWithAnnotation; var testGetterNoError2: number = foo.goodGetterWithAnnotation;
var testGetterWithError1: string = foo.goodGetterNoAnnotation; var testGetterWithError1: string = foo.goodGetterNoAnnotation;
var testGetterWithError2: string = foo.goodGetterWithAnnotation; var testGetterWithError2: string = foo.goodGetterWithAnnotation;
foo.goodSetterNoAnnotation = 123; foo.goodSetterNoAnnotation = 123;
foo.goodSetterWithAnnotation = 123; foo.goodSetterWithAnnotation = 123;
foo.goodSetterNoAnnotation = \"hello\"; foo.goodSetterNoAnnotation = \"hello\";
foo.goodSetterWithAnnotation = \"hello\"; foo.goodSetterWithAnnotation = \"hello\";
var testSubtypingGetterAndSetter: number = foo.propWithSubtypingGetterAndSetter; var testSubtypingGetterAndSetter: number = foo.propWithSubtypingGetterAndSetter;
var testPropOverridenWithGetter: number = foo.propOverriddenWithGetter; var testPropOverridenWithGetter: number = foo.propOverriddenWithGetter;
foo.propOverriddenWithSetter = 123; foo.propOverriddenWithSetter = 123;
" "
`; `;
@ -252,19 +246,12 @@ var testGetterNoError1: number = obj.goodGetterNoAnnotation;
var testGetterNoError2: number = obj.goodGetterWithAnnotation; var testGetterNoError2: number = obj.goodGetterWithAnnotation;
var testGetterWithError1: string = obj.goodGetterNoAnnotation; var testGetterWithError1: string = obj.goodGetterNoAnnotation;
var testGetterWithError2: string = obj.goodGetterWithAnnotation; var testGetterWithError2: string = obj.goodGetterWithAnnotation;
obj.goodSetterNoAnnotation = 123; obj.goodSetterNoAnnotation = 123;
obj.goodSetterWithAnnotation = 123; obj.goodSetterWithAnnotation = 123;
obj.goodSetterNoAnnotation = \"hello\"; obj.goodSetterNoAnnotation = \"hello\";
obj.goodSetterWithAnnotation = \"hello\"; obj.goodSetterWithAnnotation = \"hello\";
var testSubtypingGetterAndSetter: number = obj.propWithSubtypingGetterAndSetter; var testSubtypingGetterAndSetter: number = obj.propWithSubtypingGetterAndSetter;
obj.exampleOfOrderOfGetterAndSetter = new C(); obj.exampleOfOrderOfGetterAndSetter = new C();
var testExampleOrOrderOfGetterAndSetterReordered: number = obj.exampleOfOrderOfGetterAndSetterReordered; var testExampleOrOrderOfGetterAndSetterReordered: number = obj.exampleOfOrderOfGetterAndSetterReordered;
" "
`; `;
@ -405,52 +392,42 @@ class Base {
this.x = value; this.x = value;
} }
} }
(class extends Base { (class extends Base {
get x(): B { get x(): B {
return b; return b;
} }
}); });
(class extends Base { (class extends Base {
set x(value: B): void {} set x(value: B): void {}
}); });
(class extends Base { (class extends Base {
get x(): C { get x(): C {
return c; return c;
} }
set x(value: A): void {} set x(value: A): void {}
}); });
(class extends Base { (class extends Base {
set pos(value: B): void {} set pos(value: B): void {}
}); });
(class extends Base { (class extends Base {
get pos(): C { get pos(): C {
return c; return c;
} }
}); });
(class extends Base { (class extends Base {
get neg(): B { get neg(): B {
return b; return b;
} }
}); });
(class extends Base { (class extends Base {
set neg(value: A): void {} set neg(value: A): void {}
}); });
(class extends Base { (class extends Base {
get: C; get: C;
}); });
(class extends Base { (class extends Base {
set: A; set: A;
}); });
(class extends Base { (class extends Base {
getset: B; getset: B;
}); });

View File

@ -22,11 +22,9 @@ module.exports = foo;
\'Required module not found\'. \'Required module not found\'.
*/ */
var _ = require(\"underscore\"); var _ = require(\"underscore\");
function foo(): string { function foo(): string {
return _.foo(); return _.foo();
} }
module.exports = foo; module.exports = foo;
" "
`; `;

View File

@ -21,7 +21,6 @@ class B extends A {
} }
class C extends A {} class C extends A {}
var a: A = new B(); var a: A = new B();
a.foo = function(): C { a.foo = function(): C {
return new C(); return new C();
}; };

View File

@ -23,7 +23,6 @@ class ClassFoo3 {
return new ClassFoo3(); return new ClassFoo3();
} }
} }
module.exports = ClassFoo3; module.exports = ClassFoo3;
" "
`; `;
@ -61,21 +60,15 @@ class ClassFoo4 {
} }
} }
class ClassFoo5 {} class ClassFoo5 {}
function givesAFoo4(): ClassFoo4 { function givesAFoo4(): ClassFoo4 {
return new ClassFoo4(); return new ClassFoo4();
} }
function givesAFoo5(): ClassFoo5 { function givesAFoo5(): ClassFoo5 {
return new ClassFoo5(); return new ClassFoo5();
} }
exports.ClassFoo4 = ClassFoo4; exports.ClassFoo4 = ClassFoo4;
exports.ClassFoo5 = ClassFoo5; exports.ClassFoo5 = ClassFoo5;
exports.foo4Inst = new ClassFoo4(); exports.foo4Inst = new ClassFoo4();
exports.foo5Inst = new ClassFoo5(); exports.foo5Inst = new ClassFoo5();
" "
`; `;
@ -301,29 +294,21 @@ import type ClassFoo1 from \"./ExportDefault_Class\";
import {foo1Inst} from \"./ExportDefault_Class\"; import {foo1Inst} from \"./ExportDefault_Class\";
var a1: ClassFoo1 = foo1Inst; var a1: ClassFoo1 = foo1Inst;
var a2: number = foo1Inst; var a2: number = foo1Inst;
new ClassFoo1(); new ClassFoo1();
import type {ClassFoo2} from \"./ExportNamed_Class\"; import type {ClassFoo2} from \"./ExportNamed_Class\";
import {foo2Inst} from \"./ExportNamed_Class\"; import {foo2Inst} from \"./ExportNamed_Class\";
var b1: ClassFoo2 = foo2Inst; var b1: ClassFoo2 = foo2Inst;
var b2: number = foo2Inst; var b2: number = foo2Inst;
new ClassFoo2(); new ClassFoo2();
import type ClassFoo3T from \"./ExportCJSDefault_Class\"; import type ClassFoo3T from \"./ExportCJSDefault_Class\";
import ClassFoo3 from \"./ExportCJSDefault_Class\"; import ClassFoo3 from \"./ExportCJSDefault_Class\";
var c1: ClassFoo3T = new ClassFoo3(); var c1: ClassFoo3T = new ClassFoo3();
new ClassFoo3T(); new ClassFoo3T();
import type {ClassFoo4, ClassFoo5} from \"./ExportCJSNamed_Class\"; import type {ClassFoo4, ClassFoo5} from \"./ExportCJSNamed_Class\";
import {foo4Inst, foo5Inst} from \"./ExportCJSNamed_Class\"; import {foo4Inst, foo5Inst} from \"./ExportCJSNamed_Class\";
var d1: ClassFoo4 = foo4Inst; var d1: ClassFoo4 = foo4Inst;
var d2: number = foo4Inst; var d2: number = foo4Inst;
new ClassFoo4(); new ClassFoo4();
var d3: typeof ClassFoo5 = foo5Inst; var d3: typeof ClassFoo5 = foo5Inst;
import type {AliasFoo3} from \"./ExportNamed_Alias\"; import type {AliasFoo3} from \"./ExportNamed_Alias\";
import {givesAFoo3Obj} from \"./ExportNamed_Alias\"; import {givesAFoo3Obj} from \"./ExportNamed_Alias\";
@ -332,7 +317,6 @@ var e2: number = givesAFoo3Obj();
var e3: typeof AliasFoo3 = givesAFoo3Obj(); var e3: typeof AliasFoo3 = givesAFoo3Obj();
import type {numValue} from \"./ExportsANumber\"; import type {numValue} from \"./ExportsANumber\";
import type ClassFoo6 from \"./issue-359\"; import type ClassFoo6 from \"./issue-359\";
function foo() { function foo() {
ClassFoo6; ClassFoo6;
} }

View File

@ -23,7 +23,6 @@ class ClassFoo3 {
return new ClassFoo3(); return new ClassFoo3();
} }
} }
module.exports = ClassFoo3; module.exports = ClassFoo3;
" "
`; `;
@ -51,7 +50,6 @@ exports.ClassFoo4 = ClassFoo4;
* @flow * @flow
*/ */
class ClassFoo4 {} class ClassFoo4 {}
exports.ClassFoo4 = ClassFoo4; exports.ClassFoo4 = ClassFoo4;
" "
`; `;
@ -332,16 +330,12 @@ import typeof ClassFoo1T from \"./ExportDefault_Class\";
import ClassFoo1 from \"./ExportDefault_Class\"; import ClassFoo1 from \"./ExportDefault_Class\";
var a1: ClassFoo1T = ClassFoo1; var a1: ClassFoo1T = ClassFoo1;
var a2: ClassFoo1T = new ClassFoo1(); var a2: ClassFoo1T = new ClassFoo1();
new ClassFoo1T(); new ClassFoo1T();
import typeof {ClassFoo2 as ClassFoo2T} from \"./ExportNamed_Class\"; import typeof {ClassFoo2 as ClassFoo2T} from \"./ExportNamed_Class\";
import {ClassFoo2} from \"./ExportNamed_Class\"; import {ClassFoo2} from \"./ExportNamed_Class\";
var b1: ClassFoo2T = ClassFoo2; var b1: ClassFoo2T = ClassFoo2;
var b2: ClassFoo2T = new ClassFoo2(); var b2: ClassFoo2T = new ClassFoo2();
new ClassFoo2T(); new ClassFoo2T();
import typeof ClassFoo3T from \"./ExportCJSDefault_Class\"; import typeof ClassFoo3T from \"./ExportCJSDefault_Class\";
import ClassFoo3 from \"./ExportCJSDefault_Class\"; import ClassFoo3 from \"./ExportCJSDefault_Class\";
var c1: ClassFoo3T = ClassFoo3; var c1: ClassFoo3T = ClassFoo3;

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