Permalink
Browse files

Add private TypeDoc plugin to remove private methods

TypeDoc inexplicably ignores the `--excludePrivate` setting for methods annotated as `/** @Private */`, but we can filter those out with a plugin.

Ref. TypeStrong/typedoc#506
  • Loading branch information...
sstephenson committed Jan 6, 2018
1 parent 7e005c1 commit 22895c43c3aaaf957f880aae9135b00a41b5acd9
View
@@ -5,22 +5,18 @@
"license": "MIT",
"scripts": {
"start": "lerna run --scope @stimulus/examples --stream start",
"clean": "rimraf dist packages/*/dist packages/*/**/dist",
"doc": "typedoc --out dist/docs --mode file --excludeNotExported packages/@stimulus/core/src",
"clean": "rimraf dist packages/**/dist",
"reset": "yarn clean && rimraf node_modules packages/**/node_modules",
"doc": "typedoc --out dist/docs --mode file --excludePrivate --excludeNotExported packages/@stimulus/core/src",
"lint": "tslint --project tsconfig.json",
"pretest": "yarn clean && yarn lint",
"test": "karma start",
"precompile": "yarn clean",
"compile": "tsc",
"predist": "yarn compile",
"dist": "node scripts/dist-to-packages.js",
"prebuild": "yarn lint && yarn dist",
"build": "lerna run build",
"prerelease": "yarn build",
"release": "lerna publish"
},
@@ -42,6 +38,7 @@
"ts-loader": "^3.2.0",
"tslint": "^5.7.0",
"typedoc": "^0.9.0",
"typedoc-plugin-stimulus": "file:packages/typedoc-plugin-stimulus",
"typescript": "^2.6.2",
"webpack": "^3.10.0"
}
@@ -101,10 +101,12 @@ export class Context implements InlineActionObserverDelegate {
// Inline action observer delegate
/** @private */
inlineActionConnected(action: Action) {
this.addAction(action)
}
/** @private */
inlineActionDisconnected(action: Action) {
this.removeAction(action)
}
@@ -54,6 +54,7 @@ export class InlineActionObserver implements TokenListObserverDelegate {
// Token list observer delegate
/** @private */
elementMatchedTokenForAttribute(element: Element, token: string, attributeName: string) {
if (this.scope.containsElement(element)) {
const action = this.buildActionForElementWithDescriptorString(element, token)
@@ -64,6 +65,7 @@ export class InlineActionObserver implements TokenListObserverDelegate {
}
}
/** @private */
elementUnmatchedTokenForAttribute(element: Element, token: string, attributeName: string) {
const action = this.getConnectedActionForElementWithDescriptorString(element, token)
if (action) {
@@ -56,10 +56,12 @@ export class Router implements TokenListObserverDelegate {
// Token list observer delegate
/** @private */
elementMatchedTokenForAttribute(element: Element, token: string, attributeName: string) {
this.connectContextForIdentifierToElement(token, element)
}
/** @private */
elementUnmatchedTokenForAttribute(element: Element, token: string, attributeName: string) {
this.disconnectContextForIdentifierFromElement(token, element)
}
@@ -1,3 +1,4 @@
/** @private */
export function attributeValueContainsToken(attributeName: string, token: string) {
return `[${attributeName}~="${token}"]`
}
@@ -0,0 +1,6 @@
const { RemovePrivateMethodsPlugin } = require("./remove_private_methods")
module.exports = pluginHost => {
const app = pluginHost.owner
app.converter.addComponent("remove-private-methods", RemovePrivateMethodsPlugin)
}
@@ -0,0 +1,16 @@
{
"name": "typedoc-plugin-stimulus",
"version": "0.9.0",
"description": "Private TypeDoc extensions",
"main": "index.js",
"scripts": {
"build": "tsc"
},
"keywords": [
"typedocplugin"
],
"private": true,
"peerDependencies": {
"typedoc": "^0.9.0"
}
}
@@ -0,0 +1,58 @@
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
exports.__esModule = true;
var CommentPlugin_1 = require("typedoc/dist/lib/converter/plugins/CommentPlugin");
var components_1 = require("typedoc/dist/lib/converter/components");
var converter_1 = require("typedoc/dist/lib/converter");
var reflections_1 = require("typedoc/dist/lib/models/reflections");
var RemovePrivateMethodsPlugin = /** @class */ (function (_super) {
__extends(RemovePrivateMethodsPlugin, _super);
function RemovePrivateMethodsPlugin() {
return _super !== null && _super.apply(this, arguments) || this;
}
RemovePrivateMethodsPlugin.prototype.initialize = function () {
this.markedReflections = [];
this.listenTo(this.owner, (_a = {},
_a[converter_1.Converter.EVENT_CREATE_SIGNATURE] = this.createSignature,
_a[converter_1.Converter.EVENT_RESOLVE_BEGIN] = this.resolveBegin,
_a));
var _a;
};
RemovePrivateMethodsPlugin.prototype.createSignature = function (context, reflection, node) {
if (reflection.flags.isPrivate) {
this.markedReflections.push(reflection);
}
};
RemovePrivateMethodsPlugin.prototype.resolveBegin = function (context, reflection, node) {
var _this = this;
this.markedReflections.forEach(function (reflection) {
_this.removeReflectionFromProject(reflection, context.project);
});
};
RemovePrivateMethodsPlugin.prototype.removeReflectionFromProject = function (reflection, project) {
CommentPlugin_1.CommentPlugin.removeReflection(project, reflection);
if (reflection.parent && (reflection.parent.kind & reflections_1.ReflectionKind.FunctionOrMethod)) {
CommentPlugin_1.CommentPlugin.removeReflection(project, reflection.parent);
}
};
RemovePrivateMethodsPlugin = __decorate([
components_1.Component({ name: "remove-private-methods" })
], RemovePrivateMethodsPlugin);
return RemovePrivateMethodsPlugin;
}(components_1.ConverterComponent));
exports.RemovePrivateMethodsPlugin = RemovePrivateMethodsPlugin;
@@ -0,0 +1,39 @@
import { CommentPlugin } from "typedoc/dist/lib/converter/plugins/CommentPlugin"
import { Component, ConverterComponent } from "typedoc/dist/lib/converter/components"
import { Context } from "typedoc/dist/lib/converter/context"
import { Converter } from "typedoc/dist/lib/converter"
import { ProjectReflection } from "typedoc/dist/lib/models/reflections/project"
import { Reflection } from "typedoc/dist/lib/models/reflections/abstract"
import { ReflectionKind } from "typedoc/dist/lib/models/reflections"
@Component({ name: "remove-private-methods" })
export class RemovePrivateMethodsPlugin extends ConverterComponent {
private markedReflections: Reflection[]
initialize() {
this.markedReflections = []
this.listenTo(this.owner, {
[Converter.EVENT_CREATE_SIGNATURE]: this.createSignature,
[Converter.EVENT_RESOLVE_BEGIN]: this.resolveBegin
})
}
createSignature(context: Context, reflection: Reflection, node?) {
if (reflection.flags.isPrivate) {
this.markedReflections.push(reflection)
}
}
resolveBegin(context: Context, reflection: Reflection, node?) {
this.markedReflections.forEach(reflection => {
this.removeReflectionFromProject(reflection, context.project)
})
}
private removeReflectionFromProject(reflection: Reflection, project: ProjectReflection) {
CommentPlugin.removeReflection(project, reflection)
if (reflection.parent && (reflection.parent.kind & ReflectionKind.FunctionOrMethod)) {
CommentPlugin.removeReflection(project, reflection.parent)
}
}
}
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"experimentalDecorators": true
}
}
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

0 comments on commit 22895c4

Please sign in to comment.