@@ -22,8 +22,6 @@ export function getComponentProps(
22
22
return ;
23
23
}
24
24
const vueCode = volarFile . generated . root ;
25
- const program = languageService . getProgram ( ) ! ;
26
- const checker = program . getTypeChecker ( ) ;
27
25
const components = getVariableType ( ts , languageService , vueCode , '__VLS_components' ) ;
28
26
if ( ! components ) {
29
27
return [ ] ;
@@ -35,26 +33,16 @@ export function getComponentProps(
35
33
}
36
34
37
35
const result = new Map < string , ComponentPropInfo > ( ) ;
36
+ const program = languageService . getProgram ( ) ! ;
37
+ const checker = program . getTypeChecker ( ) ;
38
38
39
39
for ( const sig of componentType . getCallSignatures ( ) ) {
40
40
const propParam = sig . parameters [ 0 ] ;
41
41
if ( propParam ) {
42
42
const propsType = checker . getTypeOfSymbolAtLocation ( propParam , components . node ) ;
43
43
const props = propsType . getProperties ( ) ;
44
44
for ( const prop of props ) {
45
- const name = prop . name ;
46
- const required = ! ( prop . flags & ts . SymbolFlags . Optional ) || undefined ;
47
- const {
48
- content : commentMarkdown ,
49
- deprecated
50
- } = generateCommentMarkdown ( prop . getDocumentationComment ( checker ) , prop . getJsDocTags ( ) ) ;
51
-
52
- result . set ( name , {
53
- name,
54
- required,
55
- deprecated,
56
- commentMarkdown
57
- } ) ;
45
+ handlePropSymbol ( prop ) ;
58
46
}
59
47
}
60
48
}
@@ -66,27 +54,44 @@ export function getComponentProps(
66
54
const propsType = checker . getTypeOfSymbolAtLocation ( propsSymbol , components . node ) ;
67
55
const props = propsType . getProperties ( ) ;
68
56
for ( const prop of props ) {
69
- if ( prop . flags & ts . SymbolFlags . Method ) { // #2443
70
- continue ;
71
- }
72
- const name = prop . name ;
73
- const required = ! ( prop . flags & ts . SymbolFlags . Optional ) || undefined ;
74
- const {
75
- content : commentMarkdown ,
76
- deprecated
77
- } = generateCommentMarkdown ( prop . getDocumentationComment ( checker ) , prop . getJsDocTags ( ) ) ;
78
-
79
- result . set ( name , {
80
- name,
81
- required,
82
- deprecated,
83
- commentMarkdown
84
- } ) ;
57
+ handlePropSymbol ( prop ) ;
85
58
}
86
59
}
87
60
}
88
61
89
62
return [ ...result . values ( ) ] ;
63
+
64
+ function handlePropSymbol ( prop : ts . Symbol ) {
65
+ if ( prop . flags & ts . SymbolFlags . Method ) { // #2443
66
+ return ;
67
+ }
68
+ const name = prop . name ;
69
+ const required = ! ( prop . flags & ts . SymbolFlags . Optional ) || undefined ;
70
+ const {
71
+ content : commentMarkdown ,
72
+ deprecated,
73
+ } = generateCommentMarkdown ( prop . getDocumentationComment ( checker ) , prop . getJsDocTags ( ) ) ;
74
+ const values : any [ ] = [ ] ;
75
+ const type = checker . getTypeOfSymbol ( prop ) ;
76
+ const subTypes : ts . Type [ ] | undefined = ( type as any ) . types ;
77
+
78
+ if ( subTypes ) {
79
+ for ( const subType of subTypes ) {
80
+ const value = ( subType as any ) . value ;
81
+ if ( value ) {
82
+ values . push ( value ) ;
83
+ }
84
+ }
85
+ }
86
+
87
+ result . set ( name , {
88
+ name,
89
+ required,
90
+ deprecated,
91
+ commentMarkdown,
92
+ values,
93
+ } ) ;
94
+ }
90
95
}
91
96
92
97
function generateCommentMarkdown ( parts : ts . SymbolDisplayPart [ ] , jsDocTags : ts . JSDocTagInfo [ ] ) {
0 commit comments