Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

nunjucks.js 214KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423
  1. /*! Browser bundle of nunjucks 3.2.3 */
  2. (function webpackUniversalModuleDefinition(root, factory) {
  3. if(typeof exports === 'object' && typeof module === 'object')
  4. module.exports = factory();
  5. else if(typeof define === 'function' && define.amd)
  6. define([], factory);
  7. else if(typeof exports === 'object')
  8. exports["nunjucks"] = factory();
  9. else
  10. root["nunjucks"] = factory();
  11. })(typeof self !== 'undefined' ? self : this, function() {
  12. return /******/ (function(modules) { // webpackBootstrap
  13. /******/ // The module cache
  14. /******/ var installedModules = {};
  15. /******/
  16. /******/ // The require function
  17. /******/ function __webpack_require__(moduleId) {
  18. /******/
  19. /******/ // Check if module is in cache
  20. /******/ if(installedModules[moduleId]) {
  21. /******/ return installedModules[moduleId].exports;
  22. /******/ }
  23. /******/ // Create a new module (and put it into the cache)
  24. /******/ var module = installedModules[moduleId] = {
  25. /******/ i: moduleId,
  26. /******/ l: false,
  27. /******/ exports: {}
  28. /******/ };
  29. /******/
  30. /******/ // Execute the module function
  31. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  32. /******/
  33. /******/ // Flag the module as loaded
  34. /******/ module.l = true;
  35. /******/
  36. /******/ // Return the exports of the module
  37. /******/ return module.exports;
  38. /******/ }
  39. /******/
  40. /******/
  41. /******/ // expose the modules object (__webpack_modules__)
  42. /******/ __webpack_require__.m = modules;
  43. /******/
  44. /******/ // expose the module cache
  45. /******/ __webpack_require__.c = installedModules;
  46. /******/
  47. /******/ // define getter function for harmony exports
  48. /******/ __webpack_require__.d = function(exports, name, getter) {
  49. /******/ if(!__webpack_require__.o(exports, name)) {
  50. /******/ Object.defineProperty(exports, name, {
  51. /******/ configurable: false,
  52. /******/ enumerable: true,
  53. /******/ get: getter
  54. /******/ });
  55. /******/ }
  56. /******/ };
  57. /******/
  58. /******/ // getDefaultExport function for compatibility with non-harmony modules
  59. /******/ __webpack_require__.n = function(module) {
  60. /******/ var getter = module && module.__esModule ?
  61. /******/ function getDefault() { return module['default']; } :
  62. /******/ function getModuleExports() { return module; };
  63. /******/ __webpack_require__.d(getter, 'a', getter);
  64. /******/ return getter;
  65. /******/ };
  66. /******/
  67. /******/ // Object.prototype.hasOwnProperty.call
  68. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  69. /******/
  70. /******/ // __webpack_public_path__
  71. /******/ __webpack_require__.p = "";
  72. /******/
  73. /******/ // Load entry module and return exports
  74. /******/ return __webpack_require__(__webpack_require__.s = 11);
  75. /******/ })
  76. /************************************************************************/
  77. /******/ ([
  78. /* 0 */
  79. /***/ (function(module, exports, __webpack_require__) {
  80. "use strict";
  81. var ArrayProto = Array.prototype;
  82. var ObjProto = Object.prototype;
  83. var escapeMap = {
  84. '&': '&',
  85. '"': '"',
  86. '\'': ''',
  87. '<': '&lt;',
  88. '>': '&gt;'
  89. };
  90. var escapeRegex = /[&"'<>]/g;
  91. var exports = module.exports = {};
  92. function hasOwnProp(obj, k) {
  93. return ObjProto.hasOwnProperty.call(obj, k);
  94. }
  95. exports.hasOwnProp = hasOwnProp;
  96. function lookupEscape(ch) {
  97. return escapeMap[ch];
  98. }
  99. function _prettifyError(path, withInternals, err) {
  100. if (!err.Update) {
  101. // not one of ours, cast it
  102. err = new exports.TemplateError(err);
  103. }
  104. err.Update(path); // Unless they marked the dev flag, show them a trace from here
  105. if (!withInternals) {
  106. var old = err;
  107. err = new Error(old.message);
  108. err.name = old.name;
  109. }
  110. return err;
  111. }
  112. exports._prettifyError = _prettifyError;
  113. function TemplateError(message, lineno, colno) {
  114. var err;
  115. var cause;
  116. if (message instanceof Error) {
  117. cause = message;
  118. message = cause.name + ": " + cause.message;
  119. }
  120. if (Object.setPrototypeOf) {
  121. err = new Error(message);
  122. Object.setPrototypeOf(err, TemplateError.prototype);
  123. } else {
  124. err = this;
  125. Object.defineProperty(err, 'message', {
  126. enumerable: false,
  127. writable: true,
  128. value: message
  129. });
  130. }
  131. Object.defineProperty(err, 'name', {
  132. value: 'Template render error'
  133. });
  134. if (Error.captureStackTrace) {
  135. Error.captureStackTrace(err, this.constructor);
  136. }
  137. var getStack;
  138. if (cause) {
  139. var stackDescriptor = Object.getOwnPropertyDescriptor(cause, 'stack');
  140. getStack = stackDescriptor && (stackDescriptor.get || function () {
  141. return stackDescriptor.value;
  142. });
  143. if (!getStack) {
  144. getStack = function getStack() {
  145. return cause.stack;
  146. };
  147. }
  148. } else {
  149. var stack = new Error(message).stack;
  150. getStack = function getStack() {
  151. return stack;
  152. };
  153. }
  154. Object.defineProperty(err, 'stack', {
  155. get: function get() {
  156. return getStack.call(err);
  157. }
  158. });
  159. Object.defineProperty(err, 'cause', {
  160. value: cause
  161. });
  162. err.lineno = lineno;
  163. err.colno = colno;
  164. err.firstUpdate = true;
  165. err.Update = function Update(path) {
  166. var msg = '(' + (path || 'unknown path') + ')'; // only show lineno + colno next to path of template
  167. // where error occurred
  168. if (this.firstUpdate) {
  169. if (this.lineno && this.colno) {
  170. msg += " [Line " + this.lineno + ", Column " + this.colno + "]";
  171. } else if (this.lineno) {
  172. msg += " [Line " + this.lineno + "]";
  173. }
  174. }
  175. msg += '\n ';
  176. if (this.firstUpdate) {
  177. msg += ' ';
  178. }
  179. this.message = msg + (this.message || '');
  180. this.firstUpdate = false;
  181. return this;
  182. };
  183. return err;
  184. }
  185. if (Object.setPrototypeOf) {
  186. Object.setPrototypeOf(TemplateError.prototype, Error.prototype);
  187. } else {
  188. TemplateError.prototype = Object.create(Error.prototype, {
  189. constructor: {
  190. value: TemplateError
  191. }
  192. });
  193. }
  194. exports.TemplateError = TemplateError;
  195. function escape(val) {
  196. return val.replace(escapeRegex, lookupEscape);
  197. }
  198. exports.escape = escape;
  199. function isFunction(obj) {
  200. return ObjProto.toString.call(obj) === '[object Function]';
  201. }
  202. exports.isFunction = isFunction;
  203. function isArray(obj) {
  204. return ObjProto.toString.call(obj) === '[object Array]';
  205. }
  206. exports.isArray = isArray;
  207. function isString(obj) {
  208. return ObjProto.toString.call(obj) === '[object String]';
  209. }
  210. exports.isString = isString;
  211. function isObject(obj) {
  212. return ObjProto.toString.call(obj) === '[object Object]';
  213. }
  214. exports.isObject = isObject;
  215. /**
  216. * @param {string|number} attr
  217. * @returns {(string|number)[]}
  218. * @private
  219. */
  220. function _prepareAttributeParts(attr) {
  221. if (!attr) {
  222. return [];
  223. }
  224. if (typeof attr === 'string') {
  225. return attr.split('.');
  226. }
  227. return [attr];
  228. }
  229. /**
  230. * @param {string} attribute Attribute value. Dots allowed.
  231. * @returns {function(Object): *}
  232. */
  233. function getAttrGetter(attribute) {
  234. var parts = _prepareAttributeParts(attribute);
  235. return function attrGetter(item) {
  236. var _item = item;
  237. for (var i = 0; i < parts.length; i++) {
  238. var part = parts[i]; // If item is not an object, and we still got parts to handle, it means
  239. // that something goes wrong. Just roll out to undefined in that case.
  240. if (hasOwnProp(_item, part)) {
  241. _item = _item[part];
  242. } else {
  243. return undefined;
  244. }
  245. }
  246. return _item;
  247. };
  248. }
  249. exports.getAttrGetter = getAttrGetter;
  250. function groupBy(obj, val, throwOnUndefined) {
  251. var result = {};
  252. var iterator = isFunction(val) ? val : getAttrGetter(val);
  253. for (var i = 0; i < obj.length; i++) {
  254. var value = obj[i];
  255. var key = iterator(value, i);
  256. if (key === undefined && throwOnUndefined === true) {
  257. throw new TypeError("groupby: attribute \"" + val + "\" resolved to undefined");
  258. }
  259. (result[key] || (result[key] = [])).push(value);
  260. }
  261. return result;
  262. }
  263. exports.groupBy = groupBy;
  264. function toArray(obj) {
  265. return Array.prototype.slice.call(obj);
  266. }
  267. exports.toArray = toArray;
  268. function without(array) {
  269. var result = [];
  270. if (!array) {
  271. return result;
  272. }
  273. var length = array.length;
  274. var contains = toArray(arguments).slice(1);
  275. var index = -1;
  276. while (++index < length) {
  277. if (indexOf(contains, array[index]) === -1) {
  278. result.push(array[index]);
  279. }
  280. }
  281. return result;
  282. }
  283. exports.without = without;
  284. function repeat(char_, n) {
  285. var str = '';
  286. for (var i = 0; i < n; i++) {
  287. str += char_;
  288. }
  289. return str;
  290. }
  291. exports.repeat = repeat;
  292. function each(obj, func, context) {
  293. if (obj == null) {
  294. return;
  295. }
  296. if (ArrayProto.forEach && obj.forEach === ArrayProto.forEach) {
  297. obj.forEach(func, context);
  298. } else if (obj.length === +obj.length) {
  299. for (var i = 0, l = obj.length; i < l; i++) {
  300. func.call(context, obj[i], i, obj);
  301. }
  302. }
  303. }
  304. exports.each = each;
  305. function map(obj, func) {
  306. var results = [];
  307. if (obj == null) {
  308. return results;
  309. }
  310. if (ArrayProto.map && obj.map === ArrayProto.map) {
  311. return obj.map(func);
  312. }
  313. for (var i = 0; i < obj.length; i++) {
  314. results[results.length] = func(obj[i], i);
  315. }
  316. if (obj.length === +obj.length) {
  317. results.length = obj.length;
  318. }
  319. return results;
  320. }
  321. exports.map = map;
  322. function asyncIter(arr, iter, cb) {
  323. var i = -1;
  324. function next() {
  325. i++;
  326. if (i < arr.length) {
  327. iter(arr[i], i, next, cb);
  328. } else {
  329. cb();
  330. }
  331. }
  332. next();
  333. }
  334. exports.asyncIter = asyncIter;
  335. function asyncFor(obj, iter, cb) {
  336. var keys = keys_(obj || {});
  337. var len = keys.length;
  338. var i = -1;
  339. function next() {
  340. i++;
  341. var k = keys[i];
  342. if (i < len) {
  343. iter(k, obj[k], i, len, next);
  344. } else {
  345. cb();
  346. }
  347. }
  348. next();
  349. }
  350. exports.asyncFor = asyncFor;
  351. function indexOf(arr, searchElement, fromIndex) {
  352. return Array.prototype.indexOf.call(arr || [], searchElement, fromIndex);
  353. }
  354. exports.indexOf = indexOf;
  355. function keys_(obj) {
  356. /* eslint-disable no-restricted-syntax */
  357. var arr = [];
  358. for (var k in obj) {
  359. if (hasOwnProp(obj, k)) {
  360. arr.push(k);
  361. }
  362. }
  363. return arr;
  364. }
  365. exports.keys = keys_;
  366. function _entries(obj) {
  367. return keys_(obj).map(function (k) {
  368. return [k, obj[k]];
  369. });
  370. }
  371. exports._entries = _entries;
  372. function _values(obj) {
  373. return keys_(obj).map(function (k) {
  374. return obj[k];
  375. });
  376. }
  377. exports._values = _values;
  378. function extend(obj1, obj2) {
  379. obj1 = obj1 || {};
  380. keys_(obj2).forEach(function (k) {
  381. obj1[k] = obj2[k];
  382. });
  383. return obj1;
  384. }
  385. exports._assign = exports.extend = extend;
  386. function inOperator(key, val) {
  387. if (isArray(val) || isString(val)) {
  388. return val.indexOf(key) !== -1;
  389. } else if (isObject(val)) {
  390. return key in val;
  391. }
  392. throw new Error('Cannot use "in" operator to search for "' + key + '" in unexpected types.');
  393. }
  394. exports.inOperator = inOperator;
  395. /***/ }),
  396. /* 1 */
  397. /***/ (function(module, exports, __webpack_require__) {
  398. "use strict";
  399. // A simple class system, more documentation to come
  400. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  401. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  402. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  403. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  404. var EventEmitter = __webpack_require__(16);
  405. var lib = __webpack_require__(0);
  406. function parentWrap(parent, prop) {
  407. if (typeof parent !== 'function' || typeof prop !== 'function') {
  408. return prop;
  409. }
  410. return function wrap() {
  411. // Save the current parent method
  412. var tmp = this.parent; // Set parent to the previous method, call, and restore
  413. this.parent = parent;
  414. var res = prop.apply(this, arguments);
  415. this.parent = tmp;
  416. return res;
  417. };
  418. }
  419. function extendClass(cls, name, props) {
  420. props = props || {};
  421. lib.keys(props).forEach(function (k) {
  422. props[k] = parentWrap(cls.prototype[k], props[k]);
  423. });
  424. var subclass = /*#__PURE__*/function (_cls) {
  425. _inheritsLoose(subclass, _cls);
  426. function subclass() {
  427. return _cls.apply(this, arguments) || this;
  428. }
  429. _createClass(subclass, [{
  430. key: "typename",
  431. get: function get() {
  432. return name;
  433. }
  434. }]);
  435. return subclass;
  436. }(cls);
  437. lib._assign(subclass.prototype, props);
  438. return subclass;
  439. }
  440. var Obj = /*#__PURE__*/function () {
  441. function Obj() {
  442. // Unfortunately necessary for backwards compatibility
  443. this.init.apply(this, arguments);
  444. }
  445. var _proto = Obj.prototype;
  446. _proto.init = function init() {};
  447. Obj.extend = function extend(name, props) {
  448. if (typeof name === 'object') {
  449. props = name;
  450. name = 'anonymous';
  451. }
  452. return extendClass(this, name, props);
  453. };
  454. _createClass(Obj, [{
  455. key: "typename",
  456. get: function get() {
  457. return this.constructor.name;
  458. }
  459. }]);
  460. return Obj;
  461. }();
  462. var EmitterObj = /*#__PURE__*/function (_EventEmitter) {
  463. _inheritsLoose(EmitterObj, _EventEmitter);
  464. function EmitterObj() {
  465. var _this2;
  466. var _this;
  467. _this = _EventEmitter.call(this) || this; // Unfortunately necessary for backwards compatibility
  468. (_this2 = _this).init.apply(_this2, arguments);
  469. return _this;
  470. }
  471. var _proto2 = EmitterObj.prototype;
  472. _proto2.init = function init() {};
  473. EmitterObj.extend = function extend(name, props) {
  474. if (typeof name === 'object') {
  475. props = name;
  476. name = 'anonymous';
  477. }
  478. return extendClass(this, name, props);
  479. };
  480. _createClass(EmitterObj, [{
  481. key: "typename",
  482. get: function get() {
  483. return this.constructor.name;
  484. }
  485. }]);
  486. return EmitterObj;
  487. }(EventEmitter);
  488. module.exports = {
  489. Obj: Obj,
  490. EmitterObj: EmitterObj
  491. };
  492. /***/ }),
  493. /* 2 */
  494. /***/ (function(module, exports, __webpack_require__) {
  495. "use strict";
  496. var lib = __webpack_require__(0);
  497. var arrayFrom = Array.from;
  498. var supportsIterators = typeof Symbol === 'function' && Symbol.iterator && typeof arrayFrom === 'function'; // Frames keep track of scoping both at compile-time and run-time so
  499. // we know how to access variables. Block tags can introduce special
  500. // variables, for example.
  501. var Frame = /*#__PURE__*/function () {
  502. function Frame(parent, isolateWrites) {
  503. this.variables = Object.create(null);
  504. this.parent = parent;
  505. this.topLevel = false; // if this is true, writes (set) should never propagate upwards past
  506. // this frame to its parent (though reads may).
  507. this.isolateWrites = isolateWrites;
  508. }
  509. var _proto = Frame.prototype;
  510. _proto.set = function set(name, val, resolveUp) {
  511. // Allow variables with dots by automatically creating the
  512. // nested structure
  513. var parts = name.split('.');
  514. var obj = this.variables;
  515. var frame = this;
  516. if (resolveUp) {
  517. if (frame = this.resolve(parts[0], true)) {
  518. frame.set(name, val);
  519. return;
  520. }
  521. }
  522. for (var i = 0; i < parts.length - 1; i++) {
  523. var id = parts[i];
  524. if (!obj[id]) {
  525. obj[id] = {};
  526. }
  527. obj = obj[id];
  528. }
  529. obj[parts[parts.length - 1]] = val;
  530. };
  531. _proto.get = function get(name) {
  532. var val = this.variables[name];
  533. if (val !== undefined) {
  534. return val;
  535. }
  536. return null;
  537. };
  538. _proto.lookup = function lookup(name) {
  539. var p = this.parent;
  540. var val = this.variables[name];
  541. if (val !== undefined) {
  542. return val;
  543. }
  544. return p && p.lookup(name);
  545. };
  546. _proto.resolve = function resolve(name, forWrite) {
  547. var p = forWrite && this.isolateWrites ? undefined : this.parent;
  548. var val = this.variables[name];
  549. if (val !== undefined) {
  550. return this;
  551. }
  552. return p && p.resolve(name);
  553. };
  554. _proto.push = function push(isolateWrites) {
  555. return new Frame(this, isolateWrites);
  556. };
  557. _proto.pop = function pop() {
  558. return this.parent;
  559. };
  560. return Frame;
  561. }();
  562. function makeMacro(argNames, kwargNames, func) {
  563. return function macro() {
  564. for (var _len = arguments.length, macroArgs = new Array(_len), _key = 0; _key < _len; _key++) {
  565. macroArgs[_key] = arguments[_key];
  566. }
  567. var argCount = numArgs(macroArgs);
  568. var args;
  569. var kwargs = getKeywordArgs(macroArgs);
  570. if (argCount > argNames.length) {
  571. args = macroArgs.slice(0, argNames.length); // Positional arguments that should be passed in as
  572. // keyword arguments (essentially default values)
  573. macroArgs.slice(args.length, argCount).forEach(function (val, i) {
  574. if (i < kwargNames.length) {
  575. kwargs[kwargNames[i]] = val;
  576. }
  577. });
  578. args.push(kwargs);
  579. } else if (argCount < argNames.length) {
  580. args = macroArgs.slice(0, argCount);
  581. for (var i = argCount; i < argNames.length; i++) {
  582. var arg = argNames[i]; // Keyword arguments that should be passed as
  583. // positional arguments, i.e. the caller explicitly
  584. // used the name of a positional arg
  585. args.push(kwargs[arg]);
  586. delete kwargs[arg];
  587. }
  588. args.push(kwargs);
  589. } else {
  590. args = macroArgs;
  591. }
  592. return func.apply(this, args);
  593. };
  594. }
  595. function makeKeywordArgs(obj) {
  596. obj.__keywords = true;
  597. return obj;
  598. }
  599. function isKeywordArgs(obj) {
  600. return obj && Object.prototype.hasOwnProperty.call(obj, '__keywords');
  601. }
  602. function getKeywordArgs(args) {
  603. var len = args.length;
  604. if (len) {
  605. var lastArg = args[len - 1];
  606. if (isKeywordArgs(lastArg)) {
  607. return lastArg;
  608. }
  609. }
  610. return {};
  611. }
  612. function numArgs(args) {
  613. var len = args.length;
  614. if (len === 0) {
  615. return 0;
  616. }
  617. var lastArg = args[len - 1];
  618. if (isKeywordArgs(lastArg)) {
  619. return len - 1;
  620. } else {
  621. return len;
  622. }
  623. } // A SafeString object indicates that the string should not be
  624. // autoescaped. This happens magically because autoescaping only
  625. // occurs on primitive string objects.
  626. function SafeString(val) {
  627. if (typeof val !== 'string') {
  628. return val;
  629. }
  630. this.val = val;
  631. this.length = val.length;
  632. }
  633. SafeString.prototype = Object.create(String.prototype, {
  634. length: {
  635. writable: true,
  636. configurable: true,
  637. value: 0
  638. }
  639. });
  640. SafeString.prototype.valueOf = function valueOf() {
  641. return this.val;
  642. };
  643. SafeString.prototype.toString = function toString() {
  644. return this.val;
  645. };
  646. function copySafeness(dest, target) {
  647. if (dest instanceof SafeString) {
  648. return new SafeString(target);
  649. }
  650. return target.toString();
  651. }
  652. function markSafe(val) {
  653. var type = typeof val;
  654. if (type === 'string') {
  655. return new SafeString(val);
  656. } else if (type !== 'function') {
  657. return val;
  658. } else {
  659. return function wrapSafe(args) {
  660. var ret = val.apply(this, arguments);
  661. if (typeof ret === 'string') {
  662. return new SafeString(ret);
  663. }
  664. return ret;
  665. };
  666. }
  667. }
  668. function suppressValue(val, autoescape) {
  669. val = val !== undefined && val !== null ? val : '';
  670. if (autoescape && !(val instanceof SafeString)) {
  671. val = lib.escape(val.toString());
  672. }
  673. return val;
  674. }
  675. function ensureDefined(val, lineno, colno) {
  676. if (val === null || val === undefined) {
  677. throw new lib.TemplateError('attempted to output null or undefined value', lineno + 1, colno + 1);
  678. }
  679. return val;
  680. }
  681. function memberLookup(obj, val) {
  682. if (obj === undefined || obj === null) {
  683. return undefined;
  684. }
  685. if (typeof obj[val] === 'function') {
  686. return function () {
  687. for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
  688. args[_key2] = arguments[_key2];
  689. }
  690. return obj[val].apply(obj, args);
  691. };
  692. }
  693. return obj[val];
  694. }
  695. function callWrap(obj, name, context, args) {
  696. if (!obj) {
  697. throw new Error('Unable to call `' + name + '`, which is undefined or falsey');
  698. } else if (typeof obj !== 'function') {
  699. throw new Error('Unable to call `' + name + '`, which is not a function');
  700. }
  701. return obj.apply(context, args);
  702. }
  703. function contextOrFrameLookup(context, frame, name) {
  704. var val = frame.lookup(name);
  705. return val !== undefined ? val : context.lookup(name);
  706. }
  707. function handleError(error, lineno, colno) {
  708. if (error.lineno) {
  709. return error;
  710. } else {
  711. return new lib.TemplateError(error, lineno, colno);
  712. }
  713. }
  714. function asyncEach(arr, dimen, iter, cb) {
  715. if (lib.isArray(arr)) {
  716. var len = arr.length;
  717. lib.asyncIter(arr, function iterCallback(item, i, next) {
  718. switch (dimen) {
  719. case 1:
  720. iter(item, i, len, next);
  721. break;
  722. case 2:
  723. iter(item[0], item[1], i, len, next);
  724. break;
  725. case 3:
  726. iter(item[0], item[1], item[2], i, len, next);
  727. break;
  728. default:
  729. item.push(i, len, next);
  730. iter.apply(this, item);
  731. }
  732. }, cb);
  733. } else {
  734. lib.asyncFor(arr, function iterCallback(key, val, i, len, next) {
  735. iter(key, val, i, len, next);
  736. }, cb);
  737. }
  738. }
  739. function asyncAll(arr, dimen, func, cb) {
  740. var finished = 0;
  741. var len;
  742. var outputArr;
  743. function done(i, output) {
  744. finished++;
  745. outputArr[i] = output;
  746. if (finished === len) {
  747. cb(null, outputArr.join(''));
  748. }
  749. }
  750. if (lib.isArray(arr)) {
  751. len = arr.length;
  752. outputArr = new Array(len);
  753. if (len === 0) {
  754. cb(null, '');
  755. } else {
  756. for (var i = 0; i < arr.length; i++) {
  757. var item = arr[i];
  758. switch (dimen) {
  759. case 1:
  760. func(item, i, len, done);
  761. break;
  762. case 2:
  763. func(item[0], item[1], i, len, done);
  764. break;
  765. case 3:
  766. func(item[0], item[1], item[2], i, len, done);
  767. break;
  768. default:
  769. item.push(i, len, done);
  770. func.apply(this, item);
  771. }
  772. }
  773. }
  774. } else {
  775. var keys = lib.keys(arr || {});
  776. len = keys.length;
  777. outputArr = new Array(len);
  778. if (len === 0) {
  779. cb(null, '');
  780. } else {
  781. for (var _i = 0; _i < keys.length; _i++) {
  782. var k = keys[_i];
  783. func(k, arr[k], _i, len, done);
  784. }
  785. }
  786. }
  787. }
  788. function fromIterator(arr) {
  789. if (typeof arr !== 'object' || arr === null || lib.isArray(arr)) {
  790. return arr;
  791. } else if (supportsIterators && Symbol.iterator in arr) {
  792. return arrayFrom(arr);
  793. } else {
  794. return arr;
  795. }
  796. }
  797. module.exports = {
  798. Frame: Frame,
  799. makeMacro: makeMacro,
  800. makeKeywordArgs: makeKeywordArgs,
  801. numArgs: numArgs,
  802. suppressValue: suppressValue,
  803. ensureDefined: ensureDefined,
  804. memberLookup: memberLookup,
  805. contextOrFrameLookup: contextOrFrameLookup,
  806. callWrap: callWrap,
  807. handleError: handleError,
  808. isArray: lib.isArray,
  809. keys: lib.keys,
  810. SafeString: SafeString,
  811. copySafeness: copySafeness,
  812. markSafe: markSafe,
  813. asyncEach: asyncEach,
  814. asyncAll: asyncAll,
  815. inOperator: lib.inOperator,
  816. fromIterator: fromIterator
  817. };
  818. /***/ }),
  819. /* 3 */
  820. /***/ (function(module, exports, __webpack_require__) {
  821. "use strict";
  822. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  823. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  824. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  825. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  826. var _require = __webpack_require__(1),
  827. Obj = _require.Obj;
  828. function traverseAndCheck(obj, type, results) {
  829. if (obj instanceof type) {
  830. results.push(obj);
  831. }
  832. if (obj instanceof Node) {
  833. obj.findAll(type, results);
  834. }
  835. }
  836. var Node = /*#__PURE__*/function (_Obj) {
  837. _inheritsLoose(Node, _Obj);
  838. function Node() {
  839. return _Obj.apply(this, arguments) || this;
  840. }
  841. var _proto = Node.prototype;
  842. _proto.init = function init(lineno, colno) {
  843. var _arguments = arguments,
  844. _this = this;
  845. for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
  846. args[_key - 2] = arguments[_key];
  847. }
  848. this.lineno = lineno;
  849. this.colno = colno;
  850. this.fields.forEach(function (field, i) {
  851. // The first two args are line/col numbers, so offset by 2
  852. var val = _arguments[i + 2]; // Fields should never be undefined, but null. It makes
  853. // testing easier to normalize values.
  854. if (val === undefined) {
  855. val = null;
  856. }
  857. _this[field] = val;
  858. });
  859. };
  860. _proto.findAll = function findAll(type, results) {
  861. var _this2 = this;
  862. results = results || [];
  863. if (this instanceof NodeList) {
  864. this.children.forEach(function (child) {
  865. return traverseAndCheck(child, type, results);
  866. });
  867. } else {
  868. this.fields.forEach(function (field) {
  869. return traverseAndCheck(_this2[field], type, results);
  870. });
  871. }
  872. return results;
  873. };
  874. _proto.iterFields = function iterFields(func) {
  875. var _this3 = this;
  876. this.fields.forEach(function (field) {
  877. func(_this3[field], field);
  878. });
  879. };
  880. return Node;
  881. }(Obj); // Abstract nodes
  882. var Value = /*#__PURE__*/function (_Node) {
  883. _inheritsLoose(Value, _Node);
  884. function Value() {
  885. return _Node.apply(this, arguments) || this;
  886. }
  887. _createClass(Value, [{
  888. key: "typename",
  889. get: function get() {
  890. return 'Value';
  891. }
  892. }, {
  893. key: "fields",
  894. get: function get() {
  895. return ['value'];
  896. }
  897. }]);
  898. return Value;
  899. }(Node); // Concrete nodes
  900. var NodeList = /*#__PURE__*/function (_Node2) {
  901. _inheritsLoose(NodeList, _Node2);
  902. function NodeList() {
  903. return _Node2.apply(this, arguments) || this;
  904. }
  905. var _proto2 = NodeList.prototype;
  906. _proto2.init = function init(lineno, colno, nodes) {
  907. _Node2.prototype.init.call(this, lineno, colno, nodes || []);
  908. };
  909. _proto2.addChild = function addChild(node) {
  910. this.children.push(node);
  911. };
  912. _createClass(NodeList, [{
  913. key: "typename",
  914. get: function get() {
  915. return 'NodeList';
  916. }
  917. }, {
  918. key: "fields",
  919. get: function get() {
  920. return ['children'];
  921. }
  922. }]);
  923. return NodeList;
  924. }(Node);
  925. var Root = NodeList.extend('Root');
  926. var Literal = Value.extend('Literal');
  927. var Symbol = Value.extend('Symbol');
  928. var Group = NodeList.extend('Group');
  929. var ArrayNode = NodeList.extend('Array');
  930. var Pair = Node.extend('Pair', {
  931. fields: ['key', 'value']
  932. });
  933. var Dict = NodeList.extend('Dict');
  934. var LookupVal = Node.extend('LookupVal', {
  935. fields: ['target', 'val']
  936. });
  937. var If = Node.extend('If', {
  938. fields: ['cond', 'body', 'else_']
  939. });
  940. var IfAsync = If.extend('IfAsync');
  941. var InlineIf = Node.extend('InlineIf', {
  942. fields: ['cond', 'body', 'else_']
  943. });
  944. var For = Node.extend('For', {
  945. fields: ['arr', 'name', 'body', 'else_']
  946. });
  947. var AsyncEach = For.extend('AsyncEach');
  948. var AsyncAll = For.extend('AsyncAll');
  949. var Macro = Node.extend('Macro', {
  950. fields: ['name', 'args', 'body']
  951. });
  952. var Caller = Macro.extend('Caller');
  953. var Import = Node.extend('Import', {
  954. fields: ['template', 'target', 'withContext']
  955. });
  956. var FromImport = /*#__PURE__*/function (_Node3) {
  957. _inheritsLoose(FromImport, _Node3);
  958. function FromImport() {
  959. return _Node3.apply(this, arguments) || this;
  960. }
  961. var _proto3 = FromImport.prototype;
  962. _proto3.init = function init(lineno, colno, template, names, withContext) {
  963. _Node3.prototype.init.call(this, lineno, colno, template, names || new NodeList(), withContext);
  964. };
  965. _createClass(FromImport, [{
  966. key: "typename",
  967. get: function get() {
  968. return 'FromImport';
  969. }
  970. }, {
  971. key: "fields",
  972. get: function get() {
  973. return ['template', 'names', 'withContext'];
  974. }
  975. }]);
  976. return FromImport;
  977. }(Node);
  978. var FunCall = Node.extend('FunCall', {
  979. fields: ['name', 'args']
  980. });
  981. var Filter = FunCall.extend('Filter');
  982. var FilterAsync = Filter.extend('FilterAsync', {
  983. fields: ['name', 'args', 'symbol']
  984. });
  985. var KeywordArgs = Dict.extend('KeywordArgs');
  986. var Block = Node.extend('Block', {
  987. fields: ['name', 'body']
  988. });
  989. var Super = Node.extend('Super', {
  990. fields: ['blockName', 'symbol']
  991. });
  992. var TemplateRef = Node.extend('TemplateRef', {
  993. fields: ['template']
  994. });
  995. var Extends = TemplateRef.extend('Extends');
  996. var Include = Node.extend('Include', {
  997. fields: ['template', 'ignoreMissing']
  998. });
  999. var Set = Node.extend('Set', {
  1000. fields: ['targets', 'value']
  1001. });
  1002. var Switch = Node.extend('Switch', {
  1003. fields: ['expr', 'cases', 'default']
  1004. });
  1005. var Case = Node.extend('Case', {
  1006. fields: ['cond', 'body']
  1007. });
  1008. var Output = NodeList.extend('Output');
  1009. var Capture = Node.extend('Capture', {
  1010. fields: ['body']
  1011. });
  1012. var TemplateData = Literal.extend('TemplateData');
  1013. var UnaryOp = Node.extend('UnaryOp', {
  1014. fields: ['target']
  1015. });
  1016. var BinOp = Node.extend('BinOp', {
  1017. fields: ['left', 'right']
  1018. });
  1019. var In = BinOp.extend('In');
  1020. var Is = BinOp.extend('Is');
  1021. var Or = BinOp.extend('Or');
  1022. var And = BinOp.extend('And');
  1023. var Not = UnaryOp.extend('Not');
  1024. var Add = BinOp.extend('Add');
  1025. var Concat = BinOp.extend('Concat');
  1026. var Sub = BinOp.extend('Sub');
  1027. var Mul = BinOp.extend('Mul');
  1028. var Div = BinOp.extend('Div');
  1029. var FloorDiv = BinOp.extend('FloorDiv');
  1030. var Mod = BinOp.extend('Mod');
  1031. var Pow = BinOp.extend('Pow');
  1032. var Neg = UnaryOp.extend('Neg');
  1033. var Pos = UnaryOp.extend('Pos');
  1034. var Compare = Node.extend('Compare', {
  1035. fields: ['expr', 'ops']
  1036. });
  1037. var CompareOperand = Node.extend('CompareOperand', {
  1038. fields: ['expr', 'type']
  1039. });
  1040. var CallExtension = Node.extend('CallExtension', {
  1041. init: function init(ext, prop, args, contentArgs) {
  1042. this.parent();
  1043. this.extName = ext.__name || ext;
  1044. this.prop = prop;
  1045. this.args = args || new NodeList();
  1046. this.contentArgs = contentArgs || [];
  1047. this.autoescape = ext.autoescape;
  1048. },
  1049. fields: ['extName', 'prop', 'args', 'contentArgs']
  1050. });
  1051. var CallExtensionAsync = CallExtension.extend('CallExtensionAsync'); // This is hacky, but this is just a debugging function anyway
  1052. function print(str, indent, inline) {
  1053. var lines = str.split('\n');
  1054. lines.forEach(function (line, i) {
  1055. if (line && (inline && i > 0 || !inline)) {
  1056. process.stdout.write(' '.repeat(indent));
  1057. }
  1058. var nl = i === lines.length - 1 ? '' : '\n';
  1059. process.stdout.write("" + line + nl);
  1060. });
  1061. } // Print the AST in a nicely formatted tree format for debuggin
  1062. function printNodes(node, indent) {
  1063. indent = indent || 0;
  1064. print(node.typename + ': ', indent);
  1065. if (node instanceof NodeList) {
  1066. print('\n');
  1067. node.children.forEach(function (n) {
  1068. printNodes(n, indent + 2);
  1069. });
  1070. } else if (node instanceof CallExtension) {
  1071. print(node.extName + "." + node.prop + "\n");
  1072. if (node.args) {
  1073. printNodes(node.args, indent + 2);
  1074. }
  1075. if (node.contentArgs) {
  1076. node.contentArgs.forEach(function (n) {
  1077. printNodes(n, indent + 2);
  1078. });
  1079. }
  1080. } else {
  1081. var nodes = [];
  1082. var props = null;
  1083. node.iterFields(function (val, fieldName) {
  1084. if (val instanceof Node) {
  1085. nodes.push([fieldName, val]);
  1086. } else {
  1087. props = props || {};
  1088. props[fieldName] = val;
  1089. }
  1090. });
  1091. if (props) {
  1092. print(JSON.stringify(props, null, 2) + '\n', null, true);
  1093. } else {
  1094. print('\n');
  1095. }
  1096. nodes.forEach(function (_ref) {
  1097. var fieldName = _ref[0],
  1098. n = _ref[1];
  1099. print("[" + fieldName + "] =>", indent + 2);
  1100. printNodes(n, indent + 4);
  1101. });
  1102. }
  1103. }
  1104. module.exports = {
  1105. Node: Node,
  1106. Root: Root,
  1107. NodeList: NodeList,
  1108. Value: Value,
  1109. Literal: Literal,
  1110. Symbol: Symbol,
  1111. Group: Group,
  1112. Array: ArrayNode,
  1113. Pair: Pair,
  1114. Dict: Dict,
  1115. Output: Output,
  1116. Capture: Capture,
  1117. TemplateData: TemplateData,
  1118. If: If,
  1119. IfAsync: IfAsync,
  1120. InlineIf: InlineIf,
  1121. For: For,
  1122. AsyncEach: AsyncEach,
  1123. AsyncAll: AsyncAll,
  1124. Macro: Macro,
  1125. Caller: Caller,
  1126. Import: Import,
  1127. FromImport: FromImport,
  1128. FunCall: FunCall,
  1129. Filter: Filter,
  1130. FilterAsync: FilterAsync,
  1131. KeywordArgs: KeywordArgs,
  1132. Block: Block,
  1133. Super: Super,
  1134. Extends: Extends,
  1135. Include: Include,
  1136. Set: Set,
  1137. Switch: Switch,
  1138. Case: Case,
  1139. LookupVal: LookupVal,
  1140. BinOp: BinOp,
  1141. In: In,
  1142. Is: Is,
  1143. Or: Or,
  1144. And: And,
  1145. Not: Not,
  1146. Add: Add,
  1147. Concat: Concat,
  1148. Sub: Sub,
  1149. Mul: Mul,
  1150. Div: Div,
  1151. FloorDiv: FloorDiv,
  1152. Mod: Mod,
  1153. Pow: Pow,
  1154. Neg: Neg,
  1155. Pos: Pos,
  1156. Compare: Compare,
  1157. CompareOperand: CompareOperand,
  1158. CallExtension: CallExtension,
  1159. CallExtensionAsync: CallExtensionAsync,
  1160. printNodes: printNodes
  1161. };
  1162. /***/ }),
  1163. /* 4 */
  1164. /***/ (function(module, exports) {
  1165. /***/ }),
  1166. /* 5 */
  1167. /***/ (function(module, exports, __webpack_require__) {
  1168. "use strict";
  1169. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  1170. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  1171. var parser = __webpack_require__(8);
  1172. var transformer = __webpack_require__(17);
  1173. var nodes = __webpack_require__(3);
  1174. var _require = __webpack_require__(0),
  1175. TemplateError = _require.TemplateError;
  1176. var _require2 = __webpack_require__(2),
  1177. Frame = _require2.Frame;
  1178. var _require3 = __webpack_require__(1),
  1179. Obj = _require3.Obj; // These are all the same for now, but shouldn't be passed straight
  1180. // through
  1181. var compareOps = {
  1182. '==': '==',
  1183. '===': '===',
  1184. '!=': '!=',
  1185. '!==': '!==',
  1186. '<': '<',
  1187. '>': '>',
  1188. '<=': '<=',
  1189. '>=': '>='
  1190. };
  1191. var Compiler = /*#__PURE__*/function (_Obj) {
  1192. _inheritsLoose(Compiler, _Obj);
  1193. function Compiler() {
  1194. return _Obj.apply(this, arguments) || this;
  1195. }
  1196. var _proto = Compiler.prototype;
  1197. _proto.init = function init(templateName, throwOnUndefined) {
  1198. this.templateName = templateName;
  1199. this.codebuf = [];
  1200. this.lastId = 0;
  1201. this.buffer = null;
  1202. this.bufferStack = [];
  1203. this._scopeClosers = '';
  1204. this.inBlock = false;
  1205. this.throwOnUndefined = throwOnUndefined;
  1206. };
  1207. _proto.fail = function fail(msg, lineno, colno) {
  1208. if (lineno !== undefined) {
  1209. lineno += 1;
  1210. }
  1211. if (colno !== undefined) {
  1212. colno += 1;
  1213. }
  1214. throw new TemplateError(msg, lineno, colno);
  1215. };
  1216. _proto._pushBuffer = function _pushBuffer() {
  1217. var id = this._tmpid();
  1218. this.bufferStack.push(this.buffer);
  1219. this.buffer = id;
  1220. this._emit("var " + this.buffer + " = \"\";");
  1221. return id;
  1222. };
  1223. _proto._popBuffer = function _popBuffer() {
  1224. this.buffer = this.bufferStack.pop();
  1225. };
  1226. _proto._emit = function _emit(code) {
  1227. this.codebuf.push(code);
  1228. };
  1229. _proto._emitLine = function _emitLine(code) {
  1230. this._emit(code + '\n');
  1231. };
  1232. _proto._emitLines = function _emitLines() {
  1233. var _this = this;
  1234. for (var _len = arguments.length, lines = new Array(_len), _key = 0; _key < _len; _key++) {
  1235. lines[_key] = arguments[_key];
  1236. }
  1237. lines.forEach(function (line) {
  1238. return _this._emitLine(line);
  1239. });
  1240. };
  1241. _proto._emitFuncBegin = function _emitFuncBegin(node, name) {
  1242. this.buffer = 'output';
  1243. this._scopeClosers = '';
  1244. this._emitLine("function " + name + "(env, context, frame, runtime, cb) {");
  1245. this._emitLine("var lineno = " + node.lineno + ";");
  1246. this._emitLine("var colno = " + node.colno + ";");
  1247. this._emitLine("var " + this.buffer + " = \"\";");
  1248. this._emitLine('try {');
  1249. };
  1250. _proto._emitFuncEnd = function _emitFuncEnd(noReturn) {
  1251. if (!noReturn) {
  1252. this._emitLine('cb(null, ' + this.buffer + ');');
  1253. }
  1254. this._closeScopeLevels();
  1255. this._emitLine('} catch (e) {');
  1256. this._emitLine(' cb(runtime.handleError(e, lineno, colno));');
  1257. this._emitLine('}');
  1258. this._emitLine('}');
  1259. this.buffer = null;
  1260. };
  1261. _proto._addScopeLevel = function _addScopeLevel() {
  1262. this._scopeClosers += '})';
  1263. };
  1264. _proto._closeScopeLevels = function _closeScopeLevels() {
  1265. this._emitLine(this._scopeClosers + ';');
  1266. this._scopeClosers = '';
  1267. };
  1268. _proto._withScopedSyntax = function _withScopedSyntax(func) {
  1269. var _scopeClosers = this._scopeClosers;
  1270. this._scopeClosers = '';
  1271. func.call(this);
  1272. this._closeScopeLevels();
  1273. this._scopeClosers = _scopeClosers;
  1274. };
  1275. _proto._makeCallback = function _makeCallback(res) {
  1276. var err = this._tmpid();
  1277. return 'function(' + err + (res ? ',' + res : '') + ') {\n' + 'if(' + err + ') { cb(' + err + '); return; }';
  1278. };
  1279. _proto._tmpid = function _tmpid() {
  1280. this.lastId++;
  1281. return 't_' + this.lastId;
  1282. };
  1283. _proto._templateName = function _templateName() {
  1284. return this.templateName == null ? 'undefined' : JSON.stringify(this.templateName);
  1285. };
  1286. _proto._compileChildren = function _compileChildren(node, frame) {
  1287. var _this2 = this;
  1288. node.children.forEach(function (child) {
  1289. _this2.compile(child, frame);
  1290. });
  1291. };
  1292. _proto._compileAggregate = function _compileAggregate(node, frame, startChar, endChar) {
  1293. var _this3 = this;
  1294. if (startChar) {
  1295. this._emit(startChar);
  1296. }
  1297. node.children.forEach(function (child, i) {
  1298. if (i > 0) {
  1299. _this3._emit(',');
  1300. }
  1301. _this3.compile(child, frame);
  1302. });
  1303. if (endChar) {
  1304. this._emit(endChar);
  1305. }
  1306. };
  1307. _proto._compileExpression = function _compileExpression(node, frame) {
  1308. // TODO: I'm not really sure if this type check is worth it or
  1309. // not.
  1310. this.assertType(node, nodes.Literal, nodes.Symbol, nodes.Group, nodes.Array, nodes.Dict, nodes.FunCall, nodes.Caller, nodes.Filter, nodes.LookupVal, nodes.Compare, nodes.InlineIf, nodes.In, nodes.Is, nodes.And, nodes.Or, nodes.Not, nodes.Add, nodes.Concat, nodes.Sub, nodes.Mul, nodes.Div, nodes.FloorDiv, nodes.Mod, nodes.Pow, nodes.Neg, nodes.Pos, nodes.Compare, nodes.NodeList);
  1311. this.compile(node, frame);
  1312. };
  1313. _proto.assertType = function assertType(node) {
  1314. for (var _len2 = arguments.length, types = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
  1315. types[_key2 - 1] = arguments[_key2];
  1316. }
  1317. if (!types.some(function (t) {
  1318. return node instanceof t;
  1319. })) {
  1320. this.fail("assertType: invalid type: " + node.typename, node.lineno, node.colno);
  1321. }
  1322. };
  1323. _proto.compileCallExtension = function compileCallExtension(node, frame, async) {
  1324. var _this4 = this;
  1325. var args = node.args;
  1326. var contentArgs = node.contentArgs;
  1327. var autoescape = typeof node.autoescape === 'boolean' ? node.autoescape : true;
  1328. if (!async) {
  1329. this._emit(this.buffer + " += runtime.suppressValue(");
  1330. }
  1331. this._emit("env.getExtension(\"" + node.extName + "\")[\"" + node.prop + "\"](");
  1332. this._emit('context');
  1333. if (args || contentArgs) {
  1334. this._emit(',');
  1335. }
  1336. if (args) {
  1337. if (!(args instanceof nodes.NodeList)) {
  1338. this.fail('compileCallExtension: arguments must be a NodeList, ' + 'use `parser.parseSignature`');
  1339. }
  1340. args.children.forEach(function (arg, i) {
  1341. // Tag arguments are passed normally to the call. Note
  1342. // that keyword arguments are turned into a single js
  1343. // object as the last argument, if they exist.
  1344. _this4._compileExpression(arg, frame);
  1345. if (i !== args.children.length - 1 || contentArgs.length) {
  1346. _this4._emit(',');
  1347. }
  1348. });
  1349. }
  1350. if (contentArgs.length) {
  1351. contentArgs.forEach(function (arg, i) {
  1352. if (i > 0) {
  1353. _this4._emit(',');
  1354. }
  1355. if (arg) {
  1356. _this4._emitLine('function(cb) {');
  1357. _this4._emitLine('if(!cb) { cb = function(err) { if(err) { throw err; }}}');
  1358. var id = _this4._pushBuffer();
  1359. _this4._withScopedSyntax(function () {
  1360. _this4.compile(arg, frame);
  1361. _this4._emitLine("cb(null, " + id + ");");
  1362. });
  1363. _this4._popBuffer();
  1364. _this4._emitLine("return " + id + ";");
  1365. _this4._emitLine('}');
  1366. } else {
  1367. _this4._emit('null');
  1368. }
  1369. });
  1370. }
  1371. if (async) {
  1372. var res = this._tmpid();
  1373. this._emitLine(', ' + this._makeCallback(res));
  1374. this._emitLine(this.buffer + " += runtime.suppressValue(" + res + ", " + autoescape + " && env.opts.autoescape);");
  1375. this._addScopeLevel();
  1376. } else {
  1377. this._emit(')');
  1378. this._emit(", " + autoescape + " && env.opts.autoescape);\n");
  1379. }
  1380. };
  1381. _proto.compileCallExtensionAsync = function compileCallExtensionAsync(node, frame) {
  1382. this.compileCallExtension(node, frame, true);
  1383. };
  1384. _proto.compileNodeList = function compileNodeList(node, frame) {
  1385. this._compileChildren(node, frame);
  1386. };
  1387. _proto.compileLiteral = function compileLiteral(node) {
  1388. if (typeof node.value === 'string') {
  1389. var val = node.value.replace(/\\/g, '\\\\');
  1390. val = val.replace(/"/g, '\\"');
  1391. val = val.replace(/\n/g, '\\n');
  1392. val = val.replace(/\r/g, '\\r');
  1393. val = val.replace(/\t/g, '\\t');
  1394. val = val.replace(/\u2028/g, "\\u2028");
  1395. this._emit("\"" + val + "\"");
  1396. } else if (node.value === null) {
  1397. this._emit('null');
  1398. } else {
  1399. this._emit(node.value.toString());
  1400. }
  1401. };
  1402. _proto.compileSymbol = function compileSymbol(node, frame) {
  1403. var name = node.value;
  1404. var v = frame.lookup(name);
  1405. if (v) {
  1406. this._emit(v);
  1407. } else {
  1408. this._emit('runtime.contextOrFrameLookup(' + 'context, frame, "' + name + '")');
  1409. }
  1410. };
  1411. _proto.compileGroup = function compileGroup(node, frame) {
  1412. this._compileAggregate(node, frame, '(', ')');
  1413. };
  1414. _proto.compileArray = function compileArray(node, frame) {
  1415. this._compileAggregate(node, frame, '[', ']');
  1416. };
  1417. _proto.compileDict = function compileDict(node, frame) {
  1418. this._compileAggregate(node, frame, '{', '}');
  1419. };
  1420. _proto.compilePair = function compilePair(node, frame) {
  1421. var key = node.key;
  1422. var val = node.value;
  1423. if (key instanceof nodes.Symbol) {
  1424. key = new nodes.Literal(key.lineno, key.colno, key.value);
  1425. } else if (!(key instanceof nodes.Literal && typeof key.value === 'string')) {
  1426. this.fail('compilePair: Dict keys must be strings or names', key.lineno, key.colno);
  1427. }
  1428. this.compile(key, frame);
  1429. this._emit(': ');
  1430. this._compileExpression(val, frame);
  1431. };
  1432. _proto.compileInlineIf = function compileInlineIf(node, frame) {
  1433. this._emit('(');
  1434. this.compile(node.cond, frame);
  1435. this._emit('?');
  1436. this.compile(node.body, frame);
  1437. this._emit(':');
  1438. if (node.else_ !== null) {
  1439. this.compile(node.else_, frame);
  1440. } else {
  1441. this._emit('""');
  1442. }
  1443. this._emit(')');
  1444. };
  1445. _proto.compileIn = function compileIn(node, frame) {
  1446. this._emit('runtime.inOperator(');
  1447. this.compile(node.left, frame);
  1448. this._emit(',');
  1449. this.compile(node.right, frame);
  1450. this._emit(')');
  1451. };
  1452. _proto.compileIs = function compileIs(node, frame) {
  1453. // first, we need to try to get the name of the test function, if it's a
  1454. // callable (i.e., has args) and not a symbol.
  1455. var right = node.right.name ? node.right.name.value // otherwise go with the symbol value
  1456. : node.right.value;
  1457. this._emit('env.getTest("' + right + '").call(context, ');
  1458. this.compile(node.left, frame); // compile the arguments for the callable if they exist
  1459. if (node.right.args) {
  1460. this._emit(',');
  1461. this.compile(node.right.args, frame);
  1462. }
  1463. this._emit(') === true');
  1464. };
  1465. _proto._binOpEmitter = function _binOpEmitter(node, frame, str) {
  1466. this.compile(node.left, frame);
  1467. this._emit(str);
  1468. this.compile(node.right, frame);
  1469. } // ensure concatenation instead of addition
  1470. // by adding empty string in between
  1471. ;
  1472. _proto.compileOr = function compileOr(node, frame) {
  1473. return this._binOpEmitter(node, frame, ' || ');
  1474. };
  1475. _proto.compileAnd = function compileAnd(node, frame) {
  1476. return this._binOpEmitter(node, frame, ' && ');
  1477. };
  1478. _proto.compileAdd = function compileAdd(node, frame) {
  1479. return this._binOpEmitter(node, frame, ' + ');
  1480. };
  1481. _proto.compileConcat = function compileConcat(node, frame) {
  1482. return this._binOpEmitter(node, frame, ' + "" + ');
  1483. };
  1484. _proto.compileSub = function compileSub(node, frame) {
  1485. return this._binOpEmitter(node, frame, ' - ');
  1486. };
  1487. _proto.compileMul = function compileMul(node, frame) {
  1488. return this._binOpEmitter(node, frame, ' * ');
  1489. };
  1490. _proto.compileDiv = function compileDiv(node, frame) {
  1491. return this._binOpEmitter(node, frame, ' / ');
  1492. };
  1493. _proto.compileMod = function compileMod(node, frame) {
  1494. return this._binOpEmitter(node, frame, ' % ');
  1495. };
  1496. _proto.compileNot = function compileNot(node, frame) {
  1497. this._emit('!');
  1498. this.compile(node.target, frame);
  1499. };
  1500. _proto.compileFloorDiv = function compileFloorDiv(node, frame) {
  1501. this._emit('Math.floor(');
  1502. this.compile(node.left, frame);
  1503. this._emit(' / ');
  1504. this.compile(node.right, frame);
  1505. this._emit(')');
  1506. };
  1507. _proto.compilePow = function compilePow(node, frame) {
  1508. this._emit('Math.pow(');
  1509. this.compile(node.left, frame);
  1510. this._emit(', ');
  1511. this.compile(node.right, frame);
  1512. this._emit(')');
  1513. };
  1514. _proto.compileNeg = function compileNeg(node, frame) {
  1515. this._emit('-');
  1516. this.compile(node.target, frame);
  1517. };
  1518. _proto.compilePos = function compilePos(node, frame) {
  1519. this._emit('+');
  1520. this.compile(node.target, frame);
  1521. };
  1522. _proto.compileCompare = function compileCompare(node, frame) {
  1523. var _this5 = this;
  1524. this.compile(node.expr, frame);
  1525. node.ops.forEach(function (op) {
  1526. _this5._emit(" " + compareOps[op.type] + " ");
  1527. _this5.compile(op.expr, frame);
  1528. });
  1529. };
  1530. _proto.compileLookupVal = function compileLookupVal(node, frame) {
  1531. this._emit('runtime.memberLookup((');
  1532. this._compileExpression(node.target, frame);
  1533. this._emit('),');
  1534. this._compileExpression(node.val, frame);
  1535. this._emit(')');
  1536. };
  1537. _proto._getNodeName = function _getNodeName(node) {
  1538. switch (node.typename) {
  1539. case 'Symbol':
  1540. return node.value;
  1541. case 'FunCall':
  1542. return 'the return value of (' + this._getNodeName(node.name) + ')';
  1543. case 'LookupVal':
  1544. return this._getNodeName(node.target) + '["' + this._getNodeName(node.val) + '"]';
  1545. case 'Literal':
  1546. return node.value.toString();
  1547. default:
  1548. return '--expression--';
  1549. }
  1550. };
  1551. _proto.compileFunCall = function compileFunCall(node, frame) {
  1552. // Keep track of line/col info at runtime by settings
  1553. // variables within an expression. An expression in javascript
  1554. // like (x, y, z) returns the last value, and x and y can be
  1555. // anything
  1556. this._emit('(lineno = ' + node.lineno + ', colno = ' + node.colno + ', ');
  1557. this._emit('runtime.callWrap('); // Compile it as normal.
  1558. this._compileExpression(node.name, frame); // Output the name of what we're calling so we can get friendly errors
  1559. // if the lookup fails.
  1560. this._emit(', "' + this._getNodeName(node.name).replace(/"/g, '\\"') + '", context, ');
  1561. this._compileAggregate(node.args, frame, '[', '])');
  1562. this._emit(')');
  1563. };
  1564. _proto.compileFilter = function compileFilter(node, frame) {
  1565. var name = node.name;
  1566. this.assertType(name, nodes.Symbol);
  1567. this._emit('env.getFilter("' + name.value + '").call(context, ');
  1568. this._compileAggregate(node.args, frame);
  1569. this._emit(')');
  1570. };
  1571. _proto.compileFilterAsync = function compileFilterAsync(node, frame) {
  1572. var name = node.name;
  1573. var symbol = node.symbol.value;
  1574. this.assertType(name, nodes.Symbol);
  1575. frame.set(symbol, symbol);
  1576. this._emit('env.getFilter("' + name.value + '").call(context, ');
  1577. this._compileAggregate(node.args, frame);
  1578. this._emitLine(', ' + this._makeCallback(symbol));
  1579. this._addScopeLevel();
  1580. };
  1581. _proto.compileKeywordArgs = function compileKeywordArgs(node, frame) {
  1582. this._emit('runtime.makeKeywordArgs(');
  1583. this.compileDict(node, frame);
  1584. this._emit(')');
  1585. };
  1586. _proto.compileSet = function compileSet(node, frame) {
  1587. var _this6 = this;
  1588. var ids = []; // Lookup the variable names for each identifier and create
  1589. // new ones if necessary
  1590. node.targets.forEach(function (target) {
  1591. var name = target.value;
  1592. var id = frame.lookup(name);
  1593. if (id === null || id === undefined) {
  1594. id = _this6._tmpid(); // Note: This relies on js allowing scope across
  1595. // blocks, in case this is created inside an `if`
  1596. _this6._emitLine('var ' + id + ';');
  1597. }
  1598. ids.push(id);
  1599. });
  1600. if (node.value) {
  1601. this._emit(ids.join(' = ') + ' = ');
  1602. this._compileExpression(node.value, frame);
  1603. this._emitLine(';');
  1604. } else {
  1605. this._emit(ids.join(' = ') + ' = ');
  1606. this.compile(node.body, frame);
  1607. this._emitLine(';');
  1608. }
  1609. node.targets.forEach(function (target, i) {
  1610. var id = ids[i];
  1611. var name = target.value; // We are running this for every var, but it's very
  1612. // uncommon to assign to multiple vars anyway
  1613. _this6._emitLine("frame.set(\"" + name + "\", " + id + ", true);");
  1614. _this6._emitLine('if(frame.topLevel) {');
  1615. _this6._emitLine("context.setVariable(\"" + name + "\", " + id + ");");
  1616. _this6._emitLine('}');
  1617. if (name.charAt(0) !== '_') {
  1618. _this6._emitLine('if(frame.topLevel) {');
  1619. _this6._emitLine("context.addExport(\"" + name + "\", " + id + ");");
  1620. _this6._emitLine('}');
  1621. }
  1622. });
  1623. };
  1624. _proto.compileSwitch = function compileSwitch(node, frame) {
  1625. var _this7 = this;
  1626. this._emit('switch (');
  1627. this.compile(node.expr, frame);
  1628. this._emit(') {');
  1629. node.cases.forEach(function (c, i) {
  1630. _this7._emit('case ');
  1631. _this7.compile(c.cond, frame);
  1632. _this7._emit(': ');
  1633. _this7.compile(c.body, frame); // preserve fall-throughs
  1634. if (c.body.children.length) {
  1635. _this7._emitLine('break;');
  1636. }
  1637. });
  1638. if (node.default) {
  1639. this._emit('default:');
  1640. this.compile(node.default, frame);
  1641. }
  1642. this._emit('}');
  1643. };
  1644. _proto.compileIf = function compileIf(node, frame, async) {
  1645. var _this8 = this;
  1646. this._emit('if(');
  1647. this._compileExpression(node.cond, frame);
  1648. this._emitLine(') {');
  1649. this._withScopedSyntax(function () {
  1650. _this8.compile(node.body, frame);
  1651. if (async) {
  1652. _this8._emit('cb()');
  1653. }
  1654. });
  1655. if (node.else_) {
  1656. this._emitLine('}\nelse {');
  1657. this._withScopedSyntax(function () {
  1658. _this8.compile(node.else_, frame);
  1659. if (async) {
  1660. _this8._emit('cb()');
  1661. }
  1662. });
  1663. } else if (async) {
  1664. this._emitLine('}\nelse {');
  1665. this._emit('cb()');
  1666. }
  1667. this._emitLine('}');
  1668. };
  1669. _proto.compileIfAsync = function compileIfAsync(node, frame) {
  1670. this._emit('(function(cb) {');
  1671. this.compileIf(node, frame, true);
  1672. this._emit('})(' + this._makeCallback());
  1673. this._addScopeLevel();
  1674. };
  1675. _proto._emitLoopBindings = function _emitLoopBindings(node, arr, i, len) {
  1676. var _this9 = this;
  1677. var bindings = [{
  1678. name: 'index',
  1679. val: i + " + 1"
  1680. }, {
  1681. name: 'index0',
  1682. val: i
  1683. }, {
  1684. name: 'revindex',
  1685. val: len + " - " + i
  1686. }, {
  1687. name: 'revindex0',
  1688. val: len + " - " + i + " - 1"
  1689. }, {
  1690. name: 'first',
  1691. val: i + " === 0"
  1692. }, {
  1693. name: 'last',
  1694. val: i + " === " + len + " - 1"
  1695. }, {
  1696. name: 'length',
  1697. val: len
  1698. }];
  1699. bindings.forEach(function (b) {
  1700. _this9._emitLine("frame.set(\"loop." + b.name + "\", " + b.val + ");");
  1701. });
  1702. };
  1703. _proto.compileFor = function compileFor(node, frame) {
  1704. var _this10 = this;
  1705. // Some of this code is ugly, but it keeps the generated code
  1706. // as fast as possible. ForAsync also shares some of this, but
  1707. // not much.
  1708. var i = this._tmpid();
  1709. var len = this._tmpid();
  1710. var arr = this._tmpid();
  1711. frame = frame.push();
  1712. this._emitLine('frame = frame.push();');
  1713. this._emit("var " + arr + " = ");
  1714. this._compileExpression(node.arr, frame);
  1715. this._emitLine(';');
  1716. this._emit("if(" + arr + ") {");
  1717. this._emitLine(arr + ' = runtime.fromIterator(' + arr + ');'); // If multiple names are passed, we need to bind them
  1718. // appropriately
  1719. if (node.name instanceof nodes.Array) {
  1720. this._emitLine("var " + i + ";"); // The object could be an arroy or object. Note that the
  1721. // body of the loop is duplicated for each condition, but
  1722. // we are optimizing for speed over size.
  1723. this._emitLine("if(runtime.isArray(" + arr + ")) {");
  1724. this._emitLine("var " + len + " = " + arr + ".length;");
  1725. this._emitLine("for(" + i + "=0; " + i + " < " + arr + ".length; " + i + "++) {"); // Bind each declared var
  1726. node.name.children.forEach(function (child, u) {
  1727. var tid = _this10._tmpid();
  1728. _this10._emitLine("var " + tid + " = " + arr + "[" + i + "][" + u + "];");
  1729. _this10._emitLine("frame.set(\"" + child + "\", " + arr + "[" + i + "][" + u + "]);");
  1730. frame.set(node.name.children[u].value, tid);
  1731. });
  1732. this._emitLoopBindings(node, arr, i, len);
  1733. this._withScopedSyntax(function () {
  1734. _this10.compile(node.body, frame);
  1735. });
  1736. this._emitLine('}');
  1737. this._emitLine('} else {'); // Iterate over the key/values of an object
  1738. var _node$name$children = node.name.children,
  1739. key = _node$name$children[0],
  1740. val = _node$name$children[1];
  1741. var k = this._tmpid();
  1742. var v = this._tmpid();
  1743. frame.set(key.value, k);
  1744. frame.set(val.value, v);
  1745. this._emitLine(i + " = -1;");
  1746. this._emitLine("var " + len + " = runtime.keys(" + arr + ").length;");
  1747. this._emitLine("for(var " + k + " in " + arr + ") {");
  1748. this._emitLine(i + "++;");
  1749. this._emitLine("var " + v + " = " + arr + "[" + k + "];");
  1750. this._emitLine("frame.set(\"" + key.value + "\", " + k + ");");
  1751. this._emitLine("frame.set(\"" + val.value + "\", " + v + ");");
  1752. this._emitLoopBindings(node, arr, i, len);
  1753. this._withScopedSyntax(function () {
  1754. _this10.compile(node.body, frame);
  1755. });
  1756. this._emitLine('}');
  1757. this._emitLine('}');
  1758. } else {
  1759. // Generate a typical array iteration
  1760. var _v = this._tmpid();
  1761. frame.set(node.name.value, _v);
  1762. this._emitLine("var " + len + " = " + arr + ".length;");
  1763. this._emitLine("for(var " + i + "=0; " + i + " < " + arr + ".length; " + i + "++) {");
  1764. this._emitLine("var " + _v + " = " + arr + "[" + i + "];");
  1765. this._emitLine("frame.set(\"" + node.name.value + "\", " + _v + ");");
  1766. this._emitLoopBindings(node, arr, i, len);
  1767. this._withScopedSyntax(function () {
  1768. _this10.compile(node.body, frame);
  1769. });
  1770. this._emitLine('}');
  1771. }
  1772. this._emitLine('}');
  1773. if (node.else_) {
  1774. this._emitLine('if (!' + len + ') {');
  1775. this.compile(node.else_, frame);
  1776. this._emitLine('}');
  1777. }
  1778. this._emitLine('frame = frame.pop();');
  1779. };
  1780. _proto._compileAsyncLoop = function _compileAsyncLoop(node, frame, parallel) {
  1781. var _this11 = this;
  1782. // This shares some code with the For tag, but not enough to
  1783. // worry about. This iterates across an object asynchronously,
  1784. // but not in parallel.
  1785. var i = this._tmpid();
  1786. var len = this._tmpid();
  1787. var arr = this._tmpid();
  1788. var asyncMethod = parallel ? 'asyncAll' : 'asyncEach';
  1789. frame = frame.push();
  1790. this._emitLine('frame = frame.push();');
  1791. this._emit('var ' + arr + ' = runtime.fromIterator(');
  1792. this._compileExpression(node.arr, frame);
  1793. this._emitLine(');');
  1794. if (node.name instanceof nodes.Array) {
  1795. var arrayLen = node.name.children.length;
  1796. this._emit("runtime." + asyncMethod + "(" + arr + ", " + arrayLen + ", function(");
  1797. node.name.children.forEach(function (name) {
  1798. _this11._emit(name.value + ",");
  1799. });
  1800. this._emit(i + ',' + len + ',next) {');
  1801. node.name.children.forEach(function (name) {
  1802. var id = name.value;
  1803. frame.set(id, id);
  1804. _this11._emitLine("frame.set(\"" + id + "\", " + id + ");");
  1805. });
  1806. } else {
  1807. var id = node.name.value;
  1808. this._emitLine("runtime." + asyncMethod + "(" + arr + ", 1, function(" + id + ", " + i + ", " + len + ",next) {");
  1809. this._emitLine('frame.set("' + id + '", ' + id + ');');
  1810. frame.set(id, id);
  1811. }
  1812. this._emitLoopBindings(node, arr, i, len);
  1813. this._withScopedSyntax(function () {
  1814. var buf;
  1815. if (parallel) {
  1816. buf = _this11._pushBuffer();
  1817. }
  1818. _this11.compile(node.body, frame);
  1819. _this11._emitLine('next(' + i + (buf ? ',' + buf : '') + ');');
  1820. if (parallel) {
  1821. _this11._popBuffer();
  1822. }
  1823. });
  1824. var output = this._tmpid();
  1825. this._emitLine('}, ' + this._makeCallback(output));
  1826. this._addScopeLevel();
  1827. if (parallel) {
  1828. this._emitLine(this.buffer + ' += ' + output + ';');
  1829. }
  1830. if (node.else_) {
  1831. this._emitLine('if (!' + arr + '.length) {');
  1832. this.compile(node.else_, frame);
  1833. this._emitLine('}');
  1834. }
  1835. this._emitLine('frame = frame.pop();');
  1836. };
  1837. _proto.compileAsyncEach = function compileAsyncEach(node, frame) {
  1838. this._compileAsyncLoop(node, frame);
  1839. };
  1840. _proto.compileAsyncAll = function compileAsyncAll(node, frame) {
  1841. this._compileAsyncLoop(node, frame, true);
  1842. };
  1843. _proto._compileMacro = function _compileMacro(node, frame) {
  1844. var _this12 = this;
  1845. var args = [];
  1846. var kwargs = null;
  1847. var funcId = 'macro_' + this._tmpid();
  1848. var keepFrame = frame !== undefined; // Type check the definition of the args
  1849. node.args.children.forEach(function (arg, i) {
  1850. if (i === node.args.children.length - 1 && arg instanceof nodes.Dict) {
  1851. kwargs = arg;
  1852. } else {
  1853. _this12.assertType(arg, nodes.Symbol);
  1854. args.push(arg);
  1855. }
  1856. });
  1857. var realNames = [].concat(args.map(function (n) {
  1858. return "l_" + n.value;
  1859. }), ['kwargs']); // Quoted argument names
  1860. var argNames = args.map(function (n) {
  1861. return "\"" + n.value + "\"";
  1862. });
  1863. var kwargNames = (kwargs && kwargs.children || []).map(function (n) {
  1864. return "\"" + n.key.value + "\"";
  1865. }); // We pass a function to makeMacro which destructures the
  1866. // arguments so support setting positional args with keywords
  1867. // args and passing keyword args as positional args
  1868. // (essentially default values). See runtime.js.
  1869. var currFrame;
  1870. if (keepFrame) {
  1871. currFrame = frame.push(true);
  1872. } else {
  1873. currFrame = new Frame();
  1874. }
  1875. this._emitLines("var " + funcId + " = runtime.makeMacro(", "[" + argNames.join(', ') + "], ", "[" + kwargNames.join(', ') + "], ", "function (" + realNames.join(', ') + ") {", 'var callerFrame = frame;', 'frame = ' + (keepFrame ? 'frame.push(true);' : 'new runtime.Frame();'), 'kwargs = kwargs || {};', 'if (Object.prototype.hasOwnProperty.call(kwargs, "caller")) {', 'frame.set("caller", kwargs.caller); }'); // Expose the arguments to the template. Don't need to use
  1876. // random names because the function
  1877. // will create a new run-time scope for us
  1878. args.forEach(function (arg) {
  1879. _this12._emitLine("frame.set(\"" + arg.value + "\", l_" + arg.value + ");");
  1880. currFrame.set(arg.value, "l_" + arg.value);
  1881. }); // Expose the keyword arguments
  1882. if (kwargs) {
  1883. kwargs.children.forEach(function (pair) {
  1884. var name = pair.key.value;
  1885. _this12._emit("frame.set(\"" + name + "\", ");
  1886. _this12._emit("Object.prototype.hasOwnProperty.call(kwargs, \"" + name + "\")");
  1887. _this12._emit(" ? kwargs[\"" + name + "\"] : ");
  1888. _this12._compileExpression(pair.value, currFrame);
  1889. _this12._emit(');');
  1890. });
  1891. }
  1892. var bufferId = this._pushBuffer();
  1893. this._withScopedSyntax(function () {
  1894. _this12.compile(node.body, currFrame);
  1895. });
  1896. this._emitLine('frame = ' + (keepFrame ? 'frame.pop();' : 'callerFrame;'));
  1897. this._emitLine("return new runtime.SafeString(" + bufferId + ");");
  1898. this._emitLine('});');
  1899. this._popBuffer();
  1900. return funcId;
  1901. };
  1902. _proto.compileMacro = function compileMacro(node, frame) {
  1903. var funcId = this._compileMacro(node); // Expose the macro to the templates
  1904. var name = node.name.value;
  1905. frame.set(name, funcId);
  1906. if (frame.parent) {
  1907. this._emitLine("frame.set(\"" + name + "\", " + funcId + ");");
  1908. } else {
  1909. if (node.name.value.charAt(0) !== '_') {
  1910. this._emitLine("context.addExport(\"" + name + "\");");
  1911. }
  1912. this._emitLine("context.setVariable(\"" + name + "\", " + funcId + ");");
  1913. }
  1914. };
  1915. _proto.compileCaller = function compileCaller(node, frame) {
  1916. // basically an anonymous "macro expression"
  1917. this._emit('(function (){');
  1918. var funcId = this._compileMacro(node, frame);
  1919. this._emit("return " + funcId + ";})()");
  1920. };
  1921. _proto._compileGetTemplate = function _compileGetTemplate(node, frame, eagerCompile, ignoreMissing) {
  1922. var parentTemplateId = this._tmpid();
  1923. var parentName = this._templateName();
  1924. var cb = this._makeCallback(parentTemplateId);
  1925. var eagerCompileArg = eagerCompile ? 'true' : 'false';
  1926. var ignoreMissingArg = ignoreMissing ? 'true' : 'false';
  1927. this._emit('env.getTemplate(');
  1928. this._compileExpression(node.template, frame);
  1929. this._emitLine(", " + eagerCompileArg + ", " + parentName + ", " + ignoreMissingArg + ", " + cb);
  1930. return parentTemplateId;
  1931. };
  1932. _proto.compileImport = function compileImport(node, frame) {
  1933. var target = node.target.value;
  1934. var id = this._compileGetTemplate(node, frame, false, false);
  1935. this._addScopeLevel();
  1936. this._emitLine(id + '.getExported(' + (node.withContext ? 'context.getVariables(), frame, ' : '') + this._makeCallback(id));
  1937. this._addScopeLevel();
  1938. frame.set(target, id);
  1939. if (frame.parent) {
  1940. this._emitLine("frame.set(\"" + target + "\", " + id + ");");
  1941. } else {
  1942. this._emitLine("context.setVariable(\"" + target + "\", " + id + ");");
  1943. }
  1944. };
  1945. _proto.compileFromImport = function compileFromImport(node, frame) {
  1946. var _this13 = this;
  1947. var importedId = this._compileGetTemplate(node, frame, false, false);
  1948. this._addScopeLevel();
  1949. this._emitLine(importedId + '.getExported(' + (node.withContext ? 'context.getVariables(), frame, ' : '') + this._makeCallback(importedId));
  1950. this._addScopeLevel();
  1951. node.names.children.forEach(function (nameNode) {
  1952. var name;
  1953. var alias;
  1954. var id = _this13._tmpid();
  1955. if (nameNode instanceof nodes.Pair) {
  1956. name = nameNode.key.value;
  1957. alias = nameNode.value.value;
  1958. } else {
  1959. name = nameNode.value;
  1960. alias = name;
  1961. }
  1962. _this13._emitLine("if(Object.prototype.hasOwnProperty.call(" + importedId + ", \"" + name + "\")) {");
  1963. _this13._emitLine("var " + id + " = " + importedId + "." + name + ";");
  1964. _this13._emitLine('} else {');
  1965. _this13._emitLine("cb(new Error(\"cannot import '" + name + "'\")); return;");
  1966. _this13._emitLine('}');
  1967. frame.set(alias, id);
  1968. if (frame.parent) {
  1969. _this13._emitLine("frame.set(\"" + alias + "\", " + id + ");");
  1970. } else {
  1971. _this13._emitLine("context.setVariable(\"" + alias + "\", " + id + ");");
  1972. }
  1973. });
  1974. };
  1975. _proto.compileBlock = function compileBlock(node) {
  1976. var id = this._tmpid(); // If we are executing outside a block (creating a top-level
  1977. // block), we really don't want to execute its code because it
  1978. // will execute twice: once when the child template runs and
  1979. // again when the parent template runs. Note that blocks
  1980. // within blocks will *always* execute immediately *and*
  1981. // wherever else they are invoked (like used in a parent
  1982. // template). This may have behavioral differences from jinja
  1983. // because blocks can have side effects, but it seems like a
  1984. // waste of performance to always execute huge top-level
  1985. // blocks twice
  1986. if (!this.inBlock) {
  1987. this._emit('(parentTemplate ? function(e, c, f, r, cb) { cb(""); } : ');
  1988. }
  1989. this._emit("context.getBlock(\"" + node.name.value + "\")");
  1990. if (!this.inBlock) {
  1991. this._emit(')');
  1992. }
  1993. this._emitLine('(env, context, frame, runtime, ' + this._makeCallback(id));
  1994. this._emitLine(this.buffer + " += " + id + ";");
  1995. this._addScopeLevel();
  1996. };
  1997. _proto.compileSuper = function compileSuper(node, frame) {
  1998. var name = node.blockName.value;
  1999. var id = node.symbol.value;
  2000. var cb = this._makeCallback(id);
  2001. this._emitLine("context.getSuper(env, \"" + name + "\", b_" + name + ", frame, runtime, " + cb);
  2002. this._emitLine(id + " = runtime.markSafe(" + id + ");");
  2003. this._addScopeLevel();
  2004. frame.set(id, id);
  2005. };
  2006. _proto.compileExtends = function compileExtends(node, frame) {
  2007. var k = this._tmpid();
  2008. var parentTemplateId = this._compileGetTemplate(node, frame, true, false); // extends is a dynamic tag and can occur within a block like
  2009. // `if`, so if this happens we need to capture the parent
  2010. // template in the top-level scope
  2011. this._emitLine("parentTemplate = " + parentTemplateId);
  2012. this._emitLine("for(var " + k + " in parentTemplate.blocks) {");
  2013. this._emitLine("context.addBlock(" + k + ", parentTemplate.blocks[" + k + "]);");
  2014. this._emitLine('}');
  2015. this._addScopeLevel();
  2016. };
  2017. _proto.compileInclude = function compileInclude(node, frame) {
  2018. this._emitLine('var tasks = [];');
  2019. this._emitLine('tasks.push(');
  2020. this._emitLine('function(callback) {');
  2021. var id = this._compileGetTemplate(node, frame, false, node.ignoreMissing);
  2022. this._emitLine("callback(null," + id + ");});");
  2023. this._emitLine('});');
  2024. var id2 = this._tmpid();
  2025. this._emitLine('tasks.push(');
  2026. this._emitLine('function(template, callback){');
  2027. this._emitLine('template.render(context.getVariables(), frame, ' + this._makeCallback(id2));
  2028. this._emitLine('callback(null,' + id2 + ');});');
  2029. this._emitLine('});');
  2030. this._emitLine('tasks.push(');
  2031. this._emitLine('function(result, callback){');
  2032. this._emitLine(this.buffer + " += result;");
  2033. this._emitLine('callback(null);');
  2034. this._emitLine('});');
  2035. this._emitLine('env.waterfall(tasks, function(){');
  2036. this._addScopeLevel();
  2037. };
  2038. _proto.compileTemplateData = function compileTemplateData(node, frame) {
  2039. this.compileLiteral(node, frame);
  2040. };
  2041. _proto.compileCapture = function compileCapture(node, frame) {
  2042. var _this14 = this;
  2043. // we need to temporarily override the current buffer id as 'output'
  2044. // so the set block writes to the capture output instead of the buffer
  2045. var buffer = this.buffer;
  2046. this.buffer = 'output';
  2047. this._emitLine('(function() {');
  2048. this._emitLine('var output = "";');
  2049. this._withScopedSyntax(function () {
  2050. _this14.compile(node.body, frame);
  2051. });
  2052. this._emitLine('return output;');
  2053. this._emitLine('})()'); // and of course, revert back to the old buffer id
  2054. this.buffer = buffer;
  2055. };
  2056. _proto.compileOutput = function compileOutput(node, frame) {
  2057. var _this15 = this;
  2058. var children = node.children;
  2059. children.forEach(function (child) {
  2060. // TemplateData is a special case because it is never
  2061. // autoescaped, so simply output it for optimization
  2062. if (child instanceof nodes.TemplateData) {
  2063. if (child.value) {
  2064. _this15._emit(_this15.buffer + " += ");
  2065. _this15.compileLiteral(child, frame);
  2066. _this15._emitLine(';');
  2067. }
  2068. } else {
  2069. _this15._emit(_this15.buffer + " += runtime.suppressValue(");
  2070. if (_this15.throwOnUndefined) {
  2071. _this15._emit('runtime.ensureDefined(');
  2072. }
  2073. _this15.compile(child, frame);
  2074. if (_this15.throwOnUndefined) {
  2075. _this15._emit("," + node.lineno + "," + node.colno + ")");
  2076. }
  2077. _this15._emit(', env.opts.autoescape);\n');
  2078. }
  2079. });
  2080. };
  2081. _proto.compileRoot = function compileRoot(node, frame) {
  2082. var _this16 = this;
  2083. if (frame) {
  2084. this.fail('compileRoot: root node can\'t have frame');
  2085. }
  2086. frame = new Frame();
  2087. this._emitFuncBegin(node, 'root');
  2088. this._emitLine('var parentTemplate = null;');
  2089. this._compileChildren(node, frame);
  2090. this._emitLine('if(parentTemplate) {');
  2091. this._emitLine('parentTemplate.rootRenderFunc(env, context, frame, runtime, cb);');
  2092. this._emitLine('} else {');
  2093. this._emitLine("cb(null, " + this.buffer + ");");
  2094. this._emitLine('}');
  2095. this._emitFuncEnd(true);
  2096. this.inBlock = true;
  2097. var blockNames = [];
  2098. var blocks = node.findAll(nodes.Block);
  2099. blocks.forEach(function (block, i) {
  2100. var name = block.name.value;
  2101. if (blockNames.indexOf(name) !== -1) {
  2102. throw new Error("Block \"" + name + "\" defined more than once.");
  2103. }
  2104. blockNames.push(name);
  2105. _this16._emitFuncBegin(block, "b_" + name);
  2106. var tmpFrame = new Frame();
  2107. _this16._emitLine('var frame = frame.push(true);');
  2108. _this16.compile(block.body, tmpFrame);
  2109. _this16._emitFuncEnd();
  2110. });
  2111. this._emitLine('return {');
  2112. blocks.forEach(function (block, i) {
  2113. var blockName = "b_" + block.name.value;
  2114. _this16._emitLine(blockName + ": " + blockName + ",");
  2115. });
  2116. this._emitLine('root: root\n};');
  2117. };
  2118. _proto.compile = function compile(node, frame) {
  2119. var _compile = this['compile' + node.typename];
  2120. if (_compile) {
  2121. _compile.call(this, node, frame);
  2122. } else {
  2123. this.fail("compile: Cannot compile node: " + node.typename, node.lineno, node.colno);
  2124. }
  2125. };
  2126. _proto.getCode = function getCode() {
  2127. return this.codebuf.join('');
  2128. };
  2129. return Compiler;
  2130. }(Obj);
  2131. module.exports = {
  2132. compile: function compile(src, asyncFilters, extensions, name, opts) {
  2133. if (opts === void 0) {
  2134. opts = {};
  2135. }
  2136. var c = new Compiler(name, opts.throwOnUndefined); // Run the extension preprocessors against the source.
  2137. var preprocessors = (extensions || []).map(function (ext) {
  2138. return ext.preprocess;
  2139. }).filter(function (f) {
  2140. return !!f;
  2141. });
  2142. var processedSrc = preprocessors.reduce(function (s, processor) {
  2143. return processor(s);
  2144. }, src);
  2145. c.compile(transformer.transform(parser.parse(processedSrc, extensions, opts), asyncFilters, name));
  2146. return c.getCode();
  2147. },
  2148. Compiler: Compiler
  2149. };
  2150. /***/ }),
  2151. /* 6 */
  2152. /***/ (function(module, exports, __webpack_require__) {
  2153. "use strict";
  2154. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  2155. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  2156. var path = __webpack_require__(4);
  2157. var _require = __webpack_require__(1),
  2158. EmitterObj = _require.EmitterObj;
  2159. module.exports = /*#__PURE__*/function (_EmitterObj) {
  2160. _inheritsLoose(Loader, _EmitterObj);
  2161. function Loader() {
  2162. return _EmitterObj.apply(this, arguments) || this;
  2163. }
  2164. var _proto = Loader.prototype;
  2165. _proto.resolve = function resolve(from, to) {
  2166. return path.resolve(path.dirname(from), to);
  2167. };
  2168. _proto.isRelative = function isRelative(filename) {
  2169. return filename.indexOf('./') === 0 || filename.indexOf('../') === 0;
  2170. };
  2171. return Loader;
  2172. }(EmitterObj);
  2173. /***/ }),
  2174. /* 7 */
  2175. /***/ (function(module, exports, __webpack_require__) {
  2176. "use strict";
  2177. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  2178. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  2179. var asap = __webpack_require__(12);
  2180. var _waterfall = __webpack_require__(15);
  2181. var lib = __webpack_require__(0);
  2182. var compiler = __webpack_require__(5);
  2183. var filters = __webpack_require__(18);
  2184. var _require = __webpack_require__(10),
  2185. FileSystemLoader = _require.FileSystemLoader,
  2186. WebLoader = _require.WebLoader,
  2187. PrecompiledLoader = _require.PrecompiledLoader;
  2188. var tests = __webpack_require__(20);
  2189. var globals = __webpack_require__(21);
  2190. var _require2 = __webpack_require__(1),
  2191. Obj = _require2.Obj,
  2192. EmitterObj = _require2.EmitterObj;
  2193. var globalRuntime = __webpack_require__(2);
  2194. var handleError = globalRuntime.handleError,
  2195. Frame = globalRuntime.Frame;
  2196. var expressApp = __webpack_require__(22); // If the user is using the async API, *always* call it
  2197. // asynchronously even if the template was synchronous.
  2198. function callbackAsap(cb, err, res) {
  2199. asap(function () {
  2200. cb(err, res);
  2201. });
  2202. }
  2203. /**
  2204. * A no-op template, for use with {% include ignore missing %}
  2205. */
  2206. var noopTmplSrc = {
  2207. type: 'code',
  2208. obj: {
  2209. root: function root(env, context, frame, runtime, cb) {
  2210. try {
  2211. cb(null, '');
  2212. } catch (e) {
  2213. cb(handleError(e, null, null));
  2214. }
  2215. }
  2216. }
  2217. };
  2218. var Environment = /*#__PURE__*/function (_EmitterObj) {
  2219. _inheritsLoose(Environment, _EmitterObj);
  2220. function Environment() {
  2221. return _EmitterObj.apply(this, arguments) || this;
  2222. }
  2223. var _proto = Environment.prototype;
  2224. _proto.init = function init(loaders, opts) {
  2225. var _this = this;
  2226. // The dev flag determines the trace that'll be shown on errors.
  2227. // If set to true, returns the full trace from the error point,
  2228. // otherwise will return trace starting from Template.render
  2229. // (the full trace from within nunjucks may confuse developers using
  2230. // the library)
  2231. // defaults to false
  2232. opts = this.opts = opts || {};
  2233. this.opts.dev = !!opts.dev; // The autoescape flag sets global autoescaping. If true,
  2234. // every string variable will be escaped by default.
  2235. // If false, strings can be manually escaped using the `escape` filter.
  2236. // defaults to true
  2237. this.opts.autoescape = opts.autoescape != null ? opts.autoescape : true; // If true, this will make the system throw errors if trying
  2238. // to output a null or undefined value
  2239. this.opts.throwOnUndefined = !!opts.throwOnUndefined;
  2240. this.opts.trimBlocks = !!opts.trimBlocks;
  2241. this.opts.lstripBlocks = !!opts.lstripBlocks;
  2242. this.loaders = [];
  2243. if (!loaders) {
  2244. // The filesystem loader is only available server-side
  2245. if (FileSystemLoader) {
  2246. this.loaders = [new FileSystemLoader('views')];
  2247. } else if (WebLoader) {
  2248. this.loaders = [new WebLoader('/views')];
  2249. }
  2250. } else {
  2251. this.loaders = lib.isArray(loaders) ? loaders : [loaders];
  2252. } // It's easy to use precompiled templates: just include them
  2253. // before you configure nunjucks and this will automatically
  2254. // pick it up and use it
  2255. if (typeof window !== 'undefined' && window.nunjucksPrecompiled) {
  2256. this.loaders.unshift(new PrecompiledLoader(window.nunjucksPrecompiled));
  2257. }
  2258. this._initLoaders();
  2259. this.globals = globals();
  2260. this.filters = {};
  2261. this.tests = {};
  2262. this.asyncFilters = [];
  2263. this.extensions = {};
  2264. this.extensionsList = [];
  2265. lib._entries(filters).forEach(function (_ref) {
  2266. var name = _ref[0],
  2267. filter = _ref[1];
  2268. return _this.addFilter(name, filter);
  2269. });
  2270. lib._entries(tests).forEach(function (_ref2) {
  2271. var name = _ref2[0],
  2272. test = _ref2[1];
  2273. return _this.addTest(name, test);
  2274. });
  2275. };
  2276. _proto._initLoaders = function _initLoaders() {
  2277. var _this2 = this;
  2278. this.loaders.forEach(function (loader) {
  2279. // Caching and cache busting
  2280. loader.cache = {};
  2281. if (typeof loader.on === 'function') {
  2282. loader.on('update', function (name, fullname) {
  2283. loader.cache[name] = null;
  2284. _this2.emit('update', name, fullname, loader);
  2285. });
  2286. loader.on('load', function (name, source) {
  2287. _this2.emit('load', name, source, loader);
  2288. });
  2289. }
  2290. });
  2291. };
  2292. _proto.invalidateCache = function invalidateCache() {
  2293. this.loaders.forEach(function (loader) {
  2294. loader.cache = {};
  2295. });
  2296. };
  2297. _proto.addExtension = function addExtension(name, extension) {
  2298. extension.__name = name;
  2299. this.extensions[name] = extension;
  2300. this.extensionsList.push(extension);
  2301. return this;
  2302. };
  2303. _proto.removeExtension = function removeExtension(name) {
  2304. var extension = this.getExtension(name);
  2305. if (!extension) {
  2306. return;
  2307. }
  2308. this.extensionsList = lib.without(this.extensionsList, extension);
  2309. delete this.extensions[name];
  2310. };
  2311. _proto.getExtension = function getExtension(name) {
  2312. return this.extensions[name];
  2313. };
  2314. _proto.hasExtension = function hasExtension(name) {
  2315. return !!this.extensions[name];
  2316. };
  2317. _proto.addGlobal = function addGlobal(name, value) {
  2318. this.globals[name] = value;
  2319. return this;
  2320. };
  2321. _proto.getGlobal = function getGlobal(name) {
  2322. if (typeof this.globals[name] === 'undefined') {
  2323. throw new Error('global not found: ' + name);
  2324. }
  2325. return this.globals[name];
  2326. };
  2327. _proto.addFilter = function addFilter(name, func, async) {
  2328. var wrapped = func;
  2329. if (async) {
  2330. this.asyncFilters.push(name);
  2331. }
  2332. this.filters[name] = wrapped;
  2333. return this;
  2334. };
  2335. _proto.getFilter = function getFilter(name) {
  2336. if (!this.filters[name]) {
  2337. throw new Error('filter not found: ' + name);
  2338. }
  2339. return this.filters[name];
  2340. };
  2341. _proto.addTest = function addTest(name, func) {
  2342. this.tests[name] = func;
  2343. return this;
  2344. };
  2345. _proto.getTest = function getTest(name) {
  2346. if (!this.tests[name]) {
  2347. throw new Error('test not found: ' + name);
  2348. }
  2349. return this.tests[name];
  2350. };
  2351. _proto.resolveTemplate = function resolveTemplate(loader, parentName, filename) {
  2352. var isRelative = loader.isRelative && parentName ? loader.isRelative(filename) : false;
  2353. return isRelative && loader.resolve ? loader.resolve(parentName, filename) : filename;
  2354. };
  2355. _proto.getTemplate = function getTemplate(name, eagerCompile, parentName, ignoreMissing, cb) {
  2356. var _this3 = this;
  2357. var that = this;
  2358. var tmpl = null;
  2359. if (name && name.raw) {
  2360. // this fixes autoescape for templates referenced in symbols
  2361. name = name.raw;
  2362. }
  2363. if (lib.isFunction(parentName)) {
  2364. cb = parentName;
  2365. parentName = null;
  2366. eagerCompile = eagerCompile || false;
  2367. }
  2368. if (lib.isFunction(eagerCompile)) {
  2369. cb = eagerCompile;
  2370. eagerCompile = false;
  2371. }
  2372. if (name instanceof Template) {
  2373. tmpl = name;
  2374. } else if (typeof name !== 'string') {
  2375. throw new Error('template names must be a string: ' + name);
  2376. } else {
  2377. for (var i = 0; i < this.loaders.length; i++) {
  2378. var loader = this.loaders[i];
  2379. tmpl = loader.cache[this.resolveTemplate(loader, parentName, name)];
  2380. if (tmpl) {
  2381. break;
  2382. }
  2383. }
  2384. }
  2385. if (tmpl) {
  2386. if (eagerCompile) {
  2387. tmpl.compile();
  2388. }
  2389. if (cb) {
  2390. cb(null, tmpl);
  2391. return undefined;
  2392. } else {
  2393. return tmpl;
  2394. }
  2395. }
  2396. var syncResult;
  2397. var createTemplate = function createTemplate(err, info) {
  2398. if (!info && !err && !ignoreMissing) {
  2399. err = new Error('template not found: ' + name);
  2400. }
  2401. if (err) {
  2402. if (cb) {
  2403. cb(err);
  2404. return;
  2405. } else {
  2406. throw err;
  2407. }
  2408. }
  2409. var newTmpl;
  2410. if (!info) {
  2411. newTmpl = new Template(noopTmplSrc, _this3, '', eagerCompile);
  2412. } else {
  2413. newTmpl = new Template(info.src, _this3, info.path, eagerCompile);
  2414. if (!info.noCache) {
  2415. info.loader.cache[name] = newTmpl;
  2416. }
  2417. }
  2418. if (cb) {
  2419. cb(null, newTmpl);
  2420. } else {
  2421. syncResult = newTmpl;
  2422. }
  2423. };
  2424. lib.asyncIter(this.loaders, function (loader, i, next, done) {
  2425. function handle(err, src) {
  2426. if (err) {
  2427. done(err);
  2428. } else if (src) {
  2429. src.loader = loader;
  2430. done(null, src);
  2431. } else {
  2432. next();
  2433. }
  2434. } // Resolve name relative to parentName
  2435. name = that.resolveTemplate(loader, parentName, name);
  2436. if (loader.async) {
  2437. loader.getSource(name, handle);
  2438. } else {
  2439. handle(null, loader.getSource(name));
  2440. }
  2441. }, createTemplate);
  2442. return syncResult;
  2443. };
  2444. _proto.express = function express(app) {
  2445. return expressApp(this, app);
  2446. };
  2447. _proto.render = function render(name, ctx, cb) {
  2448. if (lib.isFunction(ctx)) {
  2449. cb = ctx;
  2450. ctx = null;
  2451. } // We support a synchronous API to make it easier to migrate
  2452. // existing code to async. This works because if you don't do
  2453. // anything async work, the whole thing is actually run
  2454. // synchronously.
  2455. var syncResult = null;
  2456. this.getTemplate(name, function (err, tmpl) {
  2457. if (err && cb) {
  2458. callbackAsap(cb, err);
  2459. } else if (err) {
  2460. throw err;
  2461. } else {
  2462. syncResult = tmpl.render(ctx, cb);
  2463. }
  2464. });
  2465. return syncResult;
  2466. };
  2467. _proto.renderString = function renderString(src, ctx, opts, cb) {
  2468. if (lib.isFunction(opts)) {
  2469. cb = opts;
  2470. opts = {};
  2471. }
  2472. opts = opts || {};
  2473. var tmpl = new Template(src, this, opts.path);
  2474. return tmpl.render(ctx, cb);
  2475. };
  2476. _proto.waterfall = function waterfall(tasks, callback, forceAsync) {
  2477. return _waterfall(tasks, callback, forceAsync);
  2478. };
  2479. return Environment;
  2480. }(EmitterObj);
  2481. var Context = /*#__PURE__*/function (_Obj) {
  2482. _inheritsLoose(Context, _Obj);
  2483. function Context() {
  2484. return _Obj.apply(this, arguments) || this;
  2485. }
  2486. var _proto2 = Context.prototype;
  2487. _proto2.init = function init(ctx, blocks, env) {
  2488. var _this4 = this;
  2489. // Has to be tied to an environment so we can tap into its globals.
  2490. this.env = env || new Environment(); // Make a duplicate of ctx
  2491. this.ctx = lib.extend({}, ctx);
  2492. this.blocks = {};
  2493. this.exported = [];
  2494. lib.keys(blocks).forEach(function (name) {
  2495. _this4.addBlock(name, blocks[name]);
  2496. });
  2497. };
  2498. _proto2.lookup = function lookup(name) {
  2499. // This is one of the most called functions, so optimize for
  2500. // the typical case where the name isn't in the globals
  2501. if (name in this.env.globals && !(name in this.ctx)) {
  2502. return this.env.globals[name];
  2503. } else {
  2504. return this.ctx[name];
  2505. }
  2506. };
  2507. _proto2.setVariable = function setVariable(name, val) {
  2508. this.ctx[name] = val;
  2509. };
  2510. _proto2.getVariables = function getVariables() {
  2511. return this.ctx;
  2512. };
  2513. _proto2.addBlock = function addBlock(name, block) {
  2514. this.blocks[name] = this.blocks[name] || [];
  2515. this.blocks[name].push(block);
  2516. return this;
  2517. };
  2518. _proto2.getBlock = function getBlock(name) {
  2519. if (!this.blocks[name]) {
  2520. throw new Error('unknown block "' + name + '"');
  2521. }
  2522. return this.blocks[name][0];
  2523. };
  2524. _proto2.getSuper = function getSuper(env, name, block, frame, runtime, cb) {
  2525. var idx = lib.indexOf(this.blocks[name] || [], block);
  2526. var blk = this.blocks[name][idx + 1];
  2527. var context = this;
  2528. if (idx === -1 || !blk) {
  2529. throw new Error('no super block available for "' + name + '"');
  2530. }
  2531. blk(env, context, frame, runtime, cb);
  2532. };
  2533. _proto2.addExport = function addExport(name) {
  2534. this.exported.push(name);
  2535. };
  2536. _proto2.getExported = function getExported() {
  2537. var _this5 = this;
  2538. var exported = {};
  2539. this.exported.forEach(function (name) {
  2540. exported[name] = _this5.ctx[name];
  2541. });
  2542. return exported;
  2543. };
  2544. return Context;
  2545. }(Obj);
  2546. var Template = /*#__PURE__*/function (_Obj2) {
  2547. _inheritsLoose(Template, _Obj2);
  2548. function Template() {
  2549. return _Obj2.apply(this, arguments) || this;
  2550. }
  2551. var _proto3 = Template.prototype;
  2552. _proto3.init = function init(src, env, path, eagerCompile) {
  2553. this.env = env || new Environment();
  2554. if (lib.isObject(src)) {
  2555. switch (src.type) {
  2556. case 'code':
  2557. this.tmplProps = src.obj;
  2558. break;
  2559. case 'string':
  2560. this.tmplStr = src.obj;
  2561. break;
  2562. default:
  2563. throw new Error("Unexpected template object type " + src.type + "; expected 'code', or 'string'");
  2564. }
  2565. } else if (lib.isString(src)) {
  2566. this.tmplStr = src;
  2567. } else {
  2568. throw new Error('src must be a string or an object describing the source');
  2569. }
  2570. this.path = path;
  2571. if (eagerCompile) {
  2572. try {
  2573. this._compile();
  2574. } catch (err) {
  2575. throw lib._prettifyError(this.path, this.env.opts.dev, err);
  2576. }
  2577. } else {
  2578. this.compiled = false;
  2579. }
  2580. };
  2581. _proto3.render = function render(ctx, parentFrame, cb) {
  2582. var _this6 = this;
  2583. if (typeof ctx === 'function') {
  2584. cb = ctx;
  2585. ctx = {};
  2586. } else if (typeof parentFrame === 'function') {
  2587. cb = parentFrame;
  2588. parentFrame = null;
  2589. } // If there is a parent frame, we are being called from internal
  2590. // code of another template, and the internal system
  2591. // depends on the sync/async nature of the parent template
  2592. // to be inherited, so force an async callback
  2593. var forceAsync = !parentFrame; // Catch compile errors for async rendering
  2594. try {
  2595. this.compile();
  2596. } catch (e) {
  2597. var err = lib._prettifyError(this.path, this.env.opts.dev, e);
  2598. if (cb) {
  2599. return callbackAsap(cb, err);
  2600. } else {
  2601. throw err;
  2602. }
  2603. }
  2604. var context = new Context(ctx || {}, this.blocks, this.env);
  2605. var frame = parentFrame ? parentFrame.push(true) : new Frame();
  2606. frame.topLevel = true;
  2607. var syncResult = null;
  2608. var didError = false;
  2609. this.rootRenderFunc(this.env, context, frame, globalRuntime, function (err, res) {
  2610. // TODO: this is actually a bug in the compiled template (because waterfall
  2611. // tasks are both not passing errors up the chain of callbacks AND are not
  2612. // causing a return from the top-most render function). But fixing that
  2613. // will require a more substantial change to the compiler.
  2614. if (didError && cb && typeof res !== 'undefined') {
  2615. // prevent multiple calls to cb
  2616. return;
  2617. }
  2618. if (err) {
  2619. err = lib._prettifyError(_this6.path, _this6.env.opts.dev, err);
  2620. didError = true;
  2621. }
  2622. if (cb) {
  2623. if (forceAsync) {
  2624. callbackAsap(cb, err, res);
  2625. } else {
  2626. cb(err, res);
  2627. }
  2628. } else {
  2629. if (err) {
  2630. throw err;
  2631. }
  2632. syncResult = res;
  2633. }
  2634. });
  2635. return syncResult;
  2636. };
  2637. _proto3.getExported = function getExported(ctx, parentFrame, cb) {
  2638. // eslint-disable-line consistent-return
  2639. if (typeof ctx === 'function') {
  2640. cb = ctx;
  2641. ctx = {};
  2642. }
  2643. if (typeof parentFrame === 'function') {
  2644. cb = parentFrame;
  2645. parentFrame = null;
  2646. } // Catch compile errors for async rendering
  2647. try {
  2648. this.compile();
  2649. } catch (e) {
  2650. if (cb) {
  2651. return cb(e);
  2652. } else {
  2653. throw e;
  2654. }
  2655. }
  2656. var frame = parentFrame ? parentFrame.push() : new Frame();
  2657. frame.topLevel = true; // Run the rootRenderFunc to populate the context with exported vars
  2658. var context = new Context(ctx || {}, this.blocks, this.env);
  2659. this.rootRenderFunc(this.env, context, frame, globalRuntime, function (err) {
  2660. if (err) {
  2661. cb(err, null);
  2662. } else {
  2663. cb(null, context.getExported());
  2664. }
  2665. });
  2666. };
  2667. _proto3.compile = function compile() {
  2668. if (!this.compiled) {
  2669. this._compile();
  2670. }
  2671. };
  2672. _proto3._compile = function _compile() {
  2673. var props;
  2674. if (this.tmplProps) {
  2675. props = this.tmplProps;
  2676. } else {
  2677. var source = compiler.compile(this.tmplStr, this.env.asyncFilters, this.env.extensionsList, this.path, this.env.opts);
  2678. var func = new Function(source); // eslint-disable-line no-new-func
  2679. props = func();
  2680. }
  2681. this.blocks = this._getBlocks(props);
  2682. this.rootRenderFunc = props.root;
  2683. this.compiled = true;
  2684. };
  2685. _proto3._getBlocks = function _getBlocks(props) {
  2686. var blocks = {};
  2687. lib.keys(props).forEach(function (k) {
  2688. if (k.slice(0, 2) === 'b_') {
  2689. blocks[k.slice(2)] = props[k];
  2690. }
  2691. });
  2692. return blocks;
  2693. };
  2694. return Template;
  2695. }(Obj);
  2696. module.exports = {
  2697. Environment: Environment,
  2698. Template: Template
  2699. };
  2700. /***/ }),
  2701. /* 8 */
  2702. /***/ (function(module, exports, __webpack_require__) {
  2703. "use strict";
  2704. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  2705. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  2706. var lexer = __webpack_require__(9);
  2707. var nodes = __webpack_require__(3);
  2708. var Obj = __webpack_require__(1).Obj;
  2709. var lib = __webpack_require__(0);
  2710. var Parser = /*#__PURE__*/function (_Obj) {
  2711. _inheritsLoose(Parser, _Obj);
  2712. function Parser() {
  2713. return _Obj.apply(this, arguments) || this;
  2714. }
  2715. var _proto = Parser.prototype;
  2716. _proto.init = function init(tokens) {
  2717. this.tokens = tokens;
  2718. this.peeked = null;
  2719. this.breakOnBlocks = null;
  2720. this.dropLeadingWhitespace = false;
  2721. this.extensions = [];
  2722. };
  2723. _proto.nextToken = function nextToken(withWhitespace) {
  2724. var tok;
  2725. if (this.peeked) {
  2726. if (!withWhitespace && this.peeked.type === lexer.TOKEN_WHITESPACE) {
  2727. this.peeked = null;
  2728. } else {
  2729. tok = this.peeked;
  2730. this.peeked = null;
  2731. return tok;
  2732. }
  2733. }
  2734. tok = this.tokens.nextToken();
  2735. if (!withWhitespace) {
  2736. while (tok && tok.type === lexer.TOKEN_WHITESPACE) {
  2737. tok = this.tokens.nextToken();
  2738. }
  2739. }
  2740. return tok;
  2741. };
  2742. _proto.peekToken = function peekToken() {
  2743. this.peeked = this.peeked || this.nextToken();
  2744. return this.peeked;
  2745. };
  2746. _proto.pushToken = function pushToken(tok) {
  2747. if (this.peeked) {
  2748. throw new Error('pushToken: can only push one token on between reads');
  2749. }
  2750. this.peeked = tok;
  2751. };
  2752. _proto.error = function error(msg, lineno, colno) {
  2753. if (lineno === undefined || colno === undefined) {
  2754. var tok = this.peekToken() || {};
  2755. lineno = tok.lineno;
  2756. colno = tok.colno;
  2757. }
  2758. if (lineno !== undefined) {
  2759. lineno += 1;
  2760. }
  2761. if (colno !== undefined) {
  2762. colno += 1;
  2763. }
  2764. return new lib.TemplateError(msg, lineno, colno);
  2765. };
  2766. _proto.fail = function fail(msg, lineno, colno) {
  2767. throw this.error(msg, lineno, colno);
  2768. };
  2769. _proto.skip = function skip(type) {
  2770. var tok = this.nextToken();
  2771. if (!tok || tok.type !== type) {
  2772. this.pushToken(tok);
  2773. return false;
  2774. }
  2775. return true;
  2776. };
  2777. _proto.expect = function expect(type) {
  2778. var tok = this.nextToken();
  2779. if (tok.type !== type) {
  2780. this.fail('expected ' + type + ', got ' + tok.type, tok.lineno, tok.colno);
  2781. }
  2782. return tok;
  2783. };
  2784. _proto.skipValue = function skipValue(type, val) {
  2785. var tok = this.nextToken();
  2786. if (!tok || tok.type !== type || tok.value !== val) {
  2787. this.pushToken(tok);
  2788. return false;
  2789. }
  2790. return true;
  2791. };
  2792. _proto.skipSymbol = function skipSymbol(val) {
  2793. return this.skipValue(lexer.TOKEN_SYMBOL, val);
  2794. };
  2795. _proto.advanceAfterBlockEnd = function advanceAfterBlockEnd(name) {
  2796. var tok;
  2797. if (!name) {
  2798. tok = this.peekToken();
  2799. if (!tok) {
  2800. this.fail('unexpected end of file');
  2801. }
  2802. if (tok.type !== lexer.TOKEN_SYMBOL) {
  2803. this.fail('advanceAfterBlockEnd: expected symbol token or ' + 'explicit name to be passed');
  2804. }
  2805. name = this.nextToken().value;
  2806. }
  2807. tok = this.nextToken();
  2808. if (tok && tok.type === lexer.TOKEN_BLOCK_END) {
  2809. if (tok.value.charAt(0) === '-') {
  2810. this.dropLeadingWhitespace = true;
  2811. }
  2812. } else {
  2813. this.fail('expected block end in ' + name + ' statement');
  2814. }
  2815. return tok;
  2816. };
  2817. _proto.advanceAfterVariableEnd = function advanceAfterVariableEnd() {
  2818. var tok = this.nextToken();
  2819. if (tok && tok.type === lexer.TOKEN_VARIABLE_END) {
  2820. this.dropLeadingWhitespace = tok.value.charAt(tok.value.length - this.tokens.tags.VARIABLE_END.length - 1) === '-';
  2821. } else {
  2822. this.pushToken(tok);
  2823. this.fail('expected variable end');
  2824. }
  2825. };
  2826. _proto.parseFor = function parseFor() {
  2827. var forTok = this.peekToken();
  2828. var node;
  2829. var endBlock;
  2830. if (this.skipSymbol('for')) {
  2831. node = new nodes.For(forTok.lineno, forTok.colno);
  2832. endBlock = 'endfor';
  2833. } else if (this.skipSymbol('asyncEach')) {
  2834. node = new nodes.AsyncEach(forTok.lineno, forTok.colno);
  2835. endBlock = 'endeach';
  2836. } else if (this.skipSymbol('asyncAll')) {
  2837. node = new nodes.AsyncAll(forTok.lineno, forTok.colno);
  2838. endBlock = 'endall';
  2839. } else {
  2840. this.fail('parseFor: expected for{Async}', forTok.lineno, forTok.colno);
  2841. }
  2842. node.name = this.parsePrimary();
  2843. if (!(node.name instanceof nodes.Symbol)) {
  2844. this.fail('parseFor: variable name expected for loop');
  2845. }
  2846. var type = this.peekToken().type;
  2847. if (type === lexer.TOKEN_COMMA) {
  2848. // key/value iteration
  2849. var key = node.name;
  2850. node.name = new nodes.Array(key.lineno, key.colno);
  2851. node.name.addChild(key);
  2852. while (this.skip(lexer.TOKEN_COMMA)) {
  2853. var prim = this.parsePrimary();
  2854. node.name.addChild(prim);
  2855. }
  2856. }
  2857. if (!this.skipSymbol('in')) {
  2858. this.fail('parseFor: expected "in" keyword for loop', forTok.lineno, forTok.colno);
  2859. }
  2860. node.arr = this.parseExpression();
  2861. this.advanceAfterBlockEnd(forTok.value);
  2862. node.body = this.parseUntilBlocks(endBlock, 'else');
  2863. if (this.skipSymbol('else')) {
  2864. this.advanceAfterBlockEnd('else');
  2865. node.else_ = this.parseUntilBlocks(endBlock);
  2866. }
  2867. this.advanceAfterBlockEnd();
  2868. return node;
  2869. };
  2870. _proto.parseMacro = function parseMacro() {
  2871. var macroTok = this.peekToken();
  2872. if (!this.skipSymbol('macro')) {
  2873. this.fail('expected macro');
  2874. }
  2875. var name = this.parsePrimary(true);
  2876. var args = this.parseSignature();
  2877. var node = new nodes.Macro(macroTok.lineno, macroTok.colno, name, args);
  2878. this.advanceAfterBlockEnd(macroTok.value);
  2879. node.body = this.parseUntilBlocks('endmacro');
  2880. this.advanceAfterBlockEnd();
  2881. return node;
  2882. };
  2883. _proto.parseCall = function parseCall() {
  2884. // a call block is parsed as a normal FunCall, but with an added
  2885. // 'caller' kwarg which is a Caller node.
  2886. var callTok = this.peekToken();
  2887. if (!this.skipSymbol('call')) {
  2888. this.fail('expected call');
  2889. }
  2890. var callerArgs = this.parseSignature(true) || new nodes.NodeList();
  2891. var macroCall = this.parsePrimary();
  2892. this.advanceAfterBlockEnd(callTok.value);
  2893. var body = this.parseUntilBlocks('endcall');
  2894. this.advanceAfterBlockEnd();
  2895. var callerName = new nodes.Symbol(callTok.lineno, callTok.colno, 'caller');
  2896. var callerNode = new nodes.Caller(callTok.lineno, callTok.colno, callerName, callerArgs, body); // add the additional caller kwarg, adding kwargs if necessary
  2897. var args = macroCall.args.children;
  2898. if (!(args[args.length - 1] instanceof nodes.KeywordArgs)) {
  2899. args.push(new nodes.KeywordArgs());
  2900. }
  2901. var kwargs = args[args.length - 1];
  2902. kwargs.addChild(new nodes.Pair(callTok.lineno, callTok.colno, callerName, callerNode));
  2903. return new nodes.Output(callTok.lineno, callTok.colno, [macroCall]);
  2904. };
  2905. _proto.parseWithContext = function parseWithContext() {
  2906. var tok = this.peekToken();
  2907. var withContext = null;
  2908. if (this.skipSymbol('with')) {
  2909. withContext = true;
  2910. } else if (this.skipSymbol('without')) {
  2911. withContext = false;
  2912. }
  2913. if (withContext !== null) {
  2914. if (!this.skipSymbol('context')) {
  2915. this.fail('parseFrom: expected context after with/without', tok.lineno, tok.colno);
  2916. }
  2917. }
  2918. return withContext;
  2919. };
  2920. _proto.parseImport = function parseImport() {
  2921. var importTok = this.peekToken();
  2922. if (!this.skipSymbol('import')) {
  2923. this.fail('parseImport: expected import', importTok.lineno, importTok.colno);
  2924. }
  2925. var template = this.parseExpression();
  2926. if (!this.skipSymbol('as')) {
  2927. this.fail('parseImport: expected "as" keyword', importTok.lineno, importTok.colno);
  2928. }
  2929. var target = this.parseExpression();
  2930. var withContext = this.parseWithContext();
  2931. var node = new nodes.Import(importTok.lineno, importTok.colno, template, target, withContext);
  2932. this.advanceAfterBlockEnd(importTok.value);
  2933. return node;
  2934. };
  2935. _proto.parseFrom = function parseFrom() {
  2936. var fromTok = this.peekToken();
  2937. if (!this.skipSymbol('from')) {
  2938. this.fail('parseFrom: expected from');
  2939. }
  2940. var template = this.parseExpression();
  2941. if (!this.skipSymbol('import')) {
  2942. this.fail('parseFrom: expected import', fromTok.lineno, fromTok.colno);
  2943. }
  2944. var names = new nodes.NodeList();
  2945. var withContext;
  2946. while (1) {
  2947. // eslint-disable-line no-constant-condition
  2948. var nextTok = this.peekToken();
  2949. if (nextTok.type === lexer.TOKEN_BLOCK_END) {
  2950. if (!names.children.length) {
  2951. this.fail('parseFrom: Expected at least one import name', fromTok.lineno, fromTok.colno);
  2952. } // Since we are manually advancing past the block end,
  2953. // need to keep track of whitespace control (normally
  2954. // this is done in `advanceAfterBlockEnd`
  2955. if (nextTok.value.charAt(0) === '-') {
  2956. this.dropLeadingWhitespace = true;
  2957. }
  2958. this.nextToken();
  2959. break;
  2960. }
  2961. if (names.children.length > 0 && !this.skip(lexer.TOKEN_COMMA)) {
  2962. this.fail('parseFrom: expected comma', fromTok.lineno, fromTok.colno);
  2963. }
  2964. var name = this.parsePrimary();
  2965. if (name.value.charAt(0) === '_') {
  2966. this.fail('parseFrom: names starting with an underscore cannot be imported', name.lineno, name.colno);
  2967. }
  2968. if (this.skipSymbol('as')) {
  2969. var alias = this.parsePrimary();
  2970. names.addChild(new nodes.Pair(name.lineno, name.colno, name, alias));
  2971. } else {
  2972. names.addChild(name);
  2973. }
  2974. withContext = this.parseWithContext();
  2975. }
  2976. return new nodes.FromImport(fromTok.lineno, fromTok.colno, template, names, withContext);
  2977. };
  2978. _proto.parseBlock = function parseBlock() {
  2979. var tag = this.peekToken();
  2980. if (!this.skipSymbol('block')) {
  2981. this.fail('parseBlock: expected block', tag.lineno, tag.colno);
  2982. }
  2983. var node = new nodes.Block(tag.lineno, tag.colno);
  2984. node.name = this.parsePrimary();
  2985. if (!(node.name instanceof nodes.Symbol)) {
  2986. this.fail('parseBlock: variable name expected', tag.lineno, tag.colno);
  2987. }
  2988. this.advanceAfterBlockEnd(tag.value);
  2989. node.body = this.parseUntilBlocks('endblock');
  2990. this.skipSymbol('endblock');
  2991. this.skipSymbol(node.name.value);
  2992. var tok = this.peekToken();
  2993. if (!tok) {
  2994. this.fail('parseBlock: expected endblock, got end of file');
  2995. }
  2996. this.advanceAfterBlockEnd(tok.value);
  2997. return node;
  2998. };
  2999. _proto.parseExtends = function parseExtends() {
  3000. var tagName = 'extends';
  3001. var tag = this.peekToken();
  3002. if (!this.skipSymbol(tagName)) {
  3003. this.fail('parseTemplateRef: expected ' + tagName);
  3004. }
  3005. var node = new nodes.Extends(tag.lineno, tag.colno);
  3006. node.template = this.parseExpression();
  3007. this.advanceAfterBlockEnd(tag.value);
  3008. return node;
  3009. };
  3010. _proto.parseInclude = function parseInclude() {
  3011. var tagName = 'include';
  3012. var tag = this.peekToken();
  3013. if (!this.skipSymbol(tagName)) {
  3014. this.fail('parseInclude: expected ' + tagName);
  3015. }
  3016. var node = new nodes.Include(tag.lineno, tag.colno);
  3017. node.template = this.parseExpression();
  3018. if (this.skipSymbol('ignore') && this.skipSymbol('missing')) {
  3019. node.ignoreMissing = true;
  3020. }
  3021. this.advanceAfterBlockEnd(tag.value);
  3022. return node;
  3023. };
  3024. _proto.parseIf = function parseIf() {
  3025. var tag = this.peekToken();
  3026. var node;
  3027. if (this.skipSymbol('if') || this.skipSymbol('elif') || this.skipSymbol('elseif')) {
  3028. node = new nodes.If(tag.lineno, tag.colno);
  3029. } else if (this.skipSymbol('ifAsync')) {
  3030. node = new nodes.IfAsync(tag.lineno, tag.colno);
  3031. } else {
  3032. this.fail('parseIf: expected if, elif, or elseif', tag.lineno, tag.colno);
  3033. }
  3034. node.cond = this.parseExpression();
  3035. this.advanceAfterBlockEnd(tag.value);
  3036. node.body = this.parseUntilBlocks('elif', 'elseif', 'else', 'endif');
  3037. var tok = this.peekToken();
  3038. switch (tok && tok.value) {
  3039. case 'elseif':
  3040. case 'elif':
  3041. node.else_ = this.parseIf();
  3042. break;
  3043. case 'else':
  3044. this.advanceAfterBlockEnd();
  3045. node.else_ = this.parseUntilBlocks('endif');
  3046. this.advanceAfterBlockEnd();
  3047. break;
  3048. case 'endif':
  3049. node.else_ = null;
  3050. this.advanceAfterBlockEnd();
  3051. break;
  3052. default:
  3053. this.fail('parseIf: expected elif, else, or endif, got end of file');
  3054. }
  3055. return node;
  3056. };
  3057. _proto.parseSet = function parseSet() {
  3058. var tag = this.peekToken();
  3059. if (!this.skipSymbol('set')) {
  3060. this.fail('parseSet: expected set', tag.lineno, tag.colno);
  3061. }
  3062. var node = new nodes.Set(tag.lineno, tag.colno, []);
  3063. var target;
  3064. while (target = this.parsePrimary()) {
  3065. node.targets.push(target);
  3066. if (!this.skip(lexer.TOKEN_COMMA)) {
  3067. break;
  3068. }
  3069. }
  3070. if (!this.skipValue(lexer.TOKEN_OPERATOR, '=')) {
  3071. if (!this.skip(lexer.TOKEN_BLOCK_END)) {
  3072. this.fail('parseSet: expected = or block end in set tag', tag.lineno, tag.colno);
  3073. } else {
  3074. node.body = new nodes.Capture(tag.lineno, tag.colno, this.parseUntilBlocks('endset'));
  3075. node.value = null;
  3076. this.advanceAfterBlockEnd();
  3077. }
  3078. } else {
  3079. node.value = this.parseExpression();
  3080. this.advanceAfterBlockEnd(tag.value);
  3081. }
  3082. return node;
  3083. };
  3084. _proto.parseSwitch = function parseSwitch() {
  3085. /*
  3086. * Store the tag names in variables in case someone ever wants to
  3087. * customize this.
  3088. */
  3089. var switchStart = 'switch';
  3090. var switchEnd = 'endswitch';
  3091. var caseStart = 'case';
  3092. var caseDefault = 'default'; // Get the switch tag.
  3093. var tag = this.peekToken(); // fail early if we get some unexpected tag.
  3094. if (!this.skipSymbol(switchStart) && !this.skipSymbol(caseStart) && !this.skipSymbol(caseDefault)) {
  3095. this.fail('parseSwitch: expected "switch," "case" or "default"', tag.lineno, tag.colno);
  3096. } // parse the switch expression
  3097. var expr = this.parseExpression(); // advance until a start of a case, a default case or an endswitch.
  3098. this.advanceAfterBlockEnd(switchStart);
  3099. this.parseUntilBlocks(caseStart, caseDefault, switchEnd); // this is the first case. it could also be an endswitch, we'll check.
  3100. var tok = this.peekToken(); // create new variables for our cases and default case.
  3101. var cases = [];
  3102. var defaultCase; // while we're dealing with new cases nodes...
  3103. do {
  3104. // skip the start symbol and get the case expression
  3105. this.skipSymbol(caseStart);
  3106. var cond = this.parseExpression();
  3107. this.advanceAfterBlockEnd(switchStart); // get the body of the case node and add it to the array of cases.
  3108. var body = this.parseUntilBlocks(caseStart, caseDefault, switchEnd);
  3109. cases.push(new nodes.Case(tok.line, tok.col, cond, body)); // get our next case
  3110. tok = this.peekToken();
  3111. } while (tok && tok.value === caseStart); // we either have a default case or a switch end.
  3112. switch (tok.value) {
  3113. case caseDefault:
  3114. this.advanceAfterBlockEnd();
  3115. defaultCase = this.parseUntilBlocks(switchEnd);
  3116. this.advanceAfterBlockEnd();
  3117. break;
  3118. case switchEnd:
  3119. this.advanceAfterBlockEnd();
  3120. break;
  3121. default:
  3122. // otherwise bail because EOF
  3123. this.fail('parseSwitch: expected "case," "default" or "endswitch," got EOF.');
  3124. } // and return the switch node.
  3125. return new nodes.Switch(tag.lineno, tag.colno, expr, cases, defaultCase);
  3126. };
  3127. _proto.parseStatement = function parseStatement() {
  3128. var tok = this.peekToken();
  3129. var node;
  3130. if (tok.type !== lexer.TOKEN_SYMBOL) {
  3131. this.fail('tag name expected', tok.lineno, tok.colno);
  3132. }
  3133. if (this.breakOnBlocks && lib.indexOf(this.breakOnBlocks, tok.value) !== -1) {
  3134. return null;
  3135. }
  3136. switch (tok.value) {
  3137. case 'raw':
  3138. return this.parseRaw();
  3139. case 'verbatim':
  3140. return this.parseRaw('verbatim');
  3141. case 'if':
  3142. case 'ifAsync':
  3143. return this.parseIf();
  3144. case 'for':
  3145. case 'asyncEach':
  3146. case 'asyncAll':
  3147. return this.parseFor();
  3148. case 'block':
  3149. return this.parseBlock();
  3150. case 'extends':
  3151. return this.parseExtends();
  3152. case 'include':
  3153. return this.parseInclude();
  3154. case 'set':
  3155. return this.parseSet();
  3156. case 'macro':
  3157. return this.parseMacro();
  3158. case 'call':
  3159. return this.parseCall();
  3160. case 'import':
  3161. return this.parseImport();
  3162. case 'from':
  3163. return this.parseFrom();
  3164. case 'filter':
  3165. return this.parseFilterStatement();
  3166. case 'switch':
  3167. return this.parseSwitch();
  3168. default:
  3169. if (this.extensions.length) {
  3170. for (var i = 0; i < this.extensions.length; i++) {
  3171. var ext = this.extensions[i];
  3172. if (lib.indexOf(ext.tags || [], tok.value) !== -1) {
  3173. return ext.parse(this, nodes, lexer);
  3174. }
  3175. }
  3176. }
  3177. this.fail('unknown block tag: ' + tok.value, tok.lineno, tok.colno);
  3178. }
  3179. return node;
  3180. };
  3181. _proto.parseRaw = function parseRaw(tagName) {
  3182. tagName = tagName || 'raw';
  3183. var endTagName = 'end' + tagName; // Look for upcoming raw blocks (ignore all other kinds of blocks)
  3184. var rawBlockRegex = new RegExp('([\\s\\S]*?){%\\s*(' + tagName + '|' + endTagName + ')\\s*(?=%})%}');
  3185. var rawLevel = 1;
  3186. var str = '';
  3187. var matches = null; // Skip opening raw token
  3188. // Keep this token to track line and column numbers
  3189. var begun = this.advanceAfterBlockEnd(); // Exit when there's nothing to match
  3190. // or when we've found the matching "endraw" block
  3191. while ((matches = this.tokens._extractRegex(rawBlockRegex)) && rawLevel > 0) {
  3192. var all = matches[0];
  3193. var pre = matches[1];
  3194. var blockName = matches[2]; // Adjust rawlevel
  3195. if (blockName === tagName) {
  3196. rawLevel += 1;
  3197. } else if (blockName === endTagName) {
  3198. rawLevel -= 1;
  3199. } // Add to str
  3200. if (rawLevel === 0) {
  3201. // We want to exclude the last "endraw"
  3202. str += pre; // Move tokenizer to beginning of endraw block
  3203. this.tokens.backN(all.length - pre.length);
  3204. } else {
  3205. str += all;
  3206. }
  3207. }
  3208. return new nodes.Output(begun.lineno, begun.colno, [new nodes.TemplateData(begun.lineno, begun.colno, str)]);
  3209. };
  3210. _proto.parsePostfix = function parsePostfix(node) {
  3211. var lookup;
  3212. var tok = this.peekToken();
  3213. while (tok) {
  3214. if (tok.type === lexer.TOKEN_LEFT_PAREN) {
  3215. // Function call
  3216. node = new nodes.FunCall(tok.lineno, tok.colno, node, this.parseSignature());
  3217. } else if (tok.type === lexer.TOKEN_LEFT_BRACKET) {
  3218. // Reference
  3219. lookup = this.parseAggregate();
  3220. if (lookup.children.length > 1) {
  3221. this.fail('invalid index');
  3222. }
  3223. node = new nodes.LookupVal(tok.lineno, tok.colno, node, lookup.children[0]);
  3224. } else if (tok.type === lexer.TOKEN_OPERATOR && tok.value === '.') {
  3225. // Reference
  3226. this.nextToken();
  3227. var val = this.nextToken();
  3228. if (val.type !== lexer.TOKEN_SYMBOL) {
  3229. this.fail('expected name as lookup value, got ' + val.value, val.lineno, val.colno);
  3230. } // Make a literal string because it's not a variable
  3231. // reference
  3232. lookup = new nodes.Literal(val.lineno, val.colno, val.value);
  3233. node = new nodes.LookupVal(tok.lineno, tok.colno, node, lookup);
  3234. } else {
  3235. break;
  3236. }
  3237. tok = this.peekToken();
  3238. }
  3239. return node;
  3240. };
  3241. _proto.parseExpression = function parseExpression() {
  3242. var node = this.parseInlineIf();
  3243. return node;
  3244. };
  3245. _proto.parseInlineIf = function parseInlineIf() {
  3246. var node = this.parseOr();
  3247. if (this.skipSymbol('if')) {
  3248. var condNode = this.parseOr();
  3249. var bodyNode = node;
  3250. node = new nodes.InlineIf(node.lineno, node.colno);
  3251. node.body = bodyNode;
  3252. node.cond = condNode;
  3253. if (this.skipSymbol('else')) {
  3254. node.else_ = this.parseOr();
  3255. } else {
  3256. node.else_ = null;
  3257. }
  3258. }
  3259. return node;
  3260. };
  3261. _proto.parseOr = function parseOr() {
  3262. var node = this.parseAnd();
  3263. while (this.skipSymbol('or')) {
  3264. var node2 = this.parseAnd();
  3265. node = new nodes.Or(node.lineno, node.colno, node, node2);
  3266. }
  3267. return node;
  3268. };
  3269. _proto.parseAnd = function parseAnd() {
  3270. var node = this.parseNot();
  3271. while (this.skipSymbol('and')) {
  3272. var node2 = this.parseNot();
  3273. node = new nodes.And(node.lineno, node.colno, node, node2);
  3274. }
  3275. return node;
  3276. };
  3277. _proto.parseNot = function parseNot() {
  3278. var tok = this.peekToken();
  3279. if (this.skipSymbol('not')) {
  3280. return new nodes.Not(tok.lineno, tok.colno, this.parseNot());
  3281. }
  3282. return this.parseIn();
  3283. };
  3284. _proto.parseIn = function parseIn() {
  3285. var node = this.parseIs();
  3286. while (1) {
  3287. // eslint-disable-line no-constant-condition
  3288. // check if the next token is 'not'
  3289. var tok = this.nextToken();
  3290. if (!tok) {
  3291. break;
  3292. }
  3293. var invert = tok.type === lexer.TOKEN_SYMBOL && tok.value === 'not'; // if it wasn't 'not', put it back
  3294. if (!invert) {
  3295. this.pushToken(tok);
  3296. }
  3297. if (this.skipSymbol('in')) {
  3298. var node2 = this.parseIs();
  3299. node = new nodes.In(node.lineno, node.colno, node, node2);
  3300. if (invert) {
  3301. node = new nodes.Not(node.lineno, node.colno, node);
  3302. }
  3303. } else {
  3304. // if we'd found a 'not' but this wasn't an 'in', put back the 'not'
  3305. if (invert) {
  3306. this.pushToken(tok);
  3307. }
  3308. break;
  3309. }
  3310. }
  3311. return node;
  3312. } // I put this right after "in" in the operator precedence stack. That can
  3313. // obviously be changed to be closer to Jinja.
  3314. ;
  3315. _proto.parseIs = function parseIs() {
  3316. var node = this.parseCompare(); // look for an is
  3317. if (this.skipSymbol('is')) {
  3318. // look for a not
  3319. var not = this.skipSymbol('not'); // get the next node
  3320. var node2 = this.parseCompare(); // create an Is node using the next node and the info from our Is node.
  3321. node = new nodes.Is(node.lineno, node.colno, node, node2); // if we have a Not, create a Not node from our Is node.
  3322. if (not) {
  3323. node = new nodes.Not(node.lineno, node.colno, node);
  3324. }
  3325. } // return the node.
  3326. return node;
  3327. };
  3328. _proto.parseCompare = function parseCompare() {
  3329. var compareOps = ['==', '===', '!=', '!==', '<', '>', '<=', '>='];
  3330. var expr = this.parseConcat();
  3331. var ops = [];
  3332. while (1) {
  3333. // eslint-disable-line no-constant-condition
  3334. var tok = this.nextToken();
  3335. if (!tok) {
  3336. break;
  3337. } else if (compareOps.indexOf(tok.value) !== -1) {
  3338. ops.push(new nodes.CompareOperand(tok.lineno, tok.colno, this.parseConcat(), tok.value));
  3339. } else {
  3340. this.pushToken(tok);
  3341. break;
  3342. }
  3343. }
  3344. if (ops.length) {
  3345. return new nodes.Compare(ops[0].lineno, ops[0].colno, expr, ops);
  3346. } else {
  3347. return expr;
  3348. }
  3349. } // finds the '~' for string concatenation
  3350. ;
  3351. _proto.parseConcat = function parseConcat() {
  3352. var node = this.parseAdd();
  3353. while (this.skipValue(lexer.TOKEN_TILDE, '~')) {
  3354. var node2 = this.parseAdd();
  3355. node = new nodes.Concat(node.lineno, node.colno, node, node2);
  3356. }
  3357. return node;
  3358. };
  3359. _proto.parseAdd = function parseAdd() {
  3360. var node = this.parseSub();
  3361. while (this.skipValue(lexer.TOKEN_OPERATOR, '+')) {
  3362. var node2 = this.parseSub();
  3363. node = new nodes.Add(node.lineno, node.colno, node, node2);
  3364. }
  3365. return node;
  3366. };
  3367. _proto.parseSub = function parseSub() {
  3368. var node = this.parseMul();
  3369. while (this.skipValue(lexer.TOKEN_OPERATOR, '-')) {
  3370. var node2 = this.parseMul();
  3371. node = new nodes.Sub(node.lineno, node.colno, node, node2);
  3372. }
  3373. return node;
  3374. };
  3375. _proto.parseMul = function parseMul() {
  3376. var node = this.parseDiv();
  3377. while (this.skipValue(lexer.TOKEN_OPERATOR, '*')) {
  3378. var node2 = this.parseDiv();
  3379. node = new nodes.Mul(node.lineno, node.colno, node, node2);
  3380. }
  3381. return node;
  3382. };
  3383. _proto.parseDiv = function parseDiv() {
  3384. var node = this.parseFloorDiv();
  3385. while (this.skipValue(lexer.TOKEN_OPERATOR, '/')) {
  3386. var node2 = this.parseFloorDiv();
  3387. node = new nodes.Div(node.lineno, node.colno, node, node2);
  3388. }
  3389. return node;
  3390. };
  3391. _proto.parseFloorDiv = function parseFloorDiv() {
  3392. var node = this.parseMod();
  3393. while (this.skipValue(lexer.TOKEN_OPERATOR, '//')) {
  3394. var node2 = this.parseMod();
  3395. node = new nodes.FloorDiv(node.lineno, node.colno, node, node2);
  3396. }
  3397. return node;
  3398. };
  3399. _proto.parseMod = function parseMod() {
  3400. var node = this.parsePow();
  3401. while (this.skipValue(lexer.TOKEN_OPERATOR, '%')) {
  3402. var node2 = this.parsePow();
  3403. node = new nodes.Mod(node.lineno, node.colno, node, node2);
  3404. }
  3405. return node;
  3406. };
  3407. _proto.parsePow = function parsePow() {
  3408. var node = this.parseUnary();
  3409. while (this.skipValue(lexer.TOKEN_OPERATOR, '**')) {
  3410. var node2 = this.parseUnary();
  3411. node = new nodes.Pow(node.lineno, node.colno, node, node2);
  3412. }
  3413. return node;
  3414. };
  3415. _proto.parseUnary = function parseUnary(noFilters) {
  3416. var tok = this.peekToken();
  3417. var node;
  3418. if (this.skipValue(lexer.TOKEN_OPERATOR, '-')) {
  3419. node = new nodes.Neg(tok.lineno, tok.colno, this.parseUnary(true));
  3420. } else if (this.skipValue(lexer.TOKEN_OPERATOR, '+')) {
  3421. node = new nodes.Pos(tok.lineno, tok.colno, this.parseUnary(true));
  3422. } else {
  3423. node = this.parsePrimary();
  3424. }
  3425. if (!noFilters) {
  3426. node = this.parseFilter(node);
  3427. }
  3428. return node;
  3429. };
  3430. _proto.parsePrimary = function parsePrimary(noPostfix) {
  3431. var tok = this.nextToken();
  3432. var val;
  3433. var node = null;
  3434. if (!tok) {
  3435. this.fail('expected expression, got end of file');
  3436. } else if (tok.type === lexer.TOKEN_STRING) {
  3437. val = tok.value;
  3438. } else if (tok.type === lexer.TOKEN_INT) {
  3439. val = parseInt(tok.value, 10);
  3440. } else if (tok.type === lexer.TOKEN_FLOAT) {
  3441. val = parseFloat(tok.value);
  3442. } else if (tok.type === lexer.TOKEN_BOOLEAN) {
  3443. if (tok.value === 'true') {
  3444. val = true;
  3445. } else if (tok.value === 'false') {
  3446. val = false;
  3447. } else {
  3448. this.fail('invalid boolean: ' + tok.value, tok.lineno, tok.colno);
  3449. }
  3450. } else if (tok.type === lexer.TOKEN_NONE) {
  3451. val = null;
  3452. } else if (tok.type === lexer.TOKEN_REGEX) {
  3453. val = new RegExp(tok.value.body, tok.value.flags);
  3454. }
  3455. if (val !== undefined) {
  3456. node = new nodes.Literal(tok.lineno, tok.colno, val);
  3457. } else if (tok.type === lexer.TOKEN_SYMBOL) {
  3458. node = new nodes.Symbol(tok.lineno, tok.colno, tok.value);
  3459. } else {
  3460. // See if it's an aggregate type, we need to push the
  3461. // current delimiter token back on
  3462. this.pushToken(tok);
  3463. node = this.parseAggregate();
  3464. }
  3465. if (!noPostfix) {
  3466. node = this.parsePostfix(node);
  3467. }
  3468. if (node) {
  3469. return node;
  3470. } else {
  3471. throw this.error("unexpected token: " + tok.value, tok.lineno, tok.colno);
  3472. }
  3473. };
  3474. _proto.parseFilterName = function parseFilterName() {
  3475. var tok = this.expect(lexer.TOKEN_SYMBOL);
  3476. var name = tok.value;
  3477. while (this.skipValue(lexer.TOKEN_OPERATOR, '.')) {
  3478. name += '.' + this.expect(lexer.TOKEN_SYMBOL).value;
  3479. }
  3480. return new nodes.Symbol(tok.lineno, tok.colno, name);
  3481. };
  3482. _proto.parseFilterArgs = function parseFilterArgs(node) {
  3483. if (this.peekToken().type === lexer.TOKEN_LEFT_PAREN) {
  3484. // Get a FunCall node and add the parameters to the
  3485. // filter
  3486. var call = this.parsePostfix(node);
  3487. return call.args.children;
  3488. }
  3489. return [];
  3490. };
  3491. _proto.parseFilter = function parseFilter(node) {
  3492. while (this.skip(lexer.TOKEN_PIPE)) {
  3493. var name = this.parseFilterName();
  3494. node = new nodes.Filter(name.lineno, name.colno, name, new nodes.NodeList(name.lineno, name.colno, [node].concat(this.parseFilterArgs(node))));
  3495. }
  3496. return node;
  3497. };
  3498. _proto.parseFilterStatement = function parseFilterStatement() {
  3499. var filterTok = this.peekToken();
  3500. if (!this.skipSymbol('filter')) {
  3501. this.fail('parseFilterStatement: expected filter');
  3502. }
  3503. var name = this.parseFilterName();
  3504. var args = this.parseFilterArgs(name);
  3505. this.advanceAfterBlockEnd(filterTok.value);
  3506. var body = new nodes.Capture(name.lineno, name.colno, this.parseUntilBlocks('endfilter'));
  3507. this.advanceAfterBlockEnd();
  3508. var node = new nodes.Filter(name.lineno, name.colno, name, new nodes.NodeList(name.lineno, name.colno, [body].concat(args)));
  3509. return new nodes.Output(name.lineno, name.colno, [node]);
  3510. };
  3511. _proto.parseAggregate = function parseAggregate() {
  3512. var tok = this.nextToken();
  3513. var node;
  3514. switch (tok.type) {
  3515. case lexer.TOKEN_LEFT_PAREN:
  3516. node = new nodes.Group(tok.lineno, tok.colno);
  3517. break;
  3518. case lexer.TOKEN_LEFT_BRACKET:
  3519. node = new nodes.Array(tok.lineno, tok.colno);
  3520. break;
  3521. case lexer.TOKEN_LEFT_CURLY:
  3522. node = new nodes.Dict(tok.lineno, tok.colno);
  3523. break;
  3524. default:
  3525. return null;
  3526. }
  3527. while (1) {
  3528. // eslint-disable-line no-constant-condition
  3529. var type = this.peekToken().type;
  3530. if (type === lexer.TOKEN_RIGHT_PAREN || type === lexer.TOKEN_RIGHT_BRACKET || type === lexer.TOKEN_RIGHT_CURLY) {
  3531. this.nextToken();
  3532. break;
  3533. }
  3534. if (node.children.length > 0) {
  3535. if (!this.skip(lexer.TOKEN_COMMA)) {
  3536. this.fail('parseAggregate: expected comma after expression', tok.lineno, tok.colno);
  3537. }
  3538. }
  3539. if (node instanceof nodes.Dict) {
  3540. // TODO: check for errors
  3541. var key = this.parsePrimary(); // We expect a key/value pair for dicts, separated by a
  3542. // colon
  3543. if (!this.skip(lexer.TOKEN_COLON)) {
  3544. this.fail('parseAggregate: expected colon after dict key', tok.lineno, tok.colno);
  3545. } // TODO: check for errors
  3546. var value = this.parseExpression();
  3547. node.addChild(new nodes.Pair(key.lineno, key.colno, key, value));
  3548. } else {
  3549. // TODO: check for errors
  3550. var expr = this.parseExpression();
  3551. node.addChild(expr);
  3552. }
  3553. }
  3554. return node;
  3555. };
  3556. _proto.parseSignature = function parseSignature(tolerant, noParens) {
  3557. var tok = this.peekToken();
  3558. if (!noParens && tok.type !== lexer.TOKEN_LEFT_PAREN) {
  3559. if (tolerant) {
  3560. return null;
  3561. } else {
  3562. this.fail('expected arguments', tok.lineno, tok.colno);
  3563. }
  3564. }
  3565. if (tok.type === lexer.TOKEN_LEFT_PAREN) {
  3566. tok = this.nextToken();
  3567. }
  3568. var args = new nodes.NodeList(tok.lineno, tok.colno);
  3569. var kwargs = new nodes.KeywordArgs(tok.lineno, tok.colno);
  3570. var checkComma = false;
  3571. while (1) {
  3572. // eslint-disable-line no-constant-condition
  3573. tok = this.peekToken();
  3574. if (!noParens && tok.type === lexer.TOKEN_RIGHT_PAREN) {
  3575. this.nextToken();
  3576. break;
  3577. } else if (noParens && tok.type === lexer.TOKEN_BLOCK_END) {
  3578. break;
  3579. }
  3580. if (checkComma && !this.skip(lexer.TOKEN_COMMA)) {
  3581. this.fail('parseSignature: expected comma after expression', tok.lineno, tok.colno);
  3582. } else {
  3583. var arg = this.parseExpression();
  3584. if (this.skipValue(lexer.TOKEN_OPERATOR, '=')) {
  3585. kwargs.addChild(new nodes.Pair(arg.lineno, arg.colno, arg, this.parseExpression()));
  3586. } else {
  3587. args.addChild(arg);
  3588. }
  3589. }
  3590. checkComma = true;
  3591. }
  3592. if (kwargs.children.length) {
  3593. args.addChild(kwargs);
  3594. }
  3595. return args;
  3596. };
  3597. _proto.parseUntilBlocks = function parseUntilBlocks() {
  3598. var prev = this.breakOnBlocks;
  3599. for (var _len = arguments.length, blockNames = new Array(_len), _key = 0; _key < _len; _key++) {
  3600. blockNames[_key] = arguments[_key];
  3601. }
  3602. this.breakOnBlocks = blockNames;
  3603. var ret = this.parse();
  3604. this.breakOnBlocks = prev;
  3605. return ret;
  3606. };
  3607. _proto.parseNodes = function parseNodes() {
  3608. var tok;
  3609. var buf = [];
  3610. while (tok = this.nextToken()) {
  3611. if (tok.type === lexer.TOKEN_DATA) {
  3612. var data = tok.value;
  3613. var nextToken = this.peekToken();
  3614. var nextVal = nextToken && nextToken.value; // If the last token has "-" we need to trim the
  3615. // leading whitespace of the data. This is marked with
  3616. // the `dropLeadingWhitespace` variable.
  3617. if (this.dropLeadingWhitespace) {
  3618. // TODO: this could be optimized (don't use regex)
  3619. data = data.replace(/^\s*/, '');
  3620. this.dropLeadingWhitespace = false;
  3621. } // Same for the succeeding block start token
  3622. if (nextToken && (nextToken.type === lexer.TOKEN_BLOCK_START && nextVal.charAt(nextVal.length - 1) === '-' || nextToken.type === lexer.TOKEN_VARIABLE_START && nextVal.charAt(this.tokens.tags.VARIABLE_START.length) === '-' || nextToken.type === lexer.TOKEN_COMMENT && nextVal.charAt(this.tokens.tags.COMMENT_START.length) === '-')) {
  3623. // TODO: this could be optimized (don't use regex)
  3624. data = data.replace(/\s*$/, '');
  3625. }
  3626. buf.push(new nodes.Output(tok.lineno, tok.colno, [new nodes.TemplateData(tok.lineno, tok.colno, data)]));
  3627. } else if (tok.type === lexer.TOKEN_BLOCK_START) {
  3628. this.dropLeadingWhitespace = false;
  3629. var n = this.parseStatement();
  3630. if (!n) {
  3631. break;
  3632. }
  3633. buf.push(n);
  3634. } else if (tok.type === lexer.TOKEN_VARIABLE_START) {
  3635. var e = this.parseExpression();
  3636. this.dropLeadingWhitespace = false;
  3637. this.advanceAfterVariableEnd();
  3638. buf.push(new nodes.Output(tok.lineno, tok.colno, [e]));
  3639. } else if (tok.type === lexer.TOKEN_COMMENT) {
  3640. this.dropLeadingWhitespace = tok.value.charAt(tok.value.length - this.tokens.tags.COMMENT_END.length - 1) === '-';
  3641. } else {
  3642. // Ignore comments, otherwise this should be an error
  3643. this.fail('Unexpected token at top-level: ' + tok.type, tok.lineno, tok.colno);
  3644. }
  3645. }
  3646. return buf;
  3647. };
  3648. _proto.parse = function parse() {
  3649. return new nodes.NodeList(0, 0, this.parseNodes());
  3650. };
  3651. _proto.parseAsRoot = function parseAsRoot() {
  3652. return new nodes.Root(0, 0, this.parseNodes());
  3653. };
  3654. return Parser;
  3655. }(Obj); // var util = require('util');
  3656. // var l = lexer.lex('{%- if x -%}\n hello {% endif %}');
  3657. // var t;
  3658. // while((t = l.nextToken())) {
  3659. // console.log(util.inspect(t));
  3660. // }
  3661. // var p = new Parser(lexer.lex('hello {% filter title %}' +
  3662. // 'Hello madam how are you' +
  3663. // '{% endfilter %}'));
  3664. // var n = p.parseAsRoot();
  3665. // nodes.printNodes(n);
  3666. module.exports = {
  3667. parse: function parse(src, extensions, opts) {
  3668. var p = new Parser(lexer.lex(src, opts));
  3669. if (extensions !== undefined) {
  3670. p.extensions = extensions;
  3671. }
  3672. return p.parseAsRoot();
  3673. },
  3674. Parser: Parser
  3675. };
  3676. /***/ }),
  3677. /* 9 */
  3678. /***/ (function(module, exports, __webpack_require__) {
  3679. "use strict";
  3680. var lib = __webpack_require__(0);
  3681. var whitespaceChars = " \n\t\r\xA0";
  3682. var delimChars = '()[]{}%*-+~/#,:|.<>=!';
  3683. var intChars = '0123456789';
  3684. var BLOCK_START = '{%';
  3685. var BLOCK_END = '%}';
  3686. var VARIABLE_START = '{{';
  3687. var VARIABLE_END = '}}';
  3688. var COMMENT_START = '{#';
  3689. var COMMENT_END = '#}';
  3690. var TOKEN_STRING = 'string';
  3691. var TOKEN_WHITESPACE = 'whitespace';
  3692. var TOKEN_DATA = 'data';
  3693. var TOKEN_BLOCK_START = 'block-start';
  3694. var TOKEN_BLOCK_END = 'block-end';
  3695. var TOKEN_VARIABLE_START = 'variable-start';
  3696. var TOKEN_VARIABLE_END = 'variable-end';
  3697. var TOKEN_COMMENT = 'comment';
  3698. var TOKEN_LEFT_PAREN = 'left-paren';
  3699. var TOKEN_RIGHT_PAREN = 'right-paren';
  3700. var TOKEN_LEFT_BRACKET = 'left-bracket';
  3701. var TOKEN_RIGHT_BRACKET = 'right-bracket';
  3702. var TOKEN_LEFT_CURLY = 'left-curly';
  3703. var TOKEN_RIGHT_CURLY = 'right-curly';
  3704. var TOKEN_OPERATOR = 'operator';
  3705. var TOKEN_COMMA = 'comma';
  3706. var TOKEN_COLON = 'colon';
  3707. var TOKEN_TILDE = 'tilde';
  3708. var TOKEN_PIPE = 'pipe';
  3709. var TOKEN_INT = 'int';
  3710. var TOKEN_FLOAT = 'float';
  3711. var TOKEN_BOOLEAN = 'boolean';
  3712. var TOKEN_NONE = 'none';
  3713. var TOKEN_SYMBOL = 'symbol';
  3714. var TOKEN_SPECIAL = 'special';
  3715. var TOKEN_REGEX = 'regex';
  3716. function token(type, value, lineno, colno) {
  3717. return {
  3718. type: type,
  3719. value: value,
  3720. lineno: lineno,
  3721. colno: colno
  3722. };
  3723. }
  3724. var Tokenizer = /*#__PURE__*/function () {
  3725. function Tokenizer(str, opts) {
  3726. this.str = str;
  3727. this.index = 0;
  3728. this.len = str.length;
  3729. this.lineno = 0;
  3730. this.colno = 0;
  3731. this.in_code = false;
  3732. opts = opts || {};
  3733. var tags = opts.tags || {};
  3734. this.tags = {
  3735. BLOCK_START: tags.blockStart || BLOCK_START,
  3736. BLOCK_END: tags.blockEnd || BLOCK_END,
  3737. VARIABLE_START: tags.variableStart || VARIABLE_START,
  3738. VARIABLE_END: tags.variableEnd || VARIABLE_END,
  3739. COMMENT_START: tags.commentStart || COMMENT_START,
  3740. COMMENT_END: tags.commentEnd || COMMENT_END
  3741. };
  3742. this.trimBlocks = !!opts.trimBlocks;
  3743. this.lstripBlocks = !!opts.lstripBlocks;
  3744. }
  3745. var _proto = Tokenizer.prototype;
  3746. _proto.nextToken = function nextToken() {
  3747. var lineno = this.lineno;
  3748. var colno = this.colno;
  3749. var tok;
  3750. if (this.in_code) {
  3751. // Otherwise, if we are in a block parse it as code
  3752. var cur = this.current();
  3753. if (this.isFinished()) {
  3754. // We have nothing else to parse
  3755. return null;
  3756. } else if (cur === '"' || cur === '\'') {
  3757. // We've hit a string
  3758. return token(TOKEN_STRING, this._parseString(cur), lineno, colno);
  3759. } else if (tok = this._extract(whitespaceChars)) {
  3760. // We hit some whitespace
  3761. return token(TOKEN_WHITESPACE, tok, lineno, colno);
  3762. } else if ((tok = this._extractString(this.tags.BLOCK_END)) || (tok = this._extractString('-' + this.tags.BLOCK_END))) {
  3763. // Special check for the block end tag
  3764. //
  3765. // It is a requirement that start and end tags are composed of
  3766. // delimiter characters (%{}[] etc), and our code always
  3767. // breaks on delimiters so we can assume the token parsing
  3768. // doesn't consume these elsewhere
  3769. this.in_code = false;
  3770. if (this.trimBlocks) {
  3771. cur = this.current();
  3772. if (cur === '\n') {
  3773. // Skip newline
  3774. this.forward();
  3775. } else if (cur === '\r') {
  3776. // Skip CRLF newline
  3777. this.forward();
  3778. cur = this.current();
  3779. if (cur === '\n') {
  3780. this.forward();
  3781. } else {
  3782. // Was not a CRLF, so go back
  3783. this.back();
  3784. }
  3785. }
  3786. }
  3787. return token(TOKEN_BLOCK_END, tok, lineno, colno);
  3788. } else if ((tok = this._extractString(this.tags.VARIABLE_END)) || (tok = this._extractString('-' + this.tags.VARIABLE_END))) {
  3789. // Special check for variable end tag (see above)
  3790. this.in_code = false;
  3791. return token(TOKEN_VARIABLE_END, tok, lineno, colno);
  3792. } else if (cur === 'r' && this.str.charAt(this.index + 1) === '/') {
  3793. // Skip past 'r/'.
  3794. this.forwardN(2); // Extract until the end of the regex -- / ends it, \/ does not.
  3795. var regexBody = '';
  3796. while (!this.isFinished()) {
  3797. if (this.current() === '/' && this.previous() !== '\\') {
  3798. this.forward();
  3799. break;
  3800. } else {
  3801. regexBody += this.current();
  3802. this.forward();
  3803. }
  3804. } // Check for flags.
  3805. // The possible flags are according to https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/RegExp)
  3806. var POSSIBLE_FLAGS = ['g', 'i', 'm', 'y'];
  3807. var regexFlags = '';
  3808. while (!this.isFinished()) {
  3809. var isCurrentAFlag = POSSIBLE_FLAGS.indexOf(this.current()) !== -1;
  3810. if (isCurrentAFlag) {
  3811. regexFlags += this.current();
  3812. this.forward();
  3813. } else {
  3814. break;
  3815. }
  3816. }
  3817. return token(TOKEN_REGEX, {
  3818. body: regexBody,
  3819. flags: regexFlags
  3820. }, lineno, colno);
  3821. } else if (delimChars.indexOf(cur) !== -1) {
  3822. // We've hit a delimiter (a special char like a bracket)
  3823. this.forward();
  3824. var complexOps = ['==', '===', '!=', '!==', '<=', '>=', '//', '**'];
  3825. var curComplex = cur + this.current();
  3826. var type;
  3827. if (lib.indexOf(complexOps, curComplex) !== -1) {
  3828. this.forward();
  3829. cur = curComplex; // See if this is a strict equality/inequality comparator
  3830. if (lib.indexOf(complexOps, curComplex + this.current()) !== -1) {
  3831. cur = curComplex + this.current();
  3832. this.forward();
  3833. }
  3834. }
  3835. switch (cur) {
  3836. case '(':
  3837. type = TOKEN_LEFT_PAREN;
  3838. break;
  3839. case ')':
  3840. type = TOKEN_RIGHT_PAREN;
  3841. break;
  3842. case '[':
  3843. type = TOKEN_LEFT_BRACKET;
  3844. break;
  3845. case ']':
  3846. type = TOKEN_RIGHT_BRACKET;
  3847. break;
  3848. case '{':
  3849. type = TOKEN_LEFT_CURLY;
  3850. break;
  3851. case '}':
  3852. type = TOKEN_RIGHT_CURLY;
  3853. break;
  3854. case ',':
  3855. type = TOKEN_COMMA;
  3856. break;
  3857. case ':':
  3858. type = TOKEN_COLON;
  3859. break;
  3860. case '~':
  3861. type = TOKEN_TILDE;
  3862. break;
  3863. case '|':
  3864. type = TOKEN_PIPE;
  3865. break;
  3866. default:
  3867. type = TOKEN_OPERATOR;
  3868. }
  3869. return token(type, cur, lineno, colno);
  3870. } else {
  3871. // We are not at whitespace or a delimiter, so extract the
  3872. // text and parse it
  3873. tok = this._extractUntil(whitespaceChars + delimChars);
  3874. if (tok.match(/^[-+]?[0-9]+$/)) {
  3875. if (this.current() === '.') {
  3876. this.forward();
  3877. var dec = this._extract(intChars);
  3878. return token(TOKEN_FLOAT, tok + '.' + dec, lineno, colno);
  3879. } else {
  3880. return token(TOKEN_INT, tok, lineno, colno);
  3881. }
  3882. } else if (tok.match(/^(true|false)$/)) {
  3883. return token(TOKEN_BOOLEAN, tok, lineno, colno);
  3884. } else if (tok === 'none') {
  3885. return token(TOKEN_NONE, tok, lineno, colno);
  3886. /*
  3887. * Added to make the test `null is null` evaluate truthily.
  3888. * Otherwise, Nunjucks will look up null in the context and
  3889. * return `undefined`, which is not what we want. This *may* have
  3890. * consequences is someone is using null in their templates as a
  3891. * variable.
  3892. */
  3893. } else if (tok === 'null') {
  3894. return token(TOKEN_NONE, tok, lineno, colno);
  3895. } else if (tok) {
  3896. return token(TOKEN_SYMBOL, tok, lineno, colno);
  3897. } else {
  3898. throw new Error('Unexpected value while parsing: ' + tok);
  3899. }
  3900. }
  3901. } else {
  3902. // Parse out the template text, breaking on tag
  3903. // delimiters because we need to look for block/variable start
  3904. // tags (don't use the full delimChars for optimization)
  3905. var beginChars = this.tags.BLOCK_START.charAt(0) + this.tags.VARIABLE_START.charAt(0) + this.tags.COMMENT_START.charAt(0) + this.tags.COMMENT_END.charAt(0);
  3906. if (this.isFinished()) {
  3907. return null;
  3908. } else if ((tok = this._extractString(this.tags.BLOCK_START + '-')) || (tok = this._extractString(this.tags.BLOCK_START))) {
  3909. this.in_code = true;
  3910. return token(TOKEN_BLOCK_START, tok, lineno, colno);
  3911. } else if ((tok = this._extractString(this.tags.VARIABLE_START + '-')) || (tok = this._extractString(this.tags.VARIABLE_START))) {
  3912. this.in_code = true;
  3913. return token(TOKEN_VARIABLE_START, tok, lineno, colno);
  3914. } else {
  3915. tok = '';
  3916. var data;
  3917. var inComment = false;
  3918. if (this._matches(this.tags.COMMENT_START)) {
  3919. inComment = true;
  3920. tok = this._extractString(this.tags.COMMENT_START);
  3921. } // Continually consume text, breaking on the tag delimiter
  3922. // characters and checking to see if it's a start tag.
  3923. //
  3924. // We could hit the end of the template in the middle of
  3925. // our looping, so check for the null return value from
  3926. // _extractUntil
  3927. while ((data = this._extractUntil(beginChars)) !== null) {
  3928. tok += data;
  3929. if ((this._matches(this.tags.BLOCK_START) || this._matches(this.tags.VARIABLE_START) || this._matches(this.tags.COMMENT_START)) && !inComment) {
  3930. if (this.lstripBlocks && this._matches(this.tags.BLOCK_START) && this.colno > 0 && this.colno <= tok.length) {
  3931. var lastLine = tok.slice(-this.colno);
  3932. if (/^\s+$/.test(lastLine)) {
  3933. // Remove block leading whitespace from beginning of the string
  3934. tok = tok.slice(0, -this.colno);
  3935. if (!tok.length) {
  3936. // All data removed, collapse to avoid unnecessary nodes
  3937. // by returning next token (block start)
  3938. return this.nextToken();
  3939. }
  3940. }
  3941. } // If it is a start tag, stop looping
  3942. break;
  3943. } else if (this._matches(this.tags.COMMENT_END)) {
  3944. if (!inComment) {
  3945. throw new Error('unexpected end of comment');
  3946. }
  3947. tok += this._extractString(this.tags.COMMENT_END);
  3948. break;
  3949. } else {
  3950. // It does not match any tag, so add the character and
  3951. // carry on
  3952. tok += this.current();
  3953. this.forward();
  3954. }
  3955. }
  3956. if (data === null && inComment) {
  3957. throw new Error('expected end of comment, got end of file');
  3958. }
  3959. return token(inComment ? TOKEN_COMMENT : TOKEN_DATA, tok, lineno, colno);
  3960. }
  3961. }
  3962. };
  3963. _proto._parseString = function _parseString(delimiter) {
  3964. this.forward();
  3965. var str = '';
  3966. while (!this.isFinished() && this.current() !== delimiter) {
  3967. var cur = this.current();
  3968. if (cur === '\\') {
  3969. this.forward();
  3970. switch (this.current()) {
  3971. case 'n':
  3972. str += '\n';
  3973. break;
  3974. case 't':
  3975. str += '\t';
  3976. break;
  3977. case 'r':
  3978. str += '\r';
  3979. break;
  3980. default:
  3981. str += this.current();
  3982. }
  3983. this.forward();
  3984. } else {
  3985. str += cur;
  3986. this.forward();
  3987. }
  3988. }
  3989. this.forward();
  3990. return str;
  3991. };
  3992. _proto._matches = function _matches(str) {
  3993. if (this.index + str.length > this.len) {
  3994. return null;
  3995. }
  3996. var m = this.str.slice(this.index, this.index + str.length);
  3997. return m === str;
  3998. };
  3999. _proto._extractString = function _extractString(str) {
  4000. if (this._matches(str)) {
  4001. this.forwardN(str.length);
  4002. return str;
  4003. }
  4004. return null;
  4005. };
  4006. _proto._extractUntil = function _extractUntil(charString) {
  4007. // Extract all non-matching chars, with the default matching set
  4008. // to everything
  4009. return this._extractMatching(true, charString || '');
  4010. };
  4011. _proto._extract = function _extract(charString) {
  4012. // Extract all matching chars (no default, so charString must be
  4013. // explicit)
  4014. return this._extractMatching(false, charString);
  4015. };
  4016. _proto._extractMatching = function _extractMatching(breakOnMatch, charString) {
  4017. // Pull out characters until a breaking char is hit.
  4018. // If breakOnMatch is false, a non-matching char stops it.
  4019. // If breakOnMatch is true, a matching char stops it.
  4020. if (this.isFinished()) {
  4021. return null;
  4022. }
  4023. var first = charString.indexOf(this.current()); // Only proceed if the first character doesn't meet our condition
  4024. if (breakOnMatch && first === -1 || !breakOnMatch && first !== -1) {
  4025. var t = this.current();
  4026. this.forward(); // And pull out all the chars one at a time until we hit a
  4027. // breaking char
  4028. var idx = charString.indexOf(this.current());
  4029. while ((breakOnMatch && idx === -1 || !breakOnMatch && idx !== -1) && !this.isFinished()) {
  4030. t += this.current();
  4031. this.forward();
  4032. idx = charString.indexOf(this.current());
  4033. }
  4034. return t;
  4035. }
  4036. return '';
  4037. };
  4038. _proto._extractRegex = function _extractRegex(regex) {
  4039. var matches = this.currentStr().match(regex);
  4040. if (!matches) {
  4041. return null;
  4042. } // Move forward whatever was matched
  4043. this.forwardN(matches[0].length);
  4044. return matches;
  4045. };
  4046. _proto.isFinished = function isFinished() {
  4047. return this.index >= this.len;
  4048. };
  4049. _proto.forwardN = function forwardN(n) {
  4050. for (var i = 0; i < n; i++) {
  4051. this.forward();
  4052. }
  4053. };
  4054. _proto.forward = function forward() {
  4055. this.index++;
  4056. if (this.previous() === '\n') {
  4057. this.lineno++;
  4058. this.colno = 0;
  4059. } else {
  4060. this.colno++;
  4061. }
  4062. };
  4063. _proto.backN = function backN(n) {
  4064. for (var i = 0; i < n; i++) {
  4065. this.back();
  4066. }
  4067. };
  4068. _proto.back = function back() {
  4069. this.index--;
  4070. if (this.current() === '\n') {
  4071. this.lineno--;
  4072. var idx = this.src.lastIndexOf('\n', this.index - 1);
  4073. if (idx === -1) {
  4074. this.colno = this.index;
  4075. } else {
  4076. this.colno = this.index - idx;
  4077. }
  4078. } else {
  4079. this.colno--;
  4080. }
  4081. } // current returns current character
  4082. ;
  4083. _proto.current = function current() {
  4084. if (!this.isFinished()) {
  4085. return this.str.charAt(this.index);
  4086. }
  4087. return '';
  4088. } // currentStr returns what's left of the unparsed string
  4089. ;
  4090. _proto.currentStr = function currentStr() {
  4091. if (!this.isFinished()) {
  4092. return this.str.substr(this.index);
  4093. }
  4094. return '';
  4095. };
  4096. _proto.previous = function previous() {
  4097. return this.str.charAt(this.index - 1);
  4098. };
  4099. return Tokenizer;
  4100. }();
  4101. module.exports = {
  4102. lex: function lex(src, opts) {
  4103. return new Tokenizer(src, opts);
  4104. },
  4105. TOKEN_STRING: TOKEN_STRING,
  4106. TOKEN_WHITESPACE: TOKEN_WHITESPACE,
  4107. TOKEN_DATA: TOKEN_DATA,
  4108. TOKEN_BLOCK_START: TOKEN_BLOCK_START,
  4109. TOKEN_BLOCK_END: TOKEN_BLOCK_END,
  4110. TOKEN_VARIABLE_START: TOKEN_VARIABLE_START,
  4111. TOKEN_VARIABLE_END: TOKEN_VARIABLE_END,
  4112. TOKEN_COMMENT: TOKEN_COMMENT,
  4113. TOKEN_LEFT_PAREN: TOKEN_LEFT_PAREN,
  4114. TOKEN_RIGHT_PAREN: TOKEN_RIGHT_PAREN,
  4115. TOKEN_LEFT_BRACKET: TOKEN_LEFT_BRACKET,
  4116. TOKEN_RIGHT_BRACKET: TOKEN_RIGHT_BRACKET,
  4117. TOKEN_LEFT_CURLY: TOKEN_LEFT_CURLY,
  4118. TOKEN_RIGHT_CURLY: TOKEN_RIGHT_CURLY,
  4119. TOKEN_OPERATOR: TOKEN_OPERATOR,
  4120. TOKEN_COMMA: TOKEN_COMMA,
  4121. TOKEN_COLON: TOKEN_COLON,
  4122. TOKEN_TILDE: TOKEN_TILDE,
  4123. TOKEN_PIPE: TOKEN_PIPE,
  4124. TOKEN_INT: TOKEN_INT,
  4125. TOKEN_FLOAT: TOKEN_FLOAT,
  4126. TOKEN_BOOLEAN: TOKEN_BOOLEAN,
  4127. TOKEN_NONE: TOKEN_NONE,
  4128. TOKEN_SYMBOL: TOKEN_SYMBOL,
  4129. TOKEN_SPECIAL: TOKEN_SPECIAL,
  4130. TOKEN_REGEX: TOKEN_REGEX
  4131. };
  4132. /***/ }),
  4133. /* 10 */
  4134. /***/ (function(module, exports, __webpack_require__) {
  4135. "use strict";
  4136. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  4137. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  4138. var Loader = __webpack_require__(6);
  4139. var _require = __webpack_require__(19),
  4140. PrecompiledLoader = _require.PrecompiledLoader;
  4141. var WebLoader = /*#__PURE__*/function (_Loader) {
  4142. _inheritsLoose(WebLoader, _Loader);
  4143. function WebLoader(baseURL, opts) {
  4144. var _this;
  4145. _this = _Loader.call(this) || this;
  4146. _this.baseURL = baseURL || '.';
  4147. opts = opts || {}; // By default, the cache is turned off because there's no way
  4148. // to "watch" templates over HTTP, so they are re-downloaded
  4149. // and compiled each time. (Remember, PRECOMPILE YOUR
  4150. // TEMPLATES in production!)
  4151. _this.useCache = !!opts.useCache; // We default `async` to false so that the simple synchronous
  4152. // API can be used when you aren't doing anything async in
  4153. // your templates (which is most of the time). This performs a
  4154. // sync ajax request, but that's ok because it should *only*
  4155. // happen in development. PRECOMPILE YOUR TEMPLATES.
  4156. _this.async = !!opts.async;
  4157. return _this;
  4158. }
  4159. var _proto = WebLoader.prototype;
  4160. _proto.resolve = function resolve(from, to) {
  4161. throw new Error('relative templates not support in the browser yet');
  4162. };
  4163. _proto.getSource = function getSource(name, cb) {
  4164. var _this2 = this;
  4165. var useCache = this.useCache;
  4166. var result;
  4167. this.fetch(this.baseURL + '/' + name, function (err, src) {
  4168. if (err) {
  4169. if (cb) {
  4170. cb(err.content);
  4171. } else if (err.status === 404) {
  4172. result = null;
  4173. } else {
  4174. throw err.content;
  4175. }
  4176. } else {
  4177. result = {
  4178. src: src,
  4179. path: name,
  4180. noCache: !useCache
  4181. };
  4182. _this2.emit('load', name, result);
  4183. if (cb) {
  4184. cb(null, result);
  4185. }
  4186. }
  4187. }); // if this WebLoader isn't running asynchronously, the
  4188. // fetch above would actually run sync and we'll have a
  4189. // result here
  4190. return result;
  4191. };
  4192. _proto.fetch = function fetch(url, cb) {
  4193. // Only in the browser please
  4194. if (typeof window === 'undefined') {
  4195. throw new Error('WebLoader can only by used in a browser');
  4196. }
  4197. var ajax = new XMLHttpRequest();
  4198. var loading = true;
  4199. ajax.onreadystatechange = function () {
  4200. if (ajax.readyState === 4 && loading) {
  4201. loading = false;
  4202. if (ajax.status === 0 || ajax.status === 200) {
  4203. cb(null, ajax.responseText);
  4204. } else {
  4205. cb({
  4206. status: ajax.status,
  4207. content: ajax.responseText
  4208. });
  4209. }
  4210. }
  4211. };
  4212. url += (url.indexOf('?') === -1 ? '?' : '&') + 's=' + new Date().getTime();
  4213. ajax.open('GET', url, this.async);
  4214. ajax.send();
  4215. };
  4216. return WebLoader;
  4217. }(Loader);
  4218. module.exports = {
  4219. WebLoader: WebLoader,
  4220. PrecompiledLoader: PrecompiledLoader
  4221. };
  4222. /***/ }),
  4223. /* 11 */
  4224. /***/ (function(module, exports, __webpack_require__) {
  4225. "use strict";
  4226. var lib = __webpack_require__(0);
  4227. var _require = __webpack_require__(7),
  4228. Environment = _require.Environment,
  4229. Template = _require.Template;
  4230. var Loader = __webpack_require__(6);
  4231. var loaders = __webpack_require__(10);
  4232. var precompile = __webpack_require__(23);
  4233. var compiler = __webpack_require__(5);
  4234. var parser = __webpack_require__(8);
  4235. var lexer = __webpack_require__(9);
  4236. var runtime = __webpack_require__(2);
  4237. var nodes = __webpack_require__(3);
  4238. var installJinjaCompat = __webpack_require__(25); // A single instance of an environment, since this is so commonly used
  4239. var e;
  4240. function configure(templatesPath, opts) {
  4241. opts = opts || {};
  4242. if (lib.isObject(templatesPath)) {
  4243. opts = templatesPath;
  4244. templatesPath = null;
  4245. }
  4246. var TemplateLoader;
  4247. if (loaders.FileSystemLoader) {
  4248. TemplateLoader = new loaders.FileSystemLoader(templatesPath, {
  4249. watch: opts.watch,
  4250. noCache: opts.noCache
  4251. });
  4252. } else if (loaders.WebLoader) {
  4253. TemplateLoader = new loaders.WebLoader(templatesPath, {
  4254. useCache: opts.web && opts.web.useCache,
  4255. async: opts.web && opts.web.async
  4256. });
  4257. }
  4258. e = new Environment(TemplateLoader, opts);
  4259. if (opts && opts.express) {
  4260. e.express(opts.express);
  4261. }
  4262. return e;
  4263. }
  4264. module.exports = {
  4265. Environment: Environment,
  4266. Template: Template,
  4267. Loader: Loader,
  4268. FileSystemLoader: loaders.FileSystemLoader,
  4269. NodeResolveLoader: loaders.NodeResolveLoader,
  4270. PrecompiledLoader: loaders.PrecompiledLoader,
  4271. WebLoader: loaders.WebLoader,
  4272. compiler: compiler,
  4273. parser: parser,
  4274. lexer: lexer,
  4275. runtime: runtime,
  4276. lib: lib,
  4277. nodes: nodes,
  4278. installJinjaCompat: installJinjaCompat,
  4279. configure: configure,
  4280. reset: function reset() {
  4281. e = undefined;
  4282. },
  4283. compile: function compile(src, env, path, eagerCompile) {
  4284. if (!e) {
  4285. configure();
  4286. }
  4287. return new Template(src, env, path, eagerCompile);
  4288. },
  4289. render: function render(name, ctx, cb) {
  4290. if (!e) {
  4291. configure();
  4292. }
  4293. return e.render(name, ctx, cb);
  4294. },
  4295. renderString: function renderString(src, ctx, cb) {
  4296. if (!e) {
  4297. configure();
  4298. }
  4299. return e.renderString(src, ctx, cb);
  4300. },
  4301. precompile: precompile ? precompile.precompile : undefined,
  4302. precompileString: precompile ? precompile.precompileString : undefined
  4303. };
  4304. /***/ }),
  4305. /* 12 */
  4306. /***/ (function(module, exports, __webpack_require__) {
  4307. "use strict";
  4308. // rawAsap provides everything we need except exception management.
  4309. var rawAsap = __webpack_require__(13);
  4310. // RawTasks are recycled to reduce GC churn.
  4311. var freeTasks = [];
  4312. // We queue errors to ensure they are thrown in right order (FIFO).
  4313. // Array-as-queue is good enough here, since we are just dealing with exceptions.
  4314. var pendingErrors = [];
  4315. var requestErrorThrow = rawAsap.makeRequestCallFromTimer(throwFirstError);
  4316. function throwFirstError() {
  4317. if (pendingErrors.length) {
  4318. throw pendingErrors.shift();
  4319. }
  4320. }
  4321. /**
  4322. * Calls a task as soon as possible after returning, in its own event, with priority
  4323. * over other events like animation, reflow, and repaint. An error thrown from an
  4324. * event will not interrupt, nor even substantially slow down the processing of
  4325. * other events, but will be rather postponed to a lower priority event.
  4326. * @param {{call}} task A callable object, typically a function that takes no
  4327. * arguments.
  4328. */
  4329. module.exports = asap;
  4330. function asap(task) {
  4331. var rawTask;
  4332. if (freeTasks.length) {
  4333. rawTask = freeTasks.pop();
  4334. } else {
  4335. rawTask = new RawTask();
  4336. }
  4337. rawTask.task = task;
  4338. rawAsap(rawTask);
  4339. }
  4340. // We wrap tasks with recyclable task objects. A task object implements
  4341. // `call`, just like a function.
  4342. function RawTask() {
  4343. this.task = null;
  4344. }
  4345. // The sole purpose of wrapping the task is to catch the exception and recycle
  4346. // the task object after its single use.
  4347. RawTask.prototype.call = function () {
  4348. try {
  4349. this.task.call();
  4350. } catch (error) {
  4351. if (asap.onerror) {
  4352. // This hook exists purely for testing purposes.
  4353. // Its name will be periodically randomized to break any code that
  4354. // depends on its existence.
  4355. asap.onerror(error);
  4356. } else {
  4357. // In a web browser, exceptions are not fatal. However, to avoid
  4358. // slowing down the queue of pending tasks, we rethrow the error in a
  4359. // lower priority turn.
  4360. pendingErrors.push(error);
  4361. requestErrorThrow();
  4362. }
  4363. } finally {
  4364. this.task = null;
  4365. freeTasks[freeTasks.length] = this;
  4366. }
  4367. };
  4368. /***/ }),
  4369. /* 13 */
  4370. /***/ (function(module, exports, __webpack_require__) {
  4371. "use strict";
  4372. /* WEBPACK VAR INJECTION */(function(global) {
  4373. // Use the fastest means possible to execute a task in its own turn, with
  4374. // priority over other events including IO, animation, reflow, and redraw
  4375. // events in browsers.
  4376. //
  4377. // An exception thrown by a task will permanently interrupt the processing of
  4378. // subsequent tasks. The higher level `asap` function ensures that if an
  4379. // exception is thrown by a task, that the task queue will continue flushing as
  4380. // soon as possible, but if you use `rawAsap` directly, you are responsible to
  4381. // either ensure that no exceptions are thrown from your task, or to manually
  4382. // call `rawAsap.requestFlush` if an exception is thrown.
  4383. module.exports = rawAsap;
  4384. function rawAsap(task) {
  4385. if (!queue.length) {
  4386. requestFlush();
  4387. flushing = true;
  4388. }
  4389. // Equivalent to push, but avoids a function call.
  4390. queue[queue.length] = task;
  4391. }
  4392. var queue = [];
  4393. // Once a flush has been requested, no further calls to `requestFlush` are
  4394. // necessary until the next `flush` completes.
  4395. var flushing = false;
  4396. // `requestFlush` is an implementation-specific method that attempts to kick
  4397. // off a `flush` event as quickly as possible. `flush` will attempt to exhaust
  4398. // the event queue before yielding to the browser's own event loop.
  4399. var requestFlush;
  4400. // The position of the next task to execute in the task queue. This is
  4401. // preserved between calls to `flush` so that it can be resumed if
  4402. // a task throws an exception.
  4403. var index = 0;
  4404. // If a task schedules additional tasks recursively, the task queue can grow
  4405. // unbounded. To prevent memory exhaustion, the task queue will periodically
  4406. // truncate already-completed tasks.
  4407. var capacity = 1024;
  4408. // The flush function processes all tasks that have been scheduled with
  4409. // `rawAsap` unless and until one of those tasks throws an exception.
  4410. // If a task throws an exception, `flush` ensures that its state will remain
  4411. // consistent and will resume where it left off when called again.
  4412. // However, `flush` does not make any arrangements to be called again if an
  4413. // exception is thrown.
  4414. function flush() {
  4415. while (index < queue.length) {
  4416. var currentIndex = index;
  4417. // Advance the index before calling the task. This ensures that we will
  4418. // begin flushing on the next task the task throws an error.
  4419. index = index + 1;
  4420. queue[currentIndex].call();
  4421. // Prevent leaking memory for long chains of recursive calls to `asap`.
  4422. // If we call `asap` within tasks scheduled by `asap`, the queue will
  4423. // grow, but to avoid an O(n) walk for every task we execute, we don't
  4424. // shift tasks off the queue after they have been executed.
  4425. // Instead, we periodically shift 1024 tasks off the queue.
  4426. if (index > capacity) {
  4427. // Manually shift all values starting at the index back to the
  4428. // beginning of the queue.
  4429. for (var scan = 0, newLength = queue.length - index; scan < newLength; scan++) {
  4430. queue[scan] = queue[scan + index];
  4431. }
  4432. queue.length -= index;
  4433. index = 0;
  4434. }
  4435. }
  4436. queue.length = 0;
  4437. index = 0;
  4438. flushing = false;
  4439. }
  4440. // `requestFlush` is implemented using a strategy based on data collected from
  4441. // every available SauceLabs Selenium web driver worker at time of writing.
  4442. // https://docs.google.com/spreadsheets/d/1mG-5UYGup5qxGdEMWkhP6BWCz053NUb2E1QoUTU16uA/edit#gid=783724593
  4443. // Safari 6 and 6.1 for desktop, iPad, and iPhone are the only browsers that
  4444. // have WebKitMutationObserver but not un-prefixed MutationObserver.
  4445. // Must use `global` or `self` instead of `window` to work in both frames and web
  4446. // workers. `global` is a provision of Browserify, Mr, Mrs, or Mop.
  4447. /* globals self */
  4448. var scope = typeof global !== "undefined" ? global : self;
  4449. var BrowserMutationObserver = scope.MutationObserver || scope.WebKitMutationObserver;
  4450. // MutationObservers are desirable because they have high priority and work
  4451. // reliably everywhere they are implemented.
  4452. // They are implemented in all modern browsers.
  4453. //
  4454. // - Android 4-4.3
  4455. // - Chrome 26-34
  4456. // - Firefox 14-29
  4457. // - Internet Explorer 11
  4458. // - iPad Safari 6-7.1
  4459. // - iPhone Safari 7-7.1
  4460. // - Safari 6-7
  4461. if (typeof BrowserMutationObserver === "function") {
  4462. requestFlush = makeRequestCallFromMutationObserver(flush);
  4463. // MessageChannels are desirable because they give direct access to the HTML
  4464. // task queue, are implemented in Internet Explorer 10, Safari 5.0-1, and Opera
  4465. // 11-12, and in web workers in many engines.
  4466. // Although message channels yield to any queued rendering and IO tasks, they
  4467. // would be better than imposing the 4ms delay of timers.
  4468. // However, they do not work reliably in Internet Explorer or Safari.
  4469. // Internet Explorer 10 is the only browser that has setImmediate but does
  4470. // not have MutationObservers.
  4471. // Although setImmediate yields to the browser's renderer, it would be
  4472. // preferrable to falling back to setTimeout since it does not have
  4473. // the minimum 4ms penalty.
  4474. // Unfortunately there appears to be a bug in Internet Explorer 10 Mobile (and
  4475. // Desktop to a lesser extent) that renders both setImmediate and
  4476. // MessageChannel useless for the purposes of ASAP.
  4477. // https://github.com/kriskowal/q/issues/396
  4478. // Timers are implemented universally.
  4479. // We fall back to timers in workers in most engines, and in foreground
  4480. // contexts in the following browsers.
  4481. // However, note that even this simple case requires nuances to operate in a
  4482. // broad spectrum of browsers.
  4483. //
  4484. // - Firefox 3-13
  4485. // - Internet Explorer 6-9
  4486. // - iPad Safari 4.3
  4487. // - Lynx 2.8.7
  4488. } else {
  4489. requestFlush = makeRequestCallFromTimer(flush);
  4490. }
  4491. // `requestFlush` requests that the high priority event queue be flushed as
  4492. // soon as possible.
  4493. // This is useful to prevent an error thrown in a task from stalling the event
  4494. // queue if the exception handled by Node.js’s
  4495. // `process.on("uncaughtException")` or by a domain.
  4496. rawAsap.requestFlush = requestFlush;
  4497. // To request a high priority event, we induce a mutation observer by toggling
  4498. // the text of a text node between "1" and "-1".
  4499. function makeRequestCallFromMutationObserver(callback) {
  4500. var toggle = 1;
  4501. var observer = new BrowserMutationObserver(callback);
  4502. var node = document.createTextNode("");
  4503. observer.observe(node, {characterData: true});
  4504. return function requestCall() {
  4505. toggle = -toggle;
  4506. node.data = toggle;
  4507. };
  4508. }
  4509. // The message channel technique was discovered by Malte Ubl and was the
  4510. // original foundation for this library.
  4511. // http://www.nonblocking.io/2011/06/windownexttick.html
  4512. // Safari 6.0.5 (at least) intermittently fails to create message ports on a
  4513. // page's first load. Thankfully, this version of Safari supports
  4514. // MutationObservers, so we don't need to fall back in that case.
  4515. // function makeRequestCallFromMessageChannel(callback) {
  4516. // var channel = new MessageChannel();
  4517. // channel.port1.onmessage = callback;
  4518. // return function requestCall() {
  4519. // channel.port2.postMessage(0);
  4520. // };
  4521. // }
  4522. // For reasons explained above, we are also unable to use `setImmediate`
  4523. // under any circumstances.
  4524. // Even if we were, there is another bug in Internet Explorer 10.
  4525. // It is not sufficient to assign `setImmediate` to `requestFlush` because
  4526. // `setImmediate` must be called *by name* and therefore must be wrapped in a
  4527. // closure.
  4528. // Never forget.
  4529. // function makeRequestCallFromSetImmediate(callback) {
  4530. // return function requestCall() {
  4531. // setImmediate(callback);
  4532. // };
  4533. // }
  4534. // Safari 6.0 has a problem where timers will get lost while the user is
  4535. // scrolling. This problem does not impact ASAP because Safari 6.0 supports
  4536. // mutation observers, so that implementation is used instead.
  4537. // However, if we ever elect to use timers in Safari, the prevalent work-around
  4538. // is to add a scroll event listener that calls for a flush.
  4539. // `setTimeout` does not call the passed callback if the delay is less than
  4540. // approximately 7 in web workers in Firefox 8 through 18, and sometimes not
  4541. // even then.
  4542. function makeRequestCallFromTimer(callback) {
  4543. return function requestCall() {
  4544. // We dispatch a timeout with a specified delay of 0 for engines that
  4545. // can reliably accommodate that request. This will usually be snapped
  4546. // to a 4 milisecond delay, but once we're flushing, there's no delay
  4547. // between events.
  4548. var timeoutHandle = setTimeout(handleTimer, 0);
  4549. // However, since this timer gets frequently dropped in Firefox
  4550. // workers, we enlist an interval handle that will try to fire
  4551. // an event 20 times per second until it succeeds.
  4552. var intervalHandle = setInterval(handleTimer, 50);
  4553. function handleTimer() {
  4554. // Whichever timer succeeds will cancel both timers and
  4555. // execute the callback.
  4556. clearTimeout(timeoutHandle);
  4557. clearInterval(intervalHandle);
  4558. callback();
  4559. }
  4560. };
  4561. }
  4562. // This is for `asap.js` only.
  4563. // Its name will be periodically randomized to break any code that depends on
  4564. // its existence.
  4565. rawAsap.makeRequestCallFromTimer = makeRequestCallFromTimer;
  4566. // ASAP was originally a nextTick shim included in Q. This was factored out
  4567. // into this ASAP package. It was later adapted to RSVP which made further
  4568. // amendments. These decisions, particularly to marginalize MessageChannel and
  4569. // to capture the MutationObserver implementation in a closure, were integrated
  4570. // back into ASAP proper.
  4571. // https://github.com/tildeio/rsvp.js/blob/cddf7232546a9cf858524b75cde6f9edf72620a7/lib/rsvp/asap.js
  4572. /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(14)))
  4573. /***/ }),
  4574. /* 14 */
  4575. /***/ (function(module, exports) {
  4576. var g;
  4577. // This works in non-strict mode
  4578. g = (function() {
  4579. return this;
  4580. })();
  4581. try {
  4582. // This works if eval is allowed (see CSP)
  4583. g = g || Function("return this")() || (1,eval)("this");
  4584. } catch(e) {
  4585. // This works if the window reference is available
  4586. if(typeof window === "object")
  4587. g = window;
  4588. }
  4589. // g can still be undefined, but nothing to do about it...
  4590. // We return undefined, instead of nothing here, so it's
  4591. // easier to handle this case. if(!global) { ...}
  4592. module.exports = g;
  4593. /***/ }),
  4594. /* 15 */
  4595. /***/ (function(module, exports, __webpack_require__) {
  4596. var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;// MIT license (by Elan Shanker).
  4597. (function(globals) {
  4598. 'use strict';
  4599. var executeSync = function(){
  4600. var args = Array.prototype.slice.call(arguments);
  4601. if (typeof args[0] === 'function'){
  4602. args[0].apply(null, args.splice(1));
  4603. }
  4604. };
  4605. var executeAsync = function(fn){
  4606. if (typeof setImmediate === 'function') {
  4607. setImmediate(fn);
  4608. } else if (typeof process !== 'undefined' && process.nextTick) {
  4609. process.nextTick(fn);
  4610. } else {
  4611. setTimeout(fn, 0);
  4612. }
  4613. };
  4614. var makeIterator = function (tasks) {
  4615. var makeCallback = function (index) {
  4616. var fn = function () {
  4617. if (tasks.length) {
  4618. tasks[index].apply(null, arguments);
  4619. }
  4620. return fn.next();
  4621. };
  4622. fn.next = function () {
  4623. return (index < tasks.length - 1) ? makeCallback(index + 1): null;
  4624. };
  4625. return fn;
  4626. };
  4627. return makeCallback(0);
  4628. };
  4629. var _isArray = Array.isArray || function(maybeArray){
  4630. return Object.prototype.toString.call(maybeArray) === '[object Array]';
  4631. };
  4632. var waterfall = function (tasks, callback, forceAsync) {
  4633. var nextTick = forceAsync ? executeAsync : executeSync;
  4634. callback = callback || function () {};
  4635. if (!_isArray(tasks)) {
  4636. var err = new Error('First argument to waterfall must be an array of functions');
  4637. return callback(err);
  4638. }
  4639. if (!tasks.length) {
  4640. return callback();
  4641. }
  4642. var wrapIterator = function (iterator) {
  4643. return function (err) {
  4644. if (err) {
  4645. callback.apply(null, arguments);
  4646. callback = function () {};
  4647. } else {
  4648. var args = Array.prototype.slice.call(arguments, 1);
  4649. var next = iterator.next();
  4650. if (next) {
  4651. args.push(wrapIterator(next));
  4652. } else {
  4653. args.push(callback);
  4654. }
  4655. nextTick(function () {
  4656. iterator.apply(null, args);
  4657. });
  4658. }
  4659. };
  4660. };
  4661. wrapIterator(makeIterator(tasks))();
  4662. };
  4663. if (true) {
  4664. !(__WEBPACK_AMD_DEFINE_ARRAY__ = [], __WEBPACK_AMD_DEFINE_RESULT__ = (function () {
  4665. return waterfall;
  4666. }).apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__),
  4667. __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)); // RequireJS
  4668. } else if (typeof module !== 'undefined' && module.exports) {
  4669. module.exports = waterfall; // CommonJS
  4670. } else {
  4671. globals.waterfall = waterfall; // <script>
  4672. }
  4673. })(this);
  4674. /***/ }),
  4675. /* 16 */
  4676. /***/ (function(module, exports, __webpack_require__) {
  4677. "use strict";
  4678. // Copyright Joyent, Inc. and other Node contributors.
  4679. //
  4680. // Permission is hereby granted, free of charge, to any person obtaining a
  4681. // copy of this software and associated documentation files (the
  4682. // "Software"), to deal in the Software without restriction, including
  4683. // without limitation the rights to use, copy, modify, merge, publish,
  4684. // distribute, sublicense, and/or sell copies of the Software, and to permit
  4685. // persons to whom the Software is furnished to do so, subject to the
  4686. // following conditions:
  4687. //
  4688. // The above copyright notice and this permission notice shall be included
  4689. // in all copies or substantial portions of the Software.
  4690. //
  4691. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  4692. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  4693. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  4694. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  4695. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  4696. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  4697. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  4698. var R = typeof Reflect === 'object' ? Reflect : null
  4699. var ReflectApply = R && typeof R.apply === 'function'
  4700. ? R.apply
  4701. : function ReflectApply(target, receiver, args) {
  4702. return Function.prototype.apply.call(target, receiver, args);
  4703. }
  4704. var ReflectOwnKeys
  4705. if (R && typeof R.ownKeys === 'function') {
  4706. ReflectOwnKeys = R.ownKeys
  4707. } else if (Object.getOwnPropertySymbols) {
  4708. ReflectOwnKeys = function ReflectOwnKeys(target) {
  4709. return Object.getOwnPropertyNames(target)
  4710. .concat(Object.getOwnPropertySymbols(target));
  4711. };
  4712. } else {
  4713. ReflectOwnKeys = function ReflectOwnKeys(target) {
  4714. return Object.getOwnPropertyNames(target);
  4715. };
  4716. }
  4717. function ProcessEmitWarning(warning) {
  4718. if (console && console.warn) console.warn(warning);
  4719. }
  4720. var NumberIsNaN = Number.isNaN || function NumberIsNaN(value) {
  4721. return value !== value;
  4722. }
  4723. function EventEmitter() {
  4724. EventEmitter.init.call(this);
  4725. }
  4726. module.exports = EventEmitter;
  4727. module.exports.once = once;
  4728. // Backwards-compat with node 0.10.x
  4729. EventEmitter.EventEmitter = EventEmitter;
  4730. EventEmitter.prototype._events = undefined;
  4731. EventEmitter.prototype._eventsCount = 0;
  4732. EventEmitter.prototype._maxListeners = undefined;
  4733. // By default EventEmitters will print a warning if more than 10 listeners are
  4734. // added to it. This is a useful default which helps finding memory leaks.
  4735. var defaultMaxListeners = 10;
  4736. function checkListener(listener) {
  4737. if (typeof listener !== 'function') {
  4738. throw new TypeError('The "listener" argument must be of type Function. Received type ' + typeof listener);
  4739. }
  4740. }
  4741. Object.defineProperty(EventEmitter, 'defaultMaxListeners', {
  4742. enumerable: true,
  4743. get: function() {
  4744. return defaultMaxListeners;
  4745. },
  4746. set: function(arg) {
  4747. if (typeof arg !== 'number' || arg < 0 || NumberIsNaN(arg)) {
  4748. throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received ' + arg + '.');
  4749. }
  4750. defaultMaxListeners = arg;
  4751. }
  4752. });
  4753. EventEmitter.init = function() {
  4754. if (this._events === undefined ||
  4755. this._events === Object.getPrototypeOf(this)._events) {
  4756. this._events = Object.create(null);
  4757. this._eventsCount = 0;
  4758. }
  4759. this._maxListeners = this._maxListeners || undefined;
  4760. };
  4761. // Obviously not all Emitters should be limited to 10. This function allows
  4762. // that to be increased. Set to zero for unlimited.
  4763. EventEmitter.prototype.setMaxListeners = function setMaxListeners(n) {
  4764. if (typeof n !== 'number' || n < 0 || NumberIsNaN(n)) {
  4765. throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received ' + n + '.');
  4766. }
  4767. this._maxListeners = n;
  4768. return this;
  4769. };
  4770. function _getMaxListeners(that) {
  4771. if (that._maxListeners === undefined)
  4772. return EventEmitter.defaultMaxListeners;
  4773. return that._maxListeners;
  4774. }
  4775. EventEmitter.prototype.getMaxListeners = function getMaxListeners() {
  4776. return _getMaxListeners(this);
  4777. };
  4778. EventEmitter.prototype.emit = function emit(type) {
  4779. var args = [];
  4780. for (var i = 1; i < arguments.length; i++) args.push(arguments[i]);
  4781. var doError = (type === 'error');
  4782. var events = this._events;
  4783. if (events !== undefined)
  4784. doError = (doError && events.error === undefined);
  4785. else if (!doError)
  4786. return false;
  4787. // If there is no 'error' event listener then throw.
  4788. if (doError) {
  4789. var er;
  4790. if (args.length > 0)
  4791. er = args[0];
  4792. if (er instanceof Error) {
  4793. // Note: The comments on the `throw` lines are intentional, they show
  4794. // up in Node's output if this results in an unhandled exception.
  4795. throw er; // Unhandled 'error' event
  4796. }
  4797. // At least give some kind of context to the user
  4798. var err = new Error('Unhandled error.' + (er ? ' (' + er.message + ')' : ''));
  4799. err.context = er;
  4800. throw err; // Unhandled 'error' event
  4801. }
  4802. var handler = events[type];
  4803. if (handler === undefined)
  4804. return false;
  4805. if (typeof handler === 'function') {
  4806. ReflectApply(handler, this, args);
  4807. } else {
  4808. var len = handler.length;
  4809. var listeners = arrayClone(handler, len);
  4810. for (var i = 0; i < len; ++i)
  4811. ReflectApply(listeners[i], this, args);
  4812. }
  4813. return true;
  4814. };
  4815. function _addListener(target, type, listener, prepend) {
  4816. var m;
  4817. var events;
  4818. var existing;
  4819. checkListener(listener);
  4820. events = target._events;
  4821. if (events === undefined) {
  4822. events = target._events = Object.create(null);
  4823. target._eventsCount = 0;
  4824. } else {
  4825. // To avoid recursion in the case that type === "newListener"! Before
  4826. // adding it to the listeners, first emit "newListener".
  4827. if (events.newListener !== undefined) {
  4828. target.emit('newListener', type,
  4829. listener.listener ? listener.listener : listener);
  4830. // Re-assign `events` because a newListener handler could have caused the
  4831. // this._events to be assigned to a new object
  4832. events = target._events;
  4833. }
  4834. existing = events[type];
  4835. }
  4836. if (existing === undefined) {
  4837. // Optimize the case of one listener. Don't need the extra array object.
  4838. existing = events[type] = listener;
  4839. ++target._eventsCount;
  4840. } else {
  4841. if (typeof existing === 'function') {
  4842. // Adding the second element, need to change to array.
  4843. existing = events[type] =
  4844. prepend ? [listener, existing] : [existing, listener];
  4845. // If we've already got an array, just append.
  4846. } else if (prepend) {
  4847. existing.unshift(listener);
  4848. } else {
  4849. existing.push(listener);
  4850. }
  4851. // Check for listener leak
  4852. m = _getMaxListeners(target);
  4853. if (m > 0 && existing.length > m && !existing.warned) {
  4854. existing.warned = true;
  4855. // No error code for this since it is a Warning
  4856. // eslint-disable-next-line no-restricted-syntax
  4857. var w = new Error('Possible EventEmitter memory leak detected. ' +
  4858. existing.length + ' ' + String(type) + ' listeners ' +
  4859. 'added. Use emitter.setMaxListeners() to ' +
  4860. 'increase limit');
  4861. w.name = 'MaxListenersExceededWarning';
  4862. w.emitter = target;
  4863. w.type = type;
  4864. w.count = existing.length;
  4865. ProcessEmitWarning(w);
  4866. }
  4867. }
  4868. return target;
  4869. }
  4870. EventEmitter.prototype.addListener = function addListener(type, listener) {
  4871. return _addListener(this, type, listener, false);
  4872. };
  4873. EventEmitter.prototype.on = EventEmitter.prototype.addListener;
  4874. EventEmitter.prototype.prependListener =
  4875. function prependListener(type, listener) {
  4876. return _addListener(this, type, listener, true);
  4877. };
  4878. function onceWrapper() {
  4879. if (!this.fired) {
  4880. this.target.removeListener(this.type, this.wrapFn);
  4881. this.fired = true;
  4882. if (arguments.length === 0)
  4883. return this.listener.call(this.target);
  4884. return this.listener.apply(this.target, arguments);
  4885. }
  4886. }
  4887. function _onceWrap(target, type, listener) {
  4888. var state = { fired: false, wrapFn: undefined, target: target, type: type, listener: listener };
  4889. var wrapped = onceWrapper.bind(state);
  4890. wrapped.listener = listener;
  4891. state.wrapFn = wrapped;
  4892. return wrapped;
  4893. }
  4894. EventEmitter.prototype.once = function once(type, listener) {
  4895. checkListener(listener);
  4896. this.on(type, _onceWrap(this, type, listener));
  4897. return this;
  4898. };
  4899. EventEmitter.prototype.prependOnceListener =
  4900. function prependOnceListener(type, listener) {
  4901. checkListener(listener);
  4902. this.prependListener(type, _onceWrap(this, type, listener));
  4903. return this;
  4904. };
  4905. // Emits a 'removeListener' event if and only if the listener was removed.
  4906. EventEmitter.prototype.removeListener =
  4907. function removeListener(type, listener) {
  4908. var list, events, position, i, originalListener;
  4909. checkListener(listener);
  4910. events = this._events;
  4911. if (events === undefined)
  4912. return this;
  4913. list = events[type];
  4914. if (list === undefined)
  4915. return this;
  4916. if (list === listener || list.listener === listener) {
  4917. if (--this._eventsCount === 0)
  4918. this._events = Object.create(null);
  4919. else {
  4920. delete events[type];
  4921. if (events.removeListener)
  4922. this.emit('removeListener', type, list.listener || listener);
  4923. }
  4924. } else if (typeof list !== 'function') {
  4925. position = -1;
  4926. for (i = list.length - 1; i >= 0; i--) {
  4927. if (list[i] === listener || list[i].listener === listener) {
  4928. originalListener = list[i].listener;
  4929. position = i;
  4930. break;
  4931. }
  4932. }
  4933. if (position < 0)
  4934. return this;
  4935. if (position === 0)
  4936. list.shift();
  4937. else {
  4938. spliceOne(list, position);
  4939. }
  4940. if (list.length === 1)
  4941. events[type] = list[0];
  4942. if (events.removeListener !== undefined)
  4943. this.emit('removeListener', type, originalListener || listener);
  4944. }
  4945. return this;
  4946. };
  4947. EventEmitter.prototype.off = EventEmitter.prototype.removeListener;
  4948. EventEmitter.prototype.removeAllListeners =
  4949. function removeAllListeners(type) {
  4950. var listeners, events, i;
  4951. events = this._events;
  4952. if (events === undefined)
  4953. return this;
  4954. // not listening for removeListener, no need to emit
  4955. if (events.removeListener === undefined) {
  4956. if (arguments.length === 0) {
  4957. this._events = Object.create(null);
  4958. this._eventsCount = 0;
  4959. } else if (events[type] !== undefined) {
  4960. if (--this._eventsCount === 0)
  4961. this._events = Object.create(null);
  4962. else
  4963. delete events[type];
  4964. }
  4965. return this;
  4966. }
  4967. // emit removeListener for all listeners on all events
  4968. if (arguments.length === 0) {
  4969. var keys = Object.keys(events);
  4970. var key;
  4971. for (i = 0; i < keys.length; ++i) {
  4972. key = keys[i];
  4973. if (key === 'removeListener') continue;
  4974. this.removeAllListeners(key);
  4975. }
  4976. this.removeAllListeners('removeListener');
  4977. this._events = Object.create(null);
  4978. this._eventsCount = 0;
  4979. return this;
  4980. }
  4981. listeners = events[type];
  4982. if (typeof listeners === 'function') {
  4983. this.removeListener(type, listeners);
  4984. } else if (listeners !== undefined) {
  4985. // LIFO order
  4986. for (i = listeners.length - 1; i >= 0; i--) {
  4987. this.removeListener(type, listeners[i]);
  4988. }
  4989. }
  4990. return this;
  4991. };
  4992. function _listeners(target, type, unwrap) {
  4993. var events = target._events;
  4994. if (events === undefined)
  4995. return [];
  4996. var evlistener = events[type];
  4997. if (evlistener === undefined)
  4998. return [];
  4999. if (typeof evlistener === 'function')
  5000. return unwrap ? [evlistener.listener || evlistener] : [evlistener];
  5001. return unwrap ?
  5002. unwrapListeners(evlistener) : arrayClone(evlistener, evlistener.length);
  5003. }
  5004. EventEmitter.prototype.listeners = function listeners(type) {
  5005. return _listeners(this, type, true);
  5006. };
  5007. EventEmitter.prototype.rawListeners = function rawListeners(type) {
  5008. return _listeners(this, type, false);
  5009. };
  5010. EventEmitter.listenerCount = function(emitter, type) {
  5011. if (typeof emitter.listenerCount === 'function') {
  5012. return emitter.listenerCount(type);
  5013. } else {
  5014. return listenerCount.call(emitter, type);
  5015. }
  5016. };
  5017. EventEmitter.prototype.listenerCount = listenerCount;
  5018. function listenerCount(type) {
  5019. var events = this._events;
  5020. if (events !== undefined) {
  5021. var evlistener = events[type];
  5022. if (typeof evlistener === 'function') {
  5023. return 1;
  5024. } else if (evlistener !== undefined) {
  5025. return evlistener.length;
  5026. }
  5027. }
  5028. return 0;
  5029. }
  5030. EventEmitter.prototype.eventNames = function eventNames() {
  5031. return this._eventsCount > 0 ? ReflectOwnKeys(this._events) : [];
  5032. };
  5033. function arrayClone(arr, n) {
  5034. var copy = new Array(n);
  5035. for (var i = 0; i < n; ++i)
  5036. copy[i] = arr[i];
  5037. return copy;
  5038. }
  5039. function spliceOne(list, index) {
  5040. for (; index + 1 < list.length; index++)
  5041. list[index] = list[index + 1];
  5042. list.pop();
  5043. }
  5044. function unwrapListeners(arr) {
  5045. var ret = new Array(arr.length);
  5046. for (var i = 0; i < ret.length; ++i) {
  5047. ret[i] = arr[i].listener || arr[i];
  5048. }
  5049. return ret;
  5050. }
  5051. function once(emitter, name) {
  5052. return new Promise(function (resolve, reject) {
  5053. function eventListener() {
  5054. if (errorListener !== undefined) {
  5055. emitter.removeListener('error', errorListener);
  5056. }
  5057. resolve([].slice.call(arguments));
  5058. };
  5059. var errorListener;
  5060. // Adding an error listener is not optional because
  5061. // if an error is thrown on an event emitter we cannot
  5062. // guarantee that the actual event we are waiting will
  5063. // be fired. The result could be a silent way to create
  5064. // memory or file descriptor leaks, which is something
  5065. // we should avoid.
  5066. if (name !== 'error') {
  5067. errorListener = function errorListener(err) {
  5068. emitter.removeListener(name, eventListener);
  5069. reject(err);
  5070. };
  5071. emitter.once('error', errorListener);
  5072. }
  5073. emitter.once(name, eventListener);
  5074. });
  5075. }
  5076. /***/ }),
  5077. /* 17 */
  5078. /***/ (function(module, exports, __webpack_require__) {
  5079. "use strict";
  5080. var nodes = __webpack_require__(3);
  5081. var lib = __webpack_require__(0);
  5082. var sym = 0;
  5083. function gensym() {
  5084. return 'hole_' + sym++;
  5085. } // copy-on-write version of map
  5086. function mapCOW(arr, func) {
  5087. var res = null;
  5088. for (var i = 0; i < arr.length; i++) {
  5089. var item = func(arr[i]);
  5090. if (item !== arr[i]) {
  5091. if (!res) {
  5092. res = arr.slice();
  5093. }
  5094. res[i] = item;
  5095. }
  5096. }
  5097. return res || arr;
  5098. }
  5099. function walk(ast, func, depthFirst) {
  5100. if (!(ast instanceof nodes.Node)) {
  5101. return ast;
  5102. }
  5103. if (!depthFirst) {
  5104. var astT = func(ast);
  5105. if (astT && astT !== ast) {
  5106. return astT;
  5107. }
  5108. }
  5109. if (ast instanceof nodes.NodeList) {
  5110. var children = mapCOW(ast.children, function (node) {
  5111. return walk(node, func, depthFirst);
  5112. });
  5113. if (children !== ast.children) {
  5114. ast = new nodes[ast.typename](ast.lineno, ast.colno, children);
  5115. }
  5116. } else if (ast instanceof nodes.CallExtension) {
  5117. var args = walk(ast.args, func, depthFirst);
  5118. var contentArgs = mapCOW(ast.contentArgs, function (node) {
  5119. return walk(node, func, depthFirst);
  5120. });
  5121. if (args !== ast.args || contentArgs !== ast.contentArgs) {
  5122. ast = new nodes[ast.typename](ast.extName, ast.prop, args, contentArgs);
  5123. }
  5124. } else {
  5125. var props = ast.fields.map(function (field) {
  5126. return ast[field];
  5127. });
  5128. var propsT = mapCOW(props, function (prop) {
  5129. return walk(prop, func, depthFirst);
  5130. });
  5131. if (propsT !== props) {
  5132. ast = new nodes[ast.typename](ast.lineno, ast.colno);
  5133. propsT.forEach(function (prop, i) {
  5134. ast[ast.fields[i]] = prop;
  5135. });
  5136. }
  5137. }
  5138. return depthFirst ? func(ast) || ast : ast;
  5139. }
  5140. function depthWalk(ast, func) {
  5141. return walk(ast, func, true);
  5142. }
  5143. function _liftFilters(node, asyncFilters, prop) {
  5144. var children = [];
  5145. var walked = depthWalk(prop ? node[prop] : node, function (descNode) {
  5146. var symbol;
  5147. if (descNode instanceof nodes.Block) {
  5148. return descNode;
  5149. } else if (descNode instanceof nodes.Filter && lib.indexOf(asyncFilters, descNode.name.value) !== -1 || descNode instanceof nodes.CallExtensionAsync) {
  5150. symbol = new nodes.Symbol(descNode.lineno, descNode.colno, gensym());
  5151. children.push(new nodes.FilterAsync(descNode.lineno, descNode.colno, descNode.name, descNode.args, symbol));
  5152. }
  5153. return symbol;
  5154. });
  5155. if (prop) {
  5156. node[prop] = walked;
  5157. } else {
  5158. node = walked;
  5159. }
  5160. if (children.length) {
  5161. children.push(node);
  5162. return new nodes.NodeList(node.lineno, node.colno, children);
  5163. } else {
  5164. return node;
  5165. }
  5166. }
  5167. function liftFilters(ast, asyncFilters) {
  5168. return depthWalk(ast, function (node) {
  5169. if (node instanceof nodes.Output) {
  5170. return _liftFilters(node, asyncFilters);
  5171. } else if (node instanceof nodes.Set) {
  5172. return _liftFilters(node, asyncFilters, 'value');
  5173. } else if (node instanceof nodes.For) {
  5174. return _liftFilters(node, asyncFilters, 'arr');
  5175. } else if (node instanceof nodes.If) {
  5176. return _liftFilters(node, asyncFilters, 'cond');
  5177. } else if (node instanceof nodes.CallExtension) {
  5178. return _liftFilters(node, asyncFilters, 'args');
  5179. } else {
  5180. return undefined;
  5181. }
  5182. });
  5183. }
  5184. function liftSuper(ast) {
  5185. return walk(ast, function (blockNode) {
  5186. if (!(blockNode instanceof nodes.Block)) {
  5187. return;
  5188. }
  5189. var hasSuper = false;
  5190. var symbol = gensym();
  5191. blockNode.body = walk(blockNode.body, function (node) {
  5192. // eslint-disable-line consistent-return
  5193. if (node instanceof nodes.FunCall && node.name.value === 'super') {
  5194. hasSuper = true;
  5195. return new nodes.Symbol(node.lineno, node.colno, symbol);
  5196. }
  5197. });
  5198. if (hasSuper) {
  5199. blockNode.body.children.unshift(new nodes.Super(0, 0, blockNode.name, new nodes.Symbol(0, 0, symbol)));
  5200. }
  5201. });
  5202. }
  5203. function convertStatements(ast) {
  5204. return depthWalk(ast, function (node) {
  5205. if (!(node instanceof nodes.If) && !(node instanceof nodes.For)) {
  5206. return undefined;
  5207. }
  5208. var async = false;
  5209. walk(node, function (child) {
  5210. if (child instanceof nodes.FilterAsync || child instanceof nodes.IfAsync || child instanceof nodes.AsyncEach || child instanceof nodes.AsyncAll || child instanceof nodes.CallExtensionAsync) {
  5211. async = true; // Stop iterating by returning the node
  5212. return child;
  5213. }
  5214. return undefined;
  5215. });
  5216. if (async) {
  5217. if (node instanceof nodes.If) {
  5218. return new nodes.IfAsync(node.lineno, node.colno, node.cond, node.body, node.else_);
  5219. } else if (node instanceof nodes.For && !(node instanceof nodes.AsyncAll)) {
  5220. return new nodes.AsyncEach(node.lineno, node.colno, node.arr, node.name, node.body, node.else_);
  5221. }
  5222. }
  5223. return undefined;
  5224. });
  5225. }
  5226. function cps(ast, asyncFilters) {
  5227. return convertStatements(liftSuper(liftFilters(ast, asyncFilters)));
  5228. }
  5229. function transform(ast, asyncFilters) {
  5230. return cps(ast, asyncFilters || []);
  5231. } // var parser = require('./parser');
  5232. // var src = 'hello {% foo %}{% endfoo %} end';
  5233. // var ast = transform(parser.parse(src, [new FooExtension()]), ['bar']);
  5234. // nodes.printNodes(ast);
  5235. module.exports = {
  5236. transform: transform
  5237. };
  5238. /***/ }),
  5239. /* 18 */
  5240. /***/ (function(module, exports, __webpack_require__) {
  5241. "use strict";
  5242. var lib = __webpack_require__(0);
  5243. var r = __webpack_require__(2);
  5244. var exports = module.exports = {};
  5245. function normalize(value, defaultValue) {
  5246. if (value === null || value === undefined || value === false) {
  5247. return defaultValue;
  5248. }
  5249. return value;
  5250. }
  5251. exports.abs = Math.abs;
  5252. function isNaN(num) {
  5253. return num !== num; // eslint-disable-line no-self-compare
  5254. }
  5255. function batch(arr, linecount, fillWith) {
  5256. var i;
  5257. var res = [];
  5258. var tmp = [];
  5259. for (i = 0; i < arr.length; i++) {
  5260. if (i % linecount === 0 && tmp.length) {
  5261. res.push(tmp);
  5262. tmp = [];
  5263. }
  5264. tmp.push(arr[i]);
  5265. }
  5266. if (tmp.length) {
  5267. if (fillWith) {
  5268. for (i = tmp.length; i < linecount; i++) {
  5269. tmp.push(fillWith);
  5270. }
  5271. }
  5272. res.push(tmp);
  5273. }
  5274. return res;
  5275. }
  5276. exports.batch = batch;
  5277. function capitalize(str) {
  5278. str = normalize(str, '');
  5279. var ret = str.toLowerCase();
  5280. return r.copySafeness(str, ret.charAt(0).toUpperCase() + ret.slice(1));
  5281. }
  5282. exports.capitalize = capitalize;
  5283. function center(str, width) {
  5284. str = normalize(str, '');
  5285. width = width || 80;
  5286. if (str.length >= width) {
  5287. return str;
  5288. }
  5289. var spaces = width - str.length;
  5290. var pre = lib.repeat(' ', spaces / 2 - spaces % 2);
  5291. var post = lib.repeat(' ', spaces / 2);
  5292. return r.copySafeness(str, pre + str + post);
  5293. }
  5294. exports.center = center;
  5295. function default_(val, def, bool) {
  5296. if (bool) {
  5297. return val || def;
  5298. } else {
  5299. return val !== undefined ? val : def;
  5300. }
  5301. } // TODO: it is confusing to export something called 'default'
  5302. exports['default'] = default_; // eslint-disable-line dot-notation
  5303. function dictsort(val, caseSensitive, by) {
  5304. if (!lib.isObject(val)) {
  5305. throw new lib.TemplateError('dictsort filter: val must be an object');
  5306. }
  5307. var array = []; // deliberately include properties from the object's prototype
  5308. for (var k in val) {
  5309. // eslint-disable-line guard-for-in, no-restricted-syntax
  5310. array.push([k, val[k]]);
  5311. }
  5312. var si;
  5313. if (by === undefined || by === 'key') {
  5314. si = 0;
  5315. } else if (by === 'value') {
  5316. si = 1;
  5317. } else {
  5318. throw new lib.TemplateError('dictsort filter: You can only sort by either key or value');
  5319. }
  5320. array.sort(function (t1, t2) {
  5321. var a = t1[si];
  5322. var b = t2[si];
  5323. if (!caseSensitive) {
  5324. if (lib.isString(a)) {
  5325. a = a.toUpperCase();
  5326. }
  5327. if (lib.isString(b)) {
  5328. b = b.toUpperCase();
  5329. }
  5330. }
  5331. return a > b ? 1 : a === b ? 0 : -1; // eslint-disable-line no-nested-ternary
  5332. });
  5333. return array;
  5334. }
  5335. exports.dictsort = dictsort;
  5336. function dump(obj, spaces) {
  5337. return JSON.stringify(obj, null, spaces);
  5338. }
  5339. exports.dump = dump;
  5340. function escape(str) {
  5341. if (str instanceof r.SafeString) {
  5342. return str;
  5343. }
  5344. str = str === null || str === undefined ? '' : str;
  5345. return r.markSafe(lib.escape(str.toString()));
  5346. }
  5347. exports.escape = escape;
  5348. function safe(str) {
  5349. if (str instanceof r.SafeString) {
  5350. return str;
  5351. }
  5352. str = str === null || str === undefined ? '' : str;
  5353. return r.markSafe(str.toString());
  5354. }
  5355. exports.safe = safe;
  5356. function first(arr) {
  5357. return arr[0];
  5358. }
  5359. exports.first = first;
  5360. function forceescape(str) {
  5361. str = str === null || str === undefined ? '' : str;
  5362. return r.markSafe(lib.escape(str.toString()));
  5363. }
  5364. exports.forceescape = forceescape;
  5365. function groupby(arr, attr) {
  5366. return lib.groupBy(arr, attr, this.env.opts.throwOnUndefined);
  5367. }
  5368. exports.groupby = groupby;
  5369. function indent(str, width, indentfirst) {
  5370. str = normalize(str, '');
  5371. if (str === '') {
  5372. return '';
  5373. }
  5374. width = width || 4; // let res = '';
  5375. var lines = str.split('\n');
  5376. var sp = lib.repeat(' ', width);
  5377. var res = lines.map(function (l, i) {
  5378. return i === 0 && !indentfirst ? l : "" + sp + l;
  5379. }).join('\n');
  5380. return r.copySafeness(str, res);
  5381. }
  5382. exports.indent = indent;
  5383. function join(arr, del, attr) {
  5384. del = del || '';
  5385. if (attr) {
  5386. arr = lib.map(arr, function (v) {
  5387. return v[attr];
  5388. });
  5389. }
  5390. return arr.join(del);
  5391. }
  5392. exports.join = join;
  5393. function last(arr) {
  5394. return arr[arr.length - 1];
  5395. }
  5396. exports.last = last;
  5397. function lengthFilter(val) {
  5398. var value = normalize(val, '');
  5399. if (value !== undefined) {
  5400. if (typeof Map === 'function' && value instanceof Map || typeof Set === 'function' && value instanceof Set) {
  5401. // ECMAScript 2015 Maps and Sets
  5402. return value.size;
  5403. }
  5404. if (lib.isObject(value) && !(value instanceof r.SafeString)) {
  5405. // Objects (besides SafeStrings), non-primative Arrays
  5406. return lib.keys(value).length;
  5407. }
  5408. return value.length;
  5409. }
  5410. return 0;
  5411. }
  5412. exports.length = lengthFilter;
  5413. function list(val) {
  5414. if (lib.isString(val)) {
  5415. return val.split('');
  5416. } else if (lib.isObject(val)) {
  5417. return lib._entries(val || {}).map(function (_ref) {
  5418. var key = _ref[0],
  5419. value = _ref[1];
  5420. return {
  5421. key: key,
  5422. value: value
  5423. };
  5424. });
  5425. } else if (lib.isArray(val)) {
  5426. return val;
  5427. } else {
  5428. throw new lib.TemplateError('list filter: type not iterable');
  5429. }
  5430. }
  5431. exports.list = list;
  5432. function lower(str) {
  5433. str = normalize(str, '');
  5434. return str.toLowerCase();
  5435. }
  5436. exports.lower = lower;
  5437. function nl2br(str) {
  5438. if (str === null || str === undefined) {
  5439. return '';
  5440. }
  5441. return r.copySafeness(str, str.replace(/\r\n|\n/g, '<br />\n'));
  5442. }
  5443. exports.nl2br = nl2br;
  5444. function random(arr) {
  5445. return arr[Math.floor(Math.random() * arr.length)];
  5446. }
  5447. exports.random = random;
  5448. /**
  5449. * Construct select or reject filter
  5450. *
  5451. * @param {boolean} expectedTestResult
  5452. * @returns {function(array, string, *): array}
  5453. */
  5454. function getSelectOrReject(expectedTestResult) {
  5455. function filter(arr, testName, secondArg) {
  5456. if (testName === void 0) {
  5457. testName = 'truthy';
  5458. }
  5459. var context = this;
  5460. var test = context.env.getTest(testName);
  5461. return lib.toArray(arr).filter(function examineTestResult(item) {
  5462. return test.call(context, item, secondArg) === expectedTestResult;
  5463. });
  5464. }
  5465. return filter;
  5466. }
  5467. exports.reject = getSelectOrReject(false);
  5468. function rejectattr(arr, attr) {
  5469. return arr.filter(function (item) {
  5470. return !item[attr];
  5471. });
  5472. }
  5473. exports.rejectattr = rejectattr;
  5474. exports.select = getSelectOrReject(true);
  5475. function selectattr(arr, attr) {
  5476. return arr.filter(function (item) {
  5477. return !!item[attr];
  5478. });
  5479. }
  5480. exports.selectattr = selectattr;
  5481. function replace(str, old, new_, maxCount) {
  5482. var originalStr = str;
  5483. if (old instanceof RegExp) {
  5484. return str.replace(old, new_);
  5485. }
  5486. if (typeof maxCount === 'undefined') {
  5487. maxCount = -1;
  5488. }
  5489. var res = ''; // Output
  5490. // Cast Numbers in the search term to string
  5491. if (typeof old === 'number') {
  5492. old = '' + old;
  5493. } else if (typeof old !== 'string') {
  5494. // If it is something other than number or string,
  5495. // return the original string
  5496. return str;
  5497. } // Cast numbers in the replacement to string
  5498. if (typeof str === 'number') {
  5499. str = '' + str;
  5500. } // If by now, we don't have a string, throw it back
  5501. if (typeof str !== 'string' && !(str instanceof r.SafeString)) {
  5502. return str;
  5503. } // ShortCircuits
  5504. if (old === '') {
  5505. // Mimic the python behaviour: empty string is replaced
  5506. // by replacement e.g. "abc"|replace("", ".") -> .a.b.c.
  5507. res = new_ + str.split('').join(new_) + new_;
  5508. return r.copySafeness(str, res);
  5509. }
  5510. var nextIndex = str.indexOf(old); // if # of replacements to perform is 0, or the string to does
  5511. // not contain the old value, return the string
  5512. if (maxCount === 0 || nextIndex === -1) {
  5513. return str;
  5514. }
  5515. var pos = 0;
  5516. var count = 0; // # of replacements made
  5517. while (nextIndex > -1 && (maxCount === -1 || count < maxCount)) {
  5518. // Grab the next chunk of src string and add it with the
  5519. // replacement, to the result
  5520. res += str.substring(pos, nextIndex) + new_; // Increment our pointer in the src string
  5521. pos = nextIndex + old.length;
  5522. count++; // See if there are any more replacements to be made
  5523. nextIndex = str.indexOf(old, pos);
  5524. } // We've either reached the end, or done the max # of
  5525. // replacements, tack on any remaining string
  5526. if (pos < str.length) {
  5527. res += str.substring(pos);
  5528. }
  5529. return r.copySafeness(originalStr, res);
  5530. }
  5531. exports.replace = replace;
  5532. function reverse(val) {
  5533. var arr;
  5534. if (lib.isString(val)) {
  5535. arr = list(val);
  5536. } else {
  5537. // Copy it
  5538. arr = lib.map(val, function (v) {
  5539. return v;
  5540. });
  5541. }
  5542. arr.reverse();
  5543. if (lib.isString(val)) {
  5544. return r.copySafeness(val, arr.join(''));
  5545. }
  5546. return arr;
  5547. }
  5548. exports.reverse = reverse;
  5549. function round(val, precision, method) {
  5550. precision = precision || 0;
  5551. var factor = Math.pow(10, precision);
  5552. var rounder;
  5553. if (method === 'ceil') {
  5554. rounder = Math.ceil;
  5555. } else if (method === 'floor') {
  5556. rounder = Math.floor;
  5557. } else {
  5558. rounder = Math.round;
  5559. }
  5560. return rounder(val * factor) / factor;
  5561. }
  5562. exports.round = round;
  5563. function slice(arr, slices, fillWith) {
  5564. var sliceLength = Math.floor(arr.length / slices);
  5565. var extra = arr.length % slices;
  5566. var res = [];
  5567. var offset = 0;
  5568. for (var i = 0; i < slices; i++) {
  5569. var start = offset + i * sliceLength;
  5570. if (i < extra) {
  5571. offset++;
  5572. }
  5573. var end = offset + (i + 1) * sliceLength;
  5574. var currSlice = arr.slice(start, end);
  5575. if (fillWith && i >= extra) {
  5576. currSlice.push(fillWith);
  5577. }
  5578. res.push(currSlice);
  5579. }
  5580. return res;
  5581. }
  5582. exports.slice = slice;
  5583. function sum(arr, attr, start) {
  5584. if (start === void 0) {
  5585. start = 0;
  5586. }
  5587. if (attr) {
  5588. arr = lib.map(arr, function (v) {
  5589. return v[attr];
  5590. });
  5591. }
  5592. return start + arr.reduce(function (a, b) {
  5593. return a + b;
  5594. }, 0);
  5595. }
  5596. exports.sum = sum;
  5597. exports.sort = r.makeMacro(['value', 'reverse', 'case_sensitive', 'attribute'], [], function sortFilter(arr, reversed, caseSens, attr) {
  5598. var _this = this;
  5599. // Copy it
  5600. var array = lib.map(arr, function (v) {
  5601. return v;
  5602. });
  5603. var getAttribute = lib.getAttrGetter(attr);
  5604. array.sort(function (a, b) {
  5605. var x = attr ? getAttribute(a) : a;
  5606. var y = attr ? getAttribute(b) : b;
  5607. if (_this.env.opts.throwOnUndefined && attr && (x === undefined || y === undefined)) {
  5608. throw new TypeError("sort: attribute \"" + attr + "\" resolved to undefined");
  5609. }
  5610. if (!caseSens && lib.isString(x) && lib.isString(y)) {
  5611. x = x.toLowerCase();
  5612. y = y.toLowerCase();
  5613. }
  5614. if (x < y) {
  5615. return reversed ? 1 : -1;
  5616. } else if (x > y) {
  5617. return reversed ? -1 : 1;
  5618. } else {
  5619. return 0;
  5620. }
  5621. });
  5622. return array;
  5623. });
  5624. function string(obj) {
  5625. return r.copySafeness(obj, obj);
  5626. }
  5627. exports.string = string;
  5628. function striptags(input, preserveLinebreaks) {
  5629. input = normalize(input, '');
  5630. var tags = /<\/?([a-z][a-z0-9]*)\b[^>]*>|<!--[\s\S]*?-->/gi;
  5631. var trimmedInput = trim(input.replace(tags, ''));
  5632. var res = '';
  5633. if (preserveLinebreaks) {
  5634. res = trimmedInput.replace(/^ +| +$/gm, '') // remove leading and trailing spaces
  5635. .replace(/ +/g, ' ') // squash adjacent spaces
  5636. .replace(/(\r\n)/g, '\n') // normalize linebreaks (CRLF -> LF)
  5637. .replace(/\n\n\n+/g, '\n\n'); // squash abnormal adjacent linebreaks
  5638. } else {
  5639. res = trimmedInput.replace(/\s+/gi, ' ');
  5640. }
  5641. return r.copySafeness(input, res);
  5642. }
  5643. exports.striptags = striptags;
  5644. function title(str) {
  5645. str = normalize(str, '');
  5646. var words = str.split(' ').map(function (word) {
  5647. return capitalize(word);
  5648. });
  5649. return r.copySafeness(str, words.join(' '));
  5650. }
  5651. exports.title = title;
  5652. function trim(str) {
  5653. return r.copySafeness(str, str.replace(/^\s*|\s*$/g, ''));
  5654. }
  5655. exports.trim = trim;
  5656. function truncate(input, length, killwords, end) {
  5657. var orig = input;
  5658. input = normalize(input, '');
  5659. length = length || 255;
  5660. if (input.length <= length) {
  5661. return input;
  5662. }
  5663. if (killwords) {
  5664. input = input.substring(0, length);
  5665. } else {
  5666. var idx = input.lastIndexOf(' ', length);
  5667. if (idx === -1) {
  5668. idx = length;
  5669. }
  5670. input = input.substring(0, idx);
  5671. }
  5672. input += end !== undefined && end !== null ? end : '...';
  5673. return r.copySafeness(orig, input);
  5674. }
  5675. exports.truncate = truncate;
  5676. function upper(str) {
  5677. str = normalize(str, '');
  5678. return str.toUpperCase();
  5679. }
  5680. exports.upper = upper;
  5681. function urlencode(obj) {
  5682. var enc = encodeURIComponent;
  5683. if (lib.isString(obj)) {
  5684. return enc(obj);
  5685. } else {
  5686. var keyvals = lib.isArray(obj) ? obj : lib._entries(obj);
  5687. return keyvals.map(function (_ref2) {
  5688. var k = _ref2[0],
  5689. v = _ref2[1];
  5690. return enc(k) + "=" + enc(v);
  5691. }).join('&');
  5692. }
  5693. }
  5694. exports.urlencode = urlencode; // For the jinja regexp, see
  5695. // https://github.com/mitsuhiko/jinja2/blob/f15b814dcba6aa12bc74d1f7d0c881d55f7126be/jinja2/utils.py#L20-L23
  5696. var puncRe = /^(?:\(|<|&lt;)?(.*?)(?:\.|,|\)|\n|&gt;)?$/; // from http://blog.gerv.net/2011/05/html5_email_address_regexp/
  5697. var emailRe = /^[\w.!#$%&'*+\-\/=?\^`{|}~]+@[a-z\d\-]+(\.[a-z\d\-]+)+$/i;
  5698. var httpHttpsRe = /^https?:\/\/.*$/;
  5699. var wwwRe = /^www\./;
  5700. var tldRe = /\.(?:org|net|com)(?:\:|\/|$)/;
  5701. function urlize(str, length, nofollow) {
  5702. if (isNaN(length)) {
  5703. length = Infinity;
  5704. }
  5705. var noFollowAttr = nofollow === true ? ' rel="nofollow"' : '';
  5706. var words = str.split(/(\s+)/).filter(function (word) {
  5707. // If the word has no length, bail. This can happen for str with
  5708. // trailing whitespace.
  5709. return word && word.length;
  5710. }).map(function (word) {
  5711. var matches = word.match(puncRe);
  5712. var possibleUrl = matches ? matches[1] : word;
  5713. var shortUrl = possibleUrl.substr(0, length); // url that starts with http or https
  5714. if (httpHttpsRe.test(possibleUrl)) {
  5715. return "<a href=\"" + possibleUrl + "\"" + noFollowAttr + ">" + shortUrl + "</a>";
  5716. } // url that starts with www.
  5717. if (wwwRe.test(possibleUrl)) {
  5718. return "<a href=\"http://" + possibleUrl + "\"" + noFollowAttr + ">" + shortUrl + "</a>";
  5719. } // an email address of the form username@domain.tld
  5720. if (emailRe.test(possibleUrl)) {
  5721. return "<a href=\"mailto:" + possibleUrl + "\">" + possibleUrl + "</a>";
  5722. } // url that ends in .com, .org or .net that is not an email address
  5723. if (tldRe.test(possibleUrl)) {
  5724. return "<a href=\"http://" + possibleUrl + "\"" + noFollowAttr + ">" + shortUrl + "</a>";
  5725. }
  5726. return word;
  5727. });
  5728. return words.join('');
  5729. }
  5730. exports.urlize = urlize;
  5731. function wordcount(str) {
  5732. str = normalize(str, '');
  5733. var words = str ? str.match(/\w+/g) : null;
  5734. return words ? words.length : null;
  5735. }
  5736. exports.wordcount = wordcount;
  5737. function float(val, def) {
  5738. var res = parseFloat(val);
  5739. return isNaN(res) ? def : res;
  5740. }
  5741. exports.float = float;
  5742. var intFilter = r.makeMacro(['value', 'default', 'base'], [], function doInt(value, defaultValue, base) {
  5743. if (base === void 0) {
  5744. base = 10;
  5745. }
  5746. var res = parseInt(value, base);
  5747. return isNaN(res) ? defaultValue : res;
  5748. });
  5749. exports.int = intFilter; // Aliases
  5750. exports.d = exports.default;
  5751. exports.e = exports.escape;
  5752. /***/ }),
  5753. /* 19 */
  5754. /***/ (function(module, exports, __webpack_require__) {
  5755. "use strict";
  5756. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  5757. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  5758. var Loader = __webpack_require__(6);
  5759. var PrecompiledLoader = /*#__PURE__*/function (_Loader) {
  5760. _inheritsLoose(PrecompiledLoader, _Loader);
  5761. function PrecompiledLoader(compiledTemplates) {
  5762. var _this;
  5763. _this = _Loader.call(this) || this;
  5764. _this.precompiled = compiledTemplates || {};
  5765. return _this;
  5766. }
  5767. var _proto = PrecompiledLoader.prototype;
  5768. _proto.getSource = function getSource(name) {
  5769. if (this.precompiled[name]) {
  5770. return {
  5771. src: {
  5772. type: 'code',
  5773. obj: this.precompiled[name]
  5774. },
  5775. path: name
  5776. };
  5777. }
  5778. return null;
  5779. };
  5780. return PrecompiledLoader;
  5781. }(Loader);
  5782. module.exports = {
  5783. PrecompiledLoader: PrecompiledLoader
  5784. };
  5785. /***/ }),
  5786. /* 20 */
  5787. /***/ (function(module, exports, __webpack_require__) {
  5788. "use strict";
  5789. var SafeString = __webpack_require__(2).SafeString;
  5790. /**
  5791. * Returns `true` if the object is a function, otherwise `false`.
  5792. * @param { any } value
  5793. * @returns { boolean }
  5794. */
  5795. function callable(value) {
  5796. return typeof value === 'function';
  5797. }
  5798. exports.callable = callable;
  5799. /**
  5800. * Returns `true` if the object is strictly not `undefined`.
  5801. * @param { any } value
  5802. * @returns { boolean }
  5803. */
  5804. function defined(value) {
  5805. return value !== undefined;
  5806. }
  5807. exports.defined = defined;
  5808. /**
  5809. * Returns `true` if the operand (one) is divisble by the test's argument
  5810. * (two).
  5811. * @param { number } one
  5812. * @param { number } two
  5813. * @returns { boolean }
  5814. */
  5815. function divisibleby(one, two) {
  5816. return one % two === 0;
  5817. }
  5818. exports.divisibleby = divisibleby;
  5819. /**
  5820. * Returns true if the string has been escaped (i.e., is a SafeString).
  5821. * @param { any } value
  5822. * @returns { boolean }
  5823. */
  5824. function escaped(value) {
  5825. return value instanceof SafeString;
  5826. }
  5827. exports.escaped = escaped;
  5828. /**
  5829. * Returns `true` if the arguments are strictly equal.
  5830. * @param { any } one
  5831. * @param { any } two
  5832. */
  5833. function equalto(one, two) {
  5834. return one === two;
  5835. }
  5836. exports.equalto = equalto; // Aliases
  5837. exports.eq = exports.equalto;
  5838. exports.sameas = exports.equalto;
  5839. /**
  5840. * Returns `true` if the value is evenly divisible by 2.
  5841. * @param { number } value
  5842. * @returns { boolean }
  5843. */
  5844. function even(value) {
  5845. return value % 2 === 0;
  5846. }
  5847. exports.even = even;
  5848. /**
  5849. * Returns `true` if the value is falsy - if I recall correctly, '', 0, false,
  5850. * undefined, NaN or null. I don't know if we should stick to the default JS
  5851. * behavior or attempt to replicate what Python believes should be falsy (i.e.,
  5852. * empty arrays, empty dicts, not 0...).
  5853. * @param { any } value
  5854. * @returns { boolean }
  5855. */
  5856. function falsy(value) {
  5857. return !value;
  5858. }
  5859. exports.falsy = falsy;
  5860. /**
  5861. * Returns `true` if the operand (one) is greater or equal to the test's
  5862. * argument (two).
  5863. * @param { number } one
  5864. * @param { number } two
  5865. * @returns { boolean }
  5866. */
  5867. function ge(one, two) {
  5868. return one >= two;
  5869. }
  5870. exports.ge = ge;
  5871. /**
  5872. * Returns `true` if the operand (one) is greater than the test's argument
  5873. * (two).
  5874. * @param { number } one
  5875. * @param { number } two
  5876. * @returns { boolean }
  5877. */
  5878. function greaterthan(one, two) {
  5879. return one > two;
  5880. }
  5881. exports.greaterthan = greaterthan; // alias
  5882. exports.gt = exports.greaterthan;
  5883. /**
  5884. * Returns `true` if the operand (one) is less than or equal to the test's
  5885. * argument (two).
  5886. * @param { number } one
  5887. * @param { number } two
  5888. * @returns { boolean }
  5889. */
  5890. function le(one, two) {
  5891. return one <= two;
  5892. }
  5893. exports.le = le;
  5894. /**
  5895. * Returns `true` if the operand (one) is less than the test's passed argument
  5896. * (two).
  5897. * @param { number } one
  5898. * @param { number } two
  5899. * @returns { boolean }
  5900. */
  5901. function lessthan(one, two) {
  5902. return one < two;
  5903. }
  5904. exports.lessthan = lessthan; // alias
  5905. exports.lt = exports.lessthan;
  5906. /**
  5907. * Returns `true` if the string is lowercased.
  5908. * @param { string } value
  5909. * @returns { boolean }
  5910. */
  5911. function lower(value) {
  5912. return value.toLowerCase() === value;
  5913. }
  5914. exports.lower = lower;
  5915. /**
  5916. * Returns `true` if the operand (one) is less than or equal to the test's
  5917. * argument (two).
  5918. * @param { number } one
  5919. * @param { number } two
  5920. * @returns { boolean }
  5921. */
  5922. function ne(one, two) {
  5923. return one !== two;
  5924. }
  5925. exports.ne = ne;
  5926. /**
  5927. * Returns true if the value is strictly equal to `null`.
  5928. * @param { any }
  5929. * @returns { boolean }
  5930. */
  5931. function nullTest(value) {
  5932. return value === null;
  5933. }
  5934. exports.null = nullTest;
  5935. /**
  5936. * Returns true if value is a number.
  5937. * @param { any }
  5938. * @returns { boolean }
  5939. */
  5940. function number(value) {
  5941. return typeof value === 'number';
  5942. }
  5943. exports.number = number;
  5944. /**
  5945. * Returns `true` if the value is *not* evenly divisible by 2.
  5946. * @param { number } value
  5947. * @returns { boolean }
  5948. */
  5949. function odd(value) {
  5950. return value % 2 === 1;
  5951. }
  5952. exports.odd = odd;
  5953. /**
  5954. * Returns `true` if the value is a string, `false` if not.
  5955. * @param { any } value
  5956. * @returns { boolean }
  5957. */
  5958. function string(value) {
  5959. return typeof value === 'string';
  5960. }
  5961. exports.string = string;
  5962. /**
  5963. * Returns `true` if the value is not in the list of things considered falsy:
  5964. * '', null, undefined, 0, NaN and false.
  5965. * @param { any } value
  5966. * @returns { boolean }
  5967. */
  5968. function truthy(value) {
  5969. return !!value;
  5970. }
  5971. exports.truthy = truthy;
  5972. /**
  5973. * Returns `true` if the value is undefined.
  5974. * @param { any } value
  5975. * @returns { boolean }
  5976. */
  5977. function undefinedTest(value) {
  5978. return value === undefined;
  5979. }
  5980. exports.undefined = undefinedTest;
  5981. /**
  5982. * Returns `true` if the string is uppercased.
  5983. * @param { string } value
  5984. * @returns { boolean }
  5985. */
  5986. function upper(value) {
  5987. return value.toUpperCase() === value;
  5988. }
  5989. exports.upper = upper;
  5990. /**
  5991. * If ES6 features are available, returns `true` if the value implements the
  5992. * `Symbol.iterator` method. If not, it's a string or Array.
  5993. *
  5994. * Could potentially cause issues if a browser exists that has Set and Map but
  5995. * not Symbol.
  5996. *
  5997. * @param { any } value
  5998. * @returns { boolean }
  5999. */
  6000. function iterable(value) {
  6001. if (typeof Symbol !== 'undefined') {
  6002. return !!value[Symbol.iterator];
  6003. } else {
  6004. return Array.isArray(value) || typeof value === 'string';
  6005. }
  6006. }
  6007. exports.iterable = iterable;
  6008. /**
  6009. * If ES6 features are available, returns `true` if the value is an object hash
  6010. * or an ES6 Map. Otherwise just return if it's an object hash.
  6011. * @param { any } value
  6012. * @returns { boolean }
  6013. */
  6014. function mapping(value) {
  6015. // only maps and object hashes
  6016. var bool = value !== null && value !== undefined && typeof value === 'object' && !Array.isArray(value);
  6017. if (Set) {
  6018. return bool && !(value instanceof Set);
  6019. } else {
  6020. return bool;
  6021. }
  6022. }
  6023. exports.mapping = mapping;
  6024. /***/ }),
  6025. /* 21 */
  6026. /***/ (function(module, exports, __webpack_require__) {
  6027. "use strict";
  6028. function _cycler(items) {
  6029. var index = -1;
  6030. return {
  6031. current: null,
  6032. reset: function reset() {
  6033. index = -1;
  6034. this.current = null;
  6035. },
  6036. next: function next() {
  6037. index++;
  6038. if (index >= items.length) {
  6039. index = 0;
  6040. }
  6041. this.current = items[index];
  6042. return this.current;
  6043. }
  6044. };
  6045. }
  6046. function _joiner(sep) {
  6047. sep = sep || ',';
  6048. var first = true;
  6049. return function () {
  6050. var val = first ? '' : sep;
  6051. first = false;
  6052. return val;
  6053. };
  6054. } // Making this a function instead so it returns a new object
  6055. // each time it's called. That way, if something like an environment
  6056. // uses it, they will each have their own copy.
  6057. function globals() {
  6058. return {
  6059. range: function range(start, stop, step) {
  6060. if (typeof stop === 'undefined') {
  6061. stop = start;
  6062. start = 0;
  6063. step = 1;
  6064. } else if (!step) {
  6065. step = 1;
  6066. }
  6067. var arr = [];
  6068. if (step > 0) {
  6069. for (var i = start; i < stop; i += step) {
  6070. arr.push(i);
  6071. }
  6072. } else {
  6073. for (var _i = start; _i > stop; _i += step) {
  6074. // eslint-disable-line for-direction
  6075. arr.push(_i);
  6076. }
  6077. }
  6078. return arr;
  6079. },
  6080. cycler: function cycler() {
  6081. return _cycler(Array.prototype.slice.call(arguments));
  6082. },
  6083. joiner: function joiner(sep) {
  6084. return _joiner(sep);
  6085. }
  6086. };
  6087. }
  6088. module.exports = globals;
  6089. /***/ }),
  6090. /* 22 */
  6091. /***/ (function(module, exports, __webpack_require__) {
  6092. var path = __webpack_require__(4);
  6093. module.exports = function express(env, app) {
  6094. function NunjucksView(name, opts) {
  6095. this.name = name;
  6096. this.path = name;
  6097. this.defaultEngine = opts.defaultEngine;
  6098. this.ext = path.extname(name);
  6099. if (!this.ext && !this.defaultEngine) {
  6100. throw new Error('No default engine was specified and no extension was provided.');
  6101. }
  6102. if (!this.ext) {
  6103. this.name += this.ext = (this.defaultEngine[0] !== '.' ? '.' : '') + this.defaultEngine;
  6104. }
  6105. }
  6106. NunjucksView.prototype.render = function render(opts, cb) {
  6107. env.render(this.name, opts, cb);
  6108. };
  6109. app.set('view', NunjucksView);
  6110. app.set('nunjucksEnv', env);
  6111. return env;
  6112. };
  6113. /***/ }),
  6114. /* 23 */
  6115. /***/ (function(module, exports, __webpack_require__) {
  6116. "use strict";
  6117. var fs = __webpack_require__(4);
  6118. var path = __webpack_require__(4);
  6119. var _require = __webpack_require__(0),
  6120. _prettifyError = _require._prettifyError;
  6121. var compiler = __webpack_require__(5);
  6122. var _require2 = __webpack_require__(7),
  6123. Environment = _require2.Environment;
  6124. var precompileGlobal = __webpack_require__(24);
  6125. function match(filename, patterns) {
  6126. if (!Array.isArray(patterns)) {
  6127. return false;
  6128. }
  6129. return patterns.some(function (pattern) {
  6130. return filename.match(pattern);
  6131. });
  6132. }
  6133. function precompileString(str, opts) {
  6134. opts = opts || {};
  6135. opts.isString = true;
  6136. var env = opts.env || new Environment([]);
  6137. var wrapper = opts.wrapper || precompileGlobal;
  6138. if (!opts.name) {
  6139. throw new Error('the "name" option is required when compiling a string');
  6140. }
  6141. return wrapper([_precompile(str, opts.name, env)], opts);
  6142. }
  6143. function precompile(input, opts) {
  6144. // The following options are available:
  6145. //
  6146. // * name: name of the template (auto-generated when compiling a directory)
  6147. // * isString: input is a string, not a file path
  6148. // * asFunction: generate a callable function
  6149. // * force: keep compiling on error
  6150. // * env: the Environment to use (gets extensions and async filters from it)
  6151. // * include: which file/folders to include (folders are auto-included, files are auto-excluded)
  6152. // * exclude: which file/folders to exclude (folders are auto-included, files are auto-excluded)
  6153. // * wrapper: function(templates, opts) {...}
  6154. // Customize the output format to store the compiled template.
  6155. // By default, templates are stored in a global variable used by the runtime.
  6156. // A custom loader will be necessary to load your custom wrapper.
  6157. opts = opts || {};
  6158. var env = opts.env || new Environment([]);
  6159. var wrapper = opts.wrapper || precompileGlobal;
  6160. if (opts.isString) {
  6161. return precompileString(input, opts);
  6162. }
  6163. var pathStats = fs.existsSync(input) && fs.statSync(input);
  6164. var precompiled = [];
  6165. var templates = [];
  6166. function addTemplates(dir) {
  6167. fs.readdirSync(dir).forEach(function (file) {
  6168. var filepath = path.join(dir, file);
  6169. var subpath = filepath.substr(path.join(input, '/').length);
  6170. var stat = fs.statSync(filepath);
  6171. if (stat && stat.isDirectory()) {
  6172. subpath += '/';
  6173. if (!match(subpath, opts.exclude)) {
  6174. addTemplates(filepath);
  6175. }
  6176. } else if (match(subpath, opts.include)) {
  6177. templates.push(filepath);
  6178. }
  6179. });
  6180. }
  6181. if (pathStats.isFile()) {
  6182. precompiled.push(_precompile(fs.readFileSync(input, 'utf-8'), opts.name || input, env));
  6183. } else if (pathStats.isDirectory()) {
  6184. addTemplates(input);
  6185. for (var i = 0; i < templates.length; i++) {
  6186. var name = templates[i].replace(path.join(input, '/'), '');
  6187. try {
  6188. precompiled.push(_precompile(fs.readFileSync(templates[i], 'utf-8'), name, env));
  6189. } catch (e) {
  6190. if (opts.force) {
  6191. // Don't stop generating the output if we're
  6192. // forcing compilation.
  6193. console.error(e); // eslint-disable-line no-console
  6194. } else {
  6195. throw e;
  6196. }
  6197. }
  6198. }
  6199. }
  6200. return wrapper(precompiled, opts);
  6201. }
  6202. function _precompile(str, name, env) {
  6203. env = env || new Environment([]);
  6204. var asyncFilters = env.asyncFilters;
  6205. var extensions = env.extensionsList;
  6206. var template;
  6207. name = name.replace(/\\/g, '/');
  6208. try {
  6209. template = compiler.compile(str, asyncFilters, extensions, name, env.opts);
  6210. } catch (err) {
  6211. throw _prettifyError(name, false, err);
  6212. }
  6213. return {
  6214. name: name,
  6215. template: template
  6216. };
  6217. }
  6218. module.exports = {
  6219. precompile: precompile,
  6220. precompileString: precompileString
  6221. };
  6222. /***/ }),
  6223. /* 24 */
  6224. /***/ (function(module, exports, __webpack_require__) {
  6225. "use strict";
  6226. function precompileGlobal(templates, opts) {
  6227. var out = '';
  6228. opts = opts || {};
  6229. for (var i = 0; i < templates.length; i++) {
  6230. var name = JSON.stringify(templates[i].name);
  6231. var template = templates[i].template;
  6232. out += '(function() {' + '(window.nunjucksPrecompiled = window.nunjucksPrecompiled || {})' + '[' + name + '] = (function() {\n' + template + '\n})();\n';
  6233. if (opts.asFunction) {
  6234. out += 'return function(ctx, cb) { return nunjucks.render(' + name + ', ctx, cb); }\n';
  6235. }
  6236. out += '})();\n';
  6237. }
  6238. return out;
  6239. }
  6240. module.exports = precompileGlobal;
  6241. /***/ }),
  6242. /* 25 */
  6243. /***/ (function(module, exports, __webpack_require__) {
  6244. function installCompat() {
  6245. 'use strict';
  6246. /* eslint-disable camelcase */
  6247. // This must be called like `nunjucks.installCompat` so that `this`
  6248. // references the nunjucks instance
  6249. var runtime = this.runtime;
  6250. var lib = this.lib; // Handle slim case where these 'modules' are excluded from the built source
  6251. var Compiler = this.compiler.Compiler;
  6252. var Parser = this.parser.Parser;
  6253. var nodes = this.nodes;
  6254. var lexer = this.lexer;
  6255. var orig_contextOrFrameLookup = runtime.contextOrFrameLookup;
  6256. var orig_memberLookup = runtime.memberLookup;
  6257. var orig_Compiler_assertType;
  6258. var orig_Parser_parseAggregate;
  6259. if (Compiler) {
  6260. orig_Compiler_assertType = Compiler.prototype.assertType;
  6261. }
  6262. if (Parser) {
  6263. orig_Parser_parseAggregate = Parser.prototype.parseAggregate;
  6264. }
  6265. function uninstall() {
  6266. runtime.contextOrFrameLookup = orig_contextOrFrameLookup;
  6267. runtime.memberLookup = orig_memberLookup;
  6268. if (Compiler) {
  6269. Compiler.prototype.assertType = orig_Compiler_assertType;
  6270. }
  6271. if (Parser) {
  6272. Parser.prototype.parseAggregate = orig_Parser_parseAggregate;
  6273. }
  6274. }
  6275. runtime.contextOrFrameLookup = function contextOrFrameLookup(context, frame, key) {
  6276. var val = orig_contextOrFrameLookup.apply(this, arguments);
  6277. if (val !== undefined) {
  6278. return val;
  6279. }
  6280. switch (key) {
  6281. case 'True':
  6282. return true;
  6283. case 'False':
  6284. return false;
  6285. case 'None':
  6286. return null;
  6287. default:
  6288. return undefined;
  6289. }
  6290. };
  6291. function getTokensState(tokens) {
  6292. return {
  6293. index: tokens.index,
  6294. lineno: tokens.lineno,
  6295. colno: tokens.colno
  6296. };
  6297. }
  6298. if ("STD" !== 'SLIM' && nodes && Compiler && Parser) {
  6299. // i.e., not slim mode
  6300. var Slice = nodes.Node.extend('Slice', {
  6301. fields: ['start', 'stop', 'step'],
  6302. init: function init(lineno, colno, start, stop, step) {
  6303. start = start || new nodes.Literal(lineno, colno, null);
  6304. stop = stop || new nodes.Literal(lineno, colno, null);
  6305. step = step || new nodes.Literal(lineno, colno, 1);
  6306. this.parent(lineno, colno, start, stop, step);
  6307. }
  6308. });
  6309. Compiler.prototype.assertType = function assertType(node) {
  6310. if (node instanceof Slice) {
  6311. return;
  6312. }
  6313. orig_Compiler_assertType.apply(this, arguments);
  6314. };
  6315. Compiler.prototype.compileSlice = function compileSlice(node, frame) {
  6316. this._emit('(');
  6317. this._compileExpression(node.start, frame);
  6318. this._emit('),(');
  6319. this._compileExpression(node.stop, frame);
  6320. this._emit('),(');
  6321. this._compileExpression(node.step, frame);
  6322. this._emit(')');
  6323. };
  6324. Parser.prototype.parseAggregate = function parseAggregate() {
  6325. var _this = this;
  6326. var origState = getTokensState(this.tokens); // Set back one accounting for opening bracket/parens
  6327. origState.colno--;
  6328. origState.index--;
  6329. try {
  6330. return orig_Parser_parseAggregate.apply(this);
  6331. } catch (e) {
  6332. var errState = getTokensState(this.tokens);
  6333. var rethrow = function rethrow() {
  6334. lib._assign(_this.tokens, errState);
  6335. return e;
  6336. }; // Reset to state before original parseAggregate called
  6337. lib._assign(this.tokens, origState);
  6338. this.peeked = false;
  6339. var tok = this.peekToken();
  6340. if (tok.type !== lexer.TOKEN_LEFT_BRACKET) {
  6341. throw rethrow();
  6342. } else {
  6343. this.nextToken();
  6344. }
  6345. var node = new Slice(tok.lineno, tok.colno); // If we don't encounter a colon while parsing, this is not a slice,
  6346. // so re-raise the original exception.
  6347. var isSlice = false;
  6348. for (var i = 0; i <= node.fields.length; i++) {
  6349. if (this.skip(lexer.TOKEN_RIGHT_BRACKET)) {
  6350. break;
  6351. }
  6352. if (i === node.fields.length) {
  6353. if (isSlice) {
  6354. this.fail('parseSlice: too many slice components', tok.lineno, tok.colno);
  6355. } else {
  6356. break;
  6357. }
  6358. }
  6359. if (this.skip(lexer.TOKEN_COLON)) {
  6360. isSlice = true;
  6361. } else {
  6362. var field = node.fields[i];
  6363. node[field] = this.parseExpression();
  6364. isSlice = this.skip(lexer.TOKEN_COLON) || isSlice;
  6365. }
  6366. }
  6367. if (!isSlice) {
  6368. throw rethrow();
  6369. }
  6370. return new nodes.Array(tok.lineno, tok.colno, [node]);
  6371. }
  6372. };
  6373. }
  6374. function sliceLookup(obj, start, stop, step) {
  6375. obj = obj || [];
  6376. if (start === null) {
  6377. start = step < 0 ? obj.length - 1 : 0;
  6378. }
  6379. if (stop === null) {
  6380. stop = step < 0 ? -1 : obj.length;
  6381. } else if (stop < 0) {
  6382. stop += obj.length;
  6383. }
  6384. if (start < 0) {
  6385. start += obj.length;
  6386. }
  6387. var results = [];
  6388. for (var i = start;; i += step) {
  6389. if (i < 0 || i > obj.length) {
  6390. break;
  6391. }
  6392. if (step > 0 && i >= stop) {
  6393. break;
  6394. }
  6395. if (step < 0 && i <= stop) {
  6396. break;
  6397. }
  6398. results.push(runtime.memberLookup(obj, i));
  6399. }
  6400. return results;
  6401. }
  6402. function hasOwnProp(obj, key) {
  6403. return Object.prototype.hasOwnProperty.call(obj, key);
  6404. }
  6405. var ARRAY_MEMBERS = {
  6406. pop: function pop(index) {
  6407. if (index === undefined) {
  6408. return this.pop();
  6409. }
  6410. if (index >= this.length || index < 0) {
  6411. throw new Error('KeyError');
  6412. }
  6413. return this.splice(index, 1);
  6414. },
  6415. append: function append(element) {
  6416. return this.push(element);
  6417. },
  6418. remove: function remove(element) {
  6419. for (var i = 0; i < this.length; i++) {
  6420. if (this[i] === element) {
  6421. return this.splice(i, 1);
  6422. }
  6423. }
  6424. throw new Error('ValueError');
  6425. },
  6426. count: function count(element) {
  6427. var count = 0;
  6428. for (var i = 0; i < this.length; i++) {
  6429. if (this[i] === element) {
  6430. count++;
  6431. }
  6432. }
  6433. return count;
  6434. },
  6435. index: function index(element) {
  6436. var i;
  6437. if ((i = this.indexOf(element)) === -1) {
  6438. throw new Error('ValueError');
  6439. }
  6440. return i;
  6441. },
  6442. find: function find(element) {
  6443. return this.indexOf(element);
  6444. },
  6445. insert: function insert(index, elem) {
  6446. return this.splice(index, 0, elem);
  6447. }
  6448. };
  6449. var OBJECT_MEMBERS = {
  6450. items: function items() {
  6451. return lib._entries(this);
  6452. },
  6453. values: function values() {
  6454. return lib._values(this);
  6455. },
  6456. keys: function keys() {
  6457. return lib.keys(this);
  6458. },
  6459. get: function get(key, def) {
  6460. var output = this[key];
  6461. if (output === undefined) {
  6462. output = def;
  6463. }
  6464. return output;
  6465. },
  6466. has_key: function has_key(key) {
  6467. return hasOwnProp(this, key);
  6468. },
  6469. pop: function pop(key, def) {
  6470. var output = this[key];
  6471. if (output === undefined && def !== undefined) {
  6472. output = def;
  6473. } else if (output === undefined) {
  6474. throw new Error('KeyError');
  6475. } else {
  6476. delete this[key];
  6477. }
  6478. return output;
  6479. },
  6480. popitem: function popitem() {
  6481. var keys = lib.keys(this);
  6482. if (!keys.length) {
  6483. throw new Error('KeyError');
  6484. }
  6485. var k = keys[0];
  6486. var val = this[k];
  6487. delete this[k];
  6488. return [k, val];
  6489. },
  6490. setdefault: function setdefault(key, def) {
  6491. if (def === void 0) {
  6492. def = null;
  6493. }
  6494. if (!(key in this)) {
  6495. this[key] = def;
  6496. }
  6497. return this[key];
  6498. },
  6499. update: function update(kwargs) {
  6500. lib._assign(this, kwargs);
  6501. return null; // Always returns None
  6502. }
  6503. };
  6504. OBJECT_MEMBERS.iteritems = OBJECT_MEMBERS.items;
  6505. OBJECT_MEMBERS.itervalues = OBJECT_MEMBERS.values;
  6506. OBJECT_MEMBERS.iterkeys = OBJECT_MEMBERS.keys;
  6507. runtime.memberLookup = function memberLookup(obj, val, autoescape) {
  6508. if (arguments.length === 4) {
  6509. return sliceLookup.apply(this, arguments);
  6510. }
  6511. obj = obj || {}; // If the object is an object, return any of the methods that Python would
  6512. // otherwise provide.
  6513. if (lib.isArray(obj) && hasOwnProp(ARRAY_MEMBERS, val)) {
  6514. return ARRAY_MEMBERS[val].bind(obj);
  6515. }
  6516. if (lib.isObject(obj) && hasOwnProp(OBJECT_MEMBERS, val)) {
  6517. return OBJECT_MEMBERS[val].bind(obj);
  6518. }
  6519. return orig_memberLookup.apply(this, arguments);
  6520. };
  6521. return uninstall;
  6522. }
  6523. module.exports = installCompat;
  6524. /***/ })
  6525. /******/ ]);
  6526. });
  6527. //# sourceMappingURL=nunjucks.js.map