@@ -35,68 +35,60 @@ export function* generateTemplate(
3535 if ( options . templateCodegen ) {
3636 yield * options . templateCodegen . codes ;
3737 }
38- else {
39- if ( ! options . scriptSetupRanges ?. defineSlots ) {
40- yield `type ${ names . Slots } = {}${ endOfLine } ` ;
41- }
42- yield `type ${ names . InheritedAttrs } = {}${ endOfLine } ` ;
43- yield `type ${ names . TemplateRefs } = {}${ endOfLine } ` ;
44- yield `type ${ names . RootEl } = any${ endOfLine } ` ;
45- }
4638}
4739
48- function * generateSelf ( options : ScriptCodegenOptions ) : Generator < Code > {
49- if ( options . script && options . scriptRanges ?. componentOptions ) {
50- yield `const ${ names . self } = (await import('${ options . vueCompilerOptions . lib } ')).defineComponent(` ;
51- const { args } = options . scriptRanges . componentOptions ;
52- yield * generateSfcBlockSection ( options . script , args . start , args . end , codeFeatures . all ) ;
40+ function * generateSelf ( { script , scriptRanges , vueCompilerOptions , fileName } : ScriptCodegenOptions ) : Generator < Code > {
41+ if ( script && scriptRanges ?. componentOptions ) {
42+ yield `const ${ names . self } = (await import('${ vueCompilerOptions . lib } ')).defineComponent(` ;
43+ const { args } = scriptRanges . componentOptions ;
44+ yield * generateSfcBlockSection ( script , args . start , args . end , codeFeatures . all ) ;
5345 yield `)${ endOfLine } ` ;
5446 }
55- else if ( options . script && options . scriptRanges ?. exportDefault ) {
47+ else if ( script && scriptRanges ?. exportDefault ) {
5648 yield `const ${ names . self } = ` ;
57- const { expression } = options . scriptRanges . exportDefault ;
58- yield * generateSfcBlockSection ( options . script , expression . start , expression . end , codeFeatures . all ) ;
49+ const { expression } = scriptRanges . exportDefault ;
50+ yield * generateSfcBlockSection ( script , expression . start , expression . end , codeFeatures . all ) ;
5951 yield endOfLine ;
6052 }
61- else if ( options . script ?. src ) {
62- yield `let ${ names . self } !: typeof import('./${ path . basename ( options . fileName ) } ').default${ endOfLine } ` ;
53+ else if ( script ?. src ) {
54+ yield `let ${ names . self } !: typeof import('./${ path . basename ( fileName ) } ').default${ endOfLine } ` ;
6355 }
6456}
6557
6658function * generateTemplateCtx (
67- options : ScriptCodegenOptions ,
59+ { vueCompilerOptions , script , scriptRanges , styles , scriptSetupRanges , fileName } : ScriptCodegenOptions ,
6860 ctx : ScriptCodegenContext ,
6961) : Generator < Code > {
7062 const exps : Iterable < Code > [ ] = [ ] ;
7163 const emitTypes : string [ ] = [ ] ;
7264 const propTypes : string [ ] = [ ] ;
7365
74- if ( options . vueCompilerOptions . petiteVueExtensions . some ( ext => options . fileName . endsWith ( ext ) ) ) {
66+ if ( vueCompilerOptions . petiteVueExtensions . some ( ext => fileName . endsWith ( ext ) ) ) {
7567 exps . push ( [ `globalThis` ] ) ;
7668 }
77- if ( options . script ?. src || options . scriptRanges ?. exportDefault ) {
69+ if ( script ?. src || scriptRanges ?. exportDefault ) {
7870 exps . push ( [ `{} as InstanceType<__VLS_PickNotAny<typeof ${ names . self } , new () => {}>>` ] ) ;
7971 }
8072 else {
81- exps . push ( [ `{} as import('${ options . vueCompilerOptions . lib } ').ComponentPublicInstance` ] ) ;
73+ exps . push ( [ `{} as import('${ vueCompilerOptions . lib } ').ComponentPublicInstance` ] ) ;
8274 }
83- if ( options . styles . some ( style => style . module ) ) {
75+ if ( styles . some ( style => style . module ) ) {
8476 exps . push ( [ `{} as __VLS_StyleModules` ] ) ;
8577 }
8678
87- if ( options . scriptSetupRanges ?. defineEmits ) {
88- const { defineEmits } = options . scriptSetupRanges ;
79+ if ( scriptSetupRanges ?. defineEmits ) {
80+ const { defineEmits } = scriptSetupRanges ;
8981 emitTypes . push ( `typeof ${ defineEmits . name ?? names . emit } ` ) ;
9082 }
91- if ( options . scriptSetupRanges ?. defineModel . length ) {
83+ if ( scriptSetupRanges ?. defineModel . length ) {
9284 emitTypes . push ( `typeof ${ names . modelEmit } ` ) ;
9385 }
9486 if ( emitTypes . length ) {
9587 yield `type ${ names . EmitProps } = __VLS_EmitsToProps<__VLS_NormalizeEmits<${ emitTypes . join ( ` & ` ) } >>${ endOfLine } ` ;
9688 exps . push ( [ `{} as { $emit: ${ emitTypes . join ( ` & ` ) } }` ] ) ;
9789 }
9890
99- const { defineProps, withDefaults } = options . scriptSetupRanges ?? { } ;
91+ const { defineProps, withDefaults } = scriptSetupRanges ?? { } ;
10092 const props = defineProps ?. arg
10193 ? `typeof ${ defineProps . name ?? names . props } `
10294 : defineProps ?. typeArg
@@ -107,7 +99,7 @@ function* generateTemplateCtx(
10799 if ( props ) {
108100 propTypes . push ( props ) ;
109101 }
110- if ( options . scriptSetupRanges ?. defineModel . length ) {
102+ if ( scriptSetupRanges ?. defineModel . length ) {
111103 propTypes . push ( names . ModelProps ) ;
112104 }
113105 if ( emitTypes . length ) {
@@ -119,7 +111,7 @@ function* generateTemplateCtx(
119111 exps . push ( [ `{} as ${ names . InternalProps } ` ] ) ;
120112 }
121113
122- if ( options . scriptSetupRanges && ctx . bindingNames . size ) {
114+ if ( scriptSetupRanges && ctx . bindingNames . size ) {
123115 exps . push ( [ `{} as ${ names . Bindings } ` ] ) ;
124116 }
125117
0 commit comments