@@ -4,44 +4,52 @@ import buildContent from './utils/buildContent.mjs';
44import { groupNodesByModule } from '../../utils/generators.mjs' ;
55import { getRemarkRecma } from '../../utils/remark.mjs' ;
66
7- /**
8- * Generator for converting MDAST to JSX AST.
9- *
10- * @typedef {Array<ApiDocMetadataEntry> } Input
11- * @type {GeneratorMetadata<Input, string> }
12- */
13-
147/**
158 * Sorts entries by OVERRIDDEN_POSITIONS and then heading name.
169 * @param {Array<ApiDocMetadataEntry> } entries
1710 */
1811const getSortedHeadNodes = entries => {
19- return entries
20- . filter ( node => node . heading . depth === 1 )
21- . sort ( ( a , b ) => {
22- const ai = OVERRIDDEN_POSITIONS . indexOf ( a . api ) ;
23- const bi = OVERRIDDEN_POSITIONS . indexOf ( b . api ) ;
24-
25- if ( ai !== - 1 && bi !== - 1 ) {
26- return ai - bi ;
27- }
28-
29- if ( ai !== - 1 ) {
30- return - 1 ;
31- }
32-
33- if ( bi !== - 1 ) {
34- return 1 ;
35- }
36-
37- return a . heading . data . name . localeCompare ( b . heading . data . name ) ;
38- } ) ;
12+ /**
13+ * Sorts entries by OVERRIDDEN_POSITIONS and then heading name.
14+ * @param {ApiDocMetadataEntry } a
15+ * @param {ApiDocMetadataEntry } b
16+ * @returns {number }
17+ */
18+ const headingSortFn = ( a , b ) => {
19+ const ai = OVERRIDDEN_POSITIONS . indexOf ( a . api ) ;
20+ const bi = OVERRIDDEN_POSITIONS . indexOf ( b . api ) ;
21+
22+ if ( ai !== - 1 && bi !== - 1 ) {
23+ return ai - bi ;
24+ }
25+
26+ if ( ai !== - 1 ) {
27+ return - 1 ;
28+ }
29+
30+ if ( bi !== - 1 ) {
31+ return 1 ;
32+ }
33+
34+ return a . heading . data . name . localeCompare ( b . heading . data . name ) ;
35+ } ;
36+
37+ return entries . filter ( node => node . heading . depth === 1 ) . sort ( headingSortFn ) ;
3938} ;
4039
40+ /**
41+ * Generator for converting MDAST to JSX AST.
42+ *
43+ * @typedef {Array<ApiDocMetadataEntry> } Input
44+ * @type {GeneratorMetadata<Input, string> }
45+ */
4146export default {
4247 name : 'jsx-ast' ,
48+
4349 version : '1.0.0' ,
50+
4451 description : 'Generates JSX AST from the input MDAST' ,
52+
4553 dependsOn : 'metadata' ,
4654
4755 /**
@@ -71,14 +79,14 @@ export default {
7179 docPages
7280 ) ;
7381
74- results . push (
75- await buildContent (
76- groupedModules . get ( entry . api ) ,
77- entry ,
78- sideBarProps ,
79- remarkRecma
80- )
82+ const content = await buildContent (
83+ groupedModules . get ( entry . api ) ,
84+ entry ,
85+ sideBarProps ,
86+ remarkRecma
8187 ) ;
88+
89+ results . push ( content ) ;
8290 }
8391
8492 return results ;
@@ -92,7 +100,7 @@ export default {
92100 * @returns {Promise<Array<string>> } Array of generated content
93101 */
94102 async generate ( entries , { index, releases, version, worker } ) {
95- const headNodes = getSortedHeadNodes ( entries ) ;
103+ const headNodes = entries . filter ( node => node . heading . depth === 1 ) ;
96104
97105 return worker . map ( headNodes , entries , { index, releases, version } ) ;
98106 } ,
0 commit comments