forked from Orillusion/orillusion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
typedoc-plugin-not-exported.js
73 lines (73 loc) · 3.34 KB
/
typedoc-plugin-not-exported.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
"use strict";
/**
* typedoc-plugin-not-exported
* TypeDoc plugin that forces inclusion of non-exported symbols (variables)
*/
Object.defineProperty(exports, "__esModule", { value: true });
const typedoc_1 = require("typedoc"); // version 0.20.16+
const ModuleFlags = typedoc_1.TypeScript.SymbolFlags.ValueModule | typedoc_1.TypeScript.SymbolFlags.NamespaceModule;
exports.load = function (application) {
/** @type {Map<Reflection, Set<TypeScript.SourceFile>>} */
const checkedForModuleExports = new Map();
let includeTag = 'notExported';
application.options.addDeclaration({
name: 'includeTag',
help: '[typedoc-plugin-not-exported] Specify the tag name for non-exported member to be imported under',
defaultValue: includeTag,
});
application.converter.on(typedoc_1.Converter.EVENT_BEGIN, () => {
const includeTagTemp = application.options.getValue('includeTag');
if (typeof includeTagTemp === 'string') {
includeTag = includeTagTemp.toLocaleLowerCase();
}
});
application.converter.on(typedoc_1.Converter.EVENT_CREATE_DECLARATION, lookForFakeExports);
application.converter.on(typedoc_1.Converter.EVENT_END, () => {
checkedForModuleExports.clear();
});
function lookForFakeExports(context, reflection) {
// Figure out where "not exports" will be placed, go up the tree until we get to
// the module where it belongs.
let targetModule = reflection;
while (!targetModule.kindOf(typedoc_1.ReflectionKind.Module | typedoc_1.ReflectionKind.Project)) {
targetModule = targetModule.parent;
}
const moduleContext = context.withScope(targetModule);
const reflSymbol = context.project.getSymbolFromReflection(reflection);
if (!reflSymbol) {
// Global file, no point in doing anything here. TypeDoc will already
// include everything declared in this file.
return;
}
for (const declaration of reflSymbol.declarations || []) {
checkFakeExportsOfFile(declaration.getSourceFile(), moduleContext);
}
}
function checkFakeExportsOfFile(file, context) {
const moduleSymbol = context.checker.getSymbolAtLocation(file);
// Make sure we are allowed to call getExportsOfModule
if (!moduleSymbol || (moduleSymbol.flags & ModuleFlags) === 0) {
return;
}
const checkedScopes = checkedForModuleExports.get(context.scope) || new Set();
checkedForModuleExports.set(context.scope, checkedScopes);
if (checkedScopes.has(file))
return;
checkedScopes.add(file);
const exportedSymbols = context.checker.getExportsOfModule(moduleSymbol);
const symbols = context.checker
.getSymbolsInScope(file, typedoc_1.TypeScript.SymbolFlags.ModuleMember)
.filter((symbol) => {
var _a;
return ((_a = symbol.declarations) === null || _a === void 0 ? void 0 : _a.some((d) => d.getSourceFile() === file)) &&
!exportedSymbols.includes(symbol);
});
for (const symbol of symbols) {
if (symbol
.getJsDocTags()
.some((tag) => tag.name.toLocaleLowerCase() === includeTag)) {
context.converter.convertSymbol(context, symbol);
}
}
}
};