Installations
npm install esrecurse
Score
99.5
Supply Chain
100
Quality
79.4
Maintenance
100
Vulnerability
100
License
Releases
Unable to fetch releases
Developer
estools
Developer Guide
Module System
CommonJS
Min. Node Version
>=4.0
Typescript Support
No
Node Version
10.20.1
NPM Version
6.14.4
Statistics
79 Stars
61 Commits
20 Forks
14 Watching
1 Branches
14 Contributors
Updated on 20 Jul 2024
Languages
JavaScript (100%)
Total Downloads
Cumulative downloads
Total Downloads
6,501,421,516
Last day
-8%
7,720,786
Compared to previous day
Last week
2.2%
46,416,559
Compared to previous week
Last month
19%
183,924,511
Compared to previous month
Last year
20%
1,748,839,975
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Esrecurse
Esrecurse (esrecurse) is ECMAScript recursive traversing functionality.
Example Usage
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);
License
See LICENSE.md.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE.md:0
- Warn: project license file does not contain an FSF or OSI license.
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
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 13 are checked with a SAST tool
Score
3.4
/10
Last Scanned on 2024-11-25
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