source: imaps-frontend/node_modules/@eslint-community/regexpp/index.js

main
Last change on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 101.0 KB
RevLine 
[d565449]1'use strict';
2
3Object.defineProperty(exports, '__esModule', { value: true });
4
5var ast = /*#__PURE__*/Object.freeze({
6 __proto__: null
7});
8
9const latestEcmaVersion = 2025;
10
11let largeIdStartRanges = undefined;
12let largeIdContinueRanges = undefined;
13function isIdStart(cp) {
14 if (cp < 0x41)
15 return false;
16 if (cp < 0x5b)
17 return true;
18 if (cp < 0x61)
19 return false;
20 if (cp < 0x7b)
21 return true;
22 return isLargeIdStart(cp);
23}
24function isIdContinue(cp) {
25 if (cp < 0x30)
26 return false;
27 if (cp < 0x3a)
28 return true;
29 if (cp < 0x41)
30 return false;
31 if (cp < 0x5b)
32 return true;
33 if (cp === 0x5f)
34 return true;
35 if (cp < 0x61)
36 return false;
37 if (cp < 0x7b)
38 return true;
39 return isLargeIdStart(cp) || isLargeIdContinue(cp);
40}
41function isLargeIdStart(cp) {
42 return isInRange(cp, largeIdStartRanges !== null && largeIdStartRanges !== void 0 ? largeIdStartRanges : (largeIdStartRanges = initLargeIdStartRanges()));
43}
44function isLargeIdContinue(cp) {
45 return isInRange(cp, largeIdContinueRanges !== null && largeIdContinueRanges !== void 0 ? largeIdContinueRanges : (largeIdContinueRanges = initLargeIdContinueRanges()));
46}
47function initLargeIdStartRanges() {
48 return restoreRanges("4q 0 b 0 5 0 6 m 2 u 2 cp 5 b f 4 8 0 2 0 3m 4 2 1 3 3 2 0 7 0 2 2 2 0 2 j 2 2a 2 3u 9 4l 2 11 3 0 7 14 20 q 5 3 1a 16 10 1 2 2q 2 0 g 1 8 1 b 2 3 0 h 0 2 t u 2g c 0 p w a 1 5 0 6 l 5 0 a 0 4 0 o o 8 a 6 n 2 5 i 15 1n 1h 4 0 j 0 8 9 g f 5 7 3 1 3 l 2 6 2 0 4 3 4 0 h 0 e 1 2 2 f 1 b 0 9 5 5 1 3 l 2 6 2 1 2 1 2 1 w 3 2 0 k 2 h 8 2 2 2 l 2 6 2 1 2 4 4 0 j 0 g 1 o 0 c 7 3 1 3 l 2 6 2 1 2 4 4 0 v 1 2 2 g 0 i 0 2 5 4 2 2 3 4 1 2 0 2 1 4 1 4 2 4 b n 0 1h 7 2 2 2 m 2 f 4 0 r 2 3 0 3 1 v 0 5 7 2 2 2 m 2 9 2 4 4 0 w 1 2 1 g 1 i 8 2 2 2 14 3 0 h 0 6 2 9 2 p 5 6 h 4 n 2 8 2 0 3 6 1n 1b 2 1 d 6 1n 1 2 0 2 4 2 n 2 0 2 9 2 1 a 0 3 4 2 0 m 3 x 0 1s 7 2 z s 4 38 16 l 0 h 5 5 3 4 0 4 1 8 2 5 c d 0 i 11 2 0 6 0 3 16 2 98 2 3 3 6 2 0 2 3 3 14 2 3 3 w 2 3 3 6 2 0 2 3 3 e 2 1k 2 3 3 1u 12 f h 2d 3 5 4 h7 3 g 2 p 6 22 4 a 8 h e i f h f c 2 2 g 1f 10 0 5 0 1w 2g 8 14 2 0 6 1x b u 1e t 3 4 c 17 5 p 1j m a 1g 2b 0 2m 1a i 7 1j t e 1 b 17 r z 16 2 b z 3 8 8 16 3 2 16 3 2 5 2 1 4 0 6 5b 1t 7p 3 5 3 11 3 5 3 7 2 0 2 0 2 0 2 u 3 1g 2 6 2 0 4 2 2 6 4 3 3 5 5 c 6 2 2 6 39 0 e 0 h c 2u 0 5 0 3 9 2 0 3 5 7 0 2 0 2 0 2 f 3 3 6 4 5 0 i 14 22g 6c 7 3 4 1 d 11 2 0 6 0 3 1j 8 0 h m a 6 2 6 2 6 2 6 2 6 2 6 2 6 2 6 fb 2 q 8 8 4 3 4 5 2d 5 4 2 2h 2 3 6 16 2 2l i v 1d f e9 533 1t h3g 1w 19 3 7g 4 f b 1 l 1a h u 3 27 14 8 3 2u 3 1r 6 1 2 0 2 4 p f 2 2 2 3 2 m u 1f f 1d 1r 5 4 0 2 1 c r b m q s 8 1a t 0 h 4 2 9 b 4 2 14 o 2 2 7 l m 4 0 4 1d 2 0 4 1 3 4 3 0 2 0 p 2 3 a 8 2 d 5 3 5 3 5 a 6 2 6 2 16 2 d 7 36 u 8mb d m 5 1c 6it a5 3 2x 13 6 d 4 6 0 2 9 2 c 2 4 2 0 2 1 2 1 2 2z y a2 j 1r 3 1h 15 b 39 4 2 3q 11 p 7 p c 2g 4 5 3 5 3 5 3 2 10 b 2 p 2 i 2 1 2 e 3 d z 3e 1y 1g 7g s 4 1c 1c v e t 6 11 b t 3 z 5 7 2 4 17 4d j z 5 z 5 13 9 1f d a 2 e 2 6 2 1 2 a 2 e 2 6 2 1 1w 8m a l b 7 p 5 2 15 2 8 1y 5 3 0 2 17 2 1 4 0 3 m b m a u 1u i 2 1 b l b p 1z 1j 7 1 1t 0 g 3 2 2 2 s 17 s 4 s 10 7 2 r s 1h b l b i e h 33 20 1k 1e e 1e e z 9p 15 7 1 27 s b 0 9 l 17 h 1b k s m d 1g 1m 1 3 0 e 18 x o r z u 0 3 0 9 y 4 0 d 1b f 3 m 0 2 0 10 h 2 o k 1 1s 6 2 0 2 3 2 e 2 9 8 1a 13 7 3 1 3 l 2 6 2 1 2 4 4 0 j 0 d 4 4f 1g j 3 l 2 v 1b l 1 2 0 55 1a 16 3 11 1b l 0 1o 16 e 0 20 q 12 6 56 17 39 1r w 7 3 0 3 7 2 1 2 n g 0 2 0 2n 7 3 12 h 0 2 0 t 0 b 13 8 0 m 0 c 19 k 0 j 20 7c 8 2 10 i 0 1e t 35 6 2 1 2 11 m 0 q 5 2 1 2 v f 0 94 i g 0 2 c 2 x 3h 0 28 pl 2v 32 i 5f 219 2o g tr i 5 33u g6 6nu fs 8 u i 26 i t j 1b h 3 w k 6 i j5 1r 3l 22 6 0 1v c 1t 1 2 0 t 4qf 9 yd 17 8 6w8 3 2 6 2 1 2 82 g 0 u 2 3 0 f 3 9 az 1s5 2y 6 c 4 8 8 9 4mf 2c 2 1y 2 1 3 0 3 1 3 3 2 b 2 0 2 6 2 1s 2 3 3 7 2 6 2 r 2 3 2 4 2 0 4 6 2 9f 3 o 2 o 2 u 2 o 2 u 2 o 2 u 2 o 2 u 2 o 2 7 1f9 u 7 5 7a 1p 43 18 b 6 h 0 8y t j 17 dh r l1 6 2 3 2 1 2 e 2 5g 1o 1v 8 0 xh 3 2 q 2 1 2 0 3 0 2 9 2 3 2 0 2 0 7 0 5 0 2 0 2 0 2 2 2 1 2 0 3 0 2 0 2 0 2 0 2 0 2 1 2 0 3 3 2 6 2 3 2 3 2 0 2 9 2 g 6 2 2 4 2 g 3et wyn x 37d 7 65 3 4g1 f 5rk g h9 1wj f1 15v 3t6 6 38f");
49}
50function initLargeIdContinueRanges() {
51 return restoreRanges("53 0 g9 33 o 0 70 4 7e 18 2 0 2 1 2 1 2 0 21 a 1d u 7 0 2u 6 3 5 3 1 2 3 3 9 o 0 v q 2k a g 9 y 8 a 0 p 3 2 8 2 2 2 4 18 2 1p 7 17 n 2 w 1j 2 2 h 2 6 b 1 3 9 i 2 1l 0 2 6 3 1 3 2 a 0 b 1 3 9 f 0 3 2 1l 0 2 4 5 1 3 2 4 0 l b 4 0 c 2 1l 0 2 7 2 2 2 2 l 1 3 9 b 5 2 2 1l 0 2 6 3 1 3 2 8 2 b 1 3 9 j 0 1o 4 4 2 2 3 a 0 f 9 h 4 1k 0 2 6 2 2 2 3 8 1 c 1 3 9 i 2 1l 0 2 6 2 2 2 3 8 1 c 1 3 9 4 0 d 3 1k 1 2 6 2 2 2 3 a 0 b 1 3 9 i 2 1z 0 5 5 2 0 2 7 7 9 3 1 1q 0 3 6 d 7 2 9 2g 0 3 8 c 6 2 9 1r 1 7 9 c 0 2 0 2 0 5 1 1e j 2 1 6 a 2 z a 0 2t j 2 9 d 3 5 2 2 2 3 6 4 3 e b 2 e jk 2 a 8 pt 3 t 2 u 1 v 1 1t v a 0 3 9 y 2 2 a 40 0 3b b 5 b b 9 3l a 1p 4 1m 9 2 s 3 a 7 9 n d 2 f 1e 4 1c g c 9 i 8 d 2 v c 3 9 19 d 1d j 9 9 7 9 3b 2 2 k 5 0 7 0 3 2 5j 1r el 1 1e 1 k 0 3g c 5 0 4 b 2db 2 3y 0 2p v ff 5 2y 1 2p 0 n51 9 1y 0 5 9 x 1 29 1 7l 0 4 0 5 0 o 4 5 0 2c 1 1f h b 9 7 h e a t 7 q c 19 3 1c d g 9 c 0 b 9 1c d d 0 9 1 3 9 y 2 1f 0 2 2 3 1 6 1 2 0 16 4 6 1 6l 7 2 1 3 9 fmt 0 ki f h f 4 1 p 2 5d 9 12 0 12 0 ig 0 6b 0 46 4 86 9 120 2 2 1 6 3 15 2 5 0 4m 1 fy 3 9 9 aa 1 29 2 1z a 1e 3 3f 2 1i e w a 3 1 b 3 1a a 8 0 1a 9 7 2 11 d 2 9 6 1 19 0 d 2 1d d 9 3 2 b 2b b 7 0 3 0 4e b 6 9 7 3 1k 1 2 6 3 1 3 2 a 0 b 1 3 6 4 4 5d h a 9 5 0 2a j d 9 5y 6 3 8 s 1 2b g g 9 2a c 9 9 2c e 5 9 6r e 4m 9 1z 5 2 1 3 3 2 0 2 1 d 9 3c 6 3 6 4 0 t 9 15 6 2 3 9 0 a a 1b f ba 7 2 7 h 9 1l l 2 d 3f 5 4 0 2 1 2 6 2 0 9 9 1d 4 2 1 2 4 9 9 96 3 a 1 2 0 1d 6 4 4 e 9 44n 0 7 e aob 9 2f 9 13 4 1o 6 q 9 s6 0 2 1i 8 3 2a 0 c 1 f58 1 3mq 19 3 m f3 4 4 5 9 7 3 6 v 3 45 2 13e 1d e9 1i 5 1d 9 0 f 0 n 4 2 e 11t 6 2 g 3 6 2 1 2 4 2t 0 4h 6 a 9 9x 0 1q d dv d rb 6 32 6 6 9 3o7 9 gvt3 6n");
52}
53function isInRange(cp, ranges) {
54 let l = 0, r = (ranges.length / 2) | 0, i = 0, min = 0, max = 0;
55 while (l < r) {
56 i = ((l + r) / 2) | 0;
57 min = ranges[2 * i];
58 max = ranges[2 * i + 1];
59 if (cp < min) {
60 r = i;
61 }
62 else if (cp > max) {
63 l = i + 1;
64 }
65 else {
66 return true;
67 }
68 }
69 return false;
70}
71function restoreRanges(data) {
72 let last = 0;
73 return data.split(" ").map((s) => (last += parseInt(s, 36) | 0));
74}
75
76class DataSet {
77 constructor(raw2018, raw2019, raw2020, raw2021, raw2022, raw2023, raw2024, raw2025) {
78 this._raw2018 = raw2018;
79 this._raw2019 = raw2019;
80 this._raw2020 = raw2020;
81 this._raw2021 = raw2021;
82 this._raw2022 = raw2022;
83 this._raw2023 = raw2023;
84 this._raw2024 = raw2024;
85 this._raw2025 = raw2025;
86 }
87 get es2018() {
88 var _a;
89 return ((_a = this._set2018) !== null && _a !== void 0 ? _a : (this._set2018 = new Set(this._raw2018.split(" "))));
90 }
91 get es2019() {
92 var _a;
93 return ((_a = this._set2019) !== null && _a !== void 0 ? _a : (this._set2019 = new Set(this._raw2019.split(" "))));
94 }
95 get es2020() {
96 var _a;
97 return ((_a = this._set2020) !== null && _a !== void 0 ? _a : (this._set2020 = new Set(this._raw2020.split(" "))));
98 }
99 get es2021() {
100 var _a;
101 return ((_a = this._set2021) !== null && _a !== void 0 ? _a : (this._set2021 = new Set(this._raw2021.split(" "))));
102 }
103 get es2022() {
104 var _a;
105 return ((_a = this._set2022) !== null && _a !== void 0 ? _a : (this._set2022 = new Set(this._raw2022.split(" "))));
106 }
107 get es2023() {
108 var _a;
109 return ((_a = this._set2023) !== null && _a !== void 0 ? _a : (this._set2023 = new Set(this._raw2023.split(" "))));
110 }
111 get es2024() {
112 var _a;
113 return ((_a = this._set2024) !== null && _a !== void 0 ? _a : (this._set2024 = new Set(this._raw2024.split(" "))));
114 }
115 get es2025() {
116 var _a;
117 return ((_a = this._set2025) !== null && _a !== void 0 ? _a : (this._set2025 = new Set(this._raw2025.split(" "))));
118 }
119}
120const gcNameSet = new Set(["General_Category", "gc"]);
121const scNameSet = new Set(["Script", "Script_Extensions", "sc", "scx"]);
122const gcValueSets = new DataSet("C Cased_Letter Cc Cf Close_Punctuation Cn Co Combining_Mark Connector_Punctuation Control Cs Currency_Symbol Dash_Punctuation Decimal_Number Enclosing_Mark Final_Punctuation Format Initial_Punctuation L LC Letter Letter_Number Line_Separator Ll Lm Lo Lowercase_Letter Lt Lu M Mark Math_Symbol Mc Me Mn Modifier_Letter Modifier_Symbol N Nd Nl No Nonspacing_Mark Number Open_Punctuation Other Other_Letter Other_Number Other_Punctuation Other_Symbol P Paragraph_Separator Pc Pd Pe Pf Pi Po Private_Use Ps Punctuation S Sc Separator Sk Sm So Space_Separator Spacing_Mark Surrogate Symbol Titlecase_Letter Unassigned Uppercase_Letter Z Zl Zp Zs cntrl digit punct", "", "", "", "", "", "", "");
123const scValueSets = new DataSet("Adlam Adlm Aghb Ahom Anatolian_Hieroglyphs Arab Arabic Armenian Armi Armn Avestan Avst Bali Balinese Bamu Bamum Bass Bassa_Vah Batak Batk Beng Bengali Bhaiksuki Bhks Bopo Bopomofo Brah Brahmi Brai Braille Bugi Buginese Buhd Buhid Cakm Canadian_Aboriginal Cans Cari Carian Caucasian_Albanian Chakma Cham Cher Cherokee Common Copt Coptic Cprt Cuneiform Cypriot Cyrillic Cyrl Deseret Deva Devanagari Dsrt Dupl Duployan Egyp Egyptian_Hieroglyphs Elba Elbasan Ethi Ethiopic Geor Georgian Glag Glagolitic Gonm Goth Gothic Gran Grantha Greek Grek Gujarati Gujr Gurmukhi Guru Han Hang Hangul Hani Hano Hanunoo Hatr Hatran Hebr Hebrew Hira Hiragana Hluw Hmng Hung Imperial_Aramaic Inherited Inscriptional_Pahlavi Inscriptional_Parthian Ital Java Javanese Kaithi Kali Kana Kannada Katakana Kayah_Li Khar Kharoshthi Khmer Khmr Khoj Khojki Khudawadi Knda Kthi Lana Lao Laoo Latin Latn Lepc Lepcha Limb Limbu Lina Linb Linear_A Linear_B Lisu Lyci Lycian Lydi Lydian Mahajani Mahj Malayalam Mand Mandaic Mani Manichaean Marc Marchen Masaram_Gondi Meetei_Mayek Mend Mende_Kikakui Merc Mero Meroitic_Cursive Meroitic_Hieroglyphs Miao Mlym Modi Mong Mongolian Mro Mroo Mtei Mult Multani Myanmar Mymr Nabataean Narb Nbat New_Tai_Lue Newa Nko Nkoo Nshu Nushu Ogam Ogham Ol_Chiki Olck Old_Hungarian Old_Italic Old_North_Arabian Old_Permic Old_Persian Old_South_Arabian Old_Turkic Oriya Orkh Orya Osage Osge Osma Osmanya Pahawh_Hmong Palm Palmyrene Pau_Cin_Hau Pauc Perm Phag Phags_Pa Phli Phlp Phnx Phoenician Plrd Prti Psalter_Pahlavi Qaac Qaai Rejang Rjng Runic Runr Samaritan Samr Sarb Saur Saurashtra Sgnw Sharada Shavian Shaw Shrd Sidd Siddham SignWriting Sind Sinh Sinhala Sora Sora_Sompeng Soyo Soyombo Sund Sundanese Sylo Syloti_Nagri Syrc Syriac Tagalog Tagb Tagbanwa Tai_Le Tai_Tham Tai_Viet Takr Takri Tale Talu Tamil Taml Tang Tangut Tavt Telu Telugu Tfng Tglg Thaa Thaana Thai Tibetan Tibt Tifinagh Tirh Tirhuta Ugar Ugaritic Vai Vaii Wara Warang_Citi Xpeo Xsux Yi Yiii Zanabazar_Square Zanb Zinh Zyyy", "Dogr Dogra Gong Gunjala_Gondi Hanifi_Rohingya Maka Makasar Medefaidrin Medf Old_Sogdian Rohg Sogd Sogdian Sogo", "Elym Elymaic Hmnp Nand Nandinagari Nyiakeng_Puachue_Hmong Wancho Wcho", "Chorasmian Chrs Diak Dives_Akuru Khitan_Small_Script Kits Yezi Yezidi", "Cpmn Cypro_Minoan Old_Uyghur Ougr Tangsa Tnsa Toto Vith Vithkuqi", "Hrkt Katakana_Or_Hiragana Kawi Nag_Mundari Nagm Unknown Zzzz", "", "");
124const binPropertySets = new DataSet("AHex ASCII ASCII_Hex_Digit Alpha Alphabetic Any Assigned Bidi_C Bidi_Control Bidi_M Bidi_Mirrored CI CWCF CWCM CWKCF CWL CWT CWU Case_Ignorable Cased Changes_When_Casefolded Changes_When_Casemapped Changes_When_Lowercased Changes_When_NFKC_Casefolded Changes_When_Titlecased Changes_When_Uppercased DI Dash Default_Ignorable_Code_Point Dep Deprecated Dia Diacritic Emoji Emoji_Component Emoji_Modifier Emoji_Modifier_Base Emoji_Presentation Ext Extender Gr_Base Gr_Ext Grapheme_Base Grapheme_Extend Hex Hex_Digit IDC IDS IDSB IDST IDS_Binary_Operator IDS_Trinary_Operator ID_Continue ID_Start Ideo Ideographic Join_C Join_Control LOE Logical_Order_Exception Lower Lowercase Math NChar Noncharacter_Code_Point Pat_Syn Pat_WS Pattern_Syntax Pattern_White_Space QMark Quotation_Mark RI Radical Regional_Indicator SD STerm Sentence_Terminal Soft_Dotted Term Terminal_Punctuation UIdeo Unified_Ideograph Upper Uppercase VS Variation_Selector White_Space XIDC XIDS XID_Continue XID_Start space", "Extended_Pictographic", "", "EBase EComp EMod EPres ExtPict", "", "", "", "");
125const binPropertyOfStringsSets = new DataSet("", "", "", "", "", "", "Basic_Emoji Emoji_Keycap_Sequence RGI_Emoji RGI_Emoji_Flag_Sequence RGI_Emoji_Modifier_Sequence RGI_Emoji_Tag_Sequence RGI_Emoji_ZWJ_Sequence", "");
126function isValidUnicodeProperty(version, name, value) {
127 if (gcNameSet.has(name)) {
128 return version >= 2018 && gcValueSets.es2018.has(value);
129 }
130 if (scNameSet.has(name)) {
131 return ((version >= 2018 && scValueSets.es2018.has(value)) ||
132 (version >= 2019 && scValueSets.es2019.has(value)) ||
133 (version >= 2020 && scValueSets.es2020.has(value)) ||
134 (version >= 2021 && scValueSets.es2021.has(value)) ||
135 (version >= 2022 && scValueSets.es2022.has(value)) ||
136 (version >= 2023 && scValueSets.es2023.has(value)));
137 }
138 return false;
139}
140function isValidLoneUnicodeProperty(version, value) {
141 return ((version >= 2018 && binPropertySets.es2018.has(value)) ||
142 (version >= 2019 && binPropertySets.es2019.has(value)) ||
143 (version >= 2021 && binPropertySets.es2021.has(value)));
144}
145function isValidLoneUnicodePropertyOfString(version, value) {
146 return version >= 2024 && binPropertyOfStringsSets.es2024.has(value);
147}
148
149const BACKSPACE = 0x08;
150const CHARACTER_TABULATION = 0x09;
151const LINE_FEED = 0x0a;
152const LINE_TABULATION = 0x0b;
153const FORM_FEED = 0x0c;
154const CARRIAGE_RETURN = 0x0d;
155const EXCLAMATION_MARK = 0x21;
156const NUMBER_SIGN = 0x23;
157const DOLLAR_SIGN = 0x24;
158const PERCENT_SIGN = 0x25;
159const AMPERSAND = 0x26;
160const LEFT_PARENTHESIS = 0x28;
161const RIGHT_PARENTHESIS = 0x29;
162const ASTERISK = 0x2a;
163const PLUS_SIGN = 0x2b;
164const COMMA = 0x2c;
165const HYPHEN_MINUS = 0x2d;
166const FULL_STOP = 0x2e;
167const SOLIDUS = 0x2f;
168const DIGIT_ZERO = 0x30;
169const DIGIT_ONE = 0x31;
170const DIGIT_SEVEN = 0x37;
171const DIGIT_NINE = 0x39;
172const COLON = 0x3a;
173const SEMICOLON = 0x3b;
174const LESS_THAN_SIGN = 0x3c;
175const EQUALS_SIGN = 0x3d;
176const GREATER_THAN_SIGN = 0x3e;
177const QUESTION_MARK = 0x3f;
178const COMMERCIAL_AT = 0x40;
179const LATIN_CAPITAL_LETTER_A = 0x41;
180const LATIN_CAPITAL_LETTER_B = 0x42;
181const LATIN_CAPITAL_LETTER_D = 0x44;
182const LATIN_CAPITAL_LETTER_F = 0x46;
183const LATIN_CAPITAL_LETTER_P = 0x50;
184const LATIN_CAPITAL_LETTER_S = 0x53;
185const LATIN_CAPITAL_LETTER_W = 0x57;
186const LATIN_CAPITAL_LETTER_Z = 0x5a;
187const LOW_LINE = 0x5f;
188const LATIN_SMALL_LETTER_A = 0x61;
189const LATIN_SMALL_LETTER_B = 0x62;
190const LATIN_SMALL_LETTER_C = 0x63;
191const LATIN_SMALL_LETTER_D = 0x64;
192const LATIN_SMALL_LETTER_F = 0x66;
193const LATIN_SMALL_LETTER_G = 0x67;
194const LATIN_SMALL_LETTER_I = 0x69;
195const LATIN_SMALL_LETTER_K = 0x6b;
196const LATIN_SMALL_LETTER_M = 0x6d;
197const LATIN_SMALL_LETTER_N = 0x6e;
198const LATIN_SMALL_LETTER_P = 0x70;
199const LATIN_SMALL_LETTER_Q = 0x71;
200const LATIN_SMALL_LETTER_R = 0x72;
201const LATIN_SMALL_LETTER_S = 0x73;
202const LATIN_SMALL_LETTER_T = 0x74;
203const LATIN_SMALL_LETTER_U = 0x75;
204const LATIN_SMALL_LETTER_V = 0x76;
205const LATIN_SMALL_LETTER_W = 0x77;
206const LATIN_SMALL_LETTER_X = 0x78;
207const LATIN_SMALL_LETTER_Y = 0x79;
208const LATIN_SMALL_LETTER_Z = 0x7a;
209const LEFT_SQUARE_BRACKET = 0x5b;
210const REVERSE_SOLIDUS = 0x5c;
211const RIGHT_SQUARE_BRACKET = 0x5d;
212const CIRCUMFLEX_ACCENT = 0x5e;
213const GRAVE_ACCENT = 0x60;
214const LEFT_CURLY_BRACKET = 0x7b;
215const VERTICAL_LINE = 0x7c;
216const RIGHT_CURLY_BRACKET = 0x7d;
217const TILDE = 0x7e;
218const ZERO_WIDTH_NON_JOINER = 0x200c;
219const ZERO_WIDTH_JOINER = 0x200d;
220const LINE_SEPARATOR = 0x2028;
221const PARAGRAPH_SEPARATOR = 0x2029;
222const MIN_CODE_POINT = 0x00;
223const MAX_CODE_POINT = 0x10ffff;
224function isLatinLetter(code) {
225 return ((code >= LATIN_CAPITAL_LETTER_A && code <= LATIN_CAPITAL_LETTER_Z) ||
226 (code >= LATIN_SMALL_LETTER_A && code <= LATIN_SMALL_LETTER_Z));
227}
228function isDecimalDigit(code) {
229 return code >= DIGIT_ZERO && code <= DIGIT_NINE;
230}
231function isOctalDigit(code) {
232 return code >= DIGIT_ZERO && code <= DIGIT_SEVEN;
233}
234function isHexDigit(code) {
235 return ((code >= DIGIT_ZERO && code <= DIGIT_NINE) ||
236 (code >= LATIN_CAPITAL_LETTER_A && code <= LATIN_CAPITAL_LETTER_F) ||
237 (code >= LATIN_SMALL_LETTER_A && code <= LATIN_SMALL_LETTER_F));
238}
239function isLineTerminator(code) {
240 return (code === LINE_FEED ||
241 code === CARRIAGE_RETURN ||
242 code === LINE_SEPARATOR ||
243 code === PARAGRAPH_SEPARATOR);
244}
245function isValidUnicode(code) {
246 return code >= MIN_CODE_POINT && code <= MAX_CODE_POINT;
247}
248function digitToInt(code) {
249 if (code >= LATIN_SMALL_LETTER_A && code <= LATIN_SMALL_LETTER_F) {
250 return code - LATIN_SMALL_LETTER_A + 10;
251 }
252 if (code >= LATIN_CAPITAL_LETTER_A && code <= LATIN_CAPITAL_LETTER_F) {
253 return code - LATIN_CAPITAL_LETTER_A + 10;
254 }
255 return code - DIGIT_ZERO;
256}
257function isLeadSurrogate(code) {
258 return code >= 0xd800 && code <= 0xdbff;
259}
260function isTrailSurrogate(code) {
261 return code >= 0xdc00 && code <= 0xdfff;
262}
263function combineSurrogatePair(lead, trail) {
264 return (lead - 0xd800) * 0x400 + (trail - 0xdc00) + 0x10000;
265}
266
267class GroupSpecifiersAsES2018 {
268 constructor() {
269 this.groupName = new Set();
270 }
271 clear() {
272 this.groupName.clear();
273 }
274 isEmpty() {
275 return !this.groupName.size;
276 }
277 hasInPattern(name) {
278 return this.groupName.has(name);
279 }
280 hasInScope(name) {
281 return this.hasInPattern(name);
282 }
283 addToScope(name) {
284 this.groupName.add(name);
285 }
286 enterDisjunction() {
287 }
288 enterAlternative() {
289 }
290 leaveDisjunction() {
291 }
292}
293class BranchID {
294 constructor(parent, base) {
295 this.parent = parent;
296 this.base = base !== null && base !== void 0 ? base : this;
297 }
298 separatedFrom(other) {
299 var _a, _b;
300 if (this.base === other.base && this !== other) {
301 return true;
302 }
303 if (other.parent && this.separatedFrom(other.parent)) {
304 return true;
305 }
306 return (_b = (_a = this.parent) === null || _a === void 0 ? void 0 : _a.separatedFrom(other)) !== null && _b !== void 0 ? _b : false;
307 }
308 child() {
309 return new BranchID(this, null);
310 }
311 sibling() {
312 return new BranchID(this.parent, this.base);
313 }
314}
315class GroupSpecifiersAsES2025 {
316 constructor() {
317 this.branchID = new BranchID(null, null);
318 this.groupNames = new Map();
319 }
320 clear() {
321 this.branchID = new BranchID(null, null);
322 this.groupNames.clear();
323 }
324 isEmpty() {
325 return !this.groupNames.size;
326 }
327 enterDisjunction() {
328 this.branchID = this.branchID.child();
329 }
330 enterAlternative(index) {
331 if (index === 0) {
332 return;
333 }
334 this.branchID = this.branchID.sibling();
335 }
336 leaveDisjunction() {
337 this.branchID = this.branchID.parent;
338 }
339 hasInPattern(name) {
340 return this.groupNames.has(name);
341 }
342 hasInScope(name) {
343 const branches = this.groupNames.get(name);
344 if (!branches) {
345 return false;
346 }
347 for (const branch of branches) {
348 if (!branch.separatedFrom(this.branchID)) {
349 return true;
350 }
351 }
352 return false;
353 }
354 addToScope(name) {
355 const branches = this.groupNames.get(name);
356 if (branches) {
357 branches.push(this.branchID);
358 return;
359 }
360 this.groupNames.set(name, [this.branchID]);
361 }
362}
363
364const legacyImpl = {
365 at(s, end, i) {
366 return i < end ? s.charCodeAt(i) : -1;
367 },
368 width(c) {
369 return 1;
370 },
371};
372const unicodeImpl = {
373 at(s, end, i) {
374 return i < end ? s.codePointAt(i) : -1;
375 },
376 width(c) {
377 return c > 0xffff ? 2 : 1;
378 },
379};
380class Reader {
381 constructor() {
382 this._impl = legacyImpl;
383 this._s = "";
384 this._i = 0;
385 this._end = 0;
386 this._cp1 = -1;
387 this._w1 = 1;
388 this._cp2 = -1;
389 this._w2 = 1;
390 this._cp3 = -1;
391 this._w3 = 1;
392 this._cp4 = -1;
393 }
394 get source() {
395 return this._s;
396 }
397 get index() {
398 return this._i;
399 }
400 get currentCodePoint() {
401 return this._cp1;
402 }
403 get nextCodePoint() {
404 return this._cp2;
405 }
406 get nextCodePoint2() {
407 return this._cp3;
408 }
409 get nextCodePoint3() {
410 return this._cp4;
411 }
412 reset(source, start, end, uFlag) {
413 this._impl = uFlag ? unicodeImpl : legacyImpl;
414 this._s = source;
415 this._end = end;
416 this.rewind(start);
417 }
418 rewind(index) {
419 const impl = this._impl;
420 this._i = index;
421 this._cp1 = impl.at(this._s, this._end, index);
422 this._w1 = impl.width(this._cp1);
423 this._cp2 = impl.at(this._s, this._end, index + this._w1);
424 this._w2 = impl.width(this._cp2);
425 this._cp3 = impl.at(this._s, this._end, index + this._w1 + this._w2);
426 this._w3 = impl.width(this._cp3);
427 this._cp4 = impl.at(this._s, this._end, index + this._w1 + this._w2 + this._w3);
428 }
429 advance() {
430 if (this._cp1 !== -1) {
431 const impl = this._impl;
432 this._i += this._w1;
433 this._cp1 = this._cp2;
434 this._w1 = this._w2;
435 this._cp2 = this._cp3;
436 this._w2 = impl.width(this._cp2);
437 this._cp3 = this._cp4;
438 this._w3 = impl.width(this._cp3);
439 this._cp4 = impl.at(this._s, this._end, this._i + this._w1 + this._w2 + this._w3);
440 }
441 }
442 eat(cp) {
443 if (this._cp1 === cp) {
444 this.advance();
445 return true;
446 }
447 return false;
448 }
449 eat2(cp1, cp2) {
450 if (this._cp1 === cp1 && this._cp2 === cp2) {
451 this.advance();
452 this.advance();
453 return true;
454 }
455 return false;
456 }
457 eat3(cp1, cp2, cp3) {
458 if (this._cp1 === cp1 && this._cp2 === cp2 && this._cp3 === cp3) {
459 this.advance();
460 this.advance();
461 this.advance();
462 return true;
463 }
464 return false;
465 }
466}
467
468class RegExpSyntaxError extends SyntaxError {
469 constructor(message, index) {
470 super(message);
471 this.index = index;
472 }
473}
474function newRegExpSyntaxError(srcCtx, flags, index, message) {
475 let source = "";
476 if (srcCtx.kind === "literal") {
477 const literal = srcCtx.source.slice(srcCtx.start, srcCtx.end);
478 if (literal) {
479 source = `: ${literal}`;
480 }
481 }
482 else if (srcCtx.kind === "pattern") {
483 const pattern = srcCtx.source.slice(srcCtx.start, srcCtx.end);
484 const flagsText = `${flags.unicode ? "u" : ""}${flags.unicodeSets ? "v" : ""}`;
485 source = `: /${pattern}/${flagsText}`;
486 }
487 return new RegExpSyntaxError(`Invalid regular expression${source}: ${message}`, index);
488}
489
490const SYNTAX_CHARACTER = new Set([
491 CIRCUMFLEX_ACCENT,
492 DOLLAR_SIGN,
493 REVERSE_SOLIDUS,
494 FULL_STOP,
495 ASTERISK,
496 PLUS_SIGN,
497 QUESTION_MARK,
498 LEFT_PARENTHESIS,
499 RIGHT_PARENTHESIS,
500 LEFT_SQUARE_BRACKET,
501 RIGHT_SQUARE_BRACKET,
502 LEFT_CURLY_BRACKET,
503 RIGHT_CURLY_BRACKET,
504 VERTICAL_LINE,
505]);
506const CLASS_SET_RESERVED_DOUBLE_PUNCTUATOR_CHARACTER = new Set([
507 AMPERSAND,
508 EXCLAMATION_MARK,
509 NUMBER_SIGN,
510 DOLLAR_SIGN,
511 PERCENT_SIGN,
512 ASTERISK,
513 PLUS_SIGN,
514 COMMA,
515 FULL_STOP,
516 COLON,
517 SEMICOLON,
518 LESS_THAN_SIGN,
519 EQUALS_SIGN,
520 GREATER_THAN_SIGN,
521 QUESTION_MARK,
522 COMMERCIAL_AT,
523 CIRCUMFLEX_ACCENT,
524 GRAVE_ACCENT,
525 TILDE,
526]);
527const CLASS_SET_SYNTAX_CHARACTER = new Set([
528 LEFT_PARENTHESIS,
529 RIGHT_PARENTHESIS,
530 LEFT_SQUARE_BRACKET,
531 RIGHT_SQUARE_BRACKET,
532 LEFT_CURLY_BRACKET,
533 RIGHT_CURLY_BRACKET,
534 SOLIDUS,
535 HYPHEN_MINUS,
536 REVERSE_SOLIDUS,
537 VERTICAL_LINE,
538]);
539const CLASS_SET_RESERVED_PUNCTUATOR = new Set([
540 AMPERSAND,
541 HYPHEN_MINUS,
542 EXCLAMATION_MARK,
543 NUMBER_SIGN,
544 PERCENT_SIGN,
545 COMMA,
546 COLON,
547 SEMICOLON,
548 LESS_THAN_SIGN,
549 EQUALS_SIGN,
550 GREATER_THAN_SIGN,
551 COMMERCIAL_AT,
552 GRAVE_ACCENT,
553 TILDE,
554]);
555function isSyntaxCharacter(cp) {
556 return SYNTAX_CHARACTER.has(cp);
557}
558function isClassSetReservedDoublePunctuatorCharacter(cp) {
559 return CLASS_SET_RESERVED_DOUBLE_PUNCTUATOR_CHARACTER.has(cp);
560}
561function isClassSetSyntaxCharacter(cp) {
562 return CLASS_SET_SYNTAX_CHARACTER.has(cp);
563}
564function isClassSetReservedPunctuator(cp) {
565 return CLASS_SET_RESERVED_PUNCTUATOR.has(cp);
566}
567function isIdentifierStartChar(cp) {
568 return isIdStart(cp) || cp === DOLLAR_SIGN || cp === LOW_LINE;
569}
570function isIdentifierPartChar(cp) {
571 return (isIdContinue(cp) ||
572 cp === DOLLAR_SIGN ||
573 cp === ZERO_WIDTH_NON_JOINER ||
574 cp === ZERO_WIDTH_JOINER);
575}
576function isUnicodePropertyNameCharacter(cp) {
577 return isLatinLetter(cp) || cp === LOW_LINE;
578}
579function isUnicodePropertyValueCharacter(cp) {
580 return isUnicodePropertyNameCharacter(cp) || isDecimalDigit(cp);
581}
582class RegExpValidator {
583 constructor(options) {
584 this._reader = new Reader();
585 this._unicodeMode = false;
586 this._unicodeSetsMode = false;
587 this._nFlag = false;
588 this._lastIntValue = 0;
589 this._lastRange = {
590 min: 0,
591 max: Number.POSITIVE_INFINITY,
592 };
593 this._lastStrValue = "";
594 this._lastAssertionIsQuantifiable = false;
595 this._numCapturingParens = 0;
596 this._backreferenceNames = new Set();
597 this._srcCtx = null;
598 this._options = options !== null && options !== void 0 ? options : {};
599 this._groupSpecifiers =
600 this.ecmaVersion >= 2025
601 ? new GroupSpecifiersAsES2025()
602 : new GroupSpecifiersAsES2018();
603 }
604 validateLiteral(source, start = 0, end = source.length) {
605 this._srcCtx = { source, start, end, kind: "literal" };
606 this._unicodeSetsMode = this._unicodeMode = this._nFlag = false;
607 this.reset(source, start, end);
608 this.onLiteralEnter(start);
609 if (this.eat(SOLIDUS) && this.eatRegExpBody() && this.eat(SOLIDUS)) {
610 const flagStart = this.index;
611 const unicode = source.includes("u", flagStart);
612 const unicodeSets = source.includes("v", flagStart);
613 this.validateFlagsInternal(source, flagStart, end);
614 this.validatePatternInternal(source, start + 1, flagStart - 1, {
615 unicode,
616 unicodeSets,
617 });
618 }
619 else if (start >= end) {
620 this.raise("Empty");
621 }
622 else {
623 const c = String.fromCodePoint(this.currentCodePoint);
624 this.raise(`Unexpected character '${c}'`);
625 }
626 this.onLiteralLeave(start, end);
627 }
628 validateFlags(source, start = 0, end = source.length) {
629 this._srcCtx = { source, start, end, kind: "flags" };
630 this.validateFlagsInternal(source, start, end);
631 }
632 validatePattern(source, start = 0, end = source.length, uFlagOrFlags = undefined) {
633 this._srcCtx = { source, start, end, kind: "pattern" };
634 this.validatePatternInternal(source, start, end, uFlagOrFlags);
635 }
636 validatePatternInternal(source, start = 0, end = source.length, uFlagOrFlags = undefined) {
637 const mode = this._parseFlagsOptionToMode(uFlagOrFlags, end);
638 this._unicodeMode = mode.unicodeMode;
639 this._nFlag = mode.nFlag;
640 this._unicodeSetsMode = mode.unicodeSetsMode;
641 this.reset(source, start, end);
642 this.consumePattern();
643 if (!this._nFlag &&
644 this.ecmaVersion >= 2018 &&
645 !this._groupSpecifiers.isEmpty()) {
646 this._nFlag = true;
647 this.rewind(start);
648 this.consumePattern();
649 }
650 }
651 validateFlagsInternal(source, start, end) {
652 const existingFlags = new Set();
653 let global = false;
654 let ignoreCase = false;
655 let multiline = false;
656 let sticky = false;
657 let unicode = false;
658 let dotAll = false;
659 let hasIndices = false;
660 let unicodeSets = false;
661 for (let i = start; i < end; ++i) {
662 const flag = source.charCodeAt(i);
663 if (existingFlags.has(flag)) {
664 this.raise(`Duplicated flag '${source[i]}'`, { index: start });
665 }
666 existingFlags.add(flag);
667 if (flag === LATIN_SMALL_LETTER_G) {
668 global = true;
669 }
670 else if (flag === LATIN_SMALL_LETTER_I) {
671 ignoreCase = true;
672 }
673 else if (flag === LATIN_SMALL_LETTER_M) {
674 multiline = true;
675 }
676 else if (flag === LATIN_SMALL_LETTER_U &&
677 this.ecmaVersion >= 2015) {
678 unicode = true;
679 }
680 else if (flag === LATIN_SMALL_LETTER_Y &&
681 this.ecmaVersion >= 2015) {
682 sticky = true;
683 }
684 else if (flag === LATIN_SMALL_LETTER_S &&
685 this.ecmaVersion >= 2018) {
686 dotAll = true;
687 }
688 else if (flag === LATIN_SMALL_LETTER_D &&
689 this.ecmaVersion >= 2022) {
690 hasIndices = true;
691 }
692 else if (flag === LATIN_SMALL_LETTER_V &&
693 this.ecmaVersion >= 2024) {
694 unicodeSets = true;
695 }
696 else {
697 this.raise(`Invalid flag '${source[i]}'`, { index: start });
698 }
699 }
700 this.onRegExpFlags(start, end, {
701 global,
702 ignoreCase,
703 multiline,
704 unicode,
705 sticky,
706 dotAll,
707 hasIndices,
708 unicodeSets,
709 });
710 }
711 _parseFlagsOptionToMode(uFlagOrFlags, sourceEnd) {
712 let unicode = false;
713 let unicodeSets = false;
714 if (uFlagOrFlags && this.ecmaVersion >= 2015) {
715 if (typeof uFlagOrFlags === "object") {
716 unicode = Boolean(uFlagOrFlags.unicode);
717 if (this.ecmaVersion >= 2024) {
718 unicodeSets = Boolean(uFlagOrFlags.unicodeSets);
719 }
720 }
721 else {
722 unicode = uFlagOrFlags;
723 }
724 }
725 if (unicode && unicodeSets) {
726 this.raise("Invalid regular expression flags", {
727 index: sourceEnd + 1,
728 unicode,
729 unicodeSets,
730 });
731 }
732 const unicodeMode = unicode || unicodeSets;
733 const nFlag = (unicode && this.ecmaVersion >= 2018) ||
734 unicodeSets ||
735 Boolean(this._options.strict && this.ecmaVersion >= 2023);
736 const unicodeSetsMode = unicodeSets;
737 return { unicodeMode, nFlag, unicodeSetsMode };
738 }
739 get strict() {
740 return Boolean(this._options.strict) || this._unicodeMode;
741 }
742 get ecmaVersion() {
743 var _a;
744 return (_a = this._options.ecmaVersion) !== null && _a !== void 0 ? _a : latestEcmaVersion;
745 }
746 onLiteralEnter(start) {
747 if (this._options.onLiteralEnter) {
748 this._options.onLiteralEnter(start);
749 }
750 }
751 onLiteralLeave(start, end) {
752 if (this._options.onLiteralLeave) {
753 this._options.onLiteralLeave(start, end);
754 }
755 }
756 onRegExpFlags(start, end, flags) {
757 if (this._options.onRegExpFlags) {
758 this._options.onRegExpFlags(start, end, flags);
759 }
760 if (this._options.onFlags) {
761 this._options.onFlags(start, end, flags.global, flags.ignoreCase, flags.multiline, flags.unicode, flags.sticky, flags.dotAll, flags.hasIndices);
762 }
763 }
764 onPatternEnter(start) {
765 if (this._options.onPatternEnter) {
766 this._options.onPatternEnter(start);
767 }
768 }
769 onPatternLeave(start, end) {
770 if (this._options.onPatternLeave) {
771 this._options.onPatternLeave(start, end);
772 }
773 }
774 onDisjunctionEnter(start) {
775 if (this._options.onDisjunctionEnter) {
776 this._options.onDisjunctionEnter(start);
777 }
778 }
779 onDisjunctionLeave(start, end) {
780 if (this._options.onDisjunctionLeave) {
781 this._options.onDisjunctionLeave(start, end);
782 }
783 }
784 onAlternativeEnter(start, index) {
785 if (this._options.onAlternativeEnter) {
786 this._options.onAlternativeEnter(start, index);
787 }
788 }
789 onAlternativeLeave(start, end, index) {
790 if (this._options.onAlternativeLeave) {
791 this._options.onAlternativeLeave(start, end, index);
792 }
793 }
794 onGroupEnter(start) {
795 if (this._options.onGroupEnter) {
796 this._options.onGroupEnter(start);
797 }
798 }
799 onGroupLeave(start, end) {
800 if (this._options.onGroupLeave) {
801 this._options.onGroupLeave(start, end);
802 }
803 }
804 onCapturingGroupEnter(start, name) {
805 if (this._options.onCapturingGroupEnter) {
806 this._options.onCapturingGroupEnter(start, name);
807 }
808 }
809 onCapturingGroupLeave(start, end, name) {
810 if (this._options.onCapturingGroupLeave) {
811 this._options.onCapturingGroupLeave(start, end, name);
812 }
813 }
814 onQuantifier(start, end, min, max, greedy) {
815 if (this._options.onQuantifier) {
816 this._options.onQuantifier(start, end, min, max, greedy);
817 }
818 }
819 onLookaroundAssertionEnter(start, kind, negate) {
820 if (this._options.onLookaroundAssertionEnter) {
821 this._options.onLookaroundAssertionEnter(start, kind, negate);
822 }
823 }
824 onLookaroundAssertionLeave(start, end, kind, negate) {
825 if (this._options.onLookaroundAssertionLeave) {
826 this._options.onLookaroundAssertionLeave(start, end, kind, negate);
827 }
828 }
829 onEdgeAssertion(start, end, kind) {
830 if (this._options.onEdgeAssertion) {
831 this._options.onEdgeAssertion(start, end, kind);
832 }
833 }
834 onWordBoundaryAssertion(start, end, kind, negate) {
835 if (this._options.onWordBoundaryAssertion) {
836 this._options.onWordBoundaryAssertion(start, end, kind, negate);
837 }
838 }
839 onAnyCharacterSet(start, end, kind) {
840 if (this._options.onAnyCharacterSet) {
841 this._options.onAnyCharacterSet(start, end, kind);
842 }
843 }
844 onEscapeCharacterSet(start, end, kind, negate) {
845 if (this._options.onEscapeCharacterSet) {
846 this._options.onEscapeCharacterSet(start, end, kind, negate);
847 }
848 }
849 onUnicodePropertyCharacterSet(start, end, kind, key, value, negate, strings) {
850 if (this._options.onUnicodePropertyCharacterSet) {
851 this._options.onUnicodePropertyCharacterSet(start, end, kind, key, value, negate, strings);
852 }
853 }
854 onCharacter(start, end, value) {
855 if (this._options.onCharacter) {
856 this._options.onCharacter(start, end, value);
857 }
858 }
859 onBackreference(start, end, ref) {
860 if (this._options.onBackreference) {
861 this._options.onBackreference(start, end, ref);
862 }
863 }
864 onCharacterClassEnter(start, negate, unicodeSets) {
865 if (this._options.onCharacterClassEnter) {
866 this._options.onCharacterClassEnter(start, negate, unicodeSets);
867 }
868 }
869 onCharacterClassLeave(start, end, negate) {
870 if (this._options.onCharacterClassLeave) {
871 this._options.onCharacterClassLeave(start, end, negate);
872 }
873 }
874 onCharacterClassRange(start, end, min, max) {
875 if (this._options.onCharacterClassRange) {
876 this._options.onCharacterClassRange(start, end, min, max);
877 }
878 }
879 onClassIntersection(start, end) {
880 if (this._options.onClassIntersection) {
881 this._options.onClassIntersection(start, end);
882 }
883 }
884 onClassSubtraction(start, end) {
885 if (this._options.onClassSubtraction) {
886 this._options.onClassSubtraction(start, end);
887 }
888 }
889 onClassStringDisjunctionEnter(start) {
890 if (this._options.onClassStringDisjunctionEnter) {
891 this._options.onClassStringDisjunctionEnter(start);
892 }
893 }
894 onClassStringDisjunctionLeave(start, end) {
895 if (this._options.onClassStringDisjunctionLeave) {
896 this._options.onClassStringDisjunctionLeave(start, end);
897 }
898 }
899 onStringAlternativeEnter(start, index) {
900 if (this._options.onStringAlternativeEnter) {
901 this._options.onStringAlternativeEnter(start, index);
902 }
903 }
904 onStringAlternativeLeave(start, end, index) {
905 if (this._options.onStringAlternativeLeave) {
906 this._options.onStringAlternativeLeave(start, end, index);
907 }
908 }
909 get index() {
910 return this._reader.index;
911 }
912 get currentCodePoint() {
913 return this._reader.currentCodePoint;
914 }
915 get nextCodePoint() {
916 return this._reader.nextCodePoint;
917 }
918 get nextCodePoint2() {
919 return this._reader.nextCodePoint2;
920 }
921 get nextCodePoint3() {
922 return this._reader.nextCodePoint3;
923 }
924 reset(source, start, end) {
925 this._reader.reset(source, start, end, this._unicodeMode);
926 }
927 rewind(index) {
928 this._reader.rewind(index);
929 }
930 advance() {
931 this._reader.advance();
932 }
933 eat(cp) {
934 return this._reader.eat(cp);
935 }
936 eat2(cp1, cp2) {
937 return this._reader.eat2(cp1, cp2);
938 }
939 eat3(cp1, cp2, cp3) {
940 return this._reader.eat3(cp1, cp2, cp3);
941 }
942 raise(message, context) {
943 var _a, _b, _c;
944 throw newRegExpSyntaxError(this._srcCtx, {
945 unicode: (_a = context === null || context === void 0 ? void 0 : context.unicode) !== null && _a !== void 0 ? _a : (this._unicodeMode && !this._unicodeSetsMode),
946 unicodeSets: (_b = context === null || context === void 0 ? void 0 : context.unicodeSets) !== null && _b !== void 0 ? _b : this._unicodeSetsMode,
947 }, (_c = context === null || context === void 0 ? void 0 : context.index) !== null && _c !== void 0 ? _c : this.index, message);
948 }
949 eatRegExpBody() {
950 const start = this.index;
951 let inClass = false;
952 let escaped = false;
953 for (;;) {
954 const cp = this.currentCodePoint;
955 if (cp === -1 || isLineTerminator(cp)) {
956 const kind = inClass ? "character class" : "regular expression";
957 this.raise(`Unterminated ${kind}`);
958 }
959 if (escaped) {
960 escaped = false;
961 }
962 else if (cp === REVERSE_SOLIDUS) {
963 escaped = true;
964 }
965 else if (cp === LEFT_SQUARE_BRACKET) {
966 inClass = true;
967 }
968 else if (cp === RIGHT_SQUARE_BRACKET) {
969 inClass = false;
970 }
971 else if ((cp === SOLIDUS && !inClass) ||
972 (cp === ASTERISK && this.index === start)) {
973 break;
974 }
975 this.advance();
976 }
977 return this.index !== start;
978 }
979 consumePattern() {
980 const start = this.index;
981 this._numCapturingParens = this.countCapturingParens();
982 this._groupSpecifiers.clear();
983 this._backreferenceNames.clear();
984 this.onPatternEnter(start);
985 this.consumeDisjunction();
986 const cp = this.currentCodePoint;
987 if (this.currentCodePoint !== -1) {
988 if (cp === RIGHT_PARENTHESIS) {
989 this.raise("Unmatched ')'");
990 }
991 if (cp === REVERSE_SOLIDUS) {
992 this.raise("\\ at end of pattern");
993 }
994 if (cp === RIGHT_SQUARE_BRACKET || cp === RIGHT_CURLY_BRACKET) {
995 this.raise("Lone quantifier brackets");
996 }
997 const c = String.fromCodePoint(cp);
998 this.raise(`Unexpected character '${c}'`);
999 }
1000 for (const name of this._backreferenceNames) {
1001 if (!this._groupSpecifiers.hasInPattern(name)) {
1002 this.raise("Invalid named capture referenced");
1003 }
1004 }
1005 this.onPatternLeave(start, this.index);
1006 }
1007 countCapturingParens() {
1008 const start = this.index;
1009 let inClass = false;
1010 let escaped = false;
1011 let count = 0;
1012 let cp = 0;
1013 while ((cp = this.currentCodePoint) !== -1) {
1014 if (escaped) {
1015 escaped = false;
1016 }
1017 else if (cp === REVERSE_SOLIDUS) {
1018 escaped = true;
1019 }
1020 else if (cp === LEFT_SQUARE_BRACKET) {
1021 inClass = true;
1022 }
1023 else if (cp === RIGHT_SQUARE_BRACKET) {
1024 inClass = false;
1025 }
1026 else if (cp === LEFT_PARENTHESIS &&
1027 !inClass &&
1028 (this.nextCodePoint !== QUESTION_MARK ||
1029 (this.nextCodePoint2 === LESS_THAN_SIGN &&
1030 this.nextCodePoint3 !== EQUALS_SIGN &&
1031 this.nextCodePoint3 !== EXCLAMATION_MARK))) {
1032 count += 1;
1033 }
1034 this.advance();
1035 }
1036 this.rewind(start);
1037 return count;
1038 }
1039 consumeDisjunction() {
1040 const start = this.index;
1041 let i = 0;
1042 this._groupSpecifiers.enterDisjunction();
1043 this.onDisjunctionEnter(start);
1044 do {
1045 this.consumeAlternative(i++);
1046 } while (this.eat(VERTICAL_LINE));
1047 if (this.consumeQuantifier(true)) {
1048 this.raise("Nothing to repeat");
1049 }
1050 if (this.eat(LEFT_CURLY_BRACKET)) {
1051 this.raise("Lone quantifier brackets");
1052 }
1053 this.onDisjunctionLeave(start, this.index);
1054 this._groupSpecifiers.leaveDisjunction();
1055 }
1056 consumeAlternative(i) {
1057 const start = this.index;
1058 this._groupSpecifiers.enterAlternative(i);
1059 this.onAlternativeEnter(start, i);
1060 while (this.currentCodePoint !== -1 && this.consumeTerm()) {
1061 }
1062 this.onAlternativeLeave(start, this.index, i);
1063 }
1064 consumeTerm() {
1065 if (this._unicodeMode || this.strict) {
1066 return (this.consumeAssertion() ||
1067 (this.consumeAtom() && this.consumeOptionalQuantifier()));
1068 }
1069 return ((this.consumeAssertion() &&
1070 (!this._lastAssertionIsQuantifiable ||
1071 this.consumeOptionalQuantifier())) ||
1072 (this.consumeExtendedAtom() && this.consumeOptionalQuantifier()));
1073 }
1074 consumeOptionalQuantifier() {
1075 this.consumeQuantifier();
1076 return true;
1077 }
1078 consumeAssertion() {
1079 const start = this.index;
1080 this._lastAssertionIsQuantifiable = false;
1081 if (this.eat(CIRCUMFLEX_ACCENT)) {
1082 this.onEdgeAssertion(start, this.index, "start");
1083 return true;
1084 }
1085 if (this.eat(DOLLAR_SIGN)) {
1086 this.onEdgeAssertion(start, this.index, "end");
1087 return true;
1088 }
1089 if (this.eat2(REVERSE_SOLIDUS, LATIN_CAPITAL_LETTER_B)) {
1090 this.onWordBoundaryAssertion(start, this.index, "word", true);
1091 return true;
1092 }
1093 if (this.eat2(REVERSE_SOLIDUS, LATIN_SMALL_LETTER_B)) {
1094 this.onWordBoundaryAssertion(start, this.index, "word", false);
1095 return true;
1096 }
1097 if (this.eat2(LEFT_PARENTHESIS, QUESTION_MARK)) {
1098 const lookbehind = this.ecmaVersion >= 2018 && this.eat(LESS_THAN_SIGN);
1099 let negate = false;
1100 if (this.eat(EQUALS_SIGN) ||
1101 (negate = this.eat(EXCLAMATION_MARK))) {
1102 const kind = lookbehind ? "lookbehind" : "lookahead";
1103 this.onLookaroundAssertionEnter(start, kind, negate);
1104 this.consumeDisjunction();
1105 if (!this.eat(RIGHT_PARENTHESIS)) {
1106 this.raise("Unterminated group");
1107 }
1108 this._lastAssertionIsQuantifiable = !lookbehind && !this.strict;
1109 this.onLookaroundAssertionLeave(start, this.index, kind, negate);
1110 return true;
1111 }
1112 this.rewind(start);
1113 }
1114 return false;
1115 }
1116 consumeQuantifier(noConsume = false) {
1117 const start = this.index;
1118 let min = 0;
1119 let max = 0;
1120 let greedy = false;
1121 if (this.eat(ASTERISK)) {
1122 min = 0;
1123 max = Number.POSITIVE_INFINITY;
1124 }
1125 else if (this.eat(PLUS_SIGN)) {
1126 min = 1;
1127 max = Number.POSITIVE_INFINITY;
1128 }
1129 else if (this.eat(QUESTION_MARK)) {
1130 min = 0;
1131 max = 1;
1132 }
1133 else if (this.eatBracedQuantifier(noConsume)) {
1134 ({ min, max } = this._lastRange);
1135 }
1136 else {
1137 return false;
1138 }
1139 greedy = !this.eat(QUESTION_MARK);
1140 if (!noConsume) {
1141 this.onQuantifier(start, this.index, min, max, greedy);
1142 }
1143 return true;
1144 }
1145 eatBracedQuantifier(noError) {
1146 const start = this.index;
1147 if (this.eat(LEFT_CURLY_BRACKET)) {
1148 if (this.eatDecimalDigits()) {
1149 const min = this._lastIntValue;
1150 let max = min;
1151 if (this.eat(COMMA)) {
1152 max = this.eatDecimalDigits()
1153 ? this._lastIntValue
1154 : Number.POSITIVE_INFINITY;
1155 }
1156 if (this.eat(RIGHT_CURLY_BRACKET)) {
1157 if (!noError && max < min) {
1158 this.raise("numbers out of order in {} quantifier");
1159 }
1160 this._lastRange = { min, max };
1161 return true;
1162 }
1163 }
1164 if (!noError && (this._unicodeMode || this.strict)) {
1165 this.raise("Incomplete quantifier");
1166 }
1167 this.rewind(start);
1168 }
1169 return false;
1170 }
1171 consumeAtom() {
1172 return (this.consumePatternCharacter() ||
1173 this.consumeDot() ||
1174 this.consumeReverseSolidusAtomEscape() ||
1175 Boolean(this.consumeCharacterClass()) ||
1176 this.consumeUncapturingGroup() ||
1177 this.consumeCapturingGroup());
1178 }
1179 consumeDot() {
1180 if (this.eat(FULL_STOP)) {
1181 this.onAnyCharacterSet(this.index - 1, this.index, "any");
1182 return true;
1183 }
1184 return false;
1185 }
1186 consumeReverseSolidusAtomEscape() {
1187 const start = this.index;
1188 if (this.eat(REVERSE_SOLIDUS)) {
1189 if (this.consumeAtomEscape()) {
1190 return true;
1191 }
1192 this.rewind(start);
1193 }
1194 return false;
1195 }
1196 consumeUncapturingGroup() {
1197 const start = this.index;
1198 if (this.eat3(LEFT_PARENTHESIS, QUESTION_MARK, COLON)) {
1199 this.onGroupEnter(start);
1200 this.consumeDisjunction();
1201 if (!this.eat(RIGHT_PARENTHESIS)) {
1202 this.raise("Unterminated group");
1203 }
1204 this.onGroupLeave(start, this.index);
1205 return true;
1206 }
1207 return false;
1208 }
1209 consumeCapturingGroup() {
1210 const start = this.index;
1211 if (this.eat(LEFT_PARENTHESIS)) {
1212 let name = null;
1213 if (this.ecmaVersion >= 2018) {
1214 if (this.consumeGroupSpecifier()) {
1215 name = this._lastStrValue;
1216 }
1217 }
1218 else if (this.currentCodePoint === QUESTION_MARK) {
1219 this.raise("Invalid group");
1220 }
1221 this.onCapturingGroupEnter(start, name);
1222 this.consumeDisjunction();
1223 if (!this.eat(RIGHT_PARENTHESIS)) {
1224 this.raise("Unterminated group");
1225 }
1226 this.onCapturingGroupLeave(start, this.index, name);
1227 return true;
1228 }
1229 return false;
1230 }
1231 consumeExtendedAtom() {
1232 return (this.consumeDot() ||
1233 this.consumeReverseSolidusAtomEscape() ||
1234 this.consumeReverseSolidusFollowedByC() ||
1235 Boolean(this.consumeCharacterClass()) ||
1236 this.consumeUncapturingGroup() ||
1237 this.consumeCapturingGroup() ||
1238 this.consumeInvalidBracedQuantifier() ||
1239 this.consumeExtendedPatternCharacter());
1240 }
1241 consumeReverseSolidusFollowedByC() {
1242 const start = this.index;
1243 if (this.currentCodePoint === REVERSE_SOLIDUS &&
1244 this.nextCodePoint === LATIN_SMALL_LETTER_C) {
1245 this._lastIntValue = this.currentCodePoint;
1246 this.advance();
1247 this.onCharacter(start, this.index, REVERSE_SOLIDUS);
1248 return true;
1249 }
1250 return false;
1251 }
1252 consumeInvalidBracedQuantifier() {
1253 if (this.eatBracedQuantifier(true)) {
1254 this.raise("Nothing to repeat");
1255 }
1256 return false;
1257 }
1258 consumePatternCharacter() {
1259 const start = this.index;
1260 const cp = this.currentCodePoint;
1261 if (cp !== -1 && !isSyntaxCharacter(cp)) {
1262 this.advance();
1263 this.onCharacter(start, this.index, cp);
1264 return true;
1265 }
1266 return false;
1267 }
1268 consumeExtendedPatternCharacter() {
1269 const start = this.index;
1270 const cp = this.currentCodePoint;
1271 if (cp !== -1 &&
1272 cp !== CIRCUMFLEX_ACCENT &&
1273 cp !== DOLLAR_SIGN &&
1274 cp !== REVERSE_SOLIDUS &&
1275 cp !== FULL_STOP &&
1276 cp !== ASTERISK &&
1277 cp !== PLUS_SIGN &&
1278 cp !== QUESTION_MARK &&
1279 cp !== LEFT_PARENTHESIS &&
1280 cp !== RIGHT_PARENTHESIS &&
1281 cp !== LEFT_SQUARE_BRACKET &&
1282 cp !== VERTICAL_LINE) {
1283 this.advance();
1284 this.onCharacter(start, this.index, cp);
1285 return true;
1286 }
1287 return false;
1288 }
1289 consumeGroupSpecifier() {
1290 if (this.eat(QUESTION_MARK)) {
1291 if (this.eatGroupName()) {
1292 if (!this._groupSpecifiers.hasInScope(this._lastStrValue)) {
1293 this._groupSpecifiers.addToScope(this._lastStrValue);
1294 return true;
1295 }
1296 this.raise("Duplicate capture group name");
1297 }
1298 this.raise("Invalid group");
1299 }
1300 return false;
1301 }
1302 consumeAtomEscape() {
1303 if (this.consumeBackreference() ||
1304 this.consumeCharacterClassEscape() ||
1305 this.consumeCharacterEscape() ||
1306 (this._nFlag && this.consumeKGroupName())) {
1307 return true;
1308 }
1309 if (this.strict || this._unicodeMode) {
1310 this.raise("Invalid escape");
1311 }
1312 return false;
1313 }
1314 consumeBackreference() {
1315 const start = this.index;
1316 if (this.eatDecimalEscape()) {
1317 const n = this._lastIntValue;
1318 if (n <= this._numCapturingParens) {
1319 this.onBackreference(start - 1, this.index, n);
1320 return true;
1321 }
1322 if (this.strict || this._unicodeMode) {
1323 this.raise("Invalid escape");
1324 }
1325 this.rewind(start);
1326 }
1327 return false;
1328 }
1329 consumeCharacterClassEscape() {
1330 var _a;
1331 const start = this.index;
1332 if (this.eat(LATIN_SMALL_LETTER_D)) {
1333 this._lastIntValue = -1;
1334 this.onEscapeCharacterSet(start - 1, this.index, "digit", false);
1335 return {};
1336 }
1337 if (this.eat(LATIN_CAPITAL_LETTER_D)) {
1338 this._lastIntValue = -1;
1339 this.onEscapeCharacterSet(start - 1, this.index, "digit", true);
1340 return {};
1341 }
1342 if (this.eat(LATIN_SMALL_LETTER_S)) {
1343 this._lastIntValue = -1;
1344 this.onEscapeCharacterSet(start - 1, this.index, "space", false);
1345 return {};
1346 }
1347 if (this.eat(LATIN_CAPITAL_LETTER_S)) {
1348 this._lastIntValue = -1;
1349 this.onEscapeCharacterSet(start - 1, this.index, "space", true);
1350 return {};
1351 }
1352 if (this.eat(LATIN_SMALL_LETTER_W)) {
1353 this._lastIntValue = -1;
1354 this.onEscapeCharacterSet(start - 1, this.index, "word", false);
1355 return {};
1356 }
1357 if (this.eat(LATIN_CAPITAL_LETTER_W)) {
1358 this._lastIntValue = -1;
1359 this.onEscapeCharacterSet(start - 1, this.index, "word", true);
1360 return {};
1361 }
1362 let negate = false;
1363 if (this._unicodeMode &&
1364 this.ecmaVersion >= 2018 &&
1365 (this.eat(LATIN_SMALL_LETTER_P) ||
1366 (negate = this.eat(LATIN_CAPITAL_LETTER_P)))) {
1367 this._lastIntValue = -1;
1368 let result = null;
1369 if (this.eat(LEFT_CURLY_BRACKET) &&
1370 (result = this.eatUnicodePropertyValueExpression()) &&
1371 this.eat(RIGHT_CURLY_BRACKET)) {
1372 if (negate && result.strings) {
1373 this.raise("Invalid property name");
1374 }
1375 this.onUnicodePropertyCharacterSet(start - 1, this.index, "property", result.key, result.value, negate, (_a = result.strings) !== null && _a !== void 0 ? _a : false);
1376 return { mayContainStrings: result.strings };
1377 }
1378 this.raise("Invalid property name");
1379 }
1380 return null;
1381 }
1382 consumeCharacterEscape() {
1383 const start = this.index;
1384 if (this.eatControlEscape() ||
1385 this.eatCControlLetter() ||
1386 this.eatZero() ||
1387 this.eatHexEscapeSequence() ||
1388 this.eatRegExpUnicodeEscapeSequence() ||
1389 (!this.strict &&
1390 !this._unicodeMode &&
1391 this.eatLegacyOctalEscapeSequence()) ||
1392 this.eatIdentityEscape()) {
1393 this.onCharacter(start - 1, this.index, this._lastIntValue);
1394 return true;
1395 }
1396 return false;
1397 }
1398 consumeKGroupName() {
1399 const start = this.index;
1400 if (this.eat(LATIN_SMALL_LETTER_K)) {
1401 if (this.eatGroupName()) {
1402 const groupName = this._lastStrValue;
1403 this._backreferenceNames.add(groupName);
1404 this.onBackreference(start - 1, this.index, groupName);
1405 return true;
1406 }
1407 this.raise("Invalid named reference");
1408 }
1409 return false;
1410 }
1411 consumeCharacterClass() {
1412 const start = this.index;
1413 if (this.eat(LEFT_SQUARE_BRACKET)) {
1414 const negate = this.eat(CIRCUMFLEX_ACCENT);
1415 this.onCharacterClassEnter(start, negate, this._unicodeSetsMode);
1416 const result = this.consumeClassContents();
1417 if (!this.eat(RIGHT_SQUARE_BRACKET)) {
1418 if (this.currentCodePoint === -1) {
1419 this.raise("Unterminated character class");
1420 }
1421 this.raise("Invalid character in character class");
1422 }
1423 if (negate && result.mayContainStrings) {
1424 this.raise("Negated character class may contain strings");
1425 }
1426 this.onCharacterClassLeave(start, this.index, negate);
1427 return result;
1428 }
1429 return null;
1430 }
1431 consumeClassContents() {
1432 if (this._unicodeSetsMode) {
1433 if (this.currentCodePoint === RIGHT_SQUARE_BRACKET) {
1434 return {};
1435 }
1436 const result = this.consumeClassSetExpression();
1437 return result;
1438 }
1439 const strict = this.strict || this._unicodeMode;
1440 for (;;) {
1441 const rangeStart = this.index;
1442 if (!this.consumeClassAtom()) {
1443 break;
1444 }
1445 const min = this._lastIntValue;
1446 if (!this.eat(HYPHEN_MINUS)) {
1447 continue;
1448 }
1449 this.onCharacter(this.index - 1, this.index, HYPHEN_MINUS);
1450 if (!this.consumeClassAtom()) {
1451 break;
1452 }
1453 const max = this._lastIntValue;
1454 if (min === -1 || max === -1) {
1455 if (strict) {
1456 this.raise("Invalid character class");
1457 }
1458 continue;
1459 }
1460 if (min > max) {
1461 this.raise("Range out of order in character class");
1462 }
1463 this.onCharacterClassRange(rangeStart, this.index, min, max);
1464 }
1465 return {};
1466 }
1467 consumeClassAtom() {
1468 const start = this.index;
1469 const cp = this.currentCodePoint;
1470 if (cp !== -1 &&
1471 cp !== REVERSE_SOLIDUS &&
1472 cp !== RIGHT_SQUARE_BRACKET) {
1473 this.advance();
1474 this._lastIntValue = cp;
1475 this.onCharacter(start, this.index, this._lastIntValue);
1476 return true;
1477 }
1478 if (this.eat(REVERSE_SOLIDUS)) {
1479 if (this.consumeClassEscape()) {
1480 return true;
1481 }
1482 if (!this.strict &&
1483 this.currentCodePoint === LATIN_SMALL_LETTER_C) {
1484 this._lastIntValue = REVERSE_SOLIDUS;
1485 this.onCharacter(start, this.index, this._lastIntValue);
1486 return true;
1487 }
1488 if (this.strict || this._unicodeMode) {
1489 this.raise("Invalid escape");
1490 }
1491 this.rewind(start);
1492 }
1493 return false;
1494 }
1495 consumeClassEscape() {
1496 const start = this.index;
1497 if (this.eat(LATIN_SMALL_LETTER_B)) {
1498 this._lastIntValue = BACKSPACE;
1499 this.onCharacter(start - 1, this.index, this._lastIntValue);
1500 return true;
1501 }
1502 if (this._unicodeMode && this.eat(HYPHEN_MINUS)) {
1503 this._lastIntValue = HYPHEN_MINUS;
1504 this.onCharacter(start - 1, this.index, this._lastIntValue);
1505 return true;
1506 }
1507 let cp = 0;
1508 if (!this.strict &&
1509 !this._unicodeMode &&
1510 this.currentCodePoint === LATIN_SMALL_LETTER_C &&
1511 (isDecimalDigit((cp = this.nextCodePoint)) || cp === LOW_LINE)) {
1512 this.advance();
1513 this.advance();
1514 this._lastIntValue = cp % 0x20;
1515 this.onCharacter(start - 1, this.index, this._lastIntValue);
1516 return true;
1517 }
1518 return (Boolean(this.consumeCharacterClassEscape()) ||
1519 this.consumeCharacterEscape());
1520 }
1521 consumeClassSetExpression() {
1522 const start = this.index;
1523 let mayContainStrings = false;
1524 let result = null;
1525 if (this.consumeClassSetCharacter()) {
1526 if (this.consumeClassSetRangeFromOperator(start)) {
1527 this.consumeClassUnionRight({});
1528 return {};
1529 }
1530 mayContainStrings = false;
1531 }
1532 else if ((result = this.consumeClassSetOperand())) {
1533 mayContainStrings = result.mayContainStrings;
1534 }
1535 else {
1536 const cp = this.currentCodePoint;
1537 if (cp === REVERSE_SOLIDUS) {
1538 this.advance();
1539 this.raise("Invalid escape");
1540 }
1541 if (cp === this.nextCodePoint &&
1542 isClassSetReservedDoublePunctuatorCharacter(cp)) {
1543 this.raise("Invalid set operation in character class");
1544 }
1545 this.raise("Invalid character in character class");
1546 }
1547 if (this.eat2(AMPERSAND, AMPERSAND)) {
1548 while (this.currentCodePoint !== AMPERSAND &&
1549 (result = this.consumeClassSetOperand())) {
1550 this.onClassIntersection(start, this.index);
1551 if (!result.mayContainStrings) {
1552 mayContainStrings = false;
1553 }
1554 if (this.eat2(AMPERSAND, AMPERSAND)) {
1555 continue;
1556 }
1557 return { mayContainStrings };
1558 }
1559 this.raise("Invalid character in character class");
1560 }
1561 if (this.eat2(HYPHEN_MINUS, HYPHEN_MINUS)) {
1562 while (this.consumeClassSetOperand()) {
1563 this.onClassSubtraction(start, this.index);
1564 if (this.eat2(HYPHEN_MINUS, HYPHEN_MINUS)) {
1565 continue;
1566 }
1567 return { mayContainStrings };
1568 }
1569 this.raise("Invalid character in character class");
1570 }
1571 return this.consumeClassUnionRight({ mayContainStrings });
1572 }
1573 consumeClassUnionRight(leftResult) {
1574 let mayContainStrings = leftResult.mayContainStrings;
1575 for (;;) {
1576 const start = this.index;
1577 if (this.consumeClassSetCharacter()) {
1578 this.consumeClassSetRangeFromOperator(start);
1579 continue;
1580 }
1581 const result = this.consumeClassSetOperand();
1582 if (result) {
1583 if (result.mayContainStrings) {
1584 mayContainStrings = true;
1585 }
1586 continue;
1587 }
1588 break;
1589 }
1590 return { mayContainStrings };
1591 }
1592 consumeClassSetRangeFromOperator(start) {
1593 const currentStart = this.index;
1594 const min = this._lastIntValue;
1595 if (this.eat(HYPHEN_MINUS)) {
1596 if (this.consumeClassSetCharacter()) {
1597 const max = this._lastIntValue;
1598 if (min === -1 || max === -1) {
1599 this.raise("Invalid character class");
1600 }
1601 if (min > max) {
1602 this.raise("Range out of order in character class");
1603 }
1604 this.onCharacterClassRange(start, this.index, min, max);
1605 return true;
1606 }
1607 this.rewind(currentStart);
1608 }
1609 return false;
1610 }
1611 consumeClassSetOperand() {
1612 let result = null;
1613 if ((result = this.consumeNestedClass())) {
1614 return result;
1615 }
1616 if ((result = this.consumeClassStringDisjunction())) {
1617 return result;
1618 }
1619 if (this.consumeClassSetCharacter()) {
1620 return {};
1621 }
1622 return null;
1623 }
1624 consumeNestedClass() {
1625 const start = this.index;
1626 if (this.eat(LEFT_SQUARE_BRACKET)) {
1627 const negate = this.eat(CIRCUMFLEX_ACCENT);
1628 this.onCharacterClassEnter(start, negate, true);
1629 const result = this.consumeClassContents();
1630 if (!this.eat(RIGHT_SQUARE_BRACKET)) {
1631 this.raise("Unterminated character class");
1632 }
1633 if (negate && result.mayContainStrings) {
1634 this.raise("Negated character class may contain strings");
1635 }
1636 this.onCharacterClassLeave(start, this.index, negate);
1637 return result;
1638 }
1639 if (this.eat(REVERSE_SOLIDUS)) {
1640 const result = this.consumeCharacterClassEscape();
1641 if (result) {
1642 return result;
1643 }
1644 this.rewind(start);
1645 }
1646 return null;
1647 }
1648 consumeClassStringDisjunction() {
1649 const start = this.index;
1650 if (this.eat3(REVERSE_SOLIDUS, LATIN_SMALL_LETTER_Q, LEFT_CURLY_BRACKET)) {
1651 this.onClassStringDisjunctionEnter(start);
1652 let i = 0;
1653 let mayContainStrings = false;
1654 do {
1655 if (this.consumeClassString(i++).mayContainStrings) {
1656 mayContainStrings = true;
1657 }
1658 } while (this.eat(VERTICAL_LINE));
1659 if (this.eat(RIGHT_CURLY_BRACKET)) {
1660 this.onClassStringDisjunctionLeave(start, this.index);
1661 return { mayContainStrings };
1662 }
1663 this.raise("Unterminated class string disjunction");
1664 }
1665 return null;
1666 }
1667 consumeClassString(i) {
1668 const start = this.index;
1669 let count = 0;
1670 this.onStringAlternativeEnter(start, i);
1671 while (this.currentCodePoint !== -1 &&
1672 this.consumeClassSetCharacter()) {
1673 count++;
1674 }
1675 this.onStringAlternativeLeave(start, this.index, i);
1676 return { mayContainStrings: count !== 1 };
1677 }
1678 consumeClassSetCharacter() {
1679 const start = this.index;
1680 const cp = this.currentCodePoint;
1681 if (cp !== this.nextCodePoint ||
1682 !isClassSetReservedDoublePunctuatorCharacter(cp)) {
1683 if (cp !== -1 && !isClassSetSyntaxCharacter(cp)) {
1684 this._lastIntValue = cp;
1685 this.advance();
1686 this.onCharacter(start, this.index, this._lastIntValue);
1687 return true;
1688 }
1689 }
1690 if (this.eat(REVERSE_SOLIDUS)) {
1691 if (this.consumeCharacterEscape()) {
1692 return true;
1693 }
1694 if (isClassSetReservedPunctuator(this.currentCodePoint)) {
1695 this._lastIntValue = this.currentCodePoint;
1696 this.advance();
1697 this.onCharacter(start, this.index, this._lastIntValue);
1698 return true;
1699 }
1700 if (this.eat(LATIN_SMALL_LETTER_B)) {
1701 this._lastIntValue = BACKSPACE;
1702 this.onCharacter(start, this.index, this._lastIntValue);
1703 return true;
1704 }
1705 this.rewind(start);
1706 }
1707 return false;
1708 }
1709 eatGroupName() {
1710 if (this.eat(LESS_THAN_SIGN)) {
1711 if (this.eatRegExpIdentifierName() && this.eat(GREATER_THAN_SIGN)) {
1712 return true;
1713 }
1714 this.raise("Invalid capture group name");
1715 }
1716 return false;
1717 }
1718 eatRegExpIdentifierName() {
1719 if (this.eatRegExpIdentifierStart()) {
1720 this._lastStrValue = String.fromCodePoint(this._lastIntValue);
1721 while (this.eatRegExpIdentifierPart()) {
1722 this._lastStrValue += String.fromCodePoint(this._lastIntValue);
1723 }
1724 return true;
1725 }
1726 return false;
1727 }
1728 eatRegExpIdentifierStart() {
1729 const start = this.index;
1730 const forceUFlag = !this._unicodeMode && this.ecmaVersion >= 2020;
1731 let cp = this.currentCodePoint;
1732 this.advance();
1733 if (cp === REVERSE_SOLIDUS &&
1734 this.eatRegExpUnicodeEscapeSequence(forceUFlag)) {
1735 cp = this._lastIntValue;
1736 }
1737 else if (forceUFlag &&
1738 isLeadSurrogate(cp) &&
1739 isTrailSurrogate(this.currentCodePoint)) {
1740 cp = combineSurrogatePair(cp, this.currentCodePoint);
1741 this.advance();
1742 }
1743 if (isIdentifierStartChar(cp)) {
1744 this._lastIntValue = cp;
1745 return true;
1746 }
1747 if (this.index !== start) {
1748 this.rewind(start);
1749 }
1750 return false;
1751 }
1752 eatRegExpIdentifierPart() {
1753 const start = this.index;
1754 const forceUFlag = !this._unicodeMode && this.ecmaVersion >= 2020;
1755 let cp = this.currentCodePoint;
1756 this.advance();
1757 if (cp === REVERSE_SOLIDUS &&
1758 this.eatRegExpUnicodeEscapeSequence(forceUFlag)) {
1759 cp = this._lastIntValue;
1760 }
1761 else if (forceUFlag &&
1762 isLeadSurrogate(cp) &&
1763 isTrailSurrogate(this.currentCodePoint)) {
1764 cp = combineSurrogatePair(cp, this.currentCodePoint);
1765 this.advance();
1766 }
1767 if (isIdentifierPartChar(cp)) {
1768 this._lastIntValue = cp;
1769 return true;
1770 }
1771 if (this.index !== start) {
1772 this.rewind(start);
1773 }
1774 return false;
1775 }
1776 eatCControlLetter() {
1777 const start = this.index;
1778 if (this.eat(LATIN_SMALL_LETTER_C)) {
1779 if (this.eatControlLetter()) {
1780 return true;
1781 }
1782 this.rewind(start);
1783 }
1784 return false;
1785 }
1786 eatZero() {
1787 if (this.currentCodePoint === DIGIT_ZERO &&
1788 !isDecimalDigit(this.nextCodePoint)) {
1789 this._lastIntValue = 0;
1790 this.advance();
1791 return true;
1792 }
1793 return false;
1794 }
1795 eatControlEscape() {
1796 if (this.eat(LATIN_SMALL_LETTER_F)) {
1797 this._lastIntValue = FORM_FEED;
1798 return true;
1799 }
1800 if (this.eat(LATIN_SMALL_LETTER_N)) {
1801 this._lastIntValue = LINE_FEED;
1802 return true;
1803 }
1804 if (this.eat(LATIN_SMALL_LETTER_R)) {
1805 this._lastIntValue = CARRIAGE_RETURN;
1806 return true;
1807 }
1808 if (this.eat(LATIN_SMALL_LETTER_T)) {
1809 this._lastIntValue = CHARACTER_TABULATION;
1810 return true;
1811 }
1812 if (this.eat(LATIN_SMALL_LETTER_V)) {
1813 this._lastIntValue = LINE_TABULATION;
1814 return true;
1815 }
1816 return false;
1817 }
1818 eatControlLetter() {
1819 const cp = this.currentCodePoint;
1820 if (isLatinLetter(cp)) {
1821 this.advance();
1822 this._lastIntValue = cp % 0x20;
1823 return true;
1824 }
1825 return false;
1826 }
1827 eatRegExpUnicodeEscapeSequence(forceUFlag = false) {
1828 const start = this.index;
1829 const uFlag = forceUFlag || this._unicodeMode;
1830 if (this.eat(LATIN_SMALL_LETTER_U)) {
1831 if ((uFlag && this.eatRegExpUnicodeSurrogatePairEscape()) ||
1832 this.eatFixedHexDigits(4) ||
1833 (uFlag && this.eatRegExpUnicodeCodePointEscape())) {
1834 return true;
1835 }
1836 if (this.strict || uFlag) {
1837 this.raise("Invalid unicode escape");
1838 }
1839 this.rewind(start);
1840 }
1841 return false;
1842 }
1843 eatRegExpUnicodeSurrogatePairEscape() {
1844 const start = this.index;
1845 if (this.eatFixedHexDigits(4)) {
1846 const lead = this._lastIntValue;
1847 if (isLeadSurrogate(lead) &&
1848 this.eat(REVERSE_SOLIDUS) &&
1849 this.eat(LATIN_SMALL_LETTER_U) &&
1850 this.eatFixedHexDigits(4)) {
1851 const trail = this._lastIntValue;
1852 if (isTrailSurrogate(trail)) {
1853 this._lastIntValue = combineSurrogatePair(lead, trail);
1854 return true;
1855 }
1856 }
1857 this.rewind(start);
1858 }
1859 return false;
1860 }
1861 eatRegExpUnicodeCodePointEscape() {
1862 const start = this.index;
1863 if (this.eat(LEFT_CURLY_BRACKET) &&
1864 this.eatHexDigits() &&
1865 this.eat(RIGHT_CURLY_BRACKET) &&
1866 isValidUnicode(this._lastIntValue)) {
1867 return true;
1868 }
1869 this.rewind(start);
1870 return false;
1871 }
1872 eatIdentityEscape() {
1873 const cp = this.currentCodePoint;
1874 if (this.isValidIdentityEscape(cp)) {
1875 this._lastIntValue = cp;
1876 this.advance();
1877 return true;
1878 }
1879 return false;
1880 }
1881 isValidIdentityEscape(cp) {
1882 if (cp === -1) {
1883 return false;
1884 }
1885 if (this._unicodeMode) {
1886 return isSyntaxCharacter(cp) || cp === SOLIDUS;
1887 }
1888 if (this.strict) {
1889 return !isIdContinue(cp);
1890 }
1891 if (this._nFlag) {
1892 return !(cp === LATIN_SMALL_LETTER_C || cp === LATIN_SMALL_LETTER_K);
1893 }
1894 return cp !== LATIN_SMALL_LETTER_C;
1895 }
1896 eatDecimalEscape() {
1897 this._lastIntValue = 0;
1898 let cp = this.currentCodePoint;
1899 if (cp >= DIGIT_ONE && cp <= DIGIT_NINE) {
1900 do {
1901 this._lastIntValue = 10 * this._lastIntValue + (cp - DIGIT_ZERO);
1902 this.advance();
1903 } while ((cp = this.currentCodePoint) >= DIGIT_ZERO &&
1904 cp <= DIGIT_NINE);
1905 return true;
1906 }
1907 return false;
1908 }
1909 eatUnicodePropertyValueExpression() {
1910 const start = this.index;
1911 if (this.eatUnicodePropertyName() && this.eat(EQUALS_SIGN)) {
1912 const key = this._lastStrValue;
1913 if (this.eatUnicodePropertyValue()) {
1914 const value = this._lastStrValue;
1915 if (isValidUnicodeProperty(this.ecmaVersion, key, value)) {
1916 return {
1917 key,
1918 value: value || null,
1919 };
1920 }
1921 this.raise("Invalid property name");
1922 }
1923 }
1924 this.rewind(start);
1925 if (this.eatLoneUnicodePropertyNameOrValue()) {
1926 const nameOrValue = this._lastStrValue;
1927 if (isValidUnicodeProperty(this.ecmaVersion, "General_Category", nameOrValue)) {
1928 return {
1929 key: "General_Category",
1930 value: nameOrValue || null,
1931 };
1932 }
1933 if (isValidLoneUnicodeProperty(this.ecmaVersion, nameOrValue)) {
1934 return {
1935 key: nameOrValue,
1936 value: null,
1937 };
1938 }
1939 if (this._unicodeSetsMode &&
1940 isValidLoneUnicodePropertyOfString(this.ecmaVersion, nameOrValue)) {
1941 return {
1942 key: nameOrValue,
1943 value: null,
1944 strings: true,
1945 };
1946 }
1947 this.raise("Invalid property name");
1948 }
1949 return null;
1950 }
1951 eatUnicodePropertyName() {
1952 this._lastStrValue = "";
1953 while (isUnicodePropertyNameCharacter(this.currentCodePoint)) {
1954 this._lastStrValue += String.fromCodePoint(this.currentCodePoint);
1955 this.advance();
1956 }
1957 return this._lastStrValue !== "";
1958 }
1959 eatUnicodePropertyValue() {
1960 this._lastStrValue = "";
1961 while (isUnicodePropertyValueCharacter(this.currentCodePoint)) {
1962 this._lastStrValue += String.fromCodePoint(this.currentCodePoint);
1963 this.advance();
1964 }
1965 return this._lastStrValue !== "";
1966 }
1967 eatLoneUnicodePropertyNameOrValue() {
1968 return this.eatUnicodePropertyValue();
1969 }
1970 eatHexEscapeSequence() {
1971 const start = this.index;
1972 if (this.eat(LATIN_SMALL_LETTER_X)) {
1973 if (this.eatFixedHexDigits(2)) {
1974 return true;
1975 }
1976 if (this._unicodeMode || this.strict) {
1977 this.raise("Invalid escape");
1978 }
1979 this.rewind(start);
1980 }
1981 return false;
1982 }
1983 eatDecimalDigits() {
1984 const start = this.index;
1985 this._lastIntValue = 0;
1986 while (isDecimalDigit(this.currentCodePoint)) {
1987 this._lastIntValue =
1988 10 * this._lastIntValue + digitToInt(this.currentCodePoint);
1989 this.advance();
1990 }
1991 return this.index !== start;
1992 }
1993 eatHexDigits() {
1994 const start = this.index;
1995 this._lastIntValue = 0;
1996 while (isHexDigit(this.currentCodePoint)) {
1997 this._lastIntValue =
1998 16 * this._lastIntValue + digitToInt(this.currentCodePoint);
1999 this.advance();
2000 }
2001 return this.index !== start;
2002 }
2003 eatLegacyOctalEscapeSequence() {
2004 if (this.eatOctalDigit()) {
2005 const n1 = this._lastIntValue;
2006 if (this.eatOctalDigit()) {
2007 const n2 = this._lastIntValue;
2008 if (n1 <= 3 && this.eatOctalDigit()) {
2009 this._lastIntValue = n1 * 64 + n2 * 8 + this._lastIntValue;
2010 }
2011 else {
2012 this._lastIntValue = n1 * 8 + n2;
2013 }
2014 }
2015 else {
2016 this._lastIntValue = n1;
2017 }
2018 return true;
2019 }
2020 return false;
2021 }
2022 eatOctalDigit() {
2023 const cp = this.currentCodePoint;
2024 if (isOctalDigit(cp)) {
2025 this.advance();
2026 this._lastIntValue = cp - DIGIT_ZERO;
2027 return true;
2028 }
2029 this._lastIntValue = 0;
2030 return false;
2031 }
2032 eatFixedHexDigits(length) {
2033 const start = this.index;
2034 this._lastIntValue = 0;
2035 for (let i = 0; i < length; ++i) {
2036 const cp = this.currentCodePoint;
2037 if (!isHexDigit(cp)) {
2038 this.rewind(start);
2039 return false;
2040 }
2041 this._lastIntValue = 16 * this._lastIntValue + digitToInt(cp);
2042 this.advance();
2043 }
2044 return true;
2045 }
2046}
2047
2048const DUMMY_PATTERN = {};
2049const DUMMY_FLAGS = {};
2050const DUMMY_CAPTURING_GROUP = {};
2051function isClassSetOperand(node) {
2052 return (node.type === "Character" ||
2053 node.type === "CharacterSet" ||
2054 node.type === "CharacterClass" ||
2055 node.type === "ExpressionCharacterClass" ||
2056 node.type === "ClassStringDisjunction");
2057}
2058class RegExpParserState {
2059 constructor(options) {
2060 var _a;
2061 this._node = DUMMY_PATTERN;
2062 this._expressionBufferMap = new Map();
2063 this._flags = DUMMY_FLAGS;
2064 this._backreferences = [];
2065 this._capturingGroups = [];
2066 this.source = "";
2067 this.strict = Boolean(options === null || options === void 0 ? void 0 : options.strict);
2068 this.ecmaVersion = (_a = options === null || options === void 0 ? void 0 : options.ecmaVersion) !== null && _a !== void 0 ? _a : latestEcmaVersion;
2069 }
2070 get pattern() {
2071 if (this._node.type !== "Pattern") {
2072 throw new Error("UnknownError");
2073 }
2074 return this._node;
2075 }
2076 get flags() {
2077 if (this._flags.type !== "Flags") {
2078 throw new Error("UnknownError");
2079 }
2080 return this._flags;
2081 }
2082 onRegExpFlags(start, end, { global, ignoreCase, multiline, unicode, sticky, dotAll, hasIndices, unicodeSets, }) {
2083 this._flags = {
2084 type: "Flags",
2085 parent: null,
2086 start,
2087 end,
2088 raw: this.source.slice(start, end),
2089 global,
2090 ignoreCase,
2091 multiline,
2092 unicode,
2093 sticky,
2094 dotAll,
2095 hasIndices,
2096 unicodeSets,
2097 };
2098 }
2099 onPatternEnter(start) {
2100 this._node = {
2101 type: "Pattern",
2102 parent: null,
2103 start,
2104 end: start,
2105 raw: "",
2106 alternatives: [],
2107 };
2108 this._backreferences.length = 0;
2109 this._capturingGroups.length = 0;
2110 }
2111 onPatternLeave(start, end) {
2112 this._node.end = end;
2113 this._node.raw = this.source.slice(start, end);
2114 for (const reference of this._backreferences) {
2115 const ref = reference.ref;
2116 const groups = typeof ref === "number"
2117 ? [this._capturingGroups[ref - 1]]
2118 : this._capturingGroups.filter((g) => g.name === ref);
2119 if (groups.length === 1) {
2120 const group = groups[0];
2121 reference.ambiguous = false;
2122 reference.resolved = group;
2123 }
2124 else {
2125 reference.ambiguous = true;
2126 reference.resolved = groups;
2127 }
2128 for (const group of groups) {
2129 group.references.push(reference);
2130 }
2131 }
2132 }
2133 onAlternativeEnter(start) {
2134 const parent = this._node;
2135 if (parent.type !== "Assertion" &&
2136 parent.type !== "CapturingGroup" &&
2137 parent.type !== "Group" &&
2138 parent.type !== "Pattern") {
2139 throw new Error("UnknownError");
2140 }
2141 this._node = {
2142 type: "Alternative",
2143 parent,
2144 start,
2145 end: start,
2146 raw: "",
2147 elements: [],
2148 };
2149 parent.alternatives.push(this._node);
2150 }
2151 onAlternativeLeave(start, end) {
2152 const node = this._node;
2153 if (node.type !== "Alternative") {
2154 throw new Error("UnknownError");
2155 }
2156 node.end = end;
2157 node.raw = this.source.slice(start, end);
2158 this._node = node.parent;
2159 }
2160 onGroupEnter(start) {
2161 const parent = this._node;
2162 if (parent.type !== "Alternative") {
2163 throw new Error("UnknownError");
2164 }
2165 this._node = {
2166 type: "Group",
2167 parent,
2168 start,
2169 end: start,
2170 raw: "",
2171 alternatives: [],
2172 };
2173 parent.elements.push(this._node);
2174 }
2175 onGroupLeave(start, end) {
2176 const node = this._node;
2177 if (node.type !== "Group" || node.parent.type !== "Alternative") {
2178 throw new Error("UnknownError");
2179 }
2180 node.end = end;
2181 node.raw = this.source.slice(start, end);
2182 this._node = node.parent;
2183 }
2184 onCapturingGroupEnter(start, name) {
2185 const parent = this._node;
2186 if (parent.type !== "Alternative") {
2187 throw new Error("UnknownError");
2188 }
2189 this._node = {
2190 type: "CapturingGroup",
2191 parent,
2192 start,
2193 end: start,
2194 raw: "",
2195 name,
2196 alternatives: [],
2197 references: [],
2198 };
2199 parent.elements.push(this._node);
2200 this._capturingGroups.push(this._node);
2201 }
2202 onCapturingGroupLeave(start, end) {
2203 const node = this._node;
2204 if (node.type !== "CapturingGroup" ||
2205 node.parent.type !== "Alternative") {
2206 throw new Error("UnknownError");
2207 }
2208 node.end = end;
2209 node.raw = this.source.slice(start, end);
2210 this._node = node.parent;
2211 }
2212 onQuantifier(start, end, min, max, greedy) {
2213 const parent = this._node;
2214 if (parent.type !== "Alternative") {
2215 throw new Error("UnknownError");
2216 }
2217 const element = parent.elements.pop();
2218 if (element == null ||
2219 element.type === "Quantifier" ||
2220 (element.type === "Assertion" && element.kind !== "lookahead")) {
2221 throw new Error("UnknownError");
2222 }
2223 const node = {
2224 type: "Quantifier",
2225 parent,
2226 start: element.start,
2227 end,
2228 raw: this.source.slice(element.start, end),
2229 min,
2230 max,
2231 greedy,
2232 element,
2233 };
2234 parent.elements.push(node);
2235 element.parent = node;
2236 }
2237 onLookaroundAssertionEnter(start, kind, negate) {
2238 const parent = this._node;
2239 if (parent.type !== "Alternative") {
2240 throw new Error("UnknownError");
2241 }
2242 const node = (this._node = {
2243 type: "Assertion",
2244 parent,
2245 start,
2246 end: start,
2247 raw: "",
2248 kind,
2249 negate,
2250 alternatives: [],
2251 });
2252 parent.elements.push(node);
2253 }
2254 onLookaroundAssertionLeave(start, end) {
2255 const node = this._node;
2256 if (node.type !== "Assertion" || node.parent.type !== "Alternative") {
2257 throw new Error("UnknownError");
2258 }
2259 node.end = end;
2260 node.raw = this.source.slice(start, end);
2261 this._node = node.parent;
2262 }
2263 onEdgeAssertion(start, end, kind) {
2264 const parent = this._node;
2265 if (parent.type !== "Alternative") {
2266 throw new Error("UnknownError");
2267 }
2268 parent.elements.push({
2269 type: "Assertion",
2270 parent,
2271 start,
2272 end,
2273 raw: this.source.slice(start, end),
2274 kind,
2275 });
2276 }
2277 onWordBoundaryAssertion(start, end, kind, negate) {
2278 const parent = this._node;
2279 if (parent.type !== "Alternative") {
2280 throw new Error("UnknownError");
2281 }
2282 parent.elements.push({
2283 type: "Assertion",
2284 parent,
2285 start,
2286 end,
2287 raw: this.source.slice(start, end),
2288 kind,
2289 negate,
2290 });
2291 }
2292 onAnyCharacterSet(start, end, kind) {
2293 const parent = this._node;
2294 if (parent.type !== "Alternative") {
2295 throw new Error("UnknownError");
2296 }
2297 parent.elements.push({
2298 type: "CharacterSet",
2299 parent,
2300 start,
2301 end,
2302 raw: this.source.slice(start, end),
2303 kind,
2304 });
2305 }
2306 onEscapeCharacterSet(start, end, kind, negate) {
2307 const parent = this._node;
2308 if (parent.type !== "Alternative" && parent.type !== "CharacterClass") {
2309 throw new Error("UnknownError");
2310 }
2311 parent.elements.push({
2312 type: "CharacterSet",
2313 parent,
2314 start,
2315 end,
2316 raw: this.source.slice(start, end),
2317 kind,
2318 negate,
2319 });
2320 }
2321 onUnicodePropertyCharacterSet(start, end, kind, key, value, negate, strings) {
2322 const parent = this._node;
2323 if (parent.type !== "Alternative" && parent.type !== "CharacterClass") {
2324 throw new Error("UnknownError");
2325 }
2326 const base = {
2327 type: "CharacterSet",
2328 parent: null,
2329 start,
2330 end,
2331 raw: this.source.slice(start, end),
2332 kind,
2333 strings: null,
2334 key,
2335 };
2336 if (strings) {
2337 if ((parent.type === "CharacterClass" && !parent.unicodeSets) ||
2338 negate ||
2339 value !== null) {
2340 throw new Error("UnknownError");
2341 }
2342 parent.elements.push(Object.assign(Object.assign({}, base), { parent, strings, value, negate }));
2343 }
2344 else {
2345 parent.elements.push(Object.assign(Object.assign({}, base), { parent, strings, value, negate }));
2346 }
2347 }
2348 onCharacter(start, end, value) {
2349 const parent = this._node;
2350 if (parent.type !== "Alternative" &&
2351 parent.type !== "CharacterClass" &&
2352 parent.type !== "StringAlternative") {
2353 throw new Error("UnknownError");
2354 }
2355 parent.elements.push({
2356 type: "Character",
2357 parent,
2358 start,
2359 end,
2360 raw: this.source.slice(start, end),
2361 value,
2362 });
2363 }
2364 onBackreference(start, end, ref) {
2365 const parent = this._node;
2366 if (parent.type !== "Alternative") {
2367 throw new Error("UnknownError");
2368 }
2369 const node = {
2370 type: "Backreference",
2371 parent,
2372 start,
2373 end,
2374 raw: this.source.slice(start, end),
2375 ref,
2376 ambiguous: false,
2377 resolved: DUMMY_CAPTURING_GROUP,
2378 };
2379 parent.elements.push(node);
2380 this._backreferences.push(node);
2381 }
2382 onCharacterClassEnter(start, negate, unicodeSets) {
2383 const parent = this._node;
2384 const base = {
2385 type: "CharacterClass",
2386 parent,
2387 start,
2388 end: start,
2389 raw: "",
2390 unicodeSets,
2391 negate,
2392 elements: [],
2393 };
2394 if (parent.type === "Alternative") {
2395 const node = Object.assign(Object.assign({}, base), { parent });
2396 this._node = node;
2397 parent.elements.push(node);
2398 }
2399 else if (parent.type === "CharacterClass" &&
2400 parent.unicodeSets &&
2401 unicodeSets) {
2402 const node = Object.assign(Object.assign({}, base), { parent,
2403 unicodeSets });
2404 this._node = node;
2405 parent.elements.push(node);
2406 }
2407 else {
2408 throw new Error("UnknownError");
2409 }
2410 }
2411 onCharacterClassLeave(start, end) {
2412 const node = this._node;
2413 if (node.type !== "CharacterClass" ||
2414 (node.parent.type !== "Alternative" &&
2415 node.parent.type !== "CharacterClass")) {
2416 throw new Error("UnknownError");
2417 }
2418 const parent = node.parent;
2419 node.end = end;
2420 node.raw = this.source.slice(start, end);
2421 this._node = parent;
2422 const expression = this._expressionBufferMap.get(node);
2423 if (!expression) {
2424 return;
2425 }
2426 if (node.elements.length > 0) {
2427 throw new Error("UnknownError");
2428 }
2429 this._expressionBufferMap.delete(node);
2430 const newNode = {
2431 type: "ExpressionCharacterClass",
2432 parent,
2433 start: node.start,
2434 end: node.end,
2435 raw: node.raw,
2436 negate: node.negate,
2437 expression,
2438 };
2439 expression.parent = newNode;
2440 if (node !== parent.elements.pop()) {
2441 throw new Error("UnknownError");
2442 }
2443 parent.elements.push(newNode);
2444 }
2445 onCharacterClassRange(start, end) {
2446 const parent = this._node;
2447 if (parent.type !== "CharacterClass") {
2448 throw new Error("UnknownError");
2449 }
2450 const elements = parent.elements;
2451 const max = elements.pop();
2452 if (!max || max.type !== "Character") {
2453 throw new Error("UnknownError");
2454 }
2455 if (!parent.unicodeSets) {
2456 const hyphen = elements.pop();
2457 if (!hyphen ||
2458 hyphen.type !== "Character" ||
2459 hyphen.value !== HYPHEN_MINUS) {
2460 throw new Error("UnknownError");
2461 }
2462 }
2463 const min = elements.pop();
2464 if (!min || min.type !== "Character") {
2465 throw new Error("UnknownError");
2466 }
2467 const node = {
2468 type: "CharacterClassRange",
2469 parent,
2470 start,
2471 end,
2472 raw: this.source.slice(start, end),
2473 min,
2474 max,
2475 };
2476 min.parent = node;
2477 max.parent = node;
2478 elements.push(node);
2479 }
2480 onClassIntersection(start, end) {
2481 var _a;
2482 const parent = this._node;
2483 if (parent.type !== "CharacterClass" || !parent.unicodeSets) {
2484 throw new Error("UnknownError");
2485 }
2486 const right = parent.elements.pop();
2487 const left = (_a = this._expressionBufferMap.get(parent)) !== null && _a !== void 0 ? _a : parent.elements.pop();
2488 if (!left ||
2489 !right ||
2490 left.type === "ClassSubtraction" ||
2491 (left.type !== "ClassIntersection" && !isClassSetOperand(left)) ||
2492 !isClassSetOperand(right)) {
2493 throw new Error("UnknownError");
2494 }
2495 const node = {
2496 type: "ClassIntersection",
2497 parent: parent,
2498 start,
2499 end,
2500 raw: this.source.slice(start, end),
2501 left,
2502 right,
2503 };
2504 left.parent = node;
2505 right.parent = node;
2506 this._expressionBufferMap.set(parent, node);
2507 }
2508 onClassSubtraction(start, end) {
2509 var _a;
2510 const parent = this._node;
2511 if (parent.type !== "CharacterClass" || !parent.unicodeSets) {
2512 throw new Error("UnknownError");
2513 }
2514 const right = parent.elements.pop();
2515 const left = (_a = this._expressionBufferMap.get(parent)) !== null && _a !== void 0 ? _a : parent.elements.pop();
2516 if (!left ||
2517 !right ||
2518 left.type === "ClassIntersection" ||
2519 (left.type !== "ClassSubtraction" && !isClassSetOperand(left)) ||
2520 !isClassSetOperand(right)) {
2521 throw new Error("UnknownError");
2522 }
2523 const node = {
2524 type: "ClassSubtraction",
2525 parent: parent,
2526 start,
2527 end,
2528 raw: this.source.slice(start, end),
2529 left,
2530 right,
2531 };
2532 left.parent = node;
2533 right.parent = node;
2534 this._expressionBufferMap.set(parent, node);
2535 }
2536 onClassStringDisjunctionEnter(start) {
2537 const parent = this._node;
2538 if (parent.type !== "CharacterClass" || !parent.unicodeSets) {
2539 throw new Error("UnknownError");
2540 }
2541 this._node = {
2542 type: "ClassStringDisjunction",
2543 parent,
2544 start,
2545 end: start,
2546 raw: "",
2547 alternatives: [],
2548 };
2549 parent.elements.push(this._node);
2550 }
2551 onClassStringDisjunctionLeave(start, end) {
2552 const node = this._node;
2553 if (node.type !== "ClassStringDisjunction" ||
2554 node.parent.type !== "CharacterClass") {
2555 throw new Error("UnknownError");
2556 }
2557 node.end = end;
2558 node.raw = this.source.slice(start, end);
2559 this._node = node.parent;
2560 }
2561 onStringAlternativeEnter(start) {
2562 const parent = this._node;
2563 if (parent.type !== "ClassStringDisjunction") {
2564 throw new Error("UnknownError");
2565 }
2566 this._node = {
2567 type: "StringAlternative",
2568 parent,
2569 start,
2570 end: start,
2571 raw: "",
2572 elements: [],
2573 };
2574 parent.alternatives.push(this._node);
2575 }
2576 onStringAlternativeLeave(start, end) {
2577 const node = this._node;
2578 if (node.type !== "StringAlternative") {
2579 throw new Error("UnknownError");
2580 }
2581 node.end = end;
2582 node.raw = this.source.slice(start, end);
2583 this._node = node.parent;
2584 }
2585}
2586class RegExpParser {
2587 constructor(options) {
2588 this._state = new RegExpParserState(options);
2589 this._validator = new RegExpValidator(this._state);
2590 }
2591 parseLiteral(source, start = 0, end = source.length) {
2592 this._state.source = source;
2593 this._validator.validateLiteral(source, start, end);
2594 const pattern = this._state.pattern;
2595 const flags = this._state.flags;
2596 const literal = {
2597 type: "RegExpLiteral",
2598 parent: null,
2599 start,
2600 end,
2601 raw: source,
2602 pattern,
2603 flags,
2604 };
2605 pattern.parent = literal;
2606 flags.parent = literal;
2607 return literal;
2608 }
2609 parseFlags(source, start = 0, end = source.length) {
2610 this._state.source = source;
2611 this._validator.validateFlags(source, start, end);
2612 return this._state.flags;
2613 }
2614 parsePattern(source, start = 0, end = source.length, uFlagOrFlags = undefined) {
2615 this._state.source = source;
2616 this._validator.validatePattern(source, start, end, uFlagOrFlags);
2617 return this._state.pattern;
2618 }
2619}
2620
2621class RegExpVisitor {
2622 constructor(handlers) {
2623 this._handlers = handlers;
2624 }
2625 visit(node) {
2626 switch (node.type) {
2627 case "Alternative":
2628 this.visitAlternative(node);
2629 break;
2630 case "Assertion":
2631 this.visitAssertion(node);
2632 break;
2633 case "Backreference":
2634 this.visitBackreference(node);
2635 break;
2636 case "CapturingGroup":
2637 this.visitCapturingGroup(node);
2638 break;
2639 case "Character":
2640 this.visitCharacter(node);
2641 break;
2642 case "CharacterClass":
2643 this.visitCharacterClass(node);
2644 break;
2645 case "CharacterClassRange":
2646 this.visitCharacterClassRange(node);
2647 break;
2648 case "CharacterSet":
2649 this.visitCharacterSet(node);
2650 break;
2651 case "ClassIntersection":
2652 this.visitClassIntersection(node);
2653 break;
2654 case "ClassStringDisjunction":
2655 this.visitClassStringDisjunction(node);
2656 break;
2657 case "ClassSubtraction":
2658 this.visitClassSubtraction(node);
2659 break;
2660 case "ExpressionCharacterClass":
2661 this.visitExpressionCharacterClass(node);
2662 break;
2663 case "Flags":
2664 this.visitFlags(node);
2665 break;
2666 case "Group":
2667 this.visitGroup(node);
2668 break;
2669 case "Pattern":
2670 this.visitPattern(node);
2671 break;
2672 case "Quantifier":
2673 this.visitQuantifier(node);
2674 break;
2675 case "RegExpLiteral":
2676 this.visitRegExpLiteral(node);
2677 break;
2678 case "StringAlternative":
2679 this.visitStringAlternative(node);
2680 break;
2681 default:
2682 throw new Error(`Unknown type: ${node.type}`);
2683 }
2684 }
2685 visitAlternative(node) {
2686 if (this._handlers.onAlternativeEnter) {
2687 this._handlers.onAlternativeEnter(node);
2688 }
2689 node.elements.forEach(this.visit, this);
2690 if (this._handlers.onAlternativeLeave) {
2691 this._handlers.onAlternativeLeave(node);
2692 }
2693 }
2694 visitAssertion(node) {
2695 if (this._handlers.onAssertionEnter) {
2696 this._handlers.onAssertionEnter(node);
2697 }
2698 if (node.kind === "lookahead" || node.kind === "lookbehind") {
2699 node.alternatives.forEach(this.visit, this);
2700 }
2701 if (this._handlers.onAssertionLeave) {
2702 this._handlers.onAssertionLeave(node);
2703 }
2704 }
2705 visitBackreference(node) {
2706 if (this._handlers.onBackreferenceEnter) {
2707 this._handlers.onBackreferenceEnter(node);
2708 }
2709 if (this._handlers.onBackreferenceLeave) {
2710 this._handlers.onBackreferenceLeave(node);
2711 }
2712 }
2713 visitCapturingGroup(node) {
2714 if (this._handlers.onCapturingGroupEnter) {
2715 this._handlers.onCapturingGroupEnter(node);
2716 }
2717 node.alternatives.forEach(this.visit, this);
2718 if (this._handlers.onCapturingGroupLeave) {
2719 this._handlers.onCapturingGroupLeave(node);
2720 }
2721 }
2722 visitCharacter(node) {
2723 if (this._handlers.onCharacterEnter) {
2724 this._handlers.onCharacterEnter(node);
2725 }
2726 if (this._handlers.onCharacterLeave) {
2727 this._handlers.onCharacterLeave(node);
2728 }
2729 }
2730 visitCharacterClass(node) {
2731 if (this._handlers.onCharacterClassEnter) {
2732 this._handlers.onCharacterClassEnter(node);
2733 }
2734 node.elements.forEach(this.visit, this);
2735 if (this._handlers.onCharacterClassLeave) {
2736 this._handlers.onCharacterClassLeave(node);
2737 }
2738 }
2739 visitCharacterClassRange(node) {
2740 if (this._handlers.onCharacterClassRangeEnter) {
2741 this._handlers.onCharacterClassRangeEnter(node);
2742 }
2743 this.visitCharacter(node.min);
2744 this.visitCharacter(node.max);
2745 if (this._handlers.onCharacterClassRangeLeave) {
2746 this._handlers.onCharacterClassRangeLeave(node);
2747 }
2748 }
2749 visitCharacterSet(node) {
2750 if (this._handlers.onCharacterSetEnter) {
2751 this._handlers.onCharacterSetEnter(node);
2752 }
2753 if (this._handlers.onCharacterSetLeave) {
2754 this._handlers.onCharacterSetLeave(node);
2755 }
2756 }
2757 visitClassIntersection(node) {
2758 if (this._handlers.onClassIntersectionEnter) {
2759 this._handlers.onClassIntersectionEnter(node);
2760 }
2761 this.visit(node.left);
2762 this.visit(node.right);
2763 if (this._handlers.onClassIntersectionLeave) {
2764 this._handlers.onClassIntersectionLeave(node);
2765 }
2766 }
2767 visitClassStringDisjunction(node) {
2768 if (this._handlers.onClassStringDisjunctionEnter) {
2769 this._handlers.onClassStringDisjunctionEnter(node);
2770 }
2771 node.alternatives.forEach(this.visit, this);
2772 if (this._handlers.onClassStringDisjunctionLeave) {
2773 this._handlers.onClassStringDisjunctionLeave(node);
2774 }
2775 }
2776 visitClassSubtraction(node) {
2777 if (this._handlers.onClassSubtractionEnter) {
2778 this._handlers.onClassSubtractionEnter(node);
2779 }
2780 this.visit(node.left);
2781 this.visit(node.right);
2782 if (this._handlers.onClassSubtractionLeave) {
2783 this._handlers.onClassSubtractionLeave(node);
2784 }
2785 }
2786 visitExpressionCharacterClass(node) {
2787 if (this._handlers.onExpressionCharacterClassEnter) {
2788 this._handlers.onExpressionCharacterClassEnter(node);
2789 }
2790 this.visit(node.expression);
2791 if (this._handlers.onExpressionCharacterClassLeave) {
2792 this._handlers.onExpressionCharacterClassLeave(node);
2793 }
2794 }
2795 visitFlags(node) {
2796 if (this._handlers.onFlagsEnter) {
2797 this._handlers.onFlagsEnter(node);
2798 }
2799 if (this._handlers.onFlagsLeave) {
2800 this._handlers.onFlagsLeave(node);
2801 }
2802 }
2803 visitGroup(node) {
2804 if (this._handlers.onGroupEnter) {
2805 this._handlers.onGroupEnter(node);
2806 }
2807 node.alternatives.forEach(this.visit, this);
2808 if (this._handlers.onGroupLeave) {
2809 this._handlers.onGroupLeave(node);
2810 }
2811 }
2812 visitPattern(node) {
2813 if (this._handlers.onPatternEnter) {
2814 this._handlers.onPatternEnter(node);
2815 }
2816 node.alternatives.forEach(this.visit, this);
2817 if (this._handlers.onPatternLeave) {
2818 this._handlers.onPatternLeave(node);
2819 }
2820 }
2821 visitQuantifier(node) {
2822 if (this._handlers.onQuantifierEnter) {
2823 this._handlers.onQuantifierEnter(node);
2824 }
2825 this.visit(node.element);
2826 if (this._handlers.onQuantifierLeave) {
2827 this._handlers.onQuantifierLeave(node);
2828 }
2829 }
2830 visitRegExpLiteral(node) {
2831 if (this._handlers.onRegExpLiteralEnter) {
2832 this._handlers.onRegExpLiteralEnter(node);
2833 }
2834 this.visitPattern(node.pattern);
2835 this.visitFlags(node.flags);
2836 if (this._handlers.onRegExpLiteralLeave) {
2837 this._handlers.onRegExpLiteralLeave(node);
2838 }
2839 }
2840 visitStringAlternative(node) {
2841 if (this._handlers.onStringAlternativeEnter) {
2842 this._handlers.onStringAlternativeEnter(node);
2843 }
2844 node.elements.forEach(this.visit, this);
2845 if (this._handlers.onStringAlternativeLeave) {
2846 this._handlers.onStringAlternativeLeave(node);
2847 }
2848 }
2849}
2850
2851function parseRegExpLiteral(source, options) {
2852 return new RegExpParser(options).parseLiteral(String(source));
2853}
2854function validateRegExpLiteral(source, options) {
2855 new RegExpValidator(options).validateLiteral(source);
2856}
2857function visitRegExpAST(node, handlers) {
2858 new RegExpVisitor(handlers).visit(node);
2859}
2860
2861exports.AST = ast;
2862exports.RegExpParser = RegExpParser;
2863exports.RegExpSyntaxError = RegExpSyntaxError;
2864exports.RegExpValidator = RegExpValidator;
2865exports.parseRegExpLiteral = parseRegExpLiteral;
2866exports.validateRegExpLiteral = validateRegExpLiteral;
2867exports.visitRegExpAST = visitRegExpAST;
2868//# sourceMappingURL=index.js.map
Note: See TracBrowser for help on using the repository browser.