diff --git a/packages/language-core/lib/plugins/vue-template-inline-ts.ts b/packages/language-core/lib/plugins/vue-template-inline-ts.ts index 0501f8884e..e8680686fb 100644 --- a/packages/language-core/lib/plugins/vue-template-inline-ts.ts +++ b/packages/language-core/lib/plugins/vue-template-inline-ts.ts @@ -93,14 +93,23 @@ const plugin: VueLanguagePlugin = ctx => { && prop.exp.constType !== CompilerDOM.ConstantTypes.CAN_STRINGIFY // style='z-index: 2' will compile to {'z-index':'2'} ) { if (prop.name === 'on') { - const ast = createTsAst(ctx.modules.typescript, prop.exp, prop.exp.content); - addFormatCodes( - prop.exp.content, - prop.exp.loc.start.offset, - isCompoundExpression(ctx.modules.typescript, ast) - ? formatBrackets.event - : formatBrackets.normal, - ); + if (prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) { + const ast = createTsAst(ctx.modules.typescript, prop.exp, prop.exp.content); + addFormatCodes( + prop.exp.content, + prop.exp.loc.start.offset, + isCompoundExpression(ctx.modules.typescript, ast) + ? formatBrackets.event + : formatBrackets.normal, + ); + } + else { + addFormatCodes( + prop.exp.content, + prop.exp.loc.start.offset, + formatBrackets.normal, + ); + } } else { addFormatCodes( diff --git a/packages/language-service/tests/format/4333.spec.ts b/packages/language-service/tests/format/4333.spec.ts new file mode 100644 index 0000000000..03b8a21eb1 --- /dev/null +++ b/packages/language-service/tests/format/4333.spec.ts @@ -0,0 +1,14 @@ +import { defineFormatTest } from '../utils/format'; + +defineFormatTest({ + title: '#' + __filename.split('.')[0], + languageId: 'vue', + input: ` + + `.trim(), + settings: { + 'typescript.format.semicolons': 'insert', + } +});