Skip to content

Commit 1035b26

Browse files
committed
Add range, direct positional info
1 parent f286610 commit 1035b26

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

index.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -396,17 +396,20 @@ function all(parent, context) {
396396
return results
397397
}
398398

399-
function create(hast, estree) {
399+
function create(hast, esnode) {
400400
var p = position(hast)
401401

402402
if (p.start.line) {
403-
estree.loc = {
403+
esnode.start = p.start.offset
404+
esnode.end = p.end.offset
405+
esnode.loc = {
404406
start: {line: p.start.line, column: p.start.column - 1},
405407
end: {line: p.end.line, column: p.end.column - 1}
406408
}
409+
esnode.range = [p.start.offset, p.end.offset]
407410
}
408411

409-
return estree
412+
return esnode
410413
}
411414

412415
function parseStyle(value, tagName) {

test.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,10 @@ test('hast-util-to-estree', function (t) {
6767
tagName: 'x',
6868
properties: {},
6969
children: [],
70-
position: {start: {line: 1, column: 1}, end: {line: 1, column: 5}}
70+
position: {
71+
start: {line: 1, column: 1, offset: 0},
72+
end: {line: 1, column: 5, offset: 4}
73+
}
7174
}),
7275
{
7376
type: 'Program',
@@ -84,7 +87,10 @@ test('hast-util-to-estree', function (t) {
8487
},
8588
closingElement: null,
8689
children: [],
87-
loc: {start: {line: 1, column: 0}, end: {line: 1, column: 4}}
90+
start: 0,
91+
end: 4,
92+
loc: {start: {line: 1, column: 0}, end: {line: 1, column: 4}},
93+
range: [0, 4]
8894
}
8995
}
9096
],

0 commit comments

Comments
 (0)