diff --git a/packages/language-core/lib/codegen/template/index.ts b/packages/language-core/lib/codegen/template/index.ts index 1dc04b2076..c78716c3b3 100644 --- a/packages/language-core/lib/codegen/template/index.ts +++ b/packages/language-core/lib/codegen/template/index.ts @@ -99,12 +99,9 @@ export function* generateTemplate(options: TemplateCodegenOptions): Generator { + let count = 0; + + const currentEscapeTargets = [...escapeTargets]; + const firstEscapeTarget = currentEscapeTargets.shift()!; + const splitted = className.split(firstEscapeTarget); + + for (let i = 0; i < splitted.length; i++) { + const part = splitted[i]; + const partLength = part.length; + + if (escapeTargets.length > 0) { + yield* escapeString(part, offset + count, [...currentEscapeTargets]); + } else { + yield [ + part, + 'template', + offset + count, + ctx.codeFeatures.navigationAndAdditionalCompletion, + ]; + } + + if (i !== splitted.length - 1) { + yield '\\'; + + yield [ + firstEscapeTarget, + 'template', + offset + count + partLength, + ctx.codeFeatures.navigationAndAdditionalCompletion, + ]; + + count += partLength + 1; + } else { + count += partLength; + } + } + } } export function* forEachElementNode(node: CompilerDOM.RootNode | CompilerDOM.TemplateChildNode): Generator { diff --git a/test-workspace/tsc/vue3/#4537/main.vue b/test-workspace/tsc/vue3/#4537/main.vue new file mode 100644 index 0000000000..2dbb097a3c --- /dev/null +++ b/test-workspace/tsc/vue3/#4537/main.vue @@ -0,0 +1,17 @@ + + + + +