Undeclared Identifiers Finder

1.1.3 · maintenance · verified Sun Apr 19

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.

Common errors

Warnings

Install

Imports

Quickstart

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' ]

view raw JSON →