You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
923 B

4 years ago
  1. /**
  2. * Module dependencies.
  3. */
  4. var Compressed = require('./compress');
  5. var Identity = require('./identity');
  6. /**
  7. * Stringfy the given AST `node`.
  8. *
  9. * Options:
  10. *
  11. * - `compress` space-optimized output
  12. * - `sourcemap` return an object with `.code` and `.map`
  13. *
  14. * @param {Object} node
  15. * @param {Object} [options]
  16. * @return {String}
  17. * @api public
  18. */
  19. module.exports = function(node, options){
  20. options = options || {};
  21. var compiler = options.compress
  22. ? new Compressed(options)
  23. : new Identity(options);
  24. // source maps
  25. if (options.sourcemap) {
  26. var sourcemaps = require('./source-map-support');
  27. sourcemaps(compiler);
  28. var code = compiler.compile(node);
  29. compiler.applySourceMaps();
  30. var map = options.sourcemap === 'generator'
  31. ? compiler.map
  32. : compiler.map.toJSON();
  33. return { code: code, map: map };
  34. }
  35. var code = compiler.compile(node);
  36. return code;
  37. };