From 42503bdc78cc8e2f8bd6c446e01a7ab9dec7ca79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20H=C3=B6lting?= <87192362+moritz-hoelting@users.noreply.github.com> Date: Sat, 6 Apr 2024 12:47:15 +0200 Subject: [PATCH] Always transpile function when annotated with tick or load --- src/transpile/transpiler.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/transpile/transpiler.rs b/src/transpile/transpiler.rs index baa5df5..2acb6bd 100644 --- a/src/transpile/transpiler.rs +++ b/src/transpile/transpiler.rs @@ -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)]