acorn.js 175 KB

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