Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Fix converting single line JSDoc comment to AST
- Loading branch information
Showing
3 changed files
with
142 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
node_modules | ||
coverage | ||
/.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import {expect} from 'chai'; | ||
|
||
import {commentParserToESTree} from '../src/commentParserToESTree.js'; | ||
import {parseComment} from '../src/parseComment.js'; | ||
|
||
describe('commentParserToESTree', function () { | ||
it('handles single line jsdoc comment with tag', () => { | ||
const parsedComment = parseComment({ | ||
value: `* @type {string} ` | ||
}); | ||
|
||
const ast = commentParserToESTree(parsedComment, 'javascript'); | ||
|
||
expect(ast).to.deep.equal({ | ||
type: 'JsdocBlock', | ||
delimiter: '/**', | ||
description: '', | ||
descriptionLines: [], | ||
end: '*/', | ||
lastDescriptionLine: 0, | ||
lineEnd: '', | ||
postDelimiter: ' ', | ||
tags: [ | ||
{ | ||
delimiter: '/**', | ||
description: '', | ||
descriptionLines: [], | ||
lineEnd: '', | ||
name: '', | ||
parsedType: null, | ||
postDelimiter: ' ', | ||
postName: '', | ||
postTag: ' ', | ||
postType: ' ', | ||
tag: 'type', | ||
type: 'JsdocTag', | ||
rawType: 'string', | ||
start: '', | ||
typeLines: [ | ||
{ | ||
delimiter: '/**', | ||
postDelimiter: ' ', | ||
rawType: 'string', | ||
start: '', | ||
type: 'JsdocTypeLine' | ||
} | ||
] | ||
} | ||
] | ||
}); | ||
}); | ||
|
||
it('handles multi line jsdoc comment with tag', () => { | ||
const parsedComment = parseComment({ | ||
value: '*\n' + | ||
' * @type {string}\n' + | ||
' *' | ||
}); | ||
|
||
const ast = commentParserToESTree(parsedComment, 'javascript'); | ||
|
||
expect(ast).to.deep.equal({ | ||
type: 'JsdocBlock', | ||
delimiter: '/**', | ||
description: '', | ||
descriptionLines: [], | ||
end: '*/', | ||
lastDescriptionLine: 0, | ||
lineEnd: '', | ||
postDelimiter: '', | ||
tags: [ | ||
{ | ||
delimiter: '*', | ||
description: '', | ||
descriptionLines: [], | ||
lineEnd: '', | ||
name: '', | ||
parsedType: null, | ||
postDelimiter: ' ', | ||
postName: '', | ||
postTag: ' ', | ||
postType: '', | ||
tag: 'type', | ||
type: 'JsdocTag', | ||
rawType: 'string', | ||
start: ' ', | ||
typeLines: [ | ||
{ | ||
delimiter: '*', | ||
postDelimiter: ' ', | ||
rawType: 'string', | ||
start: ' ', | ||
type: 'JsdocTypeLine' | ||
} | ||
] | ||
} | ||
] | ||
}); | ||
}); | ||
}); |