Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ class Node {
line: opts.start.line,
offset: sourceOffset(inputString, opts.start)
}
} else if (opts.index) {
} else if (typeof opts.index === 'number') {
start = this.positionInside(opts.index)
}

Expand All @@ -310,7 +310,7 @@ class Node {
}
} else if (typeof opts.endIndex === 'number') {
end = this.positionInside(opts.endIndex)
} else if (opts.index) {
} else if (typeof opts.index === 'number') {
end = this.positionInside(opts.index + 1)
}
}
Expand Down
10 changes: 10 additions & 0 deletions test/node.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,16 @@ test('rangeBy() returns range for index and endIndex', () => {
})
})

test('rangeBy() returns range for index 0', () => {
let css = parse('a { one: X }')
let a = css.first as Rule
let one = a.first as Declaration
equal(one.rangeBy({ index: 0 }), {
end: { column: 7, line: 1, offset: 6 },
start: { column: 6, line: 1, offset: 5 }
})
})

test('rangeBy() returns range for index and endIndex when offsets are missing', () => {
let css = parse('a { one: X }')
let a = css.first as Rule
Expand Down
9 changes: 9 additions & 0 deletions test/warning.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,15 @@ test('gets range from index', () => {
is(warning.endColumn, 4)
})

test('gets range from index 0', () => {
let root = parse('a b{}')
let warning = new Warning('text', { index: 0, node: root.first })
is(warning.line, 1)
is(warning.column, 1)
is(warning.endLine, 1)
is(warning.endColumn, 2)
})

test('gets range from index and endIndex', () => {
let root = parse('a b{}')
let warning = new Warning('text', { endIndex: 3, index: 2, node: root.first })
Expand Down