From 50fc0a943a2f7ea013b88d906e5bb4e5972fe056 Mon Sep 17 00:00:00 2001 From: Matthew Phillips Date: Tue, 5 Mar 2024 10:09:34 -0500 Subject: [PATCH] Implement transition:persist-props (#975) * Implement transition:persist-props * Add a changeset --- .changeset/real-otters-mix.md | 5 +++++ internal/printer/printer.go | 6 ++++++ internal/printer/printer_test.go | 8 ++++++++ internal/transform/transform.go | 1 + 4 files changed, 20 insertions(+) create mode 100644 .changeset/real-otters-mix.md diff --git a/.changeset/real-otters-mix.md b/.changeset/real-otters-mix.md new file mode 100644 index 000000000..c5a0e6584 --- /dev/null +++ b/.changeset/real-otters-mix.md @@ -0,0 +1,5 @@ +--- +'@astrojs/compiler': minor +--- + +Implement the `transition:persist-props` transformation diff --git a/internal/printer/printer.go b/internal/printer/printer.go index 89e687014..0a6274018 100644 --- a/internal/printer/printer.go +++ b/internal/printer/printer.go @@ -514,6 +514,12 @@ func maybeConvertTransition(n *astro.Node) { Type: astro.ExpressionAttribute, }) } + + // Do a simple rename for `transition:persist-props` + transitionPersistPropsIndex := transform.AttrIndex(n, transform.TRANSITION_PERSIST_PROPS) + if transitionPersistPropsIndex != -1 { + n.Attr[transitionPersistPropsIndex].Key = "data-astro-transition-persist-props" + } } } diff --git a/internal/printer/printer_test.go b/internal/printer/printer_test.go index 4a43ce71e..938e3c4e8 100644 --- a/internal/printer/printer_test.go +++ b/internal/printer/printer_test.go @@ -3490,6 +3490,14 @@ const items = ["Dog", "Cat", "Platipus"]; code: `${$$maybeRenderHead($$result)}
`, }, }, + { + name: "transition:persist-props converted to a data attribute", + source: ``, + transitions: true, + want: want{ + code: `${$$renderComponent($$result,'my-island','my-island',{"data-astro-transition-persist-props":"false","data-astro-transition-persist":($$createTransitionScope($$result, "otghnj5u"))})}`, + }, + }, { name: "trailing expression", source: `{}`, diff --git a/internal/transform/transform.go b/internal/transform/transform.go index 7e92cae16..1070ce3dd 100644 --- a/internal/transform/transform.go +++ b/internal/transform/transform.go @@ -16,6 +16,7 @@ import ( const TRANSITION_ANIMATE = "transition:animate" const TRANSITION_NAME = "transition:name" const TRANSITION_PERSIST = "transition:persist" +const TRANSITION_PERSIST_PROPS = "transition:persist-props" type TransformOptions struct { Scope string