JSDoc Parser

3.0.0 · active · verified Tue Apr 21

Doctrine is a specialized JavaScript parser focused solely on extracting and interpreting JSDoc comments from string inputs, rather than processing entire JavaScript files. Maintained by the ESLint team, its current stable version is 3.0.0. Releases appear irregularly, often aligned with maintenance or feature updates related to its integration within the broader ESLint ecosystem. Its primary differentiator is its granular approach to JSDoc parsing, offering fine-grained control over extraction options like unwrapping comment wrappers, filtering by specific tags, and handling parsing errors. It's designed for scenarios where only the documentation blocks need analysis, making it a foundational tool for linters, documentation generators, and code analysis tools that rely on JSDoc annotations.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates basic JSDoc parsing with various options and filtering tags to obtain an AST representation.

const doctrine = require('doctrine');

// Example 1: Basic JSDoc parsing with multiple options
const comment1 = [
  '/**', 
  ' * This is a test function.', 
  ' * @param {string} name - The user\'s name.', 
  ' * @param {number} [age=30] - The user\'s age (optional).', 
  ' * @returns {boolean} True if successful, false otherwise.', 
  ' * @deprecated Use `newName` instead.',
  ' */'
].join('\n');

const ast1 = doctrine.parse(comment1, { unwrap: true, recoverable: true, sloppy: true, lineNumbers: true });
console.log('AST 1 (parsed with full options):', JSON.stringify(ast1, null, 2));

// Example 2: Parsing with specific tags only
const comment2 = [
  '/**', 
  ' * Another function.', 
  ' * @param {Object} config - Configuration object.', 
  ' * @property {string} config.url - The URL to use.', 
  ' * @todo Implement error handling.', 
  ' */'
].join('\n');

const ast2 = doctrine.parse(comment2, { unwrap: true, tags: ['param', 'property'], recoverable: true });
console.log('\nAST 2 (filtered tags):', JSON.stringify(ast2, null, 2));

view raw JSON →