fix(parser): make reset() safe inside callbacks

FB
19d ago
+34-3

Two fixes for reset() being called from inside a callback:

  • count chunks before invoking tokenizer callbacks: writeIndex is incremented before the tokenizer runs, so a reset() from a callback does not leave the chunk count one behind.
  • stop closing a stack reset by a callback: the implied-close loop in onclosetag is bounded by the matched element's position, so a reset() from an onclosetag callback ends the loop instead of closing elements of the new document.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Fixed parser behavior when parsing is reset from a callback. Text queued after a reset is delivered in order, including when parsing pauses and resumes. Resetting during a closing-tag callback now stops additional closing-tag callbacks for the current input, preventing callbacks from continuing after parsing has been reset.