From 9c918ad531ac6fe25c1c99211dacbf7e0595d308 Mon Sep 17 00:00:00 2001
From: Nate Moore
Date: Thu, 11 Jan 2024 12:38:31 -0600
Subject: [PATCH 01/30] fix(#935): set transform to literal mode
---
.changeset/shiny-plums-smile.md | 5 ++++
cmd/astro-wasm/astro-wasm.go | 6 ++---
internal/printer/printer_test.go | 15 +++++++++++-
internal/transform/transform.go | 3 +--
internal/transform/transform_test.go | 18 +++++++++-----
.../compiler/test/basic/body-in-component.ts | 24 +++++++++++++++++++
.../compiler/test/basic/trailing-spaces-ii.ts | 2 +-
7 files changed, 60 insertions(+), 13 deletions(-)
create mode 100644 .changeset/shiny-plums-smile.md
create mode 100644 packages/compiler/test/basic/body-in-component.ts
diff --git a/.changeset/shiny-plums-smile.md b/.changeset/shiny-plums-smile.md
new file mode 100644
index 000000000..c928011c1
--- /dev/null
+++ b/.changeset/shiny-plums-smile.md
@@ -0,0 +1,5 @@
+---
+'@astrojs/compiler': minor
+---
+
+Fixes an edge case that caused `html` and `body` tags with attributes to be ignored when they were wrapped in a component.
diff --git a/cmd/astro-wasm/astro-wasm.go b/cmd/astro-wasm/astro-wasm.go
index ce652b850..0e0c4c369 100644
--- a/cmd/astro-wasm/astro-wasm.go
+++ b/cmd/astro-wasm/astro-wasm.go
@@ -226,7 +226,7 @@ func Parse() any {
h := handler.NewHandler(source, parseOptions.Filename)
var doc *astro.Node
- doc, err := astro.ParseWithOptions(strings.NewReader(source), astro.ParseOptionWithHandler(h), astro.ParseOptionEnableLiteral(true))
+ doc, err := astro.ParseWithOptions(strings.NewReader(source), astro.ParseOptionEnableLiteral(true), astro.ParseOptionWithHandler(h))
if err != nil {
h.AppendError(err)
}
@@ -250,7 +250,7 @@ func ConvertToTSX() any {
h := handler.NewHandler(source, transformOptions.Filename)
var doc *astro.Node
- doc, err := astro.ParseWithOptions(strings.NewReader(source), astro.ParseOptionWithHandler(h), astro.ParseOptionEnableLiteral(true))
+ doc, err := astro.ParseWithOptions(strings.NewReader(source), astro.ParseOptionEnableLiteral(true), astro.ParseOptionWithHandler(h))
if err != nil {
h.AppendError(err)
}
@@ -301,7 +301,7 @@ func Transform() any {
}
}()
- doc, err := astro.ParseWithOptions(strings.NewReader(source), astro.ParseOptionWithHandler(h))
+ doc, err := astro.ParseWithOptions(strings.NewReader(source), astro.ParseOptionEnableLiteral(true), astro.ParseOptionWithHandler(h))
if err != nil {
reject.Invoke(wasm_utils.ErrorToJSError(h, err))
return
diff --git a/internal/printer/printer_test.go b/internal/printer/printer_test.go
index b5380effa..b54c28581 100644
--- a/internal/printer/printer_test.go
+++ b/internal/printer/printer_test.go
@@ -1411,6 +1411,14 @@ const name = 'named';
code: "${cond && $$render``}${cond && $$render`My title`}",
},
},
+ {
+ name: "top-level component does not drop body attributes",
+ source: ``,
+ only: true,
+ want: want{
+ code: "${$$renderComponent($$result,'Base',Base,{},{\"default\": () => $$render`${$$maybeRenderHead($$result)}${$$renderSlot($$result,$$slots[\"default\"])}`,})}",
+ },
+ },
{
name: "custom elements",
source: `---
@@ -3227,8 +3235,8 @@ const items = ["Dog", "Cat", "Platipus"];
// transform output from source
code := test_utils.Dedent(tt.source)
- doc, err := astro.Parse(strings.NewReader(code))
h := handler.NewHandler(code, "")
+ doc, err := astro.ParseWithOptions(strings.NewReader(code), astro.ParseOptionEnableLiteral(true), astro.ParseOptionWithHandler(h))
if err != nil {
t.Error(err)
@@ -3481,6 +3489,11 @@ const c = '\''
source: ``,
want: []ASTNode{{Type: "element", Name: "main", Attributes: []ASTNode{{Type: "attribute", Kind: "template-literal", Name: "id", Value: "gotcha", Raw: "`gotcha"}}}},
},
+ {
+ name: "top-level component does not drop body attributes",
+ source: ``,
+ want: []ASTNode{{Type: "component", Name: "Base", Attributes: []ASTNode{}, Children: []ASTNode{{Type: "element", Name: "body", Attributes: []ASTNode{{Type: "attribute", Kind: "quoted", Name: "class", Value: "foobar", Raw: "\"foobar\""}}, Children: []ASTNode{{Type: "element", Name: "slot"}}}}}},
+ },
}
for _, tt := range tests {
diff --git a/internal/transform/transform.go b/internal/transform/transform.go
index d4240adbb..fedf82760 100644
--- a/internal/transform/transform.go
+++ b/internal/transform/transform.go
@@ -234,7 +234,7 @@ func TrimTrailingSpace(doc *astro.Node) {
return
}
- if doc.LastChild.Type == astro.TextNode {
+ if doc.LastChild.Type == astro.TextNode && len(doc.LastChild.Data) < len(strings.TrimRightFunc(doc.LastChild.Data, unicode.IsSpace)) {
doc.LastChild.Data = strings.TrimRightFunc(doc.LastChild.Data, unicode.IsSpace)
return
}
@@ -246,7 +246,6 @@ func TrimTrailingSpace(doc *astro.Node) {
n = n.LastChild
continue
} else {
- n = nil
break
}
}
diff --git a/internal/transform/transform_test.go b/internal/transform/transform_test.go
index a52dc11b6..2eaf49e41 100644
--- a/internal/transform/transform_test.go
+++ b/internal/transform/transform_test.go
@@ -253,13 +253,13 @@ func TestFullTransform(t *testing.T) {
},
{
name: "Component before html I",
- source: `Astro
`,
- want: `Astro
`,
+ source: `Astro
`,
+ want: `Astro
`,
},
{
name: "Component before html II",
source: ``,
- want: ``,
+ want: ``,
},
{
name: "respects explicitly authored elements",
@@ -281,6 +281,11 @@ func TestFullTransform(t *testing.T) {
source: ``,
want: ``,
},
+ {
+ name: "top-level component does not drop body attributes",
+ source: ``,
+ want: ``,
+ },
{
name: "works with nested components",
source: `
`,
@@ -302,7 +307,7 @@ func TestFullTransform(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
b.Reset()
- doc, err := astro.Parse(strings.NewReader(tt.source))
+ doc, err := astro.ParseWithOptions(strings.NewReader(tt.source), astro.ParseOptionEnableLiteral(true))
if err != nil {
t.Error(err)
}
@@ -513,11 +518,12 @@ func TestAnnotation(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
b.Reset()
- doc, err := astro.Parse(strings.NewReader(tt.source))
+
+ h := handler.NewHandler(tt.source, "/src/pages/index.astro")
+ doc, err := astro.ParseWithOptions(strings.NewReader(tt.source), astro.ParseOptionEnableLiteral(true), astro.ParseOptionWithHandler(h))
if err != nil {
t.Error(err)
}
- h := handler.NewHandler(tt.source, "/src/pages/index.astro")
Transform(doc, TransformOptions{
AnnotateSourceFile: true,
Filename: "/src/pages/index.astro",
diff --git a/packages/compiler/test/basic/body-in-component.ts b/packages/compiler/test/basic/body-in-component.ts
new file mode 100644
index 000000000..5776a1c8e
--- /dev/null
+++ b/packages/compiler/test/basic/body-in-component.ts
@@ -0,0 +1,24 @@
+import { test } from 'uvu';
+import * as assert from 'uvu/assert';
+import { transform } from '@astrojs/compiler';
+
+const FIXTURE = `
+---
+let value = 'world';
+---
+
+
+`;
+
+let result;
+test.before(async () => {
+ result = await transform(FIXTURE);
+});
+
+test('top-level component does not drop body attributes', () => {
+ console.log(result.code);
+ assert.match(result.code, "${$$renderComponent($$result,'Base',Base,{},{\"default\": () => $$render`${$$maybeRenderHead($$result)}${$$renderSlot($$result,$$slots[\"default\"])}`,})}", `Expected body to be included!`);
+});
+
+
+test.run();
diff --git a/packages/compiler/test/basic/trailing-spaces-ii.ts b/packages/compiler/test/basic/trailing-spaces-ii.ts
index 198626215..44277dcb2 100644
--- a/packages/compiler/test/basic/trailing-spaces-ii.ts
+++ b/packages/compiler/test/basic/trailing-spaces-ii.ts
@@ -23,7 +23,7 @@ test.before(async () => {
});
test('trailing space', () => {
- assert.ok(result.code, 'Expected to compiler');
+ assert.ok(result.code, 'Expected to compile');
assert.match(
result.code,
`
From cff221c92e90a335d45a9825216bb9f613b0ad2f Mon Sep 17 00:00:00 2001
From: Nate Moore
Date: Thu, 11 Jan 2024 15:13:01 -0600
Subject: [PATCH 02/30] fix: whitespace handling
---
internal/transform/transform.go | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/internal/transform/transform.go b/internal/transform/transform.go
index fedf82760..e7e81e12b 100644
--- a/internal/transform/transform.go
+++ b/internal/transform/transform.go
@@ -253,7 +253,11 @@ func TrimTrailingSpace(doc *astro.Node) {
// Collapse all trailing text nodes
for n != nil && n.Type == astro.TextNode {
n.Data = strings.TrimRightFunc(n.Data, unicode.IsSpace)
- n = n.PrevSibling
+ if len(n.Data) > 0 {
+ break
+ } else {
+ n = n.PrevSibling
+ }
}
}
From eaa580a962c7f81a47510091a2aab93c79c2e745 Mon Sep 17 00:00:00 2001
From: Nate Moore
Date: Thu, 11 Jan 2024 15:13:21 -0600
Subject: [PATCH 03/30] chore: remove only
---
internal/printer/printer_test.go | 1 -
1 file changed, 1 deletion(-)
diff --git a/internal/printer/printer_test.go b/internal/printer/printer_test.go
index b54c28581..d989c7de7 100644
--- a/internal/printer/printer_test.go
+++ b/internal/printer/printer_test.go
@@ -1414,7 +1414,6 @@ const name = 'named';
{
name: "top-level component does not drop body attributes",
source: ``,
- only: true,
want: want{
code: "${$$renderComponent($$result,'Base',Base,{},{\"default\": () => $$render`${$$maybeRenderHead($$result)}${$$renderSlot($$result,$$slots[\"default\"])}`,})}",
},
From 4abbf3c61c067a4e1baef226c2e1688353a1d890 Mon Sep 17 00:00:00 2001
From: Nate Moore
Date: Thu, 11 Jan 2024 16:28:48 -0600
Subject: [PATCH 04/30] chore: fix test typos
---
internal/printer/printer_test.go | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/internal/printer/printer_test.go b/internal/printer/printer_test.go
index d989c7de7..8905eb08f 100644
--- a/internal/printer/printer_test.go
+++ b/internal/printer/printer_test.go
@@ -226,7 +226,7 @@ func TestPrinter(t *testing.T) {
},
{
name: "slot with fallback",
- source: `Hello world!
`,
+ source: `Hello world!
`,
want: want{
code: `${$$maybeRenderHead($$result)}${$$renderSlot($$result,$$slots["default"],$$render` + BACKTICK + `Hello world!
` + BACKTICK + `)}`,
},
@@ -1477,7 +1477,7 @@ ${$$renderComponent($$result,'my-element','my-element',{"client:load":true,"clie
},
{
name: "Self-closing script in head works",
- source: ``,
+ source: ``,
want: want{
code: `` + RENDER_HEAD_RESULT + ``,
},
@@ -1498,7 +1498,7 @@ ${$$renderComponent($$result,'my-element','my-element',{"client:load":true,"clie
},
{
name: "Self-closing components in head can have siblings",
- source: ``,
+ source: ``,
want: want{
code: `${$$renderComponent($$result,'BaseHead',BaseHead,{})}` + RENDER_HEAD_RESULT + ``,
},
From 2b06c85715e347dc9355f91afd05f393e54e6372 Mon Sep 17 00:00:00 2001
From: Nate Moore
Date: Thu, 11 Jan 2024 16:29:03 -0600
Subject: [PATCH 05/30] chore: add regression test for tokenizer
---
internal/token_test.go | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/internal/token_test.go b/internal/token_test.go
index 39992f6b9..8ab374fff 100644
--- a/internal/token_test.go
+++ b/internal/token_test.go
@@ -500,6 +500,11 @@ func TestBasic(t *testing.T) {
`Hello world!
`,
+ []TokenType{StartTagToken, StartTagToken, StartTagToken, TextToken, EndTagToken, EndTagToken, EndTagToken},
+ },
}
runTokenTypeTest(t, Basic)
From 58888df98a17913bdf34b1553fa4ab22ca5c5155 Mon Sep 17 00:00:00 2001
From: Moustapha HappyDev
Date: Thu, 29 Feb 2024 21:10:53 +0000
Subject: [PATCH 06/30] test: fix incorrect tests
---
internal/printer/printer_test.go | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/internal/printer/printer_test.go b/internal/printer/printer_test.go
index d34175d27..767089717 100644
--- a/internal/printer/printer_test.go
+++ b/internal/printer/printer_test.go
@@ -568,9 +568,9 @@ import type data from "test"
div+h2 ${dummyKey}
-
p+h2 ${dummyKey}
- ` + BACKTICK + `
- );
+ p+h2 ${dummyKey}
+
` + BACKTICK + `
+ );
})
}
@@ -588,8 +588,8 @@ import type data from "test"
want: want{
code: `
${$$maybeRenderHead($$result)}
-${Object.keys(importedAuthors).map(author => $$render` + BACKTICK + `hello
` + BACKTICK + `)}
-${Object.keys(importedAuthors).map(author => $$render` + BACKTICK + `${author}
` + BACKTICK + `)}
+${Object.keys(importedAuthors).map(author => $$render` + BACKTICK + `hello
` + BACKTICK + `)}
+${Object.keys(importedAuthors).map(author => $$render` + BACKTICK + `${author}
` + BACKTICK + `)}
`,
},
@@ -2089,7 +2089,7 @@ import { Container, Col, Row } from 'react-bootstrap';
name: "Preserve namespaces in expressions",
source: ``,
want: want{
- code: `${$$maybeRenderHead($$result)}`,
+ code: `${$$maybeRenderHead($$result)}`,
},
},
{
From 1c00621b74f7e4efa7148ddd34b646127ca7d32e Mon Sep 17 00:00:00 2001
From: Moustapha HappyDev
Date: Thu, 29 Feb 2024 21:18:49 +0000
Subject: [PATCH 07/30] test: add test for #958
---
internal/printer/printer_test.go | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/internal/printer/printer_test.go b/internal/printer/printer_test.go
index 767089717..ed72d65fc 100644
--- a/internal/printer/printer_test.go
+++ b/internal/printer/printer_test.go
@@ -2304,6 +2304,25 @@ const content = "lol";
`,
},
},
+ {
+ name: "#958",
+ source: `
+
+`,
+ want: want{
+ code: `${$$maybeRenderHead($$result)}
+
+`,
+ },
+ },
{
name: "complex table",
source: `
From b827dbb4e50a4232d17fbde97cc02ed4f091f503 Mon Sep 17 00:00:00 2001
From: Moustapha HappyDev
Date: Fri, 1 Mar 2024 03:36:25 +0000
Subject: [PATCH 08/30] refactor `addFrontmatter`
---
internal/parser.go | 19 ++++---------------
1 file changed, 4 insertions(+), 15 deletions(-)
diff --git a/internal/parser.go b/internal/parser.go
index 18275683a..a413e502c 100644
--- a/internal/parser.go
+++ b/internal/parser.go
@@ -354,7 +354,7 @@ func (p *parser) addText(text string) {
})
}
-func (p *parser) addFrontmatter(empty bool) {
+func (p *parser) addFrontmatter() {
if p.frontmatterState == FrontmatterInitial {
if p.doc.FirstChild != nil {
p.fm = &Node{
@@ -369,13 +369,8 @@ func (p *parser) addFrontmatter(empty bool) {
}
p.doc.AppendChild(p.fm)
}
- if empty {
- p.frontmatterState = FrontmatterClosed
- p.fm.Attr = append(p.fm.Attr, Attribute{Key: ImplicitNodeMarker, Type: EmptyAttribute})
- } else {
- p.frontmatterState = FrontmatterOpen
- p.oe = append(p.oe, p.fm)
- }
+ p.frontmatterState = FrontmatterOpen
+ p.oe = append(p.oe, p.fm)
}
}
@@ -646,9 +641,6 @@ func initialIM(p *parser) bool {
p.im = beforeHTMLIM
return true
}
- if p.frontmatterState == FrontmatterInitial {
- p.addFrontmatter(true)
- }
p.quirks = true
p.im = beforeHTMLIM
return false
@@ -1534,9 +1526,6 @@ func inBodyIM(p *parser) bool {
}
}
}
- if p.frontmatterState == FrontmatterInitial {
- p.addFrontmatter(true)
- }
return true
}
@@ -2642,7 +2631,7 @@ func frontmatterIM(p *parser) bool {
switch p.tok.Type {
case FrontmatterFenceToken:
if p.frontmatterState == FrontmatterInitial {
- p.addFrontmatter(false)
+ p.addFrontmatter()
return true
} else {
p.frontmatterState = FrontmatterClosed
From 85fa4dc345560a4cb791db358083b153945e515b Mon Sep 17 00:00:00 2001
From: Moustapha HappyDev
Date: Fri, 1 Mar 2024 03:36:43 +0000
Subject: [PATCH 09/30] test: add json test case
---
internal/printer/printer_test.go | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/internal/printer/printer_test.go b/internal/printer/printer_test.go
index ed72d65fc..2528657d2 100644
--- a/internal/printer/printer_test.go
+++ b/internal/printer/printer_test.go
@@ -3764,6 +3764,11 @@ const c = '\''
source: `Hello world!
`,
want: []ASTNode{{Type: "element", Name: "style"}, {Type: "element", Name: "html", Children: []ASTNode{{Type: "element", Name: "body", Children: []ASTNode{{Type: "element", Name: "h1", Children: []ASTNode{{Type: "text", Value: "Hello world!"}}}}}}}},
},
+ {
+ name: "empty style",
+ source: ``,
+ want: []ASTNode{{Type: "element", Name: "style", Attributes: []ASTNode{{Type: "attribute", Kind: "expression", Name: "define:vars", Value: "{ color: \"Gainsboro\" }"}}}},
+ },
{
name: "style after html",
source: `Hello world!
`,
From 2b93f834fa234e77717585c4500175ff2b39fea8 Mon Sep 17 00:00:00 2001
From: Moustapha HappyDev
Date: Fri, 1 Mar 2024 18:30:45 +0000
Subject: [PATCH 10/30] update transition scopes
---
internal/printer/printer_test.go | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/internal/printer/printer_test.go b/internal/printer/printer_test.go
index 2528657d2..207b63a98 100644
--- a/internal/printer/printer_test.go
+++ b/internal/printer/printer_test.go
@@ -3470,7 +3470,7 @@ const items = ["Dog", "Cat", "Platipus"];
filename: "/projects/app/src/pages/page.astro",
transitions: true,
want: want{
- code: `${$$maybeRenderHead($$result)}`,
+ code: `${$$maybeRenderHead($$result)}`,
},
},
{
@@ -3479,7 +3479,7 @@ const items = ["Dog", "Cat", "Platipus"];
filename: "/projects/app/src/pages/page.astro",
transitions: true,
want: want{
- code: `${$$maybeRenderHead($$result)}`,
+ code: `${$$maybeRenderHead($$result)}`,
},
},
{
@@ -3488,7 +3488,7 @@ const items = ["Dog", "Cat", "Platipus"];
filename: "/projects/app/src/pages/page.astro",
transitions: true,
want: want{
- code: `${$$maybeRenderHead($$result)}`,
+ code: `${$$maybeRenderHead($$result)}`,
},
},
{
@@ -3497,7 +3497,7 @@ const items = ["Dog", "Cat", "Platipus"];
filename: "/projects/app/src/pages/page.astro",
transitions: true,
want: want{
- code: `${$$renderComponent($$result,'Component',Component,{"class":"bar","data-astro-transition-scope":($$renderTransition($$result, "wkm5vset", "morph", ""))})}`,
+ code: `${$$renderComponent($$result,'Component',Component,{"class":"bar","data-astro-transition-scope":($$renderTransition($$result, "byigm4lx", "morph", ""))})}`,
},
},
{
@@ -3505,7 +3505,7 @@ const items = ["Dog", "Cat", "Platipus"];
source: ``,
transitions: true,
want: want{
- code: `${$$maybeRenderHead($$result)}`,
+ code: `${$$maybeRenderHead($$result)}`,
},
},
{
@@ -3513,7 +3513,7 @@ const items = ["Dog", "Cat", "Platipus"];
source: ``,
transitions: true,
want: want{
- code: `${$$maybeRenderHead($$result)}`,
+ code: `${$$maybeRenderHead($$result)}`,
},
},
{
From 34dddcd9d3a76f30ea4f70fe420814b35143fb76 Mon Sep 17 00:00:00 2001
From: Moustapha HappyDev
Date: Fri, 1 Mar 2024 18:35:23 +0000
Subject: [PATCH 11/30] test: fix incorrect tests
---
internal/printer/printer_test.go | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/internal/printer/printer_test.go b/internal/printer/printer_test.go
index d34175d27..767089717 100644
--- a/internal/printer/printer_test.go
+++ b/internal/printer/printer_test.go
@@ -568,9 +568,9 @@ import type data from "test"
div+h2 ${dummyKey}
-
p+h2 ${dummyKey}
- ` + BACKTICK + `
- );
+ p+h2 ${dummyKey}
+ ` + BACKTICK + `
+ );
})
}
@@ -588,8 +588,8 @@ import type data from "test"
want: want{
code: `
${$$maybeRenderHead($$result)}
-${Object.keys(importedAuthors).map(author => $$render` + BACKTICK + `hello
` + BACKTICK + `)}
-${Object.keys(importedAuthors).map(author => $$render` + BACKTICK + `${author}
` + BACKTICK + `)}
+${Object.keys(importedAuthors).map(author => $$render` + BACKTICK + `hello
` + BACKTICK + `)}
+${Object.keys(importedAuthors).map(author => $$render` + BACKTICK + `${author}
` + BACKTICK + `)}
`,
},
@@ -2089,7 +2089,7 @@ import { Container, Col, Row } from 'react-bootstrap';
name: "Preserve namespaces in expressions",
source: ``,
want: want{
- code: `${$$maybeRenderHead($$result)}`,
+ code: `${$$maybeRenderHead($$result)}`,
},
},
{
From 3d2f26357dde56e674763a4797fb0f07ebbe1c0c Mon Sep 17 00:00:00 2001
From: Moustapha HappyDev
Date: Fri, 1 Mar 2024 18:35:58 +0000
Subject: [PATCH 12/30] test: add test for #958
---
internal/printer/printer_test.go | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/internal/printer/printer_test.go b/internal/printer/printer_test.go
index 767089717..ed72d65fc 100644
--- a/internal/printer/printer_test.go
+++ b/internal/printer/printer_test.go
@@ -2304,6 +2304,25 @@ const content = "lol";
`,
},
},
+ {
+ name: "#958",
+ source: `
+
+`,
+ want: want{
+ code: `${$$maybeRenderHead($$result)}
+
+`,
+ },
+ },
{
name: "complex table",
source: `
From 9b1def4d2fc105e5a1bae3e13c945d99b85b29d4 Mon Sep 17 00:00:00 2001
From: Moustapha HappyDev
Date: Fri, 1 Mar 2024 18:36:27 +0000
Subject: [PATCH 13/30] test: add json test case
---
internal/printer/printer_test.go | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/internal/printer/printer_test.go b/internal/printer/printer_test.go
index ed72d65fc..2528657d2 100644
--- a/internal/printer/printer_test.go
+++ b/internal/printer/printer_test.go
@@ -3764,6 +3764,11 @@ const c = '\''
source: `Hello world!
`,
want: []ASTNode{{Type: "element", Name: "style"}, {Type: "element", Name: "html", Children: []ASTNode{{Type: "element", Name: "body", Children: []ASTNode{{Type: "element", Name: "h1", Children: []ASTNode{{Type: "text", Value: "Hello world!"}}}}}}}},
},
+ {
+ name: "empty style",
+ source: ``,
+ want: []ASTNode{{Type: "element", Name: "style", Attributes: []ASTNode{{Type: "attribute", Kind: "expression", Name: "define:vars", Value: "{ color: \"Gainsboro\" }"}}}},
+ },
{
name: "style after html",
source: `Hello world!
`,
From 51d7a6dd120350aae97dd61ea2b9269a83b31a9f Mon Sep 17 00:00:00 2001
From: Moustapha HappyDev
Date: Fri, 1 Mar 2024 18:36:59 +0000
Subject: [PATCH 14/30] test: update transition scopes
---
internal/printer/printer_test.go | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/internal/printer/printer_test.go b/internal/printer/printer_test.go
index 2528657d2..207b63a98 100644
--- a/internal/printer/printer_test.go
+++ b/internal/printer/printer_test.go
@@ -3470,7 +3470,7 @@ const items = ["Dog", "Cat", "Platipus"];
filename: "/projects/app/src/pages/page.astro",
transitions: true,
want: want{
- code: `${$$maybeRenderHead($$result)}`,
+ code: `${$$maybeRenderHead($$result)}`,
},
},
{
@@ -3479,7 +3479,7 @@ const items = ["Dog", "Cat", "Platipus"];
filename: "/projects/app/src/pages/page.astro",
transitions: true,
want: want{
- code: `${$$maybeRenderHead($$result)}`,
+ code: `${$$maybeRenderHead($$result)}`,
},
},
{
@@ -3488,7 +3488,7 @@ const items = ["Dog", "Cat", "Platipus"];
filename: "/projects/app/src/pages/page.astro",
transitions: true,
want: want{
- code: `${$$maybeRenderHead($$result)}`,
+ code: `${$$maybeRenderHead($$result)}`,
},
},
{
@@ -3497,7 +3497,7 @@ const items = ["Dog", "Cat", "Platipus"];
filename: "/projects/app/src/pages/page.astro",
transitions: true,
want: want{
- code: `${$$renderComponent($$result,'Component',Component,{"class":"bar","data-astro-transition-scope":($$renderTransition($$result, "wkm5vset", "morph", ""))})}`,
+ code: `${$$renderComponent($$result,'Component',Component,{"class":"bar","data-astro-transition-scope":($$renderTransition($$result, "byigm4lx", "morph", ""))})}`,
},
},
{
@@ -3505,7 +3505,7 @@ const items = ["Dog", "Cat", "Platipus"];
source: ``,
transitions: true,
want: want{
- code: `${$$maybeRenderHead($$result)}`,
+ code: `${$$maybeRenderHead($$result)}`,
},
},
{
@@ -3513,7 +3513,7 @@ const items = ["Dog", "Cat", "Platipus"];
source: ``,
transitions: true,
want: want{
- code: `${$$maybeRenderHead($$result)}`,
+ code: `${$$maybeRenderHead($$result)}`,
},
},
{
From e4178e20f000e35a0c520ac8376404bf7c52e380 Mon Sep 17 00:00:00 2001
From: Moustapha HappyDev
Date: Fri, 1 Mar 2024 18:37:14 +0000
Subject: [PATCH 15/30] refactor `addFrontmatter`
---
internal/parser.go | 19 ++++---------------
1 file changed, 4 insertions(+), 15 deletions(-)
diff --git a/internal/parser.go b/internal/parser.go
index 18275683a..a413e502c 100644
--- a/internal/parser.go
+++ b/internal/parser.go
@@ -354,7 +354,7 @@ func (p *parser) addText(text string) {
})
}
-func (p *parser) addFrontmatter(empty bool) {
+func (p *parser) addFrontmatter() {
if p.frontmatterState == FrontmatterInitial {
if p.doc.FirstChild != nil {
p.fm = &Node{
@@ -369,13 +369,8 @@ func (p *parser) addFrontmatter(empty bool) {
}
p.doc.AppendChild(p.fm)
}
- if empty {
- p.frontmatterState = FrontmatterClosed
- p.fm.Attr = append(p.fm.Attr, Attribute{Key: ImplicitNodeMarker, Type: EmptyAttribute})
- } else {
- p.frontmatterState = FrontmatterOpen
- p.oe = append(p.oe, p.fm)
- }
+ p.frontmatterState = FrontmatterOpen
+ p.oe = append(p.oe, p.fm)
}
}
@@ -646,9 +641,6 @@ func initialIM(p *parser) bool {
p.im = beforeHTMLIM
return true
}
- if p.frontmatterState == FrontmatterInitial {
- p.addFrontmatter(true)
- }
p.quirks = true
p.im = beforeHTMLIM
return false
@@ -1534,9 +1526,6 @@ func inBodyIM(p *parser) bool {
}
}
}
- if p.frontmatterState == FrontmatterInitial {
- p.addFrontmatter(true)
- }
return true
}
@@ -2642,7 +2631,7 @@ func frontmatterIM(p *parser) bool {
switch p.tok.Type {
case FrontmatterFenceToken:
if p.frontmatterState == FrontmatterInitial {
- p.addFrontmatter(false)
+ p.addFrontmatter()
return true
} else {
p.frontmatterState = FrontmatterClosed
From 0784dd755dd849ed6a1f9cb944e5df64aa433a10 Mon Sep 17 00:00:00 2001
From: Moustapha HappyDev
Date: Fri, 1 Mar 2024 18:51:05 +0000
Subject: [PATCH 16/30] test: add test for #971
---
internal/printer/printer_test.go | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/internal/printer/printer_test.go b/internal/printer/printer_test.go
index 207b63a98..3be0eb6f6 100644
--- a/internal/printer/printer_test.go
+++ b/internal/printer/printer_test.go
@@ -2323,6 +2323,19 @@ const content = "lol";
`,
},
},
+ {
+ name: "#971",
+ source: `
+ {text}.
+
+This should not be a link
`,
+ want: want{
+ code: `
+ ${$$maybeRenderHead($$result)}${text}.
+
+This should not be a link
`,
+ },
+ },
{
name: "complex table",
source: `
From abf1c11a1f95a5109e244868a98ff05a37bdf3d6 Mon Sep 17 00:00:00 2001
From: Moustapha HappyDev
Date: Fri, 1 Mar 2024 19:03:35 +0000
Subject: [PATCH 17/30] chore: proper name for added tests
---
internal/printer/printer_test.go | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/internal/printer/printer_test.go b/internal/printer/printer_test.go
index 3be0eb6f6..4bf5e59bf 100644
--- a/internal/printer/printer_test.go
+++ b/internal/printer/printer_test.go
@@ -2305,7 +2305,9 @@ const content = "lol";
},
},
{
- name: "#958",
+ // ensurethere are no duplicate elements matching the ones in the link below (`` in this test)
+ // https://github.com/withastro/compiler/blob/a90d99ee8cc3ad92d1b39d73df1f7301011ee970/internal/parser.go#L1490
+ name: " tag with expression in table ",
source: `
@@ -2324,7 +2326,9 @@ const content = "lol";
},
},
{
- name: "#971",
+ // makes sure that there are no duplicate elements matching the ones in the link below (`` in this test)
+ // https://github.com/withastro/compiler/blob/a90d99ee8cc3ad92d1b39d73df1f7301011ee970/internal/parser.go#L1490
+ name: " tag with expression in template",
source: `
{text}.
From 69706847f753dd22a64d5c7803823095a8aa9f89 Mon Sep 17 00:00:00 2001
From: Moustapha HappyDev
Date: Fri, 1 Mar 2024 22:52:03 +0000
Subject: [PATCH 18/30] chore: `only` helper for json test
---
internal/printer/printer_test.go | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/internal/printer/printer_test.go b/internal/printer/printer_test.go
index 4a43ce71e..2c02c2278 100644
--- a/internal/printer/printer_test.go
+++ b/internal/printer/printer_test.go
@@ -91,6 +91,7 @@ type jsonTestcase struct {
name string
source string
want []ASTNode
+ only bool
}
func TestPrinter(t *testing.T) {
@@ -3770,6 +3771,14 @@ const c = '\''
},
}
+ for _, tt := range tests {
+ if tt.only {
+ tests = make([]jsonTestcase, 0)
+ tests = append(tests, tt)
+ break
+ }
+ }
+
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
// transform output from source
From 045f4c0017c18273cb516c5e36ec5381d4aa62be Mon Sep 17 00:00:00 2001
From: Moustapha HappyDev
Date: Fri, 1 Mar 2024 22:52:35 +0000
Subject: [PATCH 19/30] fix: remove divergence from html spec
---
internal/parser.go | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/internal/parser.go b/internal/parser.go
index 18275683a..53cf1dab3 100644
--- a/internal/parser.go
+++ b/internal/parser.go
@@ -902,8 +902,10 @@ func inHeadIM(p *parser) bool {
p.im = afterHeadIM
return true
case a.Body, a.Html, a.Br:
- p.parseImpliedToken(EndTagToken, a.Head, a.Head.String())
+ p.oe.pop()
p.addLoc()
+ p.originalIM = nil
+ p.im = afterHeadIM
return false
case a.Template:
if !p.oe.contains(a.Template) {
From 1d077f8332c4ce3764522b3567b49c154c4c491d Mon Sep 17 00:00:00 2001
From: Moustapha HappyDev
Date: Fri, 1 Mar 2024 22:53:24 +0000
Subject: [PATCH 20/30] test: add test for #712
---
internal/printer/printer_test.go | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/internal/printer/printer_test.go b/internal/printer/printer_test.go
index 2c02c2278..191268949 100644
--- a/internal/printer/printer_test.go
+++ b/internal/printer/printer_test.go
@@ -3744,6 +3744,11 @@ const c = '\''
source: `Hello world!
`,
want: []ASTNode{{Type: "element", Name: "html", Children: []ASTNode{{Type: "element", Name: "body", Children: []ASTNode{{Type: "element", Name: "h1", Children: []ASTNode{{Type: "text", Value: "Hello world!"}}}}}}}, {Type: "element", Name: "style"}},
},
+ {
+ name: "style after html with component in head",
+ source: ``,
+ want: []ASTNode{{Type: "element", Name: "html", Attributes: []ASTNode{{Type: "attribute", Kind: "quoted", Name: "lang", Value: "en", Raw: "\"en\""}}, Children: []ASTNode{{Type: "element", Name: "head", Children: []ASTNode{{Type: "component", Name: "BaseHead"}}}}}, {Type: "element", Name: "style", Children: []ASTNode{{Type: "text", Value: "@use \"../styles/global.scss\";"}}}},
+ },
{
name: "style in html",
source: `Hello world!
`,
From 69e4d4ae5a8a64fc7fbc2504c2f0e64cf8a3f5a9 Mon Sep 17 00:00:00 2001
From: Moustapha HappyDev
Date: Sat, 2 Mar 2024 00:44:13 +0000
Subject: [PATCH 21/30] `addLoc` before popping the stack of oe
---
internal/parser.go | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/internal/parser.go b/internal/parser.go
index 53cf1dab3..ecc8c6d98 100644
--- a/internal/parser.go
+++ b/internal/parser.go
@@ -902,8 +902,8 @@ func inHeadIM(p *parser) bool {
p.im = afterHeadIM
return true
case a.Body, a.Html, a.Br:
- p.oe.pop()
p.addLoc()
+ p.oe.pop()
p.originalIM = nil
p.im = afterHeadIM
return false
From 851a1282e313f31b108edf125d256fc9521f30ec Mon Sep 17 00:00:00 2001
From: Moustapha HappyDev
Date: Tue, 5 Mar 2024 19:38:04 +0000
Subject: [PATCH 22/30] test: add test
---
internal/printer/printer_test.go | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/internal/printer/printer_test.go b/internal/printer/printer_test.go
index 191268949..8a1e8dcfc 100644
--- a/internal/printer/printer_test.go
+++ b/internal/printer/printer_test.go
@@ -3749,6 +3749,11 @@ const c = '\''
source: ``,
want: []ASTNode{{Type: "element", Name: "html", Attributes: []ASTNode{{Type: "attribute", Kind: "quoted", Name: "lang", Value: "en", Raw: "\"en\""}}, Children: []ASTNode{{Type: "element", Name: "head", Children: []ASTNode{{Type: "component", Name: "BaseHead"}}}}}, {Type: "element", Name: "style", Children: []ASTNode{{Type: "text", Value: "@use \"../styles/global.scss\";"}}}},
},
+ {
+ name: "style after html with component in head and body",
+ source: ``,
+ want: []ASTNode{{Type: "element", Name: "html", Attributes: []ASTNode{{Type: "attribute", Kind: "quoted", Name: "lang", Value: "en", Raw: "\"en\""}}, Children: []ASTNode{{Type: "element", Name: "head", Children: []ASTNode{{Type: "component", Name: "BaseHead"}}}, {Type: "element", Name: "body", Children: []ASTNode{{Type: "component", Name: "Header"}}}}}, {Type: "element", Name: "style", Children: []ASTNode{{Type: "text", Value: "@use \"../styles/global.scss\";"}}}},
+ },
{
name: "style in html",
source: `Hello world!
`,
From 261d7d3c77333f0679e363718a1793cca6ebb27c Mon Sep 17 00:00:00 2001
From: Moustapha HappyDev
Date: Wed, 6 Mar 2024 14:52:25 +0000
Subject: [PATCH 23/30] literal parsing after `body` and `html`
---
internal/parser.go | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/internal/parser.go b/internal/parser.go
index ecc8c6d98..d33aa8405 100644
--- a/internal/parser.go
+++ b/internal/parser.go
@@ -1439,12 +1439,18 @@ func inBodyIM(p *parser) bool {
if p.elementInScope(defaultScope, a.Body) {
p.im = afterBodyIM
}
+ if p.literal {
+ p.oe.pop()
+ }
case a.Html:
p.addLoc()
if p.elementInScope(defaultScope, a.Body) {
p.parseImpliedToken(EndTagToken, a.Body, a.Body.String())
return false
}
+ if p.literal {
+ p.oe.pop()
+ }
return true
case a.Address, a.Article, a.Aside, a.Blockquote, a.Button, a.Center, a.Details, a.Dialog, a.Dir, a.Div, a.Dl, a.Fieldset, a.Figcaption, a.Figure, a.Footer, a.Header, a.Hgroup, a.Listing, a.Main, a.Menu, a.Nav, a.Ol, a.Pre, a.Section, a.Summary, a.Ul:
p.addLoc()
@@ -2702,9 +2708,10 @@ func inLiteralIM(p *parser) bool {
p.addLoc()
p.oe.pop()
p.acknowledgeSelfClosingTag()
+ } else {
+ // always continue `inLiteralIM`
+ return true
}
- // always continue `inLiteralIM`
- return true
case StartExpressionToken:
p.addExpression()
// always continue `inLiteralIM`
From b951379d32bf7ce5409fa8051813c69b0dd46331 Mon Sep 17 00:00:00 2001
From: Moustapha HappyDev
Date: Wed, 6 Mar 2024 15:00:00 +0000
Subject: [PATCH 24/30] test: add test for style tag after body
---
internal/printer/printer_test.go | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/internal/printer/printer_test.go b/internal/printer/printer_test.go
index 8a1e8dcfc..9d783a8c1 100644
--- a/internal/printer/printer_test.go
+++ b/internal/printer/printer_test.go
@@ -3754,6 +3754,11 @@ const c = '\''
source: ``,
want: []ASTNode{{Type: "element", Name: "html", Attributes: []ASTNode{{Type: "attribute", Kind: "quoted", Name: "lang", Value: "en", Raw: "\"en\""}}, Children: []ASTNode{{Type: "element", Name: "head", Children: []ASTNode{{Type: "component", Name: "BaseHead"}}}, {Type: "element", Name: "body", Children: []ASTNode{{Type: "component", Name: "Header"}}}}}, {Type: "element", Name: "style", Children: []ASTNode{{Type: "text", Value: "@use \"../styles/global.scss\";"}}}},
},
+ {
+ name: "style after body with component in head and body",
+ source: ``,
+ want: []ASTNode{{Type: "element", Name: "html", Attributes: []ASTNode{{Type: "attribute", Kind: "quoted", Name: "lang", Value: "en", Raw: "\"en\""}}, Children: []ASTNode{{Type: "element", Name: "head", Children: []ASTNode{{Type: "component", Name: "BaseHead"}}}, {Type: "element", Name: "body", Children: []ASTNode{{Type: "component", Name: "Header"}}}, {Type: "element", Name: "style", Children: []ASTNode{{Type: "text", Value: "@use \"../styles/global.scss\";"}}}}}},
+ },
{
name: "style in html",
source: `Hello world!
`,
From 4f8f51a015e628cf81a6eaaa79172b524c108fcf Mon Sep 17 00:00:00 2001
From: Moustapha HappyDev
Date: Wed, 6 Mar 2024 15:22:17 +0000
Subject: [PATCH 25/30] test: add tsx tests
---
.../compiler/test/tsx/literal-style-tag.ts | 68 +++++++++++++++++++
1 file changed, 68 insertions(+)
create mode 100644 packages/compiler/test/tsx/literal-style-tag.ts
diff --git a/packages/compiler/test/tsx/literal-style-tag.ts b/packages/compiler/test/tsx/literal-style-tag.ts
new file mode 100644
index 000000000..69b878d39
--- /dev/null
+++ b/packages/compiler/test/tsx/literal-style-tag.ts
@@ -0,0 +1,68 @@
+import { convertToTSX } from '@astrojs/compiler';
+import { test } from 'uvu';
+import * as assert from 'uvu/assert';
+import { TSXPrefix } from '../utils';
+
+test('preserve style tag position I', async () => {
+ const input = `
+
+ Hello world!
+
+
+`;
+ const output = `${TSXPrefix}
+
+
+ Hello world!
+
+
+
+
+export default function __AstroComponent_(_props: Record): any {}\n`;
+ const { code } = await convertToTSX(input, { sourcemap: 'external' });
+ assert.snapshot(code, output, `expected code to match snapshot`);
+});
+
+test('preserve style tag position II', async () => {
+ const input = `
+
+
+
+
+`;
+ const output = `${TSXPrefix}
+
+
+
+
+
+
+
+export default function __AstroComponent_(_props: Record): any {}\n`;
+ const { code } = await convertToTSX(input, { sourcemap: 'external' });
+ assert.snapshot(code, output, `expected code to match snapshot`);
+});
+
+test('preserve style tag position III', async () => {
+ const input = `
+`;
+ const output = `${TSXPrefix}
+
+
+
+export default function __AstroComponent_(_props: Record): any {}\n`;
+ const { code } = await convertToTSX(input, { sourcemap: 'external' });
+ assert.snapshot(code, output, `expected code to match snapshot`);
+});
+
+test('preserve style tag position IV', async () => {
+ const input = ``;
+ const output = `${TSXPrefix}
+
+
+export default function __AstroComponent_(_props: Record): any {}\n`;
+ const { code } = await convertToTSX(input, { sourcemap: 'external' });
+ assert.snapshot(code, output, `expected code to match snapshot`);
+});
+
+test.run();
From 45195560ee6ec6aac2d793819970af047441f44e Mon Sep 17 00:00:00 2001
From: Moustapha HappyDev
Date: Wed, 6 Mar 2024 15:36:22 +0000
Subject: [PATCH 26/30] test: add missing semicolon in test
---
packages/compiler/test/tsx/literal-style-tag.ts | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/packages/compiler/test/tsx/literal-style-tag.ts b/packages/compiler/test/tsx/literal-style-tag.ts
index 69b878d39..5490fe725 100644
--- a/packages/compiler/test/tsx/literal-style-tag.ts
+++ b/packages/compiler/test/tsx/literal-style-tag.ts
@@ -45,7 +45,7 @@ export default function __AstroComponent_(_props: Record): any {}\n
test('preserve style tag position III', async () => {
const input = `
-`;
+`;
const output = `${TSXPrefix}
From d4370126c160b2ac8b6f6206ed9691b1a3d02804 Mon Sep 17 00:00:00 2001
From: Moustapha HappyDev
Date: Wed, 6 Mar 2024 17:13:58 +0000
Subject: [PATCH 27/30] test: update test to reflect `addFrontmatter` refactor
---
packages/compiler/test/tsx/basic.ts | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/packages/compiler/test/tsx/basic.ts b/packages/compiler/test/tsx/basic.ts
index e5f705f6d..d2e7d80b2 100644
--- a/packages/compiler/test/tsx/basic.ts
+++ b/packages/compiler/test/tsx/basic.ts
@@ -267,8 +267,8 @@ test('return ranges - no frontmatter', async () => {
assert.equal(metaRanges, {
frontmatter: {
- start: 30,
- end: 30,
+ start: 0,
+ end: 0,
},
body: {
start: 41,
From 968b6c4be49704d1c897b89907a45ac7c549f775 Mon Sep 17 00:00:00 2001
From: Moustapha HappyDev
Date: Wed, 6 Mar 2024 17:15:02 +0000
Subject: [PATCH 28/30] test: remove code from bad merge commit
---
internal/printer/printer_test.go | 3 ---
1 file changed, 3 deletions(-)
diff --git a/internal/printer/printer_test.go b/internal/printer/printer_test.go
index 8d2405f87..4bf5e59bf 100644
--- a/internal/printer/printer_test.go
+++ b/internal/printer/printer_test.go
@@ -570,9 +570,6 @@ import type data from "test"
p+h2 ${dummyKey}
` + BACKTICK + `
- );
- p+h2 ${dummyKey}
- ` + BACKTICK + `
);
})
}
From c5a3f949b985f4d3dc5b29f0771cc14e2e5b34d1 Mon Sep 17 00:00:00 2001
From: Moustapha HappyDev
Date: Wed, 6 Mar 2024 17:30:30 +0000
Subject: [PATCH 29/30] chore: update transition scope
---
internal/printer/printer_test.go | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/internal/printer/printer_test.go b/internal/printer/printer_test.go
index d558b741b..4959dfbd9 100644
--- a/internal/printer/printer_test.go
+++ b/internal/printer/printer_test.go
@@ -3538,7 +3538,7 @@ const items = ["Dog", "Cat", "Platipus"];
source: ``,
transitions: true,
want: want{
- code: `${$$renderComponent($$result,'my-island','my-island',{"data-astro-transition-persist-props":"false","data-astro-transition-persist":($$createTransitionScope($$result, "otghnj5u"))})}`,
+ code: `${$$renderComponent($$result,'my-island','my-island',{"data-astro-transition-persist-props":"false","data-astro-transition-persist":($$createTransitionScope($$result, "rho3aldc"))})}`,
},
},
{
From b03c604b25bdb106c0fae5a38c0d28fd4ddd573d Mon Sep 17 00:00:00 2001
From: Moustapha HappyDev
Date: Wed, 6 Mar 2024 17:42:41 +0000
Subject: [PATCH 30/30] test: add more tests from duplicates
---
internal/printer/printer_test.go | 5 +++
.../compiler/test/tsx/literal-style-tag.ts | 40 +++++++++----------
2 files changed, 23 insertions(+), 22 deletions(-)
diff --git a/internal/printer/printer_test.go b/internal/printer/printer_test.go
index 31348c910..8afdfebf7 100644
--- a/internal/printer/printer_test.go
+++ b/internal/printer/printer_test.go
@@ -3800,6 +3800,11 @@ const c = '\''
source: `Hello world!
`,
want: []ASTNode{{Type: "element", Name: "html", Children: []ASTNode{{Type: "element", Name: "body", Children: []ASTNode{{Type: "element", Name: "h1", Children: []ASTNode{{Type: "text", Value: "Hello world!"}}}}}}}, {Type: "element", Name: "style"}},
},
+ {
+ name: "style after empty html",
+ source: ``,
+ want: []ASTNode{{Type: "element", Name: "html"}, {Type: "element", Name: "style"}},
+ },
{
name: "style after html with component in head",
source: ``,
diff --git a/packages/compiler/test/tsx/literal-style-tag.ts b/packages/compiler/test/tsx/literal-style-tag.ts
index 5490fe725..235be1e8f 100644
--- a/packages/compiler/test/tsx/literal-style-tag.ts
+++ b/packages/compiler/test/tsx/literal-style-tag.ts
@@ -4,18 +4,10 @@ import * as assert from 'uvu/assert';
import { TSXPrefix } from '../utils';
test('preserve style tag position I', async () => {
- const input = `
-
- Hello world!
-
-
+ const input = `Hello world!
`;
const output = `${TSXPrefix}
-
-
- Hello world!
-
-
+Hello world!
export default function __AstroComponent_(_props: Record): any {}\n`;
@@ -24,18 +16,22 @@ export default function __AstroComponent_(_props: Record): any {}\n
});
test('preserve style tag position II', async () => {
- const input = `
-
-
-
-
+ const input = `
+`;
+ const output = `${TSXPrefix}
+
+
+
+export default function __AstroComponent_(_props: Record): any {}\n`;
+ const { code } = await convertToTSX(input, { sourcemap: 'external' });
+ assert.snapshot(code, output, `expected code to match snapshot`);
+});
+
+test('preserve style tag position III', async () => {
+ const input = `
`;
const output = `${TSXPrefix}
-
-
-
-
-
+
export default function __AstroComponent_(_props: Record): any {}\n`;
@@ -43,7 +39,7 @@ export default function __AstroComponent_(_props: Record): any {}\n
assert.snapshot(code, output, `expected code to match snapshot`);
});
-test('preserve style tag position III', async () => {
+test('preserve style tag position IV', async () => {
const input = `
`;
const output = `${TSXPrefix}
@@ -55,7 +51,7 @@ export default function __AstroComponent_(_props: Record): any {}\n
assert.snapshot(code, output, `expected code to match snapshot`);
});
-test('preserve style tag position IV', async () => {
+test('preserve style tag position V', async () => {
const input = ``;
const output = `${TSXPrefix}