diff options
author | Matthew Miller <matthew@millerti.me> | 2020-05-29 15:15:28 -0700 |
---|---|---|
committer | Matthew Miller <matthew@millerti.me> | 2020-05-29 15:15:28 -0700 |
commit | 94da8b7e7750c6c61526975aad302d5ac4e2d063 (patch) | |
tree | 6be2adb04bcd318517453a66be1a00e4660e99b8 /typedoc-plugin-external-module-name/getRawComment.js | |
parent | 2df680164690e5b87bbc581280c22cb54577a923 (diff) |
Temporarily host a modified typedoc plugin
Diffstat (limited to 'typedoc-plugin-external-module-name/getRawComment.js')
-rw-r--r-- | typedoc-plugin-external-module-name/getRawComment.js | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/typedoc-plugin-external-module-name/getRawComment.js b/typedoc-plugin-external-module-name/getRawComment.js new file mode 100644 index 0000000..1bc208f --- /dev/null +++ b/typedoc-plugin-external-module-name/getRawComment.js @@ -0,0 +1,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(); + } + } +}); |