Handle [ fragment selector. Fixes #2349 (#2352)

* Handle `[` fragment selector. Fix #2349

* Update tests

* Simplify hyperscript function
This commit is contained in:
Vasil Rimar 2019-01-07 04:56:09 -05:00 committed by Isiah Meadows
parent 1aaa2ff568
commit 39c20bdb34
2 changed files with 186 additions and 173 deletions

View file

@ -90,11 +90,12 @@ function hyperscript(selector) {
var vnode = hyperscriptVnode.apply(1, arguments)
if (typeof selector === "string") {
return execSelector(selectorCache[selector] || compileSelector(selector), vnode)
} else {
vnode.children = Vnode.normalizeChildren(vnode.children)
if (selector !== "[") return execSelector(selectorCache[selector] || compileSelector(selector), vnode)
}
vnode.tag = selector
return vnode
}
}
module.exports = hyperscript

View file

@ -2,8 +2,16 @@
var o = require("../../ospec/ospec")
var fragment = require("../../render/fragment")
var m = require("../../render/hyperscript")
o.spec("fragment", function() {
function fragmentStr() {
var args = [].slice.call(arguments);
args.unshift("[");
return m.apply(null, args)
}
function runTest(name, fragment) {
o.spec(name, function() {
o("works", function() {
var attrs = {foo: 5}
var child = {tag: "p"}
@ -194,4 +202,8 @@ o.spec("fragment", function() {
o(vnode.children[1]).equals(undefined)
})
})
})
})
}
runTest("fragment", fragment);
runTest("fragment-string-selector", fragmentStr);