Skip to content

Commit

Permalink
fix(app): add support for inheritanceand extends
Browse files Browse the repository at this point in the history
fix #116
  • Loading branch information
vogloblinsky committed Mar 8, 2017
1 parent 9578f56 commit 97cff59
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 13 deletions.
58 changes: 45 additions & 13 deletions src/app/compiler/dependencies.ts
Expand Up @@ -62,6 +62,9 @@ interface Deps {
templateUrl?: string[];
viewProviders?: string[];

implements?;
extends?;

inputsClass?: Object[];

//common
Expand Down Expand Up @@ -244,6 +247,12 @@ export class Dependencies {
if(IO.constructor) {
deps.constructorObj = IO.constructor;
}
if (IO.extends) {
deps.extends = IO.extends;
}
if (IO.implements && IO.implements.length > 0) {
deps.implements = IO.implements;
}
$componentsTreeEngine.addComponent(deps);
outputSymbols['components'].push(deps);
}
Expand Down Expand Up @@ -339,6 +348,12 @@ export class Dependencies {
if(IO.methods) {
deps.methods = IO.methods;
}
if (IO.extends) {
deps.extends = IO.extends;
}
if (IO.implements && IO.implements.length > 0) {
deps.implements = IO.implements;
}
this.debug(deps);
outputSymbols['classes'].push(deps);
} else if(node.symbol.flags === ts.SymbolFlags.Interface) {
Expand Down Expand Up @@ -429,6 +444,12 @@ export class Dependencies {
if(IO.methods) {
deps.methods = IO.methods;
}
if (IO.extends) {
deps.extends = IO.extends;
}
if (IO.implements && IO.implements.length > 0) {
deps.implements = IO.implements;
}
this.debug(deps);
outputSymbols['classes'].push(deps);
}
Expand Down Expand Up @@ -1133,28 +1154,31 @@ export class Dependencies {
var className = classDeclaration.name.text;
var directiveInfo;
var members;
var implementsElements = [];
var extendsElement;
var jsdoctags = [];

if (typeof ts.getClassImplementsHeritageClauseElements !== 'undefined') {
var implementedTypes = ts.getClassImplementsHeritageClauseElements(classDeclaration);
if (implementedTypes) {
console.log('implementedTypes: ', implementedTypes);
let i = 0,
len = implementedTypes.length;
for(i; i<len; i++) {
if (implementedTypes[i].expression) {
implementsElements.push(implementedTypes[i].expression.text);
}
}
}
}

if (typeof ts.getClassExtendsHeritageClauseElement !== 'undefined') {
var extendsTypes = ts.getClassExtendsHeritageClauseElement(classDeclaration);
if (extendsTypes) {
console.log('extendsTypes: ', extendsTypes);
if (extendsTypes.expression) {
extendsElement = extendsTypes.expression.text
}
}
}
/*
if (classDeclaration.heritageClauses && classDeclaration.heritageClauses.length > 0) {
for (let i = 0; i < classDeclaration.heritageClauses.length; i++) {
console.log(classDeclaration.heritageClauses[i].kind, ts.SyntaxKind[200], ts.SyntaxKind[classDeclaration.heritageClauses[i].kind]);
console.log(util.inspect(classDeclaration.heritageClauses[i].types, { showHidden: false, depth: 8 }));
}
}*/

if (symbol.valueDeclaration) {
jsdoctags = JSDocTagsParser.getJSDocs(symbol.valueDeclaration);
Expand All @@ -1174,7 +1198,9 @@ export class Dependencies {
indexSignatures: members.indexSignatures,
kind: members.kind,
constructor: members.constructor,
jsdoctags: jsdoctags
jsdoctags: jsdoctags,
extends: extendsElement,
implements: implementsElements
};
} else if (this.isServiceDecorator(classDeclaration.decorators[i])) {
members = this.visitMembers(classDeclaration.members, sourceFile);
Expand All @@ -1186,7 +1212,9 @@ export class Dependencies {
indexSignatures: members.indexSignatures,
properties: members.properties,
kind: members.kind,
constructor: members.constructor
constructor: members.constructor,
extends: extendsElement,
implements: implementsElements
}];
} else if (this.isPipeDecorator(classDeclaration.decorators[i]) || this.isModuleDecorator(classDeclaration.decorators[i])) {
return [{
Expand All @@ -1206,7 +1234,9 @@ export class Dependencies {
indexSignatures: members.indexSignatures,
properties: members.properties,
kind: members.kind,
constructor: members.constructor
constructor: members.constructor,
extends: extendsElement,
implements: implementsElements
}];
} else {
members = this.visitMembers(classDeclaration.members, sourceFile);
Expand All @@ -1216,7 +1246,9 @@ export class Dependencies {
indexSignatures: members.indexSignatures,
properties: members.properties,
kind: members.kind,
constructor: members.constructor
constructor: members.constructor,
extends: extendsElement,
implements: implementsElements
}];
}

Expand Down
3 changes: 3 additions & 0 deletions src/app/engines/dependencies.engine.ts
Expand Up @@ -83,12 +83,15 @@ class DependenciesEngine {
},
resultInCompodocInjectables = finderInCompodocDependencies(this.injectables),
resultInCompodocClasses = finderInCompodocDependencies(this.classes),
resultInCompodocComponents = finderInCompodocDependencies(this.components),
resultInAngularAPIs = finderInAngularAPIs(type)

if (resultInCompodocInjectables.data !== null) {
return resultInCompodocInjectables
} else if (resultInCompodocClasses.data !== null) {
return resultInCompodocClasses
} else if (resultInCompodocComponents.data !== null) {
return resultInCompodocComponents
} else if (resultInAngularAPIs.data !== null) {
return resultInAngularAPIs
}
Expand Down
20 changes: 20 additions & 0 deletions src/templates/partials/class.hbs
Expand Up @@ -32,6 +32,26 @@
</p>
{{/if}}

{{#if class.extends}}
<p class="comment">
<h3>Extends</h3>
</p>
<p class="comment">
{{> link-type type=class.extends }}
</p>
{{/if}}

{{#if class.implements}}
<p class="comment">
<h3>Implements</h3>
</p>
<p class="comment">
{{#each class.implements}}
{{> link-type type=this}}
{{/each}}
</p>
{{/if}}

{{#if class.constructorObj}}
{{> block-constructor constructor=class.constructorObj file=class.file }}
{{/if}}
Expand Down
20 changes: 20 additions & 0 deletions src/templates/partials/component-detail.hbs
Expand Up @@ -14,6 +14,26 @@
</p>
{{/if}}

{{#if component.extends}}
<p class="comment">
<h3>Extends</h3>
</p>
<p class="comment">
{{> link-type type=component.extends }}
</p>
{{/if}}

{{#if component.implements}}
<p class="comment">
<h3>Implements</h3>
</p>
<p class="comment">
{{#each component.implements}}
{{> link-type type=this}}
{{/each}}
</p>
{{/if}}

{{#if component.jsdoctags}}
<p class="comment">
<h3>Example</h3>
Expand Down

0 comments on commit 97cff59

Please sign in to comment.