stringify.js 545 B

1234567891011121314151617181920
  1. "use strict";
  2. function stringify (document) {
  3. let stringify;
  4. if (document instanceof require("./document")) {
  5. stringify = docStringify;
  6. } else {
  7. stringify = document.source.syntax.stringify;
  8. }
  9. return stringify.apply(this, arguments);
  10. }
  11. function docStringify (document, builder) {
  12. document.nodes.forEach((root, i) => {
  13. builder(root.raws.beforeStart, root, "beforeStart");
  14. root.source.syntax && root.source.syntax.stringify(root, builder);
  15. });
  16. builder(document.raws.afterEnd, document, "afterEnd");
  17. }
  18. module.exports = stringify;