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

Function analyzeNode

packages/compiler-dom/src/transforms/stringifyStatic.ts:212–293  ·  view source on GitHub ↗

* for a cached node, analyze it and return: * - false: bailed (contains non-stringifiable props or runtime constant) * - [nc, ec] where * - nc is the number of nodes inside * - ec is the number of element with bindings inside

(node: StringifiableNode)

Source from the content-addressed store, hash-verified

210 * - ec is the number of element with bindings inside
211 */
212function analyzeNode(node: StringifiableNode): [number, number] | false {
213 if (node.type === NodeTypes.ELEMENT && isNonStringifiable(node.tag)) {
214 return false
215 }
216
217 // v-once nodes should not be stringified
218 if (node.type === NodeTypes.ELEMENT && findDir(node, 'once', true)) {
219 return false
220 }
221
222 if (node.type === NodeTypes.TEXT_CALL) {
223 return [1, 0]
224 }
225
226 let nc = 1 // node count
227 let ec = node.props.length > 0 ? 1 : 0 // element w/ binding count
228 let bailed = false
229 const bail = (): false => {
230 bailed = true
231 return false
232 }
233
234 // TODO: check for cases where using innerHTML will result in different
235 // output compared to imperative node insertions.
236 // probably only need to check for most common case
237 // i.e. non-phrasing-content tags inside `<p>`
238 function walk(node: ElementNode): boolean {
239 const isOptionTag = node.tag === 'option' && node.ns === Namespaces.HTML
240 for (let i = 0; i < node.props.length; i++) {
241 const p = node.props[i]
242 // bail on non-attr bindings
243 if (
244 p.type === NodeTypes.ATTRIBUTE &&
245 !isStringifiableAttr(p.name, node.ns)
246 ) {
247 return bail()
248 }
249 if (p.type === NodeTypes.DIRECTIVE && p.name === 'bind') {
250 // bail on non-attr bindings
251 if (
252 p.arg &&
253 (p.arg.type === NodeTypes.COMPOUND_EXPRESSION ||
254 (p.arg.isStatic && !isStringifiableAttr(p.arg.content, node.ns)))
255 ) {
256 return bail()
257 }
258 if (
259 p.exp &&
260 (p.exp.type === NodeTypes.COMPOUND_EXPRESSION ||
261 p.exp.constType < ConstantTypes.CAN_STRINGIFY)
262 ) {
263 return bail()
264 }
265 // <option :value="1"> cannot be safely stringified
266 if (
267 isOptionTag &&
268 isStaticArgOf(p.arg, 'value') &&
269 p.exp &&

Callers 1

stringifyStaticFunction · 0.85

Calls 2

findDirFunction · 0.90
walkFunction · 0.70

Tested by

no test coverage detected