summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfrozolotl <44589151+frozolotl@users.noreply.github.com>2023-11-24 05:41:38 -0500
committerGitHub <noreply@github.com>2023-11-24 11:41:38 +0100
commite5470401f4861a6aa57a2a4dfd6ce0402de71e1d (patch)
tree7425c2f9fc392f2b7782305da52d1862f3785f27
parent07ae4fb923cfd690ce81301397438b5112f13b11 (diff)
Fix `has` on non-inherent fields (#2745)
-rw-r--r--crates/typst-macros/src/elem.rs8
-rw-r--r--tests/ref/compiler/content-field.pngbin2423 -> 24704 bytes
-rw-r--r--tests/typ/compiler/content-field.typ14
3 files changed, 21 insertions, 1 deletions
diff --git a/crates/typst-macros/src/elem.rs b/crates/typst-macros/src/elem.rs
index c36becb2..2de0adf2 100644
--- a/crates/typst-macros/src/elem.rs
+++ b/crates/typst-macros/src/elem.rs
@@ -731,12 +731,18 @@ fn create_native_elem_impl(element: &Elem) -> TokenStream {
quote! {
<#elem as #model::ElementFields>::Fields::#name => None,
}
- } else {
+ } else if field.inherent() {
quote! {
<#elem as #model::ElementFields>::Fields::#name => Some(
::typst::eval::IntoValue::into_value(self.#field_ident.clone())
),
}
+ } else {
+ quote! {
+ <#elem as #model::ElementFields>::Fields::#name => {
+ self.#field_ident.clone().map(::typst::eval::IntoValue::into_value)
+ }
+ }
}
});
diff --git a/tests/ref/compiler/content-field.png b/tests/ref/compiler/content-field.png
index cef3274a..093d9046 100644
--- a/tests/ref/compiler/content-field.png
+++ b/tests/ref/compiler/content-field.png
Binary files differ
diff --git a/tests/typ/compiler/content-field.typ b/tests/typ/compiler/content-field.typ
index 1d3dceb7..f8adfc42 100644
--- a/tests/typ/compiler/content-field.typ
+++ b/tests/typ/compiler/content-field.typ
@@ -1,3 +1,17 @@
+// Tests for field introspection.
+
+---
+// Verify that non-inherent fields are hidden if not set.
+#show figure: it => [
+ `repr(it)`: #repr(it) \
+ `it.has("gap"): `#repr(it.has("gap")) \
+]
+
+#figure[]
+
+#figure([], gap: 1pt)
+
+---
// Integrated test for content fields.
#let compute(equation, ..vars) = {