Doctrine is a JavaScript JSDoc parser library designed to extract and interpret documentation comments. It specializes in processing individual JSDoc comment blocks, returning a structured Abstract Syntax Tree (AST) that details the comment's tags, types, descriptions, and other metadata. The package version provided is 2.1.0, though a significant v3.0.0 release exists with updated Node.js support. Maintained by the ESLint team, Doctrine's release cadence is irregular, typically addressing bug fixes and minor enhancements as needed by dependent projects. Its primary differentiating factor is its focused scope: it parses only JSDoc comments themselves, not full JavaScript files, making it a critical component for tools like linters (e.g., ESLint), documentation generators, and static analysis utilities that require granular access to JSDoc information.
npm install doctrine-temporary-forkVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to parse a JSDoc comment string using `doctrine.parse()` and inspect the resulting Abstract Syntax Tree (AST), including tag details and parsing options.
Upgrade your Node.js environment to version 6 or higher, or explicitly lock your `doctrine` dependency to a `2.x` version (e.g., `"doctrine": "^2.0.0"`).
Review the Apache License 2.0 to ensure compatibility with your project's licensing requirements. Consult legal counsel if necessary.
Extract only the JSDoc comment string (e.g., `/** ... */`) and pass it to `doctrine.parse()`. Use a separate JavaScript parser (like Acorn or Esprima) to extract comment nodes from a full file first.
When calling `doctrine.parse()`, include the option `{ sloppy: true }` in the options object to enable parsing of bracketed optional parameters.For CommonJS, use `const { parse } = require('doctrine');` or `const doctrine = require('doctrine'); const ast = doctrine.parse(...);`. For ESM, as Doctrine is primarily CJS, direct named imports for its properties are not natively supported; consider dynamic import or a bundler for interop.Review the JSDoc comment for correctness. If using optional parameters with brackets (e.g., `@param {string} [foo]`), ensure `{ sloppy: true }` is passed to `doctrine.parse()`. Consider `{ recoverable: true }` to gather all errors rather than stopping on the first one.Ensure the package is installed (`npm install doctrine`). For Node.js CommonJS files, use `require()`. For ESM projects, configure your bundler (e.g., Webpack, Rollup) to handle CommonJS modules, or consider using dynamic import with `const doctrine = await import('doctrine');` for Node.js ESM.No dependency data recorded yet.