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

Function genConditionalExpression

packages/compiler-core/src/codegen.ts:979–1013  ·  view source on GitHub ↗
(
  node: ConditionalExpression,
  context: CodegenContext,
)

Source from the content-addressed store, hash-verified

977}
978
979function genConditionalExpression(
980 node: ConditionalExpression,
981 context: CodegenContext,
982) {
983 const { test, consequent, alternate, newline: needNewline } = node
984 const { push, indent, deindent, newline } = context
985 if (test.type === NodeTypes.SIMPLE_EXPRESSION) {
986 const needsParens = !isSimpleIdentifier(test.content)
987 needsParens && push(`(`)
988 genExpression(test, context)
989 needsParens && push(`)`)
990 } else {
991 push(`(`)
992 genNode(test, context)
993 push(`)`)
994 }
995 needNewline && indent()
996 context.indentLevel++
997 needNewline || push(` `)
998 push(`? `)
999 genNode(consequent, context)
1000 context.indentLevel--
1001 needNewline && newline()
1002 needNewline || push(` `)
1003 push(`: `)
1004 const isNested = alternate.type === NodeTypes.JS_CONDITIONAL_EXPRESSION
1005 if (!isNested) {
1006 context.indentLevel++
1007 }
1008 genNode(alternate, context)
1009 if (!isNested) {
1010 context.indentLevel--
1011 }
1012 needNewline && deindent(true /* without newline */)
1013}
1014
1015function genCacheExpression(node: CacheExpression, context: CodegenContext) {
1016 const { push, helper, indent, deindent, newline } = context

Callers 1

genNodeFunction · 0.85

Calls 7

isSimpleIdentifierFunction · 0.90
genExpressionFunction · 0.85
genNodeFunction · 0.85
indentFunction · 0.85
newlineFunction · 0.85
deindentFunction · 0.85
pushFunction · 0.70

Tested by

no test coverage detected