Skip to content
This repository has been archived by the owner on Dec 1, 2023. It is now read-only.

NodeSecure/estree-ast-utils

This branch is up to date with main.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

619bc1a · Dec 1, 2023

History

65 Commits
Sep 2, 2023
Sep 2, 2023
Sep 2, 2023
Feb 27, 2023
May 22, 2022
May 22, 2022
May 21, 2022
Jan 25, 2023
Jun 13, 2022
May 21, 2022
Dec 1, 2023
Jan 19, 2023
Sep 2, 2023
Sep 2, 2023

Repository files navigation

Caution

This package has been migrated to JS-X-Ray workspaces

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): string | null

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

foobar();

will return "foobar".

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;

Contributors ✨

All Contributors

Thanks goes to these wonderful people (emoji key):

Gentilhomme
Gentilhomme

💻 🛡️ ⚠️ 🐛
Kouadio Fabrice Nguessan
Kouadio Fabrice Nguessan

🚧

License

MIT