@wordpress/docgen 1.17.3 → 1.18.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md
CHANGED
package/lib/engine.js
CHANGED
|
@@ -38,10 +38,10 @@ const engine = ( path, code, getIRFromPath = () => {} ) => {
|
|
|
38
38
|
/**
|
|
39
39
|
* Function that takes code and returns an intermediate representation.
|
|
40
40
|
*
|
|
41
|
-
* @param {string}
|
|
41
|
+
* @param {string} code The code to parse.
|
|
42
42
|
* @param {Function} [getIRFromPath=noop] Callback to retrieve the
|
|
43
|
-
*
|
|
44
|
-
*
|
|
43
|
+
* Intermediate Representation from a path relative to the file
|
|
44
|
+
* being parsed.
|
|
45
45
|
*
|
|
46
46
|
* @return {Object} Intermediate Representation in JSON.
|
|
47
47
|
*/
|
|
@@ -121,11 +121,11 @@ const getJSDoc = ( token, entry, ast, parseDependency ) => {
|
|
|
121
121
|
* the identifier declaration will be looked up in the file or dependency
|
|
122
122
|
* if an `ast` and `parseDependency` callback are provided.
|
|
123
123
|
*
|
|
124
|
-
* @param {string}
|
|
125
|
-
* @param {Object}
|
|
126
|
-
* @param {Object}
|
|
124
|
+
* @param {string} path Path to file being processed.
|
|
125
|
+
* @param {Object} token Espree export token.
|
|
126
|
+
* @param {Object} [ast] Espree ast of the file being parsed.
|
|
127
127
|
* @param {Function} [parseDependency] Function that takes a path
|
|
128
|
-
*
|
|
128
|
+
* and returns the intermediate representation of the dependency file.
|
|
129
129
|
*
|
|
130
130
|
* @return {Object} Intermediate Representation in JSON.
|
|
131
131
|
*/
|
|
@@ -8,12 +8,13 @@ const { types: babelTypes } = require( '@babel/core' );
|
|
|
8
8
|
/** @typedef {ReturnType<import('comment-parser').parse>[0]} CommentBlock */
|
|
9
9
|
/** @typedef {CommentBlock['tags'][0]} CommentTag */
|
|
10
10
|
/** @typedef {babelTypes.TSType} TypeAnnotation */
|
|
11
|
+
/** @typedef {babelTypes.TSCallSignatureDeclaration | babelTypes.TSFunctionType | babelTypes.TSConstructSignatureDeclaration} ExtendedTypeAnnotation */
|
|
11
12
|
/** @typedef {import('@babel/core').Node} ASTNode */
|
|
12
13
|
/* eslint-enable jsdoc/valid-types */
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
|
-
* @param {
|
|
16
|
-
* @param {' => ' | ': '}
|
|
16
|
+
* @param {ExtendedTypeAnnotation} typeAnnotation
|
|
17
|
+
* @param {' => ' | ': '} returnIndicator The return indicator to use. Allows using the same function for function annotations and object call properties.
|
|
17
18
|
*/
|
|
18
19
|
function getFunctionTypeAnnotation( typeAnnotation, returnIndicator ) {
|
|
19
20
|
const nonRestParams = typeAnnotation.parameters
|
|
@@ -43,7 +44,9 @@ function getFunctionTypeAnnotation( typeAnnotation, returnIndicator ) {
|
|
|
43
44
|
typeAnnotation.typeAnnotation.typeAnnotation
|
|
44
45
|
);
|
|
45
46
|
|
|
46
|
-
|
|
47
|
+
const paramsWithParens = params.length ? `( ${ params } )` : `()`;
|
|
48
|
+
|
|
49
|
+
return `${ paramsWithParens }${ returnIndicator }${ returnType }`;
|
|
47
50
|
}
|
|
48
51
|
|
|
49
52
|
/**
|
|
@@ -376,6 +379,10 @@ function getTypeAnnotation( typeAnnotation ) {
|
|
|
376
379
|
*/
|
|
377
380
|
function getFunctionToken( token ) {
|
|
378
381
|
let resolvedToken = token;
|
|
382
|
+
if ( babelTypes.isExportDefaultDeclaration( resolvedToken ) ) {
|
|
383
|
+
resolvedToken = resolvedToken.declaration;
|
|
384
|
+
}
|
|
385
|
+
|
|
379
386
|
if ( babelTypes.isExportNamedDeclaration( resolvedToken ) ) {
|
|
380
387
|
resolvedToken = resolvedToken.declaration;
|
|
381
388
|
}
|
|
@@ -441,9 +448,9 @@ function getQualifiedObjectPatternTypeAnnotation( tag, paramType ) {
|
|
|
441
448
|
}
|
|
442
449
|
|
|
443
450
|
/**
|
|
444
|
-
* @param {CommentTag} tag
|
|
445
|
-
* @param {ASTNode}
|
|
446
|
-
* @param {number}
|
|
451
|
+
* @param {CommentTag} tag The documented parameter.
|
|
452
|
+
* @param {ASTNode} declarationToken The function the parameter is documented on.
|
|
453
|
+
* @param {number} paramIndex The parameter index.
|
|
447
454
|
* @return {null | string} The parameter's type annotation.
|
|
448
455
|
*/
|
|
449
456
|
function getParamTypeAnnotation( tag, declarationToken, paramIndex ) {
|
|
@@ -540,8 +547,8 @@ function getVariableTypeAnnotation( declarationToken ) {
|
|
|
540
547
|
|
|
541
548
|
module.exports =
|
|
542
549
|
/**
|
|
543
|
-
* @param {CommentTag}
|
|
544
|
-
* @param {ASTNode}
|
|
550
|
+
* @param {CommentTag} tag A comment tag.
|
|
551
|
+
* @param {ASTNode} token A function token.
|
|
545
552
|
* @param {number | null} index The index of the parameter or `null` if not a param tag.
|
|
546
553
|
* @return {null | string} The type annotation for the given tag or null if the tag has no type annotation.
|
|
547
554
|
*/
|
package/lib/markdown/embed.js
CHANGED
|
@@ -15,8 +15,8 @@ const getHeadingIndex = ( ast, index ) => {
|
|
|
15
15
|
/**
|
|
16
16
|
* Inserts new contents within the token boundaries.
|
|
17
17
|
*
|
|
18
|
-
* @param {string} token
|
|
19
|
-
* @param {Object} targetAst
|
|
18
|
+
* @param {string} token String to embed in the start/end tokens.
|
|
19
|
+
* @param {Object} targetAst The remark AST of the file where the new contents are to be embedded.
|
|
20
20
|
* @param {Object} newContentAst The new contents to be embedded in remark AST format.
|
|
21
21
|
* @return {boolean} Whether the contents were embedded or not.
|
|
22
22
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/docgen",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.18.1",
|
|
4
4
|
"description": "Autogenerate public API documentation from exports and JSDoc comments.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"docgen": "./bin/cli.js"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@babel/core": "^7.
|
|
30
|
+
"@babel/core": "^7.16.0",
|
|
31
31
|
"comment-parser": "^1.1.1",
|
|
32
32
|
"lodash": "^4.17.21",
|
|
33
33
|
"mdast-util-inject": "1.1.0",
|
|
@@ -39,5 +39,5 @@
|
|
|
39
39
|
"publishConfig": {
|
|
40
40
|
"access": "public"
|
|
41
41
|
},
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "9a1dd3474d937468e4cf9caf9886ad61ef0a8f50"
|
|
43
43
|
}
|