Skip to content
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.

Commit

Permalink
feat(store): hiding of properties per meta-data
Browse files Browse the repository at this point in the history
  • Loading branch information
TheReincarnator committed Dec 18, 2017
1 parent 26d8e9d commit 0bab560
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 19 deletions.
18 changes: 12 additions & 6 deletions src/store/pattern/index.ts
Expand Up @@ -98,15 +98,21 @@ export class Pattern {
parsers.forEach(parser => {
if (parser.parse(this)) {
this.valid = true;
console.debug(`Successfully parsed pattern "${this.getRelativePath()}", properties:`);
this.properties.forEach(property => {
console.debug(property.toString());
});
console.debug('');
}
});
Array.from(this.properties.keys()).forEach((propertyId: string) => {
if ((this.properties.get(propertyId) as Property).isHidden()) {
this.properties.delete(propertyId);
}
});

if (!this.valid) {
if (this.valid) {
console.debug(`Successfully parsed pattern "${this.getRelativePath()}", properties:`);
this.properties.forEach(property => {
console.debug(property.toString());
});
console.debug('');
} else {
console.warn(
`Failed to parse pattern "${this.getRelativePath()}":` +
' Currently we support TypeScript patterns only' +
Expand Down
9 changes: 6 additions & 3 deletions src/store/pattern/parser/typescript_parser.ts
Expand Up @@ -90,17 +90,19 @@ export class TypeScriptParser extends PatternParser {

protected getJsDocValue(node: ts.Node, tagName: string): string | undefined {
const jsDocTags: ReadonlyArray<ts.JSDocTag> | undefined = ts.getJSDocTags(node);
let result = '';
let result: string | undefined;
if (jsDocTags) {
jsDocTags.forEach(jsDocTag => {
if (jsDocTag.tagName && jsDocTag.tagName.text === tagName) {
if (result === undefined) {
result = '';
}
result += ` ${jsDocTag.comment}`;
}
});
}

result = result.trim();
return result.length > 0 ? result : undefined;
return result === undefined ? undefined : result.trim();
}

protected getPropsTypeName(): string {
Expand Down Expand Up @@ -177,6 +179,7 @@ export class TypeScriptParser extends PatternParser {
}

property.setRequired(signature.questionToken === undefined);
property.setHidden(this.getJsDocValue(signature, 'hidden') !== undefined);

const defaultValue: string | undefined = this.getJsDocValue(signature, 'default');
if (defaultValue !== undefined) {
Expand Down
29 changes: 19 additions & 10 deletions src/store/pattern/property/index.ts
Expand Up @@ -2,6 +2,7 @@ export abstract class Property {
// tslint:disable-next-line:no-any
private defaultValue: any;
private id: string;
private hidden: boolean = false;
private name: string;
private required: boolean = false;

Expand Down Expand Up @@ -78,8 +79,22 @@ export abstract class Property {
return this.name;
}

// tslint:disable-next-line:no-any
protected getToStringProperties(): [string, any][] {
return [
['id', this.id],
['name', this.name],
['required', this.required],
['default', this.defaultValue]
];
}

public abstract getType(): string;

public isHidden(): boolean {
return this.hidden;
}

public isRequired(): boolean {
return this.required;
}
Expand All @@ -89,6 +104,10 @@ export abstract class Property {
this.defaultValue = defaultValue;
}

public setHidden(hidden: boolean): void {
this.hidden = hidden;
}

public setName(name: string): void {
this.name = name;
}
Expand All @@ -97,16 +116,6 @@ export abstract class Property {
this.required = required;
}

// tslint:disable-next-line:no-any
protected getToStringProperties(): [string, any][] {
return [
['id', this.id],
['name', this.name],
['required', this.required],
['default', this.defaultValue]
];
}

public toString(): string {
// tslint:disable-next-line:no-any
const properties: [string, any][] = this.getToStringProperties();
Expand Down

0 comments on commit 0bab560

Please sign in to comment.