@@ -13,28 +13,55 @@ export function* generateTemplateCtx(
13
13
options : ScriptCodegenOptions ,
14
14
isClassComponent : boolean
15
15
) : Generator < Code > {
16
- const exps = [ ] ;
16
+ const baseExps = [ ] ;
17
+ const extraExps = [ ] ;
18
+
17
19
if ( isClassComponent ) {
18
- exps . push ( `this` ) ;
20
+ baseExps . push ( `this` ) ;
19
21
}
20
22
else {
21
- exps . push ( `{} as InstanceType<__VLS_PickNotAny<typeof __VLS_internalComponent, new () => {}>>` ) ;
23
+ baseExps . push ( `{} as InstanceType<__VLS_PickNotAny<typeof __VLS_internalComponent, new () => {}>>` ) ;
22
24
}
23
25
if ( options . vueCompilerOptions . petiteVueExtensions . some ( ext => options . fileBaseName . endsWith ( ext ) ) ) {
24
- exps . push ( `globalThis` ) ;
26
+ extraExps . push ( `globalThis` ) ;
25
27
}
26
28
if ( options . sfc . styles . some ( style => style . module ) ) {
27
- exps . push ( `{} as __VLS_StyleModules` ) ;
29
+ extraExps . push ( `{} as __VLS_StyleModules` ) ;
30
+ }
31
+ if ( options . scriptSetupRanges ?. templateRefs . length ) {
32
+ let exp = `{} as import('${ options . vueCompilerOptions . lib } ').UnwrapRef<{${ newLine } ` ;
33
+ for ( const { name } of options . scriptSetupRanges . templateRefs ) {
34
+ if ( name ) {
35
+ exp += `${ name } : typeof ${ name } ${ newLine } ` ;
36
+ }
37
+ }
38
+ exp += `}>${ newLine } ` ;
39
+ extraExps . push ( exp ) ;
28
40
}
29
41
30
- yield `const __VLS_ctx = ` ;
31
- if ( exps . length === 1 ) {
32
- yield exps [ 0 ] ;
42
+ yield `const __VLS_ctxBase = ` ;
43
+ if ( baseExps . length === 1 ) {
44
+ yield baseExps [ 0 ] ;
33
45
yield endOfLine ;
34
46
}
35
47
else {
36
48
yield `{${ newLine } ` ;
37
- for ( const exp of exps ) {
49
+ for ( const exp of baseExps ) {
50
+ yield `...` ;
51
+ yield exp ;
52
+ yield `,${ newLine } ` ;
53
+ }
54
+ yield `}${ endOfLine } ` ;
55
+ }
56
+
57
+ yield `const __VLS_ctx = ` ;
58
+ if ( extraExps . length === 0 ) {
59
+ yield `__VLS_ctxBase${ endOfLine } ` ;
60
+ }
61
+ else {
62
+ yield `{${ newLine } ` ;
63
+ yield `...__VLS_ctxBase,${ newLine } ` ;
64
+ for ( const exp of extraExps ) {
38
65
yield `...` ;
39
66
yield exp ;
40
67
yield `,${ newLine } ` ;
@@ -76,7 +103,7 @@ export function* generateTemplateComponents(options: ScriptCodegenOptions): Gene
76
103
77
104
exps . push ( `{} as NonNullable<typeof __VLS_internalComponent extends { components: infer C } ? C : {}>` ) ;
78
105
exps . push ( `{} as __VLS_GlobalComponents` ) ;
79
- exps . push ( `{} as typeof __VLS_ctx ` ) ;
106
+ exps . push ( `__VLS_ctxBase ` ) ;
80
107
81
108
yield `const __VLS_components = {${ newLine } ` ;
82
109
for ( const type of exps ) {
0 commit comments