Skip to content

Commit

Permalink
Fix fragment in tr printing incorrect output (#926)
Browse files Browse the repository at this point in the history
* add test case

* handle  fragments in tables

* WIP: use incorrect white space  for tests to pass

* bring back expected white space in test

* appropriate whitespace fix

* chore: changeset

---------

Co-authored-by: Nate Moore <[email protected]>
  • Loading branch information
MoustaphaDev and natemoo-re committed Jan 4, 2024
1 parent b52f7d1 commit f9373f2
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/plenty-mice-beam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/compiler': patch
---

Fixes an issue where Astro fragments used inside a `table` element would cause lots of missing pieces of markup
3 changes: 1 addition & 2 deletions internal/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -1785,10 +1785,9 @@ func inTableIM(p *parser) bool {
p.im = inExpressionIM
return true
case StartTagToken:
if isComponent(p.tok.Data) {
if isComponent(p.tok.Data) || isFragment(p.tok.Data) {
p.originalIM = inTableIM
p.im = inLiteralIM
p.exitLiteralIM = getExitLiteralFunc(p)
return false
}
switch p.tok.DataAtom {
Expand Down
93 changes: 93 additions & 0 deletions internal/printer/printer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2086,6 +2086,99 @@ const content = "lol";
}
</table>Hello
</body>
</html>`,
},
},
{
name: "complex table",
source: `<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width" />
<title>Astro Multi Table</title>
</head>
<body>
<main>
<section>
{Array(3).fill(false).map((item, idx) => <div>
<div class="row">
{'a'}
<table>
<thead>
<tr>
<>{Array(7).fill(false).map((entry, index) => <th>A</th>)}</>
</tr>
</thead>
<tbody>
<tr><td></td></tr>
</tbody>
</table>
</div>
</div>)}
</section>
<section>
<div class="row">
<table>
<thead>
<tr>
<th>B</th>
<th>B</th>
<th>B</th>
</tr>
</thead>
<tbody>
<tr><td></td></tr>
</tbody>
</table>
</div>
</section>
</main>
</body>
</html>`,
want: want{
code: `<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<title>Astro Multi Table</title>
${$$renderHead($$result)}</head>
<body>
<main>
<section>
${Array(3).fill(false).map((item, idx) => $$render` + BACKTICK + `<div>
<div class="row">
${'a'}
<table>
<thead>
<tr>
${$$renderComponent($$result,'Fragment',Fragment,{},{"default": () => $$render` + BACKTICK + `${Array(7).fill(false).map((entry, index) => $$render` + BACKTICK + `<th>A</th>` + BACKTICK + `)}` + BACKTICK + `,})}
</tr>
</thead>
<tbody>
<tr><td></td></tr>
</tbody>
</table>
</div>
</div>` + BACKTICK + `)}
</section>
<section>
<div class="row">
<table>
<thead>
<tr>
<th>B</th>
<th>B</th>
<th>B</th>
</tr>
</thead>
<tbody>
<tr><td></td></tr>
</tbody>
</table>
</div>
</section>
</main>
</body>
</html>`,
},
},
Expand Down

0 comments on commit f9373f2

Please sign in to comment.