]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
refactor(runtime-vapor): throw errors when node is not found
author三咲智子 Kevin Deng <sxzz@sxzz.moe>
Mon, 29 Jan 2024 21:35:28 +0000 (05:35 +0800)
committer三咲智子 Kevin Deng <sxzz@sxzz.moe>
Mon, 29 Jan 2024 21:39:53 +0000 (05:39 +0800)
packages/runtime-vapor/src/dom.ts

index 82de1efb3adad2cc1b237e8c434254cc563156fe..c8bb7f42f4eb0fc6ab6bfb90d6d6c5407e739e63 100644 (file)
@@ -28,6 +28,7 @@ export function insert(
     if (index > -1) {
       parent.splice(index, 0, block)
     } else {
+      if (anchor) throw new Error('The child can not be found in the parent.')
       parent.push(block)
     }
   } else {
@@ -54,9 +55,9 @@ export function append(parent: ParentBlock, ...blocks: Block[]) {
 export function remove(block: Block, parent: ParentBlock) {
   if (isArray(parent)) {
     const index = parent.indexOf(block)
-    if (index > -1) {
-      parent.splice(index, 1)
-    }
+    if (index === -1)
+      throw Error('The node to be removed is not a child of this node.')
+    parent.splice(index, 1)
   } else {
     normalizeBlock(block).forEach(node => parent.removeChild(node))
   }