Gathering detailed insights and metrics for acorn-walk
Gathering detailed insights and metrics for acorn-walk
Gathering detailed insights and metrics for acorn-walk
Gathering detailed insights and metrics for acorn-walk
acorn-jsx-walk
Parse and walk through a Javascript ES6/JSX code source
node-source-walk
Execute a callback on every node of a source code's AST and stop walking when you see fit
swc-walk
Walk an AST from SWC and visit each node type.
acorn-dynamic-import-with-walk-support
Support dynamic imports in acorn, with walk support
A small, fast, JavaScript-based JavaScript parser
npm install acorn-walk
Typescript
Module System
Min. Node Version
Node Version
NPM Version
99.9
Supply Chain
100
Quality
80.4
Maintenance
100
Vulnerability
100
License
JavaScript (99.89%)
HTML (0.11%)
Total Downloads
8,568,441,376
Last Day
2,686,721
Last Week
48,216,693
Last Month
209,935,052
Last Year
2,372,442,384
11,001 Stars
1,507 Commits
939 Forks
179 Watchers
8 Branches
125 Contributors
Updated on Jul 05, 2025
Minified
Minified + Gzipped
Latest Version
8.3.4
Package Id
acorn-walk@8.3.4
Unpacked Size
51.07 kB
Size
9.34 kB
File Count
8
NPM Version
10.8.0
Node Version
20.13.1
Published on
Sep 09, 2024
Cumulative downloads
Total Downloads
Last Day
-11%
2,686,721
Compared to previous day
Last Week
-8.7%
48,216,693
Compared to previous week
Last Month
2.1%
209,935,052
Compared to previous month
Last Year
15.6%
2,372,442,384
Compared to previous year
1
An abstract syntax tree walker for the ESTree format.
Acorn is open source software released under an MIT license.
You are welcome to report bugs or create pull requests on github.
The easiest way to install acorn is from npm
:
1npm install acorn-walk
Alternately, you can download the source and build acorn yourself:
1git clone https://github.com/acornjs/acorn.git 2cd acorn 3npm install
An algorithm for recursing through a syntax tree is stored as an object, with a property for each tree node type holding a function that will recurse through such a node. There are several ways to run such a walker.
simple(node, visitors, base, state)
does a 'simple' walk over a
tree. node
should be the AST node to walk, and visitors
an object
with properties whose names correspond to node types in the ESTree
spec. The properties should contain
functions that will be called with the node object and, if applicable
the state at that point. The last two arguments are optional. base
is a walker algorithm, and state
is a start state. The default
walker will simply visit all statements and expressions and not
produce a meaningful state. (An example of a use of state is to track
scope at each point in the tree.)
1const acorn = require("acorn") 2const walk = require("acorn-walk") 3 4walk.simple(acorn.parse("let x = 10"), { 5 Literal(node) { 6 console.log(`Found a literal: ${node.value}`) 7 } 8})
ancestor(node, visitors, base, state)
does a 'simple' walk over
a tree, building up an array of ancestor nodes (including the current node)
and passing the array to the callbacks as a third parameter.
1const acorn = require("acorn") 2const walk = require("acorn-walk") 3 4walk.ancestor(acorn.parse("foo('hi')"), { 5 Literal(_node, _state, ancestors) { 6 console.log("This literal's ancestors are:", ancestors.map(n => n.type)) 7 } 8})
recursive(node, state, functions, base)
does a 'recursive'
walk, where the walker functions are responsible for continuing the
walk on the child nodes of their target node. state
is the start
state, and functions
should contain an object that maps node types
to walker functions. Such functions are called with (node, state, c)
arguments, and can cause the walk to continue on a sub-node by calling
the c
argument on it with (node, state)
arguments. The optional
base
argument provides the fallback walker functions for node types
that aren't handled in the functions
object. If not given, the
default walkers will be used.
make(functions, base)
builds a new walker object by using the
walker functions in functions
and filling in the missing ones by
taking defaults from base
.
full(node, callback, base, state)
does a 'full' walk over a
tree, calling the callback with the arguments (node, state, type) for
each node
fullAncestor(node, callback, base, state)
does a 'full' walk
over a tree, building up an array of ancestor nodes (including the
current node) and passing the array to the callbacks as a third
parameter.
1const acorn = require("acorn") 2const walk = require("acorn-walk") 3 4walk.full(acorn.parse("1 + 1"), node => { 5 console.log(`There's a ${node.type} node at ${node.ch}`) 6})
findNodeAt(node, start, end, test, base, state)
tries to locate
a node in a tree at the given start and/or end offsets, which
satisfies the predicate test
. start
and end
can be either null
(as wildcard) or a number. test
may be a string (indicating a node
type) or a function that takes (nodeType, node)
arguments and
returns a boolean indicating whether this node is interesting. base
and state
are optional, and can be used to specify a custom walker.
Nodes are tested from inner to outer, so if two nodes match the
boundaries, the inner one will be preferred.
findNodeAround(node, pos, test, base, state)
is a lot like
findNodeAt
, but will match any node that exists 'around' (spanning)
the given position.
findNodeAfter(node, pos, test, base, state)
is similar to
findNodeAround
, but will match all nodes after the given position
(testing outer nodes before inner nodes).
No vulnerabilities found.
Reason
21 commit(s) and 16 issue activity found in the last 90 days -- score normalized to 10
Reason
no dangerous workflow patterns detected
Reason
GitHub workflow tokens follow principle of least privilege
Details
Reason
no binaries found in the repo
Reason
3 existing vulnerabilities detected
Details
Reason
Found 13/30 approved changesets -- score normalized to 4
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
Reason
security policy file not detected
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
license file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-06-30
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