Skip to content

Commit

Permalink
Fix exception on tree w/o children
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Feb 9, 2021
1 parent d338b17 commit 1dba641
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,8 @@ function messageControl(options) {

// Detect gaps in `tree`.
function detectGaps(tree, file) {
var lastNode = tree.children[tree.children.length - 1]
var children = tree.children || []
var lastNode = children[children.length - 1]
var offset = 0
var gaps = []
var gap
Expand Down
16 changes: 16 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -727,5 +727,21 @@ test('control()', function (t) {
)
})

remark()
.use(function () {
return function (tree, file) {
file.message('Error')
delete tree.children
control({name: 'foo', marker: mdastMarker})(tree, file)
}
})
.process('', function (error, file) {
t.deepEqual(
[error].concat(file.messages.map(String)),
[null, '1:1: Error'],
'should not fail when there are messages but no `children` on `tree`'
)
})

t.end()
})

0 comments on commit 1dba641

Please sign in to comment.