From 7b680068d8e2ced218e811aacc56e09728228c6b Mon Sep 17 00:00:00 2001 From: Steven Levithan Date: Sun, 27 Oct 2024 17:15:43 +0100 Subject: [PATCH] Transform quantified assertions --- dist/index.min.js | 64 ++++++++++++++++++------------------- src/generate.js | 7 +++-- src/parse.js | 15 +++++---- src/transform.js | 80 ++++++++++++++++++++++++++++++----------------- src/traverse.js | 4 +-- 5 files changed, 98 insertions(+), 72 deletions(-) diff --git a/dist/index.min.js b/dist/index.min.js index 79634fa..00ce992 100644 --- a/dist/index.min.js +++ b/dist/index.min.js @@ -1,9 +1,9 @@ -var OnigurumaToES=(()=>{var ee=Object.defineProperty;var dt=Object.getOwnPropertyDescriptor;var Ct=Object.getOwnPropertyNames;var mt=Object.prototype.hasOwnProperty;var Et=(e,t)=>{for(var r in t)ee(e,r,{get:t[r],enumerable:!0})},wt=(e,t,r,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of Ct(t))!mt.call(e,n)&&n!==r&&ee(e,n,{get:()=>t[n],enumerable:!(s=dt(t,n))||s.enumerable});return e};var At=e=>wt(ee({},"__esModule",{value:!0}),e);var Ur={};Et(Ur,{compile:()=>Ae,toOnigurumaAst:()=>ht,toRegExp:()=>Rr,toRegexAst:()=>Dr});var te=String.raw,Se=te`(?:\p{Emoji}\uFE0F\u20E3?|\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation})`,ke=te`\u{E0061}-\u{E007A}`,be=()=>new RegExp(te`[\u{1F1E6}-\u{1F1FF}]{2}|\u{1F3F4}[${ke}]{2}[\u{E0030}-\u{E0039}${ke}]{1,3}\u{E007F}|${Se}(?:\u200D${Se})*`,"gu");var A=String.fromCodePoint,f=String.raw,z={ES2018:2018,ES2024:2024,ESNext:2025};function v(e,t,r){return e.has(t)||e.set(t,r),e.get(t)}function M(e,t){return z[e]>=z[t]}function I(e,t){if(!e)throw new Error(t??"Value expected");return e}var St=new Set([A(304),A(305)]);function ne(e){if(St.has(e))return[e];let t=new Set,r=e.toLowerCase(),s=r.toUpperCase(),n=_t.get(r),a=bt.get(r);return[...s].length===1&&t.add(s),t.add(r),n&&t.add(n),a&&t.add(a),[...t]}var se=new Set(["C","Other","Cc","Control","cntrl","Cf","Format","Cn","Unassigned","Co","Private_Use","Cs","Surrogate","L","Letter","LC","Cased_Letter","Ll","Lowercase_Letter","Lm","Modifier_Letter","Lo","Other_Letter","Lt","Titlecase_Letter","Lu","Uppercase_Letter","M","Mark","Combining_Mark","Mc","Spacing_Mark","Me","Enclosing_Mark","Mn","Nonspacing_Mark","N","Number","Nd","Decimal_Number","digit","Nl","Letter_Number","No","Other_Number","P","Punctuation","punct","Pc","Connector_Punctuation","Pd","Dash_Punctuation","Pe","Close_Punctuation","Pf","Final_Punctuation","Pi","Initial_Punctuation","Po","Other_Punctuation","Ps","Open_Punctuation","S","Symbol","Sc","Currency_Symbol","Sk","Modifier_Symbol","Sm","Math_Symbol","So","Other_Symbol","Z","Separator","Zl","Line_Separator","Zp","Paragraph_Separator","Zs","Space_Separator","ASCII","ASCII_Hex_Digit","AHex","Alphabetic","Alpha","Any","Assigned","Bidi_Control","Bidi_C","Bidi_Mirrored","Bidi_M","Case_Ignorable","CI","Cased","Changes_When_Casefolded","CWCF","Changes_When_Casemapped","CWCM","Changes_When_Lowercased","CWL","Changes_When_NFKC_Casefolded","CWKCF","Changes_When_Titlecased","CWT","Changes_When_Uppercased","CWU","Dash","Default_Ignorable_Code_Point","DI","Deprecated","Dep","Diacritic","Dia","Emoji","Emoji_Component","EComp","Emoji_Modifier","EMod","Emoji_Modifier_Base","EBase","Emoji_Presentation","EPres","Extended_Pictographic","ExtPict","Extender","Ext","Grapheme_Base","Gr_Base","Grapheme_Extend","Gr_Ext","Hex_Digit","Hex","IDS_Binary_Operator","IDSB","IDS_Trinary_Operator","IDST","ID_Continue","IDC","ID_Start","IDS","Ideographic","Ideo","Join_Control","Join_C","Logical_Order_Exception","LOE","Lowercase","Lower","Math","Noncharacter_Code_Point","NChar","Pattern_Syntax","Pat_Syn","Pattern_White_Space","Pat_WS","Quotation_Mark","QMark","Radical","Regional_Indicator","RI","Sentence_Terminal","STerm","Soft_Dotted","SD","Terminal_Punctuation","Term","Unified_Ideograph","UIdeo","Uppercase","Upper","Variation_Selector","VS","White_Space","space","XID_Continue","XIDC","XID_Start","XIDS"]),ae=new Map;for(let e of se)ae.set(B(e),e);var kt=new Set(["Basic_Emoji","Emoji_Keycap_Sequence","RGI_Emoji","RGI_Emoji_Flag_Sequence","RGI_Emoji_Modifier_Sequence","RGI_Emoji_Tag_Sequence","RGI_Emoji_ZWJ_Sequence"]),oe=new Map;for(let e of kt)oe.set(B(e),e);var _e=new Set("Dogr Dogra Gong Gunjala_Gondi Hanifi_Rohingya Maka Makasar Medefaidrin Medf Old_Sogdian Rohg Sogd Sogdian Sogo Extended_Pictographic Elym Elymaic Hmnp Nand Nandinagari Nyiakeng_Puachue_Hmong Wancho Wcho Chorasmian Chrs Diak Dives_Akuru Khitan_Small_Script Kits Yezi Yezidi EBase EComp EMod EPres ExtPict Cpmn Cypro_Minoan Old_Uyghur Ougr Tangsa Tnsa Toto Vith Vithkuqi Gara Garay Gukh Gurung_Khema Hrkt Katakana_Or_Hiragana Kawi Kirat_Rai Krai Nag_Mundari Nagm Ol_Onal Onao Sunu Sunuwar Todhri Todr Tulu_Tigalari Tutg Unknown Zzzz".split(" ")),bt=new Map([[A(223),A(7838)],[A(107),A(8490)],[A(229),A(8491)],[A(969),A(8486)]]),_t=new Map([P(453),P(456),P(459),P(498),...re(8072,8079),...re(8088,8095),...re(8104,8111),P(8124),P(8140),P(8188)]),K=new Map([["alnum",f`[\p{Alpha}\p{Nd}]`],["alpha",f`\p{Alpha}`],["ascii",f`\p{ASCII}`],["blank",f`[\p{Zs}\t]`],["cntrl",f`\p{cntrl}`],["digit",f`\p{Nd}`],["graph",f`[\P{space}&&\P{cntrl}&&\P{Cn}&&\P{Cs}]`],["lower",f`\p{Lower}`],["print",f`[[\P{space}&&\P{cntrl}&&\P{Cn}&&\P{Cs}]\p{Zs}]`],["punct",f`[\p{P}\p{S}]`],["space",f`\p{space}`],["upper",f`\p{Upper}`],["word",f`[\p{Alpha}\p{M}\p{Nd}\p{Pc}]`],["xdigit",f`\p{AHex}`]]),$e=new Set(["alnum","blank","graph","print","word","xdigit"]);function $t(e,t){let r=[];for(let s=e;s<=t;s++)r.push(s);return r}function B(e){return e.replace(/[- _]+/g,"").toLowerCase()}function P(e){let t=A(e);return[t.toLowerCase(),t]}function re(e,t){return $t(e,t).map(r=>P(r))}var ie=new Set(["Lower","Lowercase","Upper","Uppercase","Ll","Lowercase_Letter","Lt","Titlecase_Letter","Lu","Uppercase_Letter"]);var g={Alternator:"Alternator",Assertion:"Assertion",Backreference:"Backreference",Character:"Character",CharacterClassClose:"CharacterClassClose",CharacterClassHyphen:"CharacterClassHyphen",CharacterClassIntersector:"CharacterClassIntersector",CharacterClassOpen:"CharacterClassOpen",CharacterSet:"CharacterSet",Directive:"Directive",GroupClose:"GroupClose",GroupOpen:"GroupOpen",Subroutine:"Subroutine",Quantifier:"Quantifier",VariableLengthCharacterSet:"VariableLengthCharacterSet",EscapedNumber:"EscapedNumber"},S={any:"any",digit:"digit",hex:"hex",posix:"posix",property:"property",space:"space",word:"word"},V={keep:"keep",flags:"flags"},_={atomic:"atomic",capturing:"capturing",group:"group",lookahead:"lookahead",lookbehind:"lookbehind"},Ne=new Map([["a",7],["b",8],["e",27],["f",12],["n",10],["r",13],["t",9],["v",11]]),Fe="c.? | C(?:-.?)?",xe=f`[pP]\{(?:\^?[\x20\w]+\})?`,Le=f`u\{[^\}]*\}? | u\p{AHex}{0,4} | x\p{AHex}{0,2}`,Pe=f`\d{1,3}`,Te=f`\[\^?\]?`,ve=/[?*+][?+]?|\{\d+(?:,\d*)?\}\??/,W=new RegExp(f` +var OnigurumaToES=(()=>{var te=Object.defineProperty;var Et=Object.getOwnPropertyDescriptor;var wt=Object.getOwnPropertyNames;var At=Object.prototype.hasOwnProperty;var St=(e,t)=>{for(var r in t)te(e,r,{get:t[r],enumerable:!0})},kt=(e,t,r,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of wt(t))!At.call(e,n)&&n!==r&&te(e,n,{get:()=>t[n],enumerable:!(s=Et(t,n))||s.enumerable});return e};var bt=e=>kt(te({},"__esModule",{value:!0}),e);var Mr={};St(Mr,{compile:()=>be,toOnigurumaAst:()=>mt,toRegExp:()=>Gr,toRegexAst:()=>Or});var re=String.raw,_e=re`(?:\p{Emoji}\uFE0F\u20E3?|\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation})`,$e=re`\u{E0061}-\u{E007A}`,Ne=()=>new RegExp(re`[\u{1F1E6}-\u{1F1FF}]{2}|\u{1F3F4}[${$e}]{2}[\u{E0030}-\u{E0039}${$e}]{1,3}\u{E007F}|${_e}(?:\u200D${_e})*`,"gu");var A=String.fromCodePoint,f=String.raw,z={ES2018:2018,ES2024:2024,ESNext:2025};function T(e,t,r){return e.has(t)||e.set(t,r),e.get(t)}function B(e,t){return z[e]>=z[t]}function y(e,t){if(!e)throw new Error(t??"Value expected");return e}var _t=new Set([A(304),A(305)]);function se(e){if(_t.has(e))return[e];let t=new Set,r=e.toLowerCase(),s=r.toUpperCase(),n=yt.get(r),o=Nt.get(r);return[...s].length===1&&t.add(s),t.add(r),n&&t.add(n),o&&t.add(o),[...t]}var ae=new Set(["C","Other","Cc","Control","cntrl","Cf","Format","Cn","Unassigned","Co","Private_Use","Cs","Surrogate","L","Letter","LC","Cased_Letter","Ll","Lowercase_Letter","Lm","Modifier_Letter","Lo","Other_Letter","Lt","Titlecase_Letter","Lu","Uppercase_Letter","M","Mark","Combining_Mark","Mc","Spacing_Mark","Me","Enclosing_Mark","Mn","Nonspacing_Mark","N","Number","Nd","Decimal_Number","digit","Nl","Letter_Number","No","Other_Number","P","Punctuation","punct","Pc","Connector_Punctuation","Pd","Dash_Punctuation","Pe","Close_Punctuation","Pf","Final_Punctuation","Pi","Initial_Punctuation","Po","Other_Punctuation","Ps","Open_Punctuation","S","Symbol","Sc","Currency_Symbol","Sk","Modifier_Symbol","Sm","Math_Symbol","So","Other_Symbol","Z","Separator","Zl","Line_Separator","Zp","Paragraph_Separator","Zs","Space_Separator","ASCII","ASCII_Hex_Digit","AHex","Alphabetic","Alpha","Any","Assigned","Bidi_Control","Bidi_C","Bidi_Mirrored","Bidi_M","Case_Ignorable","CI","Cased","Changes_When_Casefolded","CWCF","Changes_When_Casemapped","CWCM","Changes_When_Lowercased","CWL","Changes_When_NFKC_Casefolded","CWKCF","Changes_When_Titlecased","CWT","Changes_When_Uppercased","CWU","Dash","Default_Ignorable_Code_Point","DI","Deprecated","Dep","Diacritic","Dia","Emoji","Emoji_Component","EComp","Emoji_Modifier","EMod","Emoji_Modifier_Base","EBase","Emoji_Presentation","EPres","Extended_Pictographic","ExtPict","Extender","Ext","Grapheme_Base","Gr_Base","Grapheme_Extend","Gr_Ext","Hex_Digit","Hex","IDS_Binary_Operator","IDSB","IDS_Trinary_Operator","IDST","ID_Continue","IDC","ID_Start","IDS","Ideographic","Ideo","Join_Control","Join_C","Logical_Order_Exception","LOE","Lowercase","Lower","Math","Noncharacter_Code_Point","NChar","Pattern_Syntax","Pat_Syn","Pattern_White_Space","Pat_WS","Quotation_Mark","QMark","Radical","Regional_Indicator","RI","Sentence_Terminal","STerm","Soft_Dotted","SD","Terminal_Punctuation","Term","Unified_Ideograph","UIdeo","Uppercase","Upper","Variation_Selector","VS","White_Space","space","XID_Continue","XIDC","XID_Start","XIDS"]),oe=new Map;for(let e of ae)oe.set(V(e),e);var $t=new Set(["Basic_Emoji","Emoji_Keycap_Sequence","RGI_Emoji","RGI_Emoji_Flag_Sequence","RGI_Emoji_Modifier_Sequence","RGI_Emoji_Tag_Sequence","RGI_Emoji_ZWJ_Sequence"]),ie=new Map;for(let e of $t)ie.set(V(e),e);var ye=new Set("Dogr Dogra Gong Gunjala_Gondi Hanifi_Rohingya Maka Makasar Medefaidrin Medf Old_Sogdian Rohg Sogd Sogdian Sogo Extended_Pictographic Elym Elymaic Hmnp Nand Nandinagari Nyiakeng_Puachue_Hmong Wancho Wcho Chorasmian Chrs Diak Dives_Akuru Khitan_Small_Script Kits Yezi Yezidi EBase EComp EMod EPres ExtPict Cpmn Cypro_Minoan Old_Uyghur Ougr Tangsa Tnsa Toto Vith Vithkuqi Gara Garay Gukh Gurung_Khema Hrkt Katakana_Or_Hiragana Kawi Kirat_Rai Krai Nag_Mundari Nagm Ol_Onal Onao Sunu Sunuwar Todhri Todr Tulu_Tigalari Tutg Unknown Zzzz".split(" ")),Nt=new Map([[A(223),A(7838)],[A(107),A(8490)],[A(229),A(8491)],[A(969),A(8486)]]),yt=new Map([P(453),P(456),P(459),P(498),...ne(8072,8079),...ne(8088,8095),...ne(8104,8111),P(8124),P(8140),P(8188)]),K=new Map([["alnum",f`[\p{Alpha}\p{Nd}]`],["alpha",f`\p{Alpha}`],["ascii",f`\p{ASCII}`],["blank",f`[\p{Zs}\t]`],["cntrl",f`\p{cntrl}`],["digit",f`\p{Nd}`],["graph",f`[\P{space}&&\P{cntrl}&&\P{Cn}&&\P{Cs}]`],["lower",f`\p{Lower}`],["print",f`[[\P{space}&&\P{cntrl}&&\P{Cn}&&\P{Cs}]\p{Zs}]`],["punct",f`[\p{P}\p{S}]`],["space",f`\p{space}`],["upper",f`\p{Upper}`],["word",f`[\p{Alpha}\p{M}\p{Nd}\p{Pc}]`],["xdigit",f`\p{AHex}`]]),Ie=new Set(["alnum","blank","graph","print","word","xdigit"]);function It(e,t){let r=[];for(let s=e;s<=t;s++)r.push(s);return r}function V(e){return e.replace(/[- _]+/g,"").toLowerCase()}function P(e){let t=A(e);return[t.toLowerCase(),t]}function ne(e,t){return It(e,t).map(r=>P(r))}var ue=new Set(["Lower","Lowercase","Upper","Uppercase","Ll","Lowercase_Letter","Lt","Titlecase_Letter","Lu","Uppercase_Letter"]);var g={Alternator:"Alternator",Assertion:"Assertion",Backreference:"Backreference",Character:"Character",CharacterClassClose:"CharacterClassClose",CharacterClassHyphen:"CharacterClassHyphen",CharacterClassIntersector:"CharacterClassIntersector",CharacterClassOpen:"CharacterClassOpen",CharacterSet:"CharacterSet",Directive:"Directive",GroupClose:"GroupClose",GroupOpen:"GroupOpen",Subroutine:"Subroutine",Quantifier:"Quantifier",VariableLengthCharacterSet:"VariableLengthCharacterSet",EscapedNumber:"EscapedNumber"},S={any:"any",digit:"digit",hex:"hex",posix:"posix",property:"property",space:"space",word:"word"},j={keep:"keep",flags:"flags"},_={atomic:"atomic",capturing:"capturing",group:"group",lookahead:"lookahead",lookbehind:"lookbehind"},xe=new Map([["a",7],["b",8],["e",27],["f",12],["n",10],["r",13],["t",9],["v",11]]),Pe="c.? | C(?:-.?)?",ve=f`[pP]\{(?:\^?[\x20\w]+\})?`,Te=f`u\{[^\}]*\}? | u\p{AHex}{0,4} | x\p{AHex}{0,2}`,De=f`\d{1,3}`,Re=f`\[\^?\]?`,Ue=/[?*+][?+]?|\{\d+(?:,\d*)?\}\??/,Q=new RegExp(f` \\ (?: - ${Fe} - | ${xe} - | ${Le} - | ${Pe} + ${Pe} + | ${ve} + | ${Te} + | ${De} | [gk]<[^>]*> | [gk]'[^']*' | . @@ -16,24 +16,24 @@ var OnigurumaToES=(()=>{var ee=Object.defineProperty;var dt=Object.getOwnPropert | # (?:[^)\\] | \\.?)* | [imx\-]+[:)] )?)? - | ${ve.source} - | ${Te} + | ${Ue.source} + | ${Re} | . -`.replace(/\s+/g,""),"gsu"),ue=new RegExp(f` +`.replace(/\s+/g,""),"gsu"),ce=new RegExp(f` \\ (?: - ${Fe} - | ${xe} - | ${Le} - | ${Pe} + ${Pe} + | ${ve} + | ${Te} + | ${De} | . ) | \[:[^:]*:\] - | ${Te} + | ${Re} | && | . -`.replace(/\s+/g,""),"gsu");function R(e,t=""){if(!/^[imx]*$/.test(t))throw new Error(`Flags "${t}" unsupported in Oniguruma`);let r=[t.includes("x")],s={getCurrentModX:()=>r.at(-1),popModX(){r.pop()},pushModX(c){r.push(c)},replaceCurrentModX(c){r[r.length-1]=c}},n=[],a;for(W.lastIndex=0;a=W.exec(e);){let c=Nt(s,e,a[0],W.lastIndex);c.tokens?n.push(...c.tokens):c.token&&n.push(c.token),c.lastIndex!==void 0&&(W.lastIndex=c.lastIndex)}let o=[],i=0;n.forEach(c=>{c.type===g.GroupOpen&&(c.kind===_.capturing?(i++,c.number=i):c.raw==="("&&o.push(c))}),i||o.forEach((c,p)=>{c.kind=_.capturing,c.number=p+1});let u=i||o.length;return n=n.map(c=>c.type===g.EscapedNumber?Dt(c,u):c).flat(),{tokens:n,flags:{ignoreCase:t.includes("i"),dotAll:t.includes("m"),extended:t.includes("x")}}}function Nt(e,t,r,s){let[n,a,o]=r;if(n==="["){let i=It(t,r,s);return{tokens:i.tokens,lastIndex:i.lastIndex}}if(n==="\\")return"AbBGzZ".includes(a)?{token:m(g.Assertion,r,{kind:r})}:/^\\g[<']/.test(r)?{token:m(g.Subroutine,r)}:/^\\k[<']/.test(r)?{token:m(g.Backreference,r)}:a==="K"?{token:m(g.Directive,r,{kind:V.keep})}:"RX".includes(a)?{token:m(g.VariableLengthCharacterSet,r,{kind:r})}:{token:De(r,{inCharClass:!1})};if(n==="("){if(o==="#"){if(t[s]!==")")throw new Error('Unclosed comment group "(?#"');return{lastIndex:s+1}}if("-imx".includes(o))return{token:xt(r,e)};if(e.pushModX(e.getCurrentModX()),r==="("||r==="(?:")return{token:m(g.GroupOpen,r,{kind:_.group})};if(r==="(?>")return{token:m(g.GroupOpen,r,{kind:_.atomic})};if(r==="(?="||r==="(?!"||r==="(?<="||r==="(?\^?)(?[a-z]+):\]/.exec(e);if(!t||!K.get(t.groups.name))throw new Error(`Invalid POSIX class "${e}"`);return m(g.CharacterSet,e,{kind:S.posix,negate:!!t.groups.negate,value:t.groups.name})}return e==="-"?m(g.CharacterClassHyphen,e):e==="&&"?m(g.CharacterClassIntersector,e):(Re(e),m(g.Character,e,{value:e.codePointAt(0)}))}function De(e,{inCharClass:t}){let r=e[1];if(r==="c"||r==="C")return Ft(e);if("dDhHsSwW".includes(r))return Pt(e);if(/^\\[pP]\{/.test(e)){if(e.length===3)throw new Error("Incomplete or invalid Unicode property");return Tt(e)}if(r==="u"||r==="x")return m(g.Character,e,{value:vt(e)});if(Ne.has(r))return m(g.Character,e,{value:Ne.get(r)});if(/\d/.test(r))return m(g.EscapedNumber,e,{inCharClass:t});if(e==="\\")throw new Error(f`Incomplete escape "\"`);if(r==="M")throw new Error(`Unsupported meta escape "${e}"`);if(e.length===2)return m(g.Character,e,{value:e.codePointAt(1)});throw new Error(`Unexpected escape "${e}"`)}function m(e,t,r){return{type:e,raw:t,...r}}function Ft(e){let t=e[1]==="c"?e[2]:e[3];if(!t||!/[a-zA-Z]/.test(t))throw new Error(`Unsupported control character "${e}"`);return m(g.Character,e,{value:t.toUpperCase().codePointAt(0)-64})}function xt(e,t){let{on:r,off:s}=/^\(\?(?[imx]*)(?:-(?[imx\-]*))?/.exec(e).groups;s??="";let n=(t.getCurrentModX()||r.includes("x"))&&!s.includes("x"),a=Ie(r),o=Ie(s),i={};if(a&&(i.enable=a),o&&(i.disable=o),e.endsWith(")"))return t.replaceCurrentModX(n),m(g.Directive,e,{kind:V.flags,flags:i});if(e.endsWith(":")){t.pushModX(n);let u=m(g.GroupOpen,e,{kind:_.group});return(a||o)&&(u.flags=i),u}throw new Error(`Unexpected flag modifier "${e}"`)}function Lt(e){let t={};if(e[0]==="{"){let{min:r,max:s}=/^\{(?\d+)(?:,(?\d*))?/.exec(e).groups,n=1e5;if(+r>n||+s>n)throw new Error("Quantifier value unsupported in Oniguruma");t.min=+r,t.max=s===void 0?+r:s===""?1/0:+s,t.greedy=!e.endsWith("?"),t.possessive=!1}else t.min=e[0]==="+"?1:0,t.max=e[0]==="?"?1:1/0,t.greedy=e[1]!=="?",t.possessive=e[1]==="+";return m(g.Quantifier,e,t)}function Pt(e){let t=e[1].toLowerCase();return m(g.CharacterSet,e,{kind:{d:S.digit,h:S.hex,s:S.space,w:S.word}[t],negate:e[1]!==t})}function Tt(e){let{p:t,neg:r,value:s}=/^\\(?

[pP])\{(?\^?)(?[ \w]+)/.exec(e).groups,n=t==="P"&&!r||t==="p"&&!!r;return m(g.CharacterSet,e,{kind:S.property,negate:n,value:s})}function vt(e){if(/^(?:\\x$|\\u(?!\p{AHex}{4}|\{\s*\p{AHex}{1,6}\s*\}))/u.test(e))throw new Error(`Incomplete or invalid escape "${e}"`);let t=e[2]==="{"?/^\\u\{\s*(?\p{AHex}+)/u.exec(e).groups.hex:e.slice(2),r=parseInt(t,16);if(r>1114111)throw new Error(`Invalid escape out of range "${e}"`);return r}function Ie(e){let t={};return e.includes("i")&&(t.ignoreCase=!0),e.includes("m")&&(t.dotAll=!0),e.includes("x")&&(t.extended=!0),Object.keys(t).length?t:null}function Dt(e,t){let{raw:r,inCharClass:s}=e,n=r.slice(1);if(!s&&(n!=="0"&&n.length===1||n[0]!=="0"&&+n<=t))return[m(g.Backreference,r)];let a=[],o=n.match(/^[0-7]+|\d/g);for(let i=0;i!!r[b]),w=C&&r[C],L=typeof w=="function"?w:w?.enter,k=w?.exit;if(L?.(d,t),!h)switch(o.type){case l.Regex:a(o.pattern,o,"pattern"),a(o.flags,o,"flags");break;case l.Alternative:case l.CharacterClass:n(o.elements,o);break;case l.Assertion:(o.kind===E.lookahead||o.kind===E.lookbehind)&&n(o.alternatives,o);break;case l.Backreference:case l.Character:case l.CharacterSet:case l.Directive:case l.Flags:case l.Recursion:case l.Subroutine:case l.VariableLengthCharacterSet:break;case l.CapturingGroup:case l.Group:case l.Pattern:n(o.alternatives,o);break;case l.CharacterClassIntersection:n(o.classes,o);break;case l.CharacterClassRange:a(o.min,o,"min"),a(o.max,o,"max");break;case l.Quantifier:a(o.element,o,"element");break;default:throw new Error(`Unexpected node type "${o.type}"`)}return k?.(d,t),p}a(e.node,e.parent,e.key,e.container)}function Rt(e,t){"parent"in t&&(e.parent=t)}var l={Alternative:"Alternative",Assertion:"Assertion",Backreference:"Backreference",CapturingGroup:"CapturingGroup",Character:"Character",CharacterClass:"CharacterClass",CharacterClassIntersection:"CharacterClassIntersection",CharacterClassRange:"CharacterClassRange",CharacterSet:"CharacterSet",Directive:"Directive",Flags:"Flags",Group:"Group",Pattern:"Pattern",Quantifier:"Quantifier",Regex:"Regex",Subroutine:"Subroutine",VariableLengthCharacterSet:"VariableLengthCharacterSet",Recursion:"Recursion"},Oe={AnyGroup:"AnyGroup",AnyNode:"AnyNode"};function Ue({type:e,kind:t}){let r=[Oe.AnyNode];return(e===l.Assertion&&(t===E.lookahead||t===E.lookbehind)||e===l.CapturingGroup||e===l.Group)&&r.push(Oe.AnyGroup),r.push(e),r}var E={line_end:"line_end",line_start:"line_start",lookahead:"lookahead",lookbehind:"lookbehind",search_start:"search_start",string_end:"string_end",string_end_newline:"string_end_newline",string_start:"string_start",word_boundary:"word_boundary"},$=S,D=V,j={newline:"newline",grapheme:"grapheme"};function U({tokens:e,flags:t},r){let s={bypassPropertyNameCheck:!1,optimize:!0,...r},n={bypassPropertyNameCheck:s.bypassPropertyNameCheck,capturingGroups:[],current:0,hasNumberedRef:!1,namedGroupsByName:new Map,optimize:s.optimize,parent:null,subroutines:[],token:null,tokens:e,walk:a};function a(d,C){let w=e[n.current];switch(n.parent=d,n.token=w,n.current++,w.type){case g.Alternator:return T();case g.Assertion:return Be(w);case g.Backreference:return Ut(n);case g.Character:return Ve(w.value);case g.CharacterClassHyphen:return Ot(n,C);case g.CharacterClassOpen:return Gt(n,C);case g.CharacterSet:return Mt(n);case g.Directive:return Qt(w);case g.GroupOpen:return Bt(n,C);case g.Quantifier:return Vt(n);case g.Subroutine:return jt(n);case g.VariableLengthCharacterSet:return er(w.kind);default:throw new Error(`Unexpected token type "${w.type}"`)}}let o=Zt(Xt(),qt(t)),i=o.pattern.alternatives[0];for(;n.currentu.length)throw new Error("Subroutine uses a group number that's not defined")}else if(p.has(d)){if(p.get(d).length>1)throw new Error(f`Subroutine uses a duplicate group name "\g<${d}>"`)}else throw new Error(f`Subroutine uses a group name that's not defined "\g<${d}>"`);return y({node:o},null,{AnyNode({node:d,parent:C}){d.parent=C}}),o}function Ut(e){let{raw:t}=e.token,r=/^\\k[<']/.test(t),s=r?t.slice(3,-1):t.slice(1),n=(a,o=!1)=>{let i=e.capturingGroups.length;if(a>i)throw new Error(`Not enough capturing groups defined to the left "${t}"`);return e.hasNumberedRef=!0,Q(o?i+1-a:a)};if(r){let a=/^(?-?)0*(?[1-9]\d*)$/.exec(s);if(a)return n(+a.groups.num,!!a.groups.sign);if(/[-+]/.test(s))throw new Error(`Invalid backref name "${t}"`);if(!e.namedGroupsByName.has(s))throw new Error(`Group name not defined to the left "${t}"`);return Q(s)}return n(+s)}function Ot(e,t){let{parent:r,tokens:s,walk:n}=e,a=r.elements.at(-1),o=s[e.current];if(a&&a.type!==l.CharacterClass&&o&&o.type!==g.CharacterClassOpen&&o.type!==g.CharacterClassClose&&o.type!==g.CharacterClassIntersector){let i=n(r,t);if(a.type===l.Character&&i.type===l.Character)return r.elements.pop(),Wt(a,i);throw new Error("Invalid character class range")}return Ve(45)}function Gt(e,t){let{token:r,tokens:s,optimize:n,walk:a}=e,o=ce({negate:r.negate}),i=o.elements[0],u=Ge(s[e.current]);for(;u.type!==g.CharacterClassClose;){if(u.type===g.CharacterClassIntersector)i.classes.push(ce({negate:!1,baseOnly:!0})),e.current++;else{let c=i.classes.at(-1);c.elements.push(a(c,t))}u=Ge(s[e.current])}if(n&&sr(i),i.classes.length===1){let c=i.classes[0];c.negate=o.negate!==c.negate,o=c}return e.current++,o}function Mt({token:e,bypassPropertyNameCheck:t}){let{kind:r,negate:s,value:n}=e;if(r===S.property){let o=B(n);if($e.has(o))r=S.posix,n=o;else return pe(n,{negate:s,allowAnyName:t})}let a={type:l.CharacterSet,kind:I($[r],`Unexpected character set kind "${r}"`)};return(r===S.digit||r===S.hex||r===S.posix||r===S.space||r===S.word)&&(a.negate=s,r===S.posix&&(a.value=n)),a}function Bt(e,t){let{token:r,tokens:s,optimize:n,capturingGroups:a,namedGroupsByName:o,walk:i}=e,u=Ht(r);u.type===l.CapturingGroup&&(a.push(u),u.name&&v(o,u.name,[]).push(u));let c=Me(s[e.current]);for(;c.type!==g.GroupClose;){if(c.type===g.Alternator)u.alternatives.push(T()),e.current++;else{let p=u.alternatives.at(-1);t.isInLookbehind||=u.kind===E.lookbehind;let h=i(p,t);if(p.elements.push(h),t.isInLookbehind&&h.type===l.Quantifier&&h.min!==h.max)throw new Error("Variable repetition within lookbehind unsupported in Oniguruma")}c=Me(s[e.current])}return n&&(u=rr(u)),e.current++,u}function Vt({token:e,parent:t}){let{min:r,max:s,greedy:n,possessive:a}=e,o=t.elements.at(-1);if(!o||o.type===l.Directive)throw new Error("Quantifier requires a repeatable token");let i=Jt(o,r,s,n,a);return t.elements.pop(),i}function jt(e){let{token:t,capturingGroups:r,subroutines:s}=e,n=t.raw.slice(3,-1),a=/^(?[-+]?)0*(?[1-9]\d*)$/.exec(n);if(a){let i=+a.groups.num,u=r.length;if(e.hasNumberedRef=!0,n={"":i,"+":u+i,"-":u+1-i}[a.groups.sign],n<1)throw new Error("Invalid subroutine number")}else n==="0"&&(n=0);let o=Yt(n);return s.push(o),o}function T(){return{type:l.Alternative,elements:[]}}function Be({type:e,kind:t,negate:r}){if(e===g.GroupOpen)return le({behind:t===_.lookbehind,negate:r});let s=I({"^":E.line_start,$:E.line_end,"\\A":E.string_start,"\\b":E.word_boundary,"\\B":E.word_boundary,"\\G":E.search_start,"\\z":E.string_end,"\\Z":E.string_end_newline}[t],`Unexpected assertion kind "${t}"`),n={type:l.Assertion,kind:s};return s===E.word_boundary&&(n.negate=t===f`\B`),n}function Q(e){return{type:l.Backreference,ref:e}}function Ht(e){let{kind:t,number:r,name:s,flags:n}=e;switch(t){case _.atomic:return F({atomic:!0});case _.capturing:return zt(r,s);case _.group:return F({flags:n});case _.lookahead:case _.lookbehind:return Be(e);default:throw new Error(`Unexpected group kind "${t}"`)}}function zt(e,t){let r=t!==void 0;if(r&&!nr(t))throw new Error(`Group name "${t}" invalid in Oniguruma`);return{type:l.CapturingGroup,number:e,...r&&{name:t},alternatives:[T()]}}function Ve(e){return{type:l.Character,value:e}}function ce(e){let t={baseOnly:!1,negate:!1,...e};return{type:l.CharacterClass,negate:t.negate,elements:t.baseOnly?[]:[Kt()]}}function Kt(){return{type:l.CharacterClassIntersection,classes:[ce({negate:!1,baseOnly:!0})]}}function Wt(e,t){if(t.values[0].toUpperCase()+s.slice(1).toLowerCase())}function rr(e){let t=e.alternatives[0],r=t.elements[0];return e.type===l.Group&&e.alternatives.length===1&&t.elements.length===1&&r.type===l.Group&&!(e.atomic&&r.flags)&&!(e.flags&&(r.atomic||r.flags))?(e.atomic?r.atomic=!0:e.flags&&(r.flags=e.flags),r):e}function nr(e){return!/^(?:[-\d]|$)/.test(e)}function sr(e){for(let t=0;ta.kind===D.flags);for(let a=r+1;a1)throw new Error(f`Uses "\K" in a way that's unsupported for conversion to JS`);o(H(le({behind:!0}),i()))}},Flags({node:e,parent:t}){delete e.extended,Object.assign(e,{global:!1,hasIndices:!1,multiline:!1,sticky:e.sticky??!1}),t.options={disable:{x:!0,n:!0},force:{v:!0}}},Group({node:e}){if(!e.flags)return;let{enable:t,disable:r}=e.flags;t?.dotAll&&r?.dotAll&&delete t.dotAll,t?.ignoreCase&&r?.ignoreCase&&delete t.ignoreCase,t&&!Object.keys(t).length&&delete e.flags.enable},Pattern({node:e}){let t=!1,r=!1;for(let s of e.alternatives)s.elements.sort((n,a)=>n.kind===E.search_start&&a.kind===D.flags?-1:n.kind===D.flags&&a.kind===E.search_start?1:0),s.elements[0]?.kind===E.search_start?t=!0:r=!0;if(t&&r)throw new Error(f`Uses "\G" in a way that's unsupported for conversion to JS`)},Quantifier({node:e}){if(e.element.type===l.Quantifier){let t=H(F(),[e.element]);t.parent=e,e.element=t}},VariableLengthCharacterSet({node:e,replaceWith:t},{allowBestEffort:r,minTargetEs2024:s}){let{kind:n}=e;if(n===j.newline)t(x(f`(?>\r\n?|[\n\v\f\x85\u2028\u2029])`));else if(n===j.grapheme){if(!r)throw new Error(f`Use of "\X" requires option allowBestEffort`);let a=s?f`\p{RGI_Emoji}`:be().source;t(x(f`(?>\r\n|${a}|\P{M}\p{M}*)`,{bypassPropertyNameCheck:!0}))}else throw new Error(`Unexpected varcharset kind "${n}"`)}},ze={Alternative({node:e},{namedGroupsInScopeByAlt:t}){let r=q(e);if(r){let s=t.get(r);s&&t.set(e,s)}},Backreference({node:e},{multiplexCapturesToLeftByRef:t,reffedNodesByBackreference:r}){let{ref:s}=e;r.set(e,[...t.get(s).map(({node:n})=>n)])},CapturingGroup:{enter({node:e,replaceWith:t,skip:r},{groupOriginByCopy:s,groupsWithDuplicateNamesToRemove:n,multiplexCapturesToLeftByRef:a,namedGroupsInScopeByAlt:o,openDirectCaptures:i,openSubroutineRefs:u}){let{name:c,number:p}=e,h=c??p,d=s.get(e),C=u.has(h)||i.has(d),w=C&&!u.size;if(C&&!w)throw new Error("Unsupported indirect recursion");if(d?u.add(h):i.add(e),w){t(je(h)),r();return}let L=v(a,h,[]);for(let k=0;kw.type===l.Group&&!!w.flags));C&&(d=H(F({flags:C}),[h]))}n(d),p||y({node:d,parent:t,key:r,container:s},a,ze)}},ar={CapturingGroup({node:e},t){e.number=++t.numCapturesToLeft,t.groupsWithDuplicateNamesToRemove.has(e)&&delete e.name},Backreference({node:e,replaceWith:t},{reffedNodesByBackreference:r}){let s=r.get(e);if(s.length>1){let n=s.map(a=>X(T(),[Q(a.number)]));t(X(F(),n))}else e.ref=s[0].number}};function X(e,t){return t.forEach(r=>r.parent=e),e[We(e)]=t,e}function Ke(e,t,r,s){let n=Array.isArray(e)?[]:{};for(let[a,o]of Object.entries(e))a==="parent"?n.parent=Array.isArray(r)?s:r:o&&typeof o=="object"?n[a]=Ke(o,t,n,r):(a==="type"&&o===l.CapturingGroup&&t.set(n,e),n[a]=o);return n}function je(e){if(typeof e=="number"&&e!==0)throw new Error("Unsupported recursion by number; use name instead");return{type:l.Recursion,ref:e}}function or(e,t){let r=[];for(;e=e.parent;)(!t||t(e))&&r.push(e);return r}function We(e){if(e.alternatives)return"alternatives";if(e.elements)return"elements";if(e.classes)return"classes";throw new Error("Accessor for child container unknown")}function Qe(e){let t=["dotAll","ignoreCase"],r={enable:{},disable:{}};return e.forEach(({flags:s})=>{t.forEach(n=>{s.enable?.[n]&&(delete r.disable[n],r.enable[n]=!0),s.disable?.[n]&&(r.disable[n]=!0)})}),Object.keys(r.enable).length||delete r.enable,Object.keys(r.disable).length||delete r.disable,r.enable||r.disable?r:null}function q(e){for(;e=e.parent;)if(e.type===l.Alternative)return e;return null}function ir(e){return/^[$_\p{IDS}][$\u200C\u200D\p{IDC}]*$/u.test(e)}function x(e,{bypassPropertyNameCheck:t}={}){let s=U(R(e),{bypassPropertyNameCheck:t}).pattern.alternatives;return s.length>1||s[0].elements.length>1?X(F(),s):s[0].elements[0]}function H(e,t){let r=We(e);return e[r][0].parent=e,t&&X(e[r][0],t),e}function Xe(e,t){let r=ge(t),s=M(r.target,"ES2024"),n=M(r.target,"ESNext"),a=r.maxRecursionDepth;if(a!==null&&(!Number.isInteger(a)||a<2||a>100))throw new Error("Invalid maxRecursionDepth; use null or 2-100");let o=null,i=null;if(!n){let C=[e.flags.ignoreCase];y({node:e},{getCurrentModI:()=>C.at(-1),popModI(){C.pop()},pushModI(w){C.push(w)},setHasCasedChar(){C.at(-1)?o=!0:i=!0}},ur)}let u={dotAll:e.flags.dotAll,ignoreCase:!!((e.flags.ignoreCase||o)&&!i)},c=null,p={allowBestEffort:r.allowBestEffort,appliedGlobalFlags:u,captureFlagIMap:new Map,currentFlags:{dotAll:e.flags.dotAll,ignoreCase:e.flags.ignoreCase},groupNames:new Set,inCharClass:!1,lastNode:c,maxRecursionDepth:a,optimize:r.optimize,useAppliedIgnoreCase:!!(!n&&o&&i),useDuplicateNames:n,useFlagMods:n,useFlagV:s,usePostEs2018Properties:s};function h(C){switch(p.lastNode=c,c=C,C.type){case l.Regex:return{pattern:h(C.pattern),flags:h(C.flags),options:{...C.options}};case l.Alternative:return C.elements.map(h).join("");case l.Assertion:return gr(C,p,h);case l.Backreference:return hr(C,p);case l.CapturingGroup:return dr(C,p,h);case l.Character:return Cr(C,p);case l.CharacterClass:return mr(C,p,h);case l.CharacterClassIntersection:if(!p.useFlagV)throw new Error("Use of class intersection requires target ES2024 or later");return C.classes.map(h).join("&&");case l.CharacterClassRange:return Er(C,p);case l.CharacterSet:return wr(C,p);case l.Flags:return Ar(C,p);case l.Group:return Sr(C,p,h);case l.Pattern:return C.alternatives.map(h).join("|");case l.Quantifier:return h(C.element)+$r(C);case l.Recursion:return kr(C,p);default:throw new Error(`Unexpected node type "${C.type}"`)}}let d=h(e);return s||(delete d.options.force.v,d.options.disable.v=!0,d.options.unicodeSetsPlugin=null),d}var ur={AnyGroup:{enter({node:e},t){let r=t.getCurrentModI();t.pushModI(e.flags?Ze({ignoreCase:r},e.flags).ignoreCase:r)},exit(e,t){t.popModI()}},Backreference(e,t){t.setHasCasedChar()},Character({node:e},t){fe(A(e.value))&&t.setHasCasedChar()},CharacterClassRange({node:e,skip:t},r){t(),Je(e,{firstOnly:!0}).length&&r.setHasCasedChar()},CharacterSet({node:e},t){e.kind===$.property&&ie.has(e.value)&&t.setHasCasedChar()}},cr=new Set(["$","(",")","*","+",".","?","[","\\","]","^","{","|","}"]),lr=new Set(["-","\\","]","^"]),pr=new Set(["(",")","-","/","[","\\","]","^","{","|","}","!","#","$","%","&","*","+",",",".",":",";","<","=",">","?","@","`","~"]),qe=new Map([[9,f`\t`],[10,f`\n`],[11,f`\v`],[12,f`\f`],[13,f`\r`]]),fr=/^\p{Cased}$/u;function fe(e){return fr.test(e)}function gr({kind:e,negate:t,alternatives:r},s,n){if(e===E.lookahead||e===E.lookbehind)return`(?${`${e===E.lookahead?"":"<"}${t?"!":"="}`}${r.map(n).join("|")})`;if(e===E.string_end)return"$";if(e===E.string_start)return"^";throw new Error(`Unexpected assertion kind "${e}"`)}function hr({ref:e},t){if(typeof e!="number")throw new Error("Unexpected named backref in transformed AST");if(!t.useFlagMods&&!t.allowBestEffort&&t.currentFlags.ignoreCase&&!t.captureFlagIMap.get(e))throw new Error("Use of case-insensitive backref to case-sensitive group requires option allowBestEffort or target ESNext");return"\\"+e}function dr({name:e,number:t,alternatives:r},s,n){return e&&(s.groupNames.has(e)?s.useDuplicateNames||(e=null):s.groupNames.add(e)),s.captureFlagIMap.set(t,s.currentFlags.ignoreCase),`(${e?`?<${e}>`:""}${r.map(n).join("|")})`}function Cr({value:e},t){let r=A(e),s=O(e,{isAfterBackref:t.lastNode.type===l.Backreference,inCharClass:t.inCharClass,useFlagV:t.useFlagV});if(s!==r)return s;if(t.useAppliedIgnoreCase&&t.currentFlags.ignoreCase&&fe(r)){let n=ne(r);return t.inCharClass?n.join(""):n.length>1?`[${n.join("")}]`:n[0]}return r}function mr({negate:e,parent:t,elements:r},s,n){if(!e&&(!s.useFlagV||s.optimize)&&t.type===l.CharacterClass&&r[0].type!==l.CharacterClassIntersection||s.optimize&&t.type===l.CharacterClassIntersection&&r.length===1&&r[0].type!==l.CharacterClassRange)return r.map(n).join("");if(!s.useFlagV&&t.type===l.CharacterClass)throw new Error("Use of nested character class requires target ES2024 or later");s.inCharClass=!0;let a=`[${e?"^":""}${r.map(n).join("")}]`;return s.inCharClass=!1,a}function Er(e,t){let r=e.min.value,s=e.max.value,n={isAfterBackref:!1,inCharClass:!0,useFlagV:t.useFlagV},a=O(r,n),o=O(s,n),i="";if(t.useAppliedIgnoreCase&&t.currentFlags.ignoreCase){let u=Je(e);br(u).forEach(p=>{i+=Array.isArray(p)?`${O(p[0],n)}-${O(p[1],n)}`:O(p,n)})}return`${a}-${o}${i}`}function wr({kind:e,negate:t,value:r,key:s},n){if(e===$.any)return n.currentFlags.dotAll?n.appliedGlobalFlags.dotAll||n.useFlagMods?".":"[^]":f`[^\n]`;if(e===$.digit)return t?f`\D`:f`\d`;if(e===$.property){if(!n.usePostEs2018Properties&&_e.has(r))throw new Error(`Unicode property "${r}" unavailable in target ES2018`);if(n.useAppliedIgnoreCase&&n.currentFlags.ignoreCase&&ie.has(r))throw new Error(`Unicode property "${r}" can't be case-insensitive when other chars have specific case`);return`${t?f`\P`:f`\p`}{${s?`${s}=`:""}${r}}`}if(e===$.word)return t?f`\W`:f`\w`;throw new Error(`Unexpected character set kind "${e}"`)}function Ar(e,t){return(t.appliedGlobalFlags.ignoreCase?"i":"")+(e.dotAll?"s":"")+(e.sticky?"y":"")}function Sr({atomic:e,flags:t,parent:r,alternatives:s},n,a){let o=n.currentFlags;t&&(n.currentFlags=Ze(o,t));let i=s.map(a).join("|"),u=n.optimize&&s.length===1&&r.type!==l.Quantifier&&!e&&(!n.useFlagMods||!t)?i:`(?${_r(e,t,n.useFlagMods)}${i})`;return n.currentFlags=o,u}function kr({ref:e},t){let r=t.maxRecursionDepth;if(!r)throw new Error("Use of recursion disabled");if(!t.allowBestEffort)throw new Error("Use of recursion requires option allowBestEffort");return e===0?`(?R=${r})`:f`\g<${e}&R=${r}>`}function Je(e,{firstOnly:t}={}){let r=e.min.value,s=e.max.value,n=[];if(r<65&&(s===65535||s>=131071)||r===65536&&s>=131071)return n;for(let a=r;a<=s;a++){let o=A(a);if(!fe(o))continue;let i=ne(o).filter(u=>{let c=u.codePointAt(0);return cs});if(i.length&&(n.push(...i),t))break}return n}function br(e){let t=e.map(n=>n.codePointAt(0)).sort((n,a)=>n-a),r=[],s=null;for(let n=0;n126&&e<160||t&&Nr(e))return f`\x${e.toString(16).padStart(2,"0")}`;let n=r?s?pr:lr:cr,a=A(e);return(n.has(a)?"\\":"")+a}function _r(e,t,r){if(e)return">";let s="";if(t&&r){let{enable:n,disable:a}=t;s=(n?.ignoreCase?"i":"")+(n?.dotAll?"s":"")+(a?"-":"")+(a?.ignoreCase?"i":"")+(a?.dotAll?"s":"")}return`${s}:`}function Ze(e,{enable:t,disable:r}){return{dotAll:!r?.dotAll&&!!(t?.dotAll||e.dotAll),ignoreCase:!r?.ignoreCase&&!!(t?.ignoreCase||e.ignoreCase)}}function $r({min:e,max:t,greedy:r,possessive:s}){let n;return!e&&t===1?n="?":!e&&t===1/0?n="*":e===1&&t===1/0?n="+":e===t?n=`{${e}}`:n=`{${e},${t===1/0?"":t}}`,n+(s?"+":r?"":"?")}function Nr(e){return e>47&&e<58}var Z=Object.freeze({DEFAULT:"DEFAULT",CHAR_CLASS:"CHAR_CLASS"});function Ir(e,t,r,s){let n=new RegExp(String.raw`${t}|(?<$skip>\[\^?|\\?.)`,"gsu"),a=[!1],o=0,i="";for(let u of e.matchAll(n)){let{0:c,groups:{$skip:p}}=u;if(!p&&(!s||s===Z.DEFAULT==!o)){r instanceof Function?i+=r(u,{context:o?Z.CHAR_CLASS:Z.DEFAULT,negated:a[a.length-1]}):i+=r;continue}c[0]==="["?(o++,a.push(c[1]==="^")):c==="]"&&o&&(o--,a.pop()),i+=c}return i}var Ye={DEFAULT:"DEFAULT",CHAR_CLASS:"CHAR_CLASS",ENCLOSED_P:"ENCLOSED_P",ENCLOSED_U:"ENCLOSED_U",GROUP_NAME:"GROUP_NAME",INTERVAL_QUANTIFIER:"INTERVAL_QUANTIFIER",INVALID_INCOMPLETE_TOKEN:"INVALID_INCOMPLETE_TOKEN"},he={DEFAULT:"DEFAULT",ENCLOSED_P:"ENCLOSED_P",ENCLOSED_Q:"ENCLOSED_Q",ENCLOSED_U:"ENCLOSED_U",INVALID_INCOMPLETE_TOKEN:"INVALID_INCOMPLETE_TOKEN",RANGE:"RANGE"},dn=new Set([Ye.ENCLOSED_P,Ye.ENCLOSED_U]),Cn=new Set([he.ENCLOSED_P,he.ENCLOSED_Q,he.ENCLOSED_U]),mn=(()=>{try{new RegExp("(?i:)")}catch{return!1}return!0})(),En=(()=>{try{new RegExp("","v")}catch{return!1}return!0})(),tt="&!#$%*+,.:;<=>?@^`~",yr="$E$",rt=String.raw`\(\?<(?![=!])(?[^>]+)>`,Fr=String.raw`\((?!\?)(?!(?<=\(\?\()DEFINE\))|${rt}`,Ce=String.raw`\(\?(?:[:=!>A-Za-z\-]|<[=!]|\(DEFINE\))`;var wn=new RegExp(String.raw` +`.replace(/\s+/g,""),"gsu");function U(e,t=""){if(!/^[imx]*$/.test(t))throw new Error(`Flags "${t}" unsupported in Oniguruma`);let r=[t.includes("x")],s={getCurrentModX:()=>r.at(-1),popModX(){r.pop()},pushModX(u){r.push(u)},replaceCurrentModX(u){r[r.length-1]=u}},n=[],o;for(Q.lastIndex=0;o=Q.exec(e);){let u=xt(s,e,o[0],Q.lastIndex);u.tokens?n.push(...u.tokens):u.token&&n.push(u.token),u.lastIndex!==void 0&&(Q.lastIndex=u.lastIndex)}let a=[],i=0;n.forEach(u=>{u.type===g.GroupOpen&&(u.kind===_.capturing?(i++,u.number=i):u.raw==="("&&a.push(u))}),i||a.forEach((u,p)=>{u.kind=_.capturing,u.number=p+1});let c=i||a.length;return n=n.map(u=>u.type===g.EscapedNumber?Ot(u,c):u).flat(),{tokens:n,flags:{ignoreCase:t.includes("i"),dotAll:t.includes("m"),extended:t.includes("x")}}}function xt(e,t,r,s){let[n,o,a]=r;if(n==="["){let i=Ft(t,r,s);return{tokens:i.tokens,lastIndex:i.lastIndex}}if(n==="\\")return"AbBGzZ".includes(o)?{token:m(g.Assertion,r,{kind:r})}:/^\\g[<']/.test(r)?{token:m(g.Subroutine,r)}:/^\\k[<']/.test(r)?{token:m(g.Backreference,r)}:o==="K"?{token:m(g.Directive,r,{kind:j.keep})}:"RX".includes(o)?{token:m(g.VariableLengthCharacterSet,r,{kind:r})}:{token:Oe(r,{inCharClass:!1})};if(n==="("){if(a==="#"){if(t[s]!==")")throw new Error('Unclosed comment group "(?#"');return{lastIndex:s+1}}if("-imx".includes(a))return{token:vt(r,e)};if(e.pushModX(e.getCurrentModX()),r==="("||r==="(?:")return{token:m(g.GroupOpen,r,{kind:_.group})};if(r==="(?>")return{token:m(g.GroupOpen,r,{kind:_.atomic})};if(r==="(?="||r==="(?!"||r==="(?<="||r==="(?\^?)(?[a-z]+):\]/.exec(e);if(!t||!K.get(t.groups.name))throw new Error(`Invalid POSIX class "${e}"`);return m(g.CharacterSet,e,{kind:S.posix,negate:!!t.groups.negate,value:t.groups.name})}return e==="-"?m(g.CharacterClassHyphen,e):e==="&&"?m(g.CharacterClassIntersector,e):(Ge(e),m(g.Character,e,{value:e.codePointAt(0)}))}function Oe(e,{inCharClass:t}){let r=e[1];if(r==="c"||r==="C")return Pt(e);if("dDhHsSwW".includes(r))return Dt(e);if(/^\\[pP]\{/.test(e)){if(e.length===3)throw new Error("Incomplete or invalid Unicode property");return Rt(e)}if(r==="u"||r==="x")return m(g.Character,e,{value:Ut(e)});if(xe.has(r))return m(g.Character,e,{value:xe.get(r)});if(/\d/.test(r))return m(g.EscapedNumber,e,{inCharClass:t});if(e==="\\")throw new Error(f`Incomplete escape "\"`);if(r==="M")throw new Error(`Unsupported meta escape "${e}"`);if(e.length===2)return m(g.Character,e,{value:e.codePointAt(1)});throw new Error(`Unexpected escape "${e}"`)}function m(e,t,r){return{type:e,raw:t,...r}}function Pt(e){let t=e[1]==="c"?e[2]:e[3];if(!t||!/[a-zA-Z]/.test(t))throw new Error(`Unsupported control character "${e}"`);return m(g.Character,e,{value:t.toUpperCase().codePointAt(0)-64})}function vt(e,t){let{on:r,off:s}=/^\(\?(?[imx]*)(?:-(?[imx\-]*))?/.exec(e).groups;s??="";let n=(t.getCurrentModX()||r.includes("x"))&&!s.includes("x"),o=Fe(r),a=Fe(s),i={};if(o&&(i.enable=o),a&&(i.disable=a),e.endsWith(")"))return t.replaceCurrentModX(n),m(g.Directive,e,{kind:j.flags,flags:i});if(e.endsWith(":")){t.pushModX(n);let c=m(g.GroupOpen,e,{kind:_.group});return(o||a)&&(c.flags=i),c}throw new Error(`Unexpected flag modifier "${e}"`)}function Tt(e){let t={};if(e[0]==="{"){let{min:r,max:s}=/^\{(?\d+)(?:,(?\d*))?/.exec(e).groups,n=1e5;if(+r>n||+s>n)throw new Error("Quantifier value unsupported in Oniguruma");t.min=+r,t.max=s===void 0?+r:s===""?1/0:+s,t.greedy=!e.endsWith("?"),t.possessive=!1}else t.min=e[0]==="+"?1:0,t.max=e[0]==="?"?1:1/0,t.greedy=e[1]!=="?",t.possessive=e[1]==="+";return m(g.Quantifier,e,t)}function Dt(e){let t=e[1].toLowerCase();return m(g.CharacterSet,e,{kind:{d:S.digit,h:S.hex,s:S.space,w:S.word}[t],negate:e[1]!==t})}function Rt(e){let{p:t,neg:r,value:s}=/^\\(?

[pP])\{(?\^?)(?[ \w]+)/.exec(e).groups,n=t==="P"&&!r||t==="p"&&!!r;return m(g.CharacterSet,e,{kind:S.property,negate:n,value:s})}function Ut(e){if(/^(?:\\x$|\\u(?!\p{AHex}{4}|\{\s*\p{AHex}{1,6}\s*\}))/u.test(e))throw new Error(`Incomplete or invalid escape "${e}"`);let t=e[2]==="{"?/^\\u\{\s*(?\p{AHex}+)/u.exec(e).groups.hex:e.slice(2),r=parseInt(t,16);if(r>1114111)throw new Error(`Invalid escape out of range "${e}"`);return r}function Fe(e){let t={};return e.includes("i")&&(t.ignoreCase=!0),e.includes("m")&&(t.dotAll=!0),e.includes("x")&&(t.extended=!0),Object.keys(t).length?t:null}function Ot(e,t){let{raw:r,inCharClass:s}=e,n=r.slice(1);if(!s&&(n!=="0"&&n.length===1||n[0]!=="0"&&+n<=t))return[m(g.Backreference,r)];let o=[],a=n.match(/^[0-7]+|\d/g);for(let i=0;i!!r[b]),w=h&&r[h],L=typeof w=="function"?w:w?.enter,k=w?.exit;if(L?.(C,t),!d)switch(a.type){case l.Regex:o(a.pattern,a,"pattern"),o(a.flags,a,"flags");break;case l.Alternative:case l.CharacterClass:n(a.elements,a);break;case l.Assertion:D(a)&&n(a.alternatives,a);break;case l.Backreference:case l.Character:case l.CharacterSet:case l.Directive:case l.Flags:case l.Recursion:case l.Subroutine:case l.VariableLengthCharacterSet:break;case l.CapturingGroup:case l.Group:case l.Pattern:n(a.alternatives,a);break;case l.CharacterClassIntersection:n(a.classes,a);break;case l.CharacterClassRange:o(a.min,a,"min"),o(a.max,a,"max");break;case l.Quantifier:o(a.element,a,"element");break;default:throw new Error(`Unexpected node type "${a.type}"`)}return k?.(C,t),p}o(e.node,e.parent,e.key,e.container)}function Gt(e,t){"parent"in t&&(e.parent=t)}var l={Alternative:"Alternative",Assertion:"Assertion",Backreference:"Backreference",CapturingGroup:"CapturingGroup",Character:"Character",CharacterClass:"CharacterClass",CharacterClassIntersection:"CharacterClassIntersection",CharacterClassRange:"CharacterClassRange",CharacterSet:"CharacterSet",Directive:"Directive",Flags:"Flags",Group:"Group",Pattern:"Pattern",Quantifier:"Quantifier",Regex:"Regex",Subroutine:"Subroutine",VariableLengthCharacterSet:"VariableLengthCharacterSet",Recursion:"Recursion"},Be={AnyGroup:"AnyGroup",AnyNode:"AnyNode"};function Me(e){let{type:t}=e,r=[Be.AnyNode];return(D(e)||t===l.CapturingGroup||t===l.Group)&&r.push(Be.AnyGroup),r.push(t),r}var E={line_end:"line_end",line_start:"line_start",lookahead:"lookahead",lookbehind:"lookbehind",search_start:"search_start",string_end:"string_end",string_end_newline:"string_end_newline",string_start:"string_start",word_boundary:"word_boundary"},$=S,R=j,W={newline:"newline",grapheme:"grapheme"};function O({tokens:e,flags:t},r){let s={bypassPropertyNameCheck:!1,optimize:!0,...r},n={bypassPropertyNameCheck:s.bypassPropertyNameCheck,capturingGroups:[],current:0,hasNumberedRef:!1,namedGroupsByName:new Map,optimize:s.optimize,parent:null,subroutines:[],token:null,tokens:e,walk:o};function o(C,h){let w=e[n.current];switch(n.parent=C,n.token=w,n.current++,w.type){case g.Alternator:return v();case g.Assertion:return We(w);case g.Backreference:return Mt(n);case g.Character:return He(w.value);case g.CharacterClassHyphen:return Bt(n,h);case g.CharacterClassOpen:return Vt(n,h);case g.CharacterSet:return jt(n);case g.Directive:return Jt(w);case g.GroupOpen:return Wt(n,h);case g.Quantifier:return Ht(n);case g.Subroutine:return zt(n);case g.VariableLengthCharacterSet:return nr(w.kind);default:throw new Error(`Unexpected token type "${w.type}"`)}}let a=tr(Yt(),Zt(t)),i=a.pattern.alternatives[0];for(;n.currentc.length)throw new Error("Subroutine uses a group number that's not defined")}else if(p.has(C)){if(p.get(C).length>1)throw new Error(f`Subroutine uses a duplicate group name "\g<${C}>"`)}else throw new Error(f`Subroutine uses a group name that's not defined "\g<${C}>"`);return I({node:a},null,{AnyNode({node:C,parent:h}){C.parent=h}}),a}function Mt(e){let{raw:t}=e.token,r=/^\\k[<']/.test(t),s=r?t.slice(3,-1):t.slice(1),n=(o,a=!1)=>{let i=e.capturingGroups.length;if(o>i)throw new Error(`Not enough capturing groups defined to the left "${t}"`);return e.hasNumberedRef=!0,q(a?i+1-o:o)};if(r){let o=/^(?-?)0*(?[1-9]\d*)$/.exec(s);if(o)return n(+o.groups.num,!!o.groups.sign);if(/[-+]/.test(s))throw new Error(`Invalid backref name "${t}"`);if(!e.namedGroupsByName.has(s))throw new Error(`Group name not defined to the left "${t}"`);return q(s)}return n(+s)}function Bt(e,t){let{parent:r,tokens:s,walk:n}=e,o=r.elements.at(-1),a=s[e.current];if(o&&o.type!==l.CharacterClass&&a&&a.type!==g.CharacterClassOpen&&a.type!==g.CharacterClassClose&&a.type!==g.CharacterClassIntersector){let i=n(r,t);if(o.type===l.Character&&i.type===l.Character)return r.elements.pop(),Xt(o,i);throw new Error("Invalid character class range")}return He(45)}function Vt(e,t){let{token:r,tokens:s,optimize:n,walk:o}=e,a=le({negate:r.negate}),i=a.elements[0],c=Ve(s[e.current]);for(;c.type!==g.CharacterClassClose;){if(c.type===g.CharacterClassIntersector)i.classes.push(le({negate:!1,baseOnly:!0})),e.current++;else{let u=i.classes.at(-1);u.elements.push(o(u,t))}c=Ve(s[e.current])}if(n&&ir(i),i.classes.length===1){let u=i.classes[0];u.negate=a.negate!==u.negate,a=u}return e.current++,a}function jt({token:e,bypassPropertyNameCheck:t}){let{kind:r,negate:s,value:n}=e;if(r===S.property){let a=V(n);if(Ie.has(a))r=S.posix,n=a;else return fe(n,{negate:s,allowAnyName:t})}let o={type:l.CharacterSet,kind:y($[r],`Unexpected character set kind "${r}"`)};return(r===S.digit||r===S.hex||r===S.posix||r===S.space||r===S.word)&&(o.negate=s,r===S.posix&&(o.value=n)),o}function Wt(e,t){let{token:r,tokens:s,optimize:n,capturingGroups:o,namedGroupsByName:a,walk:i}=e,c=Kt(r);c.type===l.CapturingGroup&&(o.push(c),c.name&&T(a,c.name,[]).push(c));let u=je(s[e.current]);for(;u.type!==g.GroupClose;){if(u.type===g.Alternator)c.alternatives.push(v()),e.current++;else{let p=c.alternatives.at(-1);t.isInLookbehind||=c.kind===E.lookbehind;let d=i(p,t);if(p.elements.push(d),t.isInLookbehind&&d.type===l.Quantifier&&d.min!==d.max)throw new Error("Variable repetition within lookbehind unsupported in Oniguruma")}u=je(s[e.current])}return n&&(c=ar(c)),e.current++,c}function Ht({token:e,parent:t}){let{min:r,max:s,greedy:n,possessive:o}=e,a=t.elements.at(-1);if(!a||a.type===l.Directive)throw new Error("Quantifier requires a repeatable token");let i=er(a,r,s,n,o);return t.elements.pop(),i}function zt(e){let{token:t,capturingGroups:r,subroutines:s}=e,n=t.raw.slice(3,-1),o=/^(?[-+]?)0*(?[1-9]\d*)$/.exec(n);if(o){let i=+o.groups.num,c=r.length;if(e.hasNumberedRef=!0,n={"":i,"+":c+i,"-":c+1-i}[o.groups.sign],n<1)throw new Error("Invalid subroutine number")}else n==="0"&&(n=0);let a=rr(n);return s.push(a),a}function v(){return{type:l.Alternative,elements:[]}}function We({type:e,kind:t,negate:r}){if(e===g.GroupOpen)return pe({behind:t===_.lookbehind,negate:r});let s=y({"^":E.line_start,$:E.line_end,"\\A":E.string_start,"\\b":E.word_boundary,"\\B":E.word_boundary,"\\G":E.search_start,"\\z":E.string_end,"\\Z":E.string_end_newline}[t],`Unexpected assertion kind "${t}"`),n={type:l.Assertion,kind:s};return s===E.word_boundary&&(n.negate=t===f`\B`),n}function q(e){return{type:l.Backreference,ref:e}}function Kt(e){let{kind:t,number:r,name:s,flags:n}=e;switch(t){case _.atomic:return x({atomic:!0});case _.capturing:return Qt(r,s);case _.group:return x({flags:n});case _.lookahead:case _.lookbehind:return We(e);default:throw new Error(`Unexpected group kind "${t}"`)}}function Qt(e,t){let r=t!==void 0;if(r&&!or(t))throw new Error(`Group name "${t}" invalid in Oniguruma`);return{type:l.CapturingGroup,number:e,...r&&{name:t},alternatives:[v()]}}function He(e){return{type:l.Character,value:e}}function le(e){let t={baseOnly:!1,negate:!1,...e};return{type:l.CharacterClass,negate:t.negate,elements:t.baseOnly?[]:[qt()]}}function qt(){return{type:l.CharacterClassIntersection,classes:[le({negate:!1,baseOnly:!0})]}}function Xt(e,t){if(t.values[0].toUpperCase()+s.slice(1).toLowerCase())}function ar(e){let t=e.alternatives[0],r=t.elements[0];return e.type===l.Group&&e.alternatives.length===1&&t.elements.length===1&&r.type===l.Group&&!(e.atomic&&r.flags)&&!(e.flags&&(r.atomic||r.flags))?(e.atomic?r.atomic=!0:e.flags&&(r.flags=e.flags),r):e}function D({type:e,kind:t}){return e===l.Assertion&&(t===E.lookahead||t===E.lookbehind)}function or(e){return!/^(?:[-\d]|$)/.test(e)}function ir(e){for(let t=0;to.kind===R.flags);for(let o=r+1;o1)throw new Error(f`Uses "\K" in a way that's unsupported for conversion to JS`);a(H(pe({behind:!0}),i()))}},Flags({node:e,parent:t}){delete e.extended,Object.assign(e,{global:!1,hasIndices:!1,multiline:!1,sticky:e.sticky??!1}),t.options={disable:{x:!0,n:!0},force:{v:!0}}},Group({node:e}){if(!e.flags)return;let{enable:t,disable:r}=e.flags;t?.dotAll&&r?.dotAll&&delete t.dotAll,t?.ignoreCase&&r?.ignoreCase&&delete t.ignoreCase,t&&!Object.keys(t).length&&delete e.flags.enable},Pattern({node:e}){let t=!1,r=!1;for(let s of e.alternatives)s.elements.sort((n,o)=>n.kind===E.search_start&&o.kind===R.flags?-1:n.kind===R.flags&&o.kind===E.search_start?1:0),s.elements[0]?.kind===E.search_start?t=!0:r=!0;if(t&&r)throw new Error(f`Uses "\G" in a way that's unsupported for conversion to JS`)},Quantifier(e,t){let{node:r,remove:s,replaceWith:n,skip:o}=e,a=r.element;a.type===l.Quantifier?Ke(r):a.type===l.Assertion&&(r.min?(n(a),de(a,e,t,ge),o()):D(a)?Ke(r):(s(),o()))},VariableLengthCharacterSet({node:e,replaceWith:t},{allowBestEffort:r,minTargetEs2024:s}){let{kind:n}=e;if(n===W.newline)t(F(f`(?>\r\n?|[\n\v\f\x85\u2028\u2029])`));else if(n===W.grapheme){if(!r)throw new Error(f`Use of "\X" requires option allowBestEffort`);let o=s?f`\p{RGI_Emoji}`:Ne().source;t(F(f`(?>\r\n|${o}|\P{M}\p{M}*)`,{bypassPropertyNameCheck:!0}))}else throw new Error(`Unexpected varcharset kind "${n}"`)}},Qe={Alternative({node:e},{namedGroupsInScopeByAlt:t}){let r=X(e);if(r){let s=t.get(r);s&&t.set(e,s)}},Backreference({node:e},{multiplexCapturesToLeftByRef:t,reffedNodesByBackreference:r}){let{ref:s}=e;r.set(e,[...t.get(s).map(({node:n})=>n)])},CapturingGroup:{enter({node:e,replaceWith:t,skip:r},{groupOriginByCopy:s,groupsWithDuplicateNamesToRemove:n,multiplexCapturesToLeftByRef:o,namedGroupsInScopeByAlt:a,openDirectCaptures:i,openSubroutineRefs:c}){let{name:u,number:p}=e,d=u??p,C=s.get(e),h=c.has(d)||i.has(C),w=h&&!c.size;if(h&&!w)throw new Error("Unsupported indirect recursion");if(C?c.add(d):i.add(e),w){t(ze(d)),r();return}let L=T(o,d,[]);for(let k=0;kp.type===l.Group&&!!p.flags));u&&(c=H(x({flags:u}),[i]))}s(c),a||de(c,e,t,Qe)}},ur={CapturingGroup({node:e},t){e.number=++t.numCapturesToLeft,t.groupsWithDuplicateNamesToRemove.has(e)&&delete e.name},Backreference({node:e,replaceWith:t},{reffedNodesByBackreference:r}){let s=r.get(e);if(s.length>1){let n=s.map(o=>J(v(),[q(o.number)]));t(J(x(),n))}else e.ref=s[0].number}};function J(e,t){return t.forEach(r=>r.parent=e),e[Xe(e)]=t,e}function qe(e,t,r,s){let n=Array.isArray(e)?[]:{};for(let[o,a]of Object.entries(e))o==="parent"?n.parent=Array.isArray(r)?s:r:a&&typeof a=="object"?n[o]=qe(a,t,n,r):(o==="type"&&a===l.CapturingGroup&&t.set(n,e),n[o]=a);return n}function ze(e){if(typeof e=="number"&&e!==0)throw new Error("Unsupported recursion by number; use name instead");return{type:l.Recursion,ref:e}}function cr(e,t){let r=[];for(;e=e.parent;)(!t||t(e))&&r.push(e);return r}function Xe(e){if(e.alternatives)return"alternatives";if(e.elements)return"elements";if(e.classes)return"classes";throw new Error("Accessor for child container unknown")}function Je(e){let t=["dotAll","ignoreCase"],r={enable:{},disable:{}};return e.forEach(({flags:s})=>{t.forEach(n=>{s.enable?.[n]&&(delete r.disable[n],r.enable[n]=!0),s.disable?.[n]&&(r.disable[n]=!0)})}),Object.keys(r.enable).length||delete r.enable,Object.keys(r.disable).length||delete r.disable,r.enable||r.disable?r:null}function X(e){for(;e=e.parent;)if(e.type===l.Alternative)return e;return null}function lr(e){return/^[$_\p{IDS}][$\u200C\u200D\p{IDC}]*$/u.test(e)}function Ke(e){let t=H(x(),[e.element]);t.parent=e,e.element=t}function F(e,{bypassPropertyNameCheck:t}={}){let s=O(U(e),{bypassPropertyNameCheck:t}).pattern.alternatives;return s.length>1||s[0].elements.length>1?J(x(),s):s[0].elements[0]}function H(e,t){let r=Xe(e);return e[r][0].parent=e,t&&J(e[r][0],t),e}function de(e,{parent:t,key:r,container:s},n,o){I({node:e,parent:t,key:r,container:s},n,o)}function Ye(e,t){let r=Ce(t),s=B(r.target,"ES2024"),n=B(r.target,"ESNext"),o=r.maxRecursionDepth;if(o!==null&&(!Number.isInteger(o)||o<2||o>100))throw new Error("Invalid maxRecursionDepth; use null or 2-100");let a=null,i=null;if(!n){let h=[e.flags.ignoreCase];I({node:e},{getCurrentModI:()=>h.at(-1),popModI(){h.pop()},pushModI(w){h.push(w)},setHasCasedChar(){h.at(-1)?a=!0:i=!0}},pr)}let c={dotAll:e.flags.dotAll,ignoreCase:!!((e.flags.ignoreCase||a)&&!i)},u=null,p={allowBestEffort:r.allowBestEffort,appliedGlobalFlags:c,captureFlagIMap:new Map,currentFlags:{dotAll:e.flags.dotAll,ignoreCase:e.flags.ignoreCase},groupNames:new Set,inCharClass:!1,lastNode:u,maxRecursionDepth:o,optimize:r.optimize,useAppliedIgnoreCase:!!(!n&&a&&i),useDuplicateNames:n,useFlagMods:n,useFlagV:s,usePostEs2018Properties:s};function d(h){switch(p.lastNode=u,u=h,h.type){case l.Regex:return{pattern:d(h.pattern),flags:d(h.flags),options:{...h.options}};case l.Alternative:return h.elements.map(d).join("");case l.Assertion:return Cr(h,p,d);case l.Backreference:return mr(h,p);case l.CapturingGroup:return Er(h,p,d);case l.Character:return wr(h,p);case l.CharacterClass:return Ar(h,p,d);case l.CharacterClassIntersection:if(!p.useFlagV)throw new Error("Use of class intersection requires target ES2024 or later");return h.classes.map(d).join("&&");case l.CharacterClassRange:return Sr(h,p);case l.CharacterSet:return kr(h,p);case l.Flags:return br(h,p);case l.Group:return _r(h,p,d);case l.Pattern:return h.alternatives.map(d).join("|");case l.Quantifier:return d(h.element)+Ir(h);case l.Recursion:return $r(h,p);default:throw new Error(`Unexpected node type "${h.type}"`)}}let C=d(e);return s||(delete C.options.force.v,C.options.disable.v=!0,C.options.unicodeSetsPlugin=null),C}var pr={AnyGroup:{enter({node:e},t){let r=t.getCurrentModI();t.pushModI(e.flags?tt({ignoreCase:r},e.flags).ignoreCase:r)},exit(e,t){t.popModI()}},Backreference(e,t){t.setHasCasedChar()},Character({node:e},t){he(A(e.value))&&t.setHasCasedChar()},CharacterClassRange({node:e,skip:t},r){t(),et(e,{firstOnly:!0}).length&&r.setHasCasedChar()},CharacterSet({node:e},t){e.kind===$.property&&ue.has(e.value)&&t.setHasCasedChar()}},fr=new Set(["$","(",")","*","+",".","?","[","\\","]","^","{","|","}"]),gr=new Set(["-","\\","]","^"]),dr=new Set(["(",")","-","/","[","\\","]","^","{","|","}","!","#","$","%","&","*","+",",",".",":",";","<","=",">","?","@","`","~"]),Ze=new Map([[9,f`\t`],[10,f`\n`],[11,f`\v`],[12,f`\f`],[13,f`\r`]]),hr=/^\p{Cased}$/u;function he(e){return hr.test(e)}function Cr(e,t,r){let{kind:s,negate:n,alternatives:o}=e;if(D(e))return`(?${`${s===E.lookahead?"":"<"}${n?"!":"="}`}${o.map(r).join("|")})`;if(s===E.string_end)return"$";if(s===E.string_start)return"^";throw new Error(`Unexpected assertion kind "${s}"`)}function mr({ref:e},t){if(typeof e!="number")throw new Error("Unexpected named backref in transformed AST");if(!t.useFlagMods&&!t.allowBestEffort&&t.currentFlags.ignoreCase&&!t.captureFlagIMap.get(e))throw new Error("Use of case-insensitive backref to case-sensitive group requires option allowBestEffort or target ESNext");return"\\"+e}function Er({name:e,number:t,alternatives:r},s,n){return e&&(s.groupNames.has(e)?s.useDuplicateNames||(e=null):s.groupNames.add(e)),s.captureFlagIMap.set(t,s.currentFlags.ignoreCase),`(${e?`?<${e}>`:""}${r.map(n).join("|")})`}function wr({value:e},t){let r=A(e),s=G(e,{isAfterBackref:t.lastNode.type===l.Backreference,inCharClass:t.inCharClass,useFlagV:t.useFlagV});if(s!==r)return s;if(t.useAppliedIgnoreCase&&t.currentFlags.ignoreCase&&he(r)){let n=se(r);return t.inCharClass?n.join(""):n.length>1?`[${n.join("")}]`:n[0]}return r}function Ar({negate:e,parent:t,elements:r},s,n){if(!e&&(!s.useFlagV||s.optimize)&&t.type===l.CharacterClass&&r[0].type!==l.CharacterClassIntersection||s.optimize&&t.type===l.CharacterClassIntersection&&r.length===1&&r[0].type!==l.CharacterClassRange)return r.map(n).join("");if(!s.useFlagV&&t.type===l.CharacterClass)throw new Error("Use of nested character class requires target ES2024 or later");s.inCharClass=!0;let o=`[${e?"^":""}${r.map(n).join("")}]`;return s.inCharClass=!1,o}function Sr(e,t){let r=e.min.value,s=e.max.value,n={isAfterBackref:!1,inCharClass:!0,useFlagV:t.useFlagV},o=G(r,n),a=G(s,n),i="";if(t.useAppliedIgnoreCase&&t.currentFlags.ignoreCase){let c=et(e);Nr(c).forEach(p=>{i+=Array.isArray(p)?`${G(p[0],n)}-${G(p[1],n)}`:G(p,n)})}return`${o}-${a}${i}`}function kr({kind:e,negate:t,value:r,key:s},n){if(e===$.any)return n.currentFlags.dotAll?n.appliedGlobalFlags.dotAll||n.useFlagMods?".":"[^]":f`[^\n]`;if(e===$.digit)return t?f`\D`:f`\d`;if(e===$.property){if(!n.usePostEs2018Properties&&ye.has(r))throw new Error(`Unicode property "${r}" unavailable in target ES2018`);if(n.useAppliedIgnoreCase&&n.currentFlags.ignoreCase&&ue.has(r))throw new Error(`Unicode property "${r}" can't be case-insensitive when other chars have specific case`);return`${t?f`\P`:f`\p`}{${s?`${s}=`:""}${r}}`}if(e===$.word)return t?f`\W`:f`\w`;throw new Error(`Unexpected character set kind "${e}"`)}function br(e,t){return(t.appliedGlobalFlags.ignoreCase?"i":"")+(e.dotAll?"s":"")+(e.sticky?"y":"")}function _r({atomic:e,flags:t,parent:r,alternatives:s},n,o){let a=n.currentFlags;t&&(n.currentFlags=tt(a,t));let i=s.map(o).join("|"),c=n.optimize&&s.length===1&&r.type!==l.Quantifier&&!e&&(!n.useFlagMods||!t)?i:`(?${yr(e,t,n.useFlagMods)}${i})`;return n.currentFlags=a,c}function $r({ref:e},t){let r=t.maxRecursionDepth;if(!r)throw new Error("Use of recursion disabled");if(!t.allowBestEffort)throw new Error("Use of recursion requires option allowBestEffort");return e===0?`(?R=${r})`:f`\g<${e}&R=${r}>`}function et(e,{firstOnly:t}={}){let r=e.min.value,s=e.max.value,n=[];if(r<65&&(s===65535||s>=131071)||r===65536&&s>=131071)return n;for(let o=r;o<=s;o++){let a=A(o);if(!he(a))continue;let i=se(a).filter(c=>{let u=c.codePointAt(0);return us});if(i.length&&(n.push(...i),t))break}return n}function Nr(e){let t=e.map(n=>n.codePointAt(0)).sort((n,o)=>n-o),r=[],s=null;for(let n=0;n126&&e<160||t&&xr(e))return f`\x${e.toString(16).padStart(2,"0")}`;let n=r?s?dr:gr:fr,o=A(e);return(n.has(o)?"\\":"")+o}function yr(e,t,r){if(e)return">";let s="";if(t&&r){let{enable:n,disable:o}=t;s=(n?.ignoreCase?"i":"")+(n?.dotAll?"s":"")+(o?"-":"")+(o?.ignoreCase?"i":"")+(o?.dotAll?"s":"")}return`${s}:`}function tt(e,{enable:t,disable:r}){return{dotAll:!r?.dotAll&&!!(t?.dotAll||e.dotAll),ignoreCase:!r?.ignoreCase&&!!(t?.ignoreCase||e.ignoreCase)}}function Ir({min:e,max:t,greedy:r,possessive:s}){let n;return!e&&t===1?n="?":!e&&t===1/0?n="*":e===1&&t===1/0?n="+":e===t?n=`{${e}}`:n=`{${e},${t===1/0?"":t}}`,n+(s?"+":r?"":"?")}function xr(e){return e>47&&e<58}var Y=Object.freeze({DEFAULT:"DEFAULT",CHAR_CLASS:"CHAR_CLASS"});function Fr(e,t,r,s){let n=new RegExp(String.raw`${t}|(?<$skip>\[\^?|\\?.)`,"gsu"),o=[!1],a=0,i="";for(let c of e.matchAll(n)){let{0:u,groups:{$skip:p}}=c;if(!p&&(!s||s===Y.DEFAULT==!a)){r instanceof Function?i+=r(c,{context:a?Y.CHAR_CLASS:Y.DEFAULT,negated:o[o.length-1]}):i+=r;continue}u[0]==="["?(a++,o.push(u[1]==="^")):u==="]"&&a&&(a--,o.pop()),i+=u}return i}var rt={DEFAULT:"DEFAULT",CHAR_CLASS:"CHAR_CLASS",ENCLOSED_P:"ENCLOSED_P",ENCLOSED_U:"ENCLOSED_U",GROUP_NAME:"GROUP_NAME",INTERVAL_QUANTIFIER:"INTERVAL_QUANTIFIER",INVALID_INCOMPLETE_TOKEN:"INVALID_INCOMPLETE_TOKEN"},me={DEFAULT:"DEFAULT",ENCLOSED_P:"ENCLOSED_P",ENCLOSED_Q:"ENCLOSED_Q",ENCLOSED_U:"ENCLOSED_U",INVALID_INCOMPLETE_TOKEN:"INVALID_INCOMPLETE_TOKEN",RANGE:"RANGE"},En=new Set([rt.ENCLOSED_P,rt.ENCLOSED_U]),wn=new Set([me.ENCLOSED_P,me.ENCLOSED_Q,me.ENCLOSED_U]),An=(()=>{try{new RegExp("(?i:)")}catch{return!1}return!0})(),Sn=(()=>{try{new RegExp("","v")}catch{return!1}return!0})(),st="&!#$%*+,.:;<=>?@^`~",Lr="$E$",at=String.raw`\(\?<(?![=!])(?[^>]+)>`,Pr=String.raw`\((?!\?)(?!(?<=\(\?\()DEFINE\))|${at}`,we=String.raw`\(\?(?:[:=!>A-Za-z\-]|<[=!]|\(DEFINE\))`;var kn=new RegExp(String.raw` (?\(\?<(?![=!])|\\[gk]<) | (?\\[pPu]\{) | (?\\q\{) @@ -46,9 +46,9 @@ var OnigurumaToES=(()=>{var ee=Object.defineProperty;var dt=Object.getOwnPropert ) | -- | \\?. -`.replace(/\s+/g,""),"gsu");function xr(e,t,r,s){return e.slice(0,t)+s+e.slice(t+r.length)}var Lr=["Basic_Emoji","Emoji_Keycap_Sequence","RGI_Emoji_Modifier_Sequence","RGI_Emoji_Flag_Sequence","RGI_Emoji_Tag_Sequence","RGI_Emoji_ZWJ_Sequence","RGI_Emoji"].join("|"),An=new RegExp(String.raw` +`.replace(/\s+/g,""),"gsu");function vr(e,t,r,s){return e.slice(0,t)+s+e.slice(t+r.length)}var Tr=["Basic_Emoji","Emoji_Keycap_Sequence","RGI_Emoji_Modifier_Sequence","RGI_Emoji_Flag_Sequence","RGI_Emoji_Tag_Sequence","RGI_Emoji_ZWJ_Sequence","RGI_Emoji"].join("|"),bn=new RegExp(String.raw` \\(?: c[A-Za-z] - | p\{(?${Lr})\} + | p\{(?${Tr})\} | [pP]\{[^\}]+\} | (?q) | u(?:[A-Fa-f\d]{4}|\{[A-Fa-f\d]+\}) @@ -58,12 +58,12 @@ var OnigurumaToES=(()=>{var ee=Object.defineProperty;var dt=Object.getOwnPropert | -- | && | . -`.replace(/\s+/g,""),"gsu");var Sn=new RegExp(String.raw` -${Ce} +`.replace(/\s+/g,""),"gsu");var _n=new RegExp(String.raw` +${we} | \(\?< | (?\\[1-9]\d*) | \\?. -`.replace(/\s+/g,""),"gsu");var kn=new RegExp(String.raw` +`.replace(/\s+/g,""),"gsu");var $n=new RegExp(String.raw` \\(?: [gk]< | [pPu]\{ | c[A-Za-z] @@ -72,12 +72,12 @@ ${Ce} | 0\d+ ) | \[\^ -| ${Ce} +| ${we} | \(\?< -| (?[${tt}])\k +| (?[${st}])\k | -- | \\?. -`.replace(/\s+/g,""),"gsu");var et=new RegExp(String.raw`(?${Ce})|(?\((?:\?<[^>]+>)?)|\\?.`,"gsu");function nt(e,t){if(!/\(\?>/.test(e))return e;let r="(?>",s=`(?:(?=(${t?.useEmulationGroups?yr:""}`,n=[0],a=0,o=0,i=NaN,u;do{u=!1;let c=0,p=0,h=!1,d;for(et.lastIndex=Number.isNaN(i)?0:i+s.length;d=et.exec(e);){let{0:C,index:w,groups:{capturingStart:L,noncapturingStart:k}}=d;if(C==="[")c++;else if(c)C==="]"&&c--;else if(C===r&&!h)i=w,h=!0;else if(h&&k)p++;else if(L)h?p++:(a++,n.push(a+o));else if(C===")"&&h){if(!p){o++,e=`${e.slice(0,i)}${s}${e.slice(i+r.length,w)}))<$$${o+a}>)${e.slice(w+1)}`,u=!0;break}p--}}}while(u);return e=Ir(e,String.raw`\\(?[1-9]\d*)|<\$\$(?\d+)>`,({0:c,groups:{backrefNum:p,wrappedBackrefNum:h}})=>{if(p){let d=+p;if(d>n.length-1)throw new Error(`Backref "${c}" greater than number of captures`);return`\\${n[d]}`}return`\\${h}`},Z.DEFAULT),e}var st=String.raw`(?:[?*+]|\{\d+(?:,\d*)?\})`,de=new RegExp(String.raw` +`.replace(/\s+/g,""),"gsu");var nt=new RegExp(String.raw`(?${we})|(?\((?:\?<[^>]+>)?)|\\?.`,"gsu");function ot(e,t){if(!/\(\?>/.test(e))return e;let r="(?>",s=`(?:(?=(${t?.useEmulationGroups?Lr:""}`,n=[0],o=0,a=0,i=NaN,c;do{c=!1;let u=0,p=0,d=!1,C;for(nt.lastIndex=Number.isNaN(i)?0:i+s.length;C=nt.exec(e);){let{0:h,index:w,groups:{capturingStart:L,noncapturingStart:k}}=C;if(h==="[")u++;else if(u)h==="]"&&u--;else if(h===r&&!d)i=w,d=!0;else if(d&&k)p++;else if(L)d?p++:(o++,n.push(o+a));else if(h===")"&&d){if(!p){a++,e=`${e.slice(0,i)}${s}${e.slice(i+r.length,w)}))<$$${a+o}>)${e.slice(w+1)}`,c=!0;break}p--}}}while(c);return e=Fr(e,String.raw`\\(?[1-9]\d*)|<\$\$(?\d+)>`,({0:u,groups:{backrefNum:p,wrappedBackrefNum:d}})=>{if(p){let C=+p;if(C>n.length-1)throw new Error(`Backref "${u}" greater than number of captures`);return`\\${n[C]}`}return`\\${d}`},Y.DEFAULT),e}var it=String.raw`(?:[?*+]|\{\d+(?:,\d*)?\})`,Ee=new RegExp(String.raw` \\(?: \d+ | c[A-Za-z] | [gk]<[^>]+> @@ -90,21 +90,21 @@ ${Ce} | [A-Za-z\-]+: | \(DEFINE\) ))? -| (?${st})(?[?+]?)(?[?*+\{]?) +| (?${it})(?[?+]?)(?[?*+\{]?) | \\?. -`.replace(/\s+/g,""),"gsu");function at(e){if(!new RegExp(`${st}\\+`).test(e))return e;let t=[],r=null,s=null,n="",a=0,o;for(de.lastIndex=0;o=de.exec(e);){let{0:i,index:u,groups:{qBase:c,qMod:p,invalidQ:h}}=o;if(i==="[")a||(s=u),a++;else if(i==="]")a?a--:s=null;else if(!a)if(p==="+"&&n&&!n.startsWith("(")){if(h)throw new Error(`Invalid quantifier "${i}"`);let d=-1;if(/^\{\d+\}$/.test(c))e=xr(e,u+c.length,p,"");else{if(n===")"||n==="]"){let C=n===")"?r:s;if(C===null)throw new Error(`Invalid unmatched "${n}"`);e=`${e.slice(0,C)}(?>${e.slice(C,u)}${c})${e.slice(u+i.length)}`}else e=`${e.slice(0,u-n.length)}(?>${n}${c})${e.slice(u+i.length)}`;d+=4}de.lastIndex+=d}else i[0]==="("?t.push(u):i===")"&&(r=t.length?t.pop():null);n=i}return e}var Pr=String.raw`\\g<(?[^>&]+)>`,bn=new RegExp(String.raw` -${Pr} -| (?${Fr}) +`.replace(/\s+/g,""),"gsu");function ut(e){if(!new RegExp(`${it}\\+`).test(e))return e;let t=[],r=null,s=null,n="",o=0,a;for(Ee.lastIndex=0;a=Ee.exec(e);){let{0:i,index:c,groups:{qBase:u,qMod:p,invalidQ:d}}=a;if(i==="[")o||(s=c),o++;else if(i==="]")o?o--:s=null;else if(!o)if(p==="+"&&n&&!n.startsWith("(")){if(d)throw new Error(`Invalid quantifier "${i}"`);let C=-1;if(/^\{\d+\}$/.test(u))e=vr(e,c+u.length,p,"");else{if(n===")"||n==="]"){let h=n===")"?r:s;if(h===null)throw new Error(`Invalid unmatched "${n}"`);e=`${e.slice(0,h)}(?>${e.slice(h,c)}${u})${e.slice(c+i.length)}`}else e=`${e.slice(0,c-n.length)}(?>${n}${u})${e.slice(c+i.length)}`;C+=4}Ee.lastIndex+=C}else i[0]==="("?t.push(c):i===")"&&(r=t.length?t.pop():null);n=i}return e}var Dr=String.raw`\\g<(?[^>&]+)>`,Nn=new RegExp(String.raw` +${Dr} +| (?${Pr}) | \\(?[1-9]\d*) | \\k<(?[^>]+)> | \\?. -`.replace(/\s+/g,""),"gsu");var _n=new RegExp(String.raw`${rt}|\(\?:\)|(?\\?.)`,"gsu");var Tr="&!#%,:;<=>@`~",$n=new RegExp(String.raw` +`.replace(/\s+/g,""),"gsu");var yn=new RegExp(String.raw`${at}|\(\?:\)|(?\\?.)`,"gsu");var Rr="&!#%,:;<=>@`~",In=new RegExp(String.raw` \[\^?-? | --?\] -| (?[${tt}])\k +| (?[${st}])\k | -- -| \\(?[${Tr}]) +| \\(?[${Rr}]) | \\[pPu]\{[^}]+\} | \\?. -`.replace(/\s+/g,""),"gsu");var N=Object.freeze({DEFAULT:"DEFAULT",CHAR_CLASS:"CHAR_CLASS"});function me(e,t,r,s){let n=new RegExp(String.raw`${t}|(?<$skip>\[\^?|\\?.)`,"gsu"),a=[!1],o=0,i="";for(let u of e.matchAll(n)){let{0:c,groups:{$skip:p}}=u;if(!p&&(!s||s===N.DEFAULT==!o)){r instanceof Function?i+=r(u,{context:o?N.CHAR_CLASS:N.DEFAULT,negated:a[a.length-1]}):i+=r;continue}c[0]==="["?(o++,a.push(c[1]==="^")):c==="]"&&o&&(o--,a.pop()),i+=c}return i}function ot(e,t,r,s){me(e,t,r,s)}function vr(e,t,r=0,s){if(!new RegExp(t,"su").test(e))return null;let n=new RegExp(`${t}|(?<$skip>\\\\?.)`,"gsu");n.lastIndex=r;let a=0,o;for(;o=n.exec(e);){let{0:i,groups:{$skip:u}}=o;if(!u&&(!s||s===N.DEFAULT==!a))return o;i==="["?a++:i==="]"&&a&&a--,n.lastIndex==o.index&&n.lastIndex++}return null}function G(e,t,r){return!!vr(e,t,0,r)}function it(e,t){let r=/\\?./gsu;r.lastIndex=t;let s=e.length,n=0,a=1,o;for(;o=r.exec(e);){let[i]=o;if(i==="[")n++;else if(n)i==="]"&&n--;else if(i==="(")a++;else if(i===")"&&(a--,!a)){s=o.index;break}}return e.slice(t,s)}var ft=String.raw`\\g<(?[^>&]+)&R=(?\d+)>`,Ee=String.raw`\(\?R=(?\d+)\)|${ft}`,we=String.raw`\(\?<(?![=!])(?[^>]+)>`,Y=new RegExp(String.raw`${we}|${Ee}|\\?.`,"gsu");function gt(e){if(!G(e,Ee,N.DEFAULT))return e;if(G(e,String.raw`\\[1-9]`,N.DEFAULT))throw new Error("Numbered backrefs cannot be used with recursion; use named backref");if(G(e,String.raw`\(\?\(DEFINE\)`,N.DEFAULT))throw new Error("DEFINE groups cannot be used with recursion");let t=new Map,r=0,s;for(Y.lastIndex=0;s=Y.exec(e);){let{0:n,groups:{captureName:a,rDepth:o,gRName:i,gRDepth:u}}=s;if(n==="[")r++;else if(r)n==="]"&&r--;else if(a)t.set(a,Y.lastIndex);else if(o){let c=+o;ut(c);let p=e.slice(0,s.index),h=e.slice(Y.lastIndex);return ct(h),lt(p,h,c,!1)}else if(i){let c=+u;ut(c);let p=`Recursion via \\g<${i}&R=${u}> must be used within the referenced group`;if(!t.has(i))throw new Error(p);let h=t.get(i),d=it(e,h);if(!G(d,ft,N.DEFAULT))throw new Error(p);let C=e.slice(h,s.index),w=d.slice(C.length+n.length);return ct(w),e.slice(0,h)+lt(C,w,c,!0)+e.slice(h+d.length)}}throw new Error("Unexpected error; recursion was not processed")}function ut(e){if(e<2||e>100)throw new Error(`Max depth must be between 2 and 100; used ${e}`)}function ct(e){if(G(e,Ee,N.DEFAULT))throw new Error("Recursion can only be used once per regex")}function lt(e,t,r,s){let n=new Set;s&&ot(e+t,we,({groups:{captureName:o}})=>{n.add(o)},N.DEFAULT);let a=r-1;return`${e}${pt(`(?:${e}`,a,s?n:null)}(?:)${pt(`${t})`,a,s?n:null,"backward")}${t}`}function pt(e,t,r,s="forward"){let a=i=>s==="backward"?t-i+2-1:i+2,o="";for(let i=0;i[^>]+)>`,({0:c,groups:{captureName:p,backref:h}})=>{if(h&&r&&!r.has(h))return c;let d=`_$${u}`;return p?`(?<${p}${d}>`:`\\k<${h}${d}>`},N.DEFAULT)}return o}function Ae(e,t,r){let s=ge(r),n=R(e,t),a=U(n,{optimize:s.optimize}),o=J(a,{allowBestEffort:s.allowBestEffort,bestEffortTarget:s.target}),i=Xe(o,s);return{pattern:nt(at(gt(i.pattern))),flags:`${i.flags}${i.options.disable.v?"u":"v"}`}}function ge(e){if(e?.target!==void 0&&!z[e.target])throw new Error(`Unexpected target "${e.target}"`);return{allowBestEffort:!0,maxRecursionDepth:6,optimize:!0,target:"ES2024",...e}}function ht(e,t){return U(R(e,t))}function Dr(e,t){return J(ht(e,t))}function Rr(e,t,r){let s=Ae(e,t,r);return new RegExp(s.pattern,s.flags)}return At(Ur);})(); +`.replace(/\s+/g,""),"gsu");var N=Object.freeze({DEFAULT:"DEFAULT",CHAR_CLASS:"CHAR_CLASS"});function Ae(e,t,r,s){let n=new RegExp(String.raw`${t}|(?<$skip>\[\^?|\\?.)`,"gsu"),o=[!1],a=0,i="";for(let c of e.matchAll(n)){let{0:u,groups:{$skip:p}}=c;if(!p&&(!s||s===N.DEFAULT==!a)){r instanceof Function?i+=r(c,{context:a?N.CHAR_CLASS:N.DEFAULT,negated:o[o.length-1]}):i+=r;continue}u[0]==="["?(a++,o.push(u[1]==="^")):u==="]"&&a&&(a--,o.pop()),i+=u}return i}function ct(e,t,r,s){Ae(e,t,r,s)}function Ur(e,t,r=0,s){if(!new RegExp(t,"su").test(e))return null;let n=new RegExp(`${t}|(?<$skip>\\\\?.)`,"gsu");n.lastIndex=r;let o=0,a;for(;a=n.exec(e);){let{0:i,groups:{$skip:c}}=a;if(!c&&(!s||s===N.DEFAULT==!o))return a;i==="["?o++:i==="]"&&o&&o--,n.lastIndex==a.index&&n.lastIndex++}return null}function M(e,t,r){return!!Ur(e,t,0,r)}function lt(e,t){let r=/\\?./gsu;r.lastIndex=t;let s=e.length,n=0,o=1,a;for(;a=r.exec(e);){let[i]=a;if(i==="[")n++;else if(n)i==="]"&&n--;else if(i==="(")o++;else if(i===")"&&(o--,!o)){s=a.index;break}}return e.slice(t,s)}var ht=String.raw`\\g<(?[^>&]+)&R=(?\d+)>`,Se=String.raw`\(\?R=(?\d+)\)|${ht}`,ke=String.raw`\(\?<(?![=!])(?[^>]+)>`,ee=new RegExp(String.raw`${ke}|${Se}|\\?.`,"gsu");function Ct(e){if(!M(e,Se,N.DEFAULT))return e;if(M(e,String.raw`\\[1-9]`,N.DEFAULT))throw new Error("Numbered backrefs cannot be used with recursion; use named backref");if(M(e,String.raw`\(\?\(DEFINE\)`,N.DEFAULT))throw new Error("DEFINE groups cannot be used with recursion");let t=new Map,r=0,s;for(ee.lastIndex=0;s=ee.exec(e);){let{0:n,groups:{captureName:o,rDepth:a,gRName:i,gRDepth:c}}=s;if(n==="[")r++;else if(r)n==="]"&&r--;else if(o)t.set(o,ee.lastIndex);else if(a){let u=+a;pt(u);let p=e.slice(0,s.index),d=e.slice(ee.lastIndex);return ft(d),gt(p,d,u,!1)}else if(i){let u=+c;pt(u);let p=`Recursion via \\g<${i}&R=${c}> must be used within the referenced group`;if(!t.has(i))throw new Error(p);let d=t.get(i),C=lt(e,d);if(!M(C,ht,N.DEFAULT))throw new Error(p);let h=e.slice(d,s.index),w=C.slice(h.length+n.length);return ft(w),e.slice(0,d)+gt(h,w,u,!0)+e.slice(d+C.length)}}throw new Error("Unexpected error; recursion was not processed")}function pt(e){if(e<2||e>100)throw new Error(`Max depth must be between 2 and 100; used ${e}`)}function ft(e){if(M(e,Se,N.DEFAULT))throw new Error("Recursion can only be used once per regex")}function gt(e,t,r,s){let n=new Set;s&&ct(e+t,ke,({groups:{captureName:a}})=>{n.add(a)},N.DEFAULT);let o=r-1;return`${e}${dt(`(?:${e}`,o,s?n:null)}(?:)${dt(`${t})`,o,s?n:null,"backward")}${t}`}function dt(e,t,r,s="forward"){let o=i=>s==="backward"?t-i+2-1:i+2,a="";for(let i=0;i[^>]+)>`,({0:u,groups:{captureName:p,backref:d}})=>{if(d&&r&&!r.has(d))return u;let C=`_$${c}`;return p?`(?<${p}${C}>`:`\\k<${d}${C}>`},N.DEFAULT)}return a}function be(e,t,r){let s=Ce(r),n=U(e,t),o=O(n,{optimize:s.optimize}),a=Z(o,{allowBestEffort:s.allowBestEffort,bestEffortTarget:s.target}),i=Ye(a,s);return{pattern:ot(ut(Ct(i.pattern))),flags:`${i.flags}${i.options.disable.v?"u":"v"}`}}function Ce(e){if(e?.target!==void 0&&!z[e.target])throw new Error(`Unexpected target "${e.target}"`);return{allowBestEffort:!0,maxRecursionDepth:6,optimize:!0,target:"ES2024",...e}}function mt(e,t){return O(U(e,t))}function Or(e,t){return Z(mt(e,t))}function Gr(e,t,r){let s=be(e,t,r);return new RegExp(s.pattern,s.flags)}return bt(Mr);})(); //# sourceMappingURL=index.min.js.map diff --git a/src/generate.js b/src/generate.js index 98601fd..d57d0b8 100644 --- a/src/generate.js +++ b/src/generate.js @@ -1,5 +1,5 @@ import {getOptions} from './compile.js'; -import {AstAssertionKinds, AstCharacterSetKinds, AstTypes} from './parse.js'; +import {AstAssertionKinds, AstCharacterSetKinds, AstTypes, isLookaround} from './parse.js'; import {traverse} from './traverse.js'; import {getIgnoreCaseMatchChars, JsUnicodePropertiesPostEs2018, UnicodePropertiesWithSpecificCase} from './unicode.js'; import {cp, isMinTarget, r} from './utils.js'; @@ -198,8 +198,9 @@ function charHasCase(char) { return casedRe.test(char); } -function genAssertion({kind, negate, alternatives}, _, gen) { - if (kind === AstAssertionKinds.lookahead || kind === AstAssertionKinds.lookbehind) { +function genAssertion(node, _, gen) { + const {kind, negate, alternatives} = node; + if (isLookaround(node)) { const prefix = `${kind === AstAssertionKinds.lookahead ? '' : '<'}${negate ? '!' : '='}`; return `(?${prefix}${alternatives.map(gen).join('|')})`; } diff --git a/src/parse.js b/src/parse.js index ee1afc6..347551f 100644 --- a/src/parse.js +++ b/src/parse.js @@ -30,13 +30,10 @@ const AstTypeAliases = { AnyNode: 'AnyNode', }; -function getAstTypeAliases({type, kind}) { +function getAstTypeAliases(node) { + const {type} = node; const types = [AstTypeAliases.AnyNode]; - if ( - (type === AstTypes.Assertion && (kind === AstAssertionKinds.lookahead || kind === AstAssertionKinds.lookbehind)) || - type === AstTypes.CapturingGroup || - type === AstTypes.Group - ) { + if (isLookaround(node) || type === AstTypes.CapturingGroup || type === AstTypes.Group) { types.push(AstTypeAliases.AnyGroup); } types.push(type); @@ -666,6 +663,11 @@ function getOptimizedGroup(node) { return node; } +function isLookaround({type, kind}) { + return type === AstTypes.Assertion && + (kind === AstAssertionKinds.lookahead || kind === AstAssertionKinds.lookbehind); +} + function isValidGroupNameOniguruma(name) { return !/^(?:[-\d]|$)/.test(name); } @@ -713,5 +715,6 @@ export { createUnicodeProperty, createVariableLengthCharacterSet, getAstTypeAliases, + isLookaround, parse, }; diff --git a/src/transform.js b/src/transform.js index 3f08a4e..16928c0 100644 --- a/src/transform.js +++ b/src/transform.js @@ -1,5 +1,5 @@ import emojiRegex from 'emoji-regex-xs'; -import {AstAssertionKinds, AstCharacterSetKinds, AstDirectiveKinds, AstTypes, AstVariableLengthCharacterSetKinds, createAlternative, createBackreference, createGroup, createLookaround, createUnicodeProperty, parse} from './parse.js'; +import {AstAssertionKinds, AstCharacterSetKinds, AstDirectiveKinds, AstTypes, AstVariableLengthCharacterSetKinds, createAlternative, createBackreference, createGroup, createLookaround, createUnicodeProperty, isLookaround, parse} from './parse.js'; import {tokenize} from './tokenize.js'; import {traverse} from './traverse.js'; import {JsUnicodeProperties, PosixClassesMap} from './unicode.js'; @@ -172,7 +172,8 @@ const FirstPassVisitor = { } }, - Directive({node, parent, key, container, ast, remove, replaceWith, removeAllPrevSiblings, removeAllNextSiblings}, state) { + Directive(path, state) { + const {node, parent, ast, remove, replaceWith, removeAllPrevSiblings, removeAllNextSiblings} = path; const {kind, flags} = node; if (kind === AstDirectiveKinds.flags) { if (!flags.enable && !flags.disable) { @@ -181,12 +182,7 @@ const FirstPassVisitor = { } else { const flagGroup = prepContainer(createGroup({flags}), removeAllNextSiblings()); replaceWith(flagGroup); - traverse({ - node: flagGroup, - parent, - key, - container, - }, state, FirstPassVisitor); + traverseReplacement(flagGroup, path, state, FirstPassVisitor); } } else if (kind === AstDirectiveKinds.keep) { // Allows multiple `\K`s since the the node is removed @@ -280,14 +276,28 @@ const FirstPassVisitor = { } }, - Quantifier({node}) { - // TODO: Handle quantified assertions; not allowed in JS. If min is 0, remove the assertion and skip kids; else unwrap - // TODO: Custom or better error for quantified flag directives `(?i)+` - if (node.element.type === AstTypes.Quantifier) { - const group = prepContainer(createGroup(), [node.element]); - // Manually set the parent since we're not using `replaceWith` - group.parent = node; - node.element = group; + Quantifier(path, state) { + const {node, remove, replaceWith, skip} = path; + const child = node.element; + if (child.type === AstTypes.Quantifier) { + // Change e.g. `a**` to `(?:a*)*` + moveQuantifierToWrapper(node); + } else if (child.type === AstTypes.Assertion) { + // Quantified assertions aren't allowed in JS + if (node.min) { + // Strip the quantifier but keep its child + replaceWith(child); + traverseReplacement(child, path, state, FirstPassVisitor); + skip(); + } else if (isLookaround(child)) { + // Change e.g. `(?=a)*` to `(?:(?=a))*`; can't remove the child since the lookaround might + // contain captures reffed elsewhere + moveQuantifierToWrapper(node); + } else { + // In other cases with `min: 0`, the quantifier makes its assertion irrelevant + remove(); + skip(); + } } }, @@ -433,16 +443,16 @@ const SecondPassVisitor = { }, }, - Subroutine({node, parent, key, container, replaceWith}, state) { - const {groupOriginByCopy, subroutineRefMap} = state; + Subroutine(path, state) { + const {node, replaceWith} = path; const {ref} = node; - const reffedGroupNode = subroutineRefMap.get(ref); + const reffedGroupNode = state.subroutineRefMap.get(ref); // Other forms of recursion are handled by the `CapturingGroup` visitor const isGlobalRecursion = ref === 0; const expandedSubroutine = isGlobalRecursion ? createRecursion(ref) : // The reffed group might itself contain subroutines, which are expanded during sub-traversal - cloneCapturingGroup(reffedGroupNode, groupOriginByCopy, null); + cloneCapturingGroup(reffedGroupNode, state.groupOriginByCopy, null); let replacement = expandedSubroutine; if (!isGlobalRecursion) { // Subroutines take their flags from the reffed group, not the flags surrounding themselves @@ -457,14 +467,9 @@ const SecondPassVisitor = { } replaceWith(replacement); if (!isGlobalRecursion) { - traverse({ - // Start traversal at the flag group wrapper so the logic for stripping duplicate names - // propagates through its alternative - node: replacement, - parent, - key, - container, - }, state, SecondPassVisitor); + // Start traversal at the flag group wrapper so the logic for stripping duplicate names + // propagates through its alternative + traverseReplacement(replacement, path, state, SecondPassVisitor); } }, }; @@ -588,8 +593,8 @@ function getCombinedFlagsFromFlagNodes(flagNodes) { } function getParentAlternative(node) { - // Skip past quantifiers, etc. while (node = node.parent) { + // Skip past quantifiers, etc. if (node.type === AstTypes.Alternative) { return node; } @@ -603,6 +608,13 @@ function isValidGroupNameJs(name) { return /^[$_\p{IDS}][$\u200C\u200D\p{IDC}]*$/u.test(name); } +function moveQuantifierToWrapper(quantifier) { + const group = prepContainer(createGroup(), [quantifier.element]); + // Manually set the parent since we're not using `replaceWith` + group.parent = quantifier; + quantifier.element = group; +} + // Returns a single node, either the given node or all nodes wrapped in a noncapturing group // TODO: Consider moving to `parse` module and dropping assumptions about `parent` props function parseFragment(pattern, {bypassPropertyNameCheck} = {}) { @@ -624,6 +636,16 @@ function prepContainer(node, kids) { return node; } +function traverseReplacement(replacement, {parent, key, container}, state, visitor) { + traverse({ + // Don't use the `node` from `path` + node: replacement, + parent, + key, + container, + }, state, visitor); +} + export { transform, }; diff --git a/src/traverse.js b/src/traverse.js index 6f9c059..9c9abeb 100644 --- a/src/traverse.js +++ b/src/traverse.js @@ -1,4 +1,4 @@ -import {AstAssertionKinds, AstTypes, getAstTypeAliases} from './parse.js'; +import {AstTypes, getAstTypeAliases, isLookaround} from './parse.js'; import {throwIfNot} from './utils.js'; function traverse(path, state, visitor) { @@ -61,7 +61,7 @@ function traverse(path, state, visitor) { traverseArray(node.elements, node); break; case AstTypes.Assertion: - if (node.kind === AstAssertionKinds.lookahead || node.kind === AstAssertionKinds.lookbehind) { + if (isLookaround(node)) { traverseArray(node.alternatives, node); } break;