Skip to content

Commit

Permalink
Implement transition:persist-props (#975)
Browse files Browse the repository at this point in the history
* Implement transition:persist-props

* Add a changeset
  • Loading branch information
matthewp committed Mar 5, 2024
1 parent f45dbfd commit 50fc0a9
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/real-otters-mix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/compiler': minor
---

Implement the `transition:persist-props` transformation
6 changes: 6 additions & 0 deletions internal/printer/printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}

Expand Down
8 changes: 8 additions & 0 deletions internal/printer/printer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3490,6 +3490,14 @@ const items = ["Dog", "Cat", "Platipus"];
code: `${$$maybeRenderHead($$result)}<div data-astro-transition-persist="foo"${$$addAttribute($$renderTransition($$result, "peuy4xf7", "", "foo"), "data-astro-transition-scope")}></div>`,
},
},
{
name: "transition:persist-props converted to a data attribute",
source: `<my-island transition:persist transition:persist-props="false"></my-island>`,
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: `<Component />{}`,
Expand Down
1 change: 1 addition & 0 deletions internal/transform/transform.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 50fc0a9

Please sign in to comment.