From d20ba1daa2e2747f5c90a7c2b35a6384e98262be Mon Sep 17 00:00:00 2001 From: Shukant Pal Date: Mon, 6 Jun 2022 22:08:06 -0400 Subject: [PATCH] Fix: Make @function override document type and allow standalone doc comments for @function (#167) --- .../src/tag-parsers/parseSimple.js | 1 + .../src/transformer/symbol-to-doc.js | 1 + packages/webdoc-parser/test/parse.js | 38 +++++++++++++++++++ 3 files changed, 40 insertions(+) diff --git a/packages/webdoc-parser/src/tag-parsers/parseSimple.js b/packages/webdoc-parser/src/tag-parsers/parseSimple.js index a9d58887..c195cc23 100644 --- a/packages/webdoc-parser/src/tag-parsers/parseSimple.js +++ b/packages/webdoc-parser/src/tag-parsers/parseSimple.js @@ -123,6 +123,7 @@ export function parseName(value: string, doc: $Shape): $Shape return { alias: value, type: "NameTag", + value, }; } diff --git a/packages/webdoc-parser/src/transformer/symbol-to-doc.js b/packages/webdoc-parser/src/transformer/symbol-to-doc.js index 201b69de..27bcc34a 100644 --- a/packages/webdoc-parser/src/transformer/symbol-to-doc.js +++ b/packages/webdoc-parser/src/transformer/symbol-to-doc.js @@ -122,6 +122,7 @@ const TAG_OVERRIDES: { [id: string]: string | any } = { // replace any, no lazy "typedef": "TypedefDoc", "namespace": "NSDoc", "event": "EventDoc", + "function": "FunctionDoc", }; // Tags that end only when another tag is found or two lines are blank for consecutively diff --git a/packages/webdoc-parser/test/parse.js b/packages/webdoc-parser/test/parse.js index 6895269a..6b30ee10 100644 --- a/packages/webdoc-parser/test/parse.js +++ b/packages/webdoc-parser/test/parse.js @@ -210,4 +210,42 @@ describe("@webdoc/parser.parse", function() { expect(docKeyEnum.members.length).to.equal(3); }); + + it("should parse method overloads in orphan doc comments", async function() { + const documentTree = await parse(` + /** Rectangle */ + class Rect { + /** + * Returns true if the rectangle contains the given rectangle + * @name contains + * @memberof Rect + * @function + * @param {Rect} rect + * @returns {boolean} true if contains + */ + + /** + * Returns true if the rectangle contains the given point + * @name contains + * @memberof Rect + * @function + * @param {number} x - x coordinate + * @param {number} y - y coordinate + * @returns {boolean} true if contains + */ + + /** + * Returns true if the rectangle contains the given point + * @name contains + * @memberof Rect + * @function + * @param {Vector2d} point + * @returns {boolean} true if contains + */ + contains() { } + } + `); + + expect(findDoc("Rect", documentTree).members.length).to.equal(4); + }); });