Add null coalescing operator.

This commit is contained in:
Stephen Chung
2022-06-10 11:22:33 +08:00
parent 0f1e51b1c9
commit 8999872d62
7 changed files with 87 additions and 15 deletions

View File

@@ -464,6 +464,17 @@ impl Engine {
}
}
Expr::Coalesce(x, ..) => {
let lhs = self.eval_expr(scope, global, caches, lib, this_ptr, &x.lhs, level);
match lhs {
Ok(value) if value.is::<()>() => {
self.eval_expr(scope, global, caches, lib, this_ptr, &x.rhs, level)
}
Ok(_) | Err(_) => lhs,
}
}
Expr::Custom(custom, pos) => {
let expressions: StaticVec<_> = custom.inputs.iter().map(Into::into).collect();
// The first token acts as the custom syntax's key