diff --git a/packages/language-core/lib/codegen/script/template.ts b/packages/language-core/lib/codegen/script/template.ts index 982e37a909..37ae7e1b07 100644 --- a/packages/language-core/lib/codegen/script/template.ts +++ b/packages/language-core/lib/codegen/script/template.ts @@ -162,7 +162,7 @@ function* generateStyleScopedClasses( ctx: TemplateCodegenContext ): Generator { const firstClasses = new Set(); - yield `type __VLS_StyleScopedClasses = {}`; + yield `let __VLS_styleScopedClasses!: {}`; for (let i = 0; i < options.sfc.styles.length; i++) { const style = options.sfc.styles[i]; const option = options.vueCompilerOptions.experimentalResolveStyleCssClasses; diff --git a/packages/language-core/lib/codegen/template/styleScopedClasses.ts b/packages/language-core/lib/codegen/template/styleScopedClasses.ts index d7f8cb5bd8..d360c3a606 100644 --- a/packages/language-core/lib/codegen/template/styleScopedClasses.ts +++ b/packages/language-core/lib/codegen/template/styleScopedClasses.ts @@ -1,27 +1,23 @@ import type { Code } from '../../types'; -import { endOfLine } from '../utils'; +import { endOfLine, newLine } from '../utils'; import type { TemplateCodegenContext } from './context'; export function* generateStyleScopedClassReferences( ctx: TemplateCodegenContext, withDot = false ): Generator { - if (!ctx.emptyClassOffsets.length && !ctx.scopedClasses.length) { - return; - } - - yield `[`; for (const offset of ctx.emptyClassOffsets) { - yield `'`; + yield `__VLS_styleScopedClasses['`; yield [ '', 'template', offset, ctx.codeFeatures.additionalCompletion, ]; - yield `', `; + yield `']${endOfLine}`; } for (const { source, className, offset } of ctx.scopedClasses) { + yield `__VLS_styleScopedClasses[`; yield [ '', source, @@ -39,9 +35,9 @@ export function* generateStyleScopedClassReferences( offset + className.length, ctx.codeFeatures.navigationWithoutRename, ]; - yield `, `; + yield `]${endOfLine}`; } - yield `] as (keyof __VLS_StyleScopedClasses)[]${endOfLine}`; + yield newLine; function* escapeString(source: string, className: string, offset: number, escapeTargets: string[]): Generator { let count = 0;