{"id":14596,"library":"get-assigned-identifiers","title":"Get Assigned Identifiers","description":"The `get-assigned-identifiers` package provides a focused utility for JavaScript AST analysis, specifically designed to extract identifiers that are initialized by a given AST node, including those within destructuring assignments. It helps developers programmatically understand which variables are being declared or assigned in a specific scope, a common requirement for static analysis tools, code linters, and refactoring utilities. The current stable version is 1.2.0, which was published over six years ago, indicating a mature but infrequently updated library. Its primary differentiator is its single-purpose API, which allows for direct integration without the overhead of larger AST manipulation frameworks. While stable for its intended use cases, users should be aware of its age when integrating with very recent JavaScript syntax or modern AST parsers, as compatibility might not be actively maintained.","status":"maintenance","version":"1.2.0","language":"javascript","source_language":"en","source_url":"https://github.com/goto-bus-stop/get-assigned-identifiers","tags":["javascript","ast","bindings","destructuring","identifiers","names","node"],"install":[{"cmd":"npm install get-assigned-identifiers","lang":"bash","label":"npm"},{"cmd":"yarn add get-assigned-identifiers","lang":"bash","label":"yarn"},{"cmd":"pnpm add get-assigned-identifiers","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The package uses a CommonJS default export, which translates to a default import in ESM. Avoid named imports.","wrong":"import { getAssignedIdentifiers } from 'get-assigned-identifiers'","symbol":"getAssignedIdentifiers","correct":"import getAssignedIdentifiers from 'get-assigned-identifiers'"},{"note":"This is the documented and primary way to use the library in CommonJS environments.","symbol":"getAssignedIdentifiers","correct":"const getAssignedIdentifiers = require('get-assigned-identifiers')"}],"quickstart":{"code":"import { parse } from 'acorn';\nimport getAssignedIdentifiers from 'get-assigned-identifiers';\n\nconst code = `\n  const { a, b: [ c,, ...x ], d = 10 } = someComplexObject();\n  let [ e, f ] = otherArray;\n  var g = 'hello';\n`;\n\ntry {\n  const ast = parse(code, { ecmaVersion: 2020 });\n  \n  // Example 1: Destructuring declaration\n  const node1 = ast.body[0].declarations[0].id; // { a, b: [ c,, ...x ], d = 10 }\n  console.log('Identifiers from destructuring:', getAssignedIdentifiers(node1));\n  // Expected: [{ name: 'a' }, { name: 'c' }, { name: 'x' }, { name: 'd' }]\n\n  // Example 2: Array destructuring\n  const node2 = ast.body[1].declarations[0].id; // [ e, f ]\n  console.log('Identifiers from array destructuring:', getAssignedIdentifiers(node2));\n  // Expected: [{ name: 'e' }, { name: 'f' }]\n\n  // Example 3: Simple variable declaration\n  const node3 = ast.body[2].declarations[0].id; // g\n  console.log('Identifiers from simple declaration:', getAssignedIdentifiers(node3));\n  // Expected: [{ name: 'g' }]\n\n} catch (error) {\n  console.error('Error parsing code:', error.message);\n}\n","lang":"javascript","description":"Demonstrates how to parse JavaScript code using Acorn and then extract assigned identifiers from various AST node types, including object and array destructuring, and simple variable declarations."},"warnings":[{"fix":"Manually verify compatibility with your specific AST parser and JavaScript syntax target. Consider alternative, more actively maintained AST utility libraries for modern projects, or fork and update the package if critical for your use case.","message":"The `get-assigned-identifiers` package has not been updated in over six years (last release v1.2.0). While its core functionality remains sound for older JavaScript syntax and AST specifications, it may not correctly parse or handle identifiers from very recent ECMAScript features (e.g., private class fields, new `import`/`export` syntax within modules) or be fully compatible with AST structures produced by modern parsers (e.g., Babel 7+, Acorn 8+).","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Always use a robust JavaScript parser (e.g., `acorn`, `@babel/parser`, `esprima`) to generate the AST nodes before passing them to `getAssignedIdentifiers`.","message":"The package expects an AST node from a parser like Acorn or Esprima. It does not provide its own parser. Ensure you are passing a valid AST node, typically an `Identifier` or `ObjectPattern`/`ArrayPattern` node.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Ensure you are using the correct import statement for your module system: `const getAssignedIdentifiers = require('get-assigned-identifiers')` for CommonJS or `import getAssignedIdentifiers from 'get-assigned-identifiers'` for ESM.","cause":"Attempting to use `getAssignedIdentifiers` before it's properly imported or if the imported value is `undefined`.","error":"TypeError: getAssignedIdentifiers is not a function"},{"fix":"Either use the CommonJS `require()` syntax (`const getAssignedIdentifiers = require('get-assigned-identifiers')`) or configure your project for ESM by adding `\"type\": \"module\"` to your `package.json` or saving the file as `.mjs`.","cause":"Attempting to use ESM `import` syntax in a CommonJS context (e.g., a `.js` file without `\"type\": \"module\"` in `package.json` or run with `node --experimental-modules`).","error":"SyntaxError: Cannot use import statement outside a module"}],"ecosystem":"npm"}