本文整理汇总了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;
}
示例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;
}
示例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
};
};
示例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;
}
示例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
}
}
})
})
示例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
}
}
})
})
示例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;
}
示例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;
}
示例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
};
};
示例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;
}
});