This repository was archived by the owner on Mar 31, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 100
feat(typescript): class docs should link to inherited class docs #207
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4c5b2cc
feat(typescript): class docs should link to inherited class docs
devversion 99449c6
Updates
devversion a02738d
rename to TypeScript Symbol Map
devversion 538e8cd
Add test interface
devversion d97e1e6
Run before parsing-tags
devversion File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,4 +21,5 @@ coverage | |
|
|
||
| .tmp | ||
|
|
||
| debug-dump.txt | ||
| debug-dump.txt | ||
| .idea/ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
typescript/mocks/readTypeScriptModules/inheritedMembers.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| export class LastParent implements TestInterface { | ||
| lastParentProp: number = 0; | ||
| } | ||
|
|
||
| export class Child extends FirstParent implements TestInterface { | ||
| childProp: boolean = false; | ||
| } | ||
|
|
||
| /** | ||
| * 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 implements TestInterface { | ||
| firstParentProp: string = 'Works'; | ||
| _privateProp: string = 'Private'; | ||
| private privateProp: string = 'Private'; | ||
| } | ||
|
|
||
| /** | ||
| * This is just a test interface that has been added to ensure that Dgeni only recognizes | ||
| * extends heritages. | ||
| **/ | ||
| export interface TestInterface {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| /** | ||
| * Processor that links the inherited symbols to the associating dgeni doc. | ||
| **/ | ||
| module.exports = function linkInheritedDocs(typescriptSymbolMap) { | ||
| return { | ||
| $runAfter: ['readTypeScriptModules'], | ||
| $runBefore: ['parsing-tags'], | ||
| $process: docs => { | ||
| // Iterate through all docs and link the doc symbols if present. | ||
| docs.filter(doc => doc.inheritedSymbols).forEach(doc => linkDocSymbols(doc)) | ||
| } | ||
| }; | ||
|
|
||
| function linkDocSymbols(doc) { | ||
| doc.inheritedDocs = []; | ||
| doc.inheritedSymbols.forEach(symbol => doc.inheritedDocs.push(typescriptSymbolMap.get(symbol))); | ||
| } | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| const mockPackage = require('../mocks/mockPackage'); | ||
| const Dgeni = require('dgeni'); | ||
| const path = require('canonical-path'); | ||
|
|
||
| describe('linkInheritedDocs', function() { | ||
|
|
||
| let dgeni, injector, tsProcessor, linkProcessor = null; | ||
|
|
||
| beforeEach(function () { | ||
| dgeni = new Dgeni([mockPackage()]); | ||
| injector = dgeni.configureInjector(); | ||
|
|
||
| tsProcessor = injector.get('readTypeScriptModules'); | ||
| linkProcessor = injector.get('linkInheritedDocs'); | ||
|
|
||
| // Since the `readTypeScriptModules` mock folder includes the a good amount files, the | ||
| // spec for linking the inherited docs will just use those. | ||
| tsProcessor.basePath = path.resolve(__dirname, '../mocks/readTypeScriptModules'); | ||
| }); | ||
|
|
||
| it('should properly link the inherited docs', () => { | ||
| let docsArray = []; | ||
|
|
||
| tsProcessor.sourceFiles = ['inheritedMembers.ts']; | ||
|
|
||
| tsProcessor.$process(docsArray); | ||
| linkProcessor.$process(docsArray); | ||
|
|
||
| let childDoc = docsArray[3]; | ||
| let firstParentDoc = docsArray[5]; | ||
| let lastParentDoc = docsArray[1]; | ||
|
|
||
| expect(childDoc.inheritedDocs).toEqual([firstParentDoc]); | ||
| expect(firstParentDoc.inheritedDocs).toEqual([lastParentDoc]); | ||
| expect(lastParentDoc.inheritedDocs).toEqual([]); | ||
| }); | ||
|
|
||
| it('should properly resolve members in inherited docs', () => { | ||
| let docsArray = []; | ||
|
|
||
| tsProcessor.sourceFiles = ['inheritedMembers.ts']; | ||
|
|
||
| tsProcessor.$process(docsArray); | ||
| linkProcessor.$process(docsArray); | ||
|
|
||
| let childDoc = docsArray[3]; | ||
| let members = getInheritedMembers(childDoc); | ||
|
|
||
| expect(members.length).toBe(3); | ||
| expect(members[0].name).toBe('childProp'); | ||
| expect(members[1].name).toBe('firstParentProp'); | ||
| expect(members[2].name).toBe('lastParentProp'); | ||
| }); | ||
|
|
||
| /** Returns a list of all inherited members of a doc. */ | ||
| function getInheritedMembers(doc) { | ||
| let members = doc.members || []; | ||
|
|
||
| doc.inheritedDocs.forEach(inheritedDoc => { | ||
| members = members.concat(getInheritedMembers(inheritedDoc)); | ||
| }); | ||
|
|
||
| return members; | ||
| } | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| /** | ||
| * Service that can be used to store typescript symbols with their associated dgeni doc. | ||
| **/ | ||
| module.exports = function typescriptSymbolMap() { | ||
| return new Map(); | ||
| }; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
$runBeforeproperty too, since we can't guarantee that it will be run before other processors otherwise...