fix: 重写闭包捕获分析为 AST 级,修复 MAKE_CELL 时序

This commit is contained in:
2026-08-05 18:41:48 +08:00
parent 0028a1787e
commit 179960ed75
8 changed files with 506 additions and 318 deletions
@@ -366,6 +366,24 @@ fn compile_closure_capture_emits_upvalue_load() {
);
}
#[test]
fn compile_closure_capture_emits_make_cell_for_captured_var() {
let module = compile_source("function outer() { var x = 1; return function() { return x; }; }");
assert!(
has_opcode(&module, OpCode::MAKE_CELL),
"captured outer var should emit MAKE_CELL so the inner closure can read it"
);
}
#[test]
fn compile_closure_capture_arrow_emits_make_cell() {
let module = compile_source("function outer() { let x = 1; return () => x; }");
assert!(
has_opcode(&module, OpCode::MAKE_CELL),
"captured let in arrow closure should emit MAKE_CELL"
);
}
#[test]
fn compile_compound_assignment_complement_ops() {
let module = compile_source("let x = 10; x -= 1; x *= 2; x /= 3; x %= 4;");