@@ -27,15 +27,16 @@ export function generate(
27
27
cssModuleClasses : ReturnType < typeof collectStyleCssClasses > ,
28
28
cssScopedClasses : ReturnType < typeof collectStyleCssClasses > ,
29
29
htmlGen : ReturnType < typeof templateGen [ 'generate' ] > | undefined ,
30
- compilerOptions : VueCompilerOptions ,
30
+ compilerOptions : ts . CompilerOptions ,
31
+ vueCompilerOptions : VueCompilerOptions ,
31
32
codeGen = new CodeGen < EmbeddedFileMappingData > ( ) ,
32
33
teleports : SourceMaps . Mapping < TeleportMappingData > [ ] = [ ] ,
33
34
) {
34
35
35
- const downgradePropsAndEmitsToSetupReturnOnScriptSetup = compilerOptions . experimentalDowngradePropsAndEmitsToSetupReturnOnScriptSetup === 'onlyJs'
36
+ const downgradePropsAndEmitsToSetupReturnOnScriptSetup = vueCompilerOptions . experimentalDowngradePropsAndEmitsToSetupReturnOnScriptSetup === 'onlyJs'
36
37
? lang === 'js' || lang === 'jsx'
37
- : ! ! compilerOptions . experimentalDowngradePropsAndEmitsToSetupReturnOnScriptSetup ;
38
- const vueVersion = compilerOptions . target ?? 3 ;
38
+ : ! ! vueCompilerOptions . experimentalDowngradePropsAndEmitsToSetupReturnOnScriptSetup ;
39
+ const vueVersion = vueCompilerOptions . target ?? 3 ;
39
40
const vueLibName = getVueLibraryName ( vueVersion ) ;
40
41
const usedTypes = {
41
42
DefinePropsToOptions : false ,
@@ -131,8 +132,13 @@ export function generate(
131
132
132
133
function writeScriptSetupTypes ( ) {
133
134
if ( usedTypes . DefinePropsToOptions ) {
134
- codeGen . addText ( `type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;\n` ) ;
135
- codeGen . addText ( `type __VLS_TypePropsToRuntimeProps<T> = { [K in keyof T]-?: {} extends Pick<T, K> ? { type: import('${ vueLibName } ').PropType<__VLS_NonUndefinedable<T[K]>> } : { type: import('${ vueLibName } ').PropType<T[K]>, required: true } };\n` ) ;
135
+ if ( compilerOptions . exactOptionalPropertyTypes ) {
136
+ codeGen . addText ( `type __VLS_TypePropsToRuntimeProps<T> = { [K in keyof T]-?: {} extends Pick<T, K> ? { type: import('${ vueLibName } ').PropType<T[K]> } : { type: import('${ vueLibName } ').PropType<T[K]>, required: true } };\n` ) ;
137
+ }
138
+ else {
139
+ codeGen . addText ( `type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;\n` ) ;
140
+ codeGen . addText ( `type __VLS_TypePropsToRuntimeProps<T> = { [K in keyof T]-?: {} extends Pick<T, K> ? { type: import('${ vueLibName } ').PropType<__VLS_NonUndefinedable<T[K]>> } : { type: import('${ vueLibName } ').PropType<T[K]>, required: true } };\n` ) ;
141
+ }
136
142
}
137
143
if ( usedTypes . mergePropDefaults ) {
138
144
codeGen . addText ( `type __VLS_WithDefaults<P, D> = {
@@ -628,7 +634,7 @@ export function generate(
628
634
/* Components */
629
635
codeGen . addText ( '/* Components */\n' ) ;
630
636
codeGen . addText ( 'let __VLS_otherComponents!: NonNullable<typeof __VLS_component extends { components: infer C } ? C : {}> & __VLS_types.GlobalComponents & typeof __VLS_vmUnwrap.components & __VLS_types.PickComponents<typeof __VLS_ctx>;\n' ) ;
631
- codeGen . addText ( `let __VLS_selfComponent!: __VLS_types.SelfComponent<typeof __VLS_name, typeof __VLS_component & (new () => { ${ getSlotsPropertyName ( compilerOptions . target ?? 3 ) } : typeof __VLS_slots })>;\n` ) ;
637
+ codeGen . addText ( `let __VLS_selfComponent!: __VLS_types.SelfComponent<typeof __VLS_name, typeof __VLS_component & (new () => { ${ getSlotsPropertyName ( vueCompilerOptions . target ?? 3 ) } : typeof __VLS_slots })>;\n` ) ;
632
638
codeGen . addText ( 'let __VLS_components!: typeof __VLS_otherComponents & Omit<typeof __VLS_selfComponent, keyof typeof __VLS_otherComponents>;\n' ) ;
633
639
634
640
codeGen . addText ( `__VLS_components['${ SearchTexts . Components } '];\n` ) ;
@@ -785,25 +791,25 @@ export function generate(
785
791
let shimComponentOptionsMode : 'defineComponent' | 'Vue.extend' | false = false ;
786
792
787
793
if (
788
- compilerOptions . experimentalImplicitWrapComponentOptionsWithVue2Extend === 'onlyJs'
794
+ vueCompilerOptions . experimentalImplicitWrapComponentOptionsWithVue2Extend === 'onlyJs'
789
795
? lang === 'js' || lang === 'jsx'
790
- : ! ! compilerOptions . experimentalImplicitWrapComponentOptionsWithVue2Extend
796
+ : ! ! vueCompilerOptions . experimentalImplicitWrapComponentOptionsWithVue2Extend
791
797
) {
792
798
shimComponentOptionsMode = 'Vue.extend' ;
793
799
}
794
800
if (
795
- compilerOptions . experimentalImplicitWrapComponentOptionsWithDefineComponent === 'onlyJs'
801
+ vueCompilerOptions . experimentalImplicitWrapComponentOptionsWithDefineComponent === 'onlyJs'
796
802
? lang === 'js' || lang === 'jsx'
797
- : ! ! compilerOptions . experimentalImplicitWrapComponentOptionsWithDefineComponent
803
+ : ! ! vueCompilerOptions . experimentalImplicitWrapComponentOptionsWithDefineComponent
798
804
) {
799
805
shimComponentOptionsMode = 'defineComponent' ;
800
806
}
801
807
802
808
// true override 'onlyJs'
803
- if ( compilerOptions . experimentalImplicitWrapComponentOptionsWithVue2Extend === true ) {
809
+ if ( vueCompilerOptions . experimentalImplicitWrapComponentOptionsWithVue2Extend === true ) {
804
810
shimComponentOptionsMode = 'Vue.extend' ;
805
811
}
806
- if ( compilerOptions . experimentalImplicitWrapComponentOptionsWithDefineComponent === true ) {
812
+ if ( vueCompilerOptions . experimentalImplicitWrapComponentOptionsWithDefineComponent === true ) {
807
813
shimComponentOptionsMode = 'defineComponent' ;
808
814
}
809
815
0 commit comments