@@ -23,33 +23,34 @@ import { buildMetaBarProps } from './buildBarProps.mjs';
23
23
* @param {import('unist').Parent } parent - The parent node containing the stability node
24
24
* @returns {[typeof SKIP] } Visitor instruction to skip the node
25
25
*/
26
- function transformStabilityNode ( node , index , parent ) {
27
- const { data } = node ;
26
+ const transformStabilityNode = ( { data } , index , parent ) => {
28
27
parent . children [ index ] = createJSXElement ( 'AlertBox' , {
29
28
children : data . description ,
30
29
level : STABILITY_LEVELS [ data . index ] ,
31
30
title : data . index ,
32
31
} ) ;
32
+
33
33
return [ SKIP ] ;
34
- }
34
+ } ;
35
35
36
36
/**
37
37
* Creates a history of changes for an API element
38
38
*
39
39
* @param {ApiDocMetadataEntry } entry - The metadata entry containing change information
40
40
* @returns {import('unist').Node|null } JSX element representing change history or null if no changes
41
41
*/
42
- function createChangeElement ( entry ) {
42
+ const createChangeElement = entry => {
43
43
// Collect changes from version fields (added, deprecated, etc.)
44
44
const changeEntries = Object . entries ( CHANGE_TYPES )
45
+ // Do we have this field?
45
46
. filter ( ( [ field ] ) => entry [ field ] )
46
- . map ( ( [ field , label ] ) => {
47
- const versions = enforceArray ( entry [ field ] ) ;
48
- return {
49
- versions ,
50
- label : ` ${ label } : ${ versions . join ( ', ' ) } ` ,
51
- } ;
52
- } ) ;
47
+ // Get the versions as an array
48
+ . map ( ( [ field , label ] ) => [ enforceArray ( entry [ field ] ) , label ] )
49
+ // Create the change entry
50
+ . map ( ( [ versions , label ] ) => ( {
51
+ versions,
52
+ label : ` ${ label } : ${ versions . join ( ', ' ) } ` ,
53
+ } ) ) ;
53
54
54
55
// Add explicit changes if they exist
55
56
if ( entry . changes ?. length ) {
@@ -61,22 +62,26 @@ function createChangeElement(entry) {
61
62
changeEntries . push ( ...explicitChanges ) ;
62
63
}
63
64
64
- if ( ! changeEntries . length ) return null ;
65
+ if ( ! changeEntries . length ) {
66
+ return null ;
67
+ }
65
68
66
69
// Sort by version, newest first and create the JSX element
67
70
return createJSXElement ( 'ChangeHistory' , {
68
71
changes : sortChanges ( changeEntries , 'versions' ) ,
69
72
} ) ;
70
- }
73
+ } ;
71
74
72
75
/**
73
76
* Creates a source link element if a source link is available
74
77
*
75
78
* @param {string|undefined } sourceLink - The source link path
76
79
* @returns {import('hastscript').Element|null } The source link element or null if no source link
77
80
*/
78
- function createSourceLink ( sourceLink ) {
79
- if ( ! sourceLink ) return null ;
81
+ const createSourceLink = sourceLink => {
82
+ if ( ! sourceLink ) {
83
+ return null ;
84
+ }
80
85
81
86
return createElement ( 'span' , [
82
87
'Source Code: ' ,
@@ -86,7 +91,7 @@ function createSourceLink(sourceLink) {
86
91
sourceLink
87
92
) ,
88
93
] ) ;
89
- }
94
+ } ;
90
95
91
96
/**
92
97
* Enhances a heading node with metadata, source links, and styling
@@ -97,7 +102,7 @@ function createSourceLink(sourceLink) {
97
102
* @param {import('unist').Parent } parent - The parent node containing the heading
98
103
* @returns {[typeof SKIP] } Visitor instruction to skip the node
99
104
*/
100
- function transformHeadingNode ( entry , node , index , parent ) {
105
+ const transformHeadingNode = ( entry , node , index , parent ) => {
101
106
const { data, children } = node ;
102
107
const headerChildren = [
103
108
createElement ( `h${ data . depth + 1 } ` , [
@@ -127,15 +132,15 @@ function transformHeadingNode(entry, node, index, parent) {
127
132
}
128
133
129
134
return [ SKIP ] ;
130
- }
135
+ } ;
131
136
132
137
/**
133
138
* Processes an API documentation entry by applying transformations to its content
134
139
*
135
140
* @param {ApiDocMetadataEntry } entry - The API metadata entry to process
136
141
* @returns {import('unist').Node } The processed content
137
142
*/
138
- function processEntry ( entry ) {
143
+ const processEntry = entry => {
139
144
// Create a copy to avoid modifying the original
140
145
const content = structuredClone ( entry . content ) ;
141
146
@@ -146,7 +151,7 @@ function processEntry(entry) {
146
151
) ;
147
152
148
153
return content ;
149
- }
154
+ } ;
150
155
151
156
/**
152
157
* Creates the overall content structure with processed entries
@@ -156,7 +161,7 @@ function processEntry(entry) {
156
161
* @param {Object } metaBarProps - Props for the meta bar component
157
162
* @returns {import('unist').Node } The root node of the content tree
158
163
*/
159
- function createContentStructure ( entries , sideBarProps , metaBarProps ) {
164
+ const createContentStructure = ( entries , sideBarProps , metaBarProps ) => {
160
165
return createTree ( 'root' , [
161
166
createJSXElement ( 'NavBar' ) ,
162
167
createJSXElement ( 'Article' , {
@@ -170,7 +175,7 @@ function createContentStructure(entries, sideBarProps, metaBarProps) {
170
175
] ,
171
176
} ) ,
172
177
] ) ;
173
- }
178
+ } ;
174
179
175
180
/**
176
181
* Transforms API metadata entries into processed MDX content
@@ -181,12 +186,7 @@ function createContentStructure(entries, sideBarProps, metaBarProps) {
181
186
* @param {import('unified').Processor } remark - Remark processor instance for markdown processing
182
187
* @returns {string } The stringified MDX content
183
188
*/
184
- export default function buildContent (
185
- metadataEntries ,
186
- head ,
187
- sideBarProps ,
188
- remark
189
- ) {
189
+ const buildContent = ( metadataEntries , head , sideBarProps , remark ) => {
190
190
const metaBarProps = buildMetaBarProps ( head , metadataEntries ) ;
191
191
192
192
const root = createContentStructure (
@@ -196,4 +196,6 @@ export default function buildContent(
196
196
) ;
197
197
198
198
return remark . runSync ( root ) ;
199
- }
199
+ } ;
200
+
201
+ export default buildContent ;
0 commit comments