diff --git a/Cargo.lock b/Cargo.lock index 24087d2db3..0316660cbb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1614,6 +1614,13 @@ dependencies = [ "serde", ] +[[package]] +name = "fastn-resolved-to-js" +version = "0.1.0" +dependencies = [ + "fastn-js", +] + [[package]] name = "fastn-update" version = "0.1.0" @@ -1732,6 +1739,7 @@ dependencies = [ "fastn-builtins", "fastn-js", "fastn-resolved", + "fastn-resolved-to-js", "format_num", "ftd-ast", "ftd-p1", diff --git a/Cargo.toml b/Cargo.toml index 46895d3f64..8d60e08b8a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,6 +11,7 @@ members = [ "fastn-lang", "fastn-package", "fastn-resolved", + "fastn-resolved-to-js", "fastn-update", "fastn-utils", "fbt", @@ -92,6 +93,7 @@ fastn-ds.path = "fastn-ds" fastn-update.path = "fastn-update" fastn-builtins.path = "fastn-builtins" fastn-resolved = { path = "fastn-resolved", version = "0.1.0" } +fastn-resolved-to-js.path = "fastn-resolved-to-js" fastn-core.path = "fastn-core" fastn-issues.path = "fastn-issues" fastn-package.path = "fastn-package" diff --git a/fastn-resolved-to-js/Cargo.toml b/fastn-resolved-to-js/Cargo.toml new file mode 100644 index 0000000000..5ceb30b96e --- /dev/null +++ b/fastn-resolved-to-js/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "fastn-resolved-to-js" +version = "0.1.0" +authors.workspace = true +edition.workspace = true +description.workspace = true +license.workspace = true +repository.workspace = true +homepage.workspace = true + +[dependencies] +fastn-js.workspace = true diff --git a/fastn-resolved-to-js/src/lib.rs b/fastn-resolved-to-js/src/lib.rs new file mode 100644 index 0000000000..9becd26b36 --- /dev/null +++ b/fastn-resolved-to-js/src/lib.rs @@ -0,0 +1,4 @@ +extern crate self as fastn_resolved_to_js; + +mod resolver; +pub use resolver::ResolverData; diff --git a/ftd/src/js/resolver.rs b/fastn-resolved-to-js/src/resolver.rs similarity index 90% rename from ftd/src/js/resolver.rs rename to fastn-resolved-to-js/src/resolver.rs index ec96610e8a..7236767b98 100644 --- a/ftd/src/js/resolver.rs +++ b/fastn-resolved-to-js/src/resolver.rs @@ -11,7 +11,7 @@ pub struct ResolverData<'a> { } impl<'a> ResolverData<'a> { - pub(crate) fn none() -> ResolverData<'a> { + pub fn none() -> ResolverData<'a> { ResolverData { component_definition_name: &None, record_definition_name: &None, @@ -24,7 +24,7 @@ impl<'a> ResolverData<'a> { } } - pub(crate) fn new_with_component_definition_name( + pub fn new_with_component_definition_name( component_definition_name: &'a Option, ) -> ResolverData<'a> { let mut rdata = ResolverData::none(); @@ -32,7 +32,7 @@ impl<'a> ResolverData<'a> { rdata } - pub(crate) fn clone_with_default_inherited_variable(&self) -> ResolverData<'a> { + pub fn clone_with_default_inherited_variable(&self) -> ResolverData<'a> { ResolverData { component_definition_name: self.component_definition_name, record_definition_name: self.record_definition_name, @@ -45,7 +45,7 @@ impl<'a> ResolverData<'a> { } } - pub(crate) fn clone_with_new_inherited_variable( + pub fn clone_with_new_inherited_variable( &self, inherited_variable_name: &'a str, ) -> ResolverData<'a> { @@ -61,7 +61,7 @@ impl<'a> ResolverData<'a> { } } - pub(crate) fn clone_with_new_component_name( + pub fn clone_with_new_component_name( &self, component_name: Option, ) -> ResolverData<'a> { @@ -77,7 +77,7 @@ impl<'a> ResolverData<'a> { } } - pub(crate) fn clone_with_new_device( + pub fn clone_with_new_device( &self, device: &'a Option, ) -> ResolverData<'a> { @@ -93,7 +93,7 @@ impl<'a> ResolverData<'a> { } } - pub(crate) fn clone_with_new_loop_alias( + pub fn clone_with_new_loop_alias( &self, loop_alias: &'a Option, loop_counter_alias: &'a Option, @@ -111,7 +111,7 @@ impl<'a> ResolverData<'a> { } } - pub(crate) fn clone_with_new_record_definition_name( + pub fn clone_with_new_record_definition_name( &self, record_definition_name: &'a Option, ) -> ResolverData<'a> { diff --git a/fastn-resolved/src/lib.rs b/fastn-resolved/src/lib.rs index dea0c22aac..f7830f198b 100644 --- a/fastn-resolved/src/lib.rs +++ b/fastn-resolved/src/lib.rs @@ -8,11 +8,11 @@ mod component; pub mod evalexpr; mod expression; mod function; -pub mod js; mod kind; mod module_thing; mod or_type; mod record; +pub mod tdoc; mod value; mod variable; mod web_component; diff --git a/fastn-resolved/src/js/mod.rs b/fastn-resolved/src/tdoc.rs similarity index 100% rename from fastn-resolved/src/js/mod.rs rename to fastn-resolved/src/tdoc.rs diff --git a/ftd/Cargo.toml b/ftd/Cargo.toml index 8f9336392d..43edb15d67 100644 --- a/ftd/Cargo.toml +++ b/ftd/Cargo.toml @@ -41,6 +41,7 @@ fastn-js.workspace = true indexmap.workspace = true fastn-resolved.workspace = true fastn-builtins.workspace = true +fastn-resolved-to-js.workspace = true [dev-dependencies] diffy.workspace = true diff --git a/ftd/src/interpreter/tdoc.rs b/ftd/src/interpreter/tdoc.rs index c2e4ce94b8..f0ecb7bb84 100644 --- a/ftd/src/interpreter/tdoc.rs +++ b/ftd/src/interpreter/tdoc.rs @@ -2217,7 +2217,7 @@ impl<'a> TDoc<'a> { } } -impl<'a> fastn_resolved::js::TDoc for TDoc<'a> { +impl<'a> fastn_resolved::tdoc::TDoc for TDoc<'a> { fn get_opt_function(&self, name: &str, line_number: usize) -> Option { let initial_thing = self.get_initial_thing(name, line_number).ok()?.0; initial_thing.function(self.name, line_number).ok() diff --git a/ftd/src/js/element.rs b/ftd/src/js/element.rs index c4ffd04f9b..3ee28f523e 100644 --- a/ftd/src/js/element.rs +++ b/ftd/src/js/element.rs @@ -26,7 +26,7 @@ pub enum Element { impl Element { pub fn from_interpreter_component( component: &fastn_resolved::ComponentInvocation, - doc: &dyn fastn_resolved::js::TDoc, + doc: &dyn fastn_resolved::tdoc::TDoc, ) -> Element { match component.name.as_str() { "ftd#text" => Element::Text(Text::from(component)), @@ -56,8 +56,8 @@ impl Element { &self, parent: &str, index: usize, - doc: &dyn fastn_resolved::js::TDoc, - rdata: &ftd::js::ResolverData, + doc: &dyn fastn_resolved::tdoc::TDoc, + rdata: &fastn_resolved_to_js::ResolverData, should_return: bool, has_rive_components: &mut bool, ) -> Vec { @@ -182,8 +182,8 @@ impl CheckBox { &self, parent: &str, index: usize, - doc: &dyn fastn_resolved::js::TDoc, - rdata: &mut ftd::js::ResolverData, + doc: &dyn fastn_resolved::tdoc::TDoc, + rdata: &mut fastn_resolved_to_js::ResolverData, should_return: bool, ) -> Vec { let mut component_statements = vec![]; @@ -294,8 +294,8 @@ impl TextInput { &self, parent: &str, index: usize, - doc: &dyn fastn_resolved::js::TDoc, - rdata: &mut ftd::js::ResolverData, + doc: &dyn fastn_resolved::tdoc::TDoc, + rdata: &mut fastn_resolved_to_js::ResolverData, should_return: bool, ) -> Vec { let mut component_statements = vec![]; @@ -438,8 +438,8 @@ impl Iframe { &self, parent: &str, index: usize, - doc: &dyn fastn_resolved::js::TDoc, - rdata: &mut ftd::js::ResolverData, + doc: &dyn fastn_resolved::tdoc::TDoc, + rdata: &mut fastn_resolved_to_js::ResolverData, should_return: bool, ) -> Vec { let mut component_statements = vec![]; @@ -517,7 +517,7 @@ pub struct Code { impl Code { pub fn from( component: &fastn_resolved::ComponentInvocation, - _doc: &dyn fastn_resolved::js::TDoc, + _doc: &dyn fastn_resolved::tdoc::TDoc, ) -> Code { let component_definition = ftd::interpreter::default::get_default_bag() .get("ftd#code") @@ -568,8 +568,8 @@ impl Code { &self, parent: &str, index: usize, - doc: &dyn fastn_resolved::js::TDoc, - rdata: &mut ftd::js::ResolverData, + doc: &dyn fastn_resolved::tdoc::TDoc, + rdata: &mut fastn_resolved_to_js::ResolverData, should_return: bool, ) -> Vec { let mut component_statements = vec![]; @@ -684,8 +684,8 @@ impl Image { &self, parent: &str, index: usize, - doc: &dyn fastn_resolved::js::TDoc, - rdata: &mut ftd::js::ResolverData, + doc: &dyn fastn_resolved::tdoc::TDoc, + rdata: &mut fastn_resolved_to_js::ResolverData, should_return: bool, ) -> Vec { let mut component_statements = vec![]; @@ -801,8 +801,8 @@ impl Audio { &self, parent: &str, index: usize, - doc: &dyn fastn_resolved::js::TDoc, - rdata: &mut ftd::js::ResolverData, + doc: &dyn fastn_resolved::tdoc::TDoc, + rdata: &mut fastn_resolved_to_js::ResolverData, should_return: bool, ) -> Vec { let mut component_statements = vec![]; @@ -939,8 +939,8 @@ impl Video { &self, parent: &str, index: usize, - doc: &dyn fastn_resolved::js::TDoc, - rdata: &mut ftd::js::ResolverData, + doc: &dyn fastn_resolved::tdoc::TDoc, + rdata: &mut fastn_resolved_to_js::ResolverData, should_return: bool, ) -> Vec { let mut component_statements = vec![]; @@ -1124,8 +1124,8 @@ impl ContainerProperties { pub fn to_set_properties( &self, element_name: &str, - doc: &dyn fastn_resolved::js::TDoc, - rdata: &ftd::js::ResolverData, + doc: &dyn fastn_resolved::tdoc::TDoc, + rdata: &fastn_resolved_to_js::ResolverData, ) -> Vec { let mut component_statements = vec![]; if let Some(ref wrap) = self.wrap { @@ -1185,8 +1185,8 @@ impl Container { pub(crate) fn to_component_statements( &self, - doc: &dyn fastn_resolved::js::TDoc, - rdata: &ftd::js::ResolverData, + doc: &dyn fastn_resolved::tdoc::TDoc, + rdata: &fastn_resolved_to_js::ResolverData, has_rive_components: &mut bool, should_return: bool, ) -> Vec { @@ -1254,8 +1254,8 @@ impl InheritedProperties { pub(crate) fn get_inherited_variables( &self, - doc: &dyn fastn_resolved::js::TDoc, - rdata: &ftd::js::ResolverData, + doc: &dyn fastn_resolved::tdoc::TDoc, + rdata: &fastn_resolved_to_js::ResolverData, component_name: &str, ) -> Option { let mut inherited_fields = vec![]; @@ -1320,8 +1320,8 @@ impl Text { &self, parent: &str, index: usize, - doc: &dyn fastn_resolved::js::TDoc, - rdata: &mut ftd::js::ResolverData, + doc: &dyn fastn_resolved::tdoc::TDoc, + rdata: &mut fastn_resolved_to_js::ResolverData, should_return: bool, ) -> Vec { let mut component_statements = vec![]; @@ -1384,8 +1384,8 @@ impl Integer { &self, parent: &str, index: usize, - doc: &dyn fastn_resolved::js::TDoc, - rdata: &mut ftd::js::ResolverData, + doc: &dyn fastn_resolved::tdoc::TDoc, + rdata: &mut fastn_resolved_to_js::ResolverData, should_return: bool, ) -> Vec { let mut component_statements = vec![]; @@ -1449,8 +1449,8 @@ impl Decimal { &self, parent: &str, index: usize, - doc: &dyn fastn_resolved::js::TDoc, - rdata: &mut ftd::js::ResolverData, + doc: &dyn fastn_resolved::tdoc::TDoc, + rdata: &mut fastn_resolved_to_js::ResolverData, should_return: bool, ) -> Vec { let mut component_statements = vec![]; @@ -1514,8 +1514,8 @@ impl Boolean { &self, parent: &str, index: usize, - doc: &dyn fastn_resolved::js::TDoc, - rdata: &mut ftd::js::ResolverData, + doc: &dyn fastn_resolved::tdoc::TDoc, + rdata: &mut fastn_resolved_to_js::ResolverData, should_return: bool, ) -> Vec { let mut component_statements = vec![]; @@ -1578,8 +1578,8 @@ impl Document { &self, parent: &str, index: usize, - doc: &dyn fastn_resolved::js::TDoc, - rdata: &mut ftd::js::ResolverData, + doc: &dyn fastn_resolved::tdoc::TDoc, + rdata: &mut fastn_resolved_to_js::ResolverData, should_return: bool, has_rive_components: &mut bool, ) -> Vec { @@ -1680,8 +1680,8 @@ impl DocumentMeta { value_kind: fastn_js::PropertyKind, referenced_value: &Option, component_statements: &mut Vec, - doc: &dyn fastn_resolved::js::TDoc, - rdata: &ftd::js::ResolverData, + doc: &dyn fastn_resolved::tdoc::TDoc, + rdata: &fastn_resolved_to_js::ResolverData, element_name: &str, ) { if self.has_self_reference(value) { @@ -1699,8 +1699,8 @@ impl DocumentMeta { pub(crate) fn to_component_statements( &self, - doc: &dyn fastn_resolved::js::TDoc, - rdata: &ftd::js::ResolverData, + doc: &dyn fastn_resolved::tdoc::TDoc, + rdata: &fastn_resolved_to_js::ResolverData, element_name: &str, ) -> Vec { let mut component_statements = vec![]; @@ -1855,8 +1855,8 @@ impl Column { &self, parent: &str, index: usize, - doc: &dyn fastn_resolved::js::TDoc, - rdata: &mut ftd::js::ResolverData, + doc: &dyn fastn_resolved::tdoc::TDoc, + rdata: &mut fastn_resolved_to_js::ResolverData, should_return: bool, has_rive_components: &mut bool, ) -> Vec { @@ -1920,8 +1920,8 @@ impl Row { &self, parent: &str, index: usize, - doc: &dyn fastn_resolved::js::TDoc, - rdata: &mut ftd::js::ResolverData, + doc: &dyn fastn_resolved::tdoc::TDoc, + rdata: &mut fastn_resolved_to_js::ResolverData, should_return: bool, has_rive_components: &mut bool, ) -> Vec { @@ -1983,8 +1983,8 @@ impl ContainerElement { &self, parent: &str, index: usize, - doc: &dyn fastn_resolved::js::TDoc, - rdata: &mut ftd::js::ResolverData, + doc: &dyn fastn_resolved::tdoc::TDoc, + rdata: &mut fastn_resolved_to_js::ResolverData, should_return: bool, has_rive_components: &mut bool, ) -> Vec { @@ -2046,8 +2046,8 @@ impl Device { &self, parent: &str, index: usize, - doc: &dyn fastn_resolved::js::TDoc, - rdata: &mut ftd::js::ResolverData, + doc: &dyn fastn_resolved::tdoc::TDoc, + rdata: &mut fastn_resolved_to_js::ResolverData, should_return: bool, has_rive_components: &mut bool, ) -> Vec { @@ -2131,8 +2131,8 @@ impl TextCommon { pub fn to_set_properties( &self, element_name: &str, - doc: &dyn fastn_resolved::js::TDoc, - rdata: &ftd::js::ResolverData, + doc: &dyn fastn_resolved::tdoc::TDoc, + rdata: &fastn_resolved_to_js::ResolverData, ) -> Vec { let mut component_statements = vec![]; if let Some(ref transform) = self.text_transform { @@ -2265,8 +2265,8 @@ impl Rive { &self, parent: &str, index: usize, - doc: &dyn fastn_resolved::js::TDoc, - rdata: &mut ftd::js::ResolverData, + doc: &dyn fastn_resolved::tdoc::TDoc, + rdata: &mut fastn_resolved_to_js::ResolverData, should_return: bool, ) -> Vec { let mut component_statements = vec![]; @@ -2642,8 +2642,8 @@ impl Common { pub fn to_set_properties_without_role( &self, element_name: &str, - doc: &dyn fastn_resolved::js::TDoc, - rdata: &ftd::js::ResolverData, + doc: &dyn fastn_resolved::tdoc::TDoc, + rdata: &fastn_resolved_to_js::ResolverData, ) -> Vec { use ftd::js::fastn_type_functions::EventExt; @@ -3250,8 +3250,8 @@ impl Common { pub fn to_set_properties_with_text( &self, element_name: &str, - doc: &dyn fastn_resolved::js::TDoc, - rdata: &ftd::js::ResolverData, + doc: &dyn fastn_resolved::tdoc::TDoc, + rdata: &fastn_resolved_to_js::ResolverData, text_component_statement: fastn_js::ComponentStatement, ) -> Vec { // Property dependencies @@ -3270,8 +3270,8 @@ impl Common { pub fn to_set_properties( &self, element_name: &str, - doc: &dyn fastn_resolved::js::TDoc, - rdata: &ftd::js::ResolverData, + doc: &dyn fastn_resolved::tdoc::TDoc, + rdata: &fastn_resolved_to_js::ResolverData, ) -> Vec { let mut component_statements = vec![]; component_statements.extend(self.to_set_properties_without_role(element_name, doc, rdata)); @@ -3316,7 +3316,7 @@ pub(crate) fn create_element( element_kind: fastn_js::ElementKind, parent: &str, index: usize, - rdata: &mut ftd::js::ResolverData, + rdata: &mut fastn_resolved_to_js::ResolverData, ) -> fastn_js::Kernel { let kernel = fastn_js::Kernel::from_component(element_kind, parent, index); *rdata = rdata.clone_with_new_component_name(Some(kernel.name.to_string())); diff --git a/ftd/src/js/fastn_type_functions.rs b/ftd/src/js/fastn_type_functions.rs index 8c53f81a79..932ee1bea7 100644 --- a/ftd/src/js/fastn_type_functions.rs +++ b/ftd/src/js/fastn_type_functions.rs @@ -3,16 +3,16 @@ use ftd::js::value::{ArgumentExt, ExpressionExt}; pub(crate) trait FunctionCallExt { fn to_js_function( &self, - doc: &dyn fastn_resolved::js::TDoc, - rdata: &ftd::js::ResolverData, + doc: &dyn fastn_resolved::tdoc::TDoc, + rdata: &fastn_resolved_to_js::ResolverData, ) -> fastn_js::Function; } impl FunctionCallExt for fastn_resolved::FunctionCall { fn to_js_function( &self, - doc: &dyn fastn_resolved::js::TDoc, - rdata: &ftd::js::ResolverData, + doc: &dyn fastn_resolved::tdoc::TDoc, + rdata: &fastn_resolved_to_js::ResolverData, ) -> fastn_js::Function { let mut parameters = vec![]; let mut name = self.name.to_string(); @@ -48,25 +48,25 @@ impl FunctionCallExt for fastn_resolved::FunctionCall { } pub(crate) trait PropertyValueExt { - fn get_deps(&self, rdata: &ftd::js::ResolverData) -> Vec; + fn get_deps(&self, rdata: &fastn_resolved_to_js::ResolverData) -> Vec; fn to_fastn_js_value_with_none( &self, - doc: &dyn fastn_resolved::js::TDoc, + doc: &dyn fastn_resolved::tdoc::TDoc, has_rive_components: &mut bool, ) -> fastn_js::SetPropertyValue; fn to_fastn_js_value( &self, - doc: &dyn fastn_resolved::js::TDoc, - rdata: &ftd::js::ResolverData, + doc: &dyn fastn_resolved::tdoc::TDoc, + rdata: &fastn_resolved_to_js::ResolverData, should_return: bool, ) -> fastn_js::SetPropertyValue; fn to_fastn_js_value_with_ui( &self, - doc: &dyn fastn_resolved::js::TDoc, - rdata: &ftd::js::ResolverData, + doc: &dyn fastn_resolved::tdoc::TDoc, + rdata: &fastn_resolved_to_js::ResolverData, has_rive_components: &mut bool, is_ui_component: bool, ) -> fastn_js::SetPropertyValue; @@ -75,7 +75,7 @@ pub(crate) trait PropertyValueExt { } impl PropertyValueExt for fastn_resolved::PropertyValue { - fn get_deps(&self, rdata: &ftd::js::ResolverData) -> Vec { + fn get_deps(&self, rdata: &fastn_resolved_to_js::ResolverData) -> Vec { let mut deps = vec![]; if let Some(reference) = self.get_reference_or_clone() { deps.push(ftd::js::utils::update_reference(reference, rdata)); @@ -89,12 +89,12 @@ impl PropertyValueExt for fastn_resolved::PropertyValue { fn to_fastn_js_value_with_none( &self, - doc: &dyn fastn_resolved::js::TDoc, + doc: &dyn fastn_resolved::tdoc::TDoc, has_rive_components: &mut bool, ) -> fastn_js::SetPropertyValue { self.to_fastn_js_value_with_ui( doc, - &ftd::js::ResolverData::none(), + &fastn_resolved_to_js::ResolverData::none(), has_rive_components, false, ) @@ -102,8 +102,8 @@ impl PropertyValueExt for fastn_resolved::PropertyValue { fn to_fastn_js_value( &self, - doc: &dyn fastn_resolved::js::TDoc, - rdata: &ftd::js::ResolverData, + doc: &dyn fastn_resolved::tdoc::TDoc, + rdata: &fastn_resolved_to_js::ResolverData, should_return: bool, ) -> fastn_js::SetPropertyValue { self.to_fastn_js_value_with_ui(doc, rdata, &mut false, should_return) @@ -111,8 +111,8 @@ impl PropertyValueExt for fastn_resolved::PropertyValue { fn to_fastn_js_value_with_ui( &self, - doc: &dyn fastn_resolved::js::TDoc, - rdata: &ftd::js::ResolverData, + doc: &dyn fastn_resolved::tdoc::TDoc, + rdata: &fastn_resolved_to_js::ResolverData, has_rive_components: &mut bool, should_return: bool, ) -> fastn_js::SetPropertyValue { @@ -148,8 +148,8 @@ impl PropertyValueExt for fastn_resolved::PropertyValue { pub(crate) trait ValueExt { fn to_fastn_js_value( &self, - doc: &dyn fastn_resolved::js::TDoc, - rdata: &ftd::js::ResolverData, + doc: &dyn fastn_resolved::tdoc::TDoc, + rdata: &fastn_resolved_to_js::ResolverData, has_rive_components: &mut bool, should_return: bool, ) -> fastn_js::SetPropertyValue; @@ -158,8 +158,8 @@ pub(crate) trait ValueExt { impl ValueExt for fastn_resolved::Value { fn to_fastn_js_value( &self, - doc: &dyn fastn_resolved::js::TDoc, - rdata: &ftd::js::ResolverData, + doc: &dyn fastn_resolved::tdoc::TDoc, + rdata: &fastn_resolved_to_js::ResolverData, has_rive_components: &mut bool, should_return: bool, ) -> fastn_js::SetPropertyValue { @@ -291,8 +291,8 @@ pub(crate) trait EventExt { fn to_event_handler_js( &self, element_name: &str, - doc: &dyn fastn_resolved::js::TDoc, - rdata: &ftd::js::ResolverData, + doc: &dyn fastn_resolved::tdoc::TDoc, + rdata: &fastn_resolved_to_js::ResolverData, ) -> Option; } @@ -300,8 +300,8 @@ impl EventExt for fastn_resolved::Event { fn to_event_handler_js( &self, element_name: &str, - doc: &dyn fastn_resolved::js::TDoc, - rdata: &ftd::js::ResolverData, + doc: &dyn fastn_resolved::tdoc::TDoc, + rdata: &fastn_resolved_to_js::ResolverData, ) -> Option { use ftd::js::fastn_type_functions::FunctionCallExt; @@ -350,8 +350,8 @@ pub(crate) trait ComponentExt { &self, parent: &str, index: usize, - doc: &dyn fastn_resolved::js::TDoc, - rdata: &ftd::js::ResolverData, + doc: &dyn fastn_resolved::tdoc::TDoc, + rdata: &fastn_resolved_to_js::ResolverData, should_return: bool, has_rive_components: &mut bool, ) -> Vec; @@ -359,8 +359,8 @@ pub(crate) trait ComponentExt { &self, parent: &str, index: usize, - doc: &dyn fastn_resolved::js::TDoc, - rdata: &ftd::js::ResolverData, + doc: &dyn fastn_resolved::tdoc::TDoc, + rdata: &fastn_resolved_to_js::ResolverData, should_return: bool, has_rive_components: &mut bool, ) -> Vec; @@ -368,8 +368,8 @@ pub(crate) trait ComponentExt { &self, parent: &str, index: usize, - doc: &dyn fastn_resolved::js::TDoc, - rdata: &ftd::js::ResolverData, + doc: &dyn fastn_resolved::tdoc::TDoc, + rdata: &fastn_resolved_to_js::ResolverData, should_return: bool, has_rive_components: &mut bool, ) -> Option>; @@ -377,8 +377,8 @@ pub(crate) trait ComponentExt { &self, parent: &str, index: usize, - doc: &dyn fastn_resolved::js::TDoc, - rdata: &ftd::js::ResolverData, + doc: &dyn fastn_resolved::tdoc::TDoc, + rdata: &fastn_resolved_to_js::ResolverData, should_return: bool, has_rive_components: &mut bool, ) -> Option>; @@ -386,8 +386,8 @@ pub(crate) trait ComponentExt { &self, parent: &str, index: usize, - doc: &dyn fastn_resolved::js::TDoc, - rdata: &ftd::js::ResolverData, + doc: &dyn fastn_resolved::tdoc::TDoc, + rdata: &fastn_resolved_to_js::ResolverData, should_return: bool, has_rive_components: &mut bool, ) -> Option>; @@ -395,8 +395,8 @@ pub(crate) trait ComponentExt { &self, parent: &str, index: usize, - doc: &dyn fastn_resolved::js::TDoc, - rdata: &ftd::js::ResolverData, + doc: &dyn fastn_resolved::tdoc::TDoc, + rdata: &fastn_resolved_to_js::ResolverData, should_return: bool, has_rive_components: &mut bool, ) -> Option>; @@ -408,8 +408,8 @@ impl ComponentExt for fastn_resolved::ComponentInvocation { &self, parent: &str, index: usize, - doc: &dyn fastn_resolved::js::TDoc, - rdata: &ftd::js::ResolverData, + doc: &dyn fastn_resolved::tdoc::TDoc, + rdata: &fastn_resolved_to_js::ResolverData, should_return: bool, has_rive_components: &mut bool, ) -> Vec { @@ -505,8 +505,8 @@ impl ComponentExt for fastn_resolved::ComponentInvocation { &self, parent: &str, index: usize, - doc: &dyn fastn_resolved::js::TDoc, - rdata: &ftd::js::ResolverData, + doc: &dyn fastn_resolved::tdoc::TDoc, + rdata: &fastn_resolved_to_js::ResolverData, should_return: bool, has_rive_components: &mut bool, ) -> Vec { @@ -561,8 +561,8 @@ impl ComponentExt for fastn_resolved::ComponentInvocation { &self, parent: &str, index: usize, - doc: &dyn fastn_resolved::js::TDoc, - rdata: &ftd::js::ResolverData, + doc: &dyn fastn_resolved::tdoc::TDoc, + rdata: &fastn_resolved_to_js::ResolverData, should_return: bool, has_rive_components: &mut bool, ) -> Option> { @@ -589,8 +589,8 @@ impl ComponentExt for fastn_resolved::ComponentInvocation { &self, parent: &str, index: usize, - doc: &dyn fastn_resolved::js::TDoc, - rdata: &ftd::js::ResolverData, + doc: &dyn fastn_resolved::tdoc::TDoc, + rdata: &fastn_resolved_to_js::ResolverData, should_return: bool, has_rive_components: &mut bool, ) -> Option> { @@ -645,8 +645,8 @@ impl ComponentExt for fastn_resolved::ComponentInvocation { &self, parent: &str, index: usize, - doc: &dyn fastn_resolved::js::TDoc, - rdata: &ftd::js::ResolverData, + doc: &dyn fastn_resolved::tdoc::TDoc, + rdata: &fastn_resolved_to_js::ResolverData, should_return: bool, has_rive_components: &mut bool, ) -> Option> { @@ -726,8 +726,8 @@ impl ComponentExt for fastn_resolved::ComponentInvocation { &self, parent: &str, index: usize, - doc: &dyn fastn_resolved::js::TDoc, - rdata: &ftd::js::ResolverData, + doc: &dyn fastn_resolved::tdoc::TDoc, + rdata: &fastn_resolved_to_js::ResolverData, should_return: bool, has_rive_components: &mut bool, ) -> Option> { diff --git a/ftd/src/js/mod.rs b/ftd/src/js/mod.rs index ecc4bcfb61..b3a98f7896 100644 --- a/ftd/src/js/mod.rs +++ b/ftd/src/js/mod.rs @@ -5,13 +5,11 @@ mod ftd_test_helpers; mod element; pub(crate) mod fastn_type_functions; -mod resolver; mod utils; mod value; pub use element::{Common, Element}; use ftd::js::value::ArgumentExt; -pub use resolver::ResolverData; pub use value::Value; pub const CODE_DEFAULT_THEME: &str = "fastn-theme.dark"; @@ -180,10 +178,10 @@ pub fn document_into_js_ast(document: ftd::interpreter::Document) -> JSAstData { } pub(crate) trait FunctionExt { - fn to_ast(&self, doc: &dyn fastn_resolved::js::TDoc) -> fastn_js::Ast; + fn to_ast(&self, doc: &dyn fastn_resolved::tdoc::TDoc) -> fastn_js::Ast; } impl FunctionExt for fastn_resolved::Function { - fn to_ast(&self, doc: &dyn fastn_resolved::js::TDoc) -> fastn_js::Ast { + fn to_ast(&self, doc: &dyn fastn_resolved::tdoc::TDoc) -> fastn_js::Ast { use itertools::Itertools; fastn_js::udf_with_arguments( @@ -203,7 +201,7 @@ impl FunctionExt for fastn_resolved::Function { v.name.to_string(), val.to_set_property_value( doc, - &ftd::js::ResolverData::new_with_component_definition_name( + &fastn_resolved_to_js::ResolverData::new_with_component_definition_name( &Some(self.name.to_string()), ), ), @@ -222,7 +220,7 @@ impl FunctionExt for fastn_resolved::Function { pub(crate) trait VariableExt { fn to_ast( &self, - doc: &dyn fastn_resolved::js::TDoc, + doc: &dyn fastn_resolved::tdoc::TDoc, prefix: Option, has_rive_components: &mut bool, ) -> fastn_js::Ast; @@ -231,7 +229,7 @@ pub(crate) trait VariableExt { impl VariableExt for fastn_resolved::Variable { fn to_ast( &self, - doc: &dyn fastn_resolved::js::TDoc, + doc: &dyn fastn_resolved::tdoc::TDoc, prefix: Option, has_rive_components: &mut bool, ) -> fastn_js::Ast { @@ -244,7 +242,7 @@ impl VariableExt for fastn_resolved::Variable { name: self.name.to_string(), fields: value.to_fastn_js_value( doc, - &ftd::js::ResolverData::none(), + &fastn_resolved_to_js::ResolverData::none(), has_rive_components, false, ), @@ -282,14 +280,14 @@ impl VariableExt for fastn_resolved::Variable { pub(crate) trait ComponentDefinitionExt { fn to_ast( &self, - doc: &dyn fastn_resolved::js::TDoc, + doc: &dyn fastn_resolved::tdoc::TDoc, has_rive_components: &mut bool, ) -> fastn_js::Ast; } impl ComponentDefinitionExt for fastn_resolved::ComponentDefinition { fn to_ast( &self, - doc: &dyn fastn_resolved::js::TDoc, + doc: &dyn fastn_resolved::tdoc::TDoc, has_rive_components: &mut bool, ) -> fastn_js::Ast { use ftd::js::fastn_type_functions::ComponentExt; @@ -300,7 +298,7 @@ impl ComponentDefinitionExt for fastn_resolved::ComponentDefinition { fastn_js::COMPONENT_PARENT, 0, doc, - &ftd::js::ResolverData::new_with_component_definition_name(&Some( + &fastn_resolved_to_js::ResolverData::new_with_component_definition_name(&Some( self.name.to_string(), )), true, @@ -317,7 +315,7 @@ impl ComponentDefinitionExt for fastn_resolved::ComponentDefinition { v.name.to_string(), val.to_set_property_value_with_ui( doc, - &ftd::js::ResolverData::new_with_component_definition_name(&Some( + &fastn_resolved_to_js::ResolverData::new_with_component_definition_name(&Some( self.name.to_string(), )), has_rive_components, @@ -334,7 +332,7 @@ impl ComponentDefinitionExt for fastn_resolved::ComponentDefinition { pub fn from_tree( tree: &[fastn_resolved::ComponentInvocation], - doc: &dyn fastn_resolved::js::TDoc, + doc: &dyn fastn_resolved::tdoc::TDoc, has_rive_components: &mut bool, ) -> fastn_js::Ast { use ftd::js::fastn_type_functions::ComponentExt; @@ -345,7 +343,7 @@ pub fn from_tree( fastn_js::COMPONENT_PARENT, index, doc, - &ftd::js::ResolverData::none(), + &fastn_resolved_to_js::ResolverData::none(), false, has_rive_components, )) @@ -354,11 +352,11 @@ pub fn from_tree( } pub trait WebComponentDefinitionExt { - fn to_ast(&self, doc: &dyn fastn_resolved::js::TDoc) -> fastn_js::Ast; + fn to_ast(&self, doc: &dyn fastn_resolved::tdoc::TDoc) -> fastn_js::Ast; } impl WebComponentDefinitionExt for fastn_resolved::WebComponentDefinition { - fn to_ast(&self, doc: &dyn fastn_resolved::js::TDoc) -> fastn_js::Ast { + fn to_ast(&self, doc: &dyn fastn_resolved::tdoc::TDoc) -> fastn_js::Ast { use itertools::Itertools; let kernel = fastn_js::Kernel::from_component( @@ -385,7 +383,7 @@ impl WebComponentDefinitionExt for fastn_resolved::WebComponentDefinition { v.name.to_string(), val.to_set_property_value( doc, - &ftd::js::ResolverData::new_with_component_definition_name(&Some( + &fastn_resolved_to_js::ResolverData::new_with_component_definition_name(&Some( self.name.to_string(), )), ), diff --git a/ftd/src/js/utils.rs b/ftd/src/js/utils.rs index ed0387ad1a..1a443e4610 100644 --- a/ftd/src/js/utils.rs +++ b/ftd/src/js/utils.rs @@ -29,8 +29,8 @@ pub fn get_css_html(external_css: &[String]) -> String { pub(crate) fn get_rive_event( events: &[fastn_resolved::Event], - doc: &dyn fastn_resolved::js::TDoc, - rdata: &ftd::js::ResolverData, + doc: &dyn fastn_resolved::tdoc::TDoc, + rdata: &fastn_resolved_to_js::ResolverData, element_name: &str, ) -> String { let mut events_map: ftd::VecMap<(&String, &fastn_resolved::FunctionCall)> = ftd::VecMap::new(); @@ -107,10 +107,13 @@ pub(crate) fn to_key(key: &str) -> String { } pub(crate) fn update_reference_with_none(reference: &str) -> String { - update_reference(reference, &ftd::js::ResolverData::none()) + update_reference(reference, &fastn_resolved_to_js::ResolverData::none()) } -pub(crate) fn update_reference(reference: &str, rdata: &ftd::js::ResolverData) -> String { +pub(crate) fn update_reference( + reference: &str, + rdata: &fastn_resolved_to_js::ResolverData, +) -> String { let name = reference.to_string(); if ftd::interpreter::FTD_SPECIAL_VALUE @@ -202,8 +205,8 @@ pub(crate) fn get_js_value_from_properties( pub(crate) fn function_call_to_js_formula( function_call: &fastn_resolved::FunctionCall, - doc: &dyn fastn_resolved::js::TDoc, - rdata: &ftd::js::ResolverData, + doc: &dyn fastn_resolved::tdoc::TDoc, + rdata: &fastn_resolved_to_js::ResolverData, ) -> fastn_js::Formula { use ftd::js::fastn_type_functions::{FunctionCallExt, PropertyValueExt}; @@ -269,8 +272,8 @@ pub(crate) fn is_module_argument( /// second element is the corresponding set property value. Returns `None` if any retrieval or /// conversion operation fails. pub(crate) fn get_set_property_values_for_provided_component_properties( - doc: &dyn fastn_resolved::js::TDoc, - rdata: &ftd::js::ResolverData, + doc: &dyn fastn_resolved::tdoc::TDoc, + rdata: &fastn_resolved_to_js::ResolverData, component_name: &str, component_properties: &[fastn_resolved::Property], line_number: usize, diff --git a/ftd/src/js/value.rs b/ftd/src/js/value.rs index a049e4c08e..0889becb98 100644 --- a/ftd/src/js/value.rs +++ b/ftd/src/js/value.rs @@ -16,12 +16,12 @@ pub struct ReferenceData { impl Value { pub(crate) fn to_set_property_value_with_none( &self, - doc: &dyn fastn_resolved::js::TDoc, + doc: &dyn fastn_resolved::tdoc::TDoc, has_rive_components: &mut bool, ) -> fastn_js::SetPropertyValue { self.to_set_property_value_with_ui( doc, - &ftd::js::ResolverData::none(), + &fastn_resolved_to_js::ResolverData::none(), has_rive_components, false, ) @@ -29,16 +29,16 @@ impl Value { pub(crate) fn to_set_property_value( &self, - doc: &dyn fastn_resolved::js::TDoc, - rdata: &ftd::js::ResolverData, + doc: &dyn fastn_resolved::tdoc::TDoc, + rdata: &fastn_resolved_to_js::ResolverData, ) -> fastn_js::SetPropertyValue { self.to_set_property_value_with_ui(doc, rdata, &mut false, false) } pub(crate) fn to_set_property_value_with_ui( &self, - doc: &dyn fastn_resolved::js::TDoc, - rdata: &ftd::js::ResolverData, + doc: &dyn fastn_resolved::tdoc::TDoc, + rdata: &fastn_resolved_to_js::ResolverData, has_rive_components: &mut bool, should_return: bool, ) -> fastn_js::SetPropertyValue { @@ -104,9 +104,9 @@ impl Value { pub(crate) fn to_set_property( &self, kind: fastn_js::PropertyKind, - doc: &dyn fastn_resolved::js::TDoc, + doc: &dyn fastn_resolved::tdoc::TDoc, element_name: &str, - rdata: &ftd::js::ResolverData, + rdata: &fastn_resolved_to_js::ResolverData, ) -> fastn_js::SetProperty { fastn_js::SetProperty { kind, @@ -131,9 +131,9 @@ impl Value { } fn properties_to_js_conditional_formula( - doc: &dyn fastn_resolved::js::TDoc, + doc: &dyn fastn_resolved::tdoc::TDoc, properties: &[fastn_resolved::Property], - rdata: &ftd::js::ResolverData, + rdata: &fastn_resolved_to_js::ResolverData, ) -> fastn_js::Formula { use ftd::js::fastn_type_functions::PropertyValueExt; @@ -161,15 +161,15 @@ fn properties_to_js_conditional_formula( } pub(crate) trait ExpressionExt { - fn get_deps(&self, rdata: &ftd::js::ResolverData) -> Vec; + fn get_deps(&self, rdata: &fastn_resolved_to_js::ResolverData) -> Vec; fn update_node_with_variable_reference_js( &self, - rdata: &ftd::js::ResolverData, + rdata: &fastn_resolved_to_js::ResolverData, ) -> fastn_resolved::evalexpr::ExprNode; } impl ExpressionExt for fastn_resolved::Expression { - fn get_deps(&self, rdata: &ftd::js::ResolverData) -> Vec { + fn get_deps(&self, rdata: &fastn_resolved_to_js::ResolverData) -> Vec { use ftd::js::fastn_type_functions::PropertyValueExt; let mut deps = vec![]; @@ -181,14 +181,14 @@ impl ExpressionExt for fastn_resolved::Expression { fn update_node_with_variable_reference_js( &self, - rdata: &ftd::js::ResolverData, + rdata: &fastn_resolved_to_js::ResolverData, ) -> fastn_resolved::evalexpr::ExprNode { return update_node_with_variable_reference_js_(&self.expression, &self.references, rdata); fn update_node_with_variable_reference_js_( expr: &fastn_resolved::evalexpr::ExprNode, references: &ftd::Map, - rdata: &ftd::js::ResolverData, + rdata: &fastn_resolved_to_js::ResolverData, ) -> fastn_resolved::evalexpr::ExprNode { let mut operator = expr.operator().clone(); if let fastn_resolved::evalexpr::Operator::VariableIdentifierRead { ref identifier } =