Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

regexp-ast-analysis

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

regexp-ast-analysis - npm Package Compare versions

Comparing version 0.6.0 to 0.7.0

285

index.d.ts

@@ -12,4 +12,11 @@ // Generated by dts-bundle-generator v5.9.0

CharacterSet,
ClassIntersection,
ClassRangesCharacterClass,
ClassRangesCharacterClassElement,
ClassSetOperand,
ClassStringDisjunction,
ClassSubtraction,
EdgeAssertion,
Element,
ExpressionCharacterClass,
Flags,

@@ -22,7 +29,73 @@ Group,

RegExpLiteral,
StringAlternative,
StringsUnicodePropertyCharacterSet,
UnicodeSetsCharacterClass,
UnicodeSetsCharacterClassElement,
WordBoundaryAssertion,
} from "@eslint-community/regexpp/ast";
import { CharSet } from "refa";
import { Char, CharSet, JS } from "refa";
/**
* A simple interface to represent JS RegExp flags.
*
* All properties are optional and assumed to be `false` by default.
*/
export interface ReadonlyFlags {
/**
* The `s` flag.
*
* @default false
*/
readonly dotAll?: boolean;
/**
* The `g` flag.
*
* @default false
*/
readonly global?: boolean;
/**
* The `d` flag.
*
* @default false
*/
readonly hasIndices?: boolean;
/**
* The `i` flag.
*
* @default false
*/
readonly ignoreCase?: boolean;
/**
* The `m` flag.
*
* @default false
*/
readonly multiline?: boolean;
/**
* The `y` flag.
*
* @default false
*/
readonly sticky?: boolean;
/**
* The `u` flag.
*
* @default false
*/
readonly unicode?: boolean;
/**
* The `v` flag.
*
* @default false
*/
readonly unicodeSets?: boolean;
}
export type CharacterElement =
| CharacterSet
| ClassIntersection
| ClassSubtraction
| CharacterClassElement
| CharacterClass
| StringAlternative;
/**
* Returns whether all (but at least one of the) paths of the given element do not consume characters.

@@ -46,3 +119,6 @@ *

*/
export declare function isZeroLength(element: Element | Alternative | readonly Alternative[]): boolean;
export declare function isZeroLength(
element: Element | CharacterElement | Alternative | readonly Alternative[],
flags: ReadonlyFlags
): boolean;
/**

@@ -64,3 +140,6 @@ * Returns whether at least one path of the given element does not consume characters.

*/
export declare function isPotentiallyZeroLength(element: Element | Alternative | readonly Alternative[]): boolean;
export declare function isPotentiallyZeroLength(
element: Element | CharacterElement | Alternative | readonly Alternative[],
flags: ReadonlyFlags
): boolean;
/**

@@ -88,3 +167,6 @@ * Returns whether all (but at least one of the) paths of the given element do neither consume characters nor assert

*/
export declare function isEmpty(element: Element | Alternative | readonly Alternative[]): boolean;
export declare function isEmpty(
element: Element | CharacterElement | Alternative | readonly Alternative[],
flags: ReadonlyFlags
): boolean;
/**

@@ -113,3 +195,6 @@ * Returns whether at least one path of the given element does neither consume characters nor assert characters.

*/
export declare function isPotentiallyEmpty(element: Element | Alternative | readonly Alternative[]): boolean;
export declare function isPotentiallyEmpty(
element: Element | CharacterElement | Alternative | readonly Alternative[],
flags: ReadonlyFlags
): boolean;
/**

@@ -120,13 +205,18 @@ * Returns the type of all possible ancestor nodes of the given node type.

*/
export declare type Ancestor<T extends Node> = AncestorImpl<T>;
declare type AncestorImpl<T extends Node> =
| (T extends CharacterSet ? T["parent"] | AlternativeAncestors : never)
| (T extends Character ? T["parent"] | AlternativeAncestors : never)
| (T extends CharacterClassRange ? T["parent"] | AlternativeAncestors : never)
| (T extends Exclude<Element, Character | CharacterSet> ? AlternativeAncestors : never)
| (T extends Alternative ? AlternativeAncestors : never)
| (T extends Pattern ? RegExpLiteral : never)
| (T extends Flags ? RegExpLiteral : never)
| (T extends RegExpLiteral ? never : never);
declare type AlternativeAncestors = Alternative["parent"] | Quantifier | Alternative | RegExpLiteral;
export type Ancestor<T extends Node> = AncestorImpl<T>;
type AncestorImpl<T extends Node> = ExtendApproximation<Anc2<GetParent<T>>>;
type ExtendApproximation<T extends Node> =
| T
| (T extends UnicodeSetsCharacterClass ? CharacterClassAnc : never)
| (T extends Alternative ? AlternativeAnc : never);
type AlternativeAnc = TrueAnc<Alternative>;
type CharacterClassAnc = TrueAnc<UnicodeSetsCharacterClass>;
type TrueAnc<T extends Node> = Anc6<GetParent<T>>;
type GetParent<T extends Node> = NonNullable<T["parent"]>;
type Anc6<T extends Node> = T | Anc5<GetParent<T>>;
type Anc5<T extends Node> = T | Anc4<GetParent<T>>;
type Anc4<T extends Node> = T | Anc3<GetParent<T>>;
type Anc3<T extends Node> = T | Anc2<GetParent<T>>;
type Anc2<T extends Node> = T | Anc1<GetParent<T>>;
type Anc1<T extends Node> = T | GetParent<T>;
/**

@@ -150,10 +240,25 @@ * Returns whether any of the ancestors of the given node fulfills the given condition.

*/
export declare type Descendant<T extends Node> = T | DescendantsImpl<T>;
declare type DescendantsImpl<T extends Node> =
export type Descendant<T extends Node> = T | DescendantsImpl<T>;
type DescendantsImpl<T extends Node> = Dec1<GetChildren<T>>;
type Dec1<T extends Node> = T | Dec2<GetChildren<T>>;
type Dec2<T extends Node> = T | GetChildren<T>;
type GetChildren<T extends Node> =
| (T extends RegExpLiteral ? Flags | Pattern | Element : never)
| (T extends Alternative | CapturingGroup | Group | LookaroundAssertion | Quantifier | Pattern
? Element | CharacterClassElement
? Alternative | Element
: never)
| (T extends CharacterClass ? CharacterClassElement : never)
| (T extends Alternative ? Element : never)
| (T extends ClassRangesCharacterClass ? ClassRangesCharacterClassElement : never)
| (T extends CharacterClassRange ? Character : never)
| (T extends RegExpLiteral ? Flags | Pattern | Element | CharacterClassElement : never);
| (T extends UnicodeSetsCharacterClass | ExpressionCharacterClass | ExpressionCharacterClass["expression"]
? UnicodeSetsDescendants
: never)
| (T extends ClassStringDisjunction ? StringAlternative : never)
| (T extends StringAlternative ? Character : never);
type UnicodeSetsDescendants =
| ClassSetOperand
| UnicodeSetsCharacterClassElement
| UnicodeSetsCharacterClass
| ExpressionCharacterClass
| ExpressionCharacterClass["expression"];
/**

@@ -211,3 +316,3 @@ * Returns whether any of the descendants of the given node fulfill the given condition.

*/
export declare type MatchingDirection = "ltr" | "rtl";
export type MatchingDirection = "ltr" | "rtl";
/**

@@ -220,3 +325,3 @@ * This extends the {@link MatchingDirection} type to allow unknown matching

*/
export declare type OptionalMatchingDirection = MatchingDirection | "unknown";
export type OptionalMatchingDirection = MatchingDirection | "unknown";
/**

@@ -270,3 +375,3 @@ * Returns the direction which which the given node will be matched relative to the closest parent alternative.

*/
export declare function isEmptyBackreference(backreference: Backreference): boolean;
export declare function isEmptyBackreference(backreference: Backreference, flags: ReadonlyFlags): boolean;
/**

@@ -300,3 +405,3 @@ * Returns whether the given backreference is a strict backreference.

*/
export declare type ContainsCapturingGroup<N extends Node> = N extends
export type ContainsCapturingGroup<N extends Node> = N extends
| CharacterClassElement

@@ -355,3 +460,6 @@ | CharacterClass

*/
export declare function getLengthRange(element: Element | Alternative | readonly Alternative[]): LengthRange;
export declare function getLengthRange(
element: Element | CharacterElement | Alternative | readonly Alternative[],
flags: ReadonlyFlags
): LengthRange;
/**

@@ -372,3 +480,6 @@ * Returns whether `getLengthRange(e).min == 0`.

*/
export declare function isLengthRangeMinZero(element: Element | Alternative | readonly Alternative[]): boolean;
export declare function isLengthRangeMinZero(
element: Element | CharacterElement | Alternative | readonly Alternative[],
flags: ReadonlyFlags
): boolean;
/**

@@ -379,3 +490,3 @@ * The type of the closest ancestor of two nodes with the given types.

*/
export declare type ClosestAncestor<A extends Node, B extends Node> = Exclude<A | B, Descendant<Pattern>> extends never
export type ClosestAncestor<A extends Node, B extends Node> = Exclude<A | B, Descendant<Pattern>> extends never
? Exclude<(A | Ancestor<A>) & (B | Ancestor<B>), RegExpLiteral>

@@ -430,51 +541,2 @@ : (A | Ancestor<A>) & (B | Ancestor<B>);

/**
* A simple interface to represent JS RegExp flags.
*
* All properties are optional and assumed to be `false` by default.
*/
export interface ReadonlyFlags {
/**
* The `s` flag.
*
* @default false
*/
readonly dotAll?: boolean;
/**
* The `g` flag.
*
* @default false
*/
readonly global?: boolean;
/**
* The `d` flag.
*
* @default false
*/
readonly hasIndices?: boolean;
/**
* The `i` flag.
*
* @default false
*/
readonly ignoreCase?: boolean;
/**
* The `m` flag.
*
* @default false
*/
readonly multiline?: boolean;
/**
* The `y` flag.
*
* @default false
*/
readonly sticky?: boolean;
/**
* The `u` flag.
*
* @default false
*/
readonly unicode?: boolean;
}
/**
* A cache that functions may use to store results.

@@ -549,8 +611,14 @@ *

*/
export declare type ToCharSetElement = Character | CharacterClassRange | CharacterSet | CharacterClass;
export type ToCharSetElement =
| Character
| CharacterClassRange
| Exclude<CharacterSet, StringsUnicodePropertyCharacterSet>
| ClassRangesCharacterClass;
/**
* Converts the given element or array of elements into a refa CharSet.
* Converts the given element or array of elements into a refa `CharSet`.
*
* If an array is given, all the character sets of all elements will be unioned. This means that for any two element `a`
* and `b`, the results of `toCharSet([a, b])` and `toCharSet(a).union(toCharSet(b))` will be the same.
*
* This is guaranteed to be equivalent to `toUnicodeSet(char).chars`.
*/

@@ -562,14 +630,42 @@ export declare function toCharSet(

/**
* All possible element types that are accepted by {@link toCharSet}.
*
* @see {@link toCharSet}
*/
export type ToUnicodeSetElement =
| ToCharSetElement
| CharacterClass
| CharacterSet
| ClassSetOperand
| ExpressionCharacterClass["expression"]
| StringAlternative;
/**
* Converts the given element or array of elements into a refa `UnicodeSet`.
*
* If an array is given, all the character sets of all elements will be unioned. This means that for any two element `a`
* and `b`, the results of `toUnicodeSet([a, b])` and `toUnicodeSet(a).union(toUnicodeSet(b))` will be the same.
*/
export declare function toUnicodeSet(
elements: ToUnicodeSetElement | readonly ToUnicodeSetElement[],
flags: ReadonlyFlags
): JS.UnicodeSet;
/**
* Returns whether the given character class/set matches all characters.
*
* This is guaranteed to be equivalent to `toCharSet(char).isAll` but is implemented more efficiently.
* This is guaranteed to be equivalent to `toUnicodeSet(char).chars.isAll` but is implemented more efficiently.
*/
export declare function matchesAllCharacters(char: ToCharSetElement, flags: ReadonlyFlags): boolean;
export declare function matchesAllCharacters(char: ToUnicodeSetElement, flags: ReadonlyFlags): boolean;
/**
* Returns whether the given character class/set matches no characters.
*
* This is guaranteed to be equivalent to `toCharSet(char).isEmpty` but is implemented more efficiently.
* This is guaranteed to be equivalent to `toUnicodeSet(char).isEmpty` but is implemented more efficiently.
*/
export declare function matchesNoCharacters(char: ToCharSetElement, flags: ReadonlyFlags): boolean;
export declare function matchesNoCharacters(char: ToUnicodeSetElement, flags: ReadonlyFlags): boolean;
/**
* Returns whether the given character elements contains strings.
*
* This is guaranteed to be equivalent to `!toUnicodeSet(char).accept.isEmpty` but is implemented more efficiently.
*/
export declare function hasStrings(char: ToUnicodeSetElement, flags: ReadonlyFlags): boolean;
/**
* A set of functions to get predefined character sets.

@@ -579,2 +675,6 @@ */

/**
* Returns the maximum character for the given flags.
*/
function maxChar(flags: ReadonlyFlags): Char;
/**
* Returns the empty character set for the given flags.

@@ -634,3 +734,3 @@ */

*/
export declare type FollowEndReason = "pattern" | "assertion";
export type FollowEndReason = "pattern" | "assertion";
/**

@@ -1017,3 +1117,3 @@ * A set of operations that determine how state is propagated and changed.

*/
export declare type FirstConsumedChar = FirstFullyConsumedChar | FirstPartiallyConsumedChar;
export type FirstConsumedChar = FirstFullyConsumedChar | FirstPartiallyConsumedChar;
/**

@@ -1255,3 +1355,18 @@ * This is equivalent to a regex fragment `[char]`.

): boolean;
export interface ConsumedChars {
chars: CharSet;
/**
* Whether `char` is exact.
*
* If `false`, then `char` is only guaranteed to be a superset of the
* actually possible characters.
*/
exact: boolean;
}
/**
* Returns the union of all characters that can possibly be consumed by the
* given element.
*/
export declare function getConsumedChars(element: Element | Pattern | Alternative, flags: ReadonlyFlags): ConsumedChars;
export {};

@@ -1,2 +0,2 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@eslint-community/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}),f=t.JS.createCharSet([{kind:"digit",negate:!1}],{unicode:!0});e.digit=function(e){return e.unicode?f:h};const p=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:p}}(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 S(e);case"CapturingGroup":case"Group":return e.alternatives.length>0&&e.alternatives.every(h);default:throw r(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 d(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 p(e){switch(e.type){case"Alternative":return e.elements.every(p);case"Assertion":case"Character":case"CharacterClass":case"CharacterSet":return!1;case"Backreference":return S(e);case"CapturingGroup":case"Group":return e.alternatives.length>0&&e.alternatives.every(p);case"Quantifier":return 0===e.max||p(e.element);default:throw r(e)}}function m(e){return function t(n){switch(n.type){case"Alternative":return n.elements.every(t);case"Assertion":case"Character":case"CharacterClass":case"CharacterSet":return!1;case"Backreference":return d(n,e);case"CapturingGroup":case"Group":return n.alternatives.some(t);case"Quantifier":return 0===n.min||t(n.element);default:throw r(n)}}(e)}function d(e,t){return!!S(e)||!!C(e.resolved,(e=>e===t))&&(!A(e)||f(e.resolved,t))}function C(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?x(e,t,r):r?x(e,(e=>e===t),r):e===t||C(t,e)}function x(e,t,r){if(t(e))return!0;if(r&&!r(e))return!1;switch(e.type){case"Alternative":case"CharacterClass":return e.elements.some((e=>x(e,t,r)));case"Assertion":return("lookahead"===e.kind||"lookbehind"===e.kind)&&e.alternatives.some((e=>x(e,t,r)));case"CapturingGroup":case"Group":case"Pattern":return e.alternatives.some((e=>x(e,t,r)));case"CharacterClassRange":return x(e.min,t,r)||x(e.max,t,r);case"Quantifier":return x(e.element,t,r);case"RegExpLiteral":return x(e.pattern,t,r)||x(e.flags,t,r)}return!1}function y(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 C(e,(e=>"Assertion"===e.type&&(t=e,!0))),void 0===t||"lookahead"===t.kind?"ltr":"rtl"}function k(e){return"ltr"===e?"rtl":"ltr"}function w(e){return"end"===e||"lookahead"===e?"ltr":"rtl"}function S(e){const t=e.resolved,r=O(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 A(e){const t=e.resolved,r=O(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 F(e){return g(e,E)}function E(e){return"CapturingGroup"===e.type}const b={min:0,max:0},_={min:1,max:1};function G(e){return a(e)?L(e):B(e)}function L(e){let t=1/0,r=0;for(const n of e){const e=B(n);t=Math.min(t,e.min),r=Math.max(r,e.max)}if(t>r)throw new RangeError("Expected the alternatives array to have at least one alternative.");return{min:t,max:r}}function B(e){switch(e.type){case"Assertion":return b;case"Character":case"CharacterClass":case"CharacterSet":return _;case"Quantifier":{if(0===e.max)return b;const t=B(e.element);return 0===t.max?b:{min:t.min*e.min,max:t.max*e.max}}case"Alternative":{let t=0,r=0;for(const n of e.elements){const e=B(n);t+=e.min,r+=e.max}return{min:t,max:r}}case"CapturingGroup":case"Group":return L(e.alternatives);case"Backreference":if(S(e))return b;{const t=B(e.resolved);return t.min>0&&!A(e)?{min:0,max:t.max}:t}default:throw r(e)}}function R(e){return a(e)?W(e):M(e)}function W(e){if(0===e.length)throw new RangeError("Expected the alternatives array to have at least one alternative.");return e.some(M)}function M(e){switch(e.type){case"Assertion":return!0;case"Character":case"CharacterClass":case"CharacterSet":return!1;case"Quantifier":return 0===e.min||M(e.element);case"Alternative":return e.elements.every(M);case"CapturingGroup":case"Group":return W(e.alternatives);case"Backreference":return S(e)||!A(e)||M(e.resolved);default:throw r(e)}}function O(...e){if(0!==e.length)return e.reduce(P)}function P(e,t){if(e===t)return e;if(e.parent&&e.parent===t.parent)return e.parent;{const r=J(e),n=J(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 J(e){const t=[];for(let r=e;r;r=r.parent)t.push(r);return t}function Q(e){return j.from(e)}class j{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 j?e:new j(e)}}function q(e,r){if(!a(e))return D(e,r);if(1===e.length)return D(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(T(n),r).union(...s.map((e=>t.JS.createCharSet(T(e.elements),r).negate()))):1===s.length?t.JS.createCharSet(T(s[0].elements),r).negate():exports.Chars.empty(r).union(...s.map((e=>t.JS.createCharSet(T(e.elements),r).negate()))):n.length?t.JS.createCharSet(T(n),r):exports.Chars.empty(r)}function D(e,t){if(t instanceof j){let r=t.toCharSet.get(e);return void 0===r&&(r=I(e,t),t.toCharSet.set(e,r)),r}return I(e,t)}function I(e,r){if("CharacterClass"===e.type){const n=t.JS.createCharSet(T(e.elements),r);return e.negate?n.negate():n}return t.JS.createCharSet([$(e)],r)}function T(e){return e.map($)}function $(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 z(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 U(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&&U(e.alternatives,r.alternatives)}return e.raw===r.raw}return!1}case"Backreference":{const r=t;return S(e)?S(r):z(e.resolved,r.resolved)&&A(e)==A(r)}case"Character":{const r=t;return e.value===r.value}case"CharacterClass":{const r=t;return e.negate===r.negate&&U(e.elements,r.elements)}case"CharacterClassRange":{const r=t;return z(e.min,r.min)&&z(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 U(e.alternatives,r.alternatives)}case"Quantifier":{const r=t;return e.min===r.min&&e.max===r.max&&e.greedy===r.greedy&&z(e.element,r.element)}case"RegExpLiteral":{const r=t;return z(e.flags,r.flags)&&z(e.pattern,r.pattern)}default:throw r(e)}}function U(e,t){if(e.length!==t.length)return!1;for(let r=0;r<e.length;r++)if(!z(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=w(e.kind),s=a.join(e.alternatives.map((e=>c(e,N(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,N(a,t,r),r))),r);break;case"Quantifier":0===e.max||(t=0===e.min?a.join([t,o(e.element,N(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,N(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 N(e,t,r){return e.fork?e.fork(t,r):t}var K,H;exports.FirstLookChars=void 0,(K=exports.FirstLookChars||(exports.FirstLookChars={})).all=function(e){return{char:exports.Chars.all(e),exact:!0,edge:!0}},K.edge=function(e){return{char:exports.Chars.empty(e),exact:!0,edge:!0}},K.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,(H=exports.FirstConsumedChars||(exports.FirstConsumedChars={})).emptyConcat=function(e){return{char:exports.Chars.empty(e),exact:!0,empty:!0,look:exports.FirstLookChars.all(e)}},H.emptyUnion=function(e){return{char:exports.Chars.empty(e),exact:!0,empty:!1}},H.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}},H.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}},H.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}},H.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 V{constructor(e){this._currentWordBoundaries=[],e instanceof j?(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 X(e,t,r){const n=new V(r);return a(e)?Y(e,t,r,n):ee(e,t,r,n)}function Y(e,t,r,n){return exports.FirstConsumedChars.union(e.map((e=>ee(e,t,r,n))),r)}function ee(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=ae(e,k(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 w(e.kind)===t?n.multiline?c():o():s();case"lookahead":case"lookbehind":if(w(e.kind)===t){if(e.negate){if(g(e,(t=>t!==e&&"Assertion"===t.type)))return s();const r=Y(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=Y(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:q(e,n),empty:!1,exact:!0};case"Quantifier":{if(0===e.max)return exports.FirstConsumedChars.emptyConcat(n);const r=ee(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 ee(e,t,n,a)}(),n)}case"CapturingGroup":case"Group":return Y(e.alternatives,t,n,a);case"Backreference":{if(S(e))return exports.FirstConsumedChars.emptyConcat(n);let r=ee(e.resolved,t,n,a);return r.exact&&r.char.size>1&&(r=Object.assign(Object.assign({},r),{exact:!1})),A(e)?r:exports.FirstConsumedChars.makeOptional(r)}default:throw r(e)}}(e,t,n,a),a.setCached(e,t,s)),s}function te(e,t,r){return re(e,t,r,new V(r))}function re(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=ee(e,a,r,n);return exports.FirstConsumedChars.concat([t,s],r)},continueInto:()=>!1,continueAfter:(e,t)=>t.empty,continueOutside:(e,t,r)=>w(e.kind)!==r},t)}function ne(e,t,r){return ae(e,t,r,new V(r))}function ae(e,t,r,n){return exports.FirstConsumedChars.toLook(re(e,t,r,n))}function se(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=ee(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)=>w(e.kind)!==r},t)}function oe(e,t,r,n={}){const a=j.from(r);r=a;const{includeAfter:s=!1,onlyInside:o=!1,looseGroups:c=!1}=n,i=a.getLongestPrefix,u=`${t},${s},${o},${c}`;let h=i.get(u);void 0===h&&(h=new WeakMap,i.set(u,h));let f=h.get(e);return void 0===f&&(f=function(e,t,r,n){const{chars:a,complete:s}=ue(e,t,r,n);for(let e=0;e<a.length;e++)if(a[e].isEmpty)return a.slice(0,e);s&&r.includeAfter&&!r.onlyInside&&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?ne(n[o],t,r):exports.FirstConsumedChars.toLook(he(e,t,r))}(e,t,n).char);return a}(e,t,{includeAfter:s,onlyInside:o,looseGroups:c,root:e},r),h.set(e,f)),f}const ce={chars:[],complete:!0},ie={chars:[],complete:!1};function ue(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=le(a[e],t,r,n);if(s.push(...o.chars),!o.complete)return{chars:s,complete:!1}}return{chars:s,complete:!0}}function le(e,t,n,a){switch(e.type){case"Assertion":return ce;case"Character":case"CharacterClass":case"CharacterSet":return{chars:[q(e,a)],complete:!0};case"CapturingGroup":case"Group":return function(e,t,r,n){const a=e.alternatives.map((e=>ue(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,!pe(e,r,t))break;u.push(ne(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 ce;if(R(e)){if(!fe(e,r,t))return ie;return{chars:[exports.FirstConsumedChars.toLook(he(e,t,n)).char],complete:!1}}const a=le(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(pe(e,r,t)){const r=ne(e,t,n);s.push(r.char.union(a.chars[0]))}return{chars:s,complete:!1}}(e,t,n,a);case"Backreference":if(S(e))return ce;if(A(e)){return le(e.resolved,t,Object.assign(Object.assign({},n),{includeAfter:!1}),a)}if(!fe(e,n,t))return ie;return{chars:[exports.FirstConsumedChars.toLook(he(e,t,a)).char],complete:!1};default:r(e)}}function he(e,t,r){const n=X(e,t,r);return n.empty?exports.FirstConsumedChars.concat([n,te(e,t,r)],r):n}function fe(e,t,r){return!!t.includeAfter&&(!t.onlyInside||function(e,t,r){return!R(e)||me(e,t,r)}(e,r,t.root))}function pe(e,t,r){return!!t.includeAfter&&(!t.onlyInside||me(e,r,t.root))}function me(e,t,r){const n=e.parent;if("CharacterClass"===n.type||"CharacterClassRange"===n.type)throw new Error("Expected an element outside a character class.");if("Quantifier"===n.type)return me(n,t,r);const a="ltr"===t?1:-1;for(let t=n.elements.indexOf(e)+a;t>=0&&t<n.elements.length;t+=a){if(!R(n.elements[t]))return!0}if(n===r)return!1;const s=n.parent;if("Pattern"===s.type)throw new Error("Expected the given element to be a descendant of the root alternative.");if("Assertion"===s.type)throw new Error;return me(s,t,r)}function de(e,t,r){return n(e),"unknown"===t?function(e,t){const r=ge(e,"ltr",t),n=ge(e,"rtl",t),a=xe([...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):ge(e,t,r)}const Ce={includeAfter:!0,looseGroups:!0};function ge(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=oe(e,r,n,Ce),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=xe(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 xe(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 ye(e,t,r,n,a){const s=de(t,r,n);return!(!a&&!function(e,t,r){let n=0,a=0;for(const r of t)F(r)&&(e.has(r)?n++:a++);if(n>1||1===n&&0!==a)return!1;if(0!==a)return r.every((t=>!t.some(F)||t.every((t=>!e.has(t)))));if(0!==n)return r.every((e=>e.length<2||!e.some(F)));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=ve(e,"ltr",t),n=ve(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=>ke(e,r)))),o="ltr"===t?n.right:n.left;if(o.some((e=>e.isDisjointWith(s))))return!0;const c=e[0].parent;if("Pattern"===c.type||"Assertion"===c.type)return!1;return ne(c,t,r).char.isDisjointWith(s)}(t,r,n)))))}function ve(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=q(t,r);else if(!s.equals(q(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 ke(e,t){const r=[];return g(e,(e=>("Character"===e.type||"CharacterClass"===e.type||"CharacterSet"===e.type?r.push(q(e,t)):"Backreference"!==e.type||S(e)||r.push(ke(e.resolved,t)),!1)),(e=>"Assertion"!==e.type&&"CharacterClass"!==e.type)),exports.Chars.empty(t).union(...r)}exports.canReorder=function(e,t,r={}){t=Q(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?ye(o,i,"ltr",t,a)&&ye(o,i,"rtl",t,a):ye(o,i,u,t,a)},exports.canReorderDirectional=ye,exports.containsCapturingGroup=F,exports.createCache=function(e){return new j(e)},exports.followPaths=Z,exports.getCapturingGroupNumber=function(t){let r=0;try{throw e.visitRegExpAST(y(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=O,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=ne,exports.getFirstCharAfterWithContributors=function(e,t,r){return function(e,t,r,n){const{char:a,contributors:s}=se(e,t,r,n);return{char:exports.FirstConsumedChars.toLook(a),contributors:s}}(e,t,r,new V(r))},exports.getFirstConsumedChar=X,exports.getFirstConsumedCharAfter=te,exports.getFirstConsumedCharAfterWithContributors=function(e,t,r){return se(e,t,r,new V(r))},exports.getLengthRange=G,exports.getLongestPrefix=oe,exports.getMatchingDirection=v,exports.getMatchingDirectionFromAssertionKind=w,exports.getPattern=y,exports.hasSomeAncestor=C,exports.hasSomeDescendant=g,exports.invertMatchingDirection=k,exports.isEmpty=function(e){return i(e,p)},exports.isEmptyBackreference=S,exports.isLengthRangeMinZero=R,exports.isPotentiallyEmpty=function(e){return u(e,m)},exports.isPotentiallyZeroLength=function(e){return u(e,(e=>f(e,e)))},exports.isStrictBackreference=A,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?q(e,t).isAll:"any"===e.kind&&!!t.dotAll:!(!e.negate||0!==e.elements.length)||(e.negate?q(e.elements,t).isEmpty:q(e.elements,t).isAll))},exports.matchesNoCharacters=function(e,t){return"Character"!==e.type&&"CharacterClassRange"!==e.type&&("CharacterSet"===e.type?"property"===e.kind&&q(e,t).isEmpty:!e.negate&&0===e.elements.length||(e.negate?q(e.elements,t).isAll:q(e.elements,t).isEmpty))},exports.structurallyEqual=z,exports.toCache=Q,exports.toCharSet=q;
"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;
//# sourceMappingURL=index.js.map
{
"name": "regexp-ast-analysis",
"version": "0.6.0",
"version": "0.7.0",
"description": "A library for analysing JS RegExp",

@@ -49,8 +49,8 @@ "main": "index",

"ts-node": "^8.10.2",
"typedoc": "^0.22.15",
"typescript": "^4.1.3"
"typedoc": "^0.24.8",
"typescript": "5.0"
},
"dependencies": {
"@eslint-community/regexpp": "^4.5.0",
"refa": "^0.11.0"
"@eslint-community/regexpp": "^4.8.0",
"refa": "^0.12.0"
},

@@ -57,0 +57,0 @@ "files": [

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc