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

Commit

Permalink
fix(object-property): infinite loop on type recursion
Browse files Browse the repository at this point in the history
  • Loading branch information
faselbaum committed Apr 25, 2018
1 parent 06b3623 commit 8a0b74e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/component/container/property-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class PropertyTree extends React.Component<PropertyTreeProps> {

return (
<Element title={property.getName()} open={this.isOpen} handleClick={this.handleClick}>
{this.renderItems()}
{this.isOpen ? this.renderItems() : 'hidden'}
</Element>
);
}
Expand Down
34 changes: 26 additions & 8 deletions src/store/styleguide/property/object-property.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Property } from './property';

export type PropertyResolver = () => Property[];

/**
* An object property is a property that supports objects with nested property values.
* The properties field declares the types of each object element.
Expand All @@ -11,7 +13,9 @@ export class ObjectProperty extends Property {
/**
* The nested properties this property supports in its object values.
*/
private properties: Map<string, Property> = new Map();
private properties?: Map<string, Property>;

private propertyResolver?: PropertyResolver;

/**
* Creates a new object property.
Expand Down Expand Up @@ -39,7 +43,7 @@ export class ObjectProperty extends Property {
* @return The nested properties this property supports.
*/
public getProperties(): Property[] {
return Array.from(this.properties.values());
return Array.from(this.resolveProperties().values());
}

/**
Expand All @@ -48,7 +52,7 @@ export class ObjectProperty extends Property {
* @return The nested property if the ID was found.
*/
public getProperty(id: string): Property | undefined {
return this.properties.get(id);
return this.resolveProperties().get(id);
}

/**
Expand All @@ -58,16 +62,30 @@ export class ObjectProperty extends Property {
return 'object';
}

private resolveProperties(): Map<string, Property> {
if (!this.properties) {
if (!this.propertyResolver) {
throw new Error('property resolver is not set');
}

const resolvedProperties = this.propertyResolver();
const properties = new Map();

resolvedProperties.forEach(property => properties.set(property.getId(), property));

this.properties = properties;
}

return this.properties;
}

/**
* Sets The nested properties this property supports in its object values.<br>
* <b>Note:</b> This method should only be called from the pattern parsers.
* @param properties The nested properties this property supports.
*/
public setProperties(properties: Property[]): void {
this.properties = new Map();
for (const property of properties) {
this.properties.set(property.getId(), property);
}
public setPropertyResolver(propertyResolver: PropertyResolver): void {
this.propertyResolver = propertyResolver;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,9 @@ export class PropertyAnalyzer {

if (objectType.objectFlags & ts.ObjectFlags.Interface) {
const property = new ObjectProperty(args.symbol.name);
property.setProperties(PropertyAnalyzer.analyze(args.type, args.typechecker));
property.setPropertyResolver(() =>
PropertyAnalyzer.analyze(args.type, args.typechecker)
);
return property;
}
}
Expand Down

0 comments on commit 8a0b74e

Please sign in to comment.