本文整理汇总了TypeScript中estraverse.replace函数的典型用法代码示例。如果您正苦于以下问题:TypeScript replace函数的具体用法?TypeScript replace怎么用?TypeScript replace使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了replace函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: appendNode
public appendNode (): void {
estraverse.replace(this.astTree, {
leave: (node, parent) => {
switch (node.type) {
case 'Program':
node.body.push(this.getNode());
break;
}
}
});
}
示例2:
.forEach((property: IPropertyNode) => {
estraverse.replace(property.key, {
leave: (node: INode, parentNode: INode): any => {
if (Nodes.isLiteralNode(node)) {
this.obfuscateLiteralPropertyKey(node);
return;
}
if (Nodes.isIdentifierNode(node)) {
this.obfuscateIdentifierPropertyKey(node);
}
}
});
});
示例3: switch
objectExpressionNode.properties.forEach((property) => {
estraverse.replace(property.key, {
leave: (node, parentNode) => {
switch (node.type) {
case 'Literal':
this.literalNodeController(node);
break;
case 'Identifier':
this.identifierNodeController(node);
break;
}
}
});
});
示例4: obfuscateNode
/**
* @param memberExpressionNode
*/
public obfuscateNode (memberExpressionNode: IMemberExpressionNode): void {
estraverse.replace(memberExpressionNode.property, {
leave: (node: INode, parentNode: INode): any => {
if (Nodes.isLiteralNode(node)) {
this.obfuscateLiteralProperty(node);
return;
}
if (Nodes.isIdentifierNode(node)) {
if (memberExpressionNode.computed) {
return;
}
memberExpressionNode.computed = true;
this.obfuscateIdentifierProperty(node);
}
}
});
}
示例5: function
files.forEach((file: {src: string[]; dest: string}) => {
var jsFileContent = fs.readFileSync(file.src[0]).toString(),
ast = esprima.parse(jsFileContent, {loc: true, range: true});
// Ensure destination folder exists
if (!fs.existsSync(path.dirname(file.dest))) {
grunt.file.mkdir(path.dirname(file.dest));
}
var processedAst = estraverse.replace(ast, {
enter: function(node: any) {
if (node.type === 'ExpressionStatement' &&
node.expression.type === 'CallExpression' &&
remove.indexOf(node.expression.callee.name) > -1) {
return {type:'EmptyStatement'};
}
}
}), output = escodegen.generate(processedAst, {sourceMap: path.relative(path.dirname(file.dest), file.src[0]), sourceMapWithCode: true});
var mapDest = file.dest + '.map';
fs.writeFileSync(mapDest, output.map);
fs.writeFileSync(file.dest, `${output.code}\n//# sourceMappingURL=${path.basename(file.dest)}.map`);
});
示例6: obfuscateNode
/**
* @param memberExpressionNode
*/
public obfuscateNode (memberExpressionNode: any): void {
estraverse.replace(memberExpressionNode.property, {
leave: (node, parentNode) => {
switch (node.type) {
case 'Literal':
this.literalNodeController(node);
break;
case 'Identifier':
if (memberExpressionNode.computed) {
break;
}
memberExpressionNode.computed = true;
this.identifierNodeController(node);
break;
}
}
});
}
示例7:
}
}
}
],
"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;
}
});
示例8: enter
}
}
],
"kind": "var"
}
],
"sourceType": "script"
};
estraverse.traverse(ast, {
enter(node: estree.Node, parentNode: estree.Node | null) {
if (node.type === 'Identifier') {
return estraverse.VisitorOption.Skip;
}
},
leave: (node: estree.Node, parentNode: estree.Node | null) => {},
fallback: 'iteration',
keys: {
TestExpression: ['argument']
}
});
estraverse.replace(ast, {
enter: (node: estree.Node, parentNode: estree.Node | null) => {
return node;
},
leave: (node: estree.Node, parentNode: estree.Node | null) => {
return node;
}
});