@@ -11,7 +11,7 @@ import type { ScriptSetupRanges } from '../parsers/scriptSetupRanges';
11
11
import { collectCssVars , collectStyleCssClasses } from '../plugins/vue-tsx' ;
12
12
import { Sfc } from '../types' ;
13
13
import type { VueCompilerOptions } from '../types' ;
14
- import { getSlotsPropertyName , getVueLibraryName } from '../utils/shared' ;
14
+ import { getSlotsPropertyName } from '../utils/shared' ;
15
15
import { walkInterpolationFragment } from '../utils/transform' ;
16
16
import * as sharedTypes from '../utils/directorySharedTypes' ;
17
17
import * as muggle from 'muggle-string' ;
@@ -72,7 +72,6 @@ export function generate(
72
72
//#endregion
73
73
74
74
const bypassDefineComponent = lang === 'js' || lang === 'jsx' ;
75
- const vueLibName = getVueLibraryName ( vueCompilerOptions . target ) ;
76
75
const usedHelperTypes = {
77
76
DefinePropsToOptions : false ,
78
77
mergePropDefaults : false ,
@@ -116,11 +115,11 @@ export function generate(
116
115
let usedPrettify = false ;
117
116
if ( usedHelperTypes . DefinePropsToOptions ) {
118
117
if ( compilerOptions . exactOptionalPropertyTypes ) {
119
- codes . push ( `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` ) ;
118
+ codes . push ( `type __VLS_TypePropsToRuntimeProps<T> = { [K in keyof T]-?: {} extends Pick<T, K> ? { type: import('${ vueCompilerOptions . lib } ').PropType<T[K]> } : { type: import('${ vueCompilerOptions . lib } ').PropType<T[K]>, required: true } };\n` ) ;
120
119
}
121
120
else {
122
121
codes . push ( `type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;\n` ) ;
123
- codes . push ( `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` ) ;
122
+ codes . push ( `type __VLS_TypePropsToRuntimeProps<T> = { [K in keyof T]-?: {} extends Pick<T, K> ? { type: import('${ vueCompilerOptions . lib } ').PropType<__VLS_NonUndefinedable<T[K]>> } : { type: import('${ vueCompilerOptions . lib } ').PropType<T[K]>, required: true } };\n` ) ;
124
123
}
125
124
}
126
125
if ( usedHelperTypes . mergePropDefaults ) {
@@ -317,9 +316,9 @@ export function generate(
317
316
codes . push ( '(\n' ) ;
318
317
codes . push (
319
318
`__VLS_props: typeof __VLS_setup['props']` ,
320
- `& import('${ vueLibName } ').VNodeProps` ,
321
- `& import('${ vueLibName } ').AllowedComponentProps` ,
322
- `& import('${ vueLibName } ').ComponentCustomProps,\n` ,
319
+ `& import('${ vueCompilerOptions . lib } ').VNodeProps` ,
320
+ `& import('${ vueCompilerOptions . lib } ').AllowedComponentProps` ,
321
+ `& import('${ vueCompilerOptions . lib } ').ComponentCustomProps,\n` ,
323
322
) ;
324
323
codes . push ( `__VLS_ctx?: Pick<typeof __VLS_setup, 'attrs' | 'emit' | 'slots'>,\n` ) ;
325
324
codes . push ( '__VLS_setup = (() => {\n' ) ;
@@ -437,7 +436,7 @@ export function generate(
437
436
codes . push ( 'emit: typeof __VLS_emit' ) ;
438
437
codes . push ( '};\n' ) ;
439
438
codes . push ( '})(),\n' ) ;
440
- codes . push ( `) => ({} as import('${ vueLibName } ').VNode & { __ctx?: typeof __VLS_setup }))` ) ;
439
+ codes . push ( `) => ({} as import('${ vueCompilerOptions . lib } ').VNode & { __ctx?: typeof __VLS_setup }))` ) ;
441
440
}
442
441
else if ( ! sfc . script ) {
443
442
// no script block, generate script setup code at root
@@ -484,20 +483,20 @@ export function generate(
484
483
const definePropProposalB = sfc . scriptSetup . content . trimStart ( ) . startsWith ( '// @experimentalDefinePropProposal=johnsonEdition' ) || vueCompilerOptions . experimentalDefinePropProposal === 'johnsonEdition' ;
485
484
486
485
if ( vueCompilerOptions . target >= 3.3 ) {
487
- codes . push ( `const { defineProps, defineEmits, defineExpose, defineOptions, defineSlots, defineModel, withDefaults } = await import('${ vueLibName } ');\n` ) ;
486
+ codes . push ( `const { defineProps, defineEmits, defineExpose, defineOptions, defineSlots, defineModel, withDefaults } = await import('${ vueCompilerOptions . lib } ');\n` ) ;
488
487
}
489
488
if ( definePropProposalA ) {
490
489
codes . push ( `
491
- declare function defineProp<T>(name: string, options: { required: true } & Record<string, unknown>): import('${ vueLibName } ').ComputedRef<T>;
492
- declare function defineProp<T>(name: string, options: { default: any } & Record<string, unknown>): import('${ vueLibName } ').ComputedRef<T>;
493
- declare function defineProp<T>(name?: string, options?: any): import('${ vueLibName } ').ComputedRef<T | undefined>;
490
+ declare function defineProp<T>(name: string, options: { required: true } & Record<string, unknown>): import('${ vueCompilerOptions . lib } ').ComputedRef<T>;
491
+ declare function defineProp<T>(name: string, options: { default: any } & Record<string, unknown>): import('${ vueCompilerOptions . lib } ').ComputedRef<T>;
492
+ declare function defineProp<T>(name?: string, options?: any): import('${ vueCompilerOptions . lib } ').ComputedRef<T | undefined>;
494
493
` . trim ( ) + '\n' ) ;
495
494
}
496
495
if ( definePropProposalB ) {
497
496
codes . push ( `
498
- declare function defineProp<T>(value: T | (() => T), required?: boolean, rest?: any): import('${ vueLibName } ').ComputedRef<T>;
499
- declare function defineProp<T>(value: T | (() => T) | undefined, required: true, rest?: any): import('${ vueLibName } ').ComputedRef<T>;
500
- declare function defineProp<T>(value?: T | (() => T), required?: boolean, rest?: any): import('${ vueLibName } ').ComputedRef<T | undefined>;
497
+ declare function defineProp<T>(value: T | (() => T), required?: boolean, rest?: any): import('${ vueCompilerOptions . lib } ').ComputedRef<T>;
498
+ declare function defineProp<T>(value: T | (() => T) | undefined, required: true, rest?: any): import('${ vueCompilerOptions . lib } ').ComputedRef<T>;
499
+ declare function defineProp<T>(value?: T | (() => T), required?: boolean, rest?: any): import('${ vueCompilerOptions . lib } ').ComputedRef<T | undefined>;
501
500
` . trim ( ) + '\n' ) ;
502
501
}
503
502
@@ -519,7 +518,7 @@ declare function defineProp<T>(value?: T | (() => T), required?: boolean, rest?:
519
518
codes . push ( `{\n` ) ;
520
519
}
521
520
else {
522
- codes . push ( `const __VLS_publicComponent = (await import('${ vueLibName } ')).defineComponent({\n` ) ;
521
+ codes . push ( `const __VLS_publicComponent = (await import('${ vueCompilerOptions . lib } ')).defineComponent({\n` ) ;
523
522
}
524
523
525
524
if ( scriptSetupRanges . defineProp . length ) {
@@ -552,10 +551,10 @@ declare function defineProp<T>(value?: T | (() => T), required?: boolean, rest?:
552
551
}
553
552
554
553
if ( defineProp . required ) {
555
- codes . push ( `{ required: true, type: import('${ vueLibName } ').PropType<${ type } > },\n` ) ;
554
+ codes . push ( `{ required: true, type: import('${ vueCompilerOptions . lib } ').PropType<${ type } > },\n` ) ;
556
555
}
557
556
else {
558
- codes . push ( `import('${ vueLibName } ').PropType<${ type } >,\n` ) ;
557
+ codes . push ( `import('${ vueCompilerOptions . lib } ').PropType<${ type } >,\n` ) ;
559
558
}
560
559
}
561
560
codes . push ( `},\n` ) ;
@@ -714,7 +713,7 @@ declare function defineProp<T>(value?: T | (() => T), required?: boolean, rest?:
714
713
715
714
if ( sfc . scriptSetup && scriptSetupRanges ) {
716
715
717
- codes . push ( `const __VLS_internalComponent = (await import('${ vueLibName } ')).defineComponent({\n` ) ;
716
+ codes . push ( `const __VLS_internalComponent = (await import('${ vueCompilerOptions . lib } ')).defineComponent({\n` ) ;
718
717
codes . push ( `setup() {\n` ) ;
719
718
codes . push ( `return {\n` ) ;
720
719
// fill ctx from props
@@ -776,7 +775,7 @@ declare function defineProp<T>(value?: T | (() => T), required?: boolean, rest?:
776
775
codes . push ( `let __VLS_internalComponent!: typeof import('./${ path . basename ( fileName ) } ')['default'];\n` ) ;
777
776
}
778
777
else {
779
- codes . push ( `const __VLS_internalComponent = (await import('${ vueLibName } ')).defineComponent({});\n` ) ;
778
+ codes . push ( `const __VLS_internalComponent = (await import('${ vueCompilerOptions . lib } ')).defineComponent({});\n` ) ;
780
779
}
781
780
}
782
781
function generateExportOptions ( ) {
0 commit comments