From 74f7e56fb8a0b244fcfd578e85596d762221548e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=92=B2=E6=99=BA=E5=AD=90=20Kevin=20Deng?= Date: Tue, 30 Jan 2024 05:35:28 +0800 Subject: [PATCH] refactor(runtime-vapor): throw errors when node is not found --- packages/runtime-vapor/src/dom.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/runtime-vapor/src/dom.ts b/packages/runtime-vapor/src/dom.ts index 82de1efb3..c8bb7f42f 100644 --- a/packages/runtime-vapor/src/dom.ts +++ b/packages/runtime-vapor/src/dom.ts @@ -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)) }