Skip to content

fix(node): always compute offset in positionBy() like rangeBy()#2099

Merged
ai merged 1 commit into
postcss:mainfrom
mahirhir:fix/positionBy-missing-offset
Jun 27, 2026
Merged

fix(node): always compute offset in positionBy() like rangeBy()#2099
ai merged 1 commit into
postcss:mainfrom
mahirhir:fix/positionBy-missing-offset

Conversation

@mahirhir

Copy link
Copy Markdown
Contributor

Mirrors #2033 to the one sibling it left out.

#2033 (issue #2029) normalized rangeBy() and positionInside() to always compute offset via sourceOffset(), so they return a complete Position. positionBy()'s default branch was left returning this.source.start as-is:

lib/node.js (default branch of positionBy)

position = this.source.start

For custom syntaxes whose source.start carries no offset (e.g. postcss-html), this returns a position missing offset, which violates the Position type that declares offset: number as required. rangeBy() two lines away already handles exactly this via sourceOffset(); positionBy() is the unmirrored twin.

Fix mirrors rangeBy() precisely (compute offset through sourceOffset() on the default branch).

Verification: added a regression test that fails on baseline (1/90 fail) and passes with the fix (90/90); the full existing suite is 89/89 on both baseline and patched, so zero regression; tsc --noEmit is clean. Branch is based on the current main tip.

positionBy()'s default branch returned this.source.start verbatim, so for
custom syntaxes whose source.start lacks an offset (e.g. postcss-html) it
returned a position without offset, violating the Position type which
declares offset as required. rangeBy()/positionInside() were normalized to
always compute offset via sourceOffset() (#2033, issue #2029) but
positionBy() was left behind. Mirror the rangeBy() pattern.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@ai
ai merged commit 698425a into postcss:main Jun 27, 2026
10 checks passed
@ai

ai commented Jun 27, 2026

Copy link
Copy Markdown
Member

Thanks

@ai

ai commented Jun 28, 2026

Copy link
Copy Markdown
Member

Released in 8.5.16.

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