|
|
@@ -20,7 +20,8 @@ import {
|
|
|
IfNode,
|
|
|
createVNodeCall,
|
|
|
AttributeNode,
|
|
|
- locStub
|
|
|
+ locStub,
|
|
|
+ CacheExpression
|
|
|
} from '../ast'
|
|
|
import { createCompilerError, ErrorCodes } from '../errors'
|
|
|
import { processExpression } from './transformExpression'
|
|
|
@@ -62,13 +63,7 @@ export const transformIf = createStructuralDirectiveTransform(
|
|
|
) as IfConditionalExpression
|
|
|
} else {
|
|
|
// attach this branch's codegen node to the v-if root.
|
|
|
- let parentCondition = ifNode.codegenNode!
|
|
|
- while (
|
|
|
- parentCondition.alternate.type ===
|
|
|
- NodeTypes.JS_CONDITIONAL_EXPRESSION
|
|
|
- ) {
|
|
|
- parentCondition = parentCondition.alternate
|
|
|
- }
|
|
|
+ const parentCondition = getParentCondition(ifNode.codegenNode!)
|
|
|
parentCondition.alternate = createCodegenNodeForBranch(
|
|
|
branch,
|
|
|
key + ifNode.branches.length - 1,
|
|
|
@@ -293,3 +288,19 @@ function isSameKey(
|
|
|
}
|
|
|
return true
|
|
|
}
|
|
|
+
|
|
|
+function getParentCondition(
|
|
|
+ node: IfConditionalExpression | CacheExpression
|
|
|
+): IfConditionalExpression {
|
|
|
+ while (true) {
|
|
|
+ if (node.type === NodeTypes.JS_CONDITIONAL_EXPRESSION) {
|
|
|
+ if (node.alternate.type === NodeTypes.JS_CONDITIONAL_EXPRESSION) {
|
|
|
+ node = node.alternate
|
|
|
+ } else {
|
|
|
+ return node
|
|
|
+ }
|
|
|
+ } else if (node.type === NodeTypes.JS_CACHE_EXPRESSION) {
|
|
|
+ node = node.value as IfConditionalExpression
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|