Skip to content

Commit 85e1d31

Browse files
authored
Move start position for elements (#593)
* Update print-to-json.go * Create ninety-cherries-guess.md * Update print-to-json.go
1 parent 2435a77 commit 85e1d31

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@astrojs/compiler': patch
3+
---
4+
5+
AST: move `start` position of elements to the first index of their opening tag

internal/printer/print-to-json.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,13 @@ func positionAt(p *printer, n *Node, opts t.ParseOptions) ASTPosition {
143143
if len(n.Loc) == 2 {
144144
s := n.Loc[0]
145145
e := n.Loc[1]
146-
// `e` marks the start location of the end tag
146+
// `s` and `e` mark the start location of the tag name
147147
if n.Type == ElementNode {
148-
// this adjusts it to be the last index of the end tag
148+
if (s.Start != 0) {
149+
// this adjusts `s` to be the first index of the element tag
150+
s.Start = s.Start - 1
151+
}
152+
// this adjusts `e` to be the last index of the end tag
149153
e.Start = e.Start + len(n.Data) + 1
150154
}
151155
start := locToPoint(p, s)

0 commit comments

Comments
 (0)