Make all tests pass the crash test and fix a few more bugs

master
James Long 2016-12-27 21:40:04 -05:00
parent 9acd34d67d
commit 88dc2681f6
215 changed files with 21774 additions and 5363 deletions

View File

@ -1,24 +1,35 @@
const assert = require("assert");
function assertDoc(val) {
assert(
typeof val === "string" ||
(val != null &&
typeof val.type === "string"),
"Value is a valid document"
);
}
function fromString(text) {
if(typeof text !== "string") {
return Object.prototype.toString.call(text);
}
return text;
return "" + text;
}
function concat(parts) {
parts.forEach(assertDoc);
return { type: 'concat', parts };
}
function indent(n, contents) {
assertDoc(contents);
return { type: 'indent', contents, n };
}
function group(contents) {
assertDoc(contents);
return { type: 'group', contents };
}
function multilineGroup(doc) {
assertDoc(doc);
const shouldBreak = hasHardLine(doc);
return { type: 'group', contents: doc, break: shouldBreak };
}
@ -48,6 +59,9 @@ function iterDoc(topDoc, func) {
}
}
else if(doc.type !== "line") {
if(doc.contents == null) {
console.log("JWL", doc);
}
docs.push(doc.contents);
}
}

View File

@ -314,7 +314,7 @@ function genericPrintNoParens(path, options, print) {
case "Identifier":
return concat([
fromString(n.name, options),
n.name,
path.call(print, "typeAnnotation")
]);
@ -706,7 +706,7 @@ function genericPrintNoParens(path, options, print) {
]));
case "SequenceExpression":
return fromString(", ").join(path.map(print, "expressions"));
return join(", ", path.map(print, "expressions"));
case "ThisExpression":
return fromString("this");
@ -727,7 +727,7 @@ function genericPrintNoParens(path, options, print) {
if (typeof n.value !== "string")
return fromString(n.value, options);
return fromString(nodeStr(n.value, options), options);
return nodeStr(n.value, options);
case "Directive": // Babel 6
return path.call(print, "value");
@ -790,7 +790,7 @@ function genericPrintNoParens(path, options, print) {
" ",
printed[0],
indent(options.tabWidth,
join(concat(",", line),
join(concat([",", line]),
printed.slice(1)))
];
@ -1096,7 +1096,7 @@ function genericPrintNoParens(path, options, print) {
return concat([
openingLines,
indent(options.tabWidth, concat(mostChildren)),
lastChild,
lastChild || "",
closingLines
]);
@ -1266,12 +1266,12 @@ function genericPrintNoParens(path, options, print) {
return concat(parts);
}
return fromString("");
return "";
case "TupleTypeAnnotation":
return concat([
"[",
path.map(print, "types"),
concat(path.map(print, "types")),
"]"
]);
@ -1428,7 +1428,7 @@ function genericPrintNoParens(path, options, print) {
]);
case "IntersectionTypeAnnotation":
return fromString(" & ").join(path.map(print, "types"));
return join(" & ", path.map(print, "types"));
case "NullableTypeAnnotation":
return concat([

View File

@ -8,7 +8,7 @@ function bar() {
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function foo() {
while ([object Boolean]) {
while (true) {
break;
}
}
@ -16,7 +16,7 @@ function bar() {
L:
do {
continue L;
} while ([object Boolean]);
} while (false);
}
"
`;
@ -33,8 +33,8 @@ function bar(x: number) {
}
function foo() {
var x = [object Null];
if (x == [object Null])
var x = null;
if (x == null)
return;
bar(x);
}

View File

@ -6,12 +6,12 @@ var bar: (str:number, i:number)=> string = foo;
var qux = function(str:string, i:number):number { return foo(str,i); }
var obj: {str:string; i:number; j:boolean} = {str: "...", i: "...", k: false};
var obj: {str:string; i:number; j:boolean} = {str: \"...\", i: \"...\", k: false};
var arr: Array<number> = [1,2,"..."];
var arr: Array<number> = [1,2,\"...\"];
// array sugar
var array: number[] = [1,2,"..."];
var array: number[] = [1,2,\"...\"];
var matrix: number[][] = [[1,2],[3,4]];
var matrix_parens: (number[])[] = matrix;
@ -21,15 +21,15 @@ var nullable_array_parens: ?(number[]) = nullable_array;
var array_of_nullable: (?number)[] = [null, 3];
var array_of_tuple: [number, string][] = [[0, "foo"], [1, "bar"]];
var array_of_tuple: [number, string][] = [[0, \"foo\"], [1, \"bar\"]];
var array_of_tuple_parens: ([number, string])[] = array_of_tuple;
type ObjType = { 'bar-foo': string; 'foo-bar': number; };
var test_obj: ObjType = { 'bar-foo': '23' };
type ObjType = { \'bar-foo\': string; \'foo-bar\': number; };
var test_obj: ObjType = { \'bar-foo\': \'23\' };
// param type annos are strict UBs like var type annos
function param_anno(n:number):void {
n = "hey"; // error
n = \"hey\"; // error
}
// another error on param UB, more typical of www (mis)use-cases
@ -38,7 +38,7 @@ function param_anno2(
batchRequests: Array<{method: string; path: string; params: ?Object}>,
): void {
// error below, since we're assigning elements to batchRequests
// error below, since we\'re assigning elements to batchRequests
// which lack a path property.
// just assign result to new var instead of reassigning to param.
@ -65,7 +65,7 @@ function barfoo(n : number | null | void) : ?number { return n; }
// error
// another error on param UB, more typical of www (mis)use-cases
// this one cribbed from API.atlas.js
// error below, since we're assigning elements to batchRequests
// error below, since we\'re assigning elements to batchRequests
// which lack a path property.
// just assign result to new var instead of reassigning to param.
// Transform the requests to the format the Graph API expects.
@ -78,29 +78,23 @@ var qux = function(str: string, i: number): number {
return foo(str, i);
};
var obj: { str: string, i: number, j: boolean } = {
str: "...",
i: "...",
k: [object Boolean]
str: \"...\",
i: \"...\",
k: false
};
var arr: Array<number> = [ [object Number], [object Number], "..." ];
var array: number[] = [ [object Number], [object Number], "..." ];
var matrix: number[][] = [
[ [object Number], [object Number] ],
[ [object Number], [object Number] ]
];
var arr: Array<number> = [ 1, 2, \"...\" ];
var array: number[] = [ 1, 2, \"...\" ];
var matrix: number[][] = [ [ 1, 2 ], [ 3, 4 ] ];
var matrix_parens: number[][] = matrix;
var nullable_array: ?number[] = [object Null];
var nullable_array: ?number[] = null;
var nullable_array_parens: ?number[] = nullable_array;
var array_of_nullable: ?number[] = [ [object Null], [object Number] ];
var array_of_tuple: [][] = [
[ [object Number], "foo" ],
[ [object Number], "bar" ]
];
var array_of_tuple_parens: [][] = array_of_tuple;
type ObjType = { "bar-foo": string, "foo-bar": number };
var test_obj: ObjType = { "bar-foo": "23" };
var array_of_nullable: ?number[] = [ null, 3 ];
var array_of_tuple: [numberstring][] = [ [ 0, \"foo\" ], [ 1, \"bar\" ] ];
var array_of_tuple_parens: [numberstring][] = array_of_tuple;
type ObjType = { \"bar-foo\": string, \"foo-bar\": number };
var test_obj: ObjType = { \"bar-foo\": \"23\" };
function param_anno(n: number): void {
n = "hey";
n = \"hey\";
}
function param_anno2(
batchRequests: Array<{ method: string, path: string, params: ?Object }>
@ -115,8 +109,8 @@ function param_anno2(
}
);
}
var toz: null = [object Number];
var zer: null = [object Null];
var toz: null = 3;
var zer: null = null;
function foobar(n: ?number): number | null | void {
return n;
}
@ -147,9 +141,9 @@ function foo() {
// looked up above
// ok (no confusion across scopes)
// looked up above
let myClassInstance: MyClass = [object Null];
let myClassInstance: MyClass = null;
function bar(): MyClass {
return [object Null];
return null;
}
class MyClass {}
function foo() {
@ -183,7 +177,7 @@ exports[`test leak.js 1`] = `
* annotation for y and stop. We should type the body of bar() with the type
* annotation of y.
*
* However, the leaky type annotation meant that we were flowing x's type to y
* However, the leaky type annotation meant that we were flowing x\'s type to y
* and type checking the body of bar() using the stricter dictionary type,
* leading to an error.
*/
@ -205,7 +199,7 @@ function bar(y: MyObj): string {
* annotation for y and stop. We should type the body of bar() with the type
* annotation of y.
*
* However, the leaky type annotation meant that we were flowing x's type to y
* However, the leaky type annotation meant that we were flowing x\'s type to y
* and type checking the body of bar() using the stricter dictionary type,
* leading to an error.
*/
@ -261,7 +255,9 @@ declare class Map {
insertWith: : (fn: Merge<V>, k: K, v: V) => Map<K, V>
}
declare function foldr(fn: (a: A, b: B) => B, b: B, as: A[]): B;
function insertMany<K, V>(merge: Merge<V>, vs: [][], m: Map<K, V>): Map<K, V> {
function insertMany<K, V>(
merge: Merge<V>, vs: [KV][], m: Map<K, V>
): Map<K, V> {
function f([ k, v ], m: Map<K, V>): Map<K, V> {
return m.insertWith(merge, k, v);
}
@ -270,7 +266,7 @@ function insertMany<K, V>(merge: Merge<V>, vs: [][], m: Map<K, V>): Map<K, V> {
class Foo<A> {
bar<B>() {
return function(a: A, b: B, c: C): void {
([ a, b, c ]: []);
([ a, b, c ]: [ABC]);
};
}
}
@ -278,10 +274,10 @@ class Foo<A> {
`;
exports[`test test.js 1`] = `
"var C = require('./other');
"var C = require(\'./other\');
((0: C): string);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
var C = require("./other");
(([object Number]: C): string);
var C = require(\"./other\");
((0: C): string);
"
`;

View File

@ -13,21 +13,21 @@ type T = any;
export default class {
p: T;
constructor() {
this.p = [object Number];
this.p = 0;
}
}
"
`;
exports[`test B.js 1`] = `
"import A from "./A"
"import A from \"./A\"
class B extends A {
p: string; // OK, string ~> any
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// OK, string ~> any
import A from "./A";
import A from \"./A\";
class B extends A {
p: string;
}

View File

@ -4,7 +4,7 @@ exports[`test A.js 1`] = `
* @flow
*/
import type T from "T";
import type T from \"T\";
export default class {
p: T;
@ -18,11 +18,11 @@ export default class {
* @providesModule A
* @flow
*/
import type T from "T";
import type T from \"T\";
export default class {
p: T;
constructor() {
this.p = [object Number];
this.p = 0;
}
}
"
@ -33,7 +33,7 @@ exports[`test B.js 1`] = `
* @flow
*/
import A from "A"
import A from \"A\"
class B extends A {
p: string; // OK, string ~> any
@ -43,7 +43,7 @@ class B extends A {
* @flow
*/
// OK, string ~> any
import A from "A";
import A from \"A\";
class B extends A {
p: string;
}

View File

@ -19,9 +19,9 @@ function bar(x: any): mixed {
function qux(x: mixed): any {
return x;
}
var x: string = foo([object Number]);
var y: string = bar([object Number]);
var z: string = qux([object Number]);
var x: string = foo(0);
var y: string = bar(0);
var z: string = qux(0);
"
`;
@ -77,10 +77,10 @@ function qux(x: $FlowFixMe<number>): $FlowFixMe<number> {
function baz(x: $FlowFixMe<nnumber>): $FlowFixMe<number> {
return x;
}
var x: string = foo([object Number]);
var y: string = bar([object Number]);
var z: string = qux([object Number]);
var w: string = baz([object Number]);
var x: string = foo(0);
var y: string = bar(0);
var z: string = qux(0);
var w: string = baz(0);
"
`;
@ -126,10 +126,10 @@ function qux(x: $FlowIssue<number>): $FlowIssue<number> {
function baz(x: $FlowIssue<nnumber>): $FlowIssue<number> {
return x;
}
var x: string = foo([object Number]);
var y: string = bar([object Number]);
var z: string = qux([object Number]);
var w: string = baz([object Number]);
var x: string = foo(0);
var y: string = bar(0);
var z: string = qux(0);
var w: string = baz(0);
"
`;
@ -156,14 +156,14 @@ function foo(c: C, x: any): string {
return c.bar(0, y); // should be able to select first case and error
}
var any_fun1 = require('./nonflowfile');
var any_fun1 = require(\'./nonflowfile\');
function bar1(x: mixed) {
if (any_fun1(x)) {
(x: boolean);
}
}
var any_fun2 = require('./anyexportflowfile');
var any_fun2 = require(\'./anyexportflowfile\');
function bar2(x: mixed) {
if (any_fun2(x)) {
(x: boolean);
@ -178,15 +178,15 @@ declare class C {
}
function foo(c: C, x: any): string {
let y = x.y;
return c.bar([object Number], y);
return c.bar(0, y);
}
var any_fun1 = require("./nonflowfile");
var any_fun1 = require(\"./nonflowfile\");
function bar1(x: mixed) {
if (any_fun1(x)) {
(x: boolean);
}
}
var any_fun2 = require("./anyexportflowfile");
var any_fun2 = require(\"./anyexportflowfile\");
function bar2(x: mixed) {
if (any_fun2(x)) {
(x: boolean);

View File

@ -8,7 +8,7 @@ function str(x:string) { }
function foo() {
var x = 0;
var y = "...";
var y = \"...\";
var z = {};
num(x+x);
num(x+y); // error
@ -54,20 +54,20 @@ num(true + null); // === 1
num(undefined + true); // === NaN
num(true + undefined); // === NaN
str("foo" + true); // error
str(true + "foo"); // error
str("foo" + null); // error
str(null + "foo"); // error
str("foo" + undefined); // error
str(undefined + "foo"); // error
str(\"foo\" + true); // error
str(true + \"foo\"); // error
str(\"foo\" + null); // error
str(null + \"foo\"); // error
str(\"foo\" + undefined); // error
str(undefined + \"foo\"); // error
let tests = [
function(x: mixed, y: mixed) {
(x + y); // error
(x + 0); // error
(0 + x); // error
(x + ""); // error
("" + x); // error
(x + \"\"); // error
(\"\" + x); // error
(x + {}); // error
({} + x); // error
},
@ -78,8 +78,8 @@ let tests = [
function() {
((1 + {}): number); // error: object !~> number
(({} + 1): number); // error: object !~> number
(("1" + {}): string); // error: object !~> string
(({} + "1"): string); // error: object !~> string
((\"1\" + {}): string); // error: object !~> string
(({} + \"1\"): string); // error: object !~> string
},
function(x: any, y: number, z: string) {
@ -139,8 +139,8 @@ function str(x: string) {
}
function foo() {
var x = [object Number];
var y = "...";
var x = 0;
var y = \"...\";
var z = {};
num(x + x);
num(x + y);
@ -166,37 +166,37 @@ function bar4(x: ?number, y: number) {
function bar5(x: number, y: ?number) {
num(x + y);
}
num([object Null] + [object Null]);
num(null + null);
num(undefined + undefined);
num([object Null] + [object Number]);
num([object Number] + [object Null]);
num(undefined + [object Number]);
num([object Number] + undefined);
num([object Null] + [object Boolean]);
num([object Boolean] + [object Null]);
num(undefined + [object Boolean]);
num([object Boolean] + undefined);
str("foo" + [object Boolean]);
str([object Boolean] + "foo");
str("foo" + [object Null]);
str([object Null] + "foo");
str("foo" + undefined);
str(undefined + "foo");
num(null + 1);
num(1 + null);
num(undefined + 1);
num(1 + undefined);
num(null + true);
num(true + null);
num(undefined + true);
num(true + undefined);
str(\"foo\" + true);
str(true + \"foo\");
str(\"foo\" + null);
str(null + \"foo\");
str(\"foo\" + undefined);
str(undefined + \"foo\");
let tests = [
function(x: mixed, y: mixed) {
x + y;
x + [object Number];
[object Number] + x;
x + "";
"" + x;
x + 0;
0 + x;
x + \"\";
\"\" + x;
x + {};
({}) + x;
},
function() {
([object Number] + {}: number);
({} + [object Number]: number);
("1" + {}: string);
({} + "1": string);
(1 + {}: number);
({} + 1: number);
(\"1\" + {}: string);
({} + \"1\": string);
},
function(x: any, y: number, z: string) {
(x + y: string);
@ -214,7 +214,7 @@ exports[`test exponent.js 1`] = `
let x: number = 2 ** 3;
x **= 4;
let y: string = "123";
let y: string = \"123\";
y **= 2; // error
1 + 2 ** 3 + 4;
@ -223,13 +223,13 @@ y **= 2; // error
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/* @flow */
// error
let x: number = [object Number] ** [object Number];
x **= [object Number];
let y: string = "123";
y **= [object Number];
[object Number] + [object Number] ** [object Number] + [object Number];
[object Number] ** [object Number];
-[object Number] ** [object Number];
let x: number = 2 ** 3;
x **= 4;
let y: string = \"123\";
y **= 2;
1 + 2 ** 3 + 4;
2 ** 2;
-2 ** 2;
"
`;
@ -277,7 +277,7 @@ num(1 * null);
let x: number = 2 * 3;
x *= 4;
let y: string = "123";
let y: string = \"123\";
y *= 2; // error
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/* @flow */
@ -285,12 +285,12 @@ y *= 2; // error
function num(x: number) {
}
num([object Null] * [object Number]);
num([object Number] * [object Null]);
let x: number = [object Number] * [object Number];
x *= [object Number];
let y: string = "123";
y *= [object Number];
num(null * 1);
num(1 * null);
let x: number = 2 * 3;
x *= 4;
let y: string = \"123\";
y *= 2;
"
`;
@ -298,14 +298,14 @@ exports[`test relational.js 1`] = `
"/* @flow */
(1 < 2);
(1 < "foo"); // error
("foo" < 1); // error
("foo" < "bar");
(1 < \"foo\"); // error
(\"foo\" < 1); // error
(\"foo\" < \"bar\");
(1 < {foo: 1}); // error
({foo: 1} < 1); // error
({foo: 1} < {foo: 1}); // error
("foo" < {foo: 1}); // error
({foo: 1} < "foo"); // error
(\"foo\" < {foo: 1}); // error
({foo: 1} < \"foo\"); // error
var x = (null : ?number);
(1 < x); // 2 errors: null !~> number; undefined !~> number
@ -340,24 +340,24 @@ let tests = [
// error
// error
// error
[object Number] < [object Number];
[object Number] < "foo";
"foo" < [object Number];
"foo" < "bar";
[object Number] < { foo: [object Number] };
({ foo: [object Number] }) < [object Number];
({ foo: [object Number] }) < { foo: [object Number] };
"foo" < { foo: [object Number] };
({ foo: [object Number] }) < "foo";
var x = ([object Null]: ?number);
[object Number] < x;
x < [object Number];
[object Null] < [object Null];
undefined < [object Null];
[object Null] < undefined;
1 < 2;
1 < \"foo\";
\"foo\" < 1;
\"foo\" < \"bar\";
1 < { foo: 1 };
({ foo: 1 }) < 1;
({ foo: 1 }) < { foo: 1 };
\"foo\" < { foo: 1 };
({ foo: 1 }) < \"foo\";
var x = (null: ?number);
1 < x;
x < 1;
null < null;
undefined < null;
null < undefined;
undefined < undefined;
NaN < [object Number];
[object Number] < NaN;
NaN < 1;
1 < NaN;
NaN < NaN;
let tests = [
function(x: any, y: number, z: string) {

View File

@ -14,7 +14,7 @@ function filterOutVoids<T>(arr: Array<?T>): Array<T> {
return arr.filter(Boolean);
}
function filterOutSmall(arr: Array<?number>): Array<?number> {
return arr.filter(num => num && num > [object Number]);
return arr.filter(num => num && num > 10);
}
"
`;
@ -24,7 +24,7 @@ exports[`test test2.js 1`] = `
function filterItems(items: Array<string|number>): Array<string|number> {
return items.map(item => {
if (typeof item === 'string') {
if (typeof item === \'string\') {
return item.length > 2 ? item : null;
} else {
return item*10;
@ -32,7 +32,7 @@ function filterItems(items: Array<string|number>): Array<string|number> {
}).filter(Boolean);
}
const filteredItems = filterItems(['foo', 'b', 1, 2]);
const filteredItems = filterItems([\'foo\', \'b\', 1, 2]);
console.log(filteredItems);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ -40,17 +40,15 @@ console.log(filteredItems);
function filterItems(items: Array<string | number>): Array<string | number> {
return items.map(
item => {
if (typeof item === "string") {
return (item.length > [object Number] ? item : [object Null]);
if (typeof item === \"string\") {
return (item.length > 2 ? item : null);
} else {
return item * [object Number];
return item * 10;
}
}
).filter(Boolean);
}
const filteredItems = filterItems(
[ "foo", "b", [object Number], [object Number] ]
);
const filteredItems = filterItems([ \"foo\", \"b\", 1, 2 ]);
console.log(filteredItems);
"
`;

View File

@ -5,15 +5,15 @@ var C = [1,2,3];
B.sort((a, b) => a - b);
C.sort((a, b) => a - b);
var x: Array<string> = ['1', '2'];
var y: Array<string> = ['3', ...x];
var x: Array<string> = [\'1\', \'2\'];
var y: Array<string> = [\'3\', ...x];
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
var A = [ [object Number], [object Number], [object Number] ];
var A = [ 1, 2, 3 ];
var B = [ ...A ];
var C = [ [object Number], [object Number], [object Number] ];
var C = [ 1, 2, 3 ];
B.sort((a, b) => a - b);
C.sort((a, b) => a - b);
var x: Array<string> = [ "1", "2" ];
var y: Array<string> = [ "3", ...x ];
var x: Array<string> = [ \"1\", \"2\" ];
var y: Array<string> = [ \"3\", ...x ];
"
`;

View File

@ -3,23 +3,23 @@ exports[`test array_lib.js 1`] = `
function foo(x:string) { }
var a = [0];
var b = a.map(function (x) { foo(x); return "" + x; });
var b = a.map(function (x) { foo(x); return \"\" + x; });
var c: number = a[0];
var d: number = b[0];
var e:Array<string> = a.reverse();
var f = [""];
var f = [\"\"];
var g:number = f.map(function () { return 0; })[0];
var h: Array<number> = [1,2,3];
var i: Array<string> = ['a', 'b', 'c'];
var i: Array<string> = [\'a\', \'b\', \'c\'];
var j: Array<number | string> = h.concat(i);
var k: Array<number> = h.concat(h);
var l: Array<number> = h.concat(1,2,3);
var m: Array<number | string> = h.concat('a', 'b', 'c');
var n: Array<number> = h.concat('a', 'b', 'c'); // Error
var m: Array<number | string> = h.concat(\'a\', \'b\', \'c\');
var n: Array<number> = h.concat(\'a\', \'b\', \'c\'); // Error
function reduce_test() {
/* Adapted from the following source:
@ -44,13 +44,13 @@ function reduce_test() {
/* Added later, because the above is insufficient */
// acc is element type of array when no init is provided
[""].reduce((acc, str) => acc * str.length); // error, string ~> number
[""].reduceRight((acc, str) => acc * str.length); // error, string ~> number
[\"\"].reduce((acc, str) => acc * str.length); // error, string ~> number
[\"\"].reduceRight((acc, str) => acc * str.length); // error, string ~> number
}
function from_test() {
var a: Array<string> = Array.from([1, 2, 3], function(val, index) {
return index % 2 ? "foo" : String(val);
return index % 2 ? \"foo\" : String(val);
});
var b: Array<string> = Array.from([1, 2, 3], function(val) {
return String(val);
@ -69,88 +69,63 @@ function from_test() {
function foo(x: string) {
}
var a = [ [object Number] ];
var a = [ 0 ];
var b = a.map(
function(x) {
foo(x);
return "" + x;
return \"\" + x;
}
);
var c: number = a[[object Number]];
var d: number = b[[object Number]];
var c: number = a[0];
var d: number = b[0];
var e: Array<string> = a.reverse();
var f = [ "" ];
var f = [ \"\" ];
var g: number = f.map(
function() {
return [object Number];
return 0;
}
)[[object Number]];
var h: Array<number> = [ [object Number], [object Number], [object Number] ];
var i: Array<string> = [ "a", "b", "c" ];
)[0];
var h: Array<number> = [ 1, 2, 3 ];
var i: Array<string> = [ \"a\", \"b\", \"c\" ];
var j: Array<number | string> = h.concat(i);
var k: Array<number> = h.concat(h);
var l: Array<number> = h.concat(
[object Number],
[object Number],
[object Number]
);
var m: Array<number | string> = h.concat("a", "b", "c");
var n: Array<number> = h.concat("a", "b", "c");
var l: Array<number> = h.concat(1, 2, 3);
var m: Array<number | string> = h.concat(\"a\", \"b\", \"c\");
var n: Array<number> = h.concat(\"a\", \"b\", \"c\");
function reduce_test() {
[
[object Number],
[object Number],
[object Number],
[object Number],
[object Number]
].reduce(
[ 0, 1, 2, 3, 4 ].reduce(
function(previousValue, currentValue, index, array) {
return previousValue + currentValue + array[index];
}
);
[
[object Number],
[object Number],
[object Number],
[object Number],
[object Number]
].reduce(
[ 0, 1, 2, 3, 4 ].reduce(
function(previousValue, currentValue, index, array) {
return previousValue + currentValue + array[index];
},
[object Number]
10
);
var total = [
[object Number],
[object Number],
[object Number],
[object Number]
].reduce(
var total = [ 0, 1, 2, 3 ].reduce(
function(a, b) {
return a + b;
}
);
var flattened = [
[ [object Number], [object Number] ],
[ [object Number], [object Number] ],
[ [object Number], [object Number] ]
].reduce(
var flattened = [ [ 0, 1 ], [ 2, 3 ], [ 4, 5 ] ].reduce(
function(a, b) {
return a.concat(b);
}
);
[ "" ].reduce((acc, str) => acc * str.length);
[ "" ].reduceRight((acc, str) => acc * str.length);
[ \"\" ].reduce((acc, str) => acc * str.length);
[ \"\" ].reduceRight((acc, str) => acc * str.length);
}
function from_test() {
var a: Array<string> = Array.from(
[ [object Number], [object Number], [object Number] ],
[ 1, 2, 3 ],
function(val, index) {
return (index % [object Number] ? "foo" : String(val));
return (index % 2 ? \"foo\" : String(val));
}
);
var b: Array<string> = Array.from(
[ [object Number], [object Number], [object Number] ],
[ 1, 2, 3 ],
function(val) {
return String(val);
}

View File

@ -6,7 +6,7 @@ function foo(x:string) { }
var a = [];
a[0] = 1;
a[1] = "...";
a[1] = \"...\";
foo(a[1]);
var y;
@ -32,12 +32,12 @@ var abig2: Array<{x:number; y:number}> = [
{x:0, y:0},
{x:0, y:0},
{x:0, y:0, a:true},
{x:0, y:0, b:"hey"},
{x:0, y:0, b:\"hey\"},
{x:0, y:0, c:1},
{x:0, y:0, c:"hey"}
{x:0, y:0, c:\"hey\"}
];
module.exports = "arrays";
module.exports = \"arrays\";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/* @providesModule Arrays */
// for literals, composite element type is union of individuals
@ -46,49 +46,33 @@ function foo(x: string) {
}
var a = [ ];
a[[object Number]] = [object Number];
a[[object Number]] = "...";
foo(a[[object Number]]);
a[0] = 1;
a[1] = \"...\";
foo(a[1]);
var y;
a.forEach(x => y = x);
var alittle: Array<?number> = [
[object Number],
[object Number],
[object Number],
[object Number],
[object Null]
];
var abig: Array<?number> = [
[object Number],
[object Number],
[object Number],
[object Number],
[object Number],
[object Number],
[object Number],
[object Number],
[object Null]
];
var alittle: Array<?number> = [ 0, 1, 2, 3, null ];
var abig: Array<?number> = [ 0, 1, 2, 3, 4, 5, 6, 8, null ];
var abig2: Array<{ x: number, y: number }> = [
{ x: [object Number], y: [object Number] },
{ x: [object Number], y: [object Number] },
{ x: [object Number], y: [object Number] },
{ x: [object Number], y: [object Number] },
{ x: [object Number], y: [object Number] },
{ x: [object Number], y: [object Number] },
{ x: [object Number], y: [object Number] },
{ x: [object Number], y: [object Number] },
{ x: [object Number], y: [object Number] },
{ x: [object Number], y: [object Number] },
{ x: [object Number], y: [object Number] },
{ x: [object Number], y: [object Number] },
{ x: [object Number], y: [object Number] },
{ x: [object Number], y: [object Number], a: [object Boolean] },
{ x: [object Number], y: [object Number], b: "hey" },
{ x: [object Number], y: [object Number], c: [object Number] },
{ x: [object Number], y: [object Number], c: "hey" }
{ x: 0, y: 0 },
{ x: 0, y: 0 },
{ x: 0, y: 0 },
{ x: 0, y: 0 },
{ x: 0, y: 0 },
{ x: 0, y: 0 },
{ x: 0, y: 0 },
{ x: 0, y: 0 },
{ x: 0, y: 0 },
{ x: 0, y: 0 },
{ x: 0, y: 0 },
{ x: 0, y: 0 },
{ x: 0, y: 0 },
{ x: 0, y: 0, a: true },
{ x: 0, y: 0, b: \"hey\" },
{ x: 0, y: 0, c: 1 },
{ x: 0, y: 0, c: \"hey\" }
];
module.exports = "arrays";
module.exports = \"arrays\";
"
`;
@ -106,7 +90,7 @@ arr[day] = 0;
// error: number ~> string
var arr = [ ];
var day = new Date();
arr[day] = [object Number];
arr[day] = 0;
(arr[day]: string);
"
`;

View File

@ -9,7 +9,7 @@ var bad = (x: number): string => x; // Error!
var ident = <T>(x: T): T => x;
(ident(1): number);
(ident("hi"): number); // Error
(ident(\"hi\"): number); // Error
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/**
* @flow
@ -19,8 +19,8 @@ var ident = <T>(x: T): T => x;
var add = (x: number, y: number): number => x + y;
var bad = (x: number): string => x;
var ident = <T>(x: T): T => x;
(ident([object Number]): number);
(ident("hi"): number);
(ident(1): number);
(ident(\"hi\"): number);
"
`;
@ -31,7 +31,7 @@ exports[`test arrows.js 1`] = `
): Image {
var maxPixelWidth = maxWidth;
//images = images.sort(function (a, b) { return a.width - b.width });
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) ||
images[images.length - 1];
}
@ -41,9 +41,9 @@ function selectBestEffortImageForWidth(
maxWidth: number, images: Array<Image>
): Image {
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) ||
images[images.length - [object Number]];
images[images.length - 1];
}
"
`;

View File

@ -3,7 +3,7 @@ exports[`test foo.js 1`] = `
/asdf/g;
// JSX also requires a lexer mode change
<div attr1='42' attr2={'asdf'} >asdf</div>;
<div attr1=\'42\' attr2={\'asdf\'} >asdf</div>;
// Async arrow functions require backtracking
var a = async () => 42;
@ -20,10 +20,10 @@ a;
// Async arrow functions require backtracking
// Type annotations have a special lex mode
// Token stream should continue even with parse errors
[object RegExp];
<div attr1="42" attr2={"asdf"}>asdf</div>;
var a = async () => [object Number];
var a: number = [object Number];
/asdf/g;
<div attr1=\"42\" attr2={\"asdf\"}>asdf</div>;
var a = async () => 42;
var a: number = 42;
var var;
a;
"

View File

@ -1,8 +1,8 @@
exports[`test async.js 1`] = `
"// @flow
// "For async functions, a Promise<T> is returned,
// and the type of return expressions must be T."
// \"For async functions, a Promise<T> is returned,
// and the type of return expressions must be T.\"
//
async function f0(): Promise<number> {
@ -27,7 +27,7 @@ async function f3(p: Promise<number>): Promise<number> {
}
// TODO: this is one of those bad generic errors, currently:
// "inconsistent use of library definitions" with two core.js locs
// \"inconsistent use of library definitions\" with two core.js locs
async function f4(p: Promise<number>): Promise<bool> {
return await p; // error, number != bool
}
@ -53,14 +53,14 @@ var obj = { f: async () => await 1 };
var objf : () => Promise<number> = obj.f;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// @flow
// "For async functions, a Promise<T> is returned,
// and the type of return expressions must be T."
// \"For async functions, a Promise<T> is returned,
// and the type of return expressions must be T.\"
//
// error, number != bool
// await: (p: Promise<T> | T) => T
//
// TODO: this is one of those bad generic errors, currently:
// "inconsistent use of library definitions" with two core.js locs
// \"inconsistent use of library definitions\" with two core.js locs
// error, number != bool
// async arrow functions
//
@ -69,14 +69,14 @@ var objf : () => Promise<number> = obj.f;
// error, void != Promise<void>
// async function props
async function f0(): Promise<number> {
return [object Number];
return 1;
}
async function f1(): Promise<boolean> {
return [object Number];
return 1;
}
async function f2(p: Promise<number>): Promise<number> {
var x: number = await p;
var y: number = await [object Number];
var y: number = await 1;
return x + y;
}
async function f3(p: Promise<number>): Promise<number> {
@ -85,10 +85,10 @@ async function f3(p: Promise<number>): Promise<number> {
async function f4(p: Promise<number>): Promise<boolean> {
return await p;
}
var f5: () => Promise<number> = async () => await [object Number];
var f5: () => Promise<number> = async () => await 1;
class C {
async m() {
return [object Number];
return 1;
}
async mt<T>(a: T): Promise<T> {
return a;
@ -100,7 +100,7 @@ class C {
return a;
}
}
var obj = { f: async () => await [object Number] };
var obj = { f: async () => await 1 };
var objf: () => Promise<number> = obj.f;
"
`;
@ -108,7 +108,7 @@ var objf: () => Promise<number> = obj.f;
exports[`test async_base_class.js 1`] = `
"// This is kind of weird, but it should parse. This works in babel without the
// parens around (await promise). From the es6 and async/await specs I (nmote)
// am not clear on whether it should. In any case it's a strange corner case
// am not clear on whether it should. In any case it\'s a strange corner case
// that is probably not important to support.
class C {};
@ -123,7 +123,7 @@ async function foo() {
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// This is kind of weird, but it should parse. This works in babel without the
// parens around (await promise). From the es6 and async/await specs I (nmote)
// am not clear on whether it should. In any case it's a strange corner case
// am not clear on whether it should. In any case it\'s a strange corner case
// that is probably not important to support.
class C {}
var P: Promise<Class<C>> = new Promise(
@ -208,9 +208,9 @@ var oz = {
}
};
var x = { async: [object Number] };
var x = { async: 5 };
console.log(x.async);
var async = [object Number];
var async = 3;
var y = { async };
"
`;
@ -221,7 +221,7 @@ exports[`test async_promise.js 1`] = `
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
async function f(): Promise<number> {
return Promise.resolve([object Number]);
return Promise.resolve(1);
}
"
`;
@ -285,7 +285,7 @@ function test1() {
function test2() {
async function voidoid1() {
console.log("HEY");
console.log(\"HEY\");
}
var voidoid2: () => Promise<void> = voidoid1; // ok
@ -298,7 +298,7 @@ function test2() {
function test3() {
async function voidoid4(): Promise<void> { // ok
console.log("HEY");
console.log(\"HEY\");
}
}
@ -309,14 +309,14 @@ function test3() {
function test4() {
async function voidoid5(): void { // error, void != Promise<void>
console.log("HEY");
console.log(\"HEY\");
}
}
function test5() {
async function voidoid6()
: Promise<number> { // error, number != void
console.log("HEY");
console.log(\"HEY\");
}
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ -343,7 +343,7 @@ function test5() {
// error, number != void
function test1() {
async function foo() {
return [object Number];
return 42;
}
async function bar() {
var a = await foo();
@ -353,24 +353,24 @@ function test1() {
}
function test2() {
async function voidoid1() {
console.log("HEY");
console.log(\"HEY\");
}
var voidoid2: () => Promise<void> = voidoid1;
var voidoid3: () => void = voidoid1;
}
function test3() {
async function voidoid4(): Promise<void> {
console.log("HEY");
console.log(\"HEY\");
}
}
function test4() {
async function voidoid5(): void {
console.log("HEY");
console.log(\"HEY\");
}
}
function test5() {
async function voidoid6(): Promise<number> {
console.log("HEY");
console.log(\"HEY\");
}
}
"
@ -381,9 +381,9 @@ exports[`test async3.js 1`] = `
/**
* test nested-promise unwrapping.
* Note: currently we don't do this properly in the underlying
* Note: currently we don\'t do this properly in the underlying
* type of the Promise class, which causes spurious errors to
* be raised here. Once that's fixed, the errors here will go
* be raised here. Once that\'s fixed, the errors here will go
* away.
*/
@ -413,9 +413,9 @@ async function baz() {
// @flow
/**
* test nested-promise unwrapping.
* Note: currently we don't do this properly in the underlying
* Note: currently we don\'t do this properly in the underlying
* type of the Promise class, which causes spurious errors to
* be raised here. Once that's fixed, the errors here will go
* be raised here. Once that\'s fixed, the errors here will go
* away.
*/
// a should now be typed as number, but is in fact
@ -425,7 +425,7 @@ async function baz() {
// should be number ~> string error, but currently gives
// Promise ~> string error for the same reason
async function foo() {
return [object Number];
return 42;
}
async function bar() {
return foo();
@ -450,7 +450,7 @@ function f() {
// done by the parser, which bails after a single error.
function f() {
await;
[object Number];
1;
}
"
`;
@ -516,42 +516,42 @@ var await = 3;
var y = { await };
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
async function f() {
await [object Number];
await 1;
}
async function ft<T>(a: T) {
await [object Number];
await 1;
}
class C {
async m() {
await [object Number];
await 1;
}
async mt<T>(a: T) {
await [object Number];
await 1;
}
static async m(a) {
await [object Number];
await 1;
}
static async mt<T>(a: T) {
await [object Number];
await 1;
}
}
var e = async function() {
await [object Number];
await 1;
};
var et = async function(a: T) {
await [object Number];
await 1;
};
var n = new async function() {
await [object Number];
await 1;
}();
var o = {
async m() {
await [object Number];
await 1;
}
};
var ot = {
async m<T>(a: T) {
await [object Number];
await 1;
}
};
var oz = {
@ -559,9 +559,9 @@ var oz = {
await async;
}
};
var x = { await: [object Number] };
var x = { await: 5 };
console.log(x.await);
var await = [object Number];
var await = 3;
var y = { await };
"
`;

View File

@ -35,10 +35,10 @@ async function* delegate_next() {
}
yield* inner();
}
delegate_next().next([object Number]);
delegate_next().next(0);
async function* delegate_yield() {
async function* inner() {
yield [object Number];
yield 0;
}
yield* inner();
}
@ -49,7 +49,7 @@ async () => {
};
async function* delegate_return() {
async function* inner() {
return [object Number];
return 0;
}
var x: void = yield* inner();
}
@ -78,7 +78,7 @@ async function* readLines(path) {
}
async function f() {
for await (const line of readLines("/path/to/file")) {
for await (const line of readLines(\"/path/to/file\")) {
(line: void); // error: string ~> void
}
}
@ -101,7 +101,7 @@ async function* readLines(path) {
}
}
async function f() {
for await (const line of readLines("/path/to/file")) {
for await (const line of readLines(\"/path/to/file\")) {
(line: void);
}
}
@ -111,13 +111,13 @@ async function f() {
exports[`test return.js 1`] = `
"declare var gen: AsyncGenerator<void,string,void>;
// You can pass whatever you like to return, it doesn't need to be related to
// the AsyncGenerator's return type
// You can pass whatever you like to return, it doesn\'t need to be related to
// the AsyncGenerator\'s return type
gen.return(0).then(result => {
(result.value: void); // error: string | number ~> void
});
// However, a generator can "refuse" the return by catching an exception and
// However, a generator can \"refuse\" the return by catching an exception and
// yielding or returning internally.
async function *refuse_return() {
try {
@ -126,32 +126,32 @@ async function *refuse_return() {
return 0;
}
}
refuse_return().return("string").then(result => {
refuse_return().return(\"string\").then(result => {
if (result.done) {
(result.value: string); // error: number | void ~> string
}
});
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// You can pass whatever you like to return, it doesn't need to be related to
// the AsyncGenerator's return type
// You can pass whatever you like to return, it doesn\'t need to be related to
// the AsyncGenerator\'s return type
// error: string | number ~> void
// However, a generator can "refuse" the return by catching an exception and
// However, a generator can \"refuse\" the return by catching an exception and
// yielding or returning internally.
// error: number | void ~> string
declare var gen: AsyncGenerator<void, string, void>;
gen.return([object Number]).then(
gen.return(0).then(
result => {
(result.value: void);
}
);
async function* refuse_return() {
try {
yield [object Number];
yield 1;
} finally {
return [object Number];
return 0;
}
}
refuse_return().return("string").then(
refuse_return().return(\"string\").then(
result => {
if (result.done) {
(result.value: string);
@ -171,7 +171,7 @@ exports[`test throw.js 1`] = `
}
(async () => {
catch_return().throw("").then(({value}) => {
catch_return().throw(\"\").then(({value}) => {
if (value !== undefined) {
(value: void); // error: number ~> void
}
@ -188,7 +188,7 @@ async function *yield_return() {
}
(async () => {
yield_return().throw("").then(({value}) => {
yield_return().throw(\"\").then(({value}) => {
if (value !== undefined) {
(value: void); // error: number ~> void
}
@ -199,13 +199,13 @@ async function *yield_return() {
// error: number ~> void
async function* catch_return() {
try {
yield [object Number];
yield 0;
} catch (e) {
return e;
}
}
async () => {
catch_return().throw("").then(
catch_return().throw(\"\").then(
({ value }) => {
if (value !== undefined) {
(value: void);
@ -215,14 +215,14 @@ async () => {
};
async function* yield_return() {
try {
yield [object Number];
yield 0;
return;
} catch (e) {
yield e;
}
}
async () => {
yield_return().throw("").then(
yield_return().throw(\"\").then(
({ value }) => {
if (value !== undefined) {
(value: void);

View File

@ -0,0 +1,409 @@
exports[`test bar.js 1`] = `
"// @flow
var o = require(\'./unknown\');
o.x.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// @flow
var o = require(\"./unknown\");
o.x.;
"
`;
exports[`test bool.js 1`] = `
"// @flow
true.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// @flow
true.;
"
`;
exports[`test customfun.js 1`] = `
"// @flow
declare var idx: $Facebookism$Idx;
declare var merge: $Facebookism$Merge;
declare var mergeDeepInto: $Facebookism$MergeDeepInto;
declare var mergeInto: $Facebookism$MergeInto;
declare var mixin: $Facebookism$Mixin;
declare var objectGetPrototypeOf: Object$GetPrototypeOf
declare var objectAssign: Object$Assign
m
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// @flow
declare var idx: $Facebookism$Idx;
declare var merge: $Facebookism$Merge;
declare var mergeDeepInto: $Facebookism$MergeDeepInto;
declare var mergeInto: $Facebookism$MergeInto;
declare var mixin: $Facebookism$Mixin;
declare var objectGetPrototypeOf: Object$GetPrototypeOf;
declare var objectAssign: Object$Assign;
m;
"
`;
exports[`test foo.js 1`] = `
"/**
* @flow
*/
var obj = {
num: 123,
str: \'hello\',
};
obj.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/**
* @flow
*/
var obj = { num: 123, str: \"hello\" };
obj.;
"
`;
exports[`test foo_parse_fail.js 1`] = `
"/**
* @flow
*/
var obj = {
num: 123,
str: \'hello\',
};
console.log(obj.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/**
* @flow
*/
var obj = { num: 123, str: \"hello\" };
console.log(obj.);
"
`;
exports[`test fun.js 1`] = `
"/* @flow */
function foo(f: () => number) {
f.
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/* @flow */
function foo(f: () => number) {
f.};
}
"
`;
exports[`test function_builtins.js 1`] = `
"/* @flow */
function foo(f: Function) {
f.
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/* @flow */
function foo(f: Function) {
f.};
}
"
`;
exports[`test generics.js 1`] = `
"// @flow
class C<X> { }
function foo(o: { cn: C<number> }) {
o.
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// @flow
class C<X> {}
function foo(o: { cn: C<number> }) {
o.};
}
"
`;
exports[`test if.js 1`] = `
"// @flow
const x = \'\';
if (x.)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// @flow
const x = \"\";
if (x.))
"
`;
exports[`test issue-1368.js 1`] = `
"/* @flow */
class Test {
prop: number;
constructor(prop: number) {
this.prop = prop;
}
}
class ExtendTest extends Test {
extended: string;
constructor(extended: string) {
super(10);
this.extended = extended;
}
method() {
this.prop = 12;
this./* here */
}
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/* @flow */
/* here */
class Test {
prop: number;
constructor(prop: number) {
this.prop = prop;
}
}
class ExtendTest extends Test {
extended: string;
constructor(extended: string) {
super(10);
this.extended = extended;
}
method() {
this.prop = 12;
this.};
}
}
"
`;
exports[`test jsx1.js 1`] = `
"// @flow
var React = require(\'react\');
class C extends React.Component {
props: { x: number };
}
<C
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// @flow
var React = require(\"react\");
class C extends React.Component {
props: { x: number };
}
<C>;
"
`;
exports[`test jsx2.js 1`] = `
"// @flow
var React = require(\'react\');
class C extends React.Component {
props: { x: number, y: string };
}
<C x = 0,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// @flow
var React = require(\"react\");
class C extends React.Component {
props: { x: number, y: string };
}
<C x=\"\" 0 ,>;
"
`;
exports[`test num.js 1`] = `
"// @flow
var num = 123;
num.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// @flow
var num = 123;
num.;
"
`;
exports[`test object_builtins.js 1`] = `
"/* @flow */
function foo(o: Object) {
o.
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/* @flow */
function foo(o: Object) {
o.};
}
"
`;
exports[`test optional.js 1`] = `
"// @flow
function foo(obj: { x?: string, f: (x?: string) => void, o: { x?: string } }) {
return obj.
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// @flow
function foo(
obj: { x?: string, f: : (x?: string) => void, o: { x?: string } }
) {
return obj.};
}
"
`;
exports[`test override.js 1`] = `
"// @flow
class C {
override(): number | string { return 0; }
}
class D extends C {
foo() { return this.override() }
override(): string { return \"\"; }
bar() { this.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// @flow
class C {
override(): number | string {
return 0;
}
}
class D extends C {
foo() {
return this.override();
}
override(): string {
return \"\";
}
bar() {
this.;
}
}
"
`;
exports[`test qux.js 1`] = `
"// @flow
class C { x: number; }
var c: C = new C;
c.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// @flow
class C {
x: number;
}
var c: C = new C();
c.;
"
`;
exports[`test str.js 1`] = `
"// @flow
\"hello\".
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// @flow
\"hello\".;
"
`;
exports[`test this.js 1`] = `
"/* @flow */
// issue #1197
class Foo {
baz: string;
bar() {}
hello() {
this.
}
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/* @flow */
// issue #1197
class Foo {
baz: string;
bar() {
}
hello() {
this.};
}
}
"
`;
exports[`test typeparams.js 1`] = `
"// @flow
class Bounds<N: number, F: () => N> {
foo: F;
bar() {
this.foo().
}
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// @flow
class Bounds<N: number, F: () => N> {
foo: F;
bar() {
this.foo().};
}
}
"
`;
exports[`test union.js 1`] = `
"/* @flow */
function foo(a: boolean, x: { bar: string }, y: Object) {
var z;
if (a) {
z = x;
} else {
z = y;
}
z.
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/* @flow */
function foo(a: boolean, x: { bar: string }, y: Object) {
var z;
if (a) {
z = x;
} else {
z = y;
}
z.};
}
"
`;
exports[`test unknown.js 1`] = `
"// @noflow
module.exports = { x: { y: \"\" } };
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// @noflow
module.exports = { x: { y: \"\" } };
"
`;

View File

@ -4,31 +4,31 @@ exports[`test in.js 1`] = `
let tests = [
// objects on RHS
function() {
('foo' in {});
('foo' in { foo: null });
(\'foo\' in {});
(\'foo\' in { foo: null });
(0 in {});
(0 in { "0": null });
(0 in { \"0\": null });
},
// arrays on RHS
function() {
('foo' in []);
(\'foo\' in []);
(0 in []);
('length' in []);
(\'length\' in []);
},
// primitive classes on RHS
function() {
('foo' in new String('bar'));
('foo' in new Number(123));
(\'foo\' in new String(\'bar\'));
(\'foo\' in new Number(123));
},
// primitives on RHS
function() {
('foo' in 123); // error
('foo' in 'bar'); // error
('foo' in void 0); // error
('foo' in null); // error
(\'foo\' in 123); // error
(\'foo\' in \'bar\'); // error
(\'foo\' in void 0); // error
(\'foo\' in null); // error
},
// bogus stuff on LHS
@ -42,15 +42,15 @@ let tests = [
// in predicates
function() {
if ('foo' in 123) {} // error
if (!'foo' in {}) {} // error, !'foo' is a boolean
if (!('foo' in {})) {}
if (\'foo\' in 123) {} // error
if (!\'foo\' in {}) {} // error, !\'foo\' is a boolean
if (!(\'foo\' in {})) {}
},
// annotations on RHS
function(x: Object, y: mixed) {
('foo' in x); // ok
('foo' in y); // error
(\'foo\' in x); // ok
(\'foo\' in y); // error
},
]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ -71,53 +71,53 @@ let tests = [
// error
// in predicates
// error
// error, !'foo' is a boolean
// error, !\'foo\' is a boolean
// annotations on RHS
// ok
// error
let tests = [
function() {
"foo" in {};
"foo" in { foo: [object Null] };
[object Number] in {};
[object Number] in { "0": [object Null] };
\"foo\" in {};
\"foo\" in { foo: null };
0 in {};
0 in { \"0\": null };
},
function() {
"foo" in [ ];
[object Number] in [ ];
"length" in [ ];
\"foo\" in [ ];
0 in [ ];
\"length\" in [ ];
},
function() {
"foo" in new String("bar");
"foo" in new Number([object Number]);
\"foo\" in new String(\"bar\");
\"foo\" in new Number(123);
},
function() {
"foo" in [object Number];
"foo" in "bar";
"foo" in void [object Number];
"foo" in [object Null];
\"foo\" in 123;
\"foo\" in \"bar\";
\"foo\" in void 0;
\"foo\" in null;
},
function() {
[object Null] in {};
void [object Number] in {};
null in {};
void 0 in {};
({}) in {};
[ ] in {};
[object Boolean] in [ ];
false in [ ];
},
function() {
if ("foo" in [object Number]) {
if (\"foo\" in 123) {
}
if (!"foo" in {}) {
if (!\"foo\" in {}) {
}
if (!("foo" in {})) {
if (!(\"foo\" in {})) {
}
},
function(x: Object, y: mixed) {
"foo" in x;
"foo" in y;
\"foo\" in x;
\"foo\" in y;
}
];
"

View File

@ -17,8 +17,8 @@ x &= 0;
// regression tests -- OK to assign consts like this:
const { foo } = { foo: "foo" }
const [ bar ] = ["bar"];
const { foo } = { foo: \"foo\" }
const [ bar ] = [\"bar\"];
(foo: number); // error: string ~> number
(bar: number); // error: string ~> number
@ -32,21 +32,21 @@ for (const { baz } of bazzes) {
// error: string ~> number
// error: string ~> number
// error: string ~> number
const x = [object Number];
const x = 0;
x++;
x--;
x += [object Number];
x -= [object Number];
x /= [object Number];
x %= [object Number];
x <<= [object Number];
x >>= [object Number];
x >>>= [object Number];
x |= [object Number];
x ^= [object Number];
x &= [object Number];
const { foo } = { foo: "foo" };
const [ bar ] = [ "bar" ];
x += 0;
x -= 0;
x /= 0;
x %= 0;
x <<= 0;
x >>= 0;
x >>>= 0;
x |= 0;
x ^= 0;
x &= 0;
const { foo } = { foo: \"foo\" };
const [ bar ] = [ \"bar\" ];
(foo: number);
(bar: number);
declare var bazzes: { baz: string }[];
@ -97,7 +97,7 @@ function type_var() {
function type_reassign() {
type A = number;
A = 42; // error: type alias ref'd from value pos
A = 42; // error: type alias ref\'d from value pos
}
// class x *
@ -271,7 +271,7 @@ function fn_params_clash_fn_binding(x,y) {
// error: name already bound
// error: name already bound
// error: name already bound
// error: type alias ref'd from value pos
// error: type alias ref\'d from value pos
// class x *
// error: name already bound
// error: name already bound
@ -317,19 +317,19 @@ function type_class() {
}
function type_let() {
type A = number;
let A = [object Number];
let A = 0;
}
function type_const() {
type A = number;
const A = [object Number];
const A = 0;
}
function type_var() {
type A = number;
var A = [object Number];
var A = 0;
}
function type_reassign() {
type A = number;
A = [object Number];
A = 42;
}
function class_type() {
class A {}
@ -341,79 +341,79 @@ function class_class() {
}
function class_let() {
class A {}
let A = [object Number];
let A = 0;
}
function class_const() {
class A {}
const A = [object Number];
const A = 0;
}
function class_var() {
class A {}
var A = [object Number];
var A = 0;
}
function let_type() {
let A = [object Number];
let A = 0;
type A = number;
}
function let_class() {
let A = [object Number];
let A = 0;
class A {}
}
function let_let() {
let A = [object Number];
let A = [object Number];
let A = 0;
let A = 0;
}
function let_const() {
let A = [object Number];
const A = [object Number];
let A = 0;
const A = 0;
}
function let_var() {
let A = [object Number];
var A = [object Number];
let A = 0;
var A = 0;
}
function const_type() {
const A = [object Number];
const A = 0;
type A = number;
}
function const_class() {
const A = [object Number];
const A = 0;
class A {}
}
function const_let() {
const A = [object Number];
let A = [object Number];
const A = 0;
let A = 0;
}
function const_const() {
const A = [object Number];
const A = [object Number];
const A = 0;
const A = 0;
}
function const_var() {
const A = [object Number];
var A = [object Number];
const A = 0;
var A = 0;
}
function const_reassign() {
const A = [object Number];
A = [object Number];
const A = 0;
A = 42;
}
function var_type() {
var A = [object Number];
var A = 0;
type A = number;
}
function var_class() {
var A = [object Number];
var A = 0;
class A {}
}
function var_let() {
var A = [object Number];
let A = [object Number];
var A = 0;
let A = 0;
}
function var_const() {
var A = [object Number];
const A = [object Number];
var A = 0;
const A = 0;
}
function var_var() {
var A = [object Number];
var A = [object Number];
var A = 0;
var A = 0;
}
function function_toplevel() {
function a() {
@ -435,15 +435,15 @@ function function_block() {
}
function var_shadow_nested_scope() {
{
let x = [object Number];
let x = 0;
{
var x = [object Number];
var x = 0;
}
}
}
function type_shadow_nested_scope() {
{
let x = [object Number];
let x = 0;
{
type x = string;
}
@ -453,8 +453,8 @@ function fn_params_name_clash(x, x) {
}
function fn_params_clash_fn_binding(x, y) {
let x = [object Number];
var y = [object Number];
let x = 0;
var y = 0;
}
"
`;
@ -464,8 +464,8 @@ exports[`test scope.js 1`] = `
let a: number = 0;
var b: number = 0;
{
let a = ""; // ok: local to block
var b = ""; // error: string ~> number
let a = \"\"; // ok: local to block
var b = \"\"; // error: string ~> number
}
}
@ -473,12 +473,12 @@ function switch_scope(x: string) {
let a: number = 0;
var b: number = 0;
switch (x) {
case "foo":
let a = ""; // ok: local to switch
var b = ""; // error: string ~> number
case \"foo\":
let a = \"\"; // ok: local to switch
var b = \"\"; // error: string ~> number
break;
case "bar":
let a = ""; // error: a already bound in switch
case \"bar\":
let a = \"\"; // error: a already bound in switch
break;
}
}
@ -489,43 +489,43 @@ function switch_scope(x: string) {
function switch_scope2(x: number) {
switch (x) {
case 0:
a = ""; // error: assign before declaration
a = \"\"; // error: assign before declaration
break;
case 1:
var b = a; // error: use before declaration
break;
case 2:
let a = "";
let a = \"\";
break;
case 3:
a = ""; // error: skipped initializer
a = \"\"; // error: skipped initializer
break;
case 4:
var c:string = a; // error: skipped initializer
break;
}
a = ""; // error: a no longer in scope
a = \"\"; // error: a no longer in scope
}
function try_scope() {
let a: number = 0;
try {
let a = ""; // ok
let a = \"\"; // ok
} catch (e) {
let a = ""; // ok
let a = \"\"; // ok
} finally {
let a = ""; // ok
let a = \"\"; // ok
}
}
function for_scope_let() {
let a: number = 0;
for (let a = "" /* ok: local to init */;;) {}
for (let a = \"\" /* ok: local to init */;;) {}
}
function for_scope_var() {
var a: number = 0;
for (var a = "" /* error: string ~> number */;;) {}
for (var a = \"\" /* error: string ~> number */;;) {}
}
function for_in_scope_let(o: Object) {
@ -559,7 +559,7 @@ function default_param_1() {
function default_param_2() {
// fn body bindings not visible from param scope
let a = "";
let a = \"\";
function f0(x = () => a): number {
let a = 0;
return x(); // error: string ~> number
@ -598,105 +598,105 @@ function default_param_2() {
// error: string ~> number
/* error: cannot resolve b */
function block_scope() {
let a: number = [object Number];
var b: number = [object Number];
let a: number = 0;
var b: number = 0;
{
let a = "";
var b = "";
let a = \"\";
var b = \"\";
}
}
function switch_scope(x: string) {
let a: number = [object Number];
var b: number = [object Number];
let a: number = 0;
var b: number = 0;
switch (x) {
case "foo":
let a = "";
var b = "";
case \"foo\":
let a = \"\";
var b = \"\";
break;
case "bar":
let a = "";
case \"bar\":
let a = \"\";
break;
}
}
function switch_scope2(x: number) {
switch (x) {
case [object Number]:
a = "";
case 0:
a = \"\";
break;
case [object Number]:
case 1:
var b = a;
break;
case [object Number]:
let a = "";
case 2:
let a = \"\";
break;
case [object Number]:
a = "";
case 3:
a = \"\";
break;
case [object Number]:
case 4:
var c: string = a;
break;
}
a = "";
a = \"\";
}
function try_scope() {
let a: number = [object Number];
let a: number = 0;
try {
let a = "";
let a = \"\";
} catch (e) {
let a = "";
let a = \"\";
} finally {
let a = "";
let a = \"\";
}
}
function for_scope_let() {
let a: number = [object Number];
for (let a = ""; ; ) {
let a: number = 0;
for (let a = \"\"; ; ) {
}
}
function for_scope_var() {
var a: number = [object Number];
for (var a = ""; ; ) {
var a: number = 0;
for (var a = \"\"; ; ) {
}
}
function for_in_scope_let(o: Object) {
let a: number = [object Number];
let a: number = 0;
for (let a in o) {
}
}
function for_in_scope_var(o: Object) {
var a: number = [object Number];
var a: number = 0;
for (var a in o) {
}
}
function for_of_scope_let(xs: string[]) {
let a: number = [object Number];
let a: number = 0;
for (let a of xs) {
}
}
function for_of_scope_var(xs: string[]) {
var a: number = [object Number];
var a: number = 0;
for (var a of xs) {
}
}
function default_param_1() {
function f(x: () => string = f): number {
return [object Number];
return 0;
}
}
function default_param_2() {
let a = "";
let a = \"\";
function f0(x = () => a): number {
let a = [object Number];
let a = 0;
return x();
}
function f1(x = b): number {
let b = [object Number];
let b = 0;
return x;
}
}
@ -720,7 +720,7 @@ type T2 = number;
// while let is in TDZ.
// - allow forward refs to lets from type positions.
//
// currently we're too lenient about TDZ in closures -
// currently we\'re too lenient about TDZ in closures -
// from value positions, we currently enforce TDZ only in-scope.
// this is unsound - a let or const may remain uninitialized when
// a lambda runs. But a simple conservative approach would prohibit
@ -758,12 +758,12 @@ function f3() {
function foo() { return 0; }
}
var s2: string = foo(); // ok, hoisted outer not clobbered
function foo() { return ""; }
function foo() { return \"\"; }
}
// out-of-scope TDZ not enforced. sometimes right...
function f4() {
function g() { return x + c; } // ok, g doesn't run in TDZ
function g() { return x + c; } // ok, g doesn\'t run in TDZ
let x = 0;
const c = 0;
}
@ -771,7 +771,7 @@ function f4() {
// ...sometimes wrong
function f5() {
function g() { return x; }
g(); // should error, but doesn't currently
g(); // should error, but doesn\'t currently
let x = 0;
const c = 0;
}
@ -791,8 +791,8 @@ var z: C = new C(); // ok
// --- vars ---
// it's possible to annotate a var with a non-maybe type,
// but leave it uninitialized until later (as long as it's
// it\'s possible to annotate a var with a non-maybe type,
// but leave it uninitialized until later (as long as it\'s
// initialized before use)
var a: number; // not an error per se - only if used before init
@ -815,7 +815,7 @@ f(a); // ok, a: number (not ?number)
// while let is in TDZ.
// - allow forward refs to lets from type positions.
//
// currently we're too lenient about TDZ in closures -
// currently we\'re too lenient about TDZ in closures -
// from value positions, we currently enforce TDZ only in-scope.
// this is unsound - a let or const may remain uninitialized when
// a lambda runs. But a simple conservative approach would prohibit
@ -830,9 +830,9 @@ f(a); // ok, a: number (not ?number)
// ok, finds hoisted inner
// ok, hoisted outer not clobbered
// out-of-scope TDZ not enforced. sometimes right...
// ok, g doesn't run in TDZ
// ok, g doesn\'t run in TDZ
// ...sometimes wrong
// should error, but doesn't currently
// should error, but doesn\'t currently
// - from type positions, we currently error on forward refs to any
// value (i.e., class or function). this is a basic flaw in our
// phasing of AST traversal, and will be fixed.
@ -841,8 +841,8 @@ f(a); // ok, a: number (not ?number)
// error: let ref before decl from value position
// ok
// --- vars ---
// it's possible to annotate a var with a non-maybe type,
// but leave it uninitialized until later (as long as it's
// it\'s possible to annotate a var with a non-maybe type,
// but leave it uninitialized until later (as long as it\'s
// initialized before use)
// not an error per se - only if used before init
// error: undefined ~/> number
@ -851,51 +851,51 @@ type T1 = T2;
type T2 = number;
function f0() {
var v = x * c;
let x = [object Number];
const c = [object Number];
let x = 0;
const c = 0;
}
function f1(b) {
x = [object Number];
let x = [object Number];
x = 10;
let x = 0;
if (b) {
y = [object Number];
let y = [object Number];
y = 10;
let y = 0;
}
}
function f2() {
{
var v = x * c;
}
let x = [object Number];
const c = [object Number];
let x = 0;
const c = 0;
}
function f3() {
var s: string = foo();
{
var n: number = foo();
function foo() {
return [object Number];
return 0;
}
}
var s2: string = foo();
function foo() {
return "";
return \"\";
}
}
function f4() {
function g() {
return x + c;
}
let x = [object Number];
const c = [object Number];
let x = 0;
const c = 0;
}
function f5() {
function g() {
return x;
}
g();
let x = [object Number];
const c = [object Number];
let x = 0;
const c = 0;
}
var x: C;
var y = new C();
@ -906,7 +906,7 @@ function f(n: number) {
return n;
}
f(a);
a = [object Number];
a = 10;
f(a);
"
`;

View File

@ -3,53 +3,53 @@ exports[`test FormData.js 1`] = `
// constructor
const a: FormData = new FormData(); // correct
new FormData(''); // incorrect
new FormData(document.createElement('input')); // incorrect
new FormData(document.createElement('form')); // correct
new FormData(\'\'); // incorrect
new FormData(document.createElement(\'input\')); // incorrect
new FormData(document.createElement(\'form\')); // correct
// has
const b: boolean = a.has('foo'); // correct
const b: boolean = a.has(\'foo\'); // correct
// get
const c: ?(string | File) = a.get('foo'); // correct
const d: string = a.get('foo'); // incorrect
const e: Blob = a.get('foo'); // incorrect
const f: ?(string | File | Blob) = a.get('foo'); // incorrect
const c: ?(string | File) = a.get(\'foo\'); // correct
const d: string = a.get(\'foo\'); // incorrect
const e: Blob = a.get(\'foo\'); // incorrect
const f: ?(string | File | Blob) = a.get(\'foo\'); // incorrect
a.get(2); // incorrect
// getAll
const a1: Array<string | File> = a.getAll('foo'); // correct
const a2: Array<string | File | number> = a.getAll('foo'); // incorrect
const a3: Array<string | Blob | File> = a.getAll('foo'); // incorrect
const a1: Array<string | File> = a.getAll(\'foo\'); // correct
const a2: Array<string | File | number> = a.getAll(\'foo\'); // incorrect
const a3: Array<string | Blob | File> = a.getAll(\'foo\'); // incorrect
a.getAll(23); // incorrect
// set
a.set('foo', 'bar'); // correct
a.set('foo', {}); // incorrect
a.set(2, 'bar'); // incorrect
a.set('foo', 'bar', 'baz'); // incorrect
a.set('bar', new File([], 'q')) // correct
a.set('bar', new File([], 'q'), 'x') // correct
a.set('bar', new File([], 'q'), 2) // incorrect
a.set('bar', new Blob) // correct
a.set('bar', new Blob, 'x') // correct
a.set('bar', new Blob, 2) // incorrect
a.set(\'foo\', \'bar\'); // correct
a.set(\'foo\', {}); // incorrect
a.set(2, \'bar\'); // incorrect
a.set(\'foo\', \'bar\', \'baz\'); // incorrect
a.set(\'bar\', new File([], \'q\')) // correct
a.set(\'bar\', new File([], \'q\'), \'x\') // correct
a.set(\'bar\', new File([], \'q\'), 2) // incorrect
a.set(\'bar\', new Blob) // correct
a.set(\'bar\', new Blob, \'x\') // correct
a.set(\'bar\', new Blob, 2) // incorrect
// append
a.append('foo', 'bar'); // correct
a.append('foo', {}); // incorrect
a.append(2, 'bar'); // incorrect
a.append('foo', 'bar', 'baz'); // incorrect
a.append('foo', 'bar'); // incorrect
a.append('bar', new File([], 'q')) // correct
a.append('bar', new File([], 'q'), 'x') // correct
a.append('bar', new File([], 'q'), 2) // incorrect
a.append('bar', new Blob) // correct
a.append('bar', new Blob, 'x') // correct
a.append('bar', new Blob, 2) // incorrect
a.append(\'foo\', \'bar\'); // correct
a.append(\'foo\', {}); // incorrect
a.append(2, \'bar\'); // incorrect
a.append(\'foo\', \'bar\', \'baz\'); // incorrect
a.append(\'foo\', \'bar\'); // incorrect
a.append(\'bar\', new File([], \'q\')) // correct
a.append(\'bar\', new File([], \'q\'), \'x\') // correct
a.append(\'bar\', new File([], \'q\'), 2) // incorrect
a.append(\'bar\', new Blob) // correct
a.append(\'bar\', new Blob, \'x\') // correct
a.append(\'bar\', new Blob, 2) // incorrect
// delete
a.delete('xx'); // correct
a.delete(\'xx\'); // correct
a.delete(3); // incorrect
// keys
@ -125,42 +125,42 @@ for (let [x, y]: [number, number] of a.entries()) {} // incorrect
// incorrect
// incorrect
const a: FormData = new FormData();
new FormData("");
new FormData(document.createElement("input"));
new FormData(document.createElement("form"));
const b: boolean = a.has("foo");
const c: ?(string | File) = a.get("foo");
const d: string = a.get("foo");
const e: Blob = a.get("foo");
const f: ?(string | File | Blob) = a.get("foo");
a.get([object Number]);
const a1: Array<string | File> = a.getAll("foo");
const a2: Array<string | File | number> = a.getAll("foo");
const a3: Array<string | Blob | File> = a.getAll("foo");
a.getAll([object Number]);
a.set("foo", "bar");
a.set("foo", {});
a.set([object Number], "bar");
a.set("foo", "bar", "baz");
a.set("bar", new File([ ], "q"));
a.set("bar", new File([ ], "q"), "x");
a.set("bar", new File([ ], "q"), [object Number]);
a.set("bar", new Blob());
a.set("bar", new Blob(), "x");
a.set("bar", new Blob(), [object Number]);
a.append("foo", "bar");
a.append("foo", {});
a.append([object Number], "bar");
a.append("foo", "bar", "baz");
a.append("foo", "bar");
a.append("bar", new File([ ], "q"));
a.append("bar", new File([ ], "q"), "x");
a.append("bar", new File([ ], "q"), [object Number]);
a.append("bar", new Blob());
a.append("bar", new Blob(), "x");
a.append("bar", new Blob(), [object Number]);
a.delete("xx");
a.delete([object Number]);
new FormData(\"\");
new FormData(document.createElement(\"input\"));
new FormData(document.createElement(\"form\"));
const b: boolean = a.has(\"foo\");
const c: ?(string | File) = a.get(\"foo\");
const d: string = a.get(\"foo\");
const e: Blob = a.get(\"foo\");
const f: ?(string | File | Blob) = a.get(\"foo\");
a.get(2);
const a1: Array<string | File> = a.getAll(\"foo\");
const a2: Array<string | File | number> = a.getAll(\"foo\");
const a3: Array<string | Blob | File> = a.getAll(\"foo\");
a.getAll(23);
a.set(\"foo\", \"bar\");
a.set(\"foo\", {});
a.set(2, \"bar\");
a.set(\"foo\", \"bar\", \"baz\");
a.set(\"bar\", new File([ ], \"q\"));
a.set(\"bar\", new File([ ], \"q\"), \"x\");
a.set(\"bar\", new File([ ], \"q\"), 2);
a.set(\"bar\", new Blob());
a.set(\"bar\", new Blob(), \"x\");
a.set(\"bar\", new Blob(), 2);
a.append(\"foo\", \"bar\");
a.append(\"foo\", {});
a.append(2, \"bar\");
a.append(\"foo\", \"bar\", \"baz\");
a.append(\"foo\", \"bar\");
a.append(\"bar\", new File([ ], \"q\"));
a.append(\"bar\", new File([ ], \"q\"), \"x\");
a.append(\"bar\", new File([ ], \"q\"), 2);
a.append(\"bar\", new Blob());
a.append(\"bar\", new Blob(), \"x\");
a.append(\"bar\", new Blob(), 2);
a.delete(\"xx\");
a.delete(3);
for (let x: string of a.keys()) {
}
@ -206,11 +206,11 @@ new MutationObserver(42); // incorrect
new MutationObserver((n: number) => {}); // incorrect
// observe
const div = document.createElement('div');
o.observe(div, { attributes: true, attributeFilter: ['style'] }); // correct
const div = document.createElement(\'div\');
o.observe(div, { attributes: true, attributeFilter: [\'style\'] }); // correct
o.observe(div, { characterData: true, invalid: true }); // correct
o.observe(); // incorrect
o.observe('invalid'); // incorrect
o.observe(\'invalid\'); // incorrect
o.observe(div); // incorrect
o.observe(div, {}); // incorrect
o.observe(div, { subtree: true }); // incorrect
@ -249,31 +249,28 @@ function callback(
return;
}
const o: MutationObserver = new MutationObserver(callback);
new MutationObserver((arr: Array<MutationRecord>) => [object Boolean]);
new MutationObserver((arr: Array<MutationRecord>) => true);
new MutationObserver(
() => {
}
);
new MutationObserver();
new MutationObserver([object Number]);
new MutationObserver(42);
new MutationObserver(
(n: number) => {
}
);
const div = document.createElement("div");
o.observe(div, { attributes: [object Boolean], attributeFilter: [ "style" ] });
o.observe(div, { characterData: [object Boolean], invalid: [object Boolean] });
const div = document.createElement(\"div\");
o.observe(div, { attributes: true, attributeFilter: [ \"style\" ] });
o.observe(div, { characterData: true, invalid: true });
o.observe();
o.observe("invalid");
o.observe(\"invalid\");
o.observe(div);
o.observe(div, {});
o.observe(div, { subtree: [object Boolean] });
o.observe(
div,
{ attributes: [object Boolean], attributeFilter: [object Boolean] }
);
o.observe(div, { subtree: true });
o.observe(div, { attributes: true, attributeFilter: true });
o.takeRecords();
o.disconnect();
"

View File

@ -1,15 +1,15 @@
exports[`test scope.js 1`] = `
"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 { return y*0; }
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function foo<X, Y: X>(x: X, y: Y): void {
}
foo([object Number], "");
foo(0, \"\");
function bar<X: number, Y: X>(x: X, y: Y): number {
return y * [object Number];
return y * 0;
}
"
`;
@ -33,7 +33,7 @@ class C<T: number> {
}
function example<T: {x: number}>(o: T): T { o.x = 0; 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 c: C<string> = new C; // error, since T = string is incompatible with number
@ -52,7 +52,7 @@ var q: number = c.qux(0);
/* 2 more errors, since argument U = number is incompatible with T = string, and
* result T = string is incompatible with number */
function foo<T: number>(x: T): T {
var _ = x * [object Number];
var _ = x * 1;
var y: string = x;
return x;
}
@ -61,18 +61,18 @@ class C<T: number> {
return x;
}
qux<U: T>(x: U): T {
var _ = x * [object Number];
var _ = x * 1;
var y: string = x;
return x;
}
}
function example<T: { x: number }>(o: T): T {
o.x = [object Number];
o.x = 0;
return o;
}
var obj1: { x: number, y: string } = example({ x: [object Number], y: "" });
var obj2: { x: number } = example({ x: [object Number] });
var obj1: { x: number, y: string } = example({ x: 0, y: \"\" });
var obj2: { x: number } = example({ x: 0 });
var c: C<string> = new C();
var q: number = c.qux([object Number]);
var q: number = c.qux(0);
"
`;

View File

@ -3,7 +3,7 @@ exports[`test break.js 1`] = `
var x = b ? null: false;
var z;
while(b) {
if (x == null) { z = ""; break; }
if (x == null) { z = \"\"; break; }
var y:number = x; // error: boolean !~> number
}
var w:number = z; // 2 errors: ?string !~> number
@ -12,10 +12,10 @@ exports[`test break.js 1`] = `
function bar(b) {
var x = b ? null: false;
if (x == null) return;
switch ("") {
switch (\"\") {
case 0:
var y:number = x; // error: boolean !~> number
x = "";
x = \"\";
case 1:
var z:number = x; // 2 errors: (boolean | string) !~> number
break;
@ -27,10 +27,10 @@ function bar(b) {
function bar2(b) {
var x = b ? null: false;
if (x == null) return;
switch ("") {
switch (\"\") {
case 0: {
let y:number = x; // error: boolean !~> number
x = "";
x = \"\";
}
case 1: {
let z:number = x; // 2 errors: (boolean | string) !~> number
@ -45,7 +45,7 @@ function qux(b) {
var z = 0;
while(b) {
var y:number = z;
if (b) { z = ""; continue; } // error: string !~> number
if (b) { z = \"\"; continue; } // error: string !~> number
z = 0;
}
var w:number = z; // error: string !~> number
@ -54,10 +54,10 @@ function qux(b) {
// same basic test as foo(), but with const. probes the
// logic that still uses havoc to do env resets.
function test_const() {
let st: string = 'abc';
let st: string = \'abc\';
for (let i = 1; i < 100; i++) {
const fooRes: ?string = "HEY";
const fooRes: ?string = \"HEY\";
if (!fooRes) {
break;
}
@ -82,11 +82,11 @@ function test_const() {
// logic that still uses havoc to do env resets.
// no error
function foo(b) {
var x = (b ? [object Null] : [object Boolean]);
var x = (b ? null : false);
var z;
while (b) {
if (x == [object Null]) {
z = "";
if (x == null) {
z = \"\";
break;
}
var y: number = x;
@ -94,55 +94,55 @@ function foo(b) {
var w: number = z;
}
function bar(b) {
var x = (b ? [object Null] : [object Boolean]);
if (x == [object Null])
var x = (b ? null : false);
if (x == null)
return;
switch ("") {
case [object Number]:
switch (\"\") {
case 0:
var y: number = x;
x = "";
case [object Number]:
x = \"\";
case 1:
var z: number = x;
break;
case [object Number]:
case 2:
}
var w: number = x;
}
function bar2(b) {
var x = (b ? [object Null] : [object Boolean]);
if (x == [object Null])
var x = (b ? null : false);
if (x == null)
return;
switch ("") {
case [object Number]:
switch (\"\") {
case 0:
{
let y: number = x;
x = "";
x = \"\";
}
case [object Number]:
case 1:
{
let z: number = x;
break;
}
case [object Number]:
case 2:
}
var w: number = x;
}
function qux(b) {
var z = [object Number];
var z = 0;
while (b) {
var y: number = z;
if (b) {
z = "";
z = \"\";
continue;
}
z = [object Number];
z = 0;
}
var w: number = z;
}
function test_const() {
let st: string = "abc";
for (let i = [object Number]; i < [object Number]; i++) {
const fooRes: ?string = "HEY";
let st: string = \"abc\";
for (let i = 1; i < 100; i++) {
const fooRes: ?string = \"HEY\";
if (!fooRes) {
break;
}

View File

@ -3,17 +3,17 @@ exports[`test test.js 1`] = `
(o.foo: string);
module.exports = o;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
var o = Object.freeze({ foo: [object Number] });
var o = Object.freeze({ foo: 0 });
(o.foo: string);
module.exports = o;
"
`;
exports[`test test2.js 1`] = `
"var o = require('./test');
"var o = require(\'./test\');
(o.foo: string);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
var o = require("./test");
var o = require(\"./test\");
(o.foo: string);
"
`;

View File

@ -1,18 +1,18 @@
exports[`test array.js 1`] = `
"var a = ["..."];
"var a = [\"...\"];
var b = a.map (function (x) { return 0; });
var c: string = b[0]; // error: number !~> string
var array = [];
function f() {
array = array.map (function () { return "..."; });
array = array.map (function () { return \"...\"; });
var x:number = array[0]; // error: string !~> number
}
var Foo = require('./genericfoo');
var Foo = require(\'./genericfoo\');
var foo = new Foo();
function g() {
var foo1 = foo.map (function() { return "..."; });
var foo1 = foo.map (function() { return \"...\"; });
var x:number = foo1.get(); // error: string !~> number
foo = foo1;
}
@ -20,28 +20,28 @@ function g() {
// error: number !~> string
// error: string !~> number
// error: string !~> number
var a = [ "..." ];
var a = [ \"...\" ];
var b = a.map(
function(x) {
return [object Number];
return 0;
}
);
var c: string = b[[object Number]];
var c: string = b[0];
var array = [ ];
function f() {
array = array.map(
function() {
return "...";
return \"...\";
}
);
var x: number = array[[object Number]];
var x: number = array[0];
}
var Foo = require("./genericfoo");
var Foo = require(\"./genericfoo\");
var foo = new Foo();
function g() {
var foo1 = foo.map(
function() {
return "...";
return \"...\";
}
);
var x: number = foo1.get();

View File

@ -11,7 +11,7 @@ function b(f: { (): string }): number {
// ...or if the param type is wrong
function c(f: { (x: number): number }): number {
return f("hello");
return f(\"hello\");
}
// ...or if the arity is wrong
@ -37,13 +37,13 @@ function f(): number {
// ...or if there is no call property
// Make sure we complain even if the object literal is unsealed.
function a(f: { (): string }, g: { (x: number): string }): string {
return f() + g([object Number]);
return f() + g(123);
}
function b(f: { (): string }): number {
return f();
}
function c(f: { (x: number): number }): number {
return f("hello");
return f(\"hello\");
}
function d(f: { (x: number): number }): number {
return f();
@ -60,25 +60,25 @@ function f(): number {
exports[`test B.js 1`] = `
"// You should be able to use a function as an object with a call property
var a: { (x: number): string } = function (x: number): string { return "hi"; };
var a: { (x: number): string } = function (x: number): string { return \"hi\"; };
// ...and it should notice when the return type is wrong
var b: { (x: number): number } = function (x: number): string { return "hi"; };
var b: { (x: number): number } = function (x: number): string { return \"hi\"; };
// ...or if the param type is wrong
var c: { (x: string): string } = function (x: number): string { return "hi"; };
var c: { (x: string): string } = function (x: number): string { return \"hi\"; };
// ...or if the arity is wrong
var d: { (): string } = function (x: number): string { return "hi"; };
var d: { (): string } = function (x: number): string { return \"hi\"; };
// ...but subtyping rules still apply
var e: { (x: any): void } = function() { } // arity
var f: { (): mixed } = function(): string { return "hi" } // return type
var f: { (): mixed } = function(): string { return \"hi\" } // return type
var g: { (x: string): void } = function(x: mixed) { } // param type
// A function can be an object
var y : {} = function (x: number): string { return "hi"; };
var z : Object = function (x: number): string { return "hi"; };
var y : {} = function (x: number): string { return \"hi\"; };
var z : Object = function (x: number): string { return \"hi\"; };
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// You should be able to use a function as an object with a call property
// ...and it should notice when the return type is wrong
@ -90,31 +90,31 @@ var z : Object = function (x: number): string { return "hi"; };
// param type
// A function can be an object
var a: { (x: number): string } = function(x: number): string {
return "hi";
return \"hi\";
};
var b: { (x: number): number } = function(x: number): string {
return "hi";
return \"hi\";
};
var c: { (x: string): string } = function(x: number): string {
return "hi";
return \"hi\";
};
var d: { (): string } = function(x: number): string {
return "hi";
return \"hi\";
};
var e: { (x: any): void } = function() {
};
var f: { (): mixed } = function(): string {
return "hi";
return \"hi\";
};
var g: { (x: string): void } = function(x: mixed) {
};
var y: {} = function(x: number): string {
return "hi";
return \"hi\";
};
var z: Object = function(x: number): string {
return "hi";
return \"hi\";
};
"
`;
@ -140,7 +140,7 @@ function d(x: { (z: number): string }): () => string {
return x;
}
// ...or if it doesn't have a call property
// ...or if it doesn\'t have a call property
function e(x: {}): () => string {
return x;
}
@ -159,7 +159,7 @@ function g(x: {}): Function {
// ...and it should notice when the return type is wrong
// ...or if the param type is wrong
// ...or if the arity is wrong
// ...or if it doesn't have a call property
// ...or if it doesn\'t have a call property
// AnyFunT should also be allowed
// ... but only if the object is callable
// error
@ -195,11 +195,11 @@ function a(f: { (): string; (x: number): string }): string {
// It should be fine when a function satisfies them all
var b: { (): string; (x: number): string } =
function (x?: number): string { return "hi"; };
function (x?: number): string { return \"hi\"; };
// ...but should notice when a function doesn't satisfy them all
// ...but should notice when a function doesn\'t satisfy them all
var c: { (): string; (x: number): string } =
function (x: number): string { return "hi"; };
function (x: number): string { return \"hi\"; };
// Only one call property needs to match the function
function d(x: { (): string; (x: number): string }): () => string {
@ -213,17 +213,17 @@ function e(x: { (): string; (x: number): string }): () => number {
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Multiple call properties should also be supported
// It should be fine when a function satisfies them all
// ...but should notice when a function doesn't satisfy them all
// ...but should notice when a function doesn\'t satisfy them all
// Only one call property needs to match the function
// ...but you need at least one
function a(f: { (): string, (x: number): string }): string {
return f() + f([object Number]);
return f() + f(123);
}
var b: { (): string, (x: number): string } = function(x: number): string {
return "hi";
return \"hi\";
};
var c: { (): string, (x: number): string } = function(x: number): string {
return "hi";
return \"hi\";
};
function d(x: { (): string, (x: number): string }): () => string {
return x;
@ -235,7 +235,7 @@ function e(x: { (): string, (x: number): string }): () => number {
`;
exports[`test E.js 1`] = `
"// Expecting properties that don't exist should be an error
"// Expecting properties that don\'t exist should be an error
var a : { someProp: number } = function () {};
// Expecting properties that do exist should be fine
@ -246,7 +246,7 @@ var f = function () {};
f.myProp = 123;
var c : { myProp: number } = f;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Expecting properties that don't exist should be an error
// Expecting properties that don\'t exist should be an error
// Expecting properties that do exist should be fine
// Expecting properties in the functions statics should be fine
var a: { someProp: number } = function() {
@ -258,7 +258,7 @@ var b: { apply: Function } = function() {
var f = function() {
};
f.myProp = [object Number];
f.myProp = 123;
var c: { myProp: number } = f;
"
`;
@ -269,22 +269,22 @@ exports[`test F.js 1`] = `
var a: { (x: number): string } = (x) => x.toString()
// ...and it should notice when the return type is wrong
var b: { (x: number): number } = (x) => "hi"
var b: { (x: number): number } = (x) => \"hi\"
// ...or if the param type is wrong
var c: { (x: string): string } = (x) => x.toFixed()
// ...or if the arity is wrong
var d: { (): string } = (x) => "hi"
var d: { (): string } = (x) => \"hi\"
// ...but subtyping rules still apply
var e: { (x: any): void } = () => { } // arity
var f: { (): mixed } = () => "hi" // return type
var f: { (): mixed } = () => \"hi\" // return type
var g: { (x: Date): void } = (x) => { x * 2 } // param type (date < number)
// A function can be an object
var y : {} = (x) => "hi"
var z : Object = (x) => "hi"
var y : {} = (x) => \"hi\"
var z : Object = (x) => \"hi\"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// You should be able to use an arrow function as an object with a call property
// ...and it should notice when the return type is wrong
@ -296,17 +296,17 @@ var z : Object = (x) => "hi"
// param type (date < number)
// A function can be an object
var a: { (x: number): string } = x => x.toString();
var b: { (x: number): number } = x => "hi";
var b: { (x: number): number } = x => \"hi\";
var c: { (x: string): string } = x => x.toFixed();
var d: { (): string } = x => "hi";
var d: { (): string } = x => \"hi\";
var e: { (x: any): void } = () => {
};
var f: { (): mixed } = () => "hi";
var f: { (): mixed } = () => \"hi\";
var g: { (x: Date): void } = x => {
x * [object Number];
x * 2;
};
var y: {} = x => "hi";
var z: Object = x => "hi";
var y: {} = x => \"hi\";
var z: Object = x => \"hi\";
"
`;

View File

@ -46,7 +46,7 @@ callable.call(null, 0); // error, number ~> string
// error, number ~> string
// error, number ~> string
// error, number ~> string
var x = Boolean([object Number]);
var x = Boolean(4);
function foo(fn: (value: any) => boolean) {
}
@ -55,11 +55,11 @@ var dict: { [k: string]: any } = {};
dict();
interface ICall extends { (x: string): void }
declare var icall: ICall;
icall([object Number]);
icall.call([object Null], [object Number]);
icall(0);
icall.call(null, 0);
type Callable = { (x: string): void };
declare var callable: Callable;
callable([object Number]);
callable.call([object Null], [object Number]);
callable(0);
callable.call(null, 0);
"
`;

View File

@ -1,7 +1,7 @@
exports[`test not_flow.js 1`] = `
"1 * 'foo';
"1 * \'foo\';
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[object Number] * "foo";
1 * \"foo\";
"
`;
@ -11,6 +11,6 @@ exports[`test syntax_error.js 1`] = `
(
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/* @flow */
[object Null];
null;
"
`;

View File

@ -7,14 +7,14 @@ class Base {
initializedField = 42;
initializedFieldWithThis = this.initializedField;
annotatedInitializedFieldValid: ?number = 42;
annotatedInitializedFieldInvalid: number = 'asdf'; // Error: string ~> number
annotatedInitializedFieldInvalid: number = \'asdf\'; // Error: string ~> number
static unannotatedField;
static annotatedField: number;
static initializedField = 'asdf';
static initializedField = \'asdf\';
static initializedFieldWithThis = this.initializedField;
static annotatedInitializedFieldValid: ?number = 42;
static annotatedInitializedFieldInvalid: number = 'asdf'; // Error: string ~> number
static annotatedInitializedFieldInvalid: number = \'asdf\'; // Error: string ~> number
}
var o = new Base();
@ -126,12 +126,12 @@ class Base {
static,
:,
;,
initializedField = "asdf",
initializedField = \"asdf\",
static,
=,
.,
;,
annotatedInitializedFieldValid: ?number = [object Number],
annotatedInitializedFieldValid: ?number = 42,
static,
:,
=,
@ -177,14 +177,14 @@ class Base {
base_initializedField = 42;
base_initializedFieldWithThis = this.base_initializedField;
base_annotatedInitializedFieldValid: ?number = 42;
base_annotatedInitializedFieldInvalid: number = 'asdf'; // Error: string ~> number
base_annotatedInitializedFieldInvalid: number = \'asdf\'; // Error: string ~> number
static base_unannotatedField;
static base_annotatedField: number;
static base_initializedField = 'asdf';
static base_initializedField = \'asdf\';
static base_initializedFieldWithThis = this.base_initializedField;
static base_annotatedInitializedFieldValid: ?number = 42;
static base_annotatedInitializedFieldInvalid: number = 'asdf'; // Error: string ~> number
static base_annotatedInitializedFieldInvalid: number = \'asdf\'; // Error: string ~> number
inherited_initializer = 42;
static inherited_initializer = 42;
@ -196,14 +196,14 @@ class Child extends Base {
child_initializedField = 42;
child_initializedFieldWithThis = this.child_initializedField;
child_annotatedInitializedFieldValid: ?number = 42;
child_annotatedInitializedFieldInvalid: number = 'asdf'; // Error: string ~> number
child_annotatedInitializedFieldInvalid: number = \'asdf\'; // Error: string ~> number
static child_unannotatedField;
static child_annotatedField: number;
static child_initializedField = 'asdf';
static child_initializedField = \'asdf\';
static child_initializedFieldWithThis = this.child_initializedField;
static child_annotatedInitializedFieldValid: ?number = 42;
static child_annotatedInitializedFieldInvalid: number = 'asdf'; // Error: string ~> number
static child_annotatedInitializedFieldInvalid: number = \'asdf\'; // Error: string ~> number
inherited_initializer;
static inherited_initializer;
@ -376,28 +376,28 @@ class Base {
static,
:,
;,
base_initializedField = "asdf",
base_initializedField = \"asdf\",
static,
=,
.,
;,
base_annotatedInitializedFieldValid: ?number = [object Number],
base_annotatedInitializedFieldValid: ?number = 42,
static,
:,
=,
;,
=,
;,
inherited_initializer = [object Number],
inherited_initializer = 42,
},
Child,
Base,
child_unannotatedField,
child_annotatedField: number,
child_initializedField = [object Number],
child_initializedField = 42,
child_initializedFieldWithThis = this.child_initializedField,
child_annotatedInitializedFieldValid: ?number = [object Number],
child_annotatedInitializedFieldInvalid: number = "asdf",
child_annotatedInitializedFieldValid: ?number = 42,
child_annotatedInitializedFieldInvalid: number = \"asdf\",
static,
;,
child_annotatedField: number,
@ -409,7 +409,7 @@ class Base {
:,
=,
;,
child_annotatedInitializedFieldInvalid: number = "asdf",
child_annotatedInitializedFieldInvalid: number = \"asdf\",
inherited_initializer,
static,
;,
@ -495,7 +495,7 @@ ClassAnnotated.p = 42;
/**
* It's always an error to initialized a generically-typed field with an
* It\'s always an error to initialized a generically-typed field with an
* expression of any type other than the generic itself.
*/
class ClassGenericInitialized<T, U> {
@ -514,7 +514,7 @@ class ClassGenericInitialized<T, U> {
// Error: number ~> string
// Error: number ~> string
/**
* It's always an error to initialized a generically-typed field with an
* It\'s always an error to initialized a generically-typed field with an
* expression of any type other than the generic itself.
*/
// Error: number ~> Generic<T>
@ -524,10 +524,10 @@ class ClassAnnotated<T> {
static p: T;
}
var o1 = new ClassAnnotated();
o1.p = [object Number];
o1.p = 42;
(o1.p: number);
(o1.p: string);
ClassAnnotated.p = [object Number];
ClassAnnotated.p = 42;
(ClassAnnotated.p: number);
(ClassAnnotated.p: string);
class ClassGenericInitialized<T, U> {
@ -535,10 +535,10 @@ class ClassGenericInitialized<T, U> {
=(;, :, =, (, :): T {
static;
invalid:
T = [object Number];
T = 42;
static;
valid:
T = (([object Number]: any): T);
T = ((42: any): T);
}
}
"
@ -559,7 +559,7 @@ class Foo {
static selfTypedInit = new Foo();
constructor() {
var someVar = 'asdf';
var someVar = \'asdf\';
}
}
@ -601,7 +601,7 @@ class Foo {
// Error: Foo ~> number
// Error: Foo ~> number
// Error: Foo ~> number
var someVar = [object Number];
var someVar = 42;
class Foo {
outer;
=(;, :, ;, =, Foo) {
@ -614,7 +614,7 @@ Foo;
selfTypedInit = new Foo();
constructor();
{
var someVar = "asdf";
var someVar = \"asdf\";
}
}
((Foo) {

View File

@ -12,9 +12,9 @@ class B extends A {
static foo(x: string) { } // error?
static main() {
B.x = 0; // error
B.x = "";
B.x = \"\";
B.foo(0); // error
B.foo("");
B.foo(\"\");
B.y = 0; // error
B.bar(0); // error
B.qux(0); // error
@ -93,13 +93,13 @@ class B extends A {
}
static main() {
B.x = [object Number];
B.x = "";
B.foo([object Number]);
B.foo("");
B.y = [object Number];
B.bar([object Number]);
B.qux([object Number]);
B.x = 0;
B.x = \"\";
B.foo(0);
B.foo(\"\");
B.y = 0;
B.bar(0);
B.qux(0);
}
static create(): A {
return new this();
@ -119,8 +119,8 @@ class C<X> {
}
class D extends C<string> {
static main() {
D.foo([object Number]);
D.bar([object Number]);
D.foo(0);
D.bar(0);
}
}
var d: C<*> = D.create();

View File

@ -14,7 +14,7 @@ module.exports = { A, B };
exports[`test test2.js 1`] = `
"/* @flow */
var I = require("./test.js");
var I = require(\"./test.js\");
class C extends I.A {}
@ -22,7 +22,7 @@ var x: I.A = new C();
var y: I.B = new C();
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/* @flow */
var I = require("./test.js");
var I = require(\"./test.js\");
class C extends I.A {}
var x: I.A = new C();
var y: I.B = new C();
@ -69,12 +69,12 @@ function foo<X>(c: C<X>, x: X) {
}
type O = { f: number };
foo((new C(): C<O>), { f_: [object Number] });
foo((new C(): C<O>), { f_: 0 });
class D extends C<O> {
bar() {
this.x;
}
}
foo(new D(), { f_: [object Number] });
foo(new D(), { f_: 0 });
"
`;

View File

@ -9,7 +9,7 @@ function takes_string(_:string) { }
// global write from function
//
var global_x = "hello";
var global_x = \"hello\";
function global_f() { }
function global_g() { global_x = 42; }
@ -20,14 +20,14 @@ takes_string(global_x); // ok
global_g();
takes_string(global_x); // error
global_x = 42; // shouldn't pollute linear refinement
global_x = 42; // shouldn\'t pollute linear refinement
// local write from function
//
function local_func() {
var local_x = "hello";
var local_x = \"hello\";
function local_f() { }
function local_g() { local_x = 42; }
@ -38,13 +38,13 @@ function local_func() {
local_g();
takes_string(local_x); // error
local_x = 42; // shouldn't pollute linear refinement
local_x = 42; // shouldn\'t pollute linear refinement
}
// global write from method
//
var global_y = "hello";
var global_y = \"hello\";
var global_o = {
f: function() { },
@ -57,14 +57,14 @@ takes_string(global_y); // ok
global_o.g();
takes_string(global_y); // error
global_y = 42; // shouldn't pollute linear refinement
global_y = 42; // shouldn\'t pollute linear refinement
// local write from method
//
function local_meth() {
var local_y = "hello";
var local_y = \"hello\";
var local_o = {
f: function() { },
@ -77,7 +77,7 @@ function local_meth() {
local_o.g();
takes_string(local_y); // error
local_y = 42; // shouldn't pollute linear refinement
local_y = 42; // shouldn\'t pollute linear refinement
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/***
@ -88,80 +88,80 @@ function local_meth() {
//
// ok
// error
// shouldn't pollute linear refinement
// shouldn\'t pollute linear refinement
// local write from function
//
// ok
// error
// shouldn't pollute linear refinement
// shouldn\'t pollute linear refinement
// global write from method
//
// ok
// error
// shouldn't pollute linear refinement
// shouldn\'t pollute linear refinement
// local write from method
//
// ok
// error
// shouldn't pollute linear refinement
// shouldn\'t pollute linear refinement
function takes_string(_: string) {
}
var global_x = "hello";
var global_x = \"hello\";
function global_f() {
}
function global_g() {
global_x = [object Number];
global_x = 42;
}
global_f();
takes_string(global_x);
global_g();
takes_string(global_x);
global_x = [object Number];
global_x = 42;
function local_func() {
var local_x = "hello";
var local_x = \"hello\";
function local_f() {
}
function local_g() {
local_x = [object Number];
local_x = 42;
}
local_f();
takes_string(local_x);
local_g();
takes_string(local_x);
local_x = [object Number];
local_x = 42;
}
var global_y = "hello";
var global_y = \"hello\";
var global_o = {
f: function() {
},
g: function() {
global_y = [object Number];
global_y = 42;
}
};
global_o.f();
takes_string(global_y);
global_o.g();
takes_string(global_y);
global_y = [object Number];
global_y = 42;
function local_meth() {
var local_y = "hello";
var local_y = \"hello\";
var local_o = {
f: function() {
},
g: function() {
local_y = [object Number];
local_y = 42;
}
};
local_o.f();
takes_string(local_y);
local_o.g();
takes_string(local_y);
local_y = [object Number];
local_y = 42;
}
"
`;
@ -174,7 +174,7 @@ exports[`test cond_havoc.js 1`] = `
//
function example(b: bool): number {
var x = 0;
function f() { x = "" }
function f() { x = \"\" }
if (b) {
f();
}
@ -187,9 +187,9 @@ function example(b: bool): number {
//
// error, string ~/~> number (return type anno) TODO
function example(b: boolean): number {
var x = [object Number];
var x = 0;
function f() {
x = "";
x = \"\";
}
if (b) {
f();
@ -212,7 +212,7 @@ function g(x: ?number) {
const const_x = x;
if (const_x) {
// ok: if const_x is truthy here, it's truthy everywhere
// ok: if const_x is truthy here, it\'s truthy everywhere
call_me = () => { var y:number = const_x; };
}
@ -227,20 +227,20 @@ function g(x: ?number) {
function h(x: number | string | boolean) {
const const_x = x;
if (typeof(const_x) == "number") {
if (typeof(const_x) == \"number\") {
call_me = () => { var y:number = const_x; }; // ok
} else if (typeof(const_x) == "string") {
} else if (typeof(const_x) == \"string\") {
call_me = () => { var y:string = const_x; }; // ok
} else if (typeof(const_x) == "boolean") {
} else if (typeof(const_x) == \"boolean\") {
call_me = () => { var y:boolean = const_x; }; // ok
}
var var_x = x;
if (typeof(var_x) == "number") {
if (typeof(var_x) == \"number\") {
call_me = () => { var y:number = var_x; }; // error
} else if (typeof(var_x) == "string") {
} else if (typeof(var_x) == \"string\") {
call_me = () => { var y:string = var_x; }; // error
} else if (typeof(var_x) == "boolean") {
} else if (typeof(var_x) == \"boolean\") {
call_me = () => { var y:boolean = var_x; }; // error
}
}
@ -253,7 +253,7 @@ call_me();
* @flow
*/
// global, anybody can call it at any time
// ok: if const_x is truthy here, it's truthy everywhere
// ok: if const_x is truthy here, it\'s truthy everywhere
// error: var_x might no longer be truthy when call_me is called
// error
// ok
@ -279,37 +279,37 @@ function g(x: ?number) {
var y: number = var_x;
};
}
var_x = [object Null];
var_x = null;
}
function h(x: number | string | boolean) {
const const_x = x;
if (typeof const_x == "number") {
if (typeof const_x == \"number\") {
call_me = () => {
var y: number = const_x;
};
} else
if (typeof const_x == "string") {
if (typeof const_x == \"string\") {
call_me = () => {
var y: string = const_x;
};
} else
if (typeof const_x == "boolean") {
if (typeof const_x == \"boolean\") {
call_me = () => {
var y: boolean = const_x;
};
}
var var_x = x;
if (typeof var_x == "number") {
if (typeof var_x == \"number\") {
call_me = () => {
var y: number = var_x;
};
} else
if (typeof var_x == "string") {
if (typeof var_x == \"string\") {
call_me = () => {
var y: string = var_x;
};
} else
if (typeof var_x == "boolean") {
if (typeof var_x == \"boolean\") {
call_me = () => {
var y: boolean = var_x;
};

View File

@ -13,11 +13,11 @@ module.exports = f;
exports[`test Rel.js 1`] = `
"
var f = require('./Abs');
var f = require(\'./Abs\');
f(0);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
var f = require("./Abs");
f([object Number]);
var f = require(\"./Abs\");
f(0);
"
`;

View File

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

View File

@ -29,21 +29,21 @@ function d(): string { // expected \`: number | boolean\`
// expected \`: number | boolean\`
// equivalent to \`return x != null && x\`
function a(): number {
var x: ?string = [object Null];
return (x ? [object Number] : [object Number]);
var x: ?string = null;
return (x ? 1 : 0);
}
function b(): number {
var x: ?number = [object Null];
return (x != [object Null] ? x : [object Number]);
var x: ?number = null;
return (x != null ? x : 0);
}
function c(): number {
var x = [object Boolean];
var temp = (x ? [object Number] : x);
return (temp ? temp : [object Number]);
var x = false;
var temp = (x ? 1 : x);
return (temp ? temp : 0);
}
function d(): string {
var x: ?number = [object Null];
return (x != [object Null] ? x : x != [object Null]);
var x: ?number = null;
return (x != null ? x : x != null);
}
"
`;

View File

@ -4,21 +4,21 @@ exports[`test test.js 1`] = `
*/
function foo(x) {
var a: number = 'asdf';
var a: number = \'asdf\';
return x * 10;
}
// This file should be ignored, so this should not result in an error
foo('Hello, world!');
foo(\'Hello, world!\');
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/*
* @flow
*/
// This file should be ignored, so this should not result in an error
function foo(x) {
var a: number = "asdf";
return x * [object Number];
var a: number = \"asdf\";
return x * 10;
}
foo("Hello, world!");
foo(\"Hello, world!\");
"
`;

View File

@ -4,6 +4,6 @@ exports[`test testmodule.js 1`] = `
export let test = 42;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// @flow
export let test = [object Number];
export let test = 42;
"
`;

View File

@ -1,31 +1,31 @@
exports[`test A.js 1`] = `
"/* @flow */
var m1 = require('1DoesntExist');
import {numVal as numVal1} from '1DoesntExist';
var m1 = require(\'1DoesntExist\');
import {numVal as numVal1} from \'1DoesntExist\';
var a_1: number = m1.numVal;
var a_2: number = numVal1;
// Error: 'Exists2' is not a valid module name
// Error: \'Exists2\' is not a valid module name
//
// This tests that, for haste, the first name_mapper regexp that happens to
// match the given module name string is picked.
var m2 = require('2DoesntExist'); // Error
import {numVal as numVal2} from '3DoesntExist'; // Error
var m2 = require(\'2DoesntExist\'); // Error
import {numVal as numVal2} from \'3DoesntExist\'; // Error
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/* @flow */
// Error: 'Exists2' is not a valid module name
// Error: \'Exists2\' is not a valid module name
//
// This tests that, for haste, the first name_mapper regexp that happens to
// match the given module name string is picked.
// Error
// Error
var m1 = require("1DoesntExist");
import { numVal as numVal1 } from "1DoesntExist";
var m1 = require(\"1DoesntExist\");
import { numVal as numVal1 } from \"1DoesntExist\";
var a_1: number = m1.numVal;
var a_2: number = numVal1;
var m2 = require("2DoesntExist");
import { numVal as numVal2 } from "3DoesntExist";
var m2 = require(\"2DoesntExist\");
import { numVal as numVal2 } from \"3DoesntExist\";
"
`;
@ -43,6 +43,6 @@ module.exports = {
* @providesModule Exists
* @flow
*/
module.exports = { numVal: [object Number] };
module.exports = { numVal: 42 };
"
`;

View File

@ -1,27 +1,27 @@
exports[`test A.js 1`] = `
"/* @flow */
var m1 = require('./1DoesntExist');
var m1 = require(\'./1DoesntExist\');
var a_1: number = m1.numVal;
var a_2: string = m1.numVal; // Error: number ~> string
import {numVal} from './1DoesntExist';
import {numVal} from \'./1DoesntExist\';
var a_3: number = numVal;
var a_4: string = numVal; // Error: number ~> string
// This tests that, for node, the first name mapping that both matches *and*
// results in a valid module filename is picked.
var m2 = require('./2DoesntExist');
var m2 = require(\'./2DoesntExist\');
var b_1: number = m2.numVal;
var b_2: string = m2.numVal; // Error: number ~> string
import {numVal as numVal2} from './3DoesntExist';
import {numVal as numVal2} from \'./3DoesntExist\';
var b_3: number = numVal2;
var b_4: string = numVal2; // Error: number ~> string
// node_modules/Exists/index.js
var m3 = require('4DoesntExist');
var m3 = require(\'4DoesntExist\');
var c_1: number = m3.numVal;
var c_2: string = m3.numVal; // Error: number ~> string
import {numVal as numVal3} from '5DoesntExist';
import {numVal as numVal3} from \'5DoesntExist\';
var c_3: number = numVal3;
var c_4: string = numVal3; // Error: number ~> string
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ -35,22 +35,22 @@ var c_4: string = numVal3; // Error: number ~> string
// node_modules/Exists/index.js
// Error: number ~> string
// Error: number ~> string
var m1 = require("./1DoesntExist");
var m1 = require(\"./1DoesntExist\");
var a_1: number = m1.numVal;
var a_2: string = m1.numVal;
import { numVal } from "./1DoesntExist";
import { numVal } from \"./1DoesntExist\";
var a_3: number = numVal;
var a_4: string = numVal;
var m2 = require("./2DoesntExist");
var m2 = require(\"./2DoesntExist\");
var b_1: number = m2.numVal;
var b_2: string = m2.numVal;
import { numVal as numVal2 } from "./3DoesntExist";
import { numVal as numVal2 } from \"./3DoesntExist\";
var b_3: number = numVal2;
var b_4: string = numVal2;
var m3 = require("4DoesntExist");
var m3 = require(\"4DoesntExist\");
var c_1: number = m3.numVal;
var c_2: string = m3.numVal;
import { numVal as numVal3 } from "5DoesntExist";
import { numVal as numVal3 } from \"5DoesntExist\";
var c_3: number = numVal3;
var c_4: string = numVal3;
"
@ -64,6 +64,6 @@ module.exports = {
};
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/* @flow */
module.exports = { numVal: [object Number] };
module.exports = { numVal: 42 };
"
`;

View File

@ -12,7 +12,7 @@ class A {
return 1;
}
static _sMethod(): string {
return "some string";
return \"some string\";
}
}
A._sProperty = 48;
@ -23,47 +23,47 @@ class B extends A {
constructor() {
super();
this._property1 = "another string";
this._property1 = \"another string\";
}
_method1(): string {
return "yet another string";
return \"yet another string\";
}
static _sMethod(): number {
return 23;
}
}
B._sProperty = "B._sProperty string";
B._sProperty = \"B._sProperty string\";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/* @flow */
class A {
_property1: number;
static _sProperty: number;
constructor() {
this._property1 = [object Number];
this._property1 = 5;
}
_method1(): number {
return [object Number];
return 1;
}
static _sMethod(): string {
return "some string";
return \"some string\";
}
}
A._sProperty = [object Number];
A._sProperty = 48;
class B extends A {
_property1: string;
static _sProperty: string;
constructor() {
super();
this._property1 = "another string";
this._property1 = \"another string\";
}
_method1(): string {
return "yet another string";
return \"yet another string\";
}
static _sMethod(): number {
return [object Number];
return 23;
}
}
B._sProperty = "B._sProperty string";
B._sProperty = \"B._sProperty string\";
"
`;
@ -87,9 +87,9 @@ module.exports = new C();
exports[`test commonjs_import.js 1`] = `
"/* @flow */
import {_p} from "./commonjs_export";
import {_p} from \"./commonjs_export\";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/* @flow */
import { _p } from "./commonjs_export";
import { _p } from \"./commonjs_export\";
"
`;

View File

@ -12,7 +12,7 @@ class A {
return 1;
}
static _sMethod(): string {
return "some string";
return \"some string\";
}
}
A._sProperty = 48;
@ -23,46 +23,46 @@ class B extends A {
constructor() {
super();
this._property1 = "another string";
this._property1 = \"another string\";
}
_method1(): string {
return "yet another string";
return \"yet another string\";
}
static _sMethod(): number {
return 23;
}
}
B._sProperty = "B._sProperty string";
B._sProperty = \"B._sProperty string\";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/* @flow */
class A {
_property1: number;
static _sProperty: number;
constructor() {
this._property1 = [object Number];
this._property1 = 5;
}
_method1(): number {
return [object Number];
return 1;
}
static _sMethod(): string {
return "some string";
return \"some string\";
}
}
A._sProperty = [object Number];
A._sProperty = 48;
class B extends A {
_property1: string;
static _sProperty: string;
constructor() {
super();
this._property1 = "another string";
this._property1 = \"another string\";
}
_method1(): string {
return "yet another string";
return \"yet another string\";
}
static _sMethod(): number {
return [object Number];
return 23;
}
}
B._sProperty = "B._sProperty string";
B._sProperty = \"B._sProperty string\";
"
`;

View File

@ -6,8 +6,8 @@ function Foo() {
Foo.y = 0; // has static property y
Foo.prototype = { m() { return 0; } };
// exporting Foo directly doesn't work
// Foo's instance and static props are not picked up
// exporting Foo directly doesn\'t work
// Foo\'s instance and static props are not picked up
exports.Foo = Foo;
// so you want to type Foo, by declaring it as a class
@ -24,18 +24,18 @@ exports.Foo2 = (Foo: Class<IFoo>);
// Foo is a class-like function
// constructs objects with property x
// has static property y
// exporting Foo directly doesn't work
// Foo's instance and static props are not picked up
// exporting Foo directly doesn\'t work
// Foo\'s instance and static props are not picked up
// so you want to type Foo, by declaring it as a class
/* error, should have declared x: number instead*/
/* error, should have declared static y: number instead*/
function Foo() {
this.x = [object Number];
this.x = 0;
}
Foo.y = [object Number];
Foo.y = 0;
Foo.prototype = {
m() {
return [object Number];
return 0;
}
};
exports.Foo = Foo;
@ -46,12 +46,12 @@ exports.Foo2 = (Foo: Class<IFoo>);
`;
exports[`test test.js 1`] = `
"var Foo = require('./constructors').Foo;
"var Foo = require(\'./constructors\').Foo;
var x: string = new Foo().x; // error, found number instead of string
var y: string = Foo.y; // error, found number instead of string
var z: string = new Foo().m();
var Foo2 = require('./constructors').Foo2;
var Foo2 = require(\'./constructors\').Foo2;
var x2: string = new Foo2().x; // error, found boolean instead of string
var y2: string = Foo2.y; // error, found boolean instead of string
var z2: string = new Foo2().m();
@ -60,11 +60,11 @@ var z2: string = new Foo2().m();
// error, found number instead of string
// error, found boolean instead of string
// error, found boolean instead of string
var Foo = require("./constructors").Foo;
var Foo = require(\"./constructors\").Foo;
var x: string = new Foo().x;
var y: string = Foo.y;
var z: string = new Foo().m();
var Foo2 = require("./constructors").Foo2;
var Foo2 = require(\"./constructors\").Foo2;
var x2: string = new Foo2().x;
var y2: string = Foo2.y;
var z2: string = new Foo2().m();

View File

@ -5,12 +5,12 @@ exports[`test dummy.js 1`] = `
`;
exports[`test test.js 1`] = `
"require('./dummy');
"require(\'./dummy\');
var xxx = 0;
xxx
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
require("./dummy");
var xxx = [object Number];
require(\"./dummy\");
var xxx = 0;
xxx;
"
`;

View File

@ -5,12 +5,12 @@ exports[`test dummy.js 1`] = `
`;
exports[`test test.js 1`] = `
"require('./dummy');
"require(\'./dummy\');
var xxx = 0;
xxx
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
require("./dummy");
var xxx = [object Number];
require(\"./dummy\");
var xxx = 0;
xxx;
"
`;

View File

@ -13,7 +13,7 @@ let tests = [
new Boolean(false);
new Boolean(NaN);
new Boolean(undefined);
new Boolean("");
new Boolean(\"\");
},
// toString
@ -38,7 +38,7 @@ let tests = [
Boolean(false);
Boolean(NaN);
Boolean(undefined);
Boolean("");
Boolean(\"\");
},
];
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ -51,32 +51,32 @@ let tests = [
let tests = [
function() {
new Boolean();
new Boolean([object Number]);
new Boolean(-[object Number]);
new Boolean([object Null]);
new Boolean([object Boolean]);
new Boolean(0);
new Boolean(-0);
new Boolean(null);
new Boolean(false);
new Boolean(NaN);
new Boolean(undefined);
new Boolean("");
new Boolean(\"\");
},
function() {
[object Boolean].toString();
let x: boolean = [object Boolean];
true.toString();
let x: boolean = false;
x.toString();
new Boolean([object Boolean]).toString();
new Boolean(true).toString();
},
function() {
(new Boolean([object Number]).valueOf(): boolean);
(new Boolean(0).valueOf(): boolean);
},
function() {
Boolean();
Boolean([object Number]);
Boolean(-[object Number]);
Boolean([object Null]);
Boolean([object Boolean]);
Boolean(0);
Boolean(-0);
Boolean(null);
Boolean(false);
Boolean(NaN);
Boolean(undefined);
Boolean("");
Boolean(\"\");
}
];
"
@ -87,7 +87,7 @@ exports[`test map.js 1`] = `
function* generator(): Iterable<[string, number]> {
while (true) {
yield ['foo', 123];
yield [\'foo\', 123];
}
}
@ -96,22 +96,22 @@ let tests = [
function() {
let w = new Map();
let x = new Map(null);
let y = new Map([['foo', 123]]);
let y = new Map([[\'foo\', 123]]);
let z = new Map(generator());
let a: Map<string, number> = new Map();
let b: Map<string, number> = new Map([['foo', 123]]);
let b: Map<string, number> = new Map([[\'foo\', 123]]);
let c: Map<string, number> = new Map(generator());
},
// bad constructors
function() {
let x = new Map(['foo', 123]); // error
let y: Map<number, string> = new Map([['foo', 123]]); // error
let x = new Map([\'foo\', 123]); // error
let y: Map<number, string> = new Map([[\'foo\', 123]]); // error
},
// get()
function(x: Map<string, number>) {
(x.get('foo'): boolean); // error, string | void
(x.get(\'foo\'): boolean); // error, string | void
x.get(123); // error, wrong key type
},
];
@ -124,28 +124,28 @@ let tests = [
// get()
// error, string | void
// error, wrong key type
function* generator(): Iterable<[]> {
while ([object Boolean]) {
yield [ "foo", [object Number] ];
function* generator(): Iterable<[stringnumber]> {
while (true) {
yield [ \"foo\", 123 ];
}
}
let tests = [
function() {
let w = new Map();
let x = new Map([object Null]);
let y = new Map([ [ "foo", [object Number] ] ]);
let x = new Map(null);
let y = new Map([ [ \"foo\", 123 ] ]);
let z = new Map(generator());
let a: Map<string, number> = new Map();
let b: Map<string, number> = new Map([ [ "foo", [object Number] ] ]);
let b: Map<string, number> = new Map([ [ \"foo\", 123 ] ]);
let c: Map<string, number> = new Map(generator());
},
function() {
let x = new Map([ "foo", [object Number] ]);
let y: Map<number, string> = new Map([ [ "foo", [object Number] ] ]);
let x = new Map([ \"foo\", 123 ]);
let y: Map<number, string> = new Map([ [ \"foo\", 123 ] ]);
},
function(x: Map<string, number>) {
(x.get("foo"): boolean);
x.get([object Number]);
(x.get(\"foo\"): boolean);
x.get(123);
}
];
"
@ -157,28 +157,28 @@ exports[`test regexp.js 1`] = `
let tests = [
// constructor
function() {
new RegExp('foo');
new RegExp(\'foo\');
new RegExp(/foo/);
new RegExp('foo', 'i');
new RegExp('foo', 'ig');
new RegExp(/foo/, 'i'); // invalid in ES5, valid in ES6
new RegExp(/foo/g, 'i'); // invalid in ES5, valid in ES6
new RegExp(\'foo\', \'i\');
new RegExp(\'foo\', \'ig\');
new RegExp(/foo/, \'i\'); // invalid in ES5, valid in ES6
new RegExp(/foo/g, \'i\'); // invalid in ES5, valid in ES6
},
// called as a function (equivalent to the constructor per ES6 21.2.3)
function() {
RegExp('foo');
RegExp(\'foo\');
RegExp(/foo/);
RegExp('foo', 'i');
RegExp('foo', 'ig');
RegExp(/foo/, 'i'); // invalid in ES5, valid in ES6
RegExp(/foo/g, 'i'); // invalid in ES5, valid in ES6
RegExp(\'foo\', \'i\');
RegExp(\'foo\', \'ig\');
RegExp(/foo/, \'i\'); // invalid in ES5, valid in ES6
RegExp(/foo/g, \'i\'); // invalid in ES5, valid in ES6
},
// invalid flags
function() {
RegExp('foo', 'z'); // error
new RegExp('foo', 'z'); // error
RegExp(\'foo\', \'z\'); // error
new RegExp(\'foo\', \'z\'); // error
}
];
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ -194,24 +194,24 @@ let tests = [
// error
let tests = [
function() {
new RegExp("foo");
new RegExp([object RegExp]);
new RegExp("foo", "i");
new RegExp("foo", "ig");
new RegExp([object RegExp], "i");
new RegExp([object RegExp], "i");
new RegExp(\"foo\");
new RegExp(/foo/);
new RegExp(\"foo\", \"i\");
new RegExp(\"foo\", \"ig\");
new RegExp(/foo/, \"i\");
new RegExp(/foo/g, \"i\");
},
function() {
RegExp("foo");
RegExp([object RegExp]);
RegExp("foo", "i");
RegExp("foo", "ig");
RegExp([object RegExp], "i");
RegExp([object RegExp], "i");
RegExp(\"foo\");
RegExp(/foo/);
RegExp(\"foo\", \"i\");
RegExp(\"foo\", \"ig\");
RegExp(/foo/, \"i\");
RegExp(/foo/g, \"i\");
},
function() {
RegExp("foo", "z");
new RegExp("foo", "z");
RegExp(\"foo\", \"z\");
new RegExp(\"foo\", \"z\");
}
];
"
@ -222,7 +222,7 @@ exports[`test weakset.js 1`] = `
let ws = new WeakSet();
let obj: Object = {};
let dict: {foo: string} = {foo: 'bar'};
let dict: {foo: string} = {foo: \'bar\'};
ws.add(window);
ws.add(obj);
@ -240,7 +240,7 @@ let ws3 = new WeakSet([1, 2, 3]); // error, must be objects
function* generator(): Iterable<{foo: string}> {
while (true) {
yield {foo: 'bar'};
yield {foo: \'bar\'};
}
}
@ -260,7 +260,7 @@ let ws5 = new WeakSet(numbers()); // error, must be objects
// error, must be objects
let ws = new WeakSet();
let obj: Object = {};
let dict: { foo: string } = { foo: "bar" };
let dict: { foo: string } = { foo: \"bar\" };
ws.add(window);
ws.add(obj);
ws.add(dict);
@ -271,16 +271,16 @@ ws.delete(window);
ws.delete(obj);
ws.delete(dict);
let ws2 = new WeakSet([ obj, dict ]);
let ws3 = new WeakSet([ [object Number], [object Number], [object Number] ]);
let ws3 = new WeakSet([ 1, 2, 3 ]);
function* generator(): Iterable<{ foo: string }> {
while ([object Boolean]) {
yield { foo: "bar" };
while (true) {
yield { foo: \"bar\" };
}
}
let ws4 = new WeakSet(generator());
function* numbers(): Iterable<number> {
let i = [object Number];
while ([object Boolean]) {
let i = 0;
while (true) {
yield i++;
}
}

View File

@ -2,7 +2,7 @@ exports[`test test.js 1`] = `
"type CovArrayVerbose<X,Y:X> = Array<Y>;
var b: CovArrayVerbose<number,*> = [];
var y: CovArrayVerbose<mixed,*> = b;
y[0] = ""; // error
y[0] = \"\"; // error
class NVerbose<E,I:E> {
x: CovArrayVerbose<E,I>;
@ -22,12 +22,12 @@ var z: CovArray<string> = c; // error
var d: CovArray<number> = [];
var w: CovArray<mixed> = d;
w[0] = ""; // error
w[0] = \"\"; // error
type P<X> = CovArray<X>;
var p: P<mixed> = [];
(p[0]: number); // not an error!
p[0] = ""; // error
p[0] = \"\"; // error
class M {
x: CovArray<number>;
@ -60,12 +60,12 @@ var z: CovArray<string> = c; // error
var d: CovArray<number> = [];
var w: CovArray<mixed> = d;
w[0] = ""; // error
w[0] = \"\"; // error
type P<X> = CovArray<X>;
var p: P<mixed> = [];
(p[0]: number); // not an error!
p[0] = ""; // error
p[0] = \"\"; // error
class M {
x: CovArray<number>;
@ -89,7 +89,7 @@ n.x = [0];
type CovArrayVerbose<X, Y: X> = Array<Y>;
var b: CovArrayVerbose<number, *> = [ ];
var y: CovArrayVerbose<mixed, *> = b;
y[[object Number]] = "";
y[0] = \"\";
class NVerbose<E, I: E> {
x: CovArrayVerbose<E, I>;
foo(): CovArrayVerbose<mixed, I> {
@ -97,8 +97,8 @@ class NVerbose<E, I: E> {
}
}
var nv: NVerbose<number, *> = new NVerbose();
nv.x = [ [object Number] ];
(nv.x[[object Number]]: string);
(nv.foo()[[object Number]]: string);
nv.x = [ 0 ];
(nv.x[0]: string);
(nv.foo()[0]: string);
"
`;

View File

@ -1,5 +1,5 @@
exports[`test crash.js 1`] = `
"// This file triggers a violation of the "disjoint-or-nested ranges invariant"
"// This file triggers a violation of the \"disjoint-or-nested ranges invariant\"
// that we implicitly assume in type-at-pos and coverage implementations. In
// particular, when unchecked it causes a crash with coverage --color.
@ -11,7 +11,7 @@ declare module bar {
// TODO
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// This file triggers a violation of the "disjoint-or-nested ranges invariant"
// This file triggers a violation of the \"disjoint-or-nested ranges invariant\"
// that we implicitly assume in type-at-pos and coverage implementations. In
// particular, when unchecked it causes a crash with coverage --color.
// TODO
@ -41,13 +41,13 @@ exports[`test no_pragma.js 1`] = `
"let x = 0;
(x: string);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
let x = [object Number];
let x = 0;
(x: string);
"
`;
exports[`test non-termination.js 1`] = `
"// This file triggers a violation of the "disjoint-or-nested ranges invariant"
"// This file triggers a violation of the \"disjoint-or-nested ranges invariant\"
// that we implicitly assume in type-at-pos and coverage implementations. In
// particular, when unchecked it causes non-termination with coverage --color.
@ -62,7 +62,7 @@ declare module bar {
declare class qux {
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// This file triggers a violation of the "disjoint-or-nested ranges invariant"
// This file triggers a violation of the \"disjoint-or-nested ranges invariant\"
// that we implicitly assume in type-at-pos and coverage implementations. In
// particular, when unchecked it causes non-termination with coverage --color.
// TODO

View File

@ -7,7 +7,7 @@ var y:number = d;
// valid constructors
new Date();
new Date(1234567890);
new Date('2015/06/18');
new Date(\'2015/06/18\');
new Date(2015, 6);
new Date(2015, 6, 18);
new Date(2015, 6, 18, 11);
@ -17,91 +17,40 @@ new Date(2015, 6, 18, 11, 55, 42, 999);
// invalid constructors
new Date({});
new Date(2015, '6');
new Date(2015, 6, '18');
new Date(2015, 6, 18, '11');
new Date(2015, 6, 18, 11, '55');
new Date(2015, 6, 18, 11, 55, '42');
new Date(2015, 6, 18, 11, 55, 42, '999');
new Date(2015, \'6\');
new Date(2015, 6, \'18\');
new Date(2015, 6, 18, \'11\');
new Date(2015, 6, 18, 11, \'55\');
new Date(2015, 6, 18, 11, 55, \'42\');
new Date(2015, 6, 18, 11, 55, 42, \'999\');
// invalid constructors that we incorrectly consider valid
new Date('2015', 6);
new Date(2015, 6, 18, 11, 55, 42, 999, 'hahaha');
new Date(\'2015\', 6);
new Date(2015, 6, 18, 11, 55, 42, 999, \'hahaha\');
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// valid constructors
// invalid constructors
// invalid constructors that we incorrectly consider valid
var d = new Date([object Number]);
var d = new Date(0);
var x: string = d.getTime();
var y: number = d;
new Date();
new Date([object Number]);
new Date("2015/06/18");
new Date([object Number], [object Number]);
new Date([object Number], [object Number], [object Number]);
new Date([object Number], [object Number], [object Number], [object Number]);
new Date(
[object Number],
[object Number],
[object Number],
[object Number],
[object Number]
);
new Date(
[object Number],
[object Number],
[object Number],
[object Number],
[object Number],
[object Number]
);
new Date(
[object Number],
[object Number],
[object Number],
[object Number],
[object Number],
[object Number],
[object Number]
);
new Date(1234567890);
new Date(\"2015/06/18\");
new Date(2015, 6);
new Date(2015, 6, 18);
new Date(2015, 6, 18, 11);
new Date(2015, 6, 18, 11, 55);
new Date(2015, 6, 18, 11, 55, 42);
new Date(2015, 6, 18, 11, 55, 42, 999);
new Date({});
new Date([object Number], "6");
new Date([object Number], [object Number], "18");
new Date([object Number], [object Number], [object Number], "11");
new Date(
[object Number],
[object Number],
[object Number],
[object Number],
"55"
);
new Date(
[object Number],
[object Number],
[object Number],
[object Number],
[object Number],
"42"
);
new Date(
[object Number],
[object Number],
[object Number],
[object Number],
[object Number],
[object Number],
"999"
);
new Date("2015", [object Number]);
new Date(
[object Number],
[object Number],
[object Number],
[object Number],
[object Number],
[object Number],
[object Number],
"hahaha"
);
new Date(2015, \"6\");
new Date(2015, 6, \"18\");
new Date(2015, 6, 18, \"11\");
new Date(2015, 6, 18, 11, \"55\");
new Date(2015, 6, 18, 11, 55, \"42\");
new Date(2015, 6, 18, 11, 55, 42, \"999\");
new Date(\"2015\", 6);
new Date(2015, 6, 18, 11, 55, 42, 999, \"hahaha\");
"
`;

View File

@ -1,10 +1,10 @@
exports[`test A.js 1`] = `
"/* @flow */
module.exports.fun = (): string => 'hello there!';
module.exports.fun = (): string => \'hello there!\';
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/* @flow */
module.exports.fun = (): string => "hello there!";
module.exports.fun = (): string => \"hello there!\";
"
`;
@ -13,7 +13,7 @@ exports[`test CJS.js 1`] = `
module.exports = 42;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// @flow
module.exports = [object Number];
module.exports = 42;
"
`;
@ -21,23 +21,23 @@ exports[`test test_absolute.js 1`] = `
"/* @flow */
// This will require ./node_modules/B.js.flow
var B1 = require('B');
var B1 = require(\'B\');
(B1.fun(): string); // Error number ~> string
// This will require ./node_modules/B.js.flow
var B2 = require('B.js');
var B2 = require(\'B.js\');
(B2.fun(): string); // Error number ~> string
var C = require('package_with_full_main');
var C = require(\'package_with_full_main\');
(C.fun(): string); // Error number ~> string
var D = require('package_with_partial_main');
var D = require(\'package_with_partial_main\');
(D.fun(): string); // Error number ~> string
var E = require('package_with_no_package_json');
var E = require(\'package_with_no_package_json\');
(E.fun(): string); // Error number ~> string
var F = require('package_with_dir_main');
var F = require(\'package_with_dir_main\');
(F.fun(): string); // Error number ~> string
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/* @flow */
@ -49,17 +49,17 @@ var F = require('package_with_dir_main');
// Error number ~> string
// Error number ~> string
// Error number ~> string
var B1 = require("B");
var B1 = require(\"B\");
(B1.fun(): string);
var B2 = require("B.js");
var B2 = require(\"B.js\");
(B2.fun(): string);
var C = require("package_with_full_main");
var C = require(\"package_with_full_main\");
(C.fun(): string);
var D = require("package_with_partial_main");
var D = require(\"package_with_partial_main\");
(D.fun(): string);
var E = require("package_with_no_package_json");
var E = require(\"package_with_no_package_json\");
(E.fun(): string);
var F = require("package_with_dir_main");
var F = require(\"package_with_dir_main\");
(F.fun(): string);
"
`;
@ -68,14 +68,14 @@ exports[`test test_relative.js 1`] = `
"/* @flow */
// This will require ./A.js.flow
var A1 = require('./A');
var A1 = require(\'./A\');
(A1.fun(): string); // Error number ~> string
// This will require ./A.js.flow
var A2 = require('./A.js');
var A2 = require(\'./A.js\');
(A2.fun(): string); // Error number ~> string
var CJS = require('./CJS.js');
var CJS = require(\'./CJS.js\');
(CJS: string);
(CJS: number); // Error: string ~> number
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ -85,11 +85,11 @@ var CJS = require('./CJS.js');
// This will require ./A.js.flow
// Error number ~> string
// Error: string ~> number
var A1 = require("./A");
var A1 = require(\"./A\");
(A1.fun(): string);
var A2 = require("./A.js");
var A2 = require(\"./A.js\");
(A2.fun(): string);
var CJS = require("./CJS.js");
var CJS = require(\"./CJS.js\");
(CJS: string);
(CJS: number);
"

View File

@ -4,7 +4,7 @@ exports[`test B.js 1`] = `
exports.numberValue = 42;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/* @flow */
exports.numberValue = [object Number];
exports.numberValue = 42;
"
`;
@ -49,19 +49,19 @@ class Base {
class Test extends Base {
static childProp: number;
static staticNumber1(): number {
return [object Number];
return 1;
}
static staticNumber2(): number {
return [object Number];
return 2;
}
static staticNumber3(): number {
return [object Number];
return 3;
}
instNumber1(): number {
return [object Number];
return 1;
}
instNumber2(): number {
return [object Number];
return 2;
}
}
module.exports = Test;
@ -87,11 +87,11 @@ module.exports = {
* @flow
*/
module.exports = {
numberValue1: [object Number],
numberValue2: [object Number],
numberValue3: [object Number],
numberValue4: [object Number],
numberValue5: [object Number]
numberValue1: 1,
numberValue2: 2,
numberValue3: 3,
numberValue4: 4,
numberValue5: 5
};
"
`;
@ -112,11 +112,11 @@ exports.numberValue5 = 5;
* @providesModule CommonJS_Named
* @flow
*/
exports.numberValue1 = [object Number];
exports.numberValue2 = [object Number];
exports.numberValue3 = [object Number];
exports.numberValue4 = [object Number];
exports.numberValue5 = [object Number];
exports.numberValue1 = 1;
exports.numberValue2 = 2;
exports.numberValue3 = 3;
exports.numberValue4 = 4;
exports.numberValue5 = 5;
"
`;
@ -245,13 +245,13 @@ exports[`test ES6_ExportAllFrom_Intermediary1.js 1`] = `
* @flow
*/
declare export * from "ES6_ExportAllFrom_Source1";
declare export * from \"ES6_ExportAllFrom_Source1\";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/**
* @providesModule ES6_ExportAllFrom_Intermediary1
* @flow
*/
declare export * from "ES6_ExportAllFrom_Source1"
declare export * from \"ES6_ExportAllFrom_Source1\"
"
`;
@ -261,13 +261,13 @@ exports[`test ES6_ExportAllFrom_Intermediary2.js 1`] = `
* @flow
*/
declare export * from "ES6_ExportAllFrom_Source2";
declare export * from \"ES6_ExportAllFrom_Source2\";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/**
* @providesModule ES6_ExportAllFrom_Intermediary2
* @flow
*/
declare export * from "ES6_ExportAllFrom_Source2"
declare export * from \"ES6_ExportAllFrom_Source2\"
"
`;
@ -306,12 +306,12 @@ declare export var numberValue2: number;
exports[`test ES6_ExportAllFromMulti.js 1`] = `
"// @flow
declare export * from "./ES6_ExportAllFrom_Source1";
declare export * from "./ES6_ExportAllFrom_Source2";
declare export * from \"./ES6_ExportAllFrom_Source1\";
declare export * from \"./ES6_ExportAllFrom_Source2\";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// @flow
declare export * from "./ES6_ExportAllFrom_Source1"
declare export * from "./ES6_ExportAllFrom_Source2"
declare export * from \"./ES6_ExportAllFrom_Source1\"
declare export * from \"./ES6_ExportAllFrom_Source2\"
"
`;
@ -324,13 +324,13 @@ exports[`test ES6_ExportFrom_Intermediary1.js 1`] = `
declare export {
numberValue1,
numberValue2 as numberValue2_renamed
} from "ES6_ExportFrom_Source1";
} from \"ES6_ExportFrom_Source1\";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/**
* @providesModule ES6_ExportFrom_Intermediary1
* @flow
*/
declare export { numberValue1, numberValue2 as numberValue2_renamed } from "ES6_ExportFrom_Source1"
declare export { numberValue1, numberValue2 as numberValue2_renamed } from \"ES6_ExportFrom_Source1\"
"
`;
@ -343,13 +343,13 @@ exports[`test ES6_ExportFrom_Intermediary2.js 1`] = `
declare export {
numberValue1,
numberValue2 as numberValue2_renamed2
} from "ES6_ExportFrom_Source2";
} from \"ES6_ExportFrom_Source2\";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/**
* @providesModule ES6_ExportFrom_Intermediary2
* @flow
*/
declare export { numberValue1, numberValue2 as numberValue2_renamed2 } from "ES6_ExportFrom_Source2"
declare export { numberValue1, numberValue2 as numberValue2_renamed2 } from \"ES6_ExportFrom_Source2\"
"
`;
@ -416,11 +416,11 @@ declare export var varDeclNumber2: number;
* @providesModule ES6_Named1
* @flow
*/
var specifierNumber1 = [object Number];
var specifierNumber2 = [object Number];
var specifierNumber3 = [object Number];
var groupedSpecifierNumber1 = [object Number];
var groupedSpecifierNumber2 = [object Number];
var specifierNumber1 = 1;
var specifierNumber2 = 2;
var specifierNumber3 = 3;
var groupedSpecifierNumber1 = 1;
var groupedSpecifierNumber2 = 2;
declare export { specifierNumber1 }
declare export { specifierNumber2 as specifierNumber2Renamed }
declare export { specifierNumber3 }
@ -457,10 +457,10 @@ declare export var varDeclNumber4: number;
* @providesModule ES6_Named2
* @flow
*/
var specifierNumber4 = [object Number];
var specifierNumber5 = [object Number];
var groupedSpecifierNumber3 = [object Number];
var groupedSpecifierNumber4 = [object Number];
var specifierNumber4 = 1;
var specifierNumber5 = 2;
var groupedSpecifierNumber3 = 1;
var groupedSpecifierNumber4 = 2;
declare export { specifierNumber4 }
declare export { specifierNumber5 as specifierNumber5Renamed }
declare export { groupedSpecifierNumber3, groupedSpecifierNumber4 }
@ -481,17 +481,17 @@ exports.numberValue1 = 42;
exports.numberValue2 = 42;
exports.numberValue3 = 42;
exports.numberValue4 = 42;
exports.stringValue = "str";
exports.stringValue = \"str\";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/**
* @providesModule A
* @flow
*/
exports.numberValue1 = [object Number];
exports.numberValue2 = [object Number];
exports.numberValue3 = [object Number];
exports.numberValue4 = [object Number];
exports.stringValue = "str";
exports.numberValue1 = 42;
exports.numberValue2 = 42;
exports.numberValue3 = 42;
exports.numberValue4 = 42;
exports.stringValue = \"str\";
"
`;
@ -509,7 +509,7 @@ module.exports = {
* @providesModule CJSDefault
* @flow
*/
module.exports = { numberValue: [object Number] };
module.exports = { numberValue: 42 };
"
`;
@ -568,44 +568,44 @@ exports[`test es6modules.js 1`] = `
// ===================== //
// @providesModule
import * as DefaultA from "A";
import * as DefaultA from \"A\";
var a1: number = DefaultA.numberValue1;
var a2: string = DefaultA.numberValue1; // Error: number ~> string
// File path
import * as DefaultB from "./B";
import * as DefaultB from \"./B\";
var b1: number = DefaultB.numberValue;
var b2: string = DefaultB.numberValue; // Error: number ~> string
// C.js exists, but not as a providesModule
import DefaultC from "C"; // Error: No such module
import DefaultC from \"C\"; // Error: No such module
// @providesModule D exists, but not as a filename
import DefaultD from "./D"; // Error: No such module
import DefaultD from \"./D\"; // Error: No such module
// ================================================ //
// == CommonJS Clobbering Literal Exports -> ES6 == //
// ================================================ //
import {doesntExist1} from "CommonJS_Clobbering_Lit"; // Error: Not an exported binding
import {doesntExist1} from \"CommonJS_Clobbering_Lit\"; // Error: Not an exported binding
import {numberValue1} from "CommonJS_Clobbering_Lit";
import {numberValue1} from \"CommonJS_Clobbering_Lit\";
var c1: number = numberValue1;
var c2: string = numberValue1; // Error: number ~> string
import {numberValue2 as numVal1} from "CommonJS_Clobbering_Lit";
import {numberValue2 as numVal1} from \"CommonJS_Clobbering_Lit\";
var d1: number = numVal1;
var d2: string = numVal1; // Error: number ~> string
import CJS_Clobb_Lit from "CommonJS_Clobbering_Lit";
import CJS_Clobb_Lit from \"CommonJS_Clobbering_Lit\";
var e1: number = CJS_Clobb_Lit.numberValue3;
var e2: string = CJS_Clobb_Lit.numberValue3; // Error: number ~> string
CJS_Clobb_Lit.doesntExist; // Error: doesntExist isn't a property
CJS_Clobb_Lit.doesntExist; // Error: doesntExist isn\'t a property
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 f2: number = CJS_Clobb_Lit_NS.default.numberValue4;
CJS_Clobb_Lit_NS.default.default; // Error: No 'default' property on the exported obj
CJS_Clobb_Lit_NS.default.default; // Error: No \'default\' property on the exported obj
var f3: string = CJS_Clobb_Lit_NS.numberValue4; // Error: number ~> string
var f4: string = CJS_Clobb_Lit_NS.default.numberValue5; // Error: number ~> string
@ -613,15 +613,15 @@ var f4: string = CJS_Clobb_Lit_NS.default.numberValue5; // Error: number ~> stri
// == CommonJS Clobbering Class Exports -> ES6 == //
// ============================================== //
import {doesntExist2} from "CommonJS_Clobbering_Class"; // Error: Not an exported binding
import {doesntExist2} from \"CommonJS_Clobbering_Class\"; // Error: Not an exported binding
// The following import should error because class statics are not turned into
// named exports for now. This avoids complexities with polymorphic static
// members (where the polymophism is defined on the class itself rather than the
// method).
import {staticNumber1, baseProp, childProp} from "CommonJS_Clobbering_Class"; // Error
import {staticNumber1, baseProp, childProp} from \"CommonJS_Clobbering_Class\"; // Error
import CJS_Clobb_Class from "CommonJS_Clobbering_Class";
import CJS_Clobb_Class from \"CommonJS_Clobbering_Class\";
new CJS_Clobb_Class();
new CJS_Clobb_Class().doesntExist; // Error: Class has no \`doesntExist\` property
var h1: number = CJS_Clobb_Class.staticNumber2();
@ -629,8 +629,8 @@ var h2: string = CJS_Clobb_Class.staticNumber2(); // Error: number ~> string
var h3: number = new CJS_Clobb_Class().instNumber1();
var h4: string = new CJS_Clobb_Class().instNumber1(); // Error: number ~> string
import * as CJS_Clobb_Class_NS from "CommonJS_Clobbering_Class";
new CJS_Clobb_Class_NS(); // Error: Namespace object isn't constructable
import * as CJS_Clobb_Class_NS from \"CommonJS_Clobbering_Class\";
new CJS_Clobb_Class_NS(); // Error: Namespace object isn\'t constructable
var i1: number = CJS_Clobb_Class_NS.staticNumber3(); // Error: Class statics not copied to Namespace object
var i2: number = new CJS_Clobb_Class_NS.default().instNumber2();
var i3: string = new CJS_Clobb_Class_NS.default().instNumber2(); // Error: number ~> string
@ -639,22 +639,22 @@ var i3: string = new CJS_Clobb_Class_NS.default().instNumber2(); // Error: numbe
// == CommonJS Named Exports -> ES6 == //
// =================================== //
import {doesntExist3} from "CommonJS_Named"; // Error: Not an exported binding
import {doesntExist3} from \"CommonJS_Named\"; // Error: Not an exported binding
import {numberValue2} from "CommonJS_Named";
import {numberValue2} from \"CommonJS_Named\";
var j1: number = numberValue2;
var j2: string = numberValue2; // Error: number ~> string
import {numberValue3 as numVal3} from "CommonJS_Named";
import {numberValue3 as numVal3} from \"CommonJS_Named\";
var k1: number = numVal3;
var k2: string = numVal3; // Error: number ~> string
import * as CJS_Named from "CommonJS_Named";
import * as CJS_Named from \"CommonJS_Named\";
var l1: number = CJS_Named.numberValue1;
var l2: string = CJS_Named.numberValue1; // Error: number ~> string
CJS_Named.doesntExist; // Error: doesntExist isn't a property
CJS_Named.doesntExist; // Error: doesntExist isn\'t a property
import * as CJS_Named_NS from "CommonJS_Named";
import * as CJS_Named_NS from \"CommonJS_Named\";
var m1: number = CJS_Named_NS.numberValue4;
var m2: string = CJS_Named_NS.default.numberValue4; // Error: CommonJS_Named has no default export
var m3: string = CJS_Named_NS.numberValue4; // Error: number ~> string
@ -663,13 +663,13 @@ var m3: string = CJS_Named_NS.numberValue4; // Error: number ~> string
// == ES6 Default -> ES6 == //
//////////////////////////////
import {doesntExist4} from "ES6_Default_AnonFunction1"; // Error: Not an exported binding
import {doesntExist4} from \"ES6_Default_AnonFunction1\"; // Error: Not an exported binding
import ES6_Def_AnonFunc1 from "ES6_Default_AnonFunction1";
import ES6_Def_AnonFunc1 from \"ES6_Default_AnonFunction1\";
var n1: number = ES6_Def_AnonFunc1();
var n2: string = ES6_Def_AnonFunc1(); // Error: number ~> string
import ES6_Def_NamedFunc1 from "ES6_Default_NamedFunction1";
import ES6_Def_NamedFunc1 from \"ES6_Default_NamedFunction1\";
var o1: number = ES6_Def_NamedFunc1();
var o2: string = ES6_Def_NamedFunc1(); // Error: number ~> string
@ -677,7 +677,7 @@ var o2: string = ES6_Def_NamedFunc1(); // Error: number ~> string
import ES6_Def_NamedClass1 from "ES6_Default_NamedClass1";
import ES6_Def_NamedClass1 from \"ES6_Default_NamedClass1\";
var q1: number = new ES6_Def_NamedClass1().givesANum();
var q2: string = new ES6_Def_NamedClass1().givesANum(); // Error: number ~> string
@ -685,35 +685,35 @@ var q2: string = new ES6_Def_NamedClass1().givesANum(); // Error: number ~> stri
// == ES6 Named -> ES6 == //
////////////////////////////
import doesntExist5 from "ES6_Named1"; // Error: Not an exported binding
import doesntExist5 from \"ES6_Named1\"; // Error: Not an exported binding
import {specifierNumber1 as specifierNumber1_1} from "ES6_Named1";
import {specifierNumber1 as specifierNumber1_1} from \"ES6_Named1\";
var r1: number = specifierNumber1_1;
var r2: string = specifierNumber1_1; // Error: number ~> string
import {specifierNumber2Renamed} from "ES6_Named1";
import {specifierNumber2Renamed} from \"ES6_Named1\";
var s1: number = specifierNumber2Renamed;
var s2: string = specifierNumber2Renamed; // Error: number ~> string
import {specifierNumber3 as specifierNumber3Renamed} from "ES6_Named1";
import {specifierNumber3 as specifierNumber3Renamed} from \"ES6_Named1\";
var t1: number = specifierNumber3Renamed;
var t2: string = specifierNumber3Renamed; // Error: number ~> string
import {groupedSpecifierNumber1, groupedSpecifierNumber2} from "ES6_Named1";
import {groupedSpecifierNumber1, groupedSpecifierNumber2} from \"ES6_Named1\";
var u1: number = groupedSpecifierNumber1;
var u2: number = groupedSpecifierNumber2;
var u3: string = groupedSpecifierNumber1; // Error: number ~> string
var u4: string = groupedSpecifierNumber2; // Error: number ~> string
import {givesANumber} from "ES6_Named1";
import {givesANumber} from \"ES6_Named1\";
var v1: number = givesANumber();
var v2: string = givesANumber(); // Error: number ~> string
import {NumberGenerator} from "ES6_Named1";
import {NumberGenerator} from \"ES6_Named1\";
var w1: number = new NumberGenerator().givesANumber();
var w2: string = new NumberGenerator().givesANumber(); // Error: number ~> string
import {varDeclNumber1, varDeclNumber2} from "ES6_Named1";
import {varDeclNumber1, varDeclNumber2} from \"ES6_Named1\";
var x1: number = varDeclNumber1;
var x2: number = varDeclNumber2;
var x3: string = varDeclNumber1; // Error: number ~> string
@ -727,15 +727,15 @@ var x4: string = varDeclNumber2; // Error: number ~> string
import {numberValue1 as numberValue4} from "ES6_ExportFrom_Intermediary1";
import {numberValue1 as numberValue4} from \"ES6_ExportFrom_Intermediary1\";
var aa1: number = numberValue4;
var aa2: string = numberValue4; // Error: number ~> string
import {numberValue2_renamed} from "ES6_ExportFrom_Intermediary1";
import {numberValue2_renamed} from \"ES6_ExportFrom_Intermediary1\";
var ab1: number = numberValue2_renamed;
var ab2: string = numberValue2_renamed; // Error: number ~> string
import {numberValue1 as numberValue5} from "ES6_ExportAllFrom_Intermediary1";
import {numberValue1 as numberValue5} from \"ES6_ExportAllFrom_Intermediary1\";
var ac1: number = numberValue5;
var ac2: string = numberValue5; // Error: number ~> string
@ -743,13 +743,13 @@ var ac2: string = numberValue5; // Error: number ~> string
// == ES6 Default -> CommonJS == //
///////////////////////////////////
require('ES6_Default_AnonFunction2').doesntExist; // Error: 'doesntExist' isn't an export
require(\'ES6_Default_AnonFunction2\').doesntExist; // Error: \'doesntExist\' isn\'t an export
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 ad2: string = ES6_Def_AnonFunc2(); // Error: number ~> string
var ES6_Def_NamedFunc2 = require("ES6_Default_NamedFunction2").default;
var ES6_Def_NamedFunc2 = require(\"ES6_Default_NamedFunction2\").default;
var ae1: number = ES6_Def_NamedFunc2();
var ae2: string = ES6_Def_NamedFunc2(); // Error: number ~> string
@ -757,7 +757,7 @@ var ae2: string = ES6_Def_NamedFunc2(); // Error: number ~> string
var ES6_Def_NamedClass2 = require("ES6_Default_NamedClass2").default;
var ES6_Def_NamedClass2 = require(\"ES6_Default_NamedClass2\").default;
var ag1: number = new ES6_Def_NamedClass2().givesANum();
var ag2: string = new ES6_Def_NamedClass2().givesANum(); // Error: number ~> string
@ -765,31 +765,31 @@ var ag2: string = new ES6_Def_NamedClass2().givesANum(); // Error: number ~> str
// == ES6 Named -> CommonJS == //
/////////////////////////////////
var specifierNumber4 = require("ES6_Named2").specifierNumber4;
var specifierNumber4 = require(\"ES6_Named2\").specifierNumber4;
var ah1: number = specifierNumber4;
var ah2: string = specifierNumber4; // Error: number ~> string
var specifierNumber5Renamed = require("ES6_Named2").specifierNumber5Renamed;
var specifierNumber5Renamed = require(\"ES6_Named2\").specifierNumber5Renamed;
var ai1: number = specifierNumber5Renamed;
var ai2: string = specifierNumber5Renamed; // Error: number ~> string
var groupedSpecifierNumber3 = require("ES6_Named2").groupedSpecifierNumber3;
var groupedSpecifierNumber4 = require("ES6_Named2").groupedSpecifierNumber4;
var groupedSpecifierNumber3 = require(\"ES6_Named2\").groupedSpecifierNumber3;
var groupedSpecifierNumber4 = require(\"ES6_Named2\").groupedSpecifierNumber4;
var aj1: number = groupedSpecifierNumber3;
var aj2: number = groupedSpecifierNumber4;
var aj3: string = groupedSpecifierNumber3; // Error: number ~> string
var aj4: string = groupedSpecifierNumber4; // Error: number ~> string
var givesANumber2 = require("ES6_Named2").givesANumber2;
var givesANumber2 = require(\"ES6_Named2\").givesANumber2;
var ak1: number = givesANumber2();
var ak2: string = givesANumber2(); // Error: number ~> string
var NumberGenerator2 = require("ES6_Named2").NumberGenerator2;
var NumberGenerator2 = require(\"ES6_Named2\").NumberGenerator2;
var al1: number = new NumberGenerator2().givesANumber();
var al2: string = new NumberGenerator2().givesANumber(); // Error: number ~> string
var varDeclNumber3 = require("ES6_Named2").varDeclNumber3;
var varDeclNumber4 = require("ES6_Named2").varDeclNumber4;
var varDeclNumber3 = require(\"ES6_Named2\").varDeclNumber3;
var varDeclNumber4 = require(\"ES6_Named2\").varDeclNumber4;
var am1: number = varDeclNumber3;
var am2: number = varDeclNumber4;
var am3: string = varDeclNumber3; // Error: number ~> string
@ -803,15 +803,15 @@ var am4: string = varDeclNumber4; // Error: number ~> string
var numberValue6 = require("ES6_ExportFrom_Intermediary2").numberValue1;
var numberValue6 = require(\"ES6_ExportFrom_Intermediary2\").numberValue1;
var ap1: number = numberValue6;
var ap2: string = numberValue6; // Error: number ~> string
var numberValue2_renamed2 = require("ES6_ExportFrom_Intermediary2").numberValue2_renamed2;
var numberValue2_renamed2 = require(\"ES6_ExportFrom_Intermediary2\").numberValue2_renamed2;
var aq1: number = numberValue2_renamed2;
var aq2: string = numberValue2_renamed2; // Error: number ~> string
var numberValue7 = require("ES6_ExportAllFrom_Intermediary2").numberValue2;
var numberValue7 = require(\"ES6_ExportAllFrom_Intermediary2\").numberValue2;
var ar1: number = numberValue7;
var ar2: string = numberValue7; // Error: number ~> string
@ -819,7 +819,7 @@ var ar2: string = numberValue7; // Error: number ~> string
// == ES6 Default+Named -> ES6 import Default+Named== //
////////////////////////////////////////////////////////
import defaultNum, {str as namedStr} from "./ES6_DefaultAndNamed";
import defaultNum, {str as namedStr} from \"./ES6_DefaultAndNamed\";
var as1: number = defaultNum;
var as2: string = defaultNum; // Error: number ~> string
@ -831,13 +831,13 @@ var as4: number = namedStr; // Error: string ~> number
// == Side-effect only ES6 imports == //
////////////////////////////////////////
import "./SideEffects";
import \"./SideEffects\";
//////////////////////////////////////////////
// == Suggest export name on likely typo == //
//////////////////////////////////////////////
import specifierNumber1 from "ES6_Named1"; // Error: Did you mean \`import {specifierNumber1} from ...\`?
import {specifierNumber} from "ES6_Named1"; // Error: Did you mean \`specifierNumber1\`?
import specifierNumber1 from \"ES6_Named1\"; // Error: Did you mean \`import {specifierNumber1} from ...\`?
import {specifierNumber} from \"ES6_Named1\"; // Error: Did you mean \`specifierNumber1\`?
///////////////////////////////////////////////////
// == Multi \`export *\` should combine exports == //
@ -845,7 +845,7 @@ import {specifierNumber} from "ES6_Named1"; // Error: Did you mean \`specifierNu
import {
numberValue1 as numberValue8,
numberValue2 as numberValue9
} from "./ES6_ExportAllFromMulti";
} from \"./ES6_ExportAllFromMulti\";
var at1: number = numberValue8;
var at2: string = numberValue8; // Error: number ~> string
@ -872,8 +872,8 @@ var at4: string = numberValue9; // Error: number ~> string
// Error: number ~> string
// Error: number ~> string
// Error: number ~> string
// Error: doesntExist isn't a property
// Error: No 'default' property on the exported obj
// Error: doesntExist isn\'t a property
// Error: No \'default\' property on the exported obj
// Error: number ~> string
// Error: number ~> string
// ============================================== //
@ -888,7 +888,7 @@ var at4: string = numberValue9; // Error: number ~> string
// Error: Class has no \`doesntExist\` property
// Error: number ~> string
// Error: number ~> string
// Error: Namespace object isn't constructable
// Error: Namespace object isn\'t constructable
// Error: Class statics not copied to Namespace object
// Error: number ~> string
// =================================== //
@ -898,7 +898,7 @@ var at4: string = numberValue9; // Error: number ~> string
// Error: number ~> string
// Error: number ~> string
// Error: number ~> string
// Error: doesntExist isn't a property
// Error: doesntExist isn\'t a property
// Error: CommonJS_Named has no default export
// Error: number ~> string
//////////////////////////////
@ -927,7 +927,7 @@ var at4: string = numberValue9; // Error: number ~> string
///////////////////////////////////
// == ES6 Default -> CommonJS == //
///////////////////////////////////
// Error: 'doesntExist' isn't an export
// Error: \'doesntExist\' isn\'t an export
// Error: number ~> string
// Error: number ~> string
// Error: number ~> string
@ -963,159 +963,159 @@ var at4: string = numberValue9; // Error: number ~> string
///////////////////////////////////////////////////
// Error: number ~> string
// Error: number ~> string
import * as DefaultA from "A";
import * as DefaultA from \"A\";
var a1: number = DefaultA.numberValue1;
var a2: string = DefaultA.numberValue1;
import * as DefaultB from "./B";
import * as DefaultB from \"./B\";
var b1: number = DefaultB.numberValue;
var b2: string = DefaultB.numberValue;
import DefaultC from "C";
import DefaultD from "./D";
import { doesntExist1 } from "CommonJS_Clobbering_Lit";
import { numberValue1 } from "CommonJS_Clobbering_Lit";
import DefaultC from \"C\";
import DefaultD from \"./D\";
import { doesntExist1 } from \"CommonJS_Clobbering_Lit\";
import { numberValue1 } from \"CommonJS_Clobbering_Lit\";
var c1: number = numberValue1;
var c2: string = numberValue1;
import { numberValue2 as numVal1 } from "CommonJS_Clobbering_Lit";
import { numberValue2 as numVal1 } from \"CommonJS_Clobbering_Lit\";
var d1: number = numVal1;
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 e2: string = CJS_Clobb_Lit.numberValue3;
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 f2: number = CJS_Clobb_Lit_NS.default.numberValue4;
CJS_Clobb_Lit_NS.default.default;
var f3: string = CJS_Clobb_Lit_NS.numberValue4;
var f4: string = CJS_Clobb_Lit_NS.default.numberValue5;
import { doesntExist2 } from "CommonJS_Clobbering_Class";
import { staticNumber1, baseProp, childProp } from "CommonJS_Clobbering_Class";
import CJS_Clobb_Class from "CommonJS_Clobbering_Class";
import { doesntExist2 } from \"CommonJS_Clobbering_Class\";
import { staticNumber1, baseProp, childProp } from \"CommonJS_Clobbering_Class\";
import CJS_Clobb_Class from \"CommonJS_Clobbering_Class\";
new CJS_Clobb_Class();
new CJS_Clobb_Class().doesntExist;
var h1: number = CJS_Clobb_Class.staticNumber2();
var h2: string = CJS_Clobb_Class.staticNumber2();
var h3: number = new CJS_Clobb_Class().instNumber1();
var h4: string = new CJS_Clobb_Class().instNumber1();
import * as CJS_Clobb_Class_NS from "CommonJS_Clobbering_Class";
import * as CJS_Clobb_Class_NS from \"CommonJS_Clobbering_Class\";
new CJS_Clobb_Class_NS();
var i1: number = CJS_Clobb_Class_NS.staticNumber3();
var i2: number = new CJS_Clobb_Class_NS.default().instNumber2();
var i3: string = new CJS_Clobb_Class_NS.default().instNumber2();
import { doesntExist3 } from "CommonJS_Named";
import { numberValue2 } from "CommonJS_Named";
import { doesntExist3 } from \"CommonJS_Named\";
import { numberValue2 } from \"CommonJS_Named\";
var j1: number = numberValue2;
var j2: string = numberValue2;
import { numberValue3 as numVal3 } from "CommonJS_Named";
import { numberValue3 as numVal3 } from \"CommonJS_Named\";
var k1: number = numVal3;
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 l2: string = CJS_Named.numberValue1;
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 m2: string = CJS_Named_NS.default.numberValue4;
var m3: string = CJS_Named_NS.numberValue4;
import { doesntExist4 } from "ES6_Default_AnonFunction1";
import ES6_Def_AnonFunc1 from "ES6_Default_AnonFunction1";
import { doesntExist4 } from \"ES6_Default_AnonFunction1\";
import ES6_Def_AnonFunc1 from \"ES6_Default_AnonFunction1\";
var n1: number = ES6_Def_AnonFunc1();
var n2: string = ES6_Def_AnonFunc1();
import ES6_Def_NamedFunc1 from "ES6_Default_NamedFunction1";
import ES6_Def_NamedFunc1 from \"ES6_Default_NamedFunction1\";
var o1: number = ES6_Def_NamedFunc1();
var o2: string = ES6_Def_NamedFunc1();
import ES6_Def_NamedClass1 from "ES6_Default_NamedClass1";
import ES6_Def_NamedClass1 from \"ES6_Default_NamedClass1\";
var q1: number = new ES6_Def_NamedClass1().givesANum();
var q2: string = new ES6_Def_NamedClass1().givesANum();
import doesntExist5 from "ES6_Named1";
import { specifierNumber1 as specifierNumber1_1 } from "ES6_Named1";
import doesntExist5 from \"ES6_Named1\";
import { specifierNumber1 as specifierNumber1_1 } from \"ES6_Named1\";
var r1: number = specifierNumber1_1;
var r2: string = specifierNumber1_1;
import { specifierNumber2Renamed } from "ES6_Named1";
import { specifierNumber2Renamed } from \"ES6_Named1\";
var s1: number = specifierNumber2Renamed;
var s2: string = specifierNumber2Renamed;
import { specifierNumber3 as specifierNumber3Renamed } from "ES6_Named1";
import { specifierNumber3 as specifierNumber3Renamed } from \"ES6_Named1\";
var t1: number = specifierNumber3Renamed;
var t2: string = specifierNumber3Renamed;
import { groupedSpecifierNumber1, groupedSpecifierNumber2 } from "ES6_Named1";
import { groupedSpecifierNumber1, groupedSpecifierNumber2 } from \"ES6_Named1\";
var u1: number = groupedSpecifierNumber1;
var u2: number = groupedSpecifierNumber2;
var u3: string = groupedSpecifierNumber1;
var u4: string = groupedSpecifierNumber2;
import { givesANumber } from "ES6_Named1";
import { givesANumber } from \"ES6_Named1\";
var v1: number = givesANumber();
var v2: string = givesANumber();
import { NumberGenerator } from "ES6_Named1";
import { NumberGenerator } from \"ES6_Named1\";
var w1: number = new NumberGenerator().givesANumber();
var w2: string = new NumberGenerator().givesANumber();
import { varDeclNumber1, varDeclNumber2 } from "ES6_Named1";
import { varDeclNumber1, varDeclNumber2 } from \"ES6_Named1\";
var x1: number = varDeclNumber1;
var x2: number = varDeclNumber2;
var x3: string = varDeclNumber1;
var x4: string = varDeclNumber2;
import { numberValue1 as numberValue4 } from "ES6_ExportFrom_Intermediary1";
import { numberValue1 as numberValue4 } from \"ES6_ExportFrom_Intermediary1\";
var aa1: number = numberValue4;
var aa2: string = numberValue4;
import { numberValue2_renamed } from "ES6_ExportFrom_Intermediary1";
import { numberValue2_renamed } from \"ES6_ExportFrom_Intermediary1\";
var ab1: number = numberValue2_renamed;
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 ac2: string = numberValue5;
require("ES6_Default_AnonFunction2").doesntExist;
var ES6_Def_AnonFunc2 = require("ES6_Default_AnonFunction2").default;
require(\"ES6_Default_AnonFunction2\").doesntExist;
var ES6_Def_AnonFunc2 = require(\"ES6_Default_AnonFunction2\").default;
var ad1: number = ES6_Def_AnonFunc2();
var ad2: string = ES6_Def_AnonFunc2();
var ES6_Def_NamedFunc2 = require("ES6_Default_NamedFunction2").default;
var ES6_Def_NamedFunc2 = require(\"ES6_Default_NamedFunction2\").default;
var ae1: number = ES6_Def_NamedFunc2();
var ae2: string = ES6_Def_NamedFunc2();
var ES6_Def_NamedClass2 = require("ES6_Default_NamedClass2").default;
var ES6_Def_NamedClass2 = require(\"ES6_Default_NamedClass2\").default;
var ag1: number = new ES6_Def_NamedClass2().givesANum();
var ag2: string = new ES6_Def_NamedClass2().givesANum();
var specifierNumber4 = require("ES6_Named2").specifierNumber4;
var specifierNumber4 = require(\"ES6_Named2\").specifierNumber4;
var ah1: number = specifierNumber4;
var ah2: string = specifierNumber4;
var specifierNumber5Renamed = require("ES6_Named2").specifierNumber5Renamed;
var specifierNumber5Renamed = require(\"ES6_Named2\").specifierNumber5Renamed;
var ai1: number = specifierNumber5Renamed;
var ai2: string = specifierNumber5Renamed;
var groupedSpecifierNumber3 = require("ES6_Named2").groupedSpecifierNumber3;
var groupedSpecifierNumber4 = require("ES6_Named2").groupedSpecifierNumber4;
var groupedSpecifierNumber3 = require(\"ES6_Named2\").groupedSpecifierNumber3;
var groupedSpecifierNumber4 = require(\"ES6_Named2\").groupedSpecifierNumber4;
var aj1: number = groupedSpecifierNumber3;
var aj2: number = groupedSpecifierNumber4;
var aj3: string = groupedSpecifierNumber3;
var aj4: string = groupedSpecifierNumber4;
var givesANumber2 = require("ES6_Named2").givesANumber2;
var givesANumber2 = require(\"ES6_Named2\").givesANumber2;
var ak1: number = givesANumber2();
var ak2: string = givesANumber2();
var NumberGenerator2 = require("ES6_Named2").NumberGenerator2;
var NumberGenerator2 = require(\"ES6_Named2\").NumberGenerator2;
var al1: number = new NumberGenerator2().givesANumber();
var al2: string = new NumberGenerator2().givesANumber();
var varDeclNumber3 = require("ES6_Named2").varDeclNumber3;
var varDeclNumber4 = require("ES6_Named2").varDeclNumber4;
var varDeclNumber3 = require(\"ES6_Named2\").varDeclNumber3;
var varDeclNumber4 = require(\"ES6_Named2\").varDeclNumber4;
var am1: number = varDeclNumber3;
var am2: number = varDeclNumber4;
var am3: string = varDeclNumber3;
var am4: string = varDeclNumber4;
var numberValue6 = require("ES6_ExportFrom_Intermediary2").numberValue1;
var numberValue6 = require(\"ES6_ExportFrom_Intermediary2\").numberValue1;
var ap1: number = numberValue6;
var ap2: string = numberValue6;
var numberValue2_renamed2 = require(
"ES6_ExportFrom_Intermediary2"
\"ES6_ExportFrom_Intermediary2\"
).numberValue2_renamed2;
var aq1: number = numberValue2_renamed2;
var aq2: string = numberValue2_renamed2;
var numberValue7 = require("ES6_ExportAllFrom_Intermediary2").numberValue2;
var numberValue7 = require(\"ES6_ExportAllFrom_Intermediary2\").numberValue2;
var ar1: number = numberValue7;
var ar2: string = numberValue7;
import defaultNum, { str as namedStr } from "./ES6_DefaultAndNamed";
import defaultNum, { str as namedStr } from \"./ES6_DefaultAndNamed\";
var as1: number = defaultNum;
var as2: string = defaultNum;
var as3: string = namedStr;
var as4: number = namedStr;
import "./SideEffects";
import specifierNumber1 from "ES6_Named1";
import { specifierNumber } from "ES6_Named1";
import { numberValue1 as numberValue8, numberValue2 as numberValue9 } from "./ES6_ExportAllFromMulti";
import \"./SideEffects\";
import specifierNumber1 from \"ES6_Named1\";
import { specifierNumber } from \"ES6_Named1\";
import { numberValue1 as numberValue8, numberValue2 as numberValue9 } from \"./ES6_ExportAllFromMulti\";
var at1: number = numberValue8;
var at2: string = numberValue8;
var at3: number = numberValue9;

View File

@ -4,7 +4,7 @@ declare function foo(x: string): number;
declare function foo<X>(x: X): X;
(foo(0): string); // OK
(foo("hello"): number); // OK
(foo(\"hello\"): number); // OK
(foo(false): void); // error, boolean ~/~ undefined
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// OK
@ -13,8 +13,8 @@ declare function foo<X>(x: X): X;
declare function foo(x: number): string;
declare function foo(x: string): number;
declare function foo(x: X): X;
(foo([object Number]): string);
(foo("hello"): number);
(foo([object Boolean]): void);
(foo(0): string);
(foo(\"hello\"): number);
(foo(false): void);
"
`;

View File

@ -1,15 +1,15 @@
exports[`test main.js 1`] = `
"// @flow
import declare_module_exports from "declare_module_exports";
import declare_module_exports from \"declare_module_exports\";
(declare_module_exports: number);
(declare_module_exports: string); // Error: number ~> string
// Error: Has no named export "str"!
import {str} from "declare_m_e_with_other_value_declares";
// Error: Has no named export \"str\"!
import {str} from \"declare_m_e_with_other_value_declares\";
import type {str2} from "declare_m_e_with_other_type_declares";
("asdf": str2);
import type {str2} from \"declare_m_e_with_other_type_declares\";
(\"asdf\": str2);
(42: str2); // Error: number ~> string
/**
@ -17,17 +17,17 @@ import type {str2} from "declare_m_e_with_other_type_declares";
* syntaxes will work.
*/
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: string); // Error: number ~> 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: string); // Error: number ~> string
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// @flow
// Error: number ~> string
// Error: Has no named export "str"!
// Error: Has no named export \"str\"!
// Error: number ~> string
/**
* \`declare var exports\` is deprecated, so we have a grace period where both
@ -35,17 +35,17 @@ import declare_m_e_with_declare_var_e from "declare_m_e_with_declare_var_e";
*/
// Error: number ~> string
// Error: number ~> string
import declare_module_exports from "declare_module_exports";
import declare_module_exports from \"declare_module_exports\";
(declare_module_exports: number);
(declare_module_exports: string);
import { str } from "declare_m_e_with_other_value_declares";
import type { str2 } from "declare_m_e_with_other_type_declares";
("asdf": str2);
([object Number]: str2);
import DEPRECATED__declare_var_exports from "DEPRECATED__declare_var_exports";
import { str } from \"declare_m_e_with_other_value_declares\";
import type { str2 } from \"declare_m_e_with_other_type_declares\";
(\"asdf\": str2);
(42: str2);
import DEPRECATED__declare_var_exports from \"DEPRECATED__declare_var_exports\";
(DEPRECATED__declare_var_exports: number);
(DEPRECATED__declare_var_exports: string);
import declare_m_e_with_declare_var_e from "declare_m_e_with_declare_var_e";
import declare_m_e_with_declare_var_e from \"declare_m_e_with_declare_var_e\";
(declare_m_e_with_declare_var_e: number);
(declare_m_e_with_declare_var_e: string);
"

View File

@ -6,21 +6,21 @@ exports[`test import_declare_type.js 1`] = `
////////////////////////////////////////////////////////////
// == Import Declared Type Alias From Declared Module == //
//////////////////////////////////////////////////////////
import type {baz} from "ModuleAliasFoo";
import {foo} from "ModuleAliasFoo";
import type {baz} from \"ModuleAliasFoo\";
import {foo} from \"ModuleAliasFoo\";
var k1: baz = 42;
var k2: baz = "shab"; // Error: string to int
var k2: baz = \"shab\"; // Error: string to int
var k3: toz = foo(k1); // works
import type {toz} from "ModuleAliasFoo";
import type {toz} from \"ModuleAliasFoo\";
var k4: toz = foo(k1); // works
//////////////////////////////////////////////////////////
// == Declared Module with exports prop (issue 880) == //
////////////////////////////////////////////////////////
import blah from 'foo';
import type { Foo, Bar, Id } from 'foo';
import blah from \'foo\';
import type { Foo, Bar, Id } from \'foo\';
blah(0, 0);
@ -28,7 +28,7 @@ blah(0, 0);
(3 : Bar); // error : number ~> A
("lol" : Id<number>); // error : string ~> number
(\"lol\" : Id<number>); // error : string ~> number
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/**
* @flow
@ -45,18 +45,18 @@ blah(0, 0);
// error : {toz : number} ~> string
// error : number ~> A
// error : string ~> number
import type { baz } from "ModuleAliasFoo";
import { foo } from "ModuleAliasFoo";
var k1: baz = [object Number];
var k2: baz = "shab";
import type { baz } from \"ModuleAliasFoo\";
import { foo } from \"ModuleAliasFoo\";
var k1: baz = 42;
var k2: baz = \"shab\";
var k3: toz = foo(k1);
import type { toz } from "ModuleAliasFoo";
import type { toz } from \"ModuleAliasFoo\";
var k4: toz = foo(k1);
import blah from "foo";
import type { Foo, Bar, Id } from "foo";
blah([object Number], [object Number]);
({ toz: [object Number] }: Foo);
([object Number]: Bar);
("lol": Id<number>);
import blah from \"foo\";
import type { Foo, Bar, Id } from \"foo\";
blah(0, 0);
({ toz: 3 }: Foo);
(3: Bar);
(\"lol\": Id<number>);
"
`;

View File

@ -11,9 +11,9 @@ f(x);
/* demo */
//...
function f(x) {
return [object Number] / x;
return 42 / x;
}
var x = [object Null];
var x = null;
f(x);
"
`;

View File

@ -36,18 +36,18 @@ class A {
function callback(x: string) {
return x.length;
}
var a = new A([object Number]);
var a = new A(42);
a.onLoad(callback);
module.exports = A;
"
`;
exports[`test B.js 1`] = `
"var A = require('Demo');
"var A = require(\'Demo\');
var z = new A("42").getX();
var z = new A(\"42\").getX();
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
var A = require("Demo");
var z = new A("42").getX();
var A = require(\"Demo\");
var z = new A(\"42\").getX();
"
`;

View File

@ -1,5 +1,5 @@
exports[`test array_rest.js 1`] = `
"let xs = [0, "", true];
"let xs = [0, \"\", true];
let [a, ...ys] = xs;
let [b, ...zs] = ys;
let c = zs[0]; // retain tuple info
@ -18,39 +18,39 @@ let [...e] = 0;
// error: string ~> void
// error: boolean ~> void
// error: number|string|boolean ~> void
let xs = [ [object Number], "", [object Boolean] ];
let xs = [ 0, \"\", true ];
let [ a, ...ys ] = xs;
let [ b, ...zs ] = ys;
let c = zs[[object Number]];
let d = zs[[object Number]];
let c = zs[0];
let d = zs[1];
(a: void);
(b: void);
(c: void);
(d: void);
let [ ...e ] = [object Number];
let [ ...e ] = 0;
"
`;
exports[`test computed.js 1`] = `
"var { ["key"]: val1 } = { key: "val" };
"var { [\"key\"]: val1 } = { key: \"val\" };
(val1: void); // error: string ~> void
var key: string = "key";
var { [key]: val2 } = { key: "val" };
var key: string = \"key\";
var { [key]: val2 } = { key: \"val\" };
(val2: void); // ok (gasp!) by existing StrT -> ElemT rule
var { ["key"]: val3, ...spread } = { key: "val" };
(spread.key: void); // error (gasp!) in general we don't know if a computed prop should be excluded from spread
var { [\"key\"]: val3, ...spread } = { key: \"val\" };
(spread.key: void); // error (gasp!) in general we don\'t know if a computed prop should be excluded from spread
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// error: string ~> void
// ok (gasp!) by existing StrT -> ElemT rule
// error (gasp!) in general we don't know if a computed prop should be excluded from spread
var { ["key"]: val1 } = { key: "val" };
// error (gasp!) in general we don\'t know if a computed prop should be excluded from spread
var { [\"key\"]: val1 } = { key: \"val\" };
(val1: void);
var key: string = "key";
var { [key]: val2 } = { key: "val" };
var key: string = \"key\";
var { [key]: val2 } = { key: \"val\" };
(val2: void);
var { ["key"]: val3, ...spread } = { key: "val" };
var { [\"key\"]: val3, ...spread } = { key: \"val\" };
(spread.key: void);
"
`;
@ -58,7 +58,7 @@ var { ["key"]: val3, ...spread } = { key: "val" };
exports[`test defaults.js 1`] = `
"/* @flow */
function obj_prop_fun({p:{q=0}={q:true}}={p:{q:""}}) {
function obj_prop_fun({p:{q=0}={q:true}}={p:{q:\"\"}}) {
// errors:
// * number ~> void, from default on _.p.q
// * boolean ~> void, from default on _.p
@ -69,9 +69,9 @@ function obj_prop_fun({p:{q=0}={q:true}}={p:{q:""}}) {
obj_prop_fun(); // ok
obj_prop_fun({}); // ok
obj_prop_fun({p:{}}); // ok
obj_prop_fun({p:{q:null}}); // ok, provides add'l lower bound
obj_prop_fun({p:{q:null}}); // ok, provides add\'l lower bound
function obj_prop_var(o={p:{q:""}}) {
function obj_prop_var(o={p:{q:\"\"}}) {
var {p:{q=0}={q:true}} = o;
// errors:
// * number ~> void, from default on o.p.q
@ -83,9 +83,9 @@ function obj_prop_var(o={p:{q:""}}) {
obj_prop_var(); // ok
obj_prop_var({}); // ok
obj_prop_var({p:{}}); // ok
obj_prop_var({p:{q:null}}); // ok, provides add'l lower bound
obj_prop_var({p:{q:null}}); // ok, provides add\'l lower bound
function obj_rest({p:{q,...o}={q:0,r:0}}={p:{q:0,r:""}}) {
function obj_rest({p:{q,...o}={q:0,r:0}}={p:{q:0,r:\"\"}}) {
// errors:
// * number ~> void, from default on _.p
// * string ~> void, from default on _
@ -148,7 +148,7 @@ function default_expr_scope({a, b = a}) {}
// ok
// ok
// ok
// ok, provides add'l lower bound
// ok, provides add\'l lower bound
// errors:
// * number ~> void, from default on o.p.q
// * boolean ~> void, from default on o.p
@ -157,7 +157,7 @@ function default_expr_scope({a, b = a}) {}
// ok
// ok
// ok
// ok, provides add'l lower bound
// ok, provides add\'l lower bound
// errors:
// * number ~> void, from default on _.p
// * string ~> void, from default on _
@ -180,49 +180,45 @@ function default_expr_scope({a, b = a}) {}
// ok
// union-like upper bounds preserved through destructuring
// TODO: union-of-objects upper bounds preserved through destructuring
function obj_prop_fun(
{ p: { q } = { q: [object Boolean] } } = { p: { q: "" } }
) {
function obj_prop_fun({ p: { q } = { q: true } } = { p: { q: \"\" } }) {
(q: void);
}
obj_prop_fun();
obj_prop_fun({});
obj_prop_fun({ p: {} });
obj_prop_fun({ p: { q: [object Null] } });
function obj_prop_var(o = { p: { q: "" } }) {
var { p: { q } = { q: [object Boolean] } } = o;
obj_prop_fun({ p: { q: null } });
function obj_prop_var(o = { p: { q: \"\" } }) {
var { p: { q } = { q: true } } = o;
(q: void);
}
obj_prop_var();
obj_prop_var({});
obj_prop_var({ p: {} });
obj_prop_var({ p: { q: [object Null] } });
obj_prop_var({ p: { q: null } });
function obj_rest(
{ p: { q, ...o } = { q: [object Number], r: [object Number] } } = {
p: { q: [object Number], r: "" }
}
{ p: { q, ...o } = { q: 0, r: 0 } } = { p: { q: 0, r: \"\" } }
) {
(o.r: void);
}
obj_rest();
obj_rest({});
obj_rest({ p: {} });
obj_rest({ p: { q: [object Number], r: [object Null] } });
function obj_prop_annot({ p } = { p: [object Number] }) {
obj_rest({ p: { q: 0, r: null } });
function obj_prop_annot({ p } = { p: 0 }) {
(p: void);
}
var { p } = { p: [object Number] };
var { p } = { p: 0 };
(p: void);
function obj_prop_err({ x: { y } } = [object Null]) {
function obj_prop_err({ x: { y } } = null) {
}
function obj_rest_err({ ...o } = [object Number]) {
function obj_rest_err({ ...o } = 0) {
}
function arr_elem_err([ x ] = [object Null]) {
function arr_elem_err([ x ] = null) {
}
function arr_rest_err([ ...a ] = [object Null]) {
function arr_rest_err([ ...a ] = null) {
}
function gen<T>(x: T, { p }): T {
@ -230,16 +226,16 @@ function gen<T>(x: T, { p }): T {
}
obj_prop_fun(({}: { p?: { q?: null } }));
obj_prop_var(({}: { p?: { q?: null } }));
function obj_prop_opt({ p } = { p: [object Number] }) {
function obj_prop_opt({ p } = { p: 0 }) {
}
function obj_prop_maybe({ p } = { p: [object Number] }) {
function obj_prop_maybe({ p } = { p: 0 }) {
}
function obj_prop_union({ p } = { p: [object Boolean] }) {
function obj_prop_union({ p } = { p: true }) {
}
function obj_prop_union2({ p } = { p: [object Boolean] }) {
function obj_prop_union2({ p } = { p: true }) {
}
function default_expr_scope({ a, b }) {
@ -259,7 +255,7 @@ var {m} = {m:0};
var obj;
({n: obj.x} = {n:3});
[obj.x] = ['foo'];
[obj.x] = [\'foo\'];
function foo({p, z:[r]}) {
a = p;
@ -273,17 +269,17 @@ foo({p:0, z:[1,2]});
function bar({x, ...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};
function qux(_: {a:number}) { }
qux({a:""});
qux({a:\"\"});
function corge({b}: {b:string}) { }
corge({b:0});
var {n}:{n: number} = {n: ""}
var {n}:{n: number} = {n: \"\"}
function test() {
var {foo} = {bar: 123}; // error on foo
@ -291,9 +287,9 @@ function test() {
}
function test() {
var x = {foo: 'abc', bar: 123};
var x = {foo: \'abc\', bar: 123};
var {foo, ...rest} = x;
(x.baz: string); // error, baz doesn't exist
(x.baz: string); // error, baz doesn\'t exist
(rest.baz: string); // no error, rest is unsealed
}
@ -323,7 +319,7 @@ var cp2_err: string = others.childprop2; // Error: number ~> string
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// error on foo
// error on baz
// error, baz doesn't exist
// error, baz doesn\'t exist
// no error, rest is unsealed
// Error: number ~> string
// Error: number ~> string
@ -332,51 +328,40 @@ var cp2_err: string = others.childprop2; // Error: number ~> string
declare var a: string;
declare var b: string;
declare var c: string;
[ { a1: a, b }, c ] = [
{ a1: [object Number], b: [object Number] },
[object Number]
];
var { m } = { m: [object Number] };
[ { a1: a, b }, c ] = [ { a1: 0, b: 1 }, 2 ];
var { m } = { m: 0 };
{ m } = { m: m };
var obj;
{ n: obj.x } = { n: [object Number] };
[ obj.x ] = [ "foo" ];
{ n: obj.x } = { n: 3 };
[ obj.x ] = [ \"foo\" ];
function foo({ p, z: [ r ] }) {
a = p;
b = z;
c = r;
}
foo({ p: [object Number], z: [ [object Number], [object Number] ] });
[ a, , b, ...c ] = [
[object Number],
[object Number],
[object Boolean],
[object Number]
];
foo({ p: 0, z: [ 1, 2 ] });
[ a, , b, ...c ] = [ 0, 1, true, 3 ];
function bar({ x, ...z }) {
var o: { x: string, y: number } = z;
}
bar({ x: "", y: [object Number] });
var spread = { y: "" };
var extend: { x: number, y: string, z: boolean } = {
x: [object Number],
...spread
};
bar({ x: \"\", y: 0 });
var spread = { y: \"\" };
var extend: { x: number, y: string, z: boolean } = { x: 0, ...spread };
function qux(_: { a: number }) {
}
qux({ a: "" });
qux({ a: \"\" });
function corge({ b }) {
}
corge({ b: [object Number] });
var { n } = { n: "" };
corge({ b: 0 });
var { n } = { n: \"\" };
function test() {
var { foo } = { bar: [object Number] };
var { bar, baz } = { bar: [object Number] };
var { foo } = { bar: 123 };
var { bar, baz } = { bar: 123 };
}
function test() {
var x = { foo: "abc", bar: [object Number] };
var x = { foo: \"abc\", bar: 123 };
var { foo, ...rest } = x;
(x.baz: string);
(rest.baz: string);
@ -448,7 +433,7 @@ exports[`test eager.js 1`] = `
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// error, property \`x\` can not be accessed on \`null\`
var x;
{ x } = [object Null];
{ x } = null;
"
`;
@ -516,7 +501,7 @@ function arr_pattern2<X>([ elem ]) {
function tup_pattern<X>([ proj ]) {
}
type Proj<X> = [];
type Proj<X> = [X];
function tup_pattern2<X>([ proj ]) {
}
@ -534,11 +519,11 @@ function obj_rest_pattern<X>({ _, ...o }) {
o.x;
}
function arr_rest_pattern<X>([ _, ...a ]) {
a[[object Number]];
a[0];
}
type ArrRest<X> = [];
type ArrRest<X> = [anyX];
function arr_rest_pattern<X>([ _, ...a ]) {
a[[object Number]];
a[0];
}
"
`;
@ -546,7 +531,7 @@ function arr_rest_pattern<X>([ _, ...a ]) {
exports[`test rec.js 1`] = `
"// @flow
// Make sure that destructuring doesn't cause infinite loops when combined with
// Make sure that destructuring doesn\'t cause infinite loops when combined with
// funny doses of repositioning
let foo = (i: number) => [i];
@ -560,15 +545,15 @@ foo = (i: number) => {
return bar(i);
};
// Also make sure that the following doesn't loop
// Also make sure that the following doesn\'t loop
declare var o;
var { x: o } = o;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// @flow
// Make sure that destructuring doesn't cause infinite loops when combined with
// Make sure that destructuring doesn\'t cause infinite loops when combined with
// funny doses of repositioning
// Also make sure that the following doesn't loop
// Also make sure that the following doesn\'t loop
let foo = (i: number) => [ i ];
const bar = (i: number) => {
[ i ] = foo(i);
@ -583,18 +568,18 @@ var { x: o } = o;
`;
exports[`test string_lit.js 1`] = `
"var { "key": val } = { key: "val" };
"var { \"key\": val } = { key: \"val\" };
(val: void); // error: string ~> void
var { "with-dash": with_dash } = { "with-dash": "motivating example" };
(with_dash: "motivating example"); // ok
var { \"with-dash\": with_dash } = { \"with-dash\": \"motivating example\" };
(with_dash: \"motivating example\"); // ok
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// error: string ~> void
// ok
var { "key": val } = { key: "val" };
var { \"key\": val } = { key: \"val\" };
(val: void);
var { "with-dash": with_dash } = { "with-dash": "motivating example" };
(with_dash: "motivating example");
var { \"with-dash\": with_dash } = { \"with-dash\": \"motivating example\" };
(with_dash: \"motivating example\");
"
`;
@ -602,7 +587,7 @@ exports[`test unannotated.js 1`] = `
"// @flow
var { x } = {
x: { foo: "foo" }
x: { foo: \"foo\" }
};
function bar() {
@ -610,7 +595,7 @@ function bar() {
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// @flow
var { x } = { x: { foo: "foo" } };
var { x } = { x: { foo: \"foo\" } };
function bar() {
x.bar;
}

View File

@ -2,13 +2,13 @@ exports[`test any.js 1`] = `
"/* @flow */
const dict: {[key: string]: number} = {}
const k: any = 'foo'
const k: any = \'foo\'
const val: string = dict[k] // error: number incompatible with string
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/* @flow */
// error: number incompatible with string
const dict: { [key: string]: number } = {};
const k: any = "foo";
const k: any = \"foo\";
const val: string = dict[k];
"
`;
@ -19,25 +19,25 @@ exports[`test compatible.js 1`] = `
function foo0(x: Array<{[key: string]: mixed}>): Array<{[key: string]: mixed}> {
// this adds a fooBar property to the param type, which should NOT cause
// an error in the return type because it is a dictionary.
x[0].fooBar = 'foobar';
x[0].fooBar = \'foobar\';
return x;
}
function foo2(
x: {[key: string]: number}
): {[key: string]: number, +toString: () => string} {
// x's prototype has a toString method
// x\'s prototype has a toString method
return x;
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/* @flow */
// this adds a fooBar property to the param type, which should NOT cause
// an error in the return type because it is a dictionary.
// x's prototype has a toString method
// x\'s prototype has a toString method
function foo0(x: Array<{ [key: string]: mixed }>): Array<{
[key: string]: mixed
}> {
x[[object Number]].fooBar = "foobar";
x[0].fooBar = \"foobar\";
return x;
}
function foo2(x: { [key: string]: number }): {
@ -59,7 +59,7 @@ exports[`test dictionary.js 1`] = `
* maps. They can also be used to represent array-like objects, e.g., NodeList
* from the DOM API.
*
* A dictionary is assumed to have every property described by it's key type.
* A dictionary is assumed to have every property described by it\'s key type.
* This behavior is similar to the behavior of arrays, which are assumed to have
* a value at every index.
*
@ -79,17 +79,17 @@ class Y {}
function set_prop_to_string_key(
o: {[k:string]:any},
) {
o.prop = "ok";
o.prop = \"ok\";
}
// **UNSOUND**
// This is allowed by design. We don't track get/set and we don't wrap the
// This is allowed by design. We don\'t track get/set and we don\'t wrap the
// return type in a maybe.
function unsound_dict_has_every_key(
o: {[k:string]:X},
) {
(o.p: X); // ok
(o["p"]: X); // ok
(o[\"p\"]: X); // ok
}
// As with any object type, we can assign subtypes to properties.
@ -101,7 +101,7 @@ function set_prop_covariant(
o.p = new C; // ok
}
// This isn't specific behavior to dictionaries, but for completeness...
// This isn\'t specific behavior to dictionaries, but for completeness...
function get_prop_contravariant(
o: {[k:string]:B},
) {
@ -115,7 +115,7 @@ function get_prop_contravariant(
function add_prop_to_nonstring_key_dot(
o: {[k:number]:any},
) {
o.prop = "err"; // error: string ~> number
o.prop = \"err\"; // error: string ~> number
}
// Bracket notation can be used to add properties to dictionaries with
@ -124,7 +124,7 @@ function add_prop_to_nonstring_key_dot(
function add_prop_to_nonstring_key_bracket(
o: {[k:number]:any},
) {
o[0] = "ok";
o[0] = \"ok\";
}
// Objects can be part dict, part not by mixing an indexer with declared props.
@ -148,12 +148,12 @@ function object_prototype(
}
// **UNSOUND**
// Because we support non-string props w/ bracket notation, it's possible to
// Because we support non-string props w/ bracket notation, it\'s possible to
// write into a declared prop unsoundly.
function unsound_string_conversion_alias_declared_prop(
o: {[k:number]:any, "0":X},
o: {[k:number]:any, \"0\":X},
) {
o[0] = "not-x"; // a["0"] no longer X
o[0] = \"not-x\"; // a[\"0\"] no longer X
}
function unification_dict_values_invariant(
@ -201,7 +201,7 @@ function subtype_dict_values_fresh_exception() {
}
// Actually, unsound_string_conversion_alias_declared_prop behavior makes an
// argument that we shouldn't really care about this, since we ignore the fact
// argument that we shouldn\'t really care about this, since we ignore the fact
// that coercing values to string keys can cause unintended aliasing in general.
// Barring some compelling use case for that in this context, though, we choose
// to be strict.
@ -380,7 +380,7 @@ function subtype_optional_c_to_dict(
* maps. They can also be used to represent array-like objects, e.g., NodeList
* from the DOM API.
*
* A dictionary is assumed to have every property described by it's key type.
* A dictionary is assumed to have every property described by it\'s key type.
* This behavior is similar to the behavior of arrays, which are assumed to have
* a value at every index.
*
@ -390,7 +390,7 @@ function subtype_optional_c_to_dict(
// Just a couple of short type names. Compare to string/number.
// Any property can be set on a dict with string keys.
// **UNSOUND**
// This is allowed by design. We don't track get/set and we don't wrap the
// This is allowed by design. We don\'t track get/set and we don\'t wrap the
// return type in a maybe.
// ok
// ok
@ -398,7 +398,7 @@ function subtype_optional_c_to_dict(
// error, A ~> B
// ok
// ok
// This isn't specific behavior to dictionaries, but for completeness...
// This isn\'t specific behavior to dictionaries, but for completeness...
// ok
// ok
// error, C ~> B
@ -417,9 +417,9 @@ function subtype_optional_c_to_dict(
// error: string ~> boolean
// ok
// **UNSOUND**
// Because we support non-string props w/ bracket notation, it's possible to
// Because we support non-string props w/ bracket notation, it\'s possible to
// write into a declared prop unsoundly.
// a["0"] no longer X
// a[\"0\"] no longer X
// error
// in[0].p no longer B
// ok
@ -440,7 +440,7 @@ function subtype_optional_c_to_dict(
// error, A not <: C
// ok, C == C
// Actually, unsound_string_conversion_alias_declared_prop behavior makes an
// argument that we shouldn't really care about this, since we ignore the fact
// argument that we shouldn\'t really care about this, since we ignore the fact
// that coercing values to string keys can cause unintended aliasing in general.
// Barring some compelling use case for that in this context, though, we choose
// to be strict.
@ -504,11 +504,11 @@ class C extends B {}
class X {}
class Y {}
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 }) {
(o.p: X);
(o["p"]: X);
(o[\"p\"]: X);
}
function set_prop_covariant(o: { [k: string]: B }) {
o.p = new A();
@ -521,15 +521,15 @@ function get_prop_contravariant(o: { [k: string]: B }) {
(o.p: C);
}
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 }) {
o[[object Number]] = "ok";
o[0] = \"ok\";
}
function mix_with_declared_props(o: { [k: number]: X, p: Y }, x: X, y: Y) {
(o[[object Number]]: X);
(o[0]: X);
(o.p: Y);
o[[object Number]] = x;
o[0] = x;
o.p = y;
}
function object_prototype(o: { [k: string]: number }): {
@ -540,16 +540,16 @@ function object_prototype(o: { [k: string]: number }): {
return o;
}
function unsound_string_conversion_alias_declared_prop(
o: { [k: number]: any, "0": X }
o: { [k: number]: any, \"0\": X }
) {
o[[object Number]] = "not-x";
o[0] = \"not-x\";
}
function unification_dict_values_invariant(x: Array<{ [k: string]: B }>) {
let a: Array<{ [k: string]: A }> = x;
a[[object Number]].p = new A();
a[0].p = new A();
let b: Array<{ [k: string]: B }> = x;
let c: Array<{ [k: string]: C }> = x;
(x[[object Number]].p: C);
(x[0].p: C);
}
function subtype_dict_values_invariant(x: { [k: string]: B }) {
let a: { [k: string]: A } = x;
@ -577,10 +577,10 @@ function unification_mix_with_declared_props_invariant_l(
x: Array<{ [k: string]: B }>
) {
let a: Array<{ [k: string]: B, p: A }> = x;
a[[object Number]].p = new A();
a[0].p = new A();
let b: Array<{ [k: string]: B, p: B }> = x;
let c: Array<{ [k: string]: B, p: C }> = x;
(x[[object Number]].p: C);
(x[0].p: C);
}
function unification_mix_with_declared_props_invariant_r(
xa: Array<{ [k: string]: A, p: B }>,
@ -588,10 +588,10 @@ function unification_mix_with_declared_props_invariant_r(
xc: Array<{ [k: string]: C, p: B }>
) {
let a: Array<{ [k: string]: A }> = xa;
a[[object Number]].p = new A();
a[0].p = new A();
let b: Array<{ [k: string]: B }> = xb;
let c: Array<{ [k: string]: C }> = xc;
(xc[[object Number]].p: C);
(xc[0].p: C);
}
function subtype_mix_with_declared_props_invariant_l(x: { [k: string]: B }) {
let a: { [k: string]: B, p: A } = x;
@ -680,14 +680,14 @@ var z : {[key: number]: string} = x; // 2 errors, string !~> number & vice versa
var a : {[key: string]: ?string} = {};
var b : {[key: string]: string} = a; // 2 errors (null & undefined)
var c : {[key: string]: ?string} = b; // 2 errors, since c['x'] = null updates b
var c : {[key: string]: ?string} = b; // 2 errors, since c[\'x\'] = null updates b
// 2 errors (number !~> string, string !~> number)
function foo0(x: Array<{[key: string]: number}>): Array<{[key: string]: string}> {
return x;
}
// error, fooBar:string !~> number (x's dictionary)
// error, fooBar:string !~> number (x\'s dictionary)
function foo1(
x: Array<{[key: string]: number}>
): Array<{[key: string]: number, fooBar: string}> {
@ -697,7 +697,7 @@ function foo1(
function foo2(
x: Array<{[key: string]: mixed}>
): Array<{[key: string]: mixed, fooBar: string}> {
x[0].fooBar = 123; // OK, since number ~> mixed (x elem's dictionary)
x[0].fooBar = 123; // OK, since number ~> mixed (x elem\'s dictionary)
return x; // error: mixed ~> string
}
@ -706,7 +706,7 @@ function foo3(x: {[key: string]: number}): {foo: number} {
return x;
}
// error: foo can't exist in x
// error: foo can\'t exist in x
function foo4(x: {[key: string]: number}): {[key: string]: number, foo: string} {
return x;
}
@ -734,13 +734,13 @@ function foo8(x: {[key: string]: number}) {
// 2 errors, number !~> string & vice versa
// 2 errors, string !~> number & vice versa
// 2 errors (null & undefined)
// 2 errors, since c['x'] = null updates b
// 2 errors, since c[\'x\'] = null updates b
// 2 errors (number !~> string, string !~> number)
// error, fooBar:string !~> number (x's dictionary)
// OK, since number ~> mixed (x elem's dictionary)
// error, fooBar:string !~> number (x\'s dictionary)
// OK, since number ~> mixed (x elem\'s dictionary)
// error: mixed ~> string
// OK, since we assume dictionaries have every key
// error: foo can't exist in x
// error: foo can\'t exist in x
// error, some prop in x could be incompatible (covariance)
// error, some prop in return could be incompatible
// error
@ -765,7 +765,7 @@ function foo2(x: Array<{ [key: string]: mixed }>): Array<{
[key: string]: mixed,
fooBar: string
}> {
x[[object Number]].fooBar = [object Number];
x[0].fooBar = 123;
return x;
}
function foo3(x: { [key: string]: number }): { foo: number } {
@ -828,19 +828,19 @@ class B {
class A {
x: { [k: string]: number };
m1() {
this.x = { bar: [object Number] };
this.x = { bar: 0 };
}
m2() {
this.x.foo = [object Number];
this.x.foo = 0;
}
}
class B {
x: { [k: string]: number };
m2() {
this.x.foo = [object Number];
this.x.foo = 0;
}
m1() {
this.x = { bar: [object Number] };
this.x = { bar: 0 };
}
}
"
@ -871,14 +871,14 @@ module.exports = o;
`;
exports[`test test_client.js 1`] = `
"var o = require('./test');
"var o = require(\'./test\');
o.foo = function (params) {
return params.count; // error, number ~/~ string
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// error, number ~/~ string
var o = require("./test");
var o = require(\"./test\");
o.foo = function(params) {
return params.count;
};

File diff suppressed because it is too large Load Diff

View File

@ -9,7 +9,7 @@ let tests = [
// moveTo
function(ctx: CanvasRenderingContext2D) {
ctx.moveTo('0', '1'); // error: should be numbers
ctx.moveTo(\'0\', \'1\'); // error: should be numbers
},
];
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ -19,15 +19,10 @@ let tests = [
// error: should be numbers
let tests = [
function(ctx: CanvasRenderingContext2D) {
ctx.fillRect(
[object Number],
[object Number],
[object Number],
[object Number]
);
ctx.fillRect(0, 0, 200, 100);
},
function(ctx: CanvasRenderingContext2D) {
ctx.moveTo("0", "1");
ctx.moveTo(\"0\", \"1\");
}
];
"
@ -39,8 +34,8 @@ exports[`test CustomEvent.js 1`] = `
let tests = [
// CustomEvent
function(document: Document) {
const event = document.createEvent('CustomEvent');
event.initCustomEvent('butts', true, false, { nice: 42 });
const event = document.createEvent(\'CustomEvent\');
event.initCustomEvent(\'butts\', true, false, { nice: 42 });
}
];
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ -48,13 +43,8 @@ let tests = [
// CustomEvent
let tests = [
function(document: Document) {
const event = document.createEvent("CustomEvent");
event.initCustomEvent(
"butts",
[object Boolean],
[object Boolean],
{ nice: [object Number] }
);
const event = document.createEvent(\"CustomEvent\");
event.initCustomEvent(\"butts\", true, false, { nice: 42 });
}
];
"
@ -66,10 +56,10 @@ exports[`test Document.js 1`] = `
let tests = [
// createElement
function(document: Document) {
(document.createElement('canvas'): HTMLCanvasElement);
(document.createElement('link'): HTMLLinkElement);
(document.createElement('option'): HTMLOptionElement);
(document.createElement('select'): HTMLSelectElement);
(document.createElement(\'canvas\'): HTMLCanvasElement);
(document.createElement(\'link\'): HTMLLinkElement);
(document.createElement(\'option\'): HTMLOptionElement);
(document.createElement(\'select\'): HTMLSelectElement);
}
];
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ -77,10 +67,10 @@ let tests = [
// createElement
let tests = [
function(document: Document) {
(document.createElement("canvas"): HTMLCanvasElement);
(document.createElement("link"): HTMLLinkElement);
(document.createElement("option"): HTMLOptionElement);
(document.createElement("select"): HTMLSelectElement);
(document.createElement(\"canvas\"): HTMLCanvasElement);
(document.createElement(\"link\"): HTMLLinkElement);
(document.createElement(\"option\"): HTMLOptionElement);
(document.createElement(\"select\"): HTMLSelectElement);
}
];
"
@ -95,13 +85,13 @@ let tests = [
element.scrollIntoView();
element.scrollIntoView(false);
element.scrollIntoView({});
element.scrollIntoView({ behavior: 'smooth', block: 'end' });
element.scrollIntoView({ block: 'end' });
element.scrollIntoView({ behavior: 'smooth' });
element.scrollIntoView({ behavior: \'smooth\', block: \'end\' });
element.scrollIntoView({ block: \'end\' });
element.scrollIntoView({ behavior: \'smooth\' });
// fails
element.scrollIntoView({ behavior: 'invalid' });
element.scrollIntoView({ block: 'invalid' });
element.scrollIntoView({ behavior: \'invalid\' });
element.scrollIntoView({ block: \'invalid\' });
element.scrollIntoView(1);
}
];
@ -112,14 +102,14 @@ let tests = [
let tests = [
function(element: Element) {
element.scrollIntoView();
element.scrollIntoView([object Boolean]);
element.scrollIntoView(false);
element.scrollIntoView({});
element.scrollIntoView({ behavior: "smooth", block: "end" });
element.scrollIntoView({ block: "end" });
element.scrollIntoView({ behavior: "smooth" });
element.scrollIntoView({ behavior: "invalid" });
element.scrollIntoView({ block: "invalid" });
element.scrollIntoView([object Number]);
element.scrollIntoView({ behavior: \"smooth\", block: \"end\" });
element.scrollIntoView({ block: \"end\" });
element.scrollIntoView({ behavior: \"smooth\" });
element.scrollIntoView({ behavior: \"invalid\" });
element.scrollIntoView({ block: \"invalid\" });
element.scrollIntoView(1);
}
];
"
@ -131,7 +121,7 @@ exports[`test HTMLCanvasElement.js 1`] = `
let tests = [
// getContext
function(el: HTMLCanvasElement) {
(el.getContext('2d'): ?CanvasRenderingContext2D);
(el.getContext(\'2d\'): ?CanvasRenderingContext2D);
}
];
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ -139,7 +129,7 @@ let tests = [
// getContext
let tests = [
function(el: HTMLCanvasElement) {
(el.getContext("2d"): ?CanvasRenderingContext2D);
(el.getContext(\"2d\"): ?CanvasRenderingContext2D);
}
];
"
@ -154,13 +144,13 @@ let tests = [
element.scrollIntoView();
element.scrollIntoView(false);
element.scrollIntoView({});
element.scrollIntoView({ behavior: 'smooth', block: 'end' });
element.scrollIntoView({ block: 'end' });
element.scrollIntoView({ behavior: 'smooth' });
element.scrollIntoView({ behavior: \'smooth\', block: \'end\' });
element.scrollIntoView({ block: \'end\' });
element.scrollIntoView({ behavior: \'smooth\' });
// fails
element.scrollIntoView({ behavior: 'invalid' });
element.scrollIntoView({ block: 'invalid' });
element.scrollIntoView({ behavior: \'invalid\' });
element.scrollIntoView({ block: \'invalid\' });
element.scrollIntoView(1);
}
];
@ -171,14 +161,14 @@ let tests = [
let tests = [
function(element: HTMLElement) {
element.scrollIntoView();
element.scrollIntoView([object Boolean]);
element.scrollIntoView(false);
element.scrollIntoView({});
element.scrollIntoView({ behavior: "smooth", block: "end" });
element.scrollIntoView({ block: "end" });
element.scrollIntoView({ behavior: "smooth" });
element.scrollIntoView({ behavior: "invalid" });
element.scrollIntoView({ block: "invalid" });
element.scrollIntoView([object Number]);
element.scrollIntoView({ behavior: \"smooth\", block: \"end\" });
element.scrollIntoView({ block: \"end\" });
element.scrollIntoView({ behavior: \"smooth\" });
element.scrollIntoView({ behavior: \"invalid\" });
element.scrollIntoView({ block: \"invalid\" });
element.scrollIntoView(1);
}
];
"
@ -190,11 +180,11 @@ exports[`test HTMLInputElement.js 1`] = `
let tests = [
// setRangeText
function(el: HTMLInputElement) {
el.setRangeText('foo');
el.setRangeText('foo', 123); // end is required
el.setRangeText('foo', 123, 234);
el.setRangeText('foo', 123, 234, 'select');
el.setRangeText('foo', 123, 234, 'bogus'); // invalid value
el.setRangeText(\'foo\');
el.setRangeText(\'foo\', 123); // end is required
el.setRangeText(\'foo\', 123, 234);
el.setRangeText(\'foo\', 123, 234, \'select\');
el.setRangeText(\'foo\', 123, 234, \'bogus\'); // invalid value
}
];
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ -204,11 +194,11 @@ let tests = [
// invalid value
let tests = [
function(el: HTMLInputElement) {
el.setRangeText("foo");
el.setRangeText("foo", [object Number]);
el.setRangeText("foo", [object Number], [object Number]);
el.setRangeText("foo", [object Number], [object Number], "select");
el.setRangeText("foo", [object Number], [object Number], "bogus");
el.setRangeText(\"foo\");
el.setRangeText(\"foo\", 123);
el.setRangeText(\"foo\", 123, 234);
el.setRangeText(\"foo\", 123, 234, \"select\");
el.setRangeText(\"foo\", 123, 234, \"bogus\");
}
];
"
@ -217,9 +207,9 @@ let tests = [
exports[`test URL.js 1`] = `
"/* @flow */
const a = new URL('http://flowtype.org/'); // correct
const b = new URL('/docs', a); // correct
const c = new URL('/docs', 'http://flowtype.org/'); // correct
const a = new URL(\'http://flowtype.org/\'); // correct
const b = new URL(\'/docs\', a); // correct
const c = new URL(\'/docs\', \'http://flowtype.org/\'); // correct
const d: URLSearchParams = c.searchParams; // correct
const e: string = c.path; // not correct
@ -254,9 +244,9 @@ const r: string = c.username; // correct
// correct
// correct
// correct
const a = new URL("http://flowtype.org/");
const b = new URL("/docs", a);
const c = new URL("/docs", "http://flowtype.org/");
const a = new URL(\"http://flowtype.org/\");
const b = new URL(\"/docs\", a);
const c = new URL(\"/docs\", \"http://flowtype.org/\");
const d: URLSearchParams = c.searchParams;
const e: string = c.path;
const f: string = c.pathname;
@ -283,15 +273,15 @@ let tests = [
// attachEvent
function() {
let target = new EventTarget();
(target.attachEvent('foo', listener): void); // invalid, may be undefined
(target.attachEvent && target.attachEvent('foo', listener): void); // valid
(target.attachEvent(\'foo\', listener): void); // invalid, may be undefined
(target.attachEvent && target.attachEvent(\'foo\', listener): void); // valid
},
// detachEvent
function() {
let target = new EventTarget();
(target.detachEvent('foo', listener): void); // invalid, may be undefined
(target.detachEvent && target.detachEvent('foo', listener): void); // valid
(target.detachEvent(\'foo\', listener): void); // invalid, may be undefined
(target.detachEvent && target.detachEvent(\'foo\', listener): void); // valid
},
function() {
@ -314,13 +304,13 @@ let listener: EventListener = function(event: Event): void {
let tests = [
function() {
let target = new EventTarget();
(target.attachEvent("foo", listener): void);
(target.attachEvent && target.attachEvent("foo", listener): void);
(target.attachEvent(\"foo\", listener): void);
(target.attachEvent && target.attachEvent(\"foo\", listener): void);
},
function() {
let target = new EventTarget();
(target.detachEvent("foo", listener): void);
(target.detachEvent && target.detachEvent("foo", listener): void);
(target.detachEvent(\"foo\", listener): void);
(target.detachEvent && target.detachEvent(\"foo\", listener): void);
},
function() {
window.onmessage = (event: MessageEvent) => {
@ -340,7 +330,7 @@ let tests = [
let path = new Path2D();
(path.arcTo(0, 0, 0, 0, 10): void); // valid
(path.arcTo(0, 0, 0, 0, 10, 20, 5): void); // valid
(path.arcTo(0, 0, 0, 0, 10, '20', 5): void); // invalid
(path.arcTo(0, 0, 0, 0, 10, \'20\', 5): void); // invalid
},
];
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ -352,31 +342,9 @@ let tests = [
let tests = [
function() {
let path = new Path2D();
(path.arcTo(
[object Number],
[object Number],
[object Number],
[object Number],
[object Number]
): void);
(path.arcTo(
[object Number],
[object Number],
[object Number],
[object Number],
[object Number],
[object Number],
[object Number]
): void);
(path.arcTo(
[object Number],
[object Number],
[object Number],
[object Number],
[object Number],
"20",
[object Number]
): 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);
}
];
"
@ -388,7 +356,7 @@ exports[`test registerElement.js 1`] = `
let tests = [
// should work with Object.create()
function() {
document.registerElement('custom-element', {
document.registerElement(\'custom-element\', {
prototype: Object.create(HTMLElement.prototype, {
createdCallback: { value: function createdCallback () {
}},
@ -410,7 +378,7 @@ let tests = [
},
// or with Object.assign()
function() {
document.registerElement('custom-element', {
document.registerElement(\'custom-element\', {
prototype: Object.assign(Object.create(HTMLElement.prototype), {
createdCallback () {
},
@ -430,7 +398,7 @@ let tests = [
},
// should complain about invalid callback parameters
function() {
document.registerElement('custom-element', {
document.registerElement(\'custom-element\', {
prototype: {
attributeChangedCallback(
localName: string,
@ -451,7 +419,7 @@ let tests = [
let tests = [
function() {
document.registerElement(
"custom-element",
\"custom-element\",
{
prototype: Object.create(
HTMLElement.prototype,
@ -488,7 +456,7 @@ let tests = [
},
function() {
document.registerElement(
"custom-element",
\"custom-element\",
{
prototype: Object.assign(
Object.create(HTMLElement.prototype),
@ -515,7 +483,7 @@ let tests = [
},
function() {
document.registerElement(
"custom-element",
\"custom-element\",
{
prototype: {
attributeChangedCallback(localName: string,
@ -715,16 +683,16 @@ let tests = [
// NodeFilterInterface
function() {
document.createNodeIterator(document.body, -1, node => NodeFilter.FILTER_ACCEPT); // valid
document.createNodeIterator(document.body, -1, node => 'accept'); // invalid
document.createNodeIterator(document.body, -1, node => \'accept\'); // invalid
document.createNodeIterator(document.body, -1, { accept: node => NodeFilter.FILTER_ACCEPT }); // valid
document.createNodeIterator(document.body, -1, { accept: node => 'accept' }); // invalid
document.createNodeIterator(document.body, -1, { accept: node => \'accept\' }); // invalid
document.createNodeIterator(document.body, -1, {}); // invalid
},
function() {
document.createTreeWalker(document.body, -1, node => NodeFilter.FILTER_ACCEPT); // valid
document.createTreeWalker(document.body, -1, node => 'accept'); // invalid
document.createTreeWalker(document.body, -1, node => \'accept\'); // invalid
document.createTreeWalker(document.body, -1, { accept: node => NodeFilter.FILTER_ACCEPT }); // valid
document.createTreeWalker(document.body, -1, { accept: node => 'accept' }); // invalid
document.createTreeWalker(document.body, -1, { accept: node => \'accept\' }); // invalid
document.createTreeWalker(document.body, -1, {}); // invalid
},
];
@ -779,7 +747,7 @@ let tests = [
const nextNode: Element | null = i.nextNode();
},
function() {
const _root = document.body.attributes[[object Number]];
const _root = document.body.attributes[0];
const i = document.createNodeIterator(_root, NodeFilter.SHOW_ATTRIBUTE);
const root: typeof _root = i.root;
const referenceNode: typeof _root | Attr = i.referenceNode;
@ -843,7 +811,7 @@ let tests = [
const nextNode: Element | null = w.nextNode();
},
function() {
const _root = document.body.attributes[[object Number]];
const _root = document.body.attributes[0];
const w = document.createTreeWalker(_root, NodeFilter.SHOW_ATTRIBUTE);
const root: typeof _root = w.root;
const currentNode: typeof _root | Attr = w.currentNode;
@ -926,48 +894,36 @@ let tests = [
function() {
document.createNodeIterator(
document.body,
-[object Number],
-1,
node => NodeFilter.FILTER_ACCEPT
);
document.createNodeIterator(document.body, -1, node => \"accept\");
document.createNodeIterator(
document.body,
-[object Number],
node => "accept"
);
document.createNodeIterator(
document.body,
-[object Number],
-1,
{ accept: node => NodeFilter.FILTER_ACCEPT }
);
document.createNodeIterator(
document.body,
-[object Number],
{ accept: node => "accept" }
-1,
{ accept: node => \"accept\" }
);
document.createNodeIterator(document.body, -[object Number], {});
document.createNodeIterator(document.body, -1, {});
},
function() {
document.createTreeWalker(
document.body,
-[object Number],
-1,
node => NodeFilter.FILTER_ACCEPT
);
document.createTreeWalker(document.body, -1, node => \"accept\");
document.createTreeWalker(
document.body,
-[object Number],
node => "accept"
);
document.createTreeWalker(
document.body,
-[object Number],
-1,
{ accept: node => NodeFilter.FILTER_ACCEPT }
);
document.createTreeWalker(
document.body,
-[object Number],
{ accept: node => "accept" }
);
document.createTreeWalker(document.body, -[object Number], {});
document.createTreeWalker(document.body, -1, { accept: node => \"accept\" });
document.createTreeWalker(document.body, -1, {});
}
];
"

View File

@ -6,7 +6,7 @@ bar();
module.exports = num;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// @flow
var num = [object Number];
var num = 42;
function bar() {
}
@ -17,7 +17,7 @@ module.exports = num;
exports[`test test.js 1`] = `
"// @flow
var num = require('./import');
var num = require(\'./import\');
function foo(x) { }
foo(0);
var a:string = num;
@ -40,16 +40,16 @@ const idxResult = idx(obj, obj => obj.a.b.c.d);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// @flow
// test deduping of inferred types
var num = require("./import");
var num = require(\"./import\");
function foo(x) {
}
foo([object Number]);
foo(0);
var a: string = num;
function unannotated(x) {
return x;
}
const nullToUndefined = val => (val === [object Null] ? undefined : val);
const nullToUndefined = val => (val === null ? undefined : val);
function f0(x: ?Object) {
return nullToUndefined(x);
}

View File

@ -46,7 +46,7 @@ class C1 {
new C1().m();
class C2 {
get m() {
return [object Number];
return 42;
}
m() {
@ -64,24 +64,24 @@ class C3 {
new C3().m();
class C4 {
get m() {
return [object Number];
return 42;
}
set m(x: number) {
}
}
new C4().m = new C4().m - [object Number];
new C4().m = new C4().m - 42;
class C5 {
m() {
}
get m() {
return [object Number];
return 42;
}
set m(x: number) {
}
}
new C5().m = new C5().m - [object Number];
new C5().m = new C5().m - 42;
"
`;

View File

@ -10,7 +10,7 @@ function tag(strings,...values) {
var s2 = tag \`l\${42}r\`;
function tag2(strings,...values) {
return { foo: "" }; // ok: tagged templates can return whatever
return { foo: \"\" }; // ok: tagged templates can return whatever
}
var s3 = tag2 \`la la la\`;
@ -24,12 +24,12 @@ class A {}
var a = new A();
var s1 = \`l\${a.x}r\`;
function tag(strings, ...values) {
var x: number = strings[[object Number]];
var x: number = strings[0];
return x;
}
var s2 = tag\`l\${[object Number]}r\`;
var s2 = tag\`l\${42}r\`;
function tag2(strings, ...values) {
return { foo: "" };
return { foo: \"\" };
}
var s3 = tag2\`la la la\`;
(s3.foo: number);

View File

@ -2,11 +2,11 @@ exports[`test equals.js 1`] = `
"/* @flow */
(1 == 1);
("foo" == "bar");
(\"foo\" == \"bar\");
(1 == null);
(null == 1);
(1 == ""); // error
("" == 1); // error
(1 == \"\"); // error
(\"\" == 1); // error
var x = (null : ?number);
(x == 1);
@ -15,14 +15,14 @@ var x = (null : ?number);
/* @flow */
// error
// error
[object Number] == [object Number];
"foo" == "bar";
[object Number] == [object Null];
[object Null] == [object Number];
[object Number] == "";
"" == [object Number];
var x = ([object Null]: ?number);
x == [object Number];
[object Number] == x;
1 == 1;
\"foo\" == \"bar\";
1 == null;
null == 1;
1 == \"\";
\"\" == 1;
var x = (null: ?number);
x == 1;
1 == x;
"
`;

File diff suppressed because it is too large Load Diff

View File

@ -1,8 +1,8 @@
exports[`test es_declare_module.js 1`] = `
"// @flow
import {num1, str1} from "CJS_Named";
import CJS_Named from "CJS_Named";
import {num1, str1} from \"CJS_Named\";
import CJS_Named from \"CJS_Named\";
(num1: number);
(num1: string); // Error: number ~> string
(str1: string);
@ -10,36 +10,36 @@ import CJS_Named from "CJS_Named";
(CJS_Named: {num1: number, str1: string});
(CJS_Named: number); // Error: Module ~> number
import {num2} from "CJS_Clobbered"; // Error: No such export!
import {numExport} from "CJS_Clobbered";
import {num2} from \"CJS_Clobbered\"; // Error: No such export!
import {numExport} from \"CJS_Clobbered\";
(numExport: number);
(numExport: string); // Error: number ~> string
import type {numType} from "CJS_Clobbered";
import type {numType} from \"CJS_Clobbered\";
(42: numType);
('asdf': numType); // Error: string ~> number
(\'asdf\': numType); // Error: string ~> number
import {strHidden} from "ES"; // Error: No such export!
import {str3} from "ES";
import {strHidden} from \"ES\"; // Error: No such export!
import {str3} from \"ES\";
(str3: string);
(str3: number); // Error: string ~> number
import {num3} from "ES";
import {num3} from \"ES\";
(num3: number);
(num3: string); // Error: number ~> string
import {C} from "ES";
import type {C as CType} from "ES";
import {C} from \"ES\";
import type {C as CType} from \"ES\";
(new C(): C);
(42: C); // Error: number ~> C
(new C(): CType);
(42: CType); // Error: number ~> CType
import {T} from "ES"; // Error: T is a type import, not a value
import type {T as T2} from "ES";
import {T} from \"ES\"; // Error: T is a type import, not a value
import type {T as T2} from \"ES\";
(42: T2);
('asdf': T2); // Error: string ~> number
(\'asdf\': T2); // Error: string ~> number
import {exports as nope} from "ES"; // Error: Not an export
import {exports as nope} from \"ES\"; // Error: Not an export
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// @flow
// Error: number ~> string
@ -56,38 +56,38 @@ import {exports as nope} from "ES"; // Error: Not an export
// Error: T is a type import, not a value
// Error: string ~> number
// Error: Not an export
import { num1, str1 } from "CJS_Named";
import CJS_Named from "CJS_Named";
import { num1, str1 } from \"CJS_Named\";
import CJS_Named from \"CJS_Named\";
(num1: number);
(num1: string);
(str1: string);
(str1: number);
(CJS_Named: { num1: number, str1: string });
(CJS_Named: number);
import { num2 } from "CJS_Clobbered";
import { numExport } from "CJS_Clobbered";
import { num2 } from \"CJS_Clobbered\";
import { numExport } from \"CJS_Clobbered\";
(numExport: number);
(numExport: string);
import type { numType } from "CJS_Clobbered";
([object Number]: numType);
("asdf": numType);
import { strHidden } from "ES";
import { str3 } from "ES";
import type { numType } from \"CJS_Clobbered\";
(42: numType);
(\"asdf\": numType);
import { strHidden } from \"ES\";
import { str3 } from \"ES\";
(str3: string);
(str3: number);
import { num3 } from "ES";
import { num3 } from \"ES\";
(num3: number);
(num3: string);
import { C } from "ES";
import type { C as CType } from "ES";
import { C } from \"ES\";
import type { C as CType } from \"ES\";
(new C(): C);
([object Number]: C);
(42: C);
(new C(): CType);
([object Number]: CType);
import { T } from "ES";
import type { T as T2 } from "ES";
([object Number]: T2);
("asdf": T2);
import { exports as nope } from "ES";
(42: CType);
import { T } from \"ES\";
import type { T as T2 } from \"ES\";
(42: T2);
(\"asdf\": T2);
import { exports as nope } from \"ES\";
"
`;

View File

@ -1,7 +1,7 @@
exports[`test dest.js 1`] = `
"// @flow
import {source} from "./test";
import {source} from \"./test\";
var a: number = source.num;
var b: string = source.num; // Error: num ~> string
@ -12,7 +12,7 @@ var d: number = source.str; // Error: num ~> string
// @flow
// Error: num ~> string
// Error: num ~> string
import { source } from "./test";
import { source } from \"./test\";
var a: number = source.num;
var b: string = source.num;
var c: string = source.str;
@ -23,23 +23,23 @@ var d: number = source.str;
exports[`test source.js 1`] = `
"// @flow
export var str = 'asdf';
export var str = \'asdf\';
export var num = 42;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// @flow
export var str = "asdf";
export var num = [object Number];
export var str = \"asdf\";
export var num = 42;
"
`;
exports[`test test.js 1`] = `
"// @flow
export * as source from "./source";
export * as source from \"./source\";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// @flow
export * from "from"
export * from \"from\"
from;
"./source";
\"./source\";
"
`;

View File

@ -1,7 +1,7 @@
exports[`test dest.js 1`] = `
"// @flow
import {source} from "./test";
import {source} from \"./test\";
var a: number = source.num;
var b: string = source.num; // Error: num ~> string
@ -12,7 +12,7 @@ var d: number = source.str; // Ignored error: num ~> string
// @flow
// Error: num ~> string
// Ignored error: num ~> string
import { source } from "./test";
import { source } from \"./test\";
var a: number = source.num;
var b: string = source.num;
var c: string = source.str;
@ -23,23 +23,23 @@ var d: number = source.str;
exports[`test source.js 1`] = `
"// @flow
export var str = 'asdf';
export var str = \'asdf\';
export var num = 42;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// @flow
export var str = "asdf";
export var num = [object Number];
export var str = \"asdf\";
export var num = 42;
"
`;
exports[`test test.js 1`] = `
"// @flow
export * as source from "./source";
export * as source from \"./source\";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// @flow
export * from "from"
export * from \"from\"
from;
"./source";
\"./source\";
"
`;

View File

@ -21,30 +21,30 @@ import type {
standaloneType1,
talias1,
talias3,
} from "./types_only";
} from \"./types_only\";
var a: inlinedType1 = 42;
var b: inlinedType1 = 'asdf'; // Error: string ~> number
var b: inlinedType1 = \'asdf\'; // Error: string ~> number
var c: standaloneType1 = 42;
var d: standaloneType1 = 'asdf'; // Error: string ~> number
var d: standaloneType1 = \'asdf\'; // Error: string ~> number
var e: talias1 = 42;
var f: talias1 = 'asdf'; // Error: string ~> number
var f: talias1 = \'asdf\'; // Error: string ~> number
var g: talias3 = 42;
var h: talias3 = 'asdf'; // Error: string ~> number
var h: talias3 = \'asdf\'; // Error: string ~> number
import type {talias4} from "./cjs_with_types";
import type {talias4} from \"./cjs_with_types\";
var i: talias4 = 42;
var j: talias4 = 'asdf'; // Error: string ~> number
var j: talias4 = \'asdf\'; // Error: string ~> number
import {IFoo, IFoo2} from "./types_only";
import {IFoo, IFoo2} from \"./types_only\";
var k: IFoo = {prop: 42};
var l: IFoo = {prop: 'asdf'}; // Error: {prop:string} ~> {prop:number}
var l: IFoo = {prop: \'asdf\'}; // Error: {prop:string} ~> {prop:number}
var m: IFoo2 = {prop: 'asdf'};
var m: IFoo2 = {prop: \'asdf\'};
var n: IFoo2 = {prop: 42}; // Error: {prop:number} ~> {prop:string}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/* @flow */
@ -55,23 +55,23 @@ var n: IFoo2 = {prop: 42}; // Error: {prop:number} ~> {prop:string}
// Error: string ~> number
// Error: {prop:string} ~> {prop:number}
// Error: {prop:number} ~> {prop:string}
import type { inlinedType1, standaloneType1, talias1, talias3 } from "./types_only";
var a: inlinedType1 = [object Number];
var b: inlinedType1 = "asdf";
var c: standaloneType1 = [object Number];
var d: standaloneType1 = "asdf";
var e: talias1 = [object Number];
var f: talias1 = "asdf";
var g: talias3 = [object Number];
var h: talias3 = "asdf";
import type { talias4 } from "./cjs_with_types";
var i: talias4 = [object Number];
var j: talias4 = "asdf";
import { IFoo, IFoo2 } from "./types_only";
var k: IFoo = { prop: [object Number] };
var l: IFoo = { prop: "asdf" };
var m: IFoo2 = { prop: "asdf" };
var n: IFoo2 = { prop: [object Number] };
import type { inlinedType1, standaloneType1, talias1, talias3 } from \"./types_only\";
var a: inlinedType1 = 42;
var b: inlinedType1 = \"asdf\";
var c: standaloneType1 = 42;
var d: standaloneType1 = \"asdf\";
var e: talias1 = 42;
var f: talias1 = \"asdf\";
var g: talias3 = 42;
var h: talias3 = \"asdf\";
import type { talias4 } from \"./cjs_with_types\";
var i: talias4 = 42;
var j: talias4 = \"asdf\";
import { IFoo, IFoo2 } from \"./types_only\";
var k: IFoo = { prop: 42 };
var l: IFoo = { prop: \"asdf\" };
var m: IFoo2 = { prop: \"asdf\" };
var n: IFoo2 = { prop: 42 };
"
`;
@ -80,7 +80,7 @@ exports[`test types_only.js 1`] = `
export type inlinedType1 = number;
var a: inlinedType1 = 42;
var b: inlinedType1 = 'asdf'; // Error: string ~> number
var b: inlinedType1 = \'asdf\'; // Error: string ~> number
type standaloneType1 = number;
export type {standaloneType1};
@ -88,7 +88,7 @@ export type {standaloneType1};
type standaloneType2 = number;
export {standaloneType2}; // Error: Missing \`type\` keyword
export type {talias1, talias2 as talias3, IFoo2} from "./types_only2";
export type {talias1, talias2 as talias3, IFoo2} from \"./types_only2\";
export interface IFoo { prop: number };
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ -96,13 +96,13 @@ export interface IFoo { prop: number };
// Error: string ~> number
// Error: Missing \`type\` keyword
export type inlinedType1 = number;
var a: inlinedType1 = [object Number];
var b: inlinedType1 = "asdf";
var a: inlinedType1 = 42;
var b: inlinedType1 = \"asdf\";
type standaloneType1 = number;
export { standaloneType1 }
type standaloneType2 = number;
export { standaloneType2 }
export { talias1, talias2 as talias3, IFoo2 } from "./types_only2"
export { talias1, talias2 as talias3, IFoo2 } from \"./types_only2\"
export interface IFoo extends { prop: number }
"
`;

View File

@ -1,8 +1,8 @@
exports[`test foo.js 1`] = `
"var imp = require('./bar');
"var imp = require(\'./bar\');
imp(1337);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
var imp = require("./bar");
imp([object Number]);
var imp = require(\"./bar\");
imp(1337);
"
`;

View File

@ -2,7 +2,7 @@ exports[`test Bar.js 1`] = `
"var Bar = { x: 0 };
module.exports = Bar;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
var Bar = { x: [object Number] };
var Bar = { x: 0 };
module.exports = Bar;
"
`;
@ -22,15 +22,15 @@ let tests = [
result.baz = false;
(copyProperties(
result,
{ foo: 'a' },
{ foo: \'a\' },
{ bar: 123 }
): { foo: string, bar: number, baz: boolean });
},
// module from lib
function() {
const copyProperties = require('copyProperties');
let x = { foo: 'a' };
const copyProperties = require(\'copyProperties\');
let x = { foo: \'a\' };
let y = { bar: 123 };
(copyProperties({}, x, y): { foo: string, bar: number });
},
@ -38,7 +38,7 @@ let tests = [
// too few args
function(copyProperties: Object$Assign) {
copyProperties();
(copyProperties({ foo: 'a' }): { foo: number }); // err, num !~> string
(copyProperties({ foo: \'a\' }): { foo: number }); // err, num !~> string
},
// passed as a function
@ -62,22 +62,22 @@ let tests = [
},
function(copyProperties: Object$Assign) {
let result = {};
result.baz = [object Boolean];
(copyProperties(result, { foo: "a" }, { bar: [object Number] }): {
result.baz = false;
(copyProperties(result, { foo: \"a\" }, { bar: 123 }): {
foo: string,
bar: number,
baz: boolean
});
},
function() {
const copyProperties = require("copyProperties");
let x = { foo: "a" };
let y = { bar: [object Number] };
const copyProperties = require(\"copyProperties\");
let x = { foo: \"a\" };
let y = { bar: 123 };
(copyProperties({}, x, y): { foo: string, bar: number });
},
function(copyProperties: Object$Assign) {
copyProperties();
(copyProperties({ foo: "a" }): { foo: number });
(copyProperties({ foo: \"a\" }): { foo: number });
},
function(copyProperties: Object$Assign) {
function x(cb: Function) {
@ -95,7 +95,7 @@ exports[`test invariant.js 1`] = `
let tests = [
function() {
let x: ?string = null;
invariant(x, 'truthy only'); // error, forgot to require invariant
invariant(x, \'truthy only\'); // error, forgot to require invariant
},
function(invariant: Function) {
@ -109,11 +109,11 @@ let tests = [
// error, forgot to require invariant
let tests = [
function() {
let x: ?string = [object Null];
invariant(x, "truthy only");
let x: ?string = null;
invariant(x, \"truthy only\");
},
function(invariant: Function) {
let x: ?string = [object Null];
let x: ?string = null;
invariant(x);
(x: string);
}
@ -122,25 +122,25 @@ let tests = [
`;
exports[`test lib.js 1`] = `
"declare module "copyProperties" {
"declare module \"copyProperties\" {
declare var exports: Object$Assign;
}
declare module "mergeInto" {
declare module \"mergeInto\" {
declare var exports: $Facebookism$MergeInto;
}
declare module "mixin" {
declare module \"mixin\" {
declare var exports: $Facebookism$Mixin;
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
declare module "copyProperties" {
declare module \"copyProperties\" {
declare var exports: Object$Assign;
}
declare module "mergeInto" {
declare module \"mergeInto\" {
declare var exports: $Facebookism$MergeInto;
}
declare module "mixin" {
declare module \"mixin\" {
declare var exports: $Facebookism$Mixin;
}
"
@ -159,15 +159,15 @@ let tests = [
function(mergeInto: $Facebookism$MergeInto) {
let result = {};
result.baz = false;
(mergeInto(result, { foo: 'a' }, { bar: 123 }): void);
(mergeInto(result, { foo: \'a\' }, { bar: 123 }): void);
(result: { foo: string, bar: number, baz: boolean });
},
// module from lib
function() {
const mergeInto = require('mergeInto');
const mergeInto = require(\'mergeInto\');
let result: { foo?: string, bar?: number, baz: boolean } = { baz: false };
(mergeInto(result, { foo: 'a' }, { bar: 123 }): void);
(mergeInto(result, { foo: \'a\' }, { bar: 123 }): void);
},
// too few args
@ -195,16 +195,14 @@ let tests = [
},
function(mergeInto: $Facebookism$MergeInto) {
let result = {};
result.baz = [object Boolean];
(mergeInto(result, { foo: "a" }, { bar: [object Number] }): void);
result.baz = false;
(mergeInto(result, { foo: \"a\" }, { bar: 123 }): void);
(result: { foo: string, bar: number, baz: boolean });
},
function() {
const mergeInto = require("mergeInto");
let result: { foo?: string, bar?: number, baz: boolean } = {
baz: [object Boolean]
};
(mergeInto(result, { foo: "a" }, { bar: [object Number] }): void);
const mergeInto = require(\"mergeInto\");
let result: { foo?: string, bar?: number, baz: boolean } = { baz: false };
(mergeInto(result, { foo: \"a\" }, { bar: 123 }): void);
},
function(mergeInto: $Facebookism$MergeInto) {
mergeInto();
@ -220,22 +218,22 @@ let tests = [
`;
exports[`test test.js 1`] = `
"var Bar = require('./Bar');
var mixin = require('mixin');
"var Bar = require(\'./Bar\');
var mixin = require(\'mixin\');
class Foo extends mixin(Bar) {
m() {
var x: string = this.x;
this.y = "";
this.y = \"\";
}
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
var Bar = require("./Bar");
var mixin = require("mixin");
var Bar = require(\"./Bar\");
var mixin = require(\"mixin\");
class Foo extends mixin(Bar) {
m() {
var x: string = this.x;
this.y = "";
this.y = \"\";
}
}
"

View File

@ -4,7 +4,7 @@ exports[`test fetch.js 1`] = `
// most of the details are tested in the separate file
// here I test the basic usage
const myRequest = new Request('http://google.com');
const myRequest = new Request(\'http://google.com\');
const a: Promise<string> =
fetch(myRequest)
@ -12,18 +12,18 @@ const a: Promise<string> =
const b: Promise<string> = fetch(myRequest); // incorrect
var myInit = { method: 'GET',
var myInit = { method: \'GET\',
headers: {
'Content-Type': 'image/jpeg'
\'Content-Type\': \'image/jpeg\'
},
mode: 'cors',
cache: 'default' };
mode: \'cors\',
cache: \'default\' };
const c: Promise<Blob> =
fetch('image.png')
fetch(\'image.png\')
.then(response => response.blob()); // correct
const d: Promise<Blob> = fetch('image.png'); // incorrect
const d: Promise<Blob> = fetch(\'image.png\'); // incorrect
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/* @flow */
// most of the details are tested in the separate file
@ -31,39 +31,39 @@ const d: Promise<Blob> = fetch('image.png'); // incorrect
// incorrect
// correct
// incorrect
const myRequest = new Request("http://google.com");
const myRequest = new Request(\"http://google.com\");
const a: Promise<string> = fetch(myRequest).then(response => response.text());
const b: Promise<string> = fetch(myRequest);
var myInit = {
method: "GET",
headers: { "Content-Type": "image/jpeg" },
mode: "cors",
cache: "default"
method: \"GET\",
headers: { \"Content-Type\": \"image/jpeg\" },
mode: \"cors\",
cache: \"default\"
};
const c: Promise<Blob> = fetch("image.png").then(response => response.blob());
const d: Promise<Blob> = fetch("image.png");
const c: Promise<Blob> = fetch(\"image.png\").then(response => response.blob());
const d: Promise<Blob> = fetch(\"image.png\");
"
`;
exports[`test headers.js 1`] = `
"/* @flow */
const a = new Headers("'Content-Type': 'image/jpeg'"); // not correct
const b = new Headers(['Content-Type', 'image/jpeg']); // not correct
const c = new Headers({'Content-Type', 'image/jpeg'}); // correct
const a = new Headers(\"\'Content-Type\': \'image/jpeg\'\"); // not correct
const b = new Headers([\'Content-Type\', \'image/jpeg\']); // not correct
const c = new Headers({\'Content-Type\', \'image/jpeg\'}); // correct
const d = new Headers(c); // correct
const e: Headers = new Headers(); // correct
e.append('Content-Type', 'image/jpeg'); // correct
e.append('Content-Type'); // not correct
e.append({'Content-Type', 'image/jpeg'}); // not correct
e.set('Content-Type', 'image/jpeg'); // correct
e.set('Content-Type'); // not correct
e.set({'Content-Type', 'image/jpeg'}); // not correct
e.append(\'Content-Type\', \'image/jpeg\'); // correct
e.append(\'Content-Type\'); // not correct
e.append({\'Content-Type\', \'image/jpeg\'}); // not correct
e.set(\'Content-Type\', \'image/jpeg\'); // correct
e.set(\'Content-Type\'); // not correct
e.set({\'Content-Type\', \'image/jpeg\'}); // not correct
const f: Headers = e.append('Content-Type', 'image/jpeg'); // not correct
const f: Headers = e.append(\'Content-Type\', \'image/jpeg\'); // not correct
const g: string = e.get('Content-Type'); // correct
const h: number = e.get('Content-Type'); // not correct
const g: string = e.get(\'Content-Type\'); // correct
const h: number = e.get(\'Content-Type\'); // not correct
for (let v of e) {
const [i, j]: [string, string] = v; // correct
@ -73,7 +73,7 @@ for (let v of e.entries()) {
const [i, j]: [string, string] = v; // correct
}
e.getAll('content-type').forEach((v: string) => {}); // correct
e.getAll(\'content-type\').forEach((v: string) => {}); // correct
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/* @flow */
// not correct
@ -93,27 +93,27 @@ e.getAll('content-type').forEach((v: string) => {}); // correct
// correct
// correct
// correct
const a = new Headers("'Content-Type': 'image/jpeg'");
const b = new Headers([ "Content-Type", "image/jpeg" ]);
const c = new Headers({ "Content-Type", "image/jpeg" });
const a = new Headers(\"\'Content-Type\': \'image/jpeg\'\");
const b = new Headers([ \"Content-Type\", \"image/jpeg\" ]);
const c = new Headers({ \"Content-Type\", \"image/jpeg\" });
const d = new Headers(c);
const e: Headers = new Headers();
e.append("Content-Type", "image/jpeg");
e.append("Content-Type");
e.append({ "Content-Type", "image/jpeg" });
e.set("Content-Type", "image/jpeg");
e.set("Content-Type");
e.set({ "Content-Type", "image/jpeg" });
const f: Headers = e.append("Content-Type", "image/jpeg");
const g: string = e.get("Content-Type");
const h: number = e.get("Content-Type");
e.append(\"Content-Type\", \"image/jpeg\");
e.append(\"Content-Type\");
e.append({ \"Content-Type\", \"image/jpeg\" });
e.set(\"Content-Type\", \"image/jpeg\");
e.set(\"Content-Type\");
e.set({ \"Content-Type\", \"image/jpeg\" });
const f: Headers = e.append(\"Content-Type\", \"image/jpeg\");
const g: string = e.get(\"Content-Type\");
const h: number = e.get(\"Content-Type\");
for (let v of e) {
const [ i, j ] = v;
}
for (let v of e.entries()) {
const [ i, j ] = v;
}
e.getAll("content-type").forEach(
e.getAll(\"content-type\").forEach(
(v: string) => {
}
@ -124,47 +124,47 @@ e.getAll("content-type").forEach(
exports[`test request.js 1`] = `
"/* @flow */
const a: Request = new Request(); // incorrect
const b: Request = new Request('http://example.org'); // correct
const b: Request = new Request(\'http://example.org\'); // correct
const c: Request = new Request(b); // correct
const d: Request = new Request(c.clone()); // correct (doesn't make much sense though)
const d: Request = new Request(c.clone()); // correct (doesn\'t make much sense though)
const e: Request = new Request(b, c); // incorrect
const f: Request = new Request({}) // incorrect
const g: Request = new Request('http://example.org', {}) // correct
const g: Request = new Request(\'http://example.org\', {}) // correct
const h: Request = new Request('http://example.org', {
method: 'GET',
const h: Request = new Request(\'http://example.org\', {
method: \'GET\',
headers: {
'Content-Type': 'image/jpeg'
\'Content-Type\': \'image/jpeg\'
},
mode: 'cors',
cache: 'default'
mode: \'cors\',
cache: \'default\'
}) // correct
const i: Request = new Request('http://example.org', {
method: 'POST',
const i: Request = new Request(\'http://example.org\', {
method: \'POST\',
headers: {
'Content-Type': 'image/jpeg'
\'Content-Type\': \'image/jpeg\'
},
body: new URLSearchParams("key=value"),
mode: 'cors',
cache: 'default'
body: new URLSearchParams(\"key=value\"),
mode: \'cors\',
cache: \'default\'
}) // correct
const j: Request = new Request('http://example.org', {
method: 'GET',
headers: 'Content-Type: image/jpeg',
mode: 'cors',
cache: 'default'
const j: Request = new Request(\'http://example.org\', {
method: \'GET\',
headers: \'Content-Type: image/jpeg\',
mode: \'cors\',
cache: \'default\'
}) // incorrect - headers is string
const k: Request = new Request('http://example.org', {
method: 'CONNECT',
const k: Request = new Request(\'http://example.org\', {
method: \'CONNECT\',
headers: {
'Content-Type': 'image/jpeg'
\'Content-Type\': \'image/jpeg\'
},
mode: 'cors',
cache: 'default'
mode: \'cors\',
cache: \'default\'
}) // incorrect - CONNECT is forbidden
var l: boolean = h.bodyUsed;
@ -178,7 +178,7 @@ h.arrayBuffer().then((ab: Buffer) => ab); // incorrect
// incorrect
// correct
// correct
// correct (doesn't make much sense though)
// correct (doesn\'t make much sense though)
// incorrect
// incorrect
// correct
@ -191,47 +191,47 @@ h.arrayBuffer().then((ab: Buffer) => ab); // incorrect
// correct
// incorrect
const a: Request = new Request();
const b: Request = new Request("http://example.org");
const b: Request = new Request(\"http://example.org\");
const c: Request = new Request(b);
const d: Request = new Request(c.clone());
const e: Request = new Request(b, c);
const f: Request = new Request({});
const g: Request = new Request("http://example.org", {});
const g: Request = new Request(\"http://example.org\", {});
const h: Request = new Request(
"http://example.org",
\"http://example.org\",
{
method: "GET",
headers: { "Content-Type": "image/jpeg" },
mode: "cors",
cache: "default"
method: \"GET\",
headers: { \"Content-Type\": \"image/jpeg\" },
mode: \"cors\",
cache: \"default\"
}
);
const i: Request = new Request(
"http://example.org",
\"http://example.org\",
{
method: "POST",
headers: { "Content-Type": "image/jpeg" },
body: new URLSearchParams("key=value"),
mode: "cors",
cache: "default"
method: \"POST\",
headers: { \"Content-Type\": \"image/jpeg\" },
body: new URLSearchParams(\"key=value\"),
mode: \"cors\",
cache: \"default\"
}
);
const j: Request = new Request(
"http://example.org",
\"http://example.org\",
{
method: "GET",
headers: "Content-Type: image/jpeg",
mode: "cors",
cache: "default"
method: \"GET\",
headers: \"Content-Type: image/jpeg\",
mode: \"cors\",
cache: \"default\"
}
);
const k: Request = new Request(
"http://example.org",
\"http://example.org\",
{
method: "CONNECT",
headers: { "Content-Type": "image/jpeg" },
mode: "cors",
cache: "default"
method: \"CONNECT\",
headers: { \"Content-Type\": \"image/jpeg\" },
mode: \"cors\",
cache: \"default\"
}
);
var l: boolean = h.bodyUsed;
@ -252,33 +252,33 @@ const d: Response = new Response(new FormData(), {
status: 404
}); // correct
const e: Response = new Response("responsebody", {
status: "404"
const e: Response = new Response(\"responsebody\", {
status: \"404\"
}); // incorrect
const f: Response = new Response("responsebody", {
const f: Response = new Response(\"responsebody\", {
status: 404,
headers: "'Content-Type': 'image/jpeg'"
headers: \"\'Content-Type\': \'image/jpeg\'\"
}); // incorrect
const g: Response = new Response("responsebody", {
const g: Response = new Response(\"responsebody\", {
status: 404,
headers: {
'Content-Type': 'image/jpeg'
\'Content-Type\': \'image/jpeg\'
}
}); // correct
const h: Response = new Response("responsebody", {
const h: Response = new Response(\"responsebody\", {
status: 404,
headers: new Headers({
'Content-Type': 'image/jpeg'
\'Content-Type\': \'image/jpeg\'
})
}); // correct, if verbose
const i: Response = new Response({
status: 404,
headers: new Headers({
'Content-Type': 'image/jpeg'
\'Content-Type\': \'image/jpeg\'
})
}); // incorrect
@ -307,26 +307,23 @@ h.arrayBuffer().then((ab: Buffer) => ab); // incorrect
const a: Response = new Response();
const b: Response = new Response(new Blob());
const c: Response = new Response(new FormData());
const d: Response = new Response(new FormData(), { status: [object Number] });
const e: Response = new Response("responsebody", { status: "404" });
const d: Response = new Response(new FormData(), { status: 404 });
const e: Response = new Response(\"responsebody\", { status: \"404\" });
const f: Response = new Response(
"responsebody",
{ status: [object Number], headers: "'Content-Type': 'image/jpeg'" }
\"responsebody\",
{ status: 404, headers: \"\'Content-Type\': \'image/jpeg\'\" }
);
const g: Response = new Response(
"responsebody",
{ status: [object Number], headers: { "Content-Type": "image/jpeg" } }
\"responsebody\",
{ status: 404, headers: { \"Content-Type\": \"image/jpeg\" } }
);
const h: Response = new Response(
"responsebody",
{
status: [object Number],
headers: new Headers({ "Content-Type": "image/jpeg" })
}
\"responsebody\",
{ status: 404, headers: new Headers({ \"Content-Type\": \"image/jpeg\" }) }
);
const i: Response = new Response({
status: [object Number],
headers: new Headers({ "Content-Type": "image/jpeg" })
status: 404,
headers: new Headers({ \"Content-Type\": \"image/jpeg\" })
});
const ok: boolean = h.ok;
const status: number = h.status;
@ -340,22 +337,22 @@ h.arrayBuffer().then((ab: Buffer) => ab);
exports[`test urlsearchparams.js 1`] = `
"/* @flow */
const a = new URLSearchParams("key1=value1"); // correct
const b = new URLSearchParams(['key1', 'value1']); // not correct
const c = new URLSearchParams({'key1', 'value1'}); // not correct
const a = new URLSearchParams(\"key1=value1\"); // correct
const b = new URLSearchParams([\'key1\', \'value1\']); // not correct
const c = new URLSearchParams({\'key1\', \'value1\'}); // not correct
const d = new URLSearchParams(c); // correct
const e: URLSearchParams = new URLSearchParams(); // correct
e.append('key1', 'value1'); // correct
e.append('key1'); // not correct
e.append({'key1', 'value1'}); // not correct
e.set('key1', 'value1'); // correct
e.set('key1'); // not correct
e.set({'key1', 'value1'}); // not correct
e.append(\'key1\', \'value1\'); // correct
e.append(\'key1\'); // not correct
e.append({\'key1\', \'value1\'}); // not correct
e.set(\'key1\', \'value1\'); // correct
e.set(\'key1\'); // not correct
e.set({\'key1\', \'value1\'}); // not correct
const f: URLSearchParams = e.append('key1', 'value1'); // not correct
const f: URLSearchParams = e.append(\'key1\', \'value1\'); // not correct
const g: string = e.get('key1'); // correct
const h: number = e.get('key1'); // not correct
const g: string = e.get(\'key1\'); // correct
const h: number = e.get(\'key1\'); // not correct
for (let v of e) {
const [i, j]: [string, string] = v; // correct
@ -365,7 +362,7 @@ for (let v of e.entries()) {
const [i, j]: [string, string] = v; // correct
}
e.getAll('key1').forEach((v: string) => {}); // correct
e.getAll(\'key1\').forEach((v: string) => {}); // correct
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/* @flow */
// correct
@ -385,27 +382,27 @@ e.getAll('key1').forEach((v: string) => {}); // correct
// correct
// correct
// correct
const a = new URLSearchParams("key1=value1");
const b = new URLSearchParams([ "key1", "value1" ]);
const c = new URLSearchParams({ "key1", "value1" });
const a = new URLSearchParams(\"key1=value1\");
const b = new URLSearchParams([ \"key1\", \"value1\" ]);
const c = new URLSearchParams({ \"key1\", \"value1\" });
const d = new URLSearchParams(c);
const e: URLSearchParams = new URLSearchParams();
e.append("key1", "value1");
e.append("key1");
e.append({ "key1", "value1" });
e.set("key1", "value1");
e.set("key1");
e.set({ "key1", "value1" });
const f: URLSearchParams = e.append("key1", "value1");
const g: string = e.get("key1");
const h: number = e.get("key1");
e.append(\"key1\", \"value1\");
e.append(\"key1\");
e.append({ \"key1\", \"value1\" });
e.set(\"key1\", \"value1\");
e.set(\"key1\");
e.set({ \"key1\", \"value1\" });
const f: URLSearchParams = e.append(\"key1\", \"value1\");
const g: string = e.get(\"key1\");
const h: number = e.get(\"key1\");
for (let v of e) {
const [ i, j ] = v;
}
for (let v of e.entries()) {
const [ i, j ] = v;
}
e.getAll("key1").forEach(
e.getAll(\"key1\").forEach(
(v: string) => {
}

View File

@ -1,18 +1,18 @@
exports[`test req.js 1`] = `
"module.exports = 0;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
module.exports = [object Number];
module.exports = 0;
"
`;
exports[`test test.js 1`] = `
"var x = require('./req');
"var x = require(\'./req\');
(x: string);
import x from './req';
import x from \'./req\';
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
var x = require("./req");
var x = require(\"./req\");
(x: string);
import x from "./req";
import x from \"./req\";
"
`;

View File

@ -26,7 +26,7 @@ type S = T;
((_: T) => {});
// Refinements
let nullable: ?string = "";
let nullable: ?string = \"\";
if (nullable != null) {
console.log(nullable.length);
nullable = null;
@ -44,15 +44,15 @@ wut1 = wut2;
wut2;
// JSX
var React = require('react');
var React = require(\'react\');
class Fancy extends React.Component {
props: { x: number };
}
<Fancy x=0/>;
// Imports
import { wut3 } from 'wutland';
import type { wut4 } from 'wutland';
import { wut3 } from \'wutland\';
import type { wut4 } from \'wutland\';
(wut3: wut4);
// Qualified types
@ -73,7 +73,7 @@ var foo = function() {
};
foo();
foo = [object Null];
foo = null;
foo();
function bar() {
function bar() {
@ -90,26 +90,26 @@ type S = T;
(_: T) => {
};
let nullable: ?string = "";
if (nullable != [object Null]) {
let nullable: ?string = \"\";
if (nullable != null) {
console.log(nullable.length);
nullable = [object Null];
nullable = null;
}
(nullable: null);
let { x, y } = { x: [object Number], y: [object Number] };
let { x, y } = { x: 0, y: 0 };
let { x: _x, y: _y } = { x, y };
({ x: _x, y: _y });
wut1;
wut1 = wut2;
wut2;
var React = require("react");
var React = require(\"react\");
class Fancy extends React.Component {
props: { x: number };
}
<Fancy x="" 0/>;
import { wut3 } from "wutland";
import type { wut4 } from "wutland";
<Fancy x=\"\" 0/>;
import { wut3 } from \"wutland\";
import type { wut4 } from \"wutland\";
(wut3: wut4);
([object Null]: React.Component);
(null: React.Component);
"
`;

View File

@ -26,19 +26,19 @@ function mk_factorial() {
var factorial = mk_factorial();
factorial("...");
factorial(\"...\");
module.exports = {fn: fix};
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/* @providesModule Fun */
function eq(x: number, y: number) {
return [object Boolean];
return true;
}
function sub(x: number, y: number) {
return [object Number];
return 0;
}
function mul(x: number, y: number) {
return [object Number];
return 0;
}
function fix(fold) {
var delta = function(delta) {
@ -55,16 +55,16 @@ function mk_factorial() {
return fix(
function(factorial) {
return function(n) {
if (eq(n, [object Number])) {
return [object Number];
if (eq(n, 1)) {
return 1;
}
return mul(factorial(sub(n, [object Number])), n);
return mul(factorial(sub(n, 1)), n);
};
}
);
}
var factorial = mk_factorial();
factorial("...");
factorial(\"...\");
module.exports = { fn: fix };
"
`;

View File

@ -9,7 +9,7 @@ function foo(x: boolean) {
}
return;
}
console.log('this is still reachable');
console.log(\'this is still reachable\');
}
function bar(x: boolean) {
@ -17,7 +17,7 @@ function bar(x: boolean) {
for (var ii = 0; ii < max; ii++) {
return;
}
console.log('this is still reachable');
console.log(\'this is still reachable\');
}
function baz(x: boolean) {
@ -25,7 +25,7 @@ function baz(x: boolean) {
for (var ii = 0; ii < max; ii++) {
continue;
}
console.log('this is still reachable');
console.log(\'this is still reachable\');
}
function bliffl(x: boolean) {
@ -34,9 +34,9 @@ function bliffl(x: boolean) {
loop2: for (var jj = 0; jj < max; jj++) {
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) {
@ -44,52 +44,52 @@ function corge(x: boolean) {
for (var ii = 0; ii < max; ii++) {
break;
}
console.log('this is still reachable');
console.log(\'this is still reachable\');
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/* @flow */
function foo(x: boolean) {
var max = [object Number];
for (var ii = [object Number]; ii < max; ii++) {
var max = 10;
for (var ii = 0; ii < max; ii++) {
if (x) {
continue;
}
return;
}
console.log("this is still reachable");
console.log(\"this is still reachable\");
}
function bar(x: boolean) {
var max = [object Number];
for (var ii = [object Number]; ii < max; ii++) {
var max = 0;
for (var ii = 0; ii < max; ii++) {
return;
}
console.log("this is still reachable");
console.log(\"this is still reachable\");
}
function baz(x: boolean) {
var max = [object Number];
for (var ii = [object Number]; ii < max; ii++) {
var max = 0;
for (var ii = 0; ii < max; ii++) {
continue;
}
console.log("this is still reachable");
console.log(\"this is still reachable\");
}
function bliffl(x: boolean) {
var max = [object Number];
var max = 10;
loop1:
for (var ii = [object Number]; ii < max; ii++) {
for (var ii = 0; ii < max; ii++) {
loop2:
for (var jj = [object Number]; jj < max; jj++) {
for (var jj = 0; jj < max; jj++) {
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) {
var max = [object Number];
for (var ii = [object Number]; ii < max; ii++) {
var max = 0;
for (var ii = 0; ii < max; ii++) {
break;
}
console.log("this is still reachable");
console.log(\"this is still reachable\");
}
"
`;
@ -103,21 +103,21 @@ exports[`test abnormal_for_in.js 1`] = `
}
return;
}
console.log('this is still reachable');
console.log(\'this is still reachable\');
}
function bar(x: boolean) {
for (var prop in {}) {
return;
}
console.log('this is still reachable');
console.log(\'this is still reachable\');
}
function baz(x: boolean) {
for (var prop in {}) {
continue;
}
console.log('this is still reachable');
console.log(\'this is still reachable\');
}
function bliffl(x: boolean) {
@ -126,57 +126,57 @@ function bliffl(x: boolean) {
loop2: for (var prop2 in obj) {
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) {
for (var prop in {}) {
break;
}
console.log('this is still reachable');
console.log(\'this is still reachable\');
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function foo(x: boolean) {
var obj = { a: [object Number], b: [object Number] };
var obj = { a: 1, b: 2 };
for (var prop in obj) {
if (x) {
continue;
}
return;
}
console.log("this is still reachable");
console.log(\"this is still reachable\");
}
function bar(x: boolean) {
for (var prop in {}) {
return;
}
console.log("this is still reachable");
console.log(\"this is still reachable\");
}
function baz(x: boolean) {
for (var prop in {}) {
continue;
}
console.log("this is still reachable");
console.log(\"this is still reachable\");
}
function bliffl(x: boolean) {
var obj = { a: [object Number], b: [object Number] };
var obj = { a: 1, b: 2 };
loop1:
for (var prop1 in obj) {
loop2:
for (var prop2 in obj) {
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) {
for (var prop in {}) {
break;
}
console.log("this is still reachable");
console.log(\"this is still reachable\");
}
"
`;
@ -190,21 +190,21 @@ exports[`test abnormal_for_of.js 1`] = `
}
return;
}
console.log('this is still reachable');
console.log(\'this is still reachable\');
}
function bar(x: boolean) {
for (var elem of []) {
return;
}
console.log('this is still reachable');
console.log(\'this is still reachable\');
}
function baz(x: boolean) {
for (var elem of []) {
continue;
}
console.log('this is still reachable');
console.log(\'this is still reachable\');
}
function bliffl(x: boolean) {
@ -213,57 +213,57 @@ function bliffl(x: boolean) {
loop2: for (var elem of arr) {
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) {
for (var elem of []) {
break;
}
console.log('this is still reachable');
console.log(\'this is still reachable\');
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function foo(x: boolean) {
var arr = [ [object Number], [object Number], [object Number] ];
var arr = [ 1, 2, 3 ];
for (var elem of arr) {
if (x) {
continue;
}
return;
}
console.log("this is still reachable");
console.log(\"this is still reachable\");
}
function bar(x: boolean) {
for (var elem of [ ]) {
return;
}
console.log("this is still reachable");
console.log(\"this is still reachable\");
}
function baz(x: boolean) {
for (var elem of [ ]) {
continue;
}
console.log("this is still reachable");
console.log(\"this is still reachable\");
}
function bliffl(x: boolean) {
var arr = [ [object Number], [object Number], [object Number] ];
var arr = [ 1, 2, 3 ];
loop1:
for (var elem of arr) {
loop2:
for (var elem of arr) {
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) {
for (var elem of [ ]) {
break;
}
console.log("this is still reachable");
console.log(\"this is still reachable\");
}
"
`;

View File

@ -86,13 +86,13 @@ function testString(str: string): void {
}
function testMap1(map: Map<string, number>): void {
for (var elem of map) {
(elem: []);
(elem: [stringnumber]);
(elem: number);
}
}
function testMap2(map: Map<*, *>): void {
for (var elem of map) {
(elem: []);
(elem: [numberstring]);
(elem: number);
}
}

View File

@ -1,36 +1,36 @@
exports[`test apply.js 1`] = `
"function test(a: string, b: number): number {
return this.length; // expect []/"" this
return this.length; // expect []/\"\" this
}
// tuples flow correctly into params
test.apply("", ["", 0]);
test.apply(\"\", [\"\", 0]);
// wrong this is an error
test.apply(0, ["", 0]); // error: lookup \`length\` on Number
test.apply(0, [\"\", 0]); // error: lookup \`length\` on Number
// not enough arguments is an error (via incompatible RestT)
test.apply("", [""]); // error: string ~> number
test.apply(\"\", [\"\"]); // error: string ~> number
// mistyped arguments is an error
test.apply("", ["", ""]); // error: string ~> number (2nd arg)
test.apply("", [0, 0]); // error: number ~> string (1st arg)
test.apply(\"\", [\"\", \"\"]); // error: string ~> number (2nd arg)
test.apply(\"\", [0, 0]); // error: number ~> string (1st arg)
// resolve args array from tvar
function f(args) { test.apply("", args) }
f(["", 0]); // OK
f(["", ""]); // error: string ~> number (2nd arg)
function f(args) { test.apply(\"\", args) }
f([\"\", 0]); // OK
f([\"\", \"\"]); // error: string ~> number (2nd arg)
f([0, 0]); // error: number ~> string (1st arg)
// expect array
test.apply("", "not array"); // error: expect array of args
test.apply(\"\", \"not array\"); // error: expect array of args
// expect 4 errors:
// - lookup length on Number (because 0 is used as \`this\`)
// - 123 is not a string
// - 'foo' is not a number
// - \'foo\' is not a number
// - return type (number) is not void
(test.call.apply(test, [0, 123, 'foo']): void);
(test.call.apply(test, [0, 123, \'foo\']): void);
// expect 2 errors:
// - lookup length on number (0 is used as \`this\`)
@ -40,9 +40,9 @@ test.apply("", "not array"); // error: expect array of args
// args are optional
function test2(): number { return 0; }
(test2.apply(): number);
(test2.apply(""): number);
(test2.apply(\"\"): number);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// expect []/"" this
// expect []/\"\" this
// tuples flow correctly into params
// wrong this is an error
// error: lookup \`length\` on Number
@ -60,7 +60,7 @@ function test2(): number { return 0; }
// expect 4 errors:
// - lookup length on Number (because 0 is used as \`this\`)
// - 123 is not a string
// - 'foo' is not a number
// - \'foo\' is not a number
// - return type (number) is not void
// expect 2 errors:
// - lookup length on number (0 is used as \`this\`)
@ -69,28 +69,25 @@ function test2(): number { return 0; }
function test(a: string, b: number): number {
return this.length;
}
test.apply("", [ "", [object Number] ]);
test.apply([object Number], [ "", [object Number] ]);
test.apply("", [ "" ]);
test.apply("", [ "", "" ]);
test.apply("", [ [object Number], [object Number] ]);
test.apply(\"\", [ \"\", 0 ]);
test.apply(0, [ \"\", 0 ]);
test.apply(\"\", [ \"\" ]);
test.apply(\"\", [ \"\", \"\" ]);
test.apply(\"\", [ 0, 0 ]);
function f(args) {
test.apply("", args);
test.apply(\"\", args);
}
f([ "", [object Number] ]);
f([ "", "" ]);
f([ [object Number], [object Number] ]);
test.apply("", "not array");
(test.call.apply(test, [ [object Number], [object Number], "foo" ]): void);
(test.bind.apply(
test,
[ [object Number], [object Number] ]
): (b: number) => number);
f([ \"\", 0 ]);
f([ \"\", \"\" ]);
f([ 0, 0 ]);
test.apply(\"\", \"not array\");
(test.call.apply(test, [ 0, 123, \"foo\" ]): void);
(test.bind.apply(test, [ 0, 123 ]): (b: number) => number);
function test2(): number {
return [object Number];
return 0;
}
(test2.apply(): number);
(test2.apply(""): number);
(test2.apply(\"\"): number);
"
`;
@ -99,8 +96,8 @@ exports[`test bind.js 1`] = `
let tests = [
function(x: (a: string, b: string) => void) {
let y = x.bind(x, 'foo');
y('bar'); // ok
let y = x.bind(x, \'foo\');
y(\'bar\'); // ok
y(123); // error, number !~> string
},
];
@ -110,9 +107,9 @@ let tests = [
// error, number !~> string
let tests = [
function(x: (a: string, b: string) => void) {
let y = x.bind(x, "foo");
y("bar");
y([object Number]);
let y = x.bind(x, \"foo\");
y(\"bar\");
y(123);
}
];
"
@ -122,41 +119,41 @@ exports[`test call.js 1`] = `
"// @flow
function test(a: string, b: number): number {
return this.length; // expect []/"" this
return this.length; // expect []/\"\" this
}
// args flow correctly into params
test.call("", "", 0);
test.call(\"\", \"\", 0);
// wrong this is an error
test.call(0, "", 0); // error: lookup \`length\` on Number
test.call(0, \"\", 0); // error: lookup \`length\` on Number
// not enough arguments is an error (via incompatible RestT)
test.call("", ""); // error: string ~> number
test.call(\"\", \"\"); // error: string ~> number
// mistyped arguments is an error
test.call("", "", ""); // error: string ~> number (2nd arg)
test.call("", 0, 0); // error: number ~> string (1st arg)
test.call(\"\", \"\", \"\"); // error: string ~> number (2nd arg)
test.call(\"\", 0, 0); // error: number ~> string (1st arg)
// resolve args array from tvar
function f(args) { test.call("", args[0], args[1]) }
f(["", 0]); // OK
f(["", ""]); // error: string ~> number (2nd arg)
function f(args) { test.call(\"\", args[0], args[1]) }
f([\"\", 0]); // OK
f([\"\", \"\"]); // error: string ~> number (2nd arg)
f([0, 0]); // error: number ~> string (1st arg)
// expect 3 errors:
// - lookup length on Number (0 used as \`this\`)
// - number !~> string (param a)
// - string !~> number (param b)
(test.apply.call(test, 0, [0, 'foo']): number);
(test.apply.call(test, 0, [0, \'foo\']): number);
// args are optional
function test2(): number { return 0; }
(test2.call(): number);
(test2.call(""): number);
(test2.call(\"\"): number);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// @flow
// expect []/"" this
// expect []/\"\" this
// args flow correctly into params
// wrong this is an error
// error: lookup \`length\` on Number
@ -177,23 +174,23 @@ function test2(): number { return 0; }
function test(a: string, b: number): number {
return this.length;
}
test.call("", "", [object Number]);
test.call([object Number], "", [object Number]);
test.call("", "");
test.call("", "", "");
test.call("", [object Number], [object Number]);
test.call(\"\", \"\", 0);
test.call(0, \"\", 0);
test.call(\"\", \"\");
test.call(\"\", \"\", \"\");
test.call(\"\", 0, 0);
function f(args) {
test.call("", args[[object Number]], args[[object Number]]);
test.call(\"\", args[0], args[1]);
}
f([ "", [object Number] ]);
f([ "", "" ]);
f([ [object Number], [object Number] ]);
(test.apply.call(test, [object Number], [ [object Number], "foo" ]): number);
f([ \"\", 0 ]);
f([ \"\", \"\" ]);
f([ 0, 0 ]);
(test.apply.call(test, 0, [ 0, \"foo\" ]): number);
function test2(): number {
return [object Number];
return 0;
}
(test2.call(): number);
(test2.call(""): number);
(test2.call(\"\"): number);
"
`;
@ -203,7 +200,7 @@ exports[`test function.js 1`] = `
*/
// Previously we represented Function as (...rest: any) => any
// This means the following wouldn't pass, because that arrow function
// This means the following wouldn\'t pass, because that arrow function
// can only be called with 3 arguments.
var a: Function = (a, b, c) => 123;
@ -216,13 +213,13 @@ var c: Function = C;
function good(x: Function, MyThing: Function): number {
var o: Object = x; // Function is an Object
x.foo = 123;
x['foo'] = 456;
x[\'foo\'] = 456;
x();
<MyThing />;
var {...something} = x;
Object.assign(x, {hi: 'there'});
Object.assign(x, {hi: \'there\'});
Object.keys(x);
return x.bar + x['bar'] + x.lala();
return x.bar + x[\'bar\'] + x.lala();
}
function bad(x: Function, y: Object): void {
@ -234,24 +231,24 @@ function bad(x: Function, y: Object): void {
let tests = [
function(y: () => void, z: Function) {
function x() {}
(x.length: void); // error, it's a number
(y.length: void); // error, it's a number
(z.length: void); // error, it's a number
(x.length: void); // error, it\'s a number
(y.length: void); // error, it\'s a number
(z.length: void); // error, it\'s a number
(x.name: void); // error, it's a string
(y.name: void); // error, it's a string
(z.name: void); // error, it's a string
(x.name: void); // error, it\'s a string
(y.name: void); // error, it\'s a string
(z.name: void); // error, it\'s a string
},
function(y: () => void, z: Function) {
function x() {}
x.length = 'foo'; // error, it's a number
y.length = 'foo'; // error, it's a number
z.length = 'foo'; // error, it's a number
x.length = \'foo\'; // error, it\'s a number
y.length = \'foo\'; // error, it\'s a number
z.length = \'foo\'; // error, it\'s a number
x.name = 123; // error, it's a string
y.name = 123; // error, it's a string
z.name = 123; // error, it's a string
x.name = 123; // error, it\'s a string
y.name = 123; // error, it\'s a string
z.name = 123; // error, it\'s a string
// Non-(Function.prototype) properties on a \`Function\` type should be \`any\`
(z.foo: number);
@ -269,27 +266,27 @@ var e = (d.bind(1): Function)();
* @flow
*/
// Previously we represented Function as (...rest: any) => any
// This means the following wouldn't pass, because that arrow function
// This means the following wouldn\'t pass, because that arrow function
// can only be called with 3 arguments.
// Function is an Object
// Error
// Error
// Object is not a Function
// error, it's a number
// error, it's a number
// error, it's a number
// error, it's a string
// error, it's a string
// error, it's a string
// error, it's a number
// error, it's a number
// error, it's a number
// error, it's a string
// error, it's a string
// error, it's a string
// error, it\'s a number
// error, it\'s a number
// error, it\'s a number
// error, it\'s a string
// error, it\'s a string
// error, it\'s a string
// error, it\'s a number
// error, it\'s a number
// error, it\'s a number
// error, it\'s a string
// error, it\'s a string
// error, it\'s a string
// Non-(Function.prototype) properties on a \`Function\` type should be \`any\`
// \`Function\` types can be bound (resulting in a \`Function\` type)
var a: Function = (a, b, c) => [object Number];
var a: Function = (a, b, c) => 123;
var b: Function = function(a: number, b: number): number {
return a + b;
};
@ -297,14 +294,14 @@ class C {}
var c: Function = C;
function good(x: Function, MyThing: Function): number {
var o: Object = x;
x.foo = [object Number];
x["foo"] = [object Number];
x.foo = 123;
x[\"foo\"] = 456;
x();
<MyThing/>;
var { ...something } = x;
Object.assign(x, { hi: "there" });
Object.assign(x, { hi: \"there\" });
Object.keys(x);
return x.bar + x["bar"] + x.lala();
return x.bar + x[\"bar\"] + x.lala();
}
function bad(x: Function, y: Object): void {
var a: number = x;
@ -327,18 +324,18 @@ let tests = [
function x() {
}
x.length = "foo";
y.length = "foo";
z.length = "foo";
x.name = [object Number];
y.name = [object Number];
z.name = [object Number];
x.length = \"foo\";
y.length = \"foo\";
z.length = \"foo\";
x.name = 123;
y.name = 123;
z.name = 123;
(z.foo: number);
(z.foo: string);
}
];
var d: Function = () => [object Number];
var e = (d.bind([object Number]): Function)();
var d: Function = () => 1;
var e = (d.bind(1): Function)();
(e: number);
(e: string);
"
@ -351,7 +348,7 @@ function rest_array<T>(...xs: Array<T>): T {
return xs[0];
}
// Warn, singleton tuple types don't represent rest params
// Warn, singleton tuple types don\'t represent rest params
function rest_tuple<T>(...xs: [T]): T {
return xs[0];
}
@ -360,25 +357,25 @@ function rest_any(...xs: any): any {
return xs[0];
}
// Warn, arbitrary subtypes of an array type don't represent rest params
// Warn, arbitrary subtypes of an array type don\'t represent rest params
function rest_t<U, T: Array<U>>(...xs: T): U {
return xs[0];
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/* regression tests */
// Warn, singleton tuple types don't represent rest params
// Warn, arbitrary subtypes of an array type don't represent rest params
// Warn, singleton tuple types don\'t represent rest params
// Warn, arbitrary subtypes of an array type don\'t represent rest params
function rest_array<T>(...xs: Array<T>): T {
return xs[[object Number]];
return xs[0];
}
function rest_tuple<T>(...xs: []): T {
return xs[[object Number]];
function rest_tuple<T>(...xs: [T]): T {
return xs[0];
}
function rest_any(...xs: any): any {
return xs[[object Number]];
return xs[0];
}
function rest_t<U, T: Array<U>>(...xs: T): U {
return xs[[object Number]];
return xs[0];
}
"
`;

View File

@ -2,7 +2,7 @@ exports[`test class.js 1`] = `
"class GeneratorExamples {
*stmt_yield(): Generator<number, void, void> {
yield 0; // ok
yield ""; // error: string ~> number
yield \"\"; // error: string ~> number
}
*stmt_next(): Generator<void, void, number> {
@ -22,18 +22,18 @@ exports[`test class.js 1`] = `
}
*stmt_return_err(): Generator<void, number, void> {
return ""; // error: string ~> number
return \"\"; // error: string ~> number
}
*infer_stmt() {
var x: boolean = yield 0; // error: number ~> boolean
return "";
return \"\";
}
*widen_next() {
var x = yield 0;
if (typeof x === "number") {
} else if (typeof x === "boolean") {
if (typeof x === \"number\") {
} else if (typeof x === \"boolean\") {
} else {
(x : string) // ok, sherlock
}
@ -41,7 +41,7 @@ exports[`test class.js 1`] = `
*widen_yield() {
yield 0;
yield "";
yield \"\";
yield true;
}
@ -54,7 +54,7 @@ exports[`test class.js 1`] = `
*delegate_yield_generator() {
function *inner() {
yield "";
yield \"\";
}
yield *inner();
@ -62,7 +62,7 @@ exports[`test class.js 1`] = `
*delegate_return_generator() {
function *inner() {
return "";
return \"\";
}
var x: number = yield *inner(); // error: string ~> number
@ -99,31 +99,31 @@ var examples = new GeneratorExamples();
for (var x of examples.infer_stmt()) { (x : string) } // error: number ~> string
var infer_stmt_next = examples.infer_stmt().next(0).value; // error: number ~> boolean
if (typeof infer_stmt_next === "undefined") {
} else if (typeof infer_stmt_next === "number") {
if (typeof infer_stmt_next === \"undefined\") {
} else if (typeof infer_stmt_next === \"number\") {
} else {
(infer_stmt_next : boolean) // error: string ~> boolean
}
examples.widen_next().next(0)
examples.widen_next().next("")
examples.widen_next().next(\"\")
examples.widen_next().next(true)
for (var x of examples.widen_yield()) {
if (typeof x === "number") {
} else if (typeof x === "boolean") {
if (typeof x === \"number\") {
} else if (typeof x === \"boolean\") {
} else {
(x : string) // ok, sherlock
}
}
examples.delegate_next_generator().next("");
examples.delegate_next_generator().next(\"\");
for (var x of examples.delegate_yield_generator()) {
(x : number) // error: string ~> number
}
examples.delegate_next_iterable([]).next(""); // error: Iterator has no next value
examples.delegate_next_iterable([]).next(\"\"); // error: Iterator has no next value
for (var x of examples.delegate_yield_iterable([])) {
(x : string) // error: number ~> string
@ -150,8 +150,8 @@ for (var x of examples.delegate_yield_iterable([])) {
// error: number ~> string
class GeneratorExamples {
*stmt_yield(): Generator<number, void, void> {
yield [object Number];
yield "";
yield 0;
yield \"\";
}
*stmt_next(): Generator<void, void, number> {
var a = yield;
@ -164,30 +164,30 @@ class GeneratorExamples {
}
}
*stmt_return_ok(): Generator<void, number, void> {
return [object Number];
return 0;
}
*stmt_return_err(): Generator<void, number, void> {
return "";
return \"\";
}
*infer_stmt() {
var x: boolean = yield [object Number];
return "";
var x: boolean = yield 0;
return \"\";
}
*widen_next() {
var x = yield [object Number];
if (typeof x === "number") {
var x = yield 0;
if (typeof x === \"number\") {
} else
if (typeof x === "boolean") {
if (typeof x === \"boolean\") {
} else {
(x: string);
}
}
*widen_yield() {
yield [object Number];
yield "";
yield [object Boolean];
yield 0;
yield \"\";
yield true;
}
*delegate_next_generator() {
function* inner() {
@ -197,13 +197,13 @@ class GeneratorExamples {
}
*delegate_yield_generator() {
function* inner() {
yield "";
yield \"\";
}
yield* inner();
}
*delegate_return_generator() {
function* inner() {
return "";
return \"\";
}
var x: number = yield* inner();
}
@ -230,33 +230,33 @@ var examples = new GeneratorExamples();
for (var x of examples.infer_stmt()) {
(x: string);
}
var infer_stmt_next = examples.infer_stmt().next([object Number]).value;
if (typeof infer_stmt_next === "undefined") {
var infer_stmt_next = examples.infer_stmt().next(0).value;
if (typeof infer_stmt_next === \"undefined\") {
} else
if (typeof infer_stmt_next === "number") {
if (typeof infer_stmt_next === \"number\") {
} else {
(infer_stmt_next: boolean);
}
examples.widen_next().next([object Number]);
examples.widen_next().next("");
examples.widen_next().next([object Boolean]);
examples.widen_next().next(0);
examples.widen_next().next(\"\");
examples.widen_next().next(true);
for (var x of examples.widen_yield()) {
if (typeof x === "number") {
if (typeof x === \"number\") {
} else
if (typeof x === "boolean") {
if (typeof x === \"boolean\") {
} else {
(x: string);
}
}
examples.delegate_next_generator().next("");
examples.delegate_next_generator().next(\"\");
for (var x of examples.delegate_yield_generator()) {
(x: number);
}
examples.delegate_next_iterable([ ]).next("");
examples.delegate_next_iterable([ ]).next(\"\");
for (var x of examples.delegate_yield_iterable([ ])) {
(x: string);
}
@ -269,7 +269,7 @@ exports[`test class_failure.js 1`] = `
class GeneratorExamples<X> {
*infer_stmt() {
var x: boolean = yield 0; // error: number ~> boolean
return "";
return \"\";
}
}
@ -279,8 +279,8 @@ for (var x of examples.infer_stmt()) { (x : string) } // error: number ~> string
var infer_stmt_next = examples.infer_stmt().next(0).value; // error: number ~> boolean
if (typeof infer_stmt_next === "undefined") {
} else if (typeof infer_stmt_next === "number") {
if (typeof infer_stmt_next === \"undefined\") {
} else if (typeof infer_stmt_next === \"number\") {
} else {
(infer_stmt_next : boolean) // error: string ~> boolean
}
@ -292,19 +292,19 @@ if (typeof infer_stmt_next === "undefined") {
// error: string ~> boolean
class GeneratorExamples<X> {
*infer_stmt() {
var x: boolean = yield [object Number];
return "";
var x: boolean = yield 0;
return \"\";
}
}
var examples = new GeneratorExamples();
for (var x of examples.infer_stmt()) {
(x: string);
}
var infer_stmt_next = examples.infer_stmt().next([object Number]).value;
if (typeof infer_stmt_next === "undefined") {
var infer_stmt_next = examples.infer_stmt().next(0).value;
if (typeof infer_stmt_next === \"undefined\") {
} else
if (typeof infer_stmt_next === "number") {
if (typeof infer_stmt_next === \"number\") {
} else {
(infer_stmt_next: boolean);
@ -315,7 +315,7 @@ if (typeof infer_stmt_next === "undefined") {
exports[`test generators.js 1`] = `
"function *stmt_yield(): Generator<number, void, void> {
yield 0; // ok
yield ""; // error: string ~> number
yield \"\"; // error: string ~> number
}
function *stmt_next(): Generator<void, void, number> {
@ -335,41 +335,41 @@ function *stmt_return_ok(): Generator<void, number, void> {
}
function *stmt_return_err(): Generator<void, number, void> {
return ""; // error: string ~> number
return \"\"; // error: string ~> number
}
function *infer_stmt() {
var x: boolean = yield 0;
return "";
return \"\";
}
for (var x of infer_stmt()) { (x : string) } // error: number ~> string
var infer_stmt_next = infer_stmt().next(0).value; // error: number ~> boolean
if (typeof infer_stmt_next === "undefined") {
} else if (typeof infer_stmt_next === "number") {
if (typeof infer_stmt_next === \"undefined\") {
} else if (typeof infer_stmt_next === \"number\") {
} else {
(infer_stmt_next : boolean) // error: string ~> boolean
}
function *widen_next() {
var x = yield 0;
if (typeof x === "number") {
} else if (typeof x === "boolean") {
if (typeof x === \"number\") {
} else if (typeof x === \"boolean\") {
} else {
(x : string) // ok, sherlock
}
}
widen_next().next(0)
widen_next().next("")
widen_next().next(\"\")
widen_next().next(true)
function *widen_yield() {
yield 0;
yield "";
yield \"\";
yield true;
}
for (var x of widen_yield()) {
if (typeof x === "number") {
} else if (typeof x === "boolean") {
if (typeof x === \"number\") {
} else if (typeof x === \"boolean\") {
} else {
(x : string) // ok, sherlock
}
@ -381,11 +381,11 @@ function *delegate_next_generator() {
}
yield *inner();
}
delegate_next_generator().next("");
delegate_next_generator().next(\"\");
function *delegate_yield_generator() {
function *inner() {
yield "";
yield \"\";
}
yield *inner();
@ -396,7 +396,7 @@ for (var x of delegate_yield_generator()) {
function *delegate_return_generator() {
function *inner() {
return "";
return \"\";
}
var x: number = yield *inner(); // error: string ~> number
@ -406,7 +406,7 @@ function *delegate_return_generator() {
function *delegate_next_iterable(xs: Array<number>) {
yield *xs;
}
delegate_next_iterable([]).next(""); // error: Iterator has no next value
delegate_next_iterable([]).next(\"\"); // error: Iterator has no next value
function *delegate_yield_iterable(xs: Array<number>) {
yield *xs;
@ -435,7 +435,7 @@ function *multiple_return(b) {
if (b) {
return 0;
} else {
return "foo";
return \"foo\";
}
}
let multiple_return_result = multiple_return().next();
@ -463,8 +463,8 @@ if (multiple_return_result.done) {
// ok: Iterator has no yield value
// error: number|string ~> void
function* stmt_yield(): Generator<number, void, void> {
yield [object Number];
yield "";
yield 0;
yield \"\";
}
function* stmt_next(): Generator<void, void, number> {
var a = yield;
@ -477,51 +477,51 @@ function* stmt_next(): Generator<void, void, number> {
}
}
function* stmt_return_ok(): Generator<void, number, void> {
return [object Number];
return 0;
}
function* stmt_return_err(): Generator<void, number, void> {
return "";
return \"\";
}
function* infer_stmt() {
var x: boolean = yield [object Number];
return "";
var x: boolean = yield 0;
return \"\";
}
for (var x of infer_stmt()) {
(x: string);
}
var infer_stmt_next = infer_stmt().next([object Number]).value;
if (typeof infer_stmt_next === "undefined") {
var infer_stmt_next = infer_stmt().next(0).value;
if (typeof infer_stmt_next === \"undefined\") {
} else
if (typeof infer_stmt_next === "number") {
if (typeof infer_stmt_next === \"number\") {
} else {
(infer_stmt_next: boolean);
}
function* widen_next() {
var x = yield [object Number];
if (typeof x === "number") {
var x = yield 0;
if (typeof x === \"number\") {
} else
if (typeof x === "boolean") {
if (typeof x === \"boolean\") {
} else {
(x: string);
}
}
widen_next().next([object Number]);
widen_next().next("");
widen_next().next([object Boolean]);
widen_next().next(0);
widen_next().next(\"\");
widen_next().next(true);
function* widen_yield() {
yield [object Number];
yield "";
yield [object Boolean];
yield 0;
yield \"\";
yield true;
}
for (var x of widen_yield()) {
if (typeof x === "number") {
if (typeof x === \"number\") {
} else
if (typeof x === "boolean") {
if (typeof x === \"boolean\") {
} else {
(x: string);
@ -533,10 +533,10 @@ function* delegate_next_generator() {
}
yield* inner();
}
delegate_next_generator().next("");
delegate_next_generator().next(\"\");
function* delegate_yield_generator() {
function* inner() {
yield "";
yield \"\";
}
yield* inner();
}
@ -545,14 +545,14 @@ for (var x of delegate_yield_generator()) {
}
function* delegate_return_generator() {
function* inner() {
return "";
return \"\";
}
var x: number = yield* inner();
}
function* delegate_next_iterable(xs: Array<number>) {
yield* xs;
}
delegate_next_iterable([ ]).next("");
delegate_next_iterable([ ]).next(\"\");
function* delegate_yield_iterable(xs: Array<number>) {
yield* xs;
}
@ -573,9 +573,9 @@ function* generic_next<N>(): Generator<void, N, N> {
}
function* multiple_return(b) {
if (b) {
return [object Number];
return 0;
} else {
return "foo";
return \"foo\";
}
}
let multiple_return_result = multiple_return().next();
@ -587,13 +587,13 @@ if (multiple_return_result.done) {
exports[`test return.js 1`] = `
"function test1(gen: Generator<void, string, void>) {
// You can pass whatever you like to return, it doesn't need to be related to
// the Generator's return type
// You can pass whatever you like to return, it doesn\'t need to be related to
// the Generator\'s return type
var ret = gen.return(0);
(ret.value: void); // error: string | number ~> void
}
// However, a generator can "refuse" the return by catching an exception and
// However, a generator can \"refuse\" the return by catching an exception and
// yielding or returning internally.
function *refuse_return() {
try {
@ -603,30 +603,30 @@ function *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) {
(refuse_return_result.value: string); // error: number | void ~> string
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// You can pass whatever you like to return, it doesn't need to be related to
// the Generator's return type
// You can pass whatever you like to return, it doesn\'t need to be related to
// the Generator\'s return type
// error: string | number ~> void
// However, a generator can "refuse" the return by catching an exception and
// However, a generator can \"refuse\" the return by catching an exception and
// yielding or returning internally.
// error: number | void ~> string
function test1(gen: Generator<void, string, void>) {
var ret = gen.return([object Number]);
var ret = gen.return(0);
(ret.value: void);
}
function* refuse_return() {
try {
yield [object Number];
yield 1;
} finally {
return [object Number];
return 0;
}
}
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) {
(refuse_return_result.value: string);
}
@ -642,7 +642,7 @@ exports[`test throw.js 1`] = `
}
}
var catch_return_value = catch_return().throw("").value;
var catch_return_value = catch_return().throw(\"\").value;
if (catch_return_value !== undefined) {
(catch_return_value : string); // error: number ~> string
}
@ -655,7 +655,7 @@ function *yield_return() {
yield e;
}
}
var yield_return_value = yield_return().throw("").value;
var yield_return_value = yield_return().throw(\"\").value;
if (yield_return_value !== undefined) {
(yield_return_value: string); // error: number ~> string
}
@ -664,24 +664,24 @@ if (yield_return_value !== undefined) {
// error: number ~> string
function* catch_return() {
try {
yield [object Number];
yield 0;
} catch (e) {
return e;
}
}
var catch_return_value = catch_return().throw("").value;
var catch_return_value = catch_return().throw(\"\").value;
if (catch_return_value !== undefined) {
(catch_return_value: string);
}
function* yield_return() {
try {
yield [object Number];
yield 0;
return;
} catch (e) {
yield e;
}
}
var yield_return_value = yield_return().throw("").value;
var yield_return_value = yield_return().throw(\"\").value;
if (yield_return_value !== undefined) {
(yield_return_value: string);
}

View File

@ -36,12 +36,12 @@ class H<Z> extends G<Array<Z>> {
}
var h1 = new H();
h1.foo(["..."]);
h1.foo([\"...\"]);
var h2:F<Array<Array<Array<number>>>> = h1;
var obj : Object<string, string> = {} // error, arity 0
var fn : Function<string> = function() { return 'foo'; } // error, arity 0
var fn : function<string> = function() { return 'foo'; } // error, arity 0
var fn : Function<string> = function() { return \'foo\'; } // error, arity 0
var fn : function<string> = function() { return \'foo\'; } // error, arity 0
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//x:X;
/*return x;*/
@ -69,7 +69,7 @@ class D<T> {
}
var d = new D();
var o = {};
var b = d.m([object Boolean], [object Number], o);
var b = d.m(true, 0, o);
var s: string = d.x;
var n: number = o.u;
class E<X> extends C<X> {
@ -79,7 +79,7 @@ class E<X> extends C<X> {
}
}
var e = new E();
var x: string = e.set([object Number]);
var x: string = e.set(0);
class F<X> {}
class G<Y> extends F<Array<Y>> {}
class H<Z> extends G<Array<Z>> {
@ -89,14 +89,14 @@ class H<Z> extends G<Array<Z>> {
}
}
var h1 = new H();
h1.foo([ "..." ]);
h1.foo([ \"...\" ]);
var h2: F<Array<Array<Array<number>>>> = h1;
var obj: Object<string, string> = {};
var fn: Function<string> = function() {
return "foo";
return \"foo\";
};
var fn: function<string> = function() {
return "foo";
return \"foo\";
};
"
`;

View File

@ -1,7 +1,7 @@
exports[`test example.js 1`] = `
"/* @flow */
var lib = require('./library');
var lib = require(\'./library\');
function add(a: number, b: number): number {
return a + b;
@ -18,12 +18,12 @@ lib.bar();
/* @flow */
// t123456
// D123456
var lib = require("./library");
var lib = require(\"./library\");
function add(a: number, b: number): number {
return a + b;
}
var re = [object RegExp];
add(lib.iTakeAString([object Number]), [object Number]);
var re = /^keynote (talk){2} (lightning){3,5} (talk){2} closing partytime!!!/;
add(lib.iTakeAString(42), 7);
lib.bar();
"
`;
@ -31,23 +31,23 @@ lib.bar();
exports[`test imports.js 1`] = `
"// @flow
import thing from "./helpers/exports_default.js";
import thing from \"./helpers/exports_default.js\";
thing;
import {foo, bar as baz} from "./helpers/exports_named.js";
import {foo, bar as baz} from \"./helpers/exports_named.js\";
foo;
baz;
import * as things from "./helpers/exports_named.js";
import * as things from \"./helpers/exports_named.js\";
things;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// @flow
import thing from "./helpers/exports_default.js";
import thing from \"./helpers/exports_default.js\";
thing;
import { foo, bar as baz } from "./helpers/exports_named.js";
import { foo, bar as baz } from \"./helpers/exports_named.js\";
foo;
baz;
import * as things from "./helpers/exports_named.js";
import * as things from \"./helpers/exports_named.js\";
things;
"
`;
@ -70,10 +70,10 @@ module.exports = {
/* @flow */
module.exports = {
iTakeAString: function(name: string): number {
return [object Number];
return 42;
},
bar: function(): number {
return [object Number];
return 42;
}
};
"

View File

@ -14,12 +14,12 @@ var f = {
*/
var f = {
get a() {
return [object Number];
return 4;
},
set b(x: number) {
this.c = b;
},
c: [object Number]
c: 10
};
"
`;

View File

@ -24,10 +24,10 @@ class Foo {
get propWithSubtypingGetterAndSetterReordered(): ?number { return 4; }
get propWithMismatchingGetterAndSetter(): number { return 4; }
set propWithMismatchingGetterAndSetter(x: string) { } // doesn't match getter (OK)
set propWithMismatchingGetterAndSetter(x: string) { } // doesn\'t match getter (OK)
propOverriddenWithGetter: number;
get propOverriddenWithGetter() { return "hello"; }
get propOverriddenWithGetter() { return \"hello\"; }
propOverriddenWithSetter: number;
set propOverriddenWithSetter(x: string) { }
@ -47,8 +47,8 @@ foo.goodSetterNoAnnotation = 123;
foo.goodSetterWithAnnotation = 123;
// TODO: Why does no annotation mean no error?
foo.goodSetterNoAnnotation = "hello"; // Error string ~> number
foo.goodSetterWithAnnotation = "hello"; // Error string ~> number
foo.goodSetterNoAnnotation = \"hello\"; // Error string ~> number
foo.goodSetterWithAnnotation = \"hello\"; // Error string ~> number
var testSubtypingGetterAndSetter: number = foo.propWithSubtypingGetterAndSetter; // Error ?number ~> number
@ -60,7 +60,7 @@ foo.propOverriddenWithSetter = 123; // Error number ~> string
*/
// The getter and setter need not have the same type - no error
// The getter and setter need not have the same type - no error
// doesn't match getter (OK)
// doesn\'t match getter (OK)
// Test getting properties with getters
// Error number ~> string
// Error number ~> string
@ -71,13 +71,13 @@ foo.propOverriddenWithSetter = 123; // Error number ~> string
// Error ?number ~> number
// Error string ~> number
// Error number ~> string
var z: number = [object Number];
var z: number = 123;
class Foo {
get goodGetterNoAnnotation() {
return [object Number];
return 4;
}
get goodGetterWithAnnotation(): number {
return [object Number];
return 4;
}
set goodSetterNoAnnotation(x) {
z = x;
@ -86,13 +86,13 @@ class Foo {
z = x;
}
get propWithMatchingGetterAndSetter(): number {
return [object Number];
return 4;
}
set propWithMatchingGetterAndSetter(x: number) {
}
get propWithSubtypingGetterAndSetter(): ?number {
return [object Number];
return 4;
}
set propWithSubtypingGetterAndSetter(x: number) {
@ -101,17 +101,17 @@ class Foo {
}
get propWithSubtypingGetterAndSetterReordered(): ?number {
return [object Number];
return 4;
}
get propWithMismatchingGetterAndSetter(): number {
return [object Number];
return 4;
}
set propWithMismatchingGetterAndSetter(x: string) {
}
propOverriddenWithGetter: number;
get propOverriddenWithGetter() {
return "hello";
return \"hello\";
}
propOverriddenWithSetter: number;
set propOverriddenWithSetter(x: string) {
@ -123,13 +123,13 @@ var testGetterNoError1: number = foo.goodGetterNoAnnotation;
var testGetterNoError2: number = foo.goodGetterWithAnnotation;
var testGetterWithError1: string = foo.goodGetterNoAnnotation;
var testGetterWithError2: string = foo.goodGetterWithAnnotation;
foo.goodSetterNoAnnotation = [object Number];
foo.goodSetterWithAnnotation = [object Number];
foo.goodSetterNoAnnotation = "hello";
foo.goodSetterWithAnnotation = "hello";
foo.goodSetterNoAnnotation = 123;
foo.goodSetterWithAnnotation = 123;
foo.goodSetterNoAnnotation = \"hello\";
foo.goodSetterWithAnnotation = \"hello\";
var testSubtypingGetterAndSetter: number = foo.propWithSubtypingGetterAndSetter;
var testPropOverridenWithGetter: number = foo.propOverriddenWithGetter;
foo.propOverriddenWithSetter = [object Number];
foo.propOverriddenWithSetter = 123;
"
`;
@ -181,17 +181,17 @@ var testGetterWithError2: string = obj.goodGetterWithAnnotation; // Error number
obj.goodSetterNoAnnotation = 123;
obj.goodSetterWithAnnotation = 123;
obj.goodSetterNoAnnotation = "hello"; // Error string ~> number
obj.goodSetterWithAnnotation = "hello"; // Error string ~> number
obj.goodSetterNoAnnotation = \"hello\"; // Error string ~> number
obj.goodSetterWithAnnotation = \"hello\"; // Error string ~> number
var testSubtypingGetterAndSetter: number = obj.propWithSubtypingGetterAndSetter; // Error ?number ~> number
// When building this feature, it was tempting to flow the setter into the
// getter and then use either the getter or setter as the type of the property.
// This example shows the danger of using the getter's type
// This example shows the danger of using the getter\'s type
obj.exampleOfOrderOfGetterAndSetter = new C(); // Error C ~> B
// And this example shows the danger of using the setter's type.
// And this example shows the danger of using the setter\'s type.
var testExampleOrOrderOfGetterAndSetterReordered: number =
obj.exampleOfOrderOfGetterAndSetterReordered; // Error A ~> B
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ -210,20 +210,20 @@ var testExampleOrOrderOfGetterAndSetterReordered: number =
// Error ?number ~> number
// When building this feature, it was tempting to flow the setter into the
// getter and then use either the getter or setter as the type of the property.
// This example shows the danger of using the getter's type
// This example shows the danger of using the getter\'s type
// Error C ~> B
// And this example shows the danger of using the setter's type.
// And this example shows the danger of using the setter\'s type.
// Error A ~> B
var z: number = [object Number];
var z: number = 123;
class A {}
class B extends A {}
class C extends A {}
var obj = {
get goodGetterNoAnnotation() {
return [object Number];
return 4;
},
get goodGetterWithAnnotation(): number {
return [object Number];
return 4;
},
set goodSetterNoAnnotation(x) {
z = x;
@ -232,13 +232,13 @@ var obj = {
z = x;
},
get propWithMatchingGetterAndSetter(): number {
return [object Number];
return 4;
},
set propWithMatchingGetterAndSetter(x: number) {
},
get propWithSubtypingGetterAndSetter(): ?number {
return [object Number];
return 4;
},
set propWithSubtypingGetterAndSetter(x: number) {
@ -247,7 +247,7 @@ var obj = {
},
get propWithSubtypingGetterAndSetterReordered(): ?number {
return [object Number];
return 4;
},
get exampleOfOrderOfGetterAndSetter(): A {
return new A();
@ -266,10 +266,10 @@ var testGetterNoError1: number = obj.goodGetterNoAnnotation;
var testGetterNoError2: number = obj.goodGetterWithAnnotation;
var testGetterWithError1: string = obj.goodGetterNoAnnotation;
var testGetterWithError2: string = obj.goodGetterWithAnnotation;
obj.goodSetterNoAnnotation = [object Number];
obj.goodSetterWithAnnotation = [object Number];
obj.goodSetterNoAnnotation = "hello";
obj.goodSetterWithAnnotation = "hello";
obj.goodSetterNoAnnotation = 123;
obj.goodSetterWithAnnotation = 123;
obj.goodSetterNoAnnotation = \"hello\";
obj.goodSetterWithAnnotation = \"hello\";
var testSubtypingGetterAndSetter: number = obj.propWithSubtypingGetterAndSetter;
obj.exampleOfOrderOfGetterAndSetter = new C();
var testExampleOrOrderOfGetterAndSetterReordered: number = obj.exampleOfOrderOfGetterAndSetterReordered;
@ -295,12 +295,12 @@ React.createClass({
React.createClass({
propTypes: {
get a() {
return [object Number];
return 4;
},
set b(x: number) {
this.c = x;
},
c: [object Number]
c: 10
}
});
"

View File

@ -17,7 +17,7 @@ module.exports = ClassFoo3;
*/
class ClassFoo3 {
givesANum(): number {
return [object Number];
return 42;
}
static givesAFoo3(): ClassFoo3 {
return new ClassFoo3();
@ -56,7 +56,7 @@ exports.foo5Inst = new ClassFoo5();
*/
class ClassFoo4 {
returnsANumber(): number {
return [object Number];
return 42;
}
}
class ClassFoo5 {}
@ -90,7 +90,7 @@ export var foo1Inst = new ClassFoo1();
*/
class ClassFoo1 {
returnsANumber(): number {
return [object Number];
return 42;
}
}
export default ClassFoo1
@ -119,7 +119,7 @@ export type AliasFoo3 = { givesANum: : () => number };
export function givesAFoo3Obj(): AliasFoo3 {
return {
givesANum(): number {
return [object Number];
return 42;
}
};
}
@ -143,7 +143,7 @@ export var foo2Inst = new ClassFoo2();
*/
class ClassFoo2 {
returnsANumber(): number {
return [object Number];
return 42;
}
}
export { ClassFoo2 }
@ -157,7 +157,7 @@ exports[`test ExportsANumber.js 1`] = `
export var numValue = 42;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/* @ flow */
export var numValue = [object Number];
export var numValue = 42;
"
`;
@ -170,8 +170,8 @@ exports[`test import_type.js 1`] = `
// == Importing Class Type (Default Export) == //
/////////////////////////////////////////////////
import type ClassFoo1 from "./ExportDefault_Class";
import {foo1Inst} from "./ExportDefault_Class";
import type ClassFoo1 from \"./ExportDefault_Class\";
import {foo1Inst} from \"./ExportDefault_Class\";
var a1: ClassFoo1 = foo1Inst;
var a2: number = foo1Inst; // Error: ClassFoo1 ~> number
@ -181,8 +181,8 @@ new ClassFoo1(); // Error: ClassFoo1 is not a value-identifier
// == Importing Class Type (Named Export) == //
///////////////////////////////////////////////
import type {ClassFoo2} from "./ExportNamed_Class";
import {foo2Inst} from "./ExportNamed_Class";
import type {ClassFoo2} from \"./ExportNamed_Class\";
import {foo2Inst} from \"./ExportNamed_Class\";
var b1: ClassFoo2 = foo2Inst;
var b2: number = foo2Inst; // Error: ClassFoo2 ~> number
@ -192,8 +192,8 @@ new ClassFoo2(); // Error: ClassFoo2 is not a value-identifier
// == Importing Class Type (CJS Default Export) == //
/////////////////////////////////////////////////////
import type ClassFoo3T from "./ExportCJSDefault_Class";
import ClassFoo3 from "./ExportCJSDefault_Class";
import type ClassFoo3T from \"./ExportCJSDefault_Class\";
import ClassFoo3 from \"./ExportCJSDefault_Class\";
var c1: ClassFoo3T = new ClassFoo3();
new ClassFoo3T(); // Error: ClassFoo3 is not a value-identifier
@ -201,38 +201,38 @@ new ClassFoo3T(); // Error: ClassFoo3 is not a value-identifier
// == Importing Class Type (CJS Named Export) == //
///////////////////////////////////////////////////
import type {ClassFoo4, ClassFoo5} from "./ExportCJSNamed_Class";
import {foo4Inst, foo5Inst} from "./ExportCJSNamed_Class";
import type {ClassFoo4, ClassFoo5} from \"./ExportCJSNamed_Class\";
import {foo4Inst, foo5Inst} from \"./ExportCJSNamed_Class\";
var d1: ClassFoo4 = foo4Inst;
var d2: number = foo4Inst; // Error: ClassFoo4 ~> number
new ClassFoo4(); // Error: ClassFoo4 is not a value-identifier
// TODO: this errors correctly, but the message is just 'can't resolve name'
var d3: typeof ClassFoo5 = foo5Inst; // Error: Can't typeof a type alias
// TODO: this errors correctly, but the message is just \'can\'t resolve name\'
var d3: typeof ClassFoo5 = foo5Inst; // Error: Can\'t typeof a type alias
////////////////////////////////////////////
// == Import Type Alias (Named Export) == //
////////////////////////////////////////////
import type {AliasFoo3} from "./ExportNamed_Alias";
import {givesAFoo3Obj} from "./ExportNamed_Alias";
import type {AliasFoo3} from \"./ExportNamed_Alias\";
import {givesAFoo3Obj} from \"./ExportNamed_Alias\";
var e1: AliasFoo3 = givesAFoo3Obj();
var e2: number = givesAFoo3Obj(); // Error: AliasFoo3 ~> number
var e3: typeof AliasFoo3 = givesAFoo3Obj(); // Error: Can't typeof a type alias
var e3: typeof AliasFoo3 = givesAFoo3Obj(); // Error: Can\'t typeof a type alias
//////////////////////////////////////////////
// == Import Type Alias (Default Export) == //
//////////////////////////////////////////////
// TODO: No support for this right now. It's most likely possible, but it's
// TODO: No support for this right now. It\'s most likely possible, but it\'s
// unclear how useful it is at the moment and it entails a little
// more work than named type exports, so I'm punting on it for now.
// more work than named type exports, so I\'m punting on it for now.
///////////////////////////////////////////////////////
// == Import Type With Non-Alias Compatible Value == //
///////////////////////////////////////////////////////
import type {numValue} from "./ExportsANumber"; // Error: Cannot import-type a number value
import type {numValue} from \"./ExportsANumber\"; // Error: Cannot import-type a number value
////////////////////////////////////////////////////////////////////////
// == Regression Test: https://github.com/facebook/flow/issues/359 == //
@ -240,7 +240,7 @@ import type {numValue} from "./ExportsANumber"; // Error: Cannot import-type a n
// env contexts. //
////////////////////////////////////////////////////////////////////////
import type ClassFoo6 from "./issue-359";
import type ClassFoo6 from \"./issue-359\";
function foo() {
ClassFoo6; // Error: Not a value binding
}
@ -267,19 +267,19 @@ function foo() {
///////////////////////////////////////////////////
// Error: ClassFoo4 ~> number
// Error: ClassFoo4 is not a value-identifier
// TODO: this errors correctly, but the message is just 'can't resolve name'
// Error: Can't typeof a type alias
// TODO: this errors correctly, but the message is just \'can\'t resolve name\'
// Error: Can\'t typeof a type alias
////////////////////////////////////////////
// == Import Type Alias (Named Export) == //
////////////////////////////////////////////
// Error: AliasFoo3 ~> number
// Error: Can't typeof a type alias
// Error: Can\'t typeof a type alias
//////////////////////////////////////////////
// == Import Type Alias (Default Export) == //
//////////////////////////////////////////////
// TODO: No support for this right now. It's most likely possible, but it's
// TODO: No support for this right now. It\'s most likely possible, but it\'s
// unclear how useful it is at the moment and it entails a little
// more work than named type exports, so I'm punting on it for now.
// more work than named type exports, so I\'m punting on it for now.
///////////////////////////////////////////////////////
// == Import Type With Non-Alias Compatible Value == //
///////////////////////////////////////////////////////
@ -290,33 +290,33 @@ function foo() {
// env contexts. //
////////////////////////////////////////////////////////////////////////
// Error: Not a value binding
import type ClassFoo1 from "./ExportDefault_Class";
import { foo1Inst } from "./ExportDefault_Class";
import type ClassFoo1 from \"./ExportDefault_Class\";
import { foo1Inst } from \"./ExportDefault_Class\";
var a1: ClassFoo1 = foo1Inst;
var a2: number = foo1Inst;
new ClassFoo1();
import type { ClassFoo2 } from "./ExportNamed_Class";
import { foo2Inst } from "./ExportNamed_Class";
import type { ClassFoo2 } from \"./ExportNamed_Class\";
import { foo2Inst } from \"./ExportNamed_Class\";
var b1: ClassFoo2 = foo2Inst;
var b2: number = foo2Inst;
new ClassFoo2();
import type ClassFoo3T from "./ExportCJSDefault_Class";
import ClassFoo3 from "./ExportCJSDefault_Class";
import type ClassFoo3T from \"./ExportCJSDefault_Class\";
import ClassFoo3 from \"./ExportCJSDefault_Class\";
var c1: ClassFoo3T = new ClassFoo3();
new ClassFoo3T();
import type { ClassFoo4, ClassFoo5 } from "./ExportCJSNamed_Class";
import { foo4Inst, foo5Inst } from "./ExportCJSNamed_Class";
import type { ClassFoo4, ClassFoo5 } from \"./ExportCJSNamed_Class\";
import { foo4Inst, foo5Inst } from \"./ExportCJSNamed_Class\";
var d1: ClassFoo4 = foo4Inst;
var d2: number = foo4Inst;
new ClassFoo4();
var d3: typeof ClassFoo5 = foo5Inst;
import type { AliasFoo3 } from "./ExportNamed_Alias";
import { givesAFoo3Obj } from "./ExportNamed_Alias";
import type { AliasFoo3 } from \"./ExportNamed_Alias\";
import { givesAFoo3Obj } from \"./ExportNamed_Alias\";
var e1: AliasFoo3 = givesAFoo3Obj();
var e2: number = givesAFoo3Obj();
var e3: typeof AliasFoo3 = givesAFoo3Obj();
import type { numValue } from "./ExportsANumber";
import type ClassFoo6 from "./issue-359";
import type { numValue } from \"./ExportsANumber\";
import type ClassFoo6 from \"./issue-359\";
function foo() {
ClassFoo6;
}

View File

@ -17,7 +17,7 @@ module.exports = ClassFoo3;
*/
class ClassFoo3 {
givesANum(): number {
return [object Number];
return 42;
}
static givesAFoo3(): ClassFoo3 {
return new ClassFoo3();
@ -33,7 +33,7 @@ exports[`test ExportCJSDefault_Number.js 1`] = `
module.exports = 42;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/* @flow */
module.exports = [object Number];
module.exports = 42;
"
`;
@ -60,7 +60,7 @@ exports[`test ExportCJSNamed_Number.js 1`] = `
exports.num = 42;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/* @flow */
exports.num = [object Number];
exports.num = 42;
"
`;
@ -80,7 +80,7 @@ export default ClassFoo1;
*/
class ClassFoo1 {
returnsANumber(): number {
return [object Number];
return 42;
}
}
export default ClassFoo1
@ -93,7 +93,7 @@ exports[`test ExportDefault_Number.js 1`] = `
export default 42;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/* @flow */
export default [object Number]
export default 42
"
`;
@ -118,7 +118,7 @@ export type AliasFoo3 = { givesANum: : () => number };
export function givesAFoo3Obj(): AliasFoo3 {
return {
givesANum(): number {
return [object Number];
return 42;
}
};
}
@ -141,7 +141,7 @@ export {ClassFoo2};
*/
class ClassFoo2 {
returnsANumber(): number {
return [object Number];
return 42;
}
}
export { ClassFoo2 }
@ -152,11 +152,11 @@ exports[`test ExportNamed_Multi.js 1`] = `
"// @flow
export var num = 42;
export var str = 'asdf';
export var str = \'asdf\';
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// @flow
export var num = [object Number];
export var str = "asdf";
export var num = 42;
export var str = \"asdf\";
"
`;
@ -166,7 +166,7 @@ exports[`test ExportNamed_Number.js 1`] = `
export var num = 42;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/* @flow */
export var num = [object Number];
export var num = 42;
"
`;
@ -179,8 +179,8 @@ exports[`test import_typeof.js 1`] = `
// == Importing Class Typeof (Default Export) == //
///////////////////////////////////////////////////
import typeof ClassFoo1T from "./ExportDefault_Class";
import ClassFoo1 from "./ExportDefault_Class";
import typeof ClassFoo1T from \"./ExportDefault_Class\";
import ClassFoo1 from \"./ExportDefault_Class\";
var a1: ClassFoo1T = ClassFoo1;
var a2: ClassFoo1T = new ClassFoo1(); // Error: ClassFoo1 (inst) ~> ClassFoo1 (class)
@ -190,8 +190,8 @@ new ClassFoo1T(); // Error: ClassFoo1T is not bound to a value
// == Importing Class Typeof (Named Export) == //
/////////////////////////////////////////////////
import typeof {ClassFoo2 as ClassFoo2T} from "./ExportNamed_Class";
import {ClassFoo2} from "./ExportNamed_Class";
import typeof {ClassFoo2 as ClassFoo2T} from \"./ExportNamed_Class\";
import {ClassFoo2} from \"./ExportNamed_Class\";
var b1: ClassFoo2T = ClassFoo2;
var b2: ClassFoo2T = new ClassFoo2(); // Error: ClassFoo2 (inst) ~> ClassFoo2 (class)
@ -201,8 +201,8 @@ new ClassFoo2T(); // Error: ClassFoo2T is not bound to a value
// == Importing Class Typeof (CJS Default Export) == //
///////////////////////////////////////////////////////
import typeof ClassFoo3T from "./ExportCJSDefault_Class";
import ClassFoo3 from "./ExportCJSDefault_Class";
import typeof ClassFoo3T from \"./ExportCJSDefault_Class\";
import ClassFoo3 from \"./ExportCJSDefault_Class\";
var c1: ClassFoo3T = ClassFoo3;
var c2: ClassFoo3T = new ClassFoo3(); // Error: ClassFoo3 (inst) ~> ClassFoo3 (class)
@ -211,8 +211,8 @@ var c2: ClassFoo3T = new ClassFoo3(); // Error: ClassFoo3 (inst) ~> ClassFoo3 (c
// == Importing Class Typeof (CJS Named Export) == //
/////////////////////////////////////////////////////
import typeof {ClassFoo4 as ClassFoo4T} from "./ExportCJSNamed_Class";
import {ClassFoo4} from "./ExportCJSNamed_Class";
import typeof {ClassFoo4 as ClassFoo4T} from \"./ExportCJSNamed_Class\";
import {ClassFoo4} from \"./ExportCJSNamed_Class\";
var d1: ClassFoo4T = ClassFoo4;
var d2: ClassFoo4T = new ClassFoo4(); // Error: ClassFoo4 (inst) ~> ClassFoo4 (class)
@ -221,58 +221,58 @@ var d2: ClassFoo4T = new ClassFoo4(); // Error: ClassFoo4 (inst) ~> ClassFoo4 (c
// == Import Typeof Alias (Named Export) == //
//////////////////////////////////////////////
import typeof {AliasFoo3} from "./ExportNamed_Alias"; // Error: Can't \`import typeof\` type aliases!
import typeof {AliasFoo3} from \"./ExportNamed_Alias\"; // Error: Can\'t \`import typeof\` type aliases!
////////////////////////////////////////////////
// == Import Typeof Alias (Default Export) == //
////////////////////////////////////////////////
// TODO: No support for this right now. It's most likely possible, but it's
// TODO: No support for this right now. It\'s most likely possible, but it\'s
// unclear how useful it is at the moment and it entails a little
// more work than named type exports, so I'm punting on it for now.
// more work than named type exports, so I\'m punting on it for now.
///////////////////////////////////////////////////////////////
// == Import Typeof With Non-Class Value (Default Export) == //
///////////////////////////////////////////////////////////////
import typeof num_default from "./ExportDefault_Number";
import typeof num_default from \"./ExportDefault_Number\";
var f1: num_default = 42;
var f2: num_default = 'asdf'; // Error: string ~> number
var f2: num_default = \'asdf\'; // Error: string ~> number
/////////////////////////////////////////////////////////////
// == Import Typeof With Non-Class Value (Named Export) == //
/////////////////////////////////////////////////////////////
import typeof {num as num_named} from "./ExportNamed_Number";
import typeof {num as num_named} from \"./ExportNamed_Number\";
var g1: num_named = 42;
var g2: num_named = 'asdf'; // Error: string ~> number
var g2: num_named = \'asdf\'; // Error: string ~> number
///////////////////////////////////////////////////////////////////
// == Import Typeof With Non-Class Value (CJS Default Export) == //
///////////////////////////////////////////////////////////////////
import typeof num_cjs_default from "./ExportCJSDefault_Number";
import typeof num_cjs_default from \"./ExportCJSDefault_Number\";
var h1: num_cjs_default = 42;
var h2: num_cjs_default = 'asdf'; // Error: string ~> number
var h2: num_cjs_default = \'asdf\'; // Error: string ~> number
/////////////////////////////////////////////////////////////////
// == Import Typeof With Non-Class Value (CJS Named Export) == //
/////////////////////////////////////////////////////////////////
import typeof {num as num_cjs_named} from "./ExportCJSNamed_Number";
import typeof {num as num_cjs_named} from \"./ExportCJSNamed_Number\";
var i1: num_cjs_named = 42;
var i2: num_cjs_named = 'asdf'; // Error: string ~> number
var i2: num_cjs_named = \'asdf\'; // Error: string ~> number
///////////////////////////////////////////////
// == Import Typeof ModuleNamespaceObject == //
///////////////////////////////////////////////
import typeof * as ModuleNSObjT from "./ExportNamed_Multi";
var j1: ModuleNSObjT = {num: 42, str: 'asdf'};
import typeof * as ModuleNSObjT from \"./ExportNamed_Multi\";
var j1: ModuleNSObjT = {num: 42, str: \'asdf\'};
var j2: ModuleNSObjT = {num: 42, str: 42}; // Error: number ~> string
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/**
@ -299,13 +299,13 @@ var j2: ModuleNSObjT = {num: 42, str: 42}; // Error: number ~> string
//////////////////////////////////////////////
// == Import Typeof Alias (Named Export) == //
//////////////////////////////////////////////
// Error: Can't \`import typeof\` type aliases!
// Error: Can\'t \`import typeof\` type aliases!
////////////////////////////////////////////////
// == Import Typeof Alias (Default Export) == //
////////////////////////////////////////////////
// TODO: No support for this right now. It's most likely possible, but it's
// TODO: No support for this right now. It\'s most likely possible, but it\'s
// unclear how useful it is at the moment and it entails a little
// more work than named type exports, so I'm punting on it for now.
// more work than named type exports, so I\'m punting on it for now.
///////////////////////////////////////////////////////////////
// == Import Typeof With Non-Class Value (Default Export) == //
///////////////////////////////////////////////////////////////
@ -326,39 +326,39 @@ var j2: ModuleNSObjT = {num: 42, str: 42}; // Error: number ~> string
// == Import Typeof ModuleNamespaceObject == //
///////////////////////////////////////////////
// Error: number ~> string
import typeof ClassFoo1T from "./ExportDefault_Class";
import ClassFoo1 from "./ExportDefault_Class";
import typeof ClassFoo1T from \"./ExportDefault_Class\";
import ClassFoo1 from \"./ExportDefault_Class\";
var a1: ClassFoo1T = ClassFoo1;
var a2: ClassFoo1T = new ClassFoo1();
new ClassFoo1T();
import typeof { ClassFoo2 as ClassFoo2T } from "./ExportNamed_Class";
import { ClassFoo2 } from "./ExportNamed_Class";
import typeof { ClassFoo2 as ClassFoo2T } from \"./ExportNamed_Class\";
import { ClassFoo2 } from \"./ExportNamed_Class\";
var b1: ClassFoo2T = ClassFoo2;
var b2: ClassFoo2T = new ClassFoo2();
new ClassFoo2T();
import typeof ClassFoo3T from "./ExportCJSDefault_Class";
import ClassFoo3 from "./ExportCJSDefault_Class";
import typeof ClassFoo3T from \"./ExportCJSDefault_Class\";
import ClassFoo3 from \"./ExportCJSDefault_Class\";
var c1: ClassFoo3T = ClassFoo3;
var c2: ClassFoo3T = new ClassFoo3();
import typeof { ClassFoo4 as ClassFoo4T } from "./ExportCJSNamed_Class";
import { ClassFoo4 } from "./ExportCJSNamed_Class";
import typeof { ClassFoo4 as ClassFoo4T } from \"./ExportCJSNamed_Class\";
import { ClassFoo4 } from \"./ExportCJSNamed_Class\";
var d1: ClassFoo4T = ClassFoo4;
var d2: ClassFoo4T = new ClassFoo4();
import typeof { AliasFoo3 } from "./ExportNamed_Alias";
import typeof num_default from "./ExportDefault_Number";
var f1: num_default = [object Number];
var f2: num_default = "asdf";
import typeof { num as num_named } from "./ExportNamed_Number";
var g1: num_named = [object Number];
var g2: num_named = "asdf";
import typeof num_cjs_default from "./ExportCJSDefault_Number";
var h1: num_cjs_default = [object Number];
var h2: num_cjs_default = "asdf";
import typeof { num as num_cjs_named } from "./ExportCJSNamed_Number";
var i1: num_cjs_named = [object Number];
var i2: num_cjs_named = "asdf";
import typeof * as ModuleNSObjT from "./ExportNamed_Multi";
var j1: ModuleNSObjT = { num: [object Number], str: "asdf" };
var j2: ModuleNSObjT = { num: [object Number], str: [object Number] };
import typeof { AliasFoo3 } from \"./ExportNamed_Alias\";
import typeof num_default from \"./ExportDefault_Number\";
var f1: num_default = 42;
var f2: num_default = \"asdf\";
import typeof { num as num_named } from \"./ExportNamed_Number\";
var g1: num_named = 42;
var g2: num_named = \"asdf\";
import typeof num_cjs_default from \"./ExportCJSDefault_Number\";
var h1: num_cjs_default = 42;
var h2: num_cjs_default = \"asdf\";
import typeof { num as num_cjs_named } from \"./ExportCJSNamed_Number\";
var i1: num_cjs_named = 42;
var i2: num_cjs_named = \"asdf\";
import typeof * as ModuleNSObjT from \"./ExportNamed_Multi\";
var j1: ModuleNSObjT = { num: 42, str: \"asdf\" };
var j2: ModuleNSObjT = { num: 42, str: 42 };
"
`;

View File

@ -1,6 +1,6 @@
exports[`test test.js 1`] = `
"(123: string);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
([object Number]: string);
(123: string);
"
`;

View File

@ -11,12 +11,12 @@ exports[`test b.js 1`] = `
@flow
*/
var A = require('IncrModuleA');
var A = require(\'IncrModuleA\');
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/* @providesModule IncrModuleB
@flow
*/
var A = require("IncrModuleA");
var A = require(\"IncrModuleA\");
"
`;
@ -26,6 +26,6 @@ exports[`test dup_a.js 1`] = `
var x:string = 0;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/* @providesModule IncrModuleA */
var x: string = [object Number];
var x: string = 0;
"
`;

View File

@ -4,19 +4,19 @@ var a: string = 0;
module.exports = a;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// @flow
var a: string = [object Number];
var a: string = 0;
module.exports = a;
"
`;
exports[`test b.js 1`] = `
"// @flow
var a = require('./a');
var a = require(\'./a\');
var b: number = a;
module.exports = b;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// @flow
var a = require("./a");
var a = require(\"./a\");
var b: number = a;
module.exports = b;
"
@ -24,12 +24,12 @@ module.exports = b;
exports[`test c.js 1`] = `
"// @flow
var b = require('./b');
var b = require(\'./b\');
var c: string = b;
module.exports = c;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// @flow
var b = require("./b");
var b = require(\"./b\");
var c: string = b;
module.exports = c;
"

View File

@ -4,7 +4,7 @@ var a = 0;
module.exports = a;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// @flow
var a = [object Number];
var a = 0;
module.exports = a;
"
`;

View File

@ -4,19 +4,19 @@ var a: string = 0;
module.exports = a;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// @flow
var a: string = [object Number];
var a: string = 0;
module.exports = a;
"
`;
exports[`test b.js 1`] = `
"// @flow
var a = require('./a');
var a = require(\'./a\');
var b: number = a;
module.exports = b;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// @flow
var a = require("./a");
var a = require(\"./a\");
var b: number = a;
module.exports = b;
"
@ -24,12 +24,12 @@ module.exports = b;
exports[`test c.js 1`] = `
"// @flow
var b = require('./b');
var b = require(\'./b\');
var c: string = b;
module.exports = c;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// @flow
var b = require("./b");
var b = require(\"./b\");
var c: string = b;
module.exports = c;
"
@ -41,14 +41,14 @@ exports[`test dupe1.js 1`] = `
* @providesModule Dupe
* @flow
*/
module.exports = "dupe1";
module.exports = \"dupe1\";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/**
* Dupe provider 1/2
* @providesModule Dupe
* @flow
*/
module.exports = "dupe1";
module.exports = \"dupe1\";
"
`;
@ -58,14 +58,14 @@ exports[`test dupe2.js 1`] = `
* @providesModule Dupe
* @flow
*/
module.exports = "dupe2";
module.exports = \"dupe2\";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/**
* Dupe provider 2/2
* @providesModule Dupe
* @flow
*/
module.exports = "dupe2";
module.exports = \"dupe2\";
"
`;
@ -74,13 +74,13 @@ exports[`test requires_dupe.js 1`] = `
* depends on doubly-provided module
* @flow
*/
var dupe = require('Dupe');
var dupe = require(\'Dupe\');
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/**
* depends on doubly-provided module
* @flow
*/
var dupe = require("Dupe");
var dupe = require(\"Dupe\");
"
`;
@ -89,13 +89,13 @@ exports[`test requires_unchecked.js 1`] = `
* depends on an unchecked module, which will be deleted
* @flow
*/
var unchecked = require('Unchecked');
var unchecked = require(\'Unchecked\');
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/**
* depends on an unchecked module, which will be deleted
* @flow
*/
var unchecked = require("Unchecked");
var unchecked = require(\"Unchecked\");
"
`;
@ -104,12 +104,12 @@ exports[`test unchecked.js 1`] = `
* Not a flow module.
* @providesModule Unchecked
*/
module.exports = "unchecked";
module.exports = \"unchecked\";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/**
* Not a flow module.
* @providesModule Unchecked
*/
module.exports = "unchecked";
module.exports = \"unchecked\";
"
`;

View File

@ -81,7 +81,7 @@ function _do_while(b: () => boolean) {
f();
}
function _for(n: number) {
for (var i = [object Number]; i < n; i++) {
for (var i = 0; i < n; i++) {
var f = function() {
};
@ -433,7 +433,7 @@ function for_in_post_init() {
// error
function linear_deferred_init() {
var x: number;
x = [object Number];
x = 0;
var y: number = x;
}
function linear_pre_init() {
@ -442,13 +442,13 @@ function linear_pre_init() {
}
function if_scoped_init(b) {
if (b) {
var x: number = [object Number];
var x: number = 0;
var y: number = x;
}
}
function if_else_partial_init(b) {
if (b) {
var x: number = [object Number];
var x: number = 0;
} else {
var y: number = x;
}
@ -456,47 +456,47 @@ function if_else_partial_init(b) {
function if_pre_init(b) {
var y: number = x;
if (b) {
var x: number = [object Number];
var x: number = 0;
}
}
function if_partial_post_init(b) {
if (b) {
var x: number = [object Number];
var x: number = 0;
}
var y: number = x;
}
function if_post_init(b) {
if (b) {
var x: number = [object Number];
var x: number = 0;
} else {
var x: number = [object Number];
var x: number = 1;
}
var y: number = x;
}
function if_partial_post_init(b) {
var x: number;
if (b) {
x = [object Number];
x = 0;
}
var y: number = x;
}
function if_post_init(b) {
var x: number;
if (b) {
x = [object Number];
x = 0;
} else {
x = [object Number];
x = 1;
}
var y: number = x;
}
function switch_partial_post_init(i) {
var x: number;
switch (i) {
case [object Number]:
x = [object Number];
case 0:
x = 0;
break;
case [object Number]:
x = [object Number];
case 1:
x = 1;
break;
}
var y: number = x;
@ -504,133 +504,133 @@ function switch_partial_post_init(i) {
function switch_post_init(i) {
var x: number;
switch (i) {
case [object Number]:
x = [object Number];
case 0:
x = 0;
break;
case [object Number]:
x = [object Number];
case 1:
x = 1;
break;
default:
x = [object Number];
x = 2;
}
var y: number = x;
}
function switch_scoped_init_1(i) {
switch (i) {
case [object Number]:
var x: number = [object Number];
case 0:
var x: number = 0;
var y: number = x;
}
}
function switch_scoped_init_2(i) {
var y: number = x;
switch (i) {
case [object Number]:
var x: number = [object Number];
case 0:
var x: number = 0;
}
}
function switch_scoped_init_3(i) {
switch (i) {
case [object Number]:
var x: number = [object Number];
case 0:
var x: number = 0;
}
var y: number = x;
}
function switch_scoped_init_4(i) {
switch (i) {
case [object Number]:
var x: number = [object Number];
case [object Number]:
case 0:
var x: number = 0;
case 1:
var y: number = x;
}
}
function while_scoped_init(b) {
while (b) {
var x: number = [object Number];
var x: number = 0;
var y: number = x;
}
}
function while_pre_init(b) {
var y: number = x;
while (b) {
var x: number = [object Number];
var x: number = 0;
}
}
function while_post_init(b) {
while (b) {
var x: number = [object Number];
var x: number = 0;
}
var y: number = x;
}
function do_while_scoped_init(b) {
do {
var x: number = [object Number];
var x: number = 0;
var y: number = x;
} while (b);
}
function do_while_pre_init(b) {
var y: number = x;
do {
var x: number = [object Number];
var x: number = 0;
} while (b);
}
function do_while_post_init(b) {
do {
var x: number = [object Number];
var x: number = 0;
} while (b);
var y: number = x;
}
function for_scoped_init(b) {
for (; b; ) {
var x: number = [object Number];
var x: number = 0;
var y: number = x;
}
}
function for_pre_init(b) {
var y: number = x;
for (; b; ) {
var x: number = [object Number];
var x: number = 0;
}
}
function for_post_init(b) {
for (; b; ) {
var x: number = [object Number];
var x: number = 0;
}
var y: number = x;
}
function for_in_scoped_init() {
for (var p in { a: [object Number], b: [object Number] }) {
var x: number = [object Number];
for (var p in { a: 1, b: 2 }) {
var x: number = 0;
var y: number = x;
}
}
function for_in_pre_init() {
var y: number = x;
for (var p in { a: [object Number], b: [object Number] }) {
var x: number = [object Number];
for (var p in { a: 1, b: 2 }) {
var x: number = 0;
}
}
function for_in_post_init() {
for (var p in { a: [object Number], b: [object Number] }) {
var x: number = [object Number];
for (var p in { a: 1, b: 2 }) {
var x: number = 0;
}
var y: number = x;
}
function for_of_scoped_init() {
for (var x of [ [object Number], [object Number], [object Number] ]) {
var x: number = [object Number];
for (var x of [ 1, 2, 3 ]) {
var x: number = 0;
var y: number = x;
}
}
function for_in_pre_init() {
var y: number = x;
for (var x of [ [object Number], [object Number], [object Number] ]) {
var x: number = [object Number];
for (var x of [ 1, 2, 3 ]) {
var x: number = 0;
}
}
function for_in_post_init() {
for (var x of [ [object Number], [object Number], [object Number] ]) {
var x: number = [object Number];
for (var x of [ 1, 2, 3 ]) {
var x: number = 0;
}
var y: number = x;
}
@ -661,7 +661,7 @@ function linear_pre_init() {
// self-references in let bindings are not ok
function self_init() {
let x = x; // 'x' not initialized!
let x = x; // \'x\' not initialized!
}
// use of let after partial init (non-exhaustive if) gives undefined
@ -768,7 +768,7 @@ function switch_post_init2(i): number {
bar = 3;
break;
default:
throw new Error('Invalid state');
throw new Error(\'Invalid state\');
}
return bar; // ok, definitely initialized
}
@ -781,7 +781,7 @@ function switch_post_init2(i): number {
bar = 3;
break;
default:
throw new Error('Invalid state');
throw new Error(\'Invalid state\');
}
return bar; // ok, definitely initialized
}
@ -806,7 +806,7 @@ function sub_closure_init_reference() {
// error
// ok
// self-references in let bindings are not ok
// 'x' not initialized!
// \'x\' not initialized!
// use of let after partial init (non-exhaustive if) gives undefined
// error, possibly uninitialized
// use of let after guaranteed init (exhaustive if) is ok
@ -833,14 +833,14 @@ function sub_closure_init_reference() {
// TDZ (...even though this is weird...)
function linear_deferred_init() {
let x: number;
x = [object Number];
x = 0;
let y: number = x;
}
function linear_pre_init() {
let x: number;
let y: ?number = x;
let z: number = x;
x = [object Number];
x = 0;
let w: number = x;
}
function self_init() {
@ -849,27 +849,27 @@ function self_init() {
function if_partial_post_init(b) {
let x: number;
if (b) {
x = [object Number];
x = 0;
}
var y: number = x;
}
function if_post_init(b) {
let x: number;
if (b) {
x = [object Number];
x = 0;
} else {
x = [object Number];
x = 1;
}
var y: number = x;
}
function switch_partial_post_init(i) {
let x: number;
switch (i) {
case [object Number]:
x = [object Number];
case 0:
x = 0;
break;
case [object Number]:
x = [object Number];
case 1:
x = 1;
break;
}
var y: number = x;
@ -877,72 +877,72 @@ function switch_partial_post_init(i) {
function switch_post_init(i) {
let x: number;
switch (i) {
case [object Number]:
x = [object Number];
case 0:
x = 0;
break;
case [object Number]:
x = [object Number];
case 1:
x = 1;
break;
default:
x = [object Number];
x = 2;
}
var y: number = x;
}
function switch_scoped_init_2(i) {
switch (i) {
case [object Number]:
case 0:
let x: number;
case [object Number]:
case 1:
let y: number = x;
}
}
function while_post_init(b) {
let x: number;
while (b) {
x = [object Number];
x = 0;
}
var y: number = x;
}
function do_while_post_init(b) {
let x: number;
do {
x = [object Number];
x = 0;
} while (b);
var y: number = x;
}
function for_in_post_init() {
var x: number;
for (var p in {}) {
x = [object Number];
x = 0;
}
var y: number = x;
}
function for_of_post_init() {
var x: number;
for (var x of [ ]) {
x = [object Number];
x = 0;
}
var y: number = x;
}
function switch_post_init2(i): number {
let bar;
switch (i) {
case [object Number]:
bar = [object Number];
case 1:
bar = 3;
break;
default:
throw new Error("Invalid state");
throw new Error(\"Invalid state\");
}
return bar;
}
function switch_post_init2(i): number {
let bar;
switch (i) {
case [object Number]:
bar = [object Number];
case 1:
bar = 3;
break;
default:
throw new Error("Invalid state");
throw new Error(\"Invalid state\");
}
return bar;
}
@ -962,7 +962,7 @@ exports[`test nullable-init.js 1`] = `
"var o: {x: ?number} = { x: null };
var a: Array<?number> = [null,null];
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
var o: { x: ?number } = { x: [object Null] };
var a: Array<?number> = [ [object Null], [object Null] ];
var o: { x: ?number } = { x: null };
var a: Array<?number> = [ null, null ];
"
`;

View File

@ -9,13 +9,13 @@ function x(b) { return b ? new X1 : new X2; }
function consumer1(b) {
var g = x(b);
if (g instanceof X2) g.foo = '1337';
if (g instanceof X2) g.foo = \'1337\';
else g.foo = 1337;
}
function consumer2(b) {
var g = x(b);
if (g instanceof X1) g.foo = '1337'; // oops
if (g instanceof X1) g.foo = \'1337\'; // oops
}
// x.y instanceof t
@ -26,13 +26,13 @@ function y(b) { return b ? new Y1 : new Y2; }
function consumer3(b) {
var g = y(b);
if (g.bar instanceof X2) g.bar.foo = '1337';
if (g.bar instanceof X2) g.bar.foo = \'1337\';
else g.bar.foo = 1337;
}
function consumer4(b) {
var g = y(b);
if (g.bar instanceof X1) g.bar.foo = '1337'; // oops
if (g.bar instanceof X1) g.bar.foo = \'1337\'; // oops
}
// x.y.z instance of t
@ -43,13 +43,13 @@ function z(b) { return b ? new Z1 : new Z2; }
function consumer5(b) {
var g = z(b);
if (g.baz.bar instanceof X2) g.baz.bar.foo = '1337';
if (g.baz.bar instanceof X2) g.baz.bar.foo = \'1337\';
else g.baz.bar.foo = 1337;
}
function consumer6(b) {
var g = z(b);
if (g.baz.bar instanceof X1) g.baz.bar.foo = '1337'; // oops
if (g.baz.bar instanceof X1) g.baz.bar.foo = \'1337\'; // oops
}
// this instanceof t
@ -58,7 +58,7 @@ class C {
if (this instanceof D)
alert(this.s);
else
alert("nope");
alert(\"nope\");
}
}
@ -66,7 +66,7 @@ class D extends C {
s: string;
constructor() {
super();
this.s = "yup";
this.s = \"yup\";
}
}
@ -109,14 +109,14 @@ function x(b) {
function consumer1(b) {
var g = x(b);
if (g instanceof X2)
g.foo = "1337";
g.foo = \"1337\";
else
g.foo = [object Number];
g.foo = 1337;
}
function consumer2(b) {
var g = x(b);
if (g instanceof X1)
g.foo = "1337";
g.foo = \"1337\";
}
class Y1 {
bar: X1;
@ -130,14 +130,14 @@ function y(b) {
function consumer3(b) {
var g = y(b);
if (g.bar instanceof X2)
g.bar.foo = "1337";
g.bar.foo = \"1337\";
else
g.bar.foo = [object Number];
g.bar.foo = 1337;
}
function consumer4(b) {
var g = y(b);
if (g.bar instanceof X1)
g.bar.foo = "1337";
g.bar.foo = \"1337\";
}
class Z1 {
baz: Y1;
@ -151,33 +151,33 @@ function z(b) {
function consumer5(b) {
var g = z(b);
if (g.baz.bar instanceof X2)
g.baz.bar.foo = "1337";
g.baz.bar.foo = \"1337\";
else
g.baz.bar.foo = [object Number];
g.baz.bar.foo = 1337;
}
function consumer6(b) {
var g = z(b);
if (g.baz.bar instanceof X1)
g.baz.bar.foo = "1337";
g.baz.bar.foo = \"1337\";
}
class C {
m() {
if (this instanceof D)
alert(this.s);
else
alert("nope");
alert(\"nope\");
}
}
class D extends C {
s: string;
constructor() {
super();
this.s = "yup";
this.s = \"yup\";
}
}
function foo0(x: Array<number> | number) {
if (x instanceof Array) {
x[[object Number]] = [object Number];
x[0] = 123;
} else {
x++;
}
@ -186,7 +186,7 @@ function foo1(x: Array<number> | number) {
if (x instanceof Array) {
x++;
} else {
x[[object Number]] = [object Number];
x[0] = 123;
}
}
"

View File

@ -0,0 +1,190 @@
exports[`test import.js 1`] = `
"interface I { x: number }
export type J = I; // workaround for export interface
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// workaround for export interface
interface I extends { x: number }
export type J = I;
"
`;
exports[`test indexer.js 1`] = `
"// @flow
interface Ok {
[key: string]: string;
}
interface Bad {
[k1: string]: string;
[k2: number]: number; // error: not supported (yet)
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// @flow
/* error: not supported (yet)*/
interface Ok extends { [key: string]: string }
interface Bad extends { [k1: string]: string, [k2: number]: number }
"
`;
exports[`test interface.js 1`] = `
"declare class C { x: number; }
var x: string = new C().x;
interface I { x: number; }
var i = new I(); // error
function testInterfaceName(o: I) {
(o.name: string); // error, name is static
(o.constructor.name: string); // ok
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// error
// error, name is static
// ok
declare class C { x: number }
var x: string = new C().x;
interface I extends { x: number }
var i = new I();
function testInterfaceName(o: I) {
(o.name: string);
(o.constructor.name: string);
}
"
`;
exports[`test test.js 1`] = `
"interface I { y: string }
interface I_ { x: number }
interface J extends I, I_ { }
interface K extends J { }
var k: K = { x: \"\", y: \"\" }; // error: x should be number
(k.x: string); // error: x is number
(k.y: string);
declare class C { x: number }
declare class D extends C, Other { } // error: multiple extends
//declare class E implements I { } // parse error
interface A<Y> { y: Y }
interface A_<X> { x: X }
interface B<Z> extends A<string>, A_<Z> { z: Z }
interface E<Z> extends B<Z> { }
var e: E<number> = { x: \"\", y: \"\", z: \"\" }; // error: x and z should be numbers
(e.x: string); // error: x is number
(e.y: string);
(e.z: string); // error: z is number
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// error: x should be number
// error: x is number
// error: multiple extends
//declare class E implements I { } // parse error
// error: x and z should be numbers
// error: x is number
// error: z is number
interface I extends { y: string }
interface I_ extends { x: number }
interface J extends I, I_ {}
interface K extends J {}
var k: K = { x: \"\", y: \"\" };
(k.x: string);
(k.y: string);
declare class C { x: number }
declare class D {}
interface A<Y> extends { y: Y }
interface A_<X> extends { x: X }
interface B<Z> extends A<string>, A_<Z> { z: Z }
interface E<Z> extends B<Z> {}
var e: E<number> = { x: \"\", y: \"\", z: \"\" };
(e.x: string);
(e.y: string);
(e.z: string);
"
`;
exports[`test test2.js 1`] = `
"import type { J } from \'./import\';
interface K { }
interface L extends J, K { y: string }
function foo(l: L) { l.x; l.y; l.z; } // error: z not found in L
// interface + multiple inheritance is similar to object type + intersection
type M = { y: string } & J & { z: boolean }
function bar(m: M) { m.x; m.y; m.z; } // OK
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// error: z not found in L
// interface + multiple inheritance is similar to object type + intersection
// OK
import type { J } from \"./import\";
interface K extends {}
interface L extends J, K { y: string }
function foo(l: L) {
l.x;
l.y;
l.z;
}
type M = { y: string } & J & { z: boolean };
function bar(m: M) {
m.x;
m.y;
m.z;
}
"
`;
exports[`test test3.js 1`] = `
"interface I { x: number, y : string }
interface J { y : number }
interface K extends I, J { x: string } // error: x is number in I
function foo(k: K) {
(k.x: number); // error: x is string in K
(k.y: number); // error: y is string in I
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// error: x is number in I
// error: x is string in K
// error: y is string in I
interface I extends { x: number, y: string }
interface J extends { y: number }
interface K extends I, J { x: string }
function foo(k: K) {
(k.x: number);
(k.y: number);
}
"
`;
exports[`test test4.js 1`] = `
"interface I { foo(x: number): void; }
(function foo(x: number) { }: I); // error, property \`foo\` not found function
declare class C {
bar(i: I): void;
bar(f: (x: number) => void): void;
}
new C().bar((x: string) => { }); // error, number ~/~> string
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// error, property \`foo\` not found function
// error, number ~/~> string
interface I extends { foo: : (x: number) => void }
(function foo(x: number) {
}: I);
declare class C {
bar: : (i: I) => void,
bar: : (f: (x: number) => void) => void
}
new C().bar(
(x: string) => {
}
);
"
`;

View File

@ -0,0 +1,214 @@
exports[`test intersection.js 1`] = `
"function foo(x: $All<Error,{type:number}>): number {
return x.type;
}
function bar(x: Error & {type:number}): number {
return x.type;
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function foo(x: $All<Error, { type: number }>): number {
return x.type;
}
function bar(x: Error & { type: number }): number {
return x.type;
}
"
`;
exports[`test objassign.js 1`] = `
"/**
* Test intersection of objects flowing to spread assignment.
*
* Definitions in lib/lib.js
*
* @noflow
*/
declare var x: ObjAssignT;
let y: ObjAssignT = { ...x }; // should be fine
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/**
* Test intersection of objects flowing to spread assignment.
*
* Definitions in lib/lib.js
*
* @noflow
*/
// should be fine
declare var x: ObjAssignT;
let y: ObjAssignT = { ...x };
"
`;
exports[`test pred.js 1`] = `
"/**
* Test interaction of object intersections and predicates.
* Definitions in lib/lib.js
*
* @flow
*/
type DuplexStreamOptions = ReadableStreamOptions & WritableStreamOptions & {
allowHalfOpen? : boolean,
readableObjectMode? : boolean,
writableObjectMode? : boolean
};
function hasObjectMode_bad(options: DuplexStreamOptions): boolean {
return options.objectMode
|| options.readableObjectMode
|| options.writableObjectMode; // error, undefined ~> boolean
}
function hasObjectMode_ok(options: DuplexStreamOptions): boolean {
return !!(options.objectMode
|| options.readableObjectMode
|| options.writableObjectMode);
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/**
* Test interaction of object intersections and predicates.
* Definitions in lib/lib.js
*
* @flow
*/
// error, undefined ~> boolean
type DuplexStreamOptions = ReadableStreamOptions & WritableStreamOptions & {
allowHalfOpen?: boolean,
readableObjectMode?: boolean,
writableObjectMode?: boolean
};
function hasObjectMode_bad(options: DuplexStreamOptions): boolean {
return options.objectMode || options.readableObjectMode ||
options.writableObjectMode;
}
function hasObjectMode_ok(options: DuplexStreamOptions): boolean {
return !!(options.objectMode || options.readableObjectMode ||
options.writableObjectMode);
}
"
`;
exports[`test test_fun.js 1`] = `
"/**
* Tests for intersections of function types.
*
* Note: Flow abuses intersection types to model
* function overloading, which precludes using a
* correct intersection of return types in the result.
*
* Here we test the special case where return types
* are equal. Tests of the overloading behavior can
* be found in tests/overload
*
* Definitions lin lib/lib.js
*
* @noflow
*/
// intersection of function types satisfies union of param types
type F = (_: ObjA) => void;
type G = (_: ObjB) => void;
type FG = (_: ObjA | ObjB) => void;
declare var fun1 : F & G;
(fun1 : FG);
var fun2 : FG = fun1;
// simpler variation
declare var f : ((_: number) => void) & ((_: string) => void);
var g: (_: number | string) => void = f;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/**
* Tests for intersections of function types.
*
* Note: Flow abuses intersection types to model
* function overloading, which precludes using a
* correct intersection of return types in the result.
*
* Here we test the special case where return types
* are equal. Tests of the overloading behavior can
* be found in tests/overload
*
* Definitions lin lib/lib.js
*
* @noflow
*/
// intersection of function types satisfies union of param types
// simpler variation
type F = : (_: ObjA) => void;
type G = : (_: ObjB) => void;
type FG = : (_: ObjA | ObjB) => void;
declare var fun1: F & G;
(fun1: FG);
var fun2: FG = fun1;
declare var f: : (_: number) => void & : (_: string) => void;
var g: (_: number | string) => void = f;
"
`;
exports[`test test_obj.js 1`] = `
"/**
* Tests for intersections of object types
*
* @noflow
*/
// TODO we should give explicit errors for incompatibilities
// which make an intersection uninhabitable:
// - shared mutable properties with different types
// - different dictionary types
//
// Currently we give no such errors. Instead, we rely on
// the impossibility of providing a value for such a type
// to produce errors on value inflows. This is clearly
// suboptimal, since eg declared vars require no explicit
// provision of values. This leaves the impossible types
// free to flow downstream and satisfy impossible constraints.
// intersection of object types satisfies union of properties
declare var a: A;
var b: B = a;
// intersection of dictionary types:
declare var c: C;
var d: D = c; // ok
// dict type mismatch
type E = { [key: string]: string };
var e: E = c; // error
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/**
* Tests for intersections of object types
*
* @noflow
*/
// TODO we should give explicit errors for incompatibilities
// which make an intersection uninhabitable:
// - shared mutable properties with different types
// - different dictionary types
//
// Currently we give no such errors. Instead, we rely on
// the impossibility of providing a value for such a type
// to produce errors on value inflows. This is clearly
// suboptimal, since eg declared vars require no explicit
// provision of values. This leaves the impossible types
// free to flow downstream and satisfy impossible constraints.
// intersection of object types satisfies union of properties
// intersection of dictionary types:
// ok
// dict type mismatch
// error
declare var a: A;
var b: B = a;
declare var c: C;
var d: D = c;
type E = { [key: string]: string };
var e: E = c;
"
`;

View File

@ -0,0 +1,65 @@
exports[`test lib.js 1`] = `
"// @flow
// defs used in tests, here to stress tvar machinery
// used in ObjAssign.js
//
type ObjAssignT = { foo: string } & { bar: string };
// used in pred.js
//
type ReadableStreamOptions = {
highWaterMark? : number,
encoding? : ?string,
objectMode? : boolean
};
type WritableStreamOptions = {
highWaterMark? : number,
decodeString? : boolean,
objectMode? : boolean
};
// used in test_fun.js
//
type ObjA = { foo: number, bar: string };
type ObjB = { baz: bool };
// used in test_obj.js
//
type A = { a: string } & { b: string };
type B = { a: string, b: string };
type C = { [key: string]: number } & { [key: string]: number };
type D = { [key: string]: number };
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// @flow
// defs used in tests, here to stress tvar machinery
// used in ObjAssign.js
//
// used in pred.js
//
// used in test_fun.js
//
// used in test_obj.js
//
type ObjAssignT = { foo: string } & { bar: string };
type ReadableStreamOptions = {
highWaterMark?: number,
encoding?: ?string,
objectMode?: boolean
};
type WritableStreamOptions = {
highWaterMark?: number,
decodeString?: boolean,
objectMode?: boolean
};
type ObjA = { foo: number, bar: string };
type ObjB = { baz: boolean };
type A = { a: string } & { b: string };
type B = { a: string, b: string };
type C = { [key: string]: number } & { [key: string]: number };
type D = { [key: string]: number };
"
`;

View File

@ -1,22 +1,22 @@
exports[`test export.js 1`] = `
"/* @flow */
exports.x = 1;
exports.y = "";
exports.y = \"\";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/* @flow */
exports.x = [object Number];
exports.y = "";
exports.x = 1;
exports.y = \"\";
"
`;
exports[`test import.js 1`] = `
"/* @flow */
var e = require('./export');
var e = require(\'./export\');
var x: string = e.x;
var y: number = e.y;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/* @flow */
var e = require("./export");
var e = require(\"./export\");
var x: string = e.x;
var y: number = e.y;
"

View File

@ -6,7 +6,7 @@ for (var i=0;i<3;i++) {
foo(a[i]);
}
for (var k in a) {
foo(a[k]); // k is a string, which shouldn't be used for array access
foo(a[k]); // k is a string, which shouldn\'t be used for array access
}
var b = (null : ?{[key: string]: string});
@ -21,7 +21,7 @@ for (var m in (c = b)) {
var d;
for (var n in (d = a)) {
foo(d[n]); // d is a string, which shouldn't be used for array access
foo(d[n]); // d is a string, which shouldn\'t be used for array access
}
for (var x in undefined) {
@ -33,27 +33,27 @@ for (var x in null) {
}
for (var y in this) {
// regression test to make sure \`in this\` doesn't fatal. it's currently
// allowed, even though we can't actually enumerate all the keys on \`this\`.
// regression test to make sure \`in this\` doesn\'t fatal. it\'s currently
// allowed, even though we can\'t actually enumerate all the keys on \`this\`.
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// k is a string, which shouldn't be used for array access
// d is a string, which shouldn't be used for array access
// k is a string, which shouldn\'t be used for array access
// d is a string, which shouldn\'t be used for array access
// unreachable
// unreachable
// regression test to make sure \`in this\` doesn't fatal. it's currently
// allowed, even though we can't actually enumerate all the keys on \`this\`.
var a = [ [object Boolean], [object Boolean] ];
// regression test to make sure \`in this\` doesn\'t fatal. it\'s currently
// allowed, even though we can\'t actually enumerate all the keys on \`this\`.
var a = [ true, false ];
function foo(x) {
}
for (var i = [object Number]; i < [object Number]; i++) {
for (var i = 0; i < 3; i++) {
foo(a[i]);
}
for (var k in a) {
foo(a[k]);
}
var b = ([object Null]: ?{ [key: string]: string });
var b = (null: ?{ [key: string]: string });
for (var j in b) {
foo(b[j]);
}
@ -68,7 +68,7 @@ for (var n in d = a) {
for (var x in undefined) {
foo(x);
}
for (var x in [object Null]) {
for (var x in null) {
foo(x);
}
for (var y in this) {

View File

@ -2,33 +2,22 @@ exports[`test array.js 1`] = `
"/* @flow */
var arrayTest1: Iterable<number> = ([1, 2]: Array<number>);
var arrayTest2: Iterable<number | string> = [1,2,"hi"];
var arrayTest2: Iterable<number | string> = [1,2,\"hi\"];
var arrayTest3: Iterable<*> = [1,2,3];
// Error string ~> number
var arrayTest4: Iterable<number> = ["hi"];
var arrayTest4: Iterable<number> = [\"hi\"];
// Error string ~> number
var arrayTest5: Iterable<string> = ["hi", 1];
var arrayTest5: Iterable<string> = [\"hi\", 1];
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/* @flow */
// Error string ~> number
// Error string ~> number
var arrayTest1: Iterable<number> = ([
[object Number],
[object Number]
]: Array<number>);
var arrayTest2: Iterable<number | string> = [
[object Number],
[object Number],
"hi"
];
var arrayTest3: Iterable<*> = [
[object Number],
[object Number],
[object Number]
];
var arrayTest4: Iterable<number> = [ "hi" ];
var arrayTest5: Iterable<string> = [ "hi", [object Number] ];
var arrayTest1: Iterable<number> = ([ 1, 2 ]: Array<number>);
var arrayTest2: Iterable<number | string> = [ 1, 2, \"hi\" ];
var arrayTest3: Iterable<*> = [ 1, 2, 3 ];
var arrayTest4: Iterable<number> = [ \"hi\" ];
var arrayTest5: Iterable<string> = [ \"hi\", 1 ];
"
`;
@ -36,17 +25,17 @@ exports[`test caching_bug.js 1`] = `
"/* @flow */
/**
* I've hit a bug with the caching in flow_js.ml. Avik is removing that caching
* I\'ve hit a bug with the caching in flow_js.ml. Avik is removing that caching
* so it should be fixed soon. The basic idea is I flow something like
*
* Array<any | any> ~> Iterable<string>
*
* then Flow won't notice when I try to flow
* then Flow won\'t notice when I try to flow
*
* Array<string | number> ~> Iterable<string>
*
* We shouldn't hit the cache because the union types are different, but we do
* anyway. I've fixed this temporarily by bumping the "meaningful" param to
* We shouldn\'t hit the cache because the union types are different, but we do
* anyway. I\'ve fixed this temporarily by bumping the \"meaningful\" param to
* Hashtbl.hash_param
*/
@ -57,17 +46,17 @@ function miss_the_cache(x: Array<string | number>): Iterable<string> { return x;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/* @flow */
/**
* I've hit a bug with the caching in flow_js.ml. Avik is removing that caching
* I\'ve hit a bug with the caching in flow_js.ml. Avik is removing that caching
* so it should be fixed soon. The basic idea is I flow something like
*
* Array<any | any> ~> Iterable<string>
*
* then Flow won't notice when I try to flow
* then Flow won\'t notice when I try to flow
*
* Array<string | number> ~> Iterable<string>
*
* We shouldn't hit the cache because the union types are different, but we do
* anyway. I've fixed this temporarily by bumping the "meaningful" param to
* We shouldn\'t hit the cache because the union types are different, but we do
* anyway. I\'ve fixed this temporarily by bumping the \"meaningful\" param to
* Hashtbl.hash_param
*/
// Error: number ~> string
@ -109,11 +98,11 @@ exports[`test iterator_result.js 1`] = `
function makeIterator(coin_flip: () => boolean ): Iterator<string> {
return {
"@@iterator"() { return makeIterator(coin_flip); },
\"@@iterator\"() { return makeIterator(coin_flip); },
next(): IteratorResult<string, void> {
var done = coin_flip();
if (!done) {
return { done, value: "still going..." };
return { done, value: \"still going...\" };
} else {
return { done };
}
@ -123,11 +112,11 @@ function makeIterator(coin_flip: () => boolean ): Iterator<string> {
function makeIterator(coin_flip: () => boolean ): Iterator<string> {
return {
"@@iterator"() { return makeIterator(coin_flip); },
\"@@iterator\"() { return makeIterator(coin_flip); },
next(): IteratorResult<string, void> {
var done = coin_flip();
if (done) { // Whoops, made a mistake and forgot to negate done
return { done, value: "still going..." }; // Error string ~> void
return { done, value: \"still going...\" }; // Error string ~> void
} else {
return { done }; // Error void ~> string
}
@ -141,13 +130,13 @@ function makeIterator(coin_flip: () => boolean ): Iterator<string> {
// Error void ~> string
function makeIterator(coin_flip: () => boolean): Iterator<string> {
return {
"@@iterator"() {
\"@@iterator\"() {
return makeIterator(coin_flip);
},
next(): IteratorResult<string, void> {
var done = coin_flip();
if (!done) {
return { done, value: "still going..." };
return { done, value: \"still going...\" };
} else {
return { done };
}
@ -156,13 +145,13 @@ function makeIterator(coin_flip: () => boolean): Iterator<string> {
}
function makeIterator(coin_flip: () => boolean): Iterator<string> {
return {
"@@iterator"() {
\"@@iterator\"() {
return makeIterator(coin_flip);
},
next(): IteratorResult<string, void> {
var done = coin_flip();
if (done) {
return { done, value: "still going..." };
return { done, value: \"still going...\" };
} else {
return { done };
}
@ -191,10 +180,10 @@ function mapTest4(map: Map<number, string>): Iterable<string> {
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/* @flow */
// Error - Map is an Iterable<[K, V]>
function mapTest1(map: Map<string, number>): Iterable<[]> {
function mapTest1(map: Map<string, number>): Iterable<[stringnumber]> {
return map;
}
function mapTest2<K, V>(map: Map<K, V>): Iterable<[]> {
function mapTest2<K, V>(map: Map<K, V>): Iterable<[KV]> {
return map;
}
function mapTest3(map: Map<string, number>): Iterable<*> {
@ -243,15 +232,15 @@ function setTest4(set: Set<string>): Iterable<number> {
exports[`test string.js 1`] = `
"/* @flow */
var stringTest1: Iterable<string> = "hi";
var stringTest3: Iterable<*> = "hi";
var stringTest3: Iterable<number> = "hi"; // Error - string is a Iterable<string>
var stringTest1: Iterable<string> = \"hi\";
var stringTest3: Iterable<*> = \"hi\";
var stringTest3: Iterable<number> = \"hi\"; // Error - string is a Iterable<string>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/* @flow */
// Error - string is a Iterable<string>
var stringTest1: Iterable<string> = "hi";
var stringTest3: Iterable<*> = "hi";
var stringTest3: Iterable<number> = "hi";
var stringTest1: Iterable<string> = \"hi\";
var stringTest3: Iterable<*> = \"hi\";
var stringTest3: Iterable<number> = \"hi\";
"
`;

View File

@ -1,7 +1,7 @@
exports[`test main.js 1`] = `
"// @flow
var React = require('react');
var React = require(\'react\');
class CustomComponent extends React.Component {
props: {
@ -9,56 +9,56 @@ class CustomComponent extends React.Component {
};
}
var a: React.Element<{prop: string}> = <CustomComponent prop="asdf" />;
var b: React.Element<{prop1: string}> = <CustomComponent prop="asdf" />; // Error: Props<{prop}> ~> Props<{prop1}>
var a: React.Element<{prop: string}> = <CustomComponent prop=\"asdf\" />;
var b: React.Element<{prop1: string}> = <CustomComponent prop=\"asdf\" />; // Error: Props<{prop}> ~> Props<{prop1}>
// Since intrinsics are typed as \`any\` out of the box, we can pass any
// attributes to intrinsics!
var c: React.Element<any> = <div not_a_real_attr="asdf" />;
// However, we don't allow such elements to be viewed as React elements with
var c: React.Element<any> = <div not_a_real_attr=\"asdf\" />;
// However, we don\'t allow such elements to be viewed as React elements with
// different attributes.
var d: React.Element<{doesntmatch: string}> = <div not_a_real_attr="asdf" />;
var d: React.Element<{doesntmatch: string}> = <div not_a_real_attr=\"asdf\" />;
// No error as long as expectations are consistent, though.
var e: React.Element<{not_a_real_attr: string}> = <div not_a_real_attr="asdf" />;
var e: React.Element<{not_a_real_attr: string}> = <div not_a_real_attr=\"asdf\" />;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// @flow
// Error: Props<{prop}> ~> Props<{prop1}>
// Since intrinsics are typed as \`any\` out of the box, we can pass any
// attributes to intrinsics!
// However, we don't allow such elements to be viewed as React elements with
// However, we don\'t allow such elements to be viewed as React elements with
// different attributes.
// No error as long as expectations are consistent, though.
var React = require("react");
var React = require(\"react\");
class CustomComponent extends React.Component {
props: { prop: string };
}
var a: React.Element<{ prop: string }> = <CustomComponent prop="asdf"/>;
var b: React.Element<{ prop1: string }> = <CustomComponent prop="asdf"/>;
var c: React.Element<any> = <div not_a_real_attr="asdf"/>;
var d: React.Element<{ doesntmatch: string }> = <div not_a_real_attr="asdf"/>;
var a: React.Element<{ prop: string }> = <CustomComponent prop=\"asdf\"/>;
var b: React.Element<{ prop1: string }> = <CustomComponent prop=\"asdf\"/>;
var c: React.Element<any> = <div not_a_real_attr=\"asdf\"/>;
var d: React.Element<{ doesntmatch: string }> = <div not_a_real_attr=\"asdf\"/>;
var e: React.Element<{
not_a_real_attr: string
}> = <div not_a_real_attr="asdf"/>;
}> = <div not_a_real_attr=\"asdf\"/>;
"
`;
exports[`test strings.js 1`] = `
"/* @flow */
var React = require('react');
var React = require(\'react\');
// The builtin $JSXIntrinsics should allow any string
var Div = 'div';
var Bad = 'bad';
var Str: string = 'str';
var Div = \'div\';
var Bad = \'bad\';
var Str: string = \'str\';
<Div />; // This is fine
<Bad />; // This is fine
<Str />; // This is fine
React.createElement('div', {}); // This is fine
React.createElement('bad', {}); // This is fine
React.createElement(\'div\', {}); // This is fine
React.createElement(\'bad\', {}); // This is fine
<Div id={42} />; // This is fine
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ -70,15 +70,15 @@ React.createElement('bad', {}); // This is fine
// This is fine
/* This is fine*/
// This is fine
var React = require("react");
var Div = "div";
var Bad = "bad";
var Str: string = "str";
var React = require(\"react\");
var Div = \"div\";
var Bad = \"bad\";
var Str: string = \"str\";
<Div/>;
<Bad/>;
<Str/>;
React.createElement("div", {});
React.createElement("bad", {});
<Div id={[object Number]}/>;
React.createElement(\"div\", {});
React.createElement(\"bad\", {});
<Div id={42}/>;
"
`;

View File

@ -1,7 +1,7 @@
exports[`test main.js 1`] = `
"// @flow
var React = require('react');
var React = require(\'react\');
class CustomComponent extends React.Component {
props: {
@ -9,46 +9,46 @@ class CustomComponent extends React.Component {
};
}
var a: React.Element<{prop: string}> = <CustomComponent prop="asdf" />;
var b: React.Element<{prop1: string}> = <CustomComponent prop="asdf" />; // Error: Props<{prop}> ~> Props<{prop1}>
var a: React.Element<{prop: string}> = <CustomComponent prop=\"asdf\" />;
var b: React.Element<{prop1: string}> = <CustomComponent prop=\"asdf\" />; // Error: Props<{prop}> ~> Props<{prop1}>
<div id="asdf" />;
<div id=\"asdf\" />;
<div id={42} />; // Error: (\`id\` prop) number ~> string
var c: React.Element<{id: string}> = <div id="asdf" />;
var d: React.Element<{id: number}> = <div id="asdf" />; // Error: Props<{id:string}> ~> Props<{id:number}>
var c: React.Element<{id: string}> = <div id=\"asdf\" />;
var d: React.Element<{id: number}> = <div id=\"asdf\" />; // Error: Props<{id:string}> ~> Props<{id:number}>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// @flow
/* Error: Props<{prop}> ~> Props<{prop1}>*/
// Error: (\`id\` prop) number ~> string
// Error: Props<{id:string}> ~> Props<{id:number}>
var React = require("react");
var React = require(\"react\");
class CustomComponent extends React.Component {
props: { prop: string };
}
var a: React.Element<{ prop: string }> = <CustomComponent prop="asdf"/>;
var b: React.Element<{ prop1: string }> = <CustomComponent prop="asdf"/>;
<div id="asdf"/>;
<div id={[object Number]}/>;
var c: React.Element<{ id: string }> = <div id="asdf"/>;
var d: React.Element<{ id: number }> = <div id="asdf"/>;
var a: React.Element<{ prop: string }> = <CustomComponent prop=\"asdf\"/>;
var b: React.Element<{ prop1: string }> = <CustomComponent prop=\"asdf\"/>;
<div id=\"asdf\"/>;
<div id={42}/>;
var c: React.Element<{ id: string }> = <div id=\"asdf\"/>;
var d: React.Element<{ id: number }> = <div id=\"asdf\"/>;
"
`;
exports[`test strings.js 1`] = `
"/* @flow */
var React = require('react');
var React = require(\'react\');
var Div = 'div';
var Bad = 'bad';
var Str: string = 'str';
var Div = \'div\';
var Bad = \'bad\';
var Str: string = \'str\';
<Div />; // This is fine
<Bad />; // Error: 'bad' not in JSXIntrinsics
<Bad />; // Error: \'bad\' not in JSXIntrinsics
<Str />; // Error: string ~> keys of JSXIntrinsics
React.createElement('div', {}); // This is fine
React.createElement('bad', {}); // Error: 'bad' not in JSXIntrinsics
React.createElement(\'div\', {}); // This is fine
React.createElement(\'bad\', {}); // Error: \'bad\' not in JSXIntrinsics
React.createElement(Str, {}); // Error: string ~> keys of JSXIntrinsics
// TODO: Make this an error
@ -56,23 +56,23 @@ React.createElement(Str, {}); // Error: string ~> keys of JSXIntrinsics
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/* @flow */
/* This is fine*/
/* Error: 'bad' not in JSXIntrinsics*/
/* Error: \'bad\' not in JSXIntrinsics*/
// Error: string ~> keys of JSXIntrinsics
// This is fine
// Error: 'bad' not in JSXIntrinsics
// Error: \'bad\' not in JSXIntrinsics
/* Error: string ~> keys of JSXIntrinsics*/
/* TODO: Make this an error*/
// Not an error but should be eventually
var React = require("react");
var Div = "div";
var Bad = "bad";
var Str: string = "str";
var React = require(\"react\");
var Div = \"div\";
var Bad = \"bad\";
var Str: string = \"str\";
<Div/>;
<Bad/>;
<Str/>;
React.createElement("div", {});
React.createElement("bad", {});
React.createElement(\"div\", {});
React.createElement(\"bad\", {});
React.createElement(Str, {});
<Div id={[object Number]}/>;
<Div id={42}/>;
"
`;

View File

@ -1,46 +1,46 @@
exports[`test keys.js 1`] = `
"/* @flow */
function testKeysOfObject(str: string, lit: 'hi') {
function testKeysOfObject(str: string, lit: \'hi\') {
(str: $Keys<Object>); // Any string should be fine
if (str) {
(str: $Keys<Object>); // No error, truthy string should be fine
}
('hi': $Keys<Object>); // String literal should be fine
(\'hi\': $Keys<Object>); // String literal should be fine
(123: $Keys<Object>); // Error: number -> keys of Object
}
type StrDict = {[key: string]: mixed};
function testKeysOfStrDict(str: string, lit: 'hi') {
function testKeysOfStrDict(str: string, lit: \'hi\') {
(str: $Keys<StrDict>); // Any string should be fine
if (str) {
(str: $Keys<StrDict>); // No error, truthy string should be fine
}
('hi': $Keys<StrDict>); // String literal should be fine
(\'hi\': $Keys<StrDict>); // String literal should be fine
(123: $Keys<StrDict>); // Error: number -> keys of StrDict
}
type StrLitDict = {[key: 'hi']: mixed};
function testKeysOfStrLitDict(str: string, lit: 'hi') {
type StrLitDict = {[key: \'hi\']: mixed};
function testKeysOfStrLitDict(str: string, lit: \'hi\') {
(str: $Keys<StrLitDict>); // Error: Not all strings are allowed
if (str) {
(str: $Keys<StrLitDict>); // Error: Not all truthy strings are allowed
}
('hi': $Keys<StrLitDict>); // The right string literal is allowed
('bye': $Keys<StrLitDict>); // Error: The wrong string literal is not allowed
(\'hi\': $Keys<StrLitDict>); // The right string literal is allowed
(\'bye\': $Keys<StrLitDict>); // Error: The wrong string literal is not allowed
(123: $Keys<StrLitDict>); // Error: number -> keys of StrLitDict
}
type ObjLit = {hi: mixed};
function testKeysOfOtherObj(str: string, lit: 'hi') {
function testKeysOfOtherObj(str: string, lit: \'hi\') {
(str: $Keys<ObjLit>); // Error: string -> keys of ObjLit
if (str) {
(str: $Keys<ObjLit>); // Error: truthy string -> keys of ObjLit
}
('hi': $Keys<ObjLit>); // String literal should be fine
(\'hi\': $Keys<ObjLit>); // String literal should be fine
(123: $Keys<ObjLit>); // Error: number -> keys of ObjLit
}
@ -63,41 +63,41 @@ function testKeysOfOtherObj(str: string, lit: 'hi') {
// Error: truthy string -> keys of ObjLit
// String literal should be fine
// Error: number -> keys of ObjLit
function testKeysOfObject(str: string, lit: "hi") {
function testKeysOfObject(str: string, lit: \"hi\") {
(str: $Keys<Object>);
if (str) {
(str: $Keys<Object>);
}
("hi": $Keys<Object>);
([object Number]: $Keys<Object>);
(\"hi\": $Keys<Object>);
(123: $Keys<Object>);
}
type StrDict = { [key: string]: mixed };
function testKeysOfStrDict(str: string, lit: "hi") {
function testKeysOfStrDict(str: string, lit: \"hi\") {
(str: $Keys<StrDict>);
if (str) {
(str: $Keys<StrDict>);
}
("hi": $Keys<StrDict>);
([object Number]: $Keys<StrDict>);
(\"hi\": $Keys<StrDict>);
(123: $Keys<StrDict>);
}
type StrLitDict = { [key: "hi"]: mixed };
function testKeysOfStrLitDict(str: string, lit: "hi") {
type StrLitDict = { [key: \"hi\"]: mixed };
function testKeysOfStrLitDict(str: string, lit: \"hi\") {
(str: $Keys<StrLitDict>);
if (str) {
(str: $Keys<StrLitDict>);
}
("hi": $Keys<StrLitDict>);
("bye": $Keys<StrLitDict>);
([object Number]: $Keys<StrLitDict>);
(\"hi\": $Keys<StrLitDict>);
(\"bye\": $Keys<StrLitDict>);
(123: $Keys<StrLitDict>);
}
type ObjLit = { hi: mixed };
function testKeysOfOtherObj(str: string, lit: "hi") {
function testKeysOfOtherObj(str: string, lit: \"hi\") {
(str: $Keys<ObjLit>);
if (str) {
(str: $Keys<ObjLit>);
}
("hi": $Keys<ObjLit>);
([object Number]: $Keys<ObjLit>);
(\"hi\": $Keys<ObjLit>);
(123: $Keys<ObjLit>);
}
"
`;

View File

@ -5,13 +5,13 @@ exports[`test test.js 1`] = `
class C {
foo(): number { return 0; }
foo(): string { return "hello" } // last wins
foo(): string { return \"hello\" } // last wins
x: number;
x: string; // last wins
bar(): number { return 0; }
bar: string; // field wins over method
qux: number;
qux(): string { return "hello" } // method loses to field!
qux(): string { return \"hello\" } // method loses to field!
}
// check
@ -19,19 +19,19 @@ class C {
((new C).foo(): boolean); // last wins
((new C).x: boolean); // last wins
((new C).bar: boolean); // last wins
((new C).qux: boolean); // weird outlier where last doesn't win in classes
((new C).qux: boolean); // weird outlier where last doesn\'t win in classes
// Objects
const o = {
foo(): number { return 0; },
foo(): string { return "hello" }, // last wins
foo(): string { return \"hello\" }, // last wins
x: 42,
x: "hello", // last wins
x: \"hello\", // last wins
bar(): number { return 0; },
bar: "hello", // last wins
bar: \"hello\", // last wins
qux: 42,
qux(): string { return "hello" }, // last wins
qux(): string { return \"hello\" }, // last wins
};
// check
@ -51,7 +51,7 @@ const o = {
// last wins
// last wins
// last wins
// weird outlier where last doesn't win in classes
// weird outlier where last doesn\'t win in classes
// Objects
// last wins
// last wins
@ -64,20 +64,20 @@ const o = {
// last wins
class C {
foo(): number {
return [object Number];
return 0;
}
foo(): string {
return "hello";
return \"hello\";
}
x: number;
x: string;
bar(): number {
return [object Number];
return 0;
}
bar: string;
qux: number;
qux(): string {
return "hello";
return \"hello\";
}
}
(new C().foo(): boolean);
@ -86,20 +86,20 @@ class C {
(new C().qux: boolean);
const o = {
foo(): number {
return [object Number];
return 0;
},
foo(): string {
return "hello";
return \"hello\";
},
x: [object Number],
x: "hello",
x: 42,
x: \"hello\",
bar(): number {
return [object Number];
return 0;
},
bar: "hello",
qux: [object Number],
bar: \"hello\",
qux: 42,
qux(): string {
return "hello";
return \"hello\";
}
};
(o.foo(): boolean);

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