import '../../../../../stringify-entities@4.0.4/node_modules/stringify-entities/index.mjs';
import { stringifyEntities } from '../../../../../stringify-entities@4.0.4/node_modules/stringify-entities/lib/index.mjs';

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


/**
 * Serialize a comment.
 *
 * @param {Comment} node
 *   Node to handle.
 * @param {number | undefined} _1
 *   Index of `node` in `parent.
 * @param {Parent | undefined} _2
 *   Parent of `node`.
 * @param {State} state
 *   Info passed around about the current state.
 * @returns {string}
 *   Serialized node.
 */
function comment(node, _1, _2, state) {
  // See: <https://html.spec.whatwg.org/multipage/syntax.html#comments>
  return state.settings.bogusComments
    ? '<?' +
        stringifyEntities(
          node.value,
          Object.assign({}, state.settings.characterReferences, {subset: ['>']})
        ) +
        '>'
    : '<!--' + node.value.replace(/^>|^->|<!--|-->|--!>|<!-$/g, encode) + '-->'

  /**
   * @param {string} $0
   */
  function encode($0) {
    return stringifyEntities(
      $0,
      Object.assign({}, state.settings.characterReferences, {
        subset: ['<', '>']
      })
    )
  }
}

export { comment };
//# sourceMappingURL=comment.mjs.map
