{"id":15083,"library":"babel-extract-comments","title":"Babel Comment Extractor","description":"The `babel-extract-comments` library is a utility designed to parse JavaScript code and extract its associated comments, leveraging Babel's (specifically, its earlier parser Babylon) capabilities. It provides methods to process either a JavaScript string or a file path, returning an array of structured comment objects. Each object in the array details the comment's `type` (e.g., 'CommentBlock', 'CommentLine'), its raw `value`, and precise `start` and `end` character positions, along with `loc` (source location data including line and column numbers). The package's current and only major version is 1.0.0, last published in February 2018. Due to its age and lack of subsequent updates, it exclusively supports CommonJS module loading patterns and relies on older Babel parsing internals, making it unsuitable for projects requiring modern JavaScript syntax parsing or native ESM integration. Users should be aware of its abandoned status and potential compatibility issues with contemporary JavaScript language features.","status":"abandoned","version":"1.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/jonschlinkert/babel-extract-comments","tags":["javascript","babel","block","code","comment","comments","context","extract","glob"],"install":[{"cmd":"npm install babel-extract-comments","lang":"bash","label":"npm"},{"cmd":"yarn add babel-extract-comments","lang":"bash","label":"yarn"},{"cmd":"pnpm add babel-extract-comments","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package is CommonJS-only and does not support ESM imports. Attempting ESM import will result in a runtime error.","wrong":"import extract from 'babel-extract-comments';","symbol":"extract","correct":"const extract = require('babel-extract-comments');"},{"note":"The `.file` method is accessed as a property of the default CommonJS import. Direct named ESM imports are not supported.","wrong":"import { file } from 'babel-extract-comments';","symbol":"extract.file","correct":"const extract = require('babel-extract-comments');\nconst commentsFromFile = extract.file('./path/to/my-file.js');"}],"quickstart":{"code":"const extract = require('babel-extract-comments');\nconst fs = require('fs');\n\nconst jsString = `\n// This is a line comment\n/**\n * This is a block comment.\n * It can span multiple lines.\n */\nconst myVariable = 123; // Inline comment\n\n/* Another block comment */\nfunction myFunction() {\n  /*\n   * Multi-line\n   * function comment\n   */\n  console.log('Hello');\n}\n`;\n\n// Extract comments from a string\nconst stringComments = extract(jsString);\nconsole.log('Comments from string:', JSON.stringify(stringComments, null, 2));\n\n// Create a dummy file for .file method demonstration\nconst filePath = './temp-script.js';\nfs.writeFileSync(filePath, jsString);\n\n// Extract comments from a file\nconst fileComments = extract.file(filePath);\nconsole.log('\\nComments from file:', JSON.stringify(fileComments, null, 2));\n\n// Clean up the dummy file\nfs.unlinkSync(filePath);\n","lang":"javascript","description":"Demonstrates extracting comments from both a JavaScript string and a file using the `extract` function and its `.file` method. It showcases different comment types and the structure of the returned comment objects."},"warnings":[{"fix":"Always use `const extract = require('babel-extract-comments');` for importing the library.","message":"This package is CommonJS-only. Attempting to import it using ES Module syntax (`import ... from '...'`) in an ESM context will result in a runtime error.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"For parsing modern JavaScript, consider using a more actively maintained parser or comment extraction library based on a current Babel version or alternative parsers like `@babel/parser` directly, or `extract-comments` with a modern extractor plugin.","message":"The library was last published in 2018 and uses an older version of Babel's parser (Babylon). It may not correctly parse or may throw errors when encountering modern JavaScript syntax (e.g., optional chaining, nullish coalescing, private class fields, top-level await) introduced after ES2017.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Evaluate alternatives if your project requires active maintenance, support for modern JavaScript, or strict security posture. If used, pin the version exactly to avoid unexpected issues.","message":"The project appears to be abandoned, with no updates or new versions released since 2018. This implies a lack of support for bug fixes, security patches, or new feature development, making it a risky dependency for new projects or those requiring long-term stability.","severity":"deprecated","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"Change your import statement to `const extract = require('babel-extract-comments');`","cause":"Attempting to use an ES Module `import` statement for a CommonJS-only package, trying to access a default export that doesn't exist in the ES Module wrapper.","error":"TypeError: (0, _babelExtractComments.default) is not a function"},{"fix":"Either refactor the JavaScript code to use older syntax, or switch to a different, actively maintained comment extraction library that supports modern ECMAScript features.","cause":"The input JavaScript string or file contains syntax features (e.g., optional chaining `?.`, nullish coalescing `??`, private class fields `#`) that are not supported by the older Babel parser version used by this library.","error":"SyntaxError: Unexpected token"}],"ecosystem":"npm"}