]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(transform): transform should still apply even when node is removed
authorEvan You <yyx990803@gmail.com>
Sun, 22 Sep 2019 21:02:32 +0000 (17:02 -0400)
committerEvan You <yyx990803@gmail.com>
Sun, 22 Sep 2019 21:02:32 +0000 (17:02 -0400)
packages/compiler-core/src/codegen.ts
packages/compiler-core/src/transform.ts

index ed2b6f050930a63b0d649d584c755ceca33e394d..4ce9c34adc69594b2ce9295ebf9e8605f343a684 100644 (file)
@@ -287,16 +287,20 @@ function genIfBranch(
   context: CodegenContext
 ) {
   if (condition) {
+    const { push, indent, deindent, newline } = context
     // v-if or v-else-if
-    context.push(`(${condition.content})`, condition)
-    context.push(`?`)
+    push(`(${condition.content})`, condition)
+    indent()
+    push(`? `)
     genChildren(children, context)
-    context.push(`:`)
+    newline()
+    push(`: `)
     if (nextIndex < branches.length) {
       genIfBranch(branches[nextIndex], branches, nextIndex + 1, context)
     } else {
       context.push(`null`)
     }
+    deindent()
   } else {
     // v-else
     __DEV__ && assert(nextIndex === branches.length)
index 4e3fda5ec5fdd147430356b7b41881356bba50c6..f9bef475e30cb4eb9ad7b6889af79f823bad8b5e 100644 (file)
@@ -132,12 +132,13 @@ function traverseNode(
   for (let i = 0; i < nodeTransforms.length; i++) {
     const plugin = nodeTransforms[i]
     plugin(node, context)
-    if (!context.currentNode) {
-      return
-    } else {
-      // node may have been replaced
-      node = context.currentNode
-    }
+    // node may have been replaced
+    node = context.currentNode || node
+  }
+
+  if (!context.currentNode) {
+    // node was removed
+    return
   }
 
   // further traverse downwards