@vue-macros/volar
Advanced tools
Comparing version 0.14.2 to 0.14.3
@@ -129,2 +129,9 @@ // src/jsx-directive.ts | ||
}) { | ||
if (nodes.length === 0) | ||
return; | ||
codes.push(`type __VLS_getSlots<T> = T extends new (...args: any) => any | ||
? InstanceType<T>['$slots'] | ||
: T extends (props: any, ctx: infer Ctx) => any | ||
? Ctx['slots'] | ||
: any`); | ||
nodes.forEach((node) => { | ||
@@ -217,3 +224,3 @@ if (!ts.isIdentifier(node.openingElement.tagName)) | ||
), | ||
`} as InstanceType<typeof ${node.openingElement.tagName.escapedText}>['$slots'] }` | ||
`} as __VLS_getSlots<typeof ${node.openingElement.tagName.escapedText}> }` | ||
]; | ||
@@ -233,2 +240,20 @@ if (attribute) { | ||
} | ||
function transformVModel({ | ||
nodes, | ||
codes, | ||
ts, | ||
sfc, | ||
source | ||
}) { | ||
nodes.forEach(({ attribute }) => { | ||
const start = attribute.getStart(sfc[`${source}Ast`]); | ||
let end = start + 7; | ||
let name = "modelValue"; | ||
if (ts.isJsxNamespacedName(attribute.name)) { | ||
name = attribute.name.name.getText(sfc[`${source}Ast`]); | ||
end += 1 + name.length; | ||
} | ||
(0, import_language_core2.replaceSourceRange)(codes, source, start, end, `onUpdate:${name} `, name); | ||
}); | ||
} | ||
function transformJsxDirective({ codes, sfc, ts, source }) { | ||
@@ -238,2 +263,3 @@ const vIfAttributeMap = /* @__PURE__ */ new Map(); | ||
const vSlotNodeSet = /* @__PURE__ */ new Set(); | ||
const vModelAttributes = []; | ||
function walkJsxDirective(node, parent) { | ||
@@ -243,2 +269,3 @@ const properties = ts.isJsxElement(node) ? node.openingElement.attributes.properties : ts.isJsxSelfClosingElement(node) ? node.attributes.properties : []; | ||
let vForAttribute; | ||
let vModelAttribute; | ||
for (const attribute of properties) { | ||
@@ -258,2 +285,7 @@ if (!ts.isJsxAttribute(attribute)) | ||
} | ||
if (/^v-model(_.*)?$/.test( | ||
(ts.isJsxNamespacedName(attribute.name) ? attribute.name.namespace : attribute.name).getText(sfc[`${source}Ast`]) | ||
)) { | ||
vModelAttribute = attribute; | ||
} | ||
} | ||
@@ -276,2 +308,8 @@ if (vIfAttribute) { | ||
} | ||
if (vModelAttribute) { | ||
vModelAttributes.push({ | ||
node, | ||
attribute: vModelAttribute | ||
}); | ||
} | ||
node.forEachChild((child) => { | ||
@@ -290,2 +328,3 @@ walkJsxDirective( | ||
); | ||
transformVModel({ nodes: vModelAttributes, codes, sfc, ts, source }); | ||
} | ||
@@ -300,3 +339,3 @@ var plugin = ({ modules: { typescript: ts } }) => { | ||
for (const source of ["script", "scriptSetup"]) { | ||
if (!/\sv-(if|for|slot)/.test(`${sfc[source]?.content}`)) | ||
if (!/\sv-(if|for|slot|model)/.test(`${sfc[source]?.content}`)) | ||
continue; | ||
@@ -303,0 +342,0 @@ transformJsxDirective({ |
{ | ||
"name": "@vue-macros/volar", | ||
"version": "0.14.2", | ||
"packageManager": "pnpm@8.6.12", | ||
"version": "0.14.3", | ||
"packageManager": "pnpm@8.7.4", | ||
"description": "Volar plugin for Vue Macros.", | ||
@@ -47,12 +47,12 @@ "keywords": [ | ||
"dependencies": { | ||
"@rollup/pluginutils": "^5.0.3", | ||
"@rollup/pluginutils": "^5.0.4", | ||
"@volar/language-core": "1.10.1", | ||
"@vue/language-core": "1.8.8", | ||
"@vue-macros/common": "1.7.2", | ||
"@vue-macros/define-props": "1.0.20", | ||
"@vue-macros/short-vmodel": "1.2.17" | ||
"@vue-macros/common": "1.8.0", | ||
"@vue-macros/define-props": "1.0.21", | ||
"@vue-macros/short-vmodel": "1.3.0" | ||
}, | ||
"devDependencies": { | ||
"@vue/compiler-dom": "^3.3.4", | ||
"typescript": "~5.1.6", | ||
"typescript": "~5.2.2", | ||
"vue-tsc": "1.8.8" | ||
@@ -59,0 +59,0 @@ }, |
32055
948
+ Added@vue-macros/define-props@1.0.21(transitive)
+ Added@vue-macros/short-vmodel@1.3.0(transitive)
- Removed@vue-macros/common@1.7.2(transitive)
- Removed@vue-macros/define-props@1.0.20(transitive)
- Removed@vue-macros/short-vmodel@1.2.17(transitive)
- Removedast-kit@0.10.0(transitive)
Updated@rollup/pluginutils@^5.0.4
Updated@vue-macros/common@1.8.0