scss-comment-parser is a JavaScript library designed to parse `///` style comments within SCSS files and extract structured context information. It is primarily used to generate documentation, serving as a core component for tools like SassDoc. The current stable version is 0.8.4. While not on a rapid release cycle (last updated in 2018), it receives maintenance updates for bug fixes and dependency upgrades. Key differentiators include its specific focus on SassDoc-style comment syntax, its ability to extract detailed SCSS context (including variables, mixins, functions, placeholders, and CSS selectors), and support for custom annotation definitions, allowing for flexible documentation generation workflows. It processes SCSS code to identify comment blocks and their associated code, providing a structured JSON output.
npm install scss-comment-parserVerified import paths — ran on the pinned version, not inferred.
Initializes the parser with custom annotations, processes a sample SCSS string containing various comment types and code contexts, and logs the extracted documentation data in a formatted JSON output.
Review existing code that processes `context.code` and adjust expectations for the content format. Manual re-addition of braces might be necessary if the raw string is critical.
For CommonJS, use `const ScssCommentParser = require('scss-comment-parser');`. For ES Modules, consider using a dynamic import (`import('scss-comment-parser').then(module => new module.default(...))`) or explicitly handling CommonJS interop.Thoroughly test parsed output when upgrading `scss-comment-parser` to ensure no regressions or unexpected changes in the extracted comment and context data occur.
Ensure you are using `const ScssCommentParser = require('scss-comment-parser');` for CommonJS. If in ESM, try `import * as ScssCommentParserModule from 'scss-comment-parser'; const ScssCommentParser = ScssCommentParserModule.default;` or the dynamic import pattern.Verify that `require('scss-comment-parser')` successfully returns the constructor and that `new ScssCommentParser(...)` is called with valid arguments before attempting to call `.parse()`.For modern Node.js ESM environments, switch to `import` syntax or use a dynamic `import()`. If strictly needing `require`, ensure your file is treated as CommonJS (e.g., `.js` extension without `type: "module"` in `package.json`, or `.cjs` extension).