You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

acorn.mjs 178KB

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