( node: ConditionalExpression, context: CodegenContext, )
| 977 | } |
| 978 | |
| 979 | function 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 | |
| 1015 | function genCacheExpression(node: CacheExpression, context: CodegenContext) { |
| 1016 | const { push, helper, indent, deindent, newline } = context |
no test coverage detected