Skip to content

Commit

Permalink
Fix nested jsx pretty printing
Browse files Browse the repository at this point in the history
  • Loading branch information
voltrevo committed Feb 29, 2024
1 parent 30c5a52 commit 4cb49dc
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions valuescript_vm/src/jsx_element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ impl ValTrait for JsxElement {
write!(f, "\x1b[36m>\x1b[39m")?;

for child in &self.children {
if let Some(jsx_child) = try_to_jsx_element(child) {
jsx_child.pretty_fmt(f)?;
if is_jsx_element(child) {
write!(f, "{}", child.pretty())?;
} else {
write!(f, "{}", child)?;
}
Expand Down Expand Up @@ -137,24 +137,24 @@ impl fmt::Display for JsxElement {

fn write_attributes(f: &mut fmt::Formatter<'_>, attrs: &Vec<(String, Val)>) -> fmt::Result {
for (key, val) in attrs {
write!(f, " {}=\x1b[33m{}\x1b[39m", key, val)?;
write!(f, " {}=\x1b[33m\"{}\"\x1b[39m", key, val)?;
}

Ok(())
}

fn write_attributes_pretty(f: &mut fmt::Formatter<'_>, attrs: &Vec<(String, Val)>) -> fmt::Result {
for (key, val) in attrs {
write!(f, " {}=\x1b[33m{}\x1b[39m", key, val)?;
write!(f, " {}=\x1b[33m\"{}\"\x1b[39m", key, val)?;
}

Ok(())
}

pub fn try_to_jsx_element(val: &Val) -> Option<Rc<JsxElement>> {
pub fn is_jsx_element(val: &Val) -> bool {
match val {
Val::Dynamic(dynamic) => dynamic.as_any().downcast_ref().cloned(),
Val::StoragePtr(ptr) => try_to_jsx_element(&ptr.get()),
_ => None,
Val::Dynamic(dynamic) => dynamic.as_any().is::<JsxElement>(),
Val::StoragePtr(ptr) => is_jsx_element(&ptr.get()),
_ => false,
}
}

0 comments on commit 4cb49dc

Please sign in to comment.