"use strict";import{generate as f}from"../generator/generate.js";import{parse as u}from"../parser/parse.js";import{traverse as O}from"../traverser/traverse.js";import{OnigUnicodePropertyMap as c}from"../unicode.js";import{optimizations as n}from"./optimizations.js";function g(e,t){const i=z(t),s=u(e,{flags:i.flags,rules:{captureGroup:i.rules.captureGroup,singleline:i.rules.singleline},skipBackrefValidation:i.rules.allowOrphanBackrefs,unicodePropertyMap:c}),a=Object.assign(p(),i.override);for(const r of n.keys())a[r]||delete a[r];const l=Object.keys(a);let o={pattern:e,flags:i.flags},m=0;do{if(++m>200)throw new Error("Optimization exceeded maximum iterations; possible infinite loop");e=o.pattern;for(const r of l)O(s,n.get(r));o=f(s)}while(e!==o.pattern);return o}function z(e={}){return{flags:"",override:{},...e,rules:{allowOrphanBackrefs:!1,captureGroup:!1,singleline:!1,...e.rules}}}function p(e={}){const t={};for(const i of n.keys())t[i]=!e.disable;return t}export{p as getOptionalOptimizations,g as optimize};
//# sourceMappingURL=optimize.js.map
