plugin-preeval.js 695 B

12345678910111213141516171819202122232425262728
  1. module.exports = {
  2. install({ tree: { Quoted }, visitors }, manager) {
  3. class Visitor {
  4. constructor() {
  5. this.native = new visitors.Visitor(this);
  6. this.isPreEvalVisitor = true;
  7. this.isReplacing = true;
  8. }
  9. run(root) {
  10. return this.native.visit(root);
  11. }
  12. visitVariable(node) {
  13. if (node.name === '@replace') {
  14. return new Quoted(`'`, 'bar', true);
  15. }
  16. return node;
  17. }
  18. }
  19. manager.addVisitor(new Visitor());
  20. // console.log(manager);
  21. },
  22. minVersion: [2,0,0]
  23. };