Commit 3effe59
fix(html): make flushText idempotent to avoid duplicate text emit at EOF
Copilot review follow-up on commit 132a4cd.
Real bug verified by `walkHtmlTokens("a<div", 0, { text: ... })` —
the `"a"` text span was emitted twice:
1) `STATE_TAG_OPEN`'s alpha branch flushed pending text on tag entry,
2) the EOF mid-tag handler called `flushText(tagStart)` again,
re-emitting the same span because `flushText` never advanced
`textStart`.
Fix: `flushText` now advances `textStart = endPos` after emitting, so
repeated `flushText` calls for the same span are no-ops. `emitOpenTag`
/ `emitCloseTag` overwrite `textStart` with their own `nextPos` after
the tag emits, so the new advance doesn't shift any subsequent ranges.
238/238 tests pass, 100% coverage on `walkHtmlTokens.js`,
`yarn lint` clean.
https://claude.ai/code/session_01N4rd8xuv5oRaHWFL8dFpwh1 parent 132a4cd commit 3effe59
1 file changed
Lines changed: 10 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
302 | 302 | | |
303 | 303 | | |
304 | 304 | | |
305 | | - | |
306 | | - | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
307 | 315 | | |
308 | 316 | | |
309 | 317 | | |
| |||
0 commit comments