feat: 支持自增自减运算符

This commit is contained in:
2026-06-06 20:31:57 +08:00
parent 8c3f4aabe6
commit 69e2c2eba1
7 changed files with 226 additions and 3 deletions
+21 -1
View File
@@ -1,4 +1,4 @@
use oxide_parser::{Expression, ForStatementInit, Statement};
use oxide_parser::{Expression, ForStatementInit, SimpleAssignmentTarget, Statement};
pub fn structural_hash(program: &oxide_parser::Program) -> u64 {
use std::hash::Hasher;
@@ -160,6 +160,26 @@ fn hash_expression(expr: &Expression, h: &mut rustc_hash::FxHasher) {
std::mem::discriminant(&assign.operator).hash(h);
hash_expression(&assign.right, h);
}
Expression::UpdateExpression(update) => {
12u8.hash(h);
std::mem::discriminant(&update.operator).hash(h);
update.prefix.hash(h);
match &update.argument {
SimpleAssignmentTarget::AssignmentTargetIdentifier(_) => {
0u8.hash(h);
}
SimpleAssignmentTarget::StaticMemberExpression(member) => {
1u8.hash(h);
hash_expression(&member.object, h);
}
SimpleAssignmentTarget::ComputedMemberExpression(member) => {
2u8.hash(h);
hash_expression(&member.object, h);
hash_expression(&member.expression, h);
}
_ => {}
}
}
_ => {
std::mem::discriminant(expr).hash(h);
}