You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
columnOffset returns -1 at offset 0 when the source starts with LF #674
columnOffset(source, 0) returns -1 when the first character of source is LF, although offset 0 is the start of the first line and should have column offset 0.
Reproduced in the published @fluent/syntax@0.19.0 package and current main (9a925d2a38b893be735ff4429be8ad62132a204d), using Node.js v24.19.0 on macOS.
Controls such as columnOffset("hello", 0), columnOffset("\nhello", 1), and columnOffset("\r\nhello", 0) return 0 as expected.
Cause and scope
The helper calls source.lastIndexOf("\n", pos - 1). At pos === 0, JavaScript clamps the search position -1 to 0, so a leading LF is found at index 0 and the final subtraction produces -1.
This gives a negative column to consumers converting a valid file-start offset into a line/column coordinate. I have not established a downstream production failure.
Related history: #64 fixed the search boundary when pos itself points to a newline. This report concerns the remaining file-start boundary. I checked the public issues and PRs, including #4, #7, and #64, and did not find this exact case reported.
Proposed fix and validation
Return 0 immediately when pos === 0. The attached patch includes eight regression/control tests covering the empty source, leading LF, LF-only source, CRLF, a position on a newline, the next line's first character, consecutive newlines, and EOF.
Before the fix: 2 regression tests failed and 6 controls passed.
After the fix: the full suite passed with 742 passed, 3 skipped across 59 test files.
All workspace builds, lint, and documentation generation passed.
The built distribution also returns 0 for both failing examples.
The patch applies cleanly to the main commit above. Discovery and test preparation were AI-assisted; the reported results were verified by local execution with synthetic text inputs.
Activity