acorn.js 228 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065
  1. (function (global, factory) {
  2. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
  3. typeof define === 'function' && define.amd ? define(['exports'], factory) :
  4. (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.acorn = {}));
  5. })(this, (function (exports) { 'use strict';
  6. // This file was generated. Do not modify manually!
  7. var astralIdentifierCodes = [509, 0, 227, 0, 150, 4, 294, 9, 1368, 2, 2, 1, 6, 3, 41, 2, 5, 0, 166, 1, 574, 3, 9, 9, 370, 1, 81, 2, 71, 10, 50, 3, 123, 2, 54, 14, 32, 10, 3, 1, 11, 3, 46, 10, 8, 0, 46, 9, 7, 2, 37, 13, 2, 9, 6, 1, 45, 0, 13, 2, 49, 13, 9, 3, 2, 11, 83, 11, 7, 0, 3, 0, 158, 11, 6, 9, 7, 3, 56, 1, 2, 6, 3, 1, 3, 2, 10, 0, 11, 1, 3, 6, 4, 4, 193, 17, 10, 9, 5, 0, 82, 19, 13, 9, 214, 6, 3, 8, 28, 1, 83, 16, 16, 9, 82, 12, 9, 9, 84, 14, 5, 9, 243, 14, 166, 9, 71, 5, 2, 1, 3, 3, 2, 0, 2, 1, 13, 9, 120, 6, 3, 6, 4, 0, 29, 9, 41, 6, 2, 3, 9, 0, 10, 10, 47, 15, 406, 7, 2, 7, 17, 9, 57, 21, 2, 13, 123, 5, 4, 0, 2, 1, 2, 6, 2, 0, 9, 9, 49, 4, 2, 1, 2, 4, 9, 9, 330, 3, 10, 1, 2, 0, 49, 6, 4, 4, 14, 9, 5351, 0, 7, 14, 13835, 9, 87, 9, 39, 4, 60, 6, 26, 9, 1014, 0, 2, 54, 8, 3, 82, 0, 12, 1, 19628, 1, 4706, 45, 3, 22, 543, 4, 4, 5, 9, 7, 3, 6, 31, 3, 149, 2, 1418, 49, 513, 54, 5, 49, 9, 0, 15, 0, 23, 4, 2, 14, 1361, 6, 2, 16, 3, 6, 2, 1, 2, 4, 101, 0, 161, 6, 10, 9, 357, 0, 62, 13, 499, 13, 983, 6, 110, 6, 6, 9, 4759, 9, 787719, 239];
  8. // This file was generated. Do not modify manually!
  9. var astralIdentifierStartCodes = [0, 11, 2, 25, 2, 18, 2, 1, 2, 14, 3, 13, 35, 122, 70, 52, 268, 28, 4, 48, 48, 31, 14, 29, 6, 37, 11, 29, 3, 35, 5, 7, 2, 4, 43, 157, 19, 35, 5, 35, 5, 39, 9, 51, 13, 10, 2, 14, 2, 6, 2, 1, 2, 10, 2, 14, 2, 6, 2, 1, 68, 310, 10, 21, 11, 7, 25, 5, 2, 41, 2, 8, 70, 5, 3, 0, 2, 43, 2, 1, 4, 0, 3, 22, 11, 22, 10, 30, 66, 18, 2, 1, 11, 21, 11, 25, 71, 55, 7, 1, 65, 0, 16, 3, 2, 2, 2, 28, 43, 28, 4, 28, 36, 7, 2, 27, 28, 53, 11, 21, 11, 18, 14, 17, 111, 72, 56, 50, 14, 50, 14, 35, 349, 41, 7, 1, 79, 28, 11, 0, 9, 21, 43, 17, 47, 20, 28, 22, 13, 52, 58, 1, 3, 0, 14, 44, 33, 24, 27, 35, 30, 0, 3, 0, 9, 34, 4, 0, 13, 47, 15, 3, 22, 0, 2, 0, 36, 17, 2, 24, 20, 1, 64, 6, 2, 0, 2, 3, 2, 14, 2, 9, 8, 46, 39, 7, 3, 1, 3, 21, 2, 6, 2, 1, 2, 4, 4, 0, 19, 0, 13, 4, 159, 52, 19, 3, 21, 2, 31, 47, 21, 1, 2, 0, 185, 46, 42, 3, 37, 47, 21, 0, 60, 42, 14, 0, 72, 26, 38, 6, 186, 43, 117, 63, 32, 7, 3, 0, 3, 7, 2, 1, 2, 23, 16, 0, 2, 0, 95, 7, 3, 38, 17, 0, 2, 0, 29, 0, 11, 39, 8, 0, 22, 0, 12, 45, 20, 0, 19, 72, 264, 8, 2, 36, 18, 0, 50, 29, 113, 6, 2, 1, 2, 37, 22, 0, 26, 5, 2, 1, 2, 31, 15, 0, 328, 18, 16, 0, 2, 12, 2, 33, 125, 0, 80, 921, 103, 110, 18, 195, 2637, 96, 16, 1071, 18, 5, 4026, 582, 8634, 568, 8, 30, 18, 78, 18, 29, 19, 47, 17, 3, 32, 20, 6, 18, 689, 63, 129, 74, 6, 0, 67, 12, 65, 1, 2, 0, 29, 6135, 9, 1237, 43, 8, 8936, 3, 2, 6, 2, 1, 2, 290, 16, 0, 30, 2, 3, 0, 15, 3, 9, 395, 2309, 106, 6, 12, 4, 8, 8, 9, 5991, 84, 2, 70, 2, 1, 3, 0, 3, 1, 3, 3, 2, 11, 2, 0, 2, 6, 2, 64, 2, 3, 3, 7, 2, 6, 2, 27, 2, 3, 2, 4, 2, 0, 4, 6, 2, 339, 3, 24, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 7, 1845, 30, 7, 5, 262, 61, 147, 44, 11, 6, 17, 0, 322, 29, 19, 43, 485, 27, 757, 6, 2, 3, 2, 1, 2, 14, 2, 196, 60, 67, 8, 0, 1205, 3, 2, 26, 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, 16, 6, 2, 2, 4, 2, 16, 4421, 42719, 33, 4153, 7, 221, 3, 5761, 15, 7472, 16, 621, 2467, 541, 1507, 4938, 6, 4191];
  10. // This file was generated. Do not modify manually!
  11. var nonASCIIidentifierChars = "\u200c\u200d\xb7\u0300-\u036f\u0387\u0483-\u0487\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u0610-\u061a\u064b-\u0669\u0670\u06d6-\u06dc\u06df-\u06e4\u06e7\u06e8\u06ea-\u06ed\u06f0-\u06f9\u0711\u0730-\u074a\u07a6-\u07b0\u07c0-\u07c9\u07eb-\u07f3\u07fd\u0816-\u0819\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0859-\u085b\u0898-\u089f\u08ca-\u08e1\u08e3-\u0903\u093a-\u093c\u093e-\u094f\u0951-\u0957\u0962\u0963\u0966-\u096f\u0981-\u0983\u09bc\u09be-\u09c4\u09c7\u09c8\u09cb-\u09cd\u09d7\u09e2\u09e3\u09e6-\u09ef\u09fe\u0a01-\u0a03\u0a3c\u0a3e-\u0a42\u0a47\u0a48\u0a4b-\u0a4d\u0a51\u0a66-\u0a71\u0a75\u0a81-\u0a83\u0abc\u0abe-\u0ac5\u0ac7-\u0ac9\u0acb-\u0acd\u0ae2\u0ae3\u0ae6-\u0aef\u0afa-\u0aff\u0b01-\u0b03\u0b3c\u0b3e-\u0b44\u0b47\u0b48\u0b4b-\u0b4d\u0b55-\u0b57\u0b62\u0b63\u0b66-\u0b6f\u0b82\u0bbe-\u0bc2\u0bc6-\u0bc8\u0bca-\u0bcd\u0bd7\u0be6-\u0bef\u0c00-\u0c04\u0c3c\u0c3e-\u0c44\u0c46-\u0c48\u0c4a-\u0c4d\u0c55\u0c56\u0c62\u0c63\u0c66-\u0c6f\u0c81-\u0c83\u0cbc\u0cbe-\u0cc4\u0cc6-\u0cc8\u0cca-\u0ccd\u0cd5\u0cd6\u0ce2\u0ce3\u0ce6-\u0cef\u0cf3\u0d00-\u0d03\u0d3b\u0d3c\u0d3e-\u0d44\u0d46-\u0d48\u0d4a-\u0d4d\u0d57\u0d62\u0d63\u0d66-\u0d6f\u0d81-\u0d83\u0dca\u0dcf-\u0dd4\u0dd6\u0dd8-\u0ddf\u0de6-\u0def\u0df2\u0df3\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\u0e50-\u0e59\u0eb1\u0eb4-\u0ebc\u0ec8-\u0ece\u0ed0-\u0ed9\u0f18\u0f19\u0f20-\u0f29\u0f35\u0f37\u0f39\u0f3e\u0f3f\u0f71-\u0f84\u0f86\u0f87\u0f8d-\u0f97\u0f99-\u0fbc\u0fc6\u102b-\u103e\u1040-\u1049\u1056-\u1059\u105e-\u1060\u1062-\u1064\u1067-\u106d\u1071-\u1074\u1082-\u108d\u108f-\u109d\u135d-\u135f\u1369-\u1371\u1712-\u1715\u1732-\u1734\u1752\u1753\u1772\u1773\u17b4-\u17d3\u17dd\u17e0-\u17e9\u180b-\u180d\u180f-\u1819\u18a9\u1920-\u192b\u1930-\u193b\u1946-\u194f\u19d0-\u19da\u1a17-\u1a1b\u1a55-\u1a5e\u1a60-\u1a7c\u1a7f-\u1a89\u1a90-\u1a99\u1ab0-\u1abd\u1abf-\u1ace\u1b00-\u1b04\u1b34-\u1b44\u1b50-\u1b59\u1b6b-\u1b73\u1b80-\u1b82\u1ba1-\u1bad\u1bb0-\u1bb9\u1be6-\u1bf3\u1c24-\u1c37\u1c40-\u1c49\u1c50-\u1c59\u1cd0-\u1cd2\u1cd4-\u1ce8\u1ced\u1cf4\u1cf7-\u1cf9\u1dc0-\u1dff\u200c\u200d\u203f\u2040\u2054\u20d0-\u20dc\u20e1\u20e5-\u20f0\u2cef-\u2cf1\u2d7f\u2de0-\u2dff\u302a-\u302f\u3099\u309a\u30fb\ua620-\ua629\ua66f\ua674-\ua67d\ua69e\ua69f\ua6f0\ua6f1\ua802\ua806\ua80b\ua823-\ua827\ua82c\ua880\ua881\ua8b4-\ua8c5\ua8d0-\ua8d9\ua8e0-\ua8f1\ua8ff-\ua909\ua926-\ua92d\ua947-\ua953\ua980-\ua983\ua9b3-\ua9c0\ua9d0-\ua9d9\ua9e5\ua9f0-\ua9f9\uaa29-\uaa36\uaa43\uaa4c\uaa4d\uaa50-\uaa59\uaa7b-\uaa7d\uaab0\uaab2-\uaab4\uaab7\uaab8\uaabe\uaabf\uaac1\uaaeb-\uaaef\uaaf5\uaaf6\uabe3-\uabea\uabec\uabed\uabf0-\uabf9\ufb1e\ufe00-\ufe0f\ufe20-\ufe2f\ufe33\ufe34\ufe4d-\ufe4f\uff10-\uff19\uff3f\uff65";
  12. // This file was generated. Do not modify manually!
  13. var nonASCIIidentifierStartChars = "\xaa\xb5\xba\xc0-\xd6\xd8-\xf6\xf8-\u02c1\u02c6-\u02d1\u02e0-\u02e4\u02ec\u02ee\u0370-\u0374\u0376\u0377\u037a-\u037d\u037f\u0386\u0388-\u038a\u038c\u038e-\u03a1\u03a3-\u03f5\u03f7-\u0481\u048a-\u052f\u0531-\u0556\u0559\u0560-\u0588\u05d0-\u05ea\u05ef-\u05f2\u0620-\u064a\u066e\u066f\u0671-\u06d3\u06d5\u06e5\u06e6\u06ee\u06ef\u06fa-\u06fc\u06ff\u0710\u0712-\u072f\u074d-\u07a5\u07b1\u07ca-\u07ea\u07f4\u07f5\u07fa\u0800-\u0815\u081a\u0824\u0828\u0840-\u0858\u0860-\u086a\u0870-\u0887\u0889-\u088e\u08a0-\u08c9\u0904-\u0939\u093d\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098c\u098f\u0990\u0993-\u09a8\u09aa-\u09b0\u09b2\u09b6-\u09b9\u09bd\u09ce\u09dc\u09dd\u09df-\u09e1\u09f0\u09f1\u09fc\u0a05-\u0a0a\u0a0f\u0a10\u0a13-\u0a28\u0a2a-\u0a30\u0a32\u0a33\u0a35\u0a36\u0a38\u0a39\u0a59-\u0a5c\u0a5e\u0a72-\u0a74\u0a85-\u0a8d\u0a8f-\u0a91\u0a93-\u0aa8\u0aaa-\u0ab0\u0ab2\u0ab3\u0ab5-\u0ab9\u0abd\u0ad0\u0ae0\u0ae1\u0af9\u0b05-\u0b0c\u0b0f\u0b10\u0b13-\u0b28\u0b2a-\u0b30\u0b32\u0b33\u0b35-\u0b39\u0b3d\u0b5c\u0b5d\u0b5f-\u0b61\u0b71\u0b83\u0b85-\u0b8a\u0b8e-\u0b90\u0b92-\u0b95\u0b99\u0b9a\u0b9c\u0b9e\u0b9f\u0ba3\u0ba4\u0ba8-\u0baa\u0bae-\u0bb9\u0bd0\u0c05-\u0c0c\u0c0e-\u0c10\u0c12-\u0c28\u0c2a-\u0c39\u0c3d\u0c58-\u0c5a\u0c5d\u0c60\u0c61\u0c80\u0c85-\u0c8c\u0c8e-\u0c90\u0c92-\u0ca8\u0caa-\u0cb3\u0cb5-\u0cb9\u0cbd\u0cdd\u0cde\u0ce0\u0ce1\u0cf1\u0cf2\u0d04-\u0d0c\u0d0e-\u0d10\u0d12-\u0d3a\u0d3d\u0d4e\u0d54-\u0d56\u0d5f-\u0d61\u0d7a-\u0d7f\u0d85-\u0d96\u0d9a-\u0db1\u0db3-\u0dbb\u0dbd\u0dc0-\u0dc6\u0e01-\u0e30\u0e32\u0e33\u0e40-\u0e46\u0e81\u0e82\u0e84\u0e86-\u0e8a\u0e8c-\u0ea3\u0ea5\u0ea7-\u0eb0\u0eb2\u0eb3\u0ebd\u0ec0-\u0ec4\u0ec6\u0edc-\u0edf\u0f00\u0f40-\u0f47\u0f49-\u0f6c\u0f88-\u0f8c\u1000-\u102a\u103f\u1050-\u1055\u105a-\u105d\u1061\u1065\u1066\u106e-\u1070\u1075-\u1081\u108e\u10a0-\u10c5\u10c7\u10cd\u10d0-\u10fa\u10fc-\u1248\u124a-\u124d\u1250-\u1256\u1258\u125a-\u125d\u1260-\u1288\u128a-\u128d\u1290-\u12b0\u12b2-\u12b5\u12b8-\u12be\u12c0\u12c2-\u12c5\u12c8-\u12d6\u12d8-\u1310\u1312-\u1315\u1318-\u135a\u1380-\u138f\u13a0-\u13f5\u13f8-\u13fd\u1401-\u166c\u166f-\u167f\u1681-\u169a\u16a0-\u16ea\u16ee-\u16f8\u1700-\u1711\u171f-\u1731\u1740-\u1751\u1760-\u176c\u176e-\u1770\u1780-\u17b3\u17d7\u17dc\u1820-\u1878\u1880-\u18a8\u18aa\u18b0-\u18f5\u1900-\u191e\u1950-\u196d\u1970-\u1974\u1980-\u19ab\u19b0-\u19c9\u1a00-\u1a16\u1a20-\u1a54\u1aa7\u1b05-\u1b33\u1b45-\u1b4c\u1b83-\u1ba0\u1bae\u1baf\u1bba-\u1be5\u1c00-\u1c23\u1c4d-\u1c4f\u1c5a-\u1c7d\u1c80-\u1c88\u1c90-\u1cba\u1cbd-\u1cbf\u1ce9-\u1cec\u1cee-\u1cf3\u1cf5\u1cf6\u1cfa\u1d00-\u1dbf\u1e00-\u1f15\u1f18-\u1f1d\u1f20-\u1f45\u1f48-\u1f4d\u1f50-\u1f57\u1f59\u1f5b\u1f5d\u1f5f-\u1f7d\u1f80-\u1fb4\u1fb6-\u1fbc\u1fbe\u1fc2-\u1fc4\u1fc6-\u1fcc\u1fd0-\u1fd3\u1fd6-\u1fdb\u1fe0-\u1fec\u1ff2-\u1ff4\u1ff6-\u1ffc\u2071\u207f\u2090-\u209c\u2102\u2107\u210a-\u2113\u2115\u2118-\u211d\u2124\u2126\u2128\u212a-\u2139\u213c-\u213f\u2145-\u2149\u214e\u2160-\u2188\u2c00-\u2ce4\u2ceb-\u2cee\u2cf2\u2cf3\u2d00-\u2d25\u2d27\u2d2d\u2d30-\u2d67\u2d6f\u2d80-\u2d96\u2da0-\u2da6\u2da8-\u2dae\u2db0-\u2db6\u2db8-\u2dbe\u2dc0-\u2dc6\u2dc8-\u2dce\u2dd0-\u2dd6\u2dd8-\u2dde\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303c\u3041-\u3096\u309b-\u309f\u30a1-\u30fa\u30fc-\u30ff\u3105-\u312f\u3131-\u318e\u31a0-\u31bf\u31f0-\u31ff\u3400-\u4dbf\u4e00-\ua48c\ua4d0-\ua4fd\ua500-\ua60c\ua610-\ua61f\ua62a\ua62b\ua640-\ua66e\ua67f-\ua69d\ua6a0-\ua6ef\ua717-\ua71f\ua722-\ua788\ua78b-\ua7ca\ua7d0\ua7d1\ua7d3\ua7d5-\ua7d9\ua7f2-\ua801\ua803-\ua805\ua807-\ua80a\ua80c-\ua822\ua840-\ua873\ua882-\ua8b3\ua8f2-\ua8f7\ua8fb\ua8fd\ua8fe\ua90a-\ua925\ua930-\ua946\ua960-\ua97c\ua984-\ua9b2\ua9cf\ua9e0-\ua9e4\ua9e6-\ua9ef\ua9fa-\ua9fe\uaa00-\uaa28\uaa40-\uaa42\uaa44-\uaa4b\uaa60-\uaa76\uaa7a\uaa7e-\uaaaf\uaab1\uaab5\uaab6\uaab9-\uaabd\uaac0\uaac2\uaadb-\uaadd\uaae0-\uaaea\uaaf2-\uaaf4\uab01-\uab06\uab09-\uab0e\uab11-\uab16\uab20-\uab26\uab28-\uab2e\uab30-\uab5a\uab5c-\uab69\uab70-\uabe2\uac00-\ud7a3\ud7b0-\ud7c6\ud7cb-\ud7fb\uf900-\ufa6d\ufa70-\ufad9\ufb00-\ufb06\ufb13-\ufb17\ufb1d\ufb1f-\ufb28\ufb2a-\ufb36\ufb38-\ufb3c\ufb3e\ufb40\ufb41\ufb43\ufb44\ufb46-\ufbb1\ufbd3-\ufd3d\ufd50-\ufd8f\ufd92-\ufdc7\ufdf0-\ufdfb\ufe70-\ufe74\ufe76-\ufefc\uff21-\uff3a\uff41-\uff5a\uff66-\uffbe\uffc2-\uffc7\uffca-\uffcf\uffd2-\uffd7\uffda-\uffdc";
  14. // These are a run-length and offset encoded representation of the
  15. // >0xffff code points that are a valid part of identifiers. The
  16. // offset starts at 0x10000, and each pair of numbers represents an
  17. // offset to the next range, and then a size of the range.
  18. // Reserved word lists for various dialects of the language
  19. var reservedWords = {
  20. 3: "abstract boolean byte char class double enum export extends final float goto implements import int interface long native package private protected public short static super synchronized throws transient volatile",
  21. 5: "class enum extends super const export import",
  22. 6: "enum",
  23. strict: "implements interface let package private protected public static yield",
  24. strictBind: "eval arguments"
  25. };
  26. // And the keywords
  27. var ecma5AndLessKeywords = "break case catch continue debugger default do else finally for function if return switch throw try var while with null true false instanceof typeof void delete new in this";
  28. var keywords$1 = {
  29. 5: ecma5AndLessKeywords,
  30. "5module": ecma5AndLessKeywords + " export import",
  31. 6: ecma5AndLessKeywords + " const class extends export import super"
  32. };
  33. var keywordRelationalOperator = /^in(stanceof)?$/;
  34. // ## Character categories
  35. var nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]");
  36. var nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]");
  37. // This has a complexity linear to the value of the code. The
  38. // assumption is that looking up astral identifier characters is
  39. // rare.
  40. function isInAstralSet(code, set) {
  41. var pos = 0x10000;
  42. for (var i = 0; i < set.length; i += 2) {
  43. pos += set[i];
  44. if (pos > code) { return false }
  45. pos += set[i + 1];
  46. if (pos >= code) { return true }
  47. }
  48. return false
  49. }
  50. // Test whether a given character code starts an identifier.
  51. function isIdentifierStart(code, astral) {
  52. if (code < 65) { return code === 36 }
  53. if (code < 91) { return true }
  54. if (code < 97) { return code === 95 }
  55. if (code < 123) { return true }
  56. if (code <= 0xffff) { return code >= 0xaa && nonASCIIidentifierStart.test(String.fromCharCode(code)) }
  57. if (astral === false) { return false }
  58. return isInAstralSet(code, astralIdentifierStartCodes)
  59. }
  60. // Test whether a given character is part of an identifier.
  61. function isIdentifierChar(code, astral) {
  62. if (code < 48) { return code === 36 }
  63. if (code < 58) { return true }
  64. if (code < 65) { return false }
  65. if (code < 91) { return true }
  66. if (code < 97) { return code === 95 }
  67. if (code < 123) { return true }
  68. if (code <= 0xffff) { return code >= 0xaa && nonASCIIidentifier.test(String.fromCharCode(code)) }
  69. if (astral === false) { return false }
  70. return isInAstralSet(code, astralIdentifierStartCodes) || isInAstralSet(code, astralIdentifierCodes)
  71. }
  72. // ## Token types
  73. // The assignment of fine-grained, information-carrying type objects
  74. // allows the tokenizer to store the information it has about a
  75. // token in a way that is very cheap for the parser to look up.
  76. // All token type variables start with an underscore, to make them
  77. // easy to recognize.
  78. // The `beforeExpr` property is used to disambiguate between regular
  79. // expressions and divisions. It is set on all token types that can
  80. // be followed by an expression (thus, a slash after them would be a
  81. // regular expression).
  82. //
  83. // The `startsExpr` property is used to check if the token ends a
  84. // `yield` expression. It is set on all token types that either can
  85. // directly start an expression (like a quotation mark) or can
  86. // continue an expression (like the body of a string).
  87. //
  88. // `isLoop` marks a keyword as starting a loop, which is important
  89. // to know when parsing a label, in order to allow or disallow
  90. // continue jumps to that label.
  91. var TokenType = function TokenType(label, conf) {
  92. if ( conf === void 0 ) conf = {};
  93. this.label = label;
  94. this.keyword = conf.keyword;
  95. this.beforeExpr = !!conf.beforeExpr;
  96. this.startsExpr = !!conf.startsExpr;
  97. this.isLoop = !!conf.isLoop;
  98. this.isAssign = !!conf.isAssign;
  99. this.prefix = !!conf.prefix;
  100. this.postfix = !!conf.postfix;
  101. this.binop = conf.binop || null;
  102. this.updateContext = null;
  103. };
  104. function binop(name, prec) {
  105. return new TokenType(name, {beforeExpr: true, binop: prec})
  106. }
  107. var beforeExpr = {beforeExpr: true}, startsExpr = {startsExpr: true};
  108. // Map keyword names to token types.
  109. var keywords = {};
  110. // Succinct definitions of keyword token types
  111. function kw(name, options) {
  112. if ( options === void 0 ) options = {};
  113. options.keyword = name;
  114. return keywords[name] = new TokenType(name, options)
  115. }
  116. var types$1 = {
  117. num: new TokenType("num", startsExpr),
  118. regexp: new TokenType("regexp", startsExpr),
  119. string: new TokenType("string", startsExpr),
  120. name: new TokenType("name", startsExpr),
  121. privateId: new TokenType("privateId", startsExpr),
  122. eof: new TokenType("eof"),
  123. // Punctuation token types.
  124. bracketL: new TokenType("[", {beforeExpr: true, startsExpr: true}),
  125. bracketR: new TokenType("]"),
  126. braceL: new TokenType("{", {beforeExpr: true, startsExpr: true}),
  127. braceR: new TokenType("}"),
  128. parenL: new TokenType("(", {beforeExpr: true, startsExpr: true}),
  129. parenR: new TokenType(")"),
  130. comma: new TokenType(",", beforeExpr),
  131. semi: new TokenType(";", beforeExpr),
  132. colon: new TokenType(":", beforeExpr),
  133. dot: new TokenType("."),
  134. question: new TokenType("?", beforeExpr),
  135. questionDot: new TokenType("?."),
  136. arrow: new TokenType("=>", beforeExpr),
  137. template: new TokenType("template"),
  138. invalidTemplate: new TokenType("invalidTemplate"),
  139. ellipsis: new TokenType("...", beforeExpr),
  140. backQuote: new TokenType("`", startsExpr),
  141. dollarBraceL: new TokenType("${", {beforeExpr: true, startsExpr: true}),
  142. // Operators. These carry several kinds of properties to help the
  143. // parser use them properly (the presence of these properties is
  144. // what categorizes them as operators).
  145. //
  146. // `binop`, when present, specifies that this operator is a binary
  147. // operator, and will refer to its precedence.
  148. //
  149. // `prefix` and `postfix` mark the operator as a prefix or postfix
  150. // unary operator.
  151. //
  152. // `isAssign` marks all of `=`, `+=`, `-=` etcetera, which act as
  153. // binary operators with a very low precedence, that should result
  154. // in AssignmentExpression nodes.
  155. eq: new TokenType("=", {beforeExpr: true, isAssign: true}),
  156. assign: new TokenType("_=", {beforeExpr: true, isAssign: true}),
  157. incDec: new TokenType("++/--", {prefix: true, postfix: true, startsExpr: true}),
  158. prefix: new TokenType("!/~", {beforeExpr: true, prefix: true, startsExpr: true}),
  159. logicalOR: binop("||", 1),
  160. logicalAND: binop("&&", 2),
  161. bitwiseOR: binop("|", 3),
  162. bitwiseXOR: binop("^", 4),
  163. bitwiseAND: binop("&", 5),
  164. equality: binop("==/!=/===/!==", 6),
  165. relational: binop("</>/<=/>=", 7),
  166. bitShift: binop("<</>>/>>>", 8),
  167. plusMin: new TokenType("+/-", {beforeExpr: true, binop: 9, prefix: true, startsExpr: true}),
  168. modulo: binop("%", 10),
  169. star: binop("*", 10),
  170. slash: binop("/", 10),
  171. starstar: new TokenType("**", {beforeExpr: true}),
  172. coalesce: binop("??", 1),
  173. // Keyword token types.
  174. _break: kw("break"),
  175. _case: kw("case", beforeExpr),
  176. _catch: kw("catch"),
  177. _continue: kw("continue"),
  178. _debugger: kw("debugger"),
  179. _default: kw("default", beforeExpr),
  180. _do: kw("do", {isLoop: true, beforeExpr: true}),
  181. _else: kw("else", beforeExpr),
  182. _finally: kw("finally"),
  183. _for: kw("for", {isLoop: true}),
  184. _function: kw("function", startsExpr),
  185. _if: kw("if"),
  186. _return: kw("return", beforeExpr),
  187. _switch: kw("switch"),
  188. _throw: kw("throw", beforeExpr),
  189. _try: kw("try"),
  190. _var: kw("var"),
  191. _const: kw("const"),
  192. _while: kw("while", {isLoop: true}),
  193. _with: kw("with"),
  194. _new: kw("new", {beforeExpr: true, startsExpr: true}),
  195. _this: kw("this", startsExpr),
  196. _super: kw("super", startsExpr),
  197. _class: kw("class", startsExpr),
  198. _extends: kw("extends", beforeExpr),
  199. _export: kw("export"),
  200. _import: kw("import", startsExpr),
  201. _null: kw("null", startsExpr),
  202. _true: kw("true", startsExpr),
  203. _false: kw("false", startsExpr),
  204. _in: kw("in", {beforeExpr: true, binop: 7}),
  205. _instanceof: kw("instanceof", {beforeExpr: true, binop: 7}),
  206. _typeof: kw("typeof", {beforeExpr: true, prefix: true, startsExpr: true}),
  207. _void: kw("void", {beforeExpr: true, prefix: true, startsExpr: true}),
  208. _delete: kw("delete", {beforeExpr: true, prefix: true, startsExpr: true})
  209. };
  210. // Matches a whole line break (where CRLF is considered a single
  211. // line break). Used to count lines.
  212. var lineBreak = /\r\n?|\n|\u2028|\u2029/;
  213. var lineBreakG = new RegExp(lineBreak.source, "g");
  214. function isNewLine(code) {
  215. return code === 10 || code === 13 || code === 0x2028 || code === 0x2029
  216. }
  217. function nextLineBreak(code, from, end) {
  218. if ( end === void 0 ) end = code.length;
  219. for (var i = from; i < end; i++) {
  220. var next = code.charCodeAt(i);
  221. if (isNewLine(next))
  222. { return i < end - 1 && next === 13 && code.charCodeAt(i + 1) === 10 ? i + 2 : i + 1 }
  223. }
  224. return -1
  225. }
  226. var nonASCIIwhitespace = /[\u1680\u2000-\u200a\u202f\u205f\u3000\ufeff]/;
  227. var skipWhiteSpace = /(?:\s|\/\/.*|\/\*[^]*?\*\/)*/g;
  228. var ref = Object.prototype;
  229. var hasOwnProperty = ref.hasOwnProperty;
  230. var toString = ref.toString;
  231. var hasOwn = Object.hasOwn || (function (obj, propName) { return (
  232. hasOwnProperty.call(obj, propName)
  233. ); });
  234. var isArray = Array.isArray || (function (obj) { return (
  235. toString.call(obj) === "[object Array]"
  236. ); });
  237. var regexpCache = Object.create(null);
  238. function wordsRegexp(words) {
  239. return regexpCache[words] || (regexpCache[words] = new RegExp("^(?:" + words.replace(/ /g, "|") + ")$"))
  240. }
  241. function codePointToString(code) {
  242. // UTF-16 Decoding
  243. if (code <= 0xFFFF) { return String.fromCharCode(code) }
  244. code -= 0x10000;
  245. return String.fromCharCode((code >> 10) + 0xD800, (code & 1023) + 0xDC00)
  246. }
  247. var loneSurrogate = /(?:[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])/;
  248. // These are used when `options.locations` is on, for the
  249. // `startLoc` and `endLoc` properties.
  250. var Position = function Position(line, col) {
  251. this.line = line;
  252. this.column = col;
  253. };
  254. Position.prototype.offset = function offset (n) {
  255. return new Position(this.line, this.column + n)
  256. };
  257. var SourceLocation = function SourceLocation(p, start, end) {
  258. this.start = start;
  259. this.end = end;
  260. if (p.sourceFile !== null) { this.source = p.sourceFile; }
  261. };
  262. // The `getLineInfo` function is mostly useful when the
  263. // `locations` option is off (for performance reasons) and you
  264. // want to find the line/column position for a given character
  265. // offset. `input` should be the code string that the offset refers
  266. // into.
  267. function getLineInfo(input, offset) {
  268. for (var line = 1, cur = 0;;) {
  269. var nextBreak = nextLineBreak(input, cur, offset);
  270. if (nextBreak < 0) { return new Position(line, offset - cur) }
  271. ++line;
  272. cur = nextBreak;
  273. }
  274. }
  275. // A second argument must be given to configure the parser process.
  276. // These options are recognized (only `ecmaVersion` is required):
  277. var defaultOptions = {
  278. // `ecmaVersion` indicates the ECMAScript version to parse. Must be
  279. // either 3, 5, 6 (or 2015), 7 (2016), 8 (2017), 9 (2018), 10
  280. // (2019), 11 (2020), 12 (2021), 13 (2022), 14 (2023), or `"latest"`
  281. // (the latest version the library supports). This influences
  282. // support for strict mode, the set of reserved words, and support
  283. // for new syntax features.
  284. ecmaVersion: null,
  285. // `sourceType` indicates the mode the code should be parsed in.
  286. // Can be either `"script"` or `"module"`. This influences global
  287. // strict mode and parsing of `import` and `export` declarations.
  288. sourceType: "script",
  289. // `onInsertedSemicolon` can be a callback that will be called when
  290. // a semicolon is automatically inserted. It will be passed the
  291. // position of the inserted semicolon as an offset, and if
  292. // `locations` is enabled, it is given the location as a `{line,
  293. // column}` object as second argument.
  294. onInsertedSemicolon: null,
  295. // `onTrailingComma` is similar to `onInsertedSemicolon`, but for
  296. // trailing commas.
  297. onTrailingComma: null,
  298. // By default, reserved words are only enforced if ecmaVersion >= 5.
  299. // Set `allowReserved` to a boolean value to explicitly turn this on
  300. // an off. When this option has the value "never", reserved words
  301. // and keywords can also not be used as property names.
  302. allowReserved: null,
  303. // When enabled, a return at the top level is not considered an
  304. // error.
  305. allowReturnOutsideFunction: false,
  306. // When enabled, import/export statements are not constrained to
  307. // appearing at the top of the program, and an import.meta expression
  308. // in a script isn't considered an error.
  309. allowImportExportEverywhere: false,
  310. // By default, await identifiers are allowed to appear at the top-level scope only if ecmaVersion >= 2022.
  311. // When enabled, await identifiers are allowed to appear at the top-level scope,
  312. // but they are still not allowed in non-async functions.
  313. allowAwaitOutsideFunction: null,
  314. // When enabled, super identifiers are not constrained to
  315. // appearing in methods and do not raise an error when they appear elsewhere.
  316. allowSuperOutsideMethod: null,
  317. // When enabled, hashbang directive in the beginning of file is
  318. // allowed and treated as a line comment. Enabled by default when
  319. // `ecmaVersion` >= 2023.
  320. allowHashBang: false,
  321. // By default, the parser will verify that private properties are
  322. // only used in places where they are valid and have been declared.
  323. // Set this to false to turn such checks off.
  324. checkPrivateFields: true,
  325. // When `locations` is on, `loc` properties holding objects with
  326. // `start` and `end` properties in `{line, column}` form (with
  327. // line being 1-based and column 0-based) will be attached to the
  328. // nodes.
  329. locations: false,
  330. // A function can be passed as `onToken` option, which will
  331. // cause Acorn to call that function with object in the same
  332. // format as tokens returned from `tokenizer().getToken()`. Note
  333. // that you are not allowed to call the parser from the
  334. // callback—that will corrupt its internal state.
  335. onToken: null,
  336. // A function can be passed as `onComment` option, which will
  337. // cause Acorn to call that function with `(block, text, start,
  338. // end)` parameters whenever a comment is skipped. `block` is a
  339. // boolean indicating whether this is a block (`/* */`) comment,
  340. // `text` is the content of the comment, and `start` and `end` are
  341. // character offsets that denote the start and end of the comment.
  342. // When the `locations` option is on, two more parameters are
  343. // passed, the full `{line, column}` locations of the start and
  344. // end of the comments. Note that you are not allowed to call the
  345. // parser from the callback—that will corrupt its internal state.
  346. // When this option has an array as value, objects representing the
  347. // comments are pushed to it.
  348. onComment: null,
  349. // Nodes have their start and end characters offsets recorded in
  350. // `start` and `end` properties (directly on the node, rather than
  351. // the `loc` object, which holds line/column data. To also add a
  352. // [semi-standardized][range] `range` property holding a `[start,
  353. // end]` array with the same numbers, set the `ranges` option to
  354. // `true`.
  355. //
  356. // [range]: https://bugzilla.mozilla.org/show_bug.cgi?id=745678
  357. ranges: false,
  358. // It is possible to parse multiple files into a single AST by
  359. // passing the tree produced by parsing the first file as
  360. // `program` option in subsequent parses. This will add the
  361. // toplevel forms of the parsed file to the `Program` (top) node
  362. // of an existing parse tree.
  363. program: null,
  364. // When `locations` is on, you can pass this to record the source
  365. // file in every node's `loc` object.
  366. sourceFile: null,
  367. // This value, if given, is stored in every node, whether
  368. // `locations` is on or off.
  369. directSourceFile: null,
  370. // When enabled, parenthesized expressions are represented by
  371. // (non-standard) ParenthesizedExpression nodes
  372. preserveParens: false
  373. };
  374. // Interpret and default an options object
  375. var warnedAboutEcmaVersion = false;
  376. function getOptions(opts) {
  377. var options = {};
  378. for (var opt in defaultOptions)
  379. { options[opt] = opts && hasOwn(opts, opt) ? opts[opt] : defaultOptions[opt]; }
  380. if (options.ecmaVersion === "latest") {
  381. options.ecmaVersion = 1e8;
  382. } else if (options.ecmaVersion == null) {
  383. if (!warnedAboutEcmaVersion && typeof console === "object" && console.warn) {
  384. warnedAboutEcmaVersion = true;
  385. console.warn("Since Acorn 8.0.0, options.ecmaVersion is required.\nDefaulting to 2020, but this will stop working in the future.");
  386. }
  387. options.ecmaVersion = 11;
  388. } else if (options.ecmaVersion >= 2015) {
  389. options.ecmaVersion -= 2009;
  390. }
  391. if (options.allowReserved == null)
  392. { options.allowReserved = options.ecmaVersion < 5; }
  393. if (!opts || opts.allowHashBang == null)
  394. { options.allowHashBang = options.ecmaVersion >= 14; }
  395. if (isArray(options.onToken)) {
  396. var tokens = options.onToken;
  397. options.onToken = function (token) { return tokens.push(token); };
  398. }
  399. if (isArray(options.onComment))
  400. { options.onComment = pushComment(options, options.onComment); }
  401. return options
  402. }
  403. function pushComment(options, array) {
  404. return function(block, text, start, end, startLoc, endLoc) {
  405. var comment = {
  406. type: block ? "Block" : "Line",
  407. value: text,
  408. start: start,
  409. end: end
  410. };
  411. if (options.locations)
  412. { comment.loc = new SourceLocation(this, startLoc, endLoc); }
  413. if (options.ranges)
  414. { comment.range = [start, end]; }
  415. array.push(comment);
  416. }
  417. }
  418. // Each scope gets a bitset that may contain these flags
  419. var
  420. SCOPE_TOP = 1,
  421. SCOPE_FUNCTION = 2,
  422. SCOPE_ASYNC = 4,
  423. SCOPE_GENERATOR = 8,
  424. SCOPE_ARROW = 16,
  425. SCOPE_SIMPLE_CATCH = 32,
  426. SCOPE_SUPER = 64,
  427. SCOPE_DIRECT_SUPER = 128,
  428. SCOPE_CLASS_STATIC_BLOCK = 256,
  429. SCOPE_VAR = SCOPE_TOP | SCOPE_FUNCTION | SCOPE_CLASS_STATIC_BLOCK;
  430. function functionFlags(async, generator) {
  431. return SCOPE_FUNCTION | (async ? SCOPE_ASYNC : 0) | (generator ? SCOPE_GENERATOR : 0)
  432. }
  433. // Used in checkLVal* and declareName to determine the type of a binding
  434. var
  435. BIND_NONE = 0, // Not a binding
  436. BIND_VAR = 1, // Var-style binding
  437. BIND_LEXICAL = 2, // Let- or const-style binding
  438. BIND_FUNCTION = 3, // Function declaration
  439. BIND_SIMPLE_CATCH = 4, // Simple (identifier pattern) catch binding
  440. BIND_OUTSIDE = 5; // Special case for function names as bound inside the function
  441. var Parser = function Parser(options, input, startPos) {
  442. this.options = options = getOptions(options);
  443. this.sourceFile = options.sourceFile;
  444. this.keywords = wordsRegexp(keywords$1[options.ecmaVersion >= 6 ? 6 : options.sourceType === "module" ? "5module" : 5]);
  445. var reserved = "";
  446. if (options.allowReserved !== true) {
  447. reserved = reservedWords[options.ecmaVersion >= 6 ? 6 : options.ecmaVersion === 5 ? 5 : 3];
  448. if (options.sourceType === "module") { reserved += " await"; }
  449. }
  450. this.reservedWords = wordsRegexp(reserved);
  451. var reservedStrict = (reserved ? reserved + " " : "") + reservedWords.strict;
  452. this.reservedWordsStrict = wordsRegexp(reservedStrict);
  453. this.reservedWordsStrictBind = wordsRegexp(reservedStrict + " " + reservedWords.strictBind);
  454. this.input = String(input);
  455. // Used to signal to callers of `readWord1` whether the word
  456. // contained any escape sequences. This is needed because words with
  457. // escape sequences must not be interpreted as keywords.
  458. this.containsEsc = false;
  459. // Set up token state
  460. // The current position of the tokenizer in the input.
  461. if (startPos) {
  462. this.pos = startPos;
  463. this.lineStart = this.input.lastIndexOf("\n", startPos - 1) + 1;
  464. this.curLine = this.input.slice(0, this.lineStart).split(lineBreak).length;
  465. } else {
  466. this.pos = this.lineStart = 0;
  467. this.curLine = 1;
  468. }
  469. // Properties of the current token:
  470. // Its type
  471. this.type = types$1.eof;
  472. // For tokens that include more information than their type, the value
  473. this.value = null;
  474. // Its start and end offset
  475. this.start = this.end = this.pos;
  476. // And, if locations are used, the {line, column} object
  477. // corresponding to those offsets
  478. this.startLoc = this.endLoc = this.curPosition();
  479. // Position information for the previous token
  480. this.lastTokEndLoc = this.lastTokStartLoc = null;
  481. this.lastTokStart = this.lastTokEnd = this.pos;
  482. // The context stack is used to superficially track syntactic
  483. // context to predict whether a regular expression is allowed in a
  484. // given position.
  485. this.context = this.initialContext();
  486. this.exprAllowed = true;
  487. // Figure out if it's a module code.
  488. this.inModule = options.sourceType === "module";
  489. this.strict = this.inModule || this.strictDirective(this.pos);
  490. // Used to signify the start of a potential arrow function
  491. this.potentialArrowAt = -1;
  492. this.potentialArrowInForAwait = false;
  493. // Positions to delayed-check that yield/await does not exist in default parameters.
  494. this.yieldPos = this.awaitPos = this.awaitIdentPos = 0;
  495. // Labels in scope.
  496. this.labels = [];
  497. // Thus-far undefined exports.
  498. this.undefinedExports = Object.create(null);
  499. // If enabled, skip leading hashbang line.
  500. if (this.pos === 0 && options.allowHashBang && this.input.slice(0, 2) === "#!")
  501. { this.skipLineComment(2); }
  502. // Scope tracking for duplicate variable names (see scope.js)
  503. this.scopeStack = [];
  504. this.enterScope(SCOPE_TOP);
  505. // For RegExp validation
  506. this.regexpState = null;
  507. // The stack of private names.
  508. // Each element has two properties: 'declared' and 'used'.
  509. // When it exited from the outermost class definition, all used private names must be declared.
  510. this.privateNameStack = [];
  511. };
  512. var prototypeAccessors = { inFunction: { configurable: true },inGenerator: { configurable: true },inAsync: { configurable: true },canAwait: { configurable: true },allowSuper: { configurable: true },allowDirectSuper: { configurable: true },treatFunctionsAsVar: { configurable: true },allowNewDotTarget: { configurable: true },inClassStaticBlock: { configurable: true } };
  513. Parser.prototype.parse = function parse () {
  514. var node = this.options.program || this.startNode();
  515. this.nextToken();
  516. return this.parseTopLevel(node)
  517. };
  518. prototypeAccessors.inFunction.get = function () { return (this.currentVarScope().flags & SCOPE_FUNCTION) > 0 };
  519. prototypeAccessors.inGenerator.get = function () { return (this.currentVarScope().flags & SCOPE_GENERATOR) > 0 && !this.currentVarScope().inClassFieldInit };
  520. prototypeAccessors.inAsync.get = function () { return (this.currentVarScope().flags & SCOPE_ASYNC) > 0 && !this.currentVarScope().inClassFieldInit };
  521. prototypeAccessors.canAwait.get = function () {
  522. for (var i = this.scopeStack.length - 1; i >= 0; i--) {
  523. var scope = this.scopeStack[i];
  524. if (scope.inClassFieldInit || scope.flags & SCOPE_CLASS_STATIC_BLOCK) { return false }
  525. if (scope.flags & SCOPE_FUNCTION) { return (scope.flags & SCOPE_ASYNC) > 0 }
  526. }
  527. return (this.inModule && this.options.ecmaVersion >= 13) || this.options.allowAwaitOutsideFunction
  528. };
  529. prototypeAccessors.allowSuper.get = function () {
  530. var ref = this.currentThisScope();
  531. var flags = ref.flags;
  532. var inClassFieldInit = ref.inClassFieldInit;
  533. return (flags & SCOPE_SUPER) > 0 || inClassFieldInit || this.options.allowSuperOutsideMethod
  534. };
  535. prototypeAccessors.allowDirectSuper.get = function () { return (this.currentThisScope().flags & SCOPE_DIRECT_SUPER) > 0 };
  536. prototypeAccessors.treatFunctionsAsVar.get = function () { return this.treatFunctionsAsVarInScope(this.currentScope()) };
  537. prototypeAccessors.allowNewDotTarget.get = function () {
  538. var ref = this.currentThisScope();
  539. var flags = ref.flags;
  540. var inClassFieldInit = ref.inClassFieldInit;
  541. return (flags & (SCOPE_FUNCTION | SCOPE_CLASS_STATIC_BLOCK)) > 0 || inClassFieldInit
  542. };
  543. prototypeAccessors.inClassStaticBlock.get = function () {
  544. return (this.currentVarScope().flags & SCOPE_CLASS_STATIC_BLOCK) > 0
  545. };
  546. Parser.extend = function extend () {
  547. var plugins = [], len = arguments.length;
  548. while ( len-- ) plugins[ len ] = arguments[ len ];
  549. var cls = this;
  550. for (var i = 0; i < plugins.length; i++) { cls = plugins[i](cls); }
  551. return cls
  552. };
  553. Parser.parse = function parse (input, options) {
  554. return new this(options, input).parse()
  555. };
  556. Parser.parseExpressionAt = function parseExpressionAt (input, pos, options) {
  557. var parser = new this(options, input, pos);
  558. parser.nextToken();
  559. return parser.parseExpression()
  560. };
  561. Parser.tokenizer = function tokenizer (input, options) {
  562. return new this(options, input)
  563. };
  564. Object.defineProperties( Parser.prototype, prototypeAccessors );
  565. var pp$9 = Parser.prototype;
  566. // ## Parser utilities
  567. var literal = /^(?:'((?:\\[^]|[^'\\])*?)'|"((?:\\[^]|[^"\\])*?)")/;
  568. pp$9.strictDirective = function(start) {
  569. if (this.options.ecmaVersion < 5) { return false }
  570. for (;;) {
  571. // Try to find string literal.
  572. skipWhiteSpace.lastIndex = start;
  573. start += skipWhiteSpace.exec(this.input)[0].length;
  574. var match = literal.exec(this.input.slice(start));
  575. if (!match) { return false }
  576. if ((match[1] || match[2]) === "use strict") {
  577. skipWhiteSpace.lastIndex = start + match[0].length;
  578. var spaceAfter = skipWhiteSpace.exec(this.input), end = spaceAfter.index + spaceAfter[0].length;
  579. var next = this.input.charAt(end);
  580. return next === ";" || next === "}" ||
  581. (lineBreak.test(spaceAfter[0]) &&
  582. !(/[(`.[+\-/*%<>=,?^&]/.test(next) || next === "!" && this.input.charAt(end + 1) === "="))
  583. }
  584. start += match[0].length;
  585. // Skip semicolon, if any.
  586. skipWhiteSpace.lastIndex = start;
  587. start += skipWhiteSpace.exec(this.input)[0].length;
  588. if (this.input[start] === ";")
  589. { start++; }
  590. }
  591. };
  592. // Predicate that tests whether the next token is of the given
  593. // type, and if yes, consumes it as a side effect.
  594. pp$9.eat = function(type) {
  595. if (this.type === type) {
  596. this.next();
  597. return true
  598. } else {
  599. return false
  600. }
  601. };
  602. // Tests whether parsed token is a contextual keyword.
  603. pp$9.isContextual = function(name) {
  604. return this.type === types$1.name && this.value === name && !this.containsEsc
  605. };
  606. // Consumes contextual keyword if possible.
  607. pp$9.eatContextual = function(name) {
  608. if (!this.isContextual(name)) { return false }
  609. this.next();
  610. return true
  611. };
  612. // Asserts that following token is given contextual keyword.
  613. pp$9.expectContextual = function(name) {
  614. if (!this.eatContextual(name)) { this.unexpected(); }
  615. };
  616. // Test whether a semicolon can be inserted at the current position.
  617. pp$9.canInsertSemicolon = function() {
  618. return this.type === types$1.eof ||
  619. this.type === types$1.braceR ||
  620. lineBreak.test(this.input.slice(this.lastTokEnd, this.start))
  621. };
  622. pp$9.insertSemicolon = function() {
  623. if (this.canInsertSemicolon()) {
  624. if (this.options.onInsertedSemicolon)
  625. { this.options.onInsertedSemicolon(this.lastTokEnd, this.lastTokEndLoc); }
  626. return true
  627. }
  628. };
  629. // Consume a semicolon, or, failing that, see if we are allowed to
  630. // pretend that there is a semicolon at this position.
  631. pp$9.semicolon = function() {
  632. if (!this.eat(types$1.semi) && !this.insertSemicolon()) { this.unexpected(); }
  633. };
  634. pp$9.afterTrailingComma = function(tokType, notNext) {
  635. if (this.type === tokType) {
  636. if (this.options.onTrailingComma)
  637. { this.options.onTrailingComma(this.lastTokStart, this.lastTokStartLoc); }
  638. if (!notNext)
  639. { this.next(); }
  640. return true
  641. }
  642. };
  643. // Expect a token of a given type. If found, consume it, otherwise,
  644. // raise an unexpected token error.
  645. pp$9.expect = function(type) {
  646. this.eat(type) || this.unexpected();
  647. };
  648. // Raise an unexpected token error.
  649. pp$9.unexpected = function(pos) {
  650. this.raise(pos != null ? pos : this.start, "Unexpected token");
  651. };
  652. var DestructuringErrors = function DestructuringErrors() {
  653. this.shorthandAssign =
  654. this.trailingComma =
  655. this.parenthesizedAssign =
  656. this.parenthesizedBind =
  657. this.doubleProto =
  658. -1;
  659. };
  660. pp$9.checkPatternErrors = function(refDestructuringErrors, isAssign) {
  661. if (!refDestructuringErrors) { return }
  662. if (refDestructuringErrors.trailingComma > -1)
  663. { this.raiseRecoverable(refDestructuringErrors.trailingComma, "Comma is not permitted after the rest element"); }
  664. var parens = isAssign ? refDestructuringErrors.parenthesizedAssign : refDestructuringErrors.parenthesizedBind;
  665. if (parens > -1) { this.raiseRecoverable(parens, isAssign ? "Assigning to rvalue" : "Parenthesized pattern"); }
  666. };
  667. pp$9.checkExpressionErrors = function(refDestructuringErrors, andThrow) {
  668. if (!refDestructuringErrors) { return false }
  669. var shorthandAssign = refDestructuringErrors.shorthandAssign;
  670. var doubleProto = refDestructuringErrors.doubleProto;
  671. if (!andThrow) { return shorthandAssign >= 0 || doubleProto >= 0 }
  672. if (shorthandAssign >= 0)
  673. { this.raise(shorthandAssign, "Shorthand property assignments are valid only in destructuring patterns"); }
  674. if (doubleProto >= 0)
  675. { this.raiseRecoverable(doubleProto, "Redefinition of __proto__ property"); }
  676. };
  677. pp$9.checkYieldAwaitInDefaultParams = function() {
  678. if (this.yieldPos && (!this.awaitPos || this.yieldPos < this.awaitPos))
  679. { this.raise(this.yieldPos, "Yield expression cannot be a default value"); }
  680. if (this.awaitPos)
  681. { this.raise(this.awaitPos, "Await expression cannot be a default value"); }
  682. };
  683. pp$9.isSimpleAssignTarget = function(expr) {
  684. if (expr.type === "ParenthesizedExpression")
  685. { return this.isSimpleAssignTarget(expr.expression) }
  686. return expr.type === "Identifier" || expr.type === "MemberExpression"
  687. };
  688. var pp$8 = Parser.prototype;
  689. // ### Statement parsing
  690. // Parse a program. Initializes the parser, reads any number of
  691. // statements, and wraps them in a Program node. Optionally takes a
  692. // `program` argument. If present, the statements will be appended
  693. // to its body instead of creating a new node.
  694. pp$8.parseTopLevel = function(node) {
  695. var exports = Object.create(null);
  696. if (!node.body) { node.body = []; }
  697. while (this.type !== types$1.eof) {
  698. var stmt = this.parseStatement(null, true, exports);
  699. node.body.push(stmt);
  700. }
  701. if (this.inModule)
  702. { for (var i = 0, list = Object.keys(this.undefinedExports); i < list.length; i += 1)
  703. {
  704. var name = list[i];
  705. this.raiseRecoverable(this.undefinedExports[name].start, ("Export '" + name + "' is not defined"));
  706. } }
  707. this.adaptDirectivePrologue(node.body);
  708. this.next();
  709. node.sourceType = this.options.sourceType;
  710. return this.finishNode(node, "Program")
  711. };
  712. var loopLabel = {kind: "loop"}, switchLabel = {kind: "switch"};
  713. pp$8.isLet = function(context) {
  714. if (this.options.ecmaVersion < 6 || !this.isContextual("let")) { return false }
  715. skipWhiteSpace.lastIndex = this.pos;
  716. var skip = skipWhiteSpace.exec(this.input);
  717. var next = this.pos + skip[0].length, nextCh = this.input.charCodeAt(next);
  718. // For ambiguous cases, determine if a LexicalDeclaration (or only a
  719. // Statement) is allowed here. If context is not empty then only a Statement
  720. // is allowed. However, `let [` is an explicit negative lookahead for
  721. // ExpressionStatement, so special-case it first.
  722. if (nextCh === 91 || nextCh === 92) { return true } // '[', '\'
  723. if (context) { return false }
  724. if (nextCh === 123 || nextCh > 0xd7ff && nextCh < 0xdc00) { return true } // '{', astral
  725. if (isIdentifierStart(nextCh, true)) {
  726. var pos = next + 1;
  727. while (isIdentifierChar(nextCh = this.input.charCodeAt(pos), true)) { ++pos; }
  728. if (nextCh === 92 || nextCh > 0xd7ff && nextCh < 0xdc00) { return true }
  729. var ident = this.input.slice(next, pos);
  730. if (!keywordRelationalOperator.test(ident)) { return true }
  731. }
  732. return false
  733. };
  734. // check 'async [no LineTerminator here] function'
  735. // - 'async /*foo*/ function' is OK.
  736. // - 'async /*\n*/ function' is invalid.
  737. pp$8.isAsyncFunction = function() {
  738. if (this.options.ecmaVersion < 8 || !this.isContextual("async"))
  739. { return false }
  740. skipWhiteSpace.lastIndex = this.pos;
  741. var skip = skipWhiteSpace.exec(this.input);
  742. var next = this.pos + skip[0].length, after;
  743. return !lineBreak.test(this.input.slice(this.pos, next)) &&
  744. this.input.slice(next, next + 8) === "function" &&
  745. (next + 8 === this.input.length ||
  746. !(isIdentifierChar(after = this.input.charCodeAt(next + 8)) || after > 0xd7ff && after < 0xdc00))
  747. };
  748. // Parse a single statement.
  749. //
  750. // If expecting a statement and finding a slash operator, parse a
  751. // regular expression literal. This is to handle cases like
  752. // `if (foo) /blah/.exec(foo)`, where looking at the previous token
  753. // does not help.
  754. pp$8.parseStatement = function(context, topLevel, exports) {
  755. var starttype = this.type, node = this.startNode(), kind;
  756. if (this.isLet(context)) {
  757. starttype = types$1._var;
  758. kind = "let";
  759. }
  760. // Most types of statements are recognized by the keyword they
  761. // start with. Many are trivial to parse, some require a bit of
  762. // complexity.
  763. switch (starttype) {
  764. case types$1._break: case types$1._continue: return this.parseBreakContinueStatement(node, starttype.keyword)
  765. case types$1._debugger: return this.parseDebuggerStatement(node)
  766. case types$1._do: return this.parseDoStatement(node)
  767. case types$1._for: return this.parseForStatement(node)
  768. case types$1._function:
  769. // Function as sole body of either an if statement or a labeled statement
  770. // works, but not when it is part of a labeled statement that is the sole
  771. // body of an if statement.
  772. if ((context && (this.strict || context !== "if" && context !== "label")) && this.options.ecmaVersion >= 6) { this.unexpected(); }
  773. return this.parseFunctionStatement(node, false, !context)
  774. case types$1._class:
  775. if (context) { this.unexpected(); }
  776. return this.parseClass(node, true)
  777. case types$1._if: return this.parseIfStatement(node)
  778. case types$1._return: return this.parseReturnStatement(node)
  779. case types$1._switch: return this.parseSwitchStatement(node)
  780. case types$1._throw: return this.parseThrowStatement(node)
  781. case types$1._try: return this.parseTryStatement(node)
  782. case types$1._const: case types$1._var:
  783. kind = kind || this.value;
  784. if (context && kind !== "var") { this.unexpected(); }
  785. return this.parseVarStatement(node, kind)
  786. case types$1._while: return this.parseWhileStatement(node)
  787. case types$1._with: return this.parseWithStatement(node)
  788. case types$1.braceL: return this.parseBlock(true, node)
  789. case types$1.semi: return this.parseEmptyStatement(node)
  790. case types$1._export:
  791. case types$1._import:
  792. if (this.options.ecmaVersion > 10 && starttype === types$1._import) {
  793. skipWhiteSpace.lastIndex = this.pos;
  794. var skip = skipWhiteSpace.exec(this.input);
  795. var next = this.pos + skip[0].length, nextCh = this.input.charCodeAt(next);
  796. if (nextCh === 40 || nextCh === 46) // '(' or '.'
  797. { return this.parseExpressionStatement(node, this.parseExpression()) }
  798. }
  799. if (!this.options.allowImportExportEverywhere) {
  800. if (!topLevel)
  801. { this.raise(this.start, "'import' and 'export' may only appear at the top level"); }
  802. if (!this.inModule)
  803. { this.raise(this.start, "'import' and 'export' may appear only with 'sourceType: module'"); }
  804. }
  805. return starttype === types$1._import ? this.parseImport(node) : this.parseExport(node, exports)
  806. // If the statement does not start with a statement keyword or a
  807. // brace, it's an ExpressionStatement or LabeledStatement. We
  808. // simply start parsing an expression, and afterwards, if the
  809. // next token is a colon and the expression was a simple
  810. // Identifier node, we switch to interpreting it as a label.
  811. default:
  812. if (this.isAsyncFunction()) {
  813. if (context) { this.unexpected(); }
  814. this.next();
  815. return this.parseFunctionStatement(node, true, !context)
  816. }
  817. var maybeName = this.value, expr = this.parseExpression();
  818. if (starttype === types$1.name && expr.type === "Identifier" && this.eat(types$1.colon))
  819. { return this.parseLabeledStatement(node, maybeName, expr, context) }
  820. else { return this.parseExpressionStatement(node, expr) }
  821. }
  822. };
  823. pp$8.parseBreakContinueStatement = function(node, keyword) {
  824. var isBreak = keyword === "break";
  825. this.next();
  826. if (this.eat(types$1.semi) || this.insertSemicolon()) { node.label = null; }
  827. else if (this.type !== types$1.name) { this.unexpected(); }
  828. else {
  829. node.label = this.parseIdent();
  830. this.semicolon();
  831. }
  832. // Verify that there is an actual destination to break or
  833. // continue to.
  834. var i = 0;
  835. for (; i < this.labels.length; ++i) {
  836. var lab = this.labels[i];
  837. if (node.label == null || lab.name === node.label.name) {
  838. if (lab.kind != null && (isBreak || lab.kind === "loop")) { break }
  839. if (node.label && isBreak) { break }
  840. }
  841. }
  842. if (i === this.labels.length) { this.raise(node.start, "Unsyntactic " + keyword); }
  843. return this.finishNode(node, isBreak ? "BreakStatement" : "ContinueStatement")
  844. };
  845. pp$8.parseDebuggerStatement = function(node) {
  846. this.next();
  847. this.semicolon();
  848. return this.finishNode(node, "DebuggerStatement")
  849. };
  850. pp$8.parseDoStatement = function(node) {
  851. this.next();
  852. this.labels.push(loopLabel);
  853. node.body = this.parseStatement("do");
  854. this.labels.pop();
  855. this.expect(types$1._while);
  856. node.test = this.parseParenExpression();
  857. if (this.options.ecmaVersion >= 6)
  858. { this.eat(types$1.semi); }
  859. else
  860. { this.semicolon(); }
  861. return this.finishNode(node, "DoWhileStatement")
  862. };
  863. // Disambiguating between a `for` and a `for`/`in` or `for`/`of`
  864. // loop is non-trivial. Basically, we have to parse the init `var`
  865. // statement or expression, disallowing the `in` operator (see
  866. // the second parameter to `parseExpression`), and then check
  867. // whether the next token is `in` or `of`. When there is no init
  868. // part (semicolon immediately after the opening parenthesis), it
  869. // is a regular `for` loop.
  870. pp$8.parseForStatement = function(node) {
  871. this.next();
  872. var awaitAt = (this.options.ecmaVersion >= 9 && this.canAwait && this.eatContextual("await")) ? this.lastTokStart : -1;
  873. this.labels.push(loopLabel);
  874. this.enterScope(0);
  875. this.expect(types$1.parenL);
  876. if (this.type === types$1.semi) {
  877. if (awaitAt > -1) { this.unexpected(awaitAt); }
  878. return this.parseFor(node, null)
  879. }
  880. var isLet = this.isLet();
  881. if (this.type === types$1._var || this.type === types$1._const || isLet) {
  882. var init$1 = this.startNode(), kind = isLet ? "let" : this.value;
  883. this.next();
  884. this.parseVar(init$1, true, kind);
  885. this.finishNode(init$1, "VariableDeclaration");
  886. if ((this.type === types$1._in || (this.options.ecmaVersion >= 6 && this.isContextual("of"))) && init$1.declarations.length === 1) {
  887. if (this.options.ecmaVersion >= 9) {
  888. if (this.type === types$1._in) {
  889. if (awaitAt > -1) { this.unexpected(awaitAt); }
  890. } else { node.await = awaitAt > -1; }
  891. }
  892. return this.parseForIn(node, init$1)
  893. }
  894. if (awaitAt > -1) { this.unexpected(awaitAt); }
  895. return this.parseFor(node, init$1)
  896. }
  897. var startsWithLet = this.isContextual("let"), isForOf = false;
  898. var containsEsc = this.containsEsc;
  899. var refDestructuringErrors = new DestructuringErrors;
  900. var initPos = this.start;
  901. var init = awaitAt > -1
  902. ? this.parseExprSubscripts(refDestructuringErrors, "await")
  903. : this.parseExpression(true, refDestructuringErrors);
  904. if (this.type === types$1._in || (isForOf = this.options.ecmaVersion >= 6 && this.isContextual("of"))) {
  905. if (awaitAt > -1) { // implies `ecmaVersion >= 9` (see declaration of awaitAt)
  906. if (this.type === types$1._in) { this.unexpected(awaitAt); }
  907. node.await = true;
  908. } else if (isForOf && this.options.ecmaVersion >= 8) {
  909. if (init.start === initPos && !containsEsc && init.type === "Identifier" && init.name === "async") { this.unexpected(); }
  910. else if (this.options.ecmaVersion >= 9) { node.await = false; }
  911. }
  912. if (startsWithLet && isForOf) { this.raise(init.start, "The left-hand side of a for-of loop may not start with 'let'."); }
  913. this.toAssignable(init, false, refDestructuringErrors);
  914. this.checkLValPattern(init);
  915. return this.parseForIn(node, init)
  916. } else {
  917. this.checkExpressionErrors(refDestructuringErrors, true);
  918. }
  919. if (awaitAt > -1) { this.unexpected(awaitAt); }
  920. return this.parseFor(node, init)
  921. };
  922. pp$8.parseFunctionStatement = function(node, isAsync, declarationPosition) {
  923. this.next();
  924. return this.parseFunction(node, FUNC_STATEMENT | (declarationPosition ? 0 : FUNC_HANGING_STATEMENT), false, isAsync)
  925. };
  926. pp$8.parseIfStatement = function(node) {
  927. this.next();
  928. node.test = this.parseParenExpression();
  929. // allow function declarations in branches, but only in non-strict mode
  930. node.consequent = this.parseStatement("if");
  931. node.alternate = this.eat(types$1._else) ? this.parseStatement("if") : null;
  932. return this.finishNode(node, "IfStatement")
  933. };
  934. pp$8.parseReturnStatement = function(node) {
  935. if (!this.inFunction && !this.options.allowReturnOutsideFunction)
  936. { this.raise(this.start, "'return' outside of function"); }
  937. this.next();
  938. // In `return` (and `break`/`continue`), the keywords with
  939. // optional arguments, we eagerly look for a semicolon or the
  940. // possibility to insert one.
  941. if (this.eat(types$1.semi) || this.insertSemicolon()) { node.argument = null; }
  942. else { node.argument = this.parseExpression(); this.semicolon(); }
  943. return this.finishNode(node, "ReturnStatement")
  944. };
  945. pp$8.parseSwitchStatement = function(node) {
  946. this.next();
  947. node.discriminant = this.parseParenExpression();
  948. node.cases = [];
  949. this.expect(types$1.braceL);
  950. this.labels.push(switchLabel);
  951. this.enterScope(0);
  952. // Statements under must be grouped (by label) in SwitchCase
  953. // nodes. `cur` is used to keep the node that we are currently
  954. // adding statements to.
  955. var cur;
  956. for (var sawDefault = false; this.type !== types$1.braceR;) {
  957. if (this.type === types$1._case || this.type === types$1._default) {
  958. var isCase = this.type === types$1._case;
  959. if (cur) { this.finishNode(cur, "SwitchCase"); }
  960. node.cases.push(cur = this.startNode());
  961. cur.consequent = [];
  962. this.next();
  963. if (isCase) {
  964. cur.test = this.parseExpression();
  965. } else {
  966. if (sawDefault) { this.raiseRecoverable(this.lastTokStart, "Multiple default clauses"); }
  967. sawDefault = true;
  968. cur.test = null;
  969. }
  970. this.expect(types$1.colon);
  971. } else {
  972. if (!cur) { this.unexpected(); }
  973. cur.consequent.push(this.parseStatement(null));
  974. }
  975. }
  976. this.exitScope();
  977. if (cur) { this.finishNode(cur, "SwitchCase"); }
  978. this.next(); // Closing brace
  979. this.labels.pop();
  980. return this.finishNode(node, "SwitchStatement")
  981. };
  982. pp$8.parseThrowStatement = function(node) {
  983. this.next();
  984. if (lineBreak.test(this.input.slice(this.lastTokEnd, this.start)))
  985. { this.raise(this.lastTokEnd, "Illegal newline after throw"); }
  986. node.argument = this.parseExpression();
  987. this.semicolon();
  988. return this.finishNode(node, "ThrowStatement")
  989. };
  990. // Reused empty array added for node fields that are always empty.
  991. var empty$1 = [];
  992. pp$8.parseCatchClauseParam = function() {
  993. var param = this.parseBindingAtom();
  994. var simple = param.type === "Identifier";
  995. this.enterScope(simple ? SCOPE_SIMPLE_CATCH : 0);
  996. this.checkLValPattern(param, simple ? BIND_SIMPLE_CATCH : BIND_LEXICAL);
  997. this.expect(types$1.parenR);
  998. return param
  999. };
  1000. pp$8.parseTryStatement = function(node) {
  1001. this.next();
  1002. node.block = this.parseBlock();
  1003. node.handler = null;
  1004. if (this.type === types$1._catch) {
  1005. var clause = this.startNode();
  1006. this.next();
  1007. if (this.eat(types$1.parenL)) {
  1008. clause.param = this.parseCatchClauseParam();
  1009. } else {
  1010. if (this.options.ecmaVersion < 10) { this.unexpected(); }
  1011. clause.param = null;
  1012. this.enterScope(0);
  1013. }
  1014. clause.body = this.parseBlock(false);
  1015. this.exitScope();
  1016. node.handler = this.finishNode(clause, "CatchClause");
  1017. }
  1018. node.finalizer = this.eat(types$1._finally) ? this.parseBlock() : null;
  1019. if (!node.handler && !node.finalizer)
  1020. { this.raise(node.start, "Missing catch or finally clause"); }
  1021. return this.finishNode(node, "TryStatement")
  1022. };
  1023. pp$8.parseVarStatement = function(node, kind, allowMissingInitializer) {
  1024. this.next();
  1025. this.parseVar(node, false, kind, allowMissingInitializer);
  1026. this.semicolon();
  1027. return this.finishNode(node, "VariableDeclaration")
  1028. };
  1029. pp$8.parseWhileStatement = function(node) {
  1030. this.next();
  1031. node.test = this.parseParenExpression();
  1032. this.labels.push(loopLabel);
  1033. node.body = this.parseStatement("while");
  1034. this.labels.pop();
  1035. return this.finishNode(node, "WhileStatement")
  1036. };
  1037. pp$8.parseWithStatement = function(node) {
  1038. if (this.strict) { this.raise(this.start, "'with' in strict mode"); }
  1039. this.next();
  1040. node.object = this.parseParenExpression();
  1041. node.body = this.parseStatement("with");
  1042. return this.finishNode(node, "WithStatement")
  1043. };
  1044. pp$8.parseEmptyStatement = function(node) {
  1045. this.next();
  1046. return this.finishNode(node, "EmptyStatement")
  1047. };
  1048. pp$8.parseLabeledStatement = function(node, maybeName, expr, context) {
  1049. for (var i$1 = 0, list = this.labels; i$1 < list.length; i$1 += 1)
  1050. {
  1051. var label = list[i$1];
  1052. if (label.name === maybeName)
  1053. { this.raise(expr.start, "Label '" + maybeName + "' is already declared");
  1054. } }
  1055. var kind = this.type.isLoop ? "loop" : this.type === types$1._switch ? "switch" : null;
  1056. for (var i = this.labels.length - 1; i >= 0; i--) {
  1057. var label$1 = this.labels[i];
  1058. if (label$1.statementStart === node.start) {
  1059. // Update information about previous labels on this node
  1060. label$1.statementStart = this.start;
  1061. label$1.kind = kind;
  1062. } else { break }
  1063. }
  1064. this.labels.push({name: maybeName, kind: kind, statementStart: this.start});
  1065. node.body = this.parseStatement(context ? context.indexOf("label") === -1 ? context + "label" : context : "label");
  1066. this.labels.pop();
  1067. node.label = expr;
  1068. return this.finishNode(node, "LabeledStatement")
  1069. };
  1070. pp$8.parseExpressionStatement = function(node, expr) {
  1071. node.expression = expr;
  1072. this.semicolon();
  1073. return this.finishNode(node, "ExpressionStatement")
  1074. };
  1075. // Parse a semicolon-enclosed block of statements, handling `"use
  1076. // strict"` declarations when `allowStrict` is true (used for
  1077. // function bodies).
  1078. pp$8.parseBlock = function(createNewLexicalScope, node, exitStrict) {
  1079. if ( createNewLexicalScope === void 0 ) createNewLexicalScope = true;
  1080. if ( node === void 0 ) node = this.startNode();
  1081. node.body = [];
  1082. this.expect(types$1.braceL);
  1083. if (createNewLexicalScope) { this.enterScope(0); }
  1084. while (this.type !== types$1.braceR) {
  1085. var stmt = this.parseStatement(null);
  1086. node.body.push(stmt);
  1087. }
  1088. if (exitStrict) { this.strict = false; }
  1089. this.next();
  1090. if (createNewLexicalScope) { this.exitScope(); }
  1091. return this.finishNode(node, "BlockStatement")
  1092. };
  1093. // Parse a regular `for` loop. The disambiguation code in
  1094. // `parseStatement` will already have parsed the init statement or
  1095. // expression.
  1096. pp$8.parseFor = function(node, init) {
  1097. node.init = init;
  1098. this.expect(types$1.semi);
  1099. node.test = this.type === types$1.semi ? null : this.parseExpression();
  1100. this.expect(types$1.semi);
  1101. node.update = this.type === types$1.parenR ? null : this.parseExpression();
  1102. this.expect(types$1.parenR);
  1103. node.body = this.parseStatement("for");
  1104. this.exitScope();
  1105. this.labels.pop();
  1106. return this.finishNode(node, "ForStatement")
  1107. };
  1108. // Parse a `for`/`in` and `for`/`of` loop, which are almost
  1109. // same from parser's perspective.
  1110. pp$8.parseForIn = function(node, init) {
  1111. var isForIn = this.type === types$1._in;
  1112. this.next();
  1113. if (
  1114. init.type === "VariableDeclaration" &&
  1115. init.declarations[0].init != null &&
  1116. (
  1117. !isForIn ||
  1118. this.options.ecmaVersion < 8 ||
  1119. this.strict ||
  1120. init.kind !== "var" ||
  1121. init.declarations[0].id.type !== "Identifier"
  1122. )
  1123. ) {
  1124. this.raise(
  1125. init.start,
  1126. ((isForIn ? "for-in" : "for-of") + " loop variable declaration may not have an initializer")
  1127. );
  1128. }
  1129. node.left = init;
  1130. node.right = isForIn ? this.parseExpression() : this.parseMaybeAssign();
  1131. this.expect(types$1.parenR);
  1132. node.body = this.parseStatement("for");
  1133. this.exitScope();
  1134. this.labels.pop();
  1135. return this.finishNode(node, isForIn ? "ForInStatement" : "ForOfStatement")
  1136. };
  1137. // Parse a list of variable declarations.
  1138. pp$8.parseVar = function(node, isFor, kind, allowMissingInitializer) {
  1139. node.declarations = [];
  1140. node.kind = kind;
  1141. for (;;) {
  1142. var decl = this.startNode();
  1143. this.parseVarId(decl, kind);
  1144. if (this.eat(types$1.eq)) {
  1145. decl.init = this.parseMaybeAssign(isFor);
  1146. } else if (!allowMissingInitializer && kind === "const" && !(this.type === types$1._in || (this.options.ecmaVersion >= 6 && this.isContextual("of")))) {
  1147. this.unexpected();
  1148. } else if (!allowMissingInitializer && decl.id.type !== "Identifier" && !(isFor && (this.type === types$1._in || this.isContextual("of")))) {
  1149. this.raise(this.lastTokEnd, "Complex binding patterns require an initialization value");
  1150. } else {
  1151. decl.init = null;
  1152. }
  1153. node.declarations.push(this.finishNode(decl, "VariableDeclarator"));
  1154. if (!this.eat(types$1.comma)) { break }
  1155. }
  1156. return node
  1157. };
  1158. pp$8.parseVarId = function(decl, kind) {
  1159. decl.id = this.parseBindingAtom();
  1160. this.checkLValPattern(decl.id, kind === "var" ? BIND_VAR : BIND_LEXICAL, false);
  1161. };
  1162. var FUNC_STATEMENT = 1, FUNC_HANGING_STATEMENT = 2, FUNC_NULLABLE_ID = 4;
  1163. // Parse a function declaration or literal (depending on the
  1164. // `statement & FUNC_STATEMENT`).
  1165. // Remove `allowExpressionBody` for 7.0.0, as it is only called with false
  1166. pp$8.parseFunction = function(node, statement, allowExpressionBody, isAsync, forInit) {
  1167. this.initFunction(node);
  1168. if (this.options.ecmaVersion >= 9 || this.options.ecmaVersion >= 6 && !isAsync) {
  1169. if (this.type === types$1.star && (statement & FUNC_HANGING_STATEMENT))
  1170. { this.unexpected(); }
  1171. node.generator = this.eat(types$1.star);
  1172. }
  1173. if (this.options.ecmaVersion >= 8)
  1174. { node.async = !!isAsync; }
  1175. if (statement & FUNC_STATEMENT) {
  1176. node.id = (statement & FUNC_NULLABLE_ID) && this.type !== types$1.name ? null : this.parseIdent();
  1177. if (node.id && !(statement & FUNC_HANGING_STATEMENT))
  1178. // If it is a regular function declaration in sloppy mode, then it is
  1179. // subject to Annex B semantics (BIND_FUNCTION). Otherwise, the binding
  1180. // mode depends on properties of the current scope (see
  1181. // treatFunctionsAsVar).
  1182. { this.checkLValSimple(node.id, (this.strict || node.generator || node.async) ? this.treatFunctionsAsVar ? BIND_VAR : BIND_LEXICAL : BIND_FUNCTION); }
  1183. }
  1184. var oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldAwaitIdentPos = this.awaitIdentPos;
  1185. this.yieldPos = 0;
  1186. this.awaitPos = 0;
  1187. this.awaitIdentPos = 0;
  1188. this.enterScope(functionFlags(node.async, node.generator));
  1189. if (!(statement & FUNC_STATEMENT))
  1190. { node.id = this.type === types$1.name ? this.parseIdent() : null; }
  1191. this.parseFunctionParams(node);
  1192. this.parseFunctionBody(node, allowExpressionBody, false, forInit);
  1193. this.yieldPos = oldYieldPos;
  1194. this.awaitPos = oldAwaitPos;
  1195. this.awaitIdentPos = oldAwaitIdentPos;
  1196. return this.finishNode(node, (statement & FUNC_STATEMENT) ? "FunctionDeclaration" : "FunctionExpression")
  1197. };
  1198. pp$8.parseFunctionParams = function(node) {
  1199. this.expect(types$1.parenL);
  1200. node.params = this.parseBindingList(types$1.parenR, false, this.options.ecmaVersion >= 8);
  1201. this.checkYieldAwaitInDefaultParams();
  1202. };
  1203. // Parse a class declaration or literal (depending on the
  1204. // `isStatement` parameter).
  1205. pp$8.parseClass = function(node, isStatement) {
  1206. this.next();
  1207. // ecma-262 14.6 Class Definitions
  1208. // A class definition is always strict mode code.
  1209. var oldStrict = this.strict;
  1210. this.strict = true;
  1211. this.parseClassId(node, isStatement);
  1212. this.parseClassSuper(node);
  1213. var privateNameMap = this.enterClassBody();
  1214. var classBody = this.startNode();
  1215. var hadConstructor = false;
  1216. classBody.body = [];
  1217. this.expect(types$1.braceL);
  1218. while (this.type !== types$1.braceR) {
  1219. var element = this.parseClassElement(node.superClass !== null);
  1220. if (element) {
  1221. classBody.body.push(element);
  1222. if (element.type === "MethodDefinition" && element.kind === "constructor") {
  1223. if (hadConstructor) { this.raiseRecoverable(element.start, "Duplicate constructor in the same class"); }
  1224. hadConstructor = true;
  1225. } else if (element.key && element.key.type === "PrivateIdentifier" && isPrivateNameConflicted(privateNameMap, element)) {
  1226. this.raiseRecoverable(element.key.start, ("Identifier '#" + (element.key.name) + "' has already been declared"));
  1227. }
  1228. }
  1229. }
  1230. this.strict = oldStrict;
  1231. this.next();
  1232. node.body = this.finishNode(classBody, "ClassBody");
  1233. this.exitClassBody();
  1234. return this.finishNode(node, isStatement ? "ClassDeclaration" : "ClassExpression")
  1235. };
  1236. pp$8.parseClassElement = function(constructorAllowsSuper) {
  1237. if (this.eat(types$1.semi)) { return null }
  1238. var ecmaVersion = this.options.ecmaVersion;
  1239. var node = this.startNode();
  1240. var keyName = "";
  1241. var isGenerator = false;
  1242. var isAsync = false;
  1243. var kind = "method";
  1244. var isStatic = false;
  1245. if (this.eatContextual("static")) {
  1246. // Parse static init block
  1247. if (ecmaVersion >= 13 && this.eat(types$1.braceL)) {
  1248. this.parseClassStaticBlock(node);
  1249. return node
  1250. }
  1251. if (this.isClassElementNameStart() || this.type === types$1.star) {
  1252. isStatic = true;
  1253. } else {
  1254. keyName = "static";
  1255. }
  1256. }
  1257. node.static = isStatic;
  1258. if (!keyName && ecmaVersion >= 8 && this.eatContextual("async")) {
  1259. if ((this.isClassElementNameStart() || this.type === types$1.star) && !this.canInsertSemicolon()) {
  1260. isAsync = true;
  1261. } else {
  1262. keyName = "async";
  1263. }
  1264. }
  1265. if (!keyName && (ecmaVersion >= 9 || !isAsync) && this.eat(types$1.star)) {
  1266. isGenerator = true;
  1267. }
  1268. if (!keyName && !isAsync && !isGenerator) {
  1269. var lastValue = this.value;
  1270. if (this.eatContextual("get") || this.eatContextual("set")) {
  1271. if (this.isClassElementNameStart()) {
  1272. kind = lastValue;
  1273. } else {
  1274. keyName = lastValue;
  1275. }
  1276. }
  1277. }
  1278. // Parse element name
  1279. if (keyName) {
  1280. // 'async', 'get', 'set', or 'static' were not a keyword contextually.
  1281. // The last token is any of those. Make it the element name.
  1282. node.computed = false;
  1283. node.key = this.startNodeAt(this.lastTokStart, this.lastTokStartLoc);
  1284. node.key.name = keyName;
  1285. this.finishNode(node.key, "Identifier");
  1286. } else {
  1287. this.parseClassElementName(node);
  1288. }
  1289. // Parse element value
  1290. if (ecmaVersion < 13 || this.type === types$1.parenL || kind !== "method" || isGenerator || isAsync) {
  1291. var isConstructor = !node.static && checkKeyName(node, "constructor");
  1292. var allowsDirectSuper = isConstructor && constructorAllowsSuper;
  1293. // Couldn't move this check into the 'parseClassMethod' method for backward compatibility.
  1294. if (isConstructor && kind !== "method") { this.raise(node.key.start, "Constructor can't have get/set modifier"); }
  1295. node.kind = isConstructor ? "constructor" : kind;
  1296. this.parseClassMethod(node, isGenerator, isAsync, allowsDirectSuper);
  1297. } else {
  1298. this.parseClassField(node);
  1299. }
  1300. return node
  1301. };
  1302. pp$8.isClassElementNameStart = function() {
  1303. return (
  1304. this.type === types$1.name ||
  1305. this.type === types$1.privateId ||
  1306. this.type === types$1.num ||
  1307. this.type === types$1.string ||
  1308. this.type === types$1.bracketL ||
  1309. this.type.keyword
  1310. )
  1311. };
  1312. pp$8.parseClassElementName = function(element) {
  1313. if (this.type === types$1.privateId) {
  1314. if (this.value === "constructor") {
  1315. this.raise(this.start, "Classes can't have an element named '#constructor'");
  1316. }
  1317. element.computed = false;
  1318. element.key = this.parsePrivateIdent();
  1319. } else {
  1320. this.parsePropertyName(element);
  1321. }
  1322. };
  1323. pp$8.parseClassMethod = function(method, isGenerator, isAsync, allowsDirectSuper) {
  1324. // Check key and flags
  1325. var key = method.key;
  1326. if (method.kind === "constructor") {
  1327. if (isGenerator) { this.raise(key.start, "Constructor can't be a generator"); }
  1328. if (isAsync) { this.raise(key.start, "Constructor can't be an async method"); }
  1329. } else if (method.static && checkKeyName(method, "prototype")) {
  1330. this.raise(key.start, "Classes may not have a static property named prototype");
  1331. }
  1332. // Parse value
  1333. var value = method.value = this.parseMethod(isGenerator, isAsync, allowsDirectSuper);
  1334. // Check value
  1335. if (method.kind === "get" && value.params.length !== 0)
  1336. { this.raiseRecoverable(value.start, "getter should have no params"); }
  1337. if (method.kind === "set" && value.params.length !== 1)
  1338. { this.raiseRecoverable(value.start, "setter should have exactly one param"); }
  1339. if (method.kind === "set" && value.params[0].type === "RestElement")
  1340. { this.raiseRecoverable(value.params[0].start, "Setter cannot use rest params"); }
  1341. return this.finishNode(method, "MethodDefinition")
  1342. };
  1343. pp$8.parseClassField = function(field) {
  1344. if (checkKeyName(field, "constructor")) {
  1345. this.raise(field.key.start, "Classes can't have a field named 'constructor'");
  1346. } else if (field.static && checkKeyName(field, "prototype")) {
  1347. this.raise(field.key.start, "Classes can't have a static field named 'prototype'");
  1348. }
  1349. if (this.eat(types$1.eq)) {
  1350. // To raise SyntaxError if 'arguments' exists in the initializer.
  1351. var scope = this.currentThisScope();
  1352. var inClassFieldInit = scope.inClassFieldInit;
  1353. scope.inClassFieldInit = true;
  1354. field.value = this.parseMaybeAssign();
  1355. scope.inClassFieldInit = inClassFieldInit;
  1356. } else {
  1357. field.value = null;
  1358. }
  1359. this.semicolon();
  1360. return this.finishNode(field, "PropertyDefinition")
  1361. };
  1362. pp$8.parseClassStaticBlock = function(node) {
  1363. node.body = [];
  1364. var oldLabels = this.labels;
  1365. this.labels = [];
  1366. this.enterScope(SCOPE_CLASS_STATIC_BLOCK | SCOPE_SUPER);
  1367. while (this.type !== types$1.braceR) {
  1368. var stmt = this.parseStatement(null);
  1369. node.body.push(stmt);
  1370. }
  1371. this.next();
  1372. this.exitScope();
  1373. this.labels = oldLabels;
  1374. return this.finishNode(node, "StaticBlock")
  1375. };
  1376. pp$8.parseClassId = function(node, isStatement) {
  1377. if (this.type === types$1.name) {
  1378. node.id = this.parseIdent();
  1379. if (isStatement)
  1380. { this.checkLValSimple(node.id, BIND_LEXICAL, false); }
  1381. } else {
  1382. if (isStatement === true)
  1383. { this.unexpected(); }
  1384. node.id = null;
  1385. }
  1386. };
  1387. pp$8.parseClassSuper = function(node) {
  1388. node.superClass = this.eat(types$1._extends) ? this.parseExprSubscripts(null, false) : null;
  1389. };
  1390. pp$8.enterClassBody = function() {
  1391. var element = {declared: Object.create(null), used: []};
  1392. this.privateNameStack.push(element);
  1393. return element.declared
  1394. };
  1395. pp$8.exitClassBody = function() {
  1396. var ref = this.privateNameStack.pop();
  1397. var declared = ref.declared;
  1398. var used = ref.used;
  1399. if (!this.options.checkPrivateFields) { return }
  1400. var len = this.privateNameStack.length;
  1401. var parent = len === 0 ? null : this.privateNameStack[len - 1];
  1402. for (var i = 0; i < used.length; ++i) {
  1403. var id = used[i];
  1404. if (!hasOwn(declared, id.name)) {
  1405. if (parent) {
  1406. parent.used.push(id);
  1407. } else {
  1408. this.raiseRecoverable(id.start, ("Private field '#" + (id.name) + "' must be declared in an enclosing class"));
  1409. }
  1410. }
  1411. }
  1412. };
  1413. function isPrivateNameConflicted(privateNameMap, element) {
  1414. var name = element.key.name;
  1415. var curr = privateNameMap[name];
  1416. var next = "true";
  1417. if (element.type === "MethodDefinition" && (element.kind === "get" || element.kind === "set")) {
  1418. next = (element.static ? "s" : "i") + element.kind;
  1419. }
  1420. // `class { get #a(){}; static set #a(_){} }` is also conflict.
  1421. if (
  1422. curr === "iget" && next === "iset" ||
  1423. curr === "iset" && next === "iget" ||
  1424. curr === "sget" && next === "sset" ||
  1425. curr === "sset" && next === "sget"
  1426. ) {
  1427. privateNameMap[name] = "true";
  1428. return false
  1429. } else if (!curr) {
  1430. privateNameMap[name] = next;
  1431. return false
  1432. } else {
  1433. return true
  1434. }
  1435. }
  1436. function checkKeyName(node, name) {
  1437. var computed = node.computed;
  1438. var key = node.key;
  1439. return !computed && (
  1440. key.type === "Identifier" && key.name === name ||
  1441. key.type === "Literal" && key.value === name
  1442. )
  1443. }
  1444. // Parses module export declaration.
  1445. pp$8.parseExportAllDeclaration = function(node, exports) {
  1446. if (this.options.ecmaVersion >= 11) {
  1447. if (this.eatContextual("as")) {
  1448. node.exported = this.parseModuleExportName();
  1449. this.checkExport(exports, node.exported, this.lastTokStart);
  1450. } else {
  1451. node.exported = null;
  1452. }
  1453. }
  1454. this.expectContextual("from");
  1455. if (this.type !== types$1.string) { this.unexpected(); }
  1456. node.source = this.parseExprAtom();
  1457. this.semicolon();
  1458. return this.finishNode(node, "ExportAllDeclaration")
  1459. };
  1460. pp$8.parseExport = function(node, exports) {
  1461. this.next();
  1462. // export * from '...'
  1463. if (this.eat(types$1.star)) {
  1464. return this.parseExportAllDeclaration(node, exports)
  1465. }
  1466. if (this.eat(types$1._default)) { // export default ...
  1467. this.checkExport(exports, "default", this.lastTokStart);
  1468. node.declaration = this.parseExportDefaultDeclaration();
  1469. return this.finishNode(node, "ExportDefaultDeclaration")
  1470. }
  1471. // export var|const|let|function|class ...
  1472. if (this.shouldParseExportStatement()) {
  1473. node.declaration = this.parseExportDeclaration(node);
  1474. if (node.declaration.type === "VariableDeclaration")
  1475. { this.checkVariableExport(exports, node.declaration.declarations); }
  1476. else
  1477. { this.checkExport(exports, node.declaration.id, node.declaration.id.start); }
  1478. node.specifiers = [];
  1479. node.source = null;
  1480. } else { // export { x, y as z } [from '...']
  1481. node.declaration = null;
  1482. node.specifiers = this.parseExportSpecifiers(exports);
  1483. if (this.eatContextual("from")) {
  1484. if (this.type !== types$1.string) { this.unexpected(); }
  1485. node.source = this.parseExprAtom();
  1486. } else {
  1487. for (var i = 0, list = node.specifiers; i < list.length; i += 1) {
  1488. // check for keywords used as local names
  1489. var spec = list[i];
  1490. this.checkUnreserved(spec.local);
  1491. // check if export is defined
  1492. this.checkLocalExport(spec.local);
  1493. if (spec.local.type === "Literal") {
  1494. this.raise(spec.local.start, "A string literal cannot be used as an exported binding without `from`.");
  1495. }
  1496. }
  1497. node.source = null;
  1498. }
  1499. this.semicolon();
  1500. }
  1501. return this.finishNode(node, "ExportNamedDeclaration")
  1502. };
  1503. pp$8.parseExportDeclaration = function(node) {
  1504. return this.parseStatement(null)
  1505. };
  1506. pp$8.parseExportDefaultDeclaration = function() {
  1507. var isAsync;
  1508. if (this.type === types$1._function || (isAsync = this.isAsyncFunction())) {
  1509. var fNode = this.startNode();
  1510. this.next();
  1511. if (isAsync) { this.next(); }
  1512. return this.parseFunction(fNode, FUNC_STATEMENT | FUNC_NULLABLE_ID, false, isAsync)
  1513. } else if (this.type === types$1._class) {
  1514. var cNode = this.startNode();
  1515. return this.parseClass(cNode, "nullableID")
  1516. } else {
  1517. var declaration = this.parseMaybeAssign();
  1518. this.semicolon();
  1519. return declaration
  1520. }
  1521. };
  1522. pp$8.checkExport = function(exports, name, pos) {
  1523. if (!exports) { return }
  1524. if (typeof name !== "string")
  1525. { name = name.type === "Identifier" ? name.name : name.value; }
  1526. if (hasOwn(exports, name))
  1527. { this.raiseRecoverable(pos, "Duplicate export '" + name + "'"); }
  1528. exports[name] = true;
  1529. };
  1530. pp$8.checkPatternExport = function(exports, pat) {
  1531. var type = pat.type;
  1532. if (type === "Identifier")
  1533. { this.checkExport(exports, pat, pat.start); }
  1534. else if (type === "ObjectPattern")
  1535. { for (var i = 0, list = pat.properties; i < list.length; i += 1)
  1536. {
  1537. var prop = list[i];
  1538. this.checkPatternExport(exports, prop);
  1539. } }
  1540. else if (type === "ArrayPattern")
  1541. { for (var i$1 = 0, list$1 = pat.elements; i$1 < list$1.length; i$1 += 1) {
  1542. var elt = list$1[i$1];
  1543. if (elt) { this.checkPatternExport(exports, elt); }
  1544. } }
  1545. else if (type === "Property")
  1546. { this.checkPatternExport(exports, pat.value); }
  1547. else if (type === "AssignmentPattern")
  1548. { this.checkPatternExport(exports, pat.left); }
  1549. else if (type === "RestElement")
  1550. { this.checkPatternExport(exports, pat.argument); }
  1551. };
  1552. pp$8.checkVariableExport = function(exports, decls) {
  1553. if (!exports) { return }
  1554. for (var i = 0, list = decls; i < list.length; i += 1)
  1555. {
  1556. var decl = list[i];
  1557. this.checkPatternExport(exports, decl.id);
  1558. }
  1559. };
  1560. pp$8.shouldParseExportStatement = function() {
  1561. return this.type.keyword === "var" ||
  1562. this.type.keyword === "const" ||
  1563. this.type.keyword === "class" ||
  1564. this.type.keyword === "function" ||
  1565. this.isLet() ||
  1566. this.isAsyncFunction()
  1567. };
  1568. // Parses a comma-separated list of module exports.
  1569. pp$8.parseExportSpecifier = function(exports) {
  1570. var node = this.startNode();
  1571. node.local = this.parseModuleExportName();
  1572. node.exported = this.eatContextual("as") ? this.parseModuleExportName() : node.local;
  1573. this.checkExport(
  1574. exports,
  1575. node.exported,
  1576. node.exported.start
  1577. );
  1578. return this.finishNode(node, "ExportSpecifier")
  1579. };
  1580. pp$8.parseExportSpecifiers = function(exports) {
  1581. var nodes = [], first = true;
  1582. // export { x, y as z } [from '...']
  1583. this.expect(types$1.braceL);
  1584. while (!this.eat(types$1.braceR)) {
  1585. if (!first) {
  1586. this.expect(types$1.comma);
  1587. if (this.afterTrailingComma(types$1.braceR)) { break }
  1588. } else { first = false; }
  1589. nodes.push(this.parseExportSpecifier(exports));
  1590. }
  1591. return nodes
  1592. };
  1593. // Parses import declaration.
  1594. pp$8.parseImport = function(node) {
  1595. this.next();
  1596. // import '...'
  1597. if (this.type === types$1.string) {
  1598. node.specifiers = empty$1;
  1599. node.source = this.parseExprAtom();
  1600. } else {
  1601. node.specifiers = this.parseImportSpecifiers();
  1602. this.expectContextual("from");
  1603. node.source = this.type === types$1.string ? this.parseExprAtom() : this.unexpected();
  1604. }
  1605. this.semicolon();
  1606. return this.finishNode(node, "ImportDeclaration")
  1607. };
  1608. // Parses a comma-separated list of module imports.
  1609. pp$8.parseImportSpecifier = function() {
  1610. var node = this.startNode();
  1611. node.imported = this.parseModuleExportName();
  1612. if (this.eatContextual("as")) {
  1613. node.local = this.parseIdent();
  1614. } else {
  1615. this.checkUnreserved(node.imported);
  1616. node.local = node.imported;
  1617. }
  1618. this.checkLValSimple(node.local, BIND_LEXICAL);
  1619. return this.finishNode(node, "ImportSpecifier")
  1620. };
  1621. pp$8.parseImportDefaultSpecifier = function() {
  1622. // import defaultObj, { x, y as z } from '...'
  1623. var node = this.startNode();
  1624. node.local = this.parseIdent();
  1625. this.checkLValSimple(node.local, BIND_LEXICAL);
  1626. return this.finishNode(node, "ImportDefaultSpecifier")
  1627. };
  1628. pp$8.parseImportNamespaceSpecifier = function() {
  1629. var node = this.startNode();
  1630. this.next();
  1631. this.expectContextual("as");
  1632. node.local = this.parseIdent();
  1633. this.checkLValSimple(node.local, BIND_LEXICAL);
  1634. return this.finishNode(node, "ImportNamespaceSpecifier")
  1635. };
  1636. pp$8.parseImportSpecifiers = function() {
  1637. var nodes = [], first = true;
  1638. if (this.type === types$1.name) {
  1639. nodes.push(this.parseImportDefaultSpecifier());
  1640. if (!this.eat(types$1.comma)) { return nodes }
  1641. }
  1642. if (this.type === types$1.star) {
  1643. nodes.push(this.parseImportNamespaceSpecifier());
  1644. return nodes
  1645. }
  1646. this.expect(types$1.braceL);
  1647. while (!this.eat(types$1.braceR)) {
  1648. if (!first) {
  1649. this.expect(types$1.comma);
  1650. if (this.afterTrailingComma(types$1.braceR)) { break }
  1651. } else { first = false; }
  1652. nodes.push(this.parseImportSpecifier());
  1653. }
  1654. return nodes
  1655. };
  1656. pp$8.parseModuleExportName = function() {
  1657. if (this.options.ecmaVersion >= 13 && this.type === types$1.string) {
  1658. var stringLiteral = this.parseLiteral(this.value);
  1659. if (loneSurrogate.test(stringLiteral.value)) {
  1660. this.raise(stringLiteral.start, "An export name cannot include a lone surrogate.");
  1661. }
  1662. return stringLiteral
  1663. }
  1664. return this.parseIdent(true)
  1665. };
  1666. // Set `ExpressionStatement#directive` property for directive prologues.
  1667. pp$8.adaptDirectivePrologue = function(statements) {
  1668. for (var i = 0; i < statements.length && this.isDirectiveCandidate(statements[i]); ++i) {
  1669. statements[i].directive = statements[i].expression.raw.slice(1, -1);
  1670. }
  1671. };
  1672. pp$8.isDirectiveCandidate = function(statement) {
  1673. return (
  1674. this.options.ecmaVersion >= 5 &&
  1675. statement.type === "ExpressionStatement" &&
  1676. statement.expression.type === "Literal" &&
  1677. typeof statement.expression.value === "string" &&
  1678. // Reject parenthesized strings.
  1679. (this.input[statement.start] === "\"" || this.input[statement.start] === "'")
  1680. )
  1681. };
  1682. var pp$7 = Parser.prototype;
  1683. // Convert existing expression atom to assignable pattern
  1684. // if possible.
  1685. pp$7.toAssignable = function(node, isBinding, refDestructuringErrors) {
  1686. if (this.options.ecmaVersion >= 6 && node) {
  1687. switch (node.type) {
  1688. case "Identifier":
  1689. if (this.inAsync && node.name === "await")
  1690. { this.raise(node.start, "Cannot use 'await' as identifier inside an async function"); }
  1691. break
  1692. case "ObjectPattern":
  1693. case "ArrayPattern":
  1694. case "AssignmentPattern":
  1695. case "RestElement":
  1696. break
  1697. case "ObjectExpression":
  1698. node.type = "ObjectPattern";
  1699. if (refDestructuringErrors) { this.checkPatternErrors(refDestructuringErrors, true); }
  1700. for (var i = 0, list = node.properties; i < list.length; i += 1) {
  1701. var prop = list[i];
  1702. this.toAssignable(prop, isBinding);
  1703. // Early error:
  1704. // AssignmentRestProperty[Yield, Await] :
  1705. // `...` DestructuringAssignmentTarget[Yield, Await]
  1706. //
  1707. // It is a Syntax Error if |DestructuringAssignmentTarget| is an |ArrayLiteral| or an |ObjectLiteral|.
  1708. if (
  1709. prop.type === "RestElement" &&
  1710. (prop.argument.type === "ArrayPattern" || prop.argument.type === "ObjectPattern")
  1711. ) {
  1712. this.raise(prop.argument.start, "Unexpected token");
  1713. }
  1714. }
  1715. break
  1716. case "Property":
  1717. // AssignmentProperty has type === "Property"
  1718. if (node.kind !== "init") { this.raise(node.key.start, "Object pattern can't contain getter or setter"); }
  1719. this.toAssignable(node.value, isBinding);
  1720. break
  1721. case "ArrayExpression":
  1722. node.type = "ArrayPattern";
  1723. if (refDestructuringErrors) { this.checkPatternErrors(refDestructuringErrors, true); }
  1724. this.toAssignableList(node.elements, isBinding);
  1725. break
  1726. case "SpreadElement":
  1727. node.type = "RestElement";
  1728. this.toAssignable(node.argument, isBinding);
  1729. if (node.argument.type === "AssignmentPattern")
  1730. { this.raise(node.argument.start, "Rest elements cannot have a default value"); }
  1731. break
  1732. case "AssignmentExpression":
  1733. if (node.operator !== "=") { this.raise(node.left.end, "Only '=' operator can be used for specifying default value."); }
  1734. node.type = "AssignmentPattern";
  1735. delete node.operator;
  1736. this.toAssignable(node.left, isBinding);
  1737. break
  1738. case "ParenthesizedExpression":
  1739. this.toAssignable(node.expression, isBinding, refDestructuringErrors);
  1740. break
  1741. case "ChainExpression":
  1742. this.raiseRecoverable(node.start, "Optional chaining cannot appear in left-hand side");
  1743. break
  1744. case "MemberExpression":
  1745. if (!isBinding) { break }
  1746. default:
  1747. this.raise(node.start, "Assigning to rvalue");
  1748. }
  1749. } else if (refDestructuringErrors) { this.checkPatternErrors(refDestructuringErrors, true); }
  1750. return node
  1751. };
  1752. // Convert list of expression atoms to binding list.
  1753. pp$7.toAssignableList = function(exprList, isBinding) {
  1754. var end = exprList.length;
  1755. for (var i = 0; i < end; i++) {
  1756. var elt = exprList[i];
  1757. if (elt) { this.toAssignable(elt, isBinding); }
  1758. }
  1759. if (end) {
  1760. var last = exprList[end - 1];
  1761. if (this.options.ecmaVersion === 6 && isBinding && last && last.type === "RestElement" && last.argument.type !== "Identifier")
  1762. { this.unexpected(last.argument.start); }
  1763. }
  1764. return exprList
  1765. };
  1766. // Parses spread element.
  1767. pp$7.parseSpread = function(refDestructuringErrors) {
  1768. var node = this.startNode();
  1769. this.next();
  1770. node.argument = this.parseMaybeAssign(false, refDestructuringErrors);
  1771. return this.finishNode(node, "SpreadElement")
  1772. };
  1773. pp$7.parseRestBinding = function() {
  1774. var node = this.startNode();
  1775. this.next();
  1776. // RestElement inside of a function parameter must be an identifier
  1777. if (this.options.ecmaVersion === 6 && this.type !== types$1.name)
  1778. { this.unexpected(); }
  1779. node.argument = this.parseBindingAtom();
  1780. return this.finishNode(node, "RestElement")
  1781. };
  1782. // Parses lvalue (assignable) atom.
  1783. pp$7.parseBindingAtom = function() {
  1784. if (this.options.ecmaVersion >= 6) {
  1785. switch (this.type) {
  1786. case types$1.bracketL:
  1787. var node = this.startNode();
  1788. this.next();
  1789. node.elements = this.parseBindingList(types$1.bracketR, true, true);
  1790. return this.finishNode(node, "ArrayPattern")
  1791. case types$1.braceL:
  1792. return this.parseObj(true)
  1793. }
  1794. }
  1795. return this.parseIdent()
  1796. };
  1797. pp$7.parseBindingList = function(close, allowEmpty, allowTrailingComma, allowModifiers) {
  1798. var elts = [], first = true;
  1799. while (!this.eat(close)) {
  1800. if (first) { first = false; }
  1801. else { this.expect(types$1.comma); }
  1802. if (allowEmpty && this.type === types$1.comma) {
  1803. elts.push(null);
  1804. } else if (allowTrailingComma && this.afterTrailingComma(close)) {
  1805. break
  1806. } else if (this.type === types$1.ellipsis) {
  1807. var rest = this.parseRestBinding();
  1808. this.parseBindingListItem(rest);
  1809. elts.push(rest);
  1810. if (this.type === types$1.comma) { this.raiseRecoverable(this.start, "Comma is not permitted after the rest element"); }
  1811. this.expect(close);
  1812. break
  1813. } else {
  1814. elts.push(this.parseAssignableListItem(allowModifiers));
  1815. }
  1816. }
  1817. return elts
  1818. };
  1819. pp$7.parseAssignableListItem = function(allowModifiers) {
  1820. var elem = this.parseMaybeDefault(this.start, this.startLoc);
  1821. this.parseBindingListItem(elem);
  1822. return elem
  1823. };
  1824. pp$7.parseBindingListItem = function(param) {
  1825. return param
  1826. };
  1827. // Parses assignment pattern around given atom if possible.
  1828. pp$7.parseMaybeDefault = function(startPos, startLoc, left) {
  1829. left = left || this.parseBindingAtom();
  1830. if (this.options.ecmaVersion < 6 || !this.eat(types$1.eq)) { return left }
  1831. var node = this.startNodeAt(startPos, startLoc);
  1832. node.left = left;
  1833. node.right = this.parseMaybeAssign();
  1834. return this.finishNode(node, "AssignmentPattern")
  1835. };
  1836. // The following three functions all verify that a node is an lvalue —
  1837. // something that can be bound, or assigned to. In order to do so, they perform
  1838. // a variety of checks:
  1839. //
  1840. // - Check that none of the bound/assigned-to identifiers are reserved words.
  1841. // - Record name declarations for bindings in the appropriate scope.
  1842. // - Check duplicate argument names, if checkClashes is set.
  1843. //
  1844. // If a complex binding pattern is encountered (e.g., object and array
  1845. // destructuring), the entire pattern is recursively checked.
  1846. //
  1847. // There are three versions of checkLVal*() appropriate for different
  1848. // circumstances:
  1849. //
  1850. // - checkLValSimple() shall be used if the syntactic construct supports
  1851. // nothing other than identifiers and member expressions. Parenthesized
  1852. // expressions are also correctly handled. This is generally appropriate for
  1853. // constructs for which the spec says
  1854. //
  1855. // > It is a Syntax Error if AssignmentTargetType of [the production] is not
  1856. // > simple.
  1857. //
  1858. // It is also appropriate for checking if an identifier is valid and not
  1859. // defined elsewhere, like import declarations or function/class identifiers.
  1860. //
  1861. // Examples where this is used include:
  1862. // a += …;
  1863. // import a from '…';
  1864. // where a is the node to be checked.
  1865. //
  1866. // - checkLValPattern() shall be used if the syntactic construct supports
  1867. // anything checkLValSimple() supports, as well as object and array
  1868. // destructuring patterns. This is generally appropriate for constructs for
  1869. // which the spec says
  1870. //
  1871. // > It is a Syntax Error if [the production] is neither an ObjectLiteral nor
  1872. // > an ArrayLiteral and AssignmentTargetType of [the production] is not
  1873. // > simple.
  1874. //
  1875. // Examples where this is used include:
  1876. // (a = …);
  1877. // const a = …;
  1878. // try { … } catch (a) { … }
  1879. // where a is the node to be checked.
  1880. //
  1881. // - checkLValInnerPattern() shall be used if the syntactic construct supports
  1882. // anything checkLValPattern() supports, as well as default assignment
  1883. // patterns, rest elements, and other constructs that may appear within an
  1884. // object or array destructuring pattern.
  1885. //
  1886. // As a special case, function parameters also use checkLValInnerPattern(),
  1887. // as they also support defaults and rest constructs.
  1888. //
  1889. // These functions deliberately support both assignment and binding constructs,
  1890. // as the logic for both is exceedingly similar. If the node is the target of
  1891. // an assignment, then bindingType should be set to BIND_NONE. Otherwise, it
  1892. // should be set to the appropriate BIND_* constant, like BIND_VAR or
  1893. // BIND_LEXICAL.
  1894. //
  1895. // If the function is called with a non-BIND_NONE bindingType, then
  1896. // additionally a checkClashes object may be specified to allow checking for
  1897. // duplicate argument names. checkClashes is ignored if the provided construct
  1898. // is an assignment (i.e., bindingType is BIND_NONE).
  1899. pp$7.checkLValSimple = function(expr, bindingType, checkClashes) {
  1900. if ( bindingType === void 0 ) bindingType = BIND_NONE;
  1901. var isBind = bindingType !== BIND_NONE;
  1902. switch (expr.type) {
  1903. case "Identifier":
  1904. if (this.strict && this.reservedWordsStrictBind.test(expr.name))
  1905. { this.raiseRecoverable(expr.start, (isBind ? "Binding " : "Assigning to ") + expr.name + " in strict mode"); }
  1906. if (isBind) {
  1907. if (bindingType === BIND_LEXICAL && expr.name === "let")
  1908. { this.raiseRecoverable(expr.start, "let is disallowed as a lexically bound name"); }
  1909. if (checkClashes) {
  1910. if (hasOwn(checkClashes, expr.name))
  1911. { this.raiseRecoverable(expr.start, "Argument name clash"); }
  1912. checkClashes[expr.name] = true;
  1913. }
  1914. if (bindingType !== BIND_OUTSIDE) { this.declareName(expr.name, bindingType, expr.start); }
  1915. }
  1916. break
  1917. case "ChainExpression":
  1918. this.raiseRecoverable(expr.start, "Optional chaining cannot appear in left-hand side");
  1919. break
  1920. case "MemberExpression":
  1921. if (isBind) { this.raiseRecoverable(expr.start, "Binding member expression"); }
  1922. break
  1923. case "ParenthesizedExpression":
  1924. if (isBind) { this.raiseRecoverable(expr.start, "Binding parenthesized expression"); }
  1925. return this.checkLValSimple(expr.expression, bindingType, checkClashes)
  1926. default:
  1927. this.raise(expr.start, (isBind ? "Binding" : "Assigning to") + " rvalue");
  1928. }
  1929. };
  1930. pp$7.checkLValPattern = function(expr, bindingType, checkClashes) {
  1931. if ( bindingType === void 0 ) bindingType = BIND_NONE;
  1932. switch (expr.type) {
  1933. case "ObjectPattern":
  1934. for (var i = 0, list = expr.properties; i < list.length; i += 1) {
  1935. var prop = list[i];
  1936. this.checkLValInnerPattern(prop, bindingType, checkClashes);
  1937. }
  1938. break
  1939. case "ArrayPattern":
  1940. for (var i$1 = 0, list$1 = expr.elements; i$1 < list$1.length; i$1 += 1) {
  1941. var elem = list$1[i$1];
  1942. if (elem) { this.checkLValInnerPattern(elem, bindingType, checkClashes); }
  1943. }
  1944. break
  1945. default:
  1946. this.checkLValSimple(expr, bindingType, checkClashes);
  1947. }
  1948. };
  1949. pp$7.checkLValInnerPattern = function(expr, bindingType, checkClashes) {
  1950. if ( bindingType === void 0 ) bindingType = BIND_NONE;
  1951. switch (expr.type) {
  1952. case "Property":
  1953. // AssignmentProperty has type === "Property"
  1954. this.checkLValInnerPattern(expr.value, bindingType, checkClashes);
  1955. break
  1956. case "AssignmentPattern":
  1957. this.checkLValPattern(expr.left, bindingType, checkClashes);
  1958. break
  1959. case "RestElement":
  1960. this.checkLValPattern(expr.argument, bindingType, checkClashes);
  1961. break
  1962. default:
  1963. this.checkLValPattern(expr, bindingType, checkClashes);
  1964. }
  1965. };
  1966. // The algorithm used to determine whether a regexp can appear at a
  1967. // given point in the program is loosely based on sweet.js' approach.
  1968. // See https://github.com/mozilla/sweet.js/wiki/design
  1969. var TokContext = function TokContext(token, isExpr, preserveSpace, override, generator) {
  1970. this.token = token;
  1971. this.isExpr = !!isExpr;
  1972. this.preserveSpace = !!preserveSpace;
  1973. this.override = override;
  1974. this.generator = !!generator;
  1975. };
  1976. var types = {
  1977. b_stat: new TokContext("{", false),
  1978. b_expr: new TokContext("{", true),
  1979. b_tmpl: new TokContext("${", false),
  1980. p_stat: new TokContext("(", false),
  1981. p_expr: new TokContext("(", true),
  1982. q_tmpl: new TokContext("`", true, true, function (p) { return p.tryReadTemplateToken(); }),
  1983. f_stat: new TokContext("function", false),
  1984. f_expr: new TokContext("function", true),
  1985. f_expr_gen: new TokContext("function", true, false, null, true),
  1986. f_gen: new TokContext("function", false, false, null, true)
  1987. };
  1988. var pp$6 = Parser.prototype;
  1989. pp$6.initialContext = function() {
  1990. return [types.b_stat]
  1991. };
  1992. pp$6.curContext = function() {
  1993. return this.context[this.context.length - 1]
  1994. };
  1995. pp$6.braceIsBlock = function(prevType) {
  1996. var parent = this.curContext();
  1997. if (parent === types.f_expr || parent === types.f_stat)
  1998. { return true }
  1999. if (prevType === types$1.colon && (parent === types.b_stat || parent === types.b_expr))
  2000. { return !parent.isExpr }
  2001. // The check for `tt.name && exprAllowed` detects whether we are
  2002. // after a `yield` or `of` construct. See the `updateContext` for
  2003. // `tt.name`.
  2004. if (prevType === types$1._return || prevType === types$1.name && this.exprAllowed)
  2005. { return lineBreak.test(this.input.slice(this.lastTokEnd, this.start)) }
  2006. if (prevType === types$1._else || prevType === types$1.semi || prevType === types$1.eof || prevType === types$1.parenR || prevType === types$1.arrow)
  2007. { return true }
  2008. if (prevType === types$1.braceL)
  2009. { return parent === types.b_stat }
  2010. if (prevType === types$1._var || prevType === types$1._const || prevType === types$1.name)
  2011. { return false }
  2012. return !this.exprAllowed
  2013. };
  2014. pp$6.inGeneratorContext = function() {
  2015. for (var i = this.context.length - 1; i >= 1; i--) {
  2016. var context = this.context[i];
  2017. if (context.token === "function")
  2018. { return context.generator }
  2019. }
  2020. return false
  2021. };
  2022. pp$6.updateContext = function(prevType) {
  2023. var update, type = this.type;
  2024. if (type.keyword && prevType === types$1.dot)
  2025. { this.exprAllowed = false; }
  2026. else if (update = type.updateContext)
  2027. { update.call(this, prevType); }
  2028. else
  2029. { this.exprAllowed = type.beforeExpr; }
  2030. };
  2031. // Used to handle edge cases when token context could not be inferred correctly during tokenization phase
  2032. pp$6.overrideContext = function(tokenCtx) {
  2033. if (this.curContext() !== tokenCtx) {
  2034. this.context[this.context.length - 1] = tokenCtx;
  2035. }
  2036. };
  2037. // Token-specific context update code
  2038. types$1.parenR.updateContext = types$1.braceR.updateContext = function() {
  2039. if (this.context.length === 1) {
  2040. this.exprAllowed = true;
  2041. return
  2042. }
  2043. var out = this.context.pop();
  2044. if (out === types.b_stat && this.curContext().token === "function") {
  2045. out = this.context.pop();
  2046. }
  2047. this.exprAllowed = !out.isExpr;
  2048. };
  2049. types$1.braceL.updateContext = function(prevType) {
  2050. this.context.push(this.braceIsBlock(prevType) ? types.b_stat : types.b_expr);
  2051. this.exprAllowed = true;
  2052. };
  2053. types$1.dollarBraceL.updateContext = function() {
  2054. this.context.push(types.b_tmpl);
  2055. this.exprAllowed = true;
  2056. };
  2057. types$1.parenL.updateContext = function(prevType) {
  2058. var statementParens = prevType === types$1._if || prevType === types$1._for || prevType === types$1._with || prevType === types$1._while;
  2059. this.context.push(statementParens ? types.p_stat : types.p_expr);
  2060. this.exprAllowed = true;
  2061. };
  2062. types$1.incDec.updateContext = function() {
  2063. // tokExprAllowed stays unchanged
  2064. };
  2065. types$1._function.updateContext = types$1._class.updateContext = function(prevType) {
  2066. if (prevType.beforeExpr && prevType !== types$1._else &&
  2067. !(prevType === types$1.semi && this.curContext() !== types.p_stat) &&
  2068. !(prevType === types$1._return && lineBreak.test(this.input.slice(this.lastTokEnd, this.start))) &&
  2069. !((prevType === types$1.colon || prevType === types$1.braceL) && this.curContext() === types.b_stat))
  2070. { this.context.push(types.f_expr); }
  2071. else
  2072. { this.context.push(types.f_stat); }
  2073. this.exprAllowed = false;
  2074. };
  2075. types$1.colon.updateContext = function() {
  2076. if (this.curContext().token === "function") { this.context.pop(); }
  2077. this.exprAllowed = true;
  2078. };
  2079. types$1.backQuote.updateContext = function() {
  2080. if (this.curContext() === types.q_tmpl)
  2081. { this.context.pop(); }
  2082. else
  2083. { this.context.push(types.q_tmpl); }
  2084. this.exprAllowed = false;
  2085. };
  2086. types$1.star.updateContext = function(prevType) {
  2087. if (prevType === types$1._function) {
  2088. var index = this.context.length - 1;
  2089. if (this.context[index] === types.f_expr)
  2090. { this.context[index] = types.f_expr_gen; }
  2091. else
  2092. { this.context[index] = types.f_gen; }
  2093. }
  2094. this.exprAllowed = true;
  2095. };
  2096. types$1.name.updateContext = function(prevType) {
  2097. var allowed = false;
  2098. if (this.options.ecmaVersion >= 6 && prevType !== types$1.dot) {
  2099. if (this.value === "of" && !this.exprAllowed ||
  2100. this.value === "yield" && this.inGeneratorContext())
  2101. { allowed = true; }
  2102. }
  2103. this.exprAllowed = allowed;
  2104. };
  2105. // A recursive descent parser operates by defining functions for all
  2106. // syntactic elements, and recursively calling those, each function
  2107. // advancing the input stream and returning an AST node. Precedence
  2108. // of constructs (for example, the fact that `!x[1]` means `!(x[1])`
  2109. // instead of `(!x)[1]` is handled by the fact that the parser
  2110. // function that parses unary prefix operators is called first, and
  2111. // in turn calls the function that parses `[]` subscripts — that
  2112. // way, it'll receive the node for `x[1]` already parsed, and wraps
  2113. // *that* in the unary operator node.
  2114. //
  2115. // Acorn uses an [operator precedence parser][opp] to handle binary
  2116. // operator precedence, because it is much more compact than using
  2117. // the technique outlined above, which uses different, nesting
  2118. // functions to specify precedence, for all of the ten binary
  2119. // precedence levels that JavaScript defines.
  2120. //
  2121. // [opp]: http://en.wikipedia.org/wiki/Operator-precedence_parser
  2122. var pp$5 = Parser.prototype;
  2123. // Check if property name clashes with already added.
  2124. // Object/class getters and setters are not allowed to clash —
  2125. // either with each other or with an init property — and in
  2126. // strict mode, init properties are also not allowed to be repeated.
  2127. pp$5.checkPropClash = function(prop, propHash, refDestructuringErrors) {
  2128. if (this.options.ecmaVersion >= 9 && prop.type === "SpreadElement")
  2129. { return }
  2130. if (this.options.ecmaVersion >= 6 && (prop.computed || prop.method || prop.shorthand))
  2131. { return }
  2132. var key = prop.key;
  2133. var name;
  2134. switch (key.type) {
  2135. case "Identifier": name = key.name; break
  2136. case "Literal": name = String(key.value); break
  2137. default: return
  2138. }
  2139. var kind = prop.kind;
  2140. if (this.options.ecmaVersion >= 6) {
  2141. if (name === "__proto__" && kind === "init") {
  2142. if (propHash.proto) {
  2143. if (refDestructuringErrors) {
  2144. if (refDestructuringErrors.doubleProto < 0) {
  2145. refDestructuringErrors.doubleProto = key.start;
  2146. }
  2147. } else {
  2148. this.raiseRecoverable(key.start, "Redefinition of __proto__ property");
  2149. }
  2150. }
  2151. propHash.proto = true;
  2152. }
  2153. return
  2154. }
  2155. name = "$" + name;
  2156. var other = propHash[name];
  2157. if (other) {
  2158. var redefinition;
  2159. if (kind === "init") {
  2160. redefinition = this.strict && other.init || other.get || other.set;
  2161. } else {
  2162. redefinition = other.init || other[kind];
  2163. }
  2164. if (redefinition)
  2165. { this.raiseRecoverable(key.start, "Redefinition of property"); }
  2166. } else {
  2167. other = propHash[name] = {
  2168. init: false,
  2169. get: false,
  2170. set: false
  2171. };
  2172. }
  2173. other[kind] = true;
  2174. };
  2175. // ### Expression parsing
  2176. // These nest, from the most general expression type at the top to
  2177. // 'atomic', nondivisible expression types at the bottom. Most of
  2178. // the functions will simply let the function(s) below them parse,
  2179. // and, *if* the syntactic construct they handle is present, wrap
  2180. // the AST node that the inner parser gave them in another node.
  2181. // Parse a full expression. The optional arguments are used to
  2182. // forbid the `in` operator (in for loops initalization expressions)
  2183. // and provide reference for storing '=' operator inside shorthand
  2184. // property assignment in contexts where both object expression
  2185. // and object pattern might appear (so it's possible to raise
  2186. // delayed syntax error at correct position).
  2187. pp$5.parseExpression = function(forInit, refDestructuringErrors) {
  2188. var startPos = this.start, startLoc = this.startLoc;
  2189. var expr = this.parseMaybeAssign(forInit, refDestructuringErrors);
  2190. if (this.type === types$1.comma) {
  2191. var node = this.startNodeAt(startPos, startLoc);
  2192. node.expressions = [expr];
  2193. while (this.eat(types$1.comma)) { node.expressions.push(this.parseMaybeAssign(forInit, refDestructuringErrors)); }
  2194. return this.finishNode(node, "SequenceExpression")
  2195. }
  2196. return expr
  2197. };
  2198. // Parse an assignment expression. This includes applications of
  2199. // operators like `+=`.
  2200. pp$5.parseMaybeAssign = function(forInit, refDestructuringErrors, afterLeftParse) {
  2201. if (this.isContextual("yield")) {
  2202. if (this.inGenerator) { return this.parseYield(forInit) }
  2203. // The tokenizer will assume an expression is allowed after
  2204. // `yield`, but this isn't that kind of yield
  2205. else { this.exprAllowed = false; }
  2206. }
  2207. var ownDestructuringErrors = false, oldParenAssign = -1, oldTrailingComma = -1, oldDoubleProto = -1;
  2208. if (refDestructuringErrors) {
  2209. oldParenAssign = refDestructuringErrors.parenthesizedAssign;
  2210. oldTrailingComma = refDestructuringErrors.trailingComma;
  2211. oldDoubleProto = refDestructuringErrors.doubleProto;
  2212. refDestructuringErrors.parenthesizedAssign = refDestructuringErrors.trailingComma = -1;
  2213. } else {
  2214. refDestructuringErrors = new DestructuringErrors;
  2215. ownDestructuringErrors = true;
  2216. }
  2217. var startPos = this.start, startLoc = this.startLoc;
  2218. if (this.type === types$1.parenL || this.type === types$1.name) {
  2219. this.potentialArrowAt = this.start;
  2220. this.potentialArrowInForAwait = forInit === "await";
  2221. }
  2222. var left = this.parseMaybeConditional(forInit, refDestructuringErrors);
  2223. if (afterLeftParse) { left = afterLeftParse.call(this, left, startPos, startLoc); }
  2224. if (this.type.isAssign) {
  2225. var node = this.startNodeAt(startPos, startLoc);
  2226. node.operator = this.value;
  2227. if (this.type === types$1.eq)
  2228. { left = this.toAssignable(left, false, refDestructuringErrors); }
  2229. if (!ownDestructuringErrors) {
  2230. refDestructuringErrors.parenthesizedAssign = refDestructuringErrors.trailingComma = refDestructuringErrors.doubleProto = -1;
  2231. }
  2232. if (refDestructuringErrors.shorthandAssign >= left.start)
  2233. { refDestructuringErrors.shorthandAssign = -1; } // reset because shorthand default was used correctly
  2234. if (this.type === types$1.eq)
  2235. { this.checkLValPattern(left); }
  2236. else
  2237. { this.checkLValSimple(left); }
  2238. node.left = left;
  2239. this.next();
  2240. node.right = this.parseMaybeAssign(forInit);
  2241. if (oldDoubleProto > -1) { refDestructuringErrors.doubleProto = oldDoubleProto; }
  2242. return this.finishNode(node, "AssignmentExpression")
  2243. } else {
  2244. if (ownDestructuringErrors) { this.checkExpressionErrors(refDestructuringErrors, true); }
  2245. }
  2246. if (oldParenAssign > -1) { refDestructuringErrors.parenthesizedAssign = oldParenAssign; }
  2247. if (oldTrailingComma > -1) { refDestructuringErrors.trailingComma = oldTrailingComma; }
  2248. return left
  2249. };
  2250. // Parse a ternary conditional (`?:`) operator.
  2251. pp$5.parseMaybeConditional = function(forInit, refDestructuringErrors) {
  2252. var startPos = this.start, startLoc = this.startLoc;
  2253. var expr = this.parseExprOps(forInit, refDestructuringErrors);
  2254. if (this.checkExpressionErrors(refDestructuringErrors)) { return expr }
  2255. if (this.eat(types$1.question)) {
  2256. var node = this.startNodeAt(startPos, startLoc);
  2257. node.test = expr;
  2258. node.consequent = this.parseMaybeAssign();
  2259. this.expect(types$1.colon);
  2260. node.alternate = this.parseMaybeAssign(forInit);
  2261. return this.finishNode(node, "ConditionalExpression")
  2262. }
  2263. return expr
  2264. };
  2265. // Start the precedence parser.
  2266. pp$5.parseExprOps = function(forInit, refDestructuringErrors) {
  2267. var startPos = this.start, startLoc = this.startLoc;
  2268. var expr = this.parseMaybeUnary(refDestructuringErrors, false, false, forInit);
  2269. if (this.checkExpressionErrors(refDestructuringErrors)) { return expr }
  2270. return expr.start === startPos && expr.type === "ArrowFunctionExpression" ? expr : this.parseExprOp(expr, startPos, startLoc, -1, forInit)
  2271. };
  2272. // Parse binary operators with the operator precedence parsing
  2273. // algorithm. `left` is the left-hand side of the operator.
  2274. // `minPrec` provides context that allows the function to stop and
  2275. // defer further parser to one of its callers when it encounters an
  2276. // operator that has a lower precedence than the set it is parsing.
  2277. pp$5.parseExprOp = function(left, leftStartPos, leftStartLoc, minPrec, forInit) {
  2278. var prec = this.type.binop;
  2279. if (prec != null && (!forInit || this.type !== types$1._in)) {
  2280. if (prec > minPrec) {
  2281. var logical = this.type === types$1.logicalOR || this.type === types$1.logicalAND;
  2282. var coalesce = this.type === types$1.coalesce;
  2283. if (coalesce) {
  2284. // Handle the precedence of `tt.coalesce` as equal to the range of logical expressions.
  2285. // In other words, `node.right` shouldn't contain logical expressions in order to check the mixed error.
  2286. prec = types$1.logicalAND.binop;
  2287. }
  2288. var op = this.value;
  2289. this.next();
  2290. var startPos = this.start, startLoc = this.startLoc;
  2291. var right = this.parseExprOp(this.parseMaybeUnary(null, false, false, forInit), startPos, startLoc, prec, forInit);
  2292. var node = this.buildBinary(leftStartPos, leftStartLoc, left, right, op, logical || coalesce);
  2293. if ((logical && this.type === types$1.coalesce) || (coalesce && (this.type === types$1.logicalOR || this.type === types$1.logicalAND))) {
  2294. this.raiseRecoverable(this.start, "Logical expressions and coalesce expressions cannot be mixed. Wrap either by parentheses");
  2295. }
  2296. return this.parseExprOp(node, leftStartPos, leftStartLoc, minPrec, forInit)
  2297. }
  2298. }
  2299. return left
  2300. };
  2301. pp$5.buildBinary = function(startPos, startLoc, left, right, op, logical) {
  2302. if (right.type === "PrivateIdentifier") { this.raise(right.start, "Private identifier can only be left side of binary expression"); }
  2303. var node = this.startNodeAt(startPos, startLoc);
  2304. node.left = left;
  2305. node.operator = op;
  2306. node.right = right;
  2307. return this.finishNode(node, logical ? "LogicalExpression" : "BinaryExpression")
  2308. };
  2309. // Parse unary operators, both prefix and postfix.
  2310. pp$5.parseMaybeUnary = function(refDestructuringErrors, sawUnary, incDec, forInit) {
  2311. var startPos = this.start, startLoc = this.startLoc, expr;
  2312. if (this.isContextual("await") && this.canAwait) {
  2313. expr = this.parseAwait(forInit);
  2314. sawUnary = true;
  2315. } else if (this.type.prefix) {
  2316. var node = this.startNode(), update = this.type === types$1.incDec;
  2317. node.operator = this.value;
  2318. node.prefix = true;
  2319. this.next();
  2320. node.argument = this.parseMaybeUnary(null, true, update, forInit);
  2321. this.checkExpressionErrors(refDestructuringErrors, true);
  2322. if (update) { this.checkLValSimple(node.argument); }
  2323. else if (this.strict && node.operator === "delete" && isLocalVariableAccess(node.argument))
  2324. { this.raiseRecoverable(node.start, "Deleting local variable in strict mode"); }
  2325. else if (node.operator === "delete" && isPrivateFieldAccess(node.argument))
  2326. { this.raiseRecoverable(node.start, "Private fields can not be deleted"); }
  2327. else { sawUnary = true; }
  2328. expr = this.finishNode(node, update ? "UpdateExpression" : "UnaryExpression");
  2329. } else if (!sawUnary && this.type === types$1.privateId) {
  2330. if ((forInit || this.privateNameStack.length === 0) && this.options.checkPrivateFields) { this.unexpected(); }
  2331. expr = this.parsePrivateIdent();
  2332. // only could be private fields in 'in', such as #x in obj
  2333. if (this.type !== types$1._in) { this.unexpected(); }
  2334. } else {
  2335. expr = this.parseExprSubscripts(refDestructuringErrors, forInit);
  2336. if (this.checkExpressionErrors(refDestructuringErrors)) { return expr }
  2337. while (this.type.postfix && !this.canInsertSemicolon()) {
  2338. var node$1 = this.startNodeAt(startPos, startLoc);
  2339. node$1.operator = this.value;
  2340. node$1.prefix = false;
  2341. node$1.argument = expr;
  2342. this.checkLValSimple(expr);
  2343. this.next();
  2344. expr = this.finishNode(node$1, "UpdateExpression");
  2345. }
  2346. }
  2347. if (!incDec && this.eat(types$1.starstar)) {
  2348. if (sawUnary)
  2349. { this.unexpected(this.lastTokStart); }
  2350. else
  2351. { return this.buildBinary(startPos, startLoc, expr, this.parseMaybeUnary(null, false, false, forInit), "**", false) }
  2352. } else {
  2353. return expr
  2354. }
  2355. };
  2356. function isLocalVariableAccess(node) {
  2357. return (
  2358. node.type === "Identifier" ||
  2359. node.type === "ParenthesizedExpression" && isLocalVariableAccess(node.expression)
  2360. )
  2361. }
  2362. function isPrivateFieldAccess(node) {
  2363. return (
  2364. node.type === "MemberExpression" && node.property.type === "PrivateIdentifier" ||
  2365. node.type === "ChainExpression" && isPrivateFieldAccess(node.expression) ||
  2366. node.type === "ParenthesizedExpression" && isPrivateFieldAccess(node.expression)
  2367. )
  2368. }
  2369. // Parse call, dot, and `[]`-subscript expressions.
  2370. pp$5.parseExprSubscripts = function(refDestructuringErrors, forInit) {
  2371. var startPos = this.start, startLoc = this.startLoc;
  2372. var expr = this.parseExprAtom(refDestructuringErrors, forInit);
  2373. if (expr.type === "ArrowFunctionExpression" && this.input.slice(this.lastTokStart, this.lastTokEnd) !== ")")
  2374. { return expr }
  2375. var result = this.parseSubscripts(expr, startPos, startLoc, false, forInit);
  2376. if (refDestructuringErrors && result.type === "MemberExpression") {
  2377. if (refDestructuringErrors.parenthesizedAssign >= result.start) { refDestructuringErrors.parenthesizedAssign = -1; }
  2378. if (refDestructuringErrors.parenthesizedBind >= result.start) { refDestructuringErrors.parenthesizedBind = -1; }
  2379. if (refDestructuringErrors.trailingComma >= result.start) { refDestructuringErrors.trailingComma = -1; }
  2380. }
  2381. return result
  2382. };
  2383. pp$5.parseSubscripts = function(base, startPos, startLoc, noCalls, forInit) {
  2384. var maybeAsyncArrow = this.options.ecmaVersion >= 8 && base.type === "Identifier" && base.name === "async" &&
  2385. this.lastTokEnd === base.end && !this.canInsertSemicolon() && base.end - base.start === 5 &&
  2386. this.potentialArrowAt === base.start;
  2387. var optionalChained = false;
  2388. while (true) {
  2389. var element = this.parseSubscript(base, startPos, startLoc, noCalls, maybeAsyncArrow, optionalChained, forInit);
  2390. if (element.optional) { optionalChained = true; }
  2391. if (element === base || element.type === "ArrowFunctionExpression") {
  2392. if (optionalChained) {
  2393. var chainNode = this.startNodeAt(startPos, startLoc);
  2394. chainNode.expression = element;
  2395. element = this.finishNode(chainNode, "ChainExpression");
  2396. }
  2397. return element
  2398. }
  2399. base = element;
  2400. }
  2401. };
  2402. pp$5.shouldParseAsyncArrow = function() {
  2403. return !this.canInsertSemicolon() && this.eat(types$1.arrow)
  2404. };
  2405. pp$5.parseSubscriptAsyncArrow = function(startPos, startLoc, exprList, forInit) {
  2406. return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), exprList, true, forInit)
  2407. };
  2408. pp$5.parseSubscript = function(base, startPos, startLoc, noCalls, maybeAsyncArrow, optionalChained, forInit) {
  2409. var optionalSupported = this.options.ecmaVersion >= 11;
  2410. var optional = optionalSupported && this.eat(types$1.questionDot);
  2411. if (noCalls && optional) { this.raise(this.lastTokStart, "Optional chaining cannot appear in the callee of new expressions"); }
  2412. var computed = this.eat(types$1.bracketL);
  2413. if (computed || (optional && this.type !== types$1.parenL && this.type !== types$1.backQuote) || this.eat(types$1.dot)) {
  2414. var node = this.startNodeAt(startPos, startLoc);
  2415. node.object = base;
  2416. if (computed) {
  2417. node.property = this.parseExpression();
  2418. this.expect(types$1.bracketR);
  2419. } else if (this.type === types$1.privateId && base.type !== "Super") {
  2420. node.property = this.parsePrivateIdent();
  2421. } else {
  2422. node.property = this.parseIdent(this.options.allowReserved !== "never");
  2423. }
  2424. node.computed = !!computed;
  2425. if (optionalSupported) {
  2426. node.optional = optional;
  2427. }
  2428. base = this.finishNode(node, "MemberExpression");
  2429. } else if (!noCalls && this.eat(types$1.parenL)) {
  2430. var refDestructuringErrors = new DestructuringErrors, oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldAwaitIdentPos = this.awaitIdentPos;
  2431. this.yieldPos = 0;
  2432. this.awaitPos = 0;
  2433. this.awaitIdentPos = 0;
  2434. var exprList = this.parseExprList(types$1.parenR, this.options.ecmaVersion >= 8, false, refDestructuringErrors);
  2435. if (maybeAsyncArrow && !optional && this.shouldParseAsyncArrow()) {
  2436. this.checkPatternErrors(refDestructuringErrors, false);
  2437. this.checkYieldAwaitInDefaultParams();
  2438. if (this.awaitIdentPos > 0)
  2439. { this.raise(this.awaitIdentPos, "Cannot use 'await' as identifier inside an async function"); }
  2440. this.yieldPos = oldYieldPos;
  2441. this.awaitPos = oldAwaitPos;
  2442. this.awaitIdentPos = oldAwaitIdentPos;
  2443. return this.parseSubscriptAsyncArrow(startPos, startLoc, exprList, forInit)
  2444. }
  2445. this.checkExpressionErrors(refDestructuringErrors, true);
  2446. this.yieldPos = oldYieldPos || this.yieldPos;
  2447. this.awaitPos = oldAwaitPos || this.awaitPos;
  2448. this.awaitIdentPos = oldAwaitIdentPos || this.awaitIdentPos;
  2449. var node$1 = this.startNodeAt(startPos, startLoc);
  2450. node$1.callee = base;
  2451. node$1.arguments = exprList;
  2452. if (optionalSupported) {
  2453. node$1.optional = optional;
  2454. }
  2455. base = this.finishNode(node$1, "CallExpression");
  2456. } else if (this.type === types$1.backQuote) {
  2457. if (optional || optionalChained) {
  2458. this.raise(this.start, "Optional chaining cannot appear in the tag of tagged template expressions");
  2459. }
  2460. var node$2 = this.startNodeAt(startPos, startLoc);
  2461. node$2.tag = base;
  2462. node$2.quasi = this.parseTemplate({isTagged: true});
  2463. base = this.finishNode(node$2, "TaggedTemplateExpression");
  2464. }
  2465. return base
  2466. };
  2467. // Parse an atomic expression — either a single token that is an
  2468. // expression, an expression started by a keyword like `function` or
  2469. // `new`, or an expression wrapped in punctuation like `()`, `[]`,
  2470. // or `{}`.
  2471. pp$5.parseExprAtom = function(refDestructuringErrors, forInit, forNew) {
  2472. // If a division operator appears in an expression position, the
  2473. // tokenizer got confused, and we force it to read a regexp instead.
  2474. if (this.type === types$1.slash) { this.readRegexp(); }
  2475. var node, canBeArrow = this.potentialArrowAt === this.start;
  2476. switch (this.type) {
  2477. case types$1._super:
  2478. if (!this.allowSuper)
  2479. { this.raise(this.start, "'super' keyword outside a method"); }
  2480. node = this.startNode();
  2481. this.next();
  2482. if (this.type === types$1.parenL && !this.allowDirectSuper)
  2483. { this.raise(node.start, "super() call outside constructor of a subclass"); }
  2484. // The `super` keyword can appear at below:
  2485. // SuperProperty:
  2486. // super [ Expression ]
  2487. // super . IdentifierName
  2488. // SuperCall:
  2489. // super ( Arguments )
  2490. if (this.type !== types$1.dot && this.type !== types$1.bracketL && this.type !== types$1.parenL)
  2491. { this.unexpected(); }
  2492. return this.finishNode(node, "Super")
  2493. case types$1._this:
  2494. node = this.startNode();
  2495. this.next();
  2496. return this.finishNode(node, "ThisExpression")
  2497. case types$1.name:
  2498. var startPos = this.start, startLoc = this.startLoc, containsEsc = this.containsEsc;
  2499. var id = this.parseIdent(false);
  2500. if (this.options.ecmaVersion >= 8 && !containsEsc && id.name === "async" && !this.canInsertSemicolon() && this.eat(types$1._function)) {
  2501. this.overrideContext(types.f_expr);
  2502. return this.parseFunction(this.startNodeAt(startPos, startLoc), 0, false, true, forInit)
  2503. }
  2504. if (canBeArrow && !this.canInsertSemicolon()) {
  2505. if (this.eat(types$1.arrow))
  2506. { return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), [id], false, forInit) }
  2507. if (this.options.ecmaVersion >= 8 && id.name === "async" && this.type === types$1.name && !containsEsc &&
  2508. (!this.potentialArrowInForAwait || this.value !== "of" || this.containsEsc)) {
  2509. id = this.parseIdent(false);
  2510. if (this.canInsertSemicolon() || !this.eat(types$1.arrow))
  2511. { this.unexpected(); }
  2512. return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), [id], true, forInit)
  2513. }
  2514. }
  2515. return id
  2516. case types$1.regexp:
  2517. var value = this.value;
  2518. node = this.parseLiteral(value.value);
  2519. node.regex = {pattern: value.pattern, flags: value.flags};
  2520. return node
  2521. case types$1.num: case types$1.string:
  2522. return this.parseLiteral(this.value)
  2523. case types$1._null: case types$1._true: case types$1._false:
  2524. node = this.startNode();
  2525. node.value = this.type === types$1._null ? null : this.type === types$1._true;
  2526. node.raw = this.type.keyword;
  2527. this.next();
  2528. return this.finishNode(node, "Literal")
  2529. case types$1.parenL:
  2530. var start = this.start, expr = this.parseParenAndDistinguishExpression(canBeArrow, forInit);
  2531. if (refDestructuringErrors) {
  2532. if (refDestructuringErrors.parenthesizedAssign < 0 && !this.isSimpleAssignTarget(expr))
  2533. { refDestructuringErrors.parenthesizedAssign = start; }
  2534. if (refDestructuringErrors.parenthesizedBind < 0)
  2535. { refDestructuringErrors.parenthesizedBind = start; }
  2536. }
  2537. return expr
  2538. case types$1.bracketL:
  2539. node = this.startNode();
  2540. this.next();
  2541. node.elements = this.parseExprList(types$1.bracketR, true, true, refDestructuringErrors);
  2542. return this.finishNode(node, "ArrayExpression")
  2543. case types$1.braceL:
  2544. this.overrideContext(types.b_expr);
  2545. return this.parseObj(false, refDestructuringErrors)
  2546. case types$1._function:
  2547. node = this.startNode();
  2548. this.next();
  2549. return this.parseFunction(node, 0)
  2550. case types$1._class:
  2551. return this.parseClass(this.startNode(), false)
  2552. case types$1._new:
  2553. return this.parseNew()
  2554. case types$1.backQuote:
  2555. return this.parseTemplate()
  2556. case types$1._import:
  2557. if (this.options.ecmaVersion >= 11) {
  2558. return this.parseExprImport(forNew)
  2559. } else {
  2560. return this.unexpected()
  2561. }
  2562. default:
  2563. return this.parseExprAtomDefault()
  2564. }
  2565. };
  2566. pp$5.parseExprAtomDefault = function() {
  2567. this.unexpected();
  2568. };
  2569. pp$5.parseExprImport = function(forNew) {
  2570. var node = this.startNode();
  2571. // Consume `import` as an identifier for `import.meta`.
  2572. // Because `this.parseIdent(true)` doesn't check escape sequences, it needs the check of `this.containsEsc`.
  2573. if (this.containsEsc) { this.raiseRecoverable(this.start, "Escape sequence in keyword import"); }
  2574. this.next();
  2575. if (this.type === types$1.parenL && !forNew) {
  2576. return this.parseDynamicImport(node)
  2577. } else if (this.type === types$1.dot) {
  2578. var meta = this.startNodeAt(node.start, node.loc && node.loc.start);
  2579. meta.name = "import";
  2580. node.meta = this.finishNode(meta, "Identifier");
  2581. return this.parseImportMeta(node)
  2582. } else {
  2583. this.unexpected();
  2584. }
  2585. };
  2586. pp$5.parseDynamicImport = function(node) {
  2587. this.next(); // skip `(`
  2588. // Parse node.source.
  2589. node.source = this.parseMaybeAssign();
  2590. // Verify ending.
  2591. if (!this.eat(types$1.parenR)) {
  2592. var errorPos = this.start;
  2593. if (this.eat(types$1.comma) && this.eat(types$1.parenR)) {
  2594. this.raiseRecoverable(errorPos, "Trailing comma is not allowed in import()");
  2595. } else {
  2596. this.unexpected(errorPos);
  2597. }
  2598. }
  2599. return this.finishNode(node, "ImportExpression")
  2600. };
  2601. pp$5.parseImportMeta = function(node) {
  2602. this.next(); // skip `.`
  2603. var containsEsc = this.containsEsc;
  2604. node.property = this.parseIdent(true);
  2605. if (node.property.name !== "meta")
  2606. { this.raiseRecoverable(node.property.start, "The only valid meta property for import is 'import.meta'"); }
  2607. if (containsEsc)
  2608. { this.raiseRecoverable(node.start, "'import.meta' must not contain escaped characters"); }
  2609. if (this.options.sourceType !== "module" && !this.options.allowImportExportEverywhere)
  2610. { this.raiseRecoverable(node.start, "Cannot use 'import.meta' outside a module"); }
  2611. return this.finishNode(node, "MetaProperty")
  2612. };
  2613. pp$5.parseLiteral = function(value) {
  2614. var node = this.startNode();
  2615. node.value = value;
  2616. node.raw = this.input.slice(this.start, this.end);
  2617. if (node.raw.charCodeAt(node.raw.length - 1) === 110) { node.bigint = node.raw.slice(0, -1).replace(/_/g, ""); }
  2618. this.next();
  2619. return this.finishNode(node, "Literal")
  2620. };
  2621. pp$5.parseParenExpression = function() {
  2622. this.expect(types$1.parenL);
  2623. var val = this.parseExpression();
  2624. this.expect(types$1.parenR);
  2625. return val
  2626. };
  2627. pp$5.shouldParseArrow = function(exprList) {
  2628. return !this.canInsertSemicolon()
  2629. };
  2630. pp$5.parseParenAndDistinguishExpression = function(canBeArrow, forInit) {
  2631. var startPos = this.start, startLoc = this.startLoc, val, allowTrailingComma = this.options.ecmaVersion >= 8;
  2632. if (this.options.ecmaVersion >= 6) {
  2633. this.next();
  2634. var innerStartPos = this.start, innerStartLoc = this.startLoc;
  2635. var exprList = [], first = true, lastIsComma = false;
  2636. var refDestructuringErrors = new DestructuringErrors, oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, spreadStart;
  2637. this.yieldPos = 0;
  2638. this.awaitPos = 0;
  2639. // Do not save awaitIdentPos to allow checking awaits nested in parameters
  2640. while (this.type !== types$1.parenR) {
  2641. first ? first = false : this.expect(types$1.comma);
  2642. if (allowTrailingComma && this.afterTrailingComma(types$1.parenR, true)) {
  2643. lastIsComma = true;
  2644. break
  2645. } else if (this.type === types$1.ellipsis) {
  2646. spreadStart = this.start;
  2647. exprList.push(this.parseParenItem(this.parseRestBinding()));
  2648. if (this.type === types$1.comma) {
  2649. this.raiseRecoverable(
  2650. this.start,
  2651. "Comma is not permitted after the rest element"
  2652. );
  2653. }
  2654. break
  2655. } else {
  2656. exprList.push(this.parseMaybeAssign(false, refDestructuringErrors, this.parseParenItem));
  2657. }
  2658. }
  2659. var innerEndPos = this.lastTokEnd, innerEndLoc = this.lastTokEndLoc;
  2660. this.expect(types$1.parenR);
  2661. if (canBeArrow && this.shouldParseArrow(exprList) && this.eat(types$1.arrow)) {
  2662. this.checkPatternErrors(refDestructuringErrors, false);
  2663. this.checkYieldAwaitInDefaultParams();
  2664. this.yieldPos = oldYieldPos;
  2665. this.awaitPos = oldAwaitPos;
  2666. return this.parseParenArrowList(startPos, startLoc, exprList, forInit)
  2667. }
  2668. if (!exprList.length || lastIsComma) { this.unexpected(this.lastTokStart); }
  2669. if (spreadStart) { this.unexpected(spreadStart); }
  2670. this.checkExpressionErrors(refDestructuringErrors, true);
  2671. this.yieldPos = oldYieldPos || this.yieldPos;
  2672. this.awaitPos = oldAwaitPos || this.awaitPos;
  2673. if (exprList.length > 1) {
  2674. val = this.startNodeAt(innerStartPos, innerStartLoc);
  2675. val.expressions = exprList;
  2676. this.finishNodeAt(val, "SequenceExpression", innerEndPos, innerEndLoc);
  2677. } else {
  2678. val = exprList[0];
  2679. }
  2680. } else {
  2681. val = this.parseParenExpression();
  2682. }
  2683. if (this.options.preserveParens) {
  2684. var par = this.startNodeAt(startPos, startLoc);
  2685. par.expression = val;
  2686. return this.finishNode(par, "ParenthesizedExpression")
  2687. } else {
  2688. return val
  2689. }
  2690. };
  2691. pp$5.parseParenItem = function(item) {
  2692. return item
  2693. };
  2694. pp$5.parseParenArrowList = function(startPos, startLoc, exprList, forInit) {
  2695. return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), exprList, false, forInit)
  2696. };
  2697. // New's precedence is slightly tricky. It must allow its argument to
  2698. // be a `[]` or dot subscript expression, but not a call — at least,
  2699. // not without wrapping it in parentheses. Thus, it uses the noCalls
  2700. // argument to parseSubscripts to prevent it from consuming the
  2701. // argument list.
  2702. var empty = [];
  2703. pp$5.parseNew = function() {
  2704. if (this.containsEsc) { this.raiseRecoverable(this.start, "Escape sequence in keyword new"); }
  2705. var node = this.startNode();
  2706. this.next();
  2707. if (this.options.ecmaVersion >= 6 && this.type === types$1.dot) {
  2708. var meta = this.startNodeAt(node.start, node.loc && node.loc.start);
  2709. meta.name = "new";
  2710. node.meta = this.finishNode(meta, "Identifier");
  2711. this.next();
  2712. var containsEsc = this.containsEsc;
  2713. node.property = this.parseIdent(true);
  2714. if (node.property.name !== "target")
  2715. { this.raiseRecoverable(node.property.start, "The only valid meta property for new is 'new.target'"); }
  2716. if (containsEsc)
  2717. { this.raiseRecoverable(node.start, "'new.target' must not contain escaped characters"); }
  2718. if (!this.allowNewDotTarget)
  2719. { this.raiseRecoverable(node.start, "'new.target' can only be used in functions and class static block"); }
  2720. return this.finishNode(node, "MetaProperty")
  2721. }
  2722. var startPos = this.start, startLoc = this.startLoc;
  2723. node.callee = this.parseSubscripts(this.parseExprAtom(null, false, true), startPos, startLoc, true, false);
  2724. if (this.eat(types$1.parenL)) { node.arguments = this.parseExprList(types$1.parenR, this.options.ecmaVersion >= 8, false); }
  2725. else { node.arguments = empty; }
  2726. return this.finishNode(node, "NewExpression")
  2727. };
  2728. // Parse template expression.
  2729. pp$5.parseTemplateElement = function(ref) {
  2730. var isTagged = ref.isTagged;
  2731. var elem = this.startNode();
  2732. if (this.type === types$1.invalidTemplate) {
  2733. if (!isTagged) {
  2734. this.raiseRecoverable(this.start, "Bad escape sequence in untagged template literal");
  2735. }
  2736. elem.value = {
  2737. raw: this.value.replace(/\r\n?/g, "\n"),
  2738. cooked: null
  2739. };
  2740. } else {
  2741. elem.value = {
  2742. raw: this.input.slice(this.start, this.end).replace(/\r\n?/g, "\n"),
  2743. cooked: this.value
  2744. };
  2745. }
  2746. this.next();
  2747. elem.tail = this.type === types$1.backQuote;
  2748. return this.finishNode(elem, "TemplateElement")
  2749. };
  2750. pp$5.parseTemplate = function(ref) {
  2751. if ( ref === void 0 ) ref = {};
  2752. var isTagged = ref.isTagged; if ( isTagged === void 0 ) isTagged = false;
  2753. var node = this.startNode();
  2754. this.next();
  2755. node.expressions = [];
  2756. var curElt = this.parseTemplateElement({isTagged: isTagged});
  2757. node.quasis = [curElt];
  2758. while (!curElt.tail) {
  2759. if (this.type === types$1.eof) { this.raise(this.pos, "Unterminated template literal"); }
  2760. this.expect(types$1.dollarBraceL);
  2761. node.expressions.push(this.parseExpression());
  2762. this.expect(types$1.braceR);
  2763. node.quasis.push(curElt = this.parseTemplateElement({isTagged: isTagged}));
  2764. }
  2765. this.next();
  2766. return this.finishNode(node, "TemplateLiteral")
  2767. };
  2768. pp$5.isAsyncProp = function(prop) {
  2769. return !prop.computed && prop.key.type === "Identifier" && prop.key.name === "async" &&
  2770. (this.type === types$1.name || this.type === types$1.num || this.type === types$1.string || this.type === types$1.bracketL || this.type.keyword || (this.options.ecmaVersion >= 9 && this.type === types$1.star)) &&
  2771. !lineBreak.test(this.input.slice(this.lastTokEnd, this.start))
  2772. };
  2773. // Parse an object literal or binding pattern.
  2774. pp$5.parseObj = function(isPattern, refDestructuringErrors) {
  2775. var node = this.startNode(), first = true, propHash = {};
  2776. node.properties = [];
  2777. this.next();
  2778. while (!this.eat(types$1.braceR)) {
  2779. if (!first) {
  2780. this.expect(types$1.comma);
  2781. if (this.options.ecmaVersion >= 5 && this.afterTrailingComma(types$1.braceR)) { break }
  2782. } else { first = false; }
  2783. var prop = this.parseProperty(isPattern, refDestructuringErrors);
  2784. if (!isPattern) { this.checkPropClash(prop, propHash, refDestructuringErrors); }
  2785. node.properties.push(prop);
  2786. }
  2787. return this.finishNode(node, isPattern ? "ObjectPattern" : "ObjectExpression")
  2788. };
  2789. pp$5.parseProperty = function(isPattern, refDestructuringErrors) {
  2790. var prop = this.startNode(), isGenerator, isAsync, startPos, startLoc;
  2791. if (this.options.ecmaVersion >= 9 && this.eat(types$1.ellipsis)) {
  2792. if (isPattern) {
  2793. prop.argument = this.parseIdent(false);
  2794. if (this.type === types$1.comma) {
  2795. this.raiseRecoverable(this.start, "Comma is not permitted after the rest element");
  2796. }
  2797. return this.finishNode(prop, "RestElement")
  2798. }
  2799. // Parse argument.
  2800. prop.argument = this.parseMaybeAssign(false, refDestructuringErrors);
  2801. // To disallow trailing comma via `this.toAssignable()`.
  2802. if (this.type === types$1.comma && refDestructuringErrors && refDestructuringErrors.trailingComma < 0) {
  2803. refDestructuringErrors.trailingComma = this.start;
  2804. }
  2805. // Finish
  2806. return this.finishNode(prop, "SpreadElement")
  2807. }
  2808. if (this.options.ecmaVersion >= 6) {
  2809. prop.method = false;
  2810. prop.shorthand = false;
  2811. if (isPattern || refDestructuringErrors) {
  2812. startPos = this.start;
  2813. startLoc = this.startLoc;
  2814. }
  2815. if (!isPattern)
  2816. { isGenerator = this.eat(types$1.star); }
  2817. }
  2818. var containsEsc = this.containsEsc;
  2819. this.parsePropertyName(prop);
  2820. if (!isPattern && !containsEsc && this.options.ecmaVersion >= 8 && !isGenerator && this.isAsyncProp(prop)) {
  2821. isAsync = true;
  2822. isGenerator = this.options.ecmaVersion >= 9 && this.eat(types$1.star);
  2823. this.parsePropertyName(prop);
  2824. } else {
  2825. isAsync = false;
  2826. }
  2827. this.parsePropertyValue(prop, isPattern, isGenerator, isAsync, startPos, startLoc, refDestructuringErrors, containsEsc);
  2828. return this.finishNode(prop, "Property")
  2829. };
  2830. pp$5.parseGetterSetter = function(prop) {
  2831. prop.kind = prop.key.name;
  2832. this.parsePropertyName(prop);
  2833. prop.value = this.parseMethod(false);
  2834. var paramCount = prop.kind === "get" ? 0 : 1;
  2835. if (prop.value.params.length !== paramCount) {
  2836. var start = prop.value.start;
  2837. if (prop.kind === "get")
  2838. { this.raiseRecoverable(start, "getter should have no params"); }
  2839. else
  2840. { this.raiseRecoverable(start, "setter should have exactly one param"); }
  2841. } else {
  2842. if (prop.kind === "set" && prop.value.params[0].type === "RestElement")
  2843. { this.raiseRecoverable(prop.value.params[0].start, "Setter cannot use rest params"); }
  2844. }
  2845. };
  2846. pp$5.parsePropertyValue = function(prop, isPattern, isGenerator, isAsync, startPos, startLoc, refDestructuringErrors, containsEsc) {
  2847. if ((isGenerator || isAsync) && this.type === types$1.colon)
  2848. { this.unexpected(); }
  2849. if (this.eat(types$1.colon)) {
  2850. prop.value = isPattern ? this.parseMaybeDefault(this.start, this.startLoc) : this.parseMaybeAssign(false, refDestructuringErrors);
  2851. prop.kind = "init";
  2852. } else if (this.options.ecmaVersion >= 6 && this.type === types$1.parenL) {
  2853. if (isPattern) { this.unexpected(); }
  2854. prop.kind = "init";
  2855. prop.method = true;
  2856. prop.value = this.parseMethod(isGenerator, isAsync);
  2857. } else if (!isPattern && !containsEsc &&
  2858. this.options.ecmaVersion >= 5 && !prop.computed && prop.key.type === "Identifier" &&
  2859. (prop.key.name === "get" || prop.key.name === "set") &&
  2860. (this.type !== types$1.comma && this.type !== types$1.braceR && this.type !== types$1.eq)) {
  2861. if (isGenerator || isAsync) { this.unexpected(); }
  2862. this.parseGetterSetter(prop);
  2863. } else if (this.options.ecmaVersion >= 6 && !prop.computed && prop.key.type === "Identifier") {
  2864. if (isGenerator || isAsync) { this.unexpected(); }
  2865. this.checkUnreserved(prop.key);
  2866. if (prop.key.name === "await" && !this.awaitIdentPos)
  2867. { this.awaitIdentPos = startPos; }
  2868. prop.kind = "init";
  2869. if (isPattern) {
  2870. prop.value = this.parseMaybeDefault(startPos, startLoc, this.copyNode(prop.key));
  2871. } else if (this.type === types$1.eq && refDestructuringErrors) {
  2872. if (refDestructuringErrors.shorthandAssign < 0)
  2873. { refDestructuringErrors.shorthandAssign = this.start; }
  2874. prop.value = this.parseMaybeDefault(startPos, startLoc, this.copyNode(prop.key));
  2875. } else {
  2876. prop.value = this.copyNode(prop.key);
  2877. }
  2878. prop.shorthand = true;
  2879. } else { this.unexpected(); }
  2880. };
  2881. pp$5.parsePropertyName = function(prop) {
  2882. if (this.options.ecmaVersion >= 6) {
  2883. if (this.eat(types$1.bracketL)) {
  2884. prop.computed = true;
  2885. prop.key = this.parseMaybeAssign();
  2886. this.expect(types$1.bracketR);
  2887. return prop.key
  2888. } else {
  2889. prop.computed = false;
  2890. }
  2891. }
  2892. return prop.key = this.type === types$1.num || this.type === types$1.string ? this.parseExprAtom() : this.parseIdent(this.options.allowReserved !== "never")
  2893. };
  2894. // Initialize empty function node.
  2895. pp$5.initFunction = function(node) {
  2896. node.id = null;
  2897. if (this.options.ecmaVersion >= 6) { node.generator = node.expression = false; }
  2898. if (this.options.ecmaVersion >= 8) { node.async = false; }
  2899. };
  2900. // Parse object or class method.
  2901. pp$5.parseMethod = function(isGenerator, isAsync, allowDirectSuper) {
  2902. var node = this.startNode(), oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldAwaitIdentPos = this.awaitIdentPos;
  2903. this.initFunction(node);
  2904. if (this.options.ecmaVersion >= 6)
  2905. { node.generator = isGenerator; }
  2906. if (this.options.ecmaVersion >= 8)
  2907. { node.async = !!isAsync; }
  2908. this.yieldPos = 0;
  2909. this.awaitPos = 0;
  2910. this.awaitIdentPos = 0;
  2911. this.enterScope(functionFlags(isAsync, node.generator) | SCOPE_SUPER | (allowDirectSuper ? SCOPE_DIRECT_SUPER : 0));
  2912. this.expect(types$1.parenL);
  2913. node.params = this.parseBindingList(types$1.parenR, false, this.options.ecmaVersion >= 8);
  2914. this.checkYieldAwaitInDefaultParams();
  2915. this.parseFunctionBody(node, false, true, false);
  2916. this.yieldPos = oldYieldPos;
  2917. this.awaitPos = oldAwaitPos;
  2918. this.awaitIdentPos = oldAwaitIdentPos;
  2919. return this.finishNode(node, "FunctionExpression")
  2920. };
  2921. // Parse arrow function expression with given parameters.
  2922. pp$5.parseArrowExpression = function(node, params, isAsync, forInit) {
  2923. var oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldAwaitIdentPos = this.awaitIdentPos;
  2924. this.enterScope(functionFlags(isAsync, false) | SCOPE_ARROW);
  2925. this.initFunction(node);
  2926. if (this.options.ecmaVersion >= 8) { node.async = !!isAsync; }
  2927. this.yieldPos = 0;
  2928. this.awaitPos = 0;
  2929. this.awaitIdentPos = 0;
  2930. node.params = this.toAssignableList(params, true);
  2931. this.parseFunctionBody(node, true, false, forInit);
  2932. this.yieldPos = oldYieldPos;
  2933. this.awaitPos = oldAwaitPos;
  2934. this.awaitIdentPos = oldAwaitIdentPos;
  2935. return this.finishNode(node, "ArrowFunctionExpression")
  2936. };
  2937. // Parse function body and check parameters.
  2938. pp$5.parseFunctionBody = function(node, isArrowFunction, isMethod, forInit) {
  2939. var isExpression = isArrowFunction && this.type !== types$1.braceL;
  2940. var oldStrict = this.strict, useStrict = false;
  2941. if (isExpression) {
  2942. node.body = this.parseMaybeAssign(forInit);
  2943. node.expression = true;
  2944. this.checkParams(node, false);
  2945. } else {
  2946. var nonSimple = this.options.ecmaVersion >= 7 && !this.isSimpleParamList(node.params);
  2947. if (!oldStrict || nonSimple) {
  2948. useStrict = this.strictDirective(this.end);
  2949. // If this is a strict mode function, verify that argument names
  2950. // are not repeated, and it does not try to bind the words `eval`
  2951. // or `arguments`.
  2952. if (useStrict && nonSimple)
  2953. { this.raiseRecoverable(node.start, "Illegal 'use strict' directive in function with non-simple parameter list"); }
  2954. }
  2955. // Start a new scope with regard to labels and the `inFunction`
  2956. // flag (restore them to their old value afterwards).
  2957. var oldLabels = this.labels;
  2958. this.labels = [];
  2959. if (useStrict) { this.strict = true; }
  2960. // Add the params to varDeclaredNames to ensure that an error is thrown
  2961. // if a let/const declaration in the function clashes with one of the params.
  2962. this.checkParams(node, !oldStrict && !useStrict && !isArrowFunction && !isMethod && this.isSimpleParamList(node.params));
  2963. // Ensure the function name isn't a forbidden identifier in strict mode, e.g. 'eval'
  2964. if (this.strict && node.id) { this.checkLValSimple(node.id, BIND_OUTSIDE); }
  2965. node.body = this.parseBlock(false, undefined, useStrict && !oldStrict);
  2966. node.expression = false;
  2967. this.adaptDirectivePrologue(node.body.body);
  2968. this.labels = oldLabels;
  2969. }
  2970. this.exitScope();
  2971. };
  2972. pp$5.isSimpleParamList = function(params) {
  2973. for (var i = 0, list = params; i < list.length; i += 1)
  2974. {
  2975. var param = list[i];
  2976. if (param.type !== "Identifier") { return false
  2977. } }
  2978. return true
  2979. };
  2980. // Checks function params for various disallowed patterns such as using "eval"
  2981. // or "arguments" and duplicate parameters.
  2982. pp$5.checkParams = function(node, allowDuplicates) {
  2983. var nameHash = Object.create(null);
  2984. for (var i = 0, list = node.params; i < list.length; i += 1)
  2985. {
  2986. var param = list[i];
  2987. this.checkLValInnerPattern(param, BIND_VAR, allowDuplicates ? null : nameHash);
  2988. }
  2989. };
  2990. // Parses a comma-separated list of expressions, and returns them as
  2991. // an array. `close` is the token type that ends the list, and
  2992. // `allowEmpty` can be turned on to allow subsequent commas with
  2993. // nothing in between them to be parsed as `null` (which is needed
  2994. // for array literals).
  2995. pp$5.parseExprList = function(close, allowTrailingComma, allowEmpty, refDestructuringErrors) {
  2996. var elts = [], first = true;
  2997. while (!this.eat(close)) {
  2998. if (!first) {
  2999. this.expect(types$1.comma);
  3000. if (allowTrailingComma && this.afterTrailingComma(close)) { break }
  3001. } else { first = false; }
  3002. var elt = (void 0);
  3003. if (allowEmpty && this.type === types$1.comma)
  3004. { elt = null; }
  3005. else if (this.type === types$1.ellipsis) {
  3006. elt = this.parseSpread(refDestructuringErrors);
  3007. if (refDestructuringErrors && this.type === types$1.comma && refDestructuringErrors.trailingComma < 0)
  3008. { refDestructuringErrors.trailingComma = this.start; }
  3009. } else {
  3010. elt = this.parseMaybeAssign(false, refDestructuringErrors);
  3011. }
  3012. elts.push(elt);
  3013. }
  3014. return elts
  3015. };
  3016. pp$5.checkUnreserved = function(ref) {
  3017. var start = ref.start;
  3018. var end = ref.end;
  3019. var name = ref.name;
  3020. if (this.inGenerator && name === "yield")
  3021. { this.raiseRecoverable(start, "Cannot use 'yield' as identifier inside a generator"); }
  3022. if (this.inAsync && name === "await")
  3023. { this.raiseRecoverable(start, "Cannot use 'await' as identifier inside an async function"); }
  3024. if (this.currentThisScope().inClassFieldInit && name === "arguments")
  3025. { this.raiseRecoverable(start, "Cannot use 'arguments' in class field initializer"); }
  3026. if (this.inClassStaticBlock && (name === "arguments" || name === "await"))
  3027. { this.raise(start, ("Cannot use " + name + " in class static initialization block")); }
  3028. if (this.keywords.test(name))
  3029. { this.raise(start, ("Unexpected keyword '" + name + "'")); }
  3030. if (this.options.ecmaVersion < 6 &&
  3031. this.input.slice(start, end).indexOf("\\") !== -1) { return }
  3032. var re = this.strict ? this.reservedWordsStrict : this.reservedWords;
  3033. if (re.test(name)) {
  3034. if (!this.inAsync && name === "await")
  3035. { this.raiseRecoverable(start, "Cannot use keyword 'await' outside an async function"); }
  3036. this.raiseRecoverable(start, ("The keyword '" + name + "' is reserved"));
  3037. }
  3038. };
  3039. // Parse the next token as an identifier. If `liberal` is true (used
  3040. // when parsing properties), it will also convert keywords into
  3041. // identifiers.
  3042. pp$5.parseIdent = function(liberal) {
  3043. var node = this.parseIdentNode();
  3044. this.next(!!liberal);
  3045. this.finishNode(node, "Identifier");
  3046. if (!liberal) {
  3047. this.checkUnreserved(node);
  3048. if (node.name === "await" && !this.awaitIdentPos)
  3049. { this.awaitIdentPos = node.start; }
  3050. }
  3051. return node
  3052. };
  3053. pp$5.parseIdentNode = function() {
  3054. var node = this.startNode();
  3055. if (this.type === types$1.name) {
  3056. node.name = this.value;
  3057. } else if (this.type.keyword) {
  3058. node.name = this.type.keyword;
  3059. // To fix https://github.com/acornjs/acorn/issues/575
  3060. // `class` and `function` keywords push new context into this.context.
  3061. // But there is no chance to pop the context if the keyword is consumed as an identifier such as a property name.
  3062. // If the previous token is a dot, this does not apply because the context-managing code already ignored the keyword
  3063. if ((node.name === "class" || node.name === "function") &&
  3064. (this.lastTokEnd !== this.lastTokStart + 1 || this.input.charCodeAt(this.lastTokStart) !== 46)) {
  3065. this.context.pop();
  3066. }
  3067. this.type = types$1.name;
  3068. } else {
  3069. this.unexpected();
  3070. }
  3071. return node
  3072. };
  3073. pp$5.parsePrivateIdent = function() {
  3074. var node = this.startNode();
  3075. if (this.type === types$1.privateId) {
  3076. node.name = this.value;
  3077. } else {
  3078. this.unexpected();
  3079. }
  3080. this.next();
  3081. this.finishNode(node, "PrivateIdentifier");
  3082. // For validating existence
  3083. if (this.options.checkPrivateFields) {
  3084. if (this.privateNameStack.length === 0) {
  3085. this.raise(node.start, ("Private field '#" + (node.name) + "' must be declared in an enclosing class"));
  3086. } else {
  3087. this.privateNameStack[this.privateNameStack.length - 1].used.push(node);
  3088. }
  3089. }
  3090. return node
  3091. };
  3092. // Parses yield expression inside generator.
  3093. pp$5.parseYield = function(forInit) {
  3094. if (!this.yieldPos) { this.yieldPos = this.start; }
  3095. var node = this.startNode();
  3096. this.next();
  3097. if (this.type === types$1.semi || this.canInsertSemicolon() || (this.type !== types$1.star && !this.type.startsExpr)) {
  3098. node.delegate = false;
  3099. node.argument = null;
  3100. } else {
  3101. node.delegate = this.eat(types$1.star);
  3102. node.argument = this.parseMaybeAssign(forInit);
  3103. }
  3104. return this.finishNode(node, "YieldExpression")
  3105. };
  3106. pp$5.parseAwait = function(forInit) {
  3107. if (!this.awaitPos) { this.awaitPos = this.start; }
  3108. var node = this.startNode();
  3109. this.next();
  3110. node.argument = this.parseMaybeUnary(null, true, false, forInit);
  3111. return this.finishNode(node, "AwaitExpression")
  3112. };
  3113. var pp$4 = Parser.prototype;
  3114. // This function is used to raise exceptions on parse errors. It
  3115. // takes an offset integer (into the current `input`) to indicate
  3116. // the location of the error, attaches the position to the end
  3117. // of the error message, and then raises a `SyntaxError` with that
  3118. // message.
  3119. pp$4.raise = function(pos, message) {
  3120. var loc = getLineInfo(this.input, pos);
  3121. message += " (" + loc.line + ":" + loc.column + ")";
  3122. var err = new SyntaxError(message);
  3123. err.pos = pos; err.loc = loc; err.raisedAt = this.pos;
  3124. throw err
  3125. };
  3126. pp$4.raiseRecoverable = pp$4.raise;
  3127. pp$4.curPosition = function() {
  3128. if (this.options.locations) {
  3129. return new Position(this.curLine, this.pos - this.lineStart)
  3130. }
  3131. };
  3132. var pp$3 = Parser.prototype;
  3133. var Scope = function Scope(flags) {
  3134. this.flags = flags;
  3135. // A list of var-declared names in the current lexical scope
  3136. this.var = [];
  3137. // A list of lexically-declared names in the current lexical scope
  3138. this.lexical = [];
  3139. // A list of lexically-declared FunctionDeclaration names in the current lexical scope
  3140. this.functions = [];
  3141. // A switch to disallow the identifier reference 'arguments'
  3142. this.inClassFieldInit = false;
  3143. };
  3144. // The functions in this module keep track of declared variables in the current scope in order to detect duplicate variable names.
  3145. pp$3.enterScope = function(flags) {
  3146. this.scopeStack.push(new Scope(flags));
  3147. };
  3148. pp$3.exitScope = function() {
  3149. this.scopeStack.pop();
  3150. };
  3151. // The spec says:
  3152. // > At the top level of a function, or script, function declarations are
  3153. // > treated like var declarations rather than like lexical declarations.
  3154. pp$3.treatFunctionsAsVarInScope = function(scope) {
  3155. return (scope.flags & SCOPE_FUNCTION) || !this.inModule && (scope.flags & SCOPE_TOP)
  3156. };
  3157. pp$3.declareName = function(name, bindingType, pos) {
  3158. var redeclared = false;
  3159. if (bindingType === BIND_LEXICAL) {
  3160. var scope = this.currentScope();
  3161. redeclared = scope.lexical.indexOf(name) > -1 || scope.functions.indexOf(name) > -1 || scope.var.indexOf(name) > -1;
  3162. scope.lexical.push(name);
  3163. if (this.inModule && (scope.flags & SCOPE_TOP))
  3164. { delete this.undefinedExports[name]; }
  3165. } else if (bindingType === BIND_SIMPLE_CATCH) {
  3166. var scope$1 = this.currentScope();
  3167. scope$1.lexical.push(name);
  3168. } else if (bindingType === BIND_FUNCTION) {
  3169. var scope$2 = this.currentScope();
  3170. if (this.treatFunctionsAsVar)
  3171. { redeclared = scope$2.lexical.indexOf(name) > -1; }
  3172. else
  3173. { redeclared = scope$2.lexical.indexOf(name) > -1 || scope$2.var.indexOf(name) > -1; }
  3174. scope$2.functions.push(name);
  3175. } else {
  3176. for (var i = this.scopeStack.length - 1; i >= 0; --i) {
  3177. var scope$3 = this.scopeStack[i];
  3178. if (scope$3.lexical.indexOf(name) > -1 && !((scope$3.flags & SCOPE_SIMPLE_CATCH) && scope$3.lexical[0] === name) ||
  3179. !this.treatFunctionsAsVarInScope(scope$3) && scope$3.functions.indexOf(name) > -1) {
  3180. redeclared = true;
  3181. break
  3182. }
  3183. scope$3.var.push(name);
  3184. if (this.inModule && (scope$3.flags & SCOPE_TOP))
  3185. { delete this.undefinedExports[name]; }
  3186. if (scope$3.flags & SCOPE_VAR) { break }
  3187. }
  3188. }
  3189. if (redeclared) { this.raiseRecoverable(pos, ("Identifier '" + name + "' has already been declared")); }
  3190. };
  3191. pp$3.checkLocalExport = function(id) {
  3192. // scope.functions must be empty as Module code is always strict.
  3193. if (this.scopeStack[0].lexical.indexOf(id.name) === -1 &&
  3194. this.scopeStack[0].var.indexOf(id.name) === -1) {
  3195. this.undefinedExports[id.name] = id;
  3196. }
  3197. };
  3198. pp$3.currentScope = function() {
  3199. return this.scopeStack[this.scopeStack.length - 1]
  3200. };
  3201. pp$3.currentVarScope = function() {
  3202. for (var i = this.scopeStack.length - 1;; i--) {
  3203. var scope = this.scopeStack[i];
  3204. if (scope.flags & SCOPE_VAR) { return scope }
  3205. }
  3206. };
  3207. // Could be useful for `this`, `new.target`, `super()`, `super.property`, and `super[property]`.
  3208. pp$3.currentThisScope = function() {
  3209. for (var i = this.scopeStack.length - 1;; i--) {
  3210. var scope = this.scopeStack[i];
  3211. if (scope.flags & SCOPE_VAR && !(scope.flags & SCOPE_ARROW)) { return scope }
  3212. }
  3213. };
  3214. var Node = function Node(parser, pos, loc) {
  3215. this.type = "";
  3216. this.start = pos;
  3217. this.end = 0;
  3218. if (parser.options.locations)
  3219. { this.loc = new SourceLocation(parser, loc); }
  3220. if (parser.options.directSourceFile)
  3221. { this.sourceFile = parser.options.directSourceFile; }
  3222. if (parser.options.ranges)
  3223. { this.range = [pos, 0]; }
  3224. };
  3225. // Start an AST node, attaching a start offset.
  3226. var pp$2 = Parser.prototype;
  3227. pp$2.startNode = function() {
  3228. return new Node(this, this.start, this.startLoc)
  3229. };
  3230. pp$2.startNodeAt = function(pos, loc) {
  3231. return new Node(this, pos, loc)
  3232. };
  3233. // Finish an AST node, adding `type` and `end` properties.
  3234. function finishNodeAt(node, type, pos, loc) {
  3235. node.type = type;
  3236. node.end = pos;
  3237. if (this.options.locations)
  3238. { node.loc.end = loc; }
  3239. if (this.options.ranges)
  3240. { node.range[1] = pos; }
  3241. return node
  3242. }
  3243. pp$2.finishNode = function(node, type) {
  3244. return finishNodeAt.call(this, node, type, this.lastTokEnd, this.lastTokEndLoc)
  3245. };
  3246. // Finish node at given position
  3247. pp$2.finishNodeAt = function(node, type, pos, loc) {
  3248. return finishNodeAt.call(this, node, type, pos, loc)
  3249. };
  3250. pp$2.copyNode = function(node) {
  3251. var newNode = new Node(this, node.start, this.startLoc);
  3252. for (var prop in node) { newNode[prop] = node[prop]; }
  3253. return newNode
  3254. };
  3255. // This file contains Unicode properties extracted from the ECMAScript specification.
  3256. // The lists are extracted like so:
  3257. // $$('#table-binary-unicode-properties > figure > table > tbody > tr > td:nth-child(1) code').map(el => el.innerText)
  3258. // #table-binary-unicode-properties
  3259. var ecma9BinaryProperties = "ASCII ASCII_Hex_Digit AHex Alphabetic Alpha Any Assigned Bidi_Control Bidi_C Bidi_Mirrored Bidi_M Case_Ignorable CI Cased Changes_When_Casefolded CWCF Changes_When_Casemapped CWCM Changes_When_Lowercased CWL Changes_When_NFKC_Casefolded CWKCF Changes_When_Titlecased CWT Changes_When_Uppercased CWU Dash Default_Ignorable_Code_Point DI Deprecated Dep Diacritic Dia Emoji Emoji_Component Emoji_Modifier Emoji_Modifier_Base Emoji_Presentation Extender Ext Grapheme_Base Gr_Base Grapheme_Extend Gr_Ext Hex_Digit Hex IDS_Binary_Operator IDSB IDS_Trinary_Operator IDST ID_Continue IDC ID_Start IDS Ideographic Ideo Join_Control Join_C Logical_Order_Exception LOE Lowercase Lower Math Noncharacter_Code_Point NChar Pattern_Syntax Pat_Syn Pattern_White_Space Pat_WS Quotation_Mark QMark Radical Regional_Indicator RI Sentence_Terminal STerm Soft_Dotted SD Terminal_Punctuation Term Unified_Ideograph UIdeo Uppercase Upper Variation_Selector VS White_Space space XID_Continue XIDC XID_Start XIDS";
  3260. var ecma10BinaryProperties = ecma9BinaryProperties + " Extended_Pictographic";
  3261. var ecma11BinaryProperties = ecma10BinaryProperties;
  3262. var ecma12BinaryProperties = ecma11BinaryProperties + " EBase EComp EMod EPres ExtPict";
  3263. var ecma13BinaryProperties = ecma12BinaryProperties;
  3264. var ecma14BinaryProperties = ecma13BinaryProperties;
  3265. var unicodeBinaryProperties = {
  3266. 9: ecma9BinaryProperties,
  3267. 10: ecma10BinaryProperties,
  3268. 11: ecma11BinaryProperties,
  3269. 12: ecma12BinaryProperties,
  3270. 13: ecma13BinaryProperties,
  3271. 14: ecma14BinaryProperties
  3272. };
  3273. // #table-binary-unicode-properties-of-strings
  3274. var ecma14BinaryPropertiesOfStrings = "Basic_Emoji Emoji_Keycap_Sequence RGI_Emoji_Modifier_Sequence RGI_Emoji_Flag_Sequence RGI_Emoji_Tag_Sequence RGI_Emoji_ZWJ_Sequence RGI_Emoji";
  3275. var unicodeBinaryPropertiesOfStrings = {
  3276. 9: "",
  3277. 10: "",
  3278. 11: "",
  3279. 12: "",
  3280. 13: "",
  3281. 14: ecma14BinaryPropertiesOfStrings
  3282. };
  3283. // #table-unicode-general-category-values
  3284. var unicodeGeneralCategoryValues = "Cased_Letter LC Close_Punctuation Pe Connector_Punctuation Pc Control Cc cntrl Currency_Symbol Sc Dash_Punctuation Pd Decimal_Number Nd digit Enclosing_Mark Me Final_Punctuation Pf Format Cf Initial_Punctuation Pi Letter L Letter_Number Nl Line_Separator Zl Lowercase_Letter Ll Mark M Combining_Mark Math_Symbol Sm Modifier_Letter Lm Modifier_Symbol Sk Nonspacing_Mark Mn Number N Open_Punctuation Ps Other C Other_Letter Lo Other_Number No Other_Punctuation Po Other_Symbol So Paragraph_Separator Zp Private_Use Co Punctuation P punct Separator Z Space_Separator Zs Spacing_Mark Mc Surrogate Cs Symbol S Titlecase_Letter Lt Unassigned Cn Uppercase_Letter Lu";
  3285. // #table-unicode-script-values
  3286. var ecma9ScriptValues = "Adlam Adlm Ahom Anatolian_Hieroglyphs Hluw Arabic Arab Armenian Armn Avestan Avst Balinese Bali Bamum Bamu Bassa_Vah Bass Batak Batk Bengali Beng Bhaiksuki Bhks Bopomofo Bopo Brahmi Brah Braille Brai Buginese Bugi Buhid Buhd Canadian_Aboriginal Cans Carian Cari Caucasian_Albanian Aghb Chakma Cakm Cham Cham Cherokee Cher Common Zyyy Coptic Copt Qaac Cuneiform Xsux Cypriot Cprt Cyrillic Cyrl Deseret Dsrt Devanagari Deva Duployan Dupl Egyptian_Hieroglyphs Egyp Elbasan Elba Ethiopic Ethi Georgian Geor Glagolitic Glag Gothic Goth Grantha Gran Greek Grek Gujarati Gujr Gurmukhi Guru Han Hani Hangul Hang Hanunoo Hano Hatran Hatr Hebrew Hebr Hiragana Hira Imperial_Aramaic Armi Inherited Zinh Qaai Inscriptional_Pahlavi Phli Inscriptional_Parthian Prti Javanese Java Kaithi Kthi Kannada Knda Katakana Kana Kayah_Li Kali Kharoshthi Khar Khmer Khmr Khojki Khoj Khudawadi Sind Lao Laoo Latin Latn Lepcha Lepc Limbu Limb Linear_A Lina Linear_B Linb Lisu Lisu Lycian Lyci Lydian Lydi Mahajani Mahj Malayalam Mlym Mandaic Mand Manichaean Mani Marchen Marc Masaram_Gondi Gonm Meetei_Mayek Mtei Mende_Kikakui Mend Meroitic_Cursive Merc Meroitic_Hieroglyphs Mero Miao Plrd Modi Mongolian Mong Mro Mroo Multani Mult Myanmar Mymr Nabataean Nbat New_Tai_Lue Talu Newa Newa Nko Nkoo Nushu Nshu Ogham Ogam Ol_Chiki Olck Old_Hungarian Hung Old_Italic Ital Old_North_Arabian Narb Old_Permic Perm Old_Persian Xpeo Old_South_Arabian Sarb Old_Turkic Orkh Oriya Orya Osage Osge Osmanya Osma Pahawh_Hmong Hmng Palmyrene Palm Pau_Cin_Hau Pauc Phags_Pa Phag Phoenician Phnx Psalter_Pahlavi Phlp Rejang Rjng Runic Runr Samaritan Samr Saurashtra Saur Sharada Shrd Shavian Shaw Siddham Sidd SignWriting Sgnw Sinhala Sinh Sora_Sompeng Sora Soyombo Soyo Sundanese Sund Syloti_Nagri Sylo Syriac Syrc Tagalog Tglg Tagbanwa Tagb Tai_Le Tale Tai_Tham Lana Tai_Viet Tavt Takri Takr Tamil Taml Tangut Tang Telugu Telu Thaana Thaa Thai Thai Tibetan Tibt Tifinagh Tfng Tirhuta Tirh Ugaritic Ugar Vai Vaii Warang_Citi Wara Yi Yiii Zanabazar_Square Zanb";
  3287. var ecma10ScriptValues = ecma9ScriptValues + " Dogra Dogr Gunjala_Gondi Gong Hanifi_Rohingya Rohg Makasar Maka Medefaidrin Medf Old_Sogdian Sogo Sogdian Sogd";
  3288. var ecma11ScriptValues = ecma10ScriptValues + " Elymaic Elym Nandinagari Nand Nyiakeng_Puachue_Hmong Hmnp Wancho Wcho";
  3289. var ecma12ScriptValues = ecma11ScriptValues + " Chorasmian Chrs Diak Dives_Akuru Khitan_Small_Script Kits Yezi Yezidi";
  3290. var ecma13ScriptValues = ecma12ScriptValues + " Cypro_Minoan Cpmn Old_Uyghur Ougr Tangsa Tnsa Toto Vithkuqi Vith";
  3291. var ecma14ScriptValues = ecma13ScriptValues + " Hrkt Katakana_Or_Hiragana Kawi Nag_Mundari Nagm Unknown Zzzz";
  3292. var unicodeScriptValues = {
  3293. 9: ecma9ScriptValues,
  3294. 10: ecma10ScriptValues,
  3295. 11: ecma11ScriptValues,
  3296. 12: ecma12ScriptValues,
  3297. 13: ecma13ScriptValues,
  3298. 14: ecma14ScriptValues
  3299. };
  3300. var data = {};
  3301. function buildUnicodeData(ecmaVersion) {
  3302. var d = data[ecmaVersion] = {
  3303. binary: wordsRegexp(unicodeBinaryProperties[ecmaVersion] + " " + unicodeGeneralCategoryValues),
  3304. binaryOfStrings: wordsRegexp(unicodeBinaryPropertiesOfStrings[ecmaVersion]),
  3305. nonBinary: {
  3306. General_Category: wordsRegexp(unicodeGeneralCategoryValues),
  3307. Script: wordsRegexp(unicodeScriptValues[ecmaVersion])
  3308. }
  3309. };
  3310. d.nonBinary.Script_Extensions = d.nonBinary.Script;
  3311. d.nonBinary.gc = d.nonBinary.General_Category;
  3312. d.nonBinary.sc = d.nonBinary.Script;
  3313. d.nonBinary.scx = d.nonBinary.Script_Extensions;
  3314. }
  3315. for (var i = 0, list = [9, 10, 11, 12, 13, 14]; i < list.length; i += 1) {
  3316. var ecmaVersion = list[i];
  3317. buildUnicodeData(ecmaVersion);
  3318. }
  3319. var pp$1 = Parser.prototype;
  3320. // Track disjunction structure to determine whether a duplicate
  3321. // capture group name is allowed because it is in a separate branch.
  3322. var BranchID = function BranchID(parent, base) {
  3323. // Parent disjunction branch
  3324. this.parent = parent;
  3325. // Identifies this set of sibling branches
  3326. this.base = base || this;
  3327. };
  3328. BranchID.prototype.separatedFrom = function separatedFrom (alt) {
  3329. // A branch is separate from another branch if they or any of
  3330. // their parents are siblings in a given disjunction
  3331. for (var self = this; self; self = self.parent) {
  3332. for (var other = alt; other; other = other.parent) {
  3333. if (self.base === other.base && self !== other) { return true }
  3334. }
  3335. }
  3336. return false
  3337. };
  3338. BranchID.prototype.sibling = function sibling () {
  3339. return new BranchID(this.parent, this.base)
  3340. };
  3341. var RegExpValidationState = function RegExpValidationState(parser) {
  3342. this.parser = parser;
  3343. this.validFlags = "gim" + (parser.options.ecmaVersion >= 6 ? "uy" : "") + (parser.options.ecmaVersion >= 9 ? "s" : "") + (parser.options.ecmaVersion >= 13 ? "d" : "") + (parser.options.ecmaVersion >= 15 ? "v" : "");
  3344. this.unicodeProperties = data[parser.options.ecmaVersion >= 14 ? 14 : parser.options.ecmaVersion];
  3345. this.source = "";
  3346. this.flags = "";
  3347. this.start = 0;
  3348. this.switchU = false;
  3349. this.switchV = false;
  3350. this.switchN = false;
  3351. this.pos = 0;
  3352. this.lastIntValue = 0;
  3353. this.lastStringValue = "";
  3354. this.lastAssertionIsQuantifiable = false;
  3355. this.numCapturingParens = 0;
  3356. this.maxBackReference = 0;
  3357. this.groupNames = Object.create(null);
  3358. this.backReferenceNames = [];
  3359. this.branchID = null;
  3360. };
  3361. RegExpValidationState.prototype.reset = function reset (start, pattern, flags) {
  3362. var unicodeSets = flags.indexOf("v") !== -1;
  3363. var unicode = flags.indexOf("u") !== -1;
  3364. this.start = start | 0;
  3365. this.source = pattern + "";
  3366. this.flags = flags;
  3367. if (unicodeSets && this.parser.options.ecmaVersion >= 15) {
  3368. this.switchU = true;
  3369. this.switchV = true;
  3370. this.switchN = true;
  3371. } else {
  3372. this.switchU = unicode && this.parser.options.ecmaVersion >= 6;
  3373. this.switchV = false;
  3374. this.switchN = unicode && this.parser.options.ecmaVersion >= 9;
  3375. }
  3376. };
  3377. RegExpValidationState.prototype.raise = function raise (message) {
  3378. this.parser.raiseRecoverable(this.start, ("Invalid regular expression: /" + (this.source) + "/: " + message));
  3379. };
  3380. // If u flag is given, this returns the code point at the index (it combines a surrogate pair).
  3381. // Otherwise, this returns the code unit of the index (can be a part of a surrogate pair).
  3382. RegExpValidationState.prototype.at = function at (i, forceU) {
  3383. if ( forceU === void 0 ) forceU = false;
  3384. var s = this.source;
  3385. var l = s.length;
  3386. if (i >= l) {
  3387. return -1
  3388. }
  3389. var c = s.charCodeAt(i);
  3390. if (!(forceU || this.switchU) || c <= 0xD7FF || c >= 0xE000 || i + 1 >= l) {
  3391. return c
  3392. }
  3393. var next = s.charCodeAt(i + 1);
  3394. return next >= 0xDC00 && next <= 0xDFFF ? (c << 10) + next - 0x35FDC00 : c
  3395. };
  3396. RegExpValidationState.prototype.nextIndex = function nextIndex (i, forceU) {
  3397. if ( forceU === void 0 ) forceU = false;
  3398. var s = this.source;
  3399. var l = s.length;
  3400. if (i >= l) {
  3401. return l
  3402. }
  3403. var c = s.charCodeAt(i), next;
  3404. if (!(forceU || this.switchU) || c <= 0xD7FF || c >= 0xE000 || i + 1 >= l ||
  3405. (next = s.charCodeAt(i + 1)) < 0xDC00 || next > 0xDFFF) {
  3406. return i + 1
  3407. }
  3408. return i + 2
  3409. };
  3410. RegExpValidationState.prototype.current = function current (forceU) {
  3411. if ( forceU === void 0 ) forceU = false;
  3412. return this.at(this.pos, forceU)
  3413. };
  3414. RegExpValidationState.prototype.lookahead = function lookahead (forceU) {
  3415. if ( forceU === void 0 ) forceU = false;
  3416. return this.at(this.nextIndex(this.pos, forceU), forceU)
  3417. };
  3418. RegExpValidationState.prototype.advance = function advance (forceU) {
  3419. if ( forceU === void 0 ) forceU = false;
  3420. this.pos = this.nextIndex(this.pos, forceU);
  3421. };
  3422. RegExpValidationState.prototype.eat = function eat (ch, forceU) {
  3423. if ( forceU === void 0 ) forceU = false;
  3424. if (this.current(forceU) === ch) {
  3425. this.advance(forceU);
  3426. return true
  3427. }
  3428. return false
  3429. };
  3430. RegExpValidationState.prototype.eatChars = function eatChars (chs, forceU) {
  3431. if ( forceU === void 0 ) forceU = false;
  3432. var pos = this.pos;
  3433. for (var i = 0, list = chs; i < list.length; i += 1) {
  3434. var ch = list[i];
  3435. var current = this.at(pos, forceU);
  3436. if (current === -1 || current !== ch) {
  3437. return false
  3438. }
  3439. pos = this.nextIndex(pos, forceU);
  3440. }
  3441. this.pos = pos;
  3442. return true
  3443. };
  3444. /**
  3445. * Validate the flags part of a given RegExpLiteral.
  3446. *
  3447. * @param {RegExpValidationState} state The state to validate RegExp.
  3448. * @returns {void}
  3449. */
  3450. pp$1.validateRegExpFlags = function(state) {
  3451. var validFlags = state.validFlags;
  3452. var flags = state.flags;
  3453. var u = false;
  3454. var v = false;
  3455. for (var i = 0; i < flags.length; i++) {
  3456. var flag = flags.charAt(i);
  3457. if (validFlags.indexOf(flag) === -1) {
  3458. this.raise(state.start, "Invalid regular expression flag");
  3459. }
  3460. if (flags.indexOf(flag, i + 1) > -1) {
  3461. this.raise(state.start, "Duplicate regular expression flag");
  3462. }
  3463. if (flag === "u") { u = true; }
  3464. if (flag === "v") { v = true; }
  3465. }
  3466. if (this.options.ecmaVersion >= 15 && u && v) {
  3467. this.raise(state.start, "Invalid regular expression flag");
  3468. }
  3469. };
  3470. function hasProp(obj) {
  3471. for (var _ in obj) { return true }
  3472. return false
  3473. }
  3474. /**
  3475. * Validate the pattern part of a given RegExpLiteral.
  3476. *
  3477. * @param {RegExpValidationState} state The state to validate RegExp.
  3478. * @returns {void}
  3479. */
  3480. pp$1.validateRegExpPattern = function(state) {
  3481. this.regexp_pattern(state);
  3482. // The goal symbol for the parse is |Pattern[~U, ~N]|. If the result of
  3483. // parsing contains a |GroupName|, reparse with the goal symbol
  3484. // |Pattern[~U, +N]| and use this result instead. Throw a *SyntaxError*
  3485. // exception if _P_ did not conform to the grammar, if any elements of _P_
  3486. // were not matched by the parse, or if any Early Error conditions exist.
  3487. if (!state.switchN && this.options.ecmaVersion >= 9 && hasProp(state.groupNames)) {
  3488. state.switchN = true;
  3489. this.regexp_pattern(state);
  3490. }
  3491. };
  3492. // https://www.ecma-international.org/ecma-262/8.0/#prod-Pattern
  3493. pp$1.regexp_pattern = function(state) {
  3494. state.pos = 0;
  3495. state.lastIntValue = 0;
  3496. state.lastStringValue = "";
  3497. state.lastAssertionIsQuantifiable = false;
  3498. state.numCapturingParens = 0;
  3499. state.maxBackReference = 0;
  3500. state.groupNames = Object.create(null);
  3501. state.backReferenceNames.length = 0;
  3502. state.branchID = null;
  3503. this.regexp_disjunction(state);
  3504. if (state.pos !== state.source.length) {
  3505. // Make the same messages as V8.
  3506. if (state.eat(0x29 /* ) */)) {
  3507. state.raise("Unmatched ')'");
  3508. }
  3509. if (state.eat(0x5D /* ] */) || state.eat(0x7D /* } */)) {
  3510. state.raise("Lone quantifier brackets");
  3511. }
  3512. }
  3513. if (state.maxBackReference > state.numCapturingParens) {
  3514. state.raise("Invalid escape");
  3515. }
  3516. for (var i = 0, list = state.backReferenceNames; i < list.length; i += 1) {
  3517. var name = list[i];
  3518. if (!state.groupNames[name]) {
  3519. state.raise("Invalid named capture referenced");
  3520. }
  3521. }
  3522. };
  3523. // https://www.ecma-international.org/ecma-262/8.0/#prod-Disjunction
  3524. pp$1.regexp_disjunction = function(state) {
  3525. var trackDisjunction = this.options.ecmaVersion >= 16;
  3526. if (trackDisjunction) { state.branchID = new BranchID(state.branchID, null); }
  3527. this.regexp_alternative(state);
  3528. while (state.eat(0x7C /* | */)) {
  3529. if (trackDisjunction) { state.branchID = state.branchID.sibling(); }
  3530. this.regexp_alternative(state);
  3531. }
  3532. if (trackDisjunction) { state.branchID = state.branchID.parent; }
  3533. // Make the same message as V8.
  3534. if (this.regexp_eatQuantifier(state, true)) {
  3535. state.raise("Nothing to repeat");
  3536. }
  3537. if (state.eat(0x7B /* { */)) {
  3538. state.raise("Lone quantifier brackets");
  3539. }
  3540. };
  3541. // https://www.ecma-international.org/ecma-262/8.0/#prod-Alternative
  3542. pp$1.regexp_alternative = function(state) {
  3543. while (state.pos < state.source.length && this.regexp_eatTerm(state)) {}
  3544. };
  3545. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-Term
  3546. pp$1.regexp_eatTerm = function(state) {
  3547. if (this.regexp_eatAssertion(state)) {
  3548. // Handle `QuantifiableAssertion Quantifier` alternative.
  3549. // `state.lastAssertionIsQuantifiable` is true if the last eaten Assertion
  3550. // is a QuantifiableAssertion.
  3551. if (state.lastAssertionIsQuantifiable && this.regexp_eatQuantifier(state)) {
  3552. // Make the same message as V8.
  3553. if (state.switchU) {
  3554. state.raise("Invalid quantifier");
  3555. }
  3556. }
  3557. return true
  3558. }
  3559. if (state.switchU ? this.regexp_eatAtom(state) : this.regexp_eatExtendedAtom(state)) {
  3560. this.regexp_eatQuantifier(state);
  3561. return true
  3562. }
  3563. return false
  3564. };
  3565. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-Assertion
  3566. pp$1.regexp_eatAssertion = function(state) {
  3567. var start = state.pos;
  3568. state.lastAssertionIsQuantifiable = false;
  3569. // ^, $
  3570. if (state.eat(0x5E /* ^ */) || state.eat(0x24 /* $ */)) {
  3571. return true
  3572. }
  3573. // \b \B
  3574. if (state.eat(0x5C /* \ */)) {
  3575. if (state.eat(0x42 /* B */) || state.eat(0x62 /* b */)) {
  3576. return true
  3577. }
  3578. state.pos = start;
  3579. }
  3580. // Lookahead / Lookbehind
  3581. if (state.eat(0x28 /* ( */) && state.eat(0x3F /* ? */)) {
  3582. var lookbehind = false;
  3583. if (this.options.ecmaVersion >= 9) {
  3584. lookbehind = state.eat(0x3C /* < */);
  3585. }
  3586. if (state.eat(0x3D /* = */) || state.eat(0x21 /* ! */)) {
  3587. this.regexp_disjunction(state);
  3588. if (!state.eat(0x29 /* ) */)) {
  3589. state.raise("Unterminated group");
  3590. }
  3591. state.lastAssertionIsQuantifiable = !lookbehind;
  3592. return true
  3593. }
  3594. }
  3595. state.pos = start;
  3596. return false
  3597. };
  3598. // https://www.ecma-international.org/ecma-262/8.0/#prod-Quantifier
  3599. pp$1.regexp_eatQuantifier = function(state, noError) {
  3600. if ( noError === void 0 ) noError = false;
  3601. if (this.regexp_eatQuantifierPrefix(state, noError)) {
  3602. state.eat(0x3F /* ? */);
  3603. return true
  3604. }
  3605. return false
  3606. };
  3607. // https://www.ecma-international.org/ecma-262/8.0/#prod-QuantifierPrefix
  3608. pp$1.regexp_eatQuantifierPrefix = function(state, noError) {
  3609. return (
  3610. state.eat(0x2A /* * */) ||
  3611. state.eat(0x2B /* + */) ||
  3612. state.eat(0x3F /* ? */) ||
  3613. this.regexp_eatBracedQuantifier(state, noError)
  3614. )
  3615. };
  3616. pp$1.regexp_eatBracedQuantifier = function(state, noError) {
  3617. var start = state.pos;
  3618. if (state.eat(0x7B /* { */)) {
  3619. var min = 0, max = -1;
  3620. if (this.regexp_eatDecimalDigits(state)) {
  3621. min = state.lastIntValue;
  3622. if (state.eat(0x2C /* , */) && this.regexp_eatDecimalDigits(state)) {
  3623. max = state.lastIntValue;
  3624. }
  3625. if (state.eat(0x7D /* } */)) {
  3626. // SyntaxError in https://www.ecma-international.org/ecma-262/8.0/#sec-term
  3627. if (max !== -1 && max < min && !noError) {
  3628. state.raise("numbers out of order in {} quantifier");
  3629. }
  3630. return true
  3631. }
  3632. }
  3633. if (state.switchU && !noError) {
  3634. state.raise("Incomplete quantifier");
  3635. }
  3636. state.pos = start;
  3637. }
  3638. return false
  3639. };
  3640. // https://www.ecma-international.org/ecma-262/8.0/#prod-Atom
  3641. pp$1.regexp_eatAtom = function(state) {
  3642. return (
  3643. this.regexp_eatPatternCharacters(state) ||
  3644. state.eat(0x2E /* . */) ||
  3645. this.regexp_eatReverseSolidusAtomEscape(state) ||
  3646. this.regexp_eatCharacterClass(state) ||
  3647. this.regexp_eatUncapturingGroup(state) ||
  3648. this.regexp_eatCapturingGroup(state)
  3649. )
  3650. };
  3651. pp$1.regexp_eatReverseSolidusAtomEscape = function(state) {
  3652. var start = state.pos;
  3653. if (state.eat(0x5C /* \ */)) {
  3654. if (this.regexp_eatAtomEscape(state)) {
  3655. return true
  3656. }
  3657. state.pos = start;
  3658. }
  3659. return false
  3660. };
  3661. pp$1.regexp_eatUncapturingGroup = function(state) {
  3662. var start = state.pos;
  3663. if (state.eat(0x28 /* ( */)) {
  3664. if (state.eat(0x3F /* ? */) && state.eat(0x3A /* : */)) {
  3665. this.regexp_disjunction(state);
  3666. if (state.eat(0x29 /* ) */)) {
  3667. return true
  3668. }
  3669. state.raise("Unterminated group");
  3670. }
  3671. state.pos = start;
  3672. }
  3673. return false
  3674. };
  3675. pp$1.regexp_eatCapturingGroup = function(state) {
  3676. if (state.eat(0x28 /* ( */)) {
  3677. if (this.options.ecmaVersion >= 9) {
  3678. this.regexp_groupSpecifier(state);
  3679. } else if (state.current() === 0x3F /* ? */) {
  3680. state.raise("Invalid group");
  3681. }
  3682. this.regexp_disjunction(state);
  3683. if (state.eat(0x29 /* ) */)) {
  3684. state.numCapturingParens += 1;
  3685. return true
  3686. }
  3687. state.raise("Unterminated group");
  3688. }
  3689. return false
  3690. };
  3691. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-ExtendedAtom
  3692. pp$1.regexp_eatExtendedAtom = function(state) {
  3693. return (
  3694. state.eat(0x2E /* . */) ||
  3695. this.regexp_eatReverseSolidusAtomEscape(state) ||
  3696. this.regexp_eatCharacterClass(state) ||
  3697. this.regexp_eatUncapturingGroup(state) ||
  3698. this.regexp_eatCapturingGroup(state) ||
  3699. this.regexp_eatInvalidBracedQuantifier(state) ||
  3700. this.regexp_eatExtendedPatternCharacter(state)
  3701. )
  3702. };
  3703. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-InvalidBracedQuantifier
  3704. pp$1.regexp_eatInvalidBracedQuantifier = function(state) {
  3705. if (this.regexp_eatBracedQuantifier(state, true)) {
  3706. state.raise("Nothing to repeat");
  3707. }
  3708. return false
  3709. };
  3710. // https://www.ecma-international.org/ecma-262/8.0/#prod-SyntaxCharacter
  3711. pp$1.regexp_eatSyntaxCharacter = function(state) {
  3712. var ch = state.current();
  3713. if (isSyntaxCharacter(ch)) {
  3714. state.lastIntValue = ch;
  3715. state.advance();
  3716. return true
  3717. }
  3718. return false
  3719. };
  3720. function isSyntaxCharacter(ch) {
  3721. return (
  3722. ch === 0x24 /* $ */ ||
  3723. ch >= 0x28 /* ( */ && ch <= 0x2B /* + */ ||
  3724. ch === 0x2E /* . */ ||
  3725. ch === 0x3F /* ? */ ||
  3726. ch >= 0x5B /* [ */ && ch <= 0x5E /* ^ */ ||
  3727. ch >= 0x7B /* { */ && ch <= 0x7D /* } */
  3728. )
  3729. }
  3730. // https://www.ecma-international.org/ecma-262/8.0/#prod-PatternCharacter
  3731. // But eat eager.
  3732. pp$1.regexp_eatPatternCharacters = function(state) {
  3733. var start = state.pos;
  3734. var ch = 0;
  3735. while ((ch = state.current()) !== -1 && !isSyntaxCharacter(ch)) {
  3736. state.advance();
  3737. }
  3738. return state.pos !== start
  3739. };
  3740. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-ExtendedPatternCharacter
  3741. pp$1.regexp_eatExtendedPatternCharacter = function(state) {
  3742. var ch = state.current();
  3743. if (
  3744. ch !== -1 &&
  3745. ch !== 0x24 /* $ */ &&
  3746. !(ch >= 0x28 /* ( */ && ch <= 0x2B /* + */) &&
  3747. ch !== 0x2E /* . */ &&
  3748. ch !== 0x3F /* ? */ &&
  3749. ch !== 0x5B /* [ */ &&
  3750. ch !== 0x5E /* ^ */ &&
  3751. ch !== 0x7C /* | */
  3752. ) {
  3753. state.advance();
  3754. return true
  3755. }
  3756. return false
  3757. };
  3758. // GroupSpecifier ::
  3759. // [empty]
  3760. // `?` GroupName
  3761. pp$1.regexp_groupSpecifier = function(state) {
  3762. if (state.eat(0x3F /* ? */)) {
  3763. if (!this.regexp_eatGroupName(state)) { state.raise("Invalid group"); }
  3764. var trackDisjunction = this.options.ecmaVersion >= 16;
  3765. var known = state.groupNames[state.lastStringValue];
  3766. if (known) {
  3767. if (trackDisjunction) {
  3768. for (var i = 0, list = known; i < list.length; i += 1) {
  3769. var altID = list[i];
  3770. if (!altID.separatedFrom(state.branchID))
  3771. { state.raise("Duplicate capture group name"); }
  3772. }
  3773. } else {
  3774. state.raise("Duplicate capture group name");
  3775. }
  3776. }
  3777. if (trackDisjunction) {
  3778. (known || (state.groupNames[state.lastStringValue] = [])).push(state.branchID);
  3779. } else {
  3780. state.groupNames[state.lastStringValue] = true;
  3781. }
  3782. }
  3783. };
  3784. // GroupName ::
  3785. // `<` RegExpIdentifierName `>`
  3786. // Note: this updates `state.lastStringValue` property with the eaten name.
  3787. pp$1.regexp_eatGroupName = function(state) {
  3788. state.lastStringValue = "";
  3789. if (state.eat(0x3C /* < */)) {
  3790. if (this.regexp_eatRegExpIdentifierName(state) && state.eat(0x3E /* > */)) {
  3791. return true
  3792. }
  3793. state.raise("Invalid capture group name");
  3794. }
  3795. return false
  3796. };
  3797. // RegExpIdentifierName ::
  3798. // RegExpIdentifierStart
  3799. // RegExpIdentifierName RegExpIdentifierPart
  3800. // Note: this updates `state.lastStringValue` property with the eaten name.
  3801. pp$1.regexp_eatRegExpIdentifierName = function(state) {
  3802. state.lastStringValue = "";
  3803. if (this.regexp_eatRegExpIdentifierStart(state)) {
  3804. state.lastStringValue += codePointToString(state.lastIntValue);
  3805. while (this.regexp_eatRegExpIdentifierPart(state)) {
  3806. state.lastStringValue += codePointToString(state.lastIntValue);
  3807. }
  3808. return true
  3809. }
  3810. return false
  3811. };
  3812. // RegExpIdentifierStart ::
  3813. // UnicodeIDStart
  3814. // `$`
  3815. // `_`
  3816. // `\` RegExpUnicodeEscapeSequence[+U]
  3817. pp$1.regexp_eatRegExpIdentifierStart = function(state) {
  3818. var start = state.pos;
  3819. var forceU = this.options.ecmaVersion >= 11;
  3820. var ch = state.current(forceU);
  3821. state.advance(forceU);
  3822. if (ch === 0x5C /* \ */ && this.regexp_eatRegExpUnicodeEscapeSequence(state, forceU)) {
  3823. ch = state.lastIntValue;
  3824. }
  3825. if (isRegExpIdentifierStart(ch)) {
  3826. state.lastIntValue = ch;
  3827. return true
  3828. }
  3829. state.pos = start;
  3830. return false
  3831. };
  3832. function isRegExpIdentifierStart(ch) {
  3833. return isIdentifierStart(ch, true) || ch === 0x24 /* $ */ || ch === 0x5F /* _ */
  3834. }
  3835. // RegExpIdentifierPart ::
  3836. // UnicodeIDContinue
  3837. // `$`
  3838. // `_`
  3839. // `\` RegExpUnicodeEscapeSequence[+U]
  3840. // <ZWNJ>
  3841. // <ZWJ>
  3842. pp$1.regexp_eatRegExpIdentifierPart = function(state) {
  3843. var start = state.pos;
  3844. var forceU = this.options.ecmaVersion >= 11;
  3845. var ch = state.current(forceU);
  3846. state.advance(forceU);
  3847. if (ch === 0x5C /* \ */ && this.regexp_eatRegExpUnicodeEscapeSequence(state, forceU)) {
  3848. ch = state.lastIntValue;
  3849. }
  3850. if (isRegExpIdentifierPart(ch)) {
  3851. state.lastIntValue = ch;
  3852. return true
  3853. }
  3854. state.pos = start;
  3855. return false
  3856. };
  3857. function isRegExpIdentifierPart(ch) {
  3858. return isIdentifierChar(ch, true) || ch === 0x24 /* $ */ || ch === 0x5F /* _ */ || ch === 0x200C /* <ZWNJ> */ || ch === 0x200D /* <ZWJ> */
  3859. }
  3860. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-AtomEscape
  3861. pp$1.regexp_eatAtomEscape = function(state) {
  3862. if (
  3863. this.regexp_eatBackReference(state) ||
  3864. this.regexp_eatCharacterClassEscape(state) ||
  3865. this.regexp_eatCharacterEscape(state) ||
  3866. (state.switchN && this.regexp_eatKGroupName(state))
  3867. ) {
  3868. return true
  3869. }
  3870. if (state.switchU) {
  3871. // Make the same message as V8.
  3872. if (state.current() === 0x63 /* c */) {
  3873. state.raise("Invalid unicode escape");
  3874. }
  3875. state.raise("Invalid escape");
  3876. }
  3877. return false
  3878. };
  3879. pp$1.regexp_eatBackReference = function(state) {
  3880. var start = state.pos;
  3881. if (this.regexp_eatDecimalEscape(state)) {
  3882. var n = state.lastIntValue;
  3883. if (state.switchU) {
  3884. // For SyntaxError in https://www.ecma-international.org/ecma-262/8.0/#sec-atomescape
  3885. if (n > state.maxBackReference) {
  3886. state.maxBackReference = n;
  3887. }
  3888. return true
  3889. }
  3890. if (n <= state.numCapturingParens) {
  3891. return true
  3892. }
  3893. state.pos = start;
  3894. }
  3895. return false
  3896. };
  3897. pp$1.regexp_eatKGroupName = function(state) {
  3898. if (state.eat(0x6B /* k */)) {
  3899. if (this.regexp_eatGroupName(state)) {
  3900. state.backReferenceNames.push(state.lastStringValue);
  3901. return true
  3902. }
  3903. state.raise("Invalid named reference");
  3904. }
  3905. return false
  3906. };
  3907. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-CharacterEscape
  3908. pp$1.regexp_eatCharacterEscape = function(state) {
  3909. return (
  3910. this.regexp_eatControlEscape(state) ||
  3911. this.regexp_eatCControlLetter(state) ||
  3912. this.regexp_eatZero(state) ||
  3913. this.regexp_eatHexEscapeSequence(state) ||
  3914. this.regexp_eatRegExpUnicodeEscapeSequence(state, false) ||
  3915. (!state.switchU && this.regexp_eatLegacyOctalEscapeSequence(state)) ||
  3916. this.regexp_eatIdentityEscape(state)
  3917. )
  3918. };
  3919. pp$1.regexp_eatCControlLetter = function(state) {
  3920. var start = state.pos;
  3921. if (state.eat(0x63 /* c */)) {
  3922. if (this.regexp_eatControlLetter(state)) {
  3923. return true
  3924. }
  3925. state.pos = start;
  3926. }
  3927. return false
  3928. };
  3929. pp$1.regexp_eatZero = function(state) {
  3930. if (state.current() === 0x30 /* 0 */ && !isDecimalDigit(state.lookahead())) {
  3931. state.lastIntValue = 0;
  3932. state.advance();
  3933. return true
  3934. }
  3935. return false
  3936. };
  3937. // https://www.ecma-international.org/ecma-262/8.0/#prod-ControlEscape
  3938. pp$1.regexp_eatControlEscape = function(state) {
  3939. var ch = state.current();
  3940. if (ch === 0x74 /* t */) {
  3941. state.lastIntValue = 0x09; /* \t */
  3942. state.advance();
  3943. return true
  3944. }
  3945. if (ch === 0x6E /* n */) {
  3946. state.lastIntValue = 0x0A; /* \n */
  3947. state.advance();
  3948. return true
  3949. }
  3950. if (ch === 0x76 /* v */) {
  3951. state.lastIntValue = 0x0B; /* \v */
  3952. state.advance();
  3953. return true
  3954. }
  3955. if (ch === 0x66 /* f */) {
  3956. state.lastIntValue = 0x0C; /* \f */
  3957. state.advance();
  3958. return true
  3959. }
  3960. if (ch === 0x72 /* r */) {
  3961. state.lastIntValue = 0x0D; /* \r */
  3962. state.advance();
  3963. return true
  3964. }
  3965. return false
  3966. };
  3967. // https://www.ecma-international.org/ecma-262/8.0/#prod-ControlLetter
  3968. pp$1.regexp_eatControlLetter = function(state) {
  3969. var ch = state.current();
  3970. if (isControlLetter(ch)) {
  3971. state.lastIntValue = ch % 0x20;
  3972. state.advance();
  3973. return true
  3974. }
  3975. return false
  3976. };
  3977. function isControlLetter(ch) {
  3978. return (
  3979. (ch >= 0x41 /* A */ && ch <= 0x5A /* Z */) ||
  3980. (ch >= 0x61 /* a */ && ch <= 0x7A /* z */)
  3981. )
  3982. }
  3983. // https://www.ecma-international.org/ecma-262/8.0/#prod-RegExpUnicodeEscapeSequence
  3984. pp$1.regexp_eatRegExpUnicodeEscapeSequence = function(state, forceU) {
  3985. if ( forceU === void 0 ) forceU = false;
  3986. var start = state.pos;
  3987. var switchU = forceU || state.switchU;
  3988. if (state.eat(0x75 /* u */)) {
  3989. if (this.regexp_eatFixedHexDigits(state, 4)) {
  3990. var lead = state.lastIntValue;
  3991. if (switchU && lead >= 0xD800 && lead <= 0xDBFF) {
  3992. var leadSurrogateEnd = state.pos;
  3993. if (state.eat(0x5C /* \ */) && state.eat(0x75 /* u */) && this.regexp_eatFixedHexDigits(state, 4)) {
  3994. var trail = state.lastIntValue;
  3995. if (trail >= 0xDC00 && trail <= 0xDFFF) {
  3996. state.lastIntValue = (lead - 0xD800) * 0x400 + (trail - 0xDC00) + 0x10000;
  3997. return true
  3998. }
  3999. }
  4000. state.pos = leadSurrogateEnd;
  4001. state.lastIntValue = lead;
  4002. }
  4003. return true
  4004. }
  4005. if (
  4006. switchU &&
  4007. state.eat(0x7B /* { */) &&
  4008. this.regexp_eatHexDigits(state) &&
  4009. state.eat(0x7D /* } */) &&
  4010. isValidUnicode(state.lastIntValue)
  4011. ) {
  4012. return true
  4013. }
  4014. if (switchU) {
  4015. state.raise("Invalid unicode escape");
  4016. }
  4017. state.pos = start;
  4018. }
  4019. return false
  4020. };
  4021. function isValidUnicode(ch) {
  4022. return ch >= 0 && ch <= 0x10FFFF
  4023. }
  4024. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-IdentityEscape
  4025. pp$1.regexp_eatIdentityEscape = function(state) {
  4026. if (state.switchU) {
  4027. if (this.regexp_eatSyntaxCharacter(state)) {
  4028. return true
  4029. }
  4030. if (state.eat(0x2F /* / */)) {
  4031. state.lastIntValue = 0x2F; /* / */
  4032. return true
  4033. }
  4034. return false
  4035. }
  4036. var ch = state.current();
  4037. if (ch !== 0x63 /* c */ && (!state.switchN || ch !== 0x6B /* k */)) {
  4038. state.lastIntValue = ch;
  4039. state.advance();
  4040. return true
  4041. }
  4042. return false
  4043. };
  4044. // https://www.ecma-international.org/ecma-262/8.0/#prod-DecimalEscape
  4045. pp$1.regexp_eatDecimalEscape = function(state) {
  4046. state.lastIntValue = 0;
  4047. var ch = state.current();
  4048. if (ch >= 0x31 /* 1 */ && ch <= 0x39 /* 9 */) {
  4049. do {
  4050. state.lastIntValue = 10 * state.lastIntValue + (ch - 0x30 /* 0 */);
  4051. state.advance();
  4052. } while ((ch = state.current()) >= 0x30 /* 0 */ && ch <= 0x39 /* 9 */)
  4053. return true
  4054. }
  4055. return false
  4056. };
  4057. // Return values used by character set parsing methods, needed to
  4058. // forbid negation of sets that can match strings.
  4059. var CharSetNone = 0; // Nothing parsed
  4060. var CharSetOk = 1; // Construct parsed, cannot contain strings
  4061. var CharSetString = 2; // Construct parsed, can contain strings
  4062. // https://www.ecma-international.org/ecma-262/8.0/#prod-CharacterClassEscape
  4063. pp$1.regexp_eatCharacterClassEscape = function(state) {
  4064. var ch = state.current();
  4065. if (isCharacterClassEscape(ch)) {
  4066. state.lastIntValue = -1;
  4067. state.advance();
  4068. return CharSetOk
  4069. }
  4070. var negate = false;
  4071. if (
  4072. state.switchU &&
  4073. this.options.ecmaVersion >= 9 &&
  4074. ((negate = ch === 0x50 /* P */) || ch === 0x70 /* p */)
  4075. ) {
  4076. state.lastIntValue = -1;
  4077. state.advance();
  4078. var result;
  4079. if (
  4080. state.eat(0x7B /* { */) &&
  4081. (result = this.regexp_eatUnicodePropertyValueExpression(state)) &&
  4082. state.eat(0x7D /* } */)
  4083. ) {
  4084. if (negate && result === CharSetString) { state.raise("Invalid property name"); }
  4085. return result
  4086. }
  4087. state.raise("Invalid property name");
  4088. }
  4089. return CharSetNone
  4090. };
  4091. function isCharacterClassEscape(ch) {
  4092. return (
  4093. ch === 0x64 /* d */ ||
  4094. ch === 0x44 /* D */ ||
  4095. ch === 0x73 /* s */ ||
  4096. ch === 0x53 /* S */ ||
  4097. ch === 0x77 /* w */ ||
  4098. ch === 0x57 /* W */
  4099. )
  4100. }
  4101. // UnicodePropertyValueExpression ::
  4102. // UnicodePropertyName `=` UnicodePropertyValue
  4103. // LoneUnicodePropertyNameOrValue
  4104. pp$1.regexp_eatUnicodePropertyValueExpression = function(state) {
  4105. var start = state.pos;
  4106. // UnicodePropertyName `=` UnicodePropertyValue
  4107. if (this.regexp_eatUnicodePropertyName(state) && state.eat(0x3D /* = */)) {
  4108. var name = state.lastStringValue;
  4109. if (this.regexp_eatUnicodePropertyValue(state)) {
  4110. var value = state.lastStringValue;
  4111. this.regexp_validateUnicodePropertyNameAndValue(state, name, value);
  4112. return CharSetOk
  4113. }
  4114. }
  4115. state.pos = start;
  4116. // LoneUnicodePropertyNameOrValue
  4117. if (this.regexp_eatLoneUnicodePropertyNameOrValue(state)) {
  4118. var nameOrValue = state.lastStringValue;
  4119. return this.regexp_validateUnicodePropertyNameOrValue(state, nameOrValue)
  4120. }
  4121. return CharSetNone
  4122. };
  4123. pp$1.regexp_validateUnicodePropertyNameAndValue = function(state, name, value) {
  4124. if (!hasOwn(state.unicodeProperties.nonBinary, name))
  4125. { state.raise("Invalid property name"); }
  4126. if (!state.unicodeProperties.nonBinary[name].test(value))
  4127. { state.raise("Invalid property value"); }
  4128. };
  4129. pp$1.regexp_validateUnicodePropertyNameOrValue = function(state, nameOrValue) {
  4130. if (state.unicodeProperties.binary.test(nameOrValue)) { return CharSetOk }
  4131. if (state.switchV && state.unicodeProperties.binaryOfStrings.test(nameOrValue)) { return CharSetString }
  4132. state.raise("Invalid property name");
  4133. };
  4134. // UnicodePropertyName ::
  4135. // UnicodePropertyNameCharacters
  4136. pp$1.regexp_eatUnicodePropertyName = function(state) {
  4137. var ch = 0;
  4138. state.lastStringValue = "";
  4139. while (isUnicodePropertyNameCharacter(ch = state.current())) {
  4140. state.lastStringValue += codePointToString(ch);
  4141. state.advance();
  4142. }
  4143. return state.lastStringValue !== ""
  4144. };
  4145. function isUnicodePropertyNameCharacter(ch) {
  4146. return isControlLetter(ch) || ch === 0x5F /* _ */
  4147. }
  4148. // UnicodePropertyValue ::
  4149. // UnicodePropertyValueCharacters
  4150. pp$1.regexp_eatUnicodePropertyValue = function(state) {
  4151. var ch = 0;
  4152. state.lastStringValue = "";
  4153. while (isUnicodePropertyValueCharacter(ch = state.current())) {
  4154. state.lastStringValue += codePointToString(ch);
  4155. state.advance();
  4156. }
  4157. return state.lastStringValue !== ""
  4158. };
  4159. function isUnicodePropertyValueCharacter(ch) {
  4160. return isUnicodePropertyNameCharacter(ch) || isDecimalDigit(ch)
  4161. }
  4162. // LoneUnicodePropertyNameOrValue ::
  4163. // UnicodePropertyValueCharacters
  4164. pp$1.regexp_eatLoneUnicodePropertyNameOrValue = function(state) {
  4165. return this.regexp_eatUnicodePropertyValue(state)
  4166. };
  4167. // https://www.ecma-international.org/ecma-262/8.0/#prod-CharacterClass
  4168. pp$1.regexp_eatCharacterClass = function(state) {
  4169. if (state.eat(0x5B /* [ */)) {
  4170. var negate = state.eat(0x5E /* ^ */);
  4171. var result = this.regexp_classContents(state);
  4172. if (!state.eat(0x5D /* ] */))
  4173. { state.raise("Unterminated character class"); }
  4174. if (negate && result === CharSetString)
  4175. { state.raise("Negated character class may contain strings"); }
  4176. return true
  4177. }
  4178. return false
  4179. };
  4180. // https://tc39.es/ecma262/#prod-ClassContents
  4181. // https://www.ecma-international.org/ecma-262/8.0/#prod-ClassRanges
  4182. pp$1.regexp_classContents = function(state) {
  4183. if (state.current() === 0x5D /* ] */) { return CharSetOk }
  4184. if (state.switchV) { return this.regexp_classSetExpression(state) }
  4185. this.regexp_nonEmptyClassRanges(state);
  4186. return CharSetOk
  4187. };
  4188. // https://www.ecma-international.org/ecma-262/8.0/#prod-NonemptyClassRanges
  4189. // https://www.ecma-international.org/ecma-262/8.0/#prod-NonemptyClassRangesNoDash
  4190. pp$1.regexp_nonEmptyClassRanges = function(state) {
  4191. while (this.regexp_eatClassAtom(state)) {
  4192. var left = state.lastIntValue;
  4193. if (state.eat(0x2D /* - */) && this.regexp_eatClassAtom(state)) {
  4194. var right = state.lastIntValue;
  4195. if (state.switchU && (left === -1 || right === -1)) {
  4196. state.raise("Invalid character class");
  4197. }
  4198. if (left !== -1 && right !== -1 && left > right) {
  4199. state.raise("Range out of order in character class");
  4200. }
  4201. }
  4202. }
  4203. };
  4204. // https://www.ecma-international.org/ecma-262/8.0/#prod-ClassAtom
  4205. // https://www.ecma-international.org/ecma-262/8.0/#prod-ClassAtomNoDash
  4206. pp$1.regexp_eatClassAtom = function(state) {
  4207. var start = state.pos;
  4208. if (state.eat(0x5C /* \ */)) {
  4209. if (this.regexp_eatClassEscape(state)) {
  4210. return true
  4211. }
  4212. if (state.switchU) {
  4213. // Make the same message as V8.
  4214. var ch$1 = state.current();
  4215. if (ch$1 === 0x63 /* c */ || isOctalDigit(ch$1)) {
  4216. state.raise("Invalid class escape");
  4217. }
  4218. state.raise("Invalid escape");
  4219. }
  4220. state.pos = start;
  4221. }
  4222. var ch = state.current();
  4223. if (ch !== 0x5D /* ] */) {
  4224. state.lastIntValue = ch;
  4225. state.advance();
  4226. return true
  4227. }
  4228. return false
  4229. };
  4230. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-ClassEscape
  4231. pp$1.regexp_eatClassEscape = function(state) {
  4232. var start = state.pos;
  4233. if (state.eat(0x62 /* b */)) {
  4234. state.lastIntValue = 0x08; /* <BS> */
  4235. return true
  4236. }
  4237. if (state.switchU && state.eat(0x2D /* - */)) {
  4238. state.lastIntValue = 0x2D; /* - */
  4239. return true
  4240. }
  4241. if (!state.switchU && state.eat(0x63 /* c */)) {
  4242. if (this.regexp_eatClassControlLetter(state)) {
  4243. return true
  4244. }
  4245. state.pos = start;
  4246. }
  4247. return (
  4248. this.regexp_eatCharacterClassEscape(state) ||
  4249. this.regexp_eatCharacterEscape(state)
  4250. )
  4251. };
  4252. // https://tc39.es/ecma262/#prod-ClassSetExpression
  4253. // https://tc39.es/ecma262/#prod-ClassUnion
  4254. // https://tc39.es/ecma262/#prod-ClassIntersection
  4255. // https://tc39.es/ecma262/#prod-ClassSubtraction
  4256. pp$1.regexp_classSetExpression = function(state) {
  4257. var result = CharSetOk, subResult;
  4258. if (this.regexp_eatClassSetRange(state)) ; else if (subResult = this.regexp_eatClassSetOperand(state)) {
  4259. if (subResult === CharSetString) { result = CharSetString; }
  4260. // https://tc39.es/ecma262/#prod-ClassIntersection
  4261. var start = state.pos;
  4262. while (state.eatChars([0x26, 0x26] /* && */)) {
  4263. if (
  4264. state.current() !== 0x26 /* & */ &&
  4265. (subResult = this.regexp_eatClassSetOperand(state))
  4266. ) {
  4267. if (subResult !== CharSetString) { result = CharSetOk; }
  4268. continue
  4269. }
  4270. state.raise("Invalid character in character class");
  4271. }
  4272. if (start !== state.pos) { return result }
  4273. // https://tc39.es/ecma262/#prod-ClassSubtraction
  4274. while (state.eatChars([0x2D, 0x2D] /* -- */)) {
  4275. if (this.regexp_eatClassSetOperand(state)) { continue }
  4276. state.raise("Invalid character in character class");
  4277. }
  4278. if (start !== state.pos) { return result }
  4279. } else {
  4280. state.raise("Invalid character in character class");
  4281. }
  4282. // https://tc39.es/ecma262/#prod-ClassUnion
  4283. for (;;) {
  4284. if (this.regexp_eatClassSetRange(state)) { continue }
  4285. subResult = this.regexp_eatClassSetOperand(state);
  4286. if (!subResult) { return result }
  4287. if (subResult === CharSetString) { result = CharSetString; }
  4288. }
  4289. };
  4290. // https://tc39.es/ecma262/#prod-ClassSetRange
  4291. pp$1.regexp_eatClassSetRange = function(state) {
  4292. var start = state.pos;
  4293. if (this.regexp_eatClassSetCharacter(state)) {
  4294. var left = state.lastIntValue;
  4295. if (state.eat(0x2D /* - */) && this.regexp_eatClassSetCharacter(state)) {
  4296. var right = state.lastIntValue;
  4297. if (left !== -1 && right !== -1 && left > right) {
  4298. state.raise("Range out of order in character class");
  4299. }
  4300. return true
  4301. }
  4302. state.pos = start;
  4303. }
  4304. return false
  4305. };
  4306. // https://tc39.es/ecma262/#prod-ClassSetOperand
  4307. pp$1.regexp_eatClassSetOperand = function(state) {
  4308. if (this.regexp_eatClassSetCharacter(state)) { return CharSetOk }
  4309. return this.regexp_eatClassStringDisjunction(state) || this.regexp_eatNestedClass(state)
  4310. };
  4311. // https://tc39.es/ecma262/#prod-NestedClass
  4312. pp$1.regexp_eatNestedClass = function(state) {
  4313. var start = state.pos;
  4314. if (state.eat(0x5B /* [ */)) {
  4315. var negate = state.eat(0x5E /* ^ */);
  4316. var result = this.regexp_classContents(state);
  4317. if (state.eat(0x5D /* ] */)) {
  4318. if (negate && result === CharSetString) {
  4319. state.raise("Negated character class may contain strings");
  4320. }
  4321. return result
  4322. }
  4323. state.pos = start;
  4324. }
  4325. if (state.eat(0x5C /* \ */)) {
  4326. var result$1 = this.regexp_eatCharacterClassEscape(state);
  4327. if (result$1) {
  4328. return result$1
  4329. }
  4330. state.pos = start;
  4331. }
  4332. return null
  4333. };
  4334. // https://tc39.es/ecma262/#prod-ClassStringDisjunction
  4335. pp$1.regexp_eatClassStringDisjunction = function(state) {
  4336. var start = state.pos;
  4337. if (state.eatChars([0x5C, 0x71] /* \q */)) {
  4338. if (state.eat(0x7B /* { */)) {
  4339. var result = this.regexp_classStringDisjunctionContents(state);
  4340. if (state.eat(0x7D /* } */)) {
  4341. return result
  4342. }
  4343. } else {
  4344. // Make the same message as V8.
  4345. state.raise("Invalid escape");
  4346. }
  4347. state.pos = start;
  4348. }
  4349. return null
  4350. };
  4351. // https://tc39.es/ecma262/#prod-ClassStringDisjunctionContents
  4352. pp$1.regexp_classStringDisjunctionContents = function(state) {
  4353. var result = this.regexp_classString(state);
  4354. while (state.eat(0x7C /* | */)) {
  4355. if (this.regexp_classString(state) === CharSetString) { result = CharSetString; }
  4356. }
  4357. return result
  4358. };
  4359. // https://tc39.es/ecma262/#prod-ClassString
  4360. // https://tc39.es/ecma262/#prod-NonEmptyClassString
  4361. pp$1.regexp_classString = function(state) {
  4362. var count = 0;
  4363. while (this.regexp_eatClassSetCharacter(state)) { count++; }
  4364. return count === 1 ? CharSetOk : CharSetString
  4365. };
  4366. // https://tc39.es/ecma262/#prod-ClassSetCharacter
  4367. pp$1.regexp_eatClassSetCharacter = function(state) {
  4368. var start = state.pos;
  4369. if (state.eat(0x5C /* \ */)) {
  4370. if (
  4371. this.regexp_eatCharacterEscape(state) ||
  4372. this.regexp_eatClassSetReservedPunctuator(state)
  4373. ) {
  4374. return true
  4375. }
  4376. if (state.eat(0x62 /* b */)) {
  4377. state.lastIntValue = 0x08; /* <BS> */
  4378. return true
  4379. }
  4380. state.pos = start;
  4381. return false
  4382. }
  4383. var ch = state.current();
  4384. if (ch < 0 || ch === state.lookahead() && isClassSetReservedDoublePunctuatorCharacter(ch)) { return false }
  4385. if (isClassSetSyntaxCharacter(ch)) { return false }
  4386. state.advance();
  4387. state.lastIntValue = ch;
  4388. return true
  4389. };
  4390. // https://tc39.es/ecma262/#prod-ClassSetReservedDoublePunctuator
  4391. function isClassSetReservedDoublePunctuatorCharacter(ch) {
  4392. return (
  4393. ch === 0x21 /* ! */ ||
  4394. ch >= 0x23 /* # */ && ch <= 0x26 /* & */ ||
  4395. ch >= 0x2A /* * */ && ch <= 0x2C /* , */ ||
  4396. ch === 0x2E /* . */ ||
  4397. ch >= 0x3A /* : */ && ch <= 0x40 /* @ */ ||
  4398. ch === 0x5E /* ^ */ ||
  4399. ch === 0x60 /* ` */ ||
  4400. ch === 0x7E /* ~ */
  4401. )
  4402. }
  4403. // https://tc39.es/ecma262/#prod-ClassSetSyntaxCharacter
  4404. function isClassSetSyntaxCharacter(ch) {
  4405. return (
  4406. ch === 0x28 /* ( */ ||
  4407. ch === 0x29 /* ) */ ||
  4408. ch === 0x2D /* - */ ||
  4409. ch === 0x2F /* / */ ||
  4410. ch >= 0x5B /* [ */ && ch <= 0x5D /* ] */ ||
  4411. ch >= 0x7B /* { */ && ch <= 0x7D /* } */
  4412. )
  4413. }
  4414. // https://tc39.es/ecma262/#prod-ClassSetReservedPunctuator
  4415. pp$1.regexp_eatClassSetReservedPunctuator = function(state) {
  4416. var ch = state.current();
  4417. if (isClassSetReservedPunctuator(ch)) {
  4418. state.lastIntValue = ch;
  4419. state.advance();
  4420. return true
  4421. }
  4422. return false
  4423. };
  4424. // https://tc39.es/ecma262/#prod-ClassSetReservedPunctuator
  4425. function isClassSetReservedPunctuator(ch) {
  4426. return (
  4427. ch === 0x21 /* ! */ ||
  4428. ch === 0x23 /* # */ ||
  4429. ch === 0x25 /* % */ ||
  4430. ch === 0x26 /* & */ ||
  4431. ch === 0x2C /* , */ ||
  4432. ch === 0x2D /* - */ ||
  4433. ch >= 0x3A /* : */ && ch <= 0x3E /* > */ ||
  4434. ch === 0x40 /* @ */ ||
  4435. ch === 0x60 /* ` */ ||
  4436. ch === 0x7E /* ~ */
  4437. )
  4438. }
  4439. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-ClassControlLetter
  4440. pp$1.regexp_eatClassControlLetter = function(state) {
  4441. var ch = state.current();
  4442. if (isDecimalDigit(ch) || ch === 0x5F /* _ */) {
  4443. state.lastIntValue = ch % 0x20;
  4444. state.advance();
  4445. return true
  4446. }
  4447. return false
  4448. };
  4449. // https://www.ecma-international.org/ecma-262/8.0/#prod-HexEscapeSequence
  4450. pp$1.regexp_eatHexEscapeSequence = function(state) {
  4451. var start = state.pos;
  4452. if (state.eat(0x78 /* x */)) {
  4453. if (this.regexp_eatFixedHexDigits(state, 2)) {
  4454. return true
  4455. }
  4456. if (state.switchU) {
  4457. state.raise("Invalid escape");
  4458. }
  4459. state.pos = start;
  4460. }
  4461. return false
  4462. };
  4463. // https://www.ecma-international.org/ecma-262/8.0/#prod-DecimalDigits
  4464. pp$1.regexp_eatDecimalDigits = function(state) {
  4465. var start = state.pos;
  4466. var ch = 0;
  4467. state.lastIntValue = 0;
  4468. while (isDecimalDigit(ch = state.current())) {
  4469. state.lastIntValue = 10 * state.lastIntValue + (ch - 0x30 /* 0 */);
  4470. state.advance();
  4471. }
  4472. return state.pos !== start
  4473. };
  4474. function isDecimalDigit(ch) {
  4475. return ch >= 0x30 /* 0 */ && ch <= 0x39 /* 9 */
  4476. }
  4477. // https://www.ecma-international.org/ecma-262/8.0/#prod-HexDigits
  4478. pp$1.regexp_eatHexDigits = function(state) {
  4479. var start = state.pos;
  4480. var ch = 0;
  4481. state.lastIntValue = 0;
  4482. while (isHexDigit(ch = state.current())) {
  4483. state.lastIntValue = 16 * state.lastIntValue + hexToInt(ch);
  4484. state.advance();
  4485. }
  4486. return state.pos !== start
  4487. };
  4488. function isHexDigit(ch) {
  4489. return (
  4490. (ch >= 0x30 /* 0 */ && ch <= 0x39 /* 9 */) ||
  4491. (ch >= 0x41 /* A */ && ch <= 0x46 /* F */) ||
  4492. (ch >= 0x61 /* a */ && ch <= 0x66 /* f */)
  4493. )
  4494. }
  4495. function hexToInt(ch) {
  4496. if (ch >= 0x41 /* A */ && ch <= 0x46 /* F */) {
  4497. return 10 + (ch - 0x41 /* A */)
  4498. }
  4499. if (ch >= 0x61 /* a */ && ch <= 0x66 /* f */) {
  4500. return 10 + (ch - 0x61 /* a */)
  4501. }
  4502. return ch - 0x30 /* 0 */
  4503. }
  4504. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-LegacyOctalEscapeSequence
  4505. // Allows only 0-377(octal) i.e. 0-255(decimal).
  4506. pp$1.regexp_eatLegacyOctalEscapeSequence = function(state) {
  4507. if (this.regexp_eatOctalDigit(state)) {
  4508. var n1 = state.lastIntValue;
  4509. if (this.regexp_eatOctalDigit(state)) {
  4510. var n2 = state.lastIntValue;
  4511. if (n1 <= 3 && this.regexp_eatOctalDigit(state)) {
  4512. state.lastIntValue = n1 * 64 + n2 * 8 + state.lastIntValue;
  4513. } else {
  4514. state.lastIntValue = n1 * 8 + n2;
  4515. }
  4516. } else {
  4517. state.lastIntValue = n1;
  4518. }
  4519. return true
  4520. }
  4521. return false
  4522. };
  4523. // https://www.ecma-international.org/ecma-262/8.0/#prod-OctalDigit
  4524. pp$1.regexp_eatOctalDigit = function(state) {
  4525. var ch = state.current();
  4526. if (isOctalDigit(ch)) {
  4527. state.lastIntValue = ch - 0x30; /* 0 */
  4528. state.advance();
  4529. return true
  4530. }
  4531. state.lastIntValue = 0;
  4532. return false
  4533. };
  4534. function isOctalDigit(ch) {
  4535. return ch >= 0x30 /* 0 */ && ch <= 0x37 /* 7 */
  4536. }
  4537. // https://www.ecma-international.org/ecma-262/8.0/#prod-Hex4Digits
  4538. // https://www.ecma-international.org/ecma-262/8.0/#prod-HexDigit
  4539. // And HexDigit HexDigit in https://www.ecma-international.org/ecma-262/8.0/#prod-HexEscapeSequence
  4540. pp$1.regexp_eatFixedHexDigits = function(state, length) {
  4541. var start = state.pos;
  4542. state.lastIntValue = 0;
  4543. for (var i = 0; i < length; ++i) {
  4544. var ch = state.current();
  4545. if (!isHexDigit(ch)) {
  4546. state.pos = start;
  4547. return false
  4548. }
  4549. state.lastIntValue = 16 * state.lastIntValue + hexToInt(ch);
  4550. state.advance();
  4551. }
  4552. return true
  4553. };
  4554. // Object type used to represent tokens. Note that normally, tokens
  4555. // simply exist as properties on the parser object. This is only
  4556. // used for the onToken callback and the external tokenizer.
  4557. var Token = function Token(p) {
  4558. this.type = p.type;
  4559. this.value = p.value;
  4560. this.start = p.start;
  4561. this.end = p.end;
  4562. if (p.options.locations)
  4563. { this.loc = new SourceLocation(p, p.startLoc, p.endLoc); }
  4564. if (p.options.ranges)
  4565. { this.range = [p.start, p.end]; }
  4566. };
  4567. // ## Tokenizer
  4568. var pp = Parser.prototype;
  4569. // Move to the next token
  4570. pp.next = function(ignoreEscapeSequenceInKeyword) {
  4571. if (!ignoreEscapeSequenceInKeyword && this.type.keyword && this.containsEsc)
  4572. { this.raiseRecoverable(this.start, "Escape sequence in keyword " + this.type.keyword); }
  4573. if (this.options.onToken)
  4574. { this.options.onToken(new Token(this)); }
  4575. this.lastTokEnd = this.end;
  4576. this.lastTokStart = this.start;
  4577. this.lastTokEndLoc = this.endLoc;
  4578. this.lastTokStartLoc = this.startLoc;
  4579. this.nextToken();
  4580. };
  4581. pp.getToken = function() {
  4582. this.next();
  4583. return new Token(this)
  4584. };
  4585. // If we're in an ES6 environment, make parsers iterable
  4586. if (typeof Symbol !== "undefined")
  4587. { pp[Symbol.iterator] = function() {
  4588. var this$1$1 = this;
  4589. return {
  4590. next: function () {
  4591. var token = this$1$1.getToken();
  4592. return {
  4593. done: token.type === types$1.eof,
  4594. value: token
  4595. }
  4596. }
  4597. }
  4598. }; }
  4599. // Toggle strict mode. Re-reads the next number or string to please
  4600. // pedantic tests (`"use strict"; 010;` should fail).
  4601. // Read a single token, updating the parser object's token-related
  4602. // properties.
  4603. pp.nextToken = function() {
  4604. var curContext = this.curContext();
  4605. if (!curContext || !curContext.preserveSpace) { this.skipSpace(); }
  4606. this.start = this.pos;
  4607. if (this.options.locations) { this.startLoc = this.curPosition(); }
  4608. if (this.pos >= this.input.length) { return this.finishToken(types$1.eof) }
  4609. if (curContext.override) { return curContext.override(this) }
  4610. else { this.readToken(this.fullCharCodeAtPos()); }
  4611. };
  4612. pp.readToken = function(code) {
  4613. // Identifier or keyword. '\uXXXX' sequences are allowed in
  4614. // identifiers, so '\' also dispatches to that.
  4615. if (isIdentifierStart(code, this.options.ecmaVersion >= 6) || code === 92 /* '\' */)
  4616. { return this.readWord() }
  4617. return this.getTokenFromCode(code)
  4618. };
  4619. pp.fullCharCodeAtPos = function() {
  4620. var code = this.input.charCodeAt(this.pos);
  4621. if (code <= 0xd7ff || code >= 0xdc00) { return code }
  4622. var next = this.input.charCodeAt(this.pos + 1);
  4623. return next <= 0xdbff || next >= 0xe000 ? code : (code << 10) + next - 0x35fdc00
  4624. };
  4625. pp.skipBlockComment = function() {
  4626. var startLoc = this.options.onComment && this.curPosition();
  4627. var start = this.pos, end = this.input.indexOf("*/", this.pos += 2);
  4628. if (end === -1) { this.raise(this.pos - 2, "Unterminated comment"); }
  4629. this.pos = end + 2;
  4630. if (this.options.locations) {
  4631. for (var nextBreak = (void 0), pos = start; (nextBreak = nextLineBreak(this.input, pos, this.pos)) > -1;) {
  4632. ++this.curLine;
  4633. pos = this.lineStart = nextBreak;
  4634. }
  4635. }
  4636. if (this.options.onComment)
  4637. { this.options.onComment(true, this.input.slice(start + 2, end), start, this.pos,
  4638. startLoc, this.curPosition()); }
  4639. };
  4640. pp.skipLineComment = function(startSkip) {
  4641. var start = this.pos;
  4642. var startLoc = this.options.onComment && this.curPosition();
  4643. var ch = this.input.charCodeAt(this.pos += startSkip);
  4644. while (this.pos < this.input.length && !isNewLine(ch)) {
  4645. ch = this.input.charCodeAt(++this.pos);
  4646. }
  4647. if (this.options.onComment)
  4648. { this.options.onComment(false, this.input.slice(start + startSkip, this.pos), start, this.pos,
  4649. startLoc, this.curPosition()); }
  4650. };
  4651. // Called at the start of the parse and after every token. Skips
  4652. // whitespace and comments, and.
  4653. pp.skipSpace = function() {
  4654. loop: while (this.pos < this.input.length) {
  4655. var ch = this.input.charCodeAt(this.pos);
  4656. switch (ch) {
  4657. case 32: case 160: // ' '
  4658. ++this.pos;
  4659. break
  4660. case 13:
  4661. if (this.input.charCodeAt(this.pos + 1) === 10) {
  4662. ++this.pos;
  4663. }
  4664. case 10: case 8232: case 8233:
  4665. ++this.pos;
  4666. if (this.options.locations) {
  4667. ++this.curLine;
  4668. this.lineStart = this.pos;
  4669. }
  4670. break
  4671. case 47: // '/'
  4672. switch (this.input.charCodeAt(this.pos + 1)) {
  4673. case 42: // '*'
  4674. this.skipBlockComment();
  4675. break
  4676. case 47:
  4677. this.skipLineComment(2);
  4678. break
  4679. default:
  4680. break loop
  4681. }
  4682. break
  4683. default:
  4684. if (ch > 8 && ch < 14 || ch >= 5760 && nonASCIIwhitespace.test(String.fromCharCode(ch))) {
  4685. ++this.pos;
  4686. } else {
  4687. break loop
  4688. }
  4689. }
  4690. }
  4691. };
  4692. // Called at the end of every token. Sets `end`, `val`, and
  4693. // maintains `context` and `exprAllowed`, and skips the space after
  4694. // the token, so that the next one's `start` will point at the
  4695. // right position.
  4696. pp.finishToken = function(type, val) {
  4697. this.end = this.pos;
  4698. if (this.options.locations) { this.endLoc = this.curPosition(); }
  4699. var prevType = this.type;
  4700. this.type = type;
  4701. this.value = val;
  4702. this.updateContext(prevType);
  4703. };
  4704. // ### Token reading
  4705. // This is the function that is called to fetch the next token. It
  4706. // is somewhat obscure, because it works in character codes rather
  4707. // than characters, and because operator parsing has been inlined
  4708. // into it.
  4709. //
  4710. // All in the name of speed.
  4711. //
  4712. pp.readToken_dot = function() {
  4713. var next = this.input.charCodeAt(this.pos + 1);
  4714. if (next >= 48 && next <= 57) { return this.readNumber(true) }
  4715. var next2 = this.input.charCodeAt(this.pos + 2);
  4716. if (this.options.ecmaVersion >= 6 && next === 46 && next2 === 46) { // 46 = dot '.'
  4717. this.pos += 3;
  4718. return this.finishToken(types$1.ellipsis)
  4719. } else {
  4720. ++this.pos;
  4721. return this.finishToken(types$1.dot)
  4722. }
  4723. };
  4724. pp.readToken_slash = function() { // '/'
  4725. var next = this.input.charCodeAt(this.pos + 1);
  4726. if (this.exprAllowed) { ++this.pos; return this.readRegexp() }
  4727. if (next === 61) { return this.finishOp(types$1.assign, 2) }
  4728. return this.finishOp(types$1.slash, 1)
  4729. };
  4730. pp.readToken_mult_modulo_exp = function(code) { // '%*'
  4731. var next = this.input.charCodeAt(this.pos + 1);
  4732. var size = 1;
  4733. var tokentype = code === 42 ? types$1.star : types$1.modulo;
  4734. // exponentiation operator ** and **=
  4735. if (this.options.ecmaVersion >= 7 && code === 42 && next === 42) {
  4736. ++size;
  4737. tokentype = types$1.starstar;
  4738. next = this.input.charCodeAt(this.pos + 2);
  4739. }
  4740. if (next === 61) { return this.finishOp(types$1.assign, size + 1) }
  4741. return this.finishOp(tokentype, size)
  4742. };
  4743. pp.readToken_pipe_amp = function(code) { // '|&'
  4744. var next = this.input.charCodeAt(this.pos + 1);
  4745. if (next === code) {
  4746. if (this.options.ecmaVersion >= 12) {
  4747. var next2 = this.input.charCodeAt(this.pos + 2);
  4748. if (next2 === 61) { return this.finishOp(types$1.assign, 3) }
  4749. }
  4750. return this.finishOp(code === 124 ? types$1.logicalOR : types$1.logicalAND, 2)
  4751. }
  4752. if (next === 61) { return this.finishOp(types$1.assign, 2) }
  4753. return this.finishOp(code === 124 ? types$1.bitwiseOR : types$1.bitwiseAND, 1)
  4754. };
  4755. pp.readToken_caret = function() { // '^'
  4756. var next = this.input.charCodeAt(this.pos + 1);
  4757. if (next === 61) { return this.finishOp(types$1.assign, 2) }
  4758. return this.finishOp(types$1.bitwiseXOR, 1)
  4759. };
  4760. pp.readToken_plus_min = function(code) { // '+-'
  4761. var next = this.input.charCodeAt(this.pos + 1);
  4762. if (next === code) {
  4763. if (next === 45 && !this.inModule && this.input.charCodeAt(this.pos + 2) === 62 &&
  4764. (this.lastTokEnd === 0 || lineBreak.test(this.input.slice(this.lastTokEnd, this.pos)))) {
  4765. // A `-->` line comment
  4766. this.skipLineComment(3);
  4767. this.skipSpace();
  4768. return this.nextToken()
  4769. }
  4770. return this.finishOp(types$1.incDec, 2)
  4771. }
  4772. if (next === 61) { return this.finishOp(types$1.assign, 2) }
  4773. return this.finishOp(types$1.plusMin, 1)
  4774. };
  4775. pp.readToken_lt_gt = function(code) { // '<>'
  4776. var next = this.input.charCodeAt(this.pos + 1);
  4777. var size = 1;
  4778. if (next === code) {
  4779. size = code === 62 && this.input.charCodeAt(this.pos + 2) === 62 ? 3 : 2;
  4780. if (this.input.charCodeAt(this.pos + size) === 61) { return this.finishOp(types$1.assign, size + 1) }
  4781. return this.finishOp(types$1.bitShift, size)
  4782. }
  4783. if (next === 33 && code === 60 && !this.inModule && this.input.charCodeAt(this.pos + 2) === 45 &&
  4784. this.input.charCodeAt(this.pos + 3) === 45) {
  4785. // `<!--`, an XML-style comment that should be interpreted as a line comment
  4786. this.skipLineComment(4);
  4787. this.skipSpace();
  4788. return this.nextToken()
  4789. }
  4790. if (next === 61) { size = 2; }
  4791. return this.finishOp(types$1.relational, size)
  4792. };
  4793. pp.readToken_eq_excl = function(code) { // '=!'
  4794. var next = this.input.charCodeAt(this.pos + 1);
  4795. if (next === 61) { return this.finishOp(types$1.equality, this.input.charCodeAt(this.pos + 2) === 61 ? 3 : 2) }
  4796. if (code === 61 && next === 62 && this.options.ecmaVersion >= 6) { // '=>'
  4797. this.pos += 2;
  4798. return this.finishToken(types$1.arrow)
  4799. }
  4800. return this.finishOp(code === 61 ? types$1.eq : types$1.prefix, 1)
  4801. };
  4802. pp.readToken_question = function() { // '?'
  4803. var ecmaVersion = this.options.ecmaVersion;
  4804. if (ecmaVersion >= 11) {
  4805. var next = this.input.charCodeAt(this.pos + 1);
  4806. if (next === 46) {
  4807. var next2 = this.input.charCodeAt(this.pos + 2);
  4808. if (next2 < 48 || next2 > 57) { return this.finishOp(types$1.questionDot, 2) }
  4809. }
  4810. if (next === 63) {
  4811. if (ecmaVersion >= 12) {
  4812. var next2$1 = this.input.charCodeAt(this.pos + 2);
  4813. if (next2$1 === 61) { return this.finishOp(types$1.assign, 3) }
  4814. }
  4815. return this.finishOp(types$1.coalesce, 2)
  4816. }
  4817. }
  4818. return this.finishOp(types$1.question, 1)
  4819. };
  4820. pp.readToken_numberSign = function() { // '#'
  4821. var ecmaVersion = this.options.ecmaVersion;
  4822. var code = 35; // '#'
  4823. if (ecmaVersion >= 13) {
  4824. ++this.pos;
  4825. code = this.fullCharCodeAtPos();
  4826. if (isIdentifierStart(code, true) || code === 92 /* '\' */) {
  4827. return this.finishToken(types$1.privateId, this.readWord1())
  4828. }
  4829. }
  4830. this.raise(this.pos, "Unexpected character '" + codePointToString(code) + "'");
  4831. };
  4832. pp.getTokenFromCode = function(code) {
  4833. switch (code) {
  4834. // The interpretation of a dot depends on whether it is followed
  4835. // by a digit or another two dots.
  4836. case 46: // '.'
  4837. return this.readToken_dot()
  4838. // Punctuation tokens.
  4839. case 40: ++this.pos; return this.finishToken(types$1.parenL)
  4840. case 41: ++this.pos; return this.finishToken(types$1.parenR)
  4841. case 59: ++this.pos; return this.finishToken(types$1.semi)
  4842. case 44: ++this.pos; return this.finishToken(types$1.comma)
  4843. case 91: ++this.pos; return this.finishToken(types$1.bracketL)
  4844. case 93: ++this.pos; return this.finishToken(types$1.bracketR)
  4845. case 123: ++this.pos; return this.finishToken(types$1.braceL)
  4846. case 125: ++this.pos; return this.finishToken(types$1.braceR)
  4847. case 58: ++this.pos; return this.finishToken(types$1.colon)
  4848. case 96: // '`'
  4849. if (this.options.ecmaVersion < 6) { break }
  4850. ++this.pos;
  4851. return this.finishToken(types$1.backQuote)
  4852. case 48: // '0'
  4853. var next = this.input.charCodeAt(this.pos + 1);
  4854. if (next === 120 || next === 88) { return this.readRadixNumber(16) } // '0x', '0X' - hex number
  4855. if (this.options.ecmaVersion >= 6) {
  4856. if (next === 111 || next === 79) { return this.readRadixNumber(8) } // '0o', '0O' - octal number
  4857. if (next === 98 || next === 66) { return this.readRadixNumber(2) } // '0b', '0B' - binary number
  4858. }
  4859. // Anything else beginning with a digit is an integer, octal
  4860. // number, or float.
  4861. case 49: case 50: case 51: case 52: case 53: case 54: case 55: case 56: case 57: // 1-9
  4862. return this.readNumber(false)
  4863. // Quotes produce strings.
  4864. case 34: case 39: // '"', "'"
  4865. return this.readString(code)
  4866. // Operators are parsed inline in tiny state machines. '=' (61) is
  4867. // often referred to. `finishOp` simply skips the amount of
  4868. // characters it is given as second argument, and returns a token
  4869. // of the type given by its first argument.
  4870. case 47: // '/'
  4871. return this.readToken_slash()
  4872. case 37: case 42: // '%*'
  4873. return this.readToken_mult_modulo_exp(code)
  4874. case 124: case 38: // '|&'
  4875. return this.readToken_pipe_amp(code)
  4876. case 94: // '^'
  4877. return this.readToken_caret()
  4878. case 43: case 45: // '+-'
  4879. return this.readToken_plus_min(code)
  4880. case 60: case 62: // '<>'
  4881. return this.readToken_lt_gt(code)
  4882. case 61: case 33: // '=!'
  4883. return this.readToken_eq_excl(code)
  4884. case 63: // '?'
  4885. return this.readToken_question()
  4886. case 126: // '~'
  4887. return this.finishOp(types$1.prefix, 1)
  4888. case 35: // '#'
  4889. return this.readToken_numberSign()
  4890. }
  4891. this.raise(this.pos, "Unexpected character '" + codePointToString(code) + "'");
  4892. };
  4893. pp.finishOp = function(type, size) {
  4894. var str = this.input.slice(this.pos, this.pos + size);
  4895. this.pos += size;
  4896. return this.finishToken(type, str)
  4897. };
  4898. pp.readRegexp = function() {
  4899. var escaped, inClass, start = this.pos;
  4900. for (;;) {
  4901. if (this.pos >= this.input.length) { this.raise(start, "Unterminated regular expression"); }
  4902. var ch = this.input.charAt(this.pos);
  4903. if (lineBreak.test(ch)) { this.raise(start, "Unterminated regular expression"); }
  4904. if (!escaped) {
  4905. if (ch === "[") { inClass = true; }
  4906. else if (ch === "]" && inClass) { inClass = false; }
  4907. else if (ch === "/" && !inClass) { break }
  4908. escaped = ch === "\\";
  4909. } else { escaped = false; }
  4910. ++this.pos;
  4911. }
  4912. var pattern = this.input.slice(start, this.pos);
  4913. ++this.pos;
  4914. var flagsStart = this.pos;
  4915. var flags = this.readWord1();
  4916. if (this.containsEsc) { this.unexpected(flagsStart); }
  4917. // Validate pattern
  4918. var state = this.regexpState || (this.regexpState = new RegExpValidationState(this));
  4919. state.reset(start, pattern, flags);
  4920. this.validateRegExpFlags(state);
  4921. this.validateRegExpPattern(state);
  4922. // Create Literal#value property value.
  4923. var value = null;
  4924. try {
  4925. value = new RegExp(pattern, flags);
  4926. } catch (e) {
  4927. // ESTree requires null if it failed to instantiate RegExp object.
  4928. // https://github.com/estree/estree/blob/a27003adf4fd7bfad44de9cef372a2eacd527b1c/es5.md#regexpliteral
  4929. }
  4930. return this.finishToken(types$1.regexp, {pattern: pattern, flags: flags, value: value})
  4931. };
  4932. // Read an integer in the given radix. Return null if zero digits
  4933. // were read, the integer value otherwise. When `len` is given, this
  4934. // will return `null` unless the integer has exactly `len` digits.
  4935. pp.readInt = function(radix, len, maybeLegacyOctalNumericLiteral) {
  4936. // `len` is used for character escape sequences. In that case, disallow separators.
  4937. var allowSeparators = this.options.ecmaVersion >= 12 && len === undefined;
  4938. // `maybeLegacyOctalNumericLiteral` is true if it doesn't have prefix (0x,0o,0b)
  4939. // and isn't fraction part nor exponent part. In that case, if the first digit
  4940. // is zero then disallow separators.
  4941. var isLegacyOctalNumericLiteral = maybeLegacyOctalNumericLiteral && this.input.charCodeAt(this.pos) === 48;
  4942. var start = this.pos, total = 0, lastCode = 0;
  4943. for (var i = 0, e = len == null ? Infinity : len; i < e; ++i, ++this.pos) {
  4944. var code = this.input.charCodeAt(this.pos), val = (void 0);
  4945. if (allowSeparators && code === 95) {
  4946. if (isLegacyOctalNumericLiteral) { this.raiseRecoverable(this.pos, "Numeric separator is not allowed in legacy octal numeric literals"); }
  4947. if (lastCode === 95) { this.raiseRecoverable(this.pos, "Numeric separator must be exactly one underscore"); }
  4948. if (i === 0) { this.raiseRecoverable(this.pos, "Numeric separator is not allowed at the first of digits"); }
  4949. lastCode = code;
  4950. continue
  4951. }
  4952. if (code >= 97) { val = code - 97 + 10; } // a
  4953. else if (code >= 65) { val = code - 65 + 10; } // A
  4954. else if (code >= 48 && code <= 57) { val = code - 48; } // 0-9
  4955. else { val = Infinity; }
  4956. if (val >= radix) { break }
  4957. lastCode = code;
  4958. total = total * radix + val;
  4959. }
  4960. if (allowSeparators && lastCode === 95) { this.raiseRecoverable(this.pos - 1, "Numeric separator is not allowed at the last of digits"); }
  4961. if (this.pos === start || len != null && this.pos - start !== len) { return null }
  4962. return total
  4963. };
  4964. function stringToNumber(str, isLegacyOctalNumericLiteral) {
  4965. if (isLegacyOctalNumericLiteral) {
  4966. return parseInt(str, 8)
  4967. }
  4968. // `parseFloat(value)` stops parsing at the first numeric separator then returns a wrong value.
  4969. return parseFloat(str.replace(/_/g, ""))
  4970. }
  4971. function stringToBigInt(str) {
  4972. if (typeof BigInt !== "function") {
  4973. return null
  4974. }
  4975. // `BigInt(value)` throws syntax error if the string contains numeric separators.
  4976. return BigInt(str.replace(/_/g, ""))
  4977. }
  4978. pp.readRadixNumber = function(radix) {
  4979. var start = this.pos;
  4980. this.pos += 2; // 0x
  4981. var val = this.readInt(radix);
  4982. if (val == null) { this.raise(this.start + 2, "Expected number in radix " + radix); }
  4983. if (this.options.ecmaVersion >= 11 && this.input.charCodeAt(this.pos) === 110) {
  4984. val = stringToBigInt(this.input.slice(start, this.pos));
  4985. ++this.pos;
  4986. } else if (isIdentifierStart(this.fullCharCodeAtPos())) { this.raise(this.pos, "Identifier directly after number"); }
  4987. return this.finishToken(types$1.num, val)
  4988. };
  4989. // Read an integer, octal integer, or floating-point number.
  4990. pp.readNumber = function(startsWithDot) {
  4991. var start = this.pos;
  4992. if (!startsWithDot && this.readInt(10, undefined, true) === null) { this.raise(start, "Invalid number"); }
  4993. var octal = this.pos - start >= 2 && this.input.charCodeAt(start) === 48;
  4994. if (octal && this.strict) { this.raise(start, "Invalid number"); }
  4995. var next = this.input.charCodeAt(this.pos);
  4996. if (!octal && !startsWithDot && this.options.ecmaVersion >= 11 && next === 110) {
  4997. var val$1 = stringToBigInt(this.input.slice(start, this.pos));
  4998. ++this.pos;
  4999. if (isIdentifierStart(this.fullCharCodeAtPos())) { this.raise(this.pos, "Identifier directly after number"); }
  5000. return this.finishToken(types$1.num, val$1)
  5001. }
  5002. if (octal && /[89]/.test(this.input.slice(start, this.pos))) { octal = false; }
  5003. if (next === 46 && !octal) { // '.'
  5004. ++this.pos;
  5005. this.readInt(10);
  5006. next = this.input.charCodeAt(this.pos);
  5007. }
  5008. if ((next === 69 || next === 101) && !octal) { // 'eE'
  5009. next = this.input.charCodeAt(++this.pos);
  5010. if (next === 43 || next === 45) { ++this.pos; } // '+-'
  5011. if (this.readInt(10) === null) { this.raise(start, "Invalid number"); }
  5012. }
  5013. if (isIdentifierStart(this.fullCharCodeAtPos())) { this.raise(this.pos, "Identifier directly after number"); }
  5014. var val = stringToNumber(this.input.slice(start, this.pos), octal);
  5015. return this.finishToken(types$1.num, val)
  5016. };
  5017. // Read a string value, interpreting backslash-escapes.
  5018. pp.readCodePoint = function() {
  5019. var ch = this.input.charCodeAt(this.pos), code;
  5020. if (ch === 123) { // '{'
  5021. if (this.options.ecmaVersion < 6) { this.unexpected(); }
  5022. var codePos = ++this.pos;
  5023. code = this.readHexChar(this.input.indexOf("}", this.pos) - this.pos);
  5024. ++this.pos;
  5025. if (code > 0x10FFFF) { this.invalidStringToken(codePos, "Code point out of bounds"); }
  5026. } else {
  5027. code = this.readHexChar(4);
  5028. }
  5029. return code
  5030. };
  5031. pp.readString = function(quote) {
  5032. var out = "", chunkStart = ++this.pos;
  5033. for (;;) {
  5034. if (this.pos >= this.input.length) { this.raise(this.start, "Unterminated string constant"); }
  5035. var ch = this.input.charCodeAt(this.pos);
  5036. if (ch === quote) { break }
  5037. if (ch === 92) { // '\'
  5038. out += this.input.slice(chunkStart, this.pos);
  5039. out += this.readEscapedChar(false);
  5040. chunkStart = this.pos;
  5041. } else if (ch === 0x2028 || ch === 0x2029) {
  5042. if (this.options.ecmaVersion < 10) { this.raise(this.start, "Unterminated string constant"); }
  5043. ++this.pos;
  5044. if (this.options.locations) {
  5045. this.curLine++;
  5046. this.lineStart = this.pos;
  5047. }
  5048. } else {
  5049. if (isNewLine(ch)) { this.raise(this.start, "Unterminated string constant"); }
  5050. ++this.pos;
  5051. }
  5052. }
  5053. out += this.input.slice(chunkStart, this.pos++);
  5054. return this.finishToken(types$1.string, out)
  5055. };
  5056. // Reads template string tokens.
  5057. var INVALID_TEMPLATE_ESCAPE_ERROR = {};
  5058. pp.tryReadTemplateToken = function() {
  5059. this.inTemplateElement = true;
  5060. try {
  5061. this.readTmplToken();
  5062. } catch (err) {
  5063. if (err === INVALID_TEMPLATE_ESCAPE_ERROR) {
  5064. this.readInvalidTemplateToken();
  5065. } else {
  5066. throw err
  5067. }
  5068. }
  5069. this.inTemplateElement = false;
  5070. };
  5071. pp.invalidStringToken = function(position, message) {
  5072. if (this.inTemplateElement && this.options.ecmaVersion >= 9) {
  5073. throw INVALID_TEMPLATE_ESCAPE_ERROR
  5074. } else {
  5075. this.raise(position, message);
  5076. }
  5077. };
  5078. pp.readTmplToken = function() {
  5079. var out = "", chunkStart = this.pos;
  5080. for (;;) {
  5081. if (this.pos >= this.input.length) { this.raise(this.start, "Unterminated template"); }
  5082. var ch = this.input.charCodeAt(this.pos);
  5083. if (ch === 96 || ch === 36 && this.input.charCodeAt(this.pos + 1) === 123) { // '`', '${'
  5084. if (this.pos === this.start && (this.type === types$1.template || this.type === types$1.invalidTemplate)) {
  5085. if (ch === 36) {
  5086. this.pos += 2;
  5087. return this.finishToken(types$1.dollarBraceL)
  5088. } else {
  5089. ++this.pos;
  5090. return this.finishToken(types$1.backQuote)
  5091. }
  5092. }
  5093. out += this.input.slice(chunkStart, this.pos);
  5094. return this.finishToken(types$1.template, out)
  5095. }
  5096. if (ch === 92) { // '\'
  5097. out += this.input.slice(chunkStart, this.pos);
  5098. out += this.readEscapedChar(true);
  5099. chunkStart = this.pos;
  5100. } else if (isNewLine(ch)) {
  5101. out += this.input.slice(chunkStart, this.pos);
  5102. ++this.pos;
  5103. switch (ch) {
  5104. case 13:
  5105. if (this.input.charCodeAt(this.pos) === 10) { ++this.pos; }
  5106. case 10:
  5107. out += "\n";
  5108. break
  5109. default:
  5110. out += String.fromCharCode(ch);
  5111. break
  5112. }
  5113. if (this.options.locations) {
  5114. ++this.curLine;
  5115. this.lineStart = this.pos;
  5116. }
  5117. chunkStart = this.pos;
  5118. } else {
  5119. ++this.pos;
  5120. }
  5121. }
  5122. };
  5123. // Reads a template token to search for the end, without validating any escape sequences
  5124. pp.readInvalidTemplateToken = function() {
  5125. for (; this.pos < this.input.length; this.pos++) {
  5126. switch (this.input[this.pos]) {
  5127. case "\\":
  5128. ++this.pos;
  5129. break
  5130. case "$":
  5131. if (this.input[this.pos + 1] !== "{") { break }
  5132. // fall through
  5133. case "`":
  5134. return this.finishToken(types$1.invalidTemplate, this.input.slice(this.start, this.pos))
  5135. case "\r":
  5136. if (this.input[this.pos + 1] === "\n") { ++this.pos; }
  5137. // fall through
  5138. case "\n": case "\u2028": case "\u2029":
  5139. ++this.curLine;
  5140. this.lineStart = this.pos + 1;
  5141. break
  5142. }
  5143. }
  5144. this.raise(this.start, "Unterminated template");
  5145. };
  5146. // Used to read escaped characters
  5147. pp.readEscapedChar = function(inTemplate) {
  5148. var ch = this.input.charCodeAt(++this.pos);
  5149. ++this.pos;
  5150. switch (ch) {
  5151. case 110: return "\n" // 'n' -> '\n'
  5152. case 114: return "\r" // 'r' -> '\r'
  5153. case 120: return String.fromCharCode(this.readHexChar(2)) // 'x'
  5154. case 117: return codePointToString(this.readCodePoint()) // 'u'
  5155. case 116: return "\t" // 't' -> '\t'
  5156. case 98: return "\b" // 'b' -> '\b'
  5157. case 118: return "\u000b" // 'v' -> '\u000b'
  5158. case 102: return "\f" // 'f' -> '\f'
  5159. case 13: if (this.input.charCodeAt(this.pos) === 10) { ++this.pos; } // '\r\n'
  5160. case 10: // ' \n'
  5161. if (this.options.locations) { this.lineStart = this.pos; ++this.curLine; }
  5162. return ""
  5163. case 56:
  5164. case 57:
  5165. if (this.strict) {
  5166. this.invalidStringToken(
  5167. this.pos - 1,
  5168. "Invalid escape sequence"
  5169. );
  5170. }
  5171. if (inTemplate) {
  5172. var codePos = this.pos - 1;
  5173. this.invalidStringToken(
  5174. codePos,
  5175. "Invalid escape sequence in template string"
  5176. );
  5177. }
  5178. default:
  5179. if (ch >= 48 && ch <= 55) {
  5180. var octalStr = this.input.substr(this.pos - 1, 3).match(/^[0-7]+/)[0];
  5181. var octal = parseInt(octalStr, 8);
  5182. if (octal > 255) {
  5183. octalStr = octalStr.slice(0, -1);
  5184. octal = parseInt(octalStr, 8);
  5185. }
  5186. this.pos += octalStr.length - 1;
  5187. ch = this.input.charCodeAt(this.pos);
  5188. if ((octalStr !== "0" || ch === 56 || ch === 57) && (this.strict || inTemplate)) {
  5189. this.invalidStringToken(
  5190. this.pos - 1 - octalStr.length,
  5191. inTemplate
  5192. ? "Octal literal in template string"
  5193. : "Octal literal in strict mode"
  5194. );
  5195. }
  5196. return String.fromCharCode(octal)
  5197. }
  5198. if (isNewLine(ch)) {
  5199. // Unicode new line characters after \ get removed from output in both
  5200. // template literals and strings
  5201. if (this.options.locations) { this.lineStart = this.pos; ++this.curLine; }
  5202. return ""
  5203. }
  5204. return String.fromCharCode(ch)
  5205. }
  5206. };
  5207. // Used to read character escape sequences ('\x', '\u', '\U').
  5208. pp.readHexChar = function(len) {
  5209. var codePos = this.pos;
  5210. var n = this.readInt(16, len);
  5211. if (n === null) { this.invalidStringToken(codePos, "Bad character escape sequence"); }
  5212. return n
  5213. };
  5214. // Read an identifier, and return it as a string. Sets `this.containsEsc`
  5215. // to whether the word contained a '\u' escape.
  5216. //
  5217. // Incrementally adds only escaped chars, adding other chunks as-is
  5218. // as a micro-optimization.
  5219. pp.readWord1 = function() {
  5220. this.containsEsc = false;
  5221. var word = "", first = true, chunkStart = this.pos;
  5222. var astral = this.options.ecmaVersion >= 6;
  5223. while (this.pos < this.input.length) {
  5224. var ch = this.fullCharCodeAtPos();
  5225. if (isIdentifierChar(ch, astral)) {
  5226. this.pos += ch <= 0xffff ? 1 : 2;
  5227. } else if (ch === 92) { // "\"
  5228. this.containsEsc = true;
  5229. word += this.input.slice(chunkStart, this.pos);
  5230. var escStart = this.pos;
  5231. if (this.input.charCodeAt(++this.pos) !== 117) // "u"
  5232. { this.invalidStringToken(this.pos, "Expecting Unicode escape sequence \\uXXXX"); }
  5233. ++this.pos;
  5234. var esc = this.readCodePoint();
  5235. if (!(first ? isIdentifierStart : isIdentifierChar)(esc, astral))
  5236. { this.invalidStringToken(escStart, "Invalid Unicode escape"); }
  5237. word += codePointToString(esc);
  5238. chunkStart = this.pos;
  5239. } else {
  5240. break
  5241. }
  5242. first = false;
  5243. }
  5244. return word + this.input.slice(chunkStart, this.pos)
  5245. };
  5246. // Read an identifier or keyword token. Will check for reserved
  5247. // words when necessary.
  5248. pp.readWord = function() {
  5249. var word = this.readWord1();
  5250. var type = types$1.name;
  5251. if (this.keywords.test(word)) {
  5252. type = keywords[word];
  5253. }
  5254. return this.finishToken(type, word)
  5255. };
  5256. // Acorn is a tiny, fast JavaScript parser written in JavaScript.
  5257. //
  5258. // Acorn was written by Marijn Haverbeke, Ingvar Stepanyan, and
  5259. // various contributors and released under an MIT license.
  5260. //
  5261. // Git repositories for Acorn are available at
  5262. //
  5263. // http://marijnhaverbeke.nl/git/acorn
  5264. // https://github.com/acornjs/acorn.git
  5265. //
  5266. // Please use the [github bug tracker][ghbt] to report issues.
  5267. //
  5268. // [ghbt]: https://github.com/acornjs/acorn/issues
  5269. //
  5270. // [walk]: util/walk.js
  5271. var version = "8.12.1";
  5272. Parser.acorn = {
  5273. Parser: Parser,
  5274. version: version,
  5275. defaultOptions: defaultOptions,
  5276. Position: Position,
  5277. SourceLocation: SourceLocation,
  5278. getLineInfo: getLineInfo,
  5279. Node: Node,
  5280. TokenType: TokenType,
  5281. tokTypes: types$1,
  5282. keywordTypes: keywords,
  5283. TokContext: TokContext,
  5284. tokContexts: types,
  5285. isIdentifierChar: isIdentifierChar,
  5286. isIdentifierStart: isIdentifierStart,
  5287. Token: Token,
  5288. isNewLine: isNewLine,
  5289. lineBreak: lineBreak,
  5290. lineBreakG: lineBreakG,
  5291. nonASCIIwhitespace: nonASCIIwhitespace
  5292. };
  5293. // The main exported interface (under `self.acorn` when in the
  5294. // browser) is a `parse` function that takes a code string and returns
  5295. // an abstract syntax tree as specified by the [ESTree spec][estree].
  5296. //
  5297. // [estree]: https://github.com/estree/estree
  5298. function parse(input, options) {
  5299. return Parser.parse(input, options)
  5300. }
  5301. // This function tries to parse a single expression at a given
  5302. // offset in a string. Useful for parsing mixed-language formats
  5303. // that embed JavaScript expressions.
  5304. function parseExpressionAt(input, pos, options) {
  5305. return Parser.parseExpressionAt(input, pos, options)
  5306. }
  5307. // Acorn is organized as a tokenizer and a recursive-descent parser.
  5308. // The `tokenizer` export provides an interface to the tokenizer.
  5309. function tokenizer(input, options) {
  5310. return Parser.tokenizer(input, options)
  5311. }
  5312. exports.Node = Node;
  5313. exports.Parser = Parser;
  5314. exports.Position = Position;
  5315. exports.SourceLocation = SourceLocation;
  5316. exports.TokContext = TokContext;
  5317. exports.Token = Token;
  5318. exports.TokenType = TokenType;
  5319. exports.defaultOptions = defaultOptions;
  5320. exports.getLineInfo = getLineInfo;
  5321. exports.isIdentifierChar = isIdentifierChar;
  5322. exports.isIdentifierStart = isIdentifierStart;
  5323. exports.isNewLine = isNewLine;
  5324. exports.keywordTypes = keywords;
  5325. exports.lineBreak = lineBreak;
  5326. exports.lineBreakG = lineBreakG;
  5327. exports.nonASCIIwhitespace = nonASCIIwhitespace;
  5328. exports.parse = parse;
  5329. exports.parseExpressionAt = parseExpressionAt;
  5330. exports.tokContexts = types;
  5331. exports.tokTypes = types$1;
  5332. exports.tokenizer = tokenizer;
  5333. exports.version = version;
  5334. }));