Skip to content

Commit

Permalink
fix(language-core): generate correct reference for v-on on <slot> (
Browse files Browse the repository at this point in the history
  • Loading branch information
KazariEX authored Oct 24, 2024
1 parent 564aa84 commit c6a4e36
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
9 changes: 4 additions & 5 deletions packages/language-core/lib/codegen/template/elementProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ export function* generateElementProps(
suffix: string;
}[]
): Generator<Code> {
const isIntrinsicElement = node.tagType === CompilerDOM.ElementTypes.ELEMENT || node.tagType === CompilerDOM.ElementTypes.TEMPLATE;
const canCamelize = node.tagType === CompilerDOM.ElementTypes.COMPONENT;
const isComponent = node.tagType === CompilerDOM.ElementTypes.COMPONENT;

for (const prop of props) {
if (
Expand All @@ -38,7 +37,7 @@ export function* generateElementProps(
&& !prop.arg.loc.source.startsWith('[')
&& !prop.arg.loc.source.endsWith(']')
) {
if (isIntrinsicElement) {
if (!isComponent) {
yield `...{ `;
yield* generateEventArg(ctx, prop.arg, true);
yield `: `;
Expand Down Expand Up @@ -102,7 +101,7 @@ export function* generateElementProps(
}

const shouldSpread = propName === 'style' || propName === 'class';
const shouldCamelize = canCamelize
const shouldCamelize = isComponent
&& (!prop.arg || (prop.arg.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION && prop.arg.isStatic)) // isStatic
&& hyphenateAttr(propName) === propName
&& !options.vueCompilerOptions.htmlAttributes.some(pattern => minimatch(propName, pattern));
Expand Down Expand Up @@ -190,7 +189,7 @@ export function* generateElementProps(
}

const shouldSpread = prop.name === 'style' || prop.name === 'class';
const shouldCamelize = canCamelize
const shouldCamelize = isComponent
&& hyphenateAttr(prop.name) === prop.name
&& !options.vueCompilerOptions.htmlAttributes.some(pattern => minimatch(prop.name, pattern));

Expand Down
7 changes: 7 additions & 0 deletions test-workspace/tsc/passedFixtures/vue3/#4862/main.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<script setup lang="ts">
const bar = () => {}
</script>

<template>
<slot @bar="bar"></slot>
</template>

0 comments on commit c6a4e36

Please sign in to comment.