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.

28 lines
804 B

4 years ago
  1. var List = require('../common/List');
  2. module.exports = function createConvertors(walk) {
  3. return {
  4. fromPlainObject: function(ast) {
  5. walk(ast, {
  6. enter: function(node) {
  7. if (node.children && node.children instanceof List === false) {
  8. node.children = new List().fromArray(node.children);
  9. }
  10. }
  11. });
  12. return ast;
  13. },
  14. toPlainObject: function(ast) {
  15. walk(ast, {
  16. leave: function(node) {
  17. if (node.children && node.children instanceof List) {
  18. node.children = node.children.toArray();
  19. }
  20. }
  21. });
  22. return ast;
  23. }
  24. };
  25. };