solidity-ast-traverse
v0.0.1
Published
Traversal function for Solidity AST trees
Downloads
6
Maintainers
Readme
Solidity AST Traverse
Traversal function for Solidity AST trees.
Description
solidity-ast-traverse
provides depth-first traversal of a Solidity abstract syntax tree (AST).
This package is a fork of sol-explore updated for modern AST code.
Install
yarn add solidity-ast-traverse
or
npm install solidity-ast-traverse --save
Usage
Basic example
const solidityAstTraverse = require('solidity-ast-traverse')
solidityAstTraverse(ast, (node, parent) => {
console.log('Node type: ' + node.nodeType)
if (node.type === 'StructDeclaration') {
console.log('Stopping traversal')
return solidityAstTraverse.STOP_TRAVERSAL
}
})
Advanced example
const solidityAstTraverse = require('solidity-ast-traverse')
solidityAstTraverse(ast, {
enter: (node, parent) => {
console.log ('Entering', node.nodeType)
if (node.type === 'StructDeclaration') {
console.log('Skipping child nodes')
return solidityAstTraverse.SKIP_NODES_BELOW
}
},
leave: (node) => {
console.log ('Leaving', node.type)
}
})
License
MIT