Registry / serialization / doctrine-temporary-fork

doctrine-temporary-fork

JSON →
library2.1.0jsnpmunverified

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-fork
INSTALL
IMPORT
SIG · DOCTRINE-TEMPORARY
D
doctrine-temporary-fork
serializationjavascriptv2.1.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

doctrine
const doctrine = require('doctrine');
import { doctrine } from 'doctrine';
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.
parse
const { parse } = require('doctrine');
import { parse } from 'doctrine';
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.
Parser
const { Parser } = require('doctrine');
import { Parser } from 'doctrine';
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.

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.

const doctrine = require("doctrine"); // JSDoc comment to parse const jsdocComment = [ "/**", " * This function comment is parsed by doctrine.", " * @param {{ok:String}} userName - The user's name.", " * @returns {boolean} True if operation was successful, false otherwise.", " * @example", " * function greet(userName) { /* ... */ }", "*/" ].join('\n'); try { const ast = doctrine.parse(jsdocComment, { unwrap: true, recoverable: true, lineNumbers: true, range: true }); console.log("Parsed AST:"); console.log(JSON.stringify(ast, null, 2)); // Example of accessing specific tags const paramTag = ast.tags.find(tag => tag.title === 'param'); if (paramTag) { console.log("\n@param tag details:"); console.log(` Name: ${paramTag.name}`); console.log(` Type: ${paramTag.type.name}`); console.log(` Description: ${paramTag.description}`); } } catch (error) { console.error("Error parsing JSDoc comment:", error.message); }
Debug
Known issues
breakingVersion 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`.
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"`).
affects: >=3.0.0
breakingEffective 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.
fix
Review the Apache License 2.0 to ensure compatibility with your project's licensing requirements. Consult legal counsel if necessary.
affects: >=2.0.0
gotchaDoctrine 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.
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.
affects: all
gotchaBy 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.
fix
When calling `doctrine.parse()`, include the option `{ sloppy: true }` in the options object to enable parsing of bracketed optional parameters.
affects: all
Errors
Common errors & fixes
TypeError: doctrine.parse is not a function
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'.
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.
SyntaxError: Unexpected token
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`).
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.
Error: Cannot find module 'doctrine'
Attempting to import a CommonJS-only module using native ESM `import` syntax without proper interop or bundler configuration, or the package is not installed.
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.
Upgrade
Version history
2.1.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
9 hits · last 30 days
node
8
Amazon
1
Resources
doctrine-temporary-fork — npm install doctrine-temporary-fork · libregistry