summaryrefslogtreecommitdiffhomepage
path: root/typedoc-plugin-external-module-name/getRawComment.js
blob: 1bc208f81a663df941a303e0ada7069a0ade6748 (plain)
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
/**
 * Monkey patches getJSDocCommentRanges to make `getRawComment` return a
 * comment for a module even if there is only one comment
 *
 * @see https://github.com/christopherthielen/typedoc-plugin-external-module-name/issues/6
 * @see https://github.com/TypeStrong/typedoc/blob/master/src/lib/converter/factories/comment.ts
 */
(function (factory) {
    if (typeof module === "object" && typeof module.exports === "object") {
        var v = factory(require, exports);
        if (v !== undefined) module.exports = v;
    }
    else if (typeof define === "function" && define.amd) {
        define(["require", "exports", "typedoc/dist/lib/ts-internal", "typedoc/dist/lib/converter/factories/comment", "./typedocVersionCompatibility"], factory);
    }
})(function (require, exports) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    const _ts = require("typedoc/dist/lib/ts-internal");
    const comment_1 = require("typedoc/dist/lib/converter/factories/comment");
    const typedocVersionCompatibility_1 = require("./typedocVersionCompatibility");
    const useMonkeyPatchedGetRawComment = typedocVersionCompatibility_1.isTypedocVersion('< 0.16.0');
    function monkeyPatch() {
        const realGetJSDocCommentRanges = _ts.getJSDocCommentRanges;
        function patchedGetJSDocCommentRanges() {
            const result = realGetJSDocCommentRanges.apply(this, arguments);
            if (result && result.length === 1) {
                result.push(null);
            }
            return result;
        }
        const tsinternal = _ts;
        tsinternal.getJSDocCommentRanges = patchedGetJSDocCommentRanges;
        return function unMonkeyPatch() {
            tsinternal.getJSDocCommentRanges = realGetJSDocCommentRanges;
        };
    }
    const getRawComment = useMonkeyPatchedGetRawComment ? monkeyPatchedGetRawComment : comment_1.getRawComment;
    exports.getRawComment = getRawComment;
    function monkeyPatchedGetRawComment(node) {
        let unpatch = monkeyPatch();
        try {
            return comment_1.getRawComment(node);
        }
        finally {
            unpatch();
        }
    }
});