Skip to content

Add absolute source offsets to parsed selector nodes - #341

Draft
deepanshupal wants to merge 4 commits into
postcss:mainfrom
deepanshupal:fix/source-offsets-251
Draft

deepanshupal wants to merge 4 commits into
postcss:mainfrom
deepanshupal:fix/source-offsets-251

Conversation

@deepanshupal

Copy link
Copy Markdown

Addresses #251. Parsed nodes now include zero-based UTF-16 source.start.offset and inclusive source.end.offset, derived from the tokenizer's existing positions. The public TypeScript declaration includes the optional offsets.

Tests cover multiline and nested selectors, CRLF, attributes, named combinators, empty pseudos, and words joined from multiple tokens. I claimed the issue after the maintainer welcomed a PR. Opening as a draft for review.

Validation: npm test (804 passed), lint, typecheck and coverage passed; git diff --check passed. format:check fails only on untouched src/__tests__/exceptions.mjs, which fails on the clean HEAD as well. AI assistance was used for investigation and implementation; outputs and tests were reviewed locally.

@MoOx

MoOx commented Nov 8, 2026

Copy link
Copy Markdown
Collaborator

Sorry for the wait. Your draft note says you opened it for review, and that review is what was missing, not anything on your side.

I rebuilt it on current main: it merges cleanly and npm test passes with 1002 tests. Then I diffed every node's position against main across six selector shapes. The offsets are purely additive everywhere, with one exception:

.#{$c}    class "#{$c}"    sourceIndex 4 -> 0

That is the right value, and it is what #243 asks for, so it is welcome. But it changes an existing property, the description does not mention it, and no test pins it, so as it stands it reads as a side effect rather than a fix.

Two things before this leaves draft:

With those, I will take it.

One practical note: main has moved a fair amount since September. 7.1.7 and 7.1.8 are out, and several PRs have landed, including work in splitWord and the source helpers. You will want to rebase before the final pass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants