Skip to content

Commit

Permalink
Add test for undocumented declaration (// comment)
Browse files Browse the repository at this point in the history
  • Loading branch information
oandregal committed Jan 24, 2019
1 parent bcf94b4 commit 843ac66
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/docgen/src/get-jsdoc-from-token.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const getLeadingComments = require( './get-leading-comments' );
module.exports = function( token ) {
let jsdoc;
const comments = getLeadingComments( token );
if ( comments ) {
if ( comments && comments.startsWith( '*\n' ) ) {
jsdoc = doctrine.parse( comments, { unwrap: true, recoverable: true } );
}
return jsdoc;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// This comment should be ignored
export default function() { }
45 changes: 45 additions & 0 deletions packages/docgen/tests/fixtures/default-undocumented-oneliner.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"type": "ExportDefaultDeclaration",
"start": 34,
"end": 63,
"range": [
34,
63
],
"declaration": {
"type": "FunctionDeclaration",
"start": 49,
"end": 63,
"range": [
49,
63
],
"id": null,
"generator": false,
"expression": false,
"async": false,
"params": [],
"body": {
"type": "BlockStatement",
"start": 60,
"end": 63,
"range": [
60,
63
],
"body": []
}
},
"leadingComments": [
{
"type": "Line",
"value": " This comment should be ignored",
"start": 0,
"end": 33,
"range": [
0,
33
]
}
]
}
9 changes: 9 additions & 0 deletions packages/docgen/tests/test-get-intermediate-representation.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ test( 'IR - undocumented', function( t ) {
description: 'Undocumented declaration.',
tags: [],
} ] );
const tokenOneliner = fs.readFileSync(
path.join( __dirname, './fixtures/default-undocumented-oneliner.json' ),
'utf-8'
);
t.deepEqual( getIntermediateRepresentation( JSON.parse( tokenOneliner ) ), [ {
name: 'default',
description: 'Undocumented declaration.',
tags: [],
} ] );
t.end();
} );

Expand Down

0 comments on commit 843ac66

Please sign in to comment.