diff --git a/api/sixtyfps-node/native/lib.rs b/api/sixtyfps-node/native/lib.rs index 551c44646..4d087613e 100644 --- a/api/sixtyfps-node/native/lib.rs +++ b/api/sixtyfps-node/native/lib.rs @@ -116,8 +116,10 @@ fn create<'cx>( let persistent_context = persistent_context::PersistentContext::new(cx); if let Some(args) = cx.argument_opt(0).and_then(|arg| arg.downcast::().ok()) { - let properties = - component_type.properties_and_callbacks().collect::>(); + let properties = component_type + .properties_and_callbacks() + .map(|(k, v)| (k.replace('_', "-"), v)) + .collect::>(); for x in args.get_own_property_names(cx)?.to_vec(cx)? { let prop_name = x.to_string(cx)?.value().replace('_', "-"); let value = args.get(cx, x)?; diff --git a/sixtyfps_runtime/interpreter/api.rs b/sixtyfps_runtime/interpreter/api.rs index ffdc3022e..8630a07d9 100644 --- a/sixtyfps_runtime/interpreter/api.rs +++ b/sixtyfps_runtime/interpreter/api.rs @@ -943,6 +943,7 @@ fn component_definition_properties() { r#" export Dummy := Rectangle { property test; + property underscores-and-dashes_preserved; callback hello; }"# .into(), @@ -953,9 +954,11 @@ fn component_definition_properties() { let props = comp_def.properties().collect::>(); - assert_eq!(props.len(), 1); + assert_eq!(props.len(), 2); assert_eq!(props[0].0, "test"); assert_eq!(props[0].1, ValueType::String); + assert_eq!(props[1].0, "underscores-and-dashes_preserved"); + assert_eq!(props[1].1, ValueType::Number); } #[test] diff --git a/sixtyfps_runtime/interpreter/dynamic_component.rs b/sixtyfps_runtime/interpreter/dynamic_component.rs index cc3b2a148..2fc5f7801 100644 --- a/sixtyfps_runtime/interpreter/dynamic_component.rs +++ b/sixtyfps_runtime/interpreter/dynamic_component.rs @@ -309,13 +309,24 @@ impl<'id> ComponentDescription<'id> { } /// List of publicly declared properties or callbacks + /// + /// We try to preserve the dashes and underscore as written in the property declaration pub fn properties( &self, ) -> impl Iterator + '_ { - self.public_properties - .iter() - .filter(|(_, v)| v.expose_in_public_api) - .map(|(s, v)| (s.clone(), v.property_type.clone())) + self.public_properties.iter().filter(|(_, v)| v.expose_in_public_api).map(|(s, v)| { + let name = v + .node + .as_ref() + .and_then(|n| { + n.as_ref() + .either(|n| n.DeclaredIdentifier(), |n| n.DeclaredIdentifier()) + .child_token(parser::SyntaxKind::Identifier) + }) + .map(|n| n.to_string()) + .unwrap_or_else(|| s.clone()); + (name, v.property_type.clone()) + }) } /// Instantiate a runtime component from this ComponentDescription diff --git a/tests/cases/callbacks/handler_with_arg.60 b/tests/cases/callbacks/handler_with_arg.60 index 055828bd8..b03b30ed5 100644 --- a/tests/cases/callbacks/handler_with_arg.60 +++ b/tests/cases/callbacks/handler_with_arg.60 @@ -85,7 +85,7 @@ try { instance.test_callback(); assert(false); } catch(e) { - assert.equal(e.toString(), "Error: test-callback expect 1 arguments, but 0 where provided"); + assert.equal(e.toString(), "Error: test_callback expect 1 arguments, but 0 where provided"); } assert.equal(instance.callback_emission_count, 0);