Always transpile function when annotated with tick or load

This commit is contained in:
Moritz Hölting 2024-04-06 12:47:15 +02:00
parent 62dd12cab3
commit 42503bdc78
1 changed files with 13 additions and 1 deletions

View File

@ -87,7 +87,7 @@ impl Transpiler {
)
})
.collect();
self.functions.write().unwrap().insert(
self.add_function_data(
name,
FunctionData {
namespace: "shulkerscript".to_string(),
@ -99,6 +99,18 @@ impl Transpiler {
};
}
/// Adds the given function data to the transpiler.
/// If the function has the `tick` or `load` annotation, it will be transpiled immediately.
fn add_function_data(&mut self, name: String, function: FunctionData) {
let always_transpile_function =
function.annotations.contains_key("tick") || function.annotations.contains_key("load");
let cloned_name = always_transpile_function.then(|| name.clone());
self.functions.write().unwrap().insert(name, function);
if let Some(name) = cloned_name {
self.get_or_transpile_function(&name);
};
}
/// Gets the function at the given path, or transpiles it if it hasn't been transpiled yet.
/// Returns the location of the function or None if the function does not exist.
#[allow(clippy::significant_drop_tightening)]