/
createElement.ts
51 lines (46 loc) · 1.42 KB
/
createElement.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import type { CreateElement } from 'vue'
import {
getVueConstructor,
getCurrentInstance,
ComponentInternalInstance,
} from '../runtimeContext'
import { defineComponentInstance } from '../utils/helper'
import { warn } from '../utils'
import { AsyncComponent, Component } from 'vue/types/options'
import { VNode, VNodeChildren, VNodeData } from 'vue/types/vnode'
export interface H extends CreateElement {
(
this: ComponentInternalInstance | null,
tag?:
| string
| Component<any, any, any, any>
| AsyncComponent<any, any, any, any>
| (() => Component),
children?: VNodeChildren
): VNode
(
this: ComponentInternalInstance | null,
tag?:
| string
| Component<any, any, any, any>
| AsyncComponent<any, any, any, any>
| (() => Component),
data?: VNodeData,
children?: VNodeChildren
): VNode
}
let fallbackCreateElement: CreateElement
export const createElement = function createElement(this, ...args: any) {
const instance = this ? this.proxy : getCurrentInstance()?.proxy
if (!instance) {
__DEV__ &&
warn('`createElement()` has been called outside of render function.')
if (!fallbackCreateElement) {
fallbackCreateElement = defineComponentInstance(
getVueConstructor()
).$createElement
}
return fallbackCreateElement.apply(fallbackCreateElement, args)
}
return instance.$createElement.apply(instance, args)
} as H