@@ -13,8 +13,8 @@ export function* generateTemplate(
1313) : Generator < Code > {
1414 yield * generateSetupExposed ( options , ctx ) ;
1515 yield * generateTemplateCtx ( options , ctx , selfType ) ;
16- yield * generateTemplateComponents ( options ) ;
17- yield * generateTemplateDirectives ( options ) ;
16+ yield * generateTemplateComponents ( options , ctx ) ;
17+ yield * generateTemplateDirectives ( options , ctx ) ;
1818
1919 if ( options . styleCodegen ) {
2020 yield * options . styleCodegen . codes ;
@@ -82,14 +82,20 @@ function* generateTemplateCtx(
8282 yield endOfLine ;
8383}
8484
85- function * generateTemplateComponents ( options : ScriptCodegenOptions ) : Generator < Code > {
86- const types : string [ ] = [ `typeof ${ names . ctx } ` ] ;
85+ function * generateTemplateComponents (
86+ { script, scriptRanges } : ScriptCodegenOptions ,
87+ ctx : ScriptCodegenContext ,
88+ ) : Generator < Code > {
89+ const types : string [ ] = [ ] ;
8790
88- if ( options . script && options . scriptRanges ?. componentOptions ?. components ) {
89- const { components } = options . scriptRanges . componentOptions ;
91+ if ( ctx . generatedTypes . has ( names . SetupExposed ) ) {
92+ types . push ( names . SetupExposed ) ;
93+ }
94+ if ( script && scriptRanges ?. componentOptions ?. components ) {
95+ const { components } = scriptRanges . componentOptions ;
9096 yield `const __VLS_componentsOption = ` ;
9197 yield * generateSfcBlockSection (
92- options . script ,
98+ script ,
9399 components . start ,
94100 components . end ,
95101 codeFeatures . navigation ,
@@ -98,18 +104,24 @@ function* generateTemplateComponents(options: ScriptCodegenOptions): Generator<C
98104 types . push ( `typeof __VLS_componentsOption` ) ;
99105 }
100106
101- yield `type __VLS_LocalComponents = ${ types . join ( ` & ` ) } ${ endOfLine } ` ;
107+ yield `type __VLS_LocalComponents = ${ types . length ? types . join ( ` & ` ) : `{}` } ${ endOfLine } ` ;
102108 yield `let ${ names . components } !: __VLS_LocalComponents & __VLS_GlobalComponents${ endOfLine } ` ;
103109}
104110
105- function * generateTemplateDirectives ( options : ScriptCodegenOptions ) : Generator < Code > {
106- const types : string [ ] = [ `typeof ${ names . ctx } ` ] ;
111+ function * generateTemplateDirectives (
112+ { script, scriptRanges } : ScriptCodegenOptions ,
113+ ctx : ScriptCodegenContext ,
114+ ) : Generator < Code > {
115+ const types : string [ ] = [ ] ;
107116
108- if ( options . script && options . scriptRanges ?. componentOptions ?. directives ) {
109- const { directives } = options . scriptRanges . componentOptions ;
117+ if ( ctx . generatedTypes . has ( names . SetupExposed ) ) {
118+ types . push ( names . SetupExposed ) ;
119+ }
120+ if ( script && scriptRanges ?. componentOptions ?. directives ) {
121+ const { directives } = scriptRanges . componentOptions ;
110122 yield `const __VLS_directivesOption = ` ;
111123 yield * generateSfcBlockSection (
112- options . script ,
124+ script ,
113125 directives . start ,
114126 directives . end ,
115127 codeFeatures . navigation ,
@@ -118,7 +130,7 @@ function* generateTemplateDirectives(options: ScriptCodegenOptions): Generator<C
118130 types . push ( `__VLS_ResolveDirectives<typeof __VLS_directivesOption>` ) ;
119131 }
120132
121- yield `type __VLS_LocalDirectives = ${ types . join ( ` & ` ) } ${ endOfLine } ` ;
133+ yield `type __VLS_LocalDirectives = ${ types . length ? types . join ( ` & ` ) : `{}` } ${ endOfLine } ` ;
122134 yield `let ${ names . directives } !: __VLS_LocalDirectives & __VLS_GlobalDirectives${ endOfLine } ` ;
123135}
124136
0 commit comments