feat: rest 参数(function f(...args)),实参区收集数组

This commit is contained in:
爱特每羊队
2026-08-10 00:33:25 +08:00
parent 9b2a56c1fa
commit da586082cc
10 changed files with 184 additions and 8 deletions
+6 -5
View File
@@ -12,11 +12,6 @@ impl Emitter {
fn emit_arrow_function_expression(
&self, arrow: &oxide_parser::ArrowFunctionExpression, ctx: &mut CompileCtx,
) -> Result<u32, String> {
// 未支持:箭头函数 rest 参数
if let Some(_rest) = &arrow.params.rest {
return Err("rest params in arrow functions not yet supported".into());
}
// 提取形参名(与函数表达式相同的形态)
let mut param_names = Vec::new();
for (idx, param) in arrow.params.items.iter().enumerate() {
@@ -36,6 +31,9 @@ impl Emitter {
}
}
}
if let Some(rest) = &arrow.params.rest {
self.push_rest_param(&rest.rest.argument, &mut param_names)?;
}
// 表达式体:以 is_expression_body=true 编译;语句体:以 false 编译。
let body_stmts = &arrow.body.statements;
@@ -77,6 +75,9 @@ impl Emitter {
}
}
}
if let Some(rest) = &fe.params.rest {
self.push_rest_param(&rest.rest.argument, &mut param_names)?;
}
let body_stmts: &[Statement] = if let Some(body) = &fe.body { &body.statements } else { &[] };