Skip to content

Commit

Permalink
Fix support for node w/o position
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Aug 12, 2021
1 parent 646fff9 commit 8e86790
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ export class VFileMessage extends Error {
if (place) {
// Node.
if ('type' in place || 'position' in place) {
position = place.position
if (place.position) {
position = place.position
}
}
// Position.
else if ('start' in place || 'end' in place) {
Expand Down
5 changes: 5 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ test('VFileMessage(reason[, place][, origin])', function (t) {

t.deepEqual(message.position, place.position, 'should accept a node (1)')
t.equal(String(message), '2:3-2:5: test', 'should accept a node (2)')
t.equal(
String(new VFileMessage('test', {type: 'x'})),
'1:1-1:1: test',
'should accept a node (3)'
)

place = place.position
message = new VFileMessage('test', place)
Expand Down

0 comments on commit 8e86790

Please sign in to comment.