create.js 804 B

12345678910111213141516171819202122232425262728
  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. };