Skip to content

Commit

Permalink
Fix missing node
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Mar 4, 2020
1 parent 878eaec commit 2f6230e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 4 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ var digit6 = 54 // `6`

// Rank of a heading: H1 -> 1, H2 -> 2, etc.
function headingRank(node) {
var name = (node.type === 'element' ? node.tagName : '').toLowerCase()
var name = (
(node && node.type === 'element' && node.tagName) ||
''
).toLowerCase()
var code =
name.length === 2 && name.charCodeAt(0) === lowercaseH
? name.charCodeAt(1)
Expand Down
2 changes: 2 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ var h = require('hastscript')
var rank = require('.')

test('rank', function(t) {
t.equal(rank(), null, 'should return null for non-nodes')

t.equal(
rank({type: 'text', value: '!'}),
null,
Expand Down

0 comments on commit 2f6230e

Please sign in to comment.