'use strict';

var index = require('../../../../../zwitch@2.0.4/node_modules/zwitch/index.js');
var comment = require('./comment.js');
var doctype = require('./doctype.js');
var element = require('./element.js');
var raw = require('./raw.js');
var root = require('./root.js');
var text = require('./text.js');

/**
 * @typedef {import('../types.js').State} State
 * @typedef {import('../types.js').Node} Node
 * @typedef {import('../types.js').Parent} Parent
 */


/**
 * @type {(node: Node, index: number | undefined, parent: Parent | undefined, state: State) => string}
 */
const handle = index.zwitch('type', {
  invalid,
  unknown,
  handlers: {comment: comment.comment, doctype: doctype.doctype, element: element.element, raw: raw.raw, root: root.root, text: text.text}
});

/**
 * Fail when a non-node is found in the tree.
 *
 * @param {unknown} node
 *   Unknown value.
 * @returns {never}
 *   Never.
 */
function invalid(node) {
  throw new Error('Expected node, not `' + node + '`')
}

/**
 * Fail when a node with an unknown type is found in the tree.
 *
 * @param {unknown} node
 *  Unknown node.
 * @returns {never}
 *   Never.
 */
function unknown(node) {
  // @ts-expect-error: `type` is defined.
  throw new Error('Cannot compile unknown node `' + node.type + '`')
}

exports.handle = handle;
//# sourceMappingURL=index.js.map
