Skip to content
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

Replace line-column with vfile-location #1466

Merged
merged 2 commits into from Nov 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 9 additions & 3 deletions lib/input.js
Expand Up @@ -3,7 +3,7 @@
let { fileURLToPath, pathToFileURL } = require('url')
let { resolve, isAbsolute } = require('path')
let { nanoid } = require('nanoid/non-secure')
let lineColumn = require('line-column')
let vfileLocation = require('vfile-location')

let terminalHighlight = require('./terminal-highlight')
let CssSyntaxError = require('./css-syntax-error')
Expand Down Expand Up @@ -50,8 +50,14 @@ class Input {
}

fromOffset (offset) {
let finder = lineColumn(this.css)
this.fromOffset = i => finder.fromIndex(i)
let finder = vfileLocation(this.css)
this.fromOffset = i => {
let position = finder.toPoint(i)
return {
line: position.line,
col: position.column
Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe add TODO here to make api consistent in v9?

Copy link
Member

Choose a reason for hiding this comment

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

I am using issue for that

}
}
return this.fromOffset(offset)
}

Expand Down
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -39,9 +39,9 @@
"repository": "postcss/postcss",
"dependencies": {
"colorette": "^1.2.1",
"line-column": "^1.0.2",
"nanoid": "^3.1.16",
"source-map": "^0.6.1"
"source-map": "^0.6.1",
"vfile-location": "^3.2.0"
},
"devDependencies": {
"@logux/eslint-config": "^42.2.2",
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Expand Up @@ -11037,6 +11037,11 @@ vfile-location@^2.0.0:
resolved "https://registry.yarnpkg.com/vfile-location/-/vfile-location-2.0.6.tgz#8a274f39411b8719ea5728802e10d9e0dff1519e"
integrity sha512-sSFdyCP3G6Ka0CEmN83A2YCMKIieHx0EDaj5IDP4g1pa5ZJ4FJDvpO0WODLxo4LUX4oe52gmSCK7Jw4SBghqxA==

vfile-location@^3.2.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/vfile-location/-/vfile-location-3.2.0.tgz#d8e41fbcbd406063669ebf6c33d56ae8721d0f3c"
integrity sha512-aLEIZKv/oxuCDZ8lkJGhuhztf/BW4M+iHdCwglA/eWc+vtuRFJj8EtgceYFX4LRjOhCAAiNHsKGssC6onJ+jbA==

vfile-message@^1.0.0:
version "1.1.1"
resolved "https://registry.yarnpkg.com/vfile-message/-/vfile-message-1.1.1.tgz#5833ae078a1dfa2d96e9647886cd32993ab313e1"
Expand Down