buble.js 424 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112
  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.buble = {})));
  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. // ## Character categories
  21. // Big ugly regular expressions that match characters in the
  22. // whitespace, identifier, and identifier-start categories. These
  23. // are only applied when a character is found to actually have a
  24. // code point above 128.
  25. // Generated by `bin/generate-identifier-regex.js`.
  26. var nonASCIIidentifierStartChars = "\xaa\xb5\xba\xc0-\xd6\xd8-\xf6\xf8-\u02c1\u02c6-\u02d1\u02e0-\u02e4\u02ec\u02ee\u0370-\u0374\u0376\u0377\u037a-\u037d\u037f\u0386\u0388-\u038a\u038c\u038e-\u03a1\u03a3-\u03f5\u03f7-\u0481\u048a-\u052f\u0531-\u0556\u0559\u0561-\u0587\u05d0-\u05ea\u05f0-\u05f2\u0620-\u064a\u066e\u066f\u0671-\u06d3\u06d5\u06e5\u06e6\u06ee\u06ef\u06fa-\u06fc\u06ff\u0710\u0712-\u072f\u074d-\u07a5\u07b1\u07ca-\u07ea\u07f4\u07f5\u07fa\u0800-\u0815\u081a\u0824\u0828\u0840-\u0858\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\u0a05-\u0a0a\u0a0f\u0a10\u0a13-\u0a28\u0a2a-\u0a30\u0a32\u0a33\u0a35\u0a36\u0a38\u0a39\u0a59-\u0a5c\u0a5e\u0a72-\u0a74\u0a85-\u0a8d\u0a8f-\u0a91\u0a93-\u0aa8\u0aaa-\u0ab0\u0ab2\u0ab3\u0ab5-\u0ab9\u0abd\u0ad0\u0ae0\u0ae1\u0af9\u0b05-\u0b0c\u0b0f\u0b10\u0b13-\u0b28\u0b2a-\u0b30\u0b32\u0b33\u0b35-\u0b39\u0b3d\u0b5c\u0b5d\u0b5f-\u0b61\u0b71\u0b83\u0b85-\u0b8a\u0b8e-\u0b90\u0b92-\u0b95\u0b99\u0b9a\u0b9c\u0b9e\u0b9f\u0ba3\u0ba4\u0ba8-\u0baa\u0bae-\u0bb9\u0bd0\u0c05-\u0c0c\u0c0e-\u0c10\u0c12-\u0c28\u0c2a-\u0c39\u0c3d\u0c58-\u0c5a\u0c60\u0c61\u0c80\u0c85-\u0c8c\u0c8e-\u0c90\u0c92-\u0ca8\u0caa-\u0cb3\u0cb5-\u0cb9\u0cbd\u0cde\u0ce0\u0ce1\u0cf1\u0cf2\u0d05-\u0d0c\u0d0e-\u0d10\u0d12-\u0d3a\u0d3d\u0d4e\u0d54-\u0d56\u0d5f-\u0d61\u0d7a-\u0d7f\u0d85-\u0d96\u0d9a-\u0db1\u0db3-\u0dbb\u0dbd\u0dc0-\u0dc6\u0e01-\u0e30\u0e32\u0e33\u0e40-\u0e46\u0e81\u0e82\u0e84\u0e87\u0e88\u0e8a\u0e8d\u0e94-\u0e97\u0e99-\u0e9f\u0ea1-\u0ea3\u0ea5\u0ea7\u0eaa\u0eab\u0ead-\u0eb0\u0eb2\u0eb3\u0ebd\u0ec0-\u0ec4\u0ec6\u0edc-\u0edf\u0f00\u0f40-\u0f47\u0f49-\u0f6c\u0f88-\u0f8c\u1000-\u102a\u103f\u1050-\u1055\u105a-\u105d\u1061\u1065\u1066\u106e-\u1070\u1075-\u1081\u108e\u10a0-\u10c5\u10c7\u10cd\u10d0-\u10fa\u10fc-\u1248\u124a-\u124d\u1250-\u1256\u1258\u125a-\u125d\u1260-\u1288\u128a-\u128d\u1290-\u12b0\u12b2-\u12b5\u12b8-\u12be\u12c0\u12c2-\u12c5\u12c8-\u12d6\u12d8-\u1310\u1312-\u1315\u1318-\u135a\u1380-\u138f\u13a0-\u13f5\u13f8-\u13fd\u1401-\u166c\u166f-\u167f\u1681-\u169a\u16a0-\u16ea\u16ee-\u16f8\u1700-\u170c\u170e-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176c\u176e-\u1770\u1780-\u17b3\u17d7\u17dc\u1820-\u1877\u1880-\u18a8\u18aa\u18b0-\u18f5\u1900-\u191e\u1950-\u196d\u1970-\u1974\u1980-\u19ab\u19b0-\u19c9\u1a00-\u1a16\u1a20-\u1a54\u1aa7\u1b05-\u1b33\u1b45-\u1b4b\u1b83-\u1ba0\u1bae\u1baf\u1bba-\u1be5\u1c00-\u1c23\u1c4d-\u1c4f\u1c5a-\u1c7d\u1c80-\u1c88\u1ce9-\u1cec\u1cee-\u1cf1\u1cf5\u1cf6\u1d00-\u1dbf\u1e00-\u1f15\u1f18-\u1f1d\u1f20-\u1f45\u1f48-\u1f4d\u1f50-\u1f57\u1f59\u1f5b\u1f5d\u1f5f-\u1f7d\u1f80-\u1fb4\u1fb6-\u1fbc\u1fbe\u1fc2-\u1fc4\u1fc6-\u1fcc\u1fd0-\u1fd3\u1fd6-\u1fdb\u1fe0-\u1fec\u1ff2-\u1ff4\u1ff6-\u1ffc\u2071\u207f\u2090-\u209c\u2102\u2107\u210a-\u2113\u2115\u2118-\u211d\u2124\u2126\u2128\u212a-\u2139\u213c-\u213f\u2145-\u2149\u214e\u2160-\u2188\u2c00-\u2c2e\u2c30-\u2c5e\u2c60-\u2ce4\u2ceb-\u2cee\u2cf2\u2cf3\u2d00-\u2d25\u2d27\u2d2d\u2d30-\u2d67\u2d6f\u2d80-\u2d96\u2da0-\u2da6\u2da8-\u2dae\u2db0-\u2db6\u2db8-\u2dbe\u2dc0-\u2dc6\u2dc8-\u2dce\u2dd0-\u2dd6\u2dd8-\u2dde\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303c\u3041-\u3096\u309b-\u309f\u30a1-\u30fa\u30fc-\u30ff\u3105-\u312d\u3131-\u318e\u31a0-\u31ba\u31f0-\u31ff\u3400-\u4db5\u4e00-\u9fd5\ua000-\ua48c\ua4d0-\ua4fd\ua500-\ua60c\ua610-\ua61f\ua62a\ua62b\ua640-\ua66e\ua67f-\ua69d\ua6a0-\ua6ef\ua717-\ua71f\ua722-\ua788\ua78b-\ua7ae\ua7b0-\ua7b7\ua7f7-\ua801\ua803-\ua805\ua807-\ua80a\ua80c-\ua822\ua840-\ua873\ua882-\ua8b3\ua8f2-\ua8f7\ua8fb\ua8fd\ua90a-\ua925\ua930-\ua946\ua960-\ua97c\ua984-\ua9b2\ua9cf\ua9e0-\ua9e4\ua9e6-\ua9ef\ua9fa-\ua9fe\uaa00-\uaa28\uaa40-\uaa42\uaa44-\uaa4b\uaa60-\uaa76\uaa7a\uaa7e-\uaaaf\uaab1\uaab5\uaab6\uaab9-\uaabd\uaac0\uaac2\uaadb-\uaadd\uaae0-\uaaea\uaaf2-\uaaf4\uab01-\uab06\uab09-\uab0e\uab11-\uab16\uab20-\uab26\uab28-\uab2e\uab30-\uab5a\uab5c-\uab65\uab70-\uabe2\uac00-\ud7a3\ud7b0-\ud7c6\ud7cb-\ud7fb\uf900-\ufa6d\ufa70-\ufad9\ufb00-\ufb06\ufb13-\ufb17\ufb1d\ufb1f-\ufb28\ufb2a-\ufb36\ufb38-\ufb3c\ufb3e\ufb40\ufb41\ufb43\ufb44\ufb46-\ufbb1\ufbd3-\ufd3d\ufd50-\ufd8f\ufd92-\ufdc7\ufdf0-\ufdfb\ufe70-\ufe74\ufe76-\ufefc\uff21-\uff3a\uff41-\uff5a\uff66-\uffbe\uffc2-\uffc7\uffca-\uffcf\uffd2-\uffd7\uffda-\uffdc";
  27. var nonASCIIidentifierChars = "\u200c\u200d\xb7\u0300-\u036f\u0387\u0483-\u0487\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u0610-\u061a\u064b-\u0669\u0670\u06d6-\u06dc\u06df-\u06e4\u06e7\u06e8\u06ea-\u06ed\u06f0-\u06f9\u0711\u0730-\u074a\u07a6-\u07b0\u07c0-\u07c9\u07eb-\u07f3\u0816-\u0819\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0859-\u085b\u08d4-\u08e1\u08e3-\u0903\u093a-\u093c\u093e-\u094f\u0951-\u0957\u0962\u0963\u0966-\u096f\u0981-\u0983\u09bc\u09be-\u09c4\u09c7\u09c8\u09cb-\u09cd\u09d7\u09e2\u09e3\u09e6-\u09ef\u0a01-\u0a03\u0a3c\u0a3e-\u0a42\u0a47\u0a48\u0a4b-\u0a4d\u0a51\u0a66-\u0a71\u0a75\u0a81-\u0a83\u0abc\u0abe-\u0ac5\u0ac7-\u0ac9\u0acb-\u0acd\u0ae2\u0ae3\u0ae6-\u0aef\u0b01-\u0b03\u0b3c\u0b3e-\u0b44\u0b47\u0b48\u0b4b-\u0b4d\u0b56\u0b57\u0b62\u0b63\u0b66-\u0b6f\u0b82\u0bbe-\u0bc2\u0bc6-\u0bc8\u0bca-\u0bcd\u0bd7\u0be6-\u0bef\u0c00-\u0c03\u0c3e-\u0c44\u0c46-\u0c48\u0c4a-\u0c4d\u0c55\u0c56\u0c62\u0c63\u0c66-\u0c6f\u0c81-\u0c83\u0cbc\u0cbe-\u0cc4\u0cc6-\u0cc8\u0cca-\u0ccd\u0cd5\u0cd6\u0ce2\u0ce3\u0ce6-\u0cef\u0d01-\u0d03\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\u1cf8\u1cf9\u1dc0-\u1df5\u1dfb-\u1dff\u203f\u2040\u2054\u20d0-\u20dc\u20e1\u20e5-\u20f0\u2cef-\u2cf1\u2d7f\u2de0-\u2dff\u302a-\u302f\u3099\u309a\ua620-\ua629\ua66f\ua674-\ua67d\ua69e\ua69f\ua6f0\ua6f1\ua802\ua806\ua80b\ua823-\ua827\ua880\ua881\ua8b4-\ua8c5\ua8d0-\ua8d9\ua8e0-\ua8f1\ua900-\ua909\ua926-\ua92d\ua947-\ua953\ua980-\ua983\ua9b3-\ua9c0\ua9d0-\ua9d9\ua9e5\ua9f0-\ua9f9\uaa29-\uaa36\uaa43\uaa4c\uaa4d\uaa50-\uaa59\uaa7b-\uaa7d\uaab0\uaab2-\uaab4\uaab7\uaab8\uaabe\uaabf\uaac1\uaaeb-\uaaef\uaaf5\uaaf6\uabe3-\uabea\uabec\uabed\uabf0-\uabf9\ufb1e\ufe00-\ufe0f\ufe20-\ufe2f\ufe33\ufe34\ufe4d-\ufe4f\uff10-\uff19\uff3f";
  28. var nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]");
  29. var nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]");
  30. nonASCIIidentifierStartChars = nonASCIIidentifierChars = null;
  31. // These are a run-length and offset encoded representation of the
  32. // >0xffff code points that are a valid part of identifiers. The
  33. // offset starts at 0x10000, and each pair of numbers represents an
  34. // offset to the next range, and then a size of the range. They were
  35. // generated by bin/generate-identifier-regex.js
  36. // eslint-disable-next-line comma-spacing
  37. var astralIdentifierStartCodes = [0,11,2,25,2,18,2,1,2,14,3,13,35,122,70,52,268,28,4,48,48,31,17,26,6,37,11,29,3,35,5,7,2,4,43,157,19,35,5,35,5,39,9,51,157,310,10,21,11,7,153,5,3,0,2,43,2,1,4,0,3,22,11,22,10,30,66,18,2,1,11,21,11,25,71,55,7,1,65,0,16,3,2,2,2,26,45,28,4,28,36,7,2,27,28,53,11,21,11,18,14,17,111,72,56,50,14,50,785,52,76,44,33,24,27,35,42,34,4,0,13,47,15,3,22,0,2,0,36,17,2,24,85,6,2,0,2,3,2,14,2,9,8,46,39,7,3,1,3,21,2,6,2,1,2,4,4,0,19,0,13,4,159,52,19,3,54,47,21,1,2,0,185,46,42,3,37,47,21,0,60,42,86,25,391,63,32,0,449,56,264,8,2,36,18,0,50,29,881,921,103,110,18,195,2749,1070,4050,582,8634,568,8,30,114,29,19,47,17,3,32,20,6,18,881,68,12,0,67,12,65,0,32,6124,20,754,9486,1,3071,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,10591,541];
  38. // eslint-disable-next-line comma-spacing
  39. var astralIdentifierCodes = [509,0,227,0,150,4,294,9,1368,2,2,1,6,3,41,2,5,0,166,1,1306,2,54,14,32,9,16,3,46,10,54,9,7,2,37,13,2,9,52,0,13,2,49,13,10,2,4,9,83,11,7,0,161,11,6,9,7,3,57,0,2,6,3,1,3,2,10,0,11,1,3,6,4,4,193,17,10,9,87,19,13,9,214,6,3,8,28,1,83,16,16,9,82,12,9,9,84,14,5,9,423,9,838,7,2,7,17,9,57,21,2,13,19882,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];
  40. // This has a complexity linear to the value of the code. The
  41. // assumption is that looking up astral identifier characters is
  42. // rare.
  43. function isInAstralSet(code, set) {
  44. var pos = 0x10000;
  45. for (var i = 0; i < set.length; i += 2) {
  46. pos += set[i];
  47. if (pos > code) { return false }
  48. pos += set[i + 1];
  49. if (pos >= code) { return true }
  50. }
  51. }
  52. // Test whether a given character code starts an identifier.
  53. function isIdentifierStart(code, astral) {
  54. if (code < 65) { return code === 36 }
  55. if (code < 91) { return true }
  56. if (code < 97) { return code === 95 }
  57. if (code < 123) { return true }
  58. if (code <= 0xffff) { return code >= 0xaa && nonASCIIidentifierStart.test(String.fromCharCode(code)) }
  59. if (astral === false) { return false }
  60. return isInAstralSet(code, astralIdentifierStartCodes)
  61. }
  62. // Test whether a given character is part of an identifier.
  63. function isIdentifierChar(code, astral) {
  64. if (code < 48) { return code === 36 }
  65. if (code < 58) { return true }
  66. if (code < 65) { return false }
  67. if (code < 91) { return true }
  68. if (code < 97) { return code === 95 }
  69. if (code < 123) { return true }
  70. if (code <= 0xffff) { return code >= 0xaa && nonASCIIidentifier.test(String.fromCharCode(code)) }
  71. if (astral === false) { return false }
  72. return isInAstralSet(code, astralIdentifierStartCodes) || isInAstralSet(code, astralIdentifierCodes)
  73. }
  74. // ## Token types
  75. // The assignment of fine-grained, information-carrying type objects
  76. // allows the tokenizer to store the information it has about a
  77. // token in a way that is very cheap for the parser to look up.
  78. // All token type variables start with an underscore, to make them
  79. // easy to recognize.
  80. // The `beforeExpr` property is used to disambiguate between regular
  81. // expressions and divisions. It is set on all token types that can
  82. // be followed by an expression (thus, a slash after them would be a
  83. // regular expression).
  84. //
  85. // The `startsExpr` property is used to check if the token ends a
  86. // `yield` expression. It is set on all token types that either can
  87. // directly start an expression (like a quotation mark) or can
  88. // continue an expression (like the body of a string).
  89. //
  90. // `isLoop` marks a keyword as starting a loop, which is important
  91. // to know when parsing a label, in order to allow or disallow
  92. // continue jumps to that label.
  93. var TokenType = function TokenType(label, conf) {
  94. if ( conf === void 0 ) conf = {};
  95. this.label = label;
  96. this.keyword = conf.keyword;
  97. this.beforeExpr = !!conf.beforeExpr;
  98. this.startsExpr = !!conf.startsExpr;
  99. this.isLoop = !!conf.isLoop;
  100. this.isAssign = !!conf.isAssign;
  101. this.prefix = !!conf.prefix;
  102. this.postfix = !!conf.postfix;
  103. this.binop = conf.binop || null;
  104. this.updateContext = null;
  105. };
  106. function binop(name, prec) {
  107. return new TokenType(name, {beforeExpr: true, binop: prec})
  108. }
  109. var beforeExpr = {beforeExpr: true};
  110. var startsExpr = {startsExpr: true};
  111. // Map keyword names to token types.
  112. var keywords$1 = {};
  113. // Succinct definitions of keyword token types
  114. function kw(name, options) {
  115. if ( options === void 0 ) options = {};
  116. options.keyword = name;
  117. return keywords$1[name] = new TokenType(name, options)
  118. }
  119. var types = {
  120. num: new TokenType("num", startsExpr),
  121. regexp: new TokenType("regexp", startsExpr),
  122. string: new TokenType("string", startsExpr),
  123. name: new TokenType("name", startsExpr),
  124. eof: new TokenType("eof"),
  125. // Punctuation token types.
  126. bracketL: new TokenType("[", {beforeExpr: true, startsExpr: true}),
  127. bracketR: new TokenType("]"),
  128. braceL: new TokenType("{", {beforeExpr: true, startsExpr: true}),
  129. braceR: new TokenType("}"),
  130. parenL: new TokenType("(", {beforeExpr: true, startsExpr: true}),
  131. parenR: new TokenType(")"),
  132. comma: new TokenType(",", beforeExpr),
  133. semi: new TokenType(";", beforeExpr),
  134. colon: new TokenType(":", beforeExpr),
  135. dot: new TokenType("."),
  136. question: new TokenType("?", beforeExpr),
  137. arrow: new TokenType("=>", beforeExpr),
  138. template: new TokenType("template"),
  139. invalidTemplate: new TokenType("invalidTemplate"),
  140. ellipsis: new TokenType("...", beforeExpr),
  141. backQuote: new TokenType("`", startsExpr),
  142. dollarBraceL: new TokenType("${", {beforeExpr: true, startsExpr: true}),
  143. // Operators. These carry several kinds of properties to help the
  144. // parser use them properly (the presence of these properties is
  145. // what categorizes them as operators).
  146. //
  147. // `binop`, when present, specifies that this operator is a binary
  148. // operator, and will refer to its precedence.
  149. //
  150. // `prefix` and `postfix` mark the operator as a prefix or postfix
  151. // unary operator.
  152. //
  153. // `isAssign` marks all of `=`, `+=`, `-=` etcetera, which act as
  154. // binary operators with a very low precedence, that should result
  155. // in AssignmentExpression nodes.
  156. eq: new TokenType("=", {beforeExpr: true, isAssign: true}),
  157. assign: new TokenType("_=", {beforeExpr: true, isAssign: true}),
  158. incDec: new TokenType("++/--", {prefix: true, postfix: true, startsExpr: true}),
  159. prefix: new TokenType("!/~", {beforeExpr: true, prefix: true, startsExpr: true}),
  160. logicalOR: binop("||", 1),
  161. logicalAND: binop("&&", 2),
  162. bitwiseOR: binop("|", 3),
  163. bitwiseXOR: binop("^", 4),
  164. bitwiseAND: binop("&", 5),
  165. equality: binop("==/!=/===/!==", 6),
  166. relational: binop("</>/<=/>=", 7),
  167. bitShift: binop("<</>>/>>>", 8),
  168. plusMin: new TokenType("+/-", {beforeExpr: true, binop: 9, prefix: true, startsExpr: true}),
  169. modulo: binop("%", 10),
  170. star: binop("*", 10),
  171. slash: binop("/", 10),
  172. starstar: new TokenType("**", {beforeExpr: true}),
  173. // Keyword token types.
  174. _break: kw("break"),
  175. _case: kw("case", beforeExpr),
  176. _catch: kw("catch"),
  177. _continue: kw("continue"),
  178. _debugger: kw("debugger"),
  179. _default: kw("default", beforeExpr),
  180. _do: kw("do", {isLoop: true, beforeExpr: true}),
  181. _else: kw("else", beforeExpr),
  182. _finally: kw("finally"),
  183. _for: kw("for", {isLoop: true}),
  184. _function: kw("function", startsExpr),
  185. _if: kw("if"),
  186. _return: kw("return", beforeExpr),
  187. _switch: kw("switch"),
  188. _throw: kw("throw", beforeExpr),
  189. _try: kw("try"),
  190. _var: kw("var"),
  191. _const: kw("const"),
  192. _while: kw("while", {isLoop: true}),
  193. _with: kw("with"),
  194. _new: kw("new", {beforeExpr: true, startsExpr: true}),
  195. _this: kw("this", startsExpr),
  196. _super: kw("super", startsExpr),
  197. _class: kw("class", startsExpr),
  198. _extends: kw("extends", beforeExpr),
  199. _export: kw("export"),
  200. _import: kw("import"),
  201. _null: kw("null", startsExpr),
  202. _true: kw("true", startsExpr),
  203. _false: kw("false", startsExpr),
  204. _in: kw("in", {beforeExpr: true, binop: 7}),
  205. _instanceof: kw("instanceof", {beforeExpr: true, binop: 7}),
  206. _typeof: kw("typeof", {beforeExpr: true, prefix: true, startsExpr: true}),
  207. _void: kw("void", {beforeExpr: true, prefix: true, startsExpr: true}),
  208. _delete: kw("delete", {beforeExpr: true, prefix: true, startsExpr: true})
  209. };
  210. // Matches a whole line break (where CRLF is considered a single
  211. // line break). Used to count lines.
  212. var lineBreak = /\r\n?|\n|\u2028|\u2029/;
  213. var lineBreakG = new RegExp(lineBreak.source, "g");
  214. function isNewLine(code) {
  215. return code === 10 || code === 13 || code === 0x2028 || code === 0x2029
  216. }
  217. var nonASCIIwhitespace = /[\u1680\u180e\u2000-\u200a\u202f\u205f\u3000\ufeff]/;
  218. var skipWhiteSpace = /(?:\s|\/\/.*|\/\*[^]*?\*\/)*/g;
  219. var ref$1 = Object.prototype;
  220. var hasOwnProperty = ref$1.hasOwnProperty;
  221. var toString = ref$1.toString;
  222. // Checks if an object has a property.
  223. function has(obj, propName) {
  224. return hasOwnProperty.call(obj, propName)
  225. }
  226. var isArray = Array.isArray || (function (obj) { return (
  227. toString.call(obj) === "[object Array]"
  228. ); });
  229. // These are used when `options.locations` is on, for the
  230. // `startLoc` and `endLoc` properties.
  231. var Position = function Position(line, col) {
  232. this.line = line;
  233. this.column = col;
  234. };
  235. Position.prototype.offset = function offset (n) {
  236. return new Position(this.line, this.column + n)
  237. };
  238. var SourceLocation = function SourceLocation(p, start, end) {
  239. this.start = start;
  240. this.end = end;
  241. if (p.sourceFile !== null) { this.source = p.sourceFile; }
  242. };
  243. // The `getLineInfo` function is mostly useful when the
  244. // `locations` option is off (for performance reasons) and you
  245. // want to find the line/column position for a given character
  246. // offset. `input` should be the code string that the offset refers
  247. // into.
  248. function getLineInfo(input, offset) {
  249. for (var line = 1, cur = 0;;) {
  250. lineBreakG.lastIndex = cur;
  251. var match = lineBreakG.exec(input);
  252. if (match && match.index < offset) {
  253. ++line;
  254. cur = match.index + match[0].length;
  255. } else {
  256. return new Position(line, offset - cur)
  257. }
  258. }
  259. }
  260. // A second optional argument can be given to further configure
  261. // the parser process. These options are recognized:
  262. var defaultOptions = {
  263. // `ecmaVersion` indicates the ECMAScript version to parse. Must
  264. // be either 3, 5, 6 (2015), 7 (2016), or 8 (2017). This influences support
  265. // for strict mode, the set of reserved words, and support for
  266. // new syntax features. The default is 7.
  267. ecmaVersion: 7,
  268. // `sourceType` indicates the mode the code should be parsed in.
  269. // Can be either `"script"` or `"module"`. This influences global
  270. // strict mode and parsing of `import` and `export` declarations.
  271. sourceType: "script",
  272. // `onInsertedSemicolon` can be a callback that will be called
  273. // when a semicolon is automatically inserted. It will be passed
  274. // th position of the comma as an offset, and if `locations` is
  275. // enabled, it is given the location as a `{line, column}` object
  276. // as second argument.
  277. onInsertedSemicolon: null,
  278. // `onTrailingComma` is similar to `onInsertedSemicolon`, but for
  279. // trailing commas.
  280. onTrailingComma: null,
  281. // By default, reserved words are only enforced if ecmaVersion >= 5.
  282. // Set `allowReserved` to a boolean value to explicitly turn this on
  283. // an off. When this option has the value "never", reserved words
  284. // and keywords can also not be used as property names.
  285. allowReserved: null,
  286. // When enabled, a return at the top level is not considered an
  287. // error.
  288. allowReturnOutsideFunction: false,
  289. // When enabled, import/export statements are not constrained to
  290. // appearing at the top of the program.
  291. allowImportExportEverywhere: false,
  292. // When enabled, hashbang directive in the beginning of file
  293. // is allowed and treated as a line comment.
  294. allowHashBang: false,
  295. // When `locations` is on, `loc` properties holding objects with
  296. // `start` and `end` properties in `{line, column}` form (with
  297. // line being 1-based and column 0-based) will be attached to the
  298. // nodes.
  299. locations: false,
  300. // A function can be passed as `onToken` option, which will
  301. // cause Acorn to call that function with object in the same
  302. // format as tokens returned from `tokenizer().getToken()`. Note
  303. // that you are not allowed to call the parser from the
  304. // callback—that will corrupt its internal state.
  305. onToken: null,
  306. // A function can be passed as `onComment` option, which will
  307. // cause Acorn to call that function with `(block, text, start,
  308. // end)` parameters whenever a comment is skipped. `block` is a
  309. // boolean indicating whether this is a block (`/* */`) comment,
  310. // `text` is the content of the comment, and `start` and `end` are
  311. // character offsets that denote the start and end of the comment.
  312. // When the `locations` option is on, two more parameters are
  313. // passed, the full `{line, column}` locations of the start and
  314. // end of the comments. Note that you are not allowed to call the
  315. // parser from the callback—that will corrupt its internal state.
  316. onComment: null,
  317. // Nodes have their start and end characters offsets recorded in
  318. // `start` and `end` properties (directly on the node, rather than
  319. // the `loc` object, which holds line/column data. To also add a
  320. // [semi-standardized][range] `range` property holding a `[start,
  321. // end]` array with the same numbers, set the `ranges` option to
  322. // `true`.
  323. //
  324. // [range]: https://bugzilla.mozilla.org/show_bug.cgi?id=745678
  325. ranges: false,
  326. // It is possible to parse multiple files into a single AST by
  327. // passing the tree produced by parsing the first file as
  328. // `program` option in subsequent parses. This will add the
  329. // toplevel forms of the parsed file to the `Program` (top) node
  330. // of an existing parse tree.
  331. program: null,
  332. // When `locations` is on, you can pass this to record the source
  333. // file in every node's `loc` object.
  334. sourceFile: null,
  335. // This value, if given, is stored in every node, whether
  336. // `locations` is on or off.
  337. directSourceFile: null,
  338. // When enabled, parenthesized expressions are represented by
  339. // (non-standard) ParenthesizedExpression nodes
  340. preserveParens: false,
  341. plugins: {}
  342. };
  343. // Interpret and default an options object
  344. function getOptions(opts) {
  345. var options = {};
  346. for (var opt in defaultOptions)
  347. { options[opt] = opts && has(opts, opt) ? opts[opt] : defaultOptions[opt]; }
  348. if (options.ecmaVersion >= 2015)
  349. { options.ecmaVersion -= 2009; }
  350. if (options.allowReserved == null)
  351. { options.allowReserved = options.ecmaVersion < 5; }
  352. if (isArray(options.onToken)) {
  353. var tokens = options.onToken;
  354. options.onToken = function (token) { return tokens.push(token); };
  355. }
  356. if (isArray(options.onComment))
  357. { options.onComment = pushComment(options, options.onComment); }
  358. return options
  359. }
  360. function pushComment(options, array) {
  361. return function(block, text, start, end, startLoc, endLoc) {
  362. var comment = {
  363. type: block ? "Block" : "Line",
  364. value: text,
  365. start: start,
  366. end: end
  367. };
  368. if (options.locations)
  369. { comment.loc = new SourceLocation(this, startLoc, endLoc); }
  370. if (options.ranges)
  371. { comment.range = [start, end]; }
  372. array.push(comment);
  373. }
  374. }
  375. // Registered plugins
  376. var plugins = {};
  377. function keywordRegexp(words) {
  378. return new RegExp("^(?:" + words.replace(/ /g, "|") + ")$")
  379. }
  380. var Parser = function Parser(options, input, startPos) {
  381. this.options = options = getOptions(options);
  382. this.sourceFile = options.sourceFile;
  383. this.keywords = keywordRegexp(keywords[options.ecmaVersion >= 6 ? 6 : 5]);
  384. var reserved = "";
  385. if (!options.allowReserved) {
  386. for (var v = options.ecmaVersion;; v--)
  387. { if (reserved = reservedWords[v]) { break } }
  388. if (options.sourceType == "module") { reserved += " await"; }
  389. }
  390. this.reservedWords = keywordRegexp(reserved);
  391. var reservedStrict = (reserved ? reserved + " " : "") + reservedWords.strict;
  392. this.reservedWordsStrict = keywordRegexp(reservedStrict);
  393. this.reservedWordsStrictBind = keywordRegexp(reservedStrict + " " + reservedWords.strictBind);
  394. this.input = String(input);
  395. // Used to signal to callers of `readWord1` whether the word
  396. // contained any escape sequences. This is needed because words with
  397. // escape sequences must not be interpreted as keywords.
  398. this.containsEsc = false;
  399. // Load plugins
  400. this.loadPlugins(options.plugins);
  401. // Set up token state
  402. // The current position of the tokenizer in the input.
  403. if (startPos) {
  404. this.pos = startPos;
  405. this.lineStart = this.input.lastIndexOf("\n", startPos - 1) + 1;
  406. this.curLine = this.input.slice(0, this.lineStart).split(lineBreak).length;
  407. } else {
  408. this.pos = this.lineStart = 0;
  409. this.curLine = 1;
  410. }
  411. // Properties of the current token:
  412. // Its type
  413. this.type = types.eof;
  414. // For tokens that include more information than their type, the value
  415. this.value = null;
  416. // Its start and end offset
  417. this.start = this.end = this.pos;
  418. // And, if locations are used, the {line, column} object
  419. // corresponding to those offsets
  420. this.startLoc = this.endLoc = this.curPosition();
  421. // Position information for the previous token
  422. this.lastTokEndLoc = this.lastTokStartLoc = null;
  423. this.lastTokStart = this.lastTokEnd = this.pos;
  424. // The context stack is used to superficially track syntactic
  425. // context to predict whether a regular expression is allowed in a
  426. // given position.
  427. this.context = this.initialContext();
  428. this.exprAllowed = true;
  429. // Figure out if it's a module code.
  430. this.inModule = options.sourceType === "module";
  431. this.strict = this.inModule || this.strictDirective(this.pos);
  432. // Used to signify the start of a potential arrow function
  433. this.potentialArrowAt = -1;
  434. // Flags to track whether we are in a function, a generator, an async function.
  435. this.inFunction = this.inGenerator = this.inAsync = false;
  436. // Positions to delayed-check that yield/await does not exist in default parameters.
  437. this.yieldPos = this.awaitPos = 0;
  438. // Labels in scope.
  439. this.labels = [];
  440. // If enabled, skip leading hashbang line.
  441. if (this.pos === 0 && options.allowHashBang && this.input.slice(0, 2) === "#!")
  442. { this.skipLineComment(2); }
  443. // Scope tracking for duplicate variable names (see scope.js)
  444. this.scopeStack = [];
  445. this.enterFunctionScope();
  446. };
  447. // DEPRECATED Kept for backwards compatibility until 3.0 in case a plugin uses them
  448. Parser.prototype.isKeyword = function isKeyword (word) { return this.keywords.test(word) };
  449. Parser.prototype.isReservedWord = function isReservedWord (word) { return this.reservedWords.test(word) };
  450. Parser.prototype.extend = function extend (name, f) {
  451. this[name] = f(this[name]);
  452. };
  453. Parser.prototype.loadPlugins = function loadPlugins (pluginConfigs) {
  454. var this$1 = this;
  455. for (var name in pluginConfigs) {
  456. var plugin = plugins[name];
  457. if (!plugin) { throw new Error("Plugin '" + name + "' not found") }
  458. plugin(this$1, pluginConfigs[name]);
  459. }
  460. };
  461. Parser.prototype.parse = function parse () {
  462. var node = this.options.program || this.startNode();
  463. this.nextToken();
  464. return this.parseTopLevel(node)
  465. };
  466. var pp = Parser.prototype;
  467. // ## Parser utilities
  468. var literal = /^(?:'((?:\\.|[^'])*?)'|"((?:\\.|[^"])*?)"|;)/;
  469. pp.strictDirective = function(start) {
  470. var this$1 = this;
  471. for (;;) {
  472. skipWhiteSpace.lastIndex = start;
  473. start += skipWhiteSpace.exec(this$1.input)[0].length;
  474. var match = literal.exec(this$1.input.slice(start));
  475. if (!match) { return false }
  476. if ((match[1] || match[2]) == "use strict") { return true }
  477. start += match[0].length;
  478. }
  479. };
  480. // Predicate that tests whether the next token is of the given
  481. // type, and if yes, consumes it as a side effect.
  482. pp.eat = function(type) {
  483. if (this.type === type) {
  484. this.next();
  485. return true
  486. } else {
  487. return false
  488. }
  489. };
  490. // Tests whether parsed token is a contextual keyword.
  491. pp.isContextual = function(name) {
  492. return this.type === types.name && this.value === name
  493. };
  494. // Consumes contextual keyword if possible.
  495. pp.eatContextual = function(name) {
  496. return this.value === name && this.eat(types.name)
  497. };
  498. // Asserts that following token is given contextual keyword.
  499. pp.expectContextual = function(name) {
  500. if (!this.eatContextual(name)) { this.unexpected(); }
  501. };
  502. // Test whether a semicolon can be inserted at the current position.
  503. pp.canInsertSemicolon = function() {
  504. return this.type === types.eof ||
  505. this.type === types.braceR ||
  506. lineBreak.test(this.input.slice(this.lastTokEnd, this.start))
  507. };
  508. pp.insertSemicolon = function() {
  509. if (this.canInsertSemicolon()) {
  510. if (this.options.onInsertedSemicolon)
  511. { this.options.onInsertedSemicolon(this.lastTokEnd, this.lastTokEndLoc); }
  512. return true
  513. }
  514. };
  515. // Consume a semicolon, or, failing that, see if we are allowed to
  516. // pretend that there is a semicolon at this position.
  517. pp.semicolon = function() {
  518. if (!this.eat(types.semi) && !this.insertSemicolon()) { this.unexpected(); }
  519. };
  520. pp.afterTrailingComma = function(tokType, notNext) {
  521. if (this.type == tokType) {
  522. if (this.options.onTrailingComma)
  523. { this.options.onTrailingComma(this.lastTokStart, this.lastTokStartLoc); }
  524. if (!notNext)
  525. { this.next(); }
  526. return true
  527. }
  528. };
  529. // Expect a token of a given type. If found, consume it, otherwise,
  530. // raise an unexpected token error.
  531. pp.expect = function(type) {
  532. this.eat(type) || this.unexpected();
  533. };
  534. // Raise an unexpected token error.
  535. pp.unexpected = function(pos) {
  536. this.raise(pos != null ? pos : this.start, "Unexpected token");
  537. };
  538. function DestructuringErrors() {
  539. this.shorthandAssign =
  540. this.trailingComma =
  541. this.parenthesizedAssign =
  542. this.parenthesizedBind =
  543. -1;
  544. }
  545. pp.checkPatternErrors = function(refDestructuringErrors, isAssign) {
  546. if (!refDestructuringErrors) { return }
  547. if (refDestructuringErrors.trailingComma > -1)
  548. { this.raiseRecoverable(refDestructuringErrors.trailingComma, "Comma is not permitted after the rest element"); }
  549. var parens = isAssign ? refDestructuringErrors.parenthesizedAssign : refDestructuringErrors.parenthesizedBind;
  550. if (parens > -1) { this.raiseRecoverable(parens, "Parenthesized pattern"); }
  551. };
  552. pp.checkExpressionErrors = function(refDestructuringErrors, andThrow) {
  553. var pos = refDestructuringErrors ? refDestructuringErrors.shorthandAssign : -1;
  554. if (!andThrow) { return pos >= 0 }
  555. if (pos > -1) { this.raise(pos, "Shorthand property assignments are valid only in destructuring patterns"); }
  556. };
  557. pp.checkYieldAwaitInDefaultParams = function() {
  558. if (this.yieldPos && (!this.awaitPos || this.yieldPos < this.awaitPos))
  559. { this.raise(this.yieldPos, "Yield expression cannot be a default value"); }
  560. if (this.awaitPos)
  561. { this.raise(this.awaitPos, "Await expression cannot be a default value"); }
  562. };
  563. pp.isSimpleAssignTarget = function(expr) {
  564. if (expr.type === "ParenthesizedExpression")
  565. { return this.isSimpleAssignTarget(expr.expression) }
  566. return expr.type === "Identifier" || expr.type === "MemberExpression"
  567. };
  568. var pp$1 = Parser.prototype;
  569. // ### Statement parsing
  570. // Parse a program. Initializes the parser, reads any number of
  571. // statements, and wraps them in a Program node. Optionally takes a
  572. // `program` argument. If present, the statements will be appended
  573. // to its body instead of creating a new node.
  574. pp$1.parseTopLevel = function(node) {
  575. var this$1 = this;
  576. var exports = {};
  577. if (!node.body) { node.body = []; }
  578. while (this.type !== types.eof) {
  579. var stmt = this$1.parseStatement(true, true, exports);
  580. node.body.push(stmt);
  581. }
  582. this.next();
  583. if (this.options.ecmaVersion >= 6) {
  584. node.sourceType = this.options.sourceType;
  585. }
  586. return this.finishNode(node, "Program")
  587. };
  588. var loopLabel = {kind: "loop"};
  589. var switchLabel = {kind: "switch"};
  590. pp$1.isLet = function() {
  591. if (this.type !== types.name || this.options.ecmaVersion < 6 || this.value != "let") { return false }
  592. skipWhiteSpace.lastIndex = this.pos;
  593. var skip = skipWhiteSpace.exec(this.input);
  594. var next = this.pos + skip[0].length, nextCh = this.input.charCodeAt(next);
  595. if (nextCh === 91 || nextCh == 123) { return true } // '{' and '['
  596. if (isIdentifierStart(nextCh, true)) {
  597. var pos = next + 1;
  598. while (isIdentifierChar(this.input.charCodeAt(pos), true)) { ++pos; }
  599. var ident = this.input.slice(next, pos);
  600. if (!this.isKeyword(ident)) { return true }
  601. }
  602. return false
  603. };
  604. // check 'async [no LineTerminator here] function'
  605. // - 'async /*foo*/ function' is OK.
  606. // - 'async /*\n*/ function' is invalid.
  607. pp$1.isAsyncFunction = function() {
  608. if (this.type !== types.name || this.options.ecmaVersion < 8 || this.value != "async")
  609. { return false }
  610. skipWhiteSpace.lastIndex = this.pos;
  611. var skip = skipWhiteSpace.exec(this.input);
  612. var next = this.pos + skip[0].length;
  613. return !lineBreak.test(this.input.slice(this.pos, next)) &&
  614. this.input.slice(next, next + 8) === "function" &&
  615. (next + 8 == this.input.length || !isIdentifierChar(this.input.charAt(next + 8)))
  616. };
  617. // Parse a single statement.
  618. //
  619. // If expecting a statement and finding a slash operator, parse a
  620. // regular expression literal. This is to handle cases like
  621. // `if (foo) /blah/.exec(foo)`, where looking at the previous token
  622. // does not help.
  623. pp$1.parseStatement = function(declaration, topLevel, exports) {
  624. var starttype = this.type, node = this.startNode(), kind;
  625. if (this.isLet()) {
  626. starttype = types._var;
  627. kind = "let";
  628. }
  629. // Most types of statements are recognized by the keyword they
  630. // start with. Many are trivial to parse, some require a bit of
  631. // complexity.
  632. switch (starttype) {
  633. case types._break: case types._continue: return this.parseBreakContinueStatement(node, starttype.keyword)
  634. case types._debugger: return this.parseDebuggerStatement(node)
  635. case types._do: return this.parseDoStatement(node)
  636. case types._for: return this.parseForStatement(node)
  637. case types._function:
  638. if (!declaration && this.options.ecmaVersion >= 6) { this.unexpected(); }
  639. return this.parseFunctionStatement(node, false)
  640. case types._class:
  641. if (!declaration) { this.unexpected(); }
  642. return this.parseClass(node, true)
  643. case types._if: return this.parseIfStatement(node)
  644. case types._return: return this.parseReturnStatement(node)
  645. case types._switch: return this.parseSwitchStatement(node)
  646. case types._throw: return this.parseThrowStatement(node)
  647. case types._try: return this.parseTryStatement(node)
  648. case types._const: case types._var:
  649. kind = kind || this.value;
  650. if (!declaration && kind != "var") { this.unexpected(); }
  651. return this.parseVarStatement(node, kind)
  652. case types._while: return this.parseWhileStatement(node)
  653. case types._with: return this.parseWithStatement(node)
  654. case types.braceL: return this.parseBlock()
  655. case types.semi: return this.parseEmptyStatement(node)
  656. case types._export:
  657. case types._import:
  658. if (!this.options.allowImportExportEverywhere) {
  659. if (!topLevel)
  660. { this.raise(this.start, "'import' and 'export' may only appear at the top level"); }
  661. if (!this.inModule)
  662. { this.raise(this.start, "'import' and 'export' may appear only with 'sourceType: module'"); }
  663. }
  664. return starttype === types._import ? this.parseImport(node) : this.parseExport(node, exports)
  665. // If the statement does not start with a statement keyword or a
  666. // brace, it's an ExpressionStatement or LabeledStatement. We
  667. // simply start parsing an expression, and afterwards, if the
  668. // next token is a colon and the expression was a simple
  669. // Identifier node, we switch to interpreting it as a label.
  670. default:
  671. if (this.isAsyncFunction() && declaration) {
  672. this.next();
  673. return this.parseFunctionStatement(node, true)
  674. }
  675. var maybeName = this.value, expr = this.parseExpression();
  676. if (starttype === types.name && expr.type === "Identifier" && this.eat(types.colon))
  677. { return this.parseLabeledStatement(node, maybeName, expr) }
  678. else { return this.parseExpressionStatement(node, expr) }
  679. }
  680. };
  681. pp$1.parseBreakContinueStatement = function(node, keyword) {
  682. var this$1 = this;
  683. var isBreak = keyword == "break";
  684. this.next();
  685. if (this.eat(types.semi) || this.insertSemicolon()) { node.label = null; }
  686. else if (this.type !== types.name) { this.unexpected(); }
  687. else {
  688. node.label = this.parseIdent();
  689. this.semicolon();
  690. }
  691. // Verify that there is an actual destination to break or
  692. // continue to.
  693. var i = 0;
  694. for (; i < this.labels.length; ++i) {
  695. var lab = this$1.labels[i];
  696. if (node.label == null || lab.name === node.label.name) {
  697. if (lab.kind != null && (isBreak || lab.kind === "loop")) { break }
  698. if (node.label && isBreak) { break }
  699. }
  700. }
  701. if (i === this.labels.length) { this.raise(node.start, "Unsyntactic " + keyword); }
  702. return this.finishNode(node, isBreak ? "BreakStatement" : "ContinueStatement")
  703. };
  704. pp$1.parseDebuggerStatement = function(node) {
  705. this.next();
  706. this.semicolon();
  707. return this.finishNode(node, "DebuggerStatement")
  708. };
  709. pp$1.parseDoStatement = function(node) {
  710. this.next();
  711. this.labels.push(loopLabel);
  712. node.body = this.parseStatement(false);
  713. this.labels.pop();
  714. this.expect(types._while);
  715. node.test = this.parseParenExpression();
  716. if (this.options.ecmaVersion >= 6)
  717. { this.eat(types.semi); }
  718. else
  719. { this.semicolon(); }
  720. return this.finishNode(node, "DoWhileStatement")
  721. };
  722. // Disambiguating between a `for` and a `for`/`in` or `for`/`of`
  723. // loop is non-trivial. Basically, we have to parse the init `var`
  724. // statement or expression, disallowing the `in` operator (see
  725. // the second parameter to `parseExpression`), and then check
  726. // whether the next token is `in` or `of`. When there is no init
  727. // part (semicolon immediately after the opening parenthesis), it
  728. // is a regular `for` loop.
  729. pp$1.parseForStatement = function(node) {
  730. this.next();
  731. this.labels.push(loopLabel);
  732. this.enterLexicalScope();
  733. this.expect(types.parenL);
  734. if (this.type === types.semi) { return this.parseFor(node, null) }
  735. var isLet = this.isLet();
  736. if (this.type === types._var || this.type === types._const || isLet) {
  737. var init$1 = this.startNode(), kind = isLet ? "let" : this.value;
  738. this.next();
  739. this.parseVar(init$1, true, kind);
  740. this.finishNode(init$1, "VariableDeclaration");
  741. if ((this.type === types._in || (this.options.ecmaVersion >= 6 && this.isContextual("of"))) && init$1.declarations.length === 1 &&
  742. !(kind !== "var" && init$1.declarations[0].init))
  743. { return this.parseForIn(node, init$1) }
  744. return this.parseFor(node, init$1)
  745. }
  746. var refDestructuringErrors = new DestructuringErrors;
  747. var init = this.parseExpression(true, refDestructuringErrors);
  748. if (this.type === types._in || (this.options.ecmaVersion >= 6 && this.isContextual("of"))) {
  749. this.toAssignable(init);
  750. this.checkLVal(init);
  751. this.checkPatternErrors(refDestructuringErrors, true);
  752. return this.parseForIn(node, init)
  753. } else {
  754. this.checkExpressionErrors(refDestructuringErrors, true);
  755. }
  756. return this.parseFor(node, init)
  757. };
  758. pp$1.parseFunctionStatement = function(node, isAsync) {
  759. this.next();
  760. return this.parseFunction(node, true, false, isAsync)
  761. };
  762. pp$1.isFunction = function() {
  763. return this.type === types._function || this.isAsyncFunction()
  764. };
  765. pp$1.parseIfStatement = function(node) {
  766. this.next();
  767. node.test = this.parseParenExpression();
  768. // allow function declarations in branches, but only in non-strict mode
  769. node.consequent = this.parseStatement(!this.strict && this.isFunction());
  770. node.alternate = this.eat(types._else) ? this.parseStatement(!this.strict && this.isFunction()) : null;
  771. return this.finishNode(node, "IfStatement")
  772. };
  773. pp$1.parseReturnStatement = function(node) {
  774. if (!this.inFunction && !this.options.allowReturnOutsideFunction)
  775. { this.raise(this.start, "'return' outside of function"); }
  776. this.next();
  777. // In `return` (and `break`/`continue`), the keywords with
  778. // optional arguments, we eagerly look for a semicolon or the
  779. // possibility to insert one.
  780. if (this.eat(types.semi) || this.insertSemicolon()) { node.argument = null; }
  781. else { node.argument = this.parseExpression(); this.semicolon(); }
  782. return this.finishNode(node, "ReturnStatement")
  783. };
  784. pp$1.parseSwitchStatement = function(node) {
  785. var this$1 = this;
  786. this.next();
  787. node.discriminant = this.parseParenExpression();
  788. node.cases = [];
  789. this.expect(types.braceL);
  790. this.labels.push(switchLabel);
  791. this.enterLexicalScope();
  792. // Statements under must be grouped (by label) in SwitchCase
  793. // nodes. `cur` is used to keep the node that we are currently
  794. // adding statements to.
  795. var cur;
  796. for (var sawDefault = false; this.type != types.braceR;) {
  797. if (this$1.type === types._case || this$1.type === types._default) {
  798. var isCase = this$1.type === types._case;
  799. if (cur) { this$1.finishNode(cur, "SwitchCase"); }
  800. node.cases.push(cur = this$1.startNode());
  801. cur.consequent = [];
  802. this$1.next();
  803. if (isCase) {
  804. cur.test = this$1.parseExpression();
  805. } else {
  806. if (sawDefault) { this$1.raiseRecoverable(this$1.lastTokStart, "Multiple default clauses"); }
  807. sawDefault = true;
  808. cur.test = null;
  809. }
  810. this$1.expect(types.colon);
  811. } else {
  812. if (!cur) { this$1.unexpected(); }
  813. cur.consequent.push(this$1.parseStatement(true));
  814. }
  815. }
  816. this.exitLexicalScope();
  817. if (cur) { this.finishNode(cur, "SwitchCase"); }
  818. this.next(); // Closing brace
  819. this.labels.pop();
  820. return this.finishNode(node, "SwitchStatement")
  821. };
  822. pp$1.parseThrowStatement = function(node) {
  823. this.next();
  824. if (lineBreak.test(this.input.slice(this.lastTokEnd, this.start)))
  825. { this.raise(this.lastTokEnd, "Illegal newline after throw"); }
  826. node.argument = this.parseExpression();
  827. this.semicolon();
  828. return this.finishNode(node, "ThrowStatement")
  829. };
  830. // Reused empty array added for node fields that are always empty.
  831. var empty = [];
  832. pp$1.parseTryStatement = function(node) {
  833. this.next();
  834. node.block = this.parseBlock();
  835. node.handler = null;
  836. if (this.type === types._catch) {
  837. var clause = this.startNode();
  838. this.next();
  839. this.expect(types.parenL);
  840. clause.param = this.parseBindingAtom();
  841. this.enterLexicalScope();
  842. this.checkLVal(clause.param, "let");
  843. this.expect(types.parenR);
  844. clause.body = this.parseBlock(false);
  845. this.exitLexicalScope();
  846. node.handler = this.finishNode(clause, "CatchClause");
  847. }
  848. node.finalizer = this.eat(types._finally) ? this.parseBlock() : null;
  849. if (!node.handler && !node.finalizer)
  850. { this.raise(node.start, "Missing catch or finally clause"); }
  851. return this.finishNode(node, "TryStatement")
  852. };
  853. pp$1.parseVarStatement = function(node, kind) {
  854. this.next();
  855. this.parseVar(node, false, kind);
  856. this.semicolon();
  857. return this.finishNode(node, "VariableDeclaration")
  858. };
  859. pp$1.parseWhileStatement = function(node) {
  860. this.next();
  861. node.test = this.parseParenExpression();
  862. this.labels.push(loopLabel);
  863. node.body = this.parseStatement(false);
  864. this.labels.pop();
  865. return this.finishNode(node, "WhileStatement")
  866. };
  867. pp$1.parseWithStatement = function(node) {
  868. if (this.strict) { this.raise(this.start, "'with' in strict mode"); }
  869. this.next();
  870. node.object = this.parseParenExpression();
  871. node.body = this.parseStatement(false);
  872. return this.finishNode(node, "WithStatement")
  873. };
  874. pp$1.parseEmptyStatement = function(node) {
  875. this.next();
  876. return this.finishNode(node, "EmptyStatement")
  877. };
  878. pp$1.parseLabeledStatement = function(node, maybeName, expr) {
  879. var this$1 = this;
  880. for (var i$1 = 0, list = this$1.labels; i$1 < list.length; i$1 += 1)
  881. {
  882. var label = list[i$1];
  883. if (label.name === maybeName)
  884. { this$1.raise(expr.start, "Label '" + maybeName + "' is already declared");
  885. } }
  886. var kind = this.type.isLoop ? "loop" : this.type === types._switch ? "switch" : null;
  887. for (var i = this.labels.length - 1; i >= 0; i--) {
  888. var label$1 = this$1.labels[i];
  889. if (label$1.statementStart == node.start) {
  890. label$1.statementStart = this$1.start;
  891. label$1.kind = kind;
  892. } else { break }
  893. }
  894. this.labels.push({name: maybeName, kind: kind, statementStart: this.start});
  895. node.body = this.parseStatement(true);
  896. if (node.body.type == "ClassDeclaration" ||
  897. node.body.type == "VariableDeclaration" && node.body.kind != "var" ||
  898. node.body.type == "FunctionDeclaration" && (this.strict || node.body.generator))
  899. { this.raiseRecoverable(node.body.start, "Invalid labeled declaration"); }
  900. this.labels.pop();
  901. node.label = expr;
  902. return this.finishNode(node, "LabeledStatement")
  903. };
  904. pp$1.parseExpressionStatement = function(node, expr) {
  905. node.expression = expr;
  906. this.semicolon();
  907. return this.finishNode(node, "ExpressionStatement")
  908. };
  909. // Parse a semicolon-enclosed block of statements, handling `"use
  910. // strict"` declarations when `allowStrict` is true (used for
  911. // function bodies).
  912. pp$1.parseBlock = function(createNewLexicalScope) {
  913. var this$1 = this;
  914. if ( createNewLexicalScope === void 0 ) createNewLexicalScope = true;
  915. var node = this.startNode();
  916. node.body = [];
  917. this.expect(types.braceL);
  918. if (createNewLexicalScope) {
  919. this.enterLexicalScope();
  920. }
  921. while (!this.eat(types.braceR)) {
  922. var stmt = this$1.parseStatement(true);
  923. node.body.push(stmt);
  924. }
  925. if (createNewLexicalScope) {
  926. this.exitLexicalScope();
  927. }
  928. return this.finishNode(node, "BlockStatement")
  929. };
  930. // Parse a regular `for` loop. The disambiguation code in
  931. // `parseStatement` will already have parsed the init statement or
  932. // expression.
  933. pp$1.parseFor = function(node, init) {
  934. node.init = init;
  935. this.expect(types.semi);
  936. node.test = this.type === types.semi ? null : this.parseExpression();
  937. this.expect(types.semi);
  938. node.update = this.type === types.parenR ? null : this.parseExpression();
  939. this.expect(types.parenR);
  940. this.exitLexicalScope();
  941. node.body = this.parseStatement(false);
  942. this.labels.pop();
  943. return this.finishNode(node, "ForStatement")
  944. };
  945. // Parse a `for`/`in` and `for`/`of` loop, which are almost
  946. // same from parser's perspective.
  947. pp$1.parseForIn = function(node, init) {
  948. var type = this.type === types._in ? "ForInStatement" : "ForOfStatement";
  949. this.next();
  950. node.left = init;
  951. node.right = this.parseExpression();
  952. this.expect(types.parenR);
  953. this.exitLexicalScope();
  954. node.body = this.parseStatement(false);
  955. this.labels.pop();
  956. return this.finishNode(node, type)
  957. };
  958. // Parse a list of variable declarations.
  959. pp$1.parseVar = function(node, isFor, kind) {
  960. var this$1 = this;
  961. node.declarations = [];
  962. node.kind = kind;
  963. for (;;) {
  964. var decl = this$1.startNode();
  965. this$1.parseVarId(decl, kind);
  966. if (this$1.eat(types.eq)) {
  967. decl.init = this$1.parseMaybeAssign(isFor);
  968. } else if (kind === "const" && !(this$1.type === types._in || (this$1.options.ecmaVersion >= 6 && this$1.isContextual("of")))) {
  969. this$1.unexpected();
  970. } else if (decl.id.type != "Identifier" && !(isFor && (this$1.type === types._in || this$1.isContextual("of")))) {
  971. this$1.raise(this$1.lastTokEnd, "Complex binding patterns require an initialization value");
  972. } else {
  973. decl.init = null;
  974. }
  975. node.declarations.push(this$1.finishNode(decl, "VariableDeclarator"));
  976. if (!this$1.eat(types.comma)) { break }
  977. }
  978. return node
  979. };
  980. pp$1.parseVarId = function(decl, kind) {
  981. decl.id = this.parseBindingAtom(kind);
  982. this.checkLVal(decl.id, kind, false);
  983. };
  984. // Parse a function declaration or literal (depending on the
  985. // `isStatement` parameter).
  986. pp$1.parseFunction = function(node, isStatement, allowExpressionBody, isAsync) {
  987. this.initFunction(node);
  988. if (this.options.ecmaVersion >= 6 && !isAsync)
  989. { node.generator = this.eat(types.star); }
  990. if (this.options.ecmaVersion >= 8)
  991. { node.async = !!isAsync; }
  992. if (isStatement) {
  993. node.id = isStatement === "nullableID" && this.type != types.name ? null : this.parseIdent();
  994. if (node.id) {
  995. this.checkLVal(node.id, "var");
  996. }
  997. }
  998. var oldInGen = this.inGenerator, oldInAsync = this.inAsync,
  999. oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldInFunc = this.inFunction;
  1000. this.inGenerator = node.generator;
  1001. this.inAsync = node.async;
  1002. this.yieldPos = 0;
  1003. this.awaitPos = 0;
  1004. this.inFunction = true;
  1005. this.enterFunctionScope();
  1006. if (!isStatement)
  1007. { node.id = this.type == types.name ? this.parseIdent() : null; }
  1008. this.parseFunctionParams(node);
  1009. this.parseFunctionBody(node, allowExpressionBody);
  1010. this.inGenerator = oldInGen;
  1011. this.inAsync = oldInAsync;
  1012. this.yieldPos = oldYieldPos;
  1013. this.awaitPos = oldAwaitPos;
  1014. this.inFunction = oldInFunc;
  1015. return this.finishNode(node, isStatement ? "FunctionDeclaration" : "FunctionExpression")
  1016. };
  1017. pp$1.parseFunctionParams = function(node) {
  1018. this.expect(types.parenL);
  1019. node.params = this.parseBindingList(types.parenR, false, this.options.ecmaVersion >= 8);
  1020. this.checkYieldAwaitInDefaultParams();
  1021. };
  1022. // Parse a class declaration or literal (depending on the
  1023. // `isStatement` parameter).
  1024. pp$1.parseClass = function(node, isStatement) {
  1025. var this$1 = this;
  1026. this.next();
  1027. this.parseClassId(node, isStatement);
  1028. this.parseClassSuper(node);
  1029. var classBody = this.startNode();
  1030. var hadConstructor = false;
  1031. classBody.body = [];
  1032. this.expect(types.braceL);
  1033. while (!this.eat(types.braceR)) {
  1034. if (this$1.eat(types.semi)) { continue }
  1035. var method = this$1.startNode();
  1036. var isGenerator = this$1.eat(types.star);
  1037. var isAsync = false;
  1038. var isMaybeStatic = this$1.type === types.name && this$1.value === "static";
  1039. this$1.parsePropertyName(method);
  1040. method.static = isMaybeStatic && this$1.type !== types.parenL;
  1041. if (method.static) {
  1042. if (isGenerator) { this$1.unexpected(); }
  1043. isGenerator = this$1.eat(types.star);
  1044. this$1.parsePropertyName(method);
  1045. }
  1046. if (this$1.options.ecmaVersion >= 8 && !isGenerator && !method.computed &&
  1047. method.key.type === "Identifier" && method.key.name === "async" && this$1.type !== types.parenL &&
  1048. !this$1.canInsertSemicolon()) {
  1049. isAsync = true;
  1050. this$1.parsePropertyName(method);
  1051. }
  1052. method.kind = "method";
  1053. var isGetSet = false;
  1054. if (!method.computed) {
  1055. var key = method.key;
  1056. if (!isGenerator && !isAsync && key.type === "Identifier" && this$1.type !== types.parenL && (key.name === "get" || key.name === "set")) {
  1057. isGetSet = true;
  1058. method.kind = key.name;
  1059. key = this$1.parsePropertyName(method);
  1060. }
  1061. if (!method.static && (key.type === "Identifier" && key.name === "constructor" ||
  1062. key.type === "Literal" && key.value === "constructor")) {
  1063. if (hadConstructor) { this$1.raise(key.start, "Duplicate constructor in the same class"); }
  1064. if (isGetSet) { this$1.raise(key.start, "Constructor can't have get/set modifier"); }
  1065. if (isGenerator) { this$1.raise(key.start, "Constructor can't be a generator"); }
  1066. if (isAsync) { this$1.raise(key.start, "Constructor can't be an async method"); }
  1067. method.kind = "constructor";
  1068. hadConstructor = true;
  1069. }
  1070. }
  1071. this$1.parseClassMethod(classBody, method, isGenerator, isAsync);
  1072. if (isGetSet) {
  1073. var paramCount = method.kind === "get" ? 0 : 1;
  1074. if (method.value.params.length !== paramCount) {
  1075. var start = method.value.start;
  1076. if (method.kind === "get")
  1077. { this$1.raiseRecoverable(start, "getter should have no params"); }
  1078. else
  1079. { this$1.raiseRecoverable(start, "setter should have exactly one param"); }
  1080. } else {
  1081. if (method.kind === "set" && method.value.params[0].type === "RestElement")
  1082. { this$1.raiseRecoverable(method.value.params[0].start, "Setter cannot use rest params"); }
  1083. }
  1084. }
  1085. }
  1086. node.body = this.finishNode(classBody, "ClassBody");
  1087. return this.finishNode(node, isStatement ? "ClassDeclaration" : "ClassExpression")
  1088. };
  1089. pp$1.parseClassMethod = function(classBody, method, isGenerator, isAsync) {
  1090. method.value = this.parseMethod(isGenerator, isAsync);
  1091. classBody.body.push(this.finishNode(method, "MethodDefinition"));
  1092. };
  1093. pp$1.parseClassId = function(node, isStatement) {
  1094. node.id = this.type === types.name ? this.parseIdent() : isStatement === true ? this.unexpected() : null;
  1095. };
  1096. pp$1.parseClassSuper = function(node) {
  1097. node.superClass = this.eat(types._extends) ? this.parseExprSubscripts() : null;
  1098. };
  1099. // Parses module export declaration.
  1100. pp$1.parseExport = function(node, exports) {
  1101. var this$1 = this;
  1102. this.next();
  1103. // export * from '...'
  1104. if (this.eat(types.star)) {
  1105. this.expectContextual("from");
  1106. node.source = this.type === types.string ? this.parseExprAtom() : this.unexpected();
  1107. this.semicolon();
  1108. return this.finishNode(node, "ExportAllDeclaration")
  1109. }
  1110. if (this.eat(types._default)) { // export default ...
  1111. this.checkExport(exports, "default", this.lastTokStart);
  1112. var isAsync;
  1113. if (this.type === types._function || (isAsync = this.isAsyncFunction())) {
  1114. var fNode = this.startNode();
  1115. this.next();
  1116. if (isAsync) { this.next(); }
  1117. node.declaration = this.parseFunction(fNode, "nullableID", false, isAsync);
  1118. } else if (this.type === types._class) {
  1119. var cNode = this.startNode();
  1120. node.declaration = this.parseClass(cNode, "nullableID");
  1121. } else {
  1122. node.declaration = this.parseMaybeAssign();
  1123. this.semicolon();
  1124. }
  1125. return this.finishNode(node, "ExportDefaultDeclaration")
  1126. }
  1127. // export var|const|let|function|class ...
  1128. if (this.shouldParseExportStatement()) {
  1129. node.declaration = this.parseStatement(true);
  1130. if (node.declaration.type === "VariableDeclaration")
  1131. { this.checkVariableExport(exports, node.declaration.declarations); }
  1132. else
  1133. { this.checkExport(exports, node.declaration.id.name, node.declaration.id.start); }
  1134. node.specifiers = [];
  1135. node.source = null;
  1136. } else { // export { x, y as z } [from '...']
  1137. node.declaration = null;
  1138. node.specifiers = this.parseExportSpecifiers(exports);
  1139. if (this.eatContextual("from")) {
  1140. node.source = this.type === types.string ? this.parseExprAtom() : this.unexpected();
  1141. } else {
  1142. // check for keywords used as local names
  1143. for (var i = 0, list = node.specifiers; i < list.length; i += 1) {
  1144. var spec = list[i];
  1145. this$1.checkUnreserved(spec.local);
  1146. }
  1147. node.source = null;
  1148. }
  1149. this.semicolon();
  1150. }
  1151. return this.finishNode(node, "ExportNamedDeclaration")
  1152. };
  1153. pp$1.checkExport = function(exports, name, pos) {
  1154. if (!exports) { return }
  1155. if (has(exports, name))
  1156. { this.raiseRecoverable(pos, "Duplicate export '" + name + "'"); }
  1157. exports[name] = true;
  1158. };
  1159. pp$1.checkPatternExport = function(exports, pat) {
  1160. var this$1 = this;
  1161. var type = pat.type;
  1162. if (type == "Identifier")
  1163. { this.checkExport(exports, pat.name, pat.start); }
  1164. else if (type == "ObjectPattern")
  1165. { for (var i = 0, list = pat.properties; i < list.length; i += 1)
  1166. {
  1167. var prop = list[i];
  1168. this$1.checkPatternExport(exports, prop.value);
  1169. } }
  1170. else if (type == "ArrayPattern")
  1171. { for (var i$1 = 0, list$1 = pat.elements; i$1 < list$1.length; i$1 += 1) {
  1172. var elt = list$1[i$1];
  1173. if (elt) { this$1.checkPatternExport(exports, elt); }
  1174. } }
  1175. else if (type == "AssignmentPattern")
  1176. { this.checkPatternExport(exports, pat.left); }
  1177. else if (type == "ParenthesizedExpression")
  1178. { this.checkPatternExport(exports, pat.expression); }
  1179. };
  1180. pp$1.checkVariableExport = function(exports, decls) {
  1181. var this$1 = this;
  1182. if (!exports) { return }
  1183. for (var i = 0, list = decls; i < list.length; i += 1)
  1184. {
  1185. var decl = list[i];
  1186. this$1.checkPatternExport(exports, decl.id);
  1187. }
  1188. };
  1189. pp$1.shouldParseExportStatement = function() {
  1190. return this.type.keyword === "var" ||
  1191. this.type.keyword === "const" ||
  1192. this.type.keyword === "class" ||
  1193. this.type.keyword === "function" ||
  1194. this.isLet() ||
  1195. this.isAsyncFunction()
  1196. };
  1197. // Parses a comma-separated list of module exports.
  1198. pp$1.parseExportSpecifiers = function(exports) {
  1199. var this$1 = this;
  1200. var nodes = [], first = true;
  1201. // export { x, y as z } [from '...']
  1202. this.expect(types.braceL);
  1203. while (!this.eat(types.braceR)) {
  1204. if (!first) {
  1205. this$1.expect(types.comma);
  1206. if (this$1.afterTrailingComma(types.braceR)) { break }
  1207. } else { first = false; }
  1208. var node = this$1.startNode();
  1209. node.local = this$1.parseIdent(true);
  1210. node.exported = this$1.eatContextual("as") ? this$1.parseIdent(true) : node.local;
  1211. this$1.checkExport(exports, node.exported.name, node.exported.start);
  1212. nodes.push(this$1.finishNode(node, "ExportSpecifier"));
  1213. }
  1214. return nodes
  1215. };
  1216. // Parses import declaration.
  1217. pp$1.parseImport = function(node) {
  1218. this.next();
  1219. // import '...'
  1220. if (this.type === types.string) {
  1221. node.specifiers = empty;
  1222. node.source = this.parseExprAtom();
  1223. } else {
  1224. node.specifiers = this.parseImportSpecifiers();
  1225. this.expectContextual("from");
  1226. node.source = this.type === types.string ? this.parseExprAtom() : this.unexpected();
  1227. }
  1228. this.semicolon();
  1229. return this.finishNode(node, "ImportDeclaration")
  1230. };
  1231. // Parses a comma-separated list of module imports.
  1232. pp$1.parseImportSpecifiers = function() {
  1233. var this$1 = this;
  1234. var nodes = [], first = true;
  1235. if (this.type === types.name) {
  1236. // import defaultObj, { x, y as z } from '...'
  1237. var node = this.startNode();
  1238. node.local = this.parseIdent();
  1239. this.checkLVal(node.local, "let");
  1240. nodes.push(this.finishNode(node, "ImportDefaultSpecifier"));
  1241. if (!this.eat(types.comma)) { return nodes }
  1242. }
  1243. if (this.type === types.star) {
  1244. var node$1 = this.startNode();
  1245. this.next();
  1246. this.expectContextual("as");
  1247. node$1.local = this.parseIdent();
  1248. this.checkLVal(node$1.local, "let");
  1249. nodes.push(this.finishNode(node$1, "ImportNamespaceSpecifier"));
  1250. return nodes
  1251. }
  1252. this.expect(types.braceL);
  1253. while (!this.eat(types.braceR)) {
  1254. if (!first) {
  1255. this$1.expect(types.comma);
  1256. if (this$1.afterTrailingComma(types.braceR)) { break }
  1257. } else { first = false; }
  1258. var node$2 = this$1.startNode();
  1259. node$2.imported = this$1.parseIdent(true);
  1260. if (this$1.eatContextual("as")) {
  1261. node$2.local = this$1.parseIdent();
  1262. } else {
  1263. this$1.checkUnreserved(node$2.imported);
  1264. node$2.local = node$2.imported;
  1265. }
  1266. this$1.checkLVal(node$2.local, "let");
  1267. nodes.push(this$1.finishNode(node$2, "ImportSpecifier"));
  1268. }
  1269. return nodes
  1270. };
  1271. var pp$2 = Parser.prototype;
  1272. // Convert existing expression atom to assignable pattern
  1273. // if possible.
  1274. pp$2.toAssignable = function(node, isBinding) {
  1275. var this$1 = this;
  1276. if (this.options.ecmaVersion >= 6 && node) {
  1277. switch (node.type) {
  1278. case "Identifier":
  1279. if (this.inAsync && node.name === "await")
  1280. { this.raise(node.start, "Can not use 'await' as identifier inside an async function"); }
  1281. break
  1282. case "ObjectPattern":
  1283. case "ArrayPattern":
  1284. break
  1285. case "ObjectExpression":
  1286. node.type = "ObjectPattern";
  1287. for (var i = 0, list = node.properties; i < list.length; i += 1) {
  1288. var prop = list[i];
  1289. if (prop.kind !== "init") { this$1.raise(prop.key.start, "Object pattern can't contain getter or setter"); }
  1290. this$1.toAssignable(prop.value, isBinding);
  1291. }
  1292. break
  1293. case "ArrayExpression":
  1294. node.type = "ArrayPattern";
  1295. this.toAssignableList(node.elements, isBinding);
  1296. break
  1297. case "AssignmentExpression":
  1298. if (node.operator === "=") {
  1299. node.type = "AssignmentPattern";
  1300. delete node.operator;
  1301. this.toAssignable(node.left, isBinding);
  1302. // falls through to AssignmentPattern
  1303. } else {
  1304. this.raise(node.left.end, "Only '=' operator can be used for specifying default value.");
  1305. break
  1306. }
  1307. case "AssignmentPattern":
  1308. break
  1309. case "ParenthesizedExpression":
  1310. this.toAssignable(node.expression, isBinding);
  1311. break
  1312. case "MemberExpression":
  1313. if (!isBinding) { break }
  1314. default:
  1315. this.raise(node.start, "Assigning to rvalue");
  1316. }
  1317. }
  1318. return node
  1319. };
  1320. // Convert list of expression atoms to binding list.
  1321. pp$2.toAssignableList = function(exprList, isBinding) {
  1322. var this$1 = this;
  1323. var end = exprList.length;
  1324. if (end) {
  1325. var last = exprList[end - 1];
  1326. if (last && last.type == "RestElement") {
  1327. --end;
  1328. } else if (last && last.type == "SpreadElement") {
  1329. last.type = "RestElement";
  1330. var arg = last.argument;
  1331. this.toAssignable(arg, isBinding);
  1332. --end;
  1333. }
  1334. if (this.options.ecmaVersion === 6 && isBinding && last && last.type === "RestElement" && last.argument.type !== "Identifier")
  1335. { this.unexpected(last.argument.start); }
  1336. }
  1337. for (var i = 0; i < end; i++) {
  1338. var elt = exprList[i];
  1339. if (elt) { this$1.toAssignable(elt, isBinding); }
  1340. }
  1341. return exprList
  1342. };
  1343. // Parses spread element.
  1344. pp$2.parseSpread = function(refDestructuringErrors) {
  1345. var node = this.startNode();
  1346. this.next();
  1347. node.argument = this.parseMaybeAssign(false, refDestructuringErrors);
  1348. return this.finishNode(node, "SpreadElement")
  1349. };
  1350. pp$2.parseRestBinding = function() {
  1351. var node = this.startNode();
  1352. this.next();
  1353. // RestElement inside of a function parameter must be an identifier
  1354. if (this.options.ecmaVersion === 6 && this.type !== types.name)
  1355. { this.unexpected(); }
  1356. node.argument = this.parseBindingAtom();
  1357. return this.finishNode(node, "RestElement")
  1358. };
  1359. // Parses lvalue (assignable) atom.
  1360. pp$2.parseBindingAtom = function() {
  1361. if (this.options.ecmaVersion < 6) { return this.parseIdent() }
  1362. switch (this.type) {
  1363. case types.name:
  1364. return this.parseIdent()
  1365. case types.bracketL:
  1366. var node = this.startNode();
  1367. this.next();
  1368. node.elements = this.parseBindingList(types.bracketR, true, true);
  1369. return this.finishNode(node, "ArrayPattern")
  1370. case types.braceL:
  1371. return this.parseObj(true)
  1372. default:
  1373. this.unexpected();
  1374. }
  1375. };
  1376. pp$2.parseBindingList = function(close, allowEmpty, allowTrailingComma) {
  1377. var this$1 = this;
  1378. var elts = [], first = true;
  1379. while (!this.eat(close)) {
  1380. if (first) { first = false; }
  1381. else { this$1.expect(types.comma); }
  1382. if (allowEmpty && this$1.type === types.comma) {
  1383. elts.push(null);
  1384. } else if (allowTrailingComma && this$1.afterTrailingComma(close)) {
  1385. break
  1386. } else if (this$1.type === types.ellipsis) {
  1387. var rest = this$1.parseRestBinding();
  1388. this$1.parseBindingListItem(rest);
  1389. elts.push(rest);
  1390. if (this$1.type === types.comma) { this$1.raise(this$1.start, "Comma is not permitted after the rest element"); }
  1391. this$1.expect(close);
  1392. break
  1393. } else {
  1394. var elem = this$1.parseMaybeDefault(this$1.start, this$1.startLoc);
  1395. this$1.parseBindingListItem(elem);
  1396. elts.push(elem);
  1397. }
  1398. }
  1399. return elts
  1400. };
  1401. pp$2.parseBindingListItem = function(param) {
  1402. return param
  1403. };
  1404. // Parses assignment pattern around given atom if possible.
  1405. pp$2.parseMaybeDefault = function(startPos, startLoc, left) {
  1406. left = left || this.parseBindingAtom();
  1407. if (this.options.ecmaVersion < 6 || !this.eat(types.eq)) { return left }
  1408. var node = this.startNodeAt(startPos, startLoc);
  1409. node.left = left;
  1410. node.right = this.parseMaybeAssign();
  1411. return this.finishNode(node, "AssignmentPattern")
  1412. };
  1413. // Verify that a node is an lval — something that can be assigned
  1414. // to.
  1415. // bindingType can be either:
  1416. // 'var' indicating that the lval creates a 'var' binding
  1417. // 'let' indicating that the lval creates a lexical ('let' or 'const') binding
  1418. // 'none' indicating that the binding should be checked for illegal identifiers, but not for duplicate references
  1419. pp$2.checkLVal = function(expr, bindingType, checkClashes) {
  1420. var this$1 = this;
  1421. switch (expr.type) {
  1422. case "Identifier":
  1423. if (this.strict && this.reservedWordsStrictBind.test(expr.name))
  1424. { this.raiseRecoverable(expr.start, (bindingType ? "Binding " : "Assigning to ") + expr.name + " in strict mode"); }
  1425. if (checkClashes) {
  1426. if (has(checkClashes, expr.name))
  1427. { this.raiseRecoverable(expr.start, "Argument name clash"); }
  1428. checkClashes[expr.name] = true;
  1429. }
  1430. if (bindingType && bindingType !== "none") {
  1431. if (
  1432. bindingType === "var" && !this.canDeclareVarName(expr.name) ||
  1433. bindingType !== "var" && !this.canDeclareLexicalName(expr.name)
  1434. ) {
  1435. this.raiseRecoverable(expr.start, ("Identifier '" + (expr.name) + "' has already been declared"));
  1436. }
  1437. if (bindingType === "var") {
  1438. this.declareVarName(expr.name);
  1439. } else {
  1440. this.declareLexicalName(expr.name);
  1441. }
  1442. }
  1443. break
  1444. case "MemberExpression":
  1445. if (bindingType) { this.raiseRecoverable(expr.start, (bindingType ? "Binding" : "Assigning to") + " member expression"); }
  1446. break
  1447. case "ObjectPattern":
  1448. for (var i = 0, list = expr.properties; i < list.length; i += 1)
  1449. {
  1450. var prop = list[i];
  1451. this$1.checkLVal(prop.value, bindingType, checkClashes);
  1452. }
  1453. break
  1454. case "ArrayPattern":
  1455. for (var i$1 = 0, list$1 = expr.elements; i$1 < list$1.length; i$1 += 1) {
  1456. var elem = list$1[i$1];
  1457. if (elem) { this$1.checkLVal(elem, bindingType, checkClashes); }
  1458. }
  1459. break
  1460. case "AssignmentPattern":
  1461. this.checkLVal(expr.left, bindingType, checkClashes);
  1462. break
  1463. case "RestElement":
  1464. this.checkLVal(expr.argument, bindingType, checkClashes);
  1465. break
  1466. case "ParenthesizedExpression":
  1467. this.checkLVal(expr.expression, bindingType, checkClashes);
  1468. break
  1469. default:
  1470. this.raise(expr.start, (bindingType ? "Binding" : "Assigning to") + " rvalue");
  1471. }
  1472. };
  1473. // A recursive descent parser operates by defining functions for all
  1474. // syntactic elements, and recursively calling those, each function
  1475. // advancing the input stream and returning an AST node. Precedence
  1476. // of constructs (for example, the fact that `!x[1]` means `!(x[1])`
  1477. // instead of `(!x)[1]` is handled by the fact that the parser
  1478. // function that parses unary prefix operators is called first, and
  1479. // in turn calls the function that parses `[]` subscripts — that
  1480. // way, it'll receive the node for `x[1]` already parsed, and wraps
  1481. // *that* in the unary operator node.
  1482. //
  1483. // Acorn uses an [operator precedence parser][opp] to handle binary
  1484. // operator precedence, because it is much more compact than using
  1485. // the technique outlined above, which uses different, nesting
  1486. // functions to specify precedence, for all of the ten binary
  1487. // precedence levels that JavaScript defines.
  1488. //
  1489. // [opp]: http://en.wikipedia.org/wiki/Operator-precedence_parser
  1490. var pp$3 = Parser.prototype;
  1491. // Check if property name clashes with already added.
  1492. // Object/class getters and setters are not allowed to clash —
  1493. // either with each other or with an init property — and in
  1494. // strict mode, init properties are also not allowed to be repeated.
  1495. pp$3.checkPropClash = function(prop, propHash) {
  1496. if (this.options.ecmaVersion >= 6 && (prop.computed || prop.method || prop.shorthand))
  1497. { return }
  1498. var key = prop.key;
  1499. var name;
  1500. switch (key.type) {
  1501. case "Identifier": name = key.name; break
  1502. case "Literal": name = String(key.value); break
  1503. default: return
  1504. }
  1505. var kind = prop.kind;
  1506. if (this.options.ecmaVersion >= 6) {
  1507. if (name === "__proto__" && kind === "init") {
  1508. if (propHash.proto) { this.raiseRecoverable(key.start, "Redefinition of __proto__ property"); }
  1509. propHash.proto = true;
  1510. }
  1511. return
  1512. }
  1513. name = "$" + name;
  1514. var other = propHash[name];
  1515. if (other) {
  1516. var redefinition;
  1517. if (kind === "init") {
  1518. redefinition = this.strict && other.init || other.get || other.set;
  1519. } else {
  1520. redefinition = other.init || other[kind];
  1521. }
  1522. if (redefinition)
  1523. { this.raiseRecoverable(key.start, "Redefinition of property"); }
  1524. } else {
  1525. other = propHash[name] = {
  1526. init: false,
  1527. get: false,
  1528. set: false
  1529. };
  1530. }
  1531. other[kind] = true;
  1532. };
  1533. // ### Expression parsing
  1534. // These nest, from the most general expression type at the top to
  1535. // 'atomic', nondivisible expression types at the bottom. Most of
  1536. // the functions will simply let the function(s) below them parse,
  1537. // and, *if* the syntactic construct they handle is present, wrap
  1538. // the AST node that the inner parser gave them in another node.
  1539. // Parse a full expression. The optional arguments are used to
  1540. // forbid the `in` operator (in for loops initalization expressions)
  1541. // and provide reference for storing '=' operator inside shorthand
  1542. // property assignment in contexts where both object expression
  1543. // and object pattern might appear (so it's possible to raise
  1544. // delayed syntax error at correct position).
  1545. pp$3.parseExpression = function(noIn, refDestructuringErrors) {
  1546. var this$1 = this;
  1547. var startPos = this.start, startLoc = this.startLoc;
  1548. var expr = this.parseMaybeAssign(noIn, refDestructuringErrors);
  1549. if (this.type === types.comma) {
  1550. var node = this.startNodeAt(startPos, startLoc);
  1551. node.expressions = [expr];
  1552. while (this.eat(types.comma)) { node.expressions.push(this$1.parseMaybeAssign(noIn, refDestructuringErrors)); }
  1553. return this.finishNode(node, "SequenceExpression")
  1554. }
  1555. return expr
  1556. };
  1557. // Parse an assignment expression. This includes applications of
  1558. // operators like `+=`.
  1559. pp$3.parseMaybeAssign = function(noIn, refDestructuringErrors, afterLeftParse) {
  1560. if (this.inGenerator && this.isContextual("yield")) { return this.parseYield() }
  1561. var ownDestructuringErrors = false, oldParenAssign = -1, oldTrailingComma = -1;
  1562. if (refDestructuringErrors) {
  1563. oldParenAssign = refDestructuringErrors.parenthesizedAssign;
  1564. oldTrailingComma = refDestructuringErrors.trailingComma;
  1565. refDestructuringErrors.parenthesizedAssign = refDestructuringErrors.trailingComma = -1;
  1566. } else {
  1567. refDestructuringErrors = new DestructuringErrors;
  1568. ownDestructuringErrors = true;
  1569. }
  1570. var startPos = this.start, startLoc = this.startLoc;
  1571. if (this.type == types.parenL || this.type == types.name)
  1572. { this.potentialArrowAt = this.start; }
  1573. var left = this.parseMaybeConditional(noIn, refDestructuringErrors);
  1574. if (afterLeftParse) { left = afterLeftParse.call(this, left, startPos, startLoc); }
  1575. if (this.type.isAssign) {
  1576. this.checkPatternErrors(refDestructuringErrors, true);
  1577. if (!ownDestructuringErrors) { DestructuringErrors.call(refDestructuringErrors); }
  1578. var node = this.startNodeAt(startPos, startLoc);
  1579. node.operator = this.value;
  1580. node.left = this.type === types.eq ? this.toAssignable(left) : left;
  1581. refDestructuringErrors.shorthandAssign = -1; // reset because shorthand default was used correctly
  1582. this.checkLVal(left);
  1583. this.next();
  1584. node.right = this.parseMaybeAssign(noIn);
  1585. return this.finishNode(node, "AssignmentExpression")
  1586. } else {
  1587. if (ownDestructuringErrors) { this.checkExpressionErrors(refDestructuringErrors, true); }
  1588. }
  1589. if (oldParenAssign > -1) { refDestructuringErrors.parenthesizedAssign = oldParenAssign; }
  1590. if (oldTrailingComma > -1) { refDestructuringErrors.trailingComma = oldTrailingComma; }
  1591. return left
  1592. };
  1593. // Parse a ternary conditional (`?:`) operator.
  1594. pp$3.parseMaybeConditional = function(noIn, refDestructuringErrors) {
  1595. var startPos = this.start, startLoc = this.startLoc;
  1596. var expr = this.parseExprOps(noIn, refDestructuringErrors);
  1597. if (this.checkExpressionErrors(refDestructuringErrors)) { return expr }
  1598. if (this.eat(types.question)) {
  1599. var node = this.startNodeAt(startPos, startLoc);
  1600. node.test = expr;
  1601. node.consequent = this.parseMaybeAssign();
  1602. this.expect(types.colon);
  1603. node.alternate = this.parseMaybeAssign(noIn);
  1604. return this.finishNode(node, "ConditionalExpression")
  1605. }
  1606. return expr
  1607. };
  1608. // Start the precedence parser.
  1609. pp$3.parseExprOps = function(noIn, refDestructuringErrors) {
  1610. var startPos = this.start, startLoc = this.startLoc;
  1611. var expr = this.parseMaybeUnary(refDestructuringErrors, false);
  1612. if (this.checkExpressionErrors(refDestructuringErrors)) { return expr }
  1613. return expr.start == startPos && expr.type === "ArrowFunctionExpression" ? expr : this.parseExprOp(expr, startPos, startLoc, -1, noIn)
  1614. };
  1615. // Parse binary operators with the operator precedence parsing
  1616. // algorithm. `left` is the left-hand side of the operator.
  1617. // `minPrec` provides context that allows the function to stop and
  1618. // defer further parser to one of its callers when it encounters an
  1619. // operator that has a lower precedence than the set it is parsing.
  1620. pp$3.parseExprOp = function(left, leftStartPos, leftStartLoc, minPrec, noIn) {
  1621. var prec = this.type.binop;
  1622. if (prec != null && (!noIn || this.type !== types._in)) {
  1623. if (prec > minPrec) {
  1624. var logical = this.type === types.logicalOR || this.type === types.logicalAND;
  1625. var op = this.value;
  1626. this.next();
  1627. var startPos = this.start, startLoc = this.startLoc;
  1628. var right = this.parseExprOp(this.parseMaybeUnary(null, false), startPos, startLoc, prec, noIn);
  1629. var node = this.buildBinary(leftStartPos, leftStartLoc, left, right, op, logical);
  1630. return this.parseExprOp(node, leftStartPos, leftStartLoc, minPrec, noIn)
  1631. }
  1632. }
  1633. return left
  1634. };
  1635. pp$3.buildBinary = function(startPos, startLoc, left, right, op, logical) {
  1636. var node = this.startNodeAt(startPos, startLoc);
  1637. node.left = left;
  1638. node.operator = op;
  1639. node.right = right;
  1640. return this.finishNode(node, logical ? "LogicalExpression" : "BinaryExpression")
  1641. };
  1642. // Parse unary operators, both prefix and postfix.
  1643. pp$3.parseMaybeUnary = function(refDestructuringErrors, sawUnary) {
  1644. var this$1 = this;
  1645. var startPos = this.start, startLoc = this.startLoc, expr;
  1646. if (this.inAsync && this.isContextual("await")) {
  1647. expr = this.parseAwait(refDestructuringErrors);
  1648. sawUnary = true;
  1649. } else if (this.type.prefix) {
  1650. var node = this.startNode(), update = this.type === types.incDec;
  1651. node.operator = this.value;
  1652. node.prefix = true;
  1653. this.next();
  1654. node.argument = this.parseMaybeUnary(null, true);
  1655. this.checkExpressionErrors(refDestructuringErrors, true);
  1656. if (update) { this.checkLVal(node.argument); }
  1657. else if (this.strict && node.operator === "delete" &&
  1658. node.argument.type === "Identifier")
  1659. { this.raiseRecoverable(node.start, "Deleting local variable in strict mode"); }
  1660. else { sawUnary = true; }
  1661. expr = this.finishNode(node, update ? "UpdateExpression" : "UnaryExpression");
  1662. } else {
  1663. expr = this.parseExprSubscripts(refDestructuringErrors);
  1664. if (this.checkExpressionErrors(refDestructuringErrors)) { return expr }
  1665. while (this.type.postfix && !this.canInsertSemicolon()) {
  1666. var node$1 = this$1.startNodeAt(startPos, startLoc);
  1667. node$1.operator = this$1.value;
  1668. node$1.prefix = false;
  1669. node$1.argument = expr;
  1670. this$1.checkLVal(expr);
  1671. this$1.next();
  1672. expr = this$1.finishNode(node$1, "UpdateExpression");
  1673. }
  1674. }
  1675. if (!sawUnary && this.eat(types.starstar))
  1676. { return this.buildBinary(startPos, startLoc, expr, this.parseMaybeUnary(null, false), "**", false) }
  1677. else
  1678. { return expr }
  1679. };
  1680. // Parse call, dot, and `[]`-subscript expressions.
  1681. pp$3.parseExprSubscripts = function(refDestructuringErrors) {
  1682. var startPos = this.start, startLoc = this.startLoc;
  1683. var expr = this.parseExprAtom(refDestructuringErrors);
  1684. var skipArrowSubscripts = expr.type === "ArrowFunctionExpression" && this.input.slice(this.lastTokStart, this.lastTokEnd) !== ")";
  1685. if (this.checkExpressionErrors(refDestructuringErrors) || skipArrowSubscripts) { return expr }
  1686. var result = this.parseSubscripts(expr, startPos, startLoc);
  1687. if (refDestructuringErrors && result.type === "MemberExpression") {
  1688. if (refDestructuringErrors.parenthesizedAssign >= result.start) { refDestructuringErrors.parenthesizedAssign = -1; }
  1689. if (refDestructuringErrors.parenthesizedBind >= result.start) { refDestructuringErrors.parenthesizedBind = -1; }
  1690. }
  1691. return result
  1692. };
  1693. pp$3.parseSubscripts = function(base, startPos, startLoc, noCalls) {
  1694. var this$1 = this;
  1695. var maybeAsyncArrow = this.options.ecmaVersion >= 8 && base.type === "Identifier" && base.name === "async" &&
  1696. this.lastTokEnd == base.end && !this.canInsertSemicolon();
  1697. for (var computed = (void 0);;) {
  1698. if ((computed = this$1.eat(types.bracketL)) || this$1.eat(types.dot)) {
  1699. var node = this$1.startNodeAt(startPos, startLoc);
  1700. node.object = base;
  1701. node.property = computed ? this$1.parseExpression() : this$1.parseIdent(true);
  1702. node.computed = !!computed;
  1703. if (computed) { this$1.expect(types.bracketR); }
  1704. base = this$1.finishNode(node, "MemberExpression");
  1705. } else if (!noCalls && this$1.eat(types.parenL)) {
  1706. var refDestructuringErrors = new DestructuringErrors, oldYieldPos = this$1.yieldPos, oldAwaitPos = this$1.awaitPos;
  1707. this$1.yieldPos = 0;
  1708. this$1.awaitPos = 0;
  1709. var exprList = this$1.parseExprList(types.parenR, this$1.options.ecmaVersion >= 8, false, refDestructuringErrors);
  1710. if (maybeAsyncArrow && !this$1.canInsertSemicolon() && this$1.eat(types.arrow)) {
  1711. this$1.checkPatternErrors(refDestructuringErrors, false);
  1712. this$1.checkYieldAwaitInDefaultParams();
  1713. this$1.yieldPos = oldYieldPos;
  1714. this$1.awaitPos = oldAwaitPos;
  1715. return this$1.parseArrowExpression(this$1.startNodeAt(startPos, startLoc), exprList, true)
  1716. }
  1717. this$1.checkExpressionErrors(refDestructuringErrors, true);
  1718. this$1.yieldPos = oldYieldPos || this$1.yieldPos;
  1719. this$1.awaitPos = oldAwaitPos || this$1.awaitPos;
  1720. var node$1 = this$1.startNodeAt(startPos, startLoc);
  1721. node$1.callee = base;
  1722. node$1.arguments = exprList;
  1723. base = this$1.finishNode(node$1, "CallExpression");
  1724. } else if (this$1.type === types.backQuote) {
  1725. var node$2 = this$1.startNodeAt(startPos, startLoc);
  1726. node$2.tag = base;
  1727. node$2.quasi = this$1.parseTemplate({isTagged: true});
  1728. base = this$1.finishNode(node$2, "TaggedTemplateExpression");
  1729. } else {
  1730. return base
  1731. }
  1732. }
  1733. };
  1734. // Parse an atomic expression — either a single token that is an
  1735. // expression, an expression started by a keyword like `function` or
  1736. // `new`, or an expression wrapped in punctuation like `()`, `[]`,
  1737. // or `{}`.
  1738. pp$3.parseExprAtom = function(refDestructuringErrors) {
  1739. var node, canBeArrow = this.potentialArrowAt == this.start;
  1740. switch (this.type) {
  1741. case types._super:
  1742. if (!this.inFunction)
  1743. { this.raise(this.start, "'super' outside of function or class"); }
  1744. case types._this:
  1745. var type = this.type === types._this ? "ThisExpression" : "Super";
  1746. node = this.startNode();
  1747. this.next();
  1748. return this.finishNode(node, type)
  1749. case types.name:
  1750. var startPos = this.start, startLoc = this.startLoc;
  1751. var id = this.parseIdent(this.type !== types.name);
  1752. if (this.options.ecmaVersion >= 8 && id.name === "async" && !this.canInsertSemicolon() && this.eat(types._function))
  1753. { return this.parseFunction(this.startNodeAt(startPos, startLoc), false, false, true) }
  1754. if (canBeArrow && !this.canInsertSemicolon()) {
  1755. if (this.eat(types.arrow))
  1756. { return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), [id], false) }
  1757. if (this.options.ecmaVersion >= 8 && id.name === "async" && this.type === types.name) {
  1758. id = this.parseIdent();
  1759. if (this.canInsertSemicolon() || !this.eat(types.arrow))
  1760. { this.unexpected(); }
  1761. return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), [id], true)
  1762. }
  1763. }
  1764. return id
  1765. case types.regexp:
  1766. var value = this.value;
  1767. node = this.parseLiteral(value.value);
  1768. node.regex = {pattern: value.pattern, flags: value.flags};
  1769. return node
  1770. case types.num: case types.string:
  1771. return this.parseLiteral(this.value)
  1772. case types._null: case types._true: case types._false:
  1773. node = this.startNode();
  1774. node.value = this.type === types._null ? null : this.type === types._true;
  1775. node.raw = this.type.keyword;
  1776. this.next();
  1777. return this.finishNode(node, "Literal")
  1778. case types.parenL:
  1779. var start = this.start, expr = this.parseParenAndDistinguishExpression(canBeArrow);
  1780. if (refDestructuringErrors) {
  1781. if (refDestructuringErrors.parenthesizedAssign < 0 && !this.isSimpleAssignTarget(expr))
  1782. { refDestructuringErrors.parenthesizedAssign = start; }
  1783. if (refDestructuringErrors.parenthesizedBind < 0)
  1784. { refDestructuringErrors.parenthesizedBind = start; }
  1785. }
  1786. return expr
  1787. case types.bracketL:
  1788. node = this.startNode();
  1789. this.next();
  1790. node.elements = this.parseExprList(types.bracketR, true, true, refDestructuringErrors);
  1791. return this.finishNode(node, "ArrayExpression")
  1792. case types.braceL:
  1793. return this.parseObj(false, refDestructuringErrors)
  1794. case types._function:
  1795. node = this.startNode();
  1796. this.next();
  1797. return this.parseFunction(node, false)
  1798. case types._class:
  1799. return this.parseClass(this.startNode(), false)
  1800. case types._new:
  1801. return this.parseNew()
  1802. case types.backQuote:
  1803. return this.parseTemplate()
  1804. default:
  1805. this.unexpected();
  1806. }
  1807. };
  1808. pp$3.parseLiteral = function(value) {
  1809. var node = this.startNode();
  1810. node.value = value;
  1811. node.raw = this.input.slice(this.start, this.end);
  1812. this.next();
  1813. return this.finishNode(node, "Literal")
  1814. };
  1815. pp$3.parseParenExpression = function() {
  1816. this.expect(types.parenL);
  1817. var val = this.parseExpression();
  1818. this.expect(types.parenR);
  1819. return val
  1820. };
  1821. pp$3.parseParenAndDistinguishExpression = function(canBeArrow) {
  1822. var this$1 = this;
  1823. var startPos = this.start, startLoc = this.startLoc, val, allowTrailingComma = this.options.ecmaVersion >= 8;
  1824. if (this.options.ecmaVersion >= 6) {
  1825. this.next();
  1826. var innerStartPos = this.start, innerStartLoc = this.startLoc;
  1827. var exprList = [], first = true, lastIsComma = false;
  1828. var refDestructuringErrors = new DestructuringErrors, oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, spreadStart, innerParenStart;
  1829. this.yieldPos = 0;
  1830. this.awaitPos = 0;
  1831. while (this.type !== types.parenR) {
  1832. first ? first = false : this$1.expect(types.comma);
  1833. if (allowTrailingComma && this$1.afterTrailingComma(types.parenR, true)) {
  1834. lastIsComma = true;
  1835. break
  1836. } else if (this$1.type === types.ellipsis) {
  1837. spreadStart = this$1.start;
  1838. exprList.push(this$1.parseParenItem(this$1.parseRestBinding()));
  1839. if (this$1.type === types.comma) { this$1.raise(this$1.start, "Comma is not permitted after the rest element"); }
  1840. break
  1841. } else {
  1842. if (this$1.type === types.parenL && !innerParenStart) {
  1843. innerParenStart = this$1.start;
  1844. }
  1845. exprList.push(this$1.parseMaybeAssign(false, refDestructuringErrors, this$1.parseParenItem));
  1846. }
  1847. }
  1848. var innerEndPos = this.start, innerEndLoc = this.startLoc;
  1849. this.expect(types.parenR);
  1850. if (canBeArrow && !this.canInsertSemicolon() && this.eat(types.arrow)) {
  1851. this.checkPatternErrors(refDestructuringErrors, false);
  1852. this.checkYieldAwaitInDefaultParams();
  1853. if (innerParenStart) { this.unexpected(innerParenStart); }
  1854. this.yieldPos = oldYieldPos;
  1855. this.awaitPos = oldAwaitPos;
  1856. return this.parseParenArrowList(startPos, startLoc, exprList)
  1857. }
  1858. if (!exprList.length || lastIsComma) { this.unexpected(this.lastTokStart); }
  1859. if (spreadStart) { this.unexpected(spreadStart); }
  1860. this.checkExpressionErrors(refDestructuringErrors, true);
  1861. this.yieldPos = oldYieldPos || this.yieldPos;
  1862. this.awaitPos = oldAwaitPos || this.awaitPos;
  1863. if (exprList.length > 1) {
  1864. val = this.startNodeAt(innerStartPos, innerStartLoc);
  1865. val.expressions = exprList;
  1866. this.finishNodeAt(val, "SequenceExpression", innerEndPos, innerEndLoc);
  1867. } else {
  1868. val = exprList[0];
  1869. }
  1870. } else {
  1871. val = this.parseParenExpression();
  1872. }
  1873. if (this.options.preserveParens) {
  1874. var par = this.startNodeAt(startPos, startLoc);
  1875. par.expression = val;
  1876. return this.finishNode(par, "ParenthesizedExpression")
  1877. } else {
  1878. return val
  1879. }
  1880. };
  1881. pp$3.parseParenItem = function(item) {
  1882. return item
  1883. };
  1884. pp$3.parseParenArrowList = function(startPos, startLoc, exprList) {
  1885. return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), exprList)
  1886. };
  1887. // New's precedence is slightly tricky. It must allow its argument to
  1888. // be a `[]` or dot subscript expression, but not a call — at least,
  1889. // not without wrapping it in parentheses. Thus, it uses the noCalls
  1890. // argument to parseSubscripts to prevent it from consuming the
  1891. // argument list.
  1892. var empty$1 = [];
  1893. pp$3.parseNew = function() {
  1894. var node = this.startNode();
  1895. var meta = this.parseIdent(true);
  1896. if (this.options.ecmaVersion >= 6 && this.eat(types.dot)) {
  1897. node.meta = meta;
  1898. node.property = this.parseIdent(true);
  1899. if (node.property.name !== "target")
  1900. { this.raiseRecoverable(node.property.start, "The only valid meta property for new is new.target"); }
  1901. if (!this.inFunction)
  1902. { this.raiseRecoverable(node.start, "new.target can only be used in functions"); }
  1903. return this.finishNode(node, "MetaProperty")
  1904. }
  1905. var startPos = this.start, startLoc = this.startLoc;
  1906. node.callee = this.parseSubscripts(this.parseExprAtom(), startPos, startLoc, true);
  1907. if (this.eat(types.parenL)) { node.arguments = this.parseExprList(types.parenR, this.options.ecmaVersion >= 8, false); }
  1908. else { node.arguments = empty$1; }
  1909. return this.finishNode(node, "NewExpression")
  1910. };
  1911. // Parse template expression.
  1912. pp$3.parseTemplateElement = function(ref) {
  1913. var isTagged = ref.isTagged;
  1914. var elem = this.startNode();
  1915. if (this.type === types.invalidTemplate) {
  1916. if (!isTagged) {
  1917. this.raiseRecoverable(this.start, "Bad escape sequence in untagged template literal");
  1918. }
  1919. elem.value = {
  1920. raw: this.value,
  1921. cooked: null
  1922. };
  1923. } else {
  1924. elem.value = {
  1925. raw: this.input.slice(this.start, this.end).replace(/\r\n?/g, "\n"),
  1926. cooked: this.value
  1927. };
  1928. }
  1929. this.next();
  1930. elem.tail = this.type === types.backQuote;
  1931. return this.finishNode(elem, "TemplateElement")
  1932. };
  1933. pp$3.parseTemplate = function(ref) {
  1934. var this$1 = this;
  1935. if ( ref === void 0 ) ref = {};
  1936. var isTagged = ref.isTagged; if ( isTagged === void 0 ) isTagged = false;
  1937. var node = this.startNode();
  1938. this.next();
  1939. node.expressions = [];
  1940. var curElt = this.parseTemplateElement({isTagged: isTagged});
  1941. node.quasis = [curElt];
  1942. while (!curElt.tail) {
  1943. this$1.expect(types.dollarBraceL);
  1944. node.expressions.push(this$1.parseExpression());
  1945. this$1.expect(types.braceR);
  1946. node.quasis.push(curElt = this$1.parseTemplateElement({isTagged: isTagged}));
  1947. }
  1948. this.next();
  1949. return this.finishNode(node, "TemplateLiteral")
  1950. };
  1951. // Parse an object literal or binding pattern.
  1952. pp$3.isAsyncProp = function(prop) {
  1953. return !prop.computed && prop.key.type === "Identifier" && prop.key.name === "async" &&
  1954. (this.type === types.name || this.type === types.num || this.type === types.string || this.type === types.bracketL || this.type.keyword) &&
  1955. !lineBreak.test(this.input.slice(this.lastTokEnd, this.start))
  1956. };
  1957. pp$3.parseObj = function(isPattern, refDestructuringErrors) {
  1958. var this$1 = this;
  1959. var node = this.startNode(), first = true, propHash = {};
  1960. node.properties = [];
  1961. this.next();
  1962. while (!this.eat(types.braceR)) {
  1963. if (!first) {
  1964. this$1.expect(types.comma);
  1965. if (this$1.afterTrailingComma(types.braceR)) { break }
  1966. } else { first = false; }
  1967. var prop = this$1.startNode(), isGenerator = (void 0), isAsync = (void 0), startPos = (void 0), startLoc = (void 0);
  1968. if (this$1.options.ecmaVersion >= 6) {
  1969. prop.method = false;
  1970. prop.shorthand = false;
  1971. if (isPattern || refDestructuringErrors) {
  1972. startPos = this$1.start;
  1973. startLoc = this$1.startLoc;
  1974. }
  1975. if (!isPattern)
  1976. { isGenerator = this$1.eat(types.star); }
  1977. }
  1978. this$1.parsePropertyName(prop);
  1979. if (!isPattern && this$1.options.ecmaVersion >= 8 && !isGenerator && this$1.isAsyncProp(prop)) {
  1980. isAsync = true;
  1981. this$1.parsePropertyName(prop, refDestructuringErrors);
  1982. } else {
  1983. isAsync = false;
  1984. }
  1985. this$1.parsePropertyValue(prop, isPattern, isGenerator, isAsync, startPos, startLoc, refDestructuringErrors);
  1986. this$1.checkPropClash(prop, propHash);
  1987. node.properties.push(this$1.finishNode(prop, "Property"));
  1988. }
  1989. return this.finishNode(node, isPattern ? "ObjectPattern" : "ObjectExpression")
  1990. };
  1991. pp$3.parsePropertyValue = function(prop, isPattern, isGenerator, isAsync, startPos, startLoc, refDestructuringErrors) {
  1992. if ((isGenerator || isAsync) && this.type === types.colon)
  1993. { this.unexpected(); }
  1994. if (this.eat(types.colon)) {
  1995. prop.value = isPattern ? this.parseMaybeDefault(this.start, this.startLoc) : this.parseMaybeAssign(false, refDestructuringErrors);
  1996. prop.kind = "init";
  1997. } else if (this.options.ecmaVersion >= 6 && this.type === types.parenL) {
  1998. if (isPattern) { this.unexpected(); }
  1999. prop.kind = "init";
  2000. prop.method = true;
  2001. prop.value = this.parseMethod(isGenerator, isAsync);
  2002. } else if (this.options.ecmaVersion >= 5 && !prop.computed && prop.key.type === "Identifier" &&
  2003. (prop.key.name === "get" || prop.key.name === "set") &&
  2004. (this.type != types.comma && this.type != types.braceR)) {
  2005. if (isGenerator || isAsync || isPattern) { this.unexpected(); }
  2006. prop.kind = prop.key.name;
  2007. this.parsePropertyName(prop);
  2008. prop.value = this.parseMethod(false);
  2009. var paramCount = prop.kind === "get" ? 0 : 1;
  2010. if (prop.value.params.length !== paramCount) {
  2011. var start = prop.value.start;
  2012. if (prop.kind === "get")
  2013. { this.raiseRecoverable(start, "getter should have no params"); }
  2014. else
  2015. { this.raiseRecoverable(start, "setter should have exactly one param"); }
  2016. } else {
  2017. if (prop.kind === "set" && prop.value.params[0].type === "RestElement")
  2018. { this.raiseRecoverable(prop.value.params[0].start, "Setter cannot use rest params"); }
  2019. }
  2020. } else if (this.options.ecmaVersion >= 6 && !prop.computed && prop.key.type === "Identifier") {
  2021. this.checkUnreserved(prop.key);
  2022. prop.kind = "init";
  2023. if (isPattern) {
  2024. prop.value = this.parseMaybeDefault(startPos, startLoc, prop.key);
  2025. } else if (this.type === types.eq && refDestructuringErrors) {
  2026. if (refDestructuringErrors.shorthandAssign < 0)
  2027. { refDestructuringErrors.shorthandAssign = this.start; }
  2028. prop.value = this.parseMaybeDefault(startPos, startLoc, prop.key);
  2029. } else {
  2030. prop.value = prop.key;
  2031. }
  2032. prop.shorthand = true;
  2033. } else { this.unexpected(); }
  2034. };
  2035. pp$3.parsePropertyName = function(prop) {
  2036. if (this.options.ecmaVersion >= 6) {
  2037. if (this.eat(types.bracketL)) {
  2038. prop.computed = true;
  2039. prop.key = this.parseMaybeAssign();
  2040. this.expect(types.bracketR);
  2041. return prop.key
  2042. } else {
  2043. prop.computed = false;
  2044. }
  2045. }
  2046. return prop.key = this.type === types.num || this.type === types.string ? this.parseExprAtom() : this.parseIdent(true)
  2047. };
  2048. // Initialize empty function node.
  2049. pp$3.initFunction = function(node) {
  2050. node.id = null;
  2051. if (this.options.ecmaVersion >= 6) {
  2052. node.generator = false;
  2053. node.expression = false;
  2054. }
  2055. if (this.options.ecmaVersion >= 8)
  2056. { node.async = false; }
  2057. };
  2058. // Parse object or class method.
  2059. pp$3.parseMethod = function(isGenerator, isAsync) {
  2060. var node = this.startNode(), oldInGen = this.inGenerator, oldInAsync = this.inAsync,
  2061. oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldInFunc = this.inFunction;
  2062. this.initFunction(node);
  2063. if (this.options.ecmaVersion >= 6)
  2064. { node.generator = isGenerator; }
  2065. if (this.options.ecmaVersion >= 8)
  2066. { node.async = !!isAsync; }
  2067. this.inGenerator = node.generator;
  2068. this.inAsync = node.async;
  2069. this.yieldPos = 0;
  2070. this.awaitPos = 0;
  2071. this.inFunction = true;
  2072. this.enterFunctionScope();
  2073. this.expect(types.parenL);
  2074. node.params = this.parseBindingList(types.parenR, false, this.options.ecmaVersion >= 8);
  2075. this.checkYieldAwaitInDefaultParams();
  2076. this.parseFunctionBody(node, false);
  2077. this.inGenerator = oldInGen;
  2078. this.inAsync = oldInAsync;
  2079. this.yieldPos = oldYieldPos;
  2080. this.awaitPos = oldAwaitPos;
  2081. this.inFunction = oldInFunc;
  2082. return this.finishNode(node, "FunctionExpression")
  2083. };
  2084. // Parse arrow function expression with given parameters.
  2085. pp$3.parseArrowExpression = function(node, params, isAsync) {
  2086. var oldInGen = this.inGenerator, oldInAsync = this.inAsync,
  2087. oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldInFunc = this.inFunction;
  2088. this.enterFunctionScope();
  2089. this.initFunction(node);
  2090. if (this.options.ecmaVersion >= 8)
  2091. { node.async = !!isAsync; }
  2092. this.inGenerator = false;
  2093. this.inAsync = node.async;
  2094. this.yieldPos = 0;
  2095. this.awaitPos = 0;
  2096. this.inFunction = true;
  2097. node.params = this.toAssignableList(params, true);
  2098. this.parseFunctionBody(node, true);
  2099. this.inGenerator = oldInGen;
  2100. this.inAsync = oldInAsync;
  2101. this.yieldPos = oldYieldPos;
  2102. this.awaitPos = oldAwaitPos;
  2103. this.inFunction = oldInFunc;
  2104. return this.finishNode(node, "ArrowFunctionExpression")
  2105. };
  2106. // Parse function body and check parameters.
  2107. pp$3.parseFunctionBody = function(node, isArrowFunction) {
  2108. var isExpression = isArrowFunction && this.type !== types.braceL;
  2109. var oldStrict = this.strict, useStrict = false;
  2110. if (isExpression) {
  2111. node.body = this.parseMaybeAssign();
  2112. node.expression = true;
  2113. this.checkParams(node, false);
  2114. } else {
  2115. var nonSimple = this.options.ecmaVersion >= 7 && !this.isSimpleParamList(node.params);
  2116. if (!oldStrict || nonSimple) {
  2117. useStrict = this.strictDirective(this.end);
  2118. // If this is a strict mode function, verify that argument names
  2119. // are not repeated, and it does not try to bind the words `eval`
  2120. // or `arguments`.
  2121. if (useStrict && nonSimple)
  2122. { this.raiseRecoverable(node.start, "Illegal 'use strict' directive in function with non-simple parameter list"); }
  2123. }
  2124. // Start a new scope with regard to labels and the `inFunction`
  2125. // flag (restore them to their old value afterwards).
  2126. var oldLabels = this.labels;
  2127. this.labels = [];
  2128. if (useStrict) { this.strict = true; }
  2129. // Add the params to varDeclaredNames to ensure that an error is thrown
  2130. // if a let/const declaration in the function clashes with one of the params.
  2131. this.checkParams(node, !oldStrict && !useStrict && !isArrowFunction && this.isSimpleParamList(node.params));
  2132. node.body = this.parseBlock(false);
  2133. node.expression = false;
  2134. this.labels = oldLabels;
  2135. }
  2136. this.exitFunctionScope();
  2137. if (this.strict && node.id) {
  2138. // Ensure the function name isn't a forbidden identifier in strict mode, e.g. 'eval'
  2139. this.checkLVal(node.id, "none");
  2140. }
  2141. this.strict = oldStrict;
  2142. };
  2143. pp$3.isSimpleParamList = function(params) {
  2144. for (var i = 0, list = params; i < list.length; i += 1)
  2145. {
  2146. var param = list[i];
  2147. if (param.type !== "Identifier") { return false
  2148. } }
  2149. return true
  2150. };
  2151. // Checks function params for various disallowed patterns such as using "eval"
  2152. // or "arguments" and duplicate parameters.
  2153. pp$3.checkParams = function(node, allowDuplicates) {
  2154. var this$1 = this;
  2155. var nameHash = {};
  2156. for (var i = 0, list = node.params; i < list.length; i += 1)
  2157. {
  2158. var param = list[i];
  2159. this$1.checkLVal(param, "var", allowDuplicates ? null : nameHash);
  2160. }
  2161. };
  2162. // Parses a comma-separated list of expressions, and returns them as
  2163. // an array. `close` is the token type that ends the list, and
  2164. // `allowEmpty` can be turned on to allow subsequent commas with
  2165. // nothing in between them to be parsed as `null` (which is needed
  2166. // for array literals).
  2167. pp$3.parseExprList = function(close, allowTrailingComma, allowEmpty, refDestructuringErrors) {
  2168. var this$1 = this;
  2169. var elts = [], first = true;
  2170. while (!this.eat(close)) {
  2171. if (!first) {
  2172. this$1.expect(types.comma);
  2173. if (allowTrailingComma && this$1.afterTrailingComma(close)) { break }
  2174. } else { first = false; }
  2175. var elt = (void 0);
  2176. if (allowEmpty && this$1.type === types.comma)
  2177. { elt = null; }
  2178. else if (this$1.type === types.ellipsis) {
  2179. elt = this$1.parseSpread(refDestructuringErrors);
  2180. if (refDestructuringErrors && this$1.type === types.comma && refDestructuringErrors.trailingComma < 0)
  2181. { refDestructuringErrors.trailingComma = this$1.start; }
  2182. } else {
  2183. elt = this$1.parseMaybeAssign(false, refDestructuringErrors);
  2184. }
  2185. elts.push(elt);
  2186. }
  2187. return elts
  2188. };
  2189. // Parse the next token as an identifier. If `liberal` is true (used
  2190. // when parsing properties), it will also convert keywords into
  2191. // identifiers.
  2192. pp$3.checkUnreserved = function(ref) {
  2193. var start = ref.start;
  2194. var end = ref.end;
  2195. var name = ref.name;
  2196. if (this.inGenerator && name === "yield")
  2197. { this.raiseRecoverable(start, "Can not use 'yield' as identifier inside a generator"); }
  2198. if (this.inAsync && name === "await")
  2199. { this.raiseRecoverable(start, "Can not use 'await' as identifier inside an async function"); }
  2200. if (this.isKeyword(name))
  2201. { this.raise(start, ("Unexpected keyword '" + name + "'")); }
  2202. if (this.options.ecmaVersion < 6 &&
  2203. this.input.slice(start, end).indexOf("\\") != -1) { return }
  2204. var re = this.strict ? this.reservedWordsStrict : this.reservedWords;
  2205. if (re.test(name))
  2206. { this.raiseRecoverable(start, ("The keyword '" + name + "' is reserved")); }
  2207. };
  2208. pp$3.parseIdent = function(liberal, isBinding) {
  2209. var node = this.startNode();
  2210. if (liberal && this.options.allowReserved == "never") { liberal = false; }
  2211. if (this.type === types.name) {
  2212. node.name = this.value;
  2213. } else if (this.type.keyword) {
  2214. node.name = this.type.keyword;
  2215. } else {
  2216. this.unexpected();
  2217. }
  2218. this.next();
  2219. this.finishNode(node, "Identifier");
  2220. if (!liberal) { this.checkUnreserved(node); }
  2221. return node
  2222. };
  2223. // Parses yield expression inside generator.
  2224. pp$3.parseYield = function() {
  2225. if (!this.yieldPos) { this.yieldPos = this.start; }
  2226. var node = this.startNode();
  2227. this.next();
  2228. if (this.type == types.semi || this.canInsertSemicolon() || (this.type != types.star && !this.type.startsExpr)) {
  2229. node.delegate = false;
  2230. node.argument = null;
  2231. } else {
  2232. node.delegate = this.eat(types.star);
  2233. node.argument = this.parseMaybeAssign();
  2234. }
  2235. return this.finishNode(node, "YieldExpression")
  2236. };
  2237. pp$3.parseAwait = function() {
  2238. if (!this.awaitPos) { this.awaitPos = this.start; }
  2239. var node = this.startNode();
  2240. this.next();
  2241. node.argument = this.parseMaybeUnary(null, true);
  2242. return this.finishNode(node, "AwaitExpression")
  2243. };
  2244. var pp$4 = Parser.prototype;
  2245. // This function is used to raise exceptions on parse errors. It
  2246. // takes an offset integer (into the current `input`) to indicate
  2247. // the location of the error, attaches the position to the end
  2248. // of the error message, and then raises a `SyntaxError` with that
  2249. // message.
  2250. pp$4.raise = function(pos, message) {
  2251. var loc = getLineInfo(this.input, pos);
  2252. message += " (" + loc.line + ":" + loc.column + ")";
  2253. var err = new SyntaxError(message);
  2254. err.pos = pos; err.loc = loc; err.raisedAt = this.pos;
  2255. throw err
  2256. };
  2257. pp$4.raiseRecoverable = pp$4.raise;
  2258. pp$4.curPosition = function() {
  2259. if (this.options.locations) {
  2260. return new Position(this.curLine, this.pos - this.lineStart)
  2261. }
  2262. };
  2263. var pp$5 = Parser.prototype;
  2264. // Object.assign polyfill
  2265. var assign = Object.assign || function(target) {
  2266. var sources = [], len = arguments.length - 1;
  2267. while ( len-- > 0 ) sources[ len ] = arguments[ len + 1 ];
  2268. for (var i = 0, list = sources; i < list.length; i += 1) {
  2269. var source = list[i];
  2270. for (var key in source) {
  2271. if (has(source, key)) {
  2272. target[key] = source[key];
  2273. }
  2274. }
  2275. }
  2276. return target
  2277. };
  2278. // The functions in this module keep track of declared variables in the current scope in order to detect duplicate variable names.
  2279. pp$5.enterFunctionScope = function() {
  2280. // var: a hash of var-declared names in the current lexical scope
  2281. // lexical: a hash of lexically-declared names in the current lexical scope
  2282. // childVar: a hash of var-declared names in all child lexical scopes of the current lexical scope (within the current function scope)
  2283. // parentLexical: a hash of lexically-declared names in all parent lexical scopes of the current lexical scope (within the current function scope)
  2284. this.scopeStack.push({var: {}, lexical: {}, childVar: {}, parentLexical: {}});
  2285. };
  2286. pp$5.exitFunctionScope = function() {
  2287. this.scopeStack.pop();
  2288. };
  2289. pp$5.enterLexicalScope = function() {
  2290. var parentScope = this.scopeStack[this.scopeStack.length - 1];
  2291. var childScope = {var: {}, lexical: {}, childVar: {}, parentLexical: {}};
  2292. this.scopeStack.push(childScope);
  2293. assign(childScope.parentLexical, parentScope.lexical, parentScope.parentLexical);
  2294. };
  2295. pp$5.exitLexicalScope = function() {
  2296. var childScope = this.scopeStack.pop();
  2297. var parentScope = this.scopeStack[this.scopeStack.length - 1];
  2298. assign(parentScope.childVar, childScope.var, childScope.childVar);
  2299. };
  2300. /**
  2301. * A name can be declared with `var` if there are no variables with the same name declared with `let`/`const`
  2302. * in the current lexical scope or any of the parent lexical scopes in this function.
  2303. */
  2304. pp$5.canDeclareVarName = function(name) {
  2305. var currentScope = this.scopeStack[this.scopeStack.length - 1];
  2306. return !has(currentScope.lexical, name) && !has(currentScope.parentLexical, name)
  2307. };
  2308. /**
  2309. * A name can be declared with `let`/`const` if there are no variables with the same name declared with `let`/`const`
  2310. * in the current scope, and there are no variables with the same name declared with `var` in the current scope or in
  2311. * any child lexical scopes in this function.
  2312. */
  2313. pp$5.canDeclareLexicalName = function(name) {
  2314. var currentScope = this.scopeStack[this.scopeStack.length - 1];
  2315. return !has(currentScope.lexical, name) && !has(currentScope.var, name) && !has(currentScope.childVar, name)
  2316. };
  2317. pp$5.declareVarName = function(name) {
  2318. this.scopeStack[this.scopeStack.length - 1].var[name] = true;
  2319. };
  2320. pp$5.declareLexicalName = function(name) {
  2321. this.scopeStack[this.scopeStack.length - 1].lexical[name] = true;
  2322. };
  2323. var Node = function Node(parser, pos, loc) {
  2324. this.type = "";
  2325. this.start = pos;
  2326. this.end = 0;
  2327. if (parser.options.locations)
  2328. { this.loc = new SourceLocation(parser, loc); }
  2329. if (parser.options.directSourceFile)
  2330. { this.sourceFile = parser.options.directSourceFile; }
  2331. if (parser.options.ranges)
  2332. { this.range = [pos, 0]; }
  2333. };
  2334. // Start an AST node, attaching a start offset.
  2335. var pp$6 = Parser.prototype;
  2336. pp$6.startNode = function() {
  2337. return new Node(this, this.start, this.startLoc)
  2338. };
  2339. pp$6.startNodeAt = function(pos, loc) {
  2340. return new Node(this, pos, loc)
  2341. };
  2342. // Finish an AST node, adding `type` and `end` properties.
  2343. function finishNodeAt(node, type, pos, loc) {
  2344. node.type = type;
  2345. node.end = pos;
  2346. if (this.options.locations)
  2347. { node.loc.end = loc; }
  2348. if (this.options.ranges)
  2349. { node.range[1] = pos; }
  2350. return node
  2351. }
  2352. pp$6.finishNode = function(node, type) {
  2353. return finishNodeAt.call(this, node, type, this.lastTokEnd, this.lastTokEndLoc)
  2354. };
  2355. // Finish node at given position
  2356. pp$6.finishNodeAt = function(node, type, pos, loc) {
  2357. return finishNodeAt.call(this, node, type, pos, loc)
  2358. };
  2359. // The algorithm used to determine whether a regexp can appear at a
  2360. // given point in the program is loosely based on sweet.js' approach.
  2361. // See https://github.com/mozilla/sweet.js/wiki/design
  2362. var TokContext = function TokContext(token, isExpr, preserveSpace, override, generator) {
  2363. this.token = token;
  2364. this.isExpr = !!isExpr;
  2365. this.preserveSpace = !!preserveSpace;
  2366. this.override = override;
  2367. this.generator = !!generator;
  2368. };
  2369. var types$1 = {
  2370. b_stat: new TokContext("{", false),
  2371. b_expr: new TokContext("{", true),
  2372. b_tmpl: new TokContext("${", false),
  2373. p_stat: new TokContext("(", false),
  2374. p_expr: new TokContext("(", true),
  2375. q_tmpl: new TokContext("`", true, true, function (p) { return p.tryReadTemplateToken(); }),
  2376. f_stat: new TokContext("function", false),
  2377. f_expr: new TokContext("function", true),
  2378. f_expr_gen: new TokContext("function", true, false, null, true),
  2379. f_gen: new TokContext("function", false, false, null, true)
  2380. };
  2381. var pp$7 = Parser.prototype;
  2382. pp$7.initialContext = function() {
  2383. return [types$1.b_stat]
  2384. };
  2385. pp$7.braceIsBlock = function(prevType) {
  2386. var parent = this.curContext();
  2387. if (parent === types$1.f_expr || parent === types$1.f_stat)
  2388. { return true }
  2389. if (prevType === types.colon && (parent === types$1.b_stat || parent === types$1.b_expr))
  2390. { return !parent.isExpr }
  2391. // The check for `tt.name && exprAllowed` detects whether we are
  2392. // after a `yield` or `of` construct. See the `updateContext` for
  2393. // `tt.name`.
  2394. if (prevType === types._return || prevType == types.name && this.exprAllowed)
  2395. { return lineBreak.test(this.input.slice(this.lastTokEnd, this.start)) }
  2396. if (prevType === types._else || prevType === types.semi || prevType === types.eof || prevType === types.parenR || prevType == types.arrow)
  2397. { return true }
  2398. if (prevType == types.braceL)
  2399. { return parent === types$1.b_stat }
  2400. if (prevType == types._var || prevType == types.name)
  2401. { return false }
  2402. return !this.exprAllowed
  2403. };
  2404. pp$7.inGeneratorContext = function() {
  2405. var this$1 = this;
  2406. for (var i = this.context.length - 1; i >= 1; i--) {
  2407. var context = this$1.context[i];
  2408. if (context.token === "function")
  2409. { return context.generator }
  2410. }
  2411. return false
  2412. };
  2413. pp$7.updateContext = function(prevType) {
  2414. var update, type = this.type;
  2415. if (type.keyword && prevType == types.dot)
  2416. { this.exprAllowed = false; }
  2417. else if (update = type.updateContext)
  2418. { update.call(this, prevType); }
  2419. else
  2420. { this.exprAllowed = type.beforeExpr; }
  2421. };
  2422. // Token-specific context update code
  2423. types.parenR.updateContext = types.braceR.updateContext = function() {
  2424. if (this.context.length == 1) {
  2425. this.exprAllowed = true;
  2426. return
  2427. }
  2428. var out = this.context.pop();
  2429. if (out === types$1.b_stat && this.curContext().token === "function") {
  2430. out = this.context.pop();
  2431. }
  2432. this.exprAllowed = !out.isExpr;
  2433. };
  2434. types.braceL.updateContext = function(prevType) {
  2435. this.context.push(this.braceIsBlock(prevType) ? types$1.b_stat : types$1.b_expr);
  2436. this.exprAllowed = true;
  2437. };
  2438. types.dollarBraceL.updateContext = function() {
  2439. this.context.push(types$1.b_tmpl);
  2440. this.exprAllowed = true;
  2441. };
  2442. types.parenL.updateContext = function(prevType) {
  2443. var statementParens = prevType === types._if || prevType === types._for || prevType === types._with || prevType === types._while;
  2444. this.context.push(statementParens ? types$1.p_stat : types$1.p_expr);
  2445. this.exprAllowed = true;
  2446. };
  2447. types.incDec.updateContext = function() {
  2448. // tokExprAllowed stays unchanged
  2449. };
  2450. types._function.updateContext = types._class.updateContext = function(prevType) {
  2451. if (prevType.beforeExpr && prevType !== types.semi && prevType !== types._else &&
  2452. !((prevType === types.colon || prevType === types.braceL) && this.curContext() === types$1.b_stat))
  2453. { this.context.push(types$1.f_expr); }
  2454. else
  2455. { this.context.push(types$1.f_stat); }
  2456. this.exprAllowed = false;
  2457. };
  2458. types.backQuote.updateContext = function() {
  2459. if (this.curContext() === types$1.q_tmpl)
  2460. { this.context.pop(); }
  2461. else
  2462. { this.context.push(types$1.q_tmpl); }
  2463. this.exprAllowed = false;
  2464. };
  2465. types.star.updateContext = function(prevType) {
  2466. if (prevType == types._function) {
  2467. var index = this.context.length - 1;
  2468. if (this.context[index] === types$1.f_expr)
  2469. { this.context[index] = types$1.f_expr_gen; }
  2470. else
  2471. { this.context[index] = types$1.f_gen; }
  2472. }
  2473. this.exprAllowed = true;
  2474. };
  2475. types.name.updateContext = function(prevType) {
  2476. var allowed = false;
  2477. if (this.options.ecmaVersion >= 6) {
  2478. if (this.value == "of" && !this.exprAllowed ||
  2479. this.value == "yield" && this.inGeneratorContext())
  2480. { allowed = true; }
  2481. }
  2482. this.exprAllowed = allowed;
  2483. };
  2484. // Object type used to represent tokens. Note that normally, tokens
  2485. // simply exist as properties on the parser object. This is only
  2486. // used for the onToken callback and the external tokenizer.
  2487. var Token = function Token(p) {
  2488. this.type = p.type;
  2489. this.value = p.value;
  2490. this.start = p.start;
  2491. this.end = p.end;
  2492. if (p.options.locations)
  2493. { this.loc = new SourceLocation(p, p.startLoc, p.endLoc); }
  2494. if (p.options.ranges)
  2495. { this.range = [p.start, p.end]; }
  2496. };
  2497. // ## Tokenizer
  2498. var pp$8 = Parser.prototype;
  2499. // Are we running under Rhino?
  2500. var isRhino = typeof Packages == "object" && Object.prototype.toString.call(Packages) == "[object JavaPackage]";
  2501. // Move to the next token
  2502. pp$8.next = function() {
  2503. if (this.options.onToken)
  2504. { this.options.onToken(new Token(this)); }
  2505. this.lastTokEnd = this.end;
  2506. this.lastTokStart = this.start;
  2507. this.lastTokEndLoc = this.endLoc;
  2508. this.lastTokStartLoc = this.startLoc;
  2509. this.nextToken();
  2510. };
  2511. pp$8.getToken = function() {
  2512. this.next();
  2513. return new Token(this)
  2514. };
  2515. // If we're in an ES6 environment, make parsers iterable
  2516. if (typeof Symbol !== "undefined")
  2517. { pp$8[Symbol.iterator] = function() {
  2518. var this$1 = this;
  2519. return {
  2520. next: function () {
  2521. var token = this$1.getToken();
  2522. return {
  2523. done: token.type === types.eof,
  2524. value: token
  2525. }
  2526. }
  2527. }
  2528. }; }
  2529. // Toggle strict mode. Re-reads the next number or string to please
  2530. // pedantic tests (`"use strict"; 010;` should fail).
  2531. pp$8.curContext = function() {
  2532. return this.context[this.context.length - 1]
  2533. };
  2534. // Read a single token, updating the parser object's token-related
  2535. // properties.
  2536. pp$8.nextToken = function() {
  2537. var curContext = this.curContext();
  2538. if (!curContext || !curContext.preserveSpace) { this.skipSpace(); }
  2539. this.start = this.pos;
  2540. if (this.options.locations) { this.startLoc = this.curPosition(); }
  2541. if (this.pos >= this.input.length) { return this.finishToken(types.eof) }
  2542. if (curContext.override) { return curContext.override(this) }
  2543. else { this.readToken(this.fullCharCodeAtPos()); }
  2544. };
  2545. pp$8.readToken = function(code) {
  2546. // Identifier or keyword. '\uXXXX' sequences are allowed in
  2547. // identifiers, so '\' also dispatches to that.
  2548. if (isIdentifierStart(code, this.options.ecmaVersion >= 6) || code === 92 /* '\' */)
  2549. { return this.readWord() }
  2550. return this.getTokenFromCode(code)
  2551. };
  2552. pp$8.fullCharCodeAtPos = function() {
  2553. var code = this.input.charCodeAt(this.pos);
  2554. if (code <= 0xd7ff || code >= 0xe000) { return code }
  2555. var next = this.input.charCodeAt(this.pos + 1);
  2556. return (code << 10) + next - 0x35fdc00
  2557. };
  2558. pp$8.skipBlockComment = function() {
  2559. var this$1 = this;
  2560. var startLoc = this.options.onComment && this.curPosition();
  2561. var start = this.pos, end = this.input.indexOf("*/", this.pos += 2);
  2562. if (end === -1) { this.raise(this.pos - 2, "Unterminated comment"); }
  2563. this.pos = end + 2;
  2564. if (this.options.locations) {
  2565. lineBreakG.lastIndex = start;
  2566. var match;
  2567. while ((match = lineBreakG.exec(this.input)) && match.index < this.pos) {
  2568. ++this$1.curLine;
  2569. this$1.lineStart = match.index + match[0].length;
  2570. }
  2571. }
  2572. if (this.options.onComment)
  2573. { this.options.onComment(true, this.input.slice(start + 2, end), start, this.pos,
  2574. startLoc, this.curPosition()); }
  2575. };
  2576. pp$8.skipLineComment = function(startSkip) {
  2577. var this$1 = this;
  2578. var start = this.pos;
  2579. var startLoc = this.options.onComment && this.curPosition();
  2580. var ch = this.input.charCodeAt(this.pos += startSkip);
  2581. while (this.pos < this.input.length && !isNewLine(ch)) {
  2582. ch = this$1.input.charCodeAt(++this$1.pos);
  2583. }
  2584. if (this.options.onComment)
  2585. { this.options.onComment(false, this.input.slice(start + startSkip, this.pos), start, this.pos,
  2586. startLoc, this.curPosition()); }
  2587. };
  2588. // Called at the start of the parse and after every token. Skips
  2589. // whitespace and comments, and.
  2590. pp$8.skipSpace = function() {
  2591. var this$1 = this;
  2592. loop: while (this.pos < this.input.length) {
  2593. var ch = this$1.input.charCodeAt(this$1.pos);
  2594. switch (ch) {
  2595. case 32: case 160: // ' '
  2596. ++this$1.pos;
  2597. break
  2598. case 13:
  2599. if (this$1.input.charCodeAt(this$1.pos + 1) === 10) {
  2600. ++this$1.pos;
  2601. }
  2602. case 10: case 8232: case 8233:
  2603. ++this$1.pos;
  2604. if (this$1.options.locations) {
  2605. ++this$1.curLine;
  2606. this$1.lineStart = this$1.pos;
  2607. }
  2608. break
  2609. case 47: // '/'
  2610. switch (this$1.input.charCodeAt(this$1.pos + 1)) {
  2611. case 42: // '*'
  2612. this$1.skipBlockComment();
  2613. break
  2614. case 47:
  2615. this$1.skipLineComment(2);
  2616. break
  2617. default:
  2618. break loop
  2619. }
  2620. break
  2621. default:
  2622. if (ch > 8 && ch < 14 || ch >= 5760 && nonASCIIwhitespace.test(String.fromCharCode(ch))) {
  2623. ++this$1.pos;
  2624. } else {
  2625. break loop
  2626. }
  2627. }
  2628. }
  2629. };
  2630. // Called at the end of every token. Sets `end`, `val`, and
  2631. // maintains `context` and `exprAllowed`, and skips the space after
  2632. // the token, so that the next one's `start` will point at the
  2633. // right position.
  2634. pp$8.finishToken = function(type, val) {
  2635. this.end = this.pos;
  2636. if (this.options.locations) { this.endLoc = this.curPosition(); }
  2637. var prevType = this.type;
  2638. this.type = type;
  2639. this.value = val;
  2640. this.updateContext(prevType);
  2641. };
  2642. // ### Token reading
  2643. // This is the function that is called to fetch the next token. It
  2644. // is somewhat obscure, because it works in character codes rather
  2645. // than characters, and because operator parsing has been inlined
  2646. // into it.
  2647. //
  2648. // All in the name of speed.
  2649. //
  2650. pp$8.readToken_dot = function() {
  2651. var next = this.input.charCodeAt(this.pos + 1);
  2652. if (next >= 48 && next <= 57) { return this.readNumber(true) }
  2653. var next2 = this.input.charCodeAt(this.pos + 2);
  2654. if (this.options.ecmaVersion >= 6 && next === 46 && next2 === 46) { // 46 = dot '.'
  2655. this.pos += 3;
  2656. return this.finishToken(types.ellipsis)
  2657. } else {
  2658. ++this.pos;
  2659. return this.finishToken(types.dot)
  2660. }
  2661. };
  2662. pp$8.readToken_slash = function() { // '/'
  2663. var next = this.input.charCodeAt(this.pos + 1);
  2664. if (this.exprAllowed) { ++this.pos; return this.readRegexp() }
  2665. if (next === 61) { return this.finishOp(types.assign, 2) }
  2666. return this.finishOp(types.slash, 1)
  2667. };
  2668. pp$8.readToken_mult_modulo_exp = function(code) { // '%*'
  2669. var next = this.input.charCodeAt(this.pos + 1);
  2670. var size = 1;
  2671. var tokentype = code === 42 ? types.star : types.modulo;
  2672. // exponentiation operator ** and **=
  2673. if (this.options.ecmaVersion >= 7 && next === 42) {
  2674. ++size;
  2675. tokentype = types.starstar;
  2676. next = this.input.charCodeAt(this.pos + 2);
  2677. }
  2678. if (next === 61) { return this.finishOp(types.assign, size + 1) }
  2679. return this.finishOp(tokentype, size)
  2680. };
  2681. pp$8.readToken_pipe_amp = function(code) { // '|&'
  2682. var next = this.input.charCodeAt(this.pos + 1);
  2683. if (next === code) { return this.finishOp(code === 124 ? types.logicalOR : types.logicalAND, 2) }
  2684. if (next === 61) { return this.finishOp(types.assign, 2) }
  2685. return this.finishOp(code === 124 ? types.bitwiseOR : types.bitwiseAND, 1)
  2686. };
  2687. pp$8.readToken_caret = function() { // '^'
  2688. var next = this.input.charCodeAt(this.pos + 1);
  2689. if (next === 61) { return this.finishOp(types.assign, 2) }
  2690. return this.finishOp(types.bitwiseXOR, 1)
  2691. };
  2692. pp$8.readToken_plus_min = function(code) { // '+-'
  2693. var next = this.input.charCodeAt(this.pos + 1);
  2694. if (next === code) {
  2695. if (next == 45 && !this.inModule && this.input.charCodeAt(this.pos + 2) == 62 &&
  2696. (this.lastTokEnd === 0 || lineBreak.test(this.input.slice(this.lastTokEnd, this.pos)))) {
  2697. // A `-->` line comment
  2698. this.skipLineComment(3);
  2699. this.skipSpace();
  2700. return this.nextToken()
  2701. }
  2702. return this.finishOp(types.incDec, 2)
  2703. }
  2704. if (next === 61) { return this.finishOp(types.assign, 2) }
  2705. return this.finishOp(types.plusMin, 1)
  2706. };
  2707. pp$8.readToken_lt_gt = function(code) { // '<>'
  2708. var next = this.input.charCodeAt(this.pos + 1);
  2709. var size = 1;
  2710. if (next === code) {
  2711. size = code === 62 && this.input.charCodeAt(this.pos + 2) === 62 ? 3 : 2;
  2712. if (this.input.charCodeAt(this.pos + size) === 61) { return this.finishOp(types.assign, size + 1) }
  2713. return this.finishOp(types.bitShift, size)
  2714. }
  2715. if (next == 33 && code == 60 && !this.inModule && this.input.charCodeAt(this.pos + 2) == 45 &&
  2716. this.input.charCodeAt(this.pos + 3) == 45) {
  2717. // `<!--`, an XML-style comment that should be interpreted as a line comment
  2718. this.skipLineComment(4);
  2719. this.skipSpace();
  2720. return this.nextToken()
  2721. }
  2722. if (next === 61) { size = 2; }
  2723. return this.finishOp(types.relational, size)
  2724. };
  2725. pp$8.readToken_eq_excl = function(code) { // '=!'
  2726. var next = this.input.charCodeAt(this.pos + 1);
  2727. if (next === 61) { return this.finishOp(types.equality, this.input.charCodeAt(this.pos + 2) === 61 ? 3 : 2) }
  2728. if (code === 61 && next === 62 && this.options.ecmaVersion >= 6) { // '=>'
  2729. this.pos += 2;
  2730. return this.finishToken(types.arrow)
  2731. }
  2732. return this.finishOp(code === 61 ? types.eq : types.prefix, 1)
  2733. };
  2734. pp$8.getTokenFromCode = function(code) {
  2735. switch (code) {
  2736. // The interpretation of a dot depends on whether it is followed
  2737. // by a digit or another two dots.
  2738. case 46: // '.'
  2739. return this.readToken_dot()
  2740. // Punctuation tokens.
  2741. case 40: ++this.pos; return this.finishToken(types.parenL)
  2742. case 41: ++this.pos; return this.finishToken(types.parenR)
  2743. case 59: ++this.pos; return this.finishToken(types.semi)
  2744. case 44: ++this.pos; return this.finishToken(types.comma)
  2745. case 91: ++this.pos; return this.finishToken(types.bracketL)
  2746. case 93: ++this.pos; return this.finishToken(types.bracketR)
  2747. case 123: ++this.pos; return this.finishToken(types.braceL)
  2748. case 125: ++this.pos; return this.finishToken(types.braceR)
  2749. case 58: ++this.pos; return this.finishToken(types.colon)
  2750. case 63: ++this.pos; return this.finishToken(types.question)
  2751. case 96: // '`'
  2752. if (this.options.ecmaVersion < 6) { break }
  2753. ++this.pos;
  2754. return this.finishToken(types.backQuote)
  2755. case 48: // '0'
  2756. var next = this.input.charCodeAt(this.pos + 1);
  2757. if (next === 120 || next === 88) { return this.readRadixNumber(16) } // '0x', '0X' - hex number
  2758. if (this.options.ecmaVersion >= 6) {
  2759. if (next === 111 || next === 79) { return this.readRadixNumber(8) } // '0o', '0O' - octal number
  2760. if (next === 98 || next === 66) { return this.readRadixNumber(2) } // '0b', '0B' - binary number
  2761. }
  2762. // Anything else beginning with a digit is an integer, octal
  2763. // number, or float.
  2764. case 49: case 50: case 51: case 52: case 53: case 54: case 55: case 56: case 57: // 1-9
  2765. return this.readNumber(false)
  2766. // Quotes produce strings.
  2767. case 34: case 39: // '"', "'"
  2768. return this.readString(code)
  2769. // Operators are parsed inline in tiny state machines. '=' (61) is
  2770. // often referred to. `finishOp` simply skips the amount of
  2771. // characters it is given as second argument, and returns a token
  2772. // of the type given by its first argument.
  2773. case 47: // '/'
  2774. return this.readToken_slash()
  2775. case 37: case 42: // '%*'
  2776. return this.readToken_mult_modulo_exp(code)
  2777. case 124: case 38: // '|&'
  2778. return this.readToken_pipe_amp(code)
  2779. case 94: // '^'
  2780. return this.readToken_caret()
  2781. case 43: case 45: // '+-'
  2782. return this.readToken_plus_min(code)
  2783. case 60: case 62: // '<>'
  2784. return this.readToken_lt_gt(code)
  2785. case 61: case 33: // '=!'
  2786. return this.readToken_eq_excl(code)
  2787. case 126: // '~'
  2788. return this.finishOp(types.prefix, 1)
  2789. }
  2790. this.raise(this.pos, "Unexpected character '" + codePointToString(code) + "'");
  2791. };
  2792. pp$8.finishOp = function(type, size) {
  2793. var str = this.input.slice(this.pos, this.pos + size);
  2794. this.pos += size;
  2795. return this.finishToken(type, str)
  2796. };
  2797. // Parse a regular expression. Some context-awareness is necessary,
  2798. // since a '/' inside a '[]' set does not end the expression.
  2799. function tryCreateRegexp(src, flags, throwErrorAt, parser) {
  2800. try {
  2801. return new RegExp(src, flags)
  2802. } catch (e) {
  2803. if (throwErrorAt !== undefined) {
  2804. if (e instanceof SyntaxError) { parser.raise(throwErrorAt, "Error parsing regular expression: " + e.message); }
  2805. throw e
  2806. }
  2807. }
  2808. }
  2809. var regexpUnicodeSupport = !!tryCreateRegexp("\uffff", "u");
  2810. pp$8.readRegexp = function() {
  2811. var this$1 = this;
  2812. var escaped, inClass, start = this.pos;
  2813. for (;;) {
  2814. if (this$1.pos >= this$1.input.length) { this$1.raise(start, "Unterminated regular expression"); }
  2815. var ch = this$1.input.charAt(this$1.pos);
  2816. if (lineBreak.test(ch)) { this$1.raise(start, "Unterminated regular expression"); }
  2817. if (!escaped) {
  2818. if (ch === "[") { inClass = true; }
  2819. else if (ch === "]" && inClass) { inClass = false; }
  2820. else if (ch === "/" && !inClass) { break }
  2821. escaped = ch === "\\";
  2822. } else { escaped = false; }
  2823. ++this$1.pos;
  2824. }
  2825. var content = this.input.slice(start, this.pos);
  2826. ++this.pos;
  2827. // Need to use `readWord1` because '\uXXXX' sequences are allowed
  2828. // here (don't ask).
  2829. var mods = this.readWord1();
  2830. var tmp = content, tmpFlags = "";
  2831. if (mods) {
  2832. var validFlags = /^[gim]*$/;
  2833. if (this.options.ecmaVersion >= 6) { validFlags = /^[gimuy]*$/; }
  2834. if (!validFlags.test(mods)) { this.raise(start, "Invalid regular expression flag"); }
  2835. if (mods.indexOf("u") >= 0) {
  2836. if (regexpUnicodeSupport) {
  2837. tmpFlags = "u";
  2838. } else {
  2839. // Replace each astral symbol and every Unicode escape sequence that
  2840. // possibly represents an astral symbol or a paired surrogate with a
  2841. // single ASCII symbol to avoid throwing on regular expressions that
  2842. // are only valid in combination with the `/u` flag.
  2843. // Note: replacing with the ASCII symbol `x` might cause false
  2844. // negatives in unlikely scenarios. For example, `[\u{61}-b]` is a
  2845. // perfectly valid pattern that is equivalent to `[a-b]`, but it would
  2846. // be replaced by `[x-b]` which throws an error.
  2847. tmp = tmp.replace(/\\u\{([0-9a-fA-F]+)\}/g, function (_match, code, offset) {
  2848. code = Number("0x" + code);
  2849. if (code > 0x10FFFF) { this$1.raise(start + offset + 3, "Code point out of bounds"); }
  2850. return "x"
  2851. });
  2852. tmp = tmp.replace(/\\u([a-fA-F0-9]{4})|[\uD800-\uDBFF][\uDC00-\uDFFF]/g, "x");
  2853. tmpFlags = tmpFlags.replace("u", "");
  2854. }
  2855. }
  2856. }
  2857. // Detect invalid regular expressions.
  2858. var value = null;
  2859. // Rhino's regular expression parser is flaky and throws uncatchable exceptions,
  2860. // so don't do detection if we are running under Rhino
  2861. if (!isRhino) {
  2862. tryCreateRegexp(tmp, tmpFlags, start, this);
  2863. // Get a regular expression object for this pattern-flag pair, or `null` in
  2864. // case the current environment doesn't support the flags it uses.
  2865. value = tryCreateRegexp(content, mods);
  2866. }
  2867. return this.finishToken(types.regexp, {pattern: content, flags: mods, value: value})
  2868. };
  2869. // Read an integer in the given radix. Return null if zero digits
  2870. // were read, the integer value otherwise. When `len` is given, this
  2871. // will return `null` unless the integer has exactly `len` digits.
  2872. pp$8.readInt = function(radix, len) {
  2873. var this$1 = this;
  2874. var start = this.pos, total = 0;
  2875. for (var i = 0, e = len == null ? Infinity : len; i < e; ++i) {
  2876. var code = this$1.input.charCodeAt(this$1.pos), val = (void 0);
  2877. if (code >= 97) { val = code - 97 + 10; } // a
  2878. else if (code >= 65) { val = code - 65 + 10; } // A
  2879. else if (code >= 48 && code <= 57) { val = code - 48; } // 0-9
  2880. else { val = Infinity; }
  2881. if (val >= radix) { break }
  2882. ++this$1.pos;
  2883. total = total * radix + val;
  2884. }
  2885. if (this.pos === start || len != null && this.pos - start !== len) { return null }
  2886. return total
  2887. };
  2888. pp$8.readRadixNumber = function(radix) {
  2889. this.pos += 2; // 0x
  2890. var val = this.readInt(radix);
  2891. if (val == null) { this.raise(this.start + 2, "Expected number in radix " + radix); }
  2892. if (isIdentifierStart(this.fullCharCodeAtPos())) { this.raise(this.pos, "Identifier directly after number"); }
  2893. return this.finishToken(types.num, val)
  2894. };
  2895. // Read an integer, octal integer, or floating-point number.
  2896. pp$8.readNumber = function(startsWithDot) {
  2897. var start = this.pos, isFloat = false, octal = this.input.charCodeAt(this.pos) === 48;
  2898. if (!startsWithDot && this.readInt(10) === null) { this.raise(start, "Invalid number"); }
  2899. if (octal && this.pos == start + 1) { octal = false; }
  2900. var next = this.input.charCodeAt(this.pos);
  2901. if (next === 46 && !octal) { // '.'
  2902. ++this.pos;
  2903. this.readInt(10);
  2904. isFloat = true;
  2905. next = this.input.charCodeAt(this.pos);
  2906. }
  2907. if ((next === 69 || next === 101) && !octal) { // 'eE'
  2908. next = this.input.charCodeAt(++this.pos);
  2909. if (next === 43 || next === 45) { ++this.pos; } // '+-'
  2910. if (this.readInt(10) === null) { this.raise(start, "Invalid number"); }
  2911. isFloat = true;
  2912. }
  2913. if (isIdentifierStart(this.fullCharCodeAtPos())) { this.raise(this.pos, "Identifier directly after number"); }
  2914. var str = this.input.slice(start, this.pos), val;
  2915. if (isFloat) { val = parseFloat(str); }
  2916. else if (!octal || str.length === 1) { val = parseInt(str, 10); }
  2917. else if (this.strict) { this.raise(start, "Invalid number"); }
  2918. else if (/[89]/.test(str)) { val = parseInt(str, 10); }
  2919. else { val = parseInt(str, 8); }
  2920. return this.finishToken(types.num, val)
  2921. };
  2922. // Read a string value, interpreting backslash-escapes.
  2923. pp$8.readCodePoint = function() {
  2924. var ch = this.input.charCodeAt(this.pos), code;
  2925. if (ch === 123) { // '{'
  2926. if (this.options.ecmaVersion < 6) { this.unexpected(); }
  2927. var codePos = ++this.pos;
  2928. code = this.readHexChar(this.input.indexOf("}", this.pos) - this.pos);
  2929. ++this.pos;
  2930. if (code > 0x10FFFF) { this.invalidStringToken(codePos, "Code point out of bounds"); }
  2931. } else {
  2932. code = this.readHexChar(4);
  2933. }
  2934. return code
  2935. };
  2936. function codePointToString(code) {
  2937. // UTF-16 Decoding
  2938. if (code <= 0xFFFF) { return String.fromCharCode(code) }
  2939. code -= 0x10000;
  2940. return String.fromCharCode((code >> 10) + 0xD800, (code & 1023) + 0xDC00)
  2941. }
  2942. pp$8.readString = function(quote) {
  2943. var this$1 = this;
  2944. var out = "", chunkStart = ++this.pos;
  2945. for (;;) {
  2946. if (this$1.pos >= this$1.input.length) { this$1.raise(this$1.start, "Unterminated string constant"); }
  2947. var ch = this$1.input.charCodeAt(this$1.pos);
  2948. if (ch === quote) { break }
  2949. if (ch === 92) { // '\'
  2950. out += this$1.input.slice(chunkStart, this$1.pos);
  2951. out += this$1.readEscapedChar(false);
  2952. chunkStart = this$1.pos;
  2953. } else {
  2954. if (isNewLine(ch)) { this$1.raise(this$1.start, "Unterminated string constant"); }
  2955. ++this$1.pos;
  2956. }
  2957. }
  2958. out += this.input.slice(chunkStart, this.pos++);
  2959. return this.finishToken(types.string, out)
  2960. };
  2961. // Reads template string tokens.
  2962. var INVALID_TEMPLATE_ESCAPE_ERROR = {};
  2963. pp$8.tryReadTemplateToken = function() {
  2964. this.inTemplateElement = true;
  2965. try {
  2966. this.readTmplToken();
  2967. } catch (err) {
  2968. if (err === INVALID_TEMPLATE_ESCAPE_ERROR) {
  2969. this.readInvalidTemplateToken();
  2970. } else {
  2971. throw err
  2972. }
  2973. }
  2974. this.inTemplateElement = false;
  2975. };
  2976. pp$8.invalidStringToken = function(position, message) {
  2977. if (this.inTemplateElement && this.options.ecmaVersion >= 9) {
  2978. throw INVALID_TEMPLATE_ESCAPE_ERROR
  2979. } else {
  2980. this.raise(position, message);
  2981. }
  2982. };
  2983. pp$8.readTmplToken = function() {
  2984. var this$1 = this;
  2985. var out = "", chunkStart = this.pos;
  2986. for (;;) {
  2987. if (this$1.pos >= this$1.input.length) { this$1.raise(this$1.start, "Unterminated template"); }
  2988. var ch = this$1.input.charCodeAt(this$1.pos);
  2989. if (ch === 96 || ch === 36 && this$1.input.charCodeAt(this$1.pos + 1) === 123) { // '`', '${'
  2990. if (this$1.pos === this$1.start && (this$1.type === types.template || this$1.type === types.invalidTemplate)) {
  2991. if (ch === 36) {
  2992. this$1.pos += 2;
  2993. return this$1.finishToken(types.dollarBraceL)
  2994. } else {
  2995. ++this$1.pos;
  2996. return this$1.finishToken(types.backQuote)
  2997. }
  2998. }
  2999. out += this$1.input.slice(chunkStart, this$1.pos);
  3000. return this$1.finishToken(types.template, out)
  3001. }
  3002. if (ch === 92) { // '\'
  3003. out += this$1.input.slice(chunkStart, this$1.pos);
  3004. out += this$1.readEscapedChar(true);
  3005. chunkStart = this$1.pos;
  3006. } else if (isNewLine(ch)) {
  3007. out += this$1.input.slice(chunkStart, this$1.pos);
  3008. ++this$1.pos;
  3009. switch (ch) {
  3010. case 13:
  3011. if (this$1.input.charCodeAt(this$1.pos) === 10) { ++this$1.pos; }
  3012. case 10:
  3013. out += "\n";
  3014. break
  3015. default:
  3016. out += String.fromCharCode(ch);
  3017. break
  3018. }
  3019. if (this$1.options.locations) {
  3020. ++this$1.curLine;
  3021. this$1.lineStart = this$1.pos;
  3022. }
  3023. chunkStart = this$1.pos;
  3024. } else {
  3025. ++this$1.pos;
  3026. }
  3027. }
  3028. };
  3029. // Reads a template token to search for the end, without validating any escape sequences
  3030. pp$8.readInvalidTemplateToken = function() {
  3031. var this$1 = this;
  3032. for (; this.pos < this.input.length; this.pos++) {
  3033. switch (this$1.input[this$1.pos]) {
  3034. case "\\":
  3035. ++this$1.pos;
  3036. break
  3037. case "$":
  3038. if (this$1.input[this$1.pos + 1] !== "{") {
  3039. break
  3040. }
  3041. // falls through
  3042. case "`":
  3043. return this$1.finishToken(types.invalidTemplate, this$1.input.slice(this$1.start, this$1.pos))
  3044. // no default
  3045. }
  3046. }
  3047. this.raise(this.start, "Unterminated template");
  3048. };
  3049. // Used to read escaped characters
  3050. pp$8.readEscapedChar = function(inTemplate) {
  3051. var ch = this.input.charCodeAt(++this.pos);
  3052. ++this.pos;
  3053. switch (ch) {
  3054. case 110: return "\n" // 'n' -> '\n'
  3055. case 114: return "\r" // 'r' -> '\r'
  3056. case 120: return String.fromCharCode(this.readHexChar(2)) // 'x'
  3057. case 117: return codePointToString(this.readCodePoint()) // 'u'
  3058. case 116: return "\t" // 't' -> '\t'
  3059. case 98: return "\b" // 'b' -> '\b'
  3060. case 118: return "\u000b" // 'v' -> '\u000b'
  3061. case 102: return "\f" // 'f' -> '\f'
  3062. case 13: if (this.input.charCodeAt(this.pos) === 10) { ++this.pos; } // '\r\n'
  3063. case 10: // ' \n'
  3064. if (this.options.locations) { this.lineStart = this.pos; ++this.curLine; }
  3065. return ""
  3066. default:
  3067. if (ch >= 48 && ch <= 55) {
  3068. var octalStr = this.input.substr(this.pos - 1, 3).match(/^[0-7]+/)[0];
  3069. var octal = parseInt(octalStr, 8);
  3070. if (octal > 255) {
  3071. octalStr = octalStr.slice(0, -1);
  3072. octal = parseInt(octalStr, 8);
  3073. }
  3074. if (octalStr !== "0" && (this.strict || inTemplate)) {
  3075. this.invalidStringToken(this.pos - 2, "Octal literal in strict mode");
  3076. }
  3077. this.pos += octalStr.length - 1;
  3078. return String.fromCharCode(octal)
  3079. }
  3080. return String.fromCharCode(ch)
  3081. }
  3082. };
  3083. // Used to read character escape sequences ('\x', '\u', '\U').
  3084. pp$8.readHexChar = function(len) {
  3085. var codePos = this.pos;
  3086. var n = this.readInt(16, len);
  3087. if (n === null) { this.invalidStringToken(codePos, "Bad character escape sequence"); }
  3088. return n
  3089. };
  3090. // Read an identifier, and return it as a string. Sets `this.containsEsc`
  3091. // to whether the word contained a '\u' escape.
  3092. //
  3093. // Incrementally adds only escaped chars, adding other chunks as-is
  3094. // as a micro-optimization.
  3095. pp$8.readWord1 = function() {
  3096. var this$1 = this;
  3097. this.containsEsc = false;
  3098. var word = "", first = true, chunkStart = this.pos;
  3099. var astral = this.options.ecmaVersion >= 6;
  3100. while (this.pos < this.input.length) {
  3101. var ch = this$1.fullCharCodeAtPos();
  3102. if (isIdentifierChar(ch, astral)) {
  3103. this$1.pos += ch <= 0xffff ? 1 : 2;
  3104. } else if (ch === 92) { // "\"
  3105. this$1.containsEsc = true;
  3106. word += this$1.input.slice(chunkStart, this$1.pos);
  3107. var escStart = this$1.pos;
  3108. if (this$1.input.charCodeAt(++this$1.pos) != 117) // "u"
  3109. { this$1.invalidStringToken(this$1.pos, "Expecting Unicode escape sequence \\uXXXX"); }
  3110. ++this$1.pos;
  3111. var esc = this$1.readCodePoint();
  3112. if (!(first ? isIdentifierStart : isIdentifierChar)(esc, astral))
  3113. { this$1.invalidStringToken(escStart, "Invalid Unicode escape"); }
  3114. word += codePointToString(esc);
  3115. chunkStart = this$1.pos;
  3116. } else {
  3117. break
  3118. }
  3119. first = false;
  3120. }
  3121. return word + this.input.slice(chunkStart, this.pos)
  3122. };
  3123. // Read an identifier or keyword token. Will check for reserved
  3124. // words when necessary.
  3125. pp$8.readWord = function() {
  3126. var word = this.readWord1();
  3127. var type = types.name;
  3128. if (this.keywords.test(word)) {
  3129. if (this.containsEsc) { this.raiseRecoverable(this.start, "Escape sequence in keyword " + word); }
  3130. type = keywords$1[word];
  3131. }
  3132. return this.finishToken(type, word)
  3133. };
  3134. // Acorn is a tiny, fast JavaScript parser written in JavaScript.
  3135. //
  3136. // Acorn was written by Marijn Haverbeke, Ingvar Stepanyan, and
  3137. // various contributors and released under an MIT license.
  3138. //
  3139. // Git repositories for Acorn are available at
  3140. //
  3141. // http://marijnhaverbeke.nl/git/acorn
  3142. // https://github.com/ternjs/acorn.git
  3143. //
  3144. // Please use the [github bug tracker][ghbt] to report issues.
  3145. //
  3146. // [ghbt]: https://github.com/ternjs/acorn/issues
  3147. //
  3148. // This file defines the main parser interface. The library also comes
  3149. // with a [error-tolerant parser][dammit] and an
  3150. // [abstract syntax tree walker][walk], defined in other files.
  3151. //
  3152. // [dammit]: acorn_loose.js
  3153. // [walk]: util/walk.js
  3154. var version = "5.1.2";
  3155. // The main exported interface (under `self.acorn` when in the
  3156. // browser) is a `parse` function that takes a code string and
  3157. // returns an abstract syntax tree as specified by [Mozilla parser
  3158. // API][api].
  3159. //
  3160. // [api]: https://developer.mozilla.org/en-US/docs/SpiderMonkey/Parser_API
  3161. function parse$1(input, options) {
  3162. return new Parser(options, input).parse()
  3163. }
  3164. // This function tries to parse a single expression at a given
  3165. // offset in a string. Useful for parsing mixed-language formats
  3166. // that embed JavaScript expressions.
  3167. function parseExpressionAt(input, pos, options) {
  3168. var p = new Parser(options, input, pos);
  3169. p.nextToken();
  3170. return p.parseExpression()
  3171. }
  3172. // Acorn is organized as a tokenizer and a recursive-descent parser.
  3173. // The `tokenizer` export provides an interface to the tokenizer.
  3174. function tokenizer(input, options) {
  3175. return new Parser(options, input)
  3176. }
  3177. // This is a terrible kludge to support the existing, pre-ES6
  3178. // interface where the loose parser module retroactively adds exports
  3179. // to this module.
  3180. var parse_dammit;
  3181. var LooseParser;
  3182. var pluginsLoose; // eslint-disable-line camelcase
  3183. function addLooseExports(parse, Parser$$1, plugins$$1) {
  3184. parse_dammit = parse; // eslint-disable-line camelcase
  3185. LooseParser = Parser$$1;
  3186. pluginsLoose = plugins$$1;
  3187. }
  3188. var acorn = Object.freeze({
  3189. version: version,
  3190. parse: parse$1,
  3191. parseExpressionAt: parseExpressionAt,
  3192. tokenizer: tokenizer,
  3193. get parse_dammit () { return parse_dammit; },
  3194. get LooseParser () { return LooseParser; },
  3195. get pluginsLoose () { return pluginsLoose; },
  3196. addLooseExports: addLooseExports,
  3197. Parser: Parser,
  3198. plugins: plugins,
  3199. defaultOptions: defaultOptions,
  3200. Position: Position,
  3201. SourceLocation: SourceLocation,
  3202. getLineInfo: getLineInfo,
  3203. Node: Node,
  3204. TokenType: TokenType,
  3205. tokTypes: types,
  3206. keywordTypes: keywords$1,
  3207. TokContext: TokContext,
  3208. tokContexts: types$1,
  3209. isIdentifierChar: isIdentifierChar,
  3210. isIdentifierStart: isIdentifierStart,
  3211. Token: Token,
  3212. isNewLine: isNewLine,
  3213. lineBreak: lineBreak,
  3214. lineBreakG: lineBreakG,
  3215. nonASCIIwhitespace: nonASCIIwhitespace
  3216. });
  3217. var xhtml = {
  3218. quot: '\u0022',
  3219. amp: '&',
  3220. apos: '\u0027',
  3221. lt: '<',
  3222. gt: '>',
  3223. nbsp: '\u00A0',
  3224. iexcl: '\u00A1',
  3225. cent: '\u00A2',
  3226. pound: '\u00A3',
  3227. curren: '\u00A4',
  3228. yen: '\u00A5',
  3229. brvbar: '\u00A6',
  3230. sect: '\u00A7',
  3231. uml: '\u00A8',
  3232. copy: '\u00A9',
  3233. ordf: '\u00AA',
  3234. laquo: '\u00AB',
  3235. not: '\u00AC',
  3236. shy: '\u00AD',
  3237. reg: '\u00AE',
  3238. macr: '\u00AF',
  3239. deg: '\u00B0',
  3240. plusmn: '\u00B1',
  3241. sup2: '\u00B2',
  3242. sup3: '\u00B3',
  3243. acute: '\u00B4',
  3244. micro: '\u00B5',
  3245. para: '\u00B6',
  3246. middot: '\u00B7',
  3247. cedil: '\u00B8',
  3248. sup1: '\u00B9',
  3249. ordm: '\u00BA',
  3250. raquo: '\u00BB',
  3251. frac14: '\u00BC',
  3252. frac12: '\u00BD',
  3253. frac34: '\u00BE',
  3254. iquest: '\u00BF',
  3255. Agrave: '\u00C0',
  3256. Aacute: '\u00C1',
  3257. Acirc: '\u00C2',
  3258. Atilde: '\u00C3',
  3259. Auml: '\u00C4',
  3260. Aring: '\u00C5',
  3261. AElig: '\u00C6',
  3262. Ccedil: '\u00C7',
  3263. Egrave: '\u00C8',
  3264. Eacute: '\u00C9',
  3265. Ecirc: '\u00CA',
  3266. Euml: '\u00CB',
  3267. Igrave: '\u00CC',
  3268. Iacute: '\u00CD',
  3269. Icirc: '\u00CE',
  3270. Iuml: '\u00CF',
  3271. ETH: '\u00D0',
  3272. Ntilde: '\u00D1',
  3273. Ograve: '\u00D2',
  3274. Oacute: '\u00D3',
  3275. Ocirc: '\u00D4',
  3276. Otilde: '\u00D5',
  3277. Ouml: '\u00D6',
  3278. times: '\u00D7',
  3279. Oslash: '\u00D8',
  3280. Ugrave: '\u00D9',
  3281. Uacute: '\u00DA',
  3282. Ucirc: '\u00DB',
  3283. Uuml: '\u00DC',
  3284. Yacute: '\u00DD',
  3285. THORN: '\u00DE',
  3286. szlig: '\u00DF',
  3287. agrave: '\u00E0',
  3288. aacute: '\u00E1',
  3289. acirc: '\u00E2',
  3290. atilde: '\u00E3',
  3291. auml: '\u00E4',
  3292. aring: '\u00E5',
  3293. aelig: '\u00E6',
  3294. ccedil: '\u00E7',
  3295. egrave: '\u00E8',
  3296. eacute: '\u00E9',
  3297. ecirc: '\u00EA',
  3298. euml: '\u00EB',
  3299. igrave: '\u00EC',
  3300. iacute: '\u00ED',
  3301. icirc: '\u00EE',
  3302. iuml: '\u00EF',
  3303. eth: '\u00F0',
  3304. ntilde: '\u00F1',
  3305. ograve: '\u00F2',
  3306. oacute: '\u00F3',
  3307. ocirc: '\u00F4',
  3308. otilde: '\u00F5',
  3309. ouml: '\u00F6',
  3310. divide: '\u00F7',
  3311. oslash: '\u00F8',
  3312. ugrave: '\u00F9',
  3313. uacute: '\u00FA',
  3314. ucirc: '\u00FB',
  3315. uuml: '\u00FC',
  3316. yacute: '\u00FD',
  3317. thorn: '\u00FE',
  3318. yuml: '\u00FF',
  3319. OElig: '\u0152',
  3320. oelig: '\u0153',
  3321. Scaron: '\u0160',
  3322. scaron: '\u0161',
  3323. Yuml: '\u0178',
  3324. fnof: '\u0192',
  3325. circ: '\u02C6',
  3326. tilde: '\u02DC',
  3327. Alpha: '\u0391',
  3328. Beta: '\u0392',
  3329. Gamma: '\u0393',
  3330. Delta: '\u0394',
  3331. Epsilon: '\u0395',
  3332. Zeta: '\u0396',
  3333. Eta: '\u0397',
  3334. Theta: '\u0398',
  3335. Iota: '\u0399',
  3336. Kappa: '\u039A',
  3337. Lambda: '\u039B',
  3338. Mu: '\u039C',
  3339. Nu: '\u039D',
  3340. Xi: '\u039E',
  3341. Omicron: '\u039F',
  3342. Pi: '\u03A0',
  3343. Rho: '\u03A1',
  3344. Sigma: '\u03A3',
  3345. Tau: '\u03A4',
  3346. Upsilon: '\u03A5',
  3347. Phi: '\u03A6',
  3348. Chi: '\u03A7',
  3349. Psi: '\u03A8',
  3350. Omega: '\u03A9',
  3351. alpha: '\u03B1',
  3352. beta: '\u03B2',
  3353. gamma: '\u03B3',
  3354. delta: '\u03B4',
  3355. epsilon: '\u03B5',
  3356. zeta: '\u03B6',
  3357. eta: '\u03B7',
  3358. theta: '\u03B8',
  3359. iota: '\u03B9',
  3360. kappa: '\u03BA',
  3361. lambda: '\u03BB',
  3362. mu: '\u03BC',
  3363. nu: '\u03BD',
  3364. xi: '\u03BE',
  3365. omicron: '\u03BF',
  3366. pi: '\u03C0',
  3367. rho: '\u03C1',
  3368. sigmaf: '\u03C2',
  3369. sigma: '\u03C3',
  3370. tau: '\u03C4',
  3371. upsilon: '\u03C5',
  3372. phi: '\u03C6',
  3373. chi: '\u03C7',
  3374. psi: '\u03C8',
  3375. omega: '\u03C9',
  3376. thetasym: '\u03D1',
  3377. upsih: '\u03D2',
  3378. piv: '\u03D6',
  3379. ensp: '\u2002',
  3380. emsp: '\u2003',
  3381. thinsp: '\u2009',
  3382. zwnj: '\u200C',
  3383. zwj: '\u200D',
  3384. lrm: '\u200E',
  3385. rlm: '\u200F',
  3386. ndash: '\u2013',
  3387. mdash: '\u2014',
  3388. lsquo: '\u2018',
  3389. rsquo: '\u2019',
  3390. sbquo: '\u201A',
  3391. ldquo: '\u201C',
  3392. rdquo: '\u201D',
  3393. bdquo: '\u201E',
  3394. dagger: '\u2020',
  3395. Dagger: '\u2021',
  3396. bull: '\u2022',
  3397. hellip: '\u2026',
  3398. permil: '\u2030',
  3399. prime: '\u2032',
  3400. Prime: '\u2033',
  3401. lsaquo: '\u2039',
  3402. rsaquo: '\u203A',
  3403. oline: '\u203E',
  3404. frasl: '\u2044',
  3405. euro: '\u20AC',
  3406. image: '\u2111',
  3407. weierp: '\u2118',
  3408. real: '\u211C',
  3409. trade: '\u2122',
  3410. alefsym: '\u2135',
  3411. larr: '\u2190',
  3412. uarr: '\u2191',
  3413. rarr: '\u2192',
  3414. darr: '\u2193',
  3415. harr: '\u2194',
  3416. crarr: '\u21B5',
  3417. lArr: '\u21D0',
  3418. uArr: '\u21D1',
  3419. rArr: '\u21D2',
  3420. dArr: '\u21D3',
  3421. hArr: '\u21D4',
  3422. forall: '\u2200',
  3423. part: '\u2202',
  3424. exist: '\u2203',
  3425. empty: '\u2205',
  3426. nabla: '\u2207',
  3427. isin: '\u2208',
  3428. notin: '\u2209',
  3429. ni: '\u220B',
  3430. prod: '\u220F',
  3431. sum: '\u2211',
  3432. minus: '\u2212',
  3433. lowast: '\u2217',
  3434. radic: '\u221A',
  3435. prop: '\u221D',
  3436. infin: '\u221E',
  3437. ang: '\u2220',
  3438. and: '\u2227',
  3439. or: '\u2228',
  3440. cap: '\u2229',
  3441. cup: '\u222A',
  3442. 'int': '\u222B',
  3443. there4: '\u2234',
  3444. sim: '\u223C',
  3445. cong: '\u2245',
  3446. asymp: '\u2248',
  3447. ne: '\u2260',
  3448. equiv: '\u2261',
  3449. le: '\u2264',
  3450. ge: '\u2265',
  3451. sub: '\u2282',
  3452. sup: '\u2283',
  3453. nsub: '\u2284',
  3454. sube: '\u2286',
  3455. supe: '\u2287',
  3456. oplus: '\u2295',
  3457. otimes: '\u2297',
  3458. perp: '\u22A5',
  3459. sdot: '\u22C5',
  3460. lceil: '\u2308',
  3461. rceil: '\u2309',
  3462. lfloor: '\u230A',
  3463. rfloor: '\u230B',
  3464. lang: '\u2329',
  3465. rang: '\u232A',
  3466. loz: '\u25CA',
  3467. spades: '\u2660',
  3468. clubs: '\u2663',
  3469. hearts: '\u2665',
  3470. diams: '\u2666'
  3471. };
  3472. 'use strict';
  3473. var hexNumber = /^[\da-fA-F]+$/;
  3474. var decimalNumber = /^\d+$/;
  3475. var inject = function(acorn) {
  3476. var tt = acorn.tokTypes;
  3477. var tc = acorn.tokContexts;
  3478. tc.j_oTag = new acorn.TokContext('<tag', false);
  3479. tc.j_cTag = new acorn.TokContext('</tag', false);
  3480. tc.j_expr = new acorn.TokContext('<tag>...</tag>', true, true);
  3481. tt.jsxName = new acorn.TokenType('jsxName');
  3482. tt.jsxText = new acorn.TokenType('jsxText', {beforeExpr: true});
  3483. tt.jsxTagStart = new acorn.TokenType('jsxTagStart');
  3484. tt.jsxTagEnd = new acorn.TokenType('jsxTagEnd');
  3485. tt.jsxTagStart.updateContext = function() {
  3486. this.context.push(tc.j_expr); // treat as beginning of JSX expression
  3487. this.context.push(tc.j_oTag); // start opening tag context
  3488. this.exprAllowed = false;
  3489. };
  3490. tt.jsxTagEnd.updateContext = function(prevType) {
  3491. var out = this.context.pop();
  3492. if (out === tc.j_oTag && prevType === tt.slash || out === tc.j_cTag) {
  3493. this.context.pop();
  3494. this.exprAllowed = this.curContext() === tc.j_expr;
  3495. } else {
  3496. this.exprAllowed = true;
  3497. }
  3498. };
  3499. var pp = acorn.Parser.prototype;
  3500. // Reads inline JSX contents token.
  3501. pp.jsx_readToken = function() {
  3502. var out = '', chunkStart = this.pos;
  3503. for (;;) {
  3504. if (this.pos >= this.input.length)
  3505. this.raise(this.start, 'Unterminated JSX contents');
  3506. var ch = this.input.charCodeAt(this.pos);
  3507. switch (ch) {
  3508. case 60: // '<'
  3509. case 123: // '{'
  3510. if (this.pos === this.start) {
  3511. if (ch === 60 && this.exprAllowed) {
  3512. ++this.pos;
  3513. return this.finishToken(tt.jsxTagStart);
  3514. }
  3515. return this.getTokenFromCode(ch);
  3516. }
  3517. out += this.input.slice(chunkStart, this.pos);
  3518. return this.finishToken(tt.jsxText, out);
  3519. case 38: // '&'
  3520. out += this.input.slice(chunkStart, this.pos);
  3521. out += this.jsx_readEntity();
  3522. chunkStart = this.pos;
  3523. break;
  3524. default:
  3525. if (acorn.isNewLine(ch)) {
  3526. out += this.input.slice(chunkStart, this.pos);
  3527. out += this.jsx_readNewLine(true);
  3528. chunkStart = this.pos;
  3529. } else {
  3530. ++this.pos;
  3531. }
  3532. }
  3533. }
  3534. };
  3535. pp.jsx_readNewLine = function(normalizeCRLF) {
  3536. var ch = this.input.charCodeAt(this.pos);
  3537. var out;
  3538. ++this.pos;
  3539. if (ch === 13 && this.input.charCodeAt(this.pos) === 10) {
  3540. ++this.pos;
  3541. out = normalizeCRLF ? '\n' : '\r\n';
  3542. } else {
  3543. out = String.fromCharCode(ch);
  3544. }
  3545. if (this.options.locations) {
  3546. ++this.curLine;
  3547. this.lineStart = this.pos;
  3548. }
  3549. return out;
  3550. };
  3551. pp.jsx_readString = function(quote) {
  3552. var out = '', chunkStart = ++this.pos;
  3553. for (;;) {
  3554. if (this.pos >= this.input.length)
  3555. this.raise(this.start, 'Unterminated string constant');
  3556. var ch = this.input.charCodeAt(this.pos);
  3557. if (ch === quote) break;
  3558. if (ch === 38) { // '&'
  3559. out += this.input.slice(chunkStart, this.pos);
  3560. out += this.jsx_readEntity();
  3561. chunkStart = this.pos;
  3562. } else if (acorn.isNewLine(ch)) {
  3563. out += this.input.slice(chunkStart, this.pos);
  3564. out += this.jsx_readNewLine(false);
  3565. chunkStart = this.pos;
  3566. } else {
  3567. ++this.pos;
  3568. }
  3569. }
  3570. out += this.input.slice(chunkStart, this.pos++);
  3571. return this.finishToken(tt.string, out);
  3572. };
  3573. pp.jsx_readEntity = function() {
  3574. var str = '', count = 0, entity;
  3575. var ch = this.input[this.pos];
  3576. if (ch !== '&')
  3577. this.raise(this.pos, 'Entity must start with an ampersand');
  3578. var startPos = ++this.pos;
  3579. while (this.pos < this.input.length && count++ < 10) {
  3580. ch = this.input[this.pos++];
  3581. if (ch === ';') {
  3582. if (str[0] === '#') {
  3583. if (str[1] === 'x') {
  3584. str = str.substr(2);
  3585. if (hexNumber.test(str))
  3586. entity = String.fromCharCode(parseInt(str, 16));
  3587. } else {
  3588. str = str.substr(1);
  3589. if (decimalNumber.test(str))
  3590. entity = String.fromCharCode(parseInt(str, 10));
  3591. }
  3592. } else {
  3593. entity = xhtml[str];
  3594. }
  3595. break;
  3596. }
  3597. str += ch;
  3598. }
  3599. if (!entity) {
  3600. this.pos = startPos;
  3601. return '&';
  3602. }
  3603. return entity;
  3604. };
  3605. // Read a JSX identifier (valid tag or attribute name).
  3606. //
  3607. // Optimized version since JSX identifiers can't contain
  3608. // escape characters and so can be read as single slice.
  3609. // Also assumes that first character was already checked
  3610. // by isIdentifierStart in readToken.
  3611. pp.jsx_readWord = function() {
  3612. var ch, start = this.pos;
  3613. do {
  3614. ch = this.input.charCodeAt(++this.pos);
  3615. } while (acorn.isIdentifierChar(ch) || ch === 45); // '-'
  3616. return this.finishToken(tt.jsxName, this.input.slice(start, this.pos));
  3617. };
  3618. // Transforms JSX element name to string.
  3619. function getQualifiedJSXName(object) {
  3620. if (object.type === 'JSXIdentifier')
  3621. return object.name;
  3622. if (object.type === 'JSXNamespacedName')
  3623. return object.namespace.name + ':' + object.name.name;
  3624. if (object.type === 'JSXMemberExpression')
  3625. return getQualifiedJSXName(object.object) + '.' +
  3626. getQualifiedJSXName(object.property);
  3627. }
  3628. // Parse next token as JSX identifier
  3629. pp.jsx_parseIdentifier = function() {
  3630. var node = this.startNode();
  3631. if (this.type === tt.jsxName)
  3632. node.name = this.value;
  3633. else if (this.type.keyword)
  3634. node.name = this.type.keyword;
  3635. else
  3636. this.unexpected();
  3637. this.next();
  3638. return this.finishNode(node, 'JSXIdentifier');
  3639. };
  3640. // Parse namespaced identifier.
  3641. pp.jsx_parseNamespacedName = function() {
  3642. var startPos = this.start, startLoc = this.startLoc;
  3643. var name = this.jsx_parseIdentifier();
  3644. if (!this.options.plugins.jsx.allowNamespaces || !this.eat(tt.colon)) return name;
  3645. var node = this.startNodeAt(startPos, startLoc);
  3646. node.namespace = name;
  3647. node.name = this.jsx_parseIdentifier();
  3648. return this.finishNode(node, 'JSXNamespacedName');
  3649. };
  3650. // Parses element name in any form - namespaced, member
  3651. // or single identifier.
  3652. pp.jsx_parseElementName = function() {
  3653. var startPos = this.start, startLoc = this.startLoc;
  3654. var node = this.jsx_parseNamespacedName();
  3655. if (this.type === tt.dot && node.type === 'JSXNamespacedName' && !this.options.plugins.jsx.allowNamespacedObjects) {
  3656. this.unexpected();
  3657. }
  3658. while (this.eat(tt.dot)) {
  3659. var newNode = this.startNodeAt(startPos, startLoc);
  3660. newNode.object = node;
  3661. newNode.property = this.jsx_parseIdentifier();
  3662. node = this.finishNode(newNode, 'JSXMemberExpression');
  3663. }
  3664. return node;
  3665. };
  3666. // Parses any type of JSX attribute value.
  3667. pp.jsx_parseAttributeValue = function() {
  3668. switch (this.type) {
  3669. case tt.braceL:
  3670. var node = this.jsx_parseExpressionContainer();
  3671. if (node.expression.type === 'JSXEmptyExpression')
  3672. this.raise(node.start, 'JSX attributes must only be assigned a non-empty expression');
  3673. return node;
  3674. case tt.jsxTagStart:
  3675. case tt.string:
  3676. return this.parseExprAtom();
  3677. default:
  3678. this.raise(this.start, 'JSX value should be either an expression or a quoted JSX text');
  3679. }
  3680. };
  3681. // JSXEmptyExpression is unique type since it doesn't actually parse anything,
  3682. // and so it should start at the end of last read token (left brace) and finish
  3683. // at the beginning of the next one (right brace).
  3684. pp.jsx_parseEmptyExpression = function() {
  3685. var node = this.startNodeAt(this.lastTokEnd, this.lastTokEndLoc);
  3686. return this.finishNodeAt(node, 'JSXEmptyExpression', this.start, this.startLoc);
  3687. };
  3688. // Parses JSX expression enclosed into curly brackets.
  3689. pp.jsx_parseExpressionContainer = function() {
  3690. var node = this.startNode();
  3691. this.next();
  3692. node.expression = this.type === tt.braceR
  3693. ? this.jsx_parseEmptyExpression()
  3694. : this.parseExpression();
  3695. this.expect(tt.braceR);
  3696. return this.finishNode(node, 'JSXExpressionContainer');
  3697. };
  3698. // Parses following JSX attribute name-value pair.
  3699. pp.jsx_parseAttribute = function() {
  3700. var node = this.startNode();
  3701. if (this.eat(tt.braceL)) {
  3702. this.expect(tt.ellipsis);
  3703. node.argument = this.parseMaybeAssign();
  3704. this.expect(tt.braceR);
  3705. return this.finishNode(node, 'JSXSpreadAttribute');
  3706. }
  3707. node.name = this.jsx_parseNamespacedName();
  3708. node.value = this.eat(tt.eq) ? this.jsx_parseAttributeValue() : null;
  3709. return this.finishNode(node, 'JSXAttribute');
  3710. };
  3711. // Parses JSX opening tag starting after '<'.
  3712. pp.jsx_parseOpeningElementAt = function(startPos, startLoc) {
  3713. var node = this.startNodeAt(startPos, startLoc);
  3714. node.attributes = [];
  3715. node.name = this.jsx_parseElementName();
  3716. while (this.type !== tt.slash && this.type !== tt.jsxTagEnd)
  3717. node.attributes.push(this.jsx_parseAttribute());
  3718. node.selfClosing = this.eat(tt.slash);
  3719. this.expect(tt.jsxTagEnd);
  3720. return this.finishNode(node, 'JSXOpeningElement');
  3721. };
  3722. // Parses JSX closing tag starting after '</'.
  3723. pp.jsx_parseClosingElementAt = function(startPos, startLoc) {
  3724. var node = this.startNodeAt(startPos, startLoc);
  3725. node.name = this.jsx_parseElementName();
  3726. this.expect(tt.jsxTagEnd);
  3727. return this.finishNode(node, 'JSXClosingElement');
  3728. };
  3729. // Parses entire JSX element, including it's opening tag
  3730. // (starting after '<'), attributes, contents and closing tag.
  3731. pp.jsx_parseElementAt = function(startPos, startLoc) {
  3732. var node = this.startNodeAt(startPos, startLoc);
  3733. var children = [];
  3734. var openingElement = this.jsx_parseOpeningElementAt(startPos, startLoc);
  3735. var closingElement = null;
  3736. if (!openingElement.selfClosing) {
  3737. contents: for (;;) {
  3738. switch (this.type) {
  3739. case tt.jsxTagStart:
  3740. startPos = this.start; startLoc = this.startLoc;
  3741. this.next();
  3742. if (this.eat(tt.slash)) {
  3743. closingElement = this.jsx_parseClosingElementAt(startPos, startLoc);
  3744. break contents;
  3745. }
  3746. children.push(this.jsx_parseElementAt(startPos, startLoc));
  3747. break;
  3748. case tt.jsxText:
  3749. children.push(this.parseExprAtom());
  3750. break;
  3751. case tt.braceL:
  3752. children.push(this.jsx_parseExpressionContainer());
  3753. break;
  3754. default:
  3755. this.unexpected();
  3756. }
  3757. }
  3758. if (getQualifiedJSXName(closingElement.name) !== getQualifiedJSXName(openingElement.name)) {
  3759. this.raise(
  3760. closingElement.start,
  3761. 'Expected corresponding JSX closing tag for <' + getQualifiedJSXName(openingElement.name) + '>');
  3762. }
  3763. }
  3764. node.openingElement = openingElement;
  3765. node.closingElement = closingElement;
  3766. node.children = children;
  3767. if (this.type === tt.relational && this.value === "<") {
  3768. this.raise(this.start, "Adjacent JSX elements must be wrapped in an enclosing tag");
  3769. }
  3770. return this.finishNode(node, 'JSXElement');
  3771. };
  3772. // Parses entire JSX element from current position.
  3773. pp.jsx_parseElement = function() {
  3774. var startPos = this.start, startLoc = this.startLoc;
  3775. this.next();
  3776. return this.jsx_parseElementAt(startPos, startLoc);
  3777. };
  3778. acorn.plugins.jsx = function(instance, opts) {
  3779. if (!opts) {
  3780. return;
  3781. }
  3782. if (typeof opts !== 'object') {
  3783. opts = {};
  3784. }
  3785. instance.options.plugins.jsx = {
  3786. allowNamespaces: opts.allowNamespaces !== false,
  3787. allowNamespacedObjects: !!opts.allowNamespacedObjects
  3788. };
  3789. instance.extend('parseExprAtom', function(inner) {
  3790. return function(refShortHandDefaultPos) {
  3791. if (this.type === tt.jsxText)
  3792. return this.parseLiteral(this.value);
  3793. else if (this.type === tt.jsxTagStart)
  3794. return this.jsx_parseElement();
  3795. else
  3796. return inner.call(this, refShortHandDefaultPos);
  3797. };
  3798. });
  3799. instance.extend('readToken', function(inner) {
  3800. return function(code) {
  3801. var context = this.curContext();
  3802. if (context === tc.j_expr) return this.jsx_readToken();
  3803. if (context === tc.j_oTag || context === tc.j_cTag) {
  3804. if (acorn.isIdentifierStart(code)) return this.jsx_readWord();
  3805. if (code == 62) {
  3806. ++this.pos;
  3807. return this.finishToken(tt.jsxTagEnd);
  3808. }
  3809. if ((code === 34 || code === 39) && context == tc.j_oTag)
  3810. return this.jsx_readString(code);
  3811. }
  3812. if (code === 60 && this.exprAllowed) {
  3813. ++this.pos;
  3814. return this.finishToken(tt.jsxTagStart);
  3815. }
  3816. return inner.call(this, code);
  3817. };
  3818. });
  3819. instance.extend('updateContext', function(inner) {
  3820. return function(prevType) {
  3821. if (this.type == tt.braceL) {
  3822. var curContext = this.curContext();
  3823. if (curContext == tc.j_oTag) this.context.push(tc.b_expr);
  3824. else if (curContext == tc.j_expr) this.context.push(tc.b_tmpl);
  3825. else inner.call(this, prevType);
  3826. this.exprAllowed = true;
  3827. } else if (this.type === tt.slash && prevType === tt.jsxTagStart) {
  3828. this.context.length -= 2; // do not consider JSX expr -> JSX open tag -> ... anymore
  3829. this.context.push(tc.j_cTag); // reconsider as closing tag context
  3830. this.exprAllowed = false;
  3831. } else {
  3832. return inner.call(this, prevType);
  3833. }
  3834. };
  3835. });
  3836. };
  3837. return acorn;
  3838. };
  3839. 'use strict';
  3840. var inject$1 = function(acorn) {
  3841. var tt = acorn.tokTypes;
  3842. var pp = acorn.Parser.prototype;
  3843. // this is the same parseObj that acorn has with...
  3844. function parseObj(isPattern, refDestructuringErrors) {
  3845. var this$1 = this;
  3846. var node = this.startNode(), first = true, propHash = {};
  3847. node.properties = [];
  3848. this.next();
  3849. while (!this$1.eat(tt.braceR)) {
  3850. if (!first) {
  3851. this$1.expect(tt.comma);
  3852. if (this$1.afterTrailingComma(tt.braceR)) break
  3853. } else first = false;
  3854. var prop = this$1.startNode(), isGenerator, isAsync, startPos, startLoc;
  3855. if (this$1.options.ecmaVersion >= 6) {
  3856. // ...the spread logic borrowed from babylon :)
  3857. if (this$1.type === tt.ellipsis) {
  3858. prop = this$1.parseSpread();
  3859. prop.type = isPattern ? "RestProperty" : "SpreadProperty";
  3860. node.properties.push(prop);
  3861. continue
  3862. }
  3863. prop.method = false;
  3864. prop.shorthand = false;
  3865. if (isPattern || refDestructuringErrors) {
  3866. startPos = this$1.start;
  3867. startLoc = this$1.startLoc;
  3868. }
  3869. if (!isPattern)
  3870. isGenerator = this$1.eat(tt.star);
  3871. }
  3872. this$1.parsePropertyName(prop);
  3873. if (!isPattern && this$1.options.ecmaVersion >= 8 && !isGenerator && !prop.computed &&
  3874. prop.key.type === "Identifier" && prop.key.name === "async" && this$1.type !== tt.parenL &&
  3875. this$1.type !== tt.colon && !this$1.canInsertSemicolon()) {
  3876. isAsync = true;
  3877. this$1.parsePropertyName(prop, refDestructuringErrors);
  3878. } else {
  3879. isAsync = false;
  3880. }
  3881. this$1.parsePropertyValue(prop, isPattern, isGenerator, isAsync, startPos, startLoc, refDestructuringErrors);
  3882. this$1.checkPropClash(prop, propHash);
  3883. node.properties.push(this$1.finishNode(prop, "Property"));
  3884. }
  3885. return this.finishNode(node, isPattern ? "ObjectPattern" : "ObjectExpression")
  3886. }
  3887. acorn.plugins.objectSpread = function objectSpreadPlugin(instance) {
  3888. pp.parseObj = parseObj;
  3889. };
  3890. return acorn;
  3891. };
  3892. var charToInteger = {};
  3893. var integerToChar = {};
  3894. 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='.split( '' ).forEach( function ( char, i ) {
  3895. charToInteger[ char ] = i;
  3896. integerToChar[ i ] = char;
  3897. });
  3898. function decode ( string ) {
  3899. var result = [];
  3900. var shift = 0;
  3901. var value = 0;
  3902. for ( var i = 0; i < string.length; i += 1 ) {
  3903. var integer = charToInteger[ string[i] ];
  3904. if ( integer === undefined ) {
  3905. throw new Error( 'Invalid character (' + string[i] + ')' );
  3906. }
  3907. var hasContinuationBit = integer & 32;
  3908. integer &= 31;
  3909. value += integer << shift;
  3910. if ( hasContinuationBit ) {
  3911. shift += 5;
  3912. } else {
  3913. var shouldNegate = value & 1;
  3914. value >>= 1;
  3915. result.push( shouldNegate ? -value : value );
  3916. // reset
  3917. value = shift = 0;
  3918. }
  3919. }
  3920. return result;
  3921. }
  3922. function encode ( value ) {
  3923. var result;
  3924. if ( typeof value === 'number' ) {
  3925. result = encodeInteger( value );
  3926. } else {
  3927. result = '';
  3928. for ( var i = 0; i < value.length; i += 1 ) {
  3929. result += encodeInteger( value[i] );
  3930. }
  3931. }
  3932. return result;
  3933. }
  3934. function encodeInteger ( num ) {
  3935. var result = '';
  3936. if ( num < 0 ) {
  3937. num = ( -num << 1 ) | 1;
  3938. } else {
  3939. num <<= 1;
  3940. }
  3941. do {
  3942. var clamped = num & 31;
  3943. num >>= 5;
  3944. if ( num > 0 ) {
  3945. clamped |= 32;
  3946. }
  3947. result += integerToChar[ clamped ];
  3948. } while ( num > 0 );
  3949. return result;
  3950. }
  3951. var vlq = Object.freeze({
  3952. decode: decode,
  3953. encode: encode
  3954. });
  3955. var vlq$1 = ( vlq && undefined ) || vlq;
  3956. 'use strict';
  3957. function Chunk ( start, end, content ) {
  3958. this.start = start;
  3959. this.end = end;
  3960. this.original = content;
  3961. this.intro = '';
  3962. this.outro = '';
  3963. this.content = content;
  3964. this.storeName = false;
  3965. this.edited = false;
  3966. // we make these non-enumerable, for sanity while debugging
  3967. Object.defineProperties( this, {
  3968. previous: { writable: true, value: null },
  3969. next: { writable: true, value: null }
  3970. });
  3971. }
  3972. Chunk.prototype = {
  3973. append: function append ( content ) {
  3974. this.outro += content;
  3975. },
  3976. clone: function clone () {
  3977. var chunk = new Chunk( this.start, this.end, this.original );
  3978. chunk.intro = this.intro;
  3979. chunk.outro = this.outro;
  3980. chunk.content = this.content;
  3981. chunk.storeName = this.storeName;
  3982. chunk.edited = this.edited;
  3983. return chunk;
  3984. },
  3985. contains: function contains ( index ) {
  3986. return this.start < index && index < this.end;
  3987. },
  3988. eachNext: function eachNext ( fn ) {
  3989. var chunk = this;
  3990. while ( chunk ) {
  3991. fn( chunk );
  3992. chunk = chunk.next;
  3993. }
  3994. },
  3995. eachPrevious: function eachPrevious ( fn ) {
  3996. var chunk = this;
  3997. while ( chunk ) {
  3998. fn( chunk );
  3999. chunk = chunk.previous;
  4000. }
  4001. },
  4002. edit: function edit ( content, storeName ) {
  4003. this.content = content;
  4004. this.storeName = storeName;
  4005. this.edited = true;
  4006. return this;
  4007. },
  4008. prepend: function prepend ( content ) {
  4009. this.intro = content + this.intro;
  4010. },
  4011. split: function split ( index ) {
  4012. var sliceIndex = index - this.start;
  4013. var originalBefore = this.original.slice( 0, sliceIndex );
  4014. var originalAfter = this.original.slice( sliceIndex );
  4015. this.original = originalBefore;
  4016. var newChunk = new Chunk( index, this.end, originalAfter );
  4017. newChunk.outro = this.outro;
  4018. this.outro = '';
  4019. this.end = index;
  4020. if ( this.edited ) {
  4021. // TODO is this block necessary?...
  4022. newChunk.edit( '', false );
  4023. this.content = '';
  4024. } else {
  4025. this.content = originalBefore;
  4026. }
  4027. newChunk.next = this.next;
  4028. if ( newChunk.next ) newChunk.next.previous = newChunk;
  4029. newChunk.previous = this;
  4030. this.next = newChunk;
  4031. return newChunk;
  4032. },
  4033. toString: function toString () {
  4034. return this.intro + this.content + this.outro;
  4035. },
  4036. trimEnd: function trimEnd ( rx ) {
  4037. this.outro = this.outro.replace( rx, '' );
  4038. if ( this.outro.length ) return true;
  4039. var trimmed = this.content.replace( rx, '' );
  4040. if ( trimmed.length ) {
  4041. if ( trimmed !== this.content ) {
  4042. this.split( this.start + trimmed.length ).edit( '', false );
  4043. }
  4044. return true;
  4045. } else {
  4046. this.edit( '', false );
  4047. this.intro = this.intro.replace( rx, '' );
  4048. if ( this.intro.length ) return true;
  4049. }
  4050. },
  4051. trimStart: function trimStart ( rx ) {
  4052. this.intro = this.intro.replace( rx, '' );
  4053. if ( this.intro.length ) return true;
  4054. var trimmed = this.content.replace( rx, '' );
  4055. if ( trimmed.length ) {
  4056. if ( trimmed !== this.content ) {
  4057. this.split( this.end - trimmed.length );
  4058. this.edit( '', false );
  4059. }
  4060. return true;
  4061. } else {
  4062. this.edit( '', false );
  4063. this.outro = this.outro.replace( rx, '' );
  4064. if ( this.outro.length ) return true;
  4065. }
  4066. }
  4067. };
  4068. var _btoa;
  4069. if ( typeof window !== 'undefined' && typeof window.btoa === 'function' ) {
  4070. _btoa = window.btoa;
  4071. } else if ( typeof Buffer === 'function' ) {
  4072. _btoa = function ( str ) { return new Buffer( str ).toString( 'base64' ); };
  4073. } else {
  4074. _btoa = function () {
  4075. throw new Error( 'Unsupported environment: `window.btoa` or `Buffer` should be supported.' );
  4076. };
  4077. }
  4078. var btoa = _btoa;
  4079. function SourceMap ( properties ) {
  4080. this.version = 3;
  4081. this.file = properties.file;
  4082. this.sources = properties.sources;
  4083. this.sourcesContent = properties.sourcesContent;
  4084. this.names = properties.names;
  4085. this.mappings = properties.mappings;
  4086. }
  4087. SourceMap.prototype = {
  4088. toString: function toString () {
  4089. return JSON.stringify( this );
  4090. },
  4091. toUrl: function toUrl () {
  4092. return 'data:application/json;charset=utf-8;base64,' + btoa( this.toString() );
  4093. }
  4094. };
  4095. function guessIndent ( code ) {
  4096. var lines = code.split( '\n' );
  4097. var tabbed = lines.filter( function ( line ) { return /^\t+/.test( line ); } );
  4098. var spaced = lines.filter( function ( line ) { return /^ {2,}/.test( line ); } );
  4099. if ( tabbed.length === 0 && spaced.length === 0 ) {
  4100. return null;
  4101. }
  4102. // More lines tabbed than spaced? Assume tabs, and
  4103. // default to tabs in the case of a tie (or nothing
  4104. // to go on)
  4105. if ( tabbed.length >= spaced.length ) {
  4106. return '\t';
  4107. }
  4108. // Otherwise, we need to guess the multiple
  4109. var min = spaced.reduce( function ( previous, current ) {
  4110. var numSpaces = /^ +/.exec( current )[0].length;
  4111. return Math.min( numSpaces, previous );
  4112. }, Infinity );
  4113. return new Array( min + 1 ).join( ' ' );
  4114. }
  4115. function getLocator ( source ) {
  4116. var originalLines = source.split( '\n' );
  4117. var start = 0;
  4118. var lineRanges = originalLines.map( function ( line, i ) {
  4119. var end = start + line.length + 1;
  4120. var range = { start: start, end: end, line: i };
  4121. start = end;
  4122. return range;
  4123. });
  4124. var i = 0;
  4125. function rangeContains ( range, index ) {
  4126. return range.start <= index && index < range.end;
  4127. }
  4128. function getLocation ( range, index ) {
  4129. return { line: range.line, column: index - range.start };
  4130. }
  4131. return function locate ( index ) {
  4132. var range = lineRanges[i];
  4133. var d = index >= range.end ? 1 : -1;
  4134. while ( range ) {
  4135. if ( rangeContains( range, index ) ) return getLocation( range, index );
  4136. i += d;
  4137. range = lineRanges[i];
  4138. }
  4139. };
  4140. }
  4141. function encodeMappings ( original, intro, chunk, hires, sourcemapLocations, sourceIndex, offsets, names ) {
  4142. var rawLines = [];
  4143. var generatedCodeLine = intro.split( '\n' ).length - 1;
  4144. var rawSegments = rawLines[ generatedCodeLine ] = [];
  4145. var generatedCodeColumn = 0;
  4146. var locate = getLocator( original );
  4147. function addEdit ( content, original, loc, nameIndex, i ) {
  4148. if ( i || content.length ) {
  4149. rawSegments.push({
  4150. generatedCodeLine: generatedCodeLine,
  4151. generatedCodeColumn: generatedCodeColumn,
  4152. sourceCodeLine: loc.line,
  4153. sourceCodeColumn: loc.column,
  4154. sourceCodeName: nameIndex,
  4155. sourceIndex: sourceIndex
  4156. });
  4157. }
  4158. var lines = content.split( '\n' );
  4159. var lastLine = lines.pop();
  4160. if ( lines.length ) {
  4161. generatedCodeLine += lines.length;
  4162. rawLines[ generatedCodeLine ] = rawSegments = [];
  4163. generatedCodeColumn = lastLine.length;
  4164. } else {
  4165. generatedCodeColumn += lastLine.length;
  4166. }
  4167. lines = original.split( '\n' );
  4168. lastLine = lines.pop();
  4169. if ( lines.length ) {
  4170. loc.line += lines.length;
  4171. loc.column = lastLine.length;
  4172. } else {
  4173. loc.column += lastLine.length;
  4174. }
  4175. }
  4176. function addUneditedChunk ( chunk, loc ) {
  4177. var originalCharIndex = chunk.start;
  4178. var first = true;
  4179. while ( originalCharIndex < chunk.end ) {
  4180. if ( hires || first || sourcemapLocations[ originalCharIndex ] ) {
  4181. rawSegments.push({
  4182. generatedCodeLine: generatedCodeLine,
  4183. generatedCodeColumn: generatedCodeColumn,
  4184. sourceCodeLine: loc.line,
  4185. sourceCodeColumn: loc.column,
  4186. sourceCodeName: -1,
  4187. sourceIndex: sourceIndex
  4188. });
  4189. }
  4190. if ( original[ originalCharIndex ] === '\n' ) {
  4191. loc.line += 1;
  4192. loc.column = 0;
  4193. generatedCodeLine += 1;
  4194. rawLines[ generatedCodeLine ] = rawSegments = [];
  4195. generatedCodeColumn = 0;
  4196. } else {
  4197. loc.column += 1;
  4198. generatedCodeColumn += 1;
  4199. }
  4200. originalCharIndex += 1;
  4201. first = false;
  4202. }
  4203. }
  4204. while ( chunk ) {
  4205. var loc = locate( chunk.start );
  4206. if ( chunk.intro.length ) {
  4207. addEdit( chunk.intro, '', loc, -1, !!chunk.previous );
  4208. }
  4209. if ( chunk.edited ) {
  4210. addEdit( chunk.content, chunk.original, loc, chunk.storeName ? names.indexOf( chunk.original ) : -1, !!chunk.previous );
  4211. } else {
  4212. addUneditedChunk( chunk, loc );
  4213. }
  4214. if ( chunk.outro.length ) {
  4215. addEdit( chunk.outro, '', loc, -1, !!chunk.previous );
  4216. }
  4217. var nextChunk = chunk.next;
  4218. chunk = nextChunk;
  4219. }
  4220. offsets.sourceIndex = offsets.sourceIndex || 0;
  4221. offsets.sourceCodeLine = offsets.sourceCodeLine || 0;
  4222. offsets.sourceCodeColumn = offsets.sourceCodeColumn || 0;
  4223. offsets.sourceCodeName = offsets.sourceCodeName || 0;
  4224. var encoded = rawLines.map( function ( segments ) {
  4225. var generatedCodeColumn = 0;
  4226. return segments.map( function ( segment ) {
  4227. var arr = [
  4228. segment.generatedCodeColumn - generatedCodeColumn,
  4229. segment.sourceIndex - offsets.sourceIndex,
  4230. segment.sourceCodeLine - offsets.sourceCodeLine,
  4231. segment.sourceCodeColumn - offsets.sourceCodeColumn
  4232. ];
  4233. generatedCodeColumn = segment.generatedCodeColumn;
  4234. offsets.sourceIndex = segment.sourceIndex;
  4235. offsets.sourceCodeLine = segment.sourceCodeLine;
  4236. offsets.sourceCodeColumn = segment.sourceCodeColumn;
  4237. if ( ~segment.sourceCodeName ) {
  4238. arr.push( segment.sourceCodeName - offsets.sourceCodeName );
  4239. offsets.sourceCodeName = segment.sourceCodeName;
  4240. }
  4241. return vlq$1.encode( arr );
  4242. }).join( ',' );
  4243. }).join( ';' );
  4244. return encoded;
  4245. }
  4246. function getRelativePath ( from, to ) {
  4247. var fromParts = from.split( /[\/\\]/ );
  4248. var toParts = to.split( /[\/\\]/ );
  4249. fromParts.pop(); // get dirname
  4250. while ( fromParts[0] === toParts[0] ) {
  4251. fromParts.shift();
  4252. toParts.shift();
  4253. }
  4254. if ( fromParts.length ) {
  4255. var i = fromParts.length;
  4256. while ( i-- ) fromParts[i] = '..';
  4257. }
  4258. return fromParts.concat( toParts ).join( '/' );
  4259. }
  4260. var toString$1 = Object.prototype.toString;
  4261. function isObject ( thing ) {
  4262. return toString$1.call( thing ) === '[object Object]';
  4263. }
  4264. function MagicString ( string, options ) {
  4265. if ( options === void 0 ) options = {};
  4266. var chunk = new Chunk( 0, string.length, string );
  4267. Object.defineProperties( this, {
  4268. original: { writable: true, value: string },
  4269. outro: { writable: true, value: '' },
  4270. intro: { writable: true, value: '' },
  4271. firstChunk: { writable: true, value: chunk },
  4272. lastChunk: { writable: true, value: chunk },
  4273. lastSearchedChunk: { writable: true, value: chunk },
  4274. byStart: { writable: true, value: {} },
  4275. byEnd: { writable: true, value: {} },
  4276. filename: { writable: true, value: options.filename },
  4277. indentExclusionRanges: { writable: true, value: options.indentExclusionRanges },
  4278. sourcemapLocations: { writable: true, value: {} },
  4279. storedNames: { writable: true, value: {} },
  4280. indentStr: { writable: true, value: guessIndent( string ) }
  4281. });
  4282. this.byStart[ 0 ] = chunk;
  4283. this.byEnd[ string.length ] = chunk;
  4284. }
  4285. MagicString.prototype = {
  4286. addSourcemapLocation: function addSourcemapLocation ( char ) {
  4287. this.sourcemapLocations[ char ] = true;
  4288. },
  4289. append: function append ( content ) {
  4290. if ( typeof content !== 'string' ) throw new TypeError( 'outro content must be a string' );
  4291. this.outro += content;
  4292. return this;
  4293. },
  4294. clone: function clone () {
  4295. var cloned = new MagicString( this.original, { filename: this.filename });
  4296. var originalChunk = this.firstChunk;
  4297. var clonedChunk = cloned.firstChunk = cloned.lastSearchedChunk = originalChunk.clone();
  4298. while ( originalChunk ) {
  4299. cloned.byStart[ clonedChunk.start ] = clonedChunk;
  4300. cloned.byEnd[ clonedChunk.end ] = clonedChunk;
  4301. var nextOriginalChunk = originalChunk.next;
  4302. var nextClonedChunk = nextOriginalChunk && nextOriginalChunk.clone();
  4303. if ( nextClonedChunk ) {
  4304. clonedChunk.next = nextClonedChunk;
  4305. nextClonedChunk.previous = clonedChunk;
  4306. clonedChunk = nextClonedChunk;
  4307. }
  4308. originalChunk = nextOriginalChunk;
  4309. }
  4310. cloned.lastChunk = clonedChunk;
  4311. if ( this.indentExclusionRanges ) {
  4312. cloned.indentExclusionRanges = typeof this.indentExclusionRanges[0] === 'number' ?
  4313. [ this.indentExclusionRanges[0], this.indentExclusionRanges[1] ] :
  4314. this.indentExclusionRanges.map( function ( range ) { return [ range.start, range.end ]; } );
  4315. }
  4316. Object.keys( this.sourcemapLocations ).forEach( function ( loc ) {
  4317. cloned.sourcemapLocations[ loc ] = true;
  4318. });
  4319. return cloned;
  4320. },
  4321. generateMap: function generateMap ( options ) {
  4322. options = options || {};
  4323. var names = Object.keys( this.storedNames );
  4324. var map = new SourceMap({
  4325. file: ( options.file ? options.file.split( /[\/\\]/ ).pop() : null ),
  4326. sources: [ options.source ? getRelativePath( options.file || '', options.source ) : null ],
  4327. sourcesContent: options.includeContent ? [ this.original ] : [ null ],
  4328. names: names,
  4329. mappings: this.getMappings( options.hires, 0, {}, names )
  4330. });
  4331. return map;
  4332. },
  4333. getIndentString: function getIndentString () {
  4334. return this.indentStr === null ? '\t' : this.indentStr;
  4335. },
  4336. getMappings: function getMappings ( hires, sourceIndex, offsets, names ) {
  4337. return encodeMappings( this.original, this.intro, this.firstChunk, hires, this.sourcemapLocations, sourceIndex, offsets, names );
  4338. },
  4339. indent: function indent ( indentStr, options ) {
  4340. var this$1 = this;
  4341. var pattern = /^[^\r\n]/gm;
  4342. if ( isObject( indentStr ) ) {
  4343. options = indentStr;
  4344. indentStr = undefined;
  4345. }
  4346. indentStr = indentStr !== undefined ? indentStr : ( this.indentStr || '\t' );
  4347. if ( indentStr === '' ) return this; // noop
  4348. options = options || {};
  4349. // Process exclusion ranges
  4350. var isExcluded = {};
  4351. if ( options.exclude ) {
  4352. var exclusions = typeof options.exclude[0] === 'number' ? [ options.exclude ] : options.exclude;
  4353. exclusions.forEach( function ( exclusion ) {
  4354. for ( var i = exclusion[0]; i < exclusion[1]; i += 1 ) {
  4355. isExcluded[i] = true;
  4356. }
  4357. });
  4358. }
  4359. var shouldIndentNextCharacter = options.indentStart !== false;
  4360. var replacer = function ( match ) {
  4361. if ( shouldIndentNextCharacter ) return ("" + indentStr + match);
  4362. shouldIndentNextCharacter = true;
  4363. return match;
  4364. };
  4365. this.intro = this.intro.replace( pattern, replacer );
  4366. var charIndex = 0;
  4367. var chunk = this.firstChunk;
  4368. while ( chunk ) {
  4369. var end = chunk.end;
  4370. if ( chunk.edited ) {
  4371. if ( !isExcluded[ charIndex ] ) {
  4372. chunk.content = chunk.content.replace( pattern, replacer );
  4373. if ( chunk.content.length ) {
  4374. shouldIndentNextCharacter = chunk.content[ chunk.content.length - 1 ] === '\n';
  4375. }
  4376. }
  4377. } else {
  4378. charIndex = chunk.start;
  4379. while ( charIndex < end ) {
  4380. if ( !isExcluded[ charIndex ] ) {
  4381. var char = this$1.original[ charIndex ];
  4382. if ( char === '\n' ) {
  4383. shouldIndentNextCharacter = true;
  4384. } else if ( char !== '\r' && shouldIndentNextCharacter ) {
  4385. shouldIndentNextCharacter = false;
  4386. if ( charIndex === chunk.start ) {
  4387. chunk.prepend( indentStr );
  4388. } else {
  4389. var rhs = chunk.split( charIndex );
  4390. rhs.prepend( indentStr );
  4391. this$1.byStart[ charIndex ] = rhs;
  4392. this$1.byEnd[ charIndex ] = chunk;
  4393. chunk = rhs;
  4394. }
  4395. }
  4396. }
  4397. charIndex += 1;
  4398. }
  4399. }
  4400. charIndex = chunk.end;
  4401. chunk = chunk.next;
  4402. }
  4403. this.outro = this.outro.replace( pattern, replacer );
  4404. return this;
  4405. },
  4406. insert: function insert () {
  4407. throw new Error( 'magicString.insert(...) is deprecated. Use insertRight(...) or insertLeft(...)' );
  4408. },
  4409. insertLeft: function insertLeft ( index, content ) {
  4410. if ( typeof content !== 'string' ) throw new TypeError( 'inserted content must be a string' );
  4411. this._split( index );
  4412. var chunk = this.byEnd[ index ];
  4413. if ( chunk ) {
  4414. chunk.append( content );
  4415. } else {
  4416. this.intro += content;
  4417. }
  4418. return this;
  4419. },
  4420. insertRight: function insertRight ( index, content ) {
  4421. if ( typeof content !== 'string' ) throw new TypeError( 'inserted content must be a string' );
  4422. this._split( index );
  4423. var chunk = this.byStart[ index ];
  4424. if ( chunk ) {
  4425. chunk.prepend( content );
  4426. } else {
  4427. this.outro += content;
  4428. }
  4429. return this;
  4430. },
  4431. move: function move ( start, end, index ) {
  4432. if ( index >= start && index <= end ) throw new Error( 'Cannot move a selection inside itself' );
  4433. this._split( start );
  4434. this._split( end );
  4435. this._split( index );
  4436. var first = this.byStart[ start ];
  4437. var last = this.byEnd[ end ];
  4438. var oldLeft = first.previous;
  4439. var oldRight = last.next;
  4440. var newRight = this.byStart[ index ];
  4441. if ( !newRight && last === this.lastChunk ) return this;
  4442. var newLeft = newRight ? newRight.previous : this.lastChunk;
  4443. if ( oldLeft ) oldLeft.next = oldRight;
  4444. if ( oldRight ) oldRight.previous = oldLeft;
  4445. if ( newLeft ) newLeft.next = first;
  4446. if ( newRight ) newRight.previous = last;
  4447. if ( !first.previous ) this.firstChunk = last.next;
  4448. if ( !last.next ) {
  4449. this.lastChunk = first.previous;
  4450. this.lastChunk.next = null;
  4451. }
  4452. first.previous = newLeft;
  4453. last.next = newRight;
  4454. if ( !newLeft ) this.firstChunk = first;
  4455. if ( !newRight ) this.lastChunk = last;
  4456. return this;
  4457. },
  4458. overwrite: function overwrite ( start, end, content, storeName ) {
  4459. var this$1 = this;
  4460. if ( typeof content !== 'string' ) throw new TypeError( 'replacement content must be a string' );
  4461. while ( start < 0 ) start += this$1.original.length;
  4462. while ( end < 0 ) end += this$1.original.length;
  4463. if ( end > this.original.length ) throw new Error( 'end is out of bounds' );
  4464. if ( start === end ) throw new Error( 'Cannot overwrite a zero-length range – use insertLeft or insertRight instead' );
  4465. this._split( start );
  4466. this._split( end );
  4467. if ( storeName ) {
  4468. var original = this.original.slice( start, end );
  4469. this.storedNames[ original ] = true;
  4470. }
  4471. var first = this.byStart[ start ];
  4472. var last = this.byEnd[ end ];
  4473. if ( first ) {
  4474. first.edit( content, storeName );
  4475. if ( first !== last ) {
  4476. first.outro = '';
  4477. var chunk = first.next;
  4478. while ( chunk !== last ) {
  4479. chunk.edit( '', false );
  4480. chunk.intro = chunk.outro = '';
  4481. chunk = chunk.next;
  4482. }
  4483. chunk.edit( '', false );
  4484. chunk.intro = '';
  4485. }
  4486. }
  4487. else {
  4488. // must be inserting at the end
  4489. var newChunk = new Chunk( start, end, '' ).edit( content, storeName );
  4490. // TODO last chunk in the array may not be the last chunk, if it's moved...
  4491. last.next = newChunk;
  4492. newChunk.previous = last;
  4493. }
  4494. return this;
  4495. },
  4496. prepend: function prepend ( content ) {
  4497. if ( typeof content !== 'string' ) throw new TypeError( 'outro content must be a string' );
  4498. this.intro = content + this.intro;
  4499. return this;
  4500. },
  4501. remove: function remove ( start, end ) {
  4502. var this$1 = this;
  4503. while ( start < 0 ) start += this$1.original.length;
  4504. while ( end < 0 ) end += this$1.original.length;
  4505. if ( start === end ) return this;
  4506. if ( start < 0 || end > this.original.length ) throw new Error( 'Character is out of bounds' );
  4507. if ( start > end ) throw new Error( 'end must be greater than start' );
  4508. return this.overwrite( start, end, '', false );
  4509. },
  4510. slice: function slice ( start, end ) {
  4511. var this$1 = this;
  4512. if ( start === void 0 ) start = 0;
  4513. if ( end === void 0 ) end = this.original.length;
  4514. while ( start < 0 ) start += this$1.original.length;
  4515. while ( end < 0 ) end += this$1.original.length;
  4516. var result = '';
  4517. // find start chunk
  4518. var chunk = this.firstChunk;
  4519. while ( chunk && ( chunk.start > start || chunk.end <= start ) ) {
  4520. // found end chunk before start
  4521. if ( chunk.start < end && chunk.end >= end ) {
  4522. return result;
  4523. }
  4524. chunk = chunk.next;
  4525. }
  4526. if ( chunk && chunk.edited && chunk.start !== start ) throw new Error(("Cannot use replaced character " + start + " as slice start anchor."));
  4527. var startChunk = chunk;
  4528. while ( chunk ) {
  4529. if ( chunk.intro && ( startChunk !== chunk || chunk.start === start ) ) {
  4530. result += chunk.intro;
  4531. }
  4532. var containsEnd = chunk.start < end && chunk.end >= end;
  4533. if ( containsEnd && chunk.edited && chunk.end !== end ) throw new Error(("Cannot use replaced character " + end + " as slice end anchor."));
  4534. var sliceStart = startChunk === chunk ? start - chunk.start : 0;
  4535. var sliceEnd = containsEnd ? chunk.content.length + end - chunk.end : chunk.content.length;
  4536. result += chunk.content.slice( sliceStart, sliceEnd );
  4537. if ( chunk.outro && ( !containsEnd || chunk.end === end ) ) {
  4538. result += chunk.outro;
  4539. }
  4540. if ( containsEnd ) {
  4541. break;
  4542. }
  4543. chunk = chunk.next;
  4544. }
  4545. return result;
  4546. },
  4547. // TODO deprecate this? not really very useful
  4548. snip: function snip ( start, end ) {
  4549. var clone = this.clone();
  4550. clone.remove( 0, start );
  4551. clone.remove( end, clone.original.length );
  4552. return clone;
  4553. },
  4554. _split: function _split ( index ) {
  4555. var this$1 = this;
  4556. if ( this.byStart[ index ] || this.byEnd[ index ] ) return;
  4557. var chunk = this.lastSearchedChunk;
  4558. var searchForward = index > chunk.end;
  4559. while ( true ) {
  4560. if ( chunk.contains( index ) ) return this$1._splitChunk( chunk, index );
  4561. chunk = searchForward ?
  4562. this$1.byStart[ chunk.end ] :
  4563. this$1.byEnd[ chunk.start ];
  4564. }
  4565. },
  4566. _splitChunk: function _splitChunk ( chunk, index ) {
  4567. if ( chunk.edited && chunk.content.length ) { // zero-length edited chunks are a special case (overlapping replacements)
  4568. var loc = getLocator( this.original )( index );
  4569. throw new Error( ("Cannot split a chunk that has already been edited (" + (loc.line) + ":" + (loc.column) + " – \"" + (chunk.original) + "\")") );
  4570. }
  4571. var newChunk = chunk.split( index );
  4572. this.byEnd[ index ] = chunk;
  4573. this.byStart[ index ] = newChunk;
  4574. this.byEnd[ newChunk.end ] = newChunk;
  4575. if ( chunk === this.lastChunk ) this.lastChunk = newChunk;
  4576. this.lastSearchedChunk = chunk;
  4577. return true;
  4578. },
  4579. toString: function toString () {
  4580. var str = this.intro;
  4581. var chunk = this.firstChunk;
  4582. while ( chunk ) {
  4583. str += chunk.toString();
  4584. chunk = chunk.next;
  4585. }
  4586. return str + this.outro;
  4587. },
  4588. trimLines: function trimLines () {
  4589. return this.trim('[\\r\\n]');
  4590. },
  4591. trim: function trim ( charType ) {
  4592. return this.trimStart( charType ).trimEnd( charType );
  4593. },
  4594. trimEnd: function trimEnd ( charType ) {
  4595. var this$1 = this;
  4596. var rx = new RegExp( ( charType || '\\s' ) + '+$' );
  4597. this.outro = this.outro.replace( rx, '' );
  4598. if ( this.outro.length ) return this;
  4599. var chunk = this.lastChunk;
  4600. do {
  4601. var end = chunk.end;
  4602. var aborted = chunk.trimEnd( rx );
  4603. // if chunk was trimmed, we have a new lastChunk
  4604. if ( chunk.end !== end ) {
  4605. this$1.lastChunk = chunk.next;
  4606. this$1.byEnd[ chunk.end ] = chunk;
  4607. this$1.byStart[ chunk.next.start ] = chunk.next;
  4608. }
  4609. if ( aborted ) return this$1;
  4610. chunk = chunk.previous;
  4611. } while ( chunk );
  4612. return this;
  4613. },
  4614. trimStart: function trimStart ( charType ) {
  4615. var this$1 = this;
  4616. var rx = new RegExp( '^' + ( charType || '\\s' ) + '+' );
  4617. this.intro = this.intro.replace( rx, '' );
  4618. if ( this.intro.length ) return this;
  4619. var chunk = this.firstChunk;
  4620. do {
  4621. var end = chunk.end;
  4622. var aborted = chunk.trimStart( rx );
  4623. if ( chunk.end !== end ) {
  4624. // special case...
  4625. if ( chunk === this$1.lastChunk ) this$1.lastChunk = chunk.next;
  4626. this$1.byEnd[ chunk.end ] = chunk;
  4627. this$1.byStart[ chunk.next.start ] = chunk.next;
  4628. }
  4629. if ( aborted ) return this$1;
  4630. chunk = chunk.next;
  4631. } while ( chunk );
  4632. return this;
  4633. }
  4634. };
  4635. var hasOwnProp = Object.prototype.hasOwnProperty;
  4636. function Bundle ( options ) {
  4637. if ( options === void 0 ) options = {};
  4638. this.intro = options.intro || '';
  4639. this.separator = options.separator !== undefined ? options.separator : '\n';
  4640. this.sources = [];
  4641. this.uniqueSources = [];
  4642. this.uniqueSourceIndexByFilename = {};
  4643. }
  4644. Bundle.prototype = {
  4645. addSource: function addSource ( source ) {
  4646. if ( source instanceof MagicString ) {
  4647. return this.addSource({
  4648. content: source,
  4649. filename: source.filename,
  4650. separator: this.separator
  4651. });
  4652. }
  4653. if ( !isObject( source ) || !source.content ) {
  4654. throw new Error( 'bundle.addSource() takes an object with a `content` property, which should be an instance of MagicString, and an optional `filename`' );
  4655. }
  4656. [ 'filename', 'indentExclusionRanges', 'separator' ].forEach( function ( option ) {
  4657. if ( !hasOwnProp.call( source, option ) ) source[ option ] = source.content[ option ];
  4658. });
  4659. if ( source.separator === undefined ) { // TODO there's a bunch of this sort of thing, needs cleaning up
  4660. source.separator = this.separator;
  4661. }
  4662. if ( source.filename ) {
  4663. if ( !hasOwnProp.call( this.uniqueSourceIndexByFilename, source.filename ) ) {
  4664. this.uniqueSourceIndexByFilename[ source.filename ] = this.uniqueSources.length;
  4665. this.uniqueSources.push({ filename: source.filename, content: source.content.original });
  4666. } else {
  4667. var uniqueSource = this.uniqueSources[ this.uniqueSourceIndexByFilename[ source.filename ] ];
  4668. if ( source.content.original !== uniqueSource.content ) {
  4669. throw new Error( ("Illegal source: same filename (" + (source.filename) + "), different contents") );
  4670. }
  4671. }
  4672. }
  4673. this.sources.push( source );
  4674. return this;
  4675. },
  4676. append: function append ( str, options ) {
  4677. this.addSource({
  4678. content: new MagicString( str ),
  4679. separator: ( options && options.separator ) || ''
  4680. });
  4681. return this;
  4682. },
  4683. clone: function clone () {
  4684. var bundle = new Bundle({
  4685. intro: this.intro,
  4686. separator: this.separator
  4687. });
  4688. this.sources.forEach( function ( source ) {
  4689. bundle.addSource({
  4690. filename: source.filename,
  4691. content: source.content.clone(),
  4692. separator: source.separator
  4693. });
  4694. });
  4695. return bundle;
  4696. },
  4697. generateMap: function generateMap ( options ) {
  4698. var this$1 = this;
  4699. var offsets = {};
  4700. var names = [];
  4701. this.sources.forEach( function ( source ) {
  4702. Object.keys( source.content.storedNames ).forEach( function ( name ) {
  4703. if ( !~names.indexOf( name ) ) names.push( name );
  4704. });
  4705. });
  4706. var encoded = (
  4707. getSemis( this.intro ) +
  4708. this.sources.map( function ( source, i ) {
  4709. var prefix = ( i > 0 ) ? ( getSemis( source.separator ) || ',' ) : '';
  4710. var mappings;
  4711. // we don't bother encoding sources without a filename
  4712. if ( !source.filename ) {
  4713. mappings = getSemis( source.content.toString() );
  4714. } else {
  4715. var sourceIndex = this$1.uniqueSourceIndexByFilename[ source.filename ];
  4716. mappings = source.content.getMappings( options.hires, sourceIndex, offsets, names );
  4717. }
  4718. return prefix + mappings;
  4719. }).join( '' )
  4720. );
  4721. return new SourceMap({
  4722. file: ( options.file ? options.file.split( /[\/\\]/ ).pop() : null ),
  4723. sources: this.uniqueSources.map( function ( source ) {
  4724. return options.file ? getRelativePath( options.file, source.filename ) : source.filename;
  4725. }),
  4726. sourcesContent: this.uniqueSources.map( function ( source ) {
  4727. return options.includeContent ? source.content : null;
  4728. }),
  4729. names: names,
  4730. mappings: encoded
  4731. });
  4732. },
  4733. getIndentString: function getIndentString () {
  4734. var indentStringCounts = {};
  4735. this.sources.forEach( function ( source ) {
  4736. var indentStr = source.content.indentStr;
  4737. if ( indentStr === null ) return;
  4738. if ( !indentStringCounts[ indentStr ] ) indentStringCounts[ indentStr ] = 0;
  4739. indentStringCounts[ indentStr ] += 1;
  4740. });
  4741. return ( Object.keys( indentStringCounts ).sort( function ( a, b ) {
  4742. return indentStringCounts[a] - indentStringCounts[b];
  4743. })[0] ) || '\t';
  4744. },
  4745. indent: function indent ( indentStr ) {
  4746. var this$1 = this;
  4747. if ( !arguments.length ) {
  4748. indentStr = this.getIndentString();
  4749. }
  4750. if ( indentStr === '' ) return this; // noop
  4751. var trailingNewline = !this.intro || this.intro.slice( -1 ) === '\n';
  4752. this.sources.forEach( function ( source, i ) {
  4753. var separator = source.separator !== undefined ? source.separator : this$1.separator;
  4754. var indentStart = trailingNewline || ( i > 0 && /\r?\n$/.test( separator ) );
  4755. source.content.indent( indentStr, {
  4756. exclude: source.indentExclusionRanges,
  4757. indentStart: indentStart//: trailingNewline || /\r?\n$/.test( separator ) //true///\r?\n/.test( separator )
  4758. });
  4759. // TODO this is a very slow way to determine this
  4760. trailingNewline = source.content.toString().slice( 0, -1 ) === '\n';
  4761. });
  4762. if ( this.intro ) {
  4763. this.intro = indentStr + this.intro.replace( /^[^\n]/gm, function ( match, index ) {
  4764. return index > 0 ? indentStr + match : match;
  4765. });
  4766. }
  4767. return this;
  4768. },
  4769. prepend: function prepend ( str ) {
  4770. this.intro = str + this.intro;
  4771. return this;
  4772. },
  4773. toString: function toString () {
  4774. var this$1 = this;
  4775. var body = this.sources.map( function ( source, i ) {
  4776. var separator = source.separator !== undefined ? source.separator : this$1.separator;
  4777. var str = ( i > 0 ? separator : '' ) + source.content.toString();
  4778. return str;
  4779. }).join( '' );
  4780. return this.intro + body;
  4781. },
  4782. trimLines: function trimLines () {
  4783. return this.trim('[\\r\\n]');
  4784. },
  4785. trim: function trim ( charType ) {
  4786. return this.trimStart( charType ).trimEnd( charType );
  4787. },
  4788. trimStart: function trimStart ( charType ) {
  4789. var this$1 = this;
  4790. var rx = new RegExp( '^' + ( charType || '\\s' ) + '+' );
  4791. this.intro = this.intro.replace( rx, '' );
  4792. if ( !this.intro ) {
  4793. var source;
  4794. var i = 0;
  4795. do {
  4796. source = this$1.sources[i];
  4797. if ( !source ) {
  4798. break;
  4799. }
  4800. source.content.trimStart( charType );
  4801. i += 1;
  4802. } while ( source.content.toString() === '' ); // TODO faster way to determine non-empty source?
  4803. }
  4804. return this;
  4805. },
  4806. trimEnd: function trimEnd ( charType ) {
  4807. var this$1 = this;
  4808. var rx = new RegExp( ( charType || '\\s' ) + '+$' );
  4809. var source;
  4810. var i = this.sources.length - 1;
  4811. do {
  4812. source = this$1.sources[i];
  4813. if ( !source ) {
  4814. this$1.intro = this$1.intro.replace( rx, '' );
  4815. break;
  4816. }
  4817. source.content.trimEnd( charType );
  4818. i -= 1;
  4819. } while ( source.content.toString() === '' ); // TODO faster way to determine non-empty source?
  4820. return this;
  4821. }
  4822. };
  4823. function getSemis ( str ) {
  4824. return new Array( str.split( '\n' ).length ).join( ';' );
  4825. }
  4826. MagicString.Bundle = Bundle;
  4827. var magicString_cjs = MagicString;
  4828. var keys = {
  4829. Program: [ 'body' ],
  4830. Literal: []
  4831. };
  4832. // used for debugging, without the noise created by
  4833. // circular references
  4834. function toJSON ( node ) {
  4835. var obj = {};
  4836. Object.keys( node ).forEach( function ( key ) {
  4837. if ( key === 'parent' || key === 'program' || key === 'keys' || key === '__wrapped' ) return;
  4838. if ( Array.isArray( node[ key ] ) ) {
  4839. obj[ key ] = node[ key ].map( toJSON );
  4840. } else if ( node[ key ] && node[ key ].toJSON ) {
  4841. obj[ key ] = node[ key ].toJSON();
  4842. } else {
  4843. obj[ key ] = node[ key ];
  4844. }
  4845. });
  4846. return obj;
  4847. }
  4848. var Node$1 = function Node ( raw, parent ) {
  4849. raw.parent = parent;
  4850. raw.program = parent.program || parent;
  4851. raw.depth = parent.depth + 1;
  4852. raw.keys = keys[ raw.type ];
  4853. raw.indentation = undefined;
  4854. for ( var i = 0, list = keys[ raw.type ]; i < list.length; i += 1 ) {
  4855. var key = list[i];
  4856. wrap( raw[ key ], raw );
  4857. }
  4858. raw.program.magicString.addSourcemapLocation( raw.start );
  4859. raw.program.magicString.addSourcemapLocation( raw.end );
  4860. };
  4861. Node$1.prototype.ancestor = function ancestor ( level ) {
  4862. var node = this;
  4863. while ( level-- ) {
  4864. node = node.parent;
  4865. if ( !node ) return null;
  4866. }
  4867. return node;
  4868. };
  4869. Node$1.prototype.contains = function contains ( node ) {
  4870. var this$1 = this;
  4871. while ( node ) {
  4872. if ( node === this$1 ) return true;
  4873. node = node.parent;
  4874. }
  4875. return false;
  4876. };
  4877. Node$1.prototype.findLexicalBoundary = function findLexicalBoundary () {
  4878. return this.parent.findLexicalBoundary();
  4879. };
  4880. Node$1.prototype.findNearest = function findNearest ( type ) {
  4881. if ( typeof type === 'string' ) type = new RegExp( ("^" + type + "$") );
  4882. if ( type.test( this.type ) ) return this;
  4883. return this.parent.findNearest( type );
  4884. };
  4885. Node$1.prototype.unparenthesizedParent = function unparenthesizedParent () {
  4886. var node = this.parent;
  4887. while ( node && node.type === 'ParenthesizedExpression' ) {
  4888. node = node.parent;
  4889. }
  4890. return node;
  4891. };
  4892. Node$1.prototype.unparenthesize = function unparenthesize () {
  4893. var node = this;
  4894. while ( node.type === 'ParenthesizedExpression' ) {
  4895. node = node.expression;
  4896. }
  4897. return node;
  4898. };
  4899. Node$1.prototype.findScope = function findScope ( functionScope ) {
  4900. return this.parent.findScope( functionScope );
  4901. };
  4902. Node$1.prototype.getIndentation = function getIndentation () {
  4903. return this.parent.getIndentation();
  4904. };
  4905. Node$1.prototype.initialise = function initialise ( transforms ) {
  4906. for ( var i = 0, list = this.keys; i < list.length; i += 1 ) {
  4907. var key = list[i];
  4908. var value = this[ key ];
  4909. if ( Array.isArray( value ) ) {
  4910. value.forEach( function ( node ) { return node && node.initialise( transforms ); } );
  4911. } else if ( value && typeof value === 'object' ) {
  4912. value.initialise( transforms );
  4913. }
  4914. }
  4915. };
  4916. Node$1.prototype.toJSON = function toJSON$1 () {
  4917. return toJSON( this );
  4918. };
  4919. Node$1.prototype.toString = function toString () {
  4920. return this.program.magicString.original.slice( this.start, this.end );
  4921. };
  4922. Node$1.prototype.transpile = function transpile ( code, transforms ) {
  4923. for ( var i = 0, list = this.keys; i < list.length; i += 1 ) {
  4924. var key = list[i];
  4925. var value = this[ key ];
  4926. if ( Array.isArray( value ) ) {
  4927. value.forEach( function ( node ) { return node && node.transpile( code, transforms ); } );
  4928. } else if ( value && typeof value === 'object' ) {
  4929. value.transpile( code, transforms );
  4930. }
  4931. }
  4932. };
  4933. function isArguments ( node ) {
  4934. return node.type === 'Identifier' && node.name === 'arguments';
  4935. }
  4936. function spread ( code, elements, start, argumentsArrayAlias, isNew ) {
  4937. var i = elements.length;
  4938. var firstSpreadIndex = -1;
  4939. while ( i-- ) {
  4940. var element$1 = elements[i];
  4941. if ( element$1 && element$1.type === 'SpreadElement' ) {
  4942. if ( isArguments( element$1.argument ) ) {
  4943. code.overwrite( element$1.argument.start, element$1.argument.end, argumentsArrayAlias );
  4944. }
  4945. firstSpreadIndex = i;
  4946. }
  4947. }
  4948. if ( firstSpreadIndex === -1 ) return false; // false indicates no spread elements
  4949. if (isNew) {
  4950. for ( i = 0; i < elements.length; i += 1 ) {
  4951. var element$2 = elements[i];
  4952. if ( element$2.type === 'SpreadElement' ) {
  4953. code.remove( element$2.start, element$2.argument.start );
  4954. } else {
  4955. code.insertRight( element$2.start, '[' );
  4956. code.insertRight( element$2.end, ']' );
  4957. }
  4958. }
  4959. return true; // true indicates some spread elements
  4960. }
  4961. var element = elements[ firstSpreadIndex ];
  4962. var previousElement = elements[ firstSpreadIndex - 1 ];
  4963. if ( !previousElement ) {
  4964. code.remove( start, element.start );
  4965. code.overwrite( element.end, elements[1].start, '.concat( ' );
  4966. } else {
  4967. code.overwrite( previousElement.end, element.start, ' ].concat( ' );
  4968. }
  4969. for ( i = firstSpreadIndex; i < elements.length; i += 1 ) {
  4970. element = elements[i];
  4971. if ( element ) {
  4972. if ( element.type === 'SpreadElement' ) {
  4973. code.remove( element.start, element.argument.start );
  4974. } else {
  4975. code.insertLeft( element.start, '[' );
  4976. code.insertLeft( element.end, ']' );
  4977. }
  4978. }
  4979. }
  4980. return true; // true indicates some spread elements
  4981. }
  4982. var ArrayExpression = (function (Node) {
  4983. function ArrayExpression () {
  4984. Node.apply(this, arguments);
  4985. }
  4986. if ( Node ) ArrayExpression.__proto__ = Node;
  4987. ArrayExpression.prototype = Object.create( Node && Node.prototype );
  4988. ArrayExpression.prototype.constructor = ArrayExpression;
  4989. ArrayExpression.prototype.initialise = function initialise ( transforms ) {
  4990. var this$1 = this;
  4991. if ( transforms.spreadRest && this.elements.length ) {
  4992. var lexicalBoundary = this.findLexicalBoundary();
  4993. var i = this.elements.length;
  4994. while ( i-- ) {
  4995. var element = this$1.elements[i];
  4996. if ( element && element.type === 'SpreadElement' && isArguments( element.argument ) ) {
  4997. this$1.argumentsArrayAlias = lexicalBoundary.getArgumentsArrayAlias();
  4998. }
  4999. }
  5000. }
  5001. Node.prototype.initialise.call( this, transforms );
  5002. };
  5003. ArrayExpression.prototype.transpile = function transpile ( code, transforms ) {
  5004. if ( transforms.spreadRest ) {
  5005. // erase trailing comma after last array element if not an array hole
  5006. if ( this.elements.length ) {
  5007. var lastElement = this.elements[ this.elements.length - 1 ];
  5008. if ( lastElement && /\s*,/.test( code.original.slice( lastElement.end, this.end ) ) ) {
  5009. code.overwrite( lastElement.end, this.end - 1, ' ' );
  5010. }
  5011. }
  5012. if ( this.elements.length === 1 ) {
  5013. var element = this.elements[0];
  5014. if ( element && element.type === 'SpreadElement' ) {
  5015. // special case – [ ...arguments ]
  5016. if ( isArguments( element.argument ) ) {
  5017. code.overwrite( this.start, this.end, ("[].concat( " + (this.argumentsArrayAlias) + " )") ); // TODO if this is the only use of argsArray, don't bother concating
  5018. } else {
  5019. code.overwrite( this.start, element.argument.start, '[].concat( ' );
  5020. code.overwrite( element.end, this.end, ' )' );
  5021. }
  5022. }
  5023. }
  5024. else {
  5025. var hasSpreadElements = spread( code, this.elements, this.start, this.argumentsArrayAlias );
  5026. if ( hasSpreadElements ) {
  5027. code.overwrite( this.end - 1, this.end, ')' );
  5028. }
  5029. }
  5030. }
  5031. Node.prototype.transpile.call( this, code, transforms );
  5032. };
  5033. return ArrayExpression;
  5034. }(Node$1));
  5035. var ArrowFunctionExpression = (function (Node) {
  5036. function ArrowFunctionExpression () {
  5037. Node.apply(this, arguments);
  5038. }
  5039. if ( Node ) ArrowFunctionExpression.__proto__ = Node;
  5040. ArrowFunctionExpression.prototype = Object.create( Node && Node.prototype );
  5041. ArrowFunctionExpression.prototype.constructor = ArrowFunctionExpression;
  5042. ArrowFunctionExpression.prototype.initialise = function initialise ( transforms ) {
  5043. this.body.createScope();
  5044. Node.prototype.initialise.call( this, transforms );
  5045. };
  5046. ArrowFunctionExpression.prototype.transpile = function transpile ( code, transforms ) {
  5047. if ( transforms.arrow ) {
  5048. // remove arrow
  5049. var charIndex = this.body.start;
  5050. while ( code.original[ charIndex ] !== '=' ) {
  5051. charIndex -= 1;
  5052. }
  5053. code.remove( charIndex, this.body.start );
  5054. // wrap naked parameter
  5055. if ( this.params.length === 1 && this.start === this.params[0].start ) {
  5056. code.insertRight( this.params[0].start, '(' );
  5057. code.insertLeft( this.params[0].end, ')' );
  5058. }
  5059. // add function
  5060. if ( this.parent && this.parent.type === 'ExpressionStatement' ) {
  5061. // standalone expression statement
  5062. code.insertRight( this.start, '(function' );
  5063. code.insertRight( this.end, ')' );
  5064. } else {
  5065. code.insertRight( this.start, 'function ' );
  5066. }
  5067. }
  5068. Node.prototype.transpile.call( this, code, transforms );
  5069. };
  5070. return ArrowFunctionExpression;
  5071. }(Node$1));
  5072. function locate ( source, index ) {
  5073. var lines = source.split( '\n' );
  5074. var len = lines.length;
  5075. var lineStart = 0;
  5076. var i;
  5077. for ( i = 0; i < len; i += 1 ) {
  5078. var line = lines[i];
  5079. var lineEnd = lineStart + line.length + 1; // +1 for newline
  5080. if ( lineEnd > index ) {
  5081. return { line: i + 1, column: index - lineStart, char: i };
  5082. }
  5083. lineStart = lineEnd;
  5084. }
  5085. throw new Error( 'Could not determine location of character' );
  5086. }
  5087. function pad ( num, len ) {
  5088. var result = String( num );
  5089. return result + repeat( ' ', len - result.length );
  5090. }
  5091. function repeat ( str, times ) {
  5092. var result = '';
  5093. while ( times-- ) result += str;
  5094. return result;
  5095. }
  5096. function getSnippet ( source, loc, length ) {
  5097. if ( length === void 0 ) length = 1;
  5098. var first = Math.max( loc.line - 5, 0 );
  5099. var last = loc.line;
  5100. var numDigits = String( last ).length;
  5101. var lines = source.split( '\n' ).slice( first, last );
  5102. var lastLine = lines[ lines.length - 1 ];
  5103. var offset = lastLine.slice( 0, loc.column ).replace( /\t/g, ' ' ).length;
  5104. var snippet = lines
  5105. .map( function ( line, i ) { return ((pad( i + first + 1, numDigits )) + " : " + (line.replace( /\t/g, ' '))); } )
  5106. .join( '\n' );
  5107. snippet += '\n' + repeat( ' ', numDigits + 3 + offset ) + repeat( '^', length );
  5108. return snippet;
  5109. }
  5110. var CompileError = (function (Error) {
  5111. function CompileError ( node, message ) {
  5112. Error.call(this);
  5113. var source = node.program.magicString.original;
  5114. var loc = locate( source, node.start );
  5115. this.name = 'CompileError';
  5116. this.message = message + " (" + (loc.line) + ":" + (loc.column) + ")";
  5117. this.stack = new Error().stack.replace( new RegExp( (".+new " + (this.name) + ".+\\n"), 'm' ), '' );
  5118. this.loc = loc;
  5119. this.snippet = getSnippet( source, loc, node.end - node.start );
  5120. }
  5121. if ( Error ) CompileError.__proto__ = Error;
  5122. CompileError.prototype = Object.create( Error && Error.prototype );
  5123. CompileError.prototype.constructor = CompileError;
  5124. CompileError.prototype.toString = function toString () {
  5125. return ((this.name) + ": " + (this.message) + "\n" + (this.snippet));
  5126. };
  5127. return CompileError;
  5128. }(Error));
  5129. var AssignmentExpression = (function (Node) {
  5130. function AssignmentExpression () {
  5131. Node.apply(this, arguments);
  5132. }
  5133. if ( Node ) AssignmentExpression.__proto__ = Node;
  5134. AssignmentExpression.prototype = Object.create( Node && Node.prototype );
  5135. AssignmentExpression.prototype.constructor = AssignmentExpression;
  5136. AssignmentExpression.prototype.initialise = function initialise ( transforms ) {
  5137. if ( this.left.type === 'Identifier' ) {
  5138. var declaration = this.findScope( false ).findDeclaration( this.left.name );
  5139. if ( declaration && declaration.kind === 'const' ) {
  5140. throw new CompileError( this.left, ((this.left.name) + " is read-only") );
  5141. }
  5142. // special case – https://gitlab.com/Rich-Harris/buble/issues/11
  5143. var statement = declaration && declaration.node.ancestor( 3 );
  5144. if ( statement && statement.type === 'ForStatement' && statement.body.contains( this ) ) {
  5145. statement.reassigned[ this.left.name ] = true;
  5146. }
  5147. }
  5148. Node.prototype.initialise.call( this, transforms );
  5149. };
  5150. AssignmentExpression.prototype.transpile = function transpile ( code, transforms ) {
  5151. if ( this.operator === '**=' && transforms.exponentiation ) {
  5152. this.transpileExponentiation( code, transforms );
  5153. }
  5154. else if ( /Pattern/.test( this.left.type ) && transforms.destructuring ) {
  5155. this.transpileDestructuring( code, transforms );
  5156. }
  5157. Node.prototype.transpile.call( this, code, transforms );
  5158. };
  5159. AssignmentExpression.prototype.transpileDestructuring = function transpileDestructuring ( code ) {
  5160. var scope = this.findScope( true );
  5161. var assign = scope.createIdentifier( 'assign' );
  5162. var temporaries = [ assign ];
  5163. var start = this.start;
  5164. // We need to pick out some elements from the original code,
  5165. // interleaved with generated code. These helpers are used to
  5166. // easily do that while keeping the order of the output
  5167. // predictable.
  5168. var text = '';
  5169. function use ( node ) {
  5170. code.insertRight( node.start, text );
  5171. code.move( node.start, node.end, start );
  5172. text = '';
  5173. }
  5174. function write ( string ) {
  5175. text += string;
  5176. }
  5177. write( ("(" + assign + " = ") );
  5178. use( this.right );
  5179. // Walk `pattern`, generating code that assigns the value in
  5180. // `ref` to it. When `mayDuplicate` is false, the function
  5181. // must take care to only output `ref` once.
  5182. function destructure ( pattern, ref, mayDuplicate ) {
  5183. if ( pattern.type === 'Identifier' || pattern.type === 'MemberExpression' ) {
  5184. write( ', ' );
  5185. use( pattern );
  5186. write( (" = " + ref) );
  5187. }
  5188. else if ( pattern.type === 'AssignmentPattern' ) {
  5189. if ( pattern.left.type === 'Identifier' ) {
  5190. var target = pattern.left.name;
  5191. var source = ref;
  5192. if ( !mayDuplicate ) {
  5193. write( (", " + target + " = " + ref) );
  5194. source = target;
  5195. }
  5196. write( (", " + target + " = " + source + " === void 0 ? ") );
  5197. use( pattern.right );
  5198. write( (" : " + source) );
  5199. }
  5200. else {
  5201. var target$1 = scope.createIdentifier( 'temp' );
  5202. var source$1 = ref;
  5203. temporaries.push( target$1 );
  5204. if ( !mayDuplicate ) {
  5205. write( (", " + target$1 + " = " + ref) );
  5206. source$1 = target$1;
  5207. }
  5208. write( (", " + target$1 + " = " + source$1 + " === void 0 ? ") );
  5209. use( pattern.right );
  5210. write( (" : " + source$1) );
  5211. destructure( pattern.left, target$1, true );
  5212. }
  5213. }
  5214. else if ( pattern.type === 'ArrayPattern' ) {
  5215. var elements = pattern.elements;
  5216. if ( elements.length === 1 ) {
  5217. destructure( elements[0], (ref + "[0]"), false );
  5218. }
  5219. else {
  5220. if ( !mayDuplicate ) {
  5221. var temp = scope.createIdentifier( 'array' );
  5222. temporaries.push( temp );
  5223. write( (", " + temp + " = " + ref) );
  5224. ref = temp;
  5225. }
  5226. elements.forEach( function ( element, i ) {
  5227. if ( element ) {
  5228. if ( element.type === 'RestElement' ) {
  5229. destructure( element.argument, (ref + ".slice(" + i + ")"), false );
  5230. } else {
  5231. destructure( element, (ref + "[" + i + "]"), false );
  5232. }
  5233. }
  5234. } );
  5235. }
  5236. }
  5237. else if ( pattern.type === 'ObjectPattern' ) {
  5238. var props = pattern.properties;
  5239. if ( props.length == 1 ) {
  5240. var prop = props[0];
  5241. var value = prop.computed || prop.key.type !== 'Identifier' ? (ref + "[" + (code.slice(prop.key.start, prop.key.end)) + "]") : (ref + "." + (prop.key.name));
  5242. destructure( prop.value, value, false );
  5243. }
  5244. else {
  5245. if ( !mayDuplicate ) {
  5246. var temp$1 = scope.createIdentifier( 'obj' );
  5247. temporaries.push( temp$1 );
  5248. write( (", " + temp$1 + " = " + ref) );
  5249. ref = temp$1;
  5250. }
  5251. props.forEach( function ( prop ) {
  5252. var value = prop.computed || prop.key.type !== 'Identifier' ? (ref + "[" + (code.slice(prop.key.start, prop.key.end)) + "]") : (ref + "." + (prop.key.name));
  5253. destructure( prop.value, value, false );
  5254. } );
  5255. }
  5256. }
  5257. else {
  5258. throw new Error( ("Unexpected node type in destructuring assignment (" + (pattern.type) + ")") );
  5259. }
  5260. }
  5261. destructure( this.left, assign, true );
  5262. if ( this.unparenthesizedParent().type === 'ExpressionStatement' ) {
  5263. // no rvalue needed for expression statement
  5264. code.insertRight( start, (text + ")") );
  5265. } else {
  5266. // destructuring is part of an expression - need an rvalue
  5267. code.insertRight( start, (text + ", " + assign + ")") );
  5268. }
  5269. code.remove( start, this.right.start );
  5270. var statement = this.findNearest( /(?:Statement|Declaration)$/ );
  5271. code.insertLeft( statement.start, ("var " + (temporaries.join( ', ' )) + ";\n" + (statement.getIndentation())) );
  5272. };
  5273. AssignmentExpression.prototype.transpileExponentiation = function transpileExponentiation ( code ) {
  5274. var scope = this.findScope( false );
  5275. var getAlias = function ( name ) {
  5276. var declaration = scope.findDeclaration( name );
  5277. return declaration ? declaration.name : name;
  5278. };
  5279. // first, the easy part – `**=` -> `=`
  5280. var charIndex = this.left.end;
  5281. while ( code.original[ charIndex ] !== '*' ) charIndex += 1;
  5282. code.remove( charIndex, charIndex + 2 );
  5283. // how we do the next part depends on a number of factors – whether
  5284. // this is a top-level statement, and whether we're updating a
  5285. // simple or complex reference
  5286. var base;
  5287. var left = this.left.unparenthesize();
  5288. if ( left.type === 'Identifier' ) {
  5289. base = getAlias( left.name );
  5290. } else if ( left.type === 'MemberExpression' ) {
  5291. var object;
  5292. var needsObjectVar = false;
  5293. var property;
  5294. var needsPropertyVar = false;
  5295. var statement = this.findNearest( /(?:Statement|Declaration)$/ );
  5296. var i0 = statement.getIndentation();
  5297. if ( left.property.type === 'Identifier' ) {
  5298. property = left.computed ? getAlias( left.property.name ) : left.property.name;
  5299. } else {
  5300. property = scope.createIdentifier( 'property' );
  5301. needsPropertyVar = true;
  5302. }
  5303. if ( left.object.type === 'Identifier' ) {
  5304. object = getAlias( left.object.name );
  5305. } else {
  5306. object = scope.createIdentifier( 'object' );
  5307. needsObjectVar = true;
  5308. }
  5309. if ( left.start === statement.start ) {
  5310. if ( needsObjectVar && needsPropertyVar ) {
  5311. code.insertRight( statement.start, ("var " + object + " = ") );
  5312. code.overwrite( left.object.end, left.property.start, (";\n" + i0 + "var " + property + " = ") );
  5313. code.overwrite( left.property.end, left.end, (";\n" + i0 + object + "[" + property + "]") );
  5314. }
  5315. else if ( needsObjectVar ) {
  5316. code.insertRight( statement.start, ("var " + object + " = ") );
  5317. code.insertLeft( left.object.end, (";\n" + i0) );
  5318. code.insertLeft( left.object.end, object );
  5319. }
  5320. else if ( needsPropertyVar ) {
  5321. code.insertRight( left.property.start, ("var " + property + " = ") );
  5322. code.insertLeft( left.property.end, (";\n" + i0) );
  5323. code.move( left.property.start, left.property.end, this.start );
  5324. code.insertLeft( left.object.end, ("[" + property + "]") );
  5325. code.remove( left.object.end, left.property.start );
  5326. code.remove( left.property.end, left.end );
  5327. }
  5328. }
  5329. else {
  5330. var declarators = [];
  5331. if ( needsObjectVar ) declarators.push( object );
  5332. if ( needsPropertyVar ) declarators.push( property );
  5333. if ( declarators.length ) {
  5334. code.insertRight( statement.start, ("var " + (declarators.join( ', ' )) + ";\n" + i0) );
  5335. }
  5336. if ( needsObjectVar && needsPropertyVar ) {
  5337. code.insertRight( left.start, ("( " + object + " = ") );
  5338. code.overwrite( left.object.end, left.property.start, (", " + property + " = ") );
  5339. code.overwrite( left.property.end, left.end, (", " + object + "[" + property + "]") );
  5340. }
  5341. else if ( needsObjectVar ) {
  5342. code.insertRight( left.start, ("( " + object + " = ") );
  5343. code.insertLeft( left.object.end, (", " + object) );
  5344. }
  5345. else if ( needsPropertyVar ) {
  5346. code.insertRight( left.property.start, ("( " + property + " = ") );
  5347. code.insertLeft( left.property.end, ", " );
  5348. code.move( left.property.start, left.property.end, left.start );
  5349. code.overwrite( left.object.end, left.property.start, ("[" + property + "]") );
  5350. code.remove( left.property.end, left.end );
  5351. }
  5352. if ( needsPropertyVar ) {
  5353. code.insertLeft( this.end, " )" );
  5354. }
  5355. }
  5356. base = object + ( left.computed || needsPropertyVar ? ("[" + property + "]") : ("." + property) );
  5357. }
  5358. code.insertRight( this.right.start, ("Math.pow( " + base + ", ") );
  5359. code.insertLeft( this.right.end, " )" );
  5360. };
  5361. return AssignmentExpression;
  5362. }(Node$1));
  5363. var BinaryExpression = (function (Node) {
  5364. function BinaryExpression () {
  5365. Node.apply(this, arguments);
  5366. }
  5367. if ( Node ) BinaryExpression.__proto__ = Node;
  5368. BinaryExpression.prototype = Object.create( Node && Node.prototype );
  5369. BinaryExpression.prototype.constructor = BinaryExpression;
  5370. BinaryExpression.prototype.transpile = function transpile ( code, transforms ) {
  5371. if ( this.operator === '**' && transforms.exponentiation ) {
  5372. code.insertRight( this.start, "Math.pow( " );
  5373. code.overwrite( this.left.end, this.right.start, ", " );
  5374. code.insertLeft( this.end, " )" );
  5375. }
  5376. Node.prototype.transpile.call( this, code, transforms );
  5377. };
  5378. return BinaryExpression;
  5379. }(Node$1));
  5380. var loopStatement = /(?:For(?:In|Of)?|While)Statement/;
  5381. var BreakStatement = (function (Node) {
  5382. function BreakStatement () {
  5383. Node.apply(this, arguments);
  5384. }
  5385. if ( Node ) BreakStatement.__proto__ = Node;
  5386. BreakStatement.prototype = Object.create( Node && Node.prototype );
  5387. BreakStatement.prototype.constructor = BreakStatement;
  5388. BreakStatement.prototype.initialise = function initialise () {
  5389. var loop = this.findNearest( loopStatement );
  5390. var switchCase = this.findNearest( 'SwitchCase' );
  5391. if ( loop && ( !switchCase || loop.depth > switchCase.depth ) ) {
  5392. loop.canBreak = true;
  5393. this.loop = loop;
  5394. }
  5395. };
  5396. BreakStatement.prototype.transpile = function transpile ( code ) {
  5397. if ( this.loop && this.loop.shouldRewriteAsFunction ) {
  5398. if ( this.label ) throw new CompileError( this, 'Labels are not currently supported in a loop with locally-scoped variables' );
  5399. code.overwrite( this.start, this.start + 5, "return 'break'" );
  5400. }
  5401. };
  5402. return BreakStatement;
  5403. }(Node$1));
  5404. var CallExpression = (function (Node) {
  5405. function CallExpression () {
  5406. Node.apply(this, arguments);
  5407. }
  5408. if ( Node ) CallExpression.__proto__ = Node;
  5409. CallExpression.prototype = Object.create( Node && Node.prototype );
  5410. CallExpression.prototype.constructor = CallExpression;
  5411. CallExpression.prototype.initialise = function initialise ( transforms ) {
  5412. var this$1 = this;
  5413. if ( transforms.spreadRest && this.arguments.length > 1 ) {
  5414. var lexicalBoundary = this.findLexicalBoundary();
  5415. var i = this.arguments.length;
  5416. while ( i-- ) {
  5417. var arg = this$1.arguments[i];
  5418. if ( arg.type === 'SpreadElement' && isArguments( arg.argument ) ) {
  5419. this$1.argumentsArrayAlias = lexicalBoundary.getArgumentsArrayAlias();
  5420. }
  5421. }
  5422. }
  5423. Node.prototype.initialise.call( this, transforms );
  5424. };
  5425. CallExpression.prototype.transpile = function transpile ( code, transforms ) {
  5426. if ( transforms.spreadRest && this.arguments.length ) {
  5427. var hasSpreadElements = false;
  5428. var context;
  5429. var firstArgument = this.arguments[0];
  5430. if ( this.arguments.length === 1 ) {
  5431. if ( firstArgument.type === 'SpreadElement' ) {
  5432. code.remove( firstArgument.start, firstArgument.argument.start );
  5433. hasSpreadElements = true;
  5434. }
  5435. } else {
  5436. hasSpreadElements = spread( code, this.arguments, firstArgument.start, this.argumentsArrayAlias );
  5437. }
  5438. if ( hasSpreadElements ) {
  5439. // we need to handle super() and super.method() differently
  5440. // due to its instance
  5441. var _super = null;
  5442. if ( this.callee.type === 'Super' ) {
  5443. _super = this.callee;
  5444. }
  5445. else if ( this.callee.type === 'MemberExpression' && this.callee.object.type === 'Super' ) {
  5446. _super = this.callee.object;
  5447. }
  5448. if ( !_super && this.callee.type === 'MemberExpression' ) {
  5449. if ( this.callee.object.type === 'Identifier' ) {
  5450. context = this.callee.object.name;
  5451. } else {
  5452. context = this.findScope( true ).createIdentifier( 'ref' );
  5453. var callExpression = this.callee.object;
  5454. var enclosure = callExpression.findNearest( /Function/ );
  5455. var block = enclosure ? enclosure.body.body
  5456. : callExpression.findNearest( /^Program$/ ).body;
  5457. var lastStatementInBlock = block[ block.length - 1 ];
  5458. var i0 = lastStatementInBlock.getIndentation();
  5459. code.insertRight( callExpression.start, ("(" + context + " = ") );
  5460. code.insertLeft( callExpression.end, ")" );
  5461. code.insertLeft( lastStatementInBlock.end, ("\n" + i0 + "var " + context + ";") );
  5462. }
  5463. } else {
  5464. context = 'void 0';
  5465. }
  5466. code.insertLeft( this.callee.end, '.apply' );
  5467. if ( _super ) {
  5468. _super.noCall = true; // bit hacky...
  5469. if ( this.arguments.length > 1 ) {
  5470. if ( firstArgument.type !== 'SpreadElement' ) {
  5471. code.insertRight( firstArgument.start, "[ " );
  5472. }
  5473. code.insertLeft( this.arguments[ this.arguments.length - 1 ].end, ' )' );
  5474. }
  5475. }
  5476. else if ( this.arguments.length === 1 ) {
  5477. code.insertRight( firstArgument.start, (context + ", ") );
  5478. } else {
  5479. if ( firstArgument.type === 'SpreadElement' ) {
  5480. code.insertLeft( firstArgument.start, (context + ", ") );
  5481. } else {
  5482. code.insertLeft( firstArgument.start, (context + ", [ ") );
  5483. }
  5484. code.insertLeft( this.arguments[ this.arguments.length - 1 ].end, ' )' );
  5485. }
  5486. }
  5487. }
  5488. Node.prototype.transpile.call( this, code, transforms );
  5489. };
  5490. return CallExpression;
  5491. }(Node$1));
  5492. function findIndex ( array, fn ) {
  5493. for ( var i = 0; i < array.length; i += 1 ) {
  5494. if ( fn( array[i], i ) ) return i;
  5495. }
  5496. return -1;
  5497. }
  5498. var reserved = Object.create( null );
  5499. 'do if in for let new try var case else enum eval null this true void with await break catch class const false super throw while yield delete export import public return static switch typeof default extends finally package private continue debugger function arguments interface protected implements instanceof'.split( ' ' )
  5500. .forEach( function ( word ) { return reserved[ word ] = true; } );
  5501. // TODO this code is pretty wild, tidy it up
  5502. var ClassBody = (function (Node) {
  5503. function ClassBody () {
  5504. Node.apply(this, arguments);
  5505. }
  5506. if ( Node ) ClassBody.__proto__ = Node;
  5507. ClassBody.prototype = Object.create( Node && Node.prototype );
  5508. ClassBody.prototype.constructor = ClassBody;
  5509. ClassBody.prototype.transpile = function transpile ( code, transforms, inFunctionExpression, superName ) {
  5510. var this$1 = this;
  5511. if ( transforms.classes ) {
  5512. var name = this.parent.name;
  5513. var indentStr = code.getIndentString();
  5514. var i0 = this.getIndentation() + ( inFunctionExpression ? indentStr : '' );
  5515. var i1 = i0 + indentStr;
  5516. var constructorIndex = findIndex( this.body, function ( node ) { return node.kind === 'constructor'; } );
  5517. var constructor = this.body[ constructorIndex ];
  5518. var introBlock = '';
  5519. var outroBlock = '';
  5520. if ( this.body.length ) {
  5521. code.remove( this.start, this.body[0].start );
  5522. code.remove( this.body[ this.body.length - 1 ].end, this.end );
  5523. } else {
  5524. code.remove( this.start, this.end );
  5525. }
  5526. if ( constructor ) {
  5527. constructor.value.body.isConstructorBody = true;
  5528. var previousMethod = this.body[ constructorIndex - 1 ];
  5529. var nextMethod = this.body[ constructorIndex + 1 ];
  5530. // ensure constructor is first
  5531. if ( constructorIndex > 0 ) {
  5532. code.remove( previousMethod.end, constructor.start );
  5533. code.move( constructor.start, nextMethod ? nextMethod.start : this.end - 1, this.body[0].start );
  5534. }
  5535. if ( !inFunctionExpression ) code.insertLeft( constructor.end, ';' );
  5536. }
  5537. var namedFunctions = this.program.options.namedFunctionExpressions !== false;
  5538. var namedConstructor = namedFunctions || this.parent.superClass || this.parent.type !== 'ClassDeclaration';
  5539. if ( this.parent.superClass ) {
  5540. var inheritanceBlock = "if ( " + superName + " ) " + name + ".__proto__ = " + superName + ";\n" + i0 + name + ".prototype = Object.create( " + superName + " && " + superName + ".prototype );\n" + i0 + name + ".prototype.constructor = " + name + ";";
  5541. if ( constructor ) {
  5542. introBlock += "\n\n" + i0 + inheritanceBlock;
  5543. } else {
  5544. var fn = "function " + name + " () {" + ( superName ?
  5545. ("\n" + i1 + superName + ".apply(this, arguments);\n" + i0 + "}") :
  5546. "}" ) + ( inFunctionExpression ? '' : ';' ) + ( this.body.length ? ("\n\n" + i0) : '' );
  5547. inheritanceBlock = fn + inheritanceBlock;
  5548. introBlock += inheritanceBlock + "\n\n" + i0;
  5549. }
  5550. } else if ( !constructor ) {
  5551. var fn$1 = 'function ' + (namedConstructor ? name + ' ' : '') + '() {}';
  5552. if ( this.parent.type === 'ClassDeclaration' ) fn$1 += ';';
  5553. if ( this.body.length ) fn$1 += "\n\n" + i0;
  5554. introBlock += fn$1;
  5555. }
  5556. var scope = this.findScope( false );
  5557. var prototypeGettersAndSetters = [];
  5558. var staticGettersAndSetters = [];
  5559. var prototypeAccessors;
  5560. var staticAccessors;
  5561. this.body.forEach( function ( method, i ) {
  5562. if ( method.kind === 'constructor' ) {
  5563. var constructorName = namedConstructor ? ' ' + name : '';
  5564. code.overwrite( method.key.start, method.key.end, ("function" + constructorName) );
  5565. return;
  5566. }
  5567. if ( method.static ) {
  5568. var len = code.original[ method.start + 6 ] == ' ' ? 7 : 6;
  5569. code.remove( method.start, method.start + len );
  5570. }
  5571. var isAccessor = method.kind !== 'method';
  5572. var lhs;
  5573. var methodName = method.key.name;
  5574. if ( reserved[ methodName ] || method.value.body.scope.references[methodName] ) {
  5575. methodName = scope.createIdentifier( methodName );
  5576. }
  5577. // when method name is a string or a number let's pretend it's a computed method
  5578. var fake_computed = false;
  5579. if ( ! method.computed && method.key.type === 'Literal' ) {
  5580. fake_computed = true;
  5581. method.computed = true;
  5582. }
  5583. if ( isAccessor ) {
  5584. if ( method.computed ) {
  5585. throw new Error( 'Computed accessor properties are not currently supported' );
  5586. }
  5587. code.remove( method.start, method.key.start );
  5588. if ( method.static ) {
  5589. if ( !~staticGettersAndSetters.indexOf( method.key.name ) ) staticGettersAndSetters.push( method.key.name );
  5590. if ( !staticAccessors ) staticAccessors = scope.createIdentifier( 'staticAccessors' );
  5591. lhs = "" + staticAccessors;
  5592. } else {
  5593. if ( !~prototypeGettersAndSetters.indexOf( method.key.name ) ) prototypeGettersAndSetters.push( method.key.name );
  5594. if ( !prototypeAccessors ) prototypeAccessors = scope.createIdentifier( 'prototypeAccessors' );
  5595. lhs = "" + prototypeAccessors;
  5596. }
  5597. } else {
  5598. lhs = method.static ?
  5599. ("" + name) :
  5600. (name + ".prototype");
  5601. }
  5602. if ( !method.computed ) lhs += '.';
  5603. var insertNewlines = ( constructorIndex > 0 && i === constructorIndex + 1 ) ||
  5604. ( i === 0 && constructorIndex === this$1.body.length - 1 );
  5605. if ( insertNewlines ) lhs = "\n\n" + i0 + lhs;
  5606. var c = method.key.end;
  5607. if ( method.computed ) {
  5608. if ( fake_computed ) {
  5609. code.insertRight( method.key.start, '[' );
  5610. code.insertLeft( method.key.end, ']' );
  5611. } else {
  5612. while ( code.original[c] !== ']' ) c += 1;
  5613. c += 1;
  5614. }
  5615. }
  5616. code.insertRight( method.start, lhs );
  5617. var funcName = method.computed || isAccessor || !namedFunctions ? '' : (methodName + " ");
  5618. var rhs = ( isAccessor ? ("." + (method.kind)) : '' ) + " = function" + ( method.value.generator ? '* ' : ' ' ) + funcName;
  5619. code.remove( c, method.value.start );
  5620. code.insertRight( method.value.start, rhs );
  5621. code.insertLeft( method.end, ';' );
  5622. if ( method.value.generator ) code.remove( method.start, method.key.start );
  5623. });
  5624. if ( prototypeGettersAndSetters.length || staticGettersAndSetters.length ) {
  5625. var intro = [];
  5626. var outro = [];
  5627. if ( prototypeGettersAndSetters.length ) {
  5628. intro.push( ("var " + prototypeAccessors + " = { " + (prototypeGettersAndSetters.map( function ( name ) { return (name + ": { configurable: true }"); } ).join( ',' )) + " };") );
  5629. outro.push( ("Object.defineProperties( " + name + ".prototype, " + prototypeAccessors + " );") );
  5630. }
  5631. if ( staticGettersAndSetters.length ) {
  5632. intro.push( ("var " + staticAccessors + " = { " + (staticGettersAndSetters.map( function ( name ) { return (name + ": { configurable: true }"); } ).join( ',' )) + " };") );
  5633. outro.push( ("Object.defineProperties( " + name + ", " + staticAccessors + " );") );
  5634. }
  5635. if ( constructor ) introBlock += "\n\n" + i0;
  5636. introBlock += intro.join( ("\n" + i0) );
  5637. if ( !constructor ) introBlock += "\n\n" + i0;
  5638. outroBlock += "\n\n" + i0 + outro.join( ("\n" + i0) );
  5639. }
  5640. if ( constructor ) {
  5641. code.insertLeft( constructor.end, introBlock );
  5642. } else {
  5643. code.insertRight( this.start, introBlock );
  5644. }
  5645. code.insertLeft( this.end, outroBlock );
  5646. }
  5647. Node.prototype.transpile.call( this, code, transforms );
  5648. };
  5649. return ClassBody;
  5650. }(Node$1));
  5651. // TODO this function is slightly flawed – it works on the original string,
  5652. // not its current edited state.
  5653. // That's not a problem for the way that it's currently used, but it could
  5654. // be in future...
  5655. function deindent ( node, code ) {
  5656. var start = node.start;
  5657. var end = node.end;
  5658. var indentStr = code.getIndentString();
  5659. var indentStrLen = indentStr.length;
  5660. var indentStart = start - indentStrLen;
  5661. if ( !node.program.indentExclusions[ indentStart ]
  5662. && code.original.slice( indentStart, start ) === indentStr ) {
  5663. code.remove( indentStart, start );
  5664. }
  5665. var pattern = new RegExp( indentStr + '\\S', 'g' );
  5666. var slice = code.original.slice( start, end );
  5667. var match;
  5668. while ( match = pattern.exec( slice ) ) {
  5669. var removeStart = start + match.index;
  5670. if ( !node.program.indentExclusions[ removeStart ] ) {
  5671. code.remove( removeStart, removeStart + indentStrLen );
  5672. }
  5673. }
  5674. }
  5675. var ClassDeclaration = (function (Node) {
  5676. function ClassDeclaration () {
  5677. Node.apply(this, arguments);
  5678. }
  5679. if ( Node ) ClassDeclaration.__proto__ = Node;
  5680. ClassDeclaration.prototype = Object.create( Node && Node.prototype );
  5681. ClassDeclaration.prototype.constructor = ClassDeclaration;
  5682. ClassDeclaration.prototype.initialise = function initialise ( transforms ) {
  5683. this.name = this.id.name;
  5684. this.findScope( true ).addDeclaration( this.id, 'class' );
  5685. Node.prototype.initialise.call( this, transforms );
  5686. };
  5687. ClassDeclaration.prototype.transpile = function transpile ( code, transforms ) {
  5688. if ( transforms.classes ) {
  5689. if ( !this.superClass ) deindent( this.body, code );
  5690. var superName = this.superClass && ( this.superClass.name || 'superclass' );
  5691. var i0 = this.getIndentation();
  5692. var i1 = i0 + code.getIndentString();
  5693. // if this is an export default statement, we have to move the export to
  5694. // after the declaration, because `export default var Foo = ...` is illegal
  5695. var syntheticDefaultExport = this.parent.type === 'ExportDefaultDeclaration' ?
  5696. ("\n\n" + i0 + "export default " + (this.id.name) + ";") :
  5697. '';
  5698. if ( syntheticDefaultExport ) code.remove( this.parent.start, this.start );
  5699. code.overwrite( this.start, this.id.start, 'var ' );
  5700. if ( this.superClass ) {
  5701. if ( this.superClass.end === this.body.start ) {
  5702. code.remove( this.id.end, this.superClass.start );
  5703. code.insertLeft( this.id.end, (" = (function (" + superName + ") {\n" + i1) );
  5704. } else {
  5705. code.overwrite( this.id.end, this.superClass.start, ' = ' );
  5706. code.overwrite( this.superClass.end, this.body.start, ("(function (" + superName + ") {\n" + i1) );
  5707. }
  5708. } else {
  5709. if ( this.id.end === this.body.start ) {
  5710. code.insertLeft( this.id.end, ' = ' );
  5711. } else {
  5712. code.overwrite( this.id.end, this.body.start, ' = ' );
  5713. }
  5714. }
  5715. this.body.transpile( code, transforms, !!this.superClass, superName );
  5716. if ( this.superClass ) {
  5717. code.insertLeft( this.end, ("\n\n" + i1 + "return " + (this.name) + ";\n" + i0 + "}(") );
  5718. code.move( this.superClass.start, this.superClass.end, this.end );
  5719. code.insertRight( this.end, ("));" + syntheticDefaultExport) );
  5720. } else if ( syntheticDefaultExport ) {
  5721. code.insertRight( this.end, syntheticDefaultExport );
  5722. }
  5723. }
  5724. else {
  5725. this.body.transpile( code, transforms, false, null );
  5726. }
  5727. };
  5728. return ClassDeclaration;
  5729. }(Node$1));
  5730. var ClassExpression = (function (Node) {
  5731. function ClassExpression () {
  5732. Node.apply(this, arguments);
  5733. }
  5734. if ( Node ) ClassExpression.__proto__ = Node;
  5735. ClassExpression.prototype = Object.create( Node && Node.prototype );
  5736. ClassExpression.prototype.constructor = ClassExpression;
  5737. ClassExpression.prototype.initialise = function initialise ( transforms ) {
  5738. this.name = this.id ? this.id.name :
  5739. this.parent.type === 'VariableDeclarator' ? this.parent.id.name :
  5740. this.parent.type === 'AssignmentExpression' ? this.parent.left.name :
  5741. this.findScope( true ).createIdentifier( 'anonymous' );
  5742. Node.prototype.initialise.call( this, transforms );
  5743. };
  5744. ClassExpression.prototype.transpile = function transpile ( code, transforms ) {
  5745. if ( transforms.classes ) {
  5746. var superName = this.superClass && ( this.superClass.name || 'superclass' );
  5747. var i0 = this.getIndentation();
  5748. var i1 = i0 + code.getIndentString();
  5749. if ( this.superClass ) {
  5750. code.remove( this.start, this.superClass.start );
  5751. code.remove( this.superClass.end, this.body.start );
  5752. code.insertLeft( this.start, ("(function (" + superName + ") {\n" + i1) );
  5753. } else {
  5754. code.overwrite( this.start, this.body.start, ("(function () {\n" + i1) );
  5755. }
  5756. this.body.transpile( code, transforms, true, superName );
  5757. var outro = "\n\n" + i1 + "return " + (this.name) + ";\n" + i0 + "}(";
  5758. if ( this.superClass ) {
  5759. code.insertLeft( this.end, outro );
  5760. code.move( this.superClass.start, this.superClass.end, this.end );
  5761. code.insertRight( this.end, '))' );
  5762. } else {
  5763. code.insertLeft( this.end, ("\n\n" + i1 + "return " + (this.name) + ";\n" + i0 + "}())") );
  5764. }
  5765. }
  5766. else {
  5767. this.body.transpile( code, transforms, false );
  5768. }
  5769. };
  5770. return ClassExpression;
  5771. }(Node$1));
  5772. var ContinueStatement = (function (Node) {
  5773. function ContinueStatement () {
  5774. Node.apply(this, arguments);
  5775. }
  5776. if ( Node ) ContinueStatement.__proto__ = Node;
  5777. ContinueStatement.prototype = Object.create( Node && Node.prototype );
  5778. ContinueStatement.prototype.constructor = ContinueStatement;
  5779. ContinueStatement.prototype.transpile = function transpile ( code ) {
  5780. var loop = this.findNearest( loopStatement );
  5781. if ( loop.shouldRewriteAsFunction ) {
  5782. if ( this.label ) throw new CompileError( this, 'Labels are not currently supported in a loop with locally-scoped variables' );
  5783. code.overwrite( this.start, this.start + 8, 'return' );
  5784. }
  5785. };
  5786. return ContinueStatement;
  5787. }(Node$1));
  5788. var ExportDefaultDeclaration = (function (Node) {
  5789. function ExportDefaultDeclaration () {
  5790. Node.apply(this, arguments);
  5791. }
  5792. if ( Node ) ExportDefaultDeclaration.__proto__ = Node;
  5793. ExportDefaultDeclaration.prototype = Object.create( Node && Node.prototype );
  5794. ExportDefaultDeclaration.prototype.constructor = ExportDefaultDeclaration;
  5795. ExportDefaultDeclaration.prototype.initialise = function initialise ( transforms ) {
  5796. if ( transforms.moduleExport ) throw new CompileError( this, 'export is not supported' );
  5797. Node.prototype.initialise.call( this, transforms );
  5798. };
  5799. return ExportDefaultDeclaration;
  5800. }(Node$1));
  5801. var ExportNamedDeclaration = (function (Node) {
  5802. function ExportNamedDeclaration () {
  5803. Node.apply(this, arguments);
  5804. }
  5805. if ( Node ) ExportNamedDeclaration.__proto__ = Node;
  5806. ExportNamedDeclaration.prototype = Object.create( Node && Node.prototype );
  5807. ExportNamedDeclaration.prototype.constructor = ExportNamedDeclaration;
  5808. ExportNamedDeclaration.prototype.initialise = function initialise ( transforms ) {
  5809. if ( transforms.moduleExport ) throw new CompileError( this, 'export is not supported' );
  5810. Node.prototype.initialise.call( this, transforms );
  5811. };
  5812. return ExportNamedDeclaration;
  5813. }(Node$1));
  5814. var LoopStatement = (function (Node) {
  5815. function LoopStatement () {
  5816. Node.apply(this, arguments);
  5817. }
  5818. if ( Node ) LoopStatement.__proto__ = Node;
  5819. LoopStatement.prototype = Object.create( Node && Node.prototype );
  5820. LoopStatement.prototype.constructor = LoopStatement;
  5821. LoopStatement.prototype.findScope = function findScope ( functionScope ) {
  5822. return functionScope || !this.createdScope ? this.parent.findScope( functionScope ) : this.body.scope;
  5823. };
  5824. LoopStatement.prototype.initialise = function initialise ( transforms ) {
  5825. var this$1 = this;
  5826. this.body.createScope();
  5827. this.createdScope = true;
  5828. // this is populated as and when reassignments occur
  5829. this.reassigned = Object.create( null );
  5830. this.aliases = Object.create( null );
  5831. Node.prototype.initialise.call( this, transforms );
  5832. if ( transforms.letConst ) {
  5833. // see if any block-scoped declarations are referenced
  5834. // inside function expressions
  5835. var names = Object.keys( this.body.scope.declarations );
  5836. var i = names.length;
  5837. while ( i-- ) {
  5838. var name = names[i];
  5839. var declaration = this$1.body.scope.declarations[ name ];
  5840. var j = declaration.instances.length;
  5841. while ( j-- ) {
  5842. var instance = declaration.instances[j];
  5843. var nearestFunctionExpression = instance.findNearest( /Function/ );
  5844. if ( nearestFunctionExpression && nearestFunctionExpression.depth > this$1.depth ) {
  5845. this$1.shouldRewriteAsFunction = true;
  5846. break;
  5847. }
  5848. }
  5849. if ( this$1.shouldRewriteAsFunction ) break;
  5850. }
  5851. }
  5852. };
  5853. LoopStatement.prototype.transpile = function transpile ( code, transforms ) {
  5854. var needsBlock = this.type != 'ForOfStatement' && (
  5855. this.body.type !== 'BlockStatement'
  5856. || this.body.type === 'BlockStatement' && this.body.synthetic );
  5857. if ( this.shouldRewriteAsFunction ) {
  5858. var i0 = this.getIndentation();
  5859. var i1 = i0 + code.getIndentString();
  5860. var argString = this.args ? (" " + (this.args.join( ', ' )) + " ") : '';
  5861. var paramString = this.params ? (" " + (this.params.join( ', ' )) + " ") : '';
  5862. var functionScope = this.findScope( true );
  5863. var loop = functionScope.createIdentifier( 'loop' );
  5864. var before = "var " + loop + " = function (" + paramString + ") " + ( this.body.synthetic ? ("{\n" + i0 + (code.getIndentString())) : '' );
  5865. var after = ( this.body.synthetic ? ("\n" + i0 + "}") : '' ) + ";\n\n" + i0;
  5866. code.insertRight( this.body.start, before );
  5867. code.insertLeft( this.body.end, after );
  5868. code.move( this.start, this.body.start, this.body.end );
  5869. if ( this.canBreak || this.canReturn ) {
  5870. var returned = functionScope.createIdentifier( 'returned' );
  5871. var insert = "{\n" + i1 + "var " + returned + " = " + loop + "(" + argString + ");\n";
  5872. if ( this.canBreak ) insert += "\n" + i1 + "if ( " + returned + " === 'break' ) break;";
  5873. if ( this.canReturn ) insert += "\n" + i1 + "if ( " + returned + " ) return " + returned + ".v;";
  5874. insert += "\n" + i0 + "}";
  5875. code.insertRight( this.body.end, insert );
  5876. } else {
  5877. var callExpression = loop + "(" + argString + ");";
  5878. if ( this.type === 'DoWhileStatement' ) {
  5879. code.overwrite( this.start, this.body.start, ("do {\n" + i1 + callExpression + "\n" + i0 + "}") );
  5880. } else {
  5881. code.insertRight( this.body.end, callExpression );
  5882. }
  5883. }
  5884. } else if ( needsBlock ) {
  5885. code.insertLeft( this.body.start, '{ ' );
  5886. code.insertRight( this.body.end, ' }' );
  5887. }
  5888. Node.prototype.transpile.call( this, code, transforms );
  5889. };
  5890. return LoopStatement;
  5891. }(Node$1));
  5892. function extractNames ( node ) {
  5893. var names = [];
  5894. extractors[ node.type ]( names, node );
  5895. return names;
  5896. }
  5897. var extractors = {
  5898. Identifier: function Identifier ( names, node ) {
  5899. names.push( node );
  5900. },
  5901. ObjectPattern: function ObjectPattern ( names, node ) {
  5902. for ( var i = 0, list = node.properties; i < list.length; i += 1 ) {
  5903. var prop = list[i];
  5904. extractors[ prop.value.type ]( names, prop.value );
  5905. }
  5906. },
  5907. ArrayPattern: function ArrayPattern ( names, node ) {
  5908. for ( var i = 0, list = node.elements; i < list.length; i += 1 ) {
  5909. var element = list[i];
  5910. if ( element ) extractors[ element.type ]( names, element );
  5911. }
  5912. },
  5913. RestElement: function RestElement ( names, node ) {
  5914. extractors[ node.argument.type ]( names, node.argument );
  5915. },
  5916. AssignmentPattern: function AssignmentPattern ( names, node ) {
  5917. extractors[ node.left.type ]( names, node.left );
  5918. }
  5919. };
  5920. var ForStatement = (function (LoopStatement$$1) {
  5921. function ForStatement () {
  5922. LoopStatement$$1.apply(this, arguments);
  5923. }
  5924. if ( LoopStatement$$1 ) ForStatement.__proto__ = LoopStatement$$1;
  5925. ForStatement.prototype = Object.create( LoopStatement$$1 && LoopStatement$$1.prototype );
  5926. ForStatement.prototype.constructor = ForStatement;
  5927. ForStatement.prototype.findScope = function findScope ( functionScope ) {
  5928. return functionScope || !this.createdScope ? this.parent.findScope( functionScope ) : this.body.scope;
  5929. };
  5930. ForStatement.prototype.transpile = function transpile ( code, transforms ) {
  5931. var this$1 = this;
  5932. var i1 = this.getIndentation() + code.getIndentString();
  5933. if ( this.shouldRewriteAsFunction ) {
  5934. // which variables are declared in the init statement?
  5935. var names = this.init.type === 'VariableDeclaration' ?
  5936. [].concat.apply( [], this.init.declarations.map( function ( declarator ) { return extractNames( declarator.id ); } ) ) :
  5937. [];
  5938. var aliases = this.aliases;
  5939. this.args = names.map( function ( name ) { return name in this$1.aliases ? this$1.aliases[ name ].outer : name; } );
  5940. this.params = names.map( function ( name ) { return name in this$1.aliases ? this$1.aliases[ name ].inner : name; } );
  5941. var updates = Object.keys( this.reassigned )
  5942. .map( function ( name ) { return ((aliases[ name ].outer) + " = " + (aliases[ name ].inner) + ";"); } );
  5943. if ( updates.length ) {
  5944. if ( this.body.synthetic ) {
  5945. code.insertLeft( this.body.body[0].end, ("; " + (updates.join(" "))) );
  5946. } else {
  5947. var lastStatement = this.body.body[ this.body.body.length - 1 ];
  5948. code.insertLeft( lastStatement.end, ("\n\n" + i1 + (updates.join(("\n" + i1)))) );
  5949. }
  5950. }
  5951. }
  5952. LoopStatement$$1.prototype.transpile.call( this, code, transforms );
  5953. };
  5954. return ForStatement;
  5955. }(LoopStatement));
  5956. var ForInStatement = (function (LoopStatement$$1) {
  5957. function ForInStatement () {
  5958. LoopStatement$$1.apply(this, arguments);
  5959. }
  5960. if ( LoopStatement$$1 ) ForInStatement.__proto__ = LoopStatement$$1;
  5961. ForInStatement.prototype = Object.create( LoopStatement$$1 && LoopStatement$$1.prototype );
  5962. ForInStatement.prototype.constructor = ForInStatement;
  5963. ForInStatement.prototype.findScope = function findScope ( functionScope ) {
  5964. return functionScope || !this.createdScope ? this.parent.findScope( functionScope ) : this.body.scope;
  5965. };
  5966. ForInStatement.prototype.transpile = function transpile ( code, transforms ) {
  5967. var this$1 = this;
  5968. if ( this.shouldRewriteAsFunction ) {
  5969. // which variables are declared in the init statement?
  5970. var names = this.left.type === 'VariableDeclaration' ?
  5971. [].concat.apply( [], this.left.declarations.map( function ( declarator ) { return extractNames( declarator.id ); } ) ) :
  5972. [];
  5973. this.args = names.map( function ( name ) { return name in this$1.aliases ? this$1.aliases[ name ].outer : name; } );
  5974. this.params = names.map( function ( name ) { return name in this$1.aliases ? this$1.aliases[ name ].inner : name; } );
  5975. }
  5976. LoopStatement$$1.prototype.transpile.call( this, code, transforms );
  5977. };
  5978. return ForInStatement;
  5979. }(LoopStatement));
  5980. var handlers = {
  5981. Identifier: destructureIdentifier,
  5982. AssignmentPattern: destructureAssignmentPattern,
  5983. ArrayPattern: destructureArrayPattern,
  5984. ObjectPattern: destructureObjectPattern
  5985. };
  5986. function destructure ( code, scope, node, ref, inline, statementGenerators ) {
  5987. handlers[ node.type ]( code, scope, node, ref, inline, statementGenerators );
  5988. }
  5989. function destructureIdentifier ( code, scope, node, ref, inline, statementGenerators ) {
  5990. statementGenerators.push( function ( start, prefix, suffix ) {
  5991. code.insertRight( node.start, inline ? prefix : (prefix + "var ") );
  5992. code.insertLeft( node.end, (" = " + ref + suffix) );
  5993. code.move( node.start, node.end, start );
  5994. });
  5995. }
  5996. function destructureAssignmentPattern ( code, scope, node, ref, inline, statementGenerators ) {
  5997. var isIdentifier = node.left.type === 'Identifier';
  5998. var name = isIdentifier ? node.left.name : ref;
  5999. if ( !inline ) {
  6000. statementGenerators.push( function ( start, prefix, suffix ) {
  6001. code.insertRight( node.left.end, (prefix + "if ( " + name + " === void 0 ) " + name) );
  6002. code.move( node.left.end, node.right.end, start );
  6003. code.insertLeft( node.right.end, suffix );
  6004. });
  6005. }
  6006. if ( !isIdentifier ) {
  6007. destructure( code, scope, node.left, ref, inline, statementGenerators );
  6008. }
  6009. }
  6010. function destructureArrayPattern ( code, scope, node, ref, inline, statementGenerators ) {
  6011. var c = node.start;
  6012. node.elements.forEach( function ( element, i ) {
  6013. if ( !element ) return;
  6014. if ( element.type === 'RestElement' ) {
  6015. handleProperty( code, scope, c, element.argument, (ref + ".slice(" + i + ")"), inline, statementGenerators );
  6016. } else {
  6017. handleProperty( code, scope, c, element, (ref + "[" + i + "]"), inline, statementGenerators );
  6018. }
  6019. c = element.end;
  6020. });
  6021. code.remove( c, node.end );
  6022. }
  6023. function destructureObjectPattern ( code, scope, node, ref, inline, statementGenerators ) {
  6024. var c = node.start;
  6025. node.properties.forEach( function ( prop ) {
  6026. var value = prop.computed || prop.key.type !== 'Identifier' ? (ref + "[" + (code.slice(prop.key.start, prop.key.end)) + "]") : (ref + "." + (prop.key.name));
  6027. handleProperty( code, scope, c, prop.value, value, inline, statementGenerators );
  6028. c = prop.end;
  6029. });
  6030. code.remove( c, node.end );
  6031. }
  6032. function handleProperty ( code, scope, c, node, value, inline, statementGenerators ) {
  6033. switch ( node.type ) {
  6034. case 'Identifier': {
  6035. code.remove( c, node.start );
  6036. destructureIdentifier( code, scope, node, value, inline, statementGenerators );
  6037. break;
  6038. }
  6039. case 'AssignmentPattern': {
  6040. var name;
  6041. var isIdentifier = node.left.type === 'Identifier';
  6042. if ( isIdentifier ) {
  6043. name = node.left.name;
  6044. var declaration = scope.findDeclaration( name );
  6045. if ( declaration ) name = declaration.name;
  6046. } else {
  6047. name = scope.createIdentifier( value );
  6048. }
  6049. statementGenerators.push( function ( start, prefix, suffix ) {
  6050. if ( inline ) {
  6051. code.insertRight( node.right.start, (name + " = " + value + " === undefined ? ") );
  6052. code.insertLeft( node.right.end, (" : " + value) );
  6053. } else {
  6054. code.insertRight( node.right.start, (prefix + "var " + name + " = " + value + "; if ( " + name + " === void 0 ) " + name + " = ") );
  6055. code.insertLeft( node.right.end, suffix );
  6056. }
  6057. code.move( node.right.start, node.right.end, start );
  6058. });
  6059. if ( isIdentifier ) {
  6060. code.remove( c, node.right.start );
  6061. } else {
  6062. code.remove( c, node.left.start );
  6063. code.remove( node.left.end, node.right.start );
  6064. handleProperty( code, scope, c, node.left, name, inline, statementGenerators );
  6065. }
  6066. break;
  6067. }
  6068. case 'ObjectPattern': {
  6069. code.remove( c, c = node.start );
  6070. if ( node.properties.length > 1 ) {
  6071. var ref = scope.createIdentifier( value );
  6072. statementGenerators.push( function ( start, prefix, suffix ) {
  6073. // this feels a tiny bit hacky, but we can't do a
  6074. // straightforward insertLeft and keep correct order...
  6075. code.insertRight( node.start, (prefix + "var " + ref + " = ") );
  6076. code.overwrite( node.start, c = node.start + 1, value );
  6077. code.insertLeft( c, suffix );
  6078. code.move( node.start, c, start );
  6079. });
  6080. node.properties.forEach( function ( prop ) {
  6081. var value = prop.computed || prop.key.type !== 'Identifier' ? (ref + "[" + (code.slice(prop.key.start, prop.key.end)) + "]") : (ref + "." + (prop.key.name));
  6082. handleProperty( code, scope, c, prop.value, value, inline, statementGenerators );
  6083. c = prop.end;
  6084. });
  6085. } else {
  6086. var prop = node.properties[0];
  6087. var value_suffix = prop.computed || prop.key.type !== 'Identifier' ? ("[" + (code.slice(prop.key.start, prop.key.end)) + "]") : ("." + (prop.key.name));
  6088. handleProperty( code, scope, c, prop.value, ("" + value + value_suffix), inline, statementGenerators );
  6089. c = prop.end;
  6090. }
  6091. code.remove( c, node.end );
  6092. break;
  6093. }
  6094. case 'ArrayPattern': {
  6095. code.remove( c, c = node.start );
  6096. if ( node.elements.filter( Boolean ).length > 1 ) {
  6097. var ref$1 = scope.createIdentifier( value );
  6098. statementGenerators.push( function ( start, prefix, suffix ) {
  6099. code.insertRight( node.start, (prefix + "var " + ref$1 + " = ") );
  6100. code.overwrite( node.start, c = node.start + 1, value );
  6101. code.insertLeft( c, suffix );
  6102. code.move( node.start, c, start );
  6103. });
  6104. node.elements.forEach( function ( element, i ) {
  6105. if ( !element ) return;
  6106. if ( element.type === 'RestElement' ) {
  6107. handleProperty( code, scope, c, element.argument, (ref$1 + ".slice(" + i + ")"), inline, statementGenerators );
  6108. } else {
  6109. handleProperty( code, scope, c, element, (ref$1 + "[" + i + "]"), inline, statementGenerators );
  6110. }
  6111. c = element.end;
  6112. });
  6113. } else {
  6114. var index = findIndex( node.elements, Boolean );
  6115. var element = node.elements[ index ];
  6116. if ( element.type === 'RestElement' ) {
  6117. handleProperty( code, scope, c, element.argument, (value + ".slice(" + index + ")"), inline, statementGenerators );
  6118. } else {
  6119. handleProperty( code, scope, c, element, (value + "[" + index + "]"), inline, statementGenerators );
  6120. }
  6121. c = element.end;
  6122. }
  6123. code.remove( c, node.end );
  6124. break;
  6125. }
  6126. default: {
  6127. throw new Error( ("Unexpected node type in destructuring (" + (node.type) + ")") );
  6128. }
  6129. }
  6130. }
  6131. var ForOfStatement = (function (LoopStatement$$1) {
  6132. function ForOfStatement () {
  6133. LoopStatement$$1.apply(this, arguments);
  6134. }
  6135. if ( LoopStatement$$1 ) ForOfStatement.__proto__ = LoopStatement$$1;
  6136. ForOfStatement.prototype = Object.create( LoopStatement$$1 && LoopStatement$$1.prototype );
  6137. ForOfStatement.prototype.constructor = ForOfStatement;
  6138. ForOfStatement.prototype.initialise = function initialise ( transforms ) {
  6139. if ( transforms.forOf && !transforms.dangerousForOf ) throw new CompileError( this, 'for...of statements are not supported. Use `transforms: { forOf: false }` to skip transformation and disable this error, or `transforms: { dangerousForOf: true }` if you know what you\'re doing' );
  6140. LoopStatement$$1.prototype.initialise.call( this, transforms );
  6141. };
  6142. ForOfStatement.prototype.transpile = function transpile ( code, transforms ) {
  6143. if ( !transforms.dangerousForOf ) {
  6144. LoopStatement$$1.prototype.transpile.call( this, code, transforms );
  6145. return;
  6146. }
  6147. // edge case (#80)
  6148. if ( !this.body.body[0] ) {
  6149. if ( this.left.type === 'VariableDeclaration' && this.left.kind === 'var' ) {
  6150. code.remove( this.start, this.left.start );
  6151. code.insertLeft( this.left.end, ';' );
  6152. code.remove( this.left.end, this.end );
  6153. } else {
  6154. code.remove( this.start, this.end );
  6155. }
  6156. return;
  6157. }
  6158. var scope = this.findScope( true );
  6159. var i0 = this.getIndentation();
  6160. var i1 = i0 + code.getIndentString();
  6161. var key = scope.createIdentifier( 'i' );
  6162. var list = scope.createIdentifier( 'list' );
  6163. if ( this.body.synthetic ) {
  6164. code.insertRight( this.left.start, ("{\n" + i1) );
  6165. code.insertLeft( this.body.body[0].end, ("\n" + i0 + "}") );
  6166. }
  6167. var bodyStart = this.body.body[0].start;
  6168. code.remove( this.left.end, this.right.start );
  6169. code.move( this.left.start, this.left.end, bodyStart );
  6170. code.insertRight( this.right.start, ("var " + key + " = 0, " + list + " = ") );
  6171. code.insertLeft( this.right.end, ("; " + key + " < " + list + ".length; " + key + " += 1") );
  6172. // destructuring. TODO non declaration destructuring
  6173. var declarator = this.left.type === 'VariableDeclaration' && this.left.declarations[0];
  6174. if ( declarator && declarator.id.type !== 'Identifier' ) {
  6175. var statementGenerators = [];
  6176. var ref = scope.createIdentifier( 'ref' );
  6177. destructure( code, scope, declarator.id, ref, false, statementGenerators );
  6178. var suffix = ";\n" + i1;
  6179. statementGenerators.forEach( function ( fn, i ) {
  6180. if ( i === statementGenerators.length - 1 ) {
  6181. suffix = ";\n\n" + i1;
  6182. }
  6183. fn( bodyStart, '', suffix );
  6184. });
  6185. code.insertLeft( this.left.start + this.left.kind.length + 1, ref );
  6186. code.insertLeft( this.left.end, (" = " + list + "[" + key + "];\n" + i1) );
  6187. } else {
  6188. code.insertLeft( this.left.end, (" = " + list + "[" + key + "];\n\n" + i1) );
  6189. }
  6190. LoopStatement$$1.prototype.transpile.call( this, code, transforms );
  6191. };
  6192. return ForOfStatement;
  6193. }(LoopStatement));
  6194. var FunctionDeclaration = (function (Node) {
  6195. function FunctionDeclaration () {
  6196. Node.apply(this, arguments);
  6197. }
  6198. if ( Node ) FunctionDeclaration.__proto__ = Node;
  6199. FunctionDeclaration.prototype = Object.create( Node && Node.prototype );
  6200. FunctionDeclaration.prototype.constructor = FunctionDeclaration;
  6201. FunctionDeclaration.prototype.initialise = function initialise ( transforms ) {
  6202. if ( this.generator && transforms.generator ) {
  6203. throw new CompileError( this, 'Generators are not supported' );
  6204. }
  6205. this.body.createScope();
  6206. this.findScope( true ).addDeclaration( this.id, 'function' );
  6207. Node.prototype.initialise.call( this, transforms );
  6208. };
  6209. return FunctionDeclaration;
  6210. }(Node$1));
  6211. var FunctionExpression = (function (Node) {
  6212. function FunctionExpression () {
  6213. Node.apply(this, arguments);
  6214. }
  6215. if ( Node ) FunctionExpression.__proto__ = Node;
  6216. FunctionExpression.prototype = Object.create( Node && Node.prototype );
  6217. FunctionExpression.prototype.constructor = FunctionExpression;
  6218. FunctionExpression.prototype.initialise = function initialise ( transforms ) {
  6219. if ( this.generator && transforms.generator ) {
  6220. throw new CompileError( this, 'Generators are not supported' );
  6221. }
  6222. this.body.createScope();
  6223. if ( this.id ) {
  6224. // function expression IDs belong to the child scope...
  6225. this.body.scope.addDeclaration( this.id, 'function' );
  6226. }
  6227. Node.prototype.initialise.call( this, transforms );
  6228. var parent = this.parent;
  6229. var methodName;
  6230. if ( transforms.conciseMethodProperty
  6231. && parent.type === 'Property'
  6232. && parent.kind === 'init'
  6233. && parent.method
  6234. && parent.key.type === 'Identifier' ) {
  6235. // object literal concise method
  6236. methodName = parent.key.name;
  6237. }
  6238. else if ( transforms.classes
  6239. && parent.type === 'MethodDefinition'
  6240. && parent.kind === 'method'
  6241. && parent.key.type === 'Identifier' ) {
  6242. // method definition in a class
  6243. methodName = parent.key.name;
  6244. }
  6245. else if ( this.id && this.id.type === 'Identifier' ) {
  6246. // naked function expression
  6247. methodName = this.id.alias || this.id.name;
  6248. }
  6249. if ( methodName ) {
  6250. for ( var i = 0, list = this.params; i < list.length; i += 1 ) {
  6251. var param = list[i];
  6252. if ( param.type === 'Identifier' && methodName === param.name ) {
  6253. // workaround for Safari 9/WebKit bug:
  6254. // https://gitlab.com/Rich-Harris/buble/issues/154
  6255. // change parameter name when same as method name
  6256. var scope = this.body.scope;
  6257. var declaration = scope.declarations[ methodName ];
  6258. var alias = scope.createIdentifier( methodName );
  6259. param.alias = alias;
  6260. for ( var i$1 = 0, list$1 = declaration.instances; i$1 < list$1.length; i$1 += 1 ) {
  6261. var identifier = list$1[i$1];
  6262. identifier.alias = alias;
  6263. }
  6264. break;
  6265. }
  6266. }
  6267. }
  6268. };
  6269. return FunctionExpression;
  6270. }(Node$1));
  6271. function isReference ( node, parent ) {
  6272. if ( node.type === 'MemberExpression' ) {
  6273. return !node.computed && isReference( node.object, node );
  6274. }
  6275. if ( node.type === 'Identifier' ) {
  6276. // the only time we could have an identifier node without a parent is
  6277. // if it's the entire body of a function without a block statement –
  6278. // i.e. an arrow function expression like `a => a`
  6279. if ( !parent ) return true;
  6280. if ( /(Function|Class)Expression/.test( parent.type ) ) return false;
  6281. if ( parent.type === 'VariableDeclarator' ) return node === parent.init;
  6282. // TODO is this right?
  6283. if ( parent.type === 'MemberExpression' || parent.type === 'MethodDefinition' ) {
  6284. return parent.computed || node === parent.object;
  6285. }
  6286. if ( parent.type === 'ArrayPattern' ) return false;
  6287. // disregard the `bar` in `{ bar: foo }`, but keep it in `{ [bar]: foo }`
  6288. if ( parent.type === 'Property' ) {
  6289. if ( parent.parent.type === 'ObjectPattern' ) return false;
  6290. return parent.computed || node === parent.value;
  6291. }
  6292. // disregard the `bar` in `class Foo { bar () {...} }`
  6293. if ( parent.type === 'MethodDefinition' ) return false;
  6294. // disregard the `bar` in `export { foo as bar }`
  6295. if ( parent.type === 'ExportSpecifier' && node !== parent.local ) return false;
  6296. return true;
  6297. }
  6298. }
  6299. // allowed globals in Vue render functions.
  6300. // same as in src/core/instance/proxy.js
  6301. var names = 'Infinity,undefined,NaN,isFinite,isNaN,' +
  6302. 'parseFloat,parseInt,decodeURI,decodeURIComponent,encodeURI,encodeURIComponent,' +
  6303. 'Math,Number,Date,Array,Object,Boolean,String,RegExp,Map,Set,JSON,Intl,' +
  6304. 'require,' + // for webpack
  6305. 'arguments,' + // parsed as identifier but is a special keyword...
  6306. '_h,_c'; // cached to save property access (_c for ^2.1.5)
  6307. var hash = Object.create(null);
  6308. names.split(',').forEach(function ( name ) {
  6309. hash[name] = true;
  6310. });
  6311. var isDeclaration = function ( type ) { return /Declaration$/.test(type); };
  6312. var isFunction = function ( type ) { return /Function(Expression|Declaration)$/.test(type); };
  6313. var Identifier = (function (Node) {
  6314. function Identifier () {
  6315. Node.apply(this, arguments);
  6316. }
  6317. if ( Node ) Identifier.__proto__ = Node;
  6318. Identifier.prototype = Object.create( Node && Node.prototype );
  6319. Identifier.prototype.constructor = Identifier;
  6320. Identifier.prototype.findScope = function findScope ( functionScope ) {
  6321. if ( this.parent.params && ~this.parent.params.indexOf( this ) ) {
  6322. return this.parent.body.scope;
  6323. }
  6324. if ( this.parent.type === 'FunctionExpression' && this === this.parent.id ) {
  6325. return this.parent.body.scope;
  6326. }
  6327. return this.parent.findScope( functionScope );
  6328. };
  6329. Identifier.prototype.initialise = function initialise ( transforms ) {
  6330. if ( transforms.arrow && isReference( this, this.parent ) ) {
  6331. if ( this.name === 'arguments' && !this.findScope( false ).contains( this.name ) ) {
  6332. var lexicalBoundary = this.findLexicalBoundary();
  6333. var arrowFunction = this.findNearest( 'ArrowFunctionExpression' );
  6334. var loop = this.findNearest( loopStatement );
  6335. if ( arrowFunction && arrowFunction.depth > lexicalBoundary.depth ) {
  6336. this.alias = lexicalBoundary.getArgumentsAlias();
  6337. }
  6338. if ( loop && loop.body.contains( this ) && loop.depth > lexicalBoundary.depth ) {
  6339. this.alias = lexicalBoundary.getArgumentsAlias();
  6340. }
  6341. }
  6342. this.findScope( false ).addReference( this );
  6343. }
  6344. };
  6345. Identifier.prototype.transpile = function transpile ( code, transforms ) {
  6346. if ( this.alias ) {
  6347. code.overwrite( this.start, this.end, this.alias, true );
  6348. }
  6349. // rewrite identifiers inside Vue render function `with` blocks
  6350. if (
  6351. this.program.inWith > 0 &&
  6352. // not id of a Declaration
  6353. !(isDeclaration(this.parent.type) && this.parent.id === this) &&
  6354. // not a params of a function
  6355. !(isFunction(this.parent.type) && this.parent.params.indexOf(this) > -1) &&
  6356. // not a key of Property
  6357. !(this.parent.type === 'Property' && this.parent.key === this && !this.parent.computed) &&
  6358. // not a property of a MemberExpression
  6359. !(this.parent.type === 'MemberExpression' && this.parent.property === this && !this.parent.computed) &&
  6360. // not in an Array destructure pattern
  6361. !(this.parent.type === 'ArrayPattern') &&
  6362. // not in an Object destructure pattern
  6363. !(this.parent.parent.type === 'ObjectPattern') &&
  6364. // skip globals + commonly used shorthands
  6365. !hash[this.name] &&
  6366. // not already in scope
  6367. !this.findScope(false).contains(this.name)
  6368. ) {
  6369. code.overwrite(this.start, this.end, ("_vm." + (this.name)));
  6370. }
  6371. };
  6372. return Identifier;
  6373. }(Node$1));
  6374. var IfStatement = (function (Node) {
  6375. function IfStatement () {
  6376. Node.apply(this, arguments);
  6377. }
  6378. if ( Node ) IfStatement.__proto__ = Node;
  6379. IfStatement.prototype = Object.create( Node && Node.prototype );
  6380. IfStatement.prototype.constructor = IfStatement;
  6381. IfStatement.prototype.initialise = function initialise ( transforms ) {
  6382. Node.prototype.initialise.call( this, transforms );
  6383. };
  6384. IfStatement.prototype.transpile = function transpile ( code, transforms ) {
  6385. if ( this.consequent.type !== 'BlockStatement'
  6386. || this.consequent.type === 'BlockStatement' && this.consequent.synthetic ) {
  6387. code.insertLeft( this.consequent.start, '{ ' );
  6388. code.insertRight( this.consequent.end, ' }' );
  6389. }
  6390. if ( this.alternate && this.alternate.type !== 'IfStatement' && (
  6391. this.alternate.type !== 'BlockStatement'
  6392. || this.alternate.type === 'BlockStatement' && this.alternate.synthetic ) ) {
  6393. code.insertLeft( this.alternate.start, '{ ' );
  6394. code.insertRight( this.alternate.end, ' }' );
  6395. }
  6396. Node.prototype.transpile.call( this, code, transforms );
  6397. };
  6398. return IfStatement;
  6399. }(Node$1));
  6400. var ImportDeclaration = (function (Node) {
  6401. function ImportDeclaration () {
  6402. Node.apply(this, arguments);
  6403. }
  6404. if ( Node ) ImportDeclaration.__proto__ = Node;
  6405. ImportDeclaration.prototype = Object.create( Node && Node.prototype );
  6406. ImportDeclaration.prototype.constructor = ImportDeclaration;
  6407. ImportDeclaration.prototype.initialise = function initialise ( transforms ) {
  6408. if ( transforms.moduleImport ) throw new CompileError( this, 'import is not supported' );
  6409. Node.prototype.initialise.call( this, transforms );
  6410. };
  6411. return ImportDeclaration;
  6412. }(Node$1));
  6413. var ImportDefaultSpecifier = (function (Node) {
  6414. function ImportDefaultSpecifier () {
  6415. Node.apply(this, arguments);
  6416. }
  6417. if ( Node ) ImportDefaultSpecifier.__proto__ = Node;
  6418. ImportDefaultSpecifier.prototype = Object.create( Node && Node.prototype );
  6419. ImportDefaultSpecifier.prototype.constructor = ImportDefaultSpecifier;
  6420. ImportDefaultSpecifier.prototype.initialise = function initialise ( transforms ) {
  6421. this.findScope( true ).addDeclaration( this.local, 'import' );
  6422. Node.prototype.initialise.call( this, transforms );
  6423. };
  6424. return ImportDefaultSpecifier;
  6425. }(Node$1));
  6426. var ImportSpecifier = (function (Node) {
  6427. function ImportSpecifier () {
  6428. Node.apply(this, arguments);
  6429. }
  6430. if ( Node ) ImportSpecifier.__proto__ = Node;
  6431. ImportSpecifier.prototype = Object.create( Node && Node.prototype );
  6432. ImportSpecifier.prototype.constructor = ImportSpecifier;
  6433. ImportSpecifier.prototype.initialise = function initialise ( transforms ) {
  6434. this.findScope( true ).addDeclaration( this.local, 'import' );
  6435. Node.prototype.initialise.call( this, transforms );
  6436. };
  6437. return ImportSpecifier;
  6438. }(Node$1));
  6439. var hasDashes = function ( val ) { return /-/.test(val); };
  6440. var formatKey = function ( key ) { return hasDashes(key) ? ("'" + key + "'") : key; };
  6441. var formatVal = function ( val ) { return val ? '' : 'true'; };
  6442. var JSXAttribute = (function (Node) {
  6443. function JSXAttribute () {
  6444. Node.apply(this, arguments);
  6445. }
  6446. if ( Node ) JSXAttribute.__proto__ = Node;
  6447. JSXAttribute.prototype = Object.create( Node && Node.prototype );
  6448. JSXAttribute.prototype.constructor = JSXAttribute;
  6449. JSXAttribute.prototype.transpile = function transpile ( code, transforms ) {
  6450. var ref = this.name;
  6451. var start = ref.start;
  6452. var name = ref.name;
  6453. // Overwrite equals sign if value is present.
  6454. var end = this.value ? this.value.start : this.name.end;
  6455. code.overwrite( start, end, ((formatKey(name)) + ": " + (formatVal(this.value))) );
  6456. Node.prototype.transpile.call( this, code, transforms );
  6457. };
  6458. return JSXAttribute;
  6459. }(Node$1));
  6460. function containsNewLine ( node ) {
  6461. return node.type === 'Literal' && !/\S/.test( node.value ) && /\n/.test( node.value );
  6462. }
  6463. var JSXClosingElement = (function (Node) {
  6464. function JSXClosingElement () {
  6465. Node.apply(this, arguments);
  6466. }
  6467. if ( Node ) JSXClosingElement.__proto__ = Node;
  6468. JSXClosingElement.prototype = Object.create( Node && Node.prototype );
  6469. JSXClosingElement.prototype.constructor = JSXClosingElement;
  6470. JSXClosingElement.prototype.transpile = function transpile ( code ) {
  6471. var spaceBeforeParen = true;
  6472. var lastChild = this.parent.children[ this.parent.children.length - 1 ];
  6473. // omit space before closing paren if
  6474. // a) this is on a separate line, or
  6475. // b) there are no children but there are attributes
  6476. if ( ( lastChild && containsNewLine( lastChild ) ) || ( this.parent.openingElement.attributes.length ) ) {
  6477. spaceBeforeParen = false;
  6478. }
  6479. code.overwrite( this.start, this.end, spaceBeforeParen ? ' )' : ')' );
  6480. };
  6481. return JSXClosingElement;
  6482. }(Node$1));
  6483. function normalise ( str, removeTrailingWhitespace ) {
  6484. if ( removeTrailingWhitespace && /\n/.test( str ) ) {
  6485. str = str.replace( /\s+$/, '' );
  6486. }
  6487. str = str
  6488. .replace( /^\n\r?\s+/, '' ) // remove leading newline + space
  6489. .replace( /\s*\n\r?\s*/gm, ' ' ); // replace newlines with spaces
  6490. // TODO prefer single quotes?
  6491. return JSON.stringify( str );
  6492. }
  6493. var JSXElement = (function (Node) {
  6494. function JSXElement () {
  6495. Node.apply(this, arguments);
  6496. }
  6497. if ( Node ) JSXElement.__proto__ = Node;
  6498. JSXElement.prototype = Object.create( Node && Node.prototype );
  6499. JSXElement.prototype.constructor = JSXElement;
  6500. JSXElement.prototype.transpile = function transpile ( code, transforms ) {
  6501. Node.prototype.transpile.call( this, code, transforms );
  6502. var children = this.children.filter( function ( child ) {
  6503. if ( child.type !== 'Literal' ) return true;
  6504. // remove whitespace-only literals, unless on a single line
  6505. return /\S/.test( child.value ) || !/\n/.test( child.value );
  6506. });
  6507. if ( children.length ) {
  6508. var c = this.openingElement.end;
  6509. var i;
  6510. for ( i = 0; i < children.length; i += 1 ) {
  6511. var child = children[i];
  6512. if ( child.type === 'JSXExpressionContainer' && child.expression.type === 'JSXEmptyExpression' ) {
  6513. // empty block is a no op
  6514. } else {
  6515. var tail = code.original[ c ] === '\n' && child.type !== 'Literal' ? '' : ' ';
  6516. code.insertLeft( c, ("," + tail) );
  6517. }
  6518. if ( child.type === 'Literal' ) {
  6519. var str = normalise( child.value, i === children.length - 1 );
  6520. code.overwrite( child.start, child.end, str );
  6521. }
  6522. c = child.end;
  6523. }
  6524. }
  6525. };
  6526. return JSXElement;
  6527. }(Node$1));
  6528. var JSXExpressionContainer = (function (Node) {
  6529. function JSXExpressionContainer () {
  6530. Node.apply(this, arguments);
  6531. }
  6532. if ( Node ) JSXExpressionContainer.__proto__ = Node;
  6533. JSXExpressionContainer.prototype = Object.create( Node && Node.prototype );
  6534. JSXExpressionContainer.prototype.constructor = JSXExpressionContainer;
  6535. JSXExpressionContainer.prototype.transpile = function transpile ( code, transforms ) {
  6536. code.remove( this.start, this.expression.start );
  6537. code.remove( this.expression.end, this.end );
  6538. Node.prototype.transpile.call( this, code, transforms );
  6539. };
  6540. return JSXExpressionContainer;
  6541. }(Node$1));
  6542. var JSXOpeningElement = (function (Node) {
  6543. function JSXOpeningElement () {
  6544. Node.apply(this, arguments);
  6545. }
  6546. if ( Node ) JSXOpeningElement.__proto__ = Node;
  6547. JSXOpeningElement.prototype = Object.create( Node && Node.prototype );
  6548. JSXOpeningElement.prototype.constructor = JSXOpeningElement;
  6549. JSXOpeningElement.prototype.transpile = function transpile ( code, transforms ) {
  6550. var this$1 = this;
  6551. code.overwrite( this.start, this.name.start, ((this.program.jsx) + "( ") );
  6552. var html = this.name.type === 'JSXIdentifier' && this.name.name[0] === this.name.name[0].toLowerCase();
  6553. if ( html ) code.insertRight( this.name.start, "'" );
  6554. var len = this.attributes.length;
  6555. var c = this.name.end;
  6556. if ( len ) {
  6557. var i;
  6558. var hasSpread = false;
  6559. for ( i = 0; i < len; i += 1 ) {
  6560. if ( this$1.attributes[i].type === 'JSXSpreadAttribute' ) {
  6561. hasSpread = true;
  6562. break;
  6563. }
  6564. }
  6565. c = this.attributes[0].end;
  6566. for ( i = 0; i < len; i += 1 ) {
  6567. var attr = this$1.attributes[i];
  6568. if ( i > 0 ) {
  6569. if ( attr.start === c )
  6570. code.insertRight( c, ', ' );
  6571. else
  6572. code.overwrite( c, attr.start, ', ' );
  6573. }
  6574. if ( hasSpread && attr.type !== 'JSXSpreadAttribute' ) {
  6575. var lastAttr = this$1.attributes[ i - 1 ];
  6576. var nextAttr = this$1.attributes[ i + 1 ];
  6577. if ( !lastAttr || lastAttr.type === 'JSXSpreadAttribute' ) {
  6578. code.insertRight( attr.start, '{ ' );
  6579. }
  6580. if ( !nextAttr || nextAttr.type === 'JSXSpreadAttribute' ) {
  6581. code.insertLeft( attr.end, ' }' );
  6582. }
  6583. }
  6584. c = attr.end;
  6585. }
  6586. var after;
  6587. var before;
  6588. if ( hasSpread ) {
  6589. if ( len === 1 ) {
  6590. before = html ? "'," : ',';
  6591. } else {
  6592. if (!this.program.options.objectAssign) {
  6593. throw new CompileError( this, 'Mixed JSX attributes ending in spread requires specified objectAssign option with \'Object.assign\' or polyfill helper.' );
  6594. }
  6595. before = html ? ("', " + (this.program.options.objectAssign) + "({},") : (", " + (this.program.options.objectAssign) + "({},");
  6596. after = ')';
  6597. }
  6598. } else {
  6599. before = html ? "', {" : ', {';
  6600. after = ' }';
  6601. }
  6602. code.insertRight( this.name.end, before );
  6603. if ( after ) {
  6604. code.insertLeft( this.attributes[ len - 1 ].end, after );
  6605. }
  6606. } else {
  6607. code.insertLeft( this.name.end, html ? "', null" : ", null" );
  6608. c = this.name.end;
  6609. }
  6610. Node.prototype.transpile.call( this, code, transforms );
  6611. if ( this.selfClosing ) {
  6612. code.overwrite( c, this.end, this.attributes.length ? ")" : " )" );
  6613. } else {
  6614. code.remove( c, this.end );
  6615. }
  6616. };
  6617. return JSXOpeningElement;
  6618. }(Node$1));
  6619. var JSXSpreadAttribute = (function (Node) {
  6620. function JSXSpreadAttribute () {
  6621. Node.apply(this, arguments);
  6622. }
  6623. if ( Node ) JSXSpreadAttribute.__proto__ = Node;
  6624. JSXSpreadAttribute.prototype = Object.create( Node && Node.prototype );
  6625. JSXSpreadAttribute.prototype.constructor = JSXSpreadAttribute;
  6626. JSXSpreadAttribute.prototype.transpile = function transpile ( code, transforms ) {
  6627. code.remove( this.start, this.argument.start );
  6628. code.remove( this.argument.end, this.end );
  6629. Node.prototype.transpile.call( this, code, transforms );
  6630. };
  6631. return JSXSpreadAttribute;
  6632. }(Node$1));
  6633. var commonjsGlobal = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
  6634. function commonjsRequire () {
  6635. throw new Error('Dynamic requires are not currently supported by rollup-plugin-commonjs');
  6636. }
  6637. function createCommonjsModule(fn, module) {
  6638. return module = { exports: {} }, fn(module, module.exports), module.exports;
  6639. }
  6640. var regjsgen = createCommonjsModule(function (module, exports) {
  6641. /*!
  6642. * regjsgen 0.3.0
  6643. * Copyright 2014-2016 Benjamin Tan <https://demoneaux.github.io/>
  6644. * Available under MIT license <https://github.com/demoneaux/regjsgen/blob/master/LICENSE>
  6645. */
  6646. (function() {
  6647. 'use strict';
  6648. // Used to determine if values are of the language type `Object`.
  6649. var objectTypes = {
  6650. 'function': true,
  6651. 'object': true
  6652. };
  6653. // Used as a reference to the global object.
  6654. var root = (objectTypes[typeof window] && window) || this;
  6655. // Detect free variable `exports`.
  6656. var freeExports = objectTypes['object'] && exports;
  6657. // Detect free variable `module`.
  6658. var freeModule = objectTypes['object'] && module && !module.nodeType && module;
  6659. // Detect free variable `global` from Node.js or Browserified code and use it as `root`.
  6660. var freeGlobal = freeExports && freeModule && typeof commonjsGlobal == 'object' && commonjsGlobal;
  6661. if (freeGlobal && (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal || freeGlobal.self === freeGlobal)) {
  6662. root = freeGlobal;
  6663. }
  6664. // Used to check objects for own properties.
  6665. var hasOwnProperty = Object.prototype.hasOwnProperty;
  6666. /*--------------------------------------------------------------------------*/
  6667. // Generates strings based on the given code points.
  6668. // Based on https://mths.be/fromcodepoint v0.2.0 by @mathias.
  6669. var stringFromCharCode = String.fromCharCode;
  6670. var floor = Math.floor;
  6671. function fromCodePoint() {
  6672. var MAX_SIZE = 0x4000;
  6673. var codeUnits = [];
  6674. var highSurrogate;
  6675. var lowSurrogate;
  6676. var index = -1;
  6677. var length = arguments.length;
  6678. if (!length) {
  6679. return '';
  6680. }
  6681. var result = '';
  6682. while (++index < length) {
  6683. var codePoint = Number(arguments[index]);
  6684. if (
  6685. !isFinite(codePoint) || // `NaN`, `+Infinity`, or `-Infinity`
  6686. codePoint < 0 || // not a valid Unicode code point
  6687. codePoint > 0x10FFFF || // not a valid Unicode code point
  6688. floor(codePoint) != codePoint // not an integer
  6689. ) {
  6690. throw RangeError('Invalid code point: ' + codePoint);
  6691. }
  6692. if (codePoint <= 0xFFFF) {
  6693. // BMP code point
  6694. codeUnits.push(codePoint);
  6695. } else {
  6696. // Astral code point; split in surrogate halves
  6697. // http://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
  6698. codePoint -= 0x10000;
  6699. highSurrogate = (codePoint >> 10) + 0xD800;
  6700. lowSurrogate = (codePoint % 0x400) + 0xDC00;
  6701. codeUnits.push(highSurrogate, lowSurrogate);
  6702. }
  6703. if (index + 1 == length || codeUnits.length > MAX_SIZE) {
  6704. result += stringFromCharCode.apply(null, codeUnits);
  6705. codeUnits.length = 0;
  6706. }
  6707. }
  6708. return result;
  6709. }
  6710. /*--------------------------------------------------------------------------*/
  6711. // Ensures that nodes have the correct types.
  6712. var assertTypeRegexMap = {};
  6713. function assertType(type, expected) {
  6714. if (expected.indexOf('|') == -1) {
  6715. if (type == expected) {
  6716. return;
  6717. }
  6718. throw Error('Invalid node type: ' + type + '; expected type: ' + expected);
  6719. }
  6720. expected = hasOwnProperty.call(assertTypeRegexMap, expected)
  6721. ? assertTypeRegexMap[expected]
  6722. : (assertTypeRegexMap[expected] = RegExp('^(?:' + expected + ')$'));
  6723. if (expected.test(type)) {
  6724. return;
  6725. }
  6726. throw Error('Invalid node type: ' + type + '; expected types: ' + expected);
  6727. }
  6728. /*--------------------------------------------------------------------------*/
  6729. // Generates a regular expression string based on an AST.
  6730. function generate(node) {
  6731. var type = node.type;
  6732. if (hasOwnProperty.call(generators, type)) {
  6733. return generators[type](node);
  6734. }
  6735. throw Error('Invalid node type: ' + type);
  6736. }
  6737. /*--------------------------------------------------------------------------*/
  6738. function generateAlternative(node) {
  6739. assertType(node.type, 'alternative');
  6740. var terms = node.body,
  6741. i = -1,
  6742. length = terms.length,
  6743. result = '';
  6744. while (++i < length) {
  6745. result += generateTerm(terms[i]);
  6746. }
  6747. return result;
  6748. }
  6749. function generateAnchor(node) {
  6750. assertType(node.type, 'anchor');
  6751. switch (node.kind) {
  6752. case 'start':
  6753. return '^';
  6754. case 'end':
  6755. return '$';
  6756. case 'boundary':
  6757. return '\\b';
  6758. case 'not-boundary':
  6759. return '\\B';
  6760. default:
  6761. throw Error('Invalid assertion');
  6762. }
  6763. }
  6764. function generateAtom(node) {
  6765. assertType(node.type, 'anchor|characterClass|characterClassEscape|dot|group|reference|value');
  6766. return generate(node);
  6767. }
  6768. function generateCharacterClass(node) {
  6769. assertType(node.type, 'characterClass');
  6770. var classRanges = node.body,
  6771. i = -1,
  6772. length = classRanges.length,
  6773. result = '';
  6774. if (node.negative) {
  6775. result += '^';
  6776. }
  6777. while (++i < length) {
  6778. result += generateClassAtom(classRanges[i]);
  6779. }
  6780. return '[' + result + ']';
  6781. }
  6782. function generateCharacterClassEscape(node) {
  6783. assertType(node.type, 'characterClassEscape');
  6784. return '\\' + node.value;
  6785. }
  6786. function generateUnicodePropertyEscape(node) {
  6787. assertType(node.type, 'unicodePropertyEscape');
  6788. return '\\' + (node.negative ? 'P' : 'p') + '{' + node.value + '}';
  6789. }
  6790. function generateCharacterClassRange(node) {
  6791. assertType(node.type, 'characterClassRange');
  6792. var min = node.min,
  6793. max = node.max;
  6794. if (min.type == 'characterClassRange' || max.type == 'characterClassRange') {
  6795. throw Error('Invalid character class range');
  6796. }
  6797. return generateClassAtom(min) + '-' + generateClassAtom(max);
  6798. }
  6799. function generateClassAtom(node) {
  6800. assertType(node.type, 'anchor|characterClassEscape|characterClassRange|dot|value');
  6801. return generate(node);
  6802. }
  6803. function generateDisjunction(node) {
  6804. assertType(node.type, 'disjunction');
  6805. var body = node.body,
  6806. i = -1,
  6807. length = body.length,
  6808. result = '';
  6809. while (++i < length) {
  6810. if (i != 0) {
  6811. result += '|';
  6812. }
  6813. result += generate(body[i]);
  6814. }
  6815. return result;
  6816. }
  6817. function generateDot(node) {
  6818. assertType(node.type, 'dot');
  6819. return '.';
  6820. }
  6821. function generateGroup(node) {
  6822. assertType(node.type, 'group');
  6823. var result = '';
  6824. switch (node.behavior) {
  6825. case 'normal':
  6826. break;
  6827. case 'ignore':
  6828. result += '?:';
  6829. break;
  6830. case 'lookahead':
  6831. result += '?=';
  6832. break;
  6833. case 'negativeLookahead':
  6834. result += '?!';
  6835. break;
  6836. default:
  6837. throw Error('Invalid behaviour: ' + node.behaviour);
  6838. }
  6839. var body = node.body,
  6840. i = -1,
  6841. length = body.length;
  6842. while (++i < length) {
  6843. result += generate(body[i]);
  6844. }
  6845. return '(' + result + ')';
  6846. }
  6847. function generateQuantifier(node) {
  6848. assertType(node.type, 'quantifier');
  6849. var quantifier = '',
  6850. min = node.min,
  6851. max = node.max;
  6852. if (max == null) {
  6853. if (min == 0) {
  6854. quantifier = '*';
  6855. } else if (min == 1) {
  6856. quantifier = '+';
  6857. } else {
  6858. quantifier = '{' + min + ',}';
  6859. }
  6860. } else if (min == max) {
  6861. quantifier = '{' + min + '}';
  6862. } else if (min == 0 && max == 1) {
  6863. quantifier = '?';
  6864. } else {
  6865. quantifier = '{' + min + ',' + max + '}';
  6866. }
  6867. if (!node.greedy) {
  6868. quantifier += '?';
  6869. }
  6870. return generateAtom(node.body[0]) + quantifier;
  6871. }
  6872. function generateReference(node) {
  6873. assertType(node.type, 'reference');
  6874. return '\\' + node.matchIndex;
  6875. }
  6876. function generateTerm(node) {
  6877. assertType(node.type, 'anchor|characterClass|characterClassEscape|empty|group|quantifier|reference|unicodePropertyEscape|value');
  6878. return generate(node);
  6879. }
  6880. function generateValue(node) {
  6881. assertType(node.type, 'value');
  6882. var kind = node.kind,
  6883. codePoint = node.codePoint;
  6884. switch (kind) {
  6885. case 'controlLetter':
  6886. return '\\c' + fromCodePoint(codePoint + 64);
  6887. case 'hexadecimalEscape':
  6888. return '\\x' + ('00' + codePoint.toString(16).toUpperCase()).slice(-2);
  6889. case 'identifier':
  6890. return '\\' + fromCodePoint(codePoint);
  6891. case 'null':
  6892. return '\\' + codePoint;
  6893. case 'octal':
  6894. return '\\' + codePoint.toString(8);
  6895. case 'singleEscape':
  6896. switch (codePoint) {
  6897. case 0x0008:
  6898. return '\\b';
  6899. case 0x0009:
  6900. return '\\t';
  6901. case 0x000A:
  6902. return '\\n';
  6903. case 0x000B:
  6904. return '\\v';
  6905. case 0x000C:
  6906. return '\\f';
  6907. case 0x000D:
  6908. return '\\r';
  6909. default:
  6910. throw Error('Invalid codepoint: ' + codePoint);
  6911. }
  6912. case 'symbol':
  6913. return fromCodePoint(codePoint);
  6914. case 'unicodeEscape':
  6915. return '\\u' + ('0000' + codePoint.toString(16).toUpperCase()).slice(-4);
  6916. case 'unicodeCodePointEscape':
  6917. return '\\u{' + codePoint.toString(16).toUpperCase() + '}';
  6918. default:
  6919. throw Error('Unsupported node kind: ' + kind);
  6920. }
  6921. }
  6922. /*--------------------------------------------------------------------------*/
  6923. // Used to generate strings for each node type.
  6924. var generators = {
  6925. 'alternative': generateAlternative,
  6926. 'anchor': generateAnchor,
  6927. 'characterClass': generateCharacterClass,
  6928. 'characterClassEscape': generateCharacterClassEscape,
  6929. 'characterClassRange': generateCharacterClassRange,
  6930. 'unicodePropertyEscape': generateUnicodePropertyEscape,
  6931. 'disjunction': generateDisjunction,
  6932. 'dot': generateDot,
  6933. 'group': generateGroup,
  6934. 'quantifier': generateQuantifier,
  6935. 'reference': generateReference,
  6936. 'value': generateValue
  6937. };
  6938. /*--------------------------------------------------------------------------*/
  6939. // Export regjsgen.
  6940. // Some AMD build optimizers, like r.js, check for condition patterns like the following:
  6941. if (typeof undefined == 'function' && typeof undefined.amd == 'object' && undefined.amd) {
  6942. // Define as an anonymous module so it can be aliased through path mapping.
  6943. undefined(function() {
  6944. return {
  6945. 'generate': generate
  6946. };
  6947. });
  6948. }
  6949. // Check for `exports` after `define` in case a build optimizer adds an `exports` object.
  6950. else if (freeExports && freeModule) {
  6951. // Export for CommonJS support.
  6952. freeExports.generate = generate;
  6953. }
  6954. else {
  6955. // Export to the global object.
  6956. root.regjsgen = {
  6957. 'generate': generate
  6958. };
  6959. }
  6960. }.call(commonjsGlobal));
  6961. });
  6962. var parser = createCommonjsModule(function (module) {
  6963. // regjsparser
  6964. //
  6965. // ==================================================================
  6966. //
  6967. // See ECMA-262 Standard: 15.10.1
  6968. //
  6969. // NOTE: The ECMA-262 standard uses the term "Assertion" for /^/. Here the
  6970. // term "Anchor" is used.
  6971. //
  6972. // Pattern ::
  6973. // Disjunction
  6974. //
  6975. // Disjunction ::
  6976. // Alternative
  6977. // Alternative | Disjunction
  6978. //
  6979. // Alternative ::
  6980. // [empty]
  6981. // Alternative Term
  6982. //
  6983. // Term ::
  6984. // Anchor
  6985. // Atom
  6986. // Atom Quantifier
  6987. //
  6988. // Anchor ::
  6989. // ^
  6990. // $
  6991. // \ b
  6992. // \ B
  6993. // ( ? = Disjunction )
  6994. // ( ? ! Disjunction )
  6995. //
  6996. // Quantifier ::
  6997. // QuantifierPrefix
  6998. // QuantifierPrefix ?
  6999. //
  7000. // QuantifierPrefix ::
  7001. // *
  7002. // +
  7003. // ?
  7004. // { DecimalDigits }
  7005. // { DecimalDigits , }
  7006. // { DecimalDigits , DecimalDigits }
  7007. //
  7008. // Atom ::
  7009. // PatternCharacter
  7010. // .
  7011. // \ AtomEscape
  7012. // CharacterClass
  7013. // ( Disjunction )
  7014. // ( ? : Disjunction )
  7015. //
  7016. // PatternCharacter ::
  7017. // SourceCharacter but not any of: ^ $ \ . * + ? ( ) [ ] { } |
  7018. //
  7019. // AtomEscape ::
  7020. // DecimalEscape
  7021. // CharacterEscape
  7022. // CharacterClassEscape
  7023. //
  7024. // CharacterEscape[U] ::
  7025. // ControlEscape
  7026. // c ControlLetter
  7027. // HexEscapeSequence
  7028. // RegExpUnicodeEscapeSequence[?U] (ES6)
  7029. // IdentityEscape[?U]
  7030. //
  7031. // ControlEscape ::
  7032. // one of f n r t v
  7033. // ControlLetter ::
  7034. // one of
  7035. // a b c d e f g h i j k l m n o p q r s t u v w x y z
  7036. // A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
  7037. //
  7038. // IdentityEscape ::
  7039. // SourceCharacter but not IdentifierPart
  7040. // <ZWJ>
  7041. // <ZWNJ>
  7042. //
  7043. // DecimalEscape ::
  7044. // DecimalIntegerLiteral [lookahead ∉ DecimalDigit]
  7045. //
  7046. // CharacterClassEscape ::
  7047. // one of d D s S w W
  7048. //
  7049. // CharacterClass ::
  7050. // [ [lookahead ∉ {^}] ClassRanges ]
  7051. // [ ^ ClassRanges ]
  7052. //
  7053. // ClassRanges ::
  7054. // [empty]
  7055. // NonemptyClassRanges
  7056. //
  7057. // NonemptyClassRanges ::
  7058. // ClassAtom
  7059. // ClassAtom NonemptyClassRangesNoDash
  7060. // ClassAtom - ClassAtom ClassRanges
  7061. //
  7062. // NonemptyClassRangesNoDash ::
  7063. // ClassAtom
  7064. // ClassAtomNoDash NonemptyClassRangesNoDash
  7065. // ClassAtomNoDash - ClassAtom ClassRanges
  7066. //
  7067. // ClassAtom ::
  7068. // -
  7069. // ClassAtomNoDash
  7070. //
  7071. // ClassAtomNoDash ::
  7072. // SourceCharacter but not one of \ or ] or -
  7073. // \ ClassEscape
  7074. //
  7075. // ClassEscape ::
  7076. // DecimalEscape
  7077. // b
  7078. // CharacterEscape
  7079. // CharacterClassEscape
  7080. (function() {
  7081. function parse(str, flags, features) {
  7082. if (!features) {
  7083. features = {};
  7084. }
  7085. function addRaw(node) {
  7086. node.raw = str.substring(node.range[0], node.range[1]);
  7087. return node;
  7088. }
  7089. function updateRawStart(node, start) {
  7090. node.range[0] = start;
  7091. return addRaw(node);
  7092. }
  7093. function createAnchor(kind, rawLength) {
  7094. return addRaw({
  7095. type: 'anchor',
  7096. kind: kind,
  7097. range: [
  7098. pos - rawLength,
  7099. pos
  7100. ]
  7101. });
  7102. }
  7103. function createValue(kind, codePoint, from, to) {
  7104. return addRaw({
  7105. type: 'value',
  7106. kind: kind,
  7107. codePoint: codePoint,
  7108. range: [from, to]
  7109. });
  7110. }
  7111. function createEscaped(kind, codePoint, value, fromOffset) {
  7112. fromOffset = fromOffset || 0;
  7113. return createValue(kind, codePoint, pos - (value.length + fromOffset), pos);
  7114. }
  7115. function createCharacter(matches) {
  7116. var _char = matches[0];
  7117. var first = _char.charCodeAt(0);
  7118. if (hasUnicodeFlag) {
  7119. var second;
  7120. if (_char.length === 1 && first >= 0xD800 && first <= 0xDBFF) {
  7121. second = lookahead().charCodeAt(0);
  7122. if (second >= 0xDC00 && second <= 0xDFFF) {
  7123. // Unicode surrogate pair
  7124. pos++;
  7125. return createValue(
  7126. 'symbol',
  7127. (first - 0xD800) * 0x400 + second - 0xDC00 + 0x10000,
  7128. pos - 2, pos);
  7129. }
  7130. }
  7131. }
  7132. return createValue('symbol', first, pos - 1, pos);
  7133. }
  7134. function createDisjunction(alternatives, from, to) {
  7135. return addRaw({
  7136. type: 'disjunction',
  7137. body: alternatives,
  7138. range: [
  7139. from,
  7140. to
  7141. ]
  7142. });
  7143. }
  7144. function createDot() {
  7145. return addRaw({
  7146. type: 'dot',
  7147. range: [
  7148. pos - 1,
  7149. pos
  7150. ]
  7151. });
  7152. }
  7153. function createCharacterClassEscape(value) {
  7154. return addRaw({
  7155. type: 'characterClassEscape',
  7156. value: value,
  7157. range: [
  7158. pos - 2,
  7159. pos
  7160. ]
  7161. });
  7162. }
  7163. function createReference(matchIndex) {
  7164. return addRaw({
  7165. type: 'reference',
  7166. matchIndex: parseInt(matchIndex, 10),
  7167. range: [
  7168. pos - 1 - matchIndex.length,
  7169. pos
  7170. ]
  7171. });
  7172. }
  7173. function createGroup(behavior, disjunction, from, to) {
  7174. return addRaw({
  7175. type: 'group',
  7176. behavior: behavior,
  7177. body: disjunction,
  7178. range: [
  7179. from,
  7180. to
  7181. ]
  7182. });
  7183. }
  7184. function createQuantifier(min, max, from, to) {
  7185. if (to == null) {
  7186. from = pos - 1;
  7187. to = pos;
  7188. }
  7189. return addRaw({
  7190. type: 'quantifier',
  7191. min: min,
  7192. max: max,
  7193. greedy: true,
  7194. body: null, // set later on
  7195. range: [
  7196. from,
  7197. to
  7198. ]
  7199. });
  7200. }
  7201. function createAlternative(terms, from, to) {
  7202. return addRaw({
  7203. type: 'alternative',
  7204. body: terms,
  7205. range: [
  7206. from,
  7207. to
  7208. ]
  7209. });
  7210. }
  7211. function createCharacterClass(classRanges, negative, from, to) {
  7212. return addRaw({
  7213. type: 'characterClass',
  7214. body: classRanges,
  7215. negative: negative,
  7216. range: [
  7217. from,
  7218. to
  7219. ]
  7220. });
  7221. }
  7222. function createClassRange(min, max, from, to) {
  7223. // See 15.10.2.15:
  7224. if (min.codePoint > max.codePoint) {
  7225. bail('invalid range in character class', min.raw + '-' + max.raw, from, to);
  7226. }
  7227. return addRaw({
  7228. type: 'characterClassRange',
  7229. min: min,
  7230. max: max,
  7231. range: [
  7232. from,
  7233. to
  7234. ]
  7235. });
  7236. }
  7237. function flattenBody(body) {
  7238. if (body.type === 'alternative') {
  7239. return body.body;
  7240. } else {
  7241. return [body];
  7242. }
  7243. }
  7244. function incr(amount) {
  7245. amount = (amount || 1);
  7246. var res = str.substring(pos, pos + amount);
  7247. pos += (amount || 1);
  7248. return res;
  7249. }
  7250. function skip(value) {
  7251. if (!match(value)) {
  7252. bail('character', value);
  7253. }
  7254. }
  7255. function match(value) {
  7256. if (str.indexOf(value, pos) === pos) {
  7257. return incr(value.length);
  7258. }
  7259. }
  7260. function lookahead() {
  7261. return str[pos];
  7262. }
  7263. function current(value) {
  7264. return str.indexOf(value, pos) === pos;
  7265. }
  7266. function next(value) {
  7267. return str[pos + 1] === value;
  7268. }
  7269. function matchReg(regExp) {
  7270. var subStr = str.substring(pos);
  7271. var res = subStr.match(regExp);
  7272. if (res) {
  7273. res.range = [];
  7274. res.range[0] = pos;
  7275. incr(res[0].length);
  7276. res.range[1] = pos;
  7277. }
  7278. return res;
  7279. }
  7280. function parseDisjunction() {
  7281. // Disjunction ::
  7282. // Alternative
  7283. // Alternative | Disjunction
  7284. var res = [], from = pos;
  7285. res.push(parseAlternative());
  7286. while (match('|')) {
  7287. res.push(parseAlternative());
  7288. }
  7289. if (res.length === 1) {
  7290. return res[0];
  7291. }
  7292. return createDisjunction(res, from, pos);
  7293. }
  7294. function parseAlternative() {
  7295. var res = [], from = pos;
  7296. var term;
  7297. // Alternative ::
  7298. // [empty]
  7299. // Alternative Term
  7300. while (term = parseTerm()) {
  7301. res.push(term);
  7302. }
  7303. if (res.length === 1) {
  7304. return res[0];
  7305. }
  7306. return createAlternative(res, from, pos);
  7307. }
  7308. function parseTerm() {
  7309. // Term ::
  7310. // Anchor
  7311. // Atom
  7312. // Atom Quantifier
  7313. if (pos >= str.length || current('|') || current(')')) {
  7314. return null; /* Means: The term is empty */
  7315. }
  7316. var anchor = parseAnchor();
  7317. if (anchor) {
  7318. return anchor;
  7319. }
  7320. var atom = parseAtom();
  7321. if (!atom) {
  7322. bail('Expected atom');
  7323. }
  7324. var quantifier = parseQuantifier() || false;
  7325. if (quantifier) {
  7326. quantifier.body = flattenBody(atom);
  7327. // The quantifier contains the atom. Therefore, the beginning of the
  7328. // quantifier range is given by the beginning of the atom.
  7329. updateRawStart(quantifier, atom.range[0]);
  7330. return quantifier;
  7331. }
  7332. return atom;
  7333. }
  7334. function parseGroup(matchA, typeA, matchB, typeB) {
  7335. var type = null, from = pos;
  7336. if (match(matchA)) {
  7337. type = typeA;
  7338. } else if (match(matchB)) {
  7339. type = typeB;
  7340. } else {
  7341. return false;
  7342. }
  7343. var body = parseDisjunction();
  7344. if (!body) {
  7345. bail('Expected disjunction');
  7346. }
  7347. skip(')');
  7348. var group = createGroup(type, flattenBody(body), from, pos);
  7349. if (type == 'normal') {
  7350. // Keep track of the number of closed groups. This is required for
  7351. // parseDecimalEscape(). In case the string is parsed a second time the
  7352. // value already holds the total count and no incrementation is required.
  7353. if (firstIteration) {
  7354. closedCaptureCounter++;
  7355. }
  7356. }
  7357. return group;
  7358. }
  7359. function parseAnchor() {
  7360. // Anchor ::
  7361. // ^
  7362. // $
  7363. // \ b
  7364. // \ B
  7365. // ( ? = Disjunction )
  7366. // ( ? ! Disjunction )
  7367. if (match('^')) {
  7368. return createAnchor('start', 1 /* rawLength */);
  7369. } else if (match('$')) {
  7370. return createAnchor('end', 1 /* rawLength */);
  7371. } else if (match('\\b')) {
  7372. return createAnchor('boundary', 2 /* rawLength */);
  7373. } else if (match('\\B')) {
  7374. return createAnchor('not-boundary', 2 /* rawLength */);
  7375. } else {
  7376. return parseGroup('(?=', 'lookahead', '(?!', 'negativeLookahead');
  7377. }
  7378. }
  7379. function parseQuantifier() {
  7380. // Quantifier ::
  7381. // QuantifierPrefix
  7382. // QuantifierPrefix ?
  7383. //
  7384. // QuantifierPrefix ::
  7385. // *
  7386. // +
  7387. // ?
  7388. // { DecimalDigits }
  7389. // { DecimalDigits , }
  7390. // { DecimalDigits , DecimalDigits }
  7391. var res, from = pos;
  7392. var quantifier;
  7393. var min, max;
  7394. if (match('*')) {
  7395. quantifier = createQuantifier(0);
  7396. }
  7397. else if (match('+')) {
  7398. quantifier = createQuantifier(1);
  7399. }
  7400. else if (match('?')) {
  7401. quantifier = createQuantifier(0, 1);
  7402. }
  7403. else if (res = matchReg(/^\{([0-9]+)\}/)) {
  7404. min = parseInt(res[1], 10);
  7405. quantifier = createQuantifier(min, min, res.range[0], res.range[1]);
  7406. }
  7407. else if (res = matchReg(/^\{([0-9]+),\}/)) {
  7408. min = parseInt(res[1], 10);
  7409. quantifier = createQuantifier(min, undefined, res.range[0], res.range[1]);
  7410. }
  7411. else if (res = matchReg(/^\{([0-9]+),([0-9]+)\}/)) {
  7412. min = parseInt(res[1], 10);
  7413. max = parseInt(res[2], 10);
  7414. if (min > max) {
  7415. bail('numbers out of order in {} quantifier', '', from, pos);
  7416. }
  7417. quantifier = createQuantifier(min, max, res.range[0], res.range[1]);
  7418. }
  7419. if (quantifier) {
  7420. if (match('?')) {
  7421. quantifier.greedy = false;
  7422. quantifier.range[1] += 1;
  7423. }
  7424. }
  7425. return quantifier;
  7426. }
  7427. function parseAtom() {
  7428. // Atom ::
  7429. // PatternCharacter
  7430. // .
  7431. // \ AtomEscape
  7432. // CharacterClass
  7433. // ( Disjunction )
  7434. // ( ? : Disjunction )
  7435. var res;
  7436. // jviereck: allow ']', '}' here as well to be compatible with browser's
  7437. // implementations: ']'.match(/]/);
  7438. // if (res = matchReg(/^[^^$\\.*+?()[\]{}|]/)) {
  7439. if (res = matchReg(/^[^^$\\.*+?(){[|]/)) {
  7440. // PatternCharacter
  7441. return createCharacter(res);
  7442. }
  7443. else if (match('.')) {
  7444. // .
  7445. return createDot();
  7446. }
  7447. else if (match('\\')) {
  7448. // \ AtomEscape
  7449. res = parseAtomEscape();
  7450. if (!res) {
  7451. bail('atomEscape');
  7452. }
  7453. return res;
  7454. }
  7455. else if (res = parseCharacterClass()) {
  7456. return res;
  7457. }
  7458. else {
  7459. // ( Disjunction )
  7460. // ( ? : Disjunction )
  7461. return parseGroup('(?:', 'ignore', '(', 'normal');
  7462. }
  7463. }
  7464. function parseUnicodeSurrogatePairEscape(firstEscape) {
  7465. if (hasUnicodeFlag) {
  7466. var first, second;
  7467. if (firstEscape.kind == 'unicodeEscape' &&
  7468. (first = firstEscape.codePoint) >= 0xD800 && first <= 0xDBFF &&
  7469. current('\\') && next('u') ) {
  7470. var prevPos = pos;
  7471. pos++;
  7472. var secondEscape = parseClassEscape();
  7473. if (secondEscape.kind == 'unicodeEscape' &&
  7474. (second = secondEscape.codePoint) >= 0xDC00 && second <= 0xDFFF) {
  7475. // Unicode surrogate pair
  7476. firstEscape.range[1] = secondEscape.range[1];
  7477. firstEscape.codePoint = (first - 0xD800) * 0x400 + second - 0xDC00 + 0x10000;
  7478. firstEscape.type = 'value';
  7479. firstEscape.kind = 'unicodeCodePointEscape';
  7480. addRaw(firstEscape);
  7481. }
  7482. else {
  7483. pos = prevPos;
  7484. }
  7485. }
  7486. }
  7487. return firstEscape;
  7488. }
  7489. function parseClassEscape() {
  7490. return parseAtomEscape(true);
  7491. }
  7492. function parseAtomEscape(insideCharacterClass) {
  7493. // AtomEscape ::
  7494. // DecimalEscape
  7495. // CharacterEscape
  7496. // CharacterClassEscape
  7497. var res, from = pos;
  7498. res = parseDecimalEscape();
  7499. if (res) {
  7500. return res;
  7501. }
  7502. // For ClassEscape
  7503. if (insideCharacterClass) {
  7504. if (match('b')) {
  7505. // 15.10.2.19
  7506. // The production ClassEscape :: b evaluates by returning the
  7507. // CharSet containing the one character <BS> (Unicode value 0008).
  7508. return createEscaped('singleEscape', 0x0008, '\\b');
  7509. } else if (match('B')) {
  7510. bail('\\B not possible inside of CharacterClass', '', from);
  7511. }
  7512. }
  7513. res = parseCharacterEscape();
  7514. return res;
  7515. }
  7516. function parseDecimalEscape() {
  7517. // DecimalEscape ::
  7518. // DecimalIntegerLiteral [lookahead ∉ DecimalDigit]
  7519. // CharacterClassEscape :: one of d D s S w W
  7520. var res, match;
  7521. if (res = matchReg(/^(?!0)\d+/)) {
  7522. match = res[0];
  7523. var refIdx = parseInt(res[0], 10);
  7524. if (refIdx <= closedCaptureCounter) {
  7525. // If the number is smaller than the normal-groups found so
  7526. // far, then it is a reference...
  7527. return createReference(res[0]);
  7528. } else {
  7529. // ... otherwise it needs to be interpreted as a octal (if the
  7530. // number is in an octal format). If it is NOT octal format,
  7531. // then the slash is ignored and the number is matched later
  7532. // as normal characters.
  7533. // Recall the negative decision to decide if the input must be parsed
  7534. // a second time with the total normal-groups.
  7535. backrefDenied.push(refIdx);
  7536. // Reset the position again, as maybe only parts of the previous
  7537. // matched numbers are actual octal numbers. E.g. in '019' only
  7538. // the '01' should be matched.
  7539. incr(-res[0].length);
  7540. if (res = matchReg(/^[0-7]{1,3}/)) {
  7541. return createEscaped('octal', parseInt(res[0], 8), res[0], 1);
  7542. } else {
  7543. // If we end up here, we have a case like /\91/. Then the
  7544. // first slash is to be ignored and the 9 & 1 to be treated
  7545. // like ordinary characters. Create a character for the
  7546. // first number only here - other number-characters
  7547. // (if available) will be matched later.
  7548. res = createCharacter(matchReg(/^[89]/));
  7549. return updateRawStart(res, res.range[0] - 1);
  7550. }
  7551. }
  7552. }
  7553. // Only allow octal numbers in the following. All matched numbers start
  7554. // with a zero (if the do not, the previous if-branch is executed).
  7555. // If the number is not octal format and starts with zero (e.g. `091`)
  7556. // then only the zeros `0` is treated here and the `91` are ordinary
  7557. // characters.
  7558. // Example:
  7559. // /\091/.exec('\091')[0].length === 3
  7560. else if (res = matchReg(/^[0-7]{1,3}/)) {
  7561. match = res[0];
  7562. if (/^0{1,3}$/.test(match)) {
  7563. // If they are all zeros, then only take the first one.
  7564. return createEscaped('null', 0x0000, '0', match.length + 1);
  7565. } else {
  7566. return createEscaped('octal', parseInt(match, 8), match, 1);
  7567. }
  7568. } else if (res = matchReg(/^[dDsSwW]/)) {
  7569. return createCharacterClassEscape(res[0]);
  7570. }
  7571. return false;
  7572. }
  7573. function parseCharacterEscape() {
  7574. // CharacterEscape ::
  7575. // ControlEscape
  7576. // c ControlLetter
  7577. // HexEscapeSequence
  7578. // UnicodeEscapeSequence
  7579. // IdentityEscape
  7580. var res;
  7581. if (res = matchReg(/^[fnrtv]/)) {
  7582. // ControlEscape
  7583. var codePoint = 0;
  7584. switch (res[0]) {
  7585. case 't': codePoint = 0x009; break;
  7586. case 'n': codePoint = 0x00A; break;
  7587. case 'v': codePoint = 0x00B; break;
  7588. case 'f': codePoint = 0x00C; break;
  7589. case 'r': codePoint = 0x00D; break;
  7590. }
  7591. return createEscaped('singleEscape', codePoint, '\\' + res[0]);
  7592. } else if (res = matchReg(/^c([a-zA-Z])/)) {
  7593. // c ControlLetter
  7594. return createEscaped('controlLetter', res[1].charCodeAt(0) % 32, res[1], 2);
  7595. } else if (res = matchReg(/^x([0-9a-fA-F]{2})/)) {
  7596. // HexEscapeSequence
  7597. return createEscaped('hexadecimalEscape', parseInt(res[1], 16), res[1], 2);
  7598. } else if (res = matchReg(/^u([0-9a-fA-F]{4})/)) {
  7599. // UnicodeEscapeSequence
  7600. return parseUnicodeSurrogatePairEscape(
  7601. createEscaped('unicodeEscape', parseInt(res[1], 16), res[1], 2)
  7602. );
  7603. } else if (hasUnicodeFlag && (res = matchReg(/^u\{([0-9a-fA-F]+)\}/))) {
  7604. // RegExpUnicodeEscapeSequence (ES6 Unicode code point escape)
  7605. return createEscaped('unicodeCodePointEscape', parseInt(res[1], 16), res[1], 4);
  7606. } else if (features.unicodePropertyEscape && hasUnicodeFlag && (res = matchReg(/^([pP])\{([^\}]+)\}/))) {
  7607. // https://github.com/jviereck/regjsparser/issues/77
  7608. return addRaw({
  7609. type: 'unicodePropertyEscape',
  7610. negative: res[1] === 'P',
  7611. value: res[2],
  7612. range: [res.range[0] - 1, res.range[1]],
  7613. raw: res[0]
  7614. });
  7615. } else {
  7616. // IdentityEscape
  7617. return parseIdentityEscape();
  7618. }
  7619. }
  7620. // Taken from the Esprima parser.
  7621. function isIdentifierPart(ch) {
  7622. // Generated by `tools/generate-identifier-regex.js`.
  7623. var NonAsciiIdentifierPart = new RegExp('[\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0300-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u0483-\u0487\u048A-\u052F\u0531-\u0556\u0559\u0561-\u0587\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u05D0-\u05EA\u05F0-\u05F2\u0610-\u061A\u0620-\u0669\u066E-\u06D3\u06D5-\u06DC\u06DF-\u06E8\u06EA-\u06FC\u06FF\u0710-\u074A\u074D-\u07B1\u07C0-\u07F5\u07FA\u0800-\u082D\u0840-\u085B\u08A0-\u08B2\u08E4-\u0963\u0966-\u096F\u0971-\u0983\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BC-\u09C4\u09C7\u09C8\u09CB-\u09CE\u09D7\u09DC\u09DD\u09DF-\u09E3\u09E6-\u09F1\u0A01-\u0A03\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A59-\u0A5C\u0A5E\u0A66-\u0A75\u0A81-\u0A83\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABC-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AD0\u0AE0-\u0AE3\u0AE6-\u0AEF\u0B01-\u0B03\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3C-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B5C\u0B5D\u0B5F-\u0B63\u0B66-\u0B6F\u0B71\u0B82\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD0\u0BD7\u0BE6-\u0BEF\u0C00-\u0C03\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C58\u0C59\u0C60-\u0C63\u0C66-\u0C6F\u0C81-\u0C83\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBC-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CDE\u0CE0-\u0CE3\u0CE6-\u0CEF\u0CF1\u0CF2\u0D01-\u0D03\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D-\u0D44\u0D46-\u0D48\u0D4A-\u0D4E\u0D57\u0D60-\u0D63\u0D66-\u0D6F\u0D7A-\u0D7F\u0D82\u0D83\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DE6-\u0DEF\u0DF2\u0DF3\u0E01-\u0E3A\u0E40-\u0E4E\u0E50-\u0E59\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB9\u0EBB-\u0EBD\u0EC0-\u0EC4\u0EC6\u0EC8-\u0ECD\u0ED0-\u0ED9\u0EDC-\u0EDF\u0F00\u0F18\u0F19\u0F20-\u0F29\u0F35\u0F37\u0F39\u0F3E-\u0F47\u0F49-\u0F6C\u0F71-\u0F84\u0F86-\u0F97\u0F99-\u0FBC\u0FC6\u1000-\u1049\u1050-\u109D\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\u135D-\u135F\u1380-\u138F\u13A0-\u13F4\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u170C\u170E-\u1714\u1720-\u1734\u1740-\u1753\u1760-\u176C\u176E-\u1770\u1772\u1773\u1780-\u17D3\u17D7\u17DC\u17DD\u17E0-\u17E9\u180B-\u180D\u1810-\u1819\u1820-\u1877\u1880-\u18AA\u18B0-\u18F5\u1900-\u191E\u1920-\u192B\u1930-\u193B\u1946-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u19D0-\u19D9\u1A00-\u1A1B\u1A20-\u1A5E\u1A60-\u1A7C\u1A7F-\u1A89\u1A90-\u1A99\u1AA7\u1AB0-\u1ABD\u1B00-\u1B4B\u1B50-\u1B59\u1B6B-\u1B73\u1B80-\u1BF3\u1C00-\u1C37\u1C40-\u1C49\u1C4D-\u1C7D\u1CD0-\u1CD2\u1CD4-\u1CF6\u1CF8\u1CF9\u1D00-\u1DF5\u1DFC-\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\u200C\u200D\u203F\u2040\u2054\u2071\u207F\u2090-\u209C\u20D0-\u20DC\u20E1\u20E5-\u20F0\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2160-\u2188\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D7F-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2DE0-\u2DFF\u2E2F\u3005-\u3007\u3021-\u302F\u3031-\u3035\u3038-\u303C\u3041-\u3096\u3099\u309A\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312D\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FCC\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA62B\uA640-\uA66F\uA674-\uA67D\uA67F-\uA69D\uA69F-\uA6F1\uA717-\uA71F\uA722-\uA788\uA78B-\uA78E\uA790-\uA7AD\uA7B0\uA7B1\uA7F7-\uA827\uA840-\uA873\uA880-\uA8C4\uA8D0-\uA8D9\uA8E0-\uA8F7\uA8FB\uA900-\uA92D\uA930-\uA953\uA960-\uA97C\uA980-\uA9C0\uA9CF-\uA9D9\uA9E0-\uA9FE\uAA00-\uAA36\uAA40-\uAA4D\uAA50-\uAA59\uAA60-\uAA76\uAA7A-\uAAC2\uAADB-\uAADD\uAAE0-\uAAEF\uAAF2-\uAAF6\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB5F\uAB64\uAB65\uABC0-\uABEA\uABEC\uABED\uABF0-\uABF9\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE00-\uFE0F\uFE20-\uFE2D\uFE33\uFE34\uFE4D-\uFE4F\uFE70-\uFE74\uFE76-\uFEFC\uFF10-\uFF19\uFF21-\uFF3A\uFF3F\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]');
  7624. return (ch === 36) || (ch === 95) || // $ (dollar) and _ (underscore)
  7625. (ch >= 65 && ch <= 90) || // A..Z
  7626. (ch >= 97 && ch <= 122) || // a..z
  7627. (ch >= 48 && ch <= 57) || // 0..9
  7628. (ch === 92) || // \ (backslash)
  7629. ((ch >= 0x80) && NonAsciiIdentifierPart.test(String.fromCharCode(ch)));
  7630. }
  7631. function parseIdentityEscape() {
  7632. // IdentityEscape ::
  7633. // SourceCharacter but not IdentifierPart
  7634. // <ZWJ>
  7635. // <ZWNJ>
  7636. var ZWJ = '\u200C';
  7637. var ZWNJ = '\u200D';
  7638. var tmp;
  7639. if (!isIdentifierPart(lookahead())) {
  7640. tmp = incr();
  7641. return createEscaped('identifier', tmp.charCodeAt(0), tmp, 1);
  7642. }
  7643. if (match(ZWJ)) {
  7644. // <ZWJ>
  7645. return createEscaped('identifier', 0x200C, ZWJ);
  7646. } else if (match(ZWNJ)) {
  7647. // <ZWNJ>
  7648. return createEscaped('identifier', 0x200D, ZWNJ);
  7649. }
  7650. return null;
  7651. }
  7652. function parseCharacterClass() {
  7653. // CharacterClass ::
  7654. // [ [lookahead ∉ {^}] ClassRanges ]
  7655. // [ ^ ClassRanges ]
  7656. var res, from = pos;
  7657. if (res = matchReg(/^\[\^/)) {
  7658. res = parseClassRanges();
  7659. skip(']');
  7660. return createCharacterClass(res, true, from, pos);
  7661. } else if (match('[')) {
  7662. res = parseClassRanges();
  7663. skip(']');
  7664. return createCharacterClass(res, false, from, pos);
  7665. }
  7666. return null;
  7667. }
  7668. function parseClassRanges() {
  7669. // ClassRanges ::
  7670. // [empty]
  7671. // NonemptyClassRanges
  7672. var res;
  7673. if (current(']')) {
  7674. // Empty array means nothing insinde of the ClassRange.
  7675. return [];
  7676. } else {
  7677. res = parseNonemptyClassRanges();
  7678. if (!res) {
  7679. bail('nonEmptyClassRanges');
  7680. }
  7681. return res;
  7682. }
  7683. }
  7684. function parseHelperClassRanges(atom) {
  7685. var from, to, res;
  7686. if (current('-') && !next(']')) {
  7687. // ClassAtom - ClassAtom ClassRanges
  7688. skip('-');
  7689. res = parseClassAtom();
  7690. if (!res) {
  7691. bail('classAtom');
  7692. }
  7693. to = pos;
  7694. var classRanges = parseClassRanges();
  7695. if (!classRanges) {
  7696. bail('classRanges');
  7697. }
  7698. from = atom.range[0];
  7699. if (classRanges.type === 'empty') {
  7700. return [createClassRange(atom, res, from, to)];
  7701. }
  7702. return [createClassRange(atom, res, from, to)].concat(classRanges);
  7703. }
  7704. res = parseNonemptyClassRangesNoDash();
  7705. if (!res) {
  7706. bail('nonEmptyClassRangesNoDash');
  7707. }
  7708. return [atom].concat(res);
  7709. }
  7710. function parseNonemptyClassRanges() {
  7711. // NonemptyClassRanges ::
  7712. // ClassAtom
  7713. // ClassAtom NonemptyClassRangesNoDash
  7714. // ClassAtom - ClassAtom ClassRanges
  7715. var atom = parseClassAtom();
  7716. if (!atom) {
  7717. bail('classAtom');
  7718. }
  7719. if (current(']')) {
  7720. // ClassAtom
  7721. return [atom];
  7722. }
  7723. // ClassAtom NonemptyClassRangesNoDash
  7724. // ClassAtom - ClassAtom ClassRanges
  7725. return parseHelperClassRanges(atom);
  7726. }
  7727. function parseNonemptyClassRangesNoDash() {
  7728. // NonemptyClassRangesNoDash ::
  7729. // ClassAtom
  7730. // ClassAtomNoDash NonemptyClassRangesNoDash
  7731. // ClassAtomNoDash - ClassAtom ClassRanges
  7732. var res = parseClassAtom();
  7733. if (!res) {
  7734. bail('classAtom');
  7735. }
  7736. if (current(']')) {
  7737. // ClassAtom
  7738. return res;
  7739. }
  7740. // ClassAtomNoDash NonemptyClassRangesNoDash
  7741. // ClassAtomNoDash - ClassAtom ClassRanges
  7742. return parseHelperClassRanges(res);
  7743. }
  7744. function parseClassAtom() {
  7745. // ClassAtom ::
  7746. // -
  7747. // ClassAtomNoDash
  7748. if (match('-')) {
  7749. return createCharacter('-');
  7750. } else {
  7751. return parseClassAtomNoDash();
  7752. }
  7753. }
  7754. function parseClassAtomNoDash() {
  7755. // ClassAtomNoDash ::
  7756. // SourceCharacter but not one of \ or ] or -
  7757. // \ ClassEscape
  7758. var res;
  7759. if (res = matchReg(/^[^\\\]-]/)) {
  7760. return createCharacter(res[0]);
  7761. } else if (match('\\')) {
  7762. res = parseClassEscape();
  7763. if (!res) {
  7764. bail('classEscape');
  7765. }
  7766. return parseUnicodeSurrogatePairEscape(res);
  7767. }
  7768. }
  7769. function bail(message, details, from, to) {
  7770. from = from == null ? pos : from;
  7771. to = to == null ? from : to;
  7772. var contextStart = Math.max(0, from - 10);
  7773. var contextEnd = Math.min(to + 10, str.length);
  7774. // Output a bit of context and a line pointing to where our error is.
  7775. //
  7776. // We are assuming that there are no actual newlines in the content as this is a regular expression.
  7777. var context = ' ' + str.substring(contextStart, contextEnd);
  7778. var pointer = ' ' + new Array(from - contextStart + 1).join(' ') + '^';
  7779. throw SyntaxError(message + ' at position ' + from + (details ? ': ' + details : '') + '\n' + context + '\n' + pointer);
  7780. }
  7781. var backrefDenied = [];
  7782. var closedCaptureCounter = 0;
  7783. var firstIteration = true;
  7784. var hasUnicodeFlag = (flags || "").indexOf("u") !== -1;
  7785. var pos = 0;
  7786. // Convert the input to a string and treat the empty string special.
  7787. str = String(str);
  7788. if (str === '') {
  7789. str = '(?:)';
  7790. }
  7791. var result = parseDisjunction();
  7792. if (result.range[1] !== str.length) {
  7793. bail('Could not parse entire input - got stuck', '', result.range[1]);
  7794. }
  7795. // The spec requires to interpret the `\2` in `/\2()()/` as backreference.
  7796. // As the parser collects the number of capture groups as the string is
  7797. // parsed it is impossible to make these decisions at the point when the
  7798. // `\2` is handled. In case the local decision turns out to be wrong after
  7799. // the parsing has finished, the input string is parsed a second time with
  7800. // the total number of capture groups set.
  7801. //
  7802. // SEE: https://github.com/jviereck/regjsparser/issues/70
  7803. for (var i = 0; i < backrefDenied.length; i++) {
  7804. if (backrefDenied[i] <= closedCaptureCounter) {
  7805. // Parse the input a second time.
  7806. pos = 0;
  7807. firstIteration = false;
  7808. return parseDisjunction();
  7809. }
  7810. }
  7811. return result;
  7812. }
  7813. var regjsparser = {
  7814. parse: parse
  7815. };
  7816. if ('object' !== 'undefined' && module.exports) {
  7817. module.exports = regjsparser;
  7818. } else {
  7819. window.regjsparser = regjsparser;
  7820. }
  7821. }());
  7822. });
  7823. var regenerate = createCommonjsModule(function (module, exports) {
  7824. /*! https://mths.be/regenerate v1.3.3 by @mathias | MIT license */
  7825. (function(root) {
  7826. // Detect free variables `exports`.
  7827. var freeExports = 'object' == 'object' && exports;
  7828. // Detect free variable `module`.
  7829. var freeModule = 'object' == 'object' && module &&
  7830. module.exports == freeExports && module;
  7831. // Detect free variable `global`, from Node.js/io.js or Browserified code,
  7832. // and use it as `root`.
  7833. var freeGlobal = typeof commonjsGlobal == 'object' && commonjsGlobal;
  7834. if (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal) {
  7835. root = freeGlobal;
  7836. }
  7837. /*--------------------------------------------------------------------------*/
  7838. var ERRORS = {
  7839. 'rangeOrder': 'A range\u2019s `stop` value must be greater than or equal ' +
  7840. 'to the `start` value.',
  7841. 'codePointRange': 'Invalid code point value. Code points range from ' +
  7842. 'U+000000 to U+10FFFF.'
  7843. };
  7844. // https://mathiasbynens.be/notes/javascript-encoding#surrogate-pairs
  7845. var HIGH_SURROGATE_MIN = 0xD800;
  7846. var HIGH_SURROGATE_MAX = 0xDBFF;
  7847. var LOW_SURROGATE_MIN = 0xDC00;
  7848. var LOW_SURROGATE_MAX = 0xDFFF;
  7849. // In Regenerate output, `\0` is never preceded by `\` because we sort by
  7850. // code point value, so let’s keep this regular expression simple.
  7851. var regexNull = /\\x00([^0123456789]|$)/g;
  7852. var object = {};
  7853. var hasOwnProperty = object.hasOwnProperty;
  7854. var extend = function(destination, source) {
  7855. var key;
  7856. for (key in source) {
  7857. if (hasOwnProperty.call(source, key)) {
  7858. destination[key] = source[key];
  7859. }
  7860. }
  7861. return destination;
  7862. };
  7863. var forEach = function(array, callback) {
  7864. var index = -1;
  7865. var length = array.length;
  7866. while (++index < length) {
  7867. callback(array[index], index);
  7868. }
  7869. };
  7870. var toString = object.toString;
  7871. var isArray = function(value) {
  7872. return toString.call(value) == '[object Array]';
  7873. };
  7874. var isNumber = function(value) {
  7875. return typeof value == 'number' ||
  7876. toString.call(value) == '[object Number]';
  7877. };
  7878. // This assumes that `number` is a positive integer that `toString()`s nicely
  7879. // (which is the case for all code point values).
  7880. var zeroes = '0000';
  7881. var pad = function(number, totalCharacters) {
  7882. var string = String(number);
  7883. return string.length < totalCharacters
  7884. ? (zeroes + string).slice(-totalCharacters)
  7885. : string;
  7886. };
  7887. var hex = function(number) {
  7888. return Number(number).toString(16).toUpperCase();
  7889. };
  7890. var slice = [].slice;
  7891. /*--------------------------------------------------------------------------*/
  7892. var dataFromCodePoints = function(codePoints) {
  7893. var index = -1;
  7894. var length = codePoints.length;
  7895. var max = length - 1;
  7896. var result = [];
  7897. var isStart = true;
  7898. var tmp;
  7899. var previous = 0;
  7900. while (++index < length) {
  7901. tmp = codePoints[index];
  7902. if (isStart) {
  7903. result.push(tmp);
  7904. previous = tmp;
  7905. isStart = false;
  7906. } else {
  7907. if (tmp == previous + 1) {
  7908. if (index != max) {
  7909. previous = tmp;
  7910. continue;
  7911. } else {
  7912. isStart = true;
  7913. result.push(tmp + 1);
  7914. }
  7915. } else {
  7916. // End the previous range and start a new one.
  7917. result.push(previous + 1, tmp);
  7918. previous = tmp;
  7919. }
  7920. }
  7921. }
  7922. if (!isStart) {
  7923. result.push(tmp + 1);
  7924. }
  7925. return result;
  7926. };
  7927. var dataRemove = function(data, codePoint) {
  7928. // Iterate over the data per `(start, end)` pair.
  7929. var index = 0;
  7930. var start;
  7931. var end;
  7932. var length = data.length;
  7933. while (index < length) {
  7934. start = data[index];
  7935. end = data[index + 1];
  7936. if (codePoint >= start && codePoint < end) {
  7937. // Modify this pair.
  7938. if (codePoint == start) {
  7939. if (end == start + 1) {
  7940. // Just remove `start` and `end`.
  7941. data.splice(index, 2);
  7942. return data;
  7943. } else {
  7944. // Just replace `start` with a new value.
  7945. data[index] = codePoint + 1;
  7946. return data;
  7947. }
  7948. } else if (codePoint == end - 1) {
  7949. // Just replace `end` with a new value.
  7950. data[index + 1] = codePoint;
  7951. return data;
  7952. } else {
  7953. // Replace `[start, end]` with `[startA, endA, startB, endB]`.
  7954. data.splice(index, 2, start, codePoint, codePoint + 1, end);
  7955. return data;
  7956. }
  7957. }
  7958. index += 2;
  7959. }
  7960. return data;
  7961. };
  7962. var dataRemoveRange = function(data, rangeStart, rangeEnd) {
  7963. if (rangeEnd < rangeStart) {
  7964. throw Error(ERRORS.rangeOrder);
  7965. }
  7966. // Iterate over the data per `(start, end)` pair.
  7967. var index = 0;
  7968. var start;
  7969. var end;
  7970. while (index < data.length) {
  7971. start = data[index];
  7972. end = data[index + 1] - 1; // Note: the `- 1` makes `end` inclusive.
  7973. // Exit as soon as no more matching pairs can be found.
  7974. if (start > rangeEnd) {
  7975. return data;
  7976. }
  7977. // Check if this range pair is equal to, or forms a subset of, the range
  7978. // to be removed.
  7979. // E.g. we have `[0, 11, 40, 51]` and want to remove 0-10 → `[40, 51]`.
  7980. // E.g. we have `[40, 51]` and want to remove 0-100 → `[]`.
  7981. if (rangeStart <= start && rangeEnd >= end) {
  7982. // Remove this pair.
  7983. data.splice(index, 2);
  7984. continue;
  7985. }
  7986. // Check if both `rangeStart` and `rangeEnd` are within the bounds of
  7987. // this pair.
  7988. // E.g. we have `[0, 11]` and want to remove 4-6 → `[0, 4, 7, 11]`.
  7989. if (rangeStart >= start && rangeEnd < end) {
  7990. if (rangeStart == start) {
  7991. // Replace `[start, end]` with `[startB, endB]`.
  7992. data[index] = rangeEnd + 1;
  7993. data[index + 1] = end + 1;
  7994. return data;
  7995. }
  7996. // Replace `[start, end]` with `[startA, endA, startB, endB]`.
  7997. data.splice(index, 2, start, rangeStart, rangeEnd + 1, end + 1);
  7998. return data;
  7999. }
  8000. // Check if only `rangeStart` is within the bounds of this pair.
  8001. // E.g. we have `[0, 11]` and want to remove 4-20 → `[0, 4]`.
  8002. if (rangeStart >= start && rangeStart <= end) {
  8003. // Replace `end` with `rangeStart`.
  8004. data[index + 1] = rangeStart;
  8005. // Note: we cannot `return` just yet, in case any following pairs still
  8006. // contain matching code points.
  8007. // E.g. we have `[0, 11, 14, 31]` and want to remove 4-20
  8008. // → `[0, 4, 21, 31]`.
  8009. }
  8010. // Check if only `rangeEnd` is within the bounds of this pair.
  8011. // E.g. we have `[14, 31]` and want to remove 4-20 → `[21, 31]`.
  8012. else if (rangeEnd >= start && rangeEnd <= end) {
  8013. // Just replace `start`.
  8014. data[index] = rangeEnd + 1;
  8015. return data;
  8016. }
  8017. index += 2;
  8018. }
  8019. return data;
  8020. };
  8021. var dataAdd = function(data, codePoint) {
  8022. // Iterate over the data per `(start, end)` pair.
  8023. var index = 0;
  8024. var start;
  8025. var end;
  8026. var lastIndex = null;
  8027. var length = data.length;
  8028. if (codePoint < 0x0 || codePoint > 0x10FFFF) {
  8029. throw RangeError(ERRORS.codePointRange);
  8030. }
  8031. while (index < length) {
  8032. start = data[index];
  8033. end = data[index + 1];
  8034. // Check if the code point is already in the set.
  8035. if (codePoint >= start && codePoint < end) {
  8036. return data;
  8037. }
  8038. if (codePoint == start - 1) {
  8039. // Just replace `start` with a new value.
  8040. data[index] = codePoint;
  8041. return data;
  8042. }
  8043. // At this point, if `start` is `greater` than `codePoint`, insert a new
  8044. // `[start, end]` pair before the current pair, or after the current pair
  8045. // if there is a known `lastIndex`.
  8046. if (start > codePoint) {
  8047. data.splice(
  8048. lastIndex != null ? lastIndex + 2 : 0,
  8049. 0,
  8050. codePoint,
  8051. codePoint + 1
  8052. );
  8053. return data;
  8054. }
  8055. if (codePoint == end) {
  8056. // Check if adding this code point causes two separate ranges to become
  8057. // a single range, e.g. `dataAdd([0, 4, 5, 10], 4)` → `[0, 10]`.
  8058. if (codePoint + 1 == data[index + 2]) {
  8059. data.splice(index, 4, start, data[index + 3]);
  8060. return data;
  8061. }
  8062. // Else, just replace `end` with a new value.
  8063. data[index + 1] = codePoint + 1;
  8064. return data;
  8065. }
  8066. lastIndex = index;
  8067. index += 2;
  8068. }
  8069. // The loop has finished; add the new pair to the end of the data set.
  8070. data.push(codePoint, codePoint + 1);
  8071. return data;
  8072. };
  8073. var dataAddData = function(dataA, dataB) {
  8074. // Iterate over the data per `(start, end)` pair.
  8075. var index = 0;
  8076. var start;
  8077. var end;
  8078. var data = dataA.slice();
  8079. var length = dataB.length;
  8080. while (index < length) {
  8081. start = dataB[index];
  8082. end = dataB[index + 1] - 1;
  8083. if (start == end) {
  8084. data = dataAdd(data, start);
  8085. } else {
  8086. data = dataAddRange(data, start, end);
  8087. }
  8088. index += 2;
  8089. }
  8090. return data;
  8091. };
  8092. var dataRemoveData = function(dataA, dataB) {
  8093. // Iterate over the data per `(start, end)` pair.
  8094. var index = 0;
  8095. var start;
  8096. var end;
  8097. var data = dataA.slice();
  8098. var length = dataB.length;
  8099. while (index < length) {
  8100. start = dataB[index];
  8101. end = dataB[index + 1] - 1;
  8102. if (start == end) {
  8103. data = dataRemove(data, start);
  8104. } else {
  8105. data = dataRemoveRange(data, start, end);
  8106. }
  8107. index += 2;
  8108. }
  8109. return data;
  8110. };
  8111. var dataAddRange = function(data, rangeStart, rangeEnd) {
  8112. if (rangeEnd < rangeStart) {
  8113. throw Error(ERRORS.rangeOrder);
  8114. }
  8115. if (
  8116. rangeStart < 0x0 || rangeStart > 0x10FFFF ||
  8117. rangeEnd < 0x0 || rangeEnd > 0x10FFFF
  8118. ) {
  8119. throw RangeError(ERRORS.codePointRange);
  8120. }
  8121. // Iterate over the data per `(start, end)` pair.
  8122. var index = 0;
  8123. var start;
  8124. var end;
  8125. var added = false;
  8126. var length = data.length;
  8127. while (index < length) {
  8128. start = data[index];
  8129. end = data[index + 1];
  8130. if (added) {
  8131. // The range has already been added to the set; at this point, we just
  8132. // need to get rid of the following ranges in case they overlap.
  8133. // Check if this range can be combined with the previous range.
  8134. if (start == rangeEnd + 1) {
  8135. data.splice(index - 1, 2);
  8136. return data;
  8137. }
  8138. // Exit as soon as no more possibly overlapping pairs can be found.
  8139. if (start > rangeEnd) {
  8140. return data;
  8141. }
  8142. // E.g. `[0, 11, 12, 16]` and we’ve added 5-15, so we now have
  8143. // `[0, 16, 12, 16]`. Remove the `12,16` part, as it lies within the
  8144. // `0,16` range that was previously added.
  8145. if (start >= rangeStart && start <= rangeEnd) {
  8146. // `start` lies within the range that was previously added.
  8147. if (end > rangeStart && end - 1 <= rangeEnd) {
  8148. // `end` lies within the range that was previously added as well,
  8149. // so remove this pair.
  8150. data.splice(index, 2);
  8151. index -= 2;
  8152. // Note: we cannot `return` just yet, as there may still be other
  8153. // overlapping pairs.
  8154. } else {
  8155. // `start` lies within the range that was previously added, but
  8156. // `end` doesn’t. E.g. `[0, 11, 12, 31]` and we’ve added 5-15, so
  8157. // now we have `[0, 16, 12, 31]`. This must be written as `[0, 31]`.
  8158. // Remove the previously added `end` and the current `start`.
  8159. data.splice(index - 1, 2);
  8160. index -= 2;
  8161. }
  8162. // Note: we cannot return yet.
  8163. }
  8164. }
  8165. else if (start == rangeEnd + 1) {
  8166. data[index] = rangeStart;
  8167. return data;
  8168. }
  8169. // Check if a new pair must be inserted *before* the current one.
  8170. else if (start > rangeEnd) {
  8171. data.splice(index, 0, rangeStart, rangeEnd + 1);
  8172. return data;
  8173. }
  8174. else if (rangeStart >= start && rangeStart < end && rangeEnd + 1 <= end) {
  8175. // The new range lies entirely within an existing range pair. No action
  8176. // needed.
  8177. return data;
  8178. }
  8179. else if (
  8180. // E.g. `[0, 11]` and you add 5-15 → `[0, 16]`.
  8181. (rangeStart >= start && rangeStart < end) ||
  8182. // E.g. `[0, 3]` and you add 3-6 → `[0, 7]`.
  8183. end == rangeStart
  8184. ) {
  8185. // Replace `end` with the new value.
  8186. data[index + 1] = rangeEnd + 1;
  8187. // Make sure the next range pair doesn’t overlap, e.g. `[0, 11, 12, 14]`
  8188. // and you add 5-15 → `[0, 16]`, i.e. remove the `12,14` part.
  8189. added = true;
  8190. // Note: we cannot `return` just yet.
  8191. }
  8192. else if (rangeStart <= start && rangeEnd + 1 >= end) {
  8193. // The new range is a superset of the old range.
  8194. data[index] = rangeStart;
  8195. data[index + 1] = rangeEnd + 1;
  8196. added = true;
  8197. }
  8198. index += 2;
  8199. }
  8200. // The loop has finished without doing anything; add the new pair to the end
  8201. // of the data set.
  8202. if (!added) {
  8203. data.push(rangeStart, rangeEnd + 1);
  8204. }
  8205. return data;
  8206. };
  8207. var dataContains = function(data, codePoint) {
  8208. var index = 0;
  8209. var length = data.length;
  8210. // Exit early if `codePoint` is not within `data`’s overall range.
  8211. var start = data[index];
  8212. var end = data[length - 1];
  8213. if (length >= 2) {
  8214. if (codePoint < start || codePoint > end) {
  8215. return false;
  8216. }
  8217. }
  8218. // Iterate over the data per `(start, end)` pair.
  8219. while (index < length) {
  8220. start = data[index];
  8221. end = data[index + 1];
  8222. if (codePoint >= start && codePoint < end) {
  8223. return true;
  8224. }
  8225. index += 2;
  8226. }
  8227. return false;
  8228. };
  8229. var dataIntersection = function(data, codePoints) {
  8230. var index = 0;
  8231. var length = codePoints.length;
  8232. var codePoint;
  8233. var result = [];
  8234. while (index < length) {
  8235. codePoint = codePoints[index];
  8236. if (dataContains(data, codePoint)) {
  8237. result.push(codePoint);
  8238. }
  8239. ++index;
  8240. }
  8241. return dataFromCodePoints(result);
  8242. };
  8243. var dataIsEmpty = function(data) {
  8244. return !data.length;
  8245. };
  8246. var dataIsSingleton = function(data) {
  8247. // Check if the set only represents a single code point.
  8248. return data.length == 2 && data[0] + 1 == data[1];
  8249. };
  8250. var dataToArray = function(data) {
  8251. // Iterate over the data per `(start, end)` pair.
  8252. var index = 0;
  8253. var start;
  8254. var end;
  8255. var result = [];
  8256. var length = data.length;
  8257. while (index < length) {
  8258. start = data[index];
  8259. end = data[index + 1];
  8260. while (start < end) {
  8261. result.push(start);
  8262. ++start;
  8263. }
  8264. index += 2;
  8265. }
  8266. return result;
  8267. };
  8268. /*--------------------------------------------------------------------------*/
  8269. // https://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
  8270. var floor = Math.floor;
  8271. var highSurrogate = function(codePoint) {
  8272. return parseInt(
  8273. floor((codePoint - 0x10000) / 0x400) + HIGH_SURROGATE_MIN,
  8274. 10
  8275. );
  8276. };
  8277. var lowSurrogate = function(codePoint) {
  8278. return parseInt(
  8279. (codePoint - 0x10000) % 0x400 + LOW_SURROGATE_MIN,
  8280. 10
  8281. );
  8282. };
  8283. var stringFromCharCode = String.fromCharCode;
  8284. var codePointToString = function(codePoint) {
  8285. var string;
  8286. // https://mathiasbynens.be/notes/javascript-escapes#single
  8287. // Note: the `\b` escape sequence for U+0008 BACKSPACE in strings has a
  8288. // different meaning in regular expressions (word boundary), so it cannot
  8289. // be used here.
  8290. if (codePoint == 0x09) {
  8291. string = '\\t';
  8292. }
  8293. // Note: IE < 9 treats `'\v'` as `'v'`, so avoid using it.
  8294. // else if (codePoint == 0x0B) {
  8295. // string = '\\v';
  8296. // }
  8297. else if (codePoint == 0x0A) {
  8298. string = '\\n';
  8299. }
  8300. else if (codePoint == 0x0C) {
  8301. string = '\\f';
  8302. }
  8303. else if (codePoint == 0x0D) {
  8304. string = '\\r';
  8305. }
  8306. else if (codePoint == 0x5C) {
  8307. string = '\\\\';
  8308. }
  8309. else if (
  8310. codePoint == 0x24 ||
  8311. (codePoint >= 0x28 && codePoint <= 0x2B) ||
  8312. (codePoint >= 0x2D && codePoint <= 0x2F) ||
  8313. codePoint == 0x3F ||
  8314. (codePoint >= 0x5B && codePoint <= 0x5E) ||
  8315. (codePoint >= 0x7B && codePoint <= 0x7D)
  8316. ) {
  8317. // The code point maps to an unsafe printable ASCII character;
  8318. // backslash-escape it. Here’s the list of those symbols:
  8319. //
  8320. // $()*+-./?[\]^{|}
  8321. //
  8322. // See #7 for more info.
  8323. string = '\\' + stringFromCharCode(codePoint);
  8324. }
  8325. else if (codePoint >= 0x20 && codePoint <= 0x7E) {
  8326. // The code point maps to one of these printable ASCII symbols
  8327. // (including the space character):
  8328. //
  8329. // !"#%&',/0123456789:;<=>@ABCDEFGHIJKLMNO
  8330. // PQRSTUVWXYZ_`abcdefghijklmnopqrstuvwxyz~
  8331. //
  8332. // These can safely be used directly.
  8333. string = stringFromCharCode(codePoint);
  8334. }
  8335. else if (codePoint <= 0xFF) {
  8336. // https://mathiasbynens.be/notes/javascript-escapes#hexadecimal
  8337. string = '\\x' + pad(hex(codePoint), 2);
  8338. }
  8339. else { // `codePoint <= 0xFFFF` holds true.
  8340. // https://mathiasbynens.be/notes/javascript-escapes#unicode
  8341. string = '\\u' + pad(hex(codePoint), 4);
  8342. }
  8343. // There’s no need to account for astral symbols / surrogate pairs here,
  8344. // since `codePointToString` is private and only used for BMP code points.
  8345. // But if that’s what you need, just add an `else` block with this code:
  8346. //
  8347. // string = '\\u' + pad(hex(highSurrogate(codePoint)), 4)
  8348. // + '\\u' + pad(hex(lowSurrogate(codePoint)), 4);
  8349. return string;
  8350. };
  8351. var codePointToStringUnicode = function(codePoint) {
  8352. if (codePoint <= 0xFFFF) {
  8353. return codePointToString(codePoint);
  8354. }
  8355. return '\\u{' + codePoint.toString(16).toUpperCase() + '}';
  8356. };
  8357. var symbolToCodePoint = function(symbol) {
  8358. var length = symbol.length;
  8359. var first = symbol.charCodeAt(0);
  8360. var second;
  8361. if (
  8362. first >= HIGH_SURROGATE_MIN && first <= HIGH_SURROGATE_MAX &&
  8363. length > 1 // There is a next code unit.
  8364. ) {
  8365. // `first` is a high surrogate, and there is a next character. Assume
  8366. // it’s a low surrogate (else it’s invalid usage of Regenerate anyway).
  8367. second = symbol.charCodeAt(1);
  8368. // https://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
  8369. return (first - HIGH_SURROGATE_MIN) * 0x400 +
  8370. second - LOW_SURROGATE_MIN + 0x10000;
  8371. }
  8372. return first;
  8373. };
  8374. var createBMPCharacterClasses = function(data) {
  8375. // Iterate over the data per `(start, end)` pair.
  8376. var result = '';
  8377. var index = 0;
  8378. var start;
  8379. var end;
  8380. var length = data.length;
  8381. if (dataIsSingleton(data)) {
  8382. return codePointToString(data[0]);
  8383. }
  8384. while (index < length) {
  8385. start = data[index];
  8386. end = data[index + 1] - 1; // Note: the `- 1` makes `end` inclusive.
  8387. if (start == end) {
  8388. result += codePointToString(start);
  8389. } else if (start + 1 == end) {
  8390. result += codePointToString(start) + codePointToString(end);
  8391. } else {
  8392. result += codePointToString(start) + '-' + codePointToString(end);
  8393. }
  8394. index += 2;
  8395. }
  8396. return '[' + result + ']';
  8397. };
  8398. var createUnicodeCharacterClasses = function(data) {
  8399. // Iterate over the data per `(start, end)` pair.
  8400. var result = '';
  8401. var index = 0;
  8402. var start;
  8403. var end;
  8404. var length = data.length;
  8405. if (dataIsSingleton(data)) {
  8406. return codePointToStringUnicode(data[0]);
  8407. }
  8408. while (index < length) {
  8409. start = data[index];
  8410. end = data[index + 1] - 1; // Note: the `- 1` makes `end` inclusive.
  8411. if (start == end) {
  8412. result += codePointToStringUnicode(start);
  8413. } else if (start + 1 == end) {
  8414. result += codePointToStringUnicode(start) + codePointToStringUnicode(end);
  8415. } else {
  8416. result += codePointToStringUnicode(start) + '-' + codePointToStringUnicode(end);
  8417. }
  8418. index += 2;
  8419. }
  8420. return '[' + result + ']';
  8421. };
  8422. var splitAtBMP = function(data) {
  8423. // Iterate over the data per `(start, end)` pair.
  8424. var loneHighSurrogates = [];
  8425. var loneLowSurrogates = [];
  8426. var bmp = [];
  8427. var astral = [];
  8428. var index = 0;
  8429. var start;
  8430. var end;
  8431. var length = data.length;
  8432. while (index < length) {
  8433. start = data[index];
  8434. end = data[index + 1] - 1; // Note: the `- 1` makes `end` inclusive.
  8435. if (start < HIGH_SURROGATE_MIN) {
  8436. // The range starts and ends before the high surrogate range.
  8437. // E.g. (0, 0x10).
  8438. if (end < HIGH_SURROGATE_MIN) {
  8439. bmp.push(start, end + 1);
  8440. }
  8441. // The range starts before the high surrogate range and ends within it.
  8442. // E.g. (0, 0xD855).
  8443. if (end >= HIGH_SURROGATE_MIN && end <= HIGH_SURROGATE_MAX) {
  8444. bmp.push(start, HIGH_SURROGATE_MIN);
  8445. loneHighSurrogates.push(HIGH_SURROGATE_MIN, end + 1);
  8446. }
  8447. // The range starts before the high surrogate range and ends in the low
  8448. // surrogate range. E.g. (0, 0xDCFF).
  8449. if (end >= LOW_SURROGATE_MIN && end <= LOW_SURROGATE_MAX) {
  8450. bmp.push(start, HIGH_SURROGATE_MIN);
  8451. loneHighSurrogates.push(HIGH_SURROGATE_MIN, HIGH_SURROGATE_MAX + 1);
  8452. loneLowSurrogates.push(LOW_SURROGATE_MIN, end + 1);
  8453. }
  8454. // The range starts before the high surrogate range and ends after the
  8455. // low surrogate range. E.g. (0, 0x10FFFF).
  8456. if (end > LOW_SURROGATE_MAX) {
  8457. bmp.push(start, HIGH_SURROGATE_MIN);
  8458. loneHighSurrogates.push(HIGH_SURROGATE_MIN, HIGH_SURROGATE_MAX + 1);
  8459. loneLowSurrogates.push(LOW_SURROGATE_MIN, LOW_SURROGATE_MAX + 1);
  8460. if (end <= 0xFFFF) {
  8461. bmp.push(LOW_SURROGATE_MAX + 1, end + 1);
  8462. } else {
  8463. bmp.push(LOW_SURROGATE_MAX + 1, 0xFFFF + 1);
  8464. astral.push(0xFFFF + 1, end + 1);
  8465. }
  8466. }
  8467. } else if (start >= HIGH_SURROGATE_MIN && start <= HIGH_SURROGATE_MAX) {
  8468. // The range starts and ends in the high surrogate range.
  8469. // E.g. (0xD855, 0xD866).
  8470. if (end >= HIGH_SURROGATE_MIN && end <= HIGH_SURROGATE_MAX) {
  8471. loneHighSurrogates.push(start, end + 1);
  8472. }
  8473. // The range starts in the high surrogate range and ends in the low
  8474. // surrogate range. E.g. (0xD855, 0xDCFF).
  8475. if (end >= LOW_SURROGATE_MIN && end <= LOW_SURROGATE_MAX) {
  8476. loneHighSurrogates.push(start, HIGH_SURROGATE_MAX + 1);
  8477. loneLowSurrogates.push(LOW_SURROGATE_MIN, end + 1);
  8478. }
  8479. // The range starts in the high surrogate range and ends after the low
  8480. // surrogate range. E.g. (0xD855, 0x10FFFF).
  8481. if (end > LOW_SURROGATE_MAX) {
  8482. loneHighSurrogates.push(start, HIGH_SURROGATE_MAX + 1);
  8483. loneLowSurrogates.push(LOW_SURROGATE_MIN, LOW_SURROGATE_MAX + 1);
  8484. if (end <= 0xFFFF) {
  8485. bmp.push(LOW_SURROGATE_MAX + 1, end + 1);
  8486. } else {
  8487. bmp.push(LOW_SURROGATE_MAX + 1, 0xFFFF + 1);
  8488. astral.push(0xFFFF + 1, end + 1);
  8489. }
  8490. }
  8491. } else if (start >= LOW_SURROGATE_MIN && start <= LOW_SURROGATE_MAX) {
  8492. // The range starts and ends in the low surrogate range.
  8493. // E.g. (0xDCFF, 0xDDFF).
  8494. if (end >= LOW_SURROGATE_MIN && end <= LOW_SURROGATE_MAX) {
  8495. loneLowSurrogates.push(start, end + 1);
  8496. }
  8497. // The range starts in the low surrogate range and ends after the low
  8498. // surrogate range. E.g. (0xDCFF, 0x10FFFF).
  8499. if (end > LOW_SURROGATE_MAX) {
  8500. loneLowSurrogates.push(start, LOW_SURROGATE_MAX + 1);
  8501. if (end <= 0xFFFF) {
  8502. bmp.push(LOW_SURROGATE_MAX + 1, end + 1);
  8503. } else {
  8504. bmp.push(LOW_SURROGATE_MAX + 1, 0xFFFF + 1);
  8505. astral.push(0xFFFF + 1, end + 1);
  8506. }
  8507. }
  8508. } else if (start > LOW_SURROGATE_MAX && start <= 0xFFFF) {
  8509. // The range starts and ends after the low surrogate range.
  8510. // E.g. (0xFFAA, 0x10FFFF).
  8511. if (end <= 0xFFFF) {
  8512. bmp.push(start, end + 1);
  8513. } else {
  8514. bmp.push(start, 0xFFFF + 1);
  8515. astral.push(0xFFFF + 1, end + 1);
  8516. }
  8517. } else {
  8518. // The range starts and ends in the astral range.
  8519. astral.push(start, end + 1);
  8520. }
  8521. index += 2;
  8522. }
  8523. return {
  8524. 'loneHighSurrogates': loneHighSurrogates,
  8525. 'loneLowSurrogates': loneLowSurrogates,
  8526. 'bmp': bmp,
  8527. 'astral': astral
  8528. };
  8529. };
  8530. var optimizeSurrogateMappings = function(surrogateMappings) {
  8531. var result = [];
  8532. var tmpLow = [];
  8533. var addLow = false;
  8534. var mapping;
  8535. var nextMapping;
  8536. var highSurrogates;
  8537. var lowSurrogates;
  8538. var nextHighSurrogates;
  8539. var nextLowSurrogates;
  8540. var index = -1;
  8541. var length = surrogateMappings.length;
  8542. while (++index < length) {
  8543. mapping = surrogateMappings[index];
  8544. nextMapping = surrogateMappings[index + 1];
  8545. if (!nextMapping) {
  8546. result.push(mapping);
  8547. continue;
  8548. }
  8549. highSurrogates = mapping[0];
  8550. lowSurrogates = mapping[1];
  8551. nextHighSurrogates = nextMapping[0];
  8552. nextLowSurrogates = nextMapping[1];
  8553. // Check for identical high surrogate ranges.
  8554. tmpLow = lowSurrogates;
  8555. while (
  8556. nextHighSurrogates &&
  8557. highSurrogates[0] == nextHighSurrogates[0] &&
  8558. highSurrogates[1] == nextHighSurrogates[1]
  8559. ) {
  8560. // Merge with the next item.
  8561. if (dataIsSingleton(nextLowSurrogates)) {
  8562. tmpLow = dataAdd(tmpLow, nextLowSurrogates[0]);
  8563. } else {
  8564. tmpLow = dataAddRange(
  8565. tmpLow,
  8566. nextLowSurrogates[0],
  8567. nextLowSurrogates[1] - 1
  8568. );
  8569. }
  8570. ++index;
  8571. mapping = surrogateMappings[index];
  8572. highSurrogates = mapping[0];
  8573. lowSurrogates = mapping[1];
  8574. nextMapping = surrogateMappings[index + 1];
  8575. nextHighSurrogates = nextMapping && nextMapping[0];
  8576. nextLowSurrogates = nextMapping && nextMapping[1];
  8577. addLow = true;
  8578. }
  8579. result.push([
  8580. highSurrogates,
  8581. addLow ? tmpLow : lowSurrogates
  8582. ]);
  8583. addLow = false;
  8584. }
  8585. return optimizeByLowSurrogates(result);
  8586. };
  8587. var optimizeByLowSurrogates = function(surrogateMappings) {
  8588. if (surrogateMappings.length == 1) {
  8589. return surrogateMappings;
  8590. }
  8591. var index = -1;
  8592. var innerIndex = -1;
  8593. while (++index < surrogateMappings.length) {
  8594. var mapping = surrogateMappings[index];
  8595. var lowSurrogates = mapping[1];
  8596. var lowSurrogateStart = lowSurrogates[0];
  8597. var lowSurrogateEnd = lowSurrogates[1];
  8598. innerIndex = index; // Note: the loop starts at the next index.
  8599. while (++innerIndex < surrogateMappings.length) {
  8600. var otherMapping = surrogateMappings[innerIndex];
  8601. var otherLowSurrogates = otherMapping[1];
  8602. var otherLowSurrogateStart = otherLowSurrogates[0];
  8603. var otherLowSurrogateEnd = otherLowSurrogates[1];
  8604. if (
  8605. lowSurrogateStart == otherLowSurrogateStart &&
  8606. lowSurrogateEnd == otherLowSurrogateEnd
  8607. ) {
  8608. // Add the code points in the other item to this one.
  8609. if (dataIsSingleton(otherMapping[0])) {
  8610. mapping[0] = dataAdd(mapping[0], otherMapping[0][0]);
  8611. } else {
  8612. mapping[0] = dataAddRange(
  8613. mapping[0],
  8614. otherMapping[0][0],
  8615. otherMapping[0][1] - 1
  8616. );
  8617. }
  8618. // Remove the other, now redundant, item.
  8619. surrogateMappings.splice(innerIndex, 1);
  8620. --innerIndex;
  8621. }
  8622. }
  8623. }
  8624. return surrogateMappings;
  8625. };
  8626. var surrogateSet = function(data) {
  8627. // Exit early if `data` is an empty set.
  8628. if (!data.length) {
  8629. return [];
  8630. }
  8631. // Iterate over the data per `(start, end)` pair.
  8632. var index = 0;
  8633. var start;
  8634. var end;
  8635. var startHigh;
  8636. var startLow;
  8637. var endHigh;
  8638. var endLow;
  8639. var surrogateMappings = [];
  8640. var length = data.length;
  8641. while (index < length) {
  8642. start = data[index];
  8643. end = data[index + 1] - 1;
  8644. startHigh = highSurrogate(start);
  8645. startLow = lowSurrogate(start);
  8646. endHigh = highSurrogate(end);
  8647. endLow = lowSurrogate(end);
  8648. var startsWithLowestLowSurrogate = startLow == LOW_SURROGATE_MIN;
  8649. var endsWithHighestLowSurrogate = endLow == LOW_SURROGATE_MAX;
  8650. var complete = false;
  8651. // Append the previous high-surrogate-to-low-surrogate mappings.
  8652. // Step 1: `(startHigh, startLow)` to `(startHigh, LOW_SURROGATE_MAX)`.
  8653. if (
  8654. startHigh == endHigh ||
  8655. startsWithLowestLowSurrogate && endsWithHighestLowSurrogate
  8656. ) {
  8657. surrogateMappings.push([
  8658. [startHigh, endHigh + 1],
  8659. [startLow, endLow + 1]
  8660. ]);
  8661. complete = true;
  8662. } else {
  8663. surrogateMappings.push([
  8664. [startHigh, startHigh + 1],
  8665. [startLow, LOW_SURROGATE_MAX + 1]
  8666. ]);
  8667. }
  8668. // Step 2: `(startHigh + 1, LOW_SURROGATE_MIN)` to
  8669. // `(endHigh - 1, LOW_SURROGATE_MAX)`.
  8670. if (!complete && startHigh + 1 < endHigh) {
  8671. if (endsWithHighestLowSurrogate) {
  8672. // Combine step 2 and step 3.
  8673. surrogateMappings.push([
  8674. [startHigh + 1, endHigh + 1],
  8675. [LOW_SURROGATE_MIN, endLow + 1]
  8676. ]);
  8677. complete = true;
  8678. } else {
  8679. surrogateMappings.push([
  8680. [startHigh + 1, endHigh],
  8681. [LOW_SURROGATE_MIN, LOW_SURROGATE_MAX + 1]
  8682. ]);
  8683. }
  8684. }
  8685. // Step 3. `(endHigh, LOW_SURROGATE_MIN)` to `(endHigh, endLow)`.
  8686. if (!complete) {
  8687. surrogateMappings.push([
  8688. [endHigh, endHigh + 1],
  8689. [LOW_SURROGATE_MIN, endLow + 1]
  8690. ]);
  8691. }
  8692. index += 2;
  8693. }
  8694. // The format of `surrogateMappings` is as follows:
  8695. //
  8696. // [ surrogateMapping1, surrogateMapping2 ]
  8697. //
  8698. // i.e.:
  8699. //
  8700. // [
  8701. // [ highSurrogates1, lowSurrogates1 ],
  8702. // [ highSurrogates2, lowSurrogates2 ]
  8703. // ]
  8704. return optimizeSurrogateMappings(surrogateMappings);
  8705. };
  8706. var createSurrogateCharacterClasses = function(surrogateMappings) {
  8707. var result = [];
  8708. forEach(surrogateMappings, function(surrogateMapping) {
  8709. var highSurrogates = surrogateMapping[0];
  8710. var lowSurrogates = surrogateMapping[1];
  8711. result.push(
  8712. createBMPCharacterClasses(highSurrogates) +
  8713. createBMPCharacterClasses(lowSurrogates)
  8714. );
  8715. });
  8716. return result.join('|');
  8717. };
  8718. var createCharacterClassesFromData = function(data, bmpOnly, hasUnicodeFlag) {
  8719. if (hasUnicodeFlag) {
  8720. return createUnicodeCharacterClasses(data);
  8721. }
  8722. var result = [];
  8723. var parts = splitAtBMP(data);
  8724. var loneHighSurrogates = parts.loneHighSurrogates;
  8725. var loneLowSurrogates = parts.loneLowSurrogates;
  8726. var bmp = parts.bmp;
  8727. var astral = parts.astral;
  8728. var hasLoneHighSurrogates = !dataIsEmpty(loneHighSurrogates);
  8729. var hasLoneLowSurrogates = !dataIsEmpty(loneLowSurrogates);
  8730. var surrogateMappings = surrogateSet(astral);
  8731. if (bmpOnly) {
  8732. bmp = dataAddData(bmp, loneHighSurrogates);
  8733. hasLoneHighSurrogates = false;
  8734. bmp = dataAddData(bmp, loneLowSurrogates);
  8735. hasLoneLowSurrogates = false;
  8736. }
  8737. if (!dataIsEmpty(bmp)) {
  8738. // The data set contains BMP code points that are not high surrogates
  8739. // needed for astral code points in the set.
  8740. result.push(createBMPCharacterClasses(bmp));
  8741. }
  8742. if (surrogateMappings.length) {
  8743. // The data set contains astral code points; append character classes
  8744. // based on their surrogate pairs.
  8745. result.push(createSurrogateCharacterClasses(surrogateMappings));
  8746. }
  8747. // https://gist.github.com/mathiasbynens/bbe7f870208abcfec860
  8748. if (hasLoneHighSurrogates) {
  8749. result.push(
  8750. createBMPCharacterClasses(loneHighSurrogates) +
  8751. // Make sure the high surrogates aren’t part of a surrogate pair.
  8752. '(?![\\uDC00-\\uDFFF])'
  8753. );
  8754. }
  8755. if (hasLoneLowSurrogates) {
  8756. result.push(
  8757. // It is not possible to accurately assert the low surrogates aren’t
  8758. // part of a surrogate pair, since JavaScript regular expressions do
  8759. // not support lookbehind.
  8760. '(?:[^\\uD800-\\uDBFF]|^)' +
  8761. createBMPCharacterClasses(loneLowSurrogates)
  8762. );
  8763. }
  8764. return result.join('|');
  8765. };
  8766. /*--------------------------------------------------------------------------*/
  8767. // `regenerate` can be used as a constructor (and new methods can be added to
  8768. // its prototype) but also as a regular function, the latter of which is the
  8769. // documented and most common usage. For that reason, it’s not capitalized.
  8770. var regenerate = function(value) {
  8771. if (arguments.length > 1) {
  8772. value = slice.call(arguments);
  8773. }
  8774. if (this instanceof regenerate) {
  8775. this.data = [];
  8776. return value ? this.add(value) : this;
  8777. }
  8778. return (new regenerate).add(value);
  8779. };
  8780. regenerate.version = '1.3.3';
  8781. var proto = regenerate.prototype;
  8782. extend(proto, {
  8783. 'add': function(value) {
  8784. var $this = this;
  8785. if (value == null) {
  8786. return $this;
  8787. }
  8788. if (value instanceof regenerate) {
  8789. // Allow passing other Regenerate instances.
  8790. $this.data = dataAddData($this.data, value.data);
  8791. return $this;
  8792. }
  8793. if (arguments.length > 1) {
  8794. value = slice.call(arguments);
  8795. }
  8796. if (isArray(value)) {
  8797. forEach(value, function(item) {
  8798. $this.add(item);
  8799. });
  8800. return $this;
  8801. }
  8802. $this.data = dataAdd(
  8803. $this.data,
  8804. isNumber(value) ? value : symbolToCodePoint(value)
  8805. );
  8806. return $this;
  8807. },
  8808. 'remove': function(value) {
  8809. var $this = this;
  8810. if (value == null) {
  8811. return $this;
  8812. }
  8813. if (value instanceof regenerate) {
  8814. // Allow passing other Regenerate instances.
  8815. $this.data = dataRemoveData($this.data, value.data);
  8816. return $this;
  8817. }
  8818. if (arguments.length > 1) {
  8819. value = slice.call(arguments);
  8820. }
  8821. if (isArray(value)) {
  8822. forEach(value, function(item) {
  8823. $this.remove(item);
  8824. });
  8825. return $this;
  8826. }
  8827. $this.data = dataRemove(
  8828. $this.data,
  8829. isNumber(value) ? value : symbolToCodePoint(value)
  8830. );
  8831. return $this;
  8832. },
  8833. 'addRange': function(start, end) {
  8834. var $this = this;
  8835. $this.data = dataAddRange($this.data,
  8836. isNumber(start) ? start : symbolToCodePoint(start),
  8837. isNumber(end) ? end : symbolToCodePoint(end)
  8838. );
  8839. return $this;
  8840. },
  8841. 'removeRange': function(start, end) {
  8842. var $this = this;
  8843. var startCodePoint = isNumber(start) ? start : symbolToCodePoint(start);
  8844. var endCodePoint = isNumber(end) ? end : symbolToCodePoint(end);
  8845. $this.data = dataRemoveRange(
  8846. $this.data,
  8847. startCodePoint,
  8848. endCodePoint
  8849. );
  8850. return $this;
  8851. },
  8852. 'intersection': function(argument) {
  8853. var $this = this;
  8854. // Allow passing other Regenerate instances.
  8855. // TODO: Optimize this by writing and using `dataIntersectionData()`.
  8856. var array = argument instanceof regenerate ?
  8857. dataToArray(argument.data) :
  8858. argument;
  8859. $this.data = dataIntersection($this.data, array);
  8860. return $this;
  8861. },
  8862. 'contains': function(codePoint) {
  8863. return dataContains(
  8864. this.data,
  8865. isNumber(codePoint) ? codePoint : symbolToCodePoint(codePoint)
  8866. );
  8867. },
  8868. 'clone': function() {
  8869. var set = new regenerate;
  8870. set.data = this.data.slice(0);
  8871. return set;
  8872. },
  8873. 'toString': function(options) {
  8874. var result = createCharacterClassesFromData(
  8875. this.data,
  8876. options ? options.bmpOnly : false,
  8877. options ? options.hasUnicodeFlag : false
  8878. );
  8879. if (!result) {
  8880. // For an empty set, return something that can be inserted `/here/` to
  8881. // form a valid regular expression. Avoid `(?:)` since that matches the
  8882. // empty string.
  8883. return '[]';
  8884. }
  8885. // Use `\0` instead of `\x00` where possible.
  8886. return result.replace(regexNull, '\\0$1');
  8887. },
  8888. 'toRegExp': function(flags) {
  8889. var pattern = this.toString(
  8890. flags && flags.indexOf('u') != -1 ?
  8891. { 'hasUnicodeFlag': true } :
  8892. null
  8893. );
  8894. return RegExp(pattern, flags || '');
  8895. },
  8896. 'valueOf': function() { // Note: `valueOf` is aliased as `toArray`.
  8897. return dataToArray(this.data);
  8898. }
  8899. });
  8900. proto.toArray = proto.valueOf;
  8901. // Some AMD build optimizers, like r.js, check for specific condition patterns
  8902. // like the following:
  8903. if (
  8904. typeof undefined == 'function' &&
  8905. typeof undefined.amd == 'object' &&
  8906. undefined.amd
  8907. ) {
  8908. undefined(function() {
  8909. return regenerate;
  8910. });
  8911. } else if (freeExports && !freeExports.nodeType) {
  8912. if (freeModule) { // in Node.js, io.js, or RingoJS v0.8.0+
  8913. freeModule.exports = regenerate;
  8914. } else { // in Narwhal or RingoJS v0.7.0-
  8915. freeExports.regenerate = regenerate;
  8916. }
  8917. } else { // in Rhino or a web browser
  8918. root.regenerate = regenerate;
  8919. }
  8920. }(commonjsGlobal));
  8921. });
  8922. var unicodeCanonicalPropertyNamesEcmascript = new Set([
  8923. // Non-binary properties:
  8924. 'General_Category',
  8925. 'Script',
  8926. 'Script_Extensions',
  8927. // Binary properties:
  8928. 'Alphabetic',
  8929. 'Any',
  8930. 'ASCII',
  8931. 'ASCII_Hex_Digit',
  8932. 'Assigned',
  8933. 'Bidi_Control',
  8934. 'Bidi_Mirrored',
  8935. 'Case_Ignorable',
  8936. 'Cased',
  8937. 'Changes_When_Casefolded',
  8938. 'Changes_When_Casemapped',
  8939. 'Changes_When_Lowercased',
  8940. 'Changes_When_NFKC_Casefolded',
  8941. 'Changes_When_Titlecased',
  8942. 'Changes_When_Uppercased',
  8943. 'Dash',
  8944. 'Default_Ignorable_Code_Point',
  8945. 'Deprecated',
  8946. 'Diacritic',
  8947. 'Emoji',
  8948. 'Emoji_Component',
  8949. 'Emoji_Modifier',
  8950. 'Emoji_Modifier_Base',
  8951. 'Emoji_Presentation',
  8952. 'Extended_Pictographic',
  8953. 'Extender',
  8954. 'Grapheme_Base',
  8955. 'Grapheme_Extend',
  8956. 'Hex_Digit',
  8957. 'ID_Continue',
  8958. 'ID_Start',
  8959. 'Ideographic',
  8960. 'IDS_Binary_Operator',
  8961. 'IDS_Trinary_Operator',
  8962. 'Join_Control',
  8963. 'Logical_Order_Exception',
  8964. 'Lowercase',
  8965. 'Math',
  8966. 'Noncharacter_Code_Point',
  8967. 'Pattern_Syntax',
  8968. 'Pattern_White_Space',
  8969. 'Quotation_Mark',
  8970. 'Radical',
  8971. 'Regional_Indicator',
  8972. 'Sentence_Terminal',
  8973. 'Soft_Dotted',
  8974. 'Terminal_Punctuation',
  8975. 'Unified_Ideograph',
  8976. 'Uppercase',
  8977. 'Variation_Selector',
  8978. 'White_Space',
  8979. 'XID_Continue',
  8980. 'XID_Start'
  8981. ]);
  8982. // Generated using `npm run build`. Do not edit!
  8983. var unicodePropertyAliasesEcmascript = new Map([
  8984. ['scx', 'Script_Extensions'],
  8985. ['sc', 'Script'],
  8986. ['gc', 'General_Category'],
  8987. ['AHex', 'ASCII_Hex_Digit'],
  8988. ['Alpha', 'Alphabetic'],
  8989. ['Bidi_C', 'Bidi_Control'],
  8990. ['Bidi_M', 'Bidi_Mirrored'],
  8991. ['Cased', 'Cased'],
  8992. ['CI', 'Case_Ignorable'],
  8993. ['CWCF', 'Changes_When_Casefolded'],
  8994. ['CWCM', 'Changes_When_Casemapped'],
  8995. ['CWKCF', 'Changes_When_NFKC_Casefolded'],
  8996. ['CWL', 'Changes_When_Lowercased'],
  8997. ['CWT', 'Changes_When_Titlecased'],
  8998. ['CWU', 'Changes_When_Uppercased'],
  8999. ['Dash', 'Dash'],
  9000. ['Dep', 'Deprecated'],
  9001. ['DI', 'Default_Ignorable_Code_Point'],
  9002. ['Dia', 'Diacritic'],
  9003. ['Ext', 'Extender'],
  9004. ['Gr_Base', 'Grapheme_Base'],
  9005. ['Gr_Ext', 'Grapheme_Extend'],
  9006. ['Hex', 'Hex_Digit'],
  9007. ['IDC', 'ID_Continue'],
  9008. ['Ideo', 'Ideographic'],
  9009. ['IDS', 'ID_Start'],
  9010. ['IDSB', 'IDS_Binary_Operator'],
  9011. ['IDST', 'IDS_Trinary_Operator'],
  9012. ['Join_C', 'Join_Control'],
  9013. ['LOE', 'Logical_Order_Exception'],
  9014. ['Lower', 'Lowercase'],
  9015. ['Math', 'Math'],
  9016. ['NChar', 'Noncharacter_Code_Point'],
  9017. ['Pat_Syn', 'Pattern_Syntax'],
  9018. ['Pat_WS', 'Pattern_White_Space'],
  9019. ['QMark', 'Quotation_Mark'],
  9020. ['Radical', 'Radical'],
  9021. ['RI', 'Regional_Indicator'],
  9022. ['SD', 'Soft_Dotted'],
  9023. ['STerm', 'Sentence_Terminal'],
  9024. ['Term', 'Terminal_Punctuation'],
  9025. ['UIdeo', 'Unified_Ideograph'],
  9026. ['Upper', 'Uppercase'],
  9027. ['VS', 'Variation_Selector'],
  9028. ['WSpace', 'White_Space'],
  9029. ['space', 'White_Space'],
  9030. ['XIDC', 'XID_Continue'],
  9031. ['XIDS', 'XID_Start']
  9032. ]);
  9033. 'use strict';
  9034. const matchProperty = function(property) {
  9035. if (unicodeCanonicalPropertyNamesEcmascript.has(property)) {
  9036. return property;
  9037. }
  9038. if (unicodePropertyAliasesEcmascript.has(property)) {
  9039. return unicodePropertyAliasesEcmascript.get(property);
  9040. }
  9041. throw new Error(`Unknown property: ${ property }`);
  9042. };
  9043. var unicodeMatchPropertyEcmascript = matchProperty;
  9044. var mappings = new Map([
  9045. ['General_Category', new Map([
  9046. ['C', 'Other'],
  9047. ['Cc', 'Control'],
  9048. ['cntrl', 'Control'],
  9049. ['Cf', 'Format'],
  9050. ['Cn', 'Unassigned'],
  9051. ['Co', 'Private_Use'],
  9052. ['Cs', 'Surrogate'],
  9053. ['L', 'Letter'],
  9054. ['LC', 'Cased_Letter'],
  9055. ['Ll', 'Lowercase_Letter'],
  9056. ['Lm', 'Modifier_Letter'],
  9057. ['Lo', 'Other_Letter'],
  9058. ['Lt', 'Titlecase_Letter'],
  9059. ['Lu', 'Uppercase_Letter'],
  9060. ['M', 'Mark'],
  9061. ['Combining_Mark', 'Mark'],
  9062. ['Mc', 'Spacing_Mark'],
  9063. ['Me', 'Enclosing_Mark'],
  9064. ['Mn', 'Nonspacing_Mark'],
  9065. ['N', 'Number'],
  9066. ['Nd', 'Decimal_Number'],
  9067. ['digit', 'Decimal_Number'],
  9068. ['Nl', 'Letter_Number'],
  9069. ['No', 'Other_Number'],
  9070. ['P', 'Punctuation'],
  9071. ['punct', 'Punctuation'],
  9072. ['Pc', 'Connector_Punctuation'],
  9073. ['Pd', 'Dash_Punctuation'],
  9074. ['Pe', 'Close_Punctuation'],
  9075. ['Pf', 'Final_Punctuation'],
  9076. ['Pi', 'Initial_Punctuation'],
  9077. ['Po', 'Other_Punctuation'],
  9078. ['Ps', 'Open_Punctuation'],
  9079. ['S', 'Symbol'],
  9080. ['Sc', 'Currency_Symbol'],
  9081. ['Sk', 'Modifier_Symbol'],
  9082. ['Sm', 'Math_Symbol'],
  9083. ['So', 'Other_Symbol'],
  9084. ['Z', 'Separator'],
  9085. ['Zl', 'Line_Separator'],
  9086. ['Zp', 'Paragraph_Separator'],
  9087. ['Zs', 'Space_Separator'],
  9088. ['Other', 'Other'],
  9089. ['Control', 'Control'],
  9090. ['Format', 'Format'],
  9091. ['Unassigned', 'Unassigned'],
  9092. ['Private_Use', 'Private_Use'],
  9093. ['Surrogate', 'Surrogate'],
  9094. ['Letter', 'Letter'],
  9095. ['Cased_Letter', 'Cased_Letter'],
  9096. ['Lowercase_Letter', 'Lowercase_Letter'],
  9097. ['Modifier_Letter', 'Modifier_Letter'],
  9098. ['Other_Letter', 'Other_Letter'],
  9099. ['Titlecase_Letter', 'Titlecase_Letter'],
  9100. ['Uppercase_Letter', 'Uppercase_Letter'],
  9101. ['Mark', 'Mark'],
  9102. ['Spacing_Mark', 'Spacing_Mark'],
  9103. ['Enclosing_Mark', 'Enclosing_Mark'],
  9104. ['Nonspacing_Mark', 'Nonspacing_Mark'],
  9105. ['Number', 'Number'],
  9106. ['Decimal_Number', 'Decimal_Number'],
  9107. ['Letter_Number', 'Letter_Number'],
  9108. ['Other_Number', 'Other_Number'],
  9109. ['Punctuation', 'Punctuation'],
  9110. ['Connector_Punctuation', 'Connector_Punctuation'],
  9111. ['Dash_Punctuation', 'Dash_Punctuation'],
  9112. ['Close_Punctuation', 'Close_Punctuation'],
  9113. ['Final_Punctuation', 'Final_Punctuation'],
  9114. ['Initial_Punctuation', 'Initial_Punctuation'],
  9115. ['Other_Punctuation', 'Other_Punctuation'],
  9116. ['Open_Punctuation', 'Open_Punctuation'],
  9117. ['Symbol', 'Symbol'],
  9118. ['Currency_Symbol', 'Currency_Symbol'],
  9119. ['Modifier_Symbol', 'Modifier_Symbol'],
  9120. ['Math_Symbol', 'Math_Symbol'],
  9121. ['Other_Symbol', 'Other_Symbol'],
  9122. ['Separator', 'Separator'],
  9123. ['Line_Separator', 'Line_Separator'],
  9124. ['Paragraph_Separator', 'Paragraph_Separator'],
  9125. ['Space_Separator', 'Space_Separator']
  9126. ])],
  9127. ['Script', new Map([
  9128. ['Adlm', 'Adlam'],
  9129. ['Aghb', 'Caucasian_Albanian'],
  9130. ['Ahom', 'Ahom'],
  9131. ['Arab', 'Arabic'],
  9132. ['Armi', 'Imperial_Aramaic'],
  9133. ['Armn', 'Armenian'],
  9134. ['Avst', 'Avestan'],
  9135. ['Bali', 'Balinese'],
  9136. ['Bamu', 'Bamum'],
  9137. ['Bass', 'Bassa_Vah'],
  9138. ['Batk', 'Batak'],
  9139. ['Beng', 'Bengali'],
  9140. ['Bhks', 'Bhaiksuki'],
  9141. ['Bopo', 'Bopomofo'],
  9142. ['Brah', 'Brahmi'],
  9143. ['Brai', 'Braille'],
  9144. ['Bugi', 'Buginese'],
  9145. ['Buhd', 'Buhid'],
  9146. ['Cakm', 'Chakma'],
  9147. ['Cans', 'Canadian_Aboriginal'],
  9148. ['Cari', 'Carian'],
  9149. ['Cham', 'Cham'],
  9150. ['Cher', 'Cherokee'],
  9151. ['Copt', 'Coptic'],
  9152. ['Qaac', 'Coptic'],
  9153. ['Cprt', 'Cypriot'],
  9154. ['Cyrl', 'Cyrillic'],
  9155. ['Deva', 'Devanagari'],
  9156. ['Dsrt', 'Deseret'],
  9157. ['Dupl', 'Duployan'],
  9158. ['Egyp', 'Egyptian_Hieroglyphs'],
  9159. ['Elba', 'Elbasan'],
  9160. ['Ethi', 'Ethiopic'],
  9161. ['Geor', 'Georgian'],
  9162. ['Glag', 'Glagolitic'],
  9163. ['Gonm', 'Masaram_Gondi'],
  9164. ['Goth', 'Gothic'],
  9165. ['Gran', 'Grantha'],
  9166. ['Grek', 'Greek'],
  9167. ['Gujr', 'Gujarati'],
  9168. ['Guru', 'Gurmukhi'],
  9169. ['Hang', 'Hangul'],
  9170. ['Hani', 'Han'],
  9171. ['Hano', 'Hanunoo'],
  9172. ['Hatr', 'Hatran'],
  9173. ['Hebr', 'Hebrew'],
  9174. ['Hira', 'Hiragana'],
  9175. ['Hluw', 'Anatolian_Hieroglyphs'],
  9176. ['Hmng', 'Pahawh_Hmong'],
  9177. ['Hrkt', 'Katakana_Or_Hiragana'],
  9178. ['Hung', 'Old_Hungarian'],
  9179. ['Ital', 'Old_Italic'],
  9180. ['Java', 'Javanese'],
  9181. ['Kali', 'Kayah_Li'],
  9182. ['Kana', 'Katakana'],
  9183. ['Khar', 'Kharoshthi'],
  9184. ['Khmr', 'Khmer'],
  9185. ['Khoj', 'Khojki'],
  9186. ['Knda', 'Kannada'],
  9187. ['Kthi', 'Kaithi'],
  9188. ['Lana', 'Tai_Tham'],
  9189. ['Laoo', 'Lao'],
  9190. ['Latn', 'Latin'],
  9191. ['Lepc', 'Lepcha'],
  9192. ['Limb', 'Limbu'],
  9193. ['Lina', 'Linear_A'],
  9194. ['Linb', 'Linear_B'],
  9195. ['Lisu', 'Lisu'],
  9196. ['Lyci', 'Lycian'],
  9197. ['Lydi', 'Lydian'],
  9198. ['Mahj', 'Mahajani'],
  9199. ['Mand', 'Mandaic'],
  9200. ['Mani', 'Manichaean'],
  9201. ['Marc', 'Marchen'],
  9202. ['Mend', 'Mende_Kikakui'],
  9203. ['Merc', 'Meroitic_Cursive'],
  9204. ['Mero', 'Meroitic_Hieroglyphs'],
  9205. ['Mlym', 'Malayalam'],
  9206. ['Modi', 'Modi'],
  9207. ['Mong', 'Mongolian'],
  9208. ['Mroo', 'Mro'],
  9209. ['Mtei', 'Meetei_Mayek'],
  9210. ['Mult', 'Multani'],
  9211. ['Mymr', 'Myanmar'],
  9212. ['Narb', 'Old_North_Arabian'],
  9213. ['Nbat', 'Nabataean'],
  9214. ['Newa', 'Newa'],
  9215. ['Nkoo', 'Nko'],
  9216. ['Nshu', 'Nushu'],
  9217. ['Ogam', 'Ogham'],
  9218. ['Olck', 'Ol_Chiki'],
  9219. ['Orkh', 'Old_Turkic'],
  9220. ['Orya', 'Oriya'],
  9221. ['Osge', 'Osage'],
  9222. ['Osma', 'Osmanya'],
  9223. ['Palm', 'Palmyrene'],
  9224. ['Pauc', 'Pau_Cin_Hau'],
  9225. ['Perm', 'Old_Permic'],
  9226. ['Phag', 'Phags_Pa'],
  9227. ['Phli', 'Inscriptional_Pahlavi'],
  9228. ['Phlp', 'Psalter_Pahlavi'],
  9229. ['Phnx', 'Phoenician'],
  9230. ['Plrd', 'Miao'],
  9231. ['Prti', 'Inscriptional_Parthian'],
  9232. ['Rjng', 'Rejang'],
  9233. ['Runr', 'Runic'],
  9234. ['Samr', 'Samaritan'],
  9235. ['Sarb', 'Old_South_Arabian'],
  9236. ['Saur', 'Saurashtra'],
  9237. ['Sgnw', 'SignWriting'],
  9238. ['Shaw', 'Shavian'],
  9239. ['Shrd', 'Sharada'],
  9240. ['Sidd', 'Siddham'],
  9241. ['Sind', 'Khudawadi'],
  9242. ['Sinh', 'Sinhala'],
  9243. ['Sora', 'Sora_Sompeng'],
  9244. ['Soyo', 'Soyombo'],
  9245. ['Sund', 'Sundanese'],
  9246. ['Sylo', 'Syloti_Nagri'],
  9247. ['Syrc', 'Syriac'],
  9248. ['Tagb', 'Tagbanwa'],
  9249. ['Takr', 'Takri'],
  9250. ['Tale', 'Tai_Le'],
  9251. ['Talu', 'New_Tai_Lue'],
  9252. ['Taml', 'Tamil'],
  9253. ['Tang', 'Tangut'],
  9254. ['Tavt', 'Tai_Viet'],
  9255. ['Telu', 'Telugu'],
  9256. ['Tfng', 'Tifinagh'],
  9257. ['Tglg', 'Tagalog'],
  9258. ['Thaa', 'Thaana'],
  9259. ['Thai', 'Thai'],
  9260. ['Tibt', 'Tibetan'],
  9261. ['Tirh', 'Tirhuta'],
  9262. ['Ugar', 'Ugaritic'],
  9263. ['Vaii', 'Vai'],
  9264. ['Wara', 'Warang_Citi'],
  9265. ['Xpeo', 'Old_Persian'],
  9266. ['Xsux', 'Cuneiform'],
  9267. ['Yiii', 'Yi'],
  9268. ['Zanb', 'Zanabazar_Square'],
  9269. ['Zinh', 'Inherited'],
  9270. ['Qaai', 'Inherited'],
  9271. ['Zyyy', 'Common'],
  9272. ['Zzzz', 'Unknown'],
  9273. ['Adlam', 'Adlam'],
  9274. ['Caucasian_Albanian', 'Caucasian_Albanian'],
  9275. ['Arabic', 'Arabic'],
  9276. ['Imperial_Aramaic', 'Imperial_Aramaic'],
  9277. ['Armenian', 'Armenian'],
  9278. ['Avestan', 'Avestan'],
  9279. ['Balinese', 'Balinese'],
  9280. ['Bamum', 'Bamum'],
  9281. ['Bassa_Vah', 'Bassa_Vah'],
  9282. ['Batak', 'Batak'],
  9283. ['Bengali', 'Bengali'],
  9284. ['Bhaiksuki', 'Bhaiksuki'],
  9285. ['Bopomofo', 'Bopomofo'],
  9286. ['Brahmi', 'Brahmi'],
  9287. ['Braille', 'Braille'],
  9288. ['Buginese', 'Buginese'],
  9289. ['Buhid', 'Buhid'],
  9290. ['Chakma', 'Chakma'],
  9291. ['Canadian_Aboriginal', 'Canadian_Aboriginal'],
  9292. ['Carian', 'Carian'],
  9293. ['Cherokee', 'Cherokee'],
  9294. ['Coptic', 'Coptic'],
  9295. ['Cypriot', 'Cypriot'],
  9296. ['Cyrillic', 'Cyrillic'],
  9297. ['Devanagari', 'Devanagari'],
  9298. ['Deseret', 'Deseret'],
  9299. ['Duployan', 'Duployan'],
  9300. ['Egyptian_Hieroglyphs', 'Egyptian_Hieroglyphs'],
  9301. ['Elbasan', 'Elbasan'],
  9302. ['Ethiopic', 'Ethiopic'],
  9303. ['Georgian', 'Georgian'],
  9304. ['Glagolitic', 'Glagolitic'],
  9305. ['Masaram_Gondi', 'Masaram_Gondi'],
  9306. ['Gothic', 'Gothic'],
  9307. ['Grantha', 'Grantha'],
  9308. ['Greek', 'Greek'],
  9309. ['Gujarati', 'Gujarati'],
  9310. ['Gurmukhi', 'Gurmukhi'],
  9311. ['Hangul', 'Hangul'],
  9312. ['Han', 'Han'],
  9313. ['Hanunoo', 'Hanunoo'],
  9314. ['Hatran', 'Hatran'],
  9315. ['Hebrew', 'Hebrew'],
  9316. ['Hiragana', 'Hiragana'],
  9317. ['Anatolian_Hieroglyphs', 'Anatolian_Hieroglyphs'],
  9318. ['Pahawh_Hmong', 'Pahawh_Hmong'],
  9319. ['Katakana_Or_Hiragana', 'Katakana_Or_Hiragana'],
  9320. ['Old_Hungarian', 'Old_Hungarian'],
  9321. ['Old_Italic', 'Old_Italic'],
  9322. ['Javanese', 'Javanese'],
  9323. ['Kayah_Li', 'Kayah_Li'],
  9324. ['Katakana', 'Katakana'],
  9325. ['Kharoshthi', 'Kharoshthi'],
  9326. ['Khmer', 'Khmer'],
  9327. ['Khojki', 'Khojki'],
  9328. ['Kannada', 'Kannada'],
  9329. ['Kaithi', 'Kaithi'],
  9330. ['Tai_Tham', 'Tai_Tham'],
  9331. ['Lao', 'Lao'],
  9332. ['Latin', 'Latin'],
  9333. ['Lepcha', 'Lepcha'],
  9334. ['Limbu', 'Limbu'],
  9335. ['Linear_A', 'Linear_A'],
  9336. ['Linear_B', 'Linear_B'],
  9337. ['Lycian', 'Lycian'],
  9338. ['Lydian', 'Lydian'],
  9339. ['Mahajani', 'Mahajani'],
  9340. ['Mandaic', 'Mandaic'],
  9341. ['Manichaean', 'Manichaean'],
  9342. ['Marchen', 'Marchen'],
  9343. ['Mende_Kikakui', 'Mende_Kikakui'],
  9344. ['Meroitic_Cursive', 'Meroitic_Cursive'],
  9345. ['Meroitic_Hieroglyphs', 'Meroitic_Hieroglyphs'],
  9346. ['Malayalam', 'Malayalam'],
  9347. ['Mongolian', 'Mongolian'],
  9348. ['Mro', 'Mro'],
  9349. ['Meetei_Mayek', 'Meetei_Mayek'],
  9350. ['Multani', 'Multani'],
  9351. ['Myanmar', 'Myanmar'],
  9352. ['Old_North_Arabian', 'Old_North_Arabian'],
  9353. ['Nabataean', 'Nabataean'],
  9354. ['Nko', 'Nko'],
  9355. ['Nushu', 'Nushu'],
  9356. ['Ogham', 'Ogham'],
  9357. ['Ol_Chiki', 'Ol_Chiki'],
  9358. ['Old_Turkic', 'Old_Turkic'],
  9359. ['Oriya', 'Oriya'],
  9360. ['Osage', 'Osage'],
  9361. ['Osmanya', 'Osmanya'],
  9362. ['Palmyrene', 'Palmyrene'],
  9363. ['Pau_Cin_Hau', 'Pau_Cin_Hau'],
  9364. ['Old_Permic', 'Old_Permic'],
  9365. ['Phags_Pa', 'Phags_Pa'],
  9366. ['Inscriptional_Pahlavi', 'Inscriptional_Pahlavi'],
  9367. ['Psalter_Pahlavi', 'Psalter_Pahlavi'],
  9368. ['Phoenician', 'Phoenician'],
  9369. ['Miao', 'Miao'],
  9370. ['Inscriptional_Parthian', 'Inscriptional_Parthian'],
  9371. ['Rejang', 'Rejang'],
  9372. ['Runic', 'Runic'],
  9373. ['Samaritan', 'Samaritan'],
  9374. ['Old_South_Arabian', 'Old_South_Arabian'],
  9375. ['Saurashtra', 'Saurashtra'],
  9376. ['SignWriting', 'SignWriting'],
  9377. ['Shavian', 'Shavian'],
  9378. ['Sharada', 'Sharada'],
  9379. ['Siddham', 'Siddham'],
  9380. ['Khudawadi', 'Khudawadi'],
  9381. ['Sinhala', 'Sinhala'],
  9382. ['Sora_Sompeng', 'Sora_Sompeng'],
  9383. ['Soyombo', 'Soyombo'],
  9384. ['Sundanese', 'Sundanese'],
  9385. ['Syloti_Nagri', 'Syloti_Nagri'],
  9386. ['Syriac', 'Syriac'],
  9387. ['Tagbanwa', 'Tagbanwa'],
  9388. ['Takri', 'Takri'],
  9389. ['Tai_Le', 'Tai_Le'],
  9390. ['New_Tai_Lue', 'New_Tai_Lue'],
  9391. ['Tamil', 'Tamil'],
  9392. ['Tangut', 'Tangut'],
  9393. ['Tai_Viet', 'Tai_Viet'],
  9394. ['Telugu', 'Telugu'],
  9395. ['Tifinagh', 'Tifinagh'],
  9396. ['Tagalog', 'Tagalog'],
  9397. ['Thaana', 'Thaana'],
  9398. ['Tibetan', 'Tibetan'],
  9399. ['Tirhuta', 'Tirhuta'],
  9400. ['Ugaritic', 'Ugaritic'],
  9401. ['Vai', 'Vai'],
  9402. ['Warang_Citi', 'Warang_Citi'],
  9403. ['Old_Persian', 'Old_Persian'],
  9404. ['Cuneiform', 'Cuneiform'],
  9405. ['Yi', 'Yi'],
  9406. ['Zanabazar_Square', 'Zanabazar_Square'],
  9407. ['Inherited', 'Inherited'],
  9408. ['Common', 'Common'],
  9409. ['Unknown', 'Unknown']
  9410. ])],
  9411. ['Script_Extensions', new Map([
  9412. ['Adlm', 'Adlam'],
  9413. ['Aghb', 'Caucasian_Albanian'],
  9414. ['Ahom', 'Ahom'],
  9415. ['Arab', 'Arabic'],
  9416. ['Armi', 'Imperial_Aramaic'],
  9417. ['Armn', 'Armenian'],
  9418. ['Avst', 'Avestan'],
  9419. ['Bali', 'Balinese'],
  9420. ['Bamu', 'Bamum'],
  9421. ['Bass', 'Bassa_Vah'],
  9422. ['Batk', 'Batak'],
  9423. ['Beng', 'Bengali'],
  9424. ['Bhks', 'Bhaiksuki'],
  9425. ['Bopo', 'Bopomofo'],
  9426. ['Brah', 'Brahmi'],
  9427. ['Brai', 'Braille'],
  9428. ['Bugi', 'Buginese'],
  9429. ['Buhd', 'Buhid'],
  9430. ['Cakm', 'Chakma'],
  9431. ['Cans', 'Canadian_Aboriginal'],
  9432. ['Cari', 'Carian'],
  9433. ['Cham', 'Cham'],
  9434. ['Cher', 'Cherokee'],
  9435. ['Copt', 'Coptic'],
  9436. ['Qaac', 'Coptic'],
  9437. ['Cprt', 'Cypriot'],
  9438. ['Cyrl', 'Cyrillic'],
  9439. ['Deva', 'Devanagari'],
  9440. ['Dsrt', 'Deseret'],
  9441. ['Dupl', 'Duployan'],
  9442. ['Egyp', 'Egyptian_Hieroglyphs'],
  9443. ['Elba', 'Elbasan'],
  9444. ['Ethi', 'Ethiopic'],
  9445. ['Geor', 'Georgian'],
  9446. ['Glag', 'Glagolitic'],
  9447. ['Gonm', 'Masaram_Gondi'],
  9448. ['Goth', 'Gothic'],
  9449. ['Gran', 'Grantha'],
  9450. ['Grek', 'Greek'],
  9451. ['Gujr', 'Gujarati'],
  9452. ['Guru', 'Gurmukhi'],
  9453. ['Hang', 'Hangul'],
  9454. ['Hani', 'Han'],
  9455. ['Hano', 'Hanunoo'],
  9456. ['Hatr', 'Hatran'],
  9457. ['Hebr', 'Hebrew'],
  9458. ['Hira', 'Hiragana'],
  9459. ['Hluw', 'Anatolian_Hieroglyphs'],
  9460. ['Hmng', 'Pahawh_Hmong'],
  9461. ['Hrkt', 'Katakana_Or_Hiragana'],
  9462. ['Hung', 'Old_Hungarian'],
  9463. ['Ital', 'Old_Italic'],
  9464. ['Java', 'Javanese'],
  9465. ['Kali', 'Kayah_Li'],
  9466. ['Kana', 'Katakana'],
  9467. ['Khar', 'Kharoshthi'],
  9468. ['Khmr', 'Khmer'],
  9469. ['Khoj', 'Khojki'],
  9470. ['Knda', 'Kannada'],
  9471. ['Kthi', 'Kaithi'],
  9472. ['Lana', 'Tai_Tham'],
  9473. ['Laoo', 'Lao'],
  9474. ['Latn', 'Latin'],
  9475. ['Lepc', 'Lepcha'],
  9476. ['Limb', 'Limbu'],
  9477. ['Lina', 'Linear_A'],
  9478. ['Linb', 'Linear_B'],
  9479. ['Lisu', 'Lisu'],
  9480. ['Lyci', 'Lycian'],
  9481. ['Lydi', 'Lydian'],
  9482. ['Mahj', 'Mahajani'],
  9483. ['Mand', 'Mandaic'],
  9484. ['Mani', 'Manichaean'],
  9485. ['Marc', 'Marchen'],
  9486. ['Mend', 'Mende_Kikakui'],
  9487. ['Merc', 'Meroitic_Cursive'],
  9488. ['Mero', 'Meroitic_Hieroglyphs'],
  9489. ['Mlym', 'Malayalam'],
  9490. ['Modi', 'Modi'],
  9491. ['Mong', 'Mongolian'],
  9492. ['Mroo', 'Mro'],
  9493. ['Mtei', 'Meetei_Mayek'],
  9494. ['Mult', 'Multani'],
  9495. ['Mymr', 'Myanmar'],
  9496. ['Narb', 'Old_North_Arabian'],
  9497. ['Nbat', 'Nabataean'],
  9498. ['Newa', 'Newa'],
  9499. ['Nkoo', 'Nko'],
  9500. ['Nshu', 'Nushu'],
  9501. ['Ogam', 'Ogham'],
  9502. ['Olck', 'Ol_Chiki'],
  9503. ['Orkh', 'Old_Turkic'],
  9504. ['Orya', 'Oriya'],
  9505. ['Osge', 'Osage'],
  9506. ['Osma', 'Osmanya'],
  9507. ['Palm', 'Palmyrene'],
  9508. ['Pauc', 'Pau_Cin_Hau'],
  9509. ['Perm', 'Old_Permic'],
  9510. ['Phag', 'Phags_Pa'],
  9511. ['Phli', 'Inscriptional_Pahlavi'],
  9512. ['Phlp', 'Psalter_Pahlavi'],
  9513. ['Phnx', 'Phoenician'],
  9514. ['Plrd', 'Miao'],
  9515. ['Prti', 'Inscriptional_Parthian'],
  9516. ['Rjng', 'Rejang'],
  9517. ['Runr', 'Runic'],
  9518. ['Samr', 'Samaritan'],
  9519. ['Sarb', 'Old_South_Arabian'],
  9520. ['Saur', 'Saurashtra'],
  9521. ['Sgnw', 'SignWriting'],
  9522. ['Shaw', 'Shavian'],
  9523. ['Shrd', 'Sharada'],
  9524. ['Sidd', 'Siddham'],
  9525. ['Sind', 'Khudawadi'],
  9526. ['Sinh', 'Sinhala'],
  9527. ['Sora', 'Sora_Sompeng'],
  9528. ['Soyo', 'Soyombo'],
  9529. ['Sund', 'Sundanese'],
  9530. ['Sylo', 'Syloti_Nagri'],
  9531. ['Syrc', 'Syriac'],
  9532. ['Tagb', 'Tagbanwa'],
  9533. ['Takr', 'Takri'],
  9534. ['Tale', 'Tai_Le'],
  9535. ['Talu', 'New_Tai_Lue'],
  9536. ['Taml', 'Tamil'],
  9537. ['Tang', 'Tangut'],
  9538. ['Tavt', 'Tai_Viet'],
  9539. ['Telu', 'Telugu'],
  9540. ['Tfng', 'Tifinagh'],
  9541. ['Tglg', 'Tagalog'],
  9542. ['Thaa', 'Thaana'],
  9543. ['Thai', 'Thai'],
  9544. ['Tibt', 'Tibetan'],
  9545. ['Tirh', 'Tirhuta'],
  9546. ['Ugar', 'Ugaritic'],
  9547. ['Vaii', 'Vai'],
  9548. ['Wara', 'Warang_Citi'],
  9549. ['Xpeo', 'Old_Persian'],
  9550. ['Xsux', 'Cuneiform'],
  9551. ['Yiii', 'Yi'],
  9552. ['Zanb', 'Zanabazar_Square'],
  9553. ['Zinh', 'Inherited'],
  9554. ['Qaai', 'Inherited'],
  9555. ['Zyyy', 'Common'],
  9556. ['Zzzz', 'Unknown'],
  9557. ['Adlam', 'Adlam'],
  9558. ['Caucasian_Albanian', 'Caucasian_Albanian'],
  9559. ['Arabic', 'Arabic'],
  9560. ['Imperial_Aramaic', 'Imperial_Aramaic'],
  9561. ['Armenian', 'Armenian'],
  9562. ['Avestan', 'Avestan'],
  9563. ['Balinese', 'Balinese'],
  9564. ['Bamum', 'Bamum'],
  9565. ['Bassa_Vah', 'Bassa_Vah'],
  9566. ['Batak', 'Batak'],
  9567. ['Bengali', 'Bengali'],
  9568. ['Bhaiksuki', 'Bhaiksuki'],
  9569. ['Bopomofo', 'Bopomofo'],
  9570. ['Brahmi', 'Brahmi'],
  9571. ['Braille', 'Braille'],
  9572. ['Buginese', 'Buginese'],
  9573. ['Buhid', 'Buhid'],
  9574. ['Chakma', 'Chakma'],
  9575. ['Canadian_Aboriginal', 'Canadian_Aboriginal'],
  9576. ['Carian', 'Carian'],
  9577. ['Cherokee', 'Cherokee'],
  9578. ['Coptic', 'Coptic'],
  9579. ['Cypriot', 'Cypriot'],
  9580. ['Cyrillic', 'Cyrillic'],
  9581. ['Devanagari', 'Devanagari'],
  9582. ['Deseret', 'Deseret'],
  9583. ['Duployan', 'Duployan'],
  9584. ['Egyptian_Hieroglyphs', 'Egyptian_Hieroglyphs'],
  9585. ['Elbasan', 'Elbasan'],
  9586. ['Ethiopic', 'Ethiopic'],
  9587. ['Georgian', 'Georgian'],
  9588. ['Glagolitic', 'Glagolitic'],
  9589. ['Masaram_Gondi', 'Masaram_Gondi'],
  9590. ['Gothic', 'Gothic'],
  9591. ['Grantha', 'Grantha'],
  9592. ['Greek', 'Greek'],
  9593. ['Gujarati', 'Gujarati'],
  9594. ['Gurmukhi', 'Gurmukhi'],
  9595. ['Hangul', 'Hangul'],
  9596. ['Han', 'Han'],
  9597. ['Hanunoo', 'Hanunoo'],
  9598. ['Hatran', 'Hatran'],
  9599. ['Hebrew', 'Hebrew'],
  9600. ['Hiragana', 'Hiragana'],
  9601. ['Anatolian_Hieroglyphs', 'Anatolian_Hieroglyphs'],
  9602. ['Pahawh_Hmong', 'Pahawh_Hmong'],
  9603. ['Katakana_Or_Hiragana', 'Katakana_Or_Hiragana'],
  9604. ['Old_Hungarian', 'Old_Hungarian'],
  9605. ['Old_Italic', 'Old_Italic'],
  9606. ['Javanese', 'Javanese'],
  9607. ['Kayah_Li', 'Kayah_Li'],
  9608. ['Katakana', 'Katakana'],
  9609. ['Kharoshthi', 'Kharoshthi'],
  9610. ['Khmer', 'Khmer'],
  9611. ['Khojki', 'Khojki'],
  9612. ['Kannada', 'Kannada'],
  9613. ['Kaithi', 'Kaithi'],
  9614. ['Tai_Tham', 'Tai_Tham'],
  9615. ['Lao', 'Lao'],
  9616. ['Latin', 'Latin'],
  9617. ['Lepcha', 'Lepcha'],
  9618. ['Limbu', 'Limbu'],
  9619. ['Linear_A', 'Linear_A'],
  9620. ['Linear_B', 'Linear_B'],
  9621. ['Lycian', 'Lycian'],
  9622. ['Lydian', 'Lydian'],
  9623. ['Mahajani', 'Mahajani'],
  9624. ['Mandaic', 'Mandaic'],
  9625. ['Manichaean', 'Manichaean'],
  9626. ['Marchen', 'Marchen'],
  9627. ['Mende_Kikakui', 'Mende_Kikakui'],
  9628. ['Meroitic_Cursive', 'Meroitic_Cursive'],
  9629. ['Meroitic_Hieroglyphs', 'Meroitic_Hieroglyphs'],
  9630. ['Malayalam', 'Malayalam'],
  9631. ['Mongolian', 'Mongolian'],
  9632. ['Mro', 'Mro'],
  9633. ['Meetei_Mayek', 'Meetei_Mayek'],
  9634. ['Multani', 'Multani'],
  9635. ['Myanmar', 'Myanmar'],
  9636. ['Old_North_Arabian', 'Old_North_Arabian'],
  9637. ['Nabataean', 'Nabataean'],
  9638. ['Nko', 'Nko'],
  9639. ['Nushu', 'Nushu'],
  9640. ['Ogham', 'Ogham'],
  9641. ['Ol_Chiki', 'Ol_Chiki'],
  9642. ['Old_Turkic', 'Old_Turkic'],
  9643. ['Oriya', 'Oriya'],
  9644. ['Osage', 'Osage'],
  9645. ['Osmanya', 'Osmanya'],
  9646. ['Palmyrene', 'Palmyrene'],
  9647. ['Pau_Cin_Hau', 'Pau_Cin_Hau'],
  9648. ['Old_Permic', 'Old_Permic'],
  9649. ['Phags_Pa', 'Phags_Pa'],
  9650. ['Inscriptional_Pahlavi', 'Inscriptional_Pahlavi'],
  9651. ['Psalter_Pahlavi', 'Psalter_Pahlavi'],
  9652. ['Phoenician', 'Phoenician'],
  9653. ['Miao', 'Miao'],
  9654. ['Inscriptional_Parthian', 'Inscriptional_Parthian'],
  9655. ['Rejang', 'Rejang'],
  9656. ['Runic', 'Runic'],
  9657. ['Samaritan', 'Samaritan'],
  9658. ['Old_South_Arabian', 'Old_South_Arabian'],
  9659. ['Saurashtra', 'Saurashtra'],
  9660. ['SignWriting', 'SignWriting'],
  9661. ['Shavian', 'Shavian'],
  9662. ['Sharada', 'Sharada'],
  9663. ['Siddham', 'Siddham'],
  9664. ['Khudawadi', 'Khudawadi'],
  9665. ['Sinhala', 'Sinhala'],
  9666. ['Sora_Sompeng', 'Sora_Sompeng'],
  9667. ['Soyombo', 'Soyombo'],
  9668. ['Sundanese', 'Sundanese'],
  9669. ['Syloti_Nagri', 'Syloti_Nagri'],
  9670. ['Syriac', 'Syriac'],
  9671. ['Tagbanwa', 'Tagbanwa'],
  9672. ['Takri', 'Takri'],
  9673. ['Tai_Le', 'Tai_Le'],
  9674. ['New_Tai_Lue', 'New_Tai_Lue'],
  9675. ['Tamil', 'Tamil'],
  9676. ['Tangut', 'Tangut'],
  9677. ['Tai_Viet', 'Tai_Viet'],
  9678. ['Telugu', 'Telugu'],
  9679. ['Tifinagh', 'Tifinagh'],
  9680. ['Tagalog', 'Tagalog'],
  9681. ['Thaana', 'Thaana'],
  9682. ['Tibetan', 'Tibetan'],
  9683. ['Tirhuta', 'Tirhuta'],
  9684. ['Ugaritic', 'Ugaritic'],
  9685. ['Vai', 'Vai'],
  9686. ['Warang_Citi', 'Warang_Citi'],
  9687. ['Old_Persian', 'Old_Persian'],
  9688. ['Cuneiform', 'Cuneiform'],
  9689. ['Yi', 'Yi'],
  9690. ['Zanabazar_Square', 'Zanabazar_Square'],
  9691. ['Inherited', 'Inherited'],
  9692. ['Common', 'Common'],
  9693. ['Unknown', 'Unknown']
  9694. ])]
  9695. ]);
  9696. 'use strict';
  9697. const matchPropertyValue = function(property, value) {
  9698. const aliasToValue = mappings.get(property);
  9699. if (!aliasToValue) {
  9700. throw new Error(`Unknown property \`${ property }\`.`);
  9701. }
  9702. const canonicalValue = aliasToValue.get(value);
  9703. if (canonicalValue) {
  9704. return canonicalValue;
  9705. }
  9706. throw new Error(
  9707. `Unknown value \`${ value }\` for property \`${ property }\`.`
  9708. );
  9709. };
  9710. var unicodeMatchPropertyValueEcmascript = matchPropertyValue;
  9711. var iuMappings = new Map([
  9712. [0x4B, 0x212A],
  9713. [0x53, 0x17F],
  9714. [0x6B, 0x212A],
  9715. [0x73, 0x17F],
  9716. [0xB5, 0x39C],
  9717. [0xC5, 0x212B],
  9718. [0xDF, 0x1E9E],
  9719. [0xE5, 0x212B],
  9720. [0x17F, 0x53],
  9721. [0x1C4, 0x1C5],
  9722. [0x1C5, 0x1C4],
  9723. [0x1C7, 0x1C8],
  9724. [0x1C8, 0x1C7],
  9725. [0x1CA, 0x1CB],
  9726. [0x1CB, 0x1CA],
  9727. [0x1F1, 0x1F2],
  9728. [0x1F2, 0x1F1],
  9729. [0x26A, 0xA7AE],
  9730. [0x29D, 0xA7B2],
  9731. [0x345, 0x1FBE],
  9732. [0x392, 0x3D0],
  9733. [0x395, 0x3F5],
  9734. [0x398, 0x3F4],
  9735. [0x399, 0x1FBE],
  9736. [0x39A, 0x3F0],
  9737. [0x39C, 0xB5],
  9738. [0x3A0, 0x3D6],
  9739. [0x3A1, 0x3F1],
  9740. [0x3A3, 0x3C2],
  9741. [0x3A6, 0x3D5],
  9742. [0x3A9, 0x2126],
  9743. [0x3B8, 0x3F4],
  9744. [0x3C2, 0x3A3],
  9745. [0x3C9, 0x2126],
  9746. [0x3D0, 0x392],
  9747. [0x3D1, 0x3F4],
  9748. [0x3D5, 0x3A6],
  9749. [0x3D6, 0x3A0],
  9750. [0x3F0, 0x39A],
  9751. [0x3F1, 0x3A1],
  9752. [0x3F4, [
  9753. 0x398,
  9754. 0x3D1,
  9755. 0x3B8
  9756. ]],
  9757. [0x3F5, 0x395],
  9758. [0x412, 0x1C80],
  9759. [0x414, 0x1C81],
  9760. [0x41E, 0x1C82],
  9761. [0x421, 0x1C83],
  9762. [0x422, 0x1C85],
  9763. [0x42A, 0x1C86],
  9764. [0x432, 0x1C80],
  9765. [0x434, 0x1C81],
  9766. [0x43E, 0x1C82],
  9767. [0x441, 0x1C83],
  9768. [0x442, [
  9769. 0x1C84,
  9770. 0x1C85
  9771. ]],
  9772. [0x44A, 0x1C86],
  9773. [0x462, 0x1C87],
  9774. [0x463, 0x1C87],
  9775. [0x13A0, 0xAB70],
  9776. [0x13A1, 0xAB71],
  9777. [0x13A2, 0xAB72],
  9778. [0x13A3, 0xAB73],
  9779. [0x13A4, 0xAB74],
  9780. [0x13A5, 0xAB75],
  9781. [0x13A6, 0xAB76],
  9782. [0x13A7, 0xAB77],
  9783. [0x13A8, 0xAB78],
  9784. [0x13A9, 0xAB79],
  9785. [0x13AA, 0xAB7A],
  9786. [0x13AB, 0xAB7B],
  9787. [0x13AC, 0xAB7C],
  9788. [0x13AD, 0xAB7D],
  9789. [0x13AE, 0xAB7E],
  9790. [0x13AF, 0xAB7F],
  9791. [0x13B0, 0xAB80],
  9792. [0x13B1, 0xAB81],
  9793. [0x13B2, 0xAB82],
  9794. [0x13B3, 0xAB83],
  9795. [0x13B4, 0xAB84],
  9796. [0x13B5, 0xAB85],
  9797. [0x13B6, 0xAB86],
  9798. [0x13B7, 0xAB87],
  9799. [0x13B8, 0xAB88],
  9800. [0x13B9, 0xAB89],
  9801. [0x13BA, 0xAB8A],
  9802. [0x13BB, 0xAB8B],
  9803. [0x13BC, 0xAB8C],
  9804. [0x13BD, 0xAB8D],
  9805. [0x13BE, 0xAB8E],
  9806. [0x13BF, 0xAB8F],
  9807. [0x13C0, 0xAB90],
  9808. [0x13C1, 0xAB91],
  9809. [0x13C2, 0xAB92],
  9810. [0x13C3, 0xAB93],
  9811. [0x13C4, 0xAB94],
  9812. [0x13C5, 0xAB95],
  9813. [0x13C6, 0xAB96],
  9814. [0x13C7, 0xAB97],
  9815. [0x13C8, 0xAB98],
  9816. [0x13C9, 0xAB99],
  9817. [0x13CA, 0xAB9A],
  9818. [0x13CB, 0xAB9B],
  9819. [0x13CC, 0xAB9C],
  9820. [0x13CD, 0xAB9D],
  9821. [0x13CE, 0xAB9E],
  9822. [0x13CF, 0xAB9F],
  9823. [0x13D0, 0xABA0],
  9824. [0x13D1, 0xABA1],
  9825. [0x13D2, 0xABA2],
  9826. [0x13D3, 0xABA3],
  9827. [0x13D4, 0xABA4],
  9828. [0x13D5, 0xABA5],
  9829. [0x13D6, 0xABA6],
  9830. [0x13D7, 0xABA7],
  9831. [0x13D8, 0xABA8],
  9832. [0x13D9, 0xABA9],
  9833. [0x13DA, 0xABAA],
  9834. [0x13DB, 0xABAB],
  9835. [0x13DC, 0xABAC],
  9836. [0x13DD, 0xABAD],
  9837. [0x13DE, 0xABAE],
  9838. [0x13DF, 0xABAF],
  9839. [0x13E0, 0xABB0],
  9840. [0x13E1, 0xABB1],
  9841. [0x13E2, 0xABB2],
  9842. [0x13E3, 0xABB3],
  9843. [0x13E4, 0xABB4],
  9844. [0x13E5, 0xABB5],
  9845. [0x13E6, 0xABB6],
  9846. [0x13E7, 0xABB7],
  9847. [0x13E8, 0xABB8],
  9848. [0x13E9, 0xABB9],
  9849. [0x13EA, 0xABBA],
  9850. [0x13EB, 0xABBB],
  9851. [0x13EC, 0xABBC],
  9852. [0x13ED, 0xABBD],
  9853. [0x13EE, 0xABBE],
  9854. [0x13EF, 0xABBF],
  9855. [0x13F0, 0x13F8],
  9856. [0x13F1, 0x13F9],
  9857. [0x13F2, 0x13FA],
  9858. [0x13F3, 0x13FB],
  9859. [0x13F4, 0x13FC],
  9860. [0x13F5, 0x13FD],
  9861. [0x13F8, 0x13F0],
  9862. [0x13F9, 0x13F1],
  9863. [0x13FA, 0x13F2],
  9864. [0x13FB, 0x13F3],
  9865. [0x13FC, 0x13F4],
  9866. [0x13FD, 0x13F5],
  9867. [0x1C80, [
  9868. 0x412,
  9869. 0x432
  9870. ]],
  9871. [0x1C81, [
  9872. 0x414,
  9873. 0x434
  9874. ]],
  9875. [0x1C82, [
  9876. 0x41E,
  9877. 0x43E
  9878. ]],
  9879. [0x1C83, [
  9880. 0x421,
  9881. 0x441
  9882. ]],
  9883. [0x1C84, [
  9884. 0x1C85,
  9885. 0x442
  9886. ]],
  9887. [0x1C85, [
  9888. 0x422,
  9889. 0x1C84,
  9890. 0x442
  9891. ]],
  9892. [0x1C86, [
  9893. 0x42A,
  9894. 0x44A
  9895. ]],
  9896. [0x1C87, [
  9897. 0x462,
  9898. 0x463
  9899. ]],
  9900. [0x1C88, [
  9901. 0xA64A,
  9902. 0xA64B
  9903. ]],
  9904. [0x1E60, 0x1E9B],
  9905. [0x1E9B, 0x1E60],
  9906. [0x1E9E, 0xDF],
  9907. [0x1F80, 0x1F88],
  9908. [0x1F81, 0x1F89],
  9909. [0x1F82, 0x1F8A],
  9910. [0x1F83, 0x1F8B],
  9911. [0x1F84, 0x1F8C],
  9912. [0x1F85, 0x1F8D],
  9913. [0x1F86, 0x1F8E],
  9914. [0x1F87, 0x1F8F],
  9915. [0x1F88, 0x1F80],
  9916. [0x1F89, 0x1F81],
  9917. [0x1F8A, 0x1F82],
  9918. [0x1F8B, 0x1F83],
  9919. [0x1F8C, 0x1F84],
  9920. [0x1F8D, 0x1F85],
  9921. [0x1F8E, 0x1F86],
  9922. [0x1F8F, 0x1F87],
  9923. [0x1F90, 0x1F98],
  9924. [0x1F91, 0x1F99],
  9925. [0x1F92, 0x1F9A],
  9926. [0x1F93, 0x1F9B],
  9927. [0x1F94, 0x1F9C],
  9928. [0x1F95, 0x1F9D],
  9929. [0x1F96, 0x1F9E],
  9930. [0x1F97, 0x1F9F],
  9931. [0x1F98, 0x1F90],
  9932. [0x1F99, 0x1F91],
  9933. [0x1F9A, 0x1F92],
  9934. [0x1F9B, 0x1F93],
  9935. [0x1F9C, 0x1F94],
  9936. [0x1F9D, 0x1F95],
  9937. [0x1F9E, 0x1F96],
  9938. [0x1F9F, 0x1F97],
  9939. [0x1FA0, 0x1FA8],
  9940. [0x1FA1, 0x1FA9],
  9941. [0x1FA2, 0x1FAA],
  9942. [0x1FA3, 0x1FAB],
  9943. [0x1FA4, 0x1FAC],
  9944. [0x1FA5, 0x1FAD],
  9945. [0x1FA6, 0x1FAE],
  9946. [0x1FA7, 0x1FAF],
  9947. [0x1FA8, 0x1FA0],
  9948. [0x1FA9, 0x1FA1],
  9949. [0x1FAA, 0x1FA2],
  9950. [0x1FAB, 0x1FA3],
  9951. [0x1FAC, 0x1FA4],
  9952. [0x1FAD, 0x1FA5],
  9953. [0x1FAE, 0x1FA6],
  9954. [0x1FAF, 0x1FA7],
  9955. [0x1FB3, 0x1FBC],
  9956. [0x1FBC, 0x1FB3],
  9957. [0x1FBE, [
  9958. 0x345,
  9959. 0x399
  9960. ]],
  9961. [0x1FC3, 0x1FCC],
  9962. [0x1FCC, 0x1FC3],
  9963. [0x1FF3, 0x1FFC],
  9964. [0x1FFC, 0x1FF3],
  9965. [0x2126, [
  9966. 0x3A9,
  9967. 0x3C9
  9968. ]],
  9969. [0x212A, 0x4B],
  9970. [0x212B, [
  9971. 0xC5,
  9972. 0xE5
  9973. ]],
  9974. [0xA64A, 0x1C88],
  9975. [0xA64B, 0x1C88],
  9976. [0xA7AE, 0x26A],
  9977. [0xA7B2, 0x29D],
  9978. [0xA7B3, 0xAB53],
  9979. [0xA7B4, 0xA7B5],
  9980. [0xA7B5, 0xA7B4],
  9981. [0xA7B6, 0xA7B7],
  9982. [0xA7B7, 0xA7B6],
  9983. [0xAB53, 0xA7B3],
  9984. [0xAB70, 0x13A0],
  9985. [0xAB71, 0x13A1],
  9986. [0xAB72, 0x13A2],
  9987. [0xAB73, 0x13A3],
  9988. [0xAB74, 0x13A4],
  9989. [0xAB75, 0x13A5],
  9990. [0xAB76, 0x13A6],
  9991. [0xAB77, 0x13A7],
  9992. [0xAB78, 0x13A8],
  9993. [0xAB79, 0x13A9],
  9994. [0xAB7A, 0x13AA],
  9995. [0xAB7B, 0x13AB],
  9996. [0xAB7C, 0x13AC],
  9997. [0xAB7D, 0x13AD],
  9998. [0xAB7E, 0x13AE],
  9999. [0xAB7F, 0x13AF],
  10000. [0xAB80, 0x13B0],
  10001. [0xAB81, 0x13B1],
  10002. [0xAB82, 0x13B2],
  10003. [0xAB83, 0x13B3],
  10004. [0xAB84, 0x13B4],
  10005. [0xAB85, 0x13B5],
  10006. [0xAB86, 0x13B6],
  10007. [0xAB87, 0x13B7],
  10008. [0xAB88, 0x13B8],
  10009. [0xAB89, 0x13B9],
  10010. [0xAB8A, 0x13BA],
  10011. [0xAB8B, 0x13BB],
  10012. [0xAB8C, 0x13BC],
  10013. [0xAB8D, 0x13BD],
  10014. [0xAB8E, 0x13BE],
  10015. [0xAB8F, 0x13BF],
  10016. [0xAB90, 0x13C0],
  10017. [0xAB91, 0x13C1],
  10018. [0xAB92, 0x13C2],
  10019. [0xAB93, 0x13C3],
  10020. [0xAB94, 0x13C4],
  10021. [0xAB95, 0x13C5],
  10022. [0xAB96, 0x13C6],
  10023. [0xAB97, 0x13C7],
  10024. [0xAB98, 0x13C8],
  10025. [0xAB99, 0x13C9],
  10026. [0xAB9A, 0x13CA],
  10027. [0xAB9B, 0x13CB],
  10028. [0xAB9C, 0x13CC],
  10029. [0xAB9D, 0x13CD],
  10030. [0xAB9E, 0x13CE],
  10031. [0xAB9F, 0x13CF],
  10032. [0xABA0, 0x13D0],
  10033. [0xABA1, 0x13D1],
  10034. [0xABA2, 0x13D2],
  10035. [0xABA3, 0x13D3],
  10036. [0xABA4, 0x13D4],
  10037. [0xABA5, 0x13D5],
  10038. [0xABA6, 0x13D6],
  10039. [0xABA7, 0x13D7],
  10040. [0xABA8, 0x13D8],
  10041. [0xABA9, 0x13D9],
  10042. [0xABAA, 0x13DA],
  10043. [0xABAB, 0x13DB],
  10044. [0xABAC, 0x13DC],
  10045. [0xABAD, 0x13DD],
  10046. [0xABAE, 0x13DE],
  10047. [0xABAF, 0x13DF],
  10048. [0xABB0, 0x13E0],
  10049. [0xABB1, 0x13E1],
  10050. [0xABB2, 0x13E2],
  10051. [0xABB3, 0x13E3],
  10052. [0xABB4, 0x13E4],
  10053. [0xABB5, 0x13E5],
  10054. [0xABB6, 0x13E6],
  10055. [0xABB7, 0x13E7],
  10056. [0xABB8, 0x13E8],
  10057. [0xABB9, 0x13E9],
  10058. [0xABBA, 0x13EA],
  10059. [0xABBB, 0x13EB],
  10060. [0xABBC, 0x13EC],
  10061. [0xABBD, 0x13ED],
  10062. [0xABBE, 0x13EE],
  10063. [0xABBF, 0x13EF],
  10064. [0x10400, 0x10428],
  10065. [0x10401, 0x10429],
  10066. [0x10402, 0x1042A],
  10067. [0x10403, 0x1042B],
  10068. [0x10404, 0x1042C],
  10069. [0x10405, 0x1042D],
  10070. [0x10406, 0x1042E],
  10071. [0x10407, 0x1042F],
  10072. [0x10408, 0x10430],
  10073. [0x10409, 0x10431],
  10074. [0x1040A, 0x10432],
  10075. [0x1040B, 0x10433],
  10076. [0x1040C, 0x10434],
  10077. [0x1040D, 0x10435],
  10078. [0x1040E, 0x10436],
  10079. [0x1040F, 0x10437],
  10080. [0x10410, 0x10438],
  10081. [0x10411, 0x10439],
  10082. [0x10412, 0x1043A],
  10083. [0x10413, 0x1043B],
  10084. [0x10414, 0x1043C],
  10085. [0x10415, 0x1043D],
  10086. [0x10416, 0x1043E],
  10087. [0x10417, 0x1043F],
  10088. [0x10418, 0x10440],
  10089. [0x10419, 0x10441],
  10090. [0x1041A, 0x10442],
  10091. [0x1041B, 0x10443],
  10092. [0x1041C, 0x10444],
  10093. [0x1041D, 0x10445],
  10094. [0x1041E, 0x10446],
  10095. [0x1041F, 0x10447],
  10096. [0x10420, 0x10448],
  10097. [0x10421, 0x10449],
  10098. [0x10422, 0x1044A],
  10099. [0x10423, 0x1044B],
  10100. [0x10424, 0x1044C],
  10101. [0x10425, 0x1044D],
  10102. [0x10426, 0x1044E],
  10103. [0x10427, 0x1044F],
  10104. [0x10428, 0x10400],
  10105. [0x10429, 0x10401],
  10106. [0x1042A, 0x10402],
  10107. [0x1042B, 0x10403],
  10108. [0x1042C, 0x10404],
  10109. [0x1042D, 0x10405],
  10110. [0x1042E, 0x10406],
  10111. [0x1042F, 0x10407],
  10112. [0x10430, 0x10408],
  10113. [0x10431, 0x10409],
  10114. [0x10432, 0x1040A],
  10115. [0x10433, 0x1040B],
  10116. [0x10434, 0x1040C],
  10117. [0x10435, 0x1040D],
  10118. [0x10436, 0x1040E],
  10119. [0x10437, 0x1040F],
  10120. [0x10438, 0x10410],
  10121. [0x10439, 0x10411],
  10122. [0x1043A, 0x10412],
  10123. [0x1043B, 0x10413],
  10124. [0x1043C, 0x10414],
  10125. [0x1043D, 0x10415],
  10126. [0x1043E, 0x10416],
  10127. [0x1043F, 0x10417],
  10128. [0x10440, 0x10418],
  10129. [0x10441, 0x10419],
  10130. [0x10442, 0x1041A],
  10131. [0x10443, 0x1041B],
  10132. [0x10444, 0x1041C],
  10133. [0x10445, 0x1041D],
  10134. [0x10446, 0x1041E],
  10135. [0x10447, 0x1041F],
  10136. [0x10448, 0x10420],
  10137. [0x10449, 0x10421],
  10138. [0x1044A, 0x10422],
  10139. [0x1044B, 0x10423],
  10140. [0x1044C, 0x10424],
  10141. [0x1044D, 0x10425],
  10142. [0x1044E, 0x10426],
  10143. [0x1044F, 0x10427],
  10144. [0x104B0, 0x104D8],
  10145. [0x104B1, 0x104D9],
  10146. [0x104B2, 0x104DA],
  10147. [0x104B3, 0x104DB],
  10148. [0x104B4, 0x104DC],
  10149. [0x104B5, 0x104DD],
  10150. [0x104B6, 0x104DE],
  10151. [0x104B7, 0x104DF],
  10152. [0x104B8, 0x104E0],
  10153. [0x104B9, 0x104E1],
  10154. [0x104BA, 0x104E2],
  10155. [0x104BB, 0x104E3],
  10156. [0x104BC, 0x104E4],
  10157. [0x104BD, 0x104E5],
  10158. [0x104BE, 0x104E6],
  10159. [0x104BF, 0x104E7],
  10160. [0x104C0, 0x104E8],
  10161. [0x104C1, 0x104E9],
  10162. [0x104C2, 0x104EA],
  10163. [0x104C3, 0x104EB],
  10164. [0x104C4, 0x104EC],
  10165. [0x104C5, 0x104ED],
  10166. [0x104C6, 0x104EE],
  10167. [0x104C7, 0x104EF],
  10168. [0x104C8, 0x104F0],
  10169. [0x104C9, 0x104F1],
  10170. [0x104CA, 0x104F2],
  10171. [0x104CB, 0x104F3],
  10172. [0x104CC, 0x104F4],
  10173. [0x104CD, 0x104F5],
  10174. [0x104CE, 0x104F6],
  10175. [0x104CF, 0x104F7],
  10176. [0x104D0, 0x104F8],
  10177. [0x104D1, 0x104F9],
  10178. [0x104D2, 0x104FA],
  10179. [0x104D3, 0x104FB],
  10180. [0x104D8, 0x104B0],
  10181. [0x104D9, 0x104B1],
  10182. [0x104DA, 0x104B2],
  10183. [0x104DB, 0x104B3],
  10184. [0x104DC, 0x104B4],
  10185. [0x104DD, 0x104B5],
  10186. [0x104DE, 0x104B6],
  10187. [0x104DF, 0x104B7],
  10188. [0x104E0, 0x104B8],
  10189. [0x104E1, 0x104B9],
  10190. [0x104E2, 0x104BA],
  10191. [0x104E3, 0x104BB],
  10192. [0x104E4, 0x104BC],
  10193. [0x104E5, 0x104BD],
  10194. [0x104E6, 0x104BE],
  10195. [0x104E7, 0x104BF],
  10196. [0x104E8, 0x104C0],
  10197. [0x104E9, 0x104C1],
  10198. [0x104EA, 0x104C2],
  10199. [0x104EB, 0x104C3],
  10200. [0x104EC, 0x104C4],
  10201. [0x104ED, 0x104C5],
  10202. [0x104EE, 0x104C6],
  10203. [0x104EF, 0x104C7],
  10204. [0x104F0, 0x104C8],
  10205. [0x104F1, 0x104C9],
  10206. [0x104F2, 0x104CA],
  10207. [0x104F3, 0x104CB],
  10208. [0x104F4, 0x104CC],
  10209. [0x104F5, 0x104CD],
  10210. [0x104F6, 0x104CE],
  10211. [0x104F7, 0x104CF],
  10212. [0x104F8, 0x104D0],
  10213. [0x104F9, 0x104D1],
  10214. [0x104FA, 0x104D2],
  10215. [0x104FB, 0x104D3],
  10216. [0x10C80, 0x10CC0],
  10217. [0x10C81, 0x10CC1],
  10218. [0x10C82, 0x10CC2],
  10219. [0x10C83, 0x10CC3],
  10220. [0x10C84, 0x10CC4],
  10221. [0x10C85, 0x10CC5],
  10222. [0x10C86, 0x10CC6],
  10223. [0x10C87, 0x10CC7],
  10224. [0x10C88, 0x10CC8],
  10225. [0x10C89, 0x10CC9],
  10226. [0x10C8A, 0x10CCA],
  10227. [0x10C8B, 0x10CCB],
  10228. [0x10C8C, 0x10CCC],
  10229. [0x10C8D, 0x10CCD],
  10230. [0x10C8E, 0x10CCE],
  10231. [0x10C8F, 0x10CCF],
  10232. [0x10C90, 0x10CD0],
  10233. [0x10C91, 0x10CD1],
  10234. [0x10C92, 0x10CD2],
  10235. [0x10C93, 0x10CD3],
  10236. [0x10C94, 0x10CD4],
  10237. [0x10C95, 0x10CD5],
  10238. [0x10C96, 0x10CD6],
  10239. [0x10C97, 0x10CD7],
  10240. [0x10C98, 0x10CD8],
  10241. [0x10C99, 0x10CD9],
  10242. [0x10C9A, 0x10CDA],
  10243. [0x10C9B, 0x10CDB],
  10244. [0x10C9C, 0x10CDC],
  10245. [0x10C9D, 0x10CDD],
  10246. [0x10C9E, 0x10CDE],
  10247. [0x10C9F, 0x10CDF],
  10248. [0x10CA0, 0x10CE0],
  10249. [0x10CA1, 0x10CE1],
  10250. [0x10CA2, 0x10CE2],
  10251. [0x10CA3, 0x10CE3],
  10252. [0x10CA4, 0x10CE4],
  10253. [0x10CA5, 0x10CE5],
  10254. [0x10CA6, 0x10CE6],
  10255. [0x10CA7, 0x10CE7],
  10256. [0x10CA8, 0x10CE8],
  10257. [0x10CA9, 0x10CE9],
  10258. [0x10CAA, 0x10CEA],
  10259. [0x10CAB, 0x10CEB],
  10260. [0x10CAC, 0x10CEC],
  10261. [0x10CAD, 0x10CED],
  10262. [0x10CAE, 0x10CEE],
  10263. [0x10CAF, 0x10CEF],
  10264. [0x10CB0, 0x10CF0],
  10265. [0x10CB1, 0x10CF1],
  10266. [0x10CB2, 0x10CF2],
  10267. [0x10CC0, 0x10C80],
  10268. [0x10CC1, 0x10C81],
  10269. [0x10CC2, 0x10C82],
  10270. [0x10CC3, 0x10C83],
  10271. [0x10CC4, 0x10C84],
  10272. [0x10CC5, 0x10C85],
  10273. [0x10CC6, 0x10C86],
  10274. [0x10CC7, 0x10C87],
  10275. [0x10CC8, 0x10C88],
  10276. [0x10CC9, 0x10C89],
  10277. [0x10CCA, 0x10C8A],
  10278. [0x10CCB, 0x10C8B],
  10279. [0x10CCC, 0x10C8C],
  10280. [0x10CCD, 0x10C8D],
  10281. [0x10CCE, 0x10C8E],
  10282. [0x10CCF, 0x10C8F],
  10283. [0x10CD0, 0x10C90],
  10284. [0x10CD1, 0x10C91],
  10285. [0x10CD2, 0x10C92],
  10286. [0x10CD3, 0x10C93],
  10287. [0x10CD4, 0x10C94],
  10288. [0x10CD5, 0x10C95],
  10289. [0x10CD6, 0x10C96],
  10290. [0x10CD7, 0x10C97],
  10291. [0x10CD8, 0x10C98],
  10292. [0x10CD9, 0x10C99],
  10293. [0x10CDA, 0x10C9A],
  10294. [0x10CDB, 0x10C9B],
  10295. [0x10CDC, 0x10C9C],
  10296. [0x10CDD, 0x10C9D],
  10297. [0x10CDE, 0x10C9E],
  10298. [0x10CDF, 0x10C9F],
  10299. [0x10CE0, 0x10CA0],
  10300. [0x10CE1, 0x10CA1],
  10301. [0x10CE2, 0x10CA2],
  10302. [0x10CE3, 0x10CA3],
  10303. [0x10CE4, 0x10CA4],
  10304. [0x10CE5, 0x10CA5],
  10305. [0x10CE6, 0x10CA6],
  10306. [0x10CE7, 0x10CA7],
  10307. [0x10CE8, 0x10CA8],
  10308. [0x10CE9, 0x10CA9],
  10309. [0x10CEA, 0x10CAA],
  10310. [0x10CEB, 0x10CAB],
  10311. [0x10CEC, 0x10CAC],
  10312. [0x10CED, 0x10CAD],
  10313. [0x10CEE, 0x10CAE],
  10314. [0x10CEF, 0x10CAF],
  10315. [0x10CF0, 0x10CB0],
  10316. [0x10CF1, 0x10CB1],
  10317. [0x10CF2, 0x10CB2],
  10318. [0x118A0, 0x118C0],
  10319. [0x118A1, 0x118C1],
  10320. [0x118A2, 0x118C2],
  10321. [0x118A3, 0x118C3],
  10322. [0x118A4, 0x118C4],
  10323. [0x118A5, 0x118C5],
  10324. [0x118A6, 0x118C6],
  10325. [0x118A7, 0x118C7],
  10326. [0x118A8, 0x118C8],
  10327. [0x118A9, 0x118C9],
  10328. [0x118AA, 0x118CA],
  10329. [0x118AB, 0x118CB],
  10330. [0x118AC, 0x118CC],
  10331. [0x118AD, 0x118CD],
  10332. [0x118AE, 0x118CE],
  10333. [0x118AF, 0x118CF],
  10334. [0x118B0, 0x118D0],
  10335. [0x118B1, 0x118D1],
  10336. [0x118B2, 0x118D2],
  10337. [0x118B3, 0x118D3],
  10338. [0x118B4, 0x118D4],
  10339. [0x118B5, 0x118D5],
  10340. [0x118B6, 0x118D6],
  10341. [0x118B7, 0x118D7],
  10342. [0x118B8, 0x118D8],
  10343. [0x118B9, 0x118D9],
  10344. [0x118BA, 0x118DA],
  10345. [0x118BB, 0x118DB],
  10346. [0x118BC, 0x118DC],
  10347. [0x118BD, 0x118DD],
  10348. [0x118BE, 0x118DE],
  10349. [0x118BF, 0x118DF],
  10350. [0x118C0, 0x118A0],
  10351. [0x118C1, 0x118A1],
  10352. [0x118C2, 0x118A2],
  10353. [0x118C3, 0x118A3],
  10354. [0x118C4, 0x118A4],
  10355. [0x118C5, 0x118A5],
  10356. [0x118C6, 0x118A6],
  10357. [0x118C7, 0x118A7],
  10358. [0x118C8, 0x118A8],
  10359. [0x118C9, 0x118A9],
  10360. [0x118CA, 0x118AA],
  10361. [0x118CB, 0x118AB],
  10362. [0x118CC, 0x118AC],
  10363. [0x118CD, 0x118AD],
  10364. [0x118CE, 0x118AE],
  10365. [0x118CF, 0x118AF],
  10366. [0x118D0, 0x118B0],
  10367. [0x118D1, 0x118B1],
  10368. [0x118D2, 0x118B2],
  10369. [0x118D3, 0x118B3],
  10370. [0x118D4, 0x118B4],
  10371. [0x118D5, 0x118B5],
  10372. [0x118D6, 0x118B6],
  10373. [0x118D7, 0x118B7],
  10374. [0x118D8, 0x118B8],
  10375. [0x118D9, 0x118B9],
  10376. [0x118DA, 0x118BA],
  10377. [0x118DB, 0x118BB],
  10378. [0x118DC, 0x118BC],
  10379. [0x118DD, 0x118BD],
  10380. [0x118DE, 0x118BE],
  10381. [0x118DF, 0x118BF],
  10382. [0x1E900, 0x1E922],
  10383. [0x1E901, 0x1E923],
  10384. [0x1E902, 0x1E924],
  10385. [0x1E903, 0x1E925],
  10386. [0x1E904, 0x1E926],
  10387. [0x1E905, 0x1E927],
  10388. [0x1E906, 0x1E928],
  10389. [0x1E907, 0x1E929],
  10390. [0x1E908, 0x1E92A],
  10391. [0x1E909, 0x1E92B],
  10392. [0x1E90A, 0x1E92C],
  10393. [0x1E90B, 0x1E92D],
  10394. [0x1E90C, 0x1E92E],
  10395. [0x1E90D, 0x1E92F],
  10396. [0x1E90E, 0x1E930],
  10397. [0x1E90F, 0x1E931],
  10398. [0x1E910, 0x1E932],
  10399. [0x1E911, 0x1E933],
  10400. [0x1E912, 0x1E934],
  10401. [0x1E913, 0x1E935],
  10402. [0x1E914, 0x1E936],
  10403. [0x1E915, 0x1E937],
  10404. [0x1E916, 0x1E938],
  10405. [0x1E917, 0x1E939],
  10406. [0x1E918, 0x1E93A],
  10407. [0x1E919, 0x1E93B],
  10408. [0x1E91A, 0x1E93C],
  10409. [0x1E91B, 0x1E93D],
  10410. [0x1E91C, 0x1E93E],
  10411. [0x1E91D, 0x1E93F],
  10412. [0x1E91E, 0x1E940],
  10413. [0x1E91F, 0x1E941],
  10414. [0x1E920, 0x1E942],
  10415. [0x1E921, 0x1E943],
  10416. [0x1E922, 0x1E900],
  10417. [0x1E923, 0x1E901],
  10418. [0x1E924, 0x1E902],
  10419. [0x1E925, 0x1E903],
  10420. [0x1E926, 0x1E904],
  10421. [0x1E927, 0x1E905],
  10422. [0x1E928, 0x1E906],
  10423. [0x1E929, 0x1E907],
  10424. [0x1E92A, 0x1E908],
  10425. [0x1E92B, 0x1E909],
  10426. [0x1E92C, 0x1E90A],
  10427. [0x1E92D, 0x1E90B],
  10428. [0x1E92E, 0x1E90C],
  10429. [0x1E92F, 0x1E90D],
  10430. [0x1E930, 0x1E90E],
  10431. [0x1E931, 0x1E90F],
  10432. [0x1E932, 0x1E910],
  10433. [0x1E933, 0x1E911],
  10434. [0x1E934, 0x1E912],
  10435. [0x1E935, 0x1E913],
  10436. [0x1E936, 0x1E914],
  10437. [0x1E937, 0x1E915],
  10438. [0x1E938, 0x1E916],
  10439. [0x1E939, 0x1E917],
  10440. [0x1E93A, 0x1E918],
  10441. [0x1E93B, 0x1E919],
  10442. [0x1E93C, 0x1E91A],
  10443. [0x1E93D, 0x1E91B],
  10444. [0x1E93E, 0x1E91C],
  10445. [0x1E93F, 0x1E91D],
  10446. [0x1E940, 0x1E91E],
  10447. [0x1E941, 0x1E91F],
  10448. [0x1E942, 0x1E920],
  10449. [0x1E943, 0x1E921]
  10450. ]);
  10451. // Generated using `npm run build`. Do not edit.
  10452. 'use strict';
  10453. var REGULAR = new Map([
  10454. ['d', regenerate()
  10455. .addRange(0x30, 0x39)],
  10456. ['D', regenerate()
  10457. .addRange(0x0, 0x2F)
  10458. .addRange(0x3A, 0xFFFF)],
  10459. ['s', regenerate(0x20, 0xA0, 0x1680, 0x202F, 0x205F, 0x3000, 0xFEFF)
  10460. .addRange(0x9, 0xD)
  10461. .addRange(0x2000, 0x200A)
  10462. .addRange(0x2028, 0x2029)],
  10463. ['S', regenerate()
  10464. .addRange(0x0, 0x8)
  10465. .addRange(0xE, 0x1F)
  10466. .addRange(0x21, 0x9F)
  10467. .addRange(0xA1, 0x167F)
  10468. .addRange(0x1681, 0x1FFF)
  10469. .addRange(0x200B, 0x2027)
  10470. .addRange(0x202A, 0x202E)
  10471. .addRange(0x2030, 0x205E)
  10472. .addRange(0x2060, 0x2FFF)
  10473. .addRange(0x3001, 0xFEFE)
  10474. .addRange(0xFF00, 0xFFFF)],
  10475. ['w', regenerate(0x5F)
  10476. .addRange(0x30, 0x39)
  10477. .addRange(0x41, 0x5A)
  10478. .addRange(0x61, 0x7A)],
  10479. ['W', regenerate(0x60)
  10480. .addRange(0x0, 0x2F)
  10481. .addRange(0x3A, 0x40)
  10482. .addRange(0x5B, 0x5E)
  10483. .addRange(0x7B, 0xFFFF)]
  10484. ]);
  10485. var UNICODE = new Map([
  10486. ['d', regenerate()
  10487. .addRange(0x30, 0x39)],
  10488. ['D', regenerate()
  10489. .addRange(0x0, 0x2F)
  10490. .addRange(0x3A, 0x10FFFF)],
  10491. ['s', regenerate(0x20, 0xA0, 0x1680, 0x202F, 0x205F, 0x3000, 0xFEFF)
  10492. .addRange(0x9, 0xD)
  10493. .addRange(0x2000, 0x200A)
  10494. .addRange(0x2028, 0x2029)],
  10495. ['S', regenerate()
  10496. .addRange(0x0, 0x8)
  10497. .addRange(0xE, 0x1F)
  10498. .addRange(0x21, 0x9F)
  10499. .addRange(0xA1, 0x167F)
  10500. .addRange(0x1681, 0x1FFF)
  10501. .addRange(0x200B, 0x2027)
  10502. .addRange(0x202A, 0x202E)
  10503. .addRange(0x2030, 0x205E)
  10504. .addRange(0x2060, 0x2FFF)
  10505. .addRange(0x3001, 0xFEFE)
  10506. .addRange(0xFF00, 0x10FFFF)],
  10507. ['w', regenerate(0x5F)
  10508. .addRange(0x30, 0x39)
  10509. .addRange(0x41, 0x5A)
  10510. .addRange(0x61, 0x7A)],
  10511. ['W', regenerate(0x60)
  10512. .addRange(0x0, 0x2F)
  10513. .addRange(0x3A, 0x40)
  10514. .addRange(0x5B, 0x5E)
  10515. .addRange(0x7B, 0x10FFFF)]
  10516. ]);
  10517. var UNICODE_IGNORE_CASE = new Map([
  10518. ['d', regenerate()
  10519. .addRange(0x30, 0x39)],
  10520. ['D', regenerate()
  10521. .addRange(0x0, 0x2F)
  10522. .addRange(0x3A, 0x10FFFF)],
  10523. ['s', regenerate(0x20, 0xA0, 0x1680, 0x202F, 0x205F, 0x3000, 0xFEFF)
  10524. .addRange(0x9, 0xD)
  10525. .addRange(0x2000, 0x200A)
  10526. .addRange(0x2028, 0x2029)],
  10527. ['S', regenerate()
  10528. .addRange(0x0, 0x8)
  10529. .addRange(0xE, 0x1F)
  10530. .addRange(0x21, 0x9F)
  10531. .addRange(0xA1, 0x167F)
  10532. .addRange(0x1681, 0x1FFF)
  10533. .addRange(0x200B, 0x2027)
  10534. .addRange(0x202A, 0x202E)
  10535. .addRange(0x2030, 0x205E)
  10536. .addRange(0x2060, 0x2FFF)
  10537. .addRange(0x3001, 0xFEFE)
  10538. .addRange(0xFF00, 0x10FFFF)],
  10539. ['w', regenerate(0x5F, 0x17F, 0x212A)
  10540. .addRange(0x30, 0x39)
  10541. .addRange(0x41, 0x5A)
  10542. .addRange(0x61, 0x7A)],
  10543. ['W', regenerate(0x60)
  10544. .addRange(0x0, 0x2F)
  10545. .addRange(0x3A, 0x40)
  10546. .addRange(0x5B, 0x5E)
  10547. .addRange(0x7B, 0x17E)
  10548. .addRange(0x180, 0x2129)
  10549. .addRange(0x212B, 0x10FFFF)]
  10550. ]);
  10551. var characterClassEscapeSets = {
  10552. REGULAR: REGULAR,
  10553. UNICODE: UNICODE,
  10554. UNICODE_IGNORE_CASE: UNICODE_IGNORE_CASE
  10555. };
  10556. var rewritePattern_1 = createCommonjsModule(function (module) {
  10557. 'use strict';
  10558. var generate = regjsgen.generate;
  10559. var parse = parser.parse;
  10560. // Prepare a Regenerate set containing all code points, used for negative
  10561. // character classes (if any).
  10562. var UNICODE_SET = regenerate().addRange(0x0, 0x10FFFF);
  10563. // Without the `u` flag, the range stops at 0xFFFF.
  10564. // https://mths.be/es6#sec-pattern-semantics
  10565. var BMP_SET = regenerate().addRange(0x0, 0xFFFF);
  10566. // Prepare a Regenerate set containing all code points that are supposed to be
  10567. // matched by `/./u`. https://mths.be/es6#sec-atom
  10568. var DOT_SET_UNICODE = UNICODE_SET.clone() // all Unicode code points
  10569. .remove(
  10570. // minus `LineTerminator`s (https://mths.be/es6#sec-line-terminators):
  10571. 0x000A, // Line Feed <LF>
  10572. 0x000D, // Carriage Return <CR>
  10573. 0x2028, // Line Separator <LS>
  10574. 0x2029 // Paragraph Separator <PS>
  10575. );
  10576. // Prepare a Regenerate set containing all code points that are supposed to be
  10577. // matched by `/./` (only BMP code points).
  10578. var DOT_SET = DOT_SET_UNICODE.clone()
  10579. .intersection(BMP_SET);
  10580. var getCharacterClassEscapeSet = function (character, unicode, ignoreCase) {
  10581. if (unicode) {
  10582. if (ignoreCase) {
  10583. return characterClassEscapeSets.UNICODE_IGNORE_CASE.get(character);
  10584. }
  10585. return characterClassEscapeSets.UNICODE.get(character);
  10586. }
  10587. return characterClassEscapeSets.REGULAR.get(character);
  10588. };
  10589. var getDotSet = function (unicode, dotAll) {
  10590. if (dotAll) {
  10591. return unicode ? UNICODE_SET : BMP_SET;
  10592. }
  10593. return unicode ? DOT_SET_UNICODE : DOT_SET;
  10594. };
  10595. var getUnicodePropertyValueSet = function (property, value) {
  10596. var path = value ?
  10597. (property + "/" + value) :
  10598. ("Binary_Property/" + property);
  10599. try {
  10600. return commonjsRequire(("regenerate-unicode-properties/" + path + ".js"));
  10601. } catch (exception) {
  10602. throw new Error(
  10603. "Failed to recognize value `" + value + "` for property " +
  10604. "`" + property + "`."
  10605. );
  10606. }
  10607. };
  10608. var handleLoneUnicodePropertyNameOrValue = function (value) {
  10609. // It could be a `General_Category` value or a binary property.
  10610. // Note: `unicodeMatchPropertyValue` throws on invalid values.
  10611. try {
  10612. var property$1 = 'General_Category';
  10613. var category = unicodeMatchPropertyValueEcmascript(property$1, value);
  10614. return getUnicodePropertyValueSet(property$1, category);
  10615. } catch (exception) {}
  10616. // It’s not a `General_Category` value, so check if it’s a binary
  10617. // property. Note: `unicodeMatchProperty` throws on invalid properties.
  10618. var property = unicodeMatchPropertyEcmascript(value);
  10619. return getUnicodePropertyValueSet(property);
  10620. };
  10621. var getUnicodePropertyEscapeSet = function (value, isNegative) {
  10622. var parts = value.split('=');
  10623. var firstPart = parts[0];
  10624. var set;
  10625. if (parts.length == 1) {
  10626. set = handleLoneUnicodePropertyNameOrValue(firstPart);
  10627. } else {
  10628. // The pattern consists of two parts, i.e. `Property=Value`.
  10629. var property = unicodeMatchPropertyEcmascript(firstPart);
  10630. var value$1 = unicodeMatchPropertyValueEcmascript(property, parts[1]);
  10631. set = getUnicodePropertyValueSet(property, value$1);
  10632. }
  10633. if (isNegative) {
  10634. return UNICODE_SET.clone().remove(set);
  10635. }
  10636. return set.clone();
  10637. };
  10638. // Given a range of code points, add any case-folded code points in that range
  10639. // to a set.
  10640. regenerate.prototype.iuAddRange = function(min, max) {
  10641. var $this = this;
  10642. do {
  10643. var folded = caseFold(min);
  10644. if (folded) {
  10645. $this.add(folded);
  10646. }
  10647. } while (++min <= max);
  10648. return $this;
  10649. };
  10650. var update = function (item, pattern) {
  10651. var tree = parse(pattern, config.useUnicodeFlag ? 'u' : '');
  10652. switch (tree.type) {
  10653. case 'characterClass':
  10654. case 'group':
  10655. case 'value':
  10656. // No wrapping needed.
  10657. break;
  10658. default:
  10659. // Wrap the pattern in a non-capturing group.
  10660. tree = wrap(tree, pattern);
  10661. }
  10662. Object.assign(item, tree);
  10663. };
  10664. var wrap = function (tree, pattern) {
  10665. // Wrap the pattern in a non-capturing group.
  10666. return {
  10667. 'type': 'group',
  10668. 'behavior': 'ignore',
  10669. 'body': [tree],
  10670. 'raw': ("(?:" + pattern + ")")
  10671. };
  10672. };
  10673. var caseFold = function (codePoint) {
  10674. return iuMappings.get(codePoint) || false;
  10675. };
  10676. var processCharacterClass = function (characterClassItem, regenerateOptions) {
  10677. var set = regenerate();
  10678. for (var i = 0, list = characterClassItem.body; i < list.length; i += 1) {
  10679. var item = list[i];
  10680. switch (item.type) {
  10681. case 'value':
  10682. set.add(item.codePoint);
  10683. if (config.ignoreCase && config.unicode && !config.useUnicodeFlag) {
  10684. var folded = caseFold(item.codePoint);
  10685. if (folded) {
  10686. set.add(folded);
  10687. }
  10688. }
  10689. break;
  10690. case 'characterClassRange':
  10691. var min = item.min.codePoint;
  10692. var max = item.max.codePoint;
  10693. set.addRange(min, max);
  10694. if (config.ignoreCase && config.unicode && !config.useUnicodeFlag) {
  10695. set.iuAddRange(min, max);
  10696. }
  10697. break;
  10698. case 'characterClassEscape':
  10699. set.add(getCharacterClassEscapeSet(
  10700. item.value,
  10701. config.unicode,
  10702. config.ignoreCase
  10703. ));
  10704. break;
  10705. case 'unicodePropertyEscape':
  10706. set.add(getUnicodePropertyEscapeSet(item.value, item.negative));
  10707. break;
  10708. // The `default` clause is only here as a safeguard; it should never be
  10709. // reached. Code coverage tools should ignore it.
  10710. /* istanbul ignore next */
  10711. default:
  10712. throw new Error(("Unknown term type: " + (item.type)));
  10713. }
  10714. }
  10715. if (characterClassItem.negative) {
  10716. set = (config.unicode ? UNICODE_SET : BMP_SET).clone().remove(set);
  10717. }
  10718. update(characterClassItem, set.toString(regenerateOptions));
  10719. return characterClassItem;
  10720. };
  10721. var processTerm = function (item, regenerateOptions) {
  10722. switch (item.type) {
  10723. case 'dot':
  10724. update(
  10725. item,
  10726. getDotSet(config.unicode, config.dotAll).toString(regenerateOptions)
  10727. );
  10728. break;
  10729. case 'characterClass':
  10730. item = processCharacterClass(item, regenerateOptions);
  10731. break;
  10732. case 'unicodePropertyEscape':
  10733. update(
  10734. item,
  10735. getUnicodePropertyEscapeSet(item.value, item.negative)
  10736. .toString(regenerateOptions)
  10737. );
  10738. break;
  10739. case 'characterClassEscape':
  10740. update(
  10741. item,
  10742. getCharacterClassEscapeSet(
  10743. item.value,
  10744. config.unicode,
  10745. config.ignoreCase
  10746. ).toString(regenerateOptions)
  10747. );
  10748. break;
  10749. case 'alternative':
  10750. case 'disjunction':
  10751. case 'group':
  10752. case 'quantifier':
  10753. item.body = item.body.map(function ( term ) {
  10754. return processTerm(term, regenerateOptions);
  10755. });
  10756. break;
  10757. case 'value':
  10758. var codePoint = item.codePoint;
  10759. var set = regenerate(codePoint);
  10760. if (config.ignoreCase && config.unicode && !config.useUnicodeFlag) {
  10761. var folded = caseFold(codePoint);
  10762. if (folded) {
  10763. set.add(folded);
  10764. }
  10765. }
  10766. update(item, set.toString(regenerateOptions));
  10767. break;
  10768. case 'anchor':
  10769. case 'empty':
  10770. case 'group':
  10771. case 'reference':
  10772. // Nothing to do here.
  10773. break;
  10774. // The `default` clause is only here as a safeguard; it should never be
  10775. // reached. Code coverage tools should ignore it.
  10776. /* istanbul ignore next */
  10777. default:
  10778. throw new Error(("Unknown term type: " + (item.type)));
  10779. }
  10780. return item;
  10781. };
  10782. var config = {
  10783. 'ignoreCase': false,
  10784. 'unicode': false,
  10785. 'dotAll': false,
  10786. 'useUnicodeFlag': false
  10787. };
  10788. var rewritePattern = function (pattern, flags, options) {
  10789. var regjsparserFeatures = {
  10790. 'unicodePropertyEscape': options && options.unicodePropertyEscape
  10791. };
  10792. config.ignoreCase = flags && flags.includes('i');
  10793. config.unicode = flags && flags.includes('u');
  10794. var supportDotAllFlag = options && options.dotAllFlag;
  10795. config.dotAll = supportDotAllFlag && flags && flags.includes('s');
  10796. config.useUnicodeFlag = options && options.useUnicodeFlag;
  10797. var regenerateOptions = {
  10798. 'hasUnicodeFlag': config.useUnicodeFlag,
  10799. 'bmpOnly': !config.unicode
  10800. };
  10801. var tree = parse(pattern, flags, regjsparserFeatures);
  10802. // Note: `processTerm` mutates `tree`.
  10803. processTerm(tree, regenerateOptions);
  10804. return generate(tree);
  10805. };
  10806. module.exports = rewritePattern;
  10807. });
  10808. var Literal = (function (Node) {
  10809. function Literal () {
  10810. Node.apply(this, arguments);
  10811. }
  10812. if ( Node ) Literal.__proto__ = Node;
  10813. Literal.prototype = Object.create( Node && Node.prototype );
  10814. Literal.prototype.constructor = Literal;
  10815. Literal.prototype.initialise = function initialise () {
  10816. if ( typeof this.value === 'string' ) {
  10817. this.program.indentExclusionElements.push( this );
  10818. }
  10819. };
  10820. Literal.prototype.transpile = function transpile ( code, transforms ) {
  10821. if ( transforms.numericLiteral ) {
  10822. var leading = this.raw.slice( 0, 2 );
  10823. if ( leading === '0b' || leading === '0o' ) {
  10824. code.overwrite( this.start, this.end, String( this.value ), true );
  10825. }
  10826. }
  10827. if ( this.regex ) {
  10828. var ref = this.regex;
  10829. var pattern = ref.pattern;
  10830. var flags = ref.flags;
  10831. if ( transforms.stickyRegExp && /y/.test( flags ) ) throw new CompileError( this, 'Regular expression sticky flag is not supported' );
  10832. if ( transforms.unicodeRegExp && /u/.test( flags ) ) {
  10833. code.overwrite( this.start, this.end, ("/" + (rewritePattern_1( pattern, flags )) + "/" + (flags.replace( 'u', '' ))) );
  10834. }
  10835. }
  10836. };
  10837. return Literal;
  10838. }(Node$1));
  10839. var MemberExpression = (function (Node) {
  10840. function MemberExpression () {
  10841. Node.apply(this, arguments);
  10842. }
  10843. if ( Node ) MemberExpression.__proto__ = Node;
  10844. MemberExpression.prototype = Object.create( Node && Node.prototype );
  10845. MemberExpression.prototype.constructor = MemberExpression;
  10846. MemberExpression.prototype.transpile = function transpile ( code, transforms ) {
  10847. if ( transforms.reservedProperties && reserved[ this.property.name ] ) {
  10848. code.overwrite( this.object.end, this.property.start, "['" );
  10849. code.insertLeft( this.property.end, "']" );
  10850. }
  10851. Node.prototype.transpile.call( this, code, transforms );
  10852. };
  10853. return MemberExpression;
  10854. }(Node$1));
  10855. var NewExpression = (function (Node) {
  10856. function NewExpression () {
  10857. Node.apply(this, arguments);
  10858. }
  10859. if ( Node ) NewExpression.__proto__ = Node;
  10860. NewExpression.prototype = Object.create( Node && Node.prototype );
  10861. NewExpression.prototype.constructor = NewExpression;
  10862. NewExpression.prototype.initialise = function initialise ( transforms ) {
  10863. var this$1 = this;
  10864. if ( transforms.spreadRest && this.arguments.length ) {
  10865. var lexicalBoundary = this.findLexicalBoundary();
  10866. var i = this.arguments.length;
  10867. while ( i-- ) {
  10868. var arg = this$1.arguments[i];
  10869. if ( arg.type === 'SpreadElement' && isArguments( arg.argument ) ) {
  10870. this$1.argumentsArrayAlias = lexicalBoundary.getArgumentsArrayAlias();
  10871. break;
  10872. }
  10873. }
  10874. }
  10875. Node.prototype.initialise.call( this, transforms );
  10876. };
  10877. NewExpression.prototype.transpile = function transpile ( code, transforms ) {
  10878. if ( transforms.spreadRest && this.arguments.length ) {
  10879. var firstArgument = this.arguments[0];
  10880. var isNew = true;
  10881. var hasSpreadElements = spread( code, this.arguments, firstArgument.start, this.argumentsArrayAlias, isNew );
  10882. if ( hasSpreadElements ) {
  10883. code.insertRight( this.start + 'new'.length, ' (Function.prototype.bind.apply(' );
  10884. code.overwrite( this.callee.end, firstArgument.start, ', [ null ].concat( ' );
  10885. code.insertLeft( this.end, ' ))' );
  10886. }
  10887. }
  10888. Node.prototype.transpile.call( this, code, transforms );
  10889. };
  10890. return NewExpression;
  10891. }(Node$1));
  10892. var ObjectExpression = (function (Node) {
  10893. function ObjectExpression () {
  10894. Node.apply(this, arguments);
  10895. }
  10896. if ( Node ) ObjectExpression.__proto__ = Node;
  10897. ObjectExpression.prototype = Object.create( Node && Node.prototype );
  10898. ObjectExpression.prototype.constructor = ObjectExpression;
  10899. ObjectExpression.prototype.transpile = function transpile ( code, transforms ) {
  10900. var this$1 = this;
  10901. Node.prototype.transpile.call( this, code, transforms );
  10902. var firstPropertyStart = this.start + 1;
  10903. var regularPropertyCount = 0;
  10904. var spreadPropertyCount = 0;
  10905. var computedPropertyCount = 0;
  10906. for ( var i$2 = 0, list = this.properties; i$2 < list.length; i$2 += 1 ) {
  10907. var prop = list[i$2];
  10908. if ( prop.type === 'SpreadProperty' ) {
  10909. spreadPropertyCount += 1;
  10910. } else if ( prop.computed ) {
  10911. computedPropertyCount += 1;
  10912. } else if ( prop.type === 'Property' ) {
  10913. regularPropertyCount += 1;
  10914. }
  10915. }
  10916. if ( spreadPropertyCount ) {
  10917. if ( !this.program.options.objectAssign ) {
  10918. throw new CompileError( this, 'Object spread operator requires specified objectAssign option with \'Object.assign\' or polyfill helper.' );
  10919. }
  10920. // enclose run of non-spread properties in curlies
  10921. var i = this.properties.length;
  10922. if ( regularPropertyCount ) {
  10923. while ( i-- ) {
  10924. var prop$1 = this$1.properties[i];
  10925. if ( prop$1.type === 'Property' && !prop$1.computed ) {
  10926. var lastProp = this$1.properties[ i - 1 ];
  10927. var nextProp = this$1.properties[ i + 1 ];
  10928. if ( !lastProp || lastProp.type !== 'Property' || lastProp.computed ) {
  10929. code.insertRight( prop$1.start, '{' );
  10930. }
  10931. if ( !nextProp || nextProp.type !== 'Property' || nextProp.computed ) {
  10932. code.insertLeft( prop$1.end, '}' );
  10933. }
  10934. }
  10935. }
  10936. }
  10937. // wrap the whole thing in Object.assign
  10938. firstPropertyStart = this.properties[0].start;
  10939. code.overwrite( this.start, firstPropertyStart, ((this.program.options.objectAssign) + "({}, "));
  10940. code.overwrite( this.properties[ this.properties.length - 1 ].end, this.end, ')' );
  10941. }
  10942. if ( computedPropertyCount && transforms.computedProperty ) {
  10943. var i0 = this.getIndentation();
  10944. var isSimpleAssignment;
  10945. var name;
  10946. if ( this.parent.type === 'VariableDeclarator' && this.parent.parent.declarations.length === 1 ) {
  10947. isSimpleAssignment = true;
  10948. name = this.parent.id.alias || this.parent.id.name; // TODO is this right?
  10949. } else if ( this.parent.type === 'AssignmentExpression' && this.parent.parent.type === 'ExpressionStatement' && this.parent.left.type === 'Identifier' ) {
  10950. isSimpleAssignment = true;
  10951. name = this.parent.left.alias || this.parent.left.name; // TODO is this right?
  10952. } else if ( this.parent.type === 'AssignmentPattern' && this.parent.left.type === 'Identifier' ) {
  10953. isSimpleAssignment = true;
  10954. name = this.parent.left.alias || this.parent.left.name; // TODO is this right?
  10955. }
  10956. // handle block scoping
  10957. var declaration = this.findScope( false ).findDeclaration( name );
  10958. if ( declaration ) name = declaration.name;
  10959. var start = firstPropertyStart;
  10960. var end = this.end;
  10961. if ( isSimpleAssignment ) {
  10962. // ???
  10963. } else {
  10964. name = this.findScope( true ).createIdentifier( '_obj' );
  10965. var statement = this.findNearest( /(?:Statement|Declaration)$/ );
  10966. code.insertLeft( statement.end, ("\n" + i0 + "var " + name + ";") );
  10967. code.insertRight( this.start, ("( " + name + " = ") );
  10968. }
  10969. var len = this.properties.length;
  10970. var lastComputedProp;
  10971. var sawNonComputedProperty = false;
  10972. for ( var i$1 = 0; i$1 < len; i$1 += 1 ) {
  10973. var prop$2 = this$1.properties[i$1];
  10974. if ( prop$2.computed ) {
  10975. lastComputedProp = prop$2;
  10976. var moveStart = i$1 > 0 ? this$1.properties[ i$1 - 1 ].end : start;
  10977. var propId = isSimpleAssignment ? (";\n" + i0 + name) : (", " + name);
  10978. if (moveStart < prop$2.start) {
  10979. code.overwrite( moveStart, prop$2.start, propId );
  10980. } else {
  10981. code.insertRight( prop$2.start, propId );
  10982. }
  10983. var c = prop$2.key.end;
  10984. while ( code.original[c] !== ']' ) c += 1;
  10985. c += 1;
  10986. if ( prop$2.value.start > c ) code.remove( c, prop$2.value.start );
  10987. code.insertLeft( c, ' = ' );
  10988. code.move( moveStart, prop$2.end, end );
  10989. if ( i$1 < len - 1 && ! sawNonComputedProperty ) {
  10990. // remove trailing comma
  10991. c = prop$2.end;
  10992. while ( code.original[c] !== ',' ) c += 1;
  10993. code.remove( prop$2.end, c + 1 );
  10994. }
  10995. if ( prop$2.method && transforms.conciseMethodProperty ) {
  10996. code.insertRight( prop$2.value.start, 'function ' );
  10997. }
  10998. } else {
  10999. sawNonComputedProperty = true;
  11000. }
  11001. }
  11002. // special case
  11003. if ( computedPropertyCount === len ) {
  11004. code.remove( this.properties[ len - 1 ].end, this.end - 1 );
  11005. }
  11006. if ( !isSimpleAssignment ) {
  11007. code.insertLeft( lastComputedProp.end, (", " + name + " )") );
  11008. }
  11009. }
  11010. };
  11011. return ObjectExpression;
  11012. }(Node$1));
  11013. var Property = (function (Node) {
  11014. function Property () {
  11015. Node.apply(this, arguments);
  11016. }
  11017. if ( Node ) Property.__proto__ = Node;
  11018. Property.prototype = Object.create( Node && Node.prototype );
  11019. Property.prototype.constructor = Property;
  11020. Property.prototype.transpile = function transpile ( code, transforms ) {
  11021. if ( transforms.conciseMethodProperty && !this.computed && this.parent.type !== 'ObjectPattern' ) {
  11022. if ( this.shorthand ) {
  11023. code.insertRight( this.start, ((this.key.name) + ": " + (this.shouldPrefix() ? '_vm.' : '')) );
  11024. } else if ( this.method ) {
  11025. var name = '';
  11026. if ( this.program.options.namedFunctionExpressions !== false ) {
  11027. if ( this.key.type === 'Literal' && typeof this.key.value === 'number' ) {
  11028. name = "";
  11029. } else if ( this.key.type === 'Identifier' ) {
  11030. if ( reserved[ this.key.name ] ||
  11031. ! /^[a-z_$][a-z0-9_$]*$/i.test( this.key.name ) ||
  11032. this.value.body.scope.references[this.key.name] ) {
  11033. name = this.findScope( true ).createIdentifier( this.key.name );
  11034. } else {
  11035. name = this.key.name;
  11036. }
  11037. } else {
  11038. name = this.findScope( true ).createIdentifier( this.key.value );
  11039. }
  11040. name = ' ' + name;
  11041. }
  11042. if ( this.value.generator ) code.remove( this.start, this.key.start );
  11043. code.insertLeft( this.key.end, (": function" + (this.value.generator ? '*' : '') + name) );
  11044. }
  11045. }
  11046. if ( transforms.reservedProperties && reserved[ this.key.name ] ) {
  11047. code.insertRight( this.key.start, "'" );
  11048. code.insertLeft( this.key.end, "'" );
  11049. }
  11050. Node.prototype.transpile.call( this, code, transforms );
  11051. };
  11052. Property.prototype.shouldPrefix = function shouldPrefix () {
  11053. if (
  11054. this.program.inWith > 0 &&
  11055. !hash[this.key.name] &&
  11056. !this.findScope(false).contains(this.key.name)
  11057. ) {
  11058. return true
  11059. }
  11060. return false
  11061. };
  11062. return Property;
  11063. }(Node$1));
  11064. var ReturnStatement = (function (Node) {
  11065. function ReturnStatement () {
  11066. Node.apply(this, arguments);
  11067. }
  11068. if ( Node ) ReturnStatement.__proto__ = Node;
  11069. ReturnStatement.prototype = Object.create( Node && Node.prototype );
  11070. ReturnStatement.prototype.constructor = ReturnStatement;
  11071. ReturnStatement.prototype.initialise = function initialise ( transforms ) {
  11072. this.loop = this.findNearest( loopStatement );
  11073. this.nearestFunction = this.findNearest( /Function/ );
  11074. if ( this.loop && ( !this.nearestFunction || this.loop.depth > this.nearestFunction.depth ) ) {
  11075. this.loop.canReturn = true;
  11076. this.shouldWrap = true;
  11077. }
  11078. if ( this.argument ) this.argument.initialise( transforms );
  11079. };
  11080. ReturnStatement.prototype.transpile = function transpile ( code, transforms ) {
  11081. var shouldWrap = this.shouldWrap && this.loop && this.loop.shouldRewriteAsFunction;
  11082. if ( this.argument ) {
  11083. if ( shouldWrap ) code.insertRight( this.argument.start, "{ v: " );
  11084. this.argument.transpile( code, transforms );
  11085. if ( shouldWrap ) code.insertLeft( this.argument.end, " }" );
  11086. } else if ( shouldWrap ) {
  11087. code.insertLeft( this.start + 6, ' {}' );
  11088. }
  11089. };
  11090. return ReturnStatement;
  11091. }(Node$1));
  11092. var SpreadProperty = (function (Node) {
  11093. function SpreadProperty () {
  11094. Node.apply(this, arguments);
  11095. }
  11096. if ( Node ) SpreadProperty.__proto__ = Node;
  11097. SpreadProperty.prototype = Object.create( Node && Node.prototype );
  11098. SpreadProperty.prototype.constructor = SpreadProperty;
  11099. SpreadProperty.prototype.transpile = function transpile ( code, transforms ) {
  11100. code.remove( this.start, this.argument.start );
  11101. code.remove( this.argument.end, this.end );
  11102. Node.prototype.transpile.call( this, code, transforms );
  11103. };
  11104. return SpreadProperty;
  11105. }(Node$1));
  11106. var Super = (function (Node) {
  11107. function Super () {
  11108. Node.apply(this, arguments);
  11109. }
  11110. if ( Node ) Super.__proto__ = Node;
  11111. Super.prototype = Object.create( Node && Node.prototype );
  11112. Super.prototype.constructor = Super;
  11113. Super.prototype.initialise = function initialise ( transforms ) {
  11114. if ( transforms.classes ) {
  11115. this.method = this.findNearest( 'MethodDefinition' );
  11116. if ( !this.method ) throw new CompileError( this, 'use of super outside class method' );
  11117. var parentClass = this.findNearest( 'ClassBody' ).parent;
  11118. this.superClassName = parentClass.superClass && (parentClass.superClass.name || 'superclass');
  11119. if ( !this.superClassName ) throw new CompileError( this, 'super used in base class' );
  11120. this.isCalled = this.parent.type === 'CallExpression' && this === this.parent.callee;
  11121. if ( this.method.kind !== 'constructor' && this.isCalled ) {
  11122. throw new CompileError( this, 'super() not allowed outside class constructor' );
  11123. }
  11124. this.isMember = this.parent.type === 'MemberExpression';
  11125. if ( !this.isCalled && !this.isMember ) {
  11126. throw new CompileError( this, 'Unexpected use of `super` (expected `super(...)` or `super.*`)' );
  11127. }
  11128. }
  11129. if ( transforms.arrow ) {
  11130. var lexicalBoundary = this.findLexicalBoundary();
  11131. var arrowFunction = this.findNearest( 'ArrowFunctionExpression' );
  11132. var loop = this.findNearest( loopStatement );
  11133. if ( arrowFunction && arrowFunction.depth > lexicalBoundary.depth ) {
  11134. this.thisAlias = lexicalBoundary.getThisAlias();
  11135. }
  11136. if ( loop && loop.body.contains( this ) && loop.depth > lexicalBoundary.depth ) {
  11137. this.thisAlias = lexicalBoundary.getThisAlias();
  11138. }
  11139. }
  11140. };
  11141. Super.prototype.transpile = function transpile ( code, transforms ) {
  11142. if ( transforms.classes ) {
  11143. var expression = ( this.isCalled || this.method.static ) ?
  11144. this.superClassName :
  11145. ((this.superClassName) + ".prototype");
  11146. code.overwrite( this.start, this.end, expression, true );
  11147. var callExpression = this.isCalled ? this.parent : this.parent.parent;
  11148. if ( callExpression && callExpression.type === 'CallExpression' ) {
  11149. if ( !this.noCall ) { // special case – `super( ...args )`
  11150. code.insertLeft( callExpression.callee.end, '.call' );
  11151. }
  11152. var thisAlias = this.thisAlias || 'this';
  11153. if ( callExpression.arguments.length ) {
  11154. code.insertLeft( callExpression.arguments[0].start, (thisAlias + ", ") );
  11155. } else {
  11156. code.insertLeft( callExpression.end - 1, ("" + thisAlias) );
  11157. }
  11158. }
  11159. }
  11160. };
  11161. return Super;
  11162. }(Node$1));
  11163. var TaggedTemplateExpression = (function (Node) {
  11164. function TaggedTemplateExpression () {
  11165. Node.apply(this, arguments);
  11166. }
  11167. if ( Node ) TaggedTemplateExpression.__proto__ = Node;
  11168. TaggedTemplateExpression.prototype = Object.create( Node && Node.prototype );
  11169. TaggedTemplateExpression.prototype.constructor = TaggedTemplateExpression;
  11170. TaggedTemplateExpression.prototype.initialise = function initialise ( transforms ) {
  11171. if ( transforms.templateString && !transforms.dangerousTaggedTemplateString ) {
  11172. throw new CompileError( this, 'Tagged template strings are not supported. Use `transforms: { templateString: false }` to skip transformation and disable this error, or `transforms: { dangerousTaggedTemplateString: true }` if you know what you\'re doing' );
  11173. }
  11174. Node.prototype.initialise.call( this, transforms );
  11175. };
  11176. TaggedTemplateExpression.prototype.transpile = function transpile ( code, transforms ) {
  11177. if ( transforms.templateString && transforms.dangerousTaggedTemplateString ) {
  11178. var ordered = this.quasi.expressions.concat( this.quasi.quasis ).sort( function ( a, b ) { return a.start - b.start; } );
  11179. // insert strings at start
  11180. var templateStrings = this.quasi.quasis.map( function ( quasi ) { return JSON.stringify( quasi.value.cooked ); } );
  11181. code.overwrite( this.tag.end, ordered[0].start, ("([" + (templateStrings.join(', ')) + "]") );
  11182. var lastIndex = ordered[0].start;
  11183. ordered.forEach( function ( node ) {
  11184. if ( node.type === 'TemplateElement' ) {
  11185. code.remove( lastIndex, node.end );
  11186. } else {
  11187. code.overwrite( lastIndex, node.start, ', ' );
  11188. }
  11189. lastIndex = node.end;
  11190. });
  11191. code.overwrite( lastIndex, this.end, ')' );
  11192. }
  11193. Node.prototype.transpile.call( this, code, transforms );
  11194. };
  11195. return TaggedTemplateExpression;
  11196. }(Node$1));
  11197. var TemplateElement = (function (Node) {
  11198. function TemplateElement () {
  11199. Node.apply(this, arguments);
  11200. }
  11201. if ( Node ) TemplateElement.__proto__ = Node;
  11202. TemplateElement.prototype = Object.create( Node && Node.prototype );
  11203. TemplateElement.prototype.constructor = TemplateElement;
  11204. TemplateElement.prototype.initialise = function initialise () {
  11205. this.program.indentExclusionElements.push( this );
  11206. };
  11207. return TemplateElement;
  11208. }(Node$1));
  11209. var TemplateLiteral = (function (Node) {
  11210. function TemplateLiteral () {
  11211. Node.apply(this, arguments);
  11212. }
  11213. if ( Node ) TemplateLiteral.__proto__ = Node;
  11214. TemplateLiteral.prototype = Object.create( Node && Node.prototype );
  11215. TemplateLiteral.prototype.constructor = TemplateLiteral;
  11216. TemplateLiteral.prototype.transpile = function transpile ( code, transforms ) {
  11217. if ( transforms.templateString && this.parent.type !== 'TaggedTemplateExpression' ) {
  11218. var ordered = this.expressions.concat( this.quasis )
  11219. .sort( function ( a, b ) { return a.start - b.start || a.end - b.end; } )
  11220. .filter( function ( node, i ) {
  11221. // include all expressions
  11222. if ( node.type !== 'TemplateElement' ) return true;
  11223. // include all non-empty strings
  11224. if ( node.value.raw ) return true;
  11225. // exclude all empty strings not at the head
  11226. return !i;
  11227. });
  11228. // special case – we may be able to skip the first element,
  11229. // if it's the empty string, but only if the second and
  11230. // third elements aren't both expressions (since they maybe
  11231. // be numeric, and `1 + 2 + '3' === '33'`)
  11232. if ( ordered.length >= 3 ) {
  11233. var first = ordered[0];
  11234. var third = ordered[2];
  11235. if ( first.type === 'TemplateElement' && first.value.raw === '' && third.type === 'TemplateElement' ) {
  11236. ordered.shift();
  11237. }
  11238. }
  11239. var parenthesise = ( this.quasis.length !== 1 || this.expressions.length !== 0 ) &&
  11240. this.parent.type !== 'AssignmentExpression' &&
  11241. this.parent.type !== 'AssignmentPattern' &&
  11242. this.parent.type !== 'VariableDeclarator' &&
  11243. ( this.parent.type !== 'BinaryExpression' || this.parent.operator !== '+' );
  11244. if ( parenthesise ) code.insertRight( this.start, '(' );
  11245. var lastIndex = this.start;
  11246. ordered.forEach( function ( node, i ) {
  11247. if ( node.type === 'TemplateElement' ) {
  11248. var replacement = '';
  11249. if ( i ) replacement += ' + ';
  11250. replacement += JSON.stringify( node.value.cooked );
  11251. code.overwrite( lastIndex, node.end, replacement );
  11252. } else {
  11253. var parenthesise = node.type !== 'Identifier'; // TODO other cases where it's safe
  11254. var replacement$1 = '';
  11255. if ( i ) replacement$1 += ' + ';
  11256. if ( parenthesise ) replacement$1 += '(';
  11257. code.overwrite( lastIndex, node.start, replacement$1 );
  11258. if ( parenthesise ) code.insertLeft( node.end, ')' );
  11259. }
  11260. lastIndex = node.end;
  11261. });
  11262. var close = '';
  11263. if ( parenthesise ) close += ')';
  11264. code.overwrite( lastIndex, this.end, close );
  11265. }
  11266. Node.prototype.transpile.call( this, code, transforms );
  11267. };
  11268. return TemplateLiteral;
  11269. }(Node$1));
  11270. var ThisExpression = (function (Node) {
  11271. function ThisExpression () {
  11272. Node.apply(this, arguments);
  11273. }
  11274. if ( Node ) ThisExpression.__proto__ = Node;
  11275. ThisExpression.prototype = Object.create( Node && Node.prototype );
  11276. ThisExpression.prototype.constructor = ThisExpression;
  11277. ThisExpression.prototype.initialise = function initialise ( transforms ) {
  11278. if ( transforms.arrow ) {
  11279. var lexicalBoundary = this.findLexicalBoundary();
  11280. var arrowFunction = this.findNearest( 'ArrowFunctionExpression' );
  11281. var loop = this.findNearest( loopStatement );
  11282. if ( ( arrowFunction && arrowFunction.depth > lexicalBoundary.depth )
  11283. || ( loop && loop.body.contains( this ) && loop.depth > lexicalBoundary.depth )
  11284. || ( loop && loop.right && loop.right.contains( this ) ) ) {
  11285. this.alias = lexicalBoundary.getThisAlias();
  11286. }
  11287. }
  11288. };
  11289. ThisExpression.prototype.transpile = function transpile ( code ) {
  11290. if ( this.alias ) {
  11291. code.overwrite( this.start, this.end, this.alias, true );
  11292. }
  11293. };
  11294. return ThisExpression;
  11295. }(Node$1));
  11296. var UpdateExpression = (function (Node) {
  11297. function UpdateExpression () {
  11298. Node.apply(this, arguments);
  11299. }
  11300. if ( Node ) UpdateExpression.__proto__ = Node;
  11301. UpdateExpression.prototype = Object.create( Node && Node.prototype );
  11302. UpdateExpression.prototype.constructor = UpdateExpression;
  11303. UpdateExpression.prototype.initialise = function initialise ( transforms ) {
  11304. if ( this.argument.type === 'Identifier' ) {
  11305. var declaration = this.findScope( false ).findDeclaration( this.argument.name );
  11306. if ( declaration && declaration.kind === 'const' ) {
  11307. throw new CompileError( this, ((this.argument.name) + " is read-only") );
  11308. }
  11309. // special case – https://gitlab.com/Rich-Harris/buble/issues/150
  11310. var statement = declaration && declaration.node.ancestor( 3 );
  11311. if ( statement && statement.type === 'ForStatement' && statement.body.contains( this ) ) {
  11312. statement.reassigned[ this.argument.name ] = true;
  11313. }
  11314. }
  11315. Node.prototype.initialise.call( this, transforms );
  11316. };
  11317. return UpdateExpression;
  11318. }(Node$1));
  11319. var VariableDeclaration = (function (Node) {
  11320. function VariableDeclaration () {
  11321. Node.apply(this, arguments);
  11322. }
  11323. if ( Node ) VariableDeclaration.__proto__ = Node;
  11324. VariableDeclaration.prototype = Object.create( Node && Node.prototype );
  11325. VariableDeclaration.prototype.constructor = VariableDeclaration;
  11326. VariableDeclaration.prototype.initialise = function initialise ( transforms ) {
  11327. this.scope = this.findScope( this.kind === 'var' );
  11328. this.declarations.forEach( function ( declarator ) { return declarator.initialise( transforms ); } );
  11329. };
  11330. VariableDeclaration.prototype.transpile = function transpile ( code, transforms ) {
  11331. var this$1 = this;
  11332. var i0 = this.getIndentation();
  11333. var kind = this.kind;
  11334. if ( transforms.letConst && kind !== 'var' ) {
  11335. kind = 'var';
  11336. code.overwrite( this.start, this.start + this.kind.length, kind, true );
  11337. }
  11338. if ( transforms.destructuring && this.parent.type !== 'ForOfStatement' ) {
  11339. var c = this.start;
  11340. var lastDeclaratorIsPattern;
  11341. this.declarations.forEach( function ( declarator, i ) {
  11342. if ( declarator.id.type === 'Identifier' ) {
  11343. if ( i > 0 && this$1.declarations[ i - 1 ].id.type !== 'Identifier' ) {
  11344. code.overwrite( c, declarator.id.start, "var " );
  11345. }
  11346. } else {
  11347. var inline = loopStatement.test( this$1.parent.type );
  11348. if ( i === 0 ) {
  11349. code.remove( c, declarator.id.start );
  11350. } else {
  11351. code.overwrite( c, declarator.id.start, (";\n" + i0) );
  11352. }
  11353. var simple = declarator.init.type === 'Identifier' && !declarator.init.rewritten;
  11354. var name = simple ? declarator.init.name : declarator.findScope( true ).createIdentifier( 'ref' );
  11355. var statementGenerators = [];
  11356. if ( simple ) {
  11357. code.remove( declarator.id.end, declarator.end );
  11358. } else {
  11359. statementGenerators.push( function ( start, prefix, suffix ) {
  11360. code.insertRight( declarator.id.end, ("var " + name) );
  11361. code.insertLeft( declarator.init.end, ("" + suffix) );
  11362. code.move( declarator.id.end, declarator.end, start );
  11363. });
  11364. }
  11365. destructure( code, declarator.findScope( false ), declarator.id, name, inline, statementGenerators );
  11366. var prefix = inline ? 'var ' : '';
  11367. var suffix = inline ? ", " : (";\n" + i0);
  11368. statementGenerators.forEach( function ( fn, j ) {
  11369. if ( i === this$1.declarations.length - 1 && j === statementGenerators.length - 1 ) {
  11370. suffix = inline ? '' : ';';
  11371. }
  11372. fn( declarator.start, j === 0 ? prefix : '', suffix );
  11373. });
  11374. }
  11375. declarator.transpile( code, transforms );
  11376. c = declarator.end;
  11377. lastDeclaratorIsPattern = declarator.id.type !== 'Identifier';
  11378. });
  11379. if ( lastDeclaratorIsPattern ) {
  11380. code.remove( c, this.end );
  11381. }
  11382. }
  11383. else {
  11384. this.declarations.forEach( function ( declarator ) {
  11385. declarator.transpile( code, transforms );
  11386. });
  11387. }
  11388. };
  11389. return VariableDeclaration;
  11390. }(Node$1));
  11391. var VariableDeclarator = (function (Node) {
  11392. function VariableDeclarator () {
  11393. Node.apply(this, arguments);
  11394. }
  11395. if ( Node ) VariableDeclarator.__proto__ = Node;
  11396. VariableDeclarator.prototype = Object.create( Node && Node.prototype );
  11397. VariableDeclarator.prototype.constructor = VariableDeclarator;
  11398. VariableDeclarator.prototype.initialise = function initialise ( transforms ) {
  11399. var kind = this.parent.kind;
  11400. if ( kind === 'let' && this.parent.parent.type === 'ForStatement' ) {
  11401. kind = 'for.let'; // special case...
  11402. }
  11403. this.parent.scope.addDeclaration( this.id, kind );
  11404. Node.prototype.initialise.call( this, transforms );
  11405. };
  11406. VariableDeclarator.prototype.transpile = function transpile ( code, transforms ) {
  11407. if ( !this.init && transforms.letConst && this.parent.kind !== 'var' ) {
  11408. var inLoop = this.findNearest( /Function|^For(In|Of)?Statement|^(?:Do)?WhileStatement/ );
  11409. if ( inLoop && ! /Function/.test( inLoop.type ) && ! this.isLeftDeclaratorOfLoop() ) {
  11410. code.insertLeft( this.id.end, ' = (void 0)' );
  11411. }
  11412. }
  11413. if ( this.id ) this.id.transpile( code, transforms );
  11414. if ( this.init ) this.init.transpile( code, transforms );
  11415. };
  11416. VariableDeclarator.prototype.isLeftDeclaratorOfLoop = function isLeftDeclaratorOfLoop () {
  11417. return this.parent
  11418. && this.parent.type === 'VariableDeclaration'
  11419. && this.parent.parent
  11420. && (this.parent.parent.type === 'ForInStatement'
  11421. || this.parent.parent.type === 'ForOfStatement')
  11422. && this.parent.parent.left
  11423. && this.parent.parent.left.declarations[0] === this;
  11424. };
  11425. return VariableDeclarator;
  11426. }(Node$1));
  11427. var WithStatement = (function (Node) {
  11428. function WithStatement () {
  11429. Node.apply(this, arguments);
  11430. }
  11431. if ( Node ) WithStatement.__proto__ = Node;
  11432. WithStatement.prototype = Object.create( Node && Node.prototype );
  11433. WithStatement.prototype.constructor = WithStatement;
  11434. WithStatement.prototype.transpile = function transpile (code, transforms) {
  11435. if (transforms.stripWith) {
  11436. this.program.inWith = (this.program.inWith || 0) + 1;
  11437. // remove surrounding with block
  11438. code.remove(this.start, this.body.start + 1);
  11439. code.remove(this.end - 1, this.end);
  11440. if (transforms.stripWithFunctional) {
  11441. code.insertRight(this.start, "var _c=_vm._c;");
  11442. } else {
  11443. code.insertRight(this.start, "var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;");
  11444. }
  11445. Node.prototype.transpile.call(this, code, transforms);
  11446. this.program.inWith--;
  11447. } else {
  11448. Node.prototype.transpile.call(this, code, transforms);
  11449. }
  11450. };
  11451. return WithStatement;
  11452. }(Node$1));
  11453. var types$1$1 = {
  11454. ArrayExpression: ArrayExpression,
  11455. ArrowFunctionExpression: ArrowFunctionExpression,
  11456. AssignmentExpression: AssignmentExpression,
  11457. BinaryExpression: BinaryExpression,
  11458. BreakStatement: BreakStatement,
  11459. CallExpression: CallExpression,
  11460. ClassBody: ClassBody,
  11461. ClassDeclaration: ClassDeclaration,
  11462. ClassExpression: ClassExpression,
  11463. ContinueStatement: ContinueStatement,
  11464. DoWhileStatement: LoopStatement,
  11465. ExportNamedDeclaration: ExportNamedDeclaration,
  11466. ExportDefaultDeclaration: ExportDefaultDeclaration,
  11467. ForStatement: ForStatement,
  11468. ForInStatement: ForInStatement,
  11469. ForOfStatement: ForOfStatement,
  11470. FunctionDeclaration: FunctionDeclaration,
  11471. FunctionExpression: FunctionExpression,
  11472. Identifier: Identifier,
  11473. IfStatement: IfStatement,
  11474. ImportDeclaration: ImportDeclaration,
  11475. ImportDefaultSpecifier: ImportDefaultSpecifier,
  11476. ImportSpecifier: ImportSpecifier,
  11477. JSXAttribute: JSXAttribute,
  11478. JSXClosingElement: JSXClosingElement,
  11479. JSXElement: JSXElement,
  11480. JSXExpressionContainer: JSXExpressionContainer,
  11481. JSXOpeningElement: JSXOpeningElement,
  11482. JSXSpreadAttribute: JSXSpreadAttribute,
  11483. Literal: Literal,
  11484. MemberExpression: MemberExpression,
  11485. NewExpression: NewExpression,
  11486. ObjectExpression: ObjectExpression,
  11487. Property: Property,
  11488. ReturnStatement: ReturnStatement,
  11489. SpreadProperty: SpreadProperty,
  11490. Super: Super,
  11491. TaggedTemplateExpression: TaggedTemplateExpression,
  11492. TemplateElement: TemplateElement,
  11493. TemplateLiteral: TemplateLiteral,
  11494. ThisExpression: ThisExpression,
  11495. UpdateExpression: UpdateExpression,
  11496. VariableDeclaration: VariableDeclaration,
  11497. VariableDeclarator: VariableDeclarator,
  11498. WhileStatement: LoopStatement,
  11499. WithStatement: WithStatement
  11500. };
  11501. var statementsWithBlocks = {
  11502. IfStatement: 'consequent',
  11503. ForStatement: 'body',
  11504. ForInStatement: 'body',
  11505. ForOfStatement: 'body',
  11506. WhileStatement: 'body',
  11507. DoWhileStatement: 'body',
  11508. ArrowFunctionExpression: 'body'
  11509. };
  11510. function wrap ( raw, parent ) {
  11511. if ( !raw ) return;
  11512. if ( 'length' in raw ) {
  11513. var i = raw.length;
  11514. while ( i-- ) wrap( raw[i], parent );
  11515. return;
  11516. }
  11517. // with e.g. shorthand properties, key and value are
  11518. // the same node. We don't want to wrap an object twice
  11519. if ( raw.__wrapped ) return;
  11520. raw.__wrapped = true;
  11521. if ( !keys[ raw.type ] ) {
  11522. keys[ raw.type ] = Object.keys( raw ).filter( function ( key ) { return typeof raw[ key ] === 'object'; } );
  11523. }
  11524. // special case – body-less if/for/while statements. TODO others?
  11525. var bodyType = statementsWithBlocks[ raw.type ];
  11526. if ( bodyType && raw[ bodyType ].type !== 'BlockStatement' ) {
  11527. var expression = raw[ bodyType ];
  11528. // create a synthetic block statement, otherwise all hell
  11529. // breaks loose when it comes to block scoping
  11530. raw[ bodyType ] = {
  11531. start: expression.start,
  11532. end: expression.end,
  11533. type: 'BlockStatement',
  11534. body: [ expression ],
  11535. synthetic: true
  11536. };
  11537. }
  11538. new Node$1( raw, parent );
  11539. var type = ( raw.type === 'BlockStatement' ? BlockStatement : types$1$1[ raw.type ] ) || Node$1;
  11540. raw.__proto__ = type.prototype;
  11541. }
  11542. function Scope ( options ) {
  11543. options = options || {};
  11544. this.parent = options.parent;
  11545. this.isBlockScope = !!options.block;
  11546. var scope = this;
  11547. while ( scope.isBlockScope ) scope = scope.parent;
  11548. this.functionScope = scope;
  11549. this.identifiers = [];
  11550. this.declarations = Object.create( null );
  11551. this.references = Object.create( null );
  11552. this.blockScopedDeclarations = this.isBlockScope ? null : Object.create( null );
  11553. this.aliases = this.isBlockScope ? null : Object.create( null );
  11554. }
  11555. Scope.prototype = {
  11556. addDeclaration: function addDeclaration ( node, kind ) {
  11557. for ( var i = 0, list = extractNames( node ); i < list.length; i += 1 ) {
  11558. var identifier = list[i];
  11559. var name = identifier.name;
  11560. var declaration = { name: name, node: identifier, kind: kind, instances: [] };
  11561. this.declarations[ name ] = declaration;
  11562. if ( this.isBlockScope ) {
  11563. if ( !this.functionScope.blockScopedDeclarations[ name ] ) this.functionScope.blockScopedDeclarations[ name ] = [];
  11564. this.functionScope.blockScopedDeclarations[ name ].push( declaration );
  11565. }
  11566. }
  11567. },
  11568. addReference: function addReference ( identifier ) {
  11569. if ( this.consolidated ) {
  11570. this.consolidateReference( identifier );
  11571. } else {
  11572. this.identifiers.push( identifier );
  11573. }
  11574. },
  11575. consolidate: function consolidate () {
  11576. var this$1 = this;
  11577. for ( var i = 0; i < this$1.identifiers.length; i += 1 ) { // we might push to the array during consolidation, so don't cache length
  11578. var identifier = this$1.identifiers[i];
  11579. this$1.consolidateReference( identifier );
  11580. }
  11581. this.consolidated = true; // TODO understand why this is necessary... seems bad
  11582. },
  11583. consolidateReference: function consolidateReference ( identifier ) {
  11584. var declaration = this.declarations[ identifier.name ];
  11585. if ( declaration ) {
  11586. declaration.instances.push( identifier );
  11587. } else {
  11588. this.references[ identifier.name ] = true;
  11589. if ( this.parent ) this.parent.addReference( identifier );
  11590. }
  11591. },
  11592. contains: function contains ( name ) {
  11593. return this.declarations[ name ] ||
  11594. ( this.parent ? this.parent.contains( name ) : false );
  11595. },
  11596. createIdentifier: function createIdentifier ( base ) {
  11597. var this$1 = this;
  11598. if ( typeof base === 'number' ) base = base.toString();
  11599. base = base
  11600. .replace( /\s/g, '' )
  11601. .replace( /\[([^\]]+)\]/g, '_$1' )
  11602. .replace( /[^a-zA-Z0-9_$]/g, '_' )
  11603. .replace( /_{2,}/, '_' );
  11604. var name = base;
  11605. var counter = 1;
  11606. while ( this$1.declarations[ name ] || this$1.references[ name ] || this$1.aliases[ name ] || name in reserved ) {
  11607. name = base + "$" + (counter++);
  11608. }
  11609. this.aliases[ name ] = true;
  11610. return name;
  11611. },
  11612. findDeclaration: function findDeclaration ( name ) {
  11613. return this.declarations[ name ] ||
  11614. ( this.parent && this.parent.findDeclaration( name ) );
  11615. }
  11616. };
  11617. function isUseStrict ( node ) {
  11618. if ( !node ) return false;
  11619. if ( node.type !== 'ExpressionStatement' ) return false;
  11620. if ( node.expression.type !== 'Literal' ) return false;
  11621. return node.expression.value === 'use strict';
  11622. }
  11623. var BlockStatement = (function (Node) {
  11624. function BlockStatement () {
  11625. Node.apply(this, arguments);
  11626. }
  11627. if ( Node ) BlockStatement.__proto__ = Node;
  11628. BlockStatement.prototype = Object.create( Node && Node.prototype );
  11629. BlockStatement.prototype.constructor = BlockStatement;
  11630. BlockStatement.prototype.createScope = function createScope () {
  11631. var this$1 = this;
  11632. this.parentIsFunction = /Function/.test( this.parent.type );
  11633. this.isFunctionBlock = this.parentIsFunction || this.parent.type === 'Root';
  11634. this.scope = new Scope({
  11635. block: !this.isFunctionBlock,
  11636. parent: this.parent.findScope( false )
  11637. });
  11638. if ( this.parentIsFunction ) {
  11639. this.parent.params.forEach( function ( node ) {
  11640. this$1.scope.addDeclaration( node, 'param' );
  11641. });
  11642. }
  11643. };
  11644. BlockStatement.prototype.initialise = function initialise ( transforms ) {
  11645. this.thisAlias = null;
  11646. this.argumentsAlias = null;
  11647. this.defaultParameters = [];
  11648. // normally the scope gets created here, during initialisation,
  11649. // but in some cases (e.g. `for` statements), we need to create
  11650. // the scope early, as it pertains to both the init block and
  11651. // the body of the statement
  11652. if ( !this.scope ) this.createScope();
  11653. this.body.forEach( function ( node ) { return node.initialise( transforms ); } );
  11654. this.scope.consolidate();
  11655. };
  11656. BlockStatement.prototype.findLexicalBoundary = function findLexicalBoundary () {
  11657. if ( this.type === 'Program' ) return this;
  11658. if ( /^Function/.test( this.parent.type ) ) return this;
  11659. return this.parent.findLexicalBoundary();
  11660. };
  11661. BlockStatement.prototype.findScope = function findScope ( functionScope ) {
  11662. if ( functionScope && !this.isFunctionBlock ) return this.parent.findScope( functionScope );
  11663. return this.scope;
  11664. };
  11665. BlockStatement.prototype.getArgumentsAlias = function getArgumentsAlias () {
  11666. if ( !this.argumentsAlias ) {
  11667. this.argumentsAlias = this.scope.createIdentifier( 'arguments' );
  11668. }
  11669. return this.argumentsAlias;
  11670. };
  11671. BlockStatement.prototype.getArgumentsArrayAlias = function getArgumentsArrayAlias () {
  11672. if ( !this.argumentsArrayAlias ) {
  11673. this.argumentsArrayAlias = this.scope.createIdentifier( 'argsArray' );
  11674. }
  11675. return this.argumentsArrayAlias;
  11676. };
  11677. BlockStatement.prototype.getThisAlias = function getThisAlias () {
  11678. if ( !this.thisAlias ) {
  11679. this.thisAlias = this.scope.createIdentifier( 'this' );
  11680. }
  11681. return this.thisAlias;
  11682. };
  11683. BlockStatement.prototype.getIndentation = function getIndentation () {
  11684. var this$1 = this;
  11685. if ( this.indentation === undefined ) {
  11686. var source = this.program.magicString.original;
  11687. var useOuter = this.synthetic || !this.body.length;
  11688. var c = useOuter ? this.start : this.body[0].start;
  11689. while ( c && source[c] !== '\n' ) c -= 1;
  11690. this.indentation = '';
  11691. while ( true ) { // eslint-disable-line no-constant-condition
  11692. c += 1;
  11693. var char = source[c];
  11694. if ( char !== ' ' && char !== '\t' ) break;
  11695. this$1.indentation += char;
  11696. }
  11697. var indentString = this.program.magicString.getIndentString();
  11698. // account for dedented class constructors
  11699. var parent = this.parent;
  11700. while ( parent ) {
  11701. if ( parent.kind === 'constructor' && !parent.parent.parent.superClass ) {
  11702. this$1.indentation = this$1.indentation.replace( indentString, '' );
  11703. }
  11704. parent = parent.parent;
  11705. }
  11706. if ( useOuter ) this.indentation += indentString;
  11707. }
  11708. return this.indentation;
  11709. };
  11710. BlockStatement.prototype.transpile = function transpile ( code, transforms ) {
  11711. var this$1 = this;
  11712. var indentation = this.getIndentation();
  11713. var introStatementGenerators = [];
  11714. if ( this.argumentsAlias ) {
  11715. introStatementGenerators.push( function ( start, prefix, suffix ) {
  11716. var assignment = prefix + "var " + (this$1.argumentsAlias) + " = arguments" + suffix;
  11717. code.insertLeft( start, assignment );
  11718. });
  11719. }
  11720. if ( this.thisAlias ) {
  11721. introStatementGenerators.push( function ( start, prefix, suffix ) {
  11722. var assignment = prefix + "var " + (this$1.thisAlias) + " = this" + suffix;
  11723. code.insertLeft( start, assignment );
  11724. });
  11725. }
  11726. if ( this.argumentsArrayAlias ) {
  11727. introStatementGenerators.push( function ( start, prefix, suffix ) {
  11728. var i = this$1.scope.createIdentifier( 'i' );
  11729. var assignment = prefix + "var " + i + " = arguments.length, " + (this$1.argumentsArrayAlias) + " = Array(" + i + ");\n" + indentation + "while ( " + i + "-- ) " + (this$1.argumentsArrayAlias) + "[" + i + "] = arguments[" + i + "]" + suffix;
  11730. code.insertLeft( start, assignment );
  11731. });
  11732. }
  11733. if ( /Function/.test( this.parent.type ) ) {
  11734. this.transpileParameters( code, transforms, indentation, introStatementGenerators );
  11735. }
  11736. if ( transforms.letConst && this.isFunctionBlock ) {
  11737. this.transpileBlockScopedIdentifiers( code );
  11738. }
  11739. Node.prototype.transpile.call( this, code, transforms );
  11740. if ( this.synthetic ) {
  11741. if ( this.parent.type === 'ArrowFunctionExpression' ) {
  11742. var expr = this.body[0];
  11743. if ( introStatementGenerators.length ) {
  11744. code.insertLeft( this.start, "{" ).insertRight( this.end, ((this.parent.getIndentation()) + "}") );
  11745. code.insertRight( expr.start, ("\n" + indentation + "return ") );
  11746. code.insertLeft( expr.end, ";\n" );
  11747. } else if ( transforms.arrow ) {
  11748. code.insertLeft( expr.start, "{ return " );
  11749. code.insertLeft( expr.end, "; }" );
  11750. }
  11751. }
  11752. else if ( introStatementGenerators.length ) {
  11753. code.insertLeft( this.start, "{" ).insertRight( this.end, "}" );
  11754. }
  11755. }
  11756. var start;
  11757. if ( isUseStrict( this.body[0] ) ) {
  11758. start = this.body[0].end;
  11759. } else if ( this.synthetic || this.parent.type === 'Root' ) {
  11760. start = this.start;
  11761. } else {
  11762. start = this.start + 1;
  11763. }
  11764. var prefix = "\n" + indentation;
  11765. var suffix = ';';
  11766. introStatementGenerators.forEach( function ( fn, i ) {
  11767. if ( i === introStatementGenerators.length - 1 ) suffix = ";\n";
  11768. fn( start, prefix, suffix );
  11769. });
  11770. };
  11771. BlockStatement.prototype.transpileParameters = function transpileParameters ( code, transforms, indentation, introStatementGenerators ) {
  11772. var this$1 = this;
  11773. var params = this.parent.params;
  11774. params.forEach( function ( param ) {
  11775. if ( param.type === 'AssignmentPattern' && param.left.type === 'Identifier' ) {
  11776. if ( transforms.defaultParameter ) {
  11777. introStatementGenerators.push( function ( start, prefix, suffix ) {
  11778. var lhs = prefix + "if ( " + (param.left.name) + " === void 0 ) " + (param.left.name);
  11779. code
  11780. .insertRight( param.left.end, lhs )
  11781. .move( param.left.end, param.right.end, start )
  11782. .insertLeft( param.right.end, suffix );
  11783. });
  11784. }
  11785. }
  11786. else if ( param.type === 'RestElement' ) {
  11787. if ( transforms.spreadRest ) {
  11788. introStatementGenerators.push( function ( start, prefix, suffix ) {
  11789. var penultimateParam = params[ params.length - 2 ];
  11790. if ( penultimateParam ) {
  11791. code.remove( penultimateParam ? penultimateParam.end : param.start, param.end );
  11792. } else {
  11793. var start$1 = param.start, end = param.end; // TODO https://gitlab.com/Rich-Harris/buble/issues/8
  11794. while ( /\s/.test( code.original[ start$1 - 1 ] ) ) start$1 -= 1;
  11795. while ( /\s/.test( code.original[ end ] ) ) end += 1;
  11796. code.remove( start$1, end );
  11797. }
  11798. var name = param.argument.name;
  11799. var len = this$1.scope.createIdentifier( 'len' );
  11800. var count = params.length - 1;
  11801. if ( count ) {
  11802. code.insertLeft( start, (prefix + "var " + name + " = [], " + len + " = arguments.length - " + count + ";\n" + indentation + "while ( " + len + "-- > 0 ) " + name + "[ " + len + " ] = arguments[ " + len + " + " + count + " ]" + suffix) );
  11803. } else {
  11804. code.insertLeft( start, (prefix + "var " + name + " = [], " + len + " = arguments.length;\n" + indentation + "while ( " + len + "-- ) " + name + "[ " + len + " ] = arguments[ " + len + " ]" + suffix) );
  11805. }
  11806. });
  11807. }
  11808. }
  11809. else if ( param.type !== 'Identifier' ) {
  11810. if ( transforms.parameterDestructuring ) {
  11811. var ref = this$1.scope.createIdentifier( 'ref' );
  11812. destructure( code, this$1.scope, param, ref, false, introStatementGenerators );
  11813. code.insertLeft( param.start, ref );
  11814. }
  11815. }
  11816. });
  11817. };
  11818. BlockStatement.prototype.transpileBlockScopedIdentifiers = function transpileBlockScopedIdentifiers ( code ) {
  11819. var this$1 = this;
  11820. Object.keys( this.scope.blockScopedDeclarations ).forEach( function ( name ) {
  11821. var declarations = this$1.scope.blockScopedDeclarations[ name ];
  11822. for ( var i = 0, list = declarations; i < list.length; i += 1 ) {
  11823. var declaration = list[i];
  11824. var cont = false; // TODO implement proper continue...
  11825. if ( declaration.kind === 'for.let' ) {
  11826. // special case
  11827. var forStatement = declaration.node.findNearest( 'ForStatement' );
  11828. if ( forStatement.shouldRewriteAsFunction ) {
  11829. var outerAlias = this$1.scope.createIdentifier( name );
  11830. var innerAlias = forStatement.reassigned[ name ] ?
  11831. this$1.scope.createIdentifier( name ) :
  11832. name;
  11833. declaration.name = outerAlias;
  11834. code.overwrite( declaration.node.start, declaration.node.end, outerAlias, true );
  11835. forStatement.aliases[ name ] = {
  11836. outer: outerAlias,
  11837. inner: innerAlias
  11838. };
  11839. for ( var i$1 = 0, list$1 = declaration.instances; i$1 < list$1.length; i$1 += 1 ) {
  11840. var identifier = list$1[i$1];
  11841. var alias = forStatement.body.contains( identifier ) ?
  11842. innerAlias :
  11843. outerAlias;
  11844. if ( name !== alias ) {
  11845. code.overwrite( identifier.start, identifier.end, alias, true );
  11846. }
  11847. }
  11848. cont = true;
  11849. }
  11850. }
  11851. if ( !cont ) {
  11852. var alias$1 = this$1.scope.createIdentifier( name );
  11853. if ( name !== alias$1 ) {
  11854. declaration.name = alias$1;
  11855. code.overwrite( declaration.node.start, declaration.node.end, alias$1, true );
  11856. for ( var i$2 = 0, list$2 = declaration.instances; i$2 < list$2.length; i$2 += 1 ) {
  11857. var identifier$1 = list$2[i$2];
  11858. identifier$1.rewritten = true;
  11859. code.overwrite( identifier$1.start, identifier$1.end, alias$1, true );
  11860. }
  11861. }
  11862. }
  11863. }
  11864. });
  11865. };
  11866. return BlockStatement;
  11867. }(Node$1));
  11868. function Program ( source, ast, transforms, options ) {
  11869. var this$1 = this;
  11870. this.type = 'Root';
  11871. // options
  11872. this.jsx = options.jsx || 'React.createElement';
  11873. this.options = options;
  11874. this.source = source;
  11875. this.magicString = new magicString_cjs( source );
  11876. this.ast = ast;
  11877. this.depth = 0;
  11878. wrap( this.body = ast, this );
  11879. this.body.__proto__ = BlockStatement.prototype;
  11880. this.indentExclusionElements = [];
  11881. this.body.initialise( transforms );
  11882. this.indentExclusions = Object.create( null );
  11883. for ( var i$1 = 0, list = this.indentExclusionElements; i$1 < list.length; i$1 += 1 ) {
  11884. var node = list[i$1];
  11885. for ( var i = node.start; i < node.end; i += 1 ) {
  11886. this$1.indentExclusions[ i ] = true;
  11887. }
  11888. }
  11889. this.body.transpile( this.magicString, transforms );
  11890. }
  11891. Program.prototype = {
  11892. export: function export$1 ( options ) {
  11893. if ( options === void 0 ) options = {};
  11894. return {
  11895. code: this.magicString.toString(),
  11896. map: this.magicString.generateMap({
  11897. file: options.file,
  11898. source: options.source,
  11899. includeContent: options.includeContent !== false
  11900. })
  11901. };
  11902. },
  11903. findNearest: function findNearest () {
  11904. return null;
  11905. },
  11906. findScope: function findScope () {
  11907. return null;
  11908. }
  11909. };
  11910. var matrix = {
  11911. chrome: {
  11912. 48: 1333689725,
  11913. 49: 1342078975,
  11914. 50: 1610514431,
  11915. 51: 1610514431,
  11916. 52: 2147385343
  11917. },
  11918. firefox: {
  11919. 43: 1207307741,
  11920. 44: 1207307741,
  11921. 45: 1207307741,
  11922. 46: 1476267485,
  11923. 47: 1476296671,
  11924. 48: 1476296671
  11925. },
  11926. safari: {
  11927. 8: 1073741824,
  11928. 9: 1328940894
  11929. },
  11930. ie: {
  11931. 8: 0,
  11932. 9: 1073741824,
  11933. 10: 1073741824,
  11934. 11: 1073770592
  11935. },
  11936. edge: {
  11937. 12: 1591620701,
  11938. 13: 1608400479
  11939. },
  11940. node: {
  11941. '0.10': 1075052608,
  11942. '0.12': 1091830852,
  11943. 4: 1327398527,
  11944. 5: 1327398527,
  11945. 6: 1610514431
  11946. }
  11947. };
  11948. var features = [
  11949. 'arrow',
  11950. 'classes',
  11951. 'collections',
  11952. 'computedProperty',
  11953. 'conciseMethodProperty',
  11954. 'constLoop',
  11955. 'constRedef',
  11956. 'defaultParameter',
  11957. 'destructuring',
  11958. 'extendNatives',
  11959. 'forOf',
  11960. 'generator',
  11961. 'letConst',
  11962. 'letLoop',
  11963. 'letLoopScope',
  11964. 'moduleExport',
  11965. 'moduleImport',
  11966. 'numericLiteral',
  11967. 'objectProto',
  11968. 'objectSuper',
  11969. 'oldOctalLiteral',
  11970. 'parameterDestructuring',
  11971. 'spreadRest',
  11972. 'stickyRegExp',
  11973. 'symbol',
  11974. 'templateString',
  11975. 'unicodeEscape',
  11976. 'unicodeIdentifier',
  11977. 'unicodeRegExp',
  11978. // ES2016
  11979. 'exponentiation',
  11980. // additional transforms, not from
  11981. // https://featuretests.io
  11982. 'reservedProperties'
  11983. ];
  11984. var version$1 = "0.16.0";
  11985. var ref = [
  11986. inject$1,
  11987. inject
  11988. ].reduce( function ( final, plugin ) { return plugin( final ); }, acorn );
  11989. var parse = ref.parse;
  11990. var dangerousTransforms = [
  11991. 'dangerousTaggedTemplateString',
  11992. 'dangerousForOf'
  11993. ];
  11994. function target ( target ) {
  11995. var targets = Object.keys( target );
  11996. var bitmask = targets.length ?
  11997. 2147483647 :
  11998. 1073741824;
  11999. Object.keys( target ).forEach( function ( environment ) {
  12000. var versions = matrix[ environment ];
  12001. if ( !versions ) throw new Error( ("Unknown environment '" + environment + "'. Please raise an issue at https://gitlab.com/Rich-Harris/buble/issues") );
  12002. var targetVersion = target[ environment ];
  12003. if ( !( targetVersion in versions ) ) throw new Error( ("Support data exists for the following versions of " + environment + ": " + (Object.keys( versions ).join( ', ')) + ". Please raise an issue at https://gitlab.com/Rich-Harris/buble/issues") );
  12004. var support = versions[ targetVersion ];
  12005. bitmask &= support;
  12006. });
  12007. var transforms = Object.create( null );
  12008. features.forEach( function ( name, i ) {
  12009. transforms[ name ] = !( bitmask & 1 << i );
  12010. });
  12011. dangerousTransforms.forEach( function ( name ) {
  12012. transforms[ name ] = false;
  12013. });
  12014. transforms.stripWith = false;
  12015. transforms.stripWithFunctional = false;
  12016. return transforms;
  12017. }
  12018. function transform ( source, options ) {
  12019. if ( options === void 0 ) options = {};
  12020. var transforms = target( options.target || {} );
  12021. Object.keys( options.transforms || {} ).forEach( function ( name ) {
  12022. if ( name === 'modules' ) {
  12023. if ( !( 'moduleImport' in options.transforms ) ) transforms.moduleImport = options.transforms.modules;
  12024. if ( !( 'moduleExport' in options.transforms ) ) transforms.moduleExport = options.transforms.modules;
  12025. return;
  12026. }
  12027. if ( !( name in transforms ) ) throw new Error( ("Unknown transform '" + name + "'") );
  12028. transforms[ name ] = options.transforms[ name ];
  12029. });
  12030. if (transforms.stripWith) {
  12031. // necessary for { key } to be prefixed properly
  12032. // in case the user uses a target environment that supports this
  12033. transforms.conciseMethodProperty = true;
  12034. }
  12035. var ast;
  12036. var jsx = null;
  12037. try {
  12038. ast = parse( source, {
  12039. ecmaVersion: 8,
  12040. preserveParens: true,
  12041. sourceType: transforms.stripWith ? 'script' : 'module',
  12042. onComment: function (block, text) {
  12043. if ( !jsx ) {
  12044. var match = /@jsx\s+([^\s]+)/.exec( text );
  12045. if ( match ) jsx = match[1];
  12046. }
  12047. },
  12048. plugins: {
  12049. jsx: true,
  12050. objectSpread: true
  12051. }
  12052. });
  12053. options.jsx = jsx || options.jsx;
  12054. } catch ( err ) {
  12055. err.snippet = getSnippet( source, err.loc );
  12056. err.toString = function () { return ((err.name) + ": " + (err.message) + "\n" + (err.snippet)); };
  12057. throw err;
  12058. }
  12059. return new Program( source, ast, transforms, options ).export( options );
  12060. }
  12061. exports.target = target;
  12062. exports.transform = transform;
  12063. exports.VERSION = version$1;
  12064. Object.defineProperty(exports, '__esModule', { value: true });
  12065. })));
  12066. //# sourceMappingURL=buble.deps.js.map