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

Function stringifyCurrentChunk

packages/compiler-dom/src/transforms/stringifyStatic.ts:94–144  ·  view source on GitHub ↗
(currentIndex: number)

Source from the content-addressed store, hash-verified

92 const currentChunk: StringifiableNode[] = []
93
94 const stringifyCurrentChunk = (currentIndex: number): number => {
95 if (
96 nc >= StringifyThresholds.NODE_COUNT ||
97 ec >= StringifyThresholds.ELEMENT_WITH_BINDING_COUNT
98 ) {
99 // combine all currently eligible nodes into a single static vnode call
100 const staticCall = createCallExpression(context.helper(CREATE_STATIC), [
101 JSON.stringify(
102 currentChunk.map(node => stringifyNode(node, context)).join(''),
103 ).replace(expReplaceRE, `" + $1 + "`),
104 // the 2nd argument indicates the number of DOM nodes this static vnode
105 // will insert / hydrate
106 String(currentChunk.length),
107 ])
108
109 const deleteCount = currentChunk.length - 1
110
111 if (isParentCached) {
112 // if the parent is cached, then `children` is also the value of the
113 // CacheExpression. Just replace the corresponding range in the cached
114 // list with staticCall.
115 children.splice(
116 currentIndex - currentChunk.length,
117 currentChunk.length,
118 // @ts-expect-error
119 staticCall,
120 )
121 } else {
122 // replace the first node's hoisted expression with the static vnode call
123 ;(currentChunk[0].codegenNode as CacheExpression).value = staticCall
124 if (currentChunk.length > 1) {
125 // remove merged nodes from children
126 children.splice(currentIndex - currentChunk.length + 1, deleteCount)
127 // also adjust index for the remaining cache items
128 const cacheIndex = context.cached.indexOf(
129 currentChunk[currentChunk.length - 1]
130 .codegenNode as CacheExpression,
131 )
132 if (cacheIndex > -1) {
133 for (let i = cacheIndex; i < context.cached.length; i++) {
134 const c = context.cached[i]
135 if (c) c.index -= deleteCount
136 }
137 context.cached.splice(cacheIndex - deleteCount + 1, deleteCount)
138 }
139 }
140 }
141 return deleteCount
142 }
143 return 0
144 }
145
146 let i = 0
147 for (; i < children.length; i++) {

Callers 1

stringifyStaticFunction · 0.85

Calls 6

createCallExpressionFunction · 0.90
stringifyNodeFunction · 0.85
StringInterface · 0.85
mapMethod · 0.80
indexOfMethod · 0.80
helperMethod · 0.65

Tested by

no test coverage detected