[Pkg-javascript-commits] [ltx] 453/469: createElement: ignore null and undefined children (#98)
Jonas Smedegaard
dr at jones.dk
Wed Aug 31 13:03:38 UTC 2016
This is an automated email from the git hooks/post-receive script.
js pushed a commit to branch master
in repository ltx.
commit 191d33d47a7f1874af63dba045f4b6079f2c8d79
Author: Sonny Piers <sonny at fastmail.net>
Date: Sun Jun 12 17:20:32 2016 +0200
createElement: ignore null and undefined children (#98)
---
lib/createElement.js | 3 ++-
test/createElement-test.js | 8 ++++++++
2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/lib/createElement.js b/lib/createElement.js
index 3454c6c..2691e2c 100644
--- a/lib/createElement.js
+++ b/lib/createElement.js
@@ -14,7 +14,8 @@ module.exports = function createElement (name, attrs /*, child1, child2, ...*/)
var el = new Element(name, attrs)
for (var i = 2; i < arguments.length; i++) {
- el.cnode(arguments[i])
+ var child = arguments[i]
+ if (child) el.cnode(child)
}
return el
diff --git a/test/createElement-test.js b/test/createElement-test.js
index af5d02f..3bf060d 100644
--- a/test/createElement-test.js
+++ b/test/createElement-test.js
@@ -16,5 +16,13 @@ vows.describe('createElement').addBatch({
assert.equal(e.children.length, 2)
assert.equal(e.children[0], 'foo')
assert.equal(e.children[1], c)
+ },
+ 'null and undefined children are discarded': function () {
+ var e = createElement('foo', null, undefined, 'bar', null, createElement('test'), 'baz')
+ var b = new Element('foo')
+ .t('bar')
+ .c('test').up()
+ .t('baz')
+ assert.equal(e.root().toString(), b.root().toString())
}
}).export(module)
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/ltx.git
More information about the Pkg-javascript-commits
mailing list