Skip to content

Commit

Permalink
feat(PropertyParser): add properties (#146)
Browse files Browse the repository at this point in the history
  • Loading branch information
RealShadowNova committed Jun 21, 2023
1 parent 6a3b31c commit d6fc2bd
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 6 deletions.
31 changes: 28 additions & 3 deletions src/bin/lib/migrateProjectJson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -715,10 +715,35 @@ function migrateParameterJson(
}

function migratePropertyJson(
propertyJson: Version.Eight.Zero.Misc.PropertyJson | Version.Eight.One.Misc.PropertyJson,
_typeDocJsonParserVersion: [number, number, number]
propertyJson: Version.Eight.Zero.Misc.PropertyJson | Version.Eight.One.Misc.PropertyJson | Version.Eight.Two.Misc.PropertyJson,
typeDocJsonParserVersion: [number, number, number]
): PropertyParser.Json {
return propertyJson;
const [major, minor] = typeDocJsonParserVersion;
const { id, name, comment, type } = propertyJson;

if (major < 9) {
if (major === 8 && minor < 2) {
return {
id,
name,
comment: migrateCommentJson(comment, typeDocJsonParserVersion),
readonly: false,
optional: false,
type: migrateTypeJson(type, typeDocJsonParserVersion)
};
}
}

const { readonly, optional } = propertyJson as Version.Eight.Two.Misc.PropertyJson;

return {
id,
name,
comment: migrateCommentJson(comment, typeDocJsonParserVersion),
readonly,
optional,
type: migrateTypeJson(type, typeDocJsonParserVersion)
};
}

function migrateSignatureJson(
Expand Down
4 changes: 4 additions & 0 deletions src/bin/lib/types/Version/Eight/Two.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@ export namespace Misc {

comment: CommentJson;

readonly: boolean;

optional: boolean;

type: TypeJson;
}

Expand Down
50 changes: 47 additions & 3 deletions src/lib/structures/misc/PropertyParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,32 @@ export class PropertyParser {
*/
public readonly comment: CommentParser;

/**
* Whether this property is readonly.
* @since 8.2.0
*/
public readonly readonly: boolean;

/**
* Whether this property is optional.
* @since 8.2.0
*/
public readonly optional: boolean;

/**
* The type of this property.
* @since 8.0.0
*/
public readonly type: TypeParser;

public constructor(data: PropertyParser.Data) {
const { id, name, comment, type } = data;
const { id, name, comment, readonly, optional, type } = data;

this.id = id;
this.name = name;
this.comment = comment;
this.readonly = readonly;
this.optional = optional;
this.type = type;
}

Expand All @@ -51,6 +65,8 @@ export class PropertyParser {
id: this.id,
name: this.name,
comment: this.comment.toJSON(),
readonly: this.readonly,
optional: this.optional,
type: this.type.toJSON()
};
}
Expand All @@ -62,7 +78,7 @@ export class PropertyParser {
* @returns The generated parser.
*/
public static generateFromTypeDoc(reflection: JSONOutput.DeclarationReflection): PropertyParser {
const { kind, id, name, comment = { summary: [] }, type } = reflection;
const { kind, id, name, comment = { summary: [] }, flags, type } = reflection;

if (kind !== ReflectionKind.Property) {
throw new Error(
Expand All @@ -74,6 +90,8 @@ export class PropertyParser {
id,
name,
comment: CommentParser.generateFromTypeDoc(comment),
readonly: Boolean(flags?.isReadonly),
optional: Boolean(flags?.isOptional),
type: TypeParser.generateFromTypeDoc(type!)
});
}
Expand All @@ -85,12 +103,14 @@ export class PropertyParser {
* @returns The generated parser.
*/
public static generateFromJson(json: PropertyParser.Json): PropertyParser {
const { id, name, comment, type } = json;
const { id, name, comment, readonly, optional, type } = json;

return new PropertyParser({
id,
name,
comment: CommentParser.generateFromJson(comment),
readonly,
optional,
type: TypeParser.generateFromJson(type)
});
}
Expand All @@ -116,6 +136,18 @@ export namespace PropertyParser {
*/
comment: CommentParser;

/**
* Whether this property is readonly.
* @since 8.2.0
*/
readonly: boolean;

/**
* Whether this property is optional.
* @since 8.2.0
*/
optional: boolean;

/**
* The type of this property.
* @since 8.0.0
Expand All @@ -142,6 +174,18 @@ export namespace PropertyParser {
*/
comment: CommentParser.Json;

/**
* Whether this property is readonly in a json compatible format.
* @since 8.2.0
*/
readonly: boolean;

/**
* Whether this property is optional in a json compatible format.
* @since 8.2.0
*/
optional: boolean;

/**
* The type of this property in a json compatible format.
* @since 8.0.0
Expand Down

0 comments on commit d6fc2bd

Please sign in to comment.