diff --git a/dist/index.min.js b/dist/index.min.js index febbe16..da5d5a8 100644 --- a/dist/index.min.js +++ b/dist/index.min.js @@ -1,4 +1,4 @@ -var OnigurumaToES=(()=>{var te=Object.defineProperty;var Ct=Object.getOwnPropertyDescriptor;var mt=Object.getOwnPropertyNames;var Et=Object.prototype.hasOwnProperty;var wt=(e,t)=>{for(var r in t)te(e,r,{get:t[r],enumerable:!0})},At=(e,t,r,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of mt(t))!Et.call(e,n)&&n!==r&&te(e,n,{get:()=>t[n],enumerable:!(s=Ct(t,n))||s.enumerable});return e};var St=e=>At(te({},"__esModule",{value:!0}),e);var Lr={};wt(Lr,{compile:()=>_e,toOnigurumaAst:()=>dt,toRegExp:()=>Tr,toRegexAst:()=>Pr});var re=String.raw,ke=re`(?:\p{Emoji}\uFE0F\u20E3?|\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation})`,xe=re`\u{E0061}-\u{E007A}`,be=()=>new RegExp(re`[\u{1F1E6}-\u{1F1FF}]{2}|\u{1F3F4}[${xe}]{2}[\u{E0030}-\u{E0039}${xe}]{1,3}\u{E007F}|${ke}(?:\u200D${ke})*`,"gu");var A=String.fromCodePoint,f=String.raw,Q={ES2018:2018,ES2024:2024,ESNext:2025};function v(e,t,r){return e.has(t)||e.set(t,r),e.get(t)}function V(e,t){return Q[e]>=Q[t]}function N(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=bt.get(r),o=xt.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(j(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"]),ie=new Map;for(let e of kt)ie.set(j(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(" ")),xt=new Map([[A(223),A(7838)],[A(107),A(8490)],[A(229),A(8491)],[A(969),A(8486)]]),bt=new Map([L(453),L(456),L(459),L(498),...ne(8072,8079),...ne(8088,8095),...ne(8104,8111),L(8124),L(8140),L(8188)]),W=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}`]]),Ne=new Set(["alnum","blank","graph","print","word","xdigit"]);function yt(e,t){let r=[];for(let s=e;s<=t;s++)r.push(s);return r}function j(e){return e.replace(/[- _]+/g,"").toLowerCase()}function L(e){let t=A(e);return[t.toLowerCase(),t]}function ne(e,t){return yt(e,t).map(r=>L(r))}var ce=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"},K={keep:"keep",flags:"flags"},x={atomic:"atomic",capturing:"capturing",group:"group",lookahead:"lookahead",lookbehind:"lookbehind"},$e=new Map([["a",7],["b",8],["e",27],["f",12],["n",10],["r",13],["t",9],["v",11]]),Pe="c.? | C(?:-.?)?",Te=f`[pP]\{(?:\^?[\x20\w]+\})?`,Le=f`u\{[^\}]*\}? | u\p{AHex}{0,4} | x\p{AHex}{0,2}`,ve=f`\d{1,3}`,Re=f`\[\^?\]?`,De=/[?*+][?+]?|\{\d+(?:,\d*)?\}\??/,q=new RegExp(f` +var OnigurumaToES=(()=>{var te=Object.defineProperty;var Ct=Object.getOwnPropertyDescriptor;var mt=Object.getOwnPropertyNames;var Et=Object.prototype.hasOwnProperty;var wt=(e,t)=>{for(var r in t)te(e,r,{get:t[r],enumerable:!0})},St=(e,t,r,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of mt(t))!Et.call(e,n)&&n!==r&&te(e,n,{get:()=>t[n],enumerable:!(s=Ct(t,n))||s.enumerable});return e};var At=e=>St(te({},"__esModule",{value:!0}),e);var Lr={};wt(Lr,{compile:()=>_e,toOnigurumaAst:()=>dt,toRegExp:()=>Tr,toRegexAst:()=>Pr});var re=String.raw,ke=re`(?:\p{Emoji}\uFE0F\u20E3?|\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation})`,xe=re`\u{E0061}-\u{E007A}`,be=()=>new RegExp(re`[\u{1F1E6}-\u{1F1FF}]{2}|\u{1F3F4}[${xe}]{2}[\u{E0030}-\u{E0039}${xe}]{1,3}\u{E007F}|${ke}(?:\u200D${ke})*`,"gu");var S=String.fromCodePoint,f=String.raw,Q={ES2018:2018,ES2024:2024,ESNext:2025};function v(e,t,r){return e.has(t)||e.set(t,r),e.get(t)}function V(e,t){return Q[e]>=Q[t]}function N(e,t){if(!e)throw new Error(t??"Value expected");return e}var _t=new Set([S(304),S(305)]);function se(e){if(_t.has(e))return[e];let t=new Set,r=e.toLowerCase(),s=r.toUpperCase(),n=bt.get(r),o=xt.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(j(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"]),ie=new Map;for(let e of kt)ie.set(j(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(" ")),xt=new Map([[S(223),S(7838)],[S(107),S(8490)],[S(229),S(8491)],[S(969),S(8486)]]),bt=new Map([L(453),L(456),L(459),L(498),...ne(8072,8079),...ne(8088,8095),...ne(8104,8111),L(8124),L(8140),L(8188)]),W=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}`]]),Ne=new Set(["alnum","blank","graph","print","word","xdigit"]);function yt(e,t){let r=[];for(let s=e;s<=t;s++)r.push(s);return r}function j(e){return e.replace(/[- _]+/g,"").toLowerCase()}function L(e){let t=S(e);return[t.toLowerCase(),t]}function ne(e,t){return yt(e,t).map(r=>L(r))}var ce=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"},A={any:"any",digit:"digit",hex:"hex",posix:"posix",property:"property",space:"space",word:"word"},K={keep:"keep",flags:"flags"},x={atomic:"atomic",capturing:"capturing",group:"group",lookahead:"lookahead",lookbehind:"lookbehind"},$e=new Map([["a",7],["b",8],["e",27],["f",12],["n",10],["r",13],["t",9],["v",11]]),Pe="c.? | C(?:-.?)?",Te=f`[pP]\{(?:\^?[\x20\w]+\})?`,Le=f`u\{[^\}]*\}? | u\p{AHex}{0,4} | x\p{AHex}{0,2}`,ve=f`\d{1,3}`,Re=f`\[\^?\]?`,De=/[?*+][?+]?|\{\d+(?:,\d*)?\}\??/,q=new RegExp(f` \\ (?: ${Pe} | ${Te} @@ -31,9 +31,9 @@ var OnigurumaToES=(()=>{var te=Object.defineProperty;var Ct=Object.getOwnPropert | ${Re} | && | . -`.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=Nt(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===x.capturing?(i++,u.number=i):u.raw==="("&&a.push(u))}),i||a.forEach((u,p)=>{u.kind=x.capturing,u.number=p+1});let c=i||a.length;return n=n.map(u=>u.type===g.EscapedNumber?Dt(u,c):u).flat(),{tokens:n,flags:{ignoreCase:t.includes("i"),dotAll:t.includes("m"),extended:t.includes("x")}}}function Nt(e,t,r,s){let[n,o,a]=r;if(n==="["){let i=$t(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:K.keep})}:"RX".includes(o)?{token:m(g.VariableLengthCharacterSet,r,{kind:r})}:{token:Ue(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:Pt(r,e)};if(e.pushModX(e.getCurrentModX()),r==="("||r==="(?:")return{token:m(g.GroupOpen,r,{kind:x.group})};if(r==="(?>")return{token:m(g.GroupOpen,r,{kind:x.atomic})};if(r==="(?="||r==="(?!"||r==="(?<="||r==="(?\^?)(?[a-z]+):\]/.exec(e);if(!t||!W.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 Ue(e,{inCharClass:t}){let r=e[1];if(r==="c"||r==="C")return Ft(e);if("dDhHsSwW".includes(r))return Lt(e);if(/^\\[pP]\{/.test(e)){if(e.length===3)throw new Error("Incomplete or invalid Unicode property");return vt(e)}if(r==="u"||r==="x")return m(g.Character,e,{value:Rt(e)});if($e.has(r))return m(g.Character,e,{value:$e.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-code "${e}"`);if(e.length===2)return m(g.Character,e,{value:e.codePointAt(1)});throw new Error(`Invalid multibyte 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 Pt(e,t){let{on:r,off:s}=/^\(\?(?[imx]*)(?:-(?[imx\-]*))?/.exec(e).groups;s??="";let n=(t.getCurrentModX()||r.includes("x"))&&!s.includes("x"),o=Ie(r),a=Ie(s),i={};if(o&&(i.enable=o),a&&(i.disable=a),e.endsWith(")"))return t.replaceCurrentModX(n),m(g.Directive,e,{kind:K.flags,flags:i});if(e.endsWith(":")){t.pushModX(n);let c=m(g.GroupOpen,e,{kind:x.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 Lt(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 vt(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 Rt(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 o=[],a=n.match(/^[0-7]+|\d/g);for(let i=0;i!!r[k]),w=d&&r[d],T=typeof w=="function"?w:w?.enter,_=w?.exit;if(T?.(C,t),!h)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:R(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 _?.(C,t),p}o(e.node,e.parent,e.key,e.container)}function Ut(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"},Me={AnyGroup:"AnyGroup",AnyNode:"AnyNode"};function Oe(e){let{type:t}=e,r=[Me.AnyNode];return(R(e)||t===l.CapturingGroup||t===l.Group)&&r.push(Me.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"},y=S,D=K,z={grapheme:"grapheme",newline:"newline"};function G({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,d){let w=e[n.current];switch(n.parent=C,n.token=w,n.current++,w.type){case g.Alternator:return F();case g.Assertion:return je(w);case g.Backreference:return Gt(n);case g.Character:return Ke(w.value);case g.CharacterClassHyphen:return Ot(n,d);case g.CharacterClassOpen:return Mt(n,d);case g.CharacterSet:return Bt(n);case g.Directive:return qt(w);case g.GroupOpen:return Vt(n,d);case g.Quantifier:return jt(n);case g.Subroutine:return Kt(n);case g.VariableLengthCharacterSet:return tr(w.kind);default:throw new Error(`Unexpected token type "${w.type}"`)}}let a=Yt(Jt(),Xt(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 $({node:a},null,{AnyNode({node:C,parent:d}){C.parent=d}}),a}function Gt(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,X(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 X(s)}return n(+s)}function Ot(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(),Wt(o,i);throw new Error("Invalid character class range")}return Ke(45)}function Mt(e,t){let{token:r,tokens:s,optimize:n,walk:o}=e,a=le({negate:r.negate}),i=a.elements[0],c=Be(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=Be(s[e.current])}if(n&&ar(i),i.classes.length===1){let u=i.classes[0];u.negate=a.negate!==u.negate,a=u}return e.current++,a}function Bt({token:e,bypassPropertyNameCheck:t}){let{kind:r,negate:s,value:n}=e;if(r===S.property){let a=j(n);if(Ne.has(a))r=S.posix,n=a;else return fe(n,{negate:s,allowAnyName:t})}let o={type:l.CharacterSet,kind:N(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 Vt(e,t){let{token:r,tokens:s,optimize:n,capturingGroups:o,namedGroupsByName:a,walk:i}=e,c=zt(r);c.type===l.CapturingGroup&&(o.push(c),c.name&&v(a,c.name,[]).push(c));let u=Ve(s[e.current]);for(;u.type!==g.GroupClose;){if(u.type===g.Alternator)c.alternatives.push(F()),e.current++;else{let p=c.alternatives.at(-1);t.isInLookbehind||=c.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")}u=Ve(s[e.current])}return n&&(c=nr(c)),e.current++,c}function jt({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=Zt(a,r,s,n,o);return t.elements.pop(),i}function Kt(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=er(n);return s.push(a),a}function F(){return{type:l.Alternative,elements:[]}}function je({type:e,kind:t,negate:r}){if(e===g.GroupOpen)return pe({behind:t===x.lookbehind,negate:r});let s=N({"^":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 X(e){return{type:l.Backreference,ref:e}}function zt(e){let{kind:t,number:r,name:s,flags:n}=e;switch(t){case x.atomic:return I({atomic:!0});case x.capturing:return Ht(r,s);case x.group:return I({flags:n});case x.lookahead:case x.lookbehind:return je(e);default:throw new Error(`Unexpected group kind "${t}"`)}}function Ht(e,t){let r=t!==void 0;if(r&&!sr(t))throw new Error(`Group name "${t}" invalid in Oniguruma`);return{type:l.CapturingGroup,number:e,...r&&{name:t},alternatives:[F()]}}function Ke(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 Wt(e,t){if(t.values[0].toUpperCase()+s.slice(1).toLowerCase())}function nr(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 R({type:e,kind:t}){return e===l.Assertion&&(t===E.lookahead||t===E.lookbehind)}function sr(e){return!/^(?:[-\d]|$)/.test(e)}function ar(e){for(let t=0;to.kind===D.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===D.flags?-1:n.kind===D.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;if(a.type===l.Quantifier){let i=H(I(),[r.element]);i.parent=r,r.element=i}else if(a.type===l.Assertion){let i=R(a);if(!r.min&&i){let c=F();c.parent=a,a.alternatives.push(c)}r.min||i?(n(a),he(a,e,t,ge),o()):(s(),o())}},VariableLengthCharacterSet({node:e,replaceWith:t},{allowBestEffort:r,minTargetEs2024:s}){let{kind:n}=e;if(n===z.newline)t(P(f`(?>\r\n?|[\n\v\f\x85\u2028\u2029])`));else if(n===z.grapheme){if(!r)throw new Error(f`Use of "\X" requires option allowBestEffort`);let o=s?f`\p{RGI_Emoji}`:be().source;t(P(f`(?>\r\n|${o}|\P{M}\p{M}*)`,{bypassPropertyNameCheck:!0}))}else throw new Error(`Unexpected varcharset kind "${n}"`)}},He={Alternative({node:e},{namedGroupsInScopeByAlt:t}){let r=J(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,h=u??p,C=s.get(e),d=c.has(h)||i.has(C),w=d&&!c.size;if(d&&!w)throw new Error("Unsupported indirect recursion");if(C?c.add(h):i.add(e),w){t(ze(h)),r();return}let T=v(o,h,[]);for(let _=0;_p.type===l.Group&&!!p.flags));u&&(c=H(I({flags:u}),[i]))}s(c),a||he(c,e,t,He)}},or={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=>Z(F(),[X(o.number)]));t(Z(I(),n))}else e.ref=s[0].number}};function Z(e,t){return t.forEach(r=>r.parent=e),e[We(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 ir(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 J(e){for(;e=e.parent;)if(e.type===l.Alternative)return e;return null}function cr(e){return/^[$_\p{IDS}][$\u200C\u200D\p{IDC}]*$/u.test(e)}function P(e,{bypassPropertyNameCheck:t}={}){let s=G(U(e),{bypassPropertyNameCheck:t}).pattern.alternatives;return s.length>1||s[0].elements.length>1?Z(I(),s):s[0].elements[0]}function H(e,t){let r=We(e);return e[r][0].parent=e,t&&Z(e[r][0],t),e}function he(e,{parent:t,key:r,container:s},n,o){$({node:e,parent:t,key:r,container:s},n,o)}function Je(e,t){let r=Ce(t),s=V(r.target,"ES2024"),n=V(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 d=[e.flags.ignoreCase];$({node:e},{getCurrentModI:()=>d.at(-1),popModI(){d.pop()},pushModI(w){d.push(w)},setHasCasedChar(){d.at(-1)?a=!0:i=!0}},ur)}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 h(d){switch(p.lastNode=u,u=d,d.type){case l.Regex:return{pattern:h(d.pattern),flags:h(d.flags),options:{...d.options}};case l.Alternative:return d.elements.map(h).join("");case l.Assertion:return hr(d,p,h);case l.Backreference:return dr(d,p);case l.CapturingGroup:return Cr(d,p,h);case l.Character:return mr(d,p);case l.CharacterClass:return Er(d,p,h);case l.CharacterClassIntersection:if(!p.useFlagV)throw new Error("Use of class intersection requires target ES2024 or later");return d.classes.map(h).join("&&");case l.CharacterClassRange:return wr(d,p);case l.CharacterSet:return Ar(d,p);case l.Flags:return Sr(d,p);case l.Group:return _r(d,p,h);case l.Pattern:return d.alternatives.map(h).join("|");case l.Quantifier:return h(d.element)+yr(d);case l.Recursion:return kr(d,p);default:throw new Error(`Unexpected node type "${d.type}"`)}}let C=h(e);return s||(delete C.options.force.v,C.options.disable.v=!0,C.options.unicodeSetsPlugin=null),C}var ur={AnyGroup:{enter({node:e},t){let r=t.getCurrentModI();t.pushModI(e.flags?Ye({ignoreCase:r},e.flags).ignoreCase:r)},exit(e,t){t.popModI()}},Backreference(e,t){t.setHasCasedChar()},Character({node:e},t){de(A(e.value))&&t.setHasCasedChar()},CharacterClassRange({node:e,skip:t},r){t(),Ze(e,{firstOnly:!0}).length&&r.setHasCasedChar()},CharacterSet({node:e},t){e.kind===y.property&&ce.has(e.value)&&t.setHasCasedChar()}},lr=new Set(["$","(",")","*","+",".","?","[","\\","]","^","{","|","}"]),pr=new Set(["-","\\","]","^"]),fr=new Set(["(",")","-","/","[","\\","]","^","{","|","}","!","#","$","%","&","*","+",",",".",":",";","<","=",">","?","@","`","~"]),Xe=new Map([[9,f`\t`],[10,f`\n`],[11,f`\v`],[12,f`\f`],[13,f`\r`],[8232,f`\u2028`],[8233,f`\u2029`]]),gr=/^\p{Cased}$/u;function de(e){return gr.test(e)}function hr(e,t,r){let{kind:s,negate:n,alternatives:o}=e;if(R(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 dr({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 Cr({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 mr({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&&de(r)){let n=se(r);return t.inCharClass?n.join(""):n.length>1?`[${n.join("")}]`:n[0]}return r}function Er({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 wr(e,t){let r=e.min.value,s=e.max.value,n={isAfterBackref:!1,inCharClass:!0,useFlagV:t.useFlagV},o=O(r,n),a=O(s,n),i="";if(t.useAppliedIgnoreCase&&t.currentFlags.ignoreCase){let c=Ze(e);xr(c).forEach(p=>{i+=Array.isArray(p)?`${O(p[0],n)}-${O(p[1],n)}`:O(p,n)})}return`${o}-${a}${i}`}function Ar({kind:e,negate:t,value:r,key:s},n){if(e===y.any)return n.currentFlags.dotAll?n.appliedGlobalFlags.dotAll||n.useFlagMods?".":"[^]":f`[^\n]`;if(e===y.digit)return t?f`\D`:f`\d`;if(e===y.property){if(!n.usePostEs2018Properties&&ye.has(r))throw new Error(`Unicode property "${r}" unavailable in target ES2018`);if(n.useAppliedIgnoreCase&&n.currentFlags.ignoreCase&&ce.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===y.word)return t?f`\W`:f`\w`;throw new Error(`Unexpected character set kind "${e}"`)}function Sr(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=Ye(a,t));let i=s.map(o).join("|"),c=n.optimize&&s.length===1&&r.type!==l.Quantifier&&!e&&(!n.useFlagMods||!t)?i:`(?${br(e,t,n.useFlagMods)}${i})`;return n.currentFlags=a,c}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 Ze(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(!de(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 O(e,{isAfterBackref:t,inCharClass:r,useFlagV:s}){if(Xe.has(e))return Xe.get(e);if(e<32||e>126&&e<160||e>262143||t&&Nr(e))return e>255?f`\u{${e.toString(16).toUpperCase()}}`:f`\x${e.toString(16).toUpperCase().padStart(2,"0")}`;let n=r?s?fr:pr:lr,o=A(e);return(n.has(o)?"\\":"")+o}function xr(e){let t=e.map(n=>n.codePointAt(0)).sort((n,o)=>n-o),r=[],s=null;for(let n=0;n";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 Ye(e,{enable:t,disable:r}){return{dotAll:!r?.dotAll&&!!(t?.dotAll||e.dotAll),ignoreCase:!r?.ignoreCase&&!!(t?.ignoreCase||e.ignoreCase)}}function yr({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 b=Object.freeze({DEFAULT:"DEFAULT",CHAR_CLASS:"CHAR_CLASS"});function M(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===b.DEFAULT==!a)){r instanceof Function?i+=r(c,{context:a?b.CHAR_CLASS:b.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 me(e,t,r,s){M(e,t,r,s)}function $r(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===b.DEFAULT==!o))return a;i==="["?o++:i==="]"&&o&&o--,n.lastIndex==a.index&&n.lastIndex++}return null}function B(e,t,r){return!!$r(e,t,0,r)}function et(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 tt={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"},Ee={DEFAULT:"DEFAULT",ENCLOSED_P:"ENCLOSED_P",ENCLOSED_Q:"ENCLOSED_Q",ENCLOSED_U:"ENCLOSED_U",INVALID_INCOMPLETE_TOKEN:"INVALID_INCOMPLETE_TOKEN",RANGE:"RANGE"},mn=new Set([tt.ENCLOSED_P,tt.ENCLOSED_U]),En=new Set([Ee.ENCLOSED_P,Ee.ENCLOSED_Q,Ee.ENCLOSED_U]),wn=(()=>{try{new RegExp("(?i:)")}catch{return!1}return!0})(),An=(()=>{try{new RegExp("","v")}catch{return!1}return!0})(),rt="$E$";var Ir=String.raw`\(\?<(?![=!])(?[^>]+)>`,Sn=String.raw`\((?!\?)(?!(?<=\(\?\()DEFINE\))|${Ir}`,nt=String.raw`\(\?(?:[:=!>A-Za-z\-]|<[=!]|\(DEFINE\))`;var Fr=["Basic_Emoji","Emoji_Keycap_Sequence","RGI_Emoji_Modifier_Sequence","RGI_Emoji_Flag_Sequence","RGI_Emoji_Tag_Sequence","RGI_Emoji_ZWJ_Sequence","RGI_Emoji"].join("|"),_n=new RegExp(String.raw` +`.replace(/\s+/g,""),"gsu");function U(e,t=""){if(typeof e!="string")throw new Error("String expected as pattern");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=Nt(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===x.capturing?(i++,u.number=i):u.raw==="("&&a.push(u))}),i||a.forEach((u,p)=>{u.kind=x.capturing,u.number=p+1});let c=i||a.length;return n=n.map(u=>u.type===g.EscapedNumber?Dt(u,c):u).flat(),{tokens:n,flags:{ignoreCase:t.includes("i"),dotAll:t.includes("m"),extended:t.includes("x")}}}function Nt(e,t,r,s){let[n,o,a]=r;if(n==="["){let i=$t(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:K.keep})}:"RX".includes(o)?{token:m(g.VariableLengthCharacterSet,r,{kind:r})}:{token:Ue(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:Pt(r,e)};if(e.pushModX(e.getCurrentModX()),r==="("||r==="(?:")return{token:m(g.GroupOpen,r,{kind:x.group})};if(r==="(?>")return{token:m(g.GroupOpen,r,{kind:x.atomic})};if(r==="(?="||r==="(?!"||r==="(?<="||r==="(?\^?)(?[a-z]+):\]/.exec(e);if(!t||!W.get(t.groups.name))throw new Error(`Invalid POSIX class "${e}"`);return m(g.CharacterSet,e,{kind:A.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 Ue(e,{inCharClass:t}){let r=e[1];if(r==="c"||r==="C")return Ft(e);if("dDhHsSwW".includes(r))return Lt(e);if(/^\\[pP]\{/.test(e)){if(e.length===3)throw new Error("Incomplete or invalid Unicode property");return vt(e)}if(r==="u"||r==="x")return m(g.Character,e,{value:Rt(e)});if($e.has(r))return m(g.Character,e,{value:$e.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-code "${e}"`);if(e.length===2)return m(g.Character,e,{value:e.codePointAt(1)});throw new Error(`Invalid multibyte 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 Pt(e,t){let{on:r,off:s}=/^\(\?(?[imx]*)(?:-(?[imx\-]*))?/.exec(e).groups;s??="";let n=(t.getCurrentModX()||r.includes("x"))&&!s.includes("x"),o=Ie(r),a=Ie(s),i={};if(o&&(i.enable=o),a&&(i.disable=a),e.endsWith(")"))return t.replaceCurrentModX(n),m(g.Directive,e,{kind:K.flags,flags:i});if(e.endsWith(":")){t.pushModX(n);let c=m(g.GroupOpen,e,{kind:x.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 Lt(e){let t=e[1].toLowerCase();return m(g.CharacterSet,e,{kind:{d:A.digit,h:A.hex,s:A.space,w:A.word}[t],negate:e[1]!==t})}function vt(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:A.property,negate:n,value:s})}function Rt(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 o=[],a=n.match(/^[0-7]+|\d/g);for(let i=0;i!!r[k]),w=d&&r[d],T=typeof w=="function"?w:w?.enter,_=w?.exit;if(T?.(C,t),!h)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:R(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 _?.(C,t),p}o(e.node,e.parent,e.key,e.container)}function Ut(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"},Me={AnyGroup:"AnyGroup",AnyNode:"AnyNode"};function Oe(e){let{type:t}=e,r=[Me.AnyNode];return(R(e)||t===l.CapturingGroup||t===l.Group)&&r.push(Me.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"},y=A,D=K,z={grapheme:"grapheme",newline:"newline"};function G({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,d){let w=e[n.current];switch(n.parent=C,n.token=w,n.current++,w.type){case g.Alternator:return F();case g.Assertion:return je(w);case g.Backreference:return Gt(n);case g.Character:return Ke(w.value);case g.CharacterClassHyphen:return Ot(n,d);case g.CharacterClassOpen:return Mt(n,d);case g.CharacterSet:return Bt(n);case g.Directive:return qt(w);case g.GroupOpen:return Vt(n,d);case g.Quantifier:return jt(n);case g.Subroutine:return Kt(n);case g.VariableLengthCharacterSet:return tr(w.kind);default:throw new Error(`Unexpected token type "${w.type}"`)}}let a=Yt(Jt(),Xt(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 $({node:a},null,{AnyNode({node:C,parent:d}){C.parent=d}}),a}function Gt(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,X(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 X(s)}return n(+s)}function Ot(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(),Wt(o,i);throw new Error("Invalid character class range")}return Ke(45)}function Mt(e,t){let{token:r,tokens:s,optimize:n,walk:o}=e,a=le({negate:r.negate}),i=a.elements[0],c=Be(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=Be(s[e.current])}if(n&&ar(i),i.classes.length===1){let u=i.classes[0];u.negate=a.negate!==u.negate,a=u}return e.current++,a}function Bt({token:e,bypassPropertyNameCheck:t}){let{kind:r,negate:s,value:n}=e;if(r===A.property){let a=j(n);if(Ne.has(a))r=A.posix,n=a;else return fe(n,{negate:s,allowAnyName:t})}let o={type:l.CharacterSet,kind:N(y[r],`Unexpected character set kind "${r}"`)};return(r===A.digit||r===A.hex||r===A.posix||r===A.space||r===A.word)&&(o.negate=s,r===A.posix&&(o.value=n)),o}function Vt(e,t){let{token:r,tokens:s,optimize:n,capturingGroups:o,namedGroupsByName:a,walk:i}=e,c=zt(r);c.type===l.CapturingGroup&&(o.push(c),c.name&&v(a,c.name,[]).push(c));let u=Ve(s[e.current]);for(;u.type!==g.GroupClose;){if(u.type===g.Alternator)c.alternatives.push(F()),e.current++;else{let p=c.alternatives.at(-1);t.isInLookbehind||=c.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")}u=Ve(s[e.current])}return n&&(c=nr(c)),e.current++,c}function jt({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=Zt(a,r,s,n,o);return t.elements.pop(),i}function Kt(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=er(n);return s.push(a),a}function F(){return{type:l.Alternative,elements:[]}}function je({type:e,kind:t,negate:r}){if(e===g.GroupOpen)return pe({behind:t===x.lookbehind,negate:r});let s=N({"^":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 X(e){return{type:l.Backreference,ref:e}}function zt(e){let{kind:t,number:r,name:s,flags:n}=e;switch(t){case x.atomic:return I({atomic:!0});case x.capturing:return Ht(r,s);case x.group:return I({flags:n});case x.lookahead:case x.lookbehind:return je(e);default:throw new Error(`Unexpected group kind "${t}"`)}}function Ht(e,t){let r=t!==void 0;if(r&&!sr(t))throw new Error(`Group name "${t}" invalid in Oniguruma`);return{type:l.CapturingGroup,number:e,...r&&{name:t},alternatives:[F()]}}function Ke(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 Wt(e,t){if(t.values[0].toUpperCase()+s.slice(1).toLowerCase())}function nr(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 R({type:e,kind:t}){return e===l.Assertion&&(t===E.lookahead||t===E.lookbehind)}function sr(e){return!/^(?:[-\d]|$)/.test(e)}function ar(e){for(let t=0;to.kind===D.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===D.flags?-1:n.kind===D.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;if(a.type===l.Quantifier){let i=H(I(),[r.element]);i.parent=r,r.element=i}else if(a.type===l.Assertion){let i=R(a);if(!r.min&&i){let c=F();c.parent=a,a.alternatives.push(c)}r.min||i?(n(a),he(a,e,t,ge),o()):(s(),o())}},VariableLengthCharacterSet({node:e,replaceWith:t},{allowBestEffort:r,minTargetEs2024:s}){let{kind:n}=e;if(n===z.newline)t(P(f`(?>\r\n?|[\n\v\f\x85\u2028\u2029])`));else if(n===z.grapheme){if(!r)throw new Error(f`Use of "\X" requires option allowBestEffort`);let o=s?f`\p{RGI_Emoji}`:be().source;t(P(f`(?>\r\n|${o}|\P{M}\p{M}*)`,{bypassPropertyNameCheck:!0}))}else throw new Error(`Unexpected varcharset kind "${n}"`)}},He={Alternative({node:e},{namedGroupsInScopeByAlt:t}){let r=J(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,h=u??p,C=s.get(e),d=c.has(h)||i.has(C),w=d&&!c.size;if(d&&!w)throw new Error("Unsupported indirect recursion");if(C?c.add(h):i.add(e),w){t(ze(h)),r();return}let T=v(o,h,[]);for(let _=0;_p.type===l.Group&&!!p.flags));u&&(c=H(I({flags:u}),[i]))}s(c),a||he(c,e,t,He)}},or={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=>Z(F(),[X(o.number)]));t(Z(I(),n))}else e.ref=s[0].number}};function Z(e,t){return t.forEach(r=>r.parent=e),e[We(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 ir(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 J(e){for(;e=e.parent;)if(e.type===l.Alternative)return e;return null}function cr(e){return/^[$_\p{IDS}][$\u200C\u200D\p{IDC}]*$/u.test(e)}function P(e,{bypassPropertyNameCheck:t}={}){let s=G(U(e),{bypassPropertyNameCheck:t}).pattern.alternatives;return s.length>1||s[0].elements.length>1?Z(I(),s):s[0].elements[0]}function H(e,t){let r=We(e);return e[r][0].parent=e,t&&Z(e[r][0],t),e}function he(e,{parent:t,key:r,container:s},n,o){$({node:e,parent:t,key:r,container:s},n,o)}function Je(e,t){let r=Ce(t),s=V(r.target,"ES2024"),n=V(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 d=[e.flags.ignoreCase];$({node:e},{getCurrentModI:()=>d.at(-1),popModI(){d.pop()},pushModI(w){d.push(w)},setHasCasedChar(){d.at(-1)?a=!0:i=!0}},ur)}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 h(d){switch(p.lastNode=u,u=d,d.type){case l.Regex:return{pattern:h(d.pattern),flags:h(d.flags),options:{...d.options}};case l.Alternative:return d.elements.map(h).join("");case l.Assertion:return hr(d,p,h);case l.Backreference:return dr(d,p);case l.CapturingGroup:return Cr(d,p,h);case l.Character:return mr(d,p);case l.CharacterClass:return Er(d,p,h);case l.CharacterClassIntersection:if(!p.useFlagV)throw new Error("Use of class intersection requires target ES2024 or later");return d.classes.map(h).join("&&");case l.CharacterClassRange:return wr(d,p);case l.CharacterSet:return Sr(d,p);case l.Flags:return Ar(d,p);case l.Group:return _r(d,p,h);case l.Pattern:return d.alternatives.map(h).join("|");case l.Quantifier:return h(d.element)+yr(d);case l.Recursion:return kr(d,p);default:throw new Error(`Unexpected node type "${d.type}"`)}}let C=h(e);return s||(delete C.options.force.v,C.options.disable.v=!0,C.options.unicodeSetsPlugin=null),C}var ur={AnyGroup:{enter({node:e},t){let r=t.getCurrentModI();t.pushModI(e.flags?Ye({ignoreCase:r},e.flags).ignoreCase:r)},exit(e,t){t.popModI()}},Backreference(e,t){t.setHasCasedChar()},Character({node:e},t){de(S(e.value))&&t.setHasCasedChar()},CharacterClassRange({node:e,skip:t},r){t(),Ze(e,{firstOnly:!0}).length&&r.setHasCasedChar()},CharacterSet({node:e},t){e.kind===y.property&&ce.has(e.value)&&t.setHasCasedChar()}},lr=new Set(["$","(",")","*","+",".","?","[","\\","]","^","{","|","}"]),pr=new Set(["-","\\","]","^"]),fr=new Set(["(",")","-","/","[","\\","]","^","{","|","}","!","#","$","%","&","*","+",",",".",":",";","<","=",">","?","@","`","~"]),Xe=new Map([[9,f`\t`],[10,f`\n`],[11,f`\v`],[12,f`\f`],[13,f`\r`],[8232,f`\u2028`],[8233,f`\u2029`]]),gr=/^\p{Cased}$/u;function de(e){return gr.test(e)}function hr(e,t,r){let{kind:s,negate:n,alternatives:o}=e;if(R(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 dr({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 Cr({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 mr({value:e},t){let r=S(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&&de(r)){let n=se(r);return t.inCharClass?n.join(""):n.length>1?`[${n.join("")}]`:n[0]}return r}function Er({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 wr(e,t){let r=e.min.value,s=e.max.value,n={isAfterBackref:!1,inCharClass:!0,useFlagV:t.useFlagV},o=O(r,n),a=O(s,n),i="";if(t.useAppliedIgnoreCase&&t.currentFlags.ignoreCase){let c=Ze(e);xr(c).forEach(p=>{i+=Array.isArray(p)?`${O(p[0],n)}-${O(p[1],n)}`:O(p,n)})}return`${o}-${a}${i}`}function Sr({kind:e,negate:t,value:r,key:s},n){if(e===y.any)return n.currentFlags.dotAll?n.appliedGlobalFlags.dotAll||n.useFlagMods?".":"[^]":f`[^\n]`;if(e===y.digit)return t?f`\D`:f`\d`;if(e===y.property){if(!n.usePostEs2018Properties&&ye.has(r))throw new Error(`Unicode property "${r}" unavailable in target ES2018`);if(n.useAppliedIgnoreCase&&n.currentFlags.ignoreCase&&ce.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===y.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 _r({atomic:e,flags:t,parent:r,alternatives:s},n,o){let a=n.currentFlags;t&&(n.currentFlags=Ye(a,t));let i=s.map(o).join("|"),c=n.optimize&&s.length===1&&r.type!==l.Quantifier&&!e&&(!n.useFlagMods||!t)?i:`(?${br(e,t,n.useFlagMods)}${i})`;return n.currentFlags=a,c}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 Ze(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=S(o);if(!de(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 O(e,{isAfterBackref:t,inCharClass:r,useFlagV:s}){if(Xe.has(e))return Xe.get(e);if(e<32||e>126&&e<160||e>262143||t&&Nr(e))return e>255?f`\u{${e.toString(16).toUpperCase()}}`:f`\x${e.toString(16).toUpperCase().padStart(2,"0")}`;let n=r?s?fr:pr:lr,o=S(e);return(n.has(o)?"\\":"")+o}function xr(e){let t=e.map(n=>n.codePointAt(0)).sort((n,o)=>n-o),r=[],s=null;for(let n=0;n";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 Ye(e,{enable:t,disable:r}){return{dotAll:!r?.dotAll&&!!(t?.dotAll||e.dotAll),ignoreCase:!r?.ignoreCase&&!!(t?.ignoreCase||e.ignoreCase)}}function yr({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 b=Object.freeze({DEFAULT:"DEFAULT",CHAR_CLASS:"CHAR_CLASS"});function M(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===b.DEFAULT==!a)){r instanceof Function?i+=r(c,{context:a?b.CHAR_CLASS:b.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 me(e,t,r,s){M(e,t,r,s)}function $r(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===b.DEFAULT==!o))return a;i==="["?o++:i==="]"&&o&&o--,n.lastIndex==a.index&&n.lastIndex++}return null}function B(e,t,r){return!!$r(e,t,0,r)}function et(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 tt={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"},Ee={DEFAULT:"DEFAULT",ENCLOSED_P:"ENCLOSED_P",ENCLOSED_Q:"ENCLOSED_Q",ENCLOSED_U:"ENCLOSED_U",INVALID_INCOMPLETE_TOKEN:"INVALID_INCOMPLETE_TOKEN",RANGE:"RANGE"},mn=new Set([tt.ENCLOSED_P,tt.ENCLOSED_U]),En=new Set([Ee.ENCLOSED_P,Ee.ENCLOSED_Q,Ee.ENCLOSED_U]),wn=(()=>{try{new RegExp("(?i:)")}catch{return!1}return!0})(),Sn=(()=>{try{new RegExp("","v")}catch{return!1}return!0})(),rt="$E$";var Ir=String.raw`\(\?<(?![=!])(?[^>]+)>`,An=String.raw`\((?!\?)(?!(?<=\(\?\()DEFINE\))|${Ir}`,nt=String.raw`\(\?(?:[:=!>A-Za-z\-]|<[=!]|\(DEFINE\))`;var Fr=["Basic_Emoji","Emoji_Keycap_Sequence","RGI_Emoji_Modifier_Sequence","RGI_Emoji_Flag_Sequence","RGI_Emoji_Tag_Sequence","RGI_Emoji_ZWJ_Sequence","RGI_Emoji"].join("|"),_n=new RegExp(String.raw` \\(?: c[A-Za-z] | p\{(?${Fr})\} | [pP]\{[^\}]+\} @@ -73,5 +73,5 @@ var OnigurumaToES=(()=>{var te=Object.defineProperty;var Ct=Object.getOwnPropert ))? | (?${it})(?[?+]?)(?[?*+\{]?) | \\?. -`.replace(/\s+/g,""),"gsu");function ct(e){if(!new RegExp(`${it}\\+`).test(e))return e;let t=[],r=null,s=null,n="",o=0,a;for(we.lastIndex=0;a=we.exec(e);){let{0:i,index:c,groups:{qBase:u,qMod:p,invalidQ:h}}=a;if(i==="[")o||(s=c),o++;else if(i==="]")o?o--:s=null;else if(!o)if(p==="+"&&n&&!n.startsWith("(")){if(h)throw new Error(`Invalid quantifier "${i}"`);let C=-1;if(/^\{\d+\}$/.test(u))e=st(e,c+u.length,p,"");else{if(n===")"||n==="]"){let d=n===")"?r:s;if(d===null)throw new Error(`Invalid unmatched "${n}"`);e=`${e.slice(0,d)}(?>${e.slice(d,c)}${u})${e.slice(c+i.length)}`}else e=`${e.slice(0,c-n.length)}(?>${n}${u})${e.slice(c+i.length)}`;C+=4}we.lastIndex+=C}else i[0]==="("?t.push(c):i===")"&&(r=t.length?t.pop():null);n=i}return e}var gt=String.raw`\\g<(?[^>&]+)&R=(?\d+)>`,Ae=String.raw`\(\?R=(?\d+)\)|${gt}`,Se=String.raw`\(\?<(?![=!])(?[^>]+)>`,ee=new RegExp(String.raw`${Se}|${Ae}|\\?.`,"gsu");function ht(e){if(!B(e,Ae,b.DEFAULT))return e;if(B(e,String.raw`\\[1-9]`,b.DEFAULT))throw new Error("Numbered backrefs cannot be used with recursion; use named backref");if(B(e,String.raw`\(\?\(DEFINE\)`,b.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;ut(u);let p=e.slice(0,s.index),h=e.slice(ee.lastIndex);return lt(h),pt(p,h,u,!1)}else if(i){let u=+c;ut(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 h=t.get(i),C=et(e,h);if(!B(C,gt,b.DEFAULT))throw new Error(p);let d=e.slice(h,s.index),w=C.slice(d.length+n.length);return lt(w),e.slice(0,h)+pt(d,w,u,!0)+e.slice(h+C.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 lt(e){if(B(e,Ae,b.DEFAULT))throw new Error("Recursion can only be used once per regex")}function pt(e,t,r,s){let n=new Set;s&&me(e+t,Se,({groups:{captureName:a}})=>{n.add(a)},b.DEFAULT);let o=r-1;return`${e}${ft(`(?:${e}`,o,s?n:null)}(?:)${ft(`${t})`,o,s?n:null,"backward")}${t}`}function ft(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:h}})=>{if(h&&r&&!r.has(h))return u;let C=`_$${c}`;return p?`(?<${p}${C}>`:`\\k<${h}${C}>`},b.DEFAULT)}return a}function _e(e,t,r){let s=Ce(r),n=U(e,t),o=G(n,{optimize:s.optimize}),a=Y(o,{allowBestEffort:s.allowBestEffort,bestEffortTarget:s.target}),i=Je(a,s);return{pattern:ot(ct(ht(i.pattern))),flags:`${i.flags}${i.options.disable.v?"u":"v"}`}}function Ce(e){if(e?.target!==void 0&&!Q[e.target])throw new Error(`Unexpected target "${e.target}"`);return{allowBestEffort:!0,maxRecursionDepth:6,optimize:!0,target:"ES2024",...e}}function dt(e,t){return G(U(e,t))}function Pr(e,t){return Y(dt(e,t))}function Tr(e,t="",r){let s=t.replace(/[^dg]+/g,"");t=t.replace(/[dg]+/g,"");let n=_e(e,t,r);return new RegExp(n.pattern,`${s}${n.flags}`)}return St(Lr);})(); +`.replace(/\s+/g,""),"gsu");function ct(e){if(!new RegExp(`${it}\\+`).test(e))return e;let t=[],r=null,s=null,n="",o=0,a;for(we.lastIndex=0;a=we.exec(e);){let{0:i,index:c,groups:{qBase:u,qMod:p,invalidQ:h}}=a;if(i==="[")o||(s=c),o++;else if(i==="]")o?o--:s=null;else if(!o)if(p==="+"&&n&&!n.startsWith("(")){if(h)throw new Error(`Invalid quantifier "${i}"`);let C=-1;if(/^\{\d+\}$/.test(u))e=st(e,c+u.length,p,"");else{if(n===")"||n==="]"){let d=n===")"?r:s;if(d===null)throw new Error(`Invalid unmatched "${n}"`);e=`${e.slice(0,d)}(?>${e.slice(d,c)}${u})${e.slice(c+i.length)}`}else e=`${e.slice(0,c-n.length)}(?>${n}${u})${e.slice(c+i.length)}`;C+=4}we.lastIndex+=C}else i[0]==="("?t.push(c):i===")"&&(r=t.length?t.pop():null);n=i}return e}var gt=String.raw`\\g<(?[^>&]+)&R=(?\d+)>`,Se=String.raw`\(\?R=(?\d+)\)|${gt}`,Ae=String.raw`\(\?<(?![=!])(?[^>]+)>`,ee=new RegExp(String.raw`${Ae}|${Se}|\\?.`,"gsu");function ht(e){if(!B(e,Se,b.DEFAULT))return e;if(B(e,String.raw`\\[1-9]`,b.DEFAULT))throw new Error("Numbered backrefs cannot be used with recursion; use named backref");if(B(e,String.raw`\(\?\(DEFINE\)`,b.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;ut(u);let p=e.slice(0,s.index),h=e.slice(ee.lastIndex);return lt(h),pt(p,h,u,!1)}else if(i){let u=+c;ut(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 h=t.get(i),C=et(e,h);if(!B(C,gt,b.DEFAULT))throw new Error(p);let d=e.slice(h,s.index),w=C.slice(d.length+n.length);return lt(w),e.slice(0,h)+pt(d,w,u,!0)+e.slice(h+C.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 lt(e){if(B(e,Se,b.DEFAULT))throw new Error("Recursion can only be used once per regex")}function pt(e,t,r,s){let n=new Set;s&&me(e+t,Ae,({groups:{captureName:a}})=>{n.add(a)},b.DEFAULT);let o=r-1;return`${e}${ft(`(?:${e}`,o,s?n:null)}(?:)${ft(`${t})`,o,s?n:null,"backward")}${t}`}function ft(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:h}})=>{if(h&&r&&!r.has(h))return u;let C=`_$${c}`;return p?`(?<${p}${C}>`:`\\k<${h}${C}>`},b.DEFAULT)}return a}function _e(e,t,r){let s=Ce(r),n=U(e,t),o=G(n,{optimize:s.optimize}),a=Y(o,{allowBestEffort:s.allowBestEffort,bestEffortTarget:s.target}),i=Je(a,s);return{pattern:ot(ct(ht(i.pattern))),flags:`${i.flags}${i.options.disable.v?"u":"v"}`}}function Ce(e){if(e?.target!==void 0&&!Q[e.target])throw new Error(`Unexpected target "${e.target}"`);return{allowBestEffort:!0,maxRecursionDepth:6,optimize:!0,target:"ES2024",...e}}function dt(e,t){return G(U(e,t))}function Pr(e,t){return Y(dt(e,t))}function Tr(e,t="",r){let s=t.replace(/[^dg]+/g,"");t=t.replace(/[dg]+/g,"");let n=_e(e,t,r);return new RegExp(n.pattern,`${s}${n.flags}`)}return At(Lr);})(); //# sourceMappingURL=index.min.js.map diff --git a/spec/compile.spec.js b/spec/compile.spec.js index 3172e07..77da3d1 100644 --- a/spec/compile.spec.js +++ b/spec/compile.spec.js @@ -2,28 +2,50 @@ import {compile} from '../dist/index.mjs'; describe('compile', () => { it('should return an object with pattern and flags properties', () => { - expect(Object.keys(compile('a'))).toEqual(['pattern', 'flags']); + expect(Object.keys(compile(''))).toEqual(['pattern', 'flags']); }); - it('should return an empty pattern string if given an empty string', () => { + it('should throw for non-string pattern', () => { + expect(() => compile()).toThrow(); + for (const value of [undefined, null, 0, false, [], {}, /(?:)/]) { + expect(() => compile(value)).toThrow(); + } + }); + + it('should return an empty pattern if given an empty string', () => { expect(compile('').pattern).toBe(''); }); - it('should accept supported flags', () => { - const compiled = compile('', 'imx'); - expect(compiled.flags).toContain('i'); - expect(compiled.flags).toContain('s'); - expect(compiled.flags).toContain('v'); - // TODO: More specs + it('should accept and translate supported flags', () => { + expect(compile('', 'i').flags).toContain('i'); + expect(compile('', 'm').flags).toContain('s'); + expect(compile('', 'm').flags).not.toContain('m'); + expect(compile('', 'x').flags).not.toContain('x'); + }); + + it('should throw for unexpected flags', () => { + expect(() => compile('', 'd')).toThrow(); + expect(() => compile('', 'g')).toThrow(); + expect(() => compile('', 's')).toThrow(); + expect(() => compile('', 'u')).toThrow(); + expect(() => compile('', 'v')).toThrow(); + expect(() => compile('', 'y')).toThrow(); + }); + + it('should add flag v if target unspecified', () => { + expect(compile('').flags).toBe('v'); + }); + + it('should add flag v for target ES2024+', () => { + expect(compile('', '', {target: 'ES2024'}).flags).toBe('v'); + expect(compile('', '', {target: 'ESNext'}).flags).toBe('v'); }); - it('should accept supported targets', () => { - expect(compile('', '', {target: 'ES2018'})).toEqual({pattern: '', flags: 'u'}); - expect(compile('', '', {target: 'ES2024'})).toEqual({pattern: '', flags: 'v'}); - expect(compile('', '', {target: 'ESNext'})).toEqual({pattern: '', flags: 'v'}); + it('should add flag u for target ES2018', () => { + expect(compile('', '', {target: 'ES2018'}).flags).toBe('u'); }); - it('should throw for unsupported targets', () => { + it('should throw for unexpected targets', () => { expect(() => compile('', '', {target: 'ES6'})).toThrow(); expect(() => compile('', '', {target: 'ES2019'})).toThrow(); }); diff --git a/spec/match-recursion.spec.js b/spec/match-recursion.spec.js index c82cc77..2243143 100644 --- a/spec/match-recursion.spec.js +++ b/spec/match-recursion.spec.js @@ -7,14 +7,30 @@ beforeEach(() => { }); describe('Recursion', () => { + it('should throw if recursion used with allowBestEffort false', () => { + expect(() => compile(r`a\g<0>?`, '', {allowBestEffort: false})).toThrow(); + expect(() => compile('', '', {allowBestEffort: false})).not.toThrow(); + }); + + it('should throw if recursion used with maxRecursionDepth null', () => { + expect(() => compile(r`a\g<0>?`, '', {maxRecursionDepth: null})).toThrow(); + expect(() => compile('', '', {maxRecursionDepth: null})).not.toThrow(); + }); + + it('should throw if maxRecursionDepth is not null or a positive-integer in range 2-100', () => { + for (const value of [-2, 0, 1, 2.5, 101, Infinity, '2', '', undefined, NaN, false, [], {}]) { + expect(() => compile('', '', {maxRecursionDepth: value})).toThrow(); + } + }); + describe('global', () => { - it('should match an equal number of two different subpatterns', () => { + it('should match direct recursion', () => { + // Match an equal number of two different subpatterns expect('aaabbb').toExactlyMatch(r`a\g<0>?b`); expect('test aaaaaabbb').toFindMatch(r`a\g<0>?b`); expect('aaabbb').toExactlyMatch(r`(?a\g<0>?b)`); - }); - it('should match balanced brackets', () => { + // Match balanced brackets const pattern = r`<(?:[^<>]|\g<0>)*>`; expect([ '<>', '<<>>', 'd>e>', '<<<<<>>bc>>>', @@ -24,7 +40,7 @@ describe('Recursion', () => { ).toEqual(['>>', '<>', '<>', '']); }); - it('should throw for multiple overlapping recursions', () => { + it('should throw for multiple direct, overlapping recursions', () => { expect(() => compile(r`a\g<0>?\g<0>?`)).toThrow(); }); @@ -42,20 +58,21 @@ describe('Recursion', () => { }); describe('relative numbered', () => { - it('should throw for relative 0', () => { - expect(() => compile(r`a\g<-0>?`)).toThrow(); - expect(() => compile(r`a\g<+0>?`)).toThrow(); - }); - // Current limitation of `regex-recursion` it('should throw for recursion by number', () => { expect(() => compile(r`(a\g<-1>?)`)).toThrow(); expect(() => compile(r`(a\g<+1>(\g<-2>?))`)).toThrow(); }); + + it('should throw for relative 0', () => { + expect(() => compile(r`a\g<-0>?`)).toThrow(); + expect(() => compile(r`a\g<+0>?`)).toThrow(); + }); }); describe('named', () => { - it('should match an equal number of two different subpatterns', () => { + it('should match direct recursion', () => { + // Match an equal number of two different subpatterns as the entire string expect('aaabbb').toExactlyMatch(r`\A(?a\g?b)\z`); expect('aaabb').not.toFindMatch(r`\A(?a\g?b)\z`); }); @@ -67,7 +84,7 @@ describe('Recursion', () => { // Current limitation of `regex-recursion` it('should throw for multiple direct, non-overlapping recursions', () => { - // TODO: `regex-recursion` has a bug so using `toRegExp` instead of `compile` + // TODO: `regex-recursion` has a bug and lets invalid JS syntax through so using `toRegExp` instead of `compile` expect(() => toRegExp(r`(?a\g?)(?a\g?)`)).toThrow(); }); diff --git a/src/generate.js b/src/generate.js index a50b94a..21d4f57 100644 --- a/src/generate.js +++ b/src/generate.js @@ -130,7 +130,6 @@ function generate(ast, options) { result.options.disable.v = true; result.options.unicodeSetsPlugin = null; } - // TODO: Include `metadata` (add to type) about use of atomic groups, possessive quantifiers, and recursion, so those plugins can be skipped if not needed return result; } diff --git a/src/index.js b/src/index.js index fa7f2ba..c4ff98d 100644 --- a/src/index.js +++ b/src/index.js @@ -37,7 +37,7 @@ function toRegexAst(pattern, flags) { } /** -Transpiles an Oniguruma regex pattern and flags to a native JS RegExp. +Transpiles an Oniguruma regex pattern and flags and returns a native JS RegExp. @param {string} pattern Oniguruma regex pattern. @param {string} [flags] Any combination of Oniguruma flags `imx` and JS flags `dg`. Flag `m` is equivalent to JS's flag `s`. diff --git a/src/tokenize.js b/src/tokenize.js index 1ca9b2a..b4fc623 100644 --- a/src/tokenize.js +++ b/src/tokenize.js @@ -126,6 +126,9 @@ const charClassTokenRe = new RegExp(r` @returns {TokenizerResult} */ function tokenize(pattern, flags = '') { + if (typeof pattern !== 'string') { + throw new Error('String expected as pattern'); + } if (!/^[imx]*$/.test(flags)) { throw new Error(`Flags "${flags}" unsupported in Oniguruma`); }