Skip to content

Commit

Permalink
fix: handle nil pointer when expression is final node in file
Browse files Browse the repository at this point in the history
  • Loading branch information
natemoo-re committed Dec 15, 2023
1 parent ee569ee commit 382e835
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/big-crabs-burn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/compiler': patch
---

Fixes a memory reference error when an expression is the final node in a file
3 changes: 3 additions & 0 deletions internal/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -2786,6 +2786,9 @@ func inExpressionIM(p *parser) bool {
p.addLoc()
p.oe.pop()
nextOpenElement := p.oe.top()
if nextOpenElement == nil {
return true
}
// only switch the insertion mode when we're no longer inside an expression
if !nextOpenElement.Parent.Expression {
p.im = textIM
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 @@ -2950,6 +2950,13 @@ 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: "trailing expression",
source: `<Component />{}`,
want: want{
code: `${$$renderComponent($$result,'Component',Component,{})}${(void 0)}`,
},
},
}

for _, tt := range tests {
Expand Down

0 comments on commit 382e835

Please sign in to comment.