@wordpress/docgen 1.20.2 → 1.21.0
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/lib/get-type-annotation.js +51 -1
- package/package.json +2 -2
|
@@ -373,6 +373,56 @@ function getTypeAnnotation( typeAnnotation ) {
|
|
|
373
373
|
}
|
|
374
374
|
}
|
|
375
375
|
|
|
376
|
+
/**
|
|
377
|
+
* Extract wrapped selector functions to reach inside for parameter types.
|
|
378
|
+
*
|
|
379
|
+
* This function wasn't necessary until we started introducing more TypeScript code into
|
|
380
|
+
* the project. With parameter types fully in the JSDoc comments we always have a direct
|
|
381
|
+
* match between parameter name and the type. However, when working in TypeScript where
|
|
382
|
+
* we rely on the type annotations for the types we introduce a mismatch when wrapping
|
|
383
|
+
* functions.
|
|
384
|
+
*
|
|
385
|
+
* Example:
|
|
386
|
+
* export const getThings = createSelector( ( state ) => state.things, ( state ) => state.version );
|
|
387
|
+
*
|
|
388
|
+
* In this example we would document `state` but its type is buried inside of `createSelector`.
|
|
389
|
+
* Because this kind of scenario is tricky to properly parse without asking TypeScript directly
|
|
390
|
+
* to give us the actual type of `getThings` we're going to special-case the known instances
|
|
391
|
+
* of selector-wrapping to extract the inner function and re-connect the parameter types
|
|
392
|
+
* with their descriptions in the JSDoc comments.
|
|
393
|
+
*
|
|
394
|
+
* If we find more wrapper functions on selectors we should add them below following the
|
|
395
|
+
* example of `createSelector` and `createRegsitrySelector`.
|
|
396
|
+
*
|
|
397
|
+
* @param {ASTNode} token Contains either a function or a call to a function-wrapper.
|
|
398
|
+
*
|
|
399
|
+
* TODO: Remove the special-casing here once we're able to infer the types from TypeScript itself.
|
|
400
|
+
*/
|
|
401
|
+
function unwrapWrappedSelectors( token ) {
|
|
402
|
+
if ( babelTypes.isFunctionDeclaration( token ) ) {
|
|
403
|
+
return token;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
if ( babelTypes.isArrowFunctionExpression( token ) ) {
|
|
407
|
+
return token;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
if ( babelTypes.isCallExpression( token ) ) {
|
|
411
|
+
// createSelector( ( state, queryId ) => state.queries[ queryId ] );
|
|
412
|
+
// \--------------------------------------------/ CallExpression.arguments[0]
|
|
413
|
+
if ( token.callee.name === 'createSelector' ) {
|
|
414
|
+
return token.arguments[ 0 ];
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
// createRegistrySelector( ( selector ) => ( state, queryId ) => select( 'core/queries' ).get( queryId ) );
|
|
418
|
+
// \-----------------------------------------------------------/ CallExpression.arguments[0].body
|
|
419
|
+
// \---------------------------------------------------------------------------/ CallExpression.arguments[0]
|
|
420
|
+
if ( token.callee.name === 'createRegistrySelector' ) {
|
|
421
|
+
return token.arguments[ 0 ].body;
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
|
|
376
426
|
/**
|
|
377
427
|
* @param {ASTNode} token
|
|
378
428
|
* @return {babelTypes.ArrowFunctionExpression | babelTypes.FunctionDeclaration} The function token.
|
|
@@ -392,7 +442,7 @@ function getFunctionToken( token ) {
|
|
|
392
442
|
resolvedToken = resolvedToken.declarations[ 0 ].init;
|
|
393
443
|
}
|
|
394
444
|
|
|
395
|
-
return resolvedToken;
|
|
445
|
+
return unwrapWrappedSelectors( resolvedToken );
|
|
396
446
|
}
|
|
397
447
|
|
|
398
448
|
function getFunctionNameForError( declarationToken ) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/docgen",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.21.0",
|
|
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",
|
|
@@ -39,5 +39,5 @@
|
|
|
39
39
|
"publishConfig": {
|
|
40
40
|
"access": "public"
|
|
41
41
|
},
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "1ba52312b56db563df2d8d4fba5b00613fb46d8c"
|
|
43
43
|
}
|