diff --git a/crates/thing-core/src/resolve/expand.rs b/crates/thing-core/src/resolve/expand.rs index 0f0b55e..99e98cf 100644 --- a/crates/thing-core/src/resolve/expand.rs +++ b/crates/thing-core/src/resolve/expand.rs @@ -326,11 +326,46 @@ impl<'a> Expander<'a> { } }, Node::Use(used) => self.expand_use(used, scope, depth, root)?, + Node::Text(_) | Node::Image(_) | Node::Toggle(_) | Node::Slider(_) | Node::TextInput(_) | Node::Select(_) | Node::Plot(_) | Node::Embed(_) => { + self.leaf(node, scope, root)? + } Node::Box(b) => { let common = self.common(&b.common, scope, root)?; let children = self.children(&b.children, scope, depth + 1)?; Node::Box(BoxNode { common, style: b.style.clone(), paint: b.paint.clone(), role: b.role.clone(), children }) } + Node::Button(b) => { + let common = self.common(&b.common, scope, root)?; + let on_activate = self.command(&b.on_activate, scope)?; + let enabled = self.boolean(&b.enabled, scope)?; + let content = self.children(&b.content, scope, depth + 1)?; + Node::Button(ButtonNode { common, content, on_activate, enabled }) + } + Node::Repeat(r) => { + let common = self.common(&r.common, scope, root)?; + let collection = self.collection(&r.collection, scope)?; + let template = std::boxed::Box::new(self.node(&r.template, scope, depth + 1, false)?); + Node::Repeat(RepeatNode { common, collection, key_member: r.key_member.clone(), template }) + } + Node::Overlay(o) => { + let common = self.common(&o.common, scope, root)?; + let anchor = match &o.anchor { + Anchor::Viewport => Anchor::Viewport, + Anchor::Node(anchor) => Anchor::Node(AnchorNode { node: self.id(&anchor.node, scope) }), + }; + let dismiss = self.command(&o.dismiss, scope)?; + let children = self.children(&o.children, scope, depth + 1)?; + Node::Overlay(OverlayNode { common, anchor, modal: o.modal, dismiss, children }) + } + }) + } + + + /// The nodes with no child list. Apart from `node` so that its frame, which every level of the + /// recursion pays for, holds only what a container needs. + #[inline(never)] + fn leaf(&mut self, node: &Node, scope: Option<&Scope>, root: bool) -> Res { + Ok(match node { Node::Text(t) => { let common = self.common(&t.common, scope, root)?; let content = self.text(&t.content, scope)?; @@ -341,13 +376,6 @@ impl<'a> Expander<'a> { let alt = self.text(&i.alt, scope)?; Node::Image(ImageNode { common, alt, ..i.clone() }) } - Node::Button(b) => { - let common = self.common(&b.common, scope, root)?; - let on_activate = self.command(&b.on_activate, scope)?; - let enabled = self.boolean(&b.enabled, scope)?; - let content = self.children(&b.content, scope, depth + 1)?; - Node::Button(ButtonNode { common, content, on_activate, enabled }) - } Node::Toggle(t) => { let common = self.common(&t.common, scope, root)?; let checked = self.boolean(&t.checked, scope)?; @@ -381,22 +409,6 @@ impl<'a> Expander<'a> { let on_change = self.command(&s.on_change, scope)?; Node::Select(SelectNode { common, options, value, on_change }) } - Node::Repeat(r) => { - let common = self.common(&r.common, scope, root)?; - let collection = self.collection(&r.collection, scope)?; - let template = std::boxed::Box::new(self.node(&r.template, scope, depth + 1, false)?); - Node::Repeat(RepeatNode { common, collection, key_member: r.key_member.clone(), template }) - } - Node::Overlay(o) => { - let common = self.common(&o.common, scope, root)?; - let anchor = match &o.anchor { - Anchor::Viewport => Anchor::Viewport, - Anchor::Node(anchor) => Anchor::Node(AnchorNode { node: self.id(&anchor.node, scope) }), - }; - let dismiss = self.command(&o.dismiss, scope)?; - let children = self.children(&o.children, scope, depth + 1)?; - Node::Overlay(OverlayNode { common, anchor, modal: o.modal, dismiss, children }) - } Node::Plot(p) => { let common = self.common(&p.common, scope, root)?; Node::Plot(PlotNode { common, series: self.bind(&p.series), ..p.clone() }) @@ -405,6 +417,9 @@ impl<'a> Expander<'a> { let common = self.common(&e.common, scope, root)?; Node::Embed(EmbedNode { common, ..e.clone() }) } + Node::Slot(_) | Node::Use(_) | Node::Box(_) | Node::Button(_) | Node::Repeat(_) | Node::Overlay(_) => { + unreachable!("node() handles containers, Use and Slot") + } }) } diff --git a/crates/thing-core/tests/resolve.rs b/crates/thing-core/tests/resolve.rs index 3eb1e7a..95949ad 100644 --- a/crates/thing-core/tests/resolve.rs +++ b/crates/thing-core/tests/resolve.rs @@ -954,4 +954,4 @@ fn a_slot_naming_a_param_of_another_kind_is_invalid() { }); } -const STACK_TEST_DEPTH: usize = 900; +const STACK_TEST_DEPTH: usize = 1100;