regexp-ast-analysis
Advanced tools
Comparing version 0.7.0 to 0.7.1
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@eslint-community/regexpp"),t=require("refa");function r(e){return e.unicode||!!e.unicodeSets}function n(e,t){throw new Error(t||e)}function s(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){e.maxChar=function(e){return r(e)?1114111:65535};const n=t.CharSet.empty(65535),s=t.CharSet.empty(1114111);e.empty=function(e){return r(e)?s:n};const a=t.CharSet.all(65535),c=t.CharSet.all(1114111);e.all=function(e){return r(e)?c:a};const o=t.JS.createCharSet([{kind:"any"}],{unicode:!1}).negate(),i=t.JS.createCharSet([{kind:"any"}],{unicode:!0}).negate();e.lineTerminator=function(e){return r(e)?i:o};const u=t.JS.createCharSet([{kind:"word",negate:!1}],{unicode:!1}),l=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 r(e)?e.ignoreCase?h:l:u};const p=t.JS.createCharSet([{kind:"digit",negate:!1}],{unicode:!1}),f=t.JS.createCharSet([{kind:"digit",negate:!1}],{unicode:!0});e.digit=function(e){return r(e)?f:p};const C=t.JS.createCharSet([{kind:"space",negate:!1}],{unicode:!1}),m=t.JS.createCharSet([{kind:"space",negate:!1}],{unicode:!0});e.space=function(e){return r(e)?m:C}}(exports.Chars||(exports.Chars={}));const a=Array.isArray;class c{get char(){return this._exactChars.union(this._inexactChars)}get exact(){return this._exactChars.isSupersetOf(this._inexactChars)}constructor(e){this._exactChars=e,this._inexactChars=e}add(e){e.exact?this._exactChars=this._exactChars.union(e.char):this._inexactChars=this._inexactChars.union(e.char)}static fromFlags(e){return new c(exports.Chars.empty(e))}static fromMaximum(e){return new c(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 i{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 u(e){return l.from(e)}class l{constructor(e){this.toCharSet=new WeakMap,this.toUnicodeSet=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,this.unicodeSets=!!e.unicodeSets}static from(e){return e instanceof l?e:new l(e)}}function h(e,r){if(!t.JS.isFlags(r))throw new Error("Invalid flags.");return a(e)?0===e.length?exports.Chars.empty(r):1===e.length?p(e[0],r):exports.Chars.empty(r).union(...e.map((e=>p(e,r)))):p(e,r)}function p(e,r){if(r instanceof l){let n=r.toCharSet.get(e);return void 0===n&&(n=t.JS.parseCharSet(e,r),r.toCharSet.set(e,n)),n}return t.JS.parseCharSet(e,r)}function f(e,r){if(!t.JS.isFlags(r))throw new Error("Invalid flags.");return a(e)?0===e.length?t.JS.UnicodeSet.empty(exports.Chars.maxChar(r)):1===e.length?C(e[0],r):t.JS.UnicodeSet.empty(exports.Chars.maxChar(r)).union(...e.map((e=>C(e,r)))):C(e,r)}function C(e,r){if(r instanceof l){let n=r.toUnicodeSet.get(e);return void 0===n&&(n=t.JS.parseUnicodeSet(e,r),r.toUnicodeSet.set(e,n)),n}return t.JS.parseUnicodeSet(e,r)}function m(e,t){switch(e.type){case"Character":case"ClassStringDisjunction":case"StringAlternative":return!1;case"CharacterClassRange":return 0===e.min.value&&e.max.value===exports.Chars.maxChar(t);case"CharacterSet":return"property"===e.kind?!e.strings&&h(e,t).isAll:"any"===e.kind&&!!t.dotAll;case"CharacterClass":return e.negate?e.elements.every((e=>d(e,t))):0!==e.elements.length&&(1===e.elements.length?m(e.elements[0],t):f(e,t).chars.isAll);case"ExpressionCharacterClass":return m(e.expression,t);case"ClassIntersection":return m(e.left,t)&&m(e.right,t);case"ClassSubtraction":return f(e,t).chars.isAll;default:return n(e)}}function d(e,t){switch(e.type){case"Character":case"CharacterClassRange":case"ClassStringDisjunction":case"StringAlternative":return!1;case"CharacterSet":return"property"===e.kind&&(!e.strings&&h(e,t).isEmpty);case"CharacterClass":return e.negate?0!==e.elements.length&&(1===e.elements.length?m(e.elements[0],t):f(e,t).isEmpty):e.elements.every((e=>d(e,t)));case"ExpressionCharacterClass":return d(e.expression,t);case"ClassIntersection":case"ClassSubtraction":return f(e,t).isEmpty;default:return n(e)}}function g(e,t){switch(e.type){case"Character":case"CharacterSet":case"CharacterClassRange":return!1;case"CharacterClass":return e.unicodeSets&&!e.negate&&e.elements.length>0&&e.elements.every((e=>g(e,t)));case"ExpressionCharacterClass":return!e.negate&&g(e.expression,t);case"ClassIntersection":case"ClassSubtraction":{const r=f(e,t);return r.chars.isEmpty&&1===r.accept.words.length&&r.accept.hasEmptyWord}case"ClassStringDisjunction":return e.alternatives.every((e=>g(e,t)));case"StringAlternative":return 0===e.elements.length;default:throw n(e)}}function x(e){switch(e.type){case"Character":case"CharacterSet":case"CharacterClassRange":return!1;case"CharacterClass":return e.unicodeSets&&!e.negate&&e.elements.some(x);case"ExpressionCharacterClass":return!e.negate&&x(e.expression);case"ClassIntersection":return x(e.left)&&x(e.right);case"ClassSubtraction":return x(e.left)&&!x(e.right);case"ClassStringDisjunction":return e.alternatives.some(x);case"StringAlternative":return 0===e.elements.length;default:throw n(e)}}function y(e,t){return a(e)?e.every(t):t(e)}function S(e,t){return a(e)?e.some(t):t(e)}function v(e,t){return y(e,(e=>w(e,t)))}function w(e,t){switch(e.type){case"Alternative":return e.elements.every((e=>w(e,t)));case"Assertion":return!0;case"Character":case"CharacterSet":case"CharacterClassRange":case"CharacterClass":case"ExpressionCharacterClass":case"ClassIntersection":case"ClassSubtraction":case"ClassStringDisjunction":case"StringAlternative":return g(e,t);case"Quantifier":return 0===e.max||w(e.element,t);case"Backreference":return j(e,t);case"CapturingGroup":case"Group":return e.alternatives.length>0&&e.alternatives.every((e=>w(e,t)));default:throw n(e)}}function k(e,t,r){return function e(s){switch(s.type){case"Alternative":return s.elements.every(e);case"Assertion":return!0;case"Backreference":return A(s,t,r);case"Character":case"CharacterSet":case"CharacterClass":case"ExpressionCharacterClass":return x(s);case"CapturingGroup":case"Group":return s.alternatives.some(e);case"Quantifier":return 0===s.min||e(s.element);default:throw n(s)}}(e)}function E(e,t){switch(e.type){case"Alternative":return e.elements.every((e=>E(e,t)));case"Assertion":return!1;case"Backreference":return j(e,t);case"Character":case"CharacterSet":case"CharacterClassRange":case"CharacterClass":case"ExpressionCharacterClass":case"ClassIntersection":case"ClassSubtraction":case"ClassStringDisjunction":case"StringAlternative":return g(e,t);case"CapturingGroup":case"Group":return e.alternatives.length>0&&e.alternatives.every((e=>E(e,t)));case"Quantifier":return 0===e.max||E(e.element,t);default:throw n(e)}}function A(e,t,r){return!!j(e,r)||!!F(e.resolved,(e=>e===t))&&(!W(e)||k(e.resolved,t,r))}function F(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 b(e,t,r){return"function"==typeof t?_(e,t,r):r?_(e,(e=>e===t),r):e===t||F(t,e)}function _(e,t,r){if(t(e))return!0;if(r&&!r(e))return!1;switch(e.type){case"Alternative":case"CharacterClass":case"StringAlternative":return e.elements.some((e=>_(e,t,r)));case"Assertion":return("lookahead"===e.kind||"lookbehind"===e.kind)&&e.alternatives.some((e=>_(e,t,r)));case"CapturingGroup":case"ClassStringDisjunction":case"Group":case"Pattern":return e.alternatives.some((e=>_(e,t,r)));case"ClassIntersection":case"ClassSubtraction":return _(e.left,t,r)||_(e.right,t,r);case"ExpressionCharacterClass":return _(e.expression,t,r);case"CharacterClassRange":return _(e.min,t,r)||_(e.max,t,r);case"Quantifier":return _(e.element,t,r);case"RegExpLiteral":return _(e.pattern,t,r)||_(e.flags,t,r);case"Backreference":case"Character":case"CharacterSet":case"Flags":return!1;default:return n(e)}}function G(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 L(e){let t;return F(e,(e=>"Assertion"===e.type&&(t=e,!0))),void 0===t||"lookahead"===t.kind?"ltr":"rtl"}function R(e){return"ltr"===e?"rtl":"ltr"}function I(e){return"end"===e||"lookahead"===e?"ltr":"rtl"}function j(e,t){const r=e.resolved,n=$(e,r);if(n===r)return!0;if("Alternative"!==n.type)return!0;const s=new Set;for(let t=e;t;t=t.parent)s.add(t);return!function e(t){const r=t.parent;switch(r.type){case"Alternative":{const n=r.elements.indexOf(t);let a;if(a="ltr"===L(t)?r.elements.slice(n+1):r.elements.slice(0,n),a.some((e=>s.has(e))))return!0;const c=r.parent;return"Pattern"!==c.type&&(("Assertion"!==c.type||!c.negate)&&e(c))}case"Quantifier":return e(r)}}(r)||v(r,t)}function W(e){const t=e.resolved,r=$(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 s=r.elements.indexOf(t);let a;if(a="ltr"===L(t)?r.elements.slice(s+1):r.elements.slice(0,s),a.some((e=>n.has(e))))return!0;const c=r.parent;return"Pattern"!==c.type&&(("Assertion"!==c.type||!c.negate)&&(!(c.alternatives.length>1)&&e(c)))}case"Quantifier":return 0!==r.min&&e(r)}}(t)}function B(e){return b(e,D)}function D(e){return"CapturingGroup"===e.type}const M={min:0,max:0},J={min:1,max:1};function O(e,t){return a(e)?P(e,t):U(e,t)}function P(e,t){let r=1/0,n=0;for(const s of e){const e=U(s,t);r=Math.min(r,e.min),n=Math.max(n,e.max)}if(r>n)throw new RangeError("Expected the alternatives array to have at least one alternative.");return{min:r,max:n}}function Q(e){let t=1/0,r=-1/0;return e.chars.isEmpty||(t=r=1),e.accept.isEmpty||(t=Math.min(t,e.accept.words[0].length),r=Math.max(r,e.accept.words[e.accept.words.length-1].length)),t>r?J:{min:t,max:r}}function U(e,t){switch(e.type){case"Assertion":return M;case"Character":case"CharacterClassRange":return J;case"CharacterSet":return"property"===e.kind&&e.strings?Q(f(e,t)):J;case"CharacterClass":return!e.unicodeSets||e.negate||0===e.elements.length?J:P(e.elements,t);case"ExpressionCharacterClass":return e.negate?J:U(e.expression,t);case"ClassIntersection":case"ClassSubtraction":return Q(f(e,t));case"StringAlternative":return{min:e.elements.length,max:e.elements.length};case"Quantifier":{if(0===e.max)return M;const r=U(e.element,t);return 0===r.max?M:{min:r.min*e.min,max:r.max*e.max}}case"Alternative":{let r=0,n=0;for(const s of e.elements){const e=U(s,t);r+=e.min,n+=e.max}return{min:r,max:n}}case"CapturingGroup":case"Group":case"ClassStringDisjunction":return P(e.alternatives,t);case"Backreference":if(j(e,t))return M;{const r=U(e.resolved,t);return r.min>0&&!W(e)?{min:0,max:r.max}:r}default:throw n(e)}}function q(e,t){return a(e)?T(e,t):z(e,t)}function T(e,t){if(0===e.length)throw new RangeError("Expected the alternatives array to have at least one alternative.");return e.some((e=>z(e,t)))}function z(e,t){switch(e.type){case"Assertion":return!0;case"Character":case"CharacterClassRange":return!1;case"CharacterSet":return"property"===e.kind&&e.strings,!1;case"CharacterClass":return!(!e.unicodeSets||e.negate||0===e.elements.length)&&T(e.elements,t);case"ExpressionCharacterClass":return!e.negate&&z(e.expression,t);case"ClassIntersection":case"ClassSubtraction":return f(e,t).hasEmptyWord;case"Quantifier":return 0===e.min||z(e.element,t);case"Alternative":return e.elements.every((e=>z(e,t)));case"StringAlternative":return 0===e.elements.length;case"CapturingGroup":case"Group":case"ClassStringDisjunction":return T(e.alternatives,t);case"Backreference":return j(e,t)||!W(e)||z(e.resolved,t);default:throw n(e)}}function $(...e){if(0!==e.length)return e.reduce(Z)}function Z(e,t){if(e===t)return e;if(e.parent&&e.parent===t.parent)return e.parent;{const r=N(e),n=N(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 s=r[r.length-1].parent;if(s)return s;throw new Error("The two nodes are not part of the same tree.")}}function N(e){const t=[];for(let r=e;r;r=r.parent)t.push(r);return t}function K(e,t){if(e==t)return!0;if(!e||!t||e.type!=t.type)return!1;switch(e.type){case"Alternative":case"StringAlternative":{const r=t;return H(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&&H(e.alternatives,r.alternatives)}return e.raw===r.raw}return!1}case"Backreference":{const r=t;return K(e.resolved,r.resolved)&&W(e)==W(r)}case"Character":{const r=t;return e.value===r.value}case"CharacterClass":{const r=t;return e.negate===r.negate&&e.unicodeSets===r.unicodeSets&&H(e.elements,r.elements)}case"CharacterClassRange":{const r=t;return K(e.min,r.min)&&K(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.value===r.value:e.raw===r.raw}case"ExpressionCharacterClass":{const r=t;return e.negate===r.negate&&K(e.expression,r.expression)}case"ClassIntersection":case"ClassSubtraction":{const r=t;return K(e.left,r.left)&&K(e.right,r.right)}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&&e.unicodeSets===r.unicodeSets}case"ClassStringDisjunction":case"CapturingGroup":case"Group":case"Pattern":{const r=t;return H(e.alternatives,r.alternatives)}case"Quantifier":{const r=t;return e.min===r.min&&e.max===r.max&&e.greedy===r.greedy&&K(e.element,r.element)}case"RegExpLiteral":{const r=t;return K(e.flags,r.flags)&&K(e.pattern,r.pattern)}default:throw n(e)}}function H(e,t){if(e.length!==t.length)return!1;for(let r=0;r<e.length;r++)if(!K(e[r],t[r]))return!1;return!0}function V(e,t,r,s,a){function c(e,t,r){var n,a;s.enter&&(t=s.enter(e,t,r));if(null===(a=null===(n=s.continueInto)||void 0===n?void 0:n.call(s,e,t,r))||void 0===a||a)switch(e.type){case"Assertion":if("lookahead"===e.kind||"lookbehind"===e.kind){const n=I(e.kind),a=s.join(e.alternatives.map((e=>o(e,X(s,t,r),n))),n);t=l(t,n,"assertion"),s.assert&&(t=s.assert(t,r,a,n))}break;case"Group":case"CapturingGroup":t=s.join(e.alternatives.map((e=>o(e,X(s,t,r),r))),r);break;case"Quantifier":0===e.max||(t=0===e.min?s.join([t,c(e.element,X(s,t,r),r)],r):c(e.element,t,r))}return s.leave&&(t=s.leave(e,t,r)),t}function o(e,t,r){var n,a;let o="ltr"===r?0:e.elements.length-1;const i="ltr"===r?1:-1;let u;for(;u=e.elements[o];o+=i){t=c(u,t,r);if(!(null===(a=null===(n=s.continueAfter)||void 0===n?void 0:n.call(s,u,t,r))||void 0===a||a))break}return t}function i(e,t,r){var a,c;const o=e.parent;if("CharacterClass"===o.type||"CharacterClassRange"===o.type||"ClassIntersection"===o.type||"ClassSubtraction"===o.type||"ExpressionCharacterClass"===o.type||"StringAlternative"===o.type)throw new Error("The given element cannot be part of a character class.");if(!(null===(c=null===(a=s.continueAfter)||void 0===a?void 0:a.call(s,e,t,r))||void 0===c||c))return!1;if("Quantifier"===o.type)return o.max<=1?i(o,t,r):[o,i(o,t,r)];{const s=o.elements.indexOf(e)+("ltr"===r?1:-1),a=o.elements[s];if(a)return a;{const e=o.parent;if("Pattern"===e.type)return"pattern";if("Assertion"===e.type)return u(e,t,r)?i(e,t,r):"assertion";if("CapturingGroup"===e.type||"Group"===e.type)return i(e,t,r);throw n(e)}}}function u(e,t,r){return!!s.continueOutside&&s.continueOutside(e,t,r)}function l(e,t,r){return s.endPath?s.endPath(e,t,r):e}if(a||(a=L(e)),"Alternative"===e.type)if(0===e.elements.length&&(t="next"),"enter"===t)h=e,e="ltr"===a?h.elements[0]:h.elements[h.elements.length-1];else{const t=e.parent;if("Pattern"===t.type)return l(r,a,"pattern");if("Assertion"===t.type&&!u(t,r,a))return l(r,a,"assertion");e=t}var h;return"enter"===t&&(r=c(e,r,a)),function(e,t,r){for(;;){let n=i(e,t,r);for(;Array.isArray(n);){const[e,a]=n;t=s.join([t,c(e,X(s,t,r),r)],r),n=a}if(!1===n)return t;if("assertion"===n||"pattern"===n)return l(t,r,n);t=c(n,t,r),e=n}}(e,r,a)}function X(e,t,r){return e.fork?e.fork(t,r):t}var Y,ee;exports.FirstLookChars=void 0,(Y=exports.FirstLookChars||(exports.FirstLookChars={})).all=function(e){return{char:exports.Chars.all(e),exact:!0,edge:!0}},Y.edge=function(e){return{char:exports.Chars.empty(e),exact:!0,edge:!0}},Y.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,(ee=exports.FirstConsumedChars||(exports.FirstConsumedChars={})).emptyConcat=function(e){return{char:exports.Chars.empty(e),exact:!0,empty:!0,look:exports.FirstLookChars.all(e)}},ee.emptyUnion=function(e){return{char:exports.Chars.empty(e),exact:!0,empty:!1}},ee.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}},ee.union=function(e,t){const r=c.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=c.fromFlags(t);let s=!1;for(const t of n)e.add(t),s=s||t.edge;return{char:r.char,exact:r.exact,empty:!0,look:{char:e.char,exact:e.exact,edge:s}}}return{char:r.char,exact:r.exact,empty:!1}},ee.concat=function(e,t){const r=c.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}},ee.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 te{constructor(e){this._currentWordBoundaries=[],e instanceof l?(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 re(e,t,r){const n=new te(r);return a(e)?ne(e,t,r,n):se(e,t,r,n)}function ne(e,t,r,n){return exports.FirstConsumedChars.union(e.map((e=>se(e,t,r,n))),r)}function se(e,r,s,a){let c=a.getCached(e,r);return void 0===c&&(c=function(e,r,s,a){switch(e.type){case"Assertion":return function(e,t,r,s){switch(e.kind){case"word":if(s.isCurrentWordBoundary(e))return a();{s.pushWordBoundary(e);const n=ie(e,R(t),r,s);s.popWordBoundary();const c=exports.Chars.word(r);return n.edge?n.char.isDisjointWith(c)?i(e.negate):a():n.char.isDisjointWith(c)?i(e.negate):n.char.isSubsetOf(c)?i(!e.negate):a()}case"end":case"start":return I(e.kind)===t?r.multiline?o():c():a();case"lookahead":case"lookbehind":if(I(e.kind)===t){if(e.negate){if(b(e,(t=>t!==e&&"Assertion"===t.type)))return a();const n=ne(e.alternatives,t,r,s),c=O(e.alternatives,r);return n.empty||!c?{char:exports.Chars.empty(r),empty:!1,exact:!0}:n.exact&&1===c.max?exports.FirstLookChars.toConsumed({char:n.char.negate(),edge:!0,exact:!0}):a()}{const n=ne(e.alternatives,t,r,s);return exports.FirstLookChars.toConsumed(exports.FirstConsumedChars.toLook(n))}}return a();default:throw n(e)}function a(){return exports.FirstLookChars.toConsumed({char:exports.Chars.all(r),edge:!0,exact:!1})}function c(){return exports.FirstLookChars.toConsumed(exports.FirstLookChars.edge(r))}function o(){return exports.FirstLookChars.toConsumed({char:exports.Chars.lineTerminator(r),edge:!0,exact:!0})}function i(e){const t=exports.Chars.word(r);return exports.FirstLookChars.toConsumed({char:e?t.negate():t,edge:e,exact:!0})}}(e,r,s,a);case"Character":case"CharacterSet":case"CharacterClass":case"ExpressionCharacterClass":{const n=f(e,s);if(n.accept.isEmpty)return{char:n.chars,empty:!1,exact:!0};{const e=new Set;if("ltr"===r)for(const t of n.accept.words)t.length>0&&e.add(t[0]);else for(const t of n.accept.words)t.length>0&&e.add(t[t.length-1]);if(!t.JS.isFlags(s))throw new Error("Invalid flags");const a={char:n.chars.union(t.JS.createCharSet(e,s)),empty:!1,exact:!0};return n.hasEmptyWord?exports.FirstConsumedChars.makeOptional(a):a}}case"Quantifier":{if(0===e.max)return exports.FirstConsumedChars.emptyConcat(s);const t=se(e.element,r,s,a);return 0===e.min?exports.FirstConsumedChars.makeOptional(t):t}case"Alternative":{let t=e.elements;return"rtl"===r&&(t=[...t],t.reverse()),exports.FirstConsumedChars.concat(function*(){for(const e of t)yield se(e,r,s,a)}(),s)}case"CapturingGroup":case"Group":return ne(e.alternatives,r,s,a);case"Backreference":{if(j(e,s))return exports.FirstConsumedChars.emptyConcat(s);let t=se(e.resolved,r,s,a);return t.exact&&t.char.size>1&&(t=Object.assign(Object.assign({},t),{exact:!1})),W(e)?t:exports.FirstConsumedChars.makeOptional(t)}default:throw n(e)}}(e,r,s,a),a.setCached(e,r,c)),c}function ae(e,t,r){return ce(e,t,r,new te(r))}function ce(e,t,r,n){return V(e,"next",exports.FirstConsumedChars.emptyConcat(r),{join:e=>exports.FirstConsumedChars.union(e,r),enter(e,t,s){const a=se(e,s,r,n);return exports.FirstConsumedChars.concat([t,a],r)},continueInto:()=>!1,continueAfter:(e,t)=>t.empty,continueOutside:(e,t,r)=>I(e.kind)!==r},t)}function oe(e,t,r){return ie(e,t,r,new te(r))}function ie(e,t,r,n){return exports.FirstConsumedChars.toLook(ce(e,t,r,n))}function ue(e,t,r,n){return V(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,s){const a=se(e,s,r,n);return{char:exports.FirstConsumedChars.concat([t.char,a],r),contributors:[...t.contributors,e]}},continueInto:()=>!1,continueAfter:(e,t)=>t.char.empty,continueOutside:(e,t,r)=>I(e.kind)!==r},t)}function le(e,t,r,n={}){const s=l.from(r);r=s;const{includeAfter:a=!1,onlyInside:c=!1,looseGroups:o=!1}=n,i=s.getLongestPrefix,u=`${t},${a},${c},${o}`;let h=i.get(u);void 0===h&&(h=new WeakMap,i.set(u,h));let p=h.get(e);return void 0===p&&(p=function(e,t,r,n){const{chars:s,complete:a}=fe(e,t,r,n);for(let e=0;e<s.length;e++)if(s[e].isEmpty)return s.slice(0,e);if(a&&r.includeAfter&&!r.onlyInside)return[...s,ge(e,t,n).char];return s}(e,t,{includeAfter:a,onlyInside:c,looseGroups:o,root:e},r),h.set(e,p)),p}const he={chars:[],complete:!0},pe={chars:[],complete:!1};function fe(e,t,r,n){const{elements:s}=e,a=[],c="ltr"===t?1:-1;for(let e="ltr"===t?0:s.length-1;e>=0&&e<s.length;e+=c){const c=Ce(s[e],t,r,n);if(a.push(...c.chars),!c.complete)return{chars:a,complete:!1}}return{chars:a,complete:!0}}function Ce(e,t,r,s){switch(e.type){case"Assertion":return he;case"Character":case"CharacterClass":case"CharacterSet":case"ExpressionCharacterClass":{const n=f(e,s);if(n.accept.isEmpty)return{chars:[n.chars],complete:!0};{const a=[];n.chars.isEmpty||a.push({chars:[n.chars],complete:!0});for(const e of n.accept.wordSets)a.push({chars:e,complete:!0});return me(e,a,t,r,s)}}case"CapturingGroup":case"Group":return function(e,t,r,n){const s=e.alternatives.map((e=>fe(e,t,r,n)));return me(e,s,t,r,n)}(e,t,r,s);case"Quantifier":return function(e,t,r,n){if(v(e,n))return he;if(q(e,n)){if(!xe(e,r,t,n))return pe;return{chars:[exports.FirstConsumedChars.toLook(de(e,t,n)).char],complete:!1}}const s=Ce(e.element,t,r,n);if(!s.complete)return s;if(0===s.chars.length)throw new Error(`Expected the quantifier '${e.raw}' to consume at least one character.`);const a=[];for(let t=0;t<e.min;t++)if(a.push(...s.chars),a.length>1e3)return{chars:a,complete:!1};if(e.min===e.max)return{chars:a,complete:!0};if(ye(e,r,t,n)){const r=oe(e,t,n);a.push(r.char.union(s.chars[0]))}return{chars:a,complete:!1}}(e,t,r,s);case"Backreference":if(j(e,s))return he;if(W(e)){return Ce(e.resolved,t,Object.assign(Object.assign({},r),{includeAfter:!1}),s)}if(!xe(e,r,t,s))return pe;return{chars:[exports.FirstConsumedChars.toLook(de(e,t,s)).char],complete:!1};default:n(e)}}function me(e,t,r,n,s){if(1===t.length)return t[0];const a=[];let c=!0,o=0;for(let i=0;c;i++){const u=[];let l=!1;for(const e of t)i>=e.chars.length?l=!0:(u.push(e.chars[i]),i===e.chars.length-1&&!e.complete&&n.includeAfter&&(c=!1));if(0===u.length)break;if(l){if(c=!1,!ye(e,n,r,s))break;u.push(oe(e,r,s).char)}else if(!n.looseGroups&&(c&&u.some((e=>!e.equals(u[0])))&&o++,o>=2&&(c=!1,!n.includeAfter)))break;const h=u[0].union(...u.slice(1));a.push(h)}return{chars:a,complete:c}}function de(e,t,r){const n=re(e,t,r);return n.empty?exports.FirstConsumedChars.concat([n,ae(e,t,r)],r):n}function ge(e,t,r){const{elements:n}=e,s="ltr"===t?1:-1;let a="rtl"===t?0:n.length-1;for(;a>=0&&a<n.length&&v(n[a],r);)a-=s;return a>=0&&a<n.length?oe(n[a],t,r):exports.FirstConsumedChars.toLook(de(e,t,r))}function xe(e,t,r,n){return!!t.includeAfter&&(!t.onlyInside||function(e,t,r,n){return!q(e,n)||Se(e,t,r,n)}(e,r,t.root,n))}function ye(e,t,r,n){return!!t.includeAfter&&(!t.onlyInside||Se(e,r,t.root,n))}function Se(e,t,r,n){const s=e.parent;if("CharacterClass"===s.type||"CharacterClassRange"===s.type||"ClassIntersection"===s.type||"ClassSubtraction"===s.type||"ExpressionCharacterClass"===s.type||"StringAlternative"===s.type)throw new Error("Expected an element outside a character class.");if("Quantifier"===s.type)return Se(s,t,r,n);const a="ltr"===t?1:-1;for(let t=s.elements.indexOf(e)+a;t>=0&&t<s.elements.length;t+=a){if(!q(s.elements[t],n))return!0}if(s===r)return!1;const c=s.parent;if("Pattern"===c.type)throw new Error("Expected the given element to be a descendant of the root alternative.");if("Assertion"===c.type)throw new Error;return Se(c,t,r,n)}function ve(e,t,r){return s(e),"unknown"===t?function(e,t){const r=ke(e,"ltr",t),n=ke(e,"rtl",t),s=Ee([...r,...n],(e=>e)),a=[];for(const e of s){const t=new Set;for(const r of e)r.forEach((e=>t.add(e)));a.push([...t])}return a}(e,r):ke(e,t,r)}const we={includeAfter:!0,looseGroups:!0};function ke(e,r,n){const s=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=le(e,r,n,we),s=0;for(let e=t.length-1;e>=0&&t[e].isAll;e--)s++;return s>0&&(t=t.slice(0,t.length-s)),t})),a=new Set;for(const t of e)s(t).forEach((e=>a.add(e)));const c=new t.CharBase(a),o=[];for(const t of e)o.push({characters:s(t).map((e=>c.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=Ee(t,(e=>e.characters[r])),s=[];for(const t of n)s.push(...e(t,r+1));return s}(o,0).map((e=>e.map((e=>e.alternative))))}function Ee(e,t){if(e.length<2)return[e];const r=new i(e.length),n=new Map;for(let s=0;s<e.length;s++){const a=e[s];for(const e of t(a)){const t=n.get(e);void 0===t?n.set(e,s):r.makeEqual(s,t)}}const s=r.getEquivalenceSets(),a=[];for(let e=0;e<s.count;e++)a.push([]);for(let t=0;t<e.length;t++)a[s.indexes[t]].push(e[t]);return a}function Ae(e,r){const n=[];let s=!0;b(e,(e=>{if("Character"===e.type||"CharacterClass"===e.type||"CharacterSet"===e.type||"ExpressionCharacterClass"===e.type){const a=f(e,r);if(n.push(a.chars),!a.accept.isEmpty){const e=new Set;for(const t of a.accept.words)for(const r of t)e.add(r);if(!t.JS.isFlags(r))throw new Error("Invalid flags.");n.push(t.JS.createCharSet(e,r))}s=s&&!a.isEmpty}else if("Backreference"===e.type&&!j(e,r)){const t=Ae(e.resolved,r);n.push(t.chars),s=s&&t.exact&&t.chars.size<2}return!1}),(e=>"CharacterClass"!==e.type&&"ExpressionCharacterClass"!==e.type&&("Assertion"!==e.type||(s=!1,!1))));return{chars:exports.Chars.empty(r).union(...n),exact:s}}function Fe(e,t,r,n,s){const a=ve(t,r,n);return!(!s&&!function(e,t,r){let n=0,s=0;for(const r of t)B(r)&&(e.has(r)?n++:s++);if(n>1||1===n&&0!==s)return!1;if(0!==s)return r.every((t=>!t.some(B)||t.every((t=>!e.has(t)))));if(0!==n)return r.every((e=>e.length<2||!e.some(B)));return!0}(e,t,a))&&a.every((t=>t.length<2||(!!t.every((t=>!e.has(t)))||(function(e,t){const r=O(e,t);return Boolean(r&&r.min===r.max)}(t,n)||function(e,t,r){const n=function(e,t){const r=be(e,"ltr",t),n=be(r.rest,"rtl",t);return{left:r.prefix,right:n.prefix,rest:n.rest}}(e.map((e=>e.elements)),r),s=[];for(const e of n.rest)s.push(...e);const a=exports.Chars.empty(r).union(...s.map((e=>Ae(e,r).chars))),c="ltr"===t?n.right:n.left;if(c.some((e=>e.isDisjointWith(a))))return!0;const o=e[0].parent;if("Pattern"===o.type||"Assertion"===o.type)return!1;return oe(o,t,r).char.isDisjointWith(a)}(t,r,n)))))}function be(e,t,r){const n=function(e,t,r){const n=[];for(let s=0;;s++){let a=null;for(const c of e){const e="ltr"===t?s:c.length-1-s;if(!(s>=0&&s<c.length))return n;{const t=c[e];switch(t.type){case"Character":case"CharacterClass":case"CharacterSet":case"ExpressionCharacterClass":{const e=f(t,r);if(!e.accept.isEmpty)return n;if(null===a)a=e.chars;else if(!a.equals(e.chars))return n;break}default:return n}}}if(null===a)throw new Error;n.push(a)}}(e,t,r);return 0===n.length?{prefix:n,rest:e}:{prefix:n,rest:e.map((e=>{const r="ltr"===t?n.length:0,s="ltr"===t?e.length:e.length-n.length;return e.slice(r,s)}))}}exports.canReorder=function(e,t,r={}){t=u(t);const{ignoreCapturingGroups:n=!1,matchingDirection:a}=r,c=(o=e)instanceof Set?o:new Set(o);var o;if(c.size<2)return!0;s(c);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,s=0;for(let t=0;t<r.length;t++){const a=r[t];e.has(a)&&(n=Math.min(n,t),s=Math.max(s,t))}return r.slice(n,s+1)}(c),l=null!=a?a:L(i[0]);return"unknown"===l?Fe(c,i,"ltr",t,n)&&Fe(c,i,"rtl",t,n):Fe(c,i,l,t,n)},exports.canReorderDirectional=Fe,exports.containsCapturingGroup=B,exports.createCache=function(e){return new l(e)},exports.followPaths=V,exports.getCapturingGroupNumber=function(t){let r=0;try{throw e.visitRegExpAST(G(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=$,exports.getConsumedChars=Ae,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=oe,exports.getFirstCharAfterWithContributors=function(e,t,r){return function(e,t,r,n){const{char:s,contributors:a}=ue(e,t,r,n);return{char:exports.FirstConsumedChars.toLook(s),contributors:a}}(e,t,r,new te(r))},exports.getFirstConsumedChar=re,exports.getFirstConsumedCharAfter=ae,exports.getFirstConsumedCharAfterWithContributors=function(e,t,r){return ue(e,t,r,new te(r))},exports.getLengthRange=O,exports.getLongestPrefix=le,exports.getMatchingDirection=L,exports.getMatchingDirectionFromAssertionKind=I,exports.getPattern=G,exports.hasSomeAncestor=F,exports.hasSomeDescendant=b,exports.hasStrings=function e(t,r){switch(t.type){case"Character":case"CharacterClassRange":return!1;case"CharacterSet":return"property"===t.kind&&t.strings;case"CharacterClass":return!(t.negate||!t.unicodeSets)&&t.elements.some((t=>e(t,r)));case"ExpressionCharacterClass":return e(t.expression,r);case"ClassIntersection":case"ClassSubtraction":return!f(t,r).accept.isEmpty;case"ClassStringDisjunction":return t.alternatives.some((t=>e(t,r)));case"StringAlternative":return 1!==t.elements.length;default:return n(t)}},exports.invertMatchingDirection=R,exports.isEmpty=function(e,t){return y(e,(e=>E(e,t)))},exports.isEmptyBackreference=j,exports.isLengthRangeMinZero=q,exports.isPotentiallyEmpty=function(e,t){if(!a(e))switch(e.type){case"Character":case"CharacterSet":case"CharacterClassRange":case"CharacterClass":case"ExpressionCharacterClass":case"ClassIntersection":case"ClassSubtraction":case"ClassStringDisjunction":case"StringAlternative":return x(e)}return S(e,(e=>function(e,t){return r(e);function r(s){switch(s.type){case"Alternative":return s.elements.every(r);case"Assertion":return!1;case"Backreference":return A(s,e,t);case"Character":case"CharacterSet":case"CharacterClass":case"ExpressionCharacterClass":return x(s);case"CapturingGroup":case"Group":return s.alternatives.some(r);case"Quantifier":return 0===s.min||r(s.element);default:throw n(s)}}}(e,t)))},exports.isPotentiallyZeroLength=function(e,t){if(!a(e))switch(e.type){case"Character":case"CharacterSet":case"CharacterClassRange":case"CharacterClass":case"ExpressionCharacterClass":case"ClassIntersection":case"ClassSubtraction":case"ClassStringDisjunction":case"StringAlternative":return x(e)}return S(e,(e=>k(e,e,t)))},exports.isStrictBackreference=W,exports.isZeroLength=v,exports.matchesAllCharacters=m,exports.matchesNoCharacters=d,exports.structurallyEqual=K,exports.toCache=u,exports.toCharSet=h,exports.toUnicodeSet=f; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@eslint-community/regexpp"),t=require("refa");function r(e){return e.unicode||!!e.unicodeSets}function n(e,t){throw new Error(t||e)}function s(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){e.maxChar=function(e){return r(e)?1114111:65535};const n=t.CharSet.empty(65535),s=t.CharSet.empty(1114111);e.empty=function(e){return r(e)?s:n};const a=t.CharSet.all(65535),o=t.CharSet.all(1114111);e.all=function(e){return r(e)?o:a};const c=t.JS.createCharSet([{kind:"any"}],{unicode:!1}).negate(),i=t.JS.createCharSet([{kind:"any"}],{unicode:!0}).negate();e.lineTerminator=function(e){return r(e)?i:c};const u=t.JS.createCharSet([{kind:"word",negate:!1}],{unicode:!1}),l=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 r(e)?e.ignoreCase?h:l:u};const p=t.JS.createCharSet([{kind:"digit",negate:!1}],{unicode:!1}),f=t.JS.createCharSet([{kind:"digit",negate:!1}],{unicode:!0});e.digit=function(e){return r(e)?f:p};const C=t.JS.createCharSet([{kind:"space",negate:!1}],{unicode:!1}),m=t.JS.createCharSet([{kind:"space",negate:!1}],{unicode:!0});e.space=function(e){return r(e)?m:C}}(exports.Chars||(exports.Chars={}));const a=Array.isArray;class o{get char(){return this._exactChars.union(this._inexactChars)}get exact(){return this._exactChars.isSupersetOf(this._inexactChars)}constructor(e){this._exactChars=e,this._inexactChars=e}add(e){e.exact?this._exactChars=this._exactChars.union(e.char):this._inexactChars=this._inexactChars.union(e.char)}static fromFlags(e){return new o(exports.Chars.empty(e))}static fromMaximum(e){return new o(t.CharSet.empty(e))}}function c(e,t){const r=e.char.intersect(t.char);return{char:r,exact:e.exact&&t.exact||r.isEmpty}}class i{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 u(e){return l.from(e)}class l{constructor(e){this.toCharSet=new WeakMap,this.toUnicodeSet=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,this.unicodeSets=!!e.unicodeSets}static from(e){return e instanceof l?e:new l(e)}}function h(e,r){if(!t.JS.isFlags(r))throw new Error("Invalid flags.");return a(e)?0===e.length?exports.Chars.empty(r):1===e.length?p(e[0],r):exports.Chars.empty(r).union(...e.map((e=>p(e,r)))):p(e,r)}function p(e,r){if(r instanceof l){let n=r.toCharSet.get(e);return void 0===n&&(n=t.JS.parseCharSet(e,r),r.toCharSet.set(e,n)),n}return t.JS.parseCharSet(e,r)}function f(e,r){if(!t.JS.isFlags(r))throw new Error("Invalid flags.");return a(e)?0===e.length?t.JS.UnicodeSet.empty(exports.Chars.maxChar(r)):1===e.length?C(e[0],r):t.JS.UnicodeSet.empty(exports.Chars.maxChar(r)).union(...e.map((e=>C(e,r)))):C(e,r)}function C(e,r){if(r instanceof l){let n=r.toUnicodeSet.get(e);return void 0===n&&(n=t.JS.parseUnicodeSet(e,r),r.toUnicodeSet.set(e,n)),n}return t.JS.parseUnicodeSet(e,r)}function m(e,t){switch(e.type){case"Character":case"ClassStringDisjunction":case"StringAlternative":return!1;case"CharacterClassRange":return 0===e.min.value&&e.max.value===exports.Chars.maxChar(t);case"CharacterSet":return"property"===e.kind?!e.strings&&h(e,t).isAll:"any"===e.kind&&!!t.dotAll;case"CharacterClass":return e.negate?e.elements.every((e=>d(e,t))):0!==e.elements.length&&(1===e.elements.length?m(e.elements[0],t):f(e,t).chars.isAll);case"ExpressionCharacterClass":return m(e.expression,t);case"ClassIntersection":return m(e.left,t)&&m(e.right,t);case"ClassSubtraction":return f(e,t).chars.isAll;default:return n(e)}}function d(e,t){switch(e.type){case"Character":case"CharacterClassRange":case"ClassStringDisjunction":case"StringAlternative":return!1;case"CharacterSet":return"property"===e.kind&&(!e.strings&&h(e,t).isEmpty);case"CharacterClass":return e.negate?0!==e.elements.length&&(1===e.elements.length?m(e.elements[0],t):f(e,t).isEmpty):e.elements.every((e=>d(e,t)));case"ExpressionCharacterClass":return d(e.expression,t);case"ClassIntersection":case"ClassSubtraction":return f(e,t).isEmpty;default:return n(e)}}function g(e,t){switch(e.type){case"Character":case"CharacterSet":case"CharacterClassRange":return!1;case"CharacterClass":return e.unicodeSets&&!e.negate&&e.elements.length>0&&e.elements.every((e=>g(e,t)));case"ExpressionCharacterClass":return!e.negate&&g(e.expression,t);case"ClassIntersection":case"ClassSubtraction":{const r=f(e,t).getLengthRange();return void 0!==r&&0===r.min&&0===r.max}case"ClassStringDisjunction":return e.alternatives.every((e=>g(e,t)));case"StringAlternative":return 0===e.elements.length;default:throw n(e)}}function x(e){switch(e.type){case"Character":case"CharacterSet":case"CharacterClassRange":return!1;case"CharacterClass":return e.unicodeSets&&!e.negate&&e.elements.some(x);case"ExpressionCharacterClass":return!e.negate&&x(e.expression);case"ClassIntersection":return x(e.left)&&x(e.right);case"ClassSubtraction":return x(e.left)&&!x(e.right);case"ClassStringDisjunction":return e.alternatives.some(x);case"StringAlternative":return 0===e.elements.length;default:throw n(e)}}function y(e,t){return a(e)?e.every(t):t(e)}function S(e,t){return a(e)?e.some(t):t(e)}function v(e,t){return y(e,(e=>w(e,t)))}function w(e,t){switch(e.type){case"Alternative":return e.elements.every((e=>w(e,t)));case"Assertion":return!0;case"Character":case"CharacterSet":case"CharacterClassRange":case"CharacterClass":case"ExpressionCharacterClass":case"ClassIntersection":case"ClassSubtraction":case"ClassStringDisjunction":case"StringAlternative":return g(e,t);case"Quantifier":return 0===e.max||w(e.element,t);case"Backreference":return I(e,t);case"CapturingGroup":case"Group":return e.alternatives.length>0&&e.alternatives.every((e=>w(e,t)));default:throw n(e)}}function k(e,t,r){return function e(s){switch(s.type){case"Alternative":return s.elements.every(e);case"Assertion":return!0;case"Backreference":return E(s,t,r);case"Character":case"CharacterSet":case"CharacterClass":case"ExpressionCharacterClass":return x(s);case"CapturingGroup":case"Group":return s.alternatives.some(e);case"Quantifier":return 0===s.min||e(s.element);default:throw n(s)}}(e)}function A(e,t){switch(e.type){case"Alternative":return e.elements.every((e=>A(e,t)));case"Assertion":return!1;case"Backreference":return I(e,t);case"Character":case"CharacterSet":case"CharacterClassRange":case"CharacterClass":case"ExpressionCharacterClass":case"ClassIntersection":case"ClassSubtraction":case"ClassStringDisjunction":case"StringAlternative":return g(e,t);case"CapturingGroup":case"Group":return e.alternatives.length>0&&e.alternatives.every((e=>A(e,t)));case"Quantifier":return 0===e.max||A(e.element,t);default:throw n(e)}}function E(e,t,r){return!!I(e,r)||!!F(e.resolved,(e=>e===t))&&(!B(e)||k(e.resolved,t,r))}function F(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 b(e,t,r){return"function"==typeof t?_(e,t,r):r?_(e,(e=>e===t),r):e===t||F(t,e)}function _(e,t,r){if(t(e))return!0;if(r&&!r(e))return!1;switch(e.type){case"Alternative":case"CharacterClass":case"StringAlternative":return e.elements.some((e=>_(e,t,r)));case"Assertion":return("lookahead"===e.kind||"lookbehind"===e.kind)&&e.alternatives.some((e=>_(e,t,r)));case"CapturingGroup":case"ClassStringDisjunction":case"Group":case"Pattern":return e.alternatives.some((e=>_(e,t,r)));case"ClassIntersection":case"ClassSubtraction":return _(e.left,t,r)||_(e.right,t,r);case"ExpressionCharacterClass":return _(e.expression,t,r);case"CharacterClassRange":return _(e.min,t,r)||_(e.max,t,r);case"Quantifier":return _(e.element,t,r);case"RegExpLiteral":return _(e.pattern,t,r)||_(e.flags,t,r);case"Backreference":case"Character":case"CharacterSet":case"Flags":return!1;default:return n(e)}}function L(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 G(e){let t;return F(e,(e=>"Assertion"===e.type&&(t=e,!0))),void 0===t||"lookahead"===t.kind?"ltr":"rtl"}function R(e){return"ltr"===e?"rtl":"ltr"}function j(e){return"end"===e||"lookahead"===e?"ltr":"rtl"}function I(e,t){const r=e.resolved,n=$(e,r);if(n===r)return!0;if("Alternative"!==n.type)return!0;const s=new Set;for(let t=e;t;t=t.parent)s.add(t);return!function e(t){const r=t.parent;switch(r.type){case"Alternative":{const n=r.elements.indexOf(t);let a;if(a="ltr"===G(t)?r.elements.slice(n+1):r.elements.slice(0,n),a.some((e=>s.has(e))))return!0;const o=r.parent;return"Pattern"!==o.type&&(("Assertion"!==o.type||!o.negate)&&e(o))}case"Quantifier":return e(r)}}(r)||v(r,t)}function B(e){const t=e.resolved,r=$(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 s=r.elements.indexOf(t);let a;if(a="ltr"===G(t)?r.elements.slice(s+1):r.elements.slice(0,s),a.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 W(e){return b(e,D)}function D(e){return"CapturingGroup"===e.type}const M={min:0,max:0},O={min:1,max:1};function P(e,t){return a(e)?J(e,t):U(e,t)}function J(e,t){let r=1/0,n=0;for(const s of e){const e=U(s,t);r=Math.min(r,e.min),n=Math.max(n,e.max)}if(r>n)throw new RangeError("Expected the alternatives array to have at least one alternative.");return{min:r,max:n}}function Q(e){const t=e.getLengthRange();return t||O}function U(e,t){switch(e.type){case"Assertion":return M;case"Character":case"CharacterClassRange":return O;case"CharacterSet":return"property"===e.kind&&e.strings?Q(f(e,t)):O;case"CharacterClass":return!e.unicodeSets||e.negate||0===e.elements.length?O:J(e.elements,t);case"ExpressionCharacterClass":return e.negate?O:U(e.expression,t);case"ClassIntersection":case"ClassSubtraction":return Q(f(e,t));case"StringAlternative":return{min:e.elements.length,max:e.elements.length};case"Quantifier":{if(0===e.max)return M;const r=U(e.element,t);return 0===r.max?M:{min:r.min*e.min,max:r.max*e.max}}case"Alternative":{let r=0,n=0;for(const s of e.elements){const e=U(s,t);r+=e.min,n+=e.max}return{min:r,max:n}}case"CapturingGroup":case"Group":case"ClassStringDisjunction":return J(e.alternatives,t);case"Backreference":if(I(e,t))return M;{const r=U(e.resolved,t);return r.min>0&&!B(e)?{min:0,max:r.max}:r}default:throw n(e)}}function q(e,t){return a(e)?T(e,t):z(e,t)}function T(e,t){if(0===e.length)throw new RangeError("Expected the alternatives array to have at least one alternative.");return e.some((e=>z(e,t)))}function z(e,t){switch(e.type){case"Assertion":return!0;case"Character":case"CharacterClassRange":return!1;case"CharacterSet":return"property"===e.kind&&e.strings,!1;case"CharacterClass":return!(!e.unicodeSets||e.negate||0===e.elements.length)&&T(e.elements,t);case"ExpressionCharacterClass":return!e.negate&&z(e.expression,t);case"ClassIntersection":case"ClassSubtraction":return f(e,t).hasEmptyWord;case"Quantifier":return 0===e.min||z(e.element,t);case"Alternative":return e.elements.every((e=>z(e,t)));case"StringAlternative":return 0===e.elements.length;case"CapturingGroup":case"Group":case"ClassStringDisjunction":return T(e.alternatives,t);case"Backreference":return I(e,t)||!B(e)||z(e.resolved,t);default:throw n(e)}}function $(...e){if(0!==e.length)return e.reduce(Z)}function Z(e,t){if(e===t)return e;if(e.parent&&e.parent===t.parent)return e.parent;{const r=N(e),n=N(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 s=r[r.length-1].parent;if(s)return s;throw new Error("The two nodes are not part of the same tree.")}}function N(e){const t=[];for(let r=e;r;r=r.parent)t.push(r);return t}function K(e,t){if(e==t)return!0;if(!e||!t||e.type!=t.type)return!1;switch(e.type){case"Alternative":case"StringAlternative":{const r=t;return H(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&&H(e.alternatives,r.alternatives)}return e.raw===r.raw}return!1}case"Backreference":{const r=t;return K(e.resolved,r.resolved)&&B(e)==B(r)}case"Character":{const r=t;return e.value===r.value}case"CharacterClass":{const r=t;return e.negate===r.negate&&e.unicodeSets===r.unicodeSets&&H(e.elements,r.elements)}case"CharacterClassRange":{const r=t;return K(e.min,r.min)&&K(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.value===r.value:e.raw===r.raw}case"ExpressionCharacterClass":{const r=t;return e.negate===r.negate&&K(e.expression,r.expression)}case"ClassIntersection":case"ClassSubtraction":{const r=t;return K(e.left,r.left)&&K(e.right,r.right)}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&&e.unicodeSets===r.unicodeSets}case"ClassStringDisjunction":case"CapturingGroup":case"Group":case"Pattern":{const r=t;return H(e.alternatives,r.alternatives)}case"Quantifier":{const r=t;return e.min===r.min&&e.max===r.max&&e.greedy===r.greedy&&K(e.element,r.element)}case"RegExpLiteral":{const r=t;return K(e.flags,r.flags)&&K(e.pattern,r.pattern)}default:throw n(e)}}function H(e,t){if(e.length!==t.length)return!1;for(let r=0;r<e.length;r++)if(!K(e[r],t[r]))return!1;return!0}function V(e,t,r,s,a){function o(e,t,r){var n,a;s.enter&&(t=s.enter(e,t,r));if(null===(a=null===(n=s.continueInto)||void 0===n?void 0:n.call(s,e,t,r))||void 0===a||a)switch(e.type){case"Assertion":if("lookahead"===e.kind||"lookbehind"===e.kind){const n=j(e.kind),a=s.join(e.alternatives.map((e=>c(e,X(s,t,r),n))),n);t=l(t,n,"assertion"),s.assert&&(t=s.assert(t,r,a,n))}break;case"Group":case"CapturingGroup":t=s.join(e.alternatives.map((e=>c(e,X(s,t,r),r))),r);break;case"Quantifier":0===e.max||(t=0===e.min?s.join([t,o(e.element,X(s,t,r),r)],r):o(e.element,t,r))}return s.leave&&(t=s.leave(e,t,r)),t}function c(e,t,r){var n,a;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===(a=null===(n=s.continueAfter)||void 0===n?void 0:n.call(s,u,t,r))||void 0===a||a))break}return t}function i(e,t,r){var a,o;const c=e.parent;if("CharacterClass"===c.type||"CharacterClassRange"===c.type||"ClassIntersection"===c.type||"ClassSubtraction"===c.type||"ExpressionCharacterClass"===c.type||"StringAlternative"===c.type)throw new Error("The given element cannot be part of a character class.");if(!(null===(o=null===(a=s.continueAfter)||void 0===a?void 0:a.call(s,e,t,r))||void 0===o||o))return!1;if("Quantifier"===c.type)return c.max<=1?i(c,t,r):[c,i(c,t,r)];{const s=c.elements.indexOf(e)+("ltr"===r?1:-1),a=c.elements[s];if(a)return a;{const e=c.parent;if("Pattern"===e.type)return"pattern";if("Assertion"===e.type)return u(e,t,r)?i(e,t,r):"assertion";if("CapturingGroup"===e.type||"Group"===e.type)return i(e,t,r);throw n(e)}}}function u(e,t,r){return!!s.continueOutside&&s.continueOutside(e,t,r)}function l(e,t,r){return s.endPath?s.endPath(e,t,r):e}if(a||(a=G(e)),"Alternative"===e.type)if(0===e.elements.length&&(t="next"),"enter"===t)h=e,e="ltr"===a?h.elements[0]:h.elements[h.elements.length-1];else{const t=e.parent;if("Pattern"===t.type)return l(r,a,"pattern");if("Assertion"===t.type&&!u(t,r,a))return l(r,a,"assertion");e=t}var h;return"enter"===t&&(r=o(e,r,a)),function(e,t,r){for(;;){let n=i(e,t,r);for(;Array.isArray(n);){const[e,a]=n;t=s.join([t,o(e,X(s,t,r),r)],r),n=a}if(!1===n)return t;if("assertion"===n||"pattern"===n)return l(t,r,n);t=o(n,t,r),e=n}}(e,r,a)}function X(e,t,r){return e.fork?e.fork(t,r):t}var Y,ee;exports.FirstLookChars=void 0,(Y=exports.FirstLookChars||(exports.FirstLookChars={})).all=function(e){return{char:exports.Chars.all(e),exact:!0,edge:!0}},Y.edge=function(e){return{char:exports.Chars.empty(e),exact:!0,edge:!0}},Y.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,(ee=exports.FirstConsumedChars||(exports.FirstConsumedChars={})).emptyConcat=function(e){return{char:exports.Chars.empty(e),exact:!0,empty:!0,look:exports.FirstLookChars.all(e)}},ee.emptyUnion=function(e){return{char:exports.Chars.empty(e),exact:!0,empty:!1}},ee.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}},ee.union=function(e,t){const r=o.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=o.fromFlags(t);let s=!1;for(const t of n)e.add(t),s=s||t.edge;return{char:r.char,exact:r.exact,empty:!0,look:{char:e.char,exact:e.exact,edge:s}}}return{char:r.char,exact:r.exact,empty:!1}},ee.concat=function(e,t){const r=o.fromFlags(t);let n=exports.FirstLookChars.all(t);for(const t of e){if(r.add(c(t,n)),!t.empty)return{char:r.char,exact:r.exact,empty:!1};{const e=c(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}},ee.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 te{constructor(e){this._currentWordBoundaries=[],e instanceof l?(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 re(e,t,r){const n=new te(r);return a(e)?ne(e,t,r,n):se(e,t,r,n)}function ne(e,t,r,n){return exports.FirstConsumedChars.union(e.map((e=>se(e,t,r,n))),r)}function se(e,t,r,s){let a=s.getCached(e,t);return void 0===a&&(a=function(e,t,r,s){switch(e.type){case"Assertion":return function(e,t,r,s){switch(e.kind){case"word":if(s.isCurrentWordBoundary(e))return a();{s.pushWordBoundary(e);const n=ie(e,R(t),r,s);s.popWordBoundary();const o=exports.Chars.word(r);return n.edge?n.char.isDisjointWith(o)?i(e.negate):a():n.char.isDisjointWith(o)?i(e.negate):n.char.isSubsetOf(o)?i(!e.negate):a()}case"end":case"start":return j(e.kind)===t?r.multiline?c():o():a();case"lookahead":case"lookbehind":if(j(e.kind)===t){if(e.negate){if(b(e,(t=>t!==e&&"Assertion"===t.type)))return a();const n=ne(e.alternatives,t,r,s),o=P(e.alternatives,r);return n.empty||!o?{char:exports.Chars.empty(r),empty:!1,exact:!0}:n.exact&&1===o.max?exports.FirstLookChars.toConsumed({char:n.char.negate(),edge:!0,exact:!0}):a()}{const n=ne(e.alternatives,t,r,s);return exports.FirstLookChars.toConsumed(exports.FirstConsumedChars.toLook(n))}}return a();default:throw n(e)}function a(){return exports.FirstLookChars.toConsumed({char:exports.Chars.all(r),edge:!0,exact:!1})}function o(){return exports.FirstLookChars.toConsumed(exports.FirstLookChars.edge(r))}function c(){return exports.FirstLookChars.toConsumed({char:exports.Chars.lineTerminator(r),edge:!0,exact:!0})}function i(e){const t=exports.Chars.word(r);return exports.FirstLookChars.toConsumed({char:e?t.negate():t,edge:e,exact:!0})}}(e,t,r,s);case"Character":case"CharacterSet":case"CharacterClass":case"ExpressionCharacterClass":{const n=f(e,r);if(n.accept.isEmpty)return{char:n.chars,empty:!1,exact:!0};{const e=new Set;if("ltr"===t)for(const t of n.accept.wordSets)t.length>0&&e.add(t[0]);else for(const t of n.accept.wordSets)t.length>0&&e.add(t[t.length-1]);const r={char:n.chars.union(...e),empty:!1,exact:!0};return n.hasEmptyWord?exports.FirstConsumedChars.makeOptional(r):r}}case"Quantifier":{if(0===e.max)return exports.FirstConsumedChars.emptyConcat(r);const n=se(e.element,t,r,s);return 0===e.min?exports.FirstConsumedChars.makeOptional(n):n}case"Alternative":{let n=e.elements;return"rtl"===t&&(n=[...n],n.reverse()),exports.FirstConsumedChars.concat(function*(){for(const e of n)yield se(e,t,r,s)}(),r)}case"CapturingGroup":case"Group":return ne(e.alternatives,t,r,s);case"Backreference":{if(I(e,r))return exports.FirstConsumedChars.emptyConcat(r);let n=se(e.resolved,t,r,s);return n.exact&&n.char.size>1&&(n=Object.assign(Object.assign({},n),{exact:!1})),B(e)?n:exports.FirstConsumedChars.makeOptional(n)}default:throw n(e)}}(e,t,r,s),s.setCached(e,t,a)),a}function ae(e,t,r){return oe(e,t,r,new te(r))}function oe(e,t,r,n){return V(e,"next",exports.FirstConsumedChars.emptyConcat(r),{join:e=>exports.FirstConsumedChars.union(e,r),enter(e,t,s){const a=se(e,s,r,n);return exports.FirstConsumedChars.concat([t,a],r)},continueInto:()=>!1,continueAfter:(e,t)=>t.empty,continueOutside:(e,t,r)=>j(e.kind)!==r},t)}function ce(e,t,r){return ie(e,t,r,new te(r))}function ie(e,t,r,n){return exports.FirstConsumedChars.toLook(oe(e,t,r,n))}function ue(e,t,r,n){return V(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,s){const a=se(e,s,r,n);return{char:exports.FirstConsumedChars.concat([t.char,a],r),contributors:[...t.contributors,e]}},continueInto:()=>!1,continueAfter:(e,t)=>t.char.empty,continueOutside:(e,t,r)=>j(e.kind)!==r},t)}function le(e,t,r,n={}){const s=l.from(r);r=s;const{includeAfter:a=!1,onlyInside:o=!1,looseGroups:c=!1}=n,i=s.getLongestPrefix,u=`${t},${a},${o},${c}`;let h=i.get(u);void 0===h&&(h=new WeakMap,i.set(u,h));let p=h.get(e);return void 0===p&&(p=function(e,t,r,n){const{chars:s,complete:a}=fe(e,t,r,n);for(let e=0;e<s.length;e++)if(s[e].isEmpty)return s.slice(0,e);if(a&&r.includeAfter&&!r.onlyInside)return[...s,ge(e,t,n).char];return s}(e,t,{includeAfter:a,onlyInside:o,looseGroups:c,root:e},r),h.set(e,p)),p}const he={chars:[],complete:!0},pe={chars:[],complete:!1};function fe(e,t,r,n){const{elements:s}=e,a=[],o="ltr"===t?1:-1;for(let e="ltr"===t?0:s.length-1;e>=0&&e<s.length;e+=o){const o=Ce(s[e],t,r,n);if(a.push(...o.chars),!o.complete)return{chars:a,complete:!1}}return{chars:a,complete:!0}}function Ce(e,t,r,s){switch(e.type){case"Assertion":return he;case"Character":case"CharacterClass":case"CharacterSet":case"ExpressionCharacterClass":{const n=f(e,s);if(n.accept.isEmpty)return{chars:[n.chars],complete:!0};{const a=[];n.chars.isEmpty||a.push({chars:[n.chars],complete:!0});for(const e of n.accept.wordSets)a.push({chars:e,complete:!0});return me(e,a,t,r,s)}}case"CapturingGroup":case"Group":return function(e,t,r,n){const s=e.alternatives.map((e=>fe(e,t,r,n)));return me(e,s,t,r,n)}(e,t,r,s);case"Quantifier":return function(e,t,r,n){if(v(e,n))return he;if(q(e,n)){if(!xe(e,r,t,n))return pe;return{chars:[exports.FirstConsumedChars.toLook(de(e,t,n)).char],complete:!1}}const s=Ce(e.element,t,r,n);if(!s.complete)return s;if(0===s.chars.length)throw new Error(`Expected the quantifier '${e.raw}' to consume at least one character.`);const a=[];for(let t=0;t<e.min;t++)if(a.push(...s.chars),a.length>1e3)return{chars:a,complete:!1};if(e.min===e.max)return{chars:a,complete:!0};if(ye(e,r,t,n)){const r=ce(e,t,n);a.push(r.char.union(s.chars[0]))}return{chars:a,complete:!1}}(e,t,r,s);case"Backreference":if(I(e,s))return he;if(B(e)){return Ce(e.resolved,t,Object.assign(Object.assign({},r),{includeAfter:!1}),s)}if(!xe(e,r,t,s))return pe;return{chars:[exports.FirstConsumedChars.toLook(de(e,t,s)).char],complete:!1};default:n(e)}}function me(e,t,r,n,s){if(1===t.length)return t[0];const a=[];let o=!0,c=0;for(let i=0;o;i++){const u=[];let l=!1;for(const e of t)i>=e.chars.length?l=!0:(u.push(e.chars[i]),i===e.chars.length-1&&!e.complete&&n.includeAfter&&(o=!1));if(0===u.length)break;if(l){if(o=!1,!ye(e,n,r,s))break;u.push(ce(e,r,s).char)}else if(!n.looseGroups&&(o&&u.some((e=>!e.equals(u[0])))&&c++,c>=2&&(o=!1,!n.includeAfter)))break;const h=u[0].union(...u.slice(1));a.push(h)}return{chars:a,complete:o}}function de(e,t,r){const n=re(e,t,r);return n.empty?exports.FirstConsumedChars.concat([n,ae(e,t,r)],r):n}function ge(e,t,r){const{elements:n}=e,s="ltr"===t?1:-1;let a="rtl"===t?0:n.length-1;for(;a>=0&&a<n.length&&v(n[a],r);)a-=s;return a>=0&&a<n.length?ce(n[a],t,r):exports.FirstConsumedChars.toLook(de(e,t,r))}function xe(e,t,r,n){return!!t.includeAfter&&(!t.onlyInside||function(e,t,r,n){return!q(e,n)||Se(e,t,r,n)}(e,r,t.root,n))}function ye(e,t,r,n){return!!t.includeAfter&&(!t.onlyInside||Se(e,r,t.root,n))}function Se(e,t,r,n){const s=e.parent;if("CharacterClass"===s.type||"CharacterClassRange"===s.type||"ClassIntersection"===s.type||"ClassSubtraction"===s.type||"ExpressionCharacterClass"===s.type||"StringAlternative"===s.type)throw new Error("Expected an element outside a character class.");if("Quantifier"===s.type)return Se(s,t,r,n);const a="ltr"===t?1:-1;for(let t=s.elements.indexOf(e)+a;t>=0&&t<s.elements.length;t+=a){if(!q(s.elements[t],n))return!0}if(s===r)return!1;const o=s.parent;if("Pattern"===o.type)throw new Error("Expected the given element to be a descendant of the root alternative.");if("Assertion"===o.type)throw new Error;return Se(o,t,r,n)}function ve(e,t,r){return s(e),"unknown"===t?function(e,t){const r=ke(e,"ltr",t),n=ke(e,"rtl",t),s=Ae([...r,...n],(e=>e)),a=[];for(const e of s){const t=new Set;for(const r of e)r.forEach((e=>t.add(e)));a.push([...t])}return a}(e,r):ke(e,t,r)}const we={includeAfter:!0,looseGroups:!0};function ke(e,r,n){const s=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=le(e,r,n,we),s=0;for(let e=t.length-1;e>=0&&t[e].isAll;e--)s++;return s>0&&(t=t.slice(0,t.length-s)),t})),a=new Set;for(const t of e)s(t).forEach((e=>a.add(e)));const o=new t.CharBase(a),c=[];for(const t of e)c.push({characters:s(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=Ae(t,(e=>e.characters[r])),s=[];for(const t of n)s.push(...e(t,r+1));return s}(c,0).map((e=>e.map((e=>e.alternative))))}function Ae(e,t){if(e.length<2)return[e];const r=new i(e.length),n=new Map;for(let s=0;s<e.length;s++){const a=e[s];for(const e of t(a)){const t=n.get(e);void 0===t?n.set(e,s):r.makeEqual(s,t)}}const s=r.getEquivalenceSets(),a=[];for(let e=0;e<s.count;e++)a.push([]);for(let t=0;t<e.length;t++)a[s.indexes[t]].push(e[t]);return a}function Ee(e,t){const r=[];let n=!0;b(e,(e=>{if("Character"===e.type||"CharacterClass"===e.type||"CharacterSet"===e.type||"ExpressionCharacterClass"===e.type){const s=f(e,t);if(r.push(s.chars),!s.accept.isEmpty){const e=new Set;for(const t of s.accept.wordSets)for(const r of t)e.add(r);r.push(exports.Chars.empty(t).union(...e))}n=n&&!s.isEmpty}else if("Backreference"===e.type&&!I(e,t)){const s=Ee(e.resolved,t);r.push(s.chars),n=n&&s.exact&&s.chars.size<2}return!1}),(e=>"CharacterClass"!==e.type&&"ExpressionCharacterClass"!==e.type&&("Assertion"!==e.type||(n=!1,!1))));return{chars:exports.Chars.empty(t).union(...r),exact:n}}function Fe(e,t,r,n,s){const a=ve(t,r,n);return!(!s&&!function(e,t,r){let n=0,s=0;for(const r of t)W(r)&&(e.has(r)?n++:s++);if(n>1||1===n&&0!==s)return!1;if(0!==s)return r.every((t=>!t.some(W)||t.every((t=>!e.has(t)))));if(0!==n)return r.every((e=>e.length<2||!e.some(W)));return!0}(e,t,a))&&a.every((t=>t.length<2||(!!t.every((t=>!e.has(t)))||(function(e,t){const r=P(e,t);return Boolean(r&&r.min===r.max)}(t,n)||function(e,t,r){const n=function(e,t){const r=be(e,"ltr",t),n=be(r.rest,"rtl",t);return{left:r.prefix,right:n.prefix,rest:n.rest}}(e.map((e=>e.elements)),r),s=[];for(const e of n.rest)s.push(...e);const a=exports.Chars.empty(r).union(...s.map((e=>Ee(e,r).chars))),o="ltr"===t?n.right:n.left;if(o.some((e=>e.isDisjointWith(a))))return!0;const c=e[0].parent;if("Pattern"===c.type||"Assertion"===c.type)return!1;return ce(c,t,r).char.isDisjointWith(a)}(t,r,n)))))}function be(e,t,r){const n=function(e,t,r){const n=[];for(let s=0;;s++){let a=null;for(const o of e){const e="ltr"===t?s:o.length-1-s;if(!(s>=0&&s<o.length))return n;{const t=o[e];switch(t.type){case"Character":case"CharacterClass":case"CharacterSet":case"ExpressionCharacterClass":{const e=f(t,r);if(!e.accept.isEmpty)return n;if(null===a)a=e.chars;else if(!a.equals(e.chars))return n;break}default:return n}}}if(null===a)throw new Error;n.push(a)}}(e,t,r);return 0===n.length?{prefix:n,rest:e}:{prefix:n,rest:e.map((e=>{const r="ltr"===t?n.length:0,s="ltr"===t?e.length:e.length-n.length;return e.slice(r,s)}))}}exports.canReorder=function(e,t,r={}){t=u(t);const{ignoreCapturingGroups:n=!1,matchingDirection:a}=r,o=(c=e)instanceof Set?c:new Set(c);var c;if(o.size<2)return!0;s(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,s=0;for(let t=0;t<r.length;t++){const a=r[t];e.has(a)&&(n=Math.min(n,t),s=Math.max(s,t))}return r.slice(n,s+1)}(o),l=null!=a?a:G(i[0]);return"unknown"===l?Fe(o,i,"ltr",t,n)&&Fe(o,i,"rtl",t,n):Fe(o,i,l,t,n)},exports.canReorderDirectional=Fe,exports.containsCapturingGroup=W,exports.createCache=function(e){return new l(e)},exports.followPaths=V,exports.getCapturingGroupNumber=function(t){let r=0;try{throw e.visitRegExpAST(L(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=$,exports.getConsumedChars=Ee,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=ce,exports.getFirstCharAfterWithContributors=function(e,t,r){return function(e,t,r,n){const{char:s,contributors:a}=ue(e,t,r,n);return{char:exports.FirstConsumedChars.toLook(s),contributors:a}}(e,t,r,new te(r))},exports.getFirstConsumedChar=re,exports.getFirstConsumedCharAfter=ae,exports.getFirstConsumedCharAfterWithContributors=function(e,t,r){return ue(e,t,r,new te(r))},exports.getLengthRange=P,exports.getLongestPrefix=le,exports.getMatchingDirection=G,exports.getMatchingDirectionFromAssertionKind=j,exports.getPattern=L,exports.hasSomeAncestor=F,exports.hasSomeDescendant=b,exports.hasStrings=function e(t,r){switch(t.type){case"Character":case"CharacterClassRange":return!1;case"CharacterSet":return"property"===t.kind&&t.strings;case"CharacterClass":return!(t.negate||!t.unicodeSets)&&t.elements.some((t=>e(t,r)));case"ExpressionCharacterClass":return e(t.expression,r);case"ClassIntersection":case"ClassSubtraction":return!f(t,r).accept.isEmpty;case"ClassStringDisjunction":return t.alternatives.some((t=>e(t,r)));case"StringAlternative":return 1!==t.elements.length;default:return n(t)}},exports.invertMatchingDirection=R,exports.isEmpty=function(e,t){return y(e,(e=>A(e,t)))},exports.isEmptyBackreference=I,exports.isLengthRangeMinZero=q,exports.isPotentiallyEmpty=function(e,t){if(!a(e))switch(e.type){case"Character":case"CharacterSet":case"CharacterClassRange":case"CharacterClass":case"ExpressionCharacterClass":case"ClassIntersection":case"ClassSubtraction":case"ClassStringDisjunction":case"StringAlternative":return x(e)}return S(e,(e=>function(e,t){return r(e);function r(s){switch(s.type){case"Alternative":return s.elements.every(r);case"Assertion":return!1;case"Backreference":return E(s,e,t);case"Character":case"CharacterSet":case"CharacterClass":case"ExpressionCharacterClass":return x(s);case"CapturingGroup":case"Group":return s.alternatives.some(r);case"Quantifier":return 0===s.min||r(s.element);default:throw n(s)}}}(e,t)))},exports.isPotentiallyZeroLength=function(e,t){if(!a(e))switch(e.type){case"Character":case"CharacterSet":case"CharacterClassRange":case"CharacterClass":case"ExpressionCharacterClass":case"ClassIntersection":case"ClassSubtraction":case"ClassStringDisjunction":case"StringAlternative":return x(e)}return S(e,(e=>k(e,e,t)))},exports.isStrictBackreference=B,exports.isZeroLength=v,exports.matchesAllCharacters=m,exports.matchesNoCharacters=d,exports.structurallyEqual=K,exports.toCache=u,exports.toCharSet=h,exports.toUnicodeSet=f; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "regexp-ast-analysis", | ||
"version": "0.7.0", | ||
"version": "0.7.1", | ||
"description": "A library for analysing JS RegExp", | ||
@@ -54,3 +54,3 @@ "main": "index", | ||
"@eslint-community/regexpp": "^4.8.0", | ||
"refa": "^0.12.0" | ||
"refa": "^0.12.1" | ||
}, | ||
@@ -57,0 +57,0 @@ "files": [ |
Sorry, the diff of this file is not supported yet
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
271127
1477
Updatedrefa@^0.12.1