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

Function stringifyElement

packages/compiler-dom/src/transforms/stringifyStatic.ts:324–394  ·  view source on GitHub ↗
(
  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 = ''
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 += `="${escapeHtml(p.value.content)}"`
336 }
337 } else if (p.type === NodeTypes.DIRECTIVE) {
338 if (p.name === 'bind') {
339 const exp = p.exp as SimpleExpressionNode
340 if (exp.content[0] === '_') {
341 // internally generated string constant references
342 // e.g. imported URL strings via compiler-sfc transformAssetUrl plugin
343 res += ` ${
344 (p.arg as SimpleExpressionNode).content
345 }="__VUE_EXP_START__${exp.content}__VUE_EXP_END__"`
346 continue
347 }
348 // #6568
349 if (
350 isBooleanAttr((p.arg as SimpleExpressionNode).content) &&
351 exp.content === 'false'
352 ) {
353 continue
354 }
355 // constant v-bind, e.g. :foo="1"
356 let evaluated = evaluateConstant(exp)
357 if (evaluated != null) {
358 const arg = p.arg && (p.arg as SimpleExpressionNode).content
359 if (arg === 'class') {
360 evaluated = normalizeClass(evaluated)
361 } else if (arg === 'style') {
362 evaluated = stringifyStyle(normalizeStyle(evaluated))
363 }
364 res += ` ${(p.arg as SimpleExpressionNode).content}="${escapeHtml(
365 evaluated,
366 )}"`
367 }
368 } else if (p.name === 'html') {
369 // #5439 v-html with constant value
370 // not sure why would anyone do this but it can happen
371 innerHTML = evaluateConstant(p.exp as SimpleExpressionNode)
372 } else if (p.name === '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