@@ -134,6 +134,7 @@ function parseListItem(child, entry) {
134134
135135 // Recursively parse nested options if a list is found within the list item
136136 const optionsNode = child . children . find ( child => child . type === 'list' ) ;
137+
137138 if ( optionsNode ) {
138139 current . options = optionsNode . children . map ( child =>
139140 parseListItem ( child , entry )
@@ -175,6 +176,7 @@ function parseStability(section, nodes) {
175176 */
176177function parseList ( section , nodes , entry ) {
177178 const list = nodes [ 0 ] ?. type === 'list' ? nodes . shift ( ) : null ;
179+
178180 const values = list
179181 ? list . children . map ( child => parseListItem ( child , entry ) )
180182 : [ ] ;
@@ -188,7 +190,8 @@ function parseList(section, nodes, entry) {
188190 case 'property' :
189191 if ( values . length ) {
190192 const { type, ...rest } = values [ 0 ] ;
191- if ( type ) section . propertySigType = type ;
193+
194+ section . type = type ;
192195 Object . assign ( section , rest ) ;
193196 section . textRaw = `\`${ section . name } \` ${ section . textRaw } ` ;
194197 }
@@ -197,26 +200,35 @@ function parseList(section, nodes, entry) {
197200 section . params = values ;
198201 break ;
199202 default :
200- if ( list ) nodes . unshift ( list ) ; // If the list wasn't processed, add it back for further processing
203+ // If the list wasn't processed, add it back for further processing
204+ if ( list ) {
205+ nodes . unshift ( list ) ;
206+ }
201207 }
202208}
203209
210+ let lazyHTML ;
211+
204212/**
205213 * Adds a description to the section.
206214 * @param {import('../types.d.ts').Section } section - The section to add description to.
207215 * @param {Array } nodes - The AST nodes.
208216 */
209217function addDescription ( section , nodes ) {
210- if ( ! nodes . length ) return ;
218+ if ( ! nodes . length ) {
219+ return ;
220+ }
211221
212222 if ( section . desc ) {
213223 section . shortDesc = section . desc ;
214224 }
215225
216- const html = getRemarkRehype ( ) ;
217- const rendered = html . stringify (
218- html . runSync ( { type : 'root' , children : nodes } )
226+ lazyHTML ??= getRemarkRehype ( ) ;
227+
228+ const rendered = lazyHTML . stringify (
229+ lazyHTML . runSync ( { type : 'root' , children : nodes } )
219230 ) ;
231+
220232 section . desc = rendered || undefined ;
221233}
222234
@@ -241,32 +253,38 @@ function addAdditionalMetadata(section, parentSection, headingNode) {
241253 */
242254function addToParent ( section , parentSection ) {
243255 const pluralType = sectionTypePlurals [ section . type ] ;
256+
244257 parentSection [ pluralType ] = parentSection [ pluralType ] || [ ] ;
245258 parentSection [ pluralType ] . push ( section ) ;
246259}
247260
261+ const notTransferredKeys = [ 'textRaw' , 'name' , 'type' , 'desc' , 'miscs' ] ;
262+
248263/**
249- * Promotes children to top-level if the section type is 'misc'.
264+ * Promotes children properties to the parent level if the section type is 'misc'.
265+ *
250266 * @param {import('../types.d.ts').Section } section - The section to promote.
251267 * @param {import('../types.d.ts').Section } parentSection - The parent section.
252268 */
253269const makeChildrenTopLevelIfMisc = ( section , parentSection ) => {
254- if ( section . type !== 'misc' || parentSection . type === 'misc' ) {
255- return ;
270+ // Only promote if the current section is of type 'misc' and the parent is not 'misc'
271+ if ( section . type === 'misc' && parentSection . type !== 'misc' ) {
272+ Object . entries ( section ) . forEach ( ( [ key , value ] ) => {
273+ // Skip keys that should not be transferred
274+ if ( notTransferredKeys . includes ( key ) ) return ;
275+
276+ // Merge the section's properties into the parent section
277+ parentSection [ key ] = parentSection [ key ]
278+ ? // If the parent already has this key, concatenate the values
279+ [ ] . concat ( parentSection [ key ] , value )
280+ : // Otherwise, directly assign the section's value to the parent
281+ value ;
282+ } ) ;
256283 }
284+ } ;
257285
258- Object . keys ( section ) . forEach ( key => {
259- if ( [ 'textRaw' , 'name' , 'type' , 'desc' , 'miscs' ] . includes ( key ) ) {
260- return ;
261- }
262- if ( parentSection [ key ] ) {
263- parentSection [ key ] = Array . isArray ( parentSection [ key ] )
264- ? parentSection [ key ] . concat ( section [ key ] )
265- : section [ key ] ;
266- } else {
267- parentSection [ key ] = section [ key ] ;
268- }
269- } ) ;
286+ const handleChildren = ( entry , section ) => {
287+ entry . hierarchyChildren ?. forEach ( child => handleEntry ( child , section ) ) ;
270288} ;
271289
272290/**
@@ -281,19 +299,10 @@ function handleEntry(entry, parentSection) {
281299 parseStability ( section , nodes ) ;
282300 parseList ( section , nodes , entry ) ;
283301 addDescription ( section , nodes ) ;
284- entry . hierarchyChildren ?. forEach ( child => handleEntry ( child , section ) ) ;
302+ handleChildren ( entry , section ) ;
285303 addAdditionalMetadata ( section , parentSection , headingNode ) ;
286304 addToParent ( section , parentSection ) ;
287305 makeChildrenTopLevelIfMisc ( section , parentSection ) ;
288-
289- if ( section . type === 'property' ) {
290- if ( section . propertySigType ) {
291- section . type = section . propertySigType ;
292- delete section . propertySigType ;
293- } else {
294- delete section . type ;
295- }
296- }
297306}
298307
299308/**
0 commit comments