aboutsummaryrefslogtreecommitdiffstats
path: root/packages/react-docs/src/utils
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2018-03-19 01:44:52 +0800
committerFabio Berger <me@fabioberger.com>2018-03-19 01:44:52 +0800
commit794b155827868d67f1cec45bbe8c3a3e4be02597 (patch)
tree8f46fb1fe23f0317b50f9d37e6fa8c671615c981 /packages/react-docs/src/utils
parent4941ffd354a7bbc4fb48cd66acd6db1e36d5ed87 (diff)
downloaddexon-sol-tools-794b155827868d67f1cec45bbe8c3a3e4be02597.tar
dexon-sol-tools-794b155827868d67f1cec45bbe8c3a3e4be02597.tar.gz
dexon-sol-tools-794b155827868d67f1cec45bbe8c3a3e4be02597.tar.bz2
dexon-sol-tools-794b155827868d67f1cec45bbe8c3a3e4be02597.tar.lz
dexon-sol-tools-794b155827868d67f1cec45bbe8c3a3e4be02597.tar.xz
dexon-sol-tools-794b155827868d67f1cec45bbe8c3a3e4be02597.tar.zst
dexon-sol-tools-794b155827868d67f1cec45bbe8c3a3e4be02597.zip
Add support for displaying exported functions
Diffstat (limited to 'packages/react-docs/src/utils')
-rw-r--r--packages/react-docs/src/utils/typedoc_utils.ts52
1 files changed, 46 insertions, 6 deletions
diff --git a/packages/react-docs/src/utils/typedoc_utils.ts b/packages/react-docs/src/utils/typedoc_utils.ts
index e4cea1e40..4c7617234 100644
--- a/packages/react-docs/src/utils/typedoc_utils.ts
+++ b/packages/react-docs/src/utils/typedoc_utils.ts
@@ -15,6 +15,7 @@ import {
TypeDocNode,
TypeDocType,
TypeParameter,
+ TypescriptFunction,
TypescriptMethod,
} from '../types';
import { utils } from '../utils/utils';
@@ -81,17 +82,16 @@ export const typeDocUtils = {
}
}
- // Since the `types.ts` file is the only file that does not export a module/class but
- // instead has each type export itself, we do not need to go down two levels of nesting
- // for it.
let entities;
let packageComment = '';
- if (sectionName === docsInfo.sections.types) {
- entities = packageDefinitionWithMergedChildren.children;
- } else {
+ // HACK: We assume 1 exported class per file
+ const isClassExport = packageDefinitionWithMergedChildren.children[0].kindString === KindString.Class;
+ if (isClassExport) {
entities = packageDefinitionWithMergedChildren.children[0].children;
const commentObj = packageDefinitionWithMergedChildren.children[0].comment;
packageComment = !_.isUndefined(commentObj) ? commentObj.shortText : packageComment;
+ } else {
+ entities = packageDefinitionWithMergedChildren.children;
}
const docSection = typeDocUtils._convertEntitiesToDocSection(entities, docsInfo, sectionName);
@@ -105,6 +105,7 @@ export const typeDocUtils = {
comment: '',
constructors: [],
methods: [],
+ functions: [],
properties: [],
types: [],
};
@@ -124,6 +125,13 @@ export const typeDocUtils = {
docSection.constructors.push(constructor);
break;
+ case KindString.Function:
+ if (entity.flags.isExported) {
+ const func = typeDocUtils._convertFunction(entity, docsInfo.sections, sectionName, docsInfo.id);
+ docSection.functions.push(func);
+ }
+ break;
+
case KindString.Method:
if (entity.flags.isPublic) {
isConstructor = false;
@@ -303,6 +311,38 @@ export const typeDocUtils = {
};
return method;
},
+ _convertFunction(
+ entity: TypeDocNode,
+ sections: SectionsMap,
+ sectionName: string,
+ docId: string,
+ ): TypescriptFunction {
+ const signature = entity.signatures[0];
+ const source = entity.sources[0];
+ const hasComment = !_.isUndefined(signature.comment);
+
+ const parameters = _.map(signature.parameters, param => {
+ return typeDocUtils._convertParameter(param, sections, sectionName, docId);
+ });
+ const returnType = typeDocUtils._convertType(signature.type, sections, sectionName, docId);
+ const typeParameter = _.isUndefined(signature.typeParameter)
+ ? undefined
+ : typeDocUtils._convertTypeParameter(signature.typeParameter[0], sections, sectionName, docId);
+
+ const func = {
+ name: signature.name,
+ comment: hasComment ? signature.comment.shortText : undefined,
+ returnComment: hasComment && signature.comment.returns ? signature.comment.returns : undefined,
+ source: {
+ fileName: source.fileName,
+ line: source.line,
+ },
+ parameters,
+ returnType,
+ typeParameter,
+ };
+ return func;
+ },
_convertTypeParameter(
entity: TypeDocNode,
sections: SectionsMap,