mirror of
https://github.com/pjh456/OxideJS.git
synced 2026-10-24 10:41:11 +08:00
b32d525141
- emit_program_module:模块顶层编译(is_global_scope=false,顶层 this undefined 由 VM 按标志绑定) - emit_module_into_ctx:预声明/闭包分析识别 export 包裹声明与 import 绑定 - 依赖收集:import/re-export/star 的 source 去重、循环检测、json/text 数据模块 - 导入绑定初始化:__moduleLinkGet 链接期检查;self-import 别名语义(export 处回写) - export 域:声明/重导出/export */export default 就地注册命名空间 - re-export 链接检查移至 prelude(先于 body 求值) - emit_module_call 参数打包连续寄存器(CALL_NATIVE 契约) - CompileCtx 增 module_ns_reg/module_dep_ns_regs/self-import 映射 - 拆分 declaration helper(export 声明复用);function/class 表达式 emitter 提升可见性
39 lines
1.5 KiB
Rust
39 lines
1.5 KiB
Rust
//! 类声明语句 emit:`emit_class_declaration_statement` 声明类名并初始化类对象。
|
||
|
||
use crate::{CompileCtx, Emitter};
|
||
use oxide_parser::{Statement, VariableDeclarationKind};
|
||
|
||
impl Emitter {
|
||
pub(crate) fn emit_class_declaration_statement(
|
||
&self, stmt: &Statement, ctx: &mut CompileCtx,
|
||
) -> Result<Option<u32>, String> {
|
||
let Statement::ClassDeclaration(class) = stmt else {
|
||
return Err("ClassDeclaration without name".into());
|
||
};
|
||
self.emit_class_declaration(class, ctx)
|
||
}
|
||
|
||
/// 类声明本体:供 export 声明复用(导出声明先按普通声明 emit,再就地注册导出值)。
|
||
pub(crate) fn emit_class_declaration(
|
||
&self, class: &oxide_parser::Class, ctx: &mut CompileCtx,
|
||
) -> Result<Option<u32>, String> {
|
||
let name = class
|
||
.id
|
||
.as_ref()
|
||
.map(|id| id.name.to_string())
|
||
.ok_or_else(|| "ClassDeclaration without name".to_string())?;
|
||
let var_reg = match ctx.scopes.symbols.consume_predeclared_slot(&name) {
|
||
Some(reg) => reg,
|
||
None => {
|
||
let reg = ctx.alloc_reg();
|
||
ctx.declare(&name, reg, VariableDeclarationKind::Let, false)?;
|
||
reg
|
||
}
|
||
};
|
||
// 类名绑定在 emit_class_with_binding 内于 extends 求值后初始化:
|
||
// 先声明未初始化绑定(TDZ),extends 引用类名按规范抛 ReferenceError。
|
||
self.emit_class_with_binding(class, ctx, Some(var_reg))?;
|
||
Ok(None)
|
||
}
|
||
}
|