Gathering detailed insights and metrics for esrecurse
Gathering detailed insights and metrics for esrecurse
Gathering detailed insights and metrics for esrecurse
Gathering detailed insights and metrics for esrecurse
npm install esrecurse
Typescript
Module System
Min. Node Version
Node Version
NPM Version
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
NOASSERTION License
79 Stars
61 Commits
20 Forks
13 Watchers
1 Branches
14 Contributors
Updated on Jul 20, 2024
Latest Version
4.3.0
Package Id
esrecurse@4.3.0
Size
3.96 kB
NPM Version
6.14.4
Node Version
10.20.1
Published on
Aug 31, 2020
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
Esrecurse (esrecurse) is ECMAScript recursive traversing functionality.
The following code will output all variables declared at the root of a file.
1esrecurse.visit(ast, { 2 XXXStatement: function (node) { 3 this.visit(node.left); 4 // do something... 5 this.visit(node.right); 6 } 7});
We can use Visitor
instance.
1var visitor = new esrecurse.Visitor({ 2 XXXStatement: function (node) { 3 this.visit(node.left); 4 // do something... 5 this.visit(node.right); 6 } 7}); 8 9visitor.visit(ast);
We can inherit Visitor
instance easily.
1class Derived extends esrecurse.Visitor { 2 constructor() 3 { 4 super(null); 5 } 6 7 XXXStatement(node) { 8 } 9}
1function DerivedVisitor() { 2 esrecurse.Visitor.call(/* this for constructor */ this /* visitor object automatically becomes this. */); 3} 4util.inherits(DerivedVisitor, esrecurse.Visitor); 5DerivedVisitor.prototype.XXXStatement = function (node) { 6 this.visit(node.left); 7 // do something... 8 this.visit(node.right); 9};
And you can invoke default visiting operation inside custom visit operation.
1function DerivedVisitor() { 2 esrecurse.Visitor.call(/* this for constructor */ this /* visitor object automatically becomes this. */); 3} 4util.inherits(DerivedVisitor, esrecurse.Visitor); 5DerivedVisitor.prototype.XXXStatement = function (node) { 6 // do something... 7 this.visitChildren(node); 8};
The childVisitorKeys
option does customize the behaviour of this.visitChildren(node)
.
We can use user-defined node types.
1// This tree contains a user-defined `TestExpression` node. 2var tree = { 3 type: 'TestExpression', 4 5 // This 'argument' is the property containing the other **node**. 6 argument: { 7 type: 'Literal', 8 value: 20 9 }, 10 11 // This 'extended' is the property not containing the other **node**. 12 extended: true 13}; 14esrecurse.visit( 15 ast, 16 { 17 Literal: function (node) { 18 // do something... 19 } 20 }, 21 { 22 // Extending the existing traversing rules. 23 childVisitorKeys: { 24 // TargetNodeName: [ 'keys', 'containing', 'the', 'other', '**node**' ] 25 TestExpression: ['argument'] 26 } 27 } 28);
We can use the fallback
option as well.
If the fallback
option is "iteration"
, esrecurse
would visit all enumerable properties of unknown nodes.
Please note circular references cause the stack overflow. AST might have circular references in additional properties for some purpose (e.g. node.parent
).
1esrecurse.visit( 2 ast, 3 { 4 Literal: function (node) { 5 // do something... 6 } 7 }, 8 { 9 fallback: 'iteration' 10 } 11);
If the fallback
option is a function, esrecurse
calls this function to determine the enumerable properties of unknown nodes.
Please note circular references cause the stack overflow. AST might have circular references in additional properties for some purpose (e.g. node.parent
).
1esrecurse.visit( 2 ast, 3 { 4 Literal: function (node) { 5 // do something... 6 } 7 }, 8 { 9 fallback: function (node) { 10 return Object.keys(node).filter(function(key) { 11 return key !== 'argument' 12 }); 13 } 14 } 15);
Copyright (C) 2014 Yusuke Suzuki (twitter: @Constellation) and other contributors.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 8/26 approved changesets -- score normalized to 3
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
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-07-07
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