diff --git a/.changeset/perfect-fishes-cover.md b/.changeset/perfect-fishes-cover.md new file mode 100644 index 000000000..14d4128b7 --- /dev/null +++ b/.changeset/perfect-fishes-cover.md @@ -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 diff --git a/internal/parser.go b/internal/parser.go index ff9d783fa..78efb09ec 100644 --- a/internal/parser.go +++ b/internal/parser.go @@ -788,6 +788,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 @@ -2730,10 +2731,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() @@ -2780,14 +2777,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{ diff --git a/internal/printer/printer_test.go b/internal/printer/printer_test.go index 21d11faf7..5d177d6bb 100644 --- a/internal/printer/printer_test.go +++ b/internal/printer/printer_test.go @@ -2020,8 +2020,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 element! code: ` ${$$maybeRenderHead($$result)}
@@ -2034,8 +2032,9 @@ const content = "lol"; ` + BACKTICK + ` ) - } Hello -
1
+ } + Hello + `, }, }, @@ -2057,6 +2056,13 @@ const items = ["Dog", "Cat", "Platipus"]; code: `${$$maybeRenderHead($$result)}
${title}
Hello
`, }, }, + { + name: "table expression with trailing div", + source: `
{title}
Div
`, + want: want{ + code: `${$$maybeRenderHead($$result)}
${title}
Div
`, + }, + }, { name: "tbody expressions", source: `---