fix: 顶层 var 全局属性求值前创建(声明定时语义)+ 无初始化 var 声明不再抹槽值

This commit is contained in:
2026-09-09 22:00:29 +08:00
parent bd1427b116
commit 2457f283fe
6 changed files with 115 additions and 16 deletions
@@ -14,7 +14,8 @@ fn compile_source(source: &str) -> CompiledModule {
fn compile_var_declaration() {
let module = compile_source("var x = 42;");
assert!(!module.bytecode.is_empty());
assert_eq!(module.constants[0], Constant::Int(42));
// 常量池下标不固定(声明实例化序言可能先入池 Undefined),只断言成员存在。
assert!(module.constants.contains(&Constant::Int(42)));
}
#[test]
@@ -14,7 +14,8 @@ fn compile_source(source: &str) -> CompiledModule {
fn symbol_table_declare_and_lookup() {
let module = compile_source("var x = 42;");
assert!(!module.bytecode.is_empty());
assert_eq!(module.constants[0], Constant::Int(42));
// 常量池下标不固定(声明实例化序言可能先入池 Undefined),只断言成员存在。
assert!(module.constants.contains(&Constant::Int(42)));
}
#[test]