blanket_mocha.js 200 KB

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