I want to do two replacements in my babel plugin. And second replacement should only happen after first one is done.
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"));
}
}
};
}
In the AST tree of my "FunctionExpression" the "ThisExpression" exists somewhere down the tree. I want first conversion to happen only after the second conversion is done. How do I achieve this.?