@es-joy/jsdoccomment
This project aims to preserve and expand upon the
SourceCode#getJSDocComment functionality of the deprecated ESLint method.
It also exports a number of functions currently for working with JSDoc:
API
parseComment
For parsing comment-parser in a JSDoc-specific manner.
Might wish to have tags with or without tags, etc. derived from a split off
JSON file.
commentParserToESTree
Converts comment-parser AST to ESTree/ESLint/Babel friendly AST. See the "ESLint AST..." section below.
jsdocVisitorKeys
The VisitorKeys
for JsdocBlock, JsdocDescriptionLine, and JsdocTag. More likely to be
subject to change or dropped in favor of another type parser.
jsdocTypeVisitorKeys
Just a re-export of VisitorKeys
from jsdoc-type-pratt-parser.
getDefaultTagStructureForMode
Provides info on JSDoc tags:
nameContents('namepath-referencing'|'namepath-defining'| 'dual-namepath-referencing'|false) - Whether and how a name is allowed following any type. Tags without a proper name (valuefalse) may still have a description (which can appear like a name);descriptionAllowedin such cases would betrue. The presence of a truthynameContentsvalue is therefore only intended to signify whether separate parsing should occur for a name vs. a description, and what its nature should be.nameRequired(boolean) - Whether a name must be present following any type.descriptionAllowed(boolean) - Whether a description (following any name) is allowed.typeAllowed(boolean) - Whether the tag accepts a curly bracketed portion. Even without a type, a tag may still have a name and/or description.typeRequired(boolean) - Whether a curly bracketed type must be present.typeOrNameRequired(boolean) - Whether either a curly bracketed type is required or a name, but not necessarily both.
Miscellaneous
Also currently exports these utilities, though they might be removed in the future:
getTokenizers- Used withparseComment(its main core)toCamelCase- Convert to CamelCase.hasSeeWithLink- A utility to detect if a tag is@seeand has a@linkcommentHandler- Used byeslint-plugin-jsdoc. Might be removed in future.commentParserToESTree- Converts comment-parser AST to ESTree/ESLint/Babel friendly ASTjsdocVisitorKeys- The VisitorKeys forJSDocBlock,JSDocDescriptionLine, andJSDocTag. Might change.jsdocTypeVisitorKeys- VisitorKeys forjsdoc-type-pratt-parser.getTokenizers- A utility. Might be removed in future.toCamelCase- A utility. Might be removed in future.hasSeeWithLink- A utility to detect if a tag is@seeand has a@linkdefaultNoTypes= The tags which allow no types by default:default,defaultvalue,see;defaultNoNames- The tags which allow no names by default:access,author,default,defaultvalue,description,example,exception,license,return,returns,since,summary,throws,version,variation
ESLint AST produced for comment-parser nodes (JsdocBlock, JsdocTag, and JsdocDescriptionLine)
Note: Although not added in this package, @es-joy/jsdoc-eslint-parser adds
a jsdoc property to other ES nodes (using this project's getJSDocComment
to determine the specific comment-block that will be attached as AST).
JsdocBlock
Has two visitable properties:
tags(an array ofJsdocTag; see below)descriptionLines(an array ofJsdocDescriptionLinefor multiline descriptions).
Has the following custom non-visitable property:
lastDescriptionLine- A number
May also have the following non-visitable properties from comment-parser:
description- Same asdescriptionLinesbut as a string with newlines.delimiterpostDelimiterend
JsdocTag
Has three visitable properties:
parsedType(thejsdoc-type-pratt-parserAST representaiton of the tag's type (see thejsdoc-type-pratt-parsersection below)).descriptionLines' (an array ofJsdocDescriptionLinefor multiline descriptions)typeLines(an array ofJsdocTypeLinefor multiline type strings)
May also have the following non-visitable properties from comment-parser
(note that all are included from comment-parser except end as that is only
for JSDoc blocks and note that type is renamed to rawType):
description- Same asdescriptionLinesbut as a string with newlines.rawType-comment-parserhas this named astype, but because of a conflict with ESTree usingtypefor Node type, we renamed it torawType. It is otherwise the same as incomment-parser, i.e., a string with newlines, though with the initial{and final}stripped out. SeetypeLinesfor the array version of this property.startdelimiterpostDelimitertag(this does differ fromcomment-parsernow in terms of our stripping the initial@)postTagnamepostNametypepostType
JsdocDescriptionLine
No visitable properties.
May also have the following non-visitable properties from comment-parser:
delimiterpostDelimiterstartdescription
JsdocTypeLine
No visitable properties.
May also have the following non-visitable properties from comment-parser:
delimiterpostDelimiterstartrawType- Renamed fromcomment-parserto avoid a conflict. See explanation underJsdocTag
ESLint AST produced for jsdoc-type-pratt-parser
The AST, including type, remains as is from jsdoc-type-pratt-parser.
The type will always begin with a JsdocType prefix added, along with a
camel-cased type name, e.g., JsdocTypeUnion.
The jsdoc-type-pratt-parser visitor keys are also preserved without change.
Installation
npm i @es-joy/jsdoccomment
Changelog
The changelog can be found on the CHANGES.md.
Authors and license
Brett Zamir and contributors.
MIT License, see the included LICENSE-MIT.txt file.
To-dos
- Get complete code coverage