本文整理匯總了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;
}
});