power-assert-formatter.js 364 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859
  1. /**
  2. * Modules in this bundle
  3. * @license
  4. *
  5. * power-assert-formatter:
  6. * license: MIT (http://opensource.org/licenses/MIT)
  7. * author: Takuto Wada <takuto.wada@gmail.com>
  8. * contributors: James Talmage
  9. * homepage: https://github.com/power-assert-js/power-assert-formatter
  10. * version: 1.4.1
  11. *
  12. * acorn:
  13. * license: MIT (http://opensource.org/licenses/MIT)
  14. * maintainers: marijn <marijnh@gmail.com>, rreverser <me@rreverser.com>
  15. * contributors: -e List of Acorn contributors. Updated before every release., Adrian Rakovsky, Alistair Braidwood, Andres Suarez, Angelo, Aparajita Fishman, Arian Stolwijk, Artem Govorov, Brandon Mills, Charles Hughes, Conrad Irwin, David Bonnet, Domenico Matteo, ForbesLindesay, Forbes Lindesay, Gilad Peleg, impinball, Ingvar Stepanyan, Jackson Ray Hamilton, Jesse McCarthy, Jiaxing Wang, Joel Kemp, Johannes Herr, Jordan Klassen, Jürg Lehni, keeyipchan, Keheliya Gallaba, Kevin Kwok, krator, Marijn Haverbeke, Martin Carlberg, Mathias Bynens, Mathieu 'p01' Henri, Matthew Bastien, Max Schaefer, Max Zerzouri, Mihai Bazon, Mike Rennie, Nicholas C. Zakas, Nick Fitzgerald, Olivier Thomann, Oskar Schöldström, Paul Harper, Peter Rust, PlNG, Prayag Verma, ReadmeCritic, r-e-d, Richard Gibson, Rich Harris, Sebastian McKenzie, Timothy Gu, Toru Nagashima, zsjforcn
  16. * homepage: https://github.com/ternjs/acorn
  17. * version: 3.2.0
  18. *
  19. * acorn-es7-plugin:
  20. * license: MIT (http://opensource.org/licenses/MIT)
  21. * author: matatbread
  22. * maintainers: matatbread <npm@mailed.me.uk>
  23. * homepage: https://github.com/MatAtBread/acorn-es7-plugin#readme
  24. * version: 1.0.15
  25. *
  26. * core-js:
  27. * license: MIT (http://opensource.org/licenses/MIT)
  28. * maintainers: zloirock <zloirock@zloirock.ru>
  29. * homepage: https://github.com/zloirock/core-js#readme
  30. * version: 2.4.0
  31. *
  32. * diff-match-patch:
  33. * license: http://www.apache.org/licenses/LICENSE-2.0
  34. * maintainers: forbeslindesay <forbes@lindeay.co.uk>
  35. * homepage: https://github.com/ForbesLindesay/diff-match-patch#readme
  36. * version: 1.0.0
  37. *
  38. * eastasianwidth:
  39. * license: MIT (http://opensource.org/licenses/MIT)
  40. * author: Masaki Komagata
  41. * maintainers: komagata <komagata@gmail.com>
  42. * homepage: https://github.com/komagata/eastasianwidth#readme
  43. * version: 0.1.1
  44. *
  45. * espurify:
  46. * license: MIT (http://opensource.org/licenses/MIT)
  47. * author: Takuto Wada <takuto.wada@gmail.com>
  48. * maintainers: twada <takuto.wada@gmail.com>
  49. * homepage: https://github.com/estools/espurify
  50. * version: 1.6.0
  51. *
  52. * estraverse:
  53. * license: BSD-2-Clause (http://opensource.org/licenses/BSD-2-Clause)
  54. * maintainers: constellation <utatane.tea@gmail.com>, michaelficarra <npm@michael.ficarra.me>, nzakas <nicholas@nczconsulting.com>
  55. * homepage: https://github.com/estools/estraverse
  56. * version: 4.2.0
  57. *
  58. * events:
  59. * license: MIT (http://opensource.org/licenses/MIT)
  60. * author: Irakli Gozalishvili <rfobic@gmail.com>
  61. * maintainers: gozala <rfobic@gmail.com>, defunctzombie <shtylman@gmail.com>
  62. * homepage: https://github.com/Gozala/events#readme
  63. * version: 1.1.1
  64. *
  65. * inherits:
  66. * license: ISC (http://opensource.org/licenses/ISC)
  67. * maintainers: isaacs <i@izs.me>
  68. * homepage: https://github.com/isaacs/inherits#readme
  69. * version: 2.0.1
  70. *
  71. * power-assert-context-formatter:
  72. * license: MIT (http://opensource.org/licenses/MIT)
  73. * author: Takuto Wada <takuto.wada@gmail.com>
  74. * maintainers: twada <takuto.wada@gmail.com>
  75. * homepage: https://github.com/twada/power-assert-runtime
  76. * version: 1.0.7
  77. *
  78. * power-assert-context-reducer-ast:
  79. * license: MIT (http://opensource.org/licenses/MIT)
  80. * author: Takuto Wada <takuto.wada@gmail.com>
  81. * maintainers: twada <takuto.wada@gmail.com>
  82. * homepage: https://github.com/twada/power-assert-runtime
  83. * version: 1.0.7
  84. *
  85. * power-assert-context-traversal:
  86. * license: MIT (http://opensource.org/licenses/MIT)
  87. * author: Takuto Wada <takuto.wada@gmail.com>
  88. * maintainers: twada <takuto.wada@gmail.com>
  89. * homepage: https://github.com/twada/power-assert-runtime
  90. * version: 1.0.7
  91. *
  92. * power-assert-renderer-assertion:
  93. * license: MIT (http://opensource.org/licenses/MIT)
  94. * author: Takuto Wada <takuto.wada@gmail.com>
  95. * maintainers: twada <takuto.wada@gmail.com>
  96. * homepage: https://github.com/twada/power-assert-runtime
  97. * version: 1.0.7
  98. *
  99. * power-assert-renderer-base:
  100. * license: MIT (http://opensource.org/licenses/MIT)
  101. * author: Takuto Wada <takuto.wada@gmail.com>
  102. * maintainers: twada <takuto.wada@gmail.com>
  103. * homepage: https://github.com/twada/power-assert-runtime
  104. * version: 1.0.7
  105. *
  106. * power-assert-renderer-comparison:
  107. * license: MIT (http://opensource.org/licenses/MIT)
  108. * author: Takuto Wada <takuto.wada@gmail.com>
  109. * maintainers: twada <takuto.wada@gmail.com>
  110. * homepage: https://github.com/twada/power-assert-runtime
  111. * version: 1.0.7
  112. *
  113. * power-assert-renderer-diagram:
  114. * license: MIT (http://opensource.org/licenses/MIT)
  115. * author: Takuto Wada <takuto.wada@gmail.com>
  116. * maintainers: twada <takuto.wada@gmail.com>
  117. * homepage: https://github.com/twada/power-assert-runtime
  118. * version: 1.0.7
  119. *
  120. * power-assert-renderer-file:
  121. * license: MIT (http://opensource.org/licenses/MIT)
  122. * author: Takuto Wada <takuto.wada@gmail.com>
  123. * maintainers: twada <takuto.wada@gmail.com>
  124. * homepage: https://github.com/twada/power-assert-runtime
  125. * version: 1.0.7
  126. *
  127. * process:
  128. * license: MIT (http://opensource.org/licenses/MIT)
  129. * author: Roman Shtylman <shtylman@gmail.com>
  130. * maintainers: coolaj86 <coolaj86@gmail.com>, cwmma <calvin.metcalf@gmail.com>, defunctzombie <shtylman@gmail.com>
  131. * homepage: https://github.com/shtylman/node-process#readme
  132. * version: 0.11.5
  133. *
  134. * stringifier:
  135. * license: MIT (http://opensource.org/licenses/MIT)
  136. * author: Takuto Wada <takuto.wada@gmail.com>
  137. * maintainers: twada <takuto.wada@gmail.com>
  138. * homepage: https://github.com/twada/stringifier
  139. * version: 1.3.0
  140. *
  141. * traverse:
  142. * license: MIT (http://opensource.org/licenses/MIT)
  143. * author: James Halliday <mail@substack.net>
  144. * maintainers: substack <mail@substack.net>
  145. * homepage: https://github.com/substack/js-traverse
  146. * version: 0.6.6
  147. *
  148. * type-name:
  149. * license: MIT (http://opensource.org/licenses/MIT)
  150. * author: Takuto Wada <takuto.wada@gmail.com>
  151. * maintainers: twada <takuto.wada@gmail.com>
  152. * contributors: azu, Yosuke Furukawa
  153. * homepage: https://github.com/twada/type-name
  154. * version: 2.0.1
  155. *
  156. * util:
  157. * license: MIT (http://opensource.org/licenses/MIT)
  158. * author: Joyent
  159. * maintainers: shtylman <shtylman@gmail.com>
  160. * homepage: https://github.com/defunctzombie/node-util
  161. * version: 0.10.3
  162. *
  163. * This header is generated by licensify (https://github.com/twada/licensify)
  164. */
  165. (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.powerAssertFormatter = 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){
  166. /**
  167. * power-assert-formatter.js - Power Assert output formatter
  168. *
  169. * https://github.com/power-assert-js/power-assert-formatter
  170. *
  171. * Copyright (c) 2013-2016 Takuto Wada
  172. * Licensed under the MIT license.
  173. * https://github.com/power-assert-js/power-assert-formatter/blob/master/MIT-LICENSE.txt
  174. */
  175. 'use strict';
  176. module.exports = _dereq_('./lib/create');
  177. },{"./lib/create":2}],2:[function(_dereq_,module,exports){
  178. 'use strict';
  179. var createFormatter = _dereq_('power-assert-context-formatter');
  180. var appendAst = _dereq_('power-assert-context-reducer-ast');
  181. var FileRenderer = _dereq_('power-assert-renderer-file');
  182. var AssertionRenderer = _dereq_('power-assert-renderer-assertion');
  183. var DiagramRenderer = _dereq_('power-assert-renderer-diagram');
  184. var ComparisonRenderer = _dereq_('power-assert-renderer-comparison');
  185. var defaultOptions = _dereq_('./default-options');
  186. var assign = _dereq_('core-js/library/fn/object/assign');
  187. var map = _dereq_('core-js/library/fn/array/map');
  188. // "Browserify can only analyze static requires. It is not in the scope of browserify to handle dynamic requires."
  189. // https://github.com/substack/node-browserify/issues/377
  190. var defaultRendererClasses = {
  191. './built-in/file': FileRenderer,
  192. './built-in/assertion': AssertionRenderer,
  193. './built-in/diagram': DiagramRenderer,
  194. './built-in/binary-expression': ComparisonRenderer
  195. };
  196. function toRendererClass (rendererName) {
  197. var RendererClass;
  198. if (typeof rendererName === 'function') {
  199. RendererClass = rendererName;
  200. } else if (typeof rendererName === 'string') {
  201. if (defaultRendererClasses[rendererName]) {
  202. RendererClass = defaultRendererClasses[rendererName];
  203. } else {
  204. RendererClass = _dereq_(rendererName);
  205. }
  206. }
  207. return RendererClass;
  208. }
  209. function create (options) {
  210. var config = assign(defaultOptions(), options);
  211. var rendererClasses = map(config.renderers, toRendererClass);
  212. var renderers = map(rendererClasses, function (clazz) {
  213. return { ctor: clazz, options: config };
  214. });
  215. return createFormatter(assign({}, config, {
  216. reducers: [
  217. appendAst
  218. ],
  219. renderers: renderers,
  220. legacy: true
  221. }));
  222. }
  223. create.renderers = {
  224. AssertionRenderer: AssertionRenderer,
  225. FileRenderer: FileRenderer,
  226. DiagramRenderer: DiagramRenderer,
  227. BinaryExpressionRenderer: ComparisonRenderer
  228. };
  229. create.defaultOptions = defaultOptions;
  230. module.exports = create;
  231. },{"./default-options":3,"core-js/library/fn/array/map":10,"core-js/library/fn/object/assign":13,"power-assert-context-formatter":76,"power-assert-context-reducer-ast":81,"power-assert-renderer-assertion":85,"power-assert-renderer-comparison":87,"power-assert-renderer-diagram":90,"power-assert-renderer-file":93}],3:[function(_dereq_,module,exports){
  232. 'use strict';
  233. module.exports = function defaultOptions () {
  234. return {
  235. lineDiffThreshold: 5,
  236. maxDepth: 1,
  237. outputOffset: 2,
  238. anonymous: 'Object',
  239. circular: '#@Circular#',
  240. lineSeparator: '\n',
  241. ambiguousEastAsianCharWidth: 2,
  242. renderers: [
  243. './built-in/file',
  244. './built-in/assertion',
  245. './built-in/diagram',
  246. './built-in/binary-expression'
  247. ]
  248. };
  249. };
  250. },{}],4:[function(_dereq_,module,exports){
  251. var NotAsync = {} ;
  252. var asyncExit = /^async[\t ]+(return|throw)/ ;
  253. var asyncFunction = /^async[\t ]+function/ ;
  254. var atomOrPropertyOrLabel = /^\s*[):;]/ ;
  255. var removeComments = /([^\n])\/\*(\*(?!\/)|[^\n*])*\*\/([^\n])/g ;
  256. function hasLineTerminatorBeforeNext(st, since) {
  257. return st.lineStart >= since;
  258. }
  259. function test(regex,st,noComment) {
  260. var src = st.input.slice(st.start) ;
  261. if (noComment) {
  262. src = src.replace(removeComments,"$1 $3") ;
  263. }
  264. return regex.test(src);
  265. }
  266. /* Return the object holding the parser's 'State'. This is different between acorn ('this')
  267. * and babylon ('this.state') */
  268. function state(p) {
  269. if (('state' in p) && p.state.constructor && p.state.constructor.name==='State')
  270. return p.state ; // Probably babylon
  271. return p ; // Probably acorn
  272. }
  273. /* Create a new parser derived from the specified parser, so that in the
  274. * event of an error we can back out and try again */
  275. function subParse(parser, pos, extensions) {
  276. // NB: The Babylon constructor does NOT expect 'pos' as an argument, and so
  277. // the input needs truncation at the start position, however at present
  278. // this doesn't work nicely as all the node location/start/end values
  279. // are therefore offset. Consequently, this plug-in is NOT currently working
  280. // with the (undocumented) Babylon plug-in interface.
  281. var p = new parser.constructor(parser.options, parser.input, pos);
  282. if (extensions)
  283. for (var k in extensions)
  284. p[k] = extensions[k] ;
  285. var src = state(parser) ;
  286. var dest = state(p) ;
  287. ['inFunction','inAsyncFunction','inAsync','inGenerator','inModule'].forEach(function(k){
  288. if (k in src)
  289. dest[k] = src[k] ;
  290. }) ;
  291. p.nextToken();
  292. return p;
  293. }
  294. function asyncAwaitPlugin (parser,options){
  295. var es7check = function(){} ;
  296. parser.extend("initialContext",function(base){
  297. return function(){
  298. if (this.options.ecmaVersion < 7) {
  299. es7check = function(node) {
  300. parser.raise(node.start,"async/await keywords only available when ecmaVersion>=7") ;
  301. } ;
  302. }
  303. this.reservedWords = new RegExp(this.reservedWords.toString().replace(/await|async/g,"").replace("|/","/").replace("/|","/").replace("||","|")) ;
  304. this.reservedWordsStrict = new RegExp(this.reservedWordsStrict.toString().replace(/await|async/g,"").replace("|/","/").replace("/|","/").replace("||","|")) ;
  305. this.reservedWordsStrictBind = new RegExp(this.reservedWordsStrictBind.toString().replace(/await|async/g,"").replace("|/","/").replace("/|","/").replace("||","|")) ;
  306. this.inAsyncFunction = options.inAsyncFunction ;
  307. if (options.awaitAnywhere && options.inAsyncFunction)
  308. parser.raise(node.start,"The options awaitAnywhere and inAsyncFunction are mutually exclusive") ;
  309. return base.apply(this,arguments);
  310. }
  311. }) ;
  312. parser.extend("shouldParseExportStatement",function(base){
  313. return function(){
  314. if (this.type.label==='name' && this.value==='async' && test(asyncFunction,state(this))) {
  315. return true ;
  316. }
  317. return base.apply(this,arguments) ;
  318. }
  319. }) ;
  320. parser.extend("parseStatement",function(base){
  321. return function (declaration, topLevel) {
  322. var st = state(this) ;
  323. var start = st.start;
  324. var startLoc = st.startLoc;
  325. if (st.type.label==='name') {
  326. if (test(asyncFunction,st,true)) {
  327. var wasAsync = st.inAsyncFunction ;
  328. try {
  329. st.inAsyncFunction = true ;
  330. this.next() ;
  331. var r = this.parseStatement(declaration, topLevel) ;
  332. r.async = true ;
  333. r.start = start;
  334. r.loc && (r.loc.start = startLoc);
  335. return r ;
  336. } finally {
  337. st.inAsyncFunction = wasAsync ;
  338. }
  339. } else if ((typeof options==="object" && options.asyncExits) && test(asyncExit,st)) {
  340. // NON-STANDARD EXTENSION iff. options.asyncExits is set, the
  341. // extensions 'async return <expr>?' and 'async throw <expr>?'
  342. // are enabled. In each case they are the standard ESTree nodes
  343. // with the flag 'async:true'
  344. this.next() ;
  345. var r = this.parseStatement(declaration, topLevel) ;
  346. r.async = true ;
  347. r.start = start;
  348. r.loc && (r.loc.start = startLoc);
  349. return r ;
  350. }
  351. }
  352. return base.apply(this,arguments);
  353. }
  354. }) ;
  355. parser.extend("parseIdent",function(base){
  356. return function(liberal){
  357. var id = base.apply(this,arguments);
  358. var st = state(this) ;
  359. if (st.inAsyncFunction && id.name==='await') {
  360. if (arguments.length===0) {
  361. this.raise(id.start,"'await' is reserved within async functions") ;
  362. }
  363. }
  364. return id ;
  365. }
  366. }) ;
  367. parser.extend("parseExprAtom",function(base){
  368. return function(refShorthandDefaultPos){
  369. var st = state(this) ;
  370. var start = st.start ;
  371. var startLoc = st.startLoc;
  372. var rhs,r = base.apply(this,arguments);
  373. if (r.type==='Identifier') {
  374. if (r.name==='async' && !hasLineTerminatorBeforeNext(st, r.end)) {
  375. // Is this really an async function?
  376. var isAsync = st.inAsyncFunction ;
  377. try {
  378. st.inAsyncFunction = true ;
  379. var pp = this ;
  380. var inBody = false ;
  381. var parseHooks = {
  382. parseFunctionBody:function(node,isArrowFunction){
  383. try {
  384. var wasInBody = inBody ;
  385. inBody = true ;
  386. return pp.parseFunctionBody.apply(this,arguments) ;
  387. } finally {
  388. inBody = wasInBody ;
  389. }
  390. },
  391. raise:function(){
  392. try {
  393. return pp.raise.apply(this,arguments) ;
  394. } catch(ex) {
  395. throw inBody?ex:NotAsync ;
  396. }
  397. }
  398. } ;
  399. rhs = subParse(this,st.start,parseHooks).parseExpression() ;
  400. if (rhs.type==='SequenceExpression')
  401. rhs = rhs.expressions[0] ;
  402. if (rhs.type==='FunctionExpression' || rhs.type==='FunctionDeclaration' || rhs.type==='ArrowFunctionExpression') {
  403. rhs.async = true ;
  404. rhs.start = start;
  405. rhs.loc && (rhs.loc.start = startLoc);
  406. st.pos = rhs.end;
  407. this.next();
  408. es7check(rhs) ;
  409. return rhs ;
  410. }
  411. } catch (ex) {
  412. if (ex!==NotAsync)
  413. throw ex ;
  414. }
  415. finally {
  416. st.inAsyncFunction = isAsync ;
  417. }
  418. }
  419. else if (r.name==='await') {
  420. var n = this.startNodeAt(r.start, r.loc && r.loc.start);
  421. if (st.inAsyncFunction) {
  422. rhs = this.parseExprSubscripts() ;
  423. n.operator = 'await' ;
  424. n.argument = rhs ;
  425. n = this.finishNodeAt(n,'AwaitExpression', rhs.end, rhs.loc && rhs.loc.end) ;
  426. es7check(n) ;
  427. return n ;
  428. } else
  429. // NON-STANDARD EXTENSION iff. options.awaitAnywhere is true,
  430. // an 'AwaitExpression' is allowed anywhere the token 'await'
  431. // could not be an identifier with the name 'await'.
  432. // Look-ahead to see if this is really a property or label called async or await
  433. if (st.input.slice(r.end).match(atomOrPropertyOrLabel))
  434. return r ; // This is a valid property name or label
  435. if (typeof options==="object" && options.awaitAnywhere) {
  436. start = st.start ;
  437. rhs = subParse(this,start-4).parseExprSubscripts() ;
  438. if (rhs.end<=start) {
  439. rhs = subParse(this,start).parseExprSubscripts() ;
  440. n.operator = 'await' ;
  441. n.argument = rhs ;
  442. n = this.finishNodeAt(n,'AwaitExpression', rhs.end, rhs.loc && rhs.loc.end) ;
  443. st.pos = rhs.end;
  444. this.next();
  445. es7check(n) ;
  446. return n ;
  447. }
  448. }
  449. }
  450. }
  451. return r ;
  452. }
  453. }) ;
  454. parser.extend('finishNodeAt',function(base){
  455. return function(node,type,pos,loc) {
  456. if (node.__asyncValue) {
  457. delete node.__asyncValue ;
  458. node.value.async = true ;
  459. }
  460. return base.apply(this,arguments) ;
  461. }
  462. }) ;
  463. parser.extend('finishNode',function(base){
  464. return function(node,type) {
  465. if (node.__asyncValue) {
  466. delete node.__asyncValue ;
  467. node.value.async = true ;
  468. }
  469. return base.apply(this,arguments) ;
  470. }
  471. }) ;
  472. parser.extend("parsePropertyName",function(base){
  473. return function (prop) {
  474. var st = state(this) ;
  475. var key = base.apply(this,arguments) ;
  476. if (key.type === "Identifier" && key.name === "async" && !hasLineTerminatorBeforeNext(st, key.end)) {
  477. // Look-ahead to see if this is really a property or label called async or await
  478. if (!st.input.slice(key.end).match(atomOrPropertyOrLabel)){
  479. es7check(prop) ;
  480. key = base.apply(this,arguments) ;
  481. if (key.type==='Identifier') {
  482. if (key.name==='constructor')
  483. this.raise(key.start,"'constructor()' cannot be be async") ;
  484. else if (key.name==='set')
  485. this.raise(key.start,"'set <member>(value)' cannot be be async") ;
  486. }
  487. prop.__asyncValue = true ;
  488. }
  489. }
  490. return key;
  491. };
  492. }) ;
  493. parser.extend("parseClassMethod",function(base){
  494. return function (classBody, method, isGenerator) {
  495. var st, wasAsync ;
  496. if (method.__asyncValue) {
  497. st = state(this) ;
  498. wasAsync = st.inAsyncFunction ;
  499. st.inAsyncFunction = true ;
  500. }
  501. var r = base.apply(this,arguments) ;
  502. if (st) {
  503. st.inAsyncFunction = wasAsync ;
  504. }
  505. return r ;
  506. }
  507. }) ;
  508. parser.extend("parsePropertyValue",function(base){
  509. return function (prop, isPattern, isGenerator, startPos, startLoc, refDestructuringErrors) {
  510. var st, wasAsync ;
  511. if (prop.__asyncValue) {
  512. st = state(this) ;
  513. wasAsync = st.inAsyncFunction ;
  514. st.inAsyncFunction = true ;
  515. }
  516. var r = base.apply(this,arguments) ;
  517. if (st) {
  518. st.inAsyncFunction = wasAsync ;
  519. }
  520. return r ;
  521. }
  522. }) ;
  523. }
  524. module.exports = function(acorn) {
  525. acorn.plugins.asyncawait = asyncAwaitPlugin ;
  526. return acorn
  527. }
  528. },{}],5:[function(_dereq_,module,exports){
  529. (function (global){
  530. (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 _dereq_=="function"&&_dereq_;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 _dereq_=="function"&&_dereq_;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){
  531. // A recursive descent parser operates by defining functions for all
  532. // syntactic elements, and recursively calling those, each function
  533. // advancing the input stream and returning an AST node. Precedence
  534. // of constructs (for example, the fact that `!x[1]` means `!(x[1])`
  535. // instead of `(!x)[1]` is handled by the fact that the parser
  536. // function that parses unary prefix operators is called first, and
  537. // in turn calls the function that parses `[]` subscripts — that
  538. // way, it'll receive the node for `x[1]` already parsed, and wraps
  539. // *that* in the unary operator node.
  540. //
  541. // Acorn uses an [operator precedence parser][opp] to handle binary
  542. // operator precedence, because it is much more compact than using
  543. // the technique outlined above, which uses different, nesting
  544. // functions to specify precedence, for all of the ten binary
  545. // precedence levels that JavaScript defines.
  546. //
  547. // [opp]: http://en.wikipedia.org/wiki/Operator-precedence_parser
  548. "use strict";
  549. var _tokentype = _dereq_("./tokentype");
  550. var _state = _dereq_("./state");
  551. var _parseutil = _dereq_("./parseutil");
  552. var pp = _state.Parser.prototype;
  553. // Check if property name clashes with already added.
  554. // Object/class getters and setters are not allowed to clash —
  555. // either with each other or with an init property — and in
  556. // strict mode, init properties are also not allowed to be repeated.
  557. pp.checkPropClash = function (prop, propHash) {
  558. if (this.options.ecmaVersion >= 6 && (prop.computed || prop.method || prop.shorthand)) return;
  559. var key = prop.key;var name = undefined;
  560. switch (key.type) {
  561. case "Identifier":
  562. name = key.name;break;
  563. case "Literal":
  564. name = String(key.value);break;
  565. default:
  566. return;
  567. }
  568. var kind = prop.kind;
  569. if (this.options.ecmaVersion >= 6) {
  570. if (name === "__proto__" && kind === "init") {
  571. if (propHash.proto) this.raiseRecoverable(key.start, "Redefinition of __proto__ property");
  572. propHash.proto = true;
  573. }
  574. return;
  575. }
  576. name = "$" + name;
  577. var other = propHash[name];
  578. if (other) {
  579. var isGetSet = kind !== "init";
  580. if ((this.strict || isGetSet) && other[kind] || !(isGetSet ^ other.init)) this.raiseRecoverable(key.start, "Redefinition of property");
  581. } else {
  582. other = propHash[name] = {
  583. init: false,
  584. get: false,
  585. set: false
  586. };
  587. }
  588. other[kind] = true;
  589. };
  590. // ### Expression parsing
  591. // These nest, from the most general expression type at the top to
  592. // 'atomic', nondivisible expression types at the bottom. Most of
  593. // the functions will simply let the function(s) below them parse,
  594. // and, *if* the syntactic construct they handle is present, wrap
  595. // the AST node that the inner parser gave them in another node.
  596. // Parse a full expression. The optional arguments are used to
  597. // forbid the `in` operator (in for loops initalization expressions)
  598. // and provide reference for storing '=' operator inside shorthand
  599. // property assignment in contexts where both object expression
  600. // and object pattern might appear (so it's possible to raise
  601. // delayed syntax error at correct position).
  602. pp.parseExpression = function (noIn, refDestructuringErrors) {
  603. var startPos = this.start,
  604. startLoc = this.startLoc;
  605. var expr = this.parseMaybeAssign(noIn, refDestructuringErrors);
  606. if (this.type === _tokentype.types.comma) {
  607. var node = this.startNodeAt(startPos, startLoc);
  608. node.expressions = [expr];
  609. while (this.eat(_tokentype.types.comma)) node.expressions.push(this.parseMaybeAssign(noIn, refDestructuringErrors));
  610. return this.finishNode(node, "SequenceExpression");
  611. }
  612. return expr;
  613. };
  614. // Parse an assignment expression. This includes applications of
  615. // operators like `+=`.
  616. pp.parseMaybeAssign = function (noIn, refDestructuringErrors, afterLeftParse) {
  617. if (this.inGenerator && this.isContextual("yield")) return this.parseYield();
  618. var ownDestructuringErrors = false;
  619. if (!refDestructuringErrors) {
  620. refDestructuringErrors = new _parseutil.DestructuringErrors();
  621. ownDestructuringErrors = true;
  622. }
  623. var startPos = this.start,
  624. startLoc = this.startLoc;
  625. if (this.type == _tokentype.types.parenL || this.type == _tokentype.types.name) this.potentialArrowAt = this.start;
  626. var left = this.parseMaybeConditional(noIn, refDestructuringErrors);
  627. if (afterLeftParse) left = afterLeftParse.call(this, left, startPos, startLoc);
  628. if (this.type.isAssign) {
  629. this.checkPatternErrors(refDestructuringErrors, true);
  630. if (!ownDestructuringErrors) _parseutil.DestructuringErrors.call(refDestructuringErrors);
  631. var node = this.startNodeAt(startPos, startLoc);
  632. node.operator = this.value;
  633. node.left = this.type === _tokentype.types.eq ? this.toAssignable(left) : left;
  634. refDestructuringErrors.shorthandAssign = 0; // reset because shorthand default was used correctly
  635. this.checkLVal(left);
  636. this.next();
  637. node.right = this.parseMaybeAssign(noIn);
  638. return this.finishNode(node, "AssignmentExpression");
  639. } else {
  640. if (ownDestructuringErrors) this.checkExpressionErrors(refDestructuringErrors, true);
  641. }
  642. return left;
  643. };
  644. // Parse a ternary conditional (`?:`) operator.
  645. pp.parseMaybeConditional = function (noIn, refDestructuringErrors) {
  646. var startPos = this.start,
  647. startLoc = this.startLoc;
  648. var expr = this.parseExprOps(noIn, refDestructuringErrors);
  649. if (this.checkExpressionErrors(refDestructuringErrors)) return expr;
  650. if (this.eat(_tokentype.types.question)) {
  651. var node = this.startNodeAt(startPos, startLoc);
  652. node.test = expr;
  653. node.consequent = this.parseMaybeAssign();
  654. this.expect(_tokentype.types.colon);
  655. node.alternate = this.parseMaybeAssign(noIn);
  656. return this.finishNode(node, "ConditionalExpression");
  657. }
  658. return expr;
  659. };
  660. // Start the precedence parser.
  661. pp.parseExprOps = function (noIn, refDestructuringErrors) {
  662. var startPos = this.start,
  663. startLoc = this.startLoc;
  664. var expr = this.parseMaybeUnary(refDestructuringErrors, false);
  665. if (this.checkExpressionErrors(refDestructuringErrors)) return expr;
  666. return this.parseExprOp(expr, startPos, startLoc, -1, noIn);
  667. };
  668. // Parse binary operators with the operator precedence parsing
  669. // algorithm. `left` is the left-hand side of the operator.
  670. // `minPrec` provides context that allows the function to stop and
  671. // defer further parser to one of its callers when it encounters an
  672. // operator that has a lower precedence than the set it is parsing.
  673. pp.parseExprOp = function (left, leftStartPos, leftStartLoc, minPrec, noIn) {
  674. var prec = this.type.binop;
  675. if (prec != null && (!noIn || this.type !== _tokentype.types._in)) {
  676. if (prec > minPrec) {
  677. var logical = this.type === _tokentype.types.logicalOR || this.type === _tokentype.types.logicalAND;
  678. var op = this.value;
  679. this.next();
  680. var startPos = this.start,
  681. startLoc = this.startLoc;
  682. var right = this.parseExprOp(this.parseMaybeUnary(null, false), startPos, startLoc, prec, noIn);
  683. var node = this.buildBinary(leftStartPos, leftStartLoc, left, right, op, logical);
  684. return this.parseExprOp(node, leftStartPos, leftStartLoc, minPrec, noIn);
  685. }
  686. }
  687. return left;
  688. };
  689. pp.buildBinary = function (startPos, startLoc, left, right, op, logical) {
  690. var node = this.startNodeAt(startPos, startLoc);
  691. node.left = left;
  692. node.operator = op;
  693. node.right = right;
  694. return this.finishNode(node, logical ? "LogicalExpression" : "BinaryExpression");
  695. };
  696. // Parse unary operators, both prefix and postfix.
  697. pp.parseMaybeUnary = function (refDestructuringErrors, sawUnary) {
  698. var startPos = this.start,
  699. startLoc = this.startLoc,
  700. expr = undefined;
  701. if (this.type.prefix) {
  702. var node = this.startNode(),
  703. update = this.type === _tokentype.types.incDec;
  704. node.operator = this.value;
  705. node.prefix = true;
  706. this.next();
  707. node.argument = this.parseMaybeUnary(null, true);
  708. this.checkExpressionErrors(refDestructuringErrors, true);
  709. if (update) this.checkLVal(node.argument);else if (this.strict && node.operator === "delete" && node.argument.type === "Identifier") this.raiseRecoverable(node.start, "Deleting local variable in strict mode");else sawUnary = true;
  710. expr = this.finishNode(node, update ? "UpdateExpression" : "UnaryExpression");
  711. } else {
  712. expr = this.parseExprSubscripts(refDestructuringErrors);
  713. if (this.checkExpressionErrors(refDestructuringErrors)) return expr;
  714. while (this.type.postfix && !this.canInsertSemicolon()) {
  715. var node = this.startNodeAt(startPos, startLoc);
  716. node.operator = this.value;
  717. node.prefix = false;
  718. node.argument = expr;
  719. this.checkLVal(expr);
  720. this.next();
  721. expr = this.finishNode(node, "UpdateExpression");
  722. }
  723. }
  724. if (!sawUnary && this.eat(_tokentype.types.starstar)) return this.buildBinary(startPos, startLoc, expr, this.parseMaybeUnary(null, false), "**", false);else return expr;
  725. };
  726. // Parse call, dot, and `[]`-subscript expressions.
  727. pp.parseExprSubscripts = function (refDestructuringErrors) {
  728. var startPos = this.start,
  729. startLoc = this.startLoc;
  730. var expr = this.parseExprAtom(refDestructuringErrors);
  731. var skipArrowSubscripts = expr.type === "ArrowFunctionExpression" && this.input.slice(this.lastTokStart, this.lastTokEnd) !== ")";
  732. if (this.checkExpressionErrors(refDestructuringErrors) || skipArrowSubscripts) return expr;
  733. return this.parseSubscripts(expr, startPos, startLoc);
  734. };
  735. pp.parseSubscripts = function (base, startPos, startLoc, noCalls) {
  736. for (;;) {
  737. if (this.eat(_tokentype.types.dot)) {
  738. var node = this.startNodeAt(startPos, startLoc);
  739. node.object = base;
  740. node.property = this.parseIdent(true);
  741. node.computed = false;
  742. base = this.finishNode(node, "MemberExpression");
  743. } else if (this.eat(_tokentype.types.bracketL)) {
  744. var node = this.startNodeAt(startPos, startLoc);
  745. node.object = base;
  746. node.property = this.parseExpression();
  747. node.computed = true;
  748. this.expect(_tokentype.types.bracketR);
  749. base = this.finishNode(node, "MemberExpression");
  750. } else if (!noCalls && this.eat(_tokentype.types.parenL)) {
  751. var node = this.startNodeAt(startPos, startLoc);
  752. node.callee = base;
  753. node.arguments = this.parseExprList(_tokentype.types.parenR, false);
  754. base = this.finishNode(node, "CallExpression");
  755. } else if (this.type === _tokentype.types.backQuote) {
  756. var node = this.startNodeAt(startPos, startLoc);
  757. node.tag = base;
  758. node.quasi = this.parseTemplate();
  759. base = this.finishNode(node, "TaggedTemplateExpression");
  760. } else {
  761. return base;
  762. }
  763. }
  764. };
  765. // Parse an atomic expression — either a single token that is an
  766. // expression, an expression started by a keyword like `function` or
  767. // `new`, or an expression wrapped in punctuation like `()`, `[]`,
  768. // or `{}`.
  769. pp.parseExprAtom = function (refDestructuringErrors) {
  770. var node = undefined,
  771. canBeArrow = this.potentialArrowAt == this.start;
  772. switch (this.type) {
  773. case _tokentype.types._super:
  774. if (!this.inFunction) this.raise(this.start, "'super' outside of function or class");
  775. case _tokentype.types._this:
  776. var type = this.type === _tokentype.types._this ? "ThisExpression" : "Super";
  777. node = this.startNode();
  778. this.next();
  779. return this.finishNode(node, type);
  780. case _tokentype.types.name:
  781. var startPos = this.start,
  782. startLoc = this.startLoc;
  783. var id = this.parseIdent(this.type !== _tokentype.types.name);
  784. if (canBeArrow && !this.canInsertSemicolon() && this.eat(_tokentype.types.arrow)) return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), [id]);
  785. return id;
  786. case _tokentype.types.regexp:
  787. var value = this.value;
  788. node = this.parseLiteral(value.value);
  789. node.regex = { pattern: value.pattern, flags: value.flags };
  790. return node;
  791. case _tokentype.types.num:case _tokentype.types.string:
  792. return this.parseLiteral(this.value);
  793. case _tokentype.types._null:case _tokentype.types._true:case _tokentype.types._false:
  794. node = this.startNode();
  795. node.value = this.type === _tokentype.types._null ? null : this.type === _tokentype.types._true;
  796. node.raw = this.type.keyword;
  797. this.next();
  798. return this.finishNode(node, "Literal");
  799. case _tokentype.types.parenL:
  800. return this.parseParenAndDistinguishExpression(canBeArrow);
  801. case _tokentype.types.bracketL:
  802. node = this.startNode();
  803. this.next();
  804. node.elements = this.parseExprList(_tokentype.types.bracketR, true, true, refDestructuringErrors);
  805. return this.finishNode(node, "ArrayExpression");
  806. case _tokentype.types.braceL:
  807. return this.parseObj(false, refDestructuringErrors);
  808. case _tokentype.types._function:
  809. node = this.startNode();
  810. this.next();
  811. return this.parseFunction(node, false);
  812. case _tokentype.types._class:
  813. return this.parseClass(this.startNode(), false);
  814. case _tokentype.types._new:
  815. return this.parseNew();
  816. case _tokentype.types.backQuote:
  817. return this.parseTemplate();
  818. default:
  819. this.unexpected();
  820. }
  821. };
  822. pp.parseLiteral = function (value) {
  823. var node = this.startNode();
  824. node.value = value;
  825. node.raw = this.input.slice(this.start, this.end);
  826. this.next();
  827. return this.finishNode(node, "Literal");
  828. };
  829. pp.parseParenExpression = function () {
  830. this.expect(_tokentype.types.parenL);
  831. var val = this.parseExpression();
  832. this.expect(_tokentype.types.parenR);
  833. return val;
  834. };
  835. pp.parseParenAndDistinguishExpression = function (canBeArrow) {
  836. var startPos = this.start,
  837. startLoc = this.startLoc,
  838. val = undefined;
  839. if (this.options.ecmaVersion >= 6) {
  840. this.next();
  841. var innerStartPos = this.start,
  842. innerStartLoc = this.startLoc;
  843. var exprList = [],
  844. first = true;
  845. var refDestructuringErrors = new _parseutil.DestructuringErrors(),
  846. spreadStart = undefined,
  847. innerParenStart = undefined;
  848. while (this.type !== _tokentype.types.parenR) {
  849. first ? first = false : this.expect(_tokentype.types.comma);
  850. if (this.type === _tokentype.types.ellipsis) {
  851. spreadStart = this.start;
  852. exprList.push(this.parseParenItem(this.parseRest()));
  853. break;
  854. } else {
  855. if (this.type === _tokentype.types.parenL && !innerParenStart) {
  856. innerParenStart = this.start;
  857. }
  858. exprList.push(this.parseMaybeAssign(false, refDestructuringErrors, this.parseParenItem));
  859. }
  860. }
  861. var innerEndPos = this.start,
  862. innerEndLoc = this.startLoc;
  863. this.expect(_tokentype.types.parenR);
  864. if (canBeArrow && !this.canInsertSemicolon() && this.eat(_tokentype.types.arrow)) {
  865. this.checkPatternErrors(refDestructuringErrors, true);
  866. if (innerParenStart) this.unexpected(innerParenStart);
  867. return this.parseParenArrowList(startPos, startLoc, exprList);
  868. }
  869. if (!exprList.length) this.unexpected(this.lastTokStart);
  870. if (spreadStart) this.unexpected(spreadStart);
  871. this.checkExpressionErrors(refDestructuringErrors, true);
  872. if (exprList.length > 1) {
  873. val = this.startNodeAt(innerStartPos, innerStartLoc);
  874. val.expressions = exprList;
  875. this.finishNodeAt(val, "SequenceExpression", innerEndPos, innerEndLoc);
  876. } else {
  877. val = exprList[0];
  878. }
  879. } else {
  880. val = this.parseParenExpression();
  881. }
  882. if (this.options.preserveParens) {
  883. var par = this.startNodeAt(startPos, startLoc);
  884. par.expression = val;
  885. return this.finishNode(par, "ParenthesizedExpression");
  886. } else {
  887. return val;
  888. }
  889. };
  890. pp.parseParenItem = function (item) {
  891. return item;
  892. };
  893. pp.parseParenArrowList = function (startPos, startLoc, exprList) {
  894. return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), exprList);
  895. };
  896. // New's precedence is slightly tricky. It must allow its argument to
  897. // be a `[]` or dot subscript expression, but not a call — at least,
  898. // not without wrapping it in parentheses. Thus, it uses the noCalls
  899. // argument to parseSubscripts to prevent it from consuming the
  900. // argument list.
  901. var empty = [];
  902. pp.parseNew = function () {
  903. var node = this.startNode();
  904. var meta = this.parseIdent(true);
  905. if (this.options.ecmaVersion >= 6 && this.eat(_tokentype.types.dot)) {
  906. node.meta = meta;
  907. node.property = this.parseIdent(true);
  908. if (node.property.name !== "target") this.raiseRecoverable(node.property.start, "The only valid meta property for new is new.target");
  909. if (!this.inFunction) this.raiseRecoverable(node.start, "new.target can only be used in functions");
  910. return this.finishNode(node, "MetaProperty");
  911. }
  912. var startPos = this.start,
  913. startLoc = this.startLoc;
  914. node.callee = this.parseSubscripts(this.parseExprAtom(), startPos, startLoc, true);
  915. if (this.eat(_tokentype.types.parenL)) node.arguments = this.parseExprList(_tokentype.types.parenR, false);else node.arguments = empty;
  916. return this.finishNode(node, "NewExpression");
  917. };
  918. // Parse template expression.
  919. pp.parseTemplateElement = function () {
  920. var elem = this.startNode();
  921. elem.value = {
  922. raw: this.input.slice(this.start, this.end).replace(/\r\n?/g, '\n'),
  923. cooked: this.value
  924. };
  925. this.next();
  926. elem.tail = this.type === _tokentype.types.backQuote;
  927. return this.finishNode(elem, "TemplateElement");
  928. };
  929. pp.parseTemplate = function () {
  930. var node = this.startNode();
  931. this.next();
  932. node.expressions = [];
  933. var curElt = this.parseTemplateElement();
  934. node.quasis = [curElt];
  935. while (!curElt.tail) {
  936. this.expect(_tokentype.types.dollarBraceL);
  937. node.expressions.push(this.parseExpression());
  938. this.expect(_tokentype.types.braceR);
  939. node.quasis.push(curElt = this.parseTemplateElement());
  940. }
  941. this.next();
  942. return this.finishNode(node, "TemplateLiteral");
  943. };
  944. // Parse an object literal or binding pattern.
  945. pp.parseObj = function (isPattern, refDestructuringErrors) {
  946. var node = this.startNode(),
  947. first = true,
  948. propHash = {};
  949. node.properties = [];
  950. this.next();
  951. while (!this.eat(_tokentype.types.braceR)) {
  952. if (!first) {
  953. this.expect(_tokentype.types.comma);
  954. if (this.afterTrailingComma(_tokentype.types.braceR)) break;
  955. } else first = false;
  956. var prop = this.startNode(),
  957. isGenerator = undefined,
  958. startPos = undefined,
  959. startLoc = undefined;
  960. if (this.options.ecmaVersion >= 6) {
  961. prop.method = false;
  962. prop.shorthand = false;
  963. if (isPattern || refDestructuringErrors) {
  964. startPos = this.start;
  965. startLoc = this.startLoc;
  966. }
  967. if (!isPattern) isGenerator = this.eat(_tokentype.types.star);
  968. }
  969. this.parsePropertyName(prop);
  970. this.parsePropertyValue(prop, isPattern, isGenerator, startPos, startLoc, refDestructuringErrors);
  971. this.checkPropClash(prop, propHash);
  972. node.properties.push(this.finishNode(prop, "Property"));
  973. }
  974. return this.finishNode(node, isPattern ? "ObjectPattern" : "ObjectExpression");
  975. };
  976. pp.parsePropertyValue = function (prop, isPattern, isGenerator, startPos, startLoc, refDestructuringErrors) {
  977. if (this.eat(_tokentype.types.colon)) {
  978. prop.value = isPattern ? this.parseMaybeDefault(this.start, this.startLoc) : this.parseMaybeAssign(false, refDestructuringErrors);
  979. prop.kind = "init";
  980. } else if (this.options.ecmaVersion >= 6 && this.type === _tokentype.types.parenL) {
  981. if (isPattern) this.unexpected();
  982. prop.kind = "init";
  983. prop.method = true;
  984. prop.value = this.parseMethod(isGenerator);
  985. } else if (this.options.ecmaVersion >= 5 && !prop.computed && prop.key.type === "Identifier" && (prop.key.name === "get" || prop.key.name === "set") && this.type != _tokentype.types.comma && this.type != _tokentype.types.braceR) {
  986. if (isGenerator || isPattern) this.unexpected();
  987. prop.kind = prop.key.name;
  988. this.parsePropertyName(prop);
  989. prop.value = this.parseMethod(false);
  990. var paramCount = prop.kind === "get" ? 0 : 1;
  991. if (prop.value.params.length !== paramCount) {
  992. var start = prop.value.start;
  993. if (prop.kind === "get") this.raiseRecoverable(start, "getter should have no params");else this.raiseRecoverable(start, "setter should have exactly one param");
  994. }
  995. if (prop.kind === "set" && prop.value.params[0].type === "RestElement") this.raiseRecoverable(prop.value.params[0].start, "Setter cannot use rest params");
  996. } else if (this.options.ecmaVersion >= 6 && !prop.computed && prop.key.type === "Identifier") {
  997. if (this.keywords.test(prop.key.name) || (this.strict ? this.reservedWordsStrictBind : this.reservedWords).test(prop.key.name) || this.inGenerator && prop.key.name == "yield") this.raiseRecoverable(prop.key.start, "'" + prop.key.name + "' can not be used as shorthand property");
  998. prop.kind = "init";
  999. if (isPattern) {
  1000. prop.value = this.parseMaybeDefault(startPos, startLoc, prop.key);
  1001. } else if (this.type === _tokentype.types.eq && refDestructuringErrors) {
  1002. if (!refDestructuringErrors.shorthandAssign) refDestructuringErrors.shorthandAssign = this.start;
  1003. prop.value = this.parseMaybeDefault(startPos, startLoc, prop.key);
  1004. } else {
  1005. prop.value = prop.key;
  1006. }
  1007. prop.shorthand = true;
  1008. } else this.unexpected();
  1009. };
  1010. pp.parsePropertyName = function (prop) {
  1011. if (this.options.ecmaVersion >= 6) {
  1012. if (this.eat(_tokentype.types.bracketL)) {
  1013. prop.computed = true;
  1014. prop.key = this.parseMaybeAssign();
  1015. this.expect(_tokentype.types.bracketR);
  1016. return prop.key;
  1017. } else {
  1018. prop.computed = false;
  1019. }
  1020. }
  1021. return prop.key = this.type === _tokentype.types.num || this.type === _tokentype.types.string ? this.parseExprAtom() : this.parseIdent(true);
  1022. };
  1023. // Initialize empty function node.
  1024. pp.initFunction = function (node) {
  1025. node.id = null;
  1026. if (this.options.ecmaVersion >= 6) {
  1027. node.generator = false;
  1028. node.expression = false;
  1029. }
  1030. };
  1031. // Parse object or class method.
  1032. pp.parseMethod = function (isGenerator) {
  1033. var node = this.startNode(),
  1034. oldInGen = this.inGenerator;
  1035. this.inGenerator = isGenerator;
  1036. this.initFunction(node);
  1037. this.expect(_tokentype.types.parenL);
  1038. node.params = this.parseBindingList(_tokentype.types.parenR, false, false);
  1039. if (this.options.ecmaVersion >= 6) node.generator = isGenerator;
  1040. this.parseFunctionBody(node, false);
  1041. this.inGenerator = oldInGen;
  1042. return this.finishNode(node, "FunctionExpression");
  1043. };
  1044. // Parse arrow function expression with given parameters.
  1045. pp.parseArrowExpression = function (node, params) {
  1046. var oldInGen = this.inGenerator;
  1047. this.inGenerator = false;
  1048. this.initFunction(node);
  1049. node.params = this.toAssignableList(params, true);
  1050. this.parseFunctionBody(node, true);
  1051. this.inGenerator = oldInGen;
  1052. return this.finishNode(node, "ArrowFunctionExpression");
  1053. };
  1054. // Parse function body and check parameters.
  1055. pp.parseFunctionBody = function (node, isArrowFunction) {
  1056. var isExpression = isArrowFunction && this.type !== _tokentype.types.braceL;
  1057. if (isExpression) {
  1058. node.body = this.parseMaybeAssign();
  1059. node.expression = true;
  1060. } else {
  1061. // Start a new scope with regard to labels and the `inFunction`
  1062. // flag (restore them to their old value afterwards).
  1063. var oldInFunc = this.inFunction,
  1064. oldLabels = this.labels;
  1065. this.inFunction = true;this.labels = [];
  1066. node.body = this.parseBlock(true);
  1067. node.expression = false;
  1068. this.inFunction = oldInFunc;this.labels = oldLabels;
  1069. }
  1070. // If this is a strict mode function, verify that argument names
  1071. // are not repeated, and it does not try to bind the words `eval`
  1072. // or `arguments`.
  1073. if (this.strict || !isExpression && node.body.body.length && this.isUseStrict(node.body.body[0])) {
  1074. var oldStrict = this.strict;
  1075. this.strict = true;
  1076. if (node.id) this.checkLVal(node.id, true);
  1077. this.checkParams(node);
  1078. this.strict = oldStrict;
  1079. } else if (isArrowFunction) {
  1080. this.checkParams(node);
  1081. }
  1082. };
  1083. // Checks function params for various disallowed patterns such as using "eval"
  1084. // or "arguments" and duplicate parameters.
  1085. pp.checkParams = function (node) {
  1086. var nameHash = {};
  1087. for (var i = 0; i < node.params.length; i++) {
  1088. this.checkLVal(node.params[i], true, nameHash);
  1089. }
  1090. };
  1091. // Parses a comma-separated list of expressions, and returns them as
  1092. // an array. `close` is the token type that ends the list, and
  1093. // `allowEmpty` can be turned on to allow subsequent commas with
  1094. // nothing in between them to be parsed as `null` (which is needed
  1095. // for array literals).
  1096. pp.parseExprList = function (close, allowTrailingComma, allowEmpty, refDestructuringErrors) {
  1097. var elts = [],
  1098. first = true;
  1099. while (!this.eat(close)) {
  1100. if (!first) {
  1101. this.expect(_tokentype.types.comma);
  1102. if (allowTrailingComma && this.afterTrailingComma(close)) break;
  1103. } else first = false;
  1104. var elt = undefined;
  1105. if (allowEmpty && this.type === _tokentype.types.comma) elt = null;else if (this.type === _tokentype.types.ellipsis) {
  1106. elt = this.parseSpread(refDestructuringErrors);
  1107. if (this.type === _tokentype.types.comma && refDestructuringErrors && !refDestructuringErrors.trailingComma) {
  1108. refDestructuringErrors.trailingComma = this.lastTokStart;
  1109. }
  1110. } else elt = this.parseMaybeAssign(false, refDestructuringErrors);
  1111. elts.push(elt);
  1112. }
  1113. return elts;
  1114. };
  1115. // Parse the next token as an identifier. If `liberal` is true (used
  1116. // when parsing properties), it will also convert keywords into
  1117. // identifiers.
  1118. pp.parseIdent = function (liberal) {
  1119. var node = this.startNode();
  1120. if (liberal && this.options.allowReserved == "never") liberal = false;
  1121. if (this.type === _tokentype.types.name) {
  1122. if (!liberal && (this.strict ? this.reservedWordsStrict : this.reservedWords).test(this.value) && (this.options.ecmaVersion >= 6 || this.input.slice(this.start, this.end).indexOf("\\") == -1)) this.raiseRecoverable(this.start, "The keyword '" + this.value + "' is reserved");
  1123. if (!liberal && this.inGenerator && this.value === "yield") this.raiseRecoverable(this.start, "Can not use 'yield' as identifier inside a generator");
  1124. node.name = this.value;
  1125. } else if (liberal && this.type.keyword) {
  1126. node.name = this.type.keyword;
  1127. } else {
  1128. this.unexpected();
  1129. }
  1130. this.next();
  1131. return this.finishNode(node, "Identifier");
  1132. };
  1133. // Parses yield expression inside generator.
  1134. pp.parseYield = function () {
  1135. var node = this.startNode();
  1136. this.next();
  1137. if (this.type == _tokentype.types.semi || this.canInsertSemicolon() || this.type != _tokentype.types.star && !this.type.startsExpr) {
  1138. node.delegate = false;
  1139. node.argument = null;
  1140. } else {
  1141. node.delegate = this.eat(_tokentype.types.star);
  1142. node.argument = this.parseMaybeAssign();
  1143. }
  1144. return this.finishNode(node, "YieldExpression");
  1145. };
  1146. },{"./parseutil":9,"./state":10,"./tokentype":14}],2:[function(_dereq_,module,exports){
  1147. // Reserved word lists for various dialects of the language
  1148. "use strict";
  1149. exports.__esModule = true;
  1150. exports.isIdentifierStart = isIdentifierStart;
  1151. exports.isIdentifierChar = isIdentifierChar;
  1152. var reservedWords = {
  1153. 3: "abstract boolean byte char class double enum export extends final float goto implements import int interface long native package private protected public short static super synchronized throws transient volatile",
  1154. 5: "class enum extends super const export import",
  1155. 6: "enum",
  1156. 7: "enum",
  1157. strict: "implements interface let package private protected public static yield",
  1158. strictBind: "eval arguments"
  1159. };
  1160. exports.reservedWords = reservedWords;
  1161. // And the keywords
  1162. 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";
  1163. var keywords = {
  1164. 5: ecma5AndLessKeywords,
  1165. 6: ecma5AndLessKeywords + " const class extends export import super"
  1166. };
  1167. exports.keywords = keywords;
  1168. // ## Character categories
  1169. // Big ugly regular expressions that match characters in the
  1170. // whitespace, identifier, and identifier-start categories. These
  1171. // are only applied when a character is found to actually have a
  1172. // code point above 128.
  1173. // Generated by `bin/generate-identifier-regex.js`.
  1174. var nonASCIIidentifierStartChars = "ªµºÀ-ÖØ-öø-ˁˆ-ˑˠ-ˤˬˮͰ-ʹͶͷͺ-ͽͿΆΈ-ΊΌΎ-ΡΣ-ϵϷ-ҁҊ-ԯԱ-Ֆՙա-ևא-תװ-ײؠ-يٮٯٱ-ۓەۥۦۮۯۺ-ۼۿܐܒ-ܯݍ-ޥޱߊ-ߪߴߵߺࠀ-ࠕࠚࠤࠨࡀ-ࡘࢠ-ࢴऄ-हऽॐक़-ॡॱ-ঀঅ-ঌএঐও-নপ-রলশ-হঽৎড়ঢ়য়-ৡৰৱਅ-ਊਏਐਓ-ਨਪ-ਰਲਲ਼ਵਸ਼ਸਹਖ਼-ੜਫ਼ੲ-ੴઅ-ઍએ-ઑઓ-નપ-રલળવ-હઽૐૠૡૹଅ-ଌଏଐଓ-ନପ-ରଲଳଵ-ହଽଡ଼ଢ଼ୟ-ୡୱஃஅ-ஊஎ-ஐஒ-கஙசஜஞடணதந-பம-ஹௐఅ-ఌఎ-ఐఒ-నప-హఽౘ-ౚౠౡಅ-ಌಎ-ಐಒ-ನಪ-ಳವ-ಹಽೞೠೡೱೲഅ-ഌഎ-ഐഒ-ഺഽൎൟ-ൡൺ-ൿඅ-ඖක-නඳ-රලව-ෆก-ะาำเ-ๆກຂຄງຈຊຍດ-ທນ-ຟມ-ຣລວສຫອ-ະາຳຽເ-ໄໆໜ-ໟༀཀ-ཇཉ-ཬྈ-ྌက-ဪဿၐ-ၕၚ-ၝၡၥၦၮ-ၰၵ-ႁႎႠ-ჅჇჍა-ჺჼ-ቈቊ-ቍቐ-ቖቘቚ-ቝበ-ኈኊ-ኍነ-ኰኲ-ኵኸ-ኾዀዂ-ዅወ-ዖዘ-ጐጒ-ጕጘ-ፚᎀ-ᎏᎠ-Ᏽᏸ-ᏽᐁ-ᙬᙯ-ᙿᚁ-ᚚᚠ-ᛪᛮ-ᛸᜀ-ᜌᜎ-ᜑᜠ-ᜱᝀ-ᝑᝠ-ᝬᝮ-ᝰក-ឳៗៜᠠ-ᡷᢀ-ᢨᢪᢰ-ᣵᤀ-ᤞᥐ-ᥭᥰ-ᥴᦀ-ᦫᦰ-ᧉᨀ-ᨖᨠ-ᩔᪧᬅ-ᬳᭅ-ᭋᮃ-ᮠᮮᮯᮺ-ᯥᰀ-ᰣᱍ-ᱏᱚ-ᱽᳩ-ᳬᳮ-ᳱᳵᳶᴀ-ᶿḀ-ἕἘ-Ἕἠ-ὅὈ-Ὅὐ-ὗὙὛὝὟ-ώᾀ-ᾴᾶ-ᾼιῂ-ῄῆ-ῌῐ-ΐῖ-Ίῠ-Ῥῲ-ῴῶ-ῼⁱⁿₐ-ₜℂℇℊ-ℓℕ℘-ℝℤΩℨK-ℹℼ-ℿⅅ-ⅉⅎⅠ-ↈⰀ-Ⱞⰰ-ⱞⱠ-ⳤⳫ-ⳮⳲⳳⴀ-ⴥⴧⴭⴰ-ⵧⵯⶀ-ⶖⶠ-ⶦⶨ-ⶮⶰ-ⶶⶸ-ⶾⷀ-ⷆⷈ-ⷎⷐ-ⷖⷘ-ⷞ々-〇〡-〩〱-〵〸-〼ぁ-ゖ゛-ゟァ-ヺー-ヿㄅ-ㄭㄱ-ㆎㆠ-ㆺㇰ-ㇿ㐀-䶵一-鿕ꀀ-ꒌꓐ-ꓽꔀ-ꘌꘐ-ꘟꘪꘫꙀ-ꙮꙿ-ꚝꚠ-ꛯꜗ-ꜟꜢ-ꞈꞋ-ꞭꞰ-ꞷꟷ-ꠁꠃ-ꠅꠇ-ꠊꠌ-ꠢꡀ-ꡳꢂ-ꢳꣲ-ꣷꣻꣽꤊ-ꤥꤰ-ꥆꥠ-ꥼꦄ-ꦲꧏꧠ-ꧤꧦ-ꧯꧺ-ꧾꨀ-ꨨꩀ-ꩂꩄ-ꩋꩠ-ꩶꩺꩾ-ꪯꪱꪵꪶꪹ-ꪽꫀꫂꫛ-ꫝꫠ-ꫪꫲ-ꫴꬁ-ꬆꬉ-ꬎꬑ-ꬖꬠ-ꬦꬨ-ꬮꬰ-ꭚꭜ-ꭥꭰ-ꯢ가-힣ힰ-ퟆퟋ-ퟻ豈-舘並-龎ff-stﬓ-ﬗיִײַ-ﬨשׁ-זּטּ-לּמּנּסּףּפּצּ-ﮱﯓ-ﴽﵐ-ﶏﶒ-ﷇﷰ-ﷻﹰ-ﹴﹶ-ﻼA-Za-zヲ-하-ᅦᅧ-ᅬᅭ-ᅲᅳ-ᅵ";
  1175. var nonASCIIidentifierChars = "‌‍·̀-ͯ·҃-֑҇-ׇֽֿׁׂׅׄؐ-ًؚ-٩ٰۖ-ۜ۟-۪ۤۧۨ-ۭ۰-۹ܑܰ-݊ަ-ް߀-߉߫-߳ࠖ-࠙ࠛ-ࠣࠥ-ࠧࠩ-࡙࠭-࡛ࣣ-ःऺ-़ा-ॏ॑-ॗॢॣ०-९ঁ-ঃ়া-ৄেৈো-্ৗৢৣ০-৯ਁ-ਃ਼ਾ-ੂੇੈੋ-੍ੑ੦-ੱੵઁ-ઃ઼ા-ૅે-ૉો-્ૢૣ૦-૯ଁ-ଃ଼ା-ୄେୈୋ-୍ୖୗୢୣ୦-୯ஂா-ூெ-ைொ-்ௗ௦-௯ఀ-ఃా-ౄె-ైొ-్ౕౖౢౣ౦-౯ಁ-ಃ಼ಾ-ೄೆ-ೈೊ-್ೕೖೢೣ೦-೯ഁ-ഃാ-ൄെ-ൈൊ-്ൗൢൣ൦-൯ංඃ්ා-ුූෘ-ෟ෦-෯ෲෳัิ-ฺ็-๎๐-๙ັິ-ູົຼ່-ໍ໐-໙༘༙༠-༩༹༵༷༾༿ཱ-྄྆྇ྍ-ྗྙ-ྼ࿆ါ-ှ၀-၉ၖ-ၙၞ-ၠၢ-ၤၧ-ၭၱ-ၴႂ-ႍႏ-ႝ፝-፟፩-፱ᜒ-᜔ᜲ-᜴ᝒᝓᝲᝳ឴-៓៝០-៩᠋-᠍᠐-᠙ᢩᤠ-ᤫᤰ-᤻᥆-᥏᧐-᧚ᨗ-ᨛᩕ-ᩞ᩠-᩿᩼-᪉᪐-᪙᪰-᪽ᬀ-ᬄ᬴-᭄᭐-᭙᭫-᭳ᮀ-ᮂᮡ-ᮭ᮰-᮹᯦-᯳ᰤ-᰷᱀-᱉᱐-᱙᳐-᳔᳒-᳨᳭ᳲ-᳴᳸᳹᷀-᷵᷼-᷿‿⁀⁔⃐-⃥⃜⃡-⃰⳯-⵿⳱ⷠ-〪ⷿ-゙゚〯꘠-꘩꙯ꙴ-꙽ꚞꚟ꛰꛱ꠂ꠆ꠋꠣ-ꠧꢀꢁꢴ-꣄꣐-꣙꣠-꣱꤀-꤉ꤦ-꤭ꥇ-꥓ꦀ-ꦃ꦳-꧀꧐-꧙ꧥ꧰-꧹ꨩ-ꨶꩃꩌꩍ꩐-꩙ꩻ-ꩽꪰꪲ-ꪴꪷꪸꪾ꪿꫁ꫫ-ꫯꫵ꫶ꯣ-ꯪ꯬꯭꯰-꯹ﬞ︀-️︠-︯︳︴﹍-﹏0-9_";
  1176. var nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]");
  1177. var nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]");
  1178. nonASCIIidentifierStartChars = nonASCIIidentifierChars = null;
  1179. // These are a run-length and offset encoded representation of the
  1180. // >0xffff code points that are a valid part of identifiers. The
  1181. // offset starts at 0x10000, and each pair of numbers represents an
  1182. // offset to the next range, and then a size of the range. They were
  1183. // generated by bin/generate-identifier-regex.js
  1184. 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, 66, 18, 2, 1, 11, 21, 11, 25, 71, 55, 7, 1, 65, 0, 16, 3, 2, 2, 2, 26, 45, 28, 4, 28, 36, 7, 2, 27, 28, 53, 11, 21, 11, 18, 14, 17, 111, 72, 56, 50, 14, 50, 785, 52, 76, 44, 33, 24, 27, 35, 42, 34, 4, 0, 13, 47, 15, 3, 22, 0, 2, 0, 36, 17, 2, 24, 85, 6, 2, 0, 2, 3, 2, 14, 2, 9, 8, 46, 39, 7, 3, 1, 3, 21, 2, 6, 2, 1, 2, 4, 4, 0, 19, 0, 13, 4, 287, 47, 21, 1, 2, 0, 185, 46, 42, 3, 37, 47, 21, 0, 60, 42, 86, 25, 391, 63, 32, 0, 449, 56, 1288, 921, 103, 110, 18, 195, 2749, 1070, 4050, 582, 8634, 568, 8, 30, 114, 29, 19, 47, 17, 3, 32, 20, 6, 18, 881, 68, 12, 0, 67, 12, 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, 3, 5761, 10591, 541];
  1185. var astralIdentifierCodes = [509, 0, 227, 0, 150, 4, 294, 9, 1368, 2, 2, 1, 6, 3, 41, 2, 5, 0, 166, 1, 1306, 2, 54, 14, 32, 9, 16, 3, 46, 10, 54, 9, 7, 2, 37, 13, 2, 9, 52, 0, 13, 2, 49, 13, 10, 2, 4, 9, 83, 11, 168, 11, 6, 9, 7, 3, 57, 0, 2, 6, 3, 1, 3, 2, 10, 0, 11, 1, 3, 6, 4, 4, 316, 19, 13, 9, 214, 6, 3, 8, 28, 1, 83, 16, 16, 9, 82, 12, 9, 9, 84, 14, 5, 9, 423, 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, 513, 54, 5, 49, 9, 0, 15, 0, 23, 4, 2, 14, 3617, 6, 792618, 239];
  1186. // This has a complexity linear to the value of the code. The
  1187. // assumption is that looking up astral identifier characters is
  1188. // rare.
  1189. function isInAstralSet(code, set) {
  1190. var pos = 0x10000;
  1191. for (var i = 0; i < set.length; i += 2) {
  1192. pos += set[i];
  1193. if (pos > code) return false;
  1194. pos += set[i + 1];
  1195. if (pos >= code) return true;
  1196. }
  1197. }
  1198. // Test whether a given character code starts an identifier.
  1199. function isIdentifierStart(code, astral) {
  1200. if (code < 65) return code === 36;
  1201. if (code < 91) return true;
  1202. if (code < 97) return code === 95;
  1203. if (code < 123) return true;
  1204. if (code <= 0xffff) return code >= 0xaa && nonASCIIidentifierStart.test(String.fromCharCode(code));
  1205. if (astral === false) return false;
  1206. return isInAstralSet(code, astralIdentifierStartCodes);
  1207. }
  1208. // Test whether a given character is part of an identifier.
  1209. function isIdentifierChar(code, astral) {
  1210. if (code < 48) return code === 36;
  1211. if (code < 58) return true;
  1212. if (code < 65) return false;
  1213. if (code < 91) return true;
  1214. if (code < 97) return code === 95;
  1215. if (code < 123) return true;
  1216. if (code <= 0xffff) return code >= 0xaa && nonASCIIidentifier.test(String.fromCharCode(code));
  1217. if (astral === false) return false;
  1218. return isInAstralSet(code, astralIdentifierStartCodes) || isInAstralSet(code, astralIdentifierCodes);
  1219. }
  1220. },{}],3:[function(_dereq_,module,exports){
  1221. // Acorn is a tiny, fast JavaScript parser written in JavaScript.
  1222. //
  1223. // Acorn was written by Marijn Haverbeke, Ingvar Stepanyan, and
  1224. // various contributors and released under an MIT license.
  1225. //
  1226. // Git repositories for Acorn are available at
  1227. //
  1228. // http://marijnhaverbeke.nl/git/acorn
  1229. // https://github.com/ternjs/acorn.git
  1230. //
  1231. // Please use the [github bug tracker][ghbt] to report issues.
  1232. //
  1233. // [ghbt]: https://github.com/ternjs/acorn/issues
  1234. //
  1235. // This file defines the main parser interface. The library also comes
  1236. // with a [error-tolerant parser][dammit] and an
  1237. // [abstract syntax tree walker][walk], defined in other files.
  1238. //
  1239. // [dammit]: acorn_loose.js
  1240. // [walk]: util/walk.js
  1241. "use strict";
  1242. exports.__esModule = true;
  1243. exports.parse = parse;
  1244. exports.parseExpressionAt = parseExpressionAt;
  1245. exports.tokenizer = tokenizer;
  1246. var _state = _dereq_("./state");
  1247. _dereq_("./parseutil");
  1248. _dereq_("./statement");
  1249. _dereq_("./lval");
  1250. _dereq_("./expression");
  1251. _dereq_("./location");
  1252. exports.Parser = _state.Parser;
  1253. exports.plugins = _state.plugins;
  1254. var _options = _dereq_("./options");
  1255. exports.defaultOptions = _options.defaultOptions;
  1256. var _locutil = _dereq_("./locutil");
  1257. exports.Position = _locutil.Position;
  1258. exports.SourceLocation = _locutil.SourceLocation;
  1259. exports.getLineInfo = _locutil.getLineInfo;
  1260. var _node = _dereq_("./node");
  1261. exports.Node = _node.Node;
  1262. var _tokentype = _dereq_("./tokentype");
  1263. exports.TokenType = _tokentype.TokenType;
  1264. exports.tokTypes = _tokentype.types;
  1265. var _tokencontext = _dereq_("./tokencontext");
  1266. exports.TokContext = _tokencontext.TokContext;
  1267. exports.tokContexts = _tokencontext.types;
  1268. var _identifier = _dereq_("./identifier");
  1269. exports.isIdentifierChar = _identifier.isIdentifierChar;
  1270. exports.isIdentifierStart = _identifier.isIdentifierStart;
  1271. var _tokenize = _dereq_("./tokenize");
  1272. exports.Token = _tokenize.Token;
  1273. var _whitespace = _dereq_("./whitespace");
  1274. exports.isNewLine = _whitespace.isNewLine;
  1275. exports.lineBreak = _whitespace.lineBreak;
  1276. exports.lineBreakG = _whitespace.lineBreakG;
  1277. var version = "3.1.0";
  1278. exports.version = version;
  1279. // The main exported interface (under `self.acorn` when in the
  1280. // browser) is a `parse` function that takes a code string and
  1281. // returns an abstract syntax tree as specified by [Mozilla parser
  1282. // API][api].
  1283. //
  1284. // [api]: https://developer.mozilla.org/en-US/docs/SpiderMonkey/Parser_API
  1285. function parse(input, options) {
  1286. return new _state.Parser(options, input).parse();
  1287. }
  1288. // This function tries to parse a single expression at a given
  1289. // offset in a string. Useful for parsing mixed-language formats
  1290. // that embed JavaScript expressions.
  1291. function parseExpressionAt(input, pos, options) {
  1292. var p = new _state.Parser(options, input, pos);
  1293. p.nextToken();
  1294. return p.parseExpression();
  1295. }
  1296. // Acorn is organized as a tokenizer and a recursive-descent parser.
  1297. // The `tokenizer` export provides an interface to the tokenizer.
  1298. function tokenizer(input, options) {
  1299. return new _state.Parser(options, input);
  1300. }
  1301. },{"./expression":1,"./identifier":2,"./location":4,"./locutil":5,"./lval":6,"./node":7,"./options":8,"./parseutil":9,"./state":10,"./statement":11,"./tokencontext":12,"./tokenize":13,"./tokentype":14,"./whitespace":16}],4:[function(_dereq_,module,exports){
  1302. "use strict";
  1303. var _state = _dereq_("./state");
  1304. var _locutil = _dereq_("./locutil");
  1305. var pp = _state.Parser.prototype;
  1306. // This function is used to raise exceptions on parse errors. It
  1307. // takes an offset integer (into the current `input`) to indicate
  1308. // the location of the error, attaches the position to the end
  1309. // of the error message, and then raises a `SyntaxError` with that
  1310. // message.
  1311. pp.raise = function (pos, message) {
  1312. var loc = _locutil.getLineInfo(this.input, pos);
  1313. message += " (" + loc.line + ":" + loc.column + ")";
  1314. var err = new SyntaxError(message);
  1315. err.pos = pos;err.loc = loc;err.raisedAt = this.pos;
  1316. throw err;
  1317. };
  1318. pp.raiseRecoverable = pp.raise;
  1319. pp.curPosition = function () {
  1320. if (this.options.locations) {
  1321. return new _locutil.Position(this.curLine, this.pos - this.lineStart);
  1322. }
  1323. };
  1324. },{"./locutil":5,"./state":10}],5:[function(_dereq_,module,exports){
  1325. "use strict";
  1326. exports.__esModule = true;
  1327. exports.getLineInfo = getLineInfo;
  1328. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  1329. var _whitespace = _dereq_("./whitespace");
  1330. // These are used when `options.locations` is on, for the
  1331. // `startLoc` and `endLoc` properties.
  1332. var Position = (function () {
  1333. function Position(line, col) {
  1334. _classCallCheck(this, Position);
  1335. this.line = line;
  1336. this.column = col;
  1337. }
  1338. Position.prototype.offset = function offset(n) {
  1339. return new Position(this.line, this.column + n);
  1340. };
  1341. return Position;
  1342. })();
  1343. exports.Position = Position;
  1344. var SourceLocation = function SourceLocation(p, start, end) {
  1345. _classCallCheck(this, SourceLocation);
  1346. this.start = start;
  1347. this.end = end;
  1348. if (p.sourceFile !== null) this.source = p.sourceFile;
  1349. }
  1350. // The `getLineInfo` function is mostly useful when the
  1351. // `locations` option is off (for performance reasons) and you
  1352. // want to find the line/column position for a given character
  1353. // offset. `input` should be the code string that the offset refers
  1354. // into.
  1355. ;
  1356. exports.SourceLocation = SourceLocation;
  1357. function getLineInfo(input, offset) {
  1358. for (var line = 1, cur = 0;;) {
  1359. _whitespace.lineBreakG.lastIndex = cur;
  1360. var match = _whitespace.lineBreakG.exec(input);
  1361. if (match && match.index < offset) {
  1362. ++line;
  1363. cur = match.index + match[0].length;
  1364. } else {
  1365. return new Position(line, offset - cur);
  1366. }
  1367. }
  1368. }
  1369. },{"./whitespace":16}],6:[function(_dereq_,module,exports){
  1370. "use strict";
  1371. var _tokentype = _dereq_("./tokentype");
  1372. var _state = _dereq_("./state");
  1373. var _util = _dereq_("./util");
  1374. var pp = _state.Parser.prototype;
  1375. // Convert existing expression atom to assignable pattern
  1376. // if possible.
  1377. pp.toAssignable = function (node, isBinding) {
  1378. if (this.options.ecmaVersion >= 6 && node) {
  1379. switch (node.type) {
  1380. case "Identifier":
  1381. case "ObjectPattern":
  1382. case "ArrayPattern":
  1383. break;
  1384. case "ObjectExpression":
  1385. node.type = "ObjectPattern";
  1386. for (var i = 0; i < node.properties.length; i++) {
  1387. var prop = node.properties[i];
  1388. if (prop.kind !== "init") this.raise(prop.key.start, "Object pattern can't contain getter or setter");
  1389. this.toAssignable(prop.value, isBinding);
  1390. }
  1391. break;
  1392. case "ArrayExpression":
  1393. node.type = "ArrayPattern";
  1394. this.toAssignableList(node.elements, isBinding);
  1395. break;
  1396. case "AssignmentExpression":
  1397. if (node.operator === "=") {
  1398. node.type = "AssignmentPattern";
  1399. delete node.operator;
  1400. // falls through to AssignmentPattern
  1401. } else {
  1402. this.raise(node.left.end, "Only '=' operator can be used for specifying default value.");
  1403. break;
  1404. }
  1405. case "AssignmentPattern":
  1406. if (node.right.type === "YieldExpression") this.raise(node.right.start, "Yield expression cannot be a default value");
  1407. break;
  1408. case "ParenthesizedExpression":
  1409. node.expression = this.toAssignable(node.expression, isBinding);
  1410. break;
  1411. case "MemberExpression":
  1412. if (!isBinding) break;
  1413. default:
  1414. this.raise(node.start, "Assigning to rvalue");
  1415. }
  1416. }
  1417. return node;
  1418. };
  1419. // Convert list of expression atoms to binding list.
  1420. pp.toAssignableList = function (exprList, isBinding) {
  1421. var end = exprList.length;
  1422. if (end) {
  1423. var last = exprList[end - 1];
  1424. if (last && last.type == "RestElement") {
  1425. --end;
  1426. } else if (last && last.type == "SpreadElement") {
  1427. last.type = "RestElement";
  1428. var arg = last.argument;
  1429. this.toAssignable(arg, isBinding);
  1430. if (arg.type !== "Identifier" && arg.type !== "MemberExpression" && arg.type !== "ArrayPattern") this.unexpected(arg.start);
  1431. --end;
  1432. }
  1433. if (isBinding && last.type === "RestElement" && last.argument.type !== "Identifier") this.unexpected(last.argument.start);
  1434. }
  1435. for (var i = 0; i < end; i++) {
  1436. var elt = exprList[i];
  1437. if (elt) this.toAssignable(elt, isBinding);
  1438. }
  1439. return exprList;
  1440. };
  1441. // Parses spread element.
  1442. pp.parseSpread = function (refDestructuringErrors) {
  1443. var node = this.startNode();
  1444. this.next();
  1445. node.argument = this.parseMaybeAssign(refDestructuringErrors);
  1446. return this.finishNode(node, "SpreadElement");
  1447. };
  1448. pp.parseRest = function (allowNonIdent) {
  1449. var node = this.startNode();
  1450. this.next();
  1451. // RestElement inside of a function parameter must be an identifier
  1452. if (allowNonIdent) node.argument = this.type === _tokentype.types.name ? this.parseIdent() : this.unexpected();else node.argument = this.type === _tokentype.types.name || this.type === _tokentype.types.bracketL ? this.parseBindingAtom() : this.unexpected();
  1453. return this.finishNode(node, "RestElement");
  1454. };
  1455. // Parses lvalue (assignable) atom.
  1456. pp.parseBindingAtom = function () {
  1457. if (this.options.ecmaVersion < 6) return this.parseIdent();
  1458. switch (this.type) {
  1459. case _tokentype.types.name:
  1460. return this.parseIdent();
  1461. case _tokentype.types.bracketL:
  1462. var node = this.startNode();
  1463. this.next();
  1464. node.elements = this.parseBindingList(_tokentype.types.bracketR, true, true);
  1465. return this.finishNode(node, "ArrayPattern");
  1466. case _tokentype.types.braceL:
  1467. return this.parseObj(true);
  1468. default:
  1469. this.unexpected();
  1470. }
  1471. };
  1472. pp.parseBindingList = function (close, allowEmpty, allowTrailingComma, allowNonIdent) {
  1473. var elts = [],
  1474. first = true;
  1475. while (!this.eat(close)) {
  1476. if (first) first = false;else this.expect(_tokentype.types.comma);
  1477. if (allowEmpty && this.type === _tokentype.types.comma) {
  1478. elts.push(null);
  1479. } else if (allowTrailingComma && this.afterTrailingComma(close)) {
  1480. break;
  1481. } else if (this.type === _tokentype.types.ellipsis) {
  1482. var rest = this.parseRest(allowNonIdent);
  1483. this.parseBindingListItem(rest);
  1484. elts.push(rest);
  1485. if (this.type === _tokentype.types.comma) this.raise(this.start, "Comma is not permitted after the rest element");
  1486. this.expect(close);
  1487. break;
  1488. } else {
  1489. var elem = this.parseMaybeDefault(this.start, this.startLoc);
  1490. this.parseBindingListItem(elem);
  1491. elts.push(elem);
  1492. }
  1493. }
  1494. return elts;
  1495. };
  1496. pp.parseBindingListItem = function (param) {
  1497. return param;
  1498. };
  1499. // Parses assignment pattern around given atom if possible.
  1500. pp.parseMaybeDefault = function (startPos, startLoc, left) {
  1501. left = left || this.parseBindingAtom();
  1502. if (this.options.ecmaVersion < 6 || !this.eat(_tokentype.types.eq)) return left;
  1503. var node = this.startNodeAt(startPos, startLoc);
  1504. node.left = left;
  1505. node.right = this.parseMaybeAssign();
  1506. return this.finishNode(node, "AssignmentPattern");
  1507. };
  1508. // Verify that a node is an lval — something that can be assigned
  1509. // to.
  1510. pp.checkLVal = function (expr, isBinding, checkClashes) {
  1511. switch (expr.type) {
  1512. case "Identifier":
  1513. if (this.strict && this.reservedWordsStrictBind.test(expr.name)) this.raiseRecoverable(expr.start, (isBinding ? "Binding " : "Assigning to ") + expr.name + " in strict mode");
  1514. if (checkClashes) {
  1515. if (_util.has(checkClashes, expr.name)) this.raiseRecoverable(expr.start, "Argument name clash");
  1516. checkClashes[expr.name] = true;
  1517. }
  1518. break;
  1519. case "MemberExpression":
  1520. if (isBinding) this.raiseRecoverable(expr.start, (isBinding ? "Binding" : "Assigning to") + " member expression");
  1521. break;
  1522. case "ObjectPattern":
  1523. for (var i = 0; i < expr.properties.length; i++) {
  1524. this.checkLVal(expr.properties[i].value, isBinding, checkClashes);
  1525. }break;
  1526. case "ArrayPattern":
  1527. for (var i = 0; i < expr.elements.length; i++) {
  1528. var elem = expr.elements[i];
  1529. if (elem) this.checkLVal(elem, isBinding, checkClashes);
  1530. }
  1531. break;
  1532. case "AssignmentPattern":
  1533. this.checkLVal(expr.left, isBinding, checkClashes);
  1534. break;
  1535. case "RestElement":
  1536. this.checkLVal(expr.argument, isBinding, checkClashes);
  1537. break;
  1538. case "ParenthesizedExpression":
  1539. this.checkLVal(expr.expression, isBinding, checkClashes);
  1540. break;
  1541. default:
  1542. this.raise(expr.start, (isBinding ? "Binding" : "Assigning to") + " rvalue");
  1543. }
  1544. };
  1545. },{"./state":10,"./tokentype":14,"./util":15}],7:[function(_dereq_,module,exports){
  1546. "use strict";
  1547. exports.__esModule = true;
  1548. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  1549. var _state = _dereq_("./state");
  1550. var _locutil = _dereq_("./locutil");
  1551. var Node = function Node(parser, pos, loc) {
  1552. _classCallCheck(this, Node);
  1553. this.type = "";
  1554. this.start = pos;
  1555. this.end = 0;
  1556. if (parser.options.locations) this.loc = new _locutil.SourceLocation(parser, loc);
  1557. if (parser.options.directSourceFile) this.sourceFile = parser.options.directSourceFile;
  1558. if (parser.options.ranges) this.range = [pos, 0];
  1559. }
  1560. // Start an AST node, attaching a start offset.
  1561. ;
  1562. exports.Node = Node;
  1563. var pp = _state.Parser.prototype;
  1564. pp.startNode = function () {
  1565. return new Node(this, this.start, this.startLoc);
  1566. };
  1567. pp.startNodeAt = function (pos, loc) {
  1568. return new Node(this, pos, loc);
  1569. };
  1570. // Finish an AST node, adding `type` and `end` properties.
  1571. function finishNodeAt(node, type, pos, loc) {
  1572. node.type = type;
  1573. node.end = pos;
  1574. if (this.options.locations) node.loc.end = loc;
  1575. if (this.options.ranges) node.range[1] = pos;
  1576. return node;
  1577. }
  1578. pp.finishNode = function (node, type) {
  1579. return finishNodeAt.call(this, node, type, this.lastTokEnd, this.lastTokEndLoc);
  1580. };
  1581. // Finish node at given position
  1582. pp.finishNodeAt = function (node, type, pos, loc) {
  1583. return finishNodeAt.call(this, node, type, pos, loc);
  1584. };
  1585. },{"./locutil":5,"./state":10}],8:[function(_dereq_,module,exports){
  1586. "use strict";
  1587. exports.__esModule = true;
  1588. exports.getOptions = getOptions;
  1589. var _util = _dereq_("./util");
  1590. var _locutil = _dereq_("./locutil");
  1591. // A second optional argument can be given to further configure
  1592. // the parser process. These options are recognized:
  1593. var defaultOptions = {
  1594. // `ecmaVersion` indicates the ECMAScript version to parse. Must
  1595. // be either 3, or 5, or 6. This influences support for strict
  1596. // mode, the set of reserved words, support for getters and
  1597. // setters and other features. The default is 6.
  1598. ecmaVersion: 6,
  1599. // Source type ("script" or "module") for different semantics
  1600. sourceType: "script",
  1601. // `onInsertedSemicolon` can be a callback that will be called
  1602. // when a semicolon is automatically inserted. It will be passed
  1603. // th position of the comma as an offset, and if `locations` is
  1604. // enabled, it is given the location as a `{line, column}` object
  1605. // as second argument.
  1606. onInsertedSemicolon: null,
  1607. // `onTrailingComma` is similar to `onInsertedSemicolon`, but for
  1608. // trailing commas.
  1609. onTrailingComma: null,
  1610. // By default, reserved words are only enforced if ecmaVersion >= 5.
  1611. // Set `allowReserved` to a boolean value to explicitly turn this on
  1612. // an off. When this option has the value "never", reserved words
  1613. // and keywords can also not be used as property names.
  1614. allowReserved: null,
  1615. // When enabled, a return at the top level is not considered an
  1616. // error.
  1617. allowReturnOutsideFunction: false,
  1618. // When enabled, import/export statements are not constrained to
  1619. // appearing at the top of the program.
  1620. allowImportExportEverywhere: false,
  1621. // When enabled, hashbang directive in the beginning of file
  1622. // is allowed and treated as a line comment.
  1623. allowHashBang: false,
  1624. // When `locations` is on, `loc` properties holding objects with
  1625. // `start` and `end` properties in `{line, column}` form (with
  1626. // line being 1-based and column 0-based) will be attached to the
  1627. // nodes.
  1628. locations: false,
  1629. // A function can be passed as `onToken` option, which will
  1630. // cause Acorn to call that function with object in the same
  1631. // format as tokens returned from `tokenizer().getToken()`. Note
  1632. // that you are not allowed to call the parser from the
  1633. // callback—that will corrupt its internal state.
  1634. onToken: null,
  1635. // A function can be passed as `onComment` option, which will
  1636. // cause Acorn to call that function with `(block, text, start,
  1637. // end)` parameters whenever a comment is skipped. `block` is a
  1638. // boolean indicating whether this is a block (`/* */`) comment,
  1639. // `text` is the content of the comment, and `start` and `end` are
  1640. // character offsets that denote the start and end of the comment.
  1641. // When the `locations` option is on, two more parameters are
  1642. // passed, the full `{line, column}` locations of the start and
  1643. // end of the comments. Note that you are not allowed to call the
  1644. // parser from the callback—that will corrupt its internal state.
  1645. onComment: null,
  1646. // Nodes have their start and end characters offsets recorded in
  1647. // `start` and `end` properties (directly on the node, rather than
  1648. // the `loc` object, which holds line/column data. To also add a
  1649. // [semi-standardized][range] `range` property holding a `[start,
  1650. // end]` array with the same numbers, set the `ranges` option to
  1651. // `true`.
  1652. //
  1653. // [range]: https://bugzilla.mozilla.org/show_bug.cgi?id=745678
  1654. ranges: false,
  1655. // It is possible to parse multiple files into a single AST by
  1656. // passing the tree produced by parsing the first file as
  1657. // `program` option in subsequent parses. This will add the
  1658. // toplevel forms of the parsed file to the `Program` (top) node
  1659. // of an existing parse tree.
  1660. program: null,
  1661. // When `locations` is on, you can pass this to record the source
  1662. // file in every node's `loc` object.
  1663. sourceFile: null,
  1664. // This value, if given, is stored in every node, whether
  1665. // `locations` is on or off.
  1666. directSourceFile: null,
  1667. // When enabled, parenthesized expressions are represented by
  1668. // (non-standard) ParenthesizedExpression nodes
  1669. preserveParens: false,
  1670. plugins: {}
  1671. };
  1672. exports.defaultOptions = defaultOptions;
  1673. // Interpret and default an options object
  1674. function getOptions(opts) {
  1675. var options = {};
  1676. for (var opt in defaultOptions) {
  1677. options[opt] = opts && _util.has(opts, opt) ? opts[opt] : defaultOptions[opt];
  1678. }if (options.allowReserved == null) options.allowReserved = options.ecmaVersion < 5;
  1679. if (_util.isArray(options.onToken)) {
  1680. (function () {
  1681. var tokens = options.onToken;
  1682. options.onToken = function (token) {
  1683. return tokens.push(token);
  1684. };
  1685. })();
  1686. }
  1687. if (_util.isArray(options.onComment)) options.onComment = pushComment(options, options.onComment);
  1688. return options;
  1689. }
  1690. function pushComment(options, array) {
  1691. return function (block, text, start, end, startLoc, endLoc) {
  1692. var comment = {
  1693. type: block ? 'Block' : 'Line',
  1694. value: text,
  1695. start: start,
  1696. end: end
  1697. };
  1698. if (options.locations) comment.loc = new _locutil.SourceLocation(this, startLoc, endLoc);
  1699. if (options.ranges) comment.range = [start, end];
  1700. array.push(comment);
  1701. };
  1702. }
  1703. },{"./locutil":5,"./util":15}],9:[function(_dereq_,module,exports){
  1704. "use strict";
  1705. exports.__esModule = true;
  1706. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  1707. var _tokentype = _dereq_("./tokentype");
  1708. var _state = _dereq_("./state");
  1709. var _whitespace = _dereq_("./whitespace");
  1710. var pp = _state.Parser.prototype;
  1711. // ## Parser utilities
  1712. // Test whether a statement node is the string literal `"use strict"`.
  1713. pp.isUseStrict = function (stmt) {
  1714. return this.options.ecmaVersion >= 5 && stmt.type === "ExpressionStatement" && stmt.expression.type === "Literal" && stmt.expression.raw.slice(1, -1) === "use strict";
  1715. };
  1716. // Predicate that tests whether the next token is of the given
  1717. // type, and if yes, consumes it as a side effect.
  1718. pp.eat = function (type) {
  1719. if (this.type === type) {
  1720. this.next();
  1721. return true;
  1722. } else {
  1723. return false;
  1724. }
  1725. };
  1726. // Tests whether parsed token is a contextual keyword.
  1727. pp.isContextual = function (name) {
  1728. return this.type === _tokentype.types.name && this.value === name;
  1729. };
  1730. // Consumes contextual keyword if possible.
  1731. pp.eatContextual = function (name) {
  1732. return this.value === name && this.eat(_tokentype.types.name);
  1733. };
  1734. // Asserts that following token is given contextual keyword.
  1735. pp.expectContextual = function (name) {
  1736. if (!this.eatContextual(name)) this.unexpected();
  1737. };
  1738. // Test whether a semicolon can be inserted at the current position.
  1739. pp.canInsertSemicolon = function () {
  1740. return this.type === _tokentype.types.eof || this.type === _tokentype.types.braceR || _whitespace.lineBreak.test(this.input.slice(this.lastTokEnd, this.start));
  1741. };
  1742. pp.insertSemicolon = function () {
  1743. if (this.canInsertSemicolon()) {
  1744. if (this.options.onInsertedSemicolon) this.options.onInsertedSemicolon(this.lastTokEnd, this.lastTokEndLoc);
  1745. return true;
  1746. }
  1747. };
  1748. // Consume a semicolon, or, failing that, see if we are allowed to
  1749. // pretend that there is a semicolon at this position.
  1750. pp.semicolon = function () {
  1751. if (!this.eat(_tokentype.types.semi) && !this.insertSemicolon()) this.unexpected();
  1752. };
  1753. pp.afterTrailingComma = function (tokType) {
  1754. if (this.type == tokType) {
  1755. if (this.options.onTrailingComma) this.options.onTrailingComma(this.lastTokStart, this.lastTokStartLoc);
  1756. this.next();
  1757. return true;
  1758. }
  1759. };
  1760. // Expect a token of a given type. If found, consume it, otherwise,
  1761. // raise an unexpected token error.
  1762. pp.expect = function (type) {
  1763. this.eat(type) || this.unexpected();
  1764. };
  1765. // Raise an unexpected token error.
  1766. pp.unexpected = function (pos) {
  1767. this.raise(pos != null ? pos : this.start, "Unexpected token");
  1768. };
  1769. var DestructuringErrors = function DestructuringErrors() {
  1770. _classCallCheck(this, DestructuringErrors);
  1771. this.shorthandAssign = 0;
  1772. this.trailingComma = 0;
  1773. };
  1774. exports.DestructuringErrors = DestructuringErrors;
  1775. pp.checkPatternErrors = function (refDestructuringErrors, andThrow) {
  1776. var trailing = refDestructuringErrors && refDestructuringErrors.trailingComma;
  1777. if (!andThrow) return !!trailing;
  1778. if (trailing) this.raise(trailing, "Comma is not permitted after the rest element");
  1779. };
  1780. pp.checkExpressionErrors = function (refDestructuringErrors, andThrow) {
  1781. var pos = refDestructuringErrors && refDestructuringErrors.shorthandAssign;
  1782. if (!andThrow) return !!pos;
  1783. if (pos) this.raise(pos, "Shorthand property assignments are valid only in destructuring patterns");
  1784. };
  1785. },{"./state":10,"./tokentype":14,"./whitespace":16}],10:[function(_dereq_,module,exports){
  1786. "use strict";
  1787. exports.__esModule = true;
  1788. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  1789. var _identifier = _dereq_("./identifier");
  1790. var _tokentype = _dereq_("./tokentype");
  1791. var _whitespace = _dereq_("./whitespace");
  1792. var _options = _dereq_("./options");
  1793. // Registered plugins
  1794. var plugins = {};
  1795. exports.plugins = plugins;
  1796. function keywordRegexp(words) {
  1797. return new RegExp("^(" + words.replace(/ /g, "|") + ")$");
  1798. }
  1799. var Parser = (function () {
  1800. function Parser(options, input, startPos) {
  1801. _classCallCheck(this, Parser);
  1802. this.options = options = _options.getOptions(options);
  1803. this.sourceFile = options.sourceFile;
  1804. this.keywords = keywordRegexp(_identifier.keywords[options.ecmaVersion >= 6 ? 6 : 5]);
  1805. var reserved = options.allowReserved ? "" : _identifier.reservedWords[options.ecmaVersion] + (options.sourceType == "module" ? " await" : "");
  1806. this.reservedWords = keywordRegexp(reserved);
  1807. var reservedStrict = (reserved ? reserved + " " : "") + _identifier.reservedWords.strict;
  1808. this.reservedWordsStrict = keywordRegexp(reservedStrict);
  1809. this.reservedWordsStrictBind = keywordRegexp(reservedStrict + " " + _identifier.reservedWords.strictBind);
  1810. this.input = String(input);
  1811. // Used to signal to callers of `readWord1` whether the word
  1812. // contained any escape sequences. This is needed because words with
  1813. // escape sequences must not be interpreted as keywords.
  1814. this.containsEsc = false;
  1815. // Load plugins
  1816. this.loadPlugins(options.plugins);
  1817. // Set up token state
  1818. // The current position of the tokenizer in the input.
  1819. if (startPos) {
  1820. this.pos = startPos;
  1821. this.lineStart = Math.max(0, this.input.lastIndexOf("\n", startPos));
  1822. this.curLine = this.input.slice(0, this.lineStart).split(_whitespace.lineBreak).length;
  1823. } else {
  1824. this.pos = this.lineStart = 0;
  1825. this.curLine = 1;
  1826. }
  1827. // Properties of the current token:
  1828. // Its type
  1829. this.type = _tokentype.types.eof;
  1830. // For tokens that include more information than their type, the value
  1831. this.value = null;
  1832. // Its start and end offset
  1833. this.start = this.end = this.pos;
  1834. // And, if locations are used, the {line, column} object
  1835. // corresponding to those offsets
  1836. this.startLoc = this.endLoc = this.curPosition();
  1837. // Position information for the previous token
  1838. this.lastTokEndLoc = this.lastTokStartLoc = null;
  1839. this.lastTokStart = this.lastTokEnd = this.pos;
  1840. // The context stack is used to superficially track syntactic
  1841. // context to predict whether a regular expression is allowed in a
  1842. // given position.
  1843. this.context = this.initialContext();
  1844. this.exprAllowed = true;
  1845. // Figure out if it's a module code.
  1846. this.strict = this.inModule = options.sourceType === "module";
  1847. // Used to signify the start of a potential arrow function
  1848. this.potentialArrowAt = -1;
  1849. // Flags to track whether we are in a function, a generator.
  1850. this.inFunction = this.inGenerator = false;
  1851. // Labels in scope.
  1852. this.labels = [];
  1853. // If enabled, skip leading hashbang line.
  1854. if (this.pos === 0 && options.allowHashBang && this.input.slice(0, 2) === '#!') this.skipLineComment(2);
  1855. }
  1856. // DEPRECATED Kept for backwards compatibility until 3.0 in case a plugin uses them
  1857. Parser.prototype.isKeyword = function isKeyword(word) {
  1858. return this.keywords.test(word);
  1859. };
  1860. Parser.prototype.isReservedWord = function isReservedWord(word) {
  1861. return this.reservedWords.test(word);
  1862. };
  1863. Parser.prototype.extend = function extend(name, f) {
  1864. this[name] = f(this[name]);
  1865. };
  1866. Parser.prototype.loadPlugins = function loadPlugins(pluginConfigs) {
  1867. for (var _name in pluginConfigs) {
  1868. var plugin = plugins[_name];
  1869. if (!plugin) throw new Error("Plugin '" + _name + "' not found");
  1870. plugin(this, pluginConfigs[_name]);
  1871. }
  1872. };
  1873. Parser.prototype.parse = function parse() {
  1874. var node = this.options.program || this.startNode();
  1875. this.nextToken();
  1876. return this.parseTopLevel(node);
  1877. };
  1878. return Parser;
  1879. })();
  1880. exports.Parser = Parser;
  1881. },{"./identifier":2,"./options":8,"./tokentype":14,"./whitespace":16}],11:[function(_dereq_,module,exports){
  1882. "use strict";
  1883. var _tokentype = _dereq_("./tokentype");
  1884. var _state = _dereq_("./state");
  1885. var _whitespace = _dereq_("./whitespace");
  1886. var _identifier = _dereq_("./identifier");
  1887. var _parseutil = _dereq_("./parseutil");
  1888. var pp = _state.Parser.prototype;
  1889. // ### Statement parsing
  1890. // Parse a program. Initializes the parser, reads any number of
  1891. // statements, and wraps them in a Program node. Optionally takes a
  1892. // `program` argument. If present, the statements will be appended
  1893. // to its body instead of creating a new node.
  1894. pp.parseTopLevel = function (node) {
  1895. var first = true;
  1896. if (!node.body) node.body = [];
  1897. while (this.type !== _tokentype.types.eof) {
  1898. var stmt = this.parseStatement(true, true);
  1899. node.body.push(stmt);
  1900. if (first) {
  1901. if (this.isUseStrict(stmt)) this.setStrict(true);
  1902. first = false;
  1903. }
  1904. }
  1905. this.next();
  1906. if (this.options.ecmaVersion >= 6) {
  1907. node.sourceType = this.options.sourceType;
  1908. }
  1909. return this.finishNode(node, "Program");
  1910. };
  1911. var loopLabel = { kind: "loop" },
  1912. switchLabel = { kind: "switch" };
  1913. pp.isLet = function () {
  1914. if (this.type !== _tokentype.types.name || this.options.ecmaVersion < 6 || this.value != "let") return false;
  1915. _whitespace.skipWhiteSpace.lastIndex = this.pos;
  1916. var skip = _whitespace.skipWhiteSpace.exec(this.input);
  1917. var next = this.pos + skip[0].length,
  1918. nextCh = this.input.charCodeAt(next);
  1919. if (nextCh === 91 || nextCh == 123) return true; // '{' and '['
  1920. if (_identifier.isIdentifierStart(nextCh, true)) {
  1921. for (var pos = next + 1; _identifier.isIdentifierChar(this.input.charCodeAt(pos, true)); ++pos) {}
  1922. var ident = this.input.slice(next, pos);
  1923. if (!this.isKeyword(ident)) return true;
  1924. }
  1925. return false;
  1926. };
  1927. // Parse a single statement.
  1928. //
  1929. // If expecting a statement and finding a slash operator, parse a
  1930. // regular expression literal. This is to handle cases like
  1931. // `if (foo) /blah/.exec(foo)`, where looking at the previous token
  1932. // does not help.
  1933. pp.parseStatement = function (declaration, topLevel) {
  1934. var starttype = this.type,
  1935. node = this.startNode(),
  1936. kind = undefined;
  1937. if (this.isLet()) {
  1938. starttype = _tokentype.types._var;
  1939. kind = "let";
  1940. }
  1941. // Most types of statements are recognized by the keyword they
  1942. // start with. Many are trivial to parse, some require a bit of
  1943. // complexity.
  1944. switch (starttype) {
  1945. case _tokentype.types._break:case _tokentype.types._continue:
  1946. return this.parseBreakContinueStatement(node, starttype.keyword);
  1947. case _tokentype.types._debugger:
  1948. return this.parseDebuggerStatement(node);
  1949. case _tokentype.types._do:
  1950. return this.parseDoStatement(node);
  1951. case _tokentype.types._for:
  1952. return this.parseForStatement(node);
  1953. case _tokentype.types._function:
  1954. if (!declaration && this.options.ecmaVersion >= 6) this.unexpected();
  1955. return this.parseFunctionStatement(node);
  1956. case _tokentype.types._class:
  1957. if (!declaration) this.unexpected();
  1958. return this.parseClass(node, true);
  1959. case _tokentype.types._if:
  1960. return this.parseIfStatement(node);
  1961. case _tokentype.types._return:
  1962. return this.parseReturnStatement(node);
  1963. case _tokentype.types._switch:
  1964. return this.parseSwitchStatement(node);
  1965. case _tokentype.types._throw:
  1966. return this.parseThrowStatement(node);
  1967. case _tokentype.types._try:
  1968. return this.parseTryStatement(node);
  1969. case _tokentype.types._const:case _tokentype.types._var:
  1970. kind = kind || this.value;
  1971. if (!declaration && kind != "var") this.unexpected();
  1972. return this.parseVarStatement(node, kind);
  1973. case _tokentype.types._while:
  1974. return this.parseWhileStatement(node);
  1975. case _tokentype.types._with:
  1976. return this.parseWithStatement(node);
  1977. case _tokentype.types.braceL:
  1978. return this.parseBlock();
  1979. case _tokentype.types.semi:
  1980. return this.parseEmptyStatement(node);
  1981. case _tokentype.types._export:
  1982. case _tokentype.types._import:
  1983. if (!this.options.allowImportExportEverywhere) {
  1984. if (!topLevel) this.raise(this.start, "'import' and 'export' may only appear at the top level");
  1985. if (!this.inModule) this.raise(this.start, "'import' and 'export' may appear only with 'sourceType: module'");
  1986. }
  1987. return starttype === _tokentype.types._import ? this.parseImport(node) : this.parseExport(node);
  1988. // If the statement does not start with a statement keyword or a
  1989. // brace, it's an ExpressionStatement or LabeledStatement. We
  1990. // simply start parsing an expression, and afterwards, if the
  1991. // next token is a colon and the expression was a simple
  1992. // Identifier node, we switch to interpreting it as a label.
  1993. default:
  1994. var maybeName = this.value,
  1995. expr = this.parseExpression();
  1996. if (starttype === _tokentype.types.name && expr.type === "Identifier" && this.eat(_tokentype.types.colon)) return this.parseLabeledStatement(node, maybeName, expr);else return this.parseExpressionStatement(node, expr);
  1997. }
  1998. };
  1999. pp.parseBreakContinueStatement = function (node, keyword) {
  2000. var isBreak = keyword == "break";
  2001. this.next();
  2002. if (this.eat(_tokentype.types.semi) || this.insertSemicolon()) node.label = null;else if (this.type !== _tokentype.types.name) this.unexpected();else {
  2003. node.label = this.parseIdent();
  2004. this.semicolon();
  2005. }
  2006. // Verify that there is an actual destination to break or
  2007. // continue to.
  2008. for (var i = 0; i < this.labels.length; ++i) {
  2009. var lab = this.labels[i];
  2010. if (node.label == null || lab.name === node.label.name) {
  2011. if (lab.kind != null && (isBreak || lab.kind === "loop")) break;
  2012. if (node.label && isBreak) break;
  2013. }
  2014. }
  2015. if (i === this.labels.length) this.raise(node.start, "Unsyntactic " + keyword);
  2016. return this.finishNode(node, isBreak ? "BreakStatement" : "ContinueStatement");
  2017. };
  2018. pp.parseDebuggerStatement = function (node) {
  2019. this.next();
  2020. this.semicolon();
  2021. return this.finishNode(node, "DebuggerStatement");
  2022. };
  2023. pp.parseDoStatement = function (node) {
  2024. this.next();
  2025. this.labels.push(loopLabel);
  2026. node.body = this.parseStatement(false);
  2027. this.labels.pop();
  2028. this.expect(_tokentype.types._while);
  2029. node.test = this.parseParenExpression();
  2030. if (this.options.ecmaVersion >= 6) this.eat(_tokentype.types.semi);else this.semicolon();
  2031. return this.finishNode(node, "DoWhileStatement");
  2032. };
  2033. // Disambiguating between a `for` and a `for`/`in` or `for`/`of`
  2034. // loop is non-trivial. Basically, we have to parse the init `var`
  2035. // statement or expression, disallowing the `in` operator (see
  2036. // the second parameter to `parseExpression`), and then check
  2037. // whether the next token is `in` or `of`. When there is no init
  2038. // part (semicolon immediately after the opening parenthesis), it
  2039. // is a regular `for` loop.
  2040. pp.parseForStatement = function (node) {
  2041. this.next();
  2042. this.labels.push(loopLabel);
  2043. this.expect(_tokentype.types.parenL);
  2044. if (this.type === _tokentype.types.semi) return this.parseFor(node, null);
  2045. var isLet = this.isLet();
  2046. if (this.type === _tokentype.types._var || this.type === _tokentype.types._const || isLet) {
  2047. var _init = this.startNode(),
  2048. kind = isLet ? "let" : this.value;
  2049. this.next();
  2050. this.parseVar(_init, true, kind);
  2051. this.finishNode(_init, "VariableDeclaration");
  2052. if ((this.type === _tokentype.types._in || this.options.ecmaVersion >= 6 && this.isContextual("of")) && _init.declarations.length === 1 && !(kind !== "var" && _init.declarations[0].init)) return this.parseForIn(node, _init);
  2053. return this.parseFor(node, _init);
  2054. }
  2055. var refDestructuringErrors = new _parseutil.DestructuringErrors();
  2056. var init = this.parseExpression(true, refDestructuringErrors);
  2057. if (this.type === _tokentype.types._in || this.options.ecmaVersion >= 6 && this.isContextual("of")) {
  2058. this.checkPatternErrors(refDestructuringErrors, true);
  2059. this.toAssignable(init);
  2060. this.checkLVal(init);
  2061. return this.parseForIn(node, init);
  2062. } else {
  2063. this.checkExpressionErrors(refDestructuringErrors, true);
  2064. }
  2065. return this.parseFor(node, init);
  2066. };
  2067. pp.parseFunctionStatement = function (node) {
  2068. this.next();
  2069. return this.parseFunction(node, true);
  2070. };
  2071. pp.parseIfStatement = function (node) {
  2072. this.next();
  2073. node.test = this.parseParenExpression();
  2074. node.consequent = this.parseStatement(false);
  2075. node.alternate = this.eat(_tokentype.types._else) ? this.parseStatement(false) : null;
  2076. return this.finishNode(node, "IfStatement");
  2077. };
  2078. pp.parseReturnStatement = function (node) {
  2079. if (!this.inFunction && !this.options.allowReturnOutsideFunction) this.raise(this.start, "'return' outside of function");
  2080. this.next();
  2081. // In `return` (and `break`/`continue`), the keywords with
  2082. // optional arguments, we eagerly look for a semicolon or the
  2083. // possibility to insert one.
  2084. if (this.eat(_tokentype.types.semi) || this.insertSemicolon()) node.argument = null;else {
  2085. node.argument = this.parseExpression();this.semicolon();
  2086. }
  2087. return this.finishNode(node, "ReturnStatement");
  2088. };
  2089. pp.parseSwitchStatement = function (node) {
  2090. this.next();
  2091. node.discriminant = this.parseParenExpression();
  2092. node.cases = [];
  2093. this.expect(_tokentype.types.braceL);
  2094. this.labels.push(switchLabel);
  2095. // Statements under must be grouped (by label) in SwitchCase
  2096. // nodes. `cur` is used to keep the node that we are currently
  2097. // adding statements to.
  2098. for (var cur, sawDefault = false; this.type != _tokentype.types.braceR;) {
  2099. if (this.type === _tokentype.types._case || this.type === _tokentype.types._default) {
  2100. var isCase = this.type === _tokentype.types._case;
  2101. if (cur) this.finishNode(cur, "SwitchCase");
  2102. node.cases.push(cur = this.startNode());
  2103. cur.consequent = [];
  2104. this.next();
  2105. if (isCase) {
  2106. cur.test = this.parseExpression();
  2107. } else {
  2108. if (sawDefault) this.raiseRecoverable(this.lastTokStart, "Multiple default clauses");
  2109. sawDefault = true;
  2110. cur.test = null;
  2111. }
  2112. this.expect(_tokentype.types.colon);
  2113. } else {
  2114. if (!cur) this.unexpected();
  2115. cur.consequent.push(this.parseStatement(true));
  2116. }
  2117. }
  2118. if (cur) this.finishNode(cur, "SwitchCase");
  2119. this.next(); // Closing brace
  2120. this.labels.pop();
  2121. return this.finishNode(node, "SwitchStatement");
  2122. };
  2123. pp.parseThrowStatement = function (node) {
  2124. this.next();
  2125. if (_whitespace.lineBreak.test(this.input.slice(this.lastTokEnd, this.start))) this.raise(this.lastTokEnd, "Illegal newline after throw");
  2126. node.argument = this.parseExpression();
  2127. this.semicolon();
  2128. return this.finishNode(node, "ThrowStatement");
  2129. };
  2130. // Reused empty array added for node fields that are always empty.
  2131. var empty = [];
  2132. pp.parseTryStatement = function (node) {
  2133. this.next();
  2134. node.block = this.parseBlock();
  2135. node.handler = null;
  2136. if (this.type === _tokentype.types._catch) {
  2137. var clause = this.startNode();
  2138. this.next();
  2139. this.expect(_tokentype.types.parenL);
  2140. clause.param = this.parseBindingAtom();
  2141. this.checkLVal(clause.param, true);
  2142. this.expect(_tokentype.types.parenR);
  2143. clause.body = this.parseBlock();
  2144. node.handler = this.finishNode(clause, "CatchClause");
  2145. }
  2146. node.finalizer = this.eat(_tokentype.types._finally) ? this.parseBlock() : null;
  2147. if (!node.handler && !node.finalizer) this.raise(node.start, "Missing catch or finally clause");
  2148. return this.finishNode(node, "TryStatement");
  2149. };
  2150. pp.parseVarStatement = function (node, kind) {
  2151. this.next();
  2152. this.parseVar(node, false, kind);
  2153. this.semicolon();
  2154. return this.finishNode(node, "VariableDeclaration");
  2155. };
  2156. pp.parseWhileStatement = function (node) {
  2157. this.next();
  2158. node.test = this.parseParenExpression();
  2159. this.labels.push(loopLabel);
  2160. node.body = this.parseStatement(false);
  2161. this.labels.pop();
  2162. return this.finishNode(node, "WhileStatement");
  2163. };
  2164. pp.parseWithStatement = function (node) {
  2165. if (this.strict) this.raise(this.start, "'with' in strict mode");
  2166. this.next();
  2167. node.object = this.parseParenExpression();
  2168. node.body = this.parseStatement(false);
  2169. return this.finishNode(node, "WithStatement");
  2170. };
  2171. pp.parseEmptyStatement = function (node) {
  2172. this.next();
  2173. return this.finishNode(node, "EmptyStatement");
  2174. };
  2175. pp.parseLabeledStatement = function (node, maybeName, expr) {
  2176. for (var i = 0; i < this.labels.length; ++i) {
  2177. if (this.labels[i].name === maybeName) this.raise(expr.start, "Label '" + maybeName + "' is already declared");
  2178. }var kind = this.type.isLoop ? "loop" : this.type === _tokentype.types._switch ? "switch" : null;
  2179. for (var i = this.labels.length - 1; i >= 0; i--) {
  2180. var label = this.labels[i];
  2181. if (label.statementStart == node.start) {
  2182. label.statementStart = this.start;
  2183. label.kind = kind;
  2184. } else break;
  2185. }
  2186. this.labels.push({ name: maybeName, kind: kind, statementStart: this.start });
  2187. node.body = this.parseStatement(true);
  2188. this.labels.pop();
  2189. node.label = expr;
  2190. return this.finishNode(node, "LabeledStatement");
  2191. };
  2192. pp.parseExpressionStatement = function (node, expr) {
  2193. node.expression = expr;
  2194. this.semicolon();
  2195. return this.finishNode(node, "ExpressionStatement");
  2196. };
  2197. // Parse a semicolon-enclosed block of statements, handling `"use
  2198. // strict"` declarations when `allowStrict` is true (used for
  2199. // function bodies).
  2200. pp.parseBlock = function (allowStrict) {
  2201. var node = this.startNode(),
  2202. first = true,
  2203. oldStrict = undefined;
  2204. node.body = [];
  2205. this.expect(_tokentype.types.braceL);
  2206. while (!this.eat(_tokentype.types.braceR)) {
  2207. var stmt = this.parseStatement(true);
  2208. node.body.push(stmt);
  2209. if (first && allowStrict && this.isUseStrict(stmt)) {
  2210. oldStrict = this.strict;
  2211. this.setStrict(this.strict = true);
  2212. }
  2213. first = false;
  2214. }
  2215. if (oldStrict === false) this.setStrict(false);
  2216. return this.finishNode(node, "BlockStatement");
  2217. };
  2218. // Parse a regular `for` loop. The disambiguation code in
  2219. // `parseStatement` will already have parsed the init statement or
  2220. // expression.
  2221. pp.parseFor = function (node, init) {
  2222. node.init = init;
  2223. this.expect(_tokentype.types.semi);
  2224. node.test = this.type === _tokentype.types.semi ? null : this.parseExpression();
  2225. this.expect(_tokentype.types.semi);
  2226. node.update = this.type === _tokentype.types.parenR ? null : this.parseExpression();
  2227. this.expect(_tokentype.types.parenR);
  2228. node.body = this.parseStatement(false);
  2229. this.labels.pop();
  2230. return this.finishNode(node, "ForStatement");
  2231. };
  2232. // Parse a `for`/`in` and `for`/`of` loop, which are almost
  2233. // same from parser's perspective.
  2234. pp.parseForIn = function (node, init) {
  2235. var type = this.type === _tokentype.types._in ? "ForInStatement" : "ForOfStatement";
  2236. this.next();
  2237. node.left = init;
  2238. node.right = this.parseExpression();
  2239. this.expect(_tokentype.types.parenR);
  2240. node.body = this.parseStatement(false);
  2241. this.labels.pop();
  2242. return this.finishNode(node, type);
  2243. };
  2244. // Parse a list of variable declarations.
  2245. pp.parseVar = function (node, isFor, kind) {
  2246. node.declarations = [];
  2247. node.kind = kind;
  2248. for (;;) {
  2249. var decl = this.startNode();
  2250. this.parseVarId(decl);
  2251. if (this.eat(_tokentype.types.eq)) {
  2252. decl.init = this.parseMaybeAssign(isFor);
  2253. } else if (kind === "const" && !(this.type === _tokentype.types._in || this.options.ecmaVersion >= 6 && this.isContextual("of"))) {
  2254. this.unexpected();
  2255. } else if (decl.id.type != "Identifier" && !(isFor && (this.type === _tokentype.types._in || this.isContextual("of")))) {
  2256. this.raise(this.lastTokEnd, "Complex binding patterns require an initialization value");
  2257. } else {
  2258. decl.init = null;
  2259. }
  2260. node.declarations.push(this.finishNode(decl, "VariableDeclarator"));
  2261. if (!this.eat(_tokentype.types.comma)) break;
  2262. }
  2263. return node;
  2264. };
  2265. pp.parseVarId = function (decl) {
  2266. decl.id = this.parseBindingAtom();
  2267. this.checkLVal(decl.id, true);
  2268. };
  2269. // Parse a function declaration or literal (depending on the
  2270. // `isStatement` parameter).
  2271. pp.parseFunction = function (node, isStatement, allowExpressionBody) {
  2272. this.initFunction(node);
  2273. if (this.options.ecmaVersion >= 6) node.generator = this.eat(_tokentype.types.star);
  2274. var oldInGen = this.inGenerator;
  2275. this.inGenerator = node.generator;
  2276. if (isStatement || this.type === _tokentype.types.name) node.id = this.parseIdent();
  2277. this.parseFunctionParams(node);
  2278. this.parseFunctionBody(node, allowExpressionBody);
  2279. this.inGenerator = oldInGen;
  2280. return this.finishNode(node, isStatement ? "FunctionDeclaration" : "FunctionExpression");
  2281. };
  2282. pp.parseFunctionParams = function (node) {
  2283. this.expect(_tokentype.types.parenL);
  2284. node.params = this.parseBindingList(_tokentype.types.parenR, false, false, true);
  2285. };
  2286. // Parse a class declaration or literal (depending on the
  2287. // `isStatement` parameter).
  2288. pp.parseClass = function (node, isStatement) {
  2289. this.next();
  2290. this.parseClassId(node, isStatement);
  2291. this.parseClassSuper(node);
  2292. var classBody = this.startNode();
  2293. var hadConstructor = false;
  2294. classBody.body = [];
  2295. this.expect(_tokentype.types.braceL);
  2296. while (!this.eat(_tokentype.types.braceR)) {
  2297. if (this.eat(_tokentype.types.semi)) continue;
  2298. var method = this.startNode();
  2299. var isGenerator = this.eat(_tokentype.types.star);
  2300. var isMaybeStatic = this.type === _tokentype.types.name && this.value === "static";
  2301. this.parsePropertyName(method);
  2302. method["static"] = isMaybeStatic && this.type !== _tokentype.types.parenL;
  2303. if (method["static"]) {
  2304. if (isGenerator) this.unexpected();
  2305. isGenerator = this.eat(_tokentype.types.star);
  2306. this.parsePropertyName(method);
  2307. }
  2308. method.kind = "method";
  2309. var isGetSet = false;
  2310. if (!method.computed) {
  2311. var key = method.key;
  2312. if (!isGenerator && key.type === "Identifier" && this.type !== _tokentype.types.parenL && (key.name === "get" || key.name === "set")) {
  2313. isGetSet = true;
  2314. method.kind = key.name;
  2315. key = this.parsePropertyName(method);
  2316. }
  2317. if (!method["static"] && (key.type === "Identifier" && key.name === "constructor" || key.type === "Literal" && key.value === "constructor")) {
  2318. if (hadConstructor) this.raise(key.start, "Duplicate constructor in the same class");
  2319. if (isGetSet) this.raise(key.start, "Constructor can't have get/set modifier");
  2320. if (isGenerator) this.raise(key.start, "Constructor can't be a generator");
  2321. method.kind = "constructor";
  2322. hadConstructor = true;
  2323. }
  2324. }
  2325. this.parseClassMethod(classBody, method, isGenerator);
  2326. if (isGetSet) {
  2327. var paramCount = method.kind === "get" ? 0 : 1;
  2328. if (method.value.params.length !== paramCount) {
  2329. var start = method.value.start;
  2330. if (method.kind === "get") this.raiseRecoverable(start, "getter should have no params");else this.raiseRecoverable(start, "setter should have exactly one param");
  2331. }
  2332. if (method.kind === "set" && method.value.params[0].type === "RestElement") this.raise(method.value.params[0].start, "Setter cannot use rest params");
  2333. }
  2334. }
  2335. node.body = this.finishNode(classBody, "ClassBody");
  2336. return this.finishNode(node, isStatement ? "ClassDeclaration" : "ClassExpression");
  2337. };
  2338. pp.parseClassMethod = function (classBody, method, isGenerator) {
  2339. method.value = this.parseMethod(isGenerator);
  2340. classBody.body.push(this.finishNode(method, "MethodDefinition"));
  2341. };
  2342. pp.parseClassId = function (node, isStatement) {
  2343. node.id = this.type === _tokentype.types.name ? this.parseIdent() : isStatement ? this.unexpected() : null;
  2344. };
  2345. pp.parseClassSuper = function (node) {
  2346. node.superClass = this.eat(_tokentype.types._extends) ? this.parseExprSubscripts() : null;
  2347. };
  2348. // Parses module export declaration.
  2349. pp.parseExport = function (node) {
  2350. this.next();
  2351. // export * from '...'
  2352. if (this.eat(_tokentype.types.star)) {
  2353. this.expectContextual("from");
  2354. node.source = this.type === _tokentype.types.string ? this.parseExprAtom() : this.unexpected();
  2355. this.semicolon();
  2356. return this.finishNode(node, "ExportAllDeclaration");
  2357. }
  2358. if (this.eat(_tokentype.types._default)) {
  2359. // export default ...
  2360. var parens = this.type == _tokentype.types.parenL;
  2361. var expr = this.parseMaybeAssign();
  2362. var needsSemi = true;
  2363. if (!parens && (expr.type == "FunctionExpression" || expr.type == "ClassExpression")) {
  2364. needsSemi = false;
  2365. if (expr.id) {
  2366. expr.type = expr.type == "FunctionExpression" ? "FunctionDeclaration" : "ClassDeclaration";
  2367. }
  2368. }
  2369. node.declaration = expr;
  2370. if (needsSemi) this.semicolon();
  2371. return this.finishNode(node, "ExportDefaultDeclaration");
  2372. }
  2373. // export var|const|let|function|class ...
  2374. if (this.shouldParseExportStatement()) {
  2375. node.declaration = this.parseStatement(true);
  2376. node.specifiers = [];
  2377. node.source = null;
  2378. } else {
  2379. // export { x, y as z } [from '...']
  2380. node.declaration = null;
  2381. node.specifiers = this.parseExportSpecifiers();
  2382. if (this.eatContextual("from")) {
  2383. node.source = this.type === _tokentype.types.string ? this.parseExprAtom() : this.unexpected();
  2384. } else {
  2385. // check for keywords used as local names
  2386. for (var i = 0; i < node.specifiers.length; i++) {
  2387. if (this.keywords.test(node.specifiers[i].local.name) || this.reservedWords.test(node.specifiers[i].local.name)) {
  2388. this.unexpected(node.specifiers[i].local.start);
  2389. }
  2390. }
  2391. node.source = null;
  2392. }
  2393. this.semicolon();
  2394. }
  2395. return this.finishNode(node, "ExportNamedDeclaration");
  2396. };
  2397. pp.shouldParseExportStatement = function () {
  2398. return this.type.keyword || this.isLet();
  2399. };
  2400. // Parses a comma-separated list of module exports.
  2401. pp.parseExportSpecifiers = function () {
  2402. var nodes = [],
  2403. first = true;
  2404. // export { x, y as z } [from '...']
  2405. this.expect(_tokentype.types.braceL);
  2406. while (!this.eat(_tokentype.types.braceR)) {
  2407. if (!first) {
  2408. this.expect(_tokentype.types.comma);
  2409. if (this.afterTrailingComma(_tokentype.types.braceR)) break;
  2410. } else first = false;
  2411. var node = this.startNode();
  2412. node.local = this.parseIdent(this.type === _tokentype.types._default);
  2413. node.exported = this.eatContextual("as") ? this.parseIdent(true) : node.local;
  2414. nodes.push(this.finishNode(node, "ExportSpecifier"));
  2415. }
  2416. return nodes;
  2417. };
  2418. // Parses import declaration.
  2419. pp.parseImport = function (node) {
  2420. this.next();
  2421. // import '...'
  2422. if (this.type === _tokentype.types.string) {
  2423. node.specifiers = empty;
  2424. node.source = this.parseExprAtom();
  2425. } else {
  2426. node.specifiers = this.parseImportSpecifiers();
  2427. this.expectContextual("from");
  2428. node.source = this.type === _tokentype.types.string ? this.parseExprAtom() : this.unexpected();
  2429. }
  2430. this.semicolon();
  2431. return this.finishNode(node, "ImportDeclaration");
  2432. };
  2433. // Parses a comma-separated list of module imports.
  2434. pp.parseImportSpecifiers = function () {
  2435. var nodes = [],
  2436. first = true;
  2437. if (this.type === _tokentype.types.name) {
  2438. // import defaultObj, { x, y as z } from '...'
  2439. var node = this.startNode();
  2440. node.local = this.parseIdent();
  2441. this.checkLVal(node.local, true);
  2442. nodes.push(this.finishNode(node, "ImportDefaultSpecifier"));
  2443. if (!this.eat(_tokentype.types.comma)) return nodes;
  2444. }
  2445. if (this.type === _tokentype.types.star) {
  2446. var node = this.startNode();
  2447. this.next();
  2448. this.expectContextual("as");
  2449. node.local = this.parseIdent();
  2450. this.checkLVal(node.local, true);
  2451. nodes.push(this.finishNode(node, "ImportNamespaceSpecifier"));
  2452. return nodes;
  2453. }
  2454. this.expect(_tokentype.types.braceL);
  2455. while (!this.eat(_tokentype.types.braceR)) {
  2456. if (!first) {
  2457. this.expect(_tokentype.types.comma);
  2458. if (this.afterTrailingComma(_tokentype.types.braceR)) break;
  2459. } else first = false;
  2460. var node = this.startNode();
  2461. node.imported = this.parseIdent(true);
  2462. if (this.eatContextual("as")) {
  2463. node.local = this.parseIdent();
  2464. } else {
  2465. node.local = node.imported;
  2466. if (this.isKeyword(node.local.name)) this.unexpected(node.local.start);
  2467. if (this.reservedWordsStrict.test(node.local.name)) this.raise(node.local.start, "The keyword '" + node.local.name + "' is reserved");
  2468. }
  2469. this.checkLVal(node.local, true);
  2470. nodes.push(this.finishNode(node, "ImportSpecifier"));
  2471. }
  2472. return nodes;
  2473. };
  2474. },{"./identifier":2,"./parseutil":9,"./state":10,"./tokentype":14,"./whitespace":16}],12:[function(_dereq_,module,exports){
  2475. // The algorithm used to determine whether a regexp can appear at a
  2476. // given point in the program is loosely based on sweet.js' approach.
  2477. // See https://github.com/mozilla/sweet.js/wiki/design
  2478. "use strict";
  2479. exports.__esModule = true;
  2480. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  2481. var _state = _dereq_("./state");
  2482. var _tokentype = _dereq_("./tokentype");
  2483. var _whitespace = _dereq_("./whitespace");
  2484. var TokContext = function TokContext(token, isExpr, preserveSpace, override) {
  2485. _classCallCheck(this, TokContext);
  2486. this.token = token;
  2487. this.isExpr = !!isExpr;
  2488. this.preserveSpace = !!preserveSpace;
  2489. this.override = override;
  2490. };
  2491. exports.TokContext = TokContext;
  2492. var types = {
  2493. b_stat: new TokContext("{", false),
  2494. b_expr: new TokContext("{", true),
  2495. b_tmpl: new TokContext("${", true),
  2496. p_stat: new TokContext("(", false),
  2497. p_expr: new TokContext("(", true),
  2498. q_tmpl: new TokContext("`", true, true, function (p) {
  2499. return p.readTmplToken();
  2500. }),
  2501. f_expr: new TokContext("function", true)
  2502. };
  2503. exports.types = types;
  2504. var pp = _state.Parser.prototype;
  2505. pp.initialContext = function () {
  2506. return [types.b_stat];
  2507. };
  2508. pp.braceIsBlock = function (prevType) {
  2509. if (prevType === _tokentype.types.colon) {
  2510. var _parent = this.curContext();
  2511. if (_parent === types.b_stat || _parent === types.b_expr) return !_parent.isExpr;
  2512. }
  2513. if (prevType === _tokentype.types._return) return _whitespace.lineBreak.test(this.input.slice(this.lastTokEnd, this.start));
  2514. if (prevType === _tokentype.types._else || prevType === _tokentype.types.semi || prevType === _tokentype.types.eof || prevType === _tokentype.types.parenR) return true;
  2515. if (prevType == _tokentype.types.braceL) return this.curContext() === types.b_stat;
  2516. return !this.exprAllowed;
  2517. };
  2518. pp.updateContext = function (prevType) {
  2519. var update = undefined,
  2520. type = this.type;
  2521. if (type.keyword && prevType == _tokentype.types.dot) this.exprAllowed = false;else if (update = type.updateContext) update.call(this, prevType);else this.exprAllowed = type.beforeExpr;
  2522. };
  2523. // Token-specific context update code
  2524. _tokentype.types.parenR.updateContext = _tokentype.types.braceR.updateContext = function () {
  2525. if (this.context.length == 1) {
  2526. this.exprAllowed = true;
  2527. return;
  2528. }
  2529. var out = this.context.pop();
  2530. if (out === types.b_stat && this.curContext() === types.f_expr) {
  2531. this.context.pop();
  2532. this.exprAllowed = false;
  2533. } else if (out === types.b_tmpl) {
  2534. this.exprAllowed = true;
  2535. } else {
  2536. this.exprAllowed = !out.isExpr;
  2537. }
  2538. };
  2539. _tokentype.types.braceL.updateContext = function (prevType) {
  2540. this.context.push(this.braceIsBlock(prevType) ? types.b_stat : types.b_expr);
  2541. this.exprAllowed = true;
  2542. };
  2543. _tokentype.types.dollarBraceL.updateContext = function () {
  2544. this.context.push(types.b_tmpl);
  2545. this.exprAllowed = true;
  2546. };
  2547. _tokentype.types.parenL.updateContext = function (prevType) {
  2548. var statementParens = prevType === _tokentype.types._if || prevType === _tokentype.types._for || prevType === _tokentype.types._with || prevType === _tokentype.types._while;
  2549. this.context.push(statementParens ? types.p_stat : types.p_expr);
  2550. this.exprAllowed = true;
  2551. };
  2552. _tokentype.types.incDec.updateContext = function () {
  2553. // tokExprAllowed stays unchanged
  2554. };
  2555. _tokentype.types._function.updateContext = function (prevType) {
  2556. if (prevType.beforeExpr && prevType !== _tokentype.types.semi && prevType !== _tokentype.types._else && (prevType !== _tokentype.types.colon || this.curContext() !== types.b_stat)) this.context.push(types.f_expr);
  2557. this.exprAllowed = false;
  2558. };
  2559. _tokentype.types.backQuote.updateContext = function () {
  2560. if (this.curContext() === types.q_tmpl) this.context.pop();else this.context.push(types.q_tmpl);
  2561. this.exprAllowed = false;
  2562. };
  2563. },{"./state":10,"./tokentype":14,"./whitespace":16}],13:[function(_dereq_,module,exports){
  2564. "use strict";
  2565. exports.__esModule = true;
  2566. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  2567. var _identifier = _dereq_("./identifier");
  2568. var _tokentype = _dereq_("./tokentype");
  2569. var _state = _dereq_("./state");
  2570. var _locutil = _dereq_("./locutil");
  2571. var _whitespace = _dereq_("./whitespace");
  2572. // Object type used to represent tokens. Note that normally, tokens
  2573. // simply exist as properties on the parser object. This is only
  2574. // used for the onToken callback and the external tokenizer.
  2575. var Token = function Token(p) {
  2576. _classCallCheck(this, Token);
  2577. this.type = p.type;
  2578. this.value = p.value;
  2579. this.start = p.start;
  2580. this.end = p.end;
  2581. if (p.options.locations) this.loc = new _locutil.SourceLocation(p, p.startLoc, p.endLoc);
  2582. if (p.options.ranges) this.range = [p.start, p.end];
  2583. }
  2584. // ## Tokenizer
  2585. ;
  2586. exports.Token = Token;
  2587. var pp = _state.Parser.prototype;
  2588. // Are we running under Rhino?
  2589. var isRhino = typeof Packages == "object" && Object.prototype.toString.call(Packages) == "[object JavaPackage]";
  2590. // Move to the next token
  2591. pp.next = function () {
  2592. if (this.options.onToken) this.options.onToken(new Token(this));
  2593. this.lastTokEnd = this.end;
  2594. this.lastTokStart = this.start;
  2595. this.lastTokEndLoc = this.endLoc;
  2596. this.lastTokStartLoc = this.startLoc;
  2597. this.nextToken();
  2598. };
  2599. pp.getToken = function () {
  2600. this.next();
  2601. return new Token(this);
  2602. };
  2603. // If we're in an ES6 environment, make parsers iterable
  2604. if (typeof Symbol !== "undefined") pp[Symbol.iterator] = function () {
  2605. var self = this;
  2606. return { next: function next() {
  2607. var token = self.getToken();
  2608. return {
  2609. done: token.type === _tokentype.types.eof,
  2610. value: token
  2611. };
  2612. } };
  2613. };
  2614. // Toggle strict mode. Re-reads the next number or string to please
  2615. // pedantic tests (`"use strict"; 010;` should fail).
  2616. pp.setStrict = function (strict) {
  2617. this.strict = strict;
  2618. if (this.type !== _tokentype.types.num && this.type !== _tokentype.types.string) return;
  2619. this.pos = this.start;
  2620. if (this.options.locations) {
  2621. while (this.pos < this.lineStart) {
  2622. this.lineStart = this.input.lastIndexOf("\n", this.lineStart - 2) + 1;
  2623. --this.curLine;
  2624. }
  2625. }
  2626. this.nextToken();
  2627. };
  2628. pp.curContext = function () {
  2629. return this.context[this.context.length - 1];
  2630. };
  2631. // Read a single token, updating the parser object's token-related
  2632. // properties.
  2633. pp.nextToken = function () {
  2634. var curContext = this.curContext();
  2635. if (!curContext || !curContext.preserveSpace) this.skipSpace();
  2636. this.start = this.pos;
  2637. if (this.options.locations) this.startLoc = this.curPosition();
  2638. if (this.pos >= this.input.length) return this.finishToken(_tokentype.types.eof);
  2639. if (curContext.override) return curContext.override(this);else this.readToken(this.fullCharCodeAtPos());
  2640. };
  2641. pp.readToken = function (code) {
  2642. // Identifier or keyword. '\uXXXX' sequences are allowed in
  2643. // identifiers, so '\' also dispatches to that.
  2644. if (_identifier.isIdentifierStart(code, this.options.ecmaVersion >= 6) || code === 92 /* '\' */) return this.readWord();
  2645. return this.getTokenFromCode(code);
  2646. };
  2647. pp.fullCharCodeAtPos = function () {
  2648. var code = this.input.charCodeAt(this.pos);
  2649. if (code <= 0xd7ff || code >= 0xe000) return code;
  2650. var next = this.input.charCodeAt(this.pos + 1);
  2651. return (code << 10) + next - 0x35fdc00;
  2652. };
  2653. pp.skipBlockComment = function () {
  2654. var startLoc = this.options.onComment && this.curPosition();
  2655. var start = this.pos,
  2656. end = this.input.indexOf("*/", this.pos += 2);
  2657. if (end === -1) this.raise(this.pos - 2, "Unterminated comment");
  2658. this.pos = end + 2;
  2659. if (this.options.locations) {
  2660. _whitespace.lineBreakG.lastIndex = start;
  2661. var match = undefined;
  2662. while ((match = _whitespace.lineBreakG.exec(this.input)) && match.index < this.pos) {
  2663. ++this.curLine;
  2664. this.lineStart = match.index + match[0].length;
  2665. }
  2666. }
  2667. if (this.options.onComment) this.options.onComment(true, this.input.slice(start + 2, end), start, this.pos, startLoc, this.curPosition());
  2668. };
  2669. pp.skipLineComment = function (startSkip) {
  2670. var start = this.pos;
  2671. var startLoc = this.options.onComment && this.curPosition();
  2672. var ch = this.input.charCodeAt(this.pos += startSkip);
  2673. while (this.pos < this.input.length && ch !== 10 && ch !== 13 && ch !== 8232 && ch !== 8233) {
  2674. ++this.pos;
  2675. ch = this.input.charCodeAt(this.pos);
  2676. }
  2677. if (this.options.onComment) this.options.onComment(false, this.input.slice(start + startSkip, this.pos), start, this.pos, startLoc, this.curPosition());
  2678. };
  2679. // Called at the start of the parse and after every token. Skips
  2680. // whitespace and comments, and.
  2681. pp.skipSpace = function () {
  2682. loop: while (this.pos < this.input.length) {
  2683. var ch = this.input.charCodeAt(this.pos);
  2684. switch (ch) {
  2685. case 32:case 160:
  2686. // ' '
  2687. ++this.pos;
  2688. break;
  2689. case 13:
  2690. if (this.input.charCodeAt(this.pos + 1) === 10) {
  2691. ++this.pos;
  2692. }
  2693. case 10:case 8232:case 8233:
  2694. ++this.pos;
  2695. if (this.options.locations) {
  2696. ++this.curLine;
  2697. this.lineStart = this.pos;
  2698. }
  2699. break;
  2700. case 47:
  2701. // '/'
  2702. switch (this.input.charCodeAt(this.pos + 1)) {
  2703. case 42:
  2704. // '*'
  2705. this.skipBlockComment();
  2706. break;
  2707. case 47:
  2708. this.skipLineComment(2);
  2709. break;
  2710. default:
  2711. break loop;
  2712. }
  2713. break;
  2714. default:
  2715. if (ch > 8 && ch < 14 || ch >= 5760 && _whitespace.nonASCIIwhitespace.test(String.fromCharCode(ch))) {
  2716. ++this.pos;
  2717. } else {
  2718. break loop;
  2719. }
  2720. }
  2721. }
  2722. };
  2723. // Called at the end of every token. Sets `end`, `val`, and
  2724. // maintains `context` and `exprAllowed`, and skips the space after
  2725. // the token, so that the next one's `start` will point at the
  2726. // right position.
  2727. pp.finishToken = function (type, val) {
  2728. this.end = this.pos;
  2729. if (this.options.locations) this.endLoc = this.curPosition();
  2730. var prevType = this.type;
  2731. this.type = type;
  2732. this.value = val;
  2733. this.updateContext(prevType);
  2734. };
  2735. // ### Token reading
  2736. // This is the function that is called to fetch the next token. It
  2737. // is somewhat obscure, because it works in character codes rather
  2738. // than characters, and because operator parsing has been inlined
  2739. // into it.
  2740. //
  2741. // All in the name of speed.
  2742. //
  2743. pp.readToken_dot = function () {
  2744. var next = this.input.charCodeAt(this.pos + 1);
  2745. if (next >= 48 && next <= 57) return this.readNumber(true);
  2746. var next2 = this.input.charCodeAt(this.pos + 2);
  2747. if (this.options.ecmaVersion >= 6 && next === 46 && next2 === 46) {
  2748. // 46 = dot '.'
  2749. this.pos += 3;
  2750. return this.finishToken(_tokentype.types.ellipsis);
  2751. } else {
  2752. ++this.pos;
  2753. return this.finishToken(_tokentype.types.dot);
  2754. }
  2755. };
  2756. pp.readToken_slash = function () {
  2757. // '/'
  2758. var next = this.input.charCodeAt(this.pos + 1);
  2759. if (this.exprAllowed) {
  2760. ++this.pos;return this.readRegexp();
  2761. }
  2762. if (next === 61) return this.finishOp(_tokentype.types.assign, 2);
  2763. return this.finishOp(_tokentype.types.slash, 1);
  2764. };
  2765. pp.readToken_mult_modulo_exp = function (code) {
  2766. // '%*'
  2767. var next = this.input.charCodeAt(this.pos + 1);
  2768. var size = 1;
  2769. var tokentype = code === 42 ? _tokentype.types.star : _tokentype.types.modulo;
  2770. // exponentiation operator ** and **=
  2771. if (this.options.ecmaVersion >= 7 && next === 42) {
  2772. ++size;
  2773. tokentype = _tokentype.types.starstar;
  2774. next = this.input.charCodeAt(this.pos + 2);
  2775. }
  2776. if (next === 61) return this.finishOp(_tokentype.types.assign, size + 1);
  2777. return this.finishOp(tokentype, size);
  2778. };
  2779. pp.readToken_pipe_amp = function (code) {
  2780. // '|&'
  2781. var next = this.input.charCodeAt(this.pos + 1);
  2782. if (next === code) return this.finishOp(code === 124 ? _tokentype.types.logicalOR : _tokentype.types.logicalAND, 2);
  2783. if (next === 61) return this.finishOp(_tokentype.types.assign, 2);
  2784. return this.finishOp(code === 124 ? _tokentype.types.bitwiseOR : _tokentype.types.bitwiseAND, 1);
  2785. };
  2786. pp.readToken_caret = function () {
  2787. // '^'
  2788. var next = this.input.charCodeAt(this.pos + 1);
  2789. if (next === 61) return this.finishOp(_tokentype.types.assign, 2);
  2790. return this.finishOp(_tokentype.types.bitwiseXOR, 1);
  2791. };
  2792. pp.readToken_plus_min = function (code) {
  2793. // '+-'
  2794. var next = this.input.charCodeAt(this.pos + 1);
  2795. if (next === code) {
  2796. if (next == 45 && this.input.charCodeAt(this.pos + 2) == 62 && _whitespace.lineBreak.test(this.input.slice(this.lastTokEnd, this.pos))) {
  2797. // A `-->` line comment
  2798. this.skipLineComment(3);
  2799. this.skipSpace();
  2800. return this.nextToken();
  2801. }
  2802. return this.finishOp(_tokentype.types.incDec, 2);
  2803. }
  2804. if (next === 61) return this.finishOp(_tokentype.types.assign, 2);
  2805. return this.finishOp(_tokentype.types.plusMin, 1);
  2806. };
  2807. pp.readToken_lt_gt = function (code) {
  2808. // '<>'
  2809. var next = this.input.charCodeAt(this.pos + 1);
  2810. var size = 1;
  2811. if (next === code) {
  2812. size = code === 62 && this.input.charCodeAt(this.pos + 2) === 62 ? 3 : 2;
  2813. if (this.input.charCodeAt(this.pos + size) === 61) return this.finishOp(_tokentype.types.assign, size + 1);
  2814. return this.finishOp(_tokentype.types.bitShift, size);
  2815. }
  2816. if (next == 33 && code == 60 && this.input.charCodeAt(this.pos + 2) == 45 && this.input.charCodeAt(this.pos + 3) == 45) {
  2817. if (this.inModule) this.unexpected();
  2818. // `<!--`, an XML-style comment that should be interpreted as a line comment
  2819. this.skipLineComment(4);
  2820. this.skipSpace();
  2821. return this.nextToken();
  2822. }
  2823. if (next === 61) size = 2;
  2824. return this.finishOp(_tokentype.types.relational, size);
  2825. };
  2826. pp.readToken_eq_excl = function (code) {
  2827. // '=!'
  2828. var next = this.input.charCodeAt(this.pos + 1);
  2829. if (next === 61) return this.finishOp(_tokentype.types.equality, this.input.charCodeAt(this.pos + 2) === 61 ? 3 : 2);
  2830. if (code === 61 && next === 62 && this.options.ecmaVersion >= 6) {
  2831. // '=>'
  2832. this.pos += 2;
  2833. return this.finishToken(_tokentype.types.arrow);
  2834. }
  2835. return this.finishOp(code === 61 ? _tokentype.types.eq : _tokentype.types.prefix, 1);
  2836. };
  2837. pp.getTokenFromCode = function (code) {
  2838. switch (code) {
  2839. // The interpretation of a dot depends on whether it is followed
  2840. // by a digit or another two dots.
  2841. case 46:
  2842. // '.'
  2843. return this.readToken_dot();
  2844. // Punctuation tokens.
  2845. case 40:
  2846. ++this.pos;return this.finishToken(_tokentype.types.parenL);
  2847. case 41:
  2848. ++this.pos;return this.finishToken(_tokentype.types.parenR);
  2849. case 59:
  2850. ++this.pos;return this.finishToken(_tokentype.types.semi);
  2851. case 44:
  2852. ++this.pos;return this.finishToken(_tokentype.types.comma);
  2853. case 91:
  2854. ++this.pos;return this.finishToken(_tokentype.types.bracketL);
  2855. case 93:
  2856. ++this.pos;return this.finishToken(_tokentype.types.bracketR);
  2857. case 123:
  2858. ++this.pos;return this.finishToken(_tokentype.types.braceL);
  2859. case 125:
  2860. ++this.pos;return this.finishToken(_tokentype.types.braceR);
  2861. case 58:
  2862. ++this.pos;return this.finishToken(_tokentype.types.colon);
  2863. case 63:
  2864. ++this.pos;return this.finishToken(_tokentype.types.question);
  2865. case 96:
  2866. // '`'
  2867. if (this.options.ecmaVersion < 6) break;
  2868. ++this.pos;
  2869. return this.finishToken(_tokentype.types.backQuote);
  2870. case 48:
  2871. // '0'
  2872. var next = this.input.charCodeAt(this.pos + 1);
  2873. if (next === 120 || next === 88) return this.readRadixNumber(16); // '0x', '0X' - hex number
  2874. if (this.options.ecmaVersion >= 6) {
  2875. if (next === 111 || next === 79) return this.readRadixNumber(8); // '0o', '0O' - octal number
  2876. if (next === 98 || next === 66) return this.readRadixNumber(2); // '0b', '0B' - binary number
  2877. }
  2878. // Anything else beginning with a digit is an integer, octal
  2879. // number, or float.
  2880. case 49:case 50:case 51:case 52:case 53:case 54:case 55:case 56:case 57:
  2881. // 1-9
  2882. return this.readNumber(false);
  2883. // Quotes produce strings.
  2884. case 34:case 39:
  2885. // '"', "'"
  2886. return this.readString(code);
  2887. // Operators are parsed inline in tiny state machines. '=' (61) is
  2888. // often referred to. `finishOp` simply skips the amount of
  2889. // characters it is given as second argument, and returns a token
  2890. // of the type given by its first argument.
  2891. case 47:
  2892. // '/'
  2893. return this.readToken_slash();
  2894. case 37:case 42:
  2895. // '%*'
  2896. return this.readToken_mult_modulo_exp(code);
  2897. case 124:case 38:
  2898. // '|&'
  2899. return this.readToken_pipe_amp(code);
  2900. case 94:
  2901. // '^'
  2902. return this.readToken_caret();
  2903. case 43:case 45:
  2904. // '+-'
  2905. return this.readToken_plus_min(code);
  2906. case 60:case 62:
  2907. // '<>'
  2908. return this.readToken_lt_gt(code);
  2909. case 61:case 33:
  2910. // '=!'
  2911. return this.readToken_eq_excl(code);
  2912. case 126:
  2913. // '~'
  2914. return this.finishOp(_tokentype.types.prefix, 1);
  2915. }
  2916. this.raise(this.pos, "Unexpected character '" + codePointToString(code) + "'");
  2917. };
  2918. pp.finishOp = function (type, size) {
  2919. var str = this.input.slice(this.pos, this.pos + size);
  2920. this.pos += size;
  2921. return this.finishToken(type, str);
  2922. };
  2923. // Parse a regular expression. Some context-awareness is necessary,
  2924. // since a '/' inside a '[]' set does not end the expression.
  2925. function tryCreateRegexp(src, flags, throwErrorAt, parser) {
  2926. try {
  2927. return new RegExp(src, flags);
  2928. } catch (e) {
  2929. if (throwErrorAt !== undefined) {
  2930. if (e instanceof SyntaxError) parser.raise(throwErrorAt, "Error parsing regular expression: " + e.message);
  2931. throw e;
  2932. }
  2933. }
  2934. }
  2935. var regexpUnicodeSupport = !!tryCreateRegexp("￿", "u");
  2936. pp.readRegexp = function () {
  2937. var _this = this;
  2938. var escaped = undefined,
  2939. inClass = undefined,
  2940. start = this.pos;
  2941. for (;;) {
  2942. if (this.pos >= this.input.length) this.raise(start, "Unterminated regular expression");
  2943. var ch = this.input.charAt(this.pos);
  2944. if (_whitespace.lineBreak.test(ch)) this.raise(start, "Unterminated regular expression");
  2945. if (!escaped) {
  2946. if (ch === "[") inClass = true;else if (ch === "]" && inClass) inClass = false;else if (ch === "/" && !inClass) break;
  2947. escaped = ch === "\\";
  2948. } else escaped = false;
  2949. ++this.pos;
  2950. }
  2951. var content = this.input.slice(start, this.pos);
  2952. ++this.pos;
  2953. // Need to use `readWord1` because '\uXXXX' sequences are allowed
  2954. // here (don't ask).
  2955. var mods = this.readWord1();
  2956. var tmp = content,
  2957. tmpFlags = "";
  2958. if (mods) {
  2959. var validFlags = /^[gim]*$/;
  2960. if (this.options.ecmaVersion >= 6) validFlags = /^[gimuy]*$/;
  2961. if (!validFlags.test(mods)) this.raise(start, "Invalid regular expression flag");
  2962. if (mods.indexOf("u") >= 0) {
  2963. if (regexpUnicodeSupport) {
  2964. tmpFlags = "u";
  2965. } else {
  2966. // Replace each astral symbol and every Unicode escape sequence that
  2967. // possibly represents an astral symbol or a paired surrogate with a
  2968. // single ASCII symbol to avoid throwing on regular expressions that
  2969. // are only valid in combination with the `/u` flag.
  2970. // Note: replacing with the ASCII symbol `x` might cause false
  2971. // negatives in unlikely scenarios. For example, `[\u{61}-b]` is a
  2972. // perfectly valid pattern that is equivalent to `[a-b]`, but it would
  2973. // be replaced by `[x-b]` which throws an error.
  2974. tmp = tmp.replace(/\\u\{([0-9a-fA-F]+)\}/g, function (_match, code, offset) {
  2975. code = Number("0x" + code);
  2976. if (code > 0x10FFFF) _this.raise(start + offset + 3, "Code point out of bounds");
  2977. return "x";
  2978. });
  2979. tmp = tmp.replace(/\\u([a-fA-F0-9]{4})|[\uD800-\uDBFF][\uDC00-\uDFFF]/g, "x");
  2980. tmpFlags = tmpFlags.replace("u", "");
  2981. }
  2982. }
  2983. }
  2984. // Detect invalid regular expressions.
  2985. var value = null;
  2986. // Rhino's regular expression parser is flaky and throws uncatchable exceptions,
  2987. // so don't do detection if we are running under Rhino
  2988. if (!isRhino) {
  2989. tryCreateRegexp(tmp, tmpFlags, start, this);
  2990. // Get a regular expression object for this pattern-flag pair, or `null` in
  2991. // case the current environment doesn't support the flags it uses.
  2992. value = tryCreateRegexp(content, mods);
  2993. }
  2994. return this.finishToken(_tokentype.types.regexp, { pattern: content, flags: mods, value: value });
  2995. };
  2996. // Read an integer in the given radix. Return null if zero digits
  2997. // were read, the integer value otherwise. When `len` is given, this
  2998. // will return `null` unless the integer has exactly `len` digits.
  2999. pp.readInt = function (radix, len) {
  3000. var start = this.pos,
  3001. total = 0;
  3002. for (var i = 0, e = len == null ? Infinity : len; i < e; ++i) {
  3003. var code = this.input.charCodeAt(this.pos),
  3004. val = undefined;
  3005. if (code >= 97) val = code - 97 + 10; // a
  3006. else if (code >= 65) val = code - 65 + 10; // A
  3007. else if (code >= 48 && code <= 57) val = code - 48; // 0-9
  3008. else val = Infinity;
  3009. if (val >= radix) break;
  3010. ++this.pos;
  3011. total = total * radix + val;
  3012. }
  3013. if (this.pos === start || len != null && this.pos - start !== len) return null;
  3014. return total;
  3015. };
  3016. pp.readRadixNumber = function (radix) {
  3017. this.pos += 2; // 0x
  3018. var val = this.readInt(radix);
  3019. if (val == null) this.raise(this.start + 2, "Expected number in radix " + radix);
  3020. if (_identifier.isIdentifierStart(this.fullCharCodeAtPos())) this.raise(this.pos, "Identifier directly after number");
  3021. return this.finishToken(_tokentype.types.num, val);
  3022. };
  3023. // Read an integer, octal integer, or floating-point number.
  3024. pp.readNumber = function (startsWithDot) {
  3025. var start = this.pos,
  3026. isFloat = false,
  3027. octal = this.input.charCodeAt(this.pos) === 48;
  3028. if (!startsWithDot && this.readInt(10) === null) this.raise(start, "Invalid number");
  3029. var next = this.input.charCodeAt(this.pos);
  3030. if (next === 46) {
  3031. // '.'
  3032. ++this.pos;
  3033. this.readInt(10);
  3034. isFloat = true;
  3035. next = this.input.charCodeAt(this.pos);
  3036. }
  3037. if (next === 69 || next === 101) {
  3038. // 'eE'
  3039. next = this.input.charCodeAt(++this.pos);
  3040. if (next === 43 || next === 45) ++this.pos; // '+-'
  3041. if (this.readInt(10) === null) this.raise(start, "Invalid number");
  3042. isFloat = true;
  3043. }
  3044. if (_identifier.isIdentifierStart(this.fullCharCodeAtPos())) this.raise(this.pos, "Identifier directly after number");
  3045. var str = this.input.slice(start, this.pos),
  3046. val = undefined;
  3047. 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);
  3048. return this.finishToken(_tokentype.types.num, val);
  3049. };
  3050. // Read a string value, interpreting backslash-escapes.
  3051. pp.readCodePoint = function () {
  3052. var ch = this.input.charCodeAt(this.pos),
  3053. code = undefined;
  3054. if (ch === 123) {
  3055. if (this.options.ecmaVersion < 6) this.unexpected();
  3056. var codePos = ++this.pos;
  3057. code = this.readHexChar(this.input.indexOf('}', this.pos) - this.pos);
  3058. ++this.pos;
  3059. if (code > 0x10FFFF) this.raise(codePos, "Code point out of bounds");
  3060. } else {
  3061. code = this.readHexChar(4);
  3062. }
  3063. return code;
  3064. };
  3065. function codePointToString(code) {
  3066. // UTF-16 Decoding
  3067. if (code <= 0xFFFF) return String.fromCharCode(code);
  3068. code -= 0x10000;
  3069. return String.fromCharCode((code >> 10) + 0xD800, (code & 1023) + 0xDC00);
  3070. }
  3071. pp.readString = function (quote) {
  3072. var out = "",
  3073. chunkStart = ++this.pos;
  3074. for (;;) {
  3075. if (this.pos >= this.input.length) this.raise(this.start, "Unterminated string constant");
  3076. var ch = this.input.charCodeAt(this.pos);
  3077. if (ch === quote) break;
  3078. if (ch === 92) {
  3079. // '\'
  3080. out += this.input.slice(chunkStart, this.pos);
  3081. out += this.readEscapedChar(false);
  3082. chunkStart = this.pos;
  3083. } else {
  3084. if (_whitespace.isNewLine(ch)) this.raise(this.start, "Unterminated string constant");
  3085. ++this.pos;
  3086. }
  3087. }
  3088. out += this.input.slice(chunkStart, this.pos++);
  3089. return this.finishToken(_tokentype.types.string, out);
  3090. };
  3091. // Reads template string tokens.
  3092. pp.readTmplToken = function () {
  3093. var out = "",
  3094. chunkStart = this.pos;
  3095. for (;;) {
  3096. if (this.pos >= this.input.length) this.raise(this.start, "Unterminated template");
  3097. var ch = this.input.charCodeAt(this.pos);
  3098. if (ch === 96 || ch === 36 && this.input.charCodeAt(this.pos + 1) === 123) {
  3099. // '`', '${'
  3100. if (this.pos === this.start && this.type === _tokentype.types.template) {
  3101. if (ch === 36) {
  3102. this.pos += 2;
  3103. return this.finishToken(_tokentype.types.dollarBraceL);
  3104. } else {
  3105. ++this.pos;
  3106. return this.finishToken(_tokentype.types.backQuote);
  3107. }
  3108. }
  3109. out += this.input.slice(chunkStart, this.pos);
  3110. return this.finishToken(_tokentype.types.template, out);
  3111. }
  3112. if (ch === 92) {
  3113. // '\'
  3114. out += this.input.slice(chunkStart, this.pos);
  3115. out += this.readEscapedChar(true);
  3116. chunkStart = this.pos;
  3117. } else if (_whitespace.isNewLine(ch)) {
  3118. out += this.input.slice(chunkStart, this.pos);
  3119. ++this.pos;
  3120. switch (ch) {
  3121. case 13:
  3122. if (this.input.charCodeAt(this.pos) === 10) ++this.pos;
  3123. case 10:
  3124. out += "\n";
  3125. break;
  3126. default:
  3127. out += String.fromCharCode(ch);
  3128. break;
  3129. }
  3130. if (this.options.locations) {
  3131. ++this.curLine;
  3132. this.lineStart = this.pos;
  3133. }
  3134. chunkStart = this.pos;
  3135. } else {
  3136. ++this.pos;
  3137. }
  3138. }
  3139. };
  3140. // Used to read escaped characters
  3141. pp.readEscapedChar = function (inTemplate) {
  3142. var ch = this.input.charCodeAt(++this.pos);
  3143. ++this.pos;
  3144. switch (ch) {
  3145. case 110:
  3146. return "\n"; // 'n' -> '\n'
  3147. case 114:
  3148. return "\r"; // 'r' -> '\r'
  3149. case 120:
  3150. return String.fromCharCode(this.readHexChar(2)); // 'x'
  3151. case 117:
  3152. return codePointToString(this.readCodePoint()); // 'u'
  3153. case 116:
  3154. return "\t"; // 't' -> '\t'
  3155. case 98:
  3156. return "\b"; // 'b' -> '\b'
  3157. case 118:
  3158. return "\u000b"; // 'v' -> '\u000b'
  3159. case 102:
  3160. return "\f"; // 'f' -> '\f'
  3161. case 13:
  3162. if (this.input.charCodeAt(this.pos) === 10) ++this.pos; // '\r\n'
  3163. case 10:
  3164. // ' \n'
  3165. if (this.options.locations) {
  3166. this.lineStart = this.pos;++this.curLine;
  3167. }
  3168. return "";
  3169. default:
  3170. if (ch >= 48 && ch <= 55) {
  3171. var octalStr = this.input.substr(this.pos - 1, 3).match(/^[0-7]+/)[0];
  3172. var octal = parseInt(octalStr, 8);
  3173. if (octal > 255) {
  3174. octalStr = octalStr.slice(0, -1);
  3175. octal = parseInt(octalStr, 8);
  3176. }
  3177. if (octalStr !== "0" && (this.strict || inTemplate)) {
  3178. this.raise(this.pos - 2, "Octal literal in strict mode");
  3179. }
  3180. this.pos += octalStr.length - 1;
  3181. return String.fromCharCode(octal);
  3182. }
  3183. return String.fromCharCode(ch);
  3184. }
  3185. };
  3186. // Used to read character escape sequences ('\x', '\u', '\U').
  3187. pp.readHexChar = function (len) {
  3188. var codePos = this.pos;
  3189. var n = this.readInt(16, len);
  3190. if (n === null) this.raise(codePos, "Bad character escape sequence");
  3191. return n;
  3192. };
  3193. // Read an identifier, and return it as a string. Sets `this.containsEsc`
  3194. // to whether the word contained a '\u' escape.
  3195. //
  3196. // Incrementally adds only escaped chars, adding other chunks as-is
  3197. // as a micro-optimization.
  3198. pp.readWord1 = function () {
  3199. this.containsEsc = false;
  3200. var word = "",
  3201. first = true,
  3202. chunkStart = this.pos;
  3203. var astral = this.options.ecmaVersion >= 6;
  3204. while (this.pos < this.input.length) {
  3205. var ch = this.fullCharCodeAtPos();
  3206. if (_identifier.isIdentifierChar(ch, astral)) {
  3207. this.pos += ch <= 0xffff ? 1 : 2;
  3208. } else if (ch === 92) {
  3209. // "\"
  3210. this.containsEsc = true;
  3211. word += this.input.slice(chunkStart, this.pos);
  3212. var escStart = this.pos;
  3213. if (this.input.charCodeAt(++this.pos) != 117) // "u"
  3214. this.raise(this.pos, "Expecting Unicode escape sequence \\uXXXX");
  3215. ++this.pos;
  3216. var esc = this.readCodePoint();
  3217. if (!(first ? _identifier.isIdentifierStart : _identifier.isIdentifierChar)(esc, astral)) this.raise(escStart, "Invalid Unicode escape");
  3218. word += codePointToString(esc);
  3219. chunkStart = this.pos;
  3220. } else {
  3221. break;
  3222. }
  3223. first = false;
  3224. }
  3225. return word + this.input.slice(chunkStart, this.pos);
  3226. };
  3227. // Read an identifier or keyword token. Will check for reserved
  3228. // words when necessary.
  3229. pp.readWord = function () {
  3230. var word = this.readWord1();
  3231. var type = _tokentype.types.name;
  3232. if ((this.options.ecmaVersion >= 6 || !this.containsEsc) && this.keywords.test(word)) type = _tokentype.keywords[word];
  3233. return this.finishToken(type, word);
  3234. };
  3235. },{"./identifier":2,"./locutil":5,"./state":10,"./tokentype":14,"./whitespace":16}],14:[function(_dereq_,module,exports){
  3236. // ## Token types
  3237. // The assignment of fine-grained, information-carrying type objects
  3238. // allows the tokenizer to store the information it has about a
  3239. // token in a way that is very cheap for the parser to look up.
  3240. // All token type variables start with an underscore, to make them
  3241. // easy to recognize.
  3242. // The `beforeExpr` property is used to disambiguate between regular
  3243. // expressions and divisions. It is set on all token types that can
  3244. // be followed by an expression (thus, a slash after them would be a
  3245. // regular expression).
  3246. //
  3247. // The `startsExpr` property is used to check if the token ends a
  3248. // `yield` expression. It is set on all token types that either can
  3249. // directly start an expression (like a quotation mark) or can
  3250. // continue an expression (like the body of a string).
  3251. //
  3252. // `isLoop` marks a keyword as starting a loop, which is important
  3253. // to know when parsing a label, in order to allow or disallow
  3254. // continue jumps to that label.
  3255. "use strict";
  3256. exports.__esModule = true;
  3257. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3258. var TokenType = function TokenType(label) {
  3259. var conf = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
  3260. _classCallCheck(this, TokenType);
  3261. this.label = label;
  3262. this.keyword = conf.keyword;
  3263. this.beforeExpr = !!conf.beforeExpr;
  3264. this.startsExpr = !!conf.startsExpr;
  3265. this.isLoop = !!conf.isLoop;
  3266. this.isAssign = !!conf.isAssign;
  3267. this.prefix = !!conf.prefix;
  3268. this.postfix = !!conf.postfix;
  3269. this.binop = conf.binop || null;
  3270. this.updateContext = null;
  3271. };
  3272. exports.TokenType = TokenType;
  3273. function binop(name, prec) {
  3274. return new TokenType(name, { beforeExpr: true, binop: prec });
  3275. }
  3276. var beforeExpr = { beforeExpr: true },
  3277. startsExpr = { startsExpr: true };
  3278. var types = {
  3279. num: new TokenType("num", startsExpr),
  3280. regexp: new TokenType("regexp", startsExpr),
  3281. string: new TokenType("string", startsExpr),
  3282. name: new TokenType("name", startsExpr),
  3283. eof: new TokenType("eof"),
  3284. // Punctuation token types.
  3285. bracketL: new TokenType("[", { beforeExpr: true, startsExpr: true }),
  3286. bracketR: new TokenType("]"),
  3287. braceL: new TokenType("{", { beforeExpr: true, startsExpr: true }),
  3288. braceR: new TokenType("}"),
  3289. parenL: new TokenType("(", { beforeExpr: true, startsExpr: true }),
  3290. parenR: new TokenType(")"),
  3291. comma: new TokenType(",", beforeExpr),
  3292. semi: new TokenType(";", beforeExpr),
  3293. colon: new TokenType(":", beforeExpr),
  3294. dot: new TokenType("."),
  3295. question: new TokenType("?", beforeExpr),
  3296. arrow: new TokenType("=>", beforeExpr),
  3297. template: new TokenType("template"),
  3298. ellipsis: new TokenType("...", beforeExpr),
  3299. backQuote: new TokenType("`", startsExpr),
  3300. dollarBraceL: new TokenType("${", { beforeExpr: true, startsExpr: true }),
  3301. // Operators. These carry several kinds of properties to help the
  3302. // parser use them properly (the presence of these properties is
  3303. // what categorizes them as operators).
  3304. //
  3305. // `binop`, when present, specifies that this operator is a binary
  3306. // operator, and will refer to its precedence.
  3307. //
  3308. // `prefix` and `postfix` mark the operator as a prefix or postfix
  3309. // unary operator.
  3310. //
  3311. // `isAssign` marks all of `=`, `+=`, `-=` etcetera, which act as
  3312. // binary operators with a very low precedence, that should result
  3313. // in AssignmentExpression nodes.
  3314. eq: new TokenType("=", { beforeExpr: true, isAssign: true }),
  3315. assign: new TokenType("_=", { beforeExpr: true, isAssign: true }),
  3316. incDec: new TokenType("++/--", { prefix: true, postfix: true, startsExpr: true }),
  3317. prefix: new TokenType("prefix", { beforeExpr: true, prefix: true, startsExpr: true }),
  3318. logicalOR: binop("||", 1),
  3319. logicalAND: binop("&&", 2),
  3320. bitwiseOR: binop("|", 3),
  3321. bitwiseXOR: binop("^", 4),
  3322. bitwiseAND: binop("&", 5),
  3323. equality: binop("==/!=", 6),
  3324. relational: binop("</>", 7),
  3325. bitShift: binop("<</>>", 8),
  3326. plusMin: new TokenType("+/-", { beforeExpr: true, binop: 9, prefix: true, startsExpr: true }),
  3327. modulo: binop("%", 10),
  3328. star: binop("*", 10),
  3329. slash: binop("/", 10),
  3330. starstar: new TokenType("**", { beforeExpr: true })
  3331. };
  3332. exports.types = types;
  3333. // Map keyword names to token types.
  3334. var keywords = {};
  3335. exports.keywords = keywords;
  3336. // Succinct definitions of keyword token types
  3337. function kw(name) {
  3338. var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
  3339. options.keyword = name;
  3340. keywords[name] = types["_" + name] = new TokenType(name, options);
  3341. }
  3342. kw("break");
  3343. kw("case", beforeExpr);
  3344. kw("catch");
  3345. kw("continue");
  3346. kw("debugger");
  3347. kw("default", beforeExpr);
  3348. kw("do", { isLoop: true, beforeExpr: true });
  3349. kw("else", beforeExpr);
  3350. kw("finally");
  3351. kw("for", { isLoop: true });
  3352. kw("function", startsExpr);
  3353. kw("if");
  3354. kw("return", beforeExpr);
  3355. kw("switch");
  3356. kw("throw", beforeExpr);
  3357. kw("try");
  3358. kw("var");
  3359. kw("const");
  3360. kw("while", { isLoop: true });
  3361. kw("with");
  3362. kw("new", { beforeExpr: true, startsExpr: true });
  3363. kw("this", startsExpr);
  3364. kw("super", startsExpr);
  3365. kw("class");
  3366. kw("extends", beforeExpr);
  3367. kw("export");
  3368. kw("import");
  3369. kw("null", startsExpr);
  3370. kw("true", startsExpr);
  3371. kw("false", startsExpr);
  3372. kw("in", { beforeExpr: true, binop: 7 });
  3373. kw("instanceof", { beforeExpr: true, binop: 7 });
  3374. kw("typeof", { beforeExpr: true, prefix: true, startsExpr: true });
  3375. kw("void", { beforeExpr: true, prefix: true, startsExpr: true });
  3376. kw("delete", { beforeExpr: true, prefix: true, startsExpr: true });
  3377. },{}],15:[function(_dereq_,module,exports){
  3378. "use strict";
  3379. exports.__esModule = true;
  3380. exports.isArray = isArray;
  3381. exports.has = has;
  3382. function isArray(obj) {
  3383. return Object.prototype.toString.call(obj) === "[object Array]";
  3384. }
  3385. // Checks if an object has a property.
  3386. function has(obj, propName) {
  3387. return Object.prototype.hasOwnProperty.call(obj, propName);
  3388. }
  3389. },{}],16:[function(_dereq_,module,exports){
  3390. // Matches a whole line break (where CRLF is considered a single
  3391. // line break). Used to count lines.
  3392. "use strict";
  3393. exports.__esModule = true;
  3394. exports.isNewLine = isNewLine;
  3395. var lineBreak = /\r\n?|\n|\u2028|\u2029/;
  3396. exports.lineBreak = lineBreak;
  3397. var lineBreakG = new RegExp(lineBreak.source, "g");
  3398. exports.lineBreakG = lineBreakG;
  3399. function isNewLine(code) {
  3400. return code === 10 || code === 13 || code === 0x2028 || code == 0x2029;
  3401. }
  3402. var nonASCIIwhitespace = /[\u1680\u180e\u2000-\u200a\u202f\u205f\u3000\ufeff]/;
  3403. exports.nonASCIIwhitespace = nonASCIIwhitespace;
  3404. var skipWhiteSpace = /(?:\s|\/\/.*|\/\*[^]*?\*\/)*/g;
  3405. exports.skipWhiteSpace = skipWhiteSpace;
  3406. },{}]},{},[3])(3)
  3407. });
  3408. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  3409. },{}],6:[function(_dereq_,module,exports){
  3410. _dereq_('../../modules/es6.array.filter');
  3411. module.exports = _dereq_('../../modules/_core').Array.filter;
  3412. },{"../../modules/_core":23,"../../modules/es6.array.filter":57}],7:[function(_dereq_,module,exports){
  3413. _dereq_('../../modules/es6.array.for-each');
  3414. module.exports = _dereq_('../../modules/_core').Array.forEach;
  3415. },{"../../modules/_core":23,"../../modules/es6.array.for-each":58}],8:[function(_dereq_,module,exports){
  3416. _dereq_('../../modules/es6.array.index-of');
  3417. module.exports = _dereq_('../../modules/_core').Array.indexOf;
  3418. },{"../../modules/_core":23,"../../modules/es6.array.index-of":59}],9:[function(_dereq_,module,exports){
  3419. _dereq_('../../modules/es6.array.is-array');
  3420. module.exports = _dereq_('../../modules/_core').Array.isArray;
  3421. },{"../../modules/_core":23,"../../modules/es6.array.is-array":60}],10:[function(_dereq_,module,exports){
  3422. _dereq_('../../modules/es6.array.map');
  3423. module.exports = _dereq_('../../modules/_core').Array.map;
  3424. },{"../../modules/_core":23,"../../modules/es6.array.map":61}],11:[function(_dereq_,module,exports){
  3425. _dereq_('../../modules/es6.array.reduce-right');
  3426. module.exports = _dereq_('../../modules/_core').Array.reduceRight;
  3427. },{"../../modules/_core":23,"../../modules/es6.array.reduce-right":62}],12:[function(_dereq_,module,exports){
  3428. _dereq_('../../modules/es6.array.reduce');
  3429. module.exports = _dereq_('../../modules/_core').Array.reduce;
  3430. },{"../../modules/_core":23,"../../modules/es6.array.reduce":63}],13:[function(_dereq_,module,exports){
  3431. _dereq_('../../modules/es6.object.assign');
  3432. module.exports = _dereq_('../../modules/_core').Object.assign;
  3433. },{"../../modules/_core":23,"../../modules/es6.object.assign":64}],14:[function(_dereq_,module,exports){
  3434. _dereq_('../../modules/es6.object.keys');
  3435. module.exports = _dereq_('../../modules/_core').Object.keys;
  3436. },{"../../modules/_core":23,"../../modules/es6.object.keys":65}],15:[function(_dereq_,module,exports){
  3437. module.exports = function(it){
  3438. if(typeof it != 'function')throw TypeError(it + ' is not a function!');
  3439. return it;
  3440. };
  3441. },{}],16:[function(_dereq_,module,exports){
  3442. var isObject = _dereq_('./_is-object');
  3443. module.exports = function(it){
  3444. if(!isObject(it))throw TypeError(it + ' is not an object!');
  3445. return it;
  3446. };
  3447. },{"./_is-object":37}],17:[function(_dereq_,module,exports){
  3448. // false -> Array#indexOf
  3449. // true -> Array#includes
  3450. var toIObject = _dereq_('./_to-iobject')
  3451. , toLength = _dereq_('./_to-length')
  3452. , toIndex = _dereq_('./_to-index');
  3453. module.exports = function(IS_INCLUDES){
  3454. return function($this, el, fromIndex){
  3455. var O = toIObject($this)
  3456. , length = toLength(O.length)
  3457. , index = toIndex(fromIndex, length)
  3458. , value;
  3459. // Array#includes uses SameValueZero equality algorithm
  3460. if(IS_INCLUDES && el != el)while(length > index){
  3461. value = O[index++];
  3462. if(value != value)return true;
  3463. // Array#toIndex ignores holes, Array#includes - not
  3464. } else for(;length > index; index++)if(IS_INCLUDES || index in O){
  3465. if(O[index] === el)return IS_INCLUDES || index || 0;
  3466. } return !IS_INCLUDES && -1;
  3467. };
  3468. };
  3469. },{"./_to-index":49,"./_to-iobject":51,"./_to-length":52}],18:[function(_dereq_,module,exports){
  3470. // 0 -> Array#forEach
  3471. // 1 -> Array#map
  3472. // 2 -> Array#filter
  3473. // 3 -> Array#some
  3474. // 4 -> Array#every
  3475. // 5 -> Array#find
  3476. // 6 -> Array#findIndex
  3477. var ctx = _dereq_('./_ctx')
  3478. , IObject = _dereq_('./_iobject')
  3479. , toObject = _dereq_('./_to-object')
  3480. , toLength = _dereq_('./_to-length')
  3481. , asc = _dereq_('./_array-species-create');
  3482. module.exports = function(TYPE, $create){
  3483. var IS_MAP = TYPE == 1
  3484. , IS_FILTER = TYPE == 2
  3485. , IS_SOME = TYPE == 3
  3486. , IS_EVERY = TYPE == 4
  3487. , IS_FIND_INDEX = TYPE == 6
  3488. , NO_HOLES = TYPE == 5 || IS_FIND_INDEX
  3489. , create = $create || asc;
  3490. return function($this, callbackfn, that){
  3491. var O = toObject($this)
  3492. , self = IObject(O)
  3493. , f = ctx(callbackfn, that, 3)
  3494. , length = toLength(self.length)
  3495. , index = 0
  3496. , result = IS_MAP ? create($this, length) : IS_FILTER ? create($this, 0) : undefined
  3497. , val, res;
  3498. for(;length > index; index++)if(NO_HOLES || index in self){
  3499. val = self[index];
  3500. res = f(val, index, O);
  3501. if(TYPE){
  3502. if(IS_MAP)result[index] = res; // map
  3503. else if(res)switch(TYPE){
  3504. case 3: return true; // some
  3505. case 5: return val; // find
  3506. case 6: return index; // findIndex
  3507. case 2: result.push(val); // filter
  3508. } else if(IS_EVERY)return false; // every
  3509. }
  3510. }
  3511. return IS_FIND_INDEX ? -1 : IS_SOME || IS_EVERY ? IS_EVERY : result;
  3512. };
  3513. };
  3514. },{"./_array-species-create":21,"./_ctx":24,"./_iobject":35,"./_to-length":52,"./_to-object":53}],19:[function(_dereq_,module,exports){
  3515. var aFunction = _dereq_('./_a-function')
  3516. , toObject = _dereq_('./_to-object')
  3517. , IObject = _dereq_('./_iobject')
  3518. , toLength = _dereq_('./_to-length');
  3519. module.exports = function(that, callbackfn, aLen, memo, isRight){
  3520. aFunction(callbackfn);
  3521. var O = toObject(that)
  3522. , self = IObject(O)
  3523. , length = toLength(O.length)
  3524. , index = isRight ? length - 1 : 0
  3525. , i = isRight ? -1 : 1;
  3526. if(aLen < 2)for(;;){
  3527. if(index in self){
  3528. memo = self[index];
  3529. index += i;
  3530. break;
  3531. }
  3532. index += i;
  3533. if(isRight ? index < 0 : length <= index){
  3534. throw TypeError('Reduce of empty array with no initial value');
  3535. }
  3536. }
  3537. for(;isRight ? index >= 0 : length > index; index += i)if(index in self){
  3538. memo = callbackfn(memo, self[index], index, O);
  3539. }
  3540. return memo;
  3541. };
  3542. },{"./_a-function":15,"./_iobject":35,"./_to-length":52,"./_to-object":53}],20:[function(_dereq_,module,exports){
  3543. var isObject = _dereq_('./_is-object')
  3544. , isArray = _dereq_('./_is-array')
  3545. , SPECIES = _dereq_('./_wks')('species');
  3546. module.exports = function(original){
  3547. var C;
  3548. if(isArray(original)){
  3549. C = original.constructor;
  3550. // cross-realm fallback
  3551. if(typeof C == 'function' && (C === Array || isArray(C.prototype)))C = undefined;
  3552. if(isObject(C)){
  3553. C = C[SPECIES];
  3554. if(C === null)C = undefined;
  3555. }
  3556. } return C === undefined ? Array : C;
  3557. };
  3558. },{"./_is-array":36,"./_is-object":37,"./_wks":56}],21:[function(_dereq_,module,exports){
  3559. // 9.4.2.3 ArraySpeciesCreate(originalArray, length)
  3560. var speciesConstructor = _dereq_('./_array-species-constructor');
  3561. module.exports = function(original, length){
  3562. return new (speciesConstructor(original))(length);
  3563. };
  3564. },{"./_array-species-constructor":20}],22:[function(_dereq_,module,exports){
  3565. var toString = {}.toString;
  3566. module.exports = function(it){
  3567. return toString.call(it).slice(8, -1);
  3568. };
  3569. },{}],23:[function(_dereq_,module,exports){
  3570. var core = module.exports = {version: '2.4.0'};
  3571. if(typeof __e == 'number')__e = core; // eslint-disable-line no-undef
  3572. },{}],24:[function(_dereq_,module,exports){
  3573. // optional / simple context binding
  3574. var aFunction = _dereq_('./_a-function');
  3575. module.exports = function(fn, that, length){
  3576. aFunction(fn);
  3577. if(that === undefined)return fn;
  3578. switch(length){
  3579. case 1: return function(a){
  3580. return fn.call(that, a);
  3581. };
  3582. case 2: return function(a, b){
  3583. return fn.call(that, a, b);
  3584. };
  3585. case 3: return function(a, b, c){
  3586. return fn.call(that, a, b, c);
  3587. };
  3588. }
  3589. return function(/* ...args */){
  3590. return fn.apply(that, arguments);
  3591. };
  3592. };
  3593. },{"./_a-function":15}],25:[function(_dereq_,module,exports){
  3594. // 7.2.1 RequireObjectCoercible(argument)
  3595. module.exports = function(it){
  3596. if(it == undefined)throw TypeError("Can't call method on " + it);
  3597. return it;
  3598. };
  3599. },{}],26:[function(_dereq_,module,exports){
  3600. // Thank's IE8 for his funny defineProperty
  3601. module.exports = !_dereq_('./_fails')(function(){
  3602. return Object.defineProperty({}, 'a', {get: function(){ return 7; }}).a != 7;
  3603. });
  3604. },{"./_fails":30}],27:[function(_dereq_,module,exports){
  3605. var isObject = _dereq_('./_is-object')
  3606. , document = _dereq_('./_global').document
  3607. // in old IE typeof document.createElement is 'object'
  3608. , is = isObject(document) && isObject(document.createElement);
  3609. module.exports = function(it){
  3610. return is ? document.createElement(it) : {};
  3611. };
  3612. },{"./_global":31,"./_is-object":37}],28:[function(_dereq_,module,exports){
  3613. // IE 8- don't enum bug keys
  3614. module.exports = (
  3615. 'constructor,hasOwnProperty,isPrototypeOf,propertyIsEnumerable,toLocaleString,toString,valueOf'
  3616. ).split(',');
  3617. },{}],29:[function(_dereq_,module,exports){
  3618. var global = _dereq_('./_global')
  3619. , core = _dereq_('./_core')
  3620. , ctx = _dereq_('./_ctx')
  3621. , hide = _dereq_('./_hide')
  3622. , PROTOTYPE = 'prototype';
  3623. var $export = function(type, name, source){
  3624. var IS_FORCED = type & $export.F
  3625. , IS_GLOBAL = type & $export.G
  3626. , IS_STATIC = type & $export.S
  3627. , IS_PROTO = type & $export.P
  3628. , IS_BIND = type & $export.B
  3629. , IS_WRAP = type & $export.W
  3630. , exports = IS_GLOBAL ? core : core[name] || (core[name] = {})
  3631. , expProto = exports[PROTOTYPE]
  3632. , target = IS_GLOBAL ? global : IS_STATIC ? global[name] : (global[name] || {})[PROTOTYPE]
  3633. , key, own, out;
  3634. if(IS_GLOBAL)source = name;
  3635. for(key in source){
  3636. // contains in native
  3637. own = !IS_FORCED && target && target[key] !== undefined;
  3638. if(own && key in exports)continue;
  3639. // export native or passed
  3640. out = own ? target[key] : source[key];
  3641. // prevent global pollution for namespaces
  3642. exports[key] = IS_GLOBAL && typeof target[key] != 'function' ? source[key]
  3643. // bind timers to global for call from export context
  3644. : IS_BIND && own ? ctx(out, global)
  3645. // wrap global constructors for prevent change them in library
  3646. : IS_WRAP && target[key] == out ? (function(C){
  3647. var F = function(a, b, c){
  3648. if(this instanceof C){
  3649. switch(arguments.length){
  3650. case 0: return new C;
  3651. case 1: return new C(a);
  3652. case 2: return new C(a, b);
  3653. } return new C(a, b, c);
  3654. } return C.apply(this, arguments);
  3655. };
  3656. F[PROTOTYPE] = C[PROTOTYPE];
  3657. return F;
  3658. // make static versions for prototype methods
  3659. })(out) : IS_PROTO && typeof out == 'function' ? ctx(Function.call, out) : out;
  3660. // export proto methods to core.%CONSTRUCTOR%.methods.%NAME%
  3661. if(IS_PROTO){
  3662. (exports.virtual || (exports.virtual = {}))[key] = out;
  3663. // export proto methods to core.%CONSTRUCTOR%.prototype.%NAME%
  3664. if(type & $export.R && expProto && !expProto[key])hide(expProto, key, out);
  3665. }
  3666. }
  3667. };
  3668. // type bitmap
  3669. $export.F = 1; // forced
  3670. $export.G = 2; // global
  3671. $export.S = 4; // static
  3672. $export.P = 8; // proto
  3673. $export.B = 16; // bind
  3674. $export.W = 32; // wrap
  3675. $export.U = 64; // safe
  3676. $export.R = 128; // real proto method for `library`
  3677. module.exports = $export;
  3678. },{"./_core":23,"./_ctx":24,"./_global":31,"./_hide":33}],30:[function(_dereq_,module,exports){
  3679. module.exports = function(exec){
  3680. try {
  3681. return !!exec();
  3682. } catch(e){
  3683. return true;
  3684. }
  3685. };
  3686. },{}],31:[function(_dereq_,module,exports){
  3687. // https://github.com/zloirock/core-js/issues/86#issuecomment-115759028
  3688. var global = module.exports = typeof window != 'undefined' && window.Math == Math
  3689. ? window : typeof self != 'undefined' && self.Math == Math ? self : Function('return this')();
  3690. if(typeof __g == 'number')__g = global; // eslint-disable-line no-undef
  3691. },{}],32:[function(_dereq_,module,exports){
  3692. var hasOwnProperty = {}.hasOwnProperty;
  3693. module.exports = function(it, key){
  3694. return hasOwnProperty.call(it, key);
  3695. };
  3696. },{}],33:[function(_dereq_,module,exports){
  3697. var dP = _dereq_('./_object-dp')
  3698. , createDesc = _dereq_('./_property-desc');
  3699. module.exports = _dereq_('./_descriptors') ? function(object, key, value){
  3700. return dP.f(object, key, createDesc(1, value));
  3701. } : function(object, key, value){
  3702. object[key] = value;
  3703. return object;
  3704. };
  3705. },{"./_descriptors":26,"./_object-dp":39,"./_property-desc":45}],34:[function(_dereq_,module,exports){
  3706. module.exports = !_dereq_('./_descriptors') && !_dereq_('./_fails')(function(){
  3707. return Object.defineProperty(_dereq_('./_dom-create')('div'), 'a', {get: function(){ return 7; }}).a != 7;
  3708. });
  3709. },{"./_descriptors":26,"./_dom-create":27,"./_fails":30}],35:[function(_dereq_,module,exports){
  3710. // fallback for non-array-like ES3 and non-enumerable old V8 strings
  3711. var cof = _dereq_('./_cof');
  3712. module.exports = Object('z').propertyIsEnumerable(0) ? Object : function(it){
  3713. return cof(it) == 'String' ? it.split('') : Object(it);
  3714. };
  3715. },{"./_cof":22}],36:[function(_dereq_,module,exports){
  3716. // 7.2.2 IsArray(argument)
  3717. var cof = _dereq_('./_cof');
  3718. module.exports = Array.isArray || function isArray(arg){
  3719. return cof(arg) == 'Array';
  3720. };
  3721. },{"./_cof":22}],37:[function(_dereq_,module,exports){
  3722. module.exports = function(it){
  3723. return typeof it === 'object' ? it !== null : typeof it === 'function';
  3724. };
  3725. },{}],38:[function(_dereq_,module,exports){
  3726. 'use strict';
  3727. // 19.1.2.1 Object.assign(target, source, ...)
  3728. var getKeys = _dereq_('./_object-keys')
  3729. , gOPS = _dereq_('./_object-gops')
  3730. , pIE = _dereq_('./_object-pie')
  3731. , toObject = _dereq_('./_to-object')
  3732. , IObject = _dereq_('./_iobject')
  3733. , $assign = Object.assign;
  3734. // should work with symbols and should have deterministic property order (V8 bug)
  3735. module.exports = !$assign || _dereq_('./_fails')(function(){
  3736. var A = {}
  3737. , B = {}
  3738. , S = Symbol()
  3739. , K = 'abcdefghijklmnopqrst';
  3740. A[S] = 7;
  3741. K.split('').forEach(function(k){ B[k] = k; });
  3742. return $assign({}, A)[S] != 7 || Object.keys($assign({}, B)).join('') != K;
  3743. }) ? function assign(target, source){ // eslint-disable-line no-unused-vars
  3744. var T = toObject(target)
  3745. , aLen = arguments.length
  3746. , index = 1
  3747. , getSymbols = gOPS.f
  3748. , isEnum = pIE.f;
  3749. while(aLen > index){
  3750. var S = IObject(arguments[index++])
  3751. , keys = getSymbols ? getKeys(S).concat(getSymbols(S)) : getKeys(S)
  3752. , length = keys.length
  3753. , j = 0
  3754. , key;
  3755. while(length > j)if(isEnum.call(S, key = keys[j++]))T[key] = S[key];
  3756. } return T;
  3757. } : $assign;
  3758. },{"./_fails":30,"./_iobject":35,"./_object-gops":40,"./_object-keys":42,"./_object-pie":43,"./_to-object":53}],39:[function(_dereq_,module,exports){
  3759. var anObject = _dereq_('./_an-object')
  3760. , IE8_DOM_DEFINE = _dereq_('./_ie8-dom-define')
  3761. , toPrimitive = _dereq_('./_to-primitive')
  3762. , dP = Object.defineProperty;
  3763. exports.f = _dereq_('./_descriptors') ? Object.defineProperty : function defineProperty(O, P, Attributes){
  3764. anObject(O);
  3765. P = toPrimitive(P, true);
  3766. anObject(Attributes);
  3767. if(IE8_DOM_DEFINE)try {
  3768. return dP(O, P, Attributes);
  3769. } catch(e){ /* empty */ }
  3770. if('get' in Attributes || 'set' in Attributes)throw TypeError('Accessors not supported!');
  3771. if('value' in Attributes)O[P] = Attributes.value;
  3772. return O;
  3773. };
  3774. },{"./_an-object":16,"./_descriptors":26,"./_ie8-dom-define":34,"./_to-primitive":54}],40:[function(_dereq_,module,exports){
  3775. exports.f = Object.getOwnPropertySymbols;
  3776. },{}],41:[function(_dereq_,module,exports){
  3777. var has = _dereq_('./_has')
  3778. , toIObject = _dereq_('./_to-iobject')
  3779. , arrayIndexOf = _dereq_('./_array-includes')(false)
  3780. , IE_PROTO = _dereq_('./_shared-key')('IE_PROTO');
  3781. module.exports = function(object, names){
  3782. var O = toIObject(object)
  3783. , i = 0
  3784. , result = []
  3785. , key;
  3786. for(key in O)if(key != IE_PROTO)has(O, key) && result.push(key);
  3787. // Don't enum bug & hidden keys
  3788. while(names.length > i)if(has(O, key = names[i++])){
  3789. ~arrayIndexOf(result, key) || result.push(key);
  3790. }
  3791. return result;
  3792. };
  3793. },{"./_array-includes":17,"./_has":32,"./_shared-key":46,"./_to-iobject":51}],42:[function(_dereq_,module,exports){
  3794. // 19.1.2.14 / 15.2.3.14 Object.keys(O)
  3795. var $keys = _dereq_('./_object-keys-internal')
  3796. , enumBugKeys = _dereq_('./_enum-bug-keys');
  3797. module.exports = Object.keys || function keys(O){
  3798. return $keys(O, enumBugKeys);
  3799. };
  3800. },{"./_enum-bug-keys":28,"./_object-keys-internal":41}],43:[function(_dereq_,module,exports){
  3801. exports.f = {}.propertyIsEnumerable;
  3802. },{}],44:[function(_dereq_,module,exports){
  3803. // most Object methods by ES6 should accept primitives
  3804. var $export = _dereq_('./_export')
  3805. , core = _dereq_('./_core')
  3806. , fails = _dereq_('./_fails');
  3807. module.exports = function(KEY, exec){
  3808. var fn = (core.Object || {})[KEY] || Object[KEY]
  3809. , exp = {};
  3810. exp[KEY] = exec(fn);
  3811. $export($export.S + $export.F * fails(function(){ fn(1); }), 'Object', exp);
  3812. };
  3813. },{"./_core":23,"./_export":29,"./_fails":30}],45:[function(_dereq_,module,exports){
  3814. module.exports = function(bitmap, value){
  3815. return {
  3816. enumerable : !(bitmap & 1),
  3817. configurable: !(bitmap & 2),
  3818. writable : !(bitmap & 4),
  3819. value : value
  3820. };
  3821. };
  3822. },{}],46:[function(_dereq_,module,exports){
  3823. var shared = _dereq_('./_shared')('keys')
  3824. , uid = _dereq_('./_uid');
  3825. module.exports = function(key){
  3826. return shared[key] || (shared[key] = uid(key));
  3827. };
  3828. },{"./_shared":47,"./_uid":55}],47:[function(_dereq_,module,exports){
  3829. var global = _dereq_('./_global')
  3830. , SHARED = '__core-js_shared__'
  3831. , store = global[SHARED] || (global[SHARED] = {});
  3832. module.exports = function(key){
  3833. return store[key] || (store[key] = {});
  3834. };
  3835. },{"./_global":31}],48:[function(_dereq_,module,exports){
  3836. var fails = _dereq_('./_fails');
  3837. module.exports = function(method, arg){
  3838. return !!method && fails(function(){
  3839. arg ? method.call(null, function(){}, 1) : method.call(null);
  3840. });
  3841. };
  3842. },{"./_fails":30}],49:[function(_dereq_,module,exports){
  3843. var toInteger = _dereq_('./_to-integer')
  3844. , max = Math.max
  3845. , min = Math.min;
  3846. module.exports = function(index, length){
  3847. index = toInteger(index);
  3848. return index < 0 ? max(index + length, 0) : min(index, length);
  3849. };
  3850. },{"./_to-integer":50}],50:[function(_dereq_,module,exports){
  3851. // 7.1.4 ToInteger
  3852. var ceil = Math.ceil
  3853. , floor = Math.floor;
  3854. module.exports = function(it){
  3855. return isNaN(it = +it) ? 0 : (it > 0 ? floor : ceil)(it);
  3856. };
  3857. },{}],51:[function(_dereq_,module,exports){
  3858. // to indexed object, toObject with fallback for non-array-like ES3 strings
  3859. var IObject = _dereq_('./_iobject')
  3860. , defined = _dereq_('./_defined');
  3861. module.exports = function(it){
  3862. return IObject(defined(it));
  3863. };
  3864. },{"./_defined":25,"./_iobject":35}],52:[function(_dereq_,module,exports){
  3865. // 7.1.15 ToLength
  3866. var toInteger = _dereq_('./_to-integer')
  3867. , min = Math.min;
  3868. module.exports = function(it){
  3869. return it > 0 ? min(toInteger(it), 0x1fffffffffffff) : 0; // pow(2, 53) - 1 == 9007199254740991
  3870. };
  3871. },{"./_to-integer":50}],53:[function(_dereq_,module,exports){
  3872. // 7.1.13 ToObject(argument)
  3873. var defined = _dereq_('./_defined');
  3874. module.exports = function(it){
  3875. return Object(defined(it));
  3876. };
  3877. },{"./_defined":25}],54:[function(_dereq_,module,exports){
  3878. // 7.1.1 ToPrimitive(input [, PreferredType])
  3879. var isObject = _dereq_('./_is-object');
  3880. // instead of the ES6 spec version, we didn't implement @@toPrimitive case
  3881. // and the second argument - flag - preferred type is a string
  3882. module.exports = function(it, S){
  3883. if(!isObject(it))return it;
  3884. var fn, val;
  3885. if(S && typeof (fn = it.toString) == 'function' && !isObject(val = fn.call(it)))return val;
  3886. if(typeof (fn = it.valueOf) == 'function' && !isObject(val = fn.call(it)))return val;
  3887. if(!S && typeof (fn = it.toString) == 'function' && !isObject(val = fn.call(it)))return val;
  3888. throw TypeError("Can't convert object to primitive value");
  3889. };
  3890. },{"./_is-object":37}],55:[function(_dereq_,module,exports){
  3891. var id = 0
  3892. , px = Math.random();
  3893. module.exports = function(key){
  3894. return 'Symbol('.concat(key === undefined ? '' : key, ')_', (++id + px).toString(36));
  3895. };
  3896. },{}],56:[function(_dereq_,module,exports){
  3897. var store = _dereq_('./_shared')('wks')
  3898. , uid = _dereq_('./_uid')
  3899. , Symbol = _dereq_('./_global').Symbol
  3900. , USE_SYMBOL = typeof Symbol == 'function';
  3901. var $exports = module.exports = function(name){
  3902. return store[name] || (store[name] =
  3903. USE_SYMBOL && Symbol[name] || (USE_SYMBOL ? Symbol : uid)('Symbol.' + name));
  3904. };
  3905. $exports.store = store;
  3906. },{"./_global":31,"./_shared":47,"./_uid":55}],57:[function(_dereq_,module,exports){
  3907. 'use strict';
  3908. var $export = _dereq_('./_export')
  3909. , $filter = _dereq_('./_array-methods')(2);
  3910. $export($export.P + $export.F * !_dereq_('./_strict-method')([].filter, true), 'Array', {
  3911. // 22.1.3.7 / 15.4.4.20 Array.prototype.filter(callbackfn [, thisArg])
  3912. filter: function filter(callbackfn /* , thisArg */){
  3913. return $filter(this, callbackfn, arguments[1]);
  3914. }
  3915. });
  3916. },{"./_array-methods":18,"./_export":29,"./_strict-method":48}],58:[function(_dereq_,module,exports){
  3917. 'use strict';
  3918. var $export = _dereq_('./_export')
  3919. , $forEach = _dereq_('./_array-methods')(0)
  3920. , STRICT = _dereq_('./_strict-method')([].forEach, true);
  3921. $export($export.P + $export.F * !STRICT, 'Array', {
  3922. // 22.1.3.10 / 15.4.4.18 Array.prototype.forEach(callbackfn [, thisArg])
  3923. forEach: function forEach(callbackfn /* , thisArg */){
  3924. return $forEach(this, callbackfn, arguments[1]);
  3925. }
  3926. });
  3927. },{"./_array-methods":18,"./_export":29,"./_strict-method":48}],59:[function(_dereq_,module,exports){
  3928. 'use strict';
  3929. var $export = _dereq_('./_export')
  3930. , $indexOf = _dereq_('./_array-includes')(false)
  3931. , $native = [].indexOf
  3932. , NEGATIVE_ZERO = !!$native && 1 / [1].indexOf(1, -0) < 0;
  3933. $export($export.P + $export.F * (NEGATIVE_ZERO || !_dereq_('./_strict-method')($native)), 'Array', {
  3934. // 22.1.3.11 / 15.4.4.14 Array.prototype.indexOf(searchElement [, fromIndex])
  3935. indexOf: function indexOf(searchElement /*, fromIndex = 0 */){
  3936. return NEGATIVE_ZERO
  3937. // convert -0 to +0
  3938. ? $native.apply(this, arguments) || 0
  3939. : $indexOf(this, searchElement, arguments[1]);
  3940. }
  3941. });
  3942. },{"./_array-includes":17,"./_export":29,"./_strict-method":48}],60:[function(_dereq_,module,exports){
  3943. // 22.1.2.2 / 15.4.3.2 Array.isArray(arg)
  3944. var $export = _dereq_('./_export');
  3945. $export($export.S, 'Array', {isArray: _dereq_('./_is-array')});
  3946. },{"./_export":29,"./_is-array":36}],61:[function(_dereq_,module,exports){
  3947. 'use strict';
  3948. var $export = _dereq_('./_export')
  3949. , $map = _dereq_('./_array-methods')(1);
  3950. $export($export.P + $export.F * !_dereq_('./_strict-method')([].map, true), 'Array', {
  3951. // 22.1.3.15 / 15.4.4.19 Array.prototype.map(callbackfn [, thisArg])
  3952. map: function map(callbackfn /* , thisArg */){
  3953. return $map(this, callbackfn, arguments[1]);
  3954. }
  3955. });
  3956. },{"./_array-methods":18,"./_export":29,"./_strict-method":48}],62:[function(_dereq_,module,exports){
  3957. 'use strict';
  3958. var $export = _dereq_('./_export')
  3959. , $reduce = _dereq_('./_array-reduce');
  3960. $export($export.P + $export.F * !_dereq_('./_strict-method')([].reduceRight, true), 'Array', {
  3961. // 22.1.3.19 / 15.4.4.22 Array.prototype.reduceRight(callbackfn [, initialValue])
  3962. reduceRight: function reduceRight(callbackfn /* , initialValue */){
  3963. return $reduce(this, callbackfn, arguments.length, arguments[1], true);
  3964. }
  3965. });
  3966. },{"./_array-reduce":19,"./_export":29,"./_strict-method":48}],63:[function(_dereq_,module,exports){
  3967. 'use strict';
  3968. var $export = _dereq_('./_export')
  3969. , $reduce = _dereq_('./_array-reduce');
  3970. $export($export.P + $export.F * !_dereq_('./_strict-method')([].reduce, true), 'Array', {
  3971. // 22.1.3.18 / 15.4.4.21 Array.prototype.reduce(callbackfn [, initialValue])
  3972. reduce: function reduce(callbackfn /* , initialValue */){
  3973. return $reduce(this, callbackfn, arguments.length, arguments[1], false);
  3974. }
  3975. });
  3976. },{"./_array-reduce":19,"./_export":29,"./_strict-method":48}],64:[function(_dereq_,module,exports){
  3977. // 19.1.3.1 Object.assign(target, source)
  3978. var $export = _dereq_('./_export');
  3979. $export($export.S + $export.F, 'Object', {assign: _dereq_('./_object-assign')});
  3980. },{"./_export":29,"./_object-assign":38}],65:[function(_dereq_,module,exports){
  3981. // 19.1.2.14 Object.keys(O)
  3982. var toObject = _dereq_('./_to-object')
  3983. , $keys = _dereq_('./_object-keys');
  3984. _dereq_('./_object-sap')('keys', function(){
  3985. return function keys(it){
  3986. return $keys(toObject(it));
  3987. };
  3988. });
  3989. },{"./_object-keys":42,"./_object-sap":44,"./_to-object":53}],66:[function(_dereq_,module,exports){
  3990. 'use strict'
  3991. /**
  3992. * Diff Match and Patch
  3993. *
  3994. * Copyright 2006 Google Inc.
  3995. * http://code.google.com/p/google-diff-match-patch/
  3996. *
  3997. * Licensed under the Apache License, Version 2.0 (the "License");
  3998. * you may not use this file except in compliance with the License.
  3999. * You may obtain a copy of the License at
  4000. *
  4001. * http://www.apache.org/licenses/LICENSE-2.0
  4002. *
  4003. * Unless required by applicable law or agreed to in writing, software
  4004. * distributed under the License is distributed on an "AS IS" BASIS,
  4005. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  4006. * See the License for the specific language governing permissions and
  4007. * limitations under the License.
  4008. */
  4009. /**
  4010. * @fileoverview Computes the difference between two texts to create a patch.
  4011. * Applies the patch onto another text, allowing for errors.
  4012. * @author fraser@google.com (Neil Fraser)
  4013. */
  4014. /**
  4015. * Class containing the diff, match and patch methods.
  4016. * @constructor
  4017. */
  4018. function diff_match_patch() {
  4019. // Defaults.
  4020. // Redefine these in your program to override the defaults.
  4021. // Number of seconds to map a diff before giving up (0 for infinity).
  4022. this.Diff_Timeout = 1.0;
  4023. // Cost of an empty edit operation in terms of edit characters.
  4024. this.Diff_EditCost = 4;
  4025. // At what point is no match declared (0.0 = perfection, 1.0 = very loose).
  4026. this.Match_Threshold = 0.5;
  4027. // How far to search for a match (0 = exact location, 1000+ = broad match).
  4028. // A match this many characters away from the expected location will add
  4029. // 1.0 to the score (0.0 is a perfect match).
  4030. this.Match_Distance = 1000;
  4031. // When deleting a large block of text (over ~64 characters), how close do
  4032. // the contents have to be to match the expected contents. (0.0 = perfection,
  4033. // 1.0 = very loose). Note that Match_Threshold controls how closely the
  4034. // end points of a delete need to match.
  4035. this.Patch_DeleteThreshold = 0.5;
  4036. // Chunk size for context length.
  4037. this.Patch_Margin = 4;
  4038. // The number of bits in an int.
  4039. this.Match_MaxBits = 32;
  4040. }
  4041. // DIFF FUNCTIONS
  4042. /**
  4043. * The data structure representing a diff is an array of tuples:
  4044. * [[DIFF_DELETE, 'Hello'], [DIFF_INSERT, 'Goodbye'], [DIFF_EQUAL, ' world.']]
  4045. * which means: delete 'Hello', add 'Goodbye' and keep ' world.'
  4046. */
  4047. var DIFF_DELETE = -1;
  4048. var DIFF_INSERT = 1;
  4049. var DIFF_EQUAL = 0;
  4050. /** @typedef {{0: number, 1: string}} */
  4051. diff_match_patch.Diff;
  4052. /**
  4053. * Find the differences between two texts. Simplifies the problem by stripping
  4054. * any common prefix or suffix off the texts before diffing.
  4055. * @param {string} text1 Old string to be diffed.
  4056. * @param {string} text2 New string to be diffed.
  4057. * @param {boolean=} opt_checklines Optional speedup flag. If present and false,
  4058. * then don't run a line-level diff first to identify the changed areas.
  4059. * Defaults to true, which does a faster, slightly less optimal diff.
  4060. * @param {number} opt_deadline Optional time when the diff should be complete
  4061. * by. Used internally for recursive calls. Users should set DiffTimeout
  4062. * instead.
  4063. * @return {!Array.<!diff_match_patch.Diff>} Array of diff tuples.
  4064. */
  4065. diff_match_patch.prototype.diff_main = function(text1, text2, opt_checklines,
  4066. opt_deadline) {
  4067. // Set a deadline by which time the diff must be complete.
  4068. if (typeof opt_deadline == 'undefined') {
  4069. if (this.Diff_Timeout <= 0) {
  4070. opt_deadline = Number.MAX_VALUE;
  4071. } else {
  4072. opt_deadline = (new Date).getTime() + this.Diff_Timeout * 1000;
  4073. }
  4074. }
  4075. var deadline = opt_deadline;
  4076. // Check for null inputs.
  4077. if (text1 == null || text2 == null) {
  4078. throw new Error('Null input. (diff_main)');
  4079. }
  4080. // Check for equality (speedup).
  4081. if (text1 == text2) {
  4082. if (text1) {
  4083. return [[DIFF_EQUAL, text1]];
  4084. }
  4085. return [];
  4086. }
  4087. if (typeof opt_checklines == 'undefined') {
  4088. opt_checklines = true;
  4089. }
  4090. var checklines = opt_checklines;
  4091. // Trim off common prefix (speedup).
  4092. var commonlength = this.diff_commonPrefix(text1, text2);
  4093. var commonprefix = text1.substring(0, commonlength);
  4094. text1 = text1.substring(commonlength);
  4095. text2 = text2.substring(commonlength);
  4096. // Trim off common suffix (speedup).
  4097. commonlength = this.diff_commonSuffix(text1, text2);
  4098. var commonsuffix = text1.substring(text1.length - commonlength);
  4099. text1 = text1.substring(0, text1.length - commonlength);
  4100. text2 = text2.substring(0, text2.length - commonlength);
  4101. // Compute the diff on the middle block.
  4102. var diffs = this.diff_compute_(text1, text2, checklines, deadline);
  4103. // Restore the prefix and suffix.
  4104. if (commonprefix) {
  4105. diffs.unshift([DIFF_EQUAL, commonprefix]);
  4106. }
  4107. if (commonsuffix) {
  4108. diffs.push([DIFF_EQUAL, commonsuffix]);
  4109. }
  4110. this.diff_cleanupMerge(diffs);
  4111. return diffs;
  4112. };
  4113. /**
  4114. * Find the differences between two texts. Assumes that the texts do not
  4115. * have any common prefix or suffix.
  4116. * @param {string} text1 Old string to be diffed.
  4117. * @param {string} text2 New string to be diffed.
  4118. * @param {boolean} checklines Speedup flag. If false, then don't run a
  4119. * line-level diff first to identify the changed areas.
  4120. * If true, then run a faster, slightly less optimal diff.
  4121. * @param {number} deadline Time when the diff should be complete by.
  4122. * @return {!Array.<!diff_match_patch.Diff>} Array of diff tuples.
  4123. * @private
  4124. */
  4125. diff_match_patch.prototype.diff_compute_ = function(text1, text2, checklines,
  4126. deadline) {
  4127. var diffs;
  4128. if (!text1) {
  4129. // Just add some text (speedup).
  4130. return [[DIFF_INSERT, text2]];
  4131. }
  4132. if (!text2) {
  4133. // Just delete some text (speedup).
  4134. return [[DIFF_DELETE, text1]];
  4135. }
  4136. var longtext = text1.length > text2.length ? text1 : text2;
  4137. var shorttext = text1.length > text2.length ? text2 : text1;
  4138. var i = longtext.indexOf(shorttext);
  4139. if (i != -1) {
  4140. // Shorter text is inside the longer text (speedup).
  4141. diffs = [[DIFF_INSERT, longtext.substring(0, i)],
  4142. [DIFF_EQUAL, shorttext],
  4143. [DIFF_INSERT, longtext.substring(i + shorttext.length)]];
  4144. // Swap insertions for deletions if diff is reversed.
  4145. if (text1.length > text2.length) {
  4146. diffs[0][0] = diffs[2][0] = DIFF_DELETE;
  4147. }
  4148. return diffs;
  4149. }
  4150. if (shorttext.length == 1) {
  4151. // Single character string.
  4152. // After the previous speedup, the character can't be an equality.
  4153. return [[DIFF_DELETE, text1], [DIFF_INSERT, text2]];
  4154. }
  4155. // Check to see if the problem can be split in two.
  4156. var hm = this.diff_halfMatch_(text1, text2);
  4157. if (hm) {
  4158. // A half-match was found, sort out the return data.
  4159. var text1_a = hm[0];
  4160. var text1_b = hm[1];
  4161. var text2_a = hm[2];
  4162. var text2_b = hm[3];
  4163. var mid_common = hm[4];
  4164. // Send both pairs off for separate processing.
  4165. var diffs_a = this.diff_main(text1_a, text2_a, checklines, deadline);
  4166. var diffs_b = this.diff_main(text1_b, text2_b, checklines, deadline);
  4167. // Merge the results.
  4168. return diffs_a.concat([[DIFF_EQUAL, mid_common]], diffs_b);
  4169. }
  4170. if (checklines && text1.length > 100 && text2.length > 100) {
  4171. return this.diff_lineMode_(text1, text2, deadline);
  4172. }
  4173. return this.diff_bisect_(text1, text2, deadline);
  4174. };
  4175. /**
  4176. * Do a quick line-level diff on both strings, then rediff the parts for
  4177. * greater accuracy.
  4178. * This speedup can produce non-minimal diffs.
  4179. * @param {string} text1 Old string to be diffed.
  4180. * @param {string} text2 New string to be diffed.
  4181. * @param {number} deadline Time when the diff should be complete by.
  4182. * @return {!Array.<!diff_match_patch.Diff>} Array of diff tuples.
  4183. * @private
  4184. */
  4185. diff_match_patch.prototype.diff_lineMode_ = function(text1, text2, deadline) {
  4186. // Scan the text on a line-by-line basis first.
  4187. var a = this.diff_linesToChars_(text1, text2);
  4188. text1 = a.chars1;
  4189. text2 = a.chars2;
  4190. var linearray = a.lineArray;
  4191. var diffs = this.diff_main(text1, text2, false, deadline);
  4192. // Convert the diff back to original text.
  4193. this.diff_charsToLines_(diffs, linearray);
  4194. // Eliminate freak matches (e.g. blank lines)
  4195. this.diff_cleanupSemantic(diffs);
  4196. // Rediff any replacement blocks, this time character-by-character.
  4197. // Add a dummy entry at the end.
  4198. diffs.push([DIFF_EQUAL, '']);
  4199. var pointer = 0;
  4200. var count_delete = 0;
  4201. var count_insert = 0;
  4202. var text_delete = '';
  4203. var text_insert = '';
  4204. while (pointer < diffs.length) {
  4205. switch (diffs[pointer][0]) {
  4206. case DIFF_INSERT:
  4207. count_insert++;
  4208. text_insert += diffs[pointer][1];
  4209. break;
  4210. case DIFF_DELETE:
  4211. count_delete++;
  4212. text_delete += diffs[pointer][1];
  4213. break;
  4214. case DIFF_EQUAL:
  4215. // Upon reaching an equality, check for prior redundancies.
  4216. if (count_delete >= 1 && count_insert >= 1) {
  4217. // Delete the offending records and add the merged ones.
  4218. diffs.splice(pointer - count_delete - count_insert,
  4219. count_delete + count_insert);
  4220. pointer = pointer - count_delete - count_insert;
  4221. var a = this.diff_main(text_delete, text_insert, false, deadline);
  4222. for (var j = a.length - 1; j >= 0; j--) {
  4223. diffs.splice(pointer, 0, a[j]);
  4224. }
  4225. pointer = pointer + a.length;
  4226. }
  4227. count_insert = 0;
  4228. count_delete = 0;
  4229. text_delete = '';
  4230. text_insert = '';
  4231. break;
  4232. }
  4233. pointer++;
  4234. }
  4235. diffs.pop(); // Remove the dummy entry at the end.
  4236. return diffs;
  4237. };
  4238. /**
  4239. * Find the 'middle snake' of a diff, split the problem in two
  4240. * and return the recursively constructed diff.
  4241. * See Myers 1986 paper: An O(ND) Difference Algorithm and Its Variations.
  4242. * @param {string} text1 Old string to be diffed.
  4243. * @param {string} text2 New string to be diffed.
  4244. * @param {number} deadline Time at which to bail if not yet complete.
  4245. * @return {!Array.<!diff_match_patch.Diff>} Array of diff tuples.
  4246. * @private
  4247. */
  4248. diff_match_patch.prototype.diff_bisect_ = function(text1, text2, deadline) {
  4249. // Cache the text lengths to prevent multiple calls.
  4250. var text1_length = text1.length;
  4251. var text2_length = text2.length;
  4252. var max_d = Math.ceil((text1_length + text2_length) / 2);
  4253. var v_offset = max_d;
  4254. var v_length = 2 * max_d;
  4255. var v1 = new Array(v_length);
  4256. var v2 = new Array(v_length);
  4257. // Setting all elements to -1 is faster in Chrome & Firefox than mixing
  4258. // integers and undefined.
  4259. for (var x = 0; x < v_length; x++) {
  4260. v1[x] = -1;
  4261. v2[x] = -1;
  4262. }
  4263. v1[v_offset + 1] = 0;
  4264. v2[v_offset + 1] = 0;
  4265. var delta = text1_length - text2_length;
  4266. // If the total number of characters is odd, then the front path will collide
  4267. // with the reverse path.
  4268. var front = (delta % 2 != 0);
  4269. // Offsets for start and end of k loop.
  4270. // Prevents mapping of space beyond the grid.
  4271. var k1start = 0;
  4272. var k1end = 0;
  4273. var k2start = 0;
  4274. var k2end = 0;
  4275. for (var d = 0; d < max_d; d++) {
  4276. // Bail out if deadline is reached.
  4277. if ((new Date()).getTime() > deadline) {
  4278. break;
  4279. }
  4280. // Walk the front path one step.
  4281. for (var k1 = -d + k1start; k1 <= d - k1end; k1 += 2) {
  4282. var k1_offset = v_offset + k1;
  4283. var x1;
  4284. if (k1 == -d || (k1 != d && v1[k1_offset - 1] < v1[k1_offset + 1])) {
  4285. x1 = v1[k1_offset + 1];
  4286. } else {
  4287. x1 = v1[k1_offset - 1] + 1;
  4288. }
  4289. var y1 = x1 - k1;
  4290. while (x1 < text1_length && y1 < text2_length &&
  4291. text1.charAt(x1) == text2.charAt(y1)) {
  4292. x1++;
  4293. y1++;
  4294. }
  4295. v1[k1_offset] = x1;
  4296. if (x1 > text1_length) {
  4297. // Ran off the right of the graph.
  4298. k1end += 2;
  4299. } else if (y1 > text2_length) {
  4300. // Ran off the bottom of the graph.
  4301. k1start += 2;
  4302. } else if (front) {
  4303. var k2_offset = v_offset + delta - k1;
  4304. if (k2_offset >= 0 && k2_offset < v_length && v2[k2_offset] != -1) {
  4305. // Mirror x2 onto top-left coordinate system.
  4306. var x2 = text1_length - v2[k2_offset];
  4307. if (x1 >= x2) {
  4308. // Overlap detected.
  4309. return this.diff_bisectSplit_(text1, text2, x1, y1, deadline);
  4310. }
  4311. }
  4312. }
  4313. }
  4314. // Walk the reverse path one step.
  4315. for (var k2 = -d + k2start; k2 <= d - k2end; k2 += 2) {
  4316. var k2_offset = v_offset + k2;
  4317. var x2;
  4318. if (k2 == -d || (k2 != d && v2[k2_offset - 1] < v2[k2_offset + 1])) {
  4319. x2 = v2[k2_offset + 1];
  4320. } else {
  4321. x2 = v2[k2_offset - 1] + 1;
  4322. }
  4323. var y2 = x2 - k2;
  4324. while (x2 < text1_length && y2 < text2_length &&
  4325. text1.charAt(text1_length - x2 - 1) ==
  4326. text2.charAt(text2_length - y2 - 1)) {
  4327. x2++;
  4328. y2++;
  4329. }
  4330. v2[k2_offset] = x2;
  4331. if (x2 > text1_length) {
  4332. // Ran off the left of the graph.
  4333. k2end += 2;
  4334. } else if (y2 > text2_length) {
  4335. // Ran off the top of the graph.
  4336. k2start += 2;
  4337. } else if (!front) {
  4338. var k1_offset = v_offset + delta - k2;
  4339. if (k1_offset >= 0 && k1_offset < v_length && v1[k1_offset] != -1) {
  4340. var x1 = v1[k1_offset];
  4341. var y1 = v_offset + x1 - k1_offset;
  4342. // Mirror x2 onto top-left coordinate system.
  4343. x2 = text1_length - x2;
  4344. if (x1 >= x2) {
  4345. // Overlap detected.
  4346. return this.diff_bisectSplit_(text1, text2, x1, y1, deadline);
  4347. }
  4348. }
  4349. }
  4350. }
  4351. }
  4352. // Diff took too long and hit the deadline or
  4353. // number of diffs equals number of characters, no commonality at all.
  4354. return [[DIFF_DELETE, text1], [DIFF_INSERT, text2]];
  4355. };
  4356. /**
  4357. * Given the location of the 'middle snake', split the diff in two parts
  4358. * and recurse.
  4359. * @param {string} text1 Old string to be diffed.
  4360. * @param {string} text2 New string to be diffed.
  4361. * @param {number} x Index of split point in text1.
  4362. * @param {number} y Index of split point in text2.
  4363. * @param {number} deadline Time at which to bail if not yet complete.
  4364. * @return {!Array.<!diff_match_patch.Diff>} Array of diff tuples.
  4365. * @private
  4366. */
  4367. diff_match_patch.prototype.diff_bisectSplit_ = function(text1, text2, x, y,
  4368. deadline) {
  4369. var text1a = text1.substring(0, x);
  4370. var text2a = text2.substring(0, y);
  4371. var text1b = text1.substring(x);
  4372. var text2b = text2.substring(y);
  4373. // Compute both diffs serially.
  4374. var diffs = this.diff_main(text1a, text2a, false, deadline);
  4375. var diffsb = this.diff_main(text1b, text2b, false, deadline);
  4376. return diffs.concat(diffsb);
  4377. };
  4378. /**
  4379. * Split two texts into an array of strings. Reduce the texts to a string of
  4380. * hashes where each Unicode character represents one line.
  4381. * @param {string} text1 First string.
  4382. * @param {string} text2 Second string.
  4383. * @return {{chars1: string, chars2: string, lineArray: !Array.<string>}}
  4384. * An object containing the encoded text1, the encoded text2 and
  4385. * the array of unique strings.
  4386. * The zeroth element of the array of unique strings is intentionally blank.
  4387. * @private
  4388. */
  4389. diff_match_patch.prototype.diff_linesToChars_ = function(text1, text2) {
  4390. var lineArray = []; // e.g. lineArray[4] == 'Hello\n'
  4391. var lineHash = {}; // e.g. lineHash['Hello\n'] == 4
  4392. // '\x00' is a valid character, but various debuggers don't like it.
  4393. // So we'll insert a junk entry to avoid generating a null character.
  4394. lineArray[0] = '';
  4395. /**
  4396. * Split a text into an array of strings. Reduce the texts to a string of
  4397. * hashes where each Unicode character represents one line.
  4398. * Modifies linearray and linehash through being a closure.
  4399. * @param {string} text String to encode.
  4400. * @return {string} Encoded string.
  4401. * @private
  4402. */
  4403. function diff_linesToCharsMunge_(text) {
  4404. var chars = '';
  4405. // Walk the text, pulling out a substring for each line.
  4406. // text.split('\n') would would temporarily double our memory footprint.
  4407. // Modifying text would create many large strings to garbage collect.
  4408. var lineStart = 0;
  4409. var lineEnd = -1;
  4410. // Keeping our own length variable is faster than looking it up.
  4411. var lineArrayLength = lineArray.length;
  4412. while (lineEnd < text.length - 1) {
  4413. lineEnd = text.indexOf('\n', lineStart);
  4414. if (lineEnd == -1) {
  4415. lineEnd = text.length - 1;
  4416. }
  4417. var line = text.substring(lineStart, lineEnd + 1);
  4418. lineStart = lineEnd + 1;
  4419. if (lineHash.hasOwnProperty ? lineHash.hasOwnProperty(line) :
  4420. (lineHash[line] !== undefined)) {
  4421. chars += String.fromCharCode(lineHash[line]);
  4422. } else {
  4423. chars += String.fromCharCode(lineArrayLength);
  4424. lineHash[line] = lineArrayLength;
  4425. lineArray[lineArrayLength++] = line;
  4426. }
  4427. }
  4428. return chars;
  4429. }
  4430. var chars1 = diff_linesToCharsMunge_(text1);
  4431. var chars2 = diff_linesToCharsMunge_(text2);
  4432. return {chars1: chars1, chars2: chars2, lineArray: lineArray};
  4433. };
  4434. /**
  4435. * Rehydrate the text in a diff from a string of line hashes to real lines of
  4436. * text.
  4437. * @param {!Array.<!diff_match_patch.Diff>} diffs Array of diff tuples.
  4438. * @param {!Array.<string>} lineArray Array of unique strings.
  4439. * @private
  4440. */
  4441. diff_match_patch.prototype.diff_charsToLines_ = function(diffs, lineArray) {
  4442. for (var x = 0; x < diffs.length; x++) {
  4443. var chars = diffs[x][1];
  4444. var text = [];
  4445. for (var y = 0; y < chars.length; y++) {
  4446. text[y] = lineArray[chars.charCodeAt(y)];
  4447. }
  4448. diffs[x][1] = text.join('');
  4449. }
  4450. };
  4451. /**
  4452. * Determine the common prefix of two strings.
  4453. * @param {string} text1 First string.
  4454. * @param {string} text2 Second string.
  4455. * @return {number} The number of characters common to the start of each
  4456. * string.
  4457. */
  4458. diff_match_patch.prototype.diff_commonPrefix = function(text1, text2) {
  4459. // Quick check for common null cases.
  4460. if (!text1 || !text2 || text1.charAt(0) != text2.charAt(0)) {
  4461. return 0;
  4462. }
  4463. // Binary search.
  4464. // Performance analysis: http://neil.fraser.name/news/2007/10/09/
  4465. var pointermin = 0;
  4466. var pointermax = Math.min(text1.length, text2.length);
  4467. var pointermid = pointermax;
  4468. var pointerstart = 0;
  4469. while (pointermin < pointermid) {
  4470. if (text1.substring(pointerstart, pointermid) ==
  4471. text2.substring(pointerstart, pointermid)) {
  4472. pointermin = pointermid;
  4473. pointerstart = pointermin;
  4474. } else {
  4475. pointermax = pointermid;
  4476. }
  4477. pointermid = Math.floor((pointermax - pointermin) / 2 + pointermin);
  4478. }
  4479. return pointermid;
  4480. };
  4481. /**
  4482. * Determine the common suffix of two strings.
  4483. * @param {string} text1 First string.
  4484. * @param {string} text2 Second string.
  4485. * @return {number} The number of characters common to the end of each string.
  4486. */
  4487. diff_match_patch.prototype.diff_commonSuffix = function(text1, text2) {
  4488. // Quick check for common null cases.
  4489. if (!text1 || !text2 ||
  4490. text1.charAt(text1.length - 1) != text2.charAt(text2.length - 1)) {
  4491. return 0;
  4492. }
  4493. // Binary search.
  4494. // Performance analysis: http://neil.fraser.name/news/2007/10/09/
  4495. var pointermin = 0;
  4496. var pointermax = Math.min(text1.length, text2.length);
  4497. var pointermid = pointermax;
  4498. var pointerend = 0;
  4499. while (pointermin < pointermid) {
  4500. if (text1.substring(text1.length - pointermid, text1.length - pointerend) ==
  4501. text2.substring(text2.length - pointermid, text2.length - pointerend)) {
  4502. pointermin = pointermid;
  4503. pointerend = pointermin;
  4504. } else {
  4505. pointermax = pointermid;
  4506. }
  4507. pointermid = Math.floor((pointermax - pointermin) / 2 + pointermin);
  4508. }
  4509. return pointermid;
  4510. };
  4511. /**
  4512. * Determine if the suffix of one string is the prefix of another.
  4513. * @param {string} text1 First string.
  4514. * @param {string} text2 Second string.
  4515. * @return {number} The number of characters common to the end of the first
  4516. * string and the start of the second string.
  4517. * @private
  4518. */
  4519. diff_match_patch.prototype.diff_commonOverlap_ = function(text1, text2) {
  4520. // Cache the text lengths to prevent multiple calls.
  4521. var text1_length = text1.length;
  4522. var text2_length = text2.length;
  4523. // Eliminate the null case.
  4524. if (text1_length == 0 || text2_length == 0) {
  4525. return 0;
  4526. }
  4527. // Truncate the longer string.
  4528. if (text1_length > text2_length) {
  4529. text1 = text1.substring(text1_length - text2_length);
  4530. } else if (text1_length < text2_length) {
  4531. text2 = text2.substring(0, text1_length);
  4532. }
  4533. var text_length = Math.min(text1_length, text2_length);
  4534. // Quick check for the worst case.
  4535. if (text1 == text2) {
  4536. return text_length;
  4537. }
  4538. // Start by looking for a single character match
  4539. // and increase length until no match is found.
  4540. // Performance analysis: http://neil.fraser.name/news/2010/11/04/
  4541. var best = 0;
  4542. var length = 1;
  4543. while (true) {
  4544. var pattern = text1.substring(text_length - length);
  4545. var found = text2.indexOf(pattern);
  4546. if (found == -1) {
  4547. return best;
  4548. }
  4549. length += found;
  4550. if (found == 0 || text1.substring(text_length - length) ==
  4551. text2.substring(0, length)) {
  4552. best = length;
  4553. length++;
  4554. }
  4555. }
  4556. };
  4557. /**
  4558. * Do the two texts share a substring which is at least half the length of the
  4559. * longer text?
  4560. * This speedup can produce non-minimal diffs.
  4561. * @param {string} text1 First string.
  4562. * @param {string} text2 Second string.
  4563. * @return {Array.<string>} Five element Array, containing the prefix of
  4564. * text1, the suffix of text1, the prefix of text2, the suffix of
  4565. * text2 and the common middle. Or null if there was no match.
  4566. * @private
  4567. */
  4568. diff_match_patch.prototype.diff_halfMatch_ = function(text1, text2) {
  4569. if (this.Diff_Timeout <= 0) {
  4570. // Don't risk returning a non-optimal diff if we have unlimited time.
  4571. return null;
  4572. }
  4573. var longtext = text1.length > text2.length ? text1 : text2;
  4574. var shorttext = text1.length > text2.length ? text2 : text1;
  4575. if (longtext.length < 4 || shorttext.length * 2 < longtext.length) {
  4576. return null; // Pointless.
  4577. }
  4578. var dmp = this; // 'this' becomes 'window' in a closure.
  4579. /**
  4580. * Does a substring of shorttext exist within longtext such that the substring
  4581. * is at least half the length of longtext?
  4582. * Closure, but does not reference any external variables.
  4583. * @param {string} longtext Longer string.
  4584. * @param {string} shorttext Shorter string.
  4585. * @param {number} i Start index of quarter length substring within longtext.
  4586. * @return {Array.<string>} Five element Array, containing the prefix of
  4587. * longtext, the suffix of longtext, the prefix of shorttext, the suffix
  4588. * of shorttext and the common middle. Or null if there was no match.
  4589. * @private
  4590. */
  4591. function diff_halfMatchI_(longtext, shorttext, i) {
  4592. // Start with a 1/4 length substring at position i as a seed.
  4593. var seed = longtext.substring(i, i + Math.floor(longtext.length / 4));
  4594. var j = -1;
  4595. var best_common = '';
  4596. var best_longtext_a, best_longtext_b, best_shorttext_a, best_shorttext_b;
  4597. while ((j = shorttext.indexOf(seed, j + 1)) != -1) {
  4598. var prefixLength = dmp.diff_commonPrefix(longtext.substring(i),
  4599. shorttext.substring(j));
  4600. var suffixLength = dmp.diff_commonSuffix(longtext.substring(0, i),
  4601. shorttext.substring(0, j));
  4602. if (best_common.length < suffixLength + prefixLength) {
  4603. best_common = shorttext.substring(j - suffixLength, j) +
  4604. shorttext.substring(j, j + prefixLength);
  4605. best_longtext_a = longtext.substring(0, i - suffixLength);
  4606. best_longtext_b = longtext.substring(i + prefixLength);
  4607. best_shorttext_a = shorttext.substring(0, j - suffixLength);
  4608. best_shorttext_b = shorttext.substring(j + prefixLength);
  4609. }
  4610. }
  4611. if (best_common.length * 2 >= longtext.length) {
  4612. return [best_longtext_a, best_longtext_b,
  4613. best_shorttext_a, best_shorttext_b, best_common];
  4614. } else {
  4615. return null;
  4616. }
  4617. }
  4618. // First check if the second quarter is the seed for a half-match.
  4619. var hm1 = diff_halfMatchI_(longtext, shorttext,
  4620. Math.ceil(longtext.length / 4));
  4621. // Check again based on the third quarter.
  4622. var hm2 = diff_halfMatchI_(longtext, shorttext,
  4623. Math.ceil(longtext.length / 2));
  4624. var hm;
  4625. if (!hm1 && !hm2) {
  4626. return null;
  4627. } else if (!hm2) {
  4628. hm = hm1;
  4629. } else if (!hm1) {
  4630. hm = hm2;
  4631. } else {
  4632. // Both matched. Select the longest.
  4633. hm = hm1[4].length > hm2[4].length ? hm1 : hm2;
  4634. }
  4635. // A half-match was found, sort out the return data.
  4636. var text1_a, text1_b, text2_a, text2_b;
  4637. if (text1.length > text2.length) {
  4638. text1_a = hm[0];
  4639. text1_b = hm[1];
  4640. text2_a = hm[2];
  4641. text2_b = hm[3];
  4642. } else {
  4643. text2_a = hm[0];
  4644. text2_b = hm[1];
  4645. text1_a = hm[2];
  4646. text1_b = hm[3];
  4647. }
  4648. var mid_common = hm[4];
  4649. return [text1_a, text1_b, text2_a, text2_b, mid_common];
  4650. };
  4651. /**
  4652. * Reduce the number of edits by eliminating semantically trivial equalities.
  4653. * @param {!Array.<!diff_match_patch.Diff>} diffs Array of diff tuples.
  4654. */
  4655. diff_match_patch.prototype.diff_cleanupSemantic = function(diffs) {
  4656. var changes = false;
  4657. var equalities = []; // Stack of indices where equalities are found.
  4658. var equalitiesLength = 0; // Keeping our own length var is faster in JS.
  4659. /** @type {?string} */
  4660. var lastequality = null;
  4661. // Always equal to diffs[equalities[equalitiesLength - 1]][1]
  4662. var pointer = 0; // Index of current position.
  4663. // Number of characters that changed prior to the equality.
  4664. var length_insertions1 = 0;
  4665. var length_deletions1 = 0;
  4666. // Number of characters that changed after the equality.
  4667. var length_insertions2 = 0;
  4668. var length_deletions2 = 0;
  4669. while (pointer < diffs.length) {
  4670. if (diffs[pointer][0] == DIFF_EQUAL) { // Equality found.
  4671. equalities[equalitiesLength++] = pointer;
  4672. length_insertions1 = length_insertions2;
  4673. length_deletions1 = length_deletions2;
  4674. length_insertions2 = 0;
  4675. length_deletions2 = 0;
  4676. lastequality = diffs[pointer][1];
  4677. } else { // An insertion or deletion.
  4678. if (diffs[pointer][0] == DIFF_INSERT) {
  4679. length_insertions2 += diffs[pointer][1].length;
  4680. } else {
  4681. length_deletions2 += diffs[pointer][1].length;
  4682. }
  4683. // Eliminate an equality that is smaller or equal to the edits on both
  4684. // sides of it.
  4685. if (lastequality && (lastequality.length <=
  4686. Math.max(length_insertions1, length_deletions1)) &&
  4687. (lastequality.length <= Math.max(length_insertions2,
  4688. length_deletions2))) {
  4689. // Duplicate record.
  4690. diffs.splice(equalities[equalitiesLength - 1], 0,
  4691. [DIFF_DELETE, lastequality]);
  4692. // Change second copy to insert.
  4693. diffs[equalities[equalitiesLength - 1] + 1][0] = DIFF_INSERT;
  4694. // Throw away the equality we just deleted.
  4695. equalitiesLength--;
  4696. // Throw away the previous equality (it needs to be reevaluated).
  4697. equalitiesLength--;
  4698. pointer = equalitiesLength > 0 ? equalities[equalitiesLength - 1] : -1;
  4699. length_insertions1 = 0; // Reset the counters.
  4700. length_deletions1 = 0;
  4701. length_insertions2 = 0;
  4702. length_deletions2 = 0;
  4703. lastequality = null;
  4704. changes = true;
  4705. }
  4706. }
  4707. pointer++;
  4708. }
  4709. // Normalize the diff.
  4710. if (changes) {
  4711. this.diff_cleanupMerge(diffs);
  4712. }
  4713. this.diff_cleanupSemanticLossless(diffs);
  4714. // Find any overlaps between deletions and insertions.
  4715. // e.g: <del>abcxxx</del><ins>xxxdef</ins>
  4716. // -> <del>abc</del>xxx<ins>def</ins>
  4717. // e.g: <del>xxxabc</del><ins>defxxx</ins>
  4718. // -> <ins>def</ins>xxx<del>abc</del>
  4719. // Only extract an overlap if it is as big as the edit ahead or behind it.
  4720. pointer = 1;
  4721. while (pointer < diffs.length) {
  4722. if (diffs[pointer - 1][0] == DIFF_DELETE &&
  4723. diffs[pointer][0] == DIFF_INSERT) {
  4724. var deletion = diffs[pointer - 1][1];
  4725. var insertion = diffs[pointer][1];
  4726. var overlap_length1 = this.diff_commonOverlap_(deletion, insertion);
  4727. var overlap_length2 = this.diff_commonOverlap_(insertion, deletion);
  4728. if (overlap_length1 >= overlap_length2) {
  4729. if (overlap_length1 >= deletion.length / 2 ||
  4730. overlap_length1 >= insertion.length / 2) {
  4731. // Overlap found. Insert an equality and trim the surrounding edits.
  4732. diffs.splice(pointer, 0,
  4733. [DIFF_EQUAL, insertion.substring(0, overlap_length1)]);
  4734. diffs[pointer - 1][1] =
  4735. deletion.substring(0, deletion.length - overlap_length1);
  4736. diffs[pointer + 1][1] = insertion.substring(overlap_length1);
  4737. pointer++;
  4738. }
  4739. } else {
  4740. if (overlap_length2 >= deletion.length / 2 ||
  4741. overlap_length2 >= insertion.length / 2) {
  4742. // Reverse overlap found.
  4743. // Insert an equality and swap and trim the surrounding edits.
  4744. diffs.splice(pointer, 0,
  4745. [DIFF_EQUAL, deletion.substring(0, overlap_length2)]);
  4746. diffs[pointer - 1][0] = DIFF_INSERT;
  4747. diffs[pointer - 1][1] =
  4748. insertion.substring(0, insertion.length - overlap_length2);
  4749. diffs[pointer + 1][0] = DIFF_DELETE;
  4750. diffs[pointer + 1][1] =
  4751. deletion.substring(overlap_length2);
  4752. pointer++;
  4753. }
  4754. }
  4755. pointer++;
  4756. }
  4757. pointer++;
  4758. }
  4759. };
  4760. /**
  4761. * Look for single edits surrounded on both sides by equalities
  4762. * which can be shifted sideways to align the edit to a word boundary.
  4763. * e.g: The c<ins>at c</ins>ame. -> The <ins>cat </ins>came.
  4764. * @param {!Array.<!diff_match_patch.Diff>} diffs Array of diff tuples.
  4765. */
  4766. diff_match_patch.prototype.diff_cleanupSemanticLossless = function(diffs) {
  4767. /**
  4768. * Given two strings, compute a score representing whether the internal
  4769. * boundary falls on logical boundaries.
  4770. * Scores range from 6 (best) to 0 (worst).
  4771. * Closure, but does not reference any external variables.
  4772. * @param {string} one First string.
  4773. * @param {string} two Second string.
  4774. * @return {number} The score.
  4775. * @private
  4776. */
  4777. function diff_cleanupSemanticScore_(one, two) {
  4778. if (!one || !two) {
  4779. // Edges are the best.
  4780. return 6;
  4781. }
  4782. // Each port of this function behaves slightly differently due to
  4783. // subtle differences in each language's definition of things like
  4784. // 'whitespace'. Since this function's purpose is largely cosmetic,
  4785. // the choice has been made to use each language's native features
  4786. // rather than force total conformity.
  4787. var char1 = one.charAt(one.length - 1);
  4788. var char2 = two.charAt(0);
  4789. var nonAlphaNumeric1 = char1.match(diff_match_patch.nonAlphaNumericRegex_);
  4790. var nonAlphaNumeric2 = char2.match(diff_match_patch.nonAlphaNumericRegex_);
  4791. var whitespace1 = nonAlphaNumeric1 &&
  4792. char1.match(diff_match_patch.whitespaceRegex_);
  4793. var whitespace2 = nonAlphaNumeric2 &&
  4794. char2.match(diff_match_patch.whitespaceRegex_);
  4795. var lineBreak1 = whitespace1 &&
  4796. char1.match(diff_match_patch.linebreakRegex_);
  4797. var lineBreak2 = whitespace2 &&
  4798. char2.match(diff_match_patch.linebreakRegex_);
  4799. var blankLine1 = lineBreak1 &&
  4800. one.match(diff_match_patch.blanklineEndRegex_);
  4801. var blankLine2 = lineBreak2 &&
  4802. two.match(diff_match_patch.blanklineStartRegex_);
  4803. if (blankLine1 || blankLine2) {
  4804. // Five points for blank lines.
  4805. return 5;
  4806. } else if (lineBreak1 || lineBreak2) {
  4807. // Four points for line breaks.
  4808. return 4;
  4809. } else if (nonAlphaNumeric1 && !whitespace1 && whitespace2) {
  4810. // Three points for end of sentences.
  4811. return 3;
  4812. } else if (whitespace1 || whitespace2) {
  4813. // Two points for whitespace.
  4814. return 2;
  4815. } else if (nonAlphaNumeric1 || nonAlphaNumeric2) {
  4816. // One point for non-alphanumeric.
  4817. return 1;
  4818. }
  4819. return 0;
  4820. }
  4821. var pointer = 1;
  4822. // Intentionally ignore the first and last element (don't need checking).
  4823. while (pointer < diffs.length - 1) {
  4824. if (diffs[pointer - 1][0] == DIFF_EQUAL &&
  4825. diffs[pointer + 1][0] == DIFF_EQUAL) {
  4826. // This is a single edit surrounded by equalities.
  4827. var equality1 = diffs[pointer - 1][1];
  4828. var edit = diffs[pointer][1];
  4829. var equality2 = diffs[pointer + 1][1];
  4830. // First, shift the edit as far left as possible.
  4831. var commonOffset = this.diff_commonSuffix(equality1, edit);
  4832. if (commonOffset) {
  4833. var commonString = edit.substring(edit.length - commonOffset);
  4834. equality1 = equality1.substring(0, equality1.length - commonOffset);
  4835. edit = commonString + edit.substring(0, edit.length - commonOffset);
  4836. equality2 = commonString + equality2;
  4837. }
  4838. // Second, step character by character right, looking for the best fit.
  4839. var bestEquality1 = equality1;
  4840. var bestEdit = edit;
  4841. var bestEquality2 = equality2;
  4842. var bestScore = diff_cleanupSemanticScore_(equality1, edit) +
  4843. diff_cleanupSemanticScore_(edit, equality2);
  4844. while (edit.charAt(0) === equality2.charAt(0)) {
  4845. equality1 += edit.charAt(0);
  4846. edit = edit.substring(1) + equality2.charAt(0);
  4847. equality2 = equality2.substring(1);
  4848. var score = diff_cleanupSemanticScore_(equality1, edit) +
  4849. diff_cleanupSemanticScore_(edit, equality2);
  4850. // The >= encourages trailing rather than leading whitespace on edits.
  4851. if (score >= bestScore) {
  4852. bestScore = score;
  4853. bestEquality1 = equality1;
  4854. bestEdit = edit;
  4855. bestEquality2 = equality2;
  4856. }
  4857. }
  4858. if (diffs[pointer - 1][1] != bestEquality1) {
  4859. // We have an improvement, save it back to the diff.
  4860. if (bestEquality1) {
  4861. diffs[pointer - 1][1] = bestEquality1;
  4862. } else {
  4863. diffs.splice(pointer - 1, 1);
  4864. pointer--;
  4865. }
  4866. diffs[pointer][1] = bestEdit;
  4867. if (bestEquality2) {
  4868. diffs[pointer + 1][1] = bestEquality2;
  4869. } else {
  4870. diffs.splice(pointer + 1, 1);
  4871. pointer--;
  4872. }
  4873. }
  4874. }
  4875. pointer++;
  4876. }
  4877. };
  4878. // Define some regex patterns for matching boundaries.
  4879. diff_match_patch.nonAlphaNumericRegex_ = /[^a-zA-Z0-9]/;
  4880. diff_match_patch.whitespaceRegex_ = /\s/;
  4881. diff_match_patch.linebreakRegex_ = /[\r\n]/;
  4882. diff_match_patch.blanklineEndRegex_ = /\n\r?\n$/;
  4883. diff_match_patch.blanklineStartRegex_ = /^\r?\n\r?\n/;
  4884. /**
  4885. * Reduce the number of edits by eliminating operationally trivial equalities.
  4886. * @param {!Array.<!diff_match_patch.Diff>} diffs Array of diff tuples.
  4887. */
  4888. diff_match_patch.prototype.diff_cleanupEfficiency = function(diffs) {
  4889. var changes = false;
  4890. var equalities = []; // Stack of indices where equalities are found.
  4891. var equalitiesLength = 0; // Keeping our own length var is faster in JS.
  4892. /** @type {?string} */
  4893. var lastequality = null;
  4894. // Always equal to diffs[equalities[equalitiesLength - 1]][1]
  4895. var pointer = 0; // Index of current position.
  4896. // Is there an insertion operation before the last equality.
  4897. var pre_ins = false;
  4898. // Is there a deletion operation before the last equality.
  4899. var pre_del = false;
  4900. // Is there an insertion operation after the last equality.
  4901. var post_ins = false;
  4902. // Is there a deletion operation after the last equality.
  4903. var post_del = false;
  4904. while (pointer < diffs.length) {
  4905. if (diffs[pointer][0] == DIFF_EQUAL) { // Equality found.
  4906. if (diffs[pointer][1].length < this.Diff_EditCost &&
  4907. (post_ins || post_del)) {
  4908. // Candidate found.
  4909. equalities[equalitiesLength++] = pointer;
  4910. pre_ins = post_ins;
  4911. pre_del = post_del;
  4912. lastequality = diffs[pointer][1];
  4913. } else {
  4914. // Not a candidate, and can never become one.
  4915. equalitiesLength = 0;
  4916. lastequality = null;
  4917. }
  4918. post_ins = post_del = false;
  4919. } else { // An insertion or deletion.
  4920. if (diffs[pointer][0] == DIFF_DELETE) {
  4921. post_del = true;
  4922. } else {
  4923. post_ins = true;
  4924. }
  4925. /*
  4926. * Five types to be split:
  4927. * <ins>A</ins><del>B</del>XY<ins>C</ins><del>D</del>
  4928. * <ins>A</ins>X<ins>C</ins><del>D</del>
  4929. * <ins>A</ins><del>B</del>X<ins>C</ins>
  4930. * <ins>A</del>X<ins>C</ins><del>D</del>
  4931. * <ins>A</ins><del>B</del>X<del>C</del>
  4932. */
  4933. if (lastequality && ((pre_ins && pre_del && post_ins && post_del) ||
  4934. ((lastequality.length < this.Diff_EditCost / 2) &&
  4935. (pre_ins + pre_del + post_ins + post_del) == 3))) {
  4936. // Duplicate record.
  4937. diffs.splice(equalities[equalitiesLength - 1], 0,
  4938. [DIFF_DELETE, lastequality]);
  4939. // Change second copy to insert.
  4940. diffs[equalities[equalitiesLength - 1] + 1][0] = DIFF_INSERT;
  4941. equalitiesLength--; // Throw away the equality we just deleted;
  4942. lastequality = null;
  4943. if (pre_ins && pre_del) {
  4944. // No changes made which could affect previous entry, keep going.
  4945. post_ins = post_del = true;
  4946. equalitiesLength = 0;
  4947. } else {
  4948. equalitiesLength--; // Throw away the previous equality.
  4949. pointer = equalitiesLength > 0 ?
  4950. equalities[equalitiesLength - 1] : -1;
  4951. post_ins = post_del = false;
  4952. }
  4953. changes = true;
  4954. }
  4955. }
  4956. pointer++;
  4957. }
  4958. if (changes) {
  4959. this.diff_cleanupMerge(diffs);
  4960. }
  4961. };
  4962. /**
  4963. * Reorder and merge like edit sections. Merge equalities.
  4964. * Any edit section can move as long as it doesn't cross an equality.
  4965. * @param {!Array.<!diff_match_patch.Diff>} diffs Array of diff tuples.
  4966. */
  4967. diff_match_patch.prototype.diff_cleanupMerge = function(diffs) {
  4968. diffs.push([DIFF_EQUAL, '']); // Add a dummy entry at the end.
  4969. var pointer = 0;
  4970. var count_delete = 0;
  4971. var count_insert = 0;
  4972. var text_delete = '';
  4973. var text_insert = '';
  4974. var commonlength;
  4975. while (pointer < diffs.length) {
  4976. switch (diffs[pointer][0]) {
  4977. case DIFF_INSERT:
  4978. count_insert++;
  4979. text_insert += diffs[pointer][1];
  4980. pointer++;
  4981. break;
  4982. case DIFF_DELETE:
  4983. count_delete++;
  4984. text_delete += diffs[pointer][1];
  4985. pointer++;
  4986. break;
  4987. case DIFF_EQUAL:
  4988. // Upon reaching an equality, check for prior redundancies.
  4989. if (count_delete + count_insert > 1) {
  4990. if (count_delete !== 0 && count_insert !== 0) {
  4991. // Factor out any common prefixies.
  4992. commonlength = this.diff_commonPrefix(text_insert, text_delete);
  4993. if (commonlength !== 0) {
  4994. if ((pointer - count_delete - count_insert) > 0 &&
  4995. diffs[pointer - count_delete - count_insert - 1][0] ==
  4996. DIFF_EQUAL) {
  4997. diffs[pointer - count_delete - count_insert - 1][1] +=
  4998. text_insert.substring(0, commonlength);
  4999. } else {
  5000. diffs.splice(0, 0, [DIFF_EQUAL,
  5001. text_insert.substring(0, commonlength)]);
  5002. pointer++;
  5003. }
  5004. text_insert = text_insert.substring(commonlength);
  5005. text_delete = text_delete.substring(commonlength);
  5006. }
  5007. // Factor out any common suffixies.
  5008. commonlength = this.diff_commonSuffix(text_insert, text_delete);
  5009. if (commonlength !== 0) {
  5010. diffs[pointer][1] = text_insert.substring(text_insert.length -
  5011. commonlength) + diffs[pointer][1];
  5012. text_insert = text_insert.substring(0, text_insert.length -
  5013. commonlength);
  5014. text_delete = text_delete.substring(0, text_delete.length -
  5015. commonlength);
  5016. }
  5017. }
  5018. // Delete the offending records and add the merged ones.
  5019. if (count_delete === 0) {
  5020. diffs.splice(pointer - count_insert,
  5021. count_delete + count_insert, [DIFF_INSERT, text_insert]);
  5022. } else if (count_insert === 0) {
  5023. diffs.splice(pointer - count_delete,
  5024. count_delete + count_insert, [DIFF_DELETE, text_delete]);
  5025. } else {
  5026. diffs.splice(pointer - count_delete - count_insert,
  5027. count_delete + count_insert, [DIFF_DELETE, text_delete],
  5028. [DIFF_INSERT, text_insert]);
  5029. }
  5030. pointer = pointer - count_delete - count_insert +
  5031. (count_delete ? 1 : 0) + (count_insert ? 1 : 0) + 1;
  5032. } else if (pointer !== 0 && diffs[pointer - 1][0] == DIFF_EQUAL) {
  5033. // Merge this equality with the previous one.
  5034. diffs[pointer - 1][1] += diffs[pointer][1];
  5035. diffs.splice(pointer, 1);
  5036. } else {
  5037. pointer++;
  5038. }
  5039. count_insert = 0;
  5040. count_delete = 0;
  5041. text_delete = '';
  5042. text_insert = '';
  5043. break;
  5044. }
  5045. }
  5046. if (diffs[diffs.length - 1][1] === '') {
  5047. diffs.pop(); // Remove the dummy entry at the end.
  5048. }
  5049. // Second pass: look for single edits surrounded on both sides by equalities
  5050. // which can be shifted sideways to eliminate an equality.
  5051. // e.g: A<ins>BA</ins>C -> <ins>AB</ins>AC
  5052. var changes = false;
  5053. pointer = 1;
  5054. // Intentionally ignore the first and last element (don't need checking).
  5055. while (pointer < diffs.length - 1) {
  5056. if (diffs[pointer - 1][0] == DIFF_EQUAL &&
  5057. diffs[pointer + 1][0] == DIFF_EQUAL) {
  5058. // This is a single edit surrounded by equalities.
  5059. if (diffs[pointer][1].substring(diffs[pointer][1].length -
  5060. diffs[pointer - 1][1].length) == diffs[pointer - 1][1]) {
  5061. // Shift the edit over the previous equality.
  5062. diffs[pointer][1] = diffs[pointer - 1][1] +
  5063. diffs[pointer][1].substring(0, diffs[pointer][1].length -
  5064. diffs[pointer - 1][1].length);
  5065. diffs[pointer + 1][1] = diffs[pointer - 1][1] + diffs[pointer + 1][1];
  5066. diffs.splice(pointer - 1, 1);
  5067. changes = true;
  5068. } else if (diffs[pointer][1].substring(0, diffs[pointer + 1][1].length) ==
  5069. diffs[pointer + 1][1]) {
  5070. // Shift the edit over the next equality.
  5071. diffs[pointer - 1][1] += diffs[pointer + 1][1];
  5072. diffs[pointer][1] =
  5073. diffs[pointer][1].substring(diffs[pointer + 1][1].length) +
  5074. diffs[pointer + 1][1];
  5075. diffs.splice(pointer + 1, 1);
  5076. changes = true;
  5077. }
  5078. }
  5079. pointer++;
  5080. }
  5081. // If shifts were made, the diff needs reordering and another shift sweep.
  5082. if (changes) {
  5083. this.diff_cleanupMerge(diffs);
  5084. }
  5085. };
  5086. /**
  5087. * loc is a location in text1, compute and return the equivalent location in
  5088. * text2.
  5089. * e.g. 'The cat' vs 'The big cat', 1->1, 5->8
  5090. * @param {!Array.<!diff_match_patch.Diff>} diffs Array of diff tuples.
  5091. * @param {number} loc Location within text1.
  5092. * @return {number} Location within text2.
  5093. */
  5094. diff_match_patch.prototype.diff_xIndex = function(diffs, loc) {
  5095. var chars1 = 0;
  5096. var chars2 = 0;
  5097. var last_chars1 = 0;
  5098. var last_chars2 = 0;
  5099. var x;
  5100. for (x = 0; x < diffs.length; x++) {
  5101. if (diffs[x][0] !== DIFF_INSERT) { // Equality or deletion.
  5102. chars1 += diffs[x][1].length;
  5103. }
  5104. if (diffs[x][0] !== DIFF_DELETE) { // Equality or insertion.
  5105. chars2 += diffs[x][1].length;
  5106. }
  5107. if (chars1 > loc) { // Overshot the location.
  5108. break;
  5109. }
  5110. last_chars1 = chars1;
  5111. last_chars2 = chars2;
  5112. }
  5113. // Was the location was deleted?
  5114. if (diffs.length != x && diffs[x][0] === DIFF_DELETE) {
  5115. return last_chars2;
  5116. }
  5117. // Add the remaining character length.
  5118. return last_chars2 + (loc - last_chars1);
  5119. };
  5120. /**
  5121. * Convert a diff array into a pretty HTML report.
  5122. * @param {!Array.<!diff_match_patch.Diff>} diffs Array of diff tuples.
  5123. * @return {string} HTML representation.
  5124. */
  5125. diff_match_patch.prototype.diff_prettyHtml = function(diffs) {
  5126. var html = [];
  5127. var pattern_amp = /&/g;
  5128. var pattern_lt = /</g;
  5129. var pattern_gt = />/g;
  5130. var pattern_para = /\n/g;
  5131. for (var x = 0; x < diffs.length; x++) {
  5132. var op = diffs[x][0]; // Operation (insert, delete, equal)
  5133. var data = diffs[x][1]; // Text of change.
  5134. var text = data.replace(pattern_amp, '&amp;').replace(pattern_lt, '&lt;')
  5135. .replace(pattern_gt, '&gt;').replace(pattern_para, '&para;<br>');
  5136. switch (op) {
  5137. case DIFF_INSERT:
  5138. html[x] = '<ins style="background:#e6ffe6;">' + text + '</ins>';
  5139. break;
  5140. case DIFF_DELETE:
  5141. html[x] = '<del style="background:#ffe6e6;">' + text + '</del>';
  5142. break;
  5143. case DIFF_EQUAL:
  5144. html[x] = '<span>' + text + '</span>';
  5145. break;
  5146. }
  5147. }
  5148. return html.join('');
  5149. };
  5150. /**
  5151. * Compute and return the source text (all equalities and deletions).
  5152. * @param {!Array.<!diff_match_patch.Diff>} diffs Array of diff tuples.
  5153. * @return {string} Source text.
  5154. */
  5155. diff_match_patch.prototype.diff_text1 = function(diffs) {
  5156. var text = [];
  5157. for (var x = 0; x < diffs.length; x++) {
  5158. if (diffs[x][0] !== DIFF_INSERT) {
  5159. text[x] = diffs[x][1];
  5160. }
  5161. }
  5162. return text.join('');
  5163. };
  5164. /**
  5165. * Compute and return the destination text (all equalities and insertions).
  5166. * @param {!Array.<!diff_match_patch.Diff>} diffs Array of diff tuples.
  5167. * @return {string} Destination text.
  5168. */
  5169. diff_match_patch.prototype.diff_text2 = function(diffs) {
  5170. var text = [];
  5171. for (var x = 0; x < diffs.length; x++) {
  5172. if (diffs[x][0] !== DIFF_DELETE) {
  5173. text[x] = diffs[x][1];
  5174. }
  5175. }
  5176. return text.join('');
  5177. };
  5178. /**
  5179. * Compute the Levenshtein distance; the number of inserted, deleted or
  5180. * substituted characters.
  5181. * @param {!Array.<!diff_match_patch.Diff>} diffs Array of diff tuples.
  5182. * @return {number} Number of changes.
  5183. */
  5184. diff_match_patch.prototype.diff_levenshtein = function(diffs) {
  5185. var levenshtein = 0;
  5186. var insertions = 0;
  5187. var deletions = 0;
  5188. for (var x = 0; x < diffs.length; x++) {
  5189. var op = diffs[x][0];
  5190. var data = diffs[x][1];
  5191. switch (op) {
  5192. case DIFF_INSERT:
  5193. insertions += data.length;
  5194. break;
  5195. case DIFF_DELETE:
  5196. deletions += data.length;
  5197. break;
  5198. case DIFF_EQUAL:
  5199. // A deletion and an insertion is one substitution.
  5200. levenshtein += Math.max(insertions, deletions);
  5201. insertions = 0;
  5202. deletions = 0;
  5203. break;
  5204. }
  5205. }
  5206. levenshtein += Math.max(insertions, deletions);
  5207. return levenshtein;
  5208. };
  5209. /**
  5210. * Crush the diff into an encoded string which describes the operations
  5211. * required to transform text1 into text2.
  5212. * E.g. =3\t-2\t+ing -> Keep 3 chars, delete 2 chars, insert 'ing'.
  5213. * Operations are tab-separated. Inserted text is escaped using %xx notation.
  5214. * @param {!Array.<!diff_match_patch.Diff>} diffs Array of diff tuples.
  5215. * @return {string} Delta text.
  5216. */
  5217. diff_match_patch.prototype.diff_toDelta = function(diffs) {
  5218. var text = [];
  5219. for (var x = 0; x < diffs.length; x++) {
  5220. switch (diffs[x][0]) {
  5221. case DIFF_INSERT:
  5222. text[x] = '+' + encodeURI(diffs[x][1]);
  5223. break;
  5224. case DIFF_DELETE:
  5225. text[x] = '-' + diffs[x][1].length;
  5226. break;
  5227. case DIFF_EQUAL:
  5228. text[x] = '=' + diffs[x][1].length;
  5229. break;
  5230. }
  5231. }
  5232. return text.join('\t').replace(/%20/g, ' ');
  5233. };
  5234. /**
  5235. * Given the original text1, and an encoded string which describes the
  5236. * operations required to transform text1 into text2, compute the full diff.
  5237. * @param {string} text1 Source string for the diff.
  5238. * @param {string} delta Delta text.
  5239. * @return {!Array.<!diff_match_patch.Diff>} Array of diff tuples.
  5240. * @throws {!Error} If invalid input.
  5241. */
  5242. diff_match_patch.prototype.diff_fromDelta = function(text1, delta) {
  5243. var diffs = [];
  5244. var diffsLength = 0; // Keeping our own length var is faster in JS.
  5245. var pointer = 0; // Cursor in text1
  5246. var tokens = delta.split(/\t/g);
  5247. for (var x = 0; x < tokens.length; x++) {
  5248. // Each token begins with a one character parameter which specifies the
  5249. // operation of this token (delete, insert, equality).
  5250. var param = tokens[x].substring(1);
  5251. switch (tokens[x].charAt(0)) {
  5252. case '+':
  5253. try {
  5254. diffs[diffsLength++] = [DIFF_INSERT, decodeURI(param)];
  5255. } catch (ex) {
  5256. // Malformed URI sequence.
  5257. throw new Error('Illegal escape in diff_fromDelta: ' + param);
  5258. }
  5259. break;
  5260. case '-':
  5261. // Fall through.
  5262. case '=':
  5263. var n = parseInt(param, 10);
  5264. if (isNaN(n) || n < 0) {
  5265. throw new Error('Invalid number in diff_fromDelta: ' + param);
  5266. }
  5267. var text = text1.substring(pointer, pointer += n);
  5268. if (tokens[x].charAt(0) == '=') {
  5269. diffs[diffsLength++] = [DIFF_EQUAL, text];
  5270. } else {
  5271. diffs[diffsLength++] = [DIFF_DELETE, text];
  5272. }
  5273. break;
  5274. default:
  5275. // Blank tokens are ok (from a trailing \t).
  5276. // Anything else is an error.
  5277. if (tokens[x]) {
  5278. throw new Error('Invalid diff operation in diff_fromDelta: ' +
  5279. tokens[x]);
  5280. }
  5281. }
  5282. }
  5283. if (pointer != text1.length) {
  5284. throw new Error('Delta length (' + pointer +
  5285. ') does not equal source text length (' + text1.length + ').');
  5286. }
  5287. return diffs;
  5288. };
  5289. // MATCH FUNCTIONS
  5290. /**
  5291. * Locate the best instance of 'pattern' in 'text' near 'loc'.
  5292. * @param {string} text The text to search.
  5293. * @param {string} pattern The pattern to search for.
  5294. * @param {number} loc The location to search around.
  5295. * @return {number} Best match index or -1.
  5296. */
  5297. diff_match_patch.prototype.match_main = function(text, pattern, loc) {
  5298. // Check for null inputs.
  5299. if (text == null || pattern == null || loc == null) {
  5300. throw new Error('Null input. (match_main)');
  5301. }
  5302. loc = Math.max(0, Math.min(loc, text.length));
  5303. if (text == pattern) {
  5304. // Shortcut (potentially not guaranteed by the algorithm)
  5305. return 0;
  5306. } else if (!text.length) {
  5307. // Nothing to match.
  5308. return -1;
  5309. } else if (text.substring(loc, loc + pattern.length) == pattern) {
  5310. // Perfect match at the perfect spot! (Includes case of null pattern)
  5311. return loc;
  5312. } else {
  5313. // Do a fuzzy compare.
  5314. return this.match_bitap_(text, pattern, loc);
  5315. }
  5316. };
  5317. /**
  5318. * Locate the best instance of 'pattern' in 'text' near 'loc' using the
  5319. * Bitap algorithm.
  5320. * @param {string} text The text to search.
  5321. * @param {string} pattern The pattern to search for.
  5322. * @param {number} loc The location to search around.
  5323. * @return {number} Best match index or -1.
  5324. * @private
  5325. */
  5326. diff_match_patch.prototype.match_bitap_ = function(text, pattern, loc) {
  5327. if (pattern.length > this.Match_MaxBits) {
  5328. throw new Error('Pattern too long for this browser.');
  5329. }
  5330. // Initialise the alphabet.
  5331. var s = this.match_alphabet_(pattern);
  5332. var dmp = this; // 'this' becomes 'window' in a closure.
  5333. /**
  5334. * Compute and return the score for a match with e errors and x location.
  5335. * Accesses loc and pattern through being a closure.
  5336. * @param {number} e Number of errors in match.
  5337. * @param {number} x Location of match.
  5338. * @return {number} Overall score for match (0.0 = good, 1.0 = bad).
  5339. * @private
  5340. */
  5341. function match_bitapScore_(e, x) {
  5342. var accuracy = e / pattern.length;
  5343. var proximity = Math.abs(loc - x);
  5344. if (!dmp.Match_Distance) {
  5345. // Dodge divide by zero error.
  5346. return proximity ? 1.0 : accuracy;
  5347. }
  5348. return accuracy + (proximity / dmp.Match_Distance);
  5349. }
  5350. // Highest score beyond which we give up.
  5351. var score_threshold = this.Match_Threshold;
  5352. // Is there a nearby exact match? (speedup)
  5353. var best_loc = text.indexOf(pattern, loc);
  5354. if (best_loc != -1) {
  5355. score_threshold = Math.min(match_bitapScore_(0, best_loc), score_threshold);
  5356. // What about in the other direction? (speedup)
  5357. best_loc = text.lastIndexOf(pattern, loc + pattern.length);
  5358. if (best_loc != -1) {
  5359. score_threshold =
  5360. Math.min(match_bitapScore_(0, best_loc), score_threshold);
  5361. }
  5362. }
  5363. // Initialise the bit arrays.
  5364. var matchmask = 1 << (pattern.length - 1);
  5365. best_loc = -1;
  5366. var bin_min, bin_mid;
  5367. var bin_max = pattern.length + text.length;
  5368. var last_rd;
  5369. for (var d = 0; d < pattern.length; d++) {
  5370. // Scan for the best match; each iteration allows for one more error.
  5371. // Run a binary search to determine how far from 'loc' we can stray at this
  5372. // error level.
  5373. bin_min = 0;
  5374. bin_mid = bin_max;
  5375. while (bin_min < bin_mid) {
  5376. if (match_bitapScore_(d, loc + bin_mid) <= score_threshold) {
  5377. bin_min = bin_mid;
  5378. } else {
  5379. bin_max = bin_mid;
  5380. }
  5381. bin_mid = Math.floor((bin_max - bin_min) / 2 + bin_min);
  5382. }
  5383. // Use the result from this iteration as the maximum for the next.
  5384. bin_max = bin_mid;
  5385. var start = Math.max(1, loc - bin_mid + 1);
  5386. var finish = Math.min(loc + bin_mid, text.length) + pattern.length;
  5387. var rd = Array(finish + 2);
  5388. rd[finish + 1] = (1 << d) - 1;
  5389. for (var j = finish; j >= start; j--) {
  5390. // The alphabet (s) is a sparse hash, so the following line generates
  5391. // warnings.
  5392. var charMatch = s[text.charAt(j - 1)];
  5393. if (d === 0) { // First pass: exact match.
  5394. rd[j] = ((rd[j + 1] << 1) | 1) & charMatch;
  5395. } else { // Subsequent passes: fuzzy match.
  5396. rd[j] = (((rd[j + 1] << 1) | 1) & charMatch) |
  5397. (((last_rd[j + 1] | last_rd[j]) << 1) | 1) |
  5398. last_rd[j + 1];
  5399. }
  5400. if (rd[j] & matchmask) {
  5401. var score = match_bitapScore_(d, j - 1);
  5402. // This match will almost certainly be better than any existing match.
  5403. // But check anyway.
  5404. if (score <= score_threshold) {
  5405. // Told you so.
  5406. score_threshold = score;
  5407. best_loc = j - 1;
  5408. if (best_loc > loc) {
  5409. // When passing loc, don't exceed our current distance from loc.
  5410. start = Math.max(1, 2 * loc - best_loc);
  5411. } else {
  5412. // Already passed loc, downhill from here on in.
  5413. break;
  5414. }
  5415. }
  5416. }
  5417. }
  5418. // No hope for a (better) match at greater error levels.
  5419. if (match_bitapScore_(d + 1, loc) > score_threshold) {
  5420. break;
  5421. }
  5422. last_rd = rd;
  5423. }
  5424. return best_loc;
  5425. };
  5426. /**
  5427. * Initialise the alphabet for the Bitap algorithm.
  5428. * @param {string} pattern The text to encode.
  5429. * @return {!Object} Hash of character locations.
  5430. * @private
  5431. */
  5432. diff_match_patch.prototype.match_alphabet_ = function(pattern) {
  5433. var s = {};
  5434. for (var i = 0; i < pattern.length; i++) {
  5435. s[pattern.charAt(i)] = 0;
  5436. }
  5437. for (var i = 0; i < pattern.length; i++) {
  5438. s[pattern.charAt(i)] |= 1 << (pattern.length - i - 1);
  5439. }
  5440. return s;
  5441. };
  5442. // PATCH FUNCTIONS
  5443. /**
  5444. * Increase the context until it is unique,
  5445. * but don't let the pattern expand beyond Match_MaxBits.
  5446. * @param {!diff_match_patch.patch_obj} patch The patch to grow.
  5447. * @param {string} text Source text.
  5448. * @private
  5449. */
  5450. diff_match_patch.prototype.patch_addContext_ = function(patch, text) {
  5451. if (text.length == 0) {
  5452. return;
  5453. }
  5454. var pattern = text.substring(patch.start2, patch.start2 + patch.length1);
  5455. var padding = 0;
  5456. // Look for the first and last matches of pattern in text. If two different
  5457. // matches are found, increase the pattern length.
  5458. while (text.indexOf(pattern) != text.lastIndexOf(pattern) &&
  5459. pattern.length < this.Match_MaxBits - this.Patch_Margin -
  5460. this.Patch_Margin) {
  5461. padding += this.Patch_Margin;
  5462. pattern = text.substring(patch.start2 - padding,
  5463. patch.start2 + patch.length1 + padding);
  5464. }
  5465. // Add one chunk for good luck.
  5466. padding += this.Patch_Margin;
  5467. // Add the prefix.
  5468. var prefix = text.substring(patch.start2 - padding, patch.start2);
  5469. if (prefix) {
  5470. patch.diffs.unshift([DIFF_EQUAL, prefix]);
  5471. }
  5472. // Add the suffix.
  5473. var suffix = text.substring(patch.start2 + patch.length1,
  5474. patch.start2 + patch.length1 + padding);
  5475. if (suffix) {
  5476. patch.diffs.push([DIFF_EQUAL, suffix]);
  5477. }
  5478. // Roll back the start points.
  5479. patch.start1 -= prefix.length;
  5480. patch.start2 -= prefix.length;
  5481. // Extend the lengths.
  5482. patch.length1 += prefix.length + suffix.length;
  5483. patch.length2 += prefix.length + suffix.length;
  5484. };
  5485. /**
  5486. * Compute a list of patches to turn text1 into text2.
  5487. * Use diffs if provided, otherwise compute it ourselves.
  5488. * There are four ways to call this function, depending on what data is
  5489. * available to the caller:
  5490. * Method 1:
  5491. * a = text1, b = text2
  5492. * Method 2:
  5493. * a = diffs
  5494. * Method 3 (optimal):
  5495. * a = text1, b = diffs
  5496. * Method 4 (deprecated, use method 3):
  5497. * a = text1, b = text2, c = diffs
  5498. *
  5499. * @param {string|!Array.<!diff_match_patch.Diff>} a text1 (methods 1,3,4) or
  5500. * Array of diff tuples for text1 to text2 (method 2).
  5501. * @param {string|!Array.<!diff_match_patch.Diff>} opt_b text2 (methods 1,4) or
  5502. * Array of diff tuples for text1 to text2 (method 3) or undefined (method 2).
  5503. * @param {string|!Array.<!diff_match_patch.Diff>} opt_c Array of diff tuples
  5504. * for text1 to text2 (method 4) or undefined (methods 1,2,3).
  5505. * @return {!Array.<!diff_match_patch.patch_obj>} Array of Patch objects.
  5506. */
  5507. diff_match_patch.prototype.patch_make = function(a, opt_b, opt_c) {
  5508. var text1, diffs;
  5509. if (typeof a == 'string' && typeof opt_b == 'string' &&
  5510. typeof opt_c == 'undefined') {
  5511. // Method 1: text1, text2
  5512. // Compute diffs from text1 and text2.
  5513. text1 = /** @type {string} */(a);
  5514. diffs = this.diff_main(text1, /** @type {string} */(opt_b), true);
  5515. if (diffs.length > 2) {
  5516. this.diff_cleanupSemantic(diffs);
  5517. this.diff_cleanupEfficiency(diffs);
  5518. }
  5519. } else if (a && typeof a == 'object' && typeof opt_b == 'undefined' &&
  5520. typeof opt_c == 'undefined') {
  5521. // Method 2: diffs
  5522. // Compute text1 from diffs.
  5523. diffs = /** @type {!Array.<!diff_match_patch.Diff>} */(a);
  5524. text1 = this.diff_text1(diffs);
  5525. } else if (typeof a == 'string' && opt_b && typeof opt_b == 'object' &&
  5526. typeof opt_c == 'undefined') {
  5527. // Method 3: text1, diffs
  5528. text1 = /** @type {string} */(a);
  5529. diffs = /** @type {!Array.<!diff_match_patch.Diff>} */(opt_b);
  5530. } else if (typeof a == 'string' && typeof opt_b == 'string' &&
  5531. opt_c && typeof opt_c == 'object') {
  5532. // Method 4: text1, text2, diffs
  5533. // text2 is not used.
  5534. text1 = /** @type {string} */(a);
  5535. diffs = /** @type {!Array.<!diff_match_patch.Diff>} */(opt_c);
  5536. } else {
  5537. throw new Error('Unknown call format to patch_make.');
  5538. }
  5539. if (diffs.length === 0) {
  5540. return []; // Get rid of the null case.
  5541. }
  5542. var patches = [];
  5543. var patch = new diff_match_patch.patch_obj();
  5544. var patchDiffLength = 0; // Keeping our own length var is faster in JS.
  5545. var char_count1 = 0; // Number of characters into the text1 string.
  5546. var char_count2 = 0; // Number of characters into the text2 string.
  5547. // Start with text1 (prepatch_text) and apply the diffs until we arrive at
  5548. // text2 (postpatch_text). We recreate the patches one by one to determine
  5549. // context info.
  5550. var prepatch_text = text1;
  5551. var postpatch_text = text1;
  5552. for (var x = 0; x < diffs.length; x++) {
  5553. var diff_type = diffs[x][0];
  5554. var diff_text = diffs[x][1];
  5555. if (!patchDiffLength && diff_type !== DIFF_EQUAL) {
  5556. // A new patch starts here.
  5557. patch.start1 = char_count1;
  5558. patch.start2 = char_count2;
  5559. }
  5560. switch (diff_type) {
  5561. case DIFF_INSERT:
  5562. patch.diffs[patchDiffLength++] = diffs[x];
  5563. patch.length2 += diff_text.length;
  5564. postpatch_text = postpatch_text.substring(0, char_count2) + diff_text +
  5565. postpatch_text.substring(char_count2);
  5566. break;
  5567. case DIFF_DELETE:
  5568. patch.length1 += diff_text.length;
  5569. patch.diffs[patchDiffLength++] = diffs[x];
  5570. postpatch_text = postpatch_text.substring(0, char_count2) +
  5571. postpatch_text.substring(char_count2 +
  5572. diff_text.length);
  5573. break;
  5574. case DIFF_EQUAL:
  5575. if (diff_text.length <= 2 * this.Patch_Margin &&
  5576. patchDiffLength && diffs.length != x + 1) {
  5577. // Small equality inside a patch.
  5578. patch.diffs[patchDiffLength++] = diffs[x];
  5579. patch.length1 += diff_text.length;
  5580. patch.length2 += diff_text.length;
  5581. } else if (diff_text.length >= 2 * this.Patch_Margin) {
  5582. // Time for a new patch.
  5583. if (patchDiffLength) {
  5584. this.patch_addContext_(patch, prepatch_text);
  5585. patches.push(patch);
  5586. patch = new diff_match_patch.patch_obj();
  5587. patchDiffLength = 0;
  5588. // Unlike Unidiff, our patch lists have a rolling context.
  5589. // http://code.google.com/p/google-diff-match-patch/wiki/Unidiff
  5590. // Update prepatch text & pos to reflect the application of the
  5591. // just completed patch.
  5592. prepatch_text = postpatch_text;
  5593. char_count1 = char_count2;
  5594. }
  5595. }
  5596. break;
  5597. }
  5598. // Update the current character count.
  5599. if (diff_type !== DIFF_INSERT) {
  5600. char_count1 += diff_text.length;
  5601. }
  5602. if (diff_type !== DIFF_DELETE) {
  5603. char_count2 += diff_text.length;
  5604. }
  5605. }
  5606. // Pick up the leftover patch if not empty.
  5607. if (patchDiffLength) {
  5608. this.patch_addContext_(patch, prepatch_text);
  5609. patches.push(patch);
  5610. }
  5611. return patches;
  5612. };
  5613. /**
  5614. * Given an array of patches, return another array that is identical.
  5615. * @param {!Array.<!diff_match_patch.patch_obj>} patches Array of Patch objects.
  5616. * @return {!Array.<!diff_match_patch.patch_obj>} Array of Patch objects.
  5617. */
  5618. diff_match_patch.prototype.patch_deepCopy = function(patches) {
  5619. // Making deep copies is hard in JavaScript.
  5620. var patchesCopy = [];
  5621. for (var x = 0; x < patches.length; x++) {
  5622. var patch = patches[x];
  5623. var patchCopy = new diff_match_patch.patch_obj();
  5624. patchCopy.diffs = [];
  5625. for (var y = 0; y < patch.diffs.length; y++) {
  5626. patchCopy.diffs[y] = patch.diffs[y].slice();
  5627. }
  5628. patchCopy.start1 = patch.start1;
  5629. patchCopy.start2 = patch.start2;
  5630. patchCopy.length1 = patch.length1;
  5631. patchCopy.length2 = patch.length2;
  5632. patchesCopy[x] = patchCopy;
  5633. }
  5634. return patchesCopy;
  5635. };
  5636. /**
  5637. * Merge a set of patches onto the text. Return a patched text, as well
  5638. * as a list of true/false values indicating which patches were applied.
  5639. * @param {!Array.<!diff_match_patch.patch_obj>} patches Array of Patch objects.
  5640. * @param {string} text Old text.
  5641. * @return {!Array.<string|!Array.<boolean>>} Two element Array, containing the
  5642. * new text and an array of boolean values.
  5643. */
  5644. diff_match_patch.prototype.patch_apply = function(patches, text) {
  5645. if (patches.length == 0) {
  5646. return [text, []];
  5647. }
  5648. // Deep copy the patches so that no changes are made to originals.
  5649. patches = this.patch_deepCopy(patches);
  5650. var nullPadding = this.patch_addPadding(patches);
  5651. text = nullPadding + text + nullPadding;
  5652. this.patch_splitMax(patches);
  5653. // delta keeps track of the offset between the expected and actual location
  5654. // of the previous patch. If there are patches expected at positions 10 and
  5655. // 20, but the first patch was found at 12, delta is 2 and the second patch
  5656. // has an effective expected position of 22.
  5657. var delta = 0;
  5658. var results = [];
  5659. for (var x = 0; x < patches.length; x++) {
  5660. var expected_loc = patches[x].start2 + delta;
  5661. var text1 = this.diff_text1(patches[x].diffs);
  5662. var start_loc;
  5663. var end_loc = -1;
  5664. if (text1.length > this.Match_MaxBits) {
  5665. // patch_splitMax will only provide an oversized pattern in the case of
  5666. // a monster delete.
  5667. start_loc = this.match_main(text, text1.substring(0, this.Match_MaxBits),
  5668. expected_loc);
  5669. if (start_loc != -1) {
  5670. end_loc = this.match_main(text,
  5671. text1.substring(text1.length - this.Match_MaxBits),
  5672. expected_loc + text1.length - this.Match_MaxBits);
  5673. if (end_loc == -1 || start_loc >= end_loc) {
  5674. // Can't find valid trailing context. Drop this patch.
  5675. start_loc = -1;
  5676. }
  5677. }
  5678. } else {
  5679. start_loc = this.match_main(text, text1, expected_loc);
  5680. }
  5681. if (start_loc == -1) {
  5682. // No match found. :(
  5683. results[x] = false;
  5684. // Subtract the delta for this failed patch from subsequent patches.
  5685. delta -= patches[x].length2 - patches[x].length1;
  5686. } else {
  5687. // Found a match. :)
  5688. results[x] = true;
  5689. delta = start_loc - expected_loc;
  5690. var text2;
  5691. if (end_loc == -1) {
  5692. text2 = text.substring(start_loc, start_loc + text1.length);
  5693. } else {
  5694. text2 = text.substring(start_loc, end_loc + this.Match_MaxBits);
  5695. }
  5696. if (text1 == text2) {
  5697. // Perfect match, just shove the replacement text in.
  5698. text = text.substring(0, start_loc) +
  5699. this.diff_text2(patches[x].diffs) +
  5700. text.substring(start_loc + text1.length);
  5701. } else {
  5702. // Imperfect match. Run a diff to get a framework of equivalent
  5703. // indices.
  5704. var diffs = this.diff_main(text1, text2, false);
  5705. if (text1.length > this.Match_MaxBits &&
  5706. this.diff_levenshtein(diffs) / text1.length >
  5707. this.Patch_DeleteThreshold) {
  5708. // The end points match, but the content is unacceptably bad.
  5709. results[x] = false;
  5710. } else {
  5711. this.diff_cleanupSemanticLossless(diffs);
  5712. var index1 = 0;
  5713. var index2;
  5714. for (var y = 0; y < patches[x].diffs.length; y++) {
  5715. var mod = patches[x].diffs[y];
  5716. if (mod[0] !== DIFF_EQUAL) {
  5717. index2 = this.diff_xIndex(diffs, index1);
  5718. }
  5719. if (mod[0] === DIFF_INSERT) { // Insertion
  5720. text = text.substring(0, start_loc + index2) + mod[1] +
  5721. text.substring(start_loc + index2);
  5722. } else if (mod[0] === DIFF_DELETE) { // Deletion
  5723. text = text.substring(0, start_loc + index2) +
  5724. text.substring(start_loc + this.diff_xIndex(diffs,
  5725. index1 + mod[1].length));
  5726. }
  5727. if (mod[0] !== DIFF_DELETE) {
  5728. index1 += mod[1].length;
  5729. }
  5730. }
  5731. }
  5732. }
  5733. }
  5734. }
  5735. // Strip the padding off.
  5736. text = text.substring(nullPadding.length, text.length - nullPadding.length);
  5737. return [text, results];
  5738. };
  5739. /**
  5740. * Add some padding on text start and end so that edges can match something.
  5741. * Intended to be called only from within patch_apply.
  5742. * @param {!Array.<!diff_match_patch.patch_obj>} patches Array of Patch objects.
  5743. * @return {string} The padding string added to each side.
  5744. */
  5745. diff_match_patch.prototype.patch_addPadding = function(patches) {
  5746. var paddingLength = this.Patch_Margin;
  5747. var nullPadding = '';
  5748. for (var x = 1; x <= paddingLength; x++) {
  5749. nullPadding += String.fromCharCode(x);
  5750. }
  5751. // Bump all the patches forward.
  5752. for (var x = 0; x < patches.length; x++) {
  5753. patches[x].start1 += paddingLength;
  5754. patches[x].start2 += paddingLength;
  5755. }
  5756. // Add some padding on start of first diff.
  5757. var patch = patches[0];
  5758. var diffs = patch.diffs;
  5759. if (diffs.length == 0 || diffs[0][0] != DIFF_EQUAL) {
  5760. // Add nullPadding equality.
  5761. diffs.unshift([DIFF_EQUAL, nullPadding]);
  5762. patch.start1 -= paddingLength; // Should be 0.
  5763. patch.start2 -= paddingLength; // Should be 0.
  5764. patch.length1 += paddingLength;
  5765. patch.length2 += paddingLength;
  5766. } else if (paddingLength > diffs[0][1].length) {
  5767. // Grow first equality.
  5768. var extraLength = paddingLength - diffs[0][1].length;
  5769. diffs[0][1] = nullPadding.substring(diffs[0][1].length) + diffs[0][1];
  5770. patch.start1 -= extraLength;
  5771. patch.start2 -= extraLength;
  5772. patch.length1 += extraLength;
  5773. patch.length2 += extraLength;
  5774. }
  5775. // Add some padding on end of last diff.
  5776. patch = patches[patches.length - 1];
  5777. diffs = patch.diffs;
  5778. if (diffs.length == 0 || diffs[diffs.length - 1][0] != DIFF_EQUAL) {
  5779. // Add nullPadding equality.
  5780. diffs.push([DIFF_EQUAL, nullPadding]);
  5781. patch.length1 += paddingLength;
  5782. patch.length2 += paddingLength;
  5783. } else if (paddingLength > diffs[diffs.length - 1][1].length) {
  5784. // Grow last equality.
  5785. var extraLength = paddingLength - diffs[diffs.length - 1][1].length;
  5786. diffs[diffs.length - 1][1] += nullPadding.substring(0, extraLength);
  5787. patch.length1 += extraLength;
  5788. patch.length2 += extraLength;
  5789. }
  5790. return nullPadding;
  5791. };
  5792. /**
  5793. * Look through the patches and break up any which are longer than the maximum
  5794. * limit of the match algorithm.
  5795. * Intended to be called only from within patch_apply.
  5796. * @param {!Array.<!diff_match_patch.patch_obj>} patches Array of Patch objects.
  5797. */
  5798. diff_match_patch.prototype.patch_splitMax = function(patches) {
  5799. var patch_size = this.Match_MaxBits;
  5800. for (var x = 0; x < patches.length; x++) {
  5801. if (patches[x].length1 <= patch_size) {
  5802. continue;
  5803. }
  5804. var bigpatch = patches[x];
  5805. // Remove the big old patch.
  5806. patches.splice(x--, 1);
  5807. var start1 = bigpatch.start1;
  5808. var start2 = bigpatch.start2;
  5809. var precontext = '';
  5810. while (bigpatch.diffs.length !== 0) {
  5811. // Create one of several smaller patches.
  5812. var patch = new diff_match_patch.patch_obj();
  5813. var empty = true;
  5814. patch.start1 = start1 - precontext.length;
  5815. patch.start2 = start2 - precontext.length;
  5816. if (precontext !== '') {
  5817. patch.length1 = patch.length2 = precontext.length;
  5818. patch.diffs.push([DIFF_EQUAL, precontext]);
  5819. }
  5820. while (bigpatch.diffs.length !== 0 &&
  5821. patch.length1 < patch_size - this.Patch_Margin) {
  5822. var diff_type = bigpatch.diffs[0][0];
  5823. var diff_text = bigpatch.diffs[0][1];
  5824. if (diff_type === DIFF_INSERT) {
  5825. // Insertions are harmless.
  5826. patch.length2 += diff_text.length;
  5827. start2 += diff_text.length;
  5828. patch.diffs.push(bigpatch.diffs.shift());
  5829. empty = false;
  5830. } else if (diff_type === DIFF_DELETE && patch.diffs.length == 1 &&
  5831. patch.diffs[0][0] == DIFF_EQUAL &&
  5832. diff_text.length > 2 * patch_size) {
  5833. // This is a large deletion. Let it pass in one chunk.
  5834. patch.length1 += diff_text.length;
  5835. start1 += diff_text.length;
  5836. empty = false;
  5837. patch.diffs.push([diff_type, diff_text]);
  5838. bigpatch.diffs.shift();
  5839. } else {
  5840. // Deletion or equality. Only take as much as we can stomach.
  5841. diff_text = diff_text.substring(0,
  5842. patch_size - patch.length1 - this.Patch_Margin);
  5843. patch.length1 += diff_text.length;
  5844. start1 += diff_text.length;
  5845. if (diff_type === DIFF_EQUAL) {
  5846. patch.length2 += diff_text.length;
  5847. start2 += diff_text.length;
  5848. } else {
  5849. empty = false;
  5850. }
  5851. patch.diffs.push([diff_type, diff_text]);
  5852. if (diff_text == bigpatch.diffs[0][1]) {
  5853. bigpatch.diffs.shift();
  5854. } else {
  5855. bigpatch.diffs[0][1] =
  5856. bigpatch.diffs[0][1].substring(diff_text.length);
  5857. }
  5858. }
  5859. }
  5860. // Compute the head context for the next patch.
  5861. precontext = this.diff_text2(patch.diffs);
  5862. precontext =
  5863. precontext.substring(precontext.length - this.Patch_Margin);
  5864. // Append the end context for this patch.
  5865. var postcontext = this.diff_text1(bigpatch.diffs)
  5866. .substring(0, this.Patch_Margin);
  5867. if (postcontext !== '') {
  5868. patch.length1 += postcontext.length;
  5869. patch.length2 += postcontext.length;
  5870. if (patch.diffs.length !== 0 &&
  5871. patch.diffs[patch.diffs.length - 1][0] === DIFF_EQUAL) {
  5872. patch.diffs[patch.diffs.length - 1][1] += postcontext;
  5873. } else {
  5874. patch.diffs.push([DIFF_EQUAL, postcontext]);
  5875. }
  5876. }
  5877. if (!empty) {
  5878. patches.splice(++x, 0, patch);
  5879. }
  5880. }
  5881. }
  5882. };
  5883. /**
  5884. * Take a list of patches and return a textual representation.
  5885. * @param {!Array.<!diff_match_patch.patch_obj>} patches Array of Patch objects.
  5886. * @return {string} Text representation of patches.
  5887. */
  5888. diff_match_patch.prototype.patch_toText = function(patches) {
  5889. var text = [];
  5890. for (var x = 0; x < patches.length; x++) {
  5891. text[x] = patches[x];
  5892. }
  5893. return text.join('');
  5894. };
  5895. /**
  5896. * Parse a textual representation of patches and return a list of Patch objects.
  5897. * @param {string} textline Text representation of patches.
  5898. * @return {!Array.<!diff_match_patch.patch_obj>} Array of Patch objects.
  5899. * @throws {!Error} If invalid input.
  5900. */
  5901. diff_match_patch.prototype.patch_fromText = function(textline) {
  5902. var patches = [];
  5903. if (!textline) {
  5904. return patches;
  5905. }
  5906. var text = textline.split('\n');
  5907. var textPointer = 0;
  5908. var patchHeader = /^@@ -(\d+),?(\d*) \+(\d+),?(\d*) @@$/;
  5909. while (textPointer < text.length) {
  5910. var m = text[textPointer].match(patchHeader);
  5911. if (!m) {
  5912. throw new Error('Invalid patch string: ' + text[textPointer]);
  5913. }
  5914. var patch = new diff_match_patch.patch_obj();
  5915. patches.push(patch);
  5916. patch.start1 = parseInt(m[1], 10);
  5917. if (m[2] === '') {
  5918. patch.start1--;
  5919. patch.length1 = 1;
  5920. } else if (m[2] == '0') {
  5921. patch.length1 = 0;
  5922. } else {
  5923. patch.start1--;
  5924. patch.length1 = parseInt(m[2], 10);
  5925. }
  5926. patch.start2 = parseInt(m[3], 10);
  5927. if (m[4] === '') {
  5928. patch.start2--;
  5929. patch.length2 = 1;
  5930. } else if (m[4] == '0') {
  5931. patch.length2 = 0;
  5932. } else {
  5933. patch.start2--;
  5934. patch.length2 = parseInt(m[4], 10);
  5935. }
  5936. textPointer++;
  5937. while (textPointer < text.length) {
  5938. var sign = text[textPointer].charAt(0);
  5939. try {
  5940. var line = decodeURI(text[textPointer].substring(1));
  5941. } catch (ex) {
  5942. // Malformed URI sequence.
  5943. throw new Error('Illegal escape in patch_fromText: ' + line);
  5944. }
  5945. if (sign == '-') {
  5946. // Deletion.
  5947. patch.diffs.push([DIFF_DELETE, line]);
  5948. } else if (sign == '+') {
  5949. // Insertion.
  5950. patch.diffs.push([DIFF_INSERT, line]);
  5951. } else if (sign == ' ') {
  5952. // Minor equality.
  5953. patch.diffs.push([DIFF_EQUAL, line]);
  5954. } else if (sign == '@') {
  5955. // Start of next patch.
  5956. break;
  5957. } else if (sign === '') {
  5958. // Blank line? Whatever.
  5959. } else {
  5960. // WTF?
  5961. throw new Error('Invalid patch mode "' + sign + '" in: ' + line);
  5962. }
  5963. textPointer++;
  5964. }
  5965. }
  5966. return patches;
  5967. };
  5968. /**
  5969. * Class representing one patch operation.
  5970. * @constructor
  5971. */
  5972. diff_match_patch.patch_obj = function() {
  5973. /** @type {!Array.<!diff_match_patch.Diff>} */
  5974. this.diffs = [];
  5975. /** @type {?number} */
  5976. this.start1 = null;
  5977. /** @type {?number} */
  5978. this.start2 = null;
  5979. /** @type {number} */
  5980. this.length1 = 0;
  5981. /** @type {number} */
  5982. this.length2 = 0;
  5983. };
  5984. /**
  5985. * Emmulate GNU diff's format.
  5986. * Header: @@ -382,8 +481,9 @@
  5987. * Indicies are printed as 1-based, not 0-based.
  5988. * @return {string} The GNU diff string.
  5989. */
  5990. diff_match_patch.patch_obj.prototype.toString = function() {
  5991. var coords1, coords2;
  5992. if (this.length1 === 0) {
  5993. coords1 = this.start1 + ',0';
  5994. } else if (this.length1 == 1) {
  5995. coords1 = this.start1 + 1;
  5996. } else {
  5997. coords1 = (this.start1 + 1) + ',' + this.length1;
  5998. }
  5999. if (this.length2 === 0) {
  6000. coords2 = this.start2 + ',0';
  6001. } else if (this.length2 == 1) {
  6002. coords2 = this.start2 + 1;
  6003. } else {
  6004. coords2 = (this.start2 + 1) + ',' + this.length2;
  6005. }
  6006. var text = ['@@ -' + coords1 + ' +' + coords2 + ' @@\n'];
  6007. var op;
  6008. // Escape the body of the patch with %xx notation.
  6009. for (var x = 0; x < this.diffs.length; x++) {
  6010. switch (this.diffs[x][0]) {
  6011. case DIFF_INSERT:
  6012. op = '+';
  6013. break;
  6014. case DIFF_DELETE:
  6015. op = '-';
  6016. break;
  6017. case DIFF_EQUAL:
  6018. op = ' ';
  6019. break;
  6020. }
  6021. text[x + 1] = op + encodeURI(this.diffs[x][1]) + '\n';
  6022. }
  6023. return text.join('').replace(/%20/g, ' ');
  6024. };
  6025. // The following export code was added by @ForbesLindesay
  6026. module.exports = diff_match_patch;
  6027. module.exports['diff_match_patch'] = diff_match_patch;
  6028. module.exports['DIFF_DELETE'] = DIFF_DELETE;
  6029. module.exports['DIFF_INSERT'] = DIFF_INSERT;
  6030. module.exports['DIFF_EQUAL'] = DIFF_EQUAL;
  6031. },{}],67:[function(_dereq_,module,exports){
  6032. var eaw = {};
  6033. if ('undefined' == typeof module) {
  6034. window.eastasianwidth = eaw;
  6035. } else {
  6036. module.exports = eaw;
  6037. }
  6038. eaw.eastAsianWidth = function(character) {
  6039. var x = character.charCodeAt(0);
  6040. var y = (character.length == 2) ? character.charCodeAt(1) : 0;
  6041. var codePoint = x;
  6042. if ((0xD800 <= x && x <= 0xDBFF) && (0xDC00 <= y && y <= 0xDFFF)) {
  6043. x &= 0x3FF;
  6044. y &= 0x3FF;
  6045. codePoint = (x << 10) | y;
  6046. codePoint += 0x10000;
  6047. }
  6048. if ((0x3000 == codePoint) ||
  6049. (0xFF01 <= codePoint && codePoint <= 0xFF60) ||
  6050. (0xFFE0 <= codePoint && codePoint <= 0xFFE6)) {
  6051. return 'F';
  6052. }
  6053. if ((0x20A9 == codePoint) ||
  6054. (0xFF61 <= codePoint && codePoint <= 0xFFBE) ||
  6055. (0xFFC2 <= codePoint && codePoint <= 0xFFC7) ||
  6056. (0xFFCA <= codePoint && codePoint <= 0xFFCF) ||
  6057. (0xFFD2 <= codePoint && codePoint <= 0xFFD7) ||
  6058. (0xFFDA <= codePoint && codePoint <= 0xFFDC) ||
  6059. (0xFFE8 <= codePoint && codePoint <= 0xFFEE)) {
  6060. return 'H';
  6061. }
  6062. if ((0x1100 <= codePoint && codePoint <= 0x115F) ||
  6063. (0x11A3 <= codePoint && codePoint <= 0x11A7) ||
  6064. (0x11FA <= codePoint && codePoint <= 0x11FF) ||
  6065. (0x2329 <= codePoint && codePoint <= 0x232A) ||
  6066. (0x2E80 <= codePoint && codePoint <= 0x2E99) ||
  6067. (0x2E9B <= codePoint && codePoint <= 0x2EF3) ||
  6068. (0x2F00 <= codePoint && codePoint <= 0x2FD5) ||
  6069. (0x2FF0 <= codePoint && codePoint <= 0x2FFB) ||
  6070. (0x3001 <= codePoint && codePoint <= 0x303E) ||
  6071. (0x3041 <= codePoint && codePoint <= 0x3096) ||
  6072. (0x3099 <= codePoint && codePoint <= 0x30FF) ||
  6073. (0x3105 <= codePoint && codePoint <= 0x312D) ||
  6074. (0x3131 <= codePoint && codePoint <= 0x318E) ||
  6075. (0x3190 <= codePoint && codePoint <= 0x31BA) ||
  6076. (0x31C0 <= codePoint && codePoint <= 0x31E3) ||
  6077. (0x31F0 <= codePoint && codePoint <= 0x321E) ||
  6078. (0x3220 <= codePoint && codePoint <= 0x3247) ||
  6079. (0x3250 <= codePoint && codePoint <= 0x32FE) ||
  6080. (0x3300 <= codePoint && codePoint <= 0x4DBF) ||
  6081. (0x4E00 <= codePoint && codePoint <= 0xA48C) ||
  6082. (0xA490 <= codePoint && codePoint <= 0xA4C6) ||
  6083. (0xA960 <= codePoint && codePoint <= 0xA97C) ||
  6084. (0xAC00 <= codePoint && codePoint <= 0xD7A3) ||
  6085. (0xD7B0 <= codePoint && codePoint <= 0xD7C6) ||
  6086. (0xD7CB <= codePoint && codePoint <= 0xD7FB) ||
  6087. (0xF900 <= codePoint && codePoint <= 0xFAFF) ||
  6088. (0xFE10 <= codePoint && codePoint <= 0xFE19) ||
  6089. (0xFE30 <= codePoint && codePoint <= 0xFE52) ||
  6090. (0xFE54 <= codePoint && codePoint <= 0xFE66) ||
  6091. (0xFE68 <= codePoint && codePoint <= 0xFE6B) ||
  6092. (0x1B000 <= codePoint && codePoint <= 0x1B001) ||
  6093. (0x1F200 <= codePoint && codePoint <= 0x1F202) ||
  6094. (0x1F210 <= codePoint && codePoint <= 0x1F23A) ||
  6095. (0x1F240 <= codePoint && codePoint <= 0x1F248) ||
  6096. (0x1F250 <= codePoint && codePoint <= 0x1F251) ||
  6097. (0x20000 <= codePoint && codePoint <= 0x2F73F) ||
  6098. (0x2B740 <= codePoint && codePoint <= 0x2FFFD) ||
  6099. (0x30000 <= codePoint && codePoint <= 0x3FFFD)) {
  6100. return 'W';
  6101. }
  6102. if ((0x0020 <= codePoint && codePoint <= 0x007E) ||
  6103. (0x00A2 <= codePoint && codePoint <= 0x00A3) ||
  6104. (0x00A5 <= codePoint && codePoint <= 0x00A6) ||
  6105. (0x00AC == codePoint) ||
  6106. (0x00AF == codePoint) ||
  6107. (0x27E6 <= codePoint && codePoint <= 0x27ED) ||
  6108. (0x2985 <= codePoint && codePoint <= 0x2986)) {
  6109. return 'Na';
  6110. }
  6111. if ((0x00A1 == codePoint) ||
  6112. (0x00A4 == codePoint) ||
  6113. (0x00A7 <= codePoint && codePoint <= 0x00A8) ||
  6114. (0x00AA == codePoint) ||
  6115. (0x00AD <= codePoint && codePoint <= 0x00AE) ||
  6116. (0x00B0 <= codePoint && codePoint <= 0x00B4) ||
  6117. (0x00B6 <= codePoint && codePoint <= 0x00BA) ||
  6118. (0x00BC <= codePoint && codePoint <= 0x00BF) ||
  6119. (0x00C6 == codePoint) ||
  6120. (0x00D0 == codePoint) ||
  6121. (0x00D7 <= codePoint && codePoint <= 0x00D8) ||
  6122. (0x00DE <= codePoint && codePoint <= 0x00E1) ||
  6123. (0x00E6 == codePoint) ||
  6124. (0x00E8 <= codePoint && codePoint <= 0x00EA) ||
  6125. (0x00EC <= codePoint && codePoint <= 0x00ED) ||
  6126. (0x00F0 == codePoint) ||
  6127. (0x00F2 <= codePoint && codePoint <= 0x00F3) ||
  6128. (0x00F7 <= codePoint && codePoint <= 0x00FA) ||
  6129. (0x00FC == codePoint) ||
  6130. (0x00FE == codePoint) ||
  6131. (0x0101 == codePoint) ||
  6132. (0x0111 == codePoint) ||
  6133. (0x0113 == codePoint) ||
  6134. (0x011B == codePoint) ||
  6135. (0x0126 <= codePoint && codePoint <= 0x0127) ||
  6136. (0x012B == codePoint) ||
  6137. (0x0131 <= codePoint && codePoint <= 0x0133) ||
  6138. (0x0138 == codePoint) ||
  6139. (0x013F <= codePoint && codePoint <= 0x0142) ||
  6140. (0x0144 == codePoint) ||
  6141. (0x0148 <= codePoint && codePoint <= 0x014B) ||
  6142. (0x014D == codePoint) ||
  6143. (0x0152 <= codePoint && codePoint <= 0x0153) ||
  6144. (0x0166 <= codePoint && codePoint <= 0x0167) ||
  6145. (0x016B == codePoint) ||
  6146. (0x01CE == codePoint) ||
  6147. (0x01D0 == codePoint) ||
  6148. (0x01D2 == codePoint) ||
  6149. (0x01D4 == codePoint) ||
  6150. (0x01D6 == codePoint) ||
  6151. (0x01D8 == codePoint) ||
  6152. (0x01DA == codePoint) ||
  6153. (0x01DC == codePoint) ||
  6154. (0x0251 == codePoint) ||
  6155. (0x0261 == codePoint) ||
  6156. (0x02C4 == codePoint) ||
  6157. (0x02C7 == codePoint) ||
  6158. (0x02C9 <= codePoint && codePoint <= 0x02CB) ||
  6159. (0x02CD == codePoint) ||
  6160. (0x02D0 == codePoint) ||
  6161. (0x02D8 <= codePoint && codePoint <= 0x02DB) ||
  6162. (0x02DD == codePoint) ||
  6163. (0x02DF == codePoint) ||
  6164. (0x0300 <= codePoint && codePoint <= 0x036F) ||
  6165. (0x0391 <= codePoint && codePoint <= 0x03A1) ||
  6166. (0x03A3 <= codePoint && codePoint <= 0x03A9) ||
  6167. (0x03B1 <= codePoint && codePoint <= 0x03C1) ||
  6168. (0x03C3 <= codePoint && codePoint <= 0x03C9) ||
  6169. (0x0401 == codePoint) ||
  6170. (0x0410 <= codePoint && codePoint <= 0x044F) ||
  6171. (0x0451 == codePoint) ||
  6172. (0x2010 == codePoint) ||
  6173. (0x2013 <= codePoint && codePoint <= 0x2016) ||
  6174. (0x2018 <= codePoint && codePoint <= 0x2019) ||
  6175. (0x201C <= codePoint && codePoint <= 0x201D) ||
  6176. (0x2020 <= codePoint && codePoint <= 0x2022) ||
  6177. (0x2024 <= codePoint && codePoint <= 0x2027) ||
  6178. (0x2030 == codePoint) ||
  6179. (0x2032 <= codePoint && codePoint <= 0x2033) ||
  6180. (0x2035 == codePoint) ||
  6181. (0x203B == codePoint) ||
  6182. (0x203E == codePoint) ||
  6183. (0x2074 == codePoint) ||
  6184. (0x207F == codePoint) ||
  6185. (0x2081 <= codePoint && codePoint <= 0x2084) ||
  6186. (0x20AC == codePoint) ||
  6187. (0x2103 == codePoint) ||
  6188. (0x2105 == codePoint) ||
  6189. (0x2109 == codePoint) ||
  6190. (0x2113 == codePoint) ||
  6191. (0x2116 == codePoint) ||
  6192. (0x2121 <= codePoint && codePoint <= 0x2122) ||
  6193. (0x2126 == codePoint) ||
  6194. (0x212B == codePoint) ||
  6195. (0x2153 <= codePoint && codePoint <= 0x2154) ||
  6196. (0x215B <= codePoint && codePoint <= 0x215E) ||
  6197. (0x2160 <= codePoint && codePoint <= 0x216B) ||
  6198. (0x2170 <= codePoint && codePoint <= 0x2179) ||
  6199. (0x2189 == codePoint) ||
  6200. (0x2190 <= codePoint && codePoint <= 0x2199) ||
  6201. (0x21B8 <= codePoint && codePoint <= 0x21B9) ||
  6202. (0x21D2 == codePoint) ||
  6203. (0x21D4 == codePoint) ||
  6204. (0x21E7 == codePoint) ||
  6205. (0x2200 == codePoint) ||
  6206. (0x2202 <= codePoint && codePoint <= 0x2203) ||
  6207. (0x2207 <= codePoint && codePoint <= 0x2208) ||
  6208. (0x220B == codePoint) ||
  6209. (0x220F == codePoint) ||
  6210. (0x2211 == codePoint) ||
  6211. (0x2215 == codePoint) ||
  6212. (0x221A == codePoint) ||
  6213. (0x221D <= codePoint && codePoint <= 0x2220) ||
  6214. (0x2223 == codePoint) ||
  6215. (0x2225 == codePoint) ||
  6216. (0x2227 <= codePoint && codePoint <= 0x222C) ||
  6217. (0x222E == codePoint) ||
  6218. (0x2234 <= codePoint && codePoint <= 0x2237) ||
  6219. (0x223C <= codePoint && codePoint <= 0x223D) ||
  6220. (0x2248 == codePoint) ||
  6221. (0x224C == codePoint) ||
  6222. (0x2252 == codePoint) ||
  6223. (0x2260 <= codePoint && codePoint <= 0x2261) ||
  6224. (0x2264 <= codePoint && codePoint <= 0x2267) ||
  6225. (0x226A <= codePoint && codePoint <= 0x226B) ||
  6226. (0x226E <= codePoint && codePoint <= 0x226F) ||
  6227. (0x2282 <= codePoint && codePoint <= 0x2283) ||
  6228. (0x2286 <= codePoint && codePoint <= 0x2287) ||
  6229. (0x2295 == codePoint) ||
  6230. (0x2299 == codePoint) ||
  6231. (0x22A5 == codePoint) ||
  6232. (0x22BF == codePoint) ||
  6233. (0x2312 == codePoint) ||
  6234. (0x2460 <= codePoint && codePoint <= 0x24E9) ||
  6235. (0x24EB <= codePoint && codePoint <= 0x254B) ||
  6236. (0x2550 <= codePoint && codePoint <= 0x2573) ||
  6237. (0x2580 <= codePoint && codePoint <= 0x258F) ||
  6238. (0x2592 <= codePoint && codePoint <= 0x2595) ||
  6239. (0x25A0 <= codePoint && codePoint <= 0x25A1) ||
  6240. (0x25A3 <= codePoint && codePoint <= 0x25A9) ||
  6241. (0x25B2 <= codePoint && codePoint <= 0x25B3) ||
  6242. (0x25B6 <= codePoint && codePoint <= 0x25B7) ||
  6243. (0x25BC <= codePoint && codePoint <= 0x25BD) ||
  6244. (0x25C0 <= codePoint && codePoint <= 0x25C1) ||
  6245. (0x25C6 <= codePoint && codePoint <= 0x25C8) ||
  6246. (0x25CB == codePoint) ||
  6247. (0x25CE <= codePoint && codePoint <= 0x25D1) ||
  6248. (0x25E2 <= codePoint && codePoint <= 0x25E5) ||
  6249. (0x25EF == codePoint) ||
  6250. (0x2605 <= codePoint && codePoint <= 0x2606) ||
  6251. (0x2609 == codePoint) ||
  6252. (0x260E <= codePoint && codePoint <= 0x260F) ||
  6253. (0x2614 <= codePoint && codePoint <= 0x2615) ||
  6254. (0x261C == codePoint) ||
  6255. (0x261E == codePoint) ||
  6256. (0x2640 == codePoint) ||
  6257. (0x2642 == codePoint) ||
  6258. (0x2660 <= codePoint && codePoint <= 0x2661) ||
  6259. (0x2663 <= codePoint && codePoint <= 0x2665) ||
  6260. (0x2667 <= codePoint && codePoint <= 0x266A) ||
  6261. (0x266C <= codePoint && codePoint <= 0x266D) ||
  6262. (0x266F == codePoint) ||
  6263. (0x269E <= codePoint && codePoint <= 0x269F) ||
  6264. (0x26BE <= codePoint && codePoint <= 0x26BF) ||
  6265. (0x26C4 <= codePoint && codePoint <= 0x26CD) ||
  6266. (0x26CF <= codePoint && codePoint <= 0x26E1) ||
  6267. (0x26E3 == codePoint) ||
  6268. (0x26E8 <= codePoint && codePoint <= 0x26FF) ||
  6269. (0x273D == codePoint) ||
  6270. (0x2757 == codePoint) ||
  6271. (0x2776 <= codePoint && codePoint <= 0x277F) ||
  6272. (0x2B55 <= codePoint && codePoint <= 0x2B59) ||
  6273. (0x3248 <= codePoint && codePoint <= 0x324F) ||
  6274. (0xE000 <= codePoint && codePoint <= 0xF8FF) ||
  6275. (0xFE00 <= codePoint && codePoint <= 0xFE0F) ||
  6276. (0xFFFD == codePoint) ||
  6277. (0x1F100 <= codePoint && codePoint <= 0x1F10A) ||
  6278. (0x1F110 <= codePoint && codePoint <= 0x1F12D) ||
  6279. (0x1F130 <= codePoint && codePoint <= 0x1F169) ||
  6280. (0x1F170 <= codePoint && codePoint <= 0x1F19A) ||
  6281. (0xE0100 <= codePoint && codePoint <= 0xE01EF) ||
  6282. (0xF0000 <= codePoint && codePoint <= 0xFFFFD) ||
  6283. (0x100000 <= codePoint && codePoint <= 0x10FFFD)) {
  6284. return 'A';
  6285. }
  6286. return 'N';
  6287. };
  6288. eaw.characterLength = function(character) {
  6289. var code = this.eastAsianWidth(character);
  6290. if (code == 'F' || code == 'W' || code == 'A') {
  6291. return 2;
  6292. } else {
  6293. return 1;
  6294. }
  6295. };
  6296. eaw.length = function(string) {
  6297. var len = 0;
  6298. for (var i = 0; i < string.length; i++) {
  6299. len = len + this.characterLength(string.charAt(i));
  6300. }
  6301. return len;
  6302. };
  6303. eaw.slice = function(text, start, end) {
  6304. start = start ? start : 0;
  6305. end = end ? end : 1;
  6306. var result = '';
  6307. for (var i = 0; i < text.length; i++) {
  6308. var char = text.charAt(i);
  6309. var eawLen = eaw.length(result + char);
  6310. if (eawLen >= 1 + start && eawLen < 1 + end) {
  6311. result += char
  6312. }
  6313. }
  6314. return result;
  6315. };
  6316. },{}],68:[function(_dereq_,module,exports){
  6317. /**
  6318. * espurify - Clone new AST without extra properties
  6319. *
  6320. * https://github.com/estools/espurify
  6321. *
  6322. * Copyright (c) 2014-2016 Takuto Wada
  6323. * Licensed under the MIT license.
  6324. * https://github.com/estools/espurify/blob/master/MIT-LICENSE.txt
  6325. */
  6326. 'use strict';
  6327. var createWhitelist = _dereq_('./lib/create-whitelist');
  6328. var cloneWithWhitelist = _dereq_('./lib/clone-ast');
  6329. function createCloneFunction (options) {
  6330. return cloneWithWhitelist(createWhitelist(options));
  6331. }
  6332. var espurify = createCloneFunction();
  6333. espurify.customize = createCloneFunction;
  6334. espurify.cloneWithWhitelist = cloneWithWhitelist;
  6335. module.exports = espurify;
  6336. },{"./lib/clone-ast":70,"./lib/create-whitelist":71}],69:[function(_dereq_,module,exports){
  6337. module.exports = {
  6338. ArrayExpression: ['type', 'elements'],
  6339. ArrayPattern: ['type', 'elements'],
  6340. ArrowFunctionExpression: ['type', 'id', 'params', 'body', 'generator', 'expression'],
  6341. AssignmentExpression: ['type', 'operator', 'left', 'right'],
  6342. AssignmentPattern: ['type', 'left', 'right'],
  6343. BinaryExpression: ['type', 'operator', 'left', 'right'],
  6344. BlockStatement: ['type', 'body'],
  6345. BreakStatement: ['type', 'label'],
  6346. CallExpression: ['type', 'callee', 'arguments'],
  6347. CatchClause: ['type', 'param', 'guard', 'body'],
  6348. ClassBody: ['type', 'body'],
  6349. ClassDeclaration: ['type', 'id', 'superClass', 'body'],
  6350. ClassExpression: ['type', 'id', 'superClass', 'body'],
  6351. ConditionalExpression: ['type', 'test', 'alternate', 'consequent'],
  6352. ContinueStatement: ['type', 'label'],
  6353. DebuggerStatement: ['type'],
  6354. DoWhileStatement: ['type', 'body', 'test'],
  6355. EmptyStatement: ['type'],
  6356. ExportAllDeclaration: ['type', 'source'],
  6357. ExportDefaultDeclaration: ['type', 'declaration'],
  6358. ExportNamedDeclaration: ['type', 'declaration', 'specifiers', 'source'],
  6359. ExportSpecifier: ['type', 'exported', 'local'],
  6360. ExpressionStatement: ['type', 'expression'],
  6361. ForInStatement: ['type', 'left', 'right', 'body'],
  6362. ForOfStatement: ['type', 'left', 'right', 'body'],
  6363. ForStatement: ['type', 'init', 'test', 'update', 'body'],
  6364. FunctionDeclaration: ['type', 'id', 'params', 'body', 'generator'],
  6365. FunctionExpression: ['type', 'id', 'params', 'body', 'generator'],
  6366. Identifier: ['type', 'name'],
  6367. IfStatement: ['type', 'test', 'consequent', 'alternate'],
  6368. ImportDeclaration: ['type', 'specifiers', 'source'],
  6369. ImportDefaultSpecifier: ['type', 'local'],
  6370. ImportNamespaceSpecifier: ['type', 'local'],
  6371. ImportSpecifier: ['type', 'imported', 'local'],
  6372. LabeledStatement: ['type', 'label', 'body'],
  6373. Literal: ['type', 'value', 'regex'],
  6374. LogicalExpression: ['type', 'operator', 'left', 'right'],
  6375. MemberExpression: ['type', 'object', 'property', 'computed'],
  6376. MetaProperty: ['type', 'meta', 'property'],
  6377. MethodDefinition: ['type', 'key', 'value', 'kind', 'computed', 'static'],
  6378. NewExpression: ['type', 'callee', 'arguments'],
  6379. ObjectExpression: ['type', 'properties'],
  6380. ObjectPattern: ['type', 'properties'],
  6381. Program: ['type', 'body', 'sourceType'],
  6382. Property: ['type', 'key', 'value', 'kind', 'method', 'shorthand', 'computed'],
  6383. RestElement: ['type', 'argument'],
  6384. ReturnStatement: ['type', 'argument'],
  6385. SequenceExpression: ['type', 'expressions'],
  6386. SpreadElement: ['type', 'argument'],
  6387. Super: ['type'],
  6388. SwitchCase: ['type', 'test', 'consequent'],
  6389. SwitchStatement: ['type', 'discriminant', 'cases', 'lexical'],
  6390. TaggedTemplateExpression: ['type', 'tag', 'quasi'],
  6391. TemplateElement: ['type', 'tail', 'value'],
  6392. TemplateLiteral: ['type', 'quasis', 'expressions'],
  6393. ThisExpression: ['type'],
  6394. ThrowStatement: ['type', 'argument'],
  6395. TryStatement: ['type', 'block', 'handler', 'finalizer'],
  6396. UnaryExpression: ['type', 'operator', 'prefix', 'argument'],
  6397. UpdateExpression: ['type', 'operator', 'argument', 'prefix'],
  6398. VariableDeclaration: ['type', 'declarations', 'kind'],
  6399. VariableDeclarator: ['type', 'id', 'init'],
  6400. WhileStatement: ['type', 'test', 'body'],
  6401. WithStatement: ['type', 'object', 'body'],
  6402. YieldExpression: ['type', 'argument', 'delegate']
  6403. };
  6404. },{}],70:[function(_dereq_,module,exports){
  6405. 'use strict';
  6406. var isArray = _dereq_('core-js/library/fn/array/is-array');
  6407. var objectKeys = _dereq_('core-js/library/fn/object/keys');
  6408. var indexOf = _dereq_('core-js/library/fn/array/index-of');
  6409. var reduce = _dereq_('core-js/library/fn/array/reduce');
  6410. module.exports = function cloneWithWhitelist (astWhiteList) {
  6411. var whitelist = reduce(objectKeys(astWhiteList), function (props, key) {
  6412. var propNames = astWhiteList[key];
  6413. var prepend = (indexOf(propNames, 'type') === -1) ? ['type'] : [];
  6414. props[key] = prepend.concat(propNames);
  6415. return props;
  6416. }, {});
  6417. function cloneNodeOrObject (obj) {
  6418. var props = obj.type ? whitelist[obj.type] : null;
  6419. if (props) {
  6420. return cloneNode(obj, props);
  6421. } else {
  6422. return cloneObject(obj);
  6423. }
  6424. }
  6425. function cloneArray (ary) {
  6426. var i = ary.length, clone = [];
  6427. while (i--) {
  6428. clone[i] = cloneOf(ary[i]);
  6429. }
  6430. return clone;
  6431. }
  6432. function cloneNode (node, props) {
  6433. var i, len, key, clone = {};
  6434. for (i = 0, len = props.length; i < len; i += 1) {
  6435. key = props[i];
  6436. if (node.hasOwnProperty(key)) {
  6437. clone[key] = cloneOf(node[key]);
  6438. }
  6439. }
  6440. return clone;
  6441. }
  6442. function cloneObject (obj) {
  6443. var props = objectKeys(obj);
  6444. var i, len, key, clone = {};
  6445. for (i = 0, len = props.length; i < len; i += 1) {
  6446. key = props[i];
  6447. clone[key] = cloneOf(obj[key]);
  6448. }
  6449. return clone;
  6450. }
  6451. function cloneOf (val) {
  6452. if (typeof val === 'object' && val !== null) {
  6453. if (val instanceof RegExp) {
  6454. return new RegExp(val);
  6455. } else if (isArray(val)) {
  6456. return cloneArray(val);
  6457. } else {
  6458. return cloneNodeOrObject(val);
  6459. }
  6460. } else {
  6461. return val;
  6462. }
  6463. }
  6464. return cloneNodeOrObject;
  6465. };
  6466. },{"core-js/library/fn/array/index-of":8,"core-js/library/fn/array/is-array":9,"core-js/library/fn/array/reduce":12,"core-js/library/fn/object/keys":14}],71:[function(_dereq_,module,exports){
  6467. 'use strict';
  6468. var defaultProps = _dereq_('./ast-properties');
  6469. var objectKeys = _dereq_('core-js/library/fn/object/keys');
  6470. var assign = _dereq_('core-js/library/fn/object/assign');
  6471. module.exports = function createWhitelist (options) {
  6472. var opts = assign({}, options);
  6473. var typeName, i, len;
  6474. var keys = objectKeys(defaultProps);
  6475. var result = {};
  6476. for (i = 0, len = keys.length; i < len; i += 1) {
  6477. typeName = keys[i];
  6478. result[typeName] = defaultProps[typeName].concat(opts.extra);
  6479. }
  6480. return result;
  6481. };
  6482. },{"./ast-properties":69,"core-js/library/fn/object/assign":13,"core-js/library/fn/object/keys":14}],72:[function(_dereq_,module,exports){
  6483. /*
  6484. Copyright (C) 2012-2013 Yusuke Suzuki <utatane.tea@gmail.com>
  6485. Copyright (C) 2012 Ariya Hidayat <ariya.hidayat@gmail.com>
  6486. Redistribution and use in source and binary forms, with or without
  6487. modification, are permitted provided that the following conditions are met:
  6488. * Redistributions of source code must retain the above copyright
  6489. notice, this list of conditions and the following disclaimer.
  6490. * Redistributions in binary form must reproduce the above copyright
  6491. notice, this list of conditions and the following disclaimer in the
  6492. documentation and/or other materials provided with the distribution.
  6493. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  6494. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  6495. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  6496. ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  6497. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  6498. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  6499. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  6500. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  6501. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  6502. THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  6503. */
  6504. /*jslint vars:false, bitwise:true*/
  6505. /*jshint indent:4*/
  6506. /*global exports:true*/
  6507. (function clone(exports) {
  6508. 'use strict';
  6509. var Syntax,
  6510. isArray,
  6511. VisitorOption,
  6512. VisitorKeys,
  6513. objectCreate,
  6514. objectKeys,
  6515. BREAK,
  6516. SKIP,
  6517. REMOVE;
  6518. function ignoreJSHintError() { }
  6519. isArray = Array.isArray;
  6520. if (!isArray) {
  6521. isArray = function isArray(array) {
  6522. return Object.prototype.toString.call(array) === '[object Array]';
  6523. };
  6524. }
  6525. function deepCopy(obj) {
  6526. var ret = {}, key, val;
  6527. for (key in obj) {
  6528. if (obj.hasOwnProperty(key)) {
  6529. val = obj[key];
  6530. if (typeof val === 'object' && val !== null) {
  6531. ret[key] = deepCopy(val);
  6532. } else {
  6533. ret[key] = val;
  6534. }
  6535. }
  6536. }
  6537. return ret;
  6538. }
  6539. function shallowCopy(obj) {
  6540. var ret = {}, key;
  6541. for (key in obj) {
  6542. if (obj.hasOwnProperty(key)) {
  6543. ret[key] = obj[key];
  6544. }
  6545. }
  6546. return ret;
  6547. }
  6548. ignoreJSHintError(shallowCopy);
  6549. // based on LLVM libc++ upper_bound / lower_bound
  6550. // MIT License
  6551. function upperBound(array, func) {
  6552. var diff, len, i, current;
  6553. len = array.length;
  6554. i = 0;
  6555. while (len) {
  6556. diff = len >>> 1;
  6557. current = i + diff;
  6558. if (func(array[current])) {
  6559. len = diff;
  6560. } else {
  6561. i = current + 1;
  6562. len -= diff + 1;
  6563. }
  6564. }
  6565. return i;
  6566. }
  6567. function lowerBound(array, func) {
  6568. var diff, len, i, current;
  6569. len = array.length;
  6570. i = 0;
  6571. while (len) {
  6572. diff = len >>> 1;
  6573. current = i + diff;
  6574. if (func(array[current])) {
  6575. i = current + 1;
  6576. len -= diff + 1;
  6577. } else {
  6578. len = diff;
  6579. }
  6580. }
  6581. return i;
  6582. }
  6583. ignoreJSHintError(lowerBound);
  6584. objectCreate = Object.create || (function () {
  6585. function F() { }
  6586. return function (o) {
  6587. F.prototype = o;
  6588. return new F();
  6589. };
  6590. })();
  6591. objectKeys = Object.keys || function (o) {
  6592. var keys = [], key;
  6593. for (key in o) {
  6594. keys.push(key);
  6595. }
  6596. return keys;
  6597. };
  6598. function extend(to, from) {
  6599. var keys = objectKeys(from), key, i, len;
  6600. for (i = 0, len = keys.length; i < len; i += 1) {
  6601. key = keys[i];
  6602. to[key] = from[key];
  6603. }
  6604. return to;
  6605. }
  6606. Syntax = {
  6607. AssignmentExpression: 'AssignmentExpression',
  6608. AssignmentPattern: 'AssignmentPattern',
  6609. ArrayExpression: 'ArrayExpression',
  6610. ArrayPattern: 'ArrayPattern',
  6611. ArrowFunctionExpression: 'ArrowFunctionExpression',
  6612. AwaitExpression: 'AwaitExpression', // CAUTION: It's deferred to ES7.
  6613. BlockStatement: 'BlockStatement',
  6614. BinaryExpression: 'BinaryExpression',
  6615. BreakStatement: 'BreakStatement',
  6616. CallExpression: 'CallExpression',
  6617. CatchClause: 'CatchClause',
  6618. ClassBody: 'ClassBody',
  6619. ClassDeclaration: 'ClassDeclaration',
  6620. ClassExpression: 'ClassExpression',
  6621. ComprehensionBlock: 'ComprehensionBlock', // CAUTION: It's deferred to ES7.
  6622. ComprehensionExpression: 'ComprehensionExpression', // CAUTION: It's deferred to ES7.
  6623. ConditionalExpression: 'ConditionalExpression',
  6624. ContinueStatement: 'ContinueStatement',
  6625. DebuggerStatement: 'DebuggerStatement',
  6626. DirectiveStatement: 'DirectiveStatement',
  6627. DoWhileStatement: 'DoWhileStatement',
  6628. EmptyStatement: 'EmptyStatement',
  6629. ExportAllDeclaration: 'ExportAllDeclaration',
  6630. ExportDefaultDeclaration: 'ExportDefaultDeclaration',
  6631. ExportNamedDeclaration: 'ExportNamedDeclaration',
  6632. ExportSpecifier: 'ExportSpecifier',
  6633. ExpressionStatement: 'ExpressionStatement',
  6634. ForStatement: 'ForStatement',
  6635. ForInStatement: 'ForInStatement',
  6636. ForOfStatement: 'ForOfStatement',
  6637. FunctionDeclaration: 'FunctionDeclaration',
  6638. FunctionExpression: 'FunctionExpression',
  6639. GeneratorExpression: 'GeneratorExpression', // CAUTION: It's deferred to ES7.
  6640. Identifier: 'Identifier',
  6641. IfStatement: 'IfStatement',
  6642. ImportDeclaration: 'ImportDeclaration',
  6643. ImportDefaultSpecifier: 'ImportDefaultSpecifier',
  6644. ImportNamespaceSpecifier: 'ImportNamespaceSpecifier',
  6645. ImportSpecifier: 'ImportSpecifier',
  6646. Literal: 'Literal',
  6647. LabeledStatement: 'LabeledStatement',
  6648. LogicalExpression: 'LogicalExpression',
  6649. MemberExpression: 'MemberExpression',
  6650. MetaProperty: 'MetaProperty',
  6651. MethodDefinition: 'MethodDefinition',
  6652. ModuleSpecifier: 'ModuleSpecifier',
  6653. NewExpression: 'NewExpression',
  6654. ObjectExpression: 'ObjectExpression',
  6655. ObjectPattern: 'ObjectPattern',
  6656. Program: 'Program',
  6657. Property: 'Property',
  6658. RestElement: 'RestElement',
  6659. ReturnStatement: 'ReturnStatement',
  6660. SequenceExpression: 'SequenceExpression',
  6661. SpreadElement: 'SpreadElement',
  6662. Super: 'Super',
  6663. SwitchStatement: 'SwitchStatement',
  6664. SwitchCase: 'SwitchCase',
  6665. TaggedTemplateExpression: 'TaggedTemplateExpression',
  6666. TemplateElement: 'TemplateElement',
  6667. TemplateLiteral: 'TemplateLiteral',
  6668. ThisExpression: 'ThisExpression',
  6669. ThrowStatement: 'ThrowStatement',
  6670. TryStatement: 'TryStatement',
  6671. UnaryExpression: 'UnaryExpression',
  6672. UpdateExpression: 'UpdateExpression',
  6673. VariableDeclaration: 'VariableDeclaration',
  6674. VariableDeclarator: 'VariableDeclarator',
  6675. WhileStatement: 'WhileStatement',
  6676. WithStatement: 'WithStatement',
  6677. YieldExpression: 'YieldExpression'
  6678. };
  6679. VisitorKeys = {
  6680. AssignmentExpression: ['left', 'right'],
  6681. AssignmentPattern: ['left', 'right'],
  6682. ArrayExpression: ['elements'],
  6683. ArrayPattern: ['elements'],
  6684. ArrowFunctionExpression: ['params', 'body'],
  6685. AwaitExpression: ['argument'], // CAUTION: It's deferred to ES7.
  6686. BlockStatement: ['body'],
  6687. BinaryExpression: ['left', 'right'],
  6688. BreakStatement: ['label'],
  6689. CallExpression: ['callee', 'arguments'],
  6690. CatchClause: ['param', 'body'],
  6691. ClassBody: ['body'],
  6692. ClassDeclaration: ['id', 'superClass', 'body'],
  6693. ClassExpression: ['id', 'superClass', 'body'],
  6694. ComprehensionBlock: ['left', 'right'], // CAUTION: It's deferred to ES7.
  6695. ComprehensionExpression: ['blocks', 'filter', 'body'], // CAUTION: It's deferred to ES7.
  6696. ConditionalExpression: ['test', 'consequent', 'alternate'],
  6697. ContinueStatement: ['label'],
  6698. DebuggerStatement: [],
  6699. DirectiveStatement: [],
  6700. DoWhileStatement: ['body', 'test'],
  6701. EmptyStatement: [],
  6702. ExportAllDeclaration: ['source'],
  6703. ExportDefaultDeclaration: ['declaration'],
  6704. ExportNamedDeclaration: ['declaration', 'specifiers', 'source'],
  6705. ExportSpecifier: ['exported', 'local'],
  6706. ExpressionStatement: ['expression'],
  6707. ForStatement: ['init', 'test', 'update', 'body'],
  6708. ForInStatement: ['left', 'right', 'body'],
  6709. ForOfStatement: ['left', 'right', 'body'],
  6710. FunctionDeclaration: ['id', 'params', 'body'],
  6711. FunctionExpression: ['id', 'params', 'body'],
  6712. GeneratorExpression: ['blocks', 'filter', 'body'], // CAUTION: It's deferred to ES7.
  6713. Identifier: [],
  6714. IfStatement: ['test', 'consequent', 'alternate'],
  6715. ImportDeclaration: ['specifiers', 'source'],
  6716. ImportDefaultSpecifier: ['local'],
  6717. ImportNamespaceSpecifier: ['local'],
  6718. ImportSpecifier: ['imported', 'local'],
  6719. Literal: [],
  6720. LabeledStatement: ['label', 'body'],
  6721. LogicalExpression: ['left', 'right'],
  6722. MemberExpression: ['object', 'property'],
  6723. MetaProperty: ['meta', 'property'],
  6724. MethodDefinition: ['key', 'value'],
  6725. ModuleSpecifier: [],
  6726. NewExpression: ['callee', 'arguments'],
  6727. ObjectExpression: ['properties'],
  6728. ObjectPattern: ['properties'],
  6729. Program: ['body'],
  6730. Property: ['key', 'value'],
  6731. RestElement: [ 'argument' ],
  6732. ReturnStatement: ['argument'],
  6733. SequenceExpression: ['expressions'],
  6734. SpreadElement: ['argument'],
  6735. Super: [],
  6736. SwitchStatement: ['discriminant', 'cases'],
  6737. SwitchCase: ['test', 'consequent'],
  6738. TaggedTemplateExpression: ['tag', 'quasi'],
  6739. TemplateElement: [],
  6740. TemplateLiteral: ['quasis', 'expressions'],
  6741. ThisExpression: [],
  6742. ThrowStatement: ['argument'],
  6743. TryStatement: ['block', 'handler', 'finalizer'],
  6744. UnaryExpression: ['argument'],
  6745. UpdateExpression: ['argument'],
  6746. VariableDeclaration: ['declarations'],
  6747. VariableDeclarator: ['id', 'init'],
  6748. WhileStatement: ['test', 'body'],
  6749. WithStatement: ['object', 'body'],
  6750. YieldExpression: ['argument']
  6751. };
  6752. // unique id
  6753. BREAK = {};
  6754. SKIP = {};
  6755. REMOVE = {};
  6756. VisitorOption = {
  6757. Break: BREAK,
  6758. Skip: SKIP,
  6759. Remove: REMOVE
  6760. };
  6761. function Reference(parent, key) {
  6762. this.parent = parent;
  6763. this.key = key;
  6764. }
  6765. Reference.prototype.replace = function replace(node) {
  6766. this.parent[this.key] = node;
  6767. };
  6768. Reference.prototype.remove = function remove() {
  6769. if (isArray(this.parent)) {
  6770. this.parent.splice(this.key, 1);
  6771. return true;
  6772. } else {
  6773. this.replace(null);
  6774. return false;
  6775. }
  6776. };
  6777. function Element(node, path, wrap, ref) {
  6778. this.node = node;
  6779. this.path = path;
  6780. this.wrap = wrap;
  6781. this.ref = ref;
  6782. }
  6783. function Controller() { }
  6784. // API:
  6785. // return property path array from root to current node
  6786. Controller.prototype.path = function path() {
  6787. var i, iz, j, jz, result, element;
  6788. function addToPath(result, path) {
  6789. if (isArray(path)) {
  6790. for (j = 0, jz = path.length; j < jz; ++j) {
  6791. result.push(path[j]);
  6792. }
  6793. } else {
  6794. result.push(path);
  6795. }
  6796. }
  6797. // root node
  6798. if (!this.__current.path) {
  6799. return null;
  6800. }
  6801. // first node is sentinel, second node is root element
  6802. result = [];
  6803. for (i = 2, iz = this.__leavelist.length; i < iz; ++i) {
  6804. element = this.__leavelist[i];
  6805. addToPath(result, element.path);
  6806. }
  6807. addToPath(result, this.__current.path);
  6808. return result;
  6809. };
  6810. // API:
  6811. // return type of current node
  6812. Controller.prototype.type = function () {
  6813. var node = this.current();
  6814. return node.type || this.__current.wrap;
  6815. };
  6816. // API:
  6817. // return array of parent elements
  6818. Controller.prototype.parents = function parents() {
  6819. var i, iz, result;
  6820. // first node is sentinel
  6821. result = [];
  6822. for (i = 1, iz = this.__leavelist.length; i < iz; ++i) {
  6823. result.push(this.__leavelist[i].node);
  6824. }
  6825. return result;
  6826. };
  6827. // API:
  6828. // return current node
  6829. Controller.prototype.current = function current() {
  6830. return this.__current.node;
  6831. };
  6832. Controller.prototype.__execute = function __execute(callback, element) {
  6833. var previous, result;
  6834. result = undefined;
  6835. previous = this.__current;
  6836. this.__current = element;
  6837. this.__state = null;
  6838. if (callback) {
  6839. result = callback.call(this, element.node, this.__leavelist[this.__leavelist.length - 1].node);
  6840. }
  6841. this.__current = previous;
  6842. return result;
  6843. };
  6844. // API:
  6845. // notify control skip / break
  6846. Controller.prototype.notify = function notify(flag) {
  6847. this.__state = flag;
  6848. };
  6849. // API:
  6850. // skip child nodes of current node
  6851. Controller.prototype.skip = function () {
  6852. this.notify(SKIP);
  6853. };
  6854. // API:
  6855. // break traversals
  6856. Controller.prototype['break'] = function () {
  6857. this.notify(BREAK);
  6858. };
  6859. // API:
  6860. // remove node
  6861. Controller.prototype.remove = function () {
  6862. this.notify(REMOVE);
  6863. };
  6864. Controller.prototype.__initialize = function(root, visitor) {
  6865. this.visitor = visitor;
  6866. this.root = root;
  6867. this.__worklist = [];
  6868. this.__leavelist = [];
  6869. this.__current = null;
  6870. this.__state = null;
  6871. this.__fallback = null;
  6872. if (visitor.fallback === 'iteration') {
  6873. this.__fallback = objectKeys;
  6874. } else if (typeof visitor.fallback === 'function') {
  6875. this.__fallback = visitor.fallback;
  6876. }
  6877. this.__keys = VisitorKeys;
  6878. if (visitor.keys) {
  6879. this.__keys = extend(objectCreate(this.__keys), visitor.keys);
  6880. }
  6881. };
  6882. function isNode(node) {
  6883. if (node == null) {
  6884. return false;
  6885. }
  6886. return typeof node === 'object' && typeof node.type === 'string';
  6887. }
  6888. function isProperty(nodeType, key) {
  6889. return (nodeType === Syntax.ObjectExpression || nodeType === Syntax.ObjectPattern) && 'properties' === key;
  6890. }
  6891. Controller.prototype.traverse = function traverse(root, visitor) {
  6892. var worklist,
  6893. leavelist,
  6894. element,
  6895. node,
  6896. nodeType,
  6897. ret,
  6898. key,
  6899. current,
  6900. current2,
  6901. candidates,
  6902. candidate,
  6903. sentinel;
  6904. this.__initialize(root, visitor);
  6905. sentinel = {};
  6906. // reference
  6907. worklist = this.__worklist;
  6908. leavelist = this.__leavelist;
  6909. // initialize
  6910. worklist.push(new Element(root, null, null, null));
  6911. leavelist.push(new Element(null, null, null, null));
  6912. while (worklist.length) {
  6913. element = worklist.pop();
  6914. if (element === sentinel) {
  6915. element = leavelist.pop();
  6916. ret = this.__execute(visitor.leave, element);
  6917. if (this.__state === BREAK || ret === BREAK) {
  6918. return;
  6919. }
  6920. continue;
  6921. }
  6922. if (element.node) {
  6923. ret = this.__execute(visitor.enter, element);
  6924. if (this.__state === BREAK || ret === BREAK) {
  6925. return;
  6926. }
  6927. worklist.push(sentinel);
  6928. leavelist.push(element);
  6929. if (this.__state === SKIP || ret === SKIP) {
  6930. continue;
  6931. }
  6932. node = element.node;
  6933. nodeType = node.type || element.wrap;
  6934. candidates = this.__keys[nodeType];
  6935. if (!candidates) {
  6936. if (this.__fallback) {
  6937. candidates = this.__fallback(node);
  6938. } else {
  6939. throw new Error('Unknown node type ' + nodeType + '.');
  6940. }
  6941. }
  6942. current = candidates.length;
  6943. while ((current -= 1) >= 0) {
  6944. key = candidates[current];
  6945. candidate = node[key];
  6946. if (!candidate) {
  6947. continue;
  6948. }
  6949. if (isArray(candidate)) {
  6950. current2 = candidate.length;
  6951. while ((current2 -= 1) >= 0) {
  6952. if (!candidate[current2]) {
  6953. continue;
  6954. }
  6955. if (isProperty(nodeType, candidates[current])) {
  6956. element = new Element(candidate[current2], [key, current2], 'Property', null);
  6957. } else if (isNode(candidate[current2])) {
  6958. element = new Element(candidate[current2], [key, current2], null, null);
  6959. } else {
  6960. continue;
  6961. }
  6962. worklist.push(element);
  6963. }
  6964. } else if (isNode(candidate)) {
  6965. worklist.push(new Element(candidate, key, null, null));
  6966. }
  6967. }
  6968. }
  6969. }
  6970. };
  6971. Controller.prototype.replace = function replace(root, visitor) {
  6972. var worklist,
  6973. leavelist,
  6974. node,
  6975. nodeType,
  6976. target,
  6977. element,
  6978. current,
  6979. current2,
  6980. candidates,
  6981. candidate,
  6982. sentinel,
  6983. outer,
  6984. key;
  6985. function removeElem(element) {
  6986. var i,
  6987. key,
  6988. nextElem,
  6989. parent;
  6990. if (element.ref.remove()) {
  6991. // When the reference is an element of an array.
  6992. key = element.ref.key;
  6993. parent = element.ref.parent;
  6994. // If removed from array, then decrease following items' keys.
  6995. i = worklist.length;
  6996. while (i--) {
  6997. nextElem = worklist[i];
  6998. if (nextElem.ref && nextElem.ref.parent === parent) {
  6999. if (nextElem.ref.key < key) {
  7000. break;
  7001. }
  7002. --nextElem.ref.key;
  7003. }
  7004. }
  7005. }
  7006. }
  7007. this.__initialize(root, visitor);
  7008. sentinel = {};
  7009. // reference
  7010. worklist = this.__worklist;
  7011. leavelist = this.__leavelist;
  7012. // initialize
  7013. outer = {
  7014. root: root
  7015. };
  7016. element = new Element(root, null, null, new Reference(outer, 'root'));
  7017. worklist.push(element);
  7018. leavelist.push(element);
  7019. while (worklist.length) {
  7020. element = worklist.pop();
  7021. if (element === sentinel) {
  7022. element = leavelist.pop();
  7023. target = this.__execute(visitor.leave, element);
  7024. // node may be replaced with null,
  7025. // so distinguish between undefined and null in this place
  7026. if (target !== undefined && target !== BREAK && target !== SKIP && target !== REMOVE) {
  7027. // replace
  7028. element.ref.replace(target);
  7029. }
  7030. if (this.__state === REMOVE || target === REMOVE) {
  7031. removeElem(element);
  7032. }
  7033. if (this.__state === BREAK || target === BREAK) {
  7034. return outer.root;
  7035. }
  7036. continue;
  7037. }
  7038. target = this.__execute(visitor.enter, element);
  7039. // node may be replaced with null,
  7040. // so distinguish between undefined and null in this place
  7041. if (target !== undefined && target !== BREAK && target !== SKIP && target !== REMOVE) {
  7042. // replace
  7043. element.ref.replace(target);
  7044. element.node = target;
  7045. }
  7046. if (this.__state === REMOVE || target === REMOVE) {
  7047. removeElem(element);
  7048. element.node = null;
  7049. }
  7050. if (this.__state === BREAK || target === BREAK) {
  7051. return outer.root;
  7052. }
  7053. // node may be null
  7054. node = element.node;
  7055. if (!node) {
  7056. continue;
  7057. }
  7058. worklist.push(sentinel);
  7059. leavelist.push(element);
  7060. if (this.__state === SKIP || target === SKIP) {
  7061. continue;
  7062. }
  7063. nodeType = node.type || element.wrap;
  7064. candidates = this.__keys[nodeType];
  7065. if (!candidates) {
  7066. if (this.__fallback) {
  7067. candidates = this.__fallback(node);
  7068. } else {
  7069. throw new Error('Unknown node type ' + nodeType + '.');
  7070. }
  7071. }
  7072. current = candidates.length;
  7073. while ((current -= 1) >= 0) {
  7074. key = candidates[current];
  7075. candidate = node[key];
  7076. if (!candidate) {
  7077. continue;
  7078. }
  7079. if (isArray(candidate)) {
  7080. current2 = candidate.length;
  7081. while ((current2 -= 1) >= 0) {
  7082. if (!candidate[current2]) {
  7083. continue;
  7084. }
  7085. if (isProperty(nodeType, candidates[current])) {
  7086. element = new Element(candidate[current2], [key, current2], 'Property', new Reference(candidate, current2));
  7087. } else if (isNode(candidate[current2])) {
  7088. element = new Element(candidate[current2], [key, current2], null, new Reference(candidate, current2));
  7089. } else {
  7090. continue;
  7091. }
  7092. worklist.push(element);
  7093. }
  7094. } else if (isNode(candidate)) {
  7095. worklist.push(new Element(candidate, key, null, new Reference(node, key)));
  7096. }
  7097. }
  7098. }
  7099. return outer.root;
  7100. };
  7101. function traverse(root, visitor) {
  7102. var controller = new Controller();
  7103. return controller.traverse(root, visitor);
  7104. }
  7105. function replace(root, visitor) {
  7106. var controller = new Controller();
  7107. return controller.replace(root, visitor);
  7108. }
  7109. function extendCommentRange(comment, tokens) {
  7110. var target;
  7111. target = upperBound(tokens, function search(token) {
  7112. return token.range[0] > comment.range[0];
  7113. });
  7114. comment.extendedRange = [comment.range[0], comment.range[1]];
  7115. if (target !== tokens.length) {
  7116. comment.extendedRange[1] = tokens[target].range[0];
  7117. }
  7118. target -= 1;
  7119. if (target >= 0) {
  7120. comment.extendedRange[0] = tokens[target].range[1];
  7121. }
  7122. return comment;
  7123. }
  7124. function attachComments(tree, providedComments, tokens) {
  7125. // At first, we should calculate extended comment ranges.
  7126. var comments = [], comment, len, i, cursor;
  7127. if (!tree.range) {
  7128. throw new Error('attachComments needs range information');
  7129. }
  7130. // tokens array is empty, we attach comments to tree as 'leadingComments'
  7131. if (!tokens.length) {
  7132. if (providedComments.length) {
  7133. for (i = 0, len = providedComments.length; i < len; i += 1) {
  7134. comment = deepCopy(providedComments[i]);
  7135. comment.extendedRange = [0, tree.range[0]];
  7136. comments.push(comment);
  7137. }
  7138. tree.leadingComments = comments;
  7139. }
  7140. return tree;
  7141. }
  7142. for (i = 0, len = providedComments.length; i < len; i += 1) {
  7143. comments.push(extendCommentRange(deepCopy(providedComments[i]), tokens));
  7144. }
  7145. // This is based on John Freeman's implementation.
  7146. cursor = 0;
  7147. traverse(tree, {
  7148. enter: function (node) {
  7149. var comment;
  7150. while (cursor < comments.length) {
  7151. comment = comments[cursor];
  7152. if (comment.extendedRange[1] > node.range[0]) {
  7153. break;
  7154. }
  7155. if (comment.extendedRange[1] === node.range[0]) {
  7156. if (!node.leadingComments) {
  7157. node.leadingComments = [];
  7158. }
  7159. node.leadingComments.push(comment);
  7160. comments.splice(cursor, 1);
  7161. } else {
  7162. cursor += 1;
  7163. }
  7164. }
  7165. // already out of owned node
  7166. if (cursor === comments.length) {
  7167. return VisitorOption.Break;
  7168. }
  7169. if (comments[cursor].extendedRange[0] > node.range[1]) {
  7170. return VisitorOption.Skip;
  7171. }
  7172. }
  7173. });
  7174. cursor = 0;
  7175. traverse(tree, {
  7176. leave: function (node) {
  7177. var comment;
  7178. while (cursor < comments.length) {
  7179. comment = comments[cursor];
  7180. if (node.range[1] < comment.extendedRange[0]) {
  7181. break;
  7182. }
  7183. if (node.range[1] === comment.extendedRange[0]) {
  7184. if (!node.trailingComments) {
  7185. node.trailingComments = [];
  7186. }
  7187. node.trailingComments.push(comment);
  7188. comments.splice(cursor, 1);
  7189. } else {
  7190. cursor += 1;
  7191. }
  7192. }
  7193. // already out of owned node
  7194. if (cursor === comments.length) {
  7195. return VisitorOption.Break;
  7196. }
  7197. if (comments[cursor].extendedRange[0] > node.range[1]) {
  7198. return VisitorOption.Skip;
  7199. }
  7200. }
  7201. });
  7202. return tree;
  7203. }
  7204. exports.version = _dereq_('./package.json').version;
  7205. exports.Syntax = Syntax;
  7206. exports.traverse = traverse;
  7207. exports.replace = replace;
  7208. exports.attachComments = attachComments;
  7209. exports.VisitorKeys = VisitorKeys;
  7210. exports.VisitorOption = VisitorOption;
  7211. exports.Controller = Controller;
  7212. exports.cloneEnvironment = function () { return clone({}); };
  7213. return exports;
  7214. }(exports));
  7215. /* vim: set sw=4 ts=4 et tw=80 : */
  7216. },{"./package.json":73}],73:[function(_dereq_,module,exports){
  7217. module.exports={"version":"4.2.0"}
  7218. },{}],74:[function(_dereq_,module,exports){
  7219. // Copyright Joyent, Inc. and other Node contributors.
  7220. //
  7221. // Permission is hereby granted, free of charge, to any person obtaining a
  7222. // copy of this software and associated documentation files (the
  7223. // "Software"), to deal in the Software without restriction, including
  7224. // without limitation the rights to use, copy, modify, merge, publish,
  7225. // distribute, sublicense, and/or sell copies of the Software, and to permit
  7226. // persons to whom the Software is furnished to do so, subject to the
  7227. // following conditions:
  7228. //
  7229. // The above copyright notice and this permission notice shall be included
  7230. // in all copies or substantial portions of the Software.
  7231. //
  7232. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  7233. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  7234. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  7235. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  7236. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  7237. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  7238. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  7239. function EventEmitter() {
  7240. this._events = this._events || {};
  7241. this._maxListeners = this._maxListeners || undefined;
  7242. }
  7243. module.exports = EventEmitter;
  7244. // Backwards-compat with node 0.10.x
  7245. EventEmitter.EventEmitter = EventEmitter;
  7246. EventEmitter.prototype._events = undefined;
  7247. EventEmitter.prototype._maxListeners = undefined;
  7248. // By default EventEmitters will print a warning if more than 10 listeners are
  7249. // added to it. This is a useful default which helps finding memory leaks.
  7250. EventEmitter.defaultMaxListeners = 10;
  7251. // Obviously not all Emitters should be limited to 10. This function allows
  7252. // that to be increased. Set to zero for unlimited.
  7253. EventEmitter.prototype.setMaxListeners = function(n) {
  7254. if (!isNumber(n) || n < 0 || isNaN(n))
  7255. throw TypeError('n must be a positive number');
  7256. this._maxListeners = n;
  7257. return this;
  7258. };
  7259. EventEmitter.prototype.emit = function(type) {
  7260. var er, handler, len, args, i, listeners;
  7261. if (!this._events)
  7262. this._events = {};
  7263. // If there is no 'error' event listener then throw.
  7264. if (type === 'error') {
  7265. if (!this._events.error ||
  7266. (isObject(this._events.error) && !this._events.error.length)) {
  7267. er = arguments[1];
  7268. if (er instanceof Error) {
  7269. throw er; // Unhandled 'error' event
  7270. } else {
  7271. // At least give some kind of context to the user
  7272. var err = new Error('Uncaught, unspecified "error" event. (' + er + ')');
  7273. err.context = er;
  7274. throw err;
  7275. }
  7276. }
  7277. }
  7278. handler = this._events[type];
  7279. if (isUndefined(handler))
  7280. return false;
  7281. if (isFunction(handler)) {
  7282. switch (arguments.length) {
  7283. // fast cases
  7284. case 1:
  7285. handler.call(this);
  7286. break;
  7287. case 2:
  7288. handler.call(this, arguments[1]);
  7289. break;
  7290. case 3:
  7291. handler.call(this, arguments[1], arguments[2]);
  7292. break;
  7293. // slower
  7294. default:
  7295. args = Array.prototype.slice.call(arguments, 1);
  7296. handler.apply(this, args);
  7297. }
  7298. } else if (isObject(handler)) {
  7299. args = Array.prototype.slice.call(arguments, 1);
  7300. listeners = handler.slice();
  7301. len = listeners.length;
  7302. for (i = 0; i < len; i++)
  7303. listeners[i].apply(this, args);
  7304. }
  7305. return true;
  7306. };
  7307. EventEmitter.prototype.addListener = function(type, listener) {
  7308. var m;
  7309. if (!isFunction(listener))
  7310. throw TypeError('listener must be a function');
  7311. if (!this._events)
  7312. this._events = {};
  7313. // To avoid recursion in the case that type === "newListener"! Before
  7314. // adding it to the listeners, first emit "newListener".
  7315. if (this._events.newListener)
  7316. this.emit('newListener', type,
  7317. isFunction(listener.listener) ?
  7318. listener.listener : listener);
  7319. if (!this._events[type])
  7320. // Optimize the case of one listener. Don't need the extra array object.
  7321. this._events[type] = listener;
  7322. else if (isObject(this._events[type]))
  7323. // If we've already got an array, just append.
  7324. this._events[type].push(listener);
  7325. else
  7326. // Adding the second element, need to change to array.
  7327. this._events[type] = [this._events[type], listener];
  7328. // Check for listener leak
  7329. if (isObject(this._events[type]) && !this._events[type].warned) {
  7330. if (!isUndefined(this._maxListeners)) {
  7331. m = this._maxListeners;
  7332. } else {
  7333. m = EventEmitter.defaultMaxListeners;
  7334. }
  7335. if (m && m > 0 && this._events[type].length > m) {
  7336. this._events[type].warned = true;
  7337. console.error('(node) warning: possible EventEmitter memory ' +
  7338. 'leak detected. %d listeners added. ' +
  7339. 'Use emitter.setMaxListeners() to increase limit.',
  7340. this._events[type].length);
  7341. if (typeof console.trace === 'function') {
  7342. // not supported in IE 10
  7343. console.trace();
  7344. }
  7345. }
  7346. }
  7347. return this;
  7348. };
  7349. EventEmitter.prototype.on = EventEmitter.prototype.addListener;
  7350. EventEmitter.prototype.once = function(type, listener) {
  7351. if (!isFunction(listener))
  7352. throw TypeError('listener must be a function');
  7353. var fired = false;
  7354. function g() {
  7355. this.removeListener(type, g);
  7356. if (!fired) {
  7357. fired = true;
  7358. listener.apply(this, arguments);
  7359. }
  7360. }
  7361. g.listener = listener;
  7362. this.on(type, g);
  7363. return this;
  7364. };
  7365. // emits a 'removeListener' event iff the listener was removed
  7366. EventEmitter.prototype.removeListener = function(type, listener) {
  7367. var list, position, length, i;
  7368. if (!isFunction(listener))
  7369. throw TypeError('listener must be a function');
  7370. if (!this._events || !this._events[type])
  7371. return this;
  7372. list = this._events[type];
  7373. length = list.length;
  7374. position = -1;
  7375. if (list === listener ||
  7376. (isFunction(list.listener) && list.listener === listener)) {
  7377. delete this._events[type];
  7378. if (this._events.removeListener)
  7379. this.emit('removeListener', type, listener);
  7380. } else if (isObject(list)) {
  7381. for (i = length; i-- > 0;) {
  7382. if (list[i] === listener ||
  7383. (list[i].listener && list[i].listener === listener)) {
  7384. position = i;
  7385. break;
  7386. }
  7387. }
  7388. if (position < 0)
  7389. return this;
  7390. if (list.length === 1) {
  7391. list.length = 0;
  7392. delete this._events[type];
  7393. } else {
  7394. list.splice(position, 1);
  7395. }
  7396. if (this._events.removeListener)
  7397. this.emit('removeListener', type, listener);
  7398. }
  7399. return this;
  7400. };
  7401. EventEmitter.prototype.removeAllListeners = function(type) {
  7402. var key, listeners;
  7403. if (!this._events)
  7404. return this;
  7405. // not listening for removeListener, no need to emit
  7406. if (!this._events.removeListener) {
  7407. if (arguments.length === 0)
  7408. this._events = {};
  7409. else if (this._events[type])
  7410. delete this._events[type];
  7411. return this;
  7412. }
  7413. // emit removeListener for all listeners on all events
  7414. if (arguments.length === 0) {
  7415. for (key in this._events) {
  7416. if (key === 'removeListener') continue;
  7417. this.removeAllListeners(key);
  7418. }
  7419. this.removeAllListeners('removeListener');
  7420. this._events = {};
  7421. return this;
  7422. }
  7423. listeners = this._events[type];
  7424. if (isFunction(listeners)) {
  7425. this.removeListener(type, listeners);
  7426. } else if (listeners) {
  7427. // LIFO order
  7428. while (listeners.length)
  7429. this.removeListener(type, listeners[listeners.length - 1]);
  7430. }
  7431. delete this._events[type];
  7432. return this;
  7433. };
  7434. EventEmitter.prototype.listeners = function(type) {
  7435. var ret;
  7436. if (!this._events || !this._events[type])
  7437. ret = [];
  7438. else if (isFunction(this._events[type]))
  7439. ret = [this._events[type]];
  7440. else
  7441. ret = this._events[type].slice();
  7442. return ret;
  7443. };
  7444. EventEmitter.prototype.listenerCount = function(type) {
  7445. if (this._events) {
  7446. var evlistener = this._events[type];
  7447. if (isFunction(evlistener))
  7448. return 1;
  7449. else if (evlistener)
  7450. return evlistener.length;
  7451. }
  7452. return 0;
  7453. };
  7454. EventEmitter.listenerCount = function(emitter, type) {
  7455. return emitter.listenerCount(type);
  7456. };
  7457. function isFunction(arg) {
  7458. return typeof arg === 'function';
  7459. }
  7460. function isNumber(arg) {
  7461. return typeof arg === 'number';
  7462. }
  7463. function isObject(arg) {
  7464. return typeof arg === 'object' && arg !== null;
  7465. }
  7466. function isUndefined(arg) {
  7467. return arg === void 0;
  7468. }
  7469. },{}],75:[function(_dereq_,module,exports){
  7470. if (typeof Object.create === 'function') {
  7471. // implementation from standard node.js 'util' module
  7472. module.exports = function inherits(ctor, superCtor) {
  7473. ctor.super_ = superCtor
  7474. ctor.prototype = Object.create(superCtor.prototype, {
  7475. constructor: {
  7476. value: ctor,
  7477. enumerable: false,
  7478. writable: true,
  7479. configurable: true
  7480. }
  7481. });
  7482. };
  7483. } else {
  7484. // old school shim for old browsers
  7485. module.exports = function inherits(ctor, superCtor) {
  7486. ctor.super_ = superCtor
  7487. var TempCtor = function () {}
  7488. TempCtor.prototype = superCtor.prototype
  7489. ctor.prototype = new TempCtor()
  7490. ctor.prototype.constructor = ctor
  7491. }
  7492. }
  7493. },{}],76:[function(_dereq_,module,exports){
  7494. module.exports = _dereq_('./lib/create-formatter');
  7495. },{"./lib/create-formatter":77}],77:[function(_dereq_,module,exports){
  7496. 'use strict';
  7497. var assign = _dereq_('core-js/library/fn/object/assign');
  7498. var ContextTraversal = _dereq_('power-assert-context-traversal');
  7499. var LegacyContextTraversal = _dereq_('./legacy-context-traversal');
  7500. var StringWriter = _dereq_('./string-writer');
  7501. var defaultOptions = _dereq_('./default-options');
  7502. var reduce = _dereq_('core-js/library/fn/array/reduce');
  7503. /**
  7504. * options.reducers [array]
  7505. * options.renderers [array]
  7506. * options.outputOffset [number]
  7507. * options.lineSeparator [string]
  7508. * options.legacy [boolean]
  7509. */
  7510. function createFormatter (options) {
  7511. var formatterConfig = assign({}, defaultOptions(), options);
  7512. var reducers = formatterConfig.reducers || [];
  7513. var rendererConfigs = formatterConfig.renderers;
  7514. var len = rendererConfigs.length;
  7515. return function (powerAssertContext) {
  7516. var context = reduce(reducers, function (prevContext, reducer) {
  7517. return reducer(prevContext);
  7518. }, powerAssertContext);
  7519. var writer = new StringWriter(formatterConfig);
  7520. var traversal;
  7521. if (formatterConfig.legacy) {
  7522. traversal = new LegacyContextTraversal(context);
  7523. traversal.setWritable(writer);
  7524. } else {
  7525. traversal = new ContextTraversal(context);
  7526. }
  7527. for (var i = 0; i < len; i += 1) {
  7528. var RendererClass;
  7529. var renderer;
  7530. var config = rendererConfigs[i];
  7531. if (typeof config === 'object') {
  7532. RendererClass = config.ctor;
  7533. renderer = new RendererClass(config.options);
  7534. } else if (typeof config === 'function') {
  7535. RendererClass = config;
  7536. renderer = new RendererClass();
  7537. }
  7538. renderer.init(traversal);
  7539. if (typeof renderer.setWritable === 'function') {
  7540. renderer.setWritable(writer);
  7541. }
  7542. }
  7543. traversal.traverse();
  7544. writer.write('');
  7545. return writer.toString();
  7546. };
  7547. }
  7548. createFormatter.StringWriter = StringWriter;
  7549. module.exports = createFormatter;
  7550. },{"./default-options":78,"./legacy-context-traversal":79,"./string-writer":80,"core-js/library/fn/array/reduce":12,"core-js/library/fn/object/assign":13,"power-assert-context-traversal":82}],78:[function(_dereq_,module,exports){
  7551. 'use strict';
  7552. module.exports = function defaultOptions () {
  7553. return {
  7554. reducers: [
  7555. ],
  7556. legacy: false,
  7557. outputOffset: 2,
  7558. lineSeparator: '\n'
  7559. };
  7560. };
  7561. },{}],79:[function(_dereq_,module,exports){
  7562. 'use strict';
  7563. var ContextTraversal = _dereq_('power-assert-context-traversal');
  7564. var inherits = _dereq_('util').inherits;
  7565. var slice = Array.prototype.slice;
  7566. function LegacyContextTraversal (powerAssertContext) {
  7567. ContextTraversal.call(this, powerAssertContext);
  7568. }
  7569. inherits(LegacyContextTraversal, ContextTraversal);
  7570. LegacyContextTraversal.prototype.setWritable = function (writer) {
  7571. this.writer = writer;
  7572. };
  7573. LegacyContextTraversal.prototype.on = function () {
  7574. var args = slice.apply(arguments);
  7575. if (args[0] === 'render') {
  7576. args[0] = 'end';
  7577. }
  7578. ContextTraversal.prototype.on.apply(this, args);
  7579. };
  7580. LegacyContextTraversal.prototype.emit = function () {
  7581. var args = slice.apply(arguments);
  7582. if (args[0] === 'end') {
  7583. args[1] = this.writer;
  7584. }
  7585. ContextTraversal.prototype.emit.apply(this, args);
  7586. };
  7587. module.exports = LegacyContextTraversal;
  7588. },{"power-assert-context-traversal":82,"util":100}],80:[function(_dereq_,module,exports){
  7589. 'use strict';
  7590. function spacerStr (len) {
  7591. var str = '';
  7592. for(var i = 0; i < len; i += 1) {
  7593. str += ' ';
  7594. }
  7595. return str;
  7596. }
  7597. function StringWriter (config) {
  7598. this.lines = [];
  7599. this.lineSeparator = config.lineSeparator;
  7600. this.regex = new RegExp(this.lineSeparator, 'g');
  7601. this.spacer = spacerStr(config.outputOffset);
  7602. }
  7603. StringWriter.prototype.write = function (str) {
  7604. this.lines.push(this.spacer + str.replace(this.regex, this.lineSeparator + this.spacer));
  7605. };
  7606. StringWriter.prototype.toString = function () {
  7607. var str = this.lines.join(this.lineSeparator);
  7608. this.lines.length = 0;
  7609. return str;
  7610. };
  7611. module.exports = StringWriter;
  7612. },{}],81:[function(_dereq_,module,exports){
  7613. 'use strict';
  7614. var parser = _dereq_('acorn');
  7615. _dereq_('acorn-es7-plugin')(parser);
  7616. var estraverse = _dereq_('estraverse');
  7617. var purifyAst = _dereq_('espurify').customize({extra: ['range']});
  7618. var assign = _dereq_('core-js/library/fn/object/assign');
  7619. module.exports = function (powerAssertContext) {
  7620. var source = powerAssertContext.source;
  7621. if (source.ast && source.tokens && source.visitorKeys) {
  7622. return powerAssertContext;
  7623. }
  7624. var astAndTokens = parse(source);
  7625. var newSource = assign({}, source, {
  7626. ast: purifyAst(astAndTokens.expression),
  7627. tokens: astAndTokens.tokens,
  7628. visitorKeys: estraverse.VisitorKeys
  7629. });
  7630. return assign({}, powerAssertContext, { source: newSource });
  7631. };
  7632. function parserOptions(tokens) {
  7633. return {
  7634. sourceType: 'module',
  7635. ecmaVersion: 7,
  7636. locations: true,
  7637. ranges: false,
  7638. onToken: tokens,
  7639. plugins: {asyncawait: true}
  7640. };
  7641. }
  7642. function parse (source) {
  7643. var code = source.content;
  7644. var ast, tokens;
  7645. function doParse(wrapper) {
  7646. var content = wrapper ? wrapper(code) : code;
  7647. var tokenBag = [];
  7648. ast = parser.parse(content, parserOptions(tokenBag));
  7649. if (wrapper) {
  7650. ast = ast.body[0].body;
  7651. tokens = tokenBag.slice(6, -2);
  7652. } else {
  7653. tokens = tokenBag.slice(0, -1);
  7654. }
  7655. }
  7656. if (source.async) {
  7657. doParse(wrappedInAsync);
  7658. } else if (source.generator) {
  7659. doParse(wrappedInGenerator);
  7660. } else {
  7661. doParse();
  7662. }
  7663. var exp = ast.body[0].expression;
  7664. var columnOffset = exp.loc.start.column;
  7665. var offsetTree = estraverse.replace(exp, {
  7666. keys: estraverse.VisitorKeys,
  7667. enter: function (eachNode) {
  7668. if (!eachNode.loc && eachNode.range) {
  7669. // skip already visited node
  7670. return eachNode;
  7671. }
  7672. eachNode.range = [
  7673. eachNode.loc.start.column - columnOffset,
  7674. eachNode.loc.end.column - columnOffset
  7675. ];
  7676. delete eachNode.loc;
  7677. return eachNode;
  7678. }
  7679. });
  7680. return {
  7681. tokens: offsetAndSlimDownTokens(tokens),
  7682. expression: offsetTree
  7683. };
  7684. }
  7685. function wrappedInGenerator (jsCode) {
  7686. return 'function *wrapper() { ' + jsCode + ' }';
  7687. }
  7688. function wrappedInAsync (jsCode) {
  7689. return 'async function wrapper() { ' + jsCode + ' }';
  7690. }
  7691. function offsetAndSlimDownTokens (tokens) {
  7692. var i, token, newToken, result = [];
  7693. var columnOffset;
  7694. for(i = 0; i < tokens.length; i += 1) {
  7695. token = tokens[i];
  7696. if (i === 0) {
  7697. columnOffset = token.loc.start.column;
  7698. }
  7699. newToken = {
  7700. type: {
  7701. label: token.type.label
  7702. }
  7703. };
  7704. if (typeof token.value !== 'undefined') {
  7705. newToken.value = token.value;
  7706. }
  7707. newToken.range = [
  7708. token.loc.start.column - columnOffset,
  7709. token.loc.end.column - columnOffset
  7710. ];
  7711. result.push(newToken);
  7712. }
  7713. return result;
  7714. }
  7715. },{"acorn":5,"acorn-es7-plugin":4,"core-js/library/fn/object/assign":13,"espurify":68,"estraverse":72}],82:[function(_dereq_,module,exports){
  7716. module.exports = _dereq_('./lib/context-traversal');
  7717. },{"./lib/context-traversal":83}],83:[function(_dereq_,module,exports){
  7718. 'use strict';
  7719. var EventEmitter = _dereq_('events').EventEmitter;
  7720. var inherits = _dereq_('util').inherits;
  7721. var estraverse = _dereq_('estraverse');
  7722. var forEach = _dereq_('core-js/library/fn/array/for-each');
  7723. var reduce = _dereq_('core-js/library/fn/array/reduce');
  7724. var locationOf = _dereq_('./location');
  7725. var literalPattern = /^(?:String|Numeric|Null|Boolean|RegExp)?Literal$/;
  7726. var assign = _dereq_('core-js/library/fn/object/assign');
  7727. function ContextTraversal (powerAssertContext) {
  7728. this.powerAssertContext = powerAssertContext;
  7729. EventEmitter.call(this);
  7730. }
  7731. inherits(ContextTraversal, EventEmitter);
  7732. ContextTraversal.prototype.traverse = function () {
  7733. var _this = this;
  7734. var source = _this.powerAssertContext.source;
  7735. parseIfJson(source, 'ast');
  7736. parseIfJson(source, 'tokens');
  7737. parseIfJson(source, 'visitorKeys');
  7738. _this.emit('start', this.powerAssertContext);
  7739. forEach(this.powerAssertContext.args, function (capturedArgument) {
  7740. onEachEsNode(capturedArgument, source, function (esNode) {
  7741. _this.emit('data', esNode);
  7742. });
  7743. });
  7744. _this.emit('end');
  7745. };
  7746. function parseIfJson (source, propName) {
  7747. if (typeof source[propName] === 'string') {
  7748. source[propName] = JSON.parse(source[propName]);
  7749. }
  7750. }
  7751. function onEachEsNode(capturedArgument, source, callback) {
  7752. var espathToValue = reduce(capturedArgument.events, function (accum, ev) {
  7753. accum[ev.espath] = ev.value;
  7754. return accum;
  7755. }, {});
  7756. var nodeStack = [];
  7757. estraverse.traverse(source.ast, {
  7758. keys: source.visitorKeys,
  7759. enter: function (currentNode, parentNode) {
  7760. var parentEsNode = (0 < nodeStack.length) ? nodeStack[nodeStack.length - 1] : null;
  7761. var esNode = createEsNode(this.path(), currentNode, espathToValue, source.content, source.tokens, parentEsNode);
  7762. nodeStack.push(esNode);
  7763. callback(esNode);
  7764. },
  7765. leave: function (currentNode, parentNode) {
  7766. nodeStack.pop();
  7767. }
  7768. });
  7769. }
  7770. function isLiteral (node) {
  7771. return literalPattern.test(node.type);
  7772. }
  7773. function createEsNode (path, currentNode, espathToValue, jsCode, tokens, parent) {
  7774. var espath = path ? path.join('/') : '';
  7775. return {
  7776. espath: espath,
  7777. parent: parent,
  7778. key: path ? path[path.length - 1] : null,
  7779. node: currentNode,
  7780. code: jsCode.slice(currentNode.range[0], currentNode.range[1]),
  7781. value: isLiteral(currentNode) ? currentNode.value : espathToValue[espath],
  7782. isCaptured: espathToValue.hasOwnProperty(espath),
  7783. range: locationOf(currentNode, tokens)
  7784. };
  7785. }
  7786. module.exports = ContextTraversal;
  7787. },{"./location":84,"core-js/library/fn/array/for-each":7,"core-js/library/fn/array/reduce":12,"core-js/library/fn/object/assign":13,"estraverse":72,"events":74,"util":100}],84:[function(_dereq_,module,exports){
  7788. 'use strict';
  7789. var syntax = _dereq_('estraverse').Syntax;
  7790. function locationOf(currentNode, tokens) {
  7791. switch(currentNode.type) {
  7792. case syntax.MemberExpression:
  7793. return propertyLocationOf(currentNode, tokens);
  7794. case syntax.CallExpression:
  7795. if (currentNode.callee.type === syntax.MemberExpression) {
  7796. return propertyLocationOf(currentNode.callee, tokens);
  7797. }
  7798. break;
  7799. case syntax.BinaryExpression:
  7800. case syntax.LogicalExpression:
  7801. case syntax.AssignmentExpression:
  7802. return infixOperatorLocationOf(currentNode, tokens);
  7803. default:
  7804. break;
  7805. }
  7806. return currentNode.range;
  7807. }
  7808. function propertyLocationOf(memberExpression, tokens) {
  7809. var prop = memberExpression.property;
  7810. var token;
  7811. if (!memberExpression.computed) {
  7812. return prop.range;
  7813. }
  7814. token = findLeftBracketTokenOf(memberExpression, tokens);
  7815. return token ? token.range : prop.range;
  7816. }
  7817. // calculate location of infix operator for BinaryExpression, AssignmentExpression and LogicalExpression.
  7818. function infixOperatorLocationOf (expression, tokens) {
  7819. var token = findOperatorTokenOf(expression, tokens);
  7820. return token ? token.range : expression.left.range;
  7821. }
  7822. function findLeftBracketTokenOf(expression, tokens) {
  7823. var fromColumn = expression.property.range[0];
  7824. return searchToken(tokens, function (token, index) {
  7825. var prevToken;
  7826. if (token.range[0] === fromColumn) {
  7827. prevToken = tokens[index - 1];
  7828. // if (prevToken.type === 'Punctuator' && prevToken.value === '[') { // esprima
  7829. if (prevToken.type.label === '[') { // acorn
  7830. return prevToken;
  7831. }
  7832. }
  7833. return undefined;
  7834. });
  7835. }
  7836. function findOperatorTokenOf(expression, tokens) {
  7837. var fromColumn = expression.left.range[1];
  7838. var toColumn = expression.right.range[0];
  7839. return searchToken(tokens, function (token, index) {
  7840. if (fromColumn < token.range[0] &&
  7841. token.range[1] < toColumn &&
  7842. token.value === expression.operator) {
  7843. return token;
  7844. }
  7845. return undefined;
  7846. });
  7847. }
  7848. function searchToken(tokens, predicate) {
  7849. var i, token, found;
  7850. for(i = 0; i < tokens.length; i += 1) {
  7851. token = tokens[i];
  7852. found = predicate(token, i);
  7853. if (found) {
  7854. return found;
  7855. }
  7856. }
  7857. return undefined;
  7858. }
  7859. module.exports = locationOf;
  7860. },{"estraverse":72}],85:[function(_dereq_,module,exports){
  7861. 'use strict';
  7862. var BaseRenderer = _dereq_('power-assert-renderer-base');
  7863. var inherits = _dereq_('util').inherits;
  7864. function AssertionRenderer () {
  7865. BaseRenderer.call(this);
  7866. }
  7867. inherits(AssertionRenderer, BaseRenderer);
  7868. AssertionRenderer.prototype.onStart = function (context) {
  7869. this.assertionLine = context.source.content;
  7870. };
  7871. AssertionRenderer.prototype.onEnd = function () {
  7872. this.write('');
  7873. this.write(this.assertionLine);
  7874. };
  7875. module.exports = AssertionRenderer;
  7876. },{"power-assert-renderer-base":86,"util":100}],86:[function(_dereq_,module,exports){
  7877. 'use strict';
  7878. function BaseRenderer () {
  7879. }
  7880. BaseRenderer.prototype.init = function (traversal) {
  7881. var _this = this;
  7882. traversal.on('start', function (context) {
  7883. _this.onStart(context);
  7884. });
  7885. traversal.on('data', function (esNode) {
  7886. _this.onData(esNode);
  7887. });
  7888. traversal.on('end', function () {
  7889. _this.onEnd();
  7890. });
  7891. };
  7892. BaseRenderer.prototype.setWritable = function (writable) {
  7893. this.writable = writable;
  7894. };
  7895. // API
  7896. BaseRenderer.prototype.onStart = function (context) {
  7897. };
  7898. // API
  7899. BaseRenderer.prototype.onData = function (esNode) {
  7900. };
  7901. // API
  7902. BaseRenderer.prototype.onEnd = function () {
  7903. };
  7904. // API
  7905. BaseRenderer.prototype.write = function (str) {
  7906. this.writable.write(str);
  7907. };
  7908. module.exports = BaseRenderer;
  7909. },{}],87:[function(_dereq_,module,exports){
  7910. 'use strict';
  7911. var BaseRenderer = _dereq_('power-assert-renderer-base');
  7912. var inherits = _dereq_('util').inherits;
  7913. var typeName = _dereq_('type-name');
  7914. var keys = _dereq_('core-js/library/fn/object/keys');
  7915. var forEach = _dereq_('core-js/library/fn/array/for-each');
  7916. var udiff = _dereq_('./lib/udiff');
  7917. var stringifier = _dereq_('stringifier');
  7918. var assign = _dereq_('core-js/library/fn/object/assign');
  7919. var defaultOptions = _dereq_('./lib/default-options');
  7920. var literalPattern = /^(?:String|Numeric|Null|Boolean|RegExp)?Literal$/;
  7921. function isLiteral (node) {
  7922. return literalPattern.test(node.type);
  7923. }
  7924. /**
  7925. * options.stringify [function]
  7926. * options.maxDepth [number]
  7927. * options.lineSeparator [string]
  7928. * options.anonymous [string]
  7929. * options.circular [string]
  7930. *
  7931. * options.diff [function]
  7932. * options.lineDiffThreshold [number]
  7933. */
  7934. function ComparisonRenderer (config) {
  7935. BaseRenderer.call(this);
  7936. this.config = assign({}, defaultOptions(), config);
  7937. if (typeof this.config.stringify === 'function') {
  7938. this.stringify = this.config.stringify;
  7939. } else {
  7940. this.stringify = stringifier(this.config);
  7941. }
  7942. if (typeof this.config.diff === 'function') {
  7943. this.diff = this.config.diff;
  7944. } else {
  7945. this.diff = udiff(this.config);
  7946. }
  7947. this.espathToPair = {};
  7948. }
  7949. inherits(ComparisonRenderer, BaseRenderer);
  7950. ComparisonRenderer.prototype.onData = function (esNode) {
  7951. var pair;
  7952. if (!esNode.isCaptured) {
  7953. if (isTargetBinaryExpression(esNode.parent) && isLiteral(esNode.node)) {
  7954. this.espathToPair[esNode.parent.espath][esNode.key] = {code: esNode.code, value: esNode.value};
  7955. }
  7956. return;
  7957. }
  7958. if (isTargetBinaryExpression(esNode.parent)) {
  7959. this.espathToPair[esNode.parent.espath][esNode.key] = {code: esNode.code, value: esNode.value};
  7960. }
  7961. if (isTargetBinaryExpression(esNode)) {
  7962. pair = {
  7963. operator: esNode.node.operator,
  7964. value: esNode.value
  7965. };
  7966. this.espathToPair[esNode.espath] = pair;
  7967. }
  7968. };
  7969. ComparisonRenderer.prototype.onEnd = function () {
  7970. var _this = this;
  7971. var pairs = [];
  7972. forEach(keys(this.espathToPair), function (espath) {
  7973. var pair = _this.espathToPair[espath];
  7974. if (pair.left && pair.right) {
  7975. pairs.push(pair);
  7976. }
  7977. });
  7978. forEach(pairs, function (pair) {
  7979. _this.compare(pair);
  7980. });
  7981. };
  7982. ComparisonRenderer.prototype.compare = function (pair) {
  7983. if (isStringDiffTarget(pair)) {
  7984. this.showStringDiff(pair);
  7985. } else {
  7986. this.showExpectedAndActual(pair);
  7987. }
  7988. };
  7989. ComparisonRenderer.prototype.showExpectedAndActual = function (pair) {
  7990. this.write('');
  7991. this.write('[' + typeName(pair.right.value) + '] ' + pair.right.code);
  7992. this.write('=> ' + this.stringify(pair.right.value));
  7993. this.write('[' + typeName(pair.left.value) + '] ' + pair.left.code);
  7994. this.write('=> ' + this.stringify(pair.left.value));
  7995. };
  7996. ComparisonRenderer.prototype.showStringDiff = function (pair) {
  7997. this.write('');
  7998. this.write('--- [string] ' + pair.right.code);
  7999. this.write('+++ [string] ' + pair.left.code);
  8000. this.write(this.diff(pair.right.value, pair.left.value, this.config));
  8001. };
  8002. function isTargetBinaryExpression (esNode) {
  8003. return esNode &&
  8004. esNode.node.type === 'BinaryExpression' &&
  8005. (esNode.node.operator === '===' || esNode.node.operator === '==') &&
  8006. esNode.isCaptured &&
  8007. !(esNode.value);
  8008. }
  8009. function isStringDiffTarget(pair) {
  8010. return typeof pair.left.value === 'string' && typeof pair.right.value === 'string';
  8011. }
  8012. ComparisonRenderer.udiff = udiff;
  8013. module.exports = ComparisonRenderer;
  8014. },{"./lib/default-options":88,"./lib/udiff":89,"core-js/library/fn/array/for-each":7,"core-js/library/fn/object/assign":13,"core-js/library/fn/object/keys":14,"power-assert-renderer-base":86,"stringifier":95,"type-name":98,"util":100}],88:[function(_dereq_,module,exports){
  8015. 'use strict';
  8016. module.exports = function defaultOptions () {
  8017. return {
  8018. lineDiffThreshold: 5,
  8019. maxDepth: 2,
  8020. indent: null,
  8021. outputOffset: 2,
  8022. anonymous: 'Object',
  8023. circular: '#@Circular#',
  8024. lineSeparator: '\n'
  8025. };
  8026. };
  8027. },{}],89:[function(_dereq_,module,exports){
  8028. 'use strict';
  8029. var DiffMatchPatch = _dereq_('diff-match-patch');
  8030. var dmp = new DiffMatchPatch();
  8031. function udiff (config) {
  8032. return function diff (text1, text2) {
  8033. var patch;
  8034. if (config && shouldUseLineLevelDiff(text1, config)) {
  8035. patch = udiffLines(text1, text2);
  8036. } else {
  8037. patch = udiffChars(text1, text2);
  8038. }
  8039. return decodeURIComponent(patch);
  8040. };
  8041. }
  8042. function shouldUseLineLevelDiff (text, config) {
  8043. return config.lineDiffThreshold < text.split(/\r\n|\r|\n/).length;
  8044. }
  8045. function udiffLines(text1, text2) {
  8046. /*jshint camelcase: false */
  8047. var a = dmp.diff_linesToChars_(text1, text2);
  8048. var diffs = dmp.diff_main(a.chars1, a.chars2, false);
  8049. dmp.diff_charsToLines_(diffs, a.lineArray);
  8050. dmp.diff_cleanupSemantic(diffs);
  8051. return dmp.patch_toText(dmp.patch_make(text1, diffs));
  8052. }
  8053. function udiffChars (text1, text2) {
  8054. /*jshint camelcase: false */
  8055. var diffs = dmp.diff_main(text1, text2, false);
  8056. dmp.diff_cleanupSemantic(diffs);
  8057. return dmp.patch_toText(dmp.patch_make(text1, diffs));
  8058. }
  8059. module.exports = udiff;
  8060. },{"diff-match-patch":66}],90:[function(_dereq_,module,exports){
  8061. 'use strict';
  8062. var BaseRenderer = _dereq_('power-assert-renderer-base');
  8063. var inherits = _dereq_('util').inherits;
  8064. var forEach = _dereq_('core-js/library/fn/array/for-each');
  8065. var stringifier = _dereq_('stringifier');
  8066. var stringWidth = _dereq_('./lib/string-width');
  8067. var assign = _dereq_('core-js/library/fn/object/assign');
  8068. var defaultOptions = _dereq_('./lib/default-options');
  8069. /**
  8070. * options.stringify [function]
  8071. * options.maxDepth [number]
  8072. * options.lineSeparator [string]
  8073. * options.anonymous [string]
  8074. * options.circular [string]
  8075. *
  8076. * options.widthOf [function]
  8077. * options.ambiguousEastAsianCharWidth [number]
  8078. */
  8079. function DiagramRenderer (config) {
  8080. BaseRenderer.call(this);
  8081. this.config = assign({}, defaultOptions(), config);
  8082. this.events = [];
  8083. if (typeof this.config.stringify === 'function') {
  8084. this.stringify = this.config.stringify;
  8085. } else {
  8086. this.stringify = stringifier(this.config);
  8087. }
  8088. if (typeof this.config.widthOf === 'function') {
  8089. this.widthOf = this.config.widthOf;
  8090. } else {
  8091. this.widthOf = stringWidth(this.config);
  8092. }
  8093. this.initialVertivalBarLength = 1;
  8094. }
  8095. inherits(DiagramRenderer, BaseRenderer);
  8096. DiagramRenderer.prototype.onStart = function (context) {
  8097. this.assertionLine = context.source.content;
  8098. this.initializeRows();
  8099. };
  8100. DiagramRenderer.prototype.onData = function (esNode) {
  8101. if (!esNode.isCaptured) {
  8102. return;
  8103. }
  8104. this.events.push({value: esNode.value, leftIndex: esNode.range[0]});
  8105. };
  8106. DiagramRenderer.prototype.onEnd = function () {
  8107. this.events.sort(rightToLeft);
  8108. this.constructRows(this.events);
  8109. var _this = this;
  8110. forEach(this.rows, function (columns) {
  8111. _this.write(columns.join(''));
  8112. });
  8113. };
  8114. DiagramRenderer.prototype.initializeRows = function () {
  8115. this.rows = [];
  8116. for (var i = 0; i <= this.initialVertivalBarLength; i += 1) {
  8117. this.addOneMoreRow();
  8118. }
  8119. };
  8120. DiagramRenderer.prototype.newRowFor = function (assertionLine) {
  8121. return createRow(this.widthOf(assertionLine), ' ');
  8122. };
  8123. DiagramRenderer.prototype.addOneMoreRow = function () {
  8124. this.rows.push(this.newRowFor(this.assertionLine));
  8125. };
  8126. DiagramRenderer.prototype.lastRow = function () {
  8127. return this.rows[this.rows.length - 1];
  8128. };
  8129. DiagramRenderer.prototype.renderVerticalBarAt = function (columnIndex) {
  8130. var i, lastRowIndex = this.rows.length - 1;
  8131. for (i = 0; i < lastRowIndex; i += 1) {
  8132. this.rows[i].splice(columnIndex, 1, '|');
  8133. }
  8134. };
  8135. DiagramRenderer.prototype.renderValueAt = function (columnIndex, dumpedValue) {
  8136. var i, width = this.widthOf(dumpedValue);
  8137. for (i = 0; i < width; i += 1) {
  8138. this.lastRow().splice(columnIndex + i, 1, dumpedValue.charAt(i));
  8139. }
  8140. };
  8141. DiagramRenderer.prototype.isOverlapped = function (prevCapturing, nextCaputuring, dumpedValue) {
  8142. return (typeof prevCapturing !== 'undefined') && this.startColumnFor(prevCapturing) <= (this.startColumnFor(nextCaputuring) + this.widthOf(dumpedValue));
  8143. };
  8144. DiagramRenderer.prototype.constructRows = function (capturedEvents) {
  8145. var that = this;
  8146. var prevCaptured;
  8147. forEach(capturedEvents, function (captured) {
  8148. var dumpedValue = that.stringify(captured.value);
  8149. if (that.isOverlapped(prevCaptured, captured, dumpedValue)) {
  8150. that.addOneMoreRow();
  8151. }
  8152. that.renderVerticalBarAt(that.startColumnFor(captured));
  8153. that.renderValueAt(that.startColumnFor(captured), dumpedValue);
  8154. prevCaptured = captured;
  8155. });
  8156. };
  8157. DiagramRenderer.prototype.startColumnFor = function (captured) {
  8158. return this.widthOf(this.assertionLine.slice(0, captured.leftIndex));
  8159. };
  8160. function createRow (numCols, initial) {
  8161. var row = [], i;
  8162. for(i = 0; i < numCols; i += 1) {
  8163. row[i] = initial;
  8164. }
  8165. return row;
  8166. }
  8167. function rightToLeft (a, b) {
  8168. return b.leftIndex - a.leftIndex;
  8169. }
  8170. DiagramRenderer.stringWidth = stringWidth;
  8171. module.exports = DiagramRenderer;
  8172. },{"./lib/default-options":91,"./lib/string-width":92,"core-js/library/fn/array/for-each":7,"core-js/library/fn/object/assign":13,"power-assert-renderer-base":86,"stringifier":95,"util":100}],91:[function(_dereq_,module,exports){
  8173. 'use strict';
  8174. module.exports = function defaultOptions () {
  8175. return {
  8176. ambiguousEastAsianCharWidth: 2,
  8177. maxDepth: 2,
  8178. indent: null,
  8179. outputOffset: 2,
  8180. anonymous: 'Object',
  8181. circular: '#@Circular#',
  8182. lineSeparator: '\n'
  8183. };
  8184. };
  8185. },{}],92:[function(_dereq_,module,exports){
  8186. 'use strict';
  8187. var eaw = _dereq_('eastasianwidth');
  8188. function stringWidth (config) {
  8189. var ambiguousCharWidth = (config && config.ambiguousEastAsianCharWidth) || 1;
  8190. return function widthOf (str) {
  8191. var i, code, width = 0;
  8192. for(i = 0; i < str.length; i+=1) {
  8193. code = eaw.eastAsianWidth(str.charAt(i));
  8194. switch(code) {
  8195. case 'F':
  8196. case 'W':
  8197. width += 2;
  8198. break;
  8199. case 'H':
  8200. case 'Na':
  8201. case 'N':
  8202. width += 1;
  8203. break;
  8204. case 'A':
  8205. width += ambiguousCharWidth;
  8206. break;
  8207. }
  8208. }
  8209. return width;
  8210. };
  8211. }
  8212. module.exports = stringWidth;
  8213. },{"eastasianwidth":67}],93:[function(_dereq_,module,exports){
  8214. 'use strict';
  8215. var BaseRenderer = _dereq_('power-assert-renderer-base');
  8216. var inherits = _dereq_('util').inherits;
  8217. function FileRenderer () {
  8218. BaseRenderer.call(this);
  8219. }
  8220. inherits(FileRenderer, BaseRenderer);
  8221. FileRenderer.prototype.onStart = function (context) {
  8222. this.filepath = context.source.filepath;
  8223. this.lineNumber = context.source.line;
  8224. };
  8225. FileRenderer.prototype.onEnd = function () {
  8226. if (this.filepath) {
  8227. this.write('# ' + [this.filepath, this.lineNumber].join(':'));
  8228. } else {
  8229. this.write('# at line: ' + this.lineNumber);
  8230. }
  8231. };
  8232. module.exports = FileRenderer;
  8233. },{"power-assert-renderer-base":86,"util":100}],94:[function(_dereq_,module,exports){
  8234. // shim for using process in browser
  8235. var process = module.exports = {};
  8236. // cached from whatever global is present so that test runners that stub it
  8237. // don't break things. But we need to wrap it in a try catch in case it is
  8238. // wrapped in strict mode code which doesn't define any globals. It's inside a
  8239. // function because try/catches deoptimize in certain engines.
  8240. var cachedSetTimeout;
  8241. var cachedClearTimeout;
  8242. (function () {
  8243. try {
  8244. cachedSetTimeout = setTimeout;
  8245. } catch (e) {
  8246. cachedSetTimeout = function () {
  8247. throw new Error('setTimeout is not defined');
  8248. }
  8249. }
  8250. try {
  8251. cachedClearTimeout = clearTimeout;
  8252. } catch (e) {
  8253. cachedClearTimeout = function () {
  8254. throw new Error('clearTimeout is not defined');
  8255. }
  8256. }
  8257. } ())
  8258. var queue = [];
  8259. var draining = false;
  8260. var currentQueue;
  8261. var queueIndex = -1;
  8262. function cleanUpNextTick() {
  8263. if (!draining || !currentQueue) {
  8264. return;
  8265. }
  8266. draining = false;
  8267. if (currentQueue.length) {
  8268. queue = currentQueue.concat(queue);
  8269. } else {
  8270. queueIndex = -1;
  8271. }
  8272. if (queue.length) {
  8273. drainQueue();
  8274. }
  8275. }
  8276. function drainQueue() {
  8277. if (draining) {
  8278. return;
  8279. }
  8280. var timeout = cachedSetTimeout(cleanUpNextTick);
  8281. draining = true;
  8282. var len = queue.length;
  8283. while(len) {
  8284. currentQueue = queue;
  8285. queue = [];
  8286. while (++queueIndex < len) {
  8287. if (currentQueue) {
  8288. currentQueue[queueIndex].run();
  8289. }
  8290. }
  8291. queueIndex = -1;
  8292. len = queue.length;
  8293. }
  8294. currentQueue = null;
  8295. draining = false;
  8296. cachedClearTimeout(timeout);
  8297. }
  8298. process.nextTick = function (fun) {
  8299. var args = new Array(arguments.length - 1);
  8300. if (arguments.length > 1) {
  8301. for (var i = 1; i < arguments.length; i++) {
  8302. args[i - 1] = arguments[i];
  8303. }
  8304. }
  8305. queue.push(new Item(fun, args));
  8306. if (queue.length === 1 && !draining) {
  8307. cachedSetTimeout(drainQueue, 0);
  8308. }
  8309. };
  8310. // v8 likes predictible objects
  8311. function Item(fun, array) {
  8312. this.fun = fun;
  8313. this.array = array;
  8314. }
  8315. Item.prototype.run = function () {
  8316. this.fun.apply(null, this.array);
  8317. };
  8318. process.title = 'browser';
  8319. process.browser = true;
  8320. process.env = {};
  8321. process.argv = [];
  8322. process.version = ''; // empty string to avoid regexp issues
  8323. process.versions = {};
  8324. function noop() {}
  8325. process.on = noop;
  8326. process.addListener = noop;
  8327. process.once = noop;
  8328. process.off = noop;
  8329. process.removeListener = noop;
  8330. process.removeAllListeners = noop;
  8331. process.emit = noop;
  8332. process.binding = function (name) {
  8333. throw new Error('process.binding is not supported');
  8334. };
  8335. process.cwd = function () { return '/' };
  8336. process.chdir = function (dir) {
  8337. throw new Error('process.chdir is not supported');
  8338. };
  8339. process.umask = function() { return 0; };
  8340. },{}],95:[function(_dereq_,module,exports){
  8341. /**
  8342. * stringifier
  8343. *
  8344. * https://github.com/twada/stringifier
  8345. *
  8346. * Copyright (c) 2014-2015 Takuto Wada
  8347. * Licensed under the MIT license.
  8348. * http://twada.mit-license.org/2014-2015
  8349. */
  8350. 'use strict';
  8351. var traverse = _dereq_('traverse');
  8352. var typeName = _dereq_('type-name');
  8353. var assign = _dereq_('core-js/library/fn/object/assign');
  8354. var s = _dereq_('./strategies');
  8355. function defaultHandlers () {
  8356. return {
  8357. 'null': s.always('null'),
  8358. 'undefined': s.always('undefined'),
  8359. 'function': s.prune(),
  8360. 'string': s.json(),
  8361. 'boolean': s.json(),
  8362. 'number': s.number(),
  8363. 'symbol': s.toStr(),
  8364. 'RegExp': s.toStr(),
  8365. 'String': s.newLike(),
  8366. 'Boolean': s.newLike(),
  8367. 'Number': s.newLike(),
  8368. 'Date': s.newLike(),
  8369. 'Array': s.array(),
  8370. 'Object': s.object(),
  8371. '@default': s.object()
  8372. };
  8373. }
  8374. function defaultOptions () {
  8375. return {
  8376. maxDepth: null,
  8377. indent: null,
  8378. anonymous: '@Anonymous',
  8379. circular: '#@Circular#',
  8380. snip: '..(snip)',
  8381. lineSeparator: '\n',
  8382. typeFun: typeName
  8383. };
  8384. }
  8385. function createStringifier (customOptions) {
  8386. var options = assign({}, defaultOptions(), customOptions);
  8387. var handlers = assign({}, defaultHandlers(), options.handlers);
  8388. return function stringifyAny (push, x) {
  8389. var context = this;
  8390. var handler = handlerFor(context.node, options, handlers);
  8391. var currentPath = '/' + context.path.join('/');
  8392. var customization = handlers[currentPath];
  8393. var acc = {
  8394. context: context,
  8395. options: options,
  8396. handlers: handlers,
  8397. push: push
  8398. };
  8399. if (typeName(customization) === 'function') {
  8400. handler = customization;
  8401. } else if (typeName(customization) === 'number') {
  8402. handler = s.flow.compose(s.filters.truncate(customization),handler);
  8403. } else if (context.parent && typeName(context.parent.node) === 'Array' && !(context.key in context.parent.node)) {
  8404. // sparse arrays
  8405. handler = s.always('');
  8406. }
  8407. handler(acc, x);
  8408. return push;
  8409. };
  8410. }
  8411. function handlerFor (val, options, handlers) {
  8412. var tname = options.typeFun(val);
  8413. if (typeName(handlers[tname]) === 'function') {
  8414. return handlers[tname];
  8415. }
  8416. return handlers['@default'];
  8417. }
  8418. function walk (val, reducer) {
  8419. var buffer = [];
  8420. var push = function (str) {
  8421. buffer.push(str);
  8422. };
  8423. traverse(val).reduce(reducer, push);
  8424. return buffer.join('');
  8425. }
  8426. function stringify (val, options) {
  8427. return walk(val, createStringifier(options));
  8428. }
  8429. function stringifier (options) {
  8430. return function (val) {
  8431. return walk(val, createStringifier(options));
  8432. };
  8433. }
  8434. stringifier.stringify = stringify;
  8435. stringifier.strategies = s;
  8436. stringifier.defaultOptions = defaultOptions;
  8437. stringifier.defaultHandlers = defaultHandlers;
  8438. module.exports = stringifier;
  8439. },{"./strategies":96,"core-js/library/fn/object/assign":13,"traverse":97,"type-name":98}],96:[function(_dereq_,module,exports){
  8440. 'use strict';
  8441. var typeName = _dereq_('type-name');
  8442. var forEach = _dereq_('core-js/library/fn/array/for-each');
  8443. var arrayFilter = _dereq_('core-js/library/fn/array/filter');
  8444. var reduceRight = _dereq_('core-js/library/fn/array/reduce-right');
  8445. var indexOf = _dereq_('core-js/library/fn/array/index-of');
  8446. var slice = Array.prototype.slice;
  8447. var END = {};
  8448. var ITERATE = {};
  8449. // arguments should end with end or iterate
  8450. function compose () {
  8451. var filters = slice.apply(arguments);
  8452. return reduceRight(filters, function(right, left) {
  8453. return left(right);
  8454. });
  8455. }
  8456. // skip children
  8457. function end () {
  8458. return function (acc, x) {
  8459. acc.context.keys = [];
  8460. return END;
  8461. };
  8462. }
  8463. // iterate children
  8464. function iterate () {
  8465. return function (acc, x) {
  8466. return ITERATE;
  8467. };
  8468. }
  8469. function filter (predicate) {
  8470. return function (next) {
  8471. return function (acc, x) {
  8472. var toBeIterated;
  8473. var isIteratingArray = (typeName(x) === 'Array');
  8474. if (typeName(predicate) === 'function') {
  8475. toBeIterated = [];
  8476. forEach(acc.context.keys, function (key) {
  8477. var indexOrKey = isIteratingArray ? parseInt(key, 10) : key;
  8478. var kvp = {
  8479. key: indexOrKey,
  8480. value: x[key]
  8481. };
  8482. var decision = predicate(kvp);
  8483. if (decision) {
  8484. toBeIterated.push(key);
  8485. }
  8486. if (typeName(decision) === 'number') {
  8487. truncateByKey(decision, key, acc);
  8488. }
  8489. if (typeName(decision) === 'function') {
  8490. customizeStrategyForKey(decision, key, acc);
  8491. }
  8492. });
  8493. acc.context.keys = toBeIterated;
  8494. }
  8495. return next(acc, x);
  8496. };
  8497. };
  8498. }
  8499. function customizeStrategyForKey (strategy, key, acc) {
  8500. acc.handlers[currentPath(key, acc)] = strategy;
  8501. }
  8502. function truncateByKey (size, key, acc) {
  8503. acc.handlers[currentPath(key, acc)] = size;
  8504. }
  8505. function currentPath (key, acc) {
  8506. var pathToCurrentNode = [''].concat(acc.context.path);
  8507. if (typeName(key) !== 'undefined') {
  8508. pathToCurrentNode.push(key);
  8509. }
  8510. return pathToCurrentNode.join('/');
  8511. }
  8512. function allowedKeys (orderedWhiteList) {
  8513. return function (next) {
  8514. return function (acc, x) {
  8515. var isIteratingArray = (typeName(x) === 'Array');
  8516. if (!isIteratingArray && typeName(orderedWhiteList) === 'Array') {
  8517. acc.context.keys = arrayFilter(orderedWhiteList, function (propKey) {
  8518. return indexOf(acc.context.keys, propKey) !== -1;
  8519. });
  8520. }
  8521. return next(acc, x);
  8522. };
  8523. };
  8524. }
  8525. function safeKeys () {
  8526. return function (next) {
  8527. return function (acc, x) {
  8528. if (typeName(x) !== 'Array') {
  8529. acc.context.keys = arrayFilter(acc.context.keys, function (propKey) {
  8530. // Error handling for unsafe property access.
  8531. // For example, on PhantomJS,
  8532. // accessing HTMLInputElement.selectionEnd causes TypeError
  8533. try {
  8534. var val = x[propKey];
  8535. return true;
  8536. } catch (e) {
  8537. // skip unsafe key
  8538. return false;
  8539. }
  8540. });
  8541. }
  8542. return next(acc, x);
  8543. };
  8544. };
  8545. }
  8546. function arrayIndicesToKeys () {
  8547. return function (next) {
  8548. return function (acc, x) {
  8549. if (typeName(x) === 'Array' && 0 < x.length) {
  8550. var indices = Array(x.length);
  8551. for(var i = 0; i < x.length; i += 1) {
  8552. indices[i] = String(i); // traverse uses strings as keys
  8553. }
  8554. acc.context.keys = indices;
  8555. }
  8556. return next(acc, x);
  8557. };
  8558. };
  8559. }
  8560. function when (guard, then) {
  8561. return function (next) {
  8562. return function (acc, x) {
  8563. var kvp = {
  8564. key: acc.context.key,
  8565. value: x
  8566. };
  8567. if (guard(kvp, acc)) {
  8568. return then(acc, x);
  8569. }
  8570. return next(acc, x);
  8571. };
  8572. };
  8573. }
  8574. function truncate (size) {
  8575. return function (next) {
  8576. return function (acc, x) {
  8577. var orig = acc.push;
  8578. var ret;
  8579. acc.push = function (str) {
  8580. var savings = str.length - size;
  8581. var truncated;
  8582. if (savings <= size) {
  8583. orig.call(acc, str);
  8584. } else {
  8585. truncated = str.substring(0, size);
  8586. orig.call(acc, truncated + acc.options.snip);
  8587. }
  8588. };
  8589. ret = next(acc, x);
  8590. acc.push = orig;
  8591. return ret;
  8592. };
  8593. };
  8594. }
  8595. function constructorName () {
  8596. return function (next) {
  8597. return function (acc, x) {
  8598. var name = acc.options.typeFun(x);
  8599. if (name === '') {
  8600. name = acc.options.anonymous;
  8601. }
  8602. acc.push(name);
  8603. return next(acc, x);
  8604. };
  8605. };
  8606. }
  8607. function always (str) {
  8608. return function (next) {
  8609. return function (acc, x) {
  8610. acc.push(str);
  8611. return next(acc, x);
  8612. };
  8613. };
  8614. }
  8615. function optionValue (key) {
  8616. return function (next) {
  8617. return function (acc, x) {
  8618. acc.push(acc.options[key]);
  8619. return next(acc, x);
  8620. };
  8621. };
  8622. }
  8623. function json (replacer) {
  8624. return function (next) {
  8625. return function (acc, x) {
  8626. acc.push(JSON.stringify(x, replacer));
  8627. return next(acc, x);
  8628. };
  8629. };
  8630. }
  8631. function toStr () {
  8632. return function (next) {
  8633. return function (acc, x) {
  8634. acc.push(x.toString());
  8635. return next(acc, x);
  8636. };
  8637. };
  8638. }
  8639. function decorateArray () {
  8640. return function (next) {
  8641. return function (acc, x) {
  8642. acc.context.before(function (node) {
  8643. acc.push('[');
  8644. });
  8645. acc.context.after(function (node) {
  8646. afterAllChildren(this, acc.push, acc.options);
  8647. acc.push(']');
  8648. });
  8649. acc.context.pre(function (val, key) {
  8650. beforeEachChild(this, acc.push, acc.options);
  8651. });
  8652. acc.context.post(function (childContext) {
  8653. afterEachChild(childContext, acc.push);
  8654. });
  8655. return next(acc, x);
  8656. };
  8657. };
  8658. }
  8659. function decorateObject () {
  8660. return function (next) {
  8661. return function (acc, x) {
  8662. acc.context.before(function (node) {
  8663. acc.push('{');
  8664. });
  8665. acc.context.after(function (node) {
  8666. afterAllChildren(this, acc.push, acc.options);
  8667. acc.push('}');
  8668. });
  8669. acc.context.pre(function (val, key) {
  8670. beforeEachChild(this, acc.push, acc.options);
  8671. acc.push(sanitizeKey(key) + (acc.options.indent ? ': ' : ':'));
  8672. });
  8673. acc.context.post(function (childContext) {
  8674. afterEachChild(childContext, acc.push);
  8675. });
  8676. return next(acc, x);
  8677. };
  8678. };
  8679. }
  8680. function sanitizeKey (key) {
  8681. return /^[A-Za-z_]+$/.test(key) ? key : JSON.stringify(key);
  8682. }
  8683. function afterAllChildren (context, push, options) {
  8684. if (options.indent && 0 < context.keys.length) {
  8685. push(options.lineSeparator);
  8686. for(var i = 0; i < context.level; i += 1) { // indent level - 1
  8687. push(options.indent);
  8688. }
  8689. }
  8690. }
  8691. function beforeEachChild (context, push, options) {
  8692. if (options.indent) {
  8693. push(options.lineSeparator);
  8694. for(var i = 0; i <= context.level; i += 1) {
  8695. push(options.indent);
  8696. }
  8697. }
  8698. }
  8699. function afterEachChild (childContext, push) {
  8700. if (!childContext.isLast) {
  8701. push(',');
  8702. }
  8703. }
  8704. function nan (kvp, acc) {
  8705. return kvp.value !== kvp.value;
  8706. }
  8707. function positiveInfinity (kvp, acc) {
  8708. return !isFinite(kvp.value) && kvp.value === Infinity;
  8709. }
  8710. function negativeInfinity (kvp, acc) {
  8711. return !isFinite(kvp.value) && kvp.value !== Infinity;
  8712. }
  8713. function circular (kvp, acc) {
  8714. return acc.context.circular;
  8715. }
  8716. function maxDepth (kvp, acc) {
  8717. return (acc.options.maxDepth && acc.options.maxDepth <= acc.context.level);
  8718. }
  8719. var prune = compose(
  8720. always('#'),
  8721. constructorName(),
  8722. always('#'),
  8723. end()
  8724. );
  8725. var omitNaN = when(nan, compose(
  8726. always('NaN'),
  8727. end()
  8728. ));
  8729. var omitPositiveInfinity = when(positiveInfinity, compose(
  8730. always('Infinity'),
  8731. end()
  8732. ));
  8733. var omitNegativeInfinity = when(negativeInfinity, compose(
  8734. always('-Infinity'),
  8735. end()
  8736. ));
  8737. var omitCircular = when(circular, compose(
  8738. optionValue('circular'),
  8739. end()
  8740. ));
  8741. var omitMaxDepth = when(maxDepth, prune);
  8742. module.exports = {
  8743. filters: {
  8744. always: always,
  8745. optionValue: optionValue,
  8746. constructorName: constructorName,
  8747. json: json,
  8748. toStr: toStr,
  8749. prune: prune,
  8750. truncate: truncate,
  8751. decorateArray: decorateArray,
  8752. decorateObject: decorateObject
  8753. },
  8754. flow: {
  8755. compose: compose,
  8756. when: when,
  8757. allowedKeys: allowedKeys,
  8758. safeKeys: safeKeys,
  8759. arrayIndicesToKeys: arrayIndicesToKeys,
  8760. filter: filter,
  8761. iterate: iterate,
  8762. end: end
  8763. },
  8764. symbols: {
  8765. END: END,
  8766. ITERATE: ITERATE
  8767. },
  8768. always: function (str) {
  8769. return compose(always(str), end());
  8770. },
  8771. json: function () {
  8772. return compose(json(), end());
  8773. },
  8774. toStr: function () {
  8775. return compose(toStr(), end());
  8776. },
  8777. prune: function () {
  8778. return prune;
  8779. },
  8780. number: function () {
  8781. return compose(
  8782. omitNaN,
  8783. omitPositiveInfinity,
  8784. omitNegativeInfinity,
  8785. json(),
  8786. end()
  8787. );
  8788. },
  8789. newLike: function () {
  8790. return compose(
  8791. always('new '),
  8792. constructorName(),
  8793. always('('),
  8794. json(),
  8795. always(')'),
  8796. end()
  8797. );
  8798. },
  8799. array: function (predicate) {
  8800. return compose(
  8801. omitCircular,
  8802. omitMaxDepth,
  8803. decorateArray(),
  8804. arrayIndicesToKeys(),
  8805. filter(predicate),
  8806. iterate()
  8807. );
  8808. },
  8809. object: function (predicate, orderedWhiteList) {
  8810. return compose(
  8811. omitCircular,
  8812. omitMaxDepth,
  8813. constructorName(),
  8814. decorateObject(),
  8815. allowedKeys(orderedWhiteList),
  8816. safeKeys(),
  8817. filter(predicate),
  8818. iterate()
  8819. );
  8820. }
  8821. };
  8822. },{"core-js/library/fn/array/filter":6,"core-js/library/fn/array/for-each":7,"core-js/library/fn/array/index-of":8,"core-js/library/fn/array/reduce-right":11,"type-name":98}],97:[function(_dereq_,module,exports){
  8823. var traverse = module.exports = function (obj) {
  8824. return new Traverse(obj);
  8825. };
  8826. function Traverse (obj) {
  8827. this.value = obj;
  8828. }
  8829. Traverse.prototype.get = function (ps) {
  8830. var node = this.value;
  8831. for (var i = 0; i < ps.length; i ++) {
  8832. var key = ps[i];
  8833. if (!node || !hasOwnProperty.call(node, key)) {
  8834. node = undefined;
  8835. break;
  8836. }
  8837. node = node[key];
  8838. }
  8839. return node;
  8840. };
  8841. Traverse.prototype.has = function (ps) {
  8842. var node = this.value;
  8843. for (var i = 0; i < ps.length; i ++) {
  8844. var key = ps[i];
  8845. if (!node || !hasOwnProperty.call(node, key)) {
  8846. return false;
  8847. }
  8848. node = node[key];
  8849. }
  8850. return true;
  8851. };
  8852. Traverse.prototype.set = function (ps, value) {
  8853. var node = this.value;
  8854. for (var i = 0; i < ps.length - 1; i ++) {
  8855. var key = ps[i];
  8856. if (!hasOwnProperty.call(node, key)) node[key] = {};
  8857. node = node[key];
  8858. }
  8859. node[ps[i]] = value;
  8860. return value;
  8861. };
  8862. Traverse.prototype.map = function (cb) {
  8863. return walk(this.value, cb, true);
  8864. };
  8865. Traverse.prototype.forEach = function (cb) {
  8866. this.value = walk(this.value, cb, false);
  8867. return this.value;
  8868. };
  8869. Traverse.prototype.reduce = function (cb, init) {
  8870. var skip = arguments.length === 1;
  8871. var acc = skip ? this.value : init;
  8872. this.forEach(function (x) {
  8873. if (!this.isRoot || !skip) {
  8874. acc = cb.call(this, acc, x);
  8875. }
  8876. });
  8877. return acc;
  8878. };
  8879. Traverse.prototype.paths = function () {
  8880. var acc = [];
  8881. this.forEach(function (x) {
  8882. acc.push(this.path);
  8883. });
  8884. return acc;
  8885. };
  8886. Traverse.prototype.nodes = function () {
  8887. var acc = [];
  8888. this.forEach(function (x) {
  8889. acc.push(this.node);
  8890. });
  8891. return acc;
  8892. };
  8893. Traverse.prototype.clone = function () {
  8894. var parents = [], nodes = [];
  8895. return (function clone (src) {
  8896. for (var i = 0; i < parents.length; i++) {
  8897. if (parents[i] === src) {
  8898. return nodes[i];
  8899. }
  8900. }
  8901. if (typeof src === 'object' && src !== null) {
  8902. var dst = copy(src);
  8903. parents.push(src);
  8904. nodes.push(dst);
  8905. forEach(objectKeys(src), function (key) {
  8906. dst[key] = clone(src[key]);
  8907. });
  8908. parents.pop();
  8909. nodes.pop();
  8910. return dst;
  8911. }
  8912. else {
  8913. return src;
  8914. }
  8915. })(this.value);
  8916. };
  8917. function walk (root, cb, immutable) {
  8918. var path = [];
  8919. var parents = [];
  8920. var alive = true;
  8921. return (function walker (node_) {
  8922. var node = immutable ? copy(node_) : node_;
  8923. var modifiers = {};
  8924. var keepGoing = true;
  8925. var state = {
  8926. node : node,
  8927. node_ : node_,
  8928. path : [].concat(path),
  8929. parent : parents[parents.length - 1],
  8930. parents : parents,
  8931. key : path.slice(-1)[0],
  8932. isRoot : path.length === 0,
  8933. level : path.length,
  8934. circular : null,
  8935. update : function (x, stopHere) {
  8936. if (!state.isRoot) {
  8937. state.parent.node[state.key] = x;
  8938. }
  8939. state.node = x;
  8940. if (stopHere) keepGoing = false;
  8941. },
  8942. 'delete' : function (stopHere) {
  8943. delete state.parent.node[state.key];
  8944. if (stopHere) keepGoing = false;
  8945. },
  8946. remove : function (stopHere) {
  8947. if (isArray(state.parent.node)) {
  8948. state.parent.node.splice(state.key, 1);
  8949. }
  8950. else {
  8951. delete state.parent.node[state.key];
  8952. }
  8953. if (stopHere) keepGoing = false;
  8954. },
  8955. keys : null,
  8956. before : function (f) { modifiers.before = f },
  8957. after : function (f) { modifiers.after = f },
  8958. pre : function (f) { modifiers.pre = f },
  8959. post : function (f) { modifiers.post = f },
  8960. stop : function () { alive = false },
  8961. block : function () { keepGoing = false }
  8962. };
  8963. if (!alive) return state;
  8964. function updateState() {
  8965. if (typeof state.node === 'object' && state.node !== null) {
  8966. if (!state.keys || state.node_ !== state.node) {
  8967. state.keys = objectKeys(state.node)
  8968. }
  8969. state.isLeaf = state.keys.length == 0;
  8970. for (var i = 0; i < parents.length; i++) {
  8971. if (parents[i].node_ === node_) {
  8972. state.circular = parents[i];
  8973. break;
  8974. }
  8975. }
  8976. }
  8977. else {
  8978. state.isLeaf = true;
  8979. state.keys = null;
  8980. }
  8981. state.notLeaf = !state.isLeaf;
  8982. state.notRoot = !state.isRoot;
  8983. }
  8984. updateState();
  8985. // use return values to update if defined
  8986. var ret = cb.call(state, state.node);
  8987. if (ret !== undefined && state.update) state.update(ret);
  8988. if (modifiers.before) modifiers.before.call(state, state.node);
  8989. if (!keepGoing) return state;
  8990. if (typeof state.node == 'object'
  8991. && state.node !== null && !state.circular) {
  8992. parents.push(state);
  8993. updateState();
  8994. forEach(state.keys, function (key, i) {
  8995. path.push(key);
  8996. if (modifiers.pre) modifiers.pre.call(state, state.node[key], key);
  8997. var child = walker(state.node[key]);
  8998. if (immutable && hasOwnProperty.call(state.node, key)) {
  8999. state.node[key] = child.node;
  9000. }
  9001. child.isLast = i == state.keys.length - 1;
  9002. child.isFirst = i == 0;
  9003. if (modifiers.post) modifiers.post.call(state, child);
  9004. path.pop();
  9005. });
  9006. parents.pop();
  9007. }
  9008. if (modifiers.after) modifiers.after.call(state, state.node);
  9009. return state;
  9010. })(root).node;
  9011. }
  9012. function copy (src) {
  9013. if (typeof src === 'object' && src !== null) {
  9014. var dst;
  9015. if (isArray(src)) {
  9016. dst = [];
  9017. }
  9018. else if (isDate(src)) {
  9019. dst = new Date(src.getTime ? src.getTime() : src);
  9020. }
  9021. else if (isRegExp(src)) {
  9022. dst = new RegExp(src);
  9023. }
  9024. else if (isError(src)) {
  9025. dst = { message: src.message };
  9026. }
  9027. else if (isBoolean(src)) {
  9028. dst = new Boolean(src);
  9029. }
  9030. else if (isNumber(src)) {
  9031. dst = new Number(src);
  9032. }
  9033. else if (isString(src)) {
  9034. dst = new String(src);
  9035. }
  9036. else if (Object.create && Object.getPrototypeOf) {
  9037. dst = Object.create(Object.getPrototypeOf(src));
  9038. }
  9039. else if (src.constructor === Object) {
  9040. dst = {};
  9041. }
  9042. else {
  9043. var proto =
  9044. (src.constructor && src.constructor.prototype)
  9045. || src.__proto__
  9046. || {}
  9047. ;
  9048. var T = function () {};
  9049. T.prototype = proto;
  9050. dst = new T;
  9051. }
  9052. forEach(objectKeys(src), function (key) {
  9053. dst[key] = src[key];
  9054. });
  9055. return dst;
  9056. }
  9057. else return src;
  9058. }
  9059. var objectKeys = Object.keys || function keys (obj) {
  9060. var res = [];
  9061. for (var key in obj) res.push(key)
  9062. return res;
  9063. };
  9064. function toS (obj) { return Object.prototype.toString.call(obj) }
  9065. function isDate (obj) { return toS(obj) === '[object Date]' }
  9066. function isRegExp (obj) { return toS(obj) === '[object RegExp]' }
  9067. function isError (obj) { return toS(obj) === '[object Error]' }
  9068. function isBoolean (obj) { return toS(obj) === '[object Boolean]' }
  9069. function isNumber (obj) { return toS(obj) === '[object Number]' }
  9070. function isString (obj) { return toS(obj) === '[object String]' }
  9071. var isArray = Array.isArray || function isArray (xs) {
  9072. return Object.prototype.toString.call(xs) === '[object Array]';
  9073. };
  9074. var forEach = function (xs, fn) {
  9075. if (xs.forEach) return xs.forEach(fn)
  9076. else for (var i = 0; i < xs.length; i++) {
  9077. fn(xs[i], i, xs);
  9078. }
  9079. };
  9080. forEach(objectKeys(Traverse.prototype), function (key) {
  9081. traverse[key] = function (obj) {
  9082. var args = [].slice.call(arguments, 1);
  9083. var t = new Traverse(obj);
  9084. return t[key].apply(t, args);
  9085. };
  9086. });
  9087. var hasOwnProperty = Object.hasOwnProperty || function (obj, key) {
  9088. return key in obj;
  9089. };
  9090. },{}],98:[function(_dereq_,module,exports){
  9091. /**
  9092. * type-name - Just a reasonable typeof
  9093. *
  9094. * https://github.com/twada/type-name
  9095. *
  9096. * Copyright (c) 2014-2016 Takuto Wada
  9097. * Licensed under the MIT license.
  9098. * http://twada.mit-license.org/2014-2016
  9099. */
  9100. 'use strict';
  9101. var toStr = Object.prototype.toString;
  9102. function funcName (f) {
  9103. return f.name ? f.name : /^\s*function\s*([^\(]*)/im.exec(f.toString())[1];
  9104. }
  9105. function ctorName (obj) {
  9106. var strName = toStr.call(obj).slice(8, -1);
  9107. if ((strName === 'Object' || strName === 'Error') && obj.constructor) {
  9108. return funcName(obj.constructor);
  9109. }
  9110. return strName;
  9111. }
  9112. function typeName (val) {
  9113. var type;
  9114. if (val === null) {
  9115. return 'null';
  9116. }
  9117. type = typeof(val);
  9118. if (type === 'object') {
  9119. return ctorName(val);
  9120. }
  9121. return type;
  9122. }
  9123. module.exports = typeName;
  9124. },{}],99:[function(_dereq_,module,exports){
  9125. module.exports = function isBuffer(arg) {
  9126. return arg && typeof arg === 'object'
  9127. && typeof arg.copy === 'function'
  9128. && typeof arg.fill === 'function'
  9129. && typeof arg.readUInt8 === 'function';
  9130. }
  9131. },{}],100:[function(_dereq_,module,exports){
  9132. (function (process,global){
  9133. // Copyright Joyent, Inc. and other Node contributors.
  9134. //
  9135. // Permission is hereby granted, free of charge, to any person obtaining a
  9136. // copy of this software and associated documentation files (the
  9137. // "Software"), to deal in the Software without restriction, including
  9138. // without limitation the rights to use, copy, modify, merge, publish,
  9139. // distribute, sublicense, and/or sell copies of the Software, and to permit
  9140. // persons to whom the Software is furnished to do so, subject to the
  9141. // following conditions:
  9142. //
  9143. // The above copyright notice and this permission notice shall be included
  9144. // in all copies or substantial portions of the Software.
  9145. //
  9146. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  9147. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  9148. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  9149. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  9150. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  9151. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  9152. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  9153. var formatRegExp = /%[sdj%]/g;
  9154. exports.format = function(f) {
  9155. if (!isString(f)) {
  9156. var objects = [];
  9157. for (var i = 0; i < arguments.length; i++) {
  9158. objects.push(inspect(arguments[i]));
  9159. }
  9160. return objects.join(' ');
  9161. }
  9162. var i = 1;
  9163. var args = arguments;
  9164. var len = args.length;
  9165. var str = String(f).replace(formatRegExp, function(x) {
  9166. if (x === '%%') return '%';
  9167. if (i >= len) return x;
  9168. switch (x) {
  9169. case '%s': return String(args[i++]);
  9170. case '%d': return Number(args[i++]);
  9171. case '%j':
  9172. try {
  9173. return JSON.stringify(args[i++]);
  9174. } catch (_) {
  9175. return '[Circular]';
  9176. }
  9177. default:
  9178. return x;
  9179. }
  9180. });
  9181. for (var x = args[i]; i < len; x = args[++i]) {
  9182. if (isNull(x) || !isObject(x)) {
  9183. str += ' ' + x;
  9184. } else {
  9185. str += ' ' + inspect(x);
  9186. }
  9187. }
  9188. return str;
  9189. };
  9190. // Mark that a method should not be used.
  9191. // Returns a modified function which warns once by default.
  9192. // If --no-deprecation is set, then it is a no-op.
  9193. exports.deprecate = function(fn, msg) {
  9194. // Allow for deprecating things in the process of starting up.
  9195. if (isUndefined(global.process)) {
  9196. return function() {
  9197. return exports.deprecate(fn, msg).apply(this, arguments);
  9198. };
  9199. }
  9200. if (process.noDeprecation === true) {
  9201. return fn;
  9202. }
  9203. var warned = false;
  9204. function deprecated() {
  9205. if (!warned) {
  9206. if (process.throwDeprecation) {
  9207. throw new Error(msg);
  9208. } else if (process.traceDeprecation) {
  9209. console.trace(msg);
  9210. } else {
  9211. console.error(msg);
  9212. }
  9213. warned = true;
  9214. }
  9215. return fn.apply(this, arguments);
  9216. }
  9217. return deprecated;
  9218. };
  9219. var debugs = {};
  9220. var debugEnviron;
  9221. exports.debuglog = function(set) {
  9222. if (isUndefined(debugEnviron))
  9223. debugEnviron = process.env.NODE_DEBUG || '';
  9224. set = set.toUpperCase();
  9225. if (!debugs[set]) {
  9226. if (new RegExp('\\b' + set + '\\b', 'i').test(debugEnviron)) {
  9227. var pid = process.pid;
  9228. debugs[set] = function() {
  9229. var msg = exports.format.apply(exports, arguments);
  9230. console.error('%s %d: %s', set, pid, msg);
  9231. };
  9232. } else {
  9233. debugs[set] = function() {};
  9234. }
  9235. }
  9236. return debugs[set];
  9237. };
  9238. /**
  9239. * Echos the value of a value. Trys to print the value out
  9240. * in the best way possible given the different types.
  9241. *
  9242. * @param {Object} obj The object to print out.
  9243. * @param {Object} opts Optional options object that alters the output.
  9244. */
  9245. /* legacy: obj, showHidden, depth, colors*/
  9246. function inspect(obj, opts) {
  9247. // default options
  9248. var ctx = {
  9249. seen: [],
  9250. stylize: stylizeNoColor
  9251. };
  9252. // legacy...
  9253. if (arguments.length >= 3) ctx.depth = arguments[2];
  9254. if (arguments.length >= 4) ctx.colors = arguments[3];
  9255. if (isBoolean(opts)) {
  9256. // legacy...
  9257. ctx.showHidden = opts;
  9258. } else if (opts) {
  9259. // got an "options" object
  9260. exports._extend(ctx, opts);
  9261. }
  9262. // set default options
  9263. if (isUndefined(ctx.showHidden)) ctx.showHidden = false;
  9264. if (isUndefined(ctx.depth)) ctx.depth = 2;
  9265. if (isUndefined(ctx.colors)) ctx.colors = false;
  9266. if (isUndefined(ctx.customInspect)) ctx.customInspect = true;
  9267. if (ctx.colors) ctx.stylize = stylizeWithColor;
  9268. return formatValue(ctx, obj, ctx.depth);
  9269. }
  9270. exports.inspect = inspect;
  9271. // http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
  9272. inspect.colors = {
  9273. 'bold' : [1, 22],
  9274. 'italic' : [3, 23],
  9275. 'underline' : [4, 24],
  9276. 'inverse' : [7, 27],
  9277. 'white' : [37, 39],
  9278. 'grey' : [90, 39],
  9279. 'black' : [30, 39],
  9280. 'blue' : [34, 39],
  9281. 'cyan' : [36, 39],
  9282. 'green' : [32, 39],
  9283. 'magenta' : [35, 39],
  9284. 'red' : [31, 39],
  9285. 'yellow' : [33, 39]
  9286. };
  9287. // Don't use 'blue' not visible on cmd.exe
  9288. inspect.styles = {
  9289. 'special': 'cyan',
  9290. 'number': 'yellow',
  9291. 'boolean': 'yellow',
  9292. 'undefined': 'grey',
  9293. 'null': 'bold',
  9294. 'string': 'green',
  9295. 'date': 'magenta',
  9296. // "name": intentionally not styling
  9297. 'regexp': 'red'
  9298. };
  9299. function stylizeWithColor(str, styleType) {
  9300. var style = inspect.styles[styleType];
  9301. if (style) {
  9302. return '\u001b[' + inspect.colors[style][0] + 'm' + str +
  9303. '\u001b[' + inspect.colors[style][1] + 'm';
  9304. } else {
  9305. return str;
  9306. }
  9307. }
  9308. function stylizeNoColor(str, styleType) {
  9309. return str;
  9310. }
  9311. function arrayToHash(array) {
  9312. var hash = {};
  9313. array.forEach(function(val, idx) {
  9314. hash[val] = true;
  9315. });
  9316. return hash;
  9317. }
  9318. function formatValue(ctx, value, recurseTimes) {
  9319. // Provide a hook for user-specified inspect functions.
  9320. // Check that value is an object with an inspect function on it
  9321. if (ctx.customInspect &&
  9322. value &&
  9323. isFunction(value.inspect) &&
  9324. // Filter out the util module, it's inspect function is special
  9325. value.inspect !== exports.inspect &&
  9326. // Also filter out any prototype objects using the circular check.
  9327. !(value.constructor && value.constructor.prototype === value)) {
  9328. var ret = value.inspect(recurseTimes, ctx);
  9329. if (!isString(ret)) {
  9330. ret = formatValue(ctx, ret, recurseTimes);
  9331. }
  9332. return ret;
  9333. }
  9334. // Primitive types cannot have properties
  9335. var primitive = formatPrimitive(ctx, value);
  9336. if (primitive) {
  9337. return primitive;
  9338. }
  9339. // Look up the keys of the object.
  9340. var keys = Object.keys(value);
  9341. var visibleKeys = arrayToHash(keys);
  9342. if (ctx.showHidden) {
  9343. keys = Object.getOwnPropertyNames(value);
  9344. }
  9345. // IE doesn't make error fields non-enumerable
  9346. // http://msdn.microsoft.com/en-us/library/ie/dww52sbt(v=vs.94).aspx
  9347. if (isError(value)
  9348. && (keys.indexOf('message') >= 0 || keys.indexOf('description') >= 0)) {
  9349. return formatError(value);
  9350. }
  9351. // Some type of object without properties can be shortcutted.
  9352. if (keys.length === 0) {
  9353. if (isFunction(value)) {
  9354. var name = value.name ? ': ' + value.name : '';
  9355. return ctx.stylize('[Function' + name + ']', 'special');
  9356. }
  9357. if (isRegExp(value)) {
  9358. return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
  9359. }
  9360. if (isDate(value)) {
  9361. return ctx.stylize(Date.prototype.toString.call(value), 'date');
  9362. }
  9363. if (isError(value)) {
  9364. return formatError(value);
  9365. }
  9366. }
  9367. var base = '', array = false, braces = ['{', '}'];
  9368. // Make Array say that they are Array
  9369. if (isArray(value)) {
  9370. array = true;
  9371. braces = ['[', ']'];
  9372. }
  9373. // Make functions say that they are functions
  9374. if (isFunction(value)) {
  9375. var n = value.name ? ': ' + value.name : '';
  9376. base = ' [Function' + n + ']';
  9377. }
  9378. // Make RegExps say that they are RegExps
  9379. if (isRegExp(value)) {
  9380. base = ' ' + RegExp.prototype.toString.call(value);
  9381. }
  9382. // Make dates with properties first say the date
  9383. if (isDate(value)) {
  9384. base = ' ' + Date.prototype.toUTCString.call(value);
  9385. }
  9386. // Make error with message first say the error
  9387. if (isError(value)) {
  9388. base = ' ' + formatError(value);
  9389. }
  9390. if (keys.length === 0 && (!array || value.length == 0)) {
  9391. return braces[0] + base + braces[1];
  9392. }
  9393. if (recurseTimes < 0) {
  9394. if (isRegExp(value)) {
  9395. return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
  9396. } else {
  9397. return ctx.stylize('[Object]', 'special');
  9398. }
  9399. }
  9400. ctx.seen.push(value);
  9401. var output;
  9402. if (array) {
  9403. output = formatArray(ctx, value, recurseTimes, visibleKeys, keys);
  9404. } else {
  9405. output = keys.map(function(key) {
  9406. return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array);
  9407. });
  9408. }
  9409. ctx.seen.pop();
  9410. return reduceToSingleString(output, base, braces);
  9411. }
  9412. function formatPrimitive(ctx, value) {
  9413. if (isUndefined(value))
  9414. return ctx.stylize('undefined', 'undefined');
  9415. if (isString(value)) {
  9416. var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '')
  9417. .replace(/'/g, "\\'")
  9418. .replace(/\\"/g, '"') + '\'';
  9419. return ctx.stylize(simple, 'string');
  9420. }
  9421. if (isNumber(value))
  9422. return ctx.stylize('' + value, 'number');
  9423. if (isBoolean(value))
  9424. return ctx.stylize('' + value, 'boolean');
  9425. // For some reason typeof null is "object", so special case here.
  9426. if (isNull(value))
  9427. return ctx.stylize('null', 'null');
  9428. }
  9429. function formatError(value) {
  9430. return '[' + Error.prototype.toString.call(value) + ']';
  9431. }
  9432. function formatArray(ctx, value, recurseTimes, visibleKeys, keys) {
  9433. var output = [];
  9434. for (var i = 0, l = value.length; i < l; ++i) {
  9435. if (hasOwnProperty(value, String(i))) {
  9436. output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
  9437. String(i), true));
  9438. } else {
  9439. output.push('');
  9440. }
  9441. }
  9442. keys.forEach(function(key) {
  9443. if (!key.match(/^\d+$/)) {
  9444. output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
  9445. key, true));
  9446. }
  9447. });
  9448. return output;
  9449. }
  9450. function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {
  9451. var name, str, desc;
  9452. desc = Object.getOwnPropertyDescriptor(value, key) || { value: value[key] };
  9453. if (desc.get) {
  9454. if (desc.set) {
  9455. str = ctx.stylize('[Getter/Setter]', 'special');
  9456. } else {
  9457. str = ctx.stylize('[Getter]', 'special');
  9458. }
  9459. } else {
  9460. if (desc.set) {
  9461. str = ctx.stylize('[Setter]', 'special');
  9462. }
  9463. }
  9464. if (!hasOwnProperty(visibleKeys, key)) {
  9465. name = '[' + key + ']';
  9466. }
  9467. if (!str) {
  9468. if (ctx.seen.indexOf(desc.value) < 0) {
  9469. if (isNull(recurseTimes)) {
  9470. str = formatValue(ctx, desc.value, null);
  9471. } else {
  9472. str = formatValue(ctx, desc.value, recurseTimes - 1);
  9473. }
  9474. if (str.indexOf('\n') > -1) {
  9475. if (array) {
  9476. str = str.split('\n').map(function(line) {
  9477. return ' ' + line;
  9478. }).join('\n').substr(2);
  9479. } else {
  9480. str = '\n' + str.split('\n').map(function(line) {
  9481. return ' ' + line;
  9482. }).join('\n');
  9483. }
  9484. }
  9485. } else {
  9486. str = ctx.stylize('[Circular]', 'special');
  9487. }
  9488. }
  9489. if (isUndefined(name)) {
  9490. if (array && key.match(/^\d+$/)) {
  9491. return str;
  9492. }
  9493. name = JSON.stringify('' + key);
  9494. if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
  9495. name = name.substr(1, name.length - 2);
  9496. name = ctx.stylize(name, 'name');
  9497. } else {
  9498. name = name.replace(/'/g, "\\'")
  9499. .replace(/\\"/g, '"')
  9500. .replace(/(^"|"$)/g, "'");
  9501. name = ctx.stylize(name, 'string');
  9502. }
  9503. }
  9504. return name + ': ' + str;
  9505. }
  9506. function reduceToSingleString(output, base, braces) {
  9507. var numLinesEst = 0;
  9508. var length = output.reduce(function(prev, cur) {
  9509. numLinesEst++;
  9510. if (cur.indexOf('\n') >= 0) numLinesEst++;
  9511. return prev + cur.replace(/\u001b\[\d\d?m/g, '').length + 1;
  9512. }, 0);
  9513. if (length > 60) {
  9514. return braces[0] +
  9515. (base === '' ? '' : base + '\n ') +
  9516. ' ' +
  9517. output.join(',\n ') +
  9518. ' ' +
  9519. braces[1];
  9520. }
  9521. return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
  9522. }
  9523. // NOTE: These type checking functions intentionally don't use `instanceof`
  9524. // because it is fragile and can be easily faked with `Object.create()`.
  9525. function isArray(ar) {
  9526. return Array.isArray(ar);
  9527. }
  9528. exports.isArray = isArray;
  9529. function isBoolean(arg) {
  9530. return typeof arg === 'boolean';
  9531. }
  9532. exports.isBoolean = isBoolean;
  9533. function isNull(arg) {
  9534. return arg === null;
  9535. }
  9536. exports.isNull = isNull;
  9537. function isNullOrUndefined(arg) {
  9538. return arg == null;
  9539. }
  9540. exports.isNullOrUndefined = isNullOrUndefined;
  9541. function isNumber(arg) {
  9542. return typeof arg === 'number';
  9543. }
  9544. exports.isNumber = isNumber;
  9545. function isString(arg) {
  9546. return typeof arg === 'string';
  9547. }
  9548. exports.isString = isString;
  9549. function isSymbol(arg) {
  9550. return typeof arg === 'symbol';
  9551. }
  9552. exports.isSymbol = isSymbol;
  9553. function isUndefined(arg) {
  9554. return arg === void 0;
  9555. }
  9556. exports.isUndefined = isUndefined;
  9557. function isRegExp(re) {
  9558. return isObject(re) && objectToString(re) === '[object RegExp]';
  9559. }
  9560. exports.isRegExp = isRegExp;
  9561. function isObject(arg) {
  9562. return typeof arg === 'object' && arg !== null;
  9563. }
  9564. exports.isObject = isObject;
  9565. function isDate(d) {
  9566. return isObject(d) && objectToString(d) === '[object Date]';
  9567. }
  9568. exports.isDate = isDate;
  9569. function isError(e) {
  9570. return isObject(e) &&
  9571. (objectToString(e) === '[object Error]' || e instanceof Error);
  9572. }
  9573. exports.isError = isError;
  9574. function isFunction(arg) {
  9575. return typeof arg === 'function';
  9576. }
  9577. exports.isFunction = isFunction;
  9578. function isPrimitive(arg) {
  9579. return arg === null ||
  9580. typeof arg === 'boolean' ||
  9581. typeof arg === 'number' ||
  9582. typeof arg === 'string' ||
  9583. typeof arg === 'symbol' || // ES6 symbol
  9584. typeof arg === 'undefined';
  9585. }
  9586. exports.isPrimitive = isPrimitive;
  9587. exports.isBuffer = _dereq_('./support/isBuffer');
  9588. function objectToString(o) {
  9589. return Object.prototype.toString.call(o);
  9590. }
  9591. function pad(n) {
  9592. return n < 10 ? '0' + n.toString(10) : n.toString(10);
  9593. }
  9594. var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep',
  9595. 'Oct', 'Nov', 'Dec'];
  9596. // 26 Feb 16:19:34
  9597. function timestamp() {
  9598. var d = new Date();
  9599. var time = [pad(d.getHours()),
  9600. pad(d.getMinutes()),
  9601. pad(d.getSeconds())].join(':');
  9602. return [d.getDate(), months[d.getMonth()], time].join(' ');
  9603. }
  9604. // log is just a thin wrapper to console.log that prepends a timestamp
  9605. exports.log = function() {
  9606. console.log('%s - %s', timestamp(), exports.format.apply(exports, arguments));
  9607. };
  9608. /**
  9609. * Inherit the prototype methods from one constructor into another.
  9610. *
  9611. * The Function.prototype.inherits from lang.js rewritten as a standalone
  9612. * function (not on Function.prototype). NOTE: If this file is to be loaded
  9613. * during bootstrapping this function needs to be rewritten using some native
  9614. * functions as prototype setup using normal JavaScript does not work as
  9615. * expected during bootstrapping (see mirror.js in r114903).
  9616. *
  9617. * @param {function} ctor Constructor function which needs to inherit the
  9618. * prototype.
  9619. * @param {function} superCtor Constructor function to inherit prototype from.
  9620. */
  9621. exports.inherits = _dereq_('inherits');
  9622. exports._extend = function(origin, add) {
  9623. // Don't do anything if add isn't an object
  9624. if (!add || !isObject(add)) return origin;
  9625. var keys = Object.keys(add);
  9626. var i = keys.length;
  9627. while (i--) {
  9628. origin[keys[i]] = add[keys[i]];
  9629. }
  9630. return origin;
  9631. };
  9632. function hasOwnProperty(obj, prop) {
  9633. return Object.prototype.hasOwnProperty.call(obj, prop);
  9634. }
  9635. }).call(this,_dereq_('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  9636. },{"./support/isBuffer":99,"_process":94,"inherits":75}]},{},[1])(1)
  9637. });