Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Add support for false as child #67

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ function dom (tag, props, ...children) {
}
break;

case 'boolean':
if (!child) {
children.splice(i, 1)
break;
}
/* fallthrough */

default:
throw new Error(`Invalid child node: ${child}`)
}
Expand Down
8 changes: 2 additions & 6 deletions test/unit/dom.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,13 @@ describe('etch.dom', () => {
expect(component.element.outerHTML).to.equal('<svg><circle></circle></svg>')
})

it('ignores nulls passed in the place of children, but throws an error if other invalid values are passed', () => {
it('ignores nulls and false passed in the place of children, but throws an error if other invalid values are passed', () => {
const element = etch.render(
<div><span/>{null}<p/></div>
<div><span/>{null}{false}<p/></div>
);

expect(Array.from(element.children).map(c => c.tagName)).to.eql(['SPAN', 'P'])

expect(() => etch.render(
<div>{false}</div>
)).to.throw('Invalid child node: false')

expect(() => etch.render(
<div>{undefined}</div>
)).to.throw('Invalid child node: undefined')
Expand Down