feat: 支持 this 语法

This commit is contained in:
爱特每羊队
2026-06-07 23:07:50 +08:00
parent 005b4659f9
commit 501a14b3af
4 changed files with 65 additions and 0 deletions
+4
View File
@@ -440,6 +440,10 @@ impl Compiler {
Expression::ParenthesizedExpression(p) => {
self.count_expression(&p.expression, ctx);
}
Expression::ThisExpression(_) => {
ctx.alloc_reg();
ctx.projected_pc += 1; // LOAD_VAR from reg 254
}
Expression::UpdateExpression(update) => match &update.argument {
SimpleAssignmentTarget::AssignmentTargetIdentifier(_) => {
ctx.alloc_reg();
+5
View File
@@ -1036,6 +1036,11 @@ impl Compiler {
ctx.emit(opcode::encode(OpCode::LOAD_VAR, result_reg, 0, 0));
Ok(result_reg)
}
Expression::ThisExpression(_) => {
let r = ctx.alloc_reg();
ctx.emit(opcode::encode(OpCode::LOAD_VAR, r, 254, 0));
Ok(r)
}
_ => Err(format!("unsupported expression type: {:?}", expr)),
}
}