@@ -9,13 +9,48 @@ import { findParentSection } from './findParentSection.mjs';
9
9
10
10
export const createMethodSectionBuilder = ( ) => {
11
11
/**
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
12
43
* @param {HierarchizedEntry } entry The AST entry
13
44
* @param {import('../generated.d.ts').Method } section The method section
14
45
*/
15
46
const parseSignatures = ( entry , section ) => {
16
47
section . signatures = [ ] ;
17
48
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);
19
54
} ;
20
55
21
56
/**
@@ -26,18 +61,23 @@ export const createMethodSectionBuilder = () => {
26
61
return ( entry , section ) => {
27
62
parseSignatures ( entry , section ) ;
28
63
29
- // TODO are there any other places that an exposed method can be defined?
30
64
const parent = findParentSection ( section , [ 'class' , 'module' ] ) ;
31
65
32
66
// Add this section to the parent if it exists
33
67
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 ] ) ) {
35
75
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 } )`
37
77
) ;
38
78
}
39
79
40
- parent . methods . push ( section ) ;
80
+ parent [ property ] . push ( section ) ;
41
81
}
42
82
} ;
43
83
} ;
0 commit comments