Fix Input#origin() returning incorrect position#2036
Merged
Conversation
mizdra
commented
Mar 24, 2025
| let consumer = this.map.consumer() | ||
|
|
||
| let from = consumer.originalPositionFor({ column, line }) | ||
| let from = consumer.originalPositionFor({ column: column - 1, line }) |
Contributor
Author
There was a problem hiding this comment.
The column argument of originalPositionFor is 0-based.
It is not clear from jsdoc whether the column argument of Input#origin is 1-based or 0-based.
Line 208 in 6a2199b
However, postcss uses 1-based columns in many APIs. It should be a 1-based column here too.
To convert a 1-based column to a 0-based column, subtract 1.
mizdra
commented
Mar 24, 2025
| column: from.column, | ||
| endColumn: to && to.column, | ||
| column: from.column + 1, | ||
| endColumn: to && to.column + 1, |
Contributor
Author
There was a problem hiding this comment.
The return value column of originalPositionFor is 0-based.
To convert a 0-based column to a 1-based column, add 1.
mizdra
commented
Mar 24, 2025
|
|
||
| test('origin() returns source position with source map', () => { | ||
| // @ts-expect-error source-map-js accepts null, but it's not in the types (ref: https://github.com/7rulnik/source-map-js/blob/428d49f6b1e1614f082b7706fa879a3d9c64f728/test/test-source-node.js#L20) | ||
| let node = new SourceNode(null, null, null, [ |
Contributor
Author
There was a problem hiding this comment.
The original columns generated by concat-with-sourcemaps are rough. So I used source-map-js.
Member
|
Thanks! |
Member
|
Released in 8.5.16. |
ai
pushed a commit
that referenced
this pull request
Jun 30, 2026
…ion (#2106) When the requested end position has no mapping in the source map, originalPositionFor() returns an object with line/column set to null rather than omitting them. endLine picked that null up correctly, but endColumn was computed as `to && to.column + 1`, which due to operator precedence is `to && (to.column + 1)`, turning null into 1. So callers could get back { endColumn: 1, endLine: null }, which doesn't match how every other unmapped case in this function behaves (undefined for both). Looks like the +1 fix in #2036 covered the mapped case but not this one. Guard `to` the same way `from` already is, so an unmapped end position just stays undefined.
chida09
added a commit
to chida09/happy-css-modules
that referenced
this pull request
Jul 2, 2026
postcss 8.5.16 (postcss/postcss#2036) fixed `Input#origin()` to correctly accept 1-based columns. The `- 1` workaround in `getOriginalLocationOfClassSelector` is no longer needed and causes double subtraction, resulting in `column = -1` which crashes `source-map-js`. Fixes mizdra#320
mizdra
added a commit
to chida09/happy-css-modules
that referenced
this pull request
Jul 2, 2026
…alue postcss 8.5.16 (postcss/postcss#2036) changed `Input#origin()` to return 1-based columns as well as accept them. The `+ 1` conversion in `getOriginalLocationOfClassSelector` is no longer needed and shifted original locations by one column. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
fix: #2035