solidity-ast-traverse

0.0.1 • Public • Published

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

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.0.1
    1
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 0.0.1
    1

Package Sidebar

Install

npm i solidity-ast-traverse

Weekly Downloads

0

Version

0.0.1

License

MIT

Unpacked Size

6.58 kB

Total Files

3

Last publish

Collaborators

  • mcormier