Skip to content

Commit 96a354a

Browse files
committed
fix: strip newlines at the end of component files
1 parent 499bfa8 commit 96a354a

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

.changeset/chilly-chairs-enjoy.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@astrojs/compiler': minor
3+
---
4+
5+
Newlines at the end of Astro files are now stripped before the Astro file is processed.

cmd/astro-wasm/astro-wasm.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,14 @@ func preprocessStyle(i int, style *astro.Node, transformOptions transform.Transf
159159
style.FirstChild.Data = str
160160
}
161161

162+
func preprocessSource(source string) string {
163+
// remove trailing newlines
164+
return strings.TrimRight(source, "\n")
165+
}
166+
162167
func Parse() interface{} {
163168
return js.FuncOf(func(this js.Value, args []js.Value) interface{} {
164-
source := jsString(args[0])
169+
source := preprocessSource(jsString(args[0]))
165170
parseOptions := makeParseOptions(js.Value(args[1]))
166171

167172
var doc *astro.Node
@@ -179,7 +184,7 @@ func Parse() interface{} {
179184

180185
func ConvertToTSX() interface{} {
181186
return js.FuncOf(func(this js.Value, args []js.Value) interface{} {
182-
source := jsString(args[0])
187+
source := preprocessSource(jsString(args[0]))
183188
transformOptions := makeTransformOptions(js.Value(args[1]), "XXXXXX")
184189

185190
var doc *astro.Node
@@ -198,7 +203,7 @@ func ConvertToTSX() interface{} {
198203

199204
func Transform() interface{} {
200205
return js.FuncOf(func(this js.Value, args []js.Value) interface{} {
201-
source := jsString(args[0])
206+
source := preprocessSource(jsString(args[0]))
202207
hash := astro.HashFromSource(source)
203208
transformOptions := makeTransformOptions(js.Value(args[1]), hash)
204209

packages/compiler/deno/astro.wasm

11 KB
Binary file not shown.

0 commit comments

Comments
 (0)