Skip to content

ben-sb/shift-ast-traverser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Shift AST Traverser

Allows you to easily traverse Shift ASTs or AST nodes. shift-traverser wasn't working for me so I wrote this.

Usage

traverse

const source = `let a = 'Hello World';`
const $script = refactor(source);

traverse($script, {
    enter: function(node) {
        console.log(`Entering ${node.type}`);
    },
    leave: function(node) {
        console.log(`Leaving ${node.type}`);
    }
});

replace

const source = `let message = 'Hello World';`
const $script = refactor(source);

replace($script, {
    enter: function(node) {
        if (node.type == 'LiteralStringExpression') {
            return new Shift.LiteralStringExpression({
                value: 'Why hello there!'
            })
        }
    }
});

console.log($script.codegen());

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published