JSXTransformer.js 482 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924
  1. /**
  2. * JSXTransformer v0.13.1
  3. */
  4. (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.JSXTransformer = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){
  5. /**
  6. * Copyright 2013-2015, Facebook, Inc.
  7. * All rights reserved.
  8. *
  9. * This source code is licensed under the BSD-style license found in the
  10. * LICENSE file in the root directory of this source tree. An additional grant
  11. * of patent rights can be found in the PATENTS file in the same directory.
  12. */
  13. /* jshint browser: true */
  14. /* jslint evil: true */
  15. /*eslint-disable no-eval */
  16. /*eslint-disable block-scoped-var */
  17. 'use strict';
  18. var ReactTools = _dereq_('../main');
  19. var inlineSourceMap = _dereq_('./inline-source-map');
  20. var headEl;
  21. var dummyAnchor;
  22. var inlineScriptCount = 0;
  23. // The source-map library relies on Object.defineProperty, but IE8 doesn't
  24. // support it fully even with es5-sham. Indeed, es5-sham's defineProperty
  25. // throws when Object.prototype.__defineGetter__ is missing, so we skip building
  26. // the source map in that case.
  27. var supportsAccessors = Object.prototype.hasOwnProperty('__defineGetter__');
  28. /**
  29. * Run provided code through jstransform.
  30. *
  31. * @param {string} source Original source code
  32. * @param {object?} options Options to pass to jstransform
  33. * @return {object} object as returned from jstransform
  34. */
  35. function transformReact(source, options) {
  36. options = options || {};
  37. // Force the sourcemaps option manually. We don't want to use it if it will
  38. // break (see above note about supportsAccessors). We'll only override the
  39. // value here if sourceMap was specified and is truthy. This guarantees that
  40. // we won't override any user intent (since this method is exposed publicly).
  41. if (options.sourceMap) {
  42. options.sourceMap = supportsAccessors;
  43. }
  44. // Otherwise just pass all options straight through to react-tools.
  45. return ReactTools.transformWithDetails(source, options);
  46. }
  47. /**
  48. * Eval provided source after transforming it.
  49. *
  50. * @param {string} source Original source code
  51. * @param {object?} options Options to pass to jstransform
  52. */
  53. function exec(source, options) {
  54. return eval(transformReact(source, options).code);
  55. }
  56. /**
  57. * This method returns a nicely formated line of code pointing to the exact
  58. * location of the error `e`. The line is limited in size so big lines of code
  59. * are also shown in a readable way.
  60. *
  61. * Example:
  62. * ... x', overflow:'scroll'}} id={} onScroll={this.scroll} class=" ...
  63. * ^
  64. *
  65. * @param {string} code The full string of code
  66. * @param {Error} e The error being thrown
  67. * @return {string} formatted message
  68. * @internal
  69. */
  70. function createSourceCodeErrorMessage(code, e) {
  71. var sourceLines = code.split('\n');
  72. // e.lineNumber is non-standard so we can't depend on its availability. If
  73. // we're in a browser where it isn't supported, don't even bother trying to
  74. // format anything. We may also hit a case where the line number is reported
  75. // incorrectly and is outside the bounds of the actual code. Handle that too.
  76. if (!e.lineNumber || e.lineNumber > sourceLines.length) {
  77. return '';
  78. }
  79. var erroneousLine = sourceLines[e.lineNumber - 1];
  80. // Removes any leading indenting spaces and gets the number of
  81. // chars indenting the `erroneousLine`
  82. var indentation = 0;
  83. erroneousLine = erroneousLine.replace(/^\s+/, function(leadingSpaces) {
  84. indentation = leadingSpaces.length;
  85. return '';
  86. });
  87. // Defines the number of characters that are going to show
  88. // before and after the erroneous code
  89. var LIMIT = 30;
  90. var errorColumn = e.column - indentation;
  91. if (errorColumn > LIMIT) {
  92. erroneousLine = '... ' + erroneousLine.slice(errorColumn - LIMIT);
  93. errorColumn = 4 + LIMIT;
  94. }
  95. if (erroneousLine.length - errorColumn > LIMIT) {
  96. erroneousLine = erroneousLine.slice(0, errorColumn + LIMIT) + ' ...';
  97. }
  98. var message = '\n\n' + erroneousLine + '\n';
  99. message += new Array(errorColumn - 1).join(' ') + '^';
  100. return message;
  101. }
  102. /**
  103. * Actually transform the code.
  104. *
  105. * @param {string} code
  106. * @param {string?} url
  107. * @param {object?} options
  108. * @return {string} The transformed code.
  109. * @internal
  110. */
  111. function transformCode(code, url, options) {
  112. try {
  113. var transformed = transformReact(code, options);
  114. } catch(e) {
  115. e.message += '\n at ';
  116. if (url) {
  117. if ('fileName' in e) {
  118. // We set `fileName` if it's supported by this error object and
  119. // a `url` was provided.
  120. // The error will correctly point to `url` in Firefox.
  121. e.fileName = url;
  122. }
  123. e.message += url + ':' + e.lineNumber + ':' + e.columnNumber;
  124. } else {
  125. e.message += location.href;
  126. }
  127. e.message += createSourceCodeErrorMessage(code, e);
  128. throw e;
  129. }
  130. if (!transformed.sourceMap) {
  131. return transformed.code;
  132. }
  133. var source;
  134. if (url == null) {
  135. source = 'Inline JSX script';
  136. inlineScriptCount++;
  137. if (inlineScriptCount > 1) {
  138. source += ' (' + inlineScriptCount + ')';
  139. }
  140. } else if (dummyAnchor) {
  141. // Firefox has problems when the sourcemap source is a proper URL with a
  142. // protocol and hostname, so use the pathname. We could use just the
  143. // filename, but hopefully using the full path will prevent potential
  144. // issues where the same filename exists in multiple directories.
  145. dummyAnchor.href = url;
  146. source = dummyAnchor.pathname.substr(1);
  147. }
  148. return (
  149. transformed.code +
  150. '\n' +
  151. inlineSourceMap(transformed.sourceMap, code, source)
  152. );
  153. }
  154. /**
  155. * Appends a script element at the end of the <head> with the content of code,
  156. * after transforming it.
  157. *
  158. * @param {string} code The original source code
  159. * @param {string?} url Where the code came from. null if inline
  160. * @param {object?} options Options to pass to jstransform
  161. * @internal
  162. */
  163. function run(code, url, options) {
  164. var scriptEl = document.createElement('script');
  165. scriptEl.text = transformCode(code, url, options);
  166. headEl.appendChild(scriptEl);
  167. }
  168. /**
  169. * Load script from the provided url and pass the content to the callback.
  170. *
  171. * @param {string} url The location of the script src
  172. * @param {function} callback Function to call with the content of url
  173. * @internal
  174. */
  175. function load(url, successCallback, errorCallback) {
  176. var xhr;
  177. xhr = window.ActiveXObject ? new window.ActiveXObject('Microsoft.XMLHTTP')
  178. : new XMLHttpRequest();
  179. // async, however scripts will be executed in the order they are in the
  180. // DOM to mirror normal script loading.
  181. xhr.open('GET', url, true);
  182. if ('overrideMimeType' in xhr) {
  183. xhr.overrideMimeType('text/plain');
  184. }
  185. xhr.onreadystatechange = function() {
  186. if (xhr.readyState === 4) {
  187. if (xhr.status === 0 || xhr.status === 200) {
  188. successCallback(xhr.responseText);
  189. } else {
  190. errorCallback();
  191. throw new Error('Could not load ' + url);
  192. }
  193. }
  194. };
  195. return xhr.send(null);
  196. }
  197. /**
  198. * Loop over provided script tags and get the content, via innerHTML if an
  199. * inline script, or by using XHR. Transforms are applied if needed. The scripts
  200. * are executed in the order they are found on the page.
  201. *
  202. * @param {array} scripts The <script> elements to load and run.
  203. * @internal
  204. */
  205. function loadScripts(scripts) {
  206. var result = [];
  207. var count = scripts.length;
  208. function check() {
  209. var script, i;
  210. for (i = 0; i < count; i++) {
  211. script = result[i];
  212. if (script.loaded && !script.executed) {
  213. script.executed = true;
  214. run(script.content, script.url, script.options);
  215. } else if (!script.loaded && !script.error && !script.async) {
  216. break;
  217. }
  218. }
  219. }
  220. scripts.forEach(function(script, i) {
  221. var options = {
  222. sourceMap: true
  223. };
  224. if (/;harmony=true(;|$)/.test(script.type)) {
  225. options.harmony = true;
  226. }
  227. if (/;stripTypes=true(;|$)/.test(script.type)) {
  228. options.stripTypes = true;
  229. }
  230. // script.async is always true for non-javascript script tags
  231. var async = script.hasAttribute('async');
  232. if (script.src) {
  233. result[i] = {
  234. async: async,
  235. error: false,
  236. executed: false,
  237. content: null,
  238. loaded: false,
  239. url: script.src,
  240. options: options
  241. };
  242. load(script.src, function(content) {
  243. result[i].loaded = true;
  244. result[i].content = content;
  245. check();
  246. }, function() {
  247. result[i].error = true;
  248. check();
  249. });
  250. } else {
  251. result[i] = {
  252. async: async,
  253. error: false,
  254. executed: false,
  255. content: script.innerHTML,
  256. loaded: true,
  257. url: null,
  258. options: options
  259. };
  260. }
  261. });
  262. check();
  263. }
  264. /**
  265. * Find and run all script tags with type="text/jsx".
  266. *
  267. * @internal
  268. */
  269. function runScripts() {
  270. var scripts = document.getElementsByTagName('script');
  271. // Array.prototype.slice cannot be used on NodeList on IE8
  272. var jsxScripts = [];
  273. for (var i = 0; i < scripts.length; i++) {
  274. if (/^text\/jsx(;|$)/.test(scripts.item(i).type)) {
  275. jsxScripts.push(scripts.item(i));
  276. }
  277. }
  278. if (jsxScripts.length < 1) {
  279. return;
  280. }
  281. console.warn(
  282. 'You are using the in-browser JSX transformer. Be sure to precompile ' +
  283. 'your JSX for production - ' +
  284. 'http://facebook.github.io/react/docs/tooling-integration.html#jsx'
  285. );
  286. loadScripts(jsxScripts);
  287. }
  288. // Listen for load event if we're in a browser and then kick off finding and
  289. // running of scripts.
  290. if (typeof window !== 'undefined' && window !== null) {
  291. headEl = document.getElementsByTagName('head')[0];
  292. dummyAnchor = document.createElement('a');
  293. if (window.addEventListener) {
  294. window.addEventListener('DOMContentLoaded', runScripts, false);
  295. } else {
  296. window.attachEvent('onload', runScripts);
  297. }
  298. }
  299. module.exports = {
  300. transform: transformReact,
  301. exec: exec
  302. };
  303. },{"../main":2,"./inline-source-map":41}],2:[function(_dereq_,module,exports){
  304. /**
  305. * Copyright 2013-2015, Facebook, Inc.
  306. * All rights reserved.
  307. *
  308. * This source code is licensed under the BSD-style license found in the
  309. * LICENSE file in the root directory of this source tree. An additional grant
  310. * of patent rights can be found in the PATENTS file in the same directory.
  311. */
  312. 'use strict';
  313. /*eslint-disable no-undef*/
  314. var visitors = _dereq_('./vendor/fbtransform/visitors');
  315. var transform = _dereq_('jstransform').transform;
  316. var typesSyntax = _dereq_('jstransform/visitors/type-syntax');
  317. var inlineSourceMap = _dereq_('./vendor/inline-source-map');
  318. module.exports = {
  319. transform: function(input, options) {
  320. options = processOptions(options);
  321. var output = innerTransform(input, options);
  322. var result = output.code;
  323. if (options.sourceMap) {
  324. var map = inlineSourceMap(
  325. output.sourceMap,
  326. input,
  327. options.filename
  328. );
  329. result += '\n' + map;
  330. }
  331. return result;
  332. },
  333. transformWithDetails: function(input, options) {
  334. options = processOptions(options);
  335. var output = innerTransform(input, options);
  336. var result = {};
  337. result.code = output.code;
  338. if (options.sourceMap) {
  339. result.sourceMap = output.sourceMap.toJSON();
  340. }
  341. if (options.filename) {
  342. result.sourceMap.sources = [options.filename];
  343. }
  344. return result;
  345. }
  346. };
  347. /**
  348. * Only copy the values that we need. We'll do some preprocessing to account for
  349. * converting command line flags to options that jstransform can actually use.
  350. */
  351. function processOptions(opts) {
  352. opts = opts || {};
  353. var options = {};
  354. options.harmony = opts.harmony;
  355. options.stripTypes = opts.stripTypes;
  356. options.sourceMap = opts.sourceMap;
  357. options.filename = opts.sourceFilename;
  358. if (opts.es6module) {
  359. options.sourceType = 'module';
  360. }
  361. if (opts.nonStrictEs6module) {
  362. options.sourceType = 'nonStrictModule';
  363. }
  364. // Instead of doing any fancy validation, only look for 'es3'. If we have
  365. // that, then use it. Otherwise use 'es5'.
  366. options.es3 = opts.target === 'es3';
  367. options.es5 = !options.es3;
  368. return options;
  369. }
  370. function innerTransform(input, options) {
  371. var visitorSets = ['react'];
  372. if (options.harmony) {
  373. visitorSets.push('harmony');
  374. }
  375. if (options.es3) {
  376. visitorSets.push('es3');
  377. }
  378. if (options.stripTypes) {
  379. // Stripping types needs to happen before the other transforms
  380. // unfortunately, due to bad interactions. For example,
  381. // es6-rest-param-visitors conflict with stripping rest param type
  382. // annotation
  383. input = transform(typesSyntax.visitorList, input, options).code;
  384. }
  385. var visitorList = visitors.getVisitorsBySet(visitorSets);
  386. return transform(visitorList, input, options);
  387. }
  388. },{"./vendor/fbtransform/visitors":40,"./vendor/inline-source-map":41,"jstransform":22,"jstransform/visitors/type-syntax":36}],3:[function(_dereq_,module,exports){
  389. /*!
  390. * The buffer module from node.js, for the browser.
  391. *
  392. * @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
  393. * @license MIT
  394. */
  395. var base64 = _dereq_('base64-js')
  396. var ieee754 = _dereq_('ieee754')
  397. var isArray = _dereq_('is-array')
  398. exports.Buffer = Buffer
  399. exports.SlowBuffer = SlowBuffer
  400. exports.INSPECT_MAX_BYTES = 50
  401. Buffer.poolSize = 8192 // not used by this implementation
  402. var kMaxLength = 0x3fffffff
  403. var rootParent = {}
  404. /**
  405. * If `Buffer.TYPED_ARRAY_SUPPORT`:
  406. * === true Use Uint8Array implementation (fastest)
  407. * === false Use Object implementation (most compatible, even IE6)
  408. *
  409. * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
  410. * Opera 11.6+, iOS 4.2+.
  411. *
  412. * Note:
  413. *
  414. * - Implementation must support adding new properties to `Uint8Array` instances.
  415. * Firefox 4-29 lacked support, fixed in Firefox 30+.
  416. * See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438.
  417. *
  418. * - Chrome 9-10 is missing the `TypedArray.prototype.subarray` function.
  419. *
  420. * - IE10 has a broken `TypedArray.prototype.subarray` function which returns arrays of
  421. * incorrect length in some situations.
  422. *
  423. * We detect these buggy browsers and set `Buffer.TYPED_ARRAY_SUPPORT` to `false` so they will
  424. * get the Object implementation, which is slower but will work correctly.
  425. */
  426. Buffer.TYPED_ARRAY_SUPPORT = (function () {
  427. try {
  428. var buf = new ArrayBuffer(0)
  429. var arr = new Uint8Array(buf)
  430. arr.foo = function () { return 42 }
  431. return arr.foo() === 42 && // typed array instances can be augmented
  432. typeof arr.subarray === 'function' && // chrome 9-10 lack `subarray`
  433. new Uint8Array(1).subarray(1, 1).byteLength === 0 // ie10 has broken `subarray`
  434. } catch (e) {
  435. return false
  436. }
  437. })()
  438. /**
  439. * Class: Buffer
  440. * =============
  441. *
  442. * The Buffer constructor returns instances of `Uint8Array` that are augmented
  443. * with function properties for all the node `Buffer` API functions. We use
  444. * `Uint8Array` so that square bracket notation works as expected -- it returns
  445. * a single octet.
  446. *
  447. * By augmenting the instances, we can avoid modifying the `Uint8Array`
  448. * prototype.
  449. */
  450. function Buffer (subject, encoding, noZero) {
  451. if (!(this instanceof Buffer)) return new Buffer(subject, encoding, noZero)
  452. var type = typeof subject
  453. var length
  454. if (type === 'number') {
  455. length = +subject
  456. } else if (type === 'string') {
  457. length = Buffer.byteLength(subject, encoding)
  458. } else if (type === 'object' && subject !== null) {
  459. // assume object is array-like
  460. if (subject.type === 'Buffer' && isArray(subject.data)) subject = subject.data
  461. length = +subject.length
  462. } else {
  463. throw new TypeError('must start with number, buffer, array or string')
  464. }
  465. if (length > kMaxLength) {
  466. throw new RangeError('Attempt to allocate Buffer larger than maximum size: 0x' +
  467. kMaxLength.toString(16) + ' bytes')
  468. }
  469. if (length < 0) length = 0
  470. else length >>>= 0 // coerce to uint32
  471. var self = this
  472. if (Buffer.TYPED_ARRAY_SUPPORT) {
  473. // Preferred: Return an augmented `Uint8Array` instance for best performance
  474. /*eslint-disable consistent-this */
  475. self = Buffer._augment(new Uint8Array(length))
  476. /*eslint-enable consistent-this */
  477. } else {
  478. // Fallback: Return THIS instance of Buffer (created by `new`)
  479. self.length = length
  480. self._isBuffer = true
  481. }
  482. var i
  483. if (Buffer.TYPED_ARRAY_SUPPORT && typeof subject.byteLength === 'number') {
  484. // Speed optimization -- use set if we're copying from a typed array
  485. self._set(subject)
  486. } else if (isArrayish(subject)) {
  487. // Treat array-ish objects as a byte array
  488. if (Buffer.isBuffer(subject)) {
  489. for (i = 0; i < length; i++) {
  490. self[i] = subject.readUInt8(i)
  491. }
  492. } else {
  493. for (i = 0; i < length; i++) {
  494. self[i] = ((subject[i] % 256) + 256) % 256
  495. }
  496. }
  497. } else if (type === 'string') {
  498. self.write(subject, 0, encoding)
  499. } else if (type === 'number' && !Buffer.TYPED_ARRAY_SUPPORT && !noZero) {
  500. for (i = 0; i < length; i++) {
  501. self[i] = 0
  502. }
  503. }
  504. if (length > 0 && length <= Buffer.poolSize) self.parent = rootParent
  505. return self
  506. }
  507. function SlowBuffer (subject, encoding, noZero) {
  508. if (!(this instanceof SlowBuffer)) return new SlowBuffer(subject, encoding, noZero)
  509. var buf = new Buffer(subject, encoding, noZero)
  510. delete buf.parent
  511. return buf
  512. }
  513. Buffer.isBuffer = function isBuffer (b) {
  514. return !!(b != null && b._isBuffer)
  515. }
  516. Buffer.compare = function compare (a, b) {
  517. if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) {
  518. throw new TypeError('Arguments must be Buffers')
  519. }
  520. if (a === b) return 0
  521. var x = a.length
  522. var y = b.length
  523. for (var i = 0, len = Math.min(x, y); i < len && a[i] === b[i]; i++) {}
  524. if (i !== len) {
  525. x = a[i]
  526. y = b[i]
  527. }
  528. if (x < y) return -1
  529. if (y < x) return 1
  530. return 0
  531. }
  532. Buffer.isEncoding = function isEncoding (encoding) {
  533. switch (String(encoding).toLowerCase()) {
  534. case 'hex':
  535. case 'utf8':
  536. case 'utf-8':
  537. case 'ascii':
  538. case 'binary':
  539. case 'base64':
  540. case 'raw':
  541. case 'ucs2':
  542. case 'ucs-2':
  543. case 'utf16le':
  544. case 'utf-16le':
  545. return true
  546. default:
  547. return false
  548. }
  549. }
  550. Buffer.concat = function concat (list, totalLength) {
  551. if (!isArray(list)) throw new TypeError('Usage: Buffer.concat(list[, length])')
  552. if (list.length === 0) {
  553. return new Buffer(0)
  554. } else if (list.length === 1) {
  555. return list[0]
  556. }
  557. var i
  558. if (totalLength === undefined) {
  559. totalLength = 0
  560. for (i = 0; i < list.length; i++) {
  561. totalLength += list[i].length
  562. }
  563. }
  564. var buf = new Buffer(totalLength)
  565. var pos = 0
  566. for (i = 0; i < list.length; i++) {
  567. var item = list[i]
  568. item.copy(buf, pos)
  569. pos += item.length
  570. }
  571. return buf
  572. }
  573. Buffer.byteLength = function byteLength (str, encoding) {
  574. var ret
  575. str = str + ''
  576. switch (encoding || 'utf8') {
  577. case 'ascii':
  578. case 'binary':
  579. case 'raw':
  580. ret = str.length
  581. break
  582. case 'ucs2':
  583. case 'ucs-2':
  584. case 'utf16le':
  585. case 'utf-16le':
  586. ret = str.length * 2
  587. break
  588. case 'hex':
  589. ret = str.length >>> 1
  590. break
  591. case 'utf8':
  592. case 'utf-8':
  593. ret = utf8ToBytes(str).length
  594. break
  595. case 'base64':
  596. ret = base64ToBytes(str).length
  597. break
  598. default:
  599. ret = str.length
  600. }
  601. return ret
  602. }
  603. // pre-set for values that may exist in the future
  604. Buffer.prototype.length = undefined
  605. Buffer.prototype.parent = undefined
  606. // toString(encoding, start=0, end=buffer.length)
  607. Buffer.prototype.toString = function toString (encoding, start, end) {
  608. var loweredCase = false
  609. start = start >>> 0
  610. end = end === undefined || end === Infinity ? this.length : end >>> 0
  611. if (!encoding) encoding = 'utf8'
  612. if (start < 0) start = 0
  613. if (end > this.length) end = this.length
  614. if (end <= start) return ''
  615. while (true) {
  616. switch (encoding) {
  617. case 'hex':
  618. return hexSlice(this, start, end)
  619. case 'utf8':
  620. case 'utf-8':
  621. return utf8Slice(this, start, end)
  622. case 'ascii':
  623. return asciiSlice(this, start, end)
  624. case 'binary':
  625. return binarySlice(this, start, end)
  626. case 'base64':
  627. return base64Slice(this, start, end)
  628. case 'ucs2':
  629. case 'ucs-2':
  630. case 'utf16le':
  631. case 'utf-16le':
  632. return utf16leSlice(this, start, end)
  633. default:
  634. if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
  635. encoding = (encoding + '').toLowerCase()
  636. loweredCase = true
  637. }
  638. }
  639. }
  640. Buffer.prototype.equals = function equals (b) {
  641. if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer')
  642. if (this === b) return true
  643. return Buffer.compare(this, b) === 0
  644. }
  645. Buffer.prototype.inspect = function inspect () {
  646. var str = ''
  647. var max = exports.INSPECT_MAX_BYTES
  648. if (this.length > 0) {
  649. str = this.toString('hex', 0, max).match(/.{2}/g).join(' ')
  650. if (this.length > max) str += ' ... '
  651. }
  652. return '<Buffer ' + str + '>'
  653. }
  654. Buffer.prototype.compare = function compare (b) {
  655. if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer')
  656. if (this === b) return 0
  657. return Buffer.compare(this, b)
  658. }
  659. Buffer.prototype.indexOf = function indexOf (val, byteOffset) {
  660. if (byteOffset > 0x7fffffff) byteOffset = 0x7fffffff
  661. else if (byteOffset < -0x80000000) byteOffset = -0x80000000
  662. byteOffset >>= 0
  663. if (this.length === 0) return -1
  664. if (byteOffset >= this.length) return -1
  665. // Negative offsets start from the end of the buffer
  666. if (byteOffset < 0) byteOffset = Math.max(this.length + byteOffset, 0)
  667. if (typeof val === 'string') {
  668. if (val.length === 0) return -1 // special case: looking for empty string always fails
  669. return String.prototype.indexOf.call(this, val, byteOffset)
  670. }
  671. if (Buffer.isBuffer(val)) {
  672. return arrayIndexOf(this, val, byteOffset)
  673. }
  674. if (typeof val === 'number') {
  675. if (Buffer.TYPED_ARRAY_SUPPORT && Uint8Array.prototype.indexOf === 'function') {
  676. return Uint8Array.prototype.indexOf.call(this, val, byteOffset)
  677. }
  678. return arrayIndexOf(this, [ val ], byteOffset)
  679. }
  680. function arrayIndexOf (arr, val, byteOffset) {
  681. var foundIndex = -1
  682. for (var i = 0; byteOffset + i < arr.length; i++) {
  683. if (arr[byteOffset + i] === val[foundIndex === -1 ? 0 : i - foundIndex]) {
  684. if (foundIndex === -1) foundIndex = i
  685. if (i - foundIndex + 1 === val.length) return byteOffset + foundIndex
  686. } else {
  687. foundIndex = -1
  688. }
  689. }
  690. return -1
  691. }
  692. throw new TypeError('val must be string, number or Buffer')
  693. }
  694. // `get` will be removed in Node 0.13+
  695. Buffer.prototype.get = function get (offset) {
  696. console.log('.get() is deprecated. Access using array indexes instead.')
  697. return this.readUInt8(offset)
  698. }
  699. // `set` will be removed in Node 0.13+
  700. Buffer.prototype.set = function set (v, offset) {
  701. console.log('.set() is deprecated. Access using array indexes instead.')
  702. return this.writeUInt8(v, offset)
  703. }
  704. function hexWrite (buf, string, offset, length) {
  705. offset = Number(offset) || 0
  706. var remaining = buf.length - offset
  707. if (!length) {
  708. length = remaining
  709. } else {
  710. length = Number(length)
  711. if (length > remaining) {
  712. length = remaining
  713. }
  714. }
  715. // must be an even number of digits
  716. var strLen = string.length
  717. if (strLen % 2 !== 0) throw new Error('Invalid hex string')
  718. if (length > strLen / 2) {
  719. length = strLen / 2
  720. }
  721. for (var i = 0; i < length; i++) {
  722. var parsed = parseInt(string.substr(i * 2, 2), 16)
  723. if (isNaN(parsed)) throw new Error('Invalid hex string')
  724. buf[offset + i] = parsed
  725. }
  726. return i
  727. }
  728. function utf8Write (buf, string, offset, length) {
  729. var charsWritten = blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length)
  730. return charsWritten
  731. }
  732. function asciiWrite (buf, string, offset, length) {
  733. var charsWritten = blitBuffer(asciiToBytes(string), buf, offset, length)
  734. return charsWritten
  735. }
  736. function binaryWrite (buf, string, offset, length) {
  737. return asciiWrite(buf, string, offset, length)
  738. }
  739. function base64Write (buf, string, offset, length) {
  740. var charsWritten = blitBuffer(base64ToBytes(string), buf, offset, length)
  741. return charsWritten
  742. }
  743. function utf16leWrite (buf, string, offset, length) {
  744. var charsWritten = blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length)
  745. return charsWritten
  746. }
  747. Buffer.prototype.write = function write (string, offset, length, encoding) {
  748. // Support both (string, offset, length, encoding)
  749. // and the legacy (string, encoding, offset, length)
  750. if (isFinite(offset)) {
  751. if (!isFinite(length)) {
  752. encoding = length
  753. length = undefined
  754. }
  755. } else { // legacy
  756. var swap = encoding
  757. encoding = offset
  758. offset = length
  759. length = swap
  760. }
  761. offset = Number(offset) || 0
  762. if (length < 0 || offset < 0 || offset > this.length) {
  763. throw new RangeError('attempt to write outside buffer bounds')
  764. }
  765. var remaining = this.length - offset
  766. if (!length) {
  767. length = remaining
  768. } else {
  769. length = Number(length)
  770. if (length > remaining) {
  771. length = remaining
  772. }
  773. }
  774. encoding = String(encoding || 'utf8').toLowerCase()
  775. var ret
  776. switch (encoding) {
  777. case 'hex':
  778. ret = hexWrite(this, string, offset, length)
  779. break
  780. case 'utf8':
  781. case 'utf-8':
  782. ret = utf8Write(this, string, offset, length)
  783. break
  784. case 'ascii':
  785. ret = asciiWrite(this, string, offset, length)
  786. break
  787. case 'binary':
  788. ret = binaryWrite(this, string, offset, length)
  789. break
  790. case 'base64':
  791. ret = base64Write(this, string, offset, length)
  792. break
  793. case 'ucs2':
  794. case 'ucs-2':
  795. case 'utf16le':
  796. case 'utf-16le':
  797. ret = utf16leWrite(this, string, offset, length)
  798. break
  799. default:
  800. throw new TypeError('Unknown encoding: ' + encoding)
  801. }
  802. return ret
  803. }
  804. Buffer.prototype.toJSON = function toJSON () {
  805. return {
  806. type: 'Buffer',
  807. data: Array.prototype.slice.call(this._arr || this, 0)
  808. }
  809. }
  810. function base64Slice (buf, start, end) {
  811. if (start === 0 && end === buf.length) {
  812. return base64.fromByteArray(buf)
  813. } else {
  814. return base64.fromByteArray(buf.slice(start, end))
  815. }
  816. }
  817. function utf8Slice (buf, start, end) {
  818. var res = ''
  819. var tmp = ''
  820. end = Math.min(buf.length, end)
  821. for (var i = start; i < end; i++) {
  822. if (buf[i] <= 0x7F) {
  823. res += decodeUtf8Char(tmp) + String.fromCharCode(buf[i])
  824. tmp = ''
  825. } else {
  826. tmp += '%' + buf[i].toString(16)
  827. }
  828. }
  829. return res + decodeUtf8Char(tmp)
  830. }
  831. function asciiSlice (buf, start, end) {
  832. var ret = ''
  833. end = Math.min(buf.length, end)
  834. for (var i = start; i < end; i++) {
  835. ret += String.fromCharCode(buf[i] & 0x7F)
  836. }
  837. return ret
  838. }
  839. function binarySlice (buf, start, end) {
  840. var ret = ''
  841. end = Math.min(buf.length, end)
  842. for (var i = start; i < end; i++) {
  843. ret += String.fromCharCode(buf[i])
  844. }
  845. return ret
  846. }
  847. function hexSlice (buf, start, end) {
  848. var len = buf.length
  849. if (!start || start < 0) start = 0
  850. if (!end || end < 0 || end > len) end = len
  851. var out = ''
  852. for (var i = start; i < end; i++) {
  853. out += toHex(buf[i])
  854. }
  855. return out
  856. }
  857. function utf16leSlice (buf, start, end) {
  858. var bytes = buf.slice(start, end)
  859. var res = ''
  860. for (var i = 0; i < bytes.length; i += 2) {
  861. res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256)
  862. }
  863. return res
  864. }
  865. Buffer.prototype.slice = function slice (start, end) {
  866. var len = this.length
  867. start = ~~start
  868. end = end === undefined ? len : ~~end
  869. if (start < 0) {
  870. start += len
  871. if (start < 0) start = 0
  872. } else if (start > len) {
  873. start = len
  874. }
  875. if (end < 0) {
  876. end += len
  877. if (end < 0) end = 0
  878. } else if (end > len) {
  879. end = len
  880. }
  881. if (end < start) end = start
  882. var newBuf
  883. if (Buffer.TYPED_ARRAY_SUPPORT) {
  884. newBuf = Buffer._augment(this.subarray(start, end))
  885. } else {
  886. var sliceLen = end - start
  887. newBuf = new Buffer(sliceLen, undefined, true)
  888. for (var i = 0; i < sliceLen; i++) {
  889. newBuf[i] = this[i + start]
  890. }
  891. }
  892. if (newBuf.length) newBuf.parent = this.parent || this
  893. return newBuf
  894. }
  895. /*
  896. * Need to make sure that buffer isn't trying to write out of bounds.
  897. */
  898. function checkOffset (offset, ext, length) {
  899. if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint')
  900. if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length')
  901. }
  902. Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) {
  903. offset = offset >>> 0
  904. byteLength = byteLength >>> 0
  905. if (!noAssert) checkOffset(offset, byteLength, this.length)
  906. var val = this[offset]
  907. var mul = 1
  908. var i = 0
  909. while (++i < byteLength && (mul *= 0x100)) {
  910. val += this[offset + i] * mul
  911. }
  912. return val
  913. }
  914. Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) {
  915. offset = offset >>> 0
  916. byteLength = byteLength >>> 0
  917. if (!noAssert) {
  918. checkOffset(offset, byteLength, this.length)
  919. }
  920. var val = this[offset + --byteLength]
  921. var mul = 1
  922. while (byteLength > 0 && (mul *= 0x100)) {
  923. val += this[offset + --byteLength] * mul
  924. }
  925. return val
  926. }
  927. Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) {
  928. if (!noAssert) checkOffset(offset, 1, this.length)
  929. return this[offset]
  930. }
  931. Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) {
  932. if (!noAssert) checkOffset(offset, 2, this.length)
  933. return this[offset] | (this[offset + 1] << 8)
  934. }
  935. Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) {
  936. if (!noAssert) checkOffset(offset, 2, this.length)
  937. return (this[offset] << 8) | this[offset + 1]
  938. }
  939. Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) {
  940. if (!noAssert) checkOffset(offset, 4, this.length)
  941. return ((this[offset]) |
  942. (this[offset + 1] << 8) |
  943. (this[offset + 2] << 16)) +
  944. (this[offset + 3] * 0x1000000)
  945. }
  946. Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) {
  947. if (!noAssert) checkOffset(offset, 4, this.length)
  948. return (this[offset] * 0x1000000) +
  949. ((this[offset + 1] << 16) |
  950. (this[offset + 2] << 8) |
  951. this[offset + 3])
  952. }
  953. Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) {
  954. offset = offset >>> 0
  955. byteLength = byteLength >>> 0
  956. if (!noAssert) checkOffset(offset, byteLength, this.length)
  957. var val = this[offset]
  958. var mul = 1
  959. var i = 0
  960. while (++i < byteLength && (mul *= 0x100)) {
  961. val += this[offset + i] * mul
  962. }
  963. mul *= 0x80
  964. if (val >= mul) val -= Math.pow(2, 8 * byteLength)
  965. return val
  966. }
  967. Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) {
  968. offset = offset >>> 0
  969. byteLength = byteLength >>> 0
  970. if (!noAssert) checkOffset(offset, byteLength, this.length)
  971. var i = byteLength
  972. var mul = 1
  973. var val = this[offset + --i]
  974. while (i > 0 && (mul *= 0x100)) {
  975. val += this[offset + --i] * mul
  976. }
  977. mul *= 0x80
  978. if (val >= mul) val -= Math.pow(2, 8 * byteLength)
  979. return val
  980. }
  981. Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) {
  982. if (!noAssert) checkOffset(offset, 1, this.length)
  983. if (!(this[offset] & 0x80)) return (this[offset])
  984. return ((0xff - this[offset] + 1) * -1)
  985. }
  986. Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) {
  987. if (!noAssert) checkOffset(offset, 2, this.length)
  988. var val = this[offset] | (this[offset + 1] << 8)
  989. return (val & 0x8000) ? val | 0xFFFF0000 : val
  990. }
  991. Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) {
  992. if (!noAssert) checkOffset(offset, 2, this.length)
  993. var val = this[offset + 1] | (this[offset] << 8)
  994. return (val & 0x8000) ? val | 0xFFFF0000 : val
  995. }
  996. Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) {
  997. if (!noAssert) checkOffset(offset, 4, this.length)
  998. return (this[offset]) |
  999. (this[offset + 1] << 8) |
  1000. (this[offset + 2] << 16) |
  1001. (this[offset + 3] << 24)
  1002. }
  1003. Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) {
  1004. if (!noAssert) checkOffset(offset, 4, this.length)
  1005. return (this[offset] << 24) |
  1006. (this[offset + 1] << 16) |
  1007. (this[offset + 2] << 8) |
  1008. (this[offset + 3])
  1009. }
  1010. Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) {
  1011. if (!noAssert) checkOffset(offset, 4, this.length)
  1012. return ieee754.read(this, offset, true, 23, 4)
  1013. }
  1014. Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) {
  1015. if (!noAssert) checkOffset(offset, 4, this.length)
  1016. return ieee754.read(this, offset, false, 23, 4)
  1017. }
  1018. Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) {
  1019. if (!noAssert) checkOffset(offset, 8, this.length)
  1020. return ieee754.read(this, offset, true, 52, 8)
  1021. }
  1022. Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) {
  1023. if (!noAssert) checkOffset(offset, 8, this.length)
  1024. return ieee754.read(this, offset, false, 52, 8)
  1025. }
  1026. function checkInt (buf, value, offset, ext, max, min) {
  1027. if (!Buffer.isBuffer(buf)) throw new TypeError('buffer must be a Buffer instance')
  1028. if (value > max || value < min) throw new RangeError('value is out of bounds')
  1029. if (offset + ext > buf.length) throw new RangeError('index out of range')
  1030. }
  1031. Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) {
  1032. value = +value
  1033. offset = offset >>> 0
  1034. byteLength = byteLength >>> 0
  1035. if (!noAssert) checkInt(this, value, offset, byteLength, Math.pow(2, 8 * byteLength), 0)
  1036. var mul = 1
  1037. var i = 0
  1038. this[offset] = value & 0xFF
  1039. while (++i < byteLength && (mul *= 0x100)) {
  1040. this[offset + i] = (value / mul) >>> 0 & 0xFF
  1041. }
  1042. return offset + byteLength
  1043. }
  1044. Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) {
  1045. value = +value
  1046. offset = offset >>> 0
  1047. byteLength = byteLength >>> 0
  1048. if (!noAssert) checkInt(this, value, offset, byteLength, Math.pow(2, 8 * byteLength), 0)
  1049. var i = byteLength - 1
  1050. var mul = 1
  1051. this[offset + i] = value & 0xFF
  1052. while (--i >= 0 && (mul *= 0x100)) {
  1053. this[offset + i] = (value / mul) >>> 0 & 0xFF
  1054. }
  1055. return offset + byteLength
  1056. }
  1057. Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) {
  1058. value = +value
  1059. offset = offset >>> 0
  1060. if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0)
  1061. if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value)
  1062. this[offset] = value
  1063. return offset + 1
  1064. }
  1065. function objectWriteUInt16 (buf, value, offset, littleEndian) {
  1066. if (value < 0) value = 0xffff + value + 1
  1067. for (var i = 0, j = Math.min(buf.length - offset, 2); i < j; i++) {
  1068. buf[offset + i] = (value & (0xff << (8 * (littleEndian ? i : 1 - i)))) >>>
  1069. (littleEndian ? i : 1 - i) * 8
  1070. }
  1071. }
  1072. Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) {
  1073. value = +value
  1074. offset = offset >>> 0
  1075. if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
  1076. if (Buffer.TYPED_ARRAY_SUPPORT) {
  1077. this[offset] = value
  1078. this[offset + 1] = (value >>> 8)
  1079. } else {
  1080. objectWriteUInt16(this, value, offset, true)
  1081. }
  1082. return offset + 2
  1083. }
  1084. Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) {
  1085. value = +value
  1086. offset = offset >>> 0
  1087. if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
  1088. if (Buffer.TYPED_ARRAY_SUPPORT) {
  1089. this[offset] = (value >>> 8)
  1090. this[offset + 1] = value
  1091. } else {
  1092. objectWriteUInt16(this, value, offset, false)
  1093. }
  1094. return offset + 2
  1095. }
  1096. function objectWriteUInt32 (buf, value, offset, littleEndian) {
  1097. if (value < 0) value = 0xffffffff + value + 1
  1098. for (var i = 0, j = Math.min(buf.length - offset, 4); i < j; i++) {
  1099. buf[offset + i] = (value >>> (littleEndian ? i : 3 - i) * 8) & 0xff
  1100. }
  1101. }
  1102. Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) {
  1103. value = +value
  1104. offset = offset >>> 0
  1105. if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
  1106. if (Buffer.TYPED_ARRAY_SUPPORT) {
  1107. this[offset + 3] = (value >>> 24)
  1108. this[offset + 2] = (value >>> 16)
  1109. this[offset + 1] = (value >>> 8)
  1110. this[offset] = value
  1111. } else {
  1112. objectWriteUInt32(this, value, offset, true)
  1113. }
  1114. return offset + 4
  1115. }
  1116. Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) {
  1117. value = +value
  1118. offset = offset >>> 0
  1119. if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
  1120. if (Buffer.TYPED_ARRAY_SUPPORT) {
  1121. this[offset] = (value >>> 24)
  1122. this[offset + 1] = (value >>> 16)
  1123. this[offset + 2] = (value >>> 8)
  1124. this[offset + 3] = value
  1125. } else {
  1126. objectWriteUInt32(this, value, offset, false)
  1127. }
  1128. return offset + 4
  1129. }
  1130. Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) {
  1131. value = +value
  1132. offset = offset >>> 0
  1133. if (!noAssert) {
  1134. checkInt(
  1135. this, value, offset, byteLength,
  1136. Math.pow(2, 8 * byteLength - 1) - 1,
  1137. -Math.pow(2, 8 * byteLength - 1)
  1138. )
  1139. }
  1140. var i = 0
  1141. var mul = 1
  1142. var sub = value < 0 ? 1 : 0
  1143. this[offset] = value & 0xFF
  1144. while (++i < byteLength && (mul *= 0x100)) {
  1145. this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
  1146. }
  1147. return offset + byteLength
  1148. }
  1149. Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) {
  1150. value = +value
  1151. offset = offset >>> 0
  1152. if (!noAssert) {
  1153. checkInt(
  1154. this, value, offset, byteLength,
  1155. Math.pow(2, 8 * byteLength - 1) - 1,
  1156. -Math.pow(2, 8 * byteLength - 1)
  1157. )
  1158. }
  1159. var i = byteLength - 1
  1160. var mul = 1
  1161. var sub = value < 0 ? 1 : 0
  1162. this[offset + i] = value & 0xFF
  1163. while (--i >= 0 && (mul *= 0x100)) {
  1164. this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
  1165. }
  1166. return offset + byteLength
  1167. }
  1168. Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) {
  1169. value = +value
  1170. offset = offset >>> 0
  1171. if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80)
  1172. if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value)
  1173. if (value < 0) value = 0xff + value + 1
  1174. this[offset] = value
  1175. return offset + 1
  1176. }
  1177. Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) {
  1178. value = +value
  1179. offset = offset >>> 0
  1180. if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
  1181. if (Buffer.TYPED_ARRAY_SUPPORT) {
  1182. this[offset] = value
  1183. this[offset + 1] = (value >>> 8)
  1184. } else {
  1185. objectWriteUInt16(this, value, offset, true)
  1186. }
  1187. return offset + 2
  1188. }
  1189. Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) {
  1190. value = +value
  1191. offset = offset >>> 0
  1192. if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
  1193. if (Buffer.TYPED_ARRAY_SUPPORT) {
  1194. this[offset] = (value >>> 8)
  1195. this[offset + 1] = value
  1196. } else {
  1197. objectWriteUInt16(this, value, offset, false)
  1198. }
  1199. return offset + 2
  1200. }
  1201. Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) {
  1202. value = +value
  1203. offset = offset >>> 0
  1204. if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
  1205. if (Buffer.TYPED_ARRAY_SUPPORT) {
  1206. this[offset] = value
  1207. this[offset + 1] = (value >>> 8)
  1208. this[offset + 2] = (value >>> 16)
  1209. this[offset + 3] = (value >>> 24)
  1210. } else {
  1211. objectWriteUInt32(this, value, offset, true)
  1212. }
  1213. return offset + 4
  1214. }
  1215. Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) {
  1216. value = +value
  1217. offset = offset >>> 0
  1218. if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
  1219. if (value < 0) value = 0xffffffff + value + 1
  1220. if (Buffer.TYPED_ARRAY_SUPPORT) {
  1221. this[offset] = (value >>> 24)
  1222. this[offset + 1] = (value >>> 16)
  1223. this[offset + 2] = (value >>> 8)
  1224. this[offset + 3] = value
  1225. } else {
  1226. objectWriteUInt32(this, value, offset, false)
  1227. }
  1228. return offset + 4
  1229. }
  1230. function checkIEEE754 (buf, value, offset, ext, max, min) {
  1231. if (value > max || value < min) throw new RangeError('value is out of bounds')
  1232. if (offset + ext > buf.length) throw new RangeError('index out of range')
  1233. if (offset < 0) throw new RangeError('index out of range')
  1234. }
  1235. function writeFloat (buf, value, offset, littleEndian, noAssert) {
  1236. if (!noAssert) {
  1237. checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38)
  1238. }
  1239. ieee754.write(buf, value, offset, littleEndian, 23, 4)
  1240. return offset + 4
  1241. }
  1242. Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) {
  1243. return writeFloat(this, value, offset, true, noAssert)
  1244. }
  1245. Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) {
  1246. return writeFloat(this, value, offset, false, noAssert)
  1247. }
  1248. function writeDouble (buf, value, offset, littleEndian, noAssert) {
  1249. if (!noAssert) {
  1250. checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308)
  1251. }
  1252. ieee754.write(buf, value, offset, littleEndian, 52, 8)
  1253. return offset + 8
  1254. }
  1255. Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) {
  1256. return writeDouble(this, value, offset, true, noAssert)
  1257. }
  1258. Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) {
  1259. return writeDouble(this, value, offset, false, noAssert)
  1260. }
  1261. // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
  1262. Buffer.prototype.copy = function copy (target, target_start, start, end) {
  1263. var self = this // source
  1264. if (!start) start = 0
  1265. if (!end && end !== 0) end = this.length
  1266. if (target_start >= target.length) target_start = target.length
  1267. if (!target_start) target_start = 0
  1268. if (end > 0 && end < start) end = start
  1269. // Copy 0 bytes; we're done
  1270. if (end === start) return 0
  1271. if (target.length === 0 || self.length === 0) return 0
  1272. // Fatal error conditions
  1273. if (target_start < 0) {
  1274. throw new RangeError('targetStart out of bounds')
  1275. }
  1276. if (start < 0 || start >= self.length) throw new RangeError('sourceStart out of bounds')
  1277. if (end < 0) throw new RangeError('sourceEnd out of bounds')
  1278. // Are we oob?
  1279. if (end > this.length) end = this.length
  1280. if (target.length - target_start < end - start) {
  1281. end = target.length - target_start + start
  1282. }
  1283. var len = end - start
  1284. if (len < 1000 || !Buffer.TYPED_ARRAY_SUPPORT) {
  1285. for (var i = 0; i < len; i++) {
  1286. target[i + target_start] = this[i + start]
  1287. }
  1288. } else {
  1289. target._set(this.subarray(start, start + len), target_start)
  1290. }
  1291. return len
  1292. }
  1293. // fill(value, start=0, end=buffer.length)
  1294. Buffer.prototype.fill = function fill (value, start, end) {
  1295. if (!value) value = 0
  1296. if (!start) start = 0
  1297. if (!end) end = this.length
  1298. if (end < start) throw new RangeError('end < start')
  1299. // Fill 0 bytes; we're done
  1300. if (end === start) return
  1301. if (this.length === 0) return
  1302. if (start < 0 || start >= this.length) throw new RangeError('start out of bounds')
  1303. if (end < 0 || end > this.length) throw new RangeError('end out of bounds')
  1304. var i
  1305. if (typeof value === 'number') {
  1306. for (i = start; i < end; i++) {
  1307. this[i] = value
  1308. }
  1309. } else {
  1310. var bytes = utf8ToBytes(value.toString())
  1311. var len = bytes.length
  1312. for (i = start; i < end; i++) {
  1313. this[i] = bytes[i % len]
  1314. }
  1315. }
  1316. return this
  1317. }
  1318. /**
  1319. * Creates a new `ArrayBuffer` with the *copied* memory of the buffer instance.
  1320. * Added in Node 0.12. Only available in browsers that support ArrayBuffer.
  1321. */
  1322. Buffer.prototype.toArrayBuffer = function toArrayBuffer () {
  1323. if (typeof Uint8Array !== 'undefined') {
  1324. if (Buffer.TYPED_ARRAY_SUPPORT) {
  1325. return (new Buffer(this)).buffer
  1326. } else {
  1327. var buf = new Uint8Array(this.length)
  1328. for (var i = 0, len = buf.length; i < len; i += 1) {
  1329. buf[i] = this[i]
  1330. }
  1331. return buf.buffer
  1332. }
  1333. } else {
  1334. throw new TypeError('Buffer.toArrayBuffer not supported in this browser')
  1335. }
  1336. }
  1337. // HELPER FUNCTIONS
  1338. // ================
  1339. var BP = Buffer.prototype
  1340. /**
  1341. * Augment a Uint8Array *instance* (not the Uint8Array class!) with Buffer methods
  1342. */
  1343. Buffer._augment = function _augment (arr) {
  1344. arr.constructor = Buffer
  1345. arr._isBuffer = true
  1346. // save reference to original Uint8Array get/set methods before overwriting
  1347. arr._get = arr.get
  1348. arr._set = arr.set
  1349. // deprecated, will be removed in node 0.13+
  1350. arr.get = BP.get
  1351. arr.set = BP.set
  1352. arr.write = BP.write
  1353. arr.toString = BP.toString
  1354. arr.toLocaleString = BP.toString
  1355. arr.toJSON = BP.toJSON
  1356. arr.equals = BP.equals
  1357. arr.compare = BP.compare
  1358. arr.indexOf = BP.indexOf
  1359. arr.copy = BP.copy
  1360. arr.slice = BP.slice
  1361. arr.readUIntLE = BP.readUIntLE
  1362. arr.readUIntBE = BP.readUIntBE
  1363. arr.readUInt8 = BP.readUInt8
  1364. arr.readUInt16LE = BP.readUInt16LE
  1365. arr.readUInt16BE = BP.readUInt16BE
  1366. arr.readUInt32LE = BP.readUInt32LE
  1367. arr.readUInt32BE = BP.readUInt32BE
  1368. arr.readIntLE = BP.readIntLE
  1369. arr.readIntBE = BP.readIntBE
  1370. arr.readInt8 = BP.readInt8
  1371. arr.readInt16LE = BP.readInt16LE
  1372. arr.readInt16BE = BP.readInt16BE
  1373. arr.readInt32LE = BP.readInt32LE
  1374. arr.readInt32BE = BP.readInt32BE
  1375. arr.readFloatLE = BP.readFloatLE
  1376. arr.readFloatBE = BP.readFloatBE
  1377. arr.readDoubleLE = BP.readDoubleLE
  1378. arr.readDoubleBE = BP.readDoubleBE
  1379. arr.writeUInt8 = BP.writeUInt8
  1380. arr.writeUIntLE = BP.writeUIntLE
  1381. arr.writeUIntBE = BP.writeUIntBE
  1382. arr.writeUInt16LE = BP.writeUInt16LE
  1383. arr.writeUInt16BE = BP.writeUInt16BE
  1384. arr.writeUInt32LE = BP.writeUInt32LE
  1385. arr.writeUInt32BE = BP.writeUInt32BE
  1386. arr.writeIntLE = BP.writeIntLE
  1387. arr.writeIntBE = BP.writeIntBE
  1388. arr.writeInt8 = BP.writeInt8
  1389. arr.writeInt16LE = BP.writeInt16LE
  1390. arr.writeInt16BE = BP.writeInt16BE
  1391. arr.writeInt32LE = BP.writeInt32LE
  1392. arr.writeInt32BE = BP.writeInt32BE
  1393. arr.writeFloatLE = BP.writeFloatLE
  1394. arr.writeFloatBE = BP.writeFloatBE
  1395. arr.writeDoubleLE = BP.writeDoubleLE
  1396. arr.writeDoubleBE = BP.writeDoubleBE
  1397. arr.fill = BP.fill
  1398. arr.inspect = BP.inspect
  1399. arr.toArrayBuffer = BP.toArrayBuffer
  1400. return arr
  1401. }
  1402. var INVALID_BASE64_RE = /[^+\/0-9A-z\-]/g
  1403. function base64clean (str) {
  1404. // Node strips out invalid characters like \n and \t from the string, base64-js does not
  1405. str = stringtrim(str).replace(INVALID_BASE64_RE, '')
  1406. // Node converts strings with length < 2 to ''
  1407. if (str.length < 2) return ''
  1408. // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
  1409. while (str.length % 4 !== 0) {
  1410. str = str + '='
  1411. }
  1412. return str
  1413. }
  1414. function stringtrim (str) {
  1415. if (str.trim) return str.trim()
  1416. return str.replace(/^\s+|\s+$/g, '')
  1417. }
  1418. function isArrayish (subject) {
  1419. return isArray(subject) || Buffer.isBuffer(subject) ||
  1420. subject && typeof subject === 'object' &&
  1421. typeof subject.length === 'number'
  1422. }
  1423. function toHex (n) {
  1424. if (n < 16) return '0' + n.toString(16)
  1425. return n.toString(16)
  1426. }
  1427. function utf8ToBytes (string, units) {
  1428. units = units || Infinity
  1429. var codePoint
  1430. var length = string.length
  1431. var leadSurrogate = null
  1432. var bytes = []
  1433. var i = 0
  1434. for (; i < length; i++) {
  1435. codePoint = string.charCodeAt(i)
  1436. // is surrogate component
  1437. if (codePoint > 0xD7FF && codePoint < 0xE000) {
  1438. // last char was a lead
  1439. if (leadSurrogate) {
  1440. // 2 leads in a row
  1441. if (codePoint < 0xDC00) {
  1442. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  1443. leadSurrogate = codePoint
  1444. continue
  1445. } else {
  1446. // valid surrogate pair
  1447. codePoint = leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00 | 0x10000
  1448. leadSurrogate = null
  1449. }
  1450. } else {
  1451. // no lead yet
  1452. if (codePoint > 0xDBFF) {
  1453. // unexpected trail
  1454. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  1455. continue
  1456. } else if (i + 1 === length) {
  1457. // unpaired lead
  1458. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  1459. continue
  1460. } else {
  1461. // valid lead
  1462. leadSurrogate = codePoint
  1463. continue
  1464. }
  1465. }
  1466. } else if (leadSurrogate) {
  1467. // valid bmp char, but last char was a lead
  1468. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  1469. leadSurrogate = null
  1470. }
  1471. // encode utf8
  1472. if (codePoint < 0x80) {
  1473. if ((units -= 1) < 0) break
  1474. bytes.push(codePoint)
  1475. } else if (codePoint < 0x800) {
  1476. if ((units -= 2) < 0) break
  1477. bytes.push(
  1478. codePoint >> 0x6 | 0xC0,
  1479. codePoint & 0x3F | 0x80
  1480. )
  1481. } else if (codePoint < 0x10000) {
  1482. if ((units -= 3) < 0) break
  1483. bytes.push(
  1484. codePoint >> 0xC | 0xE0,
  1485. codePoint >> 0x6 & 0x3F | 0x80,
  1486. codePoint & 0x3F | 0x80
  1487. )
  1488. } else if (codePoint < 0x200000) {
  1489. if ((units -= 4) < 0) break
  1490. bytes.push(
  1491. codePoint >> 0x12 | 0xF0,
  1492. codePoint >> 0xC & 0x3F | 0x80,
  1493. codePoint >> 0x6 & 0x3F | 0x80,
  1494. codePoint & 0x3F | 0x80
  1495. )
  1496. } else {
  1497. throw new Error('Invalid code point')
  1498. }
  1499. }
  1500. return bytes
  1501. }
  1502. function asciiToBytes (str) {
  1503. var byteArray = []
  1504. for (var i = 0; i < str.length; i++) {
  1505. // Node's code seems to be doing this and not & 0x7F..
  1506. byteArray.push(str.charCodeAt(i) & 0xFF)
  1507. }
  1508. return byteArray
  1509. }
  1510. function utf16leToBytes (str, units) {
  1511. var c, hi, lo
  1512. var byteArray = []
  1513. for (var i = 0; i < str.length; i++) {
  1514. if ((units -= 2) < 0) break
  1515. c = str.charCodeAt(i)
  1516. hi = c >> 8
  1517. lo = c % 256
  1518. byteArray.push(lo)
  1519. byteArray.push(hi)
  1520. }
  1521. return byteArray
  1522. }
  1523. function base64ToBytes (str) {
  1524. return base64.toByteArray(base64clean(str))
  1525. }
  1526. function blitBuffer (src, dst, offset, length) {
  1527. for (var i = 0; i < length; i++) {
  1528. if ((i + offset >= dst.length) || (i >= src.length)) break
  1529. dst[i + offset] = src[i]
  1530. }
  1531. return i
  1532. }
  1533. function decodeUtf8Char (str) {
  1534. try {
  1535. return decodeURIComponent(str)
  1536. } catch (err) {
  1537. return String.fromCharCode(0xFFFD) // UTF 8 invalid char
  1538. }
  1539. }
  1540. },{"base64-js":4,"ieee754":5,"is-array":6}],4:[function(_dereq_,module,exports){
  1541. var lookup = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
  1542. ;(function (exports) {
  1543. 'use strict';
  1544. var Arr = (typeof Uint8Array !== 'undefined')
  1545. ? Uint8Array
  1546. : Array
  1547. var PLUS = '+'.charCodeAt(0)
  1548. var SLASH = '/'.charCodeAt(0)
  1549. var NUMBER = '0'.charCodeAt(0)
  1550. var LOWER = 'a'.charCodeAt(0)
  1551. var UPPER = 'A'.charCodeAt(0)
  1552. var PLUS_URL_SAFE = '-'.charCodeAt(0)
  1553. var SLASH_URL_SAFE = '_'.charCodeAt(0)
  1554. function decode (elt) {
  1555. var code = elt.charCodeAt(0)
  1556. if (code === PLUS ||
  1557. code === PLUS_URL_SAFE)
  1558. return 62 // '+'
  1559. if (code === SLASH ||
  1560. code === SLASH_URL_SAFE)
  1561. return 63 // '/'
  1562. if (code < NUMBER)
  1563. return -1 //no match
  1564. if (code < NUMBER + 10)
  1565. return code - NUMBER + 26 + 26
  1566. if (code < UPPER + 26)
  1567. return code - UPPER
  1568. if (code < LOWER + 26)
  1569. return code - LOWER + 26
  1570. }
  1571. function b64ToByteArray (b64) {
  1572. var i, j, l, tmp, placeHolders, arr
  1573. if (b64.length % 4 > 0) {
  1574. throw new Error('Invalid string. Length must be a multiple of 4')
  1575. }
  1576. // the number of equal signs (place holders)
  1577. // if there are two placeholders, than the two characters before it
  1578. // represent one byte
  1579. // if there is only one, then the three characters before it represent 2 bytes
  1580. // this is just a cheap hack to not do indexOf twice
  1581. var len = b64.length
  1582. placeHolders = '=' === b64.charAt(len - 2) ? 2 : '=' === b64.charAt(len - 1) ? 1 : 0
  1583. // base64 is 4/3 + up to two characters of the original data
  1584. arr = new Arr(b64.length * 3 / 4 - placeHolders)
  1585. // if there are placeholders, only get up to the last complete 4 chars
  1586. l = placeHolders > 0 ? b64.length - 4 : b64.length
  1587. var L = 0
  1588. function push (v) {
  1589. arr[L++] = v
  1590. }
  1591. for (i = 0, j = 0; i < l; i += 4, j += 3) {
  1592. tmp = (decode(b64.charAt(i)) << 18) | (decode(b64.charAt(i + 1)) << 12) | (decode(b64.charAt(i + 2)) << 6) | decode(b64.charAt(i + 3))
  1593. push((tmp & 0xFF0000) >> 16)
  1594. push((tmp & 0xFF00) >> 8)
  1595. push(tmp & 0xFF)
  1596. }
  1597. if (placeHolders === 2) {
  1598. tmp = (decode(b64.charAt(i)) << 2) | (decode(b64.charAt(i + 1)) >> 4)
  1599. push(tmp & 0xFF)
  1600. } else if (placeHolders === 1) {
  1601. tmp = (decode(b64.charAt(i)) << 10) | (decode(b64.charAt(i + 1)) << 4) | (decode(b64.charAt(i + 2)) >> 2)
  1602. push((tmp >> 8) & 0xFF)
  1603. push(tmp & 0xFF)
  1604. }
  1605. return arr
  1606. }
  1607. function uint8ToBase64 (uint8) {
  1608. var i,
  1609. extraBytes = uint8.length % 3, // if we have 1 byte left, pad 2 bytes
  1610. output = "",
  1611. temp, length
  1612. function encode (num) {
  1613. return lookup.charAt(num)
  1614. }
  1615. function tripletToBase64 (num) {
  1616. return encode(num >> 18 & 0x3F) + encode(num >> 12 & 0x3F) + encode(num >> 6 & 0x3F) + encode(num & 0x3F)
  1617. }
  1618. // go through the array every three bytes, we'll deal with trailing stuff later
  1619. for (i = 0, length = uint8.length - extraBytes; i < length; i += 3) {
  1620. temp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2])
  1621. output += tripletToBase64(temp)
  1622. }
  1623. // pad the end with zeros, but make sure to not forget the extra bytes
  1624. switch (extraBytes) {
  1625. case 1:
  1626. temp = uint8[uint8.length - 1]
  1627. output += encode(temp >> 2)
  1628. output += encode((temp << 4) & 0x3F)
  1629. output += '=='
  1630. break
  1631. case 2:
  1632. temp = (uint8[uint8.length - 2] << 8) + (uint8[uint8.length - 1])
  1633. output += encode(temp >> 10)
  1634. output += encode((temp >> 4) & 0x3F)
  1635. output += encode((temp << 2) & 0x3F)
  1636. output += '='
  1637. break
  1638. }
  1639. return output
  1640. }
  1641. exports.toByteArray = b64ToByteArray
  1642. exports.fromByteArray = uint8ToBase64
  1643. }(typeof exports === 'undefined' ? (this.base64js = {}) : exports))
  1644. },{}],5:[function(_dereq_,module,exports){
  1645. exports.read = function(buffer, offset, isLE, mLen, nBytes) {
  1646. var e, m,
  1647. eLen = nBytes * 8 - mLen - 1,
  1648. eMax = (1 << eLen) - 1,
  1649. eBias = eMax >> 1,
  1650. nBits = -7,
  1651. i = isLE ? (nBytes - 1) : 0,
  1652. d = isLE ? -1 : 1,
  1653. s = buffer[offset + i];
  1654. i += d;
  1655. e = s & ((1 << (-nBits)) - 1);
  1656. s >>= (-nBits);
  1657. nBits += eLen;
  1658. for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8);
  1659. m = e & ((1 << (-nBits)) - 1);
  1660. e >>= (-nBits);
  1661. nBits += mLen;
  1662. for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8);
  1663. if (e === 0) {
  1664. e = 1 - eBias;
  1665. } else if (e === eMax) {
  1666. return m ? NaN : ((s ? -1 : 1) * Infinity);
  1667. } else {
  1668. m = m + Math.pow(2, mLen);
  1669. e = e - eBias;
  1670. }
  1671. return (s ? -1 : 1) * m * Math.pow(2, e - mLen);
  1672. };
  1673. exports.write = function(buffer, value, offset, isLE, mLen, nBytes) {
  1674. var e, m, c,
  1675. eLen = nBytes * 8 - mLen - 1,
  1676. eMax = (1 << eLen) - 1,
  1677. eBias = eMax >> 1,
  1678. rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0),
  1679. i = isLE ? 0 : (nBytes - 1),
  1680. d = isLE ? 1 : -1,
  1681. s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0;
  1682. value = Math.abs(value);
  1683. if (isNaN(value) || value === Infinity) {
  1684. m = isNaN(value) ? 1 : 0;
  1685. e = eMax;
  1686. } else {
  1687. e = Math.floor(Math.log(value) / Math.LN2);
  1688. if (value * (c = Math.pow(2, -e)) < 1) {
  1689. e--;
  1690. c *= 2;
  1691. }
  1692. if (e + eBias >= 1) {
  1693. value += rt / c;
  1694. } else {
  1695. value += rt * Math.pow(2, 1 - eBias);
  1696. }
  1697. if (value * c >= 2) {
  1698. e++;
  1699. c /= 2;
  1700. }
  1701. if (e + eBias >= eMax) {
  1702. m = 0;
  1703. e = eMax;
  1704. } else if (e + eBias >= 1) {
  1705. m = (value * c - 1) * Math.pow(2, mLen);
  1706. e = e + eBias;
  1707. } else {
  1708. m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
  1709. e = 0;
  1710. }
  1711. }
  1712. for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8);
  1713. e = (e << mLen) | m;
  1714. eLen += mLen;
  1715. for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8);
  1716. buffer[offset + i - d] |= s * 128;
  1717. };
  1718. },{}],6:[function(_dereq_,module,exports){
  1719. /**
  1720. * isArray
  1721. */
  1722. var isArray = Array.isArray;
  1723. /**
  1724. * toString
  1725. */
  1726. var str = Object.prototype.toString;
  1727. /**
  1728. * Whether or not the given `val`
  1729. * is an array.
  1730. *
  1731. * example:
  1732. *
  1733. * isArray([]);
  1734. * // > true
  1735. * isArray(arguments);
  1736. * // > false
  1737. * isArray('');
  1738. * // > false
  1739. *
  1740. * @param {mixed} val
  1741. * @return {bool}
  1742. */
  1743. module.exports = isArray || function (val) {
  1744. return !! val && '[object Array]' == str.call(val);
  1745. };
  1746. },{}],7:[function(_dereq_,module,exports){
  1747. (function (process){
  1748. // Copyright Joyent, Inc. and other Node contributors.
  1749. //
  1750. // Permission is hereby granted, free of charge, to any person obtaining a
  1751. // copy of this software and associated documentation files (the
  1752. // "Software"), to deal in the Software without restriction, including
  1753. // without limitation the rights to use, copy, modify, merge, publish,
  1754. // distribute, sublicense, and/or sell copies of the Software, and to permit
  1755. // persons to whom the Software is furnished to do so, subject to the
  1756. // following conditions:
  1757. //
  1758. // The above copyright notice and this permission notice shall be included
  1759. // in all copies or substantial portions of the Software.
  1760. //
  1761. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  1762. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  1763. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  1764. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  1765. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  1766. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  1767. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  1768. // resolves . and .. elements in a path array with directory names there
  1769. // must be no slashes, empty elements, or device names (c:\) in the array
  1770. // (so also no leading and trailing slashes - it does not distinguish
  1771. // relative and absolute paths)
  1772. function normalizeArray(parts, allowAboveRoot) {
  1773. // if the path tries to go above the root, `up` ends up > 0
  1774. var up = 0;
  1775. for (var i = parts.length - 1; i >= 0; i--) {
  1776. var last = parts[i];
  1777. if (last === '.') {
  1778. parts.splice(i, 1);
  1779. } else if (last === '..') {
  1780. parts.splice(i, 1);
  1781. up++;
  1782. } else if (up) {
  1783. parts.splice(i, 1);
  1784. up--;
  1785. }
  1786. }
  1787. // if the path is allowed to go above the root, restore leading ..s
  1788. if (allowAboveRoot) {
  1789. for (; up--; up) {
  1790. parts.unshift('..');
  1791. }
  1792. }
  1793. return parts;
  1794. }
  1795. // Split a filename into [root, dir, basename, ext], unix version
  1796. // 'root' is just a slash, or nothing.
  1797. var splitPathRe =
  1798. /^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/;
  1799. var splitPath = function(filename) {
  1800. return splitPathRe.exec(filename).slice(1);
  1801. };
  1802. // path.resolve([from ...], to)
  1803. // posix version
  1804. exports.resolve = function() {
  1805. var resolvedPath = '',
  1806. resolvedAbsolute = false;
  1807. for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) {
  1808. var path = (i >= 0) ? arguments[i] : process.cwd();
  1809. // Skip empty and invalid entries
  1810. if (typeof path !== 'string') {
  1811. throw new TypeError('Arguments to path.resolve must be strings');
  1812. } else if (!path) {
  1813. continue;
  1814. }
  1815. resolvedPath = path + '/' + resolvedPath;
  1816. resolvedAbsolute = path.charAt(0) === '/';
  1817. }
  1818. // At this point the path should be resolved to a full absolute path, but
  1819. // handle relative paths to be safe (might happen when process.cwd() fails)
  1820. // Normalize the path
  1821. resolvedPath = normalizeArray(filter(resolvedPath.split('/'), function(p) {
  1822. return !!p;
  1823. }), !resolvedAbsolute).join('/');
  1824. return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.';
  1825. };
  1826. // path.normalize(path)
  1827. // posix version
  1828. exports.normalize = function(path) {
  1829. var isAbsolute = exports.isAbsolute(path),
  1830. trailingSlash = substr(path, -1) === '/';
  1831. // Normalize the path
  1832. path = normalizeArray(filter(path.split('/'), function(p) {
  1833. return !!p;
  1834. }), !isAbsolute).join('/');
  1835. if (!path && !isAbsolute) {
  1836. path = '.';
  1837. }
  1838. if (path && trailingSlash) {
  1839. path += '/';
  1840. }
  1841. return (isAbsolute ? '/' : '') + path;
  1842. };
  1843. // posix version
  1844. exports.isAbsolute = function(path) {
  1845. return path.charAt(0) === '/';
  1846. };
  1847. // posix version
  1848. exports.join = function() {
  1849. var paths = Array.prototype.slice.call(arguments, 0);
  1850. return exports.normalize(filter(paths, function(p, index) {
  1851. if (typeof p !== 'string') {
  1852. throw new TypeError('Arguments to path.join must be strings');
  1853. }
  1854. return p;
  1855. }).join('/'));
  1856. };
  1857. // path.relative(from, to)
  1858. // posix version
  1859. exports.relative = function(from, to) {
  1860. from = exports.resolve(from).substr(1);
  1861. to = exports.resolve(to).substr(1);
  1862. function trim(arr) {
  1863. var start = 0;
  1864. for (; start < arr.length; start++) {
  1865. if (arr[start] !== '') break;
  1866. }
  1867. var end = arr.length - 1;
  1868. for (; end >= 0; end--) {
  1869. if (arr[end] !== '') break;
  1870. }
  1871. if (start > end) return [];
  1872. return arr.slice(start, end - start + 1);
  1873. }
  1874. var fromParts = trim(from.split('/'));
  1875. var toParts = trim(to.split('/'));
  1876. var length = Math.min(fromParts.length, toParts.length);
  1877. var samePartsLength = length;
  1878. for (var i = 0; i < length; i++) {
  1879. if (fromParts[i] !== toParts[i]) {
  1880. samePartsLength = i;
  1881. break;
  1882. }
  1883. }
  1884. var outputParts = [];
  1885. for (var i = samePartsLength; i < fromParts.length; i++) {
  1886. outputParts.push('..');
  1887. }
  1888. outputParts = outputParts.concat(toParts.slice(samePartsLength));
  1889. return outputParts.join('/');
  1890. };
  1891. exports.sep = '/';
  1892. exports.delimiter = ':';
  1893. exports.dirname = function(path) {
  1894. var result = splitPath(path),
  1895. root = result[0],
  1896. dir = result[1];
  1897. if (!root && !dir) {
  1898. // No dirname whatsoever
  1899. return '.';
  1900. }
  1901. if (dir) {
  1902. // It has a dirname, strip trailing slash
  1903. dir = dir.substr(0, dir.length - 1);
  1904. }
  1905. return root + dir;
  1906. };
  1907. exports.basename = function(path, ext) {
  1908. var f = splitPath(path)[2];
  1909. // TODO: make this comparison case-insensitive on windows?
  1910. if (ext && f.substr(-1 * ext.length) === ext) {
  1911. f = f.substr(0, f.length - ext.length);
  1912. }
  1913. return f;
  1914. };
  1915. exports.extname = function(path) {
  1916. return splitPath(path)[3];
  1917. };
  1918. function filter (xs, f) {
  1919. if (xs.filter) return xs.filter(f);
  1920. var res = [];
  1921. for (var i = 0; i < xs.length; i++) {
  1922. if (f(xs[i], i, xs)) res.push(xs[i]);
  1923. }
  1924. return res;
  1925. }
  1926. // String.prototype.substr - negative index don't work in IE8
  1927. var substr = 'ab'.substr(-1) === 'b'
  1928. ? function (str, start, len) { return str.substr(start, len) }
  1929. : function (str, start, len) {
  1930. if (start < 0) start = str.length + start;
  1931. return str.substr(start, len);
  1932. }
  1933. ;
  1934. }).call(this,_dereq_('_process'))
  1935. },{"_process":8}],8:[function(_dereq_,module,exports){
  1936. // shim for using process in browser
  1937. var process = module.exports = {};
  1938. var queue = [];
  1939. var draining = false;
  1940. function drainQueue() {
  1941. if (draining) {
  1942. return;
  1943. }
  1944. draining = true;
  1945. var currentQueue;
  1946. var len = queue.length;
  1947. while(len) {
  1948. currentQueue = queue;
  1949. queue = [];
  1950. var i = -1;
  1951. while (++i < len) {
  1952. currentQueue[i]();
  1953. }
  1954. len = queue.length;
  1955. }
  1956. draining = false;
  1957. }
  1958. process.nextTick = function (fun) {
  1959. queue.push(fun);
  1960. if (!draining) {
  1961. setTimeout(drainQueue, 0);
  1962. }
  1963. };
  1964. process.title = 'browser';
  1965. process.browser = true;
  1966. process.env = {};
  1967. process.argv = [];
  1968. process.version = ''; // empty string to avoid regexp issues
  1969. process.versions = {};
  1970. function noop() {}
  1971. process.on = noop;
  1972. process.addListener = noop;
  1973. process.once = noop;
  1974. process.off = noop;
  1975. process.removeListener = noop;
  1976. process.removeAllListeners = noop;
  1977. process.emit = noop;
  1978. process.binding = function (name) {
  1979. throw new Error('process.binding is not supported');
  1980. };
  1981. // TODO(shtylman)
  1982. process.cwd = function () { return '/' };
  1983. process.chdir = function (dir) {
  1984. throw new Error('process.chdir is not supported');
  1985. };
  1986. process.umask = function() { return 0; };
  1987. },{}],9:[function(_dereq_,module,exports){
  1988. /*
  1989. Copyright (C) 2013 Ariya Hidayat <ariya.hidayat@gmail.com>
  1990. Copyright (C) 2013 Thaddee Tyl <thaddee.tyl@gmail.com>
  1991. Copyright (C) 2012 Ariya Hidayat <ariya.hidayat@gmail.com>
  1992. Copyright (C) 2012 Mathias Bynens <mathias@qiwi.be>
  1993. Copyright (C) 2012 Joost-Wim Boekesteijn <joost-wim@boekesteijn.nl>
  1994. Copyright (C) 2012 Kris Kowal <kris.kowal@cixar.com>
  1995. Copyright (C) 2012 Yusuke Suzuki <utatane.tea@gmail.com>
  1996. Copyright (C) 2012 Arpad Borsos <arpad.borsos@googlemail.com>
  1997. Copyright (C) 2011 Ariya Hidayat <ariya.hidayat@gmail.com>
  1998. Redistribution and use in source and binary forms, with or without
  1999. modification, are permitted provided that the following conditions are met:
  2000. * Redistributions of source code must retain the above copyright
  2001. notice, this list of conditions and the following disclaimer.
  2002. * Redistributions in binary form must reproduce the above copyright
  2003. notice, this list of conditions and the following disclaimer in the
  2004. documentation and/or other materials provided with the distribution.
  2005. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  2006. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  2007. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  2008. ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  2009. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  2010. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  2011. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  2012. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  2013. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  2014. THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  2015. */
  2016. (function (root, factory) {
  2017. 'use strict';
  2018. // Universal Module Definition (UMD) to support AMD, CommonJS/Node.js,
  2019. // Rhino, and plain browser loading.
  2020. /* istanbul ignore next */
  2021. if (typeof define === 'function' && define.amd) {
  2022. define(['exports'], factory);
  2023. } else if (typeof exports !== 'undefined') {
  2024. factory(exports);
  2025. } else {
  2026. factory((root.esprima = {}));
  2027. }
  2028. }(this, function (exports) {
  2029. 'use strict';
  2030. var Token,
  2031. TokenName,
  2032. FnExprTokens,
  2033. Syntax,
  2034. PropertyKind,
  2035. Messages,
  2036. Regex,
  2037. SyntaxTreeDelegate,
  2038. XHTMLEntities,
  2039. ClassPropertyType,
  2040. source,
  2041. strict,
  2042. index,
  2043. lineNumber,
  2044. lineStart,
  2045. length,
  2046. delegate,
  2047. lookahead,
  2048. state,
  2049. extra;
  2050. Token = {
  2051. BooleanLiteral: 1,
  2052. EOF: 2,
  2053. Identifier: 3,
  2054. Keyword: 4,
  2055. NullLiteral: 5,
  2056. NumericLiteral: 6,
  2057. Punctuator: 7,
  2058. StringLiteral: 8,
  2059. RegularExpression: 9,
  2060. Template: 10,
  2061. JSXIdentifier: 11,
  2062. JSXText: 12
  2063. };
  2064. TokenName = {};
  2065. TokenName[Token.BooleanLiteral] = 'Boolean';
  2066. TokenName[Token.EOF] = '<end>';
  2067. TokenName[Token.Identifier] = 'Identifier';
  2068. TokenName[Token.Keyword] = 'Keyword';
  2069. TokenName[Token.NullLiteral] = 'Null';
  2070. TokenName[Token.NumericLiteral] = 'Numeric';
  2071. TokenName[Token.Punctuator] = 'Punctuator';
  2072. TokenName[Token.StringLiteral] = 'String';
  2073. TokenName[Token.JSXIdentifier] = 'JSXIdentifier';
  2074. TokenName[Token.JSXText] = 'JSXText';
  2075. TokenName[Token.RegularExpression] = 'RegularExpression';
  2076. // A function following one of those tokens is an expression.
  2077. FnExprTokens = ['(', '{', '[', 'in', 'typeof', 'instanceof', 'new',
  2078. 'return', 'case', 'delete', 'throw', 'void',
  2079. // assignment operators
  2080. '=', '+=', '-=', '*=', '/=', '%=', '<<=', '>>=', '>>>=',
  2081. '&=', '|=', '^=', ',',
  2082. // binary/unary operators
  2083. '+', '-', '*', '/', '%', '++', '--', '<<', '>>', '>>>', '&',
  2084. '|', '^', '!', '~', '&&', '||', '?', ':', '===', '==', '>=',
  2085. '<=', '<', '>', '!=', '!=='];
  2086. Syntax = {
  2087. AnyTypeAnnotation: 'AnyTypeAnnotation',
  2088. ArrayExpression: 'ArrayExpression',
  2089. ArrayPattern: 'ArrayPattern',
  2090. ArrayTypeAnnotation: 'ArrayTypeAnnotation',
  2091. ArrowFunctionExpression: 'ArrowFunctionExpression',
  2092. AssignmentExpression: 'AssignmentExpression',
  2093. BinaryExpression: 'BinaryExpression',
  2094. BlockStatement: 'BlockStatement',
  2095. BooleanTypeAnnotation: 'BooleanTypeAnnotation',
  2096. BreakStatement: 'BreakStatement',
  2097. CallExpression: 'CallExpression',
  2098. CatchClause: 'CatchClause',
  2099. ClassBody: 'ClassBody',
  2100. ClassDeclaration: 'ClassDeclaration',
  2101. ClassExpression: 'ClassExpression',
  2102. ClassImplements: 'ClassImplements',
  2103. ClassProperty: 'ClassProperty',
  2104. ComprehensionBlock: 'ComprehensionBlock',
  2105. ComprehensionExpression: 'ComprehensionExpression',
  2106. ConditionalExpression: 'ConditionalExpression',
  2107. ContinueStatement: 'ContinueStatement',
  2108. DebuggerStatement: 'DebuggerStatement',
  2109. DeclareClass: 'DeclareClass',
  2110. DeclareFunction: 'DeclareFunction',
  2111. DeclareModule: 'DeclareModule',
  2112. DeclareVariable: 'DeclareVariable',
  2113. DoWhileStatement: 'DoWhileStatement',
  2114. EmptyStatement: 'EmptyStatement',
  2115. ExportDeclaration: 'ExportDeclaration',
  2116. ExportBatchSpecifier: 'ExportBatchSpecifier',
  2117. ExportSpecifier: 'ExportSpecifier',
  2118. ExpressionStatement: 'ExpressionStatement',
  2119. ForInStatement: 'ForInStatement',
  2120. ForOfStatement: 'ForOfStatement',
  2121. ForStatement: 'ForStatement',
  2122. FunctionDeclaration: 'FunctionDeclaration',
  2123. FunctionExpression: 'FunctionExpression',
  2124. FunctionTypeAnnotation: 'FunctionTypeAnnotation',
  2125. FunctionTypeParam: 'FunctionTypeParam',
  2126. GenericTypeAnnotation: 'GenericTypeAnnotation',
  2127. Identifier: 'Identifier',
  2128. IfStatement: 'IfStatement',
  2129. ImportDeclaration: 'ImportDeclaration',
  2130. ImportDefaultSpecifier: 'ImportDefaultSpecifier',
  2131. ImportNamespaceSpecifier: 'ImportNamespaceSpecifier',
  2132. ImportSpecifier: 'ImportSpecifier',
  2133. InterfaceDeclaration: 'InterfaceDeclaration',
  2134. InterfaceExtends: 'InterfaceExtends',
  2135. IntersectionTypeAnnotation: 'IntersectionTypeAnnotation',
  2136. LabeledStatement: 'LabeledStatement',
  2137. Literal: 'Literal',
  2138. LogicalExpression: 'LogicalExpression',
  2139. MemberExpression: 'MemberExpression',
  2140. MethodDefinition: 'MethodDefinition',
  2141. ModuleSpecifier: 'ModuleSpecifier',
  2142. NewExpression: 'NewExpression',
  2143. NullableTypeAnnotation: 'NullableTypeAnnotation',
  2144. NumberTypeAnnotation: 'NumberTypeAnnotation',
  2145. ObjectExpression: 'ObjectExpression',
  2146. ObjectPattern: 'ObjectPattern',
  2147. ObjectTypeAnnotation: 'ObjectTypeAnnotation',
  2148. ObjectTypeCallProperty: 'ObjectTypeCallProperty',
  2149. ObjectTypeIndexer: 'ObjectTypeIndexer',
  2150. ObjectTypeProperty: 'ObjectTypeProperty',
  2151. Program: 'Program',
  2152. Property: 'Property',
  2153. QualifiedTypeIdentifier: 'QualifiedTypeIdentifier',
  2154. ReturnStatement: 'ReturnStatement',
  2155. SequenceExpression: 'SequenceExpression',
  2156. SpreadElement: 'SpreadElement',
  2157. SpreadProperty: 'SpreadProperty',
  2158. StringLiteralTypeAnnotation: 'StringLiteralTypeAnnotation',
  2159. StringTypeAnnotation: 'StringTypeAnnotation',
  2160. SwitchCase: 'SwitchCase',
  2161. SwitchStatement: 'SwitchStatement',
  2162. TaggedTemplateExpression: 'TaggedTemplateExpression',
  2163. TemplateElement: 'TemplateElement',
  2164. TemplateLiteral: 'TemplateLiteral',
  2165. ThisExpression: 'ThisExpression',
  2166. ThrowStatement: 'ThrowStatement',
  2167. TupleTypeAnnotation: 'TupleTypeAnnotation',
  2168. TryStatement: 'TryStatement',
  2169. TypeAlias: 'TypeAlias',
  2170. TypeAnnotation: 'TypeAnnotation',
  2171. TypeCastExpression: 'TypeCastExpression',
  2172. TypeofTypeAnnotation: 'TypeofTypeAnnotation',
  2173. TypeParameterDeclaration: 'TypeParameterDeclaration',
  2174. TypeParameterInstantiation: 'TypeParameterInstantiation',
  2175. UnaryExpression: 'UnaryExpression',
  2176. UnionTypeAnnotation: 'UnionTypeAnnotation',
  2177. UpdateExpression: 'UpdateExpression',
  2178. VariableDeclaration: 'VariableDeclaration',
  2179. VariableDeclarator: 'VariableDeclarator',
  2180. VoidTypeAnnotation: 'VoidTypeAnnotation',
  2181. WhileStatement: 'WhileStatement',
  2182. WithStatement: 'WithStatement',
  2183. JSXIdentifier: 'JSXIdentifier',
  2184. JSXNamespacedName: 'JSXNamespacedName',
  2185. JSXMemberExpression: 'JSXMemberExpression',
  2186. JSXEmptyExpression: 'JSXEmptyExpression',
  2187. JSXExpressionContainer: 'JSXExpressionContainer',
  2188. JSXElement: 'JSXElement',
  2189. JSXClosingElement: 'JSXClosingElement',
  2190. JSXOpeningElement: 'JSXOpeningElement',
  2191. JSXAttribute: 'JSXAttribute',
  2192. JSXSpreadAttribute: 'JSXSpreadAttribute',
  2193. JSXText: 'JSXText',
  2194. YieldExpression: 'YieldExpression',
  2195. AwaitExpression: 'AwaitExpression'
  2196. };
  2197. PropertyKind = {
  2198. Data: 1,
  2199. Get: 2,
  2200. Set: 4
  2201. };
  2202. ClassPropertyType = {
  2203. 'static': 'static',
  2204. prototype: 'prototype'
  2205. };
  2206. // Error messages should be identical to V8.
  2207. Messages = {
  2208. UnexpectedToken: 'Unexpected token %0',
  2209. UnexpectedNumber: 'Unexpected number',
  2210. UnexpectedString: 'Unexpected string',
  2211. UnexpectedIdentifier: 'Unexpected identifier',
  2212. UnexpectedReserved: 'Unexpected reserved word',
  2213. UnexpectedTemplate: 'Unexpected quasi %0',
  2214. UnexpectedEOS: 'Unexpected end of input',
  2215. NewlineAfterThrow: 'Illegal newline after throw',
  2216. InvalidRegExp: 'Invalid regular expression',
  2217. UnterminatedRegExp: 'Invalid regular expression: missing /',
  2218. InvalidLHSInAssignment: 'Invalid left-hand side in assignment',
  2219. InvalidLHSInFormalsList: 'Invalid left-hand side in formals list',
  2220. InvalidLHSInForIn: 'Invalid left-hand side in for-in',
  2221. MultipleDefaultsInSwitch: 'More than one default clause in switch statement',
  2222. NoCatchOrFinally: 'Missing catch or finally after try',
  2223. UnknownLabel: 'Undefined label \'%0\'',
  2224. Redeclaration: '%0 \'%1\' has already been declared',
  2225. IllegalContinue: 'Illegal continue statement',
  2226. IllegalBreak: 'Illegal break statement',
  2227. IllegalDuplicateClassProperty: 'Illegal duplicate property in class definition',
  2228. IllegalClassConstructorProperty: 'Illegal constructor property in class definition',
  2229. IllegalReturn: 'Illegal return statement',
  2230. IllegalSpread: 'Illegal spread element',
  2231. StrictModeWith: 'Strict mode code may not include a with statement',
  2232. StrictCatchVariable: 'Catch variable may not be eval or arguments in strict mode',
  2233. StrictVarName: 'Variable name may not be eval or arguments in strict mode',
  2234. StrictParamName: 'Parameter name eval or arguments is not allowed in strict mode',
  2235. StrictParamDupe: 'Strict mode function may not have duplicate parameter names',
  2236. ParameterAfterRestParameter: 'Rest parameter must be final parameter of an argument list',
  2237. DefaultRestParameter: 'Rest parameter can not have a default value',
  2238. ElementAfterSpreadElement: 'Spread must be the final element of an element list',
  2239. PropertyAfterSpreadProperty: 'A rest property must be the final property of an object literal',
  2240. ObjectPatternAsRestParameter: 'Invalid rest parameter',
  2241. ObjectPatternAsSpread: 'Invalid spread argument',
  2242. StrictFunctionName: 'Function name may not be eval or arguments in strict mode',
  2243. StrictOctalLiteral: 'Octal literals are not allowed in strict mode.',
  2244. StrictDelete: 'Delete of an unqualified identifier in strict mode.',
  2245. StrictDuplicateProperty: 'Duplicate data property in object literal not allowed in strict mode',
  2246. AccessorDataProperty: 'Object literal may not have data and accessor property with the same name',
  2247. AccessorGetSet: 'Object literal may not have multiple get/set accessors with the same name',
  2248. StrictLHSAssignment: 'Assignment to eval or arguments is not allowed in strict mode',
  2249. StrictLHSPostfix: 'Postfix increment/decrement may not have eval or arguments operand in strict mode',
  2250. StrictLHSPrefix: 'Prefix increment/decrement may not have eval or arguments operand in strict mode',
  2251. StrictReservedWord: 'Use of future reserved word in strict mode',
  2252. MissingFromClause: 'Missing from clause',
  2253. NoAsAfterImportNamespace: 'Missing as after import *',
  2254. InvalidModuleSpecifier: 'Invalid module specifier',
  2255. IllegalImportDeclaration: 'Illegal import declaration',
  2256. IllegalExportDeclaration: 'Illegal export declaration',
  2257. NoUninitializedConst: 'Const must be initialized',
  2258. ComprehensionRequiresBlock: 'Comprehension must have at least one block',
  2259. ComprehensionError: 'Comprehension Error',
  2260. EachNotAllowed: 'Each is not supported',
  2261. InvalidJSXAttributeValue: 'JSX value should be either an expression or a quoted JSX text',
  2262. ExpectedJSXClosingTag: 'Expected corresponding JSX closing tag for %0',
  2263. AdjacentJSXElements: 'Adjacent JSX elements must be wrapped in an enclosing tag',
  2264. ConfusedAboutFunctionType: 'Unexpected token =>. It looks like ' +
  2265. 'you are trying to write a function type, but you ended up ' +
  2266. 'writing a grouped type followed by an =>, which is a syntax ' +
  2267. 'error. Remember, function type parameters are named so function ' +
  2268. 'types look like (name1: type1, name2: type2) => returnType. You ' +
  2269. 'probably wrote (type1) => returnType'
  2270. };
  2271. // See also tools/generate-unicode-regex.py.
  2272. Regex = {
  2273. NonAsciiIdentifierStart: new RegExp('[\xaa\xb5\xba\xc0-\xd6\xd8-\xf6\xf8-\u02c1\u02c6-\u02d1\u02e0-\u02e4\u02ec\u02ee\u0370-\u0374\u0376\u0377\u037a-\u037d\u0386\u0388-\u038a\u038c\u038e-\u03a1\u03a3-\u03f5\u03f7-\u0481\u048a-\u0527\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\u08a2-\u08ac\u0904-\u0939\u093d\u0950\u0958-\u0961\u0971-\u0977\u0979-\u097f\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\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-\u0c33\u0c35-\u0c39\u0c3d\u0c58\u0c59\u0c60\u0c61\u0c85-\u0c8c\u0c8e-\u0c90\u0c92-\u0ca8\u0caa-\u0cb3\u0cb5-\u0cb9\u0cbd\u0cde\u0ce0\u0ce1\u0cf1\u0cf2\u0d05-\u0d0c\u0d0e-\u0d10\u0d12-\u0d3a\u0d3d\u0d4e\u0d60\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-\u13f4\u1401-\u166c\u166f-\u167f\u1681-\u169a\u16a0-\u16ea\u16ee-\u16f0\u1700-\u170c\u170e-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176c\u176e-\u1770\u1780-\u17b3\u17d7\u17dc\u1820-\u1877\u1880-\u18a8\u18aa\u18b0-\u18f5\u1900-\u191c\u1950-\u196d\u1970-\u1974\u1980-\u19ab\u19c1-\u19c7\u1a00-\u1a16\u1a20-\u1a54\u1aa7\u1b05-\u1b33\u1b45-\u1b4b\u1b83-\u1ba0\u1bae\u1baf\u1bba-\u1be5\u1c00-\u1c23\u1c4d-\u1c4f\u1c5a-\u1c7d\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\u2119-\u211d\u2124\u2126\u2128\u212a-\u212d\u212f-\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\u2e2f\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303c\u3041-\u3096\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-\ua61f\ua62a\ua62b\ua640-\ua66e\ua67f-\ua697\ua6a0-\ua6ef\ua717-\ua71f\ua722-\ua788\ua78b-\ua78e\ua790-\ua793\ua7a0-\ua7aa\ua7f8-\ua801\ua803-\ua805\ua807-\ua80a\ua80c-\ua822\ua840-\ua873\ua882-\ua8b3\ua8f2-\ua8f7\ua8fb\ua90a-\ua925\ua930-\ua946\ua960-\ua97c\ua984-\ua9b2\ua9cf\uaa00-\uaa28\uaa40-\uaa42\uaa44-\uaa4b\uaa60-\uaa76\uaa7a\uaa80-\uaaaf\uaab1\uaab5\uaab6\uaab9-\uaabd\uaac0\uaac2\uaadb-\uaadd\uaae0-\uaaea\uaaf2-\uaaf4\uab01-\uab06\uab09-\uab0e\uab11-\uab16\uab20-\uab26\uab28-\uab2e\uabc0-\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]'),
  2274. NonAsciiIdentifierPart: new RegExp('[\xaa\xb5\xba\xc0-\xd6\xd8-\xf6\xf8-\u02c1\u02c6-\u02d1\u02e0-\u02e4\u02ec\u02ee\u0300-\u0374\u0376\u0377\u037a-\u037d\u0386\u0388-\u038a\u038c\u038e-\u03a1\u03a3-\u03f5\u03f7-\u0481\u0483-\u0487\u048a-\u0527\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\u08a2-\u08ac\u08e4-\u08fe\u0900-\u0963\u0966-\u096f\u0971-\u0977\u0979-\u097f\u0981-\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\u0c01-\u0c03\u0c05-\u0c0c\u0c0e-\u0c10\u0c12-\u0c28\u0c2a-\u0c33\u0c35-\u0c39\u0c3d-\u0c44\u0c46-\u0c48\u0c4a-\u0c4d\u0c55\u0c56\u0c58\u0c59\u0c60-\u0c63\u0c66-\u0c6f\u0c82\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\u0d02\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\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-\u16f0\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-\u191c\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\u1b00-\u1b4b\u1b50-\u1b59\u1b6b-\u1b73\u1b80-\u1bf3\u1c00-\u1c37\u1c40-\u1c49\u1c4d-\u1c7d\u1cd0-\u1cd2\u1cd4-\u1cf6\u1d00-\u1de6\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-\ua697\ua69f-\ua6f1\ua717-\ua71f\ua722-\ua788\ua78b-\ua78e\ua790-\ua793\ua7a0-\ua7aa\ua7f8-\ua827\ua840-\ua873\ua880-\ua8c4\ua8d0-\ua8d9\ua8e0-\ua8f7\ua8fb\ua900-\ua92d\ua930-\ua953\ua960-\ua97c\ua980-\ua9c0\ua9cf-\ua9d9\uaa00-\uaa36\uaa40-\uaa4d\uaa50-\uaa59\uaa60-\uaa76\uaa7a\uaa7b\uaa80-\uaac2\uaadb-\uaadd\uaae0-\uaaef\uaaf2-\uaaf6\uab01-\uab06\uab09-\uab0e\uab11-\uab16\uab20-\uab26\uab28-\uab2e\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-\ufe26\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]'),
  2275. LeadingZeros: new RegExp('^0+(?!$)')
  2276. };
  2277. // Ensure the condition is true, otherwise throw an error.
  2278. // This is only to have a better contract semantic, i.e. another safety net
  2279. // to catch a logic error. The condition shall be fulfilled in normal case.
  2280. // Do NOT use this to enforce a certain condition on any user input.
  2281. function assert(condition, message) {
  2282. /* istanbul ignore if */
  2283. if (!condition) {
  2284. throw new Error('ASSERT: ' + message);
  2285. }
  2286. }
  2287. function StringMap() {
  2288. this.$data = {};
  2289. }
  2290. StringMap.prototype.get = function (key) {
  2291. key = '$' + key;
  2292. return this.$data[key];
  2293. };
  2294. StringMap.prototype.set = function (key, value) {
  2295. key = '$' + key;
  2296. this.$data[key] = value;
  2297. return this;
  2298. };
  2299. StringMap.prototype.has = function (key) {
  2300. key = '$' + key;
  2301. return Object.prototype.hasOwnProperty.call(this.$data, key);
  2302. };
  2303. StringMap.prototype["delete"] = function (key) {
  2304. key = '$' + key;
  2305. return delete this.$data[key];
  2306. };
  2307. function isDecimalDigit(ch) {
  2308. return (ch >= 48 && ch <= 57); // 0..9
  2309. }
  2310. function isHexDigit(ch) {
  2311. return '0123456789abcdefABCDEF'.indexOf(ch) >= 0;
  2312. }
  2313. function isOctalDigit(ch) {
  2314. return '01234567'.indexOf(ch) >= 0;
  2315. }
  2316. // 7.2 White Space
  2317. function isWhiteSpace(ch) {
  2318. return (ch === 32) || // space
  2319. (ch === 9) || // tab
  2320. (ch === 0xB) ||
  2321. (ch === 0xC) ||
  2322. (ch === 0xA0) ||
  2323. (ch >= 0x1680 && '\u1680\u180E\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\uFEFF'.indexOf(String.fromCharCode(ch)) > 0);
  2324. }
  2325. // 7.3 Line Terminators
  2326. function isLineTerminator(ch) {
  2327. return (ch === 10) || (ch === 13) || (ch === 0x2028) || (ch === 0x2029);
  2328. }
  2329. // 7.6 Identifier Names and Identifiers
  2330. function isIdentifierStart(ch) {
  2331. return (ch === 36) || (ch === 95) || // $ (dollar) and _ (underscore)
  2332. (ch >= 65 && ch <= 90) || // A..Z
  2333. (ch >= 97 && ch <= 122) || // a..z
  2334. (ch === 92) || // \ (backslash)
  2335. ((ch >= 0x80) && Regex.NonAsciiIdentifierStart.test(String.fromCharCode(ch)));
  2336. }
  2337. function isIdentifierPart(ch) {
  2338. return (ch === 36) || (ch === 95) || // $ (dollar) and _ (underscore)
  2339. (ch >= 65 && ch <= 90) || // A..Z
  2340. (ch >= 97 && ch <= 122) || // a..z
  2341. (ch >= 48 && ch <= 57) || // 0..9
  2342. (ch === 92) || // \ (backslash)
  2343. ((ch >= 0x80) && Regex.NonAsciiIdentifierPart.test(String.fromCharCode(ch)));
  2344. }
  2345. // 7.6.1.2 Future Reserved Words
  2346. function isFutureReservedWord(id) {
  2347. switch (id) {
  2348. case 'class':
  2349. case 'enum':
  2350. case 'export':
  2351. case 'extends':
  2352. case 'import':
  2353. case 'super':
  2354. return true;
  2355. default:
  2356. return false;
  2357. }
  2358. }
  2359. function isStrictModeReservedWord(id) {
  2360. switch (id) {
  2361. case 'implements':
  2362. case 'interface':
  2363. case 'package':
  2364. case 'private':
  2365. case 'protected':
  2366. case 'public':
  2367. case 'static':
  2368. case 'yield':
  2369. case 'let':
  2370. return true;
  2371. default:
  2372. return false;
  2373. }
  2374. }
  2375. function isRestrictedWord(id) {
  2376. return id === 'eval' || id === 'arguments';
  2377. }
  2378. // 7.6.1.1 Keywords
  2379. function isKeyword(id) {
  2380. if (strict && isStrictModeReservedWord(id)) {
  2381. return true;
  2382. }
  2383. // 'const' is specialized as Keyword in V8.
  2384. // 'yield' is only treated as a keyword in strict mode.
  2385. // 'let' is for compatiblity with SpiderMonkey and ES.next.
  2386. // Some others are from future reserved words.
  2387. switch (id.length) {
  2388. case 2:
  2389. return (id === 'if') || (id === 'in') || (id === 'do');
  2390. case 3:
  2391. return (id === 'var') || (id === 'for') || (id === 'new') ||
  2392. (id === 'try') || (id === 'let');
  2393. case 4:
  2394. return (id === 'this') || (id === 'else') || (id === 'case') ||
  2395. (id === 'void') || (id === 'with') || (id === 'enum');
  2396. case 5:
  2397. return (id === 'while') || (id === 'break') || (id === 'catch') ||
  2398. (id === 'throw') || (id === 'const') ||
  2399. (id === 'class') || (id === 'super');
  2400. case 6:
  2401. return (id === 'return') || (id === 'typeof') || (id === 'delete') ||
  2402. (id === 'switch') || (id === 'export') || (id === 'import');
  2403. case 7:
  2404. return (id === 'default') || (id === 'finally') || (id === 'extends');
  2405. case 8:
  2406. return (id === 'function') || (id === 'continue') || (id === 'debugger');
  2407. case 10:
  2408. return (id === 'instanceof');
  2409. default:
  2410. return false;
  2411. }
  2412. }
  2413. // 7.4 Comments
  2414. function addComment(type, value, start, end, loc) {
  2415. var comment;
  2416. assert(typeof start === 'number', 'Comment must have valid position');
  2417. // Because the way the actual token is scanned, often the comments
  2418. // (if any) are skipped twice during the lexical analysis.
  2419. // Thus, we need to skip adding a comment if the comment array already
  2420. // handled it.
  2421. if (state.lastCommentStart >= start) {
  2422. return;
  2423. }
  2424. state.lastCommentStart = start;
  2425. comment = {
  2426. type: type,
  2427. value: value
  2428. };
  2429. if (extra.range) {
  2430. comment.range = [start, end];
  2431. }
  2432. if (extra.loc) {
  2433. comment.loc = loc;
  2434. }
  2435. extra.comments.push(comment);
  2436. if (extra.attachComment) {
  2437. extra.leadingComments.push(comment);
  2438. extra.trailingComments.push(comment);
  2439. }
  2440. }
  2441. function skipSingleLineComment() {
  2442. var start, loc, ch, comment;
  2443. start = index - 2;
  2444. loc = {
  2445. start: {
  2446. line: lineNumber,
  2447. column: index - lineStart - 2
  2448. }
  2449. };
  2450. while (index < length) {
  2451. ch = source.charCodeAt(index);
  2452. ++index;
  2453. if (isLineTerminator(ch)) {
  2454. if (extra.comments) {
  2455. comment = source.slice(start + 2, index - 1);
  2456. loc.end = {
  2457. line: lineNumber,
  2458. column: index - lineStart - 1
  2459. };
  2460. addComment('Line', comment, start, index - 1, loc);
  2461. }
  2462. if (ch === 13 && source.charCodeAt(index) === 10) {
  2463. ++index;
  2464. }
  2465. ++lineNumber;
  2466. lineStart = index;
  2467. return;
  2468. }
  2469. }
  2470. if (extra.comments) {
  2471. comment = source.slice(start + 2, index);
  2472. loc.end = {
  2473. line: lineNumber,
  2474. column: index - lineStart
  2475. };
  2476. addComment('Line', comment, start, index, loc);
  2477. }
  2478. }
  2479. function skipMultiLineComment() {
  2480. var start, loc, ch, comment;
  2481. if (extra.comments) {
  2482. start = index - 2;
  2483. loc = {
  2484. start: {
  2485. line: lineNumber,
  2486. column: index - lineStart - 2
  2487. }
  2488. };
  2489. }
  2490. while (index < length) {
  2491. ch = source.charCodeAt(index);
  2492. if (isLineTerminator(ch)) {
  2493. if (ch === 13 && source.charCodeAt(index + 1) === 10) {
  2494. ++index;
  2495. }
  2496. ++lineNumber;
  2497. ++index;
  2498. lineStart = index;
  2499. if (index >= length) {
  2500. throwError({}, Messages.UnexpectedToken, 'ILLEGAL');
  2501. }
  2502. } else if (ch === 42) {
  2503. // Block comment ends with '*/' (char #42, char #47).
  2504. if (source.charCodeAt(index + 1) === 47) {
  2505. ++index;
  2506. ++index;
  2507. if (extra.comments) {
  2508. comment = source.slice(start + 2, index - 2);
  2509. loc.end = {
  2510. line: lineNumber,
  2511. column: index - lineStart
  2512. };
  2513. addComment('Block', comment, start, index, loc);
  2514. }
  2515. return;
  2516. }
  2517. ++index;
  2518. } else {
  2519. ++index;
  2520. }
  2521. }
  2522. throwError({}, Messages.UnexpectedToken, 'ILLEGAL');
  2523. }
  2524. function skipComment() {
  2525. var ch;
  2526. while (index < length) {
  2527. ch = source.charCodeAt(index);
  2528. if (isWhiteSpace(ch)) {
  2529. ++index;
  2530. } else if (isLineTerminator(ch)) {
  2531. ++index;
  2532. if (ch === 13 && source.charCodeAt(index) === 10) {
  2533. ++index;
  2534. }
  2535. ++lineNumber;
  2536. lineStart = index;
  2537. } else if (ch === 47) { // 47 is '/'
  2538. ch = source.charCodeAt(index + 1);
  2539. if (ch === 47) {
  2540. ++index;
  2541. ++index;
  2542. skipSingleLineComment();
  2543. } else if (ch === 42) { // 42 is '*'
  2544. ++index;
  2545. ++index;
  2546. skipMultiLineComment();
  2547. } else {
  2548. break;
  2549. }
  2550. } else {
  2551. break;
  2552. }
  2553. }
  2554. }
  2555. function scanHexEscape(prefix) {
  2556. var i, len, ch, code = 0;
  2557. len = (prefix === 'u') ? 4 : 2;
  2558. for (i = 0; i < len; ++i) {
  2559. if (index < length && isHexDigit(source[index])) {
  2560. ch = source[index++];
  2561. code = code * 16 + '0123456789abcdef'.indexOf(ch.toLowerCase());
  2562. } else {
  2563. return '';
  2564. }
  2565. }
  2566. return String.fromCharCode(code);
  2567. }
  2568. function scanUnicodeCodePointEscape() {
  2569. var ch, code, cu1, cu2;
  2570. ch = source[index];
  2571. code = 0;
  2572. // At least, one hex digit is required.
  2573. if (ch === '}') {
  2574. throwError({}, Messages.UnexpectedToken, 'ILLEGAL');
  2575. }
  2576. while (index < length) {
  2577. ch = source[index++];
  2578. if (!isHexDigit(ch)) {
  2579. break;
  2580. }
  2581. code = code * 16 + '0123456789abcdef'.indexOf(ch.toLowerCase());
  2582. }
  2583. if (code > 0x10FFFF || ch !== '}') {
  2584. throwError({}, Messages.UnexpectedToken, 'ILLEGAL');
  2585. }
  2586. // UTF-16 Encoding
  2587. if (code <= 0xFFFF) {
  2588. return String.fromCharCode(code);
  2589. }
  2590. cu1 = ((code - 0x10000) >> 10) + 0xD800;
  2591. cu2 = ((code - 0x10000) & 1023) + 0xDC00;
  2592. return String.fromCharCode(cu1, cu2);
  2593. }
  2594. function getEscapedIdentifier() {
  2595. var ch, id;
  2596. ch = source.charCodeAt(index++);
  2597. id = String.fromCharCode(ch);
  2598. // '\u' (char #92, char #117) denotes an escaped character.
  2599. if (ch === 92) {
  2600. if (source.charCodeAt(index) !== 117) {
  2601. throwError({}, Messages.UnexpectedToken, 'ILLEGAL');
  2602. }
  2603. ++index;
  2604. ch = scanHexEscape('u');
  2605. if (!ch || ch === '\\' || !isIdentifierStart(ch.charCodeAt(0))) {
  2606. throwError({}, Messages.UnexpectedToken, 'ILLEGAL');
  2607. }
  2608. id = ch;
  2609. }
  2610. while (index < length) {
  2611. ch = source.charCodeAt(index);
  2612. if (!isIdentifierPart(ch)) {
  2613. break;
  2614. }
  2615. ++index;
  2616. id += String.fromCharCode(ch);
  2617. // '\u' (char #92, char #117) denotes an escaped character.
  2618. if (ch === 92) {
  2619. id = id.substr(0, id.length - 1);
  2620. if (source.charCodeAt(index) !== 117) {
  2621. throwError({}, Messages.UnexpectedToken, 'ILLEGAL');
  2622. }
  2623. ++index;
  2624. ch = scanHexEscape('u');
  2625. if (!ch || ch === '\\' || !isIdentifierPart(ch.charCodeAt(0))) {
  2626. throwError({}, Messages.UnexpectedToken, 'ILLEGAL');
  2627. }
  2628. id += ch;
  2629. }
  2630. }
  2631. return id;
  2632. }
  2633. function getIdentifier() {
  2634. var start, ch;
  2635. start = index++;
  2636. while (index < length) {
  2637. ch = source.charCodeAt(index);
  2638. if (ch === 92) {
  2639. // Blackslash (char #92) marks Unicode escape sequence.
  2640. index = start;
  2641. return getEscapedIdentifier();
  2642. }
  2643. if (isIdentifierPart(ch)) {
  2644. ++index;
  2645. } else {
  2646. break;
  2647. }
  2648. }
  2649. return source.slice(start, index);
  2650. }
  2651. function scanIdentifier() {
  2652. var start, id, type;
  2653. start = index;
  2654. // Backslash (char #92) starts an escaped character.
  2655. id = (source.charCodeAt(index) === 92) ? getEscapedIdentifier() : getIdentifier();
  2656. // There is no keyword or literal with only one character.
  2657. // Thus, it must be an identifier.
  2658. if (id.length === 1) {
  2659. type = Token.Identifier;
  2660. } else if (isKeyword(id)) {
  2661. type = Token.Keyword;
  2662. } else if (id === 'null') {
  2663. type = Token.NullLiteral;
  2664. } else if (id === 'true' || id === 'false') {
  2665. type = Token.BooleanLiteral;
  2666. } else {
  2667. type = Token.Identifier;
  2668. }
  2669. return {
  2670. type: type,
  2671. value: id,
  2672. lineNumber: lineNumber,
  2673. lineStart: lineStart,
  2674. range: [start, index]
  2675. };
  2676. }
  2677. // 7.7 Punctuators
  2678. function scanPunctuator() {
  2679. var start = index,
  2680. code = source.charCodeAt(index),
  2681. code2,
  2682. ch1 = source[index],
  2683. ch2,
  2684. ch3,
  2685. ch4;
  2686. if (state.inJSXTag || state.inJSXChild) {
  2687. // Don't need to check for '{' and '}' as it's already handled
  2688. // correctly by default.
  2689. switch (code) {
  2690. case 60: // <
  2691. case 62: // >
  2692. ++index;
  2693. return {
  2694. type: Token.Punctuator,
  2695. value: String.fromCharCode(code),
  2696. lineNumber: lineNumber,
  2697. lineStart: lineStart,
  2698. range: [start, index]
  2699. };
  2700. }
  2701. }
  2702. switch (code) {
  2703. // Check for most common single-character punctuators.
  2704. case 40: // ( open bracket
  2705. case 41: // ) close bracket
  2706. case 59: // ; semicolon
  2707. case 44: // , comma
  2708. case 123: // { open curly brace
  2709. case 125: // } close curly brace
  2710. case 91: // [
  2711. case 93: // ]
  2712. case 58: // :
  2713. case 63: // ?
  2714. case 126: // ~
  2715. ++index;
  2716. if (extra.tokenize) {
  2717. if (code === 40) {
  2718. extra.openParenToken = extra.tokens.length;
  2719. } else if (code === 123) {
  2720. extra.openCurlyToken = extra.tokens.length;
  2721. }
  2722. }
  2723. return {
  2724. type: Token.Punctuator,
  2725. value: String.fromCharCode(code),
  2726. lineNumber: lineNumber,
  2727. lineStart: lineStart,
  2728. range: [start, index]
  2729. };
  2730. default:
  2731. code2 = source.charCodeAt(index + 1);
  2732. // '=' (char #61) marks an assignment or comparison operator.
  2733. if (code2 === 61) {
  2734. switch (code) {
  2735. case 37: // %
  2736. case 38: // &
  2737. case 42: // *:
  2738. case 43: // +
  2739. case 45: // -
  2740. case 47: // /
  2741. case 60: // <
  2742. case 62: // >
  2743. case 94: // ^
  2744. case 124: // |
  2745. index += 2;
  2746. return {
  2747. type: Token.Punctuator,
  2748. value: String.fromCharCode(code) + String.fromCharCode(code2),
  2749. lineNumber: lineNumber,
  2750. lineStart: lineStart,
  2751. range: [start, index]
  2752. };
  2753. case 33: // !
  2754. case 61: // =
  2755. index += 2;
  2756. // !== and ===
  2757. if (source.charCodeAt(index) === 61) {
  2758. ++index;
  2759. }
  2760. return {
  2761. type: Token.Punctuator,
  2762. value: source.slice(start, index),
  2763. lineNumber: lineNumber,
  2764. lineStart: lineStart,
  2765. range: [start, index]
  2766. };
  2767. default:
  2768. break;
  2769. }
  2770. }
  2771. break;
  2772. }
  2773. // Peek more characters.
  2774. ch2 = source[index + 1];
  2775. ch3 = source[index + 2];
  2776. ch4 = source[index + 3];
  2777. // 4-character punctuator: >>>=
  2778. if (ch1 === '>' && ch2 === '>' && ch3 === '>') {
  2779. if (ch4 === '=') {
  2780. index += 4;
  2781. return {
  2782. type: Token.Punctuator,
  2783. value: '>>>=',
  2784. lineNumber: lineNumber,
  2785. lineStart: lineStart,
  2786. range: [start, index]
  2787. };
  2788. }
  2789. }
  2790. // 3-character punctuators: === !== >>> <<= >>=
  2791. if (ch1 === '>' && ch2 === '>' && ch3 === '>' && !state.inType) {
  2792. index += 3;
  2793. return {
  2794. type: Token.Punctuator,
  2795. value: '>>>',
  2796. lineNumber: lineNumber,
  2797. lineStart: lineStart,
  2798. range: [start, index]
  2799. };
  2800. }
  2801. if (ch1 === '<' && ch2 === '<' && ch3 === '=') {
  2802. index += 3;
  2803. return {
  2804. type: Token.Punctuator,
  2805. value: '<<=',
  2806. lineNumber: lineNumber,
  2807. lineStart: lineStart,
  2808. range: [start, index]
  2809. };
  2810. }
  2811. if (ch1 === '>' && ch2 === '>' && ch3 === '=') {
  2812. index += 3;
  2813. return {
  2814. type: Token.Punctuator,
  2815. value: '>>=',
  2816. lineNumber: lineNumber,
  2817. lineStart: lineStart,
  2818. range: [start, index]
  2819. };
  2820. }
  2821. if (ch1 === '.' && ch2 === '.' && ch3 === '.') {
  2822. index += 3;
  2823. return {
  2824. type: Token.Punctuator,
  2825. value: '...',
  2826. lineNumber: lineNumber,
  2827. lineStart: lineStart,
  2828. range: [start, index]
  2829. };
  2830. }
  2831. // Other 2-character punctuators: ++ -- << >> && ||
  2832. // Don't match these tokens if we're in a type, since they never can
  2833. // occur and can mess up types like Map<string, Array<string>>
  2834. if (ch1 === ch2 && ('+-<>&|'.indexOf(ch1) >= 0) && !state.inType) {
  2835. index += 2;
  2836. return {
  2837. type: Token.Punctuator,
  2838. value: ch1 + ch2,
  2839. lineNumber: lineNumber,
  2840. lineStart: lineStart,
  2841. range: [start, index]
  2842. };
  2843. }
  2844. if (ch1 === '=' && ch2 === '>') {
  2845. index += 2;
  2846. return {
  2847. type: Token.Punctuator,
  2848. value: '=>',
  2849. lineNumber: lineNumber,
  2850. lineStart: lineStart,
  2851. range: [start, index]
  2852. };
  2853. }
  2854. if ('<>=!+-*%&|^/'.indexOf(ch1) >= 0) {
  2855. ++index;
  2856. return {
  2857. type: Token.Punctuator,
  2858. value: ch1,
  2859. lineNumber: lineNumber,
  2860. lineStart: lineStart,
  2861. range: [start, index]
  2862. };
  2863. }
  2864. if (ch1 === '.') {
  2865. ++index;
  2866. return {
  2867. type: Token.Punctuator,
  2868. value: ch1,
  2869. lineNumber: lineNumber,
  2870. lineStart: lineStart,
  2871. range: [start, index]
  2872. };
  2873. }
  2874. throwError({}, Messages.UnexpectedToken, 'ILLEGAL');
  2875. }
  2876. // 7.8.3 Numeric Literals
  2877. function scanHexLiteral(start) {
  2878. var number = '';
  2879. while (index < length) {
  2880. if (!isHexDigit(source[index])) {
  2881. break;
  2882. }
  2883. number += source[index++];
  2884. }
  2885. if (number.length === 0) {
  2886. throwError({}, Messages.UnexpectedToken, 'ILLEGAL');
  2887. }
  2888. if (isIdentifierStart(source.charCodeAt(index))) {
  2889. throwError({}, Messages.UnexpectedToken, 'ILLEGAL');
  2890. }
  2891. return {
  2892. type: Token.NumericLiteral,
  2893. value: parseInt('0x' + number, 16),
  2894. lineNumber: lineNumber,
  2895. lineStart: lineStart,
  2896. range: [start, index]
  2897. };
  2898. }
  2899. function scanBinaryLiteral(start) {
  2900. var ch, number;
  2901. number = '';
  2902. while (index < length) {
  2903. ch = source[index];
  2904. if (ch !== '0' && ch !== '1') {
  2905. break;
  2906. }
  2907. number += source[index++];
  2908. }
  2909. if (number.length === 0) {
  2910. // only 0b or 0B
  2911. throwError({}, Messages.UnexpectedToken, 'ILLEGAL');
  2912. }
  2913. if (index < length) {
  2914. ch = source.charCodeAt(index);
  2915. /* istanbul ignore else */
  2916. if (isIdentifierStart(ch) || isDecimalDigit(ch)) {
  2917. throwError({}, Messages.UnexpectedToken, 'ILLEGAL');
  2918. }
  2919. }
  2920. return {
  2921. type: Token.NumericLiteral,
  2922. value: parseInt(number, 2),
  2923. lineNumber: lineNumber,
  2924. lineStart: lineStart,
  2925. range: [start, index]
  2926. };
  2927. }
  2928. function scanOctalLiteral(prefix, start) {
  2929. var number, octal;
  2930. if (isOctalDigit(prefix)) {
  2931. octal = true;
  2932. number = '0' + source[index++];
  2933. } else {
  2934. octal = false;
  2935. ++index;
  2936. number = '';
  2937. }
  2938. while (index < length) {
  2939. if (!isOctalDigit(source[index])) {
  2940. break;
  2941. }
  2942. number += source[index++];
  2943. }
  2944. if (!octal && number.length === 0) {
  2945. // only 0o or 0O
  2946. throwError({}, Messages.UnexpectedToken, 'ILLEGAL');
  2947. }
  2948. if (isIdentifierStart(source.charCodeAt(index)) || isDecimalDigit(source.charCodeAt(index))) {
  2949. throwError({}, Messages.UnexpectedToken, 'ILLEGAL');
  2950. }
  2951. return {
  2952. type: Token.NumericLiteral,
  2953. value: parseInt(number, 8),
  2954. octal: octal,
  2955. lineNumber: lineNumber,
  2956. lineStart: lineStart,
  2957. range: [start, index]
  2958. };
  2959. }
  2960. function scanNumericLiteral() {
  2961. var number, start, ch;
  2962. ch = source[index];
  2963. assert(isDecimalDigit(ch.charCodeAt(0)) || (ch === '.'),
  2964. 'Numeric literal must start with a decimal digit or a decimal point');
  2965. start = index;
  2966. number = '';
  2967. if (ch !== '.') {
  2968. number = source[index++];
  2969. ch = source[index];
  2970. // Hex number starts with '0x'.
  2971. // Octal number starts with '0'.
  2972. // Octal number in ES6 starts with '0o'.
  2973. // Binary number in ES6 starts with '0b'.
  2974. if (number === '0') {
  2975. if (ch === 'x' || ch === 'X') {
  2976. ++index;
  2977. return scanHexLiteral(start);
  2978. }
  2979. if (ch === 'b' || ch === 'B') {
  2980. ++index;
  2981. return scanBinaryLiteral(start);
  2982. }
  2983. if (ch === 'o' || ch === 'O' || isOctalDigit(ch)) {
  2984. return scanOctalLiteral(ch, start);
  2985. }
  2986. // decimal number starts with '0' such as '09' is illegal.
  2987. if (ch && isDecimalDigit(ch.charCodeAt(0))) {
  2988. throwError({}, Messages.UnexpectedToken, 'ILLEGAL');
  2989. }
  2990. }
  2991. while (isDecimalDigit(source.charCodeAt(index))) {
  2992. number += source[index++];
  2993. }
  2994. ch = source[index];
  2995. }
  2996. if (ch === '.') {
  2997. number += source[index++];
  2998. while (isDecimalDigit(source.charCodeAt(index))) {
  2999. number += source[index++];
  3000. }
  3001. ch = source[index];
  3002. }
  3003. if (ch === 'e' || ch === 'E') {
  3004. number += source[index++];
  3005. ch = source[index];
  3006. if (ch === '+' || ch === '-') {
  3007. number += source[index++];
  3008. }
  3009. if (isDecimalDigit(source.charCodeAt(index))) {
  3010. while (isDecimalDigit(source.charCodeAt(index))) {
  3011. number += source[index++];
  3012. }
  3013. } else {
  3014. throwError({}, Messages.UnexpectedToken, 'ILLEGAL');
  3015. }
  3016. }
  3017. if (isIdentifierStart(source.charCodeAt(index))) {
  3018. throwError({}, Messages.UnexpectedToken, 'ILLEGAL');
  3019. }
  3020. return {
  3021. type: Token.NumericLiteral,
  3022. value: parseFloat(number),
  3023. lineNumber: lineNumber,
  3024. lineStart: lineStart,
  3025. range: [start, index]
  3026. };
  3027. }
  3028. // 7.8.4 String Literals
  3029. function scanStringLiteral() {
  3030. var str = '', quote, start, ch, code, unescaped, restore, octal = false;
  3031. quote = source[index];
  3032. assert((quote === '\'' || quote === '"'),
  3033. 'String literal must starts with a quote');
  3034. start = index;
  3035. ++index;
  3036. while (index < length) {
  3037. ch = source[index++];
  3038. if (ch === quote) {
  3039. quote = '';
  3040. break;
  3041. } else if (ch === '\\') {
  3042. ch = source[index++];
  3043. if (!ch || !isLineTerminator(ch.charCodeAt(0))) {
  3044. switch (ch) {
  3045. case 'n':
  3046. str += '\n';
  3047. break;
  3048. case 'r':
  3049. str += '\r';
  3050. break;
  3051. case 't':
  3052. str += '\t';
  3053. break;
  3054. case 'u':
  3055. case 'x':
  3056. if (source[index] === '{') {
  3057. ++index;
  3058. str += scanUnicodeCodePointEscape();
  3059. } else {
  3060. restore = index;
  3061. unescaped = scanHexEscape(ch);
  3062. if (unescaped) {
  3063. str += unescaped;
  3064. } else {
  3065. index = restore;
  3066. str += ch;
  3067. }
  3068. }
  3069. break;
  3070. case 'b':
  3071. str += '\b';
  3072. break;
  3073. case 'f':
  3074. str += '\f';
  3075. break;
  3076. case 'v':
  3077. str += '\x0B';
  3078. break;
  3079. default:
  3080. if (isOctalDigit(ch)) {
  3081. code = '01234567'.indexOf(ch);
  3082. // \0 is not octal escape sequence
  3083. if (code !== 0) {
  3084. octal = true;
  3085. }
  3086. /* istanbul ignore else */
  3087. if (index < length && isOctalDigit(source[index])) {
  3088. octal = true;
  3089. code = code * 8 + '01234567'.indexOf(source[index++]);
  3090. // 3 digits are only allowed when string starts
  3091. // with 0, 1, 2, 3
  3092. if ('0123'.indexOf(ch) >= 0 &&
  3093. index < length &&
  3094. isOctalDigit(source[index])) {
  3095. code = code * 8 + '01234567'.indexOf(source[index++]);
  3096. }
  3097. }
  3098. str += String.fromCharCode(code);
  3099. } else {
  3100. str += ch;
  3101. }
  3102. break;
  3103. }
  3104. } else {
  3105. ++lineNumber;
  3106. if (ch === '\r' && source[index] === '\n') {
  3107. ++index;
  3108. }
  3109. lineStart = index;
  3110. }
  3111. } else if (isLineTerminator(ch.charCodeAt(0))) {
  3112. break;
  3113. } else {
  3114. str += ch;
  3115. }
  3116. }
  3117. if (quote !== '') {
  3118. throwError({}, Messages.UnexpectedToken, 'ILLEGAL');
  3119. }
  3120. return {
  3121. type: Token.StringLiteral,
  3122. value: str,
  3123. octal: octal,
  3124. lineNumber: lineNumber,
  3125. lineStart: lineStart,
  3126. range: [start, index]
  3127. };
  3128. }
  3129. function scanTemplate() {
  3130. var cooked = '', ch, start, terminated, tail, restore, unescaped, code, octal;
  3131. terminated = false;
  3132. tail = false;
  3133. start = index;
  3134. ++index;
  3135. while (index < length) {
  3136. ch = source[index++];
  3137. if (ch === '`') {
  3138. tail = true;
  3139. terminated = true;
  3140. break;
  3141. } else if (ch === '$') {
  3142. if (source[index] === '{') {
  3143. ++index;
  3144. terminated = true;
  3145. break;
  3146. }
  3147. cooked += ch;
  3148. } else if (ch === '\\') {
  3149. ch = source[index++];
  3150. if (!isLineTerminator(ch.charCodeAt(0))) {
  3151. switch (ch) {
  3152. case 'n':
  3153. cooked += '\n';
  3154. break;
  3155. case 'r':
  3156. cooked += '\r';
  3157. break;
  3158. case 't':
  3159. cooked += '\t';
  3160. break;
  3161. case 'u':
  3162. case 'x':
  3163. if (source[index] === '{') {
  3164. ++index;
  3165. cooked += scanUnicodeCodePointEscape();
  3166. } else {
  3167. restore = index;
  3168. unescaped = scanHexEscape(ch);
  3169. if (unescaped) {
  3170. cooked += unescaped;
  3171. } else {
  3172. index = restore;
  3173. cooked += ch;
  3174. }
  3175. }
  3176. break;
  3177. case 'b':
  3178. cooked += '\b';
  3179. break;
  3180. case 'f':
  3181. cooked += '\f';
  3182. break;
  3183. case 'v':
  3184. cooked += '\v';
  3185. break;
  3186. default:
  3187. if (isOctalDigit(ch)) {
  3188. code = '01234567'.indexOf(ch);
  3189. // \0 is not octal escape sequence
  3190. if (code !== 0) {
  3191. octal = true;
  3192. }
  3193. /* istanbul ignore else */
  3194. if (index < length && isOctalDigit(source[index])) {
  3195. octal = true;
  3196. code = code * 8 + '01234567'.indexOf(source[index++]);
  3197. // 3 digits are only allowed when string starts
  3198. // with 0, 1, 2, 3
  3199. if ('0123'.indexOf(ch) >= 0 &&
  3200. index < length &&
  3201. isOctalDigit(source[index])) {
  3202. code = code * 8 + '01234567'.indexOf(source[index++]);
  3203. }
  3204. }
  3205. cooked += String.fromCharCode(code);
  3206. } else {
  3207. cooked += ch;
  3208. }
  3209. break;
  3210. }
  3211. } else {
  3212. ++lineNumber;
  3213. if (ch === '\r' && source[index] === '\n') {
  3214. ++index;
  3215. }
  3216. lineStart = index;
  3217. }
  3218. } else if (isLineTerminator(ch.charCodeAt(0))) {
  3219. ++lineNumber;
  3220. if (ch === '\r' && source[index] === '\n') {
  3221. ++index;
  3222. }
  3223. lineStart = index;
  3224. cooked += '\n';
  3225. } else {
  3226. cooked += ch;
  3227. }
  3228. }
  3229. if (!terminated) {
  3230. throwError({}, Messages.UnexpectedToken, 'ILLEGAL');
  3231. }
  3232. return {
  3233. type: Token.Template,
  3234. value: {
  3235. cooked: cooked,
  3236. raw: source.slice(start + 1, index - ((tail) ? 1 : 2))
  3237. },
  3238. tail: tail,
  3239. octal: octal,
  3240. lineNumber: lineNumber,
  3241. lineStart: lineStart,
  3242. range: [start, index]
  3243. };
  3244. }
  3245. function scanTemplateElement(option) {
  3246. var startsWith, template;
  3247. lookahead = null;
  3248. skipComment();
  3249. startsWith = (option.head) ? '`' : '}';
  3250. if (source[index] !== startsWith) {
  3251. throwError({}, Messages.UnexpectedToken, 'ILLEGAL');
  3252. }
  3253. template = scanTemplate();
  3254. peek();
  3255. return template;
  3256. }
  3257. function testRegExp(pattern, flags) {
  3258. var tmp = pattern,
  3259. value;
  3260. if (flags.indexOf('u') >= 0) {
  3261. // Replace each astral symbol and every Unicode code point
  3262. // escape sequence with a single ASCII symbol to avoid throwing on
  3263. // regular expressions that are only valid in combination with the
  3264. // `/u` flag.
  3265. // Note: replacing with the ASCII symbol `x` might cause false
  3266. // negatives in unlikely scenarios. For example, `[\u{61}-b]` is a
  3267. // perfectly valid pattern that is equivalent to `[a-b]`, but it
  3268. // would be replaced by `[x-b]` which throws an error.
  3269. tmp = tmp
  3270. .replace(/\\u\{([0-9a-fA-F]+)\}/g, function ($0, $1) {
  3271. if (parseInt($1, 16) <= 0x10FFFF) {
  3272. return 'x';
  3273. }
  3274. throwError({}, Messages.InvalidRegExp);
  3275. })
  3276. .replace(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g, 'x');
  3277. }
  3278. // First, detect invalid regular expressions.
  3279. try {
  3280. value = new RegExp(tmp);
  3281. } catch (e) {
  3282. throwError({}, Messages.InvalidRegExp);
  3283. }
  3284. // Return a regular expression object for this pattern-flag pair, or
  3285. // `null` in case the current environment doesn't support the flags it
  3286. // uses.
  3287. try {
  3288. return new RegExp(pattern, flags);
  3289. } catch (exception) {
  3290. return null;
  3291. }
  3292. }
  3293. function scanRegExpBody() {
  3294. var ch, str, classMarker, terminated, body;
  3295. ch = source[index];
  3296. assert(ch === '/', 'Regular expression literal must start with a slash');
  3297. str = source[index++];
  3298. classMarker = false;
  3299. terminated = false;
  3300. while (index < length) {
  3301. ch = source[index++];
  3302. str += ch;
  3303. if (ch === '\\') {
  3304. ch = source[index++];
  3305. // ECMA-262 7.8.5
  3306. if (isLineTerminator(ch.charCodeAt(0))) {
  3307. throwError({}, Messages.UnterminatedRegExp);
  3308. }
  3309. str += ch;
  3310. } else if (isLineTerminator(ch.charCodeAt(0))) {
  3311. throwError({}, Messages.UnterminatedRegExp);
  3312. } else if (classMarker) {
  3313. if (ch === ']') {
  3314. classMarker = false;
  3315. }
  3316. } else {
  3317. if (ch === '/') {
  3318. terminated = true;
  3319. break;
  3320. } else if (ch === '[') {
  3321. classMarker = true;
  3322. }
  3323. }
  3324. }
  3325. if (!terminated) {
  3326. throwError({}, Messages.UnterminatedRegExp);
  3327. }
  3328. // Exclude leading and trailing slash.
  3329. body = str.substr(1, str.length - 2);
  3330. return {
  3331. value: body,
  3332. literal: str
  3333. };
  3334. }
  3335. function scanRegExpFlags() {
  3336. var ch, str, flags, restore;
  3337. str = '';
  3338. flags = '';
  3339. while (index < length) {
  3340. ch = source[index];
  3341. if (!isIdentifierPart(ch.charCodeAt(0))) {
  3342. break;
  3343. }
  3344. ++index;
  3345. if (ch === '\\' && index < length) {
  3346. ch = source[index];
  3347. if (ch === 'u') {
  3348. ++index;
  3349. restore = index;
  3350. ch = scanHexEscape('u');
  3351. if (ch) {
  3352. flags += ch;
  3353. for (str += '\\u'; restore < index; ++restore) {
  3354. str += source[restore];
  3355. }
  3356. } else {
  3357. index = restore;
  3358. flags += 'u';
  3359. str += '\\u';
  3360. }
  3361. throwErrorTolerant({}, Messages.UnexpectedToken, 'ILLEGAL');
  3362. } else {
  3363. str += '\\';
  3364. throwErrorTolerant({}, Messages.UnexpectedToken, 'ILLEGAL');
  3365. }
  3366. } else {
  3367. flags += ch;
  3368. str += ch;
  3369. }
  3370. }
  3371. return {
  3372. value: flags,
  3373. literal: str
  3374. };
  3375. }
  3376. function scanRegExp() {
  3377. var start, body, flags, value;
  3378. lookahead = null;
  3379. skipComment();
  3380. start = index;
  3381. body = scanRegExpBody();
  3382. flags = scanRegExpFlags();
  3383. value = testRegExp(body.value, flags.value);
  3384. if (extra.tokenize) {
  3385. return {
  3386. type: Token.RegularExpression,
  3387. value: value,
  3388. regex: {
  3389. pattern: body.value,
  3390. flags: flags.value
  3391. },
  3392. lineNumber: lineNumber,
  3393. lineStart: lineStart,
  3394. range: [start, index]
  3395. };
  3396. }
  3397. return {
  3398. literal: body.literal + flags.literal,
  3399. value: value,
  3400. regex: {
  3401. pattern: body.value,
  3402. flags: flags.value
  3403. },
  3404. range: [start, index]
  3405. };
  3406. }
  3407. function isIdentifierName(token) {
  3408. return token.type === Token.Identifier ||
  3409. token.type === Token.Keyword ||
  3410. token.type === Token.BooleanLiteral ||
  3411. token.type === Token.NullLiteral;
  3412. }
  3413. function advanceSlash() {
  3414. var prevToken,
  3415. checkToken;
  3416. // Using the following algorithm:
  3417. // https://github.com/mozilla/sweet.js/wiki/design
  3418. prevToken = extra.tokens[extra.tokens.length - 1];
  3419. if (!prevToken) {
  3420. // Nothing before that: it cannot be a division.
  3421. return scanRegExp();
  3422. }
  3423. if (prevToken.type === 'Punctuator') {
  3424. if (prevToken.value === ')') {
  3425. checkToken = extra.tokens[extra.openParenToken - 1];
  3426. if (checkToken &&
  3427. checkToken.type === 'Keyword' &&
  3428. (checkToken.value === 'if' ||
  3429. checkToken.value === 'while' ||
  3430. checkToken.value === 'for' ||
  3431. checkToken.value === 'with')) {
  3432. return scanRegExp();
  3433. }
  3434. return scanPunctuator();
  3435. }
  3436. if (prevToken.value === '}') {
  3437. // Dividing a function by anything makes little sense,
  3438. // but we have to check for that.
  3439. if (extra.tokens[extra.openCurlyToken - 3] &&
  3440. extra.tokens[extra.openCurlyToken - 3].type === 'Keyword') {
  3441. // Anonymous function.
  3442. checkToken = extra.tokens[extra.openCurlyToken - 4];
  3443. if (!checkToken) {
  3444. return scanPunctuator();
  3445. }
  3446. } else if (extra.tokens[extra.openCurlyToken - 4] &&
  3447. extra.tokens[extra.openCurlyToken - 4].type === 'Keyword') {
  3448. // Named function.
  3449. checkToken = extra.tokens[extra.openCurlyToken - 5];
  3450. if (!checkToken) {
  3451. return scanRegExp();
  3452. }
  3453. } else {
  3454. return scanPunctuator();
  3455. }
  3456. // checkToken determines whether the function is
  3457. // a declaration or an expression.
  3458. if (FnExprTokens.indexOf(checkToken.value) >= 0) {
  3459. // It is an expression.
  3460. return scanPunctuator();
  3461. }
  3462. // It is a declaration.
  3463. return scanRegExp();
  3464. }
  3465. return scanRegExp();
  3466. }
  3467. if (prevToken.type === 'Keyword' && prevToken.value !== 'this') {
  3468. return scanRegExp();
  3469. }
  3470. return scanPunctuator();
  3471. }
  3472. function advance() {
  3473. var ch;
  3474. if (!state.inJSXChild) {
  3475. skipComment();
  3476. }
  3477. if (index >= length) {
  3478. return {
  3479. type: Token.EOF,
  3480. lineNumber: lineNumber,
  3481. lineStart: lineStart,
  3482. range: [index, index]
  3483. };
  3484. }
  3485. if (state.inJSXChild) {
  3486. return advanceJSXChild();
  3487. }
  3488. ch = source.charCodeAt(index);
  3489. // Very common: ( and ) and ;
  3490. if (ch === 40 || ch === 41 || ch === 58) {
  3491. return scanPunctuator();
  3492. }
  3493. // String literal starts with single quote (#39) or double quote (#34).
  3494. if (ch === 39 || ch === 34) {
  3495. if (state.inJSXTag) {
  3496. return scanJSXStringLiteral();
  3497. }
  3498. return scanStringLiteral();
  3499. }
  3500. if (state.inJSXTag && isJSXIdentifierStart(ch)) {
  3501. return scanJSXIdentifier();
  3502. }
  3503. if (ch === 96) {
  3504. return scanTemplate();
  3505. }
  3506. if (isIdentifierStart(ch)) {
  3507. return scanIdentifier();
  3508. }
  3509. // Dot (.) char #46 can also start a floating-point number, hence the need
  3510. // to check the next character.
  3511. if (ch === 46) {
  3512. if (isDecimalDigit(source.charCodeAt(index + 1))) {
  3513. return scanNumericLiteral();
  3514. }
  3515. return scanPunctuator();
  3516. }
  3517. if (isDecimalDigit(ch)) {
  3518. return scanNumericLiteral();
  3519. }
  3520. // Slash (/) char #47 can also start a regex.
  3521. if (extra.tokenize && ch === 47) {
  3522. return advanceSlash();
  3523. }
  3524. return scanPunctuator();
  3525. }
  3526. function lex() {
  3527. var token;
  3528. token = lookahead;
  3529. index = token.range[1];
  3530. lineNumber = token.lineNumber;
  3531. lineStart = token.lineStart;
  3532. lookahead = advance();
  3533. index = token.range[1];
  3534. lineNumber = token.lineNumber;
  3535. lineStart = token.lineStart;
  3536. return token;
  3537. }
  3538. function peek() {
  3539. var pos, line, start;
  3540. pos = index;
  3541. line = lineNumber;
  3542. start = lineStart;
  3543. lookahead = advance();
  3544. index = pos;
  3545. lineNumber = line;
  3546. lineStart = start;
  3547. }
  3548. function lookahead2() {
  3549. var adv, pos, line, start, result;
  3550. // If we are collecting the tokens, don't grab the next one yet.
  3551. /* istanbul ignore next */
  3552. adv = (typeof extra.advance === 'function') ? extra.advance : advance;
  3553. pos = index;
  3554. line = lineNumber;
  3555. start = lineStart;
  3556. // Scan for the next immediate token.
  3557. /* istanbul ignore if */
  3558. if (lookahead === null) {
  3559. lookahead = adv();
  3560. }
  3561. index = lookahead.range[1];
  3562. lineNumber = lookahead.lineNumber;
  3563. lineStart = lookahead.lineStart;
  3564. // Grab the token right after.
  3565. result = adv();
  3566. index = pos;
  3567. lineNumber = line;
  3568. lineStart = start;
  3569. return result;
  3570. }
  3571. function rewind(token) {
  3572. index = token.range[0];
  3573. lineNumber = token.lineNumber;
  3574. lineStart = token.lineStart;
  3575. lookahead = token;
  3576. }
  3577. function markerCreate() {
  3578. if (!extra.loc && !extra.range) {
  3579. return undefined;
  3580. }
  3581. skipComment();
  3582. return {offset: index, line: lineNumber, col: index - lineStart};
  3583. }
  3584. function markerCreatePreserveWhitespace() {
  3585. if (!extra.loc && !extra.range) {
  3586. return undefined;
  3587. }
  3588. return {offset: index, line: lineNumber, col: index - lineStart};
  3589. }
  3590. function processComment(node) {
  3591. var lastChild,
  3592. trailingComments,
  3593. bottomRight = extra.bottomRightStack,
  3594. last = bottomRight[bottomRight.length - 1];
  3595. if (node.type === Syntax.Program) {
  3596. /* istanbul ignore else */
  3597. if (node.body.length > 0) {
  3598. return;
  3599. }
  3600. }
  3601. if (extra.trailingComments.length > 0) {
  3602. if (extra.trailingComments[0].range[0] >= node.range[1]) {
  3603. trailingComments = extra.trailingComments;
  3604. extra.trailingComments = [];
  3605. } else {
  3606. extra.trailingComments.length = 0;
  3607. }
  3608. } else {
  3609. if (last && last.trailingComments && last.trailingComments[0].range[0] >= node.range[1]) {
  3610. trailingComments = last.trailingComments;
  3611. delete last.trailingComments;
  3612. }
  3613. }
  3614. // Eating the stack.
  3615. if (last) {
  3616. while (last && last.range[0] >= node.range[0]) {
  3617. lastChild = last;
  3618. last = bottomRight.pop();
  3619. }
  3620. }
  3621. if (lastChild) {
  3622. if (lastChild.leadingComments && lastChild.leadingComments[lastChild.leadingComments.length - 1].range[1] <= node.range[0]) {
  3623. node.leadingComments = lastChild.leadingComments;
  3624. delete lastChild.leadingComments;
  3625. }
  3626. } else if (extra.leadingComments.length > 0 && extra.leadingComments[extra.leadingComments.length - 1].range[1] <= node.range[0]) {
  3627. node.leadingComments = extra.leadingComments;
  3628. extra.leadingComments = [];
  3629. }
  3630. if (trailingComments) {
  3631. node.trailingComments = trailingComments;
  3632. }
  3633. bottomRight.push(node);
  3634. }
  3635. function markerApply(marker, node) {
  3636. if (extra.range) {
  3637. node.range = [marker.offset, index];
  3638. }
  3639. if (extra.loc) {
  3640. node.loc = {
  3641. start: {
  3642. line: marker.line,
  3643. column: marker.col
  3644. },
  3645. end: {
  3646. line: lineNumber,
  3647. column: index - lineStart
  3648. }
  3649. };
  3650. node = delegate.postProcess(node);
  3651. }
  3652. if (extra.attachComment) {
  3653. processComment(node);
  3654. }
  3655. return node;
  3656. }
  3657. SyntaxTreeDelegate = {
  3658. name: 'SyntaxTree',
  3659. postProcess: function (node) {
  3660. return node;
  3661. },
  3662. createArrayExpression: function (elements) {
  3663. return {
  3664. type: Syntax.ArrayExpression,
  3665. elements: elements
  3666. };
  3667. },
  3668. createAssignmentExpression: function (operator, left, right) {
  3669. return {
  3670. type: Syntax.AssignmentExpression,
  3671. operator: operator,
  3672. left: left,
  3673. right: right
  3674. };
  3675. },
  3676. createBinaryExpression: function (operator, left, right) {
  3677. var type = (operator === '||' || operator === '&&') ? Syntax.LogicalExpression :
  3678. Syntax.BinaryExpression;
  3679. return {
  3680. type: type,
  3681. operator: operator,
  3682. left: left,
  3683. right: right
  3684. };
  3685. },
  3686. createBlockStatement: function (body) {
  3687. return {
  3688. type: Syntax.BlockStatement,
  3689. body: body
  3690. };
  3691. },
  3692. createBreakStatement: function (label) {
  3693. return {
  3694. type: Syntax.BreakStatement,
  3695. label: label
  3696. };
  3697. },
  3698. createCallExpression: function (callee, args) {
  3699. return {
  3700. type: Syntax.CallExpression,
  3701. callee: callee,
  3702. 'arguments': args
  3703. };
  3704. },
  3705. createCatchClause: function (param, body) {
  3706. return {
  3707. type: Syntax.CatchClause,
  3708. param: param,
  3709. body: body
  3710. };
  3711. },
  3712. createConditionalExpression: function (test, consequent, alternate) {
  3713. return {
  3714. type: Syntax.ConditionalExpression,
  3715. test: test,
  3716. consequent: consequent,
  3717. alternate: alternate
  3718. };
  3719. },
  3720. createContinueStatement: function (label) {
  3721. return {
  3722. type: Syntax.ContinueStatement,
  3723. label: label
  3724. };
  3725. },
  3726. createDebuggerStatement: function () {
  3727. return {
  3728. type: Syntax.DebuggerStatement
  3729. };
  3730. },
  3731. createDoWhileStatement: function (body, test) {
  3732. return {
  3733. type: Syntax.DoWhileStatement,
  3734. body: body,
  3735. test: test
  3736. };
  3737. },
  3738. createEmptyStatement: function () {
  3739. return {
  3740. type: Syntax.EmptyStatement
  3741. };
  3742. },
  3743. createExpressionStatement: function (expression) {
  3744. return {
  3745. type: Syntax.ExpressionStatement,
  3746. expression: expression
  3747. };
  3748. },
  3749. createForStatement: function (init, test, update, body) {
  3750. return {
  3751. type: Syntax.ForStatement,
  3752. init: init,
  3753. test: test,
  3754. update: update,
  3755. body: body
  3756. };
  3757. },
  3758. createForInStatement: function (left, right, body) {
  3759. return {
  3760. type: Syntax.ForInStatement,
  3761. left: left,
  3762. right: right,
  3763. body: body,
  3764. each: false
  3765. };
  3766. },
  3767. createForOfStatement: function (left, right, body) {
  3768. return {
  3769. type: Syntax.ForOfStatement,
  3770. left: left,
  3771. right: right,
  3772. body: body
  3773. };
  3774. },
  3775. createFunctionDeclaration: function (id, params, defaults, body, rest, generator, expression,
  3776. isAsync, returnType, typeParameters) {
  3777. var funDecl = {
  3778. type: Syntax.FunctionDeclaration,
  3779. id: id,
  3780. params: params,
  3781. defaults: defaults,
  3782. body: body,
  3783. rest: rest,
  3784. generator: generator,
  3785. expression: expression,
  3786. returnType: returnType,
  3787. typeParameters: typeParameters
  3788. };
  3789. if (isAsync) {
  3790. funDecl.async = true;
  3791. }
  3792. return funDecl;
  3793. },
  3794. createFunctionExpression: function (id, params, defaults, body, rest, generator, expression,
  3795. isAsync, returnType, typeParameters) {
  3796. var funExpr = {
  3797. type: Syntax.FunctionExpression,
  3798. id: id,
  3799. params: params,
  3800. defaults: defaults,
  3801. body: body,
  3802. rest: rest,
  3803. generator: generator,
  3804. expression: expression,
  3805. returnType: returnType,
  3806. typeParameters: typeParameters
  3807. };
  3808. if (isAsync) {
  3809. funExpr.async = true;
  3810. }
  3811. return funExpr;
  3812. },
  3813. createIdentifier: function (name) {
  3814. return {
  3815. type: Syntax.Identifier,
  3816. name: name,
  3817. // Only here to initialize the shape of the object to ensure
  3818. // that the 'typeAnnotation' key is ordered before others that
  3819. // are added later (like 'loc' and 'range'). This just helps
  3820. // keep the shape of Identifier nodes consistent with everything
  3821. // else.
  3822. typeAnnotation: undefined,
  3823. optional: undefined
  3824. };
  3825. },
  3826. createTypeAnnotation: function (typeAnnotation) {
  3827. return {
  3828. type: Syntax.TypeAnnotation,
  3829. typeAnnotation: typeAnnotation
  3830. };
  3831. },
  3832. createTypeCast: function (expression, typeAnnotation) {
  3833. return {
  3834. type: Syntax.TypeCastExpression,
  3835. expression: expression,
  3836. typeAnnotation: typeAnnotation
  3837. };
  3838. },
  3839. createFunctionTypeAnnotation: function (params, returnType, rest, typeParameters) {
  3840. return {
  3841. type: Syntax.FunctionTypeAnnotation,
  3842. params: params,
  3843. returnType: returnType,
  3844. rest: rest,
  3845. typeParameters: typeParameters
  3846. };
  3847. },
  3848. createFunctionTypeParam: function (name, typeAnnotation, optional) {
  3849. return {
  3850. type: Syntax.FunctionTypeParam,
  3851. name: name,
  3852. typeAnnotation: typeAnnotation,
  3853. optional: optional
  3854. };
  3855. },
  3856. createNullableTypeAnnotation: function (typeAnnotation) {
  3857. return {
  3858. type: Syntax.NullableTypeAnnotation,
  3859. typeAnnotation: typeAnnotation
  3860. };
  3861. },
  3862. createArrayTypeAnnotation: function (elementType) {
  3863. return {
  3864. type: Syntax.ArrayTypeAnnotation,
  3865. elementType: elementType
  3866. };
  3867. },
  3868. createGenericTypeAnnotation: function (id, typeParameters) {
  3869. return {
  3870. type: Syntax.GenericTypeAnnotation,
  3871. id: id,
  3872. typeParameters: typeParameters
  3873. };
  3874. },
  3875. createQualifiedTypeIdentifier: function (qualification, id) {
  3876. return {
  3877. type: Syntax.QualifiedTypeIdentifier,
  3878. qualification: qualification,
  3879. id: id
  3880. };
  3881. },
  3882. createTypeParameterDeclaration: function (params) {
  3883. return {
  3884. type: Syntax.TypeParameterDeclaration,
  3885. params: params
  3886. };
  3887. },
  3888. createTypeParameterInstantiation: function (params) {
  3889. return {
  3890. type: Syntax.TypeParameterInstantiation,
  3891. params: params
  3892. };
  3893. },
  3894. createAnyTypeAnnotation: function () {
  3895. return {
  3896. type: Syntax.AnyTypeAnnotation
  3897. };
  3898. },
  3899. createBooleanTypeAnnotation: function () {
  3900. return {
  3901. type: Syntax.BooleanTypeAnnotation
  3902. };
  3903. },
  3904. createNumberTypeAnnotation: function () {
  3905. return {
  3906. type: Syntax.NumberTypeAnnotation
  3907. };
  3908. },
  3909. createStringTypeAnnotation: function () {
  3910. return {
  3911. type: Syntax.StringTypeAnnotation
  3912. };
  3913. },
  3914. createStringLiteralTypeAnnotation: function (token) {
  3915. return {
  3916. type: Syntax.StringLiteralTypeAnnotation,
  3917. value: token.value,
  3918. raw: source.slice(token.range[0], token.range[1])
  3919. };
  3920. },
  3921. createVoidTypeAnnotation: function () {
  3922. return {
  3923. type: Syntax.VoidTypeAnnotation
  3924. };
  3925. },
  3926. createTypeofTypeAnnotation: function (argument) {
  3927. return {
  3928. type: Syntax.TypeofTypeAnnotation,
  3929. argument: argument
  3930. };
  3931. },
  3932. createTupleTypeAnnotation: function (types) {
  3933. return {
  3934. type: Syntax.TupleTypeAnnotation,
  3935. types: types
  3936. };
  3937. },
  3938. createObjectTypeAnnotation: function (properties, indexers, callProperties) {
  3939. return {
  3940. type: Syntax.ObjectTypeAnnotation,
  3941. properties: properties,
  3942. indexers: indexers,
  3943. callProperties: callProperties
  3944. };
  3945. },
  3946. createObjectTypeIndexer: function (id, key, value, isStatic) {
  3947. return {
  3948. type: Syntax.ObjectTypeIndexer,
  3949. id: id,
  3950. key: key,
  3951. value: value,
  3952. "static": isStatic
  3953. };
  3954. },
  3955. createObjectTypeCallProperty: function (value, isStatic) {
  3956. return {
  3957. type: Syntax.ObjectTypeCallProperty,
  3958. value: value,
  3959. "static": isStatic
  3960. };
  3961. },
  3962. createObjectTypeProperty: function (key, value, optional, isStatic) {
  3963. return {
  3964. type: Syntax.ObjectTypeProperty,
  3965. key: key,
  3966. value: value,
  3967. optional: optional,
  3968. "static": isStatic
  3969. };
  3970. },
  3971. createUnionTypeAnnotation: function (types) {
  3972. return {
  3973. type: Syntax.UnionTypeAnnotation,
  3974. types: types
  3975. };
  3976. },
  3977. createIntersectionTypeAnnotation: function (types) {
  3978. return {
  3979. type: Syntax.IntersectionTypeAnnotation,
  3980. types: types
  3981. };
  3982. },
  3983. createTypeAlias: function (id, typeParameters, right) {
  3984. return {
  3985. type: Syntax.TypeAlias,
  3986. id: id,
  3987. typeParameters: typeParameters,
  3988. right: right
  3989. };
  3990. },
  3991. createInterface: function (id, typeParameters, body, extended) {
  3992. return {
  3993. type: Syntax.InterfaceDeclaration,
  3994. id: id,
  3995. typeParameters: typeParameters,
  3996. body: body,
  3997. "extends": extended
  3998. };
  3999. },
  4000. createInterfaceExtends: function (id, typeParameters) {
  4001. return {
  4002. type: Syntax.InterfaceExtends,
  4003. id: id,
  4004. typeParameters: typeParameters
  4005. };
  4006. },
  4007. createDeclareFunction: function (id) {
  4008. return {
  4009. type: Syntax.DeclareFunction,
  4010. id: id
  4011. };
  4012. },
  4013. createDeclareVariable: function (id) {
  4014. return {
  4015. type: Syntax.DeclareVariable,
  4016. id: id
  4017. };
  4018. },
  4019. createDeclareModule: function (id, body) {
  4020. return {
  4021. type: Syntax.DeclareModule,
  4022. id: id,
  4023. body: body
  4024. };
  4025. },
  4026. createJSXAttribute: function (name, value) {
  4027. return {
  4028. type: Syntax.JSXAttribute,
  4029. name: name,
  4030. value: value || null
  4031. };
  4032. },
  4033. createJSXSpreadAttribute: function (argument) {
  4034. return {
  4035. type: Syntax.JSXSpreadAttribute,
  4036. argument: argument
  4037. };
  4038. },
  4039. createJSXIdentifier: function (name) {
  4040. return {
  4041. type: Syntax.JSXIdentifier,
  4042. name: name
  4043. };
  4044. },
  4045. createJSXNamespacedName: function (namespace, name) {
  4046. return {
  4047. type: Syntax.JSXNamespacedName,
  4048. namespace: namespace,
  4049. name: name
  4050. };
  4051. },
  4052. createJSXMemberExpression: function (object, property) {
  4053. return {
  4054. type: Syntax.JSXMemberExpression,
  4055. object: object,
  4056. property: property
  4057. };
  4058. },
  4059. createJSXElement: function (openingElement, closingElement, children) {
  4060. return {
  4061. type: Syntax.JSXElement,
  4062. openingElement: openingElement,
  4063. closingElement: closingElement,
  4064. children: children
  4065. };
  4066. },
  4067. createJSXEmptyExpression: function () {
  4068. return {
  4069. type: Syntax.JSXEmptyExpression
  4070. };
  4071. },
  4072. createJSXExpressionContainer: function (expression) {
  4073. return {
  4074. type: Syntax.JSXExpressionContainer,
  4075. expression: expression
  4076. };
  4077. },
  4078. createJSXOpeningElement: function (name, attributes, selfClosing) {
  4079. return {
  4080. type: Syntax.JSXOpeningElement,
  4081. name: name,
  4082. selfClosing: selfClosing,
  4083. attributes: attributes
  4084. };
  4085. },
  4086. createJSXClosingElement: function (name) {
  4087. return {
  4088. type: Syntax.JSXClosingElement,
  4089. name: name
  4090. };
  4091. },
  4092. createIfStatement: function (test, consequent, alternate) {
  4093. return {
  4094. type: Syntax.IfStatement,
  4095. test: test,
  4096. consequent: consequent,
  4097. alternate: alternate
  4098. };
  4099. },
  4100. createLabeledStatement: function (label, body) {
  4101. return {
  4102. type: Syntax.LabeledStatement,
  4103. label: label,
  4104. body: body
  4105. };
  4106. },
  4107. createLiteral: function (token) {
  4108. var object = {
  4109. type: Syntax.Literal,
  4110. value: token.value,
  4111. raw: source.slice(token.range[0], token.range[1])
  4112. };
  4113. if (token.regex) {
  4114. object.regex = token.regex;
  4115. }
  4116. return object;
  4117. },
  4118. createMemberExpression: function (accessor, object, property) {
  4119. return {
  4120. type: Syntax.MemberExpression,
  4121. computed: accessor === '[',
  4122. object: object,
  4123. property: property
  4124. };
  4125. },
  4126. createNewExpression: function (callee, args) {
  4127. return {
  4128. type: Syntax.NewExpression,
  4129. callee: callee,
  4130. 'arguments': args
  4131. };
  4132. },
  4133. createObjectExpression: function (properties) {
  4134. return {
  4135. type: Syntax.ObjectExpression,
  4136. properties: properties
  4137. };
  4138. },
  4139. createPostfixExpression: function (operator, argument) {
  4140. return {
  4141. type: Syntax.UpdateExpression,
  4142. operator: operator,
  4143. argument: argument,
  4144. prefix: false
  4145. };
  4146. },
  4147. createProgram: function (body) {
  4148. return {
  4149. type: Syntax.Program,
  4150. body: body
  4151. };
  4152. },
  4153. createProperty: function (kind, key, value, method, shorthand, computed) {
  4154. return {
  4155. type: Syntax.Property,
  4156. key: key,
  4157. value: value,
  4158. kind: kind,
  4159. method: method,
  4160. shorthand: shorthand,
  4161. computed: computed
  4162. };
  4163. },
  4164. createReturnStatement: function (argument) {
  4165. return {
  4166. type: Syntax.ReturnStatement,
  4167. argument: argument
  4168. };
  4169. },
  4170. createSequenceExpression: function (expressions) {
  4171. return {
  4172. type: Syntax.SequenceExpression,
  4173. expressions: expressions
  4174. };
  4175. },
  4176. createSwitchCase: function (test, consequent) {
  4177. return {
  4178. type: Syntax.SwitchCase,
  4179. test: test,
  4180. consequent: consequent
  4181. };
  4182. },
  4183. createSwitchStatement: function (discriminant, cases) {
  4184. return {
  4185. type: Syntax.SwitchStatement,
  4186. discriminant: discriminant,
  4187. cases: cases
  4188. };
  4189. },
  4190. createThisExpression: function () {
  4191. return {
  4192. type: Syntax.ThisExpression
  4193. };
  4194. },
  4195. createThrowStatement: function (argument) {
  4196. return {
  4197. type: Syntax.ThrowStatement,
  4198. argument: argument
  4199. };
  4200. },
  4201. createTryStatement: function (block, guardedHandlers, handlers, finalizer) {
  4202. return {
  4203. type: Syntax.TryStatement,
  4204. block: block,
  4205. guardedHandlers: guardedHandlers,
  4206. handlers: handlers,
  4207. finalizer: finalizer
  4208. };
  4209. },
  4210. createUnaryExpression: function (operator, argument) {
  4211. if (operator === '++' || operator === '--') {
  4212. return {
  4213. type: Syntax.UpdateExpression,
  4214. operator: operator,
  4215. argument: argument,
  4216. prefix: true
  4217. };
  4218. }
  4219. return {
  4220. type: Syntax.UnaryExpression,
  4221. operator: operator,
  4222. argument: argument,
  4223. prefix: true
  4224. };
  4225. },
  4226. createVariableDeclaration: function (declarations, kind) {
  4227. return {
  4228. type: Syntax.VariableDeclaration,
  4229. declarations: declarations,
  4230. kind: kind
  4231. };
  4232. },
  4233. createVariableDeclarator: function (id, init) {
  4234. return {
  4235. type: Syntax.VariableDeclarator,
  4236. id: id,
  4237. init: init
  4238. };
  4239. },
  4240. createWhileStatement: function (test, body) {
  4241. return {
  4242. type: Syntax.WhileStatement,
  4243. test: test,
  4244. body: body
  4245. };
  4246. },
  4247. createWithStatement: function (object, body) {
  4248. return {
  4249. type: Syntax.WithStatement,
  4250. object: object,
  4251. body: body
  4252. };
  4253. },
  4254. createTemplateElement: function (value, tail) {
  4255. return {
  4256. type: Syntax.TemplateElement,
  4257. value: value,
  4258. tail: tail
  4259. };
  4260. },
  4261. createTemplateLiteral: function (quasis, expressions) {
  4262. return {
  4263. type: Syntax.TemplateLiteral,
  4264. quasis: quasis,
  4265. expressions: expressions
  4266. };
  4267. },
  4268. createSpreadElement: function (argument) {
  4269. return {
  4270. type: Syntax.SpreadElement,
  4271. argument: argument
  4272. };
  4273. },
  4274. createSpreadProperty: function (argument) {
  4275. return {
  4276. type: Syntax.SpreadProperty,
  4277. argument: argument
  4278. };
  4279. },
  4280. createTaggedTemplateExpression: function (tag, quasi) {
  4281. return {
  4282. type: Syntax.TaggedTemplateExpression,
  4283. tag: tag,
  4284. quasi: quasi
  4285. };
  4286. },
  4287. createArrowFunctionExpression: function (params, defaults, body, rest, expression, isAsync) {
  4288. var arrowExpr = {
  4289. type: Syntax.ArrowFunctionExpression,
  4290. id: null,
  4291. params: params,
  4292. defaults: defaults,
  4293. body: body,
  4294. rest: rest,
  4295. generator: false,
  4296. expression: expression
  4297. };
  4298. if (isAsync) {
  4299. arrowExpr.async = true;
  4300. }
  4301. return arrowExpr;
  4302. },
  4303. createMethodDefinition: function (propertyType, kind, key, value, computed) {
  4304. return {
  4305. type: Syntax.MethodDefinition,
  4306. key: key,
  4307. value: value,
  4308. kind: kind,
  4309. 'static': propertyType === ClassPropertyType["static"],
  4310. computed: computed
  4311. };
  4312. },
  4313. createClassProperty: function (key, typeAnnotation, computed, isStatic) {
  4314. return {
  4315. type: Syntax.ClassProperty,
  4316. key: key,
  4317. typeAnnotation: typeAnnotation,
  4318. computed: computed,
  4319. "static": isStatic
  4320. };
  4321. },
  4322. createClassBody: function (body) {
  4323. return {
  4324. type: Syntax.ClassBody,
  4325. body: body
  4326. };
  4327. },
  4328. createClassImplements: function (id, typeParameters) {
  4329. return {
  4330. type: Syntax.ClassImplements,
  4331. id: id,
  4332. typeParameters: typeParameters
  4333. };
  4334. },
  4335. createClassExpression: function (id, superClass, body, typeParameters, superTypeParameters, implemented) {
  4336. return {
  4337. type: Syntax.ClassExpression,
  4338. id: id,
  4339. superClass: superClass,
  4340. body: body,
  4341. typeParameters: typeParameters,
  4342. superTypeParameters: superTypeParameters,
  4343. "implements": implemented
  4344. };
  4345. },
  4346. createClassDeclaration: function (id, superClass, body, typeParameters, superTypeParameters, implemented) {
  4347. return {
  4348. type: Syntax.ClassDeclaration,
  4349. id: id,
  4350. superClass: superClass,
  4351. body: body,
  4352. typeParameters: typeParameters,
  4353. superTypeParameters: superTypeParameters,
  4354. "implements": implemented
  4355. };
  4356. },
  4357. createModuleSpecifier: function (token) {
  4358. return {
  4359. type: Syntax.ModuleSpecifier,
  4360. value: token.value,
  4361. raw: source.slice(token.range[0], token.range[1])
  4362. };
  4363. },
  4364. createExportSpecifier: function (id, name) {
  4365. return {
  4366. type: Syntax.ExportSpecifier,
  4367. id: id,
  4368. name: name
  4369. };
  4370. },
  4371. createExportBatchSpecifier: function () {
  4372. return {
  4373. type: Syntax.ExportBatchSpecifier
  4374. };
  4375. },
  4376. createImportDefaultSpecifier: function (id) {
  4377. return {
  4378. type: Syntax.ImportDefaultSpecifier,
  4379. id: id
  4380. };
  4381. },
  4382. createImportNamespaceSpecifier: function (id) {
  4383. return {
  4384. type: Syntax.ImportNamespaceSpecifier,
  4385. id: id
  4386. };
  4387. },
  4388. createExportDeclaration: function (isDefault, declaration, specifiers, src) {
  4389. return {
  4390. type: Syntax.ExportDeclaration,
  4391. 'default': !!isDefault,
  4392. declaration: declaration,
  4393. specifiers: specifiers,
  4394. source: src
  4395. };
  4396. },
  4397. createImportSpecifier: function (id, name) {
  4398. return {
  4399. type: Syntax.ImportSpecifier,
  4400. id: id,
  4401. name: name
  4402. };
  4403. },
  4404. createImportDeclaration: function (specifiers, src, isType) {
  4405. return {
  4406. type: Syntax.ImportDeclaration,
  4407. specifiers: specifiers,
  4408. source: src,
  4409. isType: isType
  4410. };
  4411. },
  4412. createYieldExpression: function (argument, dlg) {
  4413. return {
  4414. type: Syntax.YieldExpression,
  4415. argument: argument,
  4416. delegate: dlg
  4417. };
  4418. },
  4419. createAwaitExpression: function (argument) {
  4420. return {
  4421. type: Syntax.AwaitExpression,
  4422. argument: argument
  4423. };
  4424. },
  4425. createComprehensionExpression: function (filter, blocks, body) {
  4426. return {
  4427. type: Syntax.ComprehensionExpression,
  4428. filter: filter,
  4429. blocks: blocks,
  4430. body: body
  4431. };
  4432. }
  4433. };
  4434. // Return true if there is a line terminator before the next token.
  4435. function peekLineTerminator() {
  4436. var pos, line, start, found;
  4437. pos = index;
  4438. line = lineNumber;
  4439. start = lineStart;
  4440. skipComment();
  4441. found = lineNumber !== line;
  4442. index = pos;
  4443. lineNumber = line;
  4444. lineStart = start;
  4445. return found;
  4446. }
  4447. // Throw an exception
  4448. function throwError(token, messageFormat) {
  4449. var error,
  4450. args = Array.prototype.slice.call(arguments, 2),
  4451. msg = messageFormat.replace(
  4452. /%(\d)/g,
  4453. function (whole, idx) {
  4454. assert(idx < args.length, 'Message reference must be in range');
  4455. return args[idx];
  4456. }
  4457. );
  4458. if (typeof token.lineNumber === 'number') {
  4459. error = new Error('Line ' + token.lineNumber + ': ' + msg);
  4460. error.index = token.range[0];
  4461. error.lineNumber = token.lineNumber;
  4462. error.column = token.range[0] - lineStart + 1;
  4463. } else {
  4464. error = new Error('Line ' + lineNumber + ': ' + msg);
  4465. error.index = index;
  4466. error.lineNumber = lineNumber;
  4467. error.column = index - lineStart + 1;
  4468. }
  4469. error.description = msg;
  4470. throw error;
  4471. }
  4472. function throwErrorTolerant() {
  4473. try {
  4474. throwError.apply(null, arguments);
  4475. } catch (e) {
  4476. if (extra.errors) {
  4477. extra.errors.push(e);
  4478. } else {
  4479. throw e;
  4480. }
  4481. }
  4482. }
  4483. // Throw an exception because of the token.
  4484. function throwUnexpected(token) {
  4485. if (token.type === Token.EOF) {
  4486. throwError(token, Messages.UnexpectedEOS);
  4487. }
  4488. if (token.type === Token.NumericLiteral) {
  4489. throwError(token, Messages.UnexpectedNumber);
  4490. }
  4491. if (token.type === Token.StringLiteral || token.type === Token.JSXText) {
  4492. throwError(token, Messages.UnexpectedString);
  4493. }
  4494. if (token.type === Token.Identifier) {
  4495. throwError(token, Messages.UnexpectedIdentifier);
  4496. }
  4497. if (token.type === Token.Keyword) {
  4498. if (isFutureReservedWord(token.value)) {
  4499. throwError(token, Messages.UnexpectedReserved);
  4500. } else if (strict && isStrictModeReservedWord(token.value)) {
  4501. throwErrorTolerant(token, Messages.StrictReservedWord);
  4502. return;
  4503. }
  4504. throwError(token, Messages.UnexpectedToken, token.value);
  4505. }
  4506. if (token.type === Token.Template) {
  4507. throwError(token, Messages.UnexpectedTemplate, token.value.raw);
  4508. }
  4509. // BooleanLiteral, NullLiteral, or Punctuator.
  4510. throwError(token, Messages.UnexpectedToken, token.value);
  4511. }
  4512. // Expect the next token to match the specified punctuator.
  4513. // If not, an exception will be thrown.
  4514. function expect(value) {
  4515. var token = lex();
  4516. if (token.type !== Token.Punctuator || token.value !== value) {
  4517. throwUnexpected(token);
  4518. }
  4519. }
  4520. // Expect the next token to match the specified keyword.
  4521. // If not, an exception will be thrown.
  4522. function expectKeyword(keyword, contextual) {
  4523. var token = lex();
  4524. if (token.type !== (contextual ? Token.Identifier : Token.Keyword) ||
  4525. token.value !== keyword) {
  4526. throwUnexpected(token);
  4527. }
  4528. }
  4529. // Expect the next token to match the specified contextual keyword.
  4530. // If not, an exception will be thrown.
  4531. function expectContextualKeyword(keyword) {
  4532. return expectKeyword(keyword, true);
  4533. }
  4534. // Return true if the next token matches the specified punctuator.
  4535. function match(value) {
  4536. return lookahead.type === Token.Punctuator && lookahead.value === value;
  4537. }
  4538. // Return true if the next token matches the specified keyword
  4539. function matchKeyword(keyword, contextual) {
  4540. var expectedType = contextual ? Token.Identifier : Token.Keyword;
  4541. return lookahead.type === expectedType && lookahead.value === keyword;
  4542. }
  4543. // Return true if the next token matches the specified contextual keyword
  4544. function matchContextualKeyword(keyword) {
  4545. return matchKeyword(keyword, true);
  4546. }
  4547. // Return true if the next token is an assignment operator
  4548. function matchAssign() {
  4549. var op;
  4550. if (lookahead.type !== Token.Punctuator) {
  4551. return false;
  4552. }
  4553. op = lookahead.value;
  4554. return op === '=' ||
  4555. op === '*=' ||
  4556. op === '/=' ||
  4557. op === '%=' ||
  4558. op === '+=' ||
  4559. op === '-=' ||
  4560. op === '<<=' ||
  4561. op === '>>=' ||
  4562. op === '>>>=' ||
  4563. op === '&=' ||
  4564. op === '^=' ||
  4565. op === '|=';
  4566. }
  4567. // Note that 'yield' is treated as a keyword in strict mode, but a
  4568. // contextual keyword (identifier) in non-strict mode, so we need to
  4569. // use matchKeyword('yield', false) and matchKeyword('yield', true)
  4570. // (i.e. matchContextualKeyword) appropriately.
  4571. function matchYield() {
  4572. return state.yieldAllowed && matchKeyword('yield', !strict);
  4573. }
  4574. function matchAsync() {
  4575. var backtrackToken = lookahead, matches = false;
  4576. if (matchContextualKeyword('async')) {
  4577. lex(); // Make sure peekLineTerminator() starts after 'async'.
  4578. matches = !peekLineTerminator();
  4579. rewind(backtrackToken); // Revert the lex().
  4580. }
  4581. return matches;
  4582. }
  4583. function matchAwait() {
  4584. return state.awaitAllowed && matchContextualKeyword('await');
  4585. }
  4586. function consumeSemicolon() {
  4587. var line, oldIndex = index, oldLineNumber = lineNumber,
  4588. oldLineStart = lineStart, oldLookahead = lookahead;
  4589. // Catch the very common case first: immediately a semicolon (char #59).
  4590. if (source.charCodeAt(index) === 59) {
  4591. lex();
  4592. return;
  4593. }
  4594. line = lineNumber;
  4595. skipComment();
  4596. if (lineNumber !== line) {
  4597. index = oldIndex;
  4598. lineNumber = oldLineNumber;
  4599. lineStart = oldLineStart;
  4600. lookahead = oldLookahead;
  4601. return;
  4602. }
  4603. if (match(';')) {
  4604. lex();
  4605. return;
  4606. }
  4607. if (lookahead.type !== Token.EOF && !match('}')) {
  4608. throwUnexpected(lookahead);
  4609. }
  4610. }
  4611. // Return true if provided expression is LeftHandSideExpression
  4612. function isLeftHandSide(expr) {
  4613. return expr.type === Syntax.Identifier || expr.type === Syntax.MemberExpression;
  4614. }
  4615. function isAssignableLeftHandSide(expr) {
  4616. return isLeftHandSide(expr) || expr.type === Syntax.ObjectPattern || expr.type === Syntax.ArrayPattern;
  4617. }
  4618. // 11.1.4 Array Initialiser
  4619. function parseArrayInitialiser() {
  4620. var elements = [], blocks = [], filter = null, tmp, possiblecomprehension = true,
  4621. marker = markerCreate();
  4622. expect('[');
  4623. while (!match(']')) {
  4624. if (lookahead.value === 'for' &&
  4625. lookahead.type === Token.Keyword) {
  4626. if (!possiblecomprehension) {
  4627. throwError({}, Messages.ComprehensionError);
  4628. }
  4629. matchKeyword('for');
  4630. tmp = parseForStatement({ignoreBody: true});
  4631. tmp.of = tmp.type === Syntax.ForOfStatement;
  4632. tmp.type = Syntax.ComprehensionBlock;
  4633. if (tmp.left.kind) { // can't be let or const
  4634. throwError({}, Messages.ComprehensionError);
  4635. }
  4636. blocks.push(tmp);
  4637. } else if (lookahead.value === 'if' &&
  4638. lookahead.type === Token.Keyword) {
  4639. if (!possiblecomprehension) {
  4640. throwError({}, Messages.ComprehensionError);
  4641. }
  4642. expectKeyword('if');
  4643. expect('(');
  4644. filter = parseExpression();
  4645. expect(')');
  4646. } else if (lookahead.value === ',' &&
  4647. lookahead.type === Token.Punctuator) {
  4648. possiblecomprehension = false; // no longer allowed.
  4649. lex();
  4650. elements.push(null);
  4651. } else {
  4652. tmp = parseSpreadOrAssignmentExpression();
  4653. elements.push(tmp);
  4654. if (tmp && tmp.type === Syntax.SpreadElement) {
  4655. if (!match(']')) {
  4656. throwError({}, Messages.ElementAfterSpreadElement);
  4657. }
  4658. } else if (!(match(']') || matchKeyword('for') || matchKeyword('if'))) {
  4659. expect(','); // this lexes.
  4660. possiblecomprehension = false;
  4661. }
  4662. }
  4663. }
  4664. expect(']');
  4665. if (filter && !blocks.length) {
  4666. throwError({}, Messages.ComprehensionRequiresBlock);
  4667. }
  4668. if (blocks.length) {
  4669. if (elements.length !== 1) {
  4670. throwError({}, Messages.ComprehensionError);
  4671. }
  4672. return markerApply(marker, delegate.createComprehensionExpression(filter, blocks, elements[0]));
  4673. }
  4674. return markerApply(marker, delegate.createArrayExpression(elements));
  4675. }
  4676. // 11.1.5 Object Initialiser
  4677. function parsePropertyFunction(options) {
  4678. var previousStrict, previousYieldAllowed, previousAwaitAllowed,
  4679. params, defaults, body, marker = markerCreate();
  4680. previousStrict = strict;
  4681. previousYieldAllowed = state.yieldAllowed;
  4682. state.yieldAllowed = options.generator;
  4683. previousAwaitAllowed = state.awaitAllowed;
  4684. state.awaitAllowed = options.async;
  4685. params = options.params || [];
  4686. defaults = options.defaults || [];
  4687. body = parseConciseBody();
  4688. if (options.name && strict && isRestrictedWord(params[0].name)) {
  4689. throwErrorTolerant(options.name, Messages.StrictParamName);
  4690. }
  4691. strict = previousStrict;
  4692. state.yieldAllowed = previousYieldAllowed;
  4693. state.awaitAllowed = previousAwaitAllowed;
  4694. return markerApply(marker, delegate.createFunctionExpression(
  4695. null,
  4696. params,
  4697. defaults,
  4698. body,
  4699. options.rest || null,
  4700. options.generator,
  4701. body.type !== Syntax.BlockStatement,
  4702. options.async,
  4703. options.returnType,
  4704. options.typeParameters
  4705. ));
  4706. }
  4707. function parsePropertyMethodFunction(options) {
  4708. var previousStrict, tmp, method;
  4709. previousStrict = strict;
  4710. strict = true;
  4711. tmp = parseParams();
  4712. if (tmp.stricted) {
  4713. throwErrorTolerant(tmp.stricted, tmp.message);
  4714. }
  4715. method = parsePropertyFunction({
  4716. params: tmp.params,
  4717. defaults: tmp.defaults,
  4718. rest: tmp.rest,
  4719. generator: options.generator,
  4720. async: options.async,
  4721. returnType: tmp.returnType,
  4722. typeParameters: options.typeParameters
  4723. });
  4724. strict = previousStrict;
  4725. return method;
  4726. }
  4727. function parseObjectPropertyKey() {
  4728. var marker = markerCreate(),
  4729. token = lex(),
  4730. propertyKey,
  4731. result;
  4732. // Note: This function is called only from parseObjectProperty(), where
  4733. // EOF and Punctuator tokens are already filtered out.
  4734. if (token.type === Token.StringLiteral || token.type === Token.NumericLiteral) {
  4735. if (strict && token.octal) {
  4736. throwErrorTolerant(token, Messages.StrictOctalLiteral);
  4737. }
  4738. return markerApply(marker, delegate.createLiteral(token));
  4739. }
  4740. if (token.type === Token.Punctuator && token.value === '[') {
  4741. // For computed properties we should skip the [ and ], and
  4742. // capture in marker only the assignment expression itself.
  4743. marker = markerCreate();
  4744. propertyKey = parseAssignmentExpression();
  4745. result = markerApply(marker, propertyKey);
  4746. expect(']');
  4747. return result;
  4748. }
  4749. return markerApply(marker, delegate.createIdentifier(token.value));
  4750. }
  4751. function parseObjectProperty() {
  4752. var token, key, id, param, computed,
  4753. marker = markerCreate(), returnType, typeParameters;
  4754. token = lookahead;
  4755. computed = (token.value === '[' && token.type === Token.Punctuator);
  4756. if (token.type === Token.Identifier || computed || matchAsync()) {
  4757. id = parseObjectPropertyKey();
  4758. if (match(':')) {
  4759. lex();
  4760. return markerApply(
  4761. marker,
  4762. delegate.createProperty(
  4763. 'init',
  4764. id,
  4765. parseAssignmentExpression(),
  4766. false,
  4767. false,
  4768. computed
  4769. )
  4770. );
  4771. }
  4772. if (match('(') || match('<')) {
  4773. if (match('<')) {
  4774. typeParameters = parseTypeParameterDeclaration();
  4775. }
  4776. return markerApply(
  4777. marker,
  4778. delegate.createProperty(
  4779. 'init',
  4780. id,
  4781. parsePropertyMethodFunction({
  4782. generator: false,
  4783. async: false,
  4784. typeParameters: typeParameters
  4785. }),
  4786. true,
  4787. false,
  4788. computed
  4789. )
  4790. );
  4791. }
  4792. // Property Assignment: Getter and Setter.
  4793. if (token.value === 'get') {
  4794. computed = (lookahead.value === '[');
  4795. key = parseObjectPropertyKey();
  4796. expect('(');
  4797. expect(')');
  4798. if (match(':')) {
  4799. returnType = parseTypeAnnotation();
  4800. }
  4801. return markerApply(
  4802. marker,
  4803. delegate.createProperty(
  4804. 'get',
  4805. key,
  4806. parsePropertyFunction({
  4807. generator: false,
  4808. async: false,
  4809. returnType: returnType
  4810. }),
  4811. false,
  4812. false,
  4813. computed
  4814. )
  4815. );
  4816. }
  4817. if (token.value === 'set') {
  4818. computed = (lookahead.value === '[');
  4819. key = parseObjectPropertyKey();
  4820. expect('(');
  4821. token = lookahead;
  4822. param = [ parseTypeAnnotatableIdentifier() ];
  4823. expect(')');
  4824. if (match(':')) {
  4825. returnType = parseTypeAnnotation();
  4826. }
  4827. return markerApply(
  4828. marker,
  4829. delegate.createProperty(
  4830. 'set',
  4831. key,
  4832. parsePropertyFunction({
  4833. params: param,
  4834. generator: false,
  4835. async: false,
  4836. name: token,
  4837. returnType: returnType
  4838. }),
  4839. false,
  4840. false,
  4841. computed
  4842. )
  4843. );
  4844. }
  4845. if (token.value === 'async') {
  4846. computed = (lookahead.value === '[');
  4847. key = parseObjectPropertyKey();
  4848. if (match('<')) {
  4849. typeParameters = parseTypeParameterDeclaration();
  4850. }
  4851. return markerApply(
  4852. marker,
  4853. delegate.createProperty(
  4854. 'init',
  4855. key,
  4856. parsePropertyMethodFunction({
  4857. generator: false,
  4858. async: true,
  4859. typeParameters: typeParameters
  4860. }),
  4861. true,
  4862. false,
  4863. computed
  4864. )
  4865. );
  4866. }
  4867. if (computed) {
  4868. // Computed properties can only be used with full notation.
  4869. throwUnexpected(lookahead);
  4870. }
  4871. return markerApply(
  4872. marker,
  4873. delegate.createProperty('init', id, id, false, true, false)
  4874. );
  4875. }
  4876. if (token.type === Token.EOF || token.type === Token.Punctuator) {
  4877. if (!match('*')) {
  4878. throwUnexpected(token);
  4879. }
  4880. lex();
  4881. computed = (lookahead.type === Token.Punctuator && lookahead.value === '[');
  4882. id = parseObjectPropertyKey();
  4883. if (match('<')) {
  4884. typeParameters = parseTypeParameterDeclaration();
  4885. }
  4886. if (!match('(')) {
  4887. throwUnexpected(lex());
  4888. }
  4889. return markerApply(marker, delegate.createProperty(
  4890. 'init',
  4891. id,
  4892. parsePropertyMethodFunction({
  4893. generator: true,
  4894. typeParameters: typeParameters
  4895. }),
  4896. true,
  4897. false,
  4898. computed
  4899. ));
  4900. }
  4901. key = parseObjectPropertyKey();
  4902. if (match(':')) {
  4903. lex();
  4904. return markerApply(marker, delegate.createProperty('init', key, parseAssignmentExpression(), false, false, false));
  4905. }
  4906. if (match('(') || match('<')) {
  4907. if (match('<')) {
  4908. typeParameters = parseTypeParameterDeclaration();
  4909. }
  4910. return markerApply(marker, delegate.createProperty(
  4911. 'init',
  4912. key,
  4913. parsePropertyMethodFunction({
  4914. generator: false,
  4915. typeParameters: typeParameters
  4916. }),
  4917. true,
  4918. false,
  4919. false
  4920. ));
  4921. }
  4922. throwUnexpected(lex());
  4923. }
  4924. function parseObjectSpreadProperty() {
  4925. var marker = markerCreate();
  4926. expect('...');
  4927. return markerApply(marker, delegate.createSpreadProperty(parseAssignmentExpression()));
  4928. }
  4929. function getFieldName(key) {
  4930. var toString = String;
  4931. if (key.type === Syntax.Identifier) {
  4932. return key.name;
  4933. }
  4934. return toString(key.value);
  4935. }
  4936. function parseObjectInitialiser() {
  4937. var properties = [], property, name, kind, storedKind, map = new StringMap(),
  4938. marker = markerCreate(), toString = String;
  4939. expect('{');
  4940. while (!match('}')) {
  4941. if (match('...')) {
  4942. property = parseObjectSpreadProperty();
  4943. } else {
  4944. property = parseObjectProperty();
  4945. if (property.key.type === Syntax.Identifier) {
  4946. name = property.key.name;
  4947. } else {
  4948. name = toString(property.key.value);
  4949. }
  4950. kind = (property.kind === 'init') ? PropertyKind.Data : (property.kind === 'get') ? PropertyKind.Get : PropertyKind.Set;
  4951. if (map.has(name)) {
  4952. storedKind = map.get(name);
  4953. if (storedKind === PropertyKind.Data) {
  4954. if (strict && kind === PropertyKind.Data) {
  4955. throwErrorTolerant({}, Messages.StrictDuplicateProperty);
  4956. } else if (kind !== PropertyKind.Data) {
  4957. throwErrorTolerant({}, Messages.AccessorDataProperty);
  4958. }
  4959. } else {
  4960. if (kind === PropertyKind.Data) {
  4961. throwErrorTolerant({}, Messages.AccessorDataProperty);
  4962. } else if (storedKind & kind) {
  4963. throwErrorTolerant({}, Messages.AccessorGetSet);
  4964. }
  4965. }
  4966. map.set(name, storedKind | kind);
  4967. } else {
  4968. map.set(name, kind);
  4969. }
  4970. }
  4971. properties.push(property);
  4972. if (!match('}')) {
  4973. expect(',');
  4974. }
  4975. }
  4976. expect('}');
  4977. return markerApply(marker, delegate.createObjectExpression(properties));
  4978. }
  4979. function parseTemplateElement(option) {
  4980. var marker = markerCreate(),
  4981. token = scanTemplateElement(option);
  4982. if (strict && token.octal) {
  4983. throwError(token, Messages.StrictOctalLiteral);
  4984. }
  4985. return markerApply(marker, delegate.createTemplateElement({ raw: token.value.raw, cooked: token.value.cooked }, token.tail));
  4986. }
  4987. function parseTemplateLiteral() {
  4988. var quasi, quasis, expressions, marker = markerCreate();
  4989. quasi = parseTemplateElement({ head: true });
  4990. quasis = [ quasi ];
  4991. expressions = [];
  4992. while (!quasi.tail) {
  4993. expressions.push(parseExpression());
  4994. quasi = parseTemplateElement({ head: false });
  4995. quasis.push(quasi);
  4996. }
  4997. return markerApply(marker, delegate.createTemplateLiteral(quasis, expressions));
  4998. }
  4999. // 11.1.6 The Grouping Operator
  5000. function parseGroupExpression() {
  5001. var expr, marker, typeAnnotation;
  5002. expect('(');
  5003. ++state.parenthesizedCount;
  5004. marker = markerCreate();
  5005. expr = parseExpression();
  5006. if (match(':')) {
  5007. typeAnnotation = parseTypeAnnotation();
  5008. expr = markerApply(marker, delegate.createTypeCast(
  5009. expr,
  5010. typeAnnotation
  5011. ));
  5012. }
  5013. expect(')');
  5014. return expr;
  5015. }
  5016. function matchAsyncFuncExprOrDecl() {
  5017. var token;
  5018. if (matchAsync()) {
  5019. token = lookahead2();
  5020. if (token.type === Token.Keyword && token.value === 'function') {
  5021. return true;
  5022. }
  5023. }
  5024. return false;
  5025. }
  5026. // 11.1 Primary Expressions
  5027. function parsePrimaryExpression() {
  5028. var marker, type, token, expr;
  5029. type = lookahead.type;
  5030. if (type === Token.Identifier) {
  5031. marker = markerCreate();
  5032. return markerApply(marker, delegate.createIdentifier(lex().value));
  5033. }
  5034. if (type === Token.StringLiteral || type === Token.NumericLiteral) {
  5035. if (strict && lookahead.octal) {
  5036. throwErrorTolerant(lookahead, Messages.StrictOctalLiteral);
  5037. }
  5038. marker = markerCreate();
  5039. return markerApply(marker, delegate.createLiteral(lex()));
  5040. }
  5041. if (type === Token.Keyword) {
  5042. if (matchKeyword('this')) {
  5043. marker = markerCreate();
  5044. lex();
  5045. return markerApply(marker, delegate.createThisExpression());
  5046. }
  5047. if (matchKeyword('function')) {
  5048. return parseFunctionExpression();
  5049. }
  5050. if (matchKeyword('class')) {
  5051. return parseClassExpression();
  5052. }
  5053. if (matchKeyword('super')) {
  5054. marker = markerCreate();
  5055. lex();
  5056. return markerApply(marker, delegate.createIdentifier('super'));
  5057. }
  5058. }
  5059. if (type === Token.BooleanLiteral) {
  5060. marker = markerCreate();
  5061. token = lex();
  5062. token.value = (token.value === 'true');
  5063. return markerApply(marker, delegate.createLiteral(token));
  5064. }
  5065. if (type === Token.NullLiteral) {
  5066. marker = markerCreate();
  5067. token = lex();
  5068. token.value = null;
  5069. return markerApply(marker, delegate.createLiteral(token));
  5070. }
  5071. if (match('[')) {
  5072. return parseArrayInitialiser();
  5073. }
  5074. if (match('{')) {
  5075. return parseObjectInitialiser();
  5076. }
  5077. if (match('(')) {
  5078. return parseGroupExpression();
  5079. }
  5080. if (match('/') || match('/=')) {
  5081. marker = markerCreate();
  5082. expr = delegate.createLiteral(scanRegExp());
  5083. peek();
  5084. return markerApply(marker, expr);
  5085. }
  5086. if (type === Token.Template) {
  5087. return parseTemplateLiteral();
  5088. }
  5089. if (match('<')) {
  5090. return parseJSXElement();
  5091. }
  5092. throwUnexpected(lex());
  5093. }
  5094. // 11.2 Left-Hand-Side Expressions
  5095. function parseArguments() {
  5096. var args = [], arg;
  5097. expect('(');
  5098. if (!match(')')) {
  5099. while (index < length) {
  5100. arg = parseSpreadOrAssignmentExpression();
  5101. args.push(arg);
  5102. if (match(')')) {
  5103. break;
  5104. } else if (arg.type === Syntax.SpreadElement) {
  5105. throwError({}, Messages.ElementAfterSpreadElement);
  5106. }
  5107. expect(',');
  5108. }
  5109. }
  5110. expect(')');
  5111. return args;
  5112. }
  5113. function parseSpreadOrAssignmentExpression() {
  5114. if (match('...')) {
  5115. var marker = markerCreate();
  5116. lex();
  5117. return markerApply(marker, delegate.createSpreadElement(parseAssignmentExpression()));
  5118. }
  5119. return parseAssignmentExpression();
  5120. }
  5121. function parseNonComputedProperty() {
  5122. var marker = markerCreate(),
  5123. token = lex();
  5124. if (!isIdentifierName(token)) {
  5125. throwUnexpected(token);
  5126. }
  5127. return markerApply(marker, delegate.createIdentifier(token.value));
  5128. }
  5129. function parseNonComputedMember() {
  5130. expect('.');
  5131. return parseNonComputedProperty();
  5132. }
  5133. function parseComputedMember() {
  5134. var expr;
  5135. expect('[');
  5136. expr = parseExpression();
  5137. expect(']');
  5138. return expr;
  5139. }
  5140. function parseNewExpression() {
  5141. var callee, args, marker = markerCreate();
  5142. expectKeyword('new');
  5143. callee = parseLeftHandSideExpression();
  5144. args = match('(') ? parseArguments() : [];
  5145. return markerApply(marker, delegate.createNewExpression(callee, args));
  5146. }
  5147. function parseLeftHandSideExpressionAllowCall() {
  5148. var expr, args, marker = markerCreate();
  5149. expr = matchKeyword('new') ? parseNewExpression() : parsePrimaryExpression();
  5150. while (match('.') || match('[') || match('(') || lookahead.type === Token.Template) {
  5151. if (match('(')) {
  5152. args = parseArguments();
  5153. expr = markerApply(marker, delegate.createCallExpression(expr, args));
  5154. } else if (match('[')) {
  5155. expr = markerApply(marker, delegate.createMemberExpression('[', expr, parseComputedMember()));
  5156. } else if (match('.')) {
  5157. expr = markerApply(marker, delegate.createMemberExpression('.', expr, parseNonComputedMember()));
  5158. } else {
  5159. expr = markerApply(marker, delegate.createTaggedTemplateExpression(expr, parseTemplateLiteral()));
  5160. }
  5161. }
  5162. return expr;
  5163. }
  5164. function parseLeftHandSideExpression() {
  5165. var expr, marker = markerCreate();
  5166. expr = matchKeyword('new') ? parseNewExpression() : parsePrimaryExpression();
  5167. while (match('.') || match('[') || lookahead.type === Token.Template) {
  5168. if (match('[')) {
  5169. expr = markerApply(marker, delegate.createMemberExpression('[', expr, parseComputedMember()));
  5170. } else if (match('.')) {
  5171. expr = markerApply(marker, delegate.createMemberExpression('.', expr, parseNonComputedMember()));
  5172. } else {
  5173. expr = markerApply(marker, delegate.createTaggedTemplateExpression(expr, parseTemplateLiteral()));
  5174. }
  5175. }
  5176. return expr;
  5177. }
  5178. // 11.3 Postfix Expressions
  5179. function parsePostfixExpression() {
  5180. var marker = markerCreate(),
  5181. expr = parseLeftHandSideExpressionAllowCall(),
  5182. token;
  5183. if (lookahead.type !== Token.Punctuator) {
  5184. return expr;
  5185. }
  5186. if ((match('++') || match('--')) && !peekLineTerminator()) {
  5187. // 11.3.1, 11.3.2
  5188. if (strict && expr.type === Syntax.Identifier && isRestrictedWord(expr.name)) {
  5189. throwErrorTolerant({}, Messages.StrictLHSPostfix);
  5190. }
  5191. if (!isLeftHandSide(expr)) {
  5192. throwError({}, Messages.InvalidLHSInAssignment);
  5193. }
  5194. token = lex();
  5195. expr = markerApply(marker, delegate.createPostfixExpression(token.value, expr));
  5196. }
  5197. return expr;
  5198. }
  5199. // 11.4 Unary Operators
  5200. function parseUnaryExpression() {
  5201. var marker, token, expr;
  5202. if (lookahead.type !== Token.Punctuator && lookahead.type !== Token.Keyword) {
  5203. return parsePostfixExpression();
  5204. }
  5205. if (match('++') || match('--')) {
  5206. marker = markerCreate();
  5207. token = lex();
  5208. expr = parseUnaryExpression();
  5209. // 11.4.4, 11.4.5
  5210. if (strict && expr.type === Syntax.Identifier && isRestrictedWord(expr.name)) {
  5211. throwErrorTolerant({}, Messages.StrictLHSPrefix);
  5212. }
  5213. if (!isLeftHandSide(expr)) {
  5214. throwError({}, Messages.InvalidLHSInAssignment);
  5215. }
  5216. return markerApply(marker, delegate.createUnaryExpression(token.value, expr));
  5217. }
  5218. if (match('+') || match('-') || match('~') || match('!')) {
  5219. marker = markerCreate();
  5220. token = lex();
  5221. expr = parseUnaryExpression();
  5222. return markerApply(marker, delegate.createUnaryExpression(token.value, expr));
  5223. }
  5224. if (matchKeyword('delete') || matchKeyword('void') || matchKeyword('typeof')) {
  5225. marker = markerCreate();
  5226. token = lex();
  5227. expr = parseUnaryExpression();
  5228. expr = markerApply(marker, delegate.createUnaryExpression(token.value, expr));
  5229. if (strict && expr.operator === 'delete' && expr.argument.type === Syntax.Identifier) {
  5230. throwErrorTolerant({}, Messages.StrictDelete);
  5231. }
  5232. return expr;
  5233. }
  5234. return parsePostfixExpression();
  5235. }
  5236. function binaryPrecedence(token, allowIn) {
  5237. var prec = 0;
  5238. if (token.type !== Token.Punctuator && token.type !== Token.Keyword) {
  5239. return 0;
  5240. }
  5241. switch (token.value) {
  5242. case '||':
  5243. prec = 1;
  5244. break;
  5245. case '&&':
  5246. prec = 2;
  5247. break;
  5248. case '|':
  5249. prec = 3;
  5250. break;
  5251. case '^':
  5252. prec = 4;
  5253. break;
  5254. case '&':
  5255. prec = 5;
  5256. break;
  5257. case '==':
  5258. case '!=':
  5259. case '===':
  5260. case '!==':
  5261. prec = 6;
  5262. break;
  5263. case '<':
  5264. case '>':
  5265. case '<=':
  5266. case '>=':
  5267. case 'instanceof':
  5268. prec = 7;
  5269. break;
  5270. case 'in':
  5271. prec = allowIn ? 7 : 0;
  5272. break;
  5273. case '<<':
  5274. case '>>':
  5275. case '>>>':
  5276. prec = 8;
  5277. break;
  5278. case '+':
  5279. case '-':
  5280. prec = 9;
  5281. break;
  5282. case '*':
  5283. case '/':
  5284. case '%':
  5285. prec = 11;
  5286. break;
  5287. default:
  5288. break;
  5289. }
  5290. return prec;
  5291. }
  5292. // 11.5 Multiplicative Operators
  5293. // 11.6 Additive Operators
  5294. // 11.7 Bitwise Shift Operators
  5295. // 11.8 Relational Operators
  5296. // 11.9 Equality Operators
  5297. // 11.10 Binary Bitwise Operators
  5298. // 11.11 Binary Logical Operators
  5299. function parseBinaryExpression() {
  5300. var expr, token, prec, previousAllowIn, stack, right, operator, left, i,
  5301. marker, markers;
  5302. previousAllowIn = state.allowIn;
  5303. state.allowIn = true;
  5304. marker = markerCreate();
  5305. left = parseUnaryExpression();
  5306. token = lookahead;
  5307. prec = binaryPrecedence(token, previousAllowIn);
  5308. if (prec === 0) {
  5309. return left;
  5310. }
  5311. token.prec = prec;
  5312. lex();
  5313. markers = [marker, markerCreate()];
  5314. right = parseUnaryExpression();
  5315. stack = [left, token, right];
  5316. while ((prec = binaryPrecedence(lookahead, previousAllowIn)) > 0) {
  5317. // Reduce: make a binary expression from the three topmost entries.
  5318. while ((stack.length > 2) && (prec <= stack[stack.length - 2].prec)) {
  5319. right = stack.pop();
  5320. operator = stack.pop().value;
  5321. left = stack.pop();
  5322. expr = delegate.createBinaryExpression(operator, left, right);
  5323. markers.pop();
  5324. marker = markers.pop();
  5325. markerApply(marker, expr);
  5326. stack.push(expr);
  5327. markers.push(marker);
  5328. }
  5329. // Shift.
  5330. token = lex();
  5331. token.prec = prec;
  5332. stack.push(token);
  5333. markers.push(markerCreate());
  5334. expr = parseUnaryExpression();
  5335. stack.push(expr);
  5336. }
  5337. state.allowIn = previousAllowIn;
  5338. // Final reduce to clean-up the stack.
  5339. i = stack.length - 1;
  5340. expr = stack[i];
  5341. markers.pop();
  5342. while (i > 1) {
  5343. expr = delegate.createBinaryExpression(stack[i - 1].value, stack[i - 2], expr);
  5344. i -= 2;
  5345. marker = markers.pop();
  5346. markerApply(marker, expr);
  5347. }
  5348. return expr;
  5349. }
  5350. // 11.12 Conditional Operator
  5351. function parseConditionalExpression() {
  5352. var expr, previousAllowIn, consequent, alternate, marker = markerCreate();
  5353. expr = parseBinaryExpression();
  5354. if (match('?')) {
  5355. lex();
  5356. previousAllowIn = state.allowIn;
  5357. state.allowIn = true;
  5358. consequent = parseAssignmentExpression();
  5359. state.allowIn = previousAllowIn;
  5360. expect(':');
  5361. alternate = parseAssignmentExpression();
  5362. expr = markerApply(marker, delegate.createConditionalExpression(expr, consequent, alternate));
  5363. }
  5364. return expr;
  5365. }
  5366. // 11.13 Assignment Operators
  5367. // 12.14.5 AssignmentPattern
  5368. function reinterpretAsAssignmentBindingPattern(expr) {
  5369. var i, len, property, element;
  5370. if (expr.type === Syntax.ObjectExpression) {
  5371. expr.type = Syntax.ObjectPattern;
  5372. for (i = 0, len = expr.properties.length; i < len; i += 1) {
  5373. property = expr.properties[i];
  5374. if (property.type === Syntax.SpreadProperty) {
  5375. if (i < len - 1) {
  5376. throwError({}, Messages.PropertyAfterSpreadProperty);
  5377. }
  5378. reinterpretAsAssignmentBindingPattern(property.argument);
  5379. } else {
  5380. if (property.kind !== 'init') {
  5381. throwError({}, Messages.InvalidLHSInAssignment);
  5382. }
  5383. reinterpretAsAssignmentBindingPattern(property.value);
  5384. }
  5385. }
  5386. } else if (expr.type === Syntax.ArrayExpression) {
  5387. expr.type = Syntax.ArrayPattern;
  5388. for (i = 0, len = expr.elements.length; i < len; i += 1) {
  5389. element = expr.elements[i];
  5390. /* istanbul ignore else */
  5391. if (element) {
  5392. reinterpretAsAssignmentBindingPattern(element);
  5393. }
  5394. }
  5395. } else if (expr.type === Syntax.Identifier) {
  5396. if (isRestrictedWord(expr.name)) {
  5397. throwError({}, Messages.InvalidLHSInAssignment);
  5398. }
  5399. } else if (expr.type === Syntax.SpreadElement) {
  5400. reinterpretAsAssignmentBindingPattern(expr.argument);
  5401. if (expr.argument.type === Syntax.ObjectPattern) {
  5402. throwError({}, Messages.ObjectPatternAsSpread);
  5403. }
  5404. } else {
  5405. /* istanbul ignore else */
  5406. if (expr.type !== Syntax.MemberExpression && expr.type !== Syntax.CallExpression && expr.type !== Syntax.NewExpression) {
  5407. throwError({}, Messages.InvalidLHSInAssignment);
  5408. }
  5409. }
  5410. }
  5411. // 13.2.3 BindingPattern
  5412. function reinterpretAsDestructuredParameter(options, expr) {
  5413. var i, len, property, element;
  5414. if (expr.type === Syntax.ObjectExpression) {
  5415. expr.type = Syntax.ObjectPattern;
  5416. for (i = 0, len = expr.properties.length; i < len; i += 1) {
  5417. property = expr.properties[i];
  5418. if (property.type === Syntax.SpreadProperty) {
  5419. if (i < len - 1) {
  5420. throwError({}, Messages.PropertyAfterSpreadProperty);
  5421. }
  5422. reinterpretAsDestructuredParameter(options, property.argument);
  5423. } else {
  5424. if (property.kind !== 'init') {
  5425. throwError({}, Messages.InvalidLHSInFormalsList);
  5426. }
  5427. reinterpretAsDestructuredParameter(options, property.value);
  5428. }
  5429. }
  5430. } else if (expr.type === Syntax.ArrayExpression) {
  5431. expr.type = Syntax.ArrayPattern;
  5432. for (i = 0, len = expr.elements.length; i < len; i += 1) {
  5433. element = expr.elements[i];
  5434. if (element) {
  5435. reinterpretAsDestructuredParameter(options, element);
  5436. }
  5437. }
  5438. } else if (expr.type === Syntax.Identifier) {
  5439. validateParam(options, expr, expr.name);
  5440. } else if (expr.type === Syntax.SpreadElement) {
  5441. // BindingRestElement only allows BindingIdentifier
  5442. if (expr.argument.type !== Syntax.Identifier) {
  5443. throwError({}, Messages.InvalidLHSInFormalsList);
  5444. }
  5445. validateParam(options, expr.argument, expr.argument.name);
  5446. } else {
  5447. throwError({}, Messages.InvalidLHSInFormalsList);
  5448. }
  5449. }
  5450. function reinterpretAsCoverFormalsList(expressions) {
  5451. var i, len, param, params, defaults, defaultCount, options, rest;
  5452. params = [];
  5453. defaults = [];
  5454. defaultCount = 0;
  5455. rest = null;
  5456. options = {
  5457. paramSet: new StringMap()
  5458. };
  5459. for (i = 0, len = expressions.length; i < len; i += 1) {
  5460. param = expressions[i];
  5461. if (param.type === Syntax.Identifier) {
  5462. params.push(param);
  5463. defaults.push(null);
  5464. validateParam(options, param, param.name);
  5465. } else if (param.type === Syntax.ObjectExpression || param.type === Syntax.ArrayExpression) {
  5466. reinterpretAsDestructuredParameter(options, param);
  5467. params.push(param);
  5468. defaults.push(null);
  5469. } else if (param.type === Syntax.SpreadElement) {
  5470. assert(i === len - 1, 'It is guaranteed that SpreadElement is last element by parseExpression');
  5471. if (param.argument.type !== Syntax.Identifier) {
  5472. throwError({}, Messages.InvalidLHSInFormalsList);
  5473. }
  5474. reinterpretAsDestructuredParameter(options, param.argument);
  5475. rest = param.argument;
  5476. } else if (param.type === Syntax.AssignmentExpression) {
  5477. params.push(param.left);
  5478. defaults.push(param.right);
  5479. ++defaultCount;
  5480. validateParam(options, param.left, param.left.name);
  5481. } else {
  5482. return null;
  5483. }
  5484. }
  5485. if (options.message === Messages.StrictParamDupe) {
  5486. throwError(
  5487. strict ? options.stricted : options.firstRestricted,
  5488. options.message
  5489. );
  5490. }
  5491. if (defaultCount === 0) {
  5492. defaults = [];
  5493. }
  5494. return {
  5495. params: params,
  5496. defaults: defaults,
  5497. rest: rest,
  5498. stricted: options.stricted,
  5499. firstRestricted: options.firstRestricted,
  5500. message: options.message
  5501. };
  5502. }
  5503. function parseArrowFunctionExpression(options, marker) {
  5504. var previousStrict, previousYieldAllowed, previousAwaitAllowed, body;
  5505. expect('=>');
  5506. previousStrict = strict;
  5507. previousYieldAllowed = state.yieldAllowed;
  5508. state.yieldAllowed = false;
  5509. previousAwaitAllowed = state.awaitAllowed;
  5510. state.awaitAllowed = !!options.async;
  5511. body = parseConciseBody();
  5512. if (strict && options.firstRestricted) {
  5513. throwError(options.firstRestricted, options.message);
  5514. }
  5515. if (strict && options.stricted) {
  5516. throwErrorTolerant(options.stricted, options.message);
  5517. }
  5518. strict = previousStrict;
  5519. state.yieldAllowed = previousYieldAllowed;
  5520. state.awaitAllowed = previousAwaitAllowed;
  5521. return markerApply(marker, delegate.createArrowFunctionExpression(
  5522. options.params,
  5523. options.defaults,
  5524. body,
  5525. options.rest,
  5526. body.type !== Syntax.BlockStatement,
  5527. !!options.async
  5528. ));
  5529. }
  5530. function parseAssignmentExpression() {
  5531. var marker, expr, token, params, oldParenthesizedCount,
  5532. startsWithParen = false, backtrackToken = lookahead,
  5533. possiblyAsync = false;
  5534. if (matchYield()) {
  5535. return parseYieldExpression();
  5536. }
  5537. if (matchAwait()) {
  5538. return parseAwaitExpression();
  5539. }
  5540. oldParenthesizedCount = state.parenthesizedCount;
  5541. marker = markerCreate();
  5542. if (matchAsyncFuncExprOrDecl()) {
  5543. return parseFunctionExpression();
  5544. }
  5545. if (matchAsync()) {
  5546. // We can't be completely sure that this 'async' token is
  5547. // actually a contextual keyword modifying a function
  5548. // expression, so we might have to un-lex() it later by
  5549. // calling rewind(backtrackToken).
  5550. possiblyAsync = true;
  5551. lex();
  5552. }
  5553. if (match('(')) {
  5554. token = lookahead2();
  5555. if ((token.type === Token.Punctuator && token.value === ')') || token.value === '...') {
  5556. params = parseParams();
  5557. if (!match('=>')) {
  5558. throwUnexpected(lex());
  5559. }
  5560. params.async = possiblyAsync;
  5561. return parseArrowFunctionExpression(params, marker);
  5562. }
  5563. startsWithParen = true;
  5564. }
  5565. token = lookahead;
  5566. // If the 'async' keyword is not followed by a '(' character or an
  5567. // identifier, then it can't be an arrow function modifier, and we
  5568. // should interpret it as a normal identifer.
  5569. if (possiblyAsync && !match('(') && token.type !== Token.Identifier) {
  5570. possiblyAsync = false;
  5571. rewind(backtrackToken);
  5572. }
  5573. expr = parseConditionalExpression();
  5574. if (match('=>') &&
  5575. (state.parenthesizedCount === oldParenthesizedCount ||
  5576. state.parenthesizedCount === (oldParenthesizedCount + 1))) {
  5577. if (expr.type === Syntax.Identifier) {
  5578. params = reinterpretAsCoverFormalsList([ expr ]);
  5579. } else if (expr.type === Syntax.AssignmentExpression ||
  5580. expr.type === Syntax.ArrayExpression ||
  5581. expr.type === Syntax.ObjectExpression) {
  5582. if (!startsWithParen) {
  5583. throwUnexpected(lex());
  5584. }
  5585. params = reinterpretAsCoverFormalsList([ expr ]);
  5586. } else if (expr.type === Syntax.SequenceExpression) {
  5587. params = reinterpretAsCoverFormalsList(expr.expressions);
  5588. }
  5589. if (params) {
  5590. params.async = possiblyAsync;
  5591. return parseArrowFunctionExpression(params, marker);
  5592. }
  5593. }
  5594. // If we haven't returned by now, then the 'async' keyword was not
  5595. // a function modifier, and we should rewind and interpret it as a
  5596. // normal identifier.
  5597. if (possiblyAsync) {
  5598. possiblyAsync = false;
  5599. rewind(backtrackToken);
  5600. expr = parseConditionalExpression();
  5601. }
  5602. if (matchAssign()) {
  5603. // 11.13.1
  5604. if (strict && expr.type === Syntax.Identifier && isRestrictedWord(expr.name)) {
  5605. throwErrorTolerant(token, Messages.StrictLHSAssignment);
  5606. }
  5607. // ES.next draf 11.13 Runtime Semantics step 1
  5608. if (match('=') && (expr.type === Syntax.ObjectExpression || expr.type === Syntax.ArrayExpression)) {
  5609. reinterpretAsAssignmentBindingPattern(expr);
  5610. } else if (!isLeftHandSide(expr)) {
  5611. throwError({}, Messages.InvalidLHSInAssignment);
  5612. }
  5613. expr = markerApply(marker, delegate.createAssignmentExpression(lex().value, expr, parseAssignmentExpression()));
  5614. }
  5615. return expr;
  5616. }
  5617. // 11.14 Comma Operator
  5618. function parseExpression() {
  5619. var marker, expr, expressions, sequence, spreadFound;
  5620. marker = markerCreate();
  5621. expr = parseAssignmentExpression();
  5622. expressions = [ expr ];
  5623. if (match(',')) {
  5624. while (index < length) {
  5625. if (!match(',')) {
  5626. break;
  5627. }
  5628. lex();
  5629. expr = parseSpreadOrAssignmentExpression();
  5630. expressions.push(expr);
  5631. if (expr.type === Syntax.SpreadElement) {
  5632. spreadFound = true;
  5633. if (!match(')')) {
  5634. throwError({}, Messages.ElementAfterSpreadElement);
  5635. }
  5636. break;
  5637. }
  5638. }
  5639. sequence = markerApply(marker, delegate.createSequenceExpression(expressions));
  5640. }
  5641. if (spreadFound && lookahead2().value !== '=>') {
  5642. throwError({}, Messages.IllegalSpread);
  5643. }
  5644. return sequence || expr;
  5645. }
  5646. // 12.1 Block
  5647. function parseStatementList() {
  5648. var list = [],
  5649. statement;
  5650. while (index < length) {
  5651. if (match('}')) {
  5652. break;
  5653. }
  5654. statement = parseSourceElement();
  5655. if (typeof statement === 'undefined') {
  5656. break;
  5657. }
  5658. list.push(statement);
  5659. }
  5660. return list;
  5661. }
  5662. function parseBlock() {
  5663. var block, marker = markerCreate();
  5664. expect('{');
  5665. block = parseStatementList();
  5666. expect('}');
  5667. return markerApply(marker, delegate.createBlockStatement(block));
  5668. }
  5669. // 12.2 Variable Statement
  5670. function parseTypeParameterDeclaration() {
  5671. var marker = markerCreate(), paramTypes = [];
  5672. expect('<');
  5673. while (!match('>')) {
  5674. paramTypes.push(parseTypeAnnotatableIdentifier());
  5675. if (!match('>')) {
  5676. expect(',');
  5677. }
  5678. }
  5679. expect('>');
  5680. return markerApply(marker, delegate.createTypeParameterDeclaration(
  5681. paramTypes
  5682. ));
  5683. }
  5684. function parseTypeParameterInstantiation() {
  5685. var marker = markerCreate(), oldInType = state.inType, paramTypes = [];
  5686. state.inType = true;
  5687. expect('<');
  5688. while (!match('>')) {
  5689. paramTypes.push(parseType());
  5690. if (!match('>')) {
  5691. expect(',');
  5692. }
  5693. }
  5694. expect('>');
  5695. state.inType = oldInType;
  5696. return markerApply(marker, delegate.createTypeParameterInstantiation(
  5697. paramTypes
  5698. ));
  5699. }
  5700. function parseObjectTypeIndexer(marker, isStatic) {
  5701. var id, key, value;
  5702. expect('[');
  5703. id = parseObjectPropertyKey();
  5704. expect(':');
  5705. key = parseType();
  5706. expect(']');
  5707. expect(':');
  5708. value = parseType();
  5709. return markerApply(marker, delegate.createObjectTypeIndexer(
  5710. id,
  5711. key,
  5712. value,
  5713. isStatic
  5714. ));
  5715. }
  5716. function parseObjectTypeMethodish(marker) {
  5717. var params = [], rest = null, returnType, typeParameters = null;
  5718. if (match('<')) {
  5719. typeParameters = parseTypeParameterDeclaration();
  5720. }
  5721. expect('(');
  5722. while (lookahead.type === Token.Identifier) {
  5723. params.push(parseFunctionTypeParam());
  5724. if (!match(')')) {
  5725. expect(',');
  5726. }
  5727. }
  5728. if (match('...')) {
  5729. lex();
  5730. rest = parseFunctionTypeParam();
  5731. }
  5732. expect(')');
  5733. expect(':');
  5734. returnType = parseType();
  5735. return markerApply(marker, delegate.createFunctionTypeAnnotation(
  5736. params,
  5737. returnType,
  5738. rest,
  5739. typeParameters
  5740. ));
  5741. }
  5742. function parseObjectTypeMethod(marker, isStatic, key) {
  5743. var optional = false, value;
  5744. value = parseObjectTypeMethodish(marker);
  5745. return markerApply(marker, delegate.createObjectTypeProperty(
  5746. key,
  5747. value,
  5748. optional,
  5749. isStatic
  5750. ));
  5751. }
  5752. function parseObjectTypeCallProperty(marker, isStatic) {
  5753. var valueMarker = markerCreate();
  5754. return markerApply(marker, delegate.createObjectTypeCallProperty(
  5755. parseObjectTypeMethodish(valueMarker),
  5756. isStatic
  5757. ));
  5758. }
  5759. function parseObjectType(allowStatic) {
  5760. var callProperties = [], indexers = [], marker, optional = false,
  5761. properties = [], propertyKey, propertyTypeAnnotation,
  5762. token, isStatic, matchStatic;
  5763. expect('{');
  5764. while (!match('}')) {
  5765. marker = markerCreate();
  5766. matchStatic =
  5767. strict
  5768. ? matchKeyword('static')
  5769. : matchContextualKeyword('static');
  5770. if (allowStatic && matchStatic) {
  5771. token = lex();
  5772. isStatic = true;
  5773. }
  5774. if (match('[')) {
  5775. indexers.push(parseObjectTypeIndexer(marker, isStatic));
  5776. } else if (match('(') || match('<')) {
  5777. callProperties.push(parseObjectTypeCallProperty(marker, allowStatic));
  5778. } else {
  5779. if (isStatic && match(':')) {
  5780. propertyKey = markerApply(marker, delegate.createIdentifier(token));
  5781. throwErrorTolerant(token, Messages.StrictReservedWord);
  5782. } else {
  5783. propertyKey = parseObjectPropertyKey();
  5784. }
  5785. if (match('<') || match('(')) {
  5786. // This is a method property
  5787. properties.push(parseObjectTypeMethod(marker, isStatic, propertyKey));
  5788. } else {
  5789. if (match('?')) {
  5790. lex();
  5791. optional = true;
  5792. }
  5793. expect(':');
  5794. propertyTypeAnnotation = parseType();
  5795. properties.push(markerApply(marker, delegate.createObjectTypeProperty(
  5796. propertyKey,
  5797. propertyTypeAnnotation,
  5798. optional,
  5799. isStatic
  5800. )));
  5801. }
  5802. }
  5803. if (match(';')) {
  5804. lex();
  5805. } else if (!match('}')) {
  5806. throwUnexpected(lookahead);
  5807. }
  5808. }
  5809. expect('}');
  5810. return delegate.createObjectTypeAnnotation(
  5811. properties,
  5812. indexers,
  5813. callProperties
  5814. );
  5815. }
  5816. function parseGenericType() {
  5817. var marker = markerCreate(),
  5818. typeParameters = null, typeIdentifier;
  5819. typeIdentifier = parseVariableIdentifier();
  5820. while (match('.')) {
  5821. expect('.');
  5822. typeIdentifier = markerApply(marker, delegate.createQualifiedTypeIdentifier(
  5823. typeIdentifier,
  5824. parseVariableIdentifier()
  5825. ));
  5826. }
  5827. if (match('<')) {
  5828. typeParameters = parseTypeParameterInstantiation();
  5829. }
  5830. return markerApply(marker, delegate.createGenericTypeAnnotation(
  5831. typeIdentifier,
  5832. typeParameters
  5833. ));
  5834. }
  5835. function parseVoidType() {
  5836. var marker = markerCreate();
  5837. expectKeyword('void');
  5838. return markerApply(marker, delegate.createVoidTypeAnnotation());
  5839. }
  5840. function parseTypeofType() {
  5841. var argument, marker = markerCreate();
  5842. expectKeyword('typeof');
  5843. argument = parsePrimaryType();
  5844. return markerApply(marker, delegate.createTypeofTypeAnnotation(
  5845. argument
  5846. ));
  5847. }
  5848. function parseTupleType() {
  5849. var marker = markerCreate(), types = [];
  5850. expect('[');
  5851. // We allow trailing commas
  5852. while (index < length && !match(']')) {
  5853. types.push(parseType());
  5854. if (match(']')) {
  5855. break;
  5856. }
  5857. expect(',');
  5858. }
  5859. expect(']');
  5860. return markerApply(marker, delegate.createTupleTypeAnnotation(
  5861. types
  5862. ));
  5863. }
  5864. function parseFunctionTypeParam() {
  5865. var marker = markerCreate(), name, optional = false, typeAnnotation;
  5866. name = parseVariableIdentifier();
  5867. if (match('?')) {
  5868. lex();
  5869. optional = true;
  5870. }
  5871. expect(':');
  5872. typeAnnotation = parseType();
  5873. return markerApply(marker, delegate.createFunctionTypeParam(
  5874. name,
  5875. typeAnnotation,
  5876. optional
  5877. ));
  5878. }
  5879. function parseFunctionTypeParams() {
  5880. var ret = { params: [], rest: null };
  5881. while (lookahead.type === Token.Identifier) {
  5882. ret.params.push(parseFunctionTypeParam());
  5883. if (!match(')')) {
  5884. expect(',');
  5885. }
  5886. }
  5887. if (match('...')) {
  5888. lex();
  5889. ret.rest = parseFunctionTypeParam();
  5890. }
  5891. return ret;
  5892. }
  5893. // The parsing of types roughly parallels the parsing of expressions, and
  5894. // primary types are kind of like primary expressions...they're the
  5895. // primitives with which other types are constructed.
  5896. function parsePrimaryType() {
  5897. var params = null, returnType = null,
  5898. marker = markerCreate(), rest = null, tmp,
  5899. typeParameters, token, type, isGroupedType = false;
  5900. switch (lookahead.type) {
  5901. case Token.Identifier:
  5902. switch (lookahead.value) {
  5903. case 'any':
  5904. lex();
  5905. return markerApply(marker, delegate.createAnyTypeAnnotation());
  5906. case 'bool': // fallthrough
  5907. case 'boolean':
  5908. lex();
  5909. return markerApply(marker, delegate.createBooleanTypeAnnotation());
  5910. case 'number':
  5911. lex();
  5912. return markerApply(marker, delegate.createNumberTypeAnnotation());
  5913. case 'string':
  5914. lex();
  5915. return markerApply(marker, delegate.createStringTypeAnnotation());
  5916. }
  5917. return markerApply(marker, parseGenericType());
  5918. case Token.Punctuator:
  5919. switch (lookahead.value) {
  5920. case '{':
  5921. return markerApply(marker, parseObjectType());
  5922. case '[':
  5923. return parseTupleType();
  5924. case '<':
  5925. typeParameters = parseTypeParameterDeclaration();
  5926. expect('(');
  5927. tmp = parseFunctionTypeParams();
  5928. params = tmp.params;
  5929. rest = tmp.rest;
  5930. expect(')');
  5931. expect('=>');
  5932. returnType = parseType();
  5933. return markerApply(marker, delegate.createFunctionTypeAnnotation(
  5934. params,
  5935. returnType,
  5936. rest,
  5937. typeParameters
  5938. ));
  5939. case '(':
  5940. lex();
  5941. // Check to see if this is actually a grouped type
  5942. if (!match(')') && !match('...')) {
  5943. if (lookahead.type === Token.Identifier) {
  5944. token = lookahead2();
  5945. isGroupedType = token.value !== '?' && token.value !== ':';
  5946. } else {
  5947. isGroupedType = true;
  5948. }
  5949. }
  5950. if (isGroupedType) {
  5951. type = parseType();
  5952. expect(')');
  5953. // If we see a => next then someone was probably confused about
  5954. // function types, so we can provide a better error message
  5955. if (match('=>')) {
  5956. throwError({}, Messages.ConfusedAboutFunctionType);
  5957. }
  5958. return type;
  5959. }
  5960. tmp = parseFunctionTypeParams();
  5961. params = tmp.params;
  5962. rest = tmp.rest;
  5963. expect(')');
  5964. expect('=>');
  5965. returnType = parseType();
  5966. return markerApply(marker, delegate.createFunctionTypeAnnotation(
  5967. params,
  5968. returnType,
  5969. rest,
  5970. null /* typeParameters */
  5971. ));
  5972. }
  5973. break;
  5974. case Token.Keyword:
  5975. switch (lookahead.value) {
  5976. case 'void':
  5977. return markerApply(marker, parseVoidType());
  5978. case 'typeof':
  5979. return markerApply(marker, parseTypeofType());
  5980. }
  5981. break;
  5982. case Token.StringLiteral:
  5983. token = lex();
  5984. if (token.octal) {
  5985. throwError(token, Messages.StrictOctalLiteral);
  5986. }
  5987. return markerApply(marker, delegate.createStringLiteralTypeAnnotation(
  5988. token
  5989. ));
  5990. }
  5991. throwUnexpected(lookahead);
  5992. }
  5993. function parsePostfixType() {
  5994. var marker = markerCreate(), t = parsePrimaryType();
  5995. if (match('[')) {
  5996. expect('[');
  5997. expect(']');
  5998. return markerApply(marker, delegate.createArrayTypeAnnotation(t));
  5999. }
  6000. return t;
  6001. }
  6002. function parsePrefixType() {
  6003. var marker = markerCreate();
  6004. if (match('?')) {
  6005. lex();
  6006. return markerApply(marker, delegate.createNullableTypeAnnotation(
  6007. parsePrefixType()
  6008. ));
  6009. }
  6010. return parsePostfixType();
  6011. }
  6012. function parseIntersectionType() {
  6013. var marker = markerCreate(), type, types;
  6014. type = parsePrefixType();
  6015. types = [type];
  6016. while (match('&')) {
  6017. lex();
  6018. types.push(parsePrefixType());
  6019. }
  6020. return types.length === 1 ?
  6021. type :
  6022. markerApply(marker, delegate.createIntersectionTypeAnnotation(
  6023. types
  6024. ));
  6025. }
  6026. function parseUnionType() {
  6027. var marker = markerCreate(), type, types;
  6028. type = parseIntersectionType();
  6029. types = [type];
  6030. while (match('|')) {
  6031. lex();
  6032. types.push(parseIntersectionType());
  6033. }
  6034. return types.length === 1 ?
  6035. type :
  6036. markerApply(marker, delegate.createUnionTypeAnnotation(
  6037. types
  6038. ));
  6039. }
  6040. function parseType() {
  6041. var oldInType = state.inType, type;
  6042. state.inType = true;
  6043. type = parseUnionType();
  6044. state.inType = oldInType;
  6045. return type;
  6046. }
  6047. function parseTypeAnnotation() {
  6048. var marker = markerCreate(), type;
  6049. expect(':');
  6050. type = parseType();
  6051. return markerApply(marker, delegate.createTypeAnnotation(type));
  6052. }
  6053. function parseVariableIdentifier() {
  6054. var marker = markerCreate(),
  6055. token = lex();
  6056. if (token.type !== Token.Identifier) {
  6057. throwUnexpected(token);
  6058. }
  6059. return markerApply(marker, delegate.createIdentifier(token.value));
  6060. }
  6061. function parseTypeAnnotatableIdentifier(requireTypeAnnotation, canBeOptionalParam) {
  6062. var marker = markerCreate(),
  6063. ident = parseVariableIdentifier(),
  6064. isOptionalParam = false;
  6065. if (canBeOptionalParam && match('?')) {
  6066. expect('?');
  6067. isOptionalParam = true;
  6068. }
  6069. if (requireTypeAnnotation || match(':')) {
  6070. ident.typeAnnotation = parseTypeAnnotation();
  6071. ident = markerApply(marker, ident);
  6072. }
  6073. if (isOptionalParam) {
  6074. ident.optional = true;
  6075. ident = markerApply(marker, ident);
  6076. }
  6077. return ident;
  6078. }
  6079. function parseVariableDeclaration(kind) {
  6080. var id,
  6081. marker = markerCreate(),
  6082. init = null,
  6083. typeAnnotationMarker = markerCreate();
  6084. if (match('{')) {
  6085. id = parseObjectInitialiser();
  6086. reinterpretAsAssignmentBindingPattern(id);
  6087. if (match(':')) {
  6088. id.typeAnnotation = parseTypeAnnotation();
  6089. markerApply(typeAnnotationMarker, id);
  6090. }
  6091. } else if (match('[')) {
  6092. id = parseArrayInitialiser();
  6093. reinterpretAsAssignmentBindingPattern(id);
  6094. if (match(':')) {
  6095. id.typeAnnotation = parseTypeAnnotation();
  6096. markerApply(typeAnnotationMarker, id);
  6097. }
  6098. } else {
  6099. /* istanbul ignore next */
  6100. id = state.allowKeyword ? parseNonComputedProperty() : parseTypeAnnotatableIdentifier();
  6101. // 12.2.1
  6102. if (strict && isRestrictedWord(id.name)) {
  6103. throwErrorTolerant({}, Messages.StrictVarName);
  6104. }
  6105. }
  6106. if (kind === 'const') {
  6107. if (!match('=')) {
  6108. throwError({}, Messages.NoUninitializedConst);
  6109. }
  6110. expect('=');
  6111. init = parseAssignmentExpression();
  6112. } else if (match('=')) {
  6113. lex();
  6114. init = parseAssignmentExpression();
  6115. }
  6116. return markerApply(marker, delegate.createVariableDeclarator(id, init));
  6117. }
  6118. function parseVariableDeclarationList(kind) {
  6119. var list = [];
  6120. do {
  6121. list.push(parseVariableDeclaration(kind));
  6122. if (!match(',')) {
  6123. break;
  6124. }
  6125. lex();
  6126. } while (index < length);
  6127. return list;
  6128. }
  6129. function parseVariableStatement() {
  6130. var declarations, marker = markerCreate();
  6131. expectKeyword('var');
  6132. declarations = parseVariableDeclarationList();
  6133. consumeSemicolon();
  6134. return markerApply(marker, delegate.createVariableDeclaration(declarations, 'var'));
  6135. }
  6136. // kind may be `const` or `let`
  6137. // Both are experimental and not in the specification yet.
  6138. // see http://wiki.ecmascript.org/doku.php?id=harmony:const
  6139. // and http://wiki.ecmascript.org/doku.php?id=harmony:let
  6140. function parseConstLetDeclaration(kind) {
  6141. var declarations, marker = markerCreate();
  6142. expectKeyword(kind);
  6143. declarations = parseVariableDeclarationList(kind);
  6144. consumeSemicolon();
  6145. return markerApply(marker, delegate.createVariableDeclaration(declarations, kind));
  6146. }
  6147. // people.mozilla.org/~jorendorff/es6-draft.html
  6148. function parseModuleSpecifier() {
  6149. var marker = markerCreate(),
  6150. specifier;
  6151. if (lookahead.type !== Token.StringLiteral) {
  6152. throwError({}, Messages.InvalidModuleSpecifier);
  6153. }
  6154. specifier = delegate.createModuleSpecifier(lookahead);
  6155. lex();
  6156. return markerApply(marker, specifier);
  6157. }
  6158. function parseExportBatchSpecifier() {
  6159. var marker = markerCreate();
  6160. expect('*');
  6161. return markerApply(marker, delegate.createExportBatchSpecifier());
  6162. }
  6163. function parseExportSpecifier() {
  6164. var id, name = null, marker = markerCreate(), from;
  6165. if (matchKeyword('default')) {
  6166. lex();
  6167. id = markerApply(marker, delegate.createIdentifier('default'));
  6168. // export {default} from "something";
  6169. } else {
  6170. id = parseVariableIdentifier();
  6171. }
  6172. if (matchContextualKeyword('as')) {
  6173. lex();
  6174. name = parseNonComputedProperty();
  6175. }
  6176. return markerApply(marker, delegate.createExportSpecifier(id, name));
  6177. }
  6178. function parseExportDeclaration() {
  6179. var declaration = null,
  6180. possibleIdentifierToken, sourceElement,
  6181. isExportFromIdentifier,
  6182. src = null, specifiers = [],
  6183. marker = markerCreate();
  6184. expectKeyword('export');
  6185. if (matchKeyword('default')) {
  6186. // covers:
  6187. // export default ...
  6188. lex();
  6189. if (matchKeyword('function') || matchKeyword('class')) {
  6190. possibleIdentifierToken = lookahead2();
  6191. if (isIdentifierName(possibleIdentifierToken)) {
  6192. // covers:
  6193. // export default function foo () {}
  6194. // export default class foo {}
  6195. sourceElement = parseSourceElement();
  6196. return markerApply(marker, delegate.createExportDeclaration(true, sourceElement, [sourceElement.id], null));
  6197. }
  6198. // covers:
  6199. // export default function () {}
  6200. // export default class {}
  6201. switch (lookahead.value) {
  6202. case 'class':
  6203. return markerApply(marker, delegate.createExportDeclaration(true, parseClassExpression(), [], null));
  6204. case 'function':
  6205. return markerApply(marker, delegate.createExportDeclaration(true, parseFunctionExpression(), [], null));
  6206. }
  6207. }
  6208. if (matchContextualKeyword('from')) {
  6209. throwError({}, Messages.UnexpectedToken, lookahead.value);
  6210. }
  6211. // covers:
  6212. // export default {};
  6213. // export default [];
  6214. if (match('{')) {
  6215. declaration = parseObjectInitialiser();
  6216. } else if (match('[')) {
  6217. declaration = parseArrayInitialiser();
  6218. } else {
  6219. declaration = parseAssignmentExpression();
  6220. }
  6221. consumeSemicolon();
  6222. return markerApply(marker, delegate.createExportDeclaration(true, declaration, [], null));
  6223. }
  6224. // non-default export
  6225. if (lookahead.type === Token.Keyword || matchContextualKeyword('type')) {
  6226. // covers:
  6227. // export var f = 1;
  6228. switch (lookahead.value) {
  6229. case 'type':
  6230. case 'let':
  6231. case 'const':
  6232. case 'var':
  6233. case 'class':
  6234. case 'function':
  6235. return markerApply(marker, delegate.createExportDeclaration(false, parseSourceElement(), specifiers, null));
  6236. }
  6237. }
  6238. if (match('*')) {
  6239. // covers:
  6240. // export * from "foo";
  6241. specifiers.push(parseExportBatchSpecifier());
  6242. if (!matchContextualKeyword('from')) {
  6243. throwError({}, lookahead.value ?
  6244. Messages.UnexpectedToken : Messages.MissingFromClause, lookahead.value);
  6245. }
  6246. lex();
  6247. src = parseModuleSpecifier();
  6248. consumeSemicolon();
  6249. return markerApply(marker, delegate.createExportDeclaration(false, null, specifiers, src));
  6250. }
  6251. expect('{');
  6252. if (!match('}')) {
  6253. do {
  6254. isExportFromIdentifier = isExportFromIdentifier || matchKeyword('default');
  6255. specifiers.push(parseExportSpecifier());
  6256. } while (match(',') && lex());
  6257. }
  6258. expect('}');
  6259. if (matchContextualKeyword('from')) {
  6260. // covering:
  6261. // export {default} from "foo";
  6262. // export {foo} from "foo";
  6263. lex();
  6264. src = parseModuleSpecifier();
  6265. consumeSemicolon();
  6266. } else if (isExportFromIdentifier) {
  6267. // covering:
  6268. // export {default}; // missing fromClause
  6269. throwError({}, lookahead.value ?
  6270. Messages.UnexpectedToken : Messages.MissingFromClause, lookahead.value);
  6271. } else {
  6272. // cover
  6273. // export {foo};
  6274. consumeSemicolon();
  6275. }
  6276. return markerApply(marker, delegate.createExportDeclaration(false, declaration, specifiers, src));
  6277. }
  6278. function parseImportSpecifier() {
  6279. // import {<foo as bar>} ...;
  6280. var id, name = null, marker = markerCreate();
  6281. id = parseNonComputedProperty();
  6282. if (matchContextualKeyword('as')) {
  6283. lex();
  6284. name = parseVariableIdentifier();
  6285. }
  6286. return markerApply(marker, delegate.createImportSpecifier(id, name));
  6287. }
  6288. function parseNamedImports() {
  6289. var specifiers = [];
  6290. // {foo, bar as bas}
  6291. expect('{');
  6292. if (!match('}')) {
  6293. do {
  6294. specifiers.push(parseImportSpecifier());
  6295. } while (match(',') && lex());
  6296. }
  6297. expect('}');
  6298. return specifiers;
  6299. }
  6300. function parseImportDefaultSpecifier() {
  6301. // import <foo> ...;
  6302. var id, marker = markerCreate();
  6303. id = parseNonComputedProperty();
  6304. return markerApply(marker, delegate.createImportDefaultSpecifier(id));
  6305. }
  6306. function parseImportNamespaceSpecifier() {
  6307. // import <* as foo> ...;
  6308. var id, marker = markerCreate();
  6309. expect('*');
  6310. if (!matchContextualKeyword('as')) {
  6311. throwError({}, Messages.NoAsAfterImportNamespace);
  6312. }
  6313. lex();
  6314. id = parseNonComputedProperty();
  6315. return markerApply(marker, delegate.createImportNamespaceSpecifier(id));
  6316. }
  6317. function parseImportDeclaration() {
  6318. var specifiers, src, marker = markerCreate(), isType = false, token2;
  6319. expectKeyword('import');
  6320. if (matchContextualKeyword('type')) {
  6321. token2 = lookahead2();
  6322. if ((token2.type === Token.Identifier && token2.value !== 'from') ||
  6323. (token2.type === Token.Punctuator &&
  6324. (token2.value === '{' || token2.value === '*'))) {
  6325. isType = true;
  6326. lex();
  6327. }
  6328. }
  6329. specifiers = [];
  6330. if (lookahead.type === Token.StringLiteral) {
  6331. // covers:
  6332. // import "foo";
  6333. src = parseModuleSpecifier();
  6334. consumeSemicolon();
  6335. return markerApply(marker, delegate.createImportDeclaration(specifiers, src, isType));
  6336. }
  6337. if (!matchKeyword('default') && isIdentifierName(lookahead)) {
  6338. // covers:
  6339. // import foo
  6340. // import foo, ...
  6341. specifiers.push(parseImportDefaultSpecifier());
  6342. if (match(',')) {
  6343. lex();
  6344. }
  6345. }
  6346. if (match('*')) {
  6347. // covers:
  6348. // import foo, * as foo
  6349. // import * as foo
  6350. specifiers.push(parseImportNamespaceSpecifier());
  6351. } else if (match('{')) {
  6352. // covers:
  6353. // import foo, {bar}
  6354. // import {bar}
  6355. specifiers = specifiers.concat(parseNamedImports());
  6356. }
  6357. if (!matchContextualKeyword('from')) {
  6358. throwError({}, lookahead.value ?
  6359. Messages.UnexpectedToken : Messages.MissingFromClause, lookahead.value);
  6360. }
  6361. lex();
  6362. src = parseModuleSpecifier();
  6363. consumeSemicolon();
  6364. return markerApply(marker, delegate.createImportDeclaration(specifiers, src, isType));
  6365. }
  6366. // 12.3 Empty Statement
  6367. function parseEmptyStatement() {
  6368. var marker = markerCreate();
  6369. expect(';');
  6370. return markerApply(marker, delegate.createEmptyStatement());
  6371. }
  6372. // 12.4 Expression Statement
  6373. function parseExpressionStatement() {
  6374. var marker = markerCreate(), expr = parseExpression();
  6375. consumeSemicolon();
  6376. return markerApply(marker, delegate.createExpressionStatement(expr));
  6377. }
  6378. // 12.5 If statement
  6379. function parseIfStatement() {
  6380. var test, consequent, alternate, marker = markerCreate();
  6381. expectKeyword('if');
  6382. expect('(');
  6383. test = parseExpression();
  6384. expect(')');
  6385. consequent = parseStatement();
  6386. if (matchKeyword('else')) {
  6387. lex();
  6388. alternate = parseStatement();
  6389. } else {
  6390. alternate = null;
  6391. }
  6392. return markerApply(marker, delegate.createIfStatement(test, consequent, alternate));
  6393. }
  6394. // 12.6 Iteration Statements
  6395. function parseDoWhileStatement() {
  6396. var body, test, oldInIteration, marker = markerCreate();
  6397. expectKeyword('do');
  6398. oldInIteration = state.inIteration;
  6399. state.inIteration = true;
  6400. body = parseStatement();
  6401. state.inIteration = oldInIteration;
  6402. expectKeyword('while');
  6403. expect('(');
  6404. test = parseExpression();
  6405. expect(')');
  6406. if (match(';')) {
  6407. lex();
  6408. }
  6409. return markerApply(marker, delegate.createDoWhileStatement(body, test));
  6410. }
  6411. function parseWhileStatement() {
  6412. var test, body, oldInIteration, marker = markerCreate();
  6413. expectKeyword('while');
  6414. expect('(');
  6415. test = parseExpression();
  6416. expect(')');
  6417. oldInIteration = state.inIteration;
  6418. state.inIteration = true;
  6419. body = parseStatement();
  6420. state.inIteration = oldInIteration;
  6421. return markerApply(marker, delegate.createWhileStatement(test, body));
  6422. }
  6423. function parseForVariableDeclaration() {
  6424. var marker = markerCreate(),
  6425. token = lex(),
  6426. declarations = parseVariableDeclarationList();
  6427. return markerApply(marker, delegate.createVariableDeclaration(declarations, token.value));
  6428. }
  6429. function parseForStatement(opts) {
  6430. var init, test, update, left, right, body, operator, oldInIteration,
  6431. marker = markerCreate();
  6432. init = test = update = null;
  6433. expectKeyword('for');
  6434. // http://wiki.ecmascript.org/doku.php?id=proposals:iterators_and_generators&s=each
  6435. if (matchContextualKeyword('each')) {
  6436. throwError({}, Messages.EachNotAllowed);
  6437. }
  6438. expect('(');
  6439. if (match(';')) {
  6440. lex();
  6441. } else {
  6442. if (matchKeyword('var') || matchKeyword('let') || matchKeyword('const')) {
  6443. state.allowIn = false;
  6444. init = parseForVariableDeclaration();
  6445. state.allowIn = true;
  6446. if (init.declarations.length === 1) {
  6447. if (matchKeyword('in') || matchContextualKeyword('of')) {
  6448. operator = lookahead;
  6449. if (!((operator.value === 'in' || init.kind !== 'var') && init.declarations[0].init)) {
  6450. lex();
  6451. left = init;
  6452. right = parseExpression();
  6453. init = null;
  6454. }
  6455. }
  6456. }
  6457. } else {
  6458. state.allowIn = false;
  6459. init = parseExpression();
  6460. state.allowIn = true;
  6461. if (matchContextualKeyword('of')) {
  6462. operator = lex();
  6463. left = init;
  6464. right = parseExpression();
  6465. init = null;
  6466. } else if (matchKeyword('in')) {
  6467. // LeftHandSideExpression
  6468. if (!isAssignableLeftHandSide(init)) {
  6469. throwError({}, Messages.InvalidLHSInForIn);
  6470. }
  6471. operator = lex();
  6472. left = init;
  6473. right = parseExpression();
  6474. init = null;
  6475. }
  6476. }
  6477. if (typeof left === 'undefined') {
  6478. expect(';');
  6479. }
  6480. }
  6481. if (typeof left === 'undefined') {
  6482. if (!match(';')) {
  6483. test = parseExpression();
  6484. }
  6485. expect(';');
  6486. if (!match(')')) {
  6487. update = parseExpression();
  6488. }
  6489. }
  6490. expect(')');
  6491. oldInIteration = state.inIteration;
  6492. state.inIteration = true;
  6493. if (!(opts !== undefined && opts.ignoreBody)) {
  6494. body = parseStatement();
  6495. }
  6496. state.inIteration = oldInIteration;
  6497. if (typeof left === 'undefined') {
  6498. return markerApply(marker, delegate.createForStatement(init, test, update, body));
  6499. }
  6500. if (operator.value === 'in') {
  6501. return markerApply(marker, delegate.createForInStatement(left, right, body));
  6502. }
  6503. return markerApply(marker, delegate.createForOfStatement(left, right, body));
  6504. }
  6505. // 12.7 The continue statement
  6506. function parseContinueStatement() {
  6507. var label = null, marker = markerCreate();
  6508. expectKeyword('continue');
  6509. // Optimize the most common form: 'continue;'.
  6510. if (source.charCodeAt(index) === 59) {
  6511. lex();
  6512. if (!state.inIteration) {
  6513. throwError({}, Messages.IllegalContinue);
  6514. }
  6515. return markerApply(marker, delegate.createContinueStatement(null));
  6516. }
  6517. if (peekLineTerminator()) {
  6518. if (!state.inIteration) {
  6519. throwError({}, Messages.IllegalContinue);
  6520. }
  6521. return markerApply(marker, delegate.createContinueStatement(null));
  6522. }
  6523. if (lookahead.type === Token.Identifier) {
  6524. label = parseVariableIdentifier();
  6525. if (!state.labelSet.has(label.name)) {
  6526. throwError({}, Messages.UnknownLabel, label.name);
  6527. }
  6528. }
  6529. consumeSemicolon();
  6530. if (label === null && !state.inIteration) {
  6531. throwError({}, Messages.IllegalContinue);
  6532. }
  6533. return markerApply(marker, delegate.createContinueStatement(label));
  6534. }
  6535. // 12.8 The break statement
  6536. function parseBreakStatement() {
  6537. var label = null, marker = markerCreate();
  6538. expectKeyword('break');
  6539. // Catch the very common case first: immediately a semicolon (char #59).
  6540. if (source.charCodeAt(index) === 59) {
  6541. lex();
  6542. if (!(state.inIteration || state.inSwitch)) {
  6543. throwError({}, Messages.IllegalBreak);
  6544. }
  6545. return markerApply(marker, delegate.createBreakStatement(null));
  6546. }
  6547. if (peekLineTerminator()) {
  6548. if (!(state.inIteration || state.inSwitch)) {
  6549. throwError({}, Messages.IllegalBreak);
  6550. }
  6551. return markerApply(marker, delegate.createBreakStatement(null));
  6552. }
  6553. if (lookahead.type === Token.Identifier) {
  6554. label = parseVariableIdentifier();
  6555. if (!state.labelSet.has(label.name)) {
  6556. throwError({}, Messages.UnknownLabel, label.name);
  6557. }
  6558. }
  6559. consumeSemicolon();
  6560. if (label === null && !(state.inIteration || state.inSwitch)) {
  6561. throwError({}, Messages.IllegalBreak);
  6562. }
  6563. return markerApply(marker, delegate.createBreakStatement(label));
  6564. }
  6565. // 12.9 The return statement
  6566. function parseReturnStatement() {
  6567. var argument = null, marker = markerCreate();
  6568. expectKeyword('return');
  6569. if (!state.inFunctionBody) {
  6570. throwErrorTolerant({}, Messages.IllegalReturn);
  6571. }
  6572. // 'return' followed by a space and an identifier is very common.
  6573. if (source.charCodeAt(index) === 32) {
  6574. if (isIdentifierStart(source.charCodeAt(index + 1))) {
  6575. argument = parseExpression();
  6576. consumeSemicolon();
  6577. return markerApply(marker, delegate.createReturnStatement(argument));
  6578. }
  6579. }
  6580. if (peekLineTerminator()) {
  6581. return markerApply(marker, delegate.createReturnStatement(null));
  6582. }
  6583. if (!match(';')) {
  6584. if (!match('}') && lookahead.type !== Token.EOF) {
  6585. argument = parseExpression();
  6586. }
  6587. }
  6588. consumeSemicolon();
  6589. return markerApply(marker, delegate.createReturnStatement(argument));
  6590. }
  6591. // 12.10 The with statement
  6592. function parseWithStatement() {
  6593. var object, body, marker = markerCreate();
  6594. if (strict) {
  6595. throwErrorTolerant({}, Messages.StrictModeWith);
  6596. }
  6597. expectKeyword('with');
  6598. expect('(');
  6599. object = parseExpression();
  6600. expect(')');
  6601. body = parseStatement();
  6602. return markerApply(marker, delegate.createWithStatement(object, body));
  6603. }
  6604. // 12.10 The swith statement
  6605. function parseSwitchCase() {
  6606. var test,
  6607. consequent = [],
  6608. sourceElement,
  6609. marker = markerCreate();
  6610. if (matchKeyword('default')) {
  6611. lex();
  6612. test = null;
  6613. } else {
  6614. expectKeyword('case');
  6615. test = parseExpression();
  6616. }
  6617. expect(':');
  6618. while (index < length) {
  6619. if (match('}') || matchKeyword('default') || matchKeyword('case')) {
  6620. break;
  6621. }
  6622. sourceElement = parseSourceElement();
  6623. if (typeof sourceElement === 'undefined') {
  6624. break;
  6625. }
  6626. consequent.push(sourceElement);
  6627. }
  6628. return markerApply(marker, delegate.createSwitchCase(test, consequent));
  6629. }
  6630. function parseSwitchStatement() {
  6631. var discriminant, cases, clause, oldInSwitch, defaultFound, marker = markerCreate();
  6632. expectKeyword('switch');
  6633. expect('(');
  6634. discriminant = parseExpression();
  6635. expect(')');
  6636. expect('{');
  6637. cases = [];
  6638. if (match('}')) {
  6639. lex();
  6640. return markerApply(marker, delegate.createSwitchStatement(discriminant, cases));
  6641. }
  6642. oldInSwitch = state.inSwitch;
  6643. state.inSwitch = true;
  6644. defaultFound = false;
  6645. while (index < length) {
  6646. if (match('}')) {
  6647. break;
  6648. }
  6649. clause = parseSwitchCase();
  6650. if (clause.test === null) {
  6651. if (defaultFound) {
  6652. throwError({}, Messages.MultipleDefaultsInSwitch);
  6653. }
  6654. defaultFound = true;
  6655. }
  6656. cases.push(clause);
  6657. }
  6658. state.inSwitch = oldInSwitch;
  6659. expect('}');
  6660. return markerApply(marker, delegate.createSwitchStatement(discriminant, cases));
  6661. }
  6662. // 12.13 The throw statement
  6663. function parseThrowStatement() {
  6664. var argument, marker = markerCreate();
  6665. expectKeyword('throw');
  6666. if (peekLineTerminator()) {
  6667. throwError({}, Messages.NewlineAfterThrow);
  6668. }
  6669. argument = parseExpression();
  6670. consumeSemicolon();
  6671. return markerApply(marker, delegate.createThrowStatement(argument));
  6672. }
  6673. // 12.14 The try statement
  6674. function parseCatchClause() {
  6675. var param, body, marker = markerCreate();
  6676. expectKeyword('catch');
  6677. expect('(');
  6678. if (match(')')) {
  6679. throwUnexpected(lookahead);
  6680. }
  6681. param = parseExpression();
  6682. // 12.14.1
  6683. if (strict && param.type === Syntax.Identifier && isRestrictedWord(param.name)) {
  6684. throwErrorTolerant({}, Messages.StrictCatchVariable);
  6685. }
  6686. expect(')');
  6687. body = parseBlock();
  6688. return markerApply(marker, delegate.createCatchClause(param, body));
  6689. }
  6690. function parseTryStatement() {
  6691. var block, handlers = [], finalizer = null, marker = markerCreate();
  6692. expectKeyword('try');
  6693. block = parseBlock();
  6694. if (matchKeyword('catch')) {
  6695. handlers.push(parseCatchClause());
  6696. }
  6697. if (matchKeyword('finally')) {
  6698. lex();
  6699. finalizer = parseBlock();
  6700. }
  6701. if (handlers.length === 0 && !finalizer) {
  6702. throwError({}, Messages.NoCatchOrFinally);
  6703. }
  6704. return markerApply(marker, delegate.createTryStatement(block, [], handlers, finalizer));
  6705. }
  6706. // 12.15 The debugger statement
  6707. function parseDebuggerStatement() {
  6708. var marker = markerCreate();
  6709. expectKeyword('debugger');
  6710. consumeSemicolon();
  6711. return markerApply(marker, delegate.createDebuggerStatement());
  6712. }
  6713. // 12 Statements
  6714. function parseStatement() {
  6715. var type = lookahead.type,
  6716. marker,
  6717. expr,
  6718. labeledBody;
  6719. if (type === Token.EOF) {
  6720. throwUnexpected(lookahead);
  6721. }
  6722. if (type === Token.Punctuator) {
  6723. switch (lookahead.value) {
  6724. case ';':
  6725. return parseEmptyStatement();
  6726. case '{':
  6727. return parseBlock();
  6728. case '(':
  6729. return parseExpressionStatement();
  6730. default:
  6731. break;
  6732. }
  6733. }
  6734. if (type === Token.Keyword) {
  6735. switch (lookahead.value) {
  6736. case 'break':
  6737. return parseBreakStatement();
  6738. case 'continue':
  6739. return parseContinueStatement();
  6740. case 'debugger':
  6741. return parseDebuggerStatement();
  6742. case 'do':
  6743. return parseDoWhileStatement();
  6744. case 'for':
  6745. return parseForStatement();
  6746. case 'function':
  6747. return parseFunctionDeclaration();
  6748. case 'class':
  6749. return parseClassDeclaration();
  6750. case 'if':
  6751. return parseIfStatement();
  6752. case 'return':
  6753. return parseReturnStatement();
  6754. case 'switch':
  6755. return parseSwitchStatement();
  6756. case 'throw':
  6757. return parseThrowStatement();
  6758. case 'try':
  6759. return parseTryStatement();
  6760. case 'var':
  6761. return parseVariableStatement();
  6762. case 'while':
  6763. return parseWhileStatement();
  6764. case 'with':
  6765. return parseWithStatement();
  6766. default:
  6767. break;
  6768. }
  6769. }
  6770. if (matchAsyncFuncExprOrDecl()) {
  6771. return parseFunctionDeclaration();
  6772. }
  6773. marker = markerCreate();
  6774. expr = parseExpression();
  6775. // 12.12 Labelled Statements
  6776. if ((expr.type === Syntax.Identifier) && match(':')) {
  6777. lex();
  6778. if (state.labelSet.has(expr.name)) {
  6779. throwError({}, Messages.Redeclaration, 'Label', expr.name);
  6780. }
  6781. state.labelSet.set(expr.name, true);
  6782. labeledBody = parseStatement();
  6783. state.labelSet["delete"](expr.name);
  6784. return markerApply(marker, delegate.createLabeledStatement(expr, labeledBody));
  6785. }
  6786. consumeSemicolon();
  6787. return markerApply(marker, delegate.createExpressionStatement(expr));
  6788. }
  6789. // 13 Function Definition
  6790. function parseConciseBody() {
  6791. if (match('{')) {
  6792. return parseFunctionSourceElements();
  6793. }
  6794. return parseAssignmentExpression();
  6795. }
  6796. function parseFunctionSourceElements() {
  6797. var sourceElement, sourceElements = [], token, directive, firstRestricted,
  6798. oldLabelSet, oldInIteration, oldInSwitch, oldInFunctionBody, oldParenthesizedCount,
  6799. marker = markerCreate();
  6800. expect('{');
  6801. while (index < length) {
  6802. if (lookahead.type !== Token.StringLiteral) {
  6803. break;
  6804. }
  6805. token = lookahead;
  6806. sourceElement = parseSourceElement();
  6807. sourceElements.push(sourceElement);
  6808. if (sourceElement.expression.type !== Syntax.Literal) {
  6809. // this is not directive
  6810. break;
  6811. }
  6812. directive = source.slice(token.range[0] + 1, token.range[1] - 1);
  6813. if (directive === 'use strict') {
  6814. strict = true;
  6815. if (firstRestricted) {
  6816. throwErrorTolerant(firstRestricted, Messages.StrictOctalLiteral);
  6817. }
  6818. } else {
  6819. if (!firstRestricted && token.octal) {
  6820. firstRestricted = token;
  6821. }
  6822. }
  6823. }
  6824. oldLabelSet = state.labelSet;
  6825. oldInIteration = state.inIteration;
  6826. oldInSwitch = state.inSwitch;
  6827. oldInFunctionBody = state.inFunctionBody;
  6828. oldParenthesizedCount = state.parenthesizedCount;
  6829. state.labelSet = new StringMap();
  6830. state.inIteration = false;
  6831. state.inSwitch = false;
  6832. state.inFunctionBody = true;
  6833. state.parenthesizedCount = 0;
  6834. while (index < length) {
  6835. if (match('}')) {
  6836. break;
  6837. }
  6838. sourceElement = parseSourceElement();
  6839. if (typeof sourceElement === 'undefined') {
  6840. break;
  6841. }
  6842. sourceElements.push(sourceElement);
  6843. }
  6844. expect('}');
  6845. state.labelSet = oldLabelSet;
  6846. state.inIteration = oldInIteration;
  6847. state.inSwitch = oldInSwitch;
  6848. state.inFunctionBody = oldInFunctionBody;
  6849. state.parenthesizedCount = oldParenthesizedCount;
  6850. return markerApply(marker, delegate.createBlockStatement(sourceElements));
  6851. }
  6852. function validateParam(options, param, name) {
  6853. if (strict) {
  6854. if (isRestrictedWord(name)) {
  6855. options.stricted = param;
  6856. options.message = Messages.StrictParamName;
  6857. }
  6858. if (options.paramSet.has(name)) {
  6859. options.stricted = param;
  6860. options.message = Messages.StrictParamDupe;
  6861. }
  6862. } else if (!options.firstRestricted) {
  6863. if (isRestrictedWord(name)) {
  6864. options.firstRestricted = param;
  6865. options.message = Messages.StrictParamName;
  6866. } else if (isStrictModeReservedWord(name)) {
  6867. options.firstRestricted = param;
  6868. options.message = Messages.StrictReservedWord;
  6869. } else if (options.paramSet.has(name)) {
  6870. options.firstRestricted = param;
  6871. options.message = Messages.StrictParamDupe;
  6872. }
  6873. }
  6874. options.paramSet.set(name, true);
  6875. }
  6876. function parseParam(options) {
  6877. var marker, token, rest, param, def;
  6878. token = lookahead;
  6879. if (token.value === '...') {
  6880. token = lex();
  6881. rest = true;
  6882. }
  6883. if (match('[')) {
  6884. marker = markerCreate();
  6885. param = parseArrayInitialiser();
  6886. reinterpretAsDestructuredParameter(options, param);
  6887. if (match(':')) {
  6888. param.typeAnnotation = parseTypeAnnotation();
  6889. markerApply(marker, param);
  6890. }
  6891. } else if (match('{')) {
  6892. marker = markerCreate();
  6893. if (rest) {
  6894. throwError({}, Messages.ObjectPatternAsRestParameter);
  6895. }
  6896. param = parseObjectInitialiser();
  6897. reinterpretAsDestructuredParameter(options, param);
  6898. if (match(':')) {
  6899. param.typeAnnotation = parseTypeAnnotation();
  6900. markerApply(marker, param);
  6901. }
  6902. } else {
  6903. param =
  6904. rest
  6905. ? parseTypeAnnotatableIdentifier(
  6906. false, /* requireTypeAnnotation */
  6907. false /* canBeOptionalParam */
  6908. )
  6909. : parseTypeAnnotatableIdentifier(
  6910. false, /* requireTypeAnnotation */
  6911. true /* canBeOptionalParam */
  6912. );
  6913. validateParam(options, token, token.value);
  6914. }
  6915. if (match('=')) {
  6916. if (rest) {
  6917. throwErrorTolerant(lookahead, Messages.DefaultRestParameter);
  6918. }
  6919. lex();
  6920. def = parseAssignmentExpression();
  6921. ++options.defaultCount;
  6922. }
  6923. if (rest) {
  6924. if (!match(')')) {
  6925. throwError({}, Messages.ParameterAfterRestParameter);
  6926. }
  6927. options.rest = param;
  6928. return false;
  6929. }
  6930. options.params.push(param);
  6931. options.defaults.push(def);
  6932. return !match(')');
  6933. }
  6934. function parseParams(firstRestricted) {
  6935. var options, marker = markerCreate();
  6936. options = {
  6937. params: [],
  6938. defaultCount: 0,
  6939. defaults: [],
  6940. rest: null,
  6941. firstRestricted: firstRestricted
  6942. };
  6943. expect('(');
  6944. if (!match(')')) {
  6945. options.paramSet = new StringMap();
  6946. while (index < length) {
  6947. if (!parseParam(options)) {
  6948. break;
  6949. }
  6950. expect(',');
  6951. }
  6952. }
  6953. expect(')');
  6954. if (options.defaultCount === 0) {
  6955. options.defaults = [];
  6956. }
  6957. if (match(':')) {
  6958. options.returnType = parseTypeAnnotation();
  6959. }
  6960. return markerApply(marker, options);
  6961. }
  6962. function parseFunctionDeclaration() {
  6963. var id, body, token, tmp, firstRestricted, message, generator, isAsync,
  6964. previousStrict, previousYieldAllowed, previousAwaitAllowed,
  6965. marker = markerCreate(), typeParameters;
  6966. isAsync = false;
  6967. if (matchAsync()) {
  6968. lex();
  6969. isAsync = true;
  6970. }
  6971. expectKeyword('function');
  6972. generator = false;
  6973. if (match('*')) {
  6974. lex();
  6975. generator = true;
  6976. }
  6977. token = lookahead;
  6978. id = parseVariableIdentifier();
  6979. if (match('<')) {
  6980. typeParameters = parseTypeParameterDeclaration();
  6981. }
  6982. if (strict) {
  6983. if (isRestrictedWord(token.value)) {
  6984. throwErrorTolerant(token, Messages.StrictFunctionName);
  6985. }
  6986. } else {
  6987. if (isRestrictedWord(token.value)) {
  6988. firstRestricted = token;
  6989. message = Messages.StrictFunctionName;
  6990. } else if (isStrictModeReservedWord(token.value)) {
  6991. firstRestricted = token;
  6992. message = Messages.StrictReservedWord;
  6993. }
  6994. }
  6995. tmp = parseParams(firstRestricted);
  6996. firstRestricted = tmp.firstRestricted;
  6997. if (tmp.message) {
  6998. message = tmp.message;
  6999. }
  7000. previousStrict = strict;
  7001. previousYieldAllowed = state.yieldAllowed;
  7002. state.yieldAllowed = generator;
  7003. previousAwaitAllowed = state.awaitAllowed;
  7004. state.awaitAllowed = isAsync;
  7005. body = parseFunctionSourceElements();
  7006. if (strict && firstRestricted) {
  7007. throwError(firstRestricted, message);
  7008. }
  7009. if (strict && tmp.stricted) {
  7010. throwErrorTolerant(tmp.stricted, message);
  7011. }
  7012. strict = previousStrict;
  7013. state.yieldAllowed = previousYieldAllowed;
  7014. state.awaitAllowed = previousAwaitAllowed;
  7015. return markerApply(
  7016. marker,
  7017. delegate.createFunctionDeclaration(
  7018. id,
  7019. tmp.params,
  7020. tmp.defaults,
  7021. body,
  7022. tmp.rest,
  7023. generator,
  7024. false,
  7025. isAsync,
  7026. tmp.returnType,
  7027. typeParameters
  7028. )
  7029. );
  7030. }
  7031. function parseFunctionExpression() {
  7032. var token, id = null, firstRestricted, message, tmp, body, generator, isAsync,
  7033. previousStrict, previousYieldAllowed, previousAwaitAllowed,
  7034. marker = markerCreate(), typeParameters;
  7035. isAsync = false;
  7036. if (matchAsync()) {
  7037. lex();
  7038. isAsync = true;
  7039. }
  7040. expectKeyword('function');
  7041. generator = false;
  7042. if (match('*')) {
  7043. lex();
  7044. generator = true;
  7045. }
  7046. if (!match('(')) {
  7047. if (!match('<')) {
  7048. token = lookahead;
  7049. id = parseVariableIdentifier();
  7050. if (strict) {
  7051. if (isRestrictedWord(token.value)) {
  7052. throwErrorTolerant(token, Messages.StrictFunctionName);
  7053. }
  7054. } else {
  7055. if (isRestrictedWord(token.value)) {
  7056. firstRestricted = token;
  7057. message = Messages.StrictFunctionName;
  7058. } else if (isStrictModeReservedWord(token.value)) {
  7059. firstRestricted = token;
  7060. message = Messages.StrictReservedWord;
  7061. }
  7062. }
  7063. }
  7064. if (match('<')) {
  7065. typeParameters = parseTypeParameterDeclaration();
  7066. }
  7067. }
  7068. tmp = parseParams(firstRestricted);
  7069. firstRestricted = tmp.firstRestricted;
  7070. if (tmp.message) {
  7071. message = tmp.message;
  7072. }
  7073. previousStrict = strict;
  7074. previousYieldAllowed = state.yieldAllowed;
  7075. state.yieldAllowed = generator;
  7076. previousAwaitAllowed = state.awaitAllowed;
  7077. state.awaitAllowed = isAsync;
  7078. body = parseFunctionSourceElements();
  7079. if (strict && firstRestricted) {
  7080. throwError(firstRestricted, message);
  7081. }
  7082. if (strict && tmp.stricted) {
  7083. throwErrorTolerant(tmp.stricted, message);
  7084. }
  7085. strict = previousStrict;
  7086. state.yieldAllowed = previousYieldAllowed;
  7087. state.awaitAllowed = previousAwaitAllowed;
  7088. return markerApply(
  7089. marker,
  7090. delegate.createFunctionExpression(
  7091. id,
  7092. tmp.params,
  7093. tmp.defaults,
  7094. body,
  7095. tmp.rest,
  7096. generator,
  7097. false,
  7098. isAsync,
  7099. tmp.returnType,
  7100. typeParameters
  7101. )
  7102. );
  7103. }
  7104. function parseYieldExpression() {
  7105. var delegateFlag, expr, marker = markerCreate();
  7106. expectKeyword('yield', !strict);
  7107. delegateFlag = false;
  7108. if (match('*')) {
  7109. lex();
  7110. delegateFlag = true;
  7111. }
  7112. expr = parseAssignmentExpression();
  7113. return markerApply(marker, delegate.createYieldExpression(expr, delegateFlag));
  7114. }
  7115. function parseAwaitExpression() {
  7116. var expr, marker = markerCreate();
  7117. expectContextualKeyword('await');
  7118. expr = parseAssignmentExpression();
  7119. return markerApply(marker, delegate.createAwaitExpression(expr));
  7120. }
  7121. // 14 Functions and classes
  7122. // 14.1 Functions is defined above (13 in ES5)
  7123. // 14.2 Arrow Functions Definitions is defined in (7.3 assignments)
  7124. // 14.3 Method Definitions
  7125. // 14.3.7
  7126. function specialMethod(methodDefinition) {
  7127. return methodDefinition.kind === 'get' ||
  7128. methodDefinition.kind === 'set' ||
  7129. methodDefinition.value.generator;
  7130. }
  7131. function parseMethodDefinition(key, isStatic, generator, computed) {
  7132. var token, param, propType,
  7133. isAsync, typeParameters, tokenValue, returnType;
  7134. propType = isStatic ? ClassPropertyType["static"] : ClassPropertyType.prototype;
  7135. if (generator) {
  7136. return delegate.createMethodDefinition(
  7137. propType,
  7138. '',
  7139. key,
  7140. parsePropertyMethodFunction({ generator: true }),
  7141. computed
  7142. );
  7143. }
  7144. tokenValue = key.type === 'Identifier' && key.name;
  7145. if (tokenValue === 'get' && !match('(')) {
  7146. key = parseObjectPropertyKey();
  7147. expect('(');
  7148. expect(')');
  7149. if (match(':')) {
  7150. returnType = parseTypeAnnotation();
  7151. }
  7152. return delegate.createMethodDefinition(
  7153. propType,
  7154. 'get',
  7155. key,
  7156. parsePropertyFunction({ generator: false, returnType: returnType }),
  7157. computed
  7158. );
  7159. }
  7160. if (tokenValue === 'set' && !match('(')) {
  7161. key = parseObjectPropertyKey();
  7162. expect('(');
  7163. token = lookahead;
  7164. param = [ parseTypeAnnotatableIdentifier() ];
  7165. expect(')');
  7166. if (match(':')) {
  7167. returnType = parseTypeAnnotation();
  7168. }
  7169. return delegate.createMethodDefinition(
  7170. propType,
  7171. 'set',
  7172. key,
  7173. parsePropertyFunction({
  7174. params: param,
  7175. generator: false,
  7176. name: token,
  7177. returnType: returnType
  7178. }),
  7179. computed
  7180. );
  7181. }
  7182. if (match('<')) {
  7183. typeParameters = parseTypeParameterDeclaration();
  7184. }
  7185. isAsync = tokenValue === 'async' && !match('(');
  7186. if (isAsync) {
  7187. key = parseObjectPropertyKey();
  7188. }
  7189. return delegate.createMethodDefinition(
  7190. propType,
  7191. '',
  7192. key,
  7193. parsePropertyMethodFunction({
  7194. generator: false,
  7195. async: isAsync,
  7196. typeParameters: typeParameters
  7197. }),
  7198. computed
  7199. );
  7200. }
  7201. function parseClassProperty(key, computed, isStatic) {
  7202. var typeAnnotation;
  7203. typeAnnotation = parseTypeAnnotation();
  7204. expect(';');
  7205. return delegate.createClassProperty(
  7206. key,
  7207. typeAnnotation,
  7208. computed,
  7209. isStatic
  7210. );
  7211. }
  7212. function parseClassElement() {
  7213. var computed = false, generator = false, key, marker = markerCreate(),
  7214. isStatic = false, possiblyOpenBracketToken;
  7215. if (match(';')) {
  7216. lex();
  7217. return undefined;
  7218. }
  7219. if (lookahead.value === 'static') {
  7220. lex();
  7221. isStatic = true;
  7222. }
  7223. if (match('*')) {
  7224. lex();
  7225. generator = true;
  7226. }
  7227. possiblyOpenBracketToken = lookahead;
  7228. if (matchContextualKeyword('get') || matchContextualKeyword('set')) {
  7229. possiblyOpenBracketToken = lookahead2();
  7230. }
  7231. if (possiblyOpenBracketToken.type === Token.Punctuator
  7232. && possiblyOpenBracketToken.value === '[') {
  7233. computed = true;
  7234. }
  7235. key = parseObjectPropertyKey();
  7236. if (!generator && lookahead.value === ':') {
  7237. return markerApply(marker, parseClassProperty(key, computed, isStatic));
  7238. }
  7239. return markerApply(marker, parseMethodDefinition(
  7240. key,
  7241. isStatic,
  7242. generator,
  7243. computed
  7244. ));
  7245. }
  7246. function parseClassBody() {
  7247. var classElement, classElements = [], existingProps = {},
  7248. marker = markerCreate(), propName, propType;
  7249. existingProps[ClassPropertyType["static"]] = new StringMap();
  7250. existingProps[ClassPropertyType.prototype] = new StringMap();
  7251. expect('{');
  7252. while (index < length) {
  7253. if (match('}')) {
  7254. break;
  7255. }
  7256. classElement = parseClassElement(existingProps);
  7257. if (typeof classElement !== 'undefined') {
  7258. classElements.push(classElement);
  7259. propName = !classElement.computed && getFieldName(classElement.key);
  7260. if (propName !== false) {
  7261. propType = classElement["static"] ?
  7262. ClassPropertyType["static"] :
  7263. ClassPropertyType.prototype;
  7264. if (classElement.type === Syntax.MethodDefinition) {
  7265. if (propName === 'constructor' && !classElement["static"]) {
  7266. if (specialMethod(classElement)) {
  7267. throwError(classElement, Messages.IllegalClassConstructorProperty);
  7268. }
  7269. if (existingProps[ClassPropertyType.prototype].has('constructor')) {
  7270. throwError(classElement.key, Messages.IllegalDuplicateClassProperty);
  7271. }
  7272. }
  7273. existingProps[propType].set(propName, true);
  7274. }
  7275. }
  7276. }
  7277. }
  7278. expect('}');
  7279. return markerApply(marker, delegate.createClassBody(classElements));
  7280. }
  7281. function parseClassImplements() {
  7282. var id, implemented = [], marker, typeParameters;
  7283. if (strict) {
  7284. expectKeyword('implements');
  7285. } else {
  7286. expectContextualKeyword('implements');
  7287. }
  7288. while (index < length) {
  7289. marker = markerCreate();
  7290. id = parseVariableIdentifier();
  7291. if (match('<')) {
  7292. typeParameters = parseTypeParameterInstantiation();
  7293. } else {
  7294. typeParameters = null;
  7295. }
  7296. implemented.push(markerApply(marker, delegate.createClassImplements(
  7297. id,
  7298. typeParameters
  7299. )));
  7300. if (!match(',')) {
  7301. break;
  7302. }
  7303. expect(',');
  7304. }
  7305. return implemented;
  7306. }
  7307. function parseClassExpression() {
  7308. var id, implemented, previousYieldAllowed, superClass = null,
  7309. superTypeParameters, marker = markerCreate(), typeParameters,
  7310. matchImplements;
  7311. expectKeyword('class');
  7312. matchImplements =
  7313. strict
  7314. ? matchKeyword('implements')
  7315. : matchContextualKeyword('implements');
  7316. if (!matchKeyword('extends') && !matchImplements && !match('{')) {
  7317. id = parseVariableIdentifier();
  7318. }
  7319. if (match('<')) {
  7320. typeParameters = parseTypeParameterDeclaration();
  7321. }
  7322. if (matchKeyword('extends')) {
  7323. expectKeyword('extends');
  7324. previousYieldAllowed = state.yieldAllowed;
  7325. state.yieldAllowed = false;
  7326. superClass = parseLeftHandSideExpressionAllowCall();
  7327. if (match('<')) {
  7328. superTypeParameters = parseTypeParameterInstantiation();
  7329. }
  7330. state.yieldAllowed = previousYieldAllowed;
  7331. }
  7332. if (strict ? matchKeyword('implements') : matchContextualKeyword('implements')) {
  7333. implemented = parseClassImplements();
  7334. }
  7335. return markerApply(marker, delegate.createClassExpression(
  7336. id,
  7337. superClass,
  7338. parseClassBody(),
  7339. typeParameters,
  7340. superTypeParameters,
  7341. implemented
  7342. ));
  7343. }
  7344. function parseClassDeclaration() {
  7345. var id, implemented, previousYieldAllowed, superClass = null,
  7346. superTypeParameters, marker = markerCreate(), typeParameters;
  7347. expectKeyword('class');
  7348. id = parseVariableIdentifier();
  7349. if (match('<')) {
  7350. typeParameters = parseTypeParameterDeclaration();
  7351. }
  7352. if (matchKeyword('extends')) {
  7353. expectKeyword('extends');
  7354. previousYieldAllowed = state.yieldAllowed;
  7355. state.yieldAllowed = false;
  7356. superClass = parseLeftHandSideExpressionAllowCall();
  7357. if (match('<')) {
  7358. superTypeParameters = parseTypeParameterInstantiation();
  7359. }
  7360. state.yieldAllowed = previousYieldAllowed;
  7361. }
  7362. if (strict ? matchKeyword('implements') : matchContextualKeyword('implements')) {
  7363. implemented = parseClassImplements();
  7364. }
  7365. return markerApply(marker, delegate.createClassDeclaration(
  7366. id,
  7367. superClass,
  7368. parseClassBody(),
  7369. typeParameters,
  7370. superTypeParameters,
  7371. implemented
  7372. ));
  7373. }
  7374. // 15 Program
  7375. function parseSourceElement() {
  7376. var token;
  7377. if (lookahead.type === Token.Keyword) {
  7378. switch (lookahead.value) {
  7379. case 'const':
  7380. case 'let':
  7381. return parseConstLetDeclaration(lookahead.value);
  7382. case 'function':
  7383. return parseFunctionDeclaration();
  7384. case 'export':
  7385. throwErrorTolerant({}, Messages.IllegalExportDeclaration);
  7386. return parseExportDeclaration();
  7387. case 'import':
  7388. throwErrorTolerant({}, Messages.IllegalImportDeclaration);
  7389. return parseImportDeclaration();
  7390. case 'interface':
  7391. if (lookahead2().type === Token.Identifier) {
  7392. return parseInterface();
  7393. }
  7394. return parseStatement();
  7395. default:
  7396. return parseStatement();
  7397. }
  7398. }
  7399. if (matchContextualKeyword('type')
  7400. && lookahead2().type === Token.Identifier) {
  7401. return parseTypeAlias();
  7402. }
  7403. if (matchContextualKeyword('interface')
  7404. && lookahead2().type === Token.Identifier) {
  7405. return parseInterface();
  7406. }
  7407. if (matchContextualKeyword('declare')) {
  7408. token = lookahead2();
  7409. if (token.type === Token.Keyword) {
  7410. switch (token.value) {
  7411. case 'class':
  7412. return parseDeclareClass();
  7413. case 'function':
  7414. return parseDeclareFunction();
  7415. case 'var':
  7416. return parseDeclareVariable();
  7417. }
  7418. } else if (token.type === Token.Identifier
  7419. && token.value === 'module') {
  7420. return parseDeclareModule();
  7421. }
  7422. }
  7423. if (lookahead.type !== Token.EOF) {
  7424. return parseStatement();
  7425. }
  7426. }
  7427. function parseProgramElement() {
  7428. var isModule = extra.sourceType === 'module' || extra.sourceType === 'nonStrictModule';
  7429. if (isModule && lookahead.type === Token.Keyword) {
  7430. switch (lookahead.value) {
  7431. case 'export':
  7432. return parseExportDeclaration();
  7433. case 'import':
  7434. return parseImportDeclaration();
  7435. }
  7436. }
  7437. return parseSourceElement();
  7438. }
  7439. function parseProgramElements() {
  7440. var sourceElement, sourceElements = [], token, directive, firstRestricted;
  7441. while (index < length) {
  7442. token = lookahead;
  7443. if (token.type !== Token.StringLiteral) {
  7444. break;
  7445. }
  7446. sourceElement = parseProgramElement();
  7447. sourceElements.push(sourceElement);
  7448. if (sourceElement.expression.type !== Syntax.Literal) {
  7449. // this is not directive
  7450. break;
  7451. }
  7452. directive = source.slice(token.range[0] + 1, token.range[1] - 1);
  7453. if (directive === 'use strict') {
  7454. strict = true;
  7455. if (firstRestricted) {
  7456. throwErrorTolerant(firstRestricted, Messages.StrictOctalLiteral);
  7457. }
  7458. } else {
  7459. if (!firstRestricted && token.octal) {
  7460. firstRestricted = token;
  7461. }
  7462. }
  7463. }
  7464. while (index < length) {
  7465. sourceElement = parseProgramElement();
  7466. if (typeof sourceElement === 'undefined') {
  7467. break;
  7468. }
  7469. sourceElements.push(sourceElement);
  7470. }
  7471. return sourceElements;
  7472. }
  7473. function parseProgram() {
  7474. var body, marker = markerCreate();
  7475. strict = extra.sourceType === 'module';
  7476. peek();
  7477. body = parseProgramElements();
  7478. return markerApply(marker, delegate.createProgram(body));
  7479. }
  7480. // 16 JSX
  7481. XHTMLEntities = {
  7482. quot: '\u0022',
  7483. amp: '&',
  7484. apos: '\u0027',
  7485. lt: '<',
  7486. gt: '>',
  7487. nbsp: '\u00A0',
  7488. iexcl: '\u00A1',
  7489. cent: '\u00A2',
  7490. pound: '\u00A3',
  7491. curren: '\u00A4',
  7492. yen: '\u00A5',
  7493. brvbar: '\u00A6',
  7494. sect: '\u00A7',
  7495. uml: '\u00A8',
  7496. copy: '\u00A9',
  7497. ordf: '\u00AA',
  7498. laquo: '\u00AB',
  7499. not: '\u00AC',
  7500. shy: '\u00AD',
  7501. reg: '\u00AE',
  7502. macr: '\u00AF',
  7503. deg: '\u00B0',
  7504. plusmn: '\u00B1',
  7505. sup2: '\u00B2',
  7506. sup3: '\u00B3',
  7507. acute: '\u00B4',
  7508. micro: '\u00B5',
  7509. para: '\u00B6',
  7510. middot: '\u00B7',
  7511. cedil: '\u00B8',
  7512. sup1: '\u00B9',
  7513. ordm: '\u00BA',
  7514. raquo: '\u00BB',
  7515. frac14: '\u00BC',
  7516. frac12: '\u00BD',
  7517. frac34: '\u00BE',
  7518. iquest: '\u00BF',
  7519. Agrave: '\u00C0',
  7520. Aacute: '\u00C1',
  7521. Acirc: '\u00C2',
  7522. Atilde: '\u00C3',
  7523. Auml: '\u00C4',
  7524. Aring: '\u00C5',
  7525. AElig: '\u00C6',
  7526. Ccedil: '\u00C7',
  7527. Egrave: '\u00C8',
  7528. Eacute: '\u00C9',
  7529. Ecirc: '\u00CA',
  7530. Euml: '\u00CB',
  7531. Igrave: '\u00CC',
  7532. Iacute: '\u00CD',
  7533. Icirc: '\u00CE',
  7534. Iuml: '\u00CF',
  7535. ETH: '\u00D0',
  7536. Ntilde: '\u00D1',
  7537. Ograve: '\u00D2',
  7538. Oacute: '\u00D3',
  7539. Ocirc: '\u00D4',
  7540. Otilde: '\u00D5',
  7541. Ouml: '\u00D6',
  7542. times: '\u00D7',
  7543. Oslash: '\u00D8',
  7544. Ugrave: '\u00D9',
  7545. Uacute: '\u00DA',
  7546. Ucirc: '\u00DB',
  7547. Uuml: '\u00DC',
  7548. Yacute: '\u00DD',
  7549. THORN: '\u00DE',
  7550. szlig: '\u00DF',
  7551. agrave: '\u00E0',
  7552. aacute: '\u00E1',
  7553. acirc: '\u00E2',
  7554. atilde: '\u00E3',
  7555. auml: '\u00E4',
  7556. aring: '\u00E5',
  7557. aelig: '\u00E6',
  7558. ccedil: '\u00E7',
  7559. egrave: '\u00E8',
  7560. eacute: '\u00E9',
  7561. ecirc: '\u00EA',
  7562. euml: '\u00EB',
  7563. igrave: '\u00EC',
  7564. iacute: '\u00ED',
  7565. icirc: '\u00EE',
  7566. iuml: '\u00EF',
  7567. eth: '\u00F0',
  7568. ntilde: '\u00F1',
  7569. ograve: '\u00F2',
  7570. oacute: '\u00F3',
  7571. ocirc: '\u00F4',
  7572. otilde: '\u00F5',
  7573. ouml: '\u00F6',
  7574. divide: '\u00F7',
  7575. oslash: '\u00F8',
  7576. ugrave: '\u00F9',
  7577. uacute: '\u00FA',
  7578. ucirc: '\u00FB',
  7579. uuml: '\u00FC',
  7580. yacute: '\u00FD',
  7581. thorn: '\u00FE',
  7582. yuml: '\u00FF',
  7583. OElig: '\u0152',
  7584. oelig: '\u0153',
  7585. Scaron: '\u0160',
  7586. scaron: '\u0161',
  7587. Yuml: '\u0178',
  7588. fnof: '\u0192',
  7589. circ: '\u02C6',
  7590. tilde: '\u02DC',
  7591. Alpha: '\u0391',
  7592. Beta: '\u0392',
  7593. Gamma: '\u0393',
  7594. Delta: '\u0394',
  7595. Epsilon: '\u0395',
  7596. Zeta: '\u0396',
  7597. Eta: '\u0397',
  7598. Theta: '\u0398',
  7599. Iota: '\u0399',
  7600. Kappa: '\u039A',
  7601. Lambda: '\u039B',
  7602. Mu: '\u039C',
  7603. Nu: '\u039D',
  7604. Xi: '\u039E',
  7605. Omicron: '\u039F',
  7606. Pi: '\u03A0',
  7607. Rho: '\u03A1',
  7608. Sigma: '\u03A3',
  7609. Tau: '\u03A4',
  7610. Upsilon: '\u03A5',
  7611. Phi: '\u03A6',
  7612. Chi: '\u03A7',
  7613. Psi: '\u03A8',
  7614. Omega: '\u03A9',
  7615. alpha: '\u03B1',
  7616. beta: '\u03B2',
  7617. gamma: '\u03B3',
  7618. delta: '\u03B4',
  7619. epsilon: '\u03B5',
  7620. zeta: '\u03B6',
  7621. eta: '\u03B7',
  7622. theta: '\u03B8',
  7623. iota: '\u03B9',
  7624. kappa: '\u03BA',
  7625. lambda: '\u03BB',
  7626. mu: '\u03BC',
  7627. nu: '\u03BD',
  7628. xi: '\u03BE',
  7629. omicron: '\u03BF',
  7630. pi: '\u03C0',
  7631. rho: '\u03C1',
  7632. sigmaf: '\u03C2',
  7633. sigma: '\u03C3',
  7634. tau: '\u03C4',
  7635. upsilon: '\u03C5',
  7636. phi: '\u03C6',
  7637. chi: '\u03C7',
  7638. psi: '\u03C8',
  7639. omega: '\u03C9',
  7640. thetasym: '\u03D1',
  7641. upsih: '\u03D2',
  7642. piv: '\u03D6',
  7643. ensp: '\u2002',
  7644. emsp: '\u2003',
  7645. thinsp: '\u2009',
  7646. zwnj: '\u200C',
  7647. zwj: '\u200D',
  7648. lrm: '\u200E',
  7649. rlm: '\u200F',
  7650. ndash: '\u2013',
  7651. mdash: '\u2014',
  7652. lsquo: '\u2018',
  7653. rsquo: '\u2019',
  7654. sbquo: '\u201A',
  7655. ldquo: '\u201C',
  7656. rdquo: '\u201D',
  7657. bdquo: '\u201E',
  7658. dagger: '\u2020',
  7659. Dagger: '\u2021',
  7660. bull: '\u2022',
  7661. hellip: '\u2026',
  7662. permil: '\u2030',
  7663. prime: '\u2032',
  7664. Prime: '\u2033',
  7665. lsaquo: '\u2039',
  7666. rsaquo: '\u203A',
  7667. oline: '\u203E',
  7668. frasl: '\u2044',
  7669. euro: '\u20AC',
  7670. image: '\u2111',
  7671. weierp: '\u2118',
  7672. real: '\u211C',
  7673. trade: '\u2122',
  7674. alefsym: '\u2135',
  7675. larr: '\u2190',
  7676. uarr: '\u2191',
  7677. rarr: '\u2192',
  7678. darr: '\u2193',
  7679. harr: '\u2194',
  7680. crarr: '\u21B5',
  7681. lArr: '\u21D0',
  7682. uArr: '\u21D1',
  7683. rArr: '\u21D2',
  7684. dArr: '\u21D3',
  7685. hArr: '\u21D4',
  7686. forall: '\u2200',
  7687. part: '\u2202',
  7688. exist: '\u2203',
  7689. empty: '\u2205',
  7690. nabla: '\u2207',
  7691. isin: '\u2208',
  7692. notin: '\u2209',
  7693. ni: '\u220B',
  7694. prod: '\u220F',
  7695. sum: '\u2211',
  7696. minus: '\u2212',
  7697. lowast: '\u2217',
  7698. radic: '\u221A',
  7699. prop: '\u221D',
  7700. infin: '\u221E',
  7701. ang: '\u2220',
  7702. and: '\u2227',
  7703. or: '\u2228',
  7704. cap: '\u2229',
  7705. cup: '\u222A',
  7706. 'int': '\u222B',
  7707. there4: '\u2234',
  7708. sim: '\u223C',
  7709. cong: '\u2245',
  7710. asymp: '\u2248',
  7711. ne: '\u2260',
  7712. equiv: '\u2261',
  7713. le: '\u2264',
  7714. ge: '\u2265',
  7715. sub: '\u2282',
  7716. sup: '\u2283',
  7717. nsub: '\u2284',
  7718. sube: '\u2286',
  7719. supe: '\u2287',
  7720. oplus: '\u2295',
  7721. otimes: '\u2297',
  7722. perp: '\u22A5',
  7723. sdot: '\u22C5',
  7724. lceil: '\u2308',
  7725. rceil: '\u2309',
  7726. lfloor: '\u230A',
  7727. rfloor: '\u230B',
  7728. lang: '\u2329',
  7729. rang: '\u232A',
  7730. loz: '\u25CA',
  7731. spades: '\u2660',
  7732. clubs: '\u2663',
  7733. hearts: '\u2665',
  7734. diams: '\u2666'
  7735. };
  7736. function getQualifiedJSXName(object) {
  7737. if (object.type === Syntax.JSXIdentifier) {
  7738. return object.name;
  7739. }
  7740. if (object.type === Syntax.JSXNamespacedName) {
  7741. return object.namespace.name + ':' + object.name.name;
  7742. }
  7743. /* istanbul ignore else */
  7744. if (object.type === Syntax.JSXMemberExpression) {
  7745. return (
  7746. getQualifiedJSXName(object.object) + '.' +
  7747. getQualifiedJSXName(object.property)
  7748. );
  7749. }
  7750. /* istanbul ignore next */
  7751. throwUnexpected(object);
  7752. }
  7753. function isJSXIdentifierStart(ch) {
  7754. // exclude backslash (\)
  7755. return (ch !== 92) && isIdentifierStart(ch);
  7756. }
  7757. function isJSXIdentifierPart(ch) {
  7758. // exclude backslash (\) and add hyphen (-)
  7759. return (ch !== 92) && (ch === 45 || isIdentifierPart(ch));
  7760. }
  7761. function scanJSXIdentifier() {
  7762. var ch, start, value = '';
  7763. start = index;
  7764. while (index < length) {
  7765. ch = source.charCodeAt(index);
  7766. if (!isJSXIdentifierPart(ch)) {
  7767. break;
  7768. }
  7769. value += source[index++];
  7770. }
  7771. return {
  7772. type: Token.JSXIdentifier,
  7773. value: value,
  7774. lineNumber: lineNumber,
  7775. lineStart: lineStart,
  7776. range: [start, index]
  7777. };
  7778. }
  7779. function scanJSXEntity() {
  7780. var ch, str = '', start = index, count = 0, code;
  7781. ch = source[index];
  7782. assert(ch === '&', 'Entity must start with an ampersand');
  7783. index++;
  7784. while (index < length && count++ < 10) {
  7785. ch = source[index++];
  7786. if (ch === ';') {
  7787. break;
  7788. }
  7789. str += ch;
  7790. }
  7791. // Well-formed entity (ending was found).
  7792. if (ch === ';') {
  7793. // Numeric entity.
  7794. if (str[0] === '#') {
  7795. if (str[1] === 'x') {
  7796. code = +('0' + str.substr(1));
  7797. } else {
  7798. // Removing leading zeros in order to avoid treating as octal in old browsers.
  7799. code = +str.substr(1).replace(Regex.LeadingZeros, '');
  7800. }
  7801. if (!isNaN(code)) {
  7802. return String.fromCharCode(code);
  7803. }
  7804. /* istanbul ignore else */
  7805. } else if (XHTMLEntities[str]) {
  7806. return XHTMLEntities[str];
  7807. }
  7808. }
  7809. // Treat non-entity sequences as regular text.
  7810. index = start + 1;
  7811. return '&';
  7812. }
  7813. function scanJSXText(stopChars) {
  7814. var ch, str = '', start;
  7815. start = index;
  7816. while (index < length) {
  7817. ch = source[index];
  7818. if (stopChars.indexOf(ch) !== -1) {
  7819. break;
  7820. }
  7821. if (ch === '&') {
  7822. str += scanJSXEntity();
  7823. } else {
  7824. index++;
  7825. if (ch === '\r' && source[index] === '\n') {
  7826. str += ch;
  7827. ch = source[index];
  7828. index++;
  7829. }
  7830. if (isLineTerminator(ch.charCodeAt(0))) {
  7831. ++lineNumber;
  7832. lineStart = index;
  7833. }
  7834. str += ch;
  7835. }
  7836. }
  7837. return {
  7838. type: Token.JSXText,
  7839. value: str,
  7840. lineNumber: lineNumber,
  7841. lineStart: lineStart,
  7842. range: [start, index]
  7843. };
  7844. }
  7845. function scanJSXStringLiteral() {
  7846. var innerToken, quote, start;
  7847. quote = source[index];
  7848. assert((quote === '\'' || quote === '"'),
  7849. 'String literal must starts with a quote');
  7850. start = index;
  7851. ++index;
  7852. innerToken = scanJSXText([quote]);
  7853. if (quote !== source[index]) {
  7854. throwError({}, Messages.UnexpectedToken, 'ILLEGAL');
  7855. }
  7856. ++index;
  7857. innerToken.range = [start, index];
  7858. return innerToken;
  7859. }
  7860. /**
  7861. * Between JSX opening and closing tags (e.g. <foo>HERE</foo>), anything that
  7862. * is not another JSX tag and is not an expression wrapped by {} is text.
  7863. */
  7864. function advanceJSXChild() {
  7865. var ch = source.charCodeAt(index);
  7866. // '<' 60, '>' 62, '{' 123, '}' 125
  7867. if (ch !== 60 && ch !== 62 && ch !== 123 && ch !== 125) {
  7868. return scanJSXText(['<', '>', '{', '}']);
  7869. }
  7870. return scanPunctuator();
  7871. }
  7872. function parseJSXIdentifier() {
  7873. var token, marker = markerCreate();
  7874. if (lookahead.type !== Token.JSXIdentifier) {
  7875. throwUnexpected(lookahead);
  7876. }
  7877. token = lex();
  7878. return markerApply(marker, delegate.createJSXIdentifier(token.value));
  7879. }
  7880. function parseJSXNamespacedName() {
  7881. var namespace, name, marker = markerCreate();
  7882. namespace = parseJSXIdentifier();
  7883. expect(':');
  7884. name = parseJSXIdentifier();
  7885. return markerApply(marker, delegate.createJSXNamespacedName(namespace, name));
  7886. }
  7887. function parseJSXMemberExpression() {
  7888. var marker = markerCreate(),
  7889. expr = parseJSXIdentifier();
  7890. while (match('.')) {
  7891. lex();
  7892. expr = markerApply(marker, delegate.createJSXMemberExpression(expr, parseJSXIdentifier()));
  7893. }
  7894. return expr;
  7895. }
  7896. function parseJSXElementName() {
  7897. if (lookahead2().value === ':') {
  7898. return parseJSXNamespacedName();
  7899. }
  7900. if (lookahead2().value === '.') {
  7901. return parseJSXMemberExpression();
  7902. }
  7903. return parseJSXIdentifier();
  7904. }
  7905. function parseJSXAttributeName() {
  7906. if (lookahead2().value === ':') {
  7907. return parseJSXNamespacedName();
  7908. }
  7909. return parseJSXIdentifier();
  7910. }
  7911. function parseJSXAttributeValue() {
  7912. var value, marker;
  7913. if (match('{')) {
  7914. value = parseJSXExpressionContainer();
  7915. if (value.expression.type === Syntax.JSXEmptyExpression) {
  7916. throwError(
  7917. value,
  7918. 'JSX attributes must only be assigned a non-empty ' +
  7919. 'expression'
  7920. );
  7921. }
  7922. } else if (match('<')) {
  7923. value = parseJSXElement();
  7924. } else if (lookahead.type === Token.JSXText) {
  7925. marker = markerCreate();
  7926. value = markerApply(marker, delegate.createLiteral(lex()));
  7927. } else {
  7928. throwError({}, Messages.InvalidJSXAttributeValue);
  7929. }
  7930. return value;
  7931. }
  7932. function parseJSXEmptyExpression() {
  7933. var marker = markerCreatePreserveWhitespace();
  7934. while (source.charAt(index) !== '}') {
  7935. index++;
  7936. }
  7937. return markerApply(marker, delegate.createJSXEmptyExpression());
  7938. }
  7939. function parseJSXExpressionContainer() {
  7940. var expression, origInJSXChild, origInJSXTag, marker = markerCreate();
  7941. origInJSXChild = state.inJSXChild;
  7942. origInJSXTag = state.inJSXTag;
  7943. state.inJSXChild = false;
  7944. state.inJSXTag = false;
  7945. expect('{');
  7946. if (match('}')) {
  7947. expression = parseJSXEmptyExpression();
  7948. } else {
  7949. expression = parseExpression();
  7950. }
  7951. state.inJSXChild = origInJSXChild;
  7952. state.inJSXTag = origInJSXTag;
  7953. expect('}');
  7954. return markerApply(marker, delegate.createJSXExpressionContainer(expression));
  7955. }
  7956. function parseJSXSpreadAttribute() {
  7957. var expression, origInJSXChild, origInJSXTag, marker = markerCreate();
  7958. origInJSXChild = state.inJSXChild;
  7959. origInJSXTag = state.inJSXTag;
  7960. state.inJSXChild = false;
  7961. state.inJSXTag = false;
  7962. expect('{');
  7963. expect('...');
  7964. expression = parseAssignmentExpression();
  7965. state.inJSXChild = origInJSXChild;
  7966. state.inJSXTag = origInJSXTag;
  7967. expect('}');
  7968. return markerApply(marker, delegate.createJSXSpreadAttribute(expression));
  7969. }
  7970. function parseJSXAttribute() {
  7971. var name, marker;
  7972. if (match('{')) {
  7973. return parseJSXSpreadAttribute();
  7974. }
  7975. marker = markerCreate();
  7976. name = parseJSXAttributeName();
  7977. // HTML empty attribute
  7978. if (match('=')) {
  7979. lex();
  7980. return markerApply(marker, delegate.createJSXAttribute(name, parseJSXAttributeValue()));
  7981. }
  7982. return markerApply(marker, delegate.createJSXAttribute(name));
  7983. }
  7984. function parseJSXChild() {
  7985. var token, marker;
  7986. if (match('{')) {
  7987. token = parseJSXExpressionContainer();
  7988. } else if (lookahead.type === Token.JSXText) {
  7989. marker = markerCreatePreserveWhitespace();
  7990. token = markerApply(marker, delegate.createLiteral(lex()));
  7991. } else if (match('<')) {
  7992. token = parseJSXElement();
  7993. } else {
  7994. throwUnexpected(lookahead);
  7995. }
  7996. return token;
  7997. }
  7998. function parseJSXClosingElement() {
  7999. var name, origInJSXChild, origInJSXTag, marker = markerCreate();
  8000. origInJSXChild = state.inJSXChild;
  8001. origInJSXTag = state.inJSXTag;
  8002. state.inJSXChild = false;
  8003. state.inJSXTag = true;
  8004. expect('<');
  8005. expect('/');
  8006. name = parseJSXElementName();
  8007. // Because advance() (called by lex() called by expect()) expects there
  8008. // to be a valid token after >, it needs to know whether to look for a
  8009. // standard JS token or an JSX text node
  8010. state.inJSXChild = origInJSXChild;
  8011. state.inJSXTag = origInJSXTag;
  8012. expect('>');
  8013. return markerApply(marker, delegate.createJSXClosingElement(name));
  8014. }
  8015. function parseJSXOpeningElement() {
  8016. var name, attributes = [], selfClosing = false, origInJSXChild, origInJSXTag, marker = markerCreate();
  8017. origInJSXChild = state.inJSXChild;
  8018. origInJSXTag = state.inJSXTag;
  8019. state.inJSXChild = false;
  8020. state.inJSXTag = true;
  8021. expect('<');
  8022. name = parseJSXElementName();
  8023. while (index < length &&
  8024. lookahead.value !== '/' &&
  8025. lookahead.value !== '>') {
  8026. attributes.push(parseJSXAttribute());
  8027. }
  8028. state.inJSXTag = origInJSXTag;
  8029. if (lookahead.value === '/') {
  8030. expect('/');
  8031. // Because advance() (called by lex() called by expect()) expects
  8032. // there to be a valid token after >, it needs to know whether to
  8033. // look for a standard JS token or an JSX text node
  8034. state.inJSXChild = origInJSXChild;
  8035. expect('>');
  8036. selfClosing = true;
  8037. } else {
  8038. state.inJSXChild = true;
  8039. expect('>');
  8040. }
  8041. return markerApply(marker, delegate.createJSXOpeningElement(name, attributes, selfClosing));
  8042. }
  8043. function parseJSXElement() {
  8044. var openingElement, closingElement = null, children = [], origInJSXChild, origInJSXTag, marker = markerCreate();
  8045. origInJSXChild = state.inJSXChild;
  8046. origInJSXTag = state.inJSXTag;
  8047. openingElement = parseJSXOpeningElement();
  8048. if (!openingElement.selfClosing) {
  8049. while (index < length) {
  8050. state.inJSXChild = false; // Call lookahead2() with inJSXChild = false because </ should not be considered in the child
  8051. if (lookahead.value === '<' && lookahead2().value === '/') {
  8052. break;
  8053. }
  8054. state.inJSXChild = true;
  8055. children.push(parseJSXChild());
  8056. }
  8057. state.inJSXChild = origInJSXChild;
  8058. state.inJSXTag = origInJSXTag;
  8059. closingElement = parseJSXClosingElement();
  8060. if (getQualifiedJSXName(closingElement.name) !== getQualifiedJSXName(openingElement.name)) {
  8061. throwError({}, Messages.ExpectedJSXClosingTag, getQualifiedJSXName(openingElement.name));
  8062. }
  8063. }
  8064. // When (erroneously) writing two adjacent tags like
  8065. //
  8066. // var x = <div>one</div><div>two</div>;
  8067. //
  8068. // the default error message is a bit incomprehensible. Since it's
  8069. // rarely (never?) useful to write a less-than sign after an JSX
  8070. // element, we disallow it here in the parser in order to provide a
  8071. // better error message. (In the rare case that the less-than operator
  8072. // was intended, the left tag can be wrapped in parentheses.)
  8073. if (!origInJSXChild && match('<')) {
  8074. throwError(lookahead, Messages.AdjacentJSXElements);
  8075. }
  8076. return markerApply(marker, delegate.createJSXElement(openingElement, closingElement, children));
  8077. }
  8078. function parseTypeAlias() {
  8079. var id, marker = markerCreate(), typeParameters = null, right;
  8080. expectContextualKeyword('type');
  8081. id = parseVariableIdentifier();
  8082. if (match('<')) {
  8083. typeParameters = parseTypeParameterDeclaration();
  8084. }
  8085. expect('=');
  8086. right = parseType();
  8087. consumeSemicolon();
  8088. return markerApply(marker, delegate.createTypeAlias(id, typeParameters, right));
  8089. }
  8090. function parseInterfaceExtends() {
  8091. var marker = markerCreate(), id, typeParameters = null;
  8092. id = parseVariableIdentifier();
  8093. if (match('<')) {
  8094. typeParameters = parseTypeParameterInstantiation();
  8095. }
  8096. return markerApply(marker, delegate.createInterfaceExtends(
  8097. id,
  8098. typeParameters
  8099. ));
  8100. }
  8101. function parseInterfaceish(marker, allowStatic) {
  8102. var body, bodyMarker, extended = [], id,
  8103. typeParameters = null;
  8104. id = parseVariableIdentifier();
  8105. if (match('<')) {
  8106. typeParameters = parseTypeParameterDeclaration();
  8107. }
  8108. if (matchKeyword('extends')) {
  8109. expectKeyword('extends');
  8110. while (index < length) {
  8111. extended.push(parseInterfaceExtends());
  8112. if (!match(',')) {
  8113. break;
  8114. }
  8115. expect(',');
  8116. }
  8117. }
  8118. bodyMarker = markerCreate();
  8119. body = markerApply(bodyMarker, parseObjectType(allowStatic));
  8120. return markerApply(marker, delegate.createInterface(
  8121. id,
  8122. typeParameters,
  8123. body,
  8124. extended
  8125. ));
  8126. }
  8127. function parseInterface() {
  8128. var marker = markerCreate();
  8129. if (strict) {
  8130. expectKeyword('interface');
  8131. } else {
  8132. expectContextualKeyword('interface');
  8133. }
  8134. return parseInterfaceish(marker, /* allowStatic */false);
  8135. }
  8136. function parseDeclareClass() {
  8137. var marker = markerCreate(), ret;
  8138. expectContextualKeyword('declare');
  8139. expectKeyword('class');
  8140. ret = parseInterfaceish(marker, /* allowStatic */true);
  8141. ret.type = Syntax.DeclareClass;
  8142. return ret;
  8143. }
  8144. function parseDeclareFunction() {
  8145. var id, idMarker,
  8146. marker = markerCreate(), params, returnType, rest, tmp,
  8147. typeParameters = null, value, valueMarker;
  8148. expectContextualKeyword('declare');
  8149. expectKeyword('function');
  8150. idMarker = markerCreate();
  8151. id = parseVariableIdentifier();
  8152. valueMarker = markerCreate();
  8153. if (match('<')) {
  8154. typeParameters = parseTypeParameterDeclaration();
  8155. }
  8156. expect('(');
  8157. tmp = parseFunctionTypeParams();
  8158. params = tmp.params;
  8159. rest = tmp.rest;
  8160. expect(')');
  8161. expect(':');
  8162. returnType = parseType();
  8163. value = markerApply(valueMarker, delegate.createFunctionTypeAnnotation(
  8164. params,
  8165. returnType,
  8166. rest,
  8167. typeParameters
  8168. ));
  8169. id.typeAnnotation = markerApply(valueMarker, delegate.createTypeAnnotation(
  8170. value
  8171. ));
  8172. markerApply(idMarker, id);
  8173. consumeSemicolon();
  8174. return markerApply(marker, delegate.createDeclareFunction(
  8175. id
  8176. ));
  8177. }
  8178. function parseDeclareVariable() {
  8179. var id, marker = markerCreate();
  8180. expectContextualKeyword('declare');
  8181. expectKeyword('var');
  8182. id = parseTypeAnnotatableIdentifier();
  8183. consumeSemicolon();
  8184. return markerApply(marker, delegate.createDeclareVariable(
  8185. id
  8186. ));
  8187. }
  8188. function parseDeclareModule() {
  8189. var body = [], bodyMarker, id, idMarker, marker = markerCreate(), token;
  8190. expectContextualKeyword('declare');
  8191. expectContextualKeyword('module');
  8192. if (lookahead.type === Token.StringLiteral) {
  8193. if (strict && lookahead.octal) {
  8194. throwErrorTolerant(lookahead, Messages.StrictOctalLiteral);
  8195. }
  8196. idMarker = markerCreate();
  8197. id = markerApply(idMarker, delegate.createLiteral(lex()));
  8198. } else {
  8199. id = parseVariableIdentifier();
  8200. }
  8201. bodyMarker = markerCreate();
  8202. expect('{');
  8203. while (index < length && !match('}')) {
  8204. token = lookahead2();
  8205. switch (token.value) {
  8206. case 'class':
  8207. body.push(parseDeclareClass());
  8208. break;
  8209. case 'function':
  8210. body.push(parseDeclareFunction());
  8211. break;
  8212. case 'var':
  8213. body.push(parseDeclareVariable());
  8214. break;
  8215. default:
  8216. throwUnexpected(lookahead);
  8217. }
  8218. }
  8219. expect('}');
  8220. return markerApply(marker, delegate.createDeclareModule(
  8221. id,
  8222. markerApply(bodyMarker, delegate.createBlockStatement(body))
  8223. ));
  8224. }
  8225. function collectToken() {
  8226. var loc, token, range, value, entry;
  8227. /* istanbul ignore else */
  8228. if (!state.inJSXChild) {
  8229. skipComment();
  8230. }
  8231. loc = {
  8232. start: {
  8233. line: lineNumber,
  8234. column: index - lineStart
  8235. }
  8236. };
  8237. token = extra.advance();
  8238. loc.end = {
  8239. line: lineNumber,
  8240. column: index - lineStart
  8241. };
  8242. if (token.type !== Token.EOF) {
  8243. range = [token.range[0], token.range[1]];
  8244. value = source.slice(token.range[0], token.range[1]);
  8245. entry = {
  8246. type: TokenName[token.type],
  8247. value: value,
  8248. range: range,
  8249. loc: loc
  8250. };
  8251. if (token.regex) {
  8252. entry.regex = {
  8253. pattern: token.regex.pattern,
  8254. flags: token.regex.flags
  8255. };
  8256. }
  8257. extra.tokens.push(entry);
  8258. }
  8259. return token;
  8260. }
  8261. function collectRegex() {
  8262. var pos, loc, regex, token;
  8263. skipComment();
  8264. pos = index;
  8265. loc = {
  8266. start: {
  8267. line: lineNumber,
  8268. column: index - lineStart
  8269. }
  8270. };
  8271. regex = extra.scanRegExp();
  8272. loc.end = {
  8273. line: lineNumber,
  8274. column: index - lineStart
  8275. };
  8276. if (!extra.tokenize) {
  8277. /* istanbul ignore next */
  8278. // Pop the previous token, which is likely '/' or '/='
  8279. if (extra.tokens.length > 0) {
  8280. token = extra.tokens[extra.tokens.length - 1];
  8281. if (token.range[0] === pos && token.type === 'Punctuator') {
  8282. if (token.value === '/' || token.value === '/=') {
  8283. extra.tokens.pop();
  8284. }
  8285. }
  8286. }
  8287. extra.tokens.push({
  8288. type: 'RegularExpression',
  8289. value: regex.literal,
  8290. regex: regex.regex,
  8291. range: [pos, index],
  8292. loc: loc
  8293. });
  8294. }
  8295. return regex;
  8296. }
  8297. function filterTokenLocation() {
  8298. var i, entry, token, tokens = [];
  8299. for (i = 0; i < extra.tokens.length; ++i) {
  8300. entry = extra.tokens[i];
  8301. token = {
  8302. type: entry.type,
  8303. value: entry.value
  8304. };
  8305. if (entry.regex) {
  8306. token.regex = {
  8307. pattern: entry.regex.pattern,
  8308. flags: entry.regex.flags
  8309. };
  8310. }
  8311. if (extra.range) {
  8312. token.range = entry.range;
  8313. }
  8314. if (extra.loc) {
  8315. token.loc = entry.loc;
  8316. }
  8317. tokens.push(token);
  8318. }
  8319. extra.tokens = tokens;
  8320. }
  8321. function patch() {
  8322. if (typeof extra.tokens !== 'undefined') {
  8323. extra.advance = advance;
  8324. extra.scanRegExp = scanRegExp;
  8325. advance = collectToken;
  8326. scanRegExp = collectRegex;
  8327. }
  8328. }
  8329. function unpatch() {
  8330. if (typeof extra.scanRegExp === 'function') {
  8331. advance = extra.advance;
  8332. scanRegExp = extra.scanRegExp;
  8333. }
  8334. }
  8335. // This is used to modify the delegate.
  8336. function extend(object, properties) {
  8337. var entry, result = {};
  8338. for (entry in object) {
  8339. /* istanbul ignore else */
  8340. if (object.hasOwnProperty(entry)) {
  8341. result[entry] = object[entry];
  8342. }
  8343. }
  8344. for (entry in properties) {
  8345. /* istanbul ignore else */
  8346. if (properties.hasOwnProperty(entry)) {
  8347. result[entry] = properties[entry];
  8348. }
  8349. }
  8350. return result;
  8351. }
  8352. function tokenize(code, options) {
  8353. var toString,
  8354. token,
  8355. tokens;
  8356. toString = String;
  8357. if (typeof code !== 'string' && !(code instanceof String)) {
  8358. code = toString(code);
  8359. }
  8360. delegate = SyntaxTreeDelegate;
  8361. source = code;
  8362. index = 0;
  8363. lineNumber = (source.length > 0) ? 1 : 0;
  8364. lineStart = 0;
  8365. length = source.length;
  8366. lookahead = null;
  8367. state = {
  8368. allowKeyword: true,
  8369. allowIn: true,
  8370. labelSet: new StringMap(),
  8371. inFunctionBody: false,
  8372. inIteration: false,
  8373. inSwitch: false,
  8374. lastCommentStart: -1
  8375. };
  8376. extra = {};
  8377. // Options matching.
  8378. options = options || {};
  8379. // Of course we collect tokens here.
  8380. options.tokens = true;
  8381. extra.tokens = [];
  8382. extra.tokenize = true;
  8383. // The following two fields are necessary to compute the Regex tokens.
  8384. extra.openParenToken = -1;
  8385. extra.openCurlyToken = -1;
  8386. extra.range = (typeof options.range === 'boolean') && options.range;
  8387. extra.loc = (typeof options.loc === 'boolean') && options.loc;
  8388. if (typeof options.comment === 'boolean' && options.comment) {
  8389. extra.comments = [];
  8390. }
  8391. if (typeof options.tolerant === 'boolean' && options.tolerant) {
  8392. extra.errors = [];
  8393. }
  8394. patch();
  8395. try {
  8396. peek();
  8397. if (lookahead.type === Token.EOF) {
  8398. return extra.tokens;
  8399. }
  8400. token = lex();
  8401. while (lookahead.type !== Token.EOF) {
  8402. try {
  8403. token = lex();
  8404. } catch (lexError) {
  8405. token = lookahead;
  8406. if (extra.errors) {
  8407. extra.errors.push(lexError);
  8408. // We have to break on the first error
  8409. // to avoid infinite loops.
  8410. break;
  8411. } else {
  8412. throw lexError;
  8413. }
  8414. }
  8415. }
  8416. filterTokenLocation();
  8417. tokens = extra.tokens;
  8418. if (typeof extra.comments !== 'undefined') {
  8419. tokens.comments = extra.comments;
  8420. }
  8421. if (typeof extra.errors !== 'undefined') {
  8422. tokens.errors = extra.errors;
  8423. }
  8424. } catch (e) {
  8425. throw e;
  8426. } finally {
  8427. unpatch();
  8428. extra = {};
  8429. }
  8430. return tokens;
  8431. }
  8432. function parse(code, options) {
  8433. var program, toString;
  8434. toString = String;
  8435. if (typeof code !== 'string' && !(code instanceof String)) {
  8436. code = toString(code);
  8437. }
  8438. delegate = SyntaxTreeDelegate;
  8439. source = code;
  8440. index = 0;
  8441. lineNumber = (source.length > 0) ? 1 : 0;
  8442. lineStart = 0;
  8443. length = source.length;
  8444. lookahead = null;
  8445. state = {
  8446. allowKeyword: false,
  8447. allowIn: true,
  8448. labelSet: new StringMap(),
  8449. parenthesizedCount: 0,
  8450. inFunctionBody: false,
  8451. inIteration: false,
  8452. inSwitch: false,
  8453. inJSXChild: false,
  8454. inJSXTag: false,
  8455. inType: false,
  8456. lastCommentStart: -1,
  8457. yieldAllowed: false,
  8458. awaitAllowed: false
  8459. };
  8460. extra = {};
  8461. if (typeof options !== 'undefined') {
  8462. extra.range = (typeof options.range === 'boolean') && options.range;
  8463. extra.loc = (typeof options.loc === 'boolean') && options.loc;
  8464. extra.attachComment = (typeof options.attachComment === 'boolean') && options.attachComment;
  8465. if (extra.loc && options.source !== null && options.source !== undefined) {
  8466. delegate = extend(delegate, {
  8467. 'postProcess': function (node) {
  8468. node.loc.source = toString(options.source);
  8469. return node;
  8470. }
  8471. });
  8472. }
  8473. extra.sourceType = options.sourceType;
  8474. if (typeof options.tokens === 'boolean' && options.tokens) {
  8475. extra.tokens = [];
  8476. }
  8477. if (typeof options.comment === 'boolean' && options.comment) {
  8478. extra.comments = [];
  8479. }
  8480. if (typeof options.tolerant === 'boolean' && options.tolerant) {
  8481. extra.errors = [];
  8482. }
  8483. if (extra.attachComment) {
  8484. extra.range = true;
  8485. extra.comments = [];
  8486. extra.bottomRightStack = [];
  8487. extra.trailingComments = [];
  8488. extra.leadingComments = [];
  8489. }
  8490. }
  8491. patch();
  8492. try {
  8493. program = parseProgram();
  8494. if (typeof extra.comments !== 'undefined') {
  8495. program.comments = extra.comments;
  8496. }
  8497. if (typeof extra.tokens !== 'undefined') {
  8498. filterTokenLocation();
  8499. program.tokens = extra.tokens;
  8500. }
  8501. if (typeof extra.errors !== 'undefined') {
  8502. program.errors = extra.errors;
  8503. }
  8504. } catch (e) {
  8505. throw e;
  8506. } finally {
  8507. unpatch();
  8508. extra = {};
  8509. }
  8510. return program;
  8511. }
  8512. // Sync with *.json manifests.
  8513. exports.version = '13001.1001.0-dev-harmony-fb';
  8514. exports.tokenize = tokenize;
  8515. exports.parse = parse;
  8516. // Deep copy.
  8517. /* istanbul ignore next */
  8518. exports.Syntax = (function () {
  8519. var name, types = {};
  8520. if (typeof Object.create === 'function') {
  8521. types = Object.create(null);
  8522. }
  8523. for (name in Syntax) {
  8524. if (Syntax.hasOwnProperty(name)) {
  8525. types[name] = Syntax[name];
  8526. }
  8527. }
  8528. if (typeof Object.freeze === 'function') {
  8529. Object.freeze(types);
  8530. }
  8531. return types;
  8532. }());
  8533. }));
  8534. /* vim: set sw=4 ts=4 et tw=80 : */
  8535. },{}],10:[function(_dereq_,module,exports){
  8536. var Base62 = (function (my) {
  8537. my.chars = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "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", "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"]
  8538. my.encode = function(i){
  8539. if (i === 0) {return '0'}
  8540. var s = ''
  8541. while (i > 0) {
  8542. s = this.chars[i % 62] + s
  8543. i = Math.floor(i/62)
  8544. }
  8545. return s
  8546. };
  8547. my.decode = function(a,b,c,d){
  8548. for (
  8549. b = c = (
  8550. a === (/\W|_|^$/.test(a += "") || a)
  8551. ) - 1;
  8552. d = a.charCodeAt(c++);
  8553. )
  8554. b = b * 62 + d - [, 48, 29, 87][d >> 5];
  8555. return b
  8556. };
  8557. return my;
  8558. }({}));
  8559. module.exports = Base62
  8560. },{}],11:[function(_dereq_,module,exports){
  8561. /*
  8562. * Copyright 2009-2011 Mozilla Foundation and contributors
  8563. * Licensed under the New BSD license. See LICENSE.txt or:
  8564. * http://opensource.org/licenses/BSD-3-Clause
  8565. */
  8566. exports.SourceMapGenerator = _dereq_('./source-map/source-map-generator').SourceMapGenerator;
  8567. exports.SourceMapConsumer = _dereq_('./source-map/source-map-consumer').SourceMapConsumer;
  8568. exports.SourceNode = _dereq_('./source-map/source-node').SourceNode;
  8569. },{"./source-map/source-map-consumer":16,"./source-map/source-map-generator":17,"./source-map/source-node":18}],12:[function(_dereq_,module,exports){
  8570. /* -*- Mode: js; js-indent-level: 2; -*- */
  8571. /*
  8572. * Copyright 2011 Mozilla Foundation and contributors
  8573. * Licensed under the New BSD license. See LICENSE or:
  8574. * http://opensource.org/licenses/BSD-3-Clause
  8575. */
  8576. if (typeof define !== 'function') {
  8577. var define = _dereq_('amdefine')(module, _dereq_);
  8578. }
  8579. define(function (_dereq_, exports, module) {
  8580. var util = _dereq_('./util');
  8581. /**
  8582. * A data structure which is a combination of an array and a set. Adding a new
  8583. * member is O(1), testing for membership is O(1), and finding the index of an
  8584. * element is O(1). Removing elements from the set is not supported. Only
  8585. * strings are supported for membership.
  8586. */
  8587. function ArraySet() {
  8588. this._array = [];
  8589. this._set = {};
  8590. }
  8591. /**
  8592. * Static method for creating ArraySet instances from an existing array.
  8593. */
  8594. ArraySet.fromArray = function ArraySet_fromArray(aArray, aAllowDuplicates) {
  8595. var set = new ArraySet();
  8596. for (var i = 0, len = aArray.length; i < len; i++) {
  8597. set.add(aArray[i], aAllowDuplicates);
  8598. }
  8599. return set;
  8600. };
  8601. /**
  8602. * Add the given string to this set.
  8603. *
  8604. * @param String aStr
  8605. */
  8606. ArraySet.prototype.add = function ArraySet_add(aStr, aAllowDuplicates) {
  8607. var isDuplicate = this.has(aStr);
  8608. var idx = this._array.length;
  8609. if (!isDuplicate || aAllowDuplicates) {
  8610. this._array.push(aStr);
  8611. }
  8612. if (!isDuplicate) {
  8613. this._set[util.toSetString(aStr)] = idx;
  8614. }
  8615. };
  8616. /**
  8617. * Is the given string a member of this set?
  8618. *
  8619. * @param String aStr
  8620. */
  8621. ArraySet.prototype.has = function ArraySet_has(aStr) {
  8622. return Object.prototype.hasOwnProperty.call(this._set,
  8623. util.toSetString(aStr));
  8624. };
  8625. /**
  8626. * What is the index of the given string in the array?
  8627. *
  8628. * @param String aStr
  8629. */
  8630. ArraySet.prototype.indexOf = function ArraySet_indexOf(aStr) {
  8631. if (this.has(aStr)) {
  8632. return this._set[util.toSetString(aStr)];
  8633. }
  8634. throw new Error('"' + aStr + '" is not in the set.');
  8635. };
  8636. /**
  8637. * What is the element at the given index?
  8638. *
  8639. * @param Number aIdx
  8640. */
  8641. ArraySet.prototype.at = function ArraySet_at(aIdx) {
  8642. if (aIdx >= 0 && aIdx < this._array.length) {
  8643. return this._array[aIdx];
  8644. }
  8645. throw new Error('No element indexed by ' + aIdx);
  8646. };
  8647. /**
  8648. * Returns the array representation of this set (which has the proper indices
  8649. * indicated by indexOf). Note that this is a copy of the internal array used
  8650. * for storing the members so that no one can mess with internal state.
  8651. */
  8652. ArraySet.prototype.toArray = function ArraySet_toArray() {
  8653. return this._array.slice();
  8654. };
  8655. exports.ArraySet = ArraySet;
  8656. });
  8657. },{"./util":19,"amdefine":20}],13:[function(_dereq_,module,exports){
  8658. /* -*- Mode: js; js-indent-level: 2; -*- */
  8659. /*
  8660. * Copyright 2011 Mozilla Foundation and contributors
  8661. * Licensed under the New BSD license. See LICENSE or:
  8662. * http://opensource.org/licenses/BSD-3-Clause
  8663. *
  8664. * Based on the Base 64 VLQ implementation in Closure Compiler:
  8665. * https://code.google.com/p/closure-compiler/source/browse/trunk/src/com/google/debugging/sourcemap/Base64VLQ.java
  8666. *
  8667. * Copyright 2011 The Closure Compiler Authors. All rights reserved.
  8668. * Redistribution and use in source and binary forms, with or without
  8669. * modification, are permitted provided that the following conditions are
  8670. * met:
  8671. *
  8672. * * Redistributions of source code must retain the above copyright
  8673. * notice, this list of conditions and the following disclaimer.
  8674. * * Redistributions in binary form must reproduce the above
  8675. * copyright notice, this list of conditions and the following
  8676. * disclaimer in the documentation and/or other materials provided
  8677. * with the distribution.
  8678. * * Neither the name of Google Inc. nor the names of its
  8679. * contributors may be used to endorse or promote products derived
  8680. * from this software without specific prior written permission.
  8681. *
  8682. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  8683. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  8684. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  8685. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  8686. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  8687. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  8688. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  8689. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  8690. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  8691. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  8692. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  8693. */
  8694. if (typeof define !== 'function') {
  8695. var define = _dereq_('amdefine')(module, _dereq_);
  8696. }
  8697. define(function (_dereq_, exports, module) {
  8698. var base64 = _dereq_('./base64');
  8699. // A single base 64 digit can contain 6 bits of data. For the base 64 variable
  8700. // length quantities we use in the source map spec, the first bit is the sign,
  8701. // the next four bits are the actual value, and the 6th bit is the
  8702. // continuation bit. The continuation bit tells us whether there are more
  8703. // digits in this value following this digit.
  8704. //
  8705. // Continuation
  8706. // | Sign
  8707. // | |
  8708. // V V
  8709. // 101011
  8710. var VLQ_BASE_SHIFT = 5;
  8711. // binary: 100000
  8712. var VLQ_BASE = 1 << VLQ_BASE_SHIFT;
  8713. // binary: 011111
  8714. var VLQ_BASE_MASK = VLQ_BASE - 1;
  8715. // binary: 100000
  8716. var VLQ_CONTINUATION_BIT = VLQ_BASE;
  8717. /**
  8718. * Converts from a two-complement value to a value where the sign bit is
  8719. * is placed in the least significant bit. For example, as decimals:
  8720. * 1 becomes 2 (10 binary), -1 becomes 3 (11 binary)
  8721. * 2 becomes 4 (100 binary), -2 becomes 5 (101 binary)
  8722. */
  8723. function toVLQSigned(aValue) {
  8724. return aValue < 0
  8725. ? ((-aValue) << 1) + 1
  8726. : (aValue << 1) + 0;
  8727. }
  8728. /**
  8729. * Converts to a two-complement value from a value where the sign bit is
  8730. * is placed in the least significant bit. For example, as decimals:
  8731. * 2 (10 binary) becomes 1, 3 (11 binary) becomes -1
  8732. * 4 (100 binary) becomes 2, 5 (101 binary) becomes -2
  8733. */
  8734. function fromVLQSigned(aValue) {
  8735. var isNegative = (aValue & 1) === 1;
  8736. var shifted = aValue >> 1;
  8737. return isNegative
  8738. ? -shifted
  8739. : shifted;
  8740. }
  8741. /**
  8742. * Returns the base 64 VLQ encoded value.
  8743. */
  8744. exports.encode = function base64VLQ_encode(aValue) {
  8745. var encoded = "";
  8746. var digit;
  8747. var vlq = toVLQSigned(aValue);
  8748. do {
  8749. digit = vlq & VLQ_BASE_MASK;
  8750. vlq >>>= VLQ_BASE_SHIFT;
  8751. if (vlq > 0) {
  8752. // There are still more digits in this value, so we must make sure the
  8753. // continuation bit is marked.
  8754. digit |= VLQ_CONTINUATION_BIT;
  8755. }
  8756. encoded += base64.encode(digit);
  8757. } while (vlq > 0);
  8758. return encoded;
  8759. };
  8760. /**
  8761. * Decodes the next base 64 VLQ value from the given string and returns the
  8762. * value and the rest of the string.
  8763. */
  8764. exports.decode = function base64VLQ_decode(aStr) {
  8765. var i = 0;
  8766. var strLen = aStr.length;
  8767. var result = 0;
  8768. var shift = 0;
  8769. var continuation, digit;
  8770. do {
  8771. if (i >= strLen) {
  8772. throw new Error("Expected more digits in base 64 VLQ value.");
  8773. }
  8774. digit = base64.decode(aStr.charAt(i++));
  8775. continuation = !!(digit & VLQ_CONTINUATION_BIT);
  8776. digit &= VLQ_BASE_MASK;
  8777. result = result + (digit << shift);
  8778. shift += VLQ_BASE_SHIFT;
  8779. } while (continuation);
  8780. return {
  8781. value: fromVLQSigned(result),
  8782. rest: aStr.slice(i)
  8783. };
  8784. };
  8785. });
  8786. },{"./base64":14,"amdefine":20}],14:[function(_dereq_,module,exports){
  8787. /* -*- Mode: js; js-indent-level: 2; -*- */
  8788. /*
  8789. * Copyright 2011 Mozilla Foundation and contributors
  8790. * Licensed under the New BSD license. See LICENSE or:
  8791. * http://opensource.org/licenses/BSD-3-Clause
  8792. */
  8793. if (typeof define !== 'function') {
  8794. var define = _dereq_('amdefine')(module, _dereq_);
  8795. }
  8796. define(function (_dereq_, exports, module) {
  8797. var charToIntMap = {};
  8798. var intToCharMap = {};
  8799. 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
  8800. .split('')
  8801. .forEach(function (ch, index) {
  8802. charToIntMap[ch] = index;
  8803. intToCharMap[index] = ch;
  8804. });
  8805. /**
  8806. * Encode an integer in the range of 0 to 63 to a single base 64 digit.
  8807. */
  8808. exports.encode = function base64_encode(aNumber) {
  8809. if (aNumber in intToCharMap) {
  8810. return intToCharMap[aNumber];
  8811. }
  8812. throw new TypeError("Must be between 0 and 63: " + aNumber);
  8813. };
  8814. /**
  8815. * Decode a single base 64 digit to an integer.
  8816. */
  8817. exports.decode = function base64_decode(aChar) {
  8818. if (aChar in charToIntMap) {
  8819. return charToIntMap[aChar];
  8820. }
  8821. throw new TypeError("Not a valid base 64 digit: " + aChar);
  8822. };
  8823. });
  8824. },{"amdefine":20}],15:[function(_dereq_,module,exports){
  8825. /* -*- Mode: js; js-indent-level: 2; -*- */
  8826. /*
  8827. * Copyright 2011 Mozilla Foundation and contributors
  8828. * Licensed under the New BSD license. See LICENSE or:
  8829. * http://opensource.org/licenses/BSD-3-Clause
  8830. */
  8831. if (typeof define !== 'function') {
  8832. var define = _dereq_('amdefine')(module, _dereq_);
  8833. }
  8834. define(function (_dereq_, exports, module) {
  8835. /**
  8836. * Recursive implementation of binary search.
  8837. *
  8838. * @param aLow Indices here and lower do not contain the needle.
  8839. * @param aHigh Indices here and higher do not contain the needle.
  8840. * @param aNeedle The element being searched for.
  8841. * @param aHaystack The non-empty array being searched.
  8842. * @param aCompare Function which takes two elements and returns -1, 0, or 1.
  8843. */
  8844. function recursiveSearch(aLow, aHigh, aNeedle, aHaystack, aCompare) {
  8845. // This function terminates when one of the following is true:
  8846. //
  8847. // 1. We find the exact element we are looking for.
  8848. //
  8849. // 2. We did not find the exact element, but we can return the next
  8850. // closest element that is less than that element.
  8851. //
  8852. // 3. We did not find the exact element, and there is no next-closest
  8853. // element which is less than the one we are searching for, so we
  8854. // return null.
  8855. var mid = Math.floor((aHigh - aLow) / 2) + aLow;
  8856. var cmp = aCompare(aNeedle, aHaystack[mid], true);
  8857. if (cmp === 0) {
  8858. // Found the element we are looking for.
  8859. return aHaystack[mid];
  8860. }
  8861. else if (cmp > 0) {
  8862. // aHaystack[mid] is greater than our needle.
  8863. if (aHigh - mid > 1) {
  8864. // The element is in the upper half.
  8865. return recursiveSearch(mid, aHigh, aNeedle, aHaystack, aCompare);
  8866. }
  8867. // We did not find an exact match, return the next closest one
  8868. // (termination case 2).
  8869. return aHaystack[mid];
  8870. }
  8871. else {
  8872. // aHaystack[mid] is less than our needle.
  8873. if (mid - aLow > 1) {
  8874. // The element is in the lower half.
  8875. return recursiveSearch(aLow, mid, aNeedle, aHaystack, aCompare);
  8876. }
  8877. // The exact needle element was not found in this haystack. Determine if
  8878. // we are in termination case (2) or (3) and return the appropriate thing.
  8879. return aLow < 0
  8880. ? null
  8881. : aHaystack[aLow];
  8882. }
  8883. }
  8884. /**
  8885. * This is an implementation of binary search which will always try and return
  8886. * the next lowest value checked if there is no exact hit. This is because
  8887. * mappings between original and generated line/col pairs are single points,
  8888. * and there is an implicit region between each of them, so a miss just means
  8889. * that you aren't on the very start of a region.
  8890. *
  8891. * @param aNeedle The element you are looking for.
  8892. * @param aHaystack The array that is being searched.
  8893. * @param aCompare A function which takes the needle and an element in the
  8894. * array and returns -1, 0, or 1 depending on whether the needle is less
  8895. * than, equal to, or greater than the element, respectively.
  8896. */
  8897. exports.search = function search(aNeedle, aHaystack, aCompare) {
  8898. return aHaystack.length > 0
  8899. ? recursiveSearch(-1, aHaystack.length, aNeedle, aHaystack, aCompare)
  8900. : null;
  8901. };
  8902. });
  8903. },{"amdefine":20}],16:[function(_dereq_,module,exports){
  8904. /* -*- Mode: js; js-indent-level: 2; -*- */
  8905. /*
  8906. * Copyright 2011 Mozilla Foundation and contributors
  8907. * Licensed under the New BSD license. See LICENSE or:
  8908. * http://opensource.org/licenses/BSD-3-Clause
  8909. */
  8910. if (typeof define !== 'function') {
  8911. var define = _dereq_('amdefine')(module, _dereq_);
  8912. }
  8913. define(function (_dereq_, exports, module) {
  8914. var util = _dereq_('./util');
  8915. var binarySearch = _dereq_('./binary-search');
  8916. var ArraySet = _dereq_('./array-set').ArraySet;
  8917. var base64VLQ = _dereq_('./base64-vlq');
  8918. /**
  8919. * A SourceMapConsumer instance represents a parsed source map which we can
  8920. * query for information about the original file positions by giving it a file
  8921. * position in the generated source.
  8922. *
  8923. * The only parameter is the raw source map (either as a JSON string, or
  8924. * already parsed to an object). According to the spec, source maps have the
  8925. * following attributes:
  8926. *
  8927. * - version: Which version of the source map spec this map is following.
  8928. * - sources: An array of URLs to the original source files.
  8929. * - names: An array of identifiers which can be referrenced by individual mappings.
  8930. * - sourceRoot: Optional. The URL root from which all sources are relative.
  8931. * - sourcesContent: Optional. An array of contents of the original source files.
  8932. * - mappings: A string of base64 VLQs which contain the actual mappings.
  8933. * - file: The generated file this source map is associated with.
  8934. *
  8935. * Here is an example source map, taken from the source map spec[0]:
  8936. *
  8937. * {
  8938. * version : 3,
  8939. * file: "out.js",
  8940. * sourceRoot : "",
  8941. * sources: ["foo.js", "bar.js"],
  8942. * names: ["src", "maps", "are", "fun"],
  8943. * mappings: "AA,AB;;ABCDE;"
  8944. * }
  8945. *
  8946. * [0]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit?pli=1#
  8947. */
  8948. function SourceMapConsumer(aSourceMap) {
  8949. var sourceMap = aSourceMap;
  8950. if (typeof aSourceMap === 'string') {
  8951. sourceMap = JSON.parse(aSourceMap.replace(/^\)\]\}'/, ''));
  8952. }
  8953. var version = util.getArg(sourceMap, 'version');
  8954. var sources = util.getArg(sourceMap, 'sources');
  8955. // Sass 3.3 leaves out the 'names' array, so we deviate from the spec (which
  8956. // requires the array) to play nice here.
  8957. var names = util.getArg(sourceMap, 'names', []);
  8958. var sourceRoot = util.getArg(sourceMap, 'sourceRoot', null);
  8959. var sourcesContent = util.getArg(sourceMap, 'sourcesContent', null);
  8960. var mappings = util.getArg(sourceMap, 'mappings');
  8961. var file = util.getArg(sourceMap, 'file', null);
  8962. // Once again, Sass deviates from the spec and supplies the version as a
  8963. // string rather than a number, so we use loose equality checking here.
  8964. if (version != this._version) {
  8965. throw new Error('Unsupported version: ' + version);
  8966. }
  8967. // Pass `true` below to allow duplicate names and sources. While source maps
  8968. // are intended to be compressed and deduplicated, the TypeScript compiler
  8969. // sometimes generates source maps with duplicates in them. See Github issue
  8970. // #72 and bugzil.la/889492.
  8971. this._names = ArraySet.fromArray(names, true);
  8972. this._sources = ArraySet.fromArray(sources, true);
  8973. this.sourceRoot = sourceRoot;
  8974. this.sourcesContent = sourcesContent;
  8975. this._mappings = mappings;
  8976. this.file = file;
  8977. }
  8978. /**
  8979. * Create a SourceMapConsumer from a SourceMapGenerator.
  8980. *
  8981. * @param SourceMapGenerator aSourceMap
  8982. * The source map that will be consumed.
  8983. * @returns SourceMapConsumer
  8984. */
  8985. SourceMapConsumer.fromSourceMap =
  8986. function SourceMapConsumer_fromSourceMap(aSourceMap) {
  8987. var smc = Object.create(SourceMapConsumer.prototype);
  8988. smc._names = ArraySet.fromArray(aSourceMap._names.toArray(), true);
  8989. smc._sources = ArraySet.fromArray(aSourceMap._sources.toArray(), true);
  8990. smc.sourceRoot = aSourceMap._sourceRoot;
  8991. smc.sourcesContent = aSourceMap._generateSourcesContent(smc._sources.toArray(),
  8992. smc.sourceRoot);
  8993. smc.file = aSourceMap._file;
  8994. smc.__generatedMappings = aSourceMap._mappings.slice()
  8995. .sort(util.compareByGeneratedPositions);
  8996. smc.__originalMappings = aSourceMap._mappings.slice()
  8997. .sort(util.compareByOriginalPositions);
  8998. return smc;
  8999. };
  9000. /**
  9001. * The version of the source mapping spec that we are consuming.
  9002. */
  9003. SourceMapConsumer.prototype._version = 3;
  9004. /**
  9005. * The list of original sources.
  9006. */
  9007. Object.defineProperty(SourceMapConsumer.prototype, 'sources', {
  9008. get: function () {
  9009. return this._sources.toArray().map(function (s) {
  9010. return this.sourceRoot ? util.join(this.sourceRoot, s) : s;
  9011. }, this);
  9012. }
  9013. });
  9014. // `__generatedMappings` and `__originalMappings` are arrays that hold the
  9015. // parsed mapping coordinates from the source map's "mappings" attribute. They
  9016. // are lazily instantiated, accessed via the `_generatedMappings` and
  9017. // `_originalMappings` getters respectively, and we only parse the mappings
  9018. // and create these arrays once queried for a source location. We jump through
  9019. // these hoops because there can be many thousands of mappings, and parsing
  9020. // them is expensive, so we only want to do it if we must.
  9021. //
  9022. // Each object in the arrays is of the form:
  9023. //
  9024. // {
  9025. // generatedLine: The line number in the generated code,
  9026. // generatedColumn: The column number in the generated code,
  9027. // source: The path to the original source file that generated this
  9028. // chunk of code,
  9029. // originalLine: The line number in the original source that
  9030. // corresponds to this chunk of generated code,
  9031. // originalColumn: The column number in the original source that
  9032. // corresponds to this chunk of generated code,
  9033. // name: The name of the original symbol which generated this chunk of
  9034. // code.
  9035. // }
  9036. //
  9037. // All properties except for `generatedLine` and `generatedColumn` can be
  9038. // `null`.
  9039. //
  9040. // `_generatedMappings` is ordered by the generated positions.
  9041. //
  9042. // `_originalMappings` is ordered by the original positions.
  9043. SourceMapConsumer.prototype.__generatedMappings = null;
  9044. Object.defineProperty(SourceMapConsumer.prototype, '_generatedMappings', {
  9045. get: function () {
  9046. if (!this.__generatedMappings) {
  9047. this.__generatedMappings = [];
  9048. this.__originalMappings = [];
  9049. this._parseMappings(this._mappings, this.sourceRoot);
  9050. }
  9051. return this.__generatedMappings;
  9052. }
  9053. });
  9054. SourceMapConsumer.prototype.__originalMappings = null;
  9055. Object.defineProperty(SourceMapConsumer.prototype, '_originalMappings', {
  9056. get: function () {
  9057. if (!this.__originalMappings) {
  9058. this.__generatedMappings = [];
  9059. this.__originalMappings = [];
  9060. this._parseMappings(this._mappings, this.sourceRoot);
  9061. }
  9062. return this.__originalMappings;
  9063. }
  9064. });
  9065. /**
  9066. * Parse the mappings in a string in to a data structure which we can easily
  9067. * query (the ordered arrays in the `this.__generatedMappings` and
  9068. * `this.__originalMappings` properties).
  9069. */
  9070. SourceMapConsumer.prototype._parseMappings =
  9071. function SourceMapConsumer_parseMappings(aStr, aSourceRoot) {
  9072. var generatedLine = 1;
  9073. var previousGeneratedColumn = 0;
  9074. var previousOriginalLine = 0;
  9075. var previousOriginalColumn = 0;
  9076. var previousSource = 0;
  9077. var previousName = 0;
  9078. var mappingSeparator = /^[,;]/;
  9079. var str = aStr;
  9080. var mapping;
  9081. var temp;
  9082. while (str.length > 0) {
  9083. if (str.charAt(0) === ';') {
  9084. generatedLine++;
  9085. str = str.slice(1);
  9086. previousGeneratedColumn = 0;
  9087. }
  9088. else if (str.charAt(0) === ',') {
  9089. str = str.slice(1);
  9090. }
  9091. else {
  9092. mapping = {};
  9093. mapping.generatedLine = generatedLine;
  9094. // Generated column.
  9095. temp = base64VLQ.decode(str);
  9096. mapping.generatedColumn = previousGeneratedColumn + temp.value;
  9097. previousGeneratedColumn = mapping.generatedColumn;
  9098. str = temp.rest;
  9099. if (str.length > 0 && !mappingSeparator.test(str.charAt(0))) {
  9100. // Original source.
  9101. temp = base64VLQ.decode(str);
  9102. mapping.source = this._sources.at(previousSource + temp.value);
  9103. previousSource += temp.value;
  9104. str = temp.rest;
  9105. if (str.length === 0 || mappingSeparator.test(str.charAt(0))) {
  9106. throw new Error('Found a source, but no line and column');
  9107. }
  9108. // Original line.
  9109. temp = base64VLQ.decode(str);
  9110. mapping.originalLine = previousOriginalLine + temp.value;
  9111. previousOriginalLine = mapping.originalLine;
  9112. // Lines are stored 0-based
  9113. mapping.originalLine += 1;
  9114. str = temp.rest;
  9115. if (str.length === 0 || mappingSeparator.test(str.charAt(0))) {
  9116. throw new Error('Found a source and line, but no column');
  9117. }
  9118. // Original column.
  9119. temp = base64VLQ.decode(str);
  9120. mapping.originalColumn = previousOriginalColumn + temp.value;
  9121. previousOriginalColumn = mapping.originalColumn;
  9122. str = temp.rest;
  9123. if (str.length > 0 && !mappingSeparator.test(str.charAt(0))) {
  9124. // Original name.
  9125. temp = base64VLQ.decode(str);
  9126. mapping.name = this._names.at(previousName + temp.value);
  9127. previousName += temp.value;
  9128. str = temp.rest;
  9129. }
  9130. }
  9131. this.__generatedMappings.push(mapping);
  9132. if (typeof mapping.originalLine === 'number') {
  9133. this.__originalMappings.push(mapping);
  9134. }
  9135. }
  9136. }
  9137. this.__originalMappings.sort(util.compareByOriginalPositions);
  9138. };
  9139. /**
  9140. * Find the mapping that best matches the hypothetical "needle" mapping that
  9141. * we are searching for in the given "haystack" of mappings.
  9142. */
  9143. SourceMapConsumer.prototype._findMapping =
  9144. function SourceMapConsumer_findMapping(aNeedle, aMappings, aLineName,
  9145. aColumnName, aComparator) {
  9146. // To return the position we are searching for, we must first find the
  9147. // mapping for the given position and then return the opposite position it
  9148. // points to. Because the mappings are sorted, we can use binary search to
  9149. // find the best mapping.
  9150. if (aNeedle[aLineName] <= 0) {
  9151. throw new TypeError('Line must be greater than or equal to 1, got '
  9152. + aNeedle[aLineName]);
  9153. }
  9154. if (aNeedle[aColumnName] < 0) {
  9155. throw new TypeError('Column must be greater than or equal to 0, got '
  9156. + aNeedle[aColumnName]);
  9157. }
  9158. return binarySearch.search(aNeedle, aMappings, aComparator);
  9159. };
  9160. /**
  9161. * Returns the original source, line, and column information for the generated
  9162. * source's line and column positions provided. The only argument is an object
  9163. * with the following properties:
  9164. *
  9165. * - line: The line number in the generated source.
  9166. * - column: The column number in the generated source.
  9167. *
  9168. * and an object is returned with the following properties:
  9169. *
  9170. * - source: The original source file, or null.
  9171. * - line: The line number in the original source, or null.
  9172. * - column: The column number in the original source, or null.
  9173. * - name: The original identifier, or null.
  9174. */
  9175. SourceMapConsumer.prototype.originalPositionFor =
  9176. function SourceMapConsumer_originalPositionFor(aArgs) {
  9177. var needle = {
  9178. generatedLine: util.getArg(aArgs, 'line'),
  9179. generatedColumn: util.getArg(aArgs, 'column')
  9180. };
  9181. var mapping = this._findMapping(needle,
  9182. this._generatedMappings,
  9183. "generatedLine",
  9184. "generatedColumn",
  9185. util.compareByGeneratedPositions);
  9186. if (mapping) {
  9187. var source = util.getArg(mapping, 'source', null);
  9188. if (source && this.sourceRoot) {
  9189. source = util.join(this.sourceRoot, source);
  9190. }
  9191. return {
  9192. source: source,
  9193. line: util.getArg(mapping, 'originalLine', null),
  9194. column: util.getArg(mapping, 'originalColumn', null),
  9195. name: util.getArg(mapping, 'name', null)
  9196. };
  9197. }
  9198. return {
  9199. source: null,
  9200. line: null,
  9201. column: null,
  9202. name: null
  9203. };
  9204. };
  9205. /**
  9206. * Returns the original source content. The only argument is the url of the
  9207. * original source file. Returns null if no original source content is
  9208. * availible.
  9209. */
  9210. SourceMapConsumer.prototype.sourceContentFor =
  9211. function SourceMapConsumer_sourceContentFor(aSource) {
  9212. if (!this.sourcesContent) {
  9213. return null;
  9214. }
  9215. if (this.sourceRoot) {
  9216. aSource = util.relative(this.sourceRoot, aSource);
  9217. }
  9218. if (this._sources.has(aSource)) {
  9219. return this.sourcesContent[this._sources.indexOf(aSource)];
  9220. }
  9221. var url;
  9222. if (this.sourceRoot
  9223. && (url = util.urlParse(this.sourceRoot))) {
  9224. // XXX: file:// URIs and absolute paths lead to unexpected behavior for
  9225. // many users. We can help them out when they expect file:// URIs to
  9226. // behave like it would if they were running a local HTTP server. See
  9227. // https://bugzilla.mozilla.org/show_bug.cgi?id=885597.
  9228. var fileUriAbsPath = aSource.replace(/^file:\/\//, "");
  9229. if (url.scheme == "file"
  9230. && this._sources.has(fileUriAbsPath)) {
  9231. return this.sourcesContent[this._sources.indexOf(fileUriAbsPath)]
  9232. }
  9233. if ((!url.path || url.path == "/")
  9234. && this._sources.has("/" + aSource)) {
  9235. return this.sourcesContent[this._sources.indexOf("/" + aSource)];
  9236. }
  9237. }
  9238. throw new Error('"' + aSource + '" is not in the SourceMap.');
  9239. };
  9240. /**
  9241. * Returns the generated line and column information for the original source,
  9242. * line, and column positions provided. The only argument is an object with
  9243. * the following properties:
  9244. *
  9245. * - source: The filename of the original source.
  9246. * - line: The line number in the original source.
  9247. * - column: The column number in the original source.
  9248. *
  9249. * and an object is returned with the following properties:
  9250. *
  9251. * - line: The line number in the generated source, or null.
  9252. * - column: The column number in the generated source, or null.
  9253. */
  9254. SourceMapConsumer.prototype.generatedPositionFor =
  9255. function SourceMapConsumer_generatedPositionFor(aArgs) {
  9256. var needle = {
  9257. source: util.getArg(aArgs, 'source'),
  9258. originalLine: util.getArg(aArgs, 'line'),
  9259. originalColumn: util.getArg(aArgs, 'column')
  9260. };
  9261. if (this.sourceRoot) {
  9262. needle.source = util.relative(this.sourceRoot, needle.source);
  9263. }
  9264. var mapping = this._findMapping(needle,
  9265. this._originalMappings,
  9266. "originalLine",
  9267. "originalColumn",
  9268. util.compareByOriginalPositions);
  9269. if (mapping) {
  9270. return {
  9271. line: util.getArg(mapping, 'generatedLine', null),
  9272. column: util.getArg(mapping, 'generatedColumn', null)
  9273. };
  9274. }
  9275. return {
  9276. line: null,
  9277. column: null
  9278. };
  9279. };
  9280. SourceMapConsumer.GENERATED_ORDER = 1;
  9281. SourceMapConsumer.ORIGINAL_ORDER = 2;
  9282. /**
  9283. * Iterate over each mapping between an original source/line/column and a
  9284. * generated line/column in this source map.
  9285. *
  9286. * @param Function aCallback
  9287. * The function that is called with each mapping.
  9288. * @param Object aContext
  9289. * Optional. If specified, this object will be the value of `this` every
  9290. * time that `aCallback` is called.
  9291. * @param aOrder
  9292. * Either `SourceMapConsumer.GENERATED_ORDER` or
  9293. * `SourceMapConsumer.ORIGINAL_ORDER`. Specifies whether you want to
  9294. * iterate over the mappings sorted by the generated file's line/column
  9295. * order or the original's source/line/column order, respectively. Defaults to
  9296. * `SourceMapConsumer.GENERATED_ORDER`.
  9297. */
  9298. SourceMapConsumer.prototype.eachMapping =
  9299. function SourceMapConsumer_eachMapping(aCallback, aContext, aOrder) {
  9300. var context = aContext || null;
  9301. var order = aOrder || SourceMapConsumer.GENERATED_ORDER;
  9302. var mappings;
  9303. switch (order) {
  9304. case SourceMapConsumer.GENERATED_ORDER:
  9305. mappings = this._generatedMappings;
  9306. break;
  9307. case SourceMapConsumer.ORIGINAL_ORDER:
  9308. mappings = this._originalMappings;
  9309. break;
  9310. default:
  9311. throw new Error("Unknown order of iteration.");
  9312. }
  9313. var sourceRoot = this.sourceRoot;
  9314. mappings.map(function (mapping) {
  9315. var source = mapping.source;
  9316. if (source && sourceRoot) {
  9317. source = util.join(sourceRoot, source);
  9318. }
  9319. return {
  9320. source: source,
  9321. generatedLine: mapping.generatedLine,
  9322. generatedColumn: mapping.generatedColumn,
  9323. originalLine: mapping.originalLine,
  9324. originalColumn: mapping.originalColumn,
  9325. name: mapping.name
  9326. };
  9327. }).forEach(aCallback, context);
  9328. };
  9329. exports.SourceMapConsumer = SourceMapConsumer;
  9330. });
  9331. },{"./array-set":12,"./base64-vlq":13,"./binary-search":15,"./util":19,"amdefine":20}],17:[function(_dereq_,module,exports){
  9332. /* -*- Mode: js; js-indent-level: 2; -*- */
  9333. /*
  9334. * Copyright 2011 Mozilla Foundation and contributors
  9335. * Licensed under the New BSD license. See LICENSE or:
  9336. * http://opensource.org/licenses/BSD-3-Clause
  9337. */
  9338. if (typeof define !== 'function') {
  9339. var define = _dereq_('amdefine')(module, _dereq_);
  9340. }
  9341. define(function (_dereq_, exports, module) {
  9342. var base64VLQ = _dereq_('./base64-vlq');
  9343. var util = _dereq_('./util');
  9344. var ArraySet = _dereq_('./array-set').ArraySet;
  9345. /**
  9346. * An instance of the SourceMapGenerator represents a source map which is
  9347. * being built incrementally. To create a new one, you must pass an object
  9348. * with the following properties:
  9349. *
  9350. * - file: The filename of the generated source.
  9351. * - sourceRoot: An optional root for all URLs in this source map.
  9352. */
  9353. function SourceMapGenerator(aArgs) {
  9354. this._file = util.getArg(aArgs, 'file');
  9355. this._sourceRoot = util.getArg(aArgs, 'sourceRoot', null);
  9356. this._sources = new ArraySet();
  9357. this._names = new ArraySet();
  9358. this._mappings = [];
  9359. this._sourcesContents = null;
  9360. }
  9361. SourceMapGenerator.prototype._version = 3;
  9362. /**
  9363. * Creates a new SourceMapGenerator based on a SourceMapConsumer
  9364. *
  9365. * @param aSourceMapConsumer The SourceMap.
  9366. */
  9367. SourceMapGenerator.fromSourceMap =
  9368. function SourceMapGenerator_fromSourceMap(aSourceMapConsumer) {
  9369. var sourceRoot = aSourceMapConsumer.sourceRoot;
  9370. var generator = new SourceMapGenerator({
  9371. file: aSourceMapConsumer.file,
  9372. sourceRoot: sourceRoot
  9373. });
  9374. aSourceMapConsumer.eachMapping(function (mapping) {
  9375. var newMapping = {
  9376. generated: {
  9377. line: mapping.generatedLine,
  9378. column: mapping.generatedColumn
  9379. }
  9380. };
  9381. if (mapping.source) {
  9382. newMapping.source = mapping.source;
  9383. if (sourceRoot) {
  9384. newMapping.source = util.relative(sourceRoot, newMapping.source);
  9385. }
  9386. newMapping.original = {
  9387. line: mapping.originalLine,
  9388. column: mapping.originalColumn
  9389. };
  9390. if (mapping.name) {
  9391. newMapping.name = mapping.name;
  9392. }
  9393. }
  9394. generator.addMapping(newMapping);
  9395. });
  9396. aSourceMapConsumer.sources.forEach(function (sourceFile) {
  9397. var content = aSourceMapConsumer.sourceContentFor(sourceFile);
  9398. if (content) {
  9399. generator.setSourceContent(sourceFile, content);
  9400. }
  9401. });
  9402. return generator;
  9403. };
  9404. /**
  9405. * Add a single mapping from original source line and column to the generated
  9406. * source's line and column for this source map being created. The mapping
  9407. * object should have the following properties:
  9408. *
  9409. * - generated: An object with the generated line and column positions.
  9410. * - original: An object with the original line and column positions.
  9411. * - source: The original source file (relative to the sourceRoot).
  9412. * - name: An optional original token name for this mapping.
  9413. */
  9414. SourceMapGenerator.prototype.addMapping =
  9415. function SourceMapGenerator_addMapping(aArgs) {
  9416. var generated = util.getArg(aArgs, 'generated');
  9417. var original = util.getArg(aArgs, 'original', null);
  9418. var source = util.getArg(aArgs, 'source', null);
  9419. var name = util.getArg(aArgs, 'name', null);
  9420. this._validateMapping(generated, original, source, name);
  9421. if (source && !this._sources.has(source)) {
  9422. this._sources.add(source);
  9423. }
  9424. if (name && !this._names.has(name)) {
  9425. this._names.add(name);
  9426. }
  9427. this._mappings.push({
  9428. generatedLine: generated.line,
  9429. generatedColumn: generated.column,
  9430. originalLine: original != null && original.line,
  9431. originalColumn: original != null && original.column,
  9432. source: source,
  9433. name: name
  9434. });
  9435. };
  9436. /**
  9437. * Set the source content for a source file.
  9438. */
  9439. SourceMapGenerator.prototype.setSourceContent =
  9440. function SourceMapGenerator_setSourceContent(aSourceFile, aSourceContent) {
  9441. var source = aSourceFile;
  9442. if (this._sourceRoot) {
  9443. source = util.relative(this._sourceRoot, source);
  9444. }
  9445. if (aSourceContent !== null) {
  9446. // Add the source content to the _sourcesContents map.
  9447. // Create a new _sourcesContents map if the property is null.
  9448. if (!this._sourcesContents) {
  9449. this._sourcesContents = {};
  9450. }
  9451. this._sourcesContents[util.toSetString(source)] = aSourceContent;
  9452. } else {
  9453. // Remove the source file from the _sourcesContents map.
  9454. // If the _sourcesContents map is empty, set the property to null.
  9455. delete this._sourcesContents[util.toSetString(source)];
  9456. if (Object.keys(this._sourcesContents).length === 0) {
  9457. this._sourcesContents = null;
  9458. }
  9459. }
  9460. };
  9461. /**
  9462. * Applies the mappings of a sub-source-map for a specific source file to the
  9463. * source map being generated. Each mapping to the supplied source file is
  9464. * rewritten using the supplied source map. Note: The resolution for the
  9465. * resulting mappings is the minimium of this map and the supplied map.
  9466. *
  9467. * @param aSourceMapConsumer The source map to be applied.
  9468. * @param aSourceFile Optional. The filename of the source file.
  9469. * If omitted, SourceMapConsumer's file property will be used.
  9470. */
  9471. SourceMapGenerator.prototype.applySourceMap =
  9472. function SourceMapGenerator_applySourceMap(aSourceMapConsumer, aSourceFile) {
  9473. // If aSourceFile is omitted, we will use the file property of the SourceMap
  9474. if (!aSourceFile) {
  9475. aSourceFile = aSourceMapConsumer.file;
  9476. }
  9477. var sourceRoot = this._sourceRoot;
  9478. // Make "aSourceFile" relative if an absolute Url is passed.
  9479. if (sourceRoot) {
  9480. aSourceFile = util.relative(sourceRoot, aSourceFile);
  9481. }
  9482. // Applying the SourceMap can add and remove items from the sources and
  9483. // the names array.
  9484. var newSources = new ArraySet();
  9485. var newNames = new ArraySet();
  9486. // Find mappings for the "aSourceFile"
  9487. this._mappings.forEach(function (mapping) {
  9488. if (mapping.source === aSourceFile && mapping.originalLine) {
  9489. // Check if it can be mapped by the source map, then update the mapping.
  9490. var original = aSourceMapConsumer.originalPositionFor({
  9491. line: mapping.originalLine,
  9492. column: mapping.originalColumn
  9493. });
  9494. if (original.source !== null) {
  9495. // Copy mapping
  9496. if (sourceRoot) {
  9497. mapping.source = util.relative(sourceRoot, original.source);
  9498. } else {
  9499. mapping.source = original.source;
  9500. }
  9501. mapping.originalLine = original.line;
  9502. mapping.originalColumn = original.column;
  9503. if (original.name !== null && mapping.name !== null) {
  9504. // Only use the identifier name if it's an identifier
  9505. // in both SourceMaps
  9506. mapping.name = original.name;
  9507. }
  9508. }
  9509. }
  9510. var source = mapping.source;
  9511. if (source && !newSources.has(source)) {
  9512. newSources.add(source);
  9513. }
  9514. var name = mapping.name;
  9515. if (name && !newNames.has(name)) {
  9516. newNames.add(name);
  9517. }
  9518. }, this);
  9519. this._sources = newSources;
  9520. this._names = newNames;
  9521. // Copy sourcesContents of applied map.
  9522. aSourceMapConsumer.sources.forEach(function (sourceFile) {
  9523. var content = aSourceMapConsumer.sourceContentFor(sourceFile);
  9524. if (content) {
  9525. if (sourceRoot) {
  9526. sourceFile = util.relative(sourceRoot, sourceFile);
  9527. }
  9528. this.setSourceContent(sourceFile, content);
  9529. }
  9530. }, this);
  9531. };
  9532. /**
  9533. * A mapping can have one of the three levels of data:
  9534. *
  9535. * 1. Just the generated position.
  9536. * 2. The Generated position, original position, and original source.
  9537. * 3. Generated and original position, original source, as well as a name
  9538. * token.
  9539. *
  9540. * To maintain consistency, we validate that any new mapping being added falls
  9541. * in to one of these categories.
  9542. */
  9543. SourceMapGenerator.prototype._validateMapping =
  9544. function SourceMapGenerator_validateMapping(aGenerated, aOriginal, aSource,
  9545. aName) {
  9546. if (aGenerated && 'line' in aGenerated && 'column' in aGenerated
  9547. && aGenerated.line > 0 && aGenerated.column >= 0
  9548. && !aOriginal && !aSource && !aName) {
  9549. // Case 1.
  9550. return;
  9551. }
  9552. else if (aGenerated && 'line' in aGenerated && 'column' in aGenerated
  9553. && aOriginal && 'line' in aOriginal && 'column' in aOriginal
  9554. && aGenerated.line > 0 && aGenerated.column >= 0
  9555. && aOriginal.line > 0 && aOriginal.column >= 0
  9556. && aSource) {
  9557. // Cases 2 and 3.
  9558. return;
  9559. }
  9560. else {
  9561. throw new Error('Invalid mapping: ' + JSON.stringify({
  9562. generated: aGenerated,
  9563. source: aSource,
  9564. orginal: aOriginal,
  9565. name: aName
  9566. }));
  9567. }
  9568. };
  9569. /**
  9570. * Serialize the accumulated mappings in to the stream of base 64 VLQs
  9571. * specified by the source map format.
  9572. */
  9573. SourceMapGenerator.prototype._serializeMappings =
  9574. function SourceMapGenerator_serializeMappings() {
  9575. var previousGeneratedColumn = 0;
  9576. var previousGeneratedLine = 1;
  9577. var previousOriginalColumn = 0;
  9578. var previousOriginalLine = 0;
  9579. var previousName = 0;
  9580. var previousSource = 0;
  9581. var result = '';
  9582. var mapping;
  9583. // The mappings must be guaranteed to be in sorted order before we start
  9584. // serializing them or else the generated line numbers (which are defined
  9585. // via the ';' separators) will be all messed up. Note: it might be more
  9586. // performant to maintain the sorting as we insert them, rather than as we
  9587. // serialize them, but the big O is the same either way.
  9588. this._mappings.sort(util.compareByGeneratedPositions);
  9589. for (var i = 0, len = this._mappings.length; i < len; i++) {
  9590. mapping = this._mappings[i];
  9591. if (mapping.generatedLine !== previousGeneratedLine) {
  9592. previousGeneratedColumn = 0;
  9593. while (mapping.generatedLine !== previousGeneratedLine) {
  9594. result += ';';
  9595. previousGeneratedLine++;
  9596. }
  9597. }
  9598. else {
  9599. if (i > 0) {
  9600. if (!util.compareByGeneratedPositions(mapping, this._mappings[i - 1])) {
  9601. continue;
  9602. }
  9603. result += ',';
  9604. }
  9605. }
  9606. result += base64VLQ.encode(mapping.generatedColumn
  9607. - previousGeneratedColumn);
  9608. previousGeneratedColumn = mapping.generatedColumn;
  9609. if (mapping.source) {
  9610. result += base64VLQ.encode(this._sources.indexOf(mapping.source)
  9611. - previousSource);
  9612. previousSource = this._sources.indexOf(mapping.source);
  9613. // lines are stored 0-based in SourceMap spec version 3
  9614. result += base64VLQ.encode(mapping.originalLine - 1
  9615. - previousOriginalLine);
  9616. previousOriginalLine = mapping.originalLine - 1;
  9617. result += base64VLQ.encode(mapping.originalColumn
  9618. - previousOriginalColumn);
  9619. previousOriginalColumn = mapping.originalColumn;
  9620. if (mapping.name) {
  9621. result += base64VLQ.encode(this._names.indexOf(mapping.name)
  9622. - previousName);
  9623. previousName = this._names.indexOf(mapping.name);
  9624. }
  9625. }
  9626. }
  9627. return result;
  9628. };
  9629. SourceMapGenerator.prototype._generateSourcesContent =
  9630. function SourceMapGenerator_generateSourcesContent(aSources, aSourceRoot) {
  9631. return aSources.map(function (source) {
  9632. if (!this._sourcesContents) {
  9633. return null;
  9634. }
  9635. if (aSourceRoot) {
  9636. source = util.relative(aSourceRoot, source);
  9637. }
  9638. var key = util.toSetString(source);
  9639. return Object.prototype.hasOwnProperty.call(this._sourcesContents,
  9640. key)
  9641. ? this._sourcesContents[key]
  9642. : null;
  9643. }, this);
  9644. };
  9645. /**
  9646. * Externalize the source map.
  9647. */
  9648. SourceMapGenerator.prototype.toJSON =
  9649. function SourceMapGenerator_toJSON() {
  9650. var map = {
  9651. version: this._version,
  9652. file: this._file,
  9653. sources: this._sources.toArray(),
  9654. names: this._names.toArray(),
  9655. mappings: this._serializeMappings()
  9656. };
  9657. if (this._sourceRoot) {
  9658. map.sourceRoot = this._sourceRoot;
  9659. }
  9660. if (this._sourcesContents) {
  9661. map.sourcesContent = this._generateSourcesContent(map.sources, map.sourceRoot);
  9662. }
  9663. return map;
  9664. };
  9665. /**
  9666. * Render the source map being generated to a string.
  9667. */
  9668. SourceMapGenerator.prototype.toString =
  9669. function SourceMapGenerator_toString() {
  9670. return JSON.stringify(this);
  9671. };
  9672. exports.SourceMapGenerator = SourceMapGenerator;
  9673. });
  9674. },{"./array-set":12,"./base64-vlq":13,"./util":19,"amdefine":20}],18:[function(_dereq_,module,exports){
  9675. /* -*- Mode: js; js-indent-level: 2; -*- */
  9676. /*
  9677. * Copyright 2011 Mozilla Foundation and contributors
  9678. * Licensed under the New BSD license. See LICENSE or:
  9679. * http://opensource.org/licenses/BSD-3-Clause
  9680. */
  9681. if (typeof define !== 'function') {
  9682. var define = _dereq_('amdefine')(module, _dereq_);
  9683. }
  9684. define(function (_dereq_, exports, module) {
  9685. var SourceMapGenerator = _dereq_('./source-map-generator').SourceMapGenerator;
  9686. var util = _dereq_('./util');
  9687. /**
  9688. * SourceNodes provide a way to abstract over interpolating/concatenating
  9689. * snippets of generated JavaScript source code while maintaining the line and
  9690. * column information associated with the original source code.
  9691. *
  9692. * @param aLine The original line number.
  9693. * @param aColumn The original column number.
  9694. * @param aSource The original source's filename.
  9695. * @param aChunks Optional. An array of strings which are snippets of
  9696. * generated JS, or other SourceNodes.
  9697. * @param aName The original identifier.
  9698. */
  9699. function SourceNode(aLine, aColumn, aSource, aChunks, aName) {
  9700. this.children = [];
  9701. this.sourceContents = {};
  9702. this.line = aLine === undefined ? null : aLine;
  9703. this.column = aColumn === undefined ? null : aColumn;
  9704. this.source = aSource === undefined ? null : aSource;
  9705. this.name = aName === undefined ? null : aName;
  9706. if (aChunks != null) this.add(aChunks);
  9707. }
  9708. /**
  9709. * Creates a SourceNode from generated code and a SourceMapConsumer.
  9710. *
  9711. * @param aGeneratedCode The generated code
  9712. * @param aSourceMapConsumer The SourceMap for the generated code
  9713. */
  9714. SourceNode.fromStringWithSourceMap =
  9715. function SourceNode_fromStringWithSourceMap(aGeneratedCode, aSourceMapConsumer) {
  9716. // The SourceNode we want to fill with the generated code
  9717. // and the SourceMap
  9718. var node = new SourceNode();
  9719. // The generated code
  9720. // Processed fragments are removed from this array.
  9721. var remainingLines = aGeneratedCode.split('\n');
  9722. // We need to remember the position of "remainingLines"
  9723. var lastGeneratedLine = 1, lastGeneratedColumn = 0;
  9724. // The generate SourceNodes we need a code range.
  9725. // To extract it current and last mapping is used.
  9726. // Here we store the last mapping.
  9727. var lastMapping = null;
  9728. aSourceMapConsumer.eachMapping(function (mapping) {
  9729. if (lastMapping === null) {
  9730. // We add the generated code until the first mapping
  9731. // to the SourceNode without any mapping.
  9732. // Each line is added as separate string.
  9733. while (lastGeneratedLine < mapping.generatedLine) {
  9734. node.add(remainingLines.shift() + "\n");
  9735. lastGeneratedLine++;
  9736. }
  9737. if (lastGeneratedColumn < mapping.generatedColumn) {
  9738. var nextLine = remainingLines[0];
  9739. node.add(nextLine.substr(0, mapping.generatedColumn));
  9740. remainingLines[0] = nextLine.substr(mapping.generatedColumn);
  9741. lastGeneratedColumn = mapping.generatedColumn;
  9742. }
  9743. } else {
  9744. // We add the code from "lastMapping" to "mapping":
  9745. // First check if there is a new line in between.
  9746. if (lastGeneratedLine < mapping.generatedLine) {
  9747. var code = "";
  9748. // Associate full lines with "lastMapping"
  9749. do {
  9750. code += remainingLines.shift() + "\n";
  9751. lastGeneratedLine++;
  9752. lastGeneratedColumn = 0;
  9753. } while (lastGeneratedLine < mapping.generatedLine);
  9754. // When we reached the correct line, we add code until we
  9755. // reach the correct column too.
  9756. if (lastGeneratedColumn < mapping.generatedColumn) {
  9757. var nextLine = remainingLines[0];
  9758. code += nextLine.substr(0, mapping.generatedColumn);
  9759. remainingLines[0] = nextLine.substr(mapping.generatedColumn);
  9760. lastGeneratedColumn = mapping.generatedColumn;
  9761. }
  9762. // Create the SourceNode.
  9763. addMappingWithCode(lastMapping, code);
  9764. } else {
  9765. // There is no new line in between.
  9766. // Associate the code between "lastGeneratedColumn" and
  9767. // "mapping.generatedColumn" with "lastMapping"
  9768. var nextLine = remainingLines[0];
  9769. var code = nextLine.substr(0, mapping.generatedColumn -
  9770. lastGeneratedColumn);
  9771. remainingLines[0] = nextLine.substr(mapping.generatedColumn -
  9772. lastGeneratedColumn);
  9773. lastGeneratedColumn = mapping.generatedColumn;
  9774. addMappingWithCode(lastMapping, code);
  9775. }
  9776. }
  9777. lastMapping = mapping;
  9778. }, this);
  9779. // We have processed all mappings.
  9780. // Associate the remaining code in the current line with "lastMapping"
  9781. // and add the remaining lines without any mapping
  9782. addMappingWithCode(lastMapping, remainingLines.join("\n"));
  9783. // Copy sourcesContent into SourceNode
  9784. aSourceMapConsumer.sources.forEach(function (sourceFile) {
  9785. var content = aSourceMapConsumer.sourceContentFor(sourceFile);
  9786. if (content) {
  9787. node.setSourceContent(sourceFile, content);
  9788. }
  9789. });
  9790. return node;
  9791. function addMappingWithCode(mapping, code) {
  9792. if (mapping === null || mapping.source === undefined) {
  9793. node.add(code);
  9794. } else {
  9795. node.add(new SourceNode(mapping.originalLine,
  9796. mapping.originalColumn,
  9797. mapping.source,
  9798. code,
  9799. mapping.name));
  9800. }
  9801. }
  9802. };
  9803. /**
  9804. * Add a chunk of generated JS to this source node.
  9805. *
  9806. * @param aChunk A string snippet of generated JS code, another instance of
  9807. * SourceNode, or an array where each member is one of those things.
  9808. */
  9809. SourceNode.prototype.add = function SourceNode_add(aChunk) {
  9810. if (Array.isArray(aChunk)) {
  9811. aChunk.forEach(function (chunk) {
  9812. this.add(chunk);
  9813. }, this);
  9814. }
  9815. else if (aChunk instanceof SourceNode || typeof aChunk === "string") {
  9816. if (aChunk) {
  9817. this.children.push(aChunk);
  9818. }
  9819. }
  9820. else {
  9821. throw new TypeError(
  9822. "Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk
  9823. );
  9824. }
  9825. return this;
  9826. };
  9827. /**
  9828. * Add a chunk of generated JS to the beginning of this source node.
  9829. *
  9830. * @param aChunk A string snippet of generated JS code, another instance of
  9831. * SourceNode, or an array where each member is one of those things.
  9832. */
  9833. SourceNode.prototype.prepend = function SourceNode_prepend(aChunk) {
  9834. if (Array.isArray(aChunk)) {
  9835. for (var i = aChunk.length-1; i >= 0; i--) {
  9836. this.prepend(aChunk[i]);
  9837. }
  9838. }
  9839. else if (aChunk instanceof SourceNode || typeof aChunk === "string") {
  9840. this.children.unshift(aChunk);
  9841. }
  9842. else {
  9843. throw new TypeError(
  9844. "Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk
  9845. );
  9846. }
  9847. return this;
  9848. };
  9849. /**
  9850. * Walk over the tree of JS snippets in this node and its children. The
  9851. * walking function is called once for each snippet of JS and is passed that
  9852. * snippet and the its original associated source's line/column location.
  9853. *
  9854. * @param aFn The traversal function.
  9855. */
  9856. SourceNode.prototype.walk = function SourceNode_walk(aFn) {
  9857. var chunk;
  9858. for (var i = 0, len = this.children.length; i < len; i++) {
  9859. chunk = this.children[i];
  9860. if (chunk instanceof SourceNode) {
  9861. chunk.walk(aFn);
  9862. }
  9863. else {
  9864. if (chunk !== '') {
  9865. aFn(chunk, { source: this.source,
  9866. line: this.line,
  9867. column: this.column,
  9868. name: this.name });
  9869. }
  9870. }
  9871. }
  9872. };
  9873. /**
  9874. * Like `String.prototype.join` except for SourceNodes. Inserts `aStr` between
  9875. * each of `this.children`.
  9876. *
  9877. * @param aSep The separator.
  9878. */
  9879. SourceNode.prototype.join = function SourceNode_join(aSep) {
  9880. var newChildren;
  9881. var i;
  9882. var len = this.children.length;
  9883. if (len > 0) {
  9884. newChildren = [];
  9885. for (i = 0; i < len-1; i++) {
  9886. newChildren.push(this.children[i]);
  9887. newChildren.push(aSep);
  9888. }
  9889. newChildren.push(this.children[i]);
  9890. this.children = newChildren;
  9891. }
  9892. return this;
  9893. };
  9894. /**
  9895. * Call String.prototype.replace on the very right-most source snippet. Useful
  9896. * for trimming whitespace from the end of a source node, etc.
  9897. *
  9898. * @param aPattern The pattern to replace.
  9899. * @param aReplacement The thing to replace the pattern with.
  9900. */
  9901. SourceNode.prototype.replaceRight = function SourceNode_replaceRight(aPattern, aReplacement) {
  9902. var lastChild = this.children[this.children.length - 1];
  9903. if (lastChild instanceof SourceNode) {
  9904. lastChild.replaceRight(aPattern, aReplacement);
  9905. }
  9906. else if (typeof lastChild === 'string') {
  9907. this.children[this.children.length - 1] = lastChild.replace(aPattern, aReplacement);
  9908. }
  9909. else {
  9910. this.children.push(''.replace(aPattern, aReplacement));
  9911. }
  9912. return this;
  9913. };
  9914. /**
  9915. * Set the source content for a source file. This will be added to the SourceMapGenerator
  9916. * in the sourcesContent field.
  9917. *
  9918. * @param aSourceFile The filename of the source file
  9919. * @param aSourceContent The content of the source file
  9920. */
  9921. SourceNode.prototype.setSourceContent =
  9922. function SourceNode_setSourceContent(aSourceFile, aSourceContent) {
  9923. this.sourceContents[util.toSetString(aSourceFile)] = aSourceContent;
  9924. };
  9925. /**
  9926. * Walk over the tree of SourceNodes. The walking function is called for each
  9927. * source file content and is passed the filename and source content.
  9928. *
  9929. * @param aFn The traversal function.
  9930. */
  9931. SourceNode.prototype.walkSourceContents =
  9932. function SourceNode_walkSourceContents(aFn) {
  9933. for (var i = 0, len = this.children.length; i < len; i++) {
  9934. if (this.children[i] instanceof SourceNode) {
  9935. this.children[i].walkSourceContents(aFn);
  9936. }
  9937. }
  9938. var sources = Object.keys(this.sourceContents);
  9939. for (var i = 0, len = sources.length; i < len; i++) {
  9940. aFn(util.fromSetString(sources[i]), this.sourceContents[sources[i]]);
  9941. }
  9942. };
  9943. /**
  9944. * Return the string representation of this source node. Walks over the tree
  9945. * and concatenates all the various snippets together to one string.
  9946. */
  9947. SourceNode.prototype.toString = function SourceNode_toString() {
  9948. var str = "";
  9949. this.walk(function (chunk) {
  9950. str += chunk;
  9951. });
  9952. return str;
  9953. };
  9954. /**
  9955. * Returns the string representation of this source node along with a source
  9956. * map.
  9957. */
  9958. SourceNode.prototype.toStringWithSourceMap = function SourceNode_toStringWithSourceMap(aArgs) {
  9959. var generated = {
  9960. code: "",
  9961. line: 1,
  9962. column: 0
  9963. };
  9964. var map = new SourceMapGenerator(aArgs);
  9965. var sourceMappingActive = false;
  9966. var lastOriginalSource = null;
  9967. var lastOriginalLine = null;
  9968. var lastOriginalColumn = null;
  9969. var lastOriginalName = null;
  9970. this.walk(function (chunk, original) {
  9971. generated.code += chunk;
  9972. if (original.source !== null
  9973. && original.line !== null
  9974. && original.column !== null) {
  9975. if(lastOriginalSource !== original.source
  9976. || lastOriginalLine !== original.line
  9977. || lastOriginalColumn !== original.column
  9978. || lastOriginalName !== original.name) {
  9979. map.addMapping({
  9980. source: original.source,
  9981. original: {
  9982. line: original.line,
  9983. column: original.column
  9984. },
  9985. generated: {
  9986. line: generated.line,
  9987. column: generated.column
  9988. },
  9989. name: original.name
  9990. });
  9991. }
  9992. lastOriginalSource = original.source;
  9993. lastOriginalLine = original.line;
  9994. lastOriginalColumn = original.column;
  9995. lastOriginalName = original.name;
  9996. sourceMappingActive = true;
  9997. } else if (sourceMappingActive) {
  9998. map.addMapping({
  9999. generated: {
  10000. line: generated.line,
  10001. column: generated.column
  10002. }
  10003. });
  10004. lastOriginalSource = null;
  10005. sourceMappingActive = false;
  10006. }
  10007. chunk.split('').forEach(function (ch) {
  10008. if (ch === '\n') {
  10009. generated.line++;
  10010. generated.column = 0;
  10011. } else {
  10012. generated.column++;
  10013. }
  10014. });
  10015. });
  10016. this.walkSourceContents(function (sourceFile, sourceContent) {
  10017. map.setSourceContent(sourceFile, sourceContent);
  10018. });
  10019. return { code: generated.code, map: map };
  10020. };
  10021. exports.SourceNode = SourceNode;
  10022. });
  10023. },{"./source-map-generator":17,"./util":19,"amdefine":20}],19:[function(_dereq_,module,exports){
  10024. /* -*- Mode: js; js-indent-level: 2; -*- */
  10025. /*
  10026. * Copyright 2011 Mozilla Foundation and contributors
  10027. * Licensed under the New BSD license. See LICENSE or:
  10028. * http://opensource.org/licenses/BSD-3-Clause
  10029. */
  10030. if (typeof define !== 'function') {
  10031. var define = _dereq_('amdefine')(module, _dereq_);
  10032. }
  10033. define(function (_dereq_, exports, module) {
  10034. /**
  10035. * This is a helper function for getting values from parameter/options
  10036. * objects.
  10037. *
  10038. * @param args The object we are extracting values from
  10039. * @param name The name of the property we are getting.
  10040. * @param defaultValue An optional value to return if the property is missing
  10041. * from the object. If this is not specified and the property is missing, an
  10042. * error will be thrown.
  10043. */
  10044. function getArg(aArgs, aName, aDefaultValue) {
  10045. if (aName in aArgs) {
  10046. return aArgs[aName];
  10047. } else if (arguments.length === 3) {
  10048. return aDefaultValue;
  10049. } else {
  10050. throw new Error('"' + aName + '" is a required argument.');
  10051. }
  10052. }
  10053. exports.getArg = getArg;
  10054. var urlRegexp = /([\w+\-.]+):\/\/((\w+:\w+)@)?([\w.]+)?(:(\d+))?(\S+)?/;
  10055. var dataUrlRegexp = /^data:.+\,.+/;
  10056. function urlParse(aUrl) {
  10057. var match = aUrl.match(urlRegexp);
  10058. if (!match) {
  10059. return null;
  10060. }
  10061. return {
  10062. scheme: match[1],
  10063. auth: match[3],
  10064. host: match[4],
  10065. port: match[6],
  10066. path: match[7]
  10067. };
  10068. }
  10069. exports.urlParse = urlParse;
  10070. function urlGenerate(aParsedUrl) {
  10071. var url = aParsedUrl.scheme + "://";
  10072. if (aParsedUrl.auth) {
  10073. url += aParsedUrl.auth + "@"
  10074. }
  10075. if (aParsedUrl.host) {
  10076. url += aParsedUrl.host;
  10077. }
  10078. if (aParsedUrl.port) {
  10079. url += ":" + aParsedUrl.port
  10080. }
  10081. if (aParsedUrl.path) {
  10082. url += aParsedUrl.path;
  10083. }
  10084. return url;
  10085. }
  10086. exports.urlGenerate = urlGenerate;
  10087. function join(aRoot, aPath) {
  10088. var url;
  10089. if (aPath.match(urlRegexp) || aPath.match(dataUrlRegexp)) {
  10090. return aPath;
  10091. }
  10092. if (aPath.charAt(0) === '/' && (url = urlParse(aRoot))) {
  10093. url.path = aPath;
  10094. return urlGenerate(url);
  10095. }
  10096. return aRoot.replace(/\/$/, '') + '/' + aPath;
  10097. }
  10098. exports.join = join;
  10099. /**
  10100. * Because behavior goes wacky when you set `__proto__` on objects, we
  10101. * have to prefix all the strings in our set with an arbitrary character.
  10102. *
  10103. * See https://github.com/mozilla/source-map/pull/31 and
  10104. * https://github.com/mozilla/source-map/issues/30
  10105. *
  10106. * @param String aStr
  10107. */
  10108. function toSetString(aStr) {
  10109. return '$' + aStr;
  10110. }
  10111. exports.toSetString = toSetString;
  10112. function fromSetString(aStr) {
  10113. return aStr.substr(1);
  10114. }
  10115. exports.fromSetString = fromSetString;
  10116. function relative(aRoot, aPath) {
  10117. aRoot = aRoot.replace(/\/$/, '');
  10118. var url = urlParse(aRoot);
  10119. if (aPath.charAt(0) == "/" && url && url.path == "/") {
  10120. return aPath.slice(1);
  10121. }
  10122. return aPath.indexOf(aRoot + '/') === 0
  10123. ? aPath.substr(aRoot.length + 1)
  10124. : aPath;
  10125. }
  10126. exports.relative = relative;
  10127. function strcmp(aStr1, aStr2) {
  10128. var s1 = aStr1 || "";
  10129. var s2 = aStr2 || "";
  10130. return (s1 > s2) - (s1 < s2);
  10131. }
  10132. /**
  10133. * Comparator between two mappings where the original positions are compared.
  10134. *
  10135. * Optionally pass in `true` as `onlyCompareGenerated` to consider two
  10136. * mappings with the same original source/line/column, but different generated
  10137. * line and column the same. Useful when searching for a mapping with a
  10138. * stubbed out mapping.
  10139. */
  10140. function compareByOriginalPositions(mappingA, mappingB, onlyCompareOriginal) {
  10141. var cmp;
  10142. cmp = strcmp(mappingA.source, mappingB.source);
  10143. if (cmp) {
  10144. return cmp;
  10145. }
  10146. cmp = mappingA.originalLine - mappingB.originalLine;
  10147. if (cmp) {
  10148. return cmp;
  10149. }
  10150. cmp = mappingA.originalColumn - mappingB.originalColumn;
  10151. if (cmp || onlyCompareOriginal) {
  10152. return cmp;
  10153. }
  10154. cmp = strcmp(mappingA.name, mappingB.name);
  10155. if (cmp) {
  10156. return cmp;
  10157. }
  10158. cmp = mappingA.generatedLine - mappingB.generatedLine;
  10159. if (cmp) {
  10160. return cmp;
  10161. }
  10162. return mappingA.generatedColumn - mappingB.generatedColumn;
  10163. };
  10164. exports.compareByOriginalPositions = compareByOriginalPositions;
  10165. /**
  10166. * Comparator between two mappings where the generated positions are
  10167. * compared.
  10168. *
  10169. * Optionally pass in `true` as `onlyCompareGenerated` to consider two
  10170. * mappings with the same generated line and column, but different
  10171. * source/name/original line and column the same. Useful when searching for a
  10172. * mapping with a stubbed out mapping.
  10173. */
  10174. function compareByGeneratedPositions(mappingA, mappingB, onlyCompareGenerated) {
  10175. var cmp;
  10176. cmp = mappingA.generatedLine - mappingB.generatedLine;
  10177. if (cmp) {
  10178. return cmp;
  10179. }
  10180. cmp = mappingA.generatedColumn - mappingB.generatedColumn;
  10181. if (cmp || onlyCompareGenerated) {
  10182. return cmp;
  10183. }
  10184. cmp = strcmp(mappingA.source, mappingB.source);
  10185. if (cmp) {
  10186. return cmp;
  10187. }
  10188. cmp = mappingA.originalLine - mappingB.originalLine;
  10189. if (cmp) {
  10190. return cmp;
  10191. }
  10192. cmp = mappingA.originalColumn - mappingB.originalColumn;
  10193. if (cmp) {
  10194. return cmp;
  10195. }
  10196. return strcmp(mappingA.name, mappingB.name);
  10197. };
  10198. exports.compareByGeneratedPositions = compareByGeneratedPositions;
  10199. });
  10200. },{"amdefine":20}],20:[function(_dereq_,module,exports){
  10201. (function (process,__filename){
  10202. /** vim: et:ts=4:sw=4:sts=4
  10203. * @license amdefine 0.1.0 Copyright (c) 2011, The Dojo Foundation All Rights Reserved.
  10204. * Available via the MIT or new BSD license.
  10205. * see: http://github.com/jrburke/amdefine for details
  10206. */
  10207. /*jslint node: true */
  10208. /*global module, process */
  10209. 'use strict';
  10210. /**
  10211. * Creates a define for node.
  10212. * @param {Object} module the "module" object that is defined by Node for the
  10213. * current module.
  10214. * @param {Function} [requireFn]. Node's require function for the current module.
  10215. * It only needs to be passed in Node versions before 0.5, when module.require
  10216. * did not exist.
  10217. * @returns {Function} a define function that is usable for the current node
  10218. * module.
  10219. */
  10220. function amdefine(module, requireFn) {
  10221. 'use strict';
  10222. var defineCache = {},
  10223. loaderCache = {},
  10224. alreadyCalled = false,
  10225. path = _dereq_('path'),
  10226. makeRequire, stringRequire;
  10227. /**
  10228. * Trims the . and .. from an array of path segments.
  10229. * It will keep a leading path segment if a .. will become
  10230. * the first path segment, to help with module name lookups,
  10231. * which act like paths, but can be remapped. But the end result,
  10232. * all paths that use this function should look normalized.
  10233. * NOTE: this method MODIFIES the input array.
  10234. * @param {Array} ary the array of path segments.
  10235. */
  10236. function trimDots(ary) {
  10237. var i, part;
  10238. for (i = 0; ary[i]; i+= 1) {
  10239. part = ary[i];
  10240. if (part === '.') {
  10241. ary.splice(i, 1);
  10242. i -= 1;
  10243. } else if (part === '..') {
  10244. if (i === 1 && (ary[2] === '..' || ary[0] === '..')) {
  10245. //End of the line. Keep at least one non-dot
  10246. //path segment at the front so it can be mapped
  10247. //correctly to disk. Otherwise, there is likely
  10248. //no path mapping for a path starting with '..'.
  10249. //This can still fail, but catches the most reasonable
  10250. //uses of ..
  10251. break;
  10252. } else if (i > 0) {
  10253. ary.splice(i - 1, 2);
  10254. i -= 2;
  10255. }
  10256. }
  10257. }
  10258. }
  10259. function normalize(name, baseName) {
  10260. var baseParts;
  10261. //Adjust any relative paths.
  10262. if (name && name.charAt(0) === '.') {
  10263. //If have a base name, try to normalize against it,
  10264. //otherwise, assume it is a top-level require that will
  10265. //be relative to baseUrl in the end.
  10266. if (baseName) {
  10267. baseParts = baseName.split('/');
  10268. baseParts = baseParts.slice(0, baseParts.length - 1);
  10269. baseParts = baseParts.concat(name.split('/'));
  10270. trimDots(baseParts);
  10271. name = baseParts.join('/');
  10272. }
  10273. }
  10274. return name;
  10275. }
  10276. /**
  10277. * Create the normalize() function passed to a loader plugin's
  10278. * normalize method.
  10279. */
  10280. function makeNormalize(relName) {
  10281. return function (name) {
  10282. return normalize(name, relName);
  10283. };
  10284. }
  10285. function makeLoad(id) {
  10286. function load(value) {
  10287. loaderCache[id] = value;
  10288. }
  10289. load.fromText = function (id, text) {
  10290. //This one is difficult because the text can/probably uses
  10291. //define, and any relative paths and requires should be relative
  10292. //to that id was it would be found on disk. But this would require
  10293. //bootstrapping a module/require fairly deeply from node core.
  10294. //Not sure how best to go about that yet.
  10295. throw new Error('amdefine does not implement load.fromText');
  10296. };
  10297. return load;
  10298. }
  10299. makeRequire = function (systemRequire, exports, module, relId) {
  10300. function amdRequire(deps, callback) {
  10301. if (typeof deps === 'string') {
  10302. //Synchronous, single module require('')
  10303. return stringRequire(systemRequire, exports, module, deps, relId);
  10304. } else {
  10305. //Array of dependencies with a callback.
  10306. //Convert the dependencies to modules.
  10307. deps = deps.map(function (depName) {
  10308. return stringRequire(systemRequire, exports, module, depName, relId);
  10309. });
  10310. //Wait for next tick to call back the require call.
  10311. process.nextTick(function () {
  10312. callback.apply(null, deps);
  10313. });
  10314. }
  10315. }
  10316. amdRequire.toUrl = function (filePath) {
  10317. if (filePath.indexOf('.') === 0) {
  10318. return normalize(filePath, path.dirname(module.filename));
  10319. } else {
  10320. return filePath;
  10321. }
  10322. };
  10323. return amdRequire;
  10324. };
  10325. //Favor explicit value, passed in if the module wants to support Node 0.4.
  10326. requireFn = requireFn || function req() {
  10327. return module.require.apply(module, arguments);
  10328. };
  10329. function runFactory(id, deps, factory) {
  10330. var r, e, m, result;
  10331. if (id) {
  10332. e = loaderCache[id] = {};
  10333. m = {
  10334. id: id,
  10335. uri: __filename,
  10336. exports: e
  10337. };
  10338. r = makeRequire(requireFn, e, m, id);
  10339. } else {
  10340. //Only support one define call per file
  10341. if (alreadyCalled) {
  10342. throw new Error('amdefine with no module ID cannot be called more than once per file.');
  10343. }
  10344. alreadyCalled = true;
  10345. //Use the real variables from node
  10346. //Use module.exports for exports, since
  10347. //the exports in here is amdefine exports.
  10348. e = module.exports;
  10349. m = module;
  10350. r = makeRequire(requireFn, e, m, module.id);
  10351. }
  10352. //If there are dependencies, they are strings, so need
  10353. //to convert them to dependency values.
  10354. if (deps) {
  10355. deps = deps.map(function (depName) {
  10356. return r(depName);
  10357. });
  10358. }
  10359. //Call the factory with the right dependencies.
  10360. if (typeof factory === 'function') {
  10361. result = factory.apply(m.exports, deps);
  10362. } else {
  10363. result = factory;
  10364. }
  10365. if (result !== undefined) {
  10366. m.exports = result;
  10367. if (id) {
  10368. loaderCache[id] = m.exports;
  10369. }
  10370. }
  10371. }
  10372. stringRequire = function (systemRequire, exports, module, id, relId) {
  10373. //Split the ID by a ! so that
  10374. var index = id.indexOf('!'),
  10375. originalId = id,
  10376. prefix, plugin;
  10377. if (index === -1) {
  10378. id = normalize(id, relId);
  10379. //Straight module lookup. If it is one of the special dependencies,
  10380. //deal with it, otherwise, delegate to node.
  10381. if (id === 'require') {
  10382. return makeRequire(systemRequire, exports, module, relId);
  10383. } else if (id === 'exports') {
  10384. return exports;
  10385. } else if (id === 'module') {
  10386. return module;
  10387. } else if (loaderCache.hasOwnProperty(id)) {
  10388. return loaderCache[id];
  10389. } else if (defineCache[id]) {
  10390. runFactory.apply(null, defineCache[id]);
  10391. return loaderCache[id];
  10392. } else {
  10393. if(systemRequire) {
  10394. return systemRequire(originalId);
  10395. } else {
  10396. throw new Error('No module with ID: ' + id);
  10397. }
  10398. }
  10399. } else {
  10400. //There is a plugin in play.
  10401. prefix = id.substring(0, index);
  10402. id = id.substring(index + 1, id.length);
  10403. plugin = stringRequire(systemRequire, exports, module, prefix, relId);
  10404. if (plugin.normalize) {
  10405. id = plugin.normalize(id, makeNormalize(relId));
  10406. } else {
  10407. //Normalize the ID normally.
  10408. id = normalize(id, relId);
  10409. }
  10410. if (loaderCache[id]) {
  10411. return loaderCache[id];
  10412. } else {
  10413. plugin.load(id, makeRequire(systemRequire, exports, module, relId), makeLoad(id), {});
  10414. return loaderCache[id];
  10415. }
  10416. }
  10417. };
  10418. //Create a define function specific to the module asking for amdefine.
  10419. function define(id, deps, factory) {
  10420. if (Array.isArray(id)) {
  10421. factory = deps;
  10422. deps = id;
  10423. id = undefined;
  10424. } else if (typeof id !== 'string') {
  10425. factory = id;
  10426. id = deps = undefined;
  10427. }
  10428. if (deps && !Array.isArray(deps)) {
  10429. factory = deps;
  10430. deps = undefined;
  10431. }
  10432. if (!deps) {
  10433. deps = ['require', 'exports', 'module'];
  10434. }
  10435. //Set up properties for this module. If an ID, then use
  10436. //internal cache. If no ID, then use the external variables
  10437. //for this node module.
  10438. if (id) {
  10439. //Put the module in deep freeze until there is a
  10440. //require call for it.
  10441. defineCache[id] = [id, deps, factory];
  10442. } else {
  10443. runFactory(id, deps, factory);
  10444. }
  10445. }
  10446. //define.require, which has access to all the values in the
  10447. //cache. Useful for AMD modules that all have IDs in the file,
  10448. //but need to finally export a value to node based on one of those
  10449. //IDs.
  10450. define.require = function (id) {
  10451. if (loaderCache[id]) {
  10452. return loaderCache[id];
  10453. }
  10454. if (defineCache[id]) {
  10455. runFactory.apply(null, defineCache[id]);
  10456. return loaderCache[id];
  10457. }
  10458. };
  10459. define.amd = {};
  10460. return define;
  10461. }
  10462. module.exports = amdefine;
  10463. }).call(this,_dereq_('_process'),"/node_modules/jstransform/node_modules/source-map/node_modules/amdefine/amdefine.js")
  10464. },{"_process":8,"path":7}],21:[function(_dereq_,module,exports){
  10465. /**
  10466. * Copyright 2013 Facebook, Inc.
  10467. *
  10468. * Licensed under the Apache License, Version 2.0 (the "License");
  10469. * you may not use this file except in compliance with the License.
  10470. * You may obtain a copy of the License at
  10471. *
  10472. * http://www.apache.org/licenses/LICENSE-2.0
  10473. *
  10474. * Unless required by applicable law or agreed to in writing, software
  10475. * distributed under the License is distributed on an "AS IS" BASIS,
  10476. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10477. * See the License for the specific language governing permissions and
  10478. * limitations under the License.
  10479. */
  10480. var docblockRe = /^\s*(\/\*\*(.|\r?\n)*?\*\/)/;
  10481. var ltrimRe = /^\s*/;
  10482. /**
  10483. * @param {String} contents
  10484. * @return {String}
  10485. */
  10486. function extract(contents) {
  10487. var match = contents.match(docblockRe);
  10488. if (match) {
  10489. return match[0].replace(ltrimRe, '') || '';
  10490. }
  10491. return '';
  10492. }
  10493. var commentStartRe = /^\/\*\*?/;
  10494. var commentEndRe = /\*+\/$/;
  10495. var wsRe = /[\t ]+/g;
  10496. var stringStartRe = /(\r?\n|^) *\*/g;
  10497. var multilineRe = /(?:^|\r?\n) *(@[^\r\n]*?) *\r?\n *([^@\r\n\s][^@\r\n]+?) *\r?\n/g;
  10498. var propertyRe = /(?:^|\r?\n) *@(\S+) *([^\r\n]*)/g;
  10499. /**
  10500. * @param {String} contents
  10501. * @return {Array}
  10502. */
  10503. function parse(docblock) {
  10504. docblock = docblock
  10505. .replace(commentStartRe, '')
  10506. .replace(commentEndRe, '')
  10507. .replace(wsRe, ' ')
  10508. .replace(stringStartRe, '$1');
  10509. // Normalize multi-line directives
  10510. var prev = '';
  10511. while (prev != docblock) {
  10512. prev = docblock;
  10513. docblock = docblock.replace(multilineRe, "\n$1 $2\n");
  10514. }
  10515. docblock = docblock.trim();
  10516. var result = [];
  10517. var match;
  10518. while (match = propertyRe.exec(docblock)) {
  10519. result.push([match[1], match[2]]);
  10520. }
  10521. return result;
  10522. }
  10523. /**
  10524. * Same as parse but returns an object of prop: value instead of array of paris
  10525. * If a property appers more than once the last one will be returned
  10526. *
  10527. * @param {String} contents
  10528. * @return {Object}
  10529. */
  10530. function parseAsObject(docblock) {
  10531. var pairs = parse(docblock);
  10532. var result = {};
  10533. for (var i = 0; i < pairs.length; i++) {
  10534. result[pairs[i][0]] = pairs[i][1];
  10535. }
  10536. return result;
  10537. }
  10538. exports.extract = extract;
  10539. exports.parse = parse;
  10540. exports.parseAsObject = parseAsObject;
  10541. },{}],22:[function(_dereq_,module,exports){
  10542. /**
  10543. * Copyright 2013 Facebook, Inc.
  10544. *
  10545. * Licensed under the Apache License, Version 2.0 (the "License");
  10546. * you may not use this file except in compliance with the License.
  10547. * You may obtain a copy of the License at
  10548. *
  10549. * http://www.apache.org/licenses/LICENSE-2.0
  10550. *
  10551. * Unless required by applicable law or agreed to in writing, software
  10552. * distributed under the License is distributed on an "AS IS" BASIS,
  10553. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10554. * See the License for the specific language governing permissions and
  10555. * limitations under the License.
  10556. */
  10557. /*jslint node: true*/
  10558. "use strict";
  10559. var esprima = _dereq_('esprima-fb');
  10560. var utils = _dereq_('./utils');
  10561. var getBoundaryNode = utils.getBoundaryNode;
  10562. var declareIdentInScope = utils.declareIdentInLocalScope;
  10563. var initScopeMetadata = utils.initScopeMetadata;
  10564. var Syntax = esprima.Syntax;
  10565. /**
  10566. * @param {object} node
  10567. * @param {object} parentNode
  10568. * @return {boolean}
  10569. */
  10570. function _nodeIsClosureScopeBoundary(node, parentNode) {
  10571. if (node.type === Syntax.Program) {
  10572. return true;
  10573. }
  10574. var parentIsFunction =
  10575. parentNode.type === Syntax.FunctionDeclaration
  10576. || parentNode.type === Syntax.FunctionExpression
  10577. || parentNode.type === Syntax.ArrowFunctionExpression;
  10578. var parentIsCurlylessArrowFunc =
  10579. parentNode.type === Syntax.ArrowFunctionExpression
  10580. && node === parentNode.body;
  10581. return parentIsFunction
  10582. && (node.type === Syntax.BlockStatement || parentIsCurlylessArrowFunc);
  10583. }
  10584. function _nodeIsBlockScopeBoundary(node, parentNode) {
  10585. if (node.type === Syntax.Program) {
  10586. return false;
  10587. }
  10588. return node.type === Syntax.BlockStatement
  10589. && parentNode.type === Syntax.CatchClause;
  10590. }
  10591. /**
  10592. * @param {object} node
  10593. * @param {array} path
  10594. * @param {object} state
  10595. */
  10596. function traverse(node, path, state) {
  10597. /*jshint -W004*/
  10598. // Create a scope stack entry if this is the first node we've encountered in
  10599. // its local scope
  10600. var startIndex = null;
  10601. var parentNode = path[0];
  10602. if (!Array.isArray(node) && state.localScope.parentNode !== parentNode) {
  10603. if (_nodeIsClosureScopeBoundary(node, parentNode)) {
  10604. var scopeIsStrict = state.scopeIsStrict;
  10605. if (!scopeIsStrict
  10606. && (node.type === Syntax.BlockStatement
  10607. || node.type === Syntax.Program)) {
  10608. scopeIsStrict =
  10609. node.body.length > 0
  10610. && node.body[0].type === Syntax.ExpressionStatement
  10611. && node.body[0].expression.type === Syntax.Literal
  10612. && node.body[0].expression.value === 'use strict';
  10613. }
  10614. if (node.type === Syntax.Program) {
  10615. startIndex = state.g.buffer.length;
  10616. state = utils.updateState(state, {
  10617. scopeIsStrict: scopeIsStrict
  10618. });
  10619. } else {
  10620. startIndex = state.g.buffer.length + 1;
  10621. state = utils.updateState(state, {
  10622. localScope: {
  10623. parentNode: parentNode,
  10624. parentScope: state.localScope,
  10625. identifiers: {},
  10626. tempVarIndex: 0,
  10627. tempVars: []
  10628. },
  10629. scopeIsStrict: scopeIsStrict
  10630. });
  10631. // All functions have an implicit 'arguments' object in scope
  10632. declareIdentInScope('arguments', initScopeMetadata(node), state);
  10633. // Include function arg identifiers in the scope boundaries of the
  10634. // function
  10635. if (parentNode.params.length > 0) {
  10636. var param;
  10637. var metadata = initScopeMetadata(parentNode, path.slice(1), path[0]);
  10638. for (var i = 0; i < parentNode.params.length; i++) {
  10639. param = parentNode.params[i];
  10640. if (param.type === Syntax.Identifier) {
  10641. declareIdentInScope(param.name, metadata, state);
  10642. }
  10643. }
  10644. }
  10645. // Include rest arg identifiers in the scope boundaries of their
  10646. // functions
  10647. if (parentNode.rest) {
  10648. var metadata = initScopeMetadata(
  10649. parentNode,
  10650. path.slice(1),
  10651. path[0]
  10652. );
  10653. declareIdentInScope(parentNode.rest.name, metadata, state);
  10654. }
  10655. // Named FunctionExpressions scope their name within the body block of
  10656. // themselves only
  10657. if (parentNode.type === Syntax.FunctionExpression && parentNode.id) {
  10658. var metaData =
  10659. initScopeMetadata(parentNode, path.parentNodeslice, parentNode);
  10660. declareIdentInScope(parentNode.id.name, metaData, state);
  10661. }
  10662. }
  10663. // Traverse and find all local identifiers in this closure first to
  10664. // account for function/variable declaration hoisting
  10665. collectClosureIdentsAndTraverse(node, path, state);
  10666. }
  10667. if (_nodeIsBlockScopeBoundary(node, parentNode)) {
  10668. startIndex = state.g.buffer.length;
  10669. state = utils.updateState(state, {
  10670. localScope: {
  10671. parentNode: parentNode,
  10672. parentScope: state.localScope,
  10673. identifiers: {},
  10674. tempVarIndex: 0,
  10675. tempVars: []
  10676. }
  10677. });
  10678. if (parentNode.type === Syntax.CatchClause) {
  10679. var metadata = initScopeMetadata(
  10680. parentNode,
  10681. path.slice(1),
  10682. parentNode
  10683. );
  10684. declareIdentInScope(parentNode.param.name, metadata, state);
  10685. }
  10686. collectBlockIdentsAndTraverse(node, path, state);
  10687. }
  10688. }
  10689. // Only catchup() before and after traversing a child node
  10690. function traverser(node, path, state) {
  10691. node.range && utils.catchup(node.range[0], state);
  10692. traverse(node, path, state);
  10693. node.range && utils.catchup(node.range[1], state);
  10694. }
  10695. utils.analyzeAndTraverse(walker, traverser, node, path, state);
  10696. // Inject temp variables into the scope.
  10697. if (startIndex !== null) {
  10698. utils.injectTempVarDeclarations(state, startIndex);
  10699. }
  10700. }
  10701. function collectClosureIdentsAndTraverse(node, path, state) {
  10702. utils.analyzeAndTraverse(
  10703. visitLocalClosureIdentifiers,
  10704. collectClosureIdentsAndTraverse,
  10705. node,
  10706. path,
  10707. state
  10708. );
  10709. }
  10710. function collectBlockIdentsAndTraverse(node, path, state) {
  10711. utils.analyzeAndTraverse(
  10712. visitLocalBlockIdentifiers,
  10713. collectBlockIdentsAndTraverse,
  10714. node,
  10715. path,
  10716. state
  10717. );
  10718. }
  10719. function visitLocalClosureIdentifiers(node, path, state) {
  10720. var metaData;
  10721. switch (node.type) {
  10722. case Syntax.ArrowFunctionExpression:
  10723. case Syntax.FunctionExpression:
  10724. // Function expressions don't get their names (if there is one) added to
  10725. // the closure scope they're defined in
  10726. return false;
  10727. case Syntax.ClassDeclaration:
  10728. case Syntax.ClassExpression:
  10729. case Syntax.FunctionDeclaration:
  10730. if (node.id) {
  10731. metaData = initScopeMetadata(getBoundaryNode(path), path.slice(), node);
  10732. declareIdentInScope(node.id.name, metaData, state);
  10733. }
  10734. return false;
  10735. case Syntax.VariableDeclarator:
  10736. // Variables have function-local scope
  10737. if (path[0].kind === 'var') {
  10738. metaData = initScopeMetadata(getBoundaryNode(path), path.slice(), node);
  10739. declareIdentInScope(node.id.name, metaData, state);
  10740. }
  10741. break;
  10742. }
  10743. }
  10744. function visitLocalBlockIdentifiers(node, path, state) {
  10745. // TODO: Support 'let' here...maybe...one day...or something...
  10746. if (node.type === Syntax.CatchClause) {
  10747. return false;
  10748. }
  10749. }
  10750. function walker(node, path, state) {
  10751. var visitors = state.g.visitors;
  10752. for (var i = 0; i < visitors.length; i++) {
  10753. if (visitors[i].test(node, path, state)) {
  10754. return visitors[i](traverse, node, path, state);
  10755. }
  10756. }
  10757. }
  10758. var _astCache = {};
  10759. function getAstForSource(source, options) {
  10760. if (_astCache[source] && !options.disableAstCache) {
  10761. return _astCache[source];
  10762. }
  10763. var ast = esprima.parse(source, {
  10764. comment: true,
  10765. loc: true,
  10766. range: true,
  10767. sourceType: options.sourceType
  10768. });
  10769. if (!options.disableAstCache) {
  10770. _astCache[source] = ast;
  10771. }
  10772. return ast;
  10773. }
  10774. /**
  10775. * Applies all available transformations to the source
  10776. * @param {array} visitors
  10777. * @param {string} source
  10778. * @param {?object} options
  10779. * @return {object}
  10780. */
  10781. function transform(visitors, source, options) {
  10782. options = options || {};
  10783. var ast;
  10784. try {
  10785. ast = getAstForSource(source, options);
  10786. } catch (e) {
  10787. e.message = 'Parse Error: ' + e.message;
  10788. throw e;
  10789. }
  10790. var state = utils.createState(source, ast, options);
  10791. state.g.visitors = visitors;
  10792. if (options.sourceMap) {
  10793. var SourceMapGenerator = _dereq_('source-map').SourceMapGenerator;
  10794. state.g.sourceMap = new SourceMapGenerator({file: options.filename || 'transformed.js'});
  10795. }
  10796. traverse(ast, [], state);
  10797. utils.catchup(source.length, state);
  10798. var ret = {code: state.g.buffer, extra: state.g.extra};
  10799. if (options.sourceMap) {
  10800. ret.sourceMap = state.g.sourceMap;
  10801. ret.sourceMapFilename = options.filename || 'source.js';
  10802. }
  10803. return ret;
  10804. }
  10805. exports.transform = transform;
  10806. exports.Syntax = Syntax;
  10807. },{"./utils":23,"esprima-fb":9,"source-map":11}],23:[function(_dereq_,module,exports){
  10808. /**
  10809. * Copyright 2013 Facebook, Inc.
  10810. *
  10811. * Licensed under the Apache License, Version 2.0 (the "License");
  10812. * you may not use this file except in compliance with the License.
  10813. * You may obtain a copy of the License at
  10814. *
  10815. * http://www.apache.org/licenses/LICENSE-2.0
  10816. *
  10817. * Unless required by applicable law or agreed to in writing, software
  10818. * distributed under the License is distributed on an "AS IS" BASIS,
  10819. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10820. * See the License for the specific language governing permissions and
  10821. * limitations under the License.
  10822. */
  10823. /*jslint node: true*/
  10824. var Syntax = _dereq_('esprima-fb').Syntax;
  10825. var leadingIndentRegexp = /(^|\n)( {2}|\t)/g;
  10826. var nonWhiteRegexp = /(\S)/g;
  10827. /**
  10828. * A `state` object represents the state of the parser. It has "local" and
  10829. * "global" parts. Global contains parser position, source, etc. Local contains
  10830. * scope based properties like current class name. State should contain all the
  10831. * info required for transformation. It's the only mandatory object that is
  10832. * being passed to every function in transform chain.
  10833. *
  10834. * @param {string} source
  10835. * @param {object} transformOptions
  10836. * @return {object}
  10837. */
  10838. function createState(source, rootNode, transformOptions) {
  10839. return {
  10840. /**
  10841. * A tree representing the current local scope (and its lexical scope chain)
  10842. * Useful for tracking identifiers from parent scopes, etc.
  10843. * @type {Object}
  10844. */
  10845. localScope: {
  10846. parentNode: rootNode,
  10847. parentScope: null,
  10848. identifiers: {},
  10849. tempVarIndex: 0,
  10850. tempVars: []
  10851. },
  10852. /**
  10853. * The name (and, if applicable, expression) of the super class
  10854. * @type {Object}
  10855. */
  10856. superClass: null,
  10857. /**
  10858. * The namespace to use when munging identifiers
  10859. * @type {String}
  10860. */
  10861. mungeNamespace: '',
  10862. /**
  10863. * Ref to the node for the current MethodDefinition
  10864. * @type {Object}
  10865. */
  10866. methodNode: null,
  10867. /**
  10868. * Ref to the node for the FunctionExpression of the enclosing
  10869. * MethodDefinition
  10870. * @type {Object}
  10871. */
  10872. methodFuncNode: null,
  10873. /**
  10874. * Name of the enclosing class
  10875. * @type {String}
  10876. */
  10877. className: null,
  10878. /**
  10879. * Whether we're currently within a `strict` scope
  10880. * @type {Bool}
  10881. */
  10882. scopeIsStrict: null,
  10883. /**
  10884. * Indentation offset
  10885. * @type {Number}
  10886. */
  10887. indentBy: 0,
  10888. /**
  10889. * Global state (not affected by updateState)
  10890. * @type {Object}
  10891. */
  10892. g: {
  10893. /**
  10894. * A set of general options that transformations can consider while doing
  10895. * a transformation:
  10896. *
  10897. * - minify
  10898. * Specifies that transformation steps should do their best to minify
  10899. * the output source when possible. This is useful for places where
  10900. * minification optimizations are possible with higher-level context
  10901. * info than what jsxmin can provide.
  10902. *
  10903. * For example, the ES6 class transform will minify munged private
  10904. * variables if this flag is set.
  10905. */
  10906. opts: transformOptions,
  10907. /**
  10908. * Current position in the source code
  10909. * @type {Number}
  10910. */
  10911. position: 0,
  10912. /**
  10913. * Auxiliary data to be returned by transforms
  10914. * @type {Object}
  10915. */
  10916. extra: {},
  10917. /**
  10918. * Buffer containing the result
  10919. * @type {String}
  10920. */
  10921. buffer: '',
  10922. /**
  10923. * Source that is being transformed
  10924. * @type {String}
  10925. */
  10926. source: source,
  10927. /**
  10928. * Cached parsed docblock (see getDocblock)
  10929. * @type {object}
  10930. */
  10931. docblock: null,
  10932. /**
  10933. * Whether the thing was used
  10934. * @type {Boolean}
  10935. */
  10936. tagNamespaceUsed: false,
  10937. /**
  10938. * If using bolt xjs transformation
  10939. * @type {Boolean}
  10940. */
  10941. isBolt: undefined,
  10942. /**
  10943. * Whether to record source map (expensive) or not
  10944. * @type {SourceMapGenerator|null}
  10945. */
  10946. sourceMap: null,
  10947. /**
  10948. * Filename of the file being processed. Will be returned as a source
  10949. * attribute in the source map
  10950. */
  10951. sourceMapFilename: 'source.js',
  10952. /**
  10953. * Only when source map is used: last line in the source for which
  10954. * source map was generated
  10955. * @type {Number}
  10956. */
  10957. sourceLine: 1,
  10958. /**
  10959. * Only when source map is used: last line in the buffer for which
  10960. * source map was generated
  10961. * @type {Number}
  10962. */
  10963. bufferLine: 1,
  10964. /**
  10965. * The top-level Program AST for the original file.
  10966. */
  10967. originalProgramAST: null,
  10968. sourceColumn: 0,
  10969. bufferColumn: 0
  10970. }
  10971. };
  10972. }
  10973. /**
  10974. * Updates a copy of a given state with "update" and returns an updated state.
  10975. *
  10976. * @param {object} state
  10977. * @param {object} update
  10978. * @return {object}
  10979. */
  10980. function updateState(state, update) {
  10981. var ret = Object.create(state);
  10982. Object.keys(update).forEach(function(updatedKey) {
  10983. ret[updatedKey] = update[updatedKey];
  10984. });
  10985. return ret;
  10986. }
  10987. /**
  10988. * Given a state fill the resulting buffer from the original source up to
  10989. * the end
  10990. *
  10991. * @param {number} end
  10992. * @param {object} state
  10993. * @param {?function} contentTransformer Optional callback to transform newly
  10994. * added content.
  10995. */
  10996. function catchup(end, state, contentTransformer) {
  10997. if (end < state.g.position) {
  10998. // cannot move backwards
  10999. return;
  11000. }
  11001. var source = state.g.source.substring(state.g.position, end);
  11002. var transformed = updateIndent(source, state);
  11003. if (state.g.sourceMap && transformed) {
  11004. // record where we are
  11005. state.g.sourceMap.addMapping({
  11006. generated: { line: state.g.bufferLine, column: state.g.bufferColumn },
  11007. original: { line: state.g.sourceLine, column: state.g.sourceColumn },
  11008. source: state.g.sourceMapFilename
  11009. });
  11010. // record line breaks in transformed source
  11011. var sourceLines = source.split('\n');
  11012. var transformedLines = transformed.split('\n');
  11013. // Add line break mappings between last known mapping and the end of the
  11014. // added piece. So for the code piece
  11015. // (foo, bar);
  11016. // > var x = 2;
  11017. // > var b = 3;
  11018. // var c =
  11019. // only add lines marked with ">": 2, 3.
  11020. for (var i = 1; i < sourceLines.length - 1; i++) {
  11021. state.g.sourceMap.addMapping({
  11022. generated: { line: state.g.bufferLine, column: 0 },
  11023. original: { line: state.g.sourceLine, column: 0 },
  11024. source: state.g.sourceMapFilename
  11025. });
  11026. state.g.sourceLine++;
  11027. state.g.bufferLine++;
  11028. }
  11029. // offset for the last piece
  11030. if (sourceLines.length > 1) {
  11031. state.g.sourceLine++;
  11032. state.g.bufferLine++;
  11033. state.g.sourceColumn = 0;
  11034. state.g.bufferColumn = 0;
  11035. }
  11036. state.g.sourceColumn += sourceLines[sourceLines.length - 1].length;
  11037. state.g.bufferColumn +=
  11038. transformedLines[transformedLines.length - 1].length;
  11039. }
  11040. state.g.buffer +=
  11041. contentTransformer ? contentTransformer(transformed) : transformed;
  11042. state.g.position = end;
  11043. }
  11044. /**
  11045. * Returns original source for an AST node.
  11046. * @param {object} node
  11047. * @param {object} state
  11048. * @return {string}
  11049. */
  11050. function getNodeSourceText(node, state) {
  11051. return state.g.source.substring(node.range[0], node.range[1]);
  11052. }
  11053. function _replaceNonWhite(value) {
  11054. return value.replace(nonWhiteRegexp, ' ');
  11055. }
  11056. /**
  11057. * Removes all non-whitespace characters
  11058. */
  11059. function _stripNonWhite(value) {
  11060. return value.replace(nonWhiteRegexp, '');
  11061. }
  11062. /**
  11063. * Finds the position of the next instance of the specified syntactic char in
  11064. * the pending source.
  11065. *
  11066. * NOTE: This will skip instances of the specified char if they sit inside a
  11067. * comment body.
  11068. *
  11069. * NOTE: This function also assumes that the buffer's current position is not
  11070. * already within a comment or a string. This is rarely the case since all
  11071. * of the buffer-advancement utility methods tend to be used on syntactic
  11072. * nodes' range values -- but it's a small gotcha that's worth mentioning.
  11073. */
  11074. function getNextSyntacticCharOffset(char, state) {
  11075. var pendingSource = state.g.source.substring(state.g.position);
  11076. var pendingSourceLines = pendingSource.split('\n');
  11077. var charOffset = 0;
  11078. var line;
  11079. var withinBlockComment = false;
  11080. var withinString = false;
  11081. lineLoop: while ((line = pendingSourceLines.shift()) !== undefined) {
  11082. var lineEndPos = charOffset + line.length;
  11083. charLoop: for (; charOffset < lineEndPos; charOffset++) {
  11084. var currChar = pendingSource[charOffset];
  11085. if (currChar === '"' || currChar === '\'') {
  11086. withinString = !withinString;
  11087. continue charLoop;
  11088. } else if (withinString) {
  11089. continue charLoop;
  11090. } else if (charOffset + 1 < lineEndPos) {
  11091. var nextTwoChars = currChar + line[charOffset + 1];
  11092. if (nextTwoChars === '//') {
  11093. charOffset = lineEndPos + 1;
  11094. continue lineLoop;
  11095. } else if (nextTwoChars === '/*') {
  11096. withinBlockComment = true;
  11097. charOffset += 1;
  11098. continue charLoop;
  11099. } else if (nextTwoChars === '*/') {
  11100. withinBlockComment = false;
  11101. charOffset += 1;
  11102. continue charLoop;
  11103. }
  11104. }
  11105. if (!withinBlockComment && currChar === char) {
  11106. return charOffset + state.g.position;
  11107. }
  11108. }
  11109. // Account for '\n'
  11110. charOffset++;
  11111. withinString = false;
  11112. }
  11113. throw new Error('`' + char + '` not found!');
  11114. }
  11115. /**
  11116. * Catches up as `catchup` but replaces non-whitespace chars with spaces.
  11117. */
  11118. function catchupWhiteOut(end, state) {
  11119. catchup(end, state, _replaceNonWhite);
  11120. }
  11121. /**
  11122. * Catches up as `catchup` but removes all non-whitespace characters.
  11123. */
  11124. function catchupWhiteSpace(end, state) {
  11125. catchup(end, state, _stripNonWhite);
  11126. }
  11127. /**
  11128. * Removes all non-newline characters
  11129. */
  11130. var reNonNewline = /[^\n]/g;
  11131. function stripNonNewline(value) {
  11132. return value.replace(reNonNewline, function() {
  11133. return '';
  11134. });
  11135. }
  11136. /**
  11137. * Catches up as `catchup` but removes all non-newline characters.
  11138. *
  11139. * Equivalent to appending as many newlines as there are in the original source
  11140. * between the current position and `end`.
  11141. */
  11142. function catchupNewlines(end, state) {
  11143. catchup(end, state, stripNonNewline);
  11144. }
  11145. /**
  11146. * Same as catchup but does not touch the buffer
  11147. *
  11148. * @param {number} end
  11149. * @param {object} state
  11150. */
  11151. function move(end, state) {
  11152. // move the internal cursors
  11153. if (state.g.sourceMap) {
  11154. if (end < state.g.position) {
  11155. state.g.position = 0;
  11156. state.g.sourceLine = 1;
  11157. state.g.sourceColumn = 0;
  11158. }
  11159. var source = state.g.source.substring(state.g.position, end);
  11160. var sourceLines = source.split('\n');
  11161. if (sourceLines.length > 1) {
  11162. state.g.sourceLine += sourceLines.length - 1;
  11163. state.g.sourceColumn = 0;
  11164. }
  11165. state.g.sourceColumn += sourceLines[sourceLines.length - 1].length;
  11166. }
  11167. state.g.position = end;
  11168. }
  11169. /**
  11170. * Appends a string of text to the buffer
  11171. *
  11172. * @param {string} str
  11173. * @param {object} state
  11174. */
  11175. function append(str, state) {
  11176. if (state.g.sourceMap && str) {
  11177. state.g.sourceMap.addMapping({
  11178. generated: { line: state.g.bufferLine, column: state.g.bufferColumn },
  11179. original: { line: state.g.sourceLine, column: state.g.sourceColumn },
  11180. source: state.g.sourceMapFilename
  11181. });
  11182. var transformedLines = str.split('\n');
  11183. if (transformedLines.length > 1) {
  11184. state.g.bufferLine += transformedLines.length - 1;
  11185. state.g.bufferColumn = 0;
  11186. }
  11187. state.g.bufferColumn +=
  11188. transformedLines[transformedLines.length - 1].length;
  11189. }
  11190. state.g.buffer += str;
  11191. }
  11192. /**
  11193. * Update indent using state.indentBy property. Indent is measured in
  11194. * double spaces. Updates a single line only.
  11195. *
  11196. * @param {string} str
  11197. * @param {object} state
  11198. * @return {string}
  11199. */
  11200. function updateIndent(str, state) {
  11201. /*jshint -W004*/
  11202. var indentBy = state.indentBy;
  11203. if (indentBy < 0) {
  11204. for (var i = 0; i < -indentBy; i++) {
  11205. str = str.replace(leadingIndentRegexp, '$1');
  11206. }
  11207. } else {
  11208. for (var i = 0; i < indentBy; i++) {
  11209. str = str.replace(leadingIndentRegexp, '$1$2$2');
  11210. }
  11211. }
  11212. return str;
  11213. }
  11214. /**
  11215. * Calculates indent from the beginning of the line until "start" or the first
  11216. * character before start.
  11217. * @example
  11218. * " foo.bar()"
  11219. * ^
  11220. * start
  11221. * indent will be " "
  11222. *
  11223. * @param {number} start
  11224. * @param {object} state
  11225. * @return {string}
  11226. */
  11227. function indentBefore(start, state) {
  11228. var end = start;
  11229. start = start - 1;
  11230. while (start > 0 && state.g.source[start] != '\n') {
  11231. if (!state.g.source[start].match(/[ \t]/)) {
  11232. end = start;
  11233. }
  11234. start--;
  11235. }
  11236. return state.g.source.substring(start + 1, end);
  11237. }
  11238. function getDocblock(state) {
  11239. if (!state.g.docblock) {
  11240. var docblock = _dereq_('./docblock');
  11241. state.g.docblock =
  11242. docblock.parseAsObject(docblock.extract(state.g.source));
  11243. }
  11244. return state.g.docblock;
  11245. }
  11246. function identWithinLexicalScope(identName, state, stopBeforeNode) {
  11247. var currScope = state.localScope;
  11248. while (currScope) {
  11249. if (currScope.identifiers[identName] !== undefined) {
  11250. return true;
  11251. }
  11252. if (stopBeforeNode && currScope.parentNode === stopBeforeNode) {
  11253. break;
  11254. }
  11255. currScope = currScope.parentScope;
  11256. }
  11257. return false;
  11258. }
  11259. function identInLocalScope(identName, state) {
  11260. return state.localScope.identifiers[identName] !== undefined;
  11261. }
  11262. /**
  11263. * @param {object} boundaryNode
  11264. * @param {?array} path
  11265. * @return {?object} node
  11266. */
  11267. function initScopeMetadata(boundaryNode, path, node) {
  11268. return {
  11269. boundaryNode: boundaryNode,
  11270. bindingPath: path,
  11271. bindingNode: node
  11272. };
  11273. }
  11274. function declareIdentInLocalScope(identName, metaData, state) {
  11275. state.localScope.identifiers[identName] = {
  11276. boundaryNode: metaData.boundaryNode,
  11277. path: metaData.bindingPath,
  11278. node: metaData.bindingNode,
  11279. state: Object.create(state)
  11280. };
  11281. }
  11282. function getLexicalBindingMetadata(identName, state) {
  11283. var currScope = state.localScope;
  11284. while (currScope) {
  11285. if (currScope.identifiers[identName] !== undefined) {
  11286. return currScope.identifiers[identName];
  11287. }
  11288. currScope = currScope.parentScope;
  11289. }
  11290. }
  11291. function getLocalBindingMetadata(identName, state) {
  11292. return state.localScope.identifiers[identName];
  11293. }
  11294. /**
  11295. * Apply the given analyzer function to the current node. If the analyzer
  11296. * doesn't return false, traverse each child of the current node using the given
  11297. * traverser function.
  11298. *
  11299. * @param {function} analyzer
  11300. * @param {function} traverser
  11301. * @param {object} node
  11302. * @param {array} path
  11303. * @param {object} state
  11304. */
  11305. function analyzeAndTraverse(analyzer, traverser, node, path, state) {
  11306. if (node.type) {
  11307. if (analyzer(node, path, state) === false) {
  11308. return;
  11309. }
  11310. path.unshift(node);
  11311. }
  11312. getOrderedChildren(node).forEach(function(child) {
  11313. traverser(child, path, state);
  11314. });
  11315. node.type && path.shift();
  11316. }
  11317. /**
  11318. * It is crucial that we traverse in order, or else catchup() on a later
  11319. * node that is processed out of order can move the buffer past a node
  11320. * that we haven't handled yet, preventing us from modifying that node.
  11321. *
  11322. * This can happen when a node has multiple properties containing children.
  11323. * For example, XJSElement nodes have `openingElement`, `closingElement` and
  11324. * `children`. If we traverse `openingElement`, then `closingElement`, then
  11325. * when we get to `children`, the buffer has already caught up to the end of
  11326. * the closing element, after the children.
  11327. *
  11328. * This is basically a Schwartzian transform. Collects an array of children,
  11329. * each one represented as [child, startIndex]; sorts the array by start
  11330. * index; then traverses the children in that order.
  11331. */
  11332. function getOrderedChildren(node) {
  11333. var queue = [];
  11334. for (var key in node) {
  11335. if (node.hasOwnProperty(key)) {
  11336. enqueueNodeWithStartIndex(queue, node[key]);
  11337. }
  11338. }
  11339. queue.sort(function(a, b) { return a[1] - b[1]; });
  11340. return queue.map(function(pair) { return pair[0]; });
  11341. }
  11342. /**
  11343. * Helper function for analyzeAndTraverse which queues up all of the children
  11344. * of the given node.
  11345. *
  11346. * Children can also be found in arrays, so we basically want to merge all of
  11347. * those arrays together so we can sort them and then traverse the children
  11348. * in order.
  11349. *
  11350. * One example is the Program node. It contains `body` and `comments`, both
  11351. * arrays. Lexographically, comments are interspersed throughout the body
  11352. * nodes, but esprima's AST groups them together.
  11353. */
  11354. function enqueueNodeWithStartIndex(queue, node) {
  11355. if (typeof node !== 'object' || node === null) {
  11356. return;
  11357. }
  11358. if (node.range) {
  11359. queue.push([node, node.range[0]]);
  11360. } else if (Array.isArray(node)) {
  11361. for (var ii = 0; ii < node.length; ii++) {
  11362. enqueueNodeWithStartIndex(queue, node[ii]);
  11363. }
  11364. }
  11365. }
  11366. /**
  11367. * Checks whether a node or any of its sub-nodes contains
  11368. * a syntactic construct of the passed type.
  11369. * @param {object} node - AST node to test.
  11370. * @param {string} type - node type to lookup.
  11371. */
  11372. function containsChildOfType(node, type) {
  11373. return containsChildMatching(node, function(node) {
  11374. return node.type === type;
  11375. });
  11376. }
  11377. function containsChildMatching(node, matcher) {
  11378. var foundMatchingChild = false;
  11379. function nodeTypeAnalyzer(node) {
  11380. if (matcher(node) === true) {
  11381. foundMatchingChild = true;
  11382. return false;
  11383. }
  11384. }
  11385. function nodeTypeTraverser(child, path, state) {
  11386. if (!foundMatchingChild) {
  11387. foundMatchingChild = containsChildMatching(child, matcher);
  11388. }
  11389. }
  11390. analyzeAndTraverse(
  11391. nodeTypeAnalyzer,
  11392. nodeTypeTraverser,
  11393. node,
  11394. []
  11395. );
  11396. return foundMatchingChild;
  11397. }
  11398. var scopeTypes = {};
  11399. scopeTypes[Syntax.ArrowFunctionExpression] = true;
  11400. scopeTypes[Syntax.FunctionExpression] = true;
  11401. scopeTypes[Syntax.FunctionDeclaration] = true;
  11402. scopeTypes[Syntax.Program] = true;
  11403. function getBoundaryNode(path) {
  11404. for (var ii = 0; ii < path.length; ++ii) {
  11405. if (scopeTypes[path[ii].type]) {
  11406. return path[ii];
  11407. }
  11408. }
  11409. throw new Error(
  11410. 'Expected to find a node with one of the following types in path:\n' +
  11411. JSON.stringify(Object.keys(scopeTypes))
  11412. );
  11413. }
  11414. function getTempVar(tempVarIndex) {
  11415. return '$__' + tempVarIndex;
  11416. }
  11417. function injectTempVar(state) {
  11418. var tempVar = '$__' + (state.localScope.tempVarIndex++);
  11419. state.localScope.tempVars.push(tempVar);
  11420. return tempVar;
  11421. }
  11422. function injectTempVarDeclarations(state, index) {
  11423. if (state.localScope.tempVars.length) {
  11424. state.g.buffer =
  11425. state.g.buffer.slice(0, index) +
  11426. 'var ' + state.localScope.tempVars.join(', ') + ';' +
  11427. state.g.buffer.slice(index);
  11428. state.localScope.tempVars = [];
  11429. }
  11430. }
  11431. exports.analyzeAndTraverse = analyzeAndTraverse;
  11432. exports.append = append;
  11433. exports.catchup = catchup;
  11434. exports.catchupNewlines = catchupNewlines;
  11435. exports.catchupWhiteOut = catchupWhiteOut;
  11436. exports.catchupWhiteSpace = catchupWhiteSpace;
  11437. exports.containsChildMatching = containsChildMatching;
  11438. exports.containsChildOfType = containsChildOfType;
  11439. exports.createState = createState;
  11440. exports.declareIdentInLocalScope = declareIdentInLocalScope;
  11441. exports.getBoundaryNode = getBoundaryNode;
  11442. exports.getDocblock = getDocblock;
  11443. exports.getLexicalBindingMetadata = getLexicalBindingMetadata;
  11444. exports.getLocalBindingMetadata = getLocalBindingMetadata;
  11445. exports.getNextSyntacticCharOffset = getNextSyntacticCharOffset;
  11446. exports.getNodeSourceText = getNodeSourceText;
  11447. exports.getOrderedChildren = getOrderedChildren;
  11448. exports.getTempVar = getTempVar;
  11449. exports.identInLocalScope = identInLocalScope;
  11450. exports.identWithinLexicalScope = identWithinLexicalScope;
  11451. exports.indentBefore = indentBefore;
  11452. exports.initScopeMetadata = initScopeMetadata;
  11453. exports.injectTempVar = injectTempVar;
  11454. exports.injectTempVarDeclarations = injectTempVarDeclarations;
  11455. exports.move = move;
  11456. exports.scopeTypes = scopeTypes;
  11457. exports.updateIndent = updateIndent;
  11458. exports.updateState = updateState;
  11459. },{"./docblock":21,"esprima-fb":9}],24:[function(_dereq_,module,exports){
  11460. /**
  11461. * Copyright 2013 Facebook, Inc.
  11462. *
  11463. * Licensed under the Apache License, Version 2.0 (the "License");
  11464. * you may not use this file except in compliance with the License.
  11465. * You may obtain a copy of the License at
  11466. *
  11467. * http://www.apache.org/licenses/LICENSE-2.0
  11468. *
  11469. * Unless required by applicable law or agreed to in writing, software
  11470. * distributed under the License is distributed on an "AS IS" BASIS,
  11471. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11472. * See the License for the specific language governing permissions and
  11473. * limitations under the License.
  11474. */
  11475. /*global exports:true*/
  11476. /**
  11477. * Desugars ES6 Arrow functions to ES3 function expressions.
  11478. * If the function contains `this` expression -- automatically
  11479. * binds the function to current value of `this`.
  11480. *
  11481. * Single parameter, simple expression:
  11482. *
  11483. * [1, 2, 3].map(x => x * x);
  11484. *
  11485. * [1, 2, 3].map(function(x) { return x * x; });
  11486. *
  11487. * Several parameters, complex block:
  11488. *
  11489. * this.users.forEach((user, idx) => {
  11490. * return this.isActive(idx) && this.send(user);
  11491. * });
  11492. *
  11493. * this.users.forEach(function(user, idx) {
  11494. * return this.isActive(idx) && this.send(user);
  11495. * }.bind(this));
  11496. *
  11497. */
  11498. var restParamVisitors = _dereq_('./es6-rest-param-visitors');
  11499. var destructuringVisitors = _dereq_('./es6-destructuring-visitors');
  11500. var Syntax = _dereq_('esprima-fb').Syntax;
  11501. var utils = _dereq_('../src/utils');
  11502. /**
  11503. * @public
  11504. */
  11505. function visitArrowFunction(traverse, node, path, state) {
  11506. var notInExpression = (path[0].type === Syntax.ExpressionStatement);
  11507. // Wrap a function into a grouping operator, if it's not
  11508. // in the expression position.
  11509. if (notInExpression) {
  11510. utils.append('(', state);
  11511. }
  11512. utils.append('function', state);
  11513. renderParams(traverse, node, path, state);
  11514. // Skip arrow.
  11515. utils.catchupWhiteSpace(node.body.range[0], state);
  11516. var renderBody = node.body.type == Syntax.BlockStatement
  11517. ? renderStatementBody
  11518. : renderExpressionBody;
  11519. path.unshift(node);
  11520. renderBody(traverse, node, path, state);
  11521. path.shift();
  11522. // Bind the function only if `this` value is used
  11523. // inside it or inside any sub-expression.
  11524. var containsBindingSyntax =
  11525. utils.containsChildMatching(node.body, function(node) {
  11526. return node.type === Syntax.ThisExpression
  11527. || (node.type === Syntax.Identifier
  11528. && node.name === "super");
  11529. });
  11530. if (containsBindingSyntax) {
  11531. utils.append('.bind(this)', state);
  11532. }
  11533. utils.catchupWhiteSpace(node.range[1], state);
  11534. // Close wrapper if not in the expression.
  11535. if (notInExpression) {
  11536. utils.append(')', state);
  11537. }
  11538. return false;
  11539. }
  11540. function renderParams(traverse, node, path, state) {
  11541. // To preserve inline typechecking directives, we
  11542. // distinguish between parens-free and paranthesized single param.
  11543. if (isParensFreeSingleParam(node, state) || !node.params.length) {
  11544. utils.append('(', state);
  11545. }
  11546. if (node.params.length !== 0) {
  11547. path.unshift(node);
  11548. traverse(node.params, path, state);
  11549. path.unshift();
  11550. }
  11551. utils.append(')', state);
  11552. }
  11553. function isParensFreeSingleParam(node, state) {
  11554. return node.params.length === 1 &&
  11555. state.g.source[state.g.position] !== '(';
  11556. }
  11557. function renderExpressionBody(traverse, node, path, state) {
  11558. // Wrap simple expression bodies into a block
  11559. // with explicit return statement.
  11560. utils.append('{', state);
  11561. // Special handling of rest param.
  11562. if (node.rest) {
  11563. utils.append(
  11564. restParamVisitors.renderRestParamSetup(node, state),
  11565. state
  11566. );
  11567. }
  11568. // Special handling of destructured params.
  11569. destructuringVisitors.renderDestructuredComponents(
  11570. node,
  11571. utils.updateState(state, {
  11572. localScope: {
  11573. parentNode: state.parentNode,
  11574. parentScope: state.parentScope,
  11575. identifiers: state.identifiers,
  11576. tempVarIndex: 0
  11577. }
  11578. })
  11579. );
  11580. utils.append('return ', state);
  11581. renderStatementBody(traverse, node, path, state);
  11582. utils.append(';}', state);
  11583. }
  11584. function renderStatementBody(traverse, node, path, state) {
  11585. traverse(node.body, path, state);
  11586. utils.catchup(node.body.range[1], state);
  11587. }
  11588. visitArrowFunction.test = function(node, path, state) {
  11589. return node.type === Syntax.ArrowFunctionExpression;
  11590. };
  11591. exports.visitorList = [
  11592. visitArrowFunction
  11593. ];
  11594. },{"../src/utils":23,"./es6-destructuring-visitors":27,"./es6-rest-param-visitors":30,"esprima-fb":9}],25:[function(_dereq_,module,exports){
  11595. /**
  11596. * Copyright 2004-present Facebook. All Rights Reserved.
  11597. */
  11598. /*global exports:true*/
  11599. /**
  11600. * Implements ES6 call spread.
  11601. *
  11602. * instance.method(a, b, c, ...d)
  11603. *
  11604. * instance.method.apply(instance, [a, b, c].concat(d))
  11605. *
  11606. */
  11607. var Syntax = _dereq_('esprima-fb').Syntax;
  11608. var utils = _dereq_('../src/utils');
  11609. function process(traverse, node, path, state) {
  11610. utils.move(node.range[0], state);
  11611. traverse(node, path, state);
  11612. utils.catchup(node.range[1], state);
  11613. }
  11614. function visitCallSpread(traverse, node, path, state) {
  11615. utils.catchup(node.range[0], state);
  11616. if (node.type === Syntax.NewExpression) {
  11617. // Input = new Set(1, 2, ...list)
  11618. // Output = new (Function.prototype.bind.apply(Set, [null, 1, 2].concat(list)))
  11619. utils.append('new (Function.prototype.bind.apply(', state);
  11620. process(traverse, node.callee, path, state);
  11621. } else if (node.callee.type === Syntax.MemberExpression) {
  11622. // Input = get().fn(1, 2, ...more)
  11623. // Output = (_ = get()).fn.apply(_, [1, 2].apply(more))
  11624. var tempVar = utils.injectTempVar(state);
  11625. utils.append('(' + tempVar + ' = ', state);
  11626. process(traverse, node.callee.object, path, state);
  11627. utils.append(')', state);
  11628. if (node.callee.property.type === Syntax.Identifier) {
  11629. utils.append('.', state);
  11630. process(traverse, node.callee.property, path, state);
  11631. } else {
  11632. utils.append('[', state);
  11633. process(traverse, node.callee.property, path, state);
  11634. utils.append(']', state);
  11635. }
  11636. utils.append('.apply(' + tempVar, state);
  11637. } else {
  11638. // Input = max(1, 2, ...list)
  11639. // Output = max.apply(null, [1, 2].concat(list))
  11640. var needsToBeWrappedInParenthesis =
  11641. node.callee.type === Syntax.FunctionDeclaration ||
  11642. node.callee.type === Syntax.FunctionExpression;
  11643. if (needsToBeWrappedInParenthesis) {
  11644. utils.append('(', state);
  11645. }
  11646. process(traverse, node.callee, path, state);
  11647. if (needsToBeWrappedInParenthesis) {
  11648. utils.append(')', state);
  11649. }
  11650. utils.append('.apply(null', state);
  11651. }
  11652. utils.append(', ', state);
  11653. var args = node.arguments.slice();
  11654. var spread = args.pop();
  11655. if (args.length || node.type === Syntax.NewExpression) {
  11656. utils.append('[', state);
  11657. if (node.type === Syntax.NewExpression) {
  11658. utils.append('null' + (args.length ? ', ' : ''), state);
  11659. }
  11660. while (args.length) {
  11661. var arg = args.shift();
  11662. utils.move(arg.range[0], state);
  11663. traverse(arg, path, state);
  11664. if (args.length) {
  11665. utils.catchup(args[0].range[0], state);
  11666. } else {
  11667. utils.catchup(arg.range[1], state);
  11668. }
  11669. }
  11670. utils.append('].concat(', state);
  11671. process(traverse, spread.argument, path, state);
  11672. utils.append(')', state);
  11673. } else {
  11674. process(traverse, spread.argument, path, state);
  11675. }
  11676. utils.append(node.type === Syntax.NewExpression ? '))' : ')', state);
  11677. utils.move(node.range[1], state);
  11678. return false;
  11679. }
  11680. visitCallSpread.test = function(node, path, state) {
  11681. return (
  11682. (
  11683. node.type === Syntax.CallExpression ||
  11684. node.type === Syntax.NewExpression
  11685. ) &&
  11686. node.arguments.length > 0 &&
  11687. node.arguments[node.arguments.length - 1].type === Syntax.SpreadElement
  11688. );
  11689. };
  11690. exports.visitorList = [
  11691. visitCallSpread
  11692. ];
  11693. },{"../src/utils":23,"esprima-fb":9}],26:[function(_dereq_,module,exports){
  11694. /**
  11695. * Copyright 2013 Facebook, Inc.
  11696. *
  11697. * Licensed under the Apache License, Version 2.0 (the "License");
  11698. * you may not use this file except in compliance with the License.
  11699. * You may obtain a copy of the License at
  11700. *
  11701. * http://www.apache.org/licenses/LICENSE-2.0
  11702. *
  11703. * Unless required by applicable law or agreed to in writing, software
  11704. * distributed under the License is distributed on an "AS IS" BASIS,
  11705. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11706. * See the License for the specific language governing permissions and
  11707. * limitations under the License.
  11708. */
  11709. /*jslint node:true*/
  11710. /**
  11711. * @typechecks
  11712. */
  11713. 'use strict';
  11714. var base62 = _dereq_('base62');
  11715. var Syntax = _dereq_('esprima-fb').Syntax;
  11716. var utils = _dereq_('../src/utils');
  11717. var reservedWordsHelper = _dereq_('./reserved-words-helper');
  11718. var declareIdentInLocalScope = utils.declareIdentInLocalScope;
  11719. var initScopeMetadata = utils.initScopeMetadata;
  11720. var SUPER_PROTO_IDENT_PREFIX = '____SuperProtoOf';
  11721. var _anonClassUUIDCounter = 0;
  11722. var _mungedSymbolMaps = {};
  11723. function resetSymbols() {
  11724. _anonClassUUIDCounter = 0;
  11725. _mungedSymbolMaps = {};
  11726. }
  11727. /**
  11728. * Used to generate a unique class for use with code-gens for anonymous class
  11729. * expressions.
  11730. *
  11731. * @param {object} state
  11732. * @return {string}
  11733. */
  11734. function _generateAnonymousClassName(state) {
  11735. var mungeNamespace = state.mungeNamespace || '';
  11736. return '____Class' + mungeNamespace + base62.encode(_anonClassUUIDCounter++);
  11737. }
  11738. /**
  11739. * Given an identifier name, munge it using the current state's mungeNamespace.
  11740. *
  11741. * @param {string} identName
  11742. * @param {object} state
  11743. * @return {string}
  11744. */
  11745. function _getMungedName(identName, state) {
  11746. var mungeNamespace = state.mungeNamespace;
  11747. var shouldMinify = state.g.opts.minify;
  11748. if (shouldMinify) {
  11749. if (!_mungedSymbolMaps[mungeNamespace]) {
  11750. _mungedSymbolMaps[mungeNamespace] = {
  11751. symbolMap: {},
  11752. identUUIDCounter: 0
  11753. };
  11754. }
  11755. var symbolMap = _mungedSymbolMaps[mungeNamespace].symbolMap;
  11756. if (!symbolMap[identName]) {
  11757. symbolMap[identName] =
  11758. base62.encode(_mungedSymbolMaps[mungeNamespace].identUUIDCounter++);
  11759. }
  11760. identName = symbolMap[identName];
  11761. }
  11762. return '$' + mungeNamespace + identName;
  11763. }
  11764. /**
  11765. * Extracts super class information from a class node.
  11766. *
  11767. * Information includes name of the super class and/or the expression string
  11768. * (if extending from an expression)
  11769. *
  11770. * @param {object} node
  11771. * @param {object} state
  11772. * @return {object}
  11773. */
  11774. function _getSuperClassInfo(node, state) {
  11775. var ret = {
  11776. name: null,
  11777. expression: null
  11778. };
  11779. if (node.superClass) {
  11780. if (node.superClass.type === Syntax.Identifier) {
  11781. ret.name = node.superClass.name;
  11782. } else {
  11783. // Extension from an expression
  11784. ret.name = _generateAnonymousClassName(state);
  11785. ret.expression = state.g.source.substring(
  11786. node.superClass.range[0],
  11787. node.superClass.range[1]
  11788. );
  11789. }
  11790. }
  11791. return ret;
  11792. }
  11793. /**
  11794. * Used with .filter() to find the constructor method in a list of
  11795. * MethodDefinition nodes.
  11796. *
  11797. * @param {object} classElement
  11798. * @return {boolean}
  11799. */
  11800. function _isConstructorMethod(classElement) {
  11801. return classElement.type === Syntax.MethodDefinition &&
  11802. classElement.key.type === Syntax.Identifier &&
  11803. classElement.key.name === 'constructor';
  11804. }
  11805. /**
  11806. * @param {object} node
  11807. * @param {object} state
  11808. * @return {boolean}
  11809. */
  11810. function _shouldMungeIdentifier(node, state) {
  11811. return (
  11812. !!state.methodFuncNode &&
  11813. !utils.getDocblock(state).hasOwnProperty('preventMunge') &&
  11814. /^_(?!_)/.test(node.name)
  11815. );
  11816. }
  11817. /**
  11818. * @param {function} traverse
  11819. * @param {object} node
  11820. * @param {array} path
  11821. * @param {object} state
  11822. */
  11823. function visitClassMethod(traverse, node, path, state) {
  11824. if (!state.g.opts.es5 && (node.kind === 'get' || node.kind === 'set')) {
  11825. throw new Error(
  11826. 'This transform does not support ' + node.kind + 'ter methods for ES6 ' +
  11827. 'classes. (line: ' + node.loc.start.line + ', col: ' +
  11828. node.loc.start.column + ')'
  11829. );
  11830. }
  11831. state = utils.updateState(state, {
  11832. methodNode: node
  11833. });
  11834. utils.catchup(node.range[0], state);
  11835. path.unshift(node);
  11836. traverse(node.value, path, state);
  11837. path.shift();
  11838. return false;
  11839. }
  11840. visitClassMethod.test = function(node, path, state) {
  11841. return node.type === Syntax.MethodDefinition;
  11842. };
  11843. /**
  11844. * @param {function} traverse
  11845. * @param {object} node
  11846. * @param {array} path
  11847. * @param {object} state
  11848. */
  11849. function visitClassFunctionExpression(traverse, node, path, state) {
  11850. var methodNode = path[0];
  11851. var isGetter = methodNode.kind === 'get';
  11852. var isSetter = methodNode.kind === 'set';
  11853. state = utils.updateState(state, {
  11854. methodFuncNode: node
  11855. });
  11856. if (methodNode.key.name === 'constructor') {
  11857. utils.append('function ' + state.className, state);
  11858. } else {
  11859. var methodAccessorComputed = false;
  11860. var methodAccessor;
  11861. var prototypeOrStatic = methodNode["static"] ? '' : '.prototype';
  11862. var objectAccessor = state.className + prototypeOrStatic;
  11863. if (methodNode.key.type === Syntax.Identifier) {
  11864. // foo() {}
  11865. methodAccessor = methodNode.key.name;
  11866. if (_shouldMungeIdentifier(methodNode.key, state)) {
  11867. methodAccessor = _getMungedName(methodAccessor, state);
  11868. }
  11869. if (isGetter || isSetter) {
  11870. methodAccessor = JSON.stringify(methodAccessor);
  11871. } else if (reservedWordsHelper.isReservedWord(methodAccessor)) {
  11872. methodAccessorComputed = true;
  11873. methodAccessor = JSON.stringify(methodAccessor);
  11874. }
  11875. } else if (methodNode.key.type === Syntax.Literal) {
  11876. // 'foo bar'() {} | get 'foo bar'() {} | set 'foo bar'() {}
  11877. methodAccessor = JSON.stringify(methodNode.key.value);
  11878. methodAccessorComputed = true;
  11879. }
  11880. if (isSetter || isGetter) {
  11881. utils.append(
  11882. 'Object.defineProperty(' +
  11883. objectAccessor + ',' +
  11884. methodAccessor + ',' +
  11885. '{configurable:true,' +
  11886. methodNode.kind + ':function',
  11887. state
  11888. );
  11889. } else {
  11890. if (state.g.opts.es3) {
  11891. if (methodAccessorComputed) {
  11892. methodAccessor = '[' + methodAccessor + ']';
  11893. } else {
  11894. methodAccessor = '.' + methodAccessor;
  11895. }
  11896. utils.append(
  11897. objectAccessor +
  11898. methodAccessor + '=function' + (node.generator ? '*' : ''),
  11899. state
  11900. );
  11901. } else {
  11902. if (!methodAccessorComputed) {
  11903. methodAccessor = JSON.stringify(methodAccessor);
  11904. }
  11905. utils.append(
  11906. 'Object.defineProperty(' +
  11907. objectAccessor + ',' +
  11908. methodAccessor + ',' +
  11909. '{writable:true,configurable:true,' +
  11910. 'value:function' + (node.generator ? '*' : ''),
  11911. state
  11912. );
  11913. }
  11914. }
  11915. }
  11916. utils.move(methodNode.key.range[1], state);
  11917. utils.append('(', state);
  11918. var params = node.params;
  11919. if (params.length > 0) {
  11920. utils.catchupNewlines(params[0].range[0], state);
  11921. for (var i = 0; i < params.length; i++) {
  11922. utils.catchup(node.params[i].range[0], state);
  11923. path.unshift(node);
  11924. traverse(params[i], path, state);
  11925. path.shift();
  11926. }
  11927. }
  11928. var closingParenPosition = utils.getNextSyntacticCharOffset(')', state);
  11929. utils.catchupWhiteSpace(closingParenPosition, state);
  11930. var openingBracketPosition = utils.getNextSyntacticCharOffset('{', state);
  11931. utils.catchup(openingBracketPosition + 1, state);
  11932. if (!state.scopeIsStrict) {
  11933. utils.append('"use strict";', state);
  11934. state = utils.updateState(state, {
  11935. scopeIsStrict: true
  11936. });
  11937. }
  11938. utils.move(node.body.range[0] + '{'.length, state);
  11939. path.unshift(node);
  11940. traverse(node.body, path, state);
  11941. path.shift();
  11942. utils.catchup(node.body.range[1], state);
  11943. if (methodNode.key.name !== 'constructor') {
  11944. if (isGetter || isSetter || !state.g.opts.es3) {
  11945. utils.append('})', state);
  11946. }
  11947. utils.append(';', state);
  11948. }
  11949. return false;
  11950. }
  11951. visitClassFunctionExpression.test = function(node, path, state) {
  11952. return node.type === Syntax.FunctionExpression
  11953. && path[0].type === Syntax.MethodDefinition;
  11954. };
  11955. function visitClassMethodParam(traverse, node, path, state) {
  11956. var paramName = node.name;
  11957. if (_shouldMungeIdentifier(node, state)) {
  11958. paramName = _getMungedName(node.name, state);
  11959. }
  11960. utils.append(paramName, state);
  11961. utils.move(node.range[1], state);
  11962. }
  11963. visitClassMethodParam.test = function(node, path, state) {
  11964. if (!path[0] || !path[1]) {
  11965. return;
  11966. }
  11967. var parentFuncExpr = path[0];
  11968. var parentClassMethod = path[1];
  11969. return parentFuncExpr.type === Syntax.FunctionExpression
  11970. && parentClassMethod.type === Syntax.MethodDefinition
  11971. && node.type === Syntax.Identifier;
  11972. };
  11973. /**
  11974. * @param {function} traverse
  11975. * @param {object} node
  11976. * @param {array} path
  11977. * @param {object} state
  11978. */
  11979. function _renderClassBody(traverse, node, path, state) {
  11980. var className = state.className;
  11981. var superClass = state.superClass;
  11982. // Set up prototype of constructor on same line as `extends` for line-number
  11983. // preservation. This relies on function-hoisting if a constructor function is
  11984. // defined in the class body.
  11985. if (superClass.name) {
  11986. // If the super class is an expression, we need to memoize the output of the
  11987. // expression into the generated class name variable and use that to refer
  11988. // to the super class going forward. Example:
  11989. //
  11990. // class Foo extends mixin(Bar, Baz) {}
  11991. // --transforms to--
  11992. // function Foo() {} var ____Class0Blah = mixin(Bar, Baz);
  11993. if (superClass.expression !== null) {
  11994. utils.append(
  11995. 'var ' + superClass.name + '=' + superClass.expression + ';',
  11996. state
  11997. );
  11998. }
  11999. var keyName = superClass.name + '____Key';
  12000. var keyNameDeclarator = '';
  12001. if (!utils.identWithinLexicalScope(keyName, state)) {
  12002. keyNameDeclarator = 'var ';
  12003. declareIdentInLocalScope(keyName, initScopeMetadata(node), state);
  12004. }
  12005. utils.append(
  12006. 'for(' + keyNameDeclarator + keyName + ' in ' + superClass.name + '){' +
  12007. 'if(' + superClass.name + '.hasOwnProperty(' + keyName + ')){' +
  12008. className + '[' + keyName + ']=' +
  12009. superClass.name + '[' + keyName + '];' +
  12010. '}' +
  12011. '}',
  12012. state
  12013. );
  12014. var superProtoIdentStr = SUPER_PROTO_IDENT_PREFIX + superClass.name;
  12015. if (!utils.identWithinLexicalScope(superProtoIdentStr, state)) {
  12016. utils.append(
  12017. 'var ' + superProtoIdentStr + '=' + superClass.name + '===null?' +
  12018. 'null:' + superClass.name + '.prototype;',
  12019. state
  12020. );
  12021. declareIdentInLocalScope(superProtoIdentStr, initScopeMetadata(node), state);
  12022. }
  12023. utils.append(
  12024. className + '.prototype=Object.create(' + superProtoIdentStr + ');',
  12025. state
  12026. );
  12027. utils.append(
  12028. className + '.prototype.constructor=' + className + ';',
  12029. state
  12030. );
  12031. utils.append(
  12032. className + '.__superConstructor__=' + superClass.name + ';',
  12033. state
  12034. );
  12035. }
  12036. // If there's no constructor method specified in the class body, create an
  12037. // empty constructor function at the top (same line as the class keyword)
  12038. if (!node.body.body.filter(_isConstructorMethod).pop()) {
  12039. utils.append('function ' + className + '(){', state);
  12040. if (!state.scopeIsStrict) {
  12041. utils.append('"use strict";', state);
  12042. }
  12043. if (superClass.name) {
  12044. utils.append(
  12045. 'if(' + superClass.name + '!==null){' +
  12046. superClass.name + '.apply(this,arguments);}',
  12047. state
  12048. );
  12049. }
  12050. utils.append('}', state);
  12051. }
  12052. utils.move(node.body.range[0] + '{'.length, state);
  12053. traverse(node.body, path, state);
  12054. utils.catchupWhiteSpace(node.range[1], state);
  12055. }
  12056. /**
  12057. * @param {function} traverse
  12058. * @param {object} node
  12059. * @param {array} path
  12060. * @param {object} state
  12061. */
  12062. function visitClassDeclaration(traverse, node, path, state) {
  12063. var className = node.id.name;
  12064. var superClass = _getSuperClassInfo(node, state);
  12065. state = utils.updateState(state, {
  12066. mungeNamespace: className,
  12067. className: className,
  12068. superClass: superClass
  12069. });
  12070. _renderClassBody(traverse, node, path, state);
  12071. return false;
  12072. }
  12073. visitClassDeclaration.test = function(node, path, state) {
  12074. return node.type === Syntax.ClassDeclaration;
  12075. };
  12076. /**
  12077. * @param {function} traverse
  12078. * @param {object} node
  12079. * @param {array} path
  12080. * @param {object} state
  12081. */
  12082. function visitClassExpression(traverse, node, path, state) {
  12083. var className = node.id && node.id.name || _generateAnonymousClassName(state);
  12084. var superClass = _getSuperClassInfo(node, state);
  12085. utils.append('(function(){', state);
  12086. state = utils.updateState(state, {
  12087. mungeNamespace: className,
  12088. className: className,
  12089. superClass: superClass
  12090. });
  12091. _renderClassBody(traverse, node, path, state);
  12092. utils.append('return ' + className + ';})()', state);
  12093. return false;
  12094. }
  12095. visitClassExpression.test = function(node, path, state) {
  12096. return node.type === Syntax.ClassExpression;
  12097. };
  12098. /**
  12099. * @param {function} traverse
  12100. * @param {object} node
  12101. * @param {array} path
  12102. * @param {object} state
  12103. */
  12104. function visitPrivateIdentifier(traverse, node, path, state) {
  12105. utils.append(_getMungedName(node.name, state), state);
  12106. utils.move(node.range[1], state);
  12107. }
  12108. visitPrivateIdentifier.test = function(node, path, state) {
  12109. if (node.type === Syntax.Identifier && _shouldMungeIdentifier(node, state)) {
  12110. // Always munge non-computed properties of MemberExpressions
  12111. // (a la preventing access of properties of unowned objects)
  12112. if (path[0].type === Syntax.MemberExpression && path[0].object !== node
  12113. && path[0].computed === false) {
  12114. return true;
  12115. }
  12116. // Always munge identifiers that were declared within the method function
  12117. // scope
  12118. if (utils.identWithinLexicalScope(node.name, state, state.methodFuncNode)) {
  12119. return true;
  12120. }
  12121. // Always munge private keys on object literals defined within a method's
  12122. // scope.
  12123. if (path[0].type === Syntax.Property
  12124. && path[1].type === Syntax.ObjectExpression) {
  12125. return true;
  12126. }
  12127. // Always munge function parameters
  12128. if (path[0].type === Syntax.FunctionExpression
  12129. || path[0].type === Syntax.FunctionDeclaration
  12130. || path[0].type === Syntax.ArrowFunctionExpression) {
  12131. for (var i = 0; i < path[0].params.length; i++) {
  12132. if (path[0].params[i] === node) {
  12133. return true;
  12134. }
  12135. }
  12136. }
  12137. }
  12138. return false;
  12139. };
  12140. /**
  12141. * @param {function} traverse
  12142. * @param {object} node
  12143. * @param {array} path
  12144. * @param {object} state
  12145. */
  12146. function visitSuperCallExpression(traverse, node, path, state) {
  12147. var superClassName = state.superClass.name;
  12148. if (node.callee.type === Syntax.Identifier) {
  12149. if (_isConstructorMethod(state.methodNode)) {
  12150. utils.append(superClassName + '.call(', state);
  12151. } else {
  12152. var protoProp = SUPER_PROTO_IDENT_PREFIX + superClassName;
  12153. if (state.methodNode.key.type === Syntax.Identifier) {
  12154. protoProp += '.' + state.methodNode.key.name;
  12155. } else if (state.methodNode.key.type === Syntax.Literal) {
  12156. protoProp += '[' + JSON.stringify(state.methodNode.key.value) + ']';
  12157. }
  12158. utils.append(protoProp + ".call(", state);
  12159. }
  12160. utils.move(node.callee.range[1], state);
  12161. } else if (node.callee.type === Syntax.MemberExpression) {
  12162. utils.append(SUPER_PROTO_IDENT_PREFIX + superClassName, state);
  12163. utils.move(node.callee.object.range[1], state);
  12164. if (node.callee.computed) {
  12165. // ["a" + "b"]
  12166. utils.catchup(node.callee.property.range[1] + ']'.length, state);
  12167. } else {
  12168. // .ab
  12169. utils.append('.' + node.callee.property.name, state);
  12170. }
  12171. utils.append('.call(', state);
  12172. utils.move(node.callee.range[1], state);
  12173. }
  12174. utils.append('this', state);
  12175. if (node.arguments.length > 0) {
  12176. utils.append(',', state);
  12177. utils.catchupWhiteSpace(node.arguments[0].range[0], state);
  12178. traverse(node.arguments, path, state);
  12179. }
  12180. utils.catchupWhiteSpace(node.range[1], state);
  12181. utils.append(')', state);
  12182. return false;
  12183. }
  12184. visitSuperCallExpression.test = function(node, path, state) {
  12185. if (state.superClass && node.type === Syntax.CallExpression) {
  12186. var callee = node.callee;
  12187. if (callee.type === Syntax.Identifier && callee.name === 'super'
  12188. || callee.type == Syntax.MemberExpression
  12189. && callee.object.name === 'super') {
  12190. return true;
  12191. }
  12192. }
  12193. return false;
  12194. };
  12195. /**
  12196. * @param {function} traverse
  12197. * @param {object} node
  12198. * @param {array} path
  12199. * @param {object} state
  12200. */
  12201. function visitSuperMemberExpression(traverse, node, path, state) {
  12202. var superClassName = state.superClass.name;
  12203. utils.append(SUPER_PROTO_IDENT_PREFIX + superClassName, state);
  12204. utils.move(node.object.range[1], state);
  12205. }
  12206. visitSuperMemberExpression.test = function(node, path, state) {
  12207. return state.superClass
  12208. && node.type === Syntax.MemberExpression
  12209. && node.object.type === Syntax.Identifier
  12210. && node.object.name === 'super';
  12211. };
  12212. exports.resetSymbols = resetSymbols;
  12213. exports.visitorList = [
  12214. visitClassDeclaration,
  12215. visitClassExpression,
  12216. visitClassFunctionExpression,
  12217. visitClassMethod,
  12218. visitClassMethodParam,
  12219. visitPrivateIdentifier,
  12220. visitSuperCallExpression,
  12221. visitSuperMemberExpression
  12222. ];
  12223. },{"../src/utils":23,"./reserved-words-helper":34,"base62":10,"esprima-fb":9}],27:[function(_dereq_,module,exports){
  12224. /**
  12225. * Copyright 2014 Facebook, Inc.
  12226. *
  12227. * Licensed under the Apache License, Version 2.0 (the "License");
  12228. * you may not use this file except in compliance with the License.
  12229. * You may obtain a copy of the License at
  12230. *
  12231. * http://www.apache.org/licenses/LICENSE-2.0
  12232. *
  12233. * Unless required by applicable law or agreed to in writing, software
  12234. * distributed under the License is distributed on an "AS IS" BASIS,
  12235. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12236. * See the License for the specific language governing permissions and
  12237. * limitations under the License.
  12238. */
  12239. /*global exports:true*/
  12240. /**
  12241. * Implements ES6 destructuring assignment and pattern matchng.
  12242. *
  12243. * function init({port, ip, coords: [x, y]}) {
  12244. * return (x && y) ? {id, port} : {ip};
  12245. * };
  12246. *
  12247. * function init($__0) {
  12248. * var
  12249. * port = $__0.port,
  12250. * ip = $__0.ip,
  12251. * $__1 = $__0.coords,
  12252. * x = $__1[0],
  12253. * y = $__1[1];
  12254. * return (x && y) ? {id, port} : {ip};
  12255. * }
  12256. *
  12257. * var x, {ip, port} = init({ip, port});
  12258. *
  12259. * var x, $__0 = init({ip, port}), ip = $__0.ip, port = $__0.port;
  12260. *
  12261. */
  12262. var Syntax = _dereq_('esprima-fb').Syntax;
  12263. var utils = _dereq_('../src/utils');
  12264. var reservedWordsHelper = _dereq_('./reserved-words-helper');
  12265. var restParamVisitors = _dereq_('./es6-rest-param-visitors');
  12266. var restPropertyHelpers = _dereq_('./es7-rest-property-helpers');
  12267. // -------------------------------------------------------
  12268. // 1. Structured variable declarations.
  12269. //
  12270. // var [a, b] = [b, a];
  12271. // var {x, y} = {y, x};
  12272. // -------------------------------------------------------
  12273. function visitStructuredVariable(traverse, node, path, state) {
  12274. // Allocate new temp for the pattern.
  12275. utils.append(utils.getTempVar(state.localScope.tempVarIndex) + '=', state);
  12276. // Skip the pattern and assign the init to the temp.
  12277. utils.catchupWhiteSpace(node.init.range[0], state);
  12278. traverse(node.init, path, state);
  12279. utils.catchup(node.init.range[1], state);
  12280. // Render the destructured data.
  12281. utils.append(',' + getDestructuredComponents(node.id, state), state);
  12282. state.localScope.tempVarIndex++;
  12283. return false;
  12284. }
  12285. visitStructuredVariable.test = function(node, path, state) {
  12286. return node.type === Syntax.VariableDeclarator &&
  12287. isStructuredPattern(node.id);
  12288. };
  12289. function isStructuredPattern(node) {
  12290. return node.type === Syntax.ObjectPattern ||
  12291. node.type === Syntax.ArrayPattern;
  12292. }
  12293. // Main function which does actual recursive destructuring
  12294. // of nested complex structures.
  12295. function getDestructuredComponents(node, state) {
  12296. var tmpIndex = state.localScope.tempVarIndex;
  12297. var components = [];
  12298. var patternItems = getPatternItems(node);
  12299. for (var idx = 0; idx < patternItems.length; idx++) {
  12300. var item = patternItems[idx];
  12301. if (!item) {
  12302. continue;
  12303. }
  12304. if (item.type === Syntax.SpreadElement) {
  12305. // Spread/rest of an array.
  12306. // TODO(dmitrys): support spread in the middle of a pattern
  12307. // and also for function param patterns: [x, ...xs, y]
  12308. components.push(item.argument.name +
  12309. '=Array.prototype.slice.call(' +
  12310. utils.getTempVar(tmpIndex) + ',' + idx + ')'
  12311. );
  12312. continue;
  12313. }
  12314. if (item.type === Syntax.SpreadProperty) {
  12315. var restExpression = restPropertyHelpers.renderRestExpression(
  12316. utils.getTempVar(tmpIndex),
  12317. patternItems
  12318. );
  12319. components.push(item.argument.name + '=' + restExpression);
  12320. continue;
  12321. }
  12322. // Depending on pattern type (Array or Object), we get
  12323. // corresponding pattern item parts.
  12324. var accessor = getPatternItemAccessor(node, item, tmpIndex, idx);
  12325. var value = getPatternItemValue(node, item);
  12326. // TODO(dmitrys): implement default values: {x, y=5}
  12327. if (value.type === Syntax.Identifier) {
  12328. // Simple pattern item.
  12329. components.push(value.name + '=' + accessor);
  12330. } else {
  12331. // Complex sub-structure.
  12332. components.push(
  12333. utils.getTempVar(++state.localScope.tempVarIndex) + '=' + accessor +
  12334. ',' + getDestructuredComponents(value, state)
  12335. );
  12336. }
  12337. }
  12338. return components.join(',');
  12339. }
  12340. function getPatternItems(node) {
  12341. return node.properties || node.elements;
  12342. }
  12343. function getPatternItemAccessor(node, patternItem, tmpIndex, idx) {
  12344. var tmpName = utils.getTempVar(tmpIndex);
  12345. if (node.type === Syntax.ObjectPattern) {
  12346. if (reservedWordsHelper.isReservedWord(patternItem.key.name)) {
  12347. return tmpName + '["' + patternItem.key.name + '"]';
  12348. } else if (patternItem.key.type === Syntax.Literal) {
  12349. return tmpName + '[' + JSON.stringify(patternItem.key.value) + ']';
  12350. } else if (patternItem.key.type === Syntax.Identifier) {
  12351. return tmpName + '.' + patternItem.key.name;
  12352. }
  12353. } else if (node.type === Syntax.ArrayPattern) {
  12354. return tmpName + '[' + idx + ']';
  12355. }
  12356. }
  12357. function getPatternItemValue(node, patternItem) {
  12358. return node.type === Syntax.ObjectPattern
  12359. ? patternItem.value
  12360. : patternItem;
  12361. }
  12362. // -------------------------------------------------------
  12363. // 2. Assignment expression.
  12364. //
  12365. // [a, b] = [b, a];
  12366. // ({x, y} = {y, x});
  12367. // -------------------------------------------------------
  12368. function visitStructuredAssignment(traverse, node, path, state) {
  12369. var exprNode = node.expression;
  12370. utils.append('var ' + utils.getTempVar(state.localScope.tempVarIndex) + '=', state);
  12371. utils.catchupWhiteSpace(exprNode.right.range[0], state);
  12372. traverse(exprNode.right, path, state);
  12373. utils.catchup(exprNode.right.range[1], state);
  12374. utils.append(
  12375. ';' + getDestructuredComponents(exprNode.left, state) + ';',
  12376. state
  12377. );
  12378. utils.catchupWhiteSpace(node.range[1], state);
  12379. state.localScope.tempVarIndex++;
  12380. return false;
  12381. }
  12382. visitStructuredAssignment.test = function(node, path, state) {
  12383. // We consider the expression statement rather than just assignment
  12384. // expression to cover case with object patters which should be
  12385. // wrapped in grouping operator: ({x, y} = {y, x});
  12386. return node.type === Syntax.ExpressionStatement &&
  12387. node.expression.type === Syntax.AssignmentExpression &&
  12388. isStructuredPattern(node.expression.left);
  12389. };
  12390. // -------------------------------------------------------
  12391. // 3. Structured parameter.
  12392. //
  12393. // function foo({x, y}) { ... }
  12394. // -------------------------------------------------------
  12395. function visitStructuredParameter(traverse, node, path, state) {
  12396. utils.append(utils.getTempVar(getParamIndex(node, path)), state);
  12397. utils.catchupWhiteSpace(node.range[1], state);
  12398. return true;
  12399. }
  12400. function getParamIndex(paramNode, path) {
  12401. var funcNode = path[0];
  12402. var tmpIndex = 0;
  12403. for (var k = 0; k < funcNode.params.length; k++) {
  12404. var param = funcNode.params[k];
  12405. if (param === paramNode) {
  12406. break;
  12407. }
  12408. if (isStructuredPattern(param)) {
  12409. tmpIndex++;
  12410. }
  12411. }
  12412. return tmpIndex;
  12413. }
  12414. visitStructuredParameter.test = function(node, path, state) {
  12415. return isStructuredPattern(node) && isFunctionNode(path[0]);
  12416. };
  12417. function isFunctionNode(node) {
  12418. return (node.type == Syntax.FunctionDeclaration ||
  12419. node.type == Syntax.FunctionExpression ||
  12420. node.type == Syntax.MethodDefinition ||
  12421. node.type == Syntax.ArrowFunctionExpression);
  12422. }
  12423. // -------------------------------------------------------
  12424. // 4. Function body for structured parameters.
  12425. //
  12426. // function foo({x, y}) { x; y; }
  12427. // -------------------------------------------------------
  12428. function visitFunctionBodyForStructuredParameter(traverse, node, path, state) {
  12429. var funcNode = path[0];
  12430. utils.catchup(funcNode.body.range[0] + 1, state);
  12431. renderDestructuredComponents(funcNode, state);
  12432. if (funcNode.rest) {
  12433. utils.append(
  12434. restParamVisitors.renderRestParamSetup(funcNode, state),
  12435. state
  12436. );
  12437. }
  12438. return true;
  12439. }
  12440. function renderDestructuredComponents(funcNode, state) {
  12441. var destructuredComponents = [];
  12442. for (var k = 0; k < funcNode.params.length; k++) {
  12443. var param = funcNode.params[k];
  12444. if (isStructuredPattern(param)) {
  12445. destructuredComponents.push(
  12446. getDestructuredComponents(param, state)
  12447. );
  12448. state.localScope.tempVarIndex++;
  12449. }
  12450. }
  12451. if (destructuredComponents.length) {
  12452. utils.append('var ' + destructuredComponents.join(',') + ';', state);
  12453. }
  12454. }
  12455. visitFunctionBodyForStructuredParameter.test = function(node, path, state) {
  12456. return node.type === Syntax.BlockStatement && isFunctionNode(path[0]);
  12457. };
  12458. exports.visitorList = [
  12459. visitStructuredVariable,
  12460. visitStructuredAssignment,
  12461. visitStructuredParameter,
  12462. visitFunctionBodyForStructuredParameter
  12463. ];
  12464. exports.renderDestructuredComponents = renderDestructuredComponents;
  12465. },{"../src/utils":23,"./es6-rest-param-visitors":30,"./es7-rest-property-helpers":32,"./reserved-words-helper":34,"esprima-fb":9}],28:[function(_dereq_,module,exports){
  12466. /**
  12467. * Copyright 2013 Facebook, Inc.
  12468. *
  12469. * Licensed under the Apache License, Version 2.0 (the "License");
  12470. * you may not use this file except in compliance with the License.
  12471. * You may obtain a copy of the License at
  12472. *
  12473. * http://www.apache.org/licenses/LICENSE-2.0
  12474. *
  12475. * Unless required by applicable law or agreed to in writing, software
  12476. * distributed under the License is distributed on an "AS IS" BASIS,
  12477. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12478. * See the License for the specific language governing permissions and
  12479. * limitations under the License.
  12480. */
  12481. /*jslint node:true*/
  12482. /**
  12483. * Desugars concise methods of objects to function expressions.
  12484. *
  12485. * var foo = {
  12486. * method(x, y) { ... }
  12487. * };
  12488. *
  12489. * var foo = {
  12490. * method: function(x, y) { ... }
  12491. * };
  12492. *
  12493. */
  12494. var Syntax = _dereq_('esprima-fb').Syntax;
  12495. var utils = _dereq_('../src/utils');
  12496. var reservedWordsHelper = _dereq_('./reserved-words-helper');
  12497. function visitObjectConciseMethod(traverse, node, path, state) {
  12498. var isGenerator = node.value.generator;
  12499. if (isGenerator) {
  12500. utils.catchupWhiteSpace(node.range[0] + 1, state);
  12501. }
  12502. if (node.computed) { // [<expr>]() { ...}
  12503. utils.catchup(node.key.range[1] + 1, state);
  12504. } else if (reservedWordsHelper.isReservedWord(node.key.name)) {
  12505. utils.catchup(node.key.range[0], state);
  12506. utils.append('"', state);
  12507. utils.catchup(node.key.range[1], state);
  12508. utils.append('"', state);
  12509. }
  12510. utils.catchup(node.key.range[1], state);
  12511. utils.append(
  12512. ':function' + (isGenerator ? '*' : ''),
  12513. state
  12514. );
  12515. path.unshift(node);
  12516. traverse(node.value, path, state);
  12517. path.shift();
  12518. return false;
  12519. }
  12520. visitObjectConciseMethod.test = function(node, path, state) {
  12521. return node.type === Syntax.Property &&
  12522. node.value.type === Syntax.FunctionExpression &&
  12523. node.method === true;
  12524. };
  12525. exports.visitorList = [
  12526. visitObjectConciseMethod
  12527. ];
  12528. },{"../src/utils":23,"./reserved-words-helper":34,"esprima-fb":9}],29:[function(_dereq_,module,exports){
  12529. /**
  12530. * Copyright 2013 Facebook, Inc.
  12531. *
  12532. * Licensed under the Apache License, Version 2.0 (the "License");
  12533. * you may not use this file except in compliance with the License.
  12534. * You may obtain a copy of the License at
  12535. *
  12536. * http://www.apache.org/licenses/LICENSE-2.0
  12537. *
  12538. * Unless required by applicable law or agreed to in writing, software
  12539. * distributed under the License is distributed on an "AS IS" BASIS,
  12540. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12541. * See the License for the specific language governing permissions and
  12542. * limitations under the License.
  12543. */
  12544. /*jslint node: true*/
  12545. /**
  12546. * Desugars ES6 Object Literal short notations into ES3 full notation.
  12547. *
  12548. * // Easier return values.
  12549. * function foo(x, y) {
  12550. * return {x, y}; // {x: x, y: y}
  12551. * };
  12552. *
  12553. * // Destructuring.
  12554. * function init({port, ip, coords: {x, y}}) { ... }
  12555. *
  12556. */
  12557. var Syntax = _dereq_('esprima-fb').Syntax;
  12558. var utils = _dereq_('../src/utils');
  12559. /**
  12560. * @public
  12561. */
  12562. function visitObjectLiteralShortNotation(traverse, node, path, state) {
  12563. utils.catchup(node.key.range[1], state);
  12564. utils.append(':' + node.key.name, state);
  12565. return false;
  12566. }
  12567. visitObjectLiteralShortNotation.test = function(node, path, state) {
  12568. return node.type === Syntax.Property &&
  12569. node.kind === 'init' &&
  12570. node.shorthand === true &&
  12571. path[0].type !== Syntax.ObjectPattern;
  12572. };
  12573. exports.visitorList = [
  12574. visitObjectLiteralShortNotation
  12575. ];
  12576. },{"../src/utils":23,"esprima-fb":9}],30:[function(_dereq_,module,exports){
  12577. /**
  12578. * Copyright 2013 Facebook, Inc.
  12579. *
  12580. * Licensed under the Apache License, Version 2.0 (the "License");
  12581. * you may not use this file except in compliance with the License.
  12582. * You may obtain a copy of the License at
  12583. *
  12584. * http://www.apache.org/licenses/LICENSE-2.0
  12585. *
  12586. * Unless required by applicable law or agreed to in writing, software
  12587. * distributed under the License is distributed on an "AS IS" BASIS,
  12588. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12589. * See the License for the specific language governing permissions and
  12590. * limitations under the License.
  12591. */
  12592. /*jslint node:true*/
  12593. /**
  12594. * Desugars ES6 rest parameters into an ES3 arguments array.
  12595. *
  12596. * function printf(template, ...args) {
  12597. * args.forEach(...);
  12598. * }
  12599. *
  12600. * We could use `Array.prototype.slice.call`, but that usage of arguments causes
  12601. * functions to be deoptimized in V8, so instead we use a for-loop.
  12602. *
  12603. * function printf(template) {
  12604. * for (var args = [], $__0 = 1, $__1 = arguments.length; $__0 < $__1; $__0++)
  12605. * args.push(arguments[$__0]);
  12606. * args.forEach(...);
  12607. * }
  12608. *
  12609. */
  12610. var Syntax = _dereq_('esprima-fb').Syntax;
  12611. var utils = _dereq_('../src/utils');
  12612. function _nodeIsFunctionWithRestParam(node) {
  12613. return (node.type === Syntax.FunctionDeclaration
  12614. || node.type === Syntax.FunctionExpression
  12615. || node.type === Syntax.ArrowFunctionExpression)
  12616. && node.rest;
  12617. }
  12618. function visitFunctionParamsWithRestParam(traverse, node, path, state) {
  12619. if (node.parametricType) {
  12620. utils.catchup(node.parametricType.range[0], state);
  12621. path.unshift(node);
  12622. traverse(node.parametricType, path, state);
  12623. path.shift();
  12624. }
  12625. // Render params.
  12626. if (node.params.length) {
  12627. path.unshift(node);
  12628. traverse(node.params, path, state);
  12629. path.shift();
  12630. } else {
  12631. // -3 is for ... of the rest.
  12632. utils.catchup(node.rest.range[0] - 3, state);
  12633. }
  12634. utils.catchupWhiteSpace(node.rest.range[1], state);
  12635. path.unshift(node);
  12636. traverse(node.body, path, state);
  12637. path.shift();
  12638. return false;
  12639. }
  12640. visitFunctionParamsWithRestParam.test = function(node, path, state) {
  12641. return _nodeIsFunctionWithRestParam(node);
  12642. };
  12643. function renderRestParamSetup(functionNode, state) {
  12644. var idx = state.localScope.tempVarIndex++;
  12645. var len = state.localScope.tempVarIndex++;
  12646. return 'for (var ' + functionNode.rest.name + '=[],' +
  12647. utils.getTempVar(idx) + '=' + functionNode.params.length + ',' +
  12648. utils.getTempVar(len) + '=arguments.length;' +
  12649. utils.getTempVar(idx) + '<' + utils.getTempVar(len) + ';' +
  12650. utils.getTempVar(idx) + '++) ' +
  12651. functionNode.rest.name + '.push(arguments[' + utils.getTempVar(idx) + ']);';
  12652. }
  12653. function visitFunctionBodyWithRestParam(traverse, node, path, state) {
  12654. utils.catchup(node.range[0] + 1, state);
  12655. var parentNode = path[0];
  12656. utils.append(renderRestParamSetup(parentNode, state), state);
  12657. return true;
  12658. }
  12659. visitFunctionBodyWithRestParam.test = function(node, path, state) {
  12660. return node.type === Syntax.BlockStatement
  12661. && _nodeIsFunctionWithRestParam(path[0]);
  12662. };
  12663. exports.renderRestParamSetup = renderRestParamSetup;
  12664. exports.visitorList = [
  12665. visitFunctionParamsWithRestParam,
  12666. visitFunctionBodyWithRestParam
  12667. ];
  12668. },{"../src/utils":23,"esprima-fb":9}],31:[function(_dereq_,module,exports){
  12669. /**
  12670. * Copyright 2013 Facebook, Inc.
  12671. *
  12672. * Licensed under the Apache License, Version 2.0 (the "License");
  12673. * you may not use this file except in compliance with the License.
  12674. * You may obtain a copy of the License at
  12675. *
  12676. * http://www.apache.org/licenses/LICENSE-2.0
  12677. *
  12678. * Unless required by applicable law or agreed to in writing, software
  12679. * distributed under the License is distributed on an "AS IS" BASIS,
  12680. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12681. * See the License for the specific language governing permissions and
  12682. * limitations under the License.
  12683. */
  12684. /*jslint node:true*/
  12685. /**
  12686. * @typechecks
  12687. */
  12688. 'use strict';
  12689. var Syntax = _dereq_('esprima-fb').Syntax;
  12690. var utils = _dereq_('../src/utils');
  12691. /**
  12692. * http://people.mozilla.org/~jorendorff/es6-draft.html#sec-12.1.9
  12693. */
  12694. function visitTemplateLiteral(traverse, node, path, state) {
  12695. var templateElements = node.quasis;
  12696. utils.append('(', state);
  12697. for (var ii = 0; ii < templateElements.length; ii++) {
  12698. var templateElement = templateElements[ii];
  12699. if (templateElement.value.raw !== '') {
  12700. utils.append(getCookedValue(templateElement), state);
  12701. if (!templateElement.tail) {
  12702. // + between element and substitution
  12703. utils.append(' + ', state);
  12704. }
  12705. // maintain line numbers
  12706. utils.move(templateElement.range[0], state);
  12707. utils.catchupNewlines(templateElement.range[1], state);
  12708. } else { // templateElement.value.raw === ''
  12709. // Concatenat adjacent substitutions, e.g. `${x}${y}`. Empty templates
  12710. // appear before the first and after the last element - nothing to add in
  12711. // those cases.
  12712. if (ii > 0 && !templateElement.tail) {
  12713. // + between substitution and substitution
  12714. utils.append(' + ', state);
  12715. }
  12716. }
  12717. utils.move(templateElement.range[1], state);
  12718. if (!templateElement.tail) {
  12719. var substitution = node.expressions[ii];
  12720. if (substitution.type === Syntax.Identifier ||
  12721. substitution.type === Syntax.MemberExpression ||
  12722. substitution.type === Syntax.CallExpression) {
  12723. utils.catchup(substitution.range[1], state);
  12724. } else {
  12725. utils.append('(', state);
  12726. traverse(substitution, path, state);
  12727. utils.catchup(substitution.range[1], state);
  12728. utils.append(')', state);
  12729. }
  12730. // if next templateElement isn't empty...
  12731. if (templateElements[ii + 1].value.cooked !== '') {
  12732. utils.append(' + ', state);
  12733. }
  12734. }
  12735. }
  12736. utils.move(node.range[1], state);
  12737. utils.append(')', state);
  12738. return false;
  12739. }
  12740. visitTemplateLiteral.test = function(node, path, state) {
  12741. return node.type === Syntax.TemplateLiteral;
  12742. };
  12743. /**
  12744. * http://people.mozilla.org/~jorendorff/es6-draft.html#sec-12.2.6
  12745. */
  12746. function visitTaggedTemplateExpression(traverse, node, path, state) {
  12747. var template = node.quasi;
  12748. var numQuasis = template.quasis.length;
  12749. // print the tag
  12750. utils.move(node.tag.range[0], state);
  12751. traverse(node.tag, path, state);
  12752. utils.catchup(node.tag.range[1], state);
  12753. // print array of template elements
  12754. utils.append('(function() { var siteObj = [', state);
  12755. for (var ii = 0; ii < numQuasis; ii++) {
  12756. utils.append(getCookedValue(template.quasis[ii]), state);
  12757. if (ii !== numQuasis - 1) {
  12758. utils.append(', ', state);
  12759. }
  12760. }
  12761. utils.append(']; siteObj.raw = [', state);
  12762. for (ii = 0; ii < numQuasis; ii++) {
  12763. utils.append(getRawValue(template.quasis[ii]), state);
  12764. if (ii !== numQuasis - 1) {
  12765. utils.append(', ', state);
  12766. }
  12767. }
  12768. utils.append(
  12769. ']; Object.freeze(siteObj.raw); Object.freeze(siteObj); return siteObj; }()',
  12770. state
  12771. );
  12772. // print substitutions
  12773. if (numQuasis > 1) {
  12774. for (ii = 0; ii < template.expressions.length; ii++) {
  12775. var expression = template.expressions[ii];
  12776. utils.append(', ', state);
  12777. // maintain line numbers by calling catchupWhiteSpace over the whole
  12778. // previous TemplateElement
  12779. utils.move(template.quasis[ii].range[0], state);
  12780. utils.catchupNewlines(template.quasis[ii].range[1], state);
  12781. utils.move(expression.range[0], state);
  12782. traverse(expression, path, state);
  12783. utils.catchup(expression.range[1], state);
  12784. }
  12785. }
  12786. // print blank lines to push the closing ) down to account for the final
  12787. // TemplateElement.
  12788. utils.catchupNewlines(node.range[1], state);
  12789. utils.append(')', state);
  12790. return false;
  12791. }
  12792. visitTaggedTemplateExpression.test = function(node, path, state) {
  12793. return node.type === Syntax.TaggedTemplateExpression;
  12794. };
  12795. function getCookedValue(templateElement) {
  12796. return JSON.stringify(templateElement.value.cooked);
  12797. }
  12798. function getRawValue(templateElement) {
  12799. return JSON.stringify(templateElement.value.raw);
  12800. }
  12801. exports.visitorList = [
  12802. visitTemplateLiteral,
  12803. visitTaggedTemplateExpression
  12804. ];
  12805. },{"../src/utils":23,"esprima-fb":9}],32:[function(_dereq_,module,exports){
  12806. /**
  12807. * Copyright 2013 Facebook, Inc.
  12808. *
  12809. * Licensed under the Apache License, Version 2.0 (the "License");
  12810. * you may not use this file except in compliance with the License.
  12811. * You may obtain a copy of the License at
  12812. *
  12813. * http://www.apache.org/licenses/LICENSE-2.0
  12814. *
  12815. * Unless required by applicable law or agreed to in writing, software
  12816. * distributed under the License is distributed on an "AS IS" BASIS,
  12817. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12818. * See the License for the specific language governing permissions and
  12819. * limitations under the License.
  12820. */
  12821. /*jslint node:true*/
  12822. /**
  12823. * Desugars ES7 rest properties into ES5 object iteration.
  12824. */
  12825. var Syntax = _dereq_('esprima-fb').Syntax;
  12826. // TODO: This is a pretty massive helper, it should only be defined once, in the
  12827. // transform's runtime environment. We don't currently have a runtime though.
  12828. var restFunction =
  12829. '(function(source, exclusion) {' +
  12830. 'var rest = {};' +
  12831. 'var hasOwn = Object.prototype.hasOwnProperty;' +
  12832. 'if (source == null) {' +
  12833. 'throw new TypeError();' +
  12834. '}' +
  12835. 'for (var key in source) {' +
  12836. 'if (hasOwn.call(source, key) && !hasOwn.call(exclusion, key)) {' +
  12837. 'rest[key] = source[key];' +
  12838. '}' +
  12839. '}' +
  12840. 'return rest;' +
  12841. '})';
  12842. function getPropertyNames(properties) {
  12843. var names = [];
  12844. for (var i = 0; i < properties.length; i++) {
  12845. var property = properties[i];
  12846. if (property.type === Syntax.SpreadProperty) {
  12847. continue;
  12848. }
  12849. if (property.type === Syntax.Identifier) {
  12850. names.push(property.name);
  12851. } else {
  12852. names.push(property.key.name);
  12853. }
  12854. }
  12855. return names;
  12856. }
  12857. function getRestFunctionCall(source, exclusion) {
  12858. return restFunction + '(' + source + ',' + exclusion + ')';
  12859. }
  12860. function getSimpleShallowCopy(accessorExpression) {
  12861. // This could be faster with 'Object.assign({}, ' + accessorExpression + ')'
  12862. // but to unify code paths and avoid a ES6 dependency we use the same
  12863. // helper as for the exclusion case.
  12864. return getRestFunctionCall(accessorExpression, '{}');
  12865. }
  12866. function renderRestExpression(accessorExpression, excludedProperties) {
  12867. var excludedNames = getPropertyNames(excludedProperties);
  12868. if (!excludedNames.length) {
  12869. return getSimpleShallowCopy(accessorExpression);
  12870. }
  12871. return getRestFunctionCall(
  12872. accessorExpression,
  12873. '{' + excludedNames.join(':1,') + ':1}'
  12874. );
  12875. }
  12876. exports.renderRestExpression = renderRestExpression;
  12877. },{"esprima-fb":9}],33:[function(_dereq_,module,exports){
  12878. /**
  12879. * Copyright 2004-present Facebook. All Rights Reserved.
  12880. */
  12881. /*global exports:true*/
  12882. /**
  12883. * Implements ES7 object spread property.
  12884. * https://gist.github.com/sebmarkbage/aa849c7973cb4452c547
  12885. *
  12886. * { ...a, x: 1 }
  12887. *
  12888. * Object.assign({}, a, {x: 1 })
  12889. *
  12890. */
  12891. var Syntax = _dereq_('esprima-fb').Syntax;
  12892. var utils = _dereq_('../src/utils');
  12893. function visitObjectLiteralSpread(traverse, node, path, state) {
  12894. utils.catchup(node.range[0], state);
  12895. utils.append('Object.assign({', state);
  12896. // Skip the original {
  12897. utils.move(node.range[0] + 1, state);
  12898. var previousWasSpread = false;
  12899. for (var i = 0; i < node.properties.length; i++) {
  12900. var property = node.properties[i];
  12901. if (property.type === Syntax.SpreadProperty) {
  12902. // Close the previous object or initial object
  12903. if (!previousWasSpread) {
  12904. utils.append('}', state);
  12905. }
  12906. if (i === 0) {
  12907. // Normally there will be a comma when we catch up, but not before
  12908. // the first property.
  12909. utils.append(',', state);
  12910. }
  12911. utils.catchup(property.range[0], state);
  12912. // skip ...
  12913. utils.move(property.range[0] + 3, state);
  12914. traverse(property.argument, path, state);
  12915. utils.catchup(property.range[1], state);
  12916. previousWasSpread = true;
  12917. } else {
  12918. utils.catchup(property.range[0], state);
  12919. if (previousWasSpread) {
  12920. utils.append('{', state);
  12921. }
  12922. traverse(property, path, state);
  12923. utils.catchup(property.range[1], state);
  12924. previousWasSpread = false;
  12925. }
  12926. }
  12927. // Strip any non-whitespace between the last item and the end.
  12928. // We only catch up on whitespace so that we ignore any trailing commas which
  12929. // are stripped out for IE8 support. Unfortunately, this also strips out any
  12930. // trailing comments.
  12931. utils.catchupWhiteSpace(node.range[1] - 1, state);
  12932. // Skip the trailing }
  12933. utils.move(node.range[1], state);
  12934. if (!previousWasSpread) {
  12935. utils.append('}', state);
  12936. }
  12937. utils.append(')', state);
  12938. return false;
  12939. }
  12940. visitObjectLiteralSpread.test = function(node, path, state) {
  12941. if (node.type !== Syntax.ObjectExpression) {
  12942. return false;
  12943. }
  12944. // Tight loop optimization
  12945. var hasAtLeastOneSpreadProperty = false;
  12946. for (var i = 0; i < node.properties.length; i++) {
  12947. var property = node.properties[i];
  12948. if (property.type === Syntax.SpreadProperty) {
  12949. hasAtLeastOneSpreadProperty = true;
  12950. } else if (property.kind !== 'init') {
  12951. return false;
  12952. }
  12953. }
  12954. return hasAtLeastOneSpreadProperty;
  12955. };
  12956. exports.visitorList = [
  12957. visitObjectLiteralSpread
  12958. ];
  12959. },{"../src/utils":23,"esprima-fb":9}],34:[function(_dereq_,module,exports){
  12960. /**
  12961. * Copyright 2014 Facebook, Inc.
  12962. *
  12963. * Licensed under the Apache License, Version 2.0 (the "License");
  12964. * you may not use this file except in compliance with the License.
  12965. * You may obtain a copy of the License at
  12966. *
  12967. * http://www.apache.org/licenses/LICENSE-2.0
  12968. *
  12969. * Unless required by applicable law or agreed to in writing, software
  12970. * distributed under the License is distributed on an "AS IS" BASIS,
  12971. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12972. * See the License for the specific language governing permissions and
  12973. * limitations under the License.
  12974. */
  12975. var KEYWORDS = [
  12976. 'break', 'do', 'in', 'typeof', 'case', 'else', 'instanceof', 'var', 'catch',
  12977. 'export', 'new', 'void', 'class', 'extends', 'return', 'while', 'const',
  12978. 'finally', 'super', 'with', 'continue', 'for', 'switch', 'yield', 'debugger',
  12979. 'function', 'this', 'default', 'if', 'throw', 'delete', 'import', 'try'
  12980. ];
  12981. var FUTURE_RESERVED_WORDS = [
  12982. 'enum', 'await', 'implements', 'package', 'protected', 'static', 'interface',
  12983. 'private', 'public'
  12984. ];
  12985. var LITERALS = [
  12986. 'null',
  12987. 'true',
  12988. 'false'
  12989. ];
  12990. // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-reserved-words
  12991. var RESERVED_WORDS = [].concat(
  12992. KEYWORDS,
  12993. FUTURE_RESERVED_WORDS,
  12994. LITERALS
  12995. );
  12996. var reservedWordsMap = Object.create(null);
  12997. RESERVED_WORDS.forEach(function(k) {
  12998. reservedWordsMap[k] = true;
  12999. });
  13000. /**
  13001. * This list should not grow as new reserved words are introdued. This list is
  13002. * of words that need to be quoted because ES3-ish browsers do not allow their
  13003. * use as identifier names.
  13004. */
  13005. var ES3_FUTURE_RESERVED_WORDS = [
  13006. 'enum', 'implements', 'package', 'protected', 'static', 'interface',
  13007. 'private', 'public'
  13008. ];
  13009. var ES3_RESERVED_WORDS = [].concat(
  13010. KEYWORDS,
  13011. ES3_FUTURE_RESERVED_WORDS,
  13012. LITERALS
  13013. );
  13014. var es3ReservedWordsMap = Object.create(null);
  13015. ES3_RESERVED_WORDS.forEach(function(k) {
  13016. es3ReservedWordsMap[k] = true;
  13017. });
  13018. exports.isReservedWord = function(word) {
  13019. return !!reservedWordsMap[word];
  13020. };
  13021. exports.isES3ReservedWord = function(word) {
  13022. return !!es3ReservedWordsMap[word];
  13023. };
  13024. },{}],35:[function(_dereq_,module,exports){
  13025. /**
  13026. * Copyright 2014 Facebook, Inc.
  13027. *
  13028. * Licensed under the Apache License, Version 2.0 (the "License");
  13029. * you may not use this file except in compliance with the License.
  13030. * You may obtain a copy of the License at
  13031. *
  13032. * http://www.apache.org/licenses/LICENSE-2.0
  13033. *
  13034. * Unless required by applicable law or agreed to in writing, software
  13035. * distributed under the License is distributed on an "AS IS" BASIS,
  13036. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13037. * See the License for the specific language governing permissions and
  13038. * limitations under the License.
  13039. *
  13040. */
  13041. /*global exports:true*/
  13042. var Syntax = _dereq_('esprima-fb').Syntax;
  13043. var utils = _dereq_('../src/utils');
  13044. var reserverdWordsHelper = _dereq_('./reserved-words-helper');
  13045. /**
  13046. * Code adapted from https://github.com/spicyj/es3ify
  13047. * The MIT License (MIT)
  13048. * Copyright (c) 2014 Ben Alpert
  13049. */
  13050. function visitProperty(traverse, node, path, state) {
  13051. utils.catchup(node.key.range[0], state);
  13052. utils.append('"', state);
  13053. utils.catchup(node.key.range[1], state);
  13054. utils.append('"', state);
  13055. utils.catchup(node.value.range[0], state);
  13056. traverse(node.value, path, state);
  13057. return false;
  13058. }
  13059. visitProperty.test = function(node) {
  13060. return node.type === Syntax.Property &&
  13061. node.key.type === Syntax.Identifier &&
  13062. !node.method &&
  13063. !node.shorthand &&
  13064. !node.computed &&
  13065. reserverdWordsHelper.isES3ReservedWord(node.key.name);
  13066. };
  13067. function visitMemberExpression(traverse, node, path, state) {
  13068. traverse(node.object, path, state);
  13069. utils.catchup(node.property.range[0] - 1, state);
  13070. utils.append('[', state);
  13071. utils.catchupWhiteSpace(node.property.range[0], state);
  13072. utils.append('"', state);
  13073. utils.catchup(node.property.range[1], state);
  13074. utils.append('"]', state);
  13075. return false;
  13076. }
  13077. visitMemberExpression.test = function(node) {
  13078. return node.type === Syntax.MemberExpression &&
  13079. node.property.type === Syntax.Identifier &&
  13080. reserverdWordsHelper.isES3ReservedWord(node.property.name);
  13081. };
  13082. exports.visitorList = [
  13083. visitProperty,
  13084. visitMemberExpression
  13085. ];
  13086. },{"../src/utils":23,"./reserved-words-helper":34,"esprima-fb":9}],36:[function(_dereq_,module,exports){
  13087. var esprima = _dereq_('esprima-fb');
  13088. var utils = _dereq_('../src/utils');
  13089. var Syntax = esprima.Syntax;
  13090. function _isFunctionNode(node) {
  13091. return node.type === Syntax.FunctionDeclaration
  13092. || node.type === Syntax.FunctionExpression
  13093. || node.type === Syntax.ArrowFunctionExpression;
  13094. }
  13095. function visitClassProperty(traverse, node, path, state) {
  13096. utils.catchup(node.range[0], state);
  13097. utils.catchupWhiteOut(node.range[1], state);
  13098. return false;
  13099. }
  13100. visitClassProperty.test = function(node, path, state) {
  13101. return node.type === Syntax.ClassProperty;
  13102. };
  13103. function visitTypeAlias(traverse, node, path, state) {
  13104. utils.catchupWhiteOut(node.range[1], state);
  13105. return false;
  13106. }
  13107. visitTypeAlias.test = function(node, path, state) {
  13108. return node.type === Syntax.TypeAlias;
  13109. };
  13110. function visitTypeCast(traverse, node, path, state) {
  13111. path.unshift(node);
  13112. traverse(node.expression, path, state);
  13113. path.shift();
  13114. utils.catchup(node.typeAnnotation.range[0], state);
  13115. utils.catchupWhiteOut(node.typeAnnotation.range[1], state);
  13116. return false;
  13117. }
  13118. visitTypeCast.test = function(node, path, state) {
  13119. return node.type === Syntax.TypeCastExpression;
  13120. };
  13121. function visitInterfaceDeclaration(traverse, node, path, state) {
  13122. utils.catchupWhiteOut(node.range[1], state);
  13123. return false;
  13124. }
  13125. visitInterfaceDeclaration.test = function(node, path, state) {
  13126. return node.type === Syntax.InterfaceDeclaration;
  13127. };
  13128. function visitDeclare(traverse, node, path, state) {
  13129. utils.catchupWhiteOut(node.range[1], state);
  13130. return false;
  13131. }
  13132. visitDeclare.test = function(node, path, state) {
  13133. switch (node.type) {
  13134. case Syntax.DeclareVariable:
  13135. case Syntax.DeclareFunction:
  13136. case Syntax.DeclareClass:
  13137. case Syntax.DeclareModule:
  13138. return true;
  13139. }
  13140. return false;
  13141. };
  13142. function visitFunctionParametricAnnotation(traverse, node, path, state) {
  13143. utils.catchup(node.range[0], state);
  13144. utils.catchupWhiteOut(node.range[1], state);
  13145. return false;
  13146. }
  13147. visitFunctionParametricAnnotation.test = function(node, path, state) {
  13148. return node.type === Syntax.TypeParameterDeclaration
  13149. && path[0]
  13150. && _isFunctionNode(path[0])
  13151. && node === path[0].typeParameters;
  13152. };
  13153. function visitFunctionReturnAnnotation(traverse, node, path, state) {
  13154. utils.catchup(node.range[0], state);
  13155. utils.catchupWhiteOut(node.range[1], state);
  13156. return false;
  13157. }
  13158. visitFunctionReturnAnnotation.test = function(node, path, state) {
  13159. return path[0] && _isFunctionNode(path[0]) && node === path[0].returnType;
  13160. };
  13161. function visitOptionalFunctionParameterAnnotation(traverse, node, path, state) {
  13162. utils.catchup(node.range[0] + node.name.length, state);
  13163. utils.catchupWhiteOut(node.range[1], state);
  13164. return false;
  13165. }
  13166. visitOptionalFunctionParameterAnnotation.test = function(node, path, state) {
  13167. return node.type === Syntax.Identifier
  13168. && node.optional
  13169. && path[0]
  13170. && _isFunctionNode(path[0]);
  13171. };
  13172. function visitTypeAnnotatedIdentifier(traverse, node, path, state) {
  13173. utils.catchup(node.typeAnnotation.range[0], state);
  13174. utils.catchupWhiteOut(node.typeAnnotation.range[1], state);
  13175. return false;
  13176. }
  13177. visitTypeAnnotatedIdentifier.test = function(node, path, state) {
  13178. return node.type === Syntax.Identifier && node.typeAnnotation;
  13179. };
  13180. function visitTypeAnnotatedObjectOrArrayPattern(traverse, node, path, state) {
  13181. utils.catchup(node.typeAnnotation.range[0], state);
  13182. utils.catchupWhiteOut(node.typeAnnotation.range[1], state);
  13183. return false;
  13184. }
  13185. visitTypeAnnotatedObjectOrArrayPattern.test = function(node, path, state) {
  13186. var rightType = node.type === Syntax.ObjectPattern
  13187. || node.type === Syntax.ArrayPattern;
  13188. return rightType && node.typeAnnotation;
  13189. };
  13190. /**
  13191. * Methods cause trouble, since esprima parses them as a key/value pair, where
  13192. * the location of the value starts at the method body. For example
  13193. * { bar(x:number,...y:Array<number>):number {} }
  13194. * is parsed as
  13195. * { bar: function(x: number, ...y:Array<number>): number {} }
  13196. * except that the location of the FunctionExpression value is 40-something,
  13197. * which is the location of the function body. This means that by the time we
  13198. * visit the params, rest param, and return type organically, we've already
  13199. * catchup()'d passed them.
  13200. */
  13201. function visitMethod(traverse, node, path, state) {
  13202. path.unshift(node);
  13203. traverse(node.key, path, state);
  13204. path.unshift(node.value);
  13205. traverse(node.value.params, path, state);
  13206. node.value.rest && traverse(node.value.rest, path, state);
  13207. node.value.returnType && traverse(node.value.returnType, path, state);
  13208. traverse(node.value.body, path, state);
  13209. path.shift();
  13210. path.shift();
  13211. return false;
  13212. }
  13213. visitMethod.test = function(node, path, state) {
  13214. return (node.type === "Property" && (node.method || node.kind === "set" || node.kind === "get"))
  13215. || (node.type === "MethodDefinition");
  13216. };
  13217. function visitImportType(traverse, node, path, state) {
  13218. utils.catchupWhiteOut(node.range[1], state);
  13219. return false;
  13220. }
  13221. visitImportType.test = function(node, path, state) {
  13222. return node.type === 'ImportDeclaration'
  13223. && node.isType;
  13224. };
  13225. exports.visitorList = [
  13226. visitClassProperty,
  13227. visitDeclare,
  13228. visitImportType,
  13229. visitInterfaceDeclaration,
  13230. visitFunctionParametricAnnotation,
  13231. visitFunctionReturnAnnotation,
  13232. visitMethod,
  13233. visitOptionalFunctionParameterAnnotation,
  13234. visitTypeAlias,
  13235. visitTypeCast,
  13236. visitTypeAnnotatedIdentifier,
  13237. visitTypeAnnotatedObjectOrArrayPattern
  13238. ];
  13239. },{"../src/utils":23,"esprima-fb":9}],37:[function(_dereq_,module,exports){
  13240. /**
  13241. * Copyright 2013-2015, Facebook, Inc.
  13242. * All rights reserved.
  13243. *
  13244. * This source code is licensed under the BSD-style license found in the
  13245. * LICENSE file in the root directory of this source tree. An additional grant
  13246. * of patent rights can be found in the PATENTS file in the same directory.
  13247. */
  13248. /*global exports:true*/
  13249. 'use strict';
  13250. var Syntax = _dereq_('jstransform').Syntax;
  13251. var utils = _dereq_('jstransform/src/utils');
  13252. function renderJSXLiteral(object, isLast, state, start, end) {
  13253. var lines = object.value.split(/\r\n|\n|\r/);
  13254. if (start) {
  13255. utils.append(start, state);
  13256. }
  13257. var lastNonEmptyLine = 0;
  13258. lines.forEach(function(line, index) {
  13259. if (line.match(/[^ \t]/)) {
  13260. lastNonEmptyLine = index;
  13261. }
  13262. });
  13263. lines.forEach(function(line, index) {
  13264. var isFirstLine = index === 0;
  13265. var isLastLine = index === lines.length - 1;
  13266. var isLastNonEmptyLine = index === lastNonEmptyLine;
  13267. // replace rendered whitespace tabs with spaces
  13268. var trimmedLine = line.replace(/\t/g, ' ');
  13269. // trim whitespace touching a newline
  13270. if (!isFirstLine) {
  13271. trimmedLine = trimmedLine.replace(/^[ ]+/, '');
  13272. }
  13273. if (!isLastLine) {
  13274. trimmedLine = trimmedLine.replace(/[ ]+$/, '');
  13275. }
  13276. if (!isFirstLine) {
  13277. utils.append(line.match(/^[ \t]*/)[0], state);
  13278. }
  13279. if (trimmedLine || isLastNonEmptyLine) {
  13280. utils.append(
  13281. JSON.stringify(trimmedLine) +
  13282. (!isLastNonEmptyLine ? ' + \' \' +' : ''),
  13283. state);
  13284. if (isLastNonEmptyLine) {
  13285. if (end) {
  13286. utils.append(end, state);
  13287. }
  13288. if (!isLast) {
  13289. utils.append(', ', state);
  13290. }
  13291. }
  13292. // only restore tail whitespace if line had literals
  13293. if (trimmedLine && !isLastLine) {
  13294. utils.append(line.match(/[ \t]*$/)[0], state);
  13295. }
  13296. }
  13297. if (!isLastLine) {
  13298. utils.append('\n', state);
  13299. }
  13300. });
  13301. utils.move(object.range[1], state);
  13302. }
  13303. function renderJSXExpressionContainer(traverse, object, isLast, path, state) {
  13304. // Plus 1 to skip `{`.
  13305. utils.move(object.range[0] + 1, state);
  13306. utils.catchup(object.expression.range[0], state);
  13307. traverse(object.expression, path, state);
  13308. if (!isLast && object.expression.type !== Syntax.JSXEmptyExpression) {
  13309. // If we need to append a comma, make sure to do so after the expression.
  13310. utils.catchup(object.expression.range[1], state, trimLeft);
  13311. utils.append(', ', state);
  13312. }
  13313. // Minus 1 to skip `}`.
  13314. utils.catchup(object.range[1] - 1, state, trimLeft);
  13315. utils.move(object.range[1], state);
  13316. return false;
  13317. }
  13318. function quoteAttrName(attr) {
  13319. // Quote invalid JS identifiers.
  13320. if (!/^[a-z_$][a-z\d_$]*$/i.test(attr)) {
  13321. return '"' + attr + '"';
  13322. }
  13323. return attr;
  13324. }
  13325. function trimLeft(value) {
  13326. return value.replace(/^[ ]+/, '');
  13327. }
  13328. exports.renderJSXExpressionContainer = renderJSXExpressionContainer;
  13329. exports.renderJSXLiteral = renderJSXLiteral;
  13330. exports.quoteAttrName = quoteAttrName;
  13331. exports.trimLeft = trimLeft;
  13332. },{"jstransform":22,"jstransform/src/utils":23}],38:[function(_dereq_,module,exports){
  13333. /**
  13334. * Copyright 2013-2015, Facebook, Inc.
  13335. * All rights reserved.
  13336. *
  13337. * This source code is licensed under the BSD-style license found in the
  13338. * LICENSE file in the root directory of this source tree. An additional grant
  13339. * of patent rights can be found in the PATENTS file in the same directory.
  13340. */
  13341. /*global exports:true*/
  13342. 'use strict';
  13343. var Syntax = _dereq_('jstransform').Syntax;
  13344. var utils = _dereq_('jstransform/src/utils');
  13345. var renderJSXExpressionContainer =
  13346. _dereq_('./jsx').renderJSXExpressionContainer;
  13347. var renderJSXLiteral = _dereq_('./jsx').renderJSXLiteral;
  13348. var quoteAttrName = _dereq_('./jsx').quoteAttrName;
  13349. var trimLeft = _dereq_('./jsx').trimLeft;
  13350. /**
  13351. * Customized desugar processor for React JSX. Currently:
  13352. *
  13353. * <X> </X> => React.createElement(X, null)
  13354. * <X prop="1" /> => React.createElement(X, {prop: '1'}, null)
  13355. * <X prop="2"><Y /></X> => React.createElement(X, {prop:'2'},
  13356. * React.createElement(Y, null)
  13357. * )
  13358. * <div /> => React.createElement("div", null)
  13359. */
  13360. /**
  13361. * Removes all non-whitespace/parenthesis characters
  13362. */
  13363. var reNonWhiteParen = /([^\s\(\)])/g;
  13364. function stripNonWhiteParen(value) {
  13365. return value.replace(reNonWhiteParen, '');
  13366. }
  13367. var tagConvention = /^[a-z]|\-/;
  13368. function isTagName(name) {
  13369. return tagConvention.test(name);
  13370. }
  13371. function visitReactTag(traverse, object, path, state) {
  13372. var openingElement = object.openingElement;
  13373. var nameObject = openingElement.name;
  13374. var attributesObject = openingElement.attributes;
  13375. utils.catchup(openingElement.range[0], state, trimLeft);
  13376. if (nameObject.type === Syntax.JSXNamespacedName && nameObject.namespace) {
  13377. throw new Error('Namespace tags are not supported. ReactJSX is not XML.');
  13378. }
  13379. // We assume that the React runtime is already in scope
  13380. utils.append('React.createElement(', state);
  13381. if (nameObject.type === Syntax.JSXIdentifier && isTagName(nameObject.name)) {
  13382. utils.append('"' + nameObject.name + '"', state);
  13383. utils.move(nameObject.range[1], state);
  13384. } else {
  13385. // Use utils.catchup in this case so we can easily handle
  13386. // JSXMemberExpressions which look like Foo.Bar.Baz. This also handles
  13387. // JSXIdentifiers that aren't fallback tags.
  13388. utils.move(nameObject.range[0], state);
  13389. utils.catchup(nameObject.range[1], state);
  13390. }
  13391. utils.append(', ', state);
  13392. var hasAttributes = attributesObject.length;
  13393. var hasAtLeastOneSpreadProperty = attributesObject.some(function(attr) {
  13394. return attr.type === Syntax.JSXSpreadAttribute;
  13395. });
  13396. // if we don't have any attributes, pass in null
  13397. if (hasAtLeastOneSpreadProperty) {
  13398. utils.append('React.__spread({', state);
  13399. } else if (hasAttributes) {
  13400. utils.append('{', state);
  13401. } else {
  13402. utils.append('null', state);
  13403. }
  13404. // keep track of if the previous attribute was a spread attribute
  13405. var previousWasSpread = false;
  13406. // write attributes
  13407. attributesObject.forEach(function(attr, index) {
  13408. var isLast = index === attributesObject.length - 1;
  13409. if (attr.type === Syntax.JSXSpreadAttribute) {
  13410. // Close the previous object or initial object
  13411. if (!previousWasSpread) {
  13412. utils.append('}, ', state);
  13413. }
  13414. // Move to the expression start, ignoring everything except parenthesis
  13415. // and whitespace.
  13416. utils.catchup(attr.range[0], state, stripNonWhiteParen);
  13417. // Plus 1 to skip `{`.
  13418. utils.move(attr.range[0] + 1, state);
  13419. utils.catchup(attr.argument.range[0], state, stripNonWhiteParen);
  13420. traverse(attr.argument, path, state);
  13421. utils.catchup(attr.argument.range[1], state);
  13422. // Move to the end, ignoring parenthesis and the closing `}`
  13423. utils.catchup(attr.range[1] - 1, state, stripNonWhiteParen);
  13424. if (!isLast) {
  13425. utils.append(', ', state);
  13426. }
  13427. utils.move(attr.range[1], state);
  13428. previousWasSpread = true;
  13429. return;
  13430. }
  13431. // If the next attribute is a spread, we're effective last in this object
  13432. if (!isLast) {
  13433. isLast = attributesObject[index + 1].type === Syntax.JSXSpreadAttribute;
  13434. }
  13435. if (attr.name.namespace) {
  13436. throw new Error(
  13437. 'Namespace attributes are not supported. ReactJSX is not XML.');
  13438. }
  13439. var name = attr.name.name;
  13440. utils.catchup(attr.range[0], state, trimLeft);
  13441. if (previousWasSpread) {
  13442. utils.append('{', state);
  13443. }
  13444. utils.append(quoteAttrName(name), state);
  13445. utils.append(': ', state);
  13446. if (!attr.value) {
  13447. state.g.buffer += 'true';
  13448. state.g.position = attr.name.range[1];
  13449. if (!isLast) {
  13450. utils.append(', ', state);
  13451. }
  13452. } else {
  13453. utils.move(attr.name.range[1], state);
  13454. // Use catchupNewlines to skip over the '=' in the attribute
  13455. utils.catchupNewlines(attr.value.range[0], state);
  13456. if (attr.value.type === Syntax.Literal) {
  13457. renderJSXLiteral(attr.value, isLast, state);
  13458. } else {
  13459. renderJSXExpressionContainer(traverse, attr.value, isLast, path, state);
  13460. }
  13461. }
  13462. utils.catchup(attr.range[1], state, trimLeft);
  13463. previousWasSpread = false;
  13464. });
  13465. if (!openingElement.selfClosing) {
  13466. utils.catchup(openingElement.range[1] - 1, state, trimLeft);
  13467. utils.move(openingElement.range[1], state);
  13468. }
  13469. if (hasAttributes && !previousWasSpread) {
  13470. utils.append('}', state);
  13471. }
  13472. if (hasAtLeastOneSpreadProperty) {
  13473. utils.append(')', state);
  13474. }
  13475. // filter out whitespace
  13476. var childrenToRender = object.children.filter(function(child) {
  13477. return !(child.type === Syntax.Literal
  13478. && typeof child.value === 'string'
  13479. && child.value.match(/^[ \t]*[\r\n][ \t\r\n]*$/));
  13480. });
  13481. if (childrenToRender.length > 0) {
  13482. var lastRenderableIndex;
  13483. childrenToRender.forEach(function(child, index) {
  13484. if (child.type !== Syntax.JSXExpressionContainer ||
  13485. child.expression.type !== Syntax.JSXEmptyExpression) {
  13486. lastRenderableIndex = index;
  13487. }
  13488. });
  13489. if (lastRenderableIndex !== undefined) {
  13490. utils.append(', ', state);
  13491. }
  13492. childrenToRender.forEach(function(child, index) {
  13493. utils.catchup(child.range[0], state, trimLeft);
  13494. var isLast = index >= lastRenderableIndex;
  13495. if (child.type === Syntax.Literal) {
  13496. renderJSXLiteral(child, isLast, state);
  13497. } else if (child.type === Syntax.JSXExpressionContainer) {
  13498. renderJSXExpressionContainer(traverse, child, isLast, path, state);
  13499. } else {
  13500. traverse(child, path, state);
  13501. if (!isLast) {
  13502. utils.append(', ', state);
  13503. }
  13504. }
  13505. utils.catchup(child.range[1], state, trimLeft);
  13506. });
  13507. }
  13508. if (openingElement.selfClosing) {
  13509. // everything up to />
  13510. utils.catchup(openingElement.range[1] - 2, state, trimLeft);
  13511. utils.move(openingElement.range[1], state);
  13512. } else {
  13513. // everything up to </ sdflksjfd>
  13514. utils.catchup(object.closingElement.range[0], state, trimLeft);
  13515. utils.move(object.closingElement.range[1], state);
  13516. }
  13517. utils.append(')', state);
  13518. return false;
  13519. }
  13520. visitReactTag.test = function(object, path, state) {
  13521. return object.type === Syntax.JSXElement;
  13522. };
  13523. exports.visitorList = [
  13524. visitReactTag
  13525. ];
  13526. },{"./jsx":37,"jstransform":22,"jstransform/src/utils":23}],39:[function(_dereq_,module,exports){
  13527. /**
  13528. * Copyright 2013-2015, Facebook, Inc.
  13529. * All rights reserved.
  13530. *
  13531. * This source code is licensed under the BSD-style license found in the
  13532. * LICENSE file in the root directory of this source tree. An additional grant
  13533. * of patent rights can be found in the PATENTS file in the same directory.
  13534. */
  13535. /*global exports:true*/
  13536. 'use strict';
  13537. var Syntax = _dereq_('jstransform').Syntax;
  13538. var utils = _dereq_('jstransform/src/utils');
  13539. function addDisplayName(displayName, object, state) {
  13540. if (object &&
  13541. object.type === Syntax.CallExpression &&
  13542. object.callee.type === Syntax.MemberExpression &&
  13543. object.callee.object.type === Syntax.Identifier &&
  13544. object.callee.object.name === 'React' &&
  13545. object.callee.property.type === Syntax.Identifier &&
  13546. object.callee.property.name === 'createClass' &&
  13547. object.arguments.length === 1 &&
  13548. object.arguments[0].type === Syntax.ObjectExpression) {
  13549. // Verify that the displayName property isn't already set
  13550. var properties = object.arguments[0].properties;
  13551. var safe = properties.every(function(property) {
  13552. var value = property.key.type === Syntax.Identifier ?
  13553. property.key.name :
  13554. property.key.value;
  13555. return value !== 'displayName';
  13556. });
  13557. if (safe) {
  13558. utils.catchup(object.arguments[0].range[0] + 1, state);
  13559. utils.append('displayName: "' + displayName + '",', state);
  13560. }
  13561. }
  13562. }
  13563. /**
  13564. * Transforms the following:
  13565. *
  13566. * var MyComponent = React.createClass({
  13567. * render: ...
  13568. * });
  13569. *
  13570. * into:
  13571. *
  13572. * var MyComponent = React.createClass({
  13573. * displayName: 'MyComponent',
  13574. * render: ...
  13575. * });
  13576. *
  13577. * Also catches:
  13578. *
  13579. * MyComponent = React.createClass(...);
  13580. * exports.MyComponent = React.createClass(...);
  13581. * module.exports = {MyComponent: React.createClass(...)};
  13582. */
  13583. function visitReactDisplayName(traverse, object, path, state) {
  13584. var left, right;
  13585. if (object.type === Syntax.AssignmentExpression) {
  13586. left = object.left;
  13587. right = object.right;
  13588. } else if (object.type === Syntax.Property) {
  13589. left = object.key;
  13590. right = object.value;
  13591. } else if (object.type === Syntax.VariableDeclarator) {
  13592. left = object.id;
  13593. right = object.init;
  13594. }
  13595. if (left && left.type === Syntax.MemberExpression) {
  13596. left = left.property;
  13597. }
  13598. if (left && left.type === Syntax.Identifier) {
  13599. addDisplayName(left.name, right, state);
  13600. }
  13601. }
  13602. visitReactDisplayName.test = function(object, path, state) {
  13603. return (
  13604. object.type === Syntax.AssignmentExpression ||
  13605. object.type === Syntax.Property ||
  13606. object.type === Syntax.VariableDeclarator
  13607. );
  13608. };
  13609. exports.visitorList = [
  13610. visitReactDisplayName
  13611. ];
  13612. },{"jstransform":22,"jstransform/src/utils":23}],40:[function(_dereq_,module,exports){
  13613. /*global exports:true*/
  13614. 'use strict';
  13615. var es6ArrowFunctions =
  13616. _dereq_('jstransform/visitors/es6-arrow-function-visitors');
  13617. var es6Classes = _dereq_('jstransform/visitors/es6-class-visitors');
  13618. var es6Destructuring =
  13619. _dereq_('jstransform/visitors/es6-destructuring-visitors');
  13620. var es6ObjectConciseMethod =
  13621. _dereq_('jstransform/visitors/es6-object-concise-method-visitors');
  13622. var es6ObjectShortNotation =
  13623. _dereq_('jstransform/visitors/es6-object-short-notation-visitors');
  13624. var es6RestParameters = _dereq_('jstransform/visitors/es6-rest-param-visitors');
  13625. var es6Templates = _dereq_('jstransform/visitors/es6-template-visitors');
  13626. var es6CallSpread =
  13627. _dereq_('jstransform/visitors/es6-call-spread-visitors');
  13628. var es7SpreadProperty =
  13629. _dereq_('jstransform/visitors/es7-spread-property-visitors');
  13630. var react = _dereq_('./transforms/react');
  13631. var reactDisplayName = _dereq_('./transforms/reactDisplayName');
  13632. var reservedWords = _dereq_('jstransform/visitors/reserved-words-visitors');
  13633. /**
  13634. * Map from transformName => orderedListOfVisitors.
  13635. */
  13636. var transformVisitors = {
  13637. 'es6-arrow-functions': es6ArrowFunctions.visitorList,
  13638. 'es6-classes': es6Classes.visitorList,
  13639. 'es6-destructuring': es6Destructuring.visitorList,
  13640. 'es6-object-concise-method': es6ObjectConciseMethod.visitorList,
  13641. 'es6-object-short-notation': es6ObjectShortNotation.visitorList,
  13642. 'es6-rest-params': es6RestParameters.visitorList,
  13643. 'es6-templates': es6Templates.visitorList,
  13644. 'es6-call-spread': es6CallSpread.visitorList,
  13645. 'es7-spread-property': es7SpreadProperty.visitorList,
  13646. 'react': react.visitorList.concat(reactDisplayName.visitorList),
  13647. 'reserved-words': reservedWords.visitorList
  13648. };
  13649. var transformSets = {
  13650. 'harmony': [
  13651. 'es6-arrow-functions',
  13652. 'es6-object-concise-method',
  13653. 'es6-object-short-notation',
  13654. 'es6-classes',
  13655. 'es6-rest-params',
  13656. 'es6-templates',
  13657. 'es6-destructuring',
  13658. 'es6-call-spread',
  13659. 'es7-spread-property'
  13660. ],
  13661. 'es3': [
  13662. 'reserved-words'
  13663. ],
  13664. 'react': [
  13665. 'react'
  13666. ]
  13667. };
  13668. /**
  13669. * Specifies the order in which each transform should run.
  13670. */
  13671. var transformRunOrder = [
  13672. 'reserved-words',
  13673. 'es6-arrow-functions',
  13674. 'es6-object-concise-method',
  13675. 'es6-object-short-notation',
  13676. 'es6-classes',
  13677. 'es6-rest-params',
  13678. 'es6-templates',
  13679. 'es6-destructuring',
  13680. 'es6-call-spread',
  13681. 'es7-spread-property',
  13682. 'react'
  13683. ];
  13684. /**
  13685. * Given a list of transform names, return the ordered list of visitors to be
  13686. * passed to the transform() function.
  13687. *
  13688. * @param {array?} excludes
  13689. * @return {array}
  13690. */
  13691. function getAllVisitors(excludes) {
  13692. var ret = [];
  13693. for (var i = 0, il = transformRunOrder.length; i < il; i++) {
  13694. if (!excludes || excludes.indexOf(transformRunOrder[i]) === -1) {
  13695. ret = ret.concat(transformVisitors[transformRunOrder[i]]);
  13696. }
  13697. }
  13698. return ret;
  13699. }
  13700. /**
  13701. * Given a list of visitor set names, return the ordered list of visitors to be
  13702. * passed to jstransform.
  13703. *
  13704. * @param {array}
  13705. * @return {array}
  13706. */
  13707. function getVisitorsBySet(sets) {
  13708. var visitorsToInclude = sets.reduce(function(visitors, set) {
  13709. if (!transformSets.hasOwnProperty(set)) {
  13710. throw new Error('Unknown visitor set: ' + set);
  13711. }
  13712. transformSets[set].forEach(function(visitor) {
  13713. visitors[visitor] = true;
  13714. });
  13715. return visitors;
  13716. }, {});
  13717. var visitorList = [];
  13718. for (var i = 0; i < transformRunOrder.length; i++) {
  13719. if (visitorsToInclude.hasOwnProperty(transformRunOrder[i])) {
  13720. visitorList = visitorList.concat(transformVisitors[transformRunOrder[i]]);
  13721. }
  13722. }
  13723. return visitorList;
  13724. }
  13725. exports.getVisitorsBySet = getVisitorsBySet;
  13726. exports.getAllVisitors = getAllVisitors;
  13727. exports.transformVisitors = transformVisitors;
  13728. },{"./transforms/react":38,"./transforms/reactDisplayName":39,"jstransform/visitors/es6-arrow-function-visitors":24,"jstransform/visitors/es6-call-spread-visitors":25,"jstransform/visitors/es6-class-visitors":26,"jstransform/visitors/es6-destructuring-visitors":27,"jstransform/visitors/es6-object-concise-method-visitors":28,"jstransform/visitors/es6-object-short-notation-visitors":29,"jstransform/visitors/es6-rest-param-visitors":30,"jstransform/visitors/es6-template-visitors":31,"jstransform/visitors/es7-spread-property-visitors":33,"jstransform/visitors/reserved-words-visitors":35}],41:[function(_dereq_,module,exports){
  13729. /**
  13730. * Copyright 2013-2015, Facebook, Inc.
  13731. * All rights reserved.
  13732. *
  13733. * This source code is licensed under the BSD-style license found in the
  13734. * LICENSE file in the root directory of this source tree. An additional grant
  13735. * of patent rights can be found in the PATENTS file in the same directory.
  13736. */
  13737. 'use strict';
  13738. /*eslint-disable no-undef*/
  13739. var Buffer = _dereq_('buffer').Buffer;
  13740. function inlineSourceMap(sourceMap, sourceCode, sourceFilename) {
  13741. // This can be used with a sourcemap that has already has toJSON called on it.
  13742. // Check first.
  13743. var json = sourceMap;
  13744. if (typeof sourceMap.toJSON === 'function') {
  13745. json = sourceMap.toJSON();
  13746. }
  13747. json.sources = [sourceFilename];
  13748. json.sourcesContent = [sourceCode];
  13749. var base64 = Buffer(JSON.stringify(json)).toString('base64');
  13750. return '//# sourceMappingURL=data:application/json;base64,' + base64;
  13751. }
  13752. module.exports = inlineSourceMap;
  13753. },{"buffer":3}]},{},[1])(1)
  13754. });