From ba3597bec8d009b43e2096f05771d420b4f3133e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Staltz?= Date: Mon, 3 May 2021 15:44:57 +0300 Subject: [PATCH] Handle nodes that don't have a children field --- index.js | 2 +- test.js | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index d054910..28e8389 100644 --- a/index.js +++ b/index.js @@ -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]) { diff --git a/test.js b/test.js index 943641a..a4f11ab 100644 --- a/test.js +++ b/test.js @@ -50,5 +50,7 @@ test('toString()', function (t) { 'should support separators' ) + t.equal(toString(u('foo')), '', 'should support voids') + t.end() })