From 892e4de626b2353cac5ba0f6ed9f1760f6c1ef5f Mon Sep 17 00:00:00 2001 From: _Kerman Date: Fri, 2 Aug 2024 20:41:16 +0800 Subject: [PATCH] fix(language-core): semantic highlight of the end tag of namespaced elements (#4623) --- .../lib/codegen/template/element.ts | 28 +++++++++++++++---- .../language-service/syntax/namespaced.vue | 25 +++++++++++++++++ 2 files changed, 47 insertions(+), 6 deletions(-) create mode 100644 test-workspace/language-service/syntax/namespaced.vue diff --git a/packages/language-core/lib/codegen/template/element.ts b/packages/language-core/lib/codegen/template/element.ts index e7e7e5e450..a7a55b479f 100644 --- a/packages/language-core/lib/codegen/template/element.ts +++ b/packages/language-core/lib/codegen/template/element.ts @@ -47,7 +47,7 @@ export function* generateComponent( let props = node.props; let dynamicTagInfo: { exp: string; - offset: number; + offsets: [number, number | undefined]; astHolder: any; } | undefined; @@ -56,7 +56,7 @@ export function* generateComponent( if (prop.type === CompilerDOM.NodeTypes.DIRECTIVE && prop.name === 'bind' && prop.arg?.loc.source === 'is' && prop.exp) { dynamicTagInfo = { exp: prop.exp.loc.source, - offset: prop.exp.loc.start.offset, + offsets: [prop.exp.loc.start.offset, undefined], astHolder: prop.exp.loc, }; props = props.filter(p => p !== prop); @@ -69,7 +69,7 @@ export function* generateComponent( dynamicTagInfo = { exp: node.tag, astHolder: node.loc, - offset: startTagOffset, + offsets: [startTagOffset, endTagOffset], }; } @@ -104,18 +104,34 @@ export function* generateComponent( yield `]${endOfLine}`; } else if (dynamicTagInfo) { - yield `const ${var_originalComponent} = `; + yield `const ${var_originalComponent} = (`; yield* generateInterpolation( options, ctx, dynamicTagInfo.exp, dynamicTagInfo.astHolder, - dynamicTagInfo.offset, + dynamicTagInfo.offsets[0], ctx.codeFeatures.all, '(', ')' ); - yield endOfLine; + if (dynamicTagInfo.offsets[1] !== undefined) { + yield `,`; + yield* generateInterpolation( + options, + ctx, + dynamicTagInfo.exp, + dynamicTagInfo.astHolder, + dynamicTagInfo.offsets[1], + { + ...ctx.codeFeatures.all, + completion: false, + }, + '(', + ')' + ); + } + yield `)${endOfLine}`; } else if (!isComponentTag) { yield `// @ts-ignore${newLine}`; diff --git a/test-workspace/language-service/syntax/namespaced.vue b/test-workspace/language-service/syntax/namespaced.vue new file mode 100644 index 0000000000..2ea20ed432 --- /dev/null +++ b/test-workspace/language-service/syntax/namespaced.vue @@ -0,0 +1,25 @@ + + +