Remove prefix hack and add prefix for objectLiteral functions

This commit is contained in:
Fabio Berger
2018-08-04 10:09:59 +02:00
parent 7759e67a5a
commit 4527e9ce00
2 changed files with 15 additions and 17 deletions

View File

@@ -124,6 +124,7 @@ export interface TypescriptMethod extends BaseMethod {
export interface TypescriptFunction extends BaseFunction { export interface TypescriptFunction extends BaseFunction {
source?: Source; source?: Source;
typeParameter?: TypeParameter; typeParameter?: TypeParameter;
callPath: string;
} }
export interface SolidityMethod extends BaseMethod { export interface SolidityMethod extends BaseMethod {

View File

@@ -173,6 +173,7 @@ export const typeDocUtils = {
docsInfo.sections, docsInfo.sections,
sectionName, sectionName,
docsInfo.id, docsInfo.id,
isClassOrObjectLiteral,
); );
docSection.functions.push(func); docSection.functions.push(func);
} }
@@ -331,7 +332,7 @@ export const typeDocUtils = {
const commentIfExists = !_.isUndefined(entity.comment) ? entity.comment.shortText : undefined; const commentIfExists = !_.isUndefined(entity.comment) ? entity.comment.shortText : undefined;
const isConstructor = false; const isConstructor = false;
const isStatic = _.isUndefined(entity.flags.isStatic) ? false : entity.flags.isStatic; const isStatic = _.isUndefined(entity.flags.isStatic) ? false : entity.flags.isStatic;
const callPath = typeDocUtils._getCallPath(sectionName, sections, isStatic, isConstructor, docId, entity.name); const callPath = typeDocUtils._getCallPath(sectionName, isStatic, isConstructor, entity.name);
const property = { const property = {
name: entity.name, name: entity.name,
type: typeDocUtils._convertType(entity.type, sections, sectionName, docId), type: typeDocUtils._convertType(entity.type, sections, sectionName, docId),
@@ -367,7 +368,7 @@ export const typeDocUtils = {
? undefined ? undefined
: typeDocUtils._convertTypeParameter(signature.typeParameter[0], sections, sectionName, docId); : typeDocUtils._convertTypeParameter(signature.typeParameter[0], sections, sectionName, docId);
const callPath = typeDocUtils._getCallPath(sectionName, sections, isStatic, isConstructor, docId, entity.name); const callPath = typeDocUtils._getCallPath(sectionName, isStatic, isConstructor, entity.name);
const method = { const method = {
isConstructor, isConstructor,
isStatic, isStatic,
@@ -385,28 +386,16 @@ export const typeDocUtils = {
}; };
return method; return method;
}, },
_getCallPath( _getCallPath(sectionName: string, isStatic: boolean, isConstructor: boolean, entityName: string) {
sectionName: string,
sections: SectionsMap,
isStatic: boolean,
isConstructor: boolean,
docId: string,
entityName: string,
) {
// HACK: we use the fact that the sectionName is the same as the property name at the top-level // 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. // of the public interface. In the future, we shouldn't use this hack but rather get it from the JSON.
let callPath; let callPath;
if (isConstructor || entityName === '__type') { if (isConstructor || entityName === '__type') {
callPath = ''; callPath = '';
// TODO: Get rid of this 0x-specific logic // TODO: Get rid of this 0x-specific logic
} else if (docId === 'ZERO_EX_JS') {
const topLevelInterface = isStatic ? 'ZeroEx.' : 'zeroEx.';
callPath =
!_.isUndefined(sections.zeroEx) && sectionName !== sections.zeroEx
? `${topLevelInterface}${sectionName}.`
: topLevelInterface;
} else { } else {
callPath = `${sectionName}.`; const prefix = isStatic ? sectionName : `${sectionName[0].toLowerCase()}${sectionName.slice(1)}`;
callPath = `${prefix}.`;
} }
return callPath; return callPath;
}, },
@@ -415,6 +404,7 @@ export const typeDocUtils = {
sections: SectionsMap, sections: SectionsMap,
sectionName: string, sectionName: string,
docId: string, docId: string,
isObjectLiteral: boolean,
): TypescriptFunction { ): TypescriptFunction {
const signature = entity.signatures[0]; const signature = entity.signatures[0];
const source = entity.sources[0]; const source = entity.sources[0];
@@ -428,10 +418,17 @@ export const typeDocUtils = {
? undefined ? undefined
: typeDocUtils._convertTypeParameter(signature.typeParameter[0], sections, sectionName, docId); : typeDocUtils._convertTypeParameter(signature.typeParameter[0], sections, sectionName, docId);
let callPath = '';
if (isObjectLiteral) {
const isConstructor = false;
const isStatic = false;
callPath = typeDocUtils._getCallPath(sectionName, isStatic, isConstructor, entity.name);
}
const func = { const func = {
name: signature.name, name: signature.name,
comment: hasComment ? signature.comment.shortText : undefined, comment: hasComment ? signature.comment.shortText : undefined,
returnComment: hasComment && signature.comment.returns ? signature.comment.returns : undefined, returnComment: hasComment && signature.comment.returns ? signature.comment.returns : undefined,
callPath,
source: { source: {
fileName: source.fileName, fileName: source.fileName,
line: source.line, line: source.line,