fix: capture object keys and scope loop bindings
This commit is contained in:
@@ -194,6 +194,14 @@ fn eval_for_in_let_scoping() {
|
||||
assert_eq!(result, "1");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn eval_adjacent_for_of_lexical_bindings_do_not_conflict() {
|
||||
assert_eq!(
|
||||
eval("let out=0; for (const [arg, descr] of [[1, 'a']]) out += arg; for (const [arg, descr] of [[2, 'b']]) out += arg; out"),
|
||||
"3"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn eval_switch_basic_match() {
|
||||
assert_eq!(eval("var x=0;switch(2){case 1:x=10;case 2:x=20;break;default:x=30;}x"), "20");
|
||||
|
||||
@@ -92,6 +92,18 @@ fn closure_nested_expr_capture() {
|
||||
assert_eq!(result.as_double(), 2.0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn closure_captures_computed_object_key_across_caller_frame() {
|
||||
let result = eval("let key='answer'; const call=fn=>fn(); const make=()=>({[key]:42}); call(make).answer").unwrap();
|
||||
assert_eq!(result.as_int(), 42);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn closure_captures_object_spread_source_across_caller_frame() {
|
||||
let result = eval("let source={x:7}; const call=fn=>fn(); const make=()=>({...source}); call(make).x").unwrap();
|
||||
assert_eq!(result.as_int(), 7);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn for_let_per_iteration_independent() {
|
||||
let _ = eval("var fns=[]; for(let i=0;i<3;i++){ fns.push(function(){return i}); } fns[0]()+fns[1]()+fns[2]()");
|
||||
|
||||
Reference in New Issue
Block a user