MCPcopy
hub / github.com/vuejs/core / transformElement

Function transformElement

packages/compiler-core/src/transforms/transformElement.ts:73–225  ·  view source on GitHub ↗
(node, context)

Source from the content-addressed store, hash-verified

71
72// generate a JavaScript AST for this element's codegen
73export const transformElement: NodeTransform = (node, context) => {
74 // perform the work on exit, after all child expressions have been
75 // processed and merged.
76 return function postTransformElement() {
77 node = context.currentNode!
78
79 if (
80 !(
81 node.type === NodeTypes.ELEMENT &&
82 (node.tagType === ElementTypes.ELEMENT ||
83 node.tagType === ElementTypes.COMPONENT)
84 )
85 ) {
86 return
87 }
88
89 const { tag, props } = node
90 const isComponent = node.tagType === ElementTypes.COMPONENT
91
92 // The goal of the transform is to create a codegenNode implementing the
93 // VNodeCall interface.
94 let vnodeTag = isComponent
95 ? resolveComponentType(node as ComponentNode, context)
96 : `"${tag}"`
97
98 const isDynamicComponent =
99 isObject(vnodeTag) && vnodeTag.callee === RESOLVE_DYNAMIC_COMPONENT
100
101 let vnodeProps: VNodeCall['props']
102 let vnodeChildren: VNodeCall['children']
103 let patchFlag: VNodeCall['patchFlag'] | 0 = 0
104 let vnodeDynamicProps: VNodeCall['dynamicProps']
105 let dynamicPropNames: string[] | undefined
106 let vnodeDirectives: VNodeCall['directives']
107
108 let shouldUseBlock =
109 // dynamic component may resolve to plain elements
110 isDynamicComponent ||
111 vnodeTag === TELEPORT ||
112 vnodeTag === SUSPENSE ||
113 (!isComponent &&
114 // <svg> and <foreignObject> must be forced into blocks so that block
115 // updates inside get proper isSVG flag at runtime. (#639, #643)
116 // This is technically web-specific, but splitting the logic out of core
117 // leads to too much unnecessary complexity.
118 (tag === 'svg' || tag === 'foreignObject' || tag === 'math'))
119
120 // props
121 if (props.length > 0) {
122 const propsBuildResult = buildProps(
123 node,
124 context,
125 undefined,
126 isComponent,
127 isDynamicComponent,
128 )
129 vnodeProps = propsBuildResult.props
130 patchFlag = propsBuildResult.patchFlag

Callers

nothing calls this directly

Calls 11

isObjectFunction · 0.90
createArrayExpressionFunction · 0.90
createCompilerErrorFunction · 0.90
buildSlotsFunction · 0.90
getConstantTypeFunction · 0.90
createVNodeCallFunction · 0.90
resolveComponentTypeFunction · 0.85
buildPropsFunction · 0.85
buildDirectiveArgsFunction · 0.85
mapMethod · 0.80

Tested by

no test coverage detected