Registry / testing / undeclared-identifiers

undeclared-identifiers

JSON →
library1.1.3jsnpmunverified

This package, `undeclared-identifiers`, provides a utility to identify undeclared identifiers and property accesses within JavaScript source code or an existing Abstract Syntax Tree (AST). It primarily targets older JavaScript environments, as indicated by its last significant update (v1.1.3 in 2018) and its internal reliance on `acorn-node` for parsing. It returns an object containing arrays of identified undeclared variable names and their associated property accesses. It does not perform full scope resolution, but rather flags any identifier not explicitly declared within its immediate context, making it suitable for basic linting, dependency analysis, or static code checks in environments where modern tooling might be overkill or incompatible. The package has seen infrequent updates since its initial releases, suggesting it is in a maintenance mode, with no new feature development expected.

npm install undeclared-identifiers
INSTALL
IMPORT
SIG · UNDECLARED-IDENTIF
U
undeclared-identifiers
testingjavascriptv1.1.3
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.

undeclaredIdentifiers (CommonJS)
const undeclaredIdentifiers = require('undeclared-identifiers')
This is the primary and recommended way to import the function in CommonJS environments.
undeclaredIdentifiers (ESM Default Import)
import undeclaredIdentifiers from 'undeclared-identifiers'
import { undeclaredIdentifiers } from 'undeclared-identifiers'
For ESM environments, Node.js provides CommonJS interop allowing default imports. Direct named imports like `{ undeclaredIdentifiers }` will fail as the package does not explicitly export named symbols.
Dynamic Import
const { default: undeclaredIdentifiers } = await import('undeclared-identifiers')
const undeclaredIdentifiers = await import('undeclared-identifiers')
When using dynamic `import()`, the CommonJS default export is accessed via the `default` property of the resolved module object.

This quickstart demonstrates how to use `undeclared-identifiers` to find undeclared variables and property accesses in a given JavaScript source string, including the use of the `wildcard` option.

const undeclaredIdentifiers = require('undeclared-identifiers'); const sourceCode = ` function greet(name) { console.log('Hello, ' + name + '!'); console.warn('Consider using a logger.'); anotherGlobalVar = 'test'; Buffer.from('hi'); MyClass.staticMethod(); } greet('World'); `; const result = undeclaredIdentifiers(sourceCode, { wildcard: true }); console.log('Undeclared identifiers:', result.identifiers); console.log('Undeclared properties:', result.properties); // Expected output (approximately): // Undeclared identifiers: [ 'console', 'anotherGlobalVar', 'Buffer', 'MyClass' ] // Undeclared properties: [ 'console.log', 'console.warn', 'Buffer.from', 'MyClass.staticMethod' ]
Debug
Known issues
gotchaThe package was last updated in 2018 (v1.1.3) and relies on an older version of `acorn-node` for parsing. It may not correctly parse or fully support modern JavaScript syntax (e.g., ES2019+, private class fields, top-level await, import assertions/attributes).
fix
For projects using modern JavaScript, consider using a more actively maintained code analysis tool or an AST parser that supports the latest ECMAScript specifications.
affects: <=1.1.3
gotchaThis utility identifies references to undeclared identifiers but does not perform full semantic scope analysis. It will not detect all cases where an identifier is declared in an outer scope but not the immediate one, or issues related to shadowing or global variable pollution beyond a simple check for 'is it declared in this AST context?'.
fix
Understand its focused scope. For comprehensive scope analysis, static type checking, or advanced linting, combine this tool with a full linter like ESLint or a TypeScript compiler.
affects: >=1.0.0
breakingPrior to v1.1.3, class names and method names were incorrectly flagged as undeclared identifiers, leading to false positives when analyzing JavaScript classes.
fix
Update to `undeclared-identifiers@1.1.3` or newer to correctly handle class and method declarations.
affects: <1.1.3
gotchaThe `opts.wildcard` option, introduced in v1.1.0, had incorrect behavior in versions v1.1.0 and v1.1.1. Specifically, wildcard uses were not detected after property use, and standard property accesses were sometimes incorrectly flagged as wildcards.
fix
Update to `undeclared-identifiers@1.1.2` or newer to ensure correct behavior of the `wildcard` option.
affects: 1.1.0, 1.1.1
Errors
Common errors & fixes
TypeError: undeclaredIdentifiers is not a function
Attempting to use `undeclaredIdentifiers` in an ESM module with a named import, e.g., `import { undeclaredIdentifiers } from 'undeclared-identifiers'`, when the package only provides a default (CommonJS) export.
fix
Use a default import instead: `import undeclaredIdentifiers from 'undeclared-identifiers'`. If using `require`, ensure it's assigned to a variable directly: `const undeclaredIdentifiers = require('undeclared-identifiers')`.
SyntaxError: The keyword 'await' is reserved (and similar errors for modern JS features)
The package uses `acorn-node` for parsing, which may be an older version and not support recent ECMAScript syntax features (e.g., top-level await, private class fields, new module syntax).
fix
If analyzing modern JavaScript, you might need to pre-process your code to an older standard (e.g., using Babel) or consider a different code analysis tool that uses an up-to-date parser. This package is best suited for older JS codebases or environments.
Upgrade
Version history
1.1.3latest on npm
Audit
Dependencies
acorn-noderequiredUsed internally for parsing JavaScript source strings into an Abstract Syntax Tree (AST).
Agent activity
8 hits · last 30 days
node
6
Resources
undeclared-identifiers — npm install undeclared-identifiers · libregistry