Giter VIP home page Giter VIP logo

reflect-tree-builder's Introduction

A more tree-like AST builder for reflect.js.

Tree Builder

The tree builder creates default nodes extended with properties and methods for traversing and manipulating the tree.

Example:

var Reflect = require('reflect');
var treeBuilder = require('reflect-tree-builder');

var source = "a + b + c(5)";
var ast = Reflect.parse(source, {builder: treeBuilder});

function visit (node, pre, post) {
    if (pre) pre(node);
    node.children().forEach(function (child) {
        visit(child, pre, post);
    });
    if (post) post(node);
}

visit(ast, null, function (n) { console.log(n.type); });

Install

npm install reflect-tree-builder

Node Properties

See the Mozilla documentation for the default node APIs. The following are additional properties the tree builder provides.

node.parent

The node's parent.

node.children([children])

Returns the children of the node. If an array of nodes are passed as an argument, they replace node's current set of children.

node.remove(child)

Removes the specified child from node's set of children.

node.replace(delinquent, adopted)

Removes the delinquent and adds the adopted child in its place.

node.append(child)

For block type nodes, such as FunctionDeclarations, Programs, and Blocks, this appends a child to its list of statements.

License

MIT X License

reflect-tree-builder's People

Contributors

zaach avatar

Stargazers

Mauro Junior avatar  avatar

Watchers

 avatar James Cloos avatar  avatar

reflect-tree-builder's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.