Allow variadic arguments to m.fragment (#2328)
* Implement support for variadic arguments to `m.fragment` While I was at it, I refactored the common logic out of `hyperscript`. * Add a missed change from #2326 * Update docs + changelog [skip ci] * Explain rationale for `hyperscriptVnode`'s calling convention This way, it doesn't get erroneously "cleaned up" into something worse, and so it's clearer how it'd be potentially optimized once ES5 support is dropped.
This commit is contained in:
parent
843f420291
commit
966e78bcab
8 changed files with 256 additions and 43 deletions
|
|
@ -32,4 +32,166 @@ o.spec("fragment", function() {
|
|||
|
||||
o(frag.key).equals(7)
|
||||
})
|
||||
o.spec("children with no attrs", function() {
|
||||
o("handles string single child", function() {
|
||||
var vnode = fragment(["a"])
|
||||
|
||||
o(vnode.children[0].tag).equals("#")
|
||||
o(vnode.children[0].children).equals("a")
|
||||
})
|
||||
o("handles falsy string single child", function() {
|
||||
var vnode = fragment([""])
|
||||
|
||||
o(vnode.children[0].tag).equals("#")
|
||||
o(vnode.children[0].children).equals("")
|
||||
})
|
||||
o("handles number single child", function() {
|
||||
var vnode = fragment([1])
|
||||
|
||||
o(vnode.children[0].tag).equals("#")
|
||||
o(vnode.children[0].children).equals(1)
|
||||
})
|
||||
o("handles falsy number single child", function() {
|
||||
var vnode = fragment([0])
|
||||
|
||||
o(vnode.children[0].tag).equals("#")
|
||||
o(vnode.children[0].children).equals(0)
|
||||
})
|
||||
o("handles boolean single child", function() {
|
||||
var vnode = fragment([true])
|
||||
|
||||
o(vnode.children[0].tag).equals("#")
|
||||
o(vnode.children[0].children).equals(true)
|
||||
})
|
||||
o("handles falsy boolean single child", function() {
|
||||
var vnode = fragment([false])
|
||||
|
||||
o(vnode.children[0].tag).equals("#")
|
||||
o(vnode.children[0].children).equals("")
|
||||
})
|
||||
o("handles null single child", function() {
|
||||
var vnode = fragment([null])
|
||||
|
||||
o(vnode.children[0]).equals(null)
|
||||
})
|
||||
o("handles undefined single child", function() {
|
||||
var vnode = fragment([undefined])
|
||||
|
||||
o(vnode.children[0]).equals(undefined)
|
||||
})
|
||||
o("handles multiple string children", function() {
|
||||
var vnode = fragment(["", "a"])
|
||||
|
||||
o(vnode.children[0].tag).equals("#")
|
||||
o(vnode.children[0].children).equals("")
|
||||
o(vnode.children[1].tag).equals("#")
|
||||
o(vnode.children[1].children).equals("a")
|
||||
})
|
||||
o("handles multiple number children", function() {
|
||||
var vnode = fragment([0, 1])
|
||||
|
||||
o(vnode.children[0].tag).equals("#")
|
||||
o(vnode.children[0].children).equals(0)
|
||||
o(vnode.children[1].tag).equals("#")
|
||||
o(vnode.children[1].children).equals(1)
|
||||
})
|
||||
o("handles multiple boolean children", function() {
|
||||
var vnode = fragment([false, true])
|
||||
|
||||
o(vnode.children[0].tag).equals("#")
|
||||
o(vnode.children[0].children).equals("")
|
||||
o(vnode.children[1].tag).equals("#")
|
||||
o(vnode.children[1].children).equals(true)
|
||||
})
|
||||
o("handles multiple null/undefined child", function() {
|
||||
var vnode = fragment([null, undefined])
|
||||
|
||||
o(vnode.children[0]).equals(null)
|
||||
o(vnode.children[1]).equals(undefined)
|
||||
})
|
||||
o("handles falsy number single child without attrs", function() {
|
||||
var vnode = fragment(0)
|
||||
|
||||
o(vnode.children[0].tag).equals("#")
|
||||
o(vnode.children[0].children).equals(0)
|
||||
})
|
||||
})
|
||||
o.spec("children with attrs", function() {
|
||||
o("handles string single child", function() {
|
||||
var vnode = fragment({}, ["a"])
|
||||
|
||||
o(vnode.children[0].tag).equals("#")
|
||||
o(vnode.children[0].children).equals("a")
|
||||
})
|
||||
o("handles falsy string single child", function() {
|
||||
var vnode = fragment({}, [""])
|
||||
|
||||
o(vnode.children[0].tag).equals("#")
|
||||
o(vnode.children[0].children).equals("")
|
||||
})
|
||||
o("handles number single child", function() {
|
||||
var vnode = fragment({}, [1])
|
||||
|
||||
o(vnode.children[0].tag).equals("#")
|
||||
o(vnode.children[0].children).equals(1)
|
||||
})
|
||||
o("handles falsy number single child", function() {
|
||||
var vnode = fragment({}, [0])
|
||||
|
||||
o(vnode.children[0].tag).equals("#")
|
||||
o(vnode.children[0].children).equals(0)
|
||||
})
|
||||
o("handles boolean single child", function() {
|
||||
var vnode = fragment({}, [true])
|
||||
|
||||
o(vnode.children[0].tag).equals("#")
|
||||
o(vnode.children[0].children).equals(true)
|
||||
})
|
||||
o("handles falsy boolean single child", function() {
|
||||
var vnode = fragment({}, [false])
|
||||
|
||||
o(vnode.children[0].tag).equals("#")
|
||||
o(vnode.children[0].children).equals("")
|
||||
})
|
||||
o("handles null single child", function() {
|
||||
var vnode = fragment({}, [null])
|
||||
|
||||
o(vnode.children[0]).equals(null)
|
||||
})
|
||||
o("handles undefined single child", function() {
|
||||
var vnode = fragment({}, [undefined])
|
||||
|
||||
o(vnode.children[0]).equals(undefined)
|
||||
})
|
||||
o("handles multiple string children", function() {
|
||||
var vnode = fragment({}, ["", "a"])
|
||||
|
||||
o(vnode.children[0].tag).equals("#")
|
||||
o(vnode.children[0].children).equals("")
|
||||
o(vnode.children[1].tag).equals("#")
|
||||
o(vnode.children[1].children).equals("a")
|
||||
})
|
||||
o("handles multiple number children", function() {
|
||||
var vnode = fragment({}, [0, 1])
|
||||
|
||||
o(vnode.children[0].tag).equals("#")
|
||||
o(vnode.children[0].children).equals(0)
|
||||
o(vnode.children[1].tag).equals("#")
|
||||
o(vnode.children[1].children).equals(1)
|
||||
})
|
||||
o("handles multiple boolean children", function() {
|
||||
var vnode = fragment({}, [false, true])
|
||||
|
||||
o(vnode.children[0].tag).equals("#")
|
||||
o(vnode.children[0].children).equals("")
|
||||
o(vnode.children[1].tag).equals("#")
|
||||
o(vnode.children[1].children).equals(true)
|
||||
})
|
||||
o("handles multiple null/undefined child", function() {
|
||||
var vnode = fragment({}, [null, undefined])
|
||||
|
||||
o(vnode.children[0]).equals(null)
|
||||
o(vnode.children[1]).equals(undefined)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue