2017-02-22 00:59:19 +03:00
|
|
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
|
|
|
2018-11-25 11:21:14 +03:00
|
|
|
exports[`Closure.js 1`] = `
|
|
|
|
====================================options=====================================
|
|
|
|
parsers: ["flow"]
|
|
|
|
printWidth: 80
|
|
|
|
| printWidth
|
|
|
|
=====================================input======================================
|
2017-04-12 23:41:51 +03:00
|
|
|
/***
|
2016-12-23 22:31:38 +03:00
|
|
|
* Test tracking of variable types across closure calls.
|
|
|
|
* @flow
|
|
|
|
*/
|
|
|
|
|
|
|
|
function takes_string(_:string) { }
|
|
|
|
|
|
|
|
// global write from function
|
|
|
|
//
|
|
|
|
|
2017-04-12 23:41:51 +03:00
|
|
|
var global_x = "hello";
|
2016-12-23 22:31:38 +03:00
|
|
|
|
|
|
|
function global_f() { }
|
|
|
|
function global_g() { global_x = 42; }
|
|
|
|
|
|
|
|
global_f();
|
|
|
|
takes_string(global_x); // ok
|
|
|
|
|
|
|
|
global_g();
|
|
|
|
takes_string(global_x); // error
|
|
|
|
|
2017-02-22 00:59:19 +03:00
|
|
|
global_x = 42; // shouldn't pollute linear refinement
|
2016-12-23 22:31:38 +03:00
|
|
|
|
|
|
|
// local write from function
|
|
|
|
//
|
|
|
|
|
|
|
|
function local_func() {
|
|
|
|
|
2017-04-12 23:41:51 +03:00
|
|
|
var local_x = "hello";
|
2016-12-23 22:31:38 +03:00
|
|
|
|
|
|
|
function local_f() { }
|
|
|
|
function local_g() { local_x = 42; }
|
|
|
|
|
|
|
|
local_f();
|
|
|
|
takes_string(local_x); // ok
|
|
|
|
|
|
|
|
local_g();
|
|
|
|
takes_string(local_x); // error
|
|
|
|
|
2017-02-22 00:59:19 +03:00
|
|
|
local_x = 42; // shouldn't pollute linear refinement
|
2016-12-23 22:31:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// global write from method
|
|
|
|
//
|
|
|
|
|
2017-04-12 23:41:51 +03:00
|
|
|
var global_y = "hello";
|
2016-12-23 22:31:38 +03:00
|
|
|
|
|
|
|
var global_o = {
|
|
|
|
f: function() { },
|
|
|
|
g: function() { global_y = 42; }
|
|
|
|
}
|
|
|
|
|
|
|
|
global_o.f();
|
|
|
|
takes_string(global_y); // ok
|
|
|
|
|
|
|
|
global_o.g();
|
|
|
|
takes_string(global_y); // error
|
|
|
|
|
2017-02-22 00:59:19 +03:00
|
|
|
global_y = 42; // shouldn't pollute linear refinement
|
2016-12-23 22:31:38 +03:00
|
|
|
|
|
|
|
// local write from method
|
|
|
|
//
|
|
|
|
|
|
|
|
function local_meth() {
|
|
|
|
|
2017-04-12 23:41:51 +03:00
|
|
|
var local_y = "hello";
|
2016-12-23 22:31:38 +03:00
|
|
|
|
|
|
|
var local_o = {
|
|
|
|
f: function() { },
|
|
|
|
g: function() { local_y = 42; }
|
|
|
|
}
|
|
|
|
|
|
|
|
local_o.f();
|
|
|
|
takes_string(local_y); // ok
|
|
|
|
|
|
|
|
local_o.g();
|
|
|
|
takes_string(local_y); // error
|
|
|
|
|
2017-02-22 00:59:19 +03:00
|
|
|
local_y = 42; // shouldn't pollute linear refinement
|
2016-12-23 22:31:38 +03:00
|
|
|
}
|
2018-11-25 11:21:14 +03:00
|
|
|
|
|
|
|
=====================================output=====================================
|
2016-12-23 22:31:38 +03:00
|
|
|
/***
|
|
|
|
* Test tracking of variable types across closure calls.
|
|
|
|
* @flow
|
|
|
|
*/
|
2017-01-10 05:49:06 +03:00
|
|
|
|
2017-01-24 20:37:01 +03:00
|
|
|
function takes_string(_: string) {}
|
2017-01-10 05:49:06 +03:00
|
|
|
|
2016-12-27 21:29:31 +03:00
|
|
|
// global write from function
|
|
|
|
//
|
2017-01-27 22:05:41 +03:00
|
|
|
|
2017-04-12 23:41:51 +03:00
|
|
|
var global_x = "hello";
|
2017-01-10 05:49:06 +03:00
|
|
|
|
2017-01-24 20:37:01 +03:00
|
|
|
function global_f() {}
|
2016-12-23 22:31:38 +03:00
|
|
|
function global_g() {
|
2016-12-28 05:40:04 +03:00
|
|
|
global_x = 42;
|
2016-12-23 22:31:38 +03:00
|
|
|
}
|
2017-01-10 05:49:06 +03:00
|
|
|
|
2016-12-23 22:31:38 +03:00
|
|
|
global_f();
|
2017-01-26 22:57:43 +03:00
|
|
|
takes_string(global_x); // ok
|
2017-01-31 19:27:44 +03:00
|
|
|
|
2016-12-23 22:31:38 +03:00
|
|
|
global_g();
|
2017-01-26 22:57:43 +03:00
|
|
|
takes_string(global_x); // error
|
2017-01-31 19:27:44 +03:00
|
|
|
|
2017-02-22 00:59:19 +03:00
|
|
|
global_x = 42; // shouldn't pollute linear refinement
|
2017-01-31 19:27:44 +03:00
|
|
|
|
2017-01-10 05:49:06 +03:00
|
|
|
// local write from function
|
|
|
|
//
|
2017-01-27 22:05:41 +03:00
|
|
|
|
2016-12-23 22:31:38 +03:00
|
|
|
function local_func() {
|
2017-04-12 23:41:51 +03:00
|
|
|
var local_x = "hello";
|
2017-01-10 05:49:06 +03:00
|
|
|
|
2017-01-24 20:37:01 +03:00
|
|
|
function local_f() {}
|
2016-12-23 22:31:38 +03:00
|
|
|
function local_g() {
|
2016-12-28 05:40:04 +03:00
|
|
|
local_x = 42;
|
2016-12-23 22:31:38 +03:00
|
|
|
}
|
2017-01-10 05:49:06 +03:00
|
|
|
|
2016-12-23 22:31:38 +03:00
|
|
|
local_f();
|
2017-01-26 22:57:43 +03:00
|
|
|
takes_string(local_x); // ok
|
2017-01-31 19:27:44 +03:00
|
|
|
|
2016-12-23 22:31:38 +03:00
|
|
|
local_g();
|
2017-01-26 22:57:43 +03:00
|
|
|
takes_string(local_x); // error
|
2017-01-31 19:27:44 +03:00
|
|
|
|
2017-02-22 00:59:19 +03:00
|
|
|
local_x = 42; // shouldn't pollute linear refinement
|
2016-12-23 22:31:38 +03:00
|
|
|
}
|
2017-01-10 05:49:06 +03:00
|
|
|
|
|
|
|
// global write from method
|
|
|
|
//
|
2017-01-27 22:05:41 +03:00
|
|
|
|
2017-04-12 23:41:51 +03:00
|
|
|
var global_y = "hello";
|
2017-01-10 05:49:06 +03:00
|
|
|
|
2016-12-23 22:31:38 +03:00
|
|
|
var global_o = {
|
2017-01-24 20:37:01 +03:00
|
|
|
f: function() {},
|
2016-12-23 22:31:38 +03:00
|
|
|
g: function() {
|
2016-12-28 05:40:04 +03:00
|
|
|
global_y = 42;
|
2016-12-23 22:31:38 +03:00
|
|
|
}
|
|
|
|
};
|
2017-01-10 05:49:06 +03:00
|
|
|
|
2016-12-23 22:31:38 +03:00
|
|
|
global_o.f();
|
2017-01-26 22:57:43 +03:00
|
|
|
takes_string(global_y); // ok
|
2017-01-31 19:27:44 +03:00
|
|
|
|
2016-12-23 22:31:38 +03:00
|
|
|
global_o.g();
|
2017-01-26 22:57:43 +03:00
|
|
|
takes_string(global_y); // error
|
2017-01-31 19:27:44 +03:00
|
|
|
|
2017-02-22 00:59:19 +03:00
|
|
|
global_y = 42; // shouldn't pollute linear refinement
|
2017-01-31 19:27:44 +03:00
|
|
|
|
2017-01-10 05:49:06 +03:00
|
|
|
// local write from method
|
|
|
|
//
|
2017-01-27 22:05:41 +03:00
|
|
|
|
2016-12-23 22:31:38 +03:00
|
|
|
function local_meth() {
|
2017-04-12 23:41:51 +03:00
|
|
|
var local_y = "hello";
|
2017-01-10 05:49:06 +03:00
|
|
|
|
2016-12-23 22:31:38 +03:00
|
|
|
var local_o = {
|
2017-01-24 20:37:01 +03:00
|
|
|
f: function() {},
|
2016-12-23 22:31:38 +03:00
|
|
|
g: function() {
|
2016-12-28 05:40:04 +03:00
|
|
|
local_y = 42;
|
2016-12-23 22:31:38 +03:00
|
|
|
}
|
|
|
|
};
|
2017-01-10 05:49:06 +03:00
|
|
|
|
2016-12-23 22:31:38 +03:00
|
|
|
local_o.f();
|
2017-01-26 22:57:43 +03:00
|
|
|
takes_string(local_y); // ok
|
2017-01-31 19:27:44 +03:00
|
|
|
|
2016-12-23 22:31:38 +03:00
|
|
|
local_o.g();
|
2017-01-26 22:57:43 +03:00
|
|
|
takes_string(local_y); // error
|
2017-01-31 19:27:44 +03:00
|
|
|
|
2017-02-22 00:59:19 +03:00
|
|
|
local_y = 42; // shouldn't pollute linear refinement
|
2017-01-11 18:16:38 +03:00
|
|
|
}
|
2017-04-12 23:41:51 +03:00
|
|
|
|
2018-11-25 11:21:14 +03:00
|
|
|
================================================================================
|
2016-12-23 22:31:38 +03:00
|
|
|
`;
|
|
|
|
|
2018-11-25 11:21:14 +03:00
|
|
|
exports[`cond_havoc.js 1`] = `
|
|
|
|
====================================options=====================================
|
|
|
|
parsers: ["flow"]
|
|
|
|
printWidth: 80
|
|
|
|
| printWidth
|
|
|
|
=====================================input======================================
|
2017-04-12 23:41:51 +03:00
|
|
|
// @flow
|
2016-12-23 22:31:38 +03:00
|
|
|
|
|
|
|
// from sam, https://github.com/facebook/flow/issues/780
|
|
|
|
// call to f() within if should properly havoc x.
|
|
|
|
//
|
|
|
|
function example(b: bool): number {
|
|
|
|
var x = 0;
|
2017-04-12 23:41:51 +03:00
|
|
|
function f() { x = "" }
|
2016-12-23 22:31:38 +03:00
|
|
|
if (b) {
|
|
|
|
f();
|
|
|
|
}
|
|
|
|
return x; // error, string ~/~> number (return type anno) TODO
|
|
|
|
}
|
2018-11-25 11:21:14 +03:00
|
|
|
|
|
|
|
=====================================output=====================================
|
2016-12-23 22:31:38 +03:00
|
|
|
// @flow
|
2017-01-10 05:49:06 +03:00
|
|
|
|
2016-12-23 22:31:38 +03:00
|
|
|
// from sam, https://github.com/facebook/flow/issues/780
|
|
|
|
// call to f() within if should properly havoc x.
|
|
|
|
//
|
|
|
|
function example(b: boolean): number {
|
2016-12-28 05:40:04 +03:00
|
|
|
var x = 0;
|
2016-12-23 22:31:38 +03:00
|
|
|
function f() {
|
2017-04-12 23:41:51 +03:00
|
|
|
x = "";
|
2016-12-23 22:31:38 +03:00
|
|
|
}
|
|
|
|
if (b) {
|
|
|
|
f();
|
|
|
|
}
|
2017-01-10 05:49:06 +03:00
|
|
|
return x; // error, string ~/~> number (return type anno) TODO
|
2017-01-11 18:16:38 +03:00
|
|
|
}
|
2017-04-12 23:41:51 +03:00
|
|
|
|
2018-11-25 11:21:14 +03:00
|
|
|
================================================================================
|
2016-12-23 22:31:38 +03:00
|
|
|
`;
|
|
|
|
|
2018-11-25 11:21:14 +03:00
|
|
|
exports[`const.js 1`] = `
|
|
|
|
====================================options=====================================
|
|
|
|
parsers: ["flow"]
|
|
|
|
printWidth: 80
|
|
|
|
| printWidth
|
|
|
|
=====================================input======================================
|
2017-04-12 23:41:51 +03:00
|
|
|
/***
|
2016-12-23 22:31:38 +03:00
|
|
|
* consts retain refinements
|
|
|
|
* @flow
|
|
|
|
*/
|
|
|
|
|
|
|
|
// global, anybody can call it at any time
|
|
|
|
var call_me: () => void = () => {};
|
|
|
|
|
|
|
|
function g(x: ?number) {
|
|
|
|
|
|
|
|
const const_x = x;
|
|
|
|
if (const_x) {
|
2017-02-22 00:59:19 +03:00
|
|
|
// ok: if const_x is truthy here, it's truthy everywhere
|
2016-12-23 22:31:38 +03:00
|
|
|
call_me = () => { var y:number = const_x; };
|
|
|
|
}
|
|
|
|
|
|
|
|
var var_x = x;
|
|
|
|
if (var_x) {
|
|
|
|
// error: var_x might no longer be truthy when call_me is called
|
|
|
|
call_me = () => { var y:number = var_x; }; // error
|
|
|
|
}
|
|
|
|
var_x = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
function h(x: number | string | boolean) {
|
|
|
|
|
|
|
|
const const_x = x;
|
2017-04-12 23:41:51 +03:00
|
|
|
if (typeof(const_x) == "number") {
|
2016-12-23 22:31:38 +03:00
|
|
|
call_me = () => { var y:number = const_x; }; // ok
|
2017-04-12 23:41:51 +03:00
|
|
|
} else if (typeof(const_x) == "string") {
|
2016-12-23 22:31:38 +03:00
|
|
|
call_me = () => { var y:string = const_x; }; // ok
|
2017-04-12 23:41:51 +03:00
|
|
|
} else if (typeof(const_x) == "boolean") {
|
2016-12-23 22:31:38 +03:00
|
|
|
call_me = () => { var y:boolean = const_x; }; // ok
|
|
|
|
}
|
|
|
|
|
|
|
|
var var_x = x;
|
2017-04-12 23:41:51 +03:00
|
|
|
if (typeof(var_x) == "number") {
|
2016-12-23 22:31:38 +03:00
|
|
|
call_me = () => { var y:number = var_x; }; // error
|
2017-04-12 23:41:51 +03:00
|
|
|
} else if (typeof(var_x) == "string") {
|
2016-12-23 22:31:38 +03:00
|
|
|
call_me = () => { var y:string = var_x; }; // error
|
2017-04-12 23:41:51 +03:00
|
|
|
} else if (typeof(var_x) == "boolean") {
|
2016-12-23 22:31:38 +03:00
|
|
|
call_me = () => { var y:boolean = var_x; }; // error
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// in a galaxy far far away
|
|
|
|
call_me();
|
2018-11-25 11:21:14 +03:00
|
|
|
|
|
|
|
=====================================output=====================================
|
2016-12-27 21:29:31 +03:00
|
|
|
/***
|
|
|
|
* consts retain refinements
|
|
|
|
* @flow
|
|
|
|
*/
|
2017-01-10 05:49:06 +03:00
|
|
|
|
2016-12-27 21:29:31 +03:00
|
|
|
// global, anybody can call it at any time
|
2017-01-24 20:37:01 +03:00
|
|
|
var call_me: () => void = () => {};
|
2017-01-10 05:49:06 +03:00
|
|
|
|
2016-12-27 21:29:31 +03:00
|
|
|
function g(x: ?number) {
|
|
|
|
const const_x = x;
|
|
|
|
if (const_x) {
|
2017-02-22 00:59:19 +03:00
|
|
|
// ok: if const_x is truthy here, it's truthy everywhere
|
2016-12-27 21:29:31 +03:00
|
|
|
call_me = () => {
|
|
|
|
var y: number = const_x;
|
|
|
|
};
|
|
|
|
}
|
2017-01-10 05:49:06 +03:00
|
|
|
|
2016-12-27 21:29:31 +03:00
|
|
|
var var_x = x;
|
|
|
|
if (var_x) {
|
2017-01-10 05:49:06 +03:00
|
|
|
// error: var_x might no longer be truthy when call_me is called
|
2016-12-27 21:29:31 +03:00
|
|
|
call_me = () => {
|
|
|
|
var y: number = var_x;
|
2017-01-10 05:49:06 +03:00
|
|
|
}; // error
|
2016-12-27 21:29:31 +03:00
|
|
|
}
|
2016-12-28 05:40:04 +03:00
|
|
|
var_x = null;
|
2016-12-27 21:29:31 +03:00
|
|
|
}
|
2017-01-10 05:49:06 +03:00
|
|
|
|
2016-12-27 21:29:31 +03:00
|
|
|
function h(x: number | string | boolean) {
|
|
|
|
const const_x = x;
|
2017-04-12 23:41:51 +03:00
|
|
|
if (typeof const_x == "number") {
|
2016-12-27 21:29:31 +03:00
|
|
|
call_me = () => {
|
|
|
|
var y: number = const_x;
|
2017-01-10 05:49:06 +03:00
|
|
|
}; // ok
|
2017-04-12 23:41:51 +03:00
|
|
|
} else if (typeof const_x == "string") {
|
2017-01-05 20:10:14 +03:00
|
|
|
call_me = () => {
|
|
|
|
var y: string = const_x;
|
2017-01-10 05:49:06 +03:00
|
|
|
}; // ok
|
2017-04-12 23:41:51 +03:00
|
|
|
} else if (typeof const_x == "boolean") {
|
2017-01-05 20:10:14 +03:00
|
|
|
call_me = () => {
|
|
|
|
var y: boolean = const_x;
|
2017-01-10 05:49:06 +03:00
|
|
|
}; // ok
|
2017-01-05 20:10:14 +03:00
|
|
|
}
|
2017-01-10 05:49:06 +03:00
|
|
|
|
2016-12-27 21:29:31 +03:00
|
|
|
var var_x = x;
|
2017-04-12 23:41:51 +03:00
|
|
|
if (typeof var_x == "number") {
|
2016-12-27 21:29:31 +03:00
|
|
|
call_me = () => {
|
|
|
|
var y: number = var_x;
|
2017-01-10 05:49:06 +03:00
|
|
|
}; // error
|
2017-04-12 23:41:51 +03:00
|
|
|
} else if (typeof var_x == "string") {
|
2017-01-05 20:10:14 +03:00
|
|
|
call_me = () => {
|
|
|
|
var y: string = var_x;
|
2017-01-10 05:49:06 +03:00
|
|
|
}; // error
|
2017-04-12 23:41:51 +03:00
|
|
|
} else if (typeof var_x == "boolean") {
|
2017-01-05 20:10:14 +03:00
|
|
|
call_me = () => {
|
|
|
|
var y: boolean = var_x;
|
2017-01-10 05:49:06 +03:00
|
|
|
}; // error
|
2017-01-05 20:10:14 +03:00
|
|
|
}
|
2016-12-27 21:29:31 +03:00
|
|
|
}
|
2017-01-10 05:49:06 +03:00
|
|
|
|
|
|
|
// in a galaxy far far away
|
2017-01-11 18:16:38 +03:00
|
|
|
call_me();
|
2017-04-12 23:41:51 +03:00
|
|
|
|
2018-11-25 11:21:14 +03:00
|
|
|
================================================================================
|
2016-12-23 22:31:38 +03:00
|
|
|
`;
|