@@ -22,7 +22,7 @@ const WITH_DEFAULTS = 'withDefaults'
2222
2323export interface PropTypeData {
2424 key : string
25- type : string [ ]
25+ type : string [ ] | string
2626 required : boolean
2727}
2828
@@ -211,17 +211,19 @@ export function applyMacros(nodes: Statement[]) {
211211
212212 return t . objectExpression (
213213 Object . entries ( props ) . map ( ( [ key , value ] ) => {
214+ if ( value . type === 'null' )
215+ return t . objectProperty ( t . identifier ( key ) , t . nullLiteral ( ) )
216+
214217 const prop = hasStaticDefaults
215218 ? ( propsRuntimeDefaults as ObjectExpression ) . properties . find ( ( node : any ) => node . key . name === key ) as ObjectProperty
216219 : undefined
217220
218221 if ( prop )
219222 value . required = false
220223
221- const entries = Object . entries ( value ) . map ( ( [ key , value ] ) =>
222- key === 'type'
223- ? t . objectProperty ( t . identifier ( key ) , t . arrayExpression ( value . map ( ( i : any ) => t . identifier ( i ) ) ) as any )
224- : t . objectProperty ( t . identifier ( key ) , parseExpression ( JSON . stringify ( value ) ) as any ) ,
224+ const entries = Object . entries ( value ) . map ( ( [ key , value ] ) => key === 'type'
225+ ? t . objectProperty ( t . identifier ( key ) , typeof value === 'string' ? t . identifier ( value ) : t . arrayExpression ( value . map ( ( i : any ) => t . identifier ( i ) ) ) as any )
226+ : t . objectProperty ( t . identifier ( key ) , parseExpression ( JSON . stringify ( value ) ) as any ) ,
225227 )
226228
227229 if ( prop )
@@ -311,7 +313,7 @@ function extractRuntimeProps(
311313 ( m . type === 'TSPropertySignature' || m . type === 'TSMethodSignature' )
312314 && m . key . type === 'Identifier'
313315 ) {
314- let type
316+ let type : string [ ] | undefined
315317 if ( m . type === 'TSMethodSignature' ) {
316318 type = [ 'Function' ]
317319 }
@@ -324,7 +326,7 @@ function extractRuntimeProps(
324326 props [ m . key . name ] = {
325327 key : m . key . name ,
326328 required : ! m . optional ,
327- type : type || [ 'null' ] ,
329+ type : type ?. length === 1 ? type [ 0 ] : type || 'null' ,
328330 }
329331 }
330332 }
0 commit comments