Fix Input#origin() returning incorrect position#2036
Open
mizdra wants to merge 3 commits intopostcss:mainfrom
Open
Fix Input#origin() returning incorrect position#2036mizdra wants to merge 3 commits intopostcss:mainfrom
Input#origin() returning incorrect position#2036mizdra wants to merge 3 commits intopostcss:mainfrom
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.
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