Skip to content

Commit

Permalink
fix(language-core): avoid report when events do not accept parameters
Browse files Browse the repository at this point in the history
close #4387
  • Loading branch information
johnsoncodehk committed May 16, 2024
1 parent 4e31ab8 commit 86e38db
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
5 changes: 2 additions & 3 deletions packages/language-core/lib/codegen/template/elementEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export function* generateElementEvents(
prop.exp.loc,
prop.exp.loc.start.offset,
ctx.codeFeatures.all,
'$event => {(',
'[...[$event]] => {(',
')}',
);
yield endOfLine;
Expand Down Expand Up @@ -154,8 +154,7 @@ export function* generateEventExpression(
const ast = createTsAst(options.ts, prop.exp, prop.exp.content);
const _isCompoundExpression = isCompoundExpression(options.ts, ast);
if (_isCompoundExpression) {

yield `$event => {${newLine}`;
yield `(...[$event]) => {${newLine}`;
ctx.addLocalVariable('$event');

prefix = '';
Expand Down
3 changes: 3 additions & 0 deletions test-workspace/tsc/vue3/#4387/component.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<script lang="ts" setup>
defineEmits<(e: 'submit') => void>();
</script>
11 changes: 11 additions & 0 deletions test-workspace/tsc/vue3/#4387/main.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<template>
<HelloWorld @submit="handler()" />
</template>

<script lang="ts" setup>
import HelloWorld from './component.vue';
const handler = () => {
console.log('submit');
};
</script>

0 comments on commit 86e38db

Please sign in to comment.