How to use the estraverse.Controller function in estraverse

To help you get started, we’ve selected a few estraverse examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github xml3d / shade.js / src / analyze / constants / computeConstants.js View on Github external
ns.evaluate  = function(ast, propagatedConstants) {
        var controller = new estraverse.Controller();

        // console.log("Compute constants for", codegen.generate(ast), propagatedConstants)
        this.setConstants(propagatedConstants);

        controller.traverse(ast, {
            leave: exitExpression.bind(controller, this)
        })
        this.setConstants(null);

    }
}(exports));
github angelozerr / tern.java / core / ternjs / node_modules / tern-eslint / node_modules / eslint / lib / eslint.js View on Github external
// add all the node types as listeners
                    Object.keys(rule).forEach(function(nodeType) {
                        api.on(nodeType, timing.enabled
                            ? timing.time(key, rule[nodeType])
                            : rule[nodeType]
                        );
                    });
                } catch (ex) {
                    ex.message = "Error while loading rule '" + key + "': " + ex.message;
                    throw ex;
                }
            });

            // save config so rules can access as necessary
            currentConfig = config;
            controller = new estraverse.Controller();

            ecmaFeatures = currentConfig.parserOptions.ecmaFeatures || {};
            ecmaVersion = currentConfig.parserOptions.ecmaVersion || 5;

            // gather data that may be needed by the rules
            scopeManager = escope.analyze(ast, {
                ignoreEval: true,
                nodejsScope: ecmaFeatures.globalReturn,
                impliedStrict: ecmaFeatures.impliedStrict,
                ecmaVersion: ecmaVersion,
                sourceType: currentConfig.parserOptions.sourceType || "script",
                childVisitorKeys: espree.VisitorKeys,
                fallback: "none"
            });
            currentScopes = scopeManager.scopes;
github BladeRunnerJS / brjs / brjs-sdk / build-resources / includes / sdk / jsdoc-toolkit-resources / jsdoc-toolkit / node_modules / gulp-eslint / node_modules / eslint / lib / eslint.js View on Github external
api.on(nodeType, rule[nodeType]);
                        });
                    } catch(ex) {
                        ex.message = "Error while loading rule '" + key + "': " + ex.message;
                        throw ex;
                    }

                } else {
                    throw new Error("Definition for rule '" + key + "' was not found.");
                }
            });

            // save config so rules can access as necessary
            currentConfig = config;
            currentText = text;
            controller = new estraverse.Controller();

            // gather data that may be needed by the rules
            currentScopes = escope.analyze(ast, { ignoreEval: true }).scopes;

            /*
             * Index the scopes by the start range of their block for efficient
             * lookup in getScope.
             */
            scopeMap = [];
            currentScopes.forEach(function (scope, index) {
                var range = scope.block.range[0];

                // Sometimes two scopes are returned for a given node. This is
                // handled later in a known way, so just don't overwrite here.
                if (!scopeMap[range]) {
                    scopeMap[range] = index;
github qooxdoo / qooxdoo / tool / grunt / task / package / dependency / lib / qxCoreEnv.js View on Github external
function replaceEnvCallSelect(tree, envMap) {
  var controller = new estraverse.Controller();
  var resultTree = controller.replace(tree, {
    enter : function (node, parent) {
      if (isQxCoreEnvironmentCall(node, ["select"])) {
        var envKey = getKeyFromEnvCall(node);
        try {
          return getEnvSelectValueByKey(node, envMap[envKey]);
        } catch (error) {
          // intentionally empty
          // => no return means no replacement
          // possible reasons:
          //   * envMap has no envKey because the envKey is runtime based (os.version)
          //     and cannot be configured upfront.
        }
      }
    }
  });
github xml3d / shade.js / src / generate / glsl / transform.js View on Github external
replace: function(ast) {
            var controller = new walk.Controller(),
                context = this.context,
                that = this;

            ast = controller.replace(ast, {

                enter: function (node, parent) {

                    switch (node.type) {
                        case Syntax.Identifier:
                            return enterIdentifier(node, parent, context);
                        case Syntax.IfStatement:
                            return enterIfStatement(node);
                        case Syntax.FunctionDeclaration:
                            return enterFunctionDeclaration(node, context);
                    }
                },
github qooxdoo / qooxdoo / tool / grunt / task / package / dependency / lib / qxCoreEnv.js View on Github external
function replaceEnvCallGet(tree, envMap) {
  var controller = new estraverse.Controller();
  var resultTree = controller.replace(tree, {
    enter : function (node, parent) {
      if (isQxCoreEnvironmentCall(node, ["get"])) {
        var envKey = getKeyFromEnvCall(node);
        if (envMap && envKey in envMap) {
          return {
            "type": "Literal",
            "value": envMap[envKey],
            "raw": ((typeof(envMap[envKey]) === "string")
                   ? "\""+envMap[envKey]+"\""
                   : envMap[envKey].toString())
          };
        }
      }
    }
  });
github xml3d / shade.js / src / analyze / typeinference / infer_expression.js View on Github external
ns.annotateRight  = function(context, ast, propagatedConstants) {

        if(!ast)
            throw Error("No node to analyze");

        var controller = new estraverse.Controller();

        context.setConstants(propagatedConstants || null);

        controller.traverse(ast, {
            enter: function(node) {
                if(node.type == Syntax.VariableDeclaration) {
                    context.setInDeclaration(true);
                }
            },
            leave: function(node, parent) {
                if (handlers.hasOwnProperty(node.type)) {
                    return handlers[node.type].call(this, node, parent, context);
                }
                return null;
            }
        });
github qooxdoo / qooxdoo / tool / grunt / task / package / dependency / lib / annotator / parent.js View on Github external
annotate: function(tree) {
    var controller = new estraverse.Controller();
    controller.traverse(tree, {
      enter : function (node, parent) {
        node[annotateKey] = parent;
      }
    });
  }
};
github xml3d / shade.js / src / analyze / slice.js View on Github external
function findVariableReferences(ast) {
    var references = new Set();

    var controller = new walk.Controller();
    walk.traverse(ast, {
        leave: function(node, parent) {
            switch(node.type) {
                case Syntax.AssignmentExpression:
                    references = Set.union(references, findVariableReferences(node.right));
                    controller.break();
                    break;
                case Syntax.Identifier:
                    if (ASTTools.isVariableReference(node, parent)) {
                        references.add(node.name);
                    }
                    break;
                case Syntax.MemberExpression:
                    if (isMemberReference(node, parent)) {
                        if (ASTTools.isVariableReference(node.object, node)) {
                            references.add(node.name);