-
Notifications
You must be signed in to change notification settings - Fork 106
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
Use TypeScript modifiers to determine access #176
Comments
This sounds good to me. Anyone fancy putting a PR together? |
@petebacondarwin, I suppose 'hidePrivateMembers' should be a feature of the document renderer. As by now I build docs for a mixed-source project and I dislike the idea of using such property on each processor. |
It's a bit more complicated than just rendering. For instance, what if someone created a Perhaps we could have a simple processor that runs after the API docs have been read/created and removes those that are marked as private? This would have to run quite early in the pipeline to prevent other processors from picking up those docs. |
Renderer should not 'ignore' private members, but follow the links as well. It is a good idea to follow jsdoc behaviour and allow to choose which parts are accessible after rendering. |
Issue #168 added code to allow us to use the @Private, @Protected and @public tags in TypeScript but I think the point was missed. The promise of using TypeScript is that we shouldn't have to define some of our commenting metadata. TypeScript already provides facilities to determine the access level of a method and we should use that. With that said, here's what needs to be done in readTypeScriptModules.js:
We need to create a function that knows how to determine what access level the current member is. Each memberSymbol has a property that may contain its modifiers. Also, there are more modifiers than just public, private and protected, so we need to filter on the ones we're interested in.
Next we modifiy
createMemberDoc
to callgetAccess
:We update code that wants to know of the member is private or not. Specifically I'm talking about the hidePrivateMember check. Previously it was:
} else if (!hidePrivateMembers || memberSymbol.name.charAt(0) !== '_') {
but now it should be
} else if (!hidePrivateMembers || memberDoc.access != "private") {
Changing number 3 also fixes what I believe to be a bug. If you define an index property on a class, TypeScript exposes it as
__index
but if you hidePrivateMembers and use '_' as your basis for determining private members, you lose the ability to inform your API consumer that there is an index on the class and that doingmyObj["key"] = value
is ok.I've modified my local version with this code, so it works as-is but I can see where it may need some work. I would have made a pull request but time constraints on my current project prevents me from delving to deep with this. I hope this code makes it into the codebase in some form.
The text was updated successfully, but these errors were encountered: