JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 14819
  • Score
    100M100P100Q132329F
  • License MIT

Traversal functions for solidity-parser generated AST

Package Exports

  • sol-explore

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (sol-explore) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

sol-explore

Traversal functions for solidity-parser generated AST

#Documentation

sol-explore provides Depth-First Traversal of the abstract syntax tree that solidity-parser creates for your solidity code. You provide the AST and specifiy the callbacks that get called upon entering and leaving a particular node during the traversal.

#Install

npm install --save sol-explore

#API

sol-explorer exports a function traverse and an object traversalOptions. traverse expects 2 arguments - the first is the AST generated by solidity-parser (or any other parser of your choice which follows a similar Solidity Tree Pattern) and the second is either a function or an object.

If the 2nd argument is simply a function, it is treated as the callback to call when entering an un-explored node. If the argument is an object, the object must have 2 properties:

  object.enter = function () {...}  //callback to call when entering an un-explored node
  object.leave = function () {...}  //callback to call when leaving an explored node
  

You may use 2 additional features inside these functions:

  this.stopTraversal () /*OR*/ return solExplorer.traversalOptions.STOP_TRAVERSAL //stop tree traversal immediately
  this.skipNodesBelow () /*OR*/ return solExplorer.traversalOptions.SKIP_NODES_BELOW  //skip the child nodes of the current node

#Example

/*
here, solExplore is the required()d object,
ast is the Abstract Syntax Tree created by solidity-parser
See examples/ directory for complete example with sample solidity code
*/
solExplore.traverse (ast, {
    enter: function (node) {
        console.log ('Entering', node.type);
        if (node.type === 'StructDeclaration') {
            //this.skipNodesBelow ();
            this.stopTraversal ();
            
            //return solExplore.traversalOptions.STOP_TRAVERSAL;
            //return solExplore.traversalOptions.SKIP_NODES_BELOW;
        }
    },
    leave: function (node) {
        console.log ('Leaving', node.type);
    }
});

#License ##MIT