Skip to content

Fix inconsistent position calculations #1980

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

Conversation

romainmenke
Copy link
Contributor

fixes: #1979


Benchmarks:

[16:51:26] Running suite Preprocessors [/Users/romainmenke/projects/postcss-benchmark/preprocessors.js]...

PostCSS sync:      29 ms  (1.0 times faster)
Next PostCSS sync: 29 ms  (1.0 times faster)
PostCSS:           30 ms
Next PostCSS:      31 ms  (1.0 times slower)

...

[16:52:19] Running suite Parsers [/Users/romainmenke/projects/postcss-benchmark/parsers.js]...

PostCSS:      13 ms
Next PostCSS: 13 ms (1.0 times slower)

...

[16:54:02] Running suite Linters [/Users/romainmenke/projects/postcss-benchmark/linters.js]...

Next PostCSS: 207 ms (1.1 times faster)
PostCSS:      219 ms

...

[16:54:14] Running suite Sourcemaps [/Users/romainmenke/projects/postcss-benchmark/sourcemaps.js]...

Next PostCSS: 67 ms (1.0 times faster)
PostCSS:      67 ms

Stylelint even seems to run a bit faster after this update.

I assume that calling String.prototype.slice is noticeably faster than recursively calling Node.prototype.toString() and serializing all nodes.

}
return pos
}

positionInside(index, stringRepresentation) {
let string = stringRepresentation || this.toString()
positionInside(index) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

stringRepresentation argument wasn't part of the public API and it isn't needed anymore.

Comment on lines +435 to +436
equal(one.positionBy({ word: 'X' }), { column: 11, line: 1 })
equal(a.positionBy({ word: '}' }), { column: 14, line: 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.

I wanted some extra test coverage for characters at the end of nodes.

@romainmenke romainmenke changed the title fix inconsistent position calculations Fix inconsistent position calculations Nov 5, 2024
@ai
Copy link
Member

ai commented Nov 6, 2024

Sorry, I will be busy for a few days. Also, I need to review the history—maybe there was a reason to use actual CSS string and not source there. Expect merge at the end of the week.

@romainmenke
Copy link
Contributor Author

Take your time ☺️, there is no pressure on our end.

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.

Node methods that calculate source positions are inconsistent if there are AST mutations
2 participants