feat: 调用实参 spread(f(...args) / new F(...args) / super(...args))

This commit is contained in:
爱特每羊队
2026-08-08 10:33:16 +08:00
parent ea86a2c0ac
commit 2777b00c82
14 changed files with 811 additions and 140 deletions
+12 -9
View File
@@ -135,17 +135,13 @@ impl Emitter {
Expression::CallExpression(call) => {
self.pre_scan_builtin_expr(&call.callee, ctx);
for arg in &call.arguments {
if let Some(e) = arg.as_expression() {
self.pre_scan_builtin_expr(e, ctx);
}
self.pre_scan_builtin_arg(arg, ctx);
}
}
Expression::NewExpression(ne) => {
self.pre_scan_builtin_expr(&ne.callee, ctx);
for arg in &ne.arguments {
if let Some(e) = arg.as_expression() {
self.pre_scan_builtin_expr(e, ctx);
}
self.pre_scan_builtin_arg(arg, ctx);
}
}
Expression::LogicalExpression(log) => {
@@ -254,15 +250,22 @@ impl Emitter {
oxide_parser::ChainElement::CallExpression(call) => {
self.pre_scan_builtin_expr(&call.callee, ctx);
for arg in &call.arguments {
if let Some(e) = arg.as_expression() {
self.pre_scan_builtin_expr(e, ctx);
}
self.pre_scan_builtin_arg(arg, ctx);
}
}
_ => {}
}
}
/// 遍历调用实参:spread 内部表达式也纳入 builtin 预扫描。
fn pre_scan_builtin_arg(&self, arg: &oxide_parser::Argument, ctx: &mut CompileCtx) {
if let Some(e) = arg.as_expression() {
self.pre_scan_builtin_expr(e, ctx);
} else if let oxide_parser::Argument::SpreadElement(sp) = arg {
self.pre_scan_builtin_expr(&sp.argument, ctx);
}
}
pub(crate) fn predeclare_function_declarations(&self, statements: &[Statement], ctx: &mut CompileCtx) {
for statement in statements {
let Statement::FunctionDeclaration(function) = statement else {