Simplify let/const statement.
This commit is contained in:
parent
1f74b36496
commit
630ec51624
@ -1780,36 +1780,23 @@ impl Engine {
|
|||||||
|
|
||||||
Stmt::ReturnWithVal(_) => unreachable!(),
|
Stmt::ReturnWithVal(_) => unreachable!(),
|
||||||
|
|
||||||
// Let statement
|
// Let/const statement
|
||||||
Stmt::Let(x) if x.1.is_some() => {
|
Stmt::Let(x) | Stmt::Const(x) => {
|
||||||
let ((var_name, _), expr, _) = x.as_ref();
|
let ((var_name, _), expr, _) = x.as_ref();
|
||||||
let expr = expr.as_ref().unwrap();
|
let entry_type = match stmt {
|
||||||
let val = self
|
Stmt::Let(_) => ScopeEntryType::Normal,
|
||||||
.eval_expr(scope, mods, state, lib, this_ptr, expr, level)?
|
Stmt::Const(_) => ScopeEntryType::Constant,
|
||||||
.flatten();
|
_ => unreachable!(),
|
||||||
let var_name = unsafe_cast_var_name_to_lifetime(var_name, &state);
|
};
|
||||||
scope.push_dynamic_value(var_name, ScopeEntryType::Normal, val, false);
|
|
||||||
Ok(Default::default())
|
|
||||||
}
|
|
||||||
|
|
||||||
Stmt::Let(x) => {
|
let val = if let Some(expr) = expr {
|
||||||
let ((var_name, _), _, _) = x.as_ref();
|
self.eval_expr(scope, mods, state, lib, this_ptr, expr, level)?
|
||||||
let var_name = unsafe_cast_var_name_to_lifetime(var_name, &state);
|
.flatten()
|
||||||
scope.push(var_name, ());
|
|
||||||
Ok(Default::default())
|
|
||||||
}
|
|
||||||
|
|
||||||
// Const statement
|
|
||||||
Stmt::Const(x) => {
|
|
||||||
let ((var_name, _), expr, _) = x.as_ref();
|
|
||||||
let val = if let Some(expr) = expr { self
|
|
||||||
.eval_expr(scope, mods, state, lib, this_ptr, expr, level)?
|
|
||||||
.flatten()
|
|
||||||
} else {
|
} else {
|
||||||
().into()
|
().into()
|
||||||
};
|
};
|
||||||
let var_name = unsafe_cast_var_name_to_lifetime(var_name, &state);
|
let var_name = unsafe_cast_var_name_to_lifetime(var_name, &state);
|
||||||
scope.push_dynamic_value(var_name, ScopeEntryType::Constant, val, true);
|
scope.push_dynamic_value(var_name, entry_type, val, false);
|
||||||
Ok(Default::default())
|
Ok(Default::default())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user