Link class reference types exported in same package to their declaration
This commit is contained in:
@@ -30,8 +30,8 @@ import {
|
||||
import { Badge } from './badge';
|
||||
import { Comment } from './comment';
|
||||
import { EventDefinition } from './event_definition';
|
||||
import { SignatureBlock } from './signature_block';
|
||||
import { PropertyBlock } from './property_block';
|
||||
import { SignatureBlock } from './signature_block';
|
||||
import { TypeDefinition } from './type_definition';
|
||||
|
||||
const networkNameToColor: { [network: string]: string } = {
|
||||
@@ -225,6 +225,7 @@ export class Documentation extends React.Component<DocumentationProps, Documenta
|
||||
customType={customType}
|
||||
docsInfo={this.props.docsInfo}
|
||||
typeDefinitionByName={typeDefinitionByName}
|
||||
isInPopover={false}
|
||||
/>
|
||||
);
|
||||
});
|
||||
|
@@ -53,7 +53,12 @@ export class EventDefinition extends React.Component<EventDefinitionProps, Event
|
||||
const indexed = <span style={{ color: colors.green }}> indexed</span>;
|
||||
const eventArgs = _.map(this.props.event.eventArgs, (eventArg: EventArg) => {
|
||||
const type = (
|
||||
<Type type={eventArg.type} sectionName={this.props.sectionName} docsInfo={this.props.docsInfo} />
|
||||
<Type
|
||||
type={eventArg.type}
|
||||
sectionName={this.props.sectionName}
|
||||
docsInfo={this.props.docsInfo}
|
||||
isInPopover={false}
|
||||
/>
|
||||
);
|
||||
return (
|
||||
<span key={`eventArg-${eventArg.name}`}>
|
||||
|
@@ -7,14 +7,17 @@ import { CustomType, TypeDefinitionByName } from '../types';
|
||||
import { Signature } from './signature';
|
||||
import { Type } from './type';
|
||||
|
||||
const defaultProps = {};
|
||||
|
||||
export interface InterfaceProps {
|
||||
type: CustomType;
|
||||
sectionName: string;
|
||||
docsInfo: DocsInfo;
|
||||
typeDefinitionByName: TypeDefinitionByName;
|
||||
isInPopover: boolean;
|
||||
}
|
||||
|
||||
export const Interface = (props: InterfaceProps) => {
|
||||
export const Interface: React.SFC<InterfaceProps> = (props: InterfaceProps): any => {
|
||||
const type = props.type;
|
||||
const properties = _.map(type.children, property => {
|
||||
return (
|
||||
@@ -31,6 +34,7 @@ export const Interface = (props: InterfaceProps) => {
|
||||
shouldUseArrowSyntax={true}
|
||||
docsInfo={props.docsInfo}
|
||||
typeDefinitionByName={props.typeDefinitionByName}
|
||||
isInPopover={props.isInPopover}
|
||||
/>
|
||||
) : (
|
||||
<Type
|
||||
@@ -38,6 +42,7 @@ export const Interface = (props: InterfaceProps) => {
|
||||
sectionName={props.sectionName}
|
||||
docsInfo={props.docsInfo}
|
||||
typeDefinitionByName={props.typeDefinitionByName}
|
||||
isInPopover={props.isInPopover}
|
||||
/>
|
||||
)},
|
||||
</span>
|
||||
@@ -54,6 +59,7 @@ export const Interface = (props: InterfaceProps) => {
|
||||
sectionName={props.sectionName}
|
||||
docsInfo={props.docsInfo}
|
||||
typeDefinitionByName={props.typeDefinitionByName}
|
||||
isInPopover={props.isInPopover}
|
||||
/>
|
||||
</span>
|
||||
);
|
||||
@@ -77,3 +83,5 @@ export const Interface = (props: InterfaceProps) => {
|
||||
</span>
|
||||
);
|
||||
};
|
||||
|
||||
Interface.defaultProps = defaultProps;
|
||||
|
@@ -6,8 +6,8 @@ import { Property, TypeDefinitionByName } from '../types';
|
||||
import { constants } from '../utils/constants';
|
||||
|
||||
import { Comment } from './comment';
|
||||
import { Type } from './type';
|
||||
import { SourceLink } from './source_link';
|
||||
import { Type } from './type';
|
||||
|
||||
export interface PropertyBlockProps {
|
||||
property: Property;
|
||||
@@ -56,6 +56,7 @@ export class PropertyBlock extends React.Component<PropertyBlockProps, PropertyB
|
||||
sectionName={sectionName}
|
||||
docsInfo={this.props.docsInfo}
|
||||
typeDefinitionByName={this.props.typeDefinitionByName}
|
||||
isInPopover={false}
|
||||
/>
|
||||
</code>
|
||||
{property.source && (
|
||||
|
@@ -17,6 +17,7 @@ export interface SignatureProps {
|
||||
typeParameter?: TypeParameter;
|
||||
callPath?: string;
|
||||
docsInfo: DocsInfo;
|
||||
isInPopover: boolean;
|
||||
}
|
||||
|
||||
const defaultProps = {
|
||||
@@ -27,7 +28,13 @@ const defaultProps = {
|
||||
|
||||
export const Signature: React.SFC<SignatureProps> = (props: SignatureProps) => {
|
||||
const sectionName = props.sectionName;
|
||||
const parameters = renderParameters(props.parameters, props.docsInfo, sectionName, props.typeDefinitionByName);
|
||||
const parameters = renderParameters(
|
||||
props.parameters,
|
||||
props.docsInfo,
|
||||
sectionName,
|
||||
props.isInPopover,
|
||||
props.typeDefinitionByName,
|
||||
);
|
||||
const paramStringArray: any[] = [];
|
||||
// HACK: For now we don't put params on newlines if there are less then 2 of them.
|
||||
// Ideally we would check the character length of the resulting method signature and
|
||||
@@ -57,7 +64,13 @@ export const Signature: React.SFC<SignatureProps> = (props: SignatureProps) => {
|
||||
const methodName = props.shouldHideMethodName ? '' : props.name;
|
||||
const typeParameterIfExists = _.isUndefined(props.typeParameter)
|
||||
? undefined
|
||||
: renderTypeParameter(props.typeParameter, props.docsInfo, sectionName, props.typeDefinitionByName);
|
||||
: renderTypeParameter(
|
||||
props.typeParameter,
|
||||
props.docsInfo,
|
||||
sectionName,
|
||||
props.isInPopover,
|
||||
props.typeDefinitionByName,
|
||||
);
|
||||
return (
|
||||
<span style={{ fontSize: 15 }}>
|
||||
{props.callPath}
|
||||
@@ -72,6 +85,7 @@ export const Signature: React.SFC<SignatureProps> = (props: SignatureProps) => {
|
||||
sectionName={sectionName}
|
||||
typeDefinitionByName={props.typeDefinitionByName}
|
||||
docsInfo={props.docsInfo}
|
||||
isInPopover={props.isInPopover}
|
||||
/>
|
||||
</span>
|
||||
)}
|
||||
@@ -85,6 +99,7 @@ function renderParameters(
|
||||
parameters: Parameter[],
|
||||
docsInfo: DocsInfo,
|
||||
sectionName: string,
|
||||
isInPopover: boolean,
|
||||
typeDefinitionByName?: TypeDefinitionByName,
|
||||
): React.ReactNode[] {
|
||||
const params = _.map(parameters, (p: Parameter) => {
|
||||
@@ -96,6 +111,7 @@ function renderParameters(
|
||||
sectionName={sectionName}
|
||||
typeDefinitionByName={typeDefinitionByName}
|
||||
docsInfo={docsInfo}
|
||||
isInPopover={isInPopover}
|
||||
/>
|
||||
);
|
||||
return (
|
||||
@@ -113,6 +129,7 @@ function renderTypeParameter(
|
||||
typeParameter: TypeParameter,
|
||||
docsInfo: DocsInfo,
|
||||
sectionName: string,
|
||||
isInPopover: boolean,
|
||||
typeDefinitionByName?: TypeDefinitionByName,
|
||||
): React.ReactNode {
|
||||
const typeParam = (
|
||||
@@ -123,6 +140,7 @@ function renderTypeParameter(
|
||||
sectionName={sectionName}
|
||||
typeDefinitionByName={typeDefinitionByName}
|
||||
docsInfo={docsInfo}
|
||||
isInPopover={isInPopover}
|
||||
/>
|
||||
{`>`}
|
||||
</span>
|
||||
|
@@ -81,6 +81,7 @@ export class SignatureBlock extends React.Component<SignatureBlockProps, Signatu
|
||||
sectionName={this.props.sectionName}
|
||||
typeDefinitionByName={this.props.typeDefinitionByName}
|
||||
docsInfo={this.props.docsInfo}
|
||||
isInPopover={false}
|
||||
/>
|
||||
</code>
|
||||
{(method as TypescriptMethod).source && (
|
||||
|
@@ -7,23 +7,26 @@ import * as ReactTooltip from 'react-tooltip';
|
||||
|
||||
import { DocsInfo } from '../docs_info';
|
||||
import { Type as TypeDef, TypeDefinitionByName, TypeDocTypes } from '../types';
|
||||
import { constants } from '../utils/constants';
|
||||
|
||||
import { Signature } from './signature';
|
||||
import { constants } from '../utils/constants';
|
||||
import { TypeDefinition } from './type_definition';
|
||||
|
||||
const basicJsTypes = ['string', 'number', 'undefined', 'null', 'boolean'];
|
||||
|
||||
const defaultProps = {};
|
||||
|
||||
export interface TypeProps {
|
||||
type: TypeDef;
|
||||
docsInfo: DocsInfo;
|
||||
sectionName: string;
|
||||
typeDefinitionByName?: TypeDefinitionByName;
|
||||
isInPopover: boolean;
|
||||
}
|
||||
|
||||
// The return type needs to be `any` here so that we can recursively define <Type /> components within
|
||||
// <Type /> components (e.g when rendering the union type).
|
||||
export function Type(props: TypeProps): any {
|
||||
export const Type: React.SFC<TypeProps> = (props: TypeProps): any => {
|
||||
const type = props.type;
|
||||
const isReference = type.typeDocType === TypeDocTypes.Reference;
|
||||
const isArray = type.typeDocType === TypeDocTypes.Array;
|
||||
@@ -50,6 +53,7 @@ export function Type(props: TypeProps): any {
|
||||
sectionName={props.sectionName}
|
||||
typeDefinitionByName={props.typeDefinitionByName}
|
||||
docsInfo={props.docsInfo}
|
||||
isInPopover={props.isInPopover}
|
||||
/>[]
|
||||
</span>
|
||||
);
|
||||
@@ -61,6 +65,7 @@ export function Type(props: TypeProps): any {
|
||||
sectionName={props.sectionName}
|
||||
typeDefinitionByName={props.typeDefinitionByName}
|
||||
docsInfo={props.docsInfo}
|
||||
isInPopover={props.isInPopover}
|
||||
/>
|
||||
);
|
||||
return subType;
|
||||
@@ -89,6 +94,7 @@ export function Type(props: TypeProps): any {
|
||||
sectionName={props.sectionName}
|
||||
typeDefinitionByName={props.typeDefinitionByName}
|
||||
docsInfo={props.docsInfo}
|
||||
isInPopover={props.isInPopover}
|
||||
/>
|
||||
);
|
||||
});
|
||||
@@ -110,6 +116,7 @@ export function Type(props: TypeProps): any {
|
||||
shouldUseArrowSyntax={true}
|
||||
docsInfo={props.docsInfo}
|
||||
typeDefinitionByName={props.typeDefinitionByName}
|
||||
isInPopover={props.isInPopover}
|
||||
/>
|
||||
);
|
||||
} else if (!_.isUndefined(type.indexSignature)) {
|
||||
@@ -122,6 +129,7 @@ export function Type(props: TypeProps): any {
|
||||
sectionName={props.sectionName}
|
||||
docsInfo={props.docsInfo}
|
||||
typeDefinitionByName={props.typeDefinitionByName}
|
||||
isInPopover={props.isInPopover}
|
||||
/>
|
||||
</span>
|
||||
);
|
||||
@@ -150,6 +158,7 @@ export function Type(props: TypeProps): any {
|
||||
sectionName={props.sectionName}
|
||||
typeDefinitionByName={props.typeDefinitionByName}
|
||||
docsInfo={props.docsInfo}
|
||||
isInPopover={props.isInPopover}
|
||||
/>
|
||||
);
|
||||
});
|
||||
@@ -180,6 +189,7 @@ export function Type(props: TypeProps): any {
|
||||
? props.docsInfo.typeConfigs.typeNameToPrefix[typeName as string]
|
||||
: undefined;
|
||||
}
|
||||
const isExportedClassReference = !!props.type.isExportedClassReference;
|
||||
if (!_.isUndefined(typeNameUrlIfExists)) {
|
||||
typeName = (
|
||||
<a
|
||||
@@ -194,12 +204,12 @@ export function Type(props: TypeProps): any {
|
||||
);
|
||||
} else if (
|
||||
(isReference || isArray) &&
|
||||
props.typeDefinitionByName &&
|
||||
props.typeDefinitionByName[typeName as string]
|
||||
((props.typeDefinitionByName && props.typeDefinitionByName[typeName as string]) || isExportedClassReference)
|
||||
) {
|
||||
const id = Math.random().toString();
|
||||
const typeDefinitionAnchorId = `${constants.TYPES_SECTION_NAME}-${typeName}`;
|
||||
let typeDefinition = props.typeDefinitionByName[typeName as string];
|
||||
const typeDefinitionAnchorId = isExportedClassReference
|
||||
? props.type.name
|
||||
: `${constants.TYPES_SECTION_NAME}-${typeName}`;
|
||||
typeName = (
|
||||
<ScrollLink
|
||||
to={typeDefinitionAnchorId}
|
||||
@@ -208,7 +218,7 @@ export function Type(props: TypeProps): any {
|
||||
duration={sharedConstants.DOCS_SCROLL_DURATION_MS}
|
||||
containerId={sharedConstants.DOCS_CONTAINER_ID}
|
||||
>
|
||||
{sharedUtils.isUserOnMobile() ? (
|
||||
{sharedUtils.isUserOnMobile() || props.isInPopover || isExportedClassReference ? (
|
||||
<span style={{ color: colors.lightBlueA700, cursor: 'pointer' }}>{typeName}</span>
|
||||
) : (
|
||||
<span
|
||||
@@ -224,10 +234,11 @@ export function Type(props: TypeProps): any {
|
||||
<ReactTooltip type="light" effect="solid" id={id} className="typeTooltip">
|
||||
<TypeDefinition
|
||||
sectionName={props.sectionName}
|
||||
customType={typeDefinition}
|
||||
customType={props.typeDefinitionByName[typeName as string]}
|
||||
shouldAddId={false}
|
||||
docsInfo={props.docsInfo}
|
||||
typeDefinitionByName={props.typeDefinitionByName}
|
||||
isInPopover={true}
|
||||
/>
|
||||
</ReactTooltip>
|
||||
</span>
|
||||
@@ -248,4 +259,6 @@ export function Type(props: TypeProps): any {
|
||||
)}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
Type.defaultProps = defaultProps;
|
||||
|
@@ -4,7 +4,7 @@ import * as _ from 'lodash';
|
||||
import * as React from 'react';
|
||||
|
||||
import { DocsInfo } from '../docs_info';
|
||||
import { CustomType, CustomTypeChild, KindString, TypeDocTypes, TypeDefinitionByName } from '../types';
|
||||
import { CustomType, CustomTypeChild, KindString, TypeDefinitionByName, TypeDocTypes } from '../types';
|
||||
import { constants } from '../utils/constants';
|
||||
|
||||
import { Comment } from './comment';
|
||||
@@ -20,6 +20,7 @@ export interface TypeDefinitionProps {
|
||||
shouldAddId?: boolean;
|
||||
docsInfo: DocsInfo;
|
||||
typeDefinitionByName?: TypeDefinitionByName;
|
||||
isInPopover?: boolean;
|
||||
}
|
||||
|
||||
export interface TypeDefinitionState {
|
||||
@@ -29,6 +30,7 @@ export interface TypeDefinitionState {
|
||||
export class TypeDefinition extends React.Component<TypeDefinitionProps, TypeDefinitionState> {
|
||||
public static defaultProps: Partial<TypeDefinitionProps> = {
|
||||
shouldAddId: true,
|
||||
isInPopover: false,
|
||||
};
|
||||
constructor(props: TypeDefinitionProps) {
|
||||
super(props);
|
||||
@@ -50,6 +52,7 @@ export class TypeDefinition extends React.Component<TypeDefinitionProps, TypeDef
|
||||
sectionName={this.props.sectionName}
|
||||
docsInfo={this.props.docsInfo}
|
||||
typeDefinitionByName={this.props.typeDefinitionByName}
|
||||
isInPopover={this.props.isInPopover}
|
||||
/>
|
||||
);
|
||||
break;
|
||||
@@ -81,6 +84,7 @@ export class TypeDefinition extends React.Component<TypeDefinitionProps, TypeDef
|
||||
sectionName={this.props.sectionName}
|
||||
docsInfo={this.props.docsInfo}
|
||||
typeDefinitionByName={this.props.typeDefinitionByName}
|
||||
isInPopover={this.props.isInPopover}
|
||||
/>
|
||||
) : (
|
||||
<Signature
|
||||
@@ -94,6 +98,7 @@ export class TypeDefinition extends React.Component<TypeDefinitionProps, TypeDef
|
||||
shouldUseArrowSyntax={true}
|
||||
docsInfo={this.props.docsInfo}
|
||||
typeDefinitionByName={this.props.typeDefinitionByName}
|
||||
isInPopover={this.props.isInPopover}
|
||||
/>
|
||||
)}
|
||||
</span>
|
||||
|
@@ -154,6 +154,7 @@ export interface Type {
|
||||
name: string;
|
||||
typeDocType: TypeDocTypes;
|
||||
value?: string;
|
||||
isExportedClassReference?: boolean;
|
||||
typeArguments?: Type[];
|
||||
elementType?: ElementType;
|
||||
types?: Type[];
|
||||
|
@@ -7,6 +7,7 @@ import {
|
||||
CustomTypeChild,
|
||||
DocAgnosticFormat,
|
||||
DocSection,
|
||||
GeneratedDocJson,
|
||||
IndexSignature,
|
||||
KindString,
|
||||
Parameter,
|
||||
@@ -19,7 +20,6 @@ import {
|
||||
TypeParameter,
|
||||
TypescriptFunction,
|
||||
TypescriptMethod,
|
||||
GeneratedDocJson,
|
||||
} from '../types';
|
||||
|
||||
import { constants } from './constants';
|
||||
@@ -72,6 +72,15 @@ export const typeDocUtils = {
|
||||
),
|
||||
);
|
||||
|
||||
const classNames: string[] = [];
|
||||
_.each(typeDocJson.children, file => {
|
||||
_.each(file.children, child => {
|
||||
if (child.kindString === KindString.Class) {
|
||||
classNames.push(child.name);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
const docAgnosticFormat: DocAgnosticFormat = {};
|
||||
const typeEntities: TypeDocNode[] = [];
|
||||
_.each(typeDocNameOrder, typeDocName => {
|
||||
@@ -93,6 +102,7 @@ export const typeDocUtils = {
|
||||
entities,
|
||||
docsInfo,
|
||||
sectionName,
|
||||
classNames,
|
||||
isClassOrObjectLiteral,
|
||||
);
|
||||
docSection.comment = sectionComment;
|
||||
@@ -106,7 +116,12 @@ export const typeDocUtils = {
|
||||
const entities = [child];
|
||||
const commentObj = child.comment;
|
||||
const SectionComment = !_.isUndefined(commentObj) ? commentObj.shortText : '';
|
||||
const docSection = typeDocUtils._convertEntitiesToDocSection(entities, docsInfo, sectionName);
|
||||
const docSection = typeDocUtils._convertEntitiesToDocSection(
|
||||
entities,
|
||||
docsInfo,
|
||||
sectionName,
|
||||
classNames,
|
||||
);
|
||||
docSection.comment = SectionComment;
|
||||
docAgnosticFormat[sectionName] = docSection;
|
||||
break;
|
||||
@@ -129,6 +144,7 @@ export const typeDocUtils = {
|
||||
typeEntities,
|
||||
docsInfo,
|
||||
constants.TYPES_SECTION_NAME,
|
||||
classNames,
|
||||
);
|
||||
docAgnosticFormat[constants.TYPES_SECTION_NAME] = docSection;
|
||||
}
|
||||
@@ -139,6 +155,7 @@ export const typeDocUtils = {
|
||||
entities: TypeDocNode[],
|
||||
docsInfo: DocsInfo,
|
||||
sectionName: string,
|
||||
classNames: string[],
|
||||
isClassOrObjectLiteral: boolean = false,
|
||||
): DocSection {
|
||||
const docSection: DocSection = {
|
||||
@@ -161,6 +178,7 @@ export const typeDocUtils = {
|
||||
docsInfo.sections,
|
||||
sectionName,
|
||||
docsInfo.id,
|
||||
classNames,
|
||||
);
|
||||
docSection.constructors.push(constructor);
|
||||
break;
|
||||
@@ -176,6 +194,7 @@ export const typeDocUtils = {
|
||||
sectionName,
|
||||
docsInfo.id,
|
||||
isClassOrObjectLiteral,
|
||||
classNames,
|
||||
);
|
||||
docSection.functions.push(func);
|
||||
}
|
||||
@@ -191,6 +210,7 @@ export const typeDocUtils = {
|
||||
docsInfo.sections,
|
||||
sectionName,
|
||||
docsInfo.id,
|
||||
classNames,
|
||||
);
|
||||
docSection.methods.push(method);
|
||||
}
|
||||
@@ -203,6 +223,7 @@ export const typeDocUtils = {
|
||||
docsInfo.sections,
|
||||
sectionName,
|
||||
docsInfo.id,
|
||||
classNames,
|
||||
);
|
||||
docSection.properties.push(property);
|
||||
}
|
||||
@@ -216,6 +237,7 @@ export const typeDocUtils = {
|
||||
docsInfo.sections,
|
||||
sectionName,
|
||||
docsInfo.id,
|
||||
classNames,
|
||||
);
|
||||
docSection.properties.push(property);
|
||||
} else {
|
||||
@@ -225,6 +247,7 @@ export const typeDocUtils = {
|
||||
docsInfo.sections,
|
||||
sectionName,
|
||||
docsInfo.id,
|
||||
classNames,
|
||||
);
|
||||
const seenTypeNames = _.map(docSection.types, t => t.name);
|
||||
const isUnseen = !_.includes(seenTypeNames, customType.name);
|
||||
@@ -235,14 +258,14 @@ export const typeDocUtils = {
|
||||
break;
|
||||
|
||||
case KindString.Interface:
|
||||
case KindString.Variable:
|
||||
case KindString.Enumeration:
|
||||
case KindString.TypeAlias:
|
||||
case KindString.TypeAlias: {
|
||||
const customType = typeDocUtils._convertCustomType(
|
||||
entity,
|
||||
docsInfo.sections,
|
||||
sectionName,
|
||||
docsInfo.id,
|
||||
classNames,
|
||||
);
|
||||
const seenTypeNames = _.map(docSection.types, t => t.name);
|
||||
const isUnseen = !_.includes(seenTypeNames, customType.name);
|
||||
@@ -250,6 +273,7 @@ export const typeDocUtils = {
|
||||
docSection.types.push(customType);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case KindString.Class:
|
||||
// We currently do not support more then a single class per file
|
||||
@@ -263,18 +287,24 @@ export const typeDocUtils = {
|
||||
});
|
||||
return docSection;
|
||||
},
|
||||
_convertCustomType(entity: TypeDocNode, sections: SectionsMap, sectionName: string, docId: string): CustomType {
|
||||
_convertCustomType(
|
||||
entity: TypeDocNode,
|
||||
sections: SectionsMap,
|
||||
sectionName: string,
|
||||
docId: string,
|
||||
classNames: string[],
|
||||
): CustomType {
|
||||
const typeIfExists = !_.isUndefined(entity.type)
|
||||
? typeDocUtils._convertType(entity.type, sections, sectionName, docId)
|
||||
? typeDocUtils._convertType(entity.type, sections, sectionName, docId, classNames)
|
||||
: undefined;
|
||||
const isConstructor = false;
|
||||
const methodIfExists = !_.isUndefined(entity.declaration)
|
||||
? typeDocUtils._convertMethod(entity.declaration, isConstructor, sections, sectionName, docId)
|
||||
? typeDocUtils._convertMethod(entity.declaration, isConstructor, sections, sectionName, docId, classNames)
|
||||
: undefined;
|
||||
const doesIndexSignatureExist = !_.isUndefined(entity.indexSignature);
|
||||
const indexSignature = entity.indexSignature as TypeDocNode;
|
||||
const indexSignatureIfExists = doesIndexSignatureExist
|
||||
? typeDocUtils._convertIndexSignature(indexSignature, sections, sectionName, docId)
|
||||
? typeDocUtils._convertIndexSignature(indexSignature, sections, sectionName, docId, classNames)
|
||||
: undefined;
|
||||
const commentIfExists =
|
||||
!_.isUndefined(entity.comment) && !_.isUndefined(entity.comment.shortText)
|
||||
@@ -284,13 +314,20 @@ export const typeDocUtils = {
|
||||
const childrenIfExist = !_.isUndefined(entity.children)
|
||||
? _.map(entity.children, (child: TypeDocNode) => {
|
||||
let childTypeIfExists = !_.isUndefined(child.type)
|
||||
? typeDocUtils._convertType(child.type, sections, sectionName, docId)
|
||||
? typeDocUtils._convertType(child.type, sections, sectionName, docId, classNames)
|
||||
: undefined;
|
||||
if (child.kindString === KindString.Method) {
|
||||
childTypeIfExists = {
|
||||
name: child.name,
|
||||
typeDocType: TypeDocTypes.Reflection,
|
||||
method: typeDocUtils._convertMethod(child, isConstructor, sections, sectionName, docId),
|
||||
method: typeDocUtils._convertMethod(
|
||||
child,
|
||||
isConstructor,
|
||||
sections,
|
||||
sectionName,
|
||||
docId,
|
||||
classNames,
|
||||
),
|
||||
};
|
||||
}
|
||||
const c: CustomTypeChild = {
|
||||
@@ -319,16 +356,23 @@ export const typeDocUtils = {
|
||||
sections: SectionsMap,
|
||||
sectionName: string,
|
||||
docId: string,
|
||||
classNames: string[],
|
||||
): IndexSignature {
|
||||
const key = entity.parameters[0];
|
||||
const indexSignature = {
|
||||
keyName: key.name,
|
||||
keyType: typeDocUtils._convertType(key.type, sections, sectionName, docId),
|
||||
keyType: typeDocUtils._convertType(key.type, sections, sectionName, docId, classNames),
|
||||
valueName: entity.type.name,
|
||||
};
|
||||
return indexSignature;
|
||||
},
|
||||
_convertProperty(entity: TypeDocNode, sections: SectionsMap, sectionName: string, docId: string): Property {
|
||||
_convertProperty(
|
||||
entity: TypeDocNode,
|
||||
sections: SectionsMap,
|
||||
sectionName: string,
|
||||
docId: string,
|
||||
classNames: string[],
|
||||
): Property {
|
||||
const source = entity.sources[0];
|
||||
const commentIfExists = !_.isUndefined(entity.comment) ? entity.comment.shortText : undefined;
|
||||
const isConstructor = false;
|
||||
@@ -336,7 +380,7 @@ export const typeDocUtils = {
|
||||
const callPath = typeDocUtils._getCallPath(sectionName, isStatic, isConstructor, entity.name);
|
||||
const property = {
|
||||
name: entity.name,
|
||||
type: typeDocUtils._convertType(entity.type, sections, sectionName, docId),
|
||||
type: typeDocUtils._convertType(entity.type, sections, sectionName, docId, classNames),
|
||||
source: {
|
||||
fileName: source.fileName,
|
||||
line: source.line,
|
||||
@@ -352,6 +396,7 @@ export const typeDocUtils = {
|
||||
sections: SectionsMap,
|
||||
sectionName: string,
|
||||
docId: string,
|
||||
classNames: string[],
|
||||
): TypescriptMethod {
|
||||
const signature = entity.signatures[0];
|
||||
const source = entity.sources[0];
|
||||
@@ -359,12 +404,12 @@ export const typeDocUtils = {
|
||||
const isStatic = _.isUndefined(entity.flags.isStatic) ? false : entity.flags.isStatic;
|
||||
|
||||
const parameters = _.map(signature.parameters, param => {
|
||||
return typeDocUtils._convertParameter(param, sections, sectionName, docId);
|
||||
return typeDocUtils._convertParameter(param, sections, sectionName, docId, classNames);
|
||||
});
|
||||
const returnType = typeDocUtils._convertType(signature.type, sections, sectionName, docId);
|
||||
const returnType = typeDocUtils._convertType(signature.type, sections, sectionName, docId, classNames);
|
||||
const typeParameter = _.isUndefined(signature.typeParameter)
|
||||
? undefined
|
||||
: typeDocUtils._convertTypeParameter(signature.typeParameter[0], sections, sectionName, docId);
|
||||
: typeDocUtils._convertTypeParameter(signature.typeParameter[0], sections, sectionName, docId, classNames);
|
||||
|
||||
const callPath = typeDocUtils._getCallPath(sectionName, isStatic, isConstructor, entity.name);
|
||||
const method = {
|
||||
@@ -384,13 +429,12 @@ export const typeDocUtils = {
|
||||
};
|
||||
return method;
|
||||
},
|
||||
_getCallPath(sectionName: string, isStatic: boolean, isConstructor: boolean, entityName: string) {
|
||||
_getCallPath(sectionName: string, isStatic: boolean, isConstructor: boolean, entityName: string): string {
|
||||
// HACK: we use the fact that the sectionName is the same as the property name at the top-level
|
||||
// of the public interface. In the future, we shouldn't use this hack but rather get it from the JSON.
|
||||
let callPath;
|
||||
if (isConstructor || entityName === '__type') {
|
||||
callPath = '';
|
||||
// TODO: Get rid of this 0x-specific logic
|
||||
} else {
|
||||
const prefix = isStatic ? sectionName : `${sectionName[0].toLowerCase()}${sectionName.slice(1)}`;
|
||||
callPath = `${prefix}.`;
|
||||
@@ -403,18 +447,19 @@ export const typeDocUtils = {
|
||||
sectionName: string,
|
||||
docId: string,
|
||||
isObjectLiteral: boolean,
|
||||
classNames: 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);
|
||||
return typeDocUtils._convertParameter(param, sections, sectionName, docId, classNames);
|
||||
});
|
||||
const returnType = typeDocUtils._convertType(signature.type, sections, sectionName, docId);
|
||||
const returnType = typeDocUtils._convertType(signature.type, sections, sectionName, docId, classNames);
|
||||
const typeParameter = _.isUndefined(signature.typeParameter)
|
||||
? undefined
|
||||
: typeDocUtils._convertTypeParameter(signature.typeParameter[0], sections, sectionName, docId);
|
||||
: typeDocUtils._convertTypeParameter(signature.typeParameter[0], sections, sectionName, docId, classNames);
|
||||
|
||||
let callPath = '';
|
||||
if (isObjectLiteral) {
|
||||
@@ -442,15 +487,22 @@ export const typeDocUtils = {
|
||||
sections: SectionsMap,
|
||||
sectionName: string,
|
||||
docId: string,
|
||||
classNames: string[],
|
||||
): TypeParameter {
|
||||
const type = typeDocUtils._convertType(entity.type, sections, sectionName, docId);
|
||||
const type = typeDocUtils._convertType(entity.type, sections, sectionName, docId, classNames);
|
||||
const parameter = {
|
||||
name: entity.name,
|
||||
type,
|
||||
};
|
||||
return parameter;
|
||||
},
|
||||
_convertParameter(entity: TypeDocNode, sections: SectionsMap, sectionName: string, docId: string): Parameter {
|
||||
_convertParameter(
|
||||
entity: TypeDocNode,
|
||||
sections: SectionsMap,
|
||||
sectionName: string,
|
||||
docId: string,
|
||||
classNames: string[],
|
||||
): Parameter {
|
||||
let comment = '<No comment>';
|
||||
if (entity.comment && entity.comment.shortText) {
|
||||
comment = entity.comment.shortText;
|
||||
@@ -460,7 +512,7 @@ export const typeDocUtils = {
|
||||
|
||||
const isOptional = !_.isUndefined(entity.flags.isOptional) ? entity.flags.isOptional : false;
|
||||
|
||||
const type = typeDocUtils._convertType(entity.type, sections, sectionName, docId);
|
||||
const type = typeDocUtils._convertType(entity.type, sections, sectionName, docId, classNames);
|
||||
|
||||
const parameter = {
|
||||
name: entity.name,
|
||||
@@ -471,12 +523,18 @@ export const typeDocUtils = {
|
||||
};
|
||||
return parameter;
|
||||
},
|
||||
_convertType(entity: TypeDocType, sections: SectionsMap, sectionName: string, docId: string): Type {
|
||||
_convertType(
|
||||
entity: TypeDocType,
|
||||
sections: SectionsMap,
|
||||
sectionName: string,
|
||||
docId: string,
|
||||
classNames: string[],
|
||||
): Type {
|
||||
const typeArguments = _.map(entity.typeArguments, typeArgument => {
|
||||
return typeDocUtils._convertType(typeArgument, sections, sectionName, docId);
|
||||
return typeDocUtils._convertType(typeArgument, sections, sectionName, docId, classNames);
|
||||
});
|
||||
const types = _.map(entity.types, t => {
|
||||
return typeDocUtils._convertType(t, sections, sectionName, docId);
|
||||
return typeDocUtils._convertType(t, sections, sectionName, docId, classNames);
|
||||
});
|
||||
|
||||
let indexSignatureIfExists;
|
||||
@@ -485,7 +543,13 @@ export const typeDocUtils = {
|
||||
!_.isUndefined(entity.declaration) && !_.isUndefined(entity.declaration.indexSignature);
|
||||
if (doesIndexSignatureExist) {
|
||||
const indexSignature = entity.declaration.indexSignature as TypeDocNode;
|
||||
indexSignatureIfExists = typeDocUtils._convertIndexSignature(indexSignature, sections, sectionName, docId);
|
||||
indexSignatureIfExists = typeDocUtils._convertIndexSignature(
|
||||
indexSignature,
|
||||
sections,
|
||||
sectionName,
|
||||
docId,
|
||||
classNames,
|
||||
);
|
||||
} else if (!_.isUndefined(entity.declaration)) {
|
||||
const isConstructor = false;
|
||||
methodIfExists = typeDocUtils._convertMethod(
|
||||
@@ -494,6 +558,7 @@ export const typeDocUtils = {
|
||||
sections,
|
||||
sectionName,
|
||||
docId,
|
||||
classNames,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -507,6 +572,7 @@ export const typeDocUtils = {
|
||||
const type = {
|
||||
name: entity.name,
|
||||
value: entity.value,
|
||||
isExportedClassReference: _.includes(classNames, entity.name),
|
||||
typeDocType: entity.type,
|
||||
typeArguments,
|
||||
elementType: elementTypeIfExists,
|
||||
|
Reference in New Issue
Block a user