import { ComponentPropsOptions, ExtractPropTypes } from './componentProps'
import { PROPS, DYNAMIC_SLOTS, FULL_PROPS } from './patchFlags'
import { Slots } from './componentSlots'
-import { STATEFUL_COMPONENT } from './shapeFlags'
+import { STATEFUL_COMPONENT } from './typeFlags'
export type Data = { [key: string]: any }
Portal
} from './vnode'
-export { FunctionalComponent, createComponent } from './component'
-
+export { createComponent, FunctionalComponent } from './component'
+export { createRenderer, RendererOptions } from './createRenderer'
export { Slot, Slots } from './componentSlots'
-
export { PropType, ComponentPropsOptions } from './componentProps'
export * from './reactivity'
export * from './componentLifecycle'
-export { createRenderer, RendererOptions } from './createRenderer'
-
-export { TEXT, CLASS, STYLE, PROPS, KEYED, UNKEYED } from './patchFlags'
+export * from './patchFlags'
+export * from './typeFlags'
TEXT_CHILDREN,
ARRAY_CHILDREN,
SLOTS_CHILDREN
-} from './shapeFlags'
+} from './typeFlags'
export const Fragment = Symbol('Fragment')
export const Text = Symbol('Text')
): VNode {
// Allow passing 0 for props, this can save bytes on generated code.
props = props || null
- // normalize children
- children = normalizeChildren(children) as NormalizedChildren
+ // encode the vnode type information into a bitmap
const typeFlag = isString(type)
? ELEMENT
- : isFunction(type)
- ? FUNCTIONAL_COMPONENT
- : isObject(type)
- ? STATEFUL_COMPONENT
- : 0
-
- const childFlag = isString(children)
- ? TEXT_CHILDREN
- : isArray(children)
- ? ARRAY_CHILDREN
- : isObject(children)
- ? SLOTS_CHILDREN
+ : isObject(type)
+ ? STATEFUL_COMPONENT
+ : isFunction(type)
+ ? FUNCTIONAL_COMPONENT
: 0
const vnode: VNode = {
type,
props,
key: props && props.key,
- children,
+ children: null,
component: null,
el: null,
anchor: null,
target: null,
- shapeFlag: typeFlag | childFlag,
+ shapeFlag: typeFlag,
patchFlag,
dynamicProps,
dynamicChildren: null
}
+ normalizeChildren(vnode, children)
+
// class & style normalization.
if (props !== null) {
// class normalization only needed if the vnode isn't generated by
}
}
-export function normalizeChildren(children: unknown): NormalizedChildren {
+export function normalizeChildren(vnode: VNode, children: unknown) {
+ let type = 0
if (children == null) {
- return null
+ children = null
} else if (isArray(children)) {
- return children
+ type = ARRAY_CHILDREN
} else if (typeof children === 'object') {
- return children as RawSlots
+ type = SLOTS_CHILDREN
} else if (isFunction(children)) {
- return { default: children }
+ children = { default: children }
+ type = SLOTS_CHILDREN
} else {
- return isString(children) ? children : children + ''
+ children = isString(children) ? children : children + ''
+ type = TEXT_CHILDREN
}
+ vnode.children = children as NormalizedChildren
+ vnode.shapeFlag |= type
}
function normalizeStyle(