Skip to content

Commit

Permalink
feat(ParameterParser): add comment property (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
RealShadowNova committed Oct 11, 2022
1 parent 4ef3f9a commit 04076c4
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions src/lib/structures/misc/ParameterParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { JSONOutput } from 'typedoc';
import { ReflectionKind } from '../../types';
import type { ProjectParser } from '../ProjectParser';
import { TypeParser } from '../type-parsers';
import { CommentParser } from './CommentParser';

/**
* Parses data from a parameter reflection.
Expand All @@ -26,17 +27,24 @@ export class ParameterParser {
*/
public readonly name: string;

/**
* The comment of this parameter.
* @since 5.3.0
*/
public readonly comment: CommentParser;

/**
* The type of this parameter.
* @since 1.0.0
*/
public readonly type: TypeParser;

public constructor(data: ParameterParser.Data, project: ProjectParser) {
const { id, name, type } = data;
const { id, name, comment, type } = data;

this.id = id;
this.name = name;
this.comment = comment;
this.type = type;

this.project = project;
Expand All @@ -51,6 +59,7 @@ export class ParameterParser {
return {
id: this.id,
name: this.name,
comment: this.comment.toJSON(),
type: this.type.toJSON()
};
}
Expand All @@ -63,7 +72,7 @@ export class ParameterParser {
* @returns The generated parser.
*/
public static generateFromTypeDoc(reflection: JSONOutput.DeclarationReflection, project: ProjectParser): ParameterParser {
const { kind, kindString = 'Unknown', id, name, type } = reflection;
const { kind, kindString = 'Unknown', id, name, comment = { summary: [] }, type } = reflection;

if (kind !== ReflectionKind.Parameter) {
throw new Error(`Expected Parameter (${ReflectionKind.Parameter}), but received ${kindString} (${kind})`);
Expand All @@ -73,19 +82,21 @@ export class ParameterParser {
{
id,
name,
comment: CommentParser.generateFromTypeDoc(comment, project),
type: TypeParser.generateFromTypeDoc(type!, project)
},
project
);
}

public static generateFromJSON(json: ParameterParser.JSON, project: ProjectParser): ParameterParser {
const { id, name, type } = json;
const { id, name, comment, type } = json;

return new ParameterParser(
{
id,
name,
comment: CommentParser.generateFromJSON(comment, project),
type: TypeParser.generateFromJSON(type, project)
},
project
Expand All @@ -107,6 +118,12 @@ export namespace ParameterParser {
*/
name: string;

/**
* The comment of this parameter.
* @since 5.3.0
*/
comment: CommentParser;

/**
* The type of this parameter.
* @since 1.0.0
Expand All @@ -127,6 +144,12 @@ export namespace ParameterParser {
*/
name: string;

/**
* The comment of this parameter.
* @since 5.3.0
*/
comment: CommentParser.JSON;

/**
* The type of this parameter in a JSON compatible format.
* @since 1.0.0
Expand Down

0 comments on commit 04076c4

Please sign in to comment.