blanket.js 200 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765
  1. /*! blanket - v1.2.1 */
  2. if (typeof QUnit !== 'undefined'){ QUnit.config.autostart = false; }
  3. (function(define){
  4. (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.acorn = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){
  5. // The main exported interface (under `self.acorn` when in the
  6. // browser) is a `parse` function that takes a code string and
  7. // returns an abstract syntax tree as specified by [Mozilla parser
  8. // API][api].
  9. //
  10. // [api]: https://developer.mozilla.org/en-US/docs/SpiderMonkey/Parser_API
  11. "use strict";
  12. exports.parse = parse;
  13. // This function tries to parse a single expression at a given
  14. // offset in a string. Useful for parsing mixed-language formats
  15. // that embed JavaScript expressions.
  16. exports.parseExpressionAt = parseExpressionAt;
  17. // Acorn is organized as a tokenizer and a recursive-descent parser.
  18. // The `tokenize` export provides an interface to the tokenizer.
  19. exports.tokenizer = tokenizer;
  20. exports.__esModule = true;
  21. // Acorn is a tiny, fast JavaScript parser written in JavaScript.
  22. //
  23. // Acorn was written by Marijn Haverbeke, Ingvar Stepanyan, and
  24. // various contributors and released under an MIT license.
  25. //
  26. // Git repositories for Acorn are available at
  27. //
  28. // http://marijnhaverbeke.nl/git/acorn
  29. // https://github.com/marijnh/acorn.git
  30. //
  31. // Please use the [github bug tracker][ghbt] to report issues.
  32. //
  33. // [ghbt]: https://github.com/marijnh/acorn/issues
  34. //
  35. // This file defines the main parser interface. The library also comes
  36. // with a [error-tolerant parser][dammit] and an
  37. // [abstract syntax tree walker][walk], defined in other files.
  38. //
  39. // [dammit]: acorn_loose.js
  40. // [walk]: util/walk.js
  41. var _state = _dereq_("./state");
  42. var Parser = _state.Parser;
  43. var _options = _dereq_("./options");
  44. var getOptions = _options.getOptions;
  45. _dereq_("./parseutil");
  46. _dereq_("./statement");
  47. _dereq_("./lval");
  48. _dereq_("./expression");
  49. exports.Parser = _state.Parser;
  50. exports.plugins = _state.plugins;
  51. exports.defaultOptions = _options.defaultOptions;
  52. var _location = _dereq_("./location");
  53. exports.SourceLocation = _location.SourceLocation;
  54. exports.getLineInfo = _location.getLineInfo;
  55. exports.Node = _dereq_("./node").Node;
  56. var _tokentype = _dereq_("./tokentype");
  57. exports.TokenType = _tokentype.TokenType;
  58. exports.tokTypes = _tokentype.types;
  59. var _tokencontext = _dereq_("./tokencontext");
  60. exports.TokContext = _tokencontext.TokContext;
  61. exports.tokContexts = _tokencontext.types;
  62. var _identifier = _dereq_("./identifier");
  63. exports.isIdentifierChar = _identifier.isIdentifierChar;
  64. exports.isIdentifierStart = _identifier.isIdentifierStart;
  65. exports.Token = _dereq_("./tokenize").Token;
  66. var _whitespace = _dereq_("./whitespace");
  67. exports.isNewLine = _whitespace.isNewLine;
  68. exports.lineBreak = _whitespace.lineBreak;
  69. exports.lineBreakG = _whitespace.lineBreakG;
  70. var version = "1.2.2";exports.version = version;
  71. function parse(input, options) {
  72. var p = parser(options, input);
  73. var startPos = p.pos,
  74. startLoc = p.options.locations && p.curPosition();
  75. p.nextToken();
  76. return p.parseTopLevel(p.options.program || p.startNodeAt(startPos, startLoc));
  77. }
  78. function parseExpressionAt(input, pos, options) {
  79. var p = parser(options, input, pos);
  80. p.nextToken();
  81. return p.parseExpression();
  82. }
  83. function tokenizer(input, options) {
  84. return parser(options, input);
  85. }
  86. function parser(options, input) {
  87. return new Parser(getOptions(options), String(input));
  88. }
  89. },{"./expression":6,"./identifier":7,"./location":8,"./lval":9,"./node":10,"./options":11,"./parseutil":12,"./state":13,"./statement":14,"./tokencontext":15,"./tokenize":16,"./tokentype":17,"./whitespace":19}],2:[function(_dereq_,module,exports){
  90. if (typeof Object.create === 'function') {
  91. // implementation from standard node.js 'util' module
  92. module.exports = function inherits(ctor, superCtor) {
  93. ctor.super_ = superCtor
  94. ctor.prototype = Object.create(superCtor.prototype, {
  95. constructor: {
  96. value: ctor,
  97. enumerable: false,
  98. writable: true,
  99. configurable: true
  100. }
  101. });
  102. };
  103. } else {
  104. // old school shim for old browsers
  105. module.exports = function inherits(ctor, superCtor) {
  106. ctor.super_ = superCtor
  107. var TempCtor = function () {}
  108. TempCtor.prototype = superCtor.prototype
  109. ctor.prototype = new TempCtor()
  110. ctor.prototype.constructor = ctor
  111. }
  112. }
  113. },{}],3:[function(_dereq_,module,exports){
  114. // shim for using process in browser
  115. var process = module.exports = {};
  116. var queue = [];
  117. var draining = false;
  118. function drainQueue() {
  119. if (draining) {
  120. return;
  121. }
  122. draining = true;
  123. var currentQueue;
  124. var len = queue.length;
  125. while(len) {
  126. currentQueue = queue;
  127. queue = [];
  128. var i = -1;
  129. while (++i < len) {
  130. currentQueue[i]();
  131. }
  132. len = queue.length;
  133. }
  134. draining = false;
  135. }
  136. process.nextTick = function (fun) {
  137. queue.push(fun);
  138. if (!draining) {
  139. setTimeout(drainQueue, 0);
  140. }
  141. };
  142. process.title = 'browser';
  143. process.browser = true;
  144. process.env = {};
  145. process.argv = [];
  146. process.version = ''; // empty string to avoid regexp issues
  147. process.versions = {};
  148. function noop() {}
  149. process.on = noop;
  150. process.addListener = noop;
  151. process.once = noop;
  152. process.off = noop;
  153. process.removeListener = noop;
  154. process.removeAllListeners = noop;
  155. process.emit = noop;
  156. process.binding = function (name) {
  157. throw new Error('process.binding is not supported');
  158. };
  159. // TODO(shtylman)
  160. process.cwd = function () { return '/' };
  161. process.chdir = function (dir) {
  162. throw new Error('process.chdir is not supported');
  163. };
  164. process.umask = function() { return 0; };
  165. },{}],4:[function(_dereq_,module,exports){
  166. module.exports = function isBuffer(arg) {
  167. return arg && typeof arg === 'object'
  168. && typeof arg.copy === 'function'
  169. && typeof arg.fill === 'function'
  170. && typeof arg.readUInt8 === 'function';
  171. }
  172. },{}],5:[function(_dereq_,module,exports){
  173. (function (process,global){
  174. // Copyright Joyent, Inc. and other Node contributors.
  175. //
  176. // Permission is hereby granted, free of charge, to any person obtaining a
  177. // copy of this software and associated documentation files (the
  178. // "Software"), to deal in the Software without restriction, including
  179. // without limitation the rights to use, copy, modify, merge, publish,
  180. // distribute, sublicense, and/or sell copies of the Software, and to permit
  181. // persons to whom the Software is furnished to do so, subject to the
  182. // following conditions:
  183. //
  184. // The above copyright notice and this permission notice shall be included
  185. // in all copies or substantial portions of the Software.
  186. //
  187. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  188. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  189. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  190. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  191. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  192. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  193. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  194. var formatRegExp = /%[sdj%]/g;
  195. exports.format = function(f) {
  196. if (!isString(f)) {
  197. var objects = [];
  198. for (var i = 0; i < arguments.length; i++) {
  199. objects.push(inspect(arguments[i]));
  200. }
  201. return objects.join(' ');
  202. }
  203. var i = 1;
  204. var args = arguments;
  205. var len = args.length;
  206. var str = String(f).replace(formatRegExp, function(x) {
  207. if (x === '%%') return '%';
  208. if (i >= len) return x;
  209. switch (x) {
  210. case '%s': return String(args[i++]);
  211. case '%d': return Number(args[i++]);
  212. case '%j':
  213. try {
  214. return JSON.stringify(args[i++]);
  215. } catch (_) {
  216. return '[Circular]';
  217. }
  218. default:
  219. return x;
  220. }
  221. });
  222. for (var x = args[i]; i < len; x = args[++i]) {
  223. if (isNull(x) || !isObject(x)) {
  224. str += ' ' + x;
  225. } else {
  226. str += ' ' + inspect(x);
  227. }
  228. }
  229. return str;
  230. };
  231. // Mark that a method should not be used.
  232. // Returns a modified function which warns once by default.
  233. // If --no-deprecation is set, then it is a no-op.
  234. exports.deprecate = function(fn, msg) {
  235. // Allow for deprecating things in the process of starting up.
  236. if (isUndefined(global.process)) {
  237. return function() {
  238. return exports.deprecate(fn, msg).apply(this, arguments);
  239. };
  240. }
  241. if (process.noDeprecation === true) {
  242. return fn;
  243. }
  244. var warned = false;
  245. function deprecated() {
  246. if (!warned) {
  247. if (process.throwDeprecation) {
  248. throw new Error(msg);
  249. } else if (process.traceDeprecation) {
  250. console.trace(msg);
  251. } else {
  252. console.error(msg);
  253. }
  254. warned = true;
  255. }
  256. return fn.apply(this, arguments);
  257. }
  258. return deprecated;
  259. };
  260. var debugs = {};
  261. var debugEnviron;
  262. exports.debuglog = function(set) {
  263. if (isUndefined(debugEnviron))
  264. debugEnviron = process.env.NODE_DEBUG || '';
  265. set = set.toUpperCase();
  266. if (!debugs[set]) {
  267. if (new RegExp('\\b' + set + '\\b', 'i').test(debugEnviron)) {
  268. var pid = process.pid;
  269. debugs[set] = function() {
  270. var msg = exports.format.apply(exports, arguments);
  271. console.error('%s %d: %s', set, pid, msg);
  272. };
  273. } else {
  274. debugs[set] = function() {};
  275. }
  276. }
  277. return debugs[set];
  278. };
  279. /**
  280. * Echos the value of a value. Trys to print the value out
  281. * in the best way possible given the different types.
  282. *
  283. * @param {Object} obj The object to print out.
  284. * @param {Object} opts Optional options object that alters the output.
  285. */
  286. /* legacy: obj, showHidden, depth, colors*/
  287. function inspect(obj, opts) {
  288. // default options
  289. var ctx = {
  290. seen: [],
  291. stylize: stylizeNoColor
  292. };
  293. // legacy...
  294. if (arguments.length >= 3) ctx.depth = arguments[2];
  295. if (arguments.length >= 4) ctx.colors = arguments[3];
  296. if (isBoolean(opts)) {
  297. // legacy...
  298. ctx.showHidden = opts;
  299. } else if (opts) {
  300. // got an "options" object
  301. exports._extend(ctx, opts);
  302. }
  303. // set default options
  304. if (isUndefined(ctx.showHidden)) ctx.showHidden = false;
  305. if (isUndefined(ctx.depth)) ctx.depth = 2;
  306. if (isUndefined(ctx.colors)) ctx.colors = false;
  307. if (isUndefined(ctx.customInspect)) ctx.customInspect = true;
  308. if (ctx.colors) ctx.stylize = stylizeWithColor;
  309. return formatValue(ctx, obj, ctx.depth);
  310. }
  311. exports.inspect = inspect;
  312. // http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
  313. inspect.colors = {
  314. 'bold' : [1, 22],
  315. 'italic' : [3, 23],
  316. 'underline' : [4, 24],
  317. 'inverse' : [7, 27],
  318. 'white' : [37, 39],
  319. 'grey' : [90, 39],
  320. 'black' : [30, 39],
  321. 'blue' : [34, 39],
  322. 'cyan' : [36, 39],
  323. 'green' : [32, 39],
  324. 'magenta' : [35, 39],
  325. 'red' : [31, 39],
  326. 'yellow' : [33, 39]
  327. };
  328. // Don't use 'blue' not visible on cmd.exe
  329. inspect.styles = {
  330. 'special': 'cyan',
  331. 'number': 'yellow',
  332. 'boolean': 'yellow',
  333. 'undefined': 'grey',
  334. 'null': 'bold',
  335. 'string': 'green',
  336. 'date': 'magenta',
  337. // "name": intentionally not styling
  338. 'regexp': 'red'
  339. };
  340. function stylizeWithColor(str, styleType) {
  341. var style = inspect.styles[styleType];
  342. if (style) {
  343. return '\u001b[' + inspect.colors[style][0] + 'm' + str +
  344. '\u001b[' + inspect.colors[style][1] + 'm';
  345. } else {
  346. return str;
  347. }
  348. }
  349. function stylizeNoColor(str, styleType) {
  350. return str;
  351. }
  352. function arrayToHash(array) {
  353. var hash = {};
  354. array.forEach(function(val, idx) {
  355. hash[val] = true;
  356. });
  357. return hash;
  358. }
  359. function formatValue(ctx, value, recurseTimes) {
  360. // Provide a hook for user-specified inspect functions.
  361. // Check that value is an object with an inspect function on it
  362. if (ctx.customInspect &&
  363. value &&
  364. isFunction(value.inspect) &&
  365. // Filter out the util module, it's inspect function is special
  366. value.inspect !== exports.inspect &&
  367. // Also filter out any prototype objects using the circular check.
  368. !(value.constructor && value.constructor.prototype === value)) {
  369. var ret = value.inspect(recurseTimes, ctx);
  370. if (!isString(ret)) {
  371. ret = formatValue(ctx, ret, recurseTimes);
  372. }
  373. return ret;
  374. }
  375. // Primitive types cannot have properties
  376. var primitive = formatPrimitive(ctx, value);
  377. if (primitive) {
  378. return primitive;
  379. }
  380. // Look up the keys of the object.
  381. var keys = Object.keys(value);
  382. var visibleKeys = arrayToHash(keys);
  383. if (ctx.showHidden) {
  384. keys = Object.getOwnPropertyNames(value);
  385. }
  386. // IE doesn't make error fields non-enumerable
  387. // http://msdn.microsoft.com/en-us/library/ie/dww52sbt(v=vs.94).aspx
  388. if (isError(value)
  389. && (keys.indexOf('message') >= 0 || keys.indexOf('description') >= 0)) {
  390. return formatError(value);
  391. }
  392. // Some type of object without properties can be shortcutted.
  393. if (keys.length === 0) {
  394. if (isFunction(value)) {
  395. var name = value.name ? ': ' + value.name : '';
  396. return ctx.stylize('[Function' + name + ']', 'special');
  397. }
  398. if (isRegExp(value)) {
  399. return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
  400. }
  401. if (isDate(value)) {
  402. return ctx.stylize(Date.prototype.toString.call(value), 'date');
  403. }
  404. if (isError(value)) {
  405. return formatError(value);
  406. }
  407. }
  408. var base = '', array = false, braces = ['{', '}'];
  409. // Make Array say that they are Array
  410. if (isArray(value)) {
  411. array = true;
  412. braces = ['[', ']'];
  413. }
  414. // Make functions say that they are functions
  415. if (isFunction(value)) {
  416. var n = value.name ? ': ' + value.name : '';
  417. base = ' [Function' + n + ']';
  418. }
  419. // Make RegExps say that they are RegExps
  420. if (isRegExp(value)) {
  421. base = ' ' + RegExp.prototype.toString.call(value);
  422. }
  423. // Make dates with properties first say the date
  424. if (isDate(value)) {
  425. base = ' ' + Date.prototype.toUTCString.call(value);
  426. }
  427. // Make error with message first say the error
  428. if (isError(value)) {
  429. base = ' ' + formatError(value);
  430. }
  431. if (keys.length === 0 && (!array || value.length == 0)) {
  432. return braces[0] + base + braces[1];
  433. }
  434. if (recurseTimes < 0) {
  435. if (isRegExp(value)) {
  436. return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
  437. } else {
  438. return ctx.stylize('[Object]', 'special');
  439. }
  440. }
  441. ctx.seen.push(value);
  442. var output;
  443. if (array) {
  444. output = formatArray(ctx, value, recurseTimes, visibleKeys, keys);
  445. } else {
  446. output = keys.map(function(key) {
  447. return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array);
  448. });
  449. }
  450. ctx.seen.pop();
  451. return reduceToSingleString(output, base, braces);
  452. }
  453. function formatPrimitive(ctx, value) {
  454. if (isUndefined(value))
  455. return ctx.stylize('undefined', 'undefined');
  456. if (isString(value)) {
  457. var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '')
  458. .replace(/'/g, "\\'")
  459. .replace(/\\"/g, '"') + '\'';
  460. return ctx.stylize(simple, 'string');
  461. }
  462. if (isNumber(value))
  463. return ctx.stylize('' + value, 'number');
  464. if (isBoolean(value))
  465. return ctx.stylize('' + value, 'boolean');
  466. // For some reason typeof null is "object", so special case here.
  467. if (isNull(value))
  468. return ctx.stylize('null', 'null');
  469. }
  470. function formatError(value) {
  471. return '[' + Error.prototype.toString.call(value) + ']';
  472. }
  473. function formatArray(ctx, value, recurseTimes, visibleKeys, keys) {
  474. var output = [];
  475. for (var i = 0, l = value.length; i < l; ++i) {
  476. if (hasOwnProperty(value, String(i))) {
  477. output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
  478. String(i), true));
  479. } else {
  480. output.push('');
  481. }
  482. }
  483. keys.forEach(function(key) {
  484. if (!key.match(/^\d+$/)) {
  485. output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
  486. key, true));
  487. }
  488. });
  489. return output;
  490. }
  491. function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {
  492. var name, str, desc;
  493. desc = Object.getOwnPropertyDescriptor(value, key) || { value: value[key] };
  494. if (desc.get) {
  495. if (desc.set) {
  496. str = ctx.stylize('[Getter/Setter]', 'special');
  497. } else {
  498. str = ctx.stylize('[Getter]', 'special');
  499. }
  500. } else {
  501. if (desc.set) {
  502. str = ctx.stylize('[Setter]', 'special');
  503. }
  504. }
  505. if (!hasOwnProperty(visibleKeys, key)) {
  506. name = '[' + key + ']';
  507. }
  508. if (!str) {
  509. if (ctx.seen.indexOf(desc.value) < 0) {
  510. if (isNull(recurseTimes)) {
  511. str = formatValue(ctx, desc.value, null);
  512. } else {
  513. str = formatValue(ctx, desc.value, recurseTimes - 1);
  514. }
  515. if (str.indexOf('\n') > -1) {
  516. if (array) {
  517. str = str.split('\n').map(function(line) {
  518. return ' ' + line;
  519. }).join('\n').substr(2);
  520. } else {
  521. str = '\n' + str.split('\n').map(function(line) {
  522. return ' ' + line;
  523. }).join('\n');
  524. }
  525. }
  526. } else {
  527. str = ctx.stylize('[Circular]', 'special');
  528. }
  529. }
  530. if (isUndefined(name)) {
  531. if (array && key.match(/^\d+$/)) {
  532. return str;
  533. }
  534. name = JSON.stringify('' + key);
  535. if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
  536. name = name.substr(1, name.length - 2);
  537. name = ctx.stylize(name, 'name');
  538. } else {
  539. name = name.replace(/'/g, "\\'")
  540. .replace(/\\"/g, '"')
  541. .replace(/(^"|"$)/g, "'");
  542. name = ctx.stylize(name, 'string');
  543. }
  544. }
  545. return name + ': ' + str;
  546. }
  547. function reduceToSingleString(output, base, braces) {
  548. var numLinesEst = 0;
  549. var length = output.reduce(function(prev, cur) {
  550. numLinesEst++;
  551. if (cur.indexOf('\n') >= 0) numLinesEst++;
  552. return prev + cur.replace(/\u001b\[\d\d?m/g, '').length + 1;
  553. }, 0);
  554. if (length > 60) {
  555. return braces[0] +
  556. (base === '' ? '' : base + '\n ') +
  557. ' ' +
  558. output.join(',\n ') +
  559. ' ' +
  560. braces[1];
  561. }
  562. return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
  563. }
  564. // NOTE: These type checking functions intentionally don't use `instanceof`
  565. // because it is fragile and can be easily faked with `Object.create()`.
  566. function isArray(ar) {
  567. return Array.isArray(ar);
  568. }
  569. exports.isArray = isArray;
  570. function isBoolean(arg) {
  571. return typeof arg === 'boolean';
  572. }
  573. exports.isBoolean = isBoolean;
  574. function isNull(arg) {
  575. return arg === null;
  576. }
  577. exports.isNull = isNull;
  578. function isNullOrUndefined(arg) {
  579. return arg == null;
  580. }
  581. exports.isNullOrUndefined = isNullOrUndefined;
  582. function isNumber(arg) {
  583. return typeof arg === 'number';
  584. }
  585. exports.isNumber = isNumber;
  586. function isString(arg) {
  587. return typeof arg === 'string';
  588. }
  589. exports.isString = isString;
  590. function isSymbol(arg) {
  591. return typeof arg === 'symbol';
  592. }
  593. exports.isSymbol = isSymbol;
  594. function isUndefined(arg) {
  595. return arg === void 0;
  596. }
  597. exports.isUndefined = isUndefined;
  598. function isRegExp(re) {
  599. return isObject(re) && objectToString(re) === '[object RegExp]';
  600. }
  601. exports.isRegExp = isRegExp;
  602. function isObject(arg) {
  603. return typeof arg === 'object' && arg !== null;
  604. }
  605. exports.isObject = isObject;
  606. function isDate(d) {
  607. return isObject(d) && objectToString(d) === '[object Date]';
  608. }
  609. exports.isDate = isDate;
  610. function isError(e) {
  611. return isObject(e) &&
  612. (objectToString(e) === '[object Error]' || e instanceof Error);
  613. }
  614. exports.isError = isError;
  615. function isFunction(arg) {
  616. return typeof arg === 'function';
  617. }
  618. exports.isFunction = isFunction;
  619. function isPrimitive(arg) {
  620. return arg === null ||
  621. typeof arg === 'boolean' ||
  622. typeof arg === 'number' ||
  623. typeof arg === 'string' ||
  624. typeof arg === 'symbol' || // ES6 symbol
  625. typeof arg === 'undefined';
  626. }
  627. exports.isPrimitive = isPrimitive;
  628. exports.isBuffer = _dereq_('./support/isBuffer');
  629. function objectToString(o) {
  630. return Object.prototype.toString.call(o);
  631. }
  632. function pad(n) {
  633. return n < 10 ? '0' + n.toString(10) : n.toString(10);
  634. }
  635. var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep',
  636. 'Oct', 'Nov', 'Dec'];
  637. // 26 Feb 16:19:34
  638. function timestamp() {
  639. var d = new Date();
  640. var time = [pad(d.getHours()),
  641. pad(d.getMinutes()),
  642. pad(d.getSeconds())].join(':');
  643. return [d.getDate(), months[d.getMonth()], time].join(' ');
  644. }
  645. // log is just a thin wrapper to console.log that prepends a timestamp
  646. exports.log = function() {
  647. console.log('%s - %s', timestamp(), exports.format.apply(exports, arguments));
  648. };
  649. /**
  650. * Inherit the prototype methods from one constructor into another.
  651. *
  652. * The Function.prototype.inherits from lang.js rewritten as a standalone
  653. * function (not on Function.prototype). NOTE: If this file is to be loaded
  654. * during bootstrapping this function needs to be rewritten using some native
  655. * functions as prototype setup using normal JavaScript does not work as
  656. * expected during bootstrapping (see mirror.js in r114903).
  657. *
  658. * @param {function} ctor Constructor function which needs to inherit the
  659. * prototype.
  660. * @param {function} superCtor Constructor function to inherit prototype from.
  661. */
  662. exports.inherits = _dereq_('inherits');
  663. exports._extend = function(origin, add) {
  664. // Don't do anything if add isn't an object
  665. if (!add || !isObject(add)) return origin;
  666. var keys = Object.keys(add);
  667. var i = keys.length;
  668. while (i--) {
  669. origin[keys[i]] = add[keys[i]];
  670. }
  671. return origin;
  672. };
  673. function hasOwnProperty(obj, prop) {
  674. return Object.prototype.hasOwnProperty.call(obj, prop);
  675. }
  676. }).call(this,_dereq_('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  677. },{"./support/isBuffer":4,"_process":3,"inherits":2}],6:[function(_dereq_,module,exports){
  678. // A recursive descent parser operates by defining functions for all
  679. // syntactic elements, and recursively calling those, each function
  680. // advancing the input stream and returning an AST node. Precedence
  681. // of constructs (for example, the fact that `!x[1]` means `!(x[1])`
  682. // instead of `(!x)[1]` is handled by the fact that the parser
  683. // function that parses unary prefix operators is called first, and
  684. // in turn calls the function that parses `[]` subscripts — that
  685. // way, it'll receive the node for `x[1]` already parsed, and wraps
  686. // *that* in the unary operator node.
  687. //
  688. // Acorn uses an [operator precedence parser][opp] to handle binary
  689. // operator precedence, because it is much more compact than using
  690. // the technique outlined above, which uses different, nesting
  691. // functions to specify precedence, for all of the ten binary
  692. // precedence levels that JavaScript defines.
  693. //
  694. // [opp]: http://en.wikipedia.org/wiki/Operator-precedence_parser
  695. "use strict";
  696. var tt = _dereq_("./tokentype").types;
  697. var Parser = _dereq_("./state").Parser;
  698. var reservedWords = _dereq_("./identifier").reservedWords;
  699. var has = _dereq_("./util").has;
  700. var pp = Parser.prototype;
  701. // Check if property name clashes with already added.
  702. // Object/class getters and setters are not allowed to clash —
  703. // either with each other or with an init property — and in
  704. // strict mode, init properties are also not allowed to be repeated.
  705. pp.checkPropClash = function (prop, propHash) {
  706. if (this.options.ecmaVersion >= 6) return;
  707. var key = prop.key,
  708. name = undefined;
  709. switch (key.type) {
  710. case "Identifier":
  711. name = key.name;break;
  712. case "Literal":
  713. name = String(key.value);break;
  714. default:
  715. return;
  716. }
  717. var kind = prop.kind || "init",
  718. other = undefined;
  719. if (has(propHash, name)) {
  720. other = propHash[name];
  721. var isGetSet = kind !== "init";
  722. if ((this.strict || isGetSet) && other[kind] || !(isGetSet ^ other.init)) this.raise(key.start, "Redefinition of property");
  723. } else {
  724. other = propHash[name] = {
  725. init: false,
  726. get: false,
  727. set: false
  728. };
  729. }
  730. other[kind] = true;
  731. };
  732. // ### Expression parsing
  733. // These nest, from the most general expression type at the top to
  734. // 'atomic', nondivisible expression types at the bottom. Most of
  735. // the functions will simply let the function(s) below them parse,
  736. // and, *if* the syntactic construct they handle is present, wrap
  737. // the AST node that the inner parser gave them in another node.
  738. // Parse a full expression. The optional arguments are used to
  739. // forbid the `in` operator (in for loops initalization expressions)
  740. // and provide reference for storing '=' operator inside shorthand
  741. // property assignment in contexts where both object expression
  742. // and object pattern might appear (so it's possible to raise
  743. // delayed syntax error at correct position).
  744. pp.parseExpression = function (noIn, refShorthandDefaultPos) {
  745. var startPos = this.start,
  746. startLoc = this.startLoc;
  747. var expr = this.parseMaybeAssign(noIn, refShorthandDefaultPos);
  748. if (this.type === tt.comma) {
  749. var node = this.startNodeAt(startPos, startLoc);
  750. node.expressions = [expr];
  751. while (this.eat(tt.comma)) node.expressions.push(this.parseMaybeAssign(noIn, refShorthandDefaultPos));
  752. return this.finishNode(node, "SequenceExpression");
  753. }
  754. return expr;
  755. };
  756. // Parse an assignment expression. This includes applications of
  757. // operators like `+=`.
  758. pp.parseMaybeAssign = function (noIn, refShorthandDefaultPos, afterLeftParse) {
  759. if (this.type == tt._yield && this.inGenerator) return this.parseYield();
  760. var failOnShorthandAssign = undefined;
  761. if (!refShorthandDefaultPos) {
  762. refShorthandDefaultPos = { start: 0 };
  763. failOnShorthandAssign = true;
  764. } else {
  765. failOnShorthandAssign = false;
  766. }
  767. var startPos = this.start,
  768. startLoc = this.startLoc;
  769. if (this.type == tt.parenL || this.type == tt.name) this.potentialArrowAt = this.start;
  770. var left = this.parseMaybeConditional(noIn, refShorthandDefaultPos);
  771. if (afterLeftParse) left = afterLeftParse.call(this, left, startPos, startLoc);
  772. if (this.type.isAssign) {
  773. var node = this.startNodeAt(startPos, startLoc);
  774. node.operator = this.value;
  775. node.left = this.type === tt.eq ? this.toAssignable(left) : left;
  776. refShorthandDefaultPos.start = 0; // reset because shorthand default was used correctly
  777. this.checkLVal(left);
  778. this.next();
  779. node.right = this.parseMaybeAssign(noIn);
  780. return this.finishNode(node, "AssignmentExpression");
  781. } else if (failOnShorthandAssign && refShorthandDefaultPos.start) {
  782. this.unexpected(refShorthandDefaultPos.start);
  783. }
  784. return left;
  785. };
  786. // Parse a ternary conditional (`?:`) operator.
  787. pp.parseMaybeConditional = function (noIn, refShorthandDefaultPos) {
  788. var startPos = this.start,
  789. startLoc = this.startLoc;
  790. var expr = this.parseExprOps(noIn, refShorthandDefaultPos);
  791. if (refShorthandDefaultPos && refShorthandDefaultPos.start) return expr;
  792. if (this.eat(tt.question)) {
  793. var node = this.startNodeAt(startPos, startLoc);
  794. node.test = expr;
  795. node.consequent = this.parseMaybeAssign();
  796. this.expect(tt.colon);
  797. node.alternate = this.parseMaybeAssign(noIn);
  798. return this.finishNode(node, "ConditionalExpression");
  799. }
  800. return expr;
  801. };
  802. // Start the precedence parser.
  803. pp.parseExprOps = function (noIn, refShorthandDefaultPos) {
  804. var startPos = this.start,
  805. startLoc = this.startLoc;
  806. var expr = this.parseMaybeUnary(refShorthandDefaultPos);
  807. if (refShorthandDefaultPos && refShorthandDefaultPos.start) return expr;
  808. return this.parseExprOp(expr, startPos, startLoc, -1, noIn);
  809. };
  810. // Parse binary operators with the operator precedence parsing
  811. // algorithm. `left` is the left-hand side of the operator.
  812. // `minPrec` provides context that allows the function to stop and
  813. // defer further parser to one of its callers when it encounters an
  814. // operator that has a lower precedence than the set it is parsing.
  815. pp.parseExprOp = function (left, leftStartPos, leftStartLoc, minPrec, noIn) {
  816. var prec = this.type.binop;
  817. if (Array.isArray(leftStartPos)) {
  818. if (this.options.locations && noIn === undefined) {
  819. // shift arguments to left by one
  820. noIn = minPrec;
  821. minPrec = leftStartLoc;
  822. // flatten leftStartPos
  823. leftStartLoc = leftStartPos[1];
  824. leftStartPos = leftStartPos[0];
  825. }
  826. }
  827. if (prec != null && (!noIn || this.type !== tt._in)) {
  828. if (prec > minPrec) {
  829. var node = this.startNodeAt(leftStartPos, leftStartLoc);
  830. node.left = left;
  831. node.operator = this.value;
  832. var op = this.type;
  833. this.next();
  834. var startPos = this.start,
  835. startLoc = this.startLoc;
  836. node.right = this.parseExprOp(this.parseMaybeUnary(), startPos, startLoc, prec, noIn);
  837. this.finishNode(node, op === tt.logicalOR || op === tt.logicalAND ? "LogicalExpression" : "BinaryExpression");
  838. return this.parseExprOp(node, leftStartPos, leftStartLoc, minPrec, noIn);
  839. }
  840. }
  841. return left;
  842. };
  843. // Parse unary operators, both prefix and postfix.
  844. pp.parseMaybeUnary = function (refShorthandDefaultPos) {
  845. if (this.type.prefix) {
  846. var node = this.startNode(),
  847. update = this.type === tt.incDec;
  848. node.operator = this.value;
  849. node.prefix = true;
  850. this.next();
  851. node.argument = this.parseMaybeUnary();
  852. if (refShorthandDefaultPos && refShorthandDefaultPos.start) this.unexpected(refShorthandDefaultPos.start);
  853. if (update) this.checkLVal(node.argument);else if (this.strict && node.operator === "delete" && node.argument.type === "Identifier") this.raise(node.start, "Deleting local variable in strict mode");
  854. return this.finishNode(node, update ? "UpdateExpression" : "UnaryExpression");
  855. }
  856. var startPos = this.start,
  857. startLoc = this.startLoc;
  858. var expr = this.parseExprSubscripts(refShorthandDefaultPos);
  859. if (refShorthandDefaultPos && refShorthandDefaultPos.start) return expr;
  860. while (this.type.postfix && !this.canInsertSemicolon()) {
  861. var node = this.startNodeAt(startPos, startLoc);
  862. node.operator = this.value;
  863. node.prefix = false;
  864. node.argument = expr;
  865. this.checkLVal(expr);
  866. this.next();
  867. expr = this.finishNode(node, "UpdateExpression");
  868. }
  869. return expr;
  870. };
  871. // Parse call, dot, and `[]`-subscript expressions.
  872. pp.parseExprSubscripts = function (refShorthandDefaultPos) {
  873. var startPos = this.start,
  874. startLoc = this.startLoc;
  875. var expr = this.parseExprAtom(refShorthandDefaultPos);
  876. if (refShorthandDefaultPos && refShorthandDefaultPos.start) return expr;
  877. return this.parseSubscripts(expr, startPos, startLoc);
  878. };
  879. pp.parseSubscripts = function (base, startPos, startLoc, noCalls) {
  880. if (Array.isArray(startPos)) {
  881. if (this.options.locations && noCalls === undefined) {
  882. // shift arguments to left by one
  883. noCalls = startLoc;
  884. // flatten startPos
  885. startLoc = startPos[1];
  886. startPos = startPos[0];
  887. }
  888. }
  889. for (;;) {
  890. if (this.eat(tt.dot)) {
  891. var node = this.startNodeAt(startPos, startLoc);
  892. node.object = base;
  893. node.property = this.parseIdent(true);
  894. node.computed = false;
  895. base = this.finishNode(node, "MemberExpression");
  896. } else if (this.eat(tt.bracketL)) {
  897. var node = this.startNodeAt(startPos, startLoc);
  898. node.object = base;
  899. node.property = this.parseExpression();
  900. node.computed = true;
  901. this.expect(tt.bracketR);
  902. base = this.finishNode(node, "MemberExpression");
  903. } else if (!noCalls && this.eat(tt.parenL)) {
  904. var node = this.startNodeAt(startPos, startLoc);
  905. node.callee = base;
  906. node.arguments = this.parseExprList(tt.parenR, false);
  907. base = this.finishNode(node, "CallExpression");
  908. } else if (this.type === tt.backQuote) {
  909. var node = this.startNodeAt(startPos, startLoc);
  910. node.tag = base;
  911. node.quasi = this.parseTemplate();
  912. base = this.finishNode(node, "TaggedTemplateExpression");
  913. } else {
  914. return base;
  915. }
  916. }
  917. };
  918. // Parse an atomic expression — either a single token that is an
  919. // expression, an expression started by a keyword like `function` or
  920. // `new`, or an expression wrapped in punctuation like `()`, `[]`,
  921. // or `{}`.
  922. pp.parseExprAtom = function (refShorthandDefaultPos) {
  923. var node = undefined,
  924. canBeArrow = this.potentialArrowAt == this.start;
  925. switch (this.type) {
  926. case tt._this:
  927. case tt._super:
  928. var type = this.type === tt._this ? "ThisExpression" : "Super";
  929. node = this.startNode();
  930. this.next();
  931. return this.finishNode(node, type);
  932. case tt._yield:
  933. if (this.inGenerator) this.unexpected();
  934. case tt.name:
  935. var startPos = this.start,
  936. startLoc = this.startLoc;
  937. var id = this.parseIdent(this.type !== tt.name);
  938. if (canBeArrow && !this.canInsertSemicolon() && this.eat(tt.arrow)) return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), [id]);
  939. return id;
  940. case tt.regexp:
  941. var value = this.value;
  942. node = this.parseLiteral(value.value);
  943. node.regex = { pattern: value.pattern, flags: value.flags };
  944. return node;
  945. case tt.num:case tt.string:
  946. return this.parseLiteral(this.value);
  947. case tt._null:case tt._true:case tt._false:
  948. node = this.startNode();
  949. node.value = this.type === tt._null ? null : this.type === tt._true;
  950. node.raw = this.type.keyword;
  951. this.next();
  952. return this.finishNode(node, "Literal");
  953. case tt.parenL:
  954. return this.parseParenAndDistinguishExpression(canBeArrow);
  955. case tt.bracketL:
  956. node = this.startNode();
  957. this.next();
  958. // check whether this is array comprehension or regular array
  959. if (this.options.ecmaVersion >= 7 && this.type === tt._for) {
  960. return this.parseComprehension(node, false);
  961. }
  962. node.elements = this.parseExprList(tt.bracketR, true, true, refShorthandDefaultPos);
  963. return this.finishNode(node, "ArrayExpression");
  964. case tt.braceL:
  965. return this.parseObj(false, refShorthandDefaultPos);
  966. case tt._function:
  967. node = this.startNode();
  968. this.next();
  969. return this.parseFunction(node, false);
  970. case tt._class:
  971. return this.parseClass(this.startNode(), false);
  972. case tt._new:
  973. return this.parseNew();
  974. case tt.backQuote:
  975. return this.parseTemplate();
  976. default:
  977. this.unexpected();
  978. }
  979. };
  980. pp.parseLiteral = function (value) {
  981. var node = this.startNode();
  982. node.value = value;
  983. node.raw = this.input.slice(this.start, this.end);
  984. this.next();
  985. return this.finishNode(node, "Literal");
  986. };
  987. pp.parseParenExpression = function () {
  988. this.expect(tt.parenL);
  989. var val = this.parseExpression();
  990. this.expect(tt.parenR);
  991. return val;
  992. };
  993. pp.parseParenAndDistinguishExpression = function (canBeArrow) {
  994. var startPos = this.start,
  995. startLoc = this.startLoc,
  996. val = undefined;
  997. if (this.options.ecmaVersion >= 6) {
  998. this.next();
  999. if (this.options.ecmaVersion >= 7 && this.type === tt._for) {
  1000. return this.parseComprehension(this.startNodeAt(startPos, startLoc), true);
  1001. }
  1002. var innerStartPos = this.start,
  1003. innerStartLoc = this.startLoc;
  1004. var exprList = [],
  1005. first = true;
  1006. var refShorthandDefaultPos = { start: 0 },
  1007. spreadStart = undefined,
  1008. innerParenStart = undefined;
  1009. while (this.type !== tt.parenR) {
  1010. first ? first = false : this.expect(tt.comma);
  1011. if (this.type === tt.ellipsis) {
  1012. spreadStart = this.start;
  1013. exprList.push(this.parseParenItem(this.parseRest()));
  1014. break;
  1015. } else {
  1016. if (this.type === tt.parenL && !innerParenStart) {
  1017. innerParenStart = this.start;
  1018. }
  1019. exprList.push(this.parseMaybeAssign(false, refShorthandDefaultPos, this.parseParenItem));
  1020. }
  1021. }
  1022. var innerEndPos = this.start,
  1023. innerEndLoc = this.startLoc;
  1024. this.expect(tt.parenR);
  1025. if (canBeArrow && !this.canInsertSemicolon() && this.eat(tt.arrow)) {
  1026. if (innerParenStart) this.unexpected(innerParenStart);
  1027. return this.parseParenArrowList(startPos, startLoc, exprList);
  1028. }
  1029. if (!exprList.length) this.unexpected(this.lastTokStart);
  1030. if (spreadStart) this.unexpected(spreadStart);
  1031. if (refShorthandDefaultPos.start) this.unexpected(refShorthandDefaultPos.start);
  1032. if (exprList.length > 1) {
  1033. val = this.startNodeAt(innerStartPos, innerStartLoc);
  1034. val.expressions = exprList;
  1035. this.finishNodeAt(val, "SequenceExpression", innerEndPos, innerEndLoc);
  1036. } else {
  1037. val = exprList[0];
  1038. }
  1039. } else {
  1040. val = this.parseParenExpression();
  1041. }
  1042. if (this.options.preserveParens) {
  1043. var par = this.startNodeAt(startPos, startLoc);
  1044. par.expression = val;
  1045. return this.finishNode(par, "ParenthesizedExpression");
  1046. } else {
  1047. return val;
  1048. }
  1049. };
  1050. pp.parseParenItem = function (item) {
  1051. return item;
  1052. };
  1053. pp.parseParenArrowList = function (startPos, startLoc, exprList) {
  1054. return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), exprList);
  1055. };
  1056. // New's precedence is slightly tricky. It must allow its argument
  1057. // to be a `[]` or dot subscript expression, but not a call — at
  1058. // least, not without wrapping it in parentheses. Thus, it uses the
  1059. var empty = [];
  1060. pp.parseNew = function () {
  1061. var node = this.startNode();
  1062. var meta = this.parseIdent(true);
  1063. if (this.options.ecmaVersion >= 6 && this.eat(tt.dot)) {
  1064. node.meta = meta;
  1065. node.property = this.parseIdent(true);
  1066. if (node.property.name !== "target") this.raise(node.property.start, "The only valid meta property for new is new.target");
  1067. return this.finishNode(node, "MetaProperty");
  1068. }
  1069. var startPos = this.start,
  1070. startLoc = this.startLoc;
  1071. node.callee = this.parseSubscripts(this.parseExprAtom(), startPos, startLoc, true);
  1072. if (this.eat(tt.parenL)) node.arguments = this.parseExprList(tt.parenR, false);else node.arguments = empty;
  1073. return this.finishNode(node, "NewExpression");
  1074. };
  1075. // Parse template expression.
  1076. pp.parseTemplateElement = function () {
  1077. var elem = this.startNode();
  1078. elem.value = {
  1079. raw: this.input.slice(this.start, this.end),
  1080. cooked: this.value
  1081. };
  1082. this.next();
  1083. elem.tail = this.type === tt.backQuote;
  1084. return this.finishNode(elem, "TemplateElement");
  1085. };
  1086. pp.parseTemplate = function () {
  1087. var node = this.startNode();
  1088. this.next();
  1089. node.expressions = [];
  1090. var curElt = this.parseTemplateElement();
  1091. node.quasis = [curElt];
  1092. while (!curElt.tail) {
  1093. this.expect(tt.dollarBraceL);
  1094. node.expressions.push(this.parseExpression());
  1095. this.expect(tt.braceR);
  1096. node.quasis.push(curElt = this.parseTemplateElement());
  1097. }
  1098. this.next();
  1099. return this.finishNode(node, "TemplateLiteral");
  1100. };
  1101. // Parse an object literal or binding pattern.
  1102. pp.parseObj = function (isPattern, refShorthandDefaultPos) {
  1103. var node = this.startNode(),
  1104. first = true,
  1105. propHash = {};
  1106. node.properties = [];
  1107. this.next();
  1108. while (!this.eat(tt.braceR)) {
  1109. if (!first) {
  1110. this.expect(tt.comma);
  1111. if (this.afterTrailingComma(tt.braceR)) break;
  1112. } else first = false;
  1113. var prop = this.startNode(),
  1114. isGenerator = undefined,
  1115. startPos = undefined,
  1116. startLoc = undefined;
  1117. if (this.options.ecmaVersion >= 6) {
  1118. prop.method = false;
  1119. prop.shorthand = false;
  1120. if (isPattern || refShorthandDefaultPos) {
  1121. startPos = this.start;
  1122. startLoc = this.startLoc;
  1123. }
  1124. if (!isPattern) isGenerator = this.eat(tt.star);
  1125. }
  1126. this.parsePropertyName(prop);
  1127. this.parsePropertyValue(prop, isPattern, isGenerator, startPos, startLoc, refShorthandDefaultPos);
  1128. this.checkPropClash(prop, propHash);
  1129. node.properties.push(this.finishNode(prop, "Property"));
  1130. }
  1131. return this.finishNode(node, isPattern ? "ObjectPattern" : "ObjectExpression");
  1132. };
  1133. pp.parsePropertyValue = function (prop, isPattern, isGenerator, startPos, startLoc, refShorthandDefaultPos) {
  1134. if (this.eat(tt.colon)) {
  1135. prop.value = isPattern ? this.parseMaybeDefault(this.start, this.startLoc) : this.parseMaybeAssign(false, refShorthandDefaultPos);
  1136. prop.kind = "init";
  1137. } else if (this.options.ecmaVersion >= 6 && this.type === tt.parenL) {
  1138. if (isPattern) this.unexpected();
  1139. prop.kind = "init";
  1140. prop.method = true;
  1141. prop.value = this.parseMethod(isGenerator);
  1142. } else if (this.options.ecmaVersion >= 5 && !prop.computed && prop.key.type === "Identifier" && (prop.key.name === "get" || prop.key.name === "set") && (this.type != tt.comma && this.type != tt.braceR)) {
  1143. if (isGenerator || isPattern) this.unexpected();
  1144. prop.kind = prop.key.name;
  1145. this.parsePropertyName(prop);
  1146. prop.value = this.parseMethod(false);
  1147. } else if (this.options.ecmaVersion >= 6 && !prop.computed && prop.key.type === "Identifier") {
  1148. prop.kind = "init";
  1149. if (isPattern) {
  1150. if (this.isKeyword(prop.key.name) || this.strict && (reservedWords.strictBind(prop.key.name) || reservedWords.strict(prop.key.name)) || !this.options.allowReserved && this.isReservedWord(prop.key.name)) this.raise(prop.key.start, "Binding " + prop.key.name);
  1151. prop.value = this.parseMaybeDefault(startPos, startLoc, prop.key);
  1152. } else if (this.type === tt.eq && refShorthandDefaultPos) {
  1153. if (!refShorthandDefaultPos.start) refShorthandDefaultPos.start = this.start;
  1154. prop.value = this.parseMaybeDefault(startPos, startLoc, prop.key);
  1155. } else {
  1156. prop.value = prop.key;
  1157. }
  1158. prop.shorthand = true;
  1159. } else this.unexpected();
  1160. };
  1161. pp.parsePropertyName = function (prop) {
  1162. if (this.options.ecmaVersion >= 6) {
  1163. if (this.eat(tt.bracketL)) {
  1164. prop.computed = true;
  1165. prop.key = this.parseMaybeAssign();
  1166. this.expect(tt.bracketR);
  1167. return prop.key;
  1168. } else {
  1169. prop.computed = false;
  1170. }
  1171. }
  1172. return prop.key = this.type === tt.num || this.type === tt.string ? this.parseExprAtom() : this.parseIdent(true);
  1173. };
  1174. // Initialize empty function node.
  1175. pp.initFunction = function (node) {
  1176. node.id = null;
  1177. if (this.options.ecmaVersion >= 6) {
  1178. node.generator = false;
  1179. node.expression = false;
  1180. }
  1181. };
  1182. // Parse object or class method.
  1183. pp.parseMethod = function (isGenerator) {
  1184. var node = this.startNode();
  1185. this.initFunction(node);
  1186. this.expect(tt.parenL);
  1187. node.params = this.parseBindingList(tt.parenR, false, false);
  1188. var allowExpressionBody = undefined;
  1189. if (this.options.ecmaVersion >= 6) {
  1190. node.generator = isGenerator;
  1191. allowExpressionBody = true;
  1192. } else {
  1193. allowExpressionBody = false;
  1194. }
  1195. this.parseFunctionBody(node, allowExpressionBody);
  1196. return this.finishNode(node, "FunctionExpression");
  1197. };
  1198. // Parse arrow function expression with given parameters.
  1199. pp.parseArrowExpression = function (node, params) {
  1200. this.initFunction(node);
  1201. node.params = this.toAssignableList(params, true);
  1202. this.parseFunctionBody(node, true);
  1203. return this.finishNode(node, "ArrowFunctionExpression");
  1204. };
  1205. // Parse function body and check parameters.
  1206. pp.parseFunctionBody = function (node, allowExpression) {
  1207. var isExpression = allowExpression && this.type !== tt.braceL;
  1208. if (isExpression) {
  1209. node.body = this.parseMaybeAssign();
  1210. node.expression = true;
  1211. } else {
  1212. // Start a new scope with regard to labels and the `inFunction`
  1213. // flag (restore them to their old value afterwards).
  1214. var oldInFunc = this.inFunction,
  1215. oldInGen = this.inGenerator,
  1216. oldLabels = this.labels;
  1217. this.inFunction = true;this.inGenerator = node.generator;this.labels = [];
  1218. node.body = this.parseBlock(true);
  1219. node.expression = false;
  1220. this.inFunction = oldInFunc;this.inGenerator = oldInGen;this.labels = oldLabels;
  1221. }
  1222. // If this is a strict mode function, verify that argument names
  1223. // are not repeated, and it does not try to bind the words `eval`
  1224. // or `arguments`.
  1225. if (this.strict || !isExpression && node.body.body.length && this.isUseStrict(node.body.body[0])) {
  1226. var nameHash = {},
  1227. oldStrict = this.strict;
  1228. this.strict = true;
  1229. if (node.id) this.checkLVal(node.id, true);
  1230. for (var i = 0; i < node.params.length; i++) {
  1231. this.checkLVal(node.params[i], true, nameHash);
  1232. }this.strict = oldStrict;
  1233. }
  1234. };
  1235. // Parses a comma-separated list of expressions, and returns them as
  1236. // an array. `close` is the token type that ends the list, and
  1237. // `allowEmpty` can be turned on to allow subsequent commas with
  1238. // nothing in between them to be parsed as `null` (which is needed
  1239. // for array literals).
  1240. pp.parseExprList = function (close, allowTrailingComma, allowEmpty, refShorthandDefaultPos) {
  1241. var elts = [],
  1242. first = true;
  1243. while (!this.eat(close)) {
  1244. if (!first) {
  1245. this.expect(tt.comma);
  1246. if (allowTrailingComma && this.afterTrailingComma(close)) break;
  1247. } else first = false;
  1248. if (allowEmpty && this.type === tt.comma) {
  1249. elts.push(null);
  1250. } else {
  1251. if (this.type === tt.ellipsis) elts.push(this.parseSpread(refShorthandDefaultPos));else elts.push(this.parseMaybeAssign(false, refShorthandDefaultPos));
  1252. }
  1253. }
  1254. return elts;
  1255. };
  1256. // Parse the next token as an identifier. If `liberal` is true (used
  1257. // when parsing properties), it will also convert keywords into
  1258. // identifiers.
  1259. pp.parseIdent = function (liberal) {
  1260. var node = this.startNode();
  1261. if (liberal && this.options.allowReserved == "never") liberal = false;
  1262. if (this.type === tt.name) {
  1263. if (!liberal && (!this.options.allowReserved && this.isReservedWord(this.value) || this.strict && reservedWords.strict(this.value) && (this.options.ecmaVersion >= 6 || this.input.slice(this.start, this.end).indexOf("\\") == -1))) this.raise(this.start, "The keyword '" + this.value + "' is reserved");
  1264. node.name = this.value;
  1265. } else if (liberal && this.type.keyword) {
  1266. node.name = this.type.keyword;
  1267. } else {
  1268. this.unexpected();
  1269. }
  1270. this.next();
  1271. return this.finishNode(node, "Identifier");
  1272. };
  1273. // Parses yield expression inside generator.
  1274. pp.parseYield = function () {
  1275. var node = this.startNode();
  1276. this.next();
  1277. if (this.type == tt.semi || this.canInsertSemicolon() || this.type != tt.star && !this.type.startsExpr) {
  1278. node.delegate = false;
  1279. node.argument = null;
  1280. } else {
  1281. node.delegate = this.eat(tt.star);
  1282. node.argument = this.parseMaybeAssign();
  1283. }
  1284. return this.finishNode(node, "YieldExpression");
  1285. };
  1286. // Parses array and generator comprehensions.
  1287. pp.parseComprehension = function (node, isGenerator) {
  1288. node.blocks = [];
  1289. while (this.type === tt._for) {
  1290. var block = this.startNode();
  1291. this.next();
  1292. this.expect(tt.parenL);
  1293. block.left = this.parseBindingAtom();
  1294. this.checkLVal(block.left, true);
  1295. this.expectContextual("of");
  1296. block.right = this.parseExpression();
  1297. this.expect(tt.parenR);
  1298. node.blocks.push(this.finishNode(block, "ComprehensionBlock"));
  1299. }
  1300. node.filter = this.eat(tt._if) ? this.parseParenExpression() : null;
  1301. node.body = this.parseExpression();
  1302. this.expect(isGenerator ? tt.parenR : tt.bracketR);
  1303. node.generator = isGenerator;
  1304. return this.finishNode(node, "ComprehensionExpression");
  1305. };
  1306. },{"./identifier":7,"./state":13,"./tokentype":17,"./util":18}],7:[function(_dereq_,module,exports){
  1307. // Test whether a given character code starts an identifier.
  1308. "use strict";
  1309. exports.isIdentifierStart = isIdentifierStart;
  1310. // Test whether a given character is part of an identifier.
  1311. exports.isIdentifierChar = isIdentifierChar;
  1312. exports.__esModule = true;
  1313. // This is a trick taken from Esprima. It turns out that, on
  1314. // non-Chrome browsers, to check whether a string is in a set, a
  1315. // predicate containing a big ugly `switch` statement is faster than
  1316. // a regular expression, and on Chrome the two are about on par.
  1317. // This function uses `eval` (non-lexical) to produce such a
  1318. // predicate from a space-separated string of words.
  1319. //
  1320. // It starts by sorting the words by length.
  1321. function makePredicate(words) {
  1322. words = words.split(" ");
  1323. var f = "",
  1324. cats = [];
  1325. out: for (var i = 0; i < words.length; ++i) {
  1326. for (var j = 0; j < cats.length; ++j) {
  1327. if (cats[j][0].length == words[i].length) {
  1328. cats[j].push(words[i]);
  1329. continue out;
  1330. }
  1331. }cats.push([words[i]]);
  1332. }
  1333. function compareTo(arr) {
  1334. if (arr.length == 1) {
  1335. return f += "return str === " + JSON.stringify(arr[0]) + ";";
  1336. }f += "switch(str){";
  1337. for (var i = 0; i < arr.length; ++i) {
  1338. f += "case " + JSON.stringify(arr[i]) + ":";
  1339. }f += "return true}return false;";
  1340. }
  1341. // When there are more than three length categories, an outer
  1342. // switch first dispatches on the lengths, to save on comparisons.
  1343. if (cats.length > 3) {
  1344. cats.sort(function (a, b) {
  1345. return b.length - a.length;
  1346. });
  1347. f += "switch(str.length){";
  1348. for (var i = 0; i < cats.length; ++i) {
  1349. var cat = cats[i];
  1350. f += "case " + cat[0].length + ":";
  1351. compareTo(cat);
  1352. }
  1353. f += "}"
  1354. // Otherwise, simply generate a flat `switch` statement.
  1355. ;
  1356. } else {
  1357. compareTo(words);
  1358. }
  1359. return new Function("str", f);
  1360. }
  1361. // Reserved word lists for various dialects of the language
  1362. var reservedWords = {
  1363. 3: makePredicate("abstract boolean byte char class double enum export extends final float goto implements import int interface long native package private protected public short static super synchronized throws transient volatile"),
  1364. 5: makePredicate("class enum extends super const export import"),
  1365. 6: makePredicate("enum await"),
  1366. strict: makePredicate("implements interface let package private protected public static yield"),
  1367. strictBind: makePredicate("eval arguments")
  1368. };
  1369. exports.reservedWords = reservedWords;
  1370. // And the keywords
  1371. var ecma5AndLessKeywords = "break case catch continue debugger default do else finally for function if return switch throw try var while with null true false instanceof typeof void delete new in this";
  1372. var keywords = {
  1373. 5: makePredicate(ecma5AndLessKeywords),
  1374. 6: makePredicate(ecma5AndLessKeywords + " let const class extends export import yield super")
  1375. };
  1376. exports.keywords = keywords;
  1377. // ## Character categories
  1378. // Big ugly regular expressions that match characters in the
  1379. // whitespace, identifier, and identifier-start categories. These
  1380. // are only applied when a character is found to actually have a
  1381. // code point above 128.
  1382. // Generated by `tools/generate-identifier-regex.js`.
  1383. var nonASCIIidentifierStartChars = "ªµºÀ-ÖØ-öø-ˁˆ-ˑˠ-ˤˬˮͰ-ʹͶͷͺ-ͽͿΆΈ-ΊΌΎ-ΡΣ-ϵϷ-ҁҊ-ԯԱ-Ֆՙա-ևא-תװ-ײؠ-يٮٯٱ-ۓەۥۦۮۯۺ-ۼۿܐܒ-ܯݍ-ޥޱߊ-ߪߴߵߺࠀ-ࠕࠚࠤࠨࡀ-ࡘࢠ-ࢲऄ-हऽॐक़-ॡॱ-ঀঅ-ঌএঐও-নপ-রলশ-হঽৎড়ঢ়য়-ৡৰৱਅ-ਊਏਐਓ-ਨਪ-ਰਲਲ਼ਵਸ਼ਸਹਖ਼-ੜਫ਼ੲ-ੴઅ-ઍએ-ઑઓ-નપ-રલળવ-હઽૐૠૡଅ-ଌଏଐଓ-ନପ-ରଲଳଵ-ହଽଡ଼ଢ଼ୟ-ୡୱஃஅ-ஊஎ-ஐஒ-கஙசஜஞடணதந-பம-ஹௐఅ-ఌఎ-ఐఒ-నప-హఽౘౙౠౡಅ-ಌಎ-ಐಒ-ನಪ-ಳವ-ಹಽೞೠೡೱೲഅ-ഌഎ-ഐഒ-ഺഽൎൠൡൺ-ൿඅ-ඖක-නඳ-රලව-ෆก-ะาำเ-ๆກຂຄງຈຊຍດ-ທນ-ຟມ-ຣລວສຫອ-ະາຳຽເ-ໄໆໜ-ໟༀཀ-ཇཉ-ཬྈ-ྌက-ဪဿၐ-ၕၚ-ၝၡၥၦၮ-ၰၵ-ႁႎႠ-ჅჇჍა-ჺჼ-ቈቊ-ቍቐ-ቖቘቚ-ቝበ-ኈኊ-ኍነ-ኰኲ-ኵኸ-ኾዀዂ-ዅወ-ዖዘ-ጐጒ-ጕጘ-ፚᎀ-ᎏᎠ-Ᏼᐁ-ᙬᙯ-ᙿᚁ-ᚚᚠ-ᛪᛮ-ᛸᜀ-ᜌᜎ-ᜑᜠ-ᜱᝀ-ᝑᝠ-ᝬᝮ-ᝰក-ឳៗៜᠠ-ᡷᢀ-ᢨᢪᢰ-ᣵᤀ-ᤞᥐ-ᥭᥰ-ᥴᦀ-ᦫᧁ-ᧇᨀ-ᨖᨠ-ᩔᪧᬅ-ᬳᭅ-ᭋᮃ-ᮠᮮᮯᮺ-ᯥᰀ-ᰣᱍ-ᱏᱚ-ᱽᳩ-ᳬᳮ-ᳱᳵᳶᴀ-ᶿḀ-ἕἘ-Ἕἠ-ὅὈ-Ὅὐ-ὗὙὛὝὟ-ώᾀ-ᾴᾶ-ᾼιῂ-ῄῆ-ῌῐ-ΐῖ-Ίῠ-Ῥῲ-ῴῶ-ῼⁱⁿₐ-ₜℂℇℊ-ℓℕ℘-ℝℤΩℨK-ℹℼ-ℿⅅ-ⅉⅎⅠ-ↈⰀ-Ⱞⰰ-ⱞⱠ-ⳤⳫ-ⳮⳲⳳⴀ-ⴥⴧⴭⴰ-ⵧⵯⶀ-ⶖⶠ-ⶦⶨ-ⶮⶰ-ⶶⶸ-ⶾⷀ-ⷆⷈ-ⷎⷐ-ⷖⷘ-ⷞ々-〇〡-〩〱-〵〸-〼ぁ-ゖ゛-ゟァ-ヺー-ヿㄅ-ㄭㄱ-ㆎㆠ-ㆺㇰ-ㇿ㐀-䶵一-鿌ꀀ-ꒌꓐ-ꓽꔀ-ꘌꘐ-ꘟꘪꘫꙀ-ꙮꙿ-ꚝꚠ-ꛯꜗ-ꜟꜢ-ꞈꞋ-ꞎꞐ-ꞭꞰꞱꟷ-ꠁꠃ-ꠅꠇ-ꠊꠌ-ꠢꡀ-ꡳꢂ-ꢳꣲ-ꣷꣻꤊ-ꤥꤰ-ꥆꥠ-ꥼꦄ-ꦲꧏꧠ-ꧤꧦ-ꧯꧺ-ꧾꨀ-ꨨꩀ-ꩂꩄ-ꩋꩠ-ꩶꩺꩾ-ꪯꪱꪵꪶꪹ-ꪽꫀꫂꫛ-ꫝꫠ-ꫪꫲ-ꫴꬁ-ꬆꬉ-ꬎꬑ-ꬖꬠ-ꬦꬨ-ꬮꬰ-ꭚꭜ-ꭟꭤꭥꯀ-ꯢ가-힣ힰ-ퟆퟋ-ퟻ豈-舘並-龎ff-stﬓ-ﬗיִײַ-ﬨשׁ-זּטּ-לּמּנּסּףּפּצּ-ﮱﯓ-ﴽﵐ-ﶏﶒ-ﷇﷰ-ﷻﹰ-ﹴﹶ-ﻼA-Za-zヲ-하-ᅦᅧ-ᅬᅭ-ᅲᅳ-ᅵ";
  1384. var nonASCIIidentifierChars = "‌‍·̀-ͯ·҃-֑҇-ׇֽֿׁׂׅׄؐ-ًؚ-٩ٰۖ-ۜ۟-۪ۤۧۨ-ۭ۰-۹ܑܰ-݊ަ-ް߀-߉߫-߳ࠖ-࠙ࠛ-ࠣࠥ-ࠧࠩ-࡙࠭-࡛ࣤ-ःऺ-़ा-ॏ॑-ॗॢॣ०-९ঁ-ঃ়া-ৄেৈো-্ৗৢৣ০-৯ਁ-ਃ਼ਾ-ੂੇੈੋ-੍ੑ੦-ੱੵઁ-ઃ઼ા-ૅે-ૉો-્ૢૣ૦-૯ଁ-ଃ଼ା-ୄେୈୋ-୍ୖୗୢୣ୦-୯ஂா-ூெ-ைொ-்ௗ௦-௯ఀ-ఃా-ౄె-ైొ-్ౕౖౢౣ౦-౯ಁ-ಃ಼ಾ-ೄೆ-ೈೊ-್ೕೖೢೣ೦-೯ഁ-ഃാ-ൄെ-ൈൊ-്ൗൢൣ൦-൯ංඃ්ා-ුූෘ-ෟ෦-෯ෲෳัิ-ฺ็-๎๐-๙ັິ-ູົຼ່-ໍ໐-໙༘༙༠-༩༹༵༷༾༿ཱ-྄྆྇ྍ-ྗྙ-ྼ࿆ါ-ှ၀-၉ၖ-ၙၞ-ၠၢ-ၤၧ-ၭၱ-ၴႂ-ႍႏ-ႝ፝-፟፩-፱ᜒ-᜔ᜲ-᜴ᝒᝓᝲᝳ឴-៓៝០-៩᠋-᠍᠐-᠙ᢩᤠ-ᤫᤰ-᤻᥆-᥏ᦰ-ᧀᧈᧉ᧐-᧚ᨗ-ᨛᩕ-ᩞ᩠-᩿᩼-᪉᪐-᪙᪰-᪽ᬀ-ᬄ᬴-᭄᭐-᭙᭫-᭳ᮀ-ᮂᮡ-ᮭ᮰-᮹᯦-᯳ᰤ-᰷᱀-᱉᱐-᱙᳐-᳔᳒-᳨᳭ᳲ-᳴᳸᳹᷀-᷵᷼-᷿‿⁀⁔⃐-⃥⃜⃡-⃰⳯-⵿⳱ⷠ-〪ⷿ-゙゚〯꘠-꘩꙯ꙴ-꙽ꚟ꛰꛱ꠂ꠆ꠋꠣ-ꠧꢀꢁꢴ-꣄꣐-꣙꣠-꣱꤀-꤉ꤦ-꤭ꥇ-꥓ꦀ-ꦃ꦳-꧀꧐-꧙ꧥ꧰-꧹ꨩ-ꨶꩃꩌꩍ꩐-꩙ꩻ-ꩽꪰꪲ-ꪴꪷꪸꪾ꪿꫁ꫫ-ꫯꫵ꫶ꯣ-ꯪ꯬꯭꯰-꯹ﬞ︀-️︠-︭︳︴﹍-﹏0-9_";
  1385. var nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]");
  1386. var nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]");
  1387. nonASCIIidentifierStartChars = nonASCIIidentifierChars = null;
  1388. // These are a run-length and offset encoded representation of the
  1389. // >0xffff code points that are a valid part of identifiers. The
  1390. // offset starts at 0x10000, and each pair of numbers represents an
  1391. // offset to the next range, and then a size of the range. They were
  1392. // generated by tools/generate-identifier-regex.js
  1393. var astralIdentifierStartCodes = [0, 11, 2, 25, 2, 18, 2, 1, 2, 14, 3, 13, 35, 122, 70, 52, 268, 28, 4, 48, 48, 31, 17, 26, 6, 37, 11, 29, 3, 35, 5, 7, 2, 4, 43, 157, 99, 39, 9, 51, 157, 310, 10, 21, 11, 7, 153, 5, 3, 0, 2, 43, 2, 1, 4, 0, 3, 22, 11, 22, 10, 30, 98, 21, 11, 25, 71, 55, 7, 1, 65, 0, 16, 3, 2, 2, 2, 26, 45, 28, 4, 28, 36, 7, 2, 27, 28, 53, 11, 21, 11, 18, 14, 17, 111, 72, 955, 52, 76, 44, 33, 24, 27, 35, 42, 34, 4, 0, 13, 47, 15, 3, 22, 0, 38, 17, 2, 24, 133, 46, 39, 7, 3, 1, 3, 21, 2, 6, 2, 1, 2, 4, 4, 0, 32, 4, 287, 47, 21, 1, 2, 0, 185, 46, 82, 47, 21, 0, 60, 42, 502, 63, 32, 0, 449, 56, 1288, 920, 104, 110, 2962, 1070, 13266, 568, 8, 30, 114, 29, 19, 47, 17, 3, 32, 20, 6, 18, 881, 68, 12, 0, 67, 12, 16481, 1, 3071, 106, 6, 12, 4, 8, 8, 9, 5991, 84, 2, 70, 2, 1, 3, 0, 3, 1, 3, 3, 2, 11, 2, 0, 2, 6, 2, 64, 2, 3, 3, 7, 2, 6, 2, 27, 2, 3, 2, 4, 2, 0, 4, 6, 2, 339, 3, 24, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 7, 4149, 196, 1340, 3, 2, 26, 2, 1, 2, 0, 3, 0, 2, 9, 2, 3, 2, 0, 2, 0, 7, 0, 5, 0, 2, 0, 2, 0, 2, 2, 2, 1, 2, 0, 3, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 1, 2, 0, 3, 3, 2, 6, 2, 3, 2, 3, 2, 0, 2, 9, 2, 16, 6, 2, 2, 4, 2, 16, 4421, 42710, 42, 4148, 12, 221, 16355, 541];
  1394. var astralIdentifierCodes = [509, 0, 227, 0, 150, 4, 294, 9, 1368, 2, 2, 1, 6, 3, 41, 2, 5, 0, 166, 1, 1306, 2, 54, 14, 32, 9, 16, 3, 46, 10, 54, 9, 7, 2, 37, 13, 2, 9, 52, 0, 13, 2, 49, 13, 16, 9, 83, 11, 168, 11, 6, 9, 8, 2, 57, 0, 2, 6, 3, 1, 3, 2, 10, 0, 11, 1, 3, 6, 4, 4, 316, 19, 13, 9, 214, 6, 3, 8, 112, 16, 16, 9, 82, 12, 9, 9, 535, 9, 20855, 9, 135, 4, 60, 6, 26, 9, 1016, 45, 17, 3, 19723, 1, 5319, 4, 4, 5, 9, 7, 3, 6, 31, 3, 149, 2, 1418, 49, 4305, 6, 792618, 239];
  1395. // This has a complexity linear to the value of the code. The
  1396. // assumption is that looking up astral identifier characters is
  1397. // rare.
  1398. function isInAstralSet(code, set) {
  1399. var pos = 65536;
  1400. for (var i = 0; i < set.length; i += 2) {
  1401. pos += set[i];
  1402. if (pos > code) {
  1403. return false;
  1404. }pos += set[i + 1];
  1405. if (pos >= code) {
  1406. return true;
  1407. }
  1408. }
  1409. }
  1410. function isIdentifierStart(code, astral) {
  1411. if (code < 65) {
  1412. return code === 36;
  1413. }if (code < 91) {
  1414. return true;
  1415. }if (code < 97) {
  1416. return code === 95;
  1417. }if (code < 123) {
  1418. return true;
  1419. }if (code <= 65535) {
  1420. return code >= 170 && nonASCIIidentifierStart.test(String.fromCharCode(code));
  1421. }if (astral === false) {
  1422. return false;
  1423. }return isInAstralSet(code, astralIdentifierStartCodes);
  1424. }
  1425. function isIdentifierChar(code, astral) {
  1426. if (code < 48) {
  1427. return code === 36;
  1428. }if (code < 58) {
  1429. return true;
  1430. }if (code < 65) {
  1431. return false;
  1432. }if (code < 91) {
  1433. return true;
  1434. }if (code < 97) {
  1435. return code === 95;
  1436. }if (code < 123) {
  1437. return true;
  1438. }if (code <= 65535) {
  1439. return code >= 170 && nonASCIIidentifier.test(String.fromCharCode(code));
  1440. }if (astral === false) {
  1441. return false;
  1442. }return isInAstralSet(code, astralIdentifierStartCodes) || isInAstralSet(code, astralIdentifierCodes);
  1443. }
  1444. },{}],8:[function(_dereq_,module,exports){
  1445. "use strict";
  1446. var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } };
  1447. // The `getLineInfo` function is mostly useful when the
  1448. // `locations` option is off (for performance reasons) and you
  1449. // want to find the line/column position for a given character
  1450. // offset. `input` should be the code string that the offset refers
  1451. // into.
  1452. exports.getLineInfo = getLineInfo;
  1453. exports.__esModule = true;
  1454. var Parser = _dereq_("./state").Parser;
  1455. var lineBreakG = _dereq_("./whitespace").lineBreakG;
  1456. var deprecate = _dereq_("util").deprecate;
  1457. // These are used when `options.locations` is on, for the
  1458. // `startLoc` and `endLoc` properties.
  1459. var Position = exports.Position = (function () {
  1460. function Position(line, col) {
  1461. _classCallCheck(this, Position);
  1462. this.line = line;
  1463. this.column = col;
  1464. }
  1465. Position.prototype.offset = function offset(n) {
  1466. return new Position(this.line, this.column + n);
  1467. };
  1468. return Position;
  1469. })();
  1470. var SourceLocation = exports.SourceLocation = function SourceLocation(p, start, end) {
  1471. _classCallCheck(this, SourceLocation);
  1472. this.start = start;
  1473. this.end = end;
  1474. if (p.sourceFile !== null) this.source = p.sourceFile;
  1475. };
  1476. function getLineInfo(input, offset) {
  1477. for (var line = 1, cur = 0;;) {
  1478. lineBreakG.lastIndex = cur;
  1479. var match = lineBreakG.exec(input);
  1480. if (match && match.index < offset) {
  1481. ++line;
  1482. cur = match.index + match[0].length;
  1483. } else {
  1484. return new Position(line, offset - cur);
  1485. }
  1486. }
  1487. }
  1488. var pp = Parser.prototype;
  1489. // This function is used to raise exceptions on parse errors. It
  1490. // takes an offset integer (into the current `input`) to indicate
  1491. // the location of the error, attaches the position to the end
  1492. // of the error message, and then raises a `SyntaxError` with that
  1493. // message.
  1494. pp.raise = function (pos, message) {
  1495. var loc = getLineInfo(this.input, pos);
  1496. message += " (" + loc.line + ":" + loc.column + ")";
  1497. var err = new SyntaxError(message);
  1498. err.pos = pos;err.loc = loc;err.raisedAt = this.pos;
  1499. throw err;
  1500. };
  1501. pp.curPosition = function () {
  1502. return new Position(this.curLine, this.pos - this.lineStart);
  1503. };
  1504. pp.markPosition = function () {
  1505. return this.options.locations ? [this.start, this.startLoc] : this.start;
  1506. };
  1507. },{"./state":13,"./whitespace":19,"util":5}],9:[function(_dereq_,module,exports){
  1508. "use strict";
  1509. var tt = _dereq_("./tokentype").types;
  1510. var Parser = _dereq_("./state").Parser;
  1511. var reservedWords = _dereq_("./identifier").reservedWords;
  1512. var has = _dereq_("./util").has;
  1513. var pp = Parser.prototype;
  1514. // Convert existing expression atom to assignable pattern
  1515. // if possible.
  1516. pp.toAssignable = function (node, isBinding) {
  1517. if (this.options.ecmaVersion >= 6 && node) {
  1518. switch (node.type) {
  1519. case "Identifier":
  1520. case "ObjectPattern":
  1521. case "ArrayPattern":
  1522. case "AssignmentPattern":
  1523. break;
  1524. case "ObjectExpression":
  1525. node.type = "ObjectPattern";
  1526. for (var i = 0; i < node.properties.length; i++) {
  1527. var prop = node.properties[i];
  1528. if (prop.kind !== "init") this.raise(prop.key.start, "Object pattern can't contain getter or setter");
  1529. this.toAssignable(prop.value, isBinding);
  1530. }
  1531. break;
  1532. case "ArrayExpression":
  1533. node.type = "ArrayPattern";
  1534. this.toAssignableList(node.elements, isBinding);
  1535. break;
  1536. case "AssignmentExpression":
  1537. if (node.operator === "=") {
  1538. node.type = "AssignmentPattern";
  1539. } else {
  1540. this.raise(node.left.end, "Only '=' operator can be used for specifying default value.");
  1541. }
  1542. break;
  1543. case "ParenthesizedExpression":
  1544. node.expression = this.toAssignable(node.expression, isBinding);
  1545. break;
  1546. case "MemberExpression":
  1547. if (!isBinding) break;
  1548. default:
  1549. this.raise(node.start, "Assigning to rvalue");
  1550. }
  1551. }
  1552. return node;
  1553. };
  1554. // Convert list of expression atoms to binding list.
  1555. pp.toAssignableList = function (exprList, isBinding) {
  1556. var end = exprList.length;
  1557. if (end) {
  1558. var last = exprList[end - 1];
  1559. if (last && last.type == "RestElement") {
  1560. --end;
  1561. } else if (last && last.type == "SpreadElement") {
  1562. last.type = "RestElement";
  1563. var arg = last.argument;
  1564. this.toAssignable(arg, isBinding);
  1565. if (arg.type !== "Identifier" && arg.type !== "MemberExpression" && arg.type !== "ArrayPattern") this.unexpected(arg.start);
  1566. --end;
  1567. }
  1568. }
  1569. for (var i = 0; i < end; i++) {
  1570. var elt = exprList[i];
  1571. if (elt) this.toAssignable(elt, isBinding);
  1572. }
  1573. return exprList;
  1574. };
  1575. // Parses spread element.
  1576. pp.parseSpread = function (refShorthandDefaultPos) {
  1577. var node = this.startNode();
  1578. this.next();
  1579. node.argument = this.parseMaybeAssign(refShorthandDefaultPos);
  1580. return this.finishNode(node, "SpreadElement");
  1581. };
  1582. pp.parseRest = function () {
  1583. var node = this.startNode();
  1584. this.next();
  1585. node.argument = this.type === tt.name || this.type === tt.bracketL ? this.parseBindingAtom() : this.unexpected();
  1586. return this.finishNode(node, "RestElement");
  1587. };
  1588. // Parses lvalue (assignable) atom.
  1589. pp.parseBindingAtom = function () {
  1590. if (this.options.ecmaVersion < 6) return this.parseIdent();
  1591. switch (this.type) {
  1592. case tt.name:
  1593. return this.parseIdent();
  1594. case tt.bracketL:
  1595. var node = this.startNode();
  1596. this.next();
  1597. node.elements = this.parseBindingList(tt.bracketR, true, true);
  1598. return this.finishNode(node, "ArrayPattern");
  1599. case tt.braceL:
  1600. return this.parseObj(true);
  1601. default:
  1602. this.unexpected();
  1603. }
  1604. };
  1605. pp.parseBindingList = function (close, allowEmpty, allowTrailingComma) {
  1606. var elts = [],
  1607. first = true;
  1608. while (!this.eat(close)) {
  1609. if (first) first = false;else this.expect(tt.comma);
  1610. if (allowEmpty && this.type === tt.comma) {
  1611. elts.push(null);
  1612. } else if (allowTrailingComma && this.afterTrailingComma(close)) {
  1613. break;
  1614. } else if (this.type === tt.ellipsis) {
  1615. var rest = this.parseRest();
  1616. this.parseBindingListItem(rest);
  1617. elts.push(rest);
  1618. this.expect(close);
  1619. break;
  1620. } else {
  1621. var elem = this.parseMaybeDefault(this.start, this.startLoc);
  1622. this.parseBindingListItem(elem);
  1623. elts.push(elem);
  1624. }
  1625. }
  1626. return elts;
  1627. };
  1628. pp.parseBindingListItem = function (param) {
  1629. return param;
  1630. };
  1631. // Parses assignment pattern around given atom if possible.
  1632. pp.parseMaybeDefault = function (startPos, startLoc, left) {
  1633. if (Array.isArray(startPos)) {
  1634. if (this.options.locations && noCalls === undefined) {
  1635. // shift arguments to left by one
  1636. left = startLoc;
  1637. // flatten startPos
  1638. startLoc = startPos[1];
  1639. startPos = startPos[0];
  1640. }
  1641. }
  1642. left = left || this.parseBindingAtom();
  1643. if (!this.eat(tt.eq)) return left;
  1644. var node = this.startNodeAt(startPos, startLoc);
  1645. node.operator = "=";
  1646. node.left = left;
  1647. node.right = this.parseMaybeAssign();
  1648. return this.finishNode(node, "AssignmentPattern");
  1649. };
  1650. // Verify that a node is an lval — something that can be assigned
  1651. // to.
  1652. pp.checkLVal = function (expr, isBinding, checkClashes) {
  1653. switch (expr.type) {
  1654. case "Identifier":
  1655. if (this.strict && (reservedWords.strictBind(expr.name) || reservedWords.strict(expr.name))) this.raise(expr.start, (isBinding ? "Binding " : "Assigning to ") + expr.name + " in strict mode");
  1656. if (checkClashes) {
  1657. if (has(checkClashes, expr.name)) this.raise(expr.start, "Argument name clash in strict mode");
  1658. checkClashes[expr.name] = true;
  1659. }
  1660. break;
  1661. case "MemberExpression":
  1662. if (isBinding) this.raise(expr.start, (isBinding ? "Binding" : "Assigning to") + " member expression");
  1663. break;
  1664. case "ObjectPattern":
  1665. for (var i = 0; i < expr.properties.length; i++) {
  1666. this.checkLVal(expr.properties[i].value, isBinding, checkClashes);
  1667. }break;
  1668. case "ArrayPattern":
  1669. for (var i = 0; i < expr.elements.length; i++) {
  1670. var elem = expr.elements[i];
  1671. if (elem) this.checkLVal(elem, isBinding, checkClashes);
  1672. }
  1673. break;
  1674. case "AssignmentPattern":
  1675. this.checkLVal(expr.left, isBinding, checkClashes);
  1676. break;
  1677. case "RestElement":
  1678. this.checkLVal(expr.argument, isBinding, checkClashes);
  1679. break;
  1680. case "ParenthesizedExpression":
  1681. this.checkLVal(expr.expression, isBinding, checkClashes);
  1682. break;
  1683. default:
  1684. this.raise(expr.start, (isBinding ? "Binding" : "Assigning to") + " rvalue");
  1685. }
  1686. };
  1687. },{"./identifier":7,"./state":13,"./tokentype":17,"./util":18}],10:[function(_dereq_,module,exports){
  1688. "use strict";
  1689. var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } };
  1690. exports.__esModule = true;
  1691. var Parser = _dereq_("./state").Parser;
  1692. var SourceLocation = _dereq_("./location").SourceLocation;
  1693. // Start an AST node, attaching a start offset.
  1694. var pp = Parser.prototype;
  1695. var Node = exports.Node = function Node() {
  1696. _classCallCheck(this, Node);
  1697. };
  1698. pp.startNode = function () {
  1699. var node = new Node();
  1700. node.start = this.start;
  1701. if (this.options.locations) node.loc = new SourceLocation(this, this.startLoc);
  1702. if (this.options.directSourceFile) node.sourceFile = this.options.directSourceFile;
  1703. if (this.options.ranges) node.range = [this.start, 0];
  1704. return node;
  1705. };
  1706. pp.startNodeAt = function (pos, loc) {
  1707. var node = new Node();
  1708. if (Array.isArray(pos)) {
  1709. if (this.options.locations && loc === undefined) {
  1710. // flatten pos
  1711. loc = pos[1];
  1712. pos = pos[0];
  1713. }
  1714. }
  1715. node.start = pos;
  1716. if (this.options.locations) node.loc = new SourceLocation(this, loc);
  1717. if (this.options.directSourceFile) node.sourceFile = this.options.directSourceFile;
  1718. if (this.options.ranges) node.range = [pos, 0];
  1719. return node;
  1720. };
  1721. // Finish an AST node, adding `type` and `end` properties.
  1722. pp.finishNode = function (node, type) {
  1723. node.type = type;
  1724. node.end = this.lastTokEnd;
  1725. if (this.options.locations) node.loc.end = this.lastTokEndLoc;
  1726. if (this.options.ranges) node.range[1] = this.lastTokEnd;
  1727. return node;
  1728. };
  1729. // Finish node at given position
  1730. pp.finishNodeAt = function (node, type, pos, loc) {
  1731. node.type = type;
  1732. if (Array.isArray(pos)) {
  1733. if (this.options.locations && loc === undefined) {
  1734. // flatten pos
  1735. loc = pos[1];
  1736. pos = pos[0];
  1737. }
  1738. }
  1739. node.end = pos;
  1740. if (this.options.locations) node.loc.end = loc;
  1741. if (this.options.ranges) node.range[1] = pos;
  1742. return node;
  1743. };
  1744. },{"./location":8,"./state":13}],11:[function(_dereq_,module,exports){
  1745. // Interpret and default an options object
  1746. "use strict";
  1747. exports.getOptions = getOptions;
  1748. exports.__esModule = true;
  1749. var _util = _dereq_("./util");
  1750. var has = _util.has;
  1751. var isArray = _util.isArray;
  1752. var SourceLocation = _dereq_("./location").SourceLocation;
  1753. // A second optional argument can be given to further configure
  1754. // the parser process. These options are recognized:
  1755. var defaultOptions = {
  1756. // `ecmaVersion` indicates the ECMAScript version to parse. Must
  1757. // be either 3, or 5, or 6. This influences support for strict
  1758. // mode, the set of reserved words, support for getters and
  1759. // setters and other features.
  1760. ecmaVersion: 5,
  1761. // Source type ("script" or "module") for different semantics
  1762. sourceType: "script",
  1763. // `onInsertedSemicolon` can be a callback that will be called
  1764. // when a semicolon is automatically inserted. It will be passed
  1765. // th position of the comma as an offset, and if `locations` is
  1766. // enabled, it is given the location as a `{line, column}` object
  1767. // as second argument.
  1768. onInsertedSemicolon: null,
  1769. // `onTrailingComma` is similar to `onInsertedSemicolon`, but for
  1770. // trailing commas.
  1771. onTrailingComma: null,
  1772. // By default, reserved words are not enforced. Disable
  1773. // `allowReserved` to enforce them. When this option has the
  1774. // value "never", reserved words and keywords can also not be
  1775. // used as property names.
  1776. allowReserved: true,
  1777. // When enabled, a return at the top level is not considered an
  1778. // error.
  1779. allowReturnOutsideFunction: false,
  1780. // When enabled, import/export statements are not constrained to
  1781. // appearing at the top of the program.
  1782. allowImportExportEverywhere: false,
  1783. // When enabled, hashbang directive in the beginning of file
  1784. // is allowed and treated as a line comment.
  1785. allowHashBang: false,
  1786. // When `locations` is on, `loc` properties holding objects with
  1787. // `start` and `end` properties in `{line, column}` form (with
  1788. // line being 1-based and column 0-based) will be attached to the
  1789. // nodes.
  1790. locations: false,
  1791. // A function can be passed as `onToken` option, which will
  1792. // cause Acorn to call that function with object in the same
  1793. // format as tokenize() returns. Note that you are not
  1794. // allowed to call the parser from the callback—that will
  1795. // corrupt its internal state.
  1796. onToken: null,
  1797. // A function can be passed as `onComment` option, which will
  1798. // cause Acorn to call that function with `(block, text, start,
  1799. // end)` parameters whenever a comment is skipped. `block` is a
  1800. // boolean indicating whether this is a block (`/* */`) comment,
  1801. // `text` is the content of the comment, and `start` and `end` are
  1802. // character offsets that denote the start and end of the comment.
  1803. // When the `locations` option is on, two more parameters are
  1804. // passed, the full `{line, column}` locations of the start and
  1805. // end of the comments. Note that you are not allowed to call the
  1806. // parser from the callback—that will corrupt its internal state.
  1807. onComment: null,
  1808. // Nodes have their start and end characters offsets recorded in
  1809. // `start` and `end` properties (directly on the node, rather than
  1810. // the `loc` object, which holds line/column data. To also add a
  1811. // [semi-standardized][range] `range` property holding a `[start,
  1812. // end]` array with the same numbers, set the `ranges` option to
  1813. // `true`.
  1814. //
  1815. // [range]: https://bugzilla.mozilla.org/show_bug.cgi?id=745678
  1816. ranges: false,
  1817. // It is possible to parse multiple files into a single AST by
  1818. // passing the tree produced by parsing the first file as
  1819. // `program` option in subsequent parses. This will add the
  1820. // toplevel forms of the parsed file to the `Program` (top) node
  1821. // of an existing parse tree.
  1822. program: null,
  1823. // When `locations` is on, you can pass this to record the source
  1824. // file in every node's `loc` object.
  1825. sourceFile: null,
  1826. // This value, if given, is stored in every node, whether
  1827. // `locations` is on or off.
  1828. directSourceFile: null,
  1829. // When enabled, parenthesized expressions are represented by
  1830. // (non-standard) ParenthesizedExpression nodes
  1831. preserveParens: false,
  1832. plugins: {}
  1833. };exports.defaultOptions = defaultOptions;
  1834. function getOptions(opts) {
  1835. var options = {};
  1836. for (var opt in defaultOptions) {
  1837. options[opt] = opts && has(opts, opt) ? opts[opt] : defaultOptions[opt];
  1838. }if (isArray(options.onToken)) {
  1839. (function () {
  1840. var tokens = options.onToken;
  1841. options.onToken = function (token) {
  1842. return tokens.push(token);
  1843. };
  1844. })();
  1845. }
  1846. if (isArray(options.onComment)) options.onComment = pushComment(options, options.onComment);
  1847. return options;
  1848. }
  1849. function pushComment(options, array) {
  1850. return function (block, text, start, end, startLoc, endLoc) {
  1851. var comment = {
  1852. type: block ? "Block" : "Line",
  1853. value: text,
  1854. start: start,
  1855. end: end
  1856. };
  1857. if (options.locations) comment.loc = new SourceLocation(this, startLoc, endLoc);
  1858. if (options.ranges) comment.range = [start, end];
  1859. array.push(comment);
  1860. };
  1861. }
  1862. },{"./location":8,"./util":18}],12:[function(_dereq_,module,exports){
  1863. "use strict";
  1864. var tt = _dereq_("./tokentype").types;
  1865. var Parser = _dereq_("./state").Parser;
  1866. var lineBreak = _dereq_("./whitespace").lineBreak;
  1867. var pp = Parser.prototype;
  1868. // ## Parser utilities
  1869. // Test whether a statement node is the string literal `"use strict"`.
  1870. pp.isUseStrict = function (stmt) {
  1871. return this.options.ecmaVersion >= 5 && stmt.type === "ExpressionStatement" && stmt.expression.type === "Literal" && stmt.expression.value === "use strict";
  1872. };
  1873. // Predicate that tests whether the next token is of the given
  1874. // type, and if yes, consumes it as a side effect.
  1875. pp.eat = function (type) {
  1876. if (this.type === type) {
  1877. this.next();
  1878. return true;
  1879. } else {
  1880. return false;
  1881. }
  1882. };
  1883. // Tests whether parsed token is a contextual keyword.
  1884. pp.isContextual = function (name) {
  1885. return this.type === tt.name && this.value === name;
  1886. };
  1887. // Consumes contextual keyword if possible.
  1888. pp.eatContextual = function (name) {
  1889. return this.value === name && this.eat(tt.name);
  1890. };
  1891. // Asserts that following token is given contextual keyword.
  1892. pp.expectContextual = function (name) {
  1893. if (!this.eatContextual(name)) this.unexpected();
  1894. };
  1895. // Test whether a semicolon can be inserted at the current position.
  1896. pp.canInsertSemicolon = function () {
  1897. return this.type === tt.eof || this.type === tt.braceR || lineBreak.test(this.input.slice(this.lastTokEnd, this.start));
  1898. };
  1899. pp.insertSemicolon = function () {
  1900. if (this.canInsertSemicolon()) {
  1901. if (this.options.onInsertedSemicolon) this.options.onInsertedSemicolon(this.lastTokEnd, this.lastTokEndLoc);
  1902. return true;
  1903. }
  1904. };
  1905. // Consume a semicolon, or, failing that, see if we are allowed to
  1906. // pretend that there is a semicolon at this position.
  1907. pp.semicolon = function () {
  1908. if (!this.eat(tt.semi) && !this.insertSemicolon()) this.unexpected();
  1909. };
  1910. pp.afterTrailingComma = function (tokType) {
  1911. if (this.type == tokType) {
  1912. if (this.options.onTrailingComma) this.options.onTrailingComma(this.lastTokStart, this.lastTokStartLoc);
  1913. this.next();
  1914. return true;
  1915. }
  1916. };
  1917. // Expect a token of a given type. If found, consume it, otherwise,
  1918. // raise an unexpected token error.
  1919. pp.expect = function (type) {
  1920. this.eat(type) || this.unexpected();
  1921. };
  1922. // Raise an unexpected token error.
  1923. pp.unexpected = function (pos) {
  1924. this.raise(pos != null ? pos : this.start, "Unexpected token");
  1925. };
  1926. },{"./state":13,"./tokentype":17,"./whitespace":19}],13:[function(_dereq_,module,exports){
  1927. "use strict";
  1928. exports.Parser = Parser;
  1929. exports.__esModule = true;
  1930. var _identifier = _dereq_("./identifier");
  1931. var reservedWords = _identifier.reservedWords;
  1932. var keywords = _identifier.keywords;
  1933. var tt = _dereq_("./tokentype").types;
  1934. var lineBreak = _dereq_("./whitespace").lineBreak;
  1935. function Parser(options, input, startPos) {
  1936. this.options = options;
  1937. this.sourceFile = this.options.sourceFile || null;
  1938. this.isKeyword = keywords[this.options.ecmaVersion >= 6 ? 6 : 5];
  1939. this.isReservedWord = reservedWords[this.options.ecmaVersion];
  1940. this.input = input;
  1941. // Load plugins
  1942. this.loadPlugins(this.options.plugins);
  1943. // Set up token state
  1944. // The current position of the tokenizer in the input.
  1945. if (startPos) {
  1946. this.pos = startPos;
  1947. this.lineStart = Math.max(0, this.input.lastIndexOf("\n", startPos));
  1948. this.curLine = this.input.slice(0, this.lineStart).split(lineBreak).length;
  1949. } else {
  1950. this.pos = this.lineStart = 0;
  1951. this.curLine = 1;
  1952. }
  1953. // Properties of the current token:
  1954. // Its type
  1955. this.type = tt.eof;
  1956. // For tokens that include more information than their type, the value
  1957. this.value = null;
  1958. // Its start and end offset
  1959. this.start = this.end = this.pos;
  1960. // And, if locations are used, the {line, column} object
  1961. // corresponding to those offsets
  1962. this.startLoc = this.endLoc = null;
  1963. // Position information for the previous token
  1964. this.lastTokEndLoc = this.lastTokStartLoc = null;
  1965. this.lastTokStart = this.lastTokEnd = this.pos;
  1966. // The context stack is used to superficially track syntactic
  1967. // context to predict whether a regular expression is allowed in a
  1968. // given position.
  1969. this.context = this.initialContext();
  1970. this.exprAllowed = true;
  1971. // Figure out if it's a module code.
  1972. this.strict = this.inModule = this.options.sourceType === "module";
  1973. // Used to signify the start of a potential arrow function
  1974. this.potentialArrowAt = -1;
  1975. // Flags to track whether we are in a function, a generator.
  1976. this.inFunction = this.inGenerator = false;
  1977. // Labels in scope.
  1978. this.labels = [];
  1979. // If enabled, skip leading hashbang line.
  1980. if (this.pos === 0 && this.options.allowHashBang && this.input.slice(0, 2) === "#!") this.skipLineComment(2);
  1981. }
  1982. Parser.prototype.extend = function (name, f) {
  1983. this[name] = f(this[name]);
  1984. };
  1985. // Registered plugins
  1986. var plugins = {};
  1987. exports.plugins = plugins;
  1988. Parser.prototype.loadPlugins = function (plugins) {
  1989. for (var _name in plugins) {
  1990. var plugin = exports.plugins[_name];
  1991. if (!plugin) throw new Error("Plugin '" + _name + "' not found");
  1992. plugin(this, plugins[_name]);
  1993. }
  1994. };
  1995. },{"./identifier":7,"./tokentype":17,"./whitespace":19}],14:[function(_dereq_,module,exports){
  1996. "use strict";
  1997. var tt = _dereq_("./tokentype").types;
  1998. var Parser = _dereq_("./state").Parser;
  1999. var lineBreak = _dereq_("./whitespace").lineBreak;
  2000. var pp = Parser.prototype;
  2001. // ### Statement parsing
  2002. // Parse a program. Initializes the parser, reads any number of
  2003. // statements, and wraps them in a Program node. Optionally takes a
  2004. // `program` argument. If present, the statements will be appended
  2005. // to its body instead of creating a new node.
  2006. pp.parseTopLevel = function (node) {
  2007. var first = true;
  2008. if (!node.body) node.body = [];
  2009. while (this.type !== tt.eof) {
  2010. var stmt = this.parseStatement(true, true);
  2011. node.body.push(stmt);
  2012. if (first && this.isUseStrict(stmt)) this.setStrict(true);
  2013. first = false;
  2014. }
  2015. this.next();
  2016. if (this.options.ecmaVersion >= 6) {
  2017. node.sourceType = this.options.sourceType;
  2018. }
  2019. return this.finishNode(node, "Program");
  2020. };
  2021. var loopLabel = { kind: "loop" },
  2022. switchLabel = { kind: "switch" };
  2023. // Parse a single statement.
  2024. //
  2025. // If expecting a statement and finding a slash operator, parse a
  2026. // regular expression literal. This is to handle cases like
  2027. // `if (foo) /blah/.exec(foo)`, where looking at the previous token
  2028. // does not help.
  2029. pp.parseStatement = function (declaration, topLevel) {
  2030. var starttype = this.type,
  2031. node = this.startNode();
  2032. // Most types of statements are recognized by the keyword they
  2033. // start with. Many are trivial to parse, some require a bit of
  2034. // complexity.
  2035. switch (starttype) {
  2036. case tt._break:case tt._continue:
  2037. return this.parseBreakContinueStatement(node, starttype.keyword);
  2038. case tt._debugger:
  2039. return this.parseDebuggerStatement(node);
  2040. case tt._do:
  2041. return this.parseDoStatement(node);
  2042. case tt._for:
  2043. return this.parseForStatement(node);
  2044. case tt._function:
  2045. if (!declaration && this.options.ecmaVersion >= 6) this.unexpected();
  2046. return this.parseFunctionStatement(node);
  2047. case tt._class:
  2048. if (!declaration) this.unexpected();
  2049. return this.parseClass(node, true);
  2050. case tt._if:
  2051. return this.parseIfStatement(node);
  2052. case tt._return:
  2053. return this.parseReturnStatement(node);
  2054. case tt._switch:
  2055. return this.parseSwitchStatement(node);
  2056. case tt._throw:
  2057. return this.parseThrowStatement(node);
  2058. case tt._try:
  2059. return this.parseTryStatement(node);
  2060. case tt._let:case tt._const:
  2061. if (!declaration) this.unexpected(); // NOTE: falls through to _var
  2062. case tt._var:
  2063. return this.parseVarStatement(node, starttype);
  2064. case tt._while:
  2065. return this.parseWhileStatement(node);
  2066. case tt._with:
  2067. return this.parseWithStatement(node);
  2068. case tt.braceL:
  2069. return this.parseBlock();
  2070. case tt.semi:
  2071. return this.parseEmptyStatement(node);
  2072. case tt._export:
  2073. case tt._import:
  2074. if (!this.options.allowImportExportEverywhere) {
  2075. if (!topLevel) this.raise(this.start, "'import' and 'export' may only appear at the top level");
  2076. if (!this.inModule) this.raise(this.start, "'import' and 'export' may appear only with 'sourceType: module'");
  2077. }
  2078. return starttype === tt._import ? this.parseImport(node) : this.parseExport(node);
  2079. // If the statement does not start with a statement keyword or a
  2080. // brace, it's an ExpressionStatement or LabeledStatement. We
  2081. // simply start parsing an expression, and afterwards, if the
  2082. // next token is a colon and the expression was a simple
  2083. // Identifier node, we switch to interpreting it as a label.
  2084. default:
  2085. var maybeName = this.value,
  2086. expr = this.parseExpression();
  2087. if (starttype === tt.name && expr.type === "Identifier" && this.eat(tt.colon)) return this.parseLabeledStatement(node, maybeName, expr);else return this.parseExpressionStatement(node, expr);
  2088. }
  2089. };
  2090. pp.parseBreakContinueStatement = function (node, keyword) {
  2091. var isBreak = keyword == "break";
  2092. this.next();
  2093. if (this.eat(tt.semi) || this.insertSemicolon()) node.label = null;else if (this.type !== tt.name) this.unexpected();else {
  2094. node.label = this.parseIdent();
  2095. this.semicolon();
  2096. }
  2097. // Verify that there is an actual destination to break or
  2098. // continue to.
  2099. for (var i = 0; i < this.labels.length; ++i) {
  2100. var lab = this.labels[i];
  2101. if (node.label == null || lab.name === node.label.name) {
  2102. if (lab.kind != null && (isBreak || lab.kind === "loop")) break;
  2103. if (node.label && isBreak) break;
  2104. }
  2105. }
  2106. if (i === this.labels.length) this.raise(node.start, "Unsyntactic " + keyword);
  2107. return this.finishNode(node, isBreak ? "BreakStatement" : "ContinueStatement");
  2108. };
  2109. pp.parseDebuggerStatement = function (node) {
  2110. this.next();
  2111. this.semicolon();
  2112. return this.finishNode(node, "DebuggerStatement");
  2113. };
  2114. pp.parseDoStatement = function (node) {
  2115. this.next();
  2116. this.labels.push(loopLabel);
  2117. node.body = this.parseStatement(false);
  2118. this.labels.pop();
  2119. this.expect(tt._while);
  2120. node.test = this.parseParenExpression();
  2121. if (this.options.ecmaVersion >= 6) this.eat(tt.semi);else this.semicolon();
  2122. return this.finishNode(node, "DoWhileStatement");
  2123. };
  2124. // Disambiguating between a `for` and a `for`/`in` or `for`/`of`
  2125. // loop is non-trivial. Basically, we have to parse the init `var`
  2126. // statement or expression, disallowing the `in` operator (see
  2127. // the second parameter to `parseExpression`), and then check
  2128. // whether the next token is `in` or `of`. When there is no init
  2129. // part (semicolon immediately after the opening parenthesis), it
  2130. // is a regular `for` loop.
  2131. pp.parseForStatement = function (node) {
  2132. this.next();
  2133. this.labels.push(loopLabel);
  2134. this.expect(tt.parenL);
  2135. if (this.type === tt.semi) return this.parseFor(node, null);
  2136. if (this.type === tt._var || this.type === tt._let || this.type === tt._const) {
  2137. var _init = this.startNode(),
  2138. varKind = this.type;
  2139. this.next();
  2140. this.parseVar(_init, true, varKind);
  2141. this.finishNode(_init, "VariableDeclaration");
  2142. if ((this.type === tt._in || this.options.ecmaVersion >= 6 && this.isContextual("of")) && _init.declarations.length === 1 && !(varKind !== tt._var && _init.declarations[0].init)) return this.parseForIn(node, _init);
  2143. return this.parseFor(node, _init);
  2144. }
  2145. var refShorthandDefaultPos = { start: 0 };
  2146. var init = this.parseExpression(true, refShorthandDefaultPos);
  2147. if (this.type === tt._in || this.options.ecmaVersion >= 6 && this.isContextual("of")) {
  2148. this.toAssignable(init);
  2149. this.checkLVal(init);
  2150. return this.parseForIn(node, init);
  2151. } else if (refShorthandDefaultPos.start) {
  2152. this.unexpected(refShorthandDefaultPos.start);
  2153. }
  2154. return this.parseFor(node, init);
  2155. };
  2156. pp.parseFunctionStatement = function (node) {
  2157. this.next();
  2158. return this.parseFunction(node, true);
  2159. };
  2160. pp.parseIfStatement = function (node) {
  2161. this.next();
  2162. node.test = this.parseParenExpression();
  2163. node.consequent = this.parseStatement(false);
  2164. node.alternate = this.eat(tt._else) ? this.parseStatement(false) : null;
  2165. return this.finishNode(node, "IfStatement");
  2166. };
  2167. pp.parseReturnStatement = function (node) {
  2168. if (!this.inFunction && !this.options.allowReturnOutsideFunction) this.raise(this.start, "'return' outside of function");
  2169. this.next();
  2170. // In `return` (and `break`/`continue`), the keywords with
  2171. // optional arguments, we eagerly look for a semicolon or the
  2172. // possibility to insert one.
  2173. if (this.eat(tt.semi) || this.insertSemicolon()) node.argument = null;else {
  2174. node.argument = this.parseExpression();this.semicolon();
  2175. }
  2176. return this.finishNode(node, "ReturnStatement");
  2177. };
  2178. pp.parseSwitchStatement = function (node) {
  2179. this.next();
  2180. node.discriminant = this.parseParenExpression();
  2181. node.cases = [];
  2182. this.expect(tt.braceL);
  2183. this.labels.push(switchLabel);
  2184. // Statements under must be grouped (by label) in SwitchCase
  2185. // nodes. `cur` is used to keep the node that we are currently
  2186. // adding statements to.
  2187. for (var cur, sawDefault; this.type != tt.braceR;) {
  2188. if (this.type === tt._case || this.type === tt._default) {
  2189. var isCase = this.type === tt._case;
  2190. if (cur) this.finishNode(cur, "SwitchCase");
  2191. node.cases.push(cur = this.startNode());
  2192. cur.consequent = [];
  2193. this.next();
  2194. if (isCase) {
  2195. cur.test = this.parseExpression();
  2196. } else {
  2197. if (sawDefault) this.raise(this.lastTokStart, "Multiple default clauses");
  2198. sawDefault = true;
  2199. cur.test = null;
  2200. }
  2201. this.expect(tt.colon);
  2202. } else {
  2203. if (!cur) this.unexpected();
  2204. cur.consequent.push(this.parseStatement(true));
  2205. }
  2206. }
  2207. if (cur) this.finishNode(cur, "SwitchCase");
  2208. this.next(); // Closing brace
  2209. this.labels.pop();
  2210. return this.finishNode(node, "SwitchStatement");
  2211. };
  2212. pp.parseThrowStatement = function (node) {
  2213. this.next();
  2214. if (lineBreak.test(this.input.slice(this.lastTokEnd, this.start))) this.raise(this.lastTokEnd, "Illegal newline after throw");
  2215. node.argument = this.parseExpression();
  2216. this.semicolon();
  2217. return this.finishNode(node, "ThrowStatement");
  2218. };
  2219. // Reused empty array added for node fields that are always empty.
  2220. var empty = [];
  2221. pp.parseTryStatement = function (node) {
  2222. this.next();
  2223. node.block = this.parseBlock();
  2224. node.handler = null;
  2225. if (this.type === tt._catch) {
  2226. var clause = this.startNode();
  2227. this.next();
  2228. this.expect(tt.parenL);
  2229. clause.param = this.parseBindingAtom();
  2230. this.checkLVal(clause.param, true);
  2231. this.expect(tt.parenR);
  2232. clause.guard = null;
  2233. clause.body = this.parseBlock();
  2234. node.handler = this.finishNode(clause, "CatchClause");
  2235. }
  2236. node.guardedHandlers = empty;
  2237. node.finalizer = this.eat(tt._finally) ? this.parseBlock() : null;
  2238. if (!node.handler && !node.finalizer) this.raise(node.start, "Missing catch or finally clause");
  2239. return this.finishNode(node, "TryStatement");
  2240. };
  2241. pp.parseVarStatement = function (node, kind) {
  2242. this.next();
  2243. this.parseVar(node, false, kind);
  2244. this.semicolon();
  2245. return this.finishNode(node, "VariableDeclaration");
  2246. };
  2247. pp.parseWhileStatement = function (node) {
  2248. this.next();
  2249. node.test = this.parseParenExpression();
  2250. this.labels.push(loopLabel);
  2251. node.body = this.parseStatement(false);
  2252. this.labels.pop();
  2253. return this.finishNode(node, "WhileStatement");
  2254. };
  2255. pp.parseWithStatement = function (node) {
  2256. if (this.strict) this.raise(this.start, "'with' in strict mode");
  2257. this.next();
  2258. node.object = this.parseParenExpression();
  2259. node.body = this.parseStatement(false);
  2260. return this.finishNode(node, "WithStatement");
  2261. };
  2262. pp.parseEmptyStatement = function (node) {
  2263. this.next();
  2264. return this.finishNode(node, "EmptyStatement");
  2265. };
  2266. pp.parseLabeledStatement = function (node, maybeName, expr) {
  2267. for (var i = 0; i < this.labels.length; ++i) {
  2268. if (this.labels[i].name === maybeName) this.raise(expr.start, "Label '" + maybeName + "' is already declared");
  2269. }var kind = this.type.isLoop ? "loop" : this.type === tt._switch ? "switch" : null;
  2270. this.labels.push({ name: maybeName, kind: kind });
  2271. node.body = this.parseStatement(true);
  2272. this.labels.pop();
  2273. node.label = expr;
  2274. return this.finishNode(node, "LabeledStatement");
  2275. };
  2276. pp.parseExpressionStatement = function (node, expr) {
  2277. node.expression = expr;
  2278. this.semicolon();
  2279. return this.finishNode(node, "ExpressionStatement");
  2280. };
  2281. // Parse a semicolon-enclosed block of statements, handling `"use
  2282. // strict"` declarations when `allowStrict` is true (used for
  2283. // function bodies).
  2284. pp.parseBlock = function (allowStrict) {
  2285. var node = this.startNode(),
  2286. first = true,
  2287. oldStrict = undefined;
  2288. node.body = [];
  2289. this.expect(tt.braceL);
  2290. while (!this.eat(tt.braceR)) {
  2291. var stmt = this.parseStatement(true);
  2292. node.body.push(stmt);
  2293. if (first && allowStrict && this.isUseStrict(stmt)) {
  2294. oldStrict = this.strict;
  2295. this.setStrict(this.strict = true);
  2296. }
  2297. first = false;
  2298. }
  2299. if (oldStrict === false) this.setStrict(false);
  2300. return this.finishNode(node, "BlockStatement");
  2301. };
  2302. // Parse a regular `for` loop. The disambiguation code in
  2303. // `parseStatement` will already have parsed the init statement or
  2304. // expression.
  2305. pp.parseFor = function (node, init) {
  2306. node.init = init;
  2307. this.expect(tt.semi);
  2308. node.test = this.type === tt.semi ? null : this.parseExpression();
  2309. this.expect(tt.semi);
  2310. node.update = this.type === tt.parenR ? null : this.parseExpression();
  2311. this.expect(tt.parenR);
  2312. node.body = this.parseStatement(false);
  2313. this.labels.pop();
  2314. return this.finishNode(node, "ForStatement");
  2315. };
  2316. // Parse a `for`/`in` and `for`/`of` loop, which are almost
  2317. // same from parser's perspective.
  2318. pp.parseForIn = function (node, init) {
  2319. var type = this.type === tt._in ? "ForInStatement" : "ForOfStatement";
  2320. this.next();
  2321. node.left = init;
  2322. node.right = this.parseExpression();
  2323. this.expect(tt.parenR);
  2324. node.body = this.parseStatement(false);
  2325. this.labels.pop();
  2326. return this.finishNode(node, type);
  2327. };
  2328. // Parse a list of variable declarations.
  2329. pp.parseVar = function (node, isFor, kind) {
  2330. node.declarations = [];
  2331. node.kind = kind.keyword;
  2332. for (;;) {
  2333. var decl = this.startNode();
  2334. this.parseVarId(decl);
  2335. if (this.eat(tt.eq)) {
  2336. decl.init = this.parseMaybeAssign(isFor);
  2337. } else if (kind === tt._const && !(this.type === tt._in || this.options.ecmaVersion >= 6 && this.isContextual("of"))) {
  2338. this.unexpected();
  2339. } else if (decl.id.type != "Identifier" && !(isFor && (this.type === tt._in || this.isContextual("of")))) {
  2340. this.raise(this.lastTokEnd, "Complex binding patterns require an initialization value");
  2341. } else {
  2342. decl.init = null;
  2343. }
  2344. node.declarations.push(this.finishNode(decl, "VariableDeclarator"));
  2345. if (!this.eat(tt.comma)) break;
  2346. }
  2347. return node;
  2348. };
  2349. pp.parseVarId = function (decl) {
  2350. decl.id = this.parseBindingAtom();
  2351. this.checkLVal(decl.id, true);
  2352. };
  2353. // Parse a function declaration or literal (depending on the
  2354. // `isStatement` parameter).
  2355. pp.parseFunction = function (node, isStatement, allowExpressionBody) {
  2356. this.initFunction(node);
  2357. if (this.options.ecmaVersion >= 6) node.generator = this.eat(tt.star);
  2358. if (isStatement || this.type === tt.name) node.id = this.parseIdent();
  2359. this.parseFunctionParams(node);
  2360. this.parseFunctionBody(node, allowExpressionBody);
  2361. return this.finishNode(node, isStatement ? "FunctionDeclaration" : "FunctionExpression");
  2362. };
  2363. pp.parseFunctionParams = function (node) {
  2364. this.expect(tt.parenL);
  2365. node.params = this.parseBindingList(tt.parenR, false, false);
  2366. };
  2367. // Parse a class declaration or literal (depending on the
  2368. // `isStatement` parameter).
  2369. pp.parseClass = function (node, isStatement) {
  2370. this.next();
  2371. this.parseClassId(node, isStatement);
  2372. this.parseClassSuper(node);
  2373. var classBody = this.startNode();
  2374. var hadConstructor = false;
  2375. classBody.body = [];
  2376. this.expect(tt.braceL);
  2377. while (!this.eat(tt.braceR)) {
  2378. if (this.eat(tt.semi)) continue;
  2379. var method = this.startNode();
  2380. var isGenerator = this.eat(tt.star);
  2381. var isMaybeStatic = this.type === tt.name && this.value === "static";
  2382. this.parsePropertyName(method);
  2383. method["static"] = isMaybeStatic && this.type !== tt.parenL;
  2384. if (method["static"]) {
  2385. if (isGenerator) this.unexpected();
  2386. isGenerator = this.eat(tt.star);
  2387. this.parsePropertyName(method);
  2388. }
  2389. method.kind = "method";
  2390. if (!method.computed) {
  2391. var key = method.key;
  2392. var isGetSet = false;
  2393. if (!isGenerator && key.type === "Identifier" && this.type !== tt.parenL && (key.name === "get" || key.name === "set")) {
  2394. isGetSet = true;
  2395. method.kind = key.name;
  2396. key = this.parsePropertyName(method);
  2397. }
  2398. if (!method["static"] && (key.type === "Identifier" && key.name === "constructor" || key.type === "Literal" && key.value === "constructor")) {
  2399. if (hadConstructor) this.raise(key.start, "Duplicate constructor in the same class");
  2400. if (isGetSet) this.raise(key.start, "Constructor can't have get/set modifier");
  2401. if (isGenerator) this.raise(key.start, "Constructor can't be a generator");
  2402. method.kind = "constructor";
  2403. hadConstructor = true;
  2404. }
  2405. }
  2406. this.parseClassMethod(classBody, method, isGenerator);
  2407. }
  2408. node.body = this.finishNode(classBody, "ClassBody");
  2409. return this.finishNode(node, isStatement ? "ClassDeclaration" : "ClassExpression");
  2410. };
  2411. pp.parseClassMethod = function (classBody, method, isGenerator) {
  2412. method.value = this.parseMethod(isGenerator);
  2413. classBody.body.push(this.finishNode(method, "MethodDefinition"));
  2414. };
  2415. pp.parseClassId = function (node, isStatement) {
  2416. node.id = this.type === tt.name ? this.parseIdent() : isStatement ? this.unexpected() : null;
  2417. };
  2418. pp.parseClassSuper = function (node) {
  2419. node.superClass = this.eat(tt._extends) ? this.parseExprSubscripts() : null;
  2420. };
  2421. // Parses module export declaration.
  2422. pp.parseExport = function (node) {
  2423. this.next();
  2424. // export * from '...'
  2425. if (this.eat(tt.star)) {
  2426. this.expectContextual("from");
  2427. node.source = this.type === tt.string ? this.parseExprAtom() : this.unexpected();
  2428. this.semicolon();
  2429. return this.finishNode(node, "ExportAllDeclaration");
  2430. }
  2431. if (this.eat(tt._default)) {
  2432. // export default ...
  2433. var expr = this.parseMaybeAssign();
  2434. var needsSemi = true;
  2435. if (expr.type == "FunctionExpression" || expr.type == "ClassExpression") {
  2436. needsSemi = false;
  2437. if (expr.id) {
  2438. expr.type = expr.type == "FunctionExpression" ? "FunctionDeclaration" : "ClassDeclaration";
  2439. }
  2440. }
  2441. node.declaration = expr;
  2442. if (needsSemi) this.semicolon();
  2443. return this.finishNode(node, "ExportDefaultDeclaration");
  2444. }
  2445. // export var|const|let|function|class ...
  2446. if (this.shouldParseExportStatement()) {
  2447. node.declaration = this.parseStatement(true);
  2448. node.specifiers = [];
  2449. node.source = null;
  2450. } else {
  2451. // export { x, y as z } [from '...']
  2452. node.declaration = null;
  2453. node.specifiers = this.parseExportSpecifiers();
  2454. if (this.eatContextual("from")) {
  2455. node.source = this.type === tt.string ? this.parseExprAtom() : this.unexpected();
  2456. } else {
  2457. node.source = null;
  2458. }
  2459. this.semicolon();
  2460. }
  2461. return this.finishNode(node, "ExportNamedDeclaration");
  2462. };
  2463. pp.shouldParseExportStatement = function () {
  2464. return this.type.keyword;
  2465. };
  2466. // Parses a comma-separated list of module exports.
  2467. pp.parseExportSpecifiers = function () {
  2468. var nodes = [],
  2469. first = true;
  2470. // export { x, y as z } [from '...']
  2471. this.expect(tt.braceL);
  2472. while (!this.eat(tt.braceR)) {
  2473. if (!first) {
  2474. this.expect(tt.comma);
  2475. if (this.afterTrailingComma(tt.braceR)) break;
  2476. } else first = false;
  2477. var node = this.startNode();
  2478. node.local = this.parseIdent(this.type === tt._default);
  2479. node.exported = this.eatContextual("as") ? this.parseIdent(true) : node.local;
  2480. nodes.push(this.finishNode(node, "ExportSpecifier"));
  2481. }
  2482. return nodes;
  2483. };
  2484. // Parses import declaration.
  2485. pp.parseImport = function (node) {
  2486. this.next();
  2487. // import '...'
  2488. if (this.type === tt.string) {
  2489. node.specifiers = empty;
  2490. node.source = this.parseExprAtom();
  2491. node.kind = "";
  2492. } else {
  2493. node.specifiers = this.parseImportSpecifiers();
  2494. this.expectContextual("from");
  2495. node.source = this.type === tt.string ? this.parseExprAtom() : this.unexpected();
  2496. }
  2497. this.semicolon();
  2498. return this.finishNode(node, "ImportDeclaration");
  2499. };
  2500. // Parses a comma-separated list of module imports.
  2501. pp.parseImportSpecifiers = function () {
  2502. var nodes = [],
  2503. first = true;
  2504. if (this.type === tt.name) {
  2505. // import defaultObj, { x, y as z } from '...'
  2506. var node = this.startNode();
  2507. node.local = this.parseIdent();
  2508. this.checkLVal(node.local, true);
  2509. nodes.push(this.finishNode(node, "ImportDefaultSpecifier"));
  2510. if (!this.eat(tt.comma)) return nodes;
  2511. }
  2512. if (this.type === tt.star) {
  2513. var node = this.startNode();
  2514. this.next();
  2515. this.expectContextual("as");
  2516. node.local = this.parseIdent();
  2517. this.checkLVal(node.local, true);
  2518. nodes.push(this.finishNode(node, "ImportNamespaceSpecifier"));
  2519. return nodes;
  2520. }
  2521. this.expect(tt.braceL);
  2522. while (!this.eat(tt.braceR)) {
  2523. if (!first) {
  2524. this.expect(tt.comma);
  2525. if (this.afterTrailingComma(tt.braceR)) break;
  2526. } else first = false;
  2527. var node = this.startNode();
  2528. node.imported = this.parseIdent(true);
  2529. node.local = this.eatContextual("as") ? this.parseIdent() : node.imported;
  2530. this.checkLVal(node.local, true);
  2531. nodes.push(this.finishNode(node, "ImportSpecifier"));
  2532. }
  2533. return nodes;
  2534. };
  2535. },{"./state":13,"./tokentype":17,"./whitespace":19}],15:[function(_dereq_,module,exports){
  2536. "use strict";
  2537. var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } };
  2538. exports.__esModule = true;
  2539. // The algorithm used to determine whether a regexp can appear at a
  2540. // given point in the program is loosely based on sweet.js' approach.
  2541. // See https://github.com/mozilla/sweet.js/wiki/design
  2542. var Parser = _dereq_("./state").Parser;
  2543. var tt = _dereq_("./tokentype").types;
  2544. var lineBreak = _dereq_("./whitespace").lineBreak;
  2545. var TokContext = exports.TokContext = function TokContext(token, isExpr, preserveSpace, override) {
  2546. _classCallCheck(this, TokContext);
  2547. this.token = token;
  2548. this.isExpr = isExpr;
  2549. this.preserveSpace = preserveSpace;
  2550. this.override = override;
  2551. };
  2552. var types = {
  2553. b_stat: new TokContext("{", false),
  2554. b_expr: new TokContext("{", true),
  2555. b_tmpl: new TokContext("${", true),
  2556. p_stat: new TokContext("(", false),
  2557. p_expr: new TokContext("(", true),
  2558. q_tmpl: new TokContext("`", true, true, function (p) {
  2559. return p.readTmplToken();
  2560. }),
  2561. f_expr: new TokContext("function", true)
  2562. };
  2563. exports.types = types;
  2564. var pp = Parser.prototype;
  2565. pp.initialContext = function () {
  2566. return [types.b_stat];
  2567. };
  2568. pp.braceIsBlock = function (prevType) {
  2569. var parent = undefined;
  2570. if (prevType === tt.colon && (parent = this.curContext()).token == "{") return !parent.isExpr;
  2571. if (prevType === tt._return) return lineBreak.test(this.input.slice(this.lastTokEnd, this.start));
  2572. if (prevType === tt._else || prevType === tt.semi || prevType === tt.eof) return true;
  2573. if (prevType == tt.braceL) return this.curContext() === types.b_stat;
  2574. return !this.exprAllowed;
  2575. };
  2576. pp.updateContext = function (prevType) {
  2577. var update = undefined,
  2578. type = this.type;
  2579. if (type.keyword && prevType == tt.dot) this.exprAllowed = false;else if (update = type.updateContext) update.call(this, prevType);else this.exprAllowed = type.beforeExpr;
  2580. };
  2581. // Token-specific context update code
  2582. tt.parenR.updateContext = tt.braceR.updateContext = function () {
  2583. if (this.context.length == 1) {
  2584. this.exprAllowed = true;
  2585. return;
  2586. }
  2587. var out = this.context.pop();
  2588. if (out === types.b_stat && this.curContext() === types.f_expr) {
  2589. this.context.pop();
  2590. this.exprAllowed = false;
  2591. } else if (out === types.b_tmpl) {
  2592. this.exprAllowed = true;
  2593. } else {
  2594. this.exprAllowed = !out.isExpr;
  2595. }
  2596. };
  2597. tt.braceL.updateContext = function (prevType) {
  2598. this.context.push(this.braceIsBlock(prevType) ? types.b_stat : types.b_expr);
  2599. this.exprAllowed = true;
  2600. };
  2601. tt.dollarBraceL.updateContext = function () {
  2602. this.context.push(types.b_tmpl);
  2603. this.exprAllowed = true;
  2604. };
  2605. tt.parenL.updateContext = function (prevType) {
  2606. var statementParens = prevType === tt._if || prevType === tt._for || prevType === tt._with || prevType === tt._while;
  2607. this.context.push(statementParens ? types.p_stat : types.p_expr);
  2608. this.exprAllowed = true;
  2609. };
  2610. tt.incDec.updateContext = function () {};
  2611. tt._function.updateContext = function () {
  2612. if (this.curContext() !== types.b_stat) this.context.push(types.f_expr);
  2613. this.exprAllowed = false;
  2614. };
  2615. tt.backQuote.updateContext = function () {
  2616. if (this.curContext() === types.q_tmpl) this.context.pop();else this.context.push(types.q_tmpl);
  2617. this.exprAllowed = false;
  2618. };
  2619. // tokExprAllowed stays unchanged
  2620. },{"./state":13,"./tokentype":17,"./whitespace":19}],16:[function(_dereq_,module,exports){
  2621. "use strict";
  2622. var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } };
  2623. exports.__esModule = true;
  2624. var _identifier = _dereq_("./identifier");
  2625. var isIdentifierStart = _identifier.isIdentifierStart;
  2626. var isIdentifierChar = _identifier.isIdentifierChar;
  2627. var _tokentype = _dereq_("./tokentype");
  2628. var tt = _tokentype.types;
  2629. var keywordTypes = _tokentype.keywords;
  2630. var Parser = _dereq_("./state").Parser;
  2631. var SourceLocation = _dereq_("./location").SourceLocation;
  2632. var _whitespace = _dereq_("./whitespace");
  2633. var lineBreak = _whitespace.lineBreak;
  2634. var lineBreakG = _whitespace.lineBreakG;
  2635. var isNewLine = _whitespace.isNewLine;
  2636. var nonASCIIwhitespace = _whitespace.nonASCIIwhitespace;
  2637. // Object type used to represent tokens. Note that normally, tokens
  2638. // simply exist as properties on the parser object. This is only
  2639. // used for the onToken callback and the external tokenizer.
  2640. var Token = exports.Token = function Token(p) {
  2641. _classCallCheck(this, Token);
  2642. this.type = p.type;
  2643. this.value = p.value;
  2644. this.start = p.start;
  2645. this.end = p.end;
  2646. if (p.options.locations) this.loc = new SourceLocation(p, p.startLoc, p.endLoc);
  2647. if (p.options.ranges) this.range = [p.start, p.end];
  2648. };
  2649. // ## Tokenizer
  2650. var pp = Parser.prototype;
  2651. // Are we running under Rhino?
  2652. var isRhino = typeof Packages !== "undefined";
  2653. // Move to the next token
  2654. pp.next = function () {
  2655. if (this.options.onToken) this.options.onToken(new Token(this));
  2656. this.lastTokEnd = this.end;
  2657. this.lastTokStart = this.start;
  2658. this.lastTokEndLoc = this.endLoc;
  2659. this.lastTokStartLoc = this.startLoc;
  2660. this.nextToken();
  2661. };
  2662. pp.getToken = function () {
  2663. this.next();
  2664. return new Token(this);
  2665. };
  2666. // If we're in an ES6 environment, make parsers iterable
  2667. if (typeof Symbol !== "undefined") pp[Symbol.iterator] = function () {
  2668. var self = this;
  2669. return { next: function next() {
  2670. var token = self.getToken();
  2671. return {
  2672. done: token.type === tt.eof,
  2673. value: token
  2674. };
  2675. } };
  2676. };
  2677. // Toggle strict mode. Re-reads the next number or string to please
  2678. // pedantic tests (`"use strict"; 010;` should fail).
  2679. pp.setStrict = function (strict) {
  2680. this.strict = strict;
  2681. if (this.type !== tt.num && this.type !== tt.string) return;
  2682. this.pos = this.start;
  2683. if (this.options.locations) {
  2684. while (this.pos < this.lineStart) {
  2685. this.lineStart = this.input.lastIndexOf("\n", this.lineStart - 2) + 1;
  2686. --this.curLine;
  2687. }
  2688. }
  2689. this.nextToken();
  2690. };
  2691. pp.curContext = function () {
  2692. return this.context[this.context.length - 1];
  2693. };
  2694. // Read a single token, updating the parser object's token-related
  2695. // properties.
  2696. pp.nextToken = function () {
  2697. var curContext = this.curContext();
  2698. if (!curContext || !curContext.preserveSpace) this.skipSpace();
  2699. this.start = this.pos;
  2700. if (this.options.locations) this.startLoc = this.curPosition();
  2701. if (this.pos >= this.input.length) return this.finishToken(tt.eof);
  2702. if (curContext.override) return curContext.override(this);else this.readToken(this.fullCharCodeAtPos());
  2703. };
  2704. pp.readToken = function (code) {
  2705. // Identifier or keyword. '\uXXXX' sequences are allowed in
  2706. // identifiers, so '\' also dispatches to that.
  2707. if (isIdentifierStart(code, this.options.ecmaVersion >= 6) || code === 92 /* '\' */) return this.readWord();
  2708. return this.getTokenFromCode(code);
  2709. };
  2710. pp.fullCharCodeAtPos = function () {
  2711. var code = this.input.charCodeAt(this.pos);
  2712. if (code <= 55295 || code >= 57344) return code;
  2713. var next = this.input.charCodeAt(this.pos + 1);
  2714. return (code << 10) + next - 56613888;
  2715. };
  2716. pp.skipBlockComment = function () {
  2717. var startLoc = this.options.onComment && this.options.locations && this.curPosition();
  2718. var start = this.pos,
  2719. end = this.input.indexOf("*/", this.pos += 2);
  2720. if (end === -1) this.raise(this.pos - 2, "Unterminated comment");
  2721. this.pos = end + 2;
  2722. if (this.options.locations) {
  2723. lineBreakG.lastIndex = start;
  2724. var match = undefined;
  2725. while ((match = lineBreakG.exec(this.input)) && match.index < this.pos) {
  2726. ++this.curLine;
  2727. this.lineStart = match.index + match[0].length;
  2728. }
  2729. }
  2730. if (this.options.onComment) this.options.onComment(true, this.input.slice(start + 2, end), start, this.pos, startLoc, this.options.locations && this.curPosition());
  2731. };
  2732. pp.skipLineComment = function (startSkip) {
  2733. var start = this.pos;
  2734. var startLoc = this.options.onComment && this.options.locations && this.curPosition();
  2735. var ch = this.input.charCodeAt(this.pos += startSkip);
  2736. while (this.pos < this.input.length && ch !== 10 && ch !== 13 && ch !== 8232 && ch !== 8233) {
  2737. ++this.pos;
  2738. ch = this.input.charCodeAt(this.pos);
  2739. }
  2740. if (this.options.onComment) this.options.onComment(false, this.input.slice(start + startSkip, this.pos), start, this.pos, startLoc, this.options.locations && this.curPosition());
  2741. };
  2742. // Called at the start of the parse and after every token. Skips
  2743. // whitespace and comments, and.
  2744. pp.skipSpace = function () {
  2745. while (this.pos < this.input.length) {
  2746. var ch = this.input.charCodeAt(this.pos);
  2747. if (ch === 32) {
  2748. // ' '
  2749. ++this.pos;
  2750. } else if (ch === 13) {
  2751. ++this.pos;
  2752. var next = this.input.charCodeAt(this.pos);
  2753. if (next === 10) {
  2754. ++this.pos;
  2755. }
  2756. if (this.options.locations) {
  2757. ++this.curLine;
  2758. this.lineStart = this.pos;
  2759. }
  2760. } else if (ch === 10 || ch === 8232 || ch === 8233) {
  2761. ++this.pos;
  2762. if (this.options.locations) {
  2763. ++this.curLine;
  2764. this.lineStart = this.pos;
  2765. }
  2766. } else if (ch > 8 && ch < 14) {
  2767. ++this.pos;
  2768. } else if (ch === 47) {
  2769. // '/'
  2770. var next = this.input.charCodeAt(this.pos + 1);
  2771. if (next === 42) {
  2772. // '*'
  2773. this.skipBlockComment();
  2774. } else if (next === 47) {
  2775. // '/'
  2776. this.skipLineComment(2);
  2777. } else break;
  2778. } else if (ch === 160) {
  2779. // '\xa0'
  2780. ++this.pos;
  2781. } else if (ch >= 5760 && nonASCIIwhitespace.test(String.fromCharCode(ch))) {
  2782. ++this.pos;
  2783. } else {
  2784. break;
  2785. }
  2786. }
  2787. };
  2788. // Called at the end of every token. Sets `end`, `val`, and
  2789. // maintains `context` and `exprAllowed`, and skips the space after
  2790. // the token, so that the next one's `start` will point at the
  2791. // right position.
  2792. pp.finishToken = function (type, val) {
  2793. this.end = this.pos;
  2794. if (this.options.locations) this.endLoc = this.curPosition();
  2795. var prevType = this.type;
  2796. this.type = type;
  2797. this.value = val;
  2798. this.updateContext(prevType);
  2799. };
  2800. // ### Token reading
  2801. // This is the function that is called to fetch the next token. It
  2802. // is somewhat obscure, because it works in character codes rather
  2803. // than characters, and because operator parsing has been inlined
  2804. // into it.
  2805. //
  2806. // All in the name of speed.
  2807. //
  2808. pp.readToken_dot = function () {
  2809. var next = this.input.charCodeAt(this.pos + 1);
  2810. if (next >= 48 && next <= 57) return this.readNumber(true);
  2811. var next2 = this.input.charCodeAt(this.pos + 2);
  2812. if (this.options.ecmaVersion >= 6 && next === 46 && next2 === 46) {
  2813. // 46 = dot '.'
  2814. this.pos += 3;
  2815. return this.finishToken(tt.ellipsis);
  2816. } else {
  2817. ++this.pos;
  2818. return this.finishToken(tt.dot);
  2819. }
  2820. };
  2821. pp.readToken_slash = function () {
  2822. // '/'
  2823. var next = this.input.charCodeAt(this.pos + 1);
  2824. if (this.exprAllowed) {
  2825. ++this.pos;return this.readRegexp();
  2826. }
  2827. if (next === 61) return this.finishOp(tt.assign, 2);
  2828. return this.finishOp(tt.slash, 1);
  2829. };
  2830. pp.readToken_mult_modulo = function (code) {
  2831. // '%*'
  2832. var next = this.input.charCodeAt(this.pos + 1);
  2833. if (next === 61) return this.finishOp(tt.assign, 2);
  2834. return this.finishOp(code === 42 ? tt.star : tt.modulo, 1);
  2835. };
  2836. pp.readToken_pipe_amp = function (code) {
  2837. // '|&'
  2838. var next = this.input.charCodeAt(this.pos + 1);
  2839. if (next === code) return this.finishOp(code === 124 ? tt.logicalOR : tt.logicalAND, 2);
  2840. if (next === 61) return this.finishOp(tt.assign, 2);
  2841. return this.finishOp(code === 124 ? tt.bitwiseOR : tt.bitwiseAND, 1);
  2842. };
  2843. pp.readToken_caret = function () {
  2844. // '^'
  2845. var next = this.input.charCodeAt(this.pos + 1);
  2846. if (next === 61) return this.finishOp(tt.assign, 2);
  2847. return this.finishOp(tt.bitwiseXOR, 1);
  2848. };
  2849. pp.readToken_plus_min = function (code) {
  2850. // '+-'
  2851. var next = this.input.charCodeAt(this.pos + 1);
  2852. if (next === code) {
  2853. if (next == 45 && this.input.charCodeAt(this.pos + 2) == 62 && lineBreak.test(this.input.slice(this.lastTokEnd, this.pos))) {
  2854. // A `-->` line comment
  2855. this.skipLineComment(3);
  2856. this.skipSpace();
  2857. return this.nextToken();
  2858. }
  2859. return this.finishOp(tt.incDec, 2);
  2860. }
  2861. if (next === 61) return this.finishOp(tt.assign, 2);
  2862. return this.finishOp(tt.plusMin, 1);
  2863. };
  2864. pp.readToken_lt_gt = function (code) {
  2865. // '<>'
  2866. var next = this.input.charCodeAt(this.pos + 1);
  2867. var size = 1;
  2868. if (next === code) {
  2869. size = code === 62 && this.input.charCodeAt(this.pos + 2) === 62 ? 3 : 2;
  2870. if (this.input.charCodeAt(this.pos + size) === 61) return this.finishOp(tt.assign, size + 1);
  2871. return this.finishOp(tt.bitShift, size);
  2872. }
  2873. if (next == 33 && code == 60 && this.input.charCodeAt(this.pos + 2) == 45 && this.input.charCodeAt(this.pos + 3) == 45) {
  2874. if (this.inModule) this.unexpected();
  2875. // `<!--`, an XML-style comment that should be interpreted as a line comment
  2876. this.skipLineComment(4);
  2877. this.skipSpace();
  2878. return this.nextToken();
  2879. }
  2880. if (next === 61) size = this.input.charCodeAt(this.pos + 2) === 61 ? 3 : 2;
  2881. return this.finishOp(tt.relational, size);
  2882. };
  2883. pp.readToken_eq_excl = function (code) {
  2884. // '=!'
  2885. var next = this.input.charCodeAt(this.pos + 1);
  2886. if (next === 61) return this.finishOp(tt.equality, this.input.charCodeAt(this.pos + 2) === 61 ? 3 : 2);
  2887. if (code === 61 && next === 62 && this.options.ecmaVersion >= 6) {
  2888. // '=>'
  2889. this.pos += 2;
  2890. return this.finishToken(tt.arrow);
  2891. }
  2892. return this.finishOp(code === 61 ? tt.eq : tt.prefix, 1);
  2893. };
  2894. pp.getTokenFromCode = function (code) {
  2895. switch (code) {
  2896. // The interpretation of a dot depends on whether it is followed
  2897. // by a digit or another two dots.
  2898. case 46:
  2899. // '.'
  2900. return this.readToken_dot();
  2901. // Punctuation tokens.
  2902. case 40:
  2903. ++this.pos;return this.finishToken(tt.parenL);
  2904. case 41:
  2905. ++this.pos;return this.finishToken(tt.parenR);
  2906. case 59:
  2907. ++this.pos;return this.finishToken(tt.semi);
  2908. case 44:
  2909. ++this.pos;return this.finishToken(tt.comma);
  2910. case 91:
  2911. ++this.pos;return this.finishToken(tt.bracketL);
  2912. case 93:
  2913. ++this.pos;return this.finishToken(tt.bracketR);
  2914. case 123:
  2915. ++this.pos;return this.finishToken(tt.braceL);
  2916. case 125:
  2917. ++this.pos;return this.finishToken(tt.braceR);
  2918. case 58:
  2919. ++this.pos;return this.finishToken(tt.colon);
  2920. case 63:
  2921. ++this.pos;return this.finishToken(tt.question);
  2922. case 96:
  2923. // '`'
  2924. if (this.options.ecmaVersion < 6) break;
  2925. ++this.pos;
  2926. return this.finishToken(tt.backQuote);
  2927. case 48:
  2928. // '0'
  2929. var next = this.input.charCodeAt(this.pos + 1);
  2930. if (next === 120 || next === 88) return this.readRadixNumber(16); // '0x', '0X' - hex number
  2931. if (this.options.ecmaVersion >= 6) {
  2932. if (next === 111 || next === 79) return this.readRadixNumber(8); // '0o', '0O' - octal number
  2933. if (next === 98 || next === 66) return this.readRadixNumber(2); // '0b', '0B' - binary number
  2934. }
  2935. // Anything else beginning with a digit is an integer, octal
  2936. // number, or float.
  2937. case 49:case 50:case 51:case 52:case 53:case 54:case 55:case 56:case 57:
  2938. // 1-9
  2939. return this.readNumber(false);
  2940. // Quotes produce strings.
  2941. case 34:case 39:
  2942. // '"', "'"
  2943. return this.readString(code);
  2944. // Operators are parsed inline in tiny state machines. '=' (61) is
  2945. // often referred to. `finishOp` simply skips the amount of
  2946. // characters it is given as second argument, and returns a token
  2947. // of the type given by its first argument.
  2948. case 47:
  2949. // '/'
  2950. return this.readToken_slash();
  2951. case 37:case 42:
  2952. // '%*'
  2953. return this.readToken_mult_modulo(code);
  2954. case 124:case 38:
  2955. // '|&'
  2956. return this.readToken_pipe_amp(code);
  2957. case 94:
  2958. // '^'
  2959. return this.readToken_caret();
  2960. case 43:case 45:
  2961. // '+-'
  2962. return this.readToken_plus_min(code);
  2963. case 60:case 62:
  2964. // '<>'
  2965. return this.readToken_lt_gt(code);
  2966. case 61:case 33:
  2967. // '=!'
  2968. return this.readToken_eq_excl(code);
  2969. case 126:
  2970. // '~'
  2971. return this.finishOp(tt.prefix, 1);
  2972. }
  2973. this.raise(this.pos, "Unexpected character '" + codePointToString(code) + "'");
  2974. };
  2975. pp.finishOp = function (type, size) {
  2976. var str = this.input.slice(this.pos, this.pos + size);
  2977. this.pos += size;
  2978. return this.finishToken(type, str);
  2979. };
  2980. var regexpUnicodeSupport = false;
  2981. try {
  2982. new RegExp("￿", "u");regexpUnicodeSupport = true;
  2983. } catch (e) {}
  2984. // Parse a regular expression. Some context-awareness is necessary,
  2985. // since a '/' inside a '[]' set does not end the expression.
  2986. pp.readRegexp = function () {
  2987. var escaped = undefined,
  2988. inClass = undefined,
  2989. start = this.pos;
  2990. for (;;) {
  2991. if (this.pos >= this.input.length) this.raise(start, "Unterminated regular expression");
  2992. var ch = this.input.charAt(this.pos);
  2993. if (lineBreak.test(ch)) this.raise(start, "Unterminated regular expression");
  2994. if (!escaped) {
  2995. if (ch === "[") inClass = true;else if (ch === "]" && inClass) inClass = false;else if (ch === "/" && !inClass) break;
  2996. escaped = ch === "\\";
  2997. } else escaped = false;
  2998. ++this.pos;
  2999. }
  3000. var content = this.input.slice(start, this.pos);
  3001. ++this.pos;
  3002. // Need to use `readWord1` because '\uXXXX' sequences are allowed
  3003. // here (don't ask).
  3004. var mods = this.readWord1();
  3005. var tmp = content;
  3006. if (mods) {
  3007. var validFlags = /^[gmsiy]*$/;
  3008. if (this.options.ecmaVersion >= 6) validFlags = /^[gmsiyu]*$/;
  3009. if (!validFlags.test(mods)) this.raise(start, "Invalid regular expression flag");
  3010. if (mods.indexOf("u") >= 0 && !regexpUnicodeSupport) {
  3011. // Replace each astral symbol and every Unicode escape sequence that
  3012. // possibly represents an astral symbol or a paired surrogate with a
  3013. // single ASCII symbol to avoid throwing on regular expressions that
  3014. // are only valid in combination with the `/u` flag.
  3015. // Note: replacing with the ASCII symbol `x` might cause false
  3016. // negatives in unlikely scenarios. For example, `[\u{61}-b]` is a
  3017. // perfectly valid pattern that is equivalent to `[a-b]`, but it would
  3018. // be replaced by `[x-b]` which throws an error.
  3019. tmp = tmp.replace(/\\u([a-fA-F0-9]{4})|\\u\{([0-9a-fA-F]+)\}|[\uD800-\uDBFF][\uDC00-\uDFFF]/g, "x");
  3020. }
  3021. }
  3022. // Detect invalid regular expressions.
  3023. var value = null;
  3024. // Rhino's regular expression parser is flaky and throws uncatchable exceptions,
  3025. // so don't do detection if we are running under Rhino
  3026. if (!isRhino) {
  3027. try {
  3028. new RegExp(tmp);
  3029. } catch (e) {
  3030. if (e instanceof SyntaxError) this.raise(start, "Error parsing regular expression: " + e.message);
  3031. this.raise(e);
  3032. }
  3033. // Get a regular expression object for this pattern-flag pair, or `null` in
  3034. // case the current environment doesn't support the flags it uses.
  3035. try {
  3036. value = new RegExp(content, mods);
  3037. } catch (err) {}
  3038. }
  3039. return this.finishToken(tt.regexp, { pattern: content, flags: mods, value: value });
  3040. };
  3041. // Read an integer in the given radix. Return null if zero digits
  3042. // were read, the integer value otherwise. When `len` is given, this
  3043. // will return `null` unless the integer has exactly `len` digits.
  3044. pp.readInt = function (radix, len) {
  3045. var start = this.pos,
  3046. total = 0;
  3047. for (var i = 0, e = len == null ? Infinity : len; i < e; ++i) {
  3048. var code = this.input.charCodeAt(this.pos),
  3049. val = undefined;
  3050. if (code >= 97) val = code - 97 + 10; // a
  3051. else if (code >= 65) val = code - 65 + 10; // A
  3052. else if (code >= 48 && code <= 57) val = code - 48; // 0-9
  3053. else val = Infinity;
  3054. if (val >= radix) break;
  3055. ++this.pos;
  3056. total = total * radix + val;
  3057. }
  3058. if (this.pos === start || len != null && this.pos - start !== len) return null;
  3059. return total;
  3060. };
  3061. pp.readRadixNumber = function (radix) {
  3062. this.pos += 2; // 0x
  3063. var val = this.readInt(radix);
  3064. if (val == null) this.raise(this.start + 2, "Expected number in radix " + radix);
  3065. if (isIdentifierStart(this.fullCharCodeAtPos())) this.raise(this.pos, "Identifier directly after number");
  3066. return this.finishToken(tt.num, val);
  3067. };
  3068. // Read an integer, octal integer, or floating-point number.
  3069. pp.readNumber = function (startsWithDot) {
  3070. var start = this.pos,
  3071. isFloat = false,
  3072. octal = this.input.charCodeAt(this.pos) === 48;
  3073. if (!startsWithDot && this.readInt(10) === null) this.raise(start, "Invalid number");
  3074. if (this.input.charCodeAt(this.pos) === 46) {
  3075. ++this.pos;
  3076. this.readInt(10);
  3077. isFloat = true;
  3078. }
  3079. var next = this.input.charCodeAt(this.pos);
  3080. if (next === 69 || next === 101) {
  3081. // 'eE'
  3082. next = this.input.charCodeAt(++this.pos);
  3083. if (next === 43 || next === 45) ++this.pos; // '+-'
  3084. if (this.readInt(10) === null) this.raise(start, "Invalid number");
  3085. isFloat = true;
  3086. }
  3087. if (isIdentifierStart(this.fullCharCodeAtPos())) this.raise(this.pos, "Identifier directly after number");
  3088. var str = this.input.slice(start, this.pos),
  3089. val = undefined;
  3090. if (isFloat) val = parseFloat(str);else if (!octal || str.length === 1) val = parseInt(str, 10);else if (/[89]/.test(str) || this.strict) this.raise(start, "Invalid number");else val = parseInt(str, 8);
  3091. return this.finishToken(tt.num, val);
  3092. };
  3093. // Read a string value, interpreting backslash-escapes.
  3094. pp.readCodePoint = function () {
  3095. var ch = this.input.charCodeAt(this.pos),
  3096. code = undefined;
  3097. if (ch === 123) {
  3098. if (this.options.ecmaVersion < 6) this.unexpected();
  3099. ++this.pos;
  3100. code = this.readHexChar(this.input.indexOf("}", this.pos) - this.pos);
  3101. ++this.pos;
  3102. if (code > 1114111) this.unexpected();
  3103. } else {
  3104. code = this.readHexChar(4);
  3105. }
  3106. return code;
  3107. };
  3108. function codePointToString(code) {
  3109. // UTF-16 Decoding
  3110. if (code <= 65535) {
  3111. return String.fromCharCode(code);
  3112. }return String.fromCharCode((code - 65536 >> 10) + 55296, (code - 65536 & 1023) + 56320);
  3113. }
  3114. pp.readString = function (quote) {
  3115. var out = "",
  3116. chunkStart = ++this.pos;
  3117. for (;;) {
  3118. if (this.pos >= this.input.length) this.raise(this.start, "Unterminated string constant");
  3119. var ch = this.input.charCodeAt(this.pos);
  3120. if (ch === quote) break;
  3121. if (ch === 92) {
  3122. // '\'
  3123. out += this.input.slice(chunkStart, this.pos);
  3124. out += this.readEscapedChar();
  3125. chunkStart = this.pos;
  3126. } else {
  3127. if (isNewLine(ch)) this.raise(this.start, "Unterminated string constant");
  3128. ++this.pos;
  3129. }
  3130. }
  3131. out += this.input.slice(chunkStart, this.pos++);
  3132. return this.finishToken(tt.string, out);
  3133. };
  3134. // Reads template string tokens.
  3135. pp.readTmplToken = function () {
  3136. var out = "",
  3137. chunkStart = this.pos;
  3138. for (;;) {
  3139. if (this.pos >= this.input.length) this.raise(this.start, "Unterminated template");
  3140. var ch = this.input.charCodeAt(this.pos);
  3141. if (ch === 96 || ch === 36 && this.input.charCodeAt(this.pos + 1) === 123) {
  3142. // '`', '${'
  3143. if (this.pos === this.start && this.type === tt.template) {
  3144. if (ch === 36) {
  3145. this.pos += 2;
  3146. return this.finishToken(tt.dollarBraceL);
  3147. } else {
  3148. ++this.pos;
  3149. return this.finishToken(tt.backQuote);
  3150. }
  3151. }
  3152. out += this.input.slice(chunkStart, this.pos);
  3153. return this.finishToken(tt.template, out);
  3154. }
  3155. if (ch === 92) {
  3156. // '\'
  3157. out += this.input.slice(chunkStart, this.pos);
  3158. out += this.readEscapedChar();
  3159. chunkStart = this.pos;
  3160. } else if (isNewLine(ch)) {
  3161. out += this.input.slice(chunkStart, this.pos);
  3162. ++this.pos;
  3163. if (ch === 13 && this.input.charCodeAt(this.pos) === 10) {
  3164. ++this.pos;
  3165. out += "\n";
  3166. } else {
  3167. out += String.fromCharCode(ch);
  3168. }
  3169. if (this.options.locations) {
  3170. ++this.curLine;
  3171. this.lineStart = this.pos;
  3172. }
  3173. chunkStart = this.pos;
  3174. } else {
  3175. ++this.pos;
  3176. }
  3177. }
  3178. };
  3179. // Used to read escaped characters
  3180. pp.readEscapedChar = function () {
  3181. var ch = this.input.charCodeAt(++this.pos);
  3182. var octal = /^[0-7]+/.exec(this.input.slice(this.pos, this.pos + 3));
  3183. if (octal) octal = octal[0];
  3184. while (octal && parseInt(octal, 8) > 255) octal = octal.slice(0, -1);
  3185. if (octal === "0") octal = null;
  3186. ++this.pos;
  3187. if (octal) {
  3188. if (this.strict) this.raise(this.pos - 2, "Octal literal in strict mode");
  3189. this.pos += octal.length - 1;
  3190. return String.fromCharCode(parseInt(octal, 8));
  3191. } else {
  3192. switch (ch) {
  3193. case 110:
  3194. return "\n"; // 'n' -> '\n'
  3195. case 114:
  3196. return "\r"; // 'r' -> '\r'
  3197. case 120:
  3198. return String.fromCharCode(this.readHexChar(2)); // 'x'
  3199. case 117:
  3200. return codePointToString(this.readCodePoint()); // 'u'
  3201. case 116:
  3202. return "\t"; // 't' -> '\t'
  3203. case 98:
  3204. return "\b"; // 'b' -> '\b'
  3205. case 118:
  3206. return "\u000b"; // 'v' -> '\u000b'
  3207. case 102:
  3208. return "\f"; // 'f' -> '\f'
  3209. case 48:
  3210. return "\u0000"; // 0 -> '\0'
  3211. case 13:
  3212. if (this.input.charCodeAt(this.pos) === 10) ++this.pos; // '\r\n'
  3213. case 10:
  3214. // ' \n'
  3215. if (this.options.locations) {
  3216. this.lineStart = this.pos;++this.curLine;
  3217. }
  3218. return "";
  3219. default:
  3220. return String.fromCharCode(ch);
  3221. }
  3222. }
  3223. };
  3224. // Used to read character escape sequences ('\x', '\u', '\U').
  3225. pp.readHexChar = function (len) {
  3226. var n = this.readInt(16, len);
  3227. if (n === null) this.raise(this.start, "Bad character escape sequence");
  3228. return n;
  3229. };
  3230. // Used to signal to callers of `readWord1` whether the word
  3231. // contained any escape sequences. This is needed because words with
  3232. // escape sequences must not be interpreted as keywords.
  3233. var containsEsc;
  3234. // Read an identifier, and return it as a string. Sets `containsEsc`
  3235. // to whether the word contained a '\u' escape.
  3236. //
  3237. // Incrementally adds only escaped chars, adding other chunks as-is
  3238. // as a micro-optimization.
  3239. pp.readWord1 = function () {
  3240. containsEsc = false;
  3241. var word = "",
  3242. first = true,
  3243. chunkStart = this.pos;
  3244. var astral = this.options.ecmaVersion >= 6;
  3245. while (this.pos < this.input.length) {
  3246. var ch = this.fullCharCodeAtPos();
  3247. if (isIdentifierChar(ch, astral)) {
  3248. this.pos += ch <= 65535 ? 1 : 2;
  3249. } else if (ch === 92) {
  3250. // "\"
  3251. containsEsc = true;
  3252. word += this.input.slice(chunkStart, this.pos);
  3253. var escStart = this.pos;
  3254. if (this.input.charCodeAt(++this.pos) != 117) // "u"
  3255. this.raise(this.pos, "Expecting Unicode escape sequence \\uXXXX");
  3256. ++this.pos;
  3257. var esc = this.readCodePoint();
  3258. if (!(first ? isIdentifierStart : isIdentifierChar)(esc, astral)) this.raise(escStart, "Invalid Unicode escape");
  3259. word += codePointToString(esc);
  3260. chunkStart = this.pos;
  3261. } else {
  3262. break;
  3263. }
  3264. first = false;
  3265. }
  3266. return word + this.input.slice(chunkStart, this.pos);
  3267. };
  3268. // Read an identifier or keyword token. Will check for reserved
  3269. // words when necessary.
  3270. pp.readWord = function () {
  3271. var word = this.readWord1();
  3272. var type = tt.name;
  3273. if ((this.options.ecmaVersion >= 6 || !containsEsc) && this.isKeyword(word)) type = keywordTypes[word];
  3274. return this.finishToken(type, word);
  3275. };
  3276. },{"./identifier":7,"./location":8,"./state":13,"./tokentype":17,"./whitespace":19}],17:[function(_dereq_,module,exports){
  3277. "use strict";
  3278. var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } };
  3279. exports.__esModule = true;
  3280. // ## Token types
  3281. // The assignment of fine-grained, information-carrying type objects
  3282. // allows the tokenizer to store the information it has about a
  3283. // token in a way that is very cheap for the parser to look up.
  3284. // All token type variables start with an underscore, to make them
  3285. // easy to recognize.
  3286. // The `beforeExpr` property is used to disambiguate between regular
  3287. // expressions and divisions. It is set on all token types that can
  3288. // be followed by an expression (thus, a slash after them would be a
  3289. // regular expression).
  3290. //
  3291. // `isLoop` marks a keyword as starting a loop, which is important
  3292. // to know when parsing a label, in order to allow or disallow
  3293. // continue jumps to that label.
  3294. var TokenType = exports.TokenType = function TokenType(label) {
  3295. var conf = arguments[1] === undefined ? {} : arguments[1];
  3296. _classCallCheck(this, TokenType);
  3297. this.label = label;
  3298. this.keyword = conf.keyword;
  3299. this.beforeExpr = !!conf.beforeExpr;
  3300. this.startsExpr = !!conf.startsExpr;
  3301. this.isLoop = !!conf.isLoop;
  3302. this.isAssign = !!conf.isAssign;
  3303. this.prefix = !!conf.prefix;
  3304. this.postfix = !!conf.postfix;
  3305. this.binop = conf.binop || null;
  3306. this.updateContext = null;
  3307. };
  3308. function binop(name, prec) {
  3309. return new TokenType(name, { beforeExpr: true, binop: prec });
  3310. }
  3311. var beforeExpr = { beforeExpr: true },
  3312. startsExpr = { startsExpr: true };
  3313. var types = {
  3314. num: new TokenType("num", startsExpr),
  3315. regexp: new TokenType("regexp", startsExpr),
  3316. string: new TokenType("string", startsExpr),
  3317. name: new TokenType("name", startsExpr),
  3318. eof: new TokenType("eof"),
  3319. // Punctuation token types.
  3320. bracketL: new TokenType("[", { beforeExpr: true, startsExpr: true }),
  3321. bracketR: new TokenType("]"),
  3322. braceL: new TokenType("{", { beforeExpr: true, startsExpr: true }),
  3323. braceR: new TokenType("}"),
  3324. parenL: new TokenType("(", { beforeExpr: true, startsExpr: true }),
  3325. parenR: new TokenType(")"),
  3326. comma: new TokenType(",", beforeExpr),
  3327. semi: new TokenType(";", beforeExpr),
  3328. colon: new TokenType(":", beforeExpr),
  3329. dot: new TokenType("."),
  3330. question: new TokenType("?", beforeExpr),
  3331. arrow: new TokenType("=>", beforeExpr),
  3332. template: new TokenType("template"),
  3333. ellipsis: new TokenType("...", beforeExpr),
  3334. backQuote: new TokenType("`", startsExpr),
  3335. dollarBraceL: new TokenType("${", { beforeExpr: true, startsExpr: true }),
  3336. // Operators. These carry several kinds of properties to help the
  3337. // parser use them properly (the presence of these properties is
  3338. // what categorizes them as operators).
  3339. //
  3340. // `binop`, when present, specifies that this operator is a binary
  3341. // operator, and will refer to its precedence.
  3342. //
  3343. // `prefix` and `postfix` mark the operator as a prefix or postfix
  3344. // unary operator.
  3345. //
  3346. // `isAssign` marks all of `=`, `+=`, `-=` etcetera, which act as
  3347. // binary operators with a very low precedence, that should result
  3348. // in AssignmentExpression nodes.
  3349. eq: new TokenType("=", { beforeExpr: true, isAssign: true }),
  3350. assign: new TokenType("_=", { beforeExpr: true, isAssign: true }),
  3351. incDec: new TokenType("++/--", { prefix: true, postfix: true, startsExpr: true }),
  3352. prefix: new TokenType("prefix", { beforeExpr: true, prefix: true, startsExpr: true }),
  3353. logicalOR: binop("||", 1),
  3354. logicalAND: binop("&&", 2),
  3355. bitwiseOR: binop("|", 3),
  3356. bitwiseXOR: binop("^", 4),
  3357. bitwiseAND: binop("&", 5),
  3358. equality: binop("==/!=", 6),
  3359. relational: binop("</>", 7),
  3360. bitShift: binop("<</>>", 8),
  3361. plusMin: new TokenType("+/-", { beforeExpr: true, binop: 9, prefix: true, startsExpr: true }),
  3362. modulo: binop("%", 10),
  3363. star: binop("*", 10),
  3364. slash: binop("/", 10)
  3365. };
  3366. exports.types = types;
  3367. // Map keyword names to token types.
  3368. var keywords = {};
  3369. exports.keywords = keywords;
  3370. // Succinct definitions of keyword token types
  3371. function kw(name) {
  3372. var options = arguments[1] === undefined ? {} : arguments[1];
  3373. options.keyword = name;
  3374. keywords[name] = types["_" + name] = new TokenType(name, options);
  3375. }
  3376. kw("break");
  3377. kw("case", beforeExpr);
  3378. kw("catch");
  3379. kw("continue");
  3380. kw("debugger");
  3381. kw("default");
  3382. kw("do", { isLoop: true });
  3383. kw("else", beforeExpr);
  3384. kw("finally");
  3385. kw("for", { isLoop: true });
  3386. kw("function", startsExpr);
  3387. kw("if");
  3388. kw("return", beforeExpr);
  3389. kw("switch");
  3390. kw("throw", beforeExpr);
  3391. kw("try");
  3392. kw("var");
  3393. kw("let");
  3394. kw("const");
  3395. kw("while", { isLoop: true });
  3396. kw("with");
  3397. kw("new", { beforeExpr: true, startsExpr: true });
  3398. kw("this", startsExpr);
  3399. kw("super", startsExpr);
  3400. kw("class");
  3401. kw("extends", beforeExpr);
  3402. kw("export");
  3403. kw("import");
  3404. kw("yield", { beforeExpr: true, startsExpr: true });
  3405. kw("null", startsExpr);
  3406. kw("true", startsExpr);
  3407. kw("false", startsExpr);
  3408. kw("in", { beforeExpr: true, binop: 7 });
  3409. kw("instanceof", { beforeExpr: true, binop: 7 });
  3410. kw("typeof", { beforeExpr: true, prefix: true, startsExpr: true });
  3411. kw("void", { beforeExpr: true, prefix: true, startsExpr: true });
  3412. kw("delete", { beforeExpr: true, prefix: true, startsExpr: true });
  3413. },{}],18:[function(_dereq_,module,exports){
  3414. "use strict";
  3415. exports.isArray = isArray;
  3416. // Checks if an object has a property.
  3417. exports.has = has;
  3418. exports.__esModule = true;
  3419. function isArray(obj) {
  3420. return Object.prototype.toString.call(obj) === "[object Array]";
  3421. }
  3422. function has(obj, propName) {
  3423. return Object.prototype.hasOwnProperty.call(obj, propName);
  3424. }
  3425. },{}],19:[function(_dereq_,module,exports){
  3426. "use strict";
  3427. exports.isNewLine = isNewLine;
  3428. exports.__esModule = true;
  3429. // Matches a whole line break (where CRLF is considered a single
  3430. // line break). Used to count lines.
  3431. var lineBreak = /\r\n?|\n|\u2028|\u2029/;
  3432. exports.lineBreak = lineBreak;
  3433. var lineBreakG = new RegExp(lineBreak.source, "g");
  3434. exports.lineBreakG = lineBreakG;
  3435. function isNewLine(code) {
  3436. return code === 10 || code === 13 || code === 8232 || code == 8233;
  3437. }
  3438. var nonASCIIwhitespace = /[\u1680\u180e\u2000-\u200a\u202f\u205f\u3000\ufeff]/;
  3439. exports.nonASCIIwhitespace = nonASCIIwhitespace;
  3440. },{}]},{},[1])(1)
  3441. });
  3442. })(null);
  3443. (function(module){
  3444. 'use strict';
  3445. var toStr = Object.prototype.toString;
  3446. module.exports = function isArguments(value) {
  3447. var str = toStr.call(value);
  3448. var isArgs = str === '[object Arguments]';
  3449. if (!isArgs) {
  3450. isArgs = str !== '[object Array]' &&
  3451. value !== null &&
  3452. typeof value === 'object' &&
  3453. typeof value.length === 'number' &&
  3454. value.length >= 0 &&
  3455. toStr.call(value.callee) === '[object Function]';
  3456. }
  3457. return isArgs;
  3458. };
  3459. window.isArguments = module.exports;
  3460. })({exports: {}});
  3461. (function(module){
  3462. var hasOwn = Object.prototype.hasOwnProperty;
  3463. var toString = Object.prototype.toString;
  3464. module.exports = function forEach (obj, fn, ctx) {
  3465. if (toString.call(fn) !== '[object Function]') {
  3466. throw new TypeError('iterator must be a function');
  3467. }
  3468. var l = obj.length;
  3469. if (l === +l) {
  3470. for (var i = 0; i < l; i++) {
  3471. fn.call(ctx, obj[i], i, obj);
  3472. }
  3473. } else {
  3474. for (var k in obj) {
  3475. if (hasOwn.call(obj, k)) {
  3476. fn.call(ctx, obj[k], k, obj);
  3477. }
  3478. }
  3479. }
  3480. };
  3481. window.forEach = module.exports;
  3482. })({exports: {}});
  3483. (function(module){
  3484. module.exports = Array.isArray || function (arr) {
  3485. return Object.prototype.toString.call(arr) == '[object Array]';
  3486. };
  3487. window.isArray = module.exports;
  3488. })({exports: {}});
  3489. (function(require,module){
  3490. 'use strict';
  3491. // modified from https://github.com/es-shims/es5-shim
  3492. var has = Object.prototype.hasOwnProperty;
  3493. var toStr = Object.prototype.toString;
  3494. var slice = Array.prototype.slice;
  3495. var isArgs = require('./isArguments');
  3496. var hasDontEnumBug = !({ toString: null }).propertyIsEnumerable('toString');
  3497. var hasProtoEnumBug = function () {}.propertyIsEnumerable('prototype');
  3498. var dontEnums = [
  3499. 'toString',
  3500. 'toLocaleString',
  3501. 'valueOf',
  3502. 'hasOwnProperty',
  3503. 'isPrototypeOf',
  3504. 'propertyIsEnumerable',
  3505. 'constructor'
  3506. ];
  3507. var equalsConstructorPrototype = function (o) {
  3508. var ctor = o.constructor;
  3509. return ctor && ctor.prototype === o;
  3510. };
  3511. var blacklistedKeys = {
  3512. $console: true,
  3513. $frame: true,
  3514. $frameElement: true,
  3515. $frames: true,
  3516. $parent: true,
  3517. $self: true,
  3518. $webkitIndexedDB: true,
  3519. $webkitStorageInfo: true,
  3520. $window: true
  3521. };
  3522. var hasAutomationEqualityBug = (function () {
  3523. /* global window */
  3524. if (typeof window === 'undefined') { return false; }
  3525. for (var k in window) {
  3526. try {
  3527. if (!blacklistedKeys['$' + k] && has.call(window, k) && window[k] !== null && typeof window[k] === 'object') {
  3528. try {
  3529. equalsConstructorPrototype(window[k]);
  3530. } catch (e) {
  3531. return true;
  3532. }
  3533. }
  3534. } catch (e) {
  3535. return true;
  3536. }
  3537. }
  3538. return false;
  3539. }());
  3540. var equalsConstructorPrototypeIfNotBuggy = function (o) {
  3541. /* global window */
  3542. if (typeof window === 'undefined' || !hasAutomationEqualityBug) {
  3543. return equalsConstructorPrototype(o);
  3544. }
  3545. try {
  3546. return equalsConstructorPrototype(o);
  3547. } catch (e) {
  3548. return false;
  3549. }
  3550. };
  3551. var keysShim = function keys(object) {
  3552. var isObject = object !== null && typeof object === 'object';
  3553. var isFunction = toStr.call(object) === '[object Function]';
  3554. var isArguments = isArgs(object);
  3555. var isString = isObject && toStr.call(object) === '[object String]';
  3556. var theKeys = [];
  3557. if (!isObject && !isFunction && !isArguments) {
  3558. throw new TypeError('Object.keys called on a non-object');
  3559. }
  3560. var skipProto = hasProtoEnumBug && isFunction;
  3561. if (isString && object.length > 0 && !has.call(object, 0)) {
  3562. for (var i = 0; i < object.length; ++i) {
  3563. theKeys.push(String(i));
  3564. }
  3565. }
  3566. if (isArguments && object.length > 0) {
  3567. for (var j = 0; j < object.length; ++j) {
  3568. theKeys.push(String(j));
  3569. }
  3570. } else {
  3571. for (var name in object) {
  3572. if (!(skipProto && name === 'prototype') && has.call(object, name)) {
  3573. theKeys.push(String(name));
  3574. }
  3575. }
  3576. }
  3577. if (hasDontEnumBug) {
  3578. var skipConstructor = equalsConstructorPrototypeIfNotBuggy(object);
  3579. for (var k = 0; k < dontEnums.length; ++k) {
  3580. if (!(skipConstructor && dontEnums[k] === 'constructor') && has.call(object, dontEnums[k])) {
  3581. theKeys.push(dontEnums[k]);
  3582. }
  3583. }
  3584. }
  3585. return theKeys;
  3586. };
  3587. keysShim.shim = function shimObjectKeys() {
  3588. if (Object.keys) {
  3589. var keysWorksWithArguments = (function () {
  3590. // Safari 5.0 bug
  3591. return (Object.keys(arguments) || '').length === 2;
  3592. }(1, 2));
  3593. if (!keysWorksWithArguments) {
  3594. var originalKeys = Object.keys;
  3595. Object.keys = function keys(object) {
  3596. if (isArgs(object)) {
  3597. return originalKeys(slice.call(object));
  3598. } else {
  3599. return originalKeys(object);
  3600. }
  3601. };
  3602. }
  3603. } else {
  3604. Object.keys = keysShim;
  3605. }
  3606. return Object.keys || keysShim;
  3607. };
  3608. module.exports = keysShim;
  3609. window.objectKeys = module.exports;
  3610. })(function(){return isArguments;},{exports: {}});
  3611. /*!
  3612. * falafel (c) James Halliday / MIT License
  3613. * https://github.com/substack/node-falafel
  3614. */
  3615. (function(require,module){
  3616. var parse = require('acorn').parse;
  3617. var isArray = require('isarray');
  3618. var objectKeys = require('object-keys');
  3619. var forEach = require('foreach');
  3620. module.exports = function (src, opts, fn) {
  3621. if (typeof opts === 'function') {
  3622. fn = opts;
  3623. opts = {};
  3624. }
  3625. if (src && typeof src === 'object' && src.constructor.name === 'Buffer') {
  3626. src = src.toString();
  3627. }
  3628. else if (src && typeof src === 'object') {
  3629. opts = src;
  3630. src = opts.source;
  3631. delete opts.source;
  3632. }
  3633. src = src === undefined ? opts.source : src;
  3634. if (typeof src !== 'string') src = String(src);
  3635. if (opts.parser) parse = opts.parser.parse;
  3636. var ast = parse(src, opts);
  3637. var result = {
  3638. chunks : src.split(''),
  3639. toString : function () { return result.chunks.join('') },
  3640. inspect : function () { return result.toString() }
  3641. };
  3642. var index = 0;
  3643. (function walk (node, parent) {
  3644. insertHelpers(node, parent, result.chunks);
  3645. forEach(objectKeys(node), function (key) {
  3646. if (key === 'parent') return;
  3647. var child = node[key];
  3648. if (isArray(child)) {
  3649. forEach(child, function (c) {
  3650. if (c && typeof c.type === 'string') {
  3651. walk(c, node);
  3652. }
  3653. });
  3654. }
  3655. else if (child && typeof child.type === 'string') {
  3656. walk(child, node);
  3657. }
  3658. });
  3659. fn(node);
  3660. })(ast, undefined);
  3661. return result;
  3662. };
  3663. function insertHelpers (node, parent, chunks) {
  3664. node.parent = parent;
  3665. node.source = function () {
  3666. return chunks.slice(node.start, node.end).join('');
  3667. };
  3668. if (node.update && typeof node.update === 'object') {
  3669. var prev = node.update;
  3670. forEach(objectKeys(prev), function (key) {
  3671. update[key] = prev[key];
  3672. });
  3673. node.update = update;
  3674. }
  3675. else {
  3676. node.update = update;
  3677. }
  3678. function update (s) {
  3679. chunks[node.start] = s;
  3680. for (var i = node.start + 1; i < node.end; i++) {
  3681. chunks[i] = '';
  3682. }
  3683. }
  3684. }
  3685. window.falafel = module.exports;})(function(moduleName){switch(moduleName){case "acorn":
  3686. return {parse: acorn.parse};
  3687. case "object-keys":
  3688. return objectKeys;
  3689. case "foreach":
  3690. return forEach;
  3691. case "isarray":
  3692. return isArray;}},{exports: {}});
  3693. var inBrowser = typeof window !== 'undefined' && this === window;
  3694. var parseAndModify = (inBrowser ? window.falafel : require("falafel"));
  3695. (inBrowser ? window : exports).blanket = (function(){
  3696. var linesToAddTracking = [
  3697. "ExpressionStatement",
  3698. "BreakStatement" ,
  3699. "ContinueStatement" ,
  3700. "VariableDeclaration",
  3701. "ReturnStatement" ,
  3702. "ThrowStatement" ,
  3703. "TryStatement" ,
  3704. "FunctionDeclaration" ,
  3705. "IfStatement" ,
  3706. "WhileStatement" ,
  3707. "DoWhileStatement" ,
  3708. "ForStatement" ,
  3709. "ForInStatement" ,
  3710. "SwitchStatement" ,
  3711. "WithStatement"
  3712. ],
  3713. linesToAddBrackets = [
  3714. "IfStatement" ,
  3715. "WhileStatement" ,
  3716. "DoWhileStatement" ,
  3717. "ForStatement" ,
  3718. "ForInStatement" ,
  3719. "WithStatement"
  3720. ],
  3721. __blanket,
  3722. copynumber = Math.floor(Math.random()*1000),
  3723. coverageInfo = {},options = {
  3724. reporter: null,
  3725. adapter:null,
  3726. filter: null,
  3727. customVariable: null,
  3728. loader: null,
  3729. ignoreScriptError: false,
  3730. existingRequireJS:false,
  3731. autoStart: false,
  3732. timeout: 180,
  3733. ignoreCors: false,
  3734. branchTracking: false,
  3735. sourceURL: false,
  3736. debug:false,
  3737. engineOnly:false,
  3738. testReadyCallback:null,
  3739. commonJS:false,
  3740. instrumentCache:false,
  3741. modulePattern: null,
  3742. ecmaVersion: 5
  3743. };
  3744. if (inBrowser && typeof window.blanket !== 'undefined'){
  3745. __blanket = window.blanket.noConflict();
  3746. }
  3747. _blanket = {
  3748. noConflict: function(){
  3749. if (__blanket){
  3750. return __blanket;
  3751. }
  3752. return _blanket;
  3753. },
  3754. _getCopyNumber: function(){
  3755. //internal method
  3756. //for differentiating between instances
  3757. return copynumber;
  3758. },
  3759. extend: function(obj) {
  3760. //borrowed from underscore
  3761. _blanket._extend(_blanket,obj);
  3762. },
  3763. _extend: function(dest,source){
  3764. if (source) {
  3765. for (var prop in source) {
  3766. if ( dest[prop] instanceof Object && typeof dest[prop] !== "function"){
  3767. _blanket._extend(dest[prop],source[prop]);
  3768. }else{
  3769. dest[prop] = source[prop];
  3770. }
  3771. }
  3772. }
  3773. },
  3774. getCovVar: function(){
  3775. var opt = _blanket.options("customVariable");
  3776. if (opt){
  3777. if (_blanket.options("debug")) {console.log("BLANKET-Using custom tracking variable:",opt);}
  3778. return inBrowser ? "window."+opt : opt;
  3779. }
  3780. return inBrowser ? "window._$blanket" : "_$jscoverage";
  3781. },
  3782. options: function(key,value){
  3783. if (typeof key !== "string"){
  3784. _blanket._extend(options,key);
  3785. }else if (typeof value === 'undefined'){
  3786. return options[key];
  3787. }else{
  3788. options[key]=value;
  3789. }
  3790. },
  3791. // instrument the file synchronously
  3792. // `next` is optional callback which will be called
  3793. // with instrumented code when present
  3794. instrumentSync: function(config, next){
  3795. //check instrumented hash table,
  3796. //return instrumented code if available.
  3797. var inFile = config.inputFile,
  3798. inFileName = config.inputFileName;
  3799. //check instrument cache
  3800. if (_blanket.options("instrumentCache") && sessionStorage && sessionStorage.getItem("blanket_instrument_store-"+inFileName)){
  3801. if (_blanket.options("debug")) {console.log("BLANKET-Reading instrumentation from cache: ",inFileName);}
  3802. if (next) {
  3803. next(sessionStorage.getItem("blanket_instrument_store-"+inFileName));
  3804. } else {
  3805. return(sessionStorage.getItem("blanket_instrument_store-"+inFileName));
  3806. }
  3807. }else{
  3808. var sourceArray = _blanket._prepareSource(inFile);
  3809. _blanket._trackingArraySetup=[];
  3810. //remove shebang
  3811. inFile = inFile.replace(/^\#\!.*/, "");
  3812. var instrumented = parseAndModify(inFile,{locations:true,comment:true,ecmaVersion:_blanket.options("ecmaVersion")}, _blanket._addTracking(inFileName));
  3813. instrumented = _blanket._trackingSetup(inFileName,sourceArray)+instrumented;
  3814. if (_blanket.options("sourceURL")){
  3815. instrumented += "\n//@ sourceURL="+inFileName.replace("http://","");
  3816. }
  3817. if (_blanket.options("debug")) {console.log("BLANKET-Instrumented file: ",inFileName);}
  3818. if (_blanket.options("instrumentCache") && sessionStorage){
  3819. if (_blanket.options("debug")) {console.log("BLANKET-Saving instrumentation to cache: ",inFileName);}
  3820. sessionStorage.setItem("blanket_instrument_store-"+inFileName,instrumented);
  3821. }
  3822. if (next) {
  3823. next(instrumented);
  3824. } else {
  3825. return(instrumented);
  3826. }
  3827. }
  3828. },
  3829. instrument: function(config, next){
  3830. _blanket.instrumentSync(config, next);
  3831. },
  3832. _trackingArraySetup: [],
  3833. _branchingArraySetup: [],
  3834. _useStrictMode: false,
  3835. _prepareSource: function(source){
  3836. return source.replace(/\\/g,"\\\\").replace(/'/g,"\\'").replace(/(\r\n|\n|\r)/gm,"\n").split('\n');
  3837. },
  3838. _trackingSetup: function(filename,sourceArray){
  3839. var branches = _blanket.options("branchTracking");
  3840. var sourceString = sourceArray.join("',\n'");
  3841. var intro = "";
  3842. var covVar = _blanket.getCovVar();
  3843. if(_blanket._useStrictMode) {
  3844. intro += "'use strict';\n";
  3845. }
  3846. intro += "if (typeof "+covVar+" === 'undefined') "+covVar+" = {};\n";
  3847. if (branches){
  3848. intro += "var _$branchFcn=function(f,l,c,r){ ";
  3849. intro += "if (!!r) { ";
  3850. intro += covVar+"[f].branchData[l][c][0] = "+covVar+"[f].branchData[l][c][0] || [];";
  3851. intro += covVar+"[f].branchData[l][c][0].push(r); }";
  3852. intro += "else { ";
  3853. intro += covVar+"[f].branchData[l][c][1] = "+covVar+"[f].branchData[l][c][1] || [];";
  3854. intro += covVar+"[f].branchData[l][c][1].push(r); }";
  3855. intro += "return r;};\n";
  3856. }
  3857. intro += "if (typeof "+covVar+"['"+filename+"'] === 'undefined'){";
  3858. intro += covVar+"['"+filename+"']=[];\n";
  3859. if (branches){
  3860. intro += covVar+"['"+filename+"'].branchData=[];\n";
  3861. }
  3862. intro += covVar+"['"+filename+"'].source=['"+sourceString+"'];\n";
  3863. //initialize array values
  3864. _blanket._trackingArraySetup.sort(function(a,b){
  3865. return parseInt(a,10) > parseInt(b,10);
  3866. }).forEach(function(item){
  3867. intro += covVar+"['"+filename+"']["+item+"]=0;\n";
  3868. });
  3869. if (branches){
  3870. _blanket._branchingArraySetup.sort(function(a,b){
  3871. return a.line > b.line;
  3872. }).sort(function(a,b){
  3873. return a.column > b.column;
  3874. }).forEach(function(item){
  3875. if (item.file === filename){
  3876. intro += "if (typeof "+ covVar+"['"+filename+"'].branchData["+item.line+"] === 'undefined'){\n";
  3877. intro += covVar+"['"+filename+"'].branchData["+item.line+"]=[];\n";
  3878. intro += "}";
  3879. intro += covVar+"['"+filename+"'].branchData["+item.line+"]["+item.column+"] = [];\n";
  3880. intro += covVar+"['"+filename+"'].branchData["+item.line+"]["+item.column+"].consequent = "+JSON.stringify(item.consequent)+";\n";
  3881. intro += covVar+"['"+filename+"'].branchData["+item.line+"]["+item.column+"].alternate = "+JSON.stringify(item.alternate)+";\n";
  3882. }
  3883. });
  3884. }
  3885. intro += "}";
  3886. return intro;
  3887. },
  3888. _blockifyIf: function(node){
  3889. if (linesToAddBrackets.indexOf(node.type) > -1){
  3890. var bracketsExistObject = node.consequent || node.body;
  3891. var bracketsExistAlt = node.alternate;
  3892. if( bracketsExistAlt && bracketsExistAlt.type !== "BlockStatement") {
  3893. bracketsExistAlt.update("{\n"+bracketsExistAlt.source()+"}\n");
  3894. }
  3895. if( bracketsExistObject && bracketsExistObject.type !== "BlockStatement") {
  3896. bracketsExistObject.update("{\n"+bracketsExistObject.source()+"}\n");
  3897. }
  3898. }
  3899. },
  3900. _trackBranch: function(node,filename){
  3901. //recursive on consequent and alternative
  3902. var line = node.loc.start.line;
  3903. var col = node.loc.start.column;
  3904. _blanket._branchingArraySetup.push({
  3905. line: line,
  3906. column: col,
  3907. file:filename,
  3908. consequent: node.consequent.loc,
  3909. alternate: node.alternate.loc
  3910. });
  3911. var updated = "_$branchFcn"+
  3912. "('"+filename+"',"+line+","+col+","+node.test.source()+
  3913. ")?"+node.consequent.source()+":"+node.alternate.source();
  3914. node.update(updated);
  3915. },
  3916. _addTracking: function (filename) {
  3917. //falafel doesn't take a file name
  3918. //so we include the filename in a closure
  3919. //and return the function to falafel
  3920. var covVar = _blanket.getCovVar();
  3921. return function(node){
  3922. _blanket._blockifyIf(node);
  3923. if (linesToAddTracking.indexOf(node.type) > -1 && node.parent.type !== "LabeledStatement") {
  3924. _blanket._checkDefs(node,filename);
  3925. if (node.type === "VariableDeclaration" &&
  3926. (node.parent.type === "ForStatement" || node.parent.type === "ForInStatement")){
  3927. return;
  3928. }
  3929. if (node.loc && node.loc.start){
  3930. node.update(covVar+"['"+filename+"']["+node.loc.start.line+"]++;\n"+node.source());
  3931. _blanket._trackingArraySetup.push(node.loc.start.line);
  3932. }else{
  3933. //I don't think we can handle a node with no location
  3934. throw new Error("The instrumenter encountered a node with no location: "+Object.keys(node));
  3935. }
  3936. }else if (_blanket.options("branchTracking") && node.type === "ConditionalExpression"){
  3937. _blanket._trackBranch(node,filename);
  3938. }else if (node.type === "Literal" && node.value === "use strict" && node.parent && node.parent.type === "ExpressionStatement" && node.parent.parent && node.parent.parent.type === "Program"){
  3939. _blanket._useStrictMode = true;
  3940. }
  3941. };
  3942. },
  3943. _checkDefs: function(node,filename){
  3944. // Make sure developers don't redefine window. if they do, inform them it is wrong.
  3945. if (inBrowser){
  3946. if (node.type === "VariableDeclaration" && node.declarations) {
  3947. node.declarations.forEach(function(declaration) {
  3948. if (declaration.id.name === "window") {
  3949. throw new Error("Instrumentation error, you cannot redefine the 'window' variable in " + filename + ":" + node.loc.start.line);
  3950. }
  3951. });
  3952. }
  3953. if (node.type === "FunctionDeclaration" && node.params) {
  3954. node.params.forEach(function(param) {
  3955. if (param.name === "window") {
  3956. throw new Error("Instrumentation error, you cannot redefine the 'window' variable in " + filename + ":" + node.loc.start.line);
  3957. }
  3958. });
  3959. }
  3960. //Make sure developers don't redefine the coverage variable
  3961. if (node.type === "ExpressionStatement" &&
  3962. node.expression && node.expression.left &&
  3963. node.expression.left.object && node.expression.left.property &&
  3964. node.expression.left.object.name +
  3965. "." + node.expression.left.property.name === _blanket.getCovVar()) {
  3966. throw new Error("Instrumentation error, you cannot redefine the coverage variable in " + filename + ":" + node.loc.start.line);
  3967. }
  3968. }else{
  3969. //Make sure developers don't redefine the coverage variable in node
  3970. if (node.type === "ExpressionStatement" &&
  3971. node.expression && node.expression.left &&
  3972. !node.expression.left.object && !node.expression.left.property &&
  3973. node.expression.left.name === _blanket.getCovVar()) {
  3974. throw new Error("Instrumentation error, you cannot redefine the coverage variable in " + filename + ":" + node.loc.start.line);
  3975. }
  3976. }
  3977. },
  3978. setupCoverage: function(){
  3979. coverageInfo.instrumentation = "blanket";
  3980. coverageInfo.stats = {
  3981. "suites": 0,
  3982. "tests": 0,
  3983. "passes": 0,
  3984. "pending": 0,
  3985. "failures": 0,
  3986. "start": new Date()
  3987. };
  3988. },
  3989. _checkIfSetup: function(){
  3990. if (!coverageInfo.stats){
  3991. throw new Error("You must call blanket.setupCoverage() first.");
  3992. }
  3993. },
  3994. onTestStart: function(){
  3995. if (_blanket.options("debug")) {console.log("BLANKET-Test event started");}
  3996. this._checkIfSetup();
  3997. coverageInfo.stats.tests++;
  3998. coverageInfo.stats.pending++;
  3999. },
  4000. onTestDone: function(total,passed){
  4001. this._checkIfSetup();
  4002. if(passed === total){
  4003. coverageInfo.stats.passes++;
  4004. }else{
  4005. coverageInfo.stats.failures++;
  4006. }
  4007. coverageInfo.stats.pending--;
  4008. },
  4009. onModuleStart: function(){
  4010. this._checkIfSetup();
  4011. coverageInfo.stats.suites++;
  4012. },
  4013. onTestsDone: function(){
  4014. if (_blanket.options("debug")) {console.log("BLANKET-Test event done");}
  4015. this._checkIfSetup();
  4016. coverageInfo.stats.end = new Date();
  4017. if (inBrowser){
  4018. this.report(coverageInfo);
  4019. }else{
  4020. if (!_blanket.options("branchTracking")){
  4021. delete (inBrowser ? window : global)[_blanket.getCovVar()].branchFcn;
  4022. }
  4023. this.options("reporter").call(this,coverageInfo);
  4024. }
  4025. }
  4026. };
  4027. return _blanket;
  4028. })();
  4029. (function(_blanket){
  4030. var oldOptions = _blanket.options;
  4031. _blanket.extend({
  4032. outstandingRequireFiles:[],
  4033. options: function(key,value){
  4034. var newVal={};
  4035. if (typeof key !== "string"){
  4036. //key is key/value map
  4037. oldOptions(key);
  4038. newVal = key;
  4039. }else if (typeof value === 'undefined'){
  4040. //accessor
  4041. return oldOptions(key);
  4042. }else{
  4043. //setter
  4044. oldOptions(key,value);
  4045. newVal[key] = value;
  4046. }
  4047. if (newVal.adapter){
  4048. _blanket._loadFile(newVal.adapter);
  4049. }
  4050. if (newVal.loader){
  4051. _blanket._loadFile(newVal.loader);
  4052. }
  4053. },
  4054. requiringFile: function(filename,done){
  4055. if (typeof filename === "undefined"){
  4056. _blanket.outstandingRequireFiles=[];
  4057. }else if (typeof done === "undefined"){
  4058. _blanket.outstandingRequireFiles.push(filename);
  4059. }else{
  4060. _blanket.outstandingRequireFiles.splice(_blanket.outstandingRequireFiles.indexOf(filename),1);
  4061. }
  4062. },
  4063. requireFilesLoaded: function(){
  4064. return _blanket.outstandingRequireFiles.length === 0;
  4065. },
  4066. showManualLoader: function(){
  4067. if (document.getElementById("blanketLoaderDialog")){
  4068. return;
  4069. }
  4070. //copied from http://blog.avtex.com/2012/01/26/cross-browser-css-only-modal-box/
  4071. var loader = "<div class='blanketDialogOverlay'>";
  4072. loader += "&nbsp;</div>";
  4073. loader += "<div class='blanketDialogVerticalOffset'>";
  4074. loader += "<div class='blanketDialogBox'>";
  4075. loader += "<b>Error:</b> Blanket.js encountered a cross origin request error while instrumenting the source files. ";
  4076. loader += "<br><br>This is likely caused by the source files being referenced locally (using the file:// protocol). ";
  4077. loader += "<br><br>Some solutions include <a href='http://askubuntu.com/questions/160245/making-google-chrome-option-allow-file-access-from-files-permanent' target='_blank'>starting Chrome with special flags</a>, <a target='_blank' href='https://github.com/remy/servedir'>running a server locally</a>, or using a browser without these CORS restrictions (Safari).";
  4078. loader += "<br>";
  4079. if (typeof FileReader !== "undefined"){
  4080. loader += "<br>Or, try the experimental loader. When prompted, simply click on the directory containing all the source files you want covered.";
  4081. loader += "<a href='javascript:document.getElementById(\"fileInput\").click();'>Start Loader</a>";
  4082. loader += "<input type='file' type='application/x-javascript' accept='application/x-javascript' webkitdirectory id='fileInput' multiple onchange='window.blanket.manualFileLoader(this.files)' style='visibility:hidden;position:absolute;top:-50;left:-50'/>";
  4083. }
  4084. loader += "<br><span style='float:right;cursor:pointer;' onclick=document.getElementById('blanketLoaderDialog').style.display='none';>Close</span>";
  4085. loader += "<div style='clear:both'></div>";
  4086. loader += "</div></div>";
  4087. var css = ".blanketDialogWrapper {";
  4088. css += "display:block;";
  4089. css += "position:fixed;";
  4090. css += "z-index:40001; }";
  4091. css += ".blanketDialogOverlay {";
  4092. css += "position:fixed;";
  4093. css += "width:100%;";
  4094. css += "height:100%;";
  4095. css += "background-color:black;";
  4096. css += "opacity:.5; ";
  4097. css += "-ms-filter:'progid:DXImageTransform.Microsoft.Alpha(Opacity=50)'; ";
  4098. css += "filter:alpha(opacity=50); ";
  4099. css += "z-index:40001; }";
  4100. css += ".blanketDialogVerticalOffset { ";
  4101. css += "position:fixed;";
  4102. css += "top:30%;";
  4103. css += "width:100%;";
  4104. css += "z-index:40002; }";
  4105. css += ".blanketDialogBox { ";
  4106. css += "width:405px; ";
  4107. css += "position:relative;";
  4108. css += "margin:0 auto;";
  4109. css += "background-color:white;";
  4110. css += "padding:10px;";
  4111. css += "border:1px solid black; }";
  4112. var dom = document.createElement("style");
  4113. dom.innerHTML = css;
  4114. document.head.appendChild(dom);
  4115. var div = document.createElement("div");
  4116. div.id = "blanketLoaderDialog";
  4117. div.className = "blanketDialogWrapper";
  4118. div.innerHTML = loader;
  4119. document.body.insertBefore(div,document.body.firstChild);
  4120. },
  4121. manualFileLoader: function(files){
  4122. var toArray =Array.prototype.slice;
  4123. files = toArray.call(files).filter(function(item){
  4124. return item.type !== "";
  4125. });
  4126. var sessionLength = files.length-1;
  4127. var sessionIndx=0;
  4128. var sessionArray = {};
  4129. if (sessionStorage["blanketSessionLoader"]){
  4130. sessionArray = JSON.parse(sessionStorage["blanketSessionLoader"]);
  4131. }
  4132. var fileLoader = function(event){
  4133. var fileContent = event.currentTarget.result;
  4134. var file = files[sessionIndx];
  4135. var filename = file.webkitRelativePath && file.webkitRelativePath !== '' ? file.webkitRelativePath : file.name;
  4136. sessionArray[filename] = fileContent;
  4137. sessionIndx++;
  4138. if (sessionIndx === sessionLength){
  4139. sessionStorage.setItem("blanketSessionLoader", JSON.stringify(sessionArray));
  4140. document.location.reload();
  4141. }else{
  4142. readFile(files[sessionIndx]);
  4143. }
  4144. };
  4145. function readFile(file){
  4146. var reader = new FileReader();
  4147. reader.onload = fileLoader;
  4148. reader.readAsText(file);
  4149. }
  4150. readFile(files[sessionIndx]);
  4151. },
  4152. _loadFile: function(path){
  4153. if (typeof path !== "undefined"){
  4154. var request = new XMLHttpRequest();
  4155. request.open('GET', path, false);
  4156. request.send();
  4157. _blanket._addScript(request.responseText);
  4158. }
  4159. },
  4160. _addScript: function(data){
  4161. var script = document.createElement("script");
  4162. script.type = "text/javascript";
  4163. script.text = data;
  4164. (document.body || document.getElementsByTagName('head')[0]).appendChild(script);
  4165. },
  4166. hasAdapter: function(callback){
  4167. return _blanket.options("adapter") !== null;
  4168. },
  4169. report: function(coverage_data){
  4170. if (!document.getElementById("blanketLoaderDialog")){
  4171. //all found, clear it
  4172. _blanket.blanketSession = null;
  4173. }
  4174. coverage_data.files = window._$blanket;
  4175. var require = blanket.options("commonJS") ? blanket._commonjs.require : window.require;
  4176. // Check if we have any covered files that requires reporting
  4177. // otherwise just exit gracefully.
  4178. if (!coverage_data.files || !Object.keys(coverage_data.files).length) {
  4179. if (_blanket.options("debug")) {console.log("BLANKET-Reporting No files were instrumented.");}
  4180. return;
  4181. }
  4182. if (typeof coverage_data.files.branchFcn !== "undefined"){
  4183. delete coverage_data.files.branchFcn;
  4184. }
  4185. if (typeof _blanket.options("reporter") === "string"){
  4186. _blanket._loadFile(_blanket.options("reporter"));
  4187. _blanket.customReporter(coverage_data,_blanket.options("reporter_options"));
  4188. }else if (typeof _blanket.options("reporter") === "function"){
  4189. _blanket.options("reporter")(coverage_data,_blanket.options("reporter_options"));
  4190. }else if (typeof _blanket.defaultReporter === 'function'){
  4191. _blanket.defaultReporter(coverage_data,_blanket.options("reporter_options"));
  4192. }else{
  4193. throw new Error("no reporter defined.");
  4194. }
  4195. },
  4196. _bindStartTestRunner: function(bindEvent,startEvent){
  4197. if (bindEvent){
  4198. bindEvent(startEvent);
  4199. }else{
  4200. if (document.readyState === "complete") {
  4201. startEvent();
  4202. } else {
  4203. window.addEventListener("load",startEvent,false);
  4204. }
  4205. }
  4206. },
  4207. _loadSourceFiles: function(callback){
  4208. var require = blanket.options("commonJS") ? blanket._commonjs.require : window.require;
  4209. function copy(o){
  4210. var _copy = Object.create( Object.getPrototypeOf(o) );
  4211. var propNames = Object.getOwnPropertyNames(o);
  4212. propNames.forEach(function(name){
  4213. var desc = Object.getOwnPropertyDescriptor(o, name);
  4214. Object.defineProperty(_copy, name, desc);
  4215. });
  4216. return _copy;
  4217. }
  4218. if (_blanket.options("debug")) {console.log("BLANKET-Collecting page scripts");}
  4219. var scripts = _blanket.utils.collectPageScripts();
  4220. //_blanket.options("filter",scripts);
  4221. if (scripts.length === 0){
  4222. callback();
  4223. }else{
  4224. //check session state
  4225. if (sessionStorage["blanketSessionLoader"]){
  4226. _blanket.blanketSession = JSON.parse(sessionStorage["blanketSessionLoader"]);
  4227. }
  4228. scripts.forEach(function(file,indx){
  4229. _blanket.utils.cache[file]={
  4230. loaded:false
  4231. };
  4232. });
  4233. var currScript=-1;
  4234. _blanket.utils.loadAll(function(test){
  4235. if (test){
  4236. return typeof scripts[currScript+1] !== 'undefined';
  4237. }
  4238. currScript++;
  4239. if (currScript >= scripts.length){
  4240. return null;
  4241. }
  4242. return scripts[currScript];
  4243. },callback);
  4244. }
  4245. },
  4246. beforeStartTestRunner: function(opts){
  4247. opts = opts || {};
  4248. opts.checkRequirejs = typeof opts.checkRequirejs === "undefined" ? true : opts.checkRequirejs;
  4249. opts.callback = opts.callback || function() { };
  4250. opts.coverage = typeof opts.coverage === "undefined" ? true : opts.coverage;
  4251. if (opts.coverage) {
  4252. _blanket._bindStartTestRunner(opts.bindEvent,
  4253. function(){
  4254. _blanket._loadSourceFiles(function() {
  4255. var allLoaded = function(){
  4256. return opts.condition ? opts.condition() : _blanket.requireFilesLoaded();
  4257. };
  4258. var check = function() {
  4259. if (allLoaded()) {
  4260. if (_blanket.options("debug")) {console.log("BLANKET-All files loaded, init start test runner callback.");}
  4261. var cb = _blanket.options("testReadyCallback");
  4262. if (cb){
  4263. if (typeof cb === "function"){
  4264. cb(opts.callback);
  4265. }else if (typeof cb === "string"){
  4266. _blanket._addScript(cb);
  4267. opts.callback();
  4268. }
  4269. }else{
  4270. opts.callback();
  4271. }
  4272. } else {
  4273. setTimeout(check, 13);
  4274. }
  4275. };
  4276. check();
  4277. });
  4278. });
  4279. }else{
  4280. opts.callback();
  4281. }
  4282. },
  4283. utils: {
  4284. qualifyURL: function (url) {
  4285. //http://stackoverflow.com/questions/470832/getting-an-absolute-url-from-a-relative-one-ie6-issue
  4286. var a = document.createElement('a');
  4287. a.href = url;
  4288. return a.href;
  4289. }
  4290. }
  4291. });
  4292. })(blanket);
  4293. blanket.defaultReporter = function(coverage){
  4294. var cssSytle = "#blanket-main {margin:2px;background:#EEE;color:#333;clear:both;font-family:'Helvetica Neue Light', 'HelveticaNeue-Light', 'Helvetica Neue', Calibri, Helvetica, Arial, sans-serif; font-size:17px;} #blanket-main a {color:#333;text-decoration:none;} #blanket-main a:hover {text-decoration:underline;} .blanket {margin:0;padding:5px;clear:both;border-bottom: 1px solid #FFFFFF;} .bl-error {color:red;}.bl-success {color:#5E7D00;} .bl-file{width:auto;} .bl-cl{float:left;} .blanket div.rs {margin-left:50px; width:150px; float:right} .bl-nb {padding-right:10px;} #blanket-main a.bl-logo {color: #EB1764;cursor: pointer;font-weight: bold;text-decoration: none} .bl-source{ overflow-x:scroll; background-color: #FFFFFF; border: 1px solid #CBCBCB; color: #363636; margin: 25px 20px; width: 80%;} .bl-source div{white-space: pre;font-family: monospace;} .bl-source > div > span:first-child{background-color: #EAEAEA;color: #949494;display: inline-block;padding: 0 10px;text-align: center;width: 30px;} .bl-source .hit{background-color:#c3e6c7} .bl-source .miss{background-color:#e6c3c7} .bl-source span.branchWarning{color:#000;background-color:yellow;} .bl-source span.branchOkay{color:#000;background-color:transparent;}",
  4295. successRate = 60,
  4296. head = document.head,
  4297. fileNumber = 0,
  4298. body = document.body,
  4299. headerContent,
  4300. hasBranchTracking = Object.keys(coverage.files).some(function(elem){
  4301. return typeof coverage.files[elem].branchData !== 'undefined';
  4302. }),
  4303. bodyContent = "<div id='blanket-main'><div class='blanket bl-title'><div class='bl-cl bl-file'><a href='http://alex-seville.github.com/blanket/' target='_blank' class='bl-logo'>Blanket.js</a> results</div><div class='bl-cl rs'>Coverage (%)</div><div class='bl-cl rs'>Covered/Total Smts.</div>"+(hasBranchTracking ? "<div class='bl-cl rs'>Covered/Total Branches</div>":"")+"<div style='clear:both;'></div></div>",
  4304. fileTemplate = "<div class='blanket {{statusclass}}'><div class='bl-cl bl-file'><span class='bl-nb'>{{fileNumber}}.</span><a href='javascript:blanket_toggleSource(\"file-{{fileNumber}}\")'>{{file}}</a></div><div class='bl-cl rs'>{{percentage}} %</div><div class='bl-cl rs'>{{numberCovered}}/{{totalSmts}}</div>"+( hasBranchTracking ? "<div class='bl-cl rs'>{{passedBranches}}/{{totalBranches}}</div>" : "" )+"<div id='file-{{fileNumber}}' class='bl-source' style='display:none;'>{{source}}</div><div style='clear:both;'></div></div>";
  4305. grandTotalTemplate = "<div class='blanket grand-total {{statusclass}}'><div class='bl-cl'>{{rowTitle}}</div><div class='bl-cl rs'>{{percentage}} %</div><div class='bl-cl rs'>{{numberCovered}}/{{totalSmts}}</div>"+( hasBranchTracking ? "<div class='bl-cl rs'>{{passedBranches}}/{{totalBranches}}</div>" : "" ) + "<div style='clear:both;'></div></div>";
  4306. function blanket_toggleSource(id) {
  4307. var element = document.getElementById(id);
  4308. if(element.style.display === 'block') {
  4309. element.style.display = 'none';
  4310. } else {
  4311. element.style.display = 'block';
  4312. }
  4313. }
  4314. var script = document.createElement("script");
  4315. script.type = "text/javascript";
  4316. script.text = blanket_toggleSource.toString().replace('function ' + blanket_toggleSource.name, 'function blanket_toggleSource');
  4317. body.appendChild(script);
  4318. var percentage = function(number, total) {
  4319. return (Math.round(((number/total) * 100)*100)/100);
  4320. };
  4321. var appendTag = function (type, el, str) {
  4322. var dom = document.createElement(type);
  4323. dom.innerHTML = str;
  4324. el.appendChild(dom);
  4325. };
  4326. function escapeInvalidXmlChars(str) {
  4327. return str.replace(/\&/g, "&amp;")
  4328. .replace(/</g, "&lt;")
  4329. .replace(/\>/g, "&gt;")
  4330. .replace(/\"/g, "&quot;")
  4331. .replace(/\'/g, "&apos;")
  4332. .replace(/`/g, "&grave;")
  4333. .replace(/[$]/g, "&dollar;")
  4334. .replace(/&/g, "&amp;");
  4335. }
  4336. function isBranchFollowed(data,bool){
  4337. var mode = bool ? 0 : 1;
  4338. if (typeof data === 'undefined' ||
  4339. typeof data === null ||
  4340. typeof data[mode] === 'undefined'){
  4341. return false;
  4342. }
  4343. return data[mode].length > 0;
  4344. }
  4345. var branchStack = [];
  4346. function branchReport(colsIndex,src,cols,offset,lineNum){
  4347. var newsrc="";
  4348. var postfix="";
  4349. if (branchStack.length > 0){
  4350. newsrc += "<span class='" + (isBranchFollowed(branchStack[0][1],branchStack[0][1].consequent === branchStack[0][0]) ? 'branchOkay' : 'branchWarning') + "'>";
  4351. if (branchStack[0][0].end.line === lineNum){
  4352. newsrc += escapeInvalidXmlChars(src.slice(0,branchStack[0][0].end.column)) + "</span>";
  4353. src = src.slice(branchStack[0][0].end.column);
  4354. branchStack.shift();
  4355. if (branchStack.length > 0){
  4356. newsrc += "<span class='" + (isBranchFollowed(branchStack[0][1],false) ? 'branchOkay' : 'branchWarning') + "'>";
  4357. if (branchStack[0][0].end.line === lineNum){
  4358. newsrc += escapeInvalidXmlChars(src.slice(0,branchStack[0][0].end.column)) + "</span>";
  4359. src = src.slice(branchStack[0][0].end.column);
  4360. branchStack.shift();
  4361. if (!cols){
  4362. return {src: newsrc + escapeInvalidXmlChars(src) ,cols:cols};
  4363. }
  4364. }
  4365. else if (!cols){
  4366. return {src: newsrc + escapeInvalidXmlChars(src) + "</span>",cols:cols};
  4367. }
  4368. else{
  4369. postfix = "</span>";
  4370. }
  4371. }else if (!cols){
  4372. return {src: newsrc + escapeInvalidXmlChars(src) ,cols:cols};
  4373. }
  4374. }else if(!cols){
  4375. return {src: newsrc + escapeInvalidXmlChars(src) + "</span>",cols:cols};
  4376. }else{
  4377. postfix = "</span>";
  4378. }
  4379. }
  4380. var thisline = cols[colsIndex];
  4381. //consequent
  4382. var cons = thisline.consequent;
  4383. if (cons.start.line > lineNum){
  4384. branchStack.unshift([thisline.alternate,thisline]);
  4385. branchStack.unshift([cons,thisline]);
  4386. src = escapeInvalidXmlChars(src);
  4387. }else{
  4388. var style = "<span class='" + (isBranchFollowed(thisline,true) ? 'branchOkay' : 'branchWarning') + "'>";
  4389. newsrc += escapeInvalidXmlChars(src.slice(0,cons.start.column-offset)) + style;
  4390. if (cols.length > colsIndex+1 &&
  4391. cols[colsIndex+1].consequent.start.line === lineNum &&
  4392. cols[colsIndex+1].consequent.start.column-offset < cols[colsIndex].consequent.end.column-offset)
  4393. {
  4394. var res = branchReport(colsIndex+1,src.slice(cons.start.column-offset,cons.end.column-offset),cols,cons.start.column-offset,lineNum);
  4395. newsrc += res.src;
  4396. cols = res.cols;
  4397. cols[colsIndex+1] = cols[colsIndex+2];
  4398. cols.length--;
  4399. }else{
  4400. newsrc += escapeInvalidXmlChars(src.slice(cons.start.column-offset,cons.end.column-offset));
  4401. }
  4402. newsrc += "</span>";
  4403. var alt = thisline.alternate;
  4404. if (alt.start.line > lineNum){
  4405. newsrc += escapeInvalidXmlChars(src.slice(cons.end.column-offset));
  4406. branchStack.unshift([alt,thisline]);
  4407. }else{
  4408. newsrc += escapeInvalidXmlChars(src.slice(cons.end.column-offset,alt.start.column-offset));
  4409. style = "<span class='" + (isBranchFollowed(thisline,false) ? 'branchOkay' : 'branchWarning') + "'>";
  4410. newsrc += style;
  4411. if (cols.length > colsIndex+1 &&
  4412. cols[colsIndex+1].consequent.start.line === lineNum &&
  4413. cols[colsIndex+1].consequent.start.column-offset < cols[colsIndex].alternate.end.column-offset)
  4414. {
  4415. var res2 = branchReport(colsIndex+1,src.slice(alt.start.column-offset,alt.end.column-offset),cols,alt.start.column-offset,lineNum);
  4416. newsrc += res2.src;
  4417. cols = res2.cols;
  4418. cols[colsIndex+1] = cols[colsIndex+2];
  4419. cols.length--;
  4420. }else{
  4421. newsrc += escapeInvalidXmlChars(src.slice(alt.start.column-offset,alt.end.column-offset));
  4422. }
  4423. newsrc += "</span>";
  4424. newsrc += escapeInvalidXmlChars(src.slice(alt.end.column-offset));
  4425. src = newsrc;
  4426. }
  4427. }
  4428. return {src:src+postfix, cols:cols};
  4429. }
  4430. var isUndefined = function(item){
  4431. return typeof item !== 'undefined';
  4432. };
  4433. var files = coverage.files;
  4434. var totals = {
  4435. totalSmts: 0,
  4436. numberOfFilesCovered: 0,
  4437. passedBranches: 0,
  4438. totalBranches: 0,
  4439. moduleTotalStatements : {},
  4440. moduleTotalCoveredStatements : {},
  4441. moduleTotalBranches : {},
  4442. moduleTotalCoveredBranches : {}
  4443. };
  4444. // check if a data-cover-modulepattern was provided for per-module coverage reporting
  4445. var modulePattern = _blanket.options("modulePattern");
  4446. var modulePatternRegex = ( modulePattern ? new RegExp(modulePattern) : null );
  4447. for(var file in files)
  4448. {
  4449. if (!files.hasOwnProperty(file)) {
  4450. continue;
  4451. }
  4452. fileNumber++;
  4453. var statsForFile = files[file],
  4454. totalSmts = 0,
  4455. numberOfFilesCovered = 0,
  4456. code = [],
  4457. i;
  4458. var end = [];
  4459. for(i = 0; i < statsForFile.source.length; i +=1){
  4460. var src = statsForFile.source[i];
  4461. if (branchStack.length > 0 ||
  4462. typeof statsForFile.branchData !== 'undefined')
  4463. {
  4464. if (typeof statsForFile.branchData[i+1] !== 'undefined')
  4465. {
  4466. var cols = statsForFile.branchData[i+1].filter(isUndefined);
  4467. var colsIndex=0;
  4468. src = branchReport(colsIndex,src,cols,0,i+1).src;
  4469. }else if (branchStack.length){
  4470. src = branchReport(0,src,null,0,i+1).src;
  4471. }else{
  4472. src = escapeInvalidXmlChars(src);
  4473. }
  4474. }else{
  4475. src = escapeInvalidXmlChars(src);
  4476. }
  4477. var lineClass="";
  4478. if(statsForFile[i+1]) {
  4479. numberOfFilesCovered += 1;
  4480. totalSmts += 1;
  4481. lineClass = 'hit';
  4482. }else{
  4483. if(statsForFile[i+1] === 0){
  4484. totalSmts++;
  4485. lineClass = 'miss';
  4486. }
  4487. }
  4488. code[i + 1] = "<div class='"+lineClass+"'><span class=''>"+(i + 1)+"</span>"+src+"</div>";
  4489. }
  4490. totals.totalSmts += totalSmts;
  4491. totals.numberOfFilesCovered += numberOfFilesCovered;
  4492. var totalBranches=0;
  4493. var passedBranches=0;
  4494. if (typeof statsForFile.branchData !== 'undefined'){
  4495. for(var j=0;j<statsForFile.branchData.length;j++){
  4496. if (typeof statsForFile.branchData[j] !== 'undefined'){
  4497. for(var k=0;k<statsForFile.branchData[j].length;k++){
  4498. if (typeof statsForFile.branchData[j][k] !== 'undefined'){
  4499. totalBranches++;
  4500. if (typeof statsForFile.branchData[j][k][0] !== 'undefined' &&
  4501. statsForFile.branchData[j][k][0].length > 0 &&
  4502. typeof statsForFile.branchData[j][k][1] !== 'undefined' &&
  4503. statsForFile.branchData[j][k][1].length > 0){
  4504. passedBranches++;
  4505. }
  4506. }
  4507. }
  4508. }
  4509. }
  4510. }
  4511. totals.passedBranches += passedBranches;
  4512. totals.totalBranches += totalBranches;
  4513. // if "data-cover-modulepattern" was provided,
  4514. // track totals per module name as well as globally
  4515. if (modulePatternRegex) {
  4516. var moduleName = file.match(modulePatternRegex)[1];
  4517. if(!totals.moduleTotalStatements.hasOwnProperty(moduleName)) {
  4518. totals.moduleTotalStatements[moduleName] = 0;
  4519. totals.moduleTotalCoveredStatements[moduleName] = 0;
  4520. }
  4521. totals.moduleTotalStatements[moduleName] += totalSmts;
  4522. totals.moduleTotalCoveredStatements[moduleName] += numberOfFilesCovered;
  4523. if(!totals.moduleTotalBranches.hasOwnProperty(moduleName)) {
  4524. totals.moduleTotalBranches[moduleName] = 0;
  4525. totals.moduleTotalCoveredBranches[moduleName] = 0;
  4526. }
  4527. totals.moduleTotalBranches[moduleName] += totalBranches;
  4528. totals.moduleTotalCoveredBranches[moduleName] += passedBranches;
  4529. }
  4530. var result = percentage(numberOfFilesCovered, totalSmts);
  4531. var output = fileTemplate.replace("{{file}}", file)
  4532. .replace("{{percentage}}",result)
  4533. .replace("{{numberCovered}}", numberOfFilesCovered)
  4534. .replace(/\{\{fileNumber\}\}/g, fileNumber)
  4535. .replace("{{totalSmts}}", totalSmts)
  4536. .replace("{{totalBranches}}", totalBranches)
  4537. .replace("{{passedBranches}}", passedBranches)
  4538. .replace("{{source}}", code.join(" "));
  4539. if(result < successRate)
  4540. {
  4541. output = output.replace("{{statusclass}}", "bl-error");
  4542. } else {
  4543. output = output.replace("{{statusclass}}", "bl-success");
  4544. }
  4545. bodyContent += output;
  4546. }
  4547. // create temporary function for use by the global totals reporter,
  4548. // as well as the per-module totals reporter
  4549. var createAggregateTotal = function(numSt, numCov, numBranch, numCovBr, moduleName) {
  4550. var totalPercent = percentage(numCov, numSt);
  4551. var statusClass = totalPercent < successRate ? "bl-error" : "bl-success";
  4552. var rowTitle = ( moduleName ? "Total for module: " + moduleName : "Global total" );
  4553. var totalsOutput = grandTotalTemplate.replace("{{rowTitle}}", rowTitle)
  4554. .replace("{{percentage}}", totalPercent)
  4555. .replace("{{numberCovered}}", numCov)
  4556. .replace("{{totalSmts}}", numSt)
  4557. .replace("{{passedBranches}}", numCovBr)
  4558. .replace("{{totalBranches}}", numBranch)
  4559. .replace("{{statusclass}}", statusClass);
  4560. bodyContent += totalsOutput;
  4561. };
  4562. // if "data-cover-modulepattern" was provided,
  4563. // output the per-module totals alongside the global totals
  4564. if (modulePatternRegex) {
  4565. for (var thisModuleName in totals.moduleTotalStatements) {
  4566. if (totals.moduleTotalStatements.hasOwnProperty(thisModuleName)) {
  4567. var moduleTotalSt = totals.moduleTotalStatements[thisModuleName];
  4568. var moduleTotalCovSt = totals.moduleTotalCoveredStatements[thisModuleName];
  4569. var moduleTotalBr = totals.moduleTotalBranches[thisModuleName];
  4570. var moduleTotalCovBr = totals.moduleTotalCoveredBranches[thisModuleName];
  4571. createAggregateTotal(moduleTotalSt, moduleTotalCovSt, moduleTotalBr, moduleTotalCovBr, thisModuleName);
  4572. }
  4573. }
  4574. }
  4575. createAggregateTotal(totals.totalSmts, totals.numberOfFilesCovered, totals.totalBranches, totals.passedBranches, null);
  4576. bodyContent += "</div>"; //closing main
  4577. appendTag('style', head, cssSytle);
  4578. //appendStyle(body, headerContent);
  4579. if (document.getElementById("blanket-main")){
  4580. document.getElementById("blanket-main").innerHTML=
  4581. bodyContent.slice(23,-6);
  4582. }else{
  4583. appendTag('div', body, bodyContent);
  4584. }
  4585. //appendHtml(body, '</div>');
  4586. };
  4587. (function(){
  4588. var newOptions={};
  4589. //http://stackoverflow.com/a/2954896
  4590. var toArray =Array.prototype.slice;
  4591. var scripts = toArray.call(document.scripts);
  4592. toArray.call(scripts[scripts.length - 1].attributes)
  4593. .forEach(function(es){
  4594. if(es.nodeName === "data-cover-only"){
  4595. newOptions.filter = es.nodeValue;
  4596. }
  4597. if(es.nodeName === "data-cover-never"){
  4598. newOptions.antifilter = es.nodeValue;
  4599. }
  4600. if(es.nodeName === "data-cover-reporter"){
  4601. newOptions.reporter = es.nodeValue;
  4602. }
  4603. if (es.nodeName === "data-cover-adapter"){
  4604. newOptions.adapter = es.nodeValue;
  4605. }
  4606. if (es.nodeName === "data-cover-loader"){
  4607. newOptions.loader = es.nodeValue;
  4608. }
  4609. if (es.nodeName === "data-cover-timeout"){
  4610. newOptions.timeout = es.nodeValue;
  4611. }
  4612. if (es.nodeName === "data-cover-modulepattern") {
  4613. newOptions.modulePattern = es.nodeValue;
  4614. }
  4615. if (es.nodeName === "data-cover-reporter-options"){
  4616. try{
  4617. newOptions.reporter_options = JSON.parse(es.nodeValue);
  4618. }catch(e){
  4619. if (blanket.options("debug")){
  4620. throw new Error("Invalid reporter options. Must be a valid stringified JSON object.");
  4621. }
  4622. }
  4623. }
  4624. if (es.nodeName === "data-cover-testReadyCallback"){
  4625. newOptions.testReadyCallback = es.nodeValue;
  4626. }
  4627. if (es.nodeName === "data-cover-customVariable"){
  4628. newOptions.customVariable = es.nodeValue;
  4629. }
  4630. if (es.nodeName === "data-cover-flags"){
  4631. var flags = " "+es.nodeValue+" ";
  4632. if (flags.indexOf(" ignoreError ") > -1){
  4633. newOptions.ignoreScriptError = true;
  4634. }
  4635. if (flags.indexOf(" autoStart ") > -1){
  4636. newOptions.autoStart = true;
  4637. }
  4638. if (flags.indexOf(" ignoreCors ") > -1){
  4639. newOptions.ignoreCors = true;
  4640. }
  4641. if (flags.indexOf(" branchTracking ") > -1){
  4642. newOptions.branchTracking = true;
  4643. }
  4644. if (flags.indexOf(" sourceURL ") > -1){
  4645. newOptions.sourceURL = true;
  4646. }
  4647. if (flags.indexOf(" debug ") > -1){
  4648. newOptions.debug = true;
  4649. }
  4650. if (flags.indexOf(" engineOnly ") > -1){
  4651. newOptions.engineOnly = true;
  4652. }
  4653. if (flags.indexOf(" commonJS ") > -1){
  4654. newOptions.commonJS = true;
  4655. }
  4656. if (flags.indexOf(" instrumentCache ") > -1){
  4657. newOptions.instrumentCache = true;
  4658. }
  4659. }
  4660. });
  4661. blanket.options(newOptions);
  4662. if (typeof requirejs !== 'undefined'){
  4663. blanket.options("existingRequireJS",true);
  4664. }
  4665. /* setup requirejs loader, if needed */
  4666. if (blanket.options("commonJS")){
  4667. blanket._commonjs = {};
  4668. }
  4669. })();
  4670. (function(_blanket){
  4671. _blanket.extend({
  4672. utils: {
  4673. normalizeBackslashes: function(str) {
  4674. return str.replace(/\\/g, '/');
  4675. },
  4676. matchPatternAttribute: function(filename,pattern){
  4677. if (typeof pattern === 'string'){
  4678. if (pattern.indexOf("[") === 0){
  4679. //treat as array
  4680. var pattenArr = pattern.slice(1,pattern.length-1).split(",");
  4681. return pattenArr.some(function(elem){
  4682. return _blanket.utils.matchPatternAttribute(filename,_blanket.utils.normalizeBackslashes(elem.slice(1,-1)));
  4683. //return filename.indexOf(_blanket.utils.normalizeBackslashes(elem.slice(1,-1))) > -1;
  4684. });
  4685. }else if ( pattern.indexOf("//") === 0){
  4686. var ex = pattern.slice(2,pattern.lastIndexOf('/'));
  4687. var mods = pattern.slice(pattern.lastIndexOf('/')+1);
  4688. var regex = new RegExp(ex,mods);
  4689. return regex.test(filename);
  4690. }else if (pattern.indexOf("#") === 0){
  4691. return window[pattern.slice(1)].call(window,filename);
  4692. }else{
  4693. return filename.indexOf(_blanket.utils.normalizeBackslashes(pattern)) > -1;
  4694. }
  4695. }else if ( pattern instanceof Array ){
  4696. return pattern.some(function(elem){
  4697. return _blanket.utils.matchPatternAttribute(filename,elem);
  4698. });
  4699. }else if (pattern instanceof RegExp){
  4700. return pattern.test(filename);
  4701. }else if (typeof pattern === "function"){
  4702. return pattern.call(window,filename);
  4703. }
  4704. },
  4705. blanketEval: function(data){
  4706. _blanket._addScript(data);
  4707. },
  4708. collectPageScripts: function(){
  4709. var toArray = Array.prototype.slice;
  4710. var scripts = toArray.call(document.scripts);
  4711. var selectedScripts=[],scriptNames=[];
  4712. var filter = _blanket.options("filter");
  4713. if(filter != null){
  4714. //global filter in place, data-cover-only
  4715. var antimatch = _blanket.options("antifilter");
  4716. selectedScripts = toArray.call(document.scripts)
  4717. .filter(function(s){
  4718. return toArray.call(s.attributes).filter(function(sn){
  4719. return sn.nodeName === "src" && _blanket.utils.matchPatternAttribute(sn.nodeValue,filter) &&
  4720. (typeof antimatch === "undefined" || !_blanket.utils.matchPatternAttribute(sn.nodeValue,antimatch));
  4721. }).length === 1;
  4722. });
  4723. }else{
  4724. selectedScripts = toArray.call(document.querySelectorAll("script[data-cover]"));
  4725. }
  4726. scriptNames = selectedScripts.map(function(s){
  4727. return _blanket.utils.qualifyURL(
  4728. toArray.call(s.attributes).filter(
  4729. function(sn){
  4730. return sn.nodeName === "src";
  4731. })[0].nodeValue);
  4732. });
  4733. if (!filter){
  4734. _blanket.options("filter","['"+scriptNames.join("','")+"']");
  4735. }
  4736. return scriptNames;
  4737. },
  4738. loadAll: function(nextScript,cb,preprocessor){
  4739. /**
  4740. * load dependencies
  4741. * @param {nextScript} factory for priority level
  4742. * @param {cb} the done callback
  4743. */
  4744. var currScript=nextScript();
  4745. var isLoaded = _blanket.utils.scriptIsLoaded(
  4746. currScript,
  4747. _blanket.utils.ifOrdered,
  4748. nextScript,
  4749. cb
  4750. );
  4751. if (!(_blanket.utils.cache[currScript] && _blanket.utils.cache[currScript].loaded)){
  4752. var attach = function(){
  4753. if (_blanket.options("debug")) {console.log("BLANKET-Mark script:"+currScript+", as loaded and move to next script.");}
  4754. isLoaded();
  4755. };
  4756. var whenDone = function(result){
  4757. if (_blanket.options("debug")) {console.log("BLANKET-File loading finished");}
  4758. if (typeof result !== 'undefined'){
  4759. if (_blanket.options("debug")) {console.log("BLANKET-Add file to DOM.");}
  4760. _blanket._addScript(result);
  4761. }
  4762. attach();
  4763. };
  4764. _blanket.utils.attachScript(
  4765. {
  4766. url: currScript
  4767. },
  4768. function (content){
  4769. _blanket.utils.processFile(
  4770. content,
  4771. currScript,
  4772. whenDone,
  4773. whenDone
  4774. );
  4775. }
  4776. );
  4777. }else{
  4778. isLoaded();
  4779. }
  4780. },
  4781. attachScript: function(options,cb){
  4782. var timeout = _blanket.options("timeout") || 3000;
  4783. setTimeout(function(){
  4784. if (!_blanket.utils.cache[options.url].loaded){
  4785. throw new Error("error (timeout=" + timeout + ") loading source script: " + options.url);
  4786. }
  4787. },timeout);
  4788. _blanket.utils.getFile(
  4789. options.url,
  4790. cb,
  4791. function(){ throw new Error("error loading source script: " + options.url);}
  4792. );
  4793. },
  4794. ifOrdered: function(nextScript,cb){
  4795. /**
  4796. * ordered loading callback
  4797. * @param {nextScript} factory for priority level
  4798. * @param {cb} the done callback
  4799. */
  4800. var currScript = nextScript(true);
  4801. if (currScript){
  4802. _blanket.utils.loadAll(nextScript,cb);
  4803. }else{
  4804. cb(new Error("Error in loading chain."));
  4805. }
  4806. },
  4807. scriptIsLoaded: function(url,orderedCb,nextScript,cb){
  4808. /**
  4809. * returns a callback that checks a loading list to see if a script is loaded.
  4810. * @param {orderedCb} callback if ordered loading is being done
  4811. * @param {nextScript} factory for next priority level
  4812. * @param {cb} the done callback
  4813. */
  4814. if (_blanket.options("debug")) {console.log("BLANKET-Returning function");}
  4815. return function(){
  4816. if (_blanket.options("debug")) {console.log("BLANKET-Marking file as loaded: "+url);}
  4817. _blanket.utils.cache[url].loaded=true;
  4818. if (_blanket.utils.allLoaded()){
  4819. if (_blanket.options("debug")) {console.log("BLANKET-All files loaded");}
  4820. cb();
  4821. }else if (orderedCb){
  4822. //if it's ordered we need to
  4823. //traverse down to the next
  4824. //priority level
  4825. if (_blanket.options("debug")) {console.log("BLANKET-Load next file.");}
  4826. orderedCb(nextScript,cb);
  4827. }
  4828. };
  4829. },
  4830. cache: {},
  4831. allLoaded: function (){
  4832. /**
  4833. * check if depdencies are loaded in cache
  4834. */
  4835. var cached = Object.keys(_blanket.utils.cache);
  4836. for (var i=0;i<cached.length;i++){
  4837. if (!_blanket.utils.cache[cached[i]].loaded){
  4838. return false;
  4839. }
  4840. }
  4841. return true;
  4842. },
  4843. processFile: function (content,url,cb,oldCb) {
  4844. var match = _blanket.options("filter");
  4845. //we check the never matches first
  4846. var antimatch = _blanket.options("antifilter");
  4847. if (typeof antimatch !== "undefined" &&
  4848. _blanket.utils.matchPatternAttribute(url,antimatch)
  4849. ){
  4850. oldCb(content);
  4851. if (_blanket.options("debug")) {console.log("BLANKET-File will never be instrumented:"+url);}
  4852. _blanket.requiringFile(url,true);
  4853. }else if (_blanket.utils.matchPatternAttribute(url,match)){
  4854. if (_blanket.options("debug")) {console.log("BLANKET-Attempting instrument of:"+url);}
  4855. _blanket.instrument({
  4856. inputFile: content,
  4857. inputFileName: url
  4858. },function(instrumented){
  4859. try{
  4860. if (_blanket.options("debug")) {console.log("BLANKET-instrument of:"+url+" was successfull.");}
  4861. _blanket.utils.blanketEval(instrumented);
  4862. cb();
  4863. _blanket.requiringFile(url,true);
  4864. }
  4865. catch(err){
  4866. if (_blanket.options("ignoreScriptError")){
  4867. //we can continue like normal if
  4868. //we're ignoring script errors,
  4869. //but otherwise we don't want
  4870. //to completeLoad or the error might be
  4871. //missed.
  4872. if (_blanket.options("debug")) { console.log("BLANKET-There was an error loading the file:"+url); }
  4873. cb(content);
  4874. _blanket.requiringFile(url,true);
  4875. }else{
  4876. var e = new Error("Error parsing instrumented code: "+err);
  4877. e.error = err;
  4878. throw e;
  4879. }
  4880. }
  4881. });
  4882. }else{
  4883. if (_blanket.options("debug")) { console.log("BLANKET-Loading (without instrumenting) the file:"+url);}
  4884. oldCb(content);
  4885. _blanket.requiringFile(url,true);
  4886. }
  4887. },
  4888. cacheXhrConstructor: function(){
  4889. var Constructor, createXhr, i, progId;
  4890. if (typeof XMLHttpRequest !== "undefined") {
  4891. Constructor = XMLHttpRequest;
  4892. this.createXhr = function() { return new Constructor(); };
  4893. } else if (typeof ActiveXObject !== "undefined") {
  4894. Constructor = ActiveXObject;
  4895. for (i = 0; i < 3; i += 1) {
  4896. progId = progIds[i];
  4897. try {
  4898. new ActiveXObject(progId);
  4899. break;
  4900. } catch (e) {}
  4901. }
  4902. this.createXhr = function() { return new Constructor(progId); };
  4903. }
  4904. },
  4905. craeteXhr: function () {
  4906. throw new Error("cacheXhrConstructor is supposed to overwrite this function.");
  4907. },
  4908. getFile: function(url, callback, errback, onXhr){
  4909. var foundInSession = false;
  4910. if (_blanket.blanketSession){
  4911. var files = Object.keys(_blanket.blanketSession);
  4912. for (var i=0; i<files.length;i++ ){
  4913. var key = files[i];
  4914. if (url.indexOf(key) > -1){
  4915. callback(_blanket.blanketSession[key]);
  4916. foundInSession=true;
  4917. return;
  4918. }
  4919. }
  4920. }
  4921. if (!foundInSession){
  4922. var xhr = _blanket.utils.createXhr();
  4923. xhr.open('GET', url, true);
  4924. //Allow overrides specified in config
  4925. if (onXhr) {
  4926. onXhr(xhr, url);
  4927. }
  4928. xhr.onreadystatechange = function (evt) {
  4929. var status, err;
  4930. //Do not explicitly handle errors, those should be
  4931. //visible via console output in the browser.
  4932. if (xhr.readyState === 4) {
  4933. status = xhr.status;
  4934. if ((status > 399 && status < 600) /*||
  4935. (status === 0 &&
  4936. navigator.userAgent.toLowerCase().indexOf('firefox') > -1)
  4937. */ ) {
  4938. //An http 4xx or 5xx error. Signal an error.
  4939. err = new Error(url + ' HTTP status: ' + status);
  4940. err.xhr = xhr;
  4941. errback(err);
  4942. } else {
  4943. callback(xhr.responseText);
  4944. }
  4945. }
  4946. };
  4947. try{
  4948. xhr.send(null);
  4949. }catch(e){
  4950. if (e.code && (e.code === 101 || e.code === 1012) && _blanket.options("ignoreCors") === false){
  4951. //running locally and getting error from browser
  4952. _blanket.showManualLoader();
  4953. } else {
  4954. throw e;
  4955. }
  4956. }
  4957. }
  4958. }
  4959. }
  4960. });
  4961. (function(){
  4962. var require = blanket.options("commonJS") ? blanket._commonjs.require : window.require;
  4963. var requirejs = blanket.options("commonJS") ? blanket._commonjs.requirejs : window.requirejs;
  4964. if (!_blanket.options("engineOnly") && _blanket.options("existingRequireJS")){
  4965. _blanket.utils.oldloader = requirejs.load;
  4966. requirejs.load = function (context, moduleName, url) {
  4967. _blanket.requiringFile(url);
  4968. _blanket.utils.getFile(url,
  4969. function(content){
  4970. _blanket.utils.processFile(
  4971. content,
  4972. url,
  4973. function newLoader(){
  4974. context.completeLoad(moduleName);
  4975. },
  4976. function oldLoader(){
  4977. _blanket.utils.oldloader(context, moduleName, url);
  4978. }
  4979. );
  4980. }, function (err) {
  4981. _blanket.requiringFile();
  4982. throw err;
  4983. });
  4984. };
  4985. }
  4986. // Save the XHR constructor, just in case frameworks like Sinon would sandbox it.
  4987. _blanket.utils.cacheXhrConstructor();
  4988. })();
  4989. })(blanket);
  4990. (function(){
  4991. if (typeof QUnit !== 'undefined'){
  4992. //check to make sure requirejs is completed before we start the test runner
  4993. var allLoaded = function() {
  4994. return window.QUnit.config.queue.length > 0 && blanket.noConflict().requireFilesLoaded();
  4995. };
  4996. if (!QUnit.config.urlConfig[0].tooltip){
  4997. //older versions we run coverage automatically
  4998. //and we change how events are binded
  4999. QUnit.begin=function(){
  5000. blanket.noConflict().setupCoverage();
  5001. };
  5002. QUnit.done=function(failures, total) {
  5003. blanket.noConflict().onTestsDone();
  5004. };
  5005. QUnit.moduleStart=function( details ) {
  5006. blanket.noConflict().onModuleStart();
  5007. };
  5008. QUnit.testStart=function( details ) {
  5009. blanket.noConflict().onTestStart();
  5010. };
  5011. QUnit.testDone=function( details ) {
  5012. blanket.noConflict().onTestDone(details.total,details.passed);
  5013. };
  5014. blanket.beforeStartTestRunner({
  5015. condition: allLoaded,
  5016. callback: QUnit.start
  5017. });
  5018. }else{
  5019. QUnit.config.urlConfig.push({
  5020. id: "coverage",
  5021. label: "Enable coverage",
  5022. tooltip: "Enable code coverage."
  5023. });
  5024. if ( QUnit.urlParams.coverage || blanket.options("autoStart") ) {
  5025. QUnit.begin(function(){
  5026. blanket.noConflict().setupCoverage();
  5027. });
  5028. QUnit.done(function(failures, total) {
  5029. blanket.noConflict().onTestsDone();
  5030. });
  5031. QUnit.moduleStart(function( details ) {
  5032. blanket.noConflict().onModuleStart();
  5033. });
  5034. QUnit.testStart(function( details ) {
  5035. blanket.noConflict().onTestStart();
  5036. });
  5037. QUnit.testDone(function( details ) {
  5038. blanket.noConflict().onTestDone(details.total,details.passed);
  5039. });
  5040. blanket.noConflict().beforeStartTestRunner({
  5041. condition: allLoaded,
  5042. callback: function(){
  5043. if (!(blanket.options("existingRequireJS") && !blanket.options("autoStart"))){
  5044. QUnit.start();
  5045. }
  5046. }
  5047. });
  5048. }else{
  5049. if (blanket.options("existingRequireJS")){ requirejs.load = _blanket.utils.oldloader; }
  5050. blanket.noConflict().beforeStartTestRunner({
  5051. condition: allLoaded,
  5052. callback: function(){
  5053. if (!(blanket.options("existingRequireJS") && !blanket.options("autoStart"))){
  5054. QUnit.start();
  5055. }
  5056. },
  5057. coverage:false
  5058. });
  5059. }
  5060. }
  5061. }
  5062. })();