�PNG  IHDR��;���IDATx��ܻn�0���K�� �)(�pA��� ���7�LeG{�� �§㻢|��ذaÆ 6lذaÆ 6lذaÆ 6lom��$^�y���ذag�5bÆ 6lذaÆ 6lذa{���� 6lذaÆ �`����}H�Fkm�,�m����Ӫ���ô�ô!� �x�|'ܢ˟;�E:���9�&ᶒ�}�{�v]�n&�6� �h��_��t�ڠ͵-ҫ���Z;��Z$�.�P���k�ž)�!��o���>}l�eQfJ�T��u і���چ��\��X=8��Rن4`Vw�l�>����n�G�^��i�s��"ms�$�u��i��?w�bs[m�6�K4���O���.�4��%����/����b�C%��t ��M�ז� �-l�G6�mrz2���s�%�9��s@���-�k�9�=���)������k�B5����\��+͂�Zsٲ ��Rn��~G���R���C����� �wIcI��n7jJ���hۛNCS|���j0��8y�iHKֶۛ�k�Ɉ+;Sz������L/��F�*\��Ԕ�#"5��m�2��[S��������=�g��n�a�P�e�ғ�L�� lذaÆ 6l�^k��̱aÆ 6lذaÆ 6lذa;���� �_��ذaÆ 6lذaÆ 6lذaÆ ���R���IEND�B` 'use strict'; const { expect } = require('chai'); const { visit, detachNodeFromParent } = require('./xast.js'); const getAst = () => { const ast = { type: 'root', children: [ { type: 'element', name: 'g', attributes: {}, children: [ { type: 'element', name: 'rect', attributes: {}, children: [], }, { type: 'element', name: 'circle', attributes: {}, children: [], }, ], }, { type: 'element', name: 'ellipse', attributes: {}, children: [], }, ], }; ast.children[0].parentNode = ast; ast.children[0].children[0].parentNode = ast.children[0]; ast.children[0].children[1].parentNode = ast.children[0]; ast.children[1].parentNode = ast; return ast; }; describe('xast', () => { it('enter into nodes', () => { const root = getAst(); const entered = []; visit(root, { root: { enter: (node) => { entered.push(node.type); }, }, element: { enter: (node) => { entered.push(`${node.type}:${node.name}`); }, }, }); expect(entered).to.deep.equal([ 'root', 'element:g', 'element:rect', 'element:circle', 'element:ellipse', ]); }); it('exit from nodes', () => { const root = getAst(); const exited = []; visit(root, { root: { exit: (node) => { exited.push(node.type); }, }, element: { exit: (node) => { exited.push(`${node.type}:${node.name}`); }, }, }); expect(exited).to.deep.equal([ 'element:rect', 'element:circle', 'element:g', 'element:ellipse', 'root', ]); }); it('skip entering children if node is detached', () => { const root = getAst(); const entered = []; visit(root, { element: { enter: (node) => { entered.push(node.name); if (node.name === 'g') { detachNodeFromParent(node); } }, }, }); expect(entered).to.deep.equal(['g', 'ellipse']); }); });