Repository navigation
Restore scanner line positions after seeking - #155
Open
Pradeep Ramola (pradeep-ramola) wants to merge 1 commit into
Open
Pradeep Ramola (pradeep-ramola) wants to merge 1 commit into
Pradeep Ramola (pradeep-ramola) wants to merge 1 commit into
Conversation
This was referenced Nov 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #154.
setPosition()updates the scan offset but leaves the old line-number and line-start state in place. Seeking forward reports line zero for later lines, and rewinding after scanning multiline text can produce negative columns.Reset the line state alongside the existing token state. For nonzero seeks, build a line-start index lazily and use binary search to locate the target line. The index is reused on later seeks; ordinary sequential scanning does not build one. CRLF pairs remain a single line break, including when seeking between CR and LF.
Added 16 regression/control tests covering forward seeks, rewinds, offset zero, EOF, LF/CRLF/CR, both trivia modes, and single-line and mid-CRLF controls. On unchanged main, 12 new tests fail and four controls pass.
Validation on Windows:
npm testwith Node 22.23.5: TypeScript compilation, ESLint, and all 104 tests pass.git diff --check: passes.No public API, dependency, or changelog changes. Linux and macOS were not tested locally. This does not change the unterminated-comment behavior discussed in #150 or the token-value optimization in #151.