From 86e38db1a531b1cce24814da4a5c42aef75d987b Mon Sep 17 00:00:00 2001 From: Johnson Chu Date: Thu, 16 May 2024 09:58:23 +0800 Subject: [PATCH] fix(language-core): avoid report when events do not accept parameters close #4387 --- .../lib/codegen/template/elementEvents.ts | 5 ++--- test-workspace/tsc/vue3/#4387/component.vue | 3 +++ test-workspace/tsc/vue3/#4387/main.vue | 11 +++++++++++ 3 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 test-workspace/tsc/vue3/#4387/component.vue create mode 100644 test-workspace/tsc/vue3/#4387/main.vue diff --git a/packages/language-core/lib/codegen/template/elementEvents.ts b/packages/language-core/lib/codegen/template/elementEvents.ts index 078a45b9df..5f20ade8d9 100644 --- a/packages/language-core/lib/codegen/template/elementEvents.ts +++ b/packages/language-core/lib/codegen/template/elementEvents.ts @@ -77,7 +77,7 @@ export function* generateElementEvents( prop.exp.loc, prop.exp.loc.start.offset, ctx.codeFeatures.all, - '$event => {(', + '[...[$event]] => {(', ')}', ); yield endOfLine; @@ -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 = ''; diff --git a/test-workspace/tsc/vue3/#4387/component.vue b/test-workspace/tsc/vue3/#4387/component.vue new file mode 100644 index 0000000000..5e340fcaa1 --- /dev/null +++ b/test-workspace/tsc/vue3/#4387/component.vue @@ -0,0 +1,3 @@ + diff --git a/test-workspace/tsc/vue3/#4387/main.vue b/test-workspace/tsc/vue3/#4387/main.vue new file mode 100644 index 0000000000..834a97c387 --- /dev/null +++ b/test-workspace/tsc/vue3/#4387/main.vue @@ -0,0 +1,11 @@ + + +