Skip to content

Commit

Permalink
Merge pull request #58 from Daniel-Knights/fix-class-leading-comments…
Browse files Browse the repository at this point in the history
…-order

Fix class leading comments order
  • Loading branch information
ahocevar authored Sep 13, 2024
2 parents 369ae45 + bf6b345 commit c0a0dcb
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,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];
Expand Down
43 changes: 43 additions & 0 deletions test/dest/expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
14 changes: 14 additions & 0 deletions test/src/sub/LeadingComments.js
Original file line number Diff line number Diff line change
@@ -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 {}

0 comments on commit c0a0dcb

Please sign in to comment.