Skip to content

Commit 2f6230e

Browse files
committed
Fix missing node
1 parent 878eaec commit 2f6230e

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ var digit6 = 54 // `6`
88

99
// Rank of a heading: H1 -> 1, H2 -> 2, etc.
1010
function headingRank(node) {
11-
var name = (node.type === 'element' ? node.tagName : '').toLowerCase()
11+
var name = (
12+
(node && node.type === 'element' && node.tagName) ||
13+
''
14+
).toLowerCase()
1215
var code =
1316
name.length === 2 && name.charCodeAt(0) === lowercaseH
1417
? name.charCodeAt(1)

test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ var h = require('hastscript')
55
var rank = require('.')
66

77
test('rank', function(t) {
8+
t.equal(rank(), null, 'should return null for non-nodes')
9+
810
t.equal(
911
rank({type: 'text', value: '!'}),
1012
null,

0 commit comments

Comments
 (0)