{"id":12276,"library":"undeclared-identifiers","title":"Undeclared Identifiers Finder","description":"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.","status":"maintenance","version":"1.1.3","language":"javascript","source_language":"en","source_url":"https://github.com/goto-bus-stop/undeclared-identifiers","tags":["javascript","ast","check","detect","identifiers","undeclared"],"install":[{"cmd":"npm install undeclared-identifiers","lang":"bash","label":"npm"},{"cmd":"yarn add undeclared-identifiers","lang":"bash","label":"yarn"},{"cmd":"pnpm add undeclared-identifiers","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Used internally for parsing JavaScript source strings into an Abstract Syntax Tree (AST).","package":"acorn-node","optional":false}],"imports":[{"note":"This is the primary and recommended way to import the function in CommonJS environments.","symbol":"undeclaredIdentifiers (CommonJS)","correct":"const undeclaredIdentifiers = require('undeclared-identifiers')"},{"note":"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.","wrong":"import { undeclaredIdentifiers } from 'undeclared-identifiers'","symbol":"undeclaredIdentifiers (ESM Default Import)","correct":"import undeclaredIdentifiers from 'undeclared-identifiers'"},{"note":"When using dynamic `import()`, the CommonJS default export is accessed via the `default` property of the resolved module object.","wrong":"const undeclaredIdentifiers = await import('undeclared-identifiers')","symbol":"Dynamic Import","correct":"const { default: undeclaredIdentifiers } = await import('undeclared-identifiers')"}],"quickstart":{"code":"const undeclaredIdentifiers = require('undeclared-identifiers');\n\nconst sourceCode = `\n  function greet(name) {\n    console.log('Hello, ' + name + '!');\n    console.warn('Consider using a logger.');\n    anotherGlobalVar = 'test';\n    Buffer.from('hi');\n    MyClass.staticMethod();\n  }\n  greet('World');\n`;\n\nconst result = undeclaredIdentifiers(sourceCode, { wildcard: true });\n\nconsole.log('Undeclared identifiers:', result.identifiers);\nconsole.log('Undeclared properties:', result.properties);\n\n// Expected output (approximately):\n// Undeclared identifiers: [ 'console', 'anotherGlobalVar', 'Buffer', 'MyClass' ]\n// Undeclared properties: [ 'console.log', 'console.warn', 'Buffer.from', 'MyClass.staticMethod' ]","lang":"javascript","description":"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."},"warnings":[{"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.","message":"The 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).","severity":"gotcha","affected_versions":"<=1.1.3"},{"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.","message":"This 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?'.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Update to `undeclared-identifiers@1.1.3` or newer to correctly handle class and method declarations.","message":"Prior to v1.1.3, class names and method names were incorrectly flagged as undeclared identifiers, leading to false positives when analyzing JavaScript classes.","severity":"breaking","affected_versions":"<1.1.3"},{"fix":"Update to `undeclared-identifiers@1.1.2` or newer to ensure correct behavior of the `wildcard` option.","message":"The `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.","severity":"gotcha","affected_versions":"1.1.0, 1.1.1"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"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')`.","cause":"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.","error":"TypeError: undeclaredIdentifiers is not a function"},{"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.","cause":"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).","error":"SyntaxError: The keyword 'await' is reserved (and similar errors for modern JS features)"}],"ecosystem":"npm"}