Skip to content

Commit

Permalink
Remove metadata type (#147)
Browse files Browse the repository at this point in the history
* Remove metadata type

* Adds a changeset
  • Loading branch information
matthewp authored Nov 15, 2021
1 parent a3eaa59 commit 432eaaf
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 15 deletions.
5 changes: 5 additions & 0 deletions .changeset/new-weeks-mix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/compiler': patch
---

Fix for compiler regression causing nil pointer
12 changes: 3 additions & 9 deletions internal/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ type Node struct {
Parent, FirstChild, LastChild, PrevSibling, NextSibling *Node

// These are only accessible from the document root Node
Styles, Scripts []*Node
Metadata *Metadata
Styles, Scripts []*Node
HydratedComponents []*Node
ClientOnlyComponents []*Node

Type NodeType
DataAtom atom.Atom
Expand All @@ -65,13 +66,6 @@ type Node struct {
Loc []loc.Loc
}

// Metadata is a collection of anything that needs to be hoisted out of the
// template layer, as well as any additional info needed to render the component.
type Metadata struct {
HydratedComponents []*Node
ClientOnlyComponents []*Node
}

// InsertBefore inserts newChild as a child of n, immediately before oldChild
// in the sequence of n's children. oldChild may be nil, in which case newChild
// is appended to the end of n's children.
Expand Down
3 changes: 1 addition & 2 deletions internal/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -2725,8 +2725,7 @@ func ParseWithOptions(r io.Reader, opts ...ParseOption) (*Node, error) {
p := &parser{
tokenizer: NewTokenizer(r),
doc: &Node{
Type: DocumentNode,
Metadata: &Metadata{},
Type: DocumentNode,
},
scripting: true,
framesetOK: true,
Expand Down
4 changes: 2 additions & 2 deletions internal/printer/printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ func (p *printer) printComponentMetadata(doc *astro.Node, source []byte) {
loc, statement := js_scanner.NextImportStatement(source, 0)
for loc != -1 {
isClientOnlyImport := false
for _, n := range doc.Metadata.ClientOnlyComponents {
for _, n := range doc.ClientOnlyComponents {
for _, imported := range statement.Imports {
if imported.ExportName == "*" {
prefix := fmt.Sprintf("%s.", imported.LocalName)
Expand Down Expand Up @@ -345,7 +345,7 @@ func (p *printer) printComponentMetadata(doc *astro.Node, source []byte) {

// Hydrated Components
p.print(", hydratedComponents: [")
for i, node := range doc.Metadata.HydratedComponents {
for i, node := range doc.HydratedComponents {
if i > 0 {
p.print(", ")
}
Expand Down
4 changes: 2 additions & 2 deletions internal/transform/transform.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ func AddComponentProps(doc *tycho.Node, n *tycho.Node) {

if strings.HasPrefix(attr.Key, "client:") {
if attr.Key == "client:only" {
doc.Metadata.ClientOnlyComponents = append([]*tycho.Node{n}, doc.Metadata.ClientOnlyComponents...)
doc.ClientOnlyComponents = append([]*tycho.Node{n}, doc.ClientOnlyComponents...)
break
}
// prepend node to maintain authored order
doc.Metadata.HydratedComponents = append([]*tycho.Node{n}, doc.Metadata.HydratedComponents...)
doc.HydratedComponents = append([]*tycho.Node{n}, doc.HydratedComponents...)
pathAttr := tycho.Attribute{
Key: "client:component-path",
Val: fmt.Sprintf("$$metadata.getPath(%s)", id),
Expand Down

0 comments on commit 432eaaf

Please sign in to comment.