acorn.js 175 KB

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