"use strict";import{throwIfNullish as A}from"../utils.js";function S(a,v,N=null){function b(e,s){for(let t=0;t<e.length;t++){const r=n(e[t],s,t,e);t=Math.max(-1,t+r)}}function n(e,s=null,t=null,r=null){let i=0,c=!1;const d={node:e,parent:s,key:t,container:r,root:a,remove(){x(r).splice(Math.max(0,l(t)+i),1),i--,c=!0},removeAllNextSiblings(){return x(r).splice(l(t)+1)},removeAllPrevSiblings(){const o=l(t)+i;return i-=o,x(r).splice(0,Math.max(0,o))},replaceWith(o,m={}){const y=!!m.traverse;r?r[Math.max(0,l(t)+i)]=o:A(s,"Can't replace root node")[t]=o,y&&n(o,s,t,r),c=!0},replaceWithMultiple(o,m={}){const y=!!m.traverse;if(x(r).splice(Math.max(0,l(t)+i),1,...o),i+=o.length-1,y){let g=0;for(let p=0;p<o.length;p++)g+=n(o[p],s,l(t)+p+g,r)}c=!0},skip(){c=!0}},{type:f}=e,u=v["*"],h=v[f],R=typeof u=="function"?u:u?.enter,P=typeof h=="function"?h:h?.enter;if(R?.(d,N),P?.(d,N),!c)switch(f){case"AbsenceFunction":case"Alternative":case"CapturingGroup":case"CharacterClass":case"Group":case"LookaroundAssertion":b(e.body,e);break;case"Assertion":case"Backreference":case"Character":case"CharacterSet":case"Directive":case"Flags":case"NamedCallout":case"Subroutine":break;case"CharacterClassRange":n(e.min,e,"min"),n(e.max,e,"max");break;case"Quantifier":n(e.body,e,"body");break;case"Regex":b(e.body,e),n(e.flags,e,"flags");break;default:throw new Error(`Unexpected node type "${f}"`)}return h?.exit?.(d,N),u?.exit?.(d,N),i}return n(a),a}function x(a){if(!Array.isArray(a))throw new Error("Container expected");return a}function l(a){if(typeof a!="number")throw new Error("Numeric key expected");return a}export{S as traverse};
//# sourceMappingURL=traverse.js.map
