-
Notifications
You must be signed in to change notification settings - Fork 6.8k
chore: filter alias exports in docs #8782
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
josephperrott
merged 1 commit into
angular:master
from
devversion:chore/filter-export-aliases
Dec 20, 2017
Merged
Changes from all commits
Commits
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
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,48 @@ | ||
import {DocCollection, Processor} from 'dgeni'; | ||
import {ExportDoc} from 'dgeni-packages/typescript/api-doc-types/ExportDoc'; | ||
import {ModuleDoc} from 'dgeni-packages/typescript/api-doc-types/ModuleDoc'; | ||
|
||
/** | ||
* Processor to filter out Dgeni documents that are export aliases. Keeping them means | ||
* that a given document shows up multiple times in the docs. | ||
* | ||
* ```ts | ||
* export {ObserveContent} from './X'; | ||
* export {ObserveContent as CdkObserveContent} from './X'; | ||
* ``` | ||
* | ||
* This is a common pattern inside of Angular Material, but causes Dgeni to generate | ||
* documents for both exports. The second document is identical to the original document and | ||
* doesn't even show the aliased name. | ||
* | ||
* See: https://github.com/angular/dgeni-packages/issues/248 | ||
*/ | ||
export class FilterExportAliases implements Processor { | ||
name = 'filter-export-aliases'; | ||
$runBefore = ['categorizer']; | ||
|
||
$process(docs: DocCollection) { | ||
return docs.filter(doc => this.filterAliasExport(doc)); | ||
} | ||
|
||
private filterAliasExport(doc: ExportDoc) { | ||
if (!doc.moduleDoc) { | ||
return true; | ||
} | ||
|
||
const moduleDoc = doc.moduleDoc as ModuleDoc; | ||
const duplicateDocs = moduleDoc.exports.filter(exportDoc => exportDoc.id === doc.id); | ||
|
||
// Remove the current export document if there are multiple Dgeni export documents with the | ||
// same document id. If there are multiple docs with the same id, we can assume that this doc | ||
// is an alias export. | ||
if (duplicateDocs && duplicateDocs.length > 1) { | ||
moduleDoc.exports.splice( | ||
moduleDoc.exports.findIndex(exportDoc => exportDoc.id === doc.id), 1); | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
} |
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.
Is there any way to more specifically target things marked as
@deprecated
? It's possible we may want to re-export something not as a deprecation, but as an alternate name (e.g. re-exporting something from cdk with "mat").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.
I see. Unfortunately it's not possible to detect if the re-export was marked as deprecated.
Dgeni doesn't provide access to the export statement/symbol. In theory it would be possible to walk through imports file by file using the AST, but this more turns into it's own docs generation tool then.
I assume even Dgeni in general (with angular/dgeni-packages#248) won't be able to differentiate between deprecated re-exports or normal re-exports.
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.
What if we formatted it like this?
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.
Just tried that, but that information is being lost as well.