export default function({ types: t }) {
return {
pre(state) {
this.allString = '';
},
visitor: {
StringLiteral(path) {
this.allString += path.node.value;
}
},
post(state) {
// It does not work
state.code = `const allString = '${this.allString}'\n` + state.code;
}
};
}
For example, I want to add a variable that contains all the strings in the code, is it possible to be done by one plugin?