}
})
+ test('create with class component', () => {
+ class Component {
+ $props: any
+ static __vccOpts = { template: '<div />' }
+ }
+ const vnode = createVNode(Component)
+ expect(vnode.type).toEqual(Component.__vccOpts)
+ })
+
describe('class normalization', () => {
test('string', () => {
const vnode = createVNode('p', { class: 'foo baz' })
displayName?: string
}
+export interface ClassComponent {
+ new (...args: any[]): ComponentPublicInstance<any, any, any, any, any>
+ __vccOpts: ComponentOptions
+}
+
export type Component = ComponentOptions | FunctionalComponent
// A type used in public APIs where a component type is expected.
// The constructor type is an artificial type returned by defineComponent().
export type PublicAPIComponent =
| Component
- | { new (): ComponentPublicInstance<any, any, any, any, any> }
+ | { new (...args: any[]): ComponentPublicInstance<any, any, any, any, any> }
export { ComponentOptions }
children?: RawChildren | RawSlots
): VNode
-// fake constructor type returned by `defineComponent`
+// fake constructor type returned by `defineComponent` or class component
export function h(type: Constructor, children?: RawChildren): VNode
export function h<P>(
type: Constructor<P>,
ComponentInternalInstance,
Data,
SetupProxySymbol,
- Component
+ Component,
+ ClassComponent
} from './component'
import { RawSlots } from './componentSlots'
import { isReactive, Ref } from '@vue/reactivity'
// A block root keeps track of dynamic nodes within the block in the
// `dynamicChildren` array.
export function createBlock(
- type: VNodeTypes,
+ type: VNodeTypes | ClassComponent,
props?: { [key: string]: any } | null,
children?: any,
patchFlag?: number,
}
export function createVNode(
- type: VNodeTypes,
+ type: VNodeTypes | ClassComponent,
props: (Data & VNodeProps) | null = null,
children: unknown = null,
patchFlag: number = 0,
type = Comment
}
+ // class component normalization.
+ if (isFunction(type) && '__vccOpts' in type) {
+ type = type.__vccOpts
+ }
+
// class & style normalization.
if (props !== null) {
// for reactive or proxy objects, we need to clone it to enable mutation.