# is-reference

> Determine whether an AST node is a reference

Latest version **3.0.3** (published 2024-11-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install is-reference
pnpm add is-reference
yarn add is-reference
bun add is-reference
```

## Health

**Score 50/100 (C)** — status: stable.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: stale.

## Facts

| | |
|---|---|
| Version | 3.0.3 |
| Published | 2024-11-12 |
| First published | 2016-12-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Dependencies | 1 |
| Unpacked size | 3.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 26 |
| Author | Rich Harris |
| Maintainers | rich_harris |
| Keywords | ast, javascript, estree, acorn |

## Links

- npm: https://www.npmjs.com/package/is-reference
- Repository: https://github.com/Rich-Harris/is-reference
- Homepage: https://github.com/Rich-Harris/is-reference#readme
- Issues: https://github.com/Rich-Harris/is-reference/issues
- npm.io page: https://npm.io/package/is-reference

## Dependencies (1)

- [@types/estree](https://npm.io/package/@types/estree.md) ^1.0.6

## Alternatives

- [update-check](https://npm.io/package/update-check.md) — 4.0M weekly downloads
- [react-native-onesignal](https://npm.io/package/react-native-onesignal.md) — 134.5K weekly downloads
- [react-redux-toastr](https://npm.io/package/react-redux-toastr.md) — 33.7K weekly downloads
- [@nocobase/plugin-notification-manager](https://npm.io/package/@nocobase/plugin-notification-manager.md) — 2.0K weekly downloads
- [react-simple-toasts](https://npm.io/package/react-simple-toasts.md) — 1.9K weekly downloads

## Recent versions

- 3.0.3 (latest) — 2024-11-12
- 3.0.2 — 2023-09-10
- 3.0.1 — 2023-01-03
- 3.0.0 — 2021-06-14
- 2.0.0 — 2021-01-29
- 1.2.1 — 2020-06-26
- 1.2.0 — 2020-05-28
- 1.1.4 — 2019-09-24
- 1.1.3 — 2019-07-07
- 1.1.2 — 2019-03-24
- 1.1.1 — 2019-01-01
- 1.1.0 — 2018-01-10
- 1.0.1 — 2017-07-03
- 1.0.0 — 2016-12-21

## README

# is-reference

Utility for determining whether an AST node is a reference.

`foo` is a reference in these cases:

```js
console.log(foo);
var foo;
function foo() {}
function bar(foo) {}
export { foo as x };
```

`foo` is *not* a reference in these cases:

```js
var obj = { foo: 1 };
console.log(obj.foo);
export { x as foo };
```

In all cases, `foo` is an `Identifier` node, but the two kinds must be treated differently for the purposes of scope analysis etc. (The examples are non-exhaustive.)


## Installation

```bash
npm install is-reference
```


## Usage

Example using [Acorn](https://github.com/ternjs/acorn) and [estree-walker](https://github.com/Rich-Harris/estree-walker):

```js
import { parse } from 'acorn';
import { walk } from 'estree-walker';
import is_reference from 'is-reference';

const identifiers = [];
const references = [];

const ast = parse(`var a = b.c;`);

walk(ast, {
	enter(node, parent) {
		if (node.type === 'Identifier') identifiers.push(node);
		if (is_reference(node, parent)) references.push(node);
	}
});

identifiers.forEach(node => console.log(node.name)); // a, b, c
references.forEach(node => console.log(node.name)); // a, b
```


## License

MIT

---
_Source: https://npm.io/package/is-reference · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
