From b68b34e38b067a3ee99b91d5028dafd6d17f9e33 Mon Sep 17 00:00:00 2001 From: uee chart bot Date: Mon, 29 Jul 2024 23:52:56 +0800 Subject: [PATCH] fix(language-core): escape \ and ' in className avoid type error --- .../lib/codegen/template/index.ts | 50 ++++++++++++++++--- 1 file changed, 44 insertions(+), 6 deletions(-) diff --git a/packages/language-core/lib/codegen/template/index.ts b/packages/language-core/lib/codegen/template/index.ts index 1dc04b2076..32473d8774 100644 --- a/packages/language-core/lib/codegen/template/index.ts +++ b/packages/language-core/lib/codegen/template/index.ts @@ -78,6 +78,47 @@ 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; + } + } + } + function* generateStyleScopedClasses(): Generator { yield `if (typeof __VLS_styleScopedClasses === 'object' && !Array.isArray(__VLS_styleScopedClasses)) {${newLine}`; for (const offset of ctx.emptyClassOffsets) { @@ -99,12 +140,9 @@ export function* generateTemplate(options: TemplateCodegenOptions): Generator