-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Fix Input#origin() returning incorrect position
#2036
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
| let consumer = this.map.consumer() | ||
|
|
||
| let from = consumer.originalPositionFor({ column, line }) | ||
| let from = consumer.originalPositionFor({ column: column - 1, line }) |
There was a problem hiding this comment.
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.
It is not clear from jsdoc whether the column argument of Input#origin is 1-based or 0-based.
Line 208 in 6a2199b
| * @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, |
There was a problem hiding this comment.
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.
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, [ |
There was a problem hiding this comment.
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.
fix: #2035