regexp-ast-analysis
Advanced tools
Comparing version 0.4.0 to 0.4.1
@@ -1176,3 +1176,10 @@ // Generated by dts-bundle-generator v5.9.0 | ||
): boolean; | ||
export declare function canReorderDirectional( | ||
target: ReadonlySet<Alternative>, | ||
slice: Alternative[], | ||
direction: MatchingDirection, | ||
flags: ReadonlyFlags, | ||
ignoreCapturingGroups: boolean | ||
): boolean; | ||
export {}; |
@@ -1,1 +0,1 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("regexpp"),t=require("refa");function r(e,t){throw new Error(t||e)}function n(e){let t=null;for(const r of e)if(null===t)t=r.parent;else if(r.parent!==t)throw new Error("Expected all alternatives to have the same parent")}exports.Chars=void 0,function(e){const r=t.CharSet.empty(65535),n=t.CharSet.empty(1114111);e.empty=function(e){return e.unicode?n:r};const a=t.CharSet.all(65535),s=t.CharSet.all(1114111);e.all=function(e){return e.unicode?s:a};const o=t.JS.createCharSet([{kind:"any"}],{unicode:!1}).negate(),c=t.JS.createCharSet([{kind:"any"}],{unicode:!0}).negate();e.lineTerminator=function(e){return e.unicode?c:o};const i=t.JS.createCharSet([{kind:"word",negate:!1}],{unicode:!1}),u=t.JS.createCharSet([{kind:"word",negate:!1}],{unicode:!0,ignoreCase:!1}),h=t.JS.createCharSet([{kind:"word",negate:!1}],{unicode:!0,ignoreCase:!0});e.word=function(e){return e.unicode?e.ignoreCase?h:u:i};const l=t.JS.createCharSet([{kind:"digit",negate:!1}],{unicode:!1}),p=t.JS.createCharSet([{kind:"digit",negate:!1}],{unicode:!0});e.digit=function(e){return e.unicode?p:l};const f=t.JS.createCharSet([{kind:"space",negate:!1}],{unicode:!1}),m=t.JS.createCharSet([{kind:"space",negate:!1}],{unicode:!0});e.space=function(e){return e.unicode?m:f}}(exports.Chars||(exports.Chars={}));const a=Array.isArray;class s{constructor(e){this._exactChars=e,this._inexactChars=e}get char(){return this._exactChars.union(this._inexactChars)}get exact(){return this._exactChars.isSupersetOf(this._inexactChars)}add(e){e.exact?this._exactChars=this._exactChars.union(e.char):this._inexactChars=this._inexactChars.union(e.char)}static fromFlags(e){return new s(exports.Chars.empty(e))}static fromMaximum(e){return new s(t.CharSet.empty(e))}}function o(e,t){const r=e.char.intersect(t.char);return{char:r,exact:e.exact&&t.exact||r.isEmpty}}class c{constructor(e){this.count=e,this._indexes=[];for(let t=0;t<e;t++)this._indexes.push(t)}makeEqual(e,t){let r=this._indexes[e],n=this._indexes[t];for(;r!==n;)r<n?(this._indexes[t]=r,t=n,n=this._indexes[t]):(this._indexes[e]=n,e=r,r=this._indexes[e])}getEquivalenceSets(){let e=0;for(let t=0;t<this.count;t++)t===this._indexes[t]?this._indexes[t]=e++:this._indexes[t]=this._indexes[this._indexes[t]];return{count:e,indexes:this._indexes}}}function i(e,t){return a(e)?e.every(t):t(e)}function u(e,t){return a(e)?e.some(t):t(e)}function h(e){return i(e,l)}function l(e){switch(e.type){case"Alternative":return e.elements.every(l);case"Assertion":return!0;case"Character":case"CharacterClass":case"CharacterSet":return!1;case"Quantifier":return 0===e.max||l(e.element);case"Backreference":return A(e);case"CapturingGroup":case"Group":return e.alternatives.length>0&&e.alternatives.every(l);default:throw r(e)}}function p(e){return u(e,(e=>f(e,e)))}function f(e,t){return function e(n){switch(n.type){case"Alternative":return n.elements.every(e);case"Assertion":return!0;case"Backreference":return C(n,t);case"Character":case"CharacterClass":case"CharacterSet":return!1;case"CapturingGroup":case"Group":return n.alternatives.some(e);case"Quantifier":return 0===n.min||e(n.element);default:throw r(n)}}(e)}function m(e){switch(e.type){case"Alternative":return e.elements.every(m);case"Assertion":return!1;case"Backreference":return A(e);case"Character":case"CharacterClass":case"CharacterSet":return!1;case"CapturingGroup":case"Group":return e.alternatives.length>0&&e.alternatives.every(m);case"Quantifier":return 0===e.max||m(e.element);default:throw r(e)}}function d(e){return function t(n){switch(n.type){case"Alternative":return n.elements.every(t);case"Assertion":return!1;case"Backreference":return C(n,e);case"Character":case"CharacterClass":case"CharacterSet":return!1;case"CapturingGroup":case"Group":return n.alternatives.some(t);case"Quantifier":return 0===n.min||t(n.element);default:throw r(n)}}(e)}function C(e,t){return!!A(e)||!!x(e.resolved,(e=>e===t))&&(!F(e)||f(e.resolved,t))}function x(e,t){return"function"==typeof t?function(e,t){let r=e.parent;for(;r;){if(t(r))return!0;r=r.parent}return!1}(e,t):function(e,t){let r=e.parent;for(;r;){if(r===t)return!0;r=r.parent}return!1}(e,t)}function g(e,t,r){return"function"==typeof t?y(e,t,r):r?y(e,(e=>e===t),r):e===t||x(t,e)}function y(e,t,r){if(t(e))return!0;if(r&&!r(e))return!1;switch(e.type){case"Alternative":return e.elements.some((e=>y(e,t,r)));case"Assertion":return("lookahead"===e.kind||"lookbehind"===e.kind)&&e.alternatives.some((e=>y(e,t,r)));case"CapturingGroup":case"Group":case"Pattern":return e.alternatives.some((e=>y(e,t,r)));case"CharacterClass":return e.elements.some((e=>y(e,t,r)));case"CharacterClassRange":return y(e.min,t,r)||y(e.max,t,r);case"Quantifier":return y(e.element,t,r);case"RegExpLiteral":return y(e.pattern,t,r)||y(e.flags,t,r)}return!1}function v(e){switch(e.type){case"RegExpLiteral":return e.pattern;case"Pattern":return e;case"Flags":if(e.parent)return e.parent.pattern;throw new Error("Unable to find the pattern of flags without a RegExp literal.");default:{let t=e.parent;for(;"Pattern"!==t.type;)t=t.parent;return t}}}function k(e){let t;return x(e,(e=>"Assertion"===e.type&&(t=e,!0))),void 0===t||"lookahead"===t.kind?"ltr":"rtl"}function w(e){return"ltr"===e?"rtl":"ltr"}function S(e){return"end"===e||"lookahead"===e?"ltr":"rtl"}function A(e){const t=e.resolved,r=M(e,t);if(r===t)return!0;if("Alternative"!==r.type)return!0;const n=new Set;for(let t=e;t;t=t.parent)n.add(t);return!function e(t){const r=t.parent;switch(r.type){case"Alternative":{const a=r.elements.indexOf(t);let s;if(s="ltr"===k(t)?r.elements.slice(a+1):r.elements.slice(0,a),s.some((e=>n.has(e))))return!0;const o=r.parent;return"Pattern"!==o.type&&(("Assertion"!==o.type||!o.negate)&&e(o))}case"Quantifier":return e(r)}}(t)||h(t)}function F(e){const t=e.resolved,r=M(e,t);if(r===t)return!1;if("Alternative"!==r.type)return!1;const n=new Set;for(let t=e;t;t=t.parent)n.add(t);return function e(t){const r=t.parent;switch(r.type){case"Alternative":{const a=r.elements.indexOf(t);let s;if(s="ltr"===k(t)?r.elements.slice(a+1):r.elements.slice(0,a),s.some((e=>n.has(e))))return!0;const o=r.parent;return"Pattern"!==o.type&&(("Assertion"!==o.type||!o.negate)&&(!(o.alternatives.length>1)&&e(o)))}case"Quantifier":return 0!==r.min&&e(r)}}(t)}function _(e){return g(e,E)}function E(e){return"CapturingGroup"===e.type}const b={min:0,max:0},L={min:1,max:1};function G(e){return a(e)?B(e):W(e)}function B(e){let t=1/0,r=0;for(const n of e){const e=W(n);e&&(t=Math.min(t,e.min),r=Math.max(r,e.max))}return t>r?void 0:{min:t,max:r}}function W(e){switch(e.type){case"Assertion":return b;case"Character":case"CharacterClass":case"CharacterSet":return L;case"Quantifier":{if(0===e.max)return b;const t=W(e.element);return t?0===t.max?b:{min:t.min*e.min,max:t.max*e.max}:0===e.min?b:void 0}case"Alternative":{let t=0,r=0;for(const n of e.elements){const e=W(n);if(!e)return;t+=e.min,r+=e.max}return{min:t,max:r}}case"CapturingGroup":case"Group":return B(e.alternatives);case"Backreference":if(A(e))return b;{const t=W(e.resolved);return t?t.min>0&&!F(e)?{min:0,max:t.max}:t:F(e)?b:void 0}default:throw r(e)}}function M(e,t){if(e===t)return e;if(e.parent&&e.parent===t.parent)return e.parent;{const r=O(e),n=O(t);for(;;){if(0===r.length)return e;if(0===n.length)return t;if(r[r.length-1]!==n[n.length-1])break;r.pop(),n.pop()}const a=r[r.length-1].parent;if(a)return a;throw new Error("The two nodes are not part of the same tree.")}}function O(e){const t=[];for(let r=e;r;r=r.parent)t.push(r);return t}class P{constructor(e){this.toCharSet=new WeakMap,this.getFirstConsumedCharLTR=new WeakMap,this.getFirstConsumedCharRTL=new WeakMap,this.getLongestPrefix=new Map,this.dotAll=!!e.dotAll,this.global=!!e.global,this.hasIndices=!!e.hasIndices,this.ignoreCase=!!e.ignoreCase,this.multiline=!!e.multiline,this.sticky=!!e.sticky,this.unicode=!!e.unicode}static from(e){return e instanceof P?e:new P(e)}}function R(e,r){if(!a(e))return J(e,r);if(1===e.length)return J(e[0],r);const{positive:n,negated:s}=function(e){const t=[],r=[];for(const n of e)"CharacterClass"===n.type?n.negate?r.push(n):t.push(...n.elements):t.push(n);return{positive:t,negated:r}}(e);return s.length?n.length?t.JS.createCharSet(Q(n),r).union(...s.map((e=>t.JS.createCharSet(Q(e.elements),r).negate()))):1===s.length?t.JS.createCharSet(Q(s[0].elements),r).negate():exports.Chars.empty(r).union(...s.map((e=>t.JS.createCharSet(Q(e.elements),r).negate()))):n.length?t.JS.createCharSet(Q(n),r):exports.Chars.empty(r)}function J(e,t){if(t instanceof P){let r=t.toCharSet.get(e);return void 0===r&&(r=j(e,t),t.toCharSet.set(e,r)),r}return j(e,t)}function j(e,r){if("CharacterClass"===e.type){const n=t.JS.createCharSet(Q(e.elements),r);return e.negate?n.negate():n}return t.JS.createCharSet([q(e)],r)}function Q(e){return e.map(q)}function q(e){switch(e.type){case"Character":return e.value;case"CharacterClassRange":return{min:e.min.value,max:e.max.value};case"CharacterSet":return e;default:throw r(e)}}function D(e,t){if(e==t)return!0;if(!e||!t||e.type!=t.type)return!1;switch(e.type){case"Alternative":{const r=t;return T(e.elements,r.elements)}case"Assertion":{const r=t;if(e.kind===r.kind){if("lookahead"===e.kind||"lookbehind"===e.kind){const r=t;return e.negate===r.negate&&T(e.alternatives,r.alternatives)}return e.raw===r.raw}return!1}case"Backreference":{const r=t;return A(e)?A(r):D(e.resolved,r.resolved)&&F(e)==F(r)}case"Character":{const r=t;return e.value===r.value}case"CharacterClass":{const r=t;return e.negate===r.negate&&T(e.elements,r.elements)}case"CharacterClassRange":{const r=t;return D(e.min,r.min)&&D(e.max,r.max)}case"CharacterSet":{const r=t;return"property"===e.kind&&"property"===r.kind?e.negate===r.negate&&e.key===r.key:e.raw===r.raw}case"Flags":{const r=t;return e.dotAll===r.dotAll&&e.global===r.global&&e.ignoreCase===r.ignoreCase&&e.multiline===r.multiline&&e.sticky===r.sticky&&e.unicode===r.unicode}case"CapturingGroup":case"Group":case"Pattern":{const r=t;return T(e.alternatives,r.alternatives)}case"Quantifier":{const r=t;return e.min===r.min&&e.max===r.max&&e.greedy===r.greedy&&D(e.element,r.element)}case"RegExpLiteral":{const r=t;return D(e.flags,r.flags)&&D(e.pattern,r.pattern)}default:throw r(e)}}function T(e,t){if(e.length!==t.length)return!1;for(let r=0;r<e.length;r++)if(!D(e[r],t[r]))return!1;return!0}function I(e,t,n,a,s){function o(e,t,r){var n,s;a.enter&&(t=a.enter(e,t,r));if(null===(s=null===(n=a.continueInto)||void 0===n?void 0:n.call(a,e,t,r))||void 0===s||s)switch(e.type){case"Assertion":if("lookahead"===e.kind||"lookbehind"===e.kind){const n=S(e.kind),s=a.join(e.alternatives.map((e=>c(e,z(a,t,r),n))),n);t=h(t,n,"assertion"),a.assert&&(t=a.assert(t,r,s,n))}break;case"Group":case"CapturingGroup":t=a.join(e.alternatives.map((e=>c(e,z(a,t,r),r))),r);break;case"Quantifier":0===e.max||(t=0===e.min?a.join([t,o(e.element,z(a,t,r),r)],r):o(e.element,t,r))}return a.leave&&(t=a.leave(e,t,r)),t}function c(e,t,r){var n,s;let c="ltr"===r?0:e.elements.length-1;const i="ltr"===r?1:-1;let u;for(;u=e.elements[c];c+=i){t=o(u,t,r);if(!(null===(s=null===(n=a.continueAfter)||void 0===n?void 0:n.call(a,u,t,r))||void 0===s||s))break}return t}function i(e,t,n){var s,o;const c=e.parent;if("CharacterClass"===c.type||"CharacterClassRange"===c.type)throw new Error("The given element cannot be part of a character class.");if(!(null===(o=null===(s=a.continueAfter)||void 0===s?void 0:s.call(a,e,t,n))||void 0===o||o))return!1;if("Quantifier"===c.type)return c.max<=1?i(c,t,n):[c,i(c,t,n)];{const a=c.elements.indexOf(e)+("ltr"===n?1:-1),s=c.elements[a];if(s)return s;{const e=c.parent;if("Pattern"===e.type)return"pattern";if("Assertion"===e.type)return u(e,t,n)?i(e,t,n):"assertion";if("CapturingGroup"===e.type||"Group"===e.type)return i(e,t,n);throw r(e)}}}function u(e,t,r){return!!a.continueOutside&&a.continueOutside(e,t,r)}function h(e,t,r){return a.endPath?a.endPath(e,t,r):e}if(s||(s=k(e)),"Alternative"===e.type)if(0===e.elements.length&&(t="next"),"enter"===t)l=e,e="ltr"===s?l.elements[0]:l.elements[l.elements.length-1];else{const t=e.parent;if("Pattern"===t.type)return h(n,s,"pattern");if("Assertion"===t.type&&!u(t,n,s))return h(n,s,"assertion");e=t}var l;return"enter"===t&&(n=o(e,n,s)),function(e,t,r){for(;;){let n=i(e,t,r);for(;Array.isArray(n);){const[e,s]=n;t=a.join([t,o(e,z(a,t,r),r)],r),n=s}if(!1===n)return t;if("assertion"===n||"pattern"===n)return h(t,r,n);t=o(n,t,r),e=n}}(e,n,s)}function z(e,t,r){return e.fork?e.fork(t,r):t}var $,U;exports.FirstLookChars=void 0,($=exports.FirstLookChars||(exports.FirstLookChars={})).all=function(e){return{char:exports.Chars.all(e),exact:!0,edge:!0}},$.edge=function(e){return{char:exports.Chars.empty(e),exact:!0,edge:!0}},$.toConsumed=function(e){return!e.edge&&e.char.isEmpty?{char:t.CharSet.empty(e.char.maximum),exact:!0,empty:!1}:{char:t.CharSet.empty(e.char.maximum),exact:!0,empty:!0,look:e}},exports.FirstConsumedChars=void 0,(U=exports.FirstConsumedChars||(exports.FirstConsumedChars={})).emptyConcat=function(e){return{char:exports.Chars.empty(e),exact:!0,empty:!0,look:exports.FirstLookChars.all(e)}},U.emptyUnion=function(e){return{char:exports.Chars.empty(e),exact:!0,empty:!1}},U.toLook=function(e){if(e.empty){const t=function(e,t){const r=e.char.union(t.char);let n;return n=e.exact?!!t.exact||e.char.isSupersetOf(t.char):!!t.exact&&t.char.isSupersetOf(e.char),{char:r,exact:n}}(e,e.look);return{char:t.char,exact:t.exact,edge:e.look.edge}}return{char:e.char,exact:e.exact,edge:!1}},U.union=function(e,t){const r=s.fromFlags(t),n=[];for(const t of e)r.add(t),t.empty&&n.push(t.look);if(n.length>0){if(1===n.length)return{char:r.char,exact:r.exact,empty:!0,look:n[0]};const e=s.fromFlags(t);let a=!1;for(const t of n)e.add(t),a=a||t.edge;return{char:r.char,exact:r.exact,empty:!0,look:{char:e.char,exact:e.exact,edge:a}}}return{char:r.char,exact:r.exact,empty:!1}},U.concat=function(e,t){const r=s.fromFlags(t);let n=exports.FirstLookChars.all(t);for(const t of e){if(r.add(o(t,n)),!t.empty)return{char:r.char,exact:r.exact,empty:!1};{const e=o(n,t.look);if(n={char:e.char,exact:e.exact,edge:n.edge&&t.look.edge},!n.edge&&n.char.isEmpty)return{char:r.char,exact:r.exact,empty:!1}}}return{char:r.char,exact:r.exact,empty:!0,look:n}},U.makeOptional=function(e){return{char:e.char,exact:e.exact,empty:!0,look:{char:t.CharSet.all(e.char.maximum),exact:!0,edge:!0}}};class N{constructor(e){this._currentWordBoundaries=[],e instanceof P?(this._ltrCache=e.getFirstConsumedCharLTR,this._rtlCache=e.getFirstConsumedCharRTL):(this._ltrCache=new WeakMap,this._rtlCache=new WeakMap)}isCurrentWordBoundary(e){return this._currentWordBoundaries.some((t=>t===e))}pushWordBoundary(e){this._currentWordBoundaries.push(e)}popWordBoundary(){this._currentWordBoundaries.pop()}getCached(e,t){return"ltr"===t?this._ltrCache.get(e):this._rtlCache.get(e)}setCached(e,t,r){"ltr"===t?this._ltrCache.set(e,r):this._rtlCache.set(e,r)}}function Z(e,t,r){const n=new N(r);return a(e)?K(e,t,r,n):H(e,t,r,n)}function K(e,t,r,n){return exports.FirstConsumedChars.union(e.map((e=>H(e,t,r,n))),r)}function H(e,t,n,a){let s=a.getCached(e,t);return void 0===s&&(s=function(e,t,n,a){switch(e.type){case"Assertion":return function(e,t,n,a){switch(e.kind){case"word":if(a.isCurrentWordBoundary(e))return s();{a.pushWordBoundary(e);const r=ee(e,w(t),n,a);a.popWordBoundary();const o=exports.Chars.word(n);return r.edge?r.char.isDisjointWith(o)?i(e.negate):s():r.char.isDisjointWith(o)?i(e.negate):r.char.isSubsetOf(o)?i(!e.negate):s()}case"end":case"start":return S(e.kind)===t?n.multiline?c():o():s();case"lookahead":case"lookbehind":if(S(e.kind)===t){if(e.negate){if(g(e,(t=>t!==e&&"Assertion"===t.type)))return s();const r=K(e.alternatives,t,n,a),o=G(e.alternatives);return r.empty||!o?{char:exports.Chars.empty(n),empty:!1,exact:!0}:r.exact&&1===o.max?exports.FirstLookChars.toConsumed({char:r.char.negate(),edge:!0,exact:!0}):s()}{const r=K(e.alternatives,t,n,a);return exports.FirstLookChars.toConsumed(exports.FirstConsumedChars.toLook(r))}}return s();default:throw r(e)}function s(){return exports.FirstLookChars.toConsumed({char:exports.Chars.all(n),edge:!0,exact:!1})}function o(){return exports.FirstLookChars.toConsumed(exports.FirstLookChars.edge(n))}function c(){return exports.FirstLookChars.toConsumed({char:exports.Chars.lineTerminator(n),edge:!0,exact:!0})}function i(e){const t=exports.Chars.word(n);return exports.FirstLookChars.toConsumed({char:e?t.negate():t,edge:e,exact:!0})}}(e,t,n,a);case"Character":case"CharacterSet":case"CharacterClass":return{char:R(e,n),empty:!1,exact:!0};case"Quantifier":{if(0===e.max)return exports.FirstConsumedChars.emptyConcat(n);const r=H(e.element,t,n,a);return 0===e.min?exports.FirstConsumedChars.makeOptional(r):r}case"Alternative":{let r=e.elements;return"rtl"===t&&(r=[...r],r.reverse()),exports.FirstConsumedChars.concat(function*(){for(const e of r)yield H(e,t,n,a)}(),n)}case"CapturingGroup":case"Group":return K(e.alternatives,t,n,a);case"Backreference":{if(A(e))return exports.FirstConsumedChars.emptyConcat(n);let r=H(e.resolved,t,n,a);return r.exact&&r.char.size>1&&(r=Object.assign(Object.assign({},r),{exact:!1})),F(e)?r:exports.FirstConsumedChars.makeOptional(r)}default:throw r(e)}}(e,t,n,a),a.setCached(e,t,s)),s}function V(e,t,r){return X(e,t,r,new N(r))}function X(e,t,r,n){return I(e,"next",exports.FirstConsumedChars.emptyConcat(r),{join:e=>exports.FirstConsumedChars.union(e,r),enter(e,t,a){const s=H(e,a,r,n);return exports.FirstConsumedChars.concat([t,s],r)},continueInto:()=>!1,continueAfter:(e,t)=>t.empty,continueOutside:(e,t,r)=>S(e.kind)!==r},t)}function Y(e,t,r){return ee(e,t,r,new N(r))}function ee(e,t,r,n){return exports.FirstConsumedChars.toLook(X(e,t,r,n))}function te(e,t,r,n){return I(e,"next",{char:exports.FirstConsumedChars.emptyConcat(r),contributors:[]},{join(e){const t=new Set;return e.forEach((e=>e.contributors.forEach((e=>t.add(e))))),{char:exports.FirstConsumedChars.union(e.map((e=>e.char)),r),contributors:[...t]}},enter(e,t,a){const s=H(e,a,r,n);return{char:exports.FirstConsumedChars.concat([t.char,s],r),contributors:[...t.contributors,e]}},continueInto:()=>!1,continueAfter:(e,t)=>t.char.empty,continueOutside:(e,t,r)=>S(e.kind)!==r},t)}function re(e,t,r,n={}){const a=P.from(r);r=a;const{includeAfter:s=!1,looseGroups:o=!1}=n,c=a.getLongestPrefix,i=`${t},${s},${o}`;let u=c.get(i);void 0===u&&(u=new WeakMap,c.set(i,u));let l=u.get(e);return void 0===l&&(l=function(e,t,r,n){const{chars:a,complete:s}=se(e,t,r,n);for(let e=0;e<a.length;e++)if(a[e].isEmpty)return a.slice(0,e);s&&r.includeAfter&&a.push(function(e,t,r){const{elements:n}=e,a="rtl"===t?0:n.length-1,s="ltr"===t?1:-1;let o=a;for(;o>=0&&o<n.length&&h(n[o]);)o-=s;return o>=0&&o<n.length?Y(n[o],t,r):exports.FirstConsumedChars.toLook(ce(e,t,r))}(e,t,n).char);return a}(e,t,{includeAfter:s,looseGroups:o},r),u.set(e,l)),l}const ne={chars:[],complete:!0},ae={chars:[],complete:!1};function se(e,t,r,n){const{elements:a}=e,s=[],o="ltr"===t?1:-1;for(let e="ltr"===t?0:a.length-1;e>=0&&e<a.length;e+=o){const o=oe(a[e],t,r,n);if(s.push(...o.chars),!o.complete)return{chars:s,complete:!1}}return{chars:s,complete:!0}}function oe(e,t,n,a){switch(e.type){case"Assertion":return ne;case"Character":case"CharacterClass":case"CharacterSet":return{chars:[R(e,a)],complete:!0};case"CapturingGroup":case"Group":return function(e,t,r,n){const a=e.alternatives.map((e=>se(e,t,r,n)));if(1===a.length)return a[0];const s=[];let o=!0,c=0;for(let i=0;o;i++){const u=[];let h=!1;for(const e of a)i>=e.chars.length?h=!0:(u.push(e.chars[i]),i===e.chars.length-1&&!e.complete&&r.includeAfter&&(o=!1));if(0===u.length)break;if(h){if(o=!1,!r.includeAfter)break;u.push(Y(e,t,n).char)}else if(!r.looseGroups&&(o&&u.some((e=>!e.equals(u[0])))&&c++,c>=2&&(o=!1,!r.includeAfter)))break;const l=u[0].union(...u.slice(1));s.push(l)}return{chars:s,complete:o}}(e,t,n,a);case"Quantifier":return function(e,t,r,n){if(h(e))return ne;if(p(e)){if(!r.includeAfter)return ae;return{chars:[exports.FirstConsumedChars.toLook(ce(e,t,n)).char],complete:!1}}const a=oe(e.element,t,r,n);if(!a.complete)return a;if(0===a.chars.length)throw new Error(`Expected the quantifier '${e.raw}' to consume at least one character.`);const s=[];for(let t=0;t<e.min;t++)if(s.push(...a.chars),s.length>1e3)return{chars:s,complete:!1};if(e.min===e.max)return{chars:s,complete:!0};if(r.includeAfter){const r=Y(e,t,n);s.push(r.char.union(a.chars[0]))}return{chars:s,complete:!1}}(e,t,n,a);case"Backreference":if(A(e))return ne;if(F(e)){return oe(e.resolved,t,Object.assign(Object.assign({},n),{includeAfter:!1}),a)}if(!n.includeAfter)return ae;return{chars:[exports.FirstConsumedChars.toLook(ce(e,t,a)).char],complete:!1};default:r(e)}}function ce(e,t,r){const n=Z(e,t,r);return n.empty?exports.FirstConsumedChars.concat([n,V(e,t,r)],r):n}function ie(e,t,r){return n(e),"unknown"===t?function(e,t){const r=he(e,"ltr",t),n=he(e,"rtl",t),a=le([...r,...n],(e=>e)),s=[];for(const e of a){const t=new Set;for(const r of e)r.forEach((e=>t.add(e)));s.push([...t])}return s}(e,r):he(e,t,r)}const ue={includeAfter:!0,looseGroups:!0};function he(e,r,n){const a=function(e){function t(r){let n=t.cache.get(r);return void 0===n&&(n=e(r),t.cache.set(r,n)),n}return t.cache=new Map,t}((e=>{let t=re(e,r,n,ue),a=0;for(let e=t.length-1;e>=0&&t[e].isAll;e--)a++;return a>0&&(t=t.slice(0,t.length-a)),t})),s=new Set;for(const t of e)a(t).forEach((e=>s.add(e)));const o=new t.CharBase(s),c=[];for(const t of e)c.push({characters:a(t).map((e=>o.split(e))),alternative:t});return function e(t,r){if(t.length<2)return[t];for(const e of t)if(r>=e.characters.length)return[t];const n=le(t,(e=>e.characters[r])),a=[];for(const t of n)a.push(...e(t,r+1));return a}(c,0).map((e=>e.map((e=>e.alternative))))}function le(e,t){if(e.length<2)return[e];const r=new c(e.length),n=new Map;for(let a=0;a<e.length;a++){const s=e[a];for(const e of t(s)){const t=n.get(e);void 0===t?n.set(e,a):r.makeEqual(a,t)}}const a=r.getEquivalenceSets(),s=[];for(let e=0;e<a.count;e++)s.push([]);for(let t=0;t<e.length;t++)s[a.indexes[t]].push(e[t]);return s}function pe(e,t){const r=[];return g(e,(e=>("Character"===e.type||"CharacterClass"===e.type||"CharacterSet"===e.type?r.push(R(e,t)):"Backreference"!==e.type||A(e)||r.push(pe(e.resolved,t)),!1)),(e=>"Assertion"!==e.type&&"CharacterClass"!==e.type)),exports.Chars.empty(t).union(...r)}exports.canReorder=function(e,t,r={}){const{ignoreCapturingGroups:a=!1,matchingDirection:s}=r,o=(c=e)instanceof Set?c:new Set(c);var c;if(o.size<2)return!0;n(o);const i=function(e){if(e.size<=1)return[...e];let t;for(const r of e){t=r;break}if(!t)throw new Error;const r=t.parent.alternatives;let n=e.size,a=0;for(let t=0;t<r.length;t++){const s=r[t];e.has(s)&&(n=Math.min(n,t),a=Math.max(a,t))}return r.slice(n,a+1)}(o),u=ie(i,null!=s?s:k(i[0]),t);return!(!a&&!function(e,t,r){let n=0,a=0;for(const r of t)_(r)&&(e.has(r)?n++:a++);if(n>1||1===n&&0!==a)return!1;if(0!==a)return r.every((t=>!t.some(_)||t.every((t=>!e.has(t)))));if(0!==n)return r.every((e=>e.length<2||!e.some(_)));return!0}(o,i,u))&&u.every((e=>e.length<2||(!!e.every((e=>!o.has(e)))||(function(e){const t=G(e);return Boolean(t&&t.min===t.max)}(e)||function(e,t){if(e.some(p))return!1;const r=e[0].parent;if("Pattern"===r.type||"Assertion"===r.type)return!1;const n=exports.Chars.empty(t).union(...e.map((e=>pe(e,t))));return Y(r,"rtl",t).char.isDisjointWith(n)&&Y(r,"ltr",t).char.isDisjointWith(n)}(e,t)))))},exports.containsCapturingGroup=_,exports.createCache=function(e){return new P(e)},exports.followPaths=I,exports.getCapturingGroupNumber=function(t){let r=0;try{throw e.visitRegExpAST(v(t),{onCapturingGroupEnter(e){if(r++,e===t)throw new Error}}),new Error("Unable to find the given capturing group in its parent pattern.")}catch(e){return r}},exports.getClosestAncestor=M,exports.getEffectiveMaximumRepetition=function(e){let t=1;for(let r=e.parent;r;r=r.parent)if("Quantifier"===r.type){if(t*=r.max,0===t)return 0}else if("Assertion"===r.type)break;return t},exports.getFirstCharAfter=Y,exports.getFirstCharAfterWithContributors=function(e,t,r){return function(e,t,r,n){const{char:a,contributors:s}=te(e,t,r,n);return{char:exports.FirstConsumedChars.toLook(a),contributors:s}}(e,t,r,new N(r))},exports.getFirstConsumedChar=Z,exports.getFirstConsumedCharAfter=V,exports.getFirstConsumedCharAfterWithContributors=function(e,t,r){return te(e,t,r,new N(r))},exports.getLengthRange=G,exports.getLongestPrefix=re,exports.getMatchingDirection=k,exports.getMatchingDirectionFromAssertionKind=S,exports.getPattern=v,exports.hasSomeAncestor=x,exports.hasSomeDescendant=g,exports.invertMatchingDirection=w,exports.isEmpty=function(e){return i(e,m)},exports.isEmptyBackreference=A,exports.isPotentiallyEmpty=function(e){return u(e,d)},exports.isPotentiallyZeroLength=p,exports.isStrictBackreference=F,exports.isZeroLength=h,exports.matchesAllCharacters=function(e,t){return"Character"!==e.type&&("CharacterClassRange"===e.type?0===e.min.value&&e.max.value===(t.unicode?1114111:65535):"CharacterSet"===e.type?"property"===e.kind?R(e,t).isAll:"any"===e.kind&&!!t.dotAll:!(!e.negate||0!==e.elements.length)||(e.negate?R(e.elements,t).isEmpty:R(e.elements,t).isAll))},exports.matchesNoCharacters=function(e,t){return"Character"!==e.type&&"CharacterClassRange"!==e.type&&("CharacterSet"===e.type?"property"===e.kind&&R(e,t).isEmpty:!e.negate&&0===e.elements.length||(e.negate?R(e.elements,t).isAll:R(e.elements,t).isEmpty))},exports.structurallyEqual=D,exports.toCache=function(e){return P.from(e)},exports.toCharSet=R; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("regexpp"),t=require("refa");function r(e,t){throw new Error(t||e)}function n(e){let t=null;for(const r of e)if(null===t)t=r.parent;else if(r.parent!==t)throw new Error("Expected all alternatives to have the same parent")}exports.Chars=void 0,function(e){const r=t.CharSet.empty(65535),n=t.CharSet.empty(1114111);e.empty=function(e){return e.unicode?n:r};const a=t.CharSet.all(65535),s=t.CharSet.all(1114111);e.all=function(e){return e.unicode?s:a};const o=t.JS.createCharSet([{kind:"any"}],{unicode:!1}).negate(),c=t.JS.createCharSet([{kind:"any"}],{unicode:!0}).negate();e.lineTerminator=function(e){return e.unicode?c:o};const i=t.JS.createCharSet([{kind:"word",negate:!1}],{unicode:!1}),u=t.JS.createCharSet([{kind:"word",negate:!1}],{unicode:!0,ignoreCase:!1}),l=t.JS.createCharSet([{kind:"word",negate:!1}],{unicode:!0,ignoreCase:!0});e.word=function(e){return e.unicode?e.ignoreCase?l:u:i};const h=t.JS.createCharSet([{kind:"digit",negate:!1}],{unicode:!1}),p=t.JS.createCharSet([{kind:"digit",negate:!1}],{unicode:!0});e.digit=function(e){return e.unicode?p:h};const f=t.JS.createCharSet([{kind:"space",negate:!1}],{unicode:!1}),m=t.JS.createCharSet([{kind:"space",negate:!1}],{unicode:!0});e.space=function(e){return e.unicode?m:f}}(exports.Chars||(exports.Chars={}));const a=Array.isArray;class s{constructor(e){this._exactChars=e,this._inexactChars=e}get char(){return this._exactChars.union(this._inexactChars)}get exact(){return this._exactChars.isSupersetOf(this._inexactChars)}add(e){e.exact?this._exactChars=this._exactChars.union(e.char):this._inexactChars=this._inexactChars.union(e.char)}static fromFlags(e){return new s(exports.Chars.empty(e))}static fromMaximum(e){return new s(t.CharSet.empty(e))}}function o(e,t){const r=e.char.intersect(t.char);return{char:r,exact:e.exact&&t.exact||r.isEmpty}}class c{constructor(e){this.count=e,this._indexes=[];for(let t=0;t<e;t++)this._indexes.push(t)}makeEqual(e,t){let r=this._indexes[e],n=this._indexes[t];for(;r!==n;)r<n?(this._indexes[t]=r,t=n,n=this._indexes[t]):(this._indexes[e]=n,e=r,r=this._indexes[e])}getEquivalenceSets(){let e=0;for(let t=0;t<this.count;t++)t===this._indexes[t]?this._indexes[t]=e++:this._indexes[t]=this._indexes[this._indexes[t]];return{count:e,indexes:this._indexes}}}function i(e,t){return a(e)?e.every(t):t(e)}function u(e,t){return a(e)?e.some(t):t(e)}function l(e){return i(e,h)}function h(e){switch(e.type){case"Alternative":return e.elements.every(h);case"Assertion":return!0;case"Character":case"CharacterClass":case"CharacterSet":return!1;case"Quantifier":return 0===e.max||h(e.element);case"Backreference":return A(e);case"CapturingGroup":case"Group":return e.alternatives.length>0&&e.alternatives.every(h);default:throw r(e)}}function p(e){return u(e,(e=>f(e,e)))}function f(e,t){return function e(n){switch(n.type){case"Alternative":return n.elements.every(e);case"Assertion":return!0;case"Backreference":return C(n,t);case"Character":case"CharacterClass":case"CharacterSet":return!1;case"CapturingGroup":case"Group":return n.alternatives.some(e);case"Quantifier":return 0===n.min||e(n.element);default:throw r(n)}}(e)}function m(e){switch(e.type){case"Alternative":return e.elements.every(m);case"Assertion":return!1;case"Backreference":return A(e);case"Character":case"CharacterClass":case"CharacterSet":return!1;case"CapturingGroup":case"Group":return e.alternatives.length>0&&e.alternatives.every(m);case"Quantifier":return 0===e.max||m(e.element);default:throw r(e)}}function d(e){return function t(n){switch(n.type){case"Alternative":return n.elements.every(t);case"Assertion":return!1;case"Backreference":return C(n,e);case"Character":case"CharacterClass":case"CharacterSet":return!1;case"CapturingGroup":case"Group":return n.alternatives.some(t);case"Quantifier":return 0===n.min||t(n.element);default:throw r(n)}}(e)}function C(e,t){return!!A(e)||!!g(e.resolved,(e=>e===t))&&(!F(e)||f(e.resolved,t))}function g(e,t){return"function"==typeof t?function(e,t){let r=e.parent;for(;r;){if(t(r))return!0;r=r.parent}return!1}(e,t):function(e,t){let r=e.parent;for(;r;){if(r===t)return!0;r=r.parent}return!1}(e,t)}function x(e,t,r){return"function"==typeof t?y(e,t,r):r?y(e,(e=>e===t),r):e===t||g(t,e)}function y(e,t,r){if(t(e))return!0;if(r&&!r(e))return!1;switch(e.type){case"Alternative":return e.elements.some((e=>y(e,t,r)));case"Assertion":return("lookahead"===e.kind||"lookbehind"===e.kind)&&e.alternatives.some((e=>y(e,t,r)));case"CapturingGroup":case"Group":case"Pattern":return e.alternatives.some((e=>y(e,t,r)));case"CharacterClass":return e.elements.some((e=>y(e,t,r)));case"CharacterClassRange":return y(e.min,t,r)||y(e.max,t,r);case"Quantifier":return y(e.element,t,r);case"RegExpLiteral":return y(e.pattern,t,r)||y(e.flags,t,r)}return!1}function k(e){switch(e.type){case"RegExpLiteral":return e.pattern;case"Pattern":return e;case"Flags":if(e.parent)return e.parent.pattern;throw new Error("Unable to find the pattern of flags without a RegExp literal.");default:{let t=e.parent;for(;"Pattern"!==t.type;)t=t.parent;return t}}}function v(e){let t;return g(e,(e=>"Assertion"===e.type&&(t=e,!0))),void 0===t||"lookahead"===t.kind?"ltr":"rtl"}function w(e){return"ltr"===e?"rtl":"ltr"}function S(e){return"end"===e||"lookahead"===e?"ltr":"rtl"}function A(e){const t=e.resolved,r=M(e,t);if(r===t)return!0;if("Alternative"!==r.type)return!0;const n=new Set;for(let t=e;t;t=t.parent)n.add(t);return!function e(t){const r=t.parent;switch(r.type){case"Alternative":{const a=r.elements.indexOf(t);let s;if(s="ltr"===v(t)?r.elements.slice(a+1):r.elements.slice(0,a),s.some((e=>n.has(e))))return!0;const o=r.parent;return"Pattern"!==o.type&&(("Assertion"!==o.type||!o.negate)&&e(o))}case"Quantifier":return e(r)}}(t)||l(t)}function F(e){const t=e.resolved,r=M(e,t);if(r===t)return!1;if("Alternative"!==r.type)return!1;const n=new Set;for(let t=e;t;t=t.parent)n.add(t);return function e(t){const r=t.parent;switch(r.type){case"Alternative":{const a=r.elements.indexOf(t);let s;if(s="ltr"===v(t)?r.elements.slice(a+1):r.elements.slice(0,a),s.some((e=>n.has(e))))return!0;const o=r.parent;return"Pattern"!==o.type&&(("Assertion"!==o.type||!o.negate)&&(!(o.alternatives.length>1)&&e(o)))}case"Quantifier":return 0!==r.min&&e(r)}}(t)}function E(e){return x(e,_)}function _(e){return"CapturingGroup"===e.type}const b={min:0,max:0},L={min:1,max:1};function G(e){return a(e)?B(e):W(e)}function B(e){let t=1/0,r=0;for(const n of e){const e=W(n);e&&(t=Math.min(t,e.min),r=Math.max(r,e.max))}return t>r?void 0:{min:t,max:r}}function W(e){switch(e.type){case"Assertion":return b;case"Character":case"CharacterClass":case"CharacterSet":return L;case"Quantifier":{if(0===e.max)return b;const t=W(e.element);return t?0===t.max?b:{min:t.min*e.min,max:t.max*e.max}:0===e.min?b:void 0}case"Alternative":{let t=0,r=0;for(const n of e.elements){const e=W(n);if(!e)return;t+=e.min,r+=e.max}return{min:t,max:r}}case"CapturingGroup":case"Group":return B(e.alternatives);case"Backreference":if(A(e))return b;{const t=W(e.resolved);return t?t.min>0&&!F(e)?{min:0,max:t.max}:t:F(e)?b:void 0}default:throw r(e)}}function M(e,t){if(e===t)return e;if(e.parent&&e.parent===t.parent)return e.parent;{const r=O(e),n=O(t);for(;;){if(0===r.length)return e;if(0===n.length)return t;if(r[r.length-1]!==n[n.length-1])break;r.pop(),n.pop()}const a=r[r.length-1].parent;if(a)return a;throw new Error("The two nodes are not part of the same tree.")}}function O(e){const t=[];for(let r=e;r;r=r.parent)t.push(r);return t}function P(e){return R.from(e)}class R{constructor(e){this.toCharSet=new WeakMap,this.getFirstConsumedCharLTR=new WeakMap,this.getFirstConsumedCharRTL=new WeakMap,this.getLongestPrefix=new Map,this.dotAll=!!e.dotAll,this.global=!!e.global,this.hasIndices=!!e.hasIndices,this.ignoreCase=!!e.ignoreCase,this.multiline=!!e.multiline,this.sticky=!!e.sticky,this.unicode=!!e.unicode}static from(e){return e instanceof R?e:new R(e)}}function J(e,r){if(!a(e))return j(e,r);if(1===e.length)return j(e[0],r);const{positive:n,negated:s}=function(e){const t=[],r=[];for(const n of e)"CharacterClass"===n.type?n.negate?r.push(n):t.push(...n.elements):t.push(n);return{positive:t,negated:r}}(e);return s.length?n.length?t.JS.createCharSet(q(n),r).union(...s.map((e=>t.JS.createCharSet(q(e.elements),r).negate()))):1===s.length?t.JS.createCharSet(q(s[0].elements),r).negate():exports.Chars.empty(r).union(...s.map((e=>t.JS.createCharSet(q(e.elements),r).negate()))):n.length?t.JS.createCharSet(q(n),r):exports.Chars.empty(r)}function j(e,t){if(t instanceof R){let r=t.toCharSet.get(e);return void 0===r&&(r=Q(e,t),t.toCharSet.set(e,r)),r}return Q(e,t)}function Q(e,r){if("CharacterClass"===e.type){const n=t.JS.createCharSet(q(e.elements),r);return e.negate?n.negate():n}return t.JS.createCharSet([D(e)],r)}function q(e){return e.map(D)}function D(e){switch(e.type){case"Character":return e.value;case"CharacterClassRange":return{min:e.min.value,max:e.max.value};case"CharacterSet":return e;default:throw r(e)}}function T(e,t){if(e==t)return!0;if(!e||!t||e.type!=t.type)return!1;switch(e.type){case"Alternative":{const r=t;return I(e.elements,r.elements)}case"Assertion":{const r=t;if(e.kind===r.kind){if("lookahead"===e.kind||"lookbehind"===e.kind){const r=t;return e.negate===r.negate&&I(e.alternatives,r.alternatives)}return e.raw===r.raw}return!1}case"Backreference":{const r=t;return A(e)?A(r):T(e.resolved,r.resolved)&&F(e)==F(r)}case"Character":{const r=t;return e.value===r.value}case"CharacterClass":{const r=t;return e.negate===r.negate&&I(e.elements,r.elements)}case"CharacterClassRange":{const r=t;return T(e.min,r.min)&&T(e.max,r.max)}case"CharacterSet":{const r=t;return"property"===e.kind&&"property"===r.kind?e.negate===r.negate&&e.key===r.key:e.raw===r.raw}case"Flags":{const r=t;return e.dotAll===r.dotAll&&e.global===r.global&&e.ignoreCase===r.ignoreCase&&e.multiline===r.multiline&&e.sticky===r.sticky&&e.unicode===r.unicode}case"CapturingGroup":case"Group":case"Pattern":{const r=t;return I(e.alternatives,r.alternatives)}case"Quantifier":{const r=t;return e.min===r.min&&e.max===r.max&&e.greedy===r.greedy&&T(e.element,r.element)}case"RegExpLiteral":{const r=t;return T(e.flags,r.flags)&&T(e.pattern,r.pattern)}default:throw r(e)}}function I(e,t){if(e.length!==t.length)return!1;for(let r=0;r<e.length;r++)if(!T(e[r],t[r]))return!1;return!0}function z(e,t,n,a,s){function o(e,t,r){var n,s;a.enter&&(t=a.enter(e,t,r));if(null===(s=null===(n=a.continueInto)||void 0===n?void 0:n.call(a,e,t,r))||void 0===s||s)switch(e.type){case"Assertion":if("lookahead"===e.kind||"lookbehind"===e.kind){const n=S(e.kind),s=a.join(e.alternatives.map((e=>c(e,$(a,t,r),n))),n);t=l(t,n,"assertion"),a.assert&&(t=a.assert(t,r,s,n))}break;case"Group":case"CapturingGroup":t=a.join(e.alternatives.map((e=>c(e,$(a,t,r),r))),r);break;case"Quantifier":0===e.max||(t=0===e.min?a.join([t,o(e.element,$(a,t,r),r)],r):o(e.element,t,r))}return a.leave&&(t=a.leave(e,t,r)),t}function c(e,t,r){var n,s;let c="ltr"===r?0:e.elements.length-1;const i="ltr"===r?1:-1;let u;for(;u=e.elements[c];c+=i){t=o(u,t,r);if(!(null===(s=null===(n=a.continueAfter)||void 0===n?void 0:n.call(a,u,t,r))||void 0===s||s))break}return t}function i(e,t,n){var s,o;const c=e.parent;if("CharacterClass"===c.type||"CharacterClassRange"===c.type)throw new Error("The given element cannot be part of a character class.");if(!(null===(o=null===(s=a.continueAfter)||void 0===s?void 0:s.call(a,e,t,n))||void 0===o||o))return!1;if("Quantifier"===c.type)return c.max<=1?i(c,t,n):[c,i(c,t,n)];{const a=c.elements.indexOf(e)+("ltr"===n?1:-1),s=c.elements[a];if(s)return s;{const e=c.parent;if("Pattern"===e.type)return"pattern";if("Assertion"===e.type)return u(e,t,n)?i(e,t,n):"assertion";if("CapturingGroup"===e.type||"Group"===e.type)return i(e,t,n);throw r(e)}}}function u(e,t,r){return!!a.continueOutside&&a.continueOutside(e,t,r)}function l(e,t,r){return a.endPath?a.endPath(e,t,r):e}if(s||(s=v(e)),"Alternative"===e.type)if(0===e.elements.length&&(t="next"),"enter"===t)h=e,e="ltr"===s?h.elements[0]:h.elements[h.elements.length-1];else{const t=e.parent;if("Pattern"===t.type)return l(n,s,"pattern");if("Assertion"===t.type&&!u(t,n,s))return l(n,s,"assertion");e=t}var h;return"enter"===t&&(n=o(e,n,s)),function(e,t,r){for(;;){let n=i(e,t,r);for(;Array.isArray(n);){const[e,s]=n;t=a.join([t,o(e,$(a,t,r),r)],r),n=s}if(!1===n)return t;if("assertion"===n||"pattern"===n)return l(t,r,n);t=o(n,t,r),e=n}}(e,n,s)}function $(e,t,r){return e.fork?e.fork(t,r):t}var U,N;exports.FirstLookChars=void 0,(U=exports.FirstLookChars||(exports.FirstLookChars={})).all=function(e){return{char:exports.Chars.all(e),exact:!0,edge:!0}},U.edge=function(e){return{char:exports.Chars.empty(e),exact:!0,edge:!0}},U.toConsumed=function(e){return!e.edge&&e.char.isEmpty?{char:t.CharSet.empty(e.char.maximum),exact:!0,empty:!1}:{char:t.CharSet.empty(e.char.maximum),exact:!0,empty:!0,look:e}},exports.FirstConsumedChars=void 0,(N=exports.FirstConsumedChars||(exports.FirstConsumedChars={})).emptyConcat=function(e){return{char:exports.Chars.empty(e),exact:!0,empty:!0,look:exports.FirstLookChars.all(e)}},N.emptyUnion=function(e){return{char:exports.Chars.empty(e),exact:!0,empty:!1}},N.toLook=function(e){if(e.empty){const t=function(e,t){const r=e.char.union(t.char);let n;return n=e.exact?!!t.exact||e.char.isSupersetOf(t.char):!!t.exact&&t.char.isSupersetOf(e.char),{char:r,exact:n}}(e,e.look);return{char:t.char,exact:t.exact,edge:e.look.edge}}return{char:e.char,exact:e.exact,edge:!1}},N.union=function(e,t){const r=s.fromFlags(t),n=[];for(const t of e)r.add(t),t.empty&&n.push(t.look);if(n.length>0){if(1===n.length)return{char:r.char,exact:r.exact,empty:!0,look:n[0]};const e=s.fromFlags(t);let a=!1;for(const t of n)e.add(t),a=a||t.edge;return{char:r.char,exact:r.exact,empty:!0,look:{char:e.char,exact:e.exact,edge:a}}}return{char:r.char,exact:r.exact,empty:!1}},N.concat=function(e,t){const r=s.fromFlags(t);let n=exports.FirstLookChars.all(t);for(const t of e){if(r.add(o(t,n)),!t.empty)return{char:r.char,exact:r.exact,empty:!1};{const e=o(n,t.look);if(n={char:e.char,exact:e.exact,edge:n.edge&&t.look.edge},!n.edge&&n.char.isEmpty)return{char:r.char,exact:r.exact,empty:!1}}}return{char:r.char,exact:r.exact,empty:!0,look:n}},N.makeOptional=function(e){return{char:e.char,exact:e.exact,empty:!0,look:{char:t.CharSet.all(e.char.maximum),exact:!0,edge:!0}}};class Z{constructor(e){this._currentWordBoundaries=[],e instanceof R?(this._ltrCache=e.getFirstConsumedCharLTR,this._rtlCache=e.getFirstConsumedCharRTL):(this._ltrCache=new WeakMap,this._rtlCache=new WeakMap)}isCurrentWordBoundary(e){return this._currentWordBoundaries.some((t=>t===e))}pushWordBoundary(e){this._currentWordBoundaries.push(e)}popWordBoundary(){this._currentWordBoundaries.pop()}getCached(e,t){return"ltr"===t?this._ltrCache.get(e):this._rtlCache.get(e)}setCached(e,t,r){"ltr"===t?this._ltrCache.set(e,r):this._rtlCache.set(e,r)}}function K(e,t,r){const n=new Z(r);return a(e)?H(e,t,r,n):V(e,t,r,n)}function H(e,t,r,n){return exports.FirstConsumedChars.union(e.map((e=>V(e,t,r,n))),r)}function V(e,t,n,a){let s=a.getCached(e,t);return void 0===s&&(s=function(e,t,n,a){switch(e.type){case"Assertion":return function(e,t,n,a){switch(e.kind){case"word":if(a.isCurrentWordBoundary(e))return s();{a.pushWordBoundary(e);const r=te(e,w(t),n,a);a.popWordBoundary();const o=exports.Chars.word(n);return r.edge?r.char.isDisjointWith(o)?i(e.negate):s():r.char.isDisjointWith(o)?i(e.negate):r.char.isSubsetOf(o)?i(!e.negate):s()}case"end":case"start":return S(e.kind)===t?n.multiline?c():o():s();case"lookahead":case"lookbehind":if(S(e.kind)===t){if(e.negate){if(x(e,(t=>t!==e&&"Assertion"===t.type)))return s();const r=H(e.alternatives,t,n,a),o=G(e.alternatives);return r.empty||!o?{char:exports.Chars.empty(n),empty:!1,exact:!0}:r.exact&&1===o.max?exports.FirstLookChars.toConsumed({char:r.char.negate(),edge:!0,exact:!0}):s()}{const r=H(e.alternatives,t,n,a);return exports.FirstLookChars.toConsumed(exports.FirstConsumedChars.toLook(r))}}return s();default:throw r(e)}function s(){return exports.FirstLookChars.toConsumed({char:exports.Chars.all(n),edge:!0,exact:!1})}function o(){return exports.FirstLookChars.toConsumed(exports.FirstLookChars.edge(n))}function c(){return exports.FirstLookChars.toConsumed({char:exports.Chars.lineTerminator(n),edge:!0,exact:!0})}function i(e){const t=exports.Chars.word(n);return exports.FirstLookChars.toConsumed({char:e?t.negate():t,edge:e,exact:!0})}}(e,t,n,a);case"Character":case"CharacterSet":case"CharacterClass":return{char:J(e,n),empty:!1,exact:!0};case"Quantifier":{if(0===e.max)return exports.FirstConsumedChars.emptyConcat(n);const r=V(e.element,t,n,a);return 0===e.min?exports.FirstConsumedChars.makeOptional(r):r}case"Alternative":{let r=e.elements;return"rtl"===t&&(r=[...r],r.reverse()),exports.FirstConsumedChars.concat(function*(){for(const e of r)yield V(e,t,n,a)}(),n)}case"CapturingGroup":case"Group":return H(e.alternatives,t,n,a);case"Backreference":{if(A(e))return exports.FirstConsumedChars.emptyConcat(n);let r=V(e.resolved,t,n,a);return r.exact&&r.char.size>1&&(r=Object.assign(Object.assign({},r),{exact:!1})),F(e)?r:exports.FirstConsumedChars.makeOptional(r)}default:throw r(e)}}(e,t,n,a),a.setCached(e,t,s)),s}function X(e,t,r){return Y(e,t,r,new Z(r))}function Y(e,t,r,n){return z(e,"next",exports.FirstConsumedChars.emptyConcat(r),{join:e=>exports.FirstConsumedChars.union(e,r),enter(e,t,a){const s=V(e,a,r,n);return exports.FirstConsumedChars.concat([t,s],r)},continueInto:()=>!1,continueAfter:(e,t)=>t.empty,continueOutside:(e,t,r)=>S(e.kind)!==r},t)}function ee(e,t,r){return te(e,t,r,new Z(r))}function te(e,t,r,n){return exports.FirstConsumedChars.toLook(Y(e,t,r,n))}function re(e,t,r,n){return z(e,"next",{char:exports.FirstConsumedChars.emptyConcat(r),contributors:[]},{join(e){const t=new Set;return e.forEach((e=>e.contributors.forEach((e=>t.add(e))))),{char:exports.FirstConsumedChars.union(e.map((e=>e.char)),r),contributors:[...t]}},enter(e,t,a){const s=V(e,a,r,n);return{char:exports.FirstConsumedChars.concat([t.char,s],r),contributors:[...t.contributors,e]}},continueInto:()=>!1,continueAfter:(e,t)=>t.char.empty,continueOutside:(e,t,r)=>S(e.kind)!==r},t)}function ne(e,t,r,n={}){const a=R.from(r);r=a;const{includeAfter:s=!1,looseGroups:o=!1}=n,c=a.getLongestPrefix,i=`${t},${s},${o}`;let u=c.get(i);void 0===u&&(u=new WeakMap,c.set(i,u));let h=u.get(e);return void 0===h&&(h=function(e,t,r,n){const{chars:a,complete:s}=oe(e,t,r,n);for(let e=0;e<a.length;e++)if(a[e].isEmpty)return a.slice(0,e);s&&r.includeAfter&&a.push(function(e,t,r){const{elements:n}=e,a="rtl"===t?0:n.length-1,s="ltr"===t?1:-1;let o=a;for(;o>=0&&o<n.length&&l(n[o]);)o-=s;return o>=0&&o<n.length?ee(n[o],t,r):exports.FirstConsumedChars.toLook(ie(e,t,r))}(e,t,n).char);return a}(e,t,{includeAfter:s,looseGroups:o},r),u.set(e,h)),h}const ae={chars:[],complete:!0},se={chars:[],complete:!1};function oe(e,t,r,n){const{elements:a}=e,s=[],o="ltr"===t?1:-1;for(let e="ltr"===t?0:a.length-1;e>=0&&e<a.length;e+=o){const o=ce(a[e],t,r,n);if(s.push(...o.chars),!o.complete)return{chars:s,complete:!1}}return{chars:s,complete:!0}}function ce(e,t,n,a){switch(e.type){case"Assertion":return ae;case"Character":case"CharacterClass":case"CharacterSet":return{chars:[J(e,a)],complete:!0};case"CapturingGroup":case"Group":return function(e,t,r,n){const a=e.alternatives.map((e=>oe(e,t,r,n)));if(1===a.length)return a[0];const s=[];let o=!0,c=0;for(let i=0;o;i++){const u=[];let l=!1;for(const e of a)i>=e.chars.length?l=!0:(u.push(e.chars[i]),i===e.chars.length-1&&!e.complete&&r.includeAfter&&(o=!1));if(0===u.length)break;if(l){if(o=!1,!r.includeAfter)break;u.push(ee(e,t,n).char)}else if(!r.looseGroups&&(o&&u.some((e=>!e.equals(u[0])))&&c++,c>=2&&(o=!1,!r.includeAfter)))break;const h=u[0].union(...u.slice(1));s.push(h)}return{chars:s,complete:o}}(e,t,n,a);case"Quantifier":return function(e,t,r,n){if(l(e))return ae;if(p(e)){if(!r.includeAfter)return se;return{chars:[exports.FirstConsumedChars.toLook(ie(e,t,n)).char],complete:!1}}const a=ce(e.element,t,r,n);if(!a.complete)return a;if(0===a.chars.length)throw new Error(`Expected the quantifier '${e.raw}' to consume at least one character.`);const s=[];for(let t=0;t<e.min;t++)if(s.push(...a.chars),s.length>1e3)return{chars:s,complete:!1};if(e.min===e.max)return{chars:s,complete:!0};if(r.includeAfter){const r=ee(e,t,n);s.push(r.char.union(a.chars[0]))}return{chars:s,complete:!1}}(e,t,n,a);case"Backreference":if(A(e))return ae;if(F(e)){return ce(e.resolved,t,Object.assign(Object.assign({},n),{includeAfter:!1}),a)}if(!n.includeAfter)return se;return{chars:[exports.FirstConsumedChars.toLook(ie(e,t,a)).char],complete:!1};default:r(e)}}function ie(e,t,r){const n=K(e,t,r);return n.empty?exports.FirstConsumedChars.concat([n,X(e,t,r)],r):n}function ue(e,t,r){return n(e),"unknown"===t?function(e,t){const r=he(e,"ltr",t),n=he(e,"rtl",t),a=pe([...r,...n],(e=>e)),s=[];for(const e of a){const t=new Set;for(const r of e)r.forEach((e=>t.add(e)));s.push([...t])}return s}(e,r):he(e,t,r)}const le={includeAfter:!0,looseGroups:!0};function he(e,r,n){const a=function(e){function t(r){let n=t.cache.get(r);return void 0===n&&(n=e(r),t.cache.set(r,n)),n}return t.cache=new Map,t}((e=>{let t=ne(e,r,n,le),a=0;for(let e=t.length-1;e>=0&&t[e].isAll;e--)a++;return a>0&&(t=t.slice(0,t.length-a)),t})),s=new Set;for(const t of e)a(t).forEach((e=>s.add(e)));const o=new t.CharBase(s),c=[];for(const t of e)c.push({characters:a(t).map((e=>o.split(e))),alternative:t});return function e(t,r){if(t.length<2)return[t];for(const e of t)if(r>=e.characters.length)return[t];const n=pe(t,(e=>e.characters[r])),a=[];for(const t of n)a.push(...e(t,r+1));return a}(c,0).map((e=>e.map((e=>e.alternative))))}function pe(e,t){if(e.length<2)return[e];const r=new c(e.length),n=new Map;for(let a=0;a<e.length;a++){const s=e[a];for(const e of t(s)){const t=n.get(e);void 0===t?n.set(e,a):r.makeEqual(a,t)}}const a=r.getEquivalenceSets(),s=[];for(let e=0;e<a.count;e++)s.push([]);for(let t=0;t<e.length;t++)s[a.indexes[t]].push(e[t]);return s}function fe(e,t,r,n,a){const s=ue(t,r,n);return!(!a&&!function(e,t,r){let n=0,a=0;for(const r of t)E(r)&&(e.has(r)?n++:a++);if(n>1||1===n&&0!==a)return!1;if(0!==a)return r.every((t=>!t.some(E)||t.every((t=>!e.has(t)))));if(0!==n)return r.every((e=>e.length<2||!e.some(E)));return!0}(e,t,s))&&s.every((t=>t.length<2||(!!t.every((t=>!e.has(t)))||(function(e){const t=G(e);return Boolean(t&&t.min===t.max)}(t)||function(e,t,r){const n=function(e,t){const r=me(e,"ltr",t),n=me(r.rest,"rtl",t);return{left:r.prefix,right:n.prefix,rest:n.rest}}(e.map((e=>e.elements)),r),a=[];for(const e of n.rest)a.push(...e);const s=exports.Chars.empty(r).union(...a.map((e=>de(e,r))));if(("ltr"===t?n.right:n.left).some((e=>e.isDisjointWith(s))))return!0;const o=e[0].parent;if("Pattern"===o.type||"Assertion"===o.type)return!1;return ee(o,t,r).char.isDisjointWith(s)}(t,r,n)))))}function me(e,t,r){const n=function(e,t,r){const n=[];for(let a=0;;a++){let s=null;for(const o of e){const e="ltr"===t?a:o.length-1-a;if(!(a>=0&&a<o.length))return n;{const t=o[e];switch(t.type){case"Character":case"CharacterClass":case"CharacterSet":if(null===s)s=J(t,r);else if(!s.equals(J(t,r)))return n;break;default:return n}}}if(null===s)throw new Error;n.push(s)}}(e,t,r);return 0===n.length?{prefix:n,rest:e}:{prefix:n,rest:e.map((e=>{const r="ltr"===t?n.length:0,a="ltr"===t?e.length:e.length-n.length;return e.slice(r,a)}))}}function de(e,t){const r=[];return x(e,(e=>("Character"===e.type||"CharacterClass"===e.type||"CharacterSet"===e.type?r.push(J(e,t)):"Backreference"!==e.type||A(e)||r.push(de(e.resolved,t)),!1)),(e=>"Assertion"!==e.type&&"CharacterClass"!==e.type)),exports.Chars.empty(t).union(...r)}exports.canReorder=function(e,t,r={}){t=P(t);const{ignoreCapturingGroups:a=!1,matchingDirection:s}=r,o=(c=e)instanceof Set?c:new Set(c);var c;if(o.size<2)return!0;n(o);const i=function(e){if(e.size<=1)return[...e];let t;for(const r of e){t=r;break}if(!t)throw new Error;const r=t.parent.alternatives;let n=e.size,a=0;for(let t=0;t<r.length;t++){const s=r[t];e.has(s)&&(n=Math.min(n,t),a=Math.max(a,t))}return r.slice(n,a+1)}(o),u=null!=s?s:v(i[0]);return"unknown"===u?fe(o,i,"ltr",t,a)&&fe(o,i,"rtl",t,a):fe(o,i,u,t,a)},exports.canReorderDirectional=fe,exports.containsCapturingGroup=E,exports.createCache=function(e){return new R(e)},exports.followPaths=z,exports.getCapturingGroupNumber=function(t){let r=0;try{throw e.visitRegExpAST(k(t),{onCapturingGroupEnter(e){if(r++,e===t)throw new Error}}),new Error("Unable to find the given capturing group in its parent pattern.")}catch(e){return r}},exports.getClosestAncestor=M,exports.getEffectiveMaximumRepetition=function(e){let t=1;for(let r=e.parent;r;r=r.parent)if("Quantifier"===r.type){if(t*=r.max,0===t)return 0}else if("Assertion"===r.type)break;return t},exports.getFirstCharAfter=ee,exports.getFirstCharAfterWithContributors=function(e,t,r){return function(e,t,r,n){const{char:a,contributors:s}=re(e,t,r,n);return{char:exports.FirstConsumedChars.toLook(a),contributors:s}}(e,t,r,new Z(r))},exports.getFirstConsumedChar=K,exports.getFirstConsumedCharAfter=X,exports.getFirstConsumedCharAfterWithContributors=function(e,t,r){return re(e,t,r,new Z(r))},exports.getLengthRange=G,exports.getLongestPrefix=ne,exports.getMatchingDirection=v,exports.getMatchingDirectionFromAssertionKind=S,exports.getPattern=k,exports.hasSomeAncestor=g,exports.hasSomeDescendant=x,exports.invertMatchingDirection=w,exports.isEmpty=function(e){return i(e,m)},exports.isEmptyBackreference=A,exports.isPotentiallyEmpty=function(e){return u(e,d)},exports.isPotentiallyZeroLength=p,exports.isStrictBackreference=F,exports.isZeroLength=l,exports.matchesAllCharacters=function(e,t){return"Character"!==e.type&&("CharacterClassRange"===e.type?0===e.min.value&&e.max.value===(t.unicode?1114111:65535):"CharacterSet"===e.type?"property"===e.kind?J(e,t).isAll:"any"===e.kind&&!!t.dotAll:!(!e.negate||0!==e.elements.length)||(e.negate?J(e.elements,t).isEmpty:J(e.elements,t).isAll))},exports.matchesNoCharacters=function(e,t){return"Character"!==e.type&&"CharacterClassRange"!==e.type&&("CharacterSet"===e.type?"property"===e.kind&&J(e,t).isEmpty:!e.negate&&0===e.elements.length||(e.negate?J(e.elements,t).isAll:J(e.elements,t).isEmpty))},exports.structurallyEqual=T,exports.toCache=P,exports.toCharSet=J; |
{ | ||
"name": "regexp-ast-analysis", | ||
"version": "0.4.0", | ||
"version": "0.4.1", | ||
"description": "A library for analysing JS RegExp", | ||
@@ -5,0 +5,0 @@ "main": "index", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
78912
6
1283