Skip to content

Commit

Permalink
Convert object
Browse files Browse the repository at this point in the history
  • Loading branch information
TrySound committed Nov 21, 2020
1 parent 96d7e76 commit 3ef06ec
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
4 changes: 1 addition & 3 deletions lib/input.d.ts
Expand Up @@ -126,7 +126,5 @@ export default class Input {
*
* @param offset Source offset.
*/
fromOffset (
offset: number
): { offset?: number; line?: number; column?: number }
fromOffset (offset: number): { line: number; col: number } | null
}
10 changes: 8 additions & 2 deletions lib/input.js
Expand Up @@ -51,7 +51,13 @@ class Input {

fromOffset (offset) {
let finder = vfileLocation(this.css)
this.fromOffset = i => finder.toPoint(i)
this.fromOffset = i => {
let position = finder.toPoint(i)
return {
line: position.line,
col: position.column
}
}
return this.fromOffset(offset)
}

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

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

init (node, offset) {
Expand Down

0 comments on commit 3ef06ec

Please sign in to comment.