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

Function stringifyElement

packages/compiler-dom/src/transforms/stringifyStatic.ts:324–394  ·  packages/compiler-dom/src/transforms/stringifyStatic.ts::stringifyElement
(
  node: ElementNode,
  context: TransformContext,
)

Source from the content-addressed store, hash-verified

322}
323
324function stringifyElement(
325 node: ElementNode,
326 context: TransformContext,
327): string {
328 let res = `<${node.tag}`
329 let innerHTML = class="st">''
330 for (let i = 0; i < node.props.length; i++) {
331 const p = node.props[i]
332 if (p.type === NodeTypes.ATTRIBUTE) {
333 res += ` ${p.name}`
334 if (p.value) {
335 res += `=class="st">"${escapeHtml(p.value.content)}"`
336 }
337 } else if (p.type === NodeTypes.DIRECTIVE) {
338 if (p.name === class="st">'bind') {
339 const exp = p.exp as SimpleExpressionNode
340 if (exp.content[0] === class="st">'_') {
341 class="cm">// internally generated string constant references
342 class="cm">// e.g. imported URL strings via compiler-sfc transformAssetUrl plugin
343 res += ` ${
344 (p.arg as SimpleExpressionNode).content
345 }=class="st">"__VUE_EXP_START__${exp.content}__VUE_EXP_END__"`
346 continue
347 }
348 class="cm">// #6568
349 if (
350 isBooleanAttr((p.arg as SimpleExpressionNode).content) &&
351 exp.content === class="st">'false'
352 ) {
353 continue
354 }
355 class="cm">// constant v-bind, e.g. :foo=class="st">"1"
356 let evaluated = evaluateConstant(exp)
357 if (evaluated != null) {
358 const arg = p.arg && (p.arg as SimpleExpressionNode).content
359 if (arg === class="st">'class') {
360 evaluated = normalizeClass(evaluated)
361 } else if (arg === class="st">'style') {
362 evaluated = stringifyStyle(normalizeStyle(evaluated))
363 }
364 res += ` ${(p.arg as SimpleExpressionNode).content}="${escapeHtml(
365 evaluated,
366 )}"`
367 }
368 } else if (p.name === class="st">'html') {
369 class="cm">// #5439 v-html with constant value
370 class="cm">// not sure why would anyone do this but it can happen
371 innerHTML = evaluateConstant(p.exp as SimpleExpressionNode)
372 } else if (p.name === class="st">'text') {
373 innerHTML = escapeHtml(
374 toDisplayString(evaluateConstant(p.exp as SimpleExpressionNode)),
375 )
376 }
377 }
378 }
379 if (context.scopeId) {
380 res += ` ${context.scopeId}`
381 }

Callers 1

stringifyNodeFunction · 0.85

Calls 7

escapeHtmlFunction · 0.90
normalizeClassFunction · 0.90
stringifyStyleFunction · 0.90
normalizeStyleFunction · 0.90
toDisplayStringFunction · 0.90
evaluateConstantFunction · 0.85
stringifyNodeFunction · 0.85

Tested by

no test coverage detected