【发布时间】:2017-01-31 12:47:14
【问题描述】:
我想在我的 babel 插件中做两个替换。第二次替换只能在第一次替换完成后进行。
module.exports = function(babel) {
const t = babel.types;
return {
visitor: {
FunctionExpression: function(path) {
//Conversion to arrow functions
path.replaceWith(t.arrowFunctionExpression(path.node.params, path.node.body, false));
},
ThisExpression: function(path) {
//Converting all this expressions to identifiers so that it won't get translated differently
path.replaceWith(t.identifier("this"));
}
}
};
}
在我的“FunctionExpression”的 AST 树中,“ThisExpression”存在于树的某处。我希望第一次转换仅在第二次转换完成后发生。我该如何做到这一点?
【问题讨论】:
标签: javascript babeljs visitor-pattern