From: 三咲智子 Kevin Deng Date: Mon, 29 Jan 2024 21:35:28 +0000 (+0800) Subject: refactor(runtime-vapor): throw errors when node is not found X-Git-Tag: v3.6.0-alpha.1~16^2~634 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=74f7e56fb8a0b244fcfd578e85596d762221548e;p=thirdparty%2Fvuejs%2Fcore.git refactor(runtime-vapor): throw errors when node is not found --- diff --git a/packages/runtime-vapor/src/dom.ts b/packages/runtime-vapor/src/dom.ts index 82de1efb3a..c8bb7f42f4 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)) }