Urara-Blog/node_modules/.pnpm-store/v3/files/f3/a55d4028c122268ebabcbcaafa3292943e1d49b57b1d6079f06a610acebc796621820a3e8653160ba720ff2f38fe3039c0f1b424099d74446d3fe12240cfa3
2022-08-14 01:14:53 +08:00

32 lines
824 B
Text

'use strict';
const List = require('../utils/List.cjs');
function createConvertor(walk) {
return {
fromPlainObject(ast) {
walk(ast, {
enter(node) {
if (node.children && node.children instanceof List.List === false) {
node.children = new List.List().fromArray(node.children);
}
}
});
return ast;
},
toPlainObject(ast) {
walk(ast, {
leave(node) {
if (node.children && node.children instanceof List.List) {
node.children = node.children.toArray();
}
}
});
return ast;
}
};
}
exports.createConvertor = createConvertor;