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 1 commit
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
4 changes: 3 additions & 1 deletion lib/input.d.ts
Expand Up @@ -126,5 +126,7 @@ export default class Input {
*
* @param offset Source offset.
*/
fromOffset (offset: number): { line: number; col: number } | null
fromOffset (
offset: number
): { offset?: number; line?: number; column?: number }
Copy link
Member

Choose a reason for hiding this comment

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

We can’t change public API. Let’s convert object.

}
8 changes: 4 additions & 4 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,8 @@ class Input {
}

fromOffset (offset) {
let finder = lineColumn(this.css)
this.fromOffset = i => finder.fromIndex(i)
let finder = vfileLocation(this.css)
this.fromOffset = i => finder.toPoint(i)
return this.fromOffset(offset)
}

Expand All @@ -60,7 +60,7 @@ class Input {
if (!column) {
let pos = this.fromOffset(line)
line = pos.line
column = pos.col
column = pos.column
}
let origin = this.origin(line, column)
if (origin) {
Expand Down
7 changes: 1 addition & 6 deletions lib/parser.js
Expand Up @@ -376,12 +376,7 @@ class Parser {
// Helpers

getPosition (offset) {
let pos = this.input.fromOffset(offset)
return {
offset,
line: pos.line,
column: pos.col
}
return this.input.fromOffset(offset)
}

init (node, 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