Repository navigation
Parser offsets are wrong for files with CRLF line endings - #1282
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes: Reviewed the CRLF offset correction, regression tests, and documentation.
- Original-input locations: Remaps AST and syntax-error offsets after newline normalization, including shared locations and mixed line endings.
- Regression coverage: Tests node ranges, decorators, unchanged values, and error boundaries; all 289 parser tests and the parser typecheck passed.
- Documentation: Clarifies newline handling and location coordinates, with a parser patch release entry.
gpt-6.1-sol | 𝕏
The parser normalizes \r\n to \n before parsing, so every offset it reported (on nodes and on syntax errors) was an offset into the normalized text. For a CRLF file the Nth line was off by N characters, which breaks anything that slices the original source with them. Map the offsets back to the input after parsing. Line and column are unchanged, and files without \r\n skip the mapping entirely.
theoephraim
force-pushed
the
fix-crlf-parser-offsets
branch
from
November 13, 2026 00:47
b7b9600 to
ecc2a3c
Compare
@env-spec/parser
varlock
@varlock/astro-integration
@varlock/cloudflare-integration
@varlock/nextjs-integration
@varlock/nuxt-integration
@varlock/vite-integration
@varlock/1password-plugin
@varlock/aws-secrets-plugin
@varlock/azure-key-vault-plugin
@varlock/bitwarden-plugin
@varlock/keepass-plugin
@varlock/pass-plugin
@varlock/proton-pass-plugin
commit: |
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.

same for syntax errors: a stray
@oopson line 5 is reported at an offset that points into the line above it.cause: the parser turns
\r\ninto\nbefore parsing, so the offsets point into the shortened text. line N is off by N characters.fix: map offsets back to the original text after parsing. line and column were already right. files without
\r\nskip the mapping.context: found while prototyping a language server on top of the parser (#469) and fuzzing it with generated schemas. the server slices the source with these offsets. nothing inside varlock reads them today, so nobody using the CLI sees this.
heads up: this changes
packages/env-spec-parser/src/index.ts, which the parser rewrite in #744 also changes. if #744 is still planned, this would need redoing on top of it, and i'm happy to do that.test:
locations.test.ts, 9 of its cases fail on main.