Skip to content

Conversation

@mizdra
Copy link
Contributor

@mizdra mizdra commented Mar 24, 2025

fix: #2035

let consumer = this.map.consumer()

let from = consumer.originalPositionFor({ column, line })
let from = consumer.originalPositionFor({ column: column - 1, line })
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The column argument of originalPositionFor is 0-based.

https://github.com/7rulnik/source-map-js?tab=readme-ov-file#sourcemapconsumerprototypeoriginalpositionforgeneratedposition

It is not clear from jsdoc whether the column argument of Input#origin is 1-based or 0-based.

* @param column Column for inclusive start position in input CSS.

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.

column: from.column,
endColumn: to && to.column,
column: from.column + 1,
endColumn: to && to.column + 1,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The return value column of originalPositionFor is 0-based.

https://github.com/7rulnik/source-map-js?tab=readme-ov-file#sourcemapconsumerprototypeoriginalpositionforgeneratedposition

To convert a 0-based column to a 1-based column, add 1.


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, [
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original columns generated by concat-with-sourcemaps are rough. So I used source-map-js.

6a2199b

@mizdra mizdra marked this pull request as ready for review March 24, 2025 15:40
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.

In CSS with source map, input.origin().column and error.column have wrong values

1 participant