### Install Shift Traverser Source: https://github.com/jsoverson/shift-traverse-js/blob/master/README.md Installs the shift-traverser package using npm. ```sh npm install shift-traverser ``` -------------------------------- ### Traverse AST Nodes Source: https://github.com/jsoverson/shift-traverse-js/blob/master/README.md Demonstrates how to use the `traverse` function to walk through an Abstract Syntax Tree (AST). It allows defining `enter` and `leave` callbacks for each node. ```js import {traverse} from "shift-traverser" traverse(tree, { enter(node) { console.log(`entering ${node.type}`); }, leave(node) { console.log(`leaving ${node.type}`); } }); ``` -------------------------------- ### Replace AST Nodes Source: https://github.com/jsoverson/shift-traverse-js/blob/master/README.md Shows how to use the `replace` function to modify an AST. It takes an AST and a visitor object, allowing nodes to be replaced by returning new nodes from the `enter` callback. ```js import parse from 'shift-parser' import codegen from "shift-codegen"; import { LiteralStringExpression } from "shift-ast"; import { replace, Syntax } from '../' let code = ` function test() { console.log("HELLO WORLD"); } `; let tree = parse(code); let transformed = replace(tree, { enter(node, parent) { if (node.type === Syntax.LiteralStringExpression) { return new LiteralStringExpression('ご注文はうさぎですか?'); } } }); assert(codegen(transformed) === `function test(){console.log("ご注文はうさぎですか?")}`); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.