diff --git a/package.json b/package.json index 8971738..7e6f8ff 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ "cli": "node ./packages/core/cli/index.js", "test": "vitest --run", "lint": "eslint . --config eslint.config.mjs --cache", + "lint:fix": "eslint . --config eslint.config.mjs --fix", "check": "npm run format && npm run lint", "format": "prettier . --write", "prepare": "husky" @@ -35,11 +36,11 @@ }, "lint-staged": { "*.{js,ts,mjs,cjs,json,.*rc}": [ - "npx prettier --write", - "npx eslint --fix" + "npm run format", + "npm run lint:fix" ], "*.json": [ - "npx prettier --write" + "npm run format" ] } } diff --git a/packages/core/src/runtime/inject-fragments.mjs b/packages/core/src/runtime/inject-fragments.mjs index 901ae0d..7130031 100644 --- a/packages/core/src/runtime/inject-fragments.mjs +++ b/packages/core/src/runtime/inject-fragments.mjs @@ -65,7 +65,7 @@ function replaceSlots(fragmentNode, node) { if (n.type === ELEMENT_NODE && n.name === 'slot') { // find node child with same name attribute const currentSlotName = n.attributes?.['name'] ?? null - let nodeChildren = [] + let nodeChildren if (currentSlotName === null) { nodeChildren = node.children.filter( @@ -78,7 +78,11 @@ function replaceSlots(fragmentNode, node) { }) } - if (nodeChildren.length > 0 && !containsAll(slotted, nodeChildren)) { + if ( + nodeChildren && + nodeChildren.length > 0 && + !containsAll(slotted, nodeChildren) + ) { slotted = [...slotted, ...nodeChildren] const index = n.parent.children.indexOf(n) n.parent.children.splice(index, 1, ...nodeChildren)