Merge two if blocks, chomp an indentation level
This commit is contained in:
parent
905309cb17
commit
71c20b84b8
1 changed files with 32 additions and 34 deletions
|
|
@ -9,43 +9,41 @@ function hyperscript(selector) {
|
||||||
throw Error("The selector must be either a string or a component.");
|
throw Error("The selector must be either a string or a component.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof selector === "string") {
|
if (typeof selector === "string" && selectorCache[selector] === undefined) {
|
||||||
if (selectorCache[selector] === undefined) {
|
var match, tag, classes = [], attributes = {}
|
||||||
var match, tag, classes = [], attributes = {}
|
while (match = selectorParser.exec(selector)) {
|
||||||
while (match = selectorParser.exec(selector)) {
|
var type = match[1], value = match[2]
|
||||||
var type = match[1], value = match[2]
|
if (type === "" && value !== "") tag = value
|
||||||
if (type === "" && value !== "") tag = value
|
else if (type === "#") attributes.id = value
|
||||||
else if (type === "#") attributes.id = value
|
else if (type === ".") classes.push(value)
|
||||||
else if (type === ".") classes.push(value)
|
else if (match[3][0] === "[") {
|
||||||
else if (match[3][0] === "[") {
|
var attrValue = match[6]
|
||||||
var attrValue = match[6]
|
if (attrValue) attrValue = attrValue.replace(/\\(["'])/g, "$1").replace(/\\\\/g, "\\")
|
||||||
if (attrValue) attrValue = attrValue.replace(/\\(["'])/g, "$1").replace(/\\\\/g, "\\")
|
attributes[match[4]] = attrValue || true
|
||||||
attributes[match[4]] = attrValue || true
|
}
|
||||||
|
}
|
||||||
|
if (classes.length > 0) attributes.className = classes.join(" ")
|
||||||
|
selectorCache[selector] = function(attrs, children) {
|
||||||
|
var hasAttrs = false, childList, text
|
||||||
|
var className = attrs.className || attrs.class
|
||||||
|
for (var key in attributes) attrs[key] = attributes[key]
|
||||||
|
if (className !== undefined) {
|
||||||
|
if (attrs.class !== undefined) {
|
||||||
|
attrs.class = undefined
|
||||||
|
attrs.className = className
|
||||||
|
}
|
||||||
|
if (attributes.className !== undefined) attrs.className = attributes.className + " " + className
|
||||||
|
}
|
||||||
|
for (var key in attrs) {
|
||||||
|
if (key !== "key") {
|
||||||
|
hasAttrs = true
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (classes.length > 0) attributes.className = classes.join(" ")
|
if (children instanceof Array && children.length == 1 && children[0] != null && children[0].tag === "#") text = children[0].children
|
||||||
selectorCache[selector] = function(attrs, children) {
|
else childList = children
|
||||||
var hasAttrs = false, childList, text
|
|
||||||
var className = attrs.className || attrs.class
|
|
||||||
for (var key in attributes) attrs[key] = attributes[key]
|
|
||||||
if (className !== undefined) {
|
|
||||||
if (attrs.class !== undefined) {
|
|
||||||
attrs.class = undefined
|
|
||||||
attrs.className = className
|
|
||||||
}
|
|
||||||
if (attributes.className !== undefined) attrs.className = attributes.className + " " + className
|
|
||||||
}
|
|
||||||
for (var key in attrs) {
|
|
||||||
if (key !== "key") {
|
|
||||||
hasAttrs = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (children instanceof Array && children.length == 1 && children[0] != null && children[0].tag === "#") text = children[0].children
|
|
||||||
else childList = children
|
|
||||||
|
|
||||||
return Vnode(tag || "div", attrs.key, hasAttrs ? attrs : undefined, childList, text, undefined)
|
return Vnode(tag || "div", attrs.key, hasAttrs ? attrs : undefined, childList, text, undefined)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var attrs, children, childrenIndex
|
var attrs, children, childrenIndex
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue