Gathering detailed insights and metrics for estree-toolkit
Gathering detailed insights and metrics for estree-toolkit
Gathering detailed insights and metrics for estree-toolkit
Gathering detailed insights and metrics for estree-toolkit
estige
Fast and modular ESTree-compliant AST Manipulation Toolkit.
@firanorg/mollitia-molestias-accusamus
[![github actions][actions-image]][actions-url] [![coverage][codecov-image]][codecov-url] [![License][license-image]][license-url] [![Downloads][downloads-image]][downloads-url]
@teamteanpm2024/assumenda-commodi-amet
> Browser Compatible MIME Toolkit
@teamteanpm2024/debitis-occaecati-aspernatur
security holding package
npm install estree-toolkit
Typescript
Module System
Node Version
NPM Version
99.5
Supply Chain
100
Quality
83.5
Maintenance
100
Vulnerability
100
License
TypeScript (98.5%)
JavaScript (1.5%)
Total Downloads
1,645,668
Last Day
3,472
Last Week
53,330
Last Month
222,998
Last Year
1,301,684
MIT License
64 Stars
243 Commits
3 Forks
2 Watchers
2 Branches
5 Contributors
Updated on Jul 01, 2025
Minified
Minified + Gzipped
Latest Version
1.7.13
Package Id
estree-toolkit@1.7.13
Unpacked Size
346.69 kB
Size
58.70 kB
File Count
76
NPM Version
10.9.2
Node Version
23.11.0
Published on
May 10, 2025
Cumulative downloads
Total Downloads
Last Day
13.3%
3,472
Compared to previous day
Last Week
-5.6%
53,330
Compared to previous week
Last Month
12.3%
222,998
Compared to previous month
Last Year
1,136.4%
1,301,684
Compared to previous year
estree-toolkit
1npm i estree-toolkit 2# or 3yarn add estree-toolkit
1// Supports both CommonJS and ES Modules 2// ES Module 3import { traverse, builders as b } from 'estree-toolkit'; 4// CommonJS 5const { traverse, builders: b } = require('estree-toolkit');
1const { traverse } = require('estree-toolkit'); 2 3traverse(ast, { 4 Program(path) { 5 // Do something with the path 6 } 7});
1const { builders: b } = require('estree-toolkit'); 2 3b.identifier('x'); // => { type: 'Identifier', name: 'x' }
1const { traverse, is } = require('estree-toolkit'); 2const { parseModule } = require('meriyah'); 3 4const ast = parseModule(`x = 0`); 5 6traverse(ast, { 7 AssignmentExpression(path) { 8 if (is.identifier(path.node.left, { name: 'x' })) { 9 // `left` is an identifier with name `x` 10 } 11 } 12});
1const { traverse, builders: b } = require('estree-toolkit'); 2const { parseModule } = require('meriyah'); 3 4const ast = parseModule('a = b'); 5 6traverse(ast, { 7 Identifier(path) { 8 if (path.node.name === 'a') { 9 path.replaceWith(b.identifier('c')); 10 } 11 } 12}); 13 14// Now the AST represents - `c = b`
1const { traverse } = require('estree-toolkit'); 2 3traverse(ast, { 4 // Enable scope 5 $: { scope: true }, 6 Program(path) { 7 // `path.scope` is now available in all paths 8 } 9});
1const { traverse } = require('estree-toolkit');
2const { parseModule } = require('meriyah');
3
4const ast = parseModule(`
5import { a } from 'source';
6
7const { b, c: [d, { e }] } = a;
8`);
9
10traverse(ast, {
11 $: { scope: true },
12 Program(path) {
13 path.scope.hasBinding('a') // => true
14 path.scope.hasBinding('b') // => true
15 path.scope.hasBinding('c') // => false
16 path.scope.hasBinding('d') // => true
17 path.scope.hasBinding('e') // => true
18 }
19});
1const { traverse } = require('estree-toolkit'); 2const { parseModule } = require('meriyah'); 3 4const ast = parseModule(` 5import { a } from 'source'; 6 7fn(a); 8s = a; 9let obj = { a }; 10`); 11 12traverse(ast, { 13 $: { scope: true }, 14 Program(path) { 15 // Returns all the paths that reference the binding `a` 16 path.scope.getBinding('a').references // => [NodePath, NodePath, NodePath] 17 } 18});
1const { traverse } = require('estree-toolkit'); 2const { parseModule } = require('meriyah'); 3 4const ast = parseModule(` 5const fx = require('fx-mod'); 6`); 7 8traverse(ast, { 9 $: { scope: true }, 10 Program(path) { 11 path.scope.hasGlobalBinding('require') // => true 12 } 13});
1const { traverse } = require('estree-toolkit'); 2const { parseModule } = require('meriyah'); 3 4const ast = parseModule(` 5const a = 0 6 7a.reload() 8while (a.ok) a.run() 9`); 10 11traverse(ast, { 12 $: { scope: true }, 13 Program(path) { 14 // `a` -> `b` 15 path.scope.renameBinding('a', 'b') 16 } 17}); 18 19// Output code: 20// const b = 0 21// 22// b.reload() 23// while (b.ok) b.run()
There are several static utilities that you can use.
evaluate
1const { utils: u, traverse } = require('estree-toolkit'); 2// We are using `meriyah` but you can use any parser (like `acorn`) 3const { parseModule } = require('meriyah'); 4 5traverse(parseModule(`1 + 2`), { 6 BinaryExpression(path) { 7 u.evaluate(path) // => { value: 3 } 8 } 9}); 10 11traverse(parseModule(`1 === 2`), { 12 BinaryExpression(path) { 13 u.evaluate(path) // => { value: false } 14 } 15}); 16 17traverse(parseModule(`iDoNotKnowWhatThisIs === 55`), { 18 BinaryExpression(path) { 19 u.evaluate(path) // => undefined 20 } 21}); 22 23traverse(parseModule(` 24 ({ 25 text: 'This is an object', 26 data: [1, 'two'] 27 }) 28`), { 29 ObjectExpression(path) { 30 u.evaluate(path) // => { value: { text: 'This is an object', data: [1, 'two'] } } 31 } 32}); 33 34traverse(parseModule(`1 > 5 ? 'YES' : 'NO'`), { 35 ConditionalExpression(path) { 36 u.evaluate(path) // => { value: 'NO' } 37 } 38});
evaluateTruthy
true
, false
or undefined
depending on
evaluation result.There's more functionalities, please read the documentation.
You can find the documentation at https://estree-toolkit.netlify.app/
I know there is Babel. But there are
other tools which are faster than Babel. For example, meriyah
is 3x faster than @babel/parser
, astring
is up to 50x faster than @babel/generator
. But these tool only work with ESTree AST. I wanted to use these
faster alternatives for one of my projects but could not find any traverser with
batteries-included. So I built one myself, with awesome scope analysis, it has all the things that you would need for traversing an ESTree AST. Also, a little bit faster than Babel.
If you need help in any kind of ESTree AST modification, then don't hesitate to open a new discussion in Q&A Discussions. I will try my best to help you :)
Licensed under the MIT License.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
1 existing vulnerabilities detected
Details
Reason
9 commit(s) and 1 issue activity found in the last 90 days -- score normalized to 8
Reason
Found 3/25 approved changesets -- score normalized to 1
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-06-23
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More