How to use estraverse

Comprehensive estraverse code examples:

How to use estraverse.Controller:

62
63
64
65
66
67
68
    traverse : estraverse.traverse,
    replace : estraverse.replace,
    attachComments : estraverse.attachComments,
    VisitorKeys : estraverse.VisitorKeys,
    VisitorOption : estraverse.VisitorOption,
    Controller : estraverse.Controller
};

How to use estraverse.Syntax:

21
22
23
24
25
26
27
28
29
30
  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

const Map = require('es6-map');
const estraverse = require('estraverse');
const Syntax = estraverse.Syntax;

class Injector extends estraverse.Controller {
    constructor() {
        super();

How to use estraverse.replace:

118
119
120
121
122
123
124
125
126
127
function processFunctions (ast, options) {
  pre:
    ast && typeof ast === 'object';
  main:
    var total = 0;
    estraverse.replace(ast, {
      enter: function (node) {
        var result;
        if (node.type === 'FunctionDeclaration' || node.type === 'FunctionExpression') {
          result = collectLabels(node, options);

How to use estraverse.MethodDefinition:

295
296
297
298
299
300
301
302
303
304

if (node.computed) {
    this.visit(node.key);
}

const isMethodDefinition = node.type === Syntax.MethodDefinition;

if (isMethodDefinition) {
    previous = this.pushInnerMethodDefinition(true);
}

How to use estraverse.VisitorOption:

25
26
27
28
29
30
31
32
33
34
                    parentCollection = [parentCollection];
                }
            }

            if (cb(node, parent, parentCollection) === false) {
                return estraverse.VisitorOption.Skip;
            }
        }
    });
}

How to use estraverse.AssignmentPattern:

44
45
46
47
48
49
50
51
52
53
        nodeType === Syntax.Identifier ||
        nodeType === Syntax.ObjectPattern ||
        nodeType === Syntax.ArrayPattern ||
        nodeType === Syntax.SpreadElement ||
        nodeType === Syntax.RestElement ||
        nodeType === Syntax.AssignmentPattern
    );
}

constructor(options, rootPattern, callback) {

How to use estraverse.traverse:

88
89
90
91
92
93
94
95
96
97
/**
 * @param {ModuleBuilder} modul
 */
async function traverse(modul) {
  console.debug(`[Analyzer.js] traversing AST of ${modul.path}`);
  estraverse.traverse(modul.ast, {
    enter: function (node, parent) {
      node["xParent"] = parent;
      if (helper.createsNewScope(node)) {
        currentScope += 1;