Skip to content

Commit 96d7e76

Browse files
committed
Replace line-column with vfile-location
vfile-location is dependency free and quite fresh package. https://github.com/vfile/vfile-location line-column has outdated dependencies and was not touched in 5 years. https://github.com/io-monad/line-column
1 parent 6d2d1fb commit 96d7e76

File tree

5 files changed

+15
-13
lines changed

5 files changed

+15
-13
lines changed

lib/input.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,5 +126,7 @@ export default class Input {
126126
*
127127
* @param offset Source offset.
128128
*/
129-
fromOffset (offset: number): { line: number; col: number } | null
129+
fromOffset (
130+
offset: number
131+
): { offset?: number; line?: number; column?: number }
130132
}

lib/input.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
let { fileURLToPath, pathToFileURL } = require('url')
44
let { resolve, isAbsolute } = require('path')
55
let { nanoid } = require('nanoid/non-secure')
6-
let lineColumn = require('line-column')
6+
let vfileLocation = require('vfile-location')
77

88
let terminalHighlight = require('./terminal-highlight')
99
let CssSyntaxError = require('./css-syntax-error')
@@ -50,8 +50,8 @@ class Input {
5050
}
5151

5252
fromOffset (offset) {
53-
let finder = lineColumn(this.css)
54-
this.fromOffset = i => finder.fromIndex(i)
53+
let finder = vfileLocation(this.css)
54+
this.fromOffset = i => finder.toPoint(i)
5555
return this.fromOffset(offset)
5656
}
5757

@@ -60,7 +60,7 @@ class Input {
6060
if (!column) {
6161
let pos = this.fromOffset(line)
6262
line = pos.line
63-
column = pos.col
63+
column = pos.column
6464
}
6565
let origin = this.origin(line, column)
6666
if (origin) {

lib/parser.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -376,12 +376,7 @@ class Parser {
376376
// Helpers
377377

378378
getPosition (offset) {
379-
let pos = this.input.fromOffset(offset)
380-
return {
381-
offset,
382-
line: pos.line,
383-
column: pos.col
384-
}
379+
return this.input.fromOffset(offset)
385380
}
386381

387382
init (node, offset) {

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@
3939
"repository": "postcss/postcss",
4040
"dependencies": {
4141
"colorette": "^1.2.1",
42-
"line-column": "^1.0.2",
4342
"nanoid": "^3.1.16",
44-
"source-map": "^0.6.1"
43+
"source-map": "^0.6.1",
44+
"vfile-location": "^3.2.0"
4545
},
4646
"devDependencies": {
4747
"@logux/eslint-config": "^42.2.2",

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11037,6 +11037,11 @@ vfile-location@^2.0.0:
1103711037
resolved "https://registry.yarnpkg.com/vfile-location/-/vfile-location-2.0.6.tgz#8a274f39411b8719ea5728802e10d9e0dff1519e"
1103811038
integrity sha512-sSFdyCP3G6Ka0CEmN83A2YCMKIieHx0EDaj5IDP4g1pa5ZJ4FJDvpO0WODLxo4LUX4oe52gmSCK7Jw4SBghqxA==
1103911039

11040+
vfile-location@^3.2.0:
11041+
version "3.2.0"
11042+
resolved "https://registry.yarnpkg.com/vfile-location/-/vfile-location-3.2.0.tgz#d8e41fbcbd406063669ebf6c33d56ae8721d0f3c"
11043+
integrity sha512-aLEIZKv/oxuCDZ8lkJGhuhztf/BW4M+iHdCwglA/eWc+vtuRFJj8EtgceYFX4LRjOhCAAiNHsKGssC6onJ+jbA==
11044+
1104011045
vfile-message@^1.0.0:
1104111046
version "1.1.1"
1104211047
resolved "https://registry.yarnpkg.com/vfile-message/-/vfile-message-1.1.1.tgz#5833ae078a1dfa2d96e9647886cd32993ab313e1"

0 commit comments

Comments
 (0)