675510ea7e0556478c9b4e0ac21a2d274358c39df972e43520e723f25da11d8a86ba62cfbceac05a18922fcfba89f36fd6ae572437a1d60fc26368cfa3093d 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /* @flow */
  2. export default class VNode {
  3. tag: string | void;
  4. data: VNodeData | void;
  5. children: ?Array<VNode>;
  6. text: string | void;
  7. elm: Node | void;
  8. ns: string | void;
  9. context: Component | void; // rendered in this component's scope
  10. key: string | number | void;
  11. componentOptions: VNodeComponentOptions | void;
  12. componentInstance: Component | void; // component instance
  13. parent: VNode | void; // component placeholder node
  14. // strictly internal
  15. raw: boolean; // contains raw HTML? (server only)
  16. isStatic: boolean; // hoisted static node
  17. isRootInsert: boolean; // necessary for enter transition check
  18. isComment: boolean; // empty comment placeholder?
  19. isCloned: boolean; // is a cloned node?
  20. isOnce: boolean; // is a v-once node?
  21. asyncFactory: Function | void; // async component factory function
  22. asyncMeta: Object | void;
  23. isAsyncPlaceholder: boolean;
  24. ssrContext: Object | void;
  25. fnContext: Component | void; // real context vm for functional nodes
  26. fnOptions: ?ComponentOptions; // for SSR caching
  27. devtoolsMeta: ?Object; // used to store functional render context for devtools
  28. fnScopeId: ?string; // functional scope id support
  29. constructor (
  30. tag?: string,
  31. data?: VNodeData,
  32. children?: ?Array<VNode>,
  33. text?: string,
  34. elm?: Node,
  35. context?: Component,
  36. componentOptions?: VNodeComponentOptions,
  37. asyncFactory?: Function
  38. ) {
  39. this.tag = tag
  40. this.data = data
  41. this.children = children
  42. this.text = text
  43. this.elm = elm
  44. this.ns = undefined
  45. this.context = context
  46. this.fnContext = undefined
  47. this.fnOptions = undefined
  48. this.fnScopeId = undefined
  49. this.key = data && data.key
  50. this.componentOptions = componentOptions
  51. this.componentInstance = undefined
  52. this.parent = undefined
  53. this.raw = false
  54. this.isStatic = false
  55. this.isRootInsert = true
  56. this.isComment = false
  57. this.isCloned = false
  58. this.isOnce = false
  59. this.asyncFactory = asyncFactory
  60. this.asyncMeta = undefined
  61. this.isAsyncPlaceholder = false
  62. }
  63. // DEPRECATED: alias for componentInstance for backwards compat.
  64. /* istanbul ignore next */
  65. get child (): Component | void {
  66. return this.componentInstance
  67. }
  68. }
  69. export const createEmptyVNode = (text: string = '') => {
  70. const node = new VNode()
  71. node.text = text
  72. node.isComment = true
  73. return node
  74. }
  75. export function createTextVNode (val: string | number) {
  76. return new VNode(undefined, undefined, undefined, String(val))
  77. }
  78. // optimized shallow clone
  79. // used for static nodes and slot nodes because they may be reused across
  80. // multiple renders, cloning them avoids errors when DOM manipulations rely
  81. // on their elm reference.
  82. export function cloneVNode (vnode: VNode): VNode {
  83. const cloned = new VNode(
  84. vnode.tag,
  85. vnode.data,
  86. // #7975
  87. // clone children array to avoid mutating original in case of cloning
  88. // a child.
  89. vnode.children && vnode.children.slice(),
  90. vnode.text,
  91. vnode.elm,
  92. vnode.context,
  93. vnode.componentOptions,
  94. vnode.asyncFactory
  95. )
  96. cloned.ns = vnode.ns
  97. cloned.isStatic = vnode.isStatic
  98. cloned.key = vnode.key
  99. cloned.isComment = vnode.isComment
  100. cloned.fnContext = vnode.fnContext
  101. cloned.fnOptions = vnode.fnOptions
  102. cloned.fnScopeId = vnode.fnScopeId
  103. cloned.asyncMeta = vnode.asyncMeta
  104. cloned.isCloned = true
  105. return cloned
  106. }