Skip to content

Commit

Permalink
feat(Parser): remove comment property (#72)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: `Parser#comment` has been removed.
BREAKING CHANGE: `ClassMethodParser#comment` has been removed.
BREAKING CHANGE: `InterfaceMethodParser#comment` has been removed.
  • Loading branch information
RealShadowNova committed Oct 11, 2022
1 parent 04076c4 commit 09666a1
Show file tree
Hide file tree
Showing 14 changed files with 239 additions and 43 deletions.
22 changes: 21 additions & 1 deletion src/lib/structures/ConstantParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ import { TypeParser } from './type-parsers';
* @since 1.0.0
*/
export class ConstantParser extends Parser {
/**
* The comment parser of this constant.
* @since 1.0.0
*/
public readonly comment: CommentParser;

/**
* Whether this constant is external.
* @since 1.0.0
Expand All @@ -31,8 +37,9 @@ export class ConstantParser extends Parser {
public constructor(data: ConstantParser.Data, project: ProjectParser) {
super(data, project);

const { external, type, value } = data;
const { comment, external, type, value } = data;

this.comment = comment;
this.external = external;
this.type = type;
this.value = value;
Expand All @@ -46,6 +53,7 @@ export class ConstantParser extends Parser {
public toJSON(): ConstantParser.JSON {
return {
...super.toJSON(),
comment: this.comment.toJSON(),
external: this.external,
type: this.type.toJSON(),
value: this.value
Expand Down Expand Up @@ -98,6 +106,12 @@ export class ConstantParser extends Parser {

export namespace ConstantParser {
export interface Data extends Parser.Data {
/**
* The comment parser of this constant.
* @since 1.0.0
*/
comment: CommentParser;

/**
* Whether this constant is external.
* @since 1.0.0
Expand All @@ -118,6 +132,12 @@ export namespace ConstantParser {
}

export interface JSON extends Parser.JSON {
/**
* The comment parser of this constant.
* @since 1.0.0
*/
comment: CommentParser.JSON;

/**
* Whether this constant is external.
* @since 1.0.0
Expand Down
22 changes: 21 additions & 1 deletion src/lib/structures/FunctionParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ import type { ProjectParser } from './ProjectParser';
* @since 1.0.0
*/
export class FunctionParser extends Parser {
/**
* The comment parser of this function.
* @since 1.0.0
*/
public readonly comment: CommentParser;

/**
* Whether this function is external.
* @since 1.0.0
Expand All @@ -24,8 +30,9 @@ export class FunctionParser extends Parser {
public constructor(data: FunctionParser.Data, project: ProjectParser) {
super(data, project);

const { external, signatures } = data;
const { comment, external, signatures } = data;

this.comment = comment;
this.external = external;
this.signatures = signatures;
}
Expand All @@ -38,6 +45,7 @@ export class FunctionParser extends Parser {
public toJSON(): FunctionParser.JSON {
return {
...super.toJSON(),
comment: this.comment.toJSON(),
external: this.external,
signatures: this.signatures.map((signature) => signature.toJSON())
};
Expand Down Expand Up @@ -87,6 +95,12 @@ export class FunctionParser extends Parser {

export namespace FunctionParser {
export interface Data extends Parser.Data {
/**
* The comment parser of this function.
* @since 1.0.0
*/
comment: CommentParser;

/**
* Whether this function is external.
* @since 1.0.0
Expand All @@ -101,6 +115,12 @@ export namespace FunctionParser {
}

export interface JSON extends Parser.JSON {
/**
* The comment parser of this function.
* @since 1.0.0
*/
comment: CommentParser.JSON;

/**
* Whether this function is external.
* @since 1.0.0
Expand Down
22 changes: 21 additions & 1 deletion src/lib/structures/NamespaceParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ import { TypeAliasParser } from './TypeAliasParser';
* @since 1.0.0
*/
export class NamespaceParser extends Parser {
/**
* The comment parser of this namespace.
* @since 1.0.0
*/
public readonly comment: CommentParser;

/**
* Whether this namespace is external.
* @since 1.0.0
Expand Down Expand Up @@ -66,8 +72,9 @@ export class NamespaceParser extends Parser {
public constructor(data: NamespaceParser.Data, project: ProjectParser) {
super(data, project);

const { external, classes, constants, enums, functions, interfaces, namespaces, typeAliases } = data;
const { comment, external, classes, constants, enums, functions, interfaces, namespaces, typeAliases } = data;

this.comment = comment;
this.external = external;
this.classes = classes;
this.constants = constants;
Expand Down Expand Up @@ -253,6 +260,7 @@ export class NamespaceParser extends Parser {
public toJSON(): NamespaceParser.JSON {
return {
...super.toJSON(),
comment: this.comment.toJSON(),
external: this.external,
classes: this.classes.map((parser) => parser.toJSON()),
constants: this.constants.map((parser) => parser.toJSON()),
Expand Down Expand Up @@ -342,6 +350,12 @@ export class NamespaceParser extends Parser {

export namespace NamespaceParser {
export interface Data extends Parser.Data {
/**
* The comment parser of this namespace.
* @since 1.0.0
*/
comment: CommentParser;

/**
* Whether this namespace is external.
* @since 1.0.0
Expand Down Expand Up @@ -392,6 +406,12 @@ export namespace NamespaceParser {
}

export interface JSON extends Parser.JSON {
/**
* The comment parser of this namespace.
* @since 1.0.0
*/
comment: CommentParser.JSON;

/**
* Whether this namespace is external.
* @since 1.0.0
Expand Down
24 changes: 2 additions & 22 deletions src/lib/structures/Parser.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { CommentParser, SourceParser } from './misc';
import type { SourceParser } from './misc';
import type { ProjectParser } from './ProjectParser';

/**
Expand All @@ -24,24 +24,17 @@ export abstract class Parser {
*/
public readonly name: string;

/**
* The comment parser for this parser.
* @since 1.0.0
*/
public readonly comment: CommentParser;

/**
* The source parser for this parser.
* @since 1.0.0
*/
public readonly source: SourceParser | null;

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

this.id = id;
this.name = name;
this.comment = comment;
this.source = source;

this.project = project;
Expand All @@ -56,7 +49,6 @@ export abstract class Parser {
return {
id: this.id,
name: this.name,
comment: this.comment.toJSON(),
source: this.source ? this.source.toJSON() : null
};
}
Expand All @@ -76,12 +68,6 @@ export namespace Parser {
*/
name: string;

/**
* The comment parser for this parser.
* @since 1.0.0
*/
comment: CommentParser;

/**
* The source parser for this parser.
* @since 1.0.0
Expand All @@ -102,12 +88,6 @@ export namespace Parser {
*/
name: string;

/**
* The comment parser for this parser in a JSON compatible format.
* @since 1.0.0
*/
comment: CommentParser.JSON;

/**
* The source parser for this parser in a JSON compatible format.
* @since 1.0.0
Expand Down
22 changes: 21 additions & 1 deletion src/lib/structures/TypeAliasParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ import { TypeParser } from './type-parsers';
* @since 1.0.0
*/
export class TypeAliasParser extends Parser {
/**
* The comment parser of this type alias.
* @since 1.0.0
*/
public readonly comment: CommentParser;

/**
* Whether this type alias is external.
* @since 1.0.0
Expand All @@ -31,8 +37,9 @@ export class TypeAliasParser extends Parser {
public constructor(data: TypeAliasParser.Data, project: ProjectParser) {
super(data, project);

const { external, typeParameters, type } = data;
const { comment, external, typeParameters, type } = data;

this.comment = comment;
this.external = external;
this.typeParameters = typeParameters;
this.type = type;
Expand All @@ -46,6 +53,7 @@ export class TypeAliasParser extends Parser {
public toJSON(): TypeAliasParser.JSON {
return {
...super.toJSON(),
comment: this.comment.toJSON(),
external: this.external,
typeParameters: this.typeParameters.map((typeParameter) => typeParameter.toJSON()),
type: this.type.toJSON()
Expand Down Expand Up @@ -98,6 +106,12 @@ export class TypeAliasParser extends Parser {

export namespace TypeAliasParser {
export interface Data extends Parser.Data {
/**
* The comment parser of this type alias.
* @since 1.0.0
*/
comment: CommentParser;

/**
* Whether this type alias is external.
* @since 1.0.0
Expand All @@ -118,6 +132,12 @@ export namespace TypeAliasParser {
}

export interface JSON extends Parser.JSON {
/**
* The comment parser of this type alias.
* @since 1.0.0
*/
comment: CommentParser.JSON;

/**
* Whether this type alias is external.
* @since 1.0.0
Expand Down
22 changes: 21 additions & 1 deletion src/lib/structures/class-parser/ClassConstructorParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ import type { ProjectParser } from '../ProjectParser';
import type { ClassParser } from './ClassParser';

export class ClassConstructorParser extends Parser {
/**
* The comment parser of this constructor.
* @since 1.0.0
*/
public readonly comment: CommentParser;

/**
* The id of the parent class parser.
* @since 4.0.0
Expand All @@ -21,8 +27,9 @@ export class ClassConstructorParser extends Parser {
public constructor(data: ClassConstructorParser.Data, project: ProjectParser) {
super(data, project);

const { parentId, parameters } = data;
const { comment, parentId, parameters } = data;

this.comment = comment;
this.parentId = parentId;
this.parameters = parameters;
}
Expand All @@ -43,6 +50,7 @@ export class ClassConstructorParser extends Parser {
public toJSON(): ClassConstructorParser.JSON {
return {
...super.toJSON(),
comment: this.comment.toJSON(),
parentId: this.parentId,
parameters: this.parameters.map((parameter) => parameter.toJSON())
};
Expand Down Expand Up @@ -119,6 +127,12 @@ export class ClassConstructorParser extends Parser {

export namespace ClassConstructorParser {
export interface Data extends Parser.Data {
/**
* The comment parser of this constructor.
* @since 1.0.0
*/
comment: CommentParser;

/**
* The id of the parent class parser.
* @since 4.0.0
Expand All @@ -133,6 +147,12 @@ export namespace ClassConstructorParser {
}

export interface JSON extends Parser.JSON {
/**
* The comment parser of this constructor.
* @since 1.0.0
*/
comment: CommentParser.Data;

/**
* The id of the parent class parser.
* @since 4.0.0
Expand Down
8 changes: 3 additions & 5 deletions src/lib/structures/class-parser/ClassMethodParser.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { JSONOutput } from 'typedoc';
import { ReflectionKind } from '../../types';
import { CommentParser, SignatureParser, SourceParser } from '../misc';
import { SignatureParser, SourceParser } from '../misc';
import { Parser } from '../Parser';
import type { ProjectParser } from '../ProjectParser';
import { ClassParser } from './ClassParser';
Expand Down Expand Up @@ -84,15 +84,14 @@ export class ClassMethodParser extends Parser {
* @returns The generated parser.
*/
public static generateFromTypeDoc(reflection: JSONOutput.DeclarationReflection, parentId: number, project: ProjectParser): ClassMethodParser {
const { kind, kindString = 'Unknown', id, name, comment = { summary: [] }, sources = [], flags, signatures = [] } = reflection;
const { kind, kindString = 'Unknown', id, name, sources = [], flags, signatures = [] } = reflection;

if (kind !== ReflectionKind.Method) throw new Error(`Expected Method (${ReflectionKind.Method}), but received ${kindString} (${kind})`);

return new ClassMethodParser(
{
id,
name,
comment: CommentParser.generateFromTypeDoc(comment, project),
source: sources.length ? SourceParser.generateFromTypeDoc(sources[0], project) : null,
parentId,
accessibility: flags.isPrivate
Expand All @@ -109,13 +108,12 @@ export class ClassMethodParser extends Parser {
}

public static generateFromJSON(json: ClassMethodParser.JSON, project: ProjectParser): ClassMethodParser {
const { id, name, comment, source, parentId, accessibility, abstract, static: _static, signatures } = json;
const { id, name, source, parentId, accessibility, abstract, static: _static, signatures } = json;

return new ClassMethodParser(
{
id,
name,
comment: CommentParser.generateFromJSON(comment, project),
source: source ? SourceParser.generateFromJSON(source, project) : null,
parentId,
accessibility,
Expand Down

0 comments on commit 09666a1

Please sign in to comment.