* Fix #2434 * Treat holes as unkeyed, normalize boolean/null/undefined This brings a lot better consistency with that API, even though it's slightly breaking. (I had to update a bunch of tests to correspond with it.) * Fill in PR number [skip ci]
20 lines
763 B
JavaScript
20 lines
763 B
JavaScript
"use strict"
|
|
|
|
function Vnode(tag, key, attrs, children, text, dom) {
|
|
return {tag: tag, key: key, attrs: attrs, children: children, text: text, dom: dom, domSize: undefined, state: undefined, events: undefined, instance: undefined}
|
|
}
|
|
Vnode.normalize = function(node) {
|
|
if (Array.isArray(node)) return Vnode("[", undefined, undefined, Vnode.normalizeChildren(node), undefined, undefined)
|
|
if (node == null || typeof node === "boolean") return null
|
|
if (typeof node === "object") return node
|
|
return Vnode("#", undefined, undefined, String(node), undefined, undefined)
|
|
}
|
|
Vnode.normalizeChildren = function(input) {
|
|
var children = []
|
|
for (var i = 0; i < input.length; i++) {
|
|
children[i] = Vnode.normalize(input[i])
|
|
}
|
|
return children
|
|
}
|
|
|
|
module.exports = Vnode
|