Skip eval if statements are empty.

This commit is contained in:
Stephen Chung
2021-04-17 22:19:34 +08:00
parent 90198d5440
commit 2efe9d08a4
2 changed files with 23 additions and 10 deletions

View File

@@ -867,13 +867,18 @@ impl Engine {
return Err(ParseErrorType::WrongFnDefinition.into());
}
let statements = ast.statements();
if statements.is_empty() {
return Ok(Dynamic::UNIT);
}
// Evaluate the AST
let mut new_state: State = Default::default();
new_state.source = state.source.clone();
new_state.operations = state.operations;
let result =
self.eval_global_statements(scope, mods, &mut new_state, ast.statements(), lib, level);
self.eval_global_statements(scope, mods, &mut new_state, statements, lib, level);
state.operations = new_state.operations;