From 85287a3691cf0d66e926ce25809914043e111afb Mon Sep 17 00:00:00 2001 From: Mark Stahl Date: Thu, 20 Jun 2019 20:55:58 -0400 Subject: [PATCH 1/4] Fixes choojs/nanohtml#51. 'false' doesn't render --- test/types.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/test/types.js b/test/types.js index 13f6c21..af1e663 100644 --- a/test/types.js +++ b/test/types.js @@ -15,9 +15,15 @@ test('null value (empty)', function (t) { t.end() }) +test('string value (empty)', function (t) { + var tree = hx`
${''}
` + t.equal(vdom.create(tree).toString(), '
') + t.end() +}) + test('boolean value', function (t) { var tree = hx`
${false}
` - t.equal(vdom.create(tree).toString(), '
false
') + t.equal(vdom.create(tree).toString(), '
') t.end() }) @@ -26,3 +32,9 @@ test('numeric value', function (t) { t.equal(vdom.create(tree).toString(), '
555
') t.end() }) + +test('numeric value (zero)', function (t) { + var tree = hx`
${0}
` + t.equal(vdom.create(tree).toString(), '
0
') + t.end() +}) From efc27b8d080296cd9d70d7cb1a7dda07cefdf4d0 Mon Sep 17 00:00:00 2001 From: Mark Stahl Date: Fri, 21 Jun 2019 12:26:10 -0400 Subject: [PATCH 2/4] a value of false is equal to '' --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index de6fc07..4c595d9 100644 --- a/index.js +++ b/index.js @@ -117,7 +117,7 @@ module.exports = function (h, opts) { ) } } else if (s === VAR && p[1] === TEXT) { - if (p[2] === undefined || p[2] === null) p[2] = '' + if (p[2] === undefined || p[2] === null || p[2] === false) p[2] = '' else if (!p[2]) p[2] = concat('', p[2]) if (Array.isArray(p[2][0])) { cur[2].push.apply(cur[2], p[2]) From 7e14e865f00f83e4c2973e8273815c173fba0694 Mon Sep 17 00:00:00 2001 From: Mark Stahl Date: Fri, 21 Jun 2019 12:32:19 -0400 Subject: [PATCH 3/4] Added true breaking boolean type test --- test/types.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/test/types.js b/test/types.js index af1e663..f884025 100644 --- a/test/types.js +++ b/test/types.js @@ -21,12 +21,18 @@ test('string value (empty)', function (t) { t.end() }) -test('boolean value', function (t) { +test('boolean value (empty)', function (t) { var tree = hx`
${false}
` t.equal(vdom.create(tree).toString(), '
') t.end() }) +test('boolean value', function (t) { + var tree = hx`
${true}
` + t.equal(vdom.create(tree).toString(), '
true
') + t.end() +}) + test('numeric value', function (t) { var tree = hx`
${555}
` t.equal(vdom.create(tree).toString(), '
555
') From 39b34d3e4ff6833960dc0d53a3a14eaa1dea2fd9 Mon Sep 17 00:00:00 2001 From: Mark Stahl Date: Fri, 21 Jun 2019 12:53:01 -0400 Subject: [PATCH 4/4] Add support for true text node --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 4c595d9..2c707c6 100644 --- a/index.js +++ b/index.js @@ -118,7 +118,7 @@ module.exports = function (h, opts) { } } else if (s === VAR && p[1] === TEXT) { if (p[2] === undefined || p[2] === null || p[2] === false) p[2] = '' - else if (!p[2]) p[2] = concat('', p[2]) + else if (!p[2] || p[2] === true) p[2] = concat('', p[2]) if (Array.isArray(p[2][0])) { cur[2].push.apply(cur[2], p[2]) } else {