@@ -35,8 +35,11 @@ export const parseListIntoProperties = node => {
3535 if ( children [ 0 ] . type === 'inlineCode' ) {
3636 name = children . shift ( ) . value . trimEnd ( ) ;
3737 } else if ( children [ 0 ] . value && children [ 0 ] . value . startsWith ( 'Returns' ) ) {
38- children . shift ( ) ;
3938 name = 'Returns' ;
39+ children [ 0 ] . value = children [ 0 ] . value . replace ( / ^ R e t u r n s : ? \s * / i, '' ) ;
40+ if ( ! children [ 0 ] . value . trim ( ) ) {
41+ children . shift ( ) ;
42+ }
4043 }
4144
4245 if ( children [ 0 ] ?. value ?. trim ( ) === '' ) {
@@ -129,57 +132,28 @@ export const createPropertyTable = (node, withHeading = true) => {
129132} ;
130133
131134/**
132- * Generates all valid function signatures based on optional parameters
135+ * Generates the function signature based on optional parameters
133136 * @param {string } functionName - Name of the function
134137 * @param {import('../../legacy-json/types.d.ts').MethodSignature } signature - Signature object
135138 * @param {string } prefix - `'new '` or `''`
136139 */
137- export const generateSignatures = ( functionName , signature , prefix = '' ) => {
138- const { params, return : returnType } = signature ;
140+ export const generateSignature = (
141+ functionName ,
142+ { params, return : returnType } ,
143+ prefix = ''
144+ ) => {
139145 const returnStr = returnType ? `: ${ returnType . type } ` : '' ;
140-
141- // Handle case with no optional parameters
142- const optionalParams = params . filter ( param => param . optional ) ;
143- if ( ! optionalParams . length ) {
144- const paramsStr = params . map ( param => param . name ) . join ( ', ' ) ;
145- return [ `${ prefix } ${ functionName } (${ paramsStr } )${ returnStr } ` ] ;
146- }
147-
148- // Find indexes of optional parameters
149- const optionalIndexes = params
150- . map ( ( param , index ) => ( param . optional ? index : - 1 ) )
151- . filter ( index => index !== - 1 ) ;
152-
153- // Generate all possible combinations of optional parameters
154- const signatures = [ ] ;
155- const totalCombinations = 1 << optionalIndexes . length ; // 2^n using bitshift
156-
157- for ( let i = 0 ; i < totalCombinations ; i ++ ) {
158- const includedParams = params . filter ( ( param , index ) => {
159- // Always include required parameters
160- if ( ! param . optional ) {
161- return true ;
146+ const paramsStr = params
147+ . map ( param => {
148+ let paramStr = param . name ;
149+ if ( param . optional || param . default ) {
150+ paramStr += '?' ;
162151 }
152+ return paramStr ;
153+ } )
154+ . join ( ', ' ) ;
163155
164- // For optional parameters, check if this combination includes it
165- const optionalIndex = optionalIndexes . indexOf ( index ) ;
166- return ( ( i >> optionalIndex ) & 1 ) === 1 ;
167- } ) ;
168-
169- const paramsStr = includedParams
170- . map ( param => {
171- let paramStr = param . name ;
172- if ( param . optional || param . default ) {
173- paramStr += '?' ;
174- }
175- return paramStr ;
176- } )
177- . join ( ', ' ) ;
178-
179- signatures . push ( `${ prefix } ${ functionName } (${ paramsStr } )${ returnStr } ` ) ;
180- }
181-
182- return signatures ;
156+ return `${ prefix } ${ functionName } (${ paramsStr } )${ returnStr } ` ;
183157} ;
184158
185159/**
@@ -189,9 +163,8 @@ export const generateSignatures = (functionName, signature, prefix = '') => {
189163 * @param {string } prefix - `'new '` or `''`
190164 */
191165export const createSignatureCodeBlock = ( functionName , signature , prefix ) => {
192- const signatures = generateSignatures ( functionName , signature , prefix ) ;
193- const codeContent = signatures . join ( '\n' ) ;
194- const highlighted = highlightToHast ( codeContent , 'typescript' ) ;
166+ const sig = generateSignature ( functionName , signature , prefix ) ;
167+ const highlighted = highlightToHast ( sig , 'typescript' ) ;
195168 return createElement ( 'div' , { class : 'signature' } , [ highlighted ] ) ;
196169} ;
197170
0 commit comments