* Handle `[` fragment selector. Fix #2349 * Update tests * Simplify hyperscript function
This commit is contained in:
parent
1aaa2ff568
commit
39c20bdb34
2 changed files with 186 additions and 173 deletions
|
|
@ -90,11 +90,12 @@ function hyperscript(selector) {
|
||||||
var vnode = hyperscriptVnode.apply(1, arguments)
|
var vnode = hyperscriptVnode.apply(1, arguments)
|
||||||
|
|
||||||
if (typeof selector === "string") {
|
if (typeof selector === "string") {
|
||||||
return execSelector(selectorCache[selector] || compileSelector(selector), vnode)
|
vnode.children = Vnode.normalizeChildren(vnode.children)
|
||||||
} else {
|
if (selector !== "[") return execSelector(selectorCache[selector] || compileSelector(selector), vnode)
|
||||||
|
}
|
||||||
|
|
||||||
vnode.tag = selector
|
vnode.tag = selector
|
||||||
return vnode
|
return vnode
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = hyperscript
|
module.exports = hyperscript
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,16 @@
|
||||||
|
|
||||||
var o = require("../../ospec/ospec")
|
var o = require("../../ospec/ospec")
|
||||||
var fragment = require("../../render/fragment")
|
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() {
|
o("works", function() {
|
||||||
var attrs = {foo: 5}
|
var attrs = {foo: 5}
|
||||||
var child = {tag: "p"}
|
var child = {tag: "p"}
|
||||||
|
|
@ -195,3 +203,7 @@ o.spec("fragment", function() {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
runTest("fragment", fragment);
|
||||||
|
runTest("fragment-string-selector", fragmentStr);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue