diff --git a/src/lib.rs b/src/lib.rs index 433f18c..1bfba2f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -265,6 +265,32 @@ fn evaluate_cel_internal(expression: &str, context: &JsValue) -> Result Result { + // Compile the CEL expression + let program = Program::compile(expression) + .map_err(|e| JsValue::from_str(&format!("Compilation error: {}", e)))?; + + // Get references using the references() method + let references = program.references(); + + // Convert to JS array + let js_array = js_sys::Array::new(); + + // Convert each reference to a JsValue and push it to the JS array + for reference in references.variables().iter() { + js_array.push(&JsValue::from_str(reference)); + } + + // Also add function references if available + for function in references.functions().iter() { + js_array.push(&JsValue::from_str(&format!("function:{}", function))); + } + + Ok(js_array) +} + /// Initialize the WASM module (optional, for debugging) #[wasm_bindgen(start)] pub fn main() {