Skip to content

Commit

Permalink
fix(withastro#714): skip \r in sourcemapping (withastro#775)
Browse files Browse the repository at this point in the history
Co-authored-by: Princesseuh <[email protected]>
  • Loading branch information
natemoo-re and Princesseuh authored Apr 25, 2023
1 parent bedced8 commit 19c0176
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/clean-chicken-trade.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/compiler': patch
---

Fix TSX sourcemapping for components using Windows-style line returns
6 changes: 6 additions & 0 deletions internal/printer/printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ func (p *printer) printTextWithSourcemap(text string, l loc.Loc) {
lastPos := -1
for pos, c := range text {
diff := pos - lastPos
// Handle Windows-specific "\r\n" newlines
if c == '\r' && len(text[pos:]) > 0 && text[pos + 1] == '\n' {
start += diff
lastPos = pos
continue
}
p.addSourceMapping(loc.Loc{Start: start})
p.print(string(c))
start += diff
Expand Down

0 comments on commit 19c0176

Please sign in to comment.