@@ -9,13 +9,48 @@ import { findParentSection } from './findParentSection.mjs';
99
1010export const createMethodSectionBuilder = ( ) => {
1111 /**
12+ * TODO docs
13+ * @param {HierarchizedEntry } entry The AST entry
14+ * @returns {Record<string, import('../generated.d.ts').MethodParameter> | undefined }
15+ */
16+ const parseParameters = entry => {
17+ const [ , ...nodes ] = entry . content . children ;
18+
19+ const listNode = nodes . find ( node => node . type === 'list' ) ;
20+
21+ if ( ! listNode ) {
22+ // Method doesn't take in any parameters
23+ return undefined ;
24+ }
25+
26+ /**
27+ * @type {Record<string, import('../generated.d.ts').MethodParameter> }
28+ */
29+ const parameters = { } ;
30+
31+ listNode . children . forEach ( ( { children } ) => {
32+ // console.log(children)
33+ // if (children.length !== 1) {
34+ // console.log(JSON.stringify(children, null, 2))
35+ // }
36+ } ) ;
37+
38+ return parameters ;
39+ } ;
40+
41+ /**
42+ * TODO docs
1243 * @param {HierarchizedEntry } entry The AST entry
1344 * @param {import('../generated.d.ts').Method } section The method section
1445 */
1546 const parseSignatures = ( entry , section ) => {
1647 section . signatures = [ ] ;
1748
18-
49+ // Parse all the parameters and store them in a name:section map
50+ const parameters = parseParameters ( entry , section ) ;
51+
52+ // Parse the value of entry.heading.data.text to get the order of parameters and which are optional
53+ // console.log(entry.heading.data.text);
1954 } ;
2055
2156 /**
@@ -26,18 +61,23 @@ export const createMethodSectionBuilder = () => {
2661 return ( entry , section ) => {
2762 parseSignatures ( entry , section ) ;
2863
29- // TODO are there any other places that an exposed method can be defined?
3064 const parent = findParentSection ( section , [ 'class' , 'module' ] ) ;
3165
3266 // Add this section to the parent if it exists
3367 if ( parent ) {
34- if ( ! Array . isArray ( parent . methods ) ) {
68+ // Put static methods in `staticMethods` property and non-static methods
69+ // in the `methods` property
70+ const property = entry . heading . data . text . startsWith ( 'Static method:' )
71+ ? 'staticMethods'
72+ : 'methods' ;
73+
74+ if ( ! Array . isArray ( parent [ property ] ) ) {
3575 throw new TypeError (
36- `expected parent.methods to be an array, got type ${ typeof parent . methods } instead (parent type=${ parent . type } )`
76+ `expected parent[ ${ property } ] to be an array, got type ${ typeof parent [ property ] } instead (parent type=${ parent . type } )`
3777 ) ;
3878 }
3979
40- parent . methods . push ( section ) ;
80+ parent [ property ] . push ( section ) ;
4181 }
4282 } ;
4383} ;
0 commit comments