Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incorrect table parsing when it contains expressions in certain cases #925

Merged
merged 7 commits into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/perfect-fishes-cover.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/compiler': patch
---

Fixes an issue where a `tr` element which contained an expression would cause its parent table to swallow any trailing element inside said table
14 changes: 2 additions & 12 deletions internal/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,7 @@ func inHeadIM(p *parser) bool {
return true
}
p.tok.Data = s
return textIM(p)
} else if p.oe.top() != nil && (isComponent(p.oe.top().Data) || isFragment((p.oe.top().Data))) {
p.addText(p.tok.Data)
return true
Expand Down Expand Up @@ -2735,10 +2736,6 @@ func inLiteralIM(p *parser) bool {
}

func inExpressionIM(p *parser) bool {
if p.oe.contains(a.Table) {
p.clearActiveFormattingElements()
return inLiteralIM(p)
}
switch p.tok.Type {
case ErrorToken:
p.oe.pop()
Expand Down Expand Up @@ -2785,14 +2782,7 @@ func inExpressionIM(p *parser) bool {
case EndExpressionToken:
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
}
p.resetInsertionMode()
return true
case CommentToken:
p.addChild(&Node{
Expand Down
14 changes: 10 additions & 4 deletions internal/printer/printer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2019,8 +2019,6 @@ const content = "lol";
`,
want: want{
frontmatter: []string{"", `const content = "lol";`},
// TODO: This output is INCORRECT, but we're testing a regression
// The trailing text (`Hello`) shouldn't be consumed by the <table> element!
code: `<html>
${$$maybeRenderHead($$result)}<body>
<table>
Expand All @@ -2033,8 +2031,9 @@ const content = "lol";
<td>1</td>
</tr>` + BACKTICK + `
)
} Hello
</table></body>
}
</table>Hello
</body>
</html>`,
},
},
Expand All @@ -2056,6 +2055,13 @@ const items = ["Dog", "Cat", "Platipus"];
code: `${$$maybeRenderHead($$result)}<table><caption>${title}</caption><tr><td>Hello</td></tr></table>`,
},
},
{
name: "table expression with trailing div",
source: `<table><tr><td>{title}</td></tr></table><div>Div</div>`,
want: want{
code: `${$$maybeRenderHead($$result)}<table><tr><td>${title}</td></tr></table><div>Div</div>`,
},
},
{
name: "tbody expressions",
source: `---
Expand Down
Loading