From 315c17d05fb5e49e76f6243e81760f45ac778f97 Mon Sep 17 00:00:00 2001 From: anyesu Date: Mon, 15 Apr 2024 09:38:15 +0800 Subject: [PATCH] fix: warning `is not a valid value for v-model` in JetBrains IDE (#3029) --- scripts/createAttributes.cjs | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/scripts/createAttributes.cjs b/scripts/createAttributes.cjs index 4a2fa76d7a..e17fde77ee 100644 --- a/scripts/createAttributes.cjs +++ b/scripts/createAttributes.cjs @@ -67,6 +67,7 @@ const genaratorWebTypes = () => { absolutePath = path.join(`${basePath}/${componentDir}`, `doc.taro.md`) } let attributes = [] + const events = [] if (!fs.existsSync(absolutePath)) continue const data = fs.readFileSync(absolutePath, 'utf8') let sources = MarkdownIt.parse(data, {}) @@ -79,7 +80,7 @@ const genaratorWebTypes = () => { const infoItem = inlineItem.length ? `${inlineItem[1]?.content}` : '' const typeItem = inlineItem.length ? `${inlineItem[2]?.content?.toLowerCase()}` : '' const defaultItem = inlineItem.length ? `${inlineItem[3]?.content}` : '' - attributes.push({ + const attribute = { name: propItem, default: defaultItem, description: infoItem, @@ -87,13 +88,34 @@ const genaratorWebTypes = () => { type: typeItem, kind: 'expression' } - }) + } + if (propItem === 'v-model') { + const modelValue = 'modelValue' + // add `modelValue` + attributes.push({ ...attribute, name: modelValue }) + if (typeItem === 'boolean') { + // fix: warning `is not a valid value for v-model` in JetBrains IDE + // ref: https://github.com/JetBrains/web-types/issues/79#issuecomment-2045153333 + attribute.value = { ...attribute.value, type: typeItem + ' ' } + } + events.push({ + name: `update:${modelValue}`, + description: `${infoItem}\n\nEmitted when the value of \`${modelValue}\` prop changes.`, + arguments: [ + { + name: modelValue, + type: typeItem + } + ] + }) + } + attributes.push(attribute) } let compoName = kebabCase(getCompName(componentDir)) typesData.contributions.html.tags.push({ name: `nut-${compoName}`, slots: [], - events: [], + events, attributes: attributes.slice() }) }