# @nodesecure/estree-ast-utils

> Utilities for AST (ESTree compliant)

Latest version **4.3.0** (published 2026-02-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install @nodesecure/estree-ast-utils
pnpm add @nodesecure/estree-ast-utils
yarn add @nodesecure/estree-ast-utils
bun add @nodesecure/estree-ast-utils
```

## Health

**Score 70/100 (B)** — status: stable.

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

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 4.3.0 |
| Published | 2026-02-02 |
| First published | 2022-08-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Dependencies | 2 |
| Unpacked size | 43.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 287 |
| Author | GENTILHOMME Thomas |
| Maintainers | fraxken, tonygo, pierred, clemgbld |
| Keywords | estree, ast, utils |

## Links

- npm: https://www.npmjs.com/package/@nodesecure/estree-ast-utils
- Repository: https://github.com/NodeSecure/js-x-ray
- Homepage: https://github.com/NodeSecure/js-x-ray/tree/master/workspaces/estree-ast-utils#readme
- Issues: https://github.com/NodeSecure/js-x-ray/issues
- npm.io page: https://npm.io/package/@nodesecure/estree-ast-utils

## Dependencies (2)

- [meriyah](https://npm.io/package/meriyah.md) 7.0.0
- [@nodesecure/sec-literal](https://npm.io/package/@nodesecure/sec-literal.md) ^1.1.0

## 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

- 4.3.0 (latest) — 2026-02-02
- 4.2.0 — 2025-07-20
- 4.1.0 — 2025-07-01
- 4.0.0 — 2025-07-01
- 3.0.0 — 2025-06-19
- 2.0.0 — 2025-06-12
- 1.6.0 — 2025-06-11
- 1.5.0 — 2024-08-16
- 1.4.1 — 2023-09-02
- 1.4.0 — 2023-09-02
- 1.3.1 — 2023-01-15
- 1.3.0 — 2023-01-01
- 1.2.1 — 2022-10-29
- 1.2.0 — 2022-10-29
- 1.1.0 — 2022-10-22
- … 2 more at https://npm.io/package/@nodesecure/estree-ast-utils/versions

## README

<p align="center">
  <h1 align="center">
    @nodesecure/estree-ast-utils
  </h1>
</p>

<p align="center">
  ESTree compliant utilities to manipulate, extract and transform AST nodes.
</p>

## Getting Started

This package is available in the Node Package Repository and can be easily installed with [npm](https://docs.npmjs.com/getting-started/what-is-npm) or [yarn](https://yarnpkg.com).

```bash
$ npm i @nodesecure/estree-ast-utils
# or
$ yarn add @nodesecure/estree-ast-utils
```

## API

Most utility options extend the `DefaultOptions` interface:

```ts
export interface DefaultOptions {
  externalIdentifierLookup?(name: string): string | null;
}
```

You can provide a custom `externalIdentifierLookup` function to enable the utilities to resolve identifiers from external sources—such as **VariableTracer**, for example.

---

<details>
<summary>arrayExpressionToString(node: ESTree.Node | null, options?: ArrayExpressionToStringOptions): IterableIterator< string ></summary>

Transforms an ESTree `ArrayExpression` into an iterable of literal values.

```js
["foo", "bar"];
```

will yield `"foo"`, then `"bar"`.

```ts
export interface ArrayExpressionToStringOptions extends DefaultOptions {
  /**
   * When enabled, resolves the char code of the literal value.
   *
   * @default true
   * @example
   * [65, 66] // => ['A', 'B']
   */
  resolveCharCode?: boolean;
}
```

</details>

<details>
<summary>joinArrayExpression(node: ESTree.Node | null, options?: DefaultOptions): string | null</summary>

Compute simple ArrayExpression that are using a CallExpression `join()`

```js
{
  host: [
    ["goo", "g", "gle"].join(""),
    "com"
  ].join(".")
}
```

Will return `google.com`

</details>

<details>
<summary>concatBinaryExpression(node: ESTree.BinaryExpression, options?: ConcatBinaryExpressionOptions): IterableIterator< string ></summary>

Returns all `Literal` nodes from a binary expression.

```js
"foo" + "bar";
```

Will yield `"foo"`, then `"bar"`.

Options are described by the following interface:

```ts
interface ConcatBinaryExpressionOptions extends DefaultOptions {
  /**
   * When set to true, the function will throw an error if it encounters
   * a node type that is not supported (i.e., not a Literal, BinaryExpr, ArrayExpr or Identifier).
   *
   * @default false
   * @example
   * "foo" + fn() + "bar" // <- will throw an error if `stopOnUnsupportedNode` is true
   */
  stopOnUnsupportedNode?: boolean;
}
```

</details>

<details>
<summary>extractLogicalExpression(node: ESTree.Node): IterableIterator< { operator: string; node: ESTree.Expression; } ></summary>

Recursively extracts all `LogicalExpression` components.

```ts
{ operator: "||" | "&&" | "??", node: ESTree.Expression }
```

For example:

```js
freeGlobal || freeSelf || Function('return this')();
```

Will yield three components:
- freeGlobal
- freeSelf
- and finally `Function('return this')();`

</details>

<details>
<summary>getCallExpressionArguments(node: ESTree.Node, options?: DefaultOptions): string[] | null</summary>

Returns the literal arguments of a `CallExpression`.

For example:

```js
eval("require");
```

Returns

```js
["require"]
```

</details>

<details>
<summary>getCallExpressionIdentifier(node: ESTree.Node, options?: GetCallExpressionIdentifierOptions): string | null</summary>

Returns the identifier name of a `CallExpression`, or **null** if not resolvable.

```js
foobar();
```

Returns `"foobar"`.

By default, it resolves member expressions.
This can be disabled with resolveCallExpression: false.

```js
require('./file.js')();
//     ^ Second     ^ First
```

With `resolveCallExpression`: false, the function will return null.

```ts
interface GetCallExpressionIdentifierOptions extends DefaultOptions {
  /**
   * Resolve the CallExpression callee if it is a MemberExpression.
   *
   * @default true
   * @example
   * require('./file.js')();
            ^ Second     ^ First
   */
  resolveCallExpression?: boolean;
}
```

</details>

<details>
<summary>getMemberExpressionIdentifier(node: ESTree.MemberExpression, options?: DefaultOptions): IterableIterator< string ></summary>

Returns the identifier chain from a `MemberExpression`.

```js
foo.bar();
```

will return `"foo"` then `"bar"`.

</details>

<details>
<summary>getVariableDeclarationIdentifiers(node: any, options?: GetVariableDeclarationIdentifiersOptions): IterableIterator< string ></summary>

Extracts all variable identifiers from a declaration.

```js
const [foo, bar] = [1, 2];
```

will return `"foo"` then `"bar"`.

</details>

## License

MIT

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