refactor(runtime-vapor): throw errors when node is not found

This commit is contained in:
三咲智子 Kevin Deng 2024-01-30 05:35:28 +08:00
parent cd0e3273d2
commit 74f7e56fb8
No known key found for this signature in database
GPG Key ID: 69992F2250DFD93E
1 changed files with 4 additions and 3 deletions

View 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) {
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))
}