diff --git a/crates/oxide_emit/src/class/emit.rs b/crates/oxide_emit/src/class/emit.rs index 2251e4f..cc6eda4 100644 --- a/crates/oxide_emit/src/class/emit.rs +++ b/crates/oxide_emit/src/class/emit.rs @@ -400,6 +400,16 @@ impl Emitter { Operand::None, )); } + // 类名被外层嵌套函数捕获时,真实名 cell 同样须初始化(类元素自引用走 + // @@class_self_* 合成 cell,二者 cell_idx 不同则各发一次)。 + if let Some(&cell_idx) = ctx.captured_bindings.get(name) { + ctx.inst(Inst::new( + OpCode::MAKE_CELL, + Operand::Reg(binding_reg), + Operand::Imm(cell_idx as u16), + Operand::None, + )); + } } if pushed_scope { diff --git a/crates/oxide_emit/src/closure.rs b/crates/oxide_emit/src/closure.rs index 601f308..a6b6f76 100644 --- a/crates/oxide_emit/src/closure.rs +++ b/crates/oxide_emit/src/closure.rs @@ -86,6 +86,13 @@ impl Emitter { out.insert(id.name.to_string()); } } + // class 名是本作用域 const 绑定:须计入 own_bindings,否则嵌套函数 + // 引用类名时捕获分析缺失 → 落符号表兜底(TDZ 误报或读父寄存器残留)。 + Statement::ClassDeclaration(cd) => { + if let Some(id) = &cd.id { + out.insert(id.name.to_string()); + } + } // import 绑定是模块作用域 const 绑定,须计入 own_bindings 供 // 嵌套函数 cell 捕获。 Statement::ImportDeclaration(imp) => {