Skip to content

Commit be4202d

Browse files
committed
fix: handle incorrect pos & size with text_special
1 parent a62b5cb commit be4202d

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

lib/rules_core/text_join.mjs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,19 @@ export default function text_join (state) {
2323
}
2424
}
2525

26-
for (curr = last = 0; curr < max; curr++) {
26+
for (curr = last = 0; curr < tokens.length; curr++) {
2727
if (tokens[curr].type === 'text' &&
2828
curr + 1 < max &&
2929
tokens[curr + 1].type === 'text') {
3030
// collapse two adjacent text nodes
3131
tokens[curr + 1].content = tokens[curr].content + tokens[curr + 1].content
32+
33+
// only move forward position when left token has content
34+
if (tokens[curr].content) {
35+
tokens[curr + 1].position = tokens[curr].position
36+
}
37+
// add up size
38+
tokens[curr + 1].size = (tokens[curr].size || 0) + (tokens[curr + 1].size || 0)
3239
} else {
3340
if (curr !== last) { tokens[last] = tokens[curr] }
3441

lib/rules_inline/escape.mjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ export default function escape (state, silent) {
6262

6363
token.markup = origStr
6464
token.info = 'escape'
65+
// size should reflect original source span (including backslash)
66+
token.size = origStr.length
6567
}
6668

6769
state.pos = pos + 1

0 commit comments

Comments
 (0)