Spamworldpro Mini Shell
Spamworldpro


Server : Apache
System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64
User : corals ( 1002)
PHP Version : 7.4.33
Disable Function : exec,passthru,shell_exec,system
Directory :  /home/corals/clinic.corals.io/node_modules/svgo/lib/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/clinic.corals.io/node_modules/svgo/lib/xast.test.js
'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']);
  });
});

Spamworldpro Mini