當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript estraverse.traverse函數代碼示例

本文整理匯總了TypeScript中estraverse.traverse函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript traverse函數的具體用法?TypeScript traverse怎麽用?TypeScript traverse使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了traverse函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: getCalleeBlockStatement

    /**
     * @param {NodeGuards} targetNode
     * @param {TObjectMembersCallsChain} objectMembersCallsChain
     * @returns {BlockStatement}
     */
    private getCalleeBlockStatement (
        targetNode: ESTree.Node,
        objectMembersCallsChain: TObjectMembersCallsChain
    ): ESTree.BlockStatement | null {
        const objectName: string | number | undefined = objectMembersCallsChain.shift();

        if (!objectName) {
            return null;
        }

        let calleeBlockStatement: ESTree.BlockStatement | null = null;

        estraverse.traverse(targetNode, {
            enter: (node: ESTree.Node): estraverse.VisitorOption | void => {
                if (
                    NodeGuards.isVariableDeclaratorNode(node) &&
                    NodeGuards.isIdentifierNode(node.id) &&
                    node.init &&
                    NodeGuards.isObjectExpressionNode(node.init) &&
                    node.id.name === objectName
                ) {
                    calleeBlockStatement = this.findCalleeBlockStatement(node.init.properties, objectMembersCallsChain);

                    return estraverse.VisitorOption.Break;
                }
            }
        });

        return calleeBlockStatement;
    }
開發者ID:dssoft32,項目名稱:javascript-obfuscator,代碼行數:35,代碼來源:ObjectExpressionCalleeDataExtractor.ts

示例2: getCalleeBlockStatement

    /**
     * @param {NodeGuards} targetNode
     * @param {string} name
     * @returns {BlockStatement}
     */
    private getCalleeBlockStatement (targetNode: ESTree.Node, name: string): ESTree.BlockStatement | null {
        let calleeBlockStatement: ESTree.BlockStatement | null = null;

        estraverse.traverse(targetNode, {
            enter: (node: ESTree.Node): estraverse.VisitorOption | void => {
                if (NodeGuards.isFunctionDeclarationNode(node) && node.id.name === name) {
                    calleeBlockStatement = node.body;

                    return estraverse.VisitorOption.Break;
                }
            }
        });

        return calleeBlockStatement;
    }
開發者ID:dssoft32,項目名稱:javascript-obfuscator,代碼行數:20,代碼來源:FunctionDeclarationCalleeDataExtractor.ts

示例3: jsParse

export function jsParse(jsString:string) {
  var script = espree.parse(jsString, {
    attachComment: true,
    comment: true,
    loc: true,
    ecmaFeatures: {
      arrowFunctions: true,
      blockBindings: true,
      destructuring: true,
      regexYFlag: true,
      regexUFlag: true,
      templateStrings: true,
      binaryLiterals: true,
      unicodeCodePointEscapes: true,
      defaultParams: true,
      restParams: true,
      forOf: true,
      objectLiteralComputedProperties: true,
      objectLiteralShorthandMethods: true,
      objectLiteralShorthandProperties: true,
      objectLiteralDuplicateProperties: true,
      generators: true,
      spread: true,
      classes: true,
      modules: true,
      jsx: true,
      globalReturn: true,
    }
  });

  var featureInfo = featureFinder();
  var behaviorInfo = behaviorFinder();
  var elementInfo = elementFinder();

  var visitors = [featureInfo, behaviorInfo, elementInfo].map(function(info) {
    return info.visitors;
  });
  estraverse.traverse(script, traverse(visitors));

  return {
    behaviors: behaviorInfo.behaviors,
    elements:  elementInfo.elements,
    features:  featureInfo.features,
    parsedScript: script
  };
};
開發者ID:TestNaga,項目名稱:apm-sunburst,代碼行數:46,代碼來源:js-parse.ts

示例4: requires

function requires(code: string): string[] {
    let ast = esprima.parse(code);
    let requires: string[] = [];
    estraverse.traverse(ast, {
        enter: node => {
            if (node.type == "CallExpression" && node.callee.name == "require") {
                if (node.arguments > 1) {
                    throw "require 的參數大於 1";
                }
                if (node.arguments[0].type != "Literal") {
                    throw "require 的參數解析失敗";
                }
                requires.push(node.arguments[0].value);
            }
        }
    });
    return requires;
}
開發者ID:leon740727,項目名稱:wcp,代碼行數:18,代碼來源:type-js.ts

示例5: function

    paths.forEach((p:string) => {
      var src = fs.readFileSync(p).toString()
      var ast = esprima.parse(src, {comment: true, attachComment: true})

      var matcher = jsstana.createMatcher("(call (lookup AWS.util.update) ? ?)")

      estraverse.traverse(ast, {
        enter: function (n:any) {
          if (matcher(n)) {
            var classname = escodegen.generate(n.arguments[0]).replace(/AWS\.(\w+)\.prototype/, "$1")

            var methodList = n.arguments[1].properties.map((x:any) => {
              var context = {
                classname: classname,
                name: x.key.name,
                commentStr: (x.leadingComments && x.leadingComments.map((x: any) => { return x.value }).join('\n')) || ""
              } as ExtraClientMethod

              context.commentStr = context.commentStr.replace(/\n\s+\*/g, "\n     *");

              var m = /@api\s+private/.exec(context.commentStr)

              if (m) {
                return null
              }

              if (0 == context.commentStr.length) {
                context.commentStr = null;
              }

              return context
            }).filter((x: ExtraClientMethod) => {
              return null != x
            })

            console.log("Adding class: ", classname, " and methods: ", methodList)

            methodsToAdd[classname] = methodList
          }
        }
      })
    })
開發者ID:AitorGuerrero,項目名稱:aws-sdk-typescript,代碼行數:42,代碼來源:app.ts

示例6: function

    paths.forEach(function(p: string) {
      var src = fs.readFileSync(p).toString()
      var ast = esprima.parse(src)

      var matcher = jsstana.createMatcher("(call (lookup AWS.util.update) ? ?)")

      estraverse.traverse(ast, {
        enter: function(n: any) {
          if (matcher(n)) {
            var classname = escodegen.generate(n.arguments[0]).replace(/AWS\.(\w+)\.prototype/, "$1")

            var methodList = n.arguments[1].properties.map(function(x: any) { return x.key.name })

            console.log("Adding class: ", classname, " and methods: ", methodList)

            methodsToAdd[classname] = methodList
          }
        }
      })
    })
開發者ID:Bnaya,項目名稱:aws-sdk-typescript,代碼行數:20,代碼來源:app.ts

示例7: getCalleeBlockStatement

    /**
     * @param {NodeGuards} targetNode
     * @param {string} name
     * @returns {BlockStatement}
     */
    private getCalleeBlockStatement (targetNode: ESTree.Node, name: string): ESTree.BlockStatement | null {
        let calleeBlockStatement: ESTree.BlockStatement | null = null;

        estraverse.traverse(targetNode, {
            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;
                }
            }
        });

        return calleeBlockStatement;
    }
開發者ID:dssoft32,項目名稱:javascript-obfuscator,代碼行數:26,代碼來源:FunctionExpressionCalleeDataExtractor.ts

示例8: getMemberExpressionNameList

/**
 * @return {string[]|null} null if the expression includes a literal.
 */
function getMemberExpressionNameList(
  expression: estree.MemberExpression | estree.Identifier
): string[] | null {
  const fullname: string[] = [];
  let includeLiteral = false;
  estraverse.traverse(expression, {
    enter(node, parent) {
      if ((node.type === 'MemberExpression' && node.computed) || node.type === Syntax.Literal) {
        includeLiteral = true;
        this.break();
      }
    },
    leave(node, parent) {
      if (node.type === Syntax.Identifier) {
        fullname.push(node.name);
      }
    },
  });
  if (includeLiteral) {
    return null;
  }
  return fullname;
}
開發者ID:teppeis,項目名稱:closure-ts,代碼行數:26,代碼來源:generator.ts

示例9: jsParse

export function jsParse(jsString:string) {
  var script = espree.parse(jsString, {
    attachComment: true,
    comment: true,
    loc: true,
    ecmaVersion: 6
  });

  var featureInfo = featureFinder();
  var behaviorInfo = behaviorFinder();
  var elementInfo = elementFinder();

  var visitors = [featureInfo, behaviorInfo, elementInfo].map(function(info) {
    return info.visitors;
  });
  estraverse.traverse(script, traverse(visitors));

  return {
    behaviors: behaviorInfo.behaviors,
    elements:  elementInfo.elements,
    features:  featureInfo.features,
    parsedScript: script
  };
};
開發者ID:Analyticalloopholes,項目名稱:hydrolysis,代碼行數:24,代碼來源:js-parse.ts

示例10:

                        }
                    }
                }
            ],
            "kind": "var"
        }
    ],
    "sourceType": "script"
};

estraverse.traverse(ast, {
    enter: (node: any, parentNode: any) => {
        if (node.type === 'Identifier') {
            return estraverse.VisitorOption.Skip;
        }
    },
    leave: (node: any, parentNode: any) => {},
    fallback: 'iteration',
    keys: {
        TestExpression: ['argument']
    }
});

estraverse.replace(ast, {
    enter: (node: any, parentNode: any) => {
        return node;
    },
    leave: (node: any, parentNode: any) => {
        return node;
    }
});
開發者ID:1drop,項目名稱:DefinitelyTyped,代碼行數:31,代碼來源:estraverse-tests.ts


注:本文中的estraverse.traverse函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。