Skip to content

Commit

Permalink
Add propagation metadata to the TransformResult (#860)
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewp authored Sep 8, 2023
1 parent a163db5 commit 2584348
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/clean-sloths-try.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/compiler': minor
---

Add propagation metadata to the TransformResult
2 changes: 2 additions & 0 deletions cmd/astro-wasm/astro-wasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ type TransformResult struct {
ClientOnlyComponents []HydratedComponent `js:"clientOnlyComponents"`
ContainsHead bool `js:"containsHead"`
StyleError []string `js:"styleError"`
Propagation bool `js:"propagation"`
}

// This is spawned as a goroutine to preprocess style nodes using an async function passed from JS
Expand Down Expand Up @@ -412,6 +413,7 @@ func Transform() any {
ClientOnlyComponents: clientOnlyComponents,
ContainsHead: doc.ContainsHead,
StyleError: styleError,
Propagation: doc.HeadPropagation,
}
switch transformOptions.SourceMap {
case "external":
Expand Down
1 change: 1 addition & 0 deletions internal/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ type Node struct {
ClientOnlyComponents []*HydratedComponentMetadata
HydrationDirectives map[string]bool
ContainsHead bool
HeadPropagation bool

Type NodeType
DataAtom atom.Atom
Expand Down
1 change: 1 addition & 0 deletions internal/transform/transform.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func Transform(doc *astro.Node, opts TransformOptions, h *handler.Handler) *astr
}
if HasAttr(n, TRANSITION_ANIMATE) || HasAttr(n, TRANSITION_NAME) || HasAttr(n, TRANSITION_PERSIST) {
doc.Transition = true
doc.HeadPropagation = true
getOrCreateTransitionScope(n, &opts, i)
}
if len(definedVars) > 0 {
Expand Down
1 change: 1 addition & 0 deletions packages/compiler/src/shared/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export interface TransformResult {
hydratedComponents: HydratedComponent[];
clientOnlyComponents: HydratedComponent[];
containsHead: boolean;
propagation: boolean;
}

export interface SourceMap {
Expand Down
20 changes: 20 additions & 0 deletions packages/compiler/test/transition/meta.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { test } from 'uvu';
import * as assert from 'uvu/assert';
import { transform } from '@astrojs/compiler';

const FIXTURE = `
<div transition:animate="slide"></div>
`;

let result;
test.before(async () => {
result = await transform(FIXTURE, {
resolvePath: async (s) => s,
});
});

test('tagged with propagation metadata', () => {
assert.equal(result.propagation, true);
});

test.run();

0 comments on commit 2584348

Please sign in to comment.