倾斜 
@es-joy/estraverse (单位:千美元)倾斜)为
叉子为 倾斜。 。 。 .
ECMAS脚本 转动函数从 esmangle 项目。 。 。 .
文档
您可以在 维基页面。 。 。 .
示例使用
以下代码将输出文件根所声明的所有变量 .
estraverse.traverse(ast, {
enter (node, parent) {
if (node.type == 'FunctionExpression' || node.type == 'FunctionDeclaration')
return estraverse.VisitorOption.Skip;
},
leave (node, parent) {
if (node.type == 'VariableDeclarator')
console.log(node.id.name);
}
});
我们可以用 this.skip, (中文(简体) ), this.remove 财务报告和审定财务报表 this.break 函数,而不是使用跳过、删除和断开.
estraverse.traverse(ast, {
enter (node) {
this.break();
}
});
而偏执提供 estraverse.replace 函数。 返回节点时 enter编号 :leave,当前节点被替换.
const result = estraverse.replace(tree, {
enter (node) {
// Replace it with replaced.
if (node.type === 'Literal')
return replaced;
}
});
路过 visitor.keys 绘图,我们可以扩展 斜向穿行功能.
// This tree contains a user-defined `TestExpression` node.
const tree = {
type: 'TestExpression',
// This 'argument' is the property containing the other **node**.
argument: {
type: 'Literal',
value: 20
},
// This 'extended' is the property not containing the other **node**.
extended: true
};
estraverse.traverse(tree, {
enter (node) { },
// Extending the existing traversing rules.
keys: {
// TargetNodeName: [ 'keys', 'containing', 'the', 'other', '**node**' ]
TestExpression: ['argument']
}
});
路过 visitor.fallback 选项,可以在遇到未知节点时控制行为.
// This tree contains a user-defined `TestExpression` node.
const tree = {
type: 'TestExpression',
// This 'argument' is the property containing the other **node**.
argument: {
type: 'Literal',
value: 20
},
// This 'extended' is the property not containing the other **node**.
extended: true
};
estraverse.traverse(tree, {
enter (node) { },
// Iterating the child **nodes** of unknown nodes.
fallback: 'iteration'
});
何时 visitor.fallback 是一个函数, 我们可以确定每个节点上要访问的密钥 .
// This tree contains a user-defined `TestExpression` node.
const tree = {
type: 'TestExpression',
// This 'argument' is the property containing the other **node**.
argument: {
type: 'Literal',
value: 20
},
// This 'extended' is the property not containing the other **node**.
extended: true
};
estraverse.traverse(tree, {
enter (node) { },
// Skip the `argument` property of each node
fallback(node) {
return Object.keys(node).filter((key) => {
return key !== 'argument';
});
}
});
许可证
版权(C)2012-2016年 铃木雄介 (推特: @ 星座图和其他贡献者.
源形式和二进制形式的再分配和使用,不论有无 修改,但必须符合下列条件:
-
源代码的再分配必须保留上述版权 通知、本条件清单和下列免责声明.
-
二进制形式的再分配必须复制上述版权 通知、本条件清单和 分发时提供的文件和/或其他材料.
这个软件是由警察的 持有和贡献"是" 和任何战争遗留爆炸物,包括,但不受限制 紧迫性和特别目的的保证 被隔离。 绝对不能为任何人 直接、间接、突发事件、特别、紧急、或后果 (包括,但不限制,实质性货物或服务的采购; 使用、数据或赞助;或业务中断) 关于任何负债的理论,无论在合同、合同或合同中 以任何方式出现于 这个软件,甚至如果 警告这种可能性的 如此灾难.