Skip to content
This repository was archived by the owner on Mar 31, 2025. It is now read-only.

feat(typescript): class docs should link to inherited class docs #207

Closed
wants to merge 5 commits into from

Conversation

devversion
Copy link
Member

@devversion devversion commented Feb 8, 2017

  • Introduces a new property on export docs that links to the class docs that are being inherited.


export class FirstParent extends LastParent {
firstParentProp: string = 'Works';
_privateProperty: string = 'Private';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can also specify privacy by putting the private keyword before the property

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could. But I wanted this check to be private due to the leading underscore.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we should test both styles of private?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good.

var inheritedMembers = resolveInheritedMembers(resolvedExport, typeChecker);

for (var memberName in inheritedMembers) {
if (memberName === 'T') continue;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems rather hard coded. I guess you are trying to spot generic methods?
What if someone used a different letter in their generic definition?
Or am I missing something?

Copy link
Member Author

@devversion devversion Feb 19, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't put much effort into that. This logic was copied from the for-loop below. Looks like Alex Eagle wrote it at this time.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see...
OK well if it worked before then I guess we should leave it the same for consistency for now.
Perhaps we could factor that bit into a shared function so that we only have to change it in one place if we decide it needs fixing in the future?

Copy link
Contributor

@petebacondarwin petebacondarwin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks much better. I made a couple of inline comments.

I think it would be more effective if the inherited members each had a property that referenced the type from which they came. That way, one could group the inherited members by their heritage.

An alternative approach to this would be to identify the actual parent type (or more specifically the dgeni doc that represents the type) and just provide a property that references it. This way processors or templates could do the work of actually searching up the tree for the inherited members themselves - and you would get the ownership information I requested above for free.

@devversion devversion force-pushed the fix/ts-inherit-members branch from e869492 to fc85b36 Compare February 28, 2017 15:23
@devversion devversion changed the title fix: typescript should respect inherited members feat(typescript): class docs should link to inherited class docs Feb 28, 2017
* Introduces a new property on export docs that links to the class docs that are being inherited.
@devversion devversion force-pushed the fix/ts-inherit-members branch from fc85b36 to 4c5b2cc Compare February 28, 2017 15:25
function resolveInheritedDocs(exportSymbol, exportDoc) {
var inheritedSymbols = resolveInheritedSymbols(exportSymbol, typeChecker);
var inheritedDocs = inheritedSymbols.map(function(symbol) {
var relatedDoc = docs.find(function(doc) { return doc.exportSymbol === symbol; });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be super slow, given that we are doing a search of o(n) on every single inheritance symbol.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's true. Should we use some faster search algorithms? Or do you have any better ideas? I thought about creating a Map of Symbols with their associated docs, but that would then fill-up memory..

@petebacondarwin
Copy link
Contributor

OK, so this is really cool. I am worried about the performance time of doing all the searching.
Instead, can I suggest the following alternative approach:

  • in the readTypeScriptModules processor:
    • only capture the inheritance symbols in each export doc. E.g. doc.inheritanceSymbols
    • and add each exportDoc to a map keyed on its export symbol. E.g. `symbolToDocMap = new Map()
  • then in a new processor, which runs later, say, WireUpInheritanceDocs, you iterate through each export doc's inheritance symbols and map them to their appropriate doc

This way we do not have to keep searching the docs for the appropriate symbol.

What do you think?

(sorry this is turning into a bit of an epic!)

@devversion devversion force-pushed the fix/ts-inherit-members branch from 91ab3fa to 99449c6 Compare March 4, 2017 15:34
@devversion
Copy link
Member Author

@petebacondarwin Made the requested changes. Please review again.

**/
module.exports = function linkInheritedDocs(typescriptSymbolMap) {
return {
$runAfter: ['readTypeScriptModules'],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is probably worth putting in a $runBefore property too, since we can't guarantee that it will be run before other processors otherwise...

* To ensure that Dgeni properly recognizes classes from exports that will be parsed later,
* the `FirstParent` class will be ordered after the `Child` class.
**/
export class FirstParent extends LastParent {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it worth putting in some implements clauses to see what would happen?

@devversion
Copy link
Member Author

@petebacondarwin Ping for review :)

@petebacondarwin
Copy link
Contributor

We got there!
Landed and published as 0.16.9
Thanks for your hard work and patience @devversion

petebacondarwin pushed a commit that referenced this pull request Mar 7, 2017
Introduce a new property `doc.inheritedDocs` on export docs that links
to the class docs that this doc inherited from.

This can be used in templates to show members for a class that were
inherited from other classes.

Closes #207
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants