Skip to content

Commit

Permalink
Handle slot before <head> (#540)
Browse files Browse the repository at this point in the history
* fix(#531): handle slots before <head>

* chore: add changeset

* chore: update test

Co-authored-by: Nate Moore <[email protected]>
  • Loading branch information
natemoo-re and natemoo-re authored Oct 5, 2022
1 parent 52ebfb7 commit 8ee78a6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/nervous-ducks-fetch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/compiler': patch
---

handle slots that contains the head element
8 changes: 8 additions & 0 deletions internal/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,14 @@ func beforeHeadIM(p *parser) bool {
return true
case StartTagToken:
switch p.tok.DataAtom {
case a.Slot:
p.addElement()
if p.hasSelfClosingToken {
p.addLoc()
p.oe.pop()
p.acknowledgeSelfClosingTag()
}
return true
case a.Head:
p.addElement()
p.head = p.top()
Expand Down
7 changes: 7 additions & 0 deletions internal/printer/printer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,13 @@ func TestPrinter(t *testing.T) {
code: `<html><head><title>Ah</title>` + RENDER_HEAD_RESULT + `</head></html>`,
},
},
{
name: "head inside slot",
source: `<html><slot><head></head></slot></html>`,
want: want{
code: `<html>${$$renderSlot($$result,$$slots["default"],$$render` + BACKTICK + `<head>` + RENDER_HEAD_RESULT + `</head>` + BACKTICK + `)}</html>`,
},
},
{
name: "head slot",
source: `<html><head><slot /></html>`,
Expand Down

0 comments on commit 8ee78a6

Please sign in to comment.