From 4e73c66a6848c3318dcce40cf5042129fc11f106 Mon Sep 17 00:00:00 2001 From: Moustapha HappyDev Date: Tue, 9 Jan 2024 09:32:35 +0000 Subject: [PATCH 1/4] add test --- internal/printer/printer_test.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/internal/printer/printer_test.go b/internal/printer/printer_test.go index f43b34da3..b5380effa 100644 --- a/internal/printer/printer_test.go +++ b/internal/printer/printer_test.go @@ -2486,6 +2486,20 @@ const items = ["Dog", "Cat", "Platipus"]; code: `${$$maybeRenderHead($$result)}(${(void 0) })`, }, }, + { + name: "expression with leading whitespace", + source: `
+ +
`, + want: want{ + code: "${$$maybeRenderHead($$result)}
\n\n
", + }, + }, { name: "Empty attribute expression", source: "", From e0e0740950b7165ab8407a380916b386c11e3faf Mon Sep 17 00:00:00 2001 From: Moustapha HappyDev Date: Tue, 9 Jan 2024 09:35:06 +0000 Subject: [PATCH 2/4] check expressions' first child siblings are empty --- internal/printer/print-to-js.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/internal/printer/print-to-js.go b/internal/printer/print-to-js.go index 414510539..c43b0d8b2 100644 --- a/internal/printer/print-to-js.go +++ b/internal/printer/print-to-js.go @@ -316,11 +316,7 @@ func render1(p *printer, n *Node, opts RenderOptions) { // Tip! Comment this block out to debug expressions if n.Expression { - clean := "" - if n.FirstChild != nil { - clean = strings.TrimSpace(n.FirstChild.Data) - } - if n.FirstChild == nil || clean == "" { + if n.FirstChild == nil || emptyTextNodeWithoutSiblings(n.FirstChild) { p.print("${(void 0)") } else if expressionOnlyHasComment(n) { // we do not print expressions that only contain comment blocks From 0af1a35b2d4be2d22e319bd3ee3ed9c8b1835cf4 Mon Sep 17 00:00:00 2001 From: Moustapha HappyDev Date: Tue, 9 Jan 2024 09:36:54 +0000 Subject: [PATCH 3/4] chore: changeset --- .changeset/strong-chairs-walk.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/strong-chairs-walk.md diff --git a/.changeset/strong-chairs-walk.md b/.changeset/strong-chairs-walk.md new file mode 100644 index 000000000..c75f7c7dc --- /dev/null +++ b/.changeset/strong-chairs-walk.md @@ -0,0 +1,5 @@ +--- +'@astrojs/compiler': patch +--- + +Fix expression regression when the first child of an expression is whitespace and is followed by any other node From 2967451e4b1d5de7ddc677f741334e1c7bbc9389 Mon Sep 17 00:00:00 2001 From: Moustapha HappyDev Date: Tue, 9 Jan 2024 09:49:29 +0000 Subject: [PATCH 4/4] simplify changeset --- .changeset/strong-chairs-walk.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/strong-chairs-walk.md b/.changeset/strong-chairs-walk.md index c75f7c7dc..57d443431 100644 --- a/.changeset/strong-chairs-walk.md +++ b/.changeset/strong-chairs-walk.md @@ -2,4 +2,4 @@ '@astrojs/compiler': patch --- -Fix expression regression when the first child of an expression is whitespace and is followed by any other node +Fixes a bug where expressions starting with whitespace, followed by anything else, weren't printed correctly.