buble.js 374 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121
  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 = global.buble || {})));
  5. }(this, (function (exports) { 'use strict';
  6. var __commonjs_global = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : this;
  7. function __commonjs(fn, module) { return module = { exports: {} }, fn(module, module.exports, __commonjs_global), module.exports; }
  8. var acorn = __commonjs(function (module, exports, global) {
  9. (function (global, factory) {
  10. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
  11. typeof define === 'function' && define.amd ? define(['exports'], factory) :
  12. (factory((global.acorn = global.acorn || {})));
  13. }(__commonjs_global, function (exports) { 'use strict';
  14. // Reserved word lists for various dialects of the language
  15. var reservedWords = {
  16. 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",
  17. 5: "class enum extends super const export import",
  18. 6: "enum",
  19. 7: "enum",
  20. strict: "implements interface let package private protected public static yield",
  21. strictBind: "eval arguments"
  22. };
  23. // And the keywords
  24. 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";
  25. var keywords = {
  26. 5: ecma5AndLessKeywords,
  27. 6: ecma5AndLessKeywords + " const class extends export import super"
  28. };
  29. // ## Character categories
  30. // Big ugly regular expressions that match characters in the
  31. // whitespace, identifier, and identifier-start categories. These
  32. // are only applied when a character is found to actually have a
  33. // code point above 128.
  34. // Generated by `bin/generate-identifier-regex.js`.
  35. 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";
  36. 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";
  37. var nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]");
  38. var nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]");
  39. nonASCIIidentifierStartChars = nonASCIIidentifierChars = null;
  40. // These are a run-length and offset encoded representation of the
  41. // >0xffff code points that are a valid part of identifiers. The
  42. // offset starts at 0x10000, and each pair of numbers represents an
  43. // offset to the next range, and then a size of the range. They were
  44. // generated by bin/generate-identifier-regex.js
  45. 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];
  46. 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];
  47. // This has a complexity linear to the value of the code. The
  48. // assumption is that looking up astral identifier characters is
  49. // rare.
  50. function isInAstralSet(code, set) {
  51. var pos = 0x10000;
  52. for (var i = 0; i < set.length; i += 2) {
  53. pos += set[i];
  54. if (pos > code) return false
  55. pos += set[i + 1];
  56. if (pos >= code) return true
  57. }
  58. }
  59. // Test whether a given character code starts an identifier.
  60. function isIdentifierStart(code, astral) {
  61. if (code < 65) return code === 36
  62. if (code < 91) return true
  63. if (code < 97) return code === 95
  64. if (code < 123) return true
  65. if (code <= 0xffff) return code >= 0xaa && nonASCIIidentifierStart.test(String.fromCharCode(code))
  66. if (astral === false) return false
  67. return isInAstralSet(code, astralIdentifierStartCodes)
  68. }
  69. // Test whether a given character is part of an identifier.
  70. function isIdentifierChar(code, astral) {
  71. if (code < 48) return code === 36
  72. if (code < 58) return true
  73. if (code < 65) return false
  74. if (code < 91) return true
  75. if (code < 97) return code === 95
  76. if (code < 123) return true
  77. if (code <= 0xffff) return code >= 0xaa && nonASCIIidentifier.test(String.fromCharCode(code))
  78. if (astral === false) return false
  79. return isInAstralSet(code, astralIdentifierStartCodes) || isInAstralSet(code, astralIdentifierCodes)
  80. }
  81. // ## Token types
  82. // The assignment of fine-grained, information-carrying type objects
  83. // allows the tokenizer to store the information it has about a
  84. // token in a way that is very cheap for the parser to look up.
  85. // All token type variables start with an underscore, to make them
  86. // easy to recognize.
  87. // The `beforeExpr` property is used to disambiguate between regular
  88. // expressions and divisions. It is set on all token types that can
  89. // be followed by an expression (thus, a slash after them would be a
  90. // regular expression).
  91. //
  92. // The `startsExpr` property is used to check if the token ends a
  93. // `yield` expression. It is set on all token types that either can
  94. // directly start an expression (like a quotation mark) or can
  95. // continue an expression (like the body of a string).
  96. //
  97. // `isLoop` marks a keyword as starting a loop, which is important
  98. // to know when parsing a label, in order to allow or disallow
  99. // continue jumps to that label.
  100. var TokenType = function TokenType(label, conf) {
  101. if ( conf === void 0 ) conf = {};
  102. this.label = label;
  103. this.keyword = conf.keyword;
  104. this.beforeExpr = !!conf.beforeExpr;
  105. this.startsExpr = !!conf.startsExpr;
  106. this.isLoop = !!conf.isLoop;
  107. this.isAssign = !!conf.isAssign;
  108. this.prefix = !!conf.prefix;
  109. this.postfix = !!conf.postfix;
  110. this.binop = conf.binop || null;
  111. this.updateContext = null;
  112. };
  113. function binop(name, prec) {
  114. return new TokenType(name, {beforeExpr: true, binop: prec})
  115. }
  116. var beforeExpr = {beforeExpr: true};
  117. var startsExpr = {startsExpr: true};
  118. // Map keyword names to token types.
  119. var keywordTypes = {};
  120. // Succinct definitions of keyword token types
  121. function kw(name, options) {
  122. if ( options === void 0 ) options = {};
  123. options.keyword = name;
  124. return keywordTypes[name] = new TokenType(name, options)
  125. }
  126. var tt = {
  127. num: new TokenType("num", startsExpr),
  128. regexp: new TokenType("regexp", startsExpr),
  129. string: new TokenType("string", startsExpr),
  130. name: new TokenType("name", startsExpr),
  131. eof: new TokenType("eof"),
  132. // Punctuation token types.
  133. bracketL: new TokenType("[", {beforeExpr: true, startsExpr: true}),
  134. bracketR: new TokenType("]"),
  135. braceL: new TokenType("{", {beforeExpr: true, startsExpr: true}),
  136. braceR: new TokenType("}"),
  137. parenL: new TokenType("(", {beforeExpr: true, startsExpr: true}),
  138. parenR: new TokenType(")"),
  139. comma: new TokenType(",", beforeExpr),
  140. semi: new TokenType(";", beforeExpr),
  141. colon: new TokenType(":", beforeExpr),
  142. dot: new TokenType("."),
  143. question: new TokenType("?", beforeExpr),
  144. arrow: new TokenType("=>", beforeExpr),
  145. template: new TokenType("template"),
  146. ellipsis: new TokenType("...", beforeExpr),
  147. backQuote: new TokenType("`", startsExpr),
  148. dollarBraceL: new TokenType("${", {beforeExpr: true, startsExpr: true}),
  149. // Operators. These carry several kinds of properties to help the
  150. // parser use them properly (the presence of these properties is
  151. // what categorizes them as operators).
  152. //
  153. // `binop`, when present, specifies that this operator is a binary
  154. // operator, and will refer to its precedence.
  155. //
  156. // `prefix` and `postfix` mark the operator as a prefix or postfix
  157. // unary operator.
  158. //
  159. // `isAssign` marks all of `=`, `+=`, `-=` etcetera, which act as
  160. // binary operators with a very low precedence, that should result
  161. // in AssignmentExpression nodes.
  162. eq: new TokenType("=", {beforeExpr: true, isAssign: true}),
  163. assign: new TokenType("_=", {beforeExpr: true, isAssign: true}),
  164. incDec: new TokenType("++/--", {prefix: true, postfix: true, startsExpr: true}),
  165. prefix: new TokenType("prefix", {beforeExpr: true, prefix: true, startsExpr: true}),
  166. logicalOR: binop("||", 1),
  167. logicalAND: binop("&&", 2),
  168. bitwiseOR: binop("|", 3),
  169. bitwiseXOR: binop("^", 4),
  170. bitwiseAND: binop("&", 5),
  171. equality: binop("==/!=", 6),
  172. relational: binop("</>", 7),
  173. bitShift: binop("<</>>", 8),
  174. plusMin: new TokenType("+/-", {beforeExpr: true, binop: 9, prefix: true, startsExpr: true}),
  175. modulo: binop("%", 10),
  176. star: binop("*", 10),
  177. slash: binop("/", 10),
  178. starstar: new TokenType("**", {beforeExpr: true}),
  179. // Keyword token types.
  180. _break: kw("break"),
  181. _case: kw("case", beforeExpr),
  182. _catch: kw("catch"),
  183. _continue: kw("continue"),
  184. _debugger: kw("debugger"),
  185. _default: kw("default", beforeExpr),
  186. _do: kw("do", {isLoop: true, beforeExpr: true}),
  187. _else: kw("else", beforeExpr),
  188. _finally: kw("finally"),
  189. _for: kw("for", {isLoop: true}),
  190. _function: kw("function", startsExpr),
  191. _if: kw("if"),
  192. _return: kw("return", beforeExpr),
  193. _switch: kw("switch"),
  194. _throw: kw("throw", beforeExpr),
  195. _try: kw("try"),
  196. _var: kw("var"),
  197. _const: kw("const"),
  198. _while: kw("while", {isLoop: true}),
  199. _with: kw("with"),
  200. _new: kw("new", {beforeExpr: true, startsExpr: true}),
  201. _this: kw("this", startsExpr),
  202. _super: kw("super", startsExpr),
  203. _class: kw("class"),
  204. _extends: kw("extends", beforeExpr),
  205. _export: kw("export"),
  206. _import: kw("import"),
  207. _null: kw("null", startsExpr),
  208. _true: kw("true", startsExpr),
  209. _false: kw("false", startsExpr),
  210. _in: kw("in", {beforeExpr: true, binop: 7}),
  211. _instanceof: kw("instanceof", {beforeExpr: true, binop: 7}),
  212. _typeof: kw("typeof", {beforeExpr: true, prefix: true, startsExpr: true}),
  213. _void: kw("void", {beforeExpr: true, prefix: true, startsExpr: true}),
  214. _delete: kw("delete", {beforeExpr: true, prefix: true, startsExpr: true})
  215. };
  216. // Matches a whole line break (where CRLF is considered a single
  217. // line break). Used to count lines.
  218. var lineBreak = /\r\n?|\n|\u2028|\u2029/;
  219. var lineBreakG = new RegExp(lineBreak.source, "g");
  220. function isNewLine(code) {
  221. return code === 10 || code === 13 || code === 0x2028 || code == 0x2029
  222. }
  223. var nonASCIIwhitespace = /[\u1680\u180e\u2000-\u200a\u202f\u205f\u3000\ufeff]/;
  224. var skipWhiteSpace = /(?:\s|\/\/.*|\/\*[^]*?\*\/)*/g;
  225. function isArray(obj) {
  226. return Object.prototype.toString.call(obj) === "[object Array]"
  227. }
  228. // Checks if an object has a property.
  229. function has(obj, propName) {
  230. return Object.prototype.hasOwnProperty.call(obj, propName)
  231. }
  232. // These are used when `options.locations` is on, for the
  233. // `startLoc` and `endLoc` properties.
  234. var Position = function Position(line, col) {
  235. this.line = line;
  236. this.column = col;
  237. };
  238. Position.prototype.offset = function offset (n) {
  239. return new Position(this.line, this.column + n)
  240. };
  241. var SourceLocation = function SourceLocation(p, start, end) {
  242. this.start = start;
  243. this.end = end;
  244. if (p.sourceFile !== null) this.source = p.sourceFile;
  245. };
  246. // The `getLineInfo` function is mostly useful when the
  247. // `locations` option is off (for performance reasons) and you
  248. // want to find the line/column position for a given character
  249. // offset. `input` should be the code string that the offset refers
  250. // into.
  251. function getLineInfo(input, offset) {
  252. for (var line = 1, cur = 0;;) {
  253. lineBreakG.lastIndex = cur;
  254. var match = lineBreakG.exec(input);
  255. if (match && match.index < offset) {
  256. ++line;
  257. cur = match.index + match[0].length;
  258. } else {
  259. return new Position(line, offset - cur)
  260. }
  261. }
  262. }
  263. // A second optional argument can be given to further configure
  264. // the parser process. These options are recognized:
  265. var defaultOptions = {
  266. // `ecmaVersion` indicates the ECMAScript version to parse. Must
  267. // be either 3, or 5, or 6. This influences support for strict
  268. // mode, the set of reserved words, support for getters and
  269. // setters and other features. The default is 6.
  270. ecmaVersion: 6,
  271. // Source type ("script" or "module") for different semantics
  272. sourceType: "script",
  273. // `onInsertedSemicolon` can be a callback that will be called
  274. // when a semicolon is automatically inserted. It will be passed
  275. // th position of the comma as an offset, and if `locations` is
  276. // enabled, it is given the location as a `{line, column}` object
  277. // as second argument.
  278. onInsertedSemicolon: null,
  279. // `onTrailingComma` is similar to `onInsertedSemicolon`, but for
  280. // trailing commas.
  281. onTrailingComma: null,
  282. // By default, reserved words are only enforced if ecmaVersion >= 5.
  283. // Set `allowReserved` to a boolean value to explicitly turn this on
  284. // an off. When this option has the value "never", reserved words
  285. // and keywords can also not be used as property names.
  286. allowReserved: null,
  287. // When enabled, a return at the top level is not considered an
  288. // error.
  289. allowReturnOutsideFunction: false,
  290. // When enabled, import/export statements are not constrained to
  291. // appearing at the top of the program.
  292. allowImportExportEverywhere: false,
  293. // When enabled, hashbang directive in the beginning of file
  294. // is allowed and treated as a line comment.
  295. allowHashBang: false,
  296. // When `locations` is on, `loc` properties holding objects with
  297. // `start` and `end` properties in `{line, column}` form (with
  298. // line being 1-based and column 0-based) will be attached to the
  299. // nodes.
  300. locations: false,
  301. // A function can be passed as `onToken` option, which will
  302. // cause Acorn to call that function with object in the same
  303. // format as tokens returned from `tokenizer().getToken()`. Note
  304. // that you are not allowed to call the parser from the
  305. // callback—that will corrupt its internal state.
  306. onToken: null,
  307. // A function can be passed as `onComment` option, which will
  308. // cause Acorn to call that function with `(block, text, start,
  309. // end)` parameters whenever a comment is skipped. `block` is a
  310. // boolean indicating whether this is a block (`/* */`) comment,
  311. // `text` is the content of the comment, and `start` and `end` are
  312. // character offsets that denote the start and end of the comment.
  313. // When the `locations` option is on, two more parameters are
  314. // passed, the full `{line, column}` locations of the start and
  315. // end of the comments. Note that you are not allowed to call the
  316. // parser from the callback—that will corrupt its internal state.
  317. onComment: null,
  318. // Nodes have their start and end characters offsets recorded in
  319. // `start` and `end` properties (directly on the node, rather than
  320. // the `loc` object, which holds line/column data. To also add a
  321. // [semi-standardized][range] `range` property holding a `[start,
  322. // end]` array with the same numbers, set the `ranges` option to
  323. // `true`.
  324. //
  325. // [range]: https://bugzilla.mozilla.org/show_bug.cgi?id=745678
  326. ranges: false,
  327. // It is possible to parse multiple files into a single AST by
  328. // passing the tree produced by parsing the first file as
  329. // `program` option in subsequent parses. This will add the
  330. // toplevel forms of the parsed file to the `Program` (top) node
  331. // of an existing parse tree.
  332. program: null,
  333. // When `locations` is on, you can pass this to record the source
  334. // file in every node's `loc` object.
  335. sourceFile: null,
  336. // This value, if given, is stored in every node, whether
  337. // `locations` is on or off.
  338. directSourceFile: null,
  339. // When enabled, parenthesized expressions are represented by
  340. // (non-standard) ParenthesizedExpression nodes
  341. preserveParens: false,
  342. plugins: {}
  343. };
  344. // Interpret and default an options object
  345. function getOptions(opts) {
  346. var options = {};
  347. for (var opt in defaultOptions)
  348. options[opt] = opts && has(opts, opt) ? opts[opt] : defaultOptions[opt];
  349. if (options.allowReserved == null)
  350. options.allowReserved = options.ecmaVersion < 5;
  351. if (isArray(options.onToken)) {
  352. var tokens = options.onToken;
  353. options.onToken = function (token) { return tokens.push(token); };
  354. }
  355. if (isArray(options.onComment))
  356. options.onComment = pushComment(options, options.onComment);
  357. return options
  358. }
  359. function pushComment(options, array) {
  360. return function (block, text, start, end, startLoc, endLoc) {
  361. var comment = {
  362. type: block ? 'Block' : 'Line',
  363. value: text,
  364. start: start,
  365. end: end
  366. };
  367. if (options.locations)
  368. comment.loc = new SourceLocation(this, startLoc, endLoc);
  369. if (options.ranges)
  370. comment.range = [start, end];
  371. array.push(comment);
  372. }
  373. }
  374. // Registered plugins
  375. var plugins = {};
  376. function keywordRegexp(words) {
  377. return new RegExp("^(" + words.replace(/ /g, "|") + ")$")
  378. }
  379. var Parser = function Parser(options, input, startPos) {
  380. this.options = options = getOptions(options);
  381. this.sourceFile = options.sourceFile;
  382. this.keywords = keywordRegexp(keywords[options.ecmaVersion >= 6 ? 6 : 5]);
  383. var reserved = options.allowReserved ? "" :
  384. reservedWords[options.ecmaVersion] + (options.sourceType == "module" ? " await" : "");
  385. this.reservedWords = keywordRegexp(reserved);
  386. var reservedStrict = (reserved ? reserved + " " : "") + reservedWords.strict;
  387. this.reservedWordsStrict = keywordRegexp(reservedStrict);
  388. this.reservedWordsStrictBind = keywordRegexp(reservedStrict + " " + reservedWords.strictBind);
  389. this.input = String(input);
  390. // Used to signal to callers of `readWord1` whether the word
  391. // contained any escape sequences. This is needed because words with
  392. // escape sequences must not be interpreted as keywords.
  393. this.containsEsc = false;
  394. // Load plugins
  395. this.loadPlugins(options.plugins);
  396. // Set up token state
  397. // The current position of the tokenizer in the input.
  398. if (startPos) {
  399. this.pos = startPos;
  400. this.lineStart = Math.max(0, this.input.lastIndexOf("\n", startPos));
  401. this.curLine = this.input.slice(0, this.lineStart).split(lineBreak).length;
  402. } else {
  403. this.pos = this.lineStart = 0;
  404. this.curLine = 1;
  405. }
  406. // Properties of the current token:
  407. // Its type
  408. this.type = tt.eof;
  409. // For tokens that include more information than their type, the value
  410. this.value = null;
  411. // Its start and end offset
  412. this.start = this.end = this.pos;
  413. // And, if locations are used, the {line, column} object
  414. // corresponding to those offsets
  415. this.startLoc = this.endLoc = this.curPosition();
  416. // Position information for the previous token
  417. this.lastTokEndLoc = this.lastTokStartLoc = null;
  418. this.lastTokStart = this.lastTokEnd = this.pos;
  419. // The context stack is used to superficially track syntactic
  420. // context to predict whether a regular expression is allowed in a
  421. // given position.
  422. this.context = this.initialContext();
  423. this.exprAllowed = true;
  424. // Figure out if it's a module code.
  425. this.strict = this.inModule = options.sourceType === "module";
  426. // Used to signify the start of a potential arrow function
  427. this.potentialArrowAt = -1;
  428. // Flags to track whether we are in a function, a generator.
  429. this.inFunction = this.inGenerator = false;
  430. // Labels in scope.
  431. this.labels = [];
  432. // If enabled, skip leading hashbang line.
  433. if (this.pos === 0 && options.allowHashBang && this.input.slice(0, 2) === '#!')
  434. this.skipLineComment(2);
  435. };
  436. // DEPRECATED Kept for backwards compatibility until 3.0 in case a plugin uses them
  437. Parser.prototype.isKeyword = function isKeyword (word) { return this.keywords.test(word) };
  438. Parser.prototype.isReservedWord = function isReservedWord (word) { return this.reservedWords.test(word) };
  439. Parser.prototype.extend = function extend (name, f) {
  440. this[name] = f(this[name]);
  441. };
  442. Parser.prototype.loadPlugins = function loadPlugins (pluginConfigs) {
  443. var this$1 = this;
  444. for (var name in pluginConfigs) {
  445. var plugin = plugins[name];
  446. if (!plugin) throw new Error("Plugin '" + name + "' not found")
  447. plugin(this$1, pluginConfigs[name]);
  448. }
  449. };
  450. Parser.prototype.parse = function parse () {
  451. var node = this.options.program || this.startNode();
  452. this.nextToken();
  453. return this.parseTopLevel(node)
  454. };
  455. var pp = Parser.prototype;
  456. // ## Parser utilities
  457. // Test whether a statement node is the string literal `"use strict"`.
  458. pp.isUseStrict = function(stmt) {
  459. return this.options.ecmaVersion >= 5 && stmt.type === "ExpressionStatement" &&
  460. stmt.expression.type === "Literal" &&
  461. stmt.expression.raw.slice(1, -1) === "use strict"
  462. };
  463. // Predicate that tests whether the next token is of the given
  464. // type, and if yes, consumes it as a side effect.
  465. pp.eat = function(type) {
  466. if (this.type === type) {
  467. this.next();
  468. return true
  469. } else {
  470. return false
  471. }
  472. };
  473. // Tests whether parsed token is a contextual keyword.
  474. pp.isContextual = function(name) {
  475. return this.type === tt.name && this.value === name
  476. };
  477. // Consumes contextual keyword if possible.
  478. pp.eatContextual = function(name) {
  479. return this.value === name && this.eat(tt.name)
  480. };
  481. // Asserts that following token is given contextual keyword.
  482. pp.expectContextual = function(name) {
  483. if (!this.eatContextual(name)) this.unexpected();
  484. };
  485. // Test whether a semicolon can be inserted at the current position.
  486. pp.canInsertSemicolon = function() {
  487. return this.type === tt.eof ||
  488. this.type === tt.braceR ||
  489. lineBreak.test(this.input.slice(this.lastTokEnd, this.start))
  490. };
  491. pp.insertSemicolon = function() {
  492. if (this.canInsertSemicolon()) {
  493. if (this.options.onInsertedSemicolon)
  494. this.options.onInsertedSemicolon(this.lastTokEnd, this.lastTokEndLoc);
  495. return true
  496. }
  497. };
  498. // Consume a semicolon, or, failing that, see if we are allowed to
  499. // pretend that there is a semicolon at this position.
  500. pp.semicolon = function() {
  501. if (!this.eat(tt.semi) && !this.insertSemicolon()) this.unexpected();
  502. };
  503. pp.afterTrailingComma = function(tokType) {
  504. if (this.type == tokType) {
  505. if (this.options.onTrailingComma)
  506. this.options.onTrailingComma(this.lastTokStart, this.lastTokStartLoc);
  507. this.next();
  508. return true
  509. }
  510. };
  511. // Expect a token of a given type. If found, consume it, otherwise,
  512. // raise an unexpected token error.
  513. pp.expect = function(type) {
  514. this.eat(type) || this.unexpected();
  515. };
  516. // Raise an unexpected token error.
  517. pp.unexpected = function(pos) {
  518. this.raise(pos != null ? pos : this.start, "Unexpected token");
  519. };
  520. var DestructuringErrors = function DestructuringErrors() {
  521. this.shorthandAssign = 0;
  522. this.trailingComma = 0;
  523. };
  524. pp.checkPatternErrors = function(refDestructuringErrors, andThrow) {
  525. var trailing = refDestructuringErrors && refDestructuringErrors.trailingComma;
  526. if (!andThrow) return !!trailing
  527. if (trailing) this.raise(trailing, "Comma is not permitted after the rest element");
  528. };
  529. pp.checkExpressionErrors = function(refDestructuringErrors, andThrow) {
  530. var pos = refDestructuringErrors && refDestructuringErrors.shorthandAssign;
  531. if (!andThrow) return !!pos
  532. if (pos) this.raise(pos, "Shorthand property assignments are valid only in destructuring patterns");
  533. };
  534. var pp$1 = Parser.prototype;
  535. // ### Statement parsing
  536. // Parse a program. Initializes the parser, reads any number of
  537. // statements, and wraps them in a Program node. Optionally takes a
  538. // `program` argument. If present, the statements will be appended
  539. // to its body instead of creating a new node.
  540. pp$1.parseTopLevel = function(node) {
  541. var this$1 = this;
  542. var first = true;
  543. if (!node.body) node.body = [];
  544. while (this.type !== tt.eof) {
  545. var stmt = this$1.parseStatement(true, true);
  546. node.body.push(stmt);
  547. if (first) {
  548. if (this$1.isUseStrict(stmt)) this$1.setStrict(true);
  549. first = false;
  550. }
  551. }
  552. this.next();
  553. if (this.options.ecmaVersion >= 6) {
  554. node.sourceType = this.options.sourceType;
  555. }
  556. return this.finishNode(node, "Program")
  557. };
  558. var loopLabel = {kind: "loop"};
  559. var switchLabel = {kind: "switch"};
  560. pp$1.isLet = function() {
  561. if (this.type !== tt.name || this.options.ecmaVersion < 6 || this.value != "let") return false
  562. skipWhiteSpace.lastIndex = this.pos;
  563. var skip = skipWhiteSpace.exec(this.input);
  564. var next = this.pos + skip[0].length, nextCh = this.input.charCodeAt(next);
  565. if (nextCh === 91 || nextCh == 123) return true // '{' and '['
  566. if (isIdentifierStart(nextCh, true)) {
  567. for (var pos = next + 1; isIdentifierChar(this.input.charCodeAt(pos), true); ++pos) {}
  568. var ident = this.input.slice(next, pos);
  569. if (!this.isKeyword(ident)) return true
  570. }
  571. return false
  572. };
  573. // Parse a single statement.
  574. //
  575. // If expecting a statement and finding a slash operator, parse a
  576. // regular expression literal. This is to handle cases like
  577. // `if (foo) /blah/.exec(foo)`, where looking at the previous token
  578. // does not help.
  579. pp$1.parseStatement = function(declaration, topLevel) {
  580. var starttype = this.type, node = this.startNode(), kind;
  581. if (this.isLet()) {
  582. starttype = tt._var;
  583. kind = "let";
  584. }
  585. // Most types of statements are recognized by the keyword they
  586. // start with. Many are trivial to parse, some require a bit of
  587. // complexity.
  588. switch (starttype) {
  589. case tt._break: case tt._continue: return this.parseBreakContinueStatement(node, starttype.keyword)
  590. case tt._debugger: return this.parseDebuggerStatement(node)
  591. case tt._do: return this.parseDoStatement(node)
  592. case tt._for: return this.parseForStatement(node)
  593. case tt._function:
  594. if (!declaration && this.options.ecmaVersion >= 6) this.unexpected();
  595. return this.parseFunctionStatement(node)
  596. case tt._class:
  597. if (!declaration) this.unexpected();
  598. return this.parseClass(node, true)
  599. case tt._if: return this.parseIfStatement(node)
  600. case tt._return: return this.parseReturnStatement(node)
  601. case tt._switch: return this.parseSwitchStatement(node)
  602. case tt._throw: return this.parseThrowStatement(node)
  603. case tt._try: return this.parseTryStatement(node)
  604. case tt._const: case tt._var:
  605. kind = kind || this.value;
  606. if (!declaration && kind != "var") this.unexpected();
  607. return this.parseVarStatement(node, kind)
  608. case tt._while: return this.parseWhileStatement(node)
  609. case tt._with: return this.parseWithStatement(node)
  610. case tt.braceL: return this.parseBlock()
  611. case tt.semi: return this.parseEmptyStatement(node)
  612. case tt._export:
  613. case tt._import:
  614. if (!this.options.allowImportExportEverywhere) {
  615. if (!topLevel)
  616. this.raise(this.start, "'import' and 'export' may only appear at the top level");
  617. if (!this.inModule)
  618. this.raise(this.start, "'import' and 'export' may appear only with 'sourceType: module'");
  619. }
  620. return starttype === tt._import ? this.parseImport(node) : this.parseExport(node)
  621. // If the statement does not start with a statement keyword or a
  622. // brace, it's an ExpressionStatement or LabeledStatement. We
  623. // simply start parsing an expression, and afterwards, if the
  624. // next token is a colon and the expression was a simple
  625. // Identifier node, we switch to interpreting it as a label.
  626. default:
  627. var maybeName = this.value, expr = this.parseExpression();
  628. if (starttype === tt.name && expr.type === "Identifier" && this.eat(tt.colon))
  629. return this.parseLabeledStatement(node, maybeName, expr)
  630. else return this.parseExpressionStatement(node, expr)
  631. }
  632. };
  633. pp$1.parseBreakContinueStatement = function(node, keyword) {
  634. var this$1 = this;
  635. var isBreak = keyword == "break";
  636. this.next();
  637. if (this.eat(tt.semi) || this.insertSemicolon()) node.label = null;
  638. else if (this.type !== tt.name) this.unexpected();
  639. else {
  640. node.label = this.parseIdent();
  641. this.semicolon();
  642. }
  643. // Verify that there is an actual destination to break or
  644. // continue to.
  645. for (var i = 0; i < this.labels.length; ++i) {
  646. var lab = this$1.labels[i];
  647. if (node.label == null || lab.name === node.label.name) {
  648. if (lab.kind != null && (isBreak || lab.kind === "loop")) break
  649. if (node.label && isBreak) break
  650. }
  651. }
  652. if (i === this.labels.length) this.raise(node.start, "Unsyntactic " + keyword);
  653. return this.finishNode(node, isBreak ? "BreakStatement" : "ContinueStatement")
  654. };
  655. pp$1.parseDebuggerStatement = function(node) {
  656. this.next();
  657. this.semicolon();
  658. return this.finishNode(node, "DebuggerStatement")
  659. };
  660. pp$1.parseDoStatement = function(node) {
  661. this.next();
  662. this.labels.push(loopLabel);
  663. node.body = this.parseStatement(false);
  664. this.labels.pop();
  665. this.expect(tt._while);
  666. node.test = this.parseParenExpression();
  667. if (this.options.ecmaVersion >= 6)
  668. this.eat(tt.semi);
  669. else
  670. this.semicolon();
  671. return this.finishNode(node, "DoWhileStatement")
  672. };
  673. // Disambiguating between a `for` and a `for`/`in` or `for`/`of`
  674. // loop is non-trivial. Basically, we have to parse the init `var`
  675. // statement or expression, disallowing the `in` operator (see
  676. // the second parameter to `parseExpression`), and then check
  677. // whether the next token is `in` or `of`. When there is no init
  678. // part (semicolon immediately after the opening parenthesis), it
  679. // is a regular `for` loop.
  680. pp$1.parseForStatement = function(node) {
  681. this.next();
  682. this.labels.push(loopLabel);
  683. this.expect(tt.parenL);
  684. if (this.type === tt.semi) return this.parseFor(node, null)
  685. var isLet = this.isLet();
  686. if (this.type === tt._var || this.type === tt._const || isLet) {
  687. var init$1 = this.startNode(), kind = isLet ? "let" : this.value;
  688. this.next();
  689. this.parseVar(init$1, true, kind);
  690. this.finishNode(init$1, "VariableDeclaration");
  691. if ((this.type === tt._in || (this.options.ecmaVersion >= 6 && this.isContextual("of"))) && init$1.declarations.length === 1 &&
  692. !(kind !== "var" && init$1.declarations[0].init))
  693. return this.parseForIn(node, init$1)
  694. return this.parseFor(node, init$1)
  695. }
  696. var refDestructuringErrors = new DestructuringErrors;
  697. var init = this.parseExpression(true, refDestructuringErrors);
  698. if (this.type === tt._in || (this.options.ecmaVersion >= 6 && this.isContextual("of"))) {
  699. this.checkPatternErrors(refDestructuringErrors, true);
  700. this.toAssignable(init);
  701. this.checkLVal(init);
  702. return this.parseForIn(node, init)
  703. } else {
  704. this.checkExpressionErrors(refDestructuringErrors, true);
  705. }
  706. return this.parseFor(node, init)
  707. };
  708. pp$1.parseFunctionStatement = function(node) {
  709. this.next();
  710. return this.parseFunction(node, true)
  711. };
  712. pp$1.parseIfStatement = function(node) {
  713. this.next();
  714. node.test = this.parseParenExpression();
  715. node.consequent = this.parseStatement(false);
  716. node.alternate = this.eat(tt._else) ? this.parseStatement(false) : null;
  717. return this.finishNode(node, "IfStatement")
  718. };
  719. pp$1.parseReturnStatement = function(node) {
  720. if (!this.inFunction && !this.options.allowReturnOutsideFunction)
  721. this.raise(this.start, "'return' outside of function");
  722. this.next();
  723. // In `return` (and `break`/`continue`), the keywords with
  724. // optional arguments, we eagerly look for a semicolon or the
  725. // possibility to insert one.
  726. if (this.eat(tt.semi) || this.insertSemicolon()) node.argument = null;
  727. else { node.argument = this.parseExpression(); this.semicolon(); }
  728. return this.finishNode(node, "ReturnStatement")
  729. };
  730. pp$1.parseSwitchStatement = function(node) {
  731. var this$1 = this;
  732. this.next();
  733. node.discriminant = this.parseParenExpression();
  734. node.cases = [];
  735. this.expect(tt.braceL);
  736. this.labels.push(switchLabel);
  737. // Statements under must be grouped (by label) in SwitchCase
  738. // nodes. `cur` is used to keep the node that we are currently
  739. // adding statements to.
  740. for (var cur, sawDefault = false; this.type != tt.braceR;) {
  741. if (this$1.type === tt._case || this$1.type === tt._default) {
  742. var isCase = this$1.type === tt._case;
  743. if (cur) this$1.finishNode(cur, "SwitchCase");
  744. node.cases.push(cur = this$1.startNode());
  745. cur.consequent = [];
  746. this$1.next();
  747. if (isCase) {
  748. cur.test = this$1.parseExpression();
  749. } else {
  750. if (sawDefault) this$1.raiseRecoverable(this$1.lastTokStart, "Multiple default clauses");
  751. sawDefault = true;
  752. cur.test = null;
  753. }
  754. this$1.expect(tt.colon);
  755. } else {
  756. if (!cur) this$1.unexpected();
  757. cur.consequent.push(this$1.parseStatement(true));
  758. }
  759. }
  760. if (cur) this.finishNode(cur, "SwitchCase");
  761. this.next(); // Closing brace
  762. this.labels.pop();
  763. return this.finishNode(node, "SwitchStatement")
  764. };
  765. pp$1.parseThrowStatement = function(node) {
  766. this.next();
  767. if (lineBreak.test(this.input.slice(this.lastTokEnd, this.start)))
  768. this.raise(this.lastTokEnd, "Illegal newline after throw");
  769. node.argument = this.parseExpression();
  770. this.semicolon();
  771. return this.finishNode(node, "ThrowStatement")
  772. };
  773. // Reused empty array added for node fields that are always empty.
  774. var empty = [];
  775. pp$1.parseTryStatement = function(node) {
  776. this.next();
  777. node.block = this.parseBlock();
  778. node.handler = null;
  779. if (this.type === tt._catch) {
  780. var clause = this.startNode();
  781. this.next();
  782. this.expect(tt.parenL);
  783. clause.param = this.parseBindingAtom();
  784. this.checkLVal(clause.param, true);
  785. this.expect(tt.parenR);
  786. clause.body = this.parseBlock();
  787. node.handler = this.finishNode(clause, "CatchClause");
  788. }
  789. node.finalizer = this.eat(tt._finally) ? this.parseBlock() : null;
  790. if (!node.handler && !node.finalizer)
  791. this.raise(node.start, "Missing catch or finally clause");
  792. return this.finishNode(node, "TryStatement")
  793. };
  794. pp$1.parseVarStatement = function(node, kind) {
  795. this.next();
  796. this.parseVar(node, false, kind);
  797. this.semicolon();
  798. return this.finishNode(node, "VariableDeclaration")
  799. };
  800. pp$1.parseWhileStatement = function(node) {
  801. this.next();
  802. node.test = this.parseParenExpression();
  803. this.labels.push(loopLabel);
  804. node.body = this.parseStatement(false);
  805. this.labels.pop();
  806. return this.finishNode(node, "WhileStatement")
  807. };
  808. pp$1.parseWithStatement = function(node) {
  809. if (this.strict) this.raise(this.start, "'with' in strict mode");
  810. this.next();
  811. node.object = this.parseParenExpression();
  812. node.body = this.parseStatement(false);
  813. return this.finishNode(node, "WithStatement")
  814. };
  815. pp$1.parseEmptyStatement = function(node) {
  816. this.next();
  817. return this.finishNode(node, "EmptyStatement")
  818. };
  819. pp$1.parseLabeledStatement = function(node, maybeName, expr) {
  820. var this$1 = this;
  821. for (var i = 0; i < this.labels.length; ++i)
  822. if (this$1.labels[i].name === maybeName) this$1.raise(expr.start, "Label '" + maybeName + "' is already declared");
  823. var kind = this.type.isLoop ? "loop" : this.type === tt._switch ? "switch" : null;
  824. for (var i$1 = this.labels.length - 1; i$1 >= 0; i$1--) {
  825. var label = this$1.labels[i$1];
  826. if (label.statementStart == node.start) {
  827. label.statementStart = this$1.start;
  828. label.kind = kind;
  829. } else break
  830. }
  831. this.labels.push({name: maybeName, kind: kind, statementStart: this.start});
  832. node.body = this.parseStatement(true);
  833. this.labels.pop();
  834. node.label = expr;
  835. return this.finishNode(node, "LabeledStatement")
  836. };
  837. pp$1.parseExpressionStatement = function(node, expr) {
  838. node.expression = expr;
  839. this.semicolon();
  840. return this.finishNode(node, "ExpressionStatement")
  841. };
  842. // Parse a semicolon-enclosed block of statements, handling `"use
  843. // strict"` declarations when `allowStrict` is true (used for
  844. // function bodies).
  845. pp$1.parseBlock = function(allowStrict) {
  846. var this$1 = this;
  847. var node = this.startNode(), first = true, oldStrict;
  848. node.body = [];
  849. this.expect(tt.braceL);
  850. while (!this.eat(tt.braceR)) {
  851. var stmt = this$1.parseStatement(true);
  852. node.body.push(stmt);
  853. if (first && allowStrict && this$1.isUseStrict(stmt)) {
  854. oldStrict = this$1.strict;
  855. this$1.setStrict(this$1.strict = true);
  856. }
  857. first = false;
  858. }
  859. if (oldStrict === false) this.setStrict(false);
  860. return this.finishNode(node, "BlockStatement")
  861. };
  862. // Parse a regular `for` loop. The disambiguation code in
  863. // `parseStatement` will already have parsed the init statement or
  864. // expression.
  865. pp$1.parseFor = function(node, init) {
  866. node.init = init;
  867. this.expect(tt.semi);
  868. node.test = this.type === tt.semi ? null : this.parseExpression();
  869. this.expect(tt.semi);
  870. node.update = this.type === tt.parenR ? null : this.parseExpression();
  871. this.expect(tt.parenR);
  872. node.body = this.parseStatement(false);
  873. this.labels.pop();
  874. return this.finishNode(node, "ForStatement")
  875. };
  876. // Parse a `for`/`in` and `for`/`of` loop, which are almost
  877. // same from parser's perspective.
  878. pp$1.parseForIn = function(node, init) {
  879. var type = this.type === tt._in ? "ForInStatement" : "ForOfStatement";
  880. this.next();
  881. node.left = init;
  882. node.right = this.parseExpression();
  883. this.expect(tt.parenR);
  884. node.body = this.parseStatement(false);
  885. this.labels.pop();
  886. return this.finishNode(node, type)
  887. };
  888. // Parse a list of variable declarations.
  889. pp$1.parseVar = function(node, isFor, kind) {
  890. var this$1 = this;
  891. node.declarations = [];
  892. node.kind = kind;
  893. for (;;) {
  894. var decl = this$1.startNode();
  895. this$1.parseVarId(decl);
  896. if (this$1.eat(tt.eq)) {
  897. decl.init = this$1.parseMaybeAssign(isFor);
  898. } else if (kind === "const" && !(this$1.type === tt._in || (this$1.options.ecmaVersion >= 6 && this$1.isContextual("of")))) {
  899. this$1.unexpected();
  900. } else if (decl.id.type != "Identifier" && !(isFor && (this$1.type === tt._in || this$1.isContextual("of")))) {
  901. this$1.raise(this$1.lastTokEnd, "Complex binding patterns require an initialization value");
  902. } else {
  903. decl.init = null;
  904. }
  905. node.declarations.push(this$1.finishNode(decl, "VariableDeclarator"));
  906. if (!this$1.eat(tt.comma)) break
  907. }
  908. return node
  909. };
  910. pp$1.parseVarId = function(decl) {
  911. decl.id = this.parseBindingAtom();
  912. this.checkLVal(decl.id, true);
  913. };
  914. // Parse a function declaration or literal (depending on the
  915. // `isStatement` parameter).
  916. pp$1.parseFunction = function(node, isStatement, allowExpressionBody) {
  917. this.initFunction(node);
  918. if (this.options.ecmaVersion >= 6)
  919. node.generator = this.eat(tt.star);
  920. var oldInGen = this.inGenerator;
  921. this.inGenerator = node.generator;
  922. if (isStatement || this.type === tt.name)
  923. node.id = this.parseIdent();
  924. this.parseFunctionParams(node);
  925. this.parseFunctionBody(node, allowExpressionBody);
  926. this.inGenerator = oldInGen;
  927. return this.finishNode(node, isStatement ? "FunctionDeclaration" : "FunctionExpression")
  928. };
  929. pp$1.parseFunctionParams = function(node) {
  930. this.expect(tt.parenL);
  931. node.params = this.parseBindingList(tt.parenR, false, false, true);
  932. };
  933. // Parse a class declaration or literal (depending on the
  934. // `isStatement` parameter).
  935. pp$1.parseClass = function(node, isStatement) {
  936. var this$1 = this;
  937. this.next();
  938. this.parseClassId(node, isStatement);
  939. this.parseClassSuper(node);
  940. var classBody = this.startNode();
  941. var hadConstructor = false;
  942. classBody.body = [];
  943. this.expect(tt.braceL);
  944. while (!this.eat(tt.braceR)) {
  945. if (this$1.eat(tt.semi)) continue
  946. var method = this$1.startNode();
  947. var isGenerator = this$1.eat(tt.star);
  948. var isMaybeStatic = this$1.type === tt.name && this$1.value === "static";
  949. this$1.parsePropertyName(method);
  950. method.static = isMaybeStatic && this$1.type !== tt.parenL;
  951. if (method.static) {
  952. if (isGenerator) this$1.unexpected();
  953. isGenerator = this$1.eat(tt.star);
  954. this$1.parsePropertyName(method);
  955. }
  956. method.kind = "method";
  957. var isGetSet = false;
  958. if (!method.computed) {
  959. var key = method.key;
  960. if (!isGenerator && key.type === "Identifier" && this$1.type !== tt.parenL && (key.name === "get" || key.name === "set")) {
  961. isGetSet = true;
  962. method.kind = key.name;
  963. key = this$1.parsePropertyName(method);
  964. }
  965. if (!method.static && (key.type === "Identifier" && key.name === "constructor" ||
  966. key.type === "Literal" && key.value === "constructor")) {
  967. if (hadConstructor) this$1.raise(key.start, "Duplicate constructor in the same class");
  968. if (isGetSet) this$1.raise(key.start, "Constructor can't have get/set modifier");
  969. if (isGenerator) this$1.raise(key.start, "Constructor can't be a generator");
  970. method.kind = "constructor";
  971. hadConstructor = true;
  972. }
  973. }
  974. this$1.parseClassMethod(classBody, method, isGenerator);
  975. if (isGetSet) {
  976. var paramCount = method.kind === "get" ? 0 : 1;
  977. if (method.value.params.length !== paramCount) {
  978. var start = method.value.start;
  979. if (method.kind === "get")
  980. this$1.raiseRecoverable(start, "getter should have no params");
  981. else
  982. this$1.raiseRecoverable(start, "setter should have exactly one param");
  983. }
  984. if (method.kind === "set" && method.value.params[0].type === "RestElement")
  985. this$1.raise(method.value.params[0].start, "Setter cannot use rest params");
  986. }
  987. }
  988. node.body = this.finishNode(classBody, "ClassBody");
  989. return this.finishNode(node, isStatement ? "ClassDeclaration" : "ClassExpression")
  990. };
  991. pp$1.parseClassMethod = function(classBody, method, isGenerator) {
  992. method.value = this.parseMethod(isGenerator);
  993. classBody.body.push(this.finishNode(method, "MethodDefinition"));
  994. };
  995. pp$1.parseClassId = function(node, isStatement) {
  996. node.id = this.type === tt.name ? this.parseIdent() : isStatement ? this.unexpected() : null;
  997. };
  998. pp$1.parseClassSuper = function(node) {
  999. node.superClass = this.eat(tt._extends) ? this.parseExprSubscripts() : null;
  1000. };
  1001. // Parses module export declaration.
  1002. pp$1.parseExport = function(node) {
  1003. var this$1 = this;
  1004. this.next();
  1005. // export * from '...'
  1006. if (this.eat(tt.star)) {
  1007. this.expectContextual("from");
  1008. node.source = this.type === tt.string ? this.parseExprAtom() : this.unexpected();
  1009. this.semicolon();
  1010. return this.finishNode(node, "ExportAllDeclaration")
  1011. }
  1012. if (this.eat(tt._default)) { // export default ...
  1013. var parens = this.type == tt.parenL;
  1014. var expr = this.parseMaybeAssign();
  1015. var needsSemi = true;
  1016. if (!parens && (expr.type == "FunctionExpression" ||
  1017. expr.type == "ClassExpression")) {
  1018. needsSemi = false;
  1019. if (expr.id) {
  1020. expr.type = expr.type == "FunctionExpression"
  1021. ? "FunctionDeclaration"
  1022. : "ClassDeclaration";
  1023. }
  1024. }
  1025. node.declaration = expr;
  1026. if (needsSemi) this.semicolon();
  1027. return this.finishNode(node, "ExportDefaultDeclaration")
  1028. }
  1029. // export var|const|let|function|class ...
  1030. if (this.shouldParseExportStatement()) {
  1031. node.declaration = this.parseStatement(true);
  1032. node.specifiers = [];
  1033. node.source = null;
  1034. } else { // export { x, y as z } [from '...']
  1035. node.declaration = null;
  1036. node.specifiers = this.parseExportSpecifiers();
  1037. if (this.eatContextual("from")) {
  1038. node.source = this.type === tt.string ? this.parseExprAtom() : this.unexpected();
  1039. } else {
  1040. // check for keywords used as local names
  1041. for (var i = 0; i < node.specifiers.length; i++) {
  1042. if (this$1.keywords.test(node.specifiers[i].local.name) || this$1.reservedWords.test(node.specifiers[i].local.name)) {
  1043. this$1.unexpected(node.specifiers[i].local.start);
  1044. }
  1045. }
  1046. node.source = null;
  1047. }
  1048. this.semicolon();
  1049. }
  1050. return this.finishNode(node, "ExportNamedDeclaration")
  1051. };
  1052. pp$1.shouldParseExportStatement = function() {
  1053. return this.type.keyword || this.isLet()
  1054. };
  1055. // Parses a comma-separated list of module exports.
  1056. pp$1.parseExportSpecifiers = function() {
  1057. var this$1 = this;
  1058. var nodes = [], first = true;
  1059. // export { x, y as z } [from '...']
  1060. this.expect(tt.braceL);
  1061. while (!this.eat(tt.braceR)) {
  1062. if (!first) {
  1063. this$1.expect(tt.comma);
  1064. if (this$1.afterTrailingComma(tt.braceR)) break
  1065. } else first = false;
  1066. var node = this$1.startNode();
  1067. node.local = this$1.parseIdent(this$1.type === tt._default);
  1068. node.exported = this$1.eatContextual("as") ? this$1.parseIdent(true) : node.local;
  1069. nodes.push(this$1.finishNode(node, "ExportSpecifier"));
  1070. }
  1071. return nodes
  1072. };
  1073. // Parses import declaration.
  1074. pp$1.parseImport = function(node) {
  1075. this.next();
  1076. // import '...'
  1077. if (this.type === tt.string) {
  1078. node.specifiers = empty;
  1079. node.source = this.parseExprAtom();
  1080. } else {
  1081. node.specifiers = this.parseImportSpecifiers();
  1082. this.expectContextual("from");
  1083. node.source = this.type === tt.string ? this.parseExprAtom() : this.unexpected();
  1084. }
  1085. this.semicolon();
  1086. return this.finishNode(node, "ImportDeclaration")
  1087. };
  1088. // Parses a comma-separated list of module imports.
  1089. pp$1.parseImportSpecifiers = function() {
  1090. var this$1 = this;
  1091. var nodes = [], first = true;
  1092. if (this.type === tt.name) {
  1093. // import defaultObj, { x, y as z } from '...'
  1094. var node = this.startNode();
  1095. node.local = this.parseIdent();
  1096. this.checkLVal(node.local, true);
  1097. nodes.push(this.finishNode(node, "ImportDefaultSpecifier"));
  1098. if (!this.eat(tt.comma)) return nodes
  1099. }
  1100. if (this.type === tt.star) {
  1101. var node$1 = this.startNode();
  1102. this.next();
  1103. this.expectContextual("as");
  1104. node$1.local = this.parseIdent();
  1105. this.checkLVal(node$1.local, true);
  1106. nodes.push(this.finishNode(node$1, "ImportNamespaceSpecifier"));
  1107. return nodes
  1108. }
  1109. this.expect(tt.braceL);
  1110. while (!this.eat(tt.braceR)) {
  1111. if (!first) {
  1112. this$1.expect(tt.comma);
  1113. if (this$1.afterTrailingComma(tt.braceR)) break
  1114. } else first = false;
  1115. var node$2 = this$1.startNode();
  1116. node$2.imported = this$1.parseIdent(true);
  1117. if (this$1.eatContextual("as")) {
  1118. node$2.local = this$1.parseIdent();
  1119. } else {
  1120. node$2.local = node$2.imported;
  1121. if (this$1.isKeyword(node$2.local.name)) this$1.unexpected(node$2.local.start);
  1122. if (this$1.reservedWordsStrict.test(node$2.local.name)) this$1.raise(node$2.local.start, "The keyword '" + node$2.local.name + "' is reserved");
  1123. }
  1124. this$1.checkLVal(node$2.local, true);
  1125. nodes.push(this$1.finishNode(node$2, "ImportSpecifier"));
  1126. }
  1127. return nodes
  1128. };
  1129. var pp$2 = Parser.prototype;
  1130. // Convert existing expression atom to assignable pattern
  1131. // if possible.
  1132. pp$2.toAssignable = function(node, isBinding) {
  1133. var this$1 = this;
  1134. if (this.options.ecmaVersion >= 6 && node) {
  1135. switch (node.type) {
  1136. case "Identifier":
  1137. case "ObjectPattern":
  1138. case "ArrayPattern":
  1139. break
  1140. case "ObjectExpression":
  1141. node.type = "ObjectPattern";
  1142. for (var i = 0; i < node.properties.length; i++) {
  1143. var prop = node.properties[i];
  1144. if (prop.kind !== "init") this$1.raise(prop.key.start, "Object pattern can't contain getter or setter");
  1145. this$1.toAssignable(prop.value, isBinding);
  1146. }
  1147. break
  1148. case "ArrayExpression":
  1149. node.type = "ArrayPattern";
  1150. this.toAssignableList(node.elements, isBinding);
  1151. break
  1152. case "AssignmentExpression":
  1153. if (node.operator === "=") {
  1154. node.type = "AssignmentPattern";
  1155. delete node.operator;
  1156. // falls through to AssignmentPattern
  1157. } else {
  1158. this.raise(node.left.end, "Only '=' operator can be used for specifying default value.");
  1159. break
  1160. }
  1161. case "AssignmentPattern":
  1162. if (node.right.type === "YieldExpression")
  1163. this.raise(node.right.start, "Yield expression cannot be a default value");
  1164. break
  1165. case "ParenthesizedExpression":
  1166. node.expression = this.toAssignable(node.expression, isBinding);
  1167. break
  1168. case "MemberExpression":
  1169. if (!isBinding) break
  1170. default:
  1171. this.raise(node.start, "Assigning to rvalue");
  1172. }
  1173. }
  1174. return node
  1175. };
  1176. // Convert list of expression atoms to binding list.
  1177. pp$2.toAssignableList = function(exprList, isBinding) {
  1178. var this$1 = this;
  1179. var end = exprList.length;
  1180. if (end) {
  1181. var last = exprList[end - 1];
  1182. if (last && last.type == "RestElement") {
  1183. --end;
  1184. } else if (last && last.type == "SpreadElement") {
  1185. last.type = "RestElement";
  1186. var arg = last.argument;
  1187. this.toAssignable(arg, isBinding);
  1188. if (arg.type !== "Identifier" && arg.type !== "MemberExpression" && arg.type !== "ArrayPattern")
  1189. this.unexpected(arg.start);
  1190. --end;
  1191. }
  1192. if (isBinding && last && last.type === "RestElement" && last.argument.type !== "Identifier")
  1193. this.unexpected(last.argument.start);
  1194. }
  1195. for (var i = 0; i < end; i++) {
  1196. var elt = exprList[i];
  1197. if (elt) this$1.toAssignable(elt, isBinding);
  1198. }
  1199. return exprList
  1200. };
  1201. // Parses spread element.
  1202. pp$2.parseSpread = function(refDestructuringErrors) {
  1203. var node = this.startNode();
  1204. this.next();
  1205. node.argument = this.parseMaybeAssign(false, refDestructuringErrors);
  1206. return this.finishNode(node, "SpreadElement")
  1207. };
  1208. pp$2.parseRest = function(allowNonIdent) {
  1209. var node = this.startNode();
  1210. this.next();
  1211. // RestElement inside of a function parameter must be an identifier
  1212. if (allowNonIdent) node.argument = this.type === tt.name ? this.parseIdent() : this.unexpected();
  1213. else node.argument = this.type === tt.name || this.type === tt.bracketL ? this.parseBindingAtom() : this.unexpected();
  1214. return this.finishNode(node, "RestElement")
  1215. };
  1216. // Parses lvalue (assignable) atom.
  1217. pp$2.parseBindingAtom = function() {
  1218. if (this.options.ecmaVersion < 6) return this.parseIdent()
  1219. switch (this.type) {
  1220. case tt.name:
  1221. return this.parseIdent()
  1222. case tt.bracketL:
  1223. var node = this.startNode();
  1224. this.next();
  1225. node.elements = this.parseBindingList(tt.bracketR, true, true);
  1226. return this.finishNode(node, "ArrayPattern")
  1227. case tt.braceL:
  1228. return this.parseObj(true)
  1229. default:
  1230. this.unexpected();
  1231. }
  1232. };
  1233. pp$2.parseBindingList = function(close, allowEmpty, allowTrailingComma, allowNonIdent) {
  1234. var this$1 = this;
  1235. var elts = [], first = true;
  1236. while (!this.eat(close)) {
  1237. if (first) first = false;
  1238. else this$1.expect(tt.comma);
  1239. if (allowEmpty && this$1.type === tt.comma) {
  1240. elts.push(null);
  1241. } else if (allowTrailingComma && this$1.afterTrailingComma(close)) {
  1242. break
  1243. } else if (this$1.type === tt.ellipsis) {
  1244. var rest = this$1.parseRest(allowNonIdent);
  1245. this$1.parseBindingListItem(rest);
  1246. elts.push(rest);
  1247. if (this$1.type === tt.comma) this$1.raise(this$1.start, "Comma is not permitted after the rest element");
  1248. this$1.expect(close);
  1249. break
  1250. } else {
  1251. var elem = this$1.parseMaybeDefault(this$1.start, this$1.startLoc);
  1252. this$1.parseBindingListItem(elem);
  1253. elts.push(elem);
  1254. }
  1255. }
  1256. return elts
  1257. };
  1258. pp$2.parseBindingListItem = function(param) {
  1259. return param
  1260. };
  1261. // Parses assignment pattern around given atom if possible.
  1262. pp$2.parseMaybeDefault = function(startPos, startLoc, left) {
  1263. left = left || this.parseBindingAtom();
  1264. if (this.options.ecmaVersion < 6 || !this.eat(tt.eq)) return left
  1265. var node = this.startNodeAt(startPos, startLoc);
  1266. node.left = left;
  1267. node.right = this.parseMaybeAssign();
  1268. return this.finishNode(node, "AssignmentPattern")
  1269. };
  1270. // Verify that a node is an lval — something that can be assigned
  1271. // to.
  1272. pp$2.checkLVal = function(expr, isBinding, checkClashes) {
  1273. var this$1 = this;
  1274. switch (expr.type) {
  1275. case "Identifier":
  1276. if (this.strict && this.reservedWordsStrictBind.test(expr.name))
  1277. this.raiseRecoverable(expr.start, (isBinding ? "Binding " : "Assigning to ") + expr.name + " in strict mode");
  1278. if (checkClashes) {
  1279. if (has(checkClashes, expr.name))
  1280. this.raiseRecoverable(expr.start, "Argument name clash");
  1281. checkClashes[expr.name] = true;
  1282. }
  1283. break
  1284. case "MemberExpression":
  1285. if (isBinding) this.raiseRecoverable(expr.start, (isBinding ? "Binding" : "Assigning to") + " member expression");
  1286. break
  1287. case "ObjectPattern":
  1288. for (var i = 0; i < expr.properties.length; i++)
  1289. this$1.checkLVal(expr.properties[i].value, isBinding, checkClashes);
  1290. break
  1291. case "ArrayPattern":
  1292. for (var i$1 = 0; i$1 < expr.elements.length; i$1++) {
  1293. var elem = expr.elements[i$1];
  1294. if (elem) this$1.checkLVal(elem, isBinding, checkClashes);
  1295. }
  1296. break
  1297. case "AssignmentPattern":
  1298. this.checkLVal(expr.left, isBinding, checkClashes);
  1299. break
  1300. case "RestElement":
  1301. this.checkLVal(expr.argument, isBinding, checkClashes);
  1302. break
  1303. case "ParenthesizedExpression":
  1304. this.checkLVal(expr.expression, isBinding, checkClashes);
  1305. break
  1306. default:
  1307. this.raise(expr.start, (isBinding ? "Binding" : "Assigning to") + " rvalue");
  1308. }
  1309. };
  1310. var pp$3 = Parser.prototype;
  1311. // Check if property name clashes with already added.
  1312. // Object/class getters and setters are not allowed to clash —
  1313. // either with each other or with an init property — and in
  1314. // strict mode, init properties are also not allowed to be repeated.
  1315. pp$3.checkPropClash = function(prop, propHash) {
  1316. if (this.options.ecmaVersion >= 6 && (prop.computed || prop.method || prop.shorthand))
  1317. return
  1318. var key = prop.key;
  1319. var name;
  1320. switch (key.type) {
  1321. case "Identifier": name = key.name; break
  1322. case "Literal": name = String(key.value); break
  1323. default: return
  1324. }
  1325. var kind = prop.kind;
  1326. if (this.options.ecmaVersion >= 6) {
  1327. if (name === "__proto__" && kind === "init") {
  1328. if (propHash.proto) this.raiseRecoverable(key.start, "Redefinition of __proto__ property");
  1329. propHash.proto = true;
  1330. }
  1331. return
  1332. }
  1333. name = "$" + name;
  1334. var other = propHash[name];
  1335. if (other) {
  1336. var isGetSet = kind !== "init";
  1337. if ((this.strict || isGetSet) && other[kind] || !(isGetSet ^ other.init))
  1338. this.raiseRecoverable(key.start, "Redefinition of property");
  1339. } else {
  1340. other = propHash[name] = {
  1341. init: false,
  1342. get: false,
  1343. set: false
  1344. };
  1345. }
  1346. other[kind] = true;
  1347. };
  1348. // ### Expression parsing
  1349. // These nest, from the most general expression type at the top to
  1350. // 'atomic', nondivisible expression types at the bottom. Most of
  1351. // the functions will simply let the function(s) below them parse,
  1352. // and, *if* the syntactic construct they handle is present, wrap
  1353. // the AST node that the inner parser gave them in another node.
  1354. // Parse a full expression. The optional arguments are used to
  1355. // forbid the `in` operator (in for loops initalization expressions)
  1356. // and provide reference for storing '=' operator inside shorthand
  1357. // property assignment in contexts where both object expression
  1358. // and object pattern might appear (so it's possible to raise
  1359. // delayed syntax error at correct position).
  1360. pp$3.parseExpression = function(noIn, refDestructuringErrors) {
  1361. var this$1 = this;
  1362. var startPos = this.start, startLoc = this.startLoc;
  1363. var expr = this.parseMaybeAssign(noIn, refDestructuringErrors);
  1364. if (this.type === tt.comma) {
  1365. var node = this.startNodeAt(startPos, startLoc);
  1366. node.expressions = [expr];
  1367. while (this.eat(tt.comma)) node.expressions.push(this$1.parseMaybeAssign(noIn, refDestructuringErrors));
  1368. return this.finishNode(node, "SequenceExpression")
  1369. }
  1370. return expr
  1371. };
  1372. // Parse an assignment expression. This includes applications of
  1373. // operators like `+=`.
  1374. pp$3.parseMaybeAssign = function(noIn, refDestructuringErrors, afterLeftParse) {
  1375. if (this.inGenerator && this.isContextual("yield")) return this.parseYield()
  1376. var ownDestructuringErrors = false;
  1377. if (!refDestructuringErrors) {
  1378. refDestructuringErrors = new DestructuringErrors;
  1379. ownDestructuringErrors = true;
  1380. }
  1381. var startPos = this.start, startLoc = this.startLoc;
  1382. if (this.type == tt.parenL || this.type == tt.name)
  1383. this.potentialArrowAt = this.start;
  1384. var left = this.parseMaybeConditional(noIn, refDestructuringErrors);
  1385. if (afterLeftParse) left = afterLeftParse.call(this, left, startPos, startLoc);
  1386. if (this.type.isAssign) {
  1387. this.checkPatternErrors(refDestructuringErrors, true);
  1388. if (!ownDestructuringErrors) DestructuringErrors.call(refDestructuringErrors);
  1389. var node = this.startNodeAt(startPos, startLoc);
  1390. node.operator = this.value;
  1391. node.left = this.type === tt.eq ? this.toAssignable(left) : left;
  1392. refDestructuringErrors.shorthandAssign = 0; // reset because shorthand default was used correctly
  1393. this.checkLVal(left);
  1394. this.next();
  1395. node.right = this.parseMaybeAssign(noIn);
  1396. return this.finishNode(node, "AssignmentExpression")
  1397. } else {
  1398. if (ownDestructuringErrors) this.checkExpressionErrors(refDestructuringErrors, true);
  1399. }
  1400. return left
  1401. };
  1402. // Parse a ternary conditional (`?:`) operator.
  1403. pp$3.parseMaybeConditional = function(noIn, refDestructuringErrors) {
  1404. var startPos = this.start, startLoc = this.startLoc;
  1405. var expr = this.parseExprOps(noIn, refDestructuringErrors);
  1406. if (this.checkExpressionErrors(refDestructuringErrors)) return expr
  1407. if (this.eat(tt.question)) {
  1408. var node = this.startNodeAt(startPos, startLoc);
  1409. node.test = expr;
  1410. node.consequent = this.parseMaybeAssign();
  1411. this.expect(tt.colon);
  1412. node.alternate = this.parseMaybeAssign(noIn);
  1413. return this.finishNode(node, "ConditionalExpression")
  1414. }
  1415. return expr
  1416. };
  1417. // Start the precedence parser.
  1418. pp$3.parseExprOps = function(noIn, refDestructuringErrors) {
  1419. var startPos = this.start, startLoc = this.startLoc;
  1420. var expr = this.parseMaybeUnary(refDestructuringErrors, false);
  1421. if (this.checkExpressionErrors(refDestructuringErrors)) return expr
  1422. return this.parseExprOp(expr, startPos, startLoc, -1, noIn)
  1423. };
  1424. // Parse binary operators with the operator precedence parsing
  1425. // algorithm. `left` is the left-hand side of the operator.
  1426. // `minPrec` provides context that allows the function to stop and
  1427. // defer further parser to one of its callers when it encounters an
  1428. // operator that has a lower precedence than the set it is parsing.
  1429. pp$3.parseExprOp = function(left, leftStartPos, leftStartLoc, minPrec, noIn) {
  1430. var prec = this.type.binop;
  1431. if (prec != null && (!noIn || this.type !== tt._in)) {
  1432. if (prec > minPrec) {
  1433. var logical = this.type === tt.logicalOR || this.type === tt.logicalAND;
  1434. var op = this.value;
  1435. this.next();
  1436. var startPos = this.start, startLoc = this.startLoc;
  1437. var right = this.parseExprOp(this.parseMaybeUnary(null, false), startPos, startLoc, prec, noIn);
  1438. var node = this.buildBinary(leftStartPos, leftStartLoc, left, right, op, logical);
  1439. return this.parseExprOp(node, leftStartPos, leftStartLoc, minPrec, noIn)
  1440. }
  1441. }
  1442. return left
  1443. };
  1444. pp$3.buildBinary = function(startPos, startLoc, left, right, op, logical) {
  1445. var node = this.startNodeAt(startPos, startLoc);
  1446. node.left = left;
  1447. node.operator = op;
  1448. node.right = right;
  1449. return this.finishNode(node, logical ? "LogicalExpression" : "BinaryExpression")
  1450. };
  1451. // Parse unary operators, both prefix and postfix.
  1452. pp$3.parseMaybeUnary = function(refDestructuringErrors, sawUnary) {
  1453. var this$1 = this;
  1454. var startPos = this.start, startLoc = this.startLoc, expr;
  1455. if (this.type.prefix) {
  1456. var node = this.startNode(), update = this.type === tt.incDec;
  1457. node.operator = this.value;
  1458. node.prefix = true;
  1459. this.next();
  1460. node.argument = this.parseMaybeUnary(null, true);
  1461. this.checkExpressionErrors(refDestructuringErrors, true);
  1462. if (update) this.checkLVal(node.argument);
  1463. else if (this.strict && node.operator === "delete" &&
  1464. node.argument.type === "Identifier")
  1465. this.raiseRecoverable(node.start, "Deleting local variable in strict mode");
  1466. else sawUnary = true;
  1467. expr = this.finishNode(node, update ? "UpdateExpression" : "UnaryExpression");
  1468. } else {
  1469. expr = this.parseExprSubscripts(refDestructuringErrors);
  1470. if (this.checkExpressionErrors(refDestructuringErrors)) return expr
  1471. while (this.type.postfix && !this.canInsertSemicolon()) {
  1472. var node$1 = this$1.startNodeAt(startPos, startLoc);
  1473. node$1.operator = this$1.value;
  1474. node$1.prefix = false;
  1475. node$1.argument = expr;
  1476. this$1.checkLVal(expr);
  1477. this$1.next();
  1478. expr = this$1.finishNode(node$1, "UpdateExpression");
  1479. }
  1480. }
  1481. if (!sawUnary && this.eat(tt.starstar))
  1482. return this.buildBinary(startPos, startLoc, expr, this.parseMaybeUnary(null, false), "**", false)
  1483. else
  1484. return expr
  1485. };
  1486. // Parse call, dot, and `[]`-subscript expressions.
  1487. pp$3.parseExprSubscripts = function(refDestructuringErrors) {
  1488. var startPos = this.start, startLoc = this.startLoc;
  1489. var expr = this.parseExprAtom(refDestructuringErrors);
  1490. var skipArrowSubscripts = expr.type === "ArrowFunctionExpression" && this.input.slice(this.lastTokStart, this.lastTokEnd) !== ")";
  1491. if (this.checkExpressionErrors(refDestructuringErrors) || skipArrowSubscripts) return expr
  1492. return this.parseSubscripts(expr, startPos, startLoc)
  1493. };
  1494. pp$3.parseSubscripts = function(base, startPos, startLoc, noCalls) {
  1495. var this$1 = this;
  1496. for (;;) {
  1497. if (this$1.eat(tt.dot)) {
  1498. var node = this$1.startNodeAt(startPos, startLoc);
  1499. node.object = base;
  1500. node.property = this$1.parseIdent(true);
  1501. node.computed = false;
  1502. base = this$1.finishNode(node, "MemberExpression");
  1503. } else if (this$1.eat(tt.bracketL)) {
  1504. var node$1 = this$1.startNodeAt(startPos, startLoc);
  1505. node$1.object = base;
  1506. node$1.property = this$1.parseExpression();
  1507. node$1.computed = true;
  1508. this$1.expect(tt.bracketR);
  1509. base = this$1.finishNode(node$1, "MemberExpression");
  1510. } else if (!noCalls && this$1.eat(tt.parenL)) {
  1511. var node$2 = this$1.startNodeAt(startPos, startLoc);
  1512. node$2.callee = base;
  1513. node$2.arguments = this$1.parseExprList(tt.parenR, false);
  1514. base = this$1.finishNode(node$2, "CallExpression");
  1515. } else if (this$1.type === tt.backQuote) {
  1516. var node$3 = this$1.startNodeAt(startPos, startLoc);
  1517. node$3.tag = base;
  1518. node$3.quasi = this$1.parseTemplate();
  1519. base = this$1.finishNode(node$3, "TaggedTemplateExpression");
  1520. } else {
  1521. return base
  1522. }
  1523. }
  1524. };
  1525. // Parse an atomic expression — either a single token that is an
  1526. // expression, an expression started by a keyword like `function` or
  1527. // `new`, or an expression wrapped in punctuation like `()`, `[]`,
  1528. // or `{}`.
  1529. pp$3.parseExprAtom = function(refDestructuringErrors) {
  1530. var node, canBeArrow = this.potentialArrowAt == this.start;
  1531. switch (this.type) {
  1532. case tt._super:
  1533. if (!this.inFunction)
  1534. this.raise(this.start, "'super' outside of function or class");
  1535. case tt._this:
  1536. var type = this.type === tt._this ? "ThisExpression" : "Super";
  1537. node = this.startNode();
  1538. this.next();
  1539. return this.finishNode(node, type)
  1540. case tt.name:
  1541. var startPos = this.start, startLoc = this.startLoc;
  1542. var id = this.parseIdent(this.type !== tt.name);
  1543. if (canBeArrow && !this.canInsertSemicolon() && this.eat(tt.arrow))
  1544. return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), [id])
  1545. return id
  1546. case tt.regexp:
  1547. var value = this.value;
  1548. node = this.parseLiteral(value.value);
  1549. node.regex = {pattern: value.pattern, flags: value.flags};
  1550. return node
  1551. case tt.num: case tt.string:
  1552. return this.parseLiteral(this.value)
  1553. case tt._null: case tt._true: case tt._false:
  1554. node = this.startNode();
  1555. node.value = this.type === tt._null ? null : this.type === tt._true;
  1556. node.raw = this.type.keyword;
  1557. this.next();
  1558. return this.finishNode(node, "Literal")
  1559. case tt.parenL:
  1560. return this.parseParenAndDistinguishExpression(canBeArrow)
  1561. case tt.bracketL:
  1562. node = this.startNode();
  1563. this.next();
  1564. node.elements = this.parseExprList(tt.bracketR, true, true, refDestructuringErrors);
  1565. return this.finishNode(node, "ArrayExpression")
  1566. case tt.braceL:
  1567. return this.parseObj(false, refDestructuringErrors)
  1568. case tt._function:
  1569. node = this.startNode();
  1570. this.next();
  1571. return this.parseFunction(node, false)
  1572. case tt._class:
  1573. return this.parseClass(this.startNode(), false)
  1574. case tt._new:
  1575. return this.parseNew()
  1576. case tt.backQuote:
  1577. return this.parseTemplate()
  1578. default:
  1579. this.unexpected();
  1580. }
  1581. };
  1582. pp$3.parseLiteral = function(value) {
  1583. var node = this.startNode();
  1584. node.value = value;
  1585. node.raw = this.input.slice(this.start, this.end);
  1586. this.next();
  1587. return this.finishNode(node, "Literal")
  1588. };
  1589. pp$3.parseParenExpression = function() {
  1590. this.expect(tt.parenL);
  1591. var val = this.parseExpression();
  1592. this.expect(tt.parenR);
  1593. return val
  1594. };
  1595. pp$3.parseParenAndDistinguishExpression = function(canBeArrow) {
  1596. var this$1 = this;
  1597. var startPos = this.start, startLoc = this.startLoc, val;
  1598. if (this.options.ecmaVersion >= 6) {
  1599. this.next();
  1600. var innerStartPos = this.start, innerStartLoc = this.startLoc;
  1601. var exprList = [], first = true;
  1602. var refDestructuringErrors = new DestructuringErrors, spreadStart, innerParenStart;
  1603. while (this.type !== tt.parenR) {
  1604. first ? first = false : this$1.expect(tt.comma);
  1605. if (this$1.type === tt.ellipsis) {
  1606. spreadStart = this$1.start;
  1607. exprList.push(this$1.parseParenItem(this$1.parseRest()));
  1608. break
  1609. } else {
  1610. if (this$1.type === tt.parenL && !innerParenStart) {
  1611. innerParenStart = this$1.start;
  1612. }
  1613. exprList.push(this$1.parseMaybeAssign(false, refDestructuringErrors, this$1.parseParenItem));
  1614. }
  1615. }
  1616. var innerEndPos = this.start, innerEndLoc = this.startLoc;
  1617. this.expect(tt.parenR);
  1618. if (canBeArrow && !this.canInsertSemicolon() && this.eat(tt.arrow)) {
  1619. this.checkPatternErrors(refDestructuringErrors, true);
  1620. if (innerParenStart) this.unexpected(innerParenStart);
  1621. return this.parseParenArrowList(startPos, startLoc, exprList)
  1622. }
  1623. if (!exprList.length) this.unexpected(this.lastTokStart);
  1624. if (spreadStart) this.unexpected(spreadStart);
  1625. this.checkExpressionErrors(refDestructuringErrors, true);
  1626. if (exprList.length > 1) {
  1627. val = this.startNodeAt(innerStartPos, innerStartLoc);
  1628. val.expressions = exprList;
  1629. this.finishNodeAt(val, "SequenceExpression", innerEndPos, innerEndLoc);
  1630. } else {
  1631. val = exprList[0];
  1632. }
  1633. } else {
  1634. val = this.parseParenExpression();
  1635. }
  1636. if (this.options.preserveParens) {
  1637. var par = this.startNodeAt(startPos, startLoc);
  1638. par.expression = val;
  1639. return this.finishNode(par, "ParenthesizedExpression")
  1640. } else {
  1641. return val
  1642. }
  1643. };
  1644. pp$3.parseParenItem = function(item) {
  1645. return item
  1646. };
  1647. pp$3.parseParenArrowList = function(startPos, startLoc, exprList) {
  1648. return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), exprList)
  1649. };
  1650. // New's precedence is slightly tricky. It must allow its argument to
  1651. // be a `[]` or dot subscript expression, but not a call — at least,
  1652. // not without wrapping it in parentheses. Thus, it uses the noCalls
  1653. // argument to parseSubscripts to prevent it from consuming the
  1654. // argument list.
  1655. var empty$1 = [];
  1656. pp$3.parseNew = function() {
  1657. var node = this.startNode();
  1658. var meta = this.parseIdent(true);
  1659. if (this.options.ecmaVersion >= 6 && this.eat(tt.dot)) {
  1660. node.meta = meta;
  1661. node.property = this.parseIdent(true);
  1662. if (node.property.name !== "target")
  1663. this.raiseRecoverable(node.property.start, "The only valid meta property for new is new.target");
  1664. if (!this.inFunction)
  1665. this.raiseRecoverable(node.start, "new.target can only be used in functions");
  1666. return this.finishNode(node, "MetaProperty")
  1667. }
  1668. var startPos = this.start, startLoc = this.startLoc;
  1669. node.callee = this.parseSubscripts(this.parseExprAtom(), startPos, startLoc, true);
  1670. if (this.eat(tt.parenL)) node.arguments = this.parseExprList(tt.parenR, false);
  1671. else node.arguments = empty$1;
  1672. return this.finishNode(node, "NewExpression")
  1673. };
  1674. // Parse template expression.
  1675. pp$3.parseTemplateElement = function() {
  1676. var elem = this.startNode();
  1677. elem.value = {
  1678. raw: this.input.slice(this.start, this.end).replace(/\r\n?/g, '\n'),
  1679. cooked: this.value
  1680. };
  1681. this.next();
  1682. elem.tail = this.type === tt.backQuote;
  1683. return this.finishNode(elem, "TemplateElement")
  1684. };
  1685. pp$3.parseTemplate = function() {
  1686. var this$1 = this;
  1687. var node = this.startNode();
  1688. this.next();
  1689. node.expressions = [];
  1690. var curElt = this.parseTemplateElement();
  1691. node.quasis = [curElt];
  1692. while (!curElt.tail) {
  1693. this$1.expect(tt.dollarBraceL);
  1694. node.expressions.push(this$1.parseExpression());
  1695. this$1.expect(tt.braceR);
  1696. node.quasis.push(curElt = this$1.parseTemplateElement());
  1697. }
  1698. this.next();
  1699. return this.finishNode(node, "TemplateLiteral")
  1700. };
  1701. // Parse an object literal or binding pattern.
  1702. pp$3.parseObj = function(isPattern, refDestructuringErrors) {
  1703. var this$1 = this;
  1704. var node = this.startNode(), first = true, propHash = {};
  1705. node.properties = [];
  1706. this.next();
  1707. while (!this.eat(tt.braceR)) {
  1708. if (!first) {
  1709. this$1.expect(tt.comma);
  1710. if (this$1.afterTrailingComma(tt.braceR)) break
  1711. } else first = false;
  1712. var prop = this$1.startNode(), isGenerator, startPos, startLoc;
  1713. if (this$1.options.ecmaVersion >= 6) {
  1714. prop.method = false;
  1715. prop.shorthand = false;
  1716. if (isPattern || refDestructuringErrors) {
  1717. startPos = this$1.start;
  1718. startLoc = this$1.startLoc;
  1719. }
  1720. if (!isPattern)
  1721. isGenerator = this$1.eat(tt.star);
  1722. }
  1723. this$1.parsePropertyName(prop);
  1724. this$1.parsePropertyValue(prop, isPattern, isGenerator, startPos, startLoc, refDestructuringErrors);
  1725. this$1.checkPropClash(prop, propHash);
  1726. node.properties.push(this$1.finishNode(prop, "Property"));
  1727. }
  1728. return this.finishNode(node, isPattern ? "ObjectPattern" : "ObjectExpression")
  1729. };
  1730. pp$3.parsePropertyValue = function(prop, isPattern, isGenerator, startPos, startLoc, refDestructuringErrors) {
  1731. if (this.eat(tt.colon)) {
  1732. prop.value = isPattern ? this.parseMaybeDefault(this.start, this.startLoc) : this.parseMaybeAssign(false, refDestructuringErrors);
  1733. prop.kind = "init";
  1734. } else if (this.options.ecmaVersion >= 6 && this.type === tt.parenL) {
  1735. if (isPattern) this.unexpected();
  1736. prop.kind = "init";
  1737. prop.method = true;
  1738. prop.value = this.parseMethod(isGenerator);
  1739. } else if (this.options.ecmaVersion >= 5 && !prop.computed && prop.key.type === "Identifier" &&
  1740. (prop.key.name === "get" || prop.key.name === "set") &&
  1741. (this.type != tt.comma && this.type != tt.braceR)) {
  1742. if (isGenerator || isPattern) this.unexpected();
  1743. prop.kind = prop.key.name;
  1744. this.parsePropertyName(prop);
  1745. prop.value = this.parseMethod(false);
  1746. var paramCount = prop.kind === "get" ? 0 : 1;
  1747. if (prop.value.params.length !== paramCount) {
  1748. var start = prop.value.start;
  1749. if (prop.kind === "get")
  1750. this.raiseRecoverable(start, "getter should have no params");
  1751. else
  1752. this.raiseRecoverable(start, "setter should have exactly one param");
  1753. }
  1754. if (prop.kind === "set" && prop.value.params[0].type === "RestElement")
  1755. this.raiseRecoverable(prop.value.params[0].start, "Setter cannot use rest params");
  1756. } else if (this.options.ecmaVersion >= 6 && !prop.computed && prop.key.type === "Identifier") {
  1757. if (this.keywords.test(prop.key.name) ||
  1758. (this.strict ? this.reservedWordsStrictBind : this.reservedWords).test(prop.key.name) ||
  1759. (this.inGenerator && prop.key.name == "yield"))
  1760. this.raiseRecoverable(prop.key.start, "'" + prop.key.name + "' can not be used as shorthand property");
  1761. prop.kind = "init";
  1762. if (isPattern) {
  1763. prop.value = this.parseMaybeDefault(startPos, startLoc, prop.key);
  1764. } else if (this.type === tt.eq && refDestructuringErrors) {
  1765. if (!refDestructuringErrors.shorthandAssign)
  1766. refDestructuringErrors.shorthandAssign = this.start;
  1767. prop.value = this.parseMaybeDefault(startPos, startLoc, prop.key);
  1768. } else {
  1769. prop.value = prop.key;
  1770. }
  1771. prop.shorthand = true;
  1772. } else this.unexpected();
  1773. };
  1774. pp$3.parsePropertyName = function(prop) {
  1775. if (this.options.ecmaVersion >= 6) {
  1776. if (this.eat(tt.bracketL)) {
  1777. prop.computed = true;
  1778. prop.key = this.parseMaybeAssign();
  1779. this.expect(tt.bracketR);
  1780. return prop.key
  1781. } else {
  1782. prop.computed = false;
  1783. }
  1784. }
  1785. return prop.key = this.type === tt.num || this.type === tt.string ? this.parseExprAtom() : this.parseIdent(true)
  1786. };
  1787. // Initialize empty function node.
  1788. pp$3.initFunction = function(node) {
  1789. node.id = null;
  1790. if (this.options.ecmaVersion >= 6) {
  1791. node.generator = false;
  1792. node.expression = false;
  1793. }
  1794. };
  1795. // Parse object or class method.
  1796. pp$3.parseMethod = function(isGenerator) {
  1797. var node = this.startNode(), oldInGen = this.inGenerator;
  1798. this.inGenerator = isGenerator;
  1799. this.initFunction(node);
  1800. this.expect(tt.parenL);
  1801. node.params = this.parseBindingList(tt.parenR, false, false);
  1802. if (this.options.ecmaVersion >= 6)
  1803. node.generator = isGenerator;
  1804. this.parseFunctionBody(node, false);
  1805. this.inGenerator = oldInGen;
  1806. return this.finishNode(node, "FunctionExpression")
  1807. };
  1808. // Parse arrow function expression with given parameters.
  1809. pp$3.parseArrowExpression = function(node, params) {
  1810. var oldInGen = this.inGenerator;
  1811. this.inGenerator = false;
  1812. this.initFunction(node);
  1813. node.params = this.toAssignableList(params, true);
  1814. this.parseFunctionBody(node, true);
  1815. this.inGenerator = oldInGen;
  1816. return this.finishNode(node, "ArrowFunctionExpression")
  1817. };
  1818. // Parse function body and check parameters.
  1819. pp$3.parseFunctionBody = function(node, isArrowFunction) {
  1820. var isExpression = isArrowFunction && this.type !== tt.braceL;
  1821. if (isExpression) {
  1822. node.body = this.parseMaybeAssign();
  1823. node.expression = true;
  1824. } else {
  1825. // Start a new scope with regard to labels and the `inFunction`
  1826. // flag (restore them to their old value afterwards).
  1827. var oldInFunc = this.inFunction, oldLabels = this.labels;
  1828. this.inFunction = true; this.labels = [];
  1829. node.body = this.parseBlock(true);
  1830. node.expression = false;
  1831. this.inFunction = oldInFunc; this.labels = oldLabels;
  1832. }
  1833. // If this is a strict mode function, verify that argument names
  1834. // are not repeated, and it does not try to bind the words `eval`
  1835. // or `arguments`.
  1836. var useStrict = (!isExpression && node.body.body.length && this.isUseStrict(node.body.body[0])) ? node.body.body[0] : null;
  1837. if (this.strict || useStrict) {
  1838. var oldStrict = this.strict;
  1839. this.strict = true;
  1840. if (node.id)
  1841. this.checkLVal(node.id, true);
  1842. this.checkParams(node, useStrict);
  1843. this.strict = oldStrict;
  1844. } else if (isArrowFunction) {
  1845. this.checkParams(node, useStrict);
  1846. }
  1847. };
  1848. // Checks function params for various disallowed patterns such as using "eval"
  1849. // or "arguments" and duplicate parameters.
  1850. pp$3.checkParams = function(node, useStrict) {
  1851. var this$1 = this;
  1852. var nameHash = {};
  1853. for (var i = 0; i < node.params.length; i++) {
  1854. if (useStrict && this$1.options.ecmaVersion >= 7 && node.params[i].type !== "Identifier")
  1855. this$1.raiseRecoverable(useStrict.start, "Illegal 'use strict' directive in function with non-simple parameter list");
  1856. this$1.checkLVal(node.params[i], true, nameHash);
  1857. }
  1858. };
  1859. // Parses a comma-separated list of expressions, and returns them as
  1860. // an array. `close` is the token type that ends the list, and
  1861. // `allowEmpty` can be turned on to allow subsequent commas with
  1862. // nothing in between them to be parsed as `null` (which is needed
  1863. // for array literals).
  1864. pp$3.parseExprList = function(close, allowTrailingComma, allowEmpty, refDestructuringErrors) {
  1865. var this$1 = this;
  1866. var elts = [], first = true;
  1867. while (!this.eat(close)) {
  1868. if (!first) {
  1869. this$1.expect(tt.comma);
  1870. if (allowTrailingComma && this$1.afterTrailingComma(close)) break
  1871. } else first = false;
  1872. var elt;
  1873. if (allowEmpty && this$1.type === tt.comma)
  1874. elt = null;
  1875. else if (this$1.type === tt.ellipsis) {
  1876. elt = this$1.parseSpread(refDestructuringErrors);
  1877. if (this$1.type === tt.comma && refDestructuringErrors && !refDestructuringErrors.trailingComma) {
  1878. refDestructuringErrors.trailingComma = this$1.lastTokStart;
  1879. }
  1880. } else
  1881. elt = this$1.parseMaybeAssign(false, refDestructuringErrors);
  1882. elts.push(elt);
  1883. }
  1884. return elts
  1885. };
  1886. // Parse the next token as an identifier. If `liberal` is true (used
  1887. // when parsing properties), it will also convert keywords into
  1888. // identifiers.
  1889. pp$3.parseIdent = function(liberal) {
  1890. var node = this.startNode();
  1891. if (liberal && this.options.allowReserved == "never") liberal = false;
  1892. if (this.type === tt.name) {
  1893. if (!liberal && (this.strict ? this.reservedWordsStrict : this.reservedWords).test(this.value) &&
  1894. (this.options.ecmaVersion >= 6 ||
  1895. this.input.slice(this.start, this.end).indexOf("\\") == -1))
  1896. this.raiseRecoverable(this.start, "The keyword '" + this.value + "' is reserved");
  1897. if (!liberal && this.inGenerator && this.value === "yield")
  1898. this.raiseRecoverable(this.start, "Can not use 'yield' as identifier inside a generator");
  1899. node.name = this.value;
  1900. } else if (liberal && this.type.keyword) {
  1901. node.name = this.type.keyword;
  1902. } else {
  1903. this.unexpected();
  1904. }
  1905. this.next();
  1906. return this.finishNode(node, "Identifier")
  1907. };
  1908. // Parses yield expression inside generator.
  1909. pp$3.parseYield = function() {
  1910. var node = this.startNode();
  1911. this.next();
  1912. if (this.type == tt.semi || this.canInsertSemicolon() || (this.type != tt.star && !this.type.startsExpr)) {
  1913. node.delegate = false;
  1914. node.argument = null;
  1915. } else {
  1916. node.delegate = this.eat(tt.star);
  1917. node.argument = this.parseMaybeAssign();
  1918. }
  1919. return this.finishNode(node, "YieldExpression")
  1920. };
  1921. var pp$4 = Parser.prototype;
  1922. // This function is used to raise exceptions on parse errors. It
  1923. // takes an offset integer (into the current `input`) to indicate
  1924. // the location of the error, attaches the position to the end
  1925. // of the error message, and then raises a `SyntaxError` with that
  1926. // message.
  1927. pp$4.raise = function(pos, message) {
  1928. var loc = getLineInfo(this.input, pos);
  1929. message += " (" + loc.line + ":" + loc.column + ")";
  1930. var err = new SyntaxError(message);
  1931. err.pos = pos; err.loc = loc; err.raisedAt = this.pos;
  1932. throw err
  1933. };
  1934. pp$4.raiseRecoverable = pp$4.raise;
  1935. pp$4.curPosition = function() {
  1936. if (this.options.locations) {
  1937. return new Position(this.curLine, this.pos - this.lineStart)
  1938. }
  1939. };
  1940. var Node = function Node(parser, pos, loc) {
  1941. this.type = "";
  1942. this.start = pos;
  1943. this.end = 0;
  1944. if (parser.options.locations)
  1945. this.loc = new SourceLocation(parser, loc);
  1946. if (parser.options.directSourceFile)
  1947. this.sourceFile = parser.options.directSourceFile;
  1948. if (parser.options.ranges)
  1949. this.range = [pos, 0];
  1950. };
  1951. // Start an AST node, attaching a start offset.
  1952. var pp$5 = Parser.prototype;
  1953. pp$5.startNode = function() {
  1954. return new Node(this, this.start, this.startLoc)
  1955. };
  1956. pp$5.startNodeAt = function(pos, loc) {
  1957. return new Node(this, pos, loc)
  1958. };
  1959. // Finish an AST node, adding `type` and `end` properties.
  1960. function finishNodeAt(node, type, pos, loc) {
  1961. node.type = type;
  1962. node.end = pos;
  1963. if (this.options.locations)
  1964. node.loc.end = loc;
  1965. if (this.options.ranges)
  1966. node.range[1] = pos;
  1967. return node
  1968. }
  1969. pp$5.finishNode = function(node, type) {
  1970. return finishNodeAt.call(this, node, type, this.lastTokEnd, this.lastTokEndLoc)
  1971. };
  1972. // Finish node at given position
  1973. pp$5.finishNodeAt = function(node, type, pos, loc) {
  1974. return finishNodeAt.call(this, node, type, pos, loc)
  1975. };
  1976. var TokContext = function TokContext(token, isExpr, preserveSpace, override) {
  1977. this.token = token;
  1978. this.isExpr = !!isExpr;
  1979. this.preserveSpace = !!preserveSpace;
  1980. this.override = override;
  1981. };
  1982. var types = {
  1983. b_stat: new TokContext("{", false),
  1984. b_expr: new TokContext("{", true),
  1985. b_tmpl: new TokContext("${", true),
  1986. p_stat: new TokContext("(", false),
  1987. p_expr: new TokContext("(", true),
  1988. q_tmpl: new TokContext("`", true, true, function (p) { return p.readTmplToken(); }),
  1989. f_expr: new TokContext("function", true)
  1990. };
  1991. var pp$6 = Parser.prototype;
  1992. pp$6.initialContext = function() {
  1993. return [types.b_stat]
  1994. };
  1995. pp$6.braceIsBlock = function(prevType) {
  1996. if (prevType === tt.colon) {
  1997. var parent = this.curContext();
  1998. if (parent === types.b_stat || parent === types.b_expr)
  1999. return !parent.isExpr
  2000. }
  2001. if (prevType === tt._return)
  2002. return lineBreak.test(this.input.slice(this.lastTokEnd, this.start))
  2003. if (prevType === tt._else || prevType === tt.semi || prevType === tt.eof || prevType === tt.parenR)
  2004. return true
  2005. if (prevType == tt.braceL)
  2006. return this.curContext() === types.b_stat
  2007. return !this.exprAllowed
  2008. };
  2009. pp$6.updateContext = function(prevType) {
  2010. var update, type = this.type;
  2011. if (type.keyword && prevType == tt.dot)
  2012. this.exprAllowed = false;
  2013. else if (update = type.updateContext)
  2014. update.call(this, prevType);
  2015. else
  2016. this.exprAllowed = type.beforeExpr;
  2017. };
  2018. // Token-specific context update code
  2019. tt.parenR.updateContext = tt.braceR.updateContext = function() {
  2020. if (this.context.length == 1) {
  2021. this.exprAllowed = true;
  2022. return
  2023. }
  2024. var out = this.context.pop();
  2025. if (out === types.b_stat && this.curContext() === types.f_expr) {
  2026. this.context.pop();
  2027. this.exprAllowed = false;
  2028. } else if (out === types.b_tmpl) {
  2029. this.exprAllowed = true;
  2030. } else {
  2031. this.exprAllowed = !out.isExpr;
  2032. }
  2033. };
  2034. tt.braceL.updateContext = function(prevType) {
  2035. this.context.push(this.braceIsBlock(prevType) ? types.b_stat : types.b_expr);
  2036. this.exprAllowed = true;
  2037. };
  2038. tt.dollarBraceL.updateContext = function() {
  2039. this.context.push(types.b_tmpl);
  2040. this.exprAllowed = true;
  2041. };
  2042. tt.parenL.updateContext = function(prevType) {
  2043. var statementParens = prevType === tt._if || prevType === tt._for || prevType === tt._with || prevType === tt._while;
  2044. this.context.push(statementParens ? types.p_stat : types.p_expr);
  2045. this.exprAllowed = true;
  2046. };
  2047. tt.incDec.updateContext = function() {
  2048. // tokExprAllowed stays unchanged
  2049. };
  2050. tt._function.updateContext = function(prevType) {
  2051. if (prevType.beforeExpr && prevType !== tt.semi && prevType !== tt._else &&
  2052. !((prevType === tt.colon || prevType === tt.braceL) && this.curContext() === types.b_stat))
  2053. this.context.push(types.f_expr);
  2054. this.exprAllowed = false;
  2055. };
  2056. tt.backQuote.updateContext = function() {
  2057. if (this.curContext() === types.q_tmpl)
  2058. this.context.pop();
  2059. else
  2060. this.context.push(types.q_tmpl);
  2061. this.exprAllowed = false;
  2062. };
  2063. // Object type used to represent tokens. Note that normally, tokens
  2064. // simply exist as properties on the parser object. This is only
  2065. // used for the onToken callback and the external tokenizer.
  2066. var Token = function Token(p) {
  2067. this.type = p.type;
  2068. this.value = p.value;
  2069. this.start = p.start;
  2070. this.end = p.end;
  2071. if (p.options.locations)
  2072. this.loc = new SourceLocation(p, p.startLoc, p.endLoc);
  2073. if (p.options.ranges)
  2074. this.range = [p.start, p.end];
  2075. };
  2076. // ## Tokenizer
  2077. var pp$7 = Parser.prototype;
  2078. // Are we running under Rhino?
  2079. var isRhino = typeof Packages == "object" && Object.prototype.toString.call(Packages) == "[object JavaPackage]";
  2080. // Move to the next token
  2081. pp$7.next = function() {
  2082. if (this.options.onToken)
  2083. this.options.onToken(new Token(this));
  2084. this.lastTokEnd = this.end;
  2085. this.lastTokStart = this.start;
  2086. this.lastTokEndLoc = this.endLoc;
  2087. this.lastTokStartLoc = this.startLoc;
  2088. this.nextToken();
  2089. };
  2090. pp$7.getToken = function() {
  2091. this.next();
  2092. return new Token(this)
  2093. };
  2094. // If we're in an ES6 environment, make parsers iterable
  2095. if (typeof Symbol !== "undefined")
  2096. pp$7[Symbol.iterator] = function () {
  2097. var self = this;
  2098. return {next: function () {
  2099. var token = self.getToken();
  2100. return {
  2101. done: token.type === tt.eof,
  2102. value: token
  2103. }
  2104. }}
  2105. };
  2106. // Toggle strict mode. Re-reads the next number or string to please
  2107. // pedantic tests (`"use strict"; 010;` should fail).
  2108. pp$7.setStrict = function(strict) {
  2109. var this$1 = this;
  2110. this.strict = strict;
  2111. if (this.type !== tt.num && this.type !== tt.string) return
  2112. this.pos = this.start;
  2113. if (this.options.locations) {
  2114. while (this.pos < this.lineStart) {
  2115. this$1.lineStart = this$1.input.lastIndexOf("\n", this$1.lineStart - 2) + 1;
  2116. --this$1.curLine;
  2117. }
  2118. }
  2119. this.nextToken();
  2120. };
  2121. pp$7.curContext = function() {
  2122. return this.context[this.context.length - 1]
  2123. };
  2124. // Read a single token, updating the parser object's token-related
  2125. // properties.
  2126. pp$7.nextToken = function() {
  2127. var curContext = this.curContext();
  2128. if (!curContext || !curContext.preserveSpace) this.skipSpace();
  2129. this.start = this.pos;
  2130. if (this.options.locations) this.startLoc = this.curPosition();
  2131. if (this.pos >= this.input.length) return this.finishToken(tt.eof)
  2132. if (curContext.override) return curContext.override(this)
  2133. else this.readToken(this.fullCharCodeAtPos());
  2134. };
  2135. pp$7.readToken = function(code) {
  2136. // Identifier or keyword. '\uXXXX' sequences are allowed in
  2137. // identifiers, so '\' also dispatches to that.
  2138. if (isIdentifierStart(code, this.options.ecmaVersion >= 6) || code === 92 /* '\' */)
  2139. return this.readWord()
  2140. return this.getTokenFromCode(code)
  2141. };
  2142. pp$7.fullCharCodeAtPos = function() {
  2143. var code = this.input.charCodeAt(this.pos);
  2144. if (code <= 0xd7ff || code >= 0xe000) return code
  2145. var next = this.input.charCodeAt(this.pos + 1);
  2146. return (code << 10) + next - 0x35fdc00
  2147. };
  2148. pp$7.skipBlockComment = function() {
  2149. var this$1 = this;
  2150. var startLoc = this.options.onComment && this.curPosition();
  2151. var start = this.pos, end = this.input.indexOf("*/", this.pos += 2);
  2152. if (end === -1) this.raise(this.pos - 2, "Unterminated comment");
  2153. this.pos = end + 2;
  2154. if (this.options.locations) {
  2155. lineBreakG.lastIndex = start;
  2156. var match;
  2157. while ((match = lineBreakG.exec(this.input)) && match.index < this.pos) {
  2158. ++this$1.curLine;
  2159. this$1.lineStart = match.index + match[0].length;
  2160. }
  2161. }
  2162. if (this.options.onComment)
  2163. this.options.onComment(true, this.input.slice(start + 2, end), start, this.pos,
  2164. startLoc, this.curPosition());
  2165. };
  2166. pp$7.skipLineComment = function(startSkip) {
  2167. var this$1 = this;
  2168. var start = this.pos;
  2169. var startLoc = this.options.onComment && this.curPosition();
  2170. var ch = this.input.charCodeAt(this.pos+=startSkip);
  2171. while (this.pos < this.input.length && ch !== 10 && ch !== 13 && ch !== 8232 && ch !== 8233) {
  2172. ++this$1.pos;
  2173. ch = this$1.input.charCodeAt(this$1.pos);
  2174. }
  2175. if (this.options.onComment)
  2176. this.options.onComment(false, this.input.slice(start + startSkip, this.pos), start, this.pos,
  2177. startLoc, this.curPosition());
  2178. };
  2179. // Called at the start of the parse and after every token. Skips
  2180. // whitespace and comments, and.
  2181. pp$7.skipSpace = function() {
  2182. var this$1 = this;
  2183. loop: while (this.pos < this.input.length) {
  2184. var ch = this$1.input.charCodeAt(this$1.pos);
  2185. switch (ch) {
  2186. case 32: case 160: // ' '
  2187. ++this$1.pos;
  2188. break
  2189. case 13:
  2190. if (this$1.input.charCodeAt(this$1.pos + 1) === 10) {
  2191. ++this$1.pos;
  2192. }
  2193. case 10: case 8232: case 8233:
  2194. ++this$1.pos;
  2195. if (this$1.options.locations) {
  2196. ++this$1.curLine;
  2197. this$1.lineStart = this$1.pos;
  2198. }
  2199. break
  2200. case 47: // '/'
  2201. switch (this$1.input.charCodeAt(this$1.pos + 1)) {
  2202. case 42: // '*'
  2203. this$1.skipBlockComment();
  2204. break
  2205. case 47:
  2206. this$1.skipLineComment(2);
  2207. break
  2208. default:
  2209. break loop
  2210. }
  2211. break
  2212. default:
  2213. if (ch > 8 && ch < 14 || ch >= 5760 && nonASCIIwhitespace.test(String.fromCharCode(ch))) {
  2214. ++this$1.pos;
  2215. } else {
  2216. break loop
  2217. }
  2218. }
  2219. }
  2220. };
  2221. // Called at the end of every token. Sets `end`, `val`, and
  2222. // maintains `context` and `exprAllowed`, and skips the space after
  2223. // the token, so that the next one's `start` will point at the
  2224. // right position.
  2225. pp$7.finishToken = function(type, val) {
  2226. this.end = this.pos;
  2227. if (this.options.locations) this.endLoc = this.curPosition();
  2228. var prevType = this.type;
  2229. this.type = type;
  2230. this.value = val;
  2231. this.updateContext(prevType);
  2232. };
  2233. // ### Token reading
  2234. // This is the function that is called to fetch the next token. It
  2235. // is somewhat obscure, because it works in character codes rather
  2236. // than characters, and because operator parsing has been inlined
  2237. // into it.
  2238. //
  2239. // All in the name of speed.
  2240. //
  2241. pp$7.readToken_dot = function() {
  2242. var next = this.input.charCodeAt(this.pos + 1);
  2243. if (next >= 48 && next <= 57) return this.readNumber(true)
  2244. var next2 = this.input.charCodeAt(this.pos + 2);
  2245. if (this.options.ecmaVersion >= 6 && next === 46 && next2 === 46) { // 46 = dot '.'
  2246. this.pos += 3;
  2247. return this.finishToken(tt.ellipsis)
  2248. } else {
  2249. ++this.pos;
  2250. return this.finishToken(tt.dot)
  2251. }
  2252. };
  2253. pp$7.readToken_slash = function() { // '/'
  2254. var next = this.input.charCodeAt(this.pos + 1);
  2255. if (this.exprAllowed) {++this.pos; return this.readRegexp()}
  2256. if (next === 61) return this.finishOp(tt.assign, 2)
  2257. return this.finishOp(tt.slash, 1)
  2258. };
  2259. pp$7.readToken_mult_modulo_exp = function(code) { // '%*'
  2260. var next = this.input.charCodeAt(this.pos + 1);
  2261. var size = 1;
  2262. var tokentype = code === 42 ? tt.star : tt.modulo;
  2263. // exponentiation operator ** and **=
  2264. if (this.options.ecmaVersion >= 7 && next === 42) {
  2265. ++size;
  2266. tokentype = tt.starstar;
  2267. next = this.input.charCodeAt(this.pos + 2);
  2268. }
  2269. if (next === 61) return this.finishOp(tt.assign, size + 1)
  2270. return this.finishOp(tokentype, size)
  2271. };
  2272. pp$7.readToken_pipe_amp = function(code) { // '|&'
  2273. var next = this.input.charCodeAt(this.pos + 1);
  2274. if (next === code) return this.finishOp(code === 124 ? tt.logicalOR : tt.logicalAND, 2)
  2275. if (next === 61) return this.finishOp(tt.assign, 2)
  2276. return this.finishOp(code === 124 ? tt.bitwiseOR : tt.bitwiseAND, 1)
  2277. };
  2278. pp$7.readToken_caret = function() { // '^'
  2279. var next = this.input.charCodeAt(this.pos + 1);
  2280. if (next === 61) return this.finishOp(tt.assign, 2)
  2281. return this.finishOp(tt.bitwiseXOR, 1)
  2282. };
  2283. pp$7.readToken_plus_min = function(code) { // '+-'
  2284. var next = this.input.charCodeAt(this.pos + 1);
  2285. if (next === code) {
  2286. if (next == 45 && this.input.charCodeAt(this.pos + 2) == 62 &&
  2287. lineBreak.test(this.input.slice(this.lastTokEnd, this.pos))) {
  2288. // A `-->` line comment
  2289. this.skipLineComment(3);
  2290. this.skipSpace();
  2291. return this.nextToken()
  2292. }
  2293. return this.finishOp(tt.incDec, 2)
  2294. }
  2295. if (next === 61) return this.finishOp(tt.assign, 2)
  2296. return this.finishOp(tt.plusMin, 1)
  2297. };
  2298. pp$7.readToken_lt_gt = function(code) { // '<>'
  2299. var next = this.input.charCodeAt(this.pos + 1);
  2300. var size = 1;
  2301. if (next === code) {
  2302. size = code === 62 && this.input.charCodeAt(this.pos + 2) === 62 ? 3 : 2;
  2303. if (this.input.charCodeAt(this.pos + size) === 61) return this.finishOp(tt.assign, size + 1)
  2304. return this.finishOp(tt.bitShift, size)
  2305. }
  2306. if (next == 33 && code == 60 && this.input.charCodeAt(this.pos + 2) == 45 &&
  2307. this.input.charCodeAt(this.pos + 3) == 45) {
  2308. if (this.inModule) this.unexpected();
  2309. // `<!--`, an XML-style comment that should be interpreted as a line comment
  2310. this.skipLineComment(4);
  2311. this.skipSpace();
  2312. return this.nextToken()
  2313. }
  2314. if (next === 61) size = 2;
  2315. return this.finishOp(tt.relational, size)
  2316. };
  2317. pp$7.readToken_eq_excl = function(code) { // '=!'
  2318. var next = this.input.charCodeAt(this.pos + 1);
  2319. if (next === 61) return this.finishOp(tt.equality, this.input.charCodeAt(this.pos + 2) === 61 ? 3 : 2)
  2320. if (code === 61 && next === 62 && this.options.ecmaVersion >= 6) { // '=>'
  2321. this.pos += 2;
  2322. return this.finishToken(tt.arrow)
  2323. }
  2324. return this.finishOp(code === 61 ? tt.eq : tt.prefix, 1)
  2325. };
  2326. pp$7.getTokenFromCode = function(code) {
  2327. switch (code) {
  2328. // The interpretation of a dot depends on whether it is followed
  2329. // by a digit or another two dots.
  2330. case 46: // '.'
  2331. return this.readToken_dot()
  2332. // Punctuation tokens.
  2333. case 40: ++this.pos; return this.finishToken(tt.parenL)
  2334. case 41: ++this.pos; return this.finishToken(tt.parenR)
  2335. case 59: ++this.pos; return this.finishToken(tt.semi)
  2336. case 44: ++this.pos; return this.finishToken(tt.comma)
  2337. case 91: ++this.pos; return this.finishToken(tt.bracketL)
  2338. case 93: ++this.pos; return this.finishToken(tt.bracketR)
  2339. case 123: ++this.pos; return this.finishToken(tt.braceL)
  2340. case 125: ++this.pos; return this.finishToken(tt.braceR)
  2341. case 58: ++this.pos; return this.finishToken(tt.colon)
  2342. case 63: ++this.pos; return this.finishToken(tt.question)
  2343. case 96: // '`'
  2344. if (this.options.ecmaVersion < 6) break
  2345. ++this.pos;
  2346. return this.finishToken(tt.backQuote)
  2347. case 48: // '0'
  2348. var next = this.input.charCodeAt(this.pos + 1);
  2349. if (next === 120 || next === 88) return this.readRadixNumber(16) // '0x', '0X' - hex number
  2350. if (this.options.ecmaVersion >= 6) {
  2351. if (next === 111 || next === 79) return this.readRadixNumber(8) // '0o', '0O' - octal number
  2352. if (next === 98 || next === 66) return this.readRadixNumber(2) // '0b', '0B' - binary number
  2353. }
  2354. // Anything else beginning with a digit is an integer, octal
  2355. // number, or float.
  2356. case 49: case 50: case 51: case 52: case 53: case 54: case 55: case 56: case 57: // 1-9
  2357. return this.readNumber(false)
  2358. // Quotes produce strings.
  2359. case 34: case 39: // '"', "'"
  2360. return this.readString(code)
  2361. // Operators are parsed inline in tiny state machines. '=' (61) is
  2362. // often referred to. `finishOp` simply skips the amount of
  2363. // characters it is given as second argument, and returns a token
  2364. // of the type given by its first argument.
  2365. case 47: // '/'
  2366. return this.readToken_slash()
  2367. case 37: case 42: // '%*'
  2368. return this.readToken_mult_modulo_exp(code)
  2369. case 124: case 38: // '|&'
  2370. return this.readToken_pipe_amp(code)
  2371. case 94: // '^'
  2372. return this.readToken_caret()
  2373. case 43: case 45: // '+-'
  2374. return this.readToken_plus_min(code)
  2375. case 60: case 62: // '<>'
  2376. return this.readToken_lt_gt(code)
  2377. case 61: case 33: // '=!'
  2378. return this.readToken_eq_excl(code)
  2379. case 126: // '~'
  2380. return this.finishOp(tt.prefix, 1)
  2381. }
  2382. this.raise(this.pos, "Unexpected character '" + codePointToString(code) + "'");
  2383. };
  2384. pp$7.finishOp = function(type, size) {
  2385. var str = this.input.slice(this.pos, this.pos + size);
  2386. this.pos += size;
  2387. return this.finishToken(type, str)
  2388. };
  2389. // Parse a regular expression. Some context-awareness is necessary,
  2390. // since a '/' inside a '[]' set does not end the expression.
  2391. function tryCreateRegexp(src, flags, throwErrorAt, parser) {
  2392. try {
  2393. return new RegExp(src, flags)
  2394. } catch (e) {
  2395. if (throwErrorAt !== undefined) {
  2396. if (e instanceof SyntaxError) parser.raise(throwErrorAt, "Error parsing regular expression: " + e.message);
  2397. throw e
  2398. }
  2399. }
  2400. }
  2401. var regexpUnicodeSupport = !!tryCreateRegexp("\uffff", "u");
  2402. pp$7.readRegexp = function() {
  2403. var this$1 = this;
  2404. var escaped, inClass, start = this.pos;
  2405. for (;;) {
  2406. if (this$1.pos >= this$1.input.length) this$1.raise(start, "Unterminated regular expression");
  2407. var ch = this$1.input.charAt(this$1.pos);
  2408. if (lineBreak.test(ch)) this$1.raise(start, "Unterminated regular expression");
  2409. if (!escaped) {
  2410. if (ch === "[") inClass = true;
  2411. else if (ch === "]" && inClass) inClass = false;
  2412. else if (ch === "/" && !inClass) break
  2413. escaped = ch === "\\";
  2414. } else escaped = false;
  2415. ++this$1.pos;
  2416. }
  2417. var content = this.input.slice(start, this.pos);
  2418. ++this.pos;
  2419. // Need to use `readWord1` because '\uXXXX' sequences are allowed
  2420. // here (don't ask).
  2421. var mods = this.readWord1();
  2422. var tmp = content, tmpFlags = "";
  2423. if (mods) {
  2424. var validFlags = /^[gim]*$/;
  2425. if (this.options.ecmaVersion >= 6) validFlags = /^[gimuy]*$/;
  2426. if (!validFlags.test(mods)) this.raise(start, "Invalid regular expression flag");
  2427. if (mods.indexOf("u") >= 0) {
  2428. if (regexpUnicodeSupport) {
  2429. tmpFlags = "u";
  2430. } else {
  2431. // Replace each astral symbol and every Unicode escape sequence that
  2432. // possibly represents an astral symbol or a paired surrogate with a
  2433. // single ASCII symbol to avoid throwing on regular expressions that
  2434. // are only valid in combination with the `/u` flag.
  2435. // Note: replacing with the ASCII symbol `x` might cause false
  2436. // negatives in unlikely scenarios. For example, `[\u{61}-b]` is a
  2437. // perfectly valid pattern that is equivalent to `[a-b]`, but it would
  2438. // be replaced by `[x-b]` which throws an error.
  2439. tmp = tmp.replace(/\\u\{([0-9a-fA-F]+)\}/g, function (_match, code, offset) {
  2440. code = Number("0x" + code);
  2441. if (code > 0x10FFFF) this$1.raise(start + offset + 3, "Code point out of bounds");
  2442. return "x"
  2443. });
  2444. tmp = tmp.replace(/\\u([a-fA-F0-9]{4})|[\uD800-\uDBFF][\uDC00-\uDFFF]/g, "x");
  2445. tmpFlags = tmpFlags.replace("u", "");
  2446. }
  2447. }
  2448. }
  2449. // Detect invalid regular expressions.
  2450. var value = null;
  2451. // Rhino's regular expression parser is flaky and throws uncatchable exceptions,
  2452. // so don't do detection if we are running under Rhino
  2453. if (!isRhino) {
  2454. tryCreateRegexp(tmp, tmpFlags, start, this);
  2455. // Get a regular expression object for this pattern-flag pair, or `null` in
  2456. // case the current environment doesn't support the flags it uses.
  2457. value = tryCreateRegexp(content, mods);
  2458. }
  2459. return this.finishToken(tt.regexp, {pattern: content, flags: mods, value: value})
  2460. };
  2461. // Read an integer in the given radix. Return null if zero digits
  2462. // were read, the integer value otherwise. When `len` is given, this
  2463. // will return `null` unless the integer has exactly `len` digits.
  2464. pp$7.readInt = function(radix, len) {
  2465. var this$1 = this;
  2466. var start = this.pos, total = 0;
  2467. for (var i = 0, e = len == null ? Infinity : len; i < e; ++i) {
  2468. var code = this$1.input.charCodeAt(this$1.pos), val;
  2469. if (code >= 97) val = code - 97 + 10; // a
  2470. else if (code >= 65) val = code - 65 + 10; // A
  2471. else if (code >= 48 && code <= 57) val = code - 48; // 0-9
  2472. else val = Infinity;
  2473. if (val >= radix) break
  2474. ++this$1.pos;
  2475. total = total * radix + val;
  2476. }
  2477. if (this.pos === start || len != null && this.pos - start !== len) return null
  2478. return total
  2479. };
  2480. pp$7.readRadixNumber = function(radix) {
  2481. this.pos += 2; // 0x
  2482. var val = this.readInt(radix);
  2483. if (val == null) this.raise(this.start + 2, "Expected number in radix " + radix);
  2484. if (isIdentifierStart(this.fullCharCodeAtPos())) this.raise(this.pos, "Identifier directly after number");
  2485. return this.finishToken(tt.num, val)
  2486. };
  2487. // Read an integer, octal integer, or floating-point number.
  2488. pp$7.readNumber = function(startsWithDot) {
  2489. var start = this.pos, isFloat = false, octal = this.input.charCodeAt(this.pos) === 48;
  2490. if (!startsWithDot && this.readInt(10) === null) this.raise(start, "Invalid number");
  2491. var next = this.input.charCodeAt(this.pos);
  2492. if (next === 46) { // '.'
  2493. ++this.pos;
  2494. this.readInt(10);
  2495. isFloat = true;
  2496. next = this.input.charCodeAt(this.pos);
  2497. }
  2498. if (next === 69 || next === 101) { // 'eE'
  2499. next = this.input.charCodeAt(++this.pos);
  2500. if (next === 43 || next === 45) ++this.pos; // '+-'
  2501. if (this.readInt(10) === null) this.raise(start, "Invalid number");
  2502. isFloat = true;
  2503. }
  2504. if (isIdentifierStart(this.fullCharCodeAtPos())) this.raise(this.pos, "Identifier directly after number");
  2505. var str = this.input.slice(start, this.pos), val;
  2506. if (isFloat) val = parseFloat(str);
  2507. else if (!octal || str.length === 1) val = parseInt(str, 10);
  2508. else if (/[89]/.test(str) || this.strict) this.raise(start, "Invalid number");
  2509. else val = parseInt(str, 8);
  2510. return this.finishToken(tt.num, val)
  2511. };
  2512. // Read a string value, interpreting backslash-escapes.
  2513. pp$7.readCodePoint = function() {
  2514. var ch = this.input.charCodeAt(this.pos), code;
  2515. if (ch === 123) {
  2516. if (this.options.ecmaVersion < 6) this.unexpected();
  2517. var codePos = ++this.pos;
  2518. code = this.readHexChar(this.input.indexOf('}', this.pos) - this.pos);
  2519. ++this.pos;
  2520. if (code > 0x10FFFF) this.raise(codePos, "Code point out of bounds");
  2521. } else {
  2522. code = this.readHexChar(4);
  2523. }
  2524. return code
  2525. };
  2526. function codePointToString(code) {
  2527. // UTF-16 Decoding
  2528. if (code <= 0xFFFF) return String.fromCharCode(code)
  2529. code -= 0x10000;
  2530. return String.fromCharCode((code >> 10) + 0xD800, (code & 1023) + 0xDC00)
  2531. }
  2532. pp$7.readString = function(quote) {
  2533. var this$1 = this;
  2534. var out = "", chunkStart = ++this.pos;
  2535. for (;;) {
  2536. if (this$1.pos >= this$1.input.length) this$1.raise(this$1.start, "Unterminated string constant");
  2537. var ch = this$1.input.charCodeAt(this$1.pos);
  2538. if (ch === quote) break
  2539. if (ch === 92) { // '\'
  2540. out += this$1.input.slice(chunkStart, this$1.pos);
  2541. out += this$1.readEscapedChar(false);
  2542. chunkStart = this$1.pos;
  2543. } else {
  2544. if (isNewLine(ch)) this$1.raise(this$1.start, "Unterminated string constant");
  2545. ++this$1.pos;
  2546. }
  2547. }
  2548. out += this.input.slice(chunkStart, this.pos++);
  2549. return this.finishToken(tt.string, out)
  2550. };
  2551. // Reads template string tokens.
  2552. pp$7.readTmplToken = function() {
  2553. var this$1 = this;
  2554. var out = "", chunkStart = this.pos;
  2555. for (;;) {
  2556. if (this$1.pos >= this$1.input.length) this$1.raise(this$1.start, "Unterminated template");
  2557. var ch = this$1.input.charCodeAt(this$1.pos);
  2558. if (ch === 96 || ch === 36 && this$1.input.charCodeAt(this$1.pos + 1) === 123) { // '`', '${'
  2559. if (this$1.pos === this$1.start && this$1.type === tt.template) {
  2560. if (ch === 36) {
  2561. this$1.pos += 2;
  2562. return this$1.finishToken(tt.dollarBraceL)
  2563. } else {
  2564. ++this$1.pos;
  2565. return this$1.finishToken(tt.backQuote)
  2566. }
  2567. }
  2568. out += this$1.input.slice(chunkStart, this$1.pos);
  2569. return this$1.finishToken(tt.template, out)
  2570. }
  2571. if (ch === 92) { // '\'
  2572. out += this$1.input.slice(chunkStart, this$1.pos);
  2573. out += this$1.readEscapedChar(true);
  2574. chunkStart = this$1.pos;
  2575. } else if (isNewLine(ch)) {
  2576. out += this$1.input.slice(chunkStart, this$1.pos);
  2577. ++this$1.pos;
  2578. switch (ch) {
  2579. case 13:
  2580. if (this$1.input.charCodeAt(this$1.pos) === 10) ++this$1.pos;
  2581. case 10:
  2582. out += "\n";
  2583. break
  2584. default:
  2585. out += String.fromCharCode(ch);
  2586. break
  2587. }
  2588. if (this$1.options.locations) {
  2589. ++this$1.curLine;
  2590. this$1.lineStart = this$1.pos;
  2591. }
  2592. chunkStart = this$1.pos;
  2593. } else {
  2594. ++this$1.pos;
  2595. }
  2596. }
  2597. };
  2598. // Used to read escaped characters
  2599. pp$7.readEscapedChar = function(inTemplate) {
  2600. var ch = this.input.charCodeAt(++this.pos);
  2601. ++this.pos;
  2602. switch (ch) {
  2603. case 110: return "\n" // 'n' -> '\n'
  2604. case 114: return "\r" // 'r' -> '\r'
  2605. case 120: return String.fromCharCode(this.readHexChar(2)) // 'x'
  2606. case 117: return codePointToString(this.readCodePoint()) // 'u'
  2607. case 116: return "\t" // 't' -> '\t'
  2608. case 98: return "\b" // 'b' -> '\b'
  2609. case 118: return "\u000b" // 'v' -> '\u000b'
  2610. case 102: return "\f" // 'f' -> '\f'
  2611. case 13: if (this.input.charCodeAt(this.pos) === 10) ++this.pos; // '\r\n'
  2612. case 10: // ' \n'
  2613. if (this.options.locations) { this.lineStart = this.pos; ++this.curLine; }
  2614. return ""
  2615. default:
  2616. if (ch >= 48 && ch <= 55) {
  2617. var octalStr = this.input.substr(this.pos - 1, 3).match(/^[0-7]+/)[0];
  2618. var octal = parseInt(octalStr, 8);
  2619. if (octal > 255) {
  2620. octalStr = octalStr.slice(0, -1);
  2621. octal = parseInt(octalStr, 8);
  2622. }
  2623. if (octalStr !== "0" && (this.strict || inTemplate)) {
  2624. this.raise(this.pos - 2, "Octal literal in strict mode");
  2625. }
  2626. this.pos += octalStr.length - 1;
  2627. return String.fromCharCode(octal)
  2628. }
  2629. return String.fromCharCode(ch)
  2630. }
  2631. };
  2632. // Used to read character escape sequences ('\x', '\u', '\U').
  2633. pp$7.readHexChar = function(len) {
  2634. var codePos = this.pos;
  2635. var n = this.readInt(16, len);
  2636. if (n === null) this.raise(codePos, "Bad character escape sequence");
  2637. return n
  2638. };
  2639. // Read an identifier, and return it as a string. Sets `this.containsEsc`
  2640. // to whether the word contained a '\u' escape.
  2641. //
  2642. // Incrementally adds only escaped chars, adding other chunks as-is
  2643. // as a micro-optimization.
  2644. pp$7.readWord1 = function() {
  2645. var this$1 = this;
  2646. this.containsEsc = false;
  2647. var word = "", first = true, chunkStart = this.pos;
  2648. var astral = this.options.ecmaVersion >= 6;
  2649. while (this.pos < this.input.length) {
  2650. var ch = this$1.fullCharCodeAtPos();
  2651. if (isIdentifierChar(ch, astral)) {
  2652. this$1.pos += ch <= 0xffff ? 1 : 2;
  2653. } else if (ch === 92) { // "\"
  2654. this$1.containsEsc = true;
  2655. word += this$1.input.slice(chunkStart, this$1.pos);
  2656. var escStart = this$1.pos;
  2657. if (this$1.input.charCodeAt(++this$1.pos) != 117) // "u"
  2658. this$1.raise(this$1.pos, "Expecting Unicode escape sequence \\uXXXX");
  2659. ++this$1.pos;
  2660. var esc = this$1.readCodePoint();
  2661. if (!(first ? isIdentifierStart : isIdentifierChar)(esc, astral))
  2662. this$1.raise(escStart, "Invalid Unicode escape");
  2663. word += codePointToString(esc);
  2664. chunkStart = this$1.pos;
  2665. } else {
  2666. break
  2667. }
  2668. first = false;
  2669. }
  2670. return word + this.input.slice(chunkStart, this.pos)
  2671. };
  2672. // Read an identifier or keyword token. Will check for reserved
  2673. // words when necessary.
  2674. pp$7.readWord = function() {
  2675. var word = this.readWord1();
  2676. var type = tt.name;
  2677. if ((this.options.ecmaVersion >= 6 || !this.containsEsc) && this.keywords.test(word))
  2678. type = keywordTypes[word];
  2679. return this.finishToken(type, word)
  2680. };
  2681. var version = "3.3.0";
  2682. // The main exported interface (under `self.acorn` when in the
  2683. // browser) is a `parse` function that takes a code string and
  2684. // returns an abstract syntax tree as specified by [Mozilla parser
  2685. // API][api].
  2686. //
  2687. // [api]: https://developer.mozilla.org/en-US/docs/SpiderMonkey/Parser_API
  2688. function parse(input, options) {
  2689. return new Parser(options, input).parse()
  2690. }
  2691. // This function tries to parse a single expression at a given
  2692. // offset in a string. Useful for parsing mixed-language formats
  2693. // that embed JavaScript expressions.
  2694. function parseExpressionAt(input, pos, options) {
  2695. var p = new Parser(options, input, pos);
  2696. p.nextToken();
  2697. return p.parseExpression()
  2698. }
  2699. // Acorn is organized as a tokenizer and a recursive-descent parser.
  2700. // The `tokenizer` export provides an interface to the tokenizer.
  2701. function tokenizer(input, options) {
  2702. return new Parser(options, input)
  2703. }
  2704. exports.version = version;
  2705. exports.parse = parse;
  2706. exports.parseExpressionAt = parseExpressionAt;
  2707. exports.tokenizer = tokenizer;
  2708. exports.Parser = Parser;
  2709. exports.plugins = plugins;
  2710. exports.defaultOptions = defaultOptions;
  2711. exports.Position = Position;
  2712. exports.SourceLocation = SourceLocation;
  2713. exports.getLineInfo = getLineInfo;
  2714. exports.Node = Node;
  2715. exports.TokenType = TokenType;
  2716. exports.tokTypes = tt;
  2717. exports.TokContext = TokContext;
  2718. exports.tokContexts = types;
  2719. exports.isIdentifierChar = isIdentifierChar;
  2720. exports.isIdentifierStart = isIdentifierStart;
  2721. exports.Token = Token;
  2722. exports.isNewLine = isNewLine;
  2723. exports.lineBreak = lineBreak;
  2724. exports.lineBreakG = lineBreakG;
  2725. Object.defineProperty(exports, '__esModule', { value: true });
  2726. }));
  2727. });
  2728. var acorn$1 = (acorn && typeof acorn === 'object' && 'default' in acorn ? acorn['default'] : acorn);
  2729. var xhtml = __commonjs(function (module) {
  2730. module.exports = {
  2731. quot: '\u0022',
  2732. amp: '&',
  2733. apos: '\u0027',
  2734. lt: '<',
  2735. gt: '>',
  2736. nbsp: '\u00A0',
  2737. iexcl: '\u00A1',
  2738. cent: '\u00A2',
  2739. pound: '\u00A3',
  2740. curren: '\u00A4',
  2741. yen: '\u00A5',
  2742. brvbar: '\u00A6',
  2743. sect: '\u00A7',
  2744. uml: '\u00A8',
  2745. copy: '\u00A9',
  2746. ordf: '\u00AA',
  2747. laquo: '\u00AB',
  2748. not: '\u00AC',
  2749. shy: '\u00AD',
  2750. reg: '\u00AE',
  2751. macr: '\u00AF',
  2752. deg: '\u00B0',
  2753. plusmn: '\u00B1',
  2754. sup2: '\u00B2',
  2755. sup3: '\u00B3',
  2756. acute: '\u00B4',
  2757. micro: '\u00B5',
  2758. para: '\u00B6',
  2759. middot: '\u00B7',
  2760. cedil: '\u00B8',
  2761. sup1: '\u00B9',
  2762. ordm: '\u00BA',
  2763. raquo: '\u00BB',
  2764. frac14: '\u00BC',
  2765. frac12: '\u00BD',
  2766. frac34: '\u00BE',
  2767. iquest: '\u00BF',
  2768. Agrave: '\u00C0',
  2769. Aacute: '\u00C1',
  2770. Acirc: '\u00C2',
  2771. Atilde: '\u00C3',
  2772. Auml: '\u00C4',
  2773. Aring: '\u00C5',
  2774. AElig: '\u00C6',
  2775. Ccedil: '\u00C7',
  2776. Egrave: '\u00C8',
  2777. Eacute: '\u00C9',
  2778. Ecirc: '\u00CA',
  2779. Euml: '\u00CB',
  2780. Igrave: '\u00CC',
  2781. Iacute: '\u00CD',
  2782. Icirc: '\u00CE',
  2783. Iuml: '\u00CF',
  2784. ETH: '\u00D0',
  2785. Ntilde: '\u00D1',
  2786. Ograve: '\u00D2',
  2787. Oacute: '\u00D3',
  2788. Ocirc: '\u00D4',
  2789. Otilde: '\u00D5',
  2790. Ouml: '\u00D6',
  2791. times: '\u00D7',
  2792. Oslash: '\u00D8',
  2793. Ugrave: '\u00D9',
  2794. Uacute: '\u00DA',
  2795. Ucirc: '\u00DB',
  2796. Uuml: '\u00DC',
  2797. Yacute: '\u00DD',
  2798. THORN: '\u00DE',
  2799. szlig: '\u00DF',
  2800. agrave: '\u00E0',
  2801. aacute: '\u00E1',
  2802. acirc: '\u00E2',
  2803. atilde: '\u00E3',
  2804. auml: '\u00E4',
  2805. aring: '\u00E5',
  2806. aelig: '\u00E6',
  2807. ccedil: '\u00E7',
  2808. egrave: '\u00E8',
  2809. eacute: '\u00E9',
  2810. ecirc: '\u00EA',
  2811. euml: '\u00EB',
  2812. igrave: '\u00EC',
  2813. iacute: '\u00ED',
  2814. icirc: '\u00EE',
  2815. iuml: '\u00EF',
  2816. eth: '\u00F0',
  2817. ntilde: '\u00F1',
  2818. ograve: '\u00F2',
  2819. oacute: '\u00F3',
  2820. ocirc: '\u00F4',
  2821. otilde: '\u00F5',
  2822. ouml: '\u00F6',
  2823. divide: '\u00F7',
  2824. oslash: '\u00F8',
  2825. ugrave: '\u00F9',
  2826. uacute: '\u00FA',
  2827. ucirc: '\u00FB',
  2828. uuml: '\u00FC',
  2829. yacute: '\u00FD',
  2830. thorn: '\u00FE',
  2831. yuml: '\u00FF',
  2832. OElig: '\u0152',
  2833. oelig: '\u0153',
  2834. Scaron: '\u0160',
  2835. scaron: '\u0161',
  2836. Yuml: '\u0178',
  2837. fnof: '\u0192',
  2838. circ: '\u02C6',
  2839. tilde: '\u02DC',
  2840. Alpha: '\u0391',
  2841. Beta: '\u0392',
  2842. Gamma: '\u0393',
  2843. Delta: '\u0394',
  2844. Epsilon: '\u0395',
  2845. Zeta: '\u0396',
  2846. Eta: '\u0397',
  2847. Theta: '\u0398',
  2848. Iota: '\u0399',
  2849. Kappa: '\u039A',
  2850. Lambda: '\u039B',
  2851. Mu: '\u039C',
  2852. Nu: '\u039D',
  2853. Xi: '\u039E',
  2854. Omicron: '\u039F',
  2855. Pi: '\u03A0',
  2856. Rho: '\u03A1',
  2857. Sigma: '\u03A3',
  2858. Tau: '\u03A4',
  2859. Upsilon: '\u03A5',
  2860. Phi: '\u03A6',
  2861. Chi: '\u03A7',
  2862. Psi: '\u03A8',
  2863. Omega: '\u03A9',
  2864. alpha: '\u03B1',
  2865. beta: '\u03B2',
  2866. gamma: '\u03B3',
  2867. delta: '\u03B4',
  2868. epsilon: '\u03B5',
  2869. zeta: '\u03B6',
  2870. eta: '\u03B7',
  2871. theta: '\u03B8',
  2872. iota: '\u03B9',
  2873. kappa: '\u03BA',
  2874. lambda: '\u03BB',
  2875. mu: '\u03BC',
  2876. nu: '\u03BD',
  2877. xi: '\u03BE',
  2878. omicron: '\u03BF',
  2879. pi: '\u03C0',
  2880. rho: '\u03C1',
  2881. sigmaf: '\u03C2',
  2882. sigma: '\u03C3',
  2883. tau: '\u03C4',
  2884. upsilon: '\u03C5',
  2885. phi: '\u03C6',
  2886. chi: '\u03C7',
  2887. psi: '\u03C8',
  2888. omega: '\u03C9',
  2889. thetasym: '\u03D1',
  2890. upsih: '\u03D2',
  2891. piv: '\u03D6',
  2892. ensp: '\u2002',
  2893. emsp: '\u2003',
  2894. thinsp: '\u2009',
  2895. zwnj: '\u200C',
  2896. zwj: '\u200D',
  2897. lrm: '\u200E',
  2898. rlm: '\u200F',
  2899. ndash: '\u2013',
  2900. mdash: '\u2014',
  2901. lsquo: '\u2018',
  2902. rsquo: '\u2019',
  2903. sbquo: '\u201A',
  2904. ldquo: '\u201C',
  2905. rdquo: '\u201D',
  2906. bdquo: '\u201E',
  2907. dagger: '\u2020',
  2908. Dagger: '\u2021',
  2909. bull: '\u2022',
  2910. hellip: '\u2026',
  2911. permil: '\u2030',
  2912. prime: '\u2032',
  2913. Prime: '\u2033',
  2914. lsaquo: '\u2039',
  2915. rsaquo: '\u203A',
  2916. oline: '\u203E',
  2917. frasl: '\u2044',
  2918. euro: '\u20AC',
  2919. image: '\u2111',
  2920. weierp: '\u2118',
  2921. real: '\u211C',
  2922. trade: '\u2122',
  2923. alefsym: '\u2135',
  2924. larr: '\u2190',
  2925. uarr: '\u2191',
  2926. rarr: '\u2192',
  2927. darr: '\u2193',
  2928. harr: '\u2194',
  2929. crarr: '\u21B5',
  2930. lArr: '\u21D0',
  2931. uArr: '\u21D1',
  2932. rArr: '\u21D2',
  2933. dArr: '\u21D3',
  2934. hArr: '\u21D4',
  2935. forall: '\u2200',
  2936. part: '\u2202',
  2937. exist: '\u2203',
  2938. empty: '\u2205',
  2939. nabla: '\u2207',
  2940. isin: '\u2208',
  2941. notin: '\u2209',
  2942. ni: '\u220B',
  2943. prod: '\u220F',
  2944. sum: '\u2211',
  2945. minus: '\u2212',
  2946. lowast: '\u2217',
  2947. radic: '\u221A',
  2948. prop: '\u221D',
  2949. infin: '\u221E',
  2950. ang: '\u2220',
  2951. and: '\u2227',
  2952. or: '\u2228',
  2953. cap: '\u2229',
  2954. cup: '\u222A',
  2955. 'int': '\u222B',
  2956. there4: '\u2234',
  2957. sim: '\u223C',
  2958. cong: '\u2245',
  2959. asymp: '\u2248',
  2960. ne: '\u2260',
  2961. equiv: '\u2261',
  2962. le: '\u2264',
  2963. ge: '\u2265',
  2964. sub: '\u2282',
  2965. sup: '\u2283',
  2966. nsub: '\u2284',
  2967. sube: '\u2286',
  2968. supe: '\u2287',
  2969. oplus: '\u2295',
  2970. otimes: '\u2297',
  2971. perp: '\u22A5',
  2972. sdot: '\u22C5',
  2973. lceil: '\u2308',
  2974. rceil: '\u2309',
  2975. lfloor: '\u230A',
  2976. rfloor: '\u230B',
  2977. lang: '\u2329',
  2978. rang: '\u232A',
  2979. loz: '\u25CA',
  2980. spades: '\u2660',
  2981. clubs: '\u2663',
  2982. hearts: '\u2665',
  2983. diams: '\u2666'
  2984. };
  2985. });
  2986. var require$$0 = (xhtml && typeof xhtml === 'object' && 'default' in xhtml ? xhtml['default'] : xhtml);
  2987. var inject = __commonjs(function (module) {
  2988. 'use strict';
  2989. var XHTMLEntities = require$$0;
  2990. var hexNumber = /^[\da-fA-F]+$/;
  2991. var decimalNumber = /^\d+$/;
  2992. module.exports = function(acorn) {
  2993. var tt = acorn.tokTypes;
  2994. var tc = acorn.tokContexts;
  2995. tc.j_oTag = new acorn.TokContext('<tag', false);
  2996. tc.j_cTag = new acorn.TokContext('</tag', false);
  2997. tc.j_expr = new acorn.TokContext('<tag>...</tag>', true, true);
  2998. tt.jsxName = new acorn.TokenType('jsxName');
  2999. tt.jsxText = new acorn.TokenType('jsxText', {beforeExpr: true});
  3000. tt.jsxTagStart = new acorn.TokenType('jsxTagStart');
  3001. tt.jsxTagEnd = new acorn.TokenType('jsxTagEnd');
  3002. tt.jsxTagStart.updateContext = function() {
  3003. this.context.push(tc.j_expr); // treat as beginning of JSX expression
  3004. this.context.push(tc.j_oTag); // start opening tag context
  3005. this.exprAllowed = false;
  3006. };
  3007. tt.jsxTagEnd.updateContext = function(prevType) {
  3008. var out = this.context.pop();
  3009. if (out === tc.j_oTag && prevType === tt.slash || out === tc.j_cTag) {
  3010. this.context.pop();
  3011. this.exprAllowed = this.curContext() === tc.j_expr;
  3012. } else {
  3013. this.exprAllowed = true;
  3014. }
  3015. };
  3016. var pp = acorn.Parser.prototype;
  3017. // Reads inline JSX contents token.
  3018. pp.jsx_readToken = function() {
  3019. var out = '', chunkStart = this.pos;
  3020. for (;;) {
  3021. if (this.pos >= this.input.length)
  3022. this.raise(this.start, 'Unterminated JSX contents');
  3023. var ch = this.input.charCodeAt(this.pos);
  3024. switch (ch) {
  3025. case 60: // '<'
  3026. case 123: // '{'
  3027. if (this.pos === this.start) {
  3028. if (ch === 60 && this.exprAllowed) {
  3029. ++this.pos;
  3030. return this.finishToken(tt.jsxTagStart);
  3031. }
  3032. return this.getTokenFromCode(ch);
  3033. }
  3034. out += this.input.slice(chunkStart, this.pos);
  3035. return this.finishToken(tt.jsxText, out);
  3036. case 38: // '&'
  3037. out += this.input.slice(chunkStart, this.pos);
  3038. out += this.jsx_readEntity();
  3039. chunkStart = this.pos;
  3040. break;
  3041. default:
  3042. if (acorn.isNewLine(ch)) {
  3043. out += this.input.slice(chunkStart, this.pos);
  3044. out += this.jsx_readNewLine(true);
  3045. chunkStart = this.pos;
  3046. } else {
  3047. ++this.pos;
  3048. }
  3049. }
  3050. }
  3051. };
  3052. pp.jsx_readNewLine = function(normalizeCRLF) {
  3053. var ch = this.input.charCodeAt(this.pos);
  3054. var out;
  3055. ++this.pos;
  3056. if (ch === 13 && this.input.charCodeAt(this.pos) === 10) {
  3057. ++this.pos;
  3058. out = normalizeCRLF ? '\n' : '\r\n';
  3059. } else {
  3060. out = String.fromCharCode(ch);
  3061. }
  3062. if (this.options.locations) {
  3063. ++this.curLine;
  3064. this.lineStart = this.pos;
  3065. }
  3066. return out;
  3067. };
  3068. pp.jsx_readString = function(quote) {
  3069. var out = '', chunkStart = ++this.pos;
  3070. for (;;) {
  3071. if (this.pos >= this.input.length)
  3072. this.raise(this.start, 'Unterminated string constant');
  3073. var ch = this.input.charCodeAt(this.pos);
  3074. if (ch === quote) break;
  3075. if (ch === 38) { // '&'
  3076. out += this.input.slice(chunkStart, this.pos);
  3077. out += this.jsx_readEntity();
  3078. chunkStart = this.pos;
  3079. } else if (acorn.isNewLine(ch)) {
  3080. out += this.input.slice(chunkStart, this.pos);
  3081. out += this.jsx_readNewLine(false);
  3082. chunkStart = this.pos;
  3083. } else {
  3084. ++this.pos;
  3085. }
  3086. }
  3087. out += this.input.slice(chunkStart, this.pos++);
  3088. return this.finishToken(tt.string, out);
  3089. };
  3090. pp.jsx_readEntity = function() {
  3091. var str = '', count = 0, entity;
  3092. var ch = this.input[this.pos];
  3093. if (ch !== '&')
  3094. this.raise(this.pos, 'Entity must start with an ampersand');
  3095. var startPos = ++this.pos;
  3096. while (this.pos < this.input.length && count++ < 10) {
  3097. ch = this.input[this.pos++];
  3098. if (ch === ';') {
  3099. if (str[0] === '#') {
  3100. if (str[1] === 'x') {
  3101. str = str.substr(2);
  3102. if (hexNumber.test(str))
  3103. entity = String.fromCharCode(parseInt(str, 16));
  3104. } else {
  3105. str = str.substr(1);
  3106. if (decimalNumber.test(str))
  3107. entity = String.fromCharCode(parseInt(str, 10));
  3108. }
  3109. } else {
  3110. entity = XHTMLEntities[str];
  3111. }
  3112. break;
  3113. }
  3114. str += ch;
  3115. }
  3116. if (!entity) {
  3117. this.pos = startPos;
  3118. return '&';
  3119. }
  3120. return entity;
  3121. };
  3122. // Read a JSX identifier (valid tag or attribute name).
  3123. //
  3124. // Optimized version since JSX identifiers can't contain
  3125. // escape characters and so can be read as single slice.
  3126. // Also assumes that first character was already checked
  3127. // by isIdentifierStart in readToken.
  3128. pp.jsx_readWord = function() {
  3129. var ch, start = this.pos;
  3130. do {
  3131. ch = this.input.charCodeAt(++this.pos);
  3132. } while (acorn.isIdentifierChar(ch) || ch === 45); // '-'
  3133. return this.finishToken(tt.jsxName, this.input.slice(start, this.pos));
  3134. };
  3135. // Transforms JSX element name to string.
  3136. function getQualifiedJSXName(object) {
  3137. if (object.type === 'JSXIdentifier')
  3138. return object.name;
  3139. if (object.type === 'JSXNamespacedName')
  3140. return object.namespace.name + ':' + object.name.name;
  3141. if (object.type === 'JSXMemberExpression')
  3142. return getQualifiedJSXName(object.object) + '.' +
  3143. getQualifiedJSXName(object.property);
  3144. }
  3145. // Parse next token as JSX identifier
  3146. pp.jsx_parseIdentifier = function() {
  3147. var node = this.startNode();
  3148. if (this.type === tt.jsxName)
  3149. node.name = this.value;
  3150. else if (this.type.keyword)
  3151. node.name = this.type.keyword;
  3152. else
  3153. this.unexpected();
  3154. this.next();
  3155. return this.finishNode(node, 'JSXIdentifier');
  3156. };
  3157. // Parse namespaced identifier.
  3158. pp.jsx_parseNamespacedName = function() {
  3159. var startPos = this.start, startLoc = this.startLoc;
  3160. var name = this.jsx_parseIdentifier();
  3161. if (!this.options.plugins.jsx.allowNamespaces || !this.eat(tt.colon)) return name;
  3162. var node = this.startNodeAt(startPos, startLoc);
  3163. node.namespace = name;
  3164. node.name = this.jsx_parseIdentifier();
  3165. return this.finishNode(node, 'JSXNamespacedName');
  3166. };
  3167. // Parses element name in any form - namespaced, member
  3168. // or single identifier.
  3169. pp.jsx_parseElementName = function() {
  3170. var startPos = this.start, startLoc = this.startLoc;
  3171. var node = this.jsx_parseNamespacedName();
  3172. if (this.type === tt.dot && node.type === 'JSXNamespacedName' && !this.options.plugins.jsx.allowNamespacedObjects) {
  3173. this.unexpected();
  3174. }
  3175. while (this.eat(tt.dot)) {
  3176. var newNode = this.startNodeAt(startPos, startLoc);
  3177. newNode.object = node;
  3178. newNode.property = this.jsx_parseIdentifier();
  3179. node = this.finishNode(newNode, 'JSXMemberExpression');
  3180. }
  3181. return node;
  3182. };
  3183. // Parses any type of JSX attribute value.
  3184. pp.jsx_parseAttributeValue = function() {
  3185. switch (this.type) {
  3186. case tt.braceL:
  3187. var node = this.jsx_parseExpressionContainer();
  3188. if (node.expression.type === 'JSXEmptyExpression')
  3189. this.raise(node.start, 'JSX attributes must only be assigned a non-empty expression');
  3190. return node;
  3191. case tt.jsxTagStart:
  3192. case tt.string:
  3193. return this.parseExprAtom();
  3194. default:
  3195. this.raise(this.start, 'JSX value should be either an expression or a quoted JSX text');
  3196. }
  3197. };
  3198. // JSXEmptyExpression is unique type since it doesn't actually parse anything,
  3199. // and so it should start at the end of last read token (left brace) and finish
  3200. // at the beginning of the next one (right brace).
  3201. pp.jsx_parseEmptyExpression = function() {
  3202. var node = this.startNodeAt(this.lastTokEnd, this.lastTokEndLoc);
  3203. return this.finishNodeAt(node, 'JSXEmptyExpression', this.start, this.startLoc);
  3204. };
  3205. // Parses JSX expression enclosed into curly brackets.
  3206. pp.jsx_parseExpressionContainer = function() {
  3207. var node = this.startNode();
  3208. this.next();
  3209. node.expression = this.type === tt.braceR
  3210. ? this.jsx_parseEmptyExpression()
  3211. : this.parseExpression();
  3212. this.expect(tt.braceR);
  3213. return this.finishNode(node, 'JSXExpressionContainer');
  3214. };
  3215. // Parses following JSX attribute name-value pair.
  3216. pp.jsx_parseAttribute = function() {
  3217. var node = this.startNode();
  3218. if (this.eat(tt.braceL)) {
  3219. this.expect(tt.ellipsis);
  3220. node.argument = this.parseMaybeAssign();
  3221. this.expect(tt.braceR);
  3222. return this.finishNode(node, 'JSXSpreadAttribute');
  3223. }
  3224. node.name = this.jsx_parseNamespacedName();
  3225. node.value = this.eat(tt.eq) ? this.jsx_parseAttributeValue() : null;
  3226. return this.finishNode(node, 'JSXAttribute');
  3227. };
  3228. // Parses JSX opening tag starting after '<'.
  3229. pp.jsx_parseOpeningElementAt = function(startPos, startLoc) {
  3230. var node = this.startNodeAt(startPos, startLoc);
  3231. node.attributes = [];
  3232. node.name = this.jsx_parseElementName();
  3233. while (this.type !== tt.slash && this.type !== tt.jsxTagEnd)
  3234. node.attributes.push(this.jsx_parseAttribute());
  3235. node.selfClosing = this.eat(tt.slash);
  3236. this.expect(tt.jsxTagEnd);
  3237. return this.finishNode(node, 'JSXOpeningElement');
  3238. };
  3239. // Parses JSX closing tag starting after '</'.
  3240. pp.jsx_parseClosingElementAt = function(startPos, startLoc) {
  3241. var node = this.startNodeAt(startPos, startLoc);
  3242. node.name = this.jsx_parseElementName();
  3243. this.expect(tt.jsxTagEnd);
  3244. return this.finishNode(node, 'JSXClosingElement');
  3245. };
  3246. // Parses entire JSX element, including it's opening tag
  3247. // (starting after '<'), attributes, contents and closing tag.
  3248. pp.jsx_parseElementAt = function(startPos, startLoc) {
  3249. var node = this.startNodeAt(startPos, startLoc);
  3250. var children = [];
  3251. var openingElement = this.jsx_parseOpeningElementAt(startPos, startLoc);
  3252. var closingElement = null;
  3253. if (!openingElement.selfClosing) {
  3254. contents: for (;;) {
  3255. switch (this.type) {
  3256. case tt.jsxTagStart:
  3257. startPos = this.start; startLoc = this.startLoc;
  3258. this.next();
  3259. if (this.eat(tt.slash)) {
  3260. closingElement = this.jsx_parseClosingElementAt(startPos, startLoc);
  3261. break contents;
  3262. }
  3263. children.push(this.jsx_parseElementAt(startPos, startLoc));
  3264. break;
  3265. case tt.jsxText:
  3266. children.push(this.parseExprAtom());
  3267. break;
  3268. case tt.braceL:
  3269. children.push(this.jsx_parseExpressionContainer());
  3270. break;
  3271. default:
  3272. this.unexpected();
  3273. }
  3274. }
  3275. if (getQualifiedJSXName(closingElement.name) !== getQualifiedJSXName(openingElement.name)) {
  3276. this.raise(
  3277. closingElement.start,
  3278. 'Expected corresponding JSX closing tag for <' + getQualifiedJSXName(openingElement.name) + '>');
  3279. }
  3280. }
  3281. node.openingElement = openingElement;
  3282. node.closingElement = closingElement;
  3283. node.children = children;
  3284. if (this.type === tt.relational && this.value === "<") {
  3285. this.raise(this.start, "Adjacent JSX elements must be wrapped in an enclosing tag");
  3286. }
  3287. return this.finishNode(node, 'JSXElement');
  3288. };
  3289. // Parses entire JSX element from current position.
  3290. pp.jsx_parseElement = function() {
  3291. var startPos = this.start, startLoc = this.startLoc;
  3292. this.next();
  3293. return this.jsx_parseElementAt(startPos, startLoc);
  3294. };
  3295. acorn.plugins.jsx = function(instance, opts) {
  3296. if (!opts) {
  3297. return;
  3298. }
  3299. if (typeof opts !== 'object') {
  3300. opts = {};
  3301. }
  3302. instance.options.plugins.jsx = {
  3303. allowNamespaces: opts.allowNamespaces !== false,
  3304. allowNamespacedObjects: !!opts.allowNamespacedObjects
  3305. };
  3306. instance.extend('parseExprAtom', function(inner) {
  3307. return function(refShortHandDefaultPos) {
  3308. if (this.type === tt.jsxText)
  3309. return this.parseLiteral(this.value);
  3310. else if (this.type === tt.jsxTagStart)
  3311. return this.jsx_parseElement();
  3312. else
  3313. return inner.call(this, refShortHandDefaultPos);
  3314. };
  3315. });
  3316. instance.extend('readToken', function(inner) {
  3317. return function(code) {
  3318. var context = this.curContext();
  3319. if (context === tc.j_expr) return this.jsx_readToken();
  3320. if (context === tc.j_oTag || context === tc.j_cTag) {
  3321. if (acorn.isIdentifierStart(code)) return this.jsx_readWord();
  3322. if (code == 62) {
  3323. ++this.pos;
  3324. return this.finishToken(tt.jsxTagEnd);
  3325. }
  3326. if ((code === 34 || code === 39) && context == tc.j_oTag)
  3327. return this.jsx_readString(code);
  3328. }
  3329. if (code === 60 && this.exprAllowed) {
  3330. ++this.pos;
  3331. return this.finishToken(tt.jsxTagStart);
  3332. }
  3333. return inner.call(this, code);
  3334. };
  3335. });
  3336. instance.extend('updateContext', function(inner) {
  3337. return function(prevType) {
  3338. if (this.type == tt.braceL) {
  3339. var curContext = this.curContext();
  3340. if (curContext == tc.j_oTag) this.context.push(tc.b_expr);
  3341. else if (curContext == tc.j_expr) this.context.push(tc.b_tmpl);
  3342. else inner.call(this, prevType);
  3343. this.exprAllowed = true;
  3344. } else if (this.type === tt.slash && prevType === tt.jsxTagStart) {
  3345. this.context.length -= 2; // do not consider JSX expr -> JSX open tag -> ... anymore
  3346. this.context.push(tc.j_cTag); // reconsider as closing tag context
  3347. this.exprAllowed = false;
  3348. } else {
  3349. return inner.call(this, prevType);
  3350. }
  3351. };
  3352. });
  3353. };
  3354. return acorn;
  3355. };
  3356. });
  3357. var acornJsx = (inject && typeof inject === 'object' && 'default' in inject ? inject['default'] : inject);
  3358. var inject$1 = __commonjs(function (module) {
  3359. 'use strict';
  3360. module.exports = function(acorn) {
  3361. var tt = acorn.tokTypes;
  3362. var pp = acorn.Parser.prototype;
  3363. // this is the same parseObj that acorn has with...
  3364. function parseObj(isPattern, refDestructuringErrors) {
  3365. var this$1 = this;
  3366. var node = this.startNode(), first = true, propHash = {};
  3367. node.properties = [];
  3368. this.next();
  3369. while (!this$1.eat(tt.braceR)) {
  3370. if (!first) {
  3371. this$1.expect(tt.comma);
  3372. if (this$1.afterTrailingComma(tt.braceR)) break
  3373. } else first = false;
  3374. var prop = this$1.startNode(), isGenerator, startPos, startLoc;
  3375. if (this$1.options.ecmaVersion >= 6) {
  3376. // ...the spread logic borrowed from babylon :)
  3377. if (this$1.type === tt.ellipsis) {
  3378. prop = this$1.parseSpread();
  3379. prop.type = isPattern ? "RestProperty" : "SpreadProperty";
  3380. node.properties.push(prop);
  3381. continue
  3382. }
  3383. prop.method = false;
  3384. prop.shorthand = false;
  3385. if (isPattern || refDestructuringErrors) {
  3386. startPos = this$1.start;
  3387. startLoc = this$1.startLoc;
  3388. }
  3389. if (!isPattern)
  3390. isGenerator = this$1.eat(tt.star);
  3391. }
  3392. this$1.parsePropertyName(prop);
  3393. this$1.parsePropertyValue(prop, isPattern, isGenerator, startPos, startLoc, refDestructuringErrors);
  3394. this$1.checkPropClash(prop, propHash);
  3395. node.properties.push(this$1.finishNode(prop, "Property"));
  3396. }
  3397. return this.finishNode(node, isPattern ? "ObjectPattern" : "ObjectExpression")
  3398. }
  3399. acorn.plugins.objectSpread = function objectSpreadPlugin(instance) {
  3400. pp.parseObj = parseObj;
  3401. };
  3402. return acorn;
  3403. };
  3404. });
  3405. var acornObjectSpread = (inject$1 && typeof inject$1 === 'object' && 'default' in inject$1 ? inject$1['default'] : inject$1);
  3406. var charToInteger = {};
  3407. var integerToChar = {};
  3408. 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='.split( '' ).forEach( function ( char, i ) {
  3409. charToInteger[ char ] = i;
  3410. integerToChar[ i ] = char;
  3411. });
  3412. function encode ( value ) {
  3413. var result, i;
  3414. if ( typeof value === 'number' ) {
  3415. result = encodeInteger( value );
  3416. } else {
  3417. result = '';
  3418. for ( i = 0; i < value.length; i += 1 ) {
  3419. result += encodeInteger( value[i] );
  3420. }
  3421. }
  3422. return result;
  3423. }
  3424. function encodeInteger ( num ) {
  3425. var result = '', clamped;
  3426. if ( num < 0 ) {
  3427. num = ( -num << 1 ) | 1;
  3428. } else {
  3429. num <<= 1;
  3430. }
  3431. do {
  3432. clamped = num & 31;
  3433. num >>= 5;
  3434. if ( num > 0 ) {
  3435. clamped |= 32;
  3436. }
  3437. result += integerToChar[ clamped ];
  3438. } while ( num > 0 );
  3439. return result;
  3440. }
  3441. function Chunk ( start, end, content ) {
  3442. this.start = start;
  3443. this.end = end;
  3444. this.original = content;
  3445. this.intro = '';
  3446. this.outro = '';
  3447. this.content = content;
  3448. this.storeName = false;
  3449. this.edited = false;
  3450. // we make these non-enumerable, for sanity while debugging
  3451. Object.defineProperties( this, {
  3452. previous: { writable: true, value: null },
  3453. next: { writable: true, value: null }
  3454. });
  3455. }
  3456. Chunk.prototype = {
  3457. append: function append ( content ) {
  3458. this.outro += content;
  3459. },
  3460. clone: function clone () {
  3461. var chunk = new Chunk( this.start, this.end, this.original );
  3462. chunk.intro = this.intro;
  3463. chunk.outro = this.outro;
  3464. chunk.content = this.content;
  3465. chunk.storeName = this.storeName;
  3466. chunk.edited = this.edited;
  3467. return chunk;
  3468. },
  3469. contains: function contains ( index ) {
  3470. return this.start < index && index < this.end;
  3471. },
  3472. eachNext: function eachNext ( fn ) {
  3473. var chunk = this;
  3474. while ( chunk ) {
  3475. fn( chunk );
  3476. chunk = chunk.next;
  3477. }
  3478. },
  3479. eachPrevious: function eachPrevious ( fn ) {
  3480. var chunk = this;
  3481. while ( chunk ) {
  3482. fn( chunk );
  3483. chunk = chunk.previous;
  3484. }
  3485. },
  3486. edit: function edit ( content, storeName ) {
  3487. this.content = content;
  3488. this.storeName = storeName;
  3489. this.edited = true;
  3490. return this;
  3491. },
  3492. prepend: function prepend ( content ) {
  3493. this.intro = content + this.intro;
  3494. },
  3495. split: function split ( index ) {
  3496. var sliceIndex = index - this.start;
  3497. var originalBefore = this.original.slice( 0, sliceIndex );
  3498. var originalAfter = this.original.slice( sliceIndex );
  3499. this.original = originalBefore;
  3500. var newChunk = new Chunk( index, this.end, originalAfter );
  3501. newChunk.outro = this.outro;
  3502. this.outro = '';
  3503. this.end = index;
  3504. if ( this.edited ) {
  3505. // TODO is this block necessary?...
  3506. newChunk.edit( '', false );
  3507. this.content = '';
  3508. } else {
  3509. this.content = originalBefore;
  3510. }
  3511. newChunk.next = this.next;
  3512. if ( newChunk.next ) newChunk.next.previous = newChunk;
  3513. newChunk.previous = this;
  3514. this.next = newChunk;
  3515. return newChunk;
  3516. },
  3517. toString: function toString$1 () {
  3518. return this.intro + this.content + this.outro;
  3519. },
  3520. trimEnd: function trimEnd ( rx ) {
  3521. this.outro = this.outro.replace( rx, '' );
  3522. if ( this.outro.length ) return true;
  3523. var trimmed = this.content.replace( rx, '' );
  3524. if ( trimmed.length ) {
  3525. if ( trimmed !== this.content ) {
  3526. this.split( this.start + trimmed.length ).edit( '', false );
  3527. }
  3528. return true;
  3529. } else {
  3530. this.edit( '', false );
  3531. this.intro = this.intro.replace( rx, '' );
  3532. if ( this.intro.length ) return true;
  3533. }
  3534. },
  3535. trimStart: function trimStart ( rx ) {
  3536. this.intro = this.intro.replace( rx, '' );
  3537. if ( this.intro.length ) return true;
  3538. var trimmed = this.content.replace( rx, '' );
  3539. if ( trimmed.length ) {
  3540. if ( trimmed !== this.content ) {
  3541. this.split( this.end - trimmed.length );
  3542. this.edit( '', false );
  3543. }
  3544. return true;
  3545. } else {
  3546. this.edit( '', false );
  3547. this.outro = this.outro.replace( rx, '' );
  3548. if ( this.outro.length ) return true;
  3549. }
  3550. }
  3551. };
  3552. var _btoa;
  3553. if ( typeof window !== 'undefined' && typeof window.btoa === 'function' ) {
  3554. _btoa = window.btoa;
  3555. } else if ( typeof Buffer === 'function' ) {
  3556. _btoa = function ( str ) { return new Buffer( str ).toString( 'base64' ); };
  3557. } else {
  3558. _btoa = function () {
  3559. throw new Error( 'Unsupported environment: `window.btoa` or `Buffer` should be supported.' );
  3560. };
  3561. }
  3562. var btoa = _btoa;
  3563. function SourceMap ( properties ) {
  3564. this.version = 3;
  3565. this.file = properties.file;
  3566. this.sources = properties.sources;
  3567. this.sourcesContent = properties.sourcesContent;
  3568. this.names = properties.names;
  3569. this.mappings = properties.mappings;
  3570. }
  3571. SourceMap.prototype = {
  3572. toString: function toString$1 () {
  3573. return JSON.stringify( this );
  3574. },
  3575. toUrl: function toUrl () {
  3576. return 'data:application/json;charset=utf-8;base64,' + btoa( this.toString() );
  3577. }
  3578. };
  3579. function guessIndent ( code ) {
  3580. var lines = code.split( '\n' );
  3581. var tabbed = lines.filter( function ( line ) { return /^\t+/.test( line ); } );
  3582. var spaced = lines.filter( function ( line ) { return /^ {2,}/.test( line ); } );
  3583. if ( tabbed.length === 0 && spaced.length === 0 ) {
  3584. return null;
  3585. }
  3586. // More lines tabbed than spaced? Assume tabs, and
  3587. // default to tabs in the case of a tie (or nothing
  3588. // to go on)
  3589. if ( tabbed.length >= spaced.length ) {
  3590. return '\t';
  3591. }
  3592. // Otherwise, we need to guess the multiple
  3593. var min = spaced.reduce( function ( previous, current ) {
  3594. var numSpaces = /^ +/.exec( current )[0].length;
  3595. return Math.min( numSpaces, previous );
  3596. }, Infinity );
  3597. return new Array( min + 1 ).join( ' ' );
  3598. }
  3599. function getLocator ( source ) {
  3600. var originalLines = source.split( '\n' );
  3601. var start = 0;
  3602. var lineRanges = originalLines.map( function ( line, i ) {
  3603. var end = start + line.length + 1;
  3604. var range = { start: start, end: end, line: i };
  3605. start = end;
  3606. return range;
  3607. });
  3608. var i = 0;
  3609. function rangeContains ( range, index ) {
  3610. return range.start <= index && index < range.end;
  3611. }
  3612. function getLocation ( range, index ) {
  3613. return { line: range.line, column: index - range.start };
  3614. }
  3615. return function locate ( index ) {
  3616. var range = lineRanges[i];
  3617. var d = index >= range.end ? 1 : -1;
  3618. while ( range ) {
  3619. if ( rangeContains( range, index ) ) return getLocation( range, index );
  3620. i += d;
  3621. range = lineRanges[i];
  3622. }
  3623. };
  3624. }
  3625. function encodeMappings ( original, intro, chunk, hires, sourcemapLocations, sourceIndex, offsets, names ) {
  3626. var rawLines = [];
  3627. var generatedCodeLine = intro.split( '\n' ).length - 1;
  3628. var rawSegments = rawLines[ generatedCodeLine ] = [];
  3629. var generatedCodeColumn = 0;
  3630. var locate = getLocator( original );
  3631. function addEdit ( content, original, loc, nameIndex, i ) {
  3632. if ( i || content.length ) {
  3633. rawSegments.push({
  3634. generatedCodeLine: generatedCodeLine,
  3635. generatedCodeColumn: generatedCodeColumn,
  3636. sourceCodeLine: loc.line,
  3637. sourceCodeColumn: loc.column,
  3638. sourceCodeName: nameIndex,
  3639. sourceIndex: sourceIndex
  3640. });
  3641. }
  3642. var lines = content.split( '\n' );
  3643. var lastLine = lines.pop();
  3644. if ( lines.length ) {
  3645. generatedCodeLine += lines.length;
  3646. rawLines[ generatedCodeLine ] = rawSegments = [];
  3647. generatedCodeColumn = lastLine.length;
  3648. } else {
  3649. generatedCodeColumn += lastLine.length;
  3650. }
  3651. lines = original.split( '\n' );
  3652. lastLine = lines.pop();
  3653. if ( lines.length ) {
  3654. loc.line += lines.length;
  3655. loc.column = lastLine.length;
  3656. } else {
  3657. loc.column += lastLine.length;
  3658. }
  3659. }
  3660. function addUneditedChunk ( chunk, loc ) {
  3661. var originalCharIndex = chunk.start;
  3662. var first = true;
  3663. while ( originalCharIndex < chunk.end ) {
  3664. if ( hires || first || sourcemapLocations[ originalCharIndex ] ) {
  3665. rawSegments.push({
  3666. generatedCodeLine: generatedCodeLine,
  3667. generatedCodeColumn: generatedCodeColumn,
  3668. sourceCodeLine: loc.line,
  3669. sourceCodeColumn: loc.column,
  3670. sourceCodeName: -1,
  3671. sourceIndex: sourceIndex
  3672. });
  3673. }
  3674. if ( original[ originalCharIndex ] === '\n' ) {
  3675. loc.line += 1;
  3676. loc.column = 0;
  3677. generatedCodeLine += 1;
  3678. rawLines[ generatedCodeLine ] = rawSegments = [];
  3679. generatedCodeColumn = 0;
  3680. } else {
  3681. loc.column += 1;
  3682. generatedCodeColumn += 1;
  3683. }
  3684. originalCharIndex += 1;
  3685. first = false;
  3686. }
  3687. }
  3688. while ( chunk ) {
  3689. var loc = locate( chunk.start );
  3690. if ( chunk.intro.length ) {
  3691. addEdit( chunk.intro, '', loc, -1, !!chunk.previous );
  3692. }
  3693. if ( chunk.edited ) {
  3694. addEdit( chunk.content, chunk.original, loc, chunk.storeName ? names.indexOf( chunk.original ) : -1, !!chunk.previous );
  3695. } else {
  3696. addUneditedChunk( chunk, loc );
  3697. }
  3698. if ( chunk.outro.length ) {
  3699. addEdit( chunk.outro, '', loc, -1, !!chunk.previous );
  3700. }
  3701. var nextChunk = chunk.next;
  3702. chunk = nextChunk;
  3703. }
  3704. offsets.sourceIndex = offsets.sourceIndex || 0;
  3705. offsets.sourceCodeLine = offsets.sourceCodeLine || 0;
  3706. offsets.sourceCodeColumn = offsets.sourceCodeColumn || 0;
  3707. offsets.sourceCodeName = offsets.sourceCodeName || 0;
  3708. var encoded = rawLines.map( function ( segments ) {
  3709. var generatedCodeColumn = 0;
  3710. return segments.map( function ( segment ) {
  3711. var arr = [
  3712. segment.generatedCodeColumn - generatedCodeColumn,
  3713. segment.sourceIndex - offsets.sourceIndex,
  3714. segment.sourceCodeLine - offsets.sourceCodeLine,
  3715. segment.sourceCodeColumn - offsets.sourceCodeColumn
  3716. ];
  3717. generatedCodeColumn = segment.generatedCodeColumn;
  3718. offsets.sourceIndex = segment.sourceIndex;
  3719. offsets.sourceCodeLine = segment.sourceCodeLine;
  3720. offsets.sourceCodeColumn = segment.sourceCodeColumn;
  3721. if ( ~segment.sourceCodeName ) {
  3722. arr.push( segment.sourceCodeName - offsets.sourceCodeName );
  3723. offsets.sourceCodeName = segment.sourceCodeName;
  3724. }
  3725. return encode( arr );
  3726. }).join( ',' );
  3727. }).join( ';' );
  3728. return encoded;
  3729. }
  3730. function getRelativePath ( from, to ) {
  3731. var fromParts = from.split( /[\/\\]/ );
  3732. var toParts = to.split( /[\/\\]/ );
  3733. fromParts.pop(); // get dirname
  3734. while ( fromParts[0] === toParts[0] ) {
  3735. fromParts.shift();
  3736. toParts.shift();
  3737. }
  3738. if ( fromParts.length ) {
  3739. var i = fromParts.length;
  3740. while ( i-- ) fromParts[i] = '..';
  3741. }
  3742. return fromParts.concat( toParts ).join( '/' );
  3743. }
  3744. var toString$1 = Object.prototype.toString;
  3745. function isObject ( thing ) {
  3746. return toString$1.call( thing ) === '[object Object]';
  3747. }
  3748. function MagicString ( string, options ) {
  3749. if ( options === void 0 ) options = {};
  3750. var chunk = new Chunk( 0, string.length, string );
  3751. Object.defineProperties( this, {
  3752. original: { writable: true, value: string },
  3753. outro: { writable: true, value: '' },
  3754. intro: { writable: true, value: '' },
  3755. firstChunk: { writable: true, value: chunk },
  3756. lastChunk: { writable: true, value: chunk },
  3757. lastSearchedChunk: { writable: true, value: chunk },
  3758. byStart: { writable: true, value: {} },
  3759. byEnd: { writable: true, value: {} },
  3760. filename: { writable: true, value: options.filename },
  3761. indentExclusionRanges: { writable: true, value: options.indentExclusionRanges },
  3762. sourcemapLocations: { writable: true, value: {} },
  3763. storedNames: { writable: true, value: {} },
  3764. indentStr: { writable: true, value: guessIndent( string ) }
  3765. });
  3766. this.byStart[ 0 ] = chunk;
  3767. this.byEnd[ string.length ] = chunk;
  3768. }
  3769. MagicString.prototype = {
  3770. addSourcemapLocation: function addSourcemapLocation ( char ) {
  3771. this.sourcemapLocations[ char ] = true;
  3772. },
  3773. append: function append ( content ) {
  3774. if ( typeof content !== 'string' ) throw new TypeError( 'outro content must be a string' );
  3775. this.outro += content;
  3776. return this;
  3777. },
  3778. clone: function clone () {
  3779. var cloned = new MagicString( this.original, { filename: this.filename });
  3780. var originalChunk = this.firstChunk;
  3781. var clonedChunk = cloned.firstChunk = cloned.lastSearchedChunk = originalChunk.clone();
  3782. while ( originalChunk ) {
  3783. cloned.byStart[ clonedChunk.start ] = clonedChunk;
  3784. cloned.byEnd[ clonedChunk.end ] = clonedChunk;
  3785. var nextOriginalChunk = originalChunk.next;
  3786. var nextClonedChunk = nextOriginalChunk && nextOriginalChunk.clone();
  3787. if ( nextClonedChunk ) {
  3788. clonedChunk.next = nextClonedChunk;
  3789. nextClonedChunk.previous = clonedChunk;
  3790. clonedChunk = nextClonedChunk;
  3791. }
  3792. originalChunk = nextOriginalChunk;
  3793. }
  3794. cloned.lastChunk = clonedChunk;
  3795. if ( this.indentExclusionRanges ) {
  3796. cloned.indentExclusionRanges = typeof this.indentExclusionRanges[0] === 'number' ?
  3797. [ this.indentExclusionRanges[0], this.indentExclusionRanges[1] ] :
  3798. this.indentExclusionRanges.map( function ( range ) { return [ range.start, range.end ]; } );
  3799. }
  3800. Object.keys( this.sourcemapLocations ).forEach( function ( loc ) {
  3801. cloned.sourcemapLocations[ loc ] = true;
  3802. });
  3803. return cloned;
  3804. },
  3805. generateMap: function generateMap ( options ) {
  3806. options = options || {};
  3807. var names = Object.keys( this.storedNames );
  3808. var map = new SourceMap({
  3809. file: ( options.file ? options.file.split( /[\/\\]/ ).pop() : null ),
  3810. sources: [ options.source ? getRelativePath( options.file || '', options.source ) : null ],
  3811. sourcesContent: options.includeContent ? [ this.original ] : [ null ],
  3812. names: names,
  3813. mappings: this.getMappings( options.hires, 0, {}, names )
  3814. });
  3815. return map;
  3816. },
  3817. getIndentString: function getIndentString () {
  3818. return this.indentStr === null ? '\t' : this.indentStr;
  3819. },
  3820. getMappings: function getMappings ( hires, sourceIndex, offsets, names ) {
  3821. return encodeMappings( this.original, this.intro, this.firstChunk, hires, this.sourcemapLocations, sourceIndex, offsets, names );
  3822. },
  3823. indent: function indent ( indentStr, options ) {
  3824. var this$1 = this;
  3825. var pattern = /^[^\r\n]/gm;
  3826. if ( isObject( indentStr ) ) {
  3827. options = indentStr;
  3828. indentStr = undefined;
  3829. }
  3830. indentStr = indentStr !== undefined ? indentStr : ( this.indentStr || '\t' );
  3831. if ( indentStr === '' ) return this; // noop
  3832. options = options || {};
  3833. // Process exclusion ranges
  3834. var isExcluded = {};
  3835. if ( options.exclude ) {
  3836. var exclusions = typeof options.exclude[0] === 'number' ? [ options.exclude ] : options.exclude;
  3837. exclusions.forEach( function ( exclusion ) {
  3838. for ( var i = exclusion[0]; i < exclusion[1]; i += 1 ) {
  3839. isExcluded[i] = true;
  3840. }
  3841. });
  3842. }
  3843. var shouldIndentNextCharacter = options.indentStart !== false;
  3844. var replacer = function ( match ) {
  3845. if ( shouldIndentNextCharacter ) return ("" + indentStr + match);
  3846. shouldIndentNextCharacter = true;
  3847. return match;
  3848. };
  3849. this.intro = this.intro.replace( pattern, replacer );
  3850. var charIndex = 0;
  3851. var chunk = this.firstChunk;
  3852. while ( chunk ) {
  3853. var end = chunk.end;
  3854. if ( chunk.edited ) {
  3855. if ( !isExcluded[ charIndex ] ) {
  3856. chunk.content = chunk.content.replace( pattern, replacer );
  3857. if ( chunk.content.length ) {
  3858. shouldIndentNextCharacter = chunk.content[ chunk.content.length - 1 ] === '\n';
  3859. }
  3860. }
  3861. } else {
  3862. charIndex = chunk.start;
  3863. while ( charIndex < end ) {
  3864. if ( !isExcluded[ charIndex ] ) {
  3865. var char = this$1.original[ charIndex ];
  3866. if ( char === '\n' ) {
  3867. shouldIndentNextCharacter = true;
  3868. } else if ( char !== '\r' && shouldIndentNextCharacter ) {
  3869. shouldIndentNextCharacter = false;
  3870. if ( charIndex === chunk.start ) {
  3871. chunk.prepend( indentStr );
  3872. } else {
  3873. var rhs = chunk.split( charIndex );
  3874. rhs.prepend( indentStr );
  3875. this$1.byStart[ charIndex ] = rhs;
  3876. this$1.byEnd[ charIndex ] = chunk;
  3877. chunk = rhs;
  3878. }
  3879. }
  3880. }
  3881. charIndex += 1;
  3882. }
  3883. }
  3884. charIndex = chunk.end;
  3885. chunk = chunk.next;
  3886. }
  3887. this.outro = this.outro.replace( pattern, replacer );
  3888. return this;
  3889. },
  3890. insert: function insert () {
  3891. throw new Error( 'magicString.insert(...) is deprecated. Use insertRight(...) or insertLeft(...)' );
  3892. },
  3893. insertLeft: function insertLeft ( index, content ) {
  3894. if ( typeof content !== 'string' ) throw new TypeError( 'inserted content must be a string' );
  3895. this._split( index );
  3896. var chunk = this.byEnd[ index ];
  3897. if ( chunk ) {
  3898. chunk.append( content );
  3899. } else {
  3900. this.intro += content;
  3901. }
  3902. return this;
  3903. },
  3904. insertRight: function insertRight ( index, content ) {
  3905. if ( typeof content !== 'string' ) throw new TypeError( 'inserted content must be a string' );
  3906. this._split( index );
  3907. var chunk = this.byStart[ index ];
  3908. if ( chunk ) {
  3909. chunk.prepend( content );
  3910. } else {
  3911. this.outro += content;
  3912. }
  3913. return this;
  3914. },
  3915. move: function move ( start, end, index ) {
  3916. if ( index >= start && index <= end ) throw new Error( 'Cannot move a selection inside itself' );
  3917. this._split( start );
  3918. this._split( end );
  3919. this._split( index );
  3920. var first = this.byStart[ start ];
  3921. var last = this.byEnd[ end ];
  3922. var oldLeft = first.previous;
  3923. var oldRight = last.next;
  3924. var newRight = this.byStart[ index ];
  3925. if ( !newRight && last === this.lastChunk ) return this;
  3926. var newLeft = newRight ? newRight.previous : this.lastChunk;
  3927. if ( oldLeft ) oldLeft.next = oldRight;
  3928. if ( oldRight ) oldRight.previous = oldLeft;
  3929. if ( newLeft ) newLeft.next = first;
  3930. if ( newRight ) newRight.previous = last;
  3931. if ( !first.previous ) this.firstChunk = last.next;
  3932. if ( !last.next ) {
  3933. this.lastChunk = first.previous;
  3934. this.lastChunk.next = null;
  3935. }
  3936. first.previous = newLeft;
  3937. last.next = newRight;
  3938. if ( !newLeft ) this.firstChunk = first;
  3939. if ( !newRight ) this.lastChunk = last;
  3940. return this;
  3941. },
  3942. overwrite: function overwrite ( start, end, content, storeName ) {
  3943. var this$1 = this;
  3944. if ( typeof content !== 'string' ) throw new TypeError( 'replacement content must be a string' );
  3945. while ( start < 0 ) start += this$1.original.length;
  3946. while ( end < 0 ) end += this$1.original.length;
  3947. if ( end > this.original.length ) throw new Error( 'end is out of bounds' );
  3948. if ( start === end ) throw new Error( 'Cannot overwrite a zero-length range – use insertLeft or insertRight instead' );
  3949. this._split( start );
  3950. this._split( end );
  3951. if ( storeName ) {
  3952. var original = this.original.slice( start, end );
  3953. this.storedNames[ original ] = true;
  3954. }
  3955. var first = this.byStart[ start ];
  3956. var last = this.byEnd[ end ];
  3957. if ( first ) {
  3958. first.edit( content, storeName );
  3959. if ( first !== last ) {
  3960. first.outro = '';
  3961. var chunk = first.next;
  3962. while ( chunk !== last ) {
  3963. chunk.edit( '', false );
  3964. chunk.intro = chunk.outro = '';
  3965. chunk = chunk.next;
  3966. }
  3967. chunk.edit( '', false );
  3968. chunk.intro = '';
  3969. }
  3970. }
  3971. else {
  3972. // must be inserting at the end
  3973. var newChunk = new Chunk( start, end, '' ).edit( content, storeName );
  3974. // TODO last chunk in the array may not be the last chunk, if it's moved...
  3975. last.next = newChunk;
  3976. newChunk.previous = last;
  3977. }
  3978. return this;
  3979. },
  3980. prepend: function prepend ( content ) {
  3981. if ( typeof content !== 'string' ) throw new TypeError( 'outro content must be a string' );
  3982. this.intro = content + this.intro;
  3983. return this;
  3984. },
  3985. remove: function remove ( start, end ) {
  3986. var this$1 = this;
  3987. while ( start < 0 ) start += this$1.original.length;
  3988. while ( end < 0 ) end += this$1.original.length;
  3989. if ( start === end ) return this;
  3990. if ( start < 0 || end > this.original.length ) throw new Error( 'Character is out of bounds' );
  3991. if ( start > end ) throw new Error( 'end must be greater than start' );
  3992. return this.overwrite( start, end, '', false );
  3993. },
  3994. slice: function slice ( start, end ) {
  3995. var this$1 = this;
  3996. if ( start === void 0 ) start = 0;
  3997. if ( end === void 0 ) end = this.original.length;
  3998. while ( start < 0 ) start += this$1.original.length;
  3999. while ( end < 0 ) end += this$1.original.length;
  4000. var result = '';
  4001. // find start chunk
  4002. var chunk = this.firstChunk;
  4003. while ( chunk && ( chunk.start > start || chunk.end <= start ) ) {
  4004. // found end chunk before start
  4005. if ( chunk.start < end && chunk.end >= end ) {
  4006. return result;
  4007. }
  4008. chunk = chunk.next;
  4009. }
  4010. if ( chunk && chunk.edited && chunk.start !== start ) throw new Error(("Cannot use replaced character " + start + " as slice start anchor."));
  4011. var startChunk = chunk;
  4012. while ( chunk ) {
  4013. if ( chunk.intro && ( startChunk !== chunk || chunk.start === start ) ) {
  4014. result += chunk.intro;
  4015. }
  4016. var containsEnd = chunk.start < end && chunk.end >= end;
  4017. if ( containsEnd && chunk.edited && chunk.end !== end ) throw new Error(("Cannot use replaced character " + end + " as slice end anchor."));
  4018. var sliceStart = startChunk === chunk ? start - chunk.start : 0;
  4019. var sliceEnd = containsEnd ? chunk.content.length + end - chunk.end : chunk.content.length;
  4020. result += chunk.content.slice( sliceStart, sliceEnd );
  4021. if ( chunk.outro && ( !containsEnd || chunk.end === end ) ) {
  4022. result += chunk.outro;
  4023. }
  4024. if ( containsEnd ) {
  4025. break;
  4026. }
  4027. chunk = chunk.next;
  4028. }
  4029. return result;
  4030. },
  4031. // TODO deprecate this? not really very useful
  4032. snip: function snip ( start, end ) {
  4033. var clone = this.clone();
  4034. clone.remove( 0, start );
  4035. clone.remove( end, clone.original.length );
  4036. return clone;
  4037. },
  4038. _split: function _split ( index ) {
  4039. var this$1 = this;
  4040. if ( this.byStart[ index ] || this.byEnd[ index ] ) return;
  4041. var chunk = this.lastSearchedChunk;
  4042. var searchForward = index > chunk.end;
  4043. while ( true ) {
  4044. if ( chunk.contains( index ) ) return this$1._splitChunk( chunk, index );
  4045. chunk = searchForward ?
  4046. this$1.byStart[ chunk.end ] :
  4047. this$1.byEnd[ chunk.start ];
  4048. }
  4049. },
  4050. _splitChunk: function _splitChunk ( chunk, index ) {
  4051. if ( chunk.edited && chunk.content.length ) { // zero-length edited chunks are a special case (overlapping replacements)
  4052. var loc = getLocator( this.original )( index );
  4053. throw new Error( ("Cannot split a chunk that has already been edited (" + (loc.line) + ":" + (loc.column) + " – \"" + (chunk.original) + "\")") );
  4054. }
  4055. var newChunk = chunk.split( index );
  4056. this.byEnd[ index ] = chunk;
  4057. this.byStart[ index ] = newChunk;
  4058. this.byEnd[ newChunk.end ] = newChunk;
  4059. if ( chunk === this.lastChunk ) this.lastChunk = newChunk;
  4060. this.lastSearchedChunk = chunk;
  4061. return true;
  4062. },
  4063. toString: function toString$1 () {
  4064. var str = this.intro;
  4065. var chunk = this.firstChunk;
  4066. while ( chunk ) {
  4067. str += chunk.toString();
  4068. chunk = chunk.next;
  4069. }
  4070. return str + this.outro;
  4071. },
  4072. trimLines: function trimLines () {
  4073. return this.trim('[\\r\\n]');
  4074. },
  4075. trim: function trim ( charType ) {
  4076. return this.trimStart( charType ).trimEnd( charType );
  4077. },
  4078. trimEnd: function trimEnd ( charType ) {
  4079. var this$1 = this;
  4080. var rx = new RegExp( ( charType || '\\s' ) + '+$' );
  4081. this.outro = this.outro.replace( rx, '' );
  4082. if ( this.outro.length ) return this;
  4083. var chunk = this.lastChunk;
  4084. do {
  4085. var end = chunk.end;
  4086. var aborted = chunk.trimEnd( rx );
  4087. // if chunk was trimmed, we have a new lastChunk
  4088. if ( chunk.end !== end ) {
  4089. this$1.lastChunk = chunk.next;
  4090. this$1.byEnd[ chunk.end ] = chunk;
  4091. this$1.byStart[ chunk.next.start ] = chunk.next;
  4092. }
  4093. if ( aborted ) return this$1;
  4094. chunk = chunk.previous;
  4095. } while ( chunk );
  4096. return this;
  4097. },
  4098. trimStart: function trimStart ( charType ) {
  4099. var this$1 = this;
  4100. var rx = new RegExp( '^' + ( charType || '\\s' ) + '+' );
  4101. this.intro = this.intro.replace( rx, '' );
  4102. if ( this.intro.length ) return this;
  4103. var chunk = this.firstChunk;
  4104. do {
  4105. var end = chunk.end;
  4106. var aborted = chunk.trimStart( rx );
  4107. if ( chunk.end !== end ) {
  4108. // special case...
  4109. if ( chunk === this$1.lastChunk ) this$1.lastChunk = chunk.next;
  4110. this$1.byEnd[ chunk.end ] = chunk;
  4111. this$1.byStart[ chunk.next.start ] = chunk.next;
  4112. }
  4113. if ( aborted ) return this$1;
  4114. chunk = chunk.next;
  4115. } while ( chunk );
  4116. return this;
  4117. }
  4118. };
  4119. var hasOwnProp = Object.prototype.hasOwnProperty;
  4120. function Bundle ( options ) {
  4121. if ( options === void 0 ) options = {};
  4122. this.intro = options.intro || '';
  4123. this.separator = options.separator !== undefined ? options.separator : '\n';
  4124. this.sources = [];
  4125. this.uniqueSources = [];
  4126. this.uniqueSourceIndexByFilename = {};
  4127. }
  4128. Bundle.prototype = {
  4129. addSource: function addSource ( source ) {
  4130. if ( source instanceof MagicString ) {
  4131. return this.addSource({
  4132. content: source,
  4133. filename: source.filename,
  4134. separator: this.separator
  4135. });
  4136. }
  4137. if ( !isObject( source ) || !source.content ) {
  4138. throw new Error( 'bundle.addSource() takes an object with a `content` property, which should be an instance of MagicString, and an optional `filename`' );
  4139. }
  4140. [ 'filename', 'indentExclusionRanges', 'separator' ].forEach( function ( option ) {
  4141. if ( !hasOwnProp.call( source, option ) ) source[ option ] = source.content[ option ];
  4142. });
  4143. if ( source.separator === undefined ) { // TODO there's a bunch of this sort of thing, needs cleaning up
  4144. source.separator = this.separator;
  4145. }
  4146. if ( source.filename ) {
  4147. if ( !hasOwnProp.call( this.uniqueSourceIndexByFilename, source.filename ) ) {
  4148. this.uniqueSourceIndexByFilename[ source.filename ] = this.uniqueSources.length;
  4149. this.uniqueSources.push({ filename: source.filename, content: source.content.original });
  4150. } else {
  4151. var uniqueSource = this.uniqueSources[ this.uniqueSourceIndexByFilename[ source.filename ] ];
  4152. if ( source.content.original !== uniqueSource.content ) {
  4153. throw new Error( ("Illegal source: same filename (" + (source.filename) + "), different contents") );
  4154. }
  4155. }
  4156. }
  4157. this.sources.push( source );
  4158. return this;
  4159. },
  4160. append: function append ( str, options ) {
  4161. this.addSource({
  4162. content: new MagicString( str ),
  4163. separator: ( options && options.separator ) || ''
  4164. });
  4165. return this;
  4166. },
  4167. clone: function clone () {
  4168. var bundle = new Bundle({
  4169. intro: this.intro,
  4170. separator: this.separator
  4171. });
  4172. this.sources.forEach( function ( source ) {
  4173. bundle.addSource({
  4174. filename: source.filename,
  4175. content: source.content.clone(),
  4176. separator: source.separator
  4177. });
  4178. });
  4179. return bundle;
  4180. },
  4181. generateMap: function generateMap ( options ) {
  4182. var this$1 = this;
  4183. var offsets = {};
  4184. var names = [];
  4185. this.sources.forEach( function ( source ) {
  4186. Object.keys( source.content.storedNames ).forEach( function ( name ) {
  4187. if ( !~names.indexOf( name ) ) names.push( name );
  4188. });
  4189. });
  4190. var encoded = (
  4191. getSemis( this.intro ) +
  4192. this.sources.map( function ( source, i ) {
  4193. var prefix = ( i > 0 ) ? ( getSemis( source.separator ) || ',' ) : '';
  4194. var mappings;
  4195. // we don't bother encoding sources without a filename
  4196. if ( !source.filename ) {
  4197. mappings = getSemis( source.content.toString() );
  4198. } else {
  4199. var sourceIndex = this$1.uniqueSourceIndexByFilename[ source.filename ];
  4200. mappings = source.content.getMappings( options.hires, sourceIndex, offsets, names );
  4201. }
  4202. return prefix + mappings;
  4203. }).join( '' )
  4204. );
  4205. return new SourceMap({
  4206. file: ( options.file ? options.file.split( /[\/\\]/ ).pop() : null ),
  4207. sources: this.uniqueSources.map( function ( source ) {
  4208. return options.file ? getRelativePath( options.file, source.filename ) : source.filename;
  4209. }),
  4210. sourcesContent: this.uniqueSources.map( function ( source ) {
  4211. return options.includeContent ? source.content : null;
  4212. }),
  4213. names: names,
  4214. mappings: encoded
  4215. });
  4216. },
  4217. getIndentString: function getIndentString () {
  4218. var indentStringCounts = {};
  4219. this.sources.forEach( function ( source ) {
  4220. var indentStr = source.content.indentStr;
  4221. if ( indentStr === null ) return;
  4222. if ( !indentStringCounts[ indentStr ] ) indentStringCounts[ indentStr ] = 0;
  4223. indentStringCounts[ indentStr ] += 1;
  4224. });
  4225. return ( Object.keys( indentStringCounts ).sort( function ( a, b ) {
  4226. return indentStringCounts[a] - indentStringCounts[b];
  4227. })[0] ) || '\t';
  4228. },
  4229. indent: function indent ( indentStr ) {
  4230. var this$1 = this;
  4231. if ( !arguments.length ) {
  4232. indentStr = this.getIndentString();
  4233. }
  4234. if ( indentStr === '' ) return this; // noop
  4235. var trailingNewline = !this.intro || this.intro.slice( -1 ) === '\n';
  4236. this.sources.forEach( function ( source, i ) {
  4237. var separator = source.separator !== undefined ? source.separator : this$1.separator;
  4238. var indentStart = trailingNewline || ( i > 0 && /\r?\n$/.test( separator ) );
  4239. source.content.indent( indentStr, {
  4240. exclude: source.indentExclusionRanges,
  4241. indentStart: indentStart//: trailingNewline || /\r?\n$/.test( separator ) //true///\r?\n/.test( separator )
  4242. });
  4243. // TODO this is a very slow way to determine this
  4244. trailingNewline = source.content.toString().slice( 0, -1 ) === '\n';
  4245. });
  4246. if ( this.intro ) {
  4247. this.intro = indentStr + this.intro.replace( /^[^\n]/gm, function ( match, index ) {
  4248. return index > 0 ? indentStr + match : match;
  4249. });
  4250. }
  4251. return this;
  4252. },
  4253. prepend: function prepend ( str ) {
  4254. this.intro = str + this.intro;
  4255. return this;
  4256. },
  4257. toString: function toString$1 () {
  4258. var this$1 = this;
  4259. var body = this.sources.map( function ( source, i ) {
  4260. var separator = source.separator !== undefined ? source.separator : this$1.separator;
  4261. var str = ( i > 0 ? separator : '' ) + source.content.toString();
  4262. return str;
  4263. }).join( '' );
  4264. return this.intro + body;
  4265. },
  4266. trimLines: function trimLines () {
  4267. return this.trim('[\\r\\n]');
  4268. },
  4269. trim: function trim ( charType ) {
  4270. return this.trimStart( charType ).trimEnd( charType );
  4271. },
  4272. trimStart: function trimStart ( charType ) {
  4273. var this$1 = this;
  4274. var rx = new RegExp( '^' + ( charType || '\\s' ) + '+' );
  4275. this.intro = this.intro.replace( rx, '' );
  4276. if ( !this.intro ) {
  4277. var source;
  4278. var i = 0;
  4279. do {
  4280. source = this$1.sources[i];
  4281. if ( !source ) {
  4282. break;
  4283. }
  4284. source.content.trimStart( charType );
  4285. i += 1;
  4286. } while ( source.content.toString() === '' ); // TODO faster way to determine non-empty source?
  4287. }
  4288. return this;
  4289. },
  4290. trimEnd: function trimEnd ( charType ) {
  4291. var this$1 = this;
  4292. var rx = new RegExp( ( charType || '\\s' ) + '+$' );
  4293. var source;
  4294. var i = this.sources.length - 1;
  4295. do {
  4296. source = this$1.sources[i];
  4297. if ( !source ) {
  4298. this$1.intro = this$1.intro.replace( rx, '' );
  4299. break;
  4300. }
  4301. source.content.trimEnd( charType );
  4302. i -= 1;
  4303. } while ( source.content.toString() === '' ); // TODO faster way to determine non-empty source?
  4304. return this;
  4305. }
  4306. };
  4307. function getSemis ( str ) {
  4308. return new Array( str.split( '\n' ).length ).join( ';' );
  4309. }
  4310. MagicString.Bundle = Bundle;
  4311. var keys = {
  4312. Program: [ 'body' ],
  4313. Literal: []
  4314. };
  4315. // used for debugging, without the noise created by
  4316. // circular references
  4317. function toJSON ( node ) {
  4318. var obj = {};
  4319. Object.keys( node ).forEach( function ( key ) {
  4320. if ( key === 'parent' || key === 'program' || key === 'keys' || key === '__wrapped' ) return;
  4321. if ( Array.isArray( node[ key ] ) ) {
  4322. obj[ key ] = node[ key ].map( toJSON );
  4323. } else if ( node[ key ] && node[ key ].toJSON ) {
  4324. obj[ key ] = node[ key ].toJSON();
  4325. } else {
  4326. obj[ key ] = node[ key ];
  4327. }
  4328. });
  4329. return obj;
  4330. }
  4331. var Node = function Node ( raw, parent ) {
  4332. raw.parent = parent;
  4333. raw.program = parent.program || parent;
  4334. raw.depth = parent.depth + 1;
  4335. raw.keys = keys[ raw.type ];
  4336. raw.indentation = undefined;
  4337. for ( var i = 0, list = keys[ raw.type ]; i < list.length; i += 1 ) {
  4338. var key = list[i];
  4339. wrap( raw[ key ], raw );
  4340. }
  4341. raw.program.magicString.addSourcemapLocation( raw.start );
  4342. raw.program.magicString.addSourcemapLocation( raw.end );
  4343. };
  4344. Node.prototype.ancestor = function ancestor ( level ) {
  4345. var node = this;
  4346. while ( level-- ) {
  4347. node = node.parent;
  4348. if ( !node ) return null;
  4349. }
  4350. return node;
  4351. };
  4352. Node.prototype.contains = function contains ( node ) {
  4353. var this$1 = this;
  4354. while ( node ) {
  4355. if ( node === this$1 ) return true;
  4356. node = node.parent;
  4357. }
  4358. return false;
  4359. };
  4360. Node.prototype.findLexicalBoundary = function findLexicalBoundary () {
  4361. return this.parent.findLexicalBoundary();
  4362. };
  4363. Node.prototype.findNearest = function findNearest ( type ) {
  4364. if ( typeof type === 'string' ) type = new RegExp( ("^" + type + "$") );
  4365. if ( type.test( this.type ) ) return this;
  4366. return this.parent.findNearest( type );
  4367. };
  4368. Node.prototype.findScope = function findScope ( functionScope ) {
  4369. return this.parent.findScope( functionScope );
  4370. };
  4371. Node.prototype.getIndentation = function getIndentation () {
  4372. return this.parent.getIndentation();
  4373. };
  4374. Node.prototype.initialise = function initialise ( transforms ) {
  4375. for ( var i = 0, list = this.keys; i < list.length; i += 1 ) {
  4376. var key = list[i];
  4377. var value = this[ key ];
  4378. if ( Array.isArray( value ) ) {
  4379. value.forEach( function ( node ) { return node && node.initialise( transforms ); } );
  4380. } else if ( value && typeof value === 'object' ) {
  4381. value.initialise( transforms );
  4382. }
  4383. }
  4384. };
  4385. Node.prototype.toJSON = function toJSON$1 () {
  4386. return toJSON( this );
  4387. };
  4388. Node.prototype.toString = function toString () {
  4389. return this.program.magicString.original.slice( this.start, this.end );
  4390. };
  4391. Node.prototype.transpile = function transpile ( code, transforms ) {
  4392. for ( var i = 0, list = this.keys; i < list.length; i += 1 ) {
  4393. var key = list[i];
  4394. var value = this[ key ];
  4395. if ( Array.isArray( value ) ) {
  4396. value.forEach( function ( node ) { return node && node.transpile( code, transforms ); } );
  4397. } else if ( value && typeof value === 'object' ) {
  4398. value.transpile( code, transforms );
  4399. }
  4400. }
  4401. };
  4402. function isArguments ( node ) {
  4403. return node.type === 'Identifier' && node.name === 'arguments';
  4404. }
  4405. function spread ( code, elements, start, argumentsArrayAlias, isNew ) {
  4406. var i = elements.length;
  4407. var firstSpreadIndex = -1;
  4408. while ( i-- ) {
  4409. var element$1 = elements[i];
  4410. if ( element$1 && element$1.type === 'SpreadElement' ) {
  4411. if ( isArguments( element$1.argument ) ) {
  4412. code.overwrite( element$1.argument.start, element$1.argument.end, argumentsArrayAlias );
  4413. }
  4414. firstSpreadIndex = i;
  4415. }
  4416. }
  4417. if ( firstSpreadIndex === -1 ) return false; // false indicates no spread elements
  4418. if (isNew) {
  4419. for ( i = 0; i < elements.length; i += 1 ) {
  4420. var element$2 = elements[i];
  4421. if ( element$2.type === 'SpreadElement' ) {
  4422. code.remove( element$2.start, element$2.argument.start );
  4423. } else {
  4424. code.insertRight( element$2.start, '[' );
  4425. code.insertRight( element$2.end, ']' );
  4426. }
  4427. }
  4428. return true; // true indicates some spread elements
  4429. }
  4430. var element = elements[ firstSpreadIndex ];
  4431. var previousElement = elements[ firstSpreadIndex - 1 ];
  4432. if ( !previousElement ) {
  4433. code.remove( start, element.start );
  4434. code.overwrite( element.end, elements[1].start, '.concat( ' );
  4435. } else {
  4436. code.overwrite( previousElement.end, element.start, ' ].concat( ' );
  4437. }
  4438. for ( i = firstSpreadIndex; i < elements.length; i += 1 ) {
  4439. element = elements[i];
  4440. if ( element ) {
  4441. if ( element.type === 'SpreadElement' ) {
  4442. code.remove( element.start, element.argument.start );
  4443. } else {
  4444. code.insertLeft( element.start, '[' );
  4445. code.insertLeft( element.end, ']' );
  4446. }
  4447. }
  4448. }
  4449. return true; // true indicates some spread elements
  4450. }
  4451. var ArrayExpression = (function (Node$$1) {
  4452. function ArrayExpression () {
  4453. Node$$1.apply(this, arguments);
  4454. }
  4455. if ( Node$$1 ) ArrayExpression.__proto__ = Node$$1;
  4456. ArrayExpression.prototype = Object.create( Node$$1 && Node$$1.prototype );
  4457. ArrayExpression.prototype.constructor = ArrayExpression;
  4458. ArrayExpression.prototype.initialise = function initialise ( transforms ) {
  4459. var this$1 = this;
  4460. if ( transforms.spreadRest && this.elements.length ) {
  4461. var lexicalBoundary = this.findLexicalBoundary();
  4462. var i = this.elements.length;
  4463. while ( i-- ) {
  4464. var element = this$1.elements[i];
  4465. if ( element && element.type === 'SpreadElement' && isArguments( element.argument ) ) {
  4466. this$1.argumentsArrayAlias = lexicalBoundary.getArgumentsArrayAlias();
  4467. }
  4468. }
  4469. }
  4470. Node$$1.prototype.initialise.call( this, transforms );
  4471. };
  4472. ArrayExpression.prototype.transpile = function transpile ( code, transforms ) {
  4473. if ( transforms.spreadRest ) {
  4474. // erase trailing comma after last array element if not an array hole
  4475. if ( this.elements.length ) {
  4476. var lastElement = this.elements[ this.elements.length - 1 ];
  4477. if ( lastElement && /\s*,/.test( code.original.slice( lastElement.end, this.end ) ) ) {
  4478. code.overwrite( lastElement.end, this.end - 1, ' ' );
  4479. }
  4480. }
  4481. if ( this.elements.length === 1 ) {
  4482. var element = this.elements[0];
  4483. if ( element && element.type === 'SpreadElement' ) {
  4484. // special case – [ ...arguments ]
  4485. if ( isArguments( element.argument ) ) {
  4486. code.overwrite( this.start, this.end, ("[].concat( " + (this.argumentsArrayAlias) + " )") ); // TODO if this is the only use of argsArray, don't bother concating
  4487. } else {
  4488. code.overwrite( this.start, element.argument.start, '[].concat( ' );
  4489. code.overwrite( element.end, this.end, ' )' );
  4490. }
  4491. }
  4492. }
  4493. else {
  4494. var hasSpreadElements = spread( code, this.elements, this.start, this.argumentsArrayAlias );
  4495. if ( hasSpreadElements ) {
  4496. code.overwrite( this.end - 1, this.end, ')' );
  4497. }
  4498. }
  4499. }
  4500. Node$$1.prototype.transpile.call( this, code, transforms );
  4501. };
  4502. return ArrayExpression;
  4503. }(Node));
  4504. var ArrowFunctionExpression = (function (Node$$1) {
  4505. function ArrowFunctionExpression () {
  4506. Node$$1.apply(this, arguments);
  4507. }
  4508. if ( Node$$1 ) ArrowFunctionExpression.__proto__ = Node$$1;
  4509. ArrowFunctionExpression.prototype = Object.create( Node$$1 && Node$$1.prototype );
  4510. ArrowFunctionExpression.prototype.constructor = ArrowFunctionExpression;
  4511. ArrowFunctionExpression.prototype.initialise = function initialise ( transforms ) {
  4512. this.body.createScope();
  4513. Node$$1.prototype.initialise.call( this, transforms );
  4514. };
  4515. ArrowFunctionExpression.prototype.transpile = function transpile ( code, transforms ) {
  4516. if ( transforms.arrow ) {
  4517. // remove arrow
  4518. var charIndex = this.body.start;
  4519. while ( code.original[ charIndex ] !== '=' ) {
  4520. charIndex -= 1;
  4521. }
  4522. code.remove( charIndex, this.body.start );
  4523. // wrap naked parameter
  4524. if ( this.params.length === 1 && this.start === this.params[0].start ) {
  4525. code.insertRight( this.params[0].start, '(' );
  4526. code.insertLeft( this.params[0].end, ')' );
  4527. }
  4528. // add function
  4529. if ( this.parent && this.parent.type === 'ExpressionStatement' ) {
  4530. // standalone expression statement
  4531. code.insertRight( this.start, '(function' );
  4532. code.insertRight( this.end, ')' );
  4533. } else {
  4534. code.insertRight( this.start, 'function ' );
  4535. }
  4536. }
  4537. Node$$1.prototype.transpile.call( this, code, transforms );
  4538. };
  4539. return ArrowFunctionExpression;
  4540. }(Node));
  4541. function locate$1 ( source, index ) {
  4542. var lines = source.split( '\n' );
  4543. var len = lines.length;
  4544. var lineStart = 0;
  4545. var i;
  4546. for ( i = 0; i < len; i += 1 ) {
  4547. var line = lines[i];
  4548. var lineEnd = lineStart + line.length + 1; // +1 for newline
  4549. if ( lineEnd > index ) {
  4550. return { line: i + 1, column: index - lineStart, char: i };
  4551. }
  4552. lineStart = lineEnd;
  4553. }
  4554. throw new Error( 'Could not determine location of character' );
  4555. }
  4556. function pad ( num, len ) {
  4557. var result = String( num );
  4558. return result + repeat( ' ', len - result.length );
  4559. }
  4560. function repeat ( str, times ) {
  4561. var result = '';
  4562. while ( times-- ) result += str;
  4563. return result;
  4564. }
  4565. function getSnippet ( source, loc, length ) {
  4566. if ( length === void 0 ) length = 1;
  4567. var first = Math.max( loc.line - 5, 0 );
  4568. var last = loc.line;
  4569. var numDigits = String( last ).length;
  4570. var lines = source.split( '\n' ).slice( first, last );
  4571. var lastLine = lines[ lines.length - 1 ];
  4572. var offset = lastLine.slice( 0, loc.column ).replace( /\t/g, ' ' ).length;
  4573. var snippet = lines
  4574. .map( function ( line, i ) { return ((pad( i + first + 1, numDigits )) + " : " + (line.replace( /\t/g, ' '))); } )
  4575. .join( '\n' );
  4576. snippet += '\n' + repeat( ' ', numDigits + 3 + offset ) + repeat( '^', length );
  4577. return snippet;
  4578. }
  4579. var CompileError = (function (Error) {
  4580. function CompileError ( node, message ) {
  4581. Error.call(this);
  4582. var source = node.program.magicString.original;
  4583. var loc = locate$1( source, node.start );
  4584. this.name = 'CompileError';
  4585. this.message = message + " (" + (loc.line) + ":" + (loc.column) + ")";
  4586. this.stack = new Error().stack.replace( new RegExp( (".+new " + (this.name) + ".+\\n"), 'm' ), '' );
  4587. this.loc = loc;
  4588. this.snippet = getSnippet( source, loc, node.end - node.start );
  4589. }
  4590. if ( Error ) CompileError.__proto__ = Error;
  4591. CompileError.prototype = Object.create( Error && Error.prototype );
  4592. CompileError.prototype.constructor = CompileError;
  4593. CompileError.prototype.toString = function toString () {
  4594. return ((this.name) + ": " + (this.message) + "\n" + (this.snippet));
  4595. };
  4596. return CompileError;
  4597. }(Error));
  4598. var AssignmentExpression = (function (Node$$1) {
  4599. function AssignmentExpression () {
  4600. Node$$1.apply(this, arguments);
  4601. }
  4602. if ( Node$$1 ) AssignmentExpression.__proto__ = Node$$1;
  4603. AssignmentExpression.prototype = Object.create( Node$$1 && Node$$1.prototype );
  4604. AssignmentExpression.prototype.constructor = AssignmentExpression;
  4605. AssignmentExpression.prototype.initialise = function initialise ( transforms ) {
  4606. if ( this.left.type === 'Identifier' ) {
  4607. var declaration = this.findScope( false ).findDeclaration( this.left.name );
  4608. if ( declaration && declaration.kind === 'const' ) {
  4609. throw new CompileError( this.left, ((this.left.name) + " is read-only") );
  4610. }
  4611. // special case – https://gitlab.com/Rich-Harris/buble/issues/11
  4612. var statement = declaration && declaration.node.ancestor( 3 );
  4613. if ( statement && statement.type === 'ForStatement' && statement.body.contains( this ) ) {
  4614. statement.reassigned[ this.left.name ] = true;
  4615. }
  4616. }
  4617. Node$$1.prototype.initialise.call( this, transforms );
  4618. };
  4619. AssignmentExpression.prototype.transpile = function transpile ( code, transforms ) {
  4620. if ( this.operator === '**=' && transforms.exponentiation ) {
  4621. this.transpileExponentiation( code, transforms );
  4622. }
  4623. else if ( /Pattern/.test( this.left.type ) && transforms.destructuring ) {
  4624. this.transpileDestructuring( code, transforms );
  4625. }
  4626. Node$$1.prototype.transpile.call( this, code, transforms );
  4627. };
  4628. AssignmentExpression.prototype.transpileDestructuring = function transpileDestructuring ( code ) {
  4629. var scope = this.findScope( true );
  4630. var assign = scope.createIdentifier( 'assign' );
  4631. var temporaries = [ assign ];
  4632. var start = this.start;
  4633. // We need to pick out some elements from the original code,
  4634. // interleaved with generated code. These helpers are used to
  4635. // easily do that while keeping the order of the output
  4636. // predictable.
  4637. var text = '';
  4638. function use ( node ) {
  4639. code.insertRight( node.start, text );
  4640. code.move( node.start, node.end, start );
  4641. text = '';
  4642. }
  4643. function write ( string ) {
  4644. text += string;
  4645. }
  4646. write( ("(" + assign + " = ") );
  4647. use( this.right );
  4648. // Walk `pattern`, generating code that assigns the value in
  4649. // `ref` to it. When `mayDuplicate` is false, the function
  4650. // must take care to only output `ref` once.
  4651. function destructure ( pattern, ref, mayDuplicate ) {
  4652. if ( pattern.type === 'Identifier' || pattern.type === 'MemberExpression' ) {
  4653. write( ', ' );
  4654. use( pattern );
  4655. write( (" = " + ref) );
  4656. }
  4657. else if ( pattern.type === 'AssignmentPattern' ) {
  4658. if ( pattern.left.type === 'Identifier' ) {
  4659. var target = pattern.left.name;
  4660. var source = ref;
  4661. if ( !mayDuplicate ) {
  4662. write( (", " + target + " = " + ref) );
  4663. source = target;
  4664. }
  4665. write( (", " + target + " = " + source + " === void 0 ? ") );
  4666. use( pattern.right );
  4667. write( (" : " + source) );
  4668. }
  4669. else {
  4670. var target$1 = scope.createIdentifier( 'temp' );
  4671. var source$1 = ref;
  4672. temporaries.push( target$1 );
  4673. if ( !mayDuplicate ) {
  4674. write( (", " + target$1 + " = " + ref) );
  4675. source$1 = target$1;
  4676. }
  4677. write( (", " + target$1 + " = " + source$1 + " === void 0 ? ") );
  4678. use( pattern.right );
  4679. write( (" : " + source$1) );
  4680. destructure( pattern.left, target$1, true );
  4681. }
  4682. }
  4683. else if ( pattern.type === 'ArrayPattern' ) {
  4684. var elements = pattern.elements;
  4685. if ( elements.length === 1 ) {
  4686. destructure( elements[0], (ref + "[0]"), false );
  4687. }
  4688. else {
  4689. if ( !mayDuplicate ) {
  4690. var temp = scope.createIdentifier( 'array' );
  4691. temporaries.push( temp );
  4692. write( (", " + temp + " = " + ref) );
  4693. ref = temp;
  4694. }
  4695. elements.forEach( function ( element, i ) {
  4696. if ( element ) {
  4697. if ( element.type === 'RestElement' ) {
  4698. destructure( element.argument, (ref + ".slice(" + i + ")"), false );
  4699. } else {
  4700. destructure( element, (ref + "[" + i + "]"), false );
  4701. }
  4702. }
  4703. } );
  4704. }
  4705. }
  4706. else if ( pattern.type === 'ObjectPattern' ) {
  4707. var props = pattern.properties;
  4708. if ( props.length == 1 ) {
  4709. var prop = props[0];
  4710. var value = prop.computed || prop.key.type !== 'Identifier' ? (ref + "[" + (code.slice(prop.key.start, prop.key.end)) + "]") : (ref + "." + (prop.key.name));
  4711. destructure( prop.value, value, false );
  4712. }
  4713. else {
  4714. if ( !mayDuplicate ) {
  4715. var temp$1 = scope.createIdentifier( 'obj' );
  4716. temporaries.push( temp$1 );
  4717. write( (", " + temp$1 + " = " + ref) );
  4718. ref = temp$1;
  4719. }
  4720. props.forEach( function ( prop ) {
  4721. var value = prop.computed || prop.key.type !== 'Identifier' ? (ref + "[" + (code.slice(prop.key.start, prop.key.end)) + "]") : (ref + "." + (prop.key.name));
  4722. destructure( prop.value, value, false );
  4723. } );
  4724. }
  4725. }
  4726. else {
  4727. throw new Error( ("Unexpected node type in destructuring assignment (" + (pattern.type) + ")") );
  4728. }
  4729. }
  4730. destructure( this.left, assign, true );
  4731. code.insertRight( start, (text + ", " + assign + ")") );
  4732. code.remove( start, this.right.start );
  4733. var statement = this.findNearest( /(?:Statement|Declaration)$/ );
  4734. code.insertLeft( statement.start, ("var " + (temporaries.join( ', ' )) + ";\n" + (statement.getIndentation())) );
  4735. };
  4736. AssignmentExpression.prototype.transpileExponentiation = function transpileExponentiation ( code ) {
  4737. var scope = this.findScope( false );
  4738. var getAlias = function ( name ) {
  4739. var declaration = scope.findDeclaration( name );
  4740. return declaration ? declaration.name : name;
  4741. };
  4742. // first, the easy part – `**=` -> `=`
  4743. var charIndex = this.left.end;
  4744. while ( code.original[ charIndex ] !== '*' ) charIndex += 1;
  4745. code.remove( charIndex, charIndex + 2 );
  4746. // how we do the next part depends on a number of factors – whether
  4747. // this is a top-level statement, and whether we're updating a
  4748. // simple or complex reference
  4749. var base;
  4750. var left = this.left;
  4751. while ( left.type === 'ParenthesizedExpression' ) left = left.expression;
  4752. if ( left.type === 'Identifier' ) {
  4753. base = getAlias( left.name );
  4754. } else if ( left.type === 'MemberExpression' ) {
  4755. var object;
  4756. var needsObjectVar = false;
  4757. var property;
  4758. var needsPropertyVar = false;
  4759. var statement = this.findNearest( /(?:Statement|Declaration)$/ );
  4760. var i0 = statement.getIndentation();
  4761. if ( left.property.type === 'Identifier' ) {
  4762. property = left.computed ? getAlias( left.property.name ) : left.property.name;
  4763. } else {
  4764. property = scope.createIdentifier( 'property' );
  4765. needsPropertyVar = true;
  4766. }
  4767. if ( left.object.type === 'Identifier' ) {
  4768. object = getAlias( left.object.name );
  4769. } else {
  4770. object = scope.createIdentifier( 'object' );
  4771. needsObjectVar = true;
  4772. }
  4773. if ( left.start === statement.start ) {
  4774. if ( needsObjectVar && needsPropertyVar ) {
  4775. code.insertRight( statement.start, ("var " + object + " = ") );
  4776. code.overwrite( left.object.end, left.property.start, (";\n" + i0 + "var " + property + " = ") );
  4777. code.overwrite( left.property.end, left.end, (";\n" + i0 + object + "[" + property + "]") );
  4778. }
  4779. else if ( needsObjectVar ) {
  4780. code.insertRight( statement.start, ("var " + object + " = ") );
  4781. code.insertLeft( left.object.end, (";\n" + i0) );
  4782. code.insertLeft( left.object.end, object );
  4783. }
  4784. else if ( needsPropertyVar ) {
  4785. code.insertRight( left.property.start, ("var " + property + " = ") );
  4786. code.insertLeft( left.property.end, (";\n" + i0) );
  4787. code.move( left.property.start, left.property.end, this.start );
  4788. code.insertLeft( left.object.end, ("[" + property + "]") );
  4789. code.remove( left.object.end, left.property.start );
  4790. code.remove( left.property.end, left.end );
  4791. }
  4792. }
  4793. else {
  4794. var declarators = [];
  4795. if ( needsObjectVar ) declarators.push( object );
  4796. if ( needsPropertyVar ) declarators.push( property );
  4797. if ( declarators.length ) {
  4798. code.insertRight( statement.start, ("var " + (declarators.join( ', ' )) + ";\n" + i0) );
  4799. }
  4800. if ( needsObjectVar && needsPropertyVar ) {
  4801. code.insertRight( left.start, ("( " + object + " = ") );
  4802. code.overwrite( left.object.end, left.property.start, (", " + property + " = ") );
  4803. code.overwrite( left.property.end, left.end, (", " + object + "[" + property + "]") );
  4804. }
  4805. else if ( needsObjectVar ) {
  4806. code.insertRight( left.start, ("( " + object + " = ") );
  4807. code.insertLeft( left.object.end, (", " + object) );
  4808. }
  4809. else if ( needsPropertyVar ) {
  4810. code.insertRight( left.property.start, ("( " + property + " = ") );
  4811. code.insertLeft( left.property.end, ", " );
  4812. code.move( left.property.start, left.property.end, left.start );
  4813. code.overwrite( left.object.end, left.property.start, ("[" + property + "]") );
  4814. code.remove( left.property.end, left.end );
  4815. }
  4816. if ( needsPropertyVar ) {
  4817. code.insertLeft( this.end, " )" );
  4818. }
  4819. }
  4820. base = object + ( left.computed || needsPropertyVar ? ("[" + property + "]") : ("." + property) );
  4821. }
  4822. code.insertRight( this.right.start, ("Math.pow( " + base + ", ") );
  4823. code.insertLeft( this.right.end, " )" );
  4824. };
  4825. return AssignmentExpression;
  4826. }(Node));
  4827. var BinaryExpression = (function (Node$$1) {
  4828. function BinaryExpression () {
  4829. Node$$1.apply(this, arguments);
  4830. }
  4831. if ( Node$$1 ) BinaryExpression.__proto__ = Node$$1;
  4832. BinaryExpression.prototype = Object.create( Node$$1 && Node$$1.prototype );
  4833. BinaryExpression.prototype.constructor = BinaryExpression;
  4834. BinaryExpression.prototype.transpile = function transpile ( code, transforms ) {
  4835. if ( this.operator === '**' && transforms.exponentiation ) {
  4836. code.insertRight( this.start, "Math.pow( " );
  4837. code.overwrite( this.left.end, this.right.start, ", " );
  4838. code.insertLeft( this.end, " )" );
  4839. }
  4840. Node$$1.prototype.transpile.call( this, code, transforms );
  4841. };
  4842. return BinaryExpression;
  4843. }(Node));
  4844. var loopStatement = /(?:For(?:In|Of)?|While)Statement/;
  4845. var BreakStatement = (function (Node$$1) {
  4846. function BreakStatement () {
  4847. Node$$1.apply(this, arguments);
  4848. }
  4849. if ( Node$$1 ) BreakStatement.__proto__ = Node$$1;
  4850. BreakStatement.prototype = Object.create( Node$$1 && Node$$1.prototype );
  4851. BreakStatement.prototype.constructor = BreakStatement;
  4852. BreakStatement.prototype.initialise = function initialise () {
  4853. var loop = this.findNearest( loopStatement );
  4854. var switchCase = this.findNearest( 'SwitchCase' );
  4855. if ( loop && ( !switchCase || loop.depth > switchCase.depth ) ) {
  4856. loop.canBreak = true;
  4857. this.loop = loop;
  4858. }
  4859. };
  4860. BreakStatement.prototype.transpile = function transpile ( code ) {
  4861. if ( this.loop && this.loop.shouldRewriteAsFunction ) {
  4862. if ( this.label ) throw new CompileError( this, 'Labels are not currently supported in a loop with locally-scoped variables' );
  4863. code.overwrite( this.start, this.start + 5, "return 'break'" );
  4864. }
  4865. };
  4866. return BreakStatement;
  4867. }(Node));
  4868. var CallExpression = (function (Node$$1) {
  4869. function CallExpression () {
  4870. Node$$1.apply(this, arguments);
  4871. }
  4872. if ( Node$$1 ) CallExpression.__proto__ = Node$$1;
  4873. CallExpression.prototype = Object.create( Node$$1 && Node$$1.prototype );
  4874. CallExpression.prototype.constructor = CallExpression;
  4875. CallExpression.prototype.initialise = function initialise ( transforms ) {
  4876. var this$1 = this;
  4877. if ( transforms.spreadRest && this.arguments.length > 1 ) {
  4878. var lexicalBoundary = this.findLexicalBoundary();
  4879. var i = this.arguments.length;
  4880. while ( i-- ) {
  4881. var arg = this$1.arguments[i];
  4882. if ( arg.type === 'SpreadElement' && isArguments( arg.argument ) ) {
  4883. this$1.argumentsArrayAlias = lexicalBoundary.getArgumentsArrayAlias();
  4884. }
  4885. }
  4886. }
  4887. Node$$1.prototype.initialise.call( this, transforms );
  4888. };
  4889. CallExpression.prototype.transpile = function transpile ( code, transforms ) {
  4890. if ( transforms.spreadRest && this.arguments.length ) {
  4891. var hasSpreadElements = false;
  4892. var context;
  4893. var firstArgument = this.arguments[0];
  4894. if ( this.arguments.length === 1 ) {
  4895. if ( firstArgument.type === 'SpreadElement' ) {
  4896. code.remove( firstArgument.start, firstArgument.argument.start );
  4897. hasSpreadElements = true;
  4898. }
  4899. } else {
  4900. hasSpreadElements = spread( code, this.arguments, firstArgument.start, this.argumentsArrayAlias );
  4901. }
  4902. if ( hasSpreadElements ) {
  4903. // we need to handle super() and super.method() differently
  4904. // due to its instance
  4905. var _super = null;
  4906. if ( this.callee.type === 'Super' ) {
  4907. _super = this.callee;
  4908. }
  4909. else if ( this.callee.type === 'MemberExpression' && this.callee.object.type === 'Super' ) {
  4910. _super = this.callee.object;
  4911. }
  4912. if ( !_super && this.callee.type === 'MemberExpression' ) {
  4913. if ( this.callee.object.type === 'Identifier' ) {
  4914. context = this.callee.object.name;
  4915. } else {
  4916. context = this.findScope( true ).createIdentifier( 'ref' );
  4917. var callExpression = this.callee.object;
  4918. var enclosure = callExpression.findNearest( /Function/ );
  4919. var block = enclosure ? enclosure.body.body
  4920. : callExpression.findNearest( /^Program$/ ).body;
  4921. var lastStatementInBlock = block[ block.length - 1 ];
  4922. var i0 = lastStatementInBlock.getIndentation();
  4923. code.insertRight( callExpression.start, ("(" + context + " = ") );
  4924. code.insertLeft( callExpression.end, ")" );
  4925. code.insertLeft( lastStatementInBlock.end, ("\n" + i0 + "var " + context + ";") );
  4926. }
  4927. } else {
  4928. context = 'void 0';
  4929. }
  4930. code.insertLeft( this.callee.end, '.apply' );
  4931. if ( _super ) {
  4932. _super.noCall = true; // bit hacky...
  4933. if ( this.arguments.length > 1 ) {
  4934. if ( firstArgument.type !== 'SpreadElement' ) {
  4935. code.insertRight( firstArgument.start, "[ " );
  4936. }
  4937. code.insertLeft( this.arguments[ this.arguments.length - 1 ].end, ' )' );
  4938. }
  4939. }
  4940. else if ( this.arguments.length === 1 ) {
  4941. code.insertRight( firstArgument.start, (context + ", ") );
  4942. } else {
  4943. if ( firstArgument.type === 'SpreadElement' ) {
  4944. code.insertLeft( firstArgument.start, (context + ", ") );
  4945. } else {
  4946. code.insertLeft( firstArgument.start, (context + ", [ ") );
  4947. }
  4948. code.insertLeft( this.arguments[ this.arguments.length - 1 ].end, ' )' );
  4949. }
  4950. }
  4951. }
  4952. Node$$1.prototype.transpile.call( this, code, transforms );
  4953. };
  4954. return CallExpression;
  4955. }(Node));
  4956. function findIndex ( array, fn ) {
  4957. for ( var i = 0; i < array.length; i += 1 ) {
  4958. if ( fn( array[i], i ) ) return i;
  4959. }
  4960. return -1;
  4961. }
  4962. var reserved = Object.create( null );
  4963. '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( ' ' )
  4964. .forEach( function ( word ) { return reserved[ word ] = true; } );
  4965. // TODO this code is pretty wild, tidy it up
  4966. var ClassBody = (function (Node$$1) {
  4967. function ClassBody () {
  4968. Node$$1.apply(this, arguments);
  4969. }
  4970. if ( Node$$1 ) ClassBody.__proto__ = Node$$1;
  4971. ClassBody.prototype = Object.create( Node$$1 && Node$$1.prototype );
  4972. ClassBody.prototype.constructor = ClassBody;
  4973. ClassBody.prototype.transpile = function transpile ( code, transforms, inFunctionExpression, superName ) {
  4974. var this$1 = this;
  4975. if ( transforms.classes ) {
  4976. var name = this.parent.name;
  4977. var indentStr = code.getIndentString();
  4978. var i0 = this.getIndentation() + ( inFunctionExpression ? indentStr : '' );
  4979. var i1 = i0 + indentStr;
  4980. var constructorIndex = findIndex( this.body, function ( node ) { return node.kind === 'constructor'; } );
  4981. var constructor = this.body[ constructorIndex ];
  4982. var introBlock = '';
  4983. var outroBlock = '';
  4984. if ( this.body.length ) {
  4985. code.remove( this.start, this.body[0].start );
  4986. code.remove( this.body[ this.body.length - 1 ].end, this.end );
  4987. } else {
  4988. code.remove( this.start, this.end );
  4989. }
  4990. if ( constructor ) {
  4991. constructor.value.body.isConstructorBody = true;
  4992. var previousMethod = this.body[ constructorIndex - 1 ];
  4993. var nextMethod = this.body[ constructorIndex + 1 ];
  4994. // ensure constructor is first
  4995. if ( constructorIndex > 0 ) {
  4996. code.remove( previousMethod.end, constructor.start );
  4997. code.move( constructor.start, nextMethod ? nextMethod.start : this.end - 1, this.body[0].start );
  4998. }
  4999. if ( !inFunctionExpression ) code.insertLeft( constructor.end, ';' );
  5000. }
  5001. var namedFunctions = this.program.options.namedFunctionExpressions !== false;
  5002. var namedConstructor = namedFunctions || this.parent.superClass || this.parent.type !== 'ClassDeclaration';
  5003. if ( this.parent.superClass ) {
  5004. var inheritanceBlock = "if ( " + superName + " ) " + name + ".__proto__ = " + superName + ";\n" + i0 + name + ".prototype = Object.create( " + superName + " && " + superName + ".prototype );\n" + i0 + name + ".prototype.constructor = " + name + ";";
  5005. if ( constructor ) {
  5006. introBlock += "\n\n" + i0 + inheritanceBlock;
  5007. } else {
  5008. var fn = "function " + name + " () {" + ( superName ?
  5009. ("\n" + i1 + superName + ".apply(this, arguments);\n" + i0 + "}") :
  5010. "}" ) + ( inFunctionExpression ? '' : ';' ) + ( this.body.length ? ("\n\n" + i0) : '' );
  5011. inheritanceBlock = fn + inheritanceBlock;
  5012. introBlock += inheritanceBlock + "\n\n" + i0;
  5013. }
  5014. } else if ( !constructor ) {
  5015. var fn$1 = 'function ' + (namedConstructor ? name + ' ' : '') + '() {}';
  5016. if ( this.parent.type === 'ClassDeclaration' ) fn$1 += ';';
  5017. if ( this.body.length ) fn$1 += "\n\n" + i0;
  5018. introBlock += fn$1;
  5019. }
  5020. var scope = this.findScope( false );
  5021. var prototypeGettersAndSetters = [];
  5022. var staticGettersAndSetters = [];
  5023. var prototypeAccessors;
  5024. var staticAccessors;
  5025. this.body.forEach( function ( method, i ) {
  5026. if ( method.kind === 'constructor' ) {
  5027. var constructorName = namedConstructor ? ' ' + name : '';
  5028. code.overwrite( method.key.start, method.key.end, ("function" + constructorName) );
  5029. return;
  5030. }
  5031. if ( method.static ) {
  5032. var len = code.original[ method.start + 6 ] == ' ' ? 7 : 6;
  5033. code.remove( method.start, method.start + len );
  5034. }
  5035. var isAccessor = method.kind !== 'method';
  5036. var lhs;
  5037. var methodName = method.key.name;
  5038. if ( reserved[ methodName ] ) methodName = scope.createIdentifier( methodName );
  5039. // when method name is a string or a number let's pretend it's a computed method
  5040. var fake_computed = false;
  5041. if ( ! method.computed && method.key.type === 'Literal' ) {
  5042. fake_computed = true;
  5043. method.computed = true;
  5044. }
  5045. if ( isAccessor ) {
  5046. if ( method.computed ) {
  5047. throw new Error( 'Computed accessor properties are not currently supported' );
  5048. }
  5049. code.remove( method.start, method.key.start );
  5050. if ( method.static ) {
  5051. if ( !~staticGettersAndSetters.indexOf( method.key.name ) ) staticGettersAndSetters.push( method.key.name );
  5052. if ( !staticAccessors ) staticAccessors = scope.createIdentifier( 'staticAccessors' );
  5053. lhs = "" + staticAccessors;
  5054. } else {
  5055. if ( !~prototypeGettersAndSetters.indexOf( method.key.name ) ) prototypeGettersAndSetters.push( method.key.name );
  5056. if ( !prototypeAccessors ) prototypeAccessors = scope.createIdentifier( 'prototypeAccessors' );
  5057. lhs = "" + prototypeAccessors;
  5058. }
  5059. } else {
  5060. lhs = method.static ?
  5061. ("" + name) :
  5062. (name + ".prototype");
  5063. }
  5064. if ( !method.computed ) lhs += '.';
  5065. var insertNewlines = ( constructorIndex > 0 && i === constructorIndex + 1 ) ||
  5066. ( i === 0 && constructorIndex === this$1.body.length - 1 );
  5067. if ( insertNewlines ) lhs = "\n\n" + i0 + lhs;
  5068. var c = method.key.end;
  5069. if ( method.computed ) {
  5070. if ( fake_computed ) {
  5071. code.insertRight( method.key.start, '[' );
  5072. code.insertLeft( method.key.end, ']' );
  5073. } else {
  5074. while ( code.original[c] !== ']' ) c += 1;
  5075. c += 1;
  5076. }
  5077. }
  5078. code.insertRight( method.start, lhs );
  5079. var rhs = ( isAccessor ? ("." + (method.kind)) : '' ) + " = function" + ( method.value.generator ? '* ' : ' ' ) + ( method.computed || isAccessor || !namedFunctions ? '' : (methodName + " ") );
  5080. code.remove( c, method.value.start );
  5081. code.insertRight( method.value.start, rhs );
  5082. code.insertLeft( method.end, ';' );
  5083. if ( method.value.generator ) code.remove( method.start, method.key.start );
  5084. });
  5085. if ( prototypeGettersAndSetters.length || staticGettersAndSetters.length ) {
  5086. var intro = [];
  5087. var outro = [];
  5088. if ( prototypeGettersAndSetters.length ) {
  5089. intro.push( ("var " + prototypeAccessors + " = { " + (prototypeGettersAndSetters.map( function ( name ) { return (name + ": {}"); } ).join( ',' )) + " };") );
  5090. outro.push( ("Object.defineProperties( " + name + ".prototype, " + prototypeAccessors + " );") );
  5091. }
  5092. if ( staticGettersAndSetters.length ) {
  5093. intro.push( ("var " + staticAccessors + " = { " + (staticGettersAndSetters.map( function ( name ) { return (name + ": {}"); } ).join( ',' )) + " };") );
  5094. outro.push( ("Object.defineProperties( " + name + ", " + staticAccessors + " );") );
  5095. }
  5096. if ( constructor ) introBlock += "\n\n" + i0;
  5097. introBlock += intro.join( ("\n" + i0) );
  5098. if ( !constructor ) introBlock += "\n\n" + i0;
  5099. outroBlock += "\n\n" + i0 + outro.join( ("\n" + i0) );
  5100. }
  5101. if ( constructor ) {
  5102. code.insertLeft( constructor.end, introBlock );
  5103. } else {
  5104. code.insertRight( this.start, introBlock );
  5105. }
  5106. code.insertLeft( this.end, outroBlock );
  5107. }
  5108. Node$$1.prototype.transpile.call( this, code, transforms );
  5109. };
  5110. return ClassBody;
  5111. }(Node));
  5112. // TODO this function is slightly flawed – it works on the original string,
  5113. // not its current edited state.
  5114. // That's not a problem for the way that it's currently used, but it could
  5115. // be in future...
  5116. function deindent ( node, code ) {
  5117. var start = node.start;
  5118. var end = node.end;
  5119. var indentStr = code.getIndentString();
  5120. var indentStrLen = indentStr.length;
  5121. var indentStart = start - indentStrLen;
  5122. if ( !node.program.indentExclusions[ indentStart ]
  5123. && code.original.slice( indentStart, start ) === indentStr ) {
  5124. code.remove( indentStart, start );
  5125. }
  5126. var pattern = new RegExp( indentStr + '\\S', 'g' );
  5127. var slice = code.original.slice( start, end );
  5128. var match;
  5129. while ( match = pattern.exec( slice ) ) {
  5130. var removeStart = start + match.index;
  5131. if ( !node.program.indentExclusions[ removeStart ] ) {
  5132. code.remove( removeStart, removeStart + indentStrLen );
  5133. }
  5134. }
  5135. }
  5136. var ClassDeclaration = (function (Node$$1) {
  5137. function ClassDeclaration () {
  5138. Node$$1.apply(this, arguments);
  5139. }
  5140. if ( Node$$1 ) ClassDeclaration.__proto__ = Node$$1;
  5141. ClassDeclaration.prototype = Object.create( Node$$1 && Node$$1.prototype );
  5142. ClassDeclaration.prototype.constructor = ClassDeclaration;
  5143. ClassDeclaration.prototype.initialise = function initialise ( transforms ) {
  5144. this.name = this.id.name;
  5145. this.findScope( true ).addDeclaration( this.id, 'class' );
  5146. Node$$1.prototype.initialise.call( this, transforms );
  5147. };
  5148. ClassDeclaration.prototype.transpile = function transpile ( code, transforms ) {
  5149. if ( transforms.classes ) {
  5150. if ( !this.superClass ) deindent( this.body, code );
  5151. var superName = this.superClass && ( this.superClass.name || 'superclass' );
  5152. var i0 = this.getIndentation();
  5153. var i1 = i0 + code.getIndentString();
  5154. // if this is an export default statement, we have to move the export to
  5155. // after the declaration, because `export default var Foo = ...` is illegal
  5156. var syntheticDefaultExport = this.parent.type === 'ExportDefaultDeclaration' ?
  5157. ("\n\n" + i0 + "export default " + (this.id.name) + ";") :
  5158. '';
  5159. if ( syntheticDefaultExport ) code.remove( this.parent.start, this.start );
  5160. code.overwrite( this.start, this.id.start, 'var ' );
  5161. if ( this.superClass ) {
  5162. if ( this.superClass.end === this.body.start ) {
  5163. code.remove( this.id.end, this.superClass.start );
  5164. code.insertLeft( this.id.end, (" = (function (" + superName + ") {\n" + i1) );
  5165. } else {
  5166. code.overwrite( this.id.end, this.superClass.start, ' = ' );
  5167. code.overwrite( this.superClass.end, this.body.start, ("(function (" + superName + ") {\n" + i1) );
  5168. }
  5169. } else {
  5170. if ( this.id.end === this.body.start ) {
  5171. code.insertLeft( this.id.end, ' = ' );
  5172. } else {
  5173. code.overwrite( this.id.end, this.body.start, ' = ' );
  5174. }
  5175. }
  5176. this.body.transpile( code, transforms, !!this.superClass, superName );
  5177. if ( this.superClass ) {
  5178. code.insertLeft( this.end, ("\n\n" + i1 + "return " + (this.name) + ";\n" + i0 + "}(") );
  5179. code.move( this.superClass.start, this.superClass.end, this.end );
  5180. code.insertRight( this.end, ("));" + syntheticDefaultExport) );
  5181. } else if ( syntheticDefaultExport ) {
  5182. code.insertRight( this.end, syntheticDefaultExport );
  5183. }
  5184. }
  5185. else {
  5186. this.body.transpile( code, transforms, false, null );
  5187. }
  5188. };
  5189. return ClassDeclaration;
  5190. }(Node));
  5191. var ClassExpression = (function (Node$$1) {
  5192. function ClassExpression () {
  5193. Node$$1.apply(this, arguments);
  5194. }
  5195. if ( Node$$1 ) ClassExpression.__proto__ = Node$$1;
  5196. ClassExpression.prototype = Object.create( Node$$1 && Node$$1.prototype );
  5197. ClassExpression.prototype.constructor = ClassExpression;
  5198. ClassExpression.prototype.initialise = function initialise ( transforms ) {
  5199. this.name = this.id ? this.id.name :
  5200. this.parent.type === 'VariableDeclarator' ? this.parent.id.name :
  5201. this.parent.type === 'AssignmentExpression' ? this.parent.left.name :
  5202. this.findScope( true ).createIdentifier( 'anonymous' );
  5203. Node$$1.prototype.initialise.call( this, transforms );
  5204. };
  5205. ClassExpression.prototype.transpile = function transpile ( code, transforms ) {
  5206. if ( transforms.classes ) {
  5207. var superName = this.superClass && ( this.superClass.name || 'superclass' );
  5208. var i0 = this.getIndentation();
  5209. var i1 = i0 + code.getIndentString();
  5210. if ( this.superClass ) {
  5211. code.remove( this.start, this.superClass.start );
  5212. code.remove( this.superClass.end, this.body.start );
  5213. code.insertLeft( this.start, ("(function (" + superName + ") {\n" + i1) );
  5214. } else {
  5215. code.overwrite( this.start, this.body.start, ("(function () {\n" + i1) );
  5216. }
  5217. this.body.transpile( code, transforms, true, superName );
  5218. var outro = "\n\n" + i1 + "return " + (this.name) + ";\n" + i0 + "}(";
  5219. if ( this.superClass ) {
  5220. code.insertLeft( this.end, outro );
  5221. code.move( this.superClass.start, this.superClass.end, this.end );
  5222. code.insertRight( this.end, '))' );
  5223. } else {
  5224. code.insertLeft( this.end, ("\n\n" + i1 + "return " + (this.name) + ";\n" + i0 + "}())") );
  5225. }
  5226. }
  5227. else {
  5228. this.body.transpile( code, transforms, false );
  5229. }
  5230. };
  5231. return ClassExpression;
  5232. }(Node));
  5233. var ContinueStatement = (function (Node$$1) {
  5234. function ContinueStatement () {
  5235. Node$$1.apply(this, arguments);
  5236. }
  5237. if ( Node$$1 ) ContinueStatement.__proto__ = Node$$1;
  5238. ContinueStatement.prototype = Object.create( Node$$1 && Node$$1.prototype );
  5239. ContinueStatement.prototype.constructor = ContinueStatement;
  5240. ContinueStatement.prototype.transpile = function transpile ( code ) {
  5241. var loop = this.findNearest( loopStatement );
  5242. if ( loop.shouldRewriteAsFunction ) {
  5243. if ( this.label ) throw new CompileError( this, 'Labels are not currently supported in a loop with locally-scoped variables' );
  5244. code.overwrite( this.start, this.start + 8, 'return' );
  5245. }
  5246. };
  5247. return ContinueStatement;
  5248. }(Node));
  5249. var ExportDefaultDeclaration = (function (Node$$1) {
  5250. function ExportDefaultDeclaration () {
  5251. Node$$1.apply(this, arguments);
  5252. }
  5253. if ( Node$$1 ) ExportDefaultDeclaration.__proto__ = Node$$1;
  5254. ExportDefaultDeclaration.prototype = Object.create( Node$$1 && Node$$1.prototype );
  5255. ExportDefaultDeclaration.prototype.constructor = ExportDefaultDeclaration;
  5256. ExportDefaultDeclaration.prototype.initialise = function initialise ( transforms ) {
  5257. if ( transforms.moduleExport ) throw new CompileError( this, 'export is not supported' );
  5258. Node$$1.prototype.initialise.call( this, transforms );
  5259. };
  5260. return ExportDefaultDeclaration;
  5261. }(Node));
  5262. var ExportNamedDeclaration = (function (Node$$1) {
  5263. function ExportNamedDeclaration () {
  5264. Node$$1.apply(this, arguments);
  5265. }
  5266. if ( Node$$1 ) ExportNamedDeclaration.__proto__ = Node$$1;
  5267. ExportNamedDeclaration.prototype = Object.create( Node$$1 && Node$$1.prototype );
  5268. ExportNamedDeclaration.prototype.constructor = ExportNamedDeclaration;
  5269. ExportNamedDeclaration.prototype.initialise = function initialise ( transforms ) {
  5270. if ( transforms.moduleExport ) throw new CompileError( this, 'export is not supported' );
  5271. Node$$1.prototype.initialise.call( this, transforms );
  5272. };
  5273. return ExportNamedDeclaration;
  5274. }(Node));
  5275. var LoopStatement = (function (Node$$1) {
  5276. function LoopStatement () {
  5277. Node$$1.apply(this, arguments);
  5278. }
  5279. if ( Node$$1 ) LoopStatement.__proto__ = Node$$1;
  5280. LoopStatement.prototype = Object.create( Node$$1 && Node$$1.prototype );
  5281. LoopStatement.prototype.constructor = LoopStatement;
  5282. LoopStatement.prototype.findScope = function findScope ( functionScope ) {
  5283. return functionScope || !this.createdScope ? this.parent.findScope( functionScope ) : this.body.scope;
  5284. };
  5285. LoopStatement.prototype.initialise = function initialise ( transforms ) {
  5286. var this$1 = this;
  5287. this.body.createScope();
  5288. this.createdScope = true;
  5289. // this is populated as and when reassignments occur
  5290. this.reassigned = Object.create( null );
  5291. this.aliases = Object.create( null );
  5292. Node$$1.prototype.initialise.call( this, transforms );
  5293. if ( transforms.letConst ) {
  5294. // see if any block-scoped declarations are referenced
  5295. // inside function expressions
  5296. var names = Object.keys( this.body.scope.declarations );
  5297. var i = names.length;
  5298. while ( i-- ) {
  5299. var name = names[i];
  5300. var declaration = this$1.body.scope.declarations[ name ];
  5301. var j = declaration.instances.length;
  5302. while ( j-- ) {
  5303. var instance = declaration.instances[j];
  5304. var nearestFunctionExpression = instance.findNearest( /Function/ );
  5305. if ( nearestFunctionExpression && nearestFunctionExpression.depth > this$1.depth ) {
  5306. this$1.shouldRewriteAsFunction = true;
  5307. break;
  5308. }
  5309. }
  5310. if ( this$1.shouldRewriteAsFunction ) break;
  5311. }
  5312. }
  5313. };
  5314. LoopStatement.prototype.transpile = function transpile ( code, transforms ) {
  5315. var needsBlock = this.type != 'ForOfStatement' && (
  5316. this.body.type !== 'BlockStatement'
  5317. || this.body.type === 'BlockStatement' && this.body.synthetic );
  5318. if ( this.shouldRewriteAsFunction ) {
  5319. var i0 = this.getIndentation();
  5320. var i1 = i0 + code.getIndentString();
  5321. var argString = this.args ? (" " + (this.args.join( ', ' )) + " ") : '';
  5322. var paramString = this.params ? (" " + (this.params.join( ', ' )) + " ") : '';
  5323. var functionScope = this.findScope( true );
  5324. var loop = functionScope.createIdentifier( 'loop' );
  5325. var before = "var " + loop + " = function (" + paramString + ") " + ( this.body.synthetic ? ("{\n" + i0 + (code.getIndentString())) : '' );
  5326. var after = ( this.body.synthetic ? ("\n" + i0 + "}") : '' ) + ";\n\n" + i0;
  5327. code.insertRight( this.body.start, before );
  5328. code.insertLeft( this.body.end, after );
  5329. code.move( this.start, this.body.start, this.body.end );
  5330. if ( this.canBreak || this.canReturn ) {
  5331. var returned = functionScope.createIdentifier( 'returned' );
  5332. var insert = "{\n" + i1 + "var " + returned + " = " + loop + "(" + argString + ");\n";
  5333. if ( this.canBreak ) insert += "\n" + i1 + "if ( " + returned + " === 'break' ) break;";
  5334. if ( this.canReturn ) insert += "\n" + i1 + "if ( " + returned + " ) return " + returned + ".v;";
  5335. insert += "\n" + i0 + "}";
  5336. code.insertRight( this.body.end, insert );
  5337. } else {
  5338. var callExpression = loop + "(" + argString + ");";
  5339. if ( this.type === 'DoWhileStatement' ) {
  5340. code.overwrite( this.start, this.body.start, ("do {\n" + i1 + callExpression + "\n" + i0 + "}") );
  5341. } else {
  5342. code.insertRight( this.body.end, callExpression );
  5343. }
  5344. }
  5345. } else if ( needsBlock ) {
  5346. code.insertLeft( this.body.start, '{ ' );
  5347. code.insertRight( this.body.end, ' }' );
  5348. }
  5349. Node$$1.prototype.transpile.call( this, code, transforms );
  5350. };
  5351. return LoopStatement;
  5352. }(Node));
  5353. function extractNames ( node ) {
  5354. var names = [];
  5355. extractors[ node.type ]( names, node );
  5356. return names;
  5357. }
  5358. var extractors = {
  5359. Identifier: function Identifier ( names, node ) {
  5360. names.push( node );
  5361. },
  5362. ObjectPattern: function ObjectPattern ( names, node ) {
  5363. for ( var i = 0, list = node.properties; i < list.length; i += 1 ) {
  5364. var prop = list[i];
  5365. extractors[ prop.value.type ]( names, prop.value );
  5366. }
  5367. },
  5368. ArrayPattern: function ArrayPattern ( names, node ) {
  5369. for ( var i = 0, list = node.elements; i < list.length; i += 1 ) {
  5370. var element = list[i];
  5371. if ( element ) extractors[ element.type ]( names, element );
  5372. }
  5373. },
  5374. RestElement: function RestElement ( names, node ) {
  5375. extractors[ node.argument.type ]( names, node.argument );
  5376. },
  5377. AssignmentPattern: function AssignmentPattern ( names, node ) {
  5378. extractors[ node.left.type ]( names, node.left );
  5379. }
  5380. };
  5381. var ForStatement = (function (LoopStatement$$1) {
  5382. function ForStatement () {
  5383. LoopStatement$$1.apply(this, arguments);
  5384. }
  5385. if ( LoopStatement$$1 ) ForStatement.__proto__ = LoopStatement$$1;
  5386. ForStatement.prototype = Object.create( LoopStatement$$1 && LoopStatement$$1.prototype );
  5387. ForStatement.prototype.constructor = ForStatement;
  5388. ForStatement.prototype.findScope = function findScope ( functionScope ) {
  5389. return functionScope || !this.createdScope ? this.parent.findScope( functionScope ) : this.body.scope;
  5390. };
  5391. ForStatement.prototype.transpile = function transpile ( code, transforms ) {
  5392. var this$1 = this;
  5393. var i1 = this.getIndentation() + code.getIndentString();
  5394. if ( this.shouldRewriteAsFunction ) {
  5395. // which variables are declared in the init statement?
  5396. var names = this.init.type === 'VariableDeclaration' ?
  5397. [].concat.apply( [], this.init.declarations.map( function ( declarator ) { return extractNames( declarator.id ); } ) ) :
  5398. [];
  5399. var aliases = this.aliases;
  5400. this.args = names.map( function ( name ) { return name in this$1.aliases ? this$1.aliases[ name ].outer : name; } );
  5401. this.params = names.map( function ( name ) { return name in this$1.aliases ? this$1.aliases[ name ].inner : name; } );
  5402. var updates = Object.keys( this.reassigned )
  5403. .map( function ( name ) { return ((aliases[ name ].outer) + " = " + (aliases[ name ].inner) + ";"); } );
  5404. if ( updates.length ) {
  5405. if ( this.body.synthetic ) {
  5406. code.insertLeft( this.body.body[0].end, ("; " + (updates.join(" "))) );
  5407. } else {
  5408. var lastStatement = this.body.body[ this.body.body.length - 1 ];
  5409. code.insertLeft( lastStatement.end, ("\n\n" + i1 + (updates.join(("\n" + i1)))) );
  5410. }
  5411. }
  5412. }
  5413. LoopStatement$$1.prototype.transpile.call( this, code, transforms );
  5414. };
  5415. return ForStatement;
  5416. }(LoopStatement));
  5417. var ForInStatement = (function (LoopStatement$$1) {
  5418. function ForInStatement () {
  5419. LoopStatement$$1.apply(this, arguments);
  5420. }
  5421. if ( LoopStatement$$1 ) ForInStatement.__proto__ = LoopStatement$$1;
  5422. ForInStatement.prototype = Object.create( LoopStatement$$1 && LoopStatement$$1.prototype );
  5423. ForInStatement.prototype.constructor = ForInStatement;
  5424. ForInStatement.prototype.findScope = function findScope ( functionScope ) {
  5425. return functionScope || !this.createdScope ? this.parent.findScope( functionScope ) : this.body.scope;
  5426. };
  5427. ForInStatement.prototype.transpile = function transpile ( code, transforms ) {
  5428. var this$1 = this;
  5429. if ( this.shouldRewriteAsFunction ) {
  5430. // which variables are declared in the init statement?
  5431. var names = this.left.type === 'VariableDeclaration' ?
  5432. [].concat.apply( [], this.left.declarations.map( function ( declarator ) { return extractNames( declarator.id ); } ) ) :
  5433. [];
  5434. this.args = names.map( function ( name ) { return name in this$1.aliases ? this$1.aliases[ name ].outer : name; } );
  5435. this.params = names.map( function ( name ) { return name in this$1.aliases ? this$1.aliases[ name ].inner : name; } );
  5436. }
  5437. LoopStatement$$1.prototype.transpile.call( this, code, transforms );
  5438. };
  5439. return ForInStatement;
  5440. }(LoopStatement));
  5441. var handlers = {
  5442. Identifier: destructureIdentifier,
  5443. AssignmentPattern: destructureAssignmentPattern,
  5444. ArrayPattern: destructureArrayPattern,
  5445. ObjectPattern: destructureObjectPattern
  5446. };
  5447. function destructure ( code, scope, node, ref, inline, statementGenerators ) {
  5448. handlers[ node.type ]( code, scope, node, ref, inline, statementGenerators );
  5449. }
  5450. function destructureIdentifier ( code, scope, node, ref, inline, statementGenerators ) {
  5451. statementGenerators.push( function ( start, prefix, suffix ) {
  5452. code.insertRight( node.start, inline ? prefix : (prefix + "var ") );
  5453. code.insertLeft( node.end, (" = " + ref + suffix) );
  5454. code.move( node.start, node.end, start );
  5455. });
  5456. }
  5457. function destructureAssignmentPattern ( code, scope, node, ref, inline, statementGenerators ) {
  5458. var isIdentifier = node.left.type === 'Identifier';
  5459. var name = isIdentifier ? node.left.name : ref;
  5460. if ( !inline ) {
  5461. statementGenerators.push( function ( start, prefix, suffix ) {
  5462. code.insertRight( node.left.end, (prefix + "if ( " + name + " === void 0 ) " + name) );
  5463. code.move( node.left.end, node.right.end, start );
  5464. code.insertLeft( node.right.end, suffix );
  5465. });
  5466. }
  5467. if ( !isIdentifier ) {
  5468. destructure( code, scope, node.left, ref, inline, statementGenerators );
  5469. }
  5470. }
  5471. function destructureArrayPattern ( code, scope, node, ref, inline, statementGenerators ) {
  5472. var c = node.start;
  5473. node.elements.forEach( function ( element, i ) {
  5474. if ( !element ) return;
  5475. if ( element.type === 'RestElement' ) {
  5476. handleProperty( code, scope, c, element.argument, (ref + ".slice(" + i + ")"), inline, statementGenerators );
  5477. } else {
  5478. handleProperty( code, scope, c, element, (ref + "[" + i + "]"), inline, statementGenerators );
  5479. }
  5480. c = element.end;
  5481. });
  5482. code.remove( c, node.end );
  5483. }
  5484. function destructureObjectPattern ( code, scope, node, ref, inline, statementGenerators ) {
  5485. var c = node.start;
  5486. node.properties.forEach( function ( prop ) {
  5487. var value = prop.computed || prop.key.type !== 'Identifier' ? (ref + "[" + (code.slice(prop.key.start, prop.key.end)) + "]") : (ref + "." + (prop.key.name));
  5488. handleProperty( code, scope, c, prop.value, value, inline, statementGenerators );
  5489. c = prop.end;
  5490. });
  5491. code.remove( c, node.end );
  5492. }
  5493. function handleProperty ( code, scope, c, node, value, inline, statementGenerators ) {
  5494. switch ( node.type ) {
  5495. case 'Identifier': {
  5496. code.remove( c, node.start );
  5497. destructureIdentifier( code, scope, node, value, inline, statementGenerators );
  5498. break;
  5499. }
  5500. case 'AssignmentPattern': {
  5501. var name;
  5502. var isIdentifier = node.left.type === 'Identifier';
  5503. if ( isIdentifier ) {
  5504. name = node.left.name;
  5505. var declaration = scope.findDeclaration( name );
  5506. if ( declaration ) name = declaration.name;
  5507. } else {
  5508. name = scope.createIdentifier( value );
  5509. }
  5510. statementGenerators.push( function ( start, prefix, suffix ) {
  5511. if ( inline ) {
  5512. code.insertRight( node.right.start, (name + " = " + value + " === undefined ? ") );
  5513. code.insertLeft( node.right.end, (" : " + value) );
  5514. } else {
  5515. code.insertRight( node.right.start, (prefix + "var " + name + " = " + value + "; if ( " + name + " === void 0 ) " + name + " = ") );
  5516. code.insertLeft( node.right.end, suffix );
  5517. }
  5518. code.move( node.right.start, node.right.end, start );
  5519. });
  5520. if ( isIdentifier ) {
  5521. code.remove( c, node.right.start );
  5522. } else {
  5523. code.remove( c, node.left.start );
  5524. code.remove( node.left.end, node.right.start );
  5525. handleProperty( code, scope, c, node.left, name, inline, statementGenerators );
  5526. }
  5527. break;
  5528. }
  5529. case 'ObjectPattern': {
  5530. code.remove( c, c = node.start );
  5531. if ( node.properties.length > 1 ) {
  5532. var ref = scope.createIdentifier( value );
  5533. statementGenerators.push( function ( start, prefix, suffix ) {
  5534. // this feels a tiny bit hacky, but we can't do a
  5535. // straightforward insertLeft and keep correct order...
  5536. code.insertRight( node.start, (prefix + "var " + ref + " = ") );
  5537. code.overwrite( node.start, c = node.start + 1, value );
  5538. code.insertLeft( c, suffix );
  5539. code.move( node.start, c, start );
  5540. });
  5541. node.properties.forEach( function ( prop ) {
  5542. var value = prop.computed || prop.key.type !== 'Identifier' ? (ref + "[" + (code.slice(prop.key.start, prop.key.end)) + "]") : (ref + "." + (prop.key.name));
  5543. handleProperty( code, scope, c, prop.value, value, inline, statementGenerators );
  5544. c = prop.end;
  5545. });
  5546. } else {
  5547. var prop = node.properties[0];
  5548. var value_suffix = prop.computed || prop.key.type !== 'Identifier' ? ("[" + (code.slice(prop.key.start, prop.key.end)) + "]") : ("." + (prop.key.name));
  5549. handleProperty( code, scope, c, prop.value, ("" + value + value_suffix), inline, statementGenerators );
  5550. c = prop.end;
  5551. }
  5552. code.remove( c, node.end );
  5553. break;
  5554. }
  5555. case 'ArrayPattern': {
  5556. code.remove( c, c = node.start );
  5557. if ( node.elements.filter( Boolean ).length > 1 ) {
  5558. var ref$1 = scope.createIdentifier( value );
  5559. statementGenerators.push( function ( start, prefix, suffix ) {
  5560. code.insertRight( node.start, (prefix + "var " + ref$1 + " = ") );
  5561. code.overwrite( node.start, c = node.start + 1, value );
  5562. code.insertLeft( c, suffix );
  5563. code.move( node.start, c, start );
  5564. });
  5565. node.elements.forEach( function ( element, i ) {
  5566. if ( !element ) return;
  5567. if ( element.type === 'RestElement' ) {
  5568. handleProperty( code, scope, c, element.argument, (ref$1 + ".slice(" + i + ")"), inline, statementGenerators );
  5569. } else {
  5570. handleProperty( code, scope, c, element, (ref$1 + "[" + i + "]"), inline, statementGenerators );
  5571. }
  5572. c = element.end;
  5573. });
  5574. } else {
  5575. var index = findIndex( node.elements, Boolean );
  5576. var element = node.elements[ index ];
  5577. if ( element.type === 'RestElement' ) {
  5578. handleProperty( code, scope, c, element.argument, (value + ".slice(" + index + ")"), inline, statementGenerators );
  5579. } else {
  5580. handleProperty( code, scope, c, element, (value + "[" + index + "]"), inline, statementGenerators );
  5581. }
  5582. c = element.end;
  5583. }
  5584. code.remove( c, node.end );
  5585. break;
  5586. }
  5587. default: {
  5588. throw new Error( ("Unexpected node type in destructuring (" + (node.type) + ")") );
  5589. }
  5590. }
  5591. }
  5592. var ForOfStatement = (function (LoopStatement$$1) {
  5593. function ForOfStatement () {
  5594. LoopStatement$$1.apply(this, arguments);
  5595. }
  5596. if ( LoopStatement$$1 ) ForOfStatement.__proto__ = LoopStatement$$1;
  5597. ForOfStatement.prototype = Object.create( LoopStatement$$1 && LoopStatement$$1.prototype );
  5598. ForOfStatement.prototype.constructor = ForOfStatement;
  5599. ForOfStatement.prototype.initialise = function initialise ( transforms ) {
  5600. 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' );
  5601. LoopStatement$$1.prototype.initialise.call( this, transforms );
  5602. };
  5603. ForOfStatement.prototype.transpile = function transpile ( code, transforms ) {
  5604. if ( !transforms.dangerousForOf ) {
  5605. LoopStatement$$1.prototype.transpile.call( this, code, transforms );
  5606. return;
  5607. }
  5608. // edge case (#80)
  5609. if ( !this.body.body[0] ) {
  5610. if ( this.left.type === 'VariableDeclaration' && this.left.kind === 'var' ) {
  5611. code.remove( this.start, this.left.start );
  5612. code.insertLeft( this.left.end, ';' );
  5613. code.remove( this.left.end, this.end );
  5614. } else {
  5615. code.remove( this.start, this.end );
  5616. }
  5617. return;
  5618. }
  5619. var scope = this.findScope( true );
  5620. var i0 = this.getIndentation();
  5621. var i1 = i0 + code.getIndentString();
  5622. var key = scope.createIdentifier( 'i' );
  5623. var list = scope.createIdentifier( 'list' );
  5624. if ( this.body.synthetic ) {
  5625. code.insertRight( this.left.start, ("{\n" + i1) );
  5626. code.insertLeft( this.body.body[0].end, ("\n" + i0 + "}") );
  5627. }
  5628. var bodyStart = this.body.body[0].start;
  5629. code.remove( this.left.end, this.right.start );
  5630. code.move( this.left.start, this.left.end, bodyStart );
  5631. code.insertRight( this.right.start, ("var " + key + " = 0, " + list + " = ") );
  5632. code.insertLeft( this.right.end, ("; " + key + " < " + list + ".length; " + key + " += 1") );
  5633. // destructuring. TODO non declaration destructuring
  5634. var declarator = this.left.type === 'VariableDeclaration' && this.left.declarations[0];
  5635. if ( declarator && declarator.id.type !== 'Identifier' ) {
  5636. var statementGenerators = [];
  5637. var ref = scope.createIdentifier( 'ref' );
  5638. destructure( code, scope, declarator.id, ref, false, statementGenerators );
  5639. var suffix = ";\n" + i1;
  5640. statementGenerators.forEach( function ( fn, i ) {
  5641. if ( i === statementGenerators.length - 1 ) {
  5642. suffix = ";\n\n" + i1;
  5643. }
  5644. fn( bodyStart, '', suffix );
  5645. });
  5646. code.insertLeft( this.left.start + this.left.kind.length + 1, ref );
  5647. code.insertLeft( this.left.end, (" = " + list + "[" + key + "];\n" + i1) );
  5648. } else {
  5649. code.insertLeft( this.left.end, (" = " + list + "[" + key + "];\n\n" + i1) );
  5650. }
  5651. LoopStatement$$1.prototype.transpile.call( this, code, transforms );
  5652. };
  5653. return ForOfStatement;
  5654. }(LoopStatement));
  5655. var FunctionDeclaration = (function (Node$$1) {
  5656. function FunctionDeclaration () {
  5657. Node$$1.apply(this, arguments);
  5658. }
  5659. if ( Node$$1 ) FunctionDeclaration.__proto__ = Node$$1;
  5660. FunctionDeclaration.prototype = Object.create( Node$$1 && Node$$1.prototype );
  5661. FunctionDeclaration.prototype.constructor = FunctionDeclaration;
  5662. FunctionDeclaration.prototype.initialise = function initialise ( transforms ) {
  5663. if ( this.generator && transforms.generator ) {
  5664. throw new CompileError( this, 'Generators are not supported' );
  5665. }
  5666. this.body.createScope();
  5667. this.findScope( true ).addDeclaration( this.id, 'function' );
  5668. Node$$1.prototype.initialise.call( this, transforms );
  5669. };
  5670. return FunctionDeclaration;
  5671. }(Node));
  5672. var FunctionExpression = (function (Node$$1) {
  5673. function FunctionExpression () {
  5674. Node$$1.apply(this, arguments);
  5675. }
  5676. if ( Node$$1 ) FunctionExpression.__proto__ = Node$$1;
  5677. FunctionExpression.prototype = Object.create( Node$$1 && Node$$1.prototype );
  5678. FunctionExpression.prototype.constructor = FunctionExpression;
  5679. FunctionExpression.prototype.initialise = function initialise ( transforms ) {
  5680. if ( this.generator && transforms.generator ) {
  5681. throw new CompileError( this, 'Generators are not supported' );
  5682. }
  5683. this.body.createScope();
  5684. if ( this.id ) {
  5685. // function expression IDs belong to the child scope...
  5686. this.body.scope.addDeclaration( this.id, 'function' );
  5687. }
  5688. Node$$1.prototype.initialise.call( this, transforms );
  5689. var parent = this.parent;
  5690. var methodName;
  5691. if ( transforms.conciseMethodProperty
  5692. && parent.type === 'Property'
  5693. && parent.kind === 'init'
  5694. && parent.method
  5695. && parent.key.type === 'Identifier' ) {
  5696. // object literal concise method
  5697. methodName = parent.key.name;
  5698. }
  5699. else if ( transforms.classes
  5700. && parent.type === 'MethodDefinition'
  5701. && parent.kind === 'method'
  5702. && parent.key.type === 'Identifier' ) {
  5703. // method definition in a class
  5704. methodName = parent.key.name;
  5705. }
  5706. else if ( this.id && this.id.type === 'Identifier' ) {
  5707. // naked function expression
  5708. methodName = this.id.alias || this.id.name;
  5709. }
  5710. if ( methodName ) {
  5711. for ( var i = 0, list = this.params; i < list.length; i += 1 ) {
  5712. var param = list[i];
  5713. if ( param.type === 'Identifier' && methodName === param.name ) {
  5714. // workaround for Safari 9/WebKit bug:
  5715. // https://gitlab.com/Rich-Harris/buble/issues/154
  5716. // change parameter name when same as method name
  5717. var scope = this.body.scope;
  5718. var declaration = scope.declarations[ methodName ];
  5719. var alias = scope.createIdentifier( methodName );
  5720. param.alias = alias;
  5721. for ( var i$1 = 0, list$1 = declaration.instances; i$1 < list$1.length; i$1 += 1 ) {
  5722. var identifier = list$1[i$1];
  5723. identifier.alias = alias;
  5724. }
  5725. break;
  5726. }
  5727. }
  5728. }
  5729. };
  5730. return FunctionExpression;
  5731. }(Node));
  5732. function isReference ( node, parent ) {
  5733. if ( node.type === 'MemberExpression' ) {
  5734. return !node.computed && isReference( node.object, node );
  5735. }
  5736. if ( node.type === 'Identifier' ) {
  5737. // the only time we could have an identifier node without a parent is
  5738. // if it's the entire body of a function without a block statement –
  5739. // i.e. an arrow function expression like `a => a`
  5740. if ( !parent ) return true;
  5741. if ( /(Function|Class)Expression/.test( parent.type ) ) return false;
  5742. if ( parent.type === 'VariableDeclarator' ) return node === parent.init;
  5743. // TODO is this right?
  5744. if ( parent.type === 'MemberExpression' || parent.type === 'MethodDefinition' ) {
  5745. return parent.computed || node === parent.object;
  5746. }
  5747. if ( parent.type === 'ArrayPattern' ) return false;
  5748. // disregard the `bar` in `{ bar: foo }`, but keep it in `{ [bar]: foo }`
  5749. if ( parent.type === 'Property' ) {
  5750. if ( parent.parent.type === 'ObjectPattern' ) return false;
  5751. return parent.computed || node === parent.value;
  5752. }
  5753. // disregard the `bar` in `class Foo { bar () {...} }`
  5754. if ( parent.type === 'MethodDefinition' ) return false;
  5755. // disregard the `bar` in `export { foo as bar }`
  5756. if ( parent.type === 'ExportSpecifier' && node !== parent.local ) return false;
  5757. return true;
  5758. }
  5759. }
  5760. // allowed globals in Vue render functions.
  5761. // same as in src/core/instance/proxy.js
  5762. var names = 'Infinity,undefined,NaN,isFinite,isNaN,' +
  5763. 'parseFloat,parseInt,decodeURI,decodeURIComponent,encodeURI,encodeURIComponent,' +
  5764. 'Math,Number,Date,Array,Object,Boolean,String,RegExp,Map,Set,JSON,Intl,' +
  5765. 'require,' + // for webpack
  5766. 'arguments,' + // parsed as identifier but is a special keyword...
  5767. '_h,_c'; // cached to save property access (_c for ^2.1.5)
  5768. var hash = Object.create(null);
  5769. names.split(',').forEach(function ( name ) {
  5770. hash[name] = true;
  5771. });
  5772. var isDeclaration = function ( type ) { return /Declaration$/.test(type); };
  5773. var isFunction = function ( type ) { return /Function(Expression|Declaration)$/.test(type); };
  5774. var Identifier$1 = (function (Node$$1) {
  5775. function Identifier () {
  5776. Node$$1.apply(this, arguments);
  5777. }
  5778. if ( Node$$1 ) Identifier.__proto__ = Node$$1;
  5779. Identifier.prototype = Object.create( Node$$1 && Node$$1.prototype );
  5780. Identifier.prototype.constructor = Identifier;
  5781. Identifier.prototype.findScope = function findScope ( functionScope ) {
  5782. if ( this.parent.params && ~this.parent.params.indexOf( this ) ) {
  5783. return this.parent.body.scope;
  5784. }
  5785. if ( this.parent.type === 'FunctionExpression' && this === this.parent.id ) {
  5786. return this.parent.body.scope;
  5787. }
  5788. return this.parent.findScope( functionScope );
  5789. };
  5790. Identifier.prototype.initialise = function initialise ( transforms ) {
  5791. if ( transforms.arrow && isReference( this, this.parent ) ) {
  5792. if ( this.name === 'arguments' && !this.findScope( false ).contains( this.name ) ) {
  5793. var lexicalBoundary = this.findLexicalBoundary();
  5794. var arrowFunction = this.findNearest( 'ArrowFunctionExpression' );
  5795. var loop = this.findNearest( loopStatement );
  5796. if ( arrowFunction && arrowFunction.depth > lexicalBoundary.depth ) {
  5797. this.alias = lexicalBoundary.getArgumentsAlias();
  5798. }
  5799. if ( loop && loop.body.contains( this ) && loop.depth > lexicalBoundary.depth ) {
  5800. this.alias = lexicalBoundary.getArgumentsAlias();
  5801. }
  5802. }
  5803. this.findScope( false ).addReference( this );
  5804. }
  5805. };
  5806. Identifier.prototype.transpile = function transpile ( code, transforms ) {
  5807. if ( this.alias ) {
  5808. code.overwrite( this.start, this.end, this.alias, true );
  5809. }
  5810. // rewrite identifiers inside Vue render function `with` blocks
  5811. if (
  5812. this.program.inWith > 0 &&
  5813. // not id of a Declaration
  5814. !(isDeclaration(this.parent.type) && this.parent.id === this) &&
  5815. // not a params of a function
  5816. !(isFunction(this.parent.type) && this.parent.params.indexOf(this) > -1) &&
  5817. // not a key of Property
  5818. !(this.parent.type === 'Property' && this.parent.key === this && !this.parent.computed) &&
  5819. // not a property of a MemberExpression
  5820. !(this.parent.type === 'MemberExpression' && this.parent.property === this && !this.parent.computed) &&
  5821. // not in an Array destructure pattern
  5822. !(this.parent.type === 'ArrayPattern') &&
  5823. // not in an Object destructure pattern
  5824. !(this.parent.parent.type === 'ObjectPattern') &&
  5825. // skip globals + commonly used shorthands
  5826. !hash[this.name] &&
  5827. // not already in scope
  5828. !this.findScope(false).contains(this.name)
  5829. ) {
  5830. code.overwrite(this.start, this.end, ("_vm." + (this.name)));
  5831. }
  5832. };
  5833. return Identifier;
  5834. }(Node));
  5835. var IfStatement = (function (Node$$1) {
  5836. function IfStatement () {
  5837. Node$$1.apply(this, arguments);
  5838. }
  5839. if ( Node$$1 ) IfStatement.__proto__ = Node$$1;
  5840. IfStatement.prototype = Object.create( Node$$1 && Node$$1.prototype );
  5841. IfStatement.prototype.constructor = IfStatement;
  5842. IfStatement.prototype.initialise = function initialise ( transforms ) {
  5843. Node$$1.prototype.initialise.call( this, transforms );
  5844. };
  5845. IfStatement.prototype.transpile = function transpile ( code, transforms ) {
  5846. if ( this.consequent.type !== 'BlockStatement'
  5847. || this.consequent.type === 'BlockStatement' && this.consequent.synthetic ) {
  5848. code.insertLeft( this.consequent.start, '{ ' );
  5849. code.insertRight( this.consequent.end, ' }' );
  5850. }
  5851. if ( this.alternate && this.alternate.type !== 'IfStatement' && (
  5852. this.alternate.type !== 'BlockStatement'
  5853. || this.alternate.type === 'BlockStatement' && this.alternate.synthetic ) ) {
  5854. code.insertLeft( this.alternate.start, '{ ' );
  5855. code.insertRight( this.alternate.end, ' }' );
  5856. }
  5857. Node$$1.prototype.transpile.call( this, code, transforms );
  5858. };
  5859. return IfStatement;
  5860. }(Node));
  5861. var ImportDeclaration = (function (Node$$1) {
  5862. function ImportDeclaration () {
  5863. Node$$1.apply(this, arguments);
  5864. }
  5865. if ( Node$$1 ) ImportDeclaration.__proto__ = Node$$1;
  5866. ImportDeclaration.prototype = Object.create( Node$$1 && Node$$1.prototype );
  5867. ImportDeclaration.prototype.constructor = ImportDeclaration;
  5868. ImportDeclaration.prototype.initialise = function initialise ( transforms ) {
  5869. if ( transforms.moduleImport ) throw new CompileError( this, 'import is not supported' );
  5870. Node$$1.prototype.initialise.call( this, transforms );
  5871. };
  5872. return ImportDeclaration;
  5873. }(Node));
  5874. var ImportDefaultSpecifier = (function (Node$$1) {
  5875. function ImportDefaultSpecifier () {
  5876. Node$$1.apply(this, arguments);
  5877. }
  5878. if ( Node$$1 ) ImportDefaultSpecifier.__proto__ = Node$$1;
  5879. ImportDefaultSpecifier.prototype = Object.create( Node$$1 && Node$$1.prototype );
  5880. ImportDefaultSpecifier.prototype.constructor = ImportDefaultSpecifier;
  5881. ImportDefaultSpecifier.prototype.initialise = function initialise ( transforms ) {
  5882. this.findScope( true ).addDeclaration( this.local, 'import' );
  5883. Node$$1.prototype.initialise.call( this, transforms );
  5884. };
  5885. return ImportDefaultSpecifier;
  5886. }(Node));
  5887. var ImportSpecifier = (function (Node$$1) {
  5888. function ImportSpecifier () {
  5889. Node$$1.apply(this, arguments);
  5890. }
  5891. if ( Node$$1 ) ImportSpecifier.__proto__ = Node$$1;
  5892. ImportSpecifier.prototype = Object.create( Node$$1 && Node$$1.prototype );
  5893. ImportSpecifier.prototype.constructor = ImportSpecifier;
  5894. ImportSpecifier.prototype.initialise = function initialise ( transforms ) {
  5895. this.findScope( true ).addDeclaration( this.local, 'import' );
  5896. Node$$1.prototype.initialise.call( this, transforms );
  5897. };
  5898. return ImportSpecifier;
  5899. }(Node));
  5900. var IS_DATA_ATTRIBUTE = /-/;
  5901. var JSXAttribute = (function (Node$$1) {
  5902. function JSXAttribute () {
  5903. Node$$1.apply(this, arguments);
  5904. }
  5905. if ( Node$$1 ) JSXAttribute.__proto__ = Node$$1;
  5906. JSXAttribute.prototype = Object.create( Node$$1 && Node$$1.prototype );
  5907. JSXAttribute.prototype.constructor = JSXAttribute;
  5908. JSXAttribute.prototype.transpile = function transpile ( code, transforms ) {
  5909. if ( this.value ) {
  5910. code.overwrite( this.name.end, this.value.start, ': ' );
  5911. } else {
  5912. // tag without value
  5913. code.overwrite( this.name.start, this.name.end, ((this.name.name) + ": true") );
  5914. }
  5915. if ( IS_DATA_ATTRIBUTE.test( this.name.name ) ) {
  5916. code.overwrite( this.name.start, this.name.end, ("'" + (this.name.name) + "'") );
  5917. }
  5918. Node$$1.prototype.transpile.call( this, code, transforms );
  5919. };
  5920. return JSXAttribute;
  5921. }(Node));
  5922. function containsNewLine ( node ) {
  5923. return node.type === 'Literal' && !/\S/.test( node.value ) && /\n/.test( node.value );
  5924. }
  5925. var JSXClosingElement = (function (Node$$1) {
  5926. function JSXClosingElement () {
  5927. Node$$1.apply(this, arguments);
  5928. }
  5929. if ( Node$$1 ) JSXClosingElement.__proto__ = Node$$1;
  5930. JSXClosingElement.prototype = Object.create( Node$$1 && Node$$1.prototype );
  5931. JSXClosingElement.prototype.constructor = JSXClosingElement;
  5932. JSXClosingElement.prototype.transpile = function transpile ( code ) {
  5933. var spaceBeforeParen = true;
  5934. var lastChild = this.parent.children[ this.parent.children.length - 1 ];
  5935. // omit space before closing paren if
  5936. // a) this is on a separate line, or
  5937. // b) there are no children but there are attributes
  5938. if ( ( lastChild && containsNewLine( lastChild ) ) || ( this.parent.openingElement.attributes.length ) ) {
  5939. spaceBeforeParen = false;
  5940. }
  5941. code.overwrite( this.start, this.end, spaceBeforeParen ? ' )' : ')' );
  5942. };
  5943. return JSXClosingElement;
  5944. }(Node));
  5945. function normalise ( str, removeTrailingWhitespace ) {
  5946. if ( removeTrailingWhitespace && /\n/.test( str ) ) {
  5947. str = str.replace( /\s+$/, '' );
  5948. }
  5949. str = str
  5950. .replace( /^\n\r?\s+/, '' ) // remove leading newline + space
  5951. .replace( /\s*\n\r?\s*/gm, ' ' ); // replace newlines with spaces
  5952. // TODO prefer single quotes?
  5953. return JSON.stringify( str );
  5954. }
  5955. var JSXElement = (function (Node$$1) {
  5956. function JSXElement () {
  5957. Node$$1.apply(this, arguments);
  5958. }
  5959. if ( Node$$1 ) JSXElement.__proto__ = Node$$1;
  5960. JSXElement.prototype = Object.create( Node$$1 && Node$$1.prototype );
  5961. JSXElement.prototype.constructor = JSXElement;
  5962. JSXElement.prototype.transpile = function transpile ( code, transforms ) {
  5963. Node$$1.prototype.transpile.call( this, code, transforms );
  5964. var children = this.children.filter( function ( child ) {
  5965. if ( child.type !== 'Literal' ) return true;
  5966. // remove whitespace-only literals, unless on a single line
  5967. return /\S/.test( child.value ) || !/\n/.test( child.value );
  5968. });
  5969. if ( children.length ) {
  5970. var c = this.openingElement.end;
  5971. var i;
  5972. for ( i = 0; i < children.length; i += 1 ) {
  5973. var child = children[i];
  5974. if ( child.type === 'JSXExpressionContainer' && child.expression.type === 'JSXEmptyExpression' ) {
  5975. // empty block is a no op
  5976. } else {
  5977. var tail = code.original[ c ] === '\n' && child.type !== 'Literal' ? '' : ' ';
  5978. code.insertLeft( c, ("," + tail) );
  5979. }
  5980. if ( child.type === 'Literal' ) {
  5981. var str = normalise( child.value, i === children.length - 1 );
  5982. code.overwrite( child.start, child.end, str );
  5983. }
  5984. c = child.end;
  5985. }
  5986. }
  5987. };
  5988. return JSXElement;
  5989. }(Node));
  5990. var JSXExpressionContainer = (function (Node$$1) {
  5991. function JSXExpressionContainer () {
  5992. Node$$1.apply(this, arguments);
  5993. }
  5994. if ( Node$$1 ) JSXExpressionContainer.__proto__ = Node$$1;
  5995. JSXExpressionContainer.prototype = Object.create( Node$$1 && Node$$1.prototype );
  5996. JSXExpressionContainer.prototype.constructor = JSXExpressionContainer;
  5997. JSXExpressionContainer.prototype.transpile = function transpile ( code, transforms ) {
  5998. code.remove( this.start, this.expression.start );
  5999. code.remove( this.expression.end, this.end );
  6000. Node$$1.prototype.transpile.call( this, code, transforms );
  6001. };
  6002. return JSXExpressionContainer;
  6003. }(Node));
  6004. var JSXOpeningElement = (function (Node$$1) {
  6005. function JSXOpeningElement () {
  6006. Node$$1.apply(this, arguments);
  6007. }
  6008. if ( Node$$1 ) JSXOpeningElement.__proto__ = Node$$1;
  6009. JSXOpeningElement.prototype = Object.create( Node$$1 && Node$$1.prototype );
  6010. JSXOpeningElement.prototype.constructor = JSXOpeningElement;
  6011. JSXOpeningElement.prototype.transpile = function transpile ( code, transforms ) {
  6012. var this$1 = this;
  6013. code.overwrite( this.start, this.name.start, ((this.program.jsx) + "( ") );
  6014. var html = this.name.type === 'JSXIdentifier' && this.name.name[0] === this.name.name[0].toLowerCase();
  6015. if ( html ) code.insertRight( this.name.start, "'" );
  6016. var len = this.attributes.length;
  6017. var c = this.name.end;
  6018. if ( len ) {
  6019. var i;
  6020. var hasSpread = false;
  6021. for ( i = 0; i < len; i += 1 ) {
  6022. if ( this$1.attributes[i].type === 'JSXSpreadAttribute' ) {
  6023. hasSpread = true;
  6024. break;
  6025. }
  6026. }
  6027. c = this.attributes[0].end;
  6028. for ( i = 0; i < len; i += 1 ) {
  6029. var attr = this$1.attributes[i];
  6030. if ( i > 0 ) {
  6031. code.overwrite( c, attr.start, ', ' );
  6032. }
  6033. if ( hasSpread && attr.type !== 'JSXSpreadAttribute' ) {
  6034. var lastAttr = this$1.attributes[ i - 1 ];
  6035. var nextAttr = this$1.attributes[ i + 1 ];
  6036. if ( !lastAttr || lastAttr.type === 'JSXSpreadAttribute' ) {
  6037. code.insertRight( attr.start, '{ ' );
  6038. }
  6039. if ( !nextAttr || nextAttr.type === 'JSXSpreadAttribute' ) {
  6040. code.insertLeft( attr.end, ' }' );
  6041. }
  6042. }
  6043. c = attr.end;
  6044. }
  6045. var after;
  6046. var before;
  6047. if ( hasSpread ) {
  6048. if ( len === 1 ) {
  6049. before = html ? "'," : ',';
  6050. } else {
  6051. if (!this.program.options.objectAssign) {
  6052. throw new CompileError( this, 'Mixed JSX attributes ending in spread requires specified objectAssign option with \'Object.assign\' or polyfill helper.' );
  6053. }
  6054. before = html ? ("', " + (this.program.options.objectAssign) + "({},") : (", " + (this.program.options.objectAssign) + "({},");
  6055. after = ')';
  6056. }
  6057. } else {
  6058. before = html ? "', {" : ', {';
  6059. after = ' }';
  6060. }
  6061. code.insertRight( this.name.end, before );
  6062. if ( after ) {
  6063. code.insertLeft( this.attributes[ len - 1 ].end, after );
  6064. }
  6065. } else {
  6066. code.insertLeft( this.name.end, html ? "', null" : ", null" );
  6067. c = this.name.end;
  6068. }
  6069. Node$$1.prototype.transpile.call( this, code, transforms );
  6070. if ( this.selfClosing ) {
  6071. code.overwrite( c, this.end, this.attributes.length ? ")" : " )" );
  6072. } else {
  6073. code.remove( c, this.end );
  6074. }
  6075. };
  6076. return JSXOpeningElement;
  6077. }(Node));
  6078. var JSXSpreadAttribute = (function (Node$$1) {
  6079. function JSXSpreadAttribute () {
  6080. Node$$1.apply(this, arguments);
  6081. }
  6082. if ( Node$$1 ) JSXSpreadAttribute.__proto__ = Node$$1;
  6083. JSXSpreadAttribute.prototype = Object.create( Node$$1 && Node$$1.prototype );
  6084. JSXSpreadAttribute.prototype.constructor = JSXSpreadAttribute;
  6085. JSXSpreadAttribute.prototype.transpile = function transpile ( code, transforms ) {
  6086. code.remove( this.start, this.argument.start );
  6087. code.remove( this.argument.end, this.end );
  6088. Node$$1.prototype.transpile.call( this, code, transforms );
  6089. };
  6090. return JSXSpreadAttribute;
  6091. }(Node));
  6092. var regenerate = __commonjs(function (module, exports, global) {
  6093. /*! https://mths.be/regenerate v1.3.2 by @mathias | MIT license */
  6094. (function(root) {
  6095. // Detect free variables `exports`.
  6096. var freeExports = typeof exports == 'object' && exports;
  6097. // Detect free variable `module`.
  6098. var freeModule = typeof module == 'object' && module &&
  6099. module.exports == freeExports && module;
  6100. // Detect free variable `global`, from Node.js/io.js or Browserified code,
  6101. // and use it as `root`.
  6102. var freeGlobal = typeof global == 'object' && global;
  6103. if (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal) {
  6104. root = freeGlobal;
  6105. }
  6106. /*--------------------------------------------------------------------------*/
  6107. var ERRORS = {
  6108. 'rangeOrder': 'A range\u2019s `stop` value must be greater than or equal ' +
  6109. 'to the `start` value.',
  6110. 'codePointRange': 'Invalid code point value. Code points range from ' +
  6111. 'U+000000 to U+10FFFF.'
  6112. };
  6113. // https://mathiasbynens.be/notes/javascript-encoding#surrogate-pairs
  6114. var HIGH_SURROGATE_MIN = 0xD800;
  6115. var HIGH_SURROGATE_MAX = 0xDBFF;
  6116. var LOW_SURROGATE_MIN = 0xDC00;
  6117. var LOW_SURROGATE_MAX = 0xDFFF;
  6118. // In Regenerate output, `\0` is never preceded by `\` because we sort by
  6119. // code point value, so let’s keep this regular expression simple.
  6120. var regexNull = /\\x00([^0123456789]|$)/g;
  6121. var object = {};
  6122. var hasOwnProperty = object.hasOwnProperty;
  6123. var extend = function(destination, source) {
  6124. var key;
  6125. for (key in source) {
  6126. if (hasOwnProperty.call(source, key)) {
  6127. destination[key] = source[key];
  6128. }
  6129. }
  6130. return destination;
  6131. };
  6132. var forEach = function(array, callback) {
  6133. var index = -1;
  6134. var length = array.length;
  6135. while (++index < length) {
  6136. callback(array[index], index);
  6137. }
  6138. };
  6139. var toString = object.toString;
  6140. var isArray = function(value) {
  6141. return toString.call(value) == '[object Array]';
  6142. };
  6143. var isNumber = function(value) {
  6144. return typeof value == 'number' ||
  6145. toString.call(value) == '[object Number]';
  6146. };
  6147. // This assumes that `number` is a positive integer that `toString()`s nicely
  6148. // (which is the case for all code point values).
  6149. var zeroes = '0000';
  6150. var pad = function(number, totalCharacters) {
  6151. var string = String(number);
  6152. return string.length < totalCharacters
  6153. ? (zeroes + string).slice(-totalCharacters)
  6154. : string;
  6155. };
  6156. var hex = function(number) {
  6157. return Number(number).toString(16).toUpperCase();
  6158. };
  6159. var slice = [].slice;
  6160. /*--------------------------------------------------------------------------*/
  6161. var dataFromCodePoints = function(codePoints) {
  6162. var index = -1;
  6163. var length = codePoints.length;
  6164. var max = length - 1;
  6165. var result = [];
  6166. var isStart = true;
  6167. var tmp;
  6168. var previous = 0;
  6169. while (++index < length) {
  6170. tmp = codePoints[index];
  6171. if (isStart) {
  6172. result.push(tmp);
  6173. previous = tmp;
  6174. isStart = false;
  6175. } else {
  6176. if (tmp == previous + 1) {
  6177. if (index != max) {
  6178. previous = tmp;
  6179. continue;
  6180. } else {
  6181. isStart = true;
  6182. result.push(tmp + 1);
  6183. }
  6184. } else {
  6185. // End the previous range and start a new one.
  6186. result.push(previous + 1, tmp);
  6187. previous = tmp;
  6188. }
  6189. }
  6190. }
  6191. if (!isStart) {
  6192. result.push(tmp + 1);
  6193. }
  6194. return result;
  6195. };
  6196. var dataRemove = function(data, codePoint) {
  6197. // Iterate over the data per `(start, end)` pair.
  6198. var index = 0;
  6199. var start;
  6200. var end;
  6201. var length = data.length;
  6202. while (index < length) {
  6203. start = data[index];
  6204. end = data[index + 1];
  6205. if (codePoint >= start && codePoint < end) {
  6206. // Modify this pair.
  6207. if (codePoint == start) {
  6208. if (end == start + 1) {
  6209. // Just remove `start` and `end`.
  6210. data.splice(index, 2);
  6211. return data;
  6212. } else {
  6213. // Just replace `start` with a new value.
  6214. data[index] = codePoint + 1;
  6215. return data;
  6216. }
  6217. } else if (codePoint == end - 1) {
  6218. // Just replace `end` with a new value.
  6219. data[index + 1] = codePoint;
  6220. return data;
  6221. } else {
  6222. // Replace `[start, end]` with `[startA, endA, startB, endB]`.
  6223. data.splice(index, 2, start, codePoint, codePoint + 1, end);
  6224. return data;
  6225. }
  6226. }
  6227. index += 2;
  6228. }
  6229. return data;
  6230. };
  6231. var dataRemoveRange = function(data, rangeStart, rangeEnd) {
  6232. if (rangeEnd < rangeStart) {
  6233. throw Error(ERRORS.rangeOrder);
  6234. }
  6235. // Iterate over the data per `(start, end)` pair.
  6236. var index = 0;
  6237. var start;
  6238. var end;
  6239. while (index < data.length) {
  6240. start = data[index];
  6241. end = data[index + 1] - 1; // Note: the `- 1` makes `end` inclusive.
  6242. // Exit as soon as no more matching pairs can be found.
  6243. if (start > rangeEnd) {
  6244. return data;
  6245. }
  6246. // Check if this range pair is equal to, or forms a subset of, the range
  6247. // to be removed.
  6248. // E.g. we have `[0, 11, 40, 51]` and want to remove 0-10 → `[40, 51]`.
  6249. // E.g. we have `[40, 51]` and want to remove 0-100 → `[]`.
  6250. if (rangeStart <= start && rangeEnd >= end) {
  6251. // Remove this pair.
  6252. data.splice(index, 2);
  6253. continue;
  6254. }
  6255. // Check if both `rangeStart` and `rangeEnd` are within the bounds of
  6256. // this pair.
  6257. // E.g. we have `[0, 11]` and want to remove 4-6 → `[0, 4, 7, 11]`.
  6258. if (rangeStart >= start && rangeEnd < end) {
  6259. if (rangeStart == start) {
  6260. // Replace `[start, end]` with `[startB, endB]`.
  6261. data[index] = rangeEnd + 1;
  6262. data[index + 1] = end + 1;
  6263. return data;
  6264. }
  6265. // Replace `[start, end]` with `[startA, endA, startB, endB]`.
  6266. data.splice(index, 2, start, rangeStart, rangeEnd + 1, end + 1);
  6267. return data;
  6268. }
  6269. // Check if only `rangeStart` is within the bounds of this pair.
  6270. // E.g. we have `[0, 11]` and want to remove 4-20 → `[0, 4]`.
  6271. if (rangeStart >= start && rangeStart <= end) {
  6272. // Replace `end` with `rangeStart`.
  6273. data[index + 1] = rangeStart;
  6274. // Note: we cannot `return` just yet, in case any following pairs still
  6275. // contain matching code points.
  6276. // E.g. we have `[0, 11, 14, 31]` and want to remove 4-20
  6277. // → `[0, 4, 21, 31]`.
  6278. }
  6279. // Check if only `rangeEnd` is within the bounds of this pair.
  6280. // E.g. we have `[14, 31]` and want to remove 4-20 → `[21, 31]`.
  6281. else if (rangeEnd >= start && rangeEnd <= end) {
  6282. // Just replace `start`.
  6283. data[index] = rangeEnd + 1;
  6284. return data;
  6285. }
  6286. index += 2;
  6287. }
  6288. return data;
  6289. };
  6290. var dataAdd = function(data, codePoint) {
  6291. // Iterate over the data per `(start, end)` pair.
  6292. var index = 0;
  6293. var start;
  6294. var end;
  6295. var lastIndex = null;
  6296. var length = data.length;
  6297. if (codePoint < 0x0 || codePoint > 0x10FFFF) {
  6298. throw RangeError(ERRORS.codePointRange);
  6299. }
  6300. while (index < length) {
  6301. start = data[index];
  6302. end = data[index + 1];
  6303. // Check if the code point is already in the set.
  6304. if (codePoint >= start && codePoint < end) {
  6305. return data;
  6306. }
  6307. if (codePoint == start - 1) {
  6308. // Just replace `start` with a new value.
  6309. data[index] = codePoint;
  6310. return data;
  6311. }
  6312. // At this point, if `start` is `greater` than `codePoint`, insert a new
  6313. // `[start, end]` pair before the current pair, or after the current pair
  6314. // if there is a known `lastIndex`.
  6315. if (start > codePoint) {
  6316. data.splice(
  6317. lastIndex != null ? lastIndex + 2 : 0,
  6318. 0,
  6319. codePoint,
  6320. codePoint + 1
  6321. );
  6322. return data;
  6323. }
  6324. if (codePoint == end) {
  6325. // Check if adding this code point causes two separate ranges to become
  6326. // a single range, e.g. `dataAdd([0, 4, 5, 10], 4)` → `[0, 10]`.
  6327. if (codePoint + 1 == data[index + 2]) {
  6328. data.splice(index, 4, start, data[index + 3]);
  6329. return data;
  6330. }
  6331. // Else, just replace `end` with a new value.
  6332. data[index + 1] = codePoint + 1;
  6333. return data;
  6334. }
  6335. lastIndex = index;
  6336. index += 2;
  6337. }
  6338. // The loop has finished; add the new pair to the end of the data set.
  6339. data.push(codePoint, codePoint + 1);
  6340. return data;
  6341. };
  6342. var dataAddData = function(dataA, dataB) {
  6343. // Iterate over the data per `(start, end)` pair.
  6344. var index = 0;
  6345. var start;
  6346. var end;
  6347. var data = dataA.slice();
  6348. var length = dataB.length;
  6349. while (index < length) {
  6350. start = dataB[index];
  6351. end = dataB[index + 1] - 1;
  6352. if (start == end) {
  6353. data = dataAdd(data, start);
  6354. } else {
  6355. data = dataAddRange(data, start, end);
  6356. }
  6357. index += 2;
  6358. }
  6359. return data;
  6360. };
  6361. var dataRemoveData = function(dataA, dataB) {
  6362. // Iterate over the data per `(start, end)` pair.
  6363. var index = 0;
  6364. var start;
  6365. var end;
  6366. var data = dataA.slice();
  6367. var length = dataB.length;
  6368. while (index < length) {
  6369. start = dataB[index];
  6370. end = dataB[index + 1] - 1;
  6371. if (start == end) {
  6372. data = dataRemove(data, start);
  6373. } else {
  6374. data = dataRemoveRange(data, start, end);
  6375. }
  6376. index += 2;
  6377. }
  6378. return data;
  6379. };
  6380. var dataAddRange = function(data, rangeStart, rangeEnd) {
  6381. if (rangeEnd < rangeStart) {
  6382. throw Error(ERRORS.rangeOrder);
  6383. }
  6384. if (
  6385. rangeStart < 0x0 || rangeStart > 0x10FFFF ||
  6386. rangeEnd < 0x0 || rangeEnd > 0x10FFFF
  6387. ) {
  6388. throw RangeError(ERRORS.codePointRange);
  6389. }
  6390. // Iterate over the data per `(start, end)` pair.
  6391. var index = 0;
  6392. var start;
  6393. var end;
  6394. var added = false;
  6395. var length = data.length;
  6396. while (index < length) {
  6397. start = data[index];
  6398. end = data[index + 1];
  6399. if (added) {
  6400. // The range has already been added to the set; at this point, we just
  6401. // need to get rid of the following ranges in case they overlap.
  6402. // Check if this range can be combined with the previous range.
  6403. if (start == rangeEnd + 1) {
  6404. data.splice(index - 1, 2);
  6405. return data;
  6406. }
  6407. // Exit as soon as no more possibly overlapping pairs can be found.
  6408. if (start > rangeEnd) {
  6409. return data;
  6410. }
  6411. // E.g. `[0, 11, 12, 16]` and we’ve added 5-15, so we now have
  6412. // `[0, 16, 12, 16]`. Remove the `12,16` part, as it lies within the
  6413. // `0,16` range that was previously added.
  6414. if (start >= rangeStart && start <= rangeEnd) {
  6415. // `start` lies within the range that was previously added.
  6416. if (end > rangeStart && end - 1 <= rangeEnd) {
  6417. // `end` lies within the range that was previously added as well,
  6418. // so remove this pair.
  6419. data.splice(index, 2);
  6420. index -= 2;
  6421. // Note: we cannot `return` just yet, as there may still be other
  6422. // overlapping pairs.
  6423. } else {
  6424. // `start` lies within the range that was previously added, but
  6425. // `end` doesn’t. E.g. `[0, 11, 12, 31]` and we’ve added 5-15, so
  6426. // now we have `[0, 16, 12, 31]`. This must be written as `[0, 31]`.
  6427. // Remove the previously added `end` and the current `start`.
  6428. data.splice(index - 1, 2);
  6429. index -= 2;
  6430. }
  6431. // Note: we cannot return yet.
  6432. }
  6433. }
  6434. else if (start == rangeEnd + 1) {
  6435. data[index] = rangeStart;
  6436. return data;
  6437. }
  6438. // Check if a new pair must be inserted *before* the current one.
  6439. else if (start > rangeEnd) {
  6440. data.splice(index, 0, rangeStart, rangeEnd + 1);
  6441. return data;
  6442. }
  6443. else if (rangeStart >= start && rangeStart < end && rangeEnd + 1 <= end) {
  6444. // The new range lies entirely within an existing range pair. No action
  6445. // needed.
  6446. return data;
  6447. }
  6448. else if (
  6449. // E.g. `[0, 11]` and you add 5-15 → `[0, 16]`.
  6450. (rangeStart >= start && rangeStart < end) ||
  6451. // E.g. `[0, 3]` and you add 3-6 → `[0, 7]`.
  6452. end == rangeStart
  6453. ) {
  6454. // Replace `end` with the new value.
  6455. data[index + 1] = rangeEnd + 1;
  6456. // Make sure the next range pair doesn’t overlap, e.g. `[0, 11, 12, 14]`
  6457. // and you add 5-15 → `[0, 16]`, i.e. remove the `12,14` part.
  6458. added = true;
  6459. // Note: we cannot `return` just yet.
  6460. }
  6461. else if (rangeStart <= start && rangeEnd + 1 >= end) {
  6462. // The new range is a superset of the old range.
  6463. data[index] = rangeStart;
  6464. data[index + 1] = rangeEnd + 1;
  6465. added = true;
  6466. }
  6467. index += 2;
  6468. }
  6469. // The loop has finished without doing anything; add the new pair to the end
  6470. // of the data set.
  6471. if (!added) {
  6472. data.push(rangeStart, rangeEnd + 1);
  6473. }
  6474. return data;
  6475. };
  6476. var dataContains = function(data, codePoint) {
  6477. var index = 0;
  6478. var length = data.length;
  6479. // Exit early if `codePoint` is not within `data`’s overall range.
  6480. var start = data[index];
  6481. var end = data[length - 1];
  6482. if (length >= 2) {
  6483. if (codePoint < start || codePoint > end) {
  6484. return false;
  6485. }
  6486. }
  6487. // Iterate over the data per `(start, end)` pair.
  6488. while (index < length) {
  6489. start = data[index];
  6490. end = data[index + 1];
  6491. if (codePoint >= start && codePoint < end) {
  6492. return true;
  6493. }
  6494. index += 2;
  6495. }
  6496. return false;
  6497. };
  6498. var dataIntersection = function(data, codePoints) {
  6499. var index = 0;
  6500. var length = codePoints.length;
  6501. var codePoint;
  6502. var result = [];
  6503. while (index < length) {
  6504. codePoint = codePoints[index];
  6505. if (dataContains(data, codePoint)) {
  6506. result.push(codePoint);
  6507. }
  6508. ++index;
  6509. }
  6510. return dataFromCodePoints(result);
  6511. };
  6512. var dataIsEmpty = function(data) {
  6513. return !data.length;
  6514. };
  6515. var dataIsSingleton = function(data) {
  6516. // Check if the set only represents a single code point.
  6517. return data.length == 2 && data[0] + 1 == data[1];
  6518. };
  6519. var dataToArray = function(data) {
  6520. // Iterate over the data per `(start, end)` pair.
  6521. var index = 0;
  6522. var start;
  6523. var end;
  6524. var result = [];
  6525. var length = data.length;
  6526. while (index < length) {
  6527. start = data[index];
  6528. end = data[index + 1];
  6529. while (start < end) {
  6530. result.push(start);
  6531. ++start;
  6532. }
  6533. index += 2;
  6534. }
  6535. return result;
  6536. };
  6537. /*--------------------------------------------------------------------------*/
  6538. // https://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
  6539. var floor = Math.floor;
  6540. var highSurrogate = function(codePoint) {
  6541. return parseInt(
  6542. floor((codePoint - 0x10000) / 0x400) + HIGH_SURROGATE_MIN,
  6543. 10
  6544. );
  6545. };
  6546. var lowSurrogate = function(codePoint) {
  6547. return parseInt(
  6548. (codePoint - 0x10000) % 0x400 + LOW_SURROGATE_MIN,
  6549. 10
  6550. );
  6551. };
  6552. var stringFromCharCode = String.fromCharCode;
  6553. var codePointToString = function(codePoint) {
  6554. var string;
  6555. // https://mathiasbynens.be/notes/javascript-escapes#single
  6556. // Note: the `\b` escape sequence for U+0008 BACKSPACE in strings has a
  6557. // different meaning in regular expressions (word boundary), so it cannot
  6558. // be used here.
  6559. if (codePoint == 0x09) {
  6560. string = '\\t';
  6561. }
  6562. // Note: IE < 9 treats `'\v'` as `'v'`, so avoid using it.
  6563. // else if (codePoint == 0x0B) {
  6564. // string = '\\v';
  6565. // }
  6566. else if (codePoint == 0x0A) {
  6567. string = '\\n';
  6568. }
  6569. else if (codePoint == 0x0C) {
  6570. string = '\\f';
  6571. }
  6572. else if (codePoint == 0x0D) {
  6573. string = '\\r';
  6574. }
  6575. else if (codePoint == 0x5C) {
  6576. string = '\\\\';
  6577. }
  6578. else if (
  6579. codePoint == 0x24 ||
  6580. (codePoint >= 0x28 && codePoint <= 0x2B) ||
  6581. codePoint == 0x2D || codePoint == 0x2E || codePoint == 0x3F ||
  6582. (codePoint >= 0x5B && codePoint <= 0x5E) ||
  6583. (codePoint >= 0x7B && codePoint <= 0x7D)
  6584. ) {
  6585. // The code point maps to an unsafe printable ASCII character;
  6586. // backslash-escape it. Here’s the list of those symbols:
  6587. //
  6588. // $()*+-.?[\]^{|}
  6589. //
  6590. // See #7 for more info.
  6591. string = '\\' + stringFromCharCode(codePoint);
  6592. }
  6593. else if (codePoint >= 0x20 && codePoint <= 0x7E) {
  6594. // The code point maps to one of these printable ASCII symbols
  6595. // (including the space character):
  6596. //
  6597. // !"#%&',/0123456789:;<=>@ABCDEFGHIJKLMNO
  6598. // PQRSTUVWXYZ_`abcdefghijklmnopqrstuvwxyz~
  6599. //
  6600. // These can safely be used directly.
  6601. string = stringFromCharCode(codePoint);
  6602. }
  6603. else if (codePoint <= 0xFF) {
  6604. // https://mathiasbynens.be/notes/javascript-escapes#hexadecimal
  6605. string = '\\x' + pad(hex(codePoint), 2);
  6606. }
  6607. else { // `codePoint <= 0xFFFF` holds true.
  6608. // https://mathiasbynens.be/notes/javascript-escapes#unicode
  6609. string = '\\u' + pad(hex(codePoint), 4);
  6610. }
  6611. // There’s no need to account for astral symbols / surrogate pairs here,
  6612. // since `codePointToString` is private and only used for BMP code points.
  6613. // But if that’s what you need, just add an `else` block with this code:
  6614. //
  6615. // string = '\\u' + pad(hex(highSurrogate(codePoint)), 4)
  6616. // + '\\u' + pad(hex(lowSurrogate(codePoint)), 4);
  6617. return string;
  6618. };
  6619. var codePointToStringUnicode = function(codePoint) {
  6620. if (codePoint <= 0xFFFF) {
  6621. return codePointToString(codePoint);
  6622. }
  6623. return '\\u{' + codePoint.toString(16).toUpperCase() + '}';
  6624. };
  6625. var symbolToCodePoint = function(symbol) {
  6626. var length = symbol.length;
  6627. var first = symbol.charCodeAt(0);
  6628. var second;
  6629. if (
  6630. first >= HIGH_SURROGATE_MIN && first <= HIGH_SURROGATE_MAX &&
  6631. length > 1 // There is a next code unit.
  6632. ) {
  6633. // `first` is a high surrogate, and there is a next character. Assume
  6634. // it’s a low surrogate (else it’s invalid usage of Regenerate anyway).
  6635. second = symbol.charCodeAt(1);
  6636. // https://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
  6637. return (first - HIGH_SURROGATE_MIN) * 0x400 +
  6638. second - LOW_SURROGATE_MIN + 0x10000;
  6639. }
  6640. return first;
  6641. };
  6642. var createBMPCharacterClasses = function(data) {
  6643. // Iterate over the data per `(start, end)` pair.
  6644. var result = '';
  6645. var index = 0;
  6646. var start;
  6647. var end;
  6648. var length = data.length;
  6649. if (dataIsSingleton(data)) {
  6650. return codePointToString(data[0]);
  6651. }
  6652. while (index < length) {
  6653. start = data[index];
  6654. end = data[index + 1] - 1; // Note: the `- 1` makes `end` inclusive.
  6655. if (start == end) {
  6656. result += codePointToString(start);
  6657. } else if (start + 1 == end) {
  6658. result += codePointToString(start) + codePointToString(end);
  6659. } else {
  6660. result += codePointToString(start) + '-' + codePointToString(end);
  6661. }
  6662. index += 2;
  6663. }
  6664. return '[' + result + ']';
  6665. };
  6666. var createUnicodeCharacterClasses = function(data) {
  6667. // Iterate over the data per `(start, end)` pair.
  6668. var result = '';
  6669. var index = 0;
  6670. var start;
  6671. var end;
  6672. var length = data.length;
  6673. if (dataIsSingleton(data)) {
  6674. return codePointToStringUnicode(data[0]);
  6675. }
  6676. while (index < length) {
  6677. start = data[index];
  6678. end = data[index + 1] - 1; // Note: the `- 1` makes `end` inclusive.
  6679. if (start == end) {
  6680. result += codePointToStringUnicode(start);
  6681. } else if (start + 1 == end) {
  6682. result += codePointToStringUnicode(start) + codePointToStringUnicode(end);
  6683. } else {
  6684. result += codePointToStringUnicode(start) + '-' + codePointToStringUnicode(end);
  6685. }
  6686. index += 2;
  6687. }
  6688. return '[' + result + ']';
  6689. };
  6690. var splitAtBMP = function(data) {
  6691. // Iterate over the data per `(start, end)` pair.
  6692. var loneHighSurrogates = [];
  6693. var loneLowSurrogates = [];
  6694. var bmp = [];
  6695. var astral = [];
  6696. var index = 0;
  6697. var start;
  6698. var end;
  6699. var length = data.length;
  6700. while (index < length) {
  6701. start = data[index];
  6702. end = data[index + 1] - 1; // Note: the `- 1` makes `end` inclusive.
  6703. if (start < HIGH_SURROGATE_MIN) {
  6704. // The range starts and ends before the high surrogate range.
  6705. // E.g. (0, 0x10).
  6706. if (end < HIGH_SURROGATE_MIN) {
  6707. bmp.push(start, end + 1);
  6708. }
  6709. // The range starts before the high surrogate range and ends within it.
  6710. // E.g. (0, 0xD855).
  6711. if (end >= HIGH_SURROGATE_MIN && end <= HIGH_SURROGATE_MAX) {
  6712. bmp.push(start, HIGH_SURROGATE_MIN);
  6713. loneHighSurrogates.push(HIGH_SURROGATE_MIN, end + 1);
  6714. }
  6715. // The range starts before the high surrogate range and ends in the low
  6716. // surrogate range. E.g. (0, 0xDCFF).
  6717. if (end >= LOW_SURROGATE_MIN && end <= LOW_SURROGATE_MAX) {
  6718. bmp.push(start, HIGH_SURROGATE_MIN);
  6719. loneHighSurrogates.push(HIGH_SURROGATE_MIN, HIGH_SURROGATE_MAX + 1);
  6720. loneLowSurrogates.push(LOW_SURROGATE_MIN, end + 1);
  6721. }
  6722. // The range starts before the high surrogate range and ends after the
  6723. // low surrogate range. E.g. (0, 0x10FFFF).
  6724. if (end > LOW_SURROGATE_MAX) {
  6725. bmp.push(start, HIGH_SURROGATE_MIN);
  6726. loneHighSurrogates.push(HIGH_SURROGATE_MIN, HIGH_SURROGATE_MAX + 1);
  6727. loneLowSurrogates.push(LOW_SURROGATE_MIN, LOW_SURROGATE_MAX + 1);
  6728. if (end <= 0xFFFF) {
  6729. bmp.push(LOW_SURROGATE_MAX + 1, end + 1);
  6730. } else {
  6731. bmp.push(LOW_SURROGATE_MAX + 1, 0xFFFF + 1);
  6732. astral.push(0xFFFF + 1, end + 1);
  6733. }
  6734. }
  6735. } else if (start >= HIGH_SURROGATE_MIN && start <= HIGH_SURROGATE_MAX) {
  6736. // The range starts and ends in the high surrogate range.
  6737. // E.g. (0xD855, 0xD866).
  6738. if (end >= HIGH_SURROGATE_MIN && end <= HIGH_SURROGATE_MAX) {
  6739. loneHighSurrogates.push(start, end + 1);
  6740. }
  6741. // The range starts in the high surrogate range and ends in the low
  6742. // surrogate range. E.g. (0xD855, 0xDCFF).
  6743. if (end >= LOW_SURROGATE_MIN && end <= LOW_SURROGATE_MAX) {
  6744. loneHighSurrogates.push(start, HIGH_SURROGATE_MAX + 1);
  6745. loneLowSurrogates.push(LOW_SURROGATE_MIN, end + 1);
  6746. }
  6747. // The range starts in the high surrogate range and ends after the low
  6748. // surrogate range. E.g. (0xD855, 0x10FFFF).
  6749. if (end > LOW_SURROGATE_MAX) {
  6750. loneHighSurrogates.push(start, HIGH_SURROGATE_MAX + 1);
  6751. loneLowSurrogates.push(LOW_SURROGATE_MIN, LOW_SURROGATE_MAX + 1);
  6752. if (end <= 0xFFFF) {
  6753. bmp.push(LOW_SURROGATE_MAX + 1, end + 1);
  6754. } else {
  6755. bmp.push(LOW_SURROGATE_MAX + 1, 0xFFFF + 1);
  6756. astral.push(0xFFFF + 1, end + 1);
  6757. }
  6758. }
  6759. } else if (start >= LOW_SURROGATE_MIN && start <= LOW_SURROGATE_MAX) {
  6760. // The range starts and ends in the low surrogate range.
  6761. // E.g. (0xDCFF, 0xDDFF).
  6762. if (end >= LOW_SURROGATE_MIN && end <= LOW_SURROGATE_MAX) {
  6763. loneLowSurrogates.push(start, end + 1);
  6764. }
  6765. // The range starts in the low surrogate range and ends after the low
  6766. // surrogate range. E.g. (0xDCFF, 0x10FFFF).
  6767. if (end > LOW_SURROGATE_MAX) {
  6768. loneLowSurrogates.push(start, LOW_SURROGATE_MAX + 1);
  6769. if (end <= 0xFFFF) {
  6770. bmp.push(LOW_SURROGATE_MAX + 1, end + 1);
  6771. } else {
  6772. bmp.push(LOW_SURROGATE_MAX + 1, 0xFFFF + 1);
  6773. astral.push(0xFFFF + 1, end + 1);
  6774. }
  6775. }
  6776. } else if (start > LOW_SURROGATE_MAX && start <= 0xFFFF) {
  6777. // The range starts and ends after the low surrogate range.
  6778. // E.g. (0xFFAA, 0x10FFFF).
  6779. if (end <= 0xFFFF) {
  6780. bmp.push(start, end + 1);
  6781. } else {
  6782. bmp.push(start, 0xFFFF + 1);
  6783. astral.push(0xFFFF + 1, end + 1);
  6784. }
  6785. } else {
  6786. // The range starts and ends in the astral range.
  6787. astral.push(start, end + 1);
  6788. }
  6789. index += 2;
  6790. }
  6791. return {
  6792. 'loneHighSurrogates': loneHighSurrogates,
  6793. 'loneLowSurrogates': loneLowSurrogates,
  6794. 'bmp': bmp,
  6795. 'astral': astral
  6796. };
  6797. };
  6798. var optimizeSurrogateMappings = function(surrogateMappings) {
  6799. var result = [];
  6800. var tmpLow = [];
  6801. var addLow = false;
  6802. var mapping;
  6803. var nextMapping;
  6804. var highSurrogates;
  6805. var lowSurrogates;
  6806. var nextHighSurrogates;
  6807. var nextLowSurrogates;
  6808. var index = -1;
  6809. var length = surrogateMappings.length;
  6810. while (++index < length) {
  6811. mapping = surrogateMappings[index];
  6812. nextMapping = surrogateMappings[index + 1];
  6813. if (!nextMapping) {
  6814. result.push(mapping);
  6815. continue;
  6816. }
  6817. highSurrogates = mapping[0];
  6818. lowSurrogates = mapping[1];
  6819. nextHighSurrogates = nextMapping[0];
  6820. nextLowSurrogates = nextMapping[1];
  6821. // Check for identical high surrogate ranges.
  6822. tmpLow = lowSurrogates;
  6823. while (
  6824. nextHighSurrogates &&
  6825. highSurrogates[0] == nextHighSurrogates[0] &&
  6826. highSurrogates[1] == nextHighSurrogates[1]
  6827. ) {
  6828. // Merge with the next item.
  6829. if (dataIsSingleton(nextLowSurrogates)) {
  6830. tmpLow = dataAdd(tmpLow, nextLowSurrogates[0]);
  6831. } else {
  6832. tmpLow = dataAddRange(
  6833. tmpLow,
  6834. nextLowSurrogates[0],
  6835. nextLowSurrogates[1] - 1
  6836. );
  6837. }
  6838. ++index;
  6839. mapping = surrogateMappings[index];
  6840. highSurrogates = mapping[0];
  6841. lowSurrogates = mapping[1];
  6842. nextMapping = surrogateMappings[index + 1];
  6843. nextHighSurrogates = nextMapping && nextMapping[0];
  6844. nextLowSurrogates = nextMapping && nextMapping[1];
  6845. addLow = true;
  6846. }
  6847. result.push([
  6848. highSurrogates,
  6849. addLow ? tmpLow : lowSurrogates
  6850. ]);
  6851. addLow = false;
  6852. }
  6853. return optimizeByLowSurrogates(result);
  6854. };
  6855. var optimizeByLowSurrogates = function(surrogateMappings) {
  6856. if (surrogateMappings.length == 1) {
  6857. return surrogateMappings;
  6858. }
  6859. var index = -1;
  6860. var innerIndex = -1;
  6861. while (++index < surrogateMappings.length) {
  6862. var mapping = surrogateMappings[index];
  6863. var lowSurrogates = mapping[1];
  6864. var lowSurrogateStart = lowSurrogates[0];
  6865. var lowSurrogateEnd = lowSurrogates[1];
  6866. innerIndex = index; // Note: the loop starts at the next index.
  6867. while (++innerIndex < surrogateMappings.length) {
  6868. var otherMapping = surrogateMappings[innerIndex];
  6869. var otherLowSurrogates = otherMapping[1];
  6870. var otherLowSurrogateStart = otherLowSurrogates[0];
  6871. var otherLowSurrogateEnd = otherLowSurrogates[1];
  6872. if (
  6873. lowSurrogateStart == otherLowSurrogateStart &&
  6874. lowSurrogateEnd == otherLowSurrogateEnd
  6875. ) {
  6876. // Add the code points in the other item to this one.
  6877. if (dataIsSingleton(otherMapping[0])) {
  6878. mapping[0] = dataAdd(mapping[0], otherMapping[0][0]);
  6879. } else {
  6880. mapping[0] = dataAddRange(
  6881. mapping[0],
  6882. otherMapping[0][0],
  6883. otherMapping[0][1] - 1
  6884. );
  6885. }
  6886. // Remove the other, now redundant, item.
  6887. surrogateMappings.splice(innerIndex, 1);
  6888. --innerIndex;
  6889. }
  6890. }
  6891. }
  6892. return surrogateMappings;
  6893. };
  6894. var surrogateSet = function(data) {
  6895. // Exit early if `data` is an empty set.
  6896. if (!data.length) {
  6897. return [];
  6898. }
  6899. // Iterate over the data per `(start, end)` pair.
  6900. var index = 0;
  6901. var start;
  6902. var end;
  6903. var startHigh;
  6904. var startLow;
  6905. var endHigh;
  6906. var endLow;
  6907. var surrogateMappings = [];
  6908. var length = data.length;
  6909. while (index < length) {
  6910. start = data[index];
  6911. end = data[index + 1] - 1;
  6912. startHigh = highSurrogate(start);
  6913. startLow = lowSurrogate(start);
  6914. endHigh = highSurrogate(end);
  6915. endLow = lowSurrogate(end);
  6916. var startsWithLowestLowSurrogate = startLow == LOW_SURROGATE_MIN;
  6917. var endsWithHighestLowSurrogate = endLow == LOW_SURROGATE_MAX;
  6918. var complete = false;
  6919. // Append the previous high-surrogate-to-low-surrogate mappings.
  6920. // Step 1: `(startHigh, startLow)` to `(startHigh, LOW_SURROGATE_MAX)`.
  6921. if (
  6922. startHigh == endHigh ||
  6923. startsWithLowestLowSurrogate && endsWithHighestLowSurrogate
  6924. ) {
  6925. surrogateMappings.push([
  6926. [startHigh, endHigh + 1],
  6927. [startLow, endLow + 1]
  6928. ]);
  6929. complete = true;
  6930. } else {
  6931. surrogateMappings.push([
  6932. [startHigh, startHigh + 1],
  6933. [startLow, LOW_SURROGATE_MAX + 1]
  6934. ]);
  6935. }
  6936. // Step 2: `(startHigh + 1, LOW_SURROGATE_MIN)` to
  6937. // `(endHigh - 1, LOW_SURROGATE_MAX)`.
  6938. if (!complete && startHigh + 1 < endHigh) {
  6939. if (endsWithHighestLowSurrogate) {
  6940. // Combine step 2 and step 3.
  6941. surrogateMappings.push([
  6942. [startHigh + 1, endHigh + 1],
  6943. [LOW_SURROGATE_MIN, endLow + 1]
  6944. ]);
  6945. complete = true;
  6946. } else {
  6947. surrogateMappings.push([
  6948. [startHigh + 1, endHigh],
  6949. [LOW_SURROGATE_MIN, LOW_SURROGATE_MAX + 1]
  6950. ]);
  6951. }
  6952. }
  6953. // Step 3. `(endHigh, LOW_SURROGATE_MIN)` to `(endHigh, endLow)`.
  6954. if (!complete) {
  6955. surrogateMappings.push([
  6956. [endHigh, endHigh + 1],
  6957. [LOW_SURROGATE_MIN, endLow + 1]
  6958. ]);
  6959. }
  6960. index += 2;
  6961. }
  6962. // The format of `surrogateMappings` is as follows:
  6963. //
  6964. // [ surrogateMapping1, surrogateMapping2 ]
  6965. //
  6966. // i.e.:
  6967. //
  6968. // [
  6969. // [ highSurrogates1, lowSurrogates1 ],
  6970. // [ highSurrogates2, lowSurrogates2 ]
  6971. // ]
  6972. return optimizeSurrogateMappings(surrogateMappings);
  6973. };
  6974. var createSurrogateCharacterClasses = function(surrogateMappings) {
  6975. var result = [];
  6976. forEach(surrogateMappings, function(surrogateMapping) {
  6977. var highSurrogates = surrogateMapping[0];
  6978. var lowSurrogates = surrogateMapping[1];
  6979. result.push(
  6980. createBMPCharacterClasses(highSurrogates) +
  6981. createBMPCharacterClasses(lowSurrogates)
  6982. );
  6983. });
  6984. return result.join('|');
  6985. };
  6986. var createCharacterClassesFromData = function(data, bmpOnly, hasUnicodeFlag) {
  6987. if (hasUnicodeFlag) {
  6988. return createUnicodeCharacterClasses(data);
  6989. }
  6990. var result = [];
  6991. var parts = splitAtBMP(data);
  6992. var loneHighSurrogates = parts.loneHighSurrogates;
  6993. var loneLowSurrogates = parts.loneLowSurrogates;
  6994. var bmp = parts.bmp;
  6995. var astral = parts.astral;
  6996. var hasLoneHighSurrogates = !dataIsEmpty(loneHighSurrogates);
  6997. var hasLoneLowSurrogates = !dataIsEmpty(loneLowSurrogates);
  6998. var surrogateMappings = surrogateSet(astral);
  6999. if (bmpOnly) {
  7000. bmp = dataAddData(bmp, loneHighSurrogates);
  7001. hasLoneHighSurrogates = false;
  7002. bmp = dataAddData(bmp, loneLowSurrogates);
  7003. hasLoneLowSurrogates = false;
  7004. }
  7005. if (!dataIsEmpty(bmp)) {
  7006. // The data set contains BMP code points that are not high surrogates
  7007. // needed for astral code points in the set.
  7008. result.push(createBMPCharacterClasses(bmp));
  7009. }
  7010. if (surrogateMappings.length) {
  7011. // The data set contains astral code points; append character classes
  7012. // based on their surrogate pairs.
  7013. result.push(createSurrogateCharacterClasses(surrogateMappings));
  7014. }
  7015. // https://gist.github.com/mathiasbynens/bbe7f870208abcfec860
  7016. if (hasLoneHighSurrogates) {
  7017. result.push(
  7018. createBMPCharacterClasses(loneHighSurrogates) +
  7019. // Make sure the high surrogates aren’t part of a surrogate pair.
  7020. '(?![\\uDC00-\\uDFFF])'
  7021. );
  7022. }
  7023. if (hasLoneLowSurrogates) {
  7024. result.push(
  7025. // It is not possible to accurately assert the low surrogates aren’t
  7026. // part of a surrogate pair, since JavaScript regular expressions do
  7027. // not support lookbehind.
  7028. '(?:[^\\uD800-\\uDBFF]|^)' +
  7029. createBMPCharacterClasses(loneLowSurrogates)
  7030. );
  7031. }
  7032. return result.join('|');
  7033. };
  7034. /*--------------------------------------------------------------------------*/
  7035. // `regenerate` can be used as a constructor (and new methods can be added to
  7036. // its prototype) but also as a regular function, the latter of which is the
  7037. // documented and most common usage. For that reason, it’s not capitalized.
  7038. var regenerate = function(value) {
  7039. if (arguments.length > 1) {
  7040. value = slice.call(arguments);
  7041. }
  7042. if (this instanceof regenerate) {
  7043. this.data = [];
  7044. return value ? this.add(value) : this;
  7045. }
  7046. return (new regenerate).add(value);
  7047. };
  7048. regenerate.version = '1.3.2';
  7049. var proto = regenerate.prototype;
  7050. extend(proto, {
  7051. 'add': function(value) {
  7052. var $this = this;
  7053. if (value == null) {
  7054. return $this;
  7055. }
  7056. if (value instanceof regenerate) {
  7057. // Allow passing other Regenerate instances.
  7058. $this.data = dataAddData($this.data, value.data);
  7059. return $this;
  7060. }
  7061. if (arguments.length > 1) {
  7062. value = slice.call(arguments);
  7063. }
  7064. if (isArray(value)) {
  7065. forEach(value, function(item) {
  7066. $this.add(item);
  7067. });
  7068. return $this;
  7069. }
  7070. $this.data = dataAdd(
  7071. $this.data,
  7072. isNumber(value) ? value : symbolToCodePoint(value)
  7073. );
  7074. return $this;
  7075. },
  7076. 'remove': function(value) {
  7077. var $this = this;
  7078. if (value == null) {
  7079. return $this;
  7080. }
  7081. if (value instanceof regenerate) {
  7082. // Allow passing other Regenerate instances.
  7083. $this.data = dataRemoveData($this.data, value.data);
  7084. return $this;
  7085. }
  7086. if (arguments.length > 1) {
  7087. value = slice.call(arguments);
  7088. }
  7089. if (isArray(value)) {
  7090. forEach(value, function(item) {
  7091. $this.remove(item);
  7092. });
  7093. return $this;
  7094. }
  7095. $this.data = dataRemove(
  7096. $this.data,
  7097. isNumber(value) ? value : symbolToCodePoint(value)
  7098. );
  7099. return $this;
  7100. },
  7101. 'addRange': function(start, end) {
  7102. var $this = this;
  7103. $this.data = dataAddRange($this.data,
  7104. isNumber(start) ? start : symbolToCodePoint(start),
  7105. isNumber(end) ? end : symbolToCodePoint(end)
  7106. );
  7107. return $this;
  7108. },
  7109. 'removeRange': function(start, end) {
  7110. var $this = this;
  7111. var startCodePoint = isNumber(start) ? start : symbolToCodePoint(start);
  7112. var endCodePoint = isNumber(end) ? end : symbolToCodePoint(end);
  7113. $this.data = dataRemoveRange(
  7114. $this.data,
  7115. startCodePoint,
  7116. endCodePoint
  7117. );
  7118. return $this;
  7119. },
  7120. 'intersection': function(argument) {
  7121. var $this = this;
  7122. // Allow passing other Regenerate instances.
  7123. // TODO: Optimize this by writing and using `dataIntersectionData()`.
  7124. var array = argument instanceof regenerate ?
  7125. dataToArray(argument.data) :
  7126. argument;
  7127. $this.data = dataIntersection($this.data, array);
  7128. return $this;
  7129. },
  7130. 'contains': function(codePoint) {
  7131. return dataContains(
  7132. this.data,
  7133. isNumber(codePoint) ? codePoint : symbolToCodePoint(codePoint)
  7134. );
  7135. },
  7136. 'clone': function() {
  7137. var set = new regenerate;
  7138. set.data = this.data.slice(0);
  7139. return set;
  7140. },
  7141. 'toString': function(options) {
  7142. var result = createCharacterClassesFromData(
  7143. this.data,
  7144. options ? options.bmpOnly : false,
  7145. options ? options.hasUnicodeFlag : false
  7146. );
  7147. if (!result) {
  7148. // For an empty set, return something that can be inserted `/here/` to
  7149. // form a valid regular expression. Avoid `(?:)` since that matches the
  7150. // empty string.
  7151. return '[]';
  7152. }
  7153. // Use `\0` instead of `\x00` where possible.
  7154. return result.replace(regexNull, '\\0$1');
  7155. },
  7156. 'toRegExp': function(flags) {
  7157. var pattern = this.toString(
  7158. flags && flags.indexOf('u') != -1 ?
  7159. { 'hasUnicodeFlag': true } :
  7160. null
  7161. );
  7162. return RegExp(pattern, flags || '');
  7163. },
  7164. 'valueOf': function() { // Note: `valueOf` is aliased as `toArray`.
  7165. return dataToArray(this.data);
  7166. }
  7167. });
  7168. proto.toArray = proto.valueOf;
  7169. // Some AMD build optimizers, like r.js, check for specific condition patterns
  7170. // like the following:
  7171. if (
  7172. typeof define == 'function' &&
  7173. typeof define.amd == 'object' &&
  7174. define.amd
  7175. ) {
  7176. define(function() {
  7177. return regenerate;
  7178. });
  7179. } else if (freeExports && !freeExports.nodeType) {
  7180. if (freeModule) { // in Node.js, io.js, or RingoJS v0.8.0+
  7181. freeModule.exports = regenerate;
  7182. } else { // in Narwhal or RingoJS v0.7.0-
  7183. freeExports.regenerate = regenerate;
  7184. }
  7185. } else { // in Rhino or a web browser
  7186. root.regenerate = regenerate;
  7187. }
  7188. }(__commonjs_global));
  7189. });
  7190. var require$$0$2 = (regenerate && typeof regenerate === 'object' && 'default' in regenerate ? regenerate['default'] : regenerate);
  7191. var characterClassEscapeSets = __commonjs(function (module, exports) {
  7192. // Generated by `/scripts/character-class-escape-sets.js`. Do not edit.
  7193. var regenerate = require$$0$2;
  7194. exports.REGULAR = {
  7195. 'd': regenerate()
  7196. .addRange(0x30, 0x39),
  7197. 'D': regenerate()
  7198. .addRange(0x0, 0x2F)
  7199. .addRange(0x3A, 0xFFFF),
  7200. 's': regenerate(0x20, 0xA0, 0x1680, 0x202F, 0x205F, 0x3000, 0xFEFF)
  7201. .addRange(0x9, 0xD)
  7202. .addRange(0x2000, 0x200A)
  7203. .addRange(0x2028, 0x2029),
  7204. 'S': regenerate()
  7205. .addRange(0x0, 0x8)
  7206. .addRange(0xE, 0x1F)
  7207. .addRange(0x21, 0x9F)
  7208. .addRange(0xA1, 0x167F)
  7209. .addRange(0x1681, 0x1FFF)
  7210. .addRange(0x200B, 0x2027)
  7211. .addRange(0x202A, 0x202E)
  7212. .addRange(0x2030, 0x205E)
  7213. .addRange(0x2060, 0x2FFF)
  7214. .addRange(0x3001, 0xFEFE)
  7215. .addRange(0xFF00, 0xFFFF),
  7216. 'w': regenerate(0x5F)
  7217. .addRange(0x30, 0x39)
  7218. .addRange(0x41, 0x5A)
  7219. .addRange(0x61, 0x7A),
  7220. 'W': regenerate(0x60)
  7221. .addRange(0x0, 0x2F)
  7222. .addRange(0x3A, 0x40)
  7223. .addRange(0x5B, 0x5E)
  7224. .addRange(0x7B, 0xFFFF)
  7225. };
  7226. exports.UNICODE = {
  7227. 'd': regenerate()
  7228. .addRange(0x30, 0x39),
  7229. 'D': regenerate()
  7230. .addRange(0x0, 0x2F)
  7231. .addRange(0x3A, 0x10FFFF),
  7232. 's': regenerate(0x20, 0xA0, 0x1680, 0x202F, 0x205F, 0x3000, 0xFEFF)
  7233. .addRange(0x9, 0xD)
  7234. .addRange(0x2000, 0x200A)
  7235. .addRange(0x2028, 0x2029),
  7236. 'S': regenerate()
  7237. .addRange(0x0, 0x8)
  7238. .addRange(0xE, 0x1F)
  7239. .addRange(0x21, 0x9F)
  7240. .addRange(0xA1, 0x167F)
  7241. .addRange(0x1681, 0x1FFF)
  7242. .addRange(0x200B, 0x2027)
  7243. .addRange(0x202A, 0x202E)
  7244. .addRange(0x2030, 0x205E)
  7245. .addRange(0x2060, 0x2FFF)
  7246. .addRange(0x3001, 0xFEFE)
  7247. .addRange(0xFF00, 0x10FFFF),
  7248. 'w': regenerate(0x5F)
  7249. .addRange(0x30, 0x39)
  7250. .addRange(0x41, 0x5A)
  7251. .addRange(0x61, 0x7A),
  7252. 'W': regenerate(0x60)
  7253. .addRange(0x0, 0x2F)
  7254. .addRange(0x3A, 0x40)
  7255. .addRange(0x5B, 0x5E)
  7256. .addRange(0x7B, 0x10FFFF)
  7257. };
  7258. exports.UNICODE_IGNORE_CASE = {
  7259. 'd': regenerate()
  7260. .addRange(0x30, 0x39),
  7261. 'D': regenerate()
  7262. .addRange(0x0, 0x2F)
  7263. .addRange(0x3A, 0x10FFFF),
  7264. 's': regenerate(0x20, 0xA0, 0x1680, 0x202F, 0x205F, 0x3000, 0xFEFF)
  7265. .addRange(0x9, 0xD)
  7266. .addRange(0x2000, 0x200A)
  7267. .addRange(0x2028, 0x2029),
  7268. 'S': regenerate()
  7269. .addRange(0x0, 0x8)
  7270. .addRange(0xE, 0x1F)
  7271. .addRange(0x21, 0x9F)
  7272. .addRange(0xA1, 0x167F)
  7273. .addRange(0x1681, 0x1FFF)
  7274. .addRange(0x200B, 0x2027)
  7275. .addRange(0x202A, 0x202E)
  7276. .addRange(0x2030, 0x205E)
  7277. .addRange(0x2060, 0x2FFF)
  7278. .addRange(0x3001, 0xFEFE)
  7279. .addRange(0xFF00, 0x10FFFF),
  7280. 'w': regenerate(0x5F, 0x17F, 0x212A)
  7281. .addRange(0x30, 0x39)
  7282. .addRange(0x41, 0x5A)
  7283. .addRange(0x61, 0x7A),
  7284. 'W': regenerate(0x4B, 0x53, 0x60)
  7285. .addRange(0x0, 0x2F)
  7286. .addRange(0x3A, 0x40)
  7287. .addRange(0x5B, 0x5E)
  7288. .addRange(0x7B, 0x10FFFF)
  7289. };
  7290. });
  7291. var require$$0$1 = (characterClassEscapeSets && typeof characterClassEscapeSets === 'object' && 'default' in characterClassEscapeSets ? characterClassEscapeSets['default'] : characterClassEscapeSets);
  7292. var require$$1 = {
  7293. "75": 8490,
  7294. "83": 383,
  7295. "107": 8490,
  7296. "115": 383,
  7297. "181": 924,
  7298. "197": 8491,
  7299. "383": 83,
  7300. "452": 453,
  7301. "453": 452,
  7302. "455": 456,
  7303. "456": 455,
  7304. "458": 459,
  7305. "459": 458,
  7306. "497": 498,
  7307. "498": 497,
  7308. "837": 8126,
  7309. "914": 976,
  7310. "917": 1013,
  7311. "920": 1012,
  7312. "921": 8126,
  7313. "922": 1008,
  7314. "924": 181,
  7315. "928": 982,
  7316. "929": 1009,
  7317. "931": 962,
  7318. "934": 981,
  7319. "937": 8486,
  7320. "962": 931,
  7321. "976": 914,
  7322. "977": 1012,
  7323. "981": 934,
  7324. "982": 928,
  7325. "1008": 922,
  7326. "1009": 929,
  7327. "1012": [920,977],
  7328. "1013": 917,
  7329. "7776": 7835,
  7330. "7835": 7776,
  7331. "8126": [837,921],
  7332. "8486": 937,
  7333. "8490": 75,
  7334. "8491": 197,
  7335. "66560": 66600,
  7336. "66561": 66601,
  7337. "66562": 66602,
  7338. "66563": 66603,
  7339. "66564": 66604,
  7340. "66565": 66605,
  7341. "66566": 66606,
  7342. "66567": 66607,
  7343. "66568": 66608,
  7344. "66569": 66609,
  7345. "66570": 66610,
  7346. "66571": 66611,
  7347. "66572": 66612,
  7348. "66573": 66613,
  7349. "66574": 66614,
  7350. "66575": 66615,
  7351. "66576": 66616,
  7352. "66577": 66617,
  7353. "66578": 66618,
  7354. "66579": 66619,
  7355. "66580": 66620,
  7356. "66581": 66621,
  7357. "66582": 66622,
  7358. "66583": 66623,
  7359. "66584": 66624,
  7360. "66585": 66625,
  7361. "66586": 66626,
  7362. "66587": 66627,
  7363. "66588": 66628,
  7364. "66589": 66629,
  7365. "66590": 66630,
  7366. "66591": 66631,
  7367. "66592": 66632,
  7368. "66593": 66633,
  7369. "66594": 66634,
  7370. "66595": 66635,
  7371. "66596": 66636,
  7372. "66597": 66637,
  7373. "66598": 66638,
  7374. "66599": 66639,
  7375. "66600": 66560,
  7376. "66601": 66561,
  7377. "66602": 66562,
  7378. "66603": 66563,
  7379. "66604": 66564,
  7380. "66605": 66565,
  7381. "66606": 66566,
  7382. "66607": 66567,
  7383. "66608": 66568,
  7384. "66609": 66569,
  7385. "66610": 66570,
  7386. "66611": 66571,
  7387. "66612": 66572,
  7388. "66613": 66573,
  7389. "66614": 66574,
  7390. "66615": 66575,
  7391. "66616": 66576,
  7392. "66617": 66577,
  7393. "66618": 66578,
  7394. "66619": 66579,
  7395. "66620": 66580,
  7396. "66621": 66581,
  7397. "66622": 66582,
  7398. "66623": 66583,
  7399. "66624": 66584,
  7400. "66625": 66585,
  7401. "66626": 66586,
  7402. "66627": 66587,
  7403. "66628": 66588,
  7404. "66629": 66589,
  7405. "66630": 66590,
  7406. "66631": 66591,
  7407. "66632": 66592,
  7408. "66633": 66593,
  7409. "66634": 66594,
  7410. "66635": 66595,
  7411. "66636": 66596,
  7412. "66637": 66597,
  7413. "66638": 66598,
  7414. "66639": 66599,
  7415. "68736": 68800,
  7416. "68737": 68801,
  7417. "68738": 68802,
  7418. "68739": 68803,
  7419. "68740": 68804,
  7420. "68741": 68805,
  7421. "68742": 68806,
  7422. "68743": 68807,
  7423. "68744": 68808,
  7424. "68745": 68809,
  7425. "68746": 68810,
  7426. "68747": 68811,
  7427. "68748": 68812,
  7428. "68749": 68813,
  7429. "68750": 68814,
  7430. "68751": 68815,
  7431. "68752": 68816,
  7432. "68753": 68817,
  7433. "68754": 68818,
  7434. "68755": 68819,
  7435. "68756": 68820,
  7436. "68757": 68821,
  7437. "68758": 68822,
  7438. "68759": 68823,
  7439. "68760": 68824,
  7440. "68761": 68825,
  7441. "68762": 68826,
  7442. "68763": 68827,
  7443. "68764": 68828,
  7444. "68765": 68829,
  7445. "68766": 68830,
  7446. "68767": 68831,
  7447. "68768": 68832,
  7448. "68769": 68833,
  7449. "68770": 68834,
  7450. "68771": 68835,
  7451. "68772": 68836,
  7452. "68773": 68837,
  7453. "68774": 68838,
  7454. "68775": 68839,
  7455. "68776": 68840,
  7456. "68777": 68841,
  7457. "68778": 68842,
  7458. "68779": 68843,
  7459. "68780": 68844,
  7460. "68781": 68845,
  7461. "68782": 68846,
  7462. "68783": 68847,
  7463. "68784": 68848,
  7464. "68785": 68849,
  7465. "68786": 68850,
  7466. "68800": 68736,
  7467. "68801": 68737,
  7468. "68802": 68738,
  7469. "68803": 68739,
  7470. "68804": 68740,
  7471. "68805": 68741,
  7472. "68806": 68742,
  7473. "68807": 68743,
  7474. "68808": 68744,
  7475. "68809": 68745,
  7476. "68810": 68746,
  7477. "68811": 68747,
  7478. "68812": 68748,
  7479. "68813": 68749,
  7480. "68814": 68750,
  7481. "68815": 68751,
  7482. "68816": 68752,
  7483. "68817": 68753,
  7484. "68818": 68754,
  7485. "68819": 68755,
  7486. "68820": 68756,
  7487. "68821": 68757,
  7488. "68822": 68758,
  7489. "68823": 68759,
  7490. "68824": 68760,
  7491. "68825": 68761,
  7492. "68826": 68762,
  7493. "68827": 68763,
  7494. "68828": 68764,
  7495. "68829": 68765,
  7496. "68830": 68766,
  7497. "68831": 68767,
  7498. "68832": 68768,
  7499. "68833": 68769,
  7500. "68834": 68770,
  7501. "68835": 68771,
  7502. "68836": 68772,
  7503. "68837": 68773,
  7504. "68838": 68774,
  7505. "68839": 68775,
  7506. "68840": 68776,
  7507. "68841": 68777,
  7508. "68842": 68778,
  7509. "68843": 68779,
  7510. "68844": 68780,
  7511. "68845": 68781,
  7512. "68846": 68782,
  7513. "68847": 68783,
  7514. "68848": 68784,
  7515. "68849": 68785,
  7516. "68850": 68786,
  7517. "71840": 71872,
  7518. "71841": 71873,
  7519. "71842": 71874,
  7520. "71843": 71875,
  7521. "71844": 71876,
  7522. "71845": 71877,
  7523. "71846": 71878,
  7524. "71847": 71879,
  7525. "71848": 71880,
  7526. "71849": 71881,
  7527. "71850": 71882,
  7528. "71851": 71883,
  7529. "71852": 71884,
  7530. "71853": 71885,
  7531. "71854": 71886,
  7532. "71855": 71887,
  7533. "71856": 71888,
  7534. "71857": 71889,
  7535. "71858": 71890,
  7536. "71859": 71891,
  7537. "71860": 71892,
  7538. "71861": 71893,
  7539. "71862": 71894,
  7540. "71863": 71895,
  7541. "71864": 71896,
  7542. "71865": 71897,
  7543. "71866": 71898,
  7544. "71867": 71899,
  7545. "71868": 71900,
  7546. "71869": 71901,
  7547. "71870": 71902,
  7548. "71871": 71903,
  7549. "71872": 71840,
  7550. "71873": 71841,
  7551. "71874": 71842,
  7552. "71875": 71843,
  7553. "71876": 71844,
  7554. "71877": 71845,
  7555. "71878": 71846,
  7556. "71879": 71847,
  7557. "71880": 71848,
  7558. "71881": 71849,
  7559. "71882": 71850,
  7560. "71883": 71851,
  7561. "71884": 71852,
  7562. "71885": 71853,
  7563. "71886": 71854,
  7564. "71887": 71855,
  7565. "71888": 71856,
  7566. "71889": 71857,
  7567. "71890": 71858,
  7568. "71891": 71859,
  7569. "71892": 71860,
  7570. "71893": 71861,
  7571. "71894": 71862,
  7572. "71895": 71863,
  7573. "71896": 71864,
  7574. "71897": 71865,
  7575. "71898": 71866,
  7576. "71899": 71867,
  7577. "71900": 71868,
  7578. "71901": 71869,
  7579. "71902": 71870,
  7580. "71903": 71871
  7581. };
  7582. var parser = __commonjs(function (module) {
  7583. // regjsparser
  7584. //
  7585. // ==================================================================
  7586. //
  7587. // See ECMA-262 Standard: 15.10.1
  7588. //
  7589. // NOTE: The ECMA-262 standard uses the term "Assertion" for /^/. Here the
  7590. // term "Anchor" is used.
  7591. //
  7592. // Pattern ::
  7593. // Disjunction
  7594. //
  7595. // Disjunction ::
  7596. // Alternative
  7597. // Alternative | Disjunction
  7598. //
  7599. // Alternative ::
  7600. // [empty]
  7601. // Alternative Term
  7602. //
  7603. // Term ::
  7604. // Anchor
  7605. // Atom
  7606. // Atom Quantifier
  7607. //
  7608. // Anchor ::
  7609. // ^
  7610. // $
  7611. // \ b
  7612. // \ B
  7613. // ( ? = Disjunction )
  7614. // ( ? ! Disjunction )
  7615. //
  7616. // Quantifier ::
  7617. // QuantifierPrefix
  7618. // QuantifierPrefix ?
  7619. //
  7620. // QuantifierPrefix ::
  7621. // *
  7622. // +
  7623. // ?
  7624. // { DecimalDigits }
  7625. // { DecimalDigits , }
  7626. // { DecimalDigits , DecimalDigits }
  7627. //
  7628. // Atom ::
  7629. // PatternCharacter
  7630. // .
  7631. // \ AtomEscape
  7632. // CharacterClass
  7633. // ( Disjunction )
  7634. // ( ? : Disjunction )
  7635. //
  7636. // PatternCharacter ::
  7637. // SourceCharacter but not any of: ^ $ \ . * + ? ( ) [ ] { } |
  7638. //
  7639. // AtomEscape ::
  7640. // DecimalEscape
  7641. // CharacterEscape
  7642. // CharacterClassEscape
  7643. //
  7644. // CharacterEscape[U] ::
  7645. // ControlEscape
  7646. // c ControlLetter
  7647. // HexEscapeSequence
  7648. // RegExpUnicodeEscapeSequence[?U] (ES6)
  7649. // IdentityEscape[?U]
  7650. //
  7651. // ControlEscape ::
  7652. // one of f n r t v
  7653. // ControlLetter ::
  7654. // one of
  7655. // 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
  7656. // 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
  7657. //
  7658. // IdentityEscape ::
  7659. // SourceCharacter but not IdentifierPart
  7660. // <ZWJ>
  7661. // <ZWNJ>
  7662. //
  7663. // DecimalEscape ::
  7664. // DecimalIntegerLiteral [lookahead ∉ DecimalDigit]
  7665. //
  7666. // CharacterClassEscape ::
  7667. // one of d D s S w W
  7668. //
  7669. // CharacterClass ::
  7670. // [ [lookahead ∉ {^}] ClassRanges ]
  7671. // [ ^ ClassRanges ]
  7672. //
  7673. // ClassRanges ::
  7674. // [empty]
  7675. // NonemptyClassRanges
  7676. //
  7677. // NonemptyClassRanges ::
  7678. // ClassAtom
  7679. // ClassAtom NonemptyClassRangesNoDash
  7680. // ClassAtom - ClassAtom ClassRanges
  7681. //
  7682. // NonemptyClassRangesNoDash ::
  7683. // ClassAtom
  7684. // ClassAtomNoDash NonemptyClassRangesNoDash
  7685. // ClassAtomNoDash - ClassAtom ClassRanges
  7686. //
  7687. // ClassAtom ::
  7688. // -
  7689. // ClassAtomNoDash
  7690. //
  7691. // ClassAtomNoDash ::
  7692. // SourceCharacter but not one of \ or ] or -
  7693. // \ ClassEscape
  7694. //
  7695. // ClassEscape ::
  7696. // DecimalEscape
  7697. // b
  7698. // CharacterEscape
  7699. // CharacterClassEscape
  7700. (function() {
  7701. function parse(str, flags) {
  7702. function addRaw(node) {
  7703. node.raw = str.substring(node.range[0], node.range[1]);
  7704. return node;
  7705. }
  7706. function updateRawStart(node, start) {
  7707. node.range[0] = start;
  7708. return addRaw(node);
  7709. }
  7710. function createAnchor(kind, rawLength) {
  7711. return addRaw({
  7712. type: 'anchor',
  7713. kind: kind,
  7714. range: [
  7715. pos - rawLength,
  7716. pos
  7717. ]
  7718. });
  7719. }
  7720. function createValue(kind, codePoint, from, to) {
  7721. return addRaw({
  7722. type: 'value',
  7723. kind: kind,
  7724. codePoint: codePoint,
  7725. range: [from, to]
  7726. });
  7727. }
  7728. function createEscaped(kind, codePoint, value, fromOffset) {
  7729. fromOffset = fromOffset || 0;
  7730. return createValue(kind, codePoint, pos - (value.length + fromOffset), pos);
  7731. }
  7732. function createCharacter(matches) {
  7733. var _char = matches[0];
  7734. var first = _char.charCodeAt(0);
  7735. if (hasUnicodeFlag) {
  7736. var second;
  7737. if (_char.length === 1 && first >= 0xD800 && first <= 0xDBFF) {
  7738. second = lookahead().charCodeAt(0);
  7739. if (second >= 0xDC00 && second <= 0xDFFF) {
  7740. // Unicode surrogate pair
  7741. pos++;
  7742. return createValue(
  7743. 'symbol',
  7744. (first - 0xD800) * 0x400 + second - 0xDC00 + 0x10000,
  7745. pos - 2, pos);
  7746. }
  7747. }
  7748. }
  7749. return createValue('symbol', first, pos - 1, pos);
  7750. }
  7751. function createDisjunction(alternatives, from, to) {
  7752. return addRaw({
  7753. type: 'disjunction',
  7754. body: alternatives,
  7755. range: [
  7756. from,
  7757. to
  7758. ]
  7759. });
  7760. }
  7761. function createDot() {
  7762. return addRaw({
  7763. type: 'dot',
  7764. range: [
  7765. pos - 1,
  7766. pos
  7767. ]
  7768. });
  7769. }
  7770. function createCharacterClassEscape(value) {
  7771. return addRaw({
  7772. type: 'characterClassEscape',
  7773. value: value,
  7774. range: [
  7775. pos - 2,
  7776. pos
  7777. ]
  7778. });
  7779. }
  7780. function createReference(matchIndex) {
  7781. return addRaw({
  7782. type: 'reference',
  7783. matchIndex: parseInt(matchIndex, 10),
  7784. range: [
  7785. pos - 1 - matchIndex.length,
  7786. pos
  7787. ]
  7788. });
  7789. }
  7790. function createGroup(behavior, disjunction, from, to) {
  7791. return addRaw({
  7792. type: 'group',
  7793. behavior: behavior,
  7794. body: disjunction,
  7795. range: [
  7796. from,
  7797. to
  7798. ]
  7799. });
  7800. }
  7801. function createQuantifier(min, max, from, to) {
  7802. if (to == null) {
  7803. from = pos - 1;
  7804. to = pos;
  7805. }
  7806. return addRaw({
  7807. type: 'quantifier',
  7808. min: min,
  7809. max: max,
  7810. greedy: true,
  7811. body: null, // set later on
  7812. range: [
  7813. from,
  7814. to
  7815. ]
  7816. });
  7817. }
  7818. function createAlternative(terms, from, to) {
  7819. return addRaw({
  7820. type: 'alternative',
  7821. body: terms,
  7822. range: [
  7823. from,
  7824. to
  7825. ]
  7826. });
  7827. }
  7828. function createCharacterClass(classRanges, negative, from, to) {
  7829. return addRaw({
  7830. type: 'characterClass',
  7831. body: classRanges,
  7832. negative: negative,
  7833. range: [
  7834. from,
  7835. to
  7836. ]
  7837. });
  7838. }
  7839. function createClassRange(min, max, from, to) {
  7840. // See 15.10.2.15:
  7841. if (min.codePoint > max.codePoint) {
  7842. bail('invalid range in character class', min.raw + '-' + max.raw, from, to);
  7843. }
  7844. return addRaw({
  7845. type: 'characterClassRange',
  7846. min: min,
  7847. max: max,
  7848. range: [
  7849. from,
  7850. to
  7851. ]
  7852. });
  7853. }
  7854. function flattenBody(body) {
  7855. if (body.type === 'alternative') {
  7856. return body.body;
  7857. } else {
  7858. return [body];
  7859. }
  7860. }
  7861. function isEmpty(obj) {
  7862. return obj.type === 'empty';
  7863. }
  7864. function incr(amount) {
  7865. amount = (amount || 1);
  7866. var res = str.substring(pos, pos + amount);
  7867. pos += (amount || 1);
  7868. return res;
  7869. }
  7870. function skip(value) {
  7871. if (!match(value)) {
  7872. bail('character', value);
  7873. }
  7874. }
  7875. function match(value) {
  7876. if (str.indexOf(value, pos) === pos) {
  7877. return incr(value.length);
  7878. }
  7879. }
  7880. function lookahead() {
  7881. return str[pos];
  7882. }
  7883. function current(value) {
  7884. return str.indexOf(value, pos) === pos;
  7885. }
  7886. function next(value) {
  7887. return str[pos + 1] === value;
  7888. }
  7889. function matchReg(regExp) {
  7890. var subStr = str.substring(pos);
  7891. var res = subStr.match(regExp);
  7892. if (res) {
  7893. res.range = [];
  7894. res.range[0] = pos;
  7895. incr(res[0].length);
  7896. res.range[1] = pos;
  7897. }
  7898. return res;
  7899. }
  7900. function parseDisjunction() {
  7901. // Disjunction ::
  7902. // Alternative
  7903. // Alternative | Disjunction
  7904. var res = [], from = pos;
  7905. res.push(parseAlternative());
  7906. while (match('|')) {
  7907. res.push(parseAlternative());
  7908. }
  7909. if (res.length === 1) {
  7910. return res[0];
  7911. }
  7912. return createDisjunction(res, from, pos);
  7913. }
  7914. function parseAlternative() {
  7915. var res = [], from = pos;
  7916. var term;
  7917. // Alternative ::
  7918. // [empty]
  7919. // Alternative Term
  7920. while (term = parseTerm()) {
  7921. res.push(term);
  7922. }
  7923. if (res.length === 1) {
  7924. return res[0];
  7925. }
  7926. return createAlternative(res, from, pos);
  7927. }
  7928. function parseTerm() {
  7929. // Term ::
  7930. // Anchor
  7931. // Atom
  7932. // Atom Quantifier
  7933. if (pos >= str.length || current('|') || current(')')) {
  7934. return null; /* Means: The term is empty */
  7935. }
  7936. var anchor = parseAnchor();
  7937. if (anchor) {
  7938. return anchor;
  7939. }
  7940. var atom = parseAtom();
  7941. if (!atom) {
  7942. bail('Expected atom');
  7943. }
  7944. var quantifier = parseQuantifier() || false;
  7945. if (quantifier) {
  7946. quantifier.body = flattenBody(atom);
  7947. // The quantifier contains the atom. Therefore, the beginning of the
  7948. // quantifier range is given by the beginning of the atom.
  7949. updateRawStart(quantifier, atom.range[0]);
  7950. return quantifier;
  7951. }
  7952. return atom;
  7953. }
  7954. function parseGroup(matchA, typeA, matchB, typeB) {
  7955. var type = null, from = pos;
  7956. if (match(matchA)) {
  7957. type = typeA;
  7958. } else if (match(matchB)) {
  7959. type = typeB;
  7960. } else {
  7961. return false;
  7962. }
  7963. var body = parseDisjunction();
  7964. if (!body) {
  7965. bail('Expected disjunction');
  7966. }
  7967. skip(')');
  7968. var group = createGroup(type, flattenBody(body), from, pos);
  7969. if (type == 'normal') {
  7970. // Keep track of the number of closed groups. This is required for
  7971. // parseDecimalEscape(). In case the string is parsed a second time the
  7972. // value already holds the total count and no incrementation is required.
  7973. if (firstIteration) {
  7974. closedCaptureCounter++;
  7975. }
  7976. }
  7977. return group;
  7978. }
  7979. function parseAnchor() {
  7980. // Anchor ::
  7981. // ^
  7982. // $
  7983. // \ b
  7984. // \ B
  7985. // ( ? = Disjunction )
  7986. // ( ? ! Disjunction )
  7987. var res, from = pos;
  7988. if (match('^')) {
  7989. return createAnchor('start', 1 /* rawLength */);
  7990. } else if (match('$')) {
  7991. return createAnchor('end', 1 /* rawLength */);
  7992. } else if (match('\\b')) {
  7993. return createAnchor('boundary', 2 /* rawLength */);
  7994. } else if (match('\\B')) {
  7995. return createAnchor('not-boundary', 2 /* rawLength */);
  7996. } else {
  7997. return parseGroup('(?=', 'lookahead', '(?!', 'negativeLookahead');
  7998. }
  7999. }
  8000. function parseQuantifier() {
  8001. // Quantifier ::
  8002. // QuantifierPrefix
  8003. // QuantifierPrefix ?
  8004. //
  8005. // QuantifierPrefix ::
  8006. // *
  8007. // +
  8008. // ?
  8009. // { DecimalDigits }
  8010. // { DecimalDigits , }
  8011. // { DecimalDigits , DecimalDigits }
  8012. var res, from = pos;
  8013. var quantifier;
  8014. var min, max;
  8015. if (match('*')) {
  8016. quantifier = createQuantifier(0);
  8017. }
  8018. else if (match('+')) {
  8019. quantifier = createQuantifier(1);
  8020. }
  8021. else if (match('?')) {
  8022. quantifier = createQuantifier(0, 1);
  8023. }
  8024. else if (res = matchReg(/^\{([0-9]+)\}/)) {
  8025. min = parseInt(res[1], 10);
  8026. quantifier = createQuantifier(min, min, res.range[0], res.range[1]);
  8027. }
  8028. else if (res = matchReg(/^\{([0-9]+),\}/)) {
  8029. min = parseInt(res[1], 10);
  8030. quantifier = createQuantifier(min, undefined, res.range[0], res.range[1]);
  8031. }
  8032. else if (res = matchReg(/^\{([0-9]+),([0-9]+)\}/)) {
  8033. min = parseInt(res[1], 10);
  8034. max = parseInt(res[2], 10);
  8035. if (min > max) {
  8036. bail('numbers out of order in {} quantifier', '', from, pos);
  8037. }
  8038. quantifier = createQuantifier(min, max, res.range[0], res.range[1]);
  8039. }
  8040. if (quantifier) {
  8041. if (match('?')) {
  8042. quantifier.greedy = false;
  8043. quantifier.range[1] += 1;
  8044. }
  8045. }
  8046. return quantifier;
  8047. }
  8048. function parseAtom() {
  8049. // Atom ::
  8050. // PatternCharacter
  8051. // .
  8052. // \ AtomEscape
  8053. // CharacterClass
  8054. // ( Disjunction )
  8055. // ( ? : Disjunction )
  8056. var res;
  8057. // jviereck: allow ']', '}' here as well to be compatible with browser's
  8058. // implementations: ']'.match(/]/);
  8059. // if (res = matchReg(/^[^^$\\.*+?()[\]{}|]/)) {
  8060. if (res = matchReg(/^[^^$\\.*+?(){[|]/)) {
  8061. // PatternCharacter
  8062. return createCharacter(res);
  8063. }
  8064. else if (match('.')) {
  8065. // .
  8066. return createDot();
  8067. }
  8068. else if (match('\\')) {
  8069. // \ AtomEscape
  8070. res = parseAtomEscape();
  8071. if (!res) {
  8072. bail('atomEscape');
  8073. }
  8074. return res;
  8075. }
  8076. else if (res = parseCharacterClass()) {
  8077. return res;
  8078. }
  8079. else {
  8080. // ( Disjunction )
  8081. // ( ? : Disjunction )
  8082. return parseGroup('(?:', 'ignore', '(', 'normal');
  8083. }
  8084. }
  8085. function parseUnicodeSurrogatePairEscape(firstEscape) {
  8086. if (hasUnicodeFlag) {
  8087. var first, second;
  8088. if (firstEscape.kind == 'unicodeEscape' &&
  8089. (first = firstEscape.codePoint) >= 0xD800 && first <= 0xDBFF &&
  8090. current('\\') && next('u') ) {
  8091. var prevPos = pos;
  8092. pos++;
  8093. var secondEscape = parseClassEscape();
  8094. if (secondEscape.kind == 'unicodeEscape' &&
  8095. (second = secondEscape.codePoint) >= 0xDC00 && second <= 0xDFFF) {
  8096. // Unicode surrogate pair
  8097. firstEscape.range[1] = secondEscape.range[1];
  8098. firstEscape.codePoint = (first - 0xD800) * 0x400 + second - 0xDC00 + 0x10000;
  8099. firstEscape.type = 'value';
  8100. firstEscape.kind = 'unicodeCodePointEscape';
  8101. addRaw(firstEscape);
  8102. }
  8103. else {
  8104. pos = prevPos;
  8105. }
  8106. }
  8107. }
  8108. return firstEscape;
  8109. }
  8110. function parseClassEscape() {
  8111. return parseAtomEscape(true);
  8112. }
  8113. function parseAtomEscape(insideCharacterClass) {
  8114. // AtomEscape ::
  8115. // DecimalEscape
  8116. // CharacterEscape
  8117. // CharacterClassEscape
  8118. var res, from = pos;
  8119. res = parseDecimalEscape();
  8120. if (res) {
  8121. return res;
  8122. }
  8123. // For ClassEscape
  8124. if (insideCharacterClass) {
  8125. if (match('b')) {
  8126. // 15.10.2.19
  8127. // The production ClassEscape :: b evaluates by returning the
  8128. // CharSet containing the one character <BS> (Unicode value 0008).
  8129. return createEscaped('singleEscape', 0x0008, '\\b');
  8130. } else if (match('B')) {
  8131. bail('\\B not possible inside of CharacterClass', '', from);
  8132. }
  8133. }
  8134. res = parseCharacterEscape();
  8135. return res;
  8136. }
  8137. function parseDecimalEscape() {
  8138. // DecimalEscape ::
  8139. // DecimalIntegerLiteral [lookahead ∉ DecimalDigit]
  8140. // CharacterClassEscape :: one of d D s S w W
  8141. var res, match;
  8142. if (res = matchReg(/^(?!0)\d+/)) {
  8143. match = res[0];
  8144. var refIdx = parseInt(res[0], 10);
  8145. if (refIdx <= closedCaptureCounter) {
  8146. // If the number is smaller than the normal-groups found so
  8147. // far, then it is a reference...
  8148. return createReference(res[0]);
  8149. } else {
  8150. // ... otherwise it needs to be interpreted as a octal (if the
  8151. // number is in an octal format). If it is NOT octal format,
  8152. // then the slash is ignored and the number is matched later
  8153. // as normal characters.
  8154. // Recall the negative decision to decide if the input must be parsed
  8155. // a second time with the total normal-groups.
  8156. backrefDenied.push(refIdx);
  8157. // Reset the position again, as maybe only parts of the previous
  8158. // matched numbers are actual octal numbers. E.g. in '019' only
  8159. // the '01' should be matched.
  8160. incr(-res[0].length);
  8161. if (res = matchReg(/^[0-7]{1,3}/)) {
  8162. return createEscaped('octal', parseInt(res[0], 8), res[0], 1);
  8163. } else {
  8164. // If we end up here, we have a case like /\91/. Then the
  8165. // first slash is to be ignored and the 9 & 1 to be treated
  8166. // like ordinary characters. Create a character for the
  8167. // first number only here - other number-characters
  8168. // (if available) will be matched later.
  8169. res = createCharacter(matchReg(/^[89]/));
  8170. return updateRawStart(res, res.range[0] - 1);
  8171. }
  8172. }
  8173. }
  8174. // Only allow octal numbers in the following. All matched numbers start
  8175. // with a zero (if the do not, the previous if-branch is executed).
  8176. // If the number is not octal format and starts with zero (e.g. `091`)
  8177. // then only the zeros `0` is treated here and the `91` are ordinary
  8178. // characters.
  8179. // Example:
  8180. // /\091/.exec('\091')[0].length === 3
  8181. else if (res = matchReg(/^[0-7]{1,3}/)) {
  8182. match = res[0];
  8183. if (/^0{1,3}$/.test(match)) {
  8184. // If they are all zeros, then only take the first one.
  8185. return createEscaped('null', 0x0000, '0', match.length + 1);
  8186. } else {
  8187. return createEscaped('octal', parseInt(match, 8), match, 1);
  8188. }
  8189. } else if (res = matchReg(/^[dDsSwW]/)) {
  8190. return createCharacterClassEscape(res[0]);
  8191. }
  8192. return false;
  8193. }
  8194. function parseCharacterEscape() {
  8195. // CharacterEscape ::
  8196. // ControlEscape
  8197. // c ControlLetter
  8198. // HexEscapeSequence
  8199. // UnicodeEscapeSequence
  8200. // IdentityEscape
  8201. var res;
  8202. if (res = matchReg(/^[fnrtv]/)) {
  8203. // ControlEscape
  8204. var codePoint = 0;
  8205. switch (res[0]) {
  8206. case 't': codePoint = 0x009; break;
  8207. case 'n': codePoint = 0x00A; break;
  8208. case 'v': codePoint = 0x00B; break;
  8209. case 'f': codePoint = 0x00C; break;
  8210. case 'r': codePoint = 0x00D; break;
  8211. }
  8212. return createEscaped('singleEscape', codePoint, '\\' + res[0]);
  8213. } else if (res = matchReg(/^c([a-zA-Z])/)) {
  8214. // c ControlLetter
  8215. return createEscaped('controlLetter', res[1].charCodeAt(0) % 32, res[1], 2);
  8216. } else if (res = matchReg(/^x([0-9a-fA-F]{2})/)) {
  8217. // HexEscapeSequence
  8218. return createEscaped('hexadecimalEscape', parseInt(res[1], 16), res[1], 2);
  8219. } else if (res = matchReg(/^u([0-9a-fA-F]{4})/)) {
  8220. // UnicodeEscapeSequence
  8221. return parseUnicodeSurrogatePairEscape(
  8222. createEscaped('unicodeEscape', parseInt(res[1], 16), res[1], 2)
  8223. );
  8224. } else if (hasUnicodeFlag && (res = matchReg(/^u\{([0-9a-fA-F]+)\}/))) {
  8225. // RegExpUnicodeEscapeSequence (ES6 Unicode code point escape)
  8226. return createEscaped('unicodeCodePointEscape', parseInt(res[1], 16), res[1], 4);
  8227. } else {
  8228. // IdentityEscape
  8229. return parseIdentityEscape();
  8230. }
  8231. }
  8232. // Taken from the Esprima parser.
  8233. function isIdentifierPart(ch) {
  8234. // Generated by `tools/generate-identifier-regex.js`.
  8235. 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]');
  8236. return (ch === 36) || (ch === 95) || // $ (dollar) and _ (underscore)
  8237. (ch >= 65 && ch <= 90) || // A..Z
  8238. (ch >= 97 && ch <= 122) || // a..z
  8239. (ch >= 48 && ch <= 57) || // 0..9
  8240. (ch === 92) || // \ (backslash)
  8241. ((ch >= 0x80) && NonAsciiIdentifierPart.test(String.fromCharCode(ch)));
  8242. }
  8243. function parseIdentityEscape() {
  8244. // IdentityEscape ::
  8245. // SourceCharacter but not IdentifierPart
  8246. // <ZWJ>
  8247. // <ZWNJ>
  8248. var ZWJ = '\u200C';
  8249. var ZWNJ = '\u200D';
  8250. var tmp;
  8251. if (!isIdentifierPart(lookahead())) {
  8252. tmp = incr();
  8253. return createEscaped('identifier', tmp.charCodeAt(0), tmp, 1);
  8254. }
  8255. if (match(ZWJ)) {
  8256. // <ZWJ>
  8257. return createEscaped('identifier', 0x200C, ZWJ);
  8258. } else if (match(ZWNJ)) {
  8259. // <ZWNJ>
  8260. return createEscaped('identifier', 0x200D, ZWNJ);
  8261. }
  8262. return null;
  8263. }
  8264. function parseCharacterClass() {
  8265. // CharacterClass ::
  8266. // [ [lookahead ∉ {^}] ClassRanges ]
  8267. // [ ^ ClassRanges ]
  8268. var res, from = pos;
  8269. if (res = matchReg(/^\[\^/)) {
  8270. res = parseClassRanges();
  8271. skip(']');
  8272. return createCharacterClass(res, true, from, pos);
  8273. } else if (match('[')) {
  8274. res = parseClassRanges();
  8275. skip(']');
  8276. return createCharacterClass(res, false, from, pos);
  8277. }
  8278. return null;
  8279. }
  8280. function parseClassRanges() {
  8281. // ClassRanges ::
  8282. // [empty]
  8283. // NonemptyClassRanges
  8284. var res;
  8285. if (current(']')) {
  8286. // Empty array means nothing insinde of the ClassRange.
  8287. return [];
  8288. } else {
  8289. res = parseNonemptyClassRanges();
  8290. if (!res) {
  8291. bail('nonEmptyClassRanges');
  8292. }
  8293. return res;
  8294. }
  8295. }
  8296. function parseHelperClassRanges(atom) {
  8297. var from, to, res;
  8298. if (current('-') && !next(']')) {
  8299. // ClassAtom - ClassAtom ClassRanges
  8300. skip('-');
  8301. res = parseClassAtom();
  8302. if (!res) {
  8303. bail('classAtom');
  8304. }
  8305. to = pos;
  8306. var classRanges = parseClassRanges();
  8307. if (!classRanges) {
  8308. bail('classRanges');
  8309. }
  8310. from = atom.range[0];
  8311. if (classRanges.type === 'empty') {
  8312. return [createClassRange(atom, res, from, to)];
  8313. }
  8314. return [createClassRange(atom, res, from, to)].concat(classRanges);
  8315. }
  8316. res = parseNonemptyClassRangesNoDash();
  8317. if (!res) {
  8318. bail('nonEmptyClassRangesNoDash');
  8319. }
  8320. return [atom].concat(res);
  8321. }
  8322. function parseNonemptyClassRanges() {
  8323. // NonemptyClassRanges ::
  8324. // ClassAtom
  8325. // ClassAtom NonemptyClassRangesNoDash
  8326. // ClassAtom - ClassAtom ClassRanges
  8327. var atom = parseClassAtom();
  8328. if (!atom) {
  8329. bail('classAtom');
  8330. }
  8331. if (current(']')) {
  8332. // ClassAtom
  8333. return [atom];
  8334. }
  8335. // ClassAtom NonemptyClassRangesNoDash
  8336. // ClassAtom - ClassAtom ClassRanges
  8337. return parseHelperClassRanges(atom);
  8338. }
  8339. function parseNonemptyClassRangesNoDash() {
  8340. // NonemptyClassRangesNoDash ::
  8341. // ClassAtom
  8342. // ClassAtomNoDash NonemptyClassRangesNoDash
  8343. // ClassAtomNoDash - ClassAtom ClassRanges
  8344. var res = parseClassAtom();
  8345. if (!res) {
  8346. bail('classAtom');
  8347. }
  8348. if (current(']')) {
  8349. // ClassAtom
  8350. return res;
  8351. }
  8352. // ClassAtomNoDash NonemptyClassRangesNoDash
  8353. // ClassAtomNoDash - ClassAtom ClassRanges
  8354. return parseHelperClassRanges(res);
  8355. }
  8356. function parseClassAtom() {
  8357. // ClassAtom ::
  8358. // -
  8359. // ClassAtomNoDash
  8360. if (match('-')) {
  8361. return createCharacter('-');
  8362. } else {
  8363. return parseClassAtomNoDash();
  8364. }
  8365. }
  8366. function parseClassAtomNoDash() {
  8367. // ClassAtomNoDash ::
  8368. // SourceCharacter but not one of \ or ] or -
  8369. // \ ClassEscape
  8370. var res;
  8371. if (res = matchReg(/^[^\\\]-]/)) {
  8372. return createCharacter(res[0]);
  8373. } else if (match('\\')) {
  8374. res = parseClassEscape();
  8375. if (!res) {
  8376. bail('classEscape');
  8377. }
  8378. return parseUnicodeSurrogatePairEscape(res);
  8379. }
  8380. }
  8381. function bail(message, details, from, to) {
  8382. from = from == null ? pos : from;
  8383. to = to == null ? from : to;
  8384. var contextStart = Math.max(0, from - 10);
  8385. var contextEnd = Math.min(to + 10, str.length);
  8386. // Output a bit of context and a line pointing to where our error is.
  8387. //
  8388. // We are assuming that there are no actual newlines in the content as this is a regular expression.
  8389. var context = ' ' + str.substring(contextStart, contextEnd);
  8390. var pointer = ' ' + new Array(from - contextStart + 1).join(' ') + '^';
  8391. throw SyntaxError(message + ' at position ' + from + (details ? ': ' + details : '') + '\n' + context + '\n' + pointer);
  8392. }
  8393. var backrefDenied = [];
  8394. var closedCaptureCounter = 0;
  8395. var firstIteration = true;
  8396. var hasUnicodeFlag = (flags || "").indexOf("u") !== -1;
  8397. var pos = 0;
  8398. // Convert the input to a string and treat the empty string special.
  8399. str = String(str);
  8400. if (str === '') {
  8401. str = '(?:)';
  8402. }
  8403. var result = parseDisjunction();
  8404. if (result.range[1] !== str.length) {
  8405. bail('Could not parse entire input - got stuck', '', result.range[1]);
  8406. }
  8407. // The spec requires to interpret the `\2` in `/\2()()/` as backreference.
  8408. // As the parser collects the number of capture groups as the string is
  8409. // parsed it is impossible to make these decisions at the point when the
  8410. // `\2` is handled. In case the local decision turns out to be wrong after
  8411. // the parsing has finished, the input string is parsed a second time with
  8412. // the total number of capture groups set.
  8413. //
  8414. // SEE: https://github.com/jviereck/regjsparser/issues/70
  8415. for (var i = 0; i < backrefDenied.length; i++) {
  8416. if (backrefDenied[i] <= closedCaptureCounter) {
  8417. // Parse the input a second time.
  8418. pos = 0;
  8419. firstIteration = false;
  8420. return parseDisjunction();
  8421. }
  8422. }
  8423. return result;
  8424. }
  8425. var regjsparser = {
  8426. parse: parse
  8427. };
  8428. if (typeof module !== 'undefined' && module.exports) {
  8429. module.exports = regjsparser;
  8430. } else {
  8431. window.regjsparser = regjsparser;
  8432. }
  8433. }());
  8434. });
  8435. var require$$3 = (parser && typeof parser === 'object' && 'default' in parser ? parser['default'] : parser);
  8436. var regjsgen = __commonjs(function (module, exports, global) {
  8437. /*!
  8438. * RegJSGen
  8439. * Copyright 2014 Benjamin Tan <https://d10.github.io/>
  8440. * Available under MIT license <http://d10.mit-license.org/>
  8441. */
  8442. (function() {
  8443. 'use strict';
  8444. /** Used to determine if values are of the language type `Object` */
  8445. var objectTypes = {
  8446. 'function': true,
  8447. 'object': true
  8448. };
  8449. /** Used as a reference to the global object */
  8450. var root = (objectTypes[typeof window] && window) || this;
  8451. /** Backup possible global object */
  8452. var oldRoot = root;
  8453. /** Detect free variable `exports` */
  8454. var freeExports = objectTypes[typeof exports] && exports;
  8455. /** Detect free variable `module` */
  8456. var freeModule = objectTypes[typeof module] && module && !module.nodeType && module;
  8457. /** Detect free variable `global` from Node.js or Browserified code and use it as `root` */
  8458. var freeGlobal = freeExports && freeModule && typeof global == 'object' && global;
  8459. if (freeGlobal && (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal || freeGlobal.self === freeGlobal)) {
  8460. root = freeGlobal;
  8461. }
  8462. /*--------------------------------------------------------------------------*/
  8463. /*! Based on https://mths.be/fromcodepoint v0.2.0 by @mathias */
  8464. var stringFromCharCode = String.fromCharCode;
  8465. var floor = Math.floor;
  8466. function fromCodePoint() {
  8467. var MAX_SIZE = 0x4000;
  8468. var codeUnits = [];
  8469. var highSurrogate;
  8470. var lowSurrogate;
  8471. var index = -1;
  8472. var length = arguments.length;
  8473. if (!length) {
  8474. return '';
  8475. }
  8476. var result = '';
  8477. while (++index < length) {
  8478. var codePoint = Number(arguments[index]);
  8479. if (
  8480. !isFinite(codePoint) || // `NaN`, `+Infinity`, or `-Infinity`
  8481. codePoint < 0 || // not a valid Unicode code point
  8482. codePoint > 0x10FFFF || // not a valid Unicode code point
  8483. floor(codePoint) != codePoint // not an integer
  8484. ) {
  8485. throw RangeError('Invalid code point: ' + codePoint);
  8486. }
  8487. if (codePoint <= 0xFFFF) {
  8488. // BMP code point
  8489. codeUnits.push(codePoint);
  8490. } else {
  8491. // Astral code point; split in surrogate halves
  8492. // http://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
  8493. codePoint -= 0x10000;
  8494. highSurrogate = (codePoint >> 10) + 0xD800;
  8495. lowSurrogate = (codePoint % 0x400) + 0xDC00;
  8496. codeUnits.push(highSurrogate, lowSurrogate);
  8497. }
  8498. if (index + 1 == length || codeUnits.length > MAX_SIZE) {
  8499. result += stringFromCharCode.apply(null, codeUnits);
  8500. codeUnits.length = 0;
  8501. }
  8502. }
  8503. return result;
  8504. }
  8505. function assertType(type, expected) {
  8506. if (expected.indexOf('|') == -1) {
  8507. if (type == expected) {
  8508. return;
  8509. }
  8510. throw Error('Invalid node type: ' + type);
  8511. }
  8512. expected = assertType.hasOwnProperty(expected)
  8513. ? assertType[expected]
  8514. : (assertType[expected] = RegExp('^(?:' + expected + ')$'));
  8515. if (expected.test(type)) {
  8516. return;
  8517. }
  8518. throw Error('Invalid node type: ' + type);
  8519. }
  8520. /*--------------------------------------------------------------------------*/
  8521. function generate(node) {
  8522. var type = node.type;
  8523. if (generate.hasOwnProperty(type) && typeof generate[type] == 'function') {
  8524. return generate[type](node);
  8525. }
  8526. throw Error('Invalid node type: ' + type);
  8527. }
  8528. /*--------------------------------------------------------------------------*/
  8529. function generateAlternative(node) {
  8530. assertType(node.type, 'alternative');
  8531. var terms = node.body,
  8532. length = terms ? terms.length : 0;
  8533. if (length == 1) {
  8534. return generateTerm(terms[0]);
  8535. } else {
  8536. var i = -1,
  8537. result = '';
  8538. while (++i < length) {
  8539. result += generateTerm(terms[i]);
  8540. }
  8541. return result;
  8542. }
  8543. }
  8544. function generateAnchor(node) {
  8545. assertType(node.type, 'anchor');
  8546. switch (node.kind) {
  8547. case 'start':
  8548. return '^';
  8549. case 'end':
  8550. return '$';
  8551. case 'boundary':
  8552. return '\\b';
  8553. case 'not-boundary':
  8554. return '\\B';
  8555. default:
  8556. throw Error('Invalid assertion');
  8557. }
  8558. }
  8559. function generateAtom(node) {
  8560. assertType(node.type, 'anchor|characterClass|characterClassEscape|dot|group|reference|value');
  8561. return generate(node);
  8562. }
  8563. function generateCharacterClass(node) {
  8564. assertType(node.type, 'characterClass');
  8565. var classRanges = node.body,
  8566. length = classRanges ? classRanges.length : 0;
  8567. var i = -1,
  8568. result = '[';
  8569. if (node.negative) {
  8570. result += '^';
  8571. }
  8572. while (++i < length) {
  8573. result += generateClassAtom(classRanges[i]);
  8574. }
  8575. result += ']';
  8576. return result;
  8577. }
  8578. function generateCharacterClassEscape(node) {
  8579. assertType(node.type, 'characterClassEscape');
  8580. return '\\' + node.value;
  8581. }
  8582. function generateCharacterClassRange(node) {
  8583. assertType(node.type, 'characterClassRange');
  8584. var min = node.min,
  8585. max = node.max;
  8586. if (min.type == 'characterClassRange' || max.type == 'characterClassRange') {
  8587. throw Error('Invalid character class range');
  8588. }
  8589. return generateClassAtom(min) + '-' + generateClassAtom(max);
  8590. }
  8591. function generateClassAtom(node) {
  8592. assertType(node.type, 'anchor|characterClassEscape|characterClassRange|dot|value');
  8593. return generate(node);
  8594. }
  8595. function generateDisjunction(node) {
  8596. assertType(node.type, 'disjunction');
  8597. var body = node.body,
  8598. length = body ? body.length : 0;
  8599. if (length == 0) {
  8600. throw Error('No body');
  8601. } else if (length == 1) {
  8602. return generate(body[0]);
  8603. } else {
  8604. var i = -1,
  8605. result = '';
  8606. while (++i < length) {
  8607. if (i != 0) {
  8608. result += '|';
  8609. }
  8610. result += generate(body[i]);
  8611. }
  8612. return result;
  8613. }
  8614. }
  8615. function generateDot(node) {
  8616. assertType(node.type, 'dot');
  8617. return '.';
  8618. }
  8619. function generateGroup(node) {
  8620. assertType(node.type, 'group');
  8621. var result = '(';
  8622. switch (node.behavior) {
  8623. case 'normal':
  8624. break;
  8625. case 'ignore':
  8626. result += '?:';
  8627. break;
  8628. case 'lookahead':
  8629. result += '?=';
  8630. break;
  8631. case 'negativeLookahead':
  8632. result += '?!';
  8633. break;
  8634. default:
  8635. throw Error('Invalid behaviour: ' + node.behaviour);
  8636. }
  8637. var body = node.body,
  8638. length = body ? body.length : 0;
  8639. if (length == 1) {
  8640. result += generate(body[0]);
  8641. } else {
  8642. var i = -1;
  8643. while (++i < length) {
  8644. result += generate(body[i]);
  8645. }
  8646. }
  8647. result += ')';
  8648. return result;
  8649. }
  8650. function generateQuantifier(node) {
  8651. assertType(node.type, 'quantifier');
  8652. var quantifier = '',
  8653. min = node.min,
  8654. max = node.max;
  8655. switch (max) {
  8656. case undefined:
  8657. case null:
  8658. switch (min) {
  8659. case 0:
  8660. quantifier = '*';
  8661. break;
  8662. case 1:
  8663. quantifier = '+';
  8664. break;
  8665. default:
  8666. quantifier = '{' + min + ',}';
  8667. break;
  8668. }
  8669. break;
  8670. default:
  8671. if (min == max) {
  8672. quantifier = '{' + min + '}';
  8673. }
  8674. else if (min == 0 && max == 1) {
  8675. quantifier = '?';
  8676. } else {
  8677. quantifier = '{' + min + ',' + max + '}';
  8678. }
  8679. break;
  8680. }
  8681. if (!node.greedy) {
  8682. quantifier += '?';
  8683. }
  8684. return generateAtom(node.body[0]) + quantifier;
  8685. }
  8686. function generateReference(node) {
  8687. assertType(node.type, 'reference');
  8688. return '\\' + node.matchIndex;
  8689. }
  8690. function generateTerm(node) {
  8691. assertType(node.type, 'anchor|characterClass|characterClassEscape|empty|group|quantifier|reference|value');
  8692. return generate(node);
  8693. }
  8694. function generateValue(node) {
  8695. assertType(node.type, 'value');
  8696. var kind = node.kind,
  8697. codePoint = node.codePoint;
  8698. switch (kind) {
  8699. case 'controlLetter':
  8700. return '\\c' + fromCodePoint(codePoint + 64);
  8701. case 'hexadecimalEscape':
  8702. return '\\x' + ('00' + codePoint.toString(16).toUpperCase()).slice(-2);
  8703. case 'identifier':
  8704. return '\\' + fromCodePoint(codePoint);
  8705. case 'null':
  8706. return '\\' + codePoint;
  8707. case 'octal':
  8708. return '\\' + codePoint.toString(8);
  8709. case 'singleEscape':
  8710. switch (codePoint) {
  8711. case 0x0008:
  8712. return '\\b';
  8713. case 0x009:
  8714. return '\\t';
  8715. case 0x00A:
  8716. return '\\n';
  8717. case 0x00B:
  8718. return '\\v';
  8719. case 0x00C:
  8720. return '\\f';
  8721. case 0x00D:
  8722. return '\\r';
  8723. default:
  8724. throw Error('Invalid codepoint: ' + codePoint);
  8725. }
  8726. case 'symbol':
  8727. return fromCodePoint(codePoint);
  8728. case 'unicodeEscape':
  8729. return '\\u' + ('0000' + codePoint.toString(16).toUpperCase()).slice(-4);
  8730. case 'unicodeCodePointEscape':
  8731. return '\\u{' + codePoint.toString(16).toUpperCase() + '}';
  8732. default:
  8733. throw Error('Unsupported node kind: ' + kind);
  8734. }
  8735. }
  8736. /*--------------------------------------------------------------------------*/
  8737. generate.alternative = generateAlternative;
  8738. generate.anchor = generateAnchor;
  8739. generate.characterClass = generateCharacterClass;
  8740. generate.characterClassEscape = generateCharacterClassEscape;
  8741. generate.characterClassRange = generateCharacterClassRange;
  8742. generate.disjunction = generateDisjunction;
  8743. generate.dot = generateDot;
  8744. generate.group = generateGroup;
  8745. generate.quantifier = generateQuantifier;
  8746. generate.reference = generateReference;
  8747. generate.value = generateValue;
  8748. /*--------------------------------------------------------------------------*/
  8749. // export regjsgen
  8750. // some AMD build optimizers, like r.js, check for condition patterns like the following:
  8751. if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
  8752. // define as an anonymous module so, through path mapping, it can be aliased
  8753. define(function() {
  8754. return {
  8755. 'generate': generate
  8756. };
  8757. });
  8758. }
  8759. // check for `exports` after `define` in case a build optimizer adds an `exports` object
  8760. else if (freeExports && freeModule) {
  8761. // in Narwhal, Node.js, Rhino -require, or RingoJS
  8762. freeExports.generate = generate;
  8763. }
  8764. // in a browser or Rhino
  8765. else {
  8766. root.regjsgen = {
  8767. 'generate': generate
  8768. };
  8769. }
  8770. }.call(__commonjs_global));
  8771. });
  8772. var require$$4 = (regjsgen && typeof regjsgen === 'object' && 'default' in regjsgen ? regjsgen['default'] : regjsgen);
  8773. var rewritePattern = __commonjs(function (module) {
  8774. var generate = require$$4.generate;
  8775. var parse = require$$3.parse;
  8776. var regenerate = require$$0$2;
  8777. var iuMappings = require$$1;
  8778. var ESCAPE_SETS = require$$0$1;
  8779. function getCharacterClassEscapeSet(character) {
  8780. if (unicode) {
  8781. if (ignoreCase) {
  8782. return ESCAPE_SETS.UNICODE_IGNORE_CASE[character];
  8783. }
  8784. return ESCAPE_SETS.UNICODE[character];
  8785. }
  8786. return ESCAPE_SETS.REGULAR[character];
  8787. }
  8788. var object = {};
  8789. var hasOwnProperty = object.hasOwnProperty;
  8790. function has(object, property) {
  8791. return hasOwnProperty.call(object, property);
  8792. }
  8793. // Prepare a Regenerate set containing all code points, used for negative
  8794. // character classes (if any).
  8795. var UNICODE_SET = regenerate().addRange(0x0, 0x10FFFF);
  8796. // Without the `u` flag, the range stops at 0xFFFF.
  8797. // https://mths.be/es6#sec-pattern-semantics
  8798. var BMP_SET = regenerate().addRange(0x0, 0xFFFF);
  8799. // Prepare a Regenerate set containing all code points that are supposed to be
  8800. // matched by `/./u`. https://mths.be/es6#sec-atom
  8801. var DOT_SET_UNICODE = UNICODE_SET.clone() // all Unicode code points
  8802. .remove(
  8803. // minus `LineTerminator`s (https://mths.be/es6#sec-line-terminators):
  8804. 0x000A, // Line Feed <LF>
  8805. 0x000D, // Carriage Return <CR>
  8806. 0x2028, // Line Separator <LS>
  8807. 0x2029 // Paragraph Separator <PS>
  8808. );
  8809. // Prepare a Regenerate set containing all code points that are supposed to be
  8810. // matched by `/./` (only BMP code points).
  8811. var DOT_SET = DOT_SET_UNICODE.clone()
  8812. .intersection(BMP_SET);
  8813. // Add a range of code points + any case-folded code points in that range to a
  8814. // set.
  8815. regenerate.prototype.iuAddRange = function(min, max) {
  8816. var $this = this;
  8817. do {
  8818. var folded = caseFold(min);
  8819. if (folded) {
  8820. $this.add(folded);
  8821. }
  8822. } while (++min <= max);
  8823. return $this;
  8824. };
  8825. function assign(target, source) {
  8826. for (var key in source) {
  8827. // Note: `hasOwnProperty` is not needed here.
  8828. target[key] = source[key];
  8829. }
  8830. }
  8831. function update(item, pattern) {
  8832. // TODO: Test if memoizing `pattern` here is worth the effort.
  8833. if (!pattern) {
  8834. return;
  8835. }
  8836. var tree = parse(pattern, '');
  8837. switch (tree.type) {
  8838. case 'characterClass':
  8839. case 'group':
  8840. case 'value':
  8841. // No wrapping needed.
  8842. break;
  8843. default:
  8844. // Wrap the pattern in a non-capturing group.
  8845. tree = wrap(tree, pattern);
  8846. }
  8847. assign(item, tree);
  8848. }
  8849. function wrap(tree, pattern) {
  8850. // Wrap the pattern in a non-capturing group.
  8851. return {
  8852. 'type': 'group',
  8853. 'behavior': 'ignore',
  8854. 'body': [tree],
  8855. 'raw': '(?:' + pattern + ')'
  8856. };
  8857. }
  8858. function caseFold(codePoint) {
  8859. return has(iuMappings, codePoint) ? iuMappings[codePoint] : false;
  8860. }
  8861. var ignoreCase = false;
  8862. var unicode = false;
  8863. function processCharacterClass(characterClassItem) {
  8864. var set = regenerate();
  8865. var body = characterClassItem.body.forEach(function(item) {
  8866. switch (item.type) {
  8867. case 'value':
  8868. set.add(item.codePoint);
  8869. if (ignoreCase && unicode) {
  8870. var folded = caseFold(item.codePoint);
  8871. if (folded) {
  8872. set.add(folded);
  8873. }
  8874. }
  8875. break;
  8876. case 'characterClassRange':
  8877. var min = item.min.codePoint;
  8878. var max = item.max.codePoint;
  8879. set.addRange(min, max);
  8880. if (ignoreCase && unicode) {
  8881. set.iuAddRange(min, max);
  8882. }
  8883. break;
  8884. case 'characterClassEscape':
  8885. set.add(getCharacterClassEscapeSet(item.value));
  8886. break;
  8887. // The `default` clause is only here as a safeguard; it should never be
  8888. // reached. Code coverage tools should ignore it.
  8889. /* istanbul ignore next */
  8890. default:
  8891. throw Error('Unknown term type: ' + item.type);
  8892. }
  8893. });
  8894. if (characterClassItem.negative) {
  8895. set = (unicode ? UNICODE_SET : BMP_SET).clone().remove(set);
  8896. }
  8897. update(characterClassItem, set.toString());
  8898. return characterClassItem;
  8899. }
  8900. function processTerm(item) {
  8901. switch (item.type) {
  8902. case 'dot':
  8903. update(
  8904. item,
  8905. (unicode ? DOT_SET_UNICODE : DOT_SET).toString()
  8906. );
  8907. break;
  8908. case 'characterClass':
  8909. item = processCharacterClass(item);
  8910. break;
  8911. case 'characterClassEscape':
  8912. update(
  8913. item,
  8914. getCharacterClassEscapeSet(item.value).toString()
  8915. );
  8916. break;
  8917. case 'alternative':
  8918. case 'disjunction':
  8919. case 'group':
  8920. case 'quantifier':
  8921. item.body = item.body.map(processTerm);
  8922. break;
  8923. case 'value':
  8924. var codePoint = item.codePoint;
  8925. var set = regenerate(codePoint);
  8926. if (ignoreCase && unicode) {
  8927. var folded = caseFold(codePoint);
  8928. if (folded) {
  8929. set.add(folded);
  8930. }
  8931. }
  8932. update(item, set.toString());
  8933. break;
  8934. case 'anchor':
  8935. case 'empty':
  8936. case 'group':
  8937. case 'reference':
  8938. // Nothing to do here.
  8939. break;
  8940. // The `default` clause is only here as a safeguard; it should never be
  8941. // reached. Code coverage tools should ignore it.
  8942. /* istanbul ignore next */
  8943. default:
  8944. throw Error('Unknown term type: ' + item.type);
  8945. }
  8946. return item;
  8947. }
  8948. module.exports = function(pattern, flags) {
  8949. var tree = parse(pattern, flags);
  8950. ignoreCase = flags ? flags.indexOf('i') > -1 : false;
  8951. unicode = flags ? flags.indexOf('u') > -1 : false;
  8952. assign(tree, processTerm(tree));
  8953. return generate(tree);
  8954. };
  8955. });
  8956. var rewritePattern$1 = (rewritePattern && typeof rewritePattern === 'object' && 'default' in rewritePattern ? rewritePattern['default'] : rewritePattern);
  8957. var Literal = (function (Node$$1) {
  8958. function Literal () {
  8959. Node$$1.apply(this, arguments);
  8960. }
  8961. if ( Node$$1 ) Literal.__proto__ = Node$$1;
  8962. Literal.prototype = Object.create( Node$$1 && Node$$1.prototype );
  8963. Literal.prototype.constructor = Literal;
  8964. Literal.prototype.initialise = function initialise () {
  8965. if ( typeof this.value === 'string' ) {
  8966. this.program.indentExclusionElements.push( this );
  8967. }
  8968. };
  8969. Literal.prototype.transpile = function transpile ( code, transforms ) {
  8970. if ( transforms.numericLiteral ) {
  8971. var leading = this.raw.slice( 0, 2 );
  8972. if ( leading === '0b' || leading === '0o' ) {
  8973. code.overwrite( this.start, this.end, String( this.value ), true );
  8974. }
  8975. }
  8976. if ( this.regex ) {
  8977. var ref = this.regex;
  8978. var pattern = ref.pattern;
  8979. var flags = ref.flags;
  8980. if ( transforms.stickyRegExp && /y/.test( flags ) ) throw new CompileError( this, 'Regular expression sticky flag is not supported' );
  8981. if ( transforms.unicodeRegExp && /u/.test( flags ) ) {
  8982. code.overwrite( this.start, this.end, ("/" + (rewritePattern$1( pattern, flags )) + "/" + (flags.replace( 'u', '' ))) );
  8983. }
  8984. }
  8985. };
  8986. return Literal;
  8987. }(Node));
  8988. var MemberExpression = (function (Node$$1) {
  8989. function MemberExpression () {
  8990. Node$$1.apply(this, arguments);
  8991. }
  8992. if ( Node$$1 ) MemberExpression.__proto__ = Node$$1;
  8993. MemberExpression.prototype = Object.create( Node$$1 && Node$$1.prototype );
  8994. MemberExpression.prototype.constructor = MemberExpression;
  8995. MemberExpression.prototype.transpile = function transpile ( code, transforms ) {
  8996. if ( transforms.reservedProperties && reserved[ this.property.name ] ) {
  8997. code.overwrite( this.object.end, this.property.start, "['" );
  8998. code.insertLeft( this.property.end, "']" );
  8999. }
  9000. Node$$1.prototype.transpile.call( this, code, transforms );
  9001. };
  9002. return MemberExpression;
  9003. }(Node));
  9004. var NewExpression = (function (Node$$1) {
  9005. function NewExpression () {
  9006. Node$$1.apply(this, arguments);
  9007. }
  9008. if ( Node$$1 ) NewExpression.__proto__ = Node$$1;
  9009. NewExpression.prototype = Object.create( Node$$1 && Node$$1.prototype );
  9010. NewExpression.prototype.constructor = NewExpression;
  9011. NewExpression.prototype.initialise = function initialise ( transforms ) {
  9012. var this$1 = this;
  9013. if ( transforms.spreadRest && this.arguments.length ) {
  9014. var lexicalBoundary = this.findLexicalBoundary();
  9015. var i = this.arguments.length;
  9016. while ( i-- ) {
  9017. var arg = this$1.arguments[i];
  9018. if ( arg.type === 'SpreadElement' && isArguments( arg.argument ) ) {
  9019. this$1.argumentsArrayAlias = lexicalBoundary.getArgumentsArrayAlias();
  9020. break;
  9021. }
  9022. }
  9023. }
  9024. Node$$1.prototype.initialise.call( this, transforms );
  9025. };
  9026. NewExpression.prototype.transpile = function transpile ( code, transforms ) {
  9027. if ( transforms.spreadRest && this.arguments.length ) {
  9028. var firstArgument = this.arguments[0];
  9029. var isNew = true;
  9030. var hasSpreadElements = spread( code, this.arguments, firstArgument.start, this.argumentsArrayAlias, isNew );
  9031. if ( hasSpreadElements ) {
  9032. code.insertRight( this.start + 'new'.length, ' (Function.prototype.bind.apply(' );
  9033. code.overwrite( this.callee.end, firstArgument.start, ', [ null ].concat( ' );
  9034. code.insertLeft( this.end, ' ))' );
  9035. }
  9036. }
  9037. Node$$1.prototype.transpile.call( this, code, transforms );
  9038. };
  9039. return NewExpression;
  9040. }(Node));
  9041. var ObjectExpression = (function (Node$$1) {
  9042. function ObjectExpression () {
  9043. Node$$1.apply(this, arguments);
  9044. }
  9045. if ( Node$$1 ) ObjectExpression.__proto__ = Node$$1;
  9046. ObjectExpression.prototype = Object.create( Node$$1 && Node$$1.prototype );
  9047. ObjectExpression.prototype.constructor = ObjectExpression;
  9048. ObjectExpression.prototype.transpile = function transpile ( code, transforms ) {
  9049. var this$1 = this;
  9050. Node$$1.prototype.transpile.call( this, code, transforms );
  9051. var firstPropertyStart = this.start + 1;
  9052. var regularPropertyCount = 0;
  9053. var spreadPropertyCount = 0;
  9054. var computedPropertyCount = 0;
  9055. for ( var i$2 = 0, list = this.properties; i$2 < list.length; i$2 += 1 ) {
  9056. var prop = list[i$2];
  9057. if ( prop.type === 'SpreadProperty' ) {
  9058. spreadPropertyCount += 1;
  9059. } else if ( prop.computed ) {
  9060. computedPropertyCount += 1;
  9061. } else if ( prop.type === 'Property' ) {
  9062. regularPropertyCount += 1;
  9063. }
  9064. }
  9065. if ( spreadPropertyCount ) {
  9066. if ( !this.program.options.objectAssign ) {
  9067. throw new CompileError( this, 'Object spread operator requires specified objectAssign option with \'Object.assign\' or polyfill helper.' );
  9068. }
  9069. // enclose run of non-spread properties in curlies
  9070. var i = this.properties.length;
  9071. if ( regularPropertyCount ) {
  9072. while ( i-- ) {
  9073. var prop$1 = this$1.properties[i];
  9074. if ( prop$1.type === 'Property' && !prop$1.computed ) {
  9075. var lastProp = this$1.properties[ i - 1 ];
  9076. var nextProp = this$1.properties[ i + 1 ];
  9077. if ( !lastProp || lastProp.type !== 'Property' || lastProp.computed ) {
  9078. code.insertRight( prop$1.start, '{' );
  9079. }
  9080. if ( !nextProp || nextProp.type !== 'Property' || nextProp.computed ) {
  9081. code.insertLeft( prop$1.end, '}' );
  9082. }
  9083. }
  9084. }
  9085. }
  9086. // wrap the whole thing in Object.assign
  9087. firstPropertyStart = this.properties[0].start;
  9088. code.overwrite( this.start, firstPropertyStart, ((this.program.options.objectAssign) + "({}, "));
  9089. code.overwrite( this.properties[ this.properties.length - 1 ].end, this.end, ')' );
  9090. }
  9091. if ( computedPropertyCount && transforms.computedProperty ) {
  9092. var i0 = this.getIndentation();
  9093. var isSimpleAssignment;
  9094. var name;
  9095. if ( this.parent.type === 'VariableDeclarator' && this.parent.parent.declarations.length === 1 ) {
  9096. isSimpleAssignment = true;
  9097. name = this.parent.id.alias || this.parent.id.name; // TODO is this right?
  9098. } else if ( this.parent.type === 'AssignmentExpression' && this.parent.parent.type === 'ExpressionStatement' && this.parent.left.type === 'Identifier' ) {
  9099. isSimpleAssignment = true;
  9100. name = this.parent.left.alias || this.parent.left.name; // TODO is this right?
  9101. } else if ( this.parent.type === 'AssignmentPattern' && this.parent.left.type === 'Identifier' ) {
  9102. isSimpleAssignment = true;
  9103. name = this.parent.left.alias || this.parent.left.name; // TODO is this right?
  9104. }
  9105. // handle block scoping
  9106. var declaration = this.findScope( false ).findDeclaration( name );
  9107. if ( declaration ) name = declaration.name;
  9108. var start = firstPropertyStart;
  9109. var end = this.end;
  9110. if ( isSimpleAssignment ) {
  9111. // ???
  9112. } else {
  9113. name = this.findScope( true ).createIdentifier( '_obj' );
  9114. var statement = this.findNearest( /(?:Statement|Declaration)$/ );
  9115. code.insertLeft( statement.end, ("\n" + i0 + "var " + name + ";") );
  9116. code.insertRight( this.start, ("( " + name + " = ") );
  9117. }
  9118. var len = this.properties.length;
  9119. var lastComputedProp;
  9120. var sawNonComputedProperty = false;
  9121. for ( var i$1 = 0; i$1 < len; i$1 += 1 ) {
  9122. var prop$2 = this$1.properties[i$1];
  9123. if ( prop$2.computed ) {
  9124. lastComputedProp = prop$2;
  9125. var moveStart = i$1 > 0 ? this$1.properties[ i$1 - 1 ].end : start;
  9126. var propId = isSimpleAssignment ? (";\n" + i0 + name) : (", " + name);
  9127. if (moveStart < prop$2.start) {
  9128. code.overwrite( moveStart, prop$2.start, propId );
  9129. } else {
  9130. code.insertRight( prop$2.start, propId );
  9131. }
  9132. var c = prop$2.key.end;
  9133. while ( code.original[c] !== ']' ) c += 1;
  9134. c += 1;
  9135. if ( prop$2.value.start > c ) code.remove( c, prop$2.value.start );
  9136. code.insertLeft( c, ' = ' );
  9137. code.move( moveStart, prop$2.end, end );
  9138. if ( i$1 < len - 1 && ! sawNonComputedProperty ) {
  9139. // remove trailing comma
  9140. c = prop$2.end;
  9141. while ( code.original[c] !== ',' ) c += 1;
  9142. code.remove( prop$2.end, c + 1 );
  9143. }
  9144. if ( prop$2.method && transforms.conciseMethodProperty ) {
  9145. code.insertRight( prop$2.value.start, 'function ' );
  9146. }
  9147. } else {
  9148. sawNonComputedProperty = true;
  9149. }
  9150. }
  9151. // special case
  9152. if ( computedPropertyCount === len ) {
  9153. code.remove( this.properties[ len - 1 ].end, this.end - 1 );
  9154. }
  9155. if ( !isSimpleAssignment ) {
  9156. code.insertLeft( lastComputedProp.end, (", " + name + " )") );
  9157. }
  9158. }
  9159. };
  9160. return ObjectExpression;
  9161. }(Node));
  9162. var Property = (function (Node$$1) {
  9163. function Property () {
  9164. Node$$1.apply(this, arguments);
  9165. }
  9166. if ( Node$$1 ) Property.__proto__ = Node$$1;
  9167. Property.prototype = Object.create( Node$$1 && Node$$1.prototype );
  9168. Property.prototype.constructor = Property;
  9169. Property.prototype.transpile = function transpile ( code, transforms ) {
  9170. if ( transforms.conciseMethodProperty && !this.computed && this.parent.type !== 'ObjectPattern' ) {
  9171. if ( this.shorthand ) {
  9172. code.insertRight( this.start, ((this.key.name) + ": " + (this.shouldPrefix() ? '_vm.' : '')) );
  9173. } else if ( this.method ) {
  9174. var name;
  9175. if ( this.key.type === 'Literal' && typeof this.key.value === 'number' ) {
  9176. name = "";
  9177. } else if ( this.key.type === 'Identifier' ) {
  9178. if ( reserved[ this.key.name ] || ! /^[a-z_$][a-z0-9_$]*$/i.test( this.key.name ) ) {
  9179. name = this.findScope( true ).createIdentifier( this.key.name );
  9180. } else {
  9181. name = this.key.name;
  9182. }
  9183. } else {
  9184. name = this.findScope( true ).createIdentifier( this.key.value );
  9185. }
  9186. if ( this.value.generator ) code.remove( this.start, this.key.start );
  9187. code.insertLeft( this.key.end, (": function" + (this.value.generator ? '*' : '') + " " + name) );
  9188. }
  9189. }
  9190. if ( transforms.reservedProperties && reserved[ this.key.name ] ) {
  9191. code.insertRight( this.key.start, "'" );
  9192. code.insertLeft( this.key.end, "'" );
  9193. }
  9194. Node$$1.prototype.transpile.call( this, code, transforms );
  9195. };
  9196. Property.prototype.shouldPrefix = function shouldPrefix () {
  9197. if (
  9198. this.program.inWith > 0 &&
  9199. !hash[this.key.name] &&
  9200. !this.findScope(false).contains(this.key.name)
  9201. ) {
  9202. return true
  9203. }
  9204. return false
  9205. };
  9206. return Property;
  9207. }(Node));
  9208. var ReturnStatement = (function (Node$$1) {
  9209. function ReturnStatement () {
  9210. Node$$1.apply(this, arguments);
  9211. }
  9212. if ( Node$$1 ) ReturnStatement.__proto__ = Node$$1;
  9213. ReturnStatement.prototype = Object.create( Node$$1 && Node$$1.prototype );
  9214. ReturnStatement.prototype.constructor = ReturnStatement;
  9215. ReturnStatement.prototype.initialise = function initialise ( transforms ) {
  9216. this.loop = this.findNearest( loopStatement );
  9217. this.nearestFunction = this.findNearest( /Function/ );
  9218. if ( this.loop && ( !this.nearestFunction || this.loop.depth > this.nearestFunction.depth ) ) {
  9219. this.loop.canReturn = true;
  9220. this.shouldWrap = true;
  9221. }
  9222. if ( this.argument ) this.argument.initialise( transforms );
  9223. };
  9224. ReturnStatement.prototype.transpile = function transpile ( code, transforms ) {
  9225. var shouldWrap = this.shouldWrap && this.loop && this.loop.shouldRewriteAsFunction;
  9226. if ( this.argument ) {
  9227. if ( shouldWrap ) code.insertRight( this.argument.start, "{ v: " );
  9228. this.argument.transpile( code, transforms );
  9229. if ( shouldWrap ) code.insertLeft( this.argument.end, " }" );
  9230. } else if ( shouldWrap ) {
  9231. code.insertLeft( this.start + 6, ' {}' );
  9232. }
  9233. };
  9234. return ReturnStatement;
  9235. }(Node));
  9236. var SpreadProperty = (function (Node$$1) {
  9237. function SpreadProperty () {
  9238. Node$$1.apply(this, arguments);
  9239. }
  9240. if ( Node$$1 ) SpreadProperty.__proto__ = Node$$1;
  9241. SpreadProperty.prototype = Object.create( Node$$1 && Node$$1.prototype );
  9242. SpreadProperty.prototype.constructor = SpreadProperty;
  9243. SpreadProperty.prototype.transpile = function transpile ( code, transforms ) {
  9244. code.remove( this.start, this.argument.start );
  9245. code.remove( this.argument.end, this.end );
  9246. Node$$1.prototype.transpile.call( this, code, transforms );
  9247. };
  9248. return SpreadProperty;
  9249. }(Node));
  9250. var Super = (function (Node$$1) {
  9251. function Super () {
  9252. Node$$1.apply(this, arguments);
  9253. }
  9254. if ( Node$$1 ) Super.__proto__ = Node$$1;
  9255. Super.prototype = Object.create( Node$$1 && Node$$1.prototype );
  9256. Super.prototype.constructor = Super;
  9257. Super.prototype.initialise = function initialise ( transforms ) {
  9258. if ( transforms.classes ) {
  9259. this.method = this.findNearest( 'MethodDefinition' );
  9260. if ( !this.method ) throw new CompileError( this, 'use of super outside class method' );
  9261. var parentClass = this.findNearest( 'ClassBody' ).parent;
  9262. this.superClassName = parentClass.superClass && (parentClass.superClass.name || 'superclass');
  9263. if ( !this.superClassName ) throw new CompileError( this, 'super used in base class' );
  9264. this.isCalled = this.parent.type === 'CallExpression' && this === this.parent.callee;
  9265. if ( this.method.kind !== 'constructor' && this.isCalled ) {
  9266. throw new CompileError( this, 'super() not allowed outside class constructor' );
  9267. }
  9268. this.isMember = this.parent.type === 'MemberExpression';
  9269. if ( !this.isCalled && !this.isMember ) {
  9270. throw new CompileError( this, 'Unexpected use of `super` (expected `super(...)` or `super.*`)' );
  9271. }
  9272. }
  9273. if ( transforms.arrow ) {
  9274. var lexicalBoundary = this.findLexicalBoundary();
  9275. var arrowFunction = this.findNearest( 'ArrowFunctionExpression' );
  9276. var loop = this.findNearest( loopStatement );
  9277. if ( arrowFunction && arrowFunction.depth > lexicalBoundary.depth ) {
  9278. this.thisAlias = lexicalBoundary.getThisAlias();
  9279. }
  9280. if ( loop && loop.body.contains( this ) && loop.depth > lexicalBoundary.depth ) {
  9281. this.thisAlias = lexicalBoundary.getThisAlias();
  9282. }
  9283. }
  9284. };
  9285. Super.prototype.transpile = function transpile ( code, transforms ) {
  9286. if ( transforms.classes ) {
  9287. var expression = ( this.isCalled || this.method.static ) ?
  9288. this.superClassName :
  9289. ((this.superClassName) + ".prototype");
  9290. code.overwrite( this.start, this.end, expression, true );
  9291. var callExpression = this.isCalled ? this.parent : this.parent.parent;
  9292. if ( callExpression && callExpression.type === 'CallExpression' ) {
  9293. if ( !this.noCall ) { // special case – `super( ...args )`
  9294. code.insertLeft( callExpression.callee.end, '.call' );
  9295. }
  9296. var thisAlias = this.thisAlias || 'this';
  9297. if ( callExpression.arguments.length ) {
  9298. code.insertLeft( callExpression.arguments[0].start, (thisAlias + ", ") );
  9299. } else {
  9300. code.insertLeft( callExpression.end - 1, ("" + thisAlias) );
  9301. }
  9302. }
  9303. }
  9304. };
  9305. return Super;
  9306. }(Node));
  9307. var TaggedTemplateExpression = (function (Node$$1) {
  9308. function TaggedTemplateExpression () {
  9309. Node$$1.apply(this, arguments);
  9310. }
  9311. if ( Node$$1 ) TaggedTemplateExpression.__proto__ = Node$$1;
  9312. TaggedTemplateExpression.prototype = Object.create( Node$$1 && Node$$1.prototype );
  9313. TaggedTemplateExpression.prototype.constructor = TaggedTemplateExpression;
  9314. TaggedTemplateExpression.prototype.initialise = function initialise ( transforms ) {
  9315. if ( transforms.templateString && !transforms.dangerousTaggedTemplateString ) {
  9316. 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' );
  9317. }
  9318. Node$$1.prototype.initialise.call( this, transforms );
  9319. };
  9320. TaggedTemplateExpression.prototype.transpile = function transpile ( code, transforms ) {
  9321. if ( transforms.templateString && transforms.dangerousTaggedTemplateString ) {
  9322. var ordered = this.quasi.expressions.concat( this.quasi.quasis ).sort( function ( a, b ) { return a.start - b.start; } );
  9323. // insert strings at start
  9324. var templateStrings = this.quasi.quasis.map( function ( quasi ) { return JSON.stringify( quasi.value.cooked ); } );
  9325. code.overwrite( this.tag.end, ordered[0].start, ("([" + (templateStrings.join(', ')) + "]") );
  9326. var lastIndex = ordered[0].start;
  9327. ordered.forEach( function ( node ) {
  9328. if ( node.type === 'TemplateElement' ) {
  9329. code.remove( lastIndex, node.end );
  9330. } else {
  9331. code.overwrite( lastIndex, node.start, ', ' );
  9332. }
  9333. lastIndex = node.end;
  9334. });
  9335. code.overwrite( lastIndex, this.end, ')' );
  9336. }
  9337. Node$$1.prototype.transpile.call( this, code, transforms );
  9338. };
  9339. return TaggedTemplateExpression;
  9340. }(Node));
  9341. var TemplateElement = (function (Node$$1) {
  9342. function TemplateElement () {
  9343. Node$$1.apply(this, arguments);
  9344. }
  9345. if ( Node$$1 ) TemplateElement.__proto__ = Node$$1;
  9346. TemplateElement.prototype = Object.create( Node$$1 && Node$$1.prototype );
  9347. TemplateElement.prototype.constructor = TemplateElement;
  9348. TemplateElement.prototype.initialise = function initialise () {
  9349. this.program.indentExclusionElements.push( this );
  9350. };
  9351. return TemplateElement;
  9352. }(Node));
  9353. var TemplateLiteral = (function (Node$$1) {
  9354. function TemplateLiteral () {
  9355. Node$$1.apply(this, arguments);
  9356. }
  9357. if ( Node$$1 ) TemplateLiteral.__proto__ = Node$$1;
  9358. TemplateLiteral.prototype = Object.create( Node$$1 && Node$$1.prototype );
  9359. TemplateLiteral.prototype.constructor = TemplateLiteral;
  9360. TemplateLiteral.prototype.transpile = function transpile ( code, transforms ) {
  9361. if ( transforms.templateString && this.parent.type !== 'TaggedTemplateExpression' ) {
  9362. var ordered = this.expressions.concat( this.quasis )
  9363. .sort( function ( a, b ) { return a.start - b.start || a.end - b.end; } )
  9364. .filter( function ( node, i ) {
  9365. // include all expressions
  9366. if ( node.type !== 'TemplateElement' ) return true;
  9367. // include all non-empty strings
  9368. if ( node.value.raw ) return true;
  9369. // exclude all empty strings not at the head
  9370. return !i;
  9371. });
  9372. // special case – we may be able to skip the first element,
  9373. // if it's the empty string, but only if the second and
  9374. // third elements aren't both expressions (since they maybe
  9375. // be numeric, and `1 + 2 + '3' === '33'`)
  9376. if ( ordered.length >= 3 ) {
  9377. var first = ordered[0];
  9378. var third = ordered[2];
  9379. if ( first.type === 'TemplateElement' && first.value.raw === '' && third.type === 'TemplateElement' ) {
  9380. ordered.shift();
  9381. }
  9382. }
  9383. var parenthesise = ( this.quasis.length !== 1 || this.expressions.length !== 0 ) &&
  9384. this.parent.type !== 'AssignmentExpression' &&
  9385. this.parent.type !== 'AssignmentPattern' &&
  9386. this.parent.type !== 'VariableDeclarator' &&
  9387. ( this.parent.type !== 'BinaryExpression' || this.parent.operator !== '+' );
  9388. if ( parenthesise ) code.insertRight( this.start, '(' );
  9389. var lastIndex = this.start;
  9390. ordered.forEach( function ( node, i ) {
  9391. if ( node.type === 'TemplateElement' ) {
  9392. var replacement = '';
  9393. if ( i ) replacement += ' + ';
  9394. replacement += JSON.stringify( node.value.cooked );
  9395. code.overwrite( lastIndex, node.end, replacement );
  9396. } else {
  9397. var parenthesise = node.type !== 'Identifier'; // TODO other cases where it's safe
  9398. var replacement$1 = '';
  9399. if ( i ) replacement$1 += ' + ';
  9400. if ( parenthesise ) replacement$1 += '(';
  9401. code.overwrite( lastIndex, node.start, replacement$1 );
  9402. if ( parenthesise ) code.insertLeft( node.end, ')' );
  9403. }
  9404. lastIndex = node.end;
  9405. });
  9406. var close = '';
  9407. if ( parenthesise ) close += ')';
  9408. code.overwrite( lastIndex, this.end, close );
  9409. }
  9410. Node$$1.prototype.transpile.call( this, code, transforms );
  9411. };
  9412. return TemplateLiteral;
  9413. }(Node));
  9414. var ThisExpression = (function (Node$$1) {
  9415. function ThisExpression () {
  9416. Node$$1.apply(this, arguments);
  9417. }
  9418. if ( Node$$1 ) ThisExpression.__proto__ = Node$$1;
  9419. ThisExpression.prototype = Object.create( Node$$1 && Node$$1.prototype );
  9420. ThisExpression.prototype.constructor = ThisExpression;
  9421. ThisExpression.prototype.initialise = function initialise ( transforms ) {
  9422. if ( transforms.arrow ) {
  9423. var lexicalBoundary = this.findLexicalBoundary();
  9424. var arrowFunction = this.findNearest( 'ArrowFunctionExpression' );
  9425. var loop = this.findNearest( loopStatement );
  9426. if ( ( arrowFunction && arrowFunction.depth > lexicalBoundary.depth )
  9427. || ( loop && loop.body.contains( this ) && loop.depth > lexicalBoundary.depth )
  9428. || ( loop && loop.right && loop.right.contains( this ) ) ) {
  9429. this.alias = lexicalBoundary.getThisAlias();
  9430. }
  9431. }
  9432. };
  9433. ThisExpression.prototype.transpile = function transpile ( code ) {
  9434. if ( this.alias ) {
  9435. code.overwrite( this.start, this.end, this.alias, true );
  9436. }
  9437. };
  9438. return ThisExpression;
  9439. }(Node));
  9440. var UpdateExpression = (function (Node$$1) {
  9441. function UpdateExpression () {
  9442. Node$$1.apply(this, arguments);
  9443. }
  9444. if ( Node$$1 ) UpdateExpression.__proto__ = Node$$1;
  9445. UpdateExpression.prototype = Object.create( Node$$1 && Node$$1.prototype );
  9446. UpdateExpression.prototype.constructor = UpdateExpression;
  9447. UpdateExpression.prototype.initialise = function initialise ( transforms ) {
  9448. if ( this.argument.type === 'Identifier' ) {
  9449. var declaration = this.findScope( false ).findDeclaration( this.argument.name );
  9450. if ( declaration && declaration.kind === 'const' ) {
  9451. throw new CompileError( this, ((this.argument.name) + " is read-only") );
  9452. }
  9453. // special case – https://gitlab.com/Rich-Harris/buble/issues/150
  9454. var statement = declaration && declaration.node.ancestor( 3 );
  9455. if ( statement && statement.type === 'ForStatement' && statement.body.contains( this ) ) {
  9456. statement.reassigned[ this.argument.name ] = true;
  9457. }
  9458. }
  9459. Node$$1.prototype.initialise.call( this, transforms );
  9460. };
  9461. return UpdateExpression;
  9462. }(Node));
  9463. var VariableDeclaration = (function (Node$$1) {
  9464. function VariableDeclaration () {
  9465. Node$$1.apply(this, arguments);
  9466. }
  9467. if ( Node$$1 ) VariableDeclaration.__proto__ = Node$$1;
  9468. VariableDeclaration.prototype = Object.create( Node$$1 && Node$$1.prototype );
  9469. VariableDeclaration.prototype.constructor = VariableDeclaration;
  9470. VariableDeclaration.prototype.initialise = function initialise ( transforms ) {
  9471. this.scope = this.findScope( this.kind === 'var' );
  9472. this.declarations.forEach( function ( declarator ) { return declarator.initialise( transforms ); } );
  9473. };
  9474. VariableDeclaration.prototype.transpile = function transpile ( code, transforms ) {
  9475. var this$1 = this;
  9476. var i0 = this.getIndentation();
  9477. var kind = this.kind;
  9478. if ( transforms.letConst && kind !== 'var' ) {
  9479. kind = 'var';
  9480. code.overwrite( this.start, this.start + this.kind.length, kind, true );
  9481. }
  9482. if ( transforms.destructuring && this.parent.type !== 'ForOfStatement' ) {
  9483. var c = this.start;
  9484. var lastDeclaratorIsPattern;
  9485. this.declarations.forEach( function ( declarator, i ) {
  9486. if ( declarator.id.type === 'Identifier' ) {
  9487. if ( i > 0 && this$1.declarations[ i - 1 ].id.type !== 'Identifier' ) {
  9488. code.overwrite( c, declarator.id.start, "var " );
  9489. }
  9490. } else {
  9491. var inline = loopStatement.test( this$1.parent.type );
  9492. if ( i === 0 ) {
  9493. code.remove( c, declarator.id.start );
  9494. } else {
  9495. code.overwrite( c, declarator.id.start, (";\n" + i0) );
  9496. }
  9497. var simple = declarator.init.type === 'Identifier' && !declarator.init.rewritten;
  9498. var name = simple ? declarator.init.name : declarator.findScope( true ).createIdentifier( 'ref' );
  9499. var c$1 = declarator.start;
  9500. var statementGenerators = [];
  9501. if ( simple ) {
  9502. code.remove( declarator.id.end, declarator.end );
  9503. } else {
  9504. statementGenerators.push( function ( start, prefix, suffix ) {
  9505. code.insertRight( declarator.id.end, ("var " + name) );
  9506. code.insertLeft( declarator.init.end, ("" + suffix) );
  9507. code.move( declarator.id.end, declarator.end, start );
  9508. });
  9509. }
  9510. destructure( code, declarator.findScope( false ), declarator.id, name, inline, statementGenerators );
  9511. var prefix = inline ? 'var ' : '';
  9512. var suffix = inline ? ", " : (";\n" + i0);
  9513. statementGenerators.forEach( function ( fn, j ) {
  9514. if ( i === this$1.declarations.length - 1 && j === statementGenerators.length - 1 ) {
  9515. suffix = inline ? '' : ';';
  9516. }
  9517. fn( declarator.start, j === 0 ? prefix : '', suffix );
  9518. });
  9519. }
  9520. declarator.transpile( code, transforms );
  9521. c = declarator.end;
  9522. lastDeclaratorIsPattern = declarator.id.type !== 'Identifier';
  9523. });
  9524. if ( lastDeclaratorIsPattern ) {
  9525. code.remove( c, this.end );
  9526. }
  9527. }
  9528. else {
  9529. this.declarations.forEach( function ( declarator ) {
  9530. declarator.transpile( code, transforms );
  9531. });
  9532. }
  9533. };
  9534. return VariableDeclaration;
  9535. }(Node));
  9536. var VariableDeclarator = (function (Node$$1) {
  9537. function VariableDeclarator () {
  9538. Node$$1.apply(this, arguments);
  9539. }
  9540. if ( Node$$1 ) VariableDeclarator.__proto__ = Node$$1;
  9541. VariableDeclarator.prototype = Object.create( Node$$1 && Node$$1.prototype );
  9542. VariableDeclarator.prototype.constructor = VariableDeclarator;
  9543. VariableDeclarator.prototype.initialise = function initialise ( transforms ) {
  9544. var kind = this.parent.kind;
  9545. if ( kind === 'let' && this.parent.parent.type === 'ForStatement' ) {
  9546. kind = 'for.let'; // special case...
  9547. }
  9548. this.parent.scope.addDeclaration( this.id, kind );
  9549. Node$$1.prototype.initialise.call( this, transforms );
  9550. };
  9551. VariableDeclarator.prototype.transpile = function transpile ( code, transforms ) {
  9552. if ( !this.init && transforms.letConst && this.parent.kind !== 'var' ) {
  9553. var inLoop = this.findNearest( /Function|^For(In|Of)?Statement|^(?:Do)?WhileStatement/ );
  9554. if ( inLoop && ! /Function/.test( inLoop.type ) && ! this.isLeftDeclaratorOfLoop() ) {
  9555. code.insertLeft( this.id.end, ' = (void 0)' );
  9556. }
  9557. }
  9558. if ( this.id ) this.id.transpile( code, transforms );
  9559. if ( this.init ) this.init.transpile( code, transforms );
  9560. };
  9561. VariableDeclarator.prototype.isLeftDeclaratorOfLoop = function isLeftDeclaratorOfLoop () {
  9562. return this.parent
  9563. && this.parent.type === 'VariableDeclaration'
  9564. && this.parent.parent
  9565. && (this.parent.parent.type === 'ForInStatement'
  9566. || this.parent.parent.type === 'ForOfStatement')
  9567. && this.parent.parent.left
  9568. && this.parent.parent.left.declarations[0] === this;
  9569. };
  9570. return VariableDeclarator;
  9571. }(Node));
  9572. var WithStatement = (function (Node$$1) {
  9573. function WithStatement () {
  9574. Node$$1.apply(this, arguments);
  9575. }
  9576. if ( Node$$1 ) WithStatement.__proto__ = Node$$1;
  9577. WithStatement.prototype = Object.create( Node$$1 && Node$$1.prototype );
  9578. WithStatement.prototype.constructor = WithStatement;
  9579. WithStatement.prototype.transpile = function transpile (code, transforms) {
  9580. if (transforms.stripWith) {
  9581. this.program.inWith = (this.program.inWith || 0) + 1;
  9582. // remove surrounding with block
  9583. code.remove(this.start, this.body.start + 1);
  9584. code.remove(this.end - 1, this.end);
  9585. code.insertRight(this.start, "var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;");
  9586. Node$$1.prototype.transpile.call(this, code, transforms);
  9587. this.program.inWith--;
  9588. } else {
  9589. Node$$1.prototype.transpile.call(this, code, transforms);
  9590. }
  9591. };
  9592. return WithStatement;
  9593. }(Node));
  9594. var types = {
  9595. ArrayExpression: ArrayExpression,
  9596. ArrowFunctionExpression: ArrowFunctionExpression,
  9597. AssignmentExpression: AssignmentExpression,
  9598. BinaryExpression: BinaryExpression,
  9599. BreakStatement: BreakStatement,
  9600. CallExpression: CallExpression,
  9601. ClassBody: ClassBody,
  9602. ClassDeclaration: ClassDeclaration,
  9603. ClassExpression: ClassExpression,
  9604. ContinueStatement: ContinueStatement,
  9605. DoWhileStatement: LoopStatement,
  9606. ExportNamedDeclaration: ExportNamedDeclaration,
  9607. ExportDefaultDeclaration: ExportDefaultDeclaration,
  9608. ForStatement: ForStatement,
  9609. ForInStatement: ForInStatement,
  9610. ForOfStatement: ForOfStatement,
  9611. FunctionDeclaration: FunctionDeclaration,
  9612. FunctionExpression: FunctionExpression,
  9613. Identifier: Identifier$1,
  9614. IfStatement: IfStatement,
  9615. ImportDeclaration: ImportDeclaration,
  9616. ImportDefaultSpecifier: ImportDefaultSpecifier,
  9617. ImportSpecifier: ImportSpecifier,
  9618. JSXAttribute: JSXAttribute,
  9619. JSXClosingElement: JSXClosingElement,
  9620. JSXElement: JSXElement,
  9621. JSXExpressionContainer: JSXExpressionContainer,
  9622. JSXOpeningElement: JSXOpeningElement,
  9623. JSXSpreadAttribute: JSXSpreadAttribute,
  9624. Literal: Literal,
  9625. MemberExpression: MemberExpression,
  9626. NewExpression: NewExpression,
  9627. ObjectExpression: ObjectExpression,
  9628. Property: Property,
  9629. ReturnStatement: ReturnStatement,
  9630. SpreadProperty: SpreadProperty,
  9631. Super: Super,
  9632. TaggedTemplateExpression: TaggedTemplateExpression,
  9633. TemplateElement: TemplateElement,
  9634. TemplateLiteral: TemplateLiteral,
  9635. ThisExpression: ThisExpression,
  9636. UpdateExpression: UpdateExpression,
  9637. VariableDeclaration: VariableDeclaration,
  9638. VariableDeclarator: VariableDeclarator,
  9639. WhileStatement: LoopStatement,
  9640. WithStatement: WithStatement
  9641. };
  9642. var statementsWithBlocks = {
  9643. IfStatement: 'consequent',
  9644. ForStatement: 'body',
  9645. ForInStatement: 'body',
  9646. ForOfStatement: 'body',
  9647. WhileStatement: 'body',
  9648. DoWhileStatement: 'body',
  9649. ArrowFunctionExpression: 'body'
  9650. };
  9651. function wrap ( raw, parent ) {
  9652. if ( !raw ) return;
  9653. if ( 'length' in raw ) {
  9654. var i = raw.length;
  9655. while ( i-- ) wrap( raw[i], parent );
  9656. return;
  9657. }
  9658. // with e.g. shorthand properties, key and value are
  9659. // the same node. We don't want to wrap an object twice
  9660. if ( raw.__wrapped ) return;
  9661. raw.__wrapped = true;
  9662. if ( !keys[ raw.type ] ) {
  9663. keys[ raw.type ] = Object.keys( raw ).filter( function ( key ) { return typeof raw[ key ] === 'object'; } );
  9664. }
  9665. // special case – body-less if/for/while statements. TODO others?
  9666. var bodyType = statementsWithBlocks[ raw.type ];
  9667. if ( bodyType && raw[ bodyType ].type !== 'BlockStatement' ) {
  9668. var expression = raw[ bodyType ];
  9669. // create a synthetic block statement, otherwise all hell
  9670. // breaks loose when it comes to block scoping
  9671. raw[ bodyType ] = {
  9672. start: expression.start,
  9673. end: expression.end,
  9674. type: 'BlockStatement',
  9675. body: [ expression ],
  9676. synthetic: true
  9677. };
  9678. }
  9679. new Node( raw, parent );
  9680. var type = ( raw.type === 'BlockStatement' ? BlockStatement : types[ raw.type ] ) || Node;
  9681. raw.__proto__ = type.prototype;
  9682. }
  9683. var letConst = /^(?:let|const)$/;
  9684. function Scope ( options ) {
  9685. options = options || {};
  9686. this.parent = options.parent;
  9687. this.isBlockScope = !!options.block;
  9688. var scope = this;
  9689. while ( scope.isBlockScope ) scope = scope.parent;
  9690. this.functionScope = scope;
  9691. this.identifiers = [];
  9692. this.declarations = Object.create( null );
  9693. this.references = Object.create( null );
  9694. this.blockScopedDeclarations = this.isBlockScope ? null : Object.create( null );
  9695. this.aliases = this.isBlockScope ? null : Object.create( null );
  9696. }
  9697. Scope.prototype = {
  9698. addDeclaration: function addDeclaration ( node, kind ) {
  9699. for ( var i = 0, list = extractNames( node ); i < list.length; i += 1 ) {
  9700. var identifier = list[i];
  9701. var name = identifier.name;
  9702. var existingDeclaration = this.declarations[ name ];
  9703. if ( existingDeclaration && ( letConst.test( kind ) || letConst.test( existingDeclaration.kind ) ) ) {
  9704. // TODO warn about double var declarations?
  9705. throw new CompileError( identifier, (name + " is already declared") );
  9706. }
  9707. var declaration = { name: name, node: identifier, kind: kind, instances: [] };
  9708. this.declarations[ name ] = declaration;
  9709. if ( this.isBlockScope ) {
  9710. if ( !this.functionScope.blockScopedDeclarations[ name ] ) this.functionScope.blockScopedDeclarations[ name ] = [];
  9711. this.functionScope.blockScopedDeclarations[ name ].push( declaration );
  9712. }
  9713. }
  9714. },
  9715. addReference: function addReference ( identifier ) {
  9716. if ( this.consolidated ) {
  9717. this.consolidateReference( identifier );
  9718. } else {
  9719. this.identifiers.push( identifier );
  9720. }
  9721. },
  9722. consolidate: function consolidate () {
  9723. var this$1 = this;
  9724. for ( var i = 0; i < this$1.identifiers.length; i += 1 ) { // we might push to the array during consolidation, so don't cache length
  9725. var identifier = this$1.identifiers[i];
  9726. this$1.consolidateReference( identifier );
  9727. }
  9728. this.consolidated = true; // TODO understand why this is necessary... seems bad
  9729. },
  9730. consolidateReference: function consolidateReference ( identifier ) {
  9731. var declaration = this.declarations[ identifier.name ];
  9732. if ( declaration ) {
  9733. declaration.instances.push( identifier );
  9734. } else {
  9735. this.references[ identifier.name ] = true;
  9736. if ( this.parent ) this.parent.addReference( identifier );
  9737. }
  9738. },
  9739. contains: function contains ( name ) {
  9740. return this.declarations[ name ] ||
  9741. ( this.parent ? this.parent.contains( name ) : false );
  9742. },
  9743. createIdentifier: function createIdentifier ( base ) {
  9744. var this$1 = this;
  9745. if ( typeof base === 'number' ) base = base.toString();
  9746. base = base
  9747. .replace( /\s/g, '' )
  9748. .replace( /\[([^\]]+)\]/g, '_$1' )
  9749. .replace( /[^a-zA-Z0-9_$]/g, '_' )
  9750. .replace( /_{2,}/, '_' );
  9751. var name = base;
  9752. var counter = 1;
  9753. while ( this$1.declarations[ name ] || this$1.references[ name ] || this$1.aliases[ name ] || name in reserved ) {
  9754. name = base + "$" + (counter++);
  9755. }
  9756. this.aliases[ name ] = true;
  9757. return name;
  9758. },
  9759. findDeclaration: function findDeclaration ( name ) {
  9760. return this.declarations[ name ] ||
  9761. ( this.parent && this.parent.findDeclaration( name ) );
  9762. }
  9763. };
  9764. function isUseStrict ( node ) {
  9765. if ( !node ) return false;
  9766. if ( node.type !== 'ExpressionStatement' ) return false;
  9767. if ( node.expression.type !== 'Literal' ) return false;
  9768. return node.expression.value === 'use strict';
  9769. }
  9770. var BlockStatement = (function (Node$$1) {
  9771. function BlockStatement () {
  9772. Node$$1.apply(this, arguments);
  9773. }
  9774. if ( Node$$1 ) BlockStatement.__proto__ = Node$$1;
  9775. BlockStatement.prototype = Object.create( Node$$1 && Node$$1.prototype );
  9776. BlockStatement.prototype.constructor = BlockStatement;
  9777. BlockStatement.prototype.createScope = function createScope () {
  9778. var this$1 = this;
  9779. this.parentIsFunction = /Function/.test( this.parent.type );
  9780. this.isFunctionBlock = this.parentIsFunction || this.parent.type === 'Root';
  9781. this.scope = new Scope({
  9782. block: !this.isFunctionBlock,
  9783. parent: this.parent.findScope( false )
  9784. });
  9785. if ( this.parentIsFunction ) {
  9786. this.parent.params.forEach( function ( node ) {
  9787. this$1.scope.addDeclaration( node, 'param' );
  9788. });
  9789. }
  9790. };
  9791. BlockStatement.prototype.initialise = function initialise ( transforms ) {
  9792. this.thisAlias = null;
  9793. this.argumentsAlias = null;
  9794. this.defaultParameters = [];
  9795. // normally the scope gets created here, during initialisation,
  9796. // but in some cases (e.g. `for` statements), we need to create
  9797. // the scope early, as it pertains to both the init block and
  9798. // the body of the statement
  9799. if ( !this.scope ) this.createScope();
  9800. this.body.forEach( function ( node ) { return node.initialise( transforms ); } );
  9801. this.scope.consolidate();
  9802. };
  9803. BlockStatement.prototype.findLexicalBoundary = function findLexicalBoundary () {
  9804. if ( this.type === 'Program' ) return this;
  9805. if ( /^Function/.test( this.parent.type ) ) return this;
  9806. return this.parent.findLexicalBoundary();
  9807. };
  9808. BlockStatement.prototype.findScope = function findScope ( functionScope ) {
  9809. if ( functionScope && !this.isFunctionBlock ) return this.parent.findScope( functionScope );
  9810. return this.scope;
  9811. };
  9812. BlockStatement.prototype.getArgumentsAlias = function getArgumentsAlias () {
  9813. if ( !this.argumentsAlias ) {
  9814. this.argumentsAlias = this.scope.createIdentifier( 'arguments' );
  9815. }
  9816. return this.argumentsAlias;
  9817. };
  9818. BlockStatement.prototype.getArgumentsArrayAlias = function getArgumentsArrayAlias () {
  9819. if ( !this.argumentsArrayAlias ) {
  9820. this.argumentsArrayAlias = this.scope.createIdentifier( 'argsArray' );
  9821. }
  9822. return this.argumentsArrayAlias;
  9823. };
  9824. BlockStatement.prototype.getThisAlias = function getThisAlias () {
  9825. if ( !this.thisAlias ) {
  9826. this.thisAlias = this.scope.createIdentifier( 'this' );
  9827. }
  9828. return this.thisAlias;
  9829. };
  9830. BlockStatement.prototype.getIndentation = function getIndentation () {
  9831. var this$1 = this;
  9832. if ( this.indentation === undefined ) {
  9833. var source = this.program.magicString.original;
  9834. var useOuter = this.synthetic || !this.body.length;
  9835. var c = useOuter ? this.start : this.body[0].start;
  9836. while ( c && source[c] !== '\n' ) c -= 1;
  9837. this.indentation = '';
  9838. while ( true ) { // eslint-disable-line no-constant-condition
  9839. c += 1;
  9840. var char = source[c];
  9841. if ( char !== ' ' && char !== '\t' ) break;
  9842. this$1.indentation += char;
  9843. }
  9844. var indentString = this.program.magicString.getIndentString();
  9845. // account for dedented class constructors
  9846. var parent = this.parent;
  9847. while ( parent ) {
  9848. if ( parent.kind === 'constructor' && !parent.parent.parent.superClass ) {
  9849. this$1.indentation = this$1.indentation.replace( indentString, '' );
  9850. }
  9851. parent = parent.parent;
  9852. }
  9853. if ( useOuter ) this.indentation += indentString;
  9854. }
  9855. return this.indentation;
  9856. };
  9857. BlockStatement.prototype.transpile = function transpile ( code, transforms ) {
  9858. var this$1 = this;
  9859. var indentation = this.getIndentation();
  9860. var introStatementGenerators = [];
  9861. if ( this.argumentsAlias ) {
  9862. introStatementGenerators.push( function ( start, prefix, suffix ) {
  9863. var assignment = prefix + "var " + (this$1.argumentsAlias) + " = arguments" + suffix;
  9864. code.insertLeft( start, assignment );
  9865. });
  9866. }
  9867. if ( this.thisAlias ) {
  9868. introStatementGenerators.push( function ( start, prefix, suffix ) {
  9869. var assignment = prefix + "var " + (this$1.thisAlias) + " = this" + suffix;
  9870. code.insertLeft( start, assignment );
  9871. });
  9872. }
  9873. if ( this.argumentsArrayAlias ) {
  9874. introStatementGenerators.push( function ( start, prefix, suffix ) {
  9875. var i = this$1.scope.createIdentifier( 'i' );
  9876. var assignment = prefix + "var " + i + " = arguments.length, " + (this$1.argumentsArrayAlias) + " = Array(" + i + ");\n" + indentation + "while ( " + i + "-- ) " + (this$1.argumentsArrayAlias) + "[" + i + "] = arguments[" + i + "]" + suffix;
  9877. code.insertLeft( start, assignment );
  9878. });
  9879. }
  9880. if ( /Function/.test( this.parent.type ) ) {
  9881. this.transpileParameters( code, transforms, indentation, introStatementGenerators );
  9882. }
  9883. if ( transforms.letConst && this.isFunctionBlock ) {
  9884. this.transpileBlockScopedIdentifiers( code );
  9885. }
  9886. Node$$1.prototype.transpile.call( this, code, transforms );
  9887. if ( this.synthetic ) {
  9888. if ( this.parent.type === 'ArrowFunctionExpression' ) {
  9889. var expr = this.body[0];
  9890. if ( introStatementGenerators.length ) {
  9891. code.insertLeft( this.start, "{" ).insertRight( this.end, ((this.parent.getIndentation()) + "}") );
  9892. code.insertRight( expr.start, ("\n" + indentation + "return ") );
  9893. code.insertLeft( expr.end, ";\n" );
  9894. } else if ( transforms.arrow ) {
  9895. code.insertLeft( expr.start, "{ return " );
  9896. code.insertLeft( expr.end, "; }" );
  9897. }
  9898. }
  9899. else if ( introStatementGenerators.length ) {
  9900. code.insertLeft( this.start, "{" ).insertRight( this.end, "}" );
  9901. }
  9902. }
  9903. var start;
  9904. if ( isUseStrict( this.body[0] ) ) {
  9905. start = this.body[0].end;
  9906. } else if ( this.synthetic || this.parent.type === 'Root' ) {
  9907. start = this.start;
  9908. } else {
  9909. start = this.start + 1;
  9910. }
  9911. var prefix = "\n" + indentation;
  9912. var suffix = ';';
  9913. introStatementGenerators.forEach( function ( fn, i ) {
  9914. if ( i === introStatementGenerators.length - 1 ) suffix = ";\n";
  9915. fn( start, prefix, suffix );
  9916. });
  9917. };
  9918. BlockStatement.prototype.transpileParameters = function transpileParameters ( code, transforms, indentation, introStatementGenerators ) {
  9919. var this$1 = this;
  9920. var params = this.parent.params;
  9921. params.forEach( function ( param ) {
  9922. if ( param.type === 'AssignmentPattern' && param.left.type === 'Identifier' ) {
  9923. if ( transforms.defaultParameter ) {
  9924. introStatementGenerators.push( function ( start, prefix, suffix ) {
  9925. var lhs = prefix + "if ( " + (param.left.name) + " === void 0 ) " + (param.left.name);
  9926. code
  9927. .insertRight( param.left.end, lhs )
  9928. .move( param.left.end, param.right.end, start )
  9929. .insertLeft( param.right.end, suffix );
  9930. });
  9931. }
  9932. }
  9933. else if ( param.type === 'RestElement' ) {
  9934. if ( transforms.spreadRest ) {
  9935. introStatementGenerators.push( function ( start, prefix, suffix ) {
  9936. var penultimateParam = params[ params.length - 2 ];
  9937. if ( penultimateParam ) {
  9938. code.remove( penultimateParam ? penultimateParam.end : param.start, param.end );
  9939. } else {
  9940. var start$1 = param.start, end = param.end; // TODO https://gitlab.com/Rich-Harris/buble/issues/8
  9941. while ( /\s/.test( code.original[ start$1 - 1 ] ) ) start$1 -= 1;
  9942. while ( /\s/.test( code.original[ end ] ) ) end += 1;
  9943. code.remove( start$1, end );
  9944. }
  9945. var name = param.argument.name;
  9946. var len = this$1.scope.createIdentifier( 'len' );
  9947. var count = params.length - 1;
  9948. if ( count ) {
  9949. code.insertLeft( start, (prefix + "var " + name + " = [], " + len + " = arguments.length - " + count + ";\n" + indentation + "while ( " + len + "-- > 0 ) " + name + "[ " + len + " ] = arguments[ " + len + " + " + count + " ]" + suffix) );
  9950. } else {
  9951. code.insertLeft( start, (prefix + "var " + name + " = [], " + len + " = arguments.length;\n" + indentation + "while ( " + len + "-- ) " + name + "[ " + len + " ] = arguments[ " + len + " ]" + suffix) );
  9952. }
  9953. });
  9954. }
  9955. }
  9956. else if ( param.type !== 'Identifier' ) {
  9957. if ( transforms.parameterDestructuring ) {
  9958. var ref = this$1.scope.createIdentifier( 'ref' );
  9959. destructure( code, this$1.scope, param, ref, false, introStatementGenerators );
  9960. code.insertLeft( param.start, ref );
  9961. }
  9962. }
  9963. });
  9964. };
  9965. BlockStatement.prototype.transpileBlockScopedIdentifiers = function transpileBlockScopedIdentifiers ( code ) {
  9966. var this$1 = this;
  9967. Object.keys( this.scope.blockScopedDeclarations ).forEach( function ( name ) {
  9968. var declarations = this$1.scope.blockScopedDeclarations[ name ];
  9969. for ( var i = 0, list = declarations; i < list.length; i += 1 ) {
  9970. var declaration = list[i];
  9971. var cont = false; // TODO implement proper continue...
  9972. if ( declaration.kind === 'for.let' ) {
  9973. // special case
  9974. var forStatement = declaration.node.findNearest( 'ForStatement' );
  9975. if ( forStatement.shouldRewriteAsFunction ) {
  9976. var outerAlias = this$1.scope.createIdentifier( name );
  9977. var innerAlias = forStatement.reassigned[ name ] ?
  9978. this$1.scope.createIdentifier( name ) :
  9979. name;
  9980. declaration.name = outerAlias;
  9981. code.overwrite( declaration.node.start, declaration.node.end, outerAlias, true );
  9982. forStatement.aliases[ name ] = {
  9983. outer: outerAlias,
  9984. inner: innerAlias
  9985. };
  9986. for ( var i$1 = 0, list$1 = declaration.instances; i$1 < list$1.length; i$1 += 1 ) {
  9987. var identifier = list$1[i$1];
  9988. var alias = forStatement.body.contains( identifier ) ?
  9989. innerAlias :
  9990. outerAlias;
  9991. if ( name !== alias ) {
  9992. code.overwrite( identifier.start, identifier.end, alias, true );
  9993. }
  9994. }
  9995. cont = true;
  9996. }
  9997. }
  9998. if ( !cont ) {
  9999. var alias$1 = this$1.scope.createIdentifier( name );
  10000. if ( name !== alias$1 ) {
  10001. declaration.name = alias$1;
  10002. code.overwrite( declaration.node.start, declaration.node.end, alias$1, true );
  10003. for ( var i$2 = 0, list$2 = declaration.instances; i$2 < list$2.length; i$2 += 1 ) {
  10004. var identifier$1 = list$2[i$2];
  10005. identifier$1.rewritten = true;
  10006. code.overwrite( identifier$1.start, identifier$1.end, alias$1, true );
  10007. }
  10008. }
  10009. }
  10010. }
  10011. });
  10012. };
  10013. return BlockStatement;
  10014. }(Node));
  10015. function Program ( source, ast, transforms, options ) {
  10016. var this$1 = this;
  10017. this.type = 'Root';
  10018. // options
  10019. this.jsx = options.jsx || 'React.createElement';
  10020. this.options = options;
  10021. this.source = source;
  10022. this.magicString = new MagicString( source );
  10023. this.ast = ast;
  10024. this.depth = 0;
  10025. wrap( this.body = ast, this );
  10026. this.body.__proto__ = BlockStatement.prototype;
  10027. this.indentExclusionElements = [];
  10028. this.body.initialise( transforms );
  10029. this.indentExclusions = Object.create( null );
  10030. for ( var i$1 = 0, list = this.indentExclusionElements; i$1 < list.length; i$1 += 1 ) {
  10031. var node = list[i$1];
  10032. for ( var i = node.start; i < node.end; i += 1 ) {
  10033. this$1.indentExclusions[ i ] = true;
  10034. }
  10035. }
  10036. this.body.transpile( this.magicString, transforms );
  10037. }
  10038. Program.prototype = {
  10039. export: function export$1 ( options ) {
  10040. if ( options === void 0 ) options = {};
  10041. return {
  10042. code: this.magicString.toString(),
  10043. map: this.magicString.generateMap({
  10044. file: options.file,
  10045. source: options.source,
  10046. includeContent: options.includeContent !== false
  10047. })
  10048. };
  10049. },
  10050. findNearest: function findNearest () {
  10051. return null;
  10052. },
  10053. findScope: function findScope () {
  10054. return null;
  10055. }
  10056. };
  10057. var matrix = {
  10058. chrome: {
  10059. 48: 1333689725,
  10060. 49: 1342078975,
  10061. 50: 1610514431,
  10062. 51: 1610514431,
  10063. 52: 2147385343
  10064. },
  10065. firefox: {
  10066. 43: 1207307741,
  10067. 44: 1207307741,
  10068. 45: 1207307741,
  10069. 46: 1476267485,
  10070. 47: 1476296671,
  10071. 48: 1476296671
  10072. },
  10073. safari: {
  10074. 8: 1073741824,
  10075. 9: 1328940894
  10076. },
  10077. ie: {
  10078. 8: 0,
  10079. 9: 1073741824,
  10080. 10: 1073741824,
  10081. 11: 1073770592
  10082. },
  10083. edge: {
  10084. 12: 1591620701,
  10085. 13: 1608400479
  10086. },
  10087. node: {
  10088. '0.10': 1075052608,
  10089. '0.12': 1091830852,
  10090. 4: 1327398527,
  10091. 5: 1327398527,
  10092. 6: 1610514431
  10093. }
  10094. };
  10095. var features = [
  10096. 'arrow',
  10097. 'classes',
  10098. 'collections',
  10099. 'computedProperty',
  10100. 'conciseMethodProperty',
  10101. 'constLoop',
  10102. 'constRedef',
  10103. 'defaultParameter',
  10104. 'destructuring',
  10105. 'extendNatives',
  10106. 'forOf',
  10107. 'generator',
  10108. 'letConst',
  10109. 'letLoop',
  10110. 'letLoopScope',
  10111. 'moduleExport',
  10112. 'moduleImport',
  10113. 'numericLiteral',
  10114. 'objectProto',
  10115. 'objectSuper',
  10116. 'oldOctalLiteral',
  10117. 'parameterDestructuring',
  10118. 'spreadRest',
  10119. 'stickyRegExp',
  10120. 'symbol',
  10121. 'templateString',
  10122. 'unicodeEscape',
  10123. 'unicodeIdentifier',
  10124. 'unicodeRegExp',
  10125. // ES2016
  10126. 'exponentiation',
  10127. // additional transforms, not from
  10128. // https://featuretests.io
  10129. 'reservedProperties'
  10130. ];
  10131. var version = "0.15.1";
  10132. var ref = [
  10133. acornObjectSpread,
  10134. acornJsx
  10135. ].reduce( function ( final, plugin ) { return plugin( final ); }, acorn$1 );
  10136. var parse = ref.parse;
  10137. var dangerousTransforms = [
  10138. 'dangerousTaggedTemplateString',
  10139. 'dangerousForOf'
  10140. ];
  10141. function target ( target ) {
  10142. var targets = Object.keys( target );
  10143. var bitmask = targets.length ?
  10144. 2147483647 :
  10145. 1073741824;
  10146. Object.keys( target ).forEach( function ( environment ) {
  10147. var versions = matrix[ environment ];
  10148. if ( !versions ) throw new Error( ("Unknown environment '" + environment + "'. Please raise an issue at https://gitlab.com/Rich-Harris/buble/issues") );
  10149. var targetVersion = target[ environment ];
  10150. 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") );
  10151. var support = versions[ targetVersion ];
  10152. bitmask &= support;
  10153. });
  10154. var transforms = Object.create( null );
  10155. features.forEach( function ( name, i ) {
  10156. transforms[ name ] = !( bitmask & 1 << i );
  10157. });
  10158. dangerousTransforms.forEach( function ( name ) {
  10159. transforms[ name ] = false;
  10160. });
  10161. transforms.stripWith = false;
  10162. return transforms;
  10163. }
  10164. function transform ( source, options ) {
  10165. if ( options === void 0 ) options = {};
  10166. var transforms = target( options.target || {} );
  10167. Object.keys( options.transforms || {} ).forEach( function ( name ) {
  10168. if ( name === 'modules' ) {
  10169. if ( !( 'moduleImport' in options.transforms ) ) transforms.moduleImport = options.transforms.modules;
  10170. if ( !( 'moduleExport' in options.transforms ) ) transforms.moduleExport = options.transforms.modules;
  10171. return;
  10172. }
  10173. if ( !( name in transforms ) ) throw new Error( ("Unknown transform '" + name + "'") );
  10174. transforms[ name ] = options.transforms[ name ];
  10175. });
  10176. if (transforms.stripWith) {
  10177. // necessary for { key } to be prefixed properly
  10178. // in case the user uses a target environment that supports this
  10179. transforms.conciseMethodProperty = true;
  10180. }
  10181. var ast;
  10182. try {
  10183. ast = parse( source, {
  10184. ecmaVersion: 7,
  10185. preserveParens: true,
  10186. sourceType: 'script',
  10187. plugins: {
  10188. jsx: true,
  10189. objectSpread: true
  10190. }
  10191. });
  10192. } catch ( err ) {
  10193. err.snippet = getSnippet( source, err.loc );
  10194. err.toString = function () { return ((err.name) + ": " + (err.message) + "\n" + (err.snippet)); };
  10195. throw err;
  10196. }
  10197. return new Program( source, ast, transforms, options ).export( options );
  10198. }
  10199. exports.target = target;
  10200. exports.transform = transform;
  10201. exports.VERSION = version;
  10202. Object.defineProperty(exports, '__esModule', { value: true });
  10203. })));