is-reference is a focused utility designed to accurately determine whether a given JavaScript Abstract Syntax Tree (AST) node, specifically an `Identifier`, constitutes a 'reference' in the context of scope analysis. This is crucial for tools like bundlers, minifiers, and linters that need to differentiate between identifiers that refer to a variable binding (e.g., `console.log(foo)`) and those that are property names (e.g., `obj.foo`). The package is currently at version 3.0.3 and appears to follow an infrequent release cadence, driven by the needs of projects like Rollup. Its primary differentiator is its precise definition of a 'reference' within the ESTree specification, distinguishing it from simply being an `Identifier` node. It ships with TypeScript types, ensuring type-safe usage in modern JavaScript environments.
npm install is-referenceVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to parse an AST using Acorn, walk it with estree-walker, and identify 'reference' nodes using `is-reference`, distinguishing them from mere identifier occurrences within the AST.
Ensure your project is configured for ES Modules (e.g., `"type": "module"` in your `package.json`). Use `import is_reference from 'is-reference';` and adjust your build or runtime environment to handle ESM correctly. For older CJS environments, consider bundling or using dynamic `import()`.
Always provide both the `node` and its `parent` to the `is_reference` function: `is_reference(node, parent)`. If using an AST walker, ensure it provides the parent context, such as `estree-walker`'s `enter(node, parent)` callback.
Understand the precise definition of a 'reference' as documented by `is-reference`. If you need to find all `Identifier` nodes regardless of their referencing status, you should directly check `node.type === 'Identifier'` rather than relying solely on `is_reference`.
Ensure you are using the correct default import syntax: `import is_reference from 'is-reference';`. If in a CommonJS environment, verify that your tooling or Node.js version supports ESM interop for default exports, or consider bundling.
Always pass a valid AST `parent` node to `is_reference(node, parent)`. If you are at the root of the AST (e.g., a `Program` node), its `parent` would typically be `null` or `undefined`, and `is_reference` expects to handle this case, but for any child node, a correct parent must be provided by your AST traversal logic.
No dependency data recorded yet.