Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.js 74KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096
  1. /*! @author Toru Nagashima <https://github.com/mysticatea> */
  2. 'use strict';
  3. Object.defineProperty(exports, '__esModule', { value: true });
  4. var ast = /*#__PURE__*/Object.freeze({
  5. });
  6. let largeIdStartRanges = undefined;
  7. let largeIdContinueRanges = undefined;
  8. function isIdStart(cp) {
  9. if (cp < 0x41)
  10. return false;
  11. if (cp < 0x5b)
  12. return true;
  13. if (cp < 0x61)
  14. return false;
  15. if (cp < 0x7b)
  16. return true;
  17. return isLargeIdStart(cp);
  18. }
  19. function isIdContinue(cp) {
  20. if (cp < 0x30)
  21. return false;
  22. if (cp < 0x3a)
  23. return true;
  24. if (cp < 0x41)
  25. return false;
  26. if (cp < 0x5b)
  27. return true;
  28. if (cp === 0x5f)
  29. return true;
  30. if (cp < 0x61)
  31. return false;
  32. if (cp < 0x7b)
  33. return true;
  34. return isLargeIdStart(cp) || isLargeIdContinue(cp);
  35. }
  36. function isLargeIdStart(cp) {
  37. return isInRange(cp, largeIdStartRanges || (largeIdStartRanges = initLargeIdStartRanges()));
  38. }
  39. function isLargeIdContinue(cp) {
  40. return isInRange(cp, largeIdContinueRanges ||
  41. (largeIdContinueRanges = initLargeIdContinueRanges()));
  42. }
  43. function initLargeIdStartRanges() {
  44. 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 1i k 2 h 1p 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 6 1 v 0 5 7 2 2 2 m 2 9 2 4 4 0 x 0 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 c 2 3 f h 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 6 1k 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 1a 2 1a 2 3o 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 g70 4 wc 1w 19 3 7g 4 f b 1 l 1a h u 3 27 14 8 3 2u 3 1g 3 8 17 c 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 4d 8m a l b 7 49 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 2z k s m d 1g 24 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 2d 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 6e 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 z 1k 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 5a 0 28 pl 2v 32 i 5f 24d tq 34i g6 6nu fs 8 u 36 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 6wo 7y 1e 2 i 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 1th 18 b 6 h 0 aa 17 105 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 wyl z 378 c 65 3 4g1 f 5rk 2e8 f1 15v 3t6");
  45. }
  46. function initLargeIdContinueRanges() {
  47. 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 3c e 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 1m 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 h 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 5 3 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 2 u 2 u 1 v 1 1t v a 0 3 9 y 2 3 9 40 0 3b b 5 b b 9 3l a 1p 4 1m 9 2 s 3 a 7 9 n d 2 1 1s 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 1l 2 4 g0 1 k 0 3g c 5 0 4 b 2db 2 3y 0 2p v ff 5 2y 1 n7q 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 ji 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 4a a 4w 2 1i e w 9 g 3 1a a 1i 9 7 2 11 d 2 9 6 1 19 0 d 2 1d d 9 3 2 b 2b b 7 0 4h 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 ewa 9 3r 4 1o 6 q 9 s6 0 2 1i 8 3 2a 0 c 1 f58 1 43r 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 7a 6 a 9 bn d 15j 6 32 6 6 9 3o7 9 gvt3 6n");
  48. }
  49. function isInRange(cp, ranges) {
  50. let l = 0, r = (ranges.length / 2) | 0, i = 0, min = 0, max = 0;
  51. while (l < r) {
  52. i = ((l + r) / 2) | 0;
  53. min = ranges[2 * i];
  54. max = ranges[2 * i + 1];
  55. if (cp < min) {
  56. r = i;
  57. }
  58. else if (cp > max) {
  59. l = i + 1;
  60. }
  61. else {
  62. return true;
  63. }
  64. }
  65. return false;
  66. }
  67. function restoreRanges(data) {
  68. let last = 0;
  69. return data.split(" ").map(s => (last += parseInt(s, 36) | 0));
  70. }
  71. class DataSet {
  72. constructor(raw2018, raw2019, raw2020, raw2021) {
  73. this._raw2018 = raw2018;
  74. this._raw2019 = raw2019;
  75. this._raw2020 = raw2020;
  76. this._raw2021 = raw2021;
  77. }
  78. get es2018() {
  79. return (this._set2018 || (this._set2018 = new Set(this._raw2018.split(" "))));
  80. }
  81. get es2019() {
  82. return (this._set2019 || (this._set2019 = new Set(this._raw2019.split(" "))));
  83. }
  84. get es2020() {
  85. return (this._set2020 || (this._set2020 = new Set(this._raw2020.split(" "))));
  86. }
  87. get es2021() {
  88. return (this._set2021 || (this._set2021 = new Set(this._raw2021.split(" "))));
  89. }
  90. }
  91. const gcNameSet = new Set(["General_Category", "gc"]);
  92. const scNameSet = new Set(["Script", "Script_Extensions", "sc", "scx"]);
  93. const 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", "", "", "");
  94. const 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");
  95. const 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");
  96. function isValidUnicodeProperty(version, name, value) {
  97. if (gcNameSet.has(name)) {
  98. return version >= 2018 && gcValueSets.es2018.has(value);
  99. }
  100. if (scNameSet.has(name)) {
  101. return ((version >= 2018 && scValueSets.es2018.has(value)) ||
  102. (version >= 2019 && scValueSets.es2019.has(value)) ||
  103. (version >= 2020 && scValueSets.es2020.has(value)) ||
  104. (version >= 2021 && scValueSets.es2021.has(value)));
  105. }
  106. return false;
  107. }
  108. function isValidLoneUnicodeProperty(version, value) {
  109. return ((version >= 2018 && binPropertySets.es2018.has(value)) ||
  110. (version >= 2019 && binPropertySets.es2019.has(value)) ||
  111. (version >= 2021 && binPropertySets.es2021.has(value)));
  112. }
  113. const Backspace = 0x08;
  114. const CharacterTabulation = 0x09;
  115. const LineFeed = 0x0a;
  116. const LineTabulation = 0x0b;
  117. const FormFeed = 0x0c;
  118. const CarriageReturn = 0x0d;
  119. const ExclamationMark = 0x21;
  120. const DollarSign = 0x24;
  121. const LeftParenthesis = 0x28;
  122. const RightParenthesis = 0x29;
  123. const Asterisk = 0x2a;
  124. const PlusSign = 0x2b;
  125. const Comma = 0x2c;
  126. const HyphenMinus = 0x2d;
  127. const FullStop = 0x2e;
  128. const Solidus = 0x2f;
  129. const DigitZero = 0x30;
  130. const DigitOne = 0x31;
  131. const DigitSeven = 0x37;
  132. const DigitNine = 0x39;
  133. const Colon = 0x3a;
  134. const LessThanSign = 0x3c;
  135. const EqualsSign = 0x3d;
  136. const GreaterThanSign = 0x3e;
  137. const QuestionMark = 0x3f;
  138. const LatinCapitalLetterA = 0x41;
  139. const LatinCapitalLetterB = 0x42;
  140. const LatinCapitalLetterD = 0x44;
  141. const LatinCapitalLetterF = 0x46;
  142. const LatinCapitalLetterP = 0x50;
  143. const LatinCapitalLetterS = 0x53;
  144. const LatinCapitalLetterW = 0x57;
  145. const LatinCapitalLetterZ = 0x5a;
  146. const LowLine = 0x5f;
  147. const LatinSmallLetterA = 0x61;
  148. const LatinSmallLetterB = 0x62;
  149. const LatinSmallLetterC = 0x63;
  150. const LatinSmallLetterD = 0x64;
  151. const LatinSmallLetterF = 0x66;
  152. const LatinSmallLetterG = 0x67;
  153. const LatinSmallLetterI = 0x69;
  154. const LatinSmallLetterK = 0x6b;
  155. const LatinSmallLetterM = 0x6d;
  156. const LatinSmallLetterN = 0x6e;
  157. const LatinSmallLetterP = 0x70;
  158. const LatinSmallLetterR = 0x72;
  159. const LatinSmallLetterS = 0x73;
  160. const LatinSmallLetterT = 0x74;
  161. const LatinSmallLetterU = 0x75;
  162. const LatinSmallLetterV = 0x76;
  163. const LatinSmallLetterW = 0x77;
  164. const LatinSmallLetterX = 0x78;
  165. const LatinSmallLetterY = 0x79;
  166. const LatinSmallLetterZ = 0x7a;
  167. const LeftSquareBracket = 0x5b;
  168. const ReverseSolidus = 0x5c;
  169. const RightSquareBracket = 0x5d;
  170. const CircumflexAccent = 0x5e;
  171. const LeftCurlyBracket = 0x7b;
  172. const VerticalLine = 0x7c;
  173. const RightCurlyBracket = 0x7d;
  174. const ZeroWidthNonJoiner = 0x200c;
  175. const ZeroWidthJoiner = 0x200d;
  176. const LineSeparator = 0x2028;
  177. const ParagraphSeparator = 0x2029;
  178. const MinCodePoint = 0x00;
  179. const MaxCodePoint = 0x10ffff;
  180. function isLatinLetter(code) {
  181. return ((code >= LatinCapitalLetterA && code <= LatinCapitalLetterZ) ||
  182. (code >= LatinSmallLetterA && code <= LatinSmallLetterZ));
  183. }
  184. function isDecimalDigit(code) {
  185. return code >= DigitZero && code <= DigitNine;
  186. }
  187. function isOctalDigit(code) {
  188. return code >= DigitZero && code <= DigitSeven;
  189. }
  190. function isHexDigit(code) {
  191. return ((code >= DigitZero && code <= DigitNine) ||
  192. (code >= LatinCapitalLetterA && code <= LatinCapitalLetterF) ||
  193. (code >= LatinSmallLetterA && code <= LatinSmallLetterF));
  194. }
  195. function isLineTerminator(code) {
  196. return (code === LineFeed ||
  197. code === CarriageReturn ||
  198. code === LineSeparator ||
  199. code === ParagraphSeparator);
  200. }
  201. function isValidUnicode(code) {
  202. return code >= MinCodePoint && code <= MaxCodePoint;
  203. }
  204. function digitToInt(code) {
  205. if (code >= LatinSmallLetterA && code <= LatinSmallLetterF) {
  206. return code - LatinSmallLetterA + 10;
  207. }
  208. if (code >= LatinCapitalLetterA && code <= LatinCapitalLetterF) {
  209. return code - LatinCapitalLetterA + 10;
  210. }
  211. return code - DigitZero;
  212. }
  213. function isLeadSurrogate(code) {
  214. return code >= 0xd800 && code <= 0xdbff;
  215. }
  216. function isTrailSurrogate(code) {
  217. return code >= 0xdc00 && code <= 0xdfff;
  218. }
  219. function combineSurrogatePair(lead, trail) {
  220. return (lead - 0xd800) * 0x400 + (trail - 0xdc00) + 0x10000;
  221. }
  222. const legacyImpl = {
  223. at(s, end, i) {
  224. return i < end ? s.charCodeAt(i) : -1;
  225. },
  226. width(c) {
  227. return 1;
  228. },
  229. };
  230. const unicodeImpl = {
  231. at(s, end, i) {
  232. return i < end ? s.codePointAt(i) : -1;
  233. },
  234. width(c) {
  235. return c > 0xffff ? 2 : 1;
  236. },
  237. };
  238. class Reader {
  239. constructor() {
  240. this._impl = legacyImpl;
  241. this._s = "";
  242. this._i = 0;
  243. this._end = 0;
  244. this._cp1 = -1;
  245. this._w1 = 1;
  246. this._cp2 = -1;
  247. this._w2 = 1;
  248. this._cp3 = -1;
  249. this._w3 = 1;
  250. this._cp4 = -1;
  251. }
  252. get source() {
  253. return this._s;
  254. }
  255. get index() {
  256. return this._i;
  257. }
  258. get currentCodePoint() {
  259. return this._cp1;
  260. }
  261. get nextCodePoint() {
  262. return this._cp2;
  263. }
  264. get nextCodePoint2() {
  265. return this._cp3;
  266. }
  267. get nextCodePoint3() {
  268. return this._cp4;
  269. }
  270. reset(source, start, end, uFlag) {
  271. this._impl = uFlag ? unicodeImpl : legacyImpl;
  272. this._s = source;
  273. this._end = end;
  274. this.rewind(start);
  275. }
  276. rewind(index) {
  277. const impl = this._impl;
  278. this._i = index;
  279. this._cp1 = impl.at(this._s, this._end, index);
  280. this._w1 = impl.width(this._cp1);
  281. this._cp2 = impl.at(this._s, this._end, index + this._w1);
  282. this._w2 = impl.width(this._cp2);
  283. this._cp3 = impl.at(this._s, this._end, index + this._w1 + this._w2);
  284. this._w3 = impl.width(this._cp3);
  285. this._cp4 = impl.at(this._s, this._end, index + this._w1 + this._w2 + this._w3);
  286. }
  287. advance() {
  288. if (this._cp1 !== -1) {
  289. const impl = this._impl;
  290. this._i += this._w1;
  291. this._cp1 = this._cp2;
  292. this._w1 = this._w2;
  293. this._cp2 = this._cp3;
  294. this._w2 = impl.width(this._cp2);
  295. this._cp3 = this._cp4;
  296. this._w3 = impl.width(this._cp3);
  297. this._cp4 = impl.at(this._s, this._end, this._i + this._w1 + this._w2 + this._w3);
  298. }
  299. }
  300. eat(cp) {
  301. if (this._cp1 === cp) {
  302. this.advance();
  303. return true;
  304. }
  305. return false;
  306. }
  307. eat2(cp1, cp2) {
  308. if (this._cp1 === cp1 && this._cp2 === cp2) {
  309. this.advance();
  310. this.advance();
  311. return true;
  312. }
  313. return false;
  314. }
  315. eat3(cp1, cp2, cp3) {
  316. if (this._cp1 === cp1 && this._cp2 === cp2 && this._cp3 === cp3) {
  317. this.advance();
  318. this.advance();
  319. this.advance();
  320. return true;
  321. }
  322. return false;
  323. }
  324. }
  325. class RegExpSyntaxError extends SyntaxError {
  326. constructor(source, uFlag, index, message) {
  327. if (source) {
  328. if (!source.startsWith("/")) {
  329. source = `/${source}/${uFlag ? "u" : ""}`;
  330. }
  331. source = `: ${source}`;
  332. }
  333. super(`Invalid regular expression${source}: ${message}`);
  334. this.index = index;
  335. }
  336. }
  337. function isSyntaxCharacter(cp) {
  338. return (cp === CircumflexAccent ||
  339. cp === DollarSign ||
  340. cp === ReverseSolidus ||
  341. cp === FullStop ||
  342. cp === Asterisk ||
  343. cp === PlusSign ||
  344. cp === QuestionMark ||
  345. cp === LeftParenthesis ||
  346. cp === RightParenthesis ||
  347. cp === LeftSquareBracket ||
  348. cp === RightSquareBracket ||
  349. cp === LeftCurlyBracket ||
  350. cp === RightCurlyBracket ||
  351. cp === VerticalLine);
  352. }
  353. function isRegExpIdentifierStart(cp) {
  354. return isIdStart(cp) || cp === DollarSign || cp === LowLine;
  355. }
  356. function isRegExpIdentifierPart(cp) {
  357. return (isIdContinue(cp) ||
  358. cp === DollarSign ||
  359. cp === LowLine ||
  360. cp === ZeroWidthNonJoiner ||
  361. cp === ZeroWidthJoiner);
  362. }
  363. function isUnicodePropertyNameCharacter(cp) {
  364. return isLatinLetter(cp) || cp === LowLine;
  365. }
  366. function isUnicodePropertyValueCharacter(cp) {
  367. return isUnicodePropertyNameCharacter(cp) || isDecimalDigit(cp);
  368. }
  369. class RegExpValidator {
  370. constructor(options) {
  371. this._reader = new Reader();
  372. this._uFlag = false;
  373. this._nFlag = false;
  374. this._lastIntValue = 0;
  375. this._lastMinValue = 0;
  376. this._lastMaxValue = 0;
  377. this._lastStrValue = "";
  378. this._lastKeyValue = "";
  379. this._lastValValue = "";
  380. this._lastAssertionIsQuantifiable = false;
  381. this._numCapturingParens = 0;
  382. this._groupNames = new Set();
  383. this._backreferenceNames = new Set();
  384. this._options = options || {};
  385. }
  386. validateLiteral(source, start = 0, end = source.length) {
  387. this._uFlag = this._nFlag = false;
  388. this.reset(source, start, end);
  389. this.onLiteralEnter(start);
  390. if (this.eat(Solidus) && this.eatRegExpBody() && this.eat(Solidus)) {
  391. const flagStart = this.index;
  392. const uFlag = source.includes("u", flagStart);
  393. this.validateFlags(source, flagStart, end);
  394. this.validatePattern(source, start + 1, flagStart - 1, uFlag);
  395. }
  396. else if (start >= end) {
  397. this.raise("Empty");
  398. }
  399. else {
  400. const c = String.fromCodePoint(this.currentCodePoint);
  401. this.raise(`Unexpected character '${c}'`);
  402. }
  403. this.onLiteralLeave(start, end);
  404. }
  405. validateFlags(source, start = 0, end = source.length) {
  406. const existingFlags = new Set();
  407. let global = false;
  408. let ignoreCase = false;
  409. let multiline = false;
  410. let sticky = false;
  411. let unicode = false;
  412. let dotAll = false;
  413. let hasIndices = false;
  414. for (let i = start; i < end; ++i) {
  415. const flag = source.charCodeAt(i);
  416. if (existingFlags.has(flag)) {
  417. this.raise(`Duplicated flag '${source[i]}'`);
  418. }
  419. existingFlags.add(flag);
  420. if (flag === LatinSmallLetterG) {
  421. global = true;
  422. }
  423. else if (flag === LatinSmallLetterI) {
  424. ignoreCase = true;
  425. }
  426. else if (flag === LatinSmallLetterM) {
  427. multiline = true;
  428. }
  429. else if (flag === LatinSmallLetterU && this.ecmaVersion >= 2015) {
  430. unicode = true;
  431. }
  432. else if (flag === LatinSmallLetterY && this.ecmaVersion >= 2015) {
  433. sticky = true;
  434. }
  435. else if (flag === LatinSmallLetterS && this.ecmaVersion >= 2018) {
  436. dotAll = true;
  437. }
  438. else if (flag === LatinSmallLetterD && this.ecmaVersion >= 2022) {
  439. hasIndices = true;
  440. }
  441. else {
  442. this.raise(`Invalid flag '${source[i]}'`);
  443. }
  444. }
  445. this.onFlags(start, end, global, ignoreCase, multiline, unicode, sticky, dotAll, hasIndices);
  446. }
  447. validatePattern(source, start = 0, end = source.length, uFlag = false) {
  448. this._uFlag = uFlag && this.ecmaVersion >= 2015;
  449. this._nFlag = uFlag && this.ecmaVersion >= 2018;
  450. this.reset(source, start, end);
  451. this.consumePattern();
  452. if (!this._nFlag &&
  453. this.ecmaVersion >= 2018 &&
  454. this._groupNames.size > 0) {
  455. this._nFlag = true;
  456. this.rewind(start);
  457. this.consumePattern();
  458. }
  459. }
  460. get strict() {
  461. return Boolean(this._options.strict || this._uFlag);
  462. }
  463. get ecmaVersion() {
  464. return this._options.ecmaVersion || 2022;
  465. }
  466. onLiteralEnter(start) {
  467. if (this._options.onLiteralEnter) {
  468. this._options.onLiteralEnter(start);
  469. }
  470. }
  471. onLiteralLeave(start, end) {
  472. if (this._options.onLiteralLeave) {
  473. this._options.onLiteralLeave(start, end);
  474. }
  475. }
  476. onFlags(start, end, global, ignoreCase, multiline, unicode, sticky, dotAll, hasIndices) {
  477. if (this._options.onFlags) {
  478. this._options.onFlags(start, end, global, ignoreCase, multiline, unicode, sticky, dotAll, hasIndices);
  479. }
  480. }
  481. onPatternEnter(start) {
  482. if (this._options.onPatternEnter) {
  483. this._options.onPatternEnter(start);
  484. }
  485. }
  486. onPatternLeave(start, end) {
  487. if (this._options.onPatternLeave) {
  488. this._options.onPatternLeave(start, end);
  489. }
  490. }
  491. onDisjunctionEnter(start) {
  492. if (this._options.onDisjunctionEnter) {
  493. this._options.onDisjunctionEnter(start);
  494. }
  495. }
  496. onDisjunctionLeave(start, end) {
  497. if (this._options.onDisjunctionLeave) {
  498. this._options.onDisjunctionLeave(start, end);
  499. }
  500. }
  501. onAlternativeEnter(start, index) {
  502. if (this._options.onAlternativeEnter) {
  503. this._options.onAlternativeEnter(start, index);
  504. }
  505. }
  506. onAlternativeLeave(start, end, index) {
  507. if (this._options.onAlternativeLeave) {
  508. this._options.onAlternativeLeave(start, end, index);
  509. }
  510. }
  511. onGroupEnter(start) {
  512. if (this._options.onGroupEnter) {
  513. this._options.onGroupEnter(start);
  514. }
  515. }
  516. onGroupLeave(start, end) {
  517. if (this._options.onGroupLeave) {
  518. this._options.onGroupLeave(start, end);
  519. }
  520. }
  521. onCapturingGroupEnter(start, name) {
  522. if (this._options.onCapturingGroupEnter) {
  523. this._options.onCapturingGroupEnter(start, name);
  524. }
  525. }
  526. onCapturingGroupLeave(start, end, name) {
  527. if (this._options.onCapturingGroupLeave) {
  528. this._options.onCapturingGroupLeave(start, end, name);
  529. }
  530. }
  531. onQuantifier(start, end, min, max, greedy) {
  532. if (this._options.onQuantifier) {
  533. this._options.onQuantifier(start, end, min, max, greedy);
  534. }
  535. }
  536. onLookaroundAssertionEnter(start, kind, negate) {
  537. if (this._options.onLookaroundAssertionEnter) {
  538. this._options.onLookaroundAssertionEnter(start, kind, negate);
  539. }
  540. }
  541. onLookaroundAssertionLeave(start, end, kind, negate) {
  542. if (this._options.onLookaroundAssertionLeave) {
  543. this._options.onLookaroundAssertionLeave(start, end, kind, negate);
  544. }
  545. }
  546. onEdgeAssertion(start, end, kind) {
  547. if (this._options.onEdgeAssertion) {
  548. this._options.onEdgeAssertion(start, end, kind);
  549. }
  550. }
  551. onWordBoundaryAssertion(start, end, kind, negate) {
  552. if (this._options.onWordBoundaryAssertion) {
  553. this._options.onWordBoundaryAssertion(start, end, kind, negate);
  554. }
  555. }
  556. onAnyCharacterSet(start, end, kind) {
  557. if (this._options.onAnyCharacterSet) {
  558. this._options.onAnyCharacterSet(start, end, kind);
  559. }
  560. }
  561. onEscapeCharacterSet(start, end, kind, negate) {
  562. if (this._options.onEscapeCharacterSet) {
  563. this._options.onEscapeCharacterSet(start, end, kind, negate);
  564. }
  565. }
  566. onUnicodePropertyCharacterSet(start, end, kind, key, value, negate) {
  567. if (this._options.onUnicodePropertyCharacterSet) {
  568. this._options.onUnicodePropertyCharacterSet(start, end, kind, key, value, negate);
  569. }
  570. }
  571. onCharacter(start, end, value) {
  572. if (this._options.onCharacter) {
  573. this._options.onCharacter(start, end, value);
  574. }
  575. }
  576. onBackreference(start, end, ref) {
  577. if (this._options.onBackreference) {
  578. this._options.onBackreference(start, end, ref);
  579. }
  580. }
  581. onCharacterClassEnter(start, negate) {
  582. if (this._options.onCharacterClassEnter) {
  583. this._options.onCharacterClassEnter(start, negate);
  584. }
  585. }
  586. onCharacterClassLeave(start, end, negate) {
  587. if (this._options.onCharacterClassLeave) {
  588. this._options.onCharacterClassLeave(start, end, negate);
  589. }
  590. }
  591. onCharacterClassRange(start, end, min, max) {
  592. if (this._options.onCharacterClassRange) {
  593. this._options.onCharacterClassRange(start, end, min, max);
  594. }
  595. }
  596. get source() {
  597. return this._reader.source;
  598. }
  599. get index() {
  600. return this._reader.index;
  601. }
  602. get currentCodePoint() {
  603. return this._reader.currentCodePoint;
  604. }
  605. get nextCodePoint() {
  606. return this._reader.nextCodePoint;
  607. }
  608. get nextCodePoint2() {
  609. return this._reader.nextCodePoint2;
  610. }
  611. get nextCodePoint3() {
  612. return this._reader.nextCodePoint3;
  613. }
  614. reset(source, start, end) {
  615. this._reader.reset(source, start, end, this._uFlag);
  616. }
  617. rewind(index) {
  618. this._reader.rewind(index);
  619. }
  620. advance() {
  621. this._reader.advance();
  622. }
  623. eat(cp) {
  624. return this._reader.eat(cp);
  625. }
  626. eat2(cp1, cp2) {
  627. return this._reader.eat2(cp1, cp2);
  628. }
  629. eat3(cp1, cp2, cp3) {
  630. return this._reader.eat3(cp1, cp2, cp3);
  631. }
  632. raise(message) {
  633. throw new RegExpSyntaxError(this.source, this._uFlag, this.index, message);
  634. }
  635. eatRegExpBody() {
  636. const start = this.index;
  637. let inClass = false;
  638. let escaped = false;
  639. for (;;) {
  640. const cp = this.currentCodePoint;
  641. if (cp === -1 || isLineTerminator(cp)) {
  642. const kind = inClass ? "character class" : "regular expression";
  643. this.raise(`Unterminated ${kind}`);
  644. }
  645. if (escaped) {
  646. escaped = false;
  647. }
  648. else if (cp === ReverseSolidus) {
  649. escaped = true;
  650. }
  651. else if (cp === LeftSquareBracket) {
  652. inClass = true;
  653. }
  654. else if (cp === RightSquareBracket) {
  655. inClass = false;
  656. }
  657. else if ((cp === Solidus && !inClass) ||
  658. (cp === Asterisk && this.index === start)) {
  659. break;
  660. }
  661. this.advance();
  662. }
  663. return this.index !== start;
  664. }
  665. consumePattern() {
  666. const start = this.index;
  667. this._numCapturingParens = this.countCapturingParens();
  668. this._groupNames.clear();
  669. this._backreferenceNames.clear();
  670. this.onPatternEnter(start);
  671. this.consumeDisjunction();
  672. const cp = this.currentCodePoint;
  673. if (this.currentCodePoint !== -1) {
  674. if (cp === RightParenthesis) {
  675. this.raise("Unmatched ')'");
  676. }
  677. if (cp === ReverseSolidus) {
  678. this.raise("\\ at end of pattern");
  679. }
  680. if (cp === RightSquareBracket || cp === RightCurlyBracket) {
  681. this.raise("Lone quantifier brackets");
  682. }
  683. const c = String.fromCodePoint(cp);
  684. this.raise(`Unexpected character '${c}'`);
  685. }
  686. for (const name of this._backreferenceNames) {
  687. if (!this._groupNames.has(name)) {
  688. this.raise("Invalid named capture referenced");
  689. }
  690. }
  691. this.onPatternLeave(start, this.index);
  692. }
  693. countCapturingParens() {
  694. const start = this.index;
  695. let inClass = false;
  696. let escaped = false;
  697. let count = 0;
  698. let cp = 0;
  699. while ((cp = this.currentCodePoint) !== -1) {
  700. if (escaped) {
  701. escaped = false;
  702. }
  703. else if (cp === ReverseSolidus) {
  704. escaped = true;
  705. }
  706. else if (cp === LeftSquareBracket) {
  707. inClass = true;
  708. }
  709. else if (cp === RightSquareBracket) {
  710. inClass = false;
  711. }
  712. else if (cp === LeftParenthesis &&
  713. !inClass &&
  714. (this.nextCodePoint !== QuestionMark ||
  715. (this.nextCodePoint2 === LessThanSign &&
  716. this.nextCodePoint3 !== EqualsSign &&
  717. this.nextCodePoint3 !== ExclamationMark))) {
  718. count += 1;
  719. }
  720. this.advance();
  721. }
  722. this.rewind(start);
  723. return count;
  724. }
  725. consumeDisjunction() {
  726. const start = this.index;
  727. let i = 0;
  728. this.onDisjunctionEnter(start);
  729. do {
  730. this.consumeAlternative(i++);
  731. } while (this.eat(VerticalLine));
  732. if (this.consumeQuantifier(true)) {
  733. this.raise("Nothing to repeat");
  734. }
  735. if (this.eat(LeftCurlyBracket)) {
  736. this.raise("Lone quantifier brackets");
  737. }
  738. this.onDisjunctionLeave(start, this.index);
  739. }
  740. consumeAlternative(i) {
  741. const start = this.index;
  742. this.onAlternativeEnter(start, i);
  743. while (this.currentCodePoint !== -1 && this.consumeTerm()) {
  744. }
  745. this.onAlternativeLeave(start, this.index, i);
  746. }
  747. consumeTerm() {
  748. if (this._uFlag || this.strict) {
  749. return (this.consumeAssertion() ||
  750. (this.consumeAtom() && this.consumeOptionalQuantifier()));
  751. }
  752. return ((this.consumeAssertion() &&
  753. (!this._lastAssertionIsQuantifiable ||
  754. this.consumeOptionalQuantifier())) ||
  755. (this.consumeExtendedAtom() && this.consumeOptionalQuantifier()));
  756. }
  757. consumeOptionalQuantifier() {
  758. this.consumeQuantifier();
  759. return true;
  760. }
  761. consumeAssertion() {
  762. const start = this.index;
  763. this._lastAssertionIsQuantifiable = false;
  764. if (this.eat(CircumflexAccent)) {
  765. this.onEdgeAssertion(start, this.index, "start");
  766. return true;
  767. }
  768. if (this.eat(DollarSign)) {
  769. this.onEdgeAssertion(start, this.index, "end");
  770. return true;
  771. }
  772. if (this.eat2(ReverseSolidus, LatinCapitalLetterB)) {
  773. this.onWordBoundaryAssertion(start, this.index, "word", true);
  774. return true;
  775. }
  776. if (this.eat2(ReverseSolidus, LatinSmallLetterB)) {
  777. this.onWordBoundaryAssertion(start, this.index, "word", false);
  778. return true;
  779. }
  780. if (this.eat2(LeftParenthesis, QuestionMark)) {
  781. const lookbehind = this.ecmaVersion >= 2018 && this.eat(LessThanSign);
  782. let negate = false;
  783. if (this.eat(EqualsSign) || (negate = this.eat(ExclamationMark))) {
  784. const kind = lookbehind ? "lookbehind" : "lookahead";
  785. this.onLookaroundAssertionEnter(start, kind, negate);
  786. this.consumeDisjunction();
  787. if (!this.eat(RightParenthesis)) {
  788. this.raise("Unterminated group");
  789. }
  790. this._lastAssertionIsQuantifiable = !lookbehind && !this.strict;
  791. this.onLookaroundAssertionLeave(start, this.index, kind, negate);
  792. return true;
  793. }
  794. this.rewind(start);
  795. }
  796. return false;
  797. }
  798. consumeQuantifier(noConsume = false) {
  799. const start = this.index;
  800. let min = 0;
  801. let max = 0;
  802. let greedy = false;
  803. if (this.eat(Asterisk)) {
  804. min = 0;
  805. max = Number.POSITIVE_INFINITY;
  806. }
  807. else if (this.eat(PlusSign)) {
  808. min = 1;
  809. max = Number.POSITIVE_INFINITY;
  810. }
  811. else if (this.eat(QuestionMark)) {
  812. min = 0;
  813. max = 1;
  814. }
  815. else if (this.eatBracedQuantifier(noConsume)) {
  816. min = this._lastMinValue;
  817. max = this._lastMaxValue;
  818. }
  819. else {
  820. return false;
  821. }
  822. greedy = !this.eat(QuestionMark);
  823. if (!noConsume) {
  824. this.onQuantifier(start, this.index, min, max, greedy);
  825. }
  826. return true;
  827. }
  828. eatBracedQuantifier(noError) {
  829. const start = this.index;
  830. if (this.eat(LeftCurlyBracket)) {
  831. this._lastMinValue = 0;
  832. this._lastMaxValue = Number.POSITIVE_INFINITY;
  833. if (this.eatDecimalDigits()) {
  834. this._lastMinValue = this._lastMaxValue = this._lastIntValue;
  835. if (this.eat(Comma)) {
  836. this._lastMaxValue = this.eatDecimalDigits()
  837. ? this._lastIntValue
  838. : Number.POSITIVE_INFINITY;
  839. }
  840. if (this.eat(RightCurlyBracket)) {
  841. if (!noError && this._lastMaxValue < this._lastMinValue) {
  842. this.raise("numbers out of order in {} quantifier");
  843. }
  844. return true;
  845. }
  846. }
  847. if (!noError && (this._uFlag || this.strict)) {
  848. this.raise("Incomplete quantifier");
  849. }
  850. this.rewind(start);
  851. }
  852. return false;
  853. }
  854. consumeAtom() {
  855. return (this.consumePatternCharacter() ||
  856. this.consumeDot() ||
  857. this.consumeReverseSolidusAtomEscape() ||
  858. this.consumeCharacterClass() ||
  859. this.consumeUncapturingGroup() ||
  860. this.consumeCapturingGroup());
  861. }
  862. consumeDot() {
  863. if (this.eat(FullStop)) {
  864. this.onAnyCharacterSet(this.index - 1, this.index, "any");
  865. return true;
  866. }
  867. return false;
  868. }
  869. consumeReverseSolidusAtomEscape() {
  870. const start = this.index;
  871. if (this.eat(ReverseSolidus)) {
  872. if (this.consumeAtomEscape()) {
  873. return true;
  874. }
  875. this.rewind(start);
  876. }
  877. return false;
  878. }
  879. consumeUncapturingGroup() {
  880. const start = this.index;
  881. if (this.eat3(LeftParenthesis, QuestionMark, Colon)) {
  882. this.onGroupEnter(start);
  883. this.consumeDisjunction();
  884. if (!this.eat(RightParenthesis)) {
  885. this.raise("Unterminated group");
  886. }
  887. this.onGroupLeave(start, this.index);
  888. return true;
  889. }
  890. return false;
  891. }
  892. consumeCapturingGroup() {
  893. const start = this.index;
  894. if (this.eat(LeftParenthesis)) {
  895. let name = null;
  896. if (this.ecmaVersion >= 2018) {
  897. if (this.consumeGroupSpecifier()) {
  898. name = this._lastStrValue;
  899. }
  900. }
  901. else if (this.currentCodePoint === QuestionMark) {
  902. this.raise("Invalid group");
  903. }
  904. this.onCapturingGroupEnter(start, name);
  905. this.consumeDisjunction();
  906. if (!this.eat(RightParenthesis)) {
  907. this.raise("Unterminated group");
  908. }
  909. this.onCapturingGroupLeave(start, this.index, name);
  910. return true;
  911. }
  912. return false;
  913. }
  914. consumeExtendedAtom() {
  915. return (this.consumeDot() ||
  916. this.consumeReverseSolidusAtomEscape() ||
  917. this.consumeReverseSolidusFollowedByC() ||
  918. this.consumeCharacterClass() ||
  919. this.consumeUncapturingGroup() ||
  920. this.consumeCapturingGroup() ||
  921. this.consumeInvalidBracedQuantifier() ||
  922. this.consumeExtendedPatternCharacter());
  923. }
  924. consumeReverseSolidusFollowedByC() {
  925. const start = this.index;
  926. if (this.currentCodePoint === ReverseSolidus &&
  927. this.nextCodePoint === LatinSmallLetterC) {
  928. this._lastIntValue = this.currentCodePoint;
  929. this.advance();
  930. this.onCharacter(start, this.index, ReverseSolidus);
  931. return true;
  932. }
  933. return false;
  934. }
  935. consumeInvalidBracedQuantifier() {
  936. if (this.eatBracedQuantifier(true)) {
  937. this.raise("Nothing to repeat");
  938. }
  939. return false;
  940. }
  941. consumePatternCharacter() {
  942. const start = this.index;
  943. const cp = this.currentCodePoint;
  944. if (cp !== -1 && !isSyntaxCharacter(cp)) {
  945. this.advance();
  946. this.onCharacter(start, this.index, cp);
  947. return true;
  948. }
  949. return false;
  950. }
  951. consumeExtendedPatternCharacter() {
  952. const start = this.index;
  953. const cp = this.currentCodePoint;
  954. if (cp !== -1 &&
  955. cp !== CircumflexAccent &&
  956. cp !== DollarSign &&
  957. cp !== ReverseSolidus &&
  958. cp !== FullStop &&
  959. cp !== Asterisk &&
  960. cp !== PlusSign &&
  961. cp !== QuestionMark &&
  962. cp !== LeftParenthesis &&
  963. cp !== RightParenthesis &&
  964. cp !== LeftSquareBracket &&
  965. cp !== VerticalLine) {
  966. this.advance();
  967. this.onCharacter(start, this.index, cp);
  968. return true;
  969. }
  970. return false;
  971. }
  972. consumeGroupSpecifier() {
  973. if (this.eat(QuestionMark)) {
  974. if (this.eatGroupName()) {
  975. if (!this._groupNames.has(this._lastStrValue)) {
  976. this._groupNames.add(this._lastStrValue);
  977. return true;
  978. }
  979. this.raise("Duplicate capture group name");
  980. }
  981. this.raise("Invalid group");
  982. }
  983. return false;
  984. }
  985. consumeAtomEscape() {
  986. if (this.consumeBackreference() ||
  987. this.consumeCharacterClassEscape() ||
  988. this.consumeCharacterEscape() ||
  989. (this._nFlag && this.consumeKGroupName())) {
  990. return true;
  991. }
  992. if (this.strict || this._uFlag) {
  993. this.raise("Invalid escape");
  994. }
  995. return false;
  996. }
  997. consumeBackreference() {
  998. const start = this.index;
  999. if (this.eatDecimalEscape()) {
  1000. const n = this._lastIntValue;
  1001. if (n <= this._numCapturingParens) {
  1002. this.onBackreference(start - 1, this.index, n);
  1003. return true;
  1004. }
  1005. if (this.strict || this._uFlag) {
  1006. this.raise("Invalid escape");
  1007. }
  1008. this.rewind(start);
  1009. }
  1010. return false;
  1011. }
  1012. consumeCharacterClassEscape() {
  1013. const start = this.index;
  1014. if (this.eat(LatinSmallLetterD)) {
  1015. this._lastIntValue = -1;
  1016. this.onEscapeCharacterSet(start - 1, this.index, "digit", false);
  1017. return true;
  1018. }
  1019. if (this.eat(LatinCapitalLetterD)) {
  1020. this._lastIntValue = -1;
  1021. this.onEscapeCharacterSet(start - 1, this.index, "digit", true);
  1022. return true;
  1023. }
  1024. if (this.eat(LatinSmallLetterS)) {
  1025. this._lastIntValue = -1;
  1026. this.onEscapeCharacterSet(start - 1, this.index, "space", false);
  1027. return true;
  1028. }
  1029. if (this.eat(LatinCapitalLetterS)) {
  1030. this._lastIntValue = -1;
  1031. this.onEscapeCharacterSet(start - 1, this.index, "space", true);
  1032. return true;
  1033. }
  1034. if (this.eat(LatinSmallLetterW)) {
  1035. this._lastIntValue = -1;
  1036. this.onEscapeCharacterSet(start - 1, this.index, "word", false);
  1037. return true;
  1038. }
  1039. if (this.eat(LatinCapitalLetterW)) {
  1040. this._lastIntValue = -1;
  1041. this.onEscapeCharacterSet(start - 1, this.index, "word", true);
  1042. return true;
  1043. }
  1044. let negate = false;
  1045. if (this._uFlag &&
  1046. this.ecmaVersion >= 2018 &&
  1047. (this.eat(LatinSmallLetterP) ||
  1048. (negate = this.eat(LatinCapitalLetterP)))) {
  1049. this._lastIntValue = -1;
  1050. if (this.eat(LeftCurlyBracket) &&
  1051. this.eatUnicodePropertyValueExpression() &&
  1052. this.eat(RightCurlyBracket)) {
  1053. this.onUnicodePropertyCharacterSet(start - 1, this.index, "property", this._lastKeyValue, this._lastValValue || null, negate);
  1054. return true;
  1055. }
  1056. this.raise("Invalid property name");
  1057. }
  1058. return false;
  1059. }
  1060. consumeCharacterEscape() {
  1061. const start = this.index;
  1062. if (this.eatControlEscape() ||
  1063. this.eatCControlLetter() ||
  1064. this.eatZero() ||
  1065. this.eatHexEscapeSequence() ||
  1066. this.eatRegExpUnicodeEscapeSequence() ||
  1067. (!this.strict &&
  1068. !this._uFlag &&
  1069. this.eatLegacyOctalEscapeSequence()) ||
  1070. this.eatIdentityEscape()) {
  1071. this.onCharacter(start - 1, this.index, this._lastIntValue);
  1072. return true;
  1073. }
  1074. return false;
  1075. }
  1076. consumeKGroupName() {
  1077. const start = this.index;
  1078. if (this.eat(LatinSmallLetterK)) {
  1079. if (this.eatGroupName()) {
  1080. const groupName = this._lastStrValue;
  1081. this._backreferenceNames.add(groupName);
  1082. this.onBackreference(start - 1, this.index, groupName);
  1083. return true;
  1084. }
  1085. this.raise("Invalid named reference");
  1086. }
  1087. return false;
  1088. }
  1089. consumeCharacterClass() {
  1090. const start = this.index;
  1091. if (this.eat(LeftSquareBracket)) {
  1092. const negate = this.eat(CircumflexAccent);
  1093. this.onCharacterClassEnter(start, negate);
  1094. this.consumeClassRanges();
  1095. if (!this.eat(RightSquareBracket)) {
  1096. this.raise("Unterminated character class");
  1097. }
  1098. this.onCharacterClassLeave(start, this.index, negate);
  1099. return true;
  1100. }
  1101. return false;
  1102. }
  1103. consumeClassRanges() {
  1104. const strict = this.strict || this._uFlag;
  1105. for (;;) {
  1106. const rangeStart = this.index;
  1107. if (!this.consumeClassAtom()) {
  1108. break;
  1109. }
  1110. const min = this._lastIntValue;
  1111. if (!this.eat(HyphenMinus)) {
  1112. continue;
  1113. }
  1114. this.onCharacter(this.index - 1, this.index, HyphenMinus);
  1115. if (!this.consumeClassAtom()) {
  1116. break;
  1117. }
  1118. const max = this._lastIntValue;
  1119. if (min === -1 || max === -1) {
  1120. if (strict) {
  1121. this.raise("Invalid character class");
  1122. }
  1123. continue;
  1124. }
  1125. if (min > max) {
  1126. this.raise("Range out of order in character class");
  1127. }
  1128. this.onCharacterClassRange(rangeStart, this.index, min, max);
  1129. }
  1130. }
  1131. consumeClassAtom() {
  1132. const start = this.index;
  1133. const cp = this.currentCodePoint;
  1134. if (cp !== -1 && cp !== ReverseSolidus && cp !== RightSquareBracket) {
  1135. this.advance();
  1136. this._lastIntValue = cp;
  1137. this.onCharacter(start, this.index, this._lastIntValue);
  1138. return true;
  1139. }
  1140. if (this.eat(ReverseSolidus)) {
  1141. if (this.consumeClassEscape()) {
  1142. return true;
  1143. }
  1144. if (!this.strict && this.currentCodePoint === LatinSmallLetterC) {
  1145. this._lastIntValue = ReverseSolidus;
  1146. this.onCharacter(start, this.index, this._lastIntValue);
  1147. return true;
  1148. }
  1149. if (this.strict || this._uFlag) {
  1150. this.raise("Invalid escape");
  1151. }
  1152. this.rewind(start);
  1153. }
  1154. return false;
  1155. }
  1156. consumeClassEscape() {
  1157. const start = this.index;
  1158. if (this.eat(LatinSmallLetterB)) {
  1159. this._lastIntValue = Backspace;
  1160. this.onCharacter(start - 1, this.index, this._lastIntValue);
  1161. return true;
  1162. }
  1163. if (this._uFlag && this.eat(HyphenMinus)) {
  1164. this._lastIntValue = HyphenMinus;
  1165. this.onCharacter(start - 1, this.index, this._lastIntValue);
  1166. return true;
  1167. }
  1168. let cp = 0;
  1169. if (!this.strict &&
  1170. !this._uFlag &&
  1171. this.currentCodePoint === LatinSmallLetterC &&
  1172. (isDecimalDigit((cp = this.nextCodePoint)) || cp === LowLine)) {
  1173. this.advance();
  1174. this.advance();
  1175. this._lastIntValue = cp % 0x20;
  1176. this.onCharacter(start - 1, this.index, this._lastIntValue);
  1177. return true;
  1178. }
  1179. return (this.consumeCharacterClassEscape() || this.consumeCharacterEscape());
  1180. }
  1181. eatGroupName() {
  1182. if (this.eat(LessThanSign)) {
  1183. if (this.eatRegExpIdentifierName() && this.eat(GreaterThanSign)) {
  1184. return true;
  1185. }
  1186. this.raise("Invalid capture group name");
  1187. }
  1188. return false;
  1189. }
  1190. eatRegExpIdentifierName() {
  1191. if (this.eatRegExpIdentifierStart()) {
  1192. this._lastStrValue = String.fromCodePoint(this._lastIntValue);
  1193. while (this.eatRegExpIdentifierPart()) {
  1194. this._lastStrValue += String.fromCodePoint(this._lastIntValue);
  1195. }
  1196. return true;
  1197. }
  1198. return false;
  1199. }
  1200. eatRegExpIdentifierStart() {
  1201. const start = this.index;
  1202. const forceUFlag = !this._uFlag && this.ecmaVersion >= 2020;
  1203. let cp = this.currentCodePoint;
  1204. this.advance();
  1205. if (cp === ReverseSolidus &&
  1206. this.eatRegExpUnicodeEscapeSequence(forceUFlag)) {
  1207. cp = this._lastIntValue;
  1208. }
  1209. else if (forceUFlag &&
  1210. isLeadSurrogate(cp) &&
  1211. isTrailSurrogate(this.currentCodePoint)) {
  1212. cp = combineSurrogatePair(cp, this.currentCodePoint);
  1213. this.advance();
  1214. }
  1215. if (isRegExpIdentifierStart(cp)) {
  1216. this._lastIntValue = cp;
  1217. return true;
  1218. }
  1219. if (this.index !== start) {
  1220. this.rewind(start);
  1221. }
  1222. return false;
  1223. }
  1224. eatRegExpIdentifierPart() {
  1225. const start = this.index;
  1226. const forceUFlag = !this._uFlag && this.ecmaVersion >= 2020;
  1227. let cp = this.currentCodePoint;
  1228. this.advance();
  1229. if (cp === ReverseSolidus &&
  1230. this.eatRegExpUnicodeEscapeSequence(forceUFlag)) {
  1231. cp = this._lastIntValue;
  1232. }
  1233. else if (forceUFlag &&
  1234. isLeadSurrogate(cp) &&
  1235. isTrailSurrogate(this.currentCodePoint)) {
  1236. cp = combineSurrogatePair(cp, this.currentCodePoint);
  1237. this.advance();
  1238. }
  1239. if (isRegExpIdentifierPart(cp)) {
  1240. this._lastIntValue = cp;
  1241. return true;
  1242. }
  1243. if (this.index !== start) {
  1244. this.rewind(start);
  1245. }
  1246. return false;
  1247. }
  1248. eatCControlLetter() {
  1249. const start = this.index;
  1250. if (this.eat(LatinSmallLetterC)) {
  1251. if (this.eatControlLetter()) {
  1252. return true;
  1253. }
  1254. this.rewind(start);
  1255. }
  1256. return false;
  1257. }
  1258. eatZero() {
  1259. if (this.currentCodePoint === DigitZero &&
  1260. !isDecimalDigit(this.nextCodePoint)) {
  1261. this._lastIntValue = 0;
  1262. this.advance();
  1263. return true;
  1264. }
  1265. return false;
  1266. }
  1267. eatControlEscape() {
  1268. if (this.eat(LatinSmallLetterF)) {
  1269. this._lastIntValue = FormFeed;
  1270. return true;
  1271. }
  1272. if (this.eat(LatinSmallLetterN)) {
  1273. this._lastIntValue = LineFeed;
  1274. return true;
  1275. }
  1276. if (this.eat(LatinSmallLetterR)) {
  1277. this._lastIntValue = CarriageReturn;
  1278. return true;
  1279. }
  1280. if (this.eat(LatinSmallLetterT)) {
  1281. this._lastIntValue = CharacterTabulation;
  1282. return true;
  1283. }
  1284. if (this.eat(LatinSmallLetterV)) {
  1285. this._lastIntValue = LineTabulation;
  1286. return true;
  1287. }
  1288. return false;
  1289. }
  1290. eatControlLetter() {
  1291. const cp = this.currentCodePoint;
  1292. if (isLatinLetter(cp)) {
  1293. this.advance();
  1294. this._lastIntValue = cp % 0x20;
  1295. return true;
  1296. }
  1297. return false;
  1298. }
  1299. eatRegExpUnicodeEscapeSequence(forceUFlag = false) {
  1300. const start = this.index;
  1301. const uFlag = forceUFlag || this._uFlag;
  1302. if (this.eat(LatinSmallLetterU)) {
  1303. if ((uFlag && this.eatRegExpUnicodeSurrogatePairEscape()) ||
  1304. this.eatFixedHexDigits(4) ||
  1305. (uFlag && this.eatRegExpUnicodeCodePointEscape())) {
  1306. return true;
  1307. }
  1308. if (this.strict || uFlag) {
  1309. this.raise("Invalid unicode escape");
  1310. }
  1311. this.rewind(start);
  1312. }
  1313. return false;
  1314. }
  1315. eatRegExpUnicodeSurrogatePairEscape() {
  1316. const start = this.index;
  1317. if (this.eatFixedHexDigits(4)) {
  1318. const lead = this._lastIntValue;
  1319. if (isLeadSurrogate(lead) &&
  1320. this.eat(ReverseSolidus) &&
  1321. this.eat(LatinSmallLetterU) &&
  1322. this.eatFixedHexDigits(4)) {
  1323. const trail = this._lastIntValue;
  1324. if (isTrailSurrogate(trail)) {
  1325. this._lastIntValue = combineSurrogatePair(lead, trail);
  1326. return true;
  1327. }
  1328. }
  1329. this.rewind(start);
  1330. }
  1331. return false;
  1332. }
  1333. eatRegExpUnicodeCodePointEscape() {
  1334. const start = this.index;
  1335. if (this.eat(LeftCurlyBracket) &&
  1336. this.eatHexDigits() &&
  1337. this.eat(RightCurlyBracket) &&
  1338. isValidUnicode(this._lastIntValue)) {
  1339. return true;
  1340. }
  1341. this.rewind(start);
  1342. return false;
  1343. }
  1344. eatIdentityEscape() {
  1345. const cp = this.currentCodePoint;
  1346. if (this.isValidIdentityEscape(cp)) {
  1347. this._lastIntValue = cp;
  1348. this.advance();
  1349. return true;
  1350. }
  1351. return false;
  1352. }
  1353. isValidIdentityEscape(cp) {
  1354. if (cp === -1) {
  1355. return false;
  1356. }
  1357. if (this._uFlag) {
  1358. return isSyntaxCharacter(cp) || cp === Solidus;
  1359. }
  1360. if (this.strict) {
  1361. return !isIdContinue(cp);
  1362. }
  1363. if (this._nFlag) {
  1364. return !(cp === LatinSmallLetterC || cp === LatinSmallLetterK);
  1365. }
  1366. return cp !== LatinSmallLetterC;
  1367. }
  1368. eatDecimalEscape() {
  1369. this._lastIntValue = 0;
  1370. let cp = this.currentCodePoint;
  1371. if (cp >= DigitOne && cp <= DigitNine) {
  1372. do {
  1373. this._lastIntValue = 10 * this._lastIntValue + (cp - DigitZero);
  1374. this.advance();
  1375. } while ((cp = this.currentCodePoint) >= DigitZero &&
  1376. cp <= DigitNine);
  1377. return true;
  1378. }
  1379. return false;
  1380. }
  1381. eatUnicodePropertyValueExpression() {
  1382. const start = this.index;
  1383. if (this.eatUnicodePropertyName() && this.eat(EqualsSign)) {
  1384. this._lastKeyValue = this._lastStrValue;
  1385. if (this.eatUnicodePropertyValue()) {
  1386. this._lastValValue = this._lastStrValue;
  1387. if (isValidUnicodeProperty(this.ecmaVersion, this._lastKeyValue, this._lastValValue)) {
  1388. return true;
  1389. }
  1390. this.raise("Invalid property name");
  1391. }
  1392. }
  1393. this.rewind(start);
  1394. if (this.eatLoneUnicodePropertyNameOrValue()) {
  1395. const nameOrValue = this._lastStrValue;
  1396. if (isValidUnicodeProperty(this.ecmaVersion, "General_Category", nameOrValue)) {
  1397. this._lastKeyValue = "General_Category";
  1398. this._lastValValue = nameOrValue;
  1399. return true;
  1400. }
  1401. if (isValidLoneUnicodeProperty(this.ecmaVersion, nameOrValue)) {
  1402. this._lastKeyValue = nameOrValue;
  1403. this._lastValValue = "";
  1404. return true;
  1405. }
  1406. this.raise("Invalid property name");
  1407. }
  1408. return false;
  1409. }
  1410. eatUnicodePropertyName() {
  1411. this._lastStrValue = "";
  1412. while (isUnicodePropertyNameCharacter(this.currentCodePoint)) {
  1413. this._lastStrValue += String.fromCodePoint(this.currentCodePoint);
  1414. this.advance();
  1415. }
  1416. return this._lastStrValue !== "";
  1417. }
  1418. eatUnicodePropertyValue() {
  1419. this._lastStrValue = "";
  1420. while (isUnicodePropertyValueCharacter(this.currentCodePoint)) {
  1421. this._lastStrValue += String.fromCodePoint(this.currentCodePoint);
  1422. this.advance();
  1423. }
  1424. return this._lastStrValue !== "";
  1425. }
  1426. eatLoneUnicodePropertyNameOrValue() {
  1427. return this.eatUnicodePropertyValue();
  1428. }
  1429. eatHexEscapeSequence() {
  1430. const start = this.index;
  1431. if (this.eat(LatinSmallLetterX)) {
  1432. if (this.eatFixedHexDigits(2)) {
  1433. return true;
  1434. }
  1435. if (this._uFlag || this.strict) {
  1436. this.raise("Invalid escape");
  1437. }
  1438. this.rewind(start);
  1439. }
  1440. return false;
  1441. }
  1442. eatDecimalDigits() {
  1443. const start = this.index;
  1444. this._lastIntValue = 0;
  1445. while (isDecimalDigit(this.currentCodePoint)) {
  1446. this._lastIntValue =
  1447. 10 * this._lastIntValue + digitToInt(this.currentCodePoint);
  1448. this.advance();
  1449. }
  1450. return this.index !== start;
  1451. }
  1452. eatHexDigits() {
  1453. const start = this.index;
  1454. this._lastIntValue = 0;
  1455. while (isHexDigit(this.currentCodePoint)) {
  1456. this._lastIntValue =
  1457. 16 * this._lastIntValue + digitToInt(this.currentCodePoint);
  1458. this.advance();
  1459. }
  1460. return this.index !== start;
  1461. }
  1462. eatLegacyOctalEscapeSequence() {
  1463. if (this.eatOctalDigit()) {
  1464. const n1 = this._lastIntValue;
  1465. if (this.eatOctalDigit()) {
  1466. const n2 = this._lastIntValue;
  1467. if (n1 <= 3 && this.eatOctalDigit()) {
  1468. this._lastIntValue = n1 * 64 + n2 * 8 + this._lastIntValue;
  1469. }
  1470. else {
  1471. this._lastIntValue = n1 * 8 + n2;
  1472. }
  1473. }
  1474. else {
  1475. this._lastIntValue = n1;
  1476. }
  1477. return true;
  1478. }
  1479. return false;
  1480. }
  1481. eatOctalDigit() {
  1482. const cp = this.currentCodePoint;
  1483. if (isOctalDigit(cp)) {
  1484. this.advance();
  1485. this._lastIntValue = cp - DigitZero;
  1486. return true;
  1487. }
  1488. this._lastIntValue = 0;
  1489. return false;
  1490. }
  1491. eatFixedHexDigits(length) {
  1492. const start = this.index;
  1493. this._lastIntValue = 0;
  1494. for (let i = 0; i < length; ++i) {
  1495. const cp = this.currentCodePoint;
  1496. if (!isHexDigit(cp)) {
  1497. this.rewind(start);
  1498. return false;
  1499. }
  1500. this._lastIntValue = 16 * this._lastIntValue + digitToInt(cp);
  1501. this.advance();
  1502. }
  1503. return true;
  1504. }
  1505. }
  1506. const DummyPattern = {};
  1507. const DummyFlags = {};
  1508. const DummyCapturingGroup = {};
  1509. class RegExpParserState {
  1510. constructor(options) {
  1511. this._node = DummyPattern;
  1512. this._flags = DummyFlags;
  1513. this._backreferences = [];
  1514. this._capturingGroups = [];
  1515. this.source = "";
  1516. this.strict = Boolean(options && options.strict);
  1517. this.ecmaVersion = (options && options.ecmaVersion) || 2022;
  1518. }
  1519. get pattern() {
  1520. if (this._node.type !== "Pattern") {
  1521. throw new Error("UnknownError");
  1522. }
  1523. return this._node;
  1524. }
  1525. get flags() {
  1526. if (this._flags.type !== "Flags") {
  1527. throw new Error("UnknownError");
  1528. }
  1529. return this._flags;
  1530. }
  1531. onFlags(start, end, global, ignoreCase, multiline, unicode, sticky, dotAll, hasIndices) {
  1532. this._flags = {
  1533. type: "Flags",
  1534. parent: null,
  1535. start,
  1536. end,
  1537. raw: this.source.slice(start, end),
  1538. global,
  1539. ignoreCase,
  1540. multiline,
  1541. unicode,
  1542. sticky,
  1543. dotAll,
  1544. hasIndices,
  1545. };
  1546. }
  1547. onPatternEnter(start) {
  1548. this._node = {
  1549. type: "Pattern",
  1550. parent: null,
  1551. start,
  1552. end: start,
  1553. raw: "",
  1554. alternatives: [],
  1555. };
  1556. this._backreferences.length = 0;
  1557. this._capturingGroups.length = 0;
  1558. }
  1559. onPatternLeave(start, end) {
  1560. this._node.end = end;
  1561. this._node.raw = this.source.slice(start, end);
  1562. for (const reference of this._backreferences) {
  1563. const ref = reference.ref;
  1564. const group = typeof ref === "number"
  1565. ? this._capturingGroups[ref - 1]
  1566. : this._capturingGroups.find(g => g.name === ref);
  1567. reference.resolved = group;
  1568. group.references.push(reference);
  1569. }
  1570. }
  1571. onAlternativeEnter(start) {
  1572. const parent = this._node;
  1573. if (parent.type !== "Assertion" &&
  1574. parent.type !== "CapturingGroup" &&
  1575. parent.type !== "Group" &&
  1576. parent.type !== "Pattern") {
  1577. throw new Error("UnknownError");
  1578. }
  1579. this._node = {
  1580. type: "Alternative",
  1581. parent,
  1582. start,
  1583. end: start,
  1584. raw: "",
  1585. elements: [],
  1586. };
  1587. parent.alternatives.push(this._node);
  1588. }
  1589. onAlternativeLeave(start, end) {
  1590. const node = this._node;
  1591. if (node.type !== "Alternative") {
  1592. throw new Error("UnknownError");
  1593. }
  1594. node.end = end;
  1595. node.raw = this.source.slice(start, end);
  1596. this._node = node.parent;
  1597. }
  1598. onGroupEnter(start) {
  1599. const parent = this._node;
  1600. if (parent.type !== "Alternative") {
  1601. throw new Error("UnknownError");
  1602. }
  1603. this._node = {
  1604. type: "Group",
  1605. parent,
  1606. start,
  1607. end: start,
  1608. raw: "",
  1609. alternatives: [],
  1610. };
  1611. parent.elements.push(this._node);
  1612. }
  1613. onGroupLeave(start, end) {
  1614. const node = this._node;
  1615. if (node.type !== "Group" || node.parent.type !== "Alternative") {
  1616. throw new Error("UnknownError");
  1617. }
  1618. node.end = end;
  1619. node.raw = this.source.slice(start, end);
  1620. this._node = node.parent;
  1621. }
  1622. onCapturingGroupEnter(start, name) {
  1623. const parent = this._node;
  1624. if (parent.type !== "Alternative") {
  1625. throw new Error("UnknownError");
  1626. }
  1627. this._node = {
  1628. type: "CapturingGroup",
  1629. parent,
  1630. start,
  1631. end: start,
  1632. raw: "",
  1633. name,
  1634. alternatives: [],
  1635. references: [],
  1636. };
  1637. parent.elements.push(this._node);
  1638. this._capturingGroups.push(this._node);
  1639. }
  1640. onCapturingGroupLeave(start, end) {
  1641. const node = this._node;
  1642. if (node.type !== "CapturingGroup" ||
  1643. node.parent.type !== "Alternative") {
  1644. throw new Error("UnknownError");
  1645. }
  1646. node.end = end;
  1647. node.raw = this.source.slice(start, end);
  1648. this._node = node.parent;
  1649. }
  1650. onQuantifier(start, end, min, max, greedy) {
  1651. const parent = this._node;
  1652. if (parent.type !== "Alternative") {
  1653. throw new Error("UnknownError");
  1654. }
  1655. const element = parent.elements.pop();
  1656. if (element == null ||
  1657. element.type === "Quantifier" ||
  1658. (element.type === "Assertion" && element.kind !== "lookahead")) {
  1659. throw new Error("UnknownError");
  1660. }
  1661. const node = {
  1662. type: "Quantifier",
  1663. parent,
  1664. start: element.start,
  1665. end,
  1666. raw: this.source.slice(element.start, end),
  1667. min,
  1668. max,
  1669. greedy,
  1670. element,
  1671. };
  1672. parent.elements.push(node);
  1673. element.parent = node;
  1674. }
  1675. onLookaroundAssertionEnter(start, kind, negate) {
  1676. const parent = this._node;
  1677. if (parent.type !== "Alternative") {
  1678. throw new Error("UnknownError");
  1679. }
  1680. const node = (this._node = {
  1681. type: "Assertion",
  1682. parent,
  1683. start,
  1684. end: start,
  1685. raw: "",
  1686. kind,
  1687. negate,
  1688. alternatives: [],
  1689. });
  1690. parent.elements.push(node);
  1691. }
  1692. onLookaroundAssertionLeave(start, end) {
  1693. const node = this._node;
  1694. if (node.type !== "Assertion" || node.parent.type !== "Alternative") {
  1695. throw new Error("UnknownError");
  1696. }
  1697. node.end = end;
  1698. node.raw = this.source.slice(start, end);
  1699. this._node = node.parent;
  1700. }
  1701. onEdgeAssertion(start, end, kind) {
  1702. const parent = this._node;
  1703. if (parent.type !== "Alternative") {
  1704. throw new Error("UnknownError");
  1705. }
  1706. parent.elements.push({
  1707. type: "Assertion",
  1708. parent,
  1709. start,
  1710. end,
  1711. raw: this.source.slice(start, end),
  1712. kind,
  1713. });
  1714. }
  1715. onWordBoundaryAssertion(start, end, kind, negate) {
  1716. const parent = this._node;
  1717. if (parent.type !== "Alternative") {
  1718. throw new Error("UnknownError");
  1719. }
  1720. parent.elements.push({
  1721. type: "Assertion",
  1722. parent,
  1723. start,
  1724. end,
  1725. raw: this.source.slice(start, end),
  1726. kind,
  1727. negate,
  1728. });
  1729. }
  1730. onAnyCharacterSet(start, end, kind) {
  1731. const parent = this._node;
  1732. if (parent.type !== "Alternative") {
  1733. throw new Error("UnknownError");
  1734. }
  1735. parent.elements.push({
  1736. type: "CharacterSet",
  1737. parent,
  1738. start,
  1739. end,
  1740. raw: this.source.slice(start, end),
  1741. kind,
  1742. });
  1743. }
  1744. onEscapeCharacterSet(start, end, kind, negate) {
  1745. const parent = this._node;
  1746. if (parent.type !== "Alternative" && parent.type !== "CharacterClass") {
  1747. throw new Error("UnknownError");
  1748. }
  1749. parent.elements.push({
  1750. type: "CharacterSet",
  1751. parent,
  1752. start,
  1753. end,
  1754. raw: this.source.slice(start, end),
  1755. kind,
  1756. negate,
  1757. });
  1758. }
  1759. onUnicodePropertyCharacterSet(start, end, kind, key, value, negate) {
  1760. const parent = this._node;
  1761. if (parent.type !== "Alternative" && parent.type !== "CharacterClass") {
  1762. throw new Error("UnknownError");
  1763. }
  1764. parent.elements.push({
  1765. type: "CharacterSet",
  1766. parent,
  1767. start,
  1768. end,
  1769. raw: this.source.slice(start, end),
  1770. kind,
  1771. key,
  1772. value,
  1773. negate,
  1774. });
  1775. }
  1776. onCharacter(start, end, value) {
  1777. const parent = this._node;
  1778. if (parent.type !== "Alternative" && parent.type !== "CharacterClass") {
  1779. throw new Error("UnknownError");
  1780. }
  1781. parent.elements.push({
  1782. type: "Character",
  1783. parent,
  1784. start,
  1785. end,
  1786. raw: this.source.slice(start, end),
  1787. value,
  1788. });
  1789. }
  1790. onBackreference(start, end, ref) {
  1791. const parent = this._node;
  1792. if (parent.type !== "Alternative") {
  1793. throw new Error("UnknownError");
  1794. }
  1795. const node = {
  1796. type: "Backreference",
  1797. parent,
  1798. start,
  1799. end,
  1800. raw: this.source.slice(start, end),
  1801. ref,
  1802. resolved: DummyCapturingGroup,
  1803. };
  1804. parent.elements.push(node);
  1805. this._backreferences.push(node);
  1806. }
  1807. onCharacterClassEnter(start, negate) {
  1808. const parent = this._node;
  1809. if (parent.type !== "Alternative") {
  1810. throw new Error("UnknownError");
  1811. }
  1812. this._node = {
  1813. type: "CharacterClass",
  1814. parent,
  1815. start,
  1816. end: start,
  1817. raw: "",
  1818. negate,
  1819. elements: [],
  1820. };
  1821. parent.elements.push(this._node);
  1822. }
  1823. onCharacterClassLeave(start, end) {
  1824. const node = this._node;
  1825. if (node.type !== "CharacterClass" ||
  1826. node.parent.type !== "Alternative") {
  1827. throw new Error("UnknownError");
  1828. }
  1829. node.end = end;
  1830. node.raw = this.source.slice(start, end);
  1831. this._node = node.parent;
  1832. }
  1833. onCharacterClassRange(start, end) {
  1834. const parent = this._node;
  1835. if (parent.type !== "CharacterClass") {
  1836. throw new Error("UnknownError");
  1837. }
  1838. const elements = parent.elements;
  1839. const max = elements.pop();
  1840. const hyphen = elements.pop();
  1841. const min = elements.pop();
  1842. if (!min ||
  1843. !max ||
  1844. !hyphen ||
  1845. min.type !== "Character" ||
  1846. max.type !== "Character" ||
  1847. hyphen.type !== "Character" ||
  1848. hyphen.value !== HyphenMinus) {
  1849. throw new Error("UnknownError");
  1850. }
  1851. const node = {
  1852. type: "CharacterClassRange",
  1853. parent,
  1854. start,
  1855. end,
  1856. raw: this.source.slice(start, end),
  1857. min,
  1858. max,
  1859. };
  1860. min.parent = node;
  1861. max.parent = node;
  1862. elements.push(node);
  1863. }
  1864. }
  1865. class RegExpParser {
  1866. constructor(options) {
  1867. this._state = new RegExpParserState(options);
  1868. this._validator = new RegExpValidator(this._state);
  1869. }
  1870. parseLiteral(source, start = 0, end = source.length) {
  1871. this._state.source = source;
  1872. this._validator.validateLiteral(source, start, end);
  1873. const pattern = this._state.pattern;
  1874. const flags = this._state.flags;
  1875. const literal = {
  1876. type: "RegExpLiteral",
  1877. parent: null,
  1878. start,
  1879. end,
  1880. raw: source,
  1881. pattern,
  1882. flags,
  1883. };
  1884. pattern.parent = literal;
  1885. flags.parent = literal;
  1886. return literal;
  1887. }
  1888. parseFlags(source, start = 0, end = source.length) {
  1889. this._state.source = source;
  1890. this._validator.validateFlags(source, start, end);
  1891. return this._state.flags;
  1892. }
  1893. parsePattern(source, start = 0, end = source.length, uFlag = false) {
  1894. this._state.source = source;
  1895. this._validator.validatePattern(source, start, end, uFlag);
  1896. return this._state.pattern;
  1897. }
  1898. }
  1899. class RegExpVisitor {
  1900. constructor(handlers) {
  1901. this._handlers = handlers;
  1902. }
  1903. visit(node) {
  1904. switch (node.type) {
  1905. case "Alternative":
  1906. this.visitAlternative(node);
  1907. break;
  1908. case "Assertion":
  1909. this.visitAssertion(node);
  1910. break;
  1911. case "Backreference":
  1912. this.visitBackreference(node);
  1913. break;
  1914. case "CapturingGroup":
  1915. this.visitCapturingGroup(node);
  1916. break;
  1917. case "Character":
  1918. this.visitCharacter(node);
  1919. break;
  1920. case "CharacterClass":
  1921. this.visitCharacterClass(node);
  1922. break;
  1923. case "CharacterClassRange":
  1924. this.visitCharacterClassRange(node);
  1925. break;
  1926. case "CharacterSet":
  1927. this.visitCharacterSet(node);
  1928. break;
  1929. case "Flags":
  1930. this.visitFlags(node);
  1931. break;
  1932. case "Group":
  1933. this.visitGroup(node);
  1934. break;
  1935. case "Pattern":
  1936. this.visitPattern(node);
  1937. break;
  1938. case "Quantifier":
  1939. this.visitQuantifier(node);
  1940. break;
  1941. case "RegExpLiteral":
  1942. this.visitRegExpLiteral(node);
  1943. break;
  1944. default:
  1945. throw new Error(`Unknown type: ${node.type}`);
  1946. }
  1947. }
  1948. visitAlternative(node) {
  1949. if (this._handlers.onAlternativeEnter) {
  1950. this._handlers.onAlternativeEnter(node);
  1951. }
  1952. node.elements.forEach(this.visit, this);
  1953. if (this._handlers.onAlternativeLeave) {
  1954. this._handlers.onAlternativeLeave(node);
  1955. }
  1956. }
  1957. visitAssertion(node) {
  1958. if (this._handlers.onAssertionEnter) {
  1959. this._handlers.onAssertionEnter(node);
  1960. }
  1961. if (node.kind === "lookahead" || node.kind === "lookbehind") {
  1962. node.alternatives.forEach(this.visit, this);
  1963. }
  1964. if (this._handlers.onAssertionLeave) {
  1965. this._handlers.onAssertionLeave(node);
  1966. }
  1967. }
  1968. visitBackreference(node) {
  1969. if (this._handlers.onBackreferenceEnter) {
  1970. this._handlers.onBackreferenceEnter(node);
  1971. }
  1972. if (this._handlers.onBackreferenceLeave) {
  1973. this._handlers.onBackreferenceLeave(node);
  1974. }
  1975. }
  1976. visitCapturingGroup(node) {
  1977. if (this._handlers.onCapturingGroupEnter) {
  1978. this._handlers.onCapturingGroupEnter(node);
  1979. }
  1980. node.alternatives.forEach(this.visit, this);
  1981. if (this._handlers.onCapturingGroupLeave) {
  1982. this._handlers.onCapturingGroupLeave(node);
  1983. }
  1984. }
  1985. visitCharacter(node) {
  1986. if (this._handlers.onCharacterEnter) {
  1987. this._handlers.onCharacterEnter(node);
  1988. }
  1989. if (this._handlers.onCharacterLeave) {
  1990. this._handlers.onCharacterLeave(node);
  1991. }
  1992. }
  1993. visitCharacterClass(node) {
  1994. if (this._handlers.onCharacterClassEnter) {
  1995. this._handlers.onCharacterClassEnter(node);
  1996. }
  1997. node.elements.forEach(this.visit, this);
  1998. if (this._handlers.onCharacterClassLeave) {
  1999. this._handlers.onCharacterClassLeave(node);
  2000. }
  2001. }
  2002. visitCharacterClassRange(node) {
  2003. if (this._handlers.onCharacterClassRangeEnter) {
  2004. this._handlers.onCharacterClassRangeEnter(node);
  2005. }
  2006. this.visitCharacter(node.min);
  2007. this.visitCharacter(node.max);
  2008. if (this._handlers.onCharacterClassRangeLeave) {
  2009. this._handlers.onCharacterClassRangeLeave(node);
  2010. }
  2011. }
  2012. visitCharacterSet(node) {
  2013. if (this._handlers.onCharacterSetEnter) {
  2014. this._handlers.onCharacterSetEnter(node);
  2015. }
  2016. if (this._handlers.onCharacterSetLeave) {
  2017. this._handlers.onCharacterSetLeave(node);
  2018. }
  2019. }
  2020. visitFlags(node) {
  2021. if (this._handlers.onFlagsEnter) {
  2022. this._handlers.onFlagsEnter(node);
  2023. }
  2024. if (this._handlers.onFlagsLeave) {
  2025. this._handlers.onFlagsLeave(node);
  2026. }
  2027. }
  2028. visitGroup(node) {
  2029. if (this._handlers.onGroupEnter) {
  2030. this._handlers.onGroupEnter(node);
  2031. }
  2032. node.alternatives.forEach(this.visit, this);
  2033. if (this._handlers.onGroupLeave) {
  2034. this._handlers.onGroupLeave(node);
  2035. }
  2036. }
  2037. visitPattern(node) {
  2038. if (this._handlers.onPatternEnter) {
  2039. this._handlers.onPatternEnter(node);
  2040. }
  2041. node.alternatives.forEach(this.visit, this);
  2042. if (this._handlers.onPatternLeave) {
  2043. this._handlers.onPatternLeave(node);
  2044. }
  2045. }
  2046. visitQuantifier(node) {
  2047. if (this._handlers.onQuantifierEnter) {
  2048. this._handlers.onQuantifierEnter(node);
  2049. }
  2050. this.visit(node.element);
  2051. if (this._handlers.onQuantifierLeave) {
  2052. this._handlers.onQuantifierLeave(node);
  2053. }
  2054. }
  2055. visitRegExpLiteral(node) {
  2056. if (this._handlers.onRegExpLiteralEnter) {
  2057. this._handlers.onRegExpLiteralEnter(node);
  2058. }
  2059. this.visitPattern(node.pattern);
  2060. this.visitFlags(node.flags);
  2061. if (this._handlers.onRegExpLiteralLeave) {
  2062. this._handlers.onRegExpLiteralLeave(node);
  2063. }
  2064. }
  2065. }
  2066. function parseRegExpLiteral(source, options) {
  2067. return new RegExpParser(options).parseLiteral(String(source));
  2068. }
  2069. function validateRegExpLiteral(source, options) {
  2070. return new RegExpValidator(options).validateLiteral(source);
  2071. }
  2072. function visitRegExpAST(node, handlers) {
  2073. new RegExpVisitor(handlers).visit(node);
  2074. }
  2075. exports.AST = ast;
  2076. exports.RegExpParser = RegExpParser;
  2077. exports.RegExpValidator = RegExpValidator;
  2078. exports.parseRegExpLiteral = parseRegExpLiteral;
  2079. exports.validateRegExpLiteral = validateRegExpLiteral;
  2080. exports.visitRegExpAST = visitRegExpAST;
  2081. //# sourceMappingURL=index.js.map