- This brings in the flow test suite that contains a ton of JavaScript parsing edge cases - This creates snapshot tests using the pretty printer for all of them - If uncomment `RUN_AST_TESTS` line in `tests/run_specs.js`, it checks ast(pretty_print(x)) == ast(x). Right now, "178 failed, 197 passed, 375 of 377 total". So half of the tests are not passing, most of them are crashes and many of the rest are subtle issues.
81 lines
1.3 KiB
JavaScript
81 lines
1.3 KiB
JavaScript
/***
|
|
* Test tracking of variable types across closure calls.
|
|
* @flow
|
|
*/
|
|
|
|
function takes_string(_:string) { }
|
|
|
|
// global write from function
|
|
//
|
|
|
|
var global_x = "hello";
|
|
|
|
function global_f() { }
|
|
function global_g() { global_x = 42; }
|
|
|
|
global_f();
|
|
takes_string(global_x); // ok
|
|
|
|
global_g();
|
|
takes_string(global_x); // error
|
|
|
|
global_x = 42; // shouldn't pollute linear refinement
|
|
|
|
// local write from function
|
|
//
|
|
|
|
function local_func() {
|
|
|
|
var local_x = "hello";
|
|
|
|
function local_f() { }
|
|
function local_g() { local_x = 42; }
|
|
|
|
local_f();
|
|
takes_string(local_x); // ok
|
|
|
|
local_g();
|
|
takes_string(local_x); // error
|
|
|
|
local_x = 42; // shouldn't pollute linear refinement
|
|
}
|
|
|
|
// global write from method
|
|
//
|
|
|
|
var global_y = "hello";
|
|
|
|
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
|
|
|
|
global_y = 42; // shouldn't pollute linear refinement
|
|
|
|
// local write from method
|
|
//
|
|
|
|
function local_meth() {
|
|
|
|
var local_y = "hello";
|
|
|
|
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
|
|
|
|
local_y = 42; // shouldn't pollute linear refinement
|
|
}
|