JSXTransformer.js 532 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574
  1. /**
  2. * JSXTransformer v0.10.0
  3. */
  4. !function (e) { if ("object" == typeof exports) module.exports = e(); else if ("function" == typeof define && define.amd) define(e); else { var f; "undefined" != typeof window ? f = window : "undefined" != typeof global ? f = global : "undefined" != typeof self && (f = self), f.JSXTransformer = e() } }(function () {
  5. 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); throw new Error("Cannot find module '" + o + "'") } var f = n[o] = { exports: {} }; t[o][0].call(f.exports, function (e) { var n = t[o][1][e]; return s(n ? n : e) }, f, f.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 })({
  6. 1: [function (_dereq_, module, exports) {
  7. /**
  8. * The buffer module from node.js, for the browser.
  9. *
  10. * Author: Feross Aboukhadijeh <[email protected]> <http://feross.org>
  11. * License: MIT
  12. *
  13. * `npm install buffer`
  14. */
  15. var base64 = _dereq_('base64-js')
  16. var ieee754 = _dereq_('ieee754')
  17. exports.Buffer = Buffer
  18. exports.SlowBuffer = Buffer
  19. exports.INSPECT_MAX_BYTES = 50
  20. Buffer.poolSize = 8192
  21. /**
  22. * If `Buffer._useTypedArrays`:
  23. * === true Use Uint8Array implementation (fastest)
  24. * === false Use Object implementation (compatible down to IE6)
  25. */
  26. Buffer._useTypedArrays = (function () {
  27. // Detect if browser supports Typed Arrays. Supported browsers are IE 10+,
  28. // Firefox 4+, Chrome 7+, Safari 5.1+, Opera 11.6+, iOS 4.2+.
  29. if (typeof Uint8Array !== 'function' || typeof ArrayBuffer !== 'function')
  30. return false
  31. // Does the browser support adding properties to `Uint8Array` instances? If
  32. // not, then that's the same as no `Uint8Array` support. We need to be able to
  33. // add all the node Buffer API methods.
  34. // Bug in Firefox 4-29, now fixed: https://bugzilla.mozilla.org/show_bug.cgi?id=695438
  35. try {
  36. var arr = new Uint8Array(0)
  37. arr.foo = function () { return 42 }
  38. return 42 === arr.foo() &&
  39. typeof arr.subarray === 'function' // Chrome 9-10 lack `subarray`
  40. } catch (e) {
  41. return false
  42. }
  43. })()
  44. /**
  45. * Class: Buffer
  46. * =============
  47. *
  48. * The Buffer constructor returns instances of `Uint8Array` that are augmented
  49. * with function properties for all the node `Buffer` API functions. We use
  50. * `Uint8Array` so that square bracket notation works as expected -- it returns
  51. * a single octet.
  52. *
  53. * By augmenting the instances, we can avoid modifying the `Uint8Array`
  54. * prototype.
  55. */
  56. function Buffer(subject, encoding, noZero) {
  57. if (!(this instanceof Buffer))
  58. return new Buffer(subject, encoding, noZero)
  59. var type = typeof subject
  60. // Workaround: node's base64 implementation allows for non-padded strings
  61. // while base64-js does not.
  62. if (encoding === 'base64' && type === 'string') {
  63. subject = stringtrim(subject)
  64. while (subject.length % 4 !== 0) {
  65. subject = subject + '='
  66. }
  67. }
  68. // Find the length
  69. var length
  70. if (type === 'number')
  71. length = coerce(subject)
  72. else if (type === 'string')
  73. length = Buffer.byteLength(subject, encoding)
  74. else if (type === 'object')
  75. length = coerce(subject.length) // Assume object is an array
  76. else
  77. throw new Error('First argument needs to be a number, array or string.')
  78. var buf
  79. if (Buffer._useTypedArrays) {
  80. // Preferred: Return an augmented `Uint8Array` instance for best performance
  81. buf = augment(new Uint8Array(length))
  82. } else {
  83. // Fallback: Return THIS instance of Buffer (created by `new`)
  84. buf = this
  85. buf.length = length
  86. buf._isBuffer = true
  87. }
  88. var i
  89. if (Buffer._useTypedArrays && typeof Uint8Array === 'function' &&
  90. subject instanceof Uint8Array) {
  91. // Speed optimization -- use set if we're copying from a Uint8Array
  92. buf._set(subject)
  93. } else if (isArrayish(subject)) {
  94. // Treat array-ish objects as a byte array
  95. for (i = 0; i < length; i++) {
  96. if (Buffer.isBuffer(subject))
  97. buf[i] = subject.readUInt8(i)
  98. else
  99. buf[i] = subject[i]
  100. }
  101. } else if (type === 'string') {
  102. buf.write(subject, 0, encoding)
  103. } else if (type === 'number' && !Buffer._useTypedArrays && !noZero) {
  104. for (i = 0; i < length; i++) {
  105. buf[i] = 0
  106. }
  107. }
  108. return buf
  109. }
  110. // STATIC METHODS
  111. // ==============
  112. Buffer.isEncoding = function (encoding) {
  113. switch (String(encoding).toLowerCase()) {
  114. case 'hex':
  115. case 'utf8':
  116. case 'utf-8':
  117. case 'ascii':
  118. case 'binary':
  119. case 'base64':
  120. case 'raw':
  121. case 'ucs2':
  122. case 'ucs-2':
  123. case 'utf16le':
  124. case 'utf-16le':
  125. return true
  126. default:
  127. return false
  128. }
  129. }
  130. Buffer.isBuffer = function (b) {
  131. return !!(b !== null && b !== undefined && b._isBuffer)
  132. }
  133. Buffer.byteLength = function (str, encoding) {
  134. var ret
  135. str = str + ''
  136. switch (encoding || 'utf8') {
  137. case 'hex':
  138. ret = str.length / 2
  139. break
  140. case 'utf8':
  141. case 'utf-8':
  142. ret = utf8ToBytes(str).length
  143. break
  144. case 'ascii':
  145. case 'binary':
  146. case 'raw':
  147. ret = str.length
  148. break
  149. case 'base64':
  150. ret = base64ToBytes(str).length
  151. break
  152. case 'ucs2':
  153. case 'ucs-2':
  154. case 'utf16le':
  155. case 'utf-16le':
  156. ret = str.length * 2
  157. break
  158. default:
  159. throw new Error('Unknown encoding')
  160. }
  161. return ret
  162. }
  163. Buffer.concat = function (list, totalLength) {
  164. assert(isArray(list), 'Usage: Buffer.concat(list, [totalLength])\n' +
  165. 'list should be an Array.')
  166. if (list.length === 0) {
  167. return new Buffer(0)
  168. } else if (list.length === 1) {
  169. return list[0]
  170. }
  171. var i
  172. if (typeof totalLength !== 'number') {
  173. totalLength = 0
  174. for (i = 0; i < list.length; i++) {
  175. totalLength += list[i].length
  176. }
  177. }
  178. var buf = new Buffer(totalLength)
  179. var pos = 0
  180. for (i = 0; i < list.length; i++) {
  181. var item = list[i]
  182. item.copy(buf, pos)
  183. pos += item.length
  184. }
  185. return buf
  186. }
  187. // BUFFER INSTANCE METHODS
  188. // =======================
  189. function _hexWrite(buf, string, offset, length) {
  190. offset = Number(offset) || 0
  191. var remaining = buf.length - offset
  192. if (!length) {
  193. length = remaining
  194. } else {
  195. length = Number(length)
  196. if (length > remaining) {
  197. length = remaining
  198. }
  199. }
  200. // must be an even number of digits
  201. var strLen = string.length
  202. assert(strLen % 2 === 0, 'Invalid hex string')
  203. if (length > strLen / 2) {
  204. length = strLen / 2
  205. }
  206. for (var i = 0; i < length; i++) {
  207. var byte = parseInt(string.substr(i * 2, 2), 16)
  208. assert(!isNaN(byte), 'Invalid hex string')
  209. buf[offset + i] = byte
  210. }
  211. Buffer._charsWritten = i * 2
  212. return i
  213. }
  214. function _utf8Write(buf, string, offset, length) {
  215. var charsWritten = Buffer._charsWritten =
  216. blitBuffer(utf8ToBytes(string), buf, offset, length)
  217. return charsWritten
  218. }
  219. function _asciiWrite(buf, string, offset, length) {
  220. var charsWritten = Buffer._charsWritten =
  221. blitBuffer(asciiToBytes(string), buf, offset, length)
  222. return charsWritten
  223. }
  224. function _binaryWrite(buf, string, offset, length) {
  225. return _asciiWrite(buf, string, offset, length)
  226. }
  227. function _base64Write(buf, string, offset, length) {
  228. var charsWritten = Buffer._charsWritten =
  229. blitBuffer(base64ToBytes(string), buf, offset, length)
  230. return charsWritten
  231. }
  232. function _utf16leWrite(buf, string, offset, length) {
  233. var charsWritten = Buffer._charsWritten =
  234. blitBuffer(utf16leToBytes(string), buf, offset, length)
  235. return charsWritten
  236. }
  237. Buffer.prototype.write = function (string, offset, length, encoding) {
  238. // Support both (string, offset, length, encoding)
  239. // and the legacy (string, encoding, offset, length)
  240. if (isFinite(offset)) {
  241. if (!isFinite(length)) {
  242. encoding = length
  243. length = undefined
  244. }
  245. } else { // legacy
  246. var swap = encoding
  247. encoding = offset
  248. offset = length
  249. length = swap
  250. }
  251. offset = Number(offset) || 0
  252. var remaining = this.length - offset
  253. if (!length) {
  254. length = remaining
  255. } else {
  256. length = Number(length)
  257. if (length > remaining) {
  258. length = remaining
  259. }
  260. }
  261. encoding = String(encoding || 'utf8').toLowerCase()
  262. var ret
  263. switch (encoding) {
  264. case 'hex':
  265. ret = _hexWrite(this, string, offset, length)
  266. break
  267. case 'utf8':
  268. case 'utf-8':
  269. ret = _utf8Write(this, string, offset, length)
  270. break
  271. case 'ascii':
  272. ret = _asciiWrite(this, string, offset, length)
  273. break
  274. case 'binary':
  275. ret = _binaryWrite(this, string, offset, length)
  276. break
  277. case 'base64':
  278. ret = _base64Write(this, string, offset, length)
  279. break
  280. case 'ucs2':
  281. case 'ucs-2':
  282. case 'utf16le':
  283. case 'utf-16le':
  284. ret = _utf16leWrite(this, string, offset, length)
  285. break
  286. default:
  287. throw new Error('Unknown encoding')
  288. }
  289. return ret
  290. }
  291. Buffer.prototype.toString = function (encoding, start, end) {
  292. var self = this
  293. encoding = String(encoding || 'utf8').toLowerCase()
  294. start = Number(start) || 0
  295. end = (end !== undefined)
  296. ? Number(end)
  297. : end = self.length
  298. // Fastpath empty strings
  299. if (end === start)
  300. return ''
  301. var ret
  302. switch (encoding) {
  303. case 'hex':
  304. ret = _hexSlice(self, start, end)
  305. break
  306. case 'utf8':
  307. case 'utf-8':
  308. ret = _utf8Slice(self, start, end)
  309. break
  310. case 'ascii':
  311. ret = _asciiSlice(self, start, end)
  312. break
  313. case 'binary':
  314. ret = _binarySlice(self, start, end)
  315. break
  316. case 'base64':
  317. ret = _base64Slice(self, start, end)
  318. break
  319. case 'ucs2':
  320. case 'ucs-2':
  321. case 'utf16le':
  322. case 'utf-16le':
  323. ret = _utf16leSlice(self, start, end)
  324. break
  325. default:
  326. throw new Error('Unknown encoding')
  327. }
  328. return ret
  329. }
  330. Buffer.prototype.toJSON = function () {
  331. return {
  332. type: 'Buffer',
  333. data: Array.prototype.slice.call(this._arr || this, 0)
  334. }
  335. }
  336. // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
  337. Buffer.prototype.copy = function (target, target_start, start, end) {
  338. var source = this
  339. if (!start) start = 0
  340. if (!end && end !== 0) end = this.length
  341. if (!target_start) target_start = 0
  342. // Copy 0 bytes; we're done
  343. if (end === start) return
  344. if (target.length === 0 || source.length === 0) return
  345. // Fatal error conditions
  346. assert(end >= start, 'sourceEnd < sourceStart')
  347. assert(target_start >= 0 && target_start < target.length,
  348. 'targetStart out of bounds')
  349. assert(start >= 0 && start < source.length, 'sourceStart out of bounds')
  350. assert(end >= 0 && end <= source.length, 'sourceEnd out of bounds')
  351. // Are we oob?
  352. if (end > this.length)
  353. end = this.length
  354. if (target.length - target_start < end - start)
  355. end = target.length - target_start + start
  356. // copy!
  357. for (var i = 0; i < end - start; i++)
  358. target[i + target_start] = this[i + start]
  359. }
  360. function _base64Slice(buf, start, end) {
  361. if (start === 0 && end === buf.length) {
  362. return base64.fromByteArray(buf)
  363. } else {
  364. return base64.fromByteArray(buf.slice(start, end))
  365. }
  366. }
  367. function _utf8Slice(buf, start, end) {
  368. var res = ''
  369. var tmp = ''
  370. end = Math.min(buf.length, end)
  371. for (var i = start; i < end; i++) {
  372. if (buf[i] <= 0x7F) {
  373. res += decodeUtf8Char(tmp) + String.fromCharCode(buf[i])
  374. tmp = ''
  375. } else {
  376. tmp += '%' + buf[i].toString(16)
  377. }
  378. }
  379. return res + decodeUtf8Char(tmp)
  380. }
  381. function _asciiSlice(buf, start, end) {
  382. var ret = ''
  383. end = Math.min(buf.length, end)
  384. for (var i = start; i < end; i++)
  385. ret += String.fromCharCode(buf[i])
  386. return ret
  387. }
  388. function _binarySlice(buf, start, end) {
  389. return _asciiSlice(buf, start, end)
  390. }
  391. function _hexSlice(buf, start, end) {
  392. var len = buf.length
  393. if (!start || start < 0) start = 0
  394. if (!end || end < 0 || end > len) end = len
  395. var out = ''
  396. for (var i = start; i < end; i++) {
  397. out += toHex(buf[i])
  398. }
  399. return out
  400. }
  401. function _utf16leSlice(buf, start, end) {
  402. var bytes = buf.slice(start, end)
  403. var res = ''
  404. for (var i = 0; i < bytes.length; i += 2) {
  405. res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256)
  406. }
  407. return res
  408. }
  409. Buffer.prototype.slice = function (start, end) {
  410. var len = this.length
  411. start = clamp(start, len, 0)
  412. end = clamp(end, len, len)
  413. if (Buffer._useTypedArrays) {
  414. return augment(this.subarray(start, end))
  415. } else {
  416. var sliceLen = end - start
  417. var newBuf = new Buffer(sliceLen, undefined, true)
  418. for (var i = 0; i < sliceLen; i++) {
  419. newBuf[i] = this[i + start]
  420. }
  421. return newBuf
  422. }
  423. }
  424. // `get` will be removed in Node 0.13+
  425. Buffer.prototype.get = function (offset) {
  426. console.log('.get() is deprecated. Access using array indexes instead.')
  427. return this.readUInt8(offset)
  428. }
  429. // `set` will be removed in Node 0.13+
  430. Buffer.prototype.set = function (v, offset) {
  431. console.log('.set() is deprecated. Access using array indexes instead.')
  432. return this.writeUInt8(v, offset)
  433. }
  434. Buffer.prototype.readUInt8 = function (offset, noAssert) {
  435. if (!noAssert) {
  436. assert(offset !== undefined && offset !== null, 'missing offset')
  437. assert(offset < this.length, 'Trying to read beyond buffer length')
  438. }
  439. if (offset >= this.length)
  440. return
  441. return this[offset]
  442. }
  443. function _readUInt16(buf, offset, littleEndian, noAssert) {
  444. if (!noAssert) {
  445. assert(typeof littleEndian === 'boolean', 'missing or invalid endian')
  446. assert(offset !== undefined && offset !== null, 'missing offset')
  447. assert(offset + 1 < buf.length, 'Trying to read beyond buffer length')
  448. }
  449. var len = buf.length
  450. if (offset >= len)
  451. return
  452. var val
  453. if (littleEndian) {
  454. val = buf[offset]
  455. if (offset + 1 < len)
  456. val |= buf[offset + 1] << 8
  457. } else {
  458. val = buf[offset] << 8
  459. if (offset + 1 < len)
  460. val |= buf[offset + 1]
  461. }
  462. return val
  463. }
  464. Buffer.prototype.readUInt16LE = function (offset, noAssert) {
  465. return _readUInt16(this, offset, true, noAssert)
  466. }
  467. Buffer.prototype.readUInt16BE = function (offset, noAssert) {
  468. return _readUInt16(this, offset, false, noAssert)
  469. }
  470. function _readUInt32(buf, offset, littleEndian, noAssert) {
  471. if (!noAssert) {
  472. assert(typeof littleEndian === 'boolean', 'missing or invalid endian')
  473. assert(offset !== undefined && offset !== null, 'missing offset')
  474. assert(offset + 3 < buf.length, 'Trying to read beyond buffer length')
  475. }
  476. var len = buf.length
  477. if (offset >= len)
  478. return
  479. var val
  480. if (littleEndian) {
  481. if (offset + 2 < len)
  482. val = buf[offset + 2] << 16
  483. if (offset + 1 < len)
  484. val |= buf[offset + 1] << 8
  485. val |= buf[offset]
  486. if (offset + 3 < len)
  487. val = val + (buf[offset + 3] << 24 >>> 0)
  488. } else {
  489. if (offset + 1 < len)
  490. val = buf[offset + 1] << 16
  491. if (offset + 2 < len)
  492. val |= buf[offset + 2] << 8
  493. if (offset + 3 < len)
  494. val |= buf[offset + 3]
  495. val = val + (buf[offset] << 24 >>> 0)
  496. }
  497. return val
  498. }
  499. Buffer.prototype.readUInt32LE = function (offset, noAssert) {
  500. return _readUInt32(this, offset, true, noAssert)
  501. }
  502. Buffer.prototype.readUInt32BE = function (offset, noAssert) {
  503. return _readUInt32(this, offset, false, noAssert)
  504. }
  505. Buffer.prototype.readInt8 = function (offset, noAssert) {
  506. if (!noAssert) {
  507. assert(offset !== undefined && offset !== null,
  508. 'missing offset')
  509. assert(offset < this.length, 'Trying to read beyond buffer length')
  510. }
  511. if (offset >= this.length)
  512. return
  513. var neg = this[offset] & 0x80
  514. if (neg)
  515. return (0xff - this[offset] + 1) * -1
  516. else
  517. return this[offset]
  518. }
  519. function _readInt16(buf, offset, littleEndian, noAssert) {
  520. if (!noAssert) {
  521. assert(typeof littleEndian === 'boolean', 'missing or invalid endian')
  522. assert(offset !== undefined && offset !== null, 'missing offset')
  523. assert(offset + 1 < buf.length, 'Trying to read beyond buffer length')
  524. }
  525. var len = buf.length
  526. if (offset >= len)
  527. return
  528. var val = _readUInt16(buf, offset, littleEndian, true)
  529. var neg = val & 0x8000
  530. if (neg)
  531. return (0xffff - val + 1) * -1
  532. else
  533. return val
  534. }
  535. Buffer.prototype.readInt16LE = function (offset, noAssert) {
  536. return _readInt16(this, offset, true, noAssert)
  537. }
  538. Buffer.prototype.readInt16BE = function (offset, noAssert) {
  539. return _readInt16(this, offset, false, noAssert)
  540. }
  541. function _readInt32(buf, offset, littleEndian, noAssert) {
  542. if (!noAssert) {
  543. assert(typeof littleEndian === 'boolean', 'missing or invalid endian')
  544. assert(offset !== undefined && offset !== null, 'missing offset')
  545. assert(offset + 3 < buf.length, 'Trying to read beyond buffer length')
  546. }
  547. var len = buf.length
  548. if (offset >= len)
  549. return
  550. var val = _readUInt32(buf, offset, littleEndian, true)
  551. var neg = val & 0x80000000
  552. if (neg)
  553. return (0xffffffff - val + 1) * -1
  554. else
  555. return val
  556. }
  557. Buffer.prototype.readInt32LE = function (offset, noAssert) {
  558. return _readInt32(this, offset, true, noAssert)
  559. }
  560. Buffer.prototype.readInt32BE = function (offset, noAssert) {
  561. return _readInt32(this, offset, false, noAssert)
  562. }
  563. function _readFloat(buf, offset, littleEndian, noAssert) {
  564. if (!noAssert) {
  565. assert(typeof littleEndian === 'boolean', 'missing or invalid endian')
  566. assert(offset + 3 < buf.length, 'Trying to read beyond buffer length')
  567. }
  568. return ieee754.read(buf, offset, littleEndian, 23, 4)
  569. }
  570. Buffer.prototype.readFloatLE = function (offset, noAssert) {
  571. return _readFloat(this, offset, true, noAssert)
  572. }
  573. Buffer.prototype.readFloatBE = function (offset, noAssert) {
  574. return _readFloat(this, offset, false, noAssert)
  575. }
  576. function _readDouble(buf, offset, littleEndian, noAssert) {
  577. if (!noAssert) {
  578. assert(typeof littleEndian === 'boolean', 'missing or invalid endian')
  579. assert(offset + 7 < buf.length, 'Trying to read beyond buffer length')
  580. }
  581. return ieee754.read(buf, offset, littleEndian, 52, 8)
  582. }
  583. Buffer.prototype.readDoubleLE = function (offset, noAssert) {
  584. return _readDouble(this, offset, true, noAssert)
  585. }
  586. Buffer.prototype.readDoubleBE = function (offset, noAssert) {
  587. return _readDouble(this, offset, false, noAssert)
  588. }
  589. Buffer.prototype.writeUInt8 = function (value, offset, noAssert) {
  590. if (!noAssert) {
  591. assert(value !== undefined && value !== null, 'missing value')
  592. assert(offset !== undefined && offset !== null, 'missing offset')
  593. assert(offset < this.length, 'trying to write beyond buffer length')
  594. verifuint(value, 0xff)
  595. }
  596. if (offset >= this.length) return
  597. this[offset] = value
  598. }
  599. function _writeUInt16(buf, value, offset, littleEndian, noAssert) {
  600. if (!noAssert) {
  601. assert(value !== undefined && value !== null, 'missing value')
  602. assert(typeof littleEndian === 'boolean', 'missing or invalid endian')
  603. assert(offset !== undefined && offset !== null, 'missing offset')
  604. assert(offset + 1 < buf.length, 'trying to write beyond buffer length')
  605. verifuint(value, 0xffff)
  606. }
  607. var len = buf.length
  608. if (offset >= len)
  609. return
  610. for (var i = 0, j = Math.min(len - offset, 2) ; i < j; i++) {
  611. buf[offset + i] =
  612. (value & (0xff << (8 * (littleEndian ? i : 1 - i)))) >>>
  613. (littleEndian ? i : 1 - i) * 8
  614. }
  615. }
  616. Buffer.prototype.writeUInt16LE = function (value, offset, noAssert) {
  617. _writeUInt16(this, value, offset, true, noAssert)
  618. }
  619. Buffer.prototype.writeUInt16BE = function (value, offset, noAssert) {
  620. _writeUInt16(this, value, offset, false, noAssert)
  621. }
  622. function _writeUInt32(buf, value, offset, littleEndian, noAssert) {
  623. if (!noAssert) {
  624. assert(value !== undefined && value !== null, 'missing value')
  625. assert(typeof littleEndian === 'boolean', 'missing or invalid endian')
  626. assert(offset !== undefined && offset !== null, 'missing offset')
  627. assert(offset + 3 < buf.length, 'trying to write beyond buffer length')
  628. verifuint(value, 0xffffffff)
  629. }
  630. var len = buf.length
  631. if (offset >= len)
  632. return
  633. for (var i = 0, j = Math.min(len - offset, 4) ; i < j; i++) {
  634. buf[offset + i] =
  635. (value >>> (littleEndian ? i : 3 - i) * 8) & 0xff
  636. }
  637. }
  638. Buffer.prototype.writeUInt32LE = function (value, offset, noAssert) {
  639. _writeUInt32(this, value, offset, true, noAssert)
  640. }
  641. Buffer.prototype.writeUInt32BE = function (value, offset, noAssert) {
  642. _writeUInt32(this, value, offset, false, noAssert)
  643. }
  644. Buffer.prototype.writeInt8 = function (value, offset, noAssert) {
  645. if (!noAssert) {
  646. assert(value !== undefined && value !== null, 'missing value')
  647. assert(offset !== undefined && offset !== null, 'missing offset')
  648. assert(offset < this.length, 'Trying to write beyond buffer length')
  649. verifsint(value, 0x7f, -0x80)
  650. }
  651. if (offset >= this.length)
  652. return
  653. if (value >= 0)
  654. this.writeUInt8(value, offset, noAssert)
  655. else
  656. this.writeUInt8(0xff + value + 1, offset, noAssert)
  657. }
  658. function _writeInt16(buf, value, offset, littleEndian, noAssert) {
  659. if (!noAssert) {
  660. assert(value !== undefined && value !== null, 'missing value')
  661. assert(typeof littleEndian === 'boolean', 'missing or invalid endian')
  662. assert(offset !== undefined && offset !== null, 'missing offset')
  663. assert(offset + 1 < buf.length, 'Trying to write beyond buffer length')
  664. verifsint(value, 0x7fff, -0x8000)
  665. }
  666. var len = buf.length
  667. if (offset >= len)
  668. return
  669. if (value >= 0)
  670. _writeUInt16(buf, value, offset, littleEndian, noAssert)
  671. else
  672. _writeUInt16(buf, 0xffff + value + 1, offset, littleEndian, noAssert)
  673. }
  674. Buffer.prototype.writeInt16LE = function (value, offset, noAssert) {
  675. _writeInt16(this, value, offset, true, noAssert)
  676. }
  677. Buffer.prototype.writeInt16BE = function (value, offset, noAssert) {
  678. _writeInt16(this, value, offset, false, noAssert)
  679. }
  680. function _writeInt32(buf, value, offset, littleEndian, noAssert) {
  681. if (!noAssert) {
  682. assert(value !== undefined && value !== null, 'missing value')
  683. assert(typeof littleEndian === 'boolean', 'missing or invalid endian')
  684. assert(offset !== undefined && offset !== null, 'missing offset')
  685. assert(offset + 3 < buf.length, 'Trying to write beyond buffer length')
  686. verifsint(value, 0x7fffffff, -0x80000000)
  687. }
  688. var len = buf.length
  689. if (offset >= len)
  690. return
  691. if (value >= 0)
  692. _writeUInt32(buf, value, offset, littleEndian, noAssert)
  693. else
  694. _writeUInt32(buf, 0xffffffff + value + 1, offset, littleEndian, noAssert)
  695. }
  696. Buffer.prototype.writeInt32LE = function (value, offset, noAssert) {
  697. _writeInt32(this, value, offset, true, noAssert)
  698. }
  699. Buffer.prototype.writeInt32BE = function (value, offset, noAssert) {
  700. _writeInt32(this, value, offset, false, noAssert)
  701. }
  702. function _writeFloat(buf, value, offset, littleEndian, noAssert) {
  703. if (!noAssert) {
  704. assert(value !== undefined && value !== null, 'missing value')
  705. assert(typeof littleEndian === 'boolean', 'missing or invalid endian')
  706. assert(offset !== undefined && offset !== null, 'missing offset')
  707. assert(offset + 3 < buf.length, 'Trying to write beyond buffer length')
  708. verifIEEE754(value, 3.4028234663852886e+38, -3.4028234663852886e+38)
  709. }
  710. var len = buf.length
  711. if (offset >= len)
  712. return
  713. ieee754.write(buf, value, offset, littleEndian, 23, 4)
  714. }
  715. Buffer.prototype.writeFloatLE = function (value, offset, noAssert) {
  716. _writeFloat(this, value, offset, true, noAssert)
  717. }
  718. Buffer.prototype.writeFloatBE = function (value, offset, noAssert) {
  719. _writeFloat(this, value, offset, false, noAssert)
  720. }
  721. function _writeDouble(buf, value, offset, littleEndian, noAssert) {
  722. if (!noAssert) {
  723. assert(value !== undefined && value !== null, 'missing value')
  724. assert(typeof littleEndian === 'boolean', 'missing or invalid endian')
  725. assert(offset !== undefined && offset !== null, 'missing offset')
  726. assert(offset + 7 < buf.length,
  727. 'Trying to write beyond buffer length')
  728. verifIEEE754(value, 1.7976931348623157E+308, -1.7976931348623157E+308)
  729. }
  730. var len = buf.length
  731. if (offset >= len)
  732. return
  733. ieee754.write(buf, value, offset, littleEndian, 52, 8)
  734. }
  735. Buffer.prototype.writeDoubleLE = function (value, offset, noAssert) {
  736. _writeDouble(this, value, offset, true, noAssert)
  737. }
  738. Buffer.prototype.writeDoubleBE = function (value, offset, noAssert) {
  739. _writeDouble(this, value, offset, false, noAssert)
  740. }
  741. // fill(value, start=0, end=buffer.length)
  742. Buffer.prototype.fill = function (value, start, end) {
  743. if (!value) value = 0
  744. if (!start) start = 0
  745. if (!end) end = this.length
  746. if (typeof value === 'string') {
  747. value = value.charCodeAt(0)
  748. }
  749. assert(typeof value === 'number' && !isNaN(value), 'value is not a number')
  750. assert(end >= start, 'end < start')
  751. // Fill 0 bytes; we're done
  752. if (end === start) return
  753. if (this.length === 0) return
  754. assert(start >= 0 && start < this.length, 'start out of bounds')
  755. assert(end >= 0 && end <= this.length, 'end out of bounds')
  756. for (var i = start; i < end; i++) {
  757. this[i] = value
  758. }
  759. }
  760. Buffer.prototype.inspect = function () {
  761. var out = []
  762. var len = this.length
  763. for (var i = 0; i < len; i++) {
  764. out[i] = toHex(this[i])
  765. if (i === exports.INSPECT_MAX_BYTES) {
  766. out[i + 1] = '...'
  767. break
  768. }
  769. }
  770. return '<Buffer ' + out.join(' ') + '>'
  771. }
  772. /**
  773. * Creates a new `ArrayBuffer` with the *copied* memory of the buffer instance.
  774. * Added in Node 0.12. Only available in browsers that support ArrayBuffer.
  775. */
  776. Buffer.prototype.toArrayBuffer = function () {
  777. if (typeof Uint8Array === 'function') {
  778. if (Buffer._useTypedArrays) {
  779. return (new Buffer(this)).buffer
  780. } else {
  781. var buf = new Uint8Array(this.length)
  782. for (var i = 0, len = buf.length; i < len; i += 1)
  783. buf[i] = this[i]
  784. return buf.buffer
  785. }
  786. } else {
  787. throw new Error('Buffer.toArrayBuffer not supported in this browser')
  788. }
  789. }
  790. // HELPER FUNCTIONS
  791. // ================
  792. function stringtrim(str) {
  793. if (str.trim) return str.trim()
  794. return str.replace(/^\s+|\s+$/g, '')
  795. }
  796. var BP = Buffer.prototype
  797. /**
  798. * Augment the Uint8Array *instance* (not the class!) with Buffer methods
  799. */
  800. function augment(arr) {
  801. arr._isBuffer = true
  802. // save reference to original Uint8Array get/set methods before overwriting
  803. arr._get = arr.get
  804. arr._set = arr.set
  805. // deprecated, will be removed in node 0.13+
  806. arr.get = BP.get
  807. arr.set = BP.set
  808. arr.write = BP.write
  809. arr.toString = BP.toString
  810. arr.toLocaleString = BP.toString
  811. arr.toJSON = BP.toJSON
  812. arr.copy = BP.copy
  813. arr.slice = BP.slice
  814. arr.readUInt8 = BP.readUInt8
  815. arr.readUInt16LE = BP.readUInt16LE
  816. arr.readUInt16BE = BP.readUInt16BE
  817. arr.readUInt32LE = BP.readUInt32LE
  818. arr.readUInt32BE = BP.readUInt32BE
  819. arr.readInt8 = BP.readInt8
  820. arr.readInt16LE = BP.readInt16LE
  821. arr.readInt16BE = BP.readInt16BE
  822. arr.readInt32LE = BP.readInt32LE
  823. arr.readInt32BE = BP.readInt32BE
  824. arr.readFloatLE = BP.readFloatLE
  825. arr.readFloatBE = BP.readFloatBE
  826. arr.readDoubleLE = BP.readDoubleLE
  827. arr.readDoubleBE = BP.readDoubleBE
  828. arr.writeUInt8 = BP.writeUInt8
  829. arr.writeUInt16LE = BP.writeUInt16LE
  830. arr.writeUInt16BE = BP.writeUInt16BE
  831. arr.writeUInt32LE = BP.writeUInt32LE
  832. arr.writeUInt32BE = BP.writeUInt32BE
  833. arr.writeInt8 = BP.writeInt8
  834. arr.writeInt16LE = BP.writeInt16LE
  835. arr.writeInt16BE = BP.writeInt16BE
  836. arr.writeInt32LE = BP.writeInt32LE
  837. arr.writeInt32BE = BP.writeInt32BE
  838. arr.writeFloatLE = BP.writeFloatLE
  839. arr.writeFloatBE = BP.writeFloatBE
  840. arr.writeDoubleLE = BP.writeDoubleLE
  841. arr.writeDoubleBE = BP.writeDoubleBE
  842. arr.fill = BP.fill
  843. arr.inspect = BP.inspect
  844. arr.toArrayBuffer = BP.toArrayBuffer
  845. return arr
  846. }
  847. // slice(start, end)
  848. function clamp(index, len, defaultValue) {
  849. if (typeof index !== 'number') return defaultValue
  850. index = ~~index; // Coerce to integer.
  851. if (index >= len) return len
  852. if (index >= 0) return index
  853. index += len
  854. if (index >= 0) return index
  855. return 0
  856. }
  857. function coerce(length) {
  858. // Coerce length to a number (possibly NaN), round up
  859. // in case it's fractional (e.g. 123.456) then do a
  860. // double negate to coerce a NaN to 0. Easy, right?
  861. length = ~~Math.ceil(+length)
  862. return length < 0 ? 0 : length
  863. }
  864. function isArray(subject) {
  865. return (Array.isArray || function (subject) {
  866. return Object.prototype.toString.call(subject) === '[object Array]'
  867. })(subject)
  868. }
  869. function isArrayish(subject) {
  870. return isArray(subject) || Buffer.isBuffer(subject) ||
  871. subject && typeof subject === 'object' &&
  872. typeof subject.length === 'number'
  873. }
  874. function toHex(n) {
  875. if (n < 16) return '0' + n.toString(16)
  876. return n.toString(16)
  877. }
  878. function utf8ToBytes(str) {
  879. var byteArray = []
  880. for (var i = 0; i < str.length; i++) {
  881. var b = str.charCodeAt(i)
  882. if (b <= 0x7F)
  883. byteArray.push(str.charCodeAt(i))
  884. else {
  885. var start = i
  886. if (b >= 0xD800 && b <= 0xDFFF) i++
  887. var h = encodeURIComponent(str.slice(start, i + 1)).substr(1).split('%')
  888. for (var j = 0; j < h.length; j++)
  889. byteArray.push(parseInt(h[j], 16))
  890. }
  891. }
  892. return byteArray
  893. }
  894. function asciiToBytes(str) {
  895. var byteArray = []
  896. for (var i = 0; i < str.length; i++) {
  897. // Node's code seems to be doing this and not & 0x7F..
  898. byteArray.push(str.charCodeAt(i) & 0xFF)
  899. }
  900. return byteArray
  901. }
  902. function utf16leToBytes(str) {
  903. var c, hi, lo
  904. var byteArray = []
  905. for (var i = 0; i < str.length; i++) {
  906. c = str.charCodeAt(i)
  907. hi = c >> 8
  908. lo = c % 256
  909. byteArray.push(lo)
  910. byteArray.push(hi)
  911. }
  912. return byteArray
  913. }
  914. function base64ToBytes(str) {
  915. return base64.toByteArray(str)
  916. }
  917. function blitBuffer(src, dst, offset, length) {
  918. var pos
  919. for (var i = 0; i < length; i++) {
  920. if ((i + offset >= dst.length) || (i >= src.length))
  921. break
  922. dst[i + offset] = src[i]
  923. }
  924. return i
  925. }
  926. function decodeUtf8Char(str) {
  927. try {
  928. return decodeURIComponent(str)
  929. } catch (err) {
  930. return String.fromCharCode(0xFFFD) // UTF 8 invalid char
  931. }
  932. }
  933. /*
  934. * We have to make sure that the value is a valid integer. This means that it
  935. * is non-negative. It has no fractional component and that it does not
  936. * exceed the maximum allowed value.
  937. */
  938. function verifuint(value, max) {
  939. assert(typeof value === 'number', 'cannot write a non-number as a number')
  940. assert(value >= 0, 'specified a negative value for writing an unsigned value')
  941. assert(value <= max, 'value is larger than maximum value for type')
  942. assert(Math.floor(value) === value, 'value has a fractional component')
  943. }
  944. function verifsint(value, max, min) {
  945. assert(typeof value === 'number', 'cannot write a non-number as a number')
  946. assert(value <= max, 'value larger than maximum allowed value')
  947. assert(value >= min, 'value smaller than minimum allowed value')
  948. assert(Math.floor(value) === value, 'value has a fractional component')
  949. }
  950. function verifIEEE754(value, max, min) {
  951. assert(typeof value === 'number', 'cannot write a non-number as a number')
  952. assert(value <= max, 'value larger than maximum allowed value')
  953. assert(value >= min, 'value smaller than minimum allowed value')
  954. }
  955. function assert(test, message) {
  956. if (!test) throw new Error(message || 'Failed assertion')
  957. }
  958. }, { "base64-js": 2, "ieee754": 3 }], 2: [function (_dereq_, module, exports) {
  959. var lookup = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
  960. ; (function (exports) {
  961. 'use strict';
  962. var Arr = (typeof Uint8Array !== 'undefined')
  963. ? Uint8Array
  964. : Array
  965. var ZERO = '0'.charCodeAt(0)
  966. var PLUS = '+'.charCodeAt(0)
  967. var SLASH = '/'.charCodeAt(0)
  968. var NUMBER = '0'.charCodeAt(0)
  969. var LOWER = 'a'.charCodeAt(0)
  970. var UPPER = 'A'.charCodeAt(0)
  971. function decode(elt) {
  972. var code = elt.charCodeAt(0)
  973. if (code === PLUS)
  974. return 62 // '+'
  975. if (code === SLASH)
  976. return 63 // '/'
  977. if (code < NUMBER)
  978. return -1 //no match
  979. if (code < NUMBER + 10)
  980. return code - NUMBER + 26 + 26
  981. if (code < UPPER + 26)
  982. return code - UPPER
  983. if (code < LOWER + 26)
  984. return code - LOWER + 26
  985. }
  986. function b64ToByteArray(b64) {
  987. var i, j, l, tmp, placeHolders, arr
  988. if (b64.length % 4 > 0) {
  989. throw new Error('Invalid string. Length must be a multiple of 4')
  990. }
  991. // the number of equal signs (place holders)
  992. // if there are two placeholders, than the two characters before it
  993. // represent one byte
  994. // if there is only one, then the three characters before it represent 2 bytes
  995. // this is just a cheap hack to not do indexOf twice
  996. var len = b64.length
  997. placeHolders = '=' === b64.charAt(len - 2) ? 2 : '=' === b64.charAt(len - 1) ? 1 : 0
  998. // base64 is 4/3 + up to two characters of the original data
  999. arr = new Arr(b64.length * 3 / 4 - placeHolders)
  1000. // if there are placeholders, only get up to the last complete 4 chars
  1001. l = placeHolders > 0 ? b64.length - 4 : b64.length
  1002. var L = 0
  1003. function push(v) {
  1004. arr[L++] = v
  1005. }
  1006. for (i = 0, j = 0; i < l; i += 4, j += 3) {
  1007. tmp = (decode(b64.charAt(i)) << 18) | (decode(b64.charAt(i + 1)) << 12) | (decode(b64.charAt(i + 2)) << 6) | decode(b64.charAt(i + 3))
  1008. push((tmp & 0xFF0000) >> 16)
  1009. push((tmp & 0xFF00) >> 8)
  1010. push(tmp & 0xFF)
  1011. }
  1012. if (placeHolders === 2) {
  1013. tmp = (decode(b64.charAt(i)) << 2) | (decode(b64.charAt(i + 1)) >> 4)
  1014. push(tmp & 0xFF)
  1015. } else if (placeHolders === 1) {
  1016. tmp = (decode(b64.charAt(i)) << 10) | (decode(b64.charAt(i + 1)) << 4) | (decode(b64.charAt(i + 2)) >> 2)
  1017. push((tmp >> 8) & 0xFF)
  1018. push(tmp & 0xFF)
  1019. }
  1020. return arr
  1021. }
  1022. function uint8ToBase64(uint8) {
  1023. var i,
  1024. extraBytes = uint8.length % 3, // if we have 1 byte left, pad 2 bytes
  1025. output = "",
  1026. temp, length
  1027. function encode(num) {
  1028. return lookup.charAt(num)
  1029. }
  1030. function tripletToBase64(num) {
  1031. return encode(num >> 18 & 0x3F) + encode(num >> 12 & 0x3F) + encode(num >> 6 & 0x3F) + encode(num & 0x3F)
  1032. }
  1033. // go through the array every three bytes, we'll deal with trailing stuff later
  1034. for (i = 0, length = uint8.length - extraBytes; i < length; i += 3) {
  1035. temp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2])
  1036. output += tripletToBase64(temp)
  1037. }
  1038. // pad the end with zeros, but make sure to not forget the extra bytes
  1039. switch (extraBytes) {
  1040. case 1:
  1041. temp = uint8[uint8.length - 1]
  1042. output += encode(temp >> 2)
  1043. output += encode((temp << 4) & 0x3F)
  1044. output += '=='
  1045. break
  1046. case 2:
  1047. temp = (uint8[uint8.length - 2] << 8) + (uint8[uint8.length - 1])
  1048. output += encode(temp >> 10)
  1049. output += encode((temp >> 4) & 0x3F)
  1050. output += encode((temp << 2) & 0x3F)
  1051. output += '='
  1052. break
  1053. }
  1054. return output
  1055. }
  1056. module.exports.toByteArray = b64ToByteArray
  1057. module.exports.fromByteArray = uint8ToBase64
  1058. }())
  1059. }, {}], 3: [function (_dereq_, module, exports) {
  1060. exports.read = function (buffer, offset, isLE, mLen, nBytes) {
  1061. var e, m,
  1062. eLen = nBytes * 8 - mLen - 1,
  1063. eMax = (1 << eLen) - 1,
  1064. eBias = eMax >> 1,
  1065. nBits = -7,
  1066. i = isLE ? (nBytes - 1) : 0,
  1067. d = isLE ? -1 : 1,
  1068. s = buffer[offset + i];
  1069. i += d;
  1070. e = s & ((1 << (-nBits)) - 1);
  1071. s >>= (-nBits);
  1072. nBits += eLen;
  1073. for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8);
  1074. m = e & ((1 << (-nBits)) - 1);
  1075. e >>= (-nBits);
  1076. nBits += mLen;
  1077. for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8);
  1078. if (e === 0) {
  1079. e = 1 - eBias;
  1080. } else if (e === eMax) {
  1081. return m ? NaN : ((s ? -1 : 1) * Infinity);
  1082. } else {
  1083. m = m + Math.pow(2, mLen);
  1084. e = e - eBias;
  1085. }
  1086. return (s ? -1 : 1) * m * Math.pow(2, e - mLen);
  1087. };
  1088. exports.write = function (buffer, value, offset, isLE, mLen, nBytes) {
  1089. var e, m, c,
  1090. eLen = nBytes * 8 - mLen - 1,
  1091. eMax = (1 << eLen) - 1,
  1092. eBias = eMax >> 1,
  1093. rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0),
  1094. i = isLE ? 0 : (nBytes - 1),
  1095. d = isLE ? 1 : -1,
  1096. s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0;
  1097. value = Math.abs(value);
  1098. if (isNaN(value) || value === Infinity) {
  1099. m = isNaN(value) ? 1 : 0;
  1100. e = eMax;
  1101. } else {
  1102. e = Math.floor(Math.log(value) / Math.LN2);
  1103. if (value * (c = Math.pow(2, -e)) < 1) {
  1104. e--;
  1105. c *= 2;
  1106. }
  1107. if (e + eBias >= 1) {
  1108. value += rt / c;
  1109. } else {
  1110. value += rt * Math.pow(2, 1 - eBias);
  1111. }
  1112. if (value * c >= 2) {
  1113. e++;
  1114. c /= 2;
  1115. }
  1116. if (e + eBias >= eMax) {
  1117. m = 0;
  1118. e = eMax;
  1119. } else if (e + eBias >= 1) {
  1120. m = (value * c - 1) * Math.pow(2, mLen);
  1121. e = e + eBias;
  1122. } else {
  1123. m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
  1124. e = 0;
  1125. }
  1126. }
  1127. for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8);
  1128. e = (e << mLen) | m;
  1129. eLen += mLen;
  1130. for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8);
  1131. buffer[offset + i - d] |= s * 128;
  1132. };
  1133. }, {}], 4: [function (_dereq_, module, exports) {
  1134. // shim for using process in browser
  1135. var process = module.exports = {};
  1136. process.nextTick = (function () {
  1137. var canSetImmediate = typeof window !== 'undefined'
  1138. && window.setImmediate;
  1139. var canPost = typeof window !== 'undefined'
  1140. && window.postMessage && window.addEventListener
  1141. ;
  1142. if (canSetImmediate) {
  1143. return function (f) { return window.setImmediate(f) };
  1144. }
  1145. if (canPost) {
  1146. var queue = [];
  1147. window.addEventListener('message', function (ev) {
  1148. var source = ev.source;
  1149. if ((source === window || source === null) && ev.data === 'process-tick') {
  1150. ev.stopPropagation();
  1151. if (queue.length > 0) {
  1152. var fn = queue.shift();
  1153. fn();
  1154. }
  1155. }
  1156. }, true);
  1157. return function nextTick(fn) {
  1158. queue.push(fn);
  1159. window.postMessage('process-tick', '*');
  1160. };
  1161. }
  1162. return function nextTick(fn) {
  1163. setTimeout(fn, 0);
  1164. };
  1165. })();
  1166. process.title = 'browser';
  1167. process.browser = true;
  1168. process.env = {};
  1169. process.argv = [];
  1170. process.binding = function (name) {
  1171. throw new Error('process.binding is not supported');
  1172. }
  1173. // TODO(shtylman)
  1174. process.cwd = function () { return '/' };
  1175. process.chdir = function (dir) {
  1176. throw new Error('process.chdir is not supported');
  1177. };
  1178. }, {}], 5: [function (_dereq_, module, exports) {
  1179. (function (process) {
  1180. // Copyright Joyent, Inc. and other Node contributors.
  1181. //
  1182. // Permission is hereby granted, free of charge, to any person obtaining a
  1183. // copy of this software and associated documentation files (the
  1184. // "Software"), to deal in the Software without restriction, including
  1185. // without limitation the rights to use, copy, modify, merge, publish,
  1186. // distribute, sublicense, and/or sell copies of the Software, and to permit
  1187. // persons to whom the Software is furnished to do so, subject to the
  1188. // following conditions:
  1189. //
  1190. // The above copyright notice and this permission notice shall be included
  1191. // in all copies or substantial portions of the Software.
  1192. //
  1193. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  1194. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  1195. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  1196. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  1197. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  1198. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  1199. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  1200. // resolves . and .. elements in a path array with directory names there
  1201. // must be no slashes, empty elements, or device names (c:\) in the array
  1202. // (so also no leading and trailing slashes - it does not distinguish
  1203. // relative and absolute paths)
  1204. function normalizeArray(parts, allowAboveRoot) {
  1205. // if the path tries to go above the root, `up` ends up > 0
  1206. var up = 0;
  1207. for (var i = parts.length - 1; i >= 0; i--) {
  1208. var last = parts[i];
  1209. if (last === '.') {
  1210. parts.splice(i, 1);
  1211. } else if (last === '..') {
  1212. parts.splice(i, 1);
  1213. up++;
  1214. } else if (up) {
  1215. parts.splice(i, 1);
  1216. up--;
  1217. }
  1218. }
  1219. // if the path is allowed to go above the root, restore leading ..s
  1220. if (allowAboveRoot) {
  1221. for (; up--; up) {
  1222. parts.unshift('..');
  1223. }
  1224. }
  1225. return parts;
  1226. }
  1227. // Split a filename into [root, dir, basename, ext], unix version
  1228. // 'root' is just a slash, or nothing.
  1229. var splitPathRe =
  1230. /^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/;
  1231. var splitPath = function (filename) {
  1232. return splitPathRe.exec(filename).slice(1);
  1233. };
  1234. // path.resolve([from ...], to)
  1235. // posix version
  1236. exports.resolve = function () {
  1237. var resolvedPath = '',
  1238. resolvedAbsolute = false;
  1239. for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) {
  1240. var path = (i >= 0) ? arguments[i] : process.cwd();
  1241. // Skip empty and invalid entries
  1242. if (typeof path !== 'string') {
  1243. throw new TypeError('Arguments to path.resolve must be strings');
  1244. } else if (!path) {
  1245. continue;
  1246. }
  1247. resolvedPath = path + '/' + resolvedPath;
  1248. resolvedAbsolute = path.charAt(0) === '/';
  1249. }
  1250. // At this point the path should be resolved to a full absolute path, but
  1251. // handle relative paths to be safe (might happen when process.cwd() fails)
  1252. // Normalize the path
  1253. resolvedPath = normalizeArray(filter(resolvedPath.split('/'), function (p) {
  1254. return !!p;
  1255. }), !resolvedAbsolute).join('/');
  1256. return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.';
  1257. };
  1258. // path.normalize(path)
  1259. // posix version
  1260. exports.normalize = function (path) {
  1261. var isAbsolute = exports.isAbsolute(path),
  1262. trailingSlash = substr(path, -1) === '/';
  1263. // Normalize the path
  1264. path = normalizeArray(filter(path.split('/'), function (p) {
  1265. return !!p;
  1266. }), !isAbsolute).join('/');
  1267. if (!path && !isAbsolute) {
  1268. path = '.';
  1269. }
  1270. if (path && trailingSlash) {
  1271. path += '/';
  1272. }
  1273. return (isAbsolute ? '/' : '') + path;
  1274. };
  1275. // posix version
  1276. exports.isAbsolute = function (path) {
  1277. return path.charAt(0) === '/';
  1278. };
  1279. // posix version
  1280. exports.join = function () {
  1281. var paths = Array.prototype.slice.call(arguments, 0);
  1282. return exports.normalize(filter(paths, function (p, index) {
  1283. if (typeof p !== 'string') {
  1284. throw new TypeError('Arguments to path.join must be strings');
  1285. }
  1286. return p;
  1287. }).join('/'));
  1288. };
  1289. // path.relative(from, to)
  1290. // posix version
  1291. exports.relative = function (from, to) {
  1292. from = exports.resolve(from).substr(1);
  1293. to = exports.resolve(to).substr(1);
  1294. function trim(arr) {
  1295. var start = 0;
  1296. for (; start < arr.length; start++) {
  1297. if (arr[start] !== '') break;
  1298. }
  1299. var end = arr.length - 1;
  1300. for (; end >= 0; end--) {
  1301. if (arr[end] !== '') break;
  1302. }
  1303. if (start > end) return [];
  1304. return arr.slice(start, end - start + 1);
  1305. }
  1306. var fromParts = trim(from.split('/'));
  1307. var toParts = trim(to.split('/'));
  1308. var length = Math.min(fromParts.length, toParts.length);
  1309. var samePartsLength = length;
  1310. for (var i = 0; i < length; i++) {
  1311. if (fromParts[i] !== toParts[i]) {
  1312. samePartsLength = i;
  1313. break;
  1314. }
  1315. }
  1316. var outputParts = [];
  1317. for (var i = samePartsLength; i < fromParts.length; i++) {
  1318. outputParts.push('..');
  1319. }
  1320. outputParts = outputParts.concat(toParts.slice(samePartsLength));
  1321. return outputParts.join('/');
  1322. };
  1323. exports.sep = '/';
  1324. exports.delimiter = ':';
  1325. exports.dirname = function (path) {
  1326. var result = splitPath(path),
  1327. root = result[0],
  1328. dir = result[1];
  1329. if (!root && !dir) {
  1330. // No dirname whatsoever
  1331. return '.';
  1332. }
  1333. if (dir) {
  1334. // It has a dirname, strip trailing slash
  1335. dir = dir.substr(0, dir.length - 1);
  1336. }
  1337. return root + dir;
  1338. };
  1339. exports.basename = function (path, ext) {
  1340. var f = splitPath(path)[2];
  1341. // TODO: make this comparison case-insensitive on windows?
  1342. if (ext && f.substr(-1 * ext.length) === ext) {
  1343. f = f.substr(0, f.length - ext.length);
  1344. }
  1345. return f;
  1346. };
  1347. exports.extname = function (path) {
  1348. return splitPath(path)[3];
  1349. };
  1350. function filter(xs, f) {
  1351. if (xs.filter) return xs.filter(f);
  1352. var res = [];
  1353. for (var i = 0; i < xs.length; i++) {
  1354. if (f(xs[i], i, xs)) res.push(xs[i]);
  1355. }
  1356. return res;
  1357. }
  1358. // String.prototype.substr - negative index don't work in IE8
  1359. var substr = 'ab'.substr(-1) === 'b'
  1360. ? function (str, start, len) { return str.substr(start, len) }
  1361. : function (str, start, len) {
  1362. if (start < 0) start = str.length + start;
  1363. return str.substr(start, len);
  1364. }
  1365. ;
  1366. }).call(this, _dereq_("/Users/poshannessy/FB/code/react/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js"))
  1367. }, { "/Users/poshannessy/FB/code/react/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js": 4 }], 6: [function (_dereq_, module, exports) {
  1368. /*
  1369. Copyright (C) 2013 Ariya Hidayat <[email protected]>
  1370. Copyright (C) 2013 Thaddee Tyl <[email protected]>
  1371. Copyright (C) 2012 Ariya Hidayat <[email protected]>
  1372. Copyright (C) 2012 Mathias Bynens <[email protected]>
  1373. Copyright (C) 2012 Joost-Wim Boekesteijn <[email protected]>
  1374. Copyright (C) 2012 Kris Kowal <[email protected]>
  1375. Copyright (C) 2012 Yusuke Suzuki <[email protected]>
  1376. Copyright (C) 2012 Arpad Borsos <[email protected]>
  1377. Copyright (C) 2011 Ariya Hidayat <[email protected]>
  1378. Redistribution and use in source and binary forms, with or without
  1379. modification, are permitted provided that the following conditions are met:
  1380. * Redistributions of source code must retain the above copyright
  1381. notice, this list of conditions and the following disclaimer.
  1382. * Redistributions in binary form must reproduce the above copyright
  1383. notice, this list of conditions and the following disclaimer in the
  1384. documentation and/or other materials provided with the distribution.
  1385. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  1386. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  1387. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  1388. ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  1389. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  1390. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  1391. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  1392. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  1393. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  1394. THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  1395. */
  1396. /*jslint bitwise:true plusplus:true */
  1397. /*global esprima:true, define:true, exports:true, window: true,
  1398. throwError: true, generateStatement: true, peek: true,
  1399. parseAssignmentExpression: true, parseBlock: true,
  1400. parseClassExpression: true, parseClassDeclaration: true, parseExpression: true,
  1401. parseForStatement: true,
  1402. parseFunctionDeclaration: true, parseFunctionExpression: true,
  1403. parseFunctionSourceElements: true, parseVariableIdentifier: true,
  1404. parseImportSpecifier: true,
  1405. parseLeftHandSideExpression: true, parseParams: true, validateParam: true,
  1406. parseSpreadOrAssignmentExpression: true,
  1407. parseStatement: true, parseSourceElement: true, parseModuleBlock: true, parseConciseBody: true,
  1408. advanceXJSChild: true, isXJSIdentifierStart: true, isXJSIdentifierPart: true,
  1409. scanXJSStringLiteral: true, scanXJSIdentifier: true,
  1410. parseXJSAttributeValue: true, parseXJSChild: true, parseXJSElement: true, parseXJSExpressionContainer: true, parseXJSEmptyExpression: true,
  1411. parseTypeAnnotation: true, parseTypeAnnotatableIdentifier: true,
  1412. parseYieldExpression: true
  1413. */
  1414. (function (root, factory) {
  1415. 'use strict';
  1416. // Universal Module Definition (UMD) to support AMD, CommonJS/Node.js,
  1417. // Rhino, and plain browser loading.
  1418. if (typeof define === 'function' && define.amd) {
  1419. define(['exports'], factory);
  1420. } else if (typeof exports !== 'undefined') {
  1421. factory(exports);
  1422. } else {
  1423. factory((root.esprima = {}));
  1424. }
  1425. }(this, function (exports) {
  1426. 'use strict';
  1427. var Token,
  1428. TokenName,
  1429. FnExprTokens,
  1430. Syntax,
  1431. PropertyKind,
  1432. Messages,
  1433. Regex,
  1434. SyntaxTreeDelegate,
  1435. XHTMLEntities,
  1436. ClassPropertyType,
  1437. source,
  1438. strict,
  1439. index,
  1440. lineNumber,
  1441. lineStart,
  1442. length,
  1443. delegate,
  1444. lookahead,
  1445. state,
  1446. extra;
  1447. Token = {
  1448. BooleanLiteral: 1,
  1449. EOF: 2,
  1450. Identifier: 3,
  1451. Keyword: 4,
  1452. NullLiteral: 5,
  1453. NumericLiteral: 6,
  1454. Punctuator: 7,
  1455. StringLiteral: 8,
  1456. RegularExpression: 9,
  1457. Template: 10,
  1458. XJSIdentifier: 11,
  1459. XJSText: 12
  1460. };
  1461. TokenName = {};
  1462. TokenName[Token.BooleanLiteral] = 'Boolean';
  1463. TokenName[Token.EOF] = '<end>';
  1464. TokenName[Token.Identifier] = 'Identifier';
  1465. TokenName[Token.Keyword] = 'Keyword';
  1466. TokenName[Token.NullLiteral] = 'Null';
  1467. TokenName[Token.NumericLiteral] = 'Numeric';
  1468. TokenName[Token.Punctuator] = 'Punctuator';
  1469. TokenName[Token.StringLiteral] = 'String';
  1470. TokenName[Token.XJSIdentifier] = 'XJSIdentifier';
  1471. TokenName[Token.XJSText] = 'XJSText';
  1472. TokenName[Token.RegularExpression] = 'RegularExpression';
  1473. // A function following one of those tokens is an expression.
  1474. FnExprTokens = ['(', '{', '[', 'in', 'typeof', 'instanceof', 'new',
  1475. 'return', 'case', 'delete', 'throw', 'void',
  1476. // assignment operators
  1477. '=', '+=', '-=', '*=', '/=', '%=', '<<=', '>>=', '>>>=',
  1478. '&=', '|=', '^=', ',',
  1479. // binary/unary operators
  1480. '+', '-', '*', '/', '%', '++', '--', '<<', '>>', '>>>', '&',
  1481. '|', '^', '!', '~', '&&', '||', '?', ':', '===', '==', '>=',
  1482. '<=', '<', '>', '!=', '!=='];
  1483. Syntax = {
  1484. ArrayExpression: 'ArrayExpression',
  1485. ArrayPattern: 'ArrayPattern',
  1486. ArrowFunctionExpression: 'ArrowFunctionExpression',
  1487. AssignmentExpression: 'AssignmentExpression',
  1488. BinaryExpression: 'BinaryExpression',
  1489. BlockStatement: 'BlockStatement',
  1490. BreakStatement: 'BreakStatement',
  1491. CallExpression: 'CallExpression',
  1492. CatchClause: 'CatchClause',
  1493. ClassBody: 'ClassBody',
  1494. ClassDeclaration: 'ClassDeclaration',
  1495. ClassExpression: 'ClassExpression',
  1496. ClassHeritage: 'ClassHeritage',
  1497. ComprehensionBlock: 'ComprehensionBlock',
  1498. ComprehensionExpression: 'ComprehensionExpression',
  1499. ConditionalExpression: 'ConditionalExpression',
  1500. ContinueStatement: 'ContinueStatement',
  1501. DebuggerStatement: 'DebuggerStatement',
  1502. DoWhileStatement: 'DoWhileStatement',
  1503. EmptyStatement: 'EmptyStatement',
  1504. ExportDeclaration: 'ExportDeclaration',
  1505. ExportBatchSpecifier: 'ExportBatchSpecifier',
  1506. ExportSpecifier: 'ExportSpecifier',
  1507. ExpressionStatement: 'ExpressionStatement',
  1508. ForInStatement: 'ForInStatement',
  1509. ForOfStatement: 'ForOfStatement',
  1510. ForStatement: 'ForStatement',
  1511. FunctionDeclaration: 'FunctionDeclaration',
  1512. FunctionExpression: 'FunctionExpression',
  1513. Identifier: 'Identifier',
  1514. IfStatement: 'IfStatement',
  1515. ImportDeclaration: 'ImportDeclaration',
  1516. ImportSpecifier: 'ImportSpecifier',
  1517. LabeledStatement: 'LabeledStatement',
  1518. Literal: 'Literal',
  1519. LogicalExpression: 'LogicalExpression',
  1520. MemberExpression: 'MemberExpression',
  1521. MethodDefinition: 'MethodDefinition',
  1522. ModuleDeclaration: 'ModuleDeclaration',
  1523. NewExpression: 'NewExpression',
  1524. ObjectExpression: 'ObjectExpression',
  1525. ObjectPattern: 'ObjectPattern',
  1526. Program: 'Program',
  1527. Property: 'Property',
  1528. ReturnStatement: 'ReturnStatement',
  1529. SequenceExpression: 'SequenceExpression',
  1530. SpreadElement: 'SpreadElement',
  1531. SwitchCase: 'SwitchCase',
  1532. SwitchStatement: 'SwitchStatement',
  1533. TaggedTemplateExpression: 'TaggedTemplateExpression',
  1534. TemplateElement: 'TemplateElement',
  1535. TemplateLiteral: 'TemplateLiteral',
  1536. ThisExpression: 'ThisExpression',
  1537. ThrowStatement: 'ThrowStatement',
  1538. TryStatement: 'TryStatement',
  1539. TypeAnnotatedIdentifier: 'TypeAnnotatedIdentifier',
  1540. TypeAnnotation: 'TypeAnnotation',
  1541. UnaryExpression: 'UnaryExpression',
  1542. UpdateExpression: 'UpdateExpression',
  1543. VariableDeclaration: 'VariableDeclaration',
  1544. VariableDeclarator: 'VariableDeclarator',
  1545. WhileStatement: 'WhileStatement',
  1546. WithStatement: 'WithStatement',
  1547. XJSIdentifier: 'XJSIdentifier',
  1548. XJSEmptyExpression: 'XJSEmptyExpression',
  1549. XJSExpressionContainer: 'XJSExpressionContainer',
  1550. XJSElement: 'XJSElement',
  1551. XJSClosingElement: 'XJSClosingElement',
  1552. XJSOpeningElement: 'XJSOpeningElement',
  1553. XJSAttribute: 'XJSAttribute',
  1554. XJSText: 'XJSText',
  1555. YieldExpression: 'YieldExpression'
  1556. };
  1557. PropertyKind = {
  1558. Data: 1,
  1559. Get: 2,
  1560. Set: 4
  1561. };
  1562. ClassPropertyType = {
  1563. 'static': 'static',
  1564. prototype: 'prototype'
  1565. };
  1566. // Error messages should be identical to V8.
  1567. Messages = {
  1568. UnexpectedToken: 'Unexpected token %0',
  1569. UnexpectedNumber: 'Unexpected number',
  1570. UnexpectedString: 'Unexpected string',
  1571. UnexpectedIdentifier: 'Unexpected identifier',
  1572. UnexpectedReserved: 'Unexpected reserved word',
  1573. UnexpectedTemplate: 'Unexpected quasi %0',
  1574. UnexpectedEOS: 'Unexpected end of input',
  1575. NewlineAfterThrow: 'Illegal newline after throw',
  1576. InvalidRegExp: 'Invalid regular expression',
  1577. UnterminatedRegExp: 'Invalid regular expression: missing /',
  1578. InvalidLHSInAssignment: 'Invalid left-hand side in assignment',
  1579. InvalidLHSInFormalsList: 'Invalid left-hand side in formals list',
  1580. InvalidLHSInForIn: 'Invalid left-hand side in for-in',
  1581. MultipleDefaultsInSwitch: 'More than one default clause in switch statement',
  1582. NoCatchOrFinally: 'Missing catch or finally after try',
  1583. UnknownLabel: 'Undefined label \'%0\'',
  1584. Redeclaration: '%0 \'%1\' has already been declared',
  1585. IllegalContinue: 'Illegal continue statement',
  1586. IllegalBreak: 'Illegal break statement',
  1587. IllegalDuplicateClassProperty: 'Illegal duplicate property in class definition',
  1588. IllegalReturn: 'Illegal return statement',
  1589. IllegalYield: 'Illegal yield expression',
  1590. IllegalSpread: 'Illegal spread element',
  1591. StrictModeWith: 'Strict mode code may not include a with statement',
  1592. StrictCatchVariable: 'Catch variable may not be eval or arguments in strict mode',
  1593. StrictVarName: 'Variable name may not be eval or arguments in strict mode',
  1594. StrictParamName: 'Parameter name eval or arguments is not allowed in strict mode',
  1595. StrictParamDupe: 'Strict mode function may not have duplicate parameter names',
  1596. ParameterAfterRestParameter: 'Rest parameter must be final parameter of an argument list',
  1597. DefaultRestParameter: 'Rest parameter can not have a default value',
  1598. ElementAfterSpreadElement: 'Spread must be the final element of an element list',
  1599. ObjectPatternAsRestParameter: 'Invalid rest parameter',
  1600. ObjectPatternAsSpread: 'Invalid spread argument',
  1601. StrictFunctionName: 'Function name may not be eval or arguments in strict mode',
  1602. StrictOctalLiteral: 'Octal literals are not allowed in strict mode.',
  1603. StrictDelete: 'Delete of an unqualified identifier in strict mode.',
  1604. StrictDuplicateProperty: 'Duplicate data property in object literal not allowed in strict mode',
  1605. AccessorDataProperty: 'Object literal may not have data and accessor property with the same name',
  1606. AccessorGetSet: 'Object literal may not have multiple get/set accessors with the same name',
  1607. StrictLHSAssignment: 'Assignment to eval or arguments is not allowed in strict mode',
  1608. StrictLHSPostfix: 'Postfix increment/decrement may not have eval or arguments operand in strict mode',
  1609. StrictLHSPrefix: 'Prefix increment/decrement may not have eval or arguments operand in strict mode',
  1610. StrictReservedWord: 'Use of future reserved word in strict mode',
  1611. NewlineAfterModule: 'Illegal newline after module',
  1612. NoFromAfterImport: 'Missing from after import',
  1613. InvalidModuleSpecifier: 'Invalid module specifier',
  1614. NestedModule: 'Module declaration can not be nested',
  1615. NoYieldInGenerator: 'Missing yield in generator',
  1616. NoUnintializedConst: 'Const must be initialized',
  1617. ComprehensionRequiresBlock: 'Comprehension must have at least one block',
  1618. ComprehensionError: 'Comprehension Error',
  1619. EachNotAllowed: 'Each is not supported',
  1620. InvalidXJSTagName: 'XJS tag name can not be empty',
  1621. InvalidXJSAttributeValue: 'XJS value should be either an expression or a quoted XJS text',
  1622. ExpectedXJSClosingTag: 'Expected corresponding XJS closing tag for %0'
  1623. };
  1624. // See also tools/generate-unicode-regex.py.
  1625. Regex = {
  1626. 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]'),
  1627. 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]')
  1628. };
  1629. // Ensure the condition is true, otherwise throw an error.
  1630. // This is only to have a better contract semantic, i.e. another safety net
  1631. // to catch a logic error. The condition shall be fulfilled in normal case.
  1632. // Do NOT use this to enforce a certain condition on any user input.
  1633. function assert(condition, message) {
  1634. if (!condition) {
  1635. throw new Error('ASSERT: ' + message);
  1636. }
  1637. }
  1638. function isDecimalDigit(ch) {
  1639. return (ch >= 48 && ch <= 57); // 0..9
  1640. }
  1641. function isHexDigit(ch) {
  1642. return '0123456789abcdefABCDEF'.indexOf(ch) >= 0;
  1643. }
  1644. function isOctalDigit(ch) {
  1645. return '01234567'.indexOf(ch) >= 0;
  1646. }
  1647. // 7.2 White Space
  1648. function isWhiteSpace(ch) {
  1649. return (ch === 32) || // space
  1650. (ch === 9) || // tab
  1651. (ch === 0xB) ||
  1652. (ch === 0xC) ||
  1653. (ch === 0xA0) ||
  1654. (ch >= 0x1680 && '\u1680\u180E\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\uFEFF'.indexOf(String.fromCharCode(ch)) > 0);
  1655. }
  1656. // 7.3 Line Terminators
  1657. function isLineTerminator(ch) {
  1658. return (ch === 10) || (ch === 13) || (ch === 0x2028) || (ch === 0x2029);
  1659. }
  1660. // 7.6 Identifier Names and Identifiers
  1661. function isIdentifierStart(ch) {
  1662. return (ch === 36) || (ch === 95) || // $ (dollar) and _ (underscore)
  1663. (ch >= 65 && ch <= 90) || // A..Z
  1664. (ch >= 97 && ch <= 122) || // a..z
  1665. (ch === 92) || // \ (backslash)
  1666. ((ch >= 0x80) && Regex.NonAsciiIdentifierStart.test(String.fromCharCode(ch)));
  1667. }
  1668. function isIdentifierPart(ch) {
  1669. return (ch === 36) || (ch === 95) || // $ (dollar) and _ (underscore)
  1670. (ch >= 65 && ch <= 90) || // A..Z
  1671. (ch >= 97 && ch <= 122) || // a..z
  1672. (ch >= 48 && ch <= 57) || // 0..9
  1673. (ch === 92) || // \ (backslash)
  1674. ((ch >= 0x80) && Regex.NonAsciiIdentifierPart.test(String.fromCharCode(ch)));
  1675. }
  1676. // 7.6.1.2 Future Reserved Words
  1677. function isFutureReservedWord(id) {
  1678. switch (id) {
  1679. case 'class':
  1680. case 'enum':
  1681. case 'export':
  1682. case 'extends':
  1683. case 'import':
  1684. case 'super':
  1685. return true;
  1686. default:
  1687. return false;
  1688. }
  1689. }
  1690. function isStrictModeReservedWord(id) {
  1691. switch (id) {
  1692. case 'implements':
  1693. case 'interface':
  1694. case 'package':
  1695. case 'private':
  1696. case 'protected':
  1697. case 'public':
  1698. case 'static':
  1699. case 'yield':
  1700. case 'let':
  1701. return true;
  1702. default:
  1703. return false;
  1704. }
  1705. }
  1706. function isRestrictedWord(id) {
  1707. return id === 'eval' || id === 'arguments';
  1708. }
  1709. // 7.6.1.1 Keywords
  1710. function isKeyword(id) {
  1711. if (strict && isStrictModeReservedWord(id)) {
  1712. return true;
  1713. }
  1714. // 'const' is specialized as Keyword in V8.
  1715. // 'yield' and 'let' are for compatiblity with SpiderMonkey and ES.next.
  1716. // Some others are from future reserved words.
  1717. switch (id.length) {
  1718. case 2:
  1719. return (id === 'if') || (id === 'in') || (id === 'do');
  1720. case 3:
  1721. return (id === 'var') || (id === 'for') || (id === 'new') ||
  1722. (id === 'try') || (id === 'let');
  1723. case 4:
  1724. return (id === 'this') || (id === 'else') || (id === 'case') ||
  1725. (id === 'void') || (id === 'with') || (id === 'enum');
  1726. case 5:
  1727. return (id === 'while') || (id === 'break') || (id === 'catch') ||
  1728. (id === 'throw') || (id === 'const') || (id === 'yield') ||
  1729. (id === 'class') || (id === 'super');
  1730. case 6:
  1731. return (id === 'return') || (id === 'typeof') || (id === 'delete') ||
  1732. (id === 'switch') || (id === 'export') || (id === 'import');
  1733. case 7:
  1734. return (id === 'default') || (id === 'finally') || (id === 'extends');
  1735. case 8:
  1736. return (id === 'function') || (id === 'continue') || (id === 'debugger');
  1737. case 10:
  1738. return (id === 'instanceof');
  1739. default:
  1740. return false;
  1741. }
  1742. }
  1743. // 7.4 Comments
  1744. function skipComment() {
  1745. var ch, blockComment, lineComment;
  1746. blockComment = false;
  1747. lineComment = false;
  1748. while (index < length) {
  1749. ch = source.charCodeAt(index);
  1750. if (lineComment) {
  1751. ++index;
  1752. if (isLineTerminator(ch)) {
  1753. lineComment = false;
  1754. if (ch === 13 && source.charCodeAt(index) === 10) {
  1755. ++index;
  1756. }
  1757. ++lineNumber;
  1758. lineStart = index;
  1759. }
  1760. } else if (blockComment) {
  1761. if (isLineTerminator(ch)) {
  1762. if (ch === 13 && source.charCodeAt(index + 1) === 10) {
  1763. ++index;
  1764. }
  1765. ++lineNumber;
  1766. ++index;
  1767. lineStart = index;
  1768. if (index >= length) {
  1769. throwError({}, Messages.UnexpectedToken, 'ILLEGAL');
  1770. }
  1771. } else {
  1772. ch = source.charCodeAt(index++);
  1773. if (index >= length) {
  1774. throwError({}, Messages.UnexpectedToken, 'ILLEGAL');
  1775. }
  1776. // Block comment ends with '*/' (char #42, char #47).
  1777. if (ch === 42) {
  1778. ch = source.charCodeAt(index);
  1779. if (ch === 47) {
  1780. ++index;
  1781. blockComment = false;
  1782. }
  1783. }
  1784. }
  1785. } else if (ch === 47) {
  1786. ch = source.charCodeAt(index + 1);
  1787. // Line comment starts with '//' (char #47, char #47).
  1788. if (ch === 47) {
  1789. index += 2;
  1790. lineComment = true;
  1791. } else if (ch === 42) {
  1792. // Block comment starts with '/*' (char #47, char #42).
  1793. index += 2;
  1794. blockComment = true;
  1795. if (index >= length) {
  1796. throwError({}, Messages.UnexpectedToken, 'ILLEGAL');
  1797. }
  1798. } else {
  1799. break;
  1800. }
  1801. } else if (isWhiteSpace(ch)) {
  1802. ++index;
  1803. } else if (isLineTerminator(ch)) {
  1804. ++index;
  1805. if (ch === 13 && source.charCodeAt(index) === 10) {
  1806. ++index;
  1807. }
  1808. ++lineNumber;
  1809. lineStart = index;
  1810. } else {
  1811. break;
  1812. }
  1813. }
  1814. }
  1815. function scanHexEscape(prefix) {
  1816. var i, len, ch, code = 0;
  1817. len = (prefix === 'u') ? 4 : 2;
  1818. for (i = 0; i < len; ++i) {
  1819. if (index < length && isHexDigit(source[index])) {
  1820. ch = source[index++];
  1821. code = code * 16 + '0123456789abcdef'.indexOf(ch.toLowerCase());
  1822. } else {
  1823. return '';
  1824. }
  1825. }
  1826. return String.fromCharCode(code);
  1827. }
  1828. function scanUnicodeCodePointEscape() {
  1829. var ch, code, cu1, cu2;
  1830. ch = source[index];
  1831. code = 0;
  1832. // At least, one hex digit is required.
  1833. if (ch === '}') {
  1834. throwError({}, Messages.UnexpectedToken, 'ILLEGAL');
  1835. }
  1836. while (index < length) {
  1837. ch = source[index++];
  1838. if (!isHexDigit(ch)) {
  1839. break;
  1840. }
  1841. code = code * 16 + '0123456789abcdef'.indexOf(ch.toLowerCase());
  1842. }
  1843. if (code > 0x10FFFF || ch !== '}') {
  1844. throwError({}, Messages.UnexpectedToken, 'ILLEGAL');
  1845. }
  1846. // UTF-16 Encoding
  1847. if (code <= 0xFFFF) {
  1848. return String.fromCharCode(code);
  1849. }
  1850. cu1 = ((code - 0x10000) >> 10) + 0xD800;
  1851. cu2 = ((code - 0x10000) & 1023) + 0xDC00;
  1852. return String.fromCharCode(cu1, cu2);
  1853. }
  1854. function getEscapedIdentifier() {
  1855. var ch, id;
  1856. ch = source.charCodeAt(index++);
  1857. id = String.fromCharCode(ch);
  1858. // '\u' (char #92, char #117) denotes an escaped character.
  1859. if (ch === 92) {
  1860. if (source.charCodeAt(index) !== 117) {
  1861. throwError({}, Messages.UnexpectedToken, 'ILLEGAL');
  1862. }
  1863. ++index;
  1864. ch = scanHexEscape('u');
  1865. if (!ch || ch === '\\' || !isIdentifierStart(ch.charCodeAt(0))) {
  1866. throwError({}, Messages.UnexpectedToken, 'ILLEGAL');
  1867. }
  1868. id = ch;
  1869. }
  1870. while (index < length) {
  1871. ch = source.charCodeAt(index);
  1872. if (!isIdentifierPart(ch)) {
  1873. break;
  1874. }
  1875. ++index;
  1876. id += String.fromCharCode(ch);
  1877. // '\u' (char #92, char #117) denotes an escaped character.
  1878. if (ch === 92) {
  1879. id = id.substr(0, id.length - 1);
  1880. if (source.charCodeAt(index) !== 117) {
  1881. throwError({}, Messages.UnexpectedToken, 'ILLEGAL');
  1882. }
  1883. ++index;
  1884. ch = scanHexEscape('u');
  1885. if (!ch || ch === '\\' || !isIdentifierPart(ch.charCodeAt(0))) {
  1886. throwError({}, Messages.UnexpectedToken, 'ILLEGAL');
  1887. }
  1888. id += ch;
  1889. }
  1890. }
  1891. return id;
  1892. }
  1893. function getIdentifier() {
  1894. var start, ch;
  1895. start = index++;
  1896. while (index < length) {
  1897. ch = source.charCodeAt(index);
  1898. if (ch === 92) {
  1899. // Blackslash (char #92) marks Unicode escape sequence.
  1900. index = start;
  1901. return getEscapedIdentifier();
  1902. }
  1903. if (isIdentifierPart(ch)) {
  1904. ++index;
  1905. } else {
  1906. break;
  1907. }
  1908. }
  1909. return source.slice(start, index);
  1910. }
  1911. function scanIdentifier() {
  1912. var start, id, type;
  1913. start = index;
  1914. // Backslash (char #92) starts an escaped character.
  1915. id = (source.charCodeAt(index) === 92) ? getEscapedIdentifier() : getIdentifier();
  1916. // There is no keyword or literal with only one character.
  1917. // Thus, it must be an identifier.
  1918. if (id.length === 1) {
  1919. type = Token.Identifier;
  1920. } else if (isKeyword(id)) {
  1921. type = Token.Keyword;
  1922. } else if (id === 'null') {
  1923. type = Token.NullLiteral;
  1924. } else if (id === 'true' || id === 'false') {
  1925. type = Token.BooleanLiteral;
  1926. } else {
  1927. type = Token.Identifier;
  1928. }
  1929. return {
  1930. type: type,
  1931. value: id,
  1932. lineNumber: lineNumber,
  1933. lineStart: lineStart,
  1934. range: [start, index]
  1935. };
  1936. }
  1937. // 7.7 Punctuators
  1938. function scanPunctuator() {
  1939. var start = index,
  1940. code = source.charCodeAt(index),
  1941. code2,
  1942. ch1 = source[index],
  1943. ch2,
  1944. ch3,
  1945. ch4;
  1946. switch (code) {
  1947. // Check for most common single-character punctuators.
  1948. case 40: // ( open bracket
  1949. case 41: // ) close bracket
  1950. case 59: // ; semicolon
  1951. case 44: // , comma
  1952. case 123: // { open curly brace
  1953. case 125: // } close curly brace
  1954. case 91: // [
  1955. case 93: // ]
  1956. case 58: // :
  1957. case 63: // ?
  1958. case 126: // ~
  1959. ++index;
  1960. if (extra.tokenize) {
  1961. if (code === 40) {
  1962. extra.openParenToken = extra.tokens.length;
  1963. } else if (code === 123) {
  1964. extra.openCurlyToken = extra.tokens.length;
  1965. }
  1966. }
  1967. return {
  1968. type: Token.Punctuator,
  1969. value: String.fromCharCode(code),
  1970. lineNumber: lineNumber,
  1971. lineStart: lineStart,
  1972. range: [start, index]
  1973. };
  1974. default:
  1975. code2 = source.charCodeAt(index + 1);
  1976. // '=' (char #61) marks an assignment or comparison operator.
  1977. if (code2 === 61) {
  1978. switch (code) {
  1979. case 37: // %
  1980. case 38: // &
  1981. case 42: // *:
  1982. case 43: // +
  1983. case 45: // -
  1984. case 47: // /
  1985. case 60: // <
  1986. case 62: // >
  1987. case 94: // ^
  1988. case 124: // |
  1989. index += 2;
  1990. return {
  1991. type: Token.Punctuator,
  1992. value: String.fromCharCode(code) + String.fromCharCode(code2),
  1993. lineNumber: lineNumber,
  1994. lineStart: lineStart,
  1995. range: [start, index]
  1996. };
  1997. case 33: // !
  1998. case 61: // =
  1999. index += 2;
  2000. // !== and ===
  2001. if (source.charCodeAt(index) === 61) {
  2002. ++index;
  2003. }
  2004. return {
  2005. type: Token.Punctuator,
  2006. value: source.slice(start, index),
  2007. lineNumber: lineNumber,
  2008. lineStart: lineStart,
  2009. range: [start, index]
  2010. };
  2011. default:
  2012. break;
  2013. }
  2014. }
  2015. break;
  2016. }
  2017. // Peek more characters.
  2018. ch2 = source[index + 1];
  2019. ch3 = source[index + 2];
  2020. ch4 = source[index + 3];
  2021. // 4-character punctuator: >>>=
  2022. if (ch1 === '>' && ch2 === '>' && ch3 === '>') {
  2023. if (ch4 === '=') {
  2024. index += 4;
  2025. return {
  2026. type: Token.Punctuator,
  2027. value: '>>>=',
  2028. lineNumber: lineNumber,
  2029. lineStart: lineStart,
  2030. range: [start, index]
  2031. };
  2032. }
  2033. }
  2034. // 3-character punctuators: === !== >>> <<= >>=
  2035. if (ch1 === '>' && ch2 === '>' && ch3 === '>') {
  2036. index += 3;
  2037. return {
  2038. type: Token.Punctuator,
  2039. value: '>>>',
  2040. lineNumber: lineNumber,
  2041. lineStart: lineStart,
  2042. range: [start, index]
  2043. };
  2044. }
  2045. if (ch1 === '<' && ch2 === '<' && ch3 === '=') {
  2046. index += 3;
  2047. return {
  2048. type: Token.Punctuator,
  2049. value: '<<=',
  2050. lineNumber: lineNumber,
  2051. lineStart: lineStart,
  2052. range: [start, index]
  2053. };
  2054. }
  2055. if (ch1 === '>' && ch2 === '>' && ch3 === '=') {
  2056. index += 3;
  2057. return {
  2058. type: Token.Punctuator,
  2059. value: '>>=',
  2060. lineNumber: lineNumber,
  2061. lineStart: lineStart,
  2062. range: [start, index]
  2063. };
  2064. }
  2065. if (ch1 === '.' && ch2 === '.' && ch3 === '.') {
  2066. index += 3;
  2067. return {
  2068. type: Token.Punctuator,
  2069. value: '...',
  2070. lineNumber: lineNumber,
  2071. lineStart: lineStart,
  2072. range: [start, index]
  2073. };
  2074. }
  2075. // Other 2-character punctuators: ++ -- << >> && ||
  2076. if (ch1 === ch2 && ('+-<>&|'.indexOf(ch1) >= 0)) {
  2077. index += 2;
  2078. return {
  2079. type: Token.Punctuator,
  2080. value: ch1 + ch2,
  2081. lineNumber: lineNumber,
  2082. lineStart: lineStart,
  2083. range: [start, index]
  2084. };
  2085. }
  2086. if (ch1 === '=' && ch2 === '>') {
  2087. index += 2;
  2088. return {
  2089. type: Token.Punctuator,
  2090. value: '=>',
  2091. lineNumber: lineNumber,
  2092. lineStart: lineStart,
  2093. range: [start, index]
  2094. };
  2095. }
  2096. if ('<>=!+-*%&|^/'.indexOf(ch1) >= 0) {
  2097. ++index;
  2098. return {
  2099. type: Token.Punctuator,
  2100. value: ch1,
  2101. lineNumber: lineNumber,
  2102. lineStart: lineStart,
  2103. range: [start, index]
  2104. };
  2105. }
  2106. if (ch1 === '.') {
  2107. ++index;
  2108. return {
  2109. type: Token.Punctuator,
  2110. value: ch1,
  2111. lineNumber: lineNumber,
  2112. lineStart: lineStart,
  2113. range: [start, index]
  2114. };
  2115. }
  2116. throwError({}, Messages.UnexpectedToken, 'ILLEGAL');
  2117. }
  2118. // 7.8.3 Numeric Literals
  2119. function scanHexLiteral(start) {
  2120. var number = '';
  2121. while (index < length) {
  2122. if (!isHexDigit(source[index])) {
  2123. break;
  2124. }
  2125. number += source[index++];
  2126. }
  2127. if (number.length === 0) {
  2128. throwError({}, Messages.UnexpectedToken, 'ILLEGAL');
  2129. }
  2130. if (isIdentifierStart(source.charCodeAt(index))) {
  2131. throwError({}, Messages.UnexpectedToken, 'ILLEGAL');
  2132. }
  2133. return {
  2134. type: Token.NumericLiteral,
  2135. value: parseInt('0x' + number, 16),
  2136. lineNumber: lineNumber,
  2137. lineStart: lineStart,
  2138. range: [start, index]
  2139. };
  2140. }
  2141. function scanOctalLiteral(prefix, start) {
  2142. var number, octal;
  2143. if (isOctalDigit(prefix)) {
  2144. octal = true;
  2145. number = '0' + source[index++];
  2146. } else {
  2147. octal = false;
  2148. ++index;
  2149. number = '';
  2150. }
  2151. while (index < length) {
  2152. if (!isOctalDigit(source[index])) {
  2153. break;
  2154. }
  2155. number += source[index++];
  2156. }
  2157. if (!octal && number.length === 0) {
  2158. // only 0o or 0O
  2159. throwError({}, Messages.UnexpectedToken, 'ILLEGAL');
  2160. }
  2161. if (isIdentifierStart(source.charCodeAt(index)) || isDecimalDigit(source.charCodeAt(index))) {
  2162. throwError({}, Messages.UnexpectedToken, 'ILLEGAL');
  2163. }
  2164. return {
  2165. type: Token.NumericLiteral,
  2166. value: parseInt(number, 8),
  2167. octal: octal,
  2168. lineNumber: lineNumber,
  2169. lineStart: lineStart,
  2170. range: [start, index]
  2171. };
  2172. }
  2173. function scanNumericLiteral() {
  2174. var number, start, ch, octal;
  2175. ch = source[index];
  2176. assert(isDecimalDigit(ch.charCodeAt(0)) || (ch === '.'),
  2177. 'Numeric literal must start with a decimal digit or a decimal point');
  2178. start = index;
  2179. number = '';
  2180. if (ch !== '.') {
  2181. number = source[index++];
  2182. ch = source[index];
  2183. // Hex number starts with '0x'.
  2184. // Octal number starts with '0'.
  2185. // Octal number in ES6 starts with '0o'.
  2186. // Binary number in ES6 starts with '0b'.
  2187. if (number === '0') {
  2188. if (ch === 'x' || ch === 'X') {
  2189. ++index;
  2190. return scanHexLiteral(start);
  2191. }
  2192. if (ch === 'b' || ch === 'B') {
  2193. ++index;
  2194. number = '';
  2195. while (index < length) {
  2196. ch = source[index];
  2197. if (ch !== '0' && ch !== '1') {
  2198. break;
  2199. }
  2200. number += source[index++];
  2201. }
  2202. if (number.length === 0) {
  2203. // only 0b or 0B
  2204. throwError({}, Messages.UnexpectedToken, 'ILLEGAL');
  2205. }
  2206. if (index < length) {
  2207. ch = source.charCodeAt(index);
  2208. if (isIdentifierStart(ch) || isDecimalDigit(ch)) {
  2209. throwError({}, Messages.UnexpectedToken, 'ILLEGAL');
  2210. }
  2211. }
  2212. return {
  2213. type: Token.NumericLiteral,
  2214. value: parseInt(number, 2),
  2215. lineNumber: lineNumber,
  2216. lineStart: lineStart,
  2217. range: [start, index]
  2218. };
  2219. }
  2220. if (ch === 'o' || ch === 'O' || isOctalDigit(ch)) {
  2221. return scanOctalLiteral(ch, start);
  2222. }
  2223. // decimal number starts with '0' such as '09' is illegal.
  2224. if (ch && isDecimalDigit(ch.charCodeAt(0))) {
  2225. throwError({}, Messages.UnexpectedToken, 'ILLEGAL');
  2226. }
  2227. }
  2228. while (isDecimalDigit(source.charCodeAt(index))) {
  2229. number += source[index++];
  2230. }
  2231. ch = source[index];
  2232. }
  2233. if (ch === '.') {
  2234. number += source[index++];
  2235. while (isDecimalDigit(source.charCodeAt(index))) {
  2236. number += source[index++];
  2237. }
  2238. ch = source[index];
  2239. }
  2240. if (ch === 'e' || ch === 'E') {
  2241. number += source[index++];
  2242. ch = source[index];
  2243. if (ch === '+' || ch === '-') {
  2244. number += source[index++];
  2245. }
  2246. if (isDecimalDigit(source.charCodeAt(index))) {
  2247. while (isDecimalDigit(source.charCodeAt(index))) {
  2248. number += source[index++];
  2249. }
  2250. } else {
  2251. throwError({}, Messages.UnexpectedToken, 'ILLEGAL');
  2252. }
  2253. }
  2254. if (isIdentifierStart(source.charCodeAt(index))) {
  2255. throwError({}, Messages.UnexpectedToken, 'ILLEGAL');
  2256. }
  2257. return {
  2258. type: Token.NumericLiteral,
  2259. value: parseFloat(number),
  2260. lineNumber: lineNumber,
  2261. lineStart: lineStart,
  2262. range: [start, index]
  2263. };
  2264. }
  2265. // 7.8.4 String Literals
  2266. function scanStringLiteral() {
  2267. var str = '', quote, start, ch, code, unescaped, restore, octal = false;
  2268. quote = source[index];
  2269. assert((quote === '\'' || quote === '"'),
  2270. 'String literal must starts with a quote');
  2271. start = index;
  2272. ++index;
  2273. while (index < length) {
  2274. ch = source[index++];
  2275. if (ch === quote) {
  2276. quote = '';
  2277. break;
  2278. } else if (ch === '\\') {
  2279. ch = source[index++];
  2280. if (!ch || !isLineTerminator(ch.charCodeAt(0))) {
  2281. switch (ch) {
  2282. case 'n':
  2283. str += '\n';
  2284. break;
  2285. case 'r':
  2286. str += '\r';
  2287. break;
  2288. case 't':
  2289. str += '\t';
  2290. break;
  2291. case 'u':
  2292. case 'x':
  2293. if (source[index] === '{') {
  2294. ++index;
  2295. str += scanUnicodeCodePointEscape();
  2296. } else {
  2297. restore = index;
  2298. unescaped = scanHexEscape(ch);
  2299. if (unescaped) {
  2300. str += unescaped;
  2301. } else {
  2302. index = restore;
  2303. str += ch;
  2304. }
  2305. }
  2306. break;
  2307. case 'b':
  2308. str += '\b';
  2309. break;
  2310. case 'f':
  2311. str += '\f';
  2312. break;
  2313. case 'v':
  2314. str += '\x0B';
  2315. break;
  2316. default:
  2317. if (isOctalDigit(ch)) {
  2318. code = '01234567'.indexOf(ch);
  2319. // \0 is not octal escape sequence
  2320. if (code !== 0) {
  2321. octal = true;
  2322. }
  2323. if (index < length && isOctalDigit(source[index])) {
  2324. octal = true;
  2325. code = code * 8 + '01234567'.indexOf(source[index++]);
  2326. // 3 digits are only allowed when string starts
  2327. // with 0, 1, 2, 3
  2328. if ('0123'.indexOf(ch) >= 0 &&
  2329. index < length &&
  2330. isOctalDigit(source[index])) {
  2331. code = code * 8 + '01234567'.indexOf(source[index++]);
  2332. }
  2333. }
  2334. str += String.fromCharCode(code);
  2335. } else {
  2336. str += ch;
  2337. }
  2338. break;
  2339. }
  2340. } else {
  2341. ++lineNumber;
  2342. if (ch === '\r' && source[index] === '\n') {
  2343. ++index;
  2344. }
  2345. }
  2346. } else if (isLineTerminator(ch.charCodeAt(0))) {
  2347. break;
  2348. } else {
  2349. str += ch;
  2350. }
  2351. }
  2352. if (quote !== '') {
  2353. throwError({}, Messages.UnexpectedToken, 'ILLEGAL');
  2354. }
  2355. return {
  2356. type: Token.StringLiteral,
  2357. value: str,
  2358. octal: octal,
  2359. lineNumber: lineNumber,
  2360. lineStart: lineStart,
  2361. range: [start, index]
  2362. };
  2363. }
  2364. function scanTemplate() {
  2365. var cooked = '', ch, start, terminated, tail, restore, unescaped, code, octal;
  2366. terminated = false;
  2367. tail = false;
  2368. start = index;
  2369. ++index;
  2370. while (index < length) {
  2371. ch = source[index++];
  2372. if (ch === '`') {
  2373. tail = true;
  2374. terminated = true;
  2375. break;
  2376. } else if (ch === '$') {
  2377. if (source[index] === '{') {
  2378. ++index;
  2379. terminated = true;
  2380. break;
  2381. }
  2382. cooked += ch;
  2383. } else if (ch === '\\') {
  2384. ch = source[index++];
  2385. if (!isLineTerminator(ch.charCodeAt(0))) {
  2386. switch (ch) {
  2387. case 'n':
  2388. cooked += '\n';
  2389. break;
  2390. case 'r':
  2391. cooked += '\r';
  2392. break;
  2393. case 't':
  2394. cooked += '\t';
  2395. break;
  2396. case 'u':
  2397. case 'x':
  2398. if (source[index] === '{') {
  2399. ++index;
  2400. cooked += scanUnicodeCodePointEscape();
  2401. } else {
  2402. restore = index;
  2403. unescaped = scanHexEscape(ch);
  2404. if (unescaped) {
  2405. cooked += unescaped;
  2406. } else {
  2407. index = restore;
  2408. cooked += ch;
  2409. }
  2410. }
  2411. break;
  2412. case 'b':
  2413. cooked += '\b';
  2414. break;
  2415. case 'f':
  2416. cooked += '\f';
  2417. break;
  2418. case 'v':
  2419. cooked += '\v';
  2420. break;
  2421. default:
  2422. if (isOctalDigit(ch)) {
  2423. code = '01234567'.indexOf(ch);
  2424. // \0 is not octal escape sequence
  2425. if (code !== 0) {
  2426. octal = true;
  2427. }
  2428. if (index < length && isOctalDigit(source[index])) {
  2429. octal = true;
  2430. code = code * 8 + '01234567'.indexOf(source[index++]);
  2431. // 3 digits are only allowed when string starts
  2432. // with 0, 1, 2, 3
  2433. if ('0123'.indexOf(ch) >= 0 &&
  2434. index < length &&
  2435. isOctalDigit(source[index])) {
  2436. code = code * 8 + '01234567'.indexOf(source[index++]);
  2437. }
  2438. }
  2439. cooked += String.fromCharCode(code);
  2440. } else {
  2441. cooked += ch;
  2442. }
  2443. break;
  2444. }
  2445. } else {
  2446. ++lineNumber;
  2447. if (ch === '\r' && source[index] === '\n') {
  2448. ++index;
  2449. }
  2450. }
  2451. } else if (isLineTerminator(ch.charCodeAt(0))) {
  2452. ++lineNumber;
  2453. if (ch === '\r' && source[index] === '\n') {
  2454. ++index;
  2455. }
  2456. cooked += '\n';
  2457. } else {
  2458. cooked += ch;
  2459. }
  2460. }
  2461. if (!terminated) {
  2462. throwError({}, Messages.UnexpectedToken, 'ILLEGAL');
  2463. }
  2464. return {
  2465. type: Token.Template,
  2466. value: {
  2467. cooked: cooked,
  2468. raw: source.slice(start + 1, index - ((tail) ? 1 : 2))
  2469. },
  2470. tail: tail,
  2471. octal: octal,
  2472. lineNumber: lineNumber,
  2473. lineStart: lineStart,
  2474. range: [start, index]
  2475. };
  2476. }
  2477. function scanTemplateElement(option) {
  2478. var startsWith, template;
  2479. lookahead = null;
  2480. skipComment();
  2481. startsWith = (option.head) ? '`' : '}';
  2482. if (source[index] !== startsWith) {
  2483. throwError({}, Messages.UnexpectedToken, 'ILLEGAL');
  2484. }
  2485. template = scanTemplate();
  2486. peek();
  2487. return template;
  2488. }
  2489. function scanRegExp() {
  2490. var str, ch, start, pattern, flags, value, classMarker = false, restore, terminated = false;
  2491. lookahead = null;
  2492. skipComment();
  2493. start = index;
  2494. ch = source[index];
  2495. assert(ch === '/', 'Regular expression literal must start with a slash');
  2496. str = source[index++];
  2497. while (index < length) {
  2498. ch = source[index++];
  2499. str += ch;
  2500. if (classMarker) {
  2501. if (ch === ']') {
  2502. classMarker = false;
  2503. }
  2504. } else {
  2505. if (ch === '\\') {
  2506. ch = source[index++];
  2507. // ECMA-262 7.8.5
  2508. if (isLineTerminator(ch.charCodeAt(0))) {
  2509. throwError({}, Messages.UnterminatedRegExp);
  2510. }
  2511. str += ch;
  2512. } else if (ch === '/') {
  2513. terminated = true;
  2514. break;
  2515. } else if (ch === '[') {
  2516. classMarker = true;
  2517. } else if (isLineTerminator(ch.charCodeAt(0))) {
  2518. throwError({}, Messages.UnterminatedRegExp);
  2519. }
  2520. }
  2521. }
  2522. if (!terminated) {
  2523. throwError({}, Messages.UnterminatedRegExp);
  2524. }
  2525. // Exclude leading and trailing slash.
  2526. pattern = str.substr(1, str.length - 2);
  2527. flags = '';
  2528. while (index < length) {
  2529. ch = source[index];
  2530. if (!isIdentifierPart(ch.charCodeAt(0))) {
  2531. break;
  2532. }
  2533. ++index;
  2534. if (ch === '\\' && index < length) {
  2535. ch = source[index];
  2536. if (ch === 'u') {
  2537. ++index;
  2538. restore = index;
  2539. ch = scanHexEscape('u');
  2540. if (ch) {
  2541. flags += ch;
  2542. for (str += '\\u'; restore < index; ++restore) {
  2543. str += source[restore];
  2544. }
  2545. } else {
  2546. index = restore;
  2547. flags += 'u';
  2548. str += '\\u';
  2549. }
  2550. } else {
  2551. str += '\\';
  2552. }
  2553. } else {
  2554. flags += ch;
  2555. str += ch;
  2556. }
  2557. }
  2558. try {
  2559. value = new RegExp(pattern, flags);
  2560. } catch (e) {
  2561. throwError({}, Messages.InvalidRegExp);
  2562. }
  2563. peek();
  2564. if (extra.tokenize) {
  2565. return {
  2566. type: Token.RegularExpression,
  2567. value: value,
  2568. lineNumber: lineNumber,
  2569. lineStart: lineStart,
  2570. range: [start, index]
  2571. };
  2572. }
  2573. return {
  2574. literal: str,
  2575. value: value,
  2576. range: [start, index]
  2577. };
  2578. }
  2579. function isIdentifierName(token) {
  2580. return token.type === Token.Identifier ||
  2581. token.type === Token.Keyword ||
  2582. token.type === Token.BooleanLiteral ||
  2583. token.type === Token.NullLiteral;
  2584. }
  2585. function advanceSlash() {
  2586. var prevToken,
  2587. checkToken;
  2588. // Using the following algorithm:
  2589. // https://github.com/mozilla/sweet.js/wiki/design
  2590. prevToken = extra.tokens[extra.tokens.length - 1];
  2591. if (!prevToken) {
  2592. // Nothing before that: it cannot be a division.
  2593. return scanRegExp();
  2594. }
  2595. if (prevToken.type === 'Punctuator') {
  2596. if (prevToken.value === ')') {
  2597. checkToken = extra.tokens[extra.openParenToken - 1];
  2598. if (checkToken &&
  2599. checkToken.type === 'Keyword' &&
  2600. (checkToken.value === 'if' ||
  2601. checkToken.value === 'while' ||
  2602. checkToken.value === 'for' ||
  2603. checkToken.value === 'with')) {
  2604. return scanRegExp();
  2605. }
  2606. return scanPunctuator();
  2607. }
  2608. if (prevToken.value === '}') {
  2609. // Dividing a function by anything makes little sense,
  2610. // but we have to check for that.
  2611. if (extra.tokens[extra.openCurlyToken - 3] &&
  2612. extra.tokens[extra.openCurlyToken - 3].type === 'Keyword') {
  2613. // Anonymous function.
  2614. checkToken = extra.tokens[extra.openCurlyToken - 4];
  2615. if (!checkToken) {
  2616. return scanPunctuator();
  2617. }
  2618. } else if (extra.tokens[extra.openCurlyToken - 4] &&
  2619. extra.tokens[extra.openCurlyToken - 4].type === 'Keyword') {
  2620. // Named function.
  2621. checkToken = extra.tokens[extra.openCurlyToken - 5];
  2622. if (!checkToken) {
  2623. return scanRegExp();
  2624. }
  2625. } else {
  2626. return scanPunctuator();
  2627. }
  2628. // checkToken determines whether the function is
  2629. // a declaration or an expression.
  2630. if (FnExprTokens.indexOf(checkToken.value) >= 0) {
  2631. // It is an expression.
  2632. return scanPunctuator();
  2633. }
  2634. // It is a declaration.
  2635. return scanRegExp();
  2636. }
  2637. return scanRegExp();
  2638. }
  2639. if (prevToken.type === 'Keyword') {
  2640. return scanRegExp();
  2641. }
  2642. return scanPunctuator();
  2643. }
  2644. function advance() {
  2645. var ch;
  2646. if (!state.inXJSChild) {
  2647. skipComment();
  2648. }
  2649. if (index >= length) {
  2650. return {
  2651. type: Token.EOF,
  2652. lineNumber: lineNumber,
  2653. lineStart: lineStart,
  2654. range: [index, index]
  2655. };
  2656. }
  2657. if (state.inXJSChild) {
  2658. return advanceXJSChild();
  2659. }
  2660. ch = source.charCodeAt(index);
  2661. // Very common: ( and ) and ;
  2662. if (ch === 40 || ch === 41 || ch === 58) {
  2663. return scanPunctuator();
  2664. }
  2665. // String literal starts with single quote (#39) or double quote (#34).
  2666. if (ch === 39 || ch === 34) {
  2667. if (state.inXJSTag) {
  2668. return scanXJSStringLiteral();
  2669. }
  2670. return scanStringLiteral();
  2671. }
  2672. if (state.inXJSTag && isXJSIdentifierStart(ch)) {
  2673. return scanXJSIdentifier();
  2674. }
  2675. if (ch === 96) {
  2676. return scanTemplate();
  2677. }
  2678. if (isIdentifierStart(ch)) {
  2679. return scanIdentifier();
  2680. }
  2681. // Dot (.) char #46 can also start a floating-point number, hence the need
  2682. // to check the next character.
  2683. if (ch === 46) {
  2684. if (isDecimalDigit(source.charCodeAt(index + 1))) {
  2685. return scanNumericLiteral();
  2686. }
  2687. return scanPunctuator();
  2688. }
  2689. if (isDecimalDigit(ch)) {
  2690. return scanNumericLiteral();
  2691. }
  2692. // Slash (/) char #47 can also start a regex.
  2693. if (extra.tokenize && ch === 47) {
  2694. return advanceSlash();
  2695. }
  2696. return scanPunctuator();
  2697. }
  2698. function lex() {
  2699. var token;
  2700. token = lookahead;
  2701. index = token.range[1];
  2702. lineNumber = token.lineNumber;
  2703. lineStart = token.lineStart;
  2704. lookahead = advance();
  2705. index = token.range[1];
  2706. lineNumber = token.lineNumber;
  2707. lineStart = token.lineStart;
  2708. return token;
  2709. }
  2710. function peek() {
  2711. var pos, line, start;
  2712. pos = index;
  2713. line = lineNumber;
  2714. start = lineStart;
  2715. lookahead = advance();
  2716. index = pos;
  2717. lineNumber = line;
  2718. lineStart = start;
  2719. }
  2720. function lookahead2() {
  2721. var adv, pos, line, start, result;
  2722. // If we are collecting the tokens, don't grab the next one yet.
  2723. adv = (typeof extra.advance === 'function') ? extra.advance : advance;
  2724. pos = index;
  2725. line = lineNumber;
  2726. start = lineStart;
  2727. // Scan for the next immediate token.
  2728. if (lookahead === null) {
  2729. lookahead = adv();
  2730. }
  2731. index = lookahead.range[1];
  2732. lineNumber = lookahead.lineNumber;
  2733. lineStart = lookahead.lineStart;
  2734. // Grab the token right after.
  2735. result = adv();
  2736. index = pos;
  2737. lineNumber = line;
  2738. lineStart = start;
  2739. return result;
  2740. }
  2741. SyntaxTreeDelegate = {
  2742. name: 'SyntaxTree',
  2743. postProcess: function (node) {
  2744. return node;
  2745. },
  2746. createArrayExpression: function (elements) {
  2747. return {
  2748. type: Syntax.ArrayExpression,
  2749. elements: elements
  2750. };
  2751. },
  2752. createAssignmentExpression: function (operator, left, right) {
  2753. return {
  2754. type: Syntax.AssignmentExpression,
  2755. operator: operator,
  2756. left: left,
  2757. right: right
  2758. };
  2759. },
  2760. createBinaryExpression: function (operator, left, right) {
  2761. var type = (operator === '||' || operator === '&&') ? Syntax.LogicalExpression :
  2762. Syntax.BinaryExpression;
  2763. return {
  2764. type: type,
  2765. operator: operator,
  2766. left: left,
  2767. right: right
  2768. };
  2769. },
  2770. createBlockStatement: function (body) {
  2771. return {
  2772. type: Syntax.BlockStatement,
  2773. body: body
  2774. };
  2775. },
  2776. createBreakStatement: function (label) {
  2777. return {
  2778. type: Syntax.BreakStatement,
  2779. label: label
  2780. };
  2781. },
  2782. createCallExpression: function (callee, args) {
  2783. return {
  2784. type: Syntax.CallExpression,
  2785. callee: callee,
  2786. 'arguments': args
  2787. };
  2788. },
  2789. createCatchClause: function (param, body) {
  2790. return {
  2791. type: Syntax.CatchClause,
  2792. param: param,
  2793. body: body
  2794. };
  2795. },
  2796. createConditionalExpression: function (test, consequent, alternate) {
  2797. return {
  2798. type: Syntax.ConditionalExpression,
  2799. test: test,
  2800. consequent: consequent,
  2801. alternate: alternate
  2802. };
  2803. },
  2804. createContinueStatement: function (label) {
  2805. return {
  2806. type: Syntax.ContinueStatement,
  2807. label: label
  2808. };
  2809. },
  2810. createDebuggerStatement: function () {
  2811. return {
  2812. type: Syntax.DebuggerStatement
  2813. };
  2814. },
  2815. createDoWhileStatement: function (body, test) {
  2816. return {
  2817. type: Syntax.DoWhileStatement,
  2818. body: body,
  2819. test: test
  2820. };
  2821. },
  2822. createEmptyStatement: function () {
  2823. return {
  2824. type: Syntax.EmptyStatement
  2825. };
  2826. },
  2827. createExpressionStatement: function (expression) {
  2828. return {
  2829. type: Syntax.ExpressionStatement,
  2830. expression: expression
  2831. };
  2832. },
  2833. createForStatement: function (init, test, update, body) {
  2834. return {
  2835. type: Syntax.ForStatement,
  2836. init: init,
  2837. test: test,
  2838. update: update,
  2839. body: body
  2840. };
  2841. },
  2842. createForInStatement: function (left, right, body) {
  2843. return {
  2844. type: Syntax.ForInStatement,
  2845. left: left,
  2846. right: right,
  2847. body: body,
  2848. each: false
  2849. };
  2850. },
  2851. createForOfStatement: function (left, right, body) {
  2852. return {
  2853. type: Syntax.ForOfStatement,
  2854. left: left,
  2855. right: right,
  2856. body: body
  2857. };
  2858. },
  2859. createFunctionDeclaration: function (id, params, defaults, body, rest, generator, expression,
  2860. returnType) {
  2861. return {
  2862. type: Syntax.FunctionDeclaration,
  2863. id: id,
  2864. params: params,
  2865. defaults: defaults,
  2866. body: body,
  2867. rest: rest,
  2868. generator: generator,
  2869. expression: expression,
  2870. returnType: returnType
  2871. };
  2872. },
  2873. createFunctionExpression: function (id, params, defaults, body, rest, generator, expression,
  2874. returnType) {
  2875. return {
  2876. type: Syntax.FunctionExpression,
  2877. id: id,
  2878. params: params,
  2879. defaults: defaults,
  2880. body: body,
  2881. rest: rest,
  2882. generator: generator,
  2883. expression: expression,
  2884. returnType: returnType
  2885. };
  2886. },
  2887. createIdentifier: function (name) {
  2888. return {
  2889. type: Syntax.Identifier,
  2890. name: name,
  2891. // Only here to initialize the shape of the object to ensure
  2892. // that the 'typeAnnotation' key is ordered before others that
  2893. // are added later (like 'loc' and 'range'). This just helps
  2894. // keep the shape of Identifier nodes consistent with everything
  2895. // else.
  2896. typeAnnotation: undefined
  2897. };
  2898. },
  2899. createTypeAnnotation: function (typeIdentifier, paramTypes, returnType, nullable) {
  2900. return {
  2901. type: Syntax.TypeAnnotation,
  2902. id: typeIdentifier,
  2903. paramTypes: paramTypes,
  2904. returnType: returnType,
  2905. nullable: nullable
  2906. };
  2907. },
  2908. createTypeAnnotatedIdentifier: function (identifier, annotation) {
  2909. return {
  2910. type: Syntax.TypeAnnotatedIdentifier,
  2911. id: identifier,
  2912. annotation: annotation
  2913. };
  2914. },
  2915. createXJSAttribute: function (name, value) {
  2916. return {
  2917. type: Syntax.XJSAttribute,
  2918. name: name,
  2919. value: value
  2920. };
  2921. },
  2922. createXJSIdentifier: function (name, namespace) {
  2923. return {
  2924. type: Syntax.XJSIdentifier,
  2925. name: name,
  2926. namespace: namespace
  2927. };
  2928. },
  2929. createXJSElement: function (openingElement, closingElement, children) {
  2930. return {
  2931. type: Syntax.XJSElement,
  2932. openingElement: openingElement,
  2933. closingElement: closingElement,
  2934. children: children
  2935. };
  2936. },
  2937. createXJSEmptyExpression: function () {
  2938. return {
  2939. type: Syntax.XJSEmptyExpression
  2940. };
  2941. },
  2942. createXJSExpressionContainer: function (expression) {
  2943. return {
  2944. type: Syntax.XJSExpressionContainer,
  2945. expression: expression
  2946. };
  2947. },
  2948. createXJSOpeningElement: function (name, attributes, selfClosing) {
  2949. return {
  2950. type: Syntax.XJSOpeningElement,
  2951. name: name,
  2952. selfClosing: selfClosing,
  2953. attributes: attributes
  2954. };
  2955. },
  2956. createXJSClosingElement: function (name) {
  2957. return {
  2958. type: Syntax.XJSClosingElement,
  2959. name: name
  2960. };
  2961. },
  2962. createIfStatement: function (test, consequent, alternate) {
  2963. return {
  2964. type: Syntax.IfStatement,
  2965. test: test,
  2966. consequent: consequent,
  2967. alternate: alternate
  2968. };
  2969. },
  2970. createLabeledStatement: function (label, body) {
  2971. return {
  2972. type: Syntax.LabeledStatement,
  2973. label: label,
  2974. body: body
  2975. };
  2976. },
  2977. createLiteral: function (token) {
  2978. return {
  2979. type: Syntax.Literal,
  2980. value: token.value,
  2981. raw: source.slice(token.range[0], token.range[1])
  2982. };
  2983. },
  2984. createMemberExpression: function (accessor, object, property) {
  2985. return {
  2986. type: Syntax.MemberExpression,
  2987. computed: accessor === '[',
  2988. object: object,
  2989. property: property
  2990. };
  2991. },
  2992. createNewExpression: function (callee, args) {
  2993. return {
  2994. type: Syntax.NewExpression,
  2995. callee: callee,
  2996. 'arguments': args
  2997. };
  2998. },
  2999. createObjectExpression: function (properties) {
  3000. return {
  3001. type: Syntax.ObjectExpression,
  3002. properties: properties
  3003. };
  3004. },
  3005. createPostfixExpression: function (operator, argument) {
  3006. return {
  3007. type: Syntax.UpdateExpression,
  3008. operator: operator,
  3009. argument: argument,
  3010. prefix: false
  3011. };
  3012. },
  3013. createProgram: function (body) {
  3014. return {
  3015. type: Syntax.Program,
  3016. body: body
  3017. };
  3018. },
  3019. createProperty: function (kind, key, value, method, shorthand) {
  3020. return {
  3021. type: Syntax.Property,
  3022. key: key,
  3023. value: value,
  3024. kind: kind,
  3025. method: method,
  3026. shorthand: shorthand
  3027. };
  3028. },
  3029. createReturnStatement: function (argument) {
  3030. return {
  3031. type: Syntax.ReturnStatement,
  3032. argument: argument
  3033. };
  3034. },
  3035. createSequenceExpression: function (expressions) {
  3036. return {
  3037. type: Syntax.SequenceExpression,
  3038. expressions: expressions
  3039. };
  3040. },
  3041. createSwitchCase: function (test, consequent) {
  3042. return {
  3043. type: Syntax.SwitchCase,
  3044. test: test,
  3045. consequent: consequent
  3046. };
  3047. },
  3048. createSwitchStatement: function (discriminant, cases) {
  3049. return {
  3050. type: Syntax.SwitchStatement,
  3051. discriminant: discriminant,
  3052. cases: cases
  3053. };
  3054. },
  3055. createThisExpression: function () {
  3056. return {
  3057. type: Syntax.ThisExpression
  3058. };
  3059. },
  3060. createThrowStatement: function (argument) {
  3061. return {
  3062. type: Syntax.ThrowStatement,
  3063. argument: argument
  3064. };
  3065. },
  3066. createTryStatement: function (block, guardedHandlers, handlers, finalizer) {
  3067. return {
  3068. type: Syntax.TryStatement,
  3069. block: block,
  3070. guardedHandlers: guardedHandlers,
  3071. handlers: handlers,
  3072. finalizer: finalizer
  3073. };
  3074. },
  3075. createUnaryExpression: function (operator, argument) {
  3076. if (operator === '++' || operator === '--') {
  3077. return {
  3078. type: Syntax.UpdateExpression,
  3079. operator: operator,
  3080. argument: argument,
  3081. prefix: true
  3082. };
  3083. }
  3084. return {
  3085. type: Syntax.UnaryExpression,
  3086. operator: operator,
  3087. argument: argument
  3088. };
  3089. },
  3090. createVariableDeclaration: function (declarations, kind) {
  3091. return {
  3092. type: Syntax.VariableDeclaration,
  3093. declarations: declarations,
  3094. kind: kind
  3095. };
  3096. },
  3097. createVariableDeclarator: function (id, init) {
  3098. return {
  3099. type: Syntax.VariableDeclarator,
  3100. id: id,
  3101. init: init
  3102. };
  3103. },
  3104. createWhileStatement: function (test, body) {
  3105. return {
  3106. type: Syntax.WhileStatement,
  3107. test: test,
  3108. body: body
  3109. };
  3110. },
  3111. createWithStatement: function (object, body) {
  3112. return {
  3113. type: Syntax.WithStatement,
  3114. object: object,
  3115. body: body
  3116. };
  3117. },
  3118. createTemplateElement: function (value, tail) {
  3119. return {
  3120. type: Syntax.TemplateElement,
  3121. value: value,
  3122. tail: tail
  3123. };
  3124. },
  3125. createTemplateLiteral: function (quasis, expressions) {
  3126. return {
  3127. type: Syntax.TemplateLiteral,
  3128. quasis: quasis,
  3129. expressions: expressions
  3130. };
  3131. },
  3132. createSpreadElement: function (argument) {
  3133. return {
  3134. type: Syntax.SpreadElement,
  3135. argument: argument
  3136. };
  3137. },
  3138. createTaggedTemplateExpression: function (tag, quasi) {
  3139. return {
  3140. type: Syntax.TaggedTemplateExpression,
  3141. tag: tag,
  3142. quasi: quasi
  3143. };
  3144. },
  3145. createArrowFunctionExpression: function (params, defaults, body, rest, expression) {
  3146. return {
  3147. type: Syntax.ArrowFunctionExpression,
  3148. id: null,
  3149. params: params,
  3150. defaults: defaults,
  3151. body: body,
  3152. rest: rest,
  3153. generator: false,
  3154. expression: expression
  3155. };
  3156. },
  3157. createMethodDefinition: function (propertyType, kind, key, value) {
  3158. return {
  3159. type: Syntax.MethodDefinition,
  3160. key: key,
  3161. value: value,
  3162. kind: kind,
  3163. 'static': propertyType === ClassPropertyType["static"]
  3164. };
  3165. },
  3166. createClassBody: function (body) {
  3167. return {
  3168. type: Syntax.ClassBody,
  3169. body: body
  3170. };
  3171. },
  3172. createClassExpression: function (id, superClass, body) {
  3173. return {
  3174. type: Syntax.ClassExpression,
  3175. id: id,
  3176. superClass: superClass,
  3177. body: body
  3178. };
  3179. },
  3180. createClassDeclaration: function (id, superClass, body) {
  3181. return {
  3182. type: Syntax.ClassDeclaration,
  3183. id: id,
  3184. superClass: superClass,
  3185. body: body
  3186. };
  3187. },
  3188. createExportSpecifier: function (id, name) {
  3189. return {
  3190. type: Syntax.ExportSpecifier,
  3191. id: id,
  3192. name: name
  3193. };
  3194. },
  3195. createExportBatchSpecifier: function () {
  3196. return {
  3197. type: Syntax.ExportBatchSpecifier
  3198. };
  3199. },
  3200. createExportDeclaration: function (declaration, specifiers, source) {
  3201. return {
  3202. type: Syntax.ExportDeclaration,
  3203. declaration: declaration,
  3204. specifiers: specifiers,
  3205. source: source
  3206. };
  3207. },
  3208. createImportSpecifier: function (id, name) {
  3209. return {
  3210. type: Syntax.ImportSpecifier,
  3211. id: id,
  3212. name: name
  3213. };
  3214. },
  3215. createImportDeclaration: function (specifiers, kind, source) {
  3216. return {
  3217. type: Syntax.ImportDeclaration,
  3218. specifiers: specifiers,
  3219. kind: kind,
  3220. source: source
  3221. };
  3222. },
  3223. createYieldExpression: function (argument, delegate) {
  3224. return {
  3225. type: Syntax.YieldExpression,
  3226. argument: argument,
  3227. delegate: delegate
  3228. };
  3229. },
  3230. createModuleDeclaration: function (id, source, body) {
  3231. return {
  3232. type: Syntax.ModuleDeclaration,
  3233. id: id,
  3234. source: source,
  3235. body: body
  3236. };
  3237. }
  3238. };
  3239. // Return true if there is a line terminator before the next token.
  3240. function peekLineTerminator() {
  3241. var pos, line, start, found;
  3242. pos = index;
  3243. line = lineNumber;
  3244. start = lineStart;
  3245. skipComment();
  3246. found = lineNumber !== line;
  3247. index = pos;
  3248. lineNumber = line;
  3249. lineStart = start;
  3250. return found;
  3251. }
  3252. // Throw an exception
  3253. function throwError(token, messageFormat) {
  3254. var error,
  3255. args = Array.prototype.slice.call(arguments, 2),
  3256. msg = messageFormat.replace(
  3257. /%(\d)/g,
  3258. function (whole, index) {
  3259. assert(index < args.length, 'Message reference must be in range');
  3260. return args[index];
  3261. }
  3262. );
  3263. if (typeof token.lineNumber === 'number') {
  3264. error = new Error('Line ' + token.lineNumber + ': ' + msg);
  3265. error.index = token.range[0];
  3266. error.lineNumber = token.lineNumber;
  3267. error.column = token.range[0] - lineStart + 1;
  3268. } else {
  3269. error = new Error('Line ' + lineNumber + ': ' + msg);
  3270. error.index = index;
  3271. error.lineNumber = lineNumber;
  3272. error.column = index - lineStart + 1;
  3273. }
  3274. error.description = msg;
  3275. throw error;
  3276. }
  3277. function throwErrorTolerant() {
  3278. try {
  3279. throwError.apply(null, arguments);
  3280. } catch (e) {
  3281. if (extra.errors) {
  3282. extra.errors.push(e);
  3283. } else {
  3284. throw e;
  3285. }
  3286. }
  3287. }
  3288. // Throw an exception because of the token.
  3289. function throwUnexpected(token) {
  3290. if (token.type === Token.EOF) {
  3291. throwError(token, Messages.UnexpectedEOS);
  3292. }
  3293. if (token.type === Token.NumericLiteral) {
  3294. throwError(token, Messages.UnexpectedNumber);
  3295. }
  3296. if (token.type === Token.StringLiteral || token.type === Token.XJSText) {
  3297. throwError(token, Messages.UnexpectedString);
  3298. }
  3299. if (token.type === Token.Identifier) {
  3300. throwError(token, Messages.UnexpectedIdentifier);
  3301. }
  3302. if (token.type === Token.Keyword) {
  3303. if (isFutureReservedWord(token.value)) {
  3304. throwError(token, Messages.UnexpectedReserved);
  3305. } else if (strict && isStrictModeReservedWord(token.value)) {
  3306. throwErrorTolerant(token, Messages.StrictReservedWord);
  3307. return;
  3308. }
  3309. throwError(token, Messages.UnexpectedToken, token.value);
  3310. }
  3311. if (token.type === Token.Template) {
  3312. throwError(token, Messages.UnexpectedTemplate, token.value.raw);
  3313. }
  3314. // BooleanLiteral, NullLiteral, or Punctuator.
  3315. throwError(token, Messages.UnexpectedToken, token.value);
  3316. }
  3317. // Expect the next token to match the specified punctuator.
  3318. // If not, an exception will be thrown.
  3319. function expect(value) {
  3320. var token = lex();
  3321. if (token.type !== Token.Punctuator || token.value !== value) {
  3322. throwUnexpected(token);
  3323. }
  3324. }
  3325. // Expect the next token to match the specified keyword.
  3326. // If not, an exception will be thrown.
  3327. function expectKeyword(keyword) {
  3328. var token = lex();
  3329. if (token.type !== Token.Keyword || token.value !== keyword) {
  3330. throwUnexpected(token);
  3331. }
  3332. }
  3333. // Return true if the next token matches the specified punctuator.
  3334. function match(value) {
  3335. return lookahead.type === Token.Punctuator && lookahead.value === value;
  3336. }
  3337. // Return true if the next token matches the specified keyword
  3338. function matchKeyword(keyword) {
  3339. return lookahead.type === Token.Keyword && lookahead.value === keyword;
  3340. }
  3341. // Return true if the next token matches the specified contextual keyword
  3342. function matchContextualKeyword(keyword) {
  3343. return lookahead.type === Token.Identifier && lookahead.value === keyword;
  3344. }
  3345. // Return true if the next token is an assignment operator
  3346. function matchAssign() {
  3347. var op;
  3348. if (lookahead.type !== Token.Punctuator) {
  3349. return false;
  3350. }
  3351. op = lookahead.value;
  3352. return op === '=' ||
  3353. op === '*=' ||
  3354. op === '/=' ||
  3355. op === '%=' ||
  3356. op === '+=' ||
  3357. op === '-=' ||
  3358. op === '<<=' ||
  3359. op === '>>=' ||
  3360. op === '>>>=' ||
  3361. op === '&=' ||
  3362. op === '^=' ||
  3363. op === '|=';
  3364. }
  3365. function consumeSemicolon() {
  3366. var line;
  3367. // Catch the very common case first: immediately a semicolon (char #59).
  3368. if (source.charCodeAt(index) === 59) {
  3369. lex();
  3370. return;
  3371. }
  3372. line = lineNumber;
  3373. skipComment();
  3374. if (lineNumber !== line) {
  3375. return;
  3376. }
  3377. if (match(';')) {
  3378. lex();
  3379. return;
  3380. }
  3381. if (lookahead.type !== Token.EOF && !match('}')) {
  3382. throwUnexpected(lookahead);
  3383. }
  3384. }
  3385. // Return true if provided expression is LeftHandSideExpression
  3386. function isLeftHandSide(expr) {
  3387. return expr.type === Syntax.Identifier || expr.type === Syntax.MemberExpression;
  3388. }
  3389. function isAssignableLeftHandSide(expr) {
  3390. return isLeftHandSide(expr) || expr.type === Syntax.ObjectPattern || expr.type === Syntax.ArrayPattern;
  3391. }
  3392. // 11.1.4 Array Initialiser
  3393. function parseArrayInitialiser() {
  3394. var elements = [], blocks = [], filter = null, tmp, possiblecomprehension = true, body;
  3395. expect('[');
  3396. while (!match(']')) {
  3397. if (lookahead.value === 'for' &&
  3398. lookahead.type === Token.Keyword) {
  3399. if (!possiblecomprehension) {
  3400. throwError({}, Messages.ComprehensionError);
  3401. }
  3402. matchKeyword('for');
  3403. tmp = parseForStatement({ ignoreBody: true });
  3404. tmp.of = tmp.type === Syntax.ForOfStatement;
  3405. tmp.type = Syntax.ComprehensionBlock;
  3406. if (tmp.left.kind) { // can't be let or const
  3407. throwError({}, Messages.ComprehensionError);
  3408. }
  3409. blocks.push(tmp);
  3410. } else if (lookahead.value === 'if' &&
  3411. lookahead.type === Token.Keyword) {
  3412. if (!possiblecomprehension) {
  3413. throwError({}, Messages.ComprehensionError);
  3414. }
  3415. expectKeyword('if');
  3416. expect('(');
  3417. filter = parseExpression();
  3418. expect(')');
  3419. } else if (lookahead.value === ',' &&
  3420. lookahead.type === Token.Punctuator) {
  3421. possiblecomprehension = false; // no longer allowed.
  3422. lex();
  3423. elements.push(null);
  3424. } else {
  3425. tmp = parseSpreadOrAssignmentExpression();
  3426. elements.push(tmp);
  3427. if (tmp && tmp.type === Syntax.SpreadElement) {
  3428. if (!match(']')) {
  3429. throwError({}, Messages.ElementAfterSpreadElement);
  3430. }
  3431. } else if (!(match(']') || matchKeyword('for') || matchKeyword('if'))) {
  3432. expect(','); // this lexes.
  3433. possiblecomprehension = false;
  3434. }
  3435. }
  3436. }
  3437. expect(']');
  3438. if (filter && !blocks.length) {
  3439. throwError({}, Messages.ComprehensionRequiresBlock);
  3440. }
  3441. if (blocks.length) {
  3442. if (elements.length !== 1) {
  3443. throwError({}, Messages.ComprehensionError);
  3444. }
  3445. return {
  3446. type: Syntax.ComprehensionExpression,
  3447. filter: filter,
  3448. blocks: blocks,
  3449. body: elements[0]
  3450. };
  3451. }
  3452. return delegate.createArrayExpression(elements);
  3453. }
  3454. // 11.1.5 Object Initialiser
  3455. function parsePropertyFunction(options) {
  3456. var previousStrict, previousYieldAllowed, params, defaults, body;
  3457. previousStrict = strict;
  3458. previousYieldAllowed = state.yieldAllowed;
  3459. state.yieldAllowed = options.generator;
  3460. params = options.params || [];
  3461. defaults = options.defaults || [];
  3462. body = parseConciseBody();
  3463. if (options.name && strict && isRestrictedWord(params[0].name)) {
  3464. throwErrorTolerant(options.name, Messages.StrictParamName);
  3465. }
  3466. if (state.yieldAllowed && !state.yieldFound) {
  3467. throwErrorTolerant({}, Messages.NoYieldInGenerator);
  3468. }
  3469. strict = previousStrict;
  3470. state.yieldAllowed = previousYieldAllowed;
  3471. return delegate.createFunctionExpression(null, params, defaults, body, options.rest || null, options.generator, body.type !== Syntax.BlockStatement,
  3472. options.returnTypeAnnotation);
  3473. }
  3474. function parsePropertyMethodFunction(options) {
  3475. var previousStrict, tmp, method;
  3476. previousStrict = strict;
  3477. strict = true;
  3478. tmp = parseParams();
  3479. if (tmp.stricted) {
  3480. throwErrorTolerant(tmp.stricted, tmp.message);
  3481. }
  3482. method = parsePropertyFunction({
  3483. params: tmp.params,
  3484. defaults: tmp.defaults,
  3485. rest: tmp.rest,
  3486. generator: options.generator,
  3487. returnTypeAnnotation: tmp.returnTypeAnnotation
  3488. });
  3489. strict = previousStrict;
  3490. return method;
  3491. }
  3492. function parseObjectPropertyKey() {
  3493. var token = lex();
  3494. // Note: This function is called only from parseObjectProperty(), where
  3495. // EOF and Punctuator tokens are already filtered out.
  3496. if (token.type === Token.StringLiteral || token.type === Token.NumericLiteral) {
  3497. if (strict && token.octal) {
  3498. throwErrorTolerant(token, Messages.StrictOctalLiteral);
  3499. }
  3500. return delegate.createLiteral(token);
  3501. }
  3502. return delegate.createIdentifier(token.value);
  3503. }
  3504. function parseObjectProperty() {
  3505. var token, key, id, value, param;
  3506. token = lookahead;
  3507. if (token.type === Token.Identifier) {
  3508. id = parseObjectPropertyKey();
  3509. // Property Assignment: Getter and Setter.
  3510. if (token.value === 'get' && !(match(':') || match('('))) {
  3511. key = parseObjectPropertyKey();
  3512. expect('(');
  3513. expect(')');
  3514. return delegate.createProperty('get', key, parsePropertyFunction({ generator: false }), false, false);
  3515. }
  3516. if (token.value === 'set' && !(match(':') || match('('))) {
  3517. key = parseObjectPropertyKey();
  3518. expect('(');
  3519. token = lookahead;
  3520. param = [parseTypeAnnotatableIdentifier()];
  3521. expect(')');
  3522. return delegate.createProperty('set', key, parsePropertyFunction({ params: param, generator: false, name: token }), false, false);
  3523. }
  3524. if (match(':')) {
  3525. lex();
  3526. return delegate.createProperty('init', id, parseAssignmentExpression(), false, false);
  3527. }
  3528. if (match('(')) {
  3529. return delegate.createProperty('init', id, parsePropertyMethodFunction({ generator: false }), true, false);
  3530. }
  3531. return delegate.createProperty('init', id, id, false, true);
  3532. }
  3533. if (token.type === Token.EOF || token.type === Token.Punctuator) {
  3534. if (!match('*')) {
  3535. throwUnexpected(token);
  3536. }
  3537. lex();
  3538. id = parseObjectPropertyKey();
  3539. if (!match('(')) {
  3540. throwUnexpected(lex());
  3541. }
  3542. return delegate.createProperty('init', id, parsePropertyMethodFunction({ generator: true }), true, false);
  3543. }
  3544. key = parseObjectPropertyKey();
  3545. if (match(':')) {
  3546. lex();
  3547. return delegate.createProperty('init', key, parseAssignmentExpression(), false, false);
  3548. }
  3549. if (match('(')) {
  3550. return delegate.createProperty('init', key, parsePropertyMethodFunction({ generator: false }), true, false);
  3551. }
  3552. throwUnexpected(lex());
  3553. }
  3554. function parseObjectInitialiser() {
  3555. var properties = [], property, name, key, kind, map = {}, toString = String;
  3556. expect('{');
  3557. while (!match('}')) {
  3558. property = parseObjectProperty();
  3559. if (property.key.type === Syntax.Identifier) {
  3560. name = property.key.name;
  3561. } else {
  3562. name = toString(property.key.value);
  3563. }
  3564. kind = (property.kind === 'init') ? PropertyKind.Data : (property.kind === 'get') ? PropertyKind.Get : PropertyKind.Set;
  3565. key = '$' + name;
  3566. if (Object.prototype.hasOwnProperty.call(map, key)) {
  3567. if (map[key] === PropertyKind.Data) {
  3568. if (strict && kind === PropertyKind.Data) {
  3569. throwErrorTolerant({}, Messages.StrictDuplicateProperty);
  3570. } else if (kind !== PropertyKind.Data) {
  3571. throwErrorTolerant({}, Messages.AccessorDataProperty);
  3572. }
  3573. } else {
  3574. if (kind === PropertyKind.Data) {
  3575. throwErrorTolerant({}, Messages.AccessorDataProperty);
  3576. } else if (map[key] & kind) {
  3577. throwErrorTolerant({}, Messages.AccessorGetSet);
  3578. }
  3579. }
  3580. map[key] |= kind;
  3581. } else {
  3582. map[key] = kind;
  3583. }
  3584. properties.push(property);
  3585. if (!match('}')) {
  3586. expect(',');
  3587. }
  3588. }
  3589. expect('}');
  3590. return delegate.createObjectExpression(properties);
  3591. }
  3592. function parseTemplateElement(option) {
  3593. var token = scanTemplateElement(option);
  3594. if (strict && token.octal) {
  3595. throwError(token, Messages.StrictOctalLiteral);
  3596. }
  3597. return delegate.createTemplateElement({ raw: token.value.raw, cooked: token.value.cooked }, token.tail);
  3598. }
  3599. function parseTemplateLiteral() {
  3600. var quasi, quasis, expressions;
  3601. quasi = parseTemplateElement({ head: true });
  3602. quasis = [quasi];
  3603. expressions = [];
  3604. while (!quasi.tail) {
  3605. expressions.push(parseExpression());
  3606. quasi = parseTemplateElement({ head: false });
  3607. quasis.push(quasi);
  3608. }
  3609. return delegate.createTemplateLiteral(quasis, expressions);
  3610. }
  3611. // 11.1.6 The Grouping Operator
  3612. function parseGroupExpression() {
  3613. var expr;
  3614. expect('(');
  3615. ++state.parenthesizedCount;
  3616. expr = parseExpression();
  3617. expect(')');
  3618. return expr;
  3619. }
  3620. // 11.1 Primary Expressions
  3621. function parsePrimaryExpression() {
  3622. var type, token;
  3623. token = lookahead;
  3624. type = lookahead.type;
  3625. if (type === Token.Identifier) {
  3626. lex();
  3627. return delegate.createIdentifier(token.value);
  3628. }
  3629. if (type === Token.StringLiteral || type === Token.NumericLiteral) {
  3630. if (strict && lookahead.octal) {
  3631. throwErrorTolerant(lookahead, Messages.StrictOctalLiteral);
  3632. }
  3633. return delegate.createLiteral(lex());
  3634. }
  3635. if (type === Token.Keyword) {
  3636. if (matchKeyword('this')) {
  3637. lex();
  3638. return delegate.createThisExpression();
  3639. }
  3640. if (matchKeyword('function')) {
  3641. return parseFunctionExpression();
  3642. }
  3643. if (matchKeyword('class')) {
  3644. return parseClassExpression();
  3645. }
  3646. if (matchKeyword('super')) {
  3647. lex();
  3648. return delegate.createIdentifier('super');
  3649. }
  3650. }
  3651. if (type === Token.BooleanLiteral) {
  3652. token = lex();
  3653. token.value = (token.value === 'true');
  3654. return delegate.createLiteral(token);
  3655. }
  3656. if (type === Token.NullLiteral) {
  3657. token = lex();
  3658. token.value = null;
  3659. return delegate.createLiteral(token);
  3660. }
  3661. if (match('[')) {
  3662. return parseArrayInitialiser();
  3663. }
  3664. if (match('{')) {
  3665. return parseObjectInitialiser();
  3666. }
  3667. if (match('(')) {
  3668. return parseGroupExpression();
  3669. }
  3670. if (match('/') || match('/=')) {
  3671. return delegate.createLiteral(scanRegExp());
  3672. }
  3673. if (type === Token.Template) {
  3674. return parseTemplateLiteral();
  3675. }
  3676. if (match('<')) {
  3677. return parseXJSElement();
  3678. }
  3679. return throwUnexpected(lex());
  3680. }
  3681. // 11.2 Left-Hand-Side Expressions
  3682. function parseArguments() {
  3683. var args = [], arg;
  3684. expect('(');
  3685. if (!match(')')) {
  3686. while (index < length) {
  3687. arg = parseSpreadOrAssignmentExpression();
  3688. args.push(arg);
  3689. if (match(')')) {
  3690. break;
  3691. } else if (arg.type === Syntax.SpreadElement) {
  3692. throwError({}, Messages.ElementAfterSpreadElement);
  3693. }
  3694. expect(',');
  3695. }
  3696. }
  3697. expect(')');
  3698. return args;
  3699. }
  3700. function parseSpreadOrAssignmentExpression() {
  3701. if (match('...')) {
  3702. lex();
  3703. return delegate.createSpreadElement(parseAssignmentExpression());
  3704. }
  3705. return parseAssignmentExpression();
  3706. }
  3707. function parseNonComputedProperty() {
  3708. var token = lex();
  3709. if (!isIdentifierName(token)) {
  3710. throwUnexpected(token);
  3711. }
  3712. return delegate.createIdentifier(token.value);
  3713. }
  3714. function parseNonComputedMember() {
  3715. expect('.');
  3716. return parseNonComputedProperty();
  3717. }
  3718. function parseComputedMember() {
  3719. var expr;
  3720. expect('[');
  3721. expr = parseExpression();
  3722. expect(']');
  3723. return expr;
  3724. }
  3725. function parseNewExpression() {
  3726. var callee, args;
  3727. expectKeyword('new');
  3728. callee = parseLeftHandSideExpression();
  3729. args = match('(') ? parseArguments() : [];
  3730. return delegate.createNewExpression(callee, args);
  3731. }
  3732. function parseLeftHandSideExpressionAllowCall() {
  3733. var expr, args, property;
  3734. expr = matchKeyword('new') ? parseNewExpression() : parsePrimaryExpression();
  3735. while (match('.') || match('[') || match('(') || lookahead.type === Token.Template) {
  3736. if (match('(')) {
  3737. args = parseArguments();
  3738. expr = delegate.createCallExpression(expr, args);
  3739. } else if (match('[')) {
  3740. expr = delegate.createMemberExpression('[', expr, parseComputedMember());
  3741. } else if (match('.')) {
  3742. expr = delegate.createMemberExpression('.', expr, parseNonComputedMember());
  3743. } else {
  3744. expr = delegate.createTaggedTemplateExpression(expr, parseTemplateLiteral());
  3745. }
  3746. }
  3747. return expr;
  3748. }
  3749. function parseLeftHandSideExpression() {
  3750. var expr, property;
  3751. expr = matchKeyword('new') ? parseNewExpression() : parsePrimaryExpression();
  3752. while (match('.') || match('[') || lookahead.type === Token.Template) {
  3753. if (match('[')) {
  3754. expr = delegate.createMemberExpression('[', expr, parseComputedMember());
  3755. } else if (match('.')) {
  3756. expr = delegate.createMemberExpression('.', expr, parseNonComputedMember());
  3757. } else {
  3758. expr = delegate.createTaggedTemplateExpression(expr, parseTemplateLiteral());
  3759. }
  3760. }
  3761. return expr;
  3762. }
  3763. // 11.3 Postfix Expressions
  3764. function parsePostfixExpression() {
  3765. var expr = parseLeftHandSideExpressionAllowCall(),
  3766. token = lookahead;
  3767. if (lookahead.type !== Token.Punctuator) {
  3768. return expr;
  3769. }
  3770. if ((match('++') || match('--')) && !peekLineTerminator()) {
  3771. // 11.3.1, 11.3.2
  3772. if (strict && expr.type === Syntax.Identifier && isRestrictedWord(expr.name)) {
  3773. throwErrorTolerant({}, Messages.StrictLHSPostfix);
  3774. }
  3775. if (!isLeftHandSide(expr)) {
  3776. throwError({}, Messages.InvalidLHSInAssignment);
  3777. }
  3778. token = lex();
  3779. expr = delegate.createPostfixExpression(token.value, expr);
  3780. }
  3781. return expr;
  3782. }
  3783. // 11.4 Unary Operators
  3784. function parseUnaryExpression() {
  3785. var token, expr;
  3786. if (lookahead.type !== Token.Punctuator && lookahead.type !== Token.Keyword) {
  3787. return parsePostfixExpression();
  3788. }
  3789. if (match('++') || match('--')) {
  3790. token = lex();
  3791. expr = parseUnaryExpression();
  3792. // 11.4.4, 11.4.5
  3793. if (strict && expr.type === Syntax.Identifier && isRestrictedWord(expr.name)) {
  3794. throwErrorTolerant({}, Messages.StrictLHSPrefix);
  3795. }
  3796. if (!isLeftHandSide(expr)) {
  3797. throwError({}, Messages.InvalidLHSInAssignment);
  3798. }
  3799. return delegate.createUnaryExpression(token.value, expr);
  3800. }
  3801. if (match('+') || match('-') || match('~') || match('!')) {
  3802. token = lex();
  3803. expr = parseUnaryExpression();
  3804. return delegate.createUnaryExpression(token.value, expr);
  3805. }
  3806. if (matchKeyword('delete') || matchKeyword('void') || matchKeyword('typeof')) {
  3807. token = lex();
  3808. expr = parseUnaryExpression();
  3809. expr = delegate.createUnaryExpression(token.value, expr);
  3810. if (strict && expr.operator === 'delete' && expr.argument.type === Syntax.Identifier) {
  3811. throwErrorTolerant({}, Messages.StrictDelete);
  3812. }
  3813. return expr;
  3814. }
  3815. return parsePostfixExpression();
  3816. }
  3817. function binaryPrecedence(token, allowIn) {
  3818. var prec = 0;
  3819. if (token.type !== Token.Punctuator && token.type !== Token.Keyword) {
  3820. return 0;
  3821. }
  3822. switch (token.value) {
  3823. case '||':
  3824. prec = 1;
  3825. break;
  3826. case '&&':
  3827. prec = 2;
  3828. break;
  3829. case '|':
  3830. prec = 3;
  3831. break;
  3832. case '^':
  3833. prec = 4;
  3834. break;
  3835. case '&':
  3836. prec = 5;
  3837. break;
  3838. case '==':
  3839. case '!=':
  3840. case '===':
  3841. case '!==':
  3842. prec = 6;
  3843. break;
  3844. case '<':
  3845. case '>':
  3846. case '<=':
  3847. case '>=':
  3848. case 'instanceof':
  3849. prec = 7;
  3850. break;
  3851. case 'in':
  3852. prec = allowIn ? 7 : 0;
  3853. break;
  3854. case '<<':
  3855. case '>>':
  3856. case '>>>':
  3857. prec = 8;
  3858. break;
  3859. case '+':
  3860. case '-':
  3861. prec = 9;
  3862. break;
  3863. case '*':
  3864. case '/':
  3865. case '%':
  3866. prec = 11;
  3867. break;
  3868. default:
  3869. break;
  3870. }
  3871. return prec;
  3872. }
  3873. // 11.5 Multiplicative Operators
  3874. // 11.6 Additive Operators
  3875. // 11.7 Bitwise Shift Operators
  3876. // 11.8 Relational Operators
  3877. // 11.9 Equality Operators
  3878. // 11.10 Binary Bitwise Operators
  3879. // 11.11 Binary Logical Operators
  3880. function parseBinaryExpression() {
  3881. var expr, token, prec, previousAllowIn, stack, right, operator, left, i;
  3882. previousAllowIn = state.allowIn;
  3883. state.allowIn = true;
  3884. expr = parseUnaryExpression();
  3885. token = lookahead;
  3886. prec = binaryPrecedence(token, previousAllowIn);
  3887. if (prec === 0) {
  3888. return expr;
  3889. }
  3890. token.prec = prec;
  3891. lex();
  3892. stack = [expr, token, parseUnaryExpression()];
  3893. while ((prec = binaryPrecedence(lookahead, previousAllowIn)) > 0) {
  3894. // Reduce: make a binary expression from the three topmost entries.
  3895. while ((stack.length > 2) && (prec <= stack[stack.length - 2].prec)) {
  3896. right = stack.pop();
  3897. operator = stack.pop().value;
  3898. left = stack.pop();
  3899. stack.push(delegate.createBinaryExpression(operator, left, right));
  3900. }
  3901. // Shift.
  3902. token = lex();
  3903. token.prec = prec;
  3904. stack.push(token);
  3905. stack.push(parseUnaryExpression());
  3906. }
  3907. state.allowIn = previousAllowIn;
  3908. // Final reduce to clean-up the stack.
  3909. i = stack.length - 1;
  3910. expr = stack[i];
  3911. while (i > 1) {
  3912. expr = delegate.createBinaryExpression(stack[i - 1].value, stack[i - 2], expr);
  3913. i -= 2;
  3914. }
  3915. return expr;
  3916. }
  3917. // 11.12 Conditional Operator
  3918. function parseConditionalExpression() {
  3919. var expr, previousAllowIn, consequent, alternate;
  3920. expr = parseBinaryExpression();
  3921. if (match('?')) {
  3922. lex();
  3923. previousAllowIn = state.allowIn;
  3924. state.allowIn = true;
  3925. consequent = parseAssignmentExpression();
  3926. state.allowIn = previousAllowIn;
  3927. expect(':');
  3928. alternate = parseAssignmentExpression();
  3929. expr = delegate.createConditionalExpression(expr, consequent, alternate);
  3930. }
  3931. return expr;
  3932. }
  3933. // 11.13 Assignment Operators
  3934. function reinterpretAsAssignmentBindingPattern(expr) {
  3935. var i, len, property, element;
  3936. if (expr.type === Syntax.ObjectExpression) {
  3937. expr.type = Syntax.ObjectPattern;
  3938. for (i = 0, len = expr.properties.length; i < len; i += 1) {
  3939. property = expr.properties[i];
  3940. if (property.kind !== 'init') {
  3941. throwError({}, Messages.InvalidLHSInAssignment);
  3942. }
  3943. reinterpretAsAssignmentBindingPattern(property.value);
  3944. }
  3945. } else if (expr.type === Syntax.ArrayExpression) {
  3946. expr.type = Syntax.ArrayPattern;
  3947. for (i = 0, len = expr.elements.length; i < len; i += 1) {
  3948. element = expr.elements[i];
  3949. if (element) {
  3950. reinterpretAsAssignmentBindingPattern(element);
  3951. }
  3952. }
  3953. } else if (expr.type === Syntax.Identifier) {
  3954. if (isRestrictedWord(expr.name)) {
  3955. throwError({}, Messages.InvalidLHSInAssignment);
  3956. }
  3957. } else if (expr.type === Syntax.SpreadElement) {
  3958. reinterpretAsAssignmentBindingPattern(expr.argument);
  3959. if (expr.argument.type === Syntax.ObjectPattern) {
  3960. throwError({}, Messages.ObjectPatternAsSpread);
  3961. }
  3962. } else {
  3963. if (expr.type !== Syntax.MemberExpression && expr.type !== Syntax.CallExpression && expr.type !== Syntax.NewExpression) {
  3964. throwError({}, Messages.InvalidLHSInAssignment);
  3965. }
  3966. }
  3967. }
  3968. function reinterpretAsDestructuredParameter(options, expr) {
  3969. var i, len, property, element;
  3970. if (expr.type === Syntax.ObjectExpression) {
  3971. expr.type = Syntax.ObjectPattern;
  3972. for (i = 0, len = expr.properties.length; i < len; i += 1) {
  3973. property = expr.properties[i];
  3974. if (property.kind !== 'init') {
  3975. throwError({}, Messages.InvalidLHSInFormalsList);
  3976. }
  3977. reinterpretAsDestructuredParameter(options, property.value);
  3978. }
  3979. } else if (expr.type === Syntax.ArrayExpression) {
  3980. expr.type = Syntax.ArrayPattern;
  3981. for (i = 0, len = expr.elements.length; i < len; i += 1) {
  3982. element = expr.elements[i];
  3983. if (element) {
  3984. reinterpretAsDestructuredParameter(options, element);
  3985. }
  3986. }
  3987. } else if (expr.type === Syntax.Identifier) {
  3988. validateParam(options, expr, expr.name);
  3989. } else {
  3990. if (expr.type !== Syntax.MemberExpression) {
  3991. throwError({}, Messages.InvalidLHSInFormalsList);
  3992. }
  3993. }
  3994. }
  3995. function reinterpretAsCoverFormalsList(expressions) {
  3996. var i, len, param, params, defaults, defaultCount, options, rest;
  3997. params = [];
  3998. defaults = [];
  3999. defaultCount = 0;
  4000. rest = null;
  4001. options = {
  4002. paramSet: {}
  4003. };
  4004. for (i = 0, len = expressions.length; i < len; i += 1) {
  4005. param = expressions[i];
  4006. if (param.type === Syntax.Identifier) {
  4007. params.push(param);
  4008. defaults.push(null);
  4009. validateParam(options, param, param.name);
  4010. } else if (param.type === Syntax.ObjectExpression || param.type === Syntax.ArrayExpression) {
  4011. reinterpretAsDestructuredParameter(options, param);
  4012. params.push(param);
  4013. defaults.push(null);
  4014. } else if (param.type === Syntax.SpreadElement) {
  4015. assert(i === len - 1, 'It is guaranteed that SpreadElement is last element by parseExpression');
  4016. reinterpretAsDestructuredParameter(options, param.argument);
  4017. rest = param.argument;
  4018. } else if (param.type === Syntax.AssignmentExpression) {
  4019. params.push(param.left);
  4020. defaults.push(param.right);
  4021. ++defaultCount;
  4022. validateParam(options, param.left, param.left.name);
  4023. } else {
  4024. return null;
  4025. }
  4026. }
  4027. if (options.message === Messages.StrictParamDupe) {
  4028. throwError(
  4029. strict ? options.stricted : options.firstRestricted,
  4030. options.message
  4031. );
  4032. }
  4033. if (defaultCount === 0) {
  4034. defaults = [];
  4035. }
  4036. return {
  4037. params: params,
  4038. defaults: defaults,
  4039. rest: rest,
  4040. stricted: options.stricted,
  4041. firstRestricted: options.firstRestricted,
  4042. message: options.message
  4043. };
  4044. }
  4045. function parseArrowFunctionExpression(options) {
  4046. var previousStrict, previousYieldAllowed, body;
  4047. expect('=>');
  4048. previousStrict = strict;
  4049. previousYieldAllowed = state.yieldAllowed;
  4050. state.yieldAllowed = false;
  4051. body = parseConciseBody();
  4052. if (strict && options.firstRestricted) {
  4053. throwError(options.firstRestricted, options.message);
  4054. }
  4055. if (strict && options.stricted) {
  4056. throwErrorTolerant(options.stricted, options.message);
  4057. }
  4058. strict = previousStrict;
  4059. state.yieldAllowed = previousYieldAllowed;
  4060. return delegate.createArrowFunctionExpression(options.params, options.defaults, body, options.rest, body.type !== Syntax.BlockStatement);
  4061. }
  4062. function parseAssignmentExpression() {
  4063. var expr, token, params, oldParenthesizedCount;
  4064. if (matchKeyword('yield')) {
  4065. return parseYieldExpression();
  4066. }
  4067. oldParenthesizedCount = state.parenthesizedCount;
  4068. if (match('(')) {
  4069. token = lookahead2();
  4070. if ((token.type === Token.Punctuator && token.value === ')') || token.value === '...') {
  4071. params = parseParams();
  4072. if (!match('=>')) {
  4073. throwUnexpected(lex());
  4074. }
  4075. return parseArrowFunctionExpression(params);
  4076. }
  4077. }
  4078. token = lookahead;
  4079. expr = parseConditionalExpression();
  4080. if (match('=>') &&
  4081. (state.parenthesizedCount === oldParenthesizedCount ||
  4082. state.parenthesizedCount === (oldParenthesizedCount + 1))) {
  4083. if (expr.type === Syntax.Identifier) {
  4084. params = reinterpretAsCoverFormalsList([expr]);
  4085. } else if (expr.type === Syntax.SequenceExpression) {
  4086. params = reinterpretAsCoverFormalsList(expr.expressions);
  4087. }
  4088. if (params) {
  4089. return parseArrowFunctionExpression(params);
  4090. }
  4091. }
  4092. if (matchAssign()) {
  4093. // 11.13.1
  4094. if (strict && expr.type === Syntax.Identifier && isRestrictedWord(expr.name)) {
  4095. throwErrorTolerant(token, Messages.StrictLHSAssignment);
  4096. }
  4097. // ES.next draf 11.13 Runtime Semantics step 1
  4098. if (match('=') && (expr.type === Syntax.ObjectExpression || expr.type === Syntax.ArrayExpression)) {
  4099. reinterpretAsAssignmentBindingPattern(expr);
  4100. } else if (!isLeftHandSide(expr)) {
  4101. throwError({}, Messages.InvalidLHSInAssignment);
  4102. }
  4103. expr = delegate.createAssignmentExpression(lex().value, expr, parseAssignmentExpression());
  4104. }
  4105. return expr;
  4106. }
  4107. // 11.14 Comma Operator
  4108. function parseExpression() {
  4109. var expr, expressions, sequence, coverFormalsList, spreadFound, oldParenthesizedCount;
  4110. oldParenthesizedCount = state.parenthesizedCount;
  4111. expr = parseAssignmentExpression();
  4112. expressions = [expr];
  4113. if (match(',')) {
  4114. while (index < length) {
  4115. if (!match(',')) {
  4116. break;
  4117. }
  4118. lex();
  4119. expr = parseSpreadOrAssignmentExpression();
  4120. expressions.push(expr);
  4121. if (expr.type === Syntax.SpreadElement) {
  4122. spreadFound = true;
  4123. if (!match(')')) {
  4124. throwError({}, Messages.ElementAfterSpreadElement);
  4125. }
  4126. break;
  4127. }
  4128. }
  4129. sequence = delegate.createSequenceExpression(expressions);
  4130. }
  4131. if (match('=>')) {
  4132. // Do not allow nested parentheses on the LHS of the =>.
  4133. if (state.parenthesizedCount === oldParenthesizedCount || state.parenthesizedCount === (oldParenthesizedCount + 1)) {
  4134. expr = expr.type === Syntax.SequenceExpression ? expr.expressions : expressions;
  4135. coverFormalsList = reinterpretAsCoverFormalsList(expr);
  4136. if (coverFormalsList) {
  4137. return parseArrowFunctionExpression(coverFormalsList);
  4138. }
  4139. }
  4140. throwUnexpected(lex());
  4141. }
  4142. if (spreadFound && lookahead2().value !== '=>') {
  4143. throwError({}, Messages.IllegalSpread);
  4144. }
  4145. return sequence || expr;
  4146. }
  4147. // 12.1 Block
  4148. function parseStatementList() {
  4149. var list = [],
  4150. statement;
  4151. while (index < length) {
  4152. if (match('}')) {
  4153. break;
  4154. }
  4155. statement = parseSourceElement();
  4156. if (typeof statement === 'undefined') {
  4157. break;
  4158. }
  4159. list.push(statement);
  4160. }
  4161. return list;
  4162. }
  4163. function parseBlock() {
  4164. var block;
  4165. expect('{');
  4166. block = parseStatementList();
  4167. expect('}');
  4168. return delegate.createBlockStatement(block);
  4169. }
  4170. // 12.2 Variable Statement
  4171. function parseTypeAnnotation(dontExpectColon) {
  4172. var typeIdentifier = null, paramTypes = null, returnType = null,
  4173. nullable = false;
  4174. if (!dontExpectColon) {
  4175. expect(':');
  4176. }
  4177. if (match('?')) {
  4178. lex();
  4179. nullable = true;
  4180. }
  4181. if (lookahead.type === Token.Identifier) {
  4182. typeIdentifier = parseVariableIdentifier();
  4183. }
  4184. if (match('(')) {
  4185. lex();
  4186. paramTypes = [];
  4187. while (lookahead.type === Token.Identifier || match('?')) {
  4188. paramTypes.push(parseTypeAnnotation(true));
  4189. if (!match(')')) {
  4190. expect(',');
  4191. }
  4192. }
  4193. expect(')');
  4194. expect('=>');
  4195. if (matchKeyword('void')) {
  4196. lex();
  4197. } else {
  4198. returnType = parseTypeAnnotation(true);
  4199. }
  4200. }
  4201. return delegate.createTypeAnnotation(
  4202. typeIdentifier,
  4203. paramTypes,
  4204. returnType,
  4205. nullable
  4206. );
  4207. }
  4208. function parseVariableIdentifier() {
  4209. var token = lex();
  4210. if (token.type !== Token.Identifier) {
  4211. throwUnexpected(token);
  4212. }
  4213. return delegate.createIdentifier(token.value);
  4214. }
  4215. function parseTypeAnnotatableIdentifier() {
  4216. var ident = parseVariableIdentifier();
  4217. if (match(':')) {
  4218. return delegate.createTypeAnnotatedIdentifier(ident, parseTypeAnnotation());
  4219. }
  4220. return ident;
  4221. }
  4222. function parseVariableDeclaration(kind) {
  4223. var id,
  4224. init = null;
  4225. if (match('{')) {
  4226. id = parseObjectInitialiser();
  4227. reinterpretAsAssignmentBindingPattern(id);
  4228. } else if (match('[')) {
  4229. id = parseArrayInitialiser();
  4230. reinterpretAsAssignmentBindingPattern(id);
  4231. } else {
  4232. id = state.allowKeyword ? parseNonComputedProperty() : parseTypeAnnotatableIdentifier();
  4233. // 12.2.1
  4234. if (strict && isRestrictedWord(id.name)) {
  4235. throwErrorTolerant({}, Messages.StrictVarName);
  4236. }
  4237. }
  4238. if (kind === 'const') {
  4239. if (!match('=')) {
  4240. throwError({}, Messages.NoUnintializedConst);
  4241. }
  4242. expect('=');
  4243. init = parseAssignmentExpression();
  4244. } else if (match('=')) {
  4245. lex();
  4246. init = parseAssignmentExpression();
  4247. }
  4248. return delegate.createVariableDeclarator(id, init);
  4249. }
  4250. function parseVariableDeclarationList(kind) {
  4251. var list = [];
  4252. do {
  4253. list.push(parseVariableDeclaration(kind));
  4254. if (!match(',')) {
  4255. break;
  4256. }
  4257. lex();
  4258. } while (index < length);
  4259. return list;
  4260. }
  4261. function parseVariableStatement() {
  4262. var declarations;
  4263. expectKeyword('var');
  4264. declarations = parseVariableDeclarationList();
  4265. consumeSemicolon();
  4266. return delegate.createVariableDeclaration(declarations, 'var');
  4267. }
  4268. // kind may be `const` or `let`
  4269. // Both are experimental and not in the specification yet.
  4270. // see http://wiki.ecmascript.org/doku.php?id=harmony:const
  4271. // and http://wiki.ecmascript.org/doku.php?id=harmony:let
  4272. function parseConstLetDeclaration(kind) {
  4273. var declarations;
  4274. expectKeyword(kind);
  4275. declarations = parseVariableDeclarationList(kind);
  4276. consumeSemicolon();
  4277. return delegate.createVariableDeclaration(declarations, kind);
  4278. }
  4279. // http://wiki.ecmascript.org/doku.php?id=harmony:modules
  4280. function parseModuleDeclaration() {
  4281. var id, src, body;
  4282. lex(); // 'module'
  4283. if (peekLineTerminator()) {
  4284. throwError({}, Messages.NewlineAfterModule);
  4285. }
  4286. switch (lookahead.type) {
  4287. case Token.StringLiteral:
  4288. id = parsePrimaryExpression();
  4289. body = parseModuleBlock();
  4290. src = null;
  4291. break;
  4292. case Token.Identifier:
  4293. id = parseVariableIdentifier();
  4294. body = null;
  4295. if (!matchContextualKeyword('from')) {
  4296. throwUnexpected(lex());
  4297. }
  4298. lex();
  4299. src = parsePrimaryExpression();
  4300. if (src.type !== Syntax.Literal) {
  4301. throwError({}, Messages.InvalidModuleSpecifier);
  4302. }
  4303. break;
  4304. }
  4305. consumeSemicolon();
  4306. return delegate.createModuleDeclaration(id, src, body);
  4307. }
  4308. function parseExportBatchSpecifier() {
  4309. expect('*');
  4310. return delegate.createExportBatchSpecifier();
  4311. }
  4312. function parseExportSpecifier() {
  4313. var id, name = null;
  4314. id = parseVariableIdentifier();
  4315. if (matchContextualKeyword('as')) {
  4316. lex();
  4317. name = parseNonComputedProperty();
  4318. }
  4319. return delegate.createExportSpecifier(id, name);
  4320. }
  4321. function parseExportDeclaration() {
  4322. var previousAllowKeyword, decl, def, src, specifiers;
  4323. expectKeyword('export');
  4324. if (lookahead.type === Token.Keyword) {
  4325. switch (lookahead.value) {
  4326. case 'let':
  4327. case 'const':
  4328. case 'var':
  4329. case 'class':
  4330. case 'function':
  4331. return delegate.createExportDeclaration(parseSourceElement(), null, null);
  4332. }
  4333. }
  4334. if (isIdentifierName(lookahead)) {
  4335. previousAllowKeyword = state.allowKeyword;
  4336. state.allowKeyword = true;
  4337. decl = parseVariableDeclarationList('let');
  4338. state.allowKeyword = previousAllowKeyword;
  4339. return delegate.createExportDeclaration(decl, null, null);
  4340. }
  4341. specifiers = [];
  4342. src = null;
  4343. if (match('*')) {
  4344. specifiers.push(parseExportBatchSpecifier());
  4345. } else {
  4346. expect('{');
  4347. do {
  4348. specifiers.push(parseExportSpecifier());
  4349. } while (match(',') && lex());
  4350. expect('}');
  4351. }
  4352. if (matchContextualKeyword('from')) {
  4353. lex();
  4354. src = parsePrimaryExpression();
  4355. if (src.type !== Syntax.Literal) {
  4356. throwError({}, Messages.InvalidModuleSpecifier);
  4357. }
  4358. }
  4359. consumeSemicolon();
  4360. return delegate.createExportDeclaration(null, specifiers, src);
  4361. }
  4362. function parseImportDeclaration() {
  4363. var specifiers, kind, src;
  4364. expectKeyword('import');
  4365. specifiers = [];
  4366. if (isIdentifierName(lookahead)) {
  4367. kind = 'default';
  4368. specifiers.push(parseImportSpecifier());
  4369. if (!matchContextualKeyword('from')) {
  4370. throwError({}, Messages.NoFromAfterImport);
  4371. }
  4372. lex();
  4373. } else if (match('{')) {
  4374. kind = 'named';
  4375. lex();
  4376. do {
  4377. specifiers.push(parseImportSpecifier());
  4378. } while (match(',') && lex());
  4379. expect('}');
  4380. if (!matchContextualKeyword('from')) {
  4381. throwError({}, Messages.NoFromAfterImport);
  4382. }
  4383. lex();
  4384. }
  4385. src = parsePrimaryExpression();
  4386. if (src.type !== Syntax.Literal) {
  4387. throwError({}, Messages.InvalidModuleSpecifier);
  4388. }
  4389. consumeSemicolon();
  4390. return delegate.createImportDeclaration(specifiers, kind, src);
  4391. }
  4392. function parseImportSpecifier() {
  4393. var id, name = null;
  4394. id = parseNonComputedProperty();
  4395. if (matchContextualKeyword('as')) {
  4396. lex();
  4397. name = parseVariableIdentifier();
  4398. }
  4399. return delegate.createImportSpecifier(id, name);
  4400. }
  4401. // 12.3 Empty Statement
  4402. function parseEmptyStatement() {
  4403. expect(';');
  4404. return delegate.createEmptyStatement();
  4405. }
  4406. // 12.4 Expression Statement
  4407. function parseExpressionStatement() {
  4408. var expr = parseExpression();
  4409. consumeSemicolon();
  4410. return delegate.createExpressionStatement(expr);
  4411. }
  4412. // 12.5 If statement
  4413. function parseIfStatement() {
  4414. var test, consequent, alternate;
  4415. expectKeyword('if');
  4416. expect('(');
  4417. test = parseExpression();
  4418. expect(')');
  4419. consequent = parseStatement();
  4420. if (matchKeyword('else')) {
  4421. lex();
  4422. alternate = parseStatement();
  4423. } else {
  4424. alternate = null;
  4425. }
  4426. return delegate.createIfStatement(test, consequent, alternate);
  4427. }
  4428. // 12.6 Iteration Statements
  4429. function parseDoWhileStatement() {
  4430. var body, test, oldInIteration;
  4431. expectKeyword('do');
  4432. oldInIteration = state.inIteration;
  4433. state.inIteration = true;
  4434. body = parseStatement();
  4435. state.inIteration = oldInIteration;
  4436. expectKeyword('while');
  4437. expect('(');
  4438. test = parseExpression();
  4439. expect(')');
  4440. if (match(';')) {
  4441. lex();
  4442. }
  4443. return delegate.createDoWhileStatement(body, test);
  4444. }
  4445. function parseWhileStatement() {
  4446. var test, body, oldInIteration;
  4447. expectKeyword('while');
  4448. expect('(');
  4449. test = parseExpression();
  4450. expect(')');
  4451. oldInIteration = state.inIteration;
  4452. state.inIteration = true;
  4453. body = parseStatement();
  4454. state.inIteration = oldInIteration;
  4455. return delegate.createWhileStatement(test, body);
  4456. }
  4457. function parseForVariableDeclaration() {
  4458. var token = lex(),
  4459. declarations = parseVariableDeclarationList();
  4460. return delegate.createVariableDeclaration(declarations, token.value);
  4461. }
  4462. function parseForStatement(opts) {
  4463. var init, test, update, left, right, body, operator, oldInIteration;
  4464. init = test = update = null;
  4465. expectKeyword('for');
  4466. // http://wiki.ecmascript.org/doku.php?id=proposals:iterators_and_generators&s=each
  4467. if (matchContextualKeyword('each')) {
  4468. throwError({}, Messages.EachNotAllowed);
  4469. }
  4470. expect('(');
  4471. if (match(';')) {
  4472. lex();
  4473. } else {
  4474. if (matchKeyword('var') || matchKeyword('let') || matchKeyword('const')) {
  4475. state.allowIn = false;
  4476. init = parseForVariableDeclaration();
  4477. state.allowIn = true;
  4478. if (init.declarations.length === 1) {
  4479. if (matchKeyword('in') || matchContextualKeyword('of')) {
  4480. operator = lookahead;
  4481. if (!((operator.value === 'in' || init.kind !== 'var') && init.declarations[0].init)) {
  4482. lex();
  4483. left = init;
  4484. right = parseExpression();
  4485. init = null;
  4486. }
  4487. }
  4488. }
  4489. } else {
  4490. state.allowIn = false;
  4491. init = parseExpression();
  4492. state.allowIn = true;
  4493. if (matchContextualKeyword('of')) {
  4494. operator = lex();
  4495. left = init;
  4496. right = parseExpression();
  4497. init = null;
  4498. } else if (matchKeyword('in')) {
  4499. // LeftHandSideExpression
  4500. if (!isAssignableLeftHandSide(init)) {
  4501. throwError({}, Messages.InvalidLHSInForIn);
  4502. }
  4503. operator = lex();
  4504. left = init;
  4505. right = parseExpression();
  4506. init = null;
  4507. }
  4508. }
  4509. if (typeof left === 'undefined') {
  4510. expect(';');
  4511. }
  4512. }
  4513. if (typeof left === 'undefined') {
  4514. if (!match(';')) {
  4515. test = parseExpression();
  4516. }
  4517. expect(';');
  4518. if (!match(')')) {
  4519. update = parseExpression();
  4520. }
  4521. }
  4522. expect(')');
  4523. oldInIteration = state.inIteration;
  4524. state.inIteration = true;
  4525. if (!(opts !== undefined && opts.ignoreBody)) {
  4526. body = parseStatement();
  4527. }
  4528. state.inIteration = oldInIteration;
  4529. if (typeof left === 'undefined') {
  4530. return delegate.createForStatement(init, test, update, body);
  4531. }
  4532. if (operator.value === 'in') {
  4533. return delegate.createForInStatement(left, right, body);
  4534. }
  4535. return delegate.createForOfStatement(left, right, body);
  4536. }
  4537. // 12.7 The continue statement
  4538. function parseContinueStatement() {
  4539. var label = null, key;
  4540. expectKeyword('continue');
  4541. // Optimize the most common form: 'continue;'.
  4542. if (source.charCodeAt(index) === 59) {
  4543. lex();
  4544. if (!state.inIteration) {
  4545. throwError({}, Messages.IllegalContinue);
  4546. }
  4547. return delegate.createContinueStatement(null);
  4548. }
  4549. if (peekLineTerminator()) {
  4550. if (!state.inIteration) {
  4551. throwError({}, Messages.IllegalContinue);
  4552. }
  4553. return delegate.createContinueStatement(null);
  4554. }
  4555. if (lookahead.type === Token.Identifier) {
  4556. label = parseVariableIdentifier();
  4557. key = '$' + label.name;
  4558. if (!Object.prototype.hasOwnProperty.call(state.labelSet, key)) {
  4559. throwError({}, Messages.UnknownLabel, label.name);
  4560. }
  4561. }
  4562. consumeSemicolon();
  4563. if (label === null && !state.inIteration) {
  4564. throwError({}, Messages.IllegalContinue);
  4565. }
  4566. return delegate.createContinueStatement(label);
  4567. }
  4568. // 12.8 The break statement
  4569. function parseBreakStatement() {
  4570. var label = null, key;
  4571. expectKeyword('break');
  4572. // Catch the very common case first: immediately a semicolon (char #59).
  4573. if (source.charCodeAt(index) === 59) {
  4574. lex();
  4575. if (!(state.inIteration || state.inSwitch)) {
  4576. throwError({}, Messages.IllegalBreak);
  4577. }
  4578. return delegate.createBreakStatement(null);
  4579. }
  4580. if (peekLineTerminator()) {
  4581. if (!(state.inIteration || state.inSwitch)) {
  4582. throwError({}, Messages.IllegalBreak);
  4583. }
  4584. return delegate.createBreakStatement(null);
  4585. }
  4586. if (lookahead.type === Token.Identifier) {
  4587. label = parseVariableIdentifier();
  4588. key = '$' + label.name;
  4589. if (!Object.prototype.hasOwnProperty.call(state.labelSet, key)) {
  4590. throwError({}, Messages.UnknownLabel, label.name);
  4591. }
  4592. }
  4593. consumeSemicolon();
  4594. if (label === null && !(state.inIteration || state.inSwitch)) {
  4595. throwError({}, Messages.IllegalBreak);
  4596. }
  4597. return delegate.createBreakStatement(label);
  4598. }
  4599. // 12.9 The return statement
  4600. function parseReturnStatement() {
  4601. var argument = null;
  4602. expectKeyword('return');
  4603. if (!state.inFunctionBody) {
  4604. throwErrorTolerant({}, Messages.IllegalReturn);
  4605. }
  4606. // 'return' followed by a space and an identifier is very common.
  4607. if (source.charCodeAt(index) === 32) {
  4608. if (isIdentifierStart(source.charCodeAt(index + 1))) {
  4609. argument = parseExpression();
  4610. consumeSemicolon();
  4611. return delegate.createReturnStatement(argument);
  4612. }
  4613. }
  4614. if (peekLineTerminator()) {
  4615. return delegate.createReturnStatement(null);
  4616. }
  4617. if (!match(';')) {
  4618. if (!match('}') && lookahead.type !== Token.EOF) {
  4619. argument = parseExpression();
  4620. }
  4621. }
  4622. consumeSemicolon();
  4623. return delegate.createReturnStatement(argument);
  4624. }
  4625. // 12.10 The with statement
  4626. function parseWithStatement() {
  4627. var object, body;
  4628. if (strict) {
  4629. throwErrorTolerant({}, Messages.StrictModeWith);
  4630. }
  4631. expectKeyword('with');
  4632. expect('(');
  4633. object = parseExpression();
  4634. expect(')');
  4635. body = parseStatement();
  4636. return delegate.createWithStatement(object, body);
  4637. }
  4638. // 12.10 The swith statement
  4639. function parseSwitchCase() {
  4640. var test,
  4641. consequent = [],
  4642. sourceElement;
  4643. if (matchKeyword('default')) {
  4644. lex();
  4645. test = null;
  4646. } else {
  4647. expectKeyword('case');
  4648. test = parseExpression();
  4649. }
  4650. expect(':');
  4651. while (index < length) {
  4652. if (match('}') || matchKeyword('default') || matchKeyword('case')) {
  4653. break;
  4654. }
  4655. sourceElement = parseSourceElement();
  4656. if (typeof sourceElement === 'undefined') {
  4657. break;
  4658. }
  4659. consequent.push(sourceElement);
  4660. }
  4661. return delegate.createSwitchCase(test, consequent);
  4662. }
  4663. function parseSwitchStatement() {
  4664. var discriminant, cases, clause, oldInSwitch, defaultFound;
  4665. expectKeyword('switch');
  4666. expect('(');
  4667. discriminant = parseExpression();
  4668. expect(')');
  4669. expect('{');
  4670. cases = [];
  4671. if (match('}')) {
  4672. lex();
  4673. return delegate.createSwitchStatement(discriminant, cases);
  4674. }
  4675. oldInSwitch = state.inSwitch;
  4676. state.inSwitch = true;
  4677. defaultFound = false;
  4678. while (index < length) {
  4679. if (match('}')) {
  4680. break;
  4681. }
  4682. clause = parseSwitchCase();
  4683. if (clause.test === null) {
  4684. if (defaultFound) {
  4685. throwError({}, Messages.MultipleDefaultsInSwitch);
  4686. }
  4687. defaultFound = true;
  4688. }
  4689. cases.push(clause);
  4690. }
  4691. state.inSwitch = oldInSwitch;
  4692. expect('}');
  4693. return delegate.createSwitchStatement(discriminant, cases);
  4694. }
  4695. // 12.13 The throw statement
  4696. function parseThrowStatement() {
  4697. var argument;
  4698. expectKeyword('throw');
  4699. if (peekLineTerminator()) {
  4700. throwError({}, Messages.NewlineAfterThrow);
  4701. }
  4702. argument = parseExpression();
  4703. consumeSemicolon();
  4704. return delegate.createThrowStatement(argument);
  4705. }
  4706. // 12.14 The try statement
  4707. function parseCatchClause() {
  4708. var param, body;
  4709. expectKeyword('catch');
  4710. expect('(');
  4711. if (match(')')) {
  4712. throwUnexpected(lookahead);
  4713. }
  4714. param = parseExpression();
  4715. // 12.14.1
  4716. if (strict && param.type === Syntax.Identifier && isRestrictedWord(param.name)) {
  4717. throwErrorTolerant({}, Messages.StrictCatchVariable);
  4718. }
  4719. expect(')');
  4720. body = parseBlock();
  4721. return delegate.createCatchClause(param, body);
  4722. }
  4723. function parseTryStatement() {
  4724. var block, handlers = [], finalizer = null;
  4725. expectKeyword('try');
  4726. block = parseBlock();
  4727. if (matchKeyword('catch')) {
  4728. handlers.push(parseCatchClause());
  4729. }
  4730. if (matchKeyword('finally')) {
  4731. lex();
  4732. finalizer = parseBlock();
  4733. }
  4734. if (handlers.length === 0 && !finalizer) {
  4735. throwError({}, Messages.NoCatchOrFinally);
  4736. }
  4737. return delegate.createTryStatement(block, [], handlers, finalizer);
  4738. }
  4739. // 12.15 The debugger statement
  4740. function parseDebuggerStatement() {
  4741. expectKeyword('debugger');
  4742. consumeSemicolon();
  4743. return delegate.createDebuggerStatement();
  4744. }
  4745. // 12 Statements
  4746. function parseStatement() {
  4747. var type = lookahead.type,
  4748. expr,
  4749. labeledBody,
  4750. key;
  4751. if (type === Token.EOF) {
  4752. throwUnexpected(lookahead);
  4753. }
  4754. if (type === Token.Punctuator) {
  4755. switch (lookahead.value) {
  4756. case ';':
  4757. return parseEmptyStatement();
  4758. case '{':
  4759. return parseBlock();
  4760. case '(':
  4761. return parseExpressionStatement();
  4762. default:
  4763. break;
  4764. }
  4765. }
  4766. if (type === Token.Keyword) {
  4767. switch (lookahead.value) {
  4768. case 'break':
  4769. return parseBreakStatement();
  4770. case 'continue':
  4771. return parseContinueStatement();
  4772. case 'debugger':
  4773. return parseDebuggerStatement();
  4774. case 'do':
  4775. return parseDoWhileStatement();
  4776. case 'for':
  4777. return parseForStatement();
  4778. case 'function':
  4779. return parseFunctionDeclaration();
  4780. case 'class':
  4781. return parseClassDeclaration();
  4782. case 'if':
  4783. return parseIfStatement();
  4784. case 'return':
  4785. return parseReturnStatement();
  4786. case 'switch':
  4787. return parseSwitchStatement();
  4788. case 'throw':
  4789. return parseThrowStatement();
  4790. case 'try':
  4791. return parseTryStatement();
  4792. case 'var':
  4793. return parseVariableStatement();
  4794. case 'while':
  4795. return parseWhileStatement();
  4796. case 'with':
  4797. return parseWithStatement();
  4798. default:
  4799. break;
  4800. }
  4801. }
  4802. expr = parseExpression();
  4803. // 12.12 Labelled Statements
  4804. if ((expr.type === Syntax.Identifier) && match(':')) {
  4805. lex();
  4806. key = '$' + expr.name;
  4807. if (Object.prototype.hasOwnProperty.call(state.labelSet, key)) {
  4808. throwError({}, Messages.Redeclaration, 'Label', expr.name);
  4809. }
  4810. state.labelSet[key] = true;
  4811. labeledBody = parseStatement();
  4812. delete state.labelSet[key];
  4813. return delegate.createLabeledStatement(expr, labeledBody);
  4814. }
  4815. consumeSemicolon();
  4816. return delegate.createExpressionStatement(expr);
  4817. }
  4818. // 13 Function Definition
  4819. function parseConciseBody() {
  4820. if (match('{')) {
  4821. return parseFunctionSourceElements();
  4822. }
  4823. return parseAssignmentExpression();
  4824. }
  4825. function parseFunctionSourceElements() {
  4826. var sourceElement, sourceElements = [], token, directive, firstRestricted,
  4827. oldLabelSet, oldInIteration, oldInSwitch, oldInFunctionBody, oldParenthesizedCount;
  4828. expect('{');
  4829. while (index < length) {
  4830. if (lookahead.type !== Token.StringLiteral) {
  4831. break;
  4832. }
  4833. token = lookahead;
  4834. sourceElement = parseSourceElement();
  4835. sourceElements.push(sourceElement);
  4836. if (sourceElement.expression.type !== Syntax.Literal) {
  4837. // this is not directive
  4838. break;
  4839. }
  4840. directive = source.slice(token.range[0] + 1, token.range[1] - 1);
  4841. if (directive === 'use strict') {
  4842. strict = true;
  4843. if (firstRestricted) {
  4844. throwErrorTolerant(firstRestricted, Messages.StrictOctalLiteral);
  4845. }
  4846. } else {
  4847. if (!firstRestricted && token.octal) {
  4848. firstRestricted = token;
  4849. }
  4850. }
  4851. }
  4852. oldLabelSet = state.labelSet;
  4853. oldInIteration = state.inIteration;
  4854. oldInSwitch = state.inSwitch;
  4855. oldInFunctionBody = state.inFunctionBody;
  4856. oldParenthesizedCount = state.parenthesizedCount;
  4857. state.labelSet = {};
  4858. state.inIteration = false;
  4859. state.inSwitch = false;
  4860. state.inFunctionBody = true;
  4861. state.parenthesizedCount = 0;
  4862. while (index < length) {
  4863. if (match('}')) {
  4864. break;
  4865. }
  4866. sourceElement = parseSourceElement();
  4867. if (typeof sourceElement === 'undefined') {
  4868. break;
  4869. }
  4870. sourceElements.push(sourceElement);
  4871. }
  4872. expect('}');
  4873. state.labelSet = oldLabelSet;
  4874. state.inIteration = oldInIteration;
  4875. state.inSwitch = oldInSwitch;
  4876. state.inFunctionBody = oldInFunctionBody;
  4877. state.parenthesizedCount = oldParenthesizedCount;
  4878. return delegate.createBlockStatement(sourceElements);
  4879. }
  4880. function validateParam(options, param, name) {
  4881. var key = '$' + name;
  4882. if (strict) {
  4883. if (isRestrictedWord(name)) {
  4884. options.stricted = param;
  4885. options.message = Messages.StrictParamName;
  4886. }
  4887. if (Object.prototype.hasOwnProperty.call(options.paramSet, key)) {
  4888. options.stricted = param;
  4889. options.message = Messages.StrictParamDupe;
  4890. }
  4891. } else if (!options.firstRestricted) {
  4892. if (isRestrictedWord(name)) {
  4893. options.firstRestricted = param;
  4894. options.message = Messages.StrictParamName;
  4895. } else if (isStrictModeReservedWord(name)) {
  4896. options.firstRestricted = param;
  4897. options.message = Messages.StrictReservedWord;
  4898. } else if (Object.prototype.hasOwnProperty.call(options.paramSet, key)) {
  4899. options.firstRestricted = param;
  4900. options.message = Messages.StrictParamDupe;
  4901. }
  4902. }
  4903. options.paramSet[key] = true;
  4904. }
  4905. function parseParam(options) {
  4906. var token, rest, param, def;
  4907. token = lookahead;
  4908. if (token.value === '...') {
  4909. token = lex();
  4910. rest = true;
  4911. }
  4912. if (match('[')) {
  4913. param = parseArrayInitialiser();
  4914. reinterpretAsDestructuredParameter(options, param);
  4915. } else if (match('{')) {
  4916. if (rest) {
  4917. throwError({}, Messages.ObjectPatternAsRestParameter);
  4918. }
  4919. param = parseObjectInitialiser();
  4920. reinterpretAsDestructuredParameter(options, param);
  4921. } else {
  4922. // Typing rest params is awkward, so punting on that for now
  4923. param = rest
  4924. ? parseVariableIdentifier()
  4925. : parseTypeAnnotatableIdentifier();
  4926. validateParam(options, token, token.value);
  4927. if (match('=')) {
  4928. if (rest) {
  4929. throwErrorTolerant(lookahead, Messages.DefaultRestParameter);
  4930. }
  4931. lex();
  4932. def = parseAssignmentExpression();
  4933. ++options.defaultCount;
  4934. }
  4935. }
  4936. if (rest) {
  4937. if (!match(')')) {
  4938. throwError({}, Messages.ParameterAfterRestParameter);
  4939. }
  4940. options.rest = param;
  4941. return false;
  4942. }
  4943. options.params.push(param);
  4944. options.defaults.push(def);
  4945. return !match(')');
  4946. }
  4947. function parseParams(firstRestricted) {
  4948. var options;
  4949. options = {
  4950. params: [],
  4951. defaultCount: 0,
  4952. defaults: [],
  4953. rest: null,
  4954. firstRestricted: firstRestricted
  4955. };
  4956. expect('(');
  4957. if (!match(')')) {
  4958. options.paramSet = {};
  4959. while (index < length) {
  4960. if (!parseParam(options)) {
  4961. break;
  4962. }
  4963. expect(',');
  4964. }
  4965. }
  4966. expect(')');
  4967. if (options.defaultCount === 0) {
  4968. options.defaults = [];
  4969. }
  4970. if (match(':')) {
  4971. options.returnTypeAnnotation = parseTypeAnnotation();
  4972. }
  4973. return options;
  4974. }
  4975. function parseFunctionDeclaration() {
  4976. var id, body, token, tmp, firstRestricted, message, previousStrict, previousYieldAllowed, generator;
  4977. expectKeyword('function');
  4978. generator = false;
  4979. if (match('*')) {
  4980. lex();
  4981. generator = true;
  4982. }
  4983. token = lookahead;
  4984. id = parseVariableIdentifier();
  4985. if (strict) {
  4986. if (isRestrictedWord(token.value)) {
  4987. throwErrorTolerant(token, Messages.StrictFunctionName);
  4988. }
  4989. } else {
  4990. if (isRestrictedWord(token.value)) {
  4991. firstRestricted = token;
  4992. message = Messages.StrictFunctionName;
  4993. } else if (isStrictModeReservedWord(token.value)) {
  4994. firstRestricted = token;
  4995. message = Messages.StrictReservedWord;
  4996. }
  4997. }
  4998. tmp = parseParams(firstRestricted);
  4999. firstRestricted = tmp.firstRestricted;
  5000. if (tmp.message) {
  5001. message = tmp.message;
  5002. }
  5003. previousStrict = strict;
  5004. previousYieldAllowed = state.yieldAllowed;
  5005. state.yieldAllowed = generator;
  5006. body = parseFunctionSourceElements();
  5007. if (strict && firstRestricted) {
  5008. throwError(firstRestricted, message);
  5009. }
  5010. if (strict && tmp.stricted) {
  5011. throwErrorTolerant(tmp.stricted, message);
  5012. }
  5013. if (state.yieldAllowed && !state.yieldFound) {
  5014. throwErrorTolerant({}, Messages.NoYieldInGenerator);
  5015. }
  5016. strict = previousStrict;
  5017. state.yieldAllowed = previousYieldAllowed;
  5018. return delegate.createFunctionDeclaration(id, tmp.params, tmp.defaults, body, tmp.rest, generator, false,
  5019. tmp.returnTypeAnnotation);
  5020. }
  5021. function parseFunctionExpression() {
  5022. var token, id = null, firstRestricted, message, tmp, body, previousStrict, previousYieldAllowed, generator;
  5023. expectKeyword('function');
  5024. generator = false;
  5025. if (match('*')) {
  5026. lex();
  5027. generator = true;
  5028. }
  5029. if (!match('(')) {
  5030. token = lookahead;
  5031. id = parseVariableIdentifier();
  5032. if (strict) {
  5033. if (isRestrictedWord(token.value)) {
  5034. throwErrorTolerant(token, Messages.StrictFunctionName);
  5035. }
  5036. } else {
  5037. if (isRestrictedWord(token.value)) {
  5038. firstRestricted = token;
  5039. message = Messages.StrictFunctionName;
  5040. } else if (isStrictModeReservedWord(token.value)) {
  5041. firstRestricted = token;
  5042. message = Messages.StrictReservedWord;
  5043. }
  5044. }
  5045. }
  5046. tmp = parseParams(firstRestricted);
  5047. firstRestricted = tmp.firstRestricted;
  5048. if (tmp.message) {
  5049. message = tmp.message;
  5050. }
  5051. previousStrict = strict;
  5052. previousYieldAllowed = state.yieldAllowed;
  5053. state.yieldAllowed = generator;
  5054. body = parseFunctionSourceElements();
  5055. if (strict && firstRestricted) {
  5056. throwError(firstRestricted, message);
  5057. }
  5058. if (strict && tmp.stricted) {
  5059. throwErrorTolerant(tmp.stricted, message);
  5060. }
  5061. if (state.yieldAllowed && !state.yieldFound) {
  5062. throwErrorTolerant({}, Messages.NoYieldInGenerator);
  5063. }
  5064. strict = previousStrict;
  5065. state.yieldAllowed = previousYieldAllowed;
  5066. return delegate.createFunctionExpression(id, tmp.params, tmp.defaults, body, tmp.rest, generator, false,
  5067. tmp.returnTypeAnnotation);
  5068. }
  5069. function parseYieldExpression() {
  5070. var delegateFlag, expr;
  5071. expectKeyword('yield');
  5072. if (!state.yieldAllowed) {
  5073. throwErrorTolerant({}, Messages.IllegalYield);
  5074. }
  5075. delegateFlag = false;
  5076. if (match('*')) {
  5077. lex();
  5078. delegateFlag = true;
  5079. }
  5080. expr = parseAssignmentExpression();
  5081. state.yieldFound = true;
  5082. return delegate.createYieldExpression(expr, delegateFlag);
  5083. }
  5084. // 14 Classes
  5085. function parseMethodDefinition(existingPropNames) {
  5086. var token, key, param, propType, isValidDuplicateProp = false;
  5087. if (lookahead.value === 'static') {
  5088. propType = ClassPropertyType["static"];
  5089. lex();
  5090. } else {
  5091. propType = ClassPropertyType.prototype;
  5092. }
  5093. if (match('*')) {
  5094. lex();
  5095. return delegate.createMethodDefinition(
  5096. propType,
  5097. '',
  5098. parseObjectPropertyKey(),
  5099. parsePropertyMethodFunction({ generator: true })
  5100. );
  5101. }
  5102. token = lookahead;
  5103. key = parseObjectPropertyKey();
  5104. if (token.value === 'get' && !match('(')) {
  5105. key = parseObjectPropertyKey();
  5106. // It is a syntax error if any other properties have a name
  5107. // duplicating this one unless they are a setter
  5108. if (existingPropNames[propType].hasOwnProperty(key.name)) {
  5109. isValidDuplicateProp =
  5110. // There isn't already a getter for this prop
  5111. existingPropNames[propType][key.name].get === undefined
  5112. // There isn't already a data prop by this name
  5113. && existingPropNames[propType][key.name].data === undefined
  5114. // The only existing prop by this name is a setter
  5115. && existingPropNames[propType][key.name].set !== undefined;
  5116. if (!isValidDuplicateProp) {
  5117. throwError(key, Messages.IllegalDuplicateClassProperty);
  5118. }
  5119. } else {
  5120. existingPropNames[propType][key.name] = {};
  5121. }
  5122. existingPropNames[propType][key.name].get = true;
  5123. expect('(');
  5124. expect(')');
  5125. return delegate.createMethodDefinition(
  5126. propType,
  5127. 'get',
  5128. key,
  5129. parsePropertyFunction({ generator: false })
  5130. );
  5131. }
  5132. if (token.value === 'set' && !match('(')) {
  5133. key = parseObjectPropertyKey();
  5134. // It is a syntax error if any other properties have a name
  5135. // duplicating this one unless they are a getter
  5136. if (existingPropNames[propType].hasOwnProperty(key.name)) {
  5137. isValidDuplicateProp =
  5138. // There isn't already a setter for this prop
  5139. existingPropNames[propType][key.name].set === undefined
  5140. // There isn't already a data prop by this name
  5141. && existingPropNames[propType][key.name].data === undefined
  5142. // The only existing prop by this name is a getter
  5143. && existingPropNames[propType][key.name].get !== undefined;
  5144. if (!isValidDuplicateProp) {
  5145. throwError(key, Messages.IllegalDuplicateClassProperty);
  5146. }
  5147. } else {
  5148. existingPropNames[propType][key.name] = {};
  5149. }
  5150. existingPropNames[propType][key.name].set = true;
  5151. expect('(');
  5152. token = lookahead;
  5153. param = [parseTypeAnnotatableIdentifier()];
  5154. expect(')');
  5155. return delegate.createMethodDefinition(
  5156. propType,
  5157. 'set',
  5158. key,
  5159. parsePropertyFunction({ params: param, generator: false, name: token })
  5160. );
  5161. }
  5162. // It is a syntax error if any other properties have the same name as a
  5163. // non-getter, non-setter method
  5164. if (existingPropNames[propType].hasOwnProperty(key.name)) {
  5165. throwError(key, Messages.IllegalDuplicateClassProperty);
  5166. } else {
  5167. existingPropNames[propType][key.name] = {};
  5168. }
  5169. existingPropNames[propType][key.name].data = true;
  5170. return delegate.createMethodDefinition(
  5171. propType,
  5172. '',
  5173. key,
  5174. parsePropertyMethodFunction({ generator: false })
  5175. );
  5176. }
  5177. function parseClassElement(existingProps) {
  5178. if (match(';')) {
  5179. lex();
  5180. return;
  5181. }
  5182. return parseMethodDefinition(existingProps);
  5183. }
  5184. function parseClassBody() {
  5185. var classElement, classElements = [], existingProps = {};
  5186. existingProps[ClassPropertyType["static"]] = {};
  5187. existingProps[ClassPropertyType.prototype] = {};
  5188. expect('{');
  5189. while (index < length) {
  5190. if (match('}')) {
  5191. break;
  5192. }
  5193. classElement = parseClassElement(existingProps);
  5194. if (typeof classElement !== 'undefined') {
  5195. classElements.push(classElement);
  5196. }
  5197. }
  5198. expect('}');
  5199. return delegate.createClassBody(classElements);
  5200. }
  5201. function parseClassExpression() {
  5202. var id, previousYieldAllowed, superClass = null;
  5203. expectKeyword('class');
  5204. if (!matchKeyword('extends') && !match('{')) {
  5205. id = parseVariableIdentifier();
  5206. }
  5207. if (matchKeyword('extends')) {
  5208. expectKeyword('extends');
  5209. previousYieldAllowed = state.yieldAllowed;
  5210. state.yieldAllowed = false;
  5211. superClass = parseAssignmentExpression();
  5212. state.yieldAllowed = previousYieldAllowed;
  5213. }
  5214. return delegate.createClassExpression(id, superClass, parseClassBody());
  5215. }
  5216. function parseClassDeclaration() {
  5217. var id, previousYieldAllowed, superClass = null;
  5218. expectKeyword('class');
  5219. id = parseVariableIdentifier();
  5220. if (matchKeyword('extends')) {
  5221. expectKeyword('extends');
  5222. previousYieldAllowed = state.yieldAllowed;
  5223. state.yieldAllowed = false;
  5224. superClass = parseAssignmentExpression();
  5225. state.yieldAllowed = previousYieldAllowed;
  5226. }
  5227. return delegate.createClassDeclaration(id, superClass, parseClassBody());
  5228. }
  5229. // 15 Program
  5230. function matchModuleDeclaration() {
  5231. var id;
  5232. if (matchContextualKeyword('module')) {
  5233. id = lookahead2();
  5234. return id.type === Token.StringLiteral || id.type === Token.Identifier;
  5235. }
  5236. return false;
  5237. }
  5238. function parseSourceElement() {
  5239. if (lookahead.type === Token.Keyword) {
  5240. switch (lookahead.value) {
  5241. case 'const':
  5242. case 'let':
  5243. return parseConstLetDeclaration(lookahead.value);
  5244. case 'function':
  5245. return parseFunctionDeclaration();
  5246. case 'export':
  5247. return parseExportDeclaration();
  5248. case 'import':
  5249. return parseImportDeclaration();
  5250. default:
  5251. return parseStatement();
  5252. }
  5253. }
  5254. if (matchModuleDeclaration()) {
  5255. throwError({}, Messages.NestedModule);
  5256. }
  5257. if (lookahead.type !== Token.EOF) {
  5258. return parseStatement();
  5259. }
  5260. }
  5261. function parseProgramElement() {
  5262. if (lookahead.type === Token.Keyword) {
  5263. switch (lookahead.value) {
  5264. case 'export':
  5265. return parseExportDeclaration();
  5266. case 'import':
  5267. return parseImportDeclaration();
  5268. }
  5269. }
  5270. if (matchModuleDeclaration()) {
  5271. return parseModuleDeclaration();
  5272. }
  5273. return parseSourceElement();
  5274. }
  5275. function parseProgramElements() {
  5276. var sourceElement, sourceElements = [], token, directive, firstRestricted;
  5277. while (index < length) {
  5278. token = lookahead;
  5279. if (token.type !== Token.StringLiteral) {
  5280. break;
  5281. }
  5282. sourceElement = parseProgramElement();
  5283. sourceElements.push(sourceElement);
  5284. if (sourceElement.expression.type !== Syntax.Literal) {
  5285. // this is not directive
  5286. break;
  5287. }
  5288. directive = source.slice(token.range[0] + 1, token.range[1] - 1);
  5289. if (directive === 'use strict') {
  5290. strict = true;
  5291. if (firstRestricted) {
  5292. throwErrorTolerant(firstRestricted, Messages.StrictOctalLiteral);
  5293. }
  5294. } else {
  5295. if (!firstRestricted && token.octal) {
  5296. firstRestricted = token;
  5297. }
  5298. }
  5299. }
  5300. while (index < length) {
  5301. sourceElement = parseProgramElement();
  5302. if (typeof sourceElement === 'undefined') {
  5303. break;
  5304. }
  5305. sourceElements.push(sourceElement);
  5306. }
  5307. return sourceElements;
  5308. }
  5309. function parseModuleElement() {
  5310. return parseSourceElement();
  5311. }
  5312. function parseModuleElements() {
  5313. var list = [],
  5314. statement;
  5315. while (index < length) {
  5316. if (match('}')) {
  5317. break;
  5318. }
  5319. statement = parseModuleElement();
  5320. if (typeof statement === 'undefined') {
  5321. break;
  5322. }
  5323. list.push(statement);
  5324. }
  5325. return list;
  5326. }
  5327. function parseModuleBlock() {
  5328. var block;
  5329. expect('{');
  5330. block = parseModuleElements();
  5331. expect('}');
  5332. return delegate.createBlockStatement(block);
  5333. }
  5334. function parseProgram() {
  5335. var body;
  5336. strict = false;
  5337. peek();
  5338. body = parseProgramElements();
  5339. return delegate.createProgram(body);
  5340. }
  5341. // The following functions are needed only when the option to preserve
  5342. // the comments is active.
  5343. function addComment(type, value, start, end, loc) {
  5344. assert(typeof start === 'number', 'Comment must have valid position');
  5345. // Because the way the actual token is scanned, often the comments
  5346. // (if any) are skipped twice during the lexical analysis.
  5347. // Thus, we need to skip adding a comment if the comment array already
  5348. // handled it.
  5349. if (extra.comments.length > 0) {
  5350. if (extra.comments[extra.comments.length - 1].range[1] > start) {
  5351. return;
  5352. }
  5353. }
  5354. extra.comments.push({
  5355. type: type,
  5356. value: value,
  5357. range: [start, end],
  5358. loc: loc
  5359. });
  5360. }
  5361. function scanComment() {
  5362. var comment, ch, loc, start, blockComment, lineComment;
  5363. comment = '';
  5364. blockComment = false;
  5365. lineComment = false;
  5366. while (index < length) {
  5367. ch = source[index];
  5368. if (lineComment) {
  5369. ch = source[index++];
  5370. if (isLineTerminator(ch.charCodeAt(0))) {
  5371. loc.end = {
  5372. line: lineNumber,
  5373. column: index - lineStart - 1
  5374. };
  5375. lineComment = false;
  5376. addComment('Line', comment, start, index - 1, loc);
  5377. if (ch === '\r' && source[index] === '\n') {
  5378. ++index;
  5379. }
  5380. ++lineNumber;
  5381. lineStart = index;
  5382. comment = '';
  5383. } else if (index >= length) {
  5384. lineComment = false;
  5385. comment += ch;
  5386. loc.end = {
  5387. line: lineNumber,
  5388. column: length - lineStart
  5389. };
  5390. addComment('Line', comment, start, length, loc);
  5391. } else {
  5392. comment += ch;
  5393. }
  5394. } else if (blockComment) {
  5395. if (isLineTerminator(ch.charCodeAt(0))) {
  5396. if (ch === '\r' && source[index + 1] === '\n') {
  5397. ++index;
  5398. comment += '\r\n';
  5399. } else {
  5400. comment += ch;
  5401. }
  5402. ++lineNumber;
  5403. ++index;
  5404. lineStart = index;
  5405. if (index >= length) {
  5406. throwError({}, Messages.UnexpectedToken, 'ILLEGAL');
  5407. }
  5408. } else {
  5409. ch = source[index++];
  5410. if (index >= length) {
  5411. throwError({}, Messages.UnexpectedToken, 'ILLEGAL');
  5412. }
  5413. comment += ch;
  5414. if (ch === '*') {
  5415. ch = source[index];
  5416. if (ch === '/') {
  5417. comment = comment.substr(0, comment.length - 1);
  5418. blockComment = false;
  5419. ++index;
  5420. loc.end = {
  5421. line: lineNumber,
  5422. column: index - lineStart
  5423. };
  5424. addComment('Block', comment, start, index, loc);
  5425. comment = '';
  5426. }
  5427. }
  5428. }
  5429. } else if (ch === '/') {
  5430. ch = source[index + 1];
  5431. if (ch === '/') {
  5432. loc = {
  5433. start: {
  5434. line: lineNumber,
  5435. column: index - lineStart
  5436. }
  5437. };
  5438. start = index;
  5439. index += 2;
  5440. lineComment = true;
  5441. if (index >= length) {
  5442. loc.end = {
  5443. line: lineNumber,
  5444. column: index - lineStart
  5445. };
  5446. lineComment = false;
  5447. addComment('Line', comment, start, index, loc);
  5448. }
  5449. } else if (ch === '*') {
  5450. start = index;
  5451. index += 2;
  5452. blockComment = true;
  5453. loc = {
  5454. start: {
  5455. line: lineNumber,
  5456. column: index - lineStart - 2
  5457. }
  5458. };
  5459. if (index >= length) {
  5460. throwError({}, Messages.UnexpectedToken, 'ILLEGAL');
  5461. }
  5462. } else {
  5463. break;
  5464. }
  5465. } else if (isWhiteSpace(ch.charCodeAt(0))) {
  5466. ++index;
  5467. } else if (isLineTerminator(ch.charCodeAt(0))) {
  5468. ++index;
  5469. if (ch === '\r' && source[index] === '\n') {
  5470. ++index;
  5471. }
  5472. ++lineNumber;
  5473. lineStart = index;
  5474. } else {
  5475. break;
  5476. }
  5477. }
  5478. }
  5479. function filterCommentLocation() {
  5480. var i, entry, comment, comments = [];
  5481. for (i = 0; i < extra.comments.length; ++i) {
  5482. entry = extra.comments[i];
  5483. comment = {
  5484. type: entry.type,
  5485. value: entry.value
  5486. };
  5487. if (extra.range) {
  5488. comment.range = entry.range;
  5489. }
  5490. if (extra.loc) {
  5491. comment.loc = entry.loc;
  5492. }
  5493. comments.push(comment);
  5494. }
  5495. extra.comments = comments;
  5496. }
  5497. // 16 XJS
  5498. XHTMLEntities = {
  5499. quot: '\u0022',
  5500. amp: '&',
  5501. apos: "\u0027",
  5502. lt: "<",
  5503. gt: ">",
  5504. nbsp: "\u00A0",
  5505. iexcl: "\u00A1",
  5506. cent: "\u00A2",
  5507. pound: "\u00A3",
  5508. curren: "\u00A4",
  5509. yen: "\u00A5",
  5510. brvbar: "\u00A6",
  5511. sect: "\u00A7",
  5512. uml: "\u00A8",
  5513. copy: "\u00A9",
  5514. ordf: "\u00AA",
  5515. laquo: "\u00AB",
  5516. not: "\u00AC",
  5517. shy: "\u00AD",
  5518. reg: "\u00AE",
  5519. macr: "\u00AF",
  5520. deg: "\u00B0",
  5521. plusmn: "\u00B1",
  5522. sup2: "\u00B2",
  5523. sup3: "\u00B3",
  5524. acute: "\u00B4",
  5525. micro: "\u00B5",
  5526. para: "\u00B6",
  5527. middot: "\u00B7",
  5528. cedil: "\u00B8",
  5529. sup1: "\u00B9",
  5530. ordm: "\u00BA",
  5531. raquo: "\u00BB",
  5532. frac14: "\u00BC",
  5533. frac12: "\u00BD",
  5534. frac34: "\u00BE",
  5535. iquest: "\u00BF",
  5536. Agrave: "\u00C0",
  5537. Aacute: "\u00C1",
  5538. Acirc: "\u00C2",
  5539. Atilde: "\u00C3",
  5540. Auml: "\u00C4",
  5541. Aring: "\u00C5",
  5542. AElig: "\u00C6",
  5543. Ccedil: "\u00C7",
  5544. Egrave: "\u00C8",
  5545. Eacute: "\u00C9",
  5546. Ecirc: "\u00CA",
  5547. Euml: "\u00CB",
  5548. Igrave: "\u00CC",
  5549. Iacute: "\u00CD",
  5550. Icirc: "\u00CE",
  5551. Iuml: "\u00CF",
  5552. ETH: "\u00D0",
  5553. Ntilde: "\u00D1",
  5554. Ograve: "\u00D2",
  5555. Oacute: "\u00D3",
  5556. Ocirc: "\u00D4",
  5557. Otilde: "\u00D5",
  5558. Ouml: "\u00D6",
  5559. times: "\u00D7",
  5560. Oslash: "\u00D8",
  5561. Ugrave: "\u00D9",
  5562. Uacute: "\u00DA",
  5563. Ucirc: "\u00DB",
  5564. Uuml: "\u00DC",
  5565. Yacute: "\u00DD",
  5566. THORN: "\u00DE",
  5567. szlig: "\u00DF",
  5568. agrave: "\u00E0",
  5569. aacute: "\u00E1",
  5570. acirc: "\u00E2",
  5571. atilde: "\u00E3",
  5572. auml: "\u00E4",
  5573. aring: "\u00E5",
  5574. aelig: "\u00E6",
  5575. ccedil: "\u00E7",
  5576. egrave: "\u00E8",
  5577. eacute: "\u00E9",
  5578. ecirc: "\u00EA",
  5579. euml: "\u00EB",
  5580. igrave: "\u00EC",
  5581. iacute: "\u00ED",
  5582. icirc: "\u00EE",
  5583. iuml: "\u00EF",
  5584. eth: "\u00F0",
  5585. ntilde: "\u00F1",
  5586. ograve: "\u00F2",
  5587. oacute: "\u00F3",
  5588. ocirc: "\u00F4",
  5589. otilde: "\u00F5",
  5590. ouml: "\u00F6",
  5591. divide: "\u00F7",
  5592. oslash: "\u00F8",
  5593. ugrave: "\u00F9",
  5594. uacute: "\u00FA",
  5595. ucirc: "\u00FB",
  5596. uuml: "\u00FC",
  5597. yacute: "\u00FD",
  5598. thorn: "\u00FE",
  5599. yuml: "\u00FF",
  5600. OElig: "\u0152",
  5601. oelig: "\u0153",
  5602. Scaron: "\u0160",
  5603. scaron: "\u0161",
  5604. Yuml: "\u0178",
  5605. fnof: "\u0192",
  5606. circ: "\u02C6",
  5607. tilde: "\u02DC",
  5608. Alpha: "\u0391",
  5609. Beta: "\u0392",
  5610. Gamma: "\u0393",
  5611. Delta: "\u0394",
  5612. Epsilon: "\u0395",
  5613. Zeta: "\u0396",
  5614. Eta: "\u0397",
  5615. Theta: "\u0398",
  5616. Iota: "\u0399",
  5617. Kappa: "\u039A",
  5618. Lambda: "\u039B",
  5619. Mu: "\u039C",
  5620. Nu: "\u039D",
  5621. Xi: "\u039E",
  5622. Omicron: "\u039F",
  5623. Pi: "\u03A0",
  5624. Rho: "\u03A1",
  5625. Sigma: "\u03A3",
  5626. Tau: "\u03A4",
  5627. Upsilon: "\u03A5",
  5628. Phi: "\u03A6",
  5629. Chi: "\u03A7",
  5630. Psi: "\u03A8",
  5631. Omega: "\u03A9",
  5632. alpha: "\u03B1",
  5633. beta: "\u03B2",
  5634. gamma: "\u03B3",
  5635. delta: "\u03B4",
  5636. epsilon: "\u03B5",
  5637. zeta: "\u03B6",
  5638. eta: "\u03B7",
  5639. theta: "\u03B8",
  5640. iota: "\u03B9",
  5641. kappa: "\u03BA",
  5642. lambda: "\u03BB",
  5643. mu: "\u03BC",
  5644. nu: "\u03BD",
  5645. xi: "\u03BE",
  5646. omicron: "\u03BF",
  5647. pi: "\u03C0",
  5648. rho: "\u03C1",
  5649. sigmaf: "\u03C2",
  5650. sigma: "\u03C3",
  5651. tau: "\u03C4",
  5652. upsilon: "\u03C5",
  5653. phi: "\u03C6",
  5654. chi: "\u03C7",
  5655. psi: "\u03C8",
  5656. omega: "\u03C9",
  5657. thetasym: "\u03D1",
  5658. upsih: "\u03D2",
  5659. piv: "\u03D6",
  5660. ensp: "\u2002",
  5661. emsp: "\u2003",
  5662. thinsp: "\u2009",
  5663. zwnj: "\u200C",
  5664. zwj: "\u200D",
  5665. lrm: "\u200E",
  5666. rlm: "\u200F",
  5667. ndash: "\u2013",
  5668. mdash: "\u2014",
  5669. lsquo: "\u2018",
  5670. rsquo: "\u2019",
  5671. sbquo: "\u201A",
  5672. ldquo: "\u201C",
  5673. rdquo: "\u201D",
  5674. bdquo: "\u201E",
  5675. dagger: "\u2020",
  5676. Dagger: "\u2021",
  5677. bull: "\u2022",
  5678. hellip: "\u2026",
  5679. permil: "\u2030",
  5680. prime: "\u2032",
  5681. Prime: "\u2033",
  5682. lsaquo: "\u2039",
  5683. rsaquo: "\u203A",
  5684. oline: "\u203E",
  5685. frasl: "\u2044",
  5686. euro: "\u20AC",
  5687. image: "\u2111",
  5688. weierp: "\u2118",
  5689. real: "\u211C",
  5690. trade: "\u2122",
  5691. alefsym: "\u2135",
  5692. larr: "\u2190",
  5693. uarr: "\u2191",
  5694. rarr: "\u2192",
  5695. darr: "\u2193",
  5696. harr: "\u2194",
  5697. crarr: "\u21B5",
  5698. lArr: "\u21D0",
  5699. uArr: "\u21D1",
  5700. rArr: "\u21D2",
  5701. dArr: "\u21D3",
  5702. hArr: "\u21D4",
  5703. forall: "\u2200",
  5704. part: "\u2202",
  5705. exist: "\u2203",
  5706. empty: "\u2205",
  5707. nabla: "\u2207",
  5708. isin: "\u2208",
  5709. notin: "\u2209",
  5710. ni: "\u220B",
  5711. prod: "\u220F",
  5712. sum: "\u2211",
  5713. minus: "\u2212",
  5714. lowast: "\u2217",
  5715. radic: "\u221A",
  5716. prop: "\u221D",
  5717. infin: "\u221E",
  5718. ang: "\u2220",
  5719. and: "\u2227",
  5720. or: "\u2228",
  5721. cap: "\u2229",
  5722. cup: "\u222A",
  5723. "int": "\u222B",
  5724. there4: "\u2234",
  5725. sim: "\u223C",
  5726. cong: "\u2245",
  5727. asymp: "\u2248",
  5728. ne: "\u2260",
  5729. equiv: "\u2261",
  5730. le: "\u2264",
  5731. ge: "\u2265",
  5732. sub: "\u2282",
  5733. sup: "\u2283",
  5734. nsub: "\u2284",
  5735. sube: "\u2286",
  5736. supe: "\u2287",
  5737. oplus: "\u2295",
  5738. otimes: "\u2297",
  5739. perp: "\u22A5",
  5740. sdot: "\u22C5",
  5741. lceil: "\u2308",
  5742. rceil: "\u2309",
  5743. lfloor: "\u230A",
  5744. rfloor: "\u230B",
  5745. lang: "\u2329",
  5746. rang: "\u232A",
  5747. loz: "\u25CA",
  5748. spades: "\u2660",
  5749. clubs: "\u2663",
  5750. hearts: "\u2665",
  5751. diams: "\u2666"
  5752. };
  5753. function isXJSIdentifierStart(ch) {
  5754. // exclude backslash (\)
  5755. return (ch !== 92) && isIdentifierStart(ch);
  5756. }
  5757. function isXJSIdentifierPart(ch) {
  5758. // exclude backslash (\) and add hyphen (-)
  5759. return (ch !== 92) && (ch === 45 || isIdentifierPart(ch));
  5760. }
  5761. function scanXJSIdentifier() {
  5762. var ch, start, id = '', namespace;
  5763. start = index;
  5764. while (index < length) {
  5765. ch = source.charCodeAt(index);
  5766. if (!isXJSIdentifierPart(ch)) {
  5767. break;
  5768. }
  5769. id += source[index++];
  5770. }
  5771. if (ch === 58) { // :
  5772. ++index;
  5773. namespace = id;
  5774. id = '';
  5775. while (index < length) {
  5776. ch = source.charCodeAt(index);
  5777. if (!isXJSIdentifierPart(ch)) {
  5778. break;
  5779. }
  5780. id += source[index++];
  5781. }
  5782. }
  5783. if (!id) {
  5784. throwError({}, Messages.InvalidXJSTagName);
  5785. }
  5786. return {
  5787. type: Token.XJSIdentifier,
  5788. value: id,
  5789. namespace: namespace,
  5790. lineNumber: lineNumber,
  5791. lineStart: lineStart,
  5792. range: [start, index]
  5793. };
  5794. }
  5795. function scanXJSEntity() {
  5796. var ch, str = '', count = 0, entity;
  5797. ch = source[index];
  5798. assert(ch === '&', 'Entity must start with an ampersand');
  5799. index++;
  5800. while (index < length && count++ < 10) {
  5801. ch = source[index++];
  5802. if (ch === ';') {
  5803. break;
  5804. }
  5805. str += ch;
  5806. }
  5807. if (str[0] === '#' && str[1] === 'x') {
  5808. entity = String.fromCharCode(parseInt(str.substr(2), 16));
  5809. } else if (str[0] === '#') {
  5810. entity = String.fromCharCode(parseInt(str.substr(1), 10));
  5811. } else {
  5812. entity = XHTMLEntities[str];
  5813. }
  5814. return entity;
  5815. }
  5816. function scanXJSText(stopChars) {
  5817. var ch, str = '', start;
  5818. start = index;
  5819. while (index < length) {
  5820. ch = source[index];
  5821. if (stopChars.indexOf(ch) !== -1) {
  5822. break;
  5823. }
  5824. if (ch === '&') {
  5825. str += scanXJSEntity();
  5826. } else {
  5827. ch = source[index++];
  5828. if (isLineTerminator(ch.charCodeAt(0))) {
  5829. ++lineNumber;
  5830. lineStart = index;
  5831. }
  5832. str += ch;
  5833. }
  5834. }
  5835. return {
  5836. type: Token.XJSText,
  5837. value: str,
  5838. lineNumber: lineNumber,
  5839. lineStart: lineStart,
  5840. range: [start, index]
  5841. };
  5842. }
  5843. function scanXJSStringLiteral() {
  5844. var innerToken, quote, start;
  5845. quote = source[index];
  5846. assert((quote === '\'' || quote === '"'),
  5847. 'String literal must starts with a quote');
  5848. start = index;
  5849. ++index;
  5850. innerToken = scanXJSText([quote]);
  5851. if (quote !== source[index]) {
  5852. throwError({}, Messages.UnexpectedToken, 'ILLEGAL');
  5853. }
  5854. ++index;
  5855. innerToken.range = [start, index];
  5856. return innerToken;
  5857. }
  5858. /**
  5859. * Between XJS opening and closing tags (e.g. <foo>HERE</foo>), anything that
  5860. * is not another XJS tag and is not an expression wrapped by {} is text.
  5861. */
  5862. function advanceXJSChild() {
  5863. var ch = source.charCodeAt(index);
  5864. // { (123) and < (60)
  5865. if (ch !== 123 && ch !== 60) {
  5866. return scanXJSText(['<', '{']);
  5867. }
  5868. return scanPunctuator();
  5869. }
  5870. function parseXJSIdentifier() {
  5871. var token;
  5872. if (lookahead.type !== Token.XJSIdentifier) {
  5873. throwUnexpected(lookahead);
  5874. }
  5875. token = lex();
  5876. return delegate.createXJSIdentifier(token.value, token.namespace);
  5877. }
  5878. function parseXJSAttributeValue() {
  5879. var value;
  5880. if (match('{')) {
  5881. value = parseXJSExpressionContainer();
  5882. if (value.expression.type === Syntax.XJSEmptyExpression) {
  5883. throwError(
  5884. value,
  5885. 'XJS attributes must only be assigned a non-empty ' +
  5886. 'expression'
  5887. );
  5888. }
  5889. } else if (match('<')) {
  5890. value = parseXJSElement();
  5891. } else if (lookahead.type === Token.XJSText) {
  5892. value = delegate.createLiteral(lex());
  5893. } else {
  5894. throwError({}, Messages.InvalidXJSAttributeValue);
  5895. }
  5896. return value;
  5897. }
  5898. function parseXJSEmptyExpression() {
  5899. while (source.charAt(index) !== '}') {
  5900. index++;
  5901. }
  5902. return delegate.createXJSEmptyExpression();
  5903. }
  5904. function parseXJSExpressionContainer() {
  5905. var expression, origInXJSChild, origInXJSTag;
  5906. origInXJSChild = state.inXJSChild;
  5907. origInXJSTag = state.inXJSTag;
  5908. state.inXJSChild = false;
  5909. state.inXJSTag = false;
  5910. expect('{');
  5911. if (match('}')) {
  5912. expression = parseXJSEmptyExpression();
  5913. } else {
  5914. expression = parseExpression();
  5915. }
  5916. state.inXJSChild = origInXJSChild;
  5917. state.inXJSTag = origInXJSTag;
  5918. expect('}');
  5919. return delegate.createXJSExpressionContainer(expression);
  5920. }
  5921. function parseXJSAttribute() {
  5922. var token, name, value;
  5923. name = parseXJSIdentifier();
  5924. // HTML empty attribute
  5925. if (match('=')) {
  5926. lex();
  5927. return delegate.createXJSAttribute(name, parseXJSAttributeValue());
  5928. }
  5929. return delegate.createXJSAttribute(name);
  5930. }
  5931. function parseXJSChild() {
  5932. var token;
  5933. if (match('{')) {
  5934. token = parseXJSExpressionContainer();
  5935. } else if (lookahead.type === Token.XJSText) {
  5936. token = delegate.createLiteral(lex());
  5937. } else {
  5938. token = parseXJSElement();
  5939. }
  5940. return token;
  5941. }
  5942. function parseXJSClosingElement() {
  5943. var name, origInXJSChild, origInXJSTag;
  5944. origInXJSChild = state.inXJSChild;
  5945. origInXJSTag = state.inXJSTag;
  5946. state.inXJSChild = false;
  5947. state.inXJSTag = true;
  5948. expect('<');
  5949. expect('/');
  5950. name = parseXJSIdentifier();
  5951. // Because advance() (called by lex() called by expect()) expects there
  5952. // to be a valid token after >, it needs to know whether to look for a
  5953. // standard JS token or an XJS text node
  5954. state.inXJSChild = origInXJSChild;
  5955. state.inXJSTag = origInXJSTag;
  5956. expect('>');
  5957. return delegate.createXJSClosingElement(name);
  5958. }
  5959. function parseXJSOpeningElement() {
  5960. var name, attribute, attributes = [], selfClosing = false, origInXJSChild, origInXJSTag;
  5961. origInXJSChild = state.inXJSChild;
  5962. origInXJSTag = state.inXJSTag;
  5963. state.inXJSChild = false;
  5964. state.inXJSTag = true;
  5965. expect('<');
  5966. name = parseXJSIdentifier();
  5967. while (index < length &&
  5968. lookahead.value !== '/' &&
  5969. lookahead.value !== '>') {
  5970. attributes.push(parseXJSAttribute());
  5971. }
  5972. state.inXJSTag = origInXJSTag;
  5973. if (lookahead.value === '/') {
  5974. expect('/');
  5975. // Because advance() (called by lex() called by expect()) expects
  5976. // there to be a valid token after >, it needs to know whether to
  5977. // look for a standard JS token or an XJS text node
  5978. state.inXJSChild = origInXJSChild;
  5979. expect('>');
  5980. selfClosing = true;
  5981. } else {
  5982. state.inXJSChild = true;
  5983. expect('>');
  5984. }
  5985. return delegate.createXJSOpeningElement(name, attributes, selfClosing);
  5986. }
  5987. function parseXJSElement() {
  5988. var openingElement, closingElement, children = [], origInXJSChild, origInXJSTag;
  5989. origInXJSChild = state.inXJSChild;
  5990. origInXJSTag = state.inXJSTag;
  5991. openingElement = parseXJSOpeningElement();
  5992. if (!openingElement.selfClosing) {
  5993. while (index < length) {
  5994. state.inXJSChild = false; // Call lookahead2() with inXJSChild = false because </ should not be considered in the child
  5995. if (lookahead.value === '<' && lookahead2().value === '/') {
  5996. break;
  5997. }
  5998. state.inXJSChild = true;
  5999. peek(); // reset lookahead token
  6000. children.push(parseXJSChild());
  6001. }
  6002. state.inXJSChild = origInXJSChild;
  6003. state.inXJSTag = origInXJSTag;
  6004. closingElement = parseXJSClosingElement();
  6005. if (closingElement.name.namespace !== openingElement.name.namespace || closingElement.name.name !== openingElement.name.name) {
  6006. throwError({}, Messages.ExpectedXJSClosingTag, openingElement.name.namespace ? openingElement.name.namespace + ':' + openingElement.name.name : openingElement.name.name);
  6007. }
  6008. }
  6009. return delegate.createXJSElement(openingElement, closingElement, children);
  6010. }
  6011. function collectToken() {
  6012. var start, loc, token, range, value;
  6013. skipComment();
  6014. start = index;
  6015. loc = {
  6016. start: {
  6017. line: lineNumber,
  6018. column: index - lineStart
  6019. }
  6020. };
  6021. token = extra.advance();
  6022. loc.end = {
  6023. line: lineNumber,
  6024. column: index - lineStart
  6025. };
  6026. if (token.type !== Token.EOF) {
  6027. range = [token.range[0], token.range[1]];
  6028. value = source.slice(token.range[0], token.range[1]);
  6029. extra.tokens.push({
  6030. type: TokenName[token.type],
  6031. value: value,
  6032. range: range,
  6033. loc: loc
  6034. });
  6035. }
  6036. return token;
  6037. }
  6038. function collectRegex() {
  6039. var pos, loc, regex, token;
  6040. skipComment();
  6041. pos = index;
  6042. loc = {
  6043. start: {
  6044. line: lineNumber,
  6045. column: index - lineStart
  6046. }
  6047. };
  6048. regex = extra.scanRegExp();
  6049. loc.end = {
  6050. line: lineNumber,
  6051. column: index - lineStart
  6052. };
  6053. if (!extra.tokenize) {
  6054. // Pop the previous token, which is likely '/' or '/='
  6055. if (extra.tokens.length > 0) {
  6056. token = extra.tokens[extra.tokens.length - 1];
  6057. if (token.range[0] === pos && token.type === 'Punctuator') {
  6058. if (token.value === '/' || token.value === '/=') {
  6059. extra.tokens.pop();
  6060. }
  6061. }
  6062. }
  6063. extra.tokens.push({
  6064. type: 'RegularExpression',
  6065. value: regex.literal,
  6066. range: [pos, index],
  6067. loc: loc
  6068. });
  6069. }
  6070. return regex;
  6071. }
  6072. function filterTokenLocation() {
  6073. var i, entry, token, tokens = [];
  6074. for (i = 0; i < extra.tokens.length; ++i) {
  6075. entry = extra.tokens[i];
  6076. token = {
  6077. type: entry.type,
  6078. value: entry.value
  6079. };
  6080. if (extra.range) {
  6081. token.range = entry.range;
  6082. }
  6083. if (extra.loc) {
  6084. token.loc = entry.loc;
  6085. }
  6086. tokens.push(token);
  6087. }
  6088. extra.tokens = tokens;
  6089. }
  6090. function LocationMarker() {
  6091. this.range = [index, index];
  6092. this.loc = {
  6093. start: {
  6094. line: lineNumber,
  6095. column: index - lineStart
  6096. },
  6097. end: {
  6098. line: lineNumber,
  6099. column: index - lineStart
  6100. }
  6101. };
  6102. }
  6103. LocationMarker.prototype = {
  6104. constructor: LocationMarker,
  6105. end: function () {
  6106. this.range[1] = index;
  6107. this.loc.end.line = lineNumber;
  6108. this.loc.end.column = index - lineStart;
  6109. },
  6110. applyGroup: function (node) {
  6111. if (extra.range) {
  6112. node.groupRange = [this.range[0], this.range[1]];
  6113. }
  6114. if (extra.loc) {
  6115. node.groupLoc = {
  6116. start: {
  6117. line: this.loc.start.line,
  6118. column: this.loc.start.column
  6119. },
  6120. end: {
  6121. line: this.loc.end.line,
  6122. column: this.loc.end.column
  6123. }
  6124. };
  6125. node = delegate.postProcess(node);
  6126. }
  6127. },
  6128. apply: function (node) {
  6129. var nodeType = typeof node;
  6130. assert(nodeType === 'object',
  6131. 'Applying location marker to an unexpected node type: ' +
  6132. nodeType);
  6133. if (extra.range) {
  6134. node.range = [this.range[0], this.range[1]];
  6135. }
  6136. if (extra.loc) {
  6137. node.loc = {
  6138. start: {
  6139. line: this.loc.start.line,
  6140. column: this.loc.start.column
  6141. },
  6142. end: {
  6143. line: this.loc.end.line,
  6144. column: this.loc.end.column
  6145. }
  6146. };
  6147. node = delegate.postProcess(node);
  6148. }
  6149. }
  6150. };
  6151. function createLocationMarker() {
  6152. return new LocationMarker();
  6153. }
  6154. function trackGroupExpression() {
  6155. var marker, expr;
  6156. skipComment();
  6157. marker = createLocationMarker();
  6158. expect('(');
  6159. ++state.parenthesizedCount;
  6160. expr = parseExpression();
  6161. expect(')');
  6162. marker.end();
  6163. marker.applyGroup(expr);
  6164. return expr;
  6165. }
  6166. function trackLeftHandSideExpression() {
  6167. var marker, expr;
  6168. skipComment();
  6169. marker = createLocationMarker();
  6170. expr = matchKeyword('new') ? parseNewExpression() : parsePrimaryExpression();
  6171. while (match('.') || match('[') || lookahead.type === Token.Template) {
  6172. if (match('[')) {
  6173. expr = delegate.createMemberExpression('[', expr, parseComputedMember());
  6174. marker.end();
  6175. marker.apply(expr);
  6176. } else if (match('.')) {
  6177. expr = delegate.createMemberExpression('.', expr, parseNonComputedMember());
  6178. marker.end();
  6179. marker.apply(expr);
  6180. } else {
  6181. expr = delegate.createTaggedTemplateExpression(expr, parseTemplateLiteral());
  6182. marker.end();
  6183. marker.apply(expr);
  6184. }
  6185. }
  6186. return expr;
  6187. }
  6188. function trackLeftHandSideExpressionAllowCall() {
  6189. var marker, expr, args;
  6190. skipComment();
  6191. marker = createLocationMarker();
  6192. expr = matchKeyword('new') ? parseNewExpression() : parsePrimaryExpression();
  6193. while (match('.') || match('[') || match('(') || lookahead.type === Token.Template) {
  6194. if (match('(')) {
  6195. args = parseArguments();
  6196. expr = delegate.createCallExpression(expr, args);
  6197. marker.end();
  6198. marker.apply(expr);
  6199. } else if (match('[')) {
  6200. expr = delegate.createMemberExpression('[', expr, parseComputedMember());
  6201. marker.end();
  6202. marker.apply(expr);
  6203. } else if (match('.')) {
  6204. expr = delegate.createMemberExpression('.', expr, parseNonComputedMember());
  6205. marker.end();
  6206. marker.apply(expr);
  6207. } else {
  6208. expr = delegate.createTaggedTemplateExpression(expr, parseTemplateLiteral());
  6209. marker.end();
  6210. marker.apply(expr);
  6211. }
  6212. }
  6213. return expr;
  6214. }
  6215. function filterGroup(node) {
  6216. var n, i, entry;
  6217. n = (Object.prototype.toString.apply(node) === '[object Array]') ? [] : {};
  6218. for (i in node) {
  6219. if (node.hasOwnProperty(i) && i !== 'groupRange' && i !== 'groupLoc') {
  6220. entry = node[i];
  6221. if (entry === null || typeof entry !== 'object' || entry instanceof RegExp) {
  6222. n[i] = entry;
  6223. } else {
  6224. n[i] = filterGroup(entry);
  6225. }
  6226. }
  6227. }
  6228. return n;
  6229. }
  6230. function wrapTrackingFunction(range, loc, preserveWhitespace) {
  6231. return function (parseFunction) {
  6232. function isBinary(node) {
  6233. return node.type === Syntax.LogicalExpression ||
  6234. node.type === Syntax.BinaryExpression;
  6235. }
  6236. function visit(node) {
  6237. var start, end;
  6238. if (isBinary(node.left)) {
  6239. visit(node.left);
  6240. }
  6241. if (isBinary(node.right)) {
  6242. visit(node.right);
  6243. }
  6244. if (range) {
  6245. if (node.left.groupRange || node.right.groupRange) {
  6246. start = node.left.groupRange ? node.left.groupRange[0] : node.left.range[0];
  6247. end = node.right.groupRange ? node.right.groupRange[1] : node.right.range[1];
  6248. node.range = [start, end];
  6249. } else if (typeof node.range === 'undefined') {
  6250. start = node.left.range[0];
  6251. end = node.right.range[1];
  6252. node.range = [start, end];
  6253. }
  6254. }
  6255. if (loc) {
  6256. if (node.left.groupLoc || node.right.groupLoc) {
  6257. start = node.left.groupLoc ? node.left.groupLoc.start : node.left.loc.start;
  6258. end = node.right.groupLoc ? node.right.groupLoc.end : node.right.loc.end;
  6259. node.loc = {
  6260. start: start,
  6261. end: end
  6262. };
  6263. node = delegate.postProcess(node);
  6264. } else if (typeof node.loc === 'undefined') {
  6265. node.loc = {
  6266. start: node.left.loc.start,
  6267. end: node.right.loc.end
  6268. };
  6269. node = delegate.postProcess(node);
  6270. }
  6271. }
  6272. }
  6273. return function () {
  6274. var marker, node;
  6275. if (!preserveWhitespace) {
  6276. skipComment();
  6277. }
  6278. marker = createLocationMarker();
  6279. node = parseFunction.apply(null, arguments);
  6280. marker.end();
  6281. if (range && typeof node.range === 'undefined') {
  6282. marker.apply(node);
  6283. }
  6284. if (loc && typeof node.loc === 'undefined') {
  6285. marker.apply(node);
  6286. }
  6287. if (isBinary(node)) {
  6288. visit(node);
  6289. }
  6290. return node;
  6291. };
  6292. };
  6293. }
  6294. function patch() {
  6295. var wrapTracking, wrapTrackingPreserveWhitespace;
  6296. if (extra.comments) {
  6297. extra.skipComment = skipComment;
  6298. skipComment = scanComment;
  6299. }
  6300. if (extra.range || extra.loc) {
  6301. extra.parseGroupExpression = parseGroupExpression;
  6302. extra.parseLeftHandSideExpression = parseLeftHandSideExpression;
  6303. extra.parseLeftHandSideExpressionAllowCall = parseLeftHandSideExpressionAllowCall;
  6304. parseGroupExpression = trackGroupExpression;
  6305. parseLeftHandSideExpression = trackLeftHandSideExpression;
  6306. parseLeftHandSideExpressionAllowCall = trackLeftHandSideExpressionAllowCall;
  6307. wrapTracking = wrapTrackingFunction(extra.range, extra.loc);
  6308. wrapTrackingPreserveWhitespace =
  6309. wrapTrackingFunction(extra.range, extra.loc, true);
  6310. extra.parseArrayInitialiser = parseArrayInitialiser;
  6311. extra.parseAssignmentExpression = parseAssignmentExpression;
  6312. extra.parseBinaryExpression = parseBinaryExpression;
  6313. extra.parseBlock = parseBlock;
  6314. extra.parseFunctionSourceElements = parseFunctionSourceElements;
  6315. extra.parseCatchClause = parseCatchClause;
  6316. extra.parseComputedMember = parseComputedMember;
  6317. extra.parseConditionalExpression = parseConditionalExpression;
  6318. extra.parseConstLetDeclaration = parseConstLetDeclaration;
  6319. extra.parseExportBatchSpecifier = parseExportBatchSpecifier;
  6320. extra.parseExportDeclaration = parseExportDeclaration;
  6321. extra.parseExportSpecifier = parseExportSpecifier;
  6322. extra.parseExpression = parseExpression;
  6323. extra.parseForVariableDeclaration = parseForVariableDeclaration;
  6324. extra.parseFunctionDeclaration = parseFunctionDeclaration;
  6325. extra.parseFunctionExpression = parseFunctionExpression;
  6326. extra.parseParams = parseParams;
  6327. extra.parseImportDeclaration = parseImportDeclaration;
  6328. extra.parseImportSpecifier = parseImportSpecifier;
  6329. extra.parseModuleDeclaration = parseModuleDeclaration;
  6330. extra.parseModuleBlock = parseModuleBlock;
  6331. extra.parseNewExpression = parseNewExpression;
  6332. extra.parseNonComputedProperty = parseNonComputedProperty;
  6333. extra.parseObjectInitialiser = parseObjectInitialiser;
  6334. extra.parseObjectProperty = parseObjectProperty;
  6335. extra.parseObjectPropertyKey = parseObjectPropertyKey;
  6336. extra.parsePostfixExpression = parsePostfixExpression;
  6337. extra.parsePrimaryExpression = parsePrimaryExpression;
  6338. extra.parseProgram = parseProgram;
  6339. extra.parsePropertyFunction = parsePropertyFunction;
  6340. extra.parseSpreadOrAssignmentExpression = parseSpreadOrAssignmentExpression;
  6341. extra.parseTemplateElement = parseTemplateElement;
  6342. extra.parseTemplateLiteral = parseTemplateLiteral;
  6343. extra.parseTypeAnnotatableIdentifier = parseTypeAnnotatableIdentifier;
  6344. extra.parseTypeAnnotation = parseTypeAnnotation;
  6345. extra.parseStatement = parseStatement;
  6346. extra.parseSwitchCase = parseSwitchCase;
  6347. extra.parseUnaryExpression = parseUnaryExpression;
  6348. extra.parseVariableDeclaration = parseVariableDeclaration;
  6349. extra.parseVariableIdentifier = parseVariableIdentifier;
  6350. extra.parseMethodDefinition = parseMethodDefinition;
  6351. extra.parseClassDeclaration = parseClassDeclaration;
  6352. extra.parseClassExpression = parseClassExpression;
  6353. extra.parseClassBody = parseClassBody;
  6354. extra.parseXJSIdentifier = parseXJSIdentifier;
  6355. extra.parseXJSChild = parseXJSChild;
  6356. extra.parseXJSAttribute = parseXJSAttribute;
  6357. extra.parseXJSAttributeValue = parseXJSAttributeValue;
  6358. extra.parseXJSExpressionContainer = parseXJSExpressionContainer;
  6359. extra.parseXJSEmptyExpression = parseXJSEmptyExpression;
  6360. extra.parseXJSElement = parseXJSElement;
  6361. extra.parseXJSClosingElement = parseXJSClosingElement;
  6362. extra.parseXJSOpeningElement = parseXJSOpeningElement;
  6363. parseArrayInitialiser = wrapTracking(extra.parseArrayInitialiser);
  6364. parseAssignmentExpression = wrapTracking(extra.parseAssignmentExpression);
  6365. parseBinaryExpression = wrapTracking(extra.parseBinaryExpression);
  6366. parseBlock = wrapTracking(extra.parseBlock);
  6367. parseFunctionSourceElements = wrapTracking(extra.parseFunctionSourceElements);
  6368. parseCatchClause = wrapTracking(extra.parseCatchClause);
  6369. parseComputedMember = wrapTracking(extra.parseComputedMember);
  6370. parseConditionalExpression = wrapTracking(extra.parseConditionalExpression);
  6371. parseConstLetDeclaration = wrapTracking(extra.parseConstLetDeclaration);
  6372. parseExportBatchSpecifier = wrapTracking(parseExportBatchSpecifier);
  6373. parseExportDeclaration = wrapTracking(parseExportDeclaration);
  6374. parseExportSpecifier = wrapTracking(parseExportSpecifier);
  6375. parseExpression = wrapTracking(extra.parseExpression);
  6376. parseForVariableDeclaration = wrapTracking(extra.parseForVariableDeclaration);
  6377. parseFunctionDeclaration = wrapTracking(extra.parseFunctionDeclaration);
  6378. parseFunctionExpression = wrapTracking(extra.parseFunctionExpression);
  6379. parseParams = wrapTracking(extra.parseParams);
  6380. parseImportDeclaration = wrapTracking(extra.parseImportDeclaration);
  6381. parseImportSpecifier = wrapTracking(extra.parseImportSpecifier);
  6382. parseModuleDeclaration = wrapTracking(extra.parseModuleDeclaration);
  6383. parseModuleBlock = wrapTracking(extra.parseModuleBlock);
  6384. parseLeftHandSideExpression = wrapTracking(parseLeftHandSideExpression);
  6385. parseNewExpression = wrapTracking(extra.parseNewExpression);
  6386. parseNonComputedProperty = wrapTracking(extra.parseNonComputedProperty);
  6387. parseObjectInitialiser = wrapTracking(extra.parseObjectInitialiser);
  6388. parseObjectProperty = wrapTracking(extra.parseObjectProperty);
  6389. parseObjectPropertyKey = wrapTracking(extra.parseObjectPropertyKey);
  6390. parsePostfixExpression = wrapTracking(extra.parsePostfixExpression);
  6391. parsePrimaryExpression = wrapTracking(extra.parsePrimaryExpression);
  6392. parseProgram = wrapTracking(extra.parseProgram);
  6393. parsePropertyFunction = wrapTracking(extra.parsePropertyFunction);
  6394. parseTemplateElement = wrapTracking(extra.parseTemplateElement);
  6395. parseTemplateLiteral = wrapTracking(extra.parseTemplateLiteral);
  6396. parseTypeAnnotatableIdentifier = wrapTracking(extra.parseTypeAnnotatableIdentifier);
  6397. parseTypeAnnotation = wrapTracking(extra.parseTypeAnnotation);
  6398. parseSpreadOrAssignmentExpression = wrapTracking(extra.parseSpreadOrAssignmentExpression);
  6399. parseStatement = wrapTracking(extra.parseStatement);
  6400. parseSwitchCase = wrapTracking(extra.parseSwitchCase);
  6401. parseUnaryExpression = wrapTracking(extra.parseUnaryExpression);
  6402. parseVariableDeclaration = wrapTracking(extra.parseVariableDeclaration);
  6403. parseVariableIdentifier = wrapTracking(extra.parseVariableIdentifier);
  6404. parseMethodDefinition = wrapTracking(extra.parseMethodDefinition);
  6405. parseClassDeclaration = wrapTracking(extra.parseClassDeclaration);
  6406. parseClassExpression = wrapTracking(extra.parseClassExpression);
  6407. parseClassBody = wrapTracking(extra.parseClassBody);
  6408. parseXJSIdentifier = wrapTracking(extra.parseXJSIdentifier);
  6409. parseXJSChild = wrapTrackingPreserveWhitespace(extra.parseXJSChild);
  6410. parseXJSAttribute = wrapTracking(extra.parseXJSAttribute);
  6411. parseXJSAttributeValue = wrapTracking(extra.parseXJSAttributeValue);
  6412. parseXJSExpressionContainer = wrapTracking(extra.parseXJSExpressionContainer);
  6413. parseXJSEmptyExpression = wrapTrackingPreserveWhitespace(extra.parseXJSEmptyExpression);
  6414. parseXJSElement = wrapTracking(extra.parseXJSElement);
  6415. parseXJSClosingElement = wrapTracking(extra.parseXJSClosingElement);
  6416. parseXJSOpeningElement = wrapTracking(extra.parseXJSOpeningElement);
  6417. }
  6418. if (typeof extra.tokens !== 'undefined') {
  6419. extra.advance = advance;
  6420. extra.scanRegExp = scanRegExp;
  6421. advance = collectToken;
  6422. scanRegExp = collectRegex;
  6423. }
  6424. }
  6425. function unpatch() {
  6426. if (typeof extra.skipComment === 'function') {
  6427. skipComment = extra.skipComment;
  6428. }
  6429. if (extra.range || extra.loc) {
  6430. parseArrayInitialiser = extra.parseArrayInitialiser;
  6431. parseAssignmentExpression = extra.parseAssignmentExpression;
  6432. parseBinaryExpression = extra.parseBinaryExpression;
  6433. parseBlock = extra.parseBlock;
  6434. parseFunctionSourceElements = extra.parseFunctionSourceElements;
  6435. parseCatchClause = extra.parseCatchClause;
  6436. parseComputedMember = extra.parseComputedMember;
  6437. parseConditionalExpression = extra.parseConditionalExpression;
  6438. parseConstLetDeclaration = extra.parseConstLetDeclaration;
  6439. parseExportBatchSpecifier = extra.parseExportBatchSpecifier;
  6440. parseExportDeclaration = extra.parseExportDeclaration;
  6441. parseExportSpecifier = extra.parseExportSpecifier;
  6442. parseExpression = extra.parseExpression;
  6443. parseForVariableDeclaration = extra.parseForVariableDeclaration;
  6444. parseFunctionDeclaration = extra.parseFunctionDeclaration;
  6445. parseFunctionExpression = extra.parseFunctionExpression;
  6446. parseImportDeclaration = extra.parseImportDeclaration;
  6447. parseImportSpecifier = extra.parseImportSpecifier;
  6448. parseGroupExpression = extra.parseGroupExpression;
  6449. parseLeftHandSideExpression = extra.parseLeftHandSideExpression;
  6450. parseLeftHandSideExpressionAllowCall = extra.parseLeftHandSideExpressionAllowCall;
  6451. parseModuleDeclaration = extra.parseModuleDeclaration;
  6452. parseModuleBlock = extra.parseModuleBlock;
  6453. parseNewExpression = extra.parseNewExpression;
  6454. parseNonComputedProperty = extra.parseNonComputedProperty;
  6455. parseObjectInitialiser = extra.parseObjectInitialiser;
  6456. parseObjectProperty = extra.parseObjectProperty;
  6457. parseObjectPropertyKey = extra.parseObjectPropertyKey;
  6458. parsePostfixExpression = extra.parsePostfixExpression;
  6459. parsePrimaryExpression = extra.parsePrimaryExpression;
  6460. parseProgram = extra.parseProgram;
  6461. parsePropertyFunction = extra.parsePropertyFunction;
  6462. parseTemplateElement = extra.parseTemplateElement;
  6463. parseTemplateLiteral = extra.parseTemplateLiteral;
  6464. parseTypeAnnotatableIdentifier = extra.parseTypeAnnotatableIdentifier;
  6465. parseTypeAnnotation = extra.parseTypeAnnotation;
  6466. parseSpreadOrAssignmentExpression = extra.parseSpreadOrAssignmentExpression;
  6467. parseStatement = extra.parseStatement;
  6468. parseSwitchCase = extra.parseSwitchCase;
  6469. parseUnaryExpression = extra.parseUnaryExpression;
  6470. parseVariableDeclaration = extra.parseVariableDeclaration;
  6471. parseVariableIdentifier = extra.parseVariableIdentifier;
  6472. parseMethodDefinition = extra.parseMethodDefinition;
  6473. parseClassDeclaration = extra.parseClassDeclaration;
  6474. parseClassExpression = extra.parseClassExpression;
  6475. parseClassBody = extra.parseClassBody;
  6476. parseXJSIdentifier = extra.parseXJSIdentifier;
  6477. parseXJSChild = extra.parseXJSChild;
  6478. parseXJSAttribute = extra.parseXJSAttribute;
  6479. parseXJSAttributeValue = extra.parseXJSAttributeValue;
  6480. parseXJSExpressionContainer = extra.parseXJSExpressionContainer;
  6481. parseXJSEmptyExpression = extra.parseXJSEmptyExpression;
  6482. parseXJSElement = extra.parseXJSElement;
  6483. parseXJSClosingElement = extra.parseXJSClosingElement;
  6484. parseXJSOpeningElement = extra.parseXJSOpeningElement;
  6485. }
  6486. if (typeof extra.scanRegExp === 'function') {
  6487. advance = extra.advance;
  6488. scanRegExp = extra.scanRegExp;
  6489. }
  6490. }
  6491. // This is used to modify the delegate.
  6492. function extend(object, properties) {
  6493. var entry, result = {};
  6494. for (entry in object) {
  6495. if (object.hasOwnProperty(entry)) {
  6496. result[entry] = object[entry];
  6497. }
  6498. }
  6499. for (entry in properties) {
  6500. if (properties.hasOwnProperty(entry)) {
  6501. result[entry] = properties[entry];
  6502. }
  6503. }
  6504. return result;
  6505. }
  6506. function tokenize(code, options) {
  6507. var toString,
  6508. token,
  6509. tokens;
  6510. toString = String;
  6511. if (typeof code !== 'string' && !(code instanceof String)) {
  6512. code = toString(code);
  6513. }
  6514. delegate = SyntaxTreeDelegate;
  6515. source = code;
  6516. index = 0;
  6517. lineNumber = (source.length > 0) ? 1 : 0;
  6518. lineStart = 0;
  6519. length = source.length;
  6520. lookahead = null;
  6521. state = {
  6522. allowKeyword: true,
  6523. allowIn: true,
  6524. labelSet: {},
  6525. inFunctionBody: false,
  6526. inIteration: false,
  6527. inSwitch: false
  6528. };
  6529. extra = {};
  6530. // Options matching.
  6531. options = options || {};
  6532. // Of course we collect tokens here.
  6533. options.tokens = true;
  6534. extra.tokens = [];
  6535. extra.tokenize = true;
  6536. // The following two fields are necessary to compute the Regex tokens.
  6537. extra.openParenToken = -1;
  6538. extra.openCurlyToken = -1;
  6539. extra.range = (typeof options.range === 'boolean') && options.range;
  6540. extra.loc = (typeof options.loc === 'boolean') && options.loc;
  6541. if (typeof options.comment === 'boolean' && options.comment) {
  6542. extra.comments = [];
  6543. }
  6544. if (typeof options.tolerant === 'boolean' && options.tolerant) {
  6545. extra.errors = [];
  6546. }
  6547. if (length > 0) {
  6548. if (typeof source[0] === 'undefined') {
  6549. // Try first to convert to a string. This is good as fast path
  6550. // for old IE which understands string indexing for string
  6551. // literals only and not for string object.
  6552. if (code instanceof String) {
  6553. source = code.valueOf();
  6554. }
  6555. }
  6556. }
  6557. patch();
  6558. try {
  6559. peek();
  6560. if (lookahead.type === Token.EOF) {
  6561. return extra.tokens;
  6562. }
  6563. token = lex();
  6564. while (lookahead.type !== Token.EOF) {
  6565. try {
  6566. token = lex();
  6567. } catch (lexError) {
  6568. token = lookahead;
  6569. if (extra.errors) {
  6570. extra.errors.push(lexError);
  6571. // We have to break on the first error
  6572. // to avoid infinite loops.
  6573. break;
  6574. } else {
  6575. throw lexError;
  6576. }
  6577. }
  6578. }
  6579. filterTokenLocation();
  6580. tokens = extra.tokens;
  6581. if (typeof extra.comments !== 'undefined') {
  6582. filterCommentLocation();
  6583. tokens.comments = extra.comments;
  6584. }
  6585. if (typeof extra.errors !== 'undefined') {
  6586. tokens.errors = extra.errors;
  6587. }
  6588. } catch (e) {
  6589. throw e;
  6590. } finally {
  6591. unpatch();
  6592. extra = {};
  6593. }
  6594. return tokens;
  6595. }
  6596. function parse(code, options) {
  6597. var program, toString;
  6598. toString = String;
  6599. if (typeof code !== 'string' && !(code instanceof String)) {
  6600. code = toString(code);
  6601. }
  6602. delegate = SyntaxTreeDelegate;
  6603. source = code;
  6604. index = 0;
  6605. lineNumber = (source.length > 0) ? 1 : 0;
  6606. lineStart = 0;
  6607. length = source.length;
  6608. lookahead = null;
  6609. state = {
  6610. allowKeyword: false,
  6611. allowIn: true,
  6612. labelSet: {},
  6613. parenthesizedCount: 0,
  6614. inFunctionBody: false,
  6615. inIteration: false,
  6616. inSwitch: false,
  6617. inXJSChild: false,
  6618. inXJSTag: false,
  6619. yieldAllowed: false,
  6620. yieldFound: false
  6621. };
  6622. extra = {};
  6623. if (typeof options !== 'undefined') {
  6624. extra.range = (typeof options.range === 'boolean') && options.range;
  6625. extra.loc = (typeof options.loc === 'boolean') && options.loc;
  6626. if (extra.loc && options.source !== null && options.source !== undefined) {
  6627. delegate = extend(delegate, {
  6628. 'postProcess': function (node) {
  6629. node.loc.source = toString(options.source);
  6630. return node;
  6631. }
  6632. });
  6633. }
  6634. if (typeof options.tokens === 'boolean' && options.tokens) {
  6635. extra.tokens = [];
  6636. }
  6637. if (typeof options.comment === 'boolean' && options.comment) {
  6638. extra.comments = [];
  6639. }
  6640. if (typeof options.tolerant === 'boolean' && options.tolerant) {
  6641. extra.errors = [];
  6642. }
  6643. }
  6644. if (length > 0) {
  6645. if (typeof source[0] === 'undefined') {
  6646. // Try first to convert to a string. This is good as fast path
  6647. // for old IE which understands string indexing for string
  6648. // literals only and not for string object.
  6649. if (code instanceof String) {
  6650. source = code.valueOf();
  6651. }
  6652. }
  6653. }
  6654. patch();
  6655. try {
  6656. program = parseProgram();
  6657. if (typeof extra.comments !== 'undefined') {
  6658. filterCommentLocation();
  6659. program.comments = extra.comments;
  6660. }
  6661. if (typeof extra.tokens !== 'undefined') {
  6662. filterTokenLocation();
  6663. program.tokens = extra.tokens;
  6664. }
  6665. if (typeof extra.errors !== 'undefined') {
  6666. program.errors = extra.errors;
  6667. }
  6668. if (extra.range || extra.loc) {
  6669. program.body = filterGroup(program.body);
  6670. }
  6671. } catch (e) {
  6672. throw e;
  6673. } finally {
  6674. unpatch();
  6675. extra = {};
  6676. }
  6677. return program;
  6678. }
  6679. // Sync with *.json manifests.
  6680. exports.version = '1.1.0-dev-harmony';
  6681. exports.tokenize = tokenize;
  6682. exports.parse = parse;
  6683. // Deep copy.
  6684. exports.Syntax = (function () {
  6685. var name, types = {};
  6686. if (typeof Object.create === 'function') {
  6687. types = Object.create(null);
  6688. }
  6689. for (name in Syntax) {
  6690. if (Syntax.hasOwnProperty(name)) {
  6691. types[name] = Syntax[name];
  6692. }
  6693. }
  6694. if (typeof Object.freeze === 'function') {
  6695. Object.freeze(types);
  6696. }
  6697. return types;
  6698. }());
  6699. }));
  6700. /* vim: set sw=4 ts=4 et tw=80 : */
  6701. }, {}], 7: [function (_dereq_, module, exports) {
  6702. var Base62 = (function (my) {
  6703. 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"]
  6704. my.encode = function (i) {
  6705. if (i === 0) { return '0' }
  6706. var s = ''
  6707. while (i > 0) {
  6708. s = this.chars[i % 62] + s
  6709. i = Math.floor(i / 62)
  6710. }
  6711. return s
  6712. };
  6713. my.decode = function (a, b, c, d) {
  6714. for (
  6715. b = c = (
  6716. a === (/\W|_|^$/.test(a += "") || a)
  6717. ) - 1;
  6718. d = a.charCodeAt(c++) ;
  6719. )
  6720. b = b * 62 + d - [, 48, 29, 87][d >> 5];
  6721. return b
  6722. };
  6723. return my;
  6724. }({}));
  6725. module.exports = Base62
  6726. }, {}], 8: [function (_dereq_, module, exports) {
  6727. /*
  6728. * Copyright 2009-2011 Mozilla Foundation and contributors
  6729. * Licensed under the New BSD license. See LICENSE.txt or:
  6730. * http://opensource.org/licenses/BSD-3-Clause
  6731. */
  6732. exports.SourceMapGenerator = _dereq_('./source-map/source-map-generator').SourceMapGenerator;
  6733. exports.SourceMapConsumer = _dereq_('./source-map/source-map-consumer').SourceMapConsumer;
  6734. exports.SourceNode = _dereq_('./source-map/source-node').SourceNode;
  6735. }, { "./source-map/source-map-consumer": 13, "./source-map/source-map-generator": 14, "./source-map/source-node": 15 }], 9: [function (_dereq_, module, exports) {
  6736. /* -*- Mode: js; js-indent-level: 2; -*- */
  6737. /*
  6738. * Copyright 2011 Mozilla Foundation and contributors
  6739. * Licensed under the New BSD license. See LICENSE or:
  6740. * http://opensource.org/licenses/BSD-3-Clause
  6741. */
  6742. if (typeof define !== 'function') {
  6743. var define = _dereq_('amdefine')(module, _dereq_);
  6744. }
  6745. define(function (_dereq_, exports, module) {
  6746. var util = _dereq_('./util');
  6747. /**
  6748. * A data structure which is a combination of an array and a set. Adding a new
  6749. * member is O(1), testing for membership is O(1), and finding the index of an
  6750. * element is O(1). Removing elements from the set is not supported. Only
  6751. * strings are supported for membership.
  6752. */
  6753. function ArraySet() {
  6754. this._array = [];
  6755. this._set = {};
  6756. }
  6757. /**
  6758. * Static method for creating ArraySet instances from an existing array.
  6759. */
  6760. ArraySet.fromArray = function ArraySet_fromArray(aArray, aAllowDuplicates) {
  6761. var set = new ArraySet();
  6762. for (var i = 0, len = aArray.length; i < len; i++) {
  6763. set.add(aArray[i], aAllowDuplicates);
  6764. }
  6765. return set;
  6766. };
  6767. /**
  6768. * Add the given string to this set.
  6769. *
  6770. * @param String aStr
  6771. */
  6772. ArraySet.prototype.add = function ArraySet_add(aStr, aAllowDuplicates) {
  6773. var isDuplicate = this.has(aStr);
  6774. var idx = this._array.length;
  6775. if (!isDuplicate || aAllowDuplicates) {
  6776. this._array.push(aStr);
  6777. }
  6778. if (!isDuplicate) {
  6779. this._set[util.toSetString(aStr)] = idx;
  6780. }
  6781. };
  6782. /**
  6783. * Is the given string a member of this set?
  6784. *
  6785. * @param String aStr
  6786. */
  6787. ArraySet.prototype.has = function ArraySet_has(aStr) {
  6788. return Object.prototype.hasOwnProperty.call(this._set,
  6789. util.toSetString(aStr));
  6790. };
  6791. /**
  6792. * What is the index of the given string in the array?
  6793. *
  6794. * @param String aStr
  6795. */
  6796. ArraySet.prototype.indexOf = function ArraySet_indexOf(aStr) {
  6797. if (this.has(aStr)) {
  6798. return this._set[util.toSetString(aStr)];
  6799. }
  6800. throw new Error('"' + aStr + '" is not in the set.');
  6801. };
  6802. /**
  6803. * What is the element at the given index?
  6804. *
  6805. * @param Number aIdx
  6806. */
  6807. ArraySet.prototype.at = function ArraySet_at(aIdx) {
  6808. if (aIdx >= 0 && aIdx < this._array.length) {
  6809. return this._array[aIdx];
  6810. }
  6811. throw new Error('No element indexed by ' + aIdx);
  6812. };
  6813. /**
  6814. * Returns the array representation of this set (which has the proper indices
  6815. * indicated by indexOf). Note that this is a copy of the internal array used
  6816. * for storing the members so that no one can mess with internal state.
  6817. */
  6818. ArraySet.prototype.toArray = function ArraySet_toArray() {
  6819. return this._array.slice();
  6820. };
  6821. exports.ArraySet = ArraySet;
  6822. });
  6823. }, { "./util": 16, "amdefine": 17 }], 10: [function (_dereq_, module, exports) {
  6824. /* -*- Mode: js; js-indent-level: 2; -*- */
  6825. /*
  6826. * Copyright 2011 Mozilla Foundation and contributors
  6827. * Licensed under the New BSD license. See LICENSE or:
  6828. * http://opensource.org/licenses/BSD-3-Clause
  6829. *
  6830. * Based on the Base 64 VLQ implementation in Closure Compiler:
  6831. * https://code.google.com/p/closure-compiler/source/browse/trunk/src/com/google/debugging/sourcemap/Base64VLQ.java
  6832. *
  6833. * Copyright 2011 The Closure Compiler Authors. All rights reserved.
  6834. * Redistribution and use in source and binary forms, with or without
  6835. * modification, are permitted provided that the following conditions are
  6836. * met:
  6837. *
  6838. * * Redistributions of source code must retain the above copyright
  6839. * notice, this list of conditions and the following disclaimer.
  6840. * * Redistributions in binary form must reproduce the above
  6841. * copyright notice, this list of conditions and the following
  6842. * disclaimer in the documentation and/or other materials provided
  6843. * with the distribution.
  6844. * * Neither the name of Google Inc. nor the names of its
  6845. * contributors may be used to endorse or promote products derived
  6846. * from this software without specific prior written permission.
  6847. *
  6848. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  6849. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  6850. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  6851. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  6852. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  6853. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  6854. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  6855. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  6856. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  6857. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  6858. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  6859. */
  6860. if (typeof define !== 'function') {
  6861. var define = _dereq_('amdefine')(module, _dereq_);
  6862. }
  6863. define(function (_dereq_, exports, module) {
  6864. var base64 = _dereq_('./base64');
  6865. // A single base 64 digit can contain 6 bits of data. For the base 64 variable
  6866. // length quantities we use in the source map spec, the first bit is the sign,
  6867. // the next four bits are the actual value, and the 6th bit is the
  6868. // continuation bit. The continuation bit tells us whether there are more
  6869. // digits in this value following this digit.
  6870. //
  6871. // Continuation
  6872. // | Sign
  6873. // | |
  6874. // V V
  6875. // 101011
  6876. var VLQ_BASE_SHIFT = 5;
  6877. // binary: 100000
  6878. var VLQ_BASE = 1 << VLQ_BASE_SHIFT;
  6879. // binary: 011111
  6880. var VLQ_BASE_MASK = VLQ_BASE - 1;
  6881. // binary: 100000
  6882. var VLQ_CONTINUATION_BIT = VLQ_BASE;
  6883. /**
  6884. * Converts from a two-complement value to a value where the sign bit is
  6885. * is placed in the least significant bit. For example, as decimals:
  6886. * 1 becomes 2 (10 binary), -1 becomes 3 (11 binary)
  6887. * 2 becomes 4 (100 binary), -2 becomes 5 (101 binary)
  6888. */
  6889. function toVLQSigned(aValue) {
  6890. return aValue < 0
  6891. ? ((-aValue) << 1) + 1
  6892. : (aValue << 1) + 0;
  6893. }
  6894. /**
  6895. * Converts to a two-complement value from a value where the sign bit is
  6896. * is placed in the least significant bit. For example, as decimals:
  6897. * 2 (10 binary) becomes 1, 3 (11 binary) becomes -1
  6898. * 4 (100 binary) becomes 2, 5 (101 binary) becomes -2
  6899. */
  6900. function fromVLQSigned(aValue) {
  6901. var isNegative = (aValue & 1) === 1;
  6902. var shifted = aValue >> 1;
  6903. return isNegative
  6904. ? -shifted
  6905. : shifted;
  6906. }
  6907. /**
  6908. * Returns the base 64 VLQ encoded value.
  6909. */
  6910. exports.encode = function base64VLQ_encode(aValue) {
  6911. var encoded = "";
  6912. var digit;
  6913. var vlq = toVLQSigned(aValue);
  6914. do {
  6915. digit = vlq & VLQ_BASE_MASK;
  6916. vlq >>>= VLQ_BASE_SHIFT;
  6917. if (vlq > 0) {
  6918. // There are still more digits in this value, so we must make sure the
  6919. // continuation bit is marked.
  6920. digit |= VLQ_CONTINUATION_BIT;
  6921. }
  6922. encoded += base64.encode(digit);
  6923. } while (vlq > 0);
  6924. return encoded;
  6925. };
  6926. /**
  6927. * Decodes the next base 64 VLQ value from the given string and returns the
  6928. * value and the rest of the string.
  6929. */
  6930. exports.decode = function base64VLQ_decode(aStr) {
  6931. var i = 0;
  6932. var strLen = aStr.length;
  6933. var result = 0;
  6934. var shift = 0;
  6935. var continuation, digit;
  6936. do {
  6937. if (i >= strLen) {
  6938. throw new Error("Expected more digits in base 64 VLQ value.");
  6939. }
  6940. digit = base64.decode(aStr.charAt(i++));
  6941. continuation = !!(digit & VLQ_CONTINUATION_BIT);
  6942. digit &= VLQ_BASE_MASK;
  6943. result = result + (digit << shift);
  6944. shift += VLQ_BASE_SHIFT;
  6945. } while (continuation);
  6946. return {
  6947. value: fromVLQSigned(result),
  6948. rest: aStr.slice(i)
  6949. };
  6950. };
  6951. });
  6952. }, { "./base64": 11, "amdefine": 17 }], 11: [function (_dereq_, module, exports) {
  6953. /* -*- Mode: js; js-indent-level: 2; -*- */
  6954. /*
  6955. * Copyright 2011 Mozilla Foundation and contributors
  6956. * Licensed under the New BSD license. See LICENSE or:
  6957. * http://opensource.org/licenses/BSD-3-Clause
  6958. */
  6959. if (typeof define !== 'function') {
  6960. var define = _dereq_('amdefine')(module, _dereq_);
  6961. }
  6962. define(function (_dereq_, exports, module) {
  6963. var charToIntMap = {};
  6964. var intToCharMap = {};
  6965. 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
  6966. .split('')
  6967. .forEach(function (ch, index) {
  6968. charToIntMap[ch] = index;
  6969. intToCharMap[index] = ch;
  6970. });
  6971. /**
  6972. * Encode an integer in the range of 0 to 63 to a single base 64 digit.
  6973. */
  6974. exports.encode = function base64_encode(aNumber) {
  6975. if (aNumber in intToCharMap) {
  6976. return intToCharMap[aNumber];
  6977. }
  6978. throw new TypeError("Must be between 0 and 63: " + aNumber);
  6979. };
  6980. /**
  6981. * Decode a single base 64 digit to an integer.
  6982. */
  6983. exports.decode = function base64_decode(aChar) {
  6984. if (aChar in charToIntMap) {
  6985. return charToIntMap[aChar];
  6986. }
  6987. throw new TypeError("Not a valid base 64 digit: " + aChar);
  6988. };
  6989. });
  6990. }, { "amdefine": 17 }], 12: [function (_dereq_, module, exports) {
  6991. /* -*- Mode: js; js-indent-level: 2; -*- */
  6992. /*
  6993. * Copyright 2011 Mozilla Foundation and contributors
  6994. * Licensed under the New BSD license. See LICENSE or:
  6995. * http://opensource.org/licenses/BSD-3-Clause
  6996. */
  6997. if (typeof define !== 'function') {
  6998. var define = _dereq_('amdefine')(module, _dereq_);
  6999. }
  7000. define(function (_dereq_, exports, module) {
  7001. /**
  7002. * Recursive implementation of binary search.
  7003. *
  7004. * @param aLow Indices here and lower do not contain the needle.
  7005. * @param aHigh Indices here and higher do not contain the needle.
  7006. * @param aNeedle The element being searched for.
  7007. * @param aHaystack The non-empty array being searched.
  7008. * @param aCompare Function which takes two elements and returns -1, 0, or 1.
  7009. */
  7010. function recursiveSearch(aLow, aHigh, aNeedle, aHaystack, aCompare) {
  7011. // This function terminates when one of the following is true:
  7012. //
  7013. // 1. We find the exact element we are looking for.
  7014. //
  7015. // 2. We did not find the exact element, but we can return the next
  7016. // closest element that is less than that element.
  7017. //
  7018. // 3. We did not find the exact element, and there is no next-closest
  7019. // element which is less than the one we are searching for, so we
  7020. // return null.
  7021. var mid = Math.floor((aHigh - aLow) / 2) + aLow;
  7022. var cmp = aCompare(aNeedle, aHaystack[mid], true);
  7023. if (cmp === 0) {
  7024. // Found the element we are looking for.
  7025. return aHaystack[mid];
  7026. }
  7027. else if (cmp > 0) {
  7028. // aHaystack[mid] is greater than our needle.
  7029. if (aHigh - mid > 1) {
  7030. // The element is in the upper half.
  7031. return recursiveSearch(mid, aHigh, aNeedle, aHaystack, aCompare);
  7032. }
  7033. // We did not find an exact match, return the next closest one
  7034. // (termination case 2).
  7035. return aHaystack[mid];
  7036. }
  7037. else {
  7038. // aHaystack[mid] is less than our needle.
  7039. if (mid - aLow > 1) {
  7040. // The element is in the lower half.
  7041. return recursiveSearch(aLow, mid, aNeedle, aHaystack, aCompare);
  7042. }
  7043. // The exact needle element was not found in this haystack. Determine if
  7044. // we are in termination case (2) or (3) and return the appropriate thing.
  7045. return aLow < 0
  7046. ? null
  7047. : aHaystack[aLow];
  7048. }
  7049. }
  7050. /**
  7051. * This is an implementation of binary search which will always try and return
  7052. * the next lowest value checked if there is no exact hit. This is because
  7053. * mappings between original and generated line/col pairs are single points,
  7054. * and there is an implicit region between each of them, so a miss just means
  7055. * that you aren't on the very start of a region.
  7056. *
  7057. * @param aNeedle The element you are looking for.
  7058. * @param aHaystack The array that is being searched.
  7059. * @param aCompare A function which takes the needle and an element in the
  7060. * array and returns -1, 0, or 1 depending on whether the needle is less
  7061. * than, equal to, or greater than the element, respectively.
  7062. */
  7063. exports.search = function search(aNeedle, aHaystack, aCompare) {
  7064. return aHaystack.length > 0
  7065. ? recursiveSearch(-1, aHaystack.length, aNeedle, aHaystack, aCompare)
  7066. : null;
  7067. };
  7068. });
  7069. }, { "amdefine": 17 }], 13: [function (_dereq_, module, exports) {
  7070. /* -*- Mode: js; js-indent-level: 2; -*- */
  7071. /*
  7072. * Copyright 2011 Mozilla Foundation and contributors
  7073. * Licensed under the New BSD license. See LICENSE or:
  7074. * http://opensource.org/licenses/BSD-3-Clause
  7075. */
  7076. if (typeof define !== 'function') {
  7077. var define = _dereq_('amdefine')(module, _dereq_);
  7078. }
  7079. define(function (_dereq_, exports, module) {
  7080. var util = _dereq_('./util');
  7081. var binarySearch = _dereq_('./binary-search');
  7082. var ArraySet = _dereq_('./array-set').ArraySet;
  7083. var base64VLQ = _dereq_('./base64-vlq');
  7084. /**
  7085. * A SourceMapConsumer instance represents a parsed source map which we can
  7086. * query for information about the original file positions by giving it a file
  7087. * position in the generated source.
  7088. *
  7089. * The only parameter is the raw source map (either as a JSON string, or
  7090. * already parsed to an object). According to the spec, source maps have the
  7091. * following attributes:
  7092. *
  7093. * - version: Which version of the source map spec this map is following.
  7094. * - sources: An array of URLs to the original source files.
  7095. * - names: An array of identifiers which can be referrenced by individual mappings.
  7096. * - sourceRoot: Optional. The URL root from which all sources are relative.
  7097. * - sourcesContent: Optional. An array of contents of the original source files.
  7098. * - mappings: A string of base64 VLQs which contain the actual mappings.
  7099. * - file: The generated file this source map is associated with.
  7100. *
  7101. * Here is an example source map, taken from the source map spec[0]:
  7102. *
  7103. * {
  7104. * version : 3,
  7105. * file: "out.js",
  7106. * sourceRoot : "",
  7107. * sources: ["foo.js", "bar.js"],
  7108. * names: ["src", "maps", "are", "fun"],
  7109. * mappings: "AA,AB;;ABCDE;"
  7110. * }
  7111. *
  7112. * [0]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit?pli=1#
  7113. */
  7114. function SourceMapConsumer(aSourceMap) {
  7115. var sourceMap = aSourceMap;
  7116. if (typeof aSourceMap === 'string') {
  7117. sourceMap = JSON.parse(aSourceMap.replace(/^\)\]\}'/, ''));
  7118. }
  7119. var version = util.getArg(sourceMap, 'version');
  7120. var sources = util.getArg(sourceMap, 'sources');
  7121. // Sass 3.3 leaves out the 'names' array, so we deviate from the spec (which
  7122. // requires the array) to play nice here.
  7123. var names = util.getArg(sourceMap, 'names', []);
  7124. var sourceRoot = util.getArg(sourceMap, 'sourceRoot', null);
  7125. var sourcesContent = util.getArg(sourceMap, 'sourcesContent', null);
  7126. var mappings = util.getArg(sourceMap, 'mappings');
  7127. var file = util.getArg(sourceMap, 'file', null);
  7128. // Once again, Sass deviates from the spec and supplies the version as a
  7129. // string rather than a number, so we use loose equality checking here.
  7130. if (version != this._version) {
  7131. throw new Error('Unsupported version: ' + version);
  7132. }
  7133. // Pass `true` below to allow duplicate names and sources. While source maps
  7134. // are intended to be compressed and deduplicated, the TypeScript compiler
  7135. // sometimes generates source maps with duplicates in them. See Github issue
  7136. // #72 and bugzil.la/889492.
  7137. this._names = ArraySet.fromArray(names, true);
  7138. this._sources = ArraySet.fromArray(sources, true);
  7139. this.sourceRoot = sourceRoot;
  7140. this.sourcesContent = sourcesContent;
  7141. this._mappings = mappings;
  7142. this.file = file;
  7143. }
  7144. /**
  7145. * Create a SourceMapConsumer from a SourceMapGenerator.
  7146. *
  7147. * @param SourceMapGenerator aSourceMap
  7148. * The source map that will be consumed.
  7149. * @returns SourceMapConsumer
  7150. */
  7151. SourceMapConsumer.fromSourceMap =
  7152. function SourceMapConsumer_fromSourceMap(aSourceMap) {
  7153. var smc = Object.create(SourceMapConsumer.prototype);
  7154. smc._names = ArraySet.fromArray(aSourceMap._names.toArray(), true);
  7155. smc._sources = ArraySet.fromArray(aSourceMap._sources.toArray(), true);
  7156. smc.sourceRoot = aSourceMap._sourceRoot;
  7157. smc.sourcesContent = aSourceMap._generateSourcesContent(smc._sources.toArray(),
  7158. smc.sourceRoot);
  7159. smc.file = aSourceMap._file;
  7160. smc.__generatedMappings = aSourceMap._mappings.slice()
  7161. .sort(util.compareByGeneratedPositions);
  7162. smc.__originalMappings = aSourceMap._mappings.slice()
  7163. .sort(util.compareByOriginalPositions);
  7164. return smc;
  7165. };
  7166. /**
  7167. * The version of the source mapping spec that we are consuming.
  7168. */
  7169. SourceMapConsumer.prototype._version = 3;
  7170. /**
  7171. * The list of original sources.
  7172. */
  7173. Object.defineProperty(SourceMapConsumer.prototype, 'sources', {
  7174. get: function () {
  7175. return this._sources.toArray().map(function (s) {
  7176. return this.sourceRoot ? util.join(this.sourceRoot, s) : s;
  7177. }, this);
  7178. }
  7179. });
  7180. // `__generatedMappings` and `__originalMappings` are arrays that hold the
  7181. // parsed mapping coordinates from the source map's "mappings" attribute. They
  7182. // are lazily instantiated, accessed via the `_generatedMappings` and
  7183. // `_originalMappings` getters respectively, and we only parse the mappings
  7184. // and create these arrays once queried for a source location. We jump through
  7185. // these hoops because there can be many thousands of mappings, and parsing
  7186. // them is expensive, so we only want to do it if we must.
  7187. //
  7188. // Each object in the arrays is of the form:
  7189. //
  7190. // {
  7191. // generatedLine: The line number in the generated code,
  7192. // generatedColumn: The column number in the generated code,
  7193. // source: The path to the original source file that generated this
  7194. // chunk of code,
  7195. // originalLine: The line number in the original source that
  7196. // corresponds to this chunk of generated code,
  7197. // originalColumn: The column number in the original source that
  7198. // corresponds to this chunk of generated code,
  7199. // name: The name of the original symbol which generated this chunk of
  7200. // code.
  7201. // }
  7202. //
  7203. // All properties except for `generatedLine` and `generatedColumn` can be
  7204. // `null`.
  7205. //
  7206. // `_generatedMappings` is ordered by the generated positions.
  7207. //
  7208. // `_originalMappings` is ordered by the original positions.
  7209. SourceMapConsumer.prototype.__generatedMappings = null;
  7210. Object.defineProperty(SourceMapConsumer.prototype, '_generatedMappings', {
  7211. get: function () {
  7212. if (!this.__generatedMappings) {
  7213. this.__generatedMappings = [];
  7214. this.__originalMappings = [];
  7215. this._parseMappings(this._mappings, this.sourceRoot);
  7216. }
  7217. return this.__generatedMappings;
  7218. }
  7219. });
  7220. SourceMapConsumer.prototype.__originalMappings = null;
  7221. Object.defineProperty(SourceMapConsumer.prototype, '_originalMappings', {
  7222. get: function () {
  7223. if (!this.__originalMappings) {
  7224. this.__generatedMappings = [];
  7225. this.__originalMappings = [];
  7226. this._parseMappings(this._mappings, this.sourceRoot);
  7227. }
  7228. return this.__originalMappings;
  7229. }
  7230. });
  7231. /**
  7232. * Parse the mappings in a string in to a data structure which we can easily
  7233. * query (the ordered arrays in the `this.__generatedMappings` and
  7234. * `this.__originalMappings` properties).
  7235. */
  7236. SourceMapConsumer.prototype._parseMappings =
  7237. function SourceMapConsumer_parseMappings(aStr, aSourceRoot) {
  7238. var generatedLine = 1;
  7239. var previousGeneratedColumn = 0;
  7240. var previousOriginalLine = 0;
  7241. var previousOriginalColumn = 0;
  7242. var previousSource = 0;
  7243. var previousName = 0;
  7244. var mappingSeparator = /^[,;]/;
  7245. var str = aStr;
  7246. var mapping;
  7247. var temp;
  7248. while (str.length > 0) {
  7249. if (str.charAt(0) === ';') {
  7250. generatedLine++;
  7251. str = str.slice(1);
  7252. previousGeneratedColumn = 0;
  7253. }
  7254. else if (str.charAt(0) === ',') {
  7255. str = str.slice(1);
  7256. }
  7257. else {
  7258. mapping = {};
  7259. mapping.generatedLine = generatedLine;
  7260. // Generated column.
  7261. temp = base64VLQ.decode(str);
  7262. mapping.generatedColumn = previousGeneratedColumn + temp.value;
  7263. previousGeneratedColumn = mapping.generatedColumn;
  7264. str = temp.rest;
  7265. if (str.length > 0 && !mappingSeparator.test(str.charAt(0))) {
  7266. // Original source.
  7267. temp = base64VLQ.decode(str);
  7268. mapping.source = this._sources.at(previousSource + temp.value);
  7269. previousSource += temp.value;
  7270. str = temp.rest;
  7271. if (str.length === 0 || mappingSeparator.test(str.charAt(0))) {
  7272. throw new Error('Found a source, but no line and column');
  7273. }
  7274. // Original line.
  7275. temp = base64VLQ.decode(str);
  7276. mapping.originalLine = previousOriginalLine + temp.value;
  7277. previousOriginalLine = mapping.originalLine;
  7278. // Lines are stored 0-based
  7279. mapping.originalLine += 1;
  7280. str = temp.rest;
  7281. if (str.length === 0 || mappingSeparator.test(str.charAt(0))) {
  7282. throw new Error('Found a source and line, but no column');
  7283. }
  7284. // Original column.
  7285. temp = base64VLQ.decode(str);
  7286. mapping.originalColumn = previousOriginalColumn + temp.value;
  7287. previousOriginalColumn = mapping.originalColumn;
  7288. str = temp.rest;
  7289. if (str.length > 0 && !mappingSeparator.test(str.charAt(0))) {
  7290. // Original name.
  7291. temp = base64VLQ.decode(str);
  7292. mapping.name = this._names.at(previousName + temp.value);
  7293. previousName += temp.value;
  7294. str = temp.rest;
  7295. }
  7296. }
  7297. this.__generatedMappings.push(mapping);
  7298. if (typeof mapping.originalLine === 'number') {
  7299. this.__originalMappings.push(mapping);
  7300. }
  7301. }
  7302. }
  7303. this.__originalMappings.sort(util.compareByOriginalPositions);
  7304. };
  7305. /**
  7306. * Find the mapping that best matches the hypothetical "needle" mapping that
  7307. * we are searching for in the given "haystack" of mappings.
  7308. */
  7309. SourceMapConsumer.prototype._findMapping =
  7310. function SourceMapConsumer_findMapping(aNeedle, aMappings, aLineName,
  7311. aColumnName, aComparator) {
  7312. // To return the position we are searching for, we must first find the
  7313. // mapping for the given position and then return the opposite position it
  7314. // points to. Because the mappings are sorted, we can use binary search to
  7315. // find the best mapping.
  7316. if (aNeedle[aLineName] <= 0) {
  7317. throw new TypeError('Line must be greater than or equal to 1, got '
  7318. + aNeedle[aLineName]);
  7319. }
  7320. if (aNeedle[aColumnName] < 0) {
  7321. throw new TypeError('Column must be greater than or equal to 0, got '
  7322. + aNeedle[aColumnName]);
  7323. }
  7324. return binarySearch.search(aNeedle, aMappings, aComparator);
  7325. };
  7326. /**
  7327. * Returns the original source, line, and column information for the generated
  7328. * source's line and column positions provided. The only argument is an object
  7329. * with the following properties:
  7330. *
  7331. * - line: The line number in the generated source.
  7332. * - column: The column number in the generated source.
  7333. *
  7334. * and an object is returned with the following properties:
  7335. *
  7336. * - source: The original source file, or null.
  7337. * - line: The line number in the original source, or null.
  7338. * - column: The column number in the original source, or null.
  7339. * - name: The original identifier, or null.
  7340. */
  7341. SourceMapConsumer.prototype.originalPositionFor =
  7342. function SourceMapConsumer_originalPositionFor(aArgs) {
  7343. var needle = {
  7344. generatedLine: util.getArg(aArgs, 'line'),
  7345. generatedColumn: util.getArg(aArgs, 'column')
  7346. };
  7347. var mapping = this._findMapping(needle,
  7348. this._generatedMappings,
  7349. "generatedLine",
  7350. "generatedColumn",
  7351. util.compareByGeneratedPositions);
  7352. if (mapping) {
  7353. var source = util.getArg(mapping, 'source', null);
  7354. if (source && this.sourceRoot) {
  7355. source = util.join(this.sourceRoot, source);
  7356. }
  7357. return {
  7358. source: source,
  7359. line: util.getArg(mapping, 'originalLine', null),
  7360. column: util.getArg(mapping, 'originalColumn', null),
  7361. name: util.getArg(mapping, 'name', null)
  7362. };
  7363. }
  7364. return {
  7365. source: null,
  7366. line: null,
  7367. column: null,
  7368. name: null
  7369. };
  7370. };
  7371. /**
  7372. * Returns the original source content. The only argument is the url of the
  7373. * original source file. Returns null if no original source content is
  7374. * availible.
  7375. */
  7376. SourceMapConsumer.prototype.sourceContentFor =
  7377. function SourceMapConsumer_sourceContentFor(aSource) {
  7378. if (!this.sourcesContent) {
  7379. return null;
  7380. }
  7381. if (this.sourceRoot) {
  7382. aSource = util.relative(this.sourceRoot, aSource);
  7383. }
  7384. if (this._sources.has(aSource)) {
  7385. return this.sourcesContent[this._sources.indexOf(aSource)];
  7386. }
  7387. var url;
  7388. if (this.sourceRoot
  7389. && (url = util.urlParse(this.sourceRoot))) {
  7390. // XXX: file:// URIs and absolute paths lead to unexpected behavior for
  7391. // many users. We can help them out when they expect file:// URIs to
  7392. // behave like it would if they were running a local HTTP server. See
  7393. // https://bugzilla.mozilla.org/show_bug.cgi?id=885597.
  7394. var fileUriAbsPath = aSource.replace(/^file:\/\//, "");
  7395. if (url.scheme == "file"
  7396. && this._sources.has(fileUriAbsPath)) {
  7397. return this.sourcesContent[this._sources.indexOf(fileUriAbsPath)]
  7398. }
  7399. if ((!url.path || url.path == "/")
  7400. && this._sources.has("/" + aSource)) {
  7401. return this.sourcesContent[this._sources.indexOf("/" + aSource)];
  7402. }
  7403. }
  7404. throw new Error('"' + aSource + '" is not in the SourceMap.');
  7405. };
  7406. /**
  7407. * Returns the generated line and column information for the original source,
  7408. * line, and column positions provided. The only argument is an object with
  7409. * the following properties:
  7410. *
  7411. * - source: The filename of the original source.
  7412. * - line: The line number in the original source.
  7413. * - column: The column number in the original source.
  7414. *
  7415. * and an object is returned with the following properties:
  7416. *
  7417. * - line: The line number in the generated source, or null.
  7418. * - column: The column number in the generated source, or null.
  7419. */
  7420. SourceMapConsumer.prototype.generatedPositionFor =
  7421. function SourceMapConsumer_generatedPositionFor(aArgs) {
  7422. var needle = {
  7423. source: util.getArg(aArgs, 'source'),
  7424. originalLine: util.getArg(aArgs, 'line'),
  7425. originalColumn: util.getArg(aArgs, 'column')
  7426. };
  7427. if (this.sourceRoot) {
  7428. needle.source = util.relative(this.sourceRoot, needle.source);
  7429. }
  7430. var mapping = this._findMapping(needle,
  7431. this._originalMappings,
  7432. "originalLine",
  7433. "originalColumn",
  7434. util.compareByOriginalPositions);
  7435. if (mapping) {
  7436. return {
  7437. line: util.getArg(mapping, 'generatedLine', null),
  7438. column: util.getArg(mapping, 'generatedColumn', null)
  7439. };
  7440. }
  7441. return {
  7442. line: null,
  7443. column: null
  7444. };
  7445. };
  7446. SourceMapConsumer.GENERATED_ORDER = 1;
  7447. SourceMapConsumer.ORIGINAL_ORDER = 2;
  7448. /**
  7449. * Iterate over each mapping between an original source/line/column and a
  7450. * generated line/column in this source map.
  7451. *
  7452. * @param Function aCallback
  7453. * The function that is called with each mapping.
  7454. * @param Object aContext
  7455. * Optional. If specified, this object will be the value of `this` every
  7456. * time that `aCallback` is called.
  7457. * @param aOrder
  7458. * Either `SourceMapConsumer.GENERATED_ORDER` or
  7459. * `SourceMapConsumer.ORIGINAL_ORDER`. Specifies whether you want to
  7460. * iterate over the mappings sorted by the generated file's line/column
  7461. * order or the original's source/line/column order, respectively. Defaults to
  7462. * `SourceMapConsumer.GENERATED_ORDER`.
  7463. */
  7464. SourceMapConsumer.prototype.eachMapping =
  7465. function SourceMapConsumer_eachMapping(aCallback, aContext, aOrder) {
  7466. var context = aContext || null;
  7467. var order = aOrder || SourceMapConsumer.GENERATED_ORDER;
  7468. var mappings;
  7469. switch (order) {
  7470. case SourceMapConsumer.GENERATED_ORDER:
  7471. mappings = this._generatedMappings;
  7472. break;
  7473. case SourceMapConsumer.ORIGINAL_ORDER:
  7474. mappings = this._originalMappings;
  7475. break;
  7476. default:
  7477. throw new Error("Unknown order of iteration.");
  7478. }
  7479. var sourceRoot = this.sourceRoot;
  7480. mappings.map(function (mapping) {
  7481. var source = mapping.source;
  7482. if (source && sourceRoot) {
  7483. source = util.join(sourceRoot, source);
  7484. }
  7485. return {
  7486. source: source,
  7487. generatedLine: mapping.generatedLine,
  7488. generatedColumn: mapping.generatedColumn,
  7489. originalLine: mapping.originalLine,
  7490. originalColumn: mapping.originalColumn,
  7491. name: mapping.name
  7492. };
  7493. }).forEach(aCallback, context);
  7494. };
  7495. exports.SourceMapConsumer = SourceMapConsumer;
  7496. });
  7497. }, { "./array-set": 9, "./base64-vlq": 10, "./binary-search": 12, "./util": 16, "amdefine": 17 }], 14: [function (_dereq_, module, exports) {
  7498. /* -*- Mode: js; js-indent-level: 2; -*- */
  7499. /*
  7500. * Copyright 2011 Mozilla Foundation and contributors
  7501. * Licensed under the New BSD license. See LICENSE or:
  7502. * http://opensource.org/licenses/BSD-3-Clause
  7503. */
  7504. if (typeof define !== 'function') {
  7505. var define = _dereq_('amdefine')(module, _dereq_);
  7506. }
  7507. define(function (_dereq_, exports, module) {
  7508. var base64VLQ = _dereq_('./base64-vlq');
  7509. var util = _dereq_('./util');
  7510. var ArraySet = _dereq_('./array-set').ArraySet;
  7511. /**
  7512. * An instance of the SourceMapGenerator represents a source map which is
  7513. * being built incrementally. To create a new one, you must pass an object
  7514. * with the following properties:
  7515. *
  7516. * - file: The filename of the generated source.
  7517. * - sourceRoot: An optional root for all URLs in this source map.
  7518. */
  7519. function SourceMapGenerator(aArgs) {
  7520. this._file = util.getArg(aArgs, 'file');
  7521. this._sourceRoot = util.getArg(aArgs, 'sourceRoot', null);
  7522. this._sources = new ArraySet();
  7523. this._names = new ArraySet();
  7524. this._mappings = [];
  7525. this._sourcesContents = null;
  7526. }
  7527. SourceMapGenerator.prototype._version = 3;
  7528. /**
  7529. * Creates a new SourceMapGenerator based on a SourceMapConsumer
  7530. *
  7531. * @param aSourceMapConsumer The SourceMap.
  7532. */
  7533. SourceMapGenerator.fromSourceMap =
  7534. function SourceMapGenerator_fromSourceMap(aSourceMapConsumer) {
  7535. var sourceRoot = aSourceMapConsumer.sourceRoot;
  7536. var generator = new SourceMapGenerator({
  7537. file: aSourceMapConsumer.file,
  7538. sourceRoot: sourceRoot
  7539. });
  7540. aSourceMapConsumer.eachMapping(function (mapping) {
  7541. var newMapping = {
  7542. generated: {
  7543. line: mapping.generatedLine,
  7544. column: mapping.generatedColumn
  7545. }
  7546. };
  7547. if (mapping.source) {
  7548. newMapping.source = mapping.source;
  7549. if (sourceRoot) {
  7550. newMapping.source = util.relative(sourceRoot, newMapping.source);
  7551. }
  7552. newMapping.original = {
  7553. line: mapping.originalLine,
  7554. column: mapping.originalColumn
  7555. };
  7556. if (mapping.name) {
  7557. newMapping.name = mapping.name;
  7558. }
  7559. }
  7560. generator.addMapping(newMapping);
  7561. });
  7562. aSourceMapConsumer.sources.forEach(function (sourceFile) {
  7563. var content = aSourceMapConsumer.sourceContentFor(sourceFile);
  7564. if (content) {
  7565. generator.setSourceContent(sourceFile, content);
  7566. }
  7567. });
  7568. return generator;
  7569. };
  7570. /**
  7571. * Add a single mapping from original source line and column to the generated
  7572. * source's line and column for this source map being created. The mapping
  7573. * object should have the following properties:
  7574. *
  7575. * - generated: An object with the generated line and column positions.
  7576. * - original: An object with the original line and column positions.
  7577. * - source: The original source file (relative to the sourceRoot).
  7578. * - name: An optional original token name for this mapping.
  7579. */
  7580. SourceMapGenerator.prototype.addMapping =
  7581. function SourceMapGenerator_addMapping(aArgs) {
  7582. var generated = util.getArg(aArgs, 'generated');
  7583. var original = util.getArg(aArgs, 'original', null);
  7584. var source = util.getArg(aArgs, 'source', null);
  7585. var name = util.getArg(aArgs, 'name', null);
  7586. this._validateMapping(generated, original, source, name);
  7587. if (source && !this._sources.has(source)) {
  7588. this._sources.add(source);
  7589. }
  7590. if (name && !this._names.has(name)) {
  7591. this._names.add(name);
  7592. }
  7593. this._mappings.push({
  7594. generatedLine: generated.line,
  7595. generatedColumn: generated.column,
  7596. originalLine: original != null && original.line,
  7597. originalColumn: original != null && original.column,
  7598. source: source,
  7599. name: name
  7600. });
  7601. };
  7602. /**
  7603. * Set the source content for a source file.
  7604. */
  7605. SourceMapGenerator.prototype.setSourceContent =
  7606. function SourceMapGenerator_setSourceContent(aSourceFile, aSourceContent) {
  7607. var source = aSourceFile;
  7608. if (this._sourceRoot) {
  7609. source = util.relative(this._sourceRoot, source);
  7610. }
  7611. if (aSourceContent !== null) {
  7612. // Add the source content to the _sourcesContents map.
  7613. // Create a new _sourcesContents map if the property is null.
  7614. if (!this._sourcesContents) {
  7615. this._sourcesContents = {};
  7616. }
  7617. this._sourcesContents[util.toSetString(source)] = aSourceContent;
  7618. } else {
  7619. // Remove the source file from the _sourcesContents map.
  7620. // If the _sourcesContents map is empty, set the property to null.
  7621. delete this._sourcesContents[util.toSetString(source)];
  7622. if (Object.keys(this._sourcesContents).length === 0) {
  7623. this._sourcesContents = null;
  7624. }
  7625. }
  7626. };
  7627. /**
  7628. * Applies the mappings of a sub-source-map for a specific source file to the
  7629. * source map being generated. Each mapping to the supplied source file is
  7630. * rewritten using the supplied source map. Note: The resolution for the
  7631. * resulting mappings is the minimium of this map and the supplied map.
  7632. *
  7633. * @param aSourceMapConsumer The source map to be applied.
  7634. * @param aSourceFile Optional. The filename of the source file.
  7635. * If omitted, SourceMapConsumer's file property will be used.
  7636. */
  7637. SourceMapGenerator.prototype.applySourceMap =
  7638. function SourceMapGenerator_applySourceMap(aSourceMapConsumer, aSourceFile) {
  7639. // If aSourceFile is omitted, we will use the file property of the SourceMap
  7640. if (!aSourceFile) {
  7641. aSourceFile = aSourceMapConsumer.file;
  7642. }
  7643. var sourceRoot = this._sourceRoot;
  7644. // Make "aSourceFile" relative if an absolute Url is passed.
  7645. if (sourceRoot) {
  7646. aSourceFile = util.relative(sourceRoot, aSourceFile);
  7647. }
  7648. // Applying the SourceMap can add and remove items from the sources and
  7649. // the names array.
  7650. var newSources = new ArraySet();
  7651. var newNames = new ArraySet();
  7652. // Find mappings for the "aSourceFile"
  7653. this._mappings.forEach(function (mapping) {
  7654. if (mapping.source === aSourceFile && mapping.originalLine) {
  7655. // Check if it can be mapped by the source map, then update the mapping.
  7656. var original = aSourceMapConsumer.originalPositionFor({
  7657. line: mapping.originalLine,
  7658. column: mapping.originalColumn
  7659. });
  7660. if (original.source !== null) {
  7661. // Copy mapping
  7662. if (sourceRoot) {
  7663. mapping.source = util.relative(sourceRoot, original.source);
  7664. } else {
  7665. mapping.source = original.source;
  7666. }
  7667. mapping.originalLine = original.line;
  7668. mapping.originalColumn = original.column;
  7669. if (original.name !== null && mapping.name !== null) {
  7670. // Only use the identifier name if it's an identifier
  7671. // in both SourceMaps
  7672. mapping.name = original.name;
  7673. }
  7674. }
  7675. }
  7676. var source = mapping.source;
  7677. if (source && !newSources.has(source)) {
  7678. newSources.add(source);
  7679. }
  7680. var name = mapping.name;
  7681. if (name && !newNames.has(name)) {
  7682. newNames.add(name);
  7683. }
  7684. }, this);
  7685. this._sources = newSources;
  7686. this._names = newNames;
  7687. // Copy sourcesContents of applied map.
  7688. aSourceMapConsumer.sources.forEach(function (sourceFile) {
  7689. var content = aSourceMapConsumer.sourceContentFor(sourceFile);
  7690. if (content) {
  7691. if (sourceRoot) {
  7692. sourceFile = util.relative(sourceRoot, sourceFile);
  7693. }
  7694. this.setSourceContent(sourceFile, content);
  7695. }
  7696. }, this);
  7697. };
  7698. /**
  7699. * A mapping can have one of the three levels of data:
  7700. *
  7701. * 1. Just the generated position.
  7702. * 2. The Generated position, original position, and original source.
  7703. * 3. Generated and original position, original source, as well as a name
  7704. * token.
  7705. *
  7706. * To maintain consistency, we validate that any new mapping being added falls
  7707. * in to one of these categories.
  7708. */
  7709. SourceMapGenerator.prototype._validateMapping =
  7710. function SourceMapGenerator_validateMapping(aGenerated, aOriginal, aSource,
  7711. aName) {
  7712. if (aGenerated && 'line' in aGenerated && 'column' in aGenerated
  7713. && aGenerated.line > 0 && aGenerated.column >= 0
  7714. && !aOriginal && !aSource && !aName) {
  7715. // Case 1.
  7716. return;
  7717. }
  7718. else if (aGenerated && 'line' in aGenerated && 'column' in aGenerated
  7719. && aOriginal && 'line' in aOriginal && 'column' in aOriginal
  7720. && aGenerated.line > 0 && aGenerated.column >= 0
  7721. && aOriginal.line > 0 && aOriginal.column >= 0
  7722. && aSource) {
  7723. // Cases 2 and 3.
  7724. return;
  7725. }
  7726. else {
  7727. throw new Error('Invalid mapping: ' + JSON.stringify({
  7728. generated: aGenerated,
  7729. source: aSource,
  7730. orginal: aOriginal,
  7731. name: aName
  7732. }));
  7733. }
  7734. };
  7735. /**
  7736. * Serialize the accumulated mappings in to the stream of base 64 VLQs
  7737. * specified by the source map format.
  7738. */
  7739. SourceMapGenerator.prototype._serializeMappings =
  7740. function SourceMapGenerator_serializeMappings() {
  7741. var previousGeneratedColumn = 0;
  7742. var previousGeneratedLine = 1;
  7743. var previousOriginalColumn = 0;
  7744. var previousOriginalLine = 0;
  7745. var previousName = 0;
  7746. var previousSource = 0;
  7747. var result = '';
  7748. var mapping;
  7749. // The mappings must be guaranteed to be in sorted order before we start
  7750. // serializing them or else the generated line numbers (which are defined
  7751. // via the ';' separators) will be all messed up. Note: it might be more
  7752. // performant to maintain the sorting as we insert them, rather than as we
  7753. // serialize them, but the big O is the same either way.
  7754. this._mappings.sort(util.compareByGeneratedPositions);
  7755. for (var i = 0, len = this._mappings.length; i < len; i++) {
  7756. mapping = this._mappings[i];
  7757. if (mapping.generatedLine !== previousGeneratedLine) {
  7758. previousGeneratedColumn = 0;
  7759. while (mapping.generatedLine !== previousGeneratedLine) {
  7760. result += ';';
  7761. previousGeneratedLine++;
  7762. }
  7763. }
  7764. else {
  7765. if (i > 0) {
  7766. if (!util.compareByGeneratedPositions(mapping, this._mappings[i - 1])) {
  7767. continue;
  7768. }
  7769. result += ',';
  7770. }
  7771. }
  7772. result += base64VLQ.encode(mapping.generatedColumn
  7773. - previousGeneratedColumn);
  7774. previousGeneratedColumn = mapping.generatedColumn;
  7775. if (mapping.source) {
  7776. result += base64VLQ.encode(this._sources.indexOf(mapping.source)
  7777. - previousSource);
  7778. previousSource = this._sources.indexOf(mapping.source);
  7779. // lines are stored 0-based in SourceMap spec version 3
  7780. result += base64VLQ.encode(mapping.originalLine - 1
  7781. - previousOriginalLine);
  7782. previousOriginalLine = mapping.originalLine - 1;
  7783. result += base64VLQ.encode(mapping.originalColumn
  7784. - previousOriginalColumn);
  7785. previousOriginalColumn = mapping.originalColumn;
  7786. if (mapping.name) {
  7787. result += base64VLQ.encode(this._names.indexOf(mapping.name)
  7788. - previousName);
  7789. previousName = this._names.indexOf(mapping.name);
  7790. }
  7791. }
  7792. }
  7793. return result;
  7794. };
  7795. SourceMapGenerator.prototype._generateSourcesContent =
  7796. function SourceMapGenerator_generateSourcesContent(aSources, aSourceRoot) {
  7797. return aSources.map(function (source) {
  7798. if (!this._sourcesContents) {
  7799. return null;
  7800. }
  7801. if (aSourceRoot) {
  7802. source = util.relative(aSourceRoot, source);
  7803. }
  7804. var key = util.toSetString(source);
  7805. return Object.prototype.hasOwnProperty.call(this._sourcesContents,
  7806. key)
  7807. ? this._sourcesContents[key]
  7808. : null;
  7809. }, this);
  7810. };
  7811. /**
  7812. * Externalize the source map.
  7813. */
  7814. SourceMapGenerator.prototype.toJSON =
  7815. function SourceMapGenerator_toJSON() {
  7816. var map = {
  7817. version: this._version,
  7818. file: this._file,
  7819. sources: this._sources.toArray(),
  7820. names: this._names.toArray(),
  7821. mappings: this._serializeMappings()
  7822. };
  7823. if (this._sourceRoot) {
  7824. map.sourceRoot = this._sourceRoot;
  7825. }
  7826. if (this._sourcesContents) {
  7827. map.sourcesContent = this._generateSourcesContent(map.sources, map.sourceRoot);
  7828. }
  7829. return map;
  7830. };
  7831. /**
  7832. * Render the source map being generated to a string.
  7833. */
  7834. SourceMapGenerator.prototype.toString =
  7835. function SourceMapGenerator_toString() {
  7836. return JSON.stringify(this);
  7837. };
  7838. exports.SourceMapGenerator = SourceMapGenerator;
  7839. });
  7840. }, { "./array-set": 9, "./base64-vlq": 10, "./util": 16, "amdefine": 17 }], 15: [function (_dereq_, module, exports) {
  7841. /* -*- Mode: js; js-indent-level: 2; -*- */
  7842. /*
  7843. * Copyright 2011 Mozilla Foundation and contributors
  7844. * Licensed under the New BSD license. See LICENSE or:
  7845. * http://opensource.org/licenses/BSD-3-Clause
  7846. */
  7847. if (typeof define !== 'function') {
  7848. var define = _dereq_('amdefine')(module, _dereq_);
  7849. }
  7850. define(function (_dereq_, exports, module) {
  7851. var SourceMapGenerator = _dereq_('./source-map-generator').SourceMapGenerator;
  7852. var util = _dereq_('./util');
  7853. /**
  7854. * SourceNodes provide a way to abstract over interpolating/concatenating
  7855. * snippets of generated JavaScript source code while maintaining the line and
  7856. * column information associated with the original source code.
  7857. *
  7858. * @param aLine The original line number.
  7859. * @param aColumn The original column number.
  7860. * @param aSource The original source's filename.
  7861. * @param aChunks Optional. An array of strings which are snippets of
  7862. * generated JS, or other SourceNodes.
  7863. * @param aName The original identifier.
  7864. */
  7865. function SourceNode(aLine, aColumn, aSource, aChunks, aName) {
  7866. this.children = [];
  7867. this.sourceContents = {};
  7868. this.line = aLine === undefined ? null : aLine;
  7869. this.column = aColumn === undefined ? null : aColumn;
  7870. this.source = aSource === undefined ? null : aSource;
  7871. this.name = aName === undefined ? null : aName;
  7872. if (aChunks != null) this.add(aChunks);
  7873. }
  7874. /**
  7875. * Creates a SourceNode from generated code and a SourceMapConsumer.
  7876. *
  7877. * @param aGeneratedCode The generated code
  7878. * @param aSourceMapConsumer The SourceMap for the generated code
  7879. */
  7880. SourceNode.fromStringWithSourceMap =
  7881. function SourceNode_fromStringWithSourceMap(aGeneratedCode, aSourceMapConsumer) {
  7882. // The SourceNode we want to fill with the generated code
  7883. // and the SourceMap
  7884. var node = new SourceNode();
  7885. // The generated code
  7886. // Processed fragments are removed from this array.
  7887. var remainingLines = aGeneratedCode.split('\n');
  7888. // We need to remember the position of "remainingLines"
  7889. var lastGeneratedLine = 1, lastGeneratedColumn = 0;
  7890. // The generate SourceNodes we need a code range.
  7891. // To extract it current and last mapping is used.
  7892. // Here we store the last mapping.
  7893. var lastMapping = null;
  7894. aSourceMapConsumer.eachMapping(function (mapping) {
  7895. if (lastMapping === null) {
  7896. // We add the generated code until the first mapping
  7897. // to the SourceNode without any mapping.
  7898. // Each line is added as separate string.
  7899. while (lastGeneratedLine < mapping.generatedLine) {
  7900. node.add(remainingLines.shift() + "\n");
  7901. lastGeneratedLine++;
  7902. }
  7903. if (lastGeneratedColumn < mapping.generatedColumn) {
  7904. var nextLine = remainingLines[0];
  7905. node.add(nextLine.substr(0, mapping.generatedColumn));
  7906. remainingLines[0] = nextLine.substr(mapping.generatedColumn);
  7907. lastGeneratedColumn = mapping.generatedColumn;
  7908. }
  7909. } else {
  7910. // We add the code from "lastMapping" to "mapping":
  7911. // First check if there is a new line in between.
  7912. if (lastGeneratedLine < mapping.generatedLine) {
  7913. var code = "";
  7914. // Associate full lines with "lastMapping"
  7915. do {
  7916. code += remainingLines.shift() + "\n";
  7917. lastGeneratedLine++;
  7918. lastGeneratedColumn = 0;
  7919. } while (lastGeneratedLine < mapping.generatedLine);
  7920. // When we reached the correct line, we add code until we
  7921. // reach the correct column too.
  7922. if (lastGeneratedColumn < mapping.generatedColumn) {
  7923. var nextLine = remainingLines[0];
  7924. code += nextLine.substr(0, mapping.generatedColumn);
  7925. remainingLines[0] = nextLine.substr(mapping.generatedColumn);
  7926. lastGeneratedColumn = mapping.generatedColumn;
  7927. }
  7928. // Create the SourceNode.
  7929. addMappingWithCode(lastMapping, code);
  7930. } else {
  7931. // There is no new line in between.
  7932. // Associate the code between "lastGeneratedColumn" and
  7933. // "mapping.generatedColumn" with "lastMapping"
  7934. var nextLine = remainingLines[0];
  7935. var code = nextLine.substr(0, mapping.generatedColumn -
  7936. lastGeneratedColumn);
  7937. remainingLines[0] = nextLine.substr(mapping.generatedColumn -
  7938. lastGeneratedColumn);
  7939. lastGeneratedColumn = mapping.generatedColumn;
  7940. addMappingWithCode(lastMapping, code);
  7941. }
  7942. }
  7943. lastMapping = mapping;
  7944. }, this);
  7945. // We have processed all mappings.
  7946. // Associate the remaining code in the current line with "lastMapping"
  7947. // and add the remaining lines without any mapping
  7948. addMappingWithCode(lastMapping, remainingLines.join("\n"));
  7949. // Copy sourcesContent into SourceNode
  7950. aSourceMapConsumer.sources.forEach(function (sourceFile) {
  7951. var content = aSourceMapConsumer.sourceContentFor(sourceFile);
  7952. if (content) {
  7953. node.setSourceContent(sourceFile, content);
  7954. }
  7955. });
  7956. return node;
  7957. function addMappingWithCode(mapping, code) {
  7958. if (mapping === null || mapping.source === undefined) {
  7959. node.add(code);
  7960. } else {
  7961. node.add(new SourceNode(mapping.originalLine,
  7962. mapping.originalColumn,
  7963. mapping.source,
  7964. code,
  7965. mapping.name));
  7966. }
  7967. }
  7968. };
  7969. /**
  7970. * Add a chunk of generated JS to this source node.
  7971. *
  7972. * @param aChunk A string snippet of generated JS code, another instance of
  7973. * SourceNode, or an array where each member is one of those things.
  7974. */
  7975. SourceNode.prototype.add = function SourceNode_add(aChunk) {
  7976. if (Array.isArray(aChunk)) {
  7977. aChunk.forEach(function (chunk) {
  7978. this.add(chunk);
  7979. }, this);
  7980. }
  7981. else if (aChunk instanceof SourceNode || typeof aChunk === "string") {
  7982. if (aChunk) {
  7983. this.children.push(aChunk);
  7984. }
  7985. }
  7986. else {
  7987. throw new TypeError(
  7988. "Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk
  7989. );
  7990. }
  7991. return this;
  7992. };
  7993. /**
  7994. * Add a chunk of generated JS to the beginning of this source node.
  7995. *
  7996. * @param aChunk A string snippet of generated JS code, another instance of
  7997. * SourceNode, or an array where each member is one of those things.
  7998. */
  7999. SourceNode.prototype.prepend = function SourceNode_prepend(aChunk) {
  8000. if (Array.isArray(aChunk)) {
  8001. for (var i = aChunk.length - 1; i >= 0; i--) {
  8002. this.prepend(aChunk[i]);
  8003. }
  8004. }
  8005. else if (aChunk instanceof SourceNode || typeof aChunk === "string") {
  8006. this.children.unshift(aChunk);
  8007. }
  8008. else {
  8009. throw new TypeError(
  8010. "Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk
  8011. );
  8012. }
  8013. return this;
  8014. };
  8015. /**
  8016. * Walk over the tree of JS snippets in this node and its children. The
  8017. * walking function is called once for each snippet of JS and is passed that
  8018. * snippet and the its original associated source's line/column location.
  8019. *
  8020. * @param aFn The traversal function.
  8021. */
  8022. SourceNode.prototype.walk = function SourceNode_walk(aFn) {
  8023. var chunk;
  8024. for (var i = 0, len = this.children.length; i < len; i++) {
  8025. chunk = this.children[i];
  8026. if (chunk instanceof SourceNode) {
  8027. chunk.walk(aFn);
  8028. }
  8029. else {
  8030. if (chunk !== '') {
  8031. aFn(chunk, {
  8032. source: this.source,
  8033. line: this.line,
  8034. column: this.column,
  8035. name: this.name
  8036. });
  8037. }
  8038. }
  8039. }
  8040. };
  8041. /**
  8042. * Like `String.prototype.join` except for SourceNodes. Inserts `aStr` between
  8043. * each of `this.children`.
  8044. *
  8045. * @param aSep The separator.
  8046. */
  8047. SourceNode.prototype.join = function SourceNode_join(aSep) {
  8048. var newChildren;
  8049. var i;
  8050. var len = this.children.length;
  8051. if (len > 0) {
  8052. newChildren = [];
  8053. for (i = 0; i < len - 1; i++) {
  8054. newChildren.push(this.children[i]);
  8055. newChildren.push(aSep);
  8056. }
  8057. newChildren.push(this.children[i]);
  8058. this.children = newChildren;
  8059. }
  8060. return this;
  8061. };
  8062. /**
  8063. * Call String.prototype.replace on the very right-most source snippet. Useful
  8064. * for trimming whitespace from the end of a source node, etc.
  8065. *
  8066. * @param aPattern The pattern to replace.
  8067. * @param aReplacement The thing to replace the pattern with.
  8068. */
  8069. SourceNode.prototype.replaceRight = function SourceNode_replaceRight(aPattern, aReplacement) {
  8070. var lastChild = this.children[this.children.length - 1];
  8071. if (lastChild instanceof SourceNode) {
  8072. lastChild.replaceRight(aPattern, aReplacement);
  8073. }
  8074. else if (typeof lastChild === 'string') {
  8075. this.children[this.children.length - 1] = lastChild.replace(aPattern, aReplacement);
  8076. }
  8077. else {
  8078. this.children.push(''.replace(aPattern, aReplacement));
  8079. }
  8080. return this;
  8081. };
  8082. /**
  8083. * Set the source content for a source file. This will be added to the SourceMapGenerator
  8084. * in the sourcesContent field.
  8085. *
  8086. * @param aSourceFile The filename of the source file
  8087. * @param aSourceContent The content of the source file
  8088. */
  8089. SourceNode.prototype.setSourceContent =
  8090. function SourceNode_setSourceContent(aSourceFile, aSourceContent) {
  8091. this.sourceContents[util.toSetString(aSourceFile)] = aSourceContent;
  8092. };
  8093. /**
  8094. * Walk over the tree of SourceNodes. The walking function is called for each
  8095. * source file content and is passed the filename and source content.
  8096. *
  8097. * @param aFn The traversal function.
  8098. */
  8099. SourceNode.prototype.walkSourceContents =
  8100. function SourceNode_walkSourceContents(aFn) {
  8101. for (var i = 0, len = this.children.length; i < len; i++) {
  8102. if (this.children[i] instanceof SourceNode) {
  8103. this.children[i].walkSourceContents(aFn);
  8104. }
  8105. }
  8106. var sources = Object.keys(this.sourceContents);
  8107. for (var i = 0, len = sources.length; i < len; i++) {
  8108. aFn(util.fromSetString(sources[i]), this.sourceContents[sources[i]]);
  8109. }
  8110. };
  8111. /**
  8112. * Return the string representation of this source node. Walks over the tree
  8113. * and concatenates all the various snippets together to one string.
  8114. */
  8115. SourceNode.prototype.toString = function SourceNode_toString() {
  8116. var str = "";
  8117. this.walk(function (chunk) {
  8118. str += chunk;
  8119. });
  8120. return str;
  8121. };
  8122. /**
  8123. * Returns the string representation of this source node along with a source
  8124. * map.
  8125. */
  8126. SourceNode.prototype.toStringWithSourceMap = function SourceNode_toStringWithSourceMap(aArgs) {
  8127. var generated = {
  8128. code: "",
  8129. line: 1,
  8130. column: 0
  8131. };
  8132. var map = new SourceMapGenerator(aArgs);
  8133. var sourceMappingActive = false;
  8134. var lastOriginalSource = null;
  8135. var lastOriginalLine = null;
  8136. var lastOriginalColumn = null;
  8137. var lastOriginalName = null;
  8138. this.walk(function (chunk, original) {
  8139. generated.code += chunk;
  8140. if (original.source !== null
  8141. && original.line !== null
  8142. && original.column !== null) {
  8143. if (lastOriginalSource !== original.source
  8144. || lastOriginalLine !== original.line
  8145. || lastOriginalColumn !== original.column
  8146. || lastOriginalName !== original.name) {
  8147. map.addMapping({
  8148. source: original.source,
  8149. original: {
  8150. line: original.line,
  8151. column: original.column
  8152. },
  8153. generated: {
  8154. line: generated.line,
  8155. column: generated.column
  8156. },
  8157. name: original.name
  8158. });
  8159. }
  8160. lastOriginalSource = original.source;
  8161. lastOriginalLine = original.line;
  8162. lastOriginalColumn = original.column;
  8163. lastOriginalName = original.name;
  8164. sourceMappingActive = true;
  8165. } else if (sourceMappingActive) {
  8166. map.addMapping({
  8167. generated: {
  8168. line: generated.line,
  8169. column: generated.column
  8170. }
  8171. });
  8172. lastOriginalSource = null;
  8173. sourceMappingActive = false;
  8174. }
  8175. chunk.split('').forEach(function (ch) {
  8176. if (ch === '\n') {
  8177. generated.line++;
  8178. generated.column = 0;
  8179. } else {
  8180. generated.column++;
  8181. }
  8182. });
  8183. });
  8184. this.walkSourceContents(function (sourceFile, sourceContent) {
  8185. map.setSourceContent(sourceFile, sourceContent);
  8186. });
  8187. return { code: generated.code, map: map };
  8188. };
  8189. exports.SourceNode = SourceNode;
  8190. });
  8191. }, { "./source-map-generator": 14, "./util": 16, "amdefine": 17 }], 16: [function (_dereq_, module, exports) {
  8192. /* -*- Mode: js; js-indent-level: 2; -*- */
  8193. /*
  8194. * Copyright 2011 Mozilla Foundation and contributors
  8195. * Licensed under the New BSD license. See LICENSE or:
  8196. * http://opensource.org/licenses/BSD-3-Clause
  8197. */
  8198. if (typeof define !== 'function') {
  8199. var define = _dereq_('amdefine')(module, _dereq_);
  8200. }
  8201. define(function (_dereq_, exports, module) {
  8202. /**
  8203. * This is a helper function for getting values from parameter/options
  8204. * objects.
  8205. *
  8206. * @param args The object we are extracting values from
  8207. * @param name The name of the property we are getting.
  8208. * @param defaultValue An optional value to return if the property is missing
  8209. * from the object. If this is not specified and the property is missing, an
  8210. * error will be thrown.
  8211. */
  8212. function getArg(aArgs, aName, aDefaultValue) {
  8213. if (aName in aArgs) {
  8214. return aArgs[aName];
  8215. } else if (arguments.length === 3) {
  8216. return aDefaultValue;
  8217. } else {
  8218. throw new Error('"' + aName + '" is a required argument.');
  8219. }
  8220. }
  8221. exports.getArg = getArg;
  8222. var urlRegexp = /([\w+\-.]+):\/\/((\w+:\w+)@)?([\w.]+)?(:(\d+))?(\S+)?/;
  8223. var dataUrlRegexp = /^data:.+\,.+/;
  8224. function urlParse(aUrl) {
  8225. var match = aUrl.match(urlRegexp);
  8226. if (!match) {
  8227. return null;
  8228. }
  8229. return {
  8230. scheme: match[1],
  8231. auth: match[3],
  8232. host: match[4],
  8233. port: match[6],
  8234. path: match[7]
  8235. };
  8236. }
  8237. exports.urlParse = urlParse;
  8238. function urlGenerate(aParsedUrl) {
  8239. var url = aParsedUrl.scheme + "://";
  8240. if (aParsedUrl.auth) {
  8241. url += aParsedUrl.auth + "@"
  8242. }
  8243. if (aParsedUrl.host) {
  8244. url += aParsedUrl.host;
  8245. }
  8246. if (aParsedUrl.port) {
  8247. url += ":" + aParsedUrl.port
  8248. }
  8249. if (aParsedUrl.path) {
  8250. url += aParsedUrl.path;
  8251. }
  8252. return url;
  8253. }
  8254. exports.urlGenerate = urlGenerate;
  8255. function join(aRoot, aPath) {
  8256. var url;
  8257. if (aPath.match(urlRegexp) || aPath.match(dataUrlRegexp)) {
  8258. return aPath;
  8259. }
  8260. if (aPath.charAt(0) === '/' && (url = urlParse(aRoot))) {
  8261. url.path = aPath;
  8262. return urlGenerate(url);
  8263. }
  8264. return aRoot.replace(/\/$/, '') + '/' + aPath;
  8265. }
  8266. exports.join = join;
  8267. /**
  8268. * Because behavior goes wacky when you set `__proto__` on objects, we
  8269. * have to prefix all the strings in our set with an arbitrary character.
  8270. *
  8271. * See https://github.com/mozilla/source-map/pull/31 and
  8272. * https://github.com/mozilla/source-map/issues/30
  8273. *
  8274. * @param String aStr
  8275. */
  8276. function toSetString(aStr) {
  8277. return '$' + aStr;
  8278. }
  8279. exports.toSetString = toSetString;
  8280. function fromSetString(aStr) {
  8281. return aStr.substr(1);
  8282. }
  8283. exports.fromSetString = fromSetString;
  8284. function relative(aRoot, aPath) {
  8285. aRoot = aRoot.replace(/\/$/, '');
  8286. var url = urlParse(aRoot);
  8287. if (aPath.charAt(0) == "/" && url && url.path == "/") {
  8288. return aPath.slice(1);
  8289. }
  8290. return aPath.indexOf(aRoot + '/') === 0
  8291. ? aPath.substr(aRoot.length + 1)
  8292. : aPath;
  8293. }
  8294. exports.relative = relative;
  8295. function strcmp(aStr1, aStr2) {
  8296. var s1 = aStr1 || "";
  8297. var s2 = aStr2 || "";
  8298. return (s1 > s2) - (s1 < s2);
  8299. }
  8300. /**
  8301. * Comparator between two mappings where the original positions are compared.
  8302. *
  8303. * Optionally pass in `true` as `onlyCompareGenerated` to consider two
  8304. * mappings with the same original source/line/column, but different generated
  8305. * line and column the same. Useful when searching for a mapping with a
  8306. * stubbed out mapping.
  8307. */
  8308. function compareByOriginalPositions(mappingA, mappingB, onlyCompareOriginal) {
  8309. var cmp;
  8310. cmp = strcmp(mappingA.source, mappingB.source);
  8311. if (cmp) {
  8312. return cmp;
  8313. }
  8314. cmp = mappingA.originalLine - mappingB.originalLine;
  8315. if (cmp) {
  8316. return cmp;
  8317. }
  8318. cmp = mappingA.originalColumn - mappingB.originalColumn;
  8319. if (cmp || onlyCompareOriginal) {
  8320. return cmp;
  8321. }
  8322. cmp = strcmp(mappingA.name, mappingB.name);
  8323. if (cmp) {
  8324. return cmp;
  8325. }
  8326. cmp = mappingA.generatedLine - mappingB.generatedLine;
  8327. if (cmp) {
  8328. return cmp;
  8329. }
  8330. return mappingA.generatedColumn - mappingB.generatedColumn;
  8331. };
  8332. exports.compareByOriginalPositions = compareByOriginalPositions;
  8333. /**
  8334. * Comparator between two mappings where the generated positions are
  8335. * compared.
  8336. *
  8337. * Optionally pass in `true` as `onlyCompareGenerated` to consider two
  8338. * mappings with the same generated line and column, but different
  8339. * source/name/original line and column the same. Useful when searching for a
  8340. * mapping with a stubbed out mapping.
  8341. */
  8342. function compareByGeneratedPositions(mappingA, mappingB, onlyCompareGenerated) {
  8343. var cmp;
  8344. cmp = mappingA.generatedLine - mappingB.generatedLine;
  8345. if (cmp) {
  8346. return cmp;
  8347. }
  8348. cmp = mappingA.generatedColumn - mappingB.generatedColumn;
  8349. if (cmp || onlyCompareGenerated) {
  8350. return cmp;
  8351. }
  8352. cmp = strcmp(mappingA.source, mappingB.source);
  8353. if (cmp) {
  8354. return cmp;
  8355. }
  8356. cmp = mappingA.originalLine - mappingB.originalLine;
  8357. if (cmp) {
  8358. return cmp;
  8359. }
  8360. cmp = mappingA.originalColumn - mappingB.originalColumn;
  8361. if (cmp) {
  8362. return cmp;
  8363. }
  8364. return strcmp(mappingA.name, mappingB.name);
  8365. };
  8366. exports.compareByGeneratedPositions = compareByGeneratedPositions;
  8367. });
  8368. }, { "amdefine": 17 }], 17: [function (_dereq_, module, exports) {
  8369. (function (process, __filename) {
  8370. /** vim: et:ts=4:sw=4:sts=4
  8371. * @license amdefine 0.1.0 Copyright (c) 2011, The Dojo Foundation All Rights Reserved.
  8372. * Available via the MIT or new BSD license.
  8373. * see: http://github.com/jrburke/amdefine for details
  8374. */
  8375. /*jslint node: true */
  8376. /*global module, process */
  8377. 'use strict';
  8378. /**
  8379. * Creates a define for node.
  8380. * @param {Object} module the "module" object that is defined by Node for the
  8381. * current module.
  8382. * @param {Function} [requireFn]. Node's require function for the current module.
  8383. * It only needs to be passed in Node versions before 0.5, when module.require
  8384. * did not exist.
  8385. * @returns {Function} a define function that is usable for the current node
  8386. * module.
  8387. */
  8388. function amdefine(module, requireFn) {
  8389. 'use strict';
  8390. var defineCache = {},
  8391. loaderCache = {},
  8392. alreadyCalled = false,
  8393. path = _dereq_('path'),
  8394. makeRequire, stringRequire;
  8395. /**
  8396. * Trims the . and .. from an array of path segments.
  8397. * It will keep a leading path segment if a .. will become
  8398. * the first path segment, to help with module name lookups,
  8399. * which act like paths, but can be remapped. But the end result,
  8400. * all paths that use this function should look normalized.
  8401. * NOTE: this method MODIFIES the input array.
  8402. * @param {Array} ary the array of path segments.
  8403. */
  8404. function trimDots(ary) {
  8405. var i, part;
  8406. for (i = 0; ary[i]; i += 1) {
  8407. part = ary[i];
  8408. if (part === '.') {
  8409. ary.splice(i, 1);
  8410. i -= 1;
  8411. } else if (part === '..') {
  8412. if (i === 1 && (ary[2] === '..' || ary[0] === '..')) {
  8413. //End of the line. Keep at least one non-dot
  8414. //path segment at the front so it can be mapped
  8415. //correctly to disk. Otherwise, there is likely
  8416. //no path mapping for a path starting with '..'.
  8417. //This can still fail, but catches the most reasonable
  8418. //uses of ..
  8419. break;
  8420. } else if (i > 0) {
  8421. ary.splice(i - 1, 2);
  8422. i -= 2;
  8423. }
  8424. }
  8425. }
  8426. }
  8427. function normalize(name, baseName) {
  8428. var baseParts;
  8429. //Adjust any relative paths.
  8430. if (name && name.charAt(0) === '.') {
  8431. //If have a base name, try to normalize against it,
  8432. //otherwise, assume it is a top-level require that will
  8433. //be relative to baseUrl in the end.
  8434. if (baseName) {
  8435. baseParts = baseName.split('/');
  8436. baseParts = baseParts.slice(0, baseParts.length - 1);
  8437. baseParts = baseParts.concat(name.split('/'));
  8438. trimDots(baseParts);
  8439. name = baseParts.join('/');
  8440. }
  8441. }
  8442. return name;
  8443. }
  8444. /**
  8445. * Create the normalize() function passed to a loader plugin's
  8446. * normalize method.
  8447. */
  8448. function makeNormalize(relName) {
  8449. return function (name) {
  8450. return normalize(name, relName);
  8451. };
  8452. }
  8453. function makeLoad(id) {
  8454. function load(value) {
  8455. loaderCache[id] = value;
  8456. }
  8457. load.fromText = function (id, text) {
  8458. //This one is difficult because the text can/probably uses
  8459. //define, and any relative paths and requires should be relative
  8460. //to that id was it would be found on disk. But this would require
  8461. //bootstrapping a module/require fairly deeply from node core.
  8462. //Not sure how best to go about that yet.
  8463. throw new Error('amdefine does not implement load.fromText');
  8464. };
  8465. return load;
  8466. }
  8467. makeRequire = function (systemRequire, exports, module, relId) {
  8468. function amdRequire(deps, callback) {
  8469. if (typeof deps === 'string') {
  8470. //Synchronous, single module require('')
  8471. return stringRequire(systemRequire, exports, module, deps, relId);
  8472. } else {
  8473. //Array of dependencies with a callback.
  8474. //Convert the dependencies to modules.
  8475. deps = deps.map(function (depName) {
  8476. return stringRequire(systemRequire, exports, module, depName, relId);
  8477. });
  8478. //Wait for next tick to call back the require call.
  8479. process.nextTick(function () {
  8480. callback.apply(null, deps);
  8481. });
  8482. }
  8483. }
  8484. amdRequire.toUrl = function (filePath) {
  8485. if (filePath.indexOf('.') === 0) {
  8486. return normalize(filePath, path.dirname(module.filename));
  8487. } else {
  8488. return filePath;
  8489. }
  8490. };
  8491. return amdRequire;
  8492. };
  8493. //Favor explicit value, passed in if the module wants to support Node 0.4.
  8494. requireFn = requireFn || function req() {
  8495. return module.require.apply(module, arguments);
  8496. };
  8497. function runFactory(id, deps, factory) {
  8498. var r, e, m, result;
  8499. if (id) {
  8500. e = loaderCache[id] = {};
  8501. m = {
  8502. id: id,
  8503. uri: __filename,
  8504. exports: e
  8505. };
  8506. r = makeRequire(requireFn, e, m, id);
  8507. } else {
  8508. //Only support one define call per file
  8509. if (alreadyCalled) {
  8510. throw new Error('amdefine with no module ID cannot be called more than once per file.');
  8511. }
  8512. alreadyCalled = true;
  8513. //Use the real variables from node
  8514. //Use module.exports for exports, since
  8515. //the exports in here is amdefine exports.
  8516. e = module.exports;
  8517. m = module;
  8518. r = makeRequire(requireFn, e, m, module.id);
  8519. }
  8520. //If there are dependencies, they are strings, so need
  8521. //to convert them to dependency values.
  8522. if (deps) {
  8523. deps = deps.map(function (depName) {
  8524. return r(depName);
  8525. });
  8526. }
  8527. //Call the factory with the right dependencies.
  8528. if (typeof factory === 'function') {
  8529. result = factory.apply(m.exports, deps);
  8530. } else {
  8531. result = factory;
  8532. }
  8533. if (result !== undefined) {
  8534. m.exports = result;
  8535. if (id) {
  8536. loaderCache[id] = m.exports;
  8537. }
  8538. }
  8539. }
  8540. stringRequire = function (systemRequire, exports, module, id, relId) {
  8541. //Split the ID by a ! so that
  8542. var index = id.indexOf('!'),
  8543. originalId = id,
  8544. prefix, plugin;
  8545. if (index === -1) {
  8546. id = normalize(id, relId);
  8547. //Straight module lookup. If it is one of the special dependencies,
  8548. //deal with it, otherwise, delegate to node.
  8549. if (id === 'require') {
  8550. return makeRequire(systemRequire, exports, module, relId);
  8551. } else if (id === 'exports') {
  8552. return exports;
  8553. } else if (id === 'module') {
  8554. return module;
  8555. } else if (loaderCache.hasOwnProperty(id)) {
  8556. return loaderCache[id];
  8557. } else if (defineCache[id]) {
  8558. runFactory.apply(null, defineCache[id]);
  8559. return loaderCache[id];
  8560. } else {
  8561. if (systemRequire) {
  8562. return systemRequire(originalId);
  8563. } else {
  8564. throw new Error('No module with ID: ' + id);
  8565. }
  8566. }
  8567. } else {
  8568. //There is a plugin in play.
  8569. prefix = id.substring(0, index);
  8570. id = id.substring(index + 1, id.length);
  8571. plugin = stringRequire(systemRequire, exports, module, prefix, relId);
  8572. if (plugin.normalize) {
  8573. id = plugin.normalize(id, makeNormalize(relId));
  8574. } else {
  8575. //Normalize the ID normally.
  8576. id = normalize(id, relId);
  8577. }
  8578. if (loaderCache[id]) {
  8579. return loaderCache[id];
  8580. } else {
  8581. plugin.load(id, makeRequire(systemRequire, exports, module, relId), makeLoad(id), {});
  8582. return loaderCache[id];
  8583. }
  8584. }
  8585. };
  8586. //Create a define function specific to the module asking for amdefine.
  8587. function define(id, deps, factory) {
  8588. if (Array.isArray(id)) {
  8589. factory = deps;
  8590. deps = id;
  8591. id = undefined;
  8592. } else if (typeof id !== 'string') {
  8593. factory = id;
  8594. id = deps = undefined;
  8595. }
  8596. if (deps && !Array.isArray(deps)) {
  8597. factory = deps;
  8598. deps = undefined;
  8599. }
  8600. if (!deps) {
  8601. deps = ['require', 'exports', 'module'];
  8602. }
  8603. //Set up properties for this module. If an ID, then use
  8604. //internal cache. If no ID, then use the external variables
  8605. //for this node module.
  8606. if (id) {
  8607. //Put the module in deep freeze until there is a
  8608. //require call for it.
  8609. defineCache[id] = [id, deps, factory];
  8610. } else {
  8611. runFactory(id, deps, factory);
  8612. }
  8613. }
  8614. //define.require, which has access to all the values in the
  8615. //cache. Useful for AMD modules that all have IDs in the file,
  8616. //but need to finally export a value to node based on one of those
  8617. //IDs.
  8618. define.require = function (id) {
  8619. if (loaderCache[id]) {
  8620. return loaderCache[id];
  8621. }
  8622. if (defineCache[id]) {
  8623. runFactory.apply(null, defineCache[id]);
  8624. return loaderCache[id];
  8625. }
  8626. };
  8627. define.amd = {};
  8628. return define;
  8629. }
  8630. module.exports = amdefine;
  8631. }).call(this, _dereq_("/Users/poshannessy/FB/code/react/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js"), "/../node_modules/jstransform/node_modules/source-map/node_modules/amdefine/amdefine.js")
  8632. }, { "/Users/poshannessy/FB/code/react/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js": 4, "path": 5 }], 18: [function (_dereq_, module, exports) {
  8633. /**
  8634. * Copyright 2013 Facebook, Inc.
  8635. *
  8636. * Licensed under the Apache License, Version 2.0 (the "License");
  8637. * you may not use this file except in compliance with the License.
  8638. * You may obtain a copy of the License at
  8639. *
  8640. * http://www.apache.org/licenses/LICENSE-2.0
  8641. *
  8642. * Unless required by applicable law or agreed to in writing, software
  8643. * distributed under the License is distributed on an "AS IS" BASIS,
  8644. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  8645. * See the License for the specific language governing permissions and
  8646. * limitations under the License.
  8647. */
  8648. var docblockRe = /^\s*(\/\*\*(.|\r?\n)*?\*\/)/;
  8649. var ltrimRe = /^\s*/;
  8650. /**
  8651. * @param {String} contents
  8652. * @return {String}
  8653. */
  8654. function extract(contents) {
  8655. var match = contents.match(docblockRe);
  8656. if (match) {
  8657. return match[0].replace(ltrimRe, '') || '';
  8658. }
  8659. return '';
  8660. }
  8661. var commentStartRe = /^\/\*\*?/;
  8662. var commentEndRe = /\*+\/$/;
  8663. var wsRe = /[\t ]+/g;
  8664. var stringStartRe = /(\r?\n|^) *\*/g;
  8665. var multilineRe = /(?:^|\r?\n) *(@[^\r\n]*?) *\r?\n *([^@\r\n\s][^@\r\n]+?) *\r?\n/g;
  8666. var propertyRe = /(?:^|\r?\n) *@(\S+) *([^\r\n]*)/g;
  8667. /**
  8668. * @param {String} contents
  8669. * @return {Array}
  8670. */
  8671. function parse(docblock) {
  8672. docblock = docblock
  8673. .replace(commentStartRe, '')
  8674. .replace(commentEndRe, '')
  8675. .replace(wsRe, ' ')
  8676. .replace(stringStartRe, '$1');
  8677. // Normalize multi-line directives
  8678. var prev = '';
  8679. while (prev != docblock) {
  8680. prev = docblock;
  8681. docblock = docblock.replace(multilineRe, "\n$1 $2\n");
  8682. }
  8683. docblock = docblock.trim();
  8684. var result = [];
  8685. var match;
  8686. while (match = propertyRe.exec(docblock)) {
  8687. result.push([match[1], match[2]]);
  8688. }
  8689. return result;
  8690. }
  8691. /**
  8692. * Same as parse but returns an object of prop: value instead of array of paris
  8693. * If a property appers more than once the last one will be returned
  8694. *
  8695. * @param {String} contents
  8696. * @return {Object}
  8697. */
  8698. function parseAsObject(docblock) {
  8699. var pairs = parse(docblock);
  8700. var result = {};
  8701. for (var i = 0; i < pairs.length; i++) {
  8702. result[pairs[i][0]] = pairs[i][1];
  8703. }
  8704. return result;
  8705. }
  8706. exports.extract = extract;
  8707. exports.parse = parse;
  8708. exports.parseAsObject = parseAsObject;
  8709. }, {}], 19: [function (_dereq_, module, exports) {
  8710. /**
  8711. * Copyright 2013 Facebook, Inc.
  8712. *
  8713. * Licensed under the Apache License, Version 2.0 (the "License");
  8714. * you may not use this file except in compliance with the License.
  8715. * You may obtain a copy of the License at
  8716. *
  8717. * http://www.apache.org/licenses/LICENSE-2.0
  8718. *
  8719. * Unless required by applicable law or agreed to in writing, software
  8720. * distributed under the License is distributed on an "AS IS" BASIS,
  8721. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  8722. * See the License for the specific language governing permissions and
  8723. * limitations under the License.
  8724. */
  8725. /*jslint node: true*/
  8726. "use strict";
  8727. /**
  8728. * Syntax transfomer for javascript. Takes the source in, spits the source
  8729. * out.
  8730. *
  8731. * Parses input source with esprima, applies the given list of visitors to the
  8732. * AST tree, and returns the resulting output.
  8733. */
  8734. var esprima = _dereq_('esprima-fb');
  8735. var utils = _dereq_('./utils');
  8736. var Syntax = esprima.Syntax;
  8737. /**
  8738. * @param {object} node
  8739. * @param {object} parentNode
  8740. * @return {boolean}
  8741. */
  8742. function _nodeIsClosureScopeBoundary(node, parentNode) {
  8743. if (node.type === Syntax.Program) {
  8744. return true;
  8745. }
  8746. var parentIsFunction =
  8747. parentNode.type === Syntax.FunctionDeclaration
  8748. || parentNode.type === Syntax.FunctionExpression;
  8749. return node.type === Syntax.BlockStatement && parentIsFunction;
  8750. }
  8751. function _nodeIsBlockScopeBoundary(node, parentNode) {
  8752. if (node.type === Syntax.Program) {
  8753. return false;
  8754. }
  8755. return node.type === Syntax.BlockStatement
  8756. && parentNode.type === Syntax.CatchClause;
  8757. }
  8758. /**
  8759. * @param {object} node
  8760. * @param {function} visitor
  8761. * @param {array} path
  8762. * @param {object} state
  8763. */
  8764. function traverse(node, path, state) {
  8765. // Create a scope stack entry if this is the first node we've encountered in
  8766. // its local scope
  8767. var parentNode = path[0];
  8768. if (!Array.isArray(node) && state.localScope.parentNode !== parentNode) {
  8769. if (_nodeIsClosureScopeBoundary(node, parentNode)) {
  8770. var scopeIsStrict =
  8771. state.scopeIsStrict
  8772. || node.body.length > 0
  8773. && node.body[0].type === Syntax.ExpressionStatement
  8774. && node.body[0].expression.type === Syntax.Literal
  8775. && node.body[0].expression.value === 'use strict';
  8776. if (node.type === Syntax.Program) {
  8777. state = utils.updateState(state, {
  8778. scopeIsStrict: scopeIsStrict
  8779. });
  8780. } else {
  8781. state = utils.updateState(state, {
  8782. localScope: {
  8783. parentNode: parentNode,
  8784. parentScope: state.localScope,
  8785. identifiers: {}
  8786. },
  8787. scopeIsStrict: scopeIsStrict
  8788. });
  8789. // All functions have an implicit 'arguments' object in scope
  8790. state.localScope.identifiers['arguments'] = true;
  8791. // Include function arg identifiers in the scope boundaries of the
  8792. // function
  8793. if (parentNode.params.length > 0) {
  8794. var param;
  8795. for (var i = 0; i < parentNode.params.length; i++) {
  8796. param = parentNode.params[i];
  8797. if (param.type === Syntax.Identifier) {
  8798. state.localScope.identifiers[param.name] = true;
  8799. }
  8800. }
  8801. }
  8802. // Named FunctionExpressions scope their name within the body block of
  8803. // themselves only
  8804. if (parentNode.type === Syntax.FunctionExpression && parentNode.id) {
  8805. state.localScope.identifiers[parentNode.id.name] = true;
  8806. }
  8807. }
  8808. // Traverse and find all local identifiers in this closure first to
  8809. // account for function/variable declaration hoisting
  8810. collectClosureIdentsAndTraverse(node, path, state);
  8811. }
  8812. if (_nodeIsBlockScopeBoundary(node, parentNode)) {
  8813. state = utils.updateState(state, {
  8814. localScope: {
  8815. parentNode: parentNode,
  8816. parentScope: state.localScope,
  8817. identifiers: {}
  8818. }
  8819. });
  8820. if (parentNode.type === Syntax.CatchClause) {
  8821. state.localScope.identifiers[parentNode.param.name] = true;
  8822. }
  8823. collectBlockIdentsAndTraverse(node, path, state);
  8824. }
  8825. }
  8826. // Only catchup() before and after traversing a child node
  8827. function traverser(node, path, state) {
  8828. node.range && utils.catchup(node.range[0], state);
  8829. traverse(node, path, state);
  8830. node.range && utils.catchup(node.range[1], state);
  8831. }
  8832. utils.analyzeAndTraverse(walker, traverser, node, path, state);
  8833. }
  8834. function collectClosureIdentsAndTraverse(node, path, state) {
  8835. utils.analyzeAndTraverse(
  8836. visitLocalClosureIdentifiers,
  8837. collectClosureIdentsAndTraverse,
  8838. node,
  8839. path,
  8840. state
  8841. );
  8842. }
  8843. function collectBlockIdentsAndTraverse(node, path, state) {
  8844. utils.analyzeAndTraverse(
  8845. visitLocalBlockIdentifiers,
  8846. collectBlockIdentsAndTraverse,
  8847. node,
  8848. path,
  8849. state
  8850. );
  8851. }
  8852. function visitLocalClosureIdentifiers(node, path, state) {
  8853. var identifiers = state.localScope.identifiers;
  8854. switch (node.type) {
  8855. case Syntax.FunctionExpression:
  8856. // Function expressions don't get their names (if there is one) added to
  8857. // the closure scope they're defined in
  8858. return false;
  8859. case Syntax.ClassDeclaration:
  8860. case Syntax.ClassExpression:
  8861. case Syntax.FunctionDeclaration:
  8862. if (node.id) {
  8863. identifiers[node.id.name] = true;
  8864. }
  8865. return false;
  8866. case Syntax.VariableDeclarator:
  8867. if (path[0].kind === 'var') {
  8868. identifiers[node.id.name] = true;
  8869. }
  8870. break;
  8871. }
  8872. }
  8873. function visitLocalBlockIdentifiers(node, path, state) {
  8874. // TODO: Support 'let' here...maybe...one day...or something...
  8875. if (node.type === Syntax.CatchClause) {
  8876. return false;
  8877. }
  8878. }
  8879. function walker(node, path, state) {
  8880. var visitors = state.g.visitors;
  8881. for (var i = 0; i < visitors.length; i++) {
  8882. if (visitors[i].test(node, path, state)) {
  8883. return visitors[i](traverse, node, path, state);
  8884. }
  8885. }
  8886. }
  8887. /**
  8888. * Applies all available transformations to the source
  8889. * @param {array} visitors
  8890. * @param {string} source
  8891. * @param {?object} options
  8892. * @return {object}
  8893. */
  8894. function transform(visitors, source, options) {
  8895. options = options || {};
  8896. var ast;
  8897. try {
  8898. ast = esprima.parse(source, {
  8899. comment: true,
  8900. loc: true,
  8901. range: true
  8902. });
  8903. } catch (e) {
  8904. e.message = 'Parse Error: ' + e.message;
  8905. throw e;
  8906. }
  8907. var state = utils.createState(source, ast, options);
  8908. state.g.visitors = visitors;
  8909. if (options.sourceMap) {
  8910. var SourceMapGenerator = _dereq_('source-map').SourceMapGenerator;
  8911. state.g.sourceMap = new SourceMapGenerator({ file: 'transformed.js' });
  8912. }
  8913. traverse(ast, [], state);
  8914. utils.catchup(source.length, state);
  8915. var ret = { code: state.g.buffer };
  8916. if (options.sourceMap) {
  8917. ret.sourceMap = state.g.sourceMap;
  8918. ret.sourceMapFilename = options.filename || 'source.js';
  8919. }
  8920. return ret;
  8921. }
  8922. exports.transform = transform;
  8923. }, { "./utils": 20, "esprima-fb": 6, "source-map": 8 }], 20: [function (_dereq_, module, exports) {
  8924. /**
  8925. * Copyright 2013 Facebook, Inc.
  8926. *
  8927. * Licensed under the Apache License, Version 2.0 (the "License");
  8928. * you may not use this file except in compliance with the License.
  8929. * You may obtain a copy of the License at
  8930. *
  8931. * http://www.apache.org/licenses/LICENSE-2.0
  8932. *
  8933. * Unless required by applicable law or agreed to in writing, software
  8934. * distributed under the License is distributed on an "AS IS" BASIS,
  8935. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  8936. * See the License for the specific language governing permissions and
  8937. * limitations under the License.
  8938. */
  8939. /*jslint node: true*/
  8940. /**
  8941. * A `state` object represents the state of the parser. It has "local" and
  8942. * "global" parts. Global contains parser position, source, etc. Local contains
  8943. * scope based properties like current class name. State should contain all the
  8944. * info required for transformation. It's the only mandatory object that is
  8945. * being passed to every function in transform chain.
  8946. *
  8947. * @param {string} source
  8948. * @param {object} transformOptions
  8949. * @return {object}
  8950. */
  8951. function createState(source, rootNode, transformOptions) {
  8952. return {
  8953. /**
  8954. * A tree representing the current local scope (and its lexical scope chain)
  8955. * Useful for tracking identifiers from parent scopes, etc.
  8956. * @type {Object}
  8957. */
  8958. localScope: {
  8959. parentNode: rootNode,
  8960. parentScope: null,
  8961. identifiers: {}
  8962. },
  8963. /**
  8964. * The name (and, if applicable, expression) of the super class
  8965. * @type {Object}
  8966. */
  8967. superClass: null,
  8968. /**
  8969. * The namespace to use when munging identifiers
  8970. * @type {String}
  8971. */
  8972. mungeNamespace: '',
  8973. /**
  8974. * Ref to the node for the FunctionExpression of the enclosing
  8975. * MethodDefinition
  8976. * @type {Object}
  8977. */
  8978. methodFuncNode: null,
  8979. /**
  8980. * Name of the enclosing class
  8981. * @type {String}
  8982. */
  8983. className: null,
  8984. /**
  8985. * Whether we're currently within a `strict` scope
  8986. * @type {Bool}
  8987. */
  8988. scopeIsStrict: null,
  8989. /**
  8990. * Global state (not affected by updateState)
  8991. * @type {Object}
  8992. */
  8993. g: {
  8994. /**
  8995. * A set of general options that transformations can consider while doing
  8996. * a transformation:
  8997. *
  8998. * - minify
  8999. * Specifies that transformation steps should do their best to minify
  9000. * the output source when possible. This is useful for places where
  9001. * minification optimizations are possible with higher-level context
  9002. * info than what jsxmin can provide.
  9003. *
  9004. * For example, the ES6 class transform will minify munged private
  9005. * variables if this flag is set.
  9006. */
  9007. opts: transformOptions,
  9008. /**
  9009. * Current position in the source code
  9010. * @type {Number}
  9011. */
  9012. position: 0,
  9013. /**
  9014. * Buffer containing the result
  9015. * @type {String}
  9016. */
  9017. buffer: '',
  9018. /**
  9019. * Indentation offset (only negative offset is supported now)
  9020. * @type {Number}
  9021. */
  9022. indentBy: 0,
  9023. /**
  9024. * Source that is being transformed
  9025. * @type {String}
  9026. */
  9027. source: source,
  9028. /**
  9029. * Cached parsed docblock (see getDocblock)
  9030. * @type {object}
  9031. */
  9032. docblock: null,
  9033. /**
  9034. * Whether the thing was used
  9035. * @type {Boolean}
  9036. */
  9037. tagNamespaceUsed: false,
  9038. /**
  9039. * If using bolt xjs transformation
  9040. * @type {Boolean}
  9041. */
  9042. isBolt: undefined,
  9043. /**
  9044. * Whether to record source map (expensive) or not
  9045. * @type {SourceMapGenerator|null}
  9046. */
  9047. sourceMap: null,
  9048. /**
  9049. * Filename of the file being processed. Will be returned as a source
  9050. * attribute in the source map
  9051. */
  9052. sourceMapFilename: 'source.js',
  9053. /**
  9054. * Only when source map is used: last line in the source for which
  9055. * source map was generated
  9056. * @type {Number}
  9057. */
  9058. sourceLine: 1,
  9059. /**
  9060. * Only when source map is used: last line in the buffer for which
  9061. * source map was generated
  9062. * @type {Number}
  9063. */
  9064. bufferLine: 1,
  9065. /**
  9066. * The top-level Program AST for the original file.
  9067. */
  9068. originalProgramAST: null,
  9069. sourceColumn: 0,
  9070. bufferColumn: 0
  9071. }
  9072. };
  9073. }
  9074. /**
  9075. * Updates a copy of a given state with "update" and returns an updated state.
  9076. *
  9077. * @param {object} state
  9078. * @param {object} update
  9079. * @return {object}
  9080. */
  9081. function updateState(state, update) {
  9082. var ret = Object.create(state);
  9083. Object.keys(update).forEach(function (updatedKey) {
  9084. ret[updatedKey] = update[updatedKey];
  9085. });
  9086. return ret;
  9087. }
  9088. /**
  9089. * Given a state fill the resulting buffer from the original source up to
  9090. * the end
  9091. *
  9092. * @param {number} end
  9093. * @param {object} state
  9094. * @param {?function} contentTransformer Optional callback to transform newly
  9095. * added content.
  9096. */
  9097. function catchup(end, state, contentTransformer) {
  9098. if (end < state.g.position) {
  9099. // cannot move backwards
  9100. return;
  9101. }
  9102. var source = state.g.source.substring(state.g.position, end);
  9103. var transformed = updateIndent(source, state);
  9104. if (state.g.sourceMap && transformed) {
  9105. // record where we are
  9106. state.g.sourceMap.addMapping({
  9107. generated: { line: state.g.bufferLine, column: state.g.bufferColumn },
  9108. original: { line: state.g.sourceLine, column: state.g.sourceColumn },
  9109. source: state.g.sourceMapFilename
  9110. });
  9111. // record line breaks in transformed source
  9112. var sourceLines = source.split('\n');
  9113. var transformedLines = transformed.split('\n');
  9114. // Add line break mappings between last known mapping and the end of the
  9115. // added piece. So for the code piece
  9116. // (foo, bar);
  9117. // > var x = 2;
  9118. // > var b = 3;
  9119. // var c =
  9120. // only add lines marked with ">": 2, 3.
  9121. for (var i = 1; i < sourceLines.length - 1; i++) {
  9122. state.g.sourceMap.addMapping({
  9123. generated: { line: state.g.bufferLine, column: 0 },
  9124. original: { line: state.g.sourceLine, column: 0 },
  9125. source: state.g.sourceMapFilename
  9126. });
  9127. state.g.sourceLine++;
  9128. state.g.bufferLine++;
  9129. }
  9130. // offset for the last piece
  9131. if (sourceLines.length > 1) {
  9132. state.g.sourceLine++;
  9133. state.g.bufferLine++;
  9134. state.g.sourceColumn = 0;
  9135. state.g.bufferColumn = 0;
  9136. }
  9137. state.g.sourceColumn += sourceLines[sourceLines.length - 1].length;
  9138. state.g.bufferColumn +=
  9139. transformedLines[transformedLines.length - 1].length;
  9140. }
  9141. state.g.buffer +=
  9142. contentTransformer ? contentTransformer(transformed) : transformed;
  9143. state.g.position = end;
  9144. }
  9145. /**
  9146. * Removes all non-whitespace characters
  9147. */
  9148. var reNonWhite = /(\S)/g;
  9149. function stripNonWhite(value) {
  9150. return value.replace(reNonWhite, function () {
  9151. return '';
  9152. });
  9153. }
  9154. /**
  9155. * Catches up as `catchup` but removes all non-whitespace characters.
  9156. */
  9157. function catchupWhiteSpace(end, state) {
  9158. catchup(end, state, stripNonWhite);
  9159. }
  9160. /**
  9161. * Removes all non-newline characters
  9162. */
  9163. var reNonNewline = /[^\n]/g;
  9164. function stripNonNewline(value) {
  9165. return value.replace(reNonNewline, function () {
  9166. return '';
  9167. });
  9168. }
  9169. /**
  9170. * Catches up as `catchup` but removes all non-newline characters.
  9171. *
  9172. * Equivalent to appending as many newlines as there are in the original source
  9173. * between the current position and `end`.
  9174. */
  9175. function catchupNewlines(end, state) {
  9176. catchup(end, state, stripNonNewline);
  9177. }
  9178. /**
  9179. * Same as catchup but does not touch the buffer
  9180. *
  9181. * @param {number} end
  9182. * @param {object} state
  9183. */
  9184. function move(end, state) {
  9185. // move the internal cursors
  9186. if (state.g.sourceMap) {
  9187. if (end < state.g.position) {
  9188. state.g.position = 0;
  9189. state.g.sourceLine = 1;
  9190. state.g.sourceColumn = 0;
  9191. }
  9192. var source = state.g.source.substring(state.g.position, end);
  9193. var sourceLines = source.split('\n');
  9194. if (sourceLines.length > 1) {
  9195. state.g.sourceLine += sourceLines.length - 1;
  9196. state.g.sourceColumn = 0;
  9197. }
  9198. state.g.sourceColumn += sourceLines[sourceLines.length - 1].length;
  9199. }
  9200. state.g.position = end;
  9201. }
  9202. /**
  9203. * Appends a string of text to the buffer
  9204. *
  9205. * @param {string} str
  9206. * @param {object} state
  9207. */
  9208. function append(str, state) {
  9209. if (state.g.sourceMap && str) {
  9210. state.g.sourceMap.addMapping({
  9211. generated: { line: state.g.bufferLine, column: state.g.bufferColumn },
  9212. original: { line: state.g.sourceLine, column: state.g.sourceColumn },
  9213. source: state.g.sourceMapFilename
  9214. });
  9215. var transformedLines = str.split('\n');
  9216. if (transformedLines.length > 1) {
  9217. state.g.bufferLine += transformedLines.length - 1;
  9218. state.g.bufferColumn = 0;
  9219. }
  9220. state.g.bufferColumn +=
  9221. transformedLines[transformedLines.length - 1].length;
  9222. }
  9223. state.g.buffer += str;
  9224. }
  9225. /**
  9226. * Update indent using state.indentBy property. Indent is measured in
  9227. * double spaces. Updates a single line only.
  9228. *
  9229. * @param {string} str
  9230. * @param {object} state
  9231. * @return {string}
  9232. */
  9233. function updateIndent(str, state) {
  9234. for (var i = 0; i < -state.g.indentBy; i++) {
  9235. str = str.replace(/(^|\n)( {2}|\t)/g, '$1');
  9236. }
  9237. return str;
  9238. }
  9239. /**
  9240. * Calculates indent from the beginning of the line until "start" or the first
  9241. * character before start.
  9242. * @example
  9243. * " foo.bar()"
  9244. * ^
  9245. * start
  9246. * indent will be 2
  9247. *
  9248. * @param {number} start
  9249. * @param {object} state
  9250. * @return {number}
  9251. */
  9252. function indentBefore(start, state) {
  9253. var end = start;
  9254. start = start - 1;
  9255. while (start > 0 && state.g.source[start] != '\n') {
  9256. if (!state.g.source[start].match(/[ \t]/)) {
  9257. end = start;
  9258. }
  9259. start--;
  9260. }
  9261. return state.g.source.substring(start + 1, end);
  9262. }
  9263. function getDocblock(state) {
  9264. if (!state.g.docblock) {
  9265. var docblock = _dereq_('./docblock');
  9266. state.g.docblock =
  9267. docblock.parseAsObject(docblock.extract(state.g.source));
  9268. }
  9269. return state.g.docblock;
  9270. }
  9271. function identWithinLexicalScope(identName, state, stopBeforeNode) {
  9272. var currScope = state.localScope;
  9273. while (currScope) {
  9274. if (currScope.identifiers[identName] !== undefined) {
  9275. return true;
  9276. }
  9277. if (stopBeforeNode && currScope.parentNode === stopBeforeNode) {
  9278. break;
  9279. }
  9280. currScope = currScope.parentScope;
  9281. }
  9282. return false;
  9283. }
  9284. function identInLocalScope(identName, state) {
  9285. return state.localScope.identifiers[identName] !== undefined;
  9286. }
  9287. function declareIdentInLocalScope(identName, state) {
  9288. state.localScope.identifiers[identName] = true;
  9289. }
  9290. /**
  9291. * Apply the given analyzer function to the current node. If the analyzer
  9292. * doesn't return false, traverse each child of the current node using the given
  9293. * traverser function.
  9294. *
  9295. * @param {function} analyzer
  9296. * @param {function} traverser
  9297. * @param {object} node
  9298. * @param {function} visitor
  9299. * @param {array} path
  9300. * @param {object} state
  9301. */
  9302. function analyzeAndTraverse(analyzer, traverser, node, path, state) {
  9303. var key, child;
  9304. if (node.type) {
  9305. if (analyzer(node, path, state) === false) {
  9306. return;
  9307. }
  9308. path.unshift(node);
  9309. }
  9310. for (key in node) {
  9311. // skip obviously wrong attributes
  9312. if (key === 'range' || key === 'loc') {
  9313. continue;
  9314. }
  9315. if (node.hasOwnProperty(key)) {
  9316. child = node[key];
  9317. if (typeof child === 'object' && child !== null) {
  9318. traverser(child, path, state);
  9319. }
  9320. }
  9321. }
  9322. node.type && path.shift();
  9323. }
  9324. /**
  9325. * Checks whether a node or any of its sub-nodes contains
  9326. * a syntactic construct of the passed type.
  9327. * @param {object} node - AST node to test.
  9328. * @param {string} type - node type to lookup.
  9329. */
  9330. function containsChildOfType(node, type) {
  9331. var foundMatchingChild = false;
  9332. function nodeTypeAnalyzer(node) {
  9333. if (node.type === type) {
  9334. foundMatchingChild = true;
  9335. return false;
  9336. }
  9337. }
  9338. function nodeTypeTraverser(child, path, state) {
  9339. if (!foundMatchingChild) {
  9340. foundMatchingChild = containsChildOfType(child, type);
  9341. }
  9342. }
  9343. analyzeAndTraverse(
  9344. nodeTypeAnalyzer,
  9345. nodeTypeTraverser,
  9346. node,
  9347. []
  9348. );
  9349. return foundMatchingChild;
  9350. }
  9351. exports.append = append;
  9352. exports.catchup = catchup;
  9353. exports.catchupWhiteSpace = catchupWhiteSpace;
  9354. exports.catchupNewlines = catchupNewlines;
  9355. exports.containsChildOfType = containsChildOfType;
  9356. exports.createState = createState;
  9357. exports.declareIdentInLocalScope = declareIdentInLocalScope;
  9358. exports.getDocblock = getDocblock;
  9359. exports.identWithinLexicalScope = identWithinLexicalScope;
  9360. exports.identInLocalScope = identInLocalScope;
  9361. exports.indentBefore = indentBefore;
  9362. exports.move = move;
  9363. exports.updateIndent = updateIndent;
  9364. exports.updateState = updateState;
  9365. exports.analyzeAndTraverse = analyzeAndTraverse;
  9366. }, { "./docblock": 18 }], 21: [function (_dereq_, module, exports) {
  9367. /**
  9368. * Copyright 2013 Facebook, Inc.
  9369. *
  9370. * Licensed under the Apache License, Version 2.0 (the "License");
  9371. * you may not use this file except in compliance with the License.
  9372. * You may obtain a copy of the License at
  9373. *
  9374. * http://www.apache.org/licenses/LICENSE-2.0
  9375. *
  9376. * Unless required by applicable law or agreed to in writing, software
  9377. * distributed under the License is distributed on an "AS IS" BASIS,
  9378. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9379. * See the License for the specific language governing permissions and
  9380. * limitations under the License.
  9381. */
  9382. /*global exports:true*/
  9383. /**
  9384. * Desugars ES6 Arrow functions to ES3 function expressions.
  9385. * If the function contains `this` expression -- automatically
  9386. * binds the funciton to current value of `this`.
  9387. *
  9388. * Single parameter, simple expression:
  9389. *
  9390. * [1, 2, 3].map(x => x * x);
  9391. *
  9392. * [1, 2, 3].map(function(x) { return x * x; });
  9393. *
  9394. * Several parameters, complex block:
  9395. *
  9396. * this.users.forEach((user, idx) => {
  9397. * return this.isActive(idx) && this.send(user);
  9398. * });
  9399. *
  9400. * this.users.forEach(function(user, idx) {
  9401. * return this.isActive(idx) && this.send(user);
  9402. * }.bind(this));
  9403. *
  9404. */
  9405. var restParamVisitors = _dereq_('./es6-rest-param-visitors');
  9406. var Syntax = _dereq_('esprima-fb').Syntax;
  9407. var utils = _dereq_('../src/utils');
  9408. /**
  9409. * @public
  9410. */
  9411. function visitArrowFunction(traverse, node, path, state) {
  9412. // Prologue.
  9413. utils.append('function', state);
  9414. renderParams(node, state);
  9415. // Skip arrow.
  9416. utils.catchupWhiteSpace(node.body.range[0], state);
  9417. var renderBody = node.body.type == Syntax.BlockStatement
  9418. ? renderStatementBody
  9419. : renderExpressionBody;
  9420. path.unshift(node);
  9421. renderBody(traverse, node, path, state);
  9422. path.shift();
  9423. // Bind the function only if `this` value is used
  9424. // inside it or inside any sub-expression.
  9425. if (utils.containsChildOfType(node.body, Syntax.ThisExpression)) {
  9426. utils.append('.bind(this)', state);
  9427. }
  9428. return false;
  9429. }
  9430. function renderParams(node, state) {
  9431. // To preserve inline typechecking directives, we
  9432. // distinguish between parens-free and paranthesized single param.
  9433. if (isParensFreeSingleParam(node, state) || !node.params.length) {
  9434. utils.append('(', state);
  9435. }
  9436. if (node.params.length !== 0) {
  9437. utils.catchup(node.params[node.params.length - 1].range[1], state);
  9438. }
  9439. utils.append(')', state);
  9440. }
  9441. function isParensFreeSingleParam(node, state) {
  9442. return node.params.length === 1 &&
  9443. state.g.source[state.g.position] !== '(';
  9444. }
  9445. function renderExpressionBody(traverse, node, path, state) {
  9446. // Wrap simple expression bodies into a block
  9447. // with explicit return statement.
  9448. utils.append('{', state);
  9449. if (node.rest) {
  9450. utils.append(
  9451. restParamVisitors.renderRestParamSetup(node),
  9452. state
  9453. );
  9454. }
  9455. utils.append('return ', state);
  9456. renderStatementBody(traverse, node, path, state);
  9457. utils.append(';}', state);
  9458. }
  9459. function renderStatementBody(traverse, node, path, state) {
  9460. traverse(node.body, path, state);
  9461. utils.catchup(node.body.range[1], state);
  9462. }
  9463. visitArrowFunction.test = function (node, path, state) {
  9464. return node.type === Syntax.ArrowFunctionExpression;
  9465. };
  9466. exports.visitorList = [
  9467. visitArrowFunction
  9468. ];
  9469. }, { "../src/utils": 20, "./es6-rest-param-visitors": 24, "esprima-fb": 6 }], 22: [function (_dereq_, module, exports) {
  9470. /**
  9471. * Copyright 2013 Facebook, Inc.
  9472. *
  9473. * Licensed under the Apache License, Version 2.0 (the "License");
  9474. * you may not use this file except in compliance with the License.
  9475. * You may obtain a copy of the License at
  9476. *
  9477. * http://www.apache.org/licenses/LICENSE-2.0
  9478. *
  9479. * Unless required by applicable law or agreed to in writing, software
  9480. * distributed under the License is distributed on an "AS IS" BASIS,
  9481. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9482. * See the License for the specific language governing permissions and
  9483. * limitations under the License.
  9484. */
  9485. /*jslint node:true*/
  9486. /**
  9487. * @typechecks
  9488. */
  9489. 'use strict';
  9490. var base62 = _dereq_('base62');
  9491. var Syntax = _dereq_('esprima-fb').Syntax;
  9492. var utils = _dereq_('../src/utils');
  9493. var SUPER_PROTO_IDENT_PREFIX = '____SuperProtoOf';
  9494. var _anonClassUUIDCounter = 0;
  9495. var _mungedSymbolMaps = {};
  9496. /**
  9497. * Used to generate a unique class for use with code-gens for anonymous class
  9498. * expressions.
  9499. *
  9500. * @param {object} state
  9501. * @return {string}
  9502. */
  9503. function _generateAnonymousClassName(state) {
  9504. var mungeNamespace = state.mungeNamespace || '';
  9505. return '____Class' + mungeNamespace + base62.encode(_anonClassUUIDCounter++);
  9506. }
  9507. /**
  9508. * Given an identifier name, munge it using the current state's mungeNamespace.
  9509. *
  9510. * @param {string} identName
  9511. * @param {object} state
  9512. * @return {string}
  9513. */
  9514. function _getMungedName(identName, state) {
  9515. var mungeNamespace = state.mungeNamespace;
  9516. var shouldMinify = state.g.opts.minify;
  9517. if (shouldMinify) {
  9518. if (!_mungedSymbolMaps[mungeNamespace]) {
  9519. _mungedSymbolMaps[mungeNamespace] = {
  9520. symbolMap: {},
  9521. identUUIDCounter: 0
  9522. };
  9523. }
  9524. var symbolMap = _mungedSymbolMaps[mungeNamespace].symbolMap;
  9525. if (!symbolMap[identName]) {
  9526. symbolMap[identName] =
  9527. base62.encode(_mungedSymbolMaps[mungeNamespace].identUUIDCounter++);
  9528. }
  9529. identName = symbolMap[identName];
  9530. }
  9531. return '$' + mungeNamespace + identName;
  9532. }
  9533. /**
  9534. * Extracts super class information from a class node.
  9535. *
  9536. * Information includes name of the super class and/or the expression string
  9537. * (if extending from an expression)
  9538. *
  9539. * @param {object} node
  9540. * @param {object} state
  9541. * @return {object}
  9542. */
  9543. function _getSuperClassInfo(node, state) {
  9544. var ret = {
  9545. name: null,
  9546. expression: null
  9547. };
  9548. if (node.superClass) {
  9549. if (node.superClass.type === Syntax.Identifier) {
  9550. ret.name = node.superClass.name;
  9551. } else {
  9552. // Extension from an expression
  9553. ret.name = _generateAnonymousClassName(state);
  9554. ret.expression = state.g.source.substring(
  9555. node.superClass.range[0],
  9556. node.superClass.range[1]
  9557. );
  9558. }
  9559. }
  9560. return ret;
  9561. }
  9562. /**
  9563. * Used with .filter() to find the constructor method in a list of
  9564. * MethodDefinition nodes.
  9565. *
  9566. * @param {object} classElement
  9567. * @return {boolean}
  9568. */
  9569. function _isConstructorMethod(classElement) {
  9570. return classElement.type === Syntax.MethodDefinition &&
  9571. classElement.key.type === Syntax.Identifier &&
  9572. classElement.key.name === 'constructor';
  9573. }
  9574. /**
  9575. * @param {object} node
  9576. * @param {object} state
  9577. * @return {boolean}
  9578. */
  9579. function _shouldMungeIdentifier(node, state) {
  9580. return (
  9581. !!state.methodFuncNode &&
  9582. !utils.getDocblock(state).hasOwnProperty('preventMunge') &&
  9583. /^_(?!_)/.test(node.name)
  9584. );
  9585. }
  9586. /**
  9587. * @param {function} traverse
  9588. * @param {object} node
  9589. * @param {array} path
  9590. * @param {object} state
  9591. */
  9592. function visitClassMethod(traverse, node, path, state) {
  9593. utils.catchup(node.range[0], state);
  9594. path.unshift(node);
  9595. traverse(node.value, path, state);
  9596. path.shift();
  9597. return false;
  9598. }
  9599. visitClassMethod.test = function (node, path, state) {
  9600. return node.type === Syntax.MethodDefinition;
  9601. };
  9602. /**
  9603. * @param {function} traverse
  9604. * @param {object} node
  9605. * @param {array} path
  9606. * @param {object} state
  9607. */
  9608. function visitClassFunctionExpression(traverse, node, path, state) {
  9609. var methodNode = path[0];
  9610. state = utils.updateState(state, {
  9611. methodFuncNode: node
  9612. });
  9613. if (methodNode.key.name === 'constructor') {
  9614. utils.append('function ' + state.className, state);
  9615. } else {
  9616. var methodName = methodNode.key.name;
  9617. if (_shouldMungeIdentifier(methodNode.key, state)) {
  9618. methodName = _getMungedName(methodName, state);
  9619. }
  9620. var prototypeOrStatic = methodNode["static"] ? '' : 'prototype.';
  9621. utils.append(
  9622. state.className + '.' + prototypeOrStatic + methodName + '=function',
  9623. state
  9624. );
  9625. }
  9626. utils.move(methodNode.key.range[1], state);
  9627. var params = node.params;
  9628. var paramName;
  9629. if (params.length > 0) {
  9630. for (var i = 0; i < params.length; i++) {
  9631. utils.catchup(node.params[i].range[0], state);
  9632. paramName = params[i].name;
  9633. if (_shouldMungeIdentifier(params[i], state)) {
  9634. paramName = _getMungedName(params[i].name, state);
  9635. }
  9636. utils.append(paramName, state);
  9637. utils.move(params[i].range[1], state);
  9638. }
  9639. } else {
  9640. utils.append('(', state);
  9641. }
  9642. utils.append(')', state);
  9643. utils.catchupWhiteSpace(node.body.range[0], state);
  9644. utils.append('{', state);
  9645. if (!state.scopeIsStrict) {
  9646. utils.append('"use strict";', state);
  9647. }
  9648. utils.move(node.body.range[0] + '{'.length, state);
  9649. path.unshift(node);
  9650. traverse(node.body, path, state);
  9651. path.shift();
  9652. utils.catchup(node.body.range[1], state);
  9653. if (methodNode.key.name !== 'constructor') {
  9654. utils.append(';', state);
  9655. }
  9656. return false;
  9657. }
  9658. visitClassFunctionExpression.test = function (node, path, state) {
  9659. return node.type === Syntax.FunctionExpression
  9660. && path[0].type === Syntax.MethodDefinition;
  9661. };
  9662. /**
  9663. * @param {function} traverse
  9664. * @param {object} node
  9665. * @param {array} path
  9666. * @param {object} state
  9667. */
  9668. function _renderClassBody(traverse, node, path, state) {
  9669. var className = state.className;
  9670. var superClass = state.superClass;
  9671. // Set up prototype of constructor on same line as `extends` for line-number
  9672. // preservation. This relies on function-hoisting if a constructor function is
  9673. // defined in the class body.
  9674. if (superClass.name) {
  9675. // If the super class is an expression, we need to memoize the output of the
  9676. // expression into the generated class name variable and use that to refer
  9677. // to the super class going forward. Example:
  9678. //
  9679. // class Foo extends mixin(Bar, Baz) {}
  9680. // --transforms to--
  9681. // function Foo() {} var ____Class0Blah = mixin(Bar, Baz);
  9682. if (superClass.expression !== null) {
  9683. utils.append(
  9684. 'var ' + superClass.name + '=' + superClass.expression + ';',
  9685. state
  9686. );
  9687. }
  9688. var keyName = superClass.name + '____Key';
  9689. var keyNameDeclarator = '';
  9690. if (!utils.identWithinLexicalScope(keyName, state)) {
  9691. keyNameDeclarator = 'var ';
  9692. utils.declareIdentInLocalScope(keyName, state);
  9693. }
  9694. utils.append(
  9695. 'for(' + keyNameDeclarator + keyName + ' in ' + superClass.name + '){' +
  9696. 'if(' + superClass.name + '.hasOwnProperty(' + keyName + ')){' +
  9697. className + '[' + keyName + ']=' +
  9698. superClass.name + '[' + keyName + '];' +
  9699. '}' +
  9700. '}',
  9701. state
  9702. );
  9703. var superProtoIdentStr = SUPER_PROTO_IDENT_PREFIX + superClass.name;
  9704. if (!utils.identWithinLexicalScope(superProtoIdentStr, state)) {
  9705. utils.append(
  9706. 'var ' + superProtoIdentStr + '=' + superClass.name + '===null?' +
  9707. 'null:' + superClass.name + '.prototype;',
  9708. state
  9709. );
  9710. utils.declareIdentInLocalScope(superProtoIdentStr, state);
  9711. }
  9712. utils.append(
  9713. className + '.prototype=Object.create(' + superProtoIdentStr + ');',
  9714. state
  9715. );
  9716. utils.append(
  9717. className + '.prototype.constructor=' + className + ';',
  9718. state
  9719. );
  9720. utils.append(
  9721. className + '.__superConstructor__=' + superClass.name + ';',
  9722. state
  9723. );
  9724. }
  9725. // If there's no constructor method specified in the class body, create an
  9726. // empty constructor function at the top (same line as the class keyword)
  9727. if (!node.body.body.filter(_isConstructorMethod).pop()) {
  9728. utils.append('function ' + className + '(){', state);
  9729. if (!state.scopeIsStrict) {
  9730. utils.append('"use strict";', state);
  9731. }
  9732. if (superClass.name) {
  9733. utils.append(
  9734. 'if(' + superClass.name + '!==null){' +
  9735. superClass.name + '.apply(this,arguments);}',
  9736. state
  9737. );
  9738. }
  9739. utils.append('}', state);
  9740. }
  9741. utils.move(node.body.range[0] + '{'.length, state);
  9742. traverse(node.body, path, state);
  9743. utils.catchupWhiteSpace(node.range[1], state);
  9744. }
  9745. /**
  9746. * @param {function} traverse
  9747. * @param {object} node
  9748. * @param {array} path
  9749. * @param {object} state
  9750. */
  9751. function visitClassDeclaration(traverse, node, path, state) {
  9752. var className = node.id.name;
  9753. var superClass = _getSuperClassInfo(node, state);
  9754. state = utils.updateState(state, {
  9755. mungeNamespace: className,
  9756. className: className,
  9757. superClass: superClass
  9758. });
  9759. _renderClassBody(traverse, node, path, state);
  9760. return false;
  9761. }
  9762. visitClassDeclaration.test = function (node, path, state) {
  9763. return node.type === Syntax.ClassDeclaration;
  9764. };
  9765. /**
  9766. * @param {function} traverse
  9767. * @param {object} node
  9768. * @param {array} path
  9769. * @param {object} state
  9770. */
  9771. function visitClassExpression(traverse, node, path, state) {
  9772. var className = node.id && node.id.name || _generateAnonymousClassName(state);
  9773. var superClass = _getSuperClassInfo(node, state);
  9774. utils.append('(function(){', state);
  9775. state = utils.updateState(state, {
  9776. mungeNamespace: className,
  9777. className: className,
  9778. superClass: superClass
  9779. });
  9780. _renderClassBody(traverse, node, path, state);
  9781. utils.append('return ' + className + ';})()', state);
  9782. return false;
  9783. }
  9784. visitClassExpression.test = function (node, path, state) {
  9785. return node.type === Syntax.ClassExpression;
  9786. };
  9787. /**
  9788. * @param {function} traverse
  9789. * @param {object} node
  9790. * @param {array} path
  9791. * @param {object} state
  9792. */
  9793. function visitPrivateIdentifier(traverse, node, path, state) {
  9794. utils.append(_getMungedName(node.name, state), state);
  9795. utils.move(node.range[1], state);
  9796. }
  9797. visitPrivateIdentifier.test = function (node, path, state) {
  9798. if (node.type === Syntax.Identifier && _shouldMungeIdentifier(node, state)) {
  9799. // Always munge non-computed properties of MemberExpressions
  9800. // (a la preventing access of properties of unowned objects)
  9801. if (path[0].type === Syntax.MemberExpression && path[0].object !== node
  9802. && path[0].computed === false) {
  9803. return true;
  9804. }
  9805. // Always munge identifiers that were declared within the method function
  9806. // scope
  9807. if (utils.identWithinLexicalScope(node.name, state, state.methodFuncNode)) {
  9808. return true;
  9809. }
  9810. // Always munge private keys on object literals defined within a method's
  9811. // scope.
  9812. if (path[0].type === Syntax.Property
  9813. && path[1].type === Syntax.ObjectExpression) {
  9814. return true;
  9815. }
  9816. // Always munge function parameters
  9817. if (path[0].type === Syntax.FunctionExpression
  9818. || path[0].type === Syntax.FunctionDeclaration) {
  9819. for (var i = 0; i < path[0].params.length; i++) {
  9820. if (path[0].params[i] === node) {
  9821. return true;
  9822. }
  9823. }
  9824. }
  9825. }
  9826. return false;
  9827. };
  9828. /**
  9829. * @param {function} traverse
  9830. * @param {object} node
  9831. * @param {array} path
  9832. * @param {object} state
  9833. */
  9834. function visitSuperCallExpression(traverse, node, path, state) {
  9835. var superClassName = state.superClass.name;
  9836. if (node.callee.type === Syntax.Identifier) {
  9837. utils.append(superClassName + '.call(', state);
  9838. utils.move(node.callee.range[1], state);
  9839. } else if (node.callee.type === Syntax.MemberExpression) {
  9840. utils.append(SUPER_PROTO_IDENT_PREFIX + superClassName, state);
  9841. utils.move(node.callee.object.range[1], state);
  9842. if (node.callee.computed) {
  9843. // ["a" + "b"]
  9844. utils.catchup(node.callee.property.range[1] + ']'.length, state);
  9845. } else {
  9846. // .ab
  9847. utils.append('.' + node.callee.property.name, state);
  9848. }
  9849. utils.append('.call(', state);
  9850. utils.move(node.callee.range[1], state);
  9851. }
  9852. utils.append('this', state);
  9853. if (node.arguments.length > 0) {
  9854. utils.append(',', state);
  9855. utils.catchupWhiteSpace(node.arguments[0].range[0], state);
  9856. traverse(node.arguments, path, state);
  9857. }
  9858. utils.catchupWhiteSpace(node.range[1], state);
  9859. utils.append(')', state);
  9860. return false;
  9861. }
  9862. visitSuperCallExpression.test = function (node, path, state) {
  9863. if (state.superClass && node.type === Syntax.CallExpression) {
  9864. var callee = node.callee;
  9865. if (callee.type === Syntax.Identifier && callee.name === 'super'
  9866. || callee.type == Syntax.MemberExpression
  9867. && callee.object.name === 'super') {
  9868. return true;
  9869. }
  9870. }
  9871. return false;
  9872. };
  9873. /**
  9874. * @param {function} traverse
  9875. * @param {object} node
  9876. * @param {array} path
  9877. * @param {object} state
  9878. */
  9879. function visitSuperMemberExpression(traverse, node, path, state) {
  9880. var superClassName = state.superClass.name;
  9881. utils.append(SUPER_PROTO_IDENT_PREFIX + superClassName, state);
  9882. utils.move(node.object.range[1], state);
  9883. }
  9884. visitSuperMemberExpression.test = function (node, path, state) {
  9885. return state.superClass
  9886. && node.type === Syntax.MemberExpression
  9887. && node.object.type === Syntax.Identifier
  9888. && node.object.name === 'super';
  9889. };
  9890. exports.visitorList = [
  9891. visitClassDeclaration,
  9892. visitClassExpression,
  9893. visitClassFunctionExpression,
  9894. visitClassMethod,
  9895. visitPrivateIdentifier,
  9896. visitSuperCallExpression,
  9897. visitSuperMemberExpression
  9898. ];
  9899. }, { "../src/utils": 20, "base62": 7, "esprima-fb": 6 }], 23: [function (_dereq_, module, exports) {
  9900. /**
  9901. * Copyright 2013 Facebook, Inc.
  9902. *
  9903. * Licensed under the Apache License, Version 2.0 (the "License");
  9904. * you may not use this file except in compliance with the License.
  9905. * You may obtain a copy of the License at
  9906. *
  9907. * http://www.apache.org/licenses/LICENSE-2.0
  9908. *
  9909. * Unless required by applicable law or agreed to in writing, software
  9910. * distributed under the License is distributed on an "AS IS" BASIS,
  9911. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9912. * See the License for the specific language governing permissions and
  9913. * limitations under the License.
  9914. */
  9915. /*jslint node: true*/
  9916. /**
  9917. * Desugars ES6 Object Literal short notations into ES3 full notation.
  9918. *
  9919. * // Easier return values.
  9920. * function foo(x, y) {
  9921. * return {x, y}; // {x: x, y: y}
  9922. * };
  9923. *
  9924. * // Destrucruting.
  9925. * function init({port, ip, coords: {x, y}}) { ... }
  9926. *
  9927. */
  9928. var Syntax = _dereq_('esprima-fb').Syntax;
  9929. var utils = _dereq_('../src/utils');
  9930. /**
  9931. * @public
  9932. */
  9933. function visitObjectLiteralShortNotation(traverse, node, path, state) {
  9934. utils.catchup(node.key.range[1], state);
  9935. utils.append(':' + node.key.name, state);
  9936. return false;
  9937. }
  9938. visitObjectLiteralShortNotation.test = function (node, path, state) {
  9939. return node.type === Syntax.Property &&
  9940. node.kind === 'init' &&
  9941. node.shorthand === true;
  9942. };
  9943. exports.visitorList = [
  9944. visitObjectLiteralShortNotation
  9945. ];
  9946. }, { "../src/utils": 20, "esprima-fb": 6 }], 24: [function (_dereq_, module, exports) {
  9947. /**
  9948. * Copyright 2013 Facebook, Inc.
  9949. *
  9950. * Licensed under the Apache License, Version 2.0 (the "License");
  9951. * you may not use this file except in compliance with the License.
  9952. * You may obtain a copy of the License at
  9953. *
  9954. * http://www.apache.org/licenses/LICENSE-2.0
  9955. *
  9956. * Unless required by applicable law or agreed to in writing, software
  9957. * distributed under the License is distributed on an "AS IS" BASIS,
  9958. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9959. * See the License for the specific language governing permissions and
  9960. * limitations under the License.
  9961. */
  9962. /*jslint node:true*/
  9963. /**
  9964. * Desugars ES6 rest parameters into ES3 arguments slicing.
  9965. *
  9966. * function printf(template, ...args) {
  9967. * args.forEach(...);
  9968. * };
  9969. *
  9970. * function printf(template) {
  9971. * var args = [].slice.call(arguments, 1);
  9972. * args.forEach(...);
  9973. * };
  9974. *
  9975. */
  9976. var Syntax = _dereq_('esprima-fb').Syntax;
  9977. var utils = _dereq_('../src/utils');
  9978. function _nodeIsFunctionWithRestParam(node) {
  9979. return (node.type === Syntax.FunctionDeclaration
  9980. || node.type === Syntax.FunctionExpression
  9981. || node.type === Syntax.ArrowFunctionExpression)
  9982. && node.rest;
  9983. }
  9984. function visitFunctionParamsWithRestParam(traverse, node, path, state) {
  9985. // Render params.
  9986. if (node.params.length) {
  9987. utils.catchup(node.params[node.params.length - 1].range[1], state);
  9988. } else {
  9989. // -3 is for ... of the rest.
  9990. utils.catchup(node.rest.range[0] - 3, state);
  9991. }
  9992. utils.catchupWhiteSpace(node.rest.range[1], state);
  9993. }
  9994. visitFunctionParamsWithRestParam.test = function (node, path, state) {
  9995. return _nodeIsFunctionWithRestParam(node);
  9996. };
  9997. function renderRestParamSetup(functionNode) {
  9998. return 'var ' + functionNode.rest.name + '=Array.prototype.slice.call(' +
  9999. 'arguments,' +
  10000. functionNode.params.length +
  10001. ');';
  10002. }
  10003. function visitFunctionBodyWithRestParam(traverse, node, path, state) {
  10004. utils.catchup(node.range[0] + 1, state);
  10005. var parentNode = path[0];
  10006. utils.append(renderRestParamSetup(parentNode), state);
  10007. traverse(node.body, path, state);
  10008. return false;
  10009. }
  10010. visitFunctionBodyWithRestParam.test = function (node, path, state) {
  10011. return node.type === Syntax.BlockStatement
  10012. && _nodeIsFunctionWithRestParam(path[0]);
  10013. };
  10014. exports.renderRestParamSetup = renderRestParamSetup;
  10015. exports.visitorList = [
  10016. visitFunctionParamsWithRestParam,
  10017. visitFunctionBodyWithRestParam
  10018. ];
  10019. }, { "../src/utils": 20, "esprima-fb": 6 }], 25: [function (_dereq_, module, exports) {
  10020. /**
  10021. * Copyright 2013 Facebook, Inc.
  10022. *
  10023. * Licensed under the Apache License, Version 2.0 (the "License");
  10024. * you may not use this file except in compliance with the License.
  10025. * You may obtain a copy of the License at
  10026. *
  10027. * http://www.apache.org/licenses/LICENSE-2.0
  10028. *
  10029. * Unless required by applicable law or agreed to in writing, software
  10030. * distributed under the License is distributed on an "AS IS" BASIS,
  10031. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10032. * See the License for the specific language governing permissions and
  10033. * limitations under the License.
  10034. */
  10035. /*jslint node:true*/
  10036. /**
  10037. * @typechecks
  10038. */
  10039. 'use strict';
  10040. var Syntax = _dereq_('esprima-fb').Syntax;
  10041. var utils = _dereq_('../src/utils');
  10042. /**
  10043. * http://people.mozilla.org/~jorendorff/es6-draft.html#sec-12.1.9
  10044. */
  10045. function visitTemplateLiteral(traverse, node, path, state) {
  10046. var templateElements = node.quasis;
  10047. utils.append('(', state);
  10048. for (var ii = 0; ii < templateElements.length; ii++) {
  10049. var templateElement = templateElements[ii];
  10050. if (templateElement.value.raw !== '') {
  10051. utils.append(getCookedValue(templateElement), state);
  10052. if (!templateElement.tail) {
  10053. // + between element and substitution
  10054. utils.append(' + ', state);
  10055. }
  10056. // maintain line numbers
  10057. utils.move(templateElement.range[0], state);
  10058. utils.catchupNewlines(templateElement.range[1], state);
  10059. }
  10060. utils.move(templateElement.range[1], state);
  10061. if (!templateElement.tail) {
  10062. var substitution = node.expressions[ii];
  10063. if (substitution.type === Syntax.Identifier ||
  10064. substitution.type === Syntax.MemberExpression ||
  10065. substitution.type === Syntax.CallExpression) {
  10066. utils.catchup(substitution.range[1], state);
  10067. } else {
  10068. utils.append('(', state);
  10069. traverse(substitution, path, state);
  10070. utils.catchup(substitution.range[1], state);
  10071. utils.append(')', state);
  10072. }
  10073. // if next templateElement isn't empty...
  10074. if (templateElements[ii + 1].value.cooked !== '') {
  10075. utils.append(' + ', state);
  10076. }
  10077. }
  10078. }
  10079. utils.move(node.range[1], state);
  10080. utils.append(')', state);
  10081. return false;
  10082. }
  10083. visitTemplateLiteral.test = function (node, path, state) {
  10084. return node.type === Syntax.TemplateLiteral;
  10085. };
  10086. /**
  10087. * http://people.mozilla.org/~jorendorff/es6-draft.html#sec-12.2.6
  10088. */
  10089. function visitTaggedTemplateExpression(traverse, node, path, state) {
  10090. var template = node.quasi;
  10091. var numQuasis = template.quasis.length;
  10092. // print the tag
  10093. utils.move(node.tag.range[0], state);
  10094. traverse(node.tag, path, state);
  10095. utils.catchup(node.tag.range[1], state);
  10096. // print array of template elements
  10097. utils.append('(function() { var siteObj = [', state);
  10098. for (var ii = 0; ii < numQuasis; ii++) {
  10099. utils.append(getCookedValue(template.quasis[ii]), state);
  10100. if (ii !== numQuasis - 1) {
  10101. utils.append(', ', state);
  10102. }
  10103. }
  10104. utils.append(']; siteObj.raw = [', state);
  10105. for (ii = 0; ii < numQuasis; ii++) {
  10106. utils.append(getRawValue(template.quasis[ii]), state);
  10107. if (ii !== numQuasis - 1) {
  10108. utils.append(', ', state);
  10109. }
  10110. }
  10111. utils.append(
  10112. ']; Object.freeze(siteObj.raw); Object.freeze(siteObj); return siteObj; }()',
  10113. state
  10114. );
  10115. // print substitutions
  10116. if (numQuasis > 1) {
  10117. for (ii = 0; ii < template.expressions.length; ii++) {
  10118. var expression = template.expressions[ii];
  10119. utils.append(', ', state);
  10120. // maintain line numbers by calling catchupWhiteSpace over the whole
  10121. // previous TemplateElement
  10122. utils.move(template.quasis[ii].range[0], state);
  10123. utils.catchupNewlines(template.quasis[ii].range[1], state);
  10124. utils.move(expression.range[0], state);
  10125. traverse(expression, path, state);
  10126. utils.catchup(expression.range[1], state);
  10127. }
  10128. }
  10129. // print blank lines to push the closing ) down to account for the final
  10130. // TemplateElement.
  10131. utils.catchupNewlines(node.range[1], state);
  10132. utils.append(')', state);
  10133. return false;
  10134. }
  10135. visitTaggedTemplateExpression.test = function (node, path, state) {
  10136. return node.type === Syntax.TaggedTemplateExpression;
  10137. };
  10138. function getCookedValue(templateElement) {
  10139. return JSON.stringify(templateElement.value.cooked);
  10140. }
  10141. function getRawValue(templateElement) {
  10142. return JSON.stringify(templateElement.value.raw);
  10143. }
  10144. exports.visitorList = [
  10145. visitTemplateLiteral,
  10146. visitTaggedTemplateExpression
  10147. ];
  10148. }, { "../src/utils": 20, "esprima-fb": 6 }], 26: [function (_dereq_, module, exports) {
  10149. /**
  10150. * Copyright 2013-2014 Facebook, Inc.
  10151. *
  10152. * Licensed under the Apache License, Version 2.0 (the "License");
  10153. * you may not use this file except in compliance with the License.
  10154. * You may obtain a copy of the License at
  10155. *
  10156. * http://www.apache.org/licenses/LICENSE-2.0
  10157. *
  10158. * Unless required by applicable law or agreed to in writing, software
  10159. * distributed under the License is distributed on an "AS IS" BASIS,
  10160. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10161. * See the License for the specific language governing permissions and
  10162. * limitations under the License.
  10163. */
  10164. /* jshint browser: true */
  10165. /* jslint evil: true */
  10166. 'use strict';
  10167. var runScripts;
  10168. var headEl;
  10169. var buffer = _dereq_('buffer');
  10170. var transform = _dereq_('jstransform').transform;
  10171. var visitors = _dereq_('./fbtransform/visitors').transformVisitors;
  10172. var docblock = _dereq_('jstransform/src/docblock');
  10173. // The source-map library relies on Object.defineProperty, but IE8 doesn't
  10174. // support it fully even with es5-sham. Indeed, es5-sham's defineProperty
  10175. // throws when Object.prototype.__defineGetter__ is missing, so we skip building
  10176. // the source map in that case.
  10177. var supportsAccessors = Object.prototype.hasOwnProperty('__defineGetter__');
  10178. function transformReact(source) {
  10179. return transform(visitors.react, source, {
  10180. sourceMap: supportsAccessors
  10181. });
  10182. }
  10183. exports.transform = transformReact;
  10184. exports.exec = function (code) {
  10185. return eval(transformReact(code).code);
  10186. };
  10187. var inlineScriptCount = 0;
  10188. // This method returns a nicely formated line of code pointing the
  10189. // exactly location of the error `e`.
  10190. // The line is limited in size so big lines of code are also shown
  10191. // in a readable way.
  10192. // Example:
  10193. //
  10194. // ... x', overflow:'scroll'}} id={} onScroll={this.scroll} class=" ...
  10195. // ^
  10196. var createSourceCodeErrorMessage = function (code, e) {
  10197. var sourceLines = code.split('\n');
  10198. var erroneousLine = sourceLines[e.lineNumber - 1];
  10199. // Removes any leading indenting spaces and gets the number of
  10200. // chars indenting the `erroneousLine`
  10201. var indentation = 0;
  10202. erroneousLine = erroneousLine.replace(/^\s+/, function (leadingSpaces) {
  10203. indentation = leadingSpaces.length;
  10204. return '';
  10205. });
  10206. // Defines the number of characters that are going to show
  10207. // before and after the erroneous code
  10208. var LIMIT = 30;
  10209. var errorColumn = e.column - indentation;
  10210. if (errorColumn > LIMIT) {
  10211. erroneousLine = '... ' + erroneousLine.slice(errorColumn - LIMIT);
  10212. errorColumn = 4 + LIMIT;
  10213. }
  10214. if (erroneousLine.length - errorColumn > LIMIT) {
  10215. erroneousLine = erroneousLine.slice(0, errorColumn + LIMIT) + ' ...';
  10216. }
  10217. var message = '\n\n' + erroneousLine + '\n';
  10218. message += new Array(errorColumn - 1).join(' ') + '^';
  10219. return message;
  10220. };
  10221. var transformCode = function (code, source) {
  10222. var jsx = docblock.parseAsObject(docblock.extract(code)).jsx;
  10223. if (jsx) {
  10224. try {
  10225. var transformed = transformReact(code);
  10226. } catch (e) {
  10227. e.message += '\n at ';
  10228. if (source) {
  10229. if ('fileName' in e) {
  10230. // We set `fileName` if it's supported by this error object and
  10231. // a `source` was provided.
  10232. // The error will correctly point to `source` in Firefox.
  10233. e.fileName = source;
  10234. }
  10235. e.message += source + ':' + e.lineNumber + ':' + e.column;
  10236. } else {
  10237. e.message += location.href;
  10238. }
  10239. e.message += createSourceCodeErrorMessage(code, e);
  10240. throw e;
  10241. }
  10242. if (!transformed.sourceMap) {
  10243. return transformed.code;
  10244. }
  10245. var map = transformed.sourceMap.toJSON();
  10246. if (source == null) {
  10247. source = "Inline JSX script";
  10248. inlineScriptCount++;
  10249. if (inlineScriptCount > 1) {
  10250. source += ' (' + inlineScriptCount + ')';
  10251. }
  10252. }
  10253. map.sources = [source];
  10254. map.sourcesContent = [code];
  10255. return (
  10256. transformed.code +
  10257. '//# sourceMappingURL=data:application/json;base64,' +
  10258. buffer.Buffer(JSON.stringify(map)).toString('base64')
  10259. );
  10260. } else {
  10261. return code;
  10262. }
  10263. };
  10264. var run = exports.run = function (code, source) {
  10265. var scriptEl = document.createElement('script');
  10266. scriptEl.text = transformCode(code, source);
  10267. headEl.appendChild(scriptEl);
  10268. };
  10269. var load = exports.load = function (url, callback) {
  10270. var xhr;
  10271. xhr = window.ActiveXObject ? new window.ActiveXObject('Microsoft.XMLHTTP')
  10272. : new XMLHttpRequest();
  10273. // Disable async since we need to execute scripts in the order they are in the
  10274. // DOM to mirror normal script loading.
  10275. xhr.open('GET', url, false);
  10276. if ('overrideMimeType' in xhr) {
  10277. xhr.overrideMimeType('text/plain');
  10278. }
  10279. xhr.onreadystatechange = function () {
  10280. if (xhr.readyState === 4) {
  10281. if (xhr.status === 0 || xhr.status === 200) {
  10282. run(xhr.responseText, url);
  10283. } else {
  10284. throw new Error("Could not load " + url);
  10285. }
  10286. if (callback) {
  10287. return callback();
  10288. }
  10289. }
  10290. };
  10291. return xhr.send(null);
  10292. };
  10293. runScripts = function () {
  10294. var scripts = document.getElementsByTagName('script');
  10295. // Array.prototype.slice cannot be used on NodeList on IE8
  10296. var jsxScripts = [];
  10297. for (var i = 0; i < scripts.length; i++) {
  10298. if (scripts.item(i).type === 'text/jsx') {
  10299. jsxScripts.push(scripts.item(i));
  10300. }
  10301. }
  10302. console.warn("You are using the in-browser JSX transformer. Be sure to precompile your JSX for production - http://facebook.github.io/react/docs/tooling-integration.html#jsx");
  10303. jsxScripts.forEach(function (script) {
  10304. if (script.src) {
  10305. load(script.src);
  10306. } else {
  10307. run(script.innerHTML, null);
  10308. }
  10309. });
  10310. };
  10311. if (typeof window !== "undefined" && window !== null) {
  10312. headEl = document.getElementsByTagName('head')[0];
  10313. if (window.addEventListener) {
  10314. window.addEventListener('DOMContentLoaded', runScripts, false);
  10315. } else {
  10316. window.attachEvent('onload', runScripts);
  10317. }
  10318. }
  10319. }, { "./fbtransform/visitors": 30, "buffer": 1, "jstransform": 19, "jstransform/src/docblock": 18 }], 27: [function (_dereq_, module, exports) {
  10320. /**
  10321. * Copyright 2013-2014 Facebook, Inc.
  10322. *
  10323. * Licensed under the Apache License, Version 2.0 (the "License");
  10324. * you may not use this file except in compliance with the License.
  10325. * You may obtain a copy of the License at
  10326. *
  10327. * http://www.apache.org/licenses/LICENSE-2.0
  10328. *
  10329. * Unless required by applicable law or agreed to in writing, software
  10330. * distributed under the License is distributed on an "AS IS" BASIS,
  10331. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10332. * See the License for the specific language governing permissions and
  10333. * limitations under the License.
  10334. */
  10335. /*global exports:true*/
  10336. "use strict";
  10337. var Syntax = _dereq_('esprima-fb').Syntax;
  10338. var utils = _dereq_('jstransform/src/utils');
  10339. var FALLBACK_TAGS = _dereq_('./xjs').knownTags;
  10340. var renderXJSExpressionContainer =
  10341. _dereq_('./xjs').renderXJSExpressionContainer;
  10342. var renderXJSLiteral = _dereq_('./xjs').renderXJSLiteral;
  10343. var quoteAttrName = _dereq_('./xjs').quoteAttrName;
  10344. /**
  10345. * Customized desugar processor.
  10346. *
  10347. * Currently: (Somewhat tailored to React)
  10348. * <X> </X> => X(null, null)
  10349. * <X prop="1" /> => X({prop: '1'}, null)
  10350. * <X prop="2"><Y /></X> => X({prop:'2'}, Y(null, null))
  10351. * <X prop="2"><Y /><Z /></X> => X({prop:'2'}, [Y(null, null), Z(null, null)])
  10352. *
  10353. * Exceptions to the simple rules above:
  10354. * if a property is named "class" it will be changed to "className" in the
  10355. * javascript since "class" is not a valid object key in javascript.
  10356. */
  10357. var JSX_ATTRIBUTE_TRANSFORMS = {
  10358. cxName: function (attr) {
  10359. throw new Error(
  10360. "cxName is no longer supported, use className={cx(...)} instead"
  10361. );
  10362. }
  10363. };
  10364. function visitReactTag(traverse, object, path, state) {
  10365. var jsxObjIdent = utils.getDocblock(state).jsx;
  10366. var openingElement = object.openingElement;
  10367. var nameObject = openingElement.name;
  10368. var attributesObject = openingElement.attributes;
  10369. utils.catchup(openingElement.range[0], state);
  10370. if (nameObject.namespace) {
  10371. throw new Error(
  10372. 'Namespace tags are not supported. ReactJSX is not XML.');
  10373. }
  10374. var isFallbackTag = FALLBACK_TAGS.hasOwnProperty(nameObject.name);
  10375. utils.append(
  10376. (isFallbackTag ? jsxObjIdent + '.' : '') + (nameObject.name) + '(',
  10377. state
  10378. );
  10379. utils.move(nameObject.range[1], state);
  10380. // if we don't have any attributes, pass in null
  10381. if (attributesObject.length === 0) {
  10382. utils.append('null', state);
  10383. }
  10384. // write attributes
  10385. attributesObject.forEach(function (attr, index) {
  10386. utils.catchup(attr.range[0], state);
  10387. if (attr.name.namespace) {
  10388. throw new Error(
  10389. 'Namespace attributes are not supported. ReactJSX is not XML.');
  10390. }
  10391. var name = attr.name.name;
  10392. var isFirst = index === 0;
  10393. var isLast = index === attributesObject.length - 1;
  10394. if (isFirst) {
  10395. utils.append('{', state);
  10396. }
  10397. utils.append(quoteAttrName(name), state);
  10398. utils.append(':', state);
  10399. if (!attr.value) {
  10400. state.g.buffer += 'true';
  10401. state.g.position = attr.name.range[1];
  10402. if (!isLast) {
  10403. utils.append(',', state);
  10404. }
  10405. } else {
  10406. utils.move(attr.name.range[1], state);
  10407. // Use catchupWhiteSpace to skip over the '=' in the attribute
  10408. utils.catchupWhiteSpace(attr.value.range[0], state);
  10409. if (JSX_ATTRIBUTE_TRANSFORMS.hasOwnProperty(attr.name.name)) {
  10410. utils.append(JSX_ATTRIBUTE_TRANSFORMS[attr.name.name](attr), state);
  10411. utils.move(attr.value.range[1], state);
  10412. if (!isLast) {
  10413. utils.append(',', state);
  10414. }
  10415. } else if (attr.value.type === Syntax.Literal) {
  10416. renderXJSLiteral(attr.value, isLast, state);
  10417. } else {
  10418. renderXJSExpressionContainer(traverse, attr.value, isLast, path, state);
  10419. }
  10420. }
  10421. if (isLast) {
  10422. utils.append('}', state);
  10423. }
  10424. utils.catchup(attr.range[1], state);
  10425. });
  10426. if (!openingElement.selfClosing) {
  10427. utils.catchup(openingElement.range[1] - 1, state);
  10428. utils.move(openingElement.range[1], state);
  10429. }
  10430. // filter out whitespace
  10431. var childrenToRender = object.children.filter(function (child) {
  10432. return !(child.type === Syntax.Literal
  10433. && typeof child.value === 'string'
  10434. && child.value.match(/^[ \t]*[\r\n][ \t\r\n]*$/));
  10435. });
  10436. if (childrenToRender.length > 0) {
  10437. var lastRenderableIndex;
  10438. childrenToRender.forEach(function (child, index) {
  10439. if (child.type !== Syntax.XJSExpressionContainer ||
  10440. child.expression.type !== Syntax.XJSEmptyExpression) {
  10441. lastRenderableIndex = index;
  10442. }
  10443. });
  10444. if (lastRenderableIndex !== undefined) {
  10445. utils.append(', ', state);
  10446. }
  10447. childrenToRender.forEach(function (child, index) {
  10448. utils.catchup(child.range[0], state);
  10449. var isLast = index >= lastRenderableIndex;
  10450. if (child.type === Syntax.Literal) {
  10451. renderXJSLiteral(child, isLast, state);
  10452. } else if (child.type === Syntax.XJSExpressionContainer) {
  10453. renderXJSExpressionContainer(traverse, child, isLast, path, state);
  10454. } else {
  10455. traverse(child, path, state);
  10456. if (!isLast) {
  10457. utils.append(',', state);
  10458. state.g.buffer = state.g.buffer.replace(/(\s*),$/, ',$1');
  10459. }
  10460. }
  10461. utils.catchup(child.range[1], state);
  10462. });
  10463. }
  10464. if (openingElement.selfClosing) {
  10465. // everything up to />
  10466. utils.catchup(openingElement.range[1] - 2, state);
  10467. utils.move(openingElement.range[1], state);
  10468. } else {
  10469. // everything up to </ sdflksjfd>
  10470. utils.catchup(object.closingElement.range[0], state);
  10471. utils.move(object.closingElement.range[1], state);
  10472. }
  10473. utils.append(')', state);
  10474. return false;
  10475. }
  10476. visitReactTag.test = function (object, path, state) {
  10477. // only run react when react @jsx namespace is specified in docblock
  10478. var jsx = utils.getDocblock(state).jsx;
  10479. return object.type === Syntax.XJSElement && jsx && jsx.length;
  10480. };
  10481. exports.visitorList = [
  10482. visitReactTag
  10483. ];
  10484. }, { "./xjs": 29, "esprima-fb": 6, "jstransform/src/utils": 20 }], 28: [function (_dereq_, module, exports) {
  10485. /**
  10486. * Copyright 2013-2014 Facebook, Inc.
  10487. *
  10488. * Licensed under the Apache License, Version 2.0 (the "License");
  10489. * you may not use this file except in compliance with the License.
  10490. * You may obtain a copy of the License at
  10491. *
  10492. * http://www.apache.org/licenses/LICENSE-2.0
  10493. *
  10494. * Unless required by applicable law or agreed to in writing, software
  10495. * distributed under the License is distributed on an "AS IS" BASIS,
  10496. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10497. * See the License for the specific language governing permissions and
  10498. * limitations under the License.
  10499. */
  10500. /*global exports:true*/
  10501. "use strict";
  10502. var Syntax = _dereq_('esprima-fb').Syntax;
  10503. var utils = _dereq_('jstransform/src/utils');
  10504. function addDisplayName(displayName, object, state) {
  10505. if (object &&
  10506. object.type === Syntax.CallExpression &&
  10507. object.callee.type === Syntax.MemberExpression &&
  10508. object.callee.object.type === Syntax.Identifier &&
  10509. object.callee.object.name === 'React' &&
  10510. object.callee.property.type === Syntax.Identifier &&
  10511. object.callee.property.name === 'createClass' &&
  10512. object['arguments'].length === 1 &&
  10513. object['arguments'][0].type === Syntax.ObjectExpression) {
  10514. // Verify that the displayName property isn't already set
  10515. var properties = object['arguments'][0].properties;
  10516. var safe = properties.every(function (property) {
  10517. var value = property.key.type === Syntax.Identifier ?
  10518. property.key.name :
  10519. property.key.value;
  10520. return value !== 'displayName';
  10521. });
  10522. if (safe) {
  10523. utils.catchup(object['arguments'][0].range[0] + 1, state);
  10524. utils.append("displayName: '" + displayName + "',", state);
  10525. }
  10526. }
  10527. }
  10528. /**
  10529. * Transforms the following:
  10530. *
  10531. * var MyComponent = React.createClass({
  10532. * render: ...
  10533. * });
  10534. *
  10535. * into:
  10536. *
  10537. * var MyComponent = React.createClass({
  10538. * displayName: 'MyComponent',
  10539. * render: ...
  10540. * });
  10541. *
  10542. * Also catches:
  10543. *
  10544. * MyComponent = React.createClass(...);
  10545. * exports.MyComponent = React.createClass(...);
  10546. * module.exports = {MyComponent: React.createClass(...)};
  10547. */
  10548. function visitReactDisplayName(traverse, object, path, state) {
  10549. var left, right;
  10550. if (object.type === Syntax.AssignmentExpression) {
  10551. left = object.left;
  10552. right = object.right;
  10553. } else if (object.type === Syntax.Property) {
  10554. left = object.key;
  10555. right = object.value;
  10556. } else if (object.type === Syntax.VariableDeclarator) {
  10557. left = object.id;
  10558. right = object.init;
  10559. }
  10560. if (left && left.type === Syntax.MemberExpression) {
  10561. left = left.property;
  10562. }
  10563. if (left && left.type === Syntax.Identifier) {
  10564. addDisplayName(left.name, right, state);
  10565. }
  10566. }
  10567. /**
  10568. * Will only run on @jsx files for now.
  10569. */
  10570. visitReactDisplayName.test = function (object, path, state) {
  10571. if (utils.getDocblock(state).jsx) {
  10572. return (
  10573. object.type === Syntax.AssignmentExpression ||
  10574. object.type === Syntax.Property ||
  10575. object.type === Syntax.VariableDeclarator
  10576. );
  10577. } else {
  10578. return false;
  10579. }
  10580. };
  10581. exports.visitorList = [
  10582. visitReactDisplayName
  10583. ];
  10584. }, { "esprima-fb": 6, "jstransform/src/utils": 20 }], 29: [function (_dereq_, module, exports) {
  10585. /**
  10586. * Copyright 2013-2014 Facebook, Inc.
  10587. *
  10588. * Licensed under the Apache License, Version 2.0 (the "License");
  10589. * you may not use this file except in compliance with the License.
  10590. * You may obtain a copy of the License at
  10591. *
  10592. * http://www.apache.org/licenses/LICENSE-2.0
  10593. *
  10594. * Unless required by applicable law or agreed to in writing, software
  10595. * distributed under the License is distributed on an "AS IS" BASIS,
  10596. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10597. * See the License for the specific language governing permissions and
  10598. * limitations under the License.
  10599. */
  10600. /*global exports:true*/
  10601. "use strict";
  10602. var Syntax = _dereq_('esprima-fb').Syntax;
  10603. var utils = _dereq_('jstransform/src/utils');
  10604. var knownTags = {
  10605. a: true,
  10606. abbr: true,
  10607. address: true,
  10608. applet: true,
  10609. area: true,
  10610. article: true,
  10611. aside: true,
  10612. audio: true,
  10613. b: true,
  10614. base: true,
  10615. bdi: true,
  10616. bdo: true,
  10617. big: true,
  10618. blockquote: true,
  10619. body: true,
  10620. br: true,
  10621. button: true,
  10622. canvas: true,
  10623. caption: true,
  10624. circle: true,
  10625. cite: true,
  10626. code: true,
  10627. col: true,
  10628. colgroup: true,
  10629. command: true,
  10630. data: true,
  10631. datalist: true,
  10632. dd: true,
  10633. defs: true,
  10634. del: true,
  10635. details: true,
  10636. dfn: true,
  10637. dialog: true,
  10638. div: true,
  10639. dl: true,
  10640. dt: true,
  10641. ellipse: true,
  10642. em: true,
  10643. embed: true,
  10644. fieldset: true,
  10645. figcaption: true,
  10646. figure: true,
  10647. footer: true,
  10648. form: true,
  10649. g: true,
  10650. h1: true,
  10651. h2: true,
  10652. h3: true,
  10653. h4: true,
  10654. h5: true,
  10655. h6: true,
  10656. head: true,
  10657. header: true,
  10658. hgroup: true,
  10659. hr: true,
  10660. html: true,
  10661. i: true,
  10662. iframe: true,
  10663. img: true,
  10664. input: true,
  10665. ins: true,
  10666. kbd: true,
  10667. keygen: true,
  10668. label: true,
  10669. legend: true,
  10670. li: true,
  10671. line: true,
  10672. linearGradient: true,
  10673. link: true,
  10674. main: true,
  10675. map: true,
  10676. mark: true,
  10677. marquee: true,
  10678. menu: true,
  10679. menuitem: true,
  10680. meta: true,
  10681. meter: true,
  10682. nav: true,
  10683. noscript: true,
  10684. object: true,
  10685. ol: true,
  10686. optgroup: true,
  10687. option: true,
  10688. output: true,
  10689. p: true,
  10690. param: true,
  10691. path: true,
  10692. polygon: true,
  10693. polyline: true,
  10694. pre: true,
  10695. progress: true,
  10696. q: true,
  10697. radialGradient: true,
  10698. rect: true,
  10699. rp: true,
  10700. rt: true,
  10701. ruby: true,
  10702. s: true,
  10703. samp: true,
  10704. script: true,
  10705. section: true,
  10706. select: true,
  10707. small: true,
  10708. source: true,
  10709. span: true,
  10710. stop: true,
  10711. strong: true,
  10712. style: true,
  10713. sub: true,
  10714. summary: true,
  10715. sup: true,
  10716. svg: true,
  10717. table: true,
  10718. tbody: true,
  10719. td: true,
  10720. text: true,
  10721. textarea: true,
  10722. tfoot: true,
  10723. th: true,
  10724. thead: true,
  10725. time: true,
  10726. title: true,
  10727. tr: true,
  10728. track: true,
  10729. u: true,
  10730. ul: true,
  10731. 'var': true,
  10732. video: true,
  10733. wbr: true
  10734. };
  10735. function renderXJSLiteral(object, isLast, state, start, end) {
  10736. var lines = object.value.split(/\r\n|\n|\r/);
  10737. if (start) {
  10738. utils.append(start, state);
  10739. }
  10740. var lastNonEmptyLine = 0;
  10741. lines.forEach(function (line, index) {
  10742. if (line.match(/[^ \t]/)) {
  10743. lastNonEmptyLine = index;
  10744. }
  10745. });
  10746. lines.forEach(function (line, index) {
  10747. var isFirstLine = index === 0;
  10748. var isLastLine = index === lines.length - 1;
  10749. var isLastNonEmptyLine = index === lastNonEmptyLine;
  10750. // replace rendered whitespace tabs with spaces
  10751. var trimmedLine = line.replace(/\t/g, ' ');
  10752. // trim whitespace touching a newline
  10753. if (!isFirstLine) {
  10754. trimmedLine = trimmedLine.replace(/^[ ]+/, '');
  10755. }
  10756. if (!isLastLine) {
  10757. trimmedLine = trimmedLine.replace(/[ ]+$/, '');
  10758. }
  10759. utils.append(line.match(/^[ \t]*/)[0], state);
  10760. if (trimmedLine || isLastNonEmptyLine) {
  10761. utils.append(
  10762. JSON.stringify(trimmedLine) +
  10763. (!isLastNonEmptyLine ? "+' '+" : ''),
  10764. state);
  10765. if (isLastNonEmptyLine) {
  10766. if (end) {
  10767. utils.append(end, state);
  10768. }
  10769. if (!isLast) {
  10770. utils.append(',', state);
  10771. }
  10772. }
  10773. // only restore tail whitespace if line had literals
  10774. if (trimmedLine) {
  10775. utils.append(line.match(/[ \t]*$/)[0], state);
  10776. }
  10777. }
  10778. if (!isLastLine) {
  10779. utils.append('\n', state);
  10780. }
  10781. });
  10782. utils.move(object.range[1], state);
  10783. }
  10784. function renderXJSExpressionContainer(traverse, object, isLast, path, state) {
  10785. // Plus 1 to skip `{`.
  10786. utils.move(object.range[0] + 1, state);
  10787. traverse(object.expression, path, state);
  10788. if (!isLast && object.expression.type !== Syntax.XJSEmptyExpression) {
  10789. // If we need to append a comma, make sure to do so after the expression.
  10790. utils.catchup(object.expression.range[1], state);
  10791. utils.append(',', state);
  10792. }
  10793. // Minus 1 to skip `}`.
  10794. utils.catchup(object.range[1] - 1, state);
  10795. utils.move(object.range[1], state);
  10796. return false;
  10797. }
  10798. function quoteAttrName(attr) {
  10799. // Quote invalid JS identifiers.
  10800. if (!/^[a-z_$][a-z\d_$]*$/i.test(attr)) {
  10801. return "'" + attr + "'";
  10802. }
  10803. return attr;
  10804. }
  10805. exports.knownTags = knownTags;
  10806. exports.renderXJSExpressionContainer = renderXJSExpressionContainer;
  10807. exports.renderXJSLiteral = renderXJSLiteral;
  10808. exports.quoteAttrName = quoteAttrName;
  10809. }, { "esprima-fb": 6, "jstransform/src/utils": 20 }], 30: [function (_dereq_, module, exports) {
  10810. /*global exports:true*/
  10811. var es6ArrowFunctions = _dereq_('jstransform/visitors/es6-arrow-function-visitors');
  10812. var es6Classes = _dereq_('jstransform/visitors/es6-class-visitors');
  10813. var es6ObjectShortNotation = _dereq_('jstransform/visitors/es6-object-short-notation-visitors');
  10814. var es6RestParameters = _dereq_('jstransform/visitors/es6-rest-param-visitors');
  10815. var es6Templates = _dereq_('jstransform/visitors/es6-template-visitors');
  10816. var react = _dereq_('./transforms/react');
  10817. var reactDisplayName = _dereq_('./transforms/reactDisplayName');
  10818. /**
  10819. * Map from transformName => orderedListOfVisitors.
  10820. */
  10821. var transformVisitors = {
  10822. 'es6-arrow-functions': es6ArrowFunctions.visitorList,
  10823. 'es6-classes': es6Classes.visitorList,
  10824. 'es6-object-short-notation': es6ObjectShortNotation.visitorList,
  10825. 'es6-rest-params': es6RestParameters.visitorList,
  10826. 'es6-templates': es6Templates.visitorList,
  10827. 'react': react.visitorList.concat(reactDisplayName.visitorList)
  10828. };
  10829. /**
  10830. * Specifies the order in which each transform should run.
  10831. */
  10832. var transformRunOrder = [
  10833. 'es6-arrow-functions',
  10834. 'es6-object-short-notation',
  10835. 'es6-classes',
  10836. 'es6-rest-params',
  10837. 'es6-templates',
  10838. 'react'
  10839. ];
  10840. /**
  10841. * Given a list of transform names, return the ordered list of visitors to be
  10842. * passed to the transform() function.
  10843. *
  10844. * @param {array?} excludes
  10845. * @return {array}
  10846. */
  10847. function getAllVisitors(excludes) {
  10848. var ret = [];
  10849. for (var i = 0, il = transformRunOrder.length; i < il; i++) {
  10850. if (!excludes || excludes.indexOf(transformRunOrder[i]) === -1) {
  10851. ret = ret.concat(transformVisitors[transformRunOrder[i]]);
  10852. }
  10853. }
  10854. return ret;
  10855. }
  10856. exports.getAllVisitors = getAllVisitors;
  10857. exports.transformVisitors = transformVisitors;
  10858. }, { "./transforms/react": 27, "./transforms/reactDisplayName": 28, "jstransform/visitors/es6-arrow-function-visitors": 21, "jstransform/visitors/es6-class-visitors": 22, "jstransform/visitors/es6-object-short-notation-visitors": 23, "jstransform/visitors/es6-rest-param-visitors": 24, "jstransform/visitors/es6-template-visitors": 25 }]
  10859. }, {}, [26])
  10860. (26)
  10861. });