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

Commit

Permalink
#104 - "remove 'parent' to reduce complexity"
Browse files Browse the repository at this point in the history
  • Loading branch information
dsherret committed Apr 3, 2016
1 parent 70fc1de commit 5c3f431
Show file tree
Hide file tree
Showing 130 changed files with 393 additions and 522 deletions.
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,4 @@ abstract class MyClass {

### Real Life Example

* [Server Bridge](https://github.com/dsherret/server-bridge) - Automatically generates client side code to communicate with the server from the server side code (Out of date)
* [Server Bridge](https://github.com/dsherret/server-bridge) - Automatically generates client side code to communicate with the server from the server side code
1 change: 1 addition & 0 deletions src/WriteFlags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
HideFunctionBodies = 1 << 1,
HidePrivateMembers = 1 << 2,
HideProtectedMembers = 1 << 3,
IsInAmbientContext = 1 << 4,
Default = None
}
1 change: 0 additions & 1 deletion src/binders/base/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export * from "./base/ModuledBinder";
export * from "./base/NamedBinder";
export * from "./base/ObjectPropertyBinder";
export * from "./base/ParameteredBinder";
export * from "./base/ParentedBinder";
export * from "./base/ReturnTypedBinder";
export * from "./base/TypeExpressionedBinder";
export * from "./base/TypeParameteredBinder";
4 changes: 2 additions & 2 deletions src/binders/base/base/BaseFunctionBinder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {ParameteredBinder} from "./ParameteredBinder";
import {TypeParameteredBinder} from "./TypeParameteredBinder";
import {ReturnTypedBinder} from "./ReturnTypedBinder";

export abstract class BaseFunctionBinder<ParameterType extends BaseParameterDefinition<any>> {
export abstract class BaseFunctionBinder<ParameterType extends BaseParameterDefinition> {
constructor(
private namedBinder: NamedBinder,
private typeParameterBinder: TypeParameteredBinder,
Expand All @@ -13,7 +13,7 @@ export abstract class BaseFunctionBinder<ParameterType extends BaseParameterDefi
) {
}

bind(def: BaseFunctionDefinition<any, ParameterType>) {
bind(def: BaseFunctionDefinition<ParameterType>) {
this.namedBinder.bind(def);
this.typeParameterBinder.bind(def);
this.parameterBinder.bind(def);
Expand Down
2 changes: 1 addition & 1 deletion src/binders/base/base/BaseParameterBinder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export abstract class BaseParameterBinder {
) {
}

bind(def: BaseParameterDefinition<any>) {
bind(def: BaseParameterDefinition) {
this.namedBinder.bind(def);
this.typeExpressionedBinder.bind(def);
this.defaultExpressionedBinder.bind(def);
Expand Down
2 changes: 1 addition & 1 deletion src/binders/base/base/BasePropertyBinder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export abstract class BasePropertyBinder {
) {
}

bind(def: BasePropertyDefinition<any>) {
bind(def: BasePropertyDefinition) {
this.namedBinder.bind(def);
this.typeExpressionedBinder.bind(def);
def.isOptional = this.getIsOptional();
Expand Down
3 changes: 1 addition & 2 deletions src/binders/base/base/DecoratableBinder.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import {DecoratableDefinition, DecoratorDefinition, DecoratedDefinitions} from "./../../../definitions";
import {DecoratableDefinition, DecoratorDefinition} from "./../../../definitions";

export abstract class DecoratableBinder {
abstract getDecorators(): DecoratorDefinition[];

bind(def: DecoratableDefinition) {
def.decorators.push(...this.getDecorators());
def.decorators.forEach(d => d.parent = def as DecoratedDefinitions);
}
}
2 changes: 0 additions & 2 deletions src/binders/base/base/ModuledBinder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,5 @@ export abstract class ModuledBinder {
else if (handleCustomDefinition instanceof Function) {
handleCustomDefinition(member);
}

member.parent = def;
}
}
2 changes: 1 addition & 1 deletion src/binders/base/base/ObjectPropertyBinder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export abstract class ObjectPropertyBinder implements IBaseBinder {
) {
}

bind(def: ObjectPropertyDefinition<any>) {
bind(def: ObjectPropertyDefinition) {
this.basePropertyBinder.bind(def);
this.defaultExpressionedBinder.bind(def);
}
Expand Down
3 changes: 1 addition & 2 deletions src/binders/base/base/ParameteredBinder.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import {ParameteredDefinition, BaseParameterDefinition} from "./../../../definitions";

export abstract class ParameteredBinder<ParameterType extends BaseParameterDefinition<any>> {
export abstract class ParameteredBinder<ParameterType extends BaseParameterDefinition> {
abstract getParameters(): ParameterType[];

bind(def: ParameteredDefinition<ParameterType>) {
def.parameters.push(...this.getParameters());
def.parameters.forEach(p => p.parent = def);
}
}
7 changes: 0 additions & 7 deletions src/binders/base/base/ParentedBinder.ts

This file was deleted.

3 changes: 1 addition & 2 deletions src/binders/base/base/TypeParameteredBinder.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import {TypeParameterDefinition, TypeParameteredDefinition, TypeParameteredDefinitions} from "./../../../definitions";
import {TypeParameterDefinition, TypeParameteredDefinition} from "./../../../definitions";

export abstract class TypeParameteredBinder {
abstract getTypeParameters(): TypeParameterDefinition[];

bind(def: TypeParameteredDefinition) {
def.typeParameters.push(...this.getTypeParameters());
def.typeParameters.forEach(p => p.parent = def as TypeParameteredDefinitions);
}
}
6 changes: 1 addition & 5 deletions src/binders/base/class/ClassBinder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,13 @@ export abstract class ClassBinder implements IBaseBinder {
Logger.warn(`Unknown member member for class.`);
return;
}

member.parent = def;
}

private fillPropertiesFromConstructorDef(def: ClassDefinition) {
if (def.constructorDef != null) {
def.constructorDef.parameters.forEach(param => {
if (param.scope !== ClassConstructorParameterScope.None) {
const property = param.toProperty();
property.parent = def;
def.properties.push(property);
def.properties.push(param.toProperty());
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/binders/base/class/base/BaseClassMethodBinder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import {DecoratableBinder, BaseFunctionBinder} from "./../../base";
import {ScopedBinder} from "./ScopedBinder";

export abstract class BaseClassMethodBinder<ParameterType extends BaseClassMethodParameterDefinition<any>> {
export abstract class BaseClassMethodBinder<ParameterType extends BaseClassMethodParameterDefinition> {
constructor(
private baseFunctionBinder: BaseFunctionBinder<ParameterType>,
private decoratableBinder: DecoratableBinder,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export abstract class BaseClassMethodParameterBinder {
) {
}

bind(def: BaseClassMethodParameterDefinition<any>) {
bind(def: BaseClassMethodParameterDefinition) {
this.baseParameterBinder.bind(def);
this.decoratableBinder.bind(def);
this.scopedBinder.bind(def);
Expand Down
7 changes: 1 addition & 6 deletions src/binders/base/enum/EnumBinder.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import {EnumDefinition, EnumMemberDefinition} from "./../../../definitions";
import {NamedBinder, ExportableBinder, AmbientableBinder, ParentedBinder} from "./../base";
import {NamedBinder, ExportableBinder, AmbientableBinder} from "./../base";
import {IBaseBinder} from "./../IBaseBinder";

export abstract class EnumBinder implements IBaseBinder {
private parentedBinder = new ParentedBinder();

constructor(
private namedBinder: NamedBinder,
private exportableBinder: ExportableBinder,
Expand All @@ -19,8 +17,5 @@ export abstract class EnumBinder implements IBaseBinder {
this.exportableBinder.bind(def);
this.ambientableBinder.bind(def);
def.members.push(...this.getMembers());
def.members.forEach(m => {
this.parentedBinder.bindParentToChild(def, m);
});
}
}
2 changes: 0 additions & 2 deletions src/binders/base/interface/InterfaceBinder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,5 @@ export abstract class InterfaceBinder implements IBaseBinder {
Logger.warn(`Not implemented interface member.`);
return;
}

member.parent = def;
}
}
2 changes: 1 addition & 1 deletion src/binders/structure/base/StructureBaseFunctionBinder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {StructureTypeParameteredBinder} from "./StructureTypeParameteredBinder";
import {StructureParameteredBinder, StructureParameterBinderConstructor} from "./StructureParameteredBinder";
import {StructureReturnTypedBinder} from "./StructureReturnTypedBinder";

export class StructureBaseFunctionBinder<ParameterType extends BaseParameterDefinition<any>, StructureParameterType extends BaseParameterStructure>
export class StructureBaseFunctionBinder<ParameterType extends BaseParameterDefinition, StructureParameterType extends BaseParameterStructure>
extends BaseFunctionBinder<ParameterType> {
constructor(
factory: StructureFactory,
Expand Down
4 changes: 2 additions & 2 deletions src/binders/structure/base/StructureParameteredBinder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
import {BaseParameterDefinitionConstructor, BaseParameterDefinition} from "./../../../definitions";
import {ParameteredBinder} from "./../../base";

export interface StructureParameterBinderConstructor<ParameterType extends BaseParameterDefinition<any>> {
export interface StructureParameterBinderConstructor<ParameterType extends BaseParameterDefinition> {
new(structure: BaseParameterStructure): { bind(def: ParameterType): void; };
}

export class StructureParameteredBinder<ParameterType extends BaseParameterDefinition<any>, StructureParameterType extends BaseParameterStructure>
export class StructureParameteredBinder<ParameterType extends BaseParameterDefinition, StructureParameterType extends BaseParameterStructure>
extends ParameteredBinder<ParameterType> {
constructor(
private structure: ParameteredStructure<StructureParameterType>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {BaseClassMethodBinder} from "./../../../base";
import {StructureDecoratableBinder, StructureBaseFunctionBinder, StructureParameterBinderConstructor} from "./../../base";
import {StructureScopedBinder} from "./StructureScopedBinder";

export class StructureBaseClassMethodBinder<ParameterType extends BaseClassMethodParameterDefinition<any>, StructureParameterType extends BaseClassMethodParameterStructure>
export class StructureBaseClassMethodBinder<ParameterType extends BaseClassMethodParameterDefinition, StructureParameterType extends BaseClassMethodParameterStructure>
extends BaseClassMethodBinder<ParameterType> {
constructor(
factory: StructureFactory,
Expand Down
2 changes: 1 addition & 1 deletion src/binders/ts/base/TsBaseFunctionBinder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {TsTypeParameteredBinderByNode} from "./TsTypeParameteredBinderByNode";
import {TsParameteredBinderByNode, TsParameterBinderByNodeConstructor} from "./TsParameteredBinderByNode";
import {TsReturnTypedBinderByNode} from "./TsReturnTypedBinderByNode";

export class TsBaseFunctionBinder<ParameterType extends BaseParameterDefinition<any>> extends BaseFunctionBinder<ParameterType> {
export class TsBaseFunctionBinder<ParameterType extends BaseParameterDefinition> extends BaseFunctionBinder<ParameterType> {
constructor(
tsFactory: TsFactory,
node: TsNode,
Expand Down
4 changes: 2 additions & 2 deletions src/binders/ts/base/TsParameteredBinderByNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import {BaseParameterDefinitionConstructor, BaseParameterDefinition} from "./../
import {TsFactory} from "./../../../factories";
import {ParameteredBinder} from "./../../base";

export interface TsParameterBinderByNodeConstructor<ParameterType extends BaseParameterDefinition<any>> {
export interface TsParameterBinderByNodeConstructor<ParameterType extends BaseParameterDefinition> {
new(tsFactory: TsFactory, node: TsNode): { bind(def: ParameterType): void; };
}

export class TsParameteredBinderByNode<ParameterType extends BaseParameterDefinition<any>> extends ParameteredBinder<ParameterType> {
export class TsParameteredBinderByNode<ParameterType extends BaseParameterDefinition> extends ParameteredBinder<ParameterType> {
constructor(
private tsFactory: TsFactory,
private node: TsNode,
Expand Down
2 changes: 1 addition & 1 deletion src/binders/ts/base/TsParameteredBinderBySignature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {TsFactory} from "./../../../factories";
import {ParameteredBinder} from "./../../base";
import {TsParameterBinderByNodeConstructor} from "./TsParameteredBinderByNode";

export class TsParameteredBinderBySignature<ParameterType extends BaseParameterDefinition<any>> extends ParameteredBinder<ParameterType> {
export class TsParameteredBinderBySignature<ParameterType extends BaseParameterDefinition> extends ParameteredBinder<ParameterType> {
constructor(
private tsFactory: TsFactory,
private signature: TsSignature,
Expand Down
2 changes: 1 addition & 1 deletion src/binders/ts/class/base/TsBaseClassMethodBinder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {BaseClassMethodBinder} from "./../../../base";
import {TsDecoratableBinder, TsBaseFunctionBinder, TsParameterBinderByNodeConstructor} from "./../../base";
import {TsScopedBinder} from "./TsScopedBinder";

export class TsBaseClassMethodBinder<ParameterType extends BaseClassMethodParameterDefinition<any>> extends BaseClassMethodBinder<ParameterType> {
export class TsBaseClassMethodBinder<ParameterType extends BaseClassMethodParameterDefinition> extends BaseClassMethodBinder<ParameterType> {
constructor(
tsFactory: TsFactory,
node: TsNode,
Expand Down
1 change: 0 additions & 1 deletion src/definitions/base.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
export * from "./base/BaseDefinition";
export * from "./base/DefinitionType";
export * from "./base/NamedDefinition";
export * from "./base/ParentedDefinition";
export * from "./base/AbstractableDefinition";
export * from "./base/AmbientableDefinition";
export * from "./base/TypeExpressionedDefinition";
Expand Down
7 changes: 2 additions & 5 deletions src/definitions/base/BaseFunctionDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,21 @@ import {TypeParameterStructure} from "./../../structures";
import {applyMixins} from "./../../utils";
import {TypeParameterDefinition} from "./../general";
import {NamedDefinition} from "./NamedDefinition";
import {ParentedDefinition} from "./ParentedDefinition";
import {TypeParameteredDefinition} from "./TypeParameteredDefinition";
import {BaseDefinition} from "./BaseDefinition";
import {DefinitionType} from "./DefinitionType";
import {ParameteredDefinition} from "./ParameteredDefinition";
import {ReturnTypedDefinition} from "./ReturnTypedDefinition";

export class BaseFunctionDefinition<ParentType, ParameterType>
export class BaseFunctionDefinition<ParameterType>
extends BaseDefinition
implements NamedDefinition, ParentedDefinition<ParentType>, TypeParameteredDefinition, ParameteredDefinition<ParameterType>, ReturnTypedDefinition {
implements NamedDefinition, TypeParameteredDefinition, ParameteredDefinition<ParameterType>, ReturnTypedDefinition {
constructor(definitionType: DefinitionType) {
super(definitionType);
}

// NamedDefinition
name: string;
// IParentedDefinition
parent: ParentType;
// ParameteredDefinition
parameters: ParameterType[];
// ReturnTyped
Expand Down
6 changes: 1 addition & 5 deletions src/definitions/base/BaseParameterDefinition.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {applyMixins} from "./../../utils";
import {TypeExpressionDefinition, ExpressionDefinition} from "./../expressions";
import {NamedDefinition} from "./NamedDefinition";
import {ParentedDefinition} from "./ParentedDefinition";
import {TypeExpressionedDefinition} from "./TypeExpressionedDefinition";
import {DefaultExpressionedDefinition} from "./DefaultExpressionedDefinition";
import {BaseDefinition} from "./BaseDefinition";
Expand All @@ -11,8 +10,7 @@ export interface BaseParameterDefinitionConstructor<ParameterType> {
new(): ParameterType;
}

export class BaseParameterDefinition<ParentType> extends BaseDefinition
implements NamedDefinition, ParentedDefinition<ParentType>, TypeExpressionedDefinition, DefaultExpressionedDefinition {
export class BaseParameterDefinition extends BaseDefinition implements NamedDefinition, TypeExpressionedDefinition, DefaultExpressionedDefinition {
isOptional: boolean;
isRestParameter: boolean;

Expand All @@ -22,8 +20,6 @@ export class BaseParameterDefinition<ParentType> extends BaseDefinition

// NamedDefinition
name: string;
// IParentedDefinition
parent: ParentType;
// TypeExpressionedDefinition
typeExpression: TypeExpressionDefinition;
// DefaultExpressionedDefinition
Expand Down
5 changes: 1 addition & 4 deletions src/definitions/base/BasePropertyDefinition.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import {applyMixins} from "./../../utils";
import {TypeExpressionDefinition} from "./../expressions";
import {NamedDefinition} from "./NamedDefinition";
import {ParentedDefinition} from "./ParentedDefinition";
import {TypeExpressionedDefinition} from "./TypeExpressionedDefinition";
import {DefinitionType} from "./DefinitionType";
import {BaseDefinition} from "./BaseDefinition";

export class BasePropertyDefinition<ParentType> extends BaseDefinition implements NamedDefinition, ParentedDefinition<ParentType>, TypeExpressionedDefinition {
export class BasePropertyDefinition extends BaseDefinition implements NamedDefinition, TypeExpressionedDefinition {
isOptional: boolean;

constructor(definitionType: DefinitionType) {
Expand All @@ -15,8 +14,6 @@ export class BasePropertyDefinition<ParentType> extends BaseDefinition implement

// NamedDefinition
name: string;
// IParentedDefinition
parent: ParentType;
// TypeExpressionedDefinition
typeExpression: TypeExpressionDefinition;
}
Expand Down
1 change: 0 additions & 1 deletion src/definitions/base/DecoratableDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export abstract class DecoratableDefinition {
const factory = new StructureFactory();
decorators.forEach(decorator => {
const def = factory.getDecorator(decorator);
def.parent = this as any;
this.decorators.push(def);
});
return this;
Expand Down
2 changes: 1 addition & 1 deletion src/definitions/base/ObjectPropertyDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {DefinitionType} from "./DefinitionType";
import {DefaultExpressionedDefinition} from "./DefaultExpressionedDefinition";
import {BasePropertyDefinition} from "./BasePropertyDefinition";

export abstract class ObjectPropertyDefinition<ParentType> extends BasePropertyDefinition<ParentType> implements DefaultExpressionedDefinition {
export abstract class ObjectPropertyDefinition extends BasePropertyDefinition implements DefaultExpressionedDefinition {
constructor(definitionType: DefinitionType) {
super(definitionType);
}
Expand Down
3 changes: 0 additions & 3 deletions src/definitions/base/ParentedDefinition.ts

This file was deleted.

6 changes: 1 addition & 5 deletions src/definitions/base/TypeParameteredDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ import {TypeParameterDefinition} from "./../general";
export abstract class TypeParameteredDefinition {
addTypeParameters(...typeParameters: TypeParameterStructure[]) {
const factory = new StructureFactory();
typeParameters.forEach(typeParameter => {
const def = factory.getTypeParameter(typeParameter);
def.parent = this as any;
this.typeParameters.push(def);
});
typeParameters.forEach(typeParameter => this.typeParameters.push(factory.getTypeParameter(typeParameter)));
return this;
}

Expand Down
7 changes: 2 additions & 5 deletions src/definitions/class/ClassConstructorDefinition.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
import CodeBlockWriter from "code-block-writer";
import {ParentedDefinition, BaseDefinition, DefinitionType, ParameteredDefinition} from "./../base";
import {BaseDefinition, DefinitionType, ParameteredDefinition} from "./../base";
import {applyMixins} from "./../../utils";
import {ClassConstructorParameterDefinition} from "./ClassConstructorParameterDefinition";
import {ClassDefinition} from "./ClassDefinition";

export class ClassConstructorDefinition
extends BaseDefinition
implements ParentedDefinition<ClassDefinition>, ParameteredDefinition<ClassConstructorParameterDefinition> {
implements ParameteredDefinition<ClassConstructorParameterDefinition> {
onWriteFunctionBody: (writer: CodeBlockWriter) => void;

constructor() {
super(DefinitionType.ClassConstructor);
}

// IParentedDefinition
parent: ClassDefinition;
// ParameteredDefinition
parameters: ClassConstructorParameterDefinition[];
}
Expand Down
Loading

0 comments on commit 5c3f431

Please sign in to comment.