@@ -3,7 +3,6 @@ import type * as ts from 'typescript';
33import type { Code , Sfc , VueCompilerOptions } from '../../types' ;
44import { getSlotsPropertyName } from '../../utils/shared' ;
55import { endOfLine , newLine , wrapWith } from '../utils' ;
6- import { generateStringLiteralKey } from '../utils/stringLiteralKey' ;
76import { TemplateCodegenContext , createTemplateCodegenContext } from './context' ;
87import { generateObjectProperty } from './objectProperty' ;
98import { generateStyleScopedClassReferences } from './styleScopedClasses' ;
@@ -49,7 +48,7 @@ export function* generateTemplate(options: TemplateCodegenOptions): Generator<Co
4948 const speicalTypes = [
5049 [ slotsPropertyName , yield * generateSlots ( options , ctx ) ] ,
5150 [ '$attrs' , yield * generateInheritedAttrs ( options , ctx ) ] ,
52- [ '$refs' , yield * generateRefs ( ctx ) ] ,
51+ [ '$refs' , yield * generateTemplateRefs ( options , ctx ) ] ,
5352 [ '$el' , yield * generateRootEl ( ctx ) ]
5453 ] ;
5554
@@ -67,9 +66,9 @@ function* generateSlots(
6766 options : TemplateCodegenOptions ,
6867 ctx : TemplateCodegenContext
6968) : Generator < Code > {
70- const name = getSlotsPropertyName ( options . vueCompilerOptions . target ) ;
7169 if ( ! options . hasDefineSlots ) {
72- yield `var __VLS_slots!: __VLS_PrettifyGlobal<__VLS_OmitStringIndex<typeof __VLS_ctx.${ name } >` ;
70+ const name = getSlotsPropertyName ( options . vueCompilerOptions . target ) ;
71+ yield `type __VLS_Slots = __VLS_PrettifyGlobal<__VLS_OmitStringIndex<typeof __VLS_ctx.${ name } >` ;
7372 for ( const { expVar, propsVar } of ctx . dynamicSlots ) {
7473 ctx . hasSlot = true ;
7574 yield `${ newLine } & { [K in NonNullable<typeof ${ expVar } >]?: (props: typeof ${ propsVar } ) => any }` ;
@@ -99,14 +98,14 @@ function* generateSlots(
9998 }
10099 yield `>${ endOfLine } ` ;
101100 }
102- return `typeof ${ options . slotsAssignName ?? `__VLS_slots` } ` ;
101+ return `__VLS_Slots ` ;
103102}
104103
105104function * generateInheritedAttrs (
106105 options : TemplateCodegenOptions ,
107106 ctx : TemplateCodegenContext
108107) : Generator < Code > {
109- yield 'let __VLS_inheritedAttrs!: {}' ;
108+ yield `type __VLS_InheritedAttrs = {}` ;
110109 for ( const varName of ctx . inheritedAttrVars ) {
111110 yield ` & typeof ${ varName } ` ;
112111 }
@@ -126,32 +125,35 @@ function* generateInheritedAttrs(
126125 }
127126 yield `]${ endOfLine } ` ;
128127 }
129- return `import('${ options . vueCompilerOptions . lib } ').ComponentPublicInstance['$attrs'] & Partial<typeof __VLS_inheritedAttrs >` ;
128+ return `import('${ options . vueCompilerOptions . lib } ').ComponentPublicInstance['$attrs'] & Partial<__VLS_InheritedAttrs >` ;
130129}
131130
132- function * generateRefs (
131+ function * generateTemplateRefs (
132+ options : TemplateCodegenOptions ,
133133 ctx : TemplateCodegenContext
134134) : Generator < Code > {
135- yield `const __VLS_refs = {${ newLine } ` ;
135+ yield `type __VLS_TemplateRefs = {${ newLine } ` ;
136136 for ( const [ name , [ varName , offset ] ] of ctx . templateRefs ) {
137- yield * generateStringLiteralKey (
137+ yield * generateObjectProperty (
138+ options ,
139+ ctx ,
138140 name ,
139141 offset ,
140142 ctx . codeFeatures . navigationAndCompletion
141143 ) ;
142- yield `: ${ varName } ,${ newLine } ` ;
144+ yield `: typeof ${ varName } ,${ newLine } ` ;
143145 }
144146 yield `}${ endOfLine } ` ;
145- return `typeof __VLS_refs ` ;
147+ return `__VLS_TemplateRefs ` ;
146148}
147149
148150function * generateRootEl (
149151 ctx : TemplateCodegenContext
150152) : Generator < Code > {
151- yield `let __VLS_rootEl!: ` ;
153+ yield `type __VLS_RootEl = ` ;
152154 yield ctx . singleRootElType ?? `any` ;
153155 yield endOfLine ;
154- return `typeof __VLS_rootEl ` ;
156+ return `__VLS_RootEl ` ;
155157}
156158
157159export function * forEachElementNode ( node : CompilerDOM . RootNode | CompilerDOM . TemplateChildNode ) : Generator < CompilerDOM . ElementNode > {
0 commit comments