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

Function evaluateConstant

packages/compiler-dom/src/transforms/stringifyStatic.ts:403–423  ·  view source on GitHub ↗
(exp: ExpressionNode)

Source from the content-addressed store, hash-verified

401// run JSFuck in here. But we mark it unsafe for security review purposes.
402// (see compiler-core/src/transforms/transformExpression)
403function evaluateConstant(exp: ExpressionNode): string {
404 if (exp.type === NodeTypes.SIMPLE_EXPRESSION) {
405 return new Function(`return (${exp.content})`)()
406 } else {
407 // compound
408 let res = ``
409 exp.children.forEach(c => {
410 if (isString(c) || isSymbol(c)) {
411 return
412 }
413 if (c.type === NodeTypes.TEXT) {
414 res += c.content
415 } else if (c.type === NodeTypes.INTERPOLATION) {
416 res += toDisplayString(evaluateConstant(c.content))
417 } else {
418 res += evaluateConstant(c as ExpressionNode)
419 }
420 })
421 return res
422 }
423}

Callers 2

stringifyNodeFunction · 0.85
stringifyElementFunction · 0.85

Calls 4

isStringFunction · 0.90
isSymbolFunction · 0.90
toDisplayStringFunction · 0.90
forEachMethod · 0.80

Tested by

no test coverage detected