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

    Install

    npm i solidity-ast-traverse

    DownloadsWeekly Downloads

    1

    Version

    0.0.1

    License

    MIT

    Unpacked Size

    6.58 kB

    Total Files

    3

    Last publish

    Collaborators

    • mcormier