Skip to content

Commit

Permalink
Fix support for void nodes
Browse files Browse the repository at this point in the history
Closes GH-5.
Closes GH-6.

Reviewed-by: Titus Wormer <[email protected]>
  • Loading branch information
staltz authored May 4, 2021
1 parent 44e794d commit 37c315f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function toString(node, separator = '') {
if (typeof node.value === 'string') return node.value

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

// Shortcut: This is pretty common, and a small performance win.
if (children.length === 1 && 'value' in children[0]) {
Expand Down
2 changes: 2 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,7 @@ test('toString()', function (t) {
'should support separators'
)

t.equal(toString(u('foo')), '', 'should support voids')

t.end()
})

0 comments on commit 37c315f

Please sign in to comment.