Registry / testing / get-assigned-identifiers

get-assigned-identifiers

JSON →
library1.2.0jsnpmunverified

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.

npm install get-assigned-identifiers
INSTALL
IMPORT
SIG · GET-ASSIGNED-IDENT
G
get-assigned-identifiers
testingjavascriptv1.2.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.

getAssignedIdentifiers
import getAssignedIdentifiers from 'get-assigned-identifiers'
import { getAssignedIdentifiers } from 'get-assigned-identifiers'
The package uses a CommonJS default export, which translates to a default import in ESM. Avoid named imports.
getAssignedIdentifiers
const getAssignedIdentifiers = require('get-assigned-identifiers')
This is the documented and primary way to use the library in CommonJS environments.

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.

import { parse } from 'acorn'; import getAssignedIdentifiers from 'get-assigned-identifiers'; const code = ` const { a, b: [ c,, ...x ], d = 10 } = someComplexObject(); let [ e, f ] = otherArray; var g = 'hello'; `; try { const ast = parse(code, { ecmaVersion: 2020 }); // Example 1: Destructuring declaration const node1 = ast.body[0].declarations[0].id; // { a, b: [ c,, ...x ], d = 10 } console.log('Identifiers from destructuring:', getAssignedIdentifiers(node1)); // Expected: [{ name: 'a' }, { name: 'c' }, { name: 'x' }, { name: 'd' }] // Example 2: Array destructuring const node2 = ast.body[1].declarations[0].id; // [ e, f ] console.log('Identifiers from array destructuring:', getAssignedIdentifiers(node2)); // Expected: [{ name: 'e' }, { name: 'f' }] // Example 3: Simple variable declaration const node3 = ast.body[2].declarations[0].id; // g console.log('Identifiers from simple declaration:', getAssignedIdentifiers(node3)); // Expected: [{ name: 'g' }] } catch (error) { console.error('Error parsing code:', error.message); }
Debug
Known issues
gotchaThe `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+).
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.
affects: >=1.0.0
gotchaThe 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.
fix
Always use a robust JavaScript parser (e.g., `acorn`, `@babel/parser`, `esprima`) to generate the AST nodes before passing them to `getAssignedIdentifiers`.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: getAssignedIdentifiers is not a function
Attempting to use `getAssignedIdentifiers` before it's properly imported or if the imported value is `undefined`.
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.
SyntaxError: Cannot use import statement outside a module
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`).
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`.
Upgrade
Version history
1.2.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
get-assigned-identifiers — npm install get-assigned-identifiers · libregistry