create.cjs 824 B

1234567891011121314151617181920212223242526272829303132
  1. 'use strict';
  2. const List = require('../utils/List.cjs');
  3. function createConvertor(walk) {
  4. return {
  5. fromPlainObject(ast) {
  6. walk(ast, {
  7. enter(node) {
  8. if (node.children && node.children instanceof List.List === false) {
  9. node.children = new List.List().fromArray(node.children);
  10. }
  11. }
  12. });
  13. return ast;
  14. },
  15. toPlainObject(ast) {
  16. walk(ast, {
  17. leave(node) {
  18. if (node.children && node.children instanceof List.List) {
  19. node.children = node.children.toArray();
  20. }
  21. }
  22. });
  23. return ast;
  24. }
  25. };
  26. }
  27. exports.createConvertor = createConvertor;