Launch Week Day 5: Introducing Reachability for PHP.Learn More
Socket
Book a DemoSign in
Socket

@nodesecure/estree-ast-utils

Package Overview
Dependencies
Maintainers
5
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nodesecure/estree-ast-utils

Utilities for AST (ESTree compliant)

Source
npmnpm
Version
2.0.0
Version published
Maintainers
5
Created
Source

estree-ast-utils

version maintained OpenSSF
Scorecard mit build

Utilities for AST (ESTree compliant)

Getting Started

This package is available in the Node Package Repository and can be easily installed with npm or yarn.

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

Usage example

import { VariableTracer } from "@nodesecure/estree-ast-utils";

const tracer = new VariableTracer().enableDefaultTracing();

const data = tracer.getDataFromIdentifier("identifier...here");
console.log(data);

API

arrayExpressionToString(node): IterableIterator< string >

Translate an ESTree ArrayExpression into an iterable of Literal value.

["foo", "bar"];

will return "foo" then "bar".

concatBinaryExpression(node, options): IterableIterator< string >

Return all Literal part of a given Binary Expression.

"foo" + "bar";

will return "foo" then "bar".

One of the options of the method is stopOnUnsupportedNode, if true it will throw an Error if the left or right side of the Expr is not a supported type.

getCallExpressionIdentifier(node, options): string | null

Return the identifier name of the CallExpression (or null if there is none).

foobar();

will return "foobar".

One of the options of the method is resolveCallExpression (which is true by default).

Sometimes you don't want to resolve/jump early CallExpression like in the following example:

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

With resolveCallExpression equal to false the function return null.

getMemberExpressionIdentifier(node): IterableIterator< string >

Return the identifier name of the CallExpression (or null if there is none).

foo.bar();

will return "foo" then "bar".

getVariableDeclarationIdentifiers(node): IterableIterator< string >

Get all variables identifier name.

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

will return "foo" then "bar".

isLiteralRegex(node): boolean

Return true if the given Node is a Literal Regex Node.

/^hello/g;
extractLogicalExpression(node)

Extract all LogicalExpression recursively and return an IterableIterator of

{ operator: "||" | "&&" | "??", node: any }

For the following code example

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

The extract will return three parts

  • freeGlobal
  • freeSelf
  • and finally Function('return this')();

License

MIT

Keywords

estree

FAQs

Package last updated on 12 Jun 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts