From bebc700a5e6da4314e07563ad2e4dc02018d8fb3 Mon Sep 17 00:00:00 2001 From: Daniel Knights <59598622+Daniel-Knights@users.noreply.github.com> Date: Tue, 27 Aug 2024 09:30:49 +0100 Subject: [PATCH 1/2] Fix class leading comments order --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index d9e8174..8724252 100644 --- a/index.js +++ b/index.js @@ -216,7 +216,7 @@ exports.astNodeVisitor = { comment.value.indexOf('@classdesc') !== -1 || !noClassdescRegEx.test(comment.value) ) { - node.leadingComments.push(comment); + node.leadingComments.unshift(comment); node.parent.leadingComments.splice(i, 1); const ignore = parser.astBuilder.build('/** @ignore */').comments[0]; From bf6b34542fa29f72f4f7b009220f9144097d56b2 Mon Sep 17 00:00:00 2001 From: Daniel Knights <59598622+Daniel-Knights@users.noreply.github.com> Date: Thu, 5 Sep 2024 23:10:47 +0100 Subject: [PATCH 2/2] Class leading comments order test --- test/dest/expected.json | 45 ++++++++++++++++++++++++++++++++- test/src/sub/LeadingComments.js | 14 ++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 test/src/sub/LeadingComments.js diff --git a/test/dest/expected.json b/test/dest/expected.json index b616185..11f8fd4 100644 --- a/test/dest/expected.json +++ b/test/dest/expected.json @@ -237,6 +237,49 @@ "scope": "inner", "memberof": "module:test" }, + { + "comment": "/** @ignore */", + "meta": { + "range": [ + 434, + 465 + ], + "filename": "LeadingComments.js", + "lineno": 14, + "columnno": 0, + "code": { + "name": "exports.LeadingComments", + "type": "ClassDeclaration" + } + }, + "ignore": true, + "name": "LeadingComments", + "longname": "LeadingComments", + "kind": "class", + "scope": "global" + }, + { + "comment": "/**\n * Doclet\n */", + "meta": { + "range": [ + 441, + 465 + ], + "filename": "LeadingComments.js", + "lineno": 14, + "columnno": 7, + "code": { + "name": "LeadingComments", + "type": "ClassDeclaration", + "paramnames": [] + } + }, + "classdesc": "Doclet", + "name": "LeadingComments", + "longname": "LeadingComments", + "kind": "class", + "scope": "global" + }, { "comment": "/**\n * @module test/sub/NumberStore\n */", "meta": { @@ -465,4 +508,4 @@ "longname": "module:test/sub/NumberStore", "kind": "member" } -] +] \ No newline at end of file diff --git a/test/src/sub/LeadingComments.js b/test/src/sub/LeadingComments.js new file mode 100644 index 0000000..4b1ce07 --- /dev/null +++ b/test/src/sub/LeadingComments.js @@ -0,0 +1,14 @@ +// Import statement required for JSDoc to include first comment as leading comment of the class. +// Otherwise, it gets moved in the AST to the `Program` node from the `ExportNamedDeclaration` class node: +// https://github.com/jsdoc/jsdoc/blob/main/packages/jsdoc-ast/lib/walker.js#L465 +// This itself may be a bug, as it seems to be intended for @module comments. +import ''; // eslint-disable-line + +/* + Comment +*/ + +/** + * Doclet + */ +export class LeadingComments {}