Skip to content

Commit 9137af4

Browse files
committed
xml: ignore false children
1 parent 109053d commit 9137af4

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

packages/xml/lib/x.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
const Element = require('./Element')
44

55
function append(el, child) {
6+
if (child === false || child === null || child === undefined) return
67
if (child instanceof Element) {
78
el.append(child)
89
} else if (Array.isArray(child)) {
910
child.forEach(c => append(el, c))
10-
} else if (child !== null && child !== undefined) {
11+
} else {
1112
el.append(String(child))
1213
}
1314
}

packages/xml/test/Element.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
const test = require('ava')
44
const Element = require('../lib/Element')
55

6-
test('ignore __self and __source properties', t => {
6+
// TODO probably better to ignore in serialization instead
7+
test('ignore __self and __source attributes', t => {
78
const el = new Element('foo', {
89
__source: 'source',
910
__self: 'self',

packages/xml/test/x.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
'use strict'
2+
3+
const test = require('ava')
4+
const x = require('../lib/x')
5+
6+
test('ignore false children', t => {
7+
const el = x('foo', {}, false)
8+
9+
t.is(el.children.length, 0)
10+
})
11+
12+
test('ignore null children', t => {
13+
const el = x('foo', {}, null)
14+
15+
t.is(el.children.length, 0)
16+
})
17+
18+
test('ignore undefined children', t => {
19+
const el = x('foo', {}, undefined)
20+
21+
t.is(el.children.length, 0)
22+
})

0 commit comments

Comments
 (0)