Skip to content

Commit 37c315f

Browse files
authored
Fix support for void nodes
Closes GH-5. Closes GH-6. Reviewed-by: Titus Wormer <[email protected]>
1 parent 44e794d commit 37c315f

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export function toString(node, separator = '') {
2525
if (typeof node.value === 'string') return node.value
2626

2727
// @ts-ignore Looks like a list of nodes or parent.
28-
children = 'length' in node ? node : node.children
28+
children = ('length' in node ? node : node.children) || []
2929

3030
// Shortcut: This is pretty common, and a small performance win.
3131
if (children.length === 1 && 'value' in children[0]) {

test.js

+2
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,7 @@ test('toString()', function (t) {
5050
'should support separators'
5151
)
5252

53+
t.equal(toString(u('foo')), '', 'should support voids')
54+
5355
t.end()
5456
})

0 commit comments

Comments
 (0)