acorn.mjs 202 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588
  1. // Reserved word lists for various dialects of the language
  2. var reservedWords = {
  3. 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",
  4. 5: "class enum extends super const export import",
  5. 6: "enum",
  6. strict: "implements interface let package private protected public static yield",
  7. strictBind: "eval arguments"
  8. };
  9. // And the keywords
  10. 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";
  11. var keywords$1 = {
  12. 5: ecma5AndLessKeywords,
  13. "5module": ecma5AndLessKeywords + " export import",
  14. 6: ecma5AndLessKeywords + " const class extends export import super"
  15. };
  16. var keywordRelationalOperator = /^in(stanceof)?$/;
  17. // ## Character categories
  18. // Big ugly regular expressions that match characters in the
  19. // whitespace, identifier, and identifier-start categories. These
  20. // are only applied when a character is found to actually have a
  21. // code point above 128.
  22. // Generated by `bin/generate-identifier-regex.js`.
  23. 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";
  24. 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\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-\u0ecd\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\u203f\u2040\u2054\u20d0-\u20dc\u20e1\u20e5-\u20f0\u2cef-\u2cf1\u2d7f\u2de0-\u2dff\u302a-\u302f\u3099\u309a\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";
  25. var nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]");
  26. var nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]");
  27. nonASCIIidentifierStartChars = nonASCIIidentifierChars = null;
  28. // These are a run-length and offset encoded representation of the
  29. // >0xffff code points that are a valid part of identifiers. The
  30. // offset starts at 0x10000, and each pair of numbers represents an
  31. // offset to the next range, and then a size of the range. They were
  32. // generated by bin/generate-identifier-regex.js
  33. // eslint-disable-next-line comma-spacing
  34. 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,85,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,190,0,80,921,103,110,18,195,2637,96,16,1070,4050,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,46,2,18,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,482,44,11,6,17,0,322,29,19,43,1269,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,4152,8,221,3,5761,15,7472,3104,541,1507,4938];
  35. // eslint-disable-next-line comma-spacing
  36. 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,154,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,161,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,19306,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,262,6,10,9,357,0,62,13,1495,6,110,6,6,9,4759,9,787719,239];
  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. }
  49. // Test whether a given character code starts an identifier.
  50. function isIdentifierStart(code, astral) {
  51. if (code < 65) { return code === 36 }
  52. if (code < 91) { return true }
  53. if (code < 97) { return code === 95 }
  54. if (code < 123) { return true }
  55. if (code <= 0xffff) { return code >= 0xaa && nonASCIIidentifierStart.test(String.fromCharCode(code)) }
  56. if (astral === false) { return false }
  57. return isInAstralSet(code, astralIdentifierStartCodes)
  58. }
  59. // Test whether a given character is part of an identifier.
  60. function isIdentifierChar(code, astral) {
  61. if (code < 48) { return code === 36 }
  62. if (code < 58) { return true }
  63. if (code < 65) { return false }
  64. if (code < 91) { return true }
  65. if (code < 97) { return code === 95 }
  66. if (code < 123) { return true }
  67. if (code <= 0xffff) { return code >= 0xaa && nonASCIIidentifier.test(String.fromCharCode(code)) }
  68. if (astral === false) { return false }
  69. return isInAstralSet(code, astralIdentifierStartCodes) || isInAstralSet(code, astralIdentifierCodes)
  70. }
  71. // ## Token types
  72. // The assignment of fine-grained, information-carrying type objects
  73. // allows the tokenizer to store the information it has about a
  74. // token in a way that is very cheap for the parser to look up.
  75. // All token type variables start with an underscore, to make them
  76. // easy to recognize.
  77. // The `beforeExpr` property is used to disambiguate between regular
  78. // expressions and divisions. It is set on all token types that can
  79. // be followed by an expression (thus, a slash after them would be a
  80. // regular expression).
  81. //
  82. // The `startsExpr` property is used to check if the token ends a
  83. // `yield` expression. It is set on all token types that either can
  84. // directly start an expression (like a quotation mark) or can
  85. // continue an expression (like the body of a string).
  86. //
  87. // `isLoop` marks a keyword as starting a loop, which is important
  88. // to know when parsing a label, in order to allow or disallow
  89. // continue jumps to that label.
  90. var TokenType = function TokenType(label, conf) {
  91. if ( conf === void 0 ) conf = {};
  92. this.label = label;
  93. this.keyword = conf.keyword;
  94. this.beforeExpr = !!conf.beforeExpr;
  95. this.startsExpr = !!conf.startsExpr;
  96. this.isLoop = !!conf.isLoop;
  97. this.isAssign = !!conf.isAssign;
  98. this.prefix = !!conf.prefix;
  99. this.postfix = !!conf.postfix;
  100. this.binop = conf.binop || null;
  101. this.updateContext = null;
  102. };
  103. function binop(name, prec) {
  104. return new TokenType(name, {beforeExpr: true, binop: prec})
  105. }
  106. var beforeExpr = {beforeExpr: true}, startsExpr = {startsExpr: true};
  107. // Map keyword names to token types.
  108. var keywords = {};
  109. // Succinct definitions of keyword token types
  110. function kw(name, options) {
  111. if ( options === void 0 ) options = {};
  112. options.keyword = name;
  113. return keywords[name] = new TokenType(name, options)
  114. }
  115. var types$1 = {
  116. num: new TokenType("num", startsExpr),
  117. regexp: new TokenType("regexp", startsExpr),
  118. string: new TokenType("string", startsExpr),
  119. name: new TokenType("name", startsExpr),
  120. privateId: new TokenType("privateId", startsExpr),
  121. eof: new TokenType("eof"),
  122. // Punctuation token types.
  123. bracketL: new TokenType("[", {beforeExpr: true, startsExpr: true}),
  124. bracketR: new TokenType("]"),
  125. braceL: new TokenType("{", {beforeExpr: true, startsExpr: true}),
  126. braceR: new TokenType("}"),
  127. parenL: new TokenType("(", {beforeExpr: true, startsExpr: true}),
  128. parenR: new TokenType(")"),
  129. comma: new TokenType(",", beforeExpr),
  130. semi: new TokenType(";", beforeExpr),
  131. colon: new TokenType(":", beforeExpr),
  132. dot: new TokenType("."),
  133. question: new TokenType("?", beforeExpr),
  134. questionDot: new TokenType("?."),
  135. arrow: new TokenType("=>", beforeExpr),
  136. template: new TokenType("template"),
  137. invalidTemplate: new TokenType("invalidTemplate"),
  138. ellipsis: new TokenType("...", beforeExpr),
  139. backQuote: new TokenType("`", startsExpr),
  140. dollarBraceL: new TokenType("${", {beforeExpr: true, startsExpr: true}),
  141. // Operators. These carry several kinds of properties to help the
  142. // parser use them properly (the presence of these properties is
  143. // what categorizes them as operators).
  144. //
  145. // `binop`, when present, specifies that this operator is a binary
  146. // operator, and will refer to its precedence.
  147. //
  148. // `prefix` and `postfix` mark the operator as a prefix or postfix
  149. // unary operator.
  150. //
  151. // `isAssign` marks all of `=`, `+=`, `-=` etcetera, which act as
  152. // binary operators with a very low precedence, that should result
  153. // in AssignmentExpression nodes.
  154. eq: new TokenType("=", {beforeExpr: true, isAssign: true}),
  155. assign: new TokenType("_=", {beforeExpr: true, isAssign: true}),
  156. incDec: new TokenType("++/--", {prefix: true, postfix: true, startsExpr: true}),
  157. prefix: new TokenType("!/~", {beforeExpr: true, prefix: true, startsExpr: true}),
  158. logicalOR: binop("||", 1),
  159. logicalAND: binop("&&", 2),
  160. bitwiseOR: binop("|", 3),
  161. bitwiseXOR: binop("^", 4),
  162. bitwiseAND: binop("&", 5),
  163. equality: binop("==/!=/===/!==", 6),
  164. relational: binop("</>/<=/>=", 7),
  165. bitShift: binop("<</>>/>>>", 8),
  166. plusMin: new TokenType("+/-", {beforeExpr: true, binop: 9, prefix: true, startsExpr: true}),
  167. modulo: binop("%", 10),
  168. star: binop("*", 10),
  169. slash: binop("/", 10),
  170. starstar: new TokenType("**", {beforeExpr: true}),
  171. coalesce: binop("??", 1),
  172. // Keyword token types.
  173. _break: kw("break"),
  174. _case: kw("case", beforeExpr),
  175. _catch: kw("catch"),
  176. _continue: kw("continue"),
  177. _debugger: kw("debugger"),
  178. _default: kw("default", beforeExpr),
  179. _do: kw("do", {isLoop: true, beforeExpr: true}),
  180. _else: kw("else", beforeExpr),
  181. _finally: kw("finally"),
  182. _for: kw("for", {isLoop: true}),
  183. _function: kw("function", startsExpr),
  184. _if: kw("if"),
  185. _return: kw("return", beforeExpr),
  186. _switch: kw("switch"),
  187. _throw: kw("throw", beforeExpr),
  188. _try: kw("try"),
  189. _var: kw("var"),
  190. _const: kw("const"),
  191. _while: kw("while", {isLoop: true}),
  192. _with: kw("with"),
  193. _new: kw("new", {beforeExpr: true, startsExpr: true}),
  194. _this: kw("this", startsExpr),
  195. _super: kw("super", startsExpr),
  196. _class: kw("class", startsExpr),
  197. _extends: kw("extends", beforeExpr),
  198. _export: kw("export"),
  199. _import: kw("import", startsExpr),
  200. _null: kw("null", startsExpr),
  201. _true: kw("true", startsExpr),
  202. _false: kw("false", startsExpr),
  203. _in: kw("in", {beforeExpr: true, binop: 7}),
  204. _instanceof: kw("instanceof", {beforeExpr: true, binop: 7}),
  205. _typeof: kw("typeof", {beforeExpr: true, prefix: true, startsExpr: true}),
  206. _void: kw("void", {beforeExpr: true, prefix: true, startsExpr: true}),
  207. _delete: kw("delete", {beforeExpr: true, prefix: true, startsExpr: true})
  208. };
  209. // Matches a whole line break (where CRLF is considered a single
  210. // line break). Used to count lines.
  211. var lineBreak = /\r\n?|\n|\u2028|\u2029/;
  212. var lineBreakG = new RegExp(lineBreak.source, "g");
  213. function isNewLine(code) {
  214. return code === 10 || code === 13 || code === 0x2028 || code === 0x2029
  215. }
  216. function nextLineBreak(code, from, end) {
  217. if ( end === void 0 ) end = code.length;
  218. for (var i = from; i < end; i++) {
  219. var next = code.charCodeAt(i);
  220. if (isNewLine(next))
  221. { return i < end - 1 && next === 13 && code.charCodeAt(i + 1) === 10 ? i + 2 : i + 1 }
  222. }
  223. return -1
  224. }
  225. var nonASCIIwhitespace = /[\u1680\u2000-\u200a\u202f\u205f\u3000\ufeff]/;
  226. var skipWhiteSpace = /(?:\s|\/\/.*|\/\*[^]*?\*\/)*/g;
  227. var ref = Object.prototype;
  228. var hasOwnProperty = ref.hasOwnProperty;
  229. var toString = ref.toString;
  230. var hasOwn = Object.hasOwn || (function (obj, propName) { return (
  231. hasOwnProperty.call(obj, propName)
  232. ); });
  233. var isArray = Array.isArray || (function (obj) { return (
  234. toString.call(obj) === "[object Array]"
  235. ); });
  236. function wordsRegexp(words) {
  237. return new RegExp("^(?:" + words.replace(/ /g, "|") + ")$")
  238. }
  239. var loneSurrogate = /(?:[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])/;
  240. // These are used when `options.locations` is on, for the
  241. // `startLoc` and `endLoc` properties.
  242. var Position = function Position(line, col) {
  243. this.line = line;
  244. this.column = col;
  245. };
  246. Position.prototype.offset = function offset (n) {
  247. return new Position(this.line, this.column + n)
  248. };
  249. var SourceLocation = function SourceLocation(p, start, end) {
  250. this.start = start;
  251. this.end = end;
  252. if (p.sourceFile !== null) { this.source = p.sourceFile; }
  253. };
  254. // The `getLineInfo` function is mostly useful when the
  255. // `locations` option is off (for performance reasons) and you
  256. // want to find the line/column position for a given character
  257. // offset. `input` should be the code string that the offset refers
  258. // into.
  259. function getLineInfo(input, offset) {
  260. for (var line = 1, cur = 0;;) {
  261. var nextBreak = nextLineBreak(input, cur, offset);
  262. if (nextBreak < 0) { return new Position(line, offset - cur) }
  263. ++line;
  264. cur = nextBreak;
  265. }
  266. }
  267. // A second argument must be given to configure the parser process.
  268. // These options are recognized (only `ecmaVersion` is required):
  269. var defaultOptions = {
  270. // `ecmaVersion` indicates the ECMAScript version to parse. Must be
  271. // either 3, 5, 6 (or 2015), 7 (2016), 8 (2017), 9 (2018), 10
  272. // (2019), 11 (2020), 12 (2021), 13 (2022), or `"latest"` (the
  273. // latest version the library supports). This influences support
  274. // for strict mode, the set of reserved words, and support for
  275. // new syntax features.
  276. ecmaVersion: null,
  277. // `sourceType` indicates the mode the code should be parsed in.
  278. // Can be either `"script"` or `"module"`. This influences global
  279. // strict mode and parsing of `import` and `export` declarations.
  280. sourceType: "script",
  281. // `onInsertedSemicolon` can be a callback that will be called
  282. // when a semicolon is automatically inserted. It will be passed
  283. // the position of the comma as an offset, and if `locations` is
  284. // enabled, it is given the location as a `{line, column}` object
  285. // as second argument.
  286. onInsertedSemicolon: null,
  287. // `onTrailingComma` is similar to `onInsertedSemicolon`, but for
  288. // trailing commas.
  289. onTrailingComma: null,
  290. // By default, reserved words are only enforced if ecmaVersion >= 5.
  291. // Set `allowReserved` to a boolean value to explicitly turn this on
  292. // an off. When this option has the value "never", reserved words
  293. // and keywords can also not be used as property names.
  294. allowReserved: null,
  295. // When enabled, a return at the top level is not considered an
  296. // error.
  297. allowReturnOutsideFunction: false,
  298. // When enabled, import/export statements are not constrained to
  299. // appearing at the top of the program, and an import.meta expression
  300. // in a script isn't considered an error.
  301. allowImportExportEverywhere: false,
  302. // By default, await identifiers are allowed to appear at the top-level scope only if ecmaVersion >= 2022.
  303. // When enabled, await identifiers are allowed to appear at the top-level scope,
  304. // but they are still not allowed in non-async functions.
  305. allowAwaitOutsideFunction: null,
  306. // When enabled, super identifiers are not constrained to
  307. // appearing in methods and do not raise an error when they appear elsewhere.
  308. allowSuperOutsideMethod: null,
  309. // When enabled, hashbang directive in the beginning of file
  310. // is allowed and treated as a line comment.
  311. allowHashBang: false,
  312. // When `locations` is on, `loc` properties holding objects with
  313. // `start` and `end` properties in `{line, column}` form (with
  314. // line being 1-based and column 0-based) will be attached to the
  315. // nodes.
  316. locations: false,
  317. // A function can be passed as `onToken` option, which will
  318. // cause Acorn to call that function with object in the same
  319. // format as tokens returned from `tokenizer().getToken()`. Note
  320. // that you are not allowed to call the parser from the
  321. // callback—that will corrupt its internal state.
  322. onToken: null,
  323. // A function can be passed as `onComment` option, which will
  324. // cause Acorn to call that function with `(block, text, start,
  325. // end)` parameters whenever a comment is skipped. `block` is a
  326. // boolean indicating whether this is a block (`/* */`) comment,
  327. // `text` is the content of the comment, and `start` and `end` are
  328. // character offsets that denote the start and end of the comment.
  329. // When the `locations` option is on, two more parameters are
  330. // passed, the full `{line, column}` locations of the start and
  331. // end of the comments. Note that you are not allowed to call the
  332. // parser from the callback—that will corrupt its internal state.
  333. onComment: null,
  334. // Nodes have their start and end characters offsets recorded in
  335. // `start` and `end` properties (directly on the node, rather than
  336. // the `loc` object, which holds line/column data. To also add a
  337. // [semi-standardized][range] `range` property holding a `[start,
  338. // end]` array with the same numbers, set the `ranges` option to
  339. // `true`.
  340. //
  341. // [range]: https://bugzilla.mozilla.org/show_bug.cgi?id=745678
  342. ranges: false,
  343. // It is possible to parse multiple files into a single AST by
  344. // passing the tree produced by parsing the first file as
  345. // `program` option in subsequent parses. This will add the
  346. // toplevel forms of the parsed file to the `Program` (top) node
  347. // of an existing parse tree.
  348. program: null,
  349. // When `locations` is on, you can pass this to record the source
  350. // file in every node's `loc` object.
  351. sourceFile: null,
  352. // This value, if given, is stored in every node, whether
  353. // `locations` is on or off.
  354. directSourceFile: null,
  355. // When enabled, parenthesized expressions are represented by
  356. // (non-standard) ParenthesizedExpression nodes
  357. preserveParens: false
  358. };
  359. // Interpret and default an options object
  360. var warnedAboutEcmaVersion = false;
  361. function getOptions(opts) {
  362. var options = {};
  363. for (var opt in defaultOptions)
  364. { options[opt] = opts && hasOwn(opts, opt) ? opts[opt] : defaultOptions[opt]; }
  365. if (options.ecmaVersion === "latest") {
  366. options.ecmaVersion = 1e8;
  367. } else if (options.ecmaVersion == null) {
  368. if (!warnedAboutEcmaVersion && typeof console === "object" && console.warn) {
  369. warnedAboutEcmaVersion = true;
  370. console.warn("Since Acorn 8.0.0, options.ecmaVersion is required.\nDefaulting to 2020, but this will stop working in the future.");
  371. }
  372. options.ecmaVersion = 11;
  373. } else if (options.ecmaVersion >= 2015) {
  374. options.ecmaVersion -= 2009;
  375. }
  376. if (options.allowReserved == null)
  377. { options.allowReserved = options.ecmaVersion < 5; }
  378. if (isArray(options.onToken)) {
  379. var tokens = options.onToken;
  380. options.onToken = function (token) { return tokens.push(token); };
  381. }
  382. if (isArray(options.onComment))
  383. { options.onComment = pushComment(options, options.onComment); }
  384. return options
  385. }
  386. function pushComment(options, array) {
  387. return function(block, text, start, end, startLoc, endLoc) {
  388. var comment = {
  389. type: block ? "Block" : "Line",
  390. value: text,
  391. start: start,
  392. end: end
  393. };
  394. if (options.locations)
  395. { comment.loc = new SourceLocation(this, startLoc, endLoc); }
  396. if (options.ranges)
  397. { comment.range = [start, end]; }
  398. array.push(comment);
  399. }
  400. }
  401. // Each scope gets a bitset that may contain these flags
  402. var
  403. SCOPE_TOP = 1,
  404. SCOPE_FUNCTION = 2,
  405. SCOPE_ASYNC = 4,
  406. SCOPE_GENERATOR = 8,
  407. SCOPE_ARROW = 16,
  408. SCOPE_SIMPLE_CATCH = 32,
  409. SCOPE_SUPER = 64,
  410. SCOPE_DIRECT_SUPER = 128,
  411. SCOPE_CLASS_STATIC_BLOCK = 256,
  412. SCOPE_VAR = SCOPE_TOP | SCOPE_FUNCTION | SCOPE_CLASS_STATIC_BLOCK;
  413. function functionFlags(async, generator) {
  414. return SCOPE_FUNCTION | (async ? SCOPE_ASYNC : 0) | (generator ? SCOPE_GENERATOR : 0)
  415. }
  416. // Used in checkLVal* and declareName to determine the type of a binding
  417. var
  418. BIND_NONE = 0, // Not a binding
  419. BIND_VAR = 1, // Var-style binding
  420. BIND_LEXICAL = 2, // Let- or const-style binding
  421. BIND_FUNCTION = 3, // Function declaration
  422. BIND_SIMPLE_CATCH = 4, // Simple (identifier pattern) catch binding
  423. BIND_OUTSIDE = 5; // Special case for function names as bound inside the function
  424. var Parser = function Parser(options, input, startPos) {
  425. this.options = options = getOptions(options);
  426. this.sourceFile = options.sourceFile;
  427. this.keywords = wordsRegexp(keywords$1[options.ecmaVersion >= 6 ? 6 : options.sourceType === "module" ? "5module" : 5]);
  428. var reserved = "";
  429. if (options.allowReserved !== true) {
  430. reserved = reservedWords[options.ecmaVersion >= 6 ? 6 : options.ecmaVersion === 5 ? 5 : 3];
  431. if (options.sourceType === "module") { reserved += " await"; }
  432. }
  433. this.reservedWords = wordsRegexp(reserved);
  434. var reservedStrict = (reserved ? reserved + " " : "") + reservedWords.strict;
  435. this.reservedWordsStrict = wordsRegexp(reservedStrict);
  436. this.reservedWordsStrictBind = wordsRegexp(reservedStrict + " " + reservedWords.strictBind);
  437. this.input = String(input);
  438. // Used to signal to callers of `readWord1` whether the word
  439. // contained any escape sequences. This is needed because words with
  440. // escape sequences must not be interpreted as keywords.
  441. this.containsEsc = false;
  442. // Set up token state
  443. // The current position of the tokenizer in the input.
  444. if (startPos) {
  445. this.pos = startPos;
  446. this.lineStart = this.input.lastIndexOf("\n", startPos - 1) + 1;
  447. this.curLine = this.input.slice(0, this.lineStart).split(lineBreak).length;
  448. } else {
  449. this.pos = this.lineStart = 0;
  450. this.curLine = 1;
  451. }
  452. // Properties of the current token:
  453. // Its type
  454. this.type = types$1.eof;
  455. // For tokens that include more information than their type, the value
  456. this.value = null;
  457. // Its start and end offset
  458. this.start = this.end = this.pos;
  459. // And, if locations are used, the {line, column} object
  460. // corresponding to those offsets
  461. this.startLoc = this.endLoc = this.curPosition();
  462. // Position information for the previous token
  463. this.lastTokEndLoc = this.lastTokStartLoc = null;
  464. this.lastTokStart = this.lastTokEnd = this.pos;
  465. // The context stack is used to superficially track syntactic
  466. // context to predict whether a regular expression is allowed in a
  467. // given position.
  468. this.context = this.initialContext();
  469. this.exprAllowed = true;
  470. // Figure out if it's a module code.
  471. this.inModule = options.sourceType === "module";
  472. this.strict = this.inModule || this.strictDirective(this.pos);
  473. // Used to signify the start of a potential arrow function
  474. this.potentialArrowAt = -1;
  475. this.potentialArrowInForAwait = false;
  476. // Positions to delayed-check that yield/await does not exist in default parameters.
  477. this.yieldPos = this.awaitPos = this.awaitIdentPos = 0;
  478. // Labels in scope.
  479. this.labels = [];
  480. // Thus-far undefined exports.
  481. this.undefinedExports = Object.create(null);
  482. // If enabled, skip leading hashbang line.
  483. if (this.pos === 0 && options.allowHashBang && this.input.slice(0, 2) === "#!")
  484. { this.skipLineComment(2); }
  485. // Scope tracking for duplicate variable names (see scope.js)
  486. this.scopeStack = [];
  487. this.enterScope(SCOPE_TOP);
  488. // For RegExp validation
  489. this.regexpState = null;
  490. // The stack of private names.
  491. // Each element has two properties: 'declared' and 'used'.
  492. // When it exited from the outermost class definition, all used private names must be declared.
  493. this.privateNameStack = [];
  494. };
  495. 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 } };
  496. Parser.prototype.parse = function parse () {
  497. var node = this.options.program || this.startNode();
  498. this.nextToken();
  499. return this.parseTopLevel(node)
  500. };
  501. prototypeAccessors.inFunction.get = function () { return (this.currentVarScope().flags & SCOPE_FUNCTION) > 0 };
  502. prototypeAccessors.inGenerator.get = function () { return (this.currentVarScope().flags & SCOPE_GENERATOR) > 0 && !this.currentVarScope().inClassFieldInit };
  503. prototypeAccessors.inAsync.get = function () { return (this.currentVarScope().flags & SCOPE_ASYNC) > 0 && !this.currentVarScope().inClassFieldInit };
  504. prototypeAccessors.canAwait.get = function () {
  505. for (var i = this.scopeStack.length - 1; i >= 0; i--) {
  506. var scope = this.scopeStack[i];
  507. if (scope.inClassFieldInit || scope.flags & SCOPE_CLASS_STATIC_BLOCK) { return false }
  508. if (scope.flags & SCOPE_FUNCTION) { return (scope.flags & SCOPE_ASYNC) > 0 }
  509. }
  510. return (this.inModule && this.options.ecmaVersion >= 13) || this.options.allowAwaitOutsideFunction
  511. };
  512. prototypeAccessors.allowSuper.get = function () {
  513. var ref = this.currentThisScope();
  514. var flags = ref.flags;
  515. var inClassFieldInit = ref.inClassFieldInit;
  516. return (flags & SCOPE_SUPER) > 0 || inClassFieldInit || this.options.allowSuperOutsideMethod
  517. };
  518. prototypeAccessors.allowDirectSuper.get = function () { return (this.currentThisScope().flags & SCOPE_DIRECT_SUPER) > 0 };
  519. prototypeAccessors.treatFunctionsAsVar.get = function () { return this.treatFunctionsAsVarInScope(this.currentScope()) };
  520. prototypeAccessors.allowNewDotTarget.get = function () {
  521. var ref = this.currentThisScope();
  522. var flags = ref.flags;
  523. var inClassFieldInit = ref.inClassFieldInit;
  524. return (flags & (SCOPE_FUNCTION | SCOPE_CLASS_STATIC_BLOCK)) > 0 || inClassFieldInit
  525. };
  526. prototypeAccessors.inClassStaticBlock.get = function () {
  527. return (this.currentVarScope().flags & SCOPE_CLASS_STATIC_BLOCK) > 0
  528. };
  529. Parser.extend = function extend () {
  530. var plugins = [], len = arguments.length;
  531. while ( len-- ) plugins[ len ] = arguments[ len ];
  532. var cls = this;
  533. for (var i = 0; i < plugins.length; i++) { cls = plugins[i](cls); }
  534. return cls
  535. };
  536. Parser.parse = function parse (input, options) {
  537. return new this(options, input).parse()
  538. };
  539. Parser.parseExpressionAt = function parseExpressionAt (input, pos, options) {
  540. var parser = new this(options, input, pos);
  541. parser.nextToken();
  542. return parser.parseExpression()
  543. };
  544. Parser.tokenizer = function tokenizer (input, options) {
  545. return new this(options, input)
  546. };
  547. Object.defineProperties( Parser.prototype, prototypeAccessors );
  548. var pp$9 = Parser.prototype;
  549. // ## Parser utilities
  550. var literal = /^(?:'((?:\\.|[^'\\])*?)'|"((?:\\.|[^"\\])*?)")/;
  551. pp$9.strictDirective = function(start) {
  552. for (;;) {
  553. // Try to find string literal.
  554. skipWhiteSpace.lastIndex = start;
  555. start += skipWhiteSpace.exec(this.input)[0].length;
  556. var match = literal.exec(this.input.slice(start));
  557. if (!match) { return false }
  558. if ((match[1] || match[2]) === "use strict") {
  559. skipWhiteSpace.lastIndex = start + match[0].length;
  560. var spaceAfter = skipWhiteSpace.exec(this.input), end = spaceAfter.index + spaceAfter[0].length;
  561. var next = this.input.charAt(end);
  562. return next === ";" || next === "}" ||
  563. (lineBreak.test(spaceAfter[0]) &&
  564. !(/[(`.[+\-/*%<>=,?^&]/.test(next) || next === "!" && this.input.charAt(end + 1) === "="))
  565. }
  566. start += match[0].length;
  567. // Skip semicolon, if any.
  568. skipWhiteSpace.lastIndex = start;
  569. start += skipWhiteSpace.exec(this.input)[0].length;
  570. if (this.input[start] === ";")
  571. { start++; }
  572. }
  573. };
  574. // Predicate that tests whether the next token is of the given
  575. // type, and if yes, consumes it as a side effect.
  576. pp$9.eat = function(type) {
  577. if (this.type === type) {
  578. this.next();
  579. return true
  580. } else {
  581. return false
  582. }
  583. };
  584. // Tests whether parsed token is a contextual keyword.
  585. pp$9.isContextual = function(name) {
  586. return this.type === types$1.name && this.value === name && !this.containsEsc
  587. };
  588. // Consumes contextual keyword if possible.
  589. pp$9.eatContextual = function(name) {
  590. if (!this.isContextual(name)) { return false }
  591. this.next();
  592. return true
  593. };
  594. // Asserts that following token is given contextual keyword.
  595. pp$9.expectContextual = function(name) {
  596. if (!this.eatContextual(name)) { this.unexpected(); }
  597. };
  598. // Test whether a semicolon can be inserted at the current position.
  599. pp$9.canInsertSemicolon = function() {
  600. return this.type === types$1.eof ||
  601. this.type === types$1.braceR ||
  602. lineBreak.test(this.input.slice(this.lastTokEnd, this.start))
  603. };
  604. pp$9.insertSemicolon = function() {
  605. if (this.canInsertSemicolon()) {
  606. if (this.options.onInsertedSemicolon)
  607. { this.options.onInsertedSemicolon(this.lastTokEnd, this.lastTokEndLoc); }
  608. return true
  609. }
  610. };
  611. // Consume a semicolon, or, failing that, see if we are allowed to
  612. // pretend that there is a semicolon at this position.
  613. pp$9.semicolon = function() {
  614. if (!this.eat(types$1.semi) && !this.insertSemicolon()) { this.unexpected(); }
  615. };
  616. pp$9.afterTrailingComma = function(tokType, notNext) {
  617. if (this.type === tokType) {
  618. if (this.options.onTrailingComma)
  619. { this.options.onTrailingComma(this.lastTokStart, this.lastTokStartLoc); }
  620. if (!notNext)
  621. { this.next(); }
  622. return true
  623. }
  624. };
  625. // Expect a token of a given type. If found, consume it, otherwise,
  626. // raise an unexpected token error.
  627. pp$9.expect = function(type) {
  628. this.eat(type) || this.unexpected();
  629. };
  630. // Raise an unexpected token error.
  631. pp$9.unexpected = function(pos) {
  632. this.raise(pos != null ? pos : this.start, "Unexpected token");
  633. };
  634. function DestructuringErrors() {
  635. this.shorthandAssign =
  636. this.trailingComma =
  637. this.parenthesizedAssign =
  638. this.parenthesizedBind =
  639. this.doubleProto =
  640. -1;
  641. }
  642. pp$9.checkPatternErrors = function(refDestructuringErrors, isAssign) {
  643. if (!refDestructuringErrors) { return }
  644. if (refDestructuringErrors.trailingComma > -1)
  645. { this.raiseRecoverable(refDestructuringErrors.trailingComma, "Comma is not permitted after the rest element"); }
  646. var parens = isAssign ? refDestructuringErrors.parenthesizedAssign : refDestructuringErrors.parenthesizedBind;
  647. if (parens > -1) { this.raiseRecoverable(parens, "Parenthesized pattern"); }
  648. };
  649. pp$9.checkExpressionErrors = function(refDestructuringErrors, andThrow) {
  650. if (!refDestructuringErrors) { return false }
  651. var shorthandAssign = refDestructuringErrors.shorthandAssign;
  652. var doubleProto = refDestructuringErrors.doubleProto;
  653. if (!andThrow) { return shorthandAssign >= 0 || doubleProto >= 0 }
  654. if (shorthandAssign >= 0)
  655. { this.raise(shorthandAssign, "Shorthand property assignments are valid only in destructuring patterns"); }
  656. if (doubleProto >= 0)
  657. { this.raiseRecoverable(doubleProto, "Redefinition of __proto__ property"); }
  658. };
  659. pp$9.checkYieldAwaitInDefaultParams = function() {
  660. if (this.yieldPos && (!this.awaitPos || this.yieldPos < this.awaitPos))
  661. { this.raise(this.yieldPos, "Yield expression cannot be a default value"); }
  662. if (this.awaitPos)
  663. { this.raise(this.awaitPos, "Await expression cannot be a default value"); }
  664. };
  665. pp$9.isSimpleAssignTarget = function(expr) {
  666. if (expr.type === "ParenthesizedExpression")
  667. { return this.isSimpleAssignTarget(expr.expression) }
  668. return expr.type === "Identifier" || expr.type === "MemberExpression"
  669. };
  670. var pp$8 = Parser.prototype;
  671. // ### Statement parsing
  672. // Parse a program. Initializes the parser, reads any number of
  673. // statements, and wraps them in a Program node. Optionally takes a
  674. // `program` argument. If present, the statements will be appended
  675. // to its body instead of creating a new node.
  676. pp$8.parseTopLevel = function(node) {
  677. var exports = Object.create(null);
  678. if (!node.body) { node.body = []; }
  679. while (this.type !== types$1.eof) {
  680. var stmt = this.parseStatement(null, true, exports);
  681. node.body.push(stmt);
  682. }
  683. if (this.inModule)
  684. { for (var i = 0, list = Object.keys(this.undefinedExports); i < list.length; i += 1)
  685. {
  686. var name = list[i];
  687. this.raiseRecoverable(this.undefinedExports[name].start, ("Export '" + name + "' is not defined"));
  688. } }
  689. this.adaptDirectivePrologue(node.body);
  690. this.next();
  691. node.sourceType = this.options.sourceType;
  692. return this.finishNode(node, "Program")
  693. };
  694. var loopLabel = {kind: "loop"}, switchLabel = {kind: "switch"};
  695. pp$8.isLet = function(context) {
  696. if (this.options.ecmaVersion < 6 || !this.isContextual("let")) { return false }
  697. skipWhiteSpace.lastIndex = this.pos;
  698. var skip = skipWhiteSpace.exec(this.input);
  699. var next = this.pos + skip[0].length, nextCh = this.input.charCodeAt(next);
  700. // For ambiguous cases, determine if a LexicalDeclaration (or only a
  701. // Statement) is allowed here. If context is not empty then only a Statement
  702. // is allowed. However, `let [` is an explicit negative lookahead for
  703. // ExpressionStatement, so special-case it first.
  704. if (nextCh === 91 || nextCh === 92 || nextCh > 0xd7ff && nextCh < 0xdc00) { return true } // '[', '/', astral
  705. if (context) { return false }
  706. if (nextCh === 123) { return true } // '{'
  707. if (isIdentifierStart(nextCh, true)) {
  708. var pos = next + 1;
  709. while (isIdentifierChar(nextCh = this.input.charCodeAt(pos), true)) { ++pos; }
  710. if (nextCh === 92 || nextCh > 0xd7ff && nextCh < 0xdc00) { return true }
  711. var ident = this.input.slice(next, pos);
  712. if (!keywordRelationalOperator.test(ident)) { return true }
  713. }
  714. return false
  715. };
  716. // check 'async [no LineTerminator here] function'
  717. // - 'async /*foo*/ function' is OK.
  718. // - 'async /*\n*/ function' is invalid.
  719. pp$8.isAsyncFunction = function() {
  720. if (this.options.ecmaVersion < 8 || !this.isContextual("async"))
  721. { return false }
  722. skipWhiteSpace.lastIndex = this.pos;
  723. var skip = skipWhiteSpace.exec(this.input);
  724. var next = this.pos + skip[0].length, after;
  725. return !lineBreak.test(this.input.slice(this.pos, next)) &&
  726. this.input.slice(next, next + 8) === "function" &&
  727. (next + 8 === this.input.length ||
  728. !(isIdentifierChar(after = this.input.charCodeAt(next + 8)) || after > 0xd7ff && after < 0xdc00))
  729. };
  730. // Parse a single statement.
  731. //
  732. // If expecting a statement and finding a slash operator, parse a
  733. // regular expression literal. This is to handle cases like
  734. // `if (foo) /blah/.exec(foo)`, where looking at the previous token
  735. // does not help.
  736. pp$8.parseStatement = function(context, topLevel, exports) {
  737. var starttype = this.type, node = this.startNode(), kind;
  738. if (this.isLet(context)) {
  739. starttype = types$1._var;
  740. kind = "let";
  741. }
  742. // Most types of statements are recognized by the keyword they
  743. // start with. Many are trivial to parse, some require a bit of
  744. // complexity.
  745. switch (starttype) {
  746. case types$1._break: case types$1._continue: return this.parseBreakContinueStatement(node, starttype.keyword)
  747. case types$1._debugger: return this.parseDebuggerStatement(node)
  748. case types$1._do: return this.parseDoStatement(node)
  749. case types$1._for: return this.parseForStatement(node)
  750. case types$1._function:
  751. // Function as sole body of either an if statement or a labeled statement
  752. // works, but not when it is part of a labeled statement that is the sole
  753. // body of an if statement.
  754. if ((context && (this.strict || context !== "if" && context !== "label")) && this.options.ecmaVersion >= 6) { this.unexpected(); }
  755. return this.parseFunctionStatement(node, false, !context)
  756. case types$1._class:
  757. if (context) { this.unexpected(); }
  758. return this.parseClass(node, true)
  759. case types$1._if: return this.parseIfStatement(node)
  760. case types$1._return: return this.parseReturnStatement(node)
  761. case types$1._switch: return this.parseSwitchStatement(node)
  762. case types$1._throw: return this.parseThrowStatement(node)
  763. case types$1._try: return this.parseTryStatement(node)
  764. case types$1._const: case types$1._var:
  765. kind = kind || this.value;
  766. if (context && kind !== "var") { this.unexpected(); }
  767. return this.parseVarStatement(node, kind)
  768. case types$1._while: return this.parseWhileStatement(node)
  769. case types$1._with: return this.parseWithStatement(node)
  770. case types$1.braceL: return this.parseBlock(true, node)
  771. case types$1.semi: return this.parseEmptyStatement(node)
  772. case types$1._export:
  773. case types$1._import:
  774. if (this.options.ecmaVersion > 10 && starttype === types$1._import) {
  775. skipWhiteSpace.lastIndex = this.pos;
  776. var skip = skipWhiteSpace.exec(this.input);
  777. var next = this.pos + skip[0].length, nextCh = this.input.charCodeAt(next);
  778. if (nextCh === 40 || nextCh === 46) // '(' or '.'
  779. { return this.parseExpressionStatement(node, this.parseExpression()) }
  780. }
  781. if (!this.options.allowImportExportEverywhere) {
  782. if (!topLevel)
  783. { this.raise(this.start, "'import' and 'export' may only appear at the top level"); }
  784. if (!this.inModule)
  785. { this.raise(this.start, "'import' and 'export' may appear only with 'sourceType: module'"); }
  786. }
  787. return starttype === types$1._import ? this.parseImport(node) : this.parseExport(node, exports)
  788. // If the statement does not start with a statement keyword or a
  789. // brace, it's an ExpressionStatement or LabeledStatement. We
  790. // simply start parsing an expression, and afterwards, if the
  791. // next token is a colon and the expression was a simple
  792. // Identifier node, we switch to interpreting it as a label.
  793. default:
  794. if (this.isAsyncFunction()) {
  795. if (context) { this.unexpected(); }
  796. this.next();
  797. return this.parseFunctionStatement(node, true, !context)
  798. }
  799. var maybeName = this.value, expr = this.parseExpression();
  800. if (starttype === types$1.name && expr.type === "Identifier" && this.eat(types$1.colon))
  801. { return this.parseLabeledStatement(node, maybeName, expr, context) }
  802. else { return this.parseExpressionStatement(node, expr) }
  803. }
  804. };
  805. pp$8.parseBreakContinueStatement = function(node, keyword) {
  806. var isBreak = keyword === "break";
  807. this.next();
  808. if (this.eat(types$1.semi) || this.insertSemicolon()) { node.label = null; }
  809. else if (this.type !== types$1.name) { this.unexpected(); }
  810. else {
  811. node.label = this.parseIdent();
  812. this.semicolon();
  813. }
  814. // Verify that there is an actual destination to break or
  815. // continue to.
  816. var i = 0;
  817. for (; i < this.labels.length; ++i) {
  818. var lab = this.labels[i];
  819. if (node.label == null || lab.name === node.label.name) {
  820. if (lab.kind != null && (isBreak || lab.kind === "loop")) { break }
  821. if (node.label && isBreak) { break }
  822. }
  823. }
  824. if (i === this.labels.length) { this.raise(node.start, "Unsyntactic " + keyword); }
  825. return this.finishNode(node, isBreak ? "BreakStatement" : "ContinueStatement")
  826. };
  827. pp$8.parseDebuggerStatement = function(node) {
  828. this.next();
  829. this.semicolon();
  830. return this.finishNode(node, "DebuggerStatement")
  831. };
  832. pp$8.parseDoStatement = function(node) {
  833. this.next();
  834. this.labels.push(loopLabel);
  835. node.body = this.parseStatement("do");
  836. this.labels.pop();
  837. this.expect(types$1._while);
  838. node.test = this.parseParenExpression();
  839. if (this.options.ecmaVersion >= 6)
  840. { this.eat(types$1.semi); }
  841. else
  842. { this.semicolon(); }
  843. return this.finishNode(node, "DoWhileStatement")
  844. };
  845. // Disambiguating between a `for` and a `for`/`in` or `for`/`of`
  846. // loop is non-trivial. Basically, we have to parse the init `var`
  847. // statement or expression, disallowing the `in` operator (see
  848. // the second parameter to `parseExpression`), and then check
  849. // whether the next token is `in` or `of`. When there is no init
  850. // part (semicolon immediately after the opening parenthesis), it
  851. // is a regular `for` loop.
  852. pp$8.parseForStatement = function(node) {
  853. this.next();
  854. var awaitAt = (this.options.ecmaVersion >= 9 && this.canAwait && this.eatContextual("await")) ? this.lastTokStart : -1;
  855. this.labels.push(loopLabel);
  856. this.enterScope(0);
  857. this.expect(types$1.parenL);
  858. if (this.type === types$1.semi) {
  859. if (awaitAt > -1) { this.unexpected(awaitAt); }
  860. return this.parseFor(node, null)
  861. }
  862. var isLet = this.isLet();
  863. if (this.type === types$1._var || this.type === types$1._const || isLet) {
  864. var init$1 = this.startNode(), kind = isLet ? "let" : this.value;
  865. this.next();
  866. this.parseVar(init$1, true, kind);
  867. this.finishNode(init$1, "VariableDeclaration");
  868. if ((this.type === types$1._in || (this.options.ecmaVersion >= 6 && this.isContextual("of"))) && init$1.declarations.length === 1) {
  869. if (this.options.ecmaVersion >= 9) {
  870. if (this.type === types$1._in) {
  871. if (awaitAt > -1) { this.unexpected(awaitAt); }
  872. } else { node.await = awaitAt > -1; }
  873. }
  874. return this.parseForIn(node, init$1)
  875. }
  876. if (awaitAt > -1) { this.unexpected(awaitAt); }
  877. return this.parseFor(node, init$1)
  878. }
  879. var startsWithLet = this.isContextual("let"), isForOf = false;
  880. var refDestructuringErrors = new DestructuringErrors;
  881. var init = this.parseExpression(awaitAt > -1 ? "await" : true, refDestructuringErrors);
  882. if (this.type === types$1._in || (isForOf = this.options.ecmaVersion >= 6 && this.isContextual("of"))) {
  883. if (this.options.ecmaVersion >= 9) {
  884. if (this.type === types$1._in) {
  885. if (awaitAt > -1) { this.unexpected(awaitAt); }
  886. } else { node.await = awaitAt > -1; }
  887. }
  888. if (startsWithLet && isForOf) { this.raise(init.start, "The left-hand side of a for-of loop may not start with 'let'."); }
  889. this.toAssignable(init, false, refDestructuringErrors);
  890. this.checkLValPattern(init);
  891. return this.parseForIn(node, init)
  892. } else {
  893. this.checkExpressionErrors(refDestructuringErrors, true);
  894. }
  895. if (awaitAt > -1) { this.unexpected(awaitAt); }
  896. return this.parseFor(node, init)
  897. };
  898. pp$8.parseFunctionStatement = function(node, isAsync, declarationPosition) {
  899. this.next();
  900. return this.parseFunction(node, FUNC_STATEMENT | (declarationPosition ? 0 : FUNC_HANGING_STATEMENT), false, isAsync)
  901. };
  902. pp$8.parseIfStatement = function(node) {
  903. this.next();
  904. node.test = this.parseParenExpression();
  905. // allow function declarations in branches, but only in non-strict mode
  906. node.consequent = this.parseStatement("if");
  907. node.alternate = this.eat(types$1._else) ? this.parseStatement("if") : null;
  908. return this.finishNode(node, "IfStatement")
  909. };
  910. pp$8.parseReturnStatement = function(node) {
  911. if (!this.inFunction && !this.options.allowReturnOutsideFunction)
  912. { this.raise(this.start, "'return' outside of function"); }
  913. this.next();
  914. // In `return` (and `break`/`continue`), the keywords with
  915. // optional arguments, we eagerly look for a semicolon or the
  916. // possibility to insert one.
  917. if (this.eat(types$1.semi) || this.insertSemicolon()) { node.argument = null; }
  918. else { node.argument = this.parseExpression(); this.semicolon(); }
  919. return this.finishNode(node, "ReturnStatement")
  920. };
  921. pp$8.parseSwitchStatement = function(node) {
  922. this.next();
  923. node.discriminant = this.parseParenExpression();
  924. node.cases = [];
  925. this.expect(types$1.braceL);
  926. this.labels.push(switchLabel);
  927. this.enterScope(0);
  928. // Statements under must be grouped (by label) in SwitchCase
  929. // nodes. `cur` is used to keep the node that we are currently
  930. // adding statements to.
  931. var cur;
  932. for (var sawDefault = false; this.type !== types$1.braceR;) {
  933. if (this.type === types$1._case || this.type === types$1._default) {
  934. var isCase = this.type === types$1._case;
  935. if (cur) { this.finishNode(cur, "SwitchCase"); }
  936. node.cases.push(cur = this.startNode());
  937. cur.consequent = [];
  938. this.next();
  939. if (isCase) {
  940. cur.test = this.parseExpression();
  941. } else {
  942. if (sawDefault) { this.raiseRecoverable(this.lastTokStart, "Multiple default clauses"); }
  943. sawDefault = true;
  944. cur.test = null;
  945. }
  946. this.expect(types$1.colon);
  947. } else {
  948. if (!cur) { this.unexpected(); }
  949. cur.consequent.push(this.parseStatement(null));
  950. }
  951. }
  952. this.exitScope();
  953. if (cur) { this.finishNode(cur, "SwitchCase"); }
  954. this.next(); // Closing brace
  955. this.labels.pop();
  956. return this.finishNode(node, "SwitchStatement")
  957. };
  958. pp$8.parseThrowStatement = function(node) {
  959. this.next();
  960. if (lineBreak.test(this.input.slice(this.lastTokEnd, this.start)))
  961. { this.raise(this.lastTokEnd, "Illegal newline after throw"); }
  962. node.argument = this.parseExpression();
  963. this.semicolon();
  964. return this.finishNode(node, "ThrowStatement")
  965. };
  966. // Reused empty array added for node fields that are always empty.
  967. var empty$1 = [];
  968. pp$8.parseTryStatement = function(node) {
  969. this.next();
  970. node.block = this.parseBlock();
  971. node.handler = null;
  972. if (this.type === types$1._catch) {
  973. var clause = this.startNode();
  974. this.next();
  975. if (this.eat(types$1.parenL)) {
  976. clause.param = this.parseBindingAtom();
  977. var simple = clause.param.type === "Identifier";
  978. this.enterScope(simple ? SCOPE_SIMPLE_CATCH : 0);
  979. this.checkLValPattern(clause.param, simple ? BIND_SIMPLE_CATCH : BIND_LEXICAL);
  980. this.expect(types$1.parenR);
  981. } else {
  982. if (this.options.ecmaVersion < 10) { this.unexpected(); }
  983. clause.param = null;
  984. this.enterScope(0);
  985. }
  986. clause.body = this.parseBlock(false);
  987. this.exitScope();
  988. node.handler = this.finishNode(clause, "CatchClause");
  989. }
  990. node.finalizer = this.eat(types$1._finally) ? this.parseBlock() : null;
  991. if (!node.handler && !node.finalizer)
  992. { this.raise(node.start, "Missing catch or finally clause"); }
  993. return this.finishNode(node, "TryStatement")
  994. };
  995. pp$8.parseVarStatement = function(node, kind) {
  996. this.next();
  997. this.parseVar(node, false, kind);
  998. this.semicolon();
  999. return this.finishNode(node, "VariableDeclaration")
  1000. };
  1001. pp$8.parseWhileStatement = function(node) {
  1002. this.next();
  1003. node.test = this.parseParenExpression();
  1004. this.labels.push(loopLabel);
  1005. node.body = this.parseStatement("while");
  1006. this.labels.pop();
  1007. return this.finishNode(node, "WhileStatement")
  1008. };
  1009. pp$8.parseWithStatement = function(node) {
  1010. if (this.strict) { this.raise(this.start, "'with' in strict mode"); }
  1011. this.next();
  1012. node.object = this.parseParenExpression();
  1013. node.body = this.parseStatement("with");
  1014. return this.finishNode(node, "WithStatement")
  1015. };
  1016. pp$8.parseEmptyStatement = function(node) {
  1017. this.next();
  1018. return this.finishNode(node, "EmptyStatement")
  1019. };
  1020. pp$8.parseLabeledStatement = function(node, maybeName, expr, context) {
  1021. for (var i$1 = 0, list = this.labels; i$1 < list.length; i$1 += 1)
  1022. {
  1023. var label = list[i$1];
  1024. if (label.name === maybeName)
  1025. { this.raise(expr.start, "Label '" + maybeName + "' is already declared");
  1026. } }
  1027. var kind = this.type.isLoop ? "loop" : this.type === types$1._switch ? "switch" : null;
  1028. for (var i = this.labels.length - 1; i >= 0; i--) {
  1029. var label$1 = this.labels[i];
  1030. if (label$1.statementStart === node.start) {
  1031. // Update information about previous labels on this node
  1032. label$1.statementStart = this.start;
  1033. label$1.kind = kind;
  1034. } else { break }
  1035. }
  1036. this.labels.push({name: maybeName, kind: kind, statementStart: this.start});
  1037. node.body = this.parseStatement(context ? context.indexOf("label") === -1 ? context + "label" : context : "label");
  1038. this.labels.pop();
  1039. node.label = expr;
  1040. return this.finishNode(node, "LabeledStatement")
  1041. };
  1042. pp$8.parseExpressionStatement = function(node, expr) {
  1043. node.expression = expr;
  1044. this.semicolon();
  1045. return this.finishNode(node, "ExpressionStatement")
  1046. };
  1047. // Parse a semicolon-enclosed block of statements, handling `"use
  1048. // strict"` declarations when `allowStrict` is true (used for
  1049. // function bodies).
  1050. pp$8.parseBlock = function(createNewLexicalScope, node, exitStrict) {
  1051. if ( createNewLexicalScope === void 0 ) createNewLexicalScope = true;
  1052. if ( node === void 0 ) node = this.startNode();
  1053. node.body = [];
  1054. this.expect(types$1.braceL);
  1055. if (createNewLexicalScope) { this.enterScope(0); }
  1056. while (this.type !== types$1.braceR) {
  1057. var stmt = this.parseStatement(null);
  1058. node.body.push(stmt);
  1059. }
  1060. if (exitStrict) { this.strict = false; }
  1061. this.next();
  1062. if (createNewLexicalScope) { this.exitScope(); }
  1063. return this.finishNode(node, "BlockStatement")
  1064. };
  1065. // Parse a regular `for` loop. The disambiguation code in
  1066. // `parseStatement` will already have parsed the init statement or
  1067. // expression.
  1068. pp$8.parseFor = function(node, init) {
  1069. node.init = init;
  1070. this.expect(types$1.semi);
  1071. node.test = this.type === types$1.semi ? null : this.parseExpression();
  1072. this.expect(types$1.semi);
  1073. node.update = this.type === types$1.parenR ? null : this.parseExpression();
  1074. this.expect(types$1.parenR);
  1075. node.body = this.parseStatement("for");
  1076. this.exitScope();
  1077. this.labels.pop();
  1078. return this.finishNode(node, "ForStatement")
  1079. };
  1080. // Parse a `for`/`in` and `for`/`of` loop, which are almost
  1081. // same from parser's perspective.
  1082. pp$8.parseForIn = function(node, init) {
  1083. var isForIn = this.type === types$1._in;
  1084. this.next();
  1085. if (
  1086. init.type === "VariableDeclaration" &&
  1087. init.declarations[0].init != null &&
  1088. (
  1089. !isForIn ||
  1090. this.options.ecmaVersion < 8 ||
  1091. this.strict ||
  1092. init.kind !== "var" ||
  1093. init.declarations[0].id.type !== "Identifier"
  1094. )
  1095. ) {
  1096. this.raise(
  1097. init.start,
  1098. ((isForIn ? "for-in" : "for-of") + " loop variable declaration may not have an initializer")
  1099. );
  1100. }
  1101. node.left = init;
  1102. node.right = isForIn ? this.parseExpression() : this.parseMaybeAssign();
  1103. this.expect(types$1.parenR);
  1104. node.body = this.parseStatement("for");
  1105. this.exitScope();
  1106. this.labels.pop();
  1107. return this.finishNode(node, isForIn ? "ForInStatement" : "ForOfStatement")
  1108. };
  1109. // Parse a list of variable declarations.
  1110. pp$8.parseVar = function(node, isFor, kind) {
  1111. node.declarations = [];
  1112. node.kind = kind;
  1113. for (;;) {
  1114. var decl = this.startNode();
  1115. this.parseVarId(decl, kind);
  1116. if (this.eat(types$1.eq)) {
  1117. decl.init = this.parseMaybeAssign(isFor);
  1118. } else if (kind === "const" && !(this.type === types$1._in || (this.options.ecmaVersion >= 6 && this.isContextual("of")))) {
  1119. this.unexpected();
  1120. } else if (decl.id.type !== "Identifier" && !(isFor && (this.type === types$1._in || this.isContextual("of")))) {
  1121. this.raise(this.lastTokEnd, "Complex binding patterns require an initialization value");
  1122. } else {
  1123. decl.init = null;
  1124. }
  1125. node.declarations.push(this.finishNode(decl, "VariableDeclarator"));
  1126. if (!this.eat(types$1.comma)) { break }
  1127. }
  1128. return node
  1129. };
  1130. pp$8.parseVarId = function(decl, kind) {
  1131. decl.id = this.parseBindingAtom();
  1132. this.checkLValPattern(decl.id, kind === "var" ? BIND_VAR : BIND_LEXICAL, false);
  1133. };
  1134. var FUNC_STATEMENT = 1, FUNC_HANGING_STATEMENT = 2, FUNC_NULLABLE_ID = 4;
  1135. // Parse a function declaration or literal (depending on the
  1136. // `statement & FUNC_STATEMENT`).
  1137. // Remove `allowExpressionBody` for 7.0.0, as it is only called with false
  1138. pp$8.parseFunction = function(node, statement, allowExpressionBody, isAsync, forInit) {
  1139. this.initFunction(node);
  1140. if (this.options.ecmaVersion >= 9 || this.options.ecmaVersion >= 6 && !isAsync) {
  1141. if (this.type === types$1.star && (statement & FUNC_HANGING_STATEMENT))
  1142. { this.unexpected(); }
  1143. node.generator = this.eat(types$1.star);
  1144. }
  1145. if (this.options.ecmaVersion >= 8)
  1146. { node.async = !!isAsync; }
  1147. if (statement & FUNC_STATEMENT) {
  1148. node.id = (statement & FUNC_NULLABLE_ID) && this.type !== types$1.name ? null : this.parseIdent();
  1149. if (node.id && !(statement & FUNC_HANGING_STATEMENT))
  1150. // If it is a regular function declaration in sloppy mode, then it is
  1151. // subject to Annex B semantics (BIND_FUNCTION). Otherwise, the binding
  1152. // mode depends on properties of the current scope (see
  1153. // treatFunctionsAsVar).
  1154. { this.checkLValSimple(node.id, (this.strict || node.generator || node.async) ? this.treatFunctionsAsVar ? BIND_VAR : BIND_LEXICAL : BIND_FUNCTION); }
  1155. }
  1156. var oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldAwaitIdentPos = this.awaitIdentPos;
  1157. this.yieldPos = 0;
  1158. this.awaitPos = 0;
  1159. this.awaitIdentPos = 0;
  1160. this.enterScope(functionFlags(node.async, node.generator));
  1161. if (!(statement & FUNC_STATEMENT))
  1162. { node.id = this.type === types$1.name ? this.parseIdent() : null; }
  1163. this.parseFunctionParams(node);
  1164. this.parseFunctionBody(node, allowExpressionBody, false, forInit);
  1165. this.yieldPos = oldYieldPos;
  1166. this.awaitPos = oldAwaitPos;
  1167. this.awaitIdentPos = oldAwaitIdentPos;
  1168. return this.finishNode(node, (statement & FUNC_STATEMENT) ? "FunctionDeclaration" : "FunctionExpression")
  1169. };
  1170. pp$8.parseFunctionParams = function(node) {
  1171. this.expect(types$1.parenL);
  1172. node.params = this.parseBindingList(types$1.parenR, false, this.options.ecmaVersion >= 8);
  1173. this.checkYieldAwaitInDefaultParams();
  1174. };
  1175. // Parse a class declaration or literal (depending on the
  1176. // `isStatement` parameter).
  1177. pp$8.parseClass = function(node, isStatement) {
  1178. this.next();
  1179. // ecma-262 14.6 Class Definitions
  1180. // A class definition is always strict mode code.
  1181. var oldStrict = this.strict;
  1182. this.strict = true;
  1183. this.parseClassId(node, isStatement);
  1184. this.parseClassSuper(node);
  1185. var privateNameMap = this.enterClassBody();
  1186. var classBody = this.startNode();
  1187. var hadConstructor = false;
  1188. classBody.body = [];
  1189. this.expect(types$1.braceL);
  1190. while (this.type !== types$1.braceR) {
  1191. var element = this.parseClassElement(node.superClass !== null);
  1192. if (element) {
  1193. classBody.body.push(element);
  1194. if (element.type === "MethodDefinition" && element.kind === "constructor") {
  1195. if (hadConstructor) { this.raise(element.start, "Duplicate constructor in the same class"); }
  1196. hadConstructor = true;
  1197. } else if (element.key && element.key.type === "PrivateIdentifier" && isPrivateNameConflicted(privateNameMap, element)) {
  1198. this.raiseRecoverable(element.key.start, ("Identifier '#" + (element.key.name) + "' has already been declared"));
  1199. }
  1200. }
  1201. }
  1202. this.strict = oldStrict;
  1203. this.next();
  1204. node.body = this.finishNode(classBody, "ClassBody");
  1205. this.exitClassBody();
  1206. return this.finishNode(node, isStatement ? "ClassDeclaration" : "ClassExpression")
  1207. };
  1208. pp$8.parseClassElement = function(constructorAllowsSuper) {
  1209. if (this.eat(types$1.semi)) { return null }
  1210. var ecmaVersion = this.options.ecmaVersion;
  1211. var node = this.startNode();
  1212. var keyName = "";
  1213. var isGenerator = false;
  1214. var isAsync = false;
  1215. var kind = "method";
  1216. var isStatic = false;
  1217. if (this.eatContextual("static")) {
  1218. // Parse static init block
  1219. if (ecmaVersion >= 13 && this.eat(types$1.braceL)) {
  1220. this.parseClassStaticBlock(node);
  1221. return node
  1222. }
  1223. if (this.isClassElementNameStart() || this.type === types$1.star) {
  1224. isStatic = true;
  1225. } else {
  1226. keyName = "static";
  1227. }
  1228. }
  1229. node.static = isStatic;
  1230. if (!keyName && ecmaVersion >= 8 && this.eatContextual("async")) {
  1231. if ((this.isClassElementNameStart() || this.type === types$1.star) && !this.canInsertSemicolon()) {
  1232. isAsync = true;
  1233. } else {
  1234. keyName = "async";
  1235. }
  1236. }
  1237. if (!keyName && (ecmaVersion >= 9 || !isAsync) && this.eat(types$1.star)) {
  1238. isGenerator = true;
  1239. }
  1240. if (!keyName && !isAsync && !isGenerator) {
  1241. var lastValue = this.value;
  1242. if (this.eatContextual("get") || this.eatContextual("set")) {
  1243. if (this.isClassElementNameStart()) {
  1244. kind = lastValue;
  1245. } else {
  1246. keyName = lastValue;
  1247. }
  1248. }
  1249. }
  1250. // Parse element name
  1251. if (keyName) {
  1252. // 'async', 'get', 'set', or 'static' were not a keyword contextually.
  1253. // The last token is any of those. Make it the element name.
  1254. node.computed = false;
  1255. node.key = this.startNodeAt(this.lastTokStart, this.lastTokStartLoc);
  1256. node.key.name = keyName;
  1257. this.finishNode(node.key, "Identifier");
  1258. } else {
  1259. this.parseClassElementName(node);
  1260. }
  1261. // Parse element value
  1262. if (ecmaVersion < 13 || this.type === types$1.parenL || kind !== "method" || isGenerator || isAsync) {
  1263. var isConstructor = !node.static && checkKeyName(node, "constructor");
  1264. var allowsDirectSuper = isConstructor && constructorAllowsSuper;
  1265. // Couldn't move this check into the 'parseClassMethod' method for backward compatibility.
  1266. if (isConstructor && kind !== "method") { this.raise(node.key.start, "Constructor can't have get/set modifier"); }
  1267. node.kind = isConstructor ? "constructor" : kind;
  1268. this.parseClassMethod(node, isGenerator, isAsync, allowsDirectSuper);
  1269. } else {
  1270. this.parseClassField(node);
  1271. }
  1272. return node
  1273. };
  1274. pp$8.isClassElementNameStart = function() {
  1275. return (
  1276. this.type === types$1.name ||
  1277. this.type === types$1.privateId ||
  1278. this.type === types$1.num ||
  1279. this.type === types$1.string ||
  1280. this.type === types$1.bracketL ||
  1281. this.type.keyword
  1282. )
  1283. };
  1284. pp$8.parseClassElementName = function(element) {
  1285. if (this.type === types$1.privateId) {
  1286. if (this.value === "constructor") {
  1287. this.raise(this.start, "Classes can't have an element named '#constructor'");
  1288. }
  1289. element.computed = false;
  1290. element.key = this.parsePrivateIdent();
  1291. } else {
  1292. this.parsePropertyName(element);
  1293. }
  1294. };
  1295. pp$8.parseClassMethod = function(method, isGenerator, isAsync, allowsDirectSuper) {
  1296. // Check key and flags
  1297. var key = method.key;
  1298. if (method.kind === "constructor") {
  1299. if (isGenerator) { this.raise(key.start, "Constructor can't be a generator"); }
  1300. if (isAsync) { this.raise(key.start, "Constructor can't be an async method"); }
  1301. } else if (method.static && checkKeyName(method, "prototype")) {
  1302. this.raise(key.start, "Classes may not have a static property named prototype");
  1303. }
  1304. // Parse value
  1305. var value = method.value = this.parseMethod(isGenerator, isAsync, allowsDirectSuper);
  1306. // Check value
  1307. if (method.kind === "get" && value.params.length !== 0)
  1308. { this.raiseRecoverable(value.start, "getter should have no params"); }
  1309. if (method.kind === "set" && value.params.length !== 1)
  1310. { this.raiseRecoverable(value.start, "setter should have exactly one param"); }
  1311. if (method.kind === "set" && value.params[0].type === "RestElement")
  1312. { this.raiseRecoverable(value.params[0].start, "Setter cannot use rest params"); }
  1313. return this.finishNode(method, "MethodDefinition")
  1314. };
  1315. pp$8.parseClassField = function(field) {
  1316. if (checkKeyName(field, "constructor")) {
  1317. this.raise(field.key.start, "Classes can't have a field named 'constructor'");
  1318. } else if (field.static && checkKeyName(field, "prototype")) {
  1319. this.raise(field.key.start, "Classes can't have a static field named 'prototype'");
  1320. }
  1321. if (this.eat(types$1.eq)) {
  1322. // To raise SyntaxError if 'arguments' exists in the initializer.
  1323. var scope = this.currentThisScope();
  1324. var inClassFieldInit = scope.inClassFieldInit;
  1325. scope.inClassFieldInit = true;
  1326. field.value = this.parseMaybeAssign();
  1327. scope.inClassFieldInit = inClassFieldInit;
  1328. } else {
  1329. field.value = null;
  1330. }
  1331. this.semicolon();
  1332. return this.finishNode(field, "PropertyDefinition")
  1333. };
  1334. pp$8.parseClassStaticBlock = function(node) {
  1335. node.body = [];
  1336. var oldLabels = this.labels;
  1337. this.labels = [];
  1338. this.enterScope(SCOPE_CLASS_STATIC_BLOCK | SCOPE_SUPER);
  1339. while (this.type !== types$1.braceR) {
  1340. var stmt = this.parseStatement(null);
  1341. node.body.push(stmt);
  1342. }
  1343. this.next();
  1344. this.exitScope();
  1345. this.labels = oldLabels;
  1346. return this.finishNode(node, "StaticBlock")
  1347. };
  1348. pp$8.parseClassId = function(node, isStatement) {
  1349. if (this.type === types$1.name) {
  1350. node.id = this.parseIdent();
  1351. if (isStatement)
  1352. { this.checkLValSimple(node.id, BIND_LEXICAL, false); }
  1353. } else {
  1354. if (isStatement === true)
  1355. { this.unexpected(); }
  1356. node.id = null;
  1357. }
  1358. };
  1359. pp$8.parseClassSuper = function(node) {
  1360. node.superClass = this.eat(types$1._extends) ? this.parseExprSubscripts(false) : null;
  1361. };
  1362. pp$8.enterClassBody = function() {
  1363. var element = {declared: Object.create(null), used: []};
  1364. this.privateNameStack.push(element);
  1365. return element.declared
  1366. };
  1367. pp$8.exitClassBody = function() {
  1368. var ref = this.privateNameStack.pop();
  1369. var declared = ref.declared;
  1370. var used = ref.used;
  1371. var len = this.privateNameStack.length;
  1372. var parent = len === 0 ? null : this.privateNameStack[len - 1];
  1373. for (var i = 0; i < used.length; ++i) {
  1374. var id = used[i];
  1375. if (!hasOwn(declared, id.name)) {
  1376. if (parent) {
  1377. parent.used.push(id);
  1378. } else {
  1379. this.raiseRecoverable(id.start, ("Private field '#" + (id.name) + "' must be declared in an enclosing class"));
  1380. }
  1381. }
  1382. }
  1383. };
  1384. function isPrivateNameConflicted(privateNameMap, element) {
  1385. var name = element.key.name;
  1386. var curr = privateNameMap[name];
  1387. var next = "true";
  1388. if (element.type === "MethodDefinition" && (element.kind === "get" || element.kind === "set")) {
  1389. next = (element.static ? "s" : "i") + element.kind;
  1390. }
  1391. // `class { get #a(){}; static set #a(_){} }` is also conflict.
  1392. if (
  1393. curr === "iget" && next === "iset" ||
  1394. curr === "iset" && next === "iget" ||
  1395. curr === "sget" && next === "sset" ||
  1396. curr === "sset" && next === "sget"
  1397. ) {
  1398. privateNameMap[name] = "true";
  1399. return false
  1400. } else if (!curr) {
  1401. privateNameMap[name] = next;
  1402. return false
  1403. } else {
  1404. return true
  1405. }
  1406. }
  1407. function checkKeyName(node, name) {
  1408. var computed = node.computed;
  1409. var key = node.key;
  1410. return !computed && (
  1411. key.type === "Identifier" && key.name === name ||
  1412. key.type === "Literal" && key.value === name
  1413. )
  1414. }
  1415. // Parses module export declaration.
  1416. pp$8.parseExport = function(node, exports) {
  1417. this.next();
  1418. // export * from '...'
  1419. if (this.eat(types$1.star)) {
  1420. if (this.options.ecmaVersion >= 11) {
  1421. if (this.eatContextual("as")) {
  1422. node.exported = this.parseModuleExportName();
  1423. this.checkExport(exports, node.exported.name, this.lastTokStart);
  1424. } else {
  1425. node.exported = null;
  1426. }
  1427. }
  1428. this.expectContextual("from");
  1429. if (this.type !== types$1.string) { this.unexpected(); }
  1430. node.source = this.parseExprAtom();
  1431. this.semicolon();
  1432. return this.finishNode(node, "ExportAllDeclaration")
  1433. }
  1434. if (this.eat(types$1._default)) { // export default ...
  1435. this.checkExport(exports, "default", this.lastTokStart);
  1436. var isAsync;
  1437. if (this.type === types$1._function || (isAsync = this.isAsyncFunction())) {
  1438. var fNode = this.startNode();
  1439. this.next();
  1440. if (isAsync) { this.next(); }
  1441. node.declaration = this.parseFunction(fNode, FUNC_STATEMENT | FUNC_NULLABLE_ID, false, isAsync);
  1442. } else if (this.type === types$1._class) {
  1443. var cNode = this.startNode();
  1444. node.declaration = this.parseClass(cNode, "nullableID");
  1445. } else {
  1446. node.declaration = this.parseMaybeAssign();
  1447. this.semicolon();
  1448. }
  1449. return this.finishNode(node, "ExportDefaultDeclaration")
  1450. }
  1451. // export var|const|let|function|class ...
  1452. if (this.shouldParseExportStatement()) {
  1453. node.declaration = this.parseStatement(null);
  1454. if (node.declaration.type === "VariableDeclaration")
  1455. { this.checkVariableExport(exports, node.declaration.declarations); }
  1456. else
  1457. { this.checkExport(exports, node.declaration.id.name, node.declaration.id.start); }
  1458. node.specifiers = [];
  1459. node.source = null;
  1460. } else { // export { x, y as z } [from '...']
  1461. node.declaration = null;
  1462. node.specifiers = this.parseExportSpecifiers(exports);
  1463. if (this.eatContextual("from")) {
  1464. if (this.type !== types$1.string) { this.unexpected(); }
  1465. node.source = this.parseExprAtom();
  1466. } else {
  1467. for (var i = 0, list = node.specifiers; i < list.length; i += 1) {
  1468. // check for keywords used as local names
  1469. var spec = list[i];
  1470. this.checkUnreserved(spec.local);
  1471. // check if export is defined
  1472. this.checkLocalExport(spec.local);
  1473. if (spec.local.type === "Literal") {
  1474. this.raise(spec.local.start, "A string literal cannot be used as an exported binding without `from`.");
  1475. }
  1476. }
  1477. node.source = null;
  1478. }
  1479. this.semicolon();
  1480. }
  1481. return this.finishNode(node, "ExportNamedDeclaration")
  1482. };
  1483. pp$8.checkExport = function(exports, name, pos) {
  1484. if (!exports) { return }
  1485. if (hasOwn(exports, name))
  1486. { this.raiseRecoverable(pos, "Duplicate export '" + name + "'"); }
  1487. exports[name] = true;
  1488. };
  1489. pp$8.checkPatternExport = function(exports, pat) {
  1490. var type = pat.type;
  1491. if (type === "Identifier")
  1492. { this.checkExport(exports, pat.name, pat.start); }
  1493. else if (type === "ObjectPattern")
  1494. { for (var i = 0, list = pat.properties; i < list.length; i += 1)
  1495. {
  1496. var prop = list[i];
  1497. this.checkPatternExport(exports, prop);
  1498. } }
  1499. else if (type === "ArrayPattern")
  1500. { for (var i$1 = 0, list$1 = pat.elements; i$1 < list$1.length; i$1 += 1) {
  1501. var elt = list$1[i$1];
  1502. if (elt) { this.checkPatternExport(exports, elt); }
  1503. } }
  1504. else if (type === "Property")
  1505. { this.checkPatternExport(exports, pat.value); }
  1506. else if (type === "AssignmentPattern")
  1507. { this.checkPatternExport(exports, pat.left); }
  1508. else if (type === "RestElement")
  1509. { this.checkPatternExport(exports, pat.argument); }
  1510. else if (type === "ParenthesizedExpression")
  1511. { this.checkPatternExport(exports, pat.expression); }
  1512. };
  1513. pp$8.checkVariableExport = function(exports, decls) {
  1514. if (!exports) { return }
  1515. for (var i = 0, list = decls; i < list.length; i += 1)
  1516. {
  1517. var decl = list[i];
  1518. this.checkPatternExport(exports, decl.id);
  1519. }
  1520. };
  1521. pp$8.shouldParseExportStatement = function() {
  1522. return this.type.keyword === "var" ||
  1523. this.type.keyword === "const" ||
  1524. this.type.keyword === "class" ||
  1525. this.type.keyword === "function" ||
  1526. this.isLet() ||
  1527. this.isAsyncFunction()
  1528. };
  1529. // Parses a comma-separated list of module exports.
  1530. pp$8.parseExportSpecifiers = function(exports) {
  1531. var nodes = [], first = true;
  1532. // export { x, y as z } [from '...']
  1533. this.expect(types$1.braceL);
  1534. while (!this.eat(types$1.braceR)) {
  1535. if (!first) {
  1536. this.expect(types$1.comma);
  1537. if (this.afterTrailingComma(types$1.braceR)) { break }
  1538. } else { first = false; }
  1539. var node = this.startNode();
  1540. node.local = this.parseModuleExportName();
  1541. node.exported = this.eatContextual("as") ? this.parseModuleExportName() : node.local;
  1542. this.checkExport(
  1543. exports,
  1544. node.exported[node.exported.type === "Identifier" ? "name" : "value"],
  1545. node.exported.start
  1546. );
  1547. nodes.push(this.finishNode(node, "ExportSpecifier"));
  1548. }
  1549. return nodes
  1550. };
  1551. // Parses import declaration.
  1552. pp$8.parseImport = function(node) {
  1553. this.next();
  1554. // import '...'
  1555. if (this.type === types$1.string) {
  1556. node.specifiers = empty$1;
  1557. node.source = this.parseExprAtom();
  1558. } else {
  1559. node.specifiers = this.parseImportSpecifiers();
  1560. this.expectContextual("from");
  1561. node.source = this.type === types$1.string ? this.parseExprAtom() : this.unexpected();
  1562. }
  1563. this.semicolon();
  1564. return this.finishNode(node, "ImportDeclaration")
  1565. };
  1566. // Parses a comma-separated list of module imports.
  1567. pp$8.parseImportSpecifiers = function() {
  1568. var nodes = [], first = true;
  1569. if (this.type === types$1.name) {
  1570. // import defaultObj, { x, y as z } from '...'
  1571. var node = this.startNode();
  1572. node.local = this.parseIdent();
  1573. this.checkLValSimple(node.local, BIND_LEXICAL);
  1574. nodes.push(this.finishNode(node, "ImportDefaultSpecifier"));
  1575. if (!this.eat(types$1.comma)) { return nodes }
  1576. }
  1577. if (this.type === types$1.star) {
  1578. var node$1 = this.startNode();
  1579. this.next();
  1580. this.expectContextual("as");
  1581. node$1.local = this.parseIdent();
  1582. this.checkLValSimple(node$1.local, BIND_LEXICAL);
  1583. nodes.push(this.finishNode(node$1, "ImportNamespaceSpecifier"));
  1584. return nodes
  1585. }
  1586. this.expect(types$1.braceL);
  1587. while (!this.eat(types$1.braceR)) {
  1588. if (!first) {
  1589. this.expect(types$1.comma);
  1590. if (this.afterTrailingComma(types$1.braceR)) { break }
  1591. } else { first = false; }
  1592. var node$2 = this.startNode();
  1593. node$2.imported = this.parseModuleExportName();
  1594. if (this.eatContextual("as")) {
  1595. node$2.local = this.parseIdent();
  1596. } else {
  1597. this.checkUnreserved(node$2.imported);
  1598. node$2.local = node$2.imported;
  1599. }
  1600. this.checkLValSimple(node$2.local, BIND_LEXICAL);
  1601. nodes.push(this.finishNode(node$2, "ImportSpecifier"));
  1602. }
  1603. return nodes
  1604. };
  1605. pp$8.parseModuleExportName = function() {
  1606. if (this.options.ecmaVersion >= 13 && this.type === types$1.string) {
  1607. var stringLiteral = this.parseLiteral(this.value);
  1608. if (loneSurrogate.test(stringLiteral.value)) {
  1609. this.raise(stringLiteral.start, "An export name cannot include a lone surrogate.");
  1610. }
  1611. return stringLiteral
  1612. }
  1613. return this.parseIdent(true)
  1614. };
  1615. // Set `ExpressionStatement#directive` property for directive prologues.
  1616. pp$8.adaptDirectivePrologue = function(statements) {
  1617. for (var i = 0; i < statements.length && this.isDirectiveCandidate(statements[i]); ++i) {
  1618. statements[i].directive = statements[i].expression.raw.slice(1, -1);
  1619. }
  1620. };
  1621. pp$8.isDirectiveCandidate = function(statement) {
  1622. return (
  1623. statement.type === "ExpressionStatement" &&
  1624. statement.expression.type === "Literal" &&
  1625. typeof statement.expression.value === "string" &&
  1626. // Reject parenthesized strings.
  1627. (this.input[statement.start] === "\"" || this.input[statement.start] === "'")
  1628. )
  1629. };
  1630. var pp$7 = Parser.prototype;
  1631. // Convert existing expression atom to assignable pattern
  1632. // if possible.
  1633. pp$7.toAssignable = function(node, isBinding, refDestructuringErrors) {
  1634. if (this.options.ecmaVersion >= 6 && node) {
  1635. switch (node.type) {
  1636. case "Identifier":
  1637. if (this.inAsync && node.name === "await")
  1638. { this.raise(node.start, "Cannot use 'await' as identifier inside an async function"); }
  1639. break
  1640. case "ObjectPattern":
  1641. case "ArrayPattern":
  1642. case "AssignmentPattern":
  1643. case "RestElement":
  1644. break
  1645. case "ObjectExpression":
  1646. node.type = "ObjectPattern";
  1647. if (refDestructuringErrors) { this.checkPatternErrors(refDestructuringErrors, true); }
  1648. for (var i = 0, list = node.properties; i < list.length; i += 1) {
  1649. var prop = list[i];
  1650. this.toAssignable(prop, isBinding);
  1651. // Early error:
  1652. // AssignmentRestProperty[Yield, Await] :
  1653. // `...` DestructuringAssignmentTarget[Yield, Await]
  1654. //
  1655. // It is a Syntax Error if |DestructuringAssignmentTarget| is an |ArrayLiteral| or an |ObjectLiteral|.
  1656. if (
  1657. prop.type === "RestElement" &&
  1658. (prop.argument.type === "ArrayPattern" || prop.argument.type === "ObjectPattern")
  1659. ) {
  1660. this.raise(prop.argument.start, "Unexpected token");
  1661. }
  1662. }
  1663. break
  1664. case "Property":
  1665. // AssignmentProperty has type === "Property"
  1666. if (node.kind !== "init") { this.raise(node.key.start, "Object pattern can't contain getter or setter"); }
  1667. this.toAssignable(node.value, isBinding);
  1668. break
  1669. case "ArrayExpression":
  1670. node.type = "ArrayPattern";
  1671. if (refDestructuringErrors) { this.checkPatternErrors(refDestructuringErrors, true); }
  1672. this.toAssignableList(node.elements, isBinding);
  1673. break
  1674. case "SpreadElement":
  1675. node.type = "RestElement";
  1676. this.toAssignable(node.argument, isBinding);
  1677. if (node.argument.type === "AssignmentPattern")
  1678. { this.raise(node.argument.start, "Rest elements cannot have a default value"); }
  1679. break
  1680. case "AssignmentExpression":
  1681. if (node.operator !== "=") { this.raise(node.left.end, "Only '=' operator can be used for specifying default value."); }
  1682. node.type = "AssignmentPattern";
  1683. delete node.operator;
  1684. this.toAssignable(node.left, isBinding);
  1685. break
  1686. case "ParenthesizedExpression":
  1687. this.toAssignable(node.expression, isBinding, refDestructuringErrors);
  1688. break
  1689. case "ChainExpression":
  1690. this.raiseRecoverable(node.start, "Optional chaining cannot appear in left-hand side");
  1691. break
  1692. case "MemberExpression":
  1693. if (!isBinding) { break }
  1694. default:
  1695. this.raise(node.start, "Assigning to rvalue");
  1696. }
  1697. } else if (refDestructuringErrors) { this.checkPatternErrors(refDestructuringErrors, true); }
  1698. return node
  1699. };
  1700. // Convert list of expression atoms to binding list.
  1701. pp$7.toAssignableList = function(exprList, isBinding) {
  1702. var end = exprList.length;
  1703. for (var i = 0; i < end; i++) {
  1704. var elt = exprList[i];
  1705. if (elt) { this.toAssignable(elt, isBinding); }
  1706. }
  1707. if (end) {
  1708. var last = exprList[end - 1];
  1709. if (this.options.ecmaVersion === 6 && isBinding && last && last.type === "RestElement" && last.argument.type !== "Identifier")
  1710. { this.unexpected(last.argument.start); }
  1711. }
  1712. return exprList
  1713. };
  1714. // Parses spread element.
  1715. pp$7.parseSpread = function(refDestructuringErrors) {
  1716. var node = this.startNode();
  1717. this.next();
  1718. node.argument = this.parseMaybeAssign(false, refDestructuringErrors);
  1719. return this.finishNode(node, "SpreadElement")
  1720. };
  1721. pp$7.parseRestBinding = function() {
  1722. var node = this.startNode();
  1723. this.next();
  1724. // RestElement inside of a function parameter must be an identifier
  1725. if (this.options.ecmaVersion === 6 && this.type !== types$1.name)
  1726. { this.unexpected(); }
  1727. node.argument = this.parseBindingAtom();
  1728. return this.finishNode(node, "RestElement")
  1729. };
  1730. // Parses lvalue (assignable) atom.
  1731. pp$7.parseBindingAtom = function() {
  1732. if (this.options.ecmaVersion >= 6) {
  1733. switch (this.type) {
  1734. case types$1.bracketL:
  1735. var node = this.startNode();
  1736. this.next();
  1737. node.elements = this.parseBindingList(types$1.bracketR, true, true);
  1738. return this.finishNode(node, "ArrayPattern")
  1739. case types$1.braceL:
  1740. return this.parseObj(true)
  1741. }
  1742. }
  1743. return this.parseIdent()
  1744. };
  1745. pp$7.parseBindingList = function(close, allowEmpty, allowTrailingComma) {
  1746. var elts = [], first = true;
  1747. while (!this.eat(close)) {
  1748. if (first) { first = false; }
  1749. else { this.expect(types$1.comma); }
  1750. if (allowEmpty && this.type === types$1.comma) {
  1751. elts.push(null);
  1752. } else if (allowTrailingComma && this.afterTrailingComma(close)) {
  1753. break
  1754. } else if (this.type === types$1.ellipsis) {
  1755. var rest = this.parseRestBinding();
  1756. this.parseBindingListItem(rest);
  1757. elts.push(rest);
  1758. if (this.type === types$1.comma) { this.raise(this.start, "Comma is not permitted after the rest element"); }
  1759. this.expect(close);
  1760. break
  1761. } else {
  1762. var elem = this.parseMaybeDefault(this.start, this.startLoc);
  1763. this.parseBindingListItem(elem);
  1764. elts.push(elem);
  1765. }
  1766. }
  1767. return elts
  1768. };
  1769. pp$7.parseBindingListItem = function(param) {
  1770. return param
  1771. };
  1772. // Parses assignment pattern around given atom if possible.
  1773. pp$7.parseMaybeDefault = function(startPos, startLoc, left) {
  1774. left = left || this.parseBindingAtom();
  1775. if (this.options.ecmaVersion < 6 || !this.eat(types$1.eq)) { return left }
  1776. var node = this.startNodeAt(startPos, startLoc);
  1777. node.left = left;
  1778. node.right = this.parseMaybeAssign();
  1779. return this.finishNode(node, "AssignmentPattern")
  1780. };
  1781. // The following three functions all verify that a node is an lvalue —
  1782. // something that can be bound, or assigned to. In order to do so, they perform
  1783. // a variety of checks:
  1784. //
  1785. // - Check that none of the bound/assigned-to identifiers are reserved words.
  1786. // - Record name declarations for bindings in the appropriate scope.
  1787. // - Check duplicate argument names, if checkClashes is set.
  1788. //
  1789. // If a complex binding pattern is encountered (e.g., object and array
  1790. // destructuring), the entire pattern is recursively checked.
  1791. //
  1792. // There are three versions of checkLVal*() appropriate for different
  1793. // circumstances:
  1794. //
  1795. // - checkLValSimple() shall be used if the syntactic construct supports
  1796. // nothing other than identifiers and member expressions. Parenthesized
  1797. // expressions are also correctly handled. This is generally appropriate for
  1798. // constructs for which the spec says
  1799. //
  1800. // > It is a Syntax Error if AssignmentTargetType of [the production] is not
  1801. // > simple.
  1802. //
  1803. // It is also appropriate for checking if an identifier is valid and not
  1804. // defined elsewhere, like import declarations or function/class identifiers.
  1805. //
  1806. // Examples where this is used include:
  1807. // a += …;
  1808. // import a from '…';
  1809. // where a is the node to be checked.
  1810. //
  1811. // - checkLValPattern() shall be used if the syntactic construct supports
  1812. // anything checkLValSimple() supports, as well as object and array
  1813. // destructuring patterns. This is generally appropriate for constructs for
  1814. // which the spec says
  1815. //
  1816. // > It is a Syntax Error if [the production] is neither an ObjectLiteral nor
  1817. // > an ArrayLiteral and AssignmentTargetType of [the production] is not
  1818. // > simple.
  1819. //
  1820. // Examples where this is used include:
  1821. // (a = …);
  1822. // const a = …;
  1823. // try { … } catch (a) { … }
  1824. // where a is the node to be checked.
  1825. //
  1826. // - checkLValInnerPattern() shall be used if the syntactic construct supports
  1827. // anything checkLValPattern() supports, as well as default assignment
  1828. // patterns, rest elements, and other constructs that may appear within an
  1829. // object or array destructuring pattern.
  1830. //
  1831. // As a special case, function parameters also use checkLValInnerPattern(),
  1832. // as they also support defaults and rest constructs.
  1833. //
  1834. // These functions deliberately support both assignment and binding constructs,
  1835. // as the logic for both is exceedingly similar. If the node is the target of
  1836. // an assignment, then bindingType should be set to BIND_NONE. Otherwise, it
  1837. // should be set to the appropriate BIND_* constant, like BIND_VAR or
  1838. // BIND_LEXICAL.
  1839. //
  1840. // If the function is called with a non-BIND_NONE bindingType, then
  1841. // additionally a checkClashes object may be specified to allow checking for
  1842. // duplicate argument names. checkClashes is ignored if the provided construct
  1843. // is an assignment (i.e., bindingType is BIND_NONE).
  1844. pp$7.checkLValSimple = function(expr, bindingType, checkClashes) {
  1845. if ( bindingType === void 0 ) bindingType = BIND_NONE;
  1846. var isBind = bindingType !== BIND_NONE;
  1847. switch (expr.type) {
  1848. case "Identifier":
  1849. if (this.strict && this.reservedWordsStrictBind.test(expr.name))
  1850. { this.raiseRecoverable(expr.start, (isBind ? "Binding " : "Assigning to ") + expr.name + " in strict mode"); }
  1851. if (isBind) {
  1852. if (bindingType === BIND_LEXICAL && expr.name === "let")
  1853. { this.raiseRecoverable(expr.start, "let is disallowed as a lexically bound name"); }
  1854. if (checkClashes) {
  1855. if (hasOwn(checkClashes, expr.name))
  1856. { this.raiseRecoverable(expr.start, "Argument name clash"); }
  1857. checkClashes[expr.name] = true;
  1858. }
  1859. if (bindingType !== BIND_OUTSIDE) { this.declareName(expr.name, bindingType, expr.start); }
  1860. }
  1861. break
  1862. case "ChainExpression":
  1863. this.raiseRecoverable(expr.start, "Optional chaining cannot appear in left-hand side");
  1864. break
  1865. case "MemberExpression":
  1866. if (isBind) { this.raiseRecoverable(expr.start, "Binding member expression"); }
  1867. break
  1868. case "ParenthesizedExpression":
  1869. if (isBind) { this.raiseRecoverable(expr.start, "Binding parenthesized expression"); }
  1870. return this.checkLValSimple(expr.expression, bindingType, checkClashes)
  1871. default:
  1872. this.raise(expr.start, (isBind ? "Binding" : "Assigning to") + " rvalue");
  1873. }
  1874. };
  1875. pp$7.checkLValPattern = function(expr, bindingType, checkClashes) {
  1876. if ( bindingType === void 0 ) bindingType = BIND_NONE;
  1877. switch (expr.type) {
  1878. case "ObjectPattern":
  1879. for (var i = 0, list = expr.properties; i < list.length; i += 1) {
  1880. var prop = list[i];
  1881. this.checkLValInnerPattern(prop, bindingType, checkClashes);
  1882. }
  1883. break
  1884. case "ArrayPattern":
  1885. for (var i$1 = 0, list$1 = expr.elements; i$1 < list$1.length; i$1 += 1) {
  1886. var elem = list$1[i$1];
  1887. if (elem) { this.checkLValInnerPattern(elem, bindingType, checkClashes); }
  1888. }
  1889. break
  1890. default:
  1891. this.checkLValSimple(expr, bindingType, checkClashes);
  1892. }
  1893. };
  1894. pp$7.checkLValInnerPattern = function(expr, bindingType, checkClashes) {
  1895. if ( bindingType === void 0 ) bindingType = BIND_NONE;
  1896. switch (expr.type) {
  1897. case "Property":
  1898. // AssignmentProperty has type === "Property"
  1899. this.checkLValInnerPattern(expr.value, bindingType, checkClashes);
  1900. break
  1901. case "AssignmentPattern":
  1902. this.checkLValPattern(expr.left, bindingType, checkClashes);
  1903. break
  1904. case "RestElement":
  1905. this.checkLValPattern(expr.argument, bindingType, checkClashes);
  1906. break
  1907. default:
  1908. this.checkLValPattern(expr, bindingType, checkClashes);
  1909. }
  1910. };
  1911. // The algorithm used to determine whether a regexp can appear at a
  1912. var TokContext = function TokContext(token, isExpr, preserveSpace, override, generator) {
  1913. this.token = token;
  1914. this.isExpr = !!isExpr;
  1915. this.preserveSpace = !!preserveSpace;
  1916. this.override = override;
  1917. this.generator = !!generator;
  1918. };
  1919. var types = {
  1920. b_stat: new TokContext("{", false),
  1921. b_expr: new TokContext("{", true),
  1922. b_tmpl: new TokContext("${", false),
  1923. p_stat: new TokContext("(", false),
  1924. p_expr: new TokContext("(", true),
  1925. q_tmpl: new TokContext("`", true, true, function (p) { return p.tryReadTemplateToken(); }),
  1926. f_stat: new TokContext("function", false),
  1927. f_expr: new TokContext("function", true),
  1928. f_expr_gen: new TokContext("function", true, false, null, true),
  1929. f_gen: new TokContext("function", false, false, null, true)
  1930. };
  1931. var pp$6 = Parser.prototype;
  1932. pp$6.initialContext = function() {
  1933. return [types.b_stat]
  1934. };
  1935. pp$6.curContext = function() {
  1936. return this.context[this.context.length - 1]
  1937. };
  1938. pp$6.braceIsBlock = function(prevType) {
  1939. var parent = this.curContext();
  1940. if (parent === types.f_expr || parent === types.f_stat)
  1941. { return true }
  1942. if (prevType === types$1.colon && (parent === types.b_stat || parent === types.b_expr))
  1943. { return !parent.isExpr }
  1944. // The check for `tt.name && exprAllowed` detects whether we are
  1945. // after a `yield` or `of` construct. See the `updateContext` for
  1946. // `tt.name`.
  1947. if (prevType === types$1._return || prevType === types$1.name && this.exprAllowed)
  1948. { return lineBreak.test(this.input.slice(this.lastTokEnd, this.start)) }
  1949. if (prevType === types$1._else || prevType === types$1.semi || prevType === types$1.eof || prevType === types$1.parenR || prevType === types$1.arrow)
  1950. { return true }
  1951. if (prevType === types$1.braceL)
  1952. { return parent === types.b_stat }
  1953. if (prevType === types$1._var || prevType === types$1._const || prevType === types$1.name)
  1954. { return false }
  1955. return !this.exprAllowed
  1956. };
  1957. pp$6.inGeneratorContext = function() {
  1958. for (var i = this.context.length - 1; i >= 1; i--) {
  1959. var context = this.context[i];
  1960. if (context.token === "function")
  1961. { return context.generator }
  1962. }
  1963. return false
  1964. };
  1965. pp$6.updateContext = function(prevType) {
  1966. var update, type = this.type;
  1967. if (type.keyword && prevType === types$1.dot)
  1968. { this.exprAllowed = false; }
  1969. else if (update = type.updateContext)
  1970. { update.call(this, prevType); }
  1971. else
  1972. { this.exprAllowed = type.beforeExpr; }
  1973. };
  1974. // Used to handle egde case when token context could not be inferred correctly in tokenize phase
  1975. pp$6.overrideContext = function(tokenCtx) {
  1976. if (this.curContext() !== tokenCtx) {
  1977. this.context[this.context.length - 1] = tokenCtx;
  1978. }
  1979. };
  1980. // Token-specific context update code
  1981. types$1.parenR.updateContext = types$1.braceR.updateContext = function() {
  1982. if (this.context.length === 1) {
  1983. this.exprAllowed = true;
  1984. return
  1985. }
  1986. var out = this.context.pop();
  1987. if (out === types.b_stat && this.curContext().token === "function") {
  1988. out = this.context.pop();
  1989. }
  1990. this.exprAllowed = !out.isExpr;
  1991. };
  1992. types$1.braceL.updateContext = function(prevType) {
  1993. this.context.push(this.braceIsBlock(prevType) ? types.b_stat : types.b_expr);
  1994. this.exprAllowed = true;
  1995. };
  1996. types$1.dollarBraceL.updateContext = function() {
  1997. this.context.push(types.b_tmpl);
  1998. this.exprAllowed = true;
  1999. };
  2000. types$1.parenL.updateContext = function(prevType) {
  2001. var statementParens = prevType === types$1._if || prevType === types$1._for || prevType === types$1._with || prevType === types$1._while;
  2002. this.context.push(statementParens ? types.p_stat : types.p_expr);
  2003. this.exprAllowed = true;
  2004. };
  2005. types$1.incDec.updateContext = function() {
  2006. // tokExprAllowed stays unchanged
  2007. };
  2008. types$1._function.updateContext = types$1._class.updateContext = function(prevType) {
  2009. if (prevType.beforeExpr && prevType !== types$1._else &&
  2010. !(prevType === types$1.semi && this.curContext() !== types.p_stat) &&
  2011. !(prevType === types$1._return && lineBreak.test(this.input.slice(this.lastTokEnd, this.start))) &&
  2012. !((prevType === types$1.colon || prevType === types$1.braceL) && this.curContext() === types.b_stat))
  2013. { this.context.push(types.f_expr); }
  2014. else
  2015. { this.context.push(types.f_stat); }
  2016. this.exprAllowed = false;
  2017. };
  2018. types$1.backQuote.updateContext = function() {
  2019. if (this.curContext() === types.q_tmpl)
  2020. { this.context.pop(); }
  2021. else
  2022. { this.context.push(types.q_tmpl); }
  2023. this.exprAllowed = false;
  2024. };
  2025. types$1.star.updateContext = function(prevType) {
  2026. if (prevType === types$1._function) {
  2027. var index = this.context.length - 1;
  2028. if (this.context[index] === types.f_expr)
  2029. { this.context[index] = types.f_expr_gen; }
  2030. else
  2031. { this.context[index] = types.f_gen; }
  2032. }
  2033. this.exprAllowed = true;
  2034. };
  2035. types$1.name.updateContext = function(prevType) {
  2036. var allowed = false;
  2037. if (this.options.ecmaVersion >= 6 && prevType !== types$1.dot) {
  2038. if (this.value === "of" && !this.exprAllowed ||
  2039. this.value === "yield" && this.inGeneratorContext())
  2040. { allowed = true; }
  2041. }
  2042. this.exprAllowed = allowed;
  2043. };
  2044. // A recursive descent parser operates by defining functions for all
  2045. var pp$5 = Parser.prototype;
  2046. // Check if property name clashes with already added.
  2047. // Object/class getters and setters are not allowed to clash —
  2048. // either with each other or with an init property — and in
  2049. // strict mode, init properties are also not allowed to be repeated.
  2050. pp$5.checkPropClash = function(prop, propHash, refDestructuringErrors) {
  2051. if (this.options.ecmaVersion >= 9 && prop.type === "SpreadElement")
  2052. { return }
  2053. if (this.options.ecmaVersion >= 6 && (prop.computed || prop.method || prop.shorthand))
  2054. { return }
  2055. var key = prop.key;
  2056. var name;
  2057. switch (key.type) {
  2058. case "Identifier": name = key.name; break
  2059. case "Literal": name = String(key.value); break
  2060. default: return
  2061. }
  2062. var kind = prop.kind;
  2063. if (this.options.ecmaVersion >= 6) {
  2064. if (name === "__proto__" && kind === "init") {
  2065. if (propHash.proto) {
  2066. if (refDestructuringErrors) {
  2067. if (refDestructuringErrors.doubleProto < 0) {
  2068. refDestructuringErrors.doubleProto = key.start;
  2069. }
  2070. } else {
  2071. this.raiseRecoverable(key.start, "Redefinition of __proto__ property");
  2072. }
  2073. }
  2074. propHash.proto = true;
  2075. }
  2076. return
  2077. }
  2078. name = "$" + name;
  2079. var other = propHash[name];
  2080. if (other) {
  2081. var redefinition;
  2082. if (kind === "init") {
  2083. redefinition = this.strict && other.init || other.get || other.set;
  2084. } else {
  2085. redefinition = other.init || other[kind];
  2086. }
  2087. if (redefinition)
  2088. { this.raiseRecoverable(key.start, "Redefinition of property"); }
  2089. } else {
  2090. other = propHash[name] = {
  2091. init: false,
  2092. get: false,
  2093. set: false
  2094. };
  2095. }
  2096. other[kind] = true;
  2097. };
  2098. // ### Expression parsing
  2099. // These nest, from the most general expression type at the top to
  2100. // 'atomic', nondivisible expression types at the bottom. Most of
  2101. // the functions will simply let the function(s) below them parse,
  2102. // and, *if* the syntactic construct they handle is present, wrap
  2103. // the AST node that the inner parser gave them in another node.
  2104. // Parse a full expression. The optional arguments are used to
  2105. // forbid the `in` operator (in for loops initalization expressions)
  2106. // and provide reference for storing '=' operator inside shorthand
  2107. // property assignment in contexts where both object expression
  2108. // and object pattern might appear (so it's possible to raise
  2109. // delayed syntax error at correct position).
  2110. pp$5.parseExpression = function(forInit, refDestructuringErrors) {
  2111. var startPos = this.start, startLoc = this.startLoc;
  2112. var expr = this.parseMaybeAssign(forInit, refDestructuringErrors);
  2113. if (this.type === types$1.comma) {
  2114. var node = this.startNodeAt(startPos, startLoc);
  2115. node.expressions = [expr];
  2116. while (this.eat(types$1.comma)) { node.expressions.push(this.parseMaybeAssign(forInit, refDestructuringErrors)); }
  2117. return this.finishNode(node, "SequenceExpression")
  2118. }
  2119. return expr
  2120. };
  2121. // Parse an assignment expression. This includes applications of
  2122. // operators like `+=`.
  2123. pp$5.parseMaybeAssign = function(forInit, refDestructuringErrors, afterLeftParse) {
  2124. if (this.isContextual("yield")) {
  2125. if (this.inGenerator) { return this.parseYield(forInit) }
  2126. // The tokenizer will assume an expression is allowed after
  2127. // `yield`, but this isn't that kind of yield
  2128. else { this.exprAllowed = false; }
  2129. }
  2130. var ownDestructuringErrors = false, oldParenAssign = -1, oldTrailingComma = -1, oldDoubleProto = -1;
  2131. if (refDestructuringErrors) {
  2132. oldParenAssign = refDestructuringErrors.parenthesizedAssign;
  2133. oldTrailingComma = refDestructuringErrors.trailingComma;
  2134. oldDoubleProto = refDestructuringErrors.doubleProto;
  2135. refDestructuringErrors.parenthesizedAssign = refDestructuringErrors.trailingComma = -1;
  2136. } else {
  2137. refDestructuringErrors = new DestructuringErrors;
  2138. ownDestructuringErrors = true;
  2139. }
  2140. var startPos = this.start, startLoc = this.startLoc;
  2141. if (this.type === types$1.parenL || this.type === types$1.name) {
  2142. this.potentialArrowAt = this.start;
  2143. this.potentialArrowInForAwait = forInit === "await";
  2144. }
  2145. var left = this.parseMaybeConditional(forInit, refDestructuringErrors);
  2146. if (afterLeftParse) { left = afterLeftParse.call(this, left, startPos, startLoc); }
  2147. if (this.type.isAssign) {
  2148. var node = this.startNodeAt(startPos, startLoc);
  2149. node.operator = this.value;
  2150. if (this.type === types$1.eq)
  2151. { left = this.toAssignable(left, false, refDestructuringErrors); }
  2152. if (!ownDestructuringErrors) {
  2153. refDestructuringErrors.parenthesizedAssign = refDestructuringErrors.trailingComma = refDestructuringErrors.doubleProto = -1;
  2154. }
  2155. if (refDestructuringErrors.shorthandAssign >= left.start)
  2156. { refDestructuringErrors.shorthandAssign = -1; } // reset because shorthand default was used correctly
  2157. if (this.type === types$1.eq)
  2158. { this.checkLValPattern(left); }
  2159. else
  2160. { this.checkLValSimple(left); }
  2161. node.left = left;
  2162. this.next();
  2163. node.right = this.parseMaybeAssign(forInit);
  2164. if (oldDoubleProto > -1) { refDestructuringErrors.doubleProto = oldDoubleProto; }
  2165. return this.finishNode(node, "AssignmentExpression")
  2166. } else {
  2167. if (ownDestructuringErrors) { this.checkExpressionErrors(refDestructuringErrors, true); }
  2168. }
  2169. if (oldParenAssign > -1) { refDestructuringErrors.parenthesizedAssign = oldParenAssign; }
  2170. if (oldTrailingComma > -1) { refDestructuringErrors.trailingComma = oldTrailingComma; }
  2171. return left
  2172. };
  2173. // Parse a ternary conditional (`?:`) operator.
  2174. pp$5.parseMaybeConditional = function(forInit, refDestructuringErrors) {
  2175. var startPos = this.start, startLoc = this.startLoc;
  2176. var expr = this.parseExprOps(forInit, refDestructuringErrors);
  2177. if (this.checkExpressionErrors(refDestructuringErrors)) { return expr }
  2178. if (this.eat(types$1.question)) {
  2179. var node = this.startNodeAt(startPos, startLoc);
  2180. node.test = expr;
  2181. node.consequent = this.parseMaybeAssign();
  2182. this.expect(types$1.colon);
  2183. node.alternate = this.parseMaybeAssign(forInit);
  2184. return this.finishNode(node, "ConditionalExpression")
  2185. }
  2186. return expr
  2187. };
  2188. // Start the precedence parser.
  2189. pp$5.parseExprOps = function(forInit, refDestructuringErrors) {
  2190. var startPos = this.start, startLoc = this.startLoc;
  2191. var expr = this.parseMaybeUnary(refDestructuringErrors, false, false, forInit);
  2192. if (this.checkExpressionErrors(refDestructuringErrors)) { return expr }
  2193. return expr.start === startPos && expr.type === "ArrowFunctionExpression" ? expr : this.parseExprOp(expr, startPos, startLoc, -1, forInit)
  2194. };
  2195. // Parse binary operators with the operator precedence parsing
  2196. // algorithm. `left` is the left-hand side of the operator.
  2197. // `minPrec` provides context that allows the function to stop and
  2198. // defer further parser to one of its callers when it encounters an
  2199. // operator that has a lower precedence than the set it is parsing.
  2200. pp$5.parseExprOp = function(left, leftStartPos, leftStartLoc, minPrec, forInit) {
  2201. var prec = this.type.binop;
  2202. if (prec != null && (!forInit || this.type !== types$1._in)) {
  2203. if (prec > minPrec) {
  2204. var logical = this.type === types$1.logicalOR || this.type === types$1.logicalAND;
  2205. var coalesce = this.type === types$1.coalesce;
  2206. if (coalesce) {
  2207. // Handle the precedence of `tt.coalesce` as equal to the range of logical expressions.
  2208. // In other words, `node.right` shouldn't contain logical expressions in order to check the mixed error.
  2209. prec = types$1.logicalAND.binop;
  2210. }
  2211. var op = this.value;
  2212. this.next();
  2213. var startPos = this.start, startLoc = this.startLoc;
  2214. var right = this.parseExprOp(this.parseMaybeUnary(null, false, false, forInit), startPos, startLoc, prec, forInit);
  2215. var node = this.buildBinary(leftStartPos, leftStartLoc, left, right, op, logical || coalesce);
  2216. if ((logical && this.type === types$1.coalesce) || (coalesce && (this.type === types$1.logicalOR || this.type === types$1.logicalAND))) {
  2217. this.raiseRecoverable(this.start, "Logical expressions and coalesce expressions cannot be mixed. Wrap either by parentheses");
  2218. }
  2219. return this.parseExprOp(node, leftStartPos, leftStartLoc, minPrec, forInit)
  2220. }
  2221. }
  2222. return left
  2223. };
  2224. pp$5.buildBinary = function(startPos, startLoc, left, right, op, logical) {
  2225. if (right.type === "PrivateIdentifier") { this.raise(right.start, "Private identifier can only be left side of binary expression"); }
  2226. var node = this.startNodeAt(startPos, startLoc);
  2227. node.left = left;
  2228. node.operator = op;
  2229. node.right = right;
  2230. return this.finishNode(node, logical ? "LogicalExpression" : "BinaryExpression")
  2231. };
  2232. // Parse unary operators, both prefix and postfix.
  2233. pp$5.parseMaybeUnary = function(refDestructuringErrors, sawUnary, incDec, forInit) {
  2234. var startPos = this.start, startLoc = this.startLoc, expr;
  2235. if (this.isContextual("await") && this.canAwait) {
  2236. expr = this.parseAwait(forInit);
  2237. sawUnary = true;
  2238. } else if (this.type.prefix) {
  2239. var node = this.startNode(), update = this.type === types$1.incDec;
  2240. node.operator = this.value;
  2241. node.prefix = true;
  2242. this.next();
  2243. node.argument = this.parseMaybeUnary(null, true, update, forInit);
  2244. this.checkExpressionErrors(refDestructuringErrors, true);
  2245. if (update) { this.checkLValSimple(node.argument); }
  2246. else if (this.strict && node.operator === "delete" &&
  2247. node.argument.type === "Identifier")
  2248. { this.raiseRecoverable(node.start, "Deleting local variable in strict mode"); }
  2249. else if (node.operator === "delete" && isPrivateFieldAccess(node.argument))
  2250. { this.raiseRecoverable(node.start, "Private fields can not be deleted"); }
  2251. else { sawUnary = true; }
  2252. expr = this.finishNode(node, update ? "UpdateExpression" : "UnaryExpression");
  2253. } else if (!sawUnary && this.type === types$1.privateId) {
  2254. if (forInit || this.privateNameStack.length === 0) { this.unexpected(); }
  2255. expr = this.parsePrivateIdent();
  2256. // only could be private fields in 'in', such as #x in obj
  2257. if (this.type !== types$1._in) { this.unexpected(); }
  2258. } else {
  2259. expr = this.parseExprSubscripts(refDestructuringErrors, forInit);
  2260. if (this.checkExpressionErrors(refDestructuringErrors)) { return expr }
  2261. while (this.type.postfix && !this.canInsertSemicolon()) {
  2262. var node$1 = this.startNodeAt(startPos, startLoc);
  2263. node$1.operator = this.value;
  2264. node$1.prefix = false;
  2265. node$1.argument = expr;
  2266. this.checkLValSimple(expr);
  2267. this.next();
  2268. expr = this.finishNode(node$1, "UpdateExpression");
  2269. }
  2270. }
  2271. if (!incDec && this.eat(types$1.starstar)) {
  2272. if (sawUnary)
  2273. { this.unexpected(this.lastTokStart); }
  2274. else
  2275. { return this.buildBinary(startPos, startLoc, expr, this.parseMaybeUnary(null, false, false, forInit), "**", false) }
  2276. } else {
  2277. return expr
  2278. }
  2279. };
  2280. function isPrivateFieldAccess(node) {
  2281. return (
  2282. node.type === "MemberExpression" && node.property.type === "PrivateIdentifier" ||
  2283. node.type === "ChainExpression" && isPrivateFieldAccess(node.expression)
  2284. )
  2285. }
  2286. // Parse call, dot, and `[]`-subscript expressions.
  2287. pp$5.parseExprSubscripts = function(refDestructuringErrors, forInit) {
  2288. var startPos = this.start, startLoc = this.startLoc;
  2289. var expr = this.parseExprAtom(refDestructuringErrors, forInit);
  2290. if (expr.type === "ArrowFunctionExpression" && this.input.slice(this.lastTokStart, this.lastTokEnd) !== ")")
  2291. { return expr }
  2292. var result = this.parseSubscripts(expr, startPos, startLoc, false, forInit);
  2293. if (refDestructuringErrors && result.type === "MemberExpression") {
  2294. if (refDestructuringErrors.parenthesizedAssign >= result.start) { refDestructuringErrors.parenthesizedAssign = -1; }
  2295. if (refDestructuringErrors.parenthesizedBind >= result.start) { refDestructuringErrors.parenthesizedBind = -1; }
  2296. if (refDestructuringErrors.trailingComma >= result.start) { refDestructuringErrors.trailingComma = -1; }
  2297. }
  2298. return result
  2299. };
  2300. pp$5.parseSubscripts = function(base, startPos, startLoc, noCalls, forInit) {
  2301. var maybeAsyncArrow = this.options.ecmaVersion >= 8 && base.type === "Identifier" && base.name === "async" &&
  2302. this.lastTokEnd === base.end && !this.canInsertSemicolon() && base.end - base.start === 5 &&
  2303. this.potentialArrowAt === base.start;
  2304. var optionalChained = false;
  2305. while (true) {
  2306. var element = this.parseSubscript(base, startPos, startLoc, noCalls, maybeAsyncArrow, optionalChained, forInit);
  2307. if (element.optional) { optionalChained = true; }
  2308. if (element === base || element.type === "ArrowFunctionExpression") {
  2309. if (optionalChained) {
  2310. var chainNode = this.startNodeAt(startPos, startLoc);
  2311. chainNode.expression = element;
  2312. element = this.finishNode(chainNode, "ChainExpression");
  2313. }
  2314. return element
  2315. }
  2316. base = element;
  2317. }
  2318. };
  2319. pp$5.parseSubscript = function(base, startPos, startLoc, noCalls, maybeAsyncArrow, optionalChained, forInit) {
  2320. var optionalSupported = this.options.ecmaVersion >= 11;
  2321. var optional = optionalSupported && this.eat(types$1.questionDot);
  2322. if (noCalls && optional) { this.raise(this.lastTokStart, "Optional chaining cannot appear in the callee of new expressions"); }
  2323. var computed = this.eat(types$1.bracketL);
  2324. if (computed || (optional && this.type !== types$1.parenL && this.type !== types$1.backQuote) || this.eat(types$1.dot)) {
  2325. var node = this.startNodeAt(startPos, startLoc);
  2326. node.object = base;
  2327. if (computed) {
  2328. node.property = this.parseExpression();
  2329. this.expect(types$1.bracketR);
  2330. } else if (this.type === types$1.privateId && base.type !== "Super") {
  2331. node.property = this.parsePrivateIdent();
  2332. } else {
  2333. node.property = this.parseIdent(this.options.allowReserved !== "never");
  2334. }
  2335. node.computed = !!computed;
  2336. if (optionalSupported) {
  2337. node.optional = optional;
  2338. }
  2339. base = this.finishNode(node, "MemberExpression");
  2340. } else if (!noCalls && this.eat(types$1.parenL)) {
  2341. var refDestructuringErrors = new DestructuringErrors, oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldAwaitIdentPos = this.awaitIdentPos;
  2342. this.yieldPos = 0;
  2343. this.awaitPos = 0;
  2344. this.awaitIdentPos = 0;
  2345. var exprList = this.parseExprList(types$1.parenR, this.options.ecmaVersion >= 8, false, refDestructuringErrors);
  2346. if (maybeAsyncArrow && !optional && !this.canInsertSemicolon() && this.eat(types$1.arrow)) {
  2347. this.checkPatternErrors(refDestructuringErrors, false);
  2348. this.checkYieldAwaitInDefaultParams();
  2349. if (this.awaitIdentPos > 0)
  2350. { this.raise(this.awaitIdentPos, "Cannot use 'await' as identifier inside an async function"); }
  2351. this.yieldPos = oldYieldPos;
  2352. this.awaitPos = oldAwaitPos;
  2353. this.awaitIdentPos = oldAwaitIdentPos;
  2354. return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), exprList, true, forInit)
  2355. }
  2356. this.checkExpressionErrors(refDestructuringErrors, true);
  2357. this.yieldPos = oldYieldPos || this.yieldPos;
  2358. this.awaitPos = oldAwaitPos || this.awaitPos;
  2359. this.awaitIdentPos = oldAwaitIdentPos || this.awaitIdentPos;
  2360. var node$1 = this.startNodeAt(startPos, startLoc);
  2361. node$1.callee = base;
  2362. node$1.arguments = exprList;
  2363. if (optionalSupported) {
  2364. node$1.optional = optional;
  2365. }
  2366. base = this.finishNode(node$1, "CallExpression");
  2367. } else if (this.type === types$1.backQuote) {
  2368. if (optional || optionalChained) {
  2369. this.raise(this.start, "Optional chaining cannot appear in the tag of tagged template expressions");
  2370. }
  2371. var node$2 = this.startNodeAt(startPos, startLoc);
  2372. node$2.tag = base;
  2373. node$2.quasi = this.parseTemplate({isTagged: true});
  2374. base = this.finishNode(node$2, "TaggedTemplateExpression");
  2375. }
  2376. return base
  2377. };
  2378. // Parse an atomic expression — either a single token that is an
  2379. // expression, an expression started by a keyword like `function` or
  2380. // `new`, or an expression wrapped in punctuation like `()`, `[]`,
  2381. // or `{}`.
  2382. pp$5.parseExprAtom = function(refDestructuringErrors, forInit) {
  2383. // If a division operator appears in an expression position, the
  2384. // tokenizer got confused, and we force it to read a regexp instead.
  2385. if (this.type === types$1.slash) { this.readRegexp(); }
  2386. var node, canBeArrow = this.potentialArrowAt === this.start;
  2387. switch (this.type) {
  2388. case types$1._super:
  2389. if (!this.allowSuper)
  2390. { this.raise(this.start, "'super' keyword outside a method"); }
  2391. node = this.startNode();
  2392. this.next();
  2393. if (this.type === types$1.parenL && !this.allowDirectSuper)
  2394. { this.raise(node.start, "super() call outside constructor of a subclass"); }
  2395. // The `super` keyword can appear at below:
  2396. // SuperProperty:
  2397. // super [ Expression ]
  2398. // super . IdentifierName
  2399. // SuperCall:
  2400. // super ( Arguments )
  2401. if (this.type !== types$1.dot && this.type !== types$1.bracketL && this.type !== types$1.parenL)
  2402. { this.unexpected(); }
  2403. return this.finishNode(node, "Super")
  2404. case types$1._this:
  2405. node = this.startNode();
  2406. this.next();
  2407. return this.finishNode(node, "ThisExpression")
  2408. case types$1.name:
  2409. var startPos = this.start, startLoc = this.startLoc, containsEsc = this.containsEsc;
  2410. var id = this.parseIdent(false);
  2411. if (this.options.ecmaVersion >= 8 && !containsEsc && id.name === "async" && !this.canInsertSemicolon() && this.eat(types$1._function)) {
  2412. this.overrideContext(types.f_expr);
  2413. return this.parseFunction(this.startNodeAt(startPos, startLoc), 0, false, true, forInit)
  2414. }
  2415. if (canBeArrow && !this.canInsertSemicolon()) {
  2416. if (this.eat(types$1.arrow))
  2417. { return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), [id], false, forInit) }
  2418. if (this.options.ecmaVersion >= 8 && id.name === "async" && this.type === types$1.name && !containsEsc &&
  2419. (!this.potentialArrowInForAwait || this.value !== "of" || this.containsEsc)) {
  2420. id = this.parseIdent(false);
  2421. if (this.canInsertSemicolon() || !this.eat(types$1.arrow))
  2422. { this.unexpected(); }
  2423. return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), [id], true, forInit)
  2424. }
  2425. }
  2426. return id
  2427. case types$1.regexp:
  2428. var value = this.value;
  2429. node = this.parseLiteral(value.value);
  2430. node.regex = {pattern: value.pattern, flags: value.flags};
  2431. return node
  2432. case types$1.num: case types$1.string:
  2433. return this.parseLiteral(this.value)
  2434. case types$1._null: case types$1._true: case types$1._false:
  2435. node = this.startNode();
  2436. node.value = this.type === types$1._null ? null : this.type === types$1._true;
  2437. node.raw = this.type.keyword;
  2438. this.next();
  2439. return this.finishNode(node, "Literal")
  2440. case types$1.parenL:
  2441. var start = this.start, expr = this.parseParenAndDistinguishExpression(canBeArrow, forInit);
  2442. if (refDestructuringErrors) {
  2443. if (refDestructuringErrors.parenthesizedAssign < 0 && !this.isSimpleAssignTarget(expr))
  2444. { refDestructuringErrors.parenthesizedAssign = start; }
  2445. if (refDestructuringErrors.parenthesizedBind < 0)
  2446. { refDestructuringErrors.parenthesizedBind = start; }
  2447. }
  2448. return expr
  2449. case types$1.bracketL:
  2450. node = this.startNode();
  2451. this.next();
  2452. node.elements = this.parseExprList(types$1.bracketR, true, true, refDestructuringErrors);
  2453. return this.finishNode(node, "ArrayExpression")
  2454. case types$1.braceL:
  2455. this.overrideContext(types.b_expr);
  2456. return this.parseObj(false, refDestructuringErrors)
  2457. case types$1._function:
  2458. node = this.startNode();
  2459. this.next();
  2460. return this.parseFunction(node, 0)
  2461. case types$1._class:
  2462. return this.parseClass(this.startNode(), false)
  2463. case types$1._new:
  2464. return this.parseNew()
  2465. case types$1.backQuote:
  2466. return this.parseTemplate()
  2467. case types$1._import:
  2468. if (this.options.ecmaVersion >= 11) {
  2469. return this.parseExprImport()
  2470. } else {
  2471. return this.unexpected()
  2472. }
  2473. default:
  2474. this.unexpected();
  2475. }
  2476. };
  2477. pp$5.parseExprImport = function() {
  2478. var node = this.startNode();
  2479. // Consume `import` as an identifier for `import.meta`.
  2480. // Because `this.parseIdent(true)` doesn't check escape sequences, it needs the check of `this.containsEsc`.
  2481. if (this.containsEsc) { this.raiseRecoverable(this.start, "Escape sequence in keyword import"); }
  2482. var meta = this.parseIdent(true);
  2483. switch (this.type) {
  2484. case types$1.parenL:
  2485. return this.parseDynamicImport(node)
  2486. case types$1.dot:
  2487. node.meta = meta;
  2488. return this.parseImportMeta(node)
  2489. default:
  2490. this.unexpected();
  2491. }
  2492. };
  2493. pp$5.parseDynamicImport = function(node) {
  2494. this.next(); // skip `(`
  2495. // Parse node.source.
  2496. node.source = this.parseMaybeAssign();
  2497. // Verify ending.
  2498. if (!this.eat(types$1.parenR)) {
  2499. var errorPos = this.start;
  2500. if (this.eat(types$1.comma) && this.eat(types$1.parenR)) {
  2501. this.raiseRecoverable(errorPos, "Trailing comma is not allowed in import()");
  2502. } else {
  2503. this.unexpected(errorPos);
  2504. }
  2505. }
  2506. return this.finishNode(node, "ImportExpression")
  2507. };
  2508. pp$5.parseImportMeta = function(node) {
  2509. this.next(); // skip `.`
  2510. var containsEsc = this.containsEsc;
  2511. node.property = this.parseIdent(true);
  2512. if (node.property.name !== "meta")
  2513. { this.raiseRecoverable(node.property.start, "The only valid meta property for import is 'import.meta'"); }
  2514. if (containsEsc)
  2515. { this.raiseRecoverable(node.start, "'import.meta' must not contain escaped characters"); }
  2516. if (this.options.sourceType !== "module" && !this.options.allowImportExportEverywhere)
  2517. { this.raiseRecoverable(node.start, "Cannot use 'import.meta' outside a module"); }
  2518. return this.finishNode(node, "MetaProperty")
  2519. };
  2520. pp$5.parseLiteral = function(value) {
  2521. var node = this.startNode();
  2522. node.value = value;
  2523. node.raw = this.input.slice(this.start, this.end);
  2524. if (node.raw.charCodeAt(node.raw.length - 1) === 110) { node.bigint = node.raw.slice(0, -1).replace(/_/g, ""); }
  2525. this.next();
  2526. return this.finishNode(node, "Literal")
  2527. };
  2528. pp$5.parseParenExpression = function() {
  2529. this.expect(types$1.parenL);
  2530. var val = this.parseExpression();
  2531. this.expect(types$1.parenR);
  2532. return val
  2533. };
  2534. pp$5.parseParenAndDistinguishExpression = function(canBeArrow, forInit) {
  2535. var startPos = this.start, startLoc = this.startLoc, val, allowTrailingComma = this.options.ecmaVersion >= 8;
  2536. if (this.options.ecmaVersion >= 6) {
  2537. this.next();
  2538. var innerStartPos = this.start, innerStartLoc = this.startLoc;
  2539. var exprList = [], first = true, lastIsComma = false;
  2540. var refDestructuringErrors = new DestructuringErrors, oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, spreadStart;
  2541. this.yieldPos = 0;
  2542. this.awaitPos = 0;
  2543. // Do not save awaitIdentPos to allow checking awaits nested in parameters
  2544. while (this.type !== types$1.parenR) {
  2545. first ? first = false : this.expect(types$1.comma);
  2546. if (allowTrailingComma && this.afterTrailingComma(types$1.parenR, true)) {
  2547. lastIsComma = true;
  2548. break
  2549. } else if (this.type === types$1.ellipsis) {
  2550. spreadStart = this.start;
  2551. exprList.push(this.parseParenItem(this.parseRestBinding()));
  2552. if (this.type === types$1.comma) { this.raise(this.start, "Comma is not permitted after the rest element"); }
  2553. break
  2554. } else {
  2555. exprList.push(this.parseMaybeAssign(false, refDestructuringErrors, this.parseParenItem));
  2556. }
  2557. }
  2558. var innerEndPos = this.lastTokEnd, innerEndLoc = this.lastTokEndLoc;
  2559. this.expect(types$1.parenR);
  2560. if (canBeArrow && !this.canInsertSemicolon() && this.eat(types$1.arrow)) {
  2561. this.checkPatternErrors(refDestructuringErrors, false);
  2562. this.checkYieldAwaitInDefaultParams();
  2563. this.yieldPos = oldYieldPos;
  2564. this.awaitPos = oldAwaitPos;
  2565. return this.parseParenArrowList(startPos, startLoc, exprList, forInit)
  2566. }
  2567. if (!exprList.length || lastIsComma) { this.unexpected(this.lastTokStart); }
  2568. if (spreadStart) { this.unexpected(spreadStart); }
  2569. this.checkExpressionErrors(refDestructuringErrors, true);
  2570. this.yieldPos = oldYieldPos || this.yieldPos;
  2571. this.awaitPos = oldAwaitPos || this.awaitPos;
  2572. if (exprList.length > 1) {
  2573. val = this.startNodeAt(innerStartPos, innerStartLoc);
  2574. val.expressions = exprList;
  2575. this.finishNodeAt(val, "SequenceExpression", innerEndPos, innerEndLoc);
  2576. } else {
  2577. val = exprList[0];
  2578. }
  2579. } else {
  2580. val = this.parseParenExpression();
  2581. }
  2582. if (this.options.preserveParens) {
  2583. var par = this.startNodeAt(startPos, startLoc);
  2584. par.expression = val;
  2585. return this.finishNode(par, "ParenthesizedExpression")
  2586. } else {
  2587. return val
  2588. }
  2589. };
  2590. pp$5.parseParenItem = function(item) {
  2591. return item
  2592. };
  2593. pp$5.parseParenArrowList = function(startPos, startLoc, exprList, forInit) {
  2594. return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), exprList, false, forInit)
  2595. };
  2596. // New's precedence is slightly tricky. It must allow its argument to
  2597. // be a `[]` or dot subscript expression, but not a call — at least,
  2598. // not without wrapping it in parentheses. Thus, it uses the noCalls
  2599. // argument to parseSubscripts to prevent it from consuming the
  2600. // argument list.
  2601. var empty = [];
  2602. pp$5.parseNew = function() {
  2603. if (this.containsEsc) { this.raiseRecoverable(this.start, "Escape sequence in keyword new"); }
  2604. var node = this.startNode();
  2605. var meta = this.parseIdent(true);
  2606. if (this.options.ecmaVersion >= 6 && this.eat(types$1.dot)) {
  2607. node.meta = meta;
  2608. var containsEsc = this.containsEsc;
  2609. node.property = this.parseIdent(true);
  2610. if (node.property.name !== "target")
  2611. { this.raiseRecoverable(node.property.start, "The only valid meta property for new is 'new.target'"); }
  2612. if (containsEsc)
  2613. { this.raiseRecoverable(node.start, "'new.target' must not contain escaped characters"); }
  2614. if (!this.allowNewDotTarget)
  2615. { this.raiseRecoverable(node.start, "'new.target' can only be used in functions and class static block"); }
  2616. return this.finishNode(node, "MetaProperty")
  2617. }
  2618. var startPos = this.start, startLoc = this.startLoc, isImport = this.type === types$1._import;
  2619. node.callee = this.parseSubscripts(this.parseExprAtom(), startPos, startLoc, true, false);
  2620. if (isImport && node.callee.type === "ImportExpression") {
  2621. this.raise(startPos, "Cannot use new with import()");
  2622. }
  2623. if (this.eat(types$1.parenL)) { node.arguments = this.parseExprList(types$1.parenR, this.options.ecmaVersion >= 8, false); }
  2624. else { node.arguments = empty; }
  2625. return this.finishNode(node, "NewExpression")
  2626. };
  2627. // Parse template expression.
  2628. pp$5.parseTemplateElement = function(ref) {
  2629. var isTagged = ref.isTagged;
  2630. var elem = this.startNode();
  2631. if (this.type === types$1.invalidTemplate) {
  2632. if (!isTagged) {
  2633. this.raiseRecoverable(this.start, "Bad escape sequence in untagged template literal");
  2634. }
  2635. elem.value = {
  2636. raw: this.value,
  2637. cooked: null
  2638. };
  2639. } else {
  2640. elem.value = {
  2641. raw: this.input.slice(this.start, this.end).replace(/\r\n?/g, "\n"),
  2642. cooked: this.value
  2643. };
  2644. }
  2645. this.next();
  2646. elem.tail = this.type === types$1.backQuote;
  2647. return this.finishNode(elem, "TemplateElement")
  2648. };
  2649. pp$5.parseTemplate = function(ref) {
  2650. if ( ref === void 0 ) ref = {};
  2651. var isTagged = ref.isTagged; if ( isTagged === void 0 ) isTagged = false;
  2652. var node = this.startNode();
  2653. this.next();
  2654. node.expressions = [];
  2655. var curElt = this.parseTemplateElement({isTagged: isTagged});
  2656. node.quasis = [curElt];
  2657. while (!curElt.tail) {
  2658. if (this.type === types$1.eof) { this.raise(this.pos, "Unterminated template literal"); }
  2659. this.expect(types$1.dollarBraceL);
  2660. node.expressions.push(this.parseExpression());
  2661. this.expect(types$1.braceR);
  2662. node.quasis.push(curElt = this.parseTemplateElement({isTagged: isTagged}));
  2663. }
  2664. this.next();
  2665. return this.finishNode(node, "TemplateLiteral")
  2666. };
  2667. pp$5.isAsyncProp = function(prop) {
  2668. return !prop.computed && prop.key.type === "Identifier" && prop.key.name === "async" &&
  2669. (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)) &&
  2670. !lineBreak.test(this.input.slice(this.lastTokEnd, this.start))
  2671. };
  2672. // Parse an object literal or binding pattern.
  2673. pp$5.parseObj = function(isPattern, refDestructuringErrors) {
  2674. var node = this.startNode(), first = true, propHash = {};
  2675. node.properties = [];
  2676. this.next();
  2677. while (!this.eat(types$1.braceR)) {
  2678. if (!first) {
  2679. this.expect(types$1.comma);
  2680. if (this.options.ecmaVersion >= 5 && this.afterTrailingComma(types$1.braceR)) { break }
  2681. } else { first = false; }
  2682. var prop = this.parseProperty(isPattern, refDestructuringErrors);
  2683. if (!isPattern) { this.checkPropClash(prop, propHash, refDestructuringErrors); }
  2684. node.properties.push(prop);
  2685. }
  2686. return this.finishNode(node, isPattern ? "ObjectPattern" : "ObjectExpression")
  2687. };
  2688. pp$5.parseProperty = function(isPattern, refDestructuringErrors) {
  2689. var prop = this.startNode(), isGenerator, isAsync, startPos, startLoc;
  2690. if (this.options.ecmaVersion >= 9 && this.eat(types$1.ellipsis)) {
  2691. if (isPattern) {
  2692. prop.argument = this.parseIdent(false);
  2693. if (this.type === types$1.comma) {
  2694. this.raise(this.start, "Comma is not permitted after the rest element");
  2695. }
  2696. return this.finishNode(prop, "RestElement")
  2697. }
  2698. // To disallow parenthesized identifier via `this.toAssignable()`.
  2699. if (this.type === types$1.parenL && refDestructuringErrors) {
  2700. if (refDestructuringErrors.parenthesizedAssign < 0) {
  2701. refDestructuringErrors.parenthesizedAssign = this.start;
  2702. }
  2703. if (refDestructuringErrors.parenthesizedBind < 0) {
  2704. refDestructuringErrors.parenthesizedBind = this.start;
  2705. }
  2706. }
  2707. // Parse argument.
  2708. prop.argument = this.parseMaybeAssign(false, refDestructuringErrors);
  2709. // To disallow trailing comma via `this.toAssignable()`.
  2710. if (this.type === types$1.comma && refDestructuringErrors && refDestructuringErrors.trailingComma < 0) {
  2711. refDestructuringErrors.trailingComma = this.start;
  2712. }
  2713. // Finish
  2714. return this.finishNode(prop, "SpreadElement")
  2715. }
  2716. if (this.options.ecmaVersion >= 6) {
  2717. prop.method = false;
  2718. prop.shorthand = false;
  2719. if (isPattern || refDestructuringErrors) {
  2720. startPos = this.start;
  2721. startLoc = this.startLoc;
  2722. }
  2723. if (!isPattern)
  2724. { isGenerator = this.eat(types$1.star); }
  2725. }
  2726. var containsEsc = this.containsEsc;
  2727. this.parsePropertyName(prop);
  2728. if (!isPattern && !containsEsc && this.options.ecmaVersion >= 8 && !isGenerator && this.isAsyncProp(prop)) {
  2729. isAsync = true;
  2730. isGenerator = this.options.ecmaVersion >= 9 && this.eat(types$1.star);
  2731. this.parsePropertyName(prop, refDestructuringErrors);
  2732. } else {
  2733. isAsync = false;
  2734. }
  2735. this.parsePropertyValue(prop, isPattern, isGenerator, isAsync, startPos, startLoc, refDestructuringErrors, containsEsc);
  2736. return this.finishNode(prop, "Property")
  2737. };
  2738. pp$5.parsePropertyValue = function(prop, isPattern, isGenerator, isAsync, startPos, startLoc, refDestructuringErrors, containsEsc) {
  2739. if ((isGenerator || isAsync) && this.type === types$1.colon)
  2740. { this.unexpected(); }
  2741. if (this.eat(types$1.colon)) {
  2742. prop.value = isPattern ? this.parseMaybeDefault(this.start, this.startLoc) : this.parseMaybeAssign(false, refDestructuringErrors);
  2743. prop.kind = "init";
  2744. } else if (this.options.ecmaVersion >= 6 && this.type === types$1.parenL) {
  2745. if (isPattern) { this.unexpected(); }
  2746. prop.kind = "init";
  2747. prop.method = true;
  2748. prop.value = this.parseMethod(isGenerator, isAsync);
  2749. } else if (!isPattern && !containsEsc &&
  2750. this.options.ecmaVersion >= 5 && !prop.computed && prop.key.type === "Identifier" &&
  2751. (prop.key.name === "get" || prop.key.name === "set") &&
  2752. (this.type !== types$1.comma && this.type !== types$1.braceR && this.type !== types$1.eq)) {
  2753. if (isGenerator || isAsync) { this.unexpected(); }
  2754. prop.kind = prop.key.name;
  2755. this.parsePropertyName(prop);
  2756. prop.value = this.parseMethod(false);
  2757. var paramCount = prop.kind === "get" ? 0 : 1;
  2758. if (prop.value.params.length !== paramCount) {
  2759. var start = prop.value.start;
  2760. if (prop.kind === "get")
  2761. { this.raiseRecoverable(start, "getter should have no params"); }
  2762. else
  2763. { this.raiseRecoverable(start, "setter should have exactly one param"); }
  2764. } else {
  2765. if (prop.kind === "set" && prop.value.params[0].type === "RestElement")
  2766. { this.raiseRecoverable(prop.value.params[0].start, "Setter cannot use rest params"); }
  2767. }
  2768. } else if (this.options.ecmaVersion >= 6 && !prop.computed && prop.key.type === "Identifier") {
  2769. if (isGenerator || isAsync) { this.unexpected(); }
  2770. this.checkUnreserved(prop.key);
  2771. if (prop.key.name === "await" && !this.awaitIdentPos)
  2772. { this.awaitIdentPos = startPos; }
  2773. prop.kind = "init";
  2774. if (isPattern) {
  2775. prop.value = this.parseMaybeDefault(startPos, startLoc, this.copyNode(prop.key));
  2776. } else if (this.type === types$1.eq && refDestructuringErrors) {
  2777. if (refDestructuringErrors.shorthandAssign < 0)
  2778. { refDestructuringErrors.shorthandAssign = this.start; }
  2779. prop.value = this.parseMaybeDefault(startPos, startLoc, this.copyNode(prop.key));
  2780. } else {
  2781. prop.value = this.copyNode(prop.key);
  2782. }
  2783. prop.shorthand = true;
  2784. } else { this.unexpected(); }
  2785. };
  2786. pp$5.parsePropertyName = function(prop) {
  2787. if (this.options.ecmaVersion >= 6) {
  2788. if (this.eat(types$1.bracketL)) {
  2789. prop.computed = true;
  2790. prop.key = this.parseMaybeAssign();
  2791. this.expect(types$1.bracketR);
  2792. return prop.key
  2793. } else {
  2794. prop.computed = false;
  2795. }
  2796. }
  2797. return prop.key = this.type === types$1.num || this.type === types$1.string ? this.parseExprAtom() : this.parseIdent(this.options.allowReserved !== "never")
  2798. };
  2799. // Initialize empty function node.
  2800. pp$5.initFunction = function(node) {
  2801. node.id = null;
  2802. if (this.options.ecmaVersion >= 6) { node.generator = node.expression = false; }
  2803. if (this.options.ecmaVersion >= 8) { node.async = false; }
  2804. };
  2805. // Parse object or class method.
  2806. pp$5.parseMethod = function(isGenerator, isAsync, allowDirectSuper) {
  2807. var node = this.startNode(), oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldAwaitIdentPos = this.awaitIdentPos;
  2808. this.initFunction(node);
  2809. if (this.options.ecmaVersion >= 6)
  2810. { node.generator = isGenerator; }
  2811. if (this.options.ecmaVersion >= 8)
  2812. { node.async = !!isAsync; }
  2813. this.yieldPos = 0;
  2814. this.awaitPos = 0;
  2815. this.awaitIdentPos = 0;
  2816. this.enterScope(functionFlags(isAsync, node.generator) | SCOPE_SUPER | (allowDirectSuper ? SCOPE_DIRECT_SUPER : 0));
  2817. this.expect(types$1.parenL);
  2818. node.params = this.parseBindingList(types$1.parenR, false, this.options.ecmaVersion >= 8);
  2819. this.checkYieldAwaitInDefaultParams();
  2820. this.parseFunctionBody(node, false, true, false);
  2821. this.yieldPos = oldYieldPos;
  2822. this.awaitPos = oldAwaitPos;
  2823. this.awaitIdentPos = oldAwaitIdentPos;
  2824. return this.finishNode(node, "FunctionExpression")
  2825. };
  2826. // Parse arrow function expression with given parameters.
  2827. pp$5.parseArrowExpression = function(node, params, isAsync, forInit) {
  2828. var oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldAwaitIdentPos = this.awaitIdentPos;
  2829. this.enterScope(functionFlags(isAsync, false) | SCOPE_ARROW);
  2830. this.initFunction(node);
  2831. if (this.options.ecmaVersion >= 8) { node.async = !!isAsync; }
  2832. this.yieldPos = 0;
  2833. this.awaitPos = 0;
  2834. this.awaitIdentPos = 0;
  2835. node.params = this.toAssignableList(params, true);
  2836. this.parseFunctionBody(node, true, false, forInit);
  2837. this.yieldPos = oldYieldPos;
  2838. this.awaitPos = oldAwaitPos;
  2839. this.awaitIdentPos = oldAwaitIdentPos;
  2840. return this.finishNode(node, "ArrowFunctionExpression")
  2841. };
  2842. // Parse function body and check parameters.
  2843. pp$5.parseFunctionBody = function(node, isArrowFunction, isMethod, forInit) {
  2844. var isExpression = isArrowFunction && this.type !== types$1.braceL;
  2845. var oldStrict = this.strict, useStrict = false;
  2846. if (isExpression) {
  2847. node.body = this.parseMaybeAssign(forInit);
  2848. node.expression = true;
  2849. this.checkParams(node, false);
  2850. } else {
  2851. var nonSimple = this.options.ecmaVersion >= 7 && !this.isSimpleParamList(node.params);
  2852. if (!oldStrict || nonSimple) {
  2853. useStrict = this.strictDirective(this.end);
  2854. // If this is a strict mode function, verify that argument names
  2855. // are not repeated, and it does not try to bind the words `eval`
  2856. // or `arguments`.
  2857. if (useStrict && nonSimple)
  2858. { this.raiseRecoverable(node.start, "Illegal 'use strict' directive in function with non-simple parameter list"); }
  2859. }
  2860. // Start a new scope with regard to labels and the `inFunction`
  2861. // flag (restore them to their old value afterwards).
  2862. var oldLabels = this.labels;
  2863. this.labels = [];
  2864. if (useStrict) { this.strict = true; }
  2865. // Add the params to varDeclaredNames to ensure that an error is thrown
  2866. // if a let/const declaration in the function clashes with one of the params.
  2867. this.checkParams(node, !oldStrict && !useStrict && !isArrowFunction && !isMethod && this.isSimpleParamList(node.params));
  2868. // Ensure the function name isn't a forbidden identifier in strict mode, e.g. 'eval'
  2869. if (this.strict && node.id) { this.checkLValSimple(node.id, BIND_OUTSIDE); }
  2870. node.body = this.parseBlock(false, undefined, useStrict && !oldStrict);
  2871. node.expression = false;
  2872. this.adaptDirectivePrologue(node.body.body);
  2873. this.labels = oldLabels;
  2874. }
  2875. this.exitScope();
  2876. };
  2877. pp$5.isSimpleParamList = function(params) {
  2878. for (var i = 0, list = params; i < list.length; i += 1)
  2879. {
  2880. var param = list[i];
  2881. if (param.type !== "Identifier") { return false
  2882. } }
  2883. return true
  2884. };
  2885. // Checks function params for various disallowed patterns such as using "eval"
  2886. // or "arguments" and duplicate parameters.
  2887. pp$5.checkParams = function(node, allowDuplicates) {
  2888. var nameHash = Object.create(null);
  2889. for (var i = 0, list = node.params; i < list.length; i += 1)
  2890. {
  2891. var param = list[i];
  2892. this.checkLValInnerPattern(param, BIND_VAR, allowDuplicates ? null : nameHash);
  2893. }
  2894. };
  2895. // Parses a comma-separated list of expressions, and returns them as
  2896. // an array. `close` is the token type that ends the list, and
  2897. // `allowEmpty` can be turned on to allow subsequent commas with
  2898. // nothing in between them to be parsed as `null` (which is needed
  2899. // for array literals).
  2900. pp$5.parseExprList = function(close, allowTrailingComma, allowEmpty, refDestructuringErrors) {
  2901. var elts = [], first = true;
  2902. while (!this.eat(close)) {
  2903. if (!first) {
  2904. this.expect(types$1.comma);
  2905. if (allowTrailingComma && this.afterTrailingComma(close)) { break }
  2906. } else { first = false; }
  2907. var elt = (void 0);
  2908. if (allowEmpty && this.type === types$1.comma)
  2909. { elt = null; }
  2910. else if (this.type === types$1.ellipsis) {
  2911. elt = this.parseSpread(refDestructuringErrors);
  2912. if (refDestructuringErrors && this.type === types$1.comma && refDestructuringErrors.trailingComma < 0)
  2913. { refDestructuringErrors.trailingComma = this.start; }
  2914. } else {
  2915. elt = this.parseMaybeAssign(false, refDestructuringErrors);
  2916. }
  2917. elts.push(elt);
  2918. }
  2919. return elts
  2920. };
  2921. pp$5.checkUnreserved = function(ref) {
  2922. var start = ref.start;
  2923. var end = ref.end;
  2924. var name = ref.name;
  2925. if (this.inGenerator && name === "yield")
  2926. { this.raiseRecoverable(start, "Cannot use 'yield' as identifier inside a generator"); }
  2927. if (this.inAsync && name === "await")
  2928. { this.raiseRecoverable(start, "Cannot use 'await' as identifier inside an async function"); }
  2929. if (this.currentThisScope().inClassFieldInit && name === "arguments")
  2930. { this.raiseRecoverable(start, "Cannot use 'arguments' in class field initializer"); }
  2931. if (this.inClassStaticBlock && (name === "arguments" || name === "await"))
  2932. { this.raise(start, ("Cannot use " + name + " in class static initialization block")); }
  2933. if (this.keywords.test(name))
  2934. { this.raise(start, ("Unexpected keyword '" + name + "'")); }
  2935. if (this.options.ecmaVersion < 6 &&
  2936. this.input.slice(start, end).indexOf("\\") !== -1) { return }
  2937. var re = this.strict ? this.reservedWordsStrict : this.reservedWords;
  2938. if (re.test(name)) {
  2939. if (!this.inAsync && name === "await")
  2940. { this.raiseRecoverable(start, "Cannot use keyword 'await' outside an async function"); }
  2941. this.raiseRecoverable(start, ("The keyword '" + name + "' is reserved"));
  2942. }
  2943. };
  2944. // Parse the next token as an identifier. If `liberal` is true (used
  2945. // when parsing properties), it will also convert keywords into
  2946. // identifiers.
  2947. pp$5.parseIdent = function(liberal, isBinding) {
  2948. var node = this.startNode();
  2949. if (this.type === types$1.name) {
  2950. node.name = this.value;
  2951. } else if (this.type.keyword) {
  2952. node.name = this.type.keyword;
  2953. // To fix https://github.com/acornjs/acorn/issues/575
  2954. // `class` and `function` keywords push new context into this.context.
  2955. // But there is no chance to pop the context if the keyword is consumed as an identifier such as a property name.
  2956. // If the previous token is a dot, this does not apply because the context-managing code already ignored the keyword
  2957. if ((node.name === "class" || node.name === "function") &&
  2958. (this.lastTokEnd !== this.lastTokStart + 1 || this.input.charCodeAt(this.lastTokStart) !== 46)) {
  2959. this.context.pop();
  2960. }
  2961. } else {
  2962. this.unexpected();
  2963. }
  2964. this.next(!!liberal);
  2965. this.finishNode(node, "Identifier");
  2966. if (!liberal) {
  2967. this.checkUnreserved(node);
  2968. if (node.name === "await" && !this.awaitIdentPos)
  2969. { this.awaitIdentPos = node.start; }
  2970. }
  2971. return node
  2972. };
  2973. pp$5.parsePrivateIdent = function() {
  2974. var node = this.startNode();
  2975. if (this.type === types$1.privateId) {
  2976. node.name = this.value;
  2977. } else {
  2978. this.unexpected();
  2979. }
  2980. this.next();
  2981. this.finishNode(node, "PrivateIdentifier");
  2982. // For validating existence
  2983. if (this.privateNameStack.length === 0) {
  2984. this.raise(node.start, ("Private field '#" + (node.name) + "' must be declared in an enclosing class"));
  2985. } else {
  2986. this.privateNameStack[this.privateNameStack.length - 1].used.push(node);
  2987. }
  2988. return node
  2989. };
  2990. // Parses yield expression inside generator.
  2991. pp$5.parseYield = function(forInit) {
  2992. if (!this.yieldPos) { this.yieldPos = this.start; }
  2993. var node = this.startNode();
  2994. this.next();
  2995. if (this.type === types$1.semi || this.canInsertSemicolon() || (this.type !== types$1.star && !this.type.startsExpr)) {
  2996. node.delegate = false;
  2997. node.argument = null;
  2998. } else {
  2999. node.delegate = this.eat(types$1.star);
  3000. node.argument = this.parseMaybeAssign(forInit);
  3001. }
  3002. return this.finishNode(node, "YieldExpression")
  3003. };
  3004. pp$5.parseAwait = function(forInit) {
  3005. if (!this.awaitPos) { this.awaitPos = this.start; }
  3006. var node = this.startNode();
  3007. this.next();
  3008. node.argument = this.parseMaybeUnary(null, true, false, forInit);
  3009. return this.finishNode(node, "AwaitExpression")
  3010. };
  3011. var pp$4 = Parser.prototype;
  3012. // This function is used to raise exceptions on parse errors. It
  3013. // takes an offset integer (into the current `input`) to indicate
  3014. // the location of the error, attaches the position to the end
  3015. // of the error message, and then raises a `SyntaxError` with that
  3016. // message.
  3017. pp$4.raise = function(pos, message) {
  3018. var loc = getLineInfo(this.input, pos);
  3019. message += " (" + loc.line + ":" + loc.column + ")";
  3020. var err = new SyntaxError(message);
  3021. err.pos = pos; err.loc = loc; err.raisedAt = this.pos;
  3022. throw err
  3023. };
  3024. pp$4.raiseRecoverable = pp$4.raise;
  3025. pp$4.curPosition = function() {
  3026. if (this.options.locations) {
  3027. return new Position(this.curLine, this.pos - this.lineStart)
  3028. }
  3029. };
  3030. var pp$3 = Parser.prototype;
  3031. var Scope = function Scope(flags) {
  3032. this.flags = flags;
  3033. // A list of var-declared names in the current lexical scope
  3034. this.var = [];
  3035. // A list of lexically-declared names in the current lexical scope
  3036. this.lexical = [];
  3037. // A list of lexically-declared FunctionDeclaration names in the current lexical scope
  3038. this.functions = [];
  3039. // A switch to disallow the identifier reference 'arguments'
  3040. this.inClassFieldInit = false;
  3041. };
  3042. // The functions in this module keep track of declared variables in the current scope in order to detect duplicate variable names.
  3043. pp$3.enterScope = function(flags) {
  3044. this.scopeStack.push(new Scope(flags));
  3045. };
  3046. pp$3.exitScope = function() {
  3047. this.scopeStack.pop();
  3048. };
  3049. // The spec says:
  3050. // > At the top level of a function, or script, function declarations are
  3051. // > treated like var declarations rather than like lexical declarations.
  3052. pp$3.treatFunctionsAsVarInScope = function(scope) {
  3053. return (scope.flags & SCOPE_FUNCTION) || !this.inModule && (scope.flags & SCOPE_TOP)
  3054. };
  3055. pp$3.declareName = function(name, bindingType, pos) {
  3056. var redeclared = false;
  3057. if (bindingType === BIND_LEXICAL) {
  3058. var scope = this.currentScope();
  3059. redeclared = scope.lexical.indexOf(name) > -1 || scope.functions.indexOf(name) > -1 || scope.var.indexOf(name) > -1;
  3060. scope.lexical.push(name);
  3061. if (this.inModule && (scope.flags & SCOPE_TOP))
  3062. { delete this.undefinedExports[name]; }
  3063. } else if (bindingType === BIND_SIMPLE_CATCH) {
  3064. var scope$1 = this.currentScope();
  3065. scope$1.lexical.push(name);
  3066. } else if (bindingType === BIND_FUNCTION) {
  3067. var scope$2 = this.currentScope();
  3068. if (this.treatFunctionsAsVar)
  3069. { redeclared = scope$2.lexical.indexOf(name) > -1; }
  3070. else
  3071. { redeclared = scope$2.lexical.indexOf(name) > -1 || scope$2.var.indexOf(name) > -1; }
  3072. scope$2.functions.push(name);
  3073. } else {
  3074. for (var i = this.scopeStack.length - 1; i >= 0; --i) {
  3075. var scope$3 = this.scopeStack[i];
  3076. if (scope$3.lexical.indexOf(name) > -1 && !((scope$3.flags & SCOPE_SIMPLE_CATCH) && scope$3.lexical[0] === name) ||
  3077. !this.treatFunctionsAsVarInScope(scope$3) && scope$3.functions.indexOf(name) > -1) {
  3078. redeclared = true;
  3079. break
  3080. }
  3081. scope$3.var.push(name);
  3082. if (this.inModule && (scope$3.flags & SCOPE_TOP))
  3083. { delete this.undefinedExports[name]; }
  3084. if (scope$3.flags & SCOPE_VAR) { break }
  3085. }
  3086. }
  3087. if (redeclared) { this.raiseRecoverable(pos, ("Identifier '" + name + "' has already been declared")); }
  3088. };
  3089. pp$3.checkLocalExport = function(id) {
  3090. // scope.functions must be empty as Module code is always strict.
  3091. if (this.scopeStack[0].lexical.indexOf(id.name) === -1 &&
  3092. this.scopeStack[0].var.indexOf(id.name) === -1) {
  3093. this.undefinedExports[id.name] = id;
  3094. }
  3095. };
  3096. pp$3.currentScope = function() {
  3097. return this.scopeStack[this.scopeStack.length - 1]
  3098. };
  3099. pp$3.currentVarScope = function() {
  3100. for (var i = this.scopeStack.length - 1;; i--) {
  3101. var scope = this.scopeStack[i];
  3102. if (scope.flags & SCOPE_VAR) { return scope }
  3103. }
  3104. };
  3105. // Could be useful for `this`, `new.target`, `super()`, `super.property`, and `super[property]`.
  3106. pp$3.currentThisScope = function() {
  3107. for (var i = this.scopeStack.length - 1;; i--) {
  3108. var scope = this.scopeStack[i];
  3109. if (scope.flags & SCOPE_VAR && !(scope.flags & SCOPE_ARROW)) { return scope }
  3110. }
  3111. };
  3112. var Node = function Node(parser, pos, loc) {
  3113. this.type = "";
  3114. this.start = pos;
  3115. this.end = 0;
  3116. if (parser.options.locations)
  3117. { this.loc = new SourceLocation(parser, loc); }
  3118. if (parser.options.directSourceFile)
  3119. { this.sourceFile = parser.options.directSourceFile; }
  3120. if (parser.options.ranges)
  3121. { this.range = [pos, 0]; }
  3122. };
  3123. // Start an AST node, attaching a start offset.
  3124. var pp$2 = Parser.prototype;
  3125. pp$2.startNode = function() {
  3126. return new Node(this, this.start, this.startLoc)
  3127. };
  3128. pp$2.startNodeAt = function(pos, loc) {
  3129. return new Node(this, pos, loc)
  3130. };
  3131. // Finish an AST node, adding `type` and `end` properties.
  3132. function finishNodeAt(node, type, pos, loc) {
  3133. node.type = type;
  3134. node.end = pos;
  3135. if (this.options.locations)
  3136. { node.loc.end = loc; }
  3137. if (this.options.ranges)
  3138. { node.range[1] = pos; }
  3139. return node
  3140. }
  3141. pp$2.finishNode = function(node, type) {
  3142. return finishNodeAt.call(this, node, type, this.lastTokEnd, this.lastTokEndLoc)
  3143. };
  3144. // Finish node at given position
  3145. pp$2.finishNodeAt = function(node, type, pos, loc) {
  3146. return finishNodeAt.call(this, node, type, pos, loc)
  3147. };
  3148. pp$2.copyNode = function(node) {
  3149. var newNode = new Node(this, node.start, this.startLoc);
  3150. for (var prop in node) { newNode[prop] = node[prop]; }
  3151. return newNode
  3152. };
  3153. // This file contains Unicode properties extracted from the ECMAScript
  3154. // specification. The lists are extracted like so:
  3155. // $$('#table-binary-unicode-properties > figure > table > tbody > tr > td:nth-child(1) code').map(el => el.innerText)
  3156. // #table-binary-unicode-properties
  3157. 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";
  3158. var ecma10BinaryProperties = ecma9BinaryProperties + " Extended_Pictographic";
  3159. var ecma11BinaryProperties = ecma10BinaryProperties;
  3160. var ecma12BinaryProperties = ecma11BinaryProperties + " EBase EComp EMod EPres ExtPict";
  3161. var ecma13BinaryProperties = ecma12BinaryProperties;
  3162. var unicodeBinaryProperties = {
  3163. 9: ecma9BinaryProperties,
  3164. 10: ecma10BinaryProperties,
  3165. 11: ecma11BinaryProperties,
  3166. 12: ecma12BinaryProperties,
  3167. 13: ecma13BinaryProperties
  3168. };
  3169. // #table-unicode-general-category-values
  3170. 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";
  3171. // #table-unicode-script-values
  3172. 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";
  3173. var ecma10ScriptValues = ecma9ScriptValues + " Dogra Dogr Gunjala_Gondi Gong Hanifi_Rohingya Rohg Makasar Maka Medefaidrin Medf Old_Sogdian Sogo Sogdian Sogd";
  3174. var ecma11ScriptValues = ecma10ScriptValues + " Elymaic Elym Nandinagari Nand Nyiakeng_Puachue_Hmong Hmnp Wancho Wcho";
  3175. var ecma12ScriptValues = ecma11ScriptValues + " Chorasmian Chrs Diak Dives_Akuru Khitan_Small_Script Kits Yezi Yezidi";
  3176. var ecma13ScriptValues = ecma12ScriptValues + " Cypro_Minoan Cpmn Old_Uyghur Ougr Tangsa Tnsa Toto Vithkuqi Vith";
  3177. var unicodeScriptValues = {
  3178. 9: ecma9ScriptValues,
  3179. 10: ecma10ScriptValues,
  3180. 11: ecma11ScriptValues,
  3181. 12: ecma12ScriptValues,
  3182. 13: ecma13ScriptValues
  3183. };
  3184. var data = {};
  3185. function buildUnicodeData(ecmaVersion) {
  3186. var d = data[ecmaVersion] = {
  3187. binary: wordsRegexp(unicodeBinaryProperties[ecmaVersion] + " " + unicodeGeneralCategoryValues),
  3188. nonBinary: {
  3189. General_Category: wordsRegexp(unicodeGeneralCategoryValues),
  3190. Script: wordsRegexp(unicodeScriptValues[ecmaVersion])
  3191. }
  3192. };
  3193. d.nonBinary.Script_Extensions = d.nonBinary.Script;
  3194. d.nonBinary.gc = d.nonBinary.General_Category;
  3195. d.nonBinary.sc = d.nonBinary.Script;
  3196. d.nonBinary.scx = d.nonBinary.Script_Extensions;
  3197. }
  3198. for (var i = 0, list = [9, 10, 11, 12, 13]; i < list.length; i += 1) {
  3199. var ecmaVersion = list[i];
  3200. buildUnicodeData(ecmaVersion);
  3201. }
  3202. var pp$1 = Parser.prototype;
  3203. var RegExpValidationState = function RegExpValidationState(parser) {
  3204. this.parser = parser;
  3205. this.validFlags = "gim" + (parser.options.ecmaVersion >= 6 ? "uy" : "") + (parser.options.ecmaVersion >= 9 ? "s" : "") + (parser.options.ecmaVersion >= 13 ? "d" : "");
  3206. this.unicodeProperties = data[parser.options.ecmaVersion >= 13 ? 13 : parser.options.ecmaVersion];
  3207. this.source = "";
  3208. this.flags = "";
  3209. this.start = 0;
  3210. this.switchU = false;
  3211. this.switchN = false;
  3212. this.pos = 0;
  3213. this.lastIntValue = 0;
  3214. this.lastStringValue = "";
  3215. this.lastAssertionIsQuantifiable = false;
  3216. this.numCapturingParens = 0;
  3217. this.maxBackReference = 0;
  3218. this.groupNames = [];
  3219. this.backReferenceNames = [];
  3220. };
  3221. RegExpValidationState.prototype.reset = function reset (start, pattern, flags) {
  3222. var unicode = flags.indexOf("u") !== -1;
  3223. this.start = start | 0;
  3224. this.source = pattern + "";
  3225. this.flags = flags;
  3226. this.switchU = unicode && this.parser.options.ecmaVersion >= 6;
  3227. this.switchN = unicode && this.parser.options.ecmaVersion >= 9;
  3228. };
  3229. RegExpValidationState.prototype.raise = function raise (message) {
  3230. this.parser.raiseRecoverable(this.start, ("Invalid regular expression: /" + (this.source) + "/: " + message));
  3231. };
  3232. // If u flag is given, this returns the code point at the index (it combines a surrogate pair).
  3233. // Otherwise, this returns the code unit of the index (can be a part of a surrogate pair).
  3234. RegExpValidationState.prototype.at = function at (i, forceU) {
  3235. if ( forceU === void 0 ) forceU = false;
  3236. var s = this.source;
  3237. var l = s.length;
  3238. if (i >= l) {
  3239. return -1
  3240. }
  3241. var c = s.charCodeAt(i);
  3242. if (!(forceU || this.switchU) || c <= 0xD7FF || c >= 0xE000 || i + 1 >= l) {
  3243. return c
  3244. }
  3245. var next = s.charCodeAt(i + 1);
  3246. return next >= 0xDC00 && next <= 0xDFFF ? (c << 10) + next - 0x35FDC00 : c
  3247. };
  3248. RegExpValidationState.prototype.nextIndex = function nextIndex (i, forceU) {
  3249. if ( forceU === void 0 ) forceU = false;
  3250. var s = this.source;
  3251. var l = s.length;
  3252. if (i >= l) {
  3253. return l
  3254. }
  3255. var c = s.charCodeAt(i), next;
  3256. if (!(forceU || this.switchU) || c <= 0xD7FF || c >= 0xE000 || i + 1 >= l ||
  3257. (next = s.charCodeAt(i + 1)) < 0xDC00 || next > 0xDFFF) {
  3258. return i + 1
  3259. }
  3260. return i + 2
  3261. };
  3262. RegExpValidationState.prototype.current = function current (forceU) {
  3263. if ( forceU === void 0 ) forceU = false;
  3264. return this.at(this.pos, forceU)
  3265. };
  3266. RegExpValidationState.prototype.lookahead = function lookahead (forceU) {
  3267. if ( forceU === void 0 ) forceU = false;
  3268. return this.at(this.nextIndex(this.pos, forceU), forceU)
  3269. };
  3270. RegExpValidationState.prototype.advance = function advance (forceU) {
  3271. if ( forceU === void 0 ) forceU = false;
  3272. this.pos = this.nextIndex(this.pos, forceU);
  3273. };
  3274. RegExpValidationState.prototype.eat = function eat (ch, forceU) {
  3275. if ( forceU === void 0 ) forceU = false;
  3276. if (this.current(forceU) === ch) {
  3277. this.advance(forceU);
  3278. return true
  3279. }
  3280. return false
  3281. };
  3282. function codePointToString$1(ch) {
  3283. if (ch <= 0xFFFF) { return String.fromCharCode(ch) }
  3284. ch -= 0x10000;
  3285. return String.fromCharCode((ch >> 10) + 0xD800, (ch & 0x03FF) + 0xDC00)
  3286. }
  3287. /**
  3288. * Validate the flags part of a given RegExpLiteral.
  3289. *
  3290. * @param {RegExpValidationState} state The state to validate RegExp.
  3291. * @returns {void}
  3292. */
  3293. pp$1.validateRegExpFlags = function(state) {
  3294. var validFlags = state.validFlags;
  3295. var flags = state.flags;
  3296. for (var i = 0; i < flags.length; i++) {
  3297. var flag = flags.charAt(i);
  3298. if (validFlags.indexOf(flag) === -1) {
  3299. this.raise(state.start, "Invalid regular expression flag");
  3300. }
  3301. if (flags.indexOf(flag, i + 1) > -1) {
  3302. this.raise(state.start, "Duplicate regular expression flag");
  3303. }
  3304. }
  3305. };
  3306. /**
  3307. * Validate the pattern part of a given RegExpLiteral.
  3308. *
  3309. * @param {RegExpValidationState} state The state to validate RegExp.
  3310. * @returns {void}
  3311. */
  3312. pp$1.validateRegExpPattern = function(state) {
  3313. this.regexp_pattern(state);
  3314. // The goal symbol for the parse is |Pattern[~U, ~N]|. If the result of
  3315. // parsing contains a |GroupName|, reparse with the goal symbol
  3316. // |Pattern[~U, +N]| and use this result instead. Throw a *SyntaxError*
  3317. // exception if _P_ did not conform to the grammar, if any elements of _P_
  3318. // were not matched by the parse, or if any Early Error conditions exist.
  3319. if (!state.switchN && this.options.ecmaVersion >= 9 && state.groupNames.length > 0) {
  3320. state.switchN = true;
  3321. this.regexp_pattern(state);
  3322. }
  3323. };
  3324. // https://www.ecma-international.org/ecma-262/8.0/#prod-Pattern
  3325. pp$1.regexp_pattern = function(state) {
  3326. state.pos = 0;
  3327. state.lastIntValue = 0;
  3328. state.lastStringValue = "";
  3329. state.lastAssertionIsQuantifiable = false;
  3330. state.numCapturingParens = 0;
  3331. state.maxBackReference = 0;
  3332. state.groupNames.length = 0;
  3333. state.backReferenceNames.length = 0;
  3334. this.regexp_disjunction(state);
  3335. if (state.pos !== state.source.length) {
  3336. // Make the same messages as V8.
  3337. if (state.eat(0x29 /* ) */)) {
  3338. state.raise("Unmatched ')'");
  3339. }
  3340. if (state.eat(0x5D /* ] */) || state.eat(0x7D /* } */)) {
  3341. state.raise("Lone quantifier brackets");
  3342. }
  3343. }
  3344. if (state.maxBackReference > state.numCapturingParens) {
  3345. state.raise("Invalid escape");
  3346. }
  3347. for (var i = 0, list = state.backReferenceNames; i < list.length; i += 1) {
  3348. var name = list[i];
  3349. if (state.groupNames.indexOf(name) === -1) {
  3350. state.raise("Invalid named capture referenced");
  3351. }
  3352. }
  3353. };
  3354. // https://www.ecma-international.org/ecma-262/8.0/#prod-Disjunction
  3355. pp$1.regexp_disjunction = function(state) {
  3356. this.regexp_alternative(state);
  3357. while (state.eat(0x7C /* | */)) {
  3358. this.regexp_alternative(state);
  3359. }
  3360. // Make the same message as V8.
  3361. if (this.regexp_eatQuantifier(state, true)) {
  3362. state.raise("Nothing to repeat");
  3363. }
  3364. if (state.eat(0x7B /* { */)) {
  3365. state.raise("Lone quantifier brackets");
  3366. }
  3367. };
  3368. // https://www.ecma-international.org/ecma-262/8.0/#prod-Alternative
  3369. pp$1.regexp_alternative = function(state) {
  3370. while (state.pos < state.source.length && this.regexp_eatTerm(state))
  3371. { }
  3372. };
  3373. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-Term
  3374. pp$1.regexp_eatTerm = function(state) {
  3375. if (this.regexp_eatAssertion(state)) {
  3376. // Handle `QuantifiableAssertion Quantifier` alternative.
  3377. // `state.lastAssertionIsQuantifiable` is true if the last eaten Assertion
  3378. // is a QuantifiableAssertion.
  3379. if (state.lastAssertionIsQuantifiable && this.regexp_eatQuantifier(state)) {
  3380. // Make the same message as V8.
  3381. if (state.switchU) {
  3382. state.raise("Invalid quantifier");
  3383. }
  3384. }
  3385. return true
  3386. }
  3387. if (state.switchU ? this.regexp_eatAtom(state) : this.regexp_eatExtendedAtom(state)) {
  3388. this.regexp_eatQuantifier(state);
  3389. return true
  3390. }
  3391. return false
  3392. };
  3393. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-Assertion
  3394. pp$1.regexp_eatAssertion = function(state) {
  3395. var start = state.pos;
  3396. state.lastAssertionIsQuantifiable = false;
  3397. // ^, $
  3398. if (state.eat(0x5E /* ^ */) || state.eat(0x24 /* $ */)) {
  3399. return true
  3400. }
  3401. // \b \B
  3402. if (state.eat(0x5C /* \ */)) {
  3403. if (state.eat(0x42 /* B */) || state.eat(0x62 /* b */)) {
  3404. return true
  3405. }
  3406. state.pos = start;
  3407. }
  3408. // Lookahead / Lookbehind
  3409. if (state.eat(0x28 /* ( */) && state.eat(0x3F /* ? */)) {
  3410. var lookbehind = false;
  3411. if (this.options.ecmaVersion >= 9) {
  3412. lookbehind = state.eat(0x3C /* < */);
  3413. }
  3414. if (state.eat(0x3D /* = */) || state.eat(0x21 /* ! */)) {
  3415. this.regexp_disjunction(state);
  3416. if (!state.eat(0x29 /* ) */)) {
  3417. state.raise("Unterminated group");
  3418. }
  3419. state.lastAssertionIsQuantifiable = !lookbehind;
  3420. return true
  3421. }
  3422. }
  3423. state.pos = start;
  3424. return false
  3425. };
  3426. // https://www.ecma-international.org/ecma-262/8.0/#prod-Quantifier
  3427. pp$1.regexp_eatQuantifier = function(state, noError) {
  3428. if ( noError === void 0 ) noError = false;
  3429. if (this.regexp_eatQuantifierPrefix(state, noError)) {
  3430. state.eat(0x3F /* ? */);
  3431. return true
  3432. }
  3433. return false
  3434. };
  3435. // https://www.ecma-international.org/ecma-262/8.0/#prod-QuantifierPrefix
  3436. pp$1.regexp_eatQuantifierPrefix = function(state, noError) {
  3437. return (
  3438. state.eat(0x2A /* * */) ||
  3439. state.eat(0x2B /* + */) ||
  3440. state.eat(0x3F /* ? */) ||
  3441. this.regexp_eatBracedQuantifier(state, noError)
  3442. )
  3443. };
  3444. pp$1.regexp_eatBracedQuantifier = function(state, noError) {
  3445. var start = state.pos;
  3446. if (state.eat(0x7B /* { */)) {
  3447. var min = 0, max = -1;
  3448. if (this.regexp_eatDecimalDigits(state)) {
  3449. min = state.lastIntValue;
  3450. if (state.eat(0x2C /* , */) && this.regexp_eatDecimalDigits(state)) {
  3451. max = state.lastIntValue;
  3452. }
  3453. if (state.eat(0x7D /* } */)) {
  3454. // SyntaxError in https://www.ecma-international.org/ecma-262/8.0/#sec-term
  3455. if (max !== -1 && max < min && !noError) {
  3456. state.raise("numbers out of order in {} quantifier");
  3457. }
  3458. return true
  3459. }
  3460. }
  3461. if (state.switchU && !noError) {
  3462. state.raise("Incomplete quantifier");
  3463. }
  3464. state.pos = start;
  3465. }
  3466. return false
  3467. };
  3468. // https://www.ecma-international.org/ecma-262/8.0/#prod-Atom
  3469. pp$1.regexp_eatAtom = function(state) {
  3470. return (
  3471. this.regexp_eatPatternCharacters(state) ||
  3472. state.eat(0x2E /* . */) ||
  3473. this.regexp_eatReverseSolidusAtomEscape(state) ||
  3474. this.regexp_eatCharacterClass(state) ||
  3475. this.regexp_eatUncapturingGroup(state) ||
  3476. this.regexp_eatCapturingGroup(state)
  3477. )
  3478. };
  3479. pp$1.regexp_eatReverseSolidusAtomEscape = function(state) {
  3480. var start = state.pos;
  3481. if (state.eat(0x5C /* \ */)) {
  3482. if (this.regexp_eatAtomEscape(state)) {
  3483. return true
  3484. }
  3485. state.pos = start;
  3486. }
  3487. return false
  3488. };
  3489. pp$1.regexp_eatUncapturingGroup = function(state) {
  3490. var start = state.pos;
  3491. if (state.eat(0x28 /* ( */)) {
  3492. if (state.eat(0x3F /* ? */) && state.eat(0x3A /* : */)) {
  3493. this.regexp_disjunction(state);
  3494. if (state.eat(0x29 /* ) */)) {
  3495. return true
  3496. }
  3497. state.raise("Unterminated group");
  3498. }
  3499. state.pos = start;
  3500. }
  3501. return false
  3502. };
  3503. pp$1.regexp_eatCapturingGroup = function(state) {
  3504. if (state.eat(0x28 /* ( */)) {
  3505. if (this.options.ecmaVersion >= 9) {
  3506. this.regexp_groupSpecifier(state);
  3507. } else if (state.current() === 0x3F /* ? */) {
  3508. state.raise("Invalid group");
  3509. }
  3510. this.regexp_disjunction(state);
  3511. if (state.eat(0x29 /* ) */)) {
  3512. state.numCapturingParens += 1;
  3513. return true
  3514. }
  3515. state.raise("Unterminated group");
  3516. }
  3517. return false
  3518. };
  3519. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-ExtendedAtom
  3520. pp$1.regexp_eatExtendedAtom = function(state) {
  3521. return (
  3522. state.eat(0x2E /* . */) ||
  3523. this.regexp_eatReverseSolidusAtomEscape(state) ||
  3524. this.regexp_eatCharacterClass(state) ||
  3525. this.regexp_eatUncapturingGroup(state) ||
  3526. this.regexp_eatCapturingGroup(state) ||
  3527. this.regexp_eatInvalidBracedQuantifier(state) ||
  3528. this.regexp_eatExtendedPatternCharacter(state)
  3529. )
  3530. };
  3531. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-InvalidBracedQuantifier
  3532. pp$1.regexp_eatInvalidBracedQuantifier = function(state) {
  3533. if (this.regexp_eatBracedQuantifier(state, true)) {
  3534. state.raise("Nothing to repeat");
  3535. }
  3536. return false
  3537. };
  3538. // https://www.ecma-international.org/ecma-262/8.0/#prod-SyntaxCharacter
  3539. pp$1.regexp_eatSyntaxCharacter = function(state) {
  3540. var ch = state.current();
  3541. if (isSyntaxCharacter(ch)) {
  3542. state.lastIntValue = ch;
  3543. state.advance();
  3544. return true
  3545. }
  3546. return false
  3547. };
  3548. function isSyntaxCharacter(ch) {
  3549. return (
  3550. ch === 0x24 /* $ */ ||
  3551. ch >= 0x28 /* ( */ && ch <= 0x2B /* + */ ||
  3552. ch === 0x2E /* . */ ||
  3553. ch === 0x3F /* ? */ ||
  3554. ch >= 0x5B /* [ */ && ch <= 0x5E /* ^ */ ||
  3555. ch >= 0x7B /* { */ && ch <= 0x7D /* } */
  3556. )
  3557. }
  3558. // https://www.ecma-international.org/ecma-262/8.0/#prod-PatternCharacter
  3559. // But eat eager.
  3560. pp$1.regexp_eatPatternCharacters = function(state) {
  3561. var start = state.pos;
  3562. var ch = 0;
  3563. while ((ch = state.current()) !== -1 && !isSyntaxCharacter(ch)) {
  3564. state.advance();
  3565. }
  3566. return state.pos !== start
  3567. };
  3568. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-ExtendedPatternCharacter
  3569. pp$1.regexp_eatExtendedPatternCharacter = function(state) {
  3570. var ch = state.current();
  3571. if (
  3572. ch !== -1 &&
  3573. ch !== 0x24 /* $ */ &&
  3574. !(ch >= 0x28 /* ( */ && ch <= 0x2B /* + */) &&
  3575. ch !== 0x2E /* . */ &&
  3576. ch !== 0x3F /* ? */ &&
  3577. ch !== 0x5B /* [ */ &&
  3578. ch !== 0x5E /* ^ */ &&
  3579. ch !== 0x7C /* | */
  3580. ) {
  3581. state.advance();
  3582. return true
  3583. }
  3584. return false
  3585. };
  3586. // GroupSpecifier ::
  3587. // [empty]
  3588. // `?` GroupName
  3589. pp$1.regexp_groupSpecifier = function(state) {
  3590. if (state.eat(0x3F /* ? */)) {
  3591. if (this.regexp_eatGroupName(state)) {
  3592. if (state.groupNames.indexOf(state.lastStringValue) !== -1) {
  3593. state.raise("Duplicate capture group name");
  3594. }
  3595. state.groupNames.push(state.lastStringValue);
  3596. return
  3597. }
  3598. state.raise("Invalid group");
  3599. }
  3600. };
  3601. // GroupName ::
  3602. // `<` RegExpIdentifierName `>`
  3603. // Note: this updates `state.lastStringValue` property with the eaten name.
  3604. pp$1.regexp_eatGroupName = function(state) {
  3605. state.lastStringValue = "";
  3606. if (state.eat(0x3C /* < */)) {
  3607. if (this.regexp_eatRegExpIdentifierName(state) && state.eat(0x3E /* > */)) {
  3608. return true
  3609. }
  3610. state.raise("Invalid capture group name");
  3611. }
  3612. return false
  3613. };
  3614. // RegExpIdentifierName ::
  3615. // RegExpIdentifierStart
  3616. // RegExpIdentifierName RegExpIdentifierPart
  3617. // Note: this updates `state.lastStringValue` property with the eaten name.
  3618. pp$1.regexp_eatRegExpIdentifierName = function(state) {
  3619. state.lastStringValue = "";
  3620. if (this.regexp_eatRegExpIdentifierStart(state)) {
  3621. state.lastStringValue += codePointToString$1(state.lastIntValue);
  3622. while (this.regexp_eatRegExpIdentifierPart(state)) {
  3623. state.lastStringValue += codePointToString$1(state.lastIntValue);
  3624. }
  3625. return true
  3626. }
  3627. return false
  3628. };
  3629. // RegExpIdentifierStart ::
  3630. // UnicodeIDStart
  3631. // `$`
  3632. // `_`
  3633. // `\` RegExpUnicodeEscapeSequence[+U]
  3634. pp$1.regexp_eatRegExpIdentifierStart = function(state) {
  3635. var start = state.pos;
  3636. var forceU = this.options.ecmaVersion >= 11;
  3637. var ch = state.current(forceU);
  3638. state.advance(forceU);
  3639. if (ch === 0x5C /* \ */ && this.regexp_eatRegExpUnicodeEscapeSequence(state, forceU)) {
  3640. ch = state.lastIntValue;
  3641. }
  3642. if (isRegExpIdentifierStart(ch)) {
  3643. state.lastIntValue = ch;
  3644. return true
  3645. }
  3646. state.pos = start;
  3647. return false
  3648. };
  3649. function isRegExpIdentifierStart(ch) {
  3650. return isIdentifierStart(ch, true) || ch === 0x24 /* $ */ || ch === 0x5F /* _ */
  3651. }
  3652. // RegExpIdentifierPart ::
  3653. // UnicodeIDContinue
  3654. // `$`
  3655. // `_`
  3656. // `\` RegExpUnicodeEscapeSequence[+U]
  3657. // <ZWNJ>
  3658. // <ZWJ>
  3659. pp$1.regexp_eatRegExpIdentifierPart = function(state) {
  3660. var start = state.pos;
  3661. var forceU = this.options.ecmaVersion >= 11;
  3662. var ch = state.current(forceU);
  3663. state.advance(forceU);
  3664. if (ch === 0x5C /* \ */ && this.regexp_eatRegExpUnicodeEscapeSequence(state, forceU)) {
  3665. ch = state.lastIntValue;
  3666. }
  3667. if (isRegExpIdentifierPart(ch)) {
  3668. state.lastIntValue = ch;
  3669. return true
  3670. }
  3671. state.pos = start;
  3672. return false
  3673. };
  3674. function isRegExpIdentifierPart(ch) {
  3675. return isIdentifierChar(ch, true) || ch === 0x24 /* $ */ || ch === 0x5F /* _ */ || ch === 0x200C /* <ZWNJ> */ || ch === 0x200D /* <ZWJ> */
  3676. }
  3677. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-AtomEscape
  3678. pp$1.regexp_eatAtomEscape = function(state) {
  3679. if (
  3680. this.regexp_eatBackReference(state) ||
  3681. this.regexp_eatCharacterClassEscape(state) ||
  3682. this.regexp_eatCharacterEscape(state) ||
  3683. (state.switchN && this.regexp_eatKGroupName(state))
  3684. ) {
  3685. return true
  3686. }
  3687. if (state.switchU) {
  3688. // Make the same message as V8.
  3689. if (state.current() === 0x63 /* c */) {
  3690. state.raise("Invalid unicode escape");
  3691. }
  3692. state.raise("Invalid escape");
  3693. }
  3694. return false
  3695. };
  3696. pp$1.regexp_eatBackReference = function(state) {
  3697. var start = state.pos;
  3698. if (this.regexp_eatDecimalEscape(state)) {
  3699. var n = state.lastIntValue;
  3700. if (state.switchU) {
  3701. // For SyntaxError in https://www.ecma-international.org/ecma-262/8.0/#sec-atomescape
  3702. if (n > state.maxBackReference) {
  3703. state.maxBackReference = n;
  3704. }
  3705. return true
  3706. }
  3707. if (n <= state.numCapturingParens) {
  3708. return true
  3709. }
  3710. state.pos = start;
  3711. }
  3712. return false
  3713. };
  3714. pp$1.regexp_eatKGroupName = function(state) {
  3715. if (state.eat(0x6B /* k */)) {
  3716. if (this.regexp_eatGroupName(state)) {
  3717. state.backReferenceNames.push(state.lastStringValue);
  3718. return true
  3719. }
  3720. state.raise("Invalid named reference");
  3721. }
  3722. return false
  3723. };
  3724. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-CharacterEscape
  3725. pp$1.regexp_eatCharacterEscape = function(state) {
  3726. return (
  3727. this.regexp_eatControlEscape(state) ||
  3728. this.regexp_eatCControlLetter(state) ||
  3729. this.regexp_eatZero(state) ||
  3730. this.regexp_eatHexEscapeSequence(state) ||
  3731. this.regexp_eatRegExpUnicodeEscapeSequence(state, false) ||
  3732. (!state.switchU && this.regexp_eatLegacyOctalEscapeSequence(state)) ||
  3733. this.regexp_eatIdentityEscape(state)
  3734. )
  3735. };
  3736. pp$1.regexp_eatCControlLetter = function(state) {
  3737. var start = state.pos;
  3738. if (state.eat(0x63 /* c */)) {
  3739. if (this.regexp_eatControlLetter(state)) {
  3740. return true
  3741. }
  3742. state.pos = start;
  3743. }
  3744. return false
  3745. };
  3746. pp$1.regexp_eatZero = function(state) {
  3747. if (state.current() === 0x30 /* 0 */ && !isDecimalDigit(state.lookahead())) {
  3748. state.lastIntValue = 0;
  3749. state.advance();
  3750. return true
  3751. }
  3752. return false
  3753. };
  3754. // https://www.ecma-international.org/ecma-262/8.0/#prod-ControlEscape
  3755. pp$1.regexp_eatControlEscape = function(state) {
  3756. var ch = state.current();
  3757. if (ch === 0x74 /* t */) {
  3758. state.lastIntValue = 0x09; /* \t */
  3759. state.advance();
  3760. return true
  3761. }
  3762. if (ch === 0x6E /* n */) {
  3763. state.lastIntValue = 0x0A; /* \n */
  3764. state.advance();
  3765. return true
  3766. }
  3767. if (ch === 0x76 /* v */) {
  3768. state.lastIntValue = 0x0B; /* \v */
  3769. state.advance();
  3770. return true
  3771. }
  3772. if (ch === 0x66 /* f */) {
  3773. state.lastIntValue = 0x0C; /* \f */
  3774. state.advance();
  3775. return true
  3776. }
  3777. if (ch === 0x72 /* r */) {
  3778. state.lastIntValue = 0x0D; /* \r */
  3779. state.advance();
  3780. return true
  3781. }
  3782. return false
  3783. };
  3784. // https://www.ecma-international.org/ecma-262/8.0/#prod-ControlLetter
  3785. pp$1.regexp_eatControlLetter = function(state) {
  3786. var ch = state.current();
  3787. if (isControlLetter(ch)) {
  3788. state.lastIntValue = ch % 0x20;
  3789. state.advance();
  3790. return true
  3791. }
  3792. return false
  3793. };
  3794. function isControlLetter(ch) {
  3795. return (
  3796. (ch >= 0x41 /* A */ && ch <= 0x5A /* Z */) ||
  3797. (ch >= 0x61 /* a */ && ch <= 0x7A /* z */)
  3798. )
  3799. }
  3800. // https://www.ecma-international.org/ecma-262/8.0/#prod-RegExpUnicodeEscapeSequence
  3801. pp$1.regexp_eatRegExpUnicodeEscapeSequence = function(state, forceU) {
  3802. if ( forceU === void 0 ) forceU = false;
  3803. var start = state.pos;
  3804. var switchU = forceU || state.switchU;
  3805. if (state.eat(0x75 /* u */)) {
  3806. if (this.regexp_eatFixedHexDigits(state, 4)) {
  3807. var lead = state.lastIntValue;
  3808. if (switchU && lead >= 0xD800 && lead <= 0xDBFF) {
  3809. var leadSurrogateEnd = state.pos;
  3810. if (state.eat(0x5C /* \ */) && state.eat(0x75 /* u */) && this.regexp_eatFixedHexDigits(state, 4)) {
  3811. var trail = state.lastIntValue;
  3812. if (trail >= 0xDC00 && trail <= 0xDFFF) {
  3813. state.lastIntValue = (lead - 0xD800) * 0x400 + (trail - 0xDC00) + 0x10000;
  3814. return true
  3815. }
  3816. }
  3817. state.pos = leadSurrogateEnd;
  3818. state.lastIntValue = lead;
  3819. }
  3820. return true
  3821. }
  3822. if (
  3823. switchU &&
  3824. state.eat(0x7B /* { */) &&
  3825. this.regexp_eatHexDigits(state) &&
  3826. state.eat(0x7D /* } */) &&
  3827. isValidUnicode(state.lastIntValue)
  3828. ) {
  3829. return true
  3830. }
  3831. if (switchU) {
  3832. state.raise("Invalid unicode escape");
  3833. }
  3834. state.pos = start;
  3835. }
  3836. return false
  3837. };
  3838. function isValidUnicode(ch) {
  3839. return ch >= 0 && ch <= 0x10FFFF
  3840. }
  3841. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-IdentityEscape
  3842. pp$1.regexp_eatIdentityEscape = function(state) {
  3843. if (state.switchU) {
  3844. if (this.regexp_eatSyntaxCharacter(state)) {
  3845. return true
  3846. }
  3847. if (state.eat(0x2F /* / */)) {
  3848. state.lastIntValue = 0x2F; /* / */
  3849. return true
  3850. }
  3851. return false
  3852. }
  3853. var ch = state.current();
  3854. if (ch !== 0x63 /* c */ && (!state.switchN || ch !== 0x6B /* k */)) {
  3855. state.lastIntValue = ch;
  3856. state.advance();
  3857. return true
  3858. }
  3859. return false
  3860. };
  3861. // https://www.ecma-international.org/ecma-262/8.0/#prod-DecimalEscape
  3862. pp$1.regexp_eatDecimalEscape = function(state) {
  3863. state.lastIntValue = 0;
  3864. var ch = state.current();
  3865. if (ch >= 0x31 /* 1 */ && ch <= 0x39 /* 9 */) {
  3866. do {
  3867. state.lastIntValue = 10 * state.lastIntValue + (ch - 0x30 /* 0 */);
  3868. state.advance();
  3869. } while ((ch = state.current()) >= 0x30 /* 0 */ && ch <= 0x39 /* 9 */)
  3870. return true
  3871. }
  3872. return false
  3873. };
  3874. // https://www.ecma-international.org/ecma-262/8.0/#prod-CharacterClassEscape
  3875. pp$1.regexp_eatCharacterClassEscape = function(state) {
  3876. var ch = state.current();
  3877. if (isCharacterClassEscape(ch)) {
  3878. state.lastIntValue = -1;
  3879. state.advance();
  3880. return true
  3881. }
  3882. if (
  3883. state.switchU &&
  3884. this.options.ecmaVersion >= 9 &&
  3885. (ch === 0x50 /* P */ || ch === 0x70 /* p */)
  3886. ) {
  3887. state.lastIntValue = -1;
  3888. state.advance();
  3889. if (
  3890. state.eat(0x7B /* { */) &&
  3891. this.regexp_eatUnicodePropertyValueExpression(state) &&
  3892. state.eat(0x7D /* } */)
  3893. ) {
  3894. return true
  3895. }
  3896. state.raise("Invalid property name");
  3897. }
  3898. return false
  3899. };
  3900. function isCharacterClassEscape(ch) {
  3901. return (
  3902. ch === 0x64 /* d */ ||
  3903. ch === 0x44 /* D */ ||
  3904. ch === 0x73 /* s */ ||
  3905. ch === 0x53 /* S */ ||
  3906. ch === 0x77 /* w */ ||
  3907. ch === 0x57 /* W */
  3908. )
  3909. }
  3910. // UnicodePropertyValueExpression ::
  3911. // UnicodePropertyName `=` UnicodePropertyValue
  3912. // LoneUnicodePropertyNameOrValue
  3913. pp$1.regexp_eatUnicodePropertyValueExpression = function(state) {
  3914. var start = state.pos;
  3915. // UnicodePropertyName `=` UnicodePropertyValue
  3916. if (this.regexp_eatUnicodePropertyName(state) && state.eat(0x3D /* = */)) {
  3917. var name = state.lastStringValue;
  3918. if (this.regexp_eatUnicodePropertyValue(state)) {
  3919. var value = state.lastStringValue;
  3920. this.regexp_validateUnicodePropertyNameAndValue(state, name, value);
  3921. return true
  3922. }
  3923. }
  3924. state.pos = start;
  3925. // LoneUnicodePropertyNameOrValue
  3926. if (this.regexp_eatLoneUnicodePropertyNameOrValue(state)) {
  3927. var nameOrValue = state.lastStringValue;
  3928. this.regexp_validateUnicodePropertyNameOrValue(state, nameOrValue);
  3929. return true
  3930. }
  3931. return false
  3932. };
  3933. pp$1.regexp_validateUnicodePropertyNameAndValue = function(state, name, value) {
  3934. if (!hasOwn(state.unicodeProperties.nonBinary, name))
  3935. { state.raise("Invalid property name"); }
  3936. if (!state.unicodeProperties.nonBinary[name].test(value))
  3937. { state.raise("Invalid property value"); }
  3938. };
  3939. pp$1.regexp_validateUnicodePropertyNameOrValue = function(state, nameOrValue) {
  3940. if (!state.unicodeProperties.binary.test(nameOrValue))
  3941. { state.raise("Invalid property name"); }
  3942. };
  3943. // UnicodePropertyName ::
  3944. // UnicodePropertyNameCharacters
  3945. pp$1.regexp_eatUnicodePropertyName = function(state) {
  3946. var ch = 0;
  3947. state.lastStringValue = "";
  3948. while (isUnicodePropertyNameCharacter(ch = state.current())) {
  3949. state.lastStringValue += codePointToString$1(ch);
  3950. state.advance();
  3951. }
  3952. return state.lastStringValue !== ""
  3953. };
  3954. function isUnicodePropertyNameCharacter(ch) {
  3955. return isControlLetter(ch) || ch === 0x5F /* _ */
  3956. }
  3957. // UnicodePropertyValue ::
  3958. // UnicodePropertyValueCharacters
  3959. pp$1.regexp_eatUnicodePropertyValue = function(state) {
  3960. var ch = 0;
  3961. state.lastStringValue = "";
  3962. while (isUnicodePropertyValueCharacter(ch = state.current())) {
  3963. state.lastStringValue += codePointToString$1(ch);
  3964. state.advance();
  3965. }
  3966. return state.lastStringValue !== ""
  3967. };
  3968. function isUnicodePropertyValueCharacter(ch) {
  3969. return isUnicodePropertyNameCharacter(ch) || isDecimalDigit(ch)
  3970. }
  3971. // LoneUnicodePropertyNameOrValue ::
  3972. // UnicodePropertyValueCharacters
  3973. pp$1.regexp_eatLoneUnicodePropertyNameOrValue = function(state) {
  3974. return this.regexp_eatUnicodePropertyValue(state)
  3975. };
  3976. // https://www.ecma-international.org/ecma-262/8.0/#prod-CharacterClass
  3977. pp$1.regexp_eatCharacterClass = function(state) {
  3978. if (state.eat(0x5B /* [ */)) {
  3979. state.eat(0x5E /* ^ */);
  3980. this.regexp_classRanges(state);
  3981. if (state.eat(0x5D /* ] */)) {
  3982. return true
  3983. }
  3984. // Unreachable since it threw "unterminated regular expression" error before.
  3985. state.raise("Unterminated character class");
  3986. }
  3987. return false
  3988. };
  3989. // https://www.ecma-international.org/ecma-262/8.0/#prod-ClassRanges
  3990. // https://www.ecma-international.org/ecma-262/8.0/#prod-NonemptyClassRanges
  3991. // https://www.ecma-international.org/ecma-262/8.0/#prod-NonemptyClassRangesNoDash
  3992. pp$1.regexp_classRanges = function(state) {
  3993. while (this.regexp_eatClassAtom(state)) {
  3994. var left = state.lastIntValue;
  3995. if (state.eat(0x2D /* - */) && this.regexp_eatClassAtom(state)) {
  3996. var right = state.lastIntValue;
  3997. if (state.switchU && (left === -1 || right === -1)) {
  3998. state.raise("Invalid character class");
  3999. }
  4000. if (left !== -1 && right !== -1 && left > right) {
  4001. state.raise("Range out of order in character class");
  4002. }
  4003. }
  4004. }
  4005. };
  4006. // https://www.ecma-international.org/ecma-262/8.0/#prod-ClassAtom
  4007. // https://www.ecma-international.org/ecma-262/8.0/#prod-ClassAtomNoDash
  4008. pp$1.regexp_eatClassAtom = function(state) {
  4009. var start = state.pos;
  4010. if (state.eat(0x5C /* \ */)) {
  4011. if (this.regexp_eatClassEscape(state)) {
  4012. return true
  4013. }
  4014. if (state.switchU) {
  4015. // Make the same message as V8.
  4016. var ch$1 = state.current();
  4017. if (ch$1 === 0x63 /* c */ || isOctalDigit(ch$1)) {
  4018. state.raise("Invalid class escape");
  4019. }
  4020. state.raise("Invalid escape");
  4021. }
  4022. state.pos = start;
  4023. }
  4024. var ch = state.current();
  4025. if (ch !== 0x5D /* ] */) {
  4026. state.lastIntValue = ch;
  4027. state.advance();
  4028. return true
  4029. }
  4030. return false
  4031. };
  4032. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-ClassEscape
  4033. pp$1.regexp_eatClassEscape = function(state) {
  4034. var start = state.pos;
  4035. if (state.eat(0x62 /* b */)) {
  4036. state.lastIntValue = 0x08; /* <BS> */
  4037. return true
  4038. }
  4039. if (state.switchU && state.eat(0x2D /* - */)) {
  4040. state.lastIntValue = 0x2D; /* - */
  4041. return true
  4042. }
  4043. if (!state.switchU && state.eat(0x63 /* c */)) {
  4044. if (this.regexp_eatClassControlLetter(state)) {
  4045. return true
  4046. }
  4047. state.pos = start;
  4048. }
  4049. return (
  4050. this.regexp_eatCharacterClassEscape(state) ||
  4051. this.regexp_eatCharacterEscape(state)
  4052. )
  4053. };
  4054. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-ClassControlLetter
  4055. pp$1.regexp_eatClassControlLetter = function(state) {
  4056. var ch = state.current();
  4057. if (isDecimalDigit(ch) || ch === 0x5F /* _ */) {
  4058. state.lastIntValue = ch % 0x20;
  4059. state.advance();
  4060. return true
  4061. }
  4062. return false
  4063. };
  4064. // https://www.ecma-international.org/ecma-262/8.0/#prod-HexEscapeSequence
  4065. pp$1.regexp_eatHexEscapeSequence = function(state) {
  4066. var start = state.pos;
  4067. if (state.eat(0x78 /* x */)) {
  4068. if (this.regexp_eatFixedHexDigits(state, 2)) {
  4069. return true
  4070. }
  4071. if (state.switchU) {
  4072. state.raise("Invalid escape");
  4073. }
  4074. state.pos = start;
  4075. }
  4076. return false
  4077. };
  4078. // https://www.ecma-international.org/ecma-262/8.0/#prod-DecimalDigits
  4079. pp$1.regexp_eatDecimalDigits = function(state) {
  4080. var start = state.pos;
  4081. var ch = 0;
  4082. state.lastIntValue = 0;
  4083. while (isDecimalDigit(ch = state.current())) {
  4084. state.lastIntValue = 10 * state.lastIntValue + (ch - 0x30 /* 0 */);
  4085. state.advance();
  4086. }
  4087. return state.pos !== start
  4088. };
  4089. function isDecimalDigit(ch) {
  4090. return ch >= 0x30 /* 0 */ && ch <= 0x39 /* 9 */
  4091. }
  4092. // https://www.ecma-international.org/ecma-262/8.0/#prod-HexDigits
  4093. pp$1.regexp_eatHexDigits = function(state) {
  4094. var start = state.pos;
  4095. var ch = 0;
  4096. state.lastIntValue = 0;
  4097. while (isHexDigit(ch = state.current())) {
  4098. state.lastIntValue = 16 * state.lastIntValue + hexToInt(ch);
  4099. state.advance();
  4100. }
  4101. return state.pos !== start
  4102. };
  4103. function isHexDigit(ch) {
  4104. return (
  4105. (ch >= 0x30 /* 0 */ && ch <= 0x39 /* 9 */) ||
  4106. (ch >= 0x41 /* A */ && ch <= 0x46 /* F */) ||
  4107. (ch >= 0x61 /* a */ && ch <= 0x66 /* f */)
  4108. )
  4109. }
  4110. function hexToInt(ch) {
  4111. if (ch >= 0x41 /* A */ && ch <= 0x46 /* F */) {
  4112. return 10 + (ch - 0x41 /* A */)
  4113. }
  4114. if (ch >= 0x61 /* a */ && ch <= 0x66 /* f */) {
  4115. return 10 + (ch - 0x61 /* a */)
  4116. }
  4117. return ch - 0x30 /* 0 */
  4118. }
  4119. // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-LegacyOctalEscapeSequence
  4120. // Allows only 0-377(octal) i.e. 0-255(decimal).
  4121. pp$1.regexp_eatLegacyOctalEscapeSequence = function(state) {
  4122. if (this.regexp_eatOctalDigit(state)) {
  4123. var n1 = state.lastIntValue;
  4124. if (this.regexp_eatOctalDigit(state)) {
  4125. var n2 = state.lastIntValue;
  4126. if (n1 <= 3 && this.regexp_eatOctalDigit(state)) {
  4127. state.lastIntValue = n1 * 64 + n2 * 8 + state.lastIntValue;
  4128. } else {
  4129. state.lastIntValue = n1 * 8 + n2;
  4130. }
  4131. } else {
  4132. state.lastIntValue = n1;
  4133. }
  4134. return true
  4135. }
  4136. return false
  4137. };
  4138. // https://www.ecma-international.org/ecma-262/8.0/#prod-OctalDigit
  4139. pp$1.regexp_eatOctalDigit = function(state) {
  4140. var ch = state.current();
  4141. if (isOctalDigit(ch)) {
  4142. state.lastIntValue = ch - 0x30; /* 0 */
  4143. state.advance();
  4144. return true
  4145. }
  4146. state.lastIntValue = 0;
  4147. return false
  4148. };
  4149. function isOctalDigit(ch) {
  4150. return ch >= 0x30 /* 0 */ && ch <= 0x37 /* 7 */
  4151. }
  4152. // https://www.ecma-international.org/ecma-262/8.0/#prod-Hex4Digits
  4153. // https://www.ecma-international.org/ecma-262/8.0/#prod-HexDigit
  4154. // And HexDigit HexDigit in https://www.ecma-international.org/ecma-262/8.0/#prod-HexEscapeSequence
  4155. pp$1.regexp_eatFixedHexDigits = function(state, length) {
  4156. var start = state.pos;
  4157. state.lastIntValue = 0;
  4158. for (var i = 0; i < length; ++i) {
  4159. var ch = state.current();
  4160. if (!isHexDigit(ch)) {
  4161. state.pos = start;
  4162. return false
  4163. }
  4164. state.lastIntValue = 16 * state.lastIntValue + hexToInt(ch);
  4165. state.advance();
  4166. }
  4167. return true
  4168. };
  4169. // Object type used to represent tokens. Note that normally, tokens
  4170. // simply exist as properties on the parser object. This is only
  4171. // used for the onToken callback and the external tokenizer.
  4172. var Token = function Token(p) {
  4173. this.type = p.type;
  4174. this.value = p.value;
  4175. this.start = p.start;
  4176. this.end = p.end;
  4177. if (p.options.locations)
  4178. { this.loc = new SourceLocation(p, p.startLoc, p.endLoc); }
  4179. if (p.options.ranges)
  4180. { this.range = [p.start, p.end]; }
  4181. };
  4182. // ## Tokenizer
  4183. var pp = Parser.prototype;
  4184. // Move to the next token
  4185. pp.next = function(ignoreEscapeSequenceInKeyword) {
  4186. if (!ignoreEscapeSequenceInKeyword && this.type.keyword && this.containsEsc)
  4187. { this.raiseRecoverable(this.start, "Escape sequence in keyword " + this.type.keyword); }
  4188. if (this.options.onToken)
  4189. { this.options.onToken(new Token(this)); }
  4190. this.lastTokEnd = this.end;
  4191. this.lastTokStart = this.start;
  4192. this.lastTokEndLoc = this.endLoc;
  4193. this.lastTokStartLoc = this.startLoc;
  4194. this.nextToken();
  4195. };
  4196. pp.getToken = function() {
  4197. this.next();
  4198. return new Token(this)
  4199. };
  4200. // If we're in an ES6 environment, make parsers iterable
  4201. if (typeof Symbol !== "undefined")
  4202. { pp[Symbol.iterator] = function() {
  4203. var this$1$1 = this;
  4204. return {
  4205. next: function () {
  4206. var token = this$1$1.getToken();
  4207. return {
  4208. done: token.type === types$1.eof,
  4209. value: token
  4210. }
  4211. }
  4212. }
  4213. }; }
  4214. // Toggle strict mode. Re-reads the next number or string to please
  4215. // pedantic tests (`"use strict"; 010;` should fail).
  4216. // Read a single token, updating the parser object's token-related
  4217. // properties.
  4218. pp.nextToken = function() {
  4219. var curContext = this.curContext();
  4220. if (!curContext || !curContext.preserveSpace) { this.skipSpace(); }
  4221. this.start = this.pos;
  4222. if (this.options.locations) { this.startLoc = this.curPosition(); }
  4223. if (this.pos >= this.input.length) { return this.finishToken(types$1.eof) }
  4224. if (curContext.override) { return curContext.override(this) }
  4225. else { this.readToken(this.fullCharCodeAtPos()); }
  4226. };
  4227. pp.readToken = function(code) {
  4228. // Identifier or keyword. '\uXXXX' sequences are allowed in
  4229. // identifiers, so '\' also dispatches to that.
  4230. if (isIdentifierStart(code, this.options.ecmaVersion >= 6) || code === 92 /* '\' */)
  4231. { return this.readWord() }
  4232. return this.getTokenFromCode(code)
  4233. };
  4234. pp.fullCharCodeAtPos = function() {
  4235. var code = this.input.charCodeAt(this.pos);
  4236. if (code <= 0xd7ff || code >= 0xdc00) { return code }
  4237. var next = this.input.charCodeAt(this.pos + 1);
  4238. return next <= 0xdbff || next >= 0xe000 ? code : (code << 10) + next - 0x35fdc00
  4239. };
  4240. pp.skipBlockComment = function() {
  4241. var startLoc = this.options.onComment && this.curPosition();
  4242. var start = this.pos, end = this.input.indexOf("*/", this.pos += 2);
  4243. if (end === -1) { this.raise(this.pos - 2, "Unterminated comment"); }
  4244. this.pos = end + 2;
  4245. if (this.options.locations) {
  4246. for (var nextBreak = (void 0), pos = start; (nextBreak = nextLineBreak(this.input, pos, this.pos)) > -1;) {
  4247. ++this.curLine;
  4248. pos = this.lineStart = nextBreak;
  4249. }
  4250. }
  4251. if (this.options.onComment)
  4252. { this.options.onComment(true, this.input.slice(start + 2, end), start, this.pos,
  4253. startLoc, this.curPosition()); }
  4254. };
  4255. pp.skipLineComment = function(startSkip) {
  4256. var start = this.pos;
  4257. var startLoc = this.options.onComment && this.curPosition();
  4258. var ch = this.input.charCodeAt(this.pos += startSkip);
  4259. while (this.pos < this.input.length && !isNewLine(ch)) {
  4260. ch = this.input.charCodeAt(++this.pos);
  4261. }
  4262. if (this.options.onComment)
  4263. { this.options.onComment(false, this.input.slice(start + startSkip, this.pos), start, this.pos,
  4264. startLoc, this.curPosition()); }
  4265. };
  4266. // Called at the start of the parse and after every token. Skips
  4267. // whitespace and comments, and.
  4268. pp.skipSpace = function() {
  4269. loop: while (this.pos < this.input.length) {
  4270. var ch = this.input.charCodeAt(this.pos);
  4271. switch (ch) {
  4272. case 32: case 160: // ' '
  4273. ++this.pos;
  4274. break
  4275. case 13:
  4276. if (this.input.charCodeAt(this.pos + 1) === 10) {
  4277. ++this.pos;
  4278. }
  4279. case 10: case 8232: case 8233:
  4280. ++this.pos;
  4281. if (this.options.locations) {
  4282. ++this.curLine;
  4283. this.lineStart = this.pos;
  4284. }
  4285. break
  4286. case 47: // '/'
  4287. switch (this.input.charCodeAt(this.pos + 1)) {
  4288. case 42: // '*'
  4289. this.skipBlockComment();
  4290. break
  4291. case 47:
  4292. this.skipLineComment(2);
  4293. break
  4294. default:
  4295. break loop
  4296. }
  4297. break
  4298. default:
  4299. if (ch > 8 && ch < 14 || ch >= 5760 && nonASCIIwhitespace.test(String.fromCharCode(ch))) {
  4300. ++this.pos;
  4301. } else {
  4302. break loop
  4303. }
  4304. }
  4305. }
  4306. };
  4307. // Called at the end of every token. Sets `end`, `val`, and
  4308. // maintains `context` and `exprAllowed`, and skips the space after
  4309. // the token, so that the next one's `start` will point at the
  4310. // right position.
  4311. pp.finishToken = function(type, val) {
  4312. this.end = this.pos;
  4313. if (this.options.locations) { this.endLoc = this.curPosition(); }
  4314. var prevType = this.type;
  4315. this.type = type;
  4316. this.value = val;
  4317. this.updateContext(prevType);
  4318. };
  4319. // ### Token reading
  4320. // This is the function that is called to fetch the next token. It
  4321. // is somewhat obscure, because it works in character codes rather
  4322. // than characters, and because operator parsing has been inlined
  4323. // into it.
  4324. //
  4325. // All in the name of speed.
  4326. //
  4327. pp.readToken_dot = function() {
  4328. var next = this.input.charCodeAt(this.pos + 1);
  4329. if (next >= 48 && next <= 57) { return this.readNumber(true) }
  4330. var next2 = this.input.charCodeAt(this.pos + 2);
  4331. if (this.options.ecmaVersion >= 6 && next === 46 && next2 === 46) { // 46 = dot '.'
  4332. this.pos += 3;
  4333. return this.finishToken(types$1.ellipsis)
  4334. } else {
  4335. ++this.pos;
  4336. return this.finishToken(types$1.dot)
  4337. }
  4338. };
  4339. pp.readToken_slash = function() { // '/'
  4340. var next = this.input.charCodeAt(this.pos + 1);
  4341. if (this.exprAllowed) { ++this.pos; return this.readRegexp() }
  4342. if (next === 61) { return this.finishOp(types$1.assign, 2) }
  4343. return this.finishOp(types$1.slash, 1)
  4344. };
  4345. pp.readToken_mult_modulo_exp = function(code) { // '%*'
  4346. var next = this.input.charCodeAt(this.pos + 1);
  4347. var size = 1;
  4348. var tokentype = code === 42 ? types$1.star : types$1.modulo;
  4349. // exponentiation operator ** and **=
  4350. if (this.options.ecmaVersion >= 7 && code === 42 && next === 42) {
  4351. ++size;
  4352. tokentype = types$1.starstar;
  4353. next = this.input.charCodeAt(this.pos + 2);
  4354. }
  4355. if (next === 61) { return this.finishOp(types$1.assign, size + 1) }
  4356. return this.finishOp(tokentype, size)
  4357. };
  4358. pp.readToken_pipe_amp = function(code) { // '|&'
  4359. var next = this.input.charCodeAt(this.pos + 1);
  4360. if (next === code) {
  4361. if (this.options.ecmaVersion >= 12) {
  4362. var next2 = this.input.charCodeAt(this.pos + 2);
  4363. if (next2 === 61) { return this.finishOp(types$1.assign, 3) }
  4364. }
  4365. return this.finishOp(code === 124 ? types$1.logicalOR : types$1.logicalAND, 2)
  4366. }
  4367. if (next === 61) { return this.finishOp(types$1.assign, 2) }
  4368. return this.finishOp(code === 124 ? types$1.bitwiseOR : types$1.bitwiseAND, 1)
  4369. };
  4370. pp.readToken_caret = function() { // '^'
  4371. var next = this.input.charCodeAt(this.pos + 1);
  4372. if (next === 61) { return this.finishOp(types$1.assign, 2) }
  4373. return this.finishOp(types$1.bitwiseXOR, 1)
  4374. };
  4375. pp.readToken_plus_min = function(code) { // '+-'
  4376. var next = this.input.charCodeAt(this.pos + 1);
  4377. if (next === code) {
  4378. if (next === 45 && !this.inModule && this.input.charCodeAt(this.pos + 2) === 62 &&
  4379. (this.lastTokEnd === 0 || lineBreak.test(this.input.slice(this.lastTokEnd, this.pos)))) {
  4380. // A `-->` line comment
  4381. this.skipLineComment(3);
  4382. this.skipSpace();
  4383. return this.nextToken()
  4384. }
  4385. return this.finishOp(types$1.incDec, 2)
  4386. }
  4387. if (next === 61) { return this.finishOp(types$1.assign, 2) }
  4388. return this.finishOp(types$1.plusMin, 1)
  4389. };
  4390. pp.readToken_lt_gt = function(code) { // '<>'
  4391. var next = this.input.charCodeAt(this.pos + 1);
  4392. var size = 1;
  4393. if (next === code) {
  4394. size = code === 62 && this.input.charCodeAt(this.pos + 2) === 62 ? 3 : 2;
  4395. if (this.input.charCodeAt(this.pos + size) === 61) { return this.finishOp(types$1.assign, size + 1) }
  4396. return this.finishOp(types$1.bitShift, size)
  4397. }
  4398. if (next === 33 && code === 60 && !this.inModule && this.input.charCodeAt(this.pos + 2) === 45 &&
  4399. this.input.charCodeAt(this.pos + 3) === 45) {
  4400. // `<!--`, an XML-style comment that should be interpreted as a line comment
  4401. this.skipLineComment(4);
  4402. this.skipSpace();
  4403. return this.nextToken()
  4404. }
  4405. if (next === 61) { size = 2; }
  4406. return this.finishOp(types$1.relational, size)
  4407. };
  4408. pp.readToken_eq_excl = function(code) { // '=!'
  4409. var next = this.input.charCodeAt(this.pos + 1);
  4410. if (next === 61) { return this.finishOp(types$1.equality, this.input.charCodeAt(this.pos + 2) === 61 ? 3 : 2) }
  4411. if (code === 61 && next === 62 && this.options.ecmaVersion >= 6) { // '=>'
  4412. this.pos += 2;
  4413. return this.finishToken(types$1.arrow)
  4414. }
  4415. return this.finishOp(code === 61 ? types$1.eq : types$1.prefix, 1)
  4416. };
  4417. pp.readToken_question = function() { // '?'
  4418. var ecmaVersion = this.options.ecmaVersion;
  4419. if (ecmaVersion >= 11) {
  4420. var next = this.input.charCodeAt(this.pos + 1);
  4421. if (next === 46) {
  4422. var next2 = this.input.charCodeAt(this.pos + 2);
  4423. if (next2 < 48 || next2 > 57) { return this.finishOp(types$1.questionDot, 2) }
  4424. }
  4425. if (next === 63) {
  4426. if (ecmaVersion >= 12) {
  4427. var next2$1 = this.input.charCodeAt(this.pos + 2);
  4428. if (next2$1 === 61) { return this.finishOp(types$1.assign, 3) }
  4429. }
  4430. return this.finishOp(types$1.coalesce, 2)
  4431. }
  4432. }
  4433. return this.finishOp(types$1.question, 1)
  4434. };
  4435. pp.readToken_numberSign = function() { // '#'
  4436. var ecmaVersion = this.options.ecmaVersion;
  4437. var code = 35; // '#'
  4438. if (ecmaVersion >= 13) {
  4439. ++this.pos;
  4440. code = this.fullCharCodeAtPos();
  4441. if (isIdentifierStart(code, true) || code === 92 /* '\' */) {
  4442. return this.finishToken(types$1.privateId, this.readWord1())
  4443. }
  4444. }
  4445. this.raise(this.pos, "Unexpected character '" + codePointToString(code) + "'");
  4446. };
  4447. pp.getTokenFromCode = function(code) {
  4448. switch (code) {
  4449. // The interpretation of a dot depends on whether it is followed
  4450. // by a digit or another two dots.
  4451. case 46: // '.'
  4452. return this.readToken_dot()
  4453. // Punctuation tokens.
  4454. case 40: ++this.pos; return this.finishToken(types$1.parenL)
  4455. case 41: ++this.pos; return this.finishToken(types$1.parenR)
  4456. case 59: ++this.pos; return this.finishToken(types$1.semi)
  4457. case 44: ++this.pos; return this.finishToken(types$1.comma)
  4458. case 91: ++this.pos; return this.finishToken(types$1.bracketL)
  4459. case 93: ++this.pos; return this.finishToken(types$1.bracketR)
  4460. case 123: ++this.pos; return this.finishToken(types$1.braceL)
  4461. case 125: ++this.pos; return this.finishToken(types$1.braceR)
  4462. case 58: ++this.pos; return this.finishToken(types$1.colon)
  4463. case 96: // '`'
  4464. if (this.options.ecmaVersion < 6) { break }
  4465. ++this.pos;
  4466. return this.finishToken(types$1.backQuote)
  4467. case 48: // '0'
  4468. var next = this.input.charCodeAt(this.pos + 1);
  4469. if (next === 120 || next === 88) { return this.readRadixNumber(16) } // '0x', '0X' - hex number
  4470. if (this.options.ecmaVersion >= 6) {
  4471. if (next === 111 || next === 79) { return this.readRadixNumber(8) } // '0o', '0O' - octal number
  4472. if (next === 98 || next === 66) { return this.readRadixNumber(2) } // '0b', '0B' - binary number
  4473. }
  4474. // Anything else beginning with a digit is an integer, octal
  4475. // number, or float.
  4476. case 49: case 50: case 51: case 52: case 53: case 54: case 55: case 56: case 57: // 1-9
  4477. return this.readNumber(false)
  4478. // Quotes produce strings.
  4479. case 34: case 39: // '"', "'"
  4480. return this.readString(code)
  4481. // Operators are parsed inline in tiny state machines. '=' (61) is
  4482. // often referred to. `finishOp` simply skips the amount of
  4483. // characters it is given as second argument, and returns a token
  4484. // of the type given by its first argument.
  4485. case 47: // '/'
  4486. return this.readToken_slash()
  4487. case 37: case 42: // '%*'
  4488. return this.readToken_mult_modulo_exp(code)
  4489. case 124: case 38: // '|&'
  4490. return this.readToken_pipe_amp(code)
  4491. case 94: // '^'
  4492. return this.readToken_caret()
  4493. case 43: case 45: // '+-'
  4494. return this.readToken_plus_min(code)
  4495. case 60: case 62: // '<>'
  4496. return this.readToken_lt_gt(code)
  4497. case 61: case 33: // '=!'
  4498. return this.readToken_eq_excl(code)
  4499. case 63: // '?'
  4500. return this.readToken_question()
  4501. case 126: // '~'
  4502. return this.finishOp(types$1.prefix, 1)
  4503. case 35: // '#'
  4504. return this.readToken_numberSign()
  4505. }
  4506. this.raise(this.pos, "Unexpected character '" + codePointToString(code) + "'");
  4507. };
  4508. pp.finishOp = function(type, size) {
  4509. var str = this.input.slice(this.pos, this.pos + size);
  4510. this.pos += size;
  4511. return this.finishToken(type, str)
  4512. };
  4513. pp.readRegexp = function() {
  4514. var escaped, inClass, start = this.pos;
  4515. for (;;) {
  4516. if (this.pos >= this.input.length) { this.raise(start, "Unterminated regular expression"); }
  4517. var ch = this.input.charAt(this.pos);
  4518. if (lineBreak.test(ch)) { this.raise(start, "Unterminated regular expression"); }
  4519. if (!escaped) {
  4520. if (ch === "[") { inClass = true; }
  4521. else if (ch === "]" && inClass) { inClass = false; }
  4522. else if (ch === "/" && !inClass) { break }
  4523. escaped = ch === "\\";
  4524. } else { escaped = false; }
  4525. ++this.pos;
  4526. }
  4527. var pattern = this.input.slice(start, this.pos);
  4528. ++this.pos;
  4529. var flagsStart = this.pos;
  4530. var flags = this.readWord1();
  4531. if (this.containsEsc) { this.unexpected(flagsStart); }
  4532. // Validate pattern
  4533. var state = this.regexpState || (this.regexpState = new RegExpValidationState(this));
  4534. state.reset(start, pattern, flags);
  4535. this.validateRegExpFlags(state);
  4536. this.validateRegExpPattern(state);
  4537. // Create Literal#value property value.
  4538. var value = null;
  4539. try {
  4540. value = new RegExp(pattern, flags);
  4541. } catch (e) {
  4542. // ESTree requires null if it failed to instantiate RegExp object.
  4543. // https://github.com/estree/estree/blob/a27003adf4fd7bfad44de9cef372a2eacd527b1c/es5.md#regexpliteral
  4544. }
  4545. return this.finishToken(types$1.regexp, {pattern: pattern, flags: flags, value: value})
  4546. };
  4547. // Read an integer in the given radix. Return null if zero digits
  4548. // were read, the integer value otherwise. When `len` is given, this
  4549. // will return `null` unless the integer has exactly `len` digits.
  4550. pp.readInt = function(radix, len, maybeLegacyOctalNumericLiteral) {
  4551. // `len` is used for character escape sequences. In that case, disallow separators.
  4552. var allowSeparators = this.options.ecmaVersion >= 12 && len === undefined;
  4553. // `maybeLegacyOctalNumericLiteral` is true if it doesn't have prefix (0x,0o,0b)
  4554. // and isn't fraction part nor exponent part. In that case, if the first digit
  4555. // is zero then disallow separators.
  4556. var isLegacyOctalNumericLiteral = maybeLegacyOctalNumericLiteral && this.input.charCodeAt(this.pos) === 48;
  4557. var start = this.pos, total = 0, lastCode = 0;
  4558. for (var i = 0, e = len == null ? Infinity : len; i < e; ++i, ++this.pos) {
  4559. var code = this.input.charCodeAt(this.pos), val = (void 0);
  4560. if (allowSeparators && code === 95) {
  4561. if (isLegacyOctalNumericLiteral) { this.raiseRecoverable(this.pos, "Numeric separator is not allowed in legacy octal numeric literals"); }
  4562. if (lastCode === 95) { this.raiseRecoverable(this.pos, "Numeric separator must be exactly one underscore"); }
  4563. if (i === 0) { this.raiseRecoverable(this.pos, "Numeric separator is not allowed at the first of digits"); }
  4564. lastCode = code;
  4565. continue
  4566. }
  4567. if (code >= 97) { val = code - 97 + 10; } // a
  4568. else if (code >= 65) { val = code - 65 + 10; } // A
  4569. else if (code >= 48 && code <= 57) { val = code - 48; } // 0-9
  4570. else { val = Infinity; }
  4571. if (val >= radix) { break }
  4572. lastCode = code;
  4573. total = total * radix + val;
  4574. }
  4575. if (allowSeparators && lastCode === 95) { this.raiseRecoverable(this.pos - 1, "Numeric separator is not allowed at the last of digits"); }
  4576. if (this.pos === start || len != null && this.pos - start !== len) { return null }
  4577. return total
  4578. };
  4579. function stringToNumber(str, isLegacyOctalNumericLiteral) {
  4580. if (isLegacyOctalNumericLiteral) {
  4581. return parseInt(str, 8)
  4582. }
  4583. // `parseFloat(value)` stops parsing at the first numeric separator then returns a wrong value.
  4584. return parseFloat(str.replace(/_/g, ""))
  4585. }
  4586. function stringToBigInt(str) {
  4587. if (typeof BigInt !== "function") {
  4588. return null
  4589. }
  4590. // `BigInt(value)` throws syntax error if the string contains numeric separators.
  4591. return BigInt(str.replace(/_/g, ""))
  4592. }
  4593. pp.readRadixNumber = function(radix) {
  4594. var start = this.pos;
  4595. this.pos += 2; // 0x
  4596. var val = this.readInt(radix);
  4597. if (val == null) { this.raise(this.start + 2, "Expected number in radix " + radix); }
  4598. if (this.options.ecmaVersion >= 11 && this.input.charCodeAt(this.pos) === 110) {
  4599. val = stringToBigInt(this.input.slice(start, this.pos));
  4600. ++this.pos;
  4601. } else if (isIdentifierStart(this.fullCharCodeAtPos())) { this.raise(this.pos, "Identifier directly after number"); }
  4602. return this.finishToken(types$1.num, val)
  4603. };
  4604. // Read an integer, octal integer, or floating-point number.
  4605. pp.readNumber = function(startsWithDot) {
  4606. var start = this.pos;
  4607. if (!startsWithDot && this.readInt(10, undefined, true) === null) { this.raise(start, "Invalid number"); }
  4608. var octal = this.pos - start >= 2 && this.input.charCodeAt(start) === 48;
  4609. if (octal && this.strict) { this.raise(start, "Invalid number"); }
  4610. var next = this.input.charCodeAt(this.pos);
  4611. if (!octal && !startsWithDot && this.options.ecmaVersion >= 11 && next === 110) {
  4612. var val$1 = stringToBigInt(this.input.slice(start, this.pos));
  4613. ++this.pos;
  4614. if (isIdentifierStart(this.fullCharCodeAtPos())) { this.raise(this.pos, "Identifier directly after number"); }
  4615. return this.finishToken(types$1.num, val$1)
  4616. }
  4617. if (octal && /[89]/.test(this.input.slice(start, this.pos))) { octal = false; }
  4618. if (next === 46 && !octal) { // '.'
  4619. ++this.pos;
  4620. this.readInt(10);
  4621. next = this.input.charCodeAt(this.pos);
  4622. }
  4623. if ((next === 69 || next === 101) && !octal) { // 'eE'
  4624. next = this.input.charCodeAt(++this.pos);
  4625. if (next === 43 || next === 45) { ++this.pos; } // '+-'
  4626. if (this.readInt(10) === null) { this.raise(start, "Invalid number"); }
  4627. }
  4628. if (isIdentifierStart(this.fullCharCodeAtPos())) { this.raise(this.pos, "Identifier directly after number"); }
  4629. var val = stringToNumber(this.input.slice(start, this.pos), octal);
  4630. return this.finishToken(types$1.num, val)
  4631. };
  4632. // Read a string value, interpreting backslash-escapes.
  4633. pp.readCodePoint = function() {
  4634. var ch = this.input.charCodeAt(this.pos), code;
  4635. if (ch === 123) { // '{'
  4636. if (this.options.ecmaVersion < 6) { this.unexpected(); }
  4637. var codePos = ++this.pos;
  4638. code = this.readHexChar(this.input.indexOf("}", this.pos) - this.pos);
  4639. ++this.pos;
  4640. if (code > 0x10FFFF) { this.invalidStringToken(codePos, "Code point out of bounds"); }
  4641. } else {
  4642. code = this.readHexChar(4);
  4643. }
  4644. return code
  4645. };
  4646. function codePointToString(code) {
  4647. // UTF-16 Decoding
  4648. if (code <= 0xFFFF) { return String.fromCharCode(code) }
  4649. code -= 0x10000;
  4650. return String.fromCharCode((code >> 10) + 0xD800, (code & 1023) + 0xDC00)
  4651. }
  4652. pp.readString = function(quote) {
  4653. var out = "", chunkStart = ++this.pos;
  4654. for (;;) {
  4655. if (this.pos >= this.input.length) { this.raise(this.start, "Unterminated string constant"); }
  4656. var ch = this.input.charCodeAt(this.pos);
  4657. if (ch === quote) { break }
  4658. if (ch === 92) { // '\'
  4659. out += this.input.slice(chunkStart, this.pos);
  4660. out += this.readEscapedChar(false);
  4661. chunkStart = this.pos;
  4662. } else if (ch === 0x2028 || ch === 0x2029) {
  4663. if (this.options.ecmaVersion < 10) { this.raise(this.start, "Unterminated string constant"); }
  4664. ++this.pos;
  4665. if (this.options.locations) {
  4666. this.curLine++;
  4667. this.lineStart = this.pos;
  4668. }
  4669. } else {
  4670. if (isNewLine(ch)) { this.raise(this.start, "Unterminated string constant"); }
  4671. ++this.pos;
  4672. }
  4673. }
  4674. out += this.input.slice(chunkStart, this.pos++);
  4675. return this.finishToken(types$1.string, out)
  4676. };
  4677. // Reads template string tokens.
  4678. var INVALID_TEMPLATE_ESCAPE_ERROR = {};
  4679. pp.tryReadTemplateToken = function() {
  4680. this.inTemplateElement = true;
  4681. try {
  4682. this.readTmplToken();
  4683. } catch (err) {
  4684. if (err === INVALID_TEMPLATE_ESCAPE_ERROR) {
  4685. this.readInvalidTemplateToken();
  4686. } else {
  4687. throw err
  4688. }
  4689. }
  4690. this.inTemplateElement = false;
  4691. };
  4692. pp.invalidStringToken = function(position, message) {
  4693. if (this.inTemplateElement && this.options.ecmaVersion >= 9) {
  4694. throw INVALID_TEMPLATE_ESCAPE_ERROR
  4695. } else {
  4696. this.raise(position, message);
  4697. }
  4698. };
  4699. pp.readTmplToken = function() {
  4700. var out = "", chunkStart = this.pos;
  4701. for (;;) {
  4702. if (this.pos >= this.input.length) { this.raise(this.start, "Unterminated template"); }
  4703. var ch = this.input.charCodeAt(this.pos);
  4704. if (ch === 96 || ch === 36 && this.input.charCodeAt(this.pos + 1) === 123) { // '`', '${'
  4705. if (this.pos === this.start && (this.type === types$1.template || this.type === types$1.invalidTemplate)) {
  4706. if (ch === 36) {
  4707. this.pos += 2;
  4708. return this.finishToken(types$1.dollarBraceL)
  4709. } else {
  4710. ++this.pos;
  4711. return this.finishToken(types$1.backQuote)
  4712. }
  4713. }
  4714. out += this.input.slice(chunkStart, this.pos);
  4715. return this.finishToken(types$1.template, out)
  4716. }
  4717. if (ch === 92) { // '\'
  4718. out += this.input.slice(chunkStart, this.pos);
  4719. out += this.readEscapedChar(true);
  4720. chunkStart = this.pos;
  4721. } else if (isNewLine(ch)) {
  4722. out += this.input.slice(chunkStart, this.pos);
  4723. ++this.pos;
  4724. switch (ch) {
  4725. case 13:
  4726. if (this.input.charCodeAt(this.pos) === 10) { ++this.pos; }
  4727. case 10:
  4728. out += "\n";
  4729. break
  4730. default:
  4731. out += String.fromCharCode(ch);
  4732. break
  4733. }
  4734. if (this.options.locations) {
  4735. ++this.curLine;
  4736. this.lineStart = this.pos;
  4737. }
  4738. chunkStart = this.pos;
  4739. } else {
  4740. ++this.pos;
  4741. }
  4742. }
  4743. };
  4744. // Reads a template token to search for the end, without validating any escape sequences
  4745. pp.readInvalidTemplateToken = function() {
  4746. for (; this.pos < this.input.length; this.pos++) {
  4747. switch (this.input[this.pos]) {
  4748. case "\\":
  4749. ++this.pos;
  4750. break
  4751. case "$":
  4752. if (this.input[this.pos + 1] !== "{") {
  4753. break
  4754. }
  4755. // falls through
  4756. case "`":
  4757. return this.finishToken(types$1.invalidTemplate, this.input.slice(this.start, this.pos))
  4758. // no default
  4759. }
  4760. }
  4761. this.raise(this.start, "Unterminated template");
  4762. };
  4763. // Used to read escaped characters
  4764. pp.readEscapedChar = function(inTemplate) {
  4765. var ch = this.input.charCodeAt(++this.pos);
  4766. ++this.pos;
  4767. switch (ch) {
  4768. case 110: return "\n" // 'n' -> '\n'
  4769. case 114: return "\r" // 'r' -> '\r'
  4770. case 120: return String.fromCharCode(this.readHexChar(2)) // 'x'
  4771. case 117: return codePointToString(this.readCodePoint()) // 'u'
  4772. case 116: return "\t" // 't' -> '\t'
  4773. case 98: return "\b" // 'b' -> '\b'
  4774. case 118: return "\u000b" // 'v' -> '\u000b'
  4775. case 102: return "\f" // 'f' -> '\f'
  4776. case 13: if (this.input.charCodeAt(this.pos) === 10) { ++this.pos; } // '\r\n'
  4777. case 10: // ' \n'
  4778. if (this.options.locations) { this.lineStart = this.pos; ++this.curLine; }
  4779. return ""
  4780. case 56:
  4781. case 57:
  4782. if (this.strict) {
  4783. this.invalidStringToken(
  4784. this.pos - 1,
  4785. "Invalid escape sequence"
  4786. );
  4787. }
  4788. if (inTemplate) {
  4789. var codePos = this.pos - 1;
  4790. this.invalidStringToken(
  4791. codePos,
  4792. "Invalid escape sequence in template string"
  4793. );
  4794. return null
  4795. }
  4796. default:
  4797. if (ch >= 48 && ch <= 55) {
  4798. var octalStr = this.input.substr(this.pos - 1, 3).match(/^[0-7]+/)[0];
  4799. var octal = parseInt(octalStr, 8);
  4800. if (octal > 255) {
  4801. octalStr = octalStr.slice(0, -1);
  4802. octal = parseInt(octalStr, 8);
  4803. }
  4804. this.pos += octalStr.length - 1;
  4805. ch = this.input.charCodeAt(this.pos);
  4806. if ((octalStr !== "0" || ch === 56 || ch === 57) && (this.strict || inTemplate)) {
  4807. this.invalidStringToken(
  4808. this.pos - 1 - octalStr.length,
  4809. inTemplate
  4810. ? "Octal literal in template string"
  4811. : "Octal literal in strict mode"
  4812. );
  4813. }
  4814. return String.fromCharCode(octal)
  4815. }
  4816. if (isNewLine(ch)) {
  4817. // Unicode new line characters after \ get removed from output in both
  4818. // template literals and strings
  4819. return ""
  4820. }
  4821. return String.fromCharCode(ch)
  4822. }
  4823. };
  4824. // Used to read character escape sequences ('\x', '\u', '\U').
  4825. pp.readHexChar = function(len) {
  4826. var codePos = this.pos;
  4827. var n = this.readInt(16, len);
  4828. if (n === null) { this.invalidStringToken(codePos, "Bad character escape sequence"); }
  4829. return n
  4830. };
  4831. // Read an identifier, and return it as a string. Sets `this.containsEsc`
  4832. // to whether the word contained a '\u' escape.
  4833. //
  4834. // Incrementally adds only escaped chars, adding other chunks as-is
  4835. // as a micro-optimization.
  4836. pp.readWord1 = function() {
  4837. this.containsEsc = false;
  4838. var word = "", first = true, chunkStart = this.pos;
  4839. var astral = this.options.ecmaVersion >= 6;
  4840. while (this.pos < this.input.length) {
  4841. var ch = this.fullCharCodeAtPos();
  4842. if (isIdentifierChar(ch, astral)) {
  4843. this.pos += ch <= 0xffff ? 1 : 2;
  4844. } else if (ch === 92) { // "\"
  4845. this.containsEsc = true;
  4846. word += this.input.slice(chunkStart, this.pos);
  4847. var escStart = this.pos;
  4848. if (this.input.charCodeAt(++this.pos) !== 117) // "u"
  4849. { this.invalidStringToken(this.pos, "Expecting Unicode escape sequence \\uXXXX"); }
  4850. ++this.pos;
  4851. var esc = this.readCodePoint();
  4852. if (!(first ? isIdentifierStart : isIdentifierChar)(esc, astral))
  4853. { this.invalidStringToken(escStart, "Invalid Unicode escape"); }
  4854. word += codePointToString(esc);
  4855. chunkStart = this.pos;
  4856. } else {
  4857. break
  4858. }
  4859. first = false;
  4860. }
  4861. return word + this.input.slice(chunkStart, this.pos)
  4862. };
  4863. // Read an identifier or keyword token. Will check for reserved
  4864. // words when necessary.
  4865. pp.readWord = function() {
  4866. var word = this.readWord1();
  4867. var type = types$1.name;
  4868. if (this.keywords.test(word)) {
  4869. type = keywords[word];
  4870. }
  4871. return this.finishToken(type, word)
  4872. };
  4873. // Acorn is a tiny, fast JavaScript parser written in JavaScript.
  4874. var version = "8.7.0";
  4875. Parser.acorn = {
  4876. Parser: Parser,
  4877. version: version,
  4878. defaultOptions: defaultOptions,
  4879. Position: Position,
  4880. SourceLocation: SourceLocation,
  4881. getLineInfo: getLineInfo,
  4882. Node: Node,
  4883. TokenType: TokenType,
  4884. tokTypes: types$1,
  4885. keywordTypes: keywords,
  4886. TokContext: TokContext,
  4887. tokContexts: types,
  4888. isIdentifierChar: isIdentifierChar,
  4889. isIdentifierStart: isIdentifierStart,
  4890. Token: Token,
  4891. isNewLine: isNewLine,
  4892. lineBreak: lineBreak,
  4893. lineBreakG: lineBreakG,
  4894. nonASCIIwhitespace: nonASCIIwhitespace
  4895. };
  4896. // The main exported interface (under `self.acorn` when in the
  4897. // browser) is a `parse` function that takes a code string and
  4898. // returns an abstract syntax tree as specified by [Mozilla parser
  4899. // API][api].
  4900. //
  4901. // [api]: https://developer.mozilla.org/en-US/docs/SpiderMonkey/Parser_API
  4902. function parse(input, options) {
  4903. return Parser.parse(input, options)
  4904. }
  4905. // This function tries to parse a single expression at a given
  4906. // offset in a string. Useful for parsing mixed-language formats
  4907. // that embed JavaScript expressions.
  4908. function parseExpressionAt(input, pos, options) {
  4909. return Parser.parseExpressionAt(input, pos, options)
  4910. }
  4911. // Acorn is organized as a tokenizer and a recursive-descent parser.
  4912. // The `tokenizer` export provides an interface to the tokenizer.
  4913. function tokenizer(input, options) {
  4914. return Parser.tokenizer(input, options)
  4915. }
  4916. export { Node, Parser, Position, SourceLocation, TokContext, Token, TokenType, defaultOptions, getLineInfo, isIdentifierChar, isIdentifierStart, isNewLine, keywords as keywordTypes, lineBreak, lineBreakG, nonASCIIwhitespace, parse, parseExpressionAt, types as tokContexts, types$1 as tokTypes, tokenizer, version };