修复ref解析部分缺失的bug

pull/1/head 1.5.13
yutent 2023-03-23 11:50:28 +08:00
parent 9b76cfa141
commit 9641f5b82a
2 changed files with 8 additions and 8 deletions

View File

@ -1,6 +1,6 @@
{
"name": "@bd/core",
"version": "1.5.12",
"version": "1.5.13",
"type": "module",
"description": "百搭UI组件库的核心",
"main": "dist/index.js",

View File

@ -289,7 +289,7 @@ class TemplateInstance {
#checkRef(node, walker, options) {
do {
if (node?.nodeType === 1 && node?.getAttribute('ref')) {
if (node && node.nodeType === 1 && node.getAttribute('ref')) {
options.host.$refs[node.getAttribute('ref')] = node
node.removeAttribute('ref')
}
@ -316,6 +316,12 @@ class TemplateInstance {
this.#checkRef(node, walker, options)
} else {
while (templatePart !== void 0) {
if (node.nodeType === 1 && node.getAttribute('ref')) {
if (options.host.$refs) {
options.host.$refs[node.getAttribute('ref')] = node
node.removeAttribute('ref')
}
}
if (nodeIndex === templatePart.index) {
let part
if (templatePart.type === CHILD_PART) {
@ -331,12 +337,6 @@ class TemplateInstance {
} else if (templatePart.type === ELEMENT_PART) {
part = new ElementPart(node, this, options)
}
if (node.nodeType === 1 && node.getAttribute('ref')) {
if (options.host.$refs) {
options.host.$refs[node.getAttribute('ref')] = node
node.removeAttribute('ref')
}
}
this._parts.push(part)
templatePart = parts[++partIndex]
}