8000 fix(volar/jsx-directive): prevent missing types when v-slots are used with v-for by zhiyuanzmj · Pull Request #932 · vue-macros/vue-macros · GitHub
[go: up one dir, main page]

Skip to content

fix(volar/jsx-directive): prevent missing types when v-slots are used with v-for #932

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix(volar/jsx-directive): prevent missing types when v-slots are used…
… with v-for
  • Loading branch information
zhiyuanzmj committed Mar 13, 2025
commit ff0f2b0bb0eb9af2fd60754ed071ca3a9b73df3b
5 changes: 4 additions & 1 deletion packages/volar/src/jsx-directive/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ export function transformJsxDirective(options: TransformOptions): void {

const ctxNodeMap: CtxMap = new Map()

let hasVForAttribute = false

function walkJsxDirective(
node: import('typescript').Node,
parent?: import('typescript').Node,
Expand All @@ -74,6 +76,7 @@ export function transformJsxDirective(options: TransformOptions): void {
vIfAttribute = attribute
} else if (attributeName === `${prefix}for`) {
vForAttribute = attribute
hasVForAttribute = true
} else if (slotRegex.test(attributeName)) {
vSlotAttribute = attribute
} else if (modelRegex.test(attributeName)) {
Expand Down Expand Up @@ -217,7 +220,7 @@ export function transformJsxDirective(options: TransformOptions): void {
const ctxMap = resolveCtxMap(ctxNodeMap, options)

transformVSlot(vSlotMap, ctxMap, options)
transformVFor(vForNodes, options)
transformVFor(vForNodes, options, hasVForAttribute)
vIfMap.forEach((nodes) => transformVIf(nodes, options))
transformVModel(vModelMap, ctxMap, options)
transformVOn(vOnNodes, ctxMap, options)
Expand Down
3 changes: 2 additions & 1 deletion packages/volar/src/jsx-directive/v-for.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,9 @@ export function resolveVFor(
export function transformVFor(
nodes: JsxDirective[],
options: TransformOptions,
hasVForAttribute: boolean,
): void {
if (!nodes.length) return
if (!nodes.length && !hasVForAttribute) return
const { codes, source } = options

nodes.forEach(({ attribute, node, parent }) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/volar/src/jsx-directive/v-slot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export function transformVSlot(
)

if (vForAttribute) {
result.push('})),')
result.push('})) as any,')
}

if (vIfAttribute && vIfAttributeName) {
Expand Down
0