fix(emit): 修复 clippy 阻塞(doc comment 空行 + single_match_else)
This commit is contained in:
@@ -14,57 +14,54 @@ impl Emitter {
|
|||||||
ctx: &mut CompileCtx,
|
ctx: &mut CompileCtx,
|
||||||
) -> Result<(), String> {
|
) -> Result<(), String> {
|
||||||
for element in elements {
|
for element in elements {
|
||||||
match element {
|
if let ClassElement::MethodDefinition(method) = element {
|
||||||
ClassElement::MethodDefinition(method) => {
|
let method = method.as_ref();
|
||||||
let method = method.as_ref();
|
if method.kind == MethodDefinitionKind::Constructor {
|
||||||
if method.kind == MethodDefinitionKind::Constructor {
|
continue;
|
||||||
continue;
|
}
|
||||||
}
|
if matches!(method.key, PropertyKey::PrivateIdentifier(_)) {
|
||||||
if matches!(method.key, PropertyKey::PrivateIdentifier(_)) {
|
let home_reg = if method.r#static { ctor_reg } else { proto_reg };
|
||||||
let home_reg = if method.r#static { ctor_reg } else { proto_reg };
|
self.emit_private_method_init(Operand::Reg(home_reg as u32), method, Operand::Reg(home_reg as u32), ctx)?;
|
||||||
self.emit_private_method_init(Operand::Reg(home_reg as u32), method, Operand::Reg(home_reg as u32), ctx)?;
|
continue;
|
||||||
continue;
|
}
|
||||||
}
|
let home_reg = if method.r#static { ctor_reg } else { proto_reg };
|
||||||
let home_reg = if method.r#static { ctor_reg } else { proto_reg };
|
let key_reg = self.emit_class_key_reg(&method.key, method.computed, ctx)?;
|
||||||
let key_reg = self.emit_class_key_reg(&method.key, method.computed, ctx)?;
|
let method_name = if method.computed {
|
||||||
let method_name = if method.computed {
|
"<computed>".to_string()
|
||||||
"<computed>".to_string()
|
} else {
|
||||||
} else {
|
self.class_property_name(&method.key)?
|
||||||
self.class_property_name(&method.key)?
|
};
|
||||||
};
|
let accessor_reg =
|
||||||
let accessor_reg =
|
self.emit_class_method_function(method, &method_name, Operand::Reg(home_reg as u32), ctx, self_binding)?;
|
||||||
self.emit_class_method_function(method, &method_name, Operand::Reg(home_reg as u32), ctx, self_binding)?;
|
match method.kind {
|
||||||
match method.kind {
|
MethodDefinitionKind::Method => {
|
||||||
MethodDefinitionKind::Method => {
|
if method.computed {
|
||||||
if method.computed {
|
ctx.inst(Inst::new(OpCode::SET_PROP_DYNAMIC, Operand::Reg(home_reg as u32), Operand::Reg(key_reg as u32), Operand::Reg(accessor_reg as u32)));
|
||||||
ctx.inst(Inst::new(OpCode::SET_PROP_DYNAMIC, Operand::Reg(home_reg as u32), Operand::Reg(key_reg as u32), Operand::Reg(accessor_reg as u32)));
|
} else {
|
||||||
} else {
|
ctx.inst(Inst::new(OpCode::SET_PROP, Operand::Reg(home_reg as u32), Operand::Reg(accessor_reg as u32), Operand::Reg(key_reg as u32)));
|
||||||
ctx.inst(Inst::new(OpCode::SET_PROP, Operand::Reg(home_reg as u32), Operand::Reg(accessor_reg as u32), Operand::Reg(key_reg as u32)));
|
}
|
||||||
}
|
}
|
||||||
}
|
MethodDefinitionKind::Get | MethodDefinitionKind::Set => {
|
||||||
MethodDefinitionKind::Get | MethodDefinitionKind::Set => {
|
if method.computed {
|
||||||
if method.computed {
|
return Err("computed class accessors not yet supported".into());
|
||||||
return Err("computed class accessors not yet supported".into());
|
}
|
||||||
}
|
let undef_reg = self.emit_undefined(ctx);
|
||||||
let undef_reg = self.emit_undefined(ctx);
|
let (get_reg, set_reg) = if method.kind == MethodDefinitionKind::Get {
|
||||||
let (get_reg, set_reg) = if method.kind == MethodDefinitionKind::Get {
|
(accessor_reg, undef_reg)
|
||||||
(accessor_reg, undef_reg)
|
} else {
|
||||||
} else {
|
(undef_reg, accessor_reg)
|
||||||
(undef_reg, accessor_reg)
|
};
|
||||||
};
|
let key_name = self.class_property_name(&method.key)?;
|
||||||
let key_name = self.class_property_name(&method.key)?;
|
let key_idx = ctx.add_constant(Constant::String(key_name));
|
||||||
let key_idx = ctx.add_constant(Constant::String(key_name));
|
ctx.inst(Inst::define_accessor(
|
||||||
ctx.inst(Inst::define_accessor(
|
Operand::Reg(home_reg as u32),
|
||||||
Operand::Reg(home_reg as u32),
|
Operand::Reg(get_reg as u32),
|
||||||
Operand::Reg(get_reg as u32),
|
Operand::Reg(set_reg as u32),
|
||||||
Operand::Reg(set_reg as u32),
|
key_idx as u32,
|
||||||
key_idx as u32,
|
));
|
||||||
));
|
}
|
||||||
}
|
MethodDefinitionKind::Constructor => continue,
|
||||||
MethodDefinitionKind::Constructor => continue,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -542,8 +542,6 @@ impl Emitter {
|
|||||||
// ── 闭包捕获分析(AST 级,时序无关)──
|
// ── 闭包捕获分析(AST 级,时序无关)──
|
||||||
|
|
||||||
/// 收集函数参数的绑定名(BindingIdentifier 形态)。
|
/// 收集函数参数的绑定名(BindingIdentifier 形态)。
|
||||||
|
|
||||||
|
|
||||||
pub(crate) fn extract_function_parts<'a>(
|
pub(crate) fn extract_function_parts<'a>(
|
||||||
&self, function: &'a oxide_parser::Function<'a>,
|
&self, function: &'a oxide_parser::Function<'a>,
|
||||||
) -> Result<(Vec<ParamSpec<'a>>, &'a [Statement<'a>]), String> {
|
) -> Result<(Vec<ParamSpec<'a>>, &'a [Statement<'a>]), String> {
|
||||||
|
|||||||
Reference in New Issue
Block a user