How to use the estraverse.VisitorOption 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 saltlab / sahand / esinstrument.js View on Github external
function instrumentFunctionEnter(node, isCallback) {
    var functionEnterName = '_functionEnter_cb' ? isCallback : '_functionEnter';
    var name;

    // TODO TODO TODO TODO TODO TODO
    if (node.type == 'FunctionDeclaration') {
        // TODO TODO TODO TODO TODO TODO
        if (node.id.name == '_functionEnter' || node.id.name == '_functionExit' || node.id.name == '_functionEnter_callback')
            return estraverse.VisitorOption.Skip; //////////////// TODO TODO TODO ?????????????

        name = node.id.name;
//					console.log('***** DEC: ', name);
    }

    var functionBody = node.body.body;

    // TODO  TODO  TODO  TODO  TODO  TODO  TODO ???
    if (functionBody == null || functionBody == 'undefined') {//} || functionBody.length < 1) {
        console.warn('func-inst.js::instrumentAST -> empty function body');
    }
//								console.log(functionBody.length);


    // TODO TODO TODO  TODO TODO TODO ///////////////
    if (node.type == 'FunctionExpression') {
github xml3d / shade.js / src / generate / embree / transform.js View on Github external
common = require("../../base/common.js"),
        FunctionAnnotation = require("../../type-system/annotation.js").FunctionAnnotation,
        TypeInfo = require("../../type-system/typeinfo.js").TypeInfo,
        Shade = require("./../../interfaces.js"),
        Types = Shade.TYPES,
        Kinds = Shade.OBJECT_KINDS,
        Sources = require("./../../interfaces.js").SOURCES,
        Tools = require('./registry/tools.js');

    var ObjectRegistry = require("./registry/index.js").Registry,
        Scope = require("../../type-system/scope.js"); // TODO: .getScope(ObjectRegistry);


    var walk = require('estraverse');
    var Syntax = walk.Syntax;
    var VisitorOption = walk.VisitorOption;
    var ANNO = common.ANNO;


    /**
     * Transforms the JS AST to an AST representation convenient
     * for code generation
     * @constructor
     */
    var EmbreeASTTransformer = function (mainId) {
        this.mainId = mainId;
    };

    Base.extend(EmbreeASTTransformer.prototype, {
        registerGlobalContext : function (program) {
            var ctx = new Scope(program, null, {name: "global"});
            ctx.registerObject("Math", ObjectRegistry.getByName("Math"));
github babel / kneden / lib / index.js View on Github external
function removeEmptyExprStmt(node) {
    // fix AST after removing expressions
    if (node.type === 'ExpressionStatement' && !node.expression) {
      return estraverse.VisitorOption.Remove;
    }
}
github lebab / lebab / src / traverser.js View on Github external
* @param  {Object} tree
   * @param  {Object} cfg Object with optional enter() and leave() methods.
   * @return {Object} The transformed tree
   */
  replace(tree, cfg) {
    return estraverse.replace(tree, Object.assign(cfg, jsxExtensionKeys));
  },

  /**
   * Constants to return from enter()/leave() to control traversal:
   *
   * - Skip - skips walking child nodes
   * - Break - ends it all
   * - Remove - removes the current node (only with replace())
   */
  VisitorOption: estraverse.VisitorOption,

  /**
   * Searches in AST tree for node which satisfies the predicate.
   * @param  {Object} tree
   * @param  {Function|String} query Search function called with `node` and `parent`
   *   Alternatively it can be string: the node type to search for.
   * @param  {String[]} opts.skipTypes List of node types to skip (not traversing into these nodes)
   * @return {Object} The found node or undefined when not found
   */
  find(tree, query, {skipTypes = []} = {}) {
    const predicate = this.createFindPredicate(query);
    let found;

    this.traverse(tree, {
      enter(node, parent) {
        if (includes(node.type, skipTypes)) {
github javascript-obfuscator / javascript-obfuscator / src / node-transformers / converting-transformers / properties-extractors / VariableDeclaratorPropertiesExtractor.ts View on Github external
enter: (node: ESTree.Node): estraverse.VisitorOption | ESTree.Node => {
                    if (
                        NodeGuards.isMemberExpressionNode(node)
                        && NodeGuards.isIdentifierNode(node.object)
                        && node.object.name === memberExpressionHostNode.name
                    ) {
                        isProhibitedObjectExpressionNode = true;

                        return estraverse.VisitorOption.Break;
                    }

                    return node;
                }
            });
github javascript-obfuscator / javascript-obfuscator / src / analyzers / stack-trace-analyzer / callee-data-extractors / FunctionExpressionCalleeDataExtractor.ts View on Github external
enter: (node: ESTree.Node, parentNode: ESTree.Node | null): estraverse.VisitorOption | void => {
                if (
                    NodeGuards.isFunctionExpressionNode(node) &&
                    parentNode &&
                    NodeGuards.isVariableDeclaratorNode(parentNode) &&
                    NodeGuards.isIdentifierNode(parentNode.id) &&
                    parentNode.id.name === name
                ) {
                    calleeBlockStatement = node.body;

                    return estraverse.VisitorOption.Break;
                }
            }
        });
github xml3d / shade.js / src / base / common.js View on Github external
result.setStaticValue(propagatedConstant[0].constant);
                    }
                }
                return binding;

            }
        } else if (node.type == Syntax.ThisExpression) {
            binding = scope.getBindingByName('this');
        }
        return binding || ANNO(node);
    };



    ns.Syntax = Syntax;
    ns.VisitorOption = estraverse.VisitorOption;

    ns.ANNO = ANNO;
    ns.getObjectReferenceFromNode = ns.getTypeInfo;


}(exports));
github javascript-obfuscator / javascript-obfuscator / src / analyzers / stack-trace-analyzer / callee-data-extractors / FunctionDeclarationCalleeDataExtractor.ts View on Github external
enter: (node: ESTree.Node): estraverse.VisitorOption | void => {
                if (NodeGuards.isFunctionDeclarationNode(node) && node.id.name === name) {
                    calleeBlockStatement = node.body;

                    return estraverse.VisitorOption.Break;
                }
            }
        });
github javascript-obfuscator / javascript-obfuscator / dist / src / node-obfuscators / FunctionDeclarationObfuscator.js View on Github external
leave: function leave(node) {
                    if (NodeUtils_1.NodeUtils.isIdentifierNode(node) && !_this2.isReservedName(node.name)) {
                        _this2.functionName.set(node.name, Utils_1.Utils.getRandomVariableName());
                        node.name = _this2.functionName.get(node.name);
                        return;
                    }
                    return estraverse.VisitorOption.Skip;
                }
            });
github hcvazquez / UFFRemover / src / task / instrumentor.js View on Github external
enter: function enter(node) {
            if (_astTypes.namedTypes.FunctionDeclaration.check(node) || _astTypes.namedTypes.FunctionExpression.check(node)) {
                return _estraverse.VisitorOption.Skip;
            }
            if (_astTypes.namedTypes.ThisExpression.check(node)) {
                thisExpression = true;
                return parser.parseWithLOC("$that");
            }
        }
    });