Skip to content

Commit 1e6a01e

Browse files
committed
Remove ancient handling of nodes w/o offsets
1 parent 29da6bc commit 1e6a01e

File tree

2 files changed

+6
-24
lines changed

2 files changed

+6
-24
lines changed

index.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,19 +98,18 @@ export function toNlcst(tree, file, Parser, options = {}) {
9898
function one(config, node) {
9999
/** @type {number} */
100100
var start
101-
/** @type {number} */
102-
var end
103101

104102
if (!config.ignore.includes(node.type)) {
105-
// To do: next major — nodes should have offsets, so
106-
// `config.location.toOffset` should be superfluous.
107-
start = config.location.toOffset(pointStart(node))
108-
end = config.location.toOffset(pointEnd(node))
103+
start = node.position.start.offset
109104

110105
if (config.source.includes(node.type)) {
111106
return patch(
112107
config,
113-
[config.parser.tokenizeSource(config.doc.slice(start, end))],
108+
[
109+
config.parser.tokenizeSource(
110+
config.doc.slice(start, node.position.end.offset)
111+
)
112+
],
114113
start
115114
)
116115
}

test/index.js

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -120,23 +120,6 @@ test('mdast-util-to-nlcst', function (t) {
120120
'should fail when not given positional information (#2)'
121121
)
122122

123-
t.test('should accept nodes without offsets', function (st) {
124-
var node = toNlcst(
125-
{
126-
type: 'text',
127-
value: 'foo',
128-
position: {start: {line: 1, column: 1}, end: {line: 1, column: 4}}
129-
},
130-
vfile({contents: 'foo'}),
131-
ParseLatin
132-
)
133-
134-
st.equal(node.position.start.offset, 0, 'should set starting offset')
135-
st.equal(node.position.end.offset, 3, 'should set ending offset')
136-
137-
st.end()
138-
})
139-
140123
t.end()
141124
})
142125

0 commit comments

Comments
 (0)