{"id":13077,"library":"doctrine-temporary-fork","title":"Doctrine JSDoc Parser","description":"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.","status":"active","version":"2.1.0","language":"javascript","source_language":"en","source_url":"https://github.com/eslint/doctrine","tags":["javascript"],"install":[{"cmd":"npm install doctrine-temporary-fork","lang":"bash","label":"npm"},{"cmd":"yarn add doctrine-temporary-fork","lang":"bash","label":"yarn"},{"cmd":"pnpm add doctrine-temporary-fork","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package is primarily CommonJS. Direct ESM 'import' may require Node.js `--experimental-json-modules` or bundler configuration for interop. The 'doctrine' object contains all parsing utilities.","wrong":"import { doctrine } from 'doctrine';","symbol":"doctrine","correct":"const doctrine = require('doctrine');"},{"note":"The 'parse' function is a property of the object exported by the 'doctrine' module, not a top-level named export itself in CommonJS. It must be accessed via the module's main export.","wrong":"import { parse } from 'doctrine';","symbol":"parse","correct":"const { parse } = require('doctrine');"},{"note":"The 'Parser' constructor is a property of the 'doctrine' module's main export, used for advanced or custom parsing scenarios. Not a direct named ESM export.","wrong":"import { Parser } from 'doctrine';","symbol":"Parser","correct":"const { Parser } = require('doctrine');"}],"quickstart":{"code":"const doctrine = require(\"doctrine\");\n\n// JSDoc comment to parse\nconst jsdocComment = [\n    \"/**\",\n    \" * This function comment is parsed by doctrine.\",\n    \" * @param {{ok:String}} userName - The user's name.\",\n    \" * @returns {boolean} True if operation was successful, false otherwise.\",\n    \" * @example\",\n    \" * function greet(userName) { /* ... */ }\",\n    \"*/\"\n].join('\\n');\n\ntry {\n    const ast = doctrine.parse(jsdocComment, {\n        unwrap: true,\n        recoverable: true,\n        lineNumbers: true,\n        range: true\n    });\n\n    console.log(\"Parsed AST:\");\n    console.log(JSON.stringify(ast, null, 2));\n\n    // Example of accessing specific tags\n    const paramTag = ast.tags.find(tag => tag.title === 'param');\n    if (paramTag) {\n        console.log(\"\\n@param tag details:\");\n        console.log(`  Name: ${paramTag.name}`);\n        console.log(`  Type: ${paramTag.type.name}`);\n        console.log(`  Description: ${paramTag.description}`);\n    }\n\n} catch (error) {\n    console.error(\"Error parsing JSDoc comment:\", error.message);\n}","lang":"javascript","description":"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."},"warnings":[{"fix":"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\"`).","message":"Version 3.0.0 of doctrine dropped support for Node.js versions older than 6. Projects running on older Node.js environments must stick to `doctrine@2.x`.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Review the Apache License 2.0 to ensure compatibility with your project's licensing requirements. Consult legal counsel if necessary.","message":"Effective from version 2.0.0, Doctrine re-licensed its codebase to Apache License, Version 2.0. This change may have legal implications for projects depending on previous licenses.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"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.","message":"Doctrine is designed to parse individual JSDoc comment blocks, not entire JavaScript files. Attempting to pass a full file's content will result in parsing errors or incomplete results, as it lacks a full JavaScript parser.","severity":"gotcha","affected_versions":"all"},{"fix":"When calling `doctrine.parse()`, include the option `{ sloppy: true }` in the options object to enable parsing of bracketed optional parameters.","message":"By default, Doctrine does not correctly parse optional parameters specified in square brackets (e.g., `@param {string} [foo]`). The `sloppy` option must be explicitly enabled for this syntax.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"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.","cause":"Attempting to call 'parse' directly on a module imported via default ESM import or a malformed CommonJS require that doesn't correctly return the object containing 'parse'.","error":"TypeError: doctrine.parse is not a function"},{"fix":"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.","cause":"The input JSDoc comment contains syntax errors, or an unsupported JSDoc pattern is used without enabling necessary options (e.g., optional parameters in brackets without `sloppy: true`).","error":"SyntaxError: Unexpected token"},{"fix":"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.","cause":"Attempting to import a CommonJS-only module using native ESM `import` syntax without proper interop or bundler configuration, or the package is not installed.","error":"Error: Cannot find module 'doctrine'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":""}