compiler.js 738 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /**
  2. * Expose `Compiler`.
  3. */
  4. module.exports = Compiler;
  5. /**
  6. * Initialize a compiler.
  7. *
  8. * @param {Type} name
  9. * @return {Type}
  10. * @api public
  11. */
  12. function Compiler(opts) {
  13. this.options = opts || {};
  14. }
  15. /**
  16. * Emit `str`
  17. */
  18. Compiler.prototype.emit = function(str) {
  19. return str;
  20. };
  21. /**
  22. * Visit `node`.
  23. */
  24. Compiler.prototype.visit = function(node){
  25. return this[node.type](node);
  26. };
  27. /**
  28. * Map visit over array of `nodes`, optionally using a `delim`
  29. */
  30. Compiler.prototype.mapVisit = function(nodes, delim){
  31. var buf = '';
  32. delim = delim || '';
  33. for (var i = 0, length = nodes.length; i < length; i++) {
  34. buf += this.visit(nodes[i]);
  35. if (delim && i < length - 1) buf += this.emit(delim);
  36. }
  37. return buf;
  38. };