jade.js 261 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196
  1. (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.jade = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
  2. (function (process){
  3. 'use strict';
  4. /*!
  5. * Jade
  6. * Copyright(c) 2010 TJ Holowaychuk <tj@vision-media.ca>
  7. * MIT Licensed
  8. */
  9. /**
  10. * Module dependencies.
  11. */
  12. var Parser = require('./parser')
  13. , Lexer = require('./lexer')
  14. , Compiler = require('./compiler')
  15. , runtime = require('./runtime')
  16. , addWith = require('with')
  17. , fs = require('fs')
  18. , utils = require('./utils');
  19. /**
  20. * Expose self closing tags.
  21. */
  22. // FIXME: either stop exporting selfClosing in v2 or export the new object
  23. // form
  24. exports.selfClosing = Object.keys(require('void-elements'));
  25. /**
  26. * Default supported doctypes.
  27. */
  28. exports.doctypes = require('./doctypes');
  29. /**
  30. * Text filters.
  31. */
  32. exports.filters = require('./filters');
  33. /**
  34. * Utilities.
  35. */
  36. exports.utils = utils;
  37. /**
  38. * Expose `Compiler`.
  39. */
  40. exports.Compiler = Compiler;
  41. /**
  42. * Expose `Parser`.
  43. */
  44. exports.Parser = Parser;
  45. /**
  46. * Expose `Lexer`.
  47. */
  48. exports.Lexer = Lexer;
  49. /**
  50. * Nodes.
  51. */
  52. exports.nodes = require('./nodes');
  53. /**
  54. * Jade runtime helpers.
  55. */
  56. exports.runtime = runtime;
  57. /**
  58. * Template function cache.
  59. */
  60. exports.cache = {};
  61. /**
  62. * Parse the given `str` of jade and return a function body.
  63. *
  64. * @param {String} str
  65. * @param {Object} options
  66. * @return {Object}
  67. * @api private
  68. */
  69. function parse(str, options){
  70. if (options.lexer) {
  71. console.warn('Using `lexer` as a local in render() is deprecated and '
  72. + 'will be interpreted as an option in Jade 2.0.0');
  73. }
  74. // Parse
  75. var parser = new (options.parser || Parser)(str, options.filename, options);
  76. var tokens;
  77. try {
  78. // Parse
  79. tokens = parser.parse();
  80. } catch (err) {
  81. parser = parser.context();
  82. runtime.rethrow(err, parser.filename, parser.lexer.lineno, parser.input);
  83. }
  84. // Compile
  85. var compiler = new (options.compiler || Compiler)(tokens, options);
  86. var js;
  87. try {
  88. js = compiler.compile();
  89. } catch (err) {
  90. if (err.line && (err.filename || !options.filename)) {
  91. runtime.rethrow(err, err.filename, err.line, parser.input);
  92. } else {
  93. if (err instanceof Error) {
  94. err.message += '\n\nPlease report this entire error and stack trace to https://github.com/jadejs/jade/issues';
  95. }
  96. throw err;
  97. }
  98. }
  99. // Debug compiler
  100. if (options.debug) {
  101. console.error('\nCompiled Function:\n\n\u001b[90m%s\u001b[0m', js.replace(/^/gm, ' '));
  102. }
  103. var globals = [];
  104. if (options.globals) {
  105. globals = options.globals.slice();
  106. }
  107. globals.push('jade');
  108. globals.push('jade_mixins');
  109. globals.push('jade_interp');
  110. globals.push('jade_debug');
  111. globals.push('buf');
  112. var body = ''
  113. + 'var buf = [];\n'
  114. + 'var jade_mixins = {};\n'
  115. + 'var jade_interp;\n'
  116. + (options.self
  117. ? 'var self = locals || {};\n' + js
  118. : addWith('locals || {}', '\n' + js, globals)) + ';'
  119. + 'return buf.join("");';
  120. return {body: body, dependencies: parser.dependencies};
  121. }
  122. /**
  123. * Get the template from a string or a file, either compiled on-the-fly or
  124. * read from cache (if enabled), and cache the template if needed.
  125. *
  126. * If `str` is not set, the file specified in `options.filename` will be read.
  127. *
  128. * If `options.cache` is true, this function reads the file from
  129. * `options.filename` so it must be set prior to calling this function.
  130. *
  131. * @param {Object} options
  132. * @param {String=} str
  133. * @return {Function}
  134. * @api private
  135. */
  136. function handleTemplateCache (options, str) {
  137. var key = options.filename;
  138. if (options.cache && exports.cache[key]) {
  139. return exports.cache[key];
  140. } else {
  141. if (str === undefined) str = fs.readFileSync(options.filename, 'utf8');
  142. var templ = exports.compile(str, options);
  143. if (options.cache) exports.cache[key] = templ;
  144. return templ;
  145. }
  146. }
  147. /**
  148. * Compile a `Function` representation of the given jade `str`.
  149. *
  150. * Options:
  151. *
  152. * - `compileDebug` when `false` debugging code is stripped from the compiled
  153. template, when it is explicitly `true`, the source code is included in
  154. the compiled template for better accuracy.
  155. * - `filename` used to improve errors when `compileDebug` is not `false` and to resolve imports/extends
  156. *
  157. * @param {String} str
  158. * @param {Options} options
  159. * @return {Function}
  160. * @api public
  161. */
  162. exports.compile = function(str, options){
  163. var options = options || {}
  164. , filename = options.filename
  165. ? utils.stringify(options.filename)
  166. : 'undefined'
  167. , fn;
  168. str = String(str);
  169. var parsed = parse(str, options);
  170. if (options.compileDebug !== false) {
  171. fn = [
  172. 'var jade_debug = [ new jade.DebugItem( 1, ' + filename + ' ) ];'
  173. , 'try {'
  174. , parsed.body
  175. , '} catch (err) {'
  176. , ' jade.rethrow(err, jade_debug[0].filename, jade_debug[0].lineno' + (options.compileDebug === true ? ',' + utils.stringify(str) : '') + ');'
  177. , '}'
  178. ].join('\n');
  179. } else {
  180. fn = parsed.body;
  181. }
  182. fn = new Function('locals, jade', fn)
  183. var res = function(locals){ return fn(locals, Object.create(runtime)) };
  184. if (options.client) {
  185. res.toString = function () {
  186. var err = new Error('The `client` option is deprecated, use the `jade.compileClient` method instead');
  187. err.name = 'Warning';
  188. console.error(err.stack || /* istanbul ignore next */ err.message);
  189. return exports.compileClient(str, options);
  190. };
  191. }
  192. res.dependencies = parsed.dependencies;
  193. return res;
  194. };
  195. /**
  196. * Compile a JavaScript source representation of the given jade `str`.
  197. *
  198. * Options:
  199. *
  200. * - `compileDebug` When it is `true`, the source code is included in
  201. * the compiled template for better error messages.
  202. * - `filename` used to improve errors when `compileDebug` is not `true` and to resolve imports/extends
  203. * - `name` the name of the resulting function (defaults to "template")
  204. *
  205. * @param {String} str
  206. * @param {Options} options
  207. * @return {Object}
  208. * @api public
  209. */
  210. exports.compileClientWithDependenciesTracked = function(str, options){
  211. var options = options || {};
  212. var name = options.name || 'template';
  213. var filename = options.filename ? utils.stringify(options.filename) : 'undefined';
  214. var fn;
  215. str = String(str);
  216. options.compileDebug = options.compileDebug ? true : false;
  217. var parsed = parse(str, options);
  218. if (options.compileDebug) {
  219. fn = [
  220. 'var jade_debug = [ new jade.DebugItem( 1, ' + filename + ' ) ];'
  221. , 'try {'
  222. , parsed.body
  223. , '} catch (err) {'
  224. , ' jade.rethrow(err, jade_debug[0].filename, jade_debug[0].lineno, ' + utils.stringify(str) + ');'
  225. , '}'
  226. ].join('\n');
  227. } else {
  228. fn = parsed.body;
  229. }
  230. return {body: 'function ' + name + '(locals) {\n' + fn + '\n}', dependencies: parsed.dependencies};
  231. };
  232. /**
  233. * Compile a JavaScript source representation of the given jade `str`.
  234. *
  235. * Options:
  236. *
  237. * - `compileDebug` When it is `true`, the source code is included in
  238. * the compiled template for better error messages.
  239. * - `filename` used to improve errors when `compileDebug` is not `true` and to resolve imports/extends
  240. * - `name` the name of the resulting function (defaults to "template")
  241. *
  242. * @param {String} str
  243. * @param {Options} options
  244. * @return {String}
  245. * @api public
  246. */
  247. exports.compileClient = function (str, options) {
  248. return exports.compileClientWithDependenciesTracked(str, options).body;
  249. };
  250. /**
  251. * Compile a `Function` representation of the given jade file.
  252. *
  253. * Options:
  254. *
  255. * - `compileDebug` when `false` debugging code is stripped from the compiled
  256. template, when it is explicitly `true`, the source code is included in
  257. the compiled template for better accuracy.
  258. *
  259. * @param {String} path
  260. * @param {Options} options
  261. * @return {Function}
  262. * @api public
  263. */
  264. exports.compileFile = function (path, options) {
  265. options = options || {};
  266. options.filename = path;
  267. return handleTemplateCache(options);
  268. };
  269. /**
  270. * Render the given `str` of jade.
  271. *
  272. * Options:
  273. *
  274. * - `cache` enable template caching
  275. * - `filename` filename required for `include` / `extends` and caching
  276. *
  277. * @param {String} str
  278. * @param {Object|Function} options or fn
  279. * @param {Function|undefined} fn
  280. * @returns {String}
  281. * @api public
  282. */
  283. exports.render = function(str, options, fn){
  284. // support callback API
  285. if ('function' == typeof options) {
  286. fn = options, options = undefined;
  287. }
  288. if (typeof fn === 'function') {
  289. var res
  290. try {
  291. res = exports.render(str, options);
  292. } catch (ex) {
  293. return fn(ex);
  294. }
  295. return fn(null, res);
  296. }
  297. options = options || {};
  298. // cache requires .filename
  299. if (options.cache && !options.filename) {
  300. throw new Error('the "filename" option is required for caching');
  301. }
  302. return handleTemplateCache(options, str)(options);
  303. };
  304. /**
  305. * Render a Jade file at the given `path`.
  306. *
  307. * @param {String} path
  308. * @param {Object|Function} options or callback
  309. * @param {Function|undefined} fn
  310. * @returns {String}
  311. * @api public
  312. */
  313. exports.renderFile = function(path, options, fn){
  314. // support callback API
  315. if ('function' == typeof options) {
  316. fn = options, options = undefined;
  317. }
  318. if (typeof fn === 'function') {
  319. var res
  320. try {
  321. res = exports.renderFile(path, options);
  322. } catch (ex) {
  323. return fn(ex);
  324. }
  325. return fn(null, res);
  326. }
  327. options = options || {};
  328. options.filename = path;
  329. return handleTemplateCache(options)(options);
  330. };
  331. /**
  332. * Compile a Jade file at the given `path` for use on the client.
  333. *
  334. * @param {String} path
  335. * @param {Object} options
  336. * @returns {String}
  337. * @api public
  338. */
  339. exports.compileFileClient = function(path, options){
  340. var key = path + ':client';
  341. options = options || {};
  342. options.filename = path;
  343. if (options.cache && exports.cache[key]) {
  344. return exports.cache[key];
  345. }
  346. var str = fs.readFileSync(options.filename, 'utf8');
  347. var out = exports.compileClient(str, options);
  348. if (options.cache) exports.cache[key] = out;
  349. return out;
  350. };
  351. /**
  352. * Express support.
  353. */
  354. exports.__express = function(path, options, fn) {
  355. if(options.compileDebug == undefined && process.env.NODE_ENV === 'production') {
  356. options.compileDebug = false;
  357. }
  358. exports.renderFile(path, options, fn);
  359. }
  360. }).call(this,require('_process'))
  361. },{"./compiler":2,"./doctypes":3,"./filters":4,"./lexer":6,"./nodes":16,"./parser":23,"./runtime":24,"./utils":25,"_process":28,"fs":26,"void-elements":34,"with":35}],2:[function(require,module,exports){
  362. 'use strict';
  363. var nodes = require('./nodes');
  364. var filters = require('./filters');
  365. var doctypes = require('./doctypes');
  366. var runtime = require('./runtime');
  367. var utils = require('./utils');
  368. var selfClosing = require('void-elements');
  369. var parseJSExpression = require('character-parser').parseMax;
  370. var constantinople = require('constantinople');
  371. function isConstant(src) {
  372. return constantinople(src, {jade: runtime, 'jade_interp': undefined});
  373. }
  374. function toConstant(src) {
  375. return constantinople.toConstant(src, {jade: runtime, 'jade_interp': undefined});
  376. }
  377. function errorAtNode(node, error) {
  378. error.line = node.line;
  379. error.filename = node.filename;
  380. return error;
  381. }
  382. /**
  383. * Initialize `Compiler` with the given `node`.
  384. *
  385. * @param {Node} node
  386. * @param {Object} options
  387. * @api public
  388. */
  389. var Compiler = module.exports = function Compiler(node, options) {
  390. this.options = options = options || {};
  391. this.node = node;
  392. this.hasCompiledDoctype = false;
  393. this.hasCompiledTag = false;
  394. this.pp = options.pretty || false;
  395. if (this.pp && typeof this.pp !== 'string') {
  396. this.pp = ' ';
  397. }
  398. this.debug = false !== options.compileDebug;
  399. this.indents = 0;
  400. this.parentIndents = 0;
  401. this.terse = false;
  402. this.mixins = {};
  403. this.dynamicMixins = false;
  404. if (options.doctype) this.setDoctype(options.doctype);
  405. };
  406. /**
  407. * Compiler prototype.
  408. */
  409. Compiler.prototype = {
  410. /**
  411. * Compile parse tree to JavaScript.
  412. *
  413. * @api public
  414. */
  415. compile: function(){
  416. this.buf = [];
  417. if (this.pp) this.buf.push("var jade_indent = [];");
  418. this.lastBufferedIdx = -1;
  419. this.visit(this.node);
  420. if (!this.dynamicMixins) {
  421. // if there are no dynamic mixins we can remove any un-used mixins
  422. var mixinNames = Object.keys(this.mixins);
  423. for (var i = 0; i < mixinNames.length; i++) {
  424. var mixin = this.mixins[mixinNames[i]];
  425. if (!mixin.used) {
  426. for (var x = 0; x < mixin.instances.length; x++) {
  427. for (var y = mixin.instances[x].start; y < mixin.instances[x].end; y++) {
  428. this.buf[y] = '';
  429. }
  430. }
  431. }
  432. }
  433. }
  434. return this.buf.join('\n');
  435. },
  436. /**
  437. * Sets the default doctype `name`. Sets terse mode to `true` when
  438. * html 5 is used, causing self-closing tags to end with ">" vs "/>",
  439. * and boolean attributes are not mirrored.
  440. *
  441. * @param {string} name
  442. * @api public
  443. */
  444. setDoctype: function(name){
  445. this.doctype = doctypes[name.toLowerCase()] || '<!DOCTYPE ' + name + '>';
  446. this.terse = this.doctype.toLowerCase() == '<!doctype html>';
  447. this.xml = 0 == this.doctype.indexOf('<?xml');
  448. },
  449. /**
  450. * Buffer the given `str` exactly as is or with interpolation
  451. *
  452. * @param {String} str
  453. * @param {Boolean} interpolate
  454. * @api public
  455. */
  456. buffer: function (str, interpolate) {
  457. var self = this;
  458. if (interpolate) {
  459. var match = /(\\)?([#!]){((?:.|\n)*)$/.exec(str);
  460. if (match) {
  461. this.buffer(str.substr(0, match.index), false);
  462. if (match[1]) { // escape
  463. this.buffer(match[2] + '{', false);
  464. this.buffer(match[3], true);
  465. return;
  466. } else {
  467. var rest = match[3];
  468. var range = parseJSExpression(rest);
  469. var code = ('!' == match[2] ? '' : 'jade.escape') + "((jade_interp = " + range.src + ") == null ? '' : jade_interp)";
  470. this.bufferExpression(code);
  471. this.buffer(rest.substr(range.end + 1), true);
  472. return;
  473. }
  474. }
  475. }
  476. str = utils.stringify(str);
  477. str = str.substr(1, str.length - 2);
  478. if (this.lastBufferedIdx == this.buf.length) {
  479. if (this.lastBufferedType === 'code') this.lastBuffered += ' + "';
  480. this.lastBufferedType = 'text';
  481. this.lastBuffered += str;
  482. this.buf[this.lastBufferedIdx - 1] = 'buf.push(' + this.bufferStartChar + this.lastBuffered + '");'
  483. } else {
  484. this.buf.push('buf.push("' + str + '");');
  485. this.lastBufferedType = 'text';
  486. this.bufferStartChar = '"';
  487. this.lastBuffered = str;
  488. this.lastBufferedIdx = this.buf.length;
  489. }
  490. },
  491. /**
  492. * Buffer the given `src` so it is evaluated at run time
  493. *
  494. * @param {String} src
  495. * @api public
  496. */
  497. bufferExpression: function (src) {
  498. if (isConstant(src)) {
  499. return this.buffer(toConstant(src) + '', false)
  500. }
  501. if (this.lastBufferedIdx == this.buf.length) {
  502. if (this.lastBufferedType === 'text') this.lastBuffered += '"';
  503. this.lastBufferedType = 'code';
  504. this.lastBuffered += ' + (' + src + ')';
  505. this.buf[this.lastBufferedIdx - 1] = 'buf.push(' + this.bufferStartChar + this.lastBuffered + ');'
  506. } else {
  507. this.buf.push('buf.push(' + src + ');');
  508. this.lastBufferedType = 'code';
  509. this.bufferStartChar = '';
  510. this.lastBuffered = '(' + src + ')';
  511. this.lastBufferedIdx = this.buf.length;
  512. }
  513. },
  514. /**
  515. * Buffer an indent based on the current `indent`
  516. * property and an additional `offset`.
  517. *
  518. * @param {Number} offset
  519. * @param {Boolean} newline
  520. * @api public
  521. */
  522. prettyIndent: function(offset, newline){
  523. offset = offset || 0;
  524. newline = newline ? '\n' : '';
  525. this.buffer(newline + Array(this.indents + offset).join(this.pp));
  526. if (this.parentIndents)
  527. this.buf.push("buf.push.apply(buf, jade_indent);");
  528. },
  529. /**
  530. * Visit `node`.
  531. *
  532. * @param {Node} node
  533. * @api public
  534. */
  535. visit: function(node){
  536. var debug = this.debug;
  537. if (debug) {
  538. this.buf.push('jade_debug.unshift(new jade.DebugItem( ' + node.line
  539. + ', ' + (node.filename
  540. ? utils.stringify(node.filename)
  541. : 'jade_debug[0].filename')
  542. + ' ));');
  543. }
  544. // Massive hack to fix our context
  545. // stack for - else[ if] etc
  546. if (false === node.debug && this.debug) {
  547. this.buf.pop();
  548. this.buf.pop();
  549. }
  550. this.visitNode(node);
  551. if (debug) this.buf.push('jade_debug.shift();');
  552. },
  553. /**
  554. * Visit `node`.
  555. *
  556. * @param {Node} node
  557. * @api public
  558. */
  559. visitNode: function(node){
  560. return this['visit' + node.type](node);
  561. },
  562. /**
  563. * Visit case `node`.
  564. *
  565. * @param {Literal} node
  566. * @api public
  567. */
  568. visitCase: function(node){
  569. var _ = this.withinCase;
  570. this.withinCase = true;
  571. this.buf.push('switch (' + node.expr + '){');
  572. this.visit(node.block);
  573. this.buf.push('}');
  574. this.withinCase = _;
  575. },
  576. /**
  577. * Visit when `node`.
  578. *
  579. * @param {Literal} node
  580. * @api public
  581. */
  582. visitWhen: function(node){
  583. if ('default' == node.expr) {
  584. this.buf.push('default:');
  585. } else {
  586. this.buf.push('case ' + node.expr + ':');
  587. }
  588. if (node.block) {
  589. this.visit(node.block);
  590. this.buf.push(' break;');
  591. }
  592. },
  593. /**
  594. * Visit literal `node`.
  595. *
  596. * @param {Literal} node
  597. * @api public
  598. */
  599. visitLiteral: function(node){
  600. this.buffer(node.str);
  601. },
  602. /**
  603. * Visit all nodes in `block`.
  604. *
  605. * @param {Block} block
  606. * @api public
  607. */
  608. visitBlock: function(block){
  609. var len = block.nodes.length
  610. , escape = this.escape
  611. , pp = this.pp
  612. // Pretty print multi-line text
  613. if (pp && len > 1 && !escape && block.nodes[0].isText && block.nodes[1].isText)
  614. this.prettyIndent(1, true);
  615. for (var i = 0; i < len; ++i) {
  616. // Pretty print text
  617. if (pp && i > 0 && !escape && block.nodes[i].isText && block.nodes[i-1].isText)
  618. this.prettyIndent(1, false);
  619. this.visit(block.nodes[i]);
  620. // Multiple text nodes are separated by newlines
  621. if (block.nodes[i+1] && block.nodes[i].isText && block.nodes[i+1].isText)
  622. this.buffer('\n');
  623. }
  624. },
  625. /**
  626. * Visit a mixin's `block` keyword.
  627. *
  628. * @param {MixinBlock} block
  629. * @api public
  630. */
  631. visitMixinBlock: function(block){
  632. if (this.pp) this.buf.push("jade_indent.push('" + Array(this.indents + 1).join(this.pp) + "');");
  633. this.buf.push('block && block();');
  634. if (this.pp) this.buf.push("jade_indent.pop();");
  635. },
  636. /**
  637. * Visit `doctype`. Sets terse mode to `true` when html 5
  638. * is used, causing self-closing tags to end with ">" vs "/>",
  639. * and boolean attributes are not mirrored.
  640. *
  641. * @param {Doctype} doctype
  642. * @api public
  643. */
  644. visitDoctype: function(doctype){
  645. if (doctype && (doctype.val || !this.doctype)) {
  646. this.setDoctype(doctype.val || 'default');
  647. }
  648. if (this.doctype) this.buffer(this.doctype);
  649. this.hasCompiledDoctype = true;
  650. },
  651. /**
  652. * Visit `mixin`, generating a function that
  653. * may be called within the template.
  654. *
  655. * @param {Mixin} mixin
  656. * @api public
  657. */
  658. visitMixin: function(mixin){
  659. var name = 'jade_mixins[';
  660. var args = mixin.args || '';
  661. var block = mixin.block;
  662. var attrs = mixin.attrs;
  663. var attrsBlocks = mixin.attributeBlocks.slice();
  664. var pp = this.pp;
  665. var dynamic = mixin.name[0]==='#';
  666. var key = mixin.name;
  667. if (dynamic) this.dynamicMixins = true;
  668. name += (dynamic ? mixin.name.substr(2,mixin.name.length-3):'"'+mixin.name+'"')+']';
  669. this.mixins[key] = this.mixins[key] || {used: false, instances: []};
  670. if (mixin.call) {
  671. this.mixins[key].used = true;
  672. if (pp) this.buf.push("jade_indent.push('" + Array(this.indents + 1).join(pp) + "');")
  673. if (block || attrs.length || attrsBlocks.length) {
  674. this.buf.push(name + '.call({');
  675. if (block) {
  676. this.buf.push('block: function(){');
  677. // Render block with no indents, dynamically added when rendered
  678. this.parentIndents++;
  679. var _indents = this.indents;
  680. this.indents = 0;
  681. this.visit(mixin.block);
  682. this.indents = _indents;
  683. this.parentIndents--;
  684. if (attrs.length || attrsBlocks.length) {
  685. this.buf.push('},');
  686. } else {
  687. this.buf.push('}');
  688. }
  689. }
  690. if (attrsBlocks.length) {
  691. if (attrs.length) {
  692. var val = this.attrs(attrs);
  693. attrsBlocks.unshift(val);
  694. }
  695. this.buf.push('attributes: jade.merge([' + attrsBlocks.join(',') + '])');
  696. } else if (attrs.length) {
  697. var val = this.attrs(attrs);
  698. this.buf.push('attributes: ' + val);
  699. }
  700. if (args) {
  701. this.buf.push('}, ' + args + ');');
  702. } else {
  703. this.buf.push('});');
  704. }
  705. } else {
  706. this.buf.push(name + '(' + args + ');');
  707. }
  708. if (pp) this.buf.push("jade_indent.pop();")
  709. } else {
  710. var mixin_start = this.buf.length;
  711. args = args ? args.split(',') : [];
  712. var rest;
  713. if (args.length && /^\.\.\./.test(args[args.length - 1].trim())) {
  714. rest = args.pop().trim().replace(/^\.\.\./, '');
  715. }
  716. // we need use jade_interp here for v8: https://code.google.com/p/v8/issues/detail?id=4165
  717. // once fixed, use this: this.buf.push(name + ' = function(' + args.join(',') + '){');
  718. this.buf.push(name + ' = jade_interp = function(' + args.join(',') + '){');
  719. this.buf.push('var block = (this && this.block), attributes = (this && this.attributes) || {};');
  720. if (rest) {
  721. this.buf.push('var ' + rest + ' = [];');
  722. this.buf.push('for (jade_interp = ' + args.length + '; jade_interp < arguments.length; jade_interp++) {');
  723. this.buf.push(' ' + rest + '.push(arguments[jade_interp]);');
  724. this.buf.push('}');
  725. }
  726. this.parentIndents++;
  727. this.visit(block);
  728. this.parentIndents--;
  729. this.buf.push('};');
  730. var mixin_end = this.buf.length;
  731. this.mixins[key].instances.push({start: mixin_start, end: mixin_end});
  732. }
  733. },
  734. /**
  735. * Visit `tag` buffering tag markup, generating
  736. * attributes, visiting the `tag`'s code and block.
  737. *
  738. * @param {Tag} tag
  739. * @api public
  740. */
  741. visitTag: function(tag){
  742. this.indents++;
  743. var name = tag.name
  744. , pp = this.pp
  745. , self = this;
  746. function bufferName() {
  747. if (tag.buffer) self.bufferExpression(name);
  748. else self.buffer(name);
  749. }
  750. if ('pre' == tag.name) this.escape = true;
  751. if (!this.hasCompiledTag) {
  752. if (!this.hasCompiledDoctype && 'html' == name) {
  753. this.visitDoctype();
  754. }
  755. this.hasCompiledTag = true;
  756. }
  757. // pretty print
  758. if (pp && !tag.isInline())
  759. this.prettyIndent(0, true);
  760. if (tag.selfClosing || (!this.xml && selfClosing[tag.name])) {
  761. this.buffer('<');
  762. bufferName();
  763. this.visitAttributes(tag.attrs, tag.attributeBlocks.slice());
  764. this.terse
  765. ? this.buffer('>')
  766. : this.buffer('/>');
  767. // if it is non-empty throw an error
  768. if (tag.block &&
  769. !(tag.block.type === 'Block' && tag.block.nodes.length === 0) &&
  770. tag.block.nodes.some(function (tag) {
  771. return tag.type !== 'Text' || !/^\s*$/.test(tag.val)
  772. })) {
  773. throw errorAtNode(tag, new Error(name + ' is self closing and should not have content.'));
  774. }
  775. } else {
  776. // Optimize attributes buffering
  777. this.buffer('<');
  778. bufferName();
  779. this.visitAttributes(tag.attrs, tag.attributeBlocks.slice());
  780. this.buffer('>');
  781. if (tag.code) this.visitCode(tag.code);
  782. this.visit(tag.block);
  783. // pretty print
  784. if (pp && !tag.isInline() && 'pre' != tag.name && !tag.canInline())
  785. this.prettyIndent(0, true);
  786. this.buffer('</');
  787. bufferName();
  788. this.buffer('>');
  789. }
  790. if ('pre' == tag.name) this.escape = false;
  791. this.indents--;
  792. },
  793. /**
  794. * Visit `filter`, throwing when the filter does not exist.
  795. *
  796. * @param {Filter} filter
  797. * @api public
  798. */
  799. visitFilter: function(filter){
  800. var text = filter.block.nodes.map(
  801. function(node){ return node.val; }
  802. ).join('\n');
  803. filter.attrs.filename = this.options.filename;
  804. try {
  805. this.buffer(filters(filter.name, text, filter.attrs), true);
  806. } catch (err) {
  807. throw errorAtNode(filter, err);
  808. }
  809. },
  810. /**
  811. * Visit `text` node.
  812. *
  813. * @param {Text} text
  814. * @api public
  815. */
  816. visitText: function(text){
  817. this.buffer(text.val, true);
  818. },
  819. /**
  820. * Visit a `comment`, only buffering when the buffer flag is set.
  821. *
  822. * @param {Comment} comment
  823. * @api public
  824. */
  825. visitComment: function(comment){
  826. if (!comment.buffer) return;
  827. if (this.pp) this.prettyIndent(1, true);
  828. this.buffer('<!--' + comment.val + '-->');
  829. },
  830. /**
  831. * Visit a `BlockComment`.
  832. *
  833. * @param {Comment} comment
  834. * @api public
  835. */
  836. visitBlockComment: function(comment){
  837. if (!comment.buffer) return;
  838. if (this.pp) this.prettyIndent(1, true);
  839. this.buffer('<!--' + comment.val);
  840. this.visit(comment.block);
  841. if (this.pp) this.prettyIndent(1, true);
  842. this.buffer('-->');
  843. },
  844. /**
  845. * Visit `code`, respecting buffer / escape flags.
  846. * If the code is followed by a block, wrap it in
  847. * a self-calling function.
  848. *
  849. * @param {Code} code
  850. * @api public
  851. */
  852. visitCode: function(code){
  853. // Wrap code blocks with {}.
  854. // we only wrap unbuffered code blocks ATM
  855. // since they are usually flow control
  856. // Buffer code
  857. if (code.buffer) {
  858. var val = code.val.trim();
  859. val = 'null == (jade_interp = '+val+') ? "" : jade_interp';
  860. if (code.escape) val = 'jade.escape(' + val + ')';
  861. this.bufferExpression(val);
  862. } else {
  863. this.buf.push(code.val);
  864. }
  865. // Block support
  866. if (code.block) {
  867. if (!code.buffer) this.buf.push('{');
  868. this.visit(code.block);
  869. if (!code.buffer) this.buf.push('}');
  870. }
  871. },
  872. /**
  873. * Visit `each` block.
  874. *
  875. * @param {Each} each
  876. * @api public
  877. */
  878. visitEach: function(each){
  879. this.buf.push(''
  880. + '// iterate ' + each.obj + '\n'
  881. + ';(function(){\n'
  882. + ' var $$obj = ' + each.obj + ';\n'
  883. + ' if (\'number\' == typeof $$obj.length) {\n');
  884. if (each.alternative) {
  885. this.buf.push(' if ($$obj.length) {');
  886. }
  887. this.buf.push(''
  888. + ' for (var ' + each.key + ' = 0, $$l = $$obj.length; ' + each.key + ' < $$l; ' + each.key + '++) {\n'
  889. + ' var ' + each.val + ' = $$obj[' + each.key + '];\n');
  890. this.visit(each.block);
  891. this.buf.push(' }\n');
  892. if (each.alternative) {
  893. this.buf.push(' } else {');
  894. this.visit(each.alternative);
  895. this.buf.push(' }');
  896. }
  897. this.buf.push(''
  898. + ' } else {\n'
  899. + ' var $$l = 0;\n'
  900. + ' for (var ' + each.key + ' in $$obj) {\n'
  901. + ' $$l++;'
  902. + ' var ' + each.val + ' = $$obj[' + each.key + '];\n');
  903. this.visit(each.block);
  904. this.buf.push(' }\n');
  905. if (each.alternative) {
  906. this.buf.push(' if ($$l === 0) {');
  907. this.visit(each.alternative);
  908. this.buf.push(' }');
  909. }
  910. this.buf.push(' }\n}).call(this);\n');
  911. },
  912. /**
  913. * Visit `attrs`.
  914. *
  915. * @param {Array} attrs
  916. * @api public
  917. */
  918. visitAttributes: function(attrs, attributeBlocks){
  919. if (attributeBlocks.length) {
  920. if (attrs.length) {
  921. var val = this.attrs(attrs);
  922. attributeBlocks.unshift(val);
  923. }
  924. this.bufferExpression('jade.attrs(jade.merge([' + attributeBlocks.join(',') + ']), ' + utils.stringify(this.terse) + ')');
  925. } else if (attrs.length) {
  926. this.attrs(attrs, true);
  927. }
  928. },
  929. /**
  930. * Compile attributes.
  931. */
  932. attrs: function(attrs, buffer){
  933. var buf = [];
  934. var classes = [];
  935. var classEscaping = [];
  936. attrs.forEach(function(attr){
  937. var key = attr.name;
  938. var escaped = attr.escaped;
  939. if (key === 'class') {
  940. classes.push(attr.val);
  941. classEscaping.push(attr.escaped);
  942. } else if (isConstant(attr.val)) {
  943. if (buffer) {
  944. this.buffer(runtime.attr(key, toConstant(attr.val), escaped, this.terse));
  945. } else {
  946. var val = toConstant(attr.val);
  947. if (key === 'style') val = runtime.style(val);
  948. if (escaped && !(key.indexOf('data') === 0 && typeof val !== 'string')) {
  949. val = runtime.escape(val);
  950. }
  951. buf.push(utils.stringify(key) + ': ' + utils.stringify(val));
  952. }
  953. } else {
  954. if (buffer) {
  955. this.bufferExpression('jade.attr("' + key + '", ' + attr.val + ', ' + utils.stringify(escaped) + ', ' + utils.stringify(this.terse) + ')');
  956. } else {
  957. var val = attr.val;
  958. if (key === 'style') {
  959. val = 'jade.style(' + val + ')';
  960. }
  961. if (escaped && !(key.indexOf('data') === 0)) {
  962. val = 'jade.escape(' + val + ')';
  963. } else if (escaped) {
  964. val = '(typeof (jade_interp = ' + val + ') == "string" ? jade.escape(jade_interp) : jade_interp)';
  965. }
  966. buf.push(utils.stringify(key) + ': ' + val);
  967. }
  968. }
  969. }.bind(this));
  970. if (buffer) {
  971. if (classes.every(isConstant)) {
  972. this.buffer(runtime.cls(classes.map(toConstant), classEscaping));
  973. } else {
  974. this.bufferExpression('jade.cls([' + classes.join(',') + '], ' + utils.stringify(classEscaping) + ')');
  975. }
  976. } else if (classes.length) {
  977. if (classes.every(isConstant)) {
  978. classes = utils.stringify(runtime.joinClasses(classes.map(toConstant).map(runtime.joinClasses).map(function (cls, i) {
  979. return classEscaping[i] ? runtime.escape(cls) : cls;
  980. })));
  981. } else {
  982. classes = '(jade_interp = ' + utils.stringify(classEscaping) + ',' +
  983. ' jade.joinClasses([' + classes.join(',') + '].map(jade.joinClasses).map(function (cls, i) {' +
  984. ' return jade_interp[i] ? jade.escape(cls) : cls' +
  985. ' }))' +
  986. ')';
  987. }
  988. if (classes.length)
  989. buf.push('"class": ' + classes);
  990. }
  991. return '{' + buf.join(',') + '}';
  992. }
  993. };
  994. },{"./doctypes":3,"./filters":4,"./nodes":16,"./runtime":24,"./utils":25,"character-parser":29,"constantinople":30,"void-elements":34}],3:[function(require,module,exports){
  995. 'use strict';
  996. module.exports = {
  997. 'default': '<!DOCTYPE html>'
  998. , 'xml': '<?xml version="1.0" encoding="utf-8" ?>'
  999. , 'transitional': '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
  1000. , 'strict': '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'
  1001. , 'frameset': '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">'
  1002. , '1.1': '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">'
  1003. , 'basic': '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.1//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic11.dtd">'
  1004. , 'mobile': '<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.2//EN" "http://www.openmobilealliance.org/tech/DTD/xhtml-mobile12.dtd">'
  1005. };
  1006. },{}],4:[function(require,module,exports){
  1007. 'use strict';
  1008. module.exports = filter;
  1009. function filter(name, str, options) {
  1010. if (typeof filter[name] === 'function') {
  1011. return filter[name](str, options);
  1012. } else {
  1013. throw new Error('unknown filter ":' + name + '"');
  1014. }
  1015. }
  1016. },{}],5:[function(require,module,exports){
  1017. 'use strict';
  1018. module.exports = [
  1019. 'a'
  1020. , 'abbr'
  1021. , 'acronym'
  1022. , 'b'
  1023. , 'br'
  1024. , 'code'
  1025. , 'em'
  1026. , 'font'
  1027. , 'i'
  1028. , 'img'
  1029. , 'ins'
  1030. , 'kbd'
  1031. , 'map'
  1032. , 'samp'
  1033. , 'small'
  1034. , 'span'
  1035. , 'strong'
  1036. , 'sub'
  1037. , 'sup'
  1038. ];
  1039. },{}],6:[function(require,module,exports){
  1040. 'use strict';
  1041. var utils = require('./utils');
  1042. var characterParser = require('character-parser');
  1043. /**
  1044. * Initialize `Lexer` with the given `str`.
  1045. *
  1046. * @param {String} str
  1047. * @param {String} filename
  1048. * @api private
  1049. */
  1050. var Lexer = module.exports = function Lexer(str, filename) {
  1051. this.input = str.replace(/\r\n|\r/g, '\n');
  1052. this.filename = filename;
  1053. this.deferredTokens = [];
  1054. this.lastIndents = 0;
  1055. this.lineno = 1;
  1056. this.stash = [];
  1057. this.indentStack = [];
  1058. this.indentRe = null;
  1059. this.pipeless = false;
  1060. };
  1061. function assertExpression(exp) {
  1062. //this verifies that a JavaScript expression is valid
  1063. Function('', 'return (' + exp + ')');
  1064. }
  1065. function assertNestingCorrect(exp) {
  1066. //this verifies that code is properly nested, but allows
  1067. //invalid JavaScript such as the contents of `attributes`
  1068. var res = characterParser(exp)
  1069. if (res.isNesting()) {
  1070. throw new Error('Nesting must match on expression `' + exp + '`')
  1071. }
  1072. }
  1073. /**
  1074. * Lexer prototype.
  1075. */
  1076. Lexer.prototype = {
  1077. /**
  1078. * Construct a token with the given `type` and `val`.
  1079. *
  1080. * @param {String} type
  1081. * @param {String} val
  1082. * @return {Object}
  1083. * @api private
  1084. */
  1085. tok: function(type, val){
  1086. return {
  1087. type: type
  1088. , line: this.lineno
  1089. , val: val
  1090. }
  1091. },
  1092. /**
  1093. * Consume the given `len` of input.
  1094. *
  1095. * @param {Number} len
  1096. * @api private
  1097. */
  1098. consume: function(len){
  1099. this.input = this.input.substr(len);
  1100. },
  1101. /**
  1102. * Scan for `type` with the given `regexp`.
  1103. *
  1104. * @param {String} type
  1105. * @param {RegExp} regexp
  1106. * @return {Object}
  1107. * @api private
  1108. */
  1109. scan: function(regexp, type){
  1110. var captures;
  1111. if (captures = regexp.exec(this.input)) {
  1112. this.consume(captures[0].length);
  1113. return this.tok(type, captures[1]);
  1114. }
  1115. },
  1116. /**
  1117. * Defer the given `tok`.
  1118. *
  1119. * @param {Object} tok
  1120. * @api private
  1121. */
  1122. defer: function(tok){
  1123. this.deferredTokens.push(tok);
  1124. },
  1125. /**
  1126. * Lookahead `n` tokens.
  1127. *
  1128. * @param {Number} n
  1129. * @return {Object}
  1130. * @api private
  1131. */
  1132. lookahead: function(n){
  1133. var fetch = n - this.stash.length;
  1134. while (fetch-- > 0) this.stash.push(this.next());
  1135. return this.stash[--n];
  1136. },
  1137. /**
  1138. * Return the indexOf `(` or `{` or `[` / `)` or `}` or `]` delimiters.
  1139. *
  1140. * @return {Number}
  1141. * @api private
  1142. */
  1143. bracketExpression: function(skip){
  1144. skip = skip || 0;
  1145. var start = this.input[skip];
  1146. if (start != '(' && start != '{' && start != '[') throw new Error('unrecognized start character');
  1147. var end = ({'(': ')', '{': '}', '[': ']'})[start];
  1148. var range = characterParser.parseMax(this.input, {start: skip + 1});
  1149. if (this.input[range.end] !== end) throw new Error('start character ' + start + ' does not match end character ' + this.input[range.end]);
  1150. return range;
  1151. },
  1152. /**
  1153. * Stashed token.
  1154. */
  1155. stashed: function() {
  1156. return this.stash.length
  1157. && this.stash.shift();
  1158. },
  1159. /**
  1160. * Deferred token.
  1161. */
  1162. deferred: function() {
  1163. return this.deferredTokens.length
  1164. && this.deferredTokens.shift();
  1165. },
  1166. /**
  1167. * end-of-source.
  1168. */
  1169. eos: function() {
  1170. if (this.input.length) return;
  1171. if (this.indentStack.length) {
  1172. this.indentStack.shift();
  1173. return this.tok('outdent');
  1174. } else {
  1175. return this.tok('eos');
  1176. }
  1177. },
  1178. /**
  1179. * Blank line.
  1180. */
  1181. blank: function() {
  1182. var captures;
  1183. if (captures = /^\n *\n/.exec(this.input)) {
  1184. this.consume(captures[0].length - 1);
  1185. ++this.lineno;
  1186. if (this.pipeless) return this.tok('text', '');
  1187. return this.next();
  1188. }
  1189. },
  1190. /**
  1191. * Comment.
  1192. */
  1193. comment: function() {
  1194. var captures;
  1195. if (captures = /^\/\/(-)?([^\n]*)/.exec(this.input)) {
  1196. this.consume(captures[0].length);
  1197. var tok = this.tok('comment', captures[2]);
  1198. tok.buffer = '-' != captures[1];
  1199. this.pipeless = true;
  1200. return tok;
  1201. }
  1202. },
  1203. /**
  1204. * Interpolated tag.
  1205. */
  1206. interpolation: function() {
  1207. if (/^#\{/.test(this.input)) {
  1208. var match = this.bracketExpression(1);
  1209. this.consume(match.end + 1);
  1210. return this.tok('interpolation', match.src);
  1211. }
  1212. },
  1213. /**
  1214. * Tag.
  1215. */
  1216. tag: function() {
  1217. var captures;
  1218. if (captures = /^(\w[-:\w]*)(\/?)/.exec(this.input)) {
  1219. this.consume(captures[0].length);
  1220. var tok, name = captures[1];
  1221. if (':' == name[name.length - 1]) {
  1222. name = name.slice(0, -1);
  1223. tok = this.tok('tag', name);
  1224. this.defer(this.tok(':'));
  1225. if (this.input[0] !== ' ') {
  1226. console.warn('Warning: space required after `:` on line ' + this.lineno +
  1227. ' of jade file "' + this.filename + '"');
  1228. }
  1229. while (' ' == this.input[0]) this.input = this.input.substr(1);
  1230. } else {
  1231. tok = this.tok('tag', name);
  1232. }
  1233. tok.selfClosing = !!captures[2];
  1234. return tok;
  1235. }
  1236. },
  1237. /**
  1238. * Filter.
  1239. */
  1240. filter: function() {
  1241. var tok = this.scan(/^:([\w\-]+)/, 'filter');
  1242. if (tok) {
  1243. this.pipeless = true;
  1244. return tok;
  1245. }
  1246. },
  1247. /**
  1248. * Doctype.
  1249. */
  1250. doctype: function() {
  1251. if (this.scan(/^!!! *([^\n]+)?/, 'doctype')) {
  1252. throw new Error('`!!!` is deprecated, you must now use `doctype`');
  1253. }
  1254. var node = this.scan(/^(?:doctype) *([^\n]+)?/, 'doctype');
  1255. if (node && node.val && node.val.trim() === '5') {
  1256. throw new Error('`doctype 5` is deprecated, you must now use `doctype html`');
  1257. }
  1258. return node;
  1259. },
  1260. /**
  1261. * Id.
  1262. */
  1263. id: function() {
  1264. return this.scan(/^#([\w-]+)/, 'id');
  1265. },
  1266. /**
  1267. * Class.
  1268. */
  1269. className: function() {
  1270. return this.scan(/^\.([\w-]+)/, 'class');
  1271. },
  1272. /**
  1273. * Text.
  1274. */
  1275. text: function() {
  1276. return this.scan(/^(?:\| ?| )([^\n]+)/, 'text') ||
  1277. this.scan(/^\|?( )/, 'text') ||
  1278. this.scan(/^(<[^\n]*)/, 'text');
  1279. },
  1280. textFail: function () {
  1281. var tok;
  1282. if (tok = this.scan(/^([^\.\n][^\n]+)/, 'text')) {
  1283. console.warn('Warning: missing space before text for line ' + this.lineno +
  1284. ' of jade file "' + this.filename + '"');
  1285. return tok;
  1286. }
  1287. },
  1288. /**
  1289. * Dot.
  1290. */
  1291. dot: function() {
  1292. var match;
  1293. if (match = this.scan(/^\./, 'dot')) {
  1294. this.pipeless = true;
  1295. return match;
  1296. }
  1297. },
  1298. /**
  1299. * Extends.
  1300. */
  1301. "extends": function() {
  1302. return this.scan(/^extends? +([^\n]+)/, 'extends');
  1303. },
  1304. /**
  1305. * Block prepend.
  1306. */
  1307. prepend: function() {
  1308. var captures;
  1309. if (captures = /^prepend +([^\n]+)/.exec(this.input)) {
  1310. this.consume(captures[0].length);
  1311. var mode = 'prepend'
  1312. , name = captures[1]
  1313. , tok = this.tok('block', name);
  1314. tok.mode = mode;
  1315. return tok;
  1316. }
  1317. },
  1318. /**
  1319. * Block append.
  1320. */
  1321. append: function() {
  1322. var captures;
  1323. if (captures = /^append +([^\n]+)/.exec(this.input)) {
  1324. this.consume(captures[0].length);
  1325. var mode = 'append'
  1326. , name = captures[1]
  1327. , tok = this.tok('block', name);
  1328. tok.mode = mode;
  1329. return tok;
  1330. }
  1331. },
  1332. /**
  1333. * Block.
  1334. */
  1335. block: function() {
  1336. var captures;
  1337. if (captures = /^block\b *(?:(prepend|append) +)?([^\n]+)/.exec(this.input)) {
  1338. this.consume(captures[0].length);
  1339. var mode = captures[1] || 'replace'
  1340. , name = captures[2]
  1341. , tok = this.tok('block', name);
  1342. tok.mode = mode;
  1343. return tok;
  1344. }
  1345. },
  1346. /**
  1347. * Mixin Block.
  1348. */
  1349. mixinBlock: function() {
  1350. var captures;
  1351. if (captures = /^block[ \t]*(\n|$)/.exec(this.input)) {
  1352. this.consume(captures[0].length - captures[1].length);
  1353. return this.tok('mixin-block');
  1354. }
  1355. },
  1356. /**
  1357. * Yield.
  1358. */
  1359. 'yield': function() {
  1360. return this.scan(/^yield */, 'yield');
  1361. },
  1362. /**
  1363. * Include.
  1364. */
  1365. include: function() {
  1366. return this.scan(/^include +([^\n]+)/, 'include');
  1367. },
  1368. /**
  1369. * Include with filter
  1370. */
  1371. includeFiltered: function() {
  1372. var captures;
  1373. if (captures = /^include:([\w\-]+)([\( ])/.exec(this.input)) {
  1374. this.consume(captures[0].length - 1);
  1375. var filter = captures[1];
  1376. var attrs = captures[2] === '(' ? this.attrs() : null;
  1377. if (!(captures[2] === ' ' || this.input[0] === ' ')) {
  1378. throw new Error('expected space after include:filter but got ' + utils.stringify(this.input[0]));
  1379. }
  1380. captures = /^ *([^\n]+)/.exec(this.input);
  1381. if (!captures || captures[1].trim() === '') {
  1382. throw new Error('missing path for include:filter');
  1383. }
  1384. this.consume(captures[0].length);
  1385. var path = captures[1];
  1386. var tok = this.tok('include', path);
  1387. tok.filter = filter;
  1388. tok.attrs = attrs;
  1389. return tok;
  1390. }
  1391. },
  1392. /**
  1393. * Case.
  1394. */
  1395. "case": function() {
  1396. return this.scan(/^case +([^\n]+)/, 'case');
  1397. },
  1398. /**
  1399. * When.
  1400. */
  1401. when: function() {
  1402. return this.scan(/^when +([^:\n]+)/, 'when');
  1403. },
  1404. /**
  1405. * Default.
  1406. */
  1407. "default": function() {
  1408. return this.scan(/^default */, 'default');
  1409. },
  1410. /**
  1411. * Call mixin.
  1412. */
  1413. call: function(){
  1414. var tok, captures;
  1415. if (captures = /^\+(\s*)(([-\w]+)|(#\{))/.exec(this.input)) {
  1416. // try to consume simple or interpolated call
  1417. if (captures[3]) {
  1418. // simple call
  1419. this.consume(captures[0].length);
  1420. tok = this.tok('call', captures[3]);
  1421. } else {
  1422. // interpolated call
  1423. var match = this.bracketExpression(2 + captures[1].length);
  1424. this.consume(match.end + 1);
  1425. assertExpression(match.src);
  1426. tok = this.tok('call', '#{'+match.src+'}');
  1427. }
  1428. // Check for args (not attributes)
  1429. if (captures = /^ *\(/.exec(this.input)) {
  1430. var range = this.bracketExpression(captures[0].length - 1);
  1431. if (!/^\s*[-\w]+ *=/.test(range.src)) { // not attributes
  1432. this.consume(range.end + 1);
  1433. tok.args = range.src;
  1434. }
  1435. if (tok.args) {
  1436. assertExpression('[' + tok.args + ']');
  1437. }
  1438. }
  1439. return tok;
  1440. }
  1441. },
  1442. /**
  1443. * Mixin.
  1444. */
  1445. mixin: function(){
  1446. var captures;
  1447. if (captures = /^mixin +([-\w]+)(?: *\((.*)\))? */.exec(this.input)) {
  1448. this.consume(captures[0].length);
  1449. var tok = this.tok('mixin', captures[1]);
  1450. tok.args = captures[2];
  1451. return tok;
  1452. }
  1453. },
  1454. /**
  1455. * Conditional.
  1456. */
  1457. conditional: function() {
  1458. var captures;
  1459. if (captures = /^(if|unless|else if|else)\b([^\n]*)/.exec(this.input)) {
  1460. this.consume(captures[0].length);
  1461. var type = captures[1]
  1462. var js = captures[2];
  1463. var isIf = false;
  1464. var isElse = false;
  1465. switch (type) {
  1466. case 'if':
  1467. assertExpression(js)
  1468. js = 'if (' + js + ')';
  1469. isIf = true;
  1470. break;
  1471. case 'unless':
  1472. assertExpression(js)
  1473. js = 'if (!(' + js + '))';
  1474. isIf = true;
  1475. break;
  1476. case 'else if':
  1477. assertExpression(js)
  1478. js = 'else if (' + js + ')';
  1479. isIf = true;
  1480. isElse = true;
  1481. break;
  1482. case 'else':
  1483. if (js && js.trim()) {
  1484. throw new Error('`else` cannot have a condition, perhaps you meant `else if`');
  1485. }
  1486. js = 'else';
  1487. isElse = true;
  1488. break;
  1489. }
  1490. var tok = this.tok('code', js);
  1491. tok.isElse = isElse;
  1492. tok.isIf = isIf;
  1493. tok.requiresBlock = true;
  1494. return tok;
  1495. }
  1496. },
  1497. /**
  1498. * While.
  1499. */
  1500. "while": function() {
  1501. var captures;
  1502. if (captures = /^while +([^\n]+)/.exec(this.input)) {
  1503. this.consume(captures[0].length);
  1504. assertExpression(captures[1])
  1505. var tok = this.tok('code', 'while (' + captures[1] + ')');
  1506. tok.requiresBlock = true;
  1507. return tok;
  1508. }
  1509. },
  1510. /**
  1511. * Each.
  1512. */
  1513. each: function() {
  1514. var captures;
  1515. if (captures = /^(?:- *)?(?:each|for) +([a-zA-Z_$][\w$]*)(?: *, *([a-zA-Z_$][\w$]*))? * in *([^\n]+)/.exec(this.input)) {
  1516. this.consume(captures[0].length);
  1517. var tok = this.tok('each', captures[1]);
  1518. tok.key = captures[2] || '$index';
  1519. assertExpression(captures[3])
  1520. tok.code = captures[3];
  1521. return tok;
  1522. }
  1523. },
  1524. /**
  1525. * Code.
  1526. */
  1527. code: function() {
  1528. var captures;
  1529. if (captures = /^(!?=|-)[ \t]*([^\n]+)/.exec(this.input)) {
  1530. this.consume(captures[0].length);
  1531. var flags = captures[1];
  1532. captures[1] = captures[2];
  1533. var tok = this.tok('code', captures[1]);
  1534. tok.escape = flags.charAt(0) === '=';
  1535. tok.buffer = flags.charAt(0) === '=' || flags.charAt(1) === '=';
  1536. if (tok.buffer) assertExpression(captures[1])
  1537. return tok;
  1538. }
  1539. },
  1540. /**
  1541. * Block code.
  1542. */
  1543. blockCode: function() {
  1544. var captures;
  1545. if (captures = /^-\n/.exec(this.input)) {
  1546. this.consume(captures[0].length - 1);
  1547. var tok = this.tok('blockCode');
  1548. this.pipeless = true;
  1549. return tok;
  1550. }
  1551. },
  1552. /**
  1553. * Attributes.
  1554. */
  1555. attrs: function() {
  1556. if ('(' == this.input.charAt(0)) {
  1557. var index = this.bracketExpression().end
  1558. , str = this.input.substr(1, index-1)
  1559. , tok = this.tok('attrs');
  1560. assertNestingCorrect(str);
  1561. var quote = '';
  1562. var interpolate = function (attr) {
  1563. return attr.replace(/(\\)?#\{(.+)/g, function(_, escape, expr){
  1564. if (escape) return _;
  1565. try {
  1566. var range = characterParser.parseMax(expr);
  1567. if (expr[range.end] !== '}') return _.substr(0, 2) + interpolate(_.substr(2));
  1568. assertExpression(range.src)
  1569. return quote + " + (" + range.src + ") + " + quote + interpolate(expr.substr(range.end + 1));
  1570. } catch (ex) {
  1571. return _.substr(0, 2) + interpolate(_.substr(2));
  1572. }
  1573. });
  1574. }
  1575. this.consume(index + 1);
  1576. tok.attrs = [];
  1577. var escapedAttr = true
  1578. var key = '';
  1579. var val = '';
  1580. var interpolatable = '';
  1581. var state = characterParser.defaultState();
  1582. var loc = 'key';
  1583. var isEndOfAttribute = function (i) {
  1584. if (key.trim() === '') return false;
  1585. if (i === str.length) return true;
  1586. if (loc === 'key') {
  1587. if (str[i] === ' ' || str[i] === '\n') {
  1588. for (var x = i; x < str.length; x++) {
  1589. if (str[x] != ' ' && str[x] != '\n') {
  1590. if (str[x] === '=' || str[x] === '!' || str[x] === ',') return false;
  1591. else return true;
  1592. }
  1593. }
  1594. }
  1595. return str[i] === ','
  1596. } else if (loc === 'value' && !state.isNesting()) {
  1597. try {
  1598. assertExpression(val);
  1599. if (str[i] === ' ' || str[i] === '\n') {
  1600. for (var x = i; x < str.length; x++) {
  1601. if (str[x] != ' ' && str[x] != '\n') {
  1602. if (characterParser.isPunctuator(str[x]) && str[x] != '"' && str[x] != "'") return false;
  1603. else return true;
  1604. }
  1605. }
  1606. }
  1607. return str[i] === ',';
  1608. } catch (ex) {
  1609. return false;
  1610. }
  1611. }
  1612. }
  1613. this.lineno += str.split("\n").length - 1;
  1614. for (var i = 0; i <= str.length; i++) {
  1615. if (isEndOfAttribute(i)) {
  1616. val = val.trim();
  1617. if (val) assertExpression(val)
  1618. key = key.trim();
  1619. key = key.replace(/^['"]|['"]$/g, '');
  1620. tok.attrs.push({
  1621. name: key,
  1622. val: '' == val ? true : val,
  1623. escaped: escapedAttr
  1624. });
  1625. key = val = '';
  1626. loc = 'key';
  1627. escapedAttr = false;
  1628. } else {
  1629. switch (loc) {
  1630. case 'key-char':
  1631. if (str[i] === quote) {
  1632. loc = 'key';
  1633. if (i + 1 < str.length && [' ', ',', '!', '=', '\n'].indexOf(str[i + 1]) === -1)
  1634. throw new Error('Unexpected character ' + str[i + 1] + ' expected ` `, `\\n`, `,`, `!` or `=`');
  1635. } else {
  1636. key += str[i];
  1637. }
  1638. break;
  1639. case 'key':
  1640. if (key === '' && (str[i] === '"' || str[i] === "'")) {
  1641. loc = 'key-char';
  1642. quote = str[i];
  1643. } else if (str[i] === '!' || str[i] === '=') {
  1644. escapedAttr = str[i] !== '!';
  1645. if (str[i] === '!') i++;
  1646. if (str[i] !== '=') throw new Error('Unexpected character ' + str[i] + ' expected `=`');
  1647. loc = 'value';
  1648. state = characterParser.defaultState();
  1649. } else {
  1650. key += str[i]
  1651. }
  1652. break;
  1653. case 'value':
  1654. state = characterParser.parseChar(str[i], state);
  1655. if (state.isString()) {
  1656. loc = 'string';
  1657. quote = str[i];
  1658. interpolatable = str[i];
  1659. } else {
  1660. val += str[i];
  1661. }
  1662. break;
  1663. case 'string':
  1664. state = characterParser.parseChar(str[i], state);
  1665. interpolatable += str[i];
  1666. if (!state.isString()) {
  1667. loc = 'value';
  1668. val += interpolate(interpolatable);
  1669. }
  1670. break;
  1671. }
  1672. }
  1673. }
  1674. if ('/' == this.input.charAt(0)) {
  1675. this.consume(1);
  1676. tok.selfClosing = true;
  1677. }
  1678. return tok;
  1679. }
  1680. },
  1681. /**
  1682. * &attributes block
  1683. */
  1684. attributesBlock: function () {
  1685. var captures;
  1686. if (/^&attributes\b/.test(this.input)) {
  1687. this.consume(11);
  1688. var args = this.bracketExpression();
  1689. this.consume(args.end + 1);
  1690. return this.tok('&attributes', args.src);
  1691. }
  1692. },
  1693. /**
  1694. * Indent | Outdent | Newline.
  1695. */
  1696. indent: function() {
  1697. var captures, re;
  1698. // established regexp
  1699. if (this.indentRe) {
  1700. captures = this.indentRe.exec(this.input);
  1701. // determine regexp
  1702. } else {
  1703. // tabs
  1704. re = /^\n(\t*) */;
  1705. captures = re.exec(this.input);
  1706. // spaces
  1707. if (captures && !captures[1].length) {
  1708. re = /^\n( *)/;
  1709. captures = re.exec(this.input);
  1710. }
  1711. // established
  1712. if (captures && captures[1].length) this.indentRe = re;
  1713. }
  1714. if (captures) {
  1715. var tok
  1716. , indents = captures[1].length;
  1717. ++this.lineno;
  1718. this.consume(indents + 1);
  1719. if (' ' == this.input[0] || '\t' == this.input[0]) {
  1720. throw new Error('Invalid indentation, you can use tabs or spaces but not both');
  1721. }
  1722. // blank line
  1723. if ('\n' == this.input[0]) {
  1724. this.pipeless = false;
  1725. return this.tok('newline');
  1726. }
  1727. // outdent
  1728. if (this.indentStack.length && indents < this.indentStack[0]) {
  1729. while (this.indentStack.length && this.indentStack[0] > indents) {
  1730. this.stash.push(this.tok('outdent'));
  1731. this.indentStack.shift();
  1732. }
  1733. tok = this.stash.pop();
  1734. // indent
  1735. } else if (indents && indents != this.indentStack[0]) {
  1736. this.indentStack.unshift(indents);
  1737. tok = this.tok('indent', indents);
  1738. // newline
  1739. } else {
  1740. tok = this.tok('newline');
  1741. }
  1742. this.pipeless = false;
  1743. return tok;
  1744. }
  1745. },
  1746. /**
  1747. * Pipe-less text consumed only when
  1748. * pipeless is true;
  1749. */
  1750. pipelessText: function() {
  1751. if (!this.pipeless) return;
  1752. var captures, re;
  1753. // established regexp
  1754. if (this.indentRe) {
  1755. captures = this.indentRe.exec(this.input);
  1756. // determine regexp
  1757. } else {
  1758. // tabs
  1759. re = /^\n(\t*) */;
  1760. captures = re.exec(this.input);
  1761. // spaces
  1762. if (captures && !captures[1].length) {
  1763. re = /^\n( *)/;
  1764. captures = re.exec(this.input);
  1765. }
  1766. // established
  1767. if (captures && captures[1].length) this.indentRe = re;
  1768. }
  1769. var indents = captures && captures[1].length;
  1770. if (indents && (this.indentStack.length === 0 || indents > this.indentStack[0])) {
  1771. var indent = captures[1];
  1772. var line;
  1773. var tokens = [];
  1774. var isMatch;
  1775. do {
  1776. // text has `\n` as a prefix
  1777. var i = this.input.substr(1).indexOf('\n');
  1778. if (-1 == i) i = this.input.length - 1;
  1779. var str = this.input.substr(1, i);
  1780. isMatch = str.substr(0, indent.length) === indent || !str.trim();
  1781. if (isMatch) {
  1782. // consume test along with `\n` prefix if match
  1783. this.consume(str.length + 1);
  1784. ++this.lineno;
  1785. tokens.push(str.substr(indent.length));
  1786. }
  1787. } while(this.input.length && isMatch);
  1788. while (this.input.length === 0 && tokens[tokens.length - 1] === '') tokens.pop();
  1789. return this.tok('pipeless-text', tokens);
  1790. }
  1791. },
  1792. /**
  1793. * ':'
  1794. */
  1795. colon: function() {
  1796. var good = /^: +/.test(this.input);
  1797. var res = this.scan(/^: */, ':');
  1798. if (res && !good) {
  1799. console.warn('Warning: space required after `:` on line ' + this.lineno +
  1800. ' of jade file "' + this.filename + '"');
  1801. }
  1802. return res;
  1803. },
  1804. fail: function () {
  1805. throw new Error('unexpected text ' + this.input.substr(0, 5));
  1806. },
  1807. /**
  1808. * Return the next token object, or those
  1809. * previously stashed by lookahead.
  1810. *
  1811. * @return {Object}
  1812. * @api private
  1813. */
  1814. advance: function(){
  1815. return this.stashed()
  1816. || this.next();
  1817. },
  1818. /**
  1819. * Return the next token object.
  1820. *
  1821. * @return {Object}
  1822. * @api private
  1823. */
  1824. next: function() {
  1825. return this.deferred()
  1826. || this.blank()
  1827. || this.eos()
  1828. || this.pipelessText()
  1829. || this.yield()
  1830. || this.doctype()
  1831. || this.interpolation()
  1832. || this["case"]()
  1833. || this.when()
  1834. || this["default"]()
  1835. || this["extends"]()
  1836. || this.append()
  1837. || this.prepend()
  1838. || this.block()
  1839. || this.mixinBlock()
  1840. || this.include()
  1841. || this.includeFiltered()
  1842. || this.mixin()
  1843. || this.call()
  1844. || this.conditional()
  1845. || this.each()
  1846. || this["while"]()
  1847. || this.tag()
  1848. || this.filter()
  1849. || this.blockCode()
  1850. || this.code()
  1851. || this.id()
  1852. || this.className()
  1853. || this.attrs()
  1854. || this.attributesBlock()
  1855. || this.indent()
  1856. || this.text()
  1857. || this.comment()
  1858. || this.colon()
  1859. || this.dot()
  1860. || this.textFail()
  1861. || this.fail();
  1862. }
  1863. };
  1864. },{"./utils":25,"character-parser":29}],7:[function(require,module,exports){
  1865. 'use strict';
  1866. var Node = require('./node');
  1867. /**
  1868. * Initialize a `Attrs` node.
  1869. *
  1870. * @api public
  1871. */
  1872. var Attrs = module.exports = function Attrs() {
  1873. this.attributeNames = [];
  1874. this.attrs = [];
  1875. this.attributeBlocks = [];
  1876. };
  1877. // Inherit from `Node`.
  1878. Attrs.prototype = Object.create(Node.prototype);
  1879. Attrs.prototype.constructor = Attrs;
  1880. Attrs.prototype.type = 'Attrs';
  1881. /**
  1882. * Set attribute `name` to `val`, keep in mind these become
  1883. * part of a raw js object literal, so to quote a value you must
  1884. * '"quote me"', otherwise or example 'user.name' is literal JavaScript.
  1885. *
  1886. * @param {String} name
  1887. * @param {String} val
  1888. * @param {Boolean} escaped
  1889. * @return {Tag} for chaining
  1890. * @api public
  1891. */
  1892. Attrs.prototype.setAttribute = function(name, val, escaped){
  1893. if (name !== 'class' && this.attributeNames.indexOf(name) !== -1) {
  1894. throw new Error('Duplicate attribute "' + name + '" is not allowed.');
  1895. }
  1896. this.attributeNames.push(name);
  1897. this.attrs.push({ name: name, val: val, escaped: escaped });
  1898. return this;
  1899. };
  1900. /**
  1901. * Remove attribute `name` when present.
  1902. *
  1903. * @param {String} name
  1904. * @api public
  1905. */
  1906. Attrs.prototype.removeAttribute = function(name){
  1907. var err = new Error('attrs.removeAttribute is deprecated and will be removed in v2.0.0');
  1908. console.warn(err.stack);
  1909. for (var i = 0, len = this.attrs.length; i < len; ++i) {
  1910. if (this.attrs[i] && this.attrs[i].name == name) {
  1911. delete this.attrs[i];
  1912. }
  1913. }
  1914. };
  1915. /**
  1916. * Get attribute value by `name`.
  1917. *
  1918. * @param {String} name
  1919. * @return {String}
  1920. * @api public
  1921. */
  1922. Attrs.prototype.getAttribute = function(name){
  1923. var err = new Error('attrs.getAttribute is deprecated and will be removed in v2.0.0');
  1924. console.warn(err.stack);
  1925. for (var i = 0, len = this.attrs.length; i < len; ++i) {
  1926. if (this.attrs[i] && this.attrs[i].name == name) {
  1927. return this.attrs[i].val;
  1928. }
  1929. }
  1930. };
  1931. Attrs.prototype.addAttributes = function (src) {
  1932. this.attributeBlocks.push(src);
  1933. };
  1934. },{"./node":20}],8:[function(require,module,exports){
  1935. 'use strict';
  1936. var Node = require('./node');
  1937. /**
  1938. * Initialize a `BlockComment` with the given `block`.
  1939. *
  1940. * @param {String} val
  1941. * @param {Block} block
  1942. * @param {Boolean} buffer
  1943. * @api public
  1944. */
  1945. var BlockComment = module.exports = function BlockComment(val, block, buffer) {
  1946. this.block = block;
  1947. this.val = val;
  1948. this.buffer = buffer;
  1949. };
  1950. // Inherit from `Node`.
  1951. BlockComment.prototype = Object.create(Node.prototype);
  1952. BlockComment.prototype.constructor = BlockComment;
  1953. BlockComment.prototype.type = 'BlockComment';
  1954. },{"./node":20}],9:[function(require,module,exports){
  1955. 'use strict';
  1956. var Node = require('./node');
  1957. /**
  1958. * Initialize a new `Block` with an optional `node`.
  1959. *
  1960. * @param {Node} node
  1961. * @api public
  1962. */
  1963. var Block = module.exports = function Block(node){
  1964. this.nodes = [];
  1965. if (node) this.push(node);
  1966. };
  1967. // Inherit from `Node`.
  1968. Block.prototype = Object.create(Node.prototype);
  1969. Block.prototype.constructor = Block;
  1970. Block.prototype.type = 'Block';
  1971. /**
  1972. * Block flag.
  1973. */
  1974. Block.prototype.isBlock = true;
  1975. /**
  1976. * Replace the nodes in `other` with the nodes
  1977. * in `this` block.
  1978. *
  1979. * @param {Block} other
  1980. * @api private
  1981. */
  1982. Block.prototype.replace = function(other){
  1983. var err = new Error('block.replace is deprecated and will be removed in v2.0.0');
  1984. console.warn(err.stack);
  1985. other.nodes = this.nodes;
  1986. };
  1987. /**
  1988. * Push the given `node`.
  1989. *
  1990. * @param {Node} node
  1991. * @return {Number}
  1992. * @api public
  1993. */
  1994. Block.prototype.push = function(node){
  1995. return this.nodes.push(node);
  1996. };
  1997. /**
  1998. * Check if this block is empty.
  1999. *
  2000. * @return {Boolean}
  2001. * @api public
  2002. */
  2003. Block.prototype.isEmpty = function(){
  2004. return 0 == this.nodes.length;
  2005. };
  2006. /**
  2007. * Unshift the given `node`.
  2008. *
  2009. * @param {Node} node
  2010. * @return {Number}
  2011. * @api public
  2012. */
  2013. Block.prototype.unshift = function(node){
  2014. return this.nodes.unshift(node);
  2015. };
  2016. /**
  2017. * Return the "last" block, or the first `yield` node.
  2018. *
  2019. * @return {Block}
  2020. * @api private
  2021. */
  2022. Block.prototype.includeBlock = function(){
  2023. var ret = this
  2024. , node;
  2025. for (var i = 0, len = this.nodes.length; i < len; ++i) {
  2026. node = this.nodes[i];
  2027. if (node.yield) return node;
  2028. else if (node.textOnly) continue;
  2029. else if (node.includeBlock) ret = node.includeBlock();
  2030. else if (node.block && !node.block.isEmpty()) ret = node.block.includeBlock();
  2031. if (ret.yield) return ret;
  2032. }
  2033. return ret;
  2034. };
  2035. /**
  2036. * Return a clone of this block.
  2037. *
  2038. * @return {Block}
  2039. * @api private
  2040. */
  2041. Block.prototype.clone = function(){
  2042. var err = new Error('block.clone is deprecated and will be removed in v2.0.0');
  2043. console.warn(err.stack);
  2044. var clone = new Block;
  2045. for (var i = 0, len = this.nodes.length; i < len; ++i) {
  2046. clone.push(this.nodes[i].clone());
  2047. }
  2048. return clone;
  2049. };
  2050. },{"./node":20}],10:[function(require,module,exports){
  2051. 'use strict';
  2052. var Node = require('./node');
  2053. /**
  2054. * Initialize a new `Case` with `expr`.
  2055. *
  2056. * @param {String} expr
  2057. * @api public
  2058. */
  2059. var Case = exports = module.exports = function Case(expr, block){
  2060. this.expr = expr;
  2061. this.block = block;
  2062. };
  2063. // Inherit from `Node`.
  2064. Case.prototype = Object.create(Node.prototype);
  2065. Case.prototype.constructor = Case;
  2066. Case.prototype.type = 'Case';
  2067. var When = exports.When = function When(expr, block){
  2068. this.expr = expr;
  2069. this.block = block;
  2070. this.debug = false;
  2071. };
  2072. // Inherit from `Node`.
  2073. When.prototype = Object.create(Node.prototype);
  2074. When.prototype.constructor = When;
  2075. When.prototype.type = 'When';
  2076. },{"./node":20}],11:[function(require,module,exports){
  2077. 'use strict';
  2078. var Node = require('./node');
  2079. /**
  2080. * Initialize a `Code` node with the given code `val`.
  2081. * Code may also be optionally buffered and escaped.
  2082. *
  2083. * @param {String} val
  2084. * @param {Boolean} buffer
  2085. * @param {Boolean} escape
  2086. * @api public
  2087. */
  2088. var Code = module.exports = function Code(val, buffer, escape) {
  2089. this.val = val;
  2090. this.buffer = buffer;
  2091. this.escape = escape;
  2092. if (val.match(/^ *else/)) this.debug = false;
  2093. };
  2094. // Inherit from `Node`.
  2095. Code.prototype = Object.create(Node.prototype);
  2096. Code.prototype.constructor = Code;
  2097. Code.prototype.type = 'Code'; // prevent the minifiers removing this
  2098. },{"./node":20}],12:[function(require,module,exports){
  2099. 'use strict';
  2100. var Node = require('./node');
  2101. /**
  2102. * Initialize a `Comment` with the given `val`, optionally `buffer`,
  2103. * otherwise the comment may render in the output.
  2104. *
  2105. * @param {String} val
  2106. * @param {Boolean} buffer
  2107. * @api public
  2108. */
  2109. var Comment = module.exports = function Comment(val, buffer) {
  2110. this.val = val;
  2111. this.buffer = buffer;
  2112. };
  2113. // Inherit from `Node`.
  2114. Comment.prototype = Object.create(Node.prototype);
  2115. Comment.prototype.constructor = Comment;
  2116. Comment.prototype.type = 'Comment';
  2117. },{"./node":20}],13:[function(require,module,exports){
  2118. 'use strict';
  2119. var Node = require('./node');
  2120. /**
  2121. * Initialize a `Doctype` with the given `val`.
  2122. *
  2123. * @param {String} val
  2124. * @api public
  2125. */
  2126. var Doctype = module.exports = function Doctype(val) {
  2127. this.val = val;
  2128. };
  2129. // Inherit from `Node`.
  2130. Doctype.prototype = Object.create(Node.prototype);
  2131. Doctype.prototype.constructor = Doctype;
  2132. Doctype.prototype.type = 'Doctype';
  2133. },{"./node":20}],14:[function(require,module,exports){
  2134. 'use strict';
  2135. var Node = require('./node');
  2136. /**
  2137. * Initialize an `Each` node, representing iteration
  2138. *
  2139. * @param {String} obj
  2140. * @param {String} val
  2141. * @param {String} key
  2142. * @param {Block} block
  2143. * @api public
  2144. */
  2145. var Each = module.exports = function Each(obj, val, key, block) {
  2146. this.obj = obj;
  2147. this.val = val;
  2148. this.key = key;
  2149. this.block = block;
  2150. };
  2151. // Inherit from `Node`.
  2152. Each.prototype = Object.create(Node.prototype);
  2153. Each.prototype.constructor = Each;
  2154. Each.prototype.type = 'Each';
  2155. },{"./node":20}],15:[function(require,module,exports){
  2156. 'use strict';
  2157. var Node = require('./node');
  2158. /**
  2159. * Initialize a `Filter` node with the given
  2160. * filter `name` and `block`.
  2161. *
  2162. * @param {String} name
  2163. * @param {Block|Node} block
  2164. * @api public
  2165. */
  2166. var Filter = module.exports = function Filter(name, block, attrs) {
  2167. this.name = name;
  2168. this.block = block;
  2169. this.attrs = attrs;
  2170. };
  2171. // Inherit from `Node`.
  2172. Filter.prototype = Object.create(Node.prototype);
  2173. Filter.prototype.constructor = Filter;
  2174. Filter.prototype.type = 'Filter';
  2175. },{"./node":20}],16:[function(require,module,exports){
  2176. 'use strict';
  2177. exports.Node = require('./node');
  2178. exports.Tag = require('./tag');
  2179. exports.Code = require('./code');
  2180. exports.Each = require('./each');
  2181. exports.Case = require('./case');
  2182. exports.Text = require('./text');
  2183. exports.Block = require('./block');
  2184. exports.MixinBlock = require('./mixin-block');
  2185. exports.Mixin = require('./mixin');
  2186. exports.Filter = require('./filter');
  2187. exports.Comment = require('./comment');
  2188. exports.Literal = require('./literal');
  2189. exports.BlockComment = require('./block-comment');
  2190. exports.Doctype = require('./doctype');
  2191. },{"./block":9,"./block-comment":8,"./case":10,"./code":11,"./comment":12,"./doctype":13,"./each":14,"./filter":15,"./literal":17,"./mixin":19,"./mixin-block":18,"./node":20,"./tag":21,"./text":22}],17:[function(require,module,exports){
  2192. 'use strict';
  2193. var Node = require('./node');
  2194. /**
  2195. * Initialize a `Literal` node with the given `str.
  2196. *
  2197. * @param {String} str
  2198. * @api public
  2199. */
  2200. var Literal = module.exports = function Literal(str) {
  2201. this.str = str;
  2202. };
  2203. // Inherit from `Node`.
  2204. Literal.prototype = Object.create(Node.prototype);
  2205. Literal.prototype.constructor = Literal;
  2206. Literal.prototype.type = 'Literal';
  2207. },{"./node":20}],18:[function(require,module,exports){
  2208. 'use strict';
  2209. var Node = require('./node');
  2210. /**
  2211. * Initialize a new `Block` with an optional `node`.
  2212. *
  2213. * @param {Node} node
  2214. * @api public
  2215. */
  2216. var MixinBlock = module.exports = function MixinBlock(){};
  2217. // Inherit from `Node`.
  2218. MixinBlock.prototype = Object.create(Node.prototype);
  2219. MixinBlock.prototype.constructor = MixinBlock;
  2220. MixinBlock.prototype.type = 'MixinBlock';
  2221. },{"./node":20}],19:[function(require,module,exports){
  2222. 'use strict';
  2223. var Attrs = require('./attrs');
  2224. /**
  2225. * Initialize a new `Mixin` with `name` and `block`.
  2226. *
  2227. * @param {String} name
  2228. * @param {String} args
  2229. * @param {Block} block
  2230. * @api public
  2231. */
  2232. var Mixin = module.exports = function Mixin(name, args, block, call){
  2233. Attrs.call(this);
  2234. this.name = name;
  2235. this.args = args;
  2236. this.block = block;
  2237. this.call = call;
  2238. };
  2239. // Inherit from `Attrs`.
  2240. Mixin.prototype = Object.create(Attrs.prototype);
  2241. Mixin.prototype.constructor = Mixin;
  2242. Mixin.prototype.type = 'Mixin';
  2243. },{"./attrs":7}],20:[function(require,module,exports){
  2244. 'use strict';
  2245. var Node = module.exports = function Node(){};
  2246. /**
  2247. * Clone this node (return itself)
  2248. *
  2249. * @return {Node}
  2250. * @api private
  2251. */
  2252. Node.prototype.clone = function(){
  2253. var err = new Error('node.clone is deprecated and will be removed in v2.0.0');
  2254. console.warn(err.stack);
  2255. return this;
  2256. };
  2257. Node.prototype.type = '';
  2258. },{}],21:[function(require,module,exports){
  2259. 'use strict';
  2260. var Attrs = require('./attrs');
  2261. var Block = require('./block');
  2262. var inlineTags = require('../inline-tags');
  2263. /**
  2264. * Initialize a `Tag` node with the given tag `name` and optional `block`.
  2265. *
  2266. * @param {String} name
  2267. * @param {Block} block
  2268. * @api public
  2269. */
  2270. var Tag = module.exports = function Tag(name, block) {
  2271. Attrs.call(this);
  2272. this.name = name;
  2273. this.block = block || new Block;
  2274. };
  2275. // Inherit from `Attrs`.
  2276. Tag.prototype = Object.create(Attrs.prototype);
  2277. Tag.prototype.constructor = Tag;
  2278. Tag.prototype.type = 'Tag';
  2279. /**
  2280. * Clone this tag.
  2281. *
  2282. * @return {Tag}
  2283. * @api private
  2284. */
  2285. Tag.prototype.clone = function(){
  2286. var err = new Error('tag.clone is deprecated and will be removed in v2.0.0');
  2287. console.warn(err.stack);
  2288. var clone = new Tag(this.name, this.block.clone());
  2289. clone.line = this.line;
  2290. clone.attrs = this.attrs;
  2291. clone.textOnly = this.textOnly;
  2292. return clone;
  2293. };
  2294. /**
  2295. * Check if this tag is an inline tag.
  2296. *
  2297. * @return {Boolean}
  2298. * @api private
  2299. */
  2300. Tag.prototype.isInline = function(){
  2301. return ~inlineTags.indexOf(this.name);
  2302. };
  2303. /**
  2304. * Check if this tag's contents can be inlined. Used for pretty printing.
  2305. *
  2306. * @return {Boolean}
  2307. * @api private
  2308. */
  2309. Tag.prototype.canInline = function(){
  2310. var nodes = this.block.nodes;
  2311. function isInline(node){
  2312. // Recurse if the node is a block
  2313. if (node.isBlock) return node.nodes.every(isInline);
  2314. return node.isText || (node.isInline && node.isInline());
  2315. }
  2316. // Empty tag
  2317. if (!nodes.length) return true;
  2318. // Text-only or inline-only tag
  2319. if (1 == nodes.length) return isInline(nodes[0]);
  2320. // Multi-line inline-only tag
  2321. if (this.block.nodes.every(isInline)) {
  2322. for (var i = 1, len = nodes.length; i < len; ++i) {
  2323. if (nodes[i-1].isText && nodes[i].isText)
  2324. return false;
  2325. }
  2326. return true;
  2327. }
  2328. // Mixed tag
  2329. return false;
  2330. };
  2331. },{"../inline-tags":5,"./attrs":7,"./block":9}],22:[function(require,module,exports){
  2332. 'use strict';
  2333. var Node = require('./node');
  2334. /**
  2335. * Initialize a `Text` node with optional `line`.
  2336. *
  2337. * @param {String} line
  2338. * @api public
  2339. */
  2340. var Text = module.exports = function Text(line) {
  2341. this.val = line;
  2342. };
  2343. // Inherit from `Node`.
  2344. Text.prototype = Object.create(Node.prototype);
  2345. Text.prototype.constructor = Text;
  2346. Text.prototype.type = 'Text';
  2347. /**
  2348. * Flag as text.
  2349. */
  2350. Text.prototype.isText = true;
  2351. },{"./node":20}],23:[function(require,module,exports){
  2352. 'use strict';
  2353. var Lexer = require('./lexer');
  2354. var nodes = require('./nodes');
  2355. var utils = require('./utils');
  2356. var filters = require('./filters');
  2357. var path = require('path');
  2358. var constantinople = require('constantinople');
  2359. var parseJSExpression = require('character-parser').parseMax;
  2360. var extname = path.extname;
  2361. /**
  2362. * Initialize `Parser` with the given input `str` and `filename`.
  2363. *
  2364. * @param {String} str
  2365. * @param {String} filename
  2366. * @param {Object} options
  2367. * @api public
  2368. */
  2369. var Parser = exports = module.exports = function Parser(str, filename, options){
  2370. //Strip any UTF-8 BOM off of the start of `str`, if it exists.
  2371. this.input = str.replace(/^\uFEFF/, '');
  2372. this.lexer = new Lexer(this.input, filename);
  2373. this.filename = filename;
  2374. this.blocks = {};
  2375. this.mixins = {};
  2376. this.options = options;
  2377. this.contexts = [this];
  2378. this.inMixin = 0;
  2379. this.dependencies = [];
  2380. this.inBlock = 0;
  2381. };
  2382. /**
  2383. * Parser prototype.
  2384. */
  2385. Parser.prototype = {
  2386. /**
  2387. * Save original constructor
  2388. */
  2389. constructor: Parser,
  2390. /**
  2391. * Push `parser` onto the context stack,
  2392. * or pop and return a `Parser`.
  2393. */
  2394. context: function(parser){
  2395. if (parser) {
  2396. this.contexts.push(parser);
  2397. } else {
  2398. return this.contexts.pop();
  2399. }
  2400. },
  2401. /**
  2402. * Return the next token object.
  2403. *
  2404. * @return {Object}
  2405. * @api private
  2406. */
  2407. advance: function(){
  2408. return this.lexer.advance();
  2409. },
  2410. /**
  2411. * Single token lookahead.
  2412. *
  2413. * @return {Object}
  2414. * @api private
  2415. */
  2416. peek: function() {
  2417. return this.lookahead(1);
  2418. },
  2419. /**
  2420. * Return lexer lineno.
  2421. *
  2422. * @return {Number}
  2423. * @api private
  2424. */
  2425. line: function() {
  2426. return this.lexer.lineno;
  2427. },
  2428. /**
  2429. * `n` token lookahead.
  2430. *
  2431. * @param {Number} n
  2432. * @return {Object}
  2433. * @api private
  2434. */
  2435. lookahead: function(n){
  2436. return this.lexer.lookahead(n);
  2437. },
  2438. /**
  2439. * Parse input returning a string of js for evaluation.
  2440. *
  2441. * @return {String}
  2442. * @api public
  2443. */
  2444. parse: function(){
  2445. var block = new nodes.Block, parser;
  2446. block.line = 0;
  2447. block.filename = this.filename;
  2448. while ('eos' != this.peek().type) {
  2449. if ('newline' == this.peek().type) {
  2450. this.advance();
  2451. } else {
  2452. var next = this.peek();
  2453. var expr = this.parseExpr();
  2454. expr.filename = expr.filename || this.filename;
  2455. expr.line = next.line;
  2456. block.push(expr);
  2457. }
  2458. }
  2459. if (parser = this.extending) {
  2460. this.context(parser);
  2461. var ast = parser.parse();
  2462. this.context();
  2463. // hoist mixins
  2464. for (var name in this.mixins)
  2465. ast.unshift(this.mixins[name]);
  2466. return ast;
  2467. }
  2468. if (!this.extending && !this.included && Object.keys(this.blocks).length){
  2469. var blocks = [];
  2470. utils.walkAST(block, function (node) {
  2471. if (node.type === 'Block' && node.name) {
  2472. blocks.push(node.name);
  2473. }
  2474. });
  2475. Object.keys(this.blocks).forEach(function (name) {
  2476. if (blocks.indexOf(name) === -1 && !this.blocks[name].isSubBlock) {
  2477. console.warn('Warning: Unexpected block "'
  2478. + name
  2479. + '" '
  2480. + ' on line '
  2481. + this.blocks[name].line
  2482. + ' of '
  2483. + (this.blocks[name].filename)
  2484. + '. This block is never used. This warning will be an error in v2.0.0');
  2485. }
  2486. }.bind(this));
  2487. }
  2488. return block;
  2489. },
  2490. /**
  2491. * Expect the given type, or throw an exception.
  2492. *
  2493. * @param {String} type
  2494. * @api private
  2495. */
  2496. expect: function(type){
  2497. if (this.peek().type === type) {
  2498. return this.advance();
  2499. } else {
  2500. throw new Error('expected "' + type + '", but got "' + this.peek().type + '"');
  2501. }
  2502. },
  2503. /**
  2504. * Accept the given `type`.
  2505. *
  2506. * @param {String} type
  2507. * @api private
  2508. */
  2509. accept: function(type){
  2510. if (this.peek().type === type) {
  2511. return this.advance();
  2512. }
  2513. },
  2514. /**
  2515. * tag
  2516. * | doctype
  2517. * | mixin
  2518. * | include
  2519. * | filter
  2520. * | comment
  2521. * | text
  2522. * | each
  2523. * | code
  2524. * | yield
  2525. * | id
  2526. * | class
  2527. * | interpolation
  2528. */
  2529. parseExpr: function(){
  2530. switch (this.peek().type) {
  2531. case 'tag':
  2532. return this.parseTag();
  2533. case 'mixin':
  2534. return this.parseMixin();
  2535. case 'block':
  2536. return this.parseBlock();
  2537. case 'mixin-block':
  2538. return this.parseMixinBlock();
  2539. case 'case':
  2540. return this.parseCase();
  2541. case 'extends':
  2542. return this.parseExtends();
  2543. case 'include':
  2544. return this.parseInclude();
  2545. case 'doctype':
  2546. return this.parseDoctype();
  2547. case 'filter':
  2548. return this.parseFilter();
  2549. case 'comment':
  2550. return this.parseComment();
  2551. case 'text':
  2552. return this.parseText();
  2553. case 'each':
  2554. return this.parseEach();
  2555. case 'code':
  2556. return this.parseCode();
  2557. case 'blockCode':
  2558. return this.parseBlockCode();
  2559. case 'call':
  2560. return this.parseCall();
  2561. case 'interpolation':
  2562. return this.parseInterpolation();
  2563. case 'yield':
  2564. this.advance();
  2565. var block = new nodes.Block;
  2566. block.yield = true;
  2567. return block;
  2568. case 'id':
  2569. case 'class':
  2570. var tok = this.advance();
  2571. this.lexer.defer(this.lexer.tok('tag', 'div'));
  2572. this.lexer.defer(tok);
  2573. return this.parseExpr();
  2574. default:
  2575. throw new Error('unexpected token "' + this.peek().type + '"');
  2576. }
  2577. },
  2578. /**
  2579. * Text
  2580. */
  2581. parseText: function(){
  2582. var tok = this.expect('text');
  2583. var tokens = this.parseInlineTagsInText(tok.val);
  2584. if (tokens.length === 1) return tokens[0];
  2585. var node = new nodes.Block;
  2586. for (var i = 0; i < tokens.length; i++) {
  2587. node.push(tokens[i]);
  2588. };
  2589. return node;
  2590. },
  2591. /**
  2592. * ':' expr
  2593. * | block
  2594. */
  2595. parseBlockExpansion: function(){
  2596. if (':' == this.peek().type) {
  2597. this.advance();
  2598. return new nodes.Block(this.parseExpr());
  2599. } else {
  2600. return this.block();
  2601. }
  2602. },
  2603. /**
  2604. * case
  2605. */
  2606. parseCase: function(){
  2607. var val = this.expect('case').val;
  2608. var node = new nodes.Case(val);
  2609. node.line = this.line();
  2610. var block = new nodes.Block;
  2611. block.line = this.line();
  2612. block.filename = this.filename;
  2613. this.expect('indent');
  2614. while ('outdent' != this.peek().type) {
  2615. switch (this.peek().type) {
  2616. case 'comment':
  2617. case 'newline':
  2618. this.advance();
  2619. break;
  2620. case 'when':
  2621. block.push(this.parseWhen());
  2622. break;
  2623. case 'default':
  2624. block.push(this.parseDefault());
  2625. break;
  2626. default:
  2627. throw new Error('Unexpected token "' + this.peek().type
  2628. + '", expected "when", "default" or "newline"');
  2629. }
  2630. }
  2631. this.expect('outdent');
  2632. node.block = block;
  2633. return node;
  2634. },
  2635. /**
  2636. * when
  2637. */
  2638. parseWhen: function(){
  2639. var val = this.expect('when').val;
  2640. if (this.peek().type !== 'newline')
  2641. return new nodes.Case.When(val, this.parseBlockExpansion());
  2642. else
  2643. return new nodes.Case.When(val);
  2644. },
  2645. /**
  2646. * default
  2647. */
  2648. parseDefault: function(){
  2649. this.expect('default');
  2650. return new nodes.Case.When('default', this.parseBlockExpansion());
  2651. },
  2652. /**
  2653. * code
  2654. */
  2655. parseCode: function(afterIf){
  2656. var tok = this.expect('code');
  2657. var node = new nodes.Code(tok.val, tok.buffer, tok.escape);
  2658. var block;
  2659. node.line = this.line();
  2660. // throw an error if an else does not have an if
  2661. if (tok.isElse && !tok.hasIf) {
  2662. throw new Error('Unexpected else without if');
  2663. }
  2664. // handle block
  2665. block = 'indent' == this.peek().type;
  2666. if (block) {
  2667. node.block = this.block();
  2668. }
  2669. // handle missing block
  2670. if (tok.requiresBlock && !block) {
  2671. node.block = new nodes.Block();
  2672. }
  2673. // mark presense of if for future elses
  2674. if (tok.isIf && this.peek().isElse) {
  2675. this.peek().hasIf = true;
  2676. } else if (tok.isIf && this.peek().type === 'newline' && this.lookahead(2).isElse) {
  2677. this.lookahead(2).hasIf = true;
  2678. }
  2679. return node;
  2680. },
  2681. /**
  2682. * block code
  2683. */
  2684. parseBlockCode: function(){
  2685. var tok = this.expect('blockCode');
  2686. var node;
  2687. var body = this.peek();
  2688. var text;
  2689. if (body.type === 'pipeless-text') {
  2690. this.advance();
  2691. text = body.val.join('\n');
  2692. } else {
  2693. text = '';
  2694. }
  2695. node = new nodes.Code(text, false, false);
  2696. return node;
  2697. },
  2698. /**
  2699. * comment
  2700. */
  2701. parseComment: function(){
  2702. var tok = this.expect('comment');
  2703. var node;
  2704. var block;
  2705. if (block = this.parseTextBlock()) {
  2706. node = new nodes.BlockComment(tok.val, block, tok.buffer);
  2707. } else {
  2708. node = new nodes.Comment(tok.val, tok.buffer);
  2709. }
  2710. node.line = this.line();
  2711. return node;
  2712. },
  2713. /**
  2714. * doctype
  2715. */
  2716. parseDoctype: function(){
  2717. var tok = this.expect('doctype');
  2718. var node = new nodes.Doctype(tok.val);
  2719. node.line = this.line();
  2720. return node;
  2721. },
  2722. /**
  2723. * filter attrs? text-block
  2724. */
  2725. parseFilter: function(){
  2726. var tok = this.expect('filter');
  2727. var attrs = this.accept('attrs');
  2728. var block;
  2729. block = this.parseTextBlock() || new nodes.Block();
  2730. var options = {};
  2731. if (attrs) {
  2732. attrs.attrs.forEach(function (attribute) {
  2733. options[attribute.name] = constantinople.toConstant(attribute.val);
  2734. });
  2735. }
  2736. var node = new nodes.Filter(tok.val, block, options);
  2737. node.line = this.line();
  2738. return node;
  2739. },
  2740. /**
  2741. * each block
  2742. */
  2743. parseEach: function(){
  2744. var tok = this.expect('each');
  2745. var node = new nodes.Each(tok.code, tok.val, tok.key);
  2746. node.line = this.line();
  2747. node.block = this.block();
  2748. if (this.peek().type == 'code' && this.peek().val == 'else') {
  2749. this.advance();
  2750. node.alternative = this.block();
  2751. }
  2752. return node;
  2753. },
  2754. /**
  2755. * Resolves a path relative to the template for use in
  2756. * includes and extends
  2757. *
  2758. * @param {String} path
  2759. * @param {String} purpose Used in error messages.
  2760. * @return {String}
  2761. * @api private
  2762. */
  2763. resolvePath: function (path, purpose) {
  2764. var p = require('path');
  2765. var dirname = p.dirname;
  2766. var basename = p.basename;
  2767. var join = p.join;
  2768. if (path[0] !== '/' && !this.filename)
  2769. throw new Error('the "filename" option is required to use "' + purpose + '" with "relative" paths');
  2770. if (path[0] === '/' && !this.options.basedir)
  2771. throw new Error('the "basedir" option is required to use "' + purpose + '" with "absolute" paths');
  2772. path = join(path[0] === '/' ? this.options.basedir : dirname(this.filename), path);
  2773. if (basename(path).indexOf('.') === -1) path += '.jade';
  2774. return path;
  2775. },
  2776. /**
  2777. * 'extends' name
  2778. */
  2779. parseExtends: function(){
  2780. var fs = require('fs');
  2781. var path = this.resolvePath(this.expect('extends').val.trim(), 'extends');
  2782. if ('.jade' != path.substr(-5)) path += '.jade';
  2783. this.dependencies.push(path);
  2784. var str = fs.readFileSync(path, 'utf8');
  2785. var parser = new this.constructor(str, path, this.options);
  2786. parser.dependencies = this.dependencies;
  2787. parser.blocks = this.blocks;
  2788. parser.included = this.included;
  2789. parser.contexts = this.contexts;
  2790. this.extending = parser;
  2791. // TODO: null node
  2792. return new nodes.Literal('');
  2793. },
  2794. /**
  2795. * 'block' name block
  2796. */
  2797. parseBlock: function(){
  2798. var block = this.expect('block');
  2799. var mode = block.mode;
  2800. var name = block.val.trim();
  2801. var line = block.line;
  2802. this.inBlock++;
  2803. block = 'indent' == this.peek().type
  2804. ? this.block()
  2805. : new nodes.Block(new nodes.Literal(''));
  2806. this.inBlock--;
  2807. block.name = name;
  2808. block.line = line;
  2809. var prev = this.blocks[name] || {prepended: [], appended: []}
  2810. if (prev.mode === 'replace') return this.blocks[name] = prev;
  2811. var allNodes = prev.prepended.concat(block.nodes).concat(prev.appended);
  2812. switch (mode) {
  2813. case 'append':
  2814. prev.appended = prev.parser === this ?
  2815. prev.appended.concat(block.nodes) :
  2816. block.nodes.concat(prev.appended);
  2817. break;
  2818. case 'prepend':
  2819. prev.prepended = prev.parser === this ?
  2820. block.nodes.concat(prev.prepended) :
  2821. prev.prepended.concat(block.nodes);
  2822. break;
  2823. }
  2824. block.nodes = allNodes;
  2825. block.appended = prev.appended;
  2826. block.prepended = prev.prepended;
  2827. block.mode = mode;
  2828. block.parser = this;
  2829. block.isSubBlock = this.inBlock > 0;
  2830. return this.blocks[name] = block;
  2831. },
  2832. parseMixinBlock: function () {
  2833. var block = this.expect('mixin-block');
  2834. if (!this.inMixin) {
  2835. throw new Error('Anonymous blocks are not allowed unless they are part of a mixin.');
  2836. }
  2837. return new nodes.MixinBlock();
  2838. },
  2839. /**
  2840. * include block?
  2841. */
  2842. parseInclude: function(){
  2843. var fs = require('fs');
  2844. var tok = this.expect('include');
  2845. var path = this.resolvePath(tok.val.trim(), 'include');
  2846. this.dependencies.push(path);
  2847. // has-filter
  2848. if (tok.filter) {
  2849. var str = fs.readFileSync(path, 'utf8').replace(/\r/g, '');
  2850. var options = {filename: path};
  2851. if (tok.attrs) {
  2852. tok.attrs.attrs.forEach(function (attribute) {
  2853. options[attribute.name] = constantinople.toConstant(attribute.val);
  2854. });
  2855. }
  2856. str = filters(tok.filter, str, options);
  2857. return new nodes.Literal(str);
  2858. }
  2859. // non-jade
  2860. if ('.jade' != path.substr(-5)) {
  2861. var str = fs.readFileSync(path, 'utf8').replace(/\r/g, '');
  2862. return new nodes.Literal(str);
  2863. }
  2864. var str = fs.readFileSync(path, 'utf8');
  2865. var parser = new this.constructor(str, path, this.options);
  2866. parser.dependencies = this.dependencies;
  2867. parser.blocks = utils.merge({}, this.blocks);
  2868. parser.included = true;
  2869. parser.mixins = this.mixins;
  2870. this.context(parser);
  2871. var ast = parser.parse();
  2872. this.context();
  2873. ast.filename = path;
  2874. if ('indent' == this.peek().type) {
  2875. ast.includeBlock().push(this.block());
  2876. }
  2877. return ast;
  2878. },
  2879. /**
  2880. * call ident block
  2881. */
  2882. parseCall: function(){
  2883. var tok = this.expect('call');
  2884. var name = tok.val;
  2885. var args = tok.args;
  2886. var mixin = new nodes.Mixin(name, args, new nodes.Block, true);
  2887. this.tag(mixin);
  2888. if (mixin.code) {
  2889. mixin.block.push(mixin.code);
  2890. mixin.code = null;
  2891. }
  2892. if (mixin.block.isEmpty()) mixin.block = null;
  2893. return mixin;
  2894. },
  2895. /**
  2896. * mixin block
  2897. */
  2898. parseMixin: function(){
  2899. var tok = this.expect('mixin');
  2900. var name = tok.val;
  2901. var args = tok.args;
  2902. var mixin;
  2903. // definition
  2904. if ('indent' == this.peek().type) {
  2905. this.inMixin++;
  2906. mixin = new nodes.Mixin(name, args, this.block(), false);
  2907. this.mixins[name] = mixin;
  2908. this.inMixin--;
  2909. return mixin;
  2910. // call
  2911. } else {
  2912. return new nodes.Mixin(name, args, null, true);
  2913. }
  2914. },
  2915. parseInlineTagsInText: function (str) {
  2916. var line = this.line();
  2917. var match = /(\\)?#\[((?:.|\n)*)$/.exec(str);
  2918. if (match) {
  2919. if (match[1]) { // escape
  2920. var text = new nodes.Text(str.substr(0, match.index) + '#[');
  2921. text.line = line;
  2922. var rest = this.parseInlineTagsInText(match[2]);
  2923. if (rest[0].type === 'Text') {
  2924. text.val += rest[0].val;
  2925. rest.shift();
  2926. }
  2927. return [text].concat(rest);
  2928. } else {
  2929. var text = new nodes.Text(str.substr(0, match.index));
  2930. text.line = line;
  2931. var buffer = [text];
  2932. var rest = match[2];
  2933. var range = parseJSExpression(rest);
  2934. var inner = new Parser(range.src, this.filename, this.options);
  2935. buffer.push(inner.parse());
  2936. return buffer.concat(this.parseInlineTagsInText(rest.substr(range.end + 1)));
  2937. }
  2938. } else {
  2939. var text = new nodes.Text(str);
  2940. text.line = line;
  2941. return [text];
  2942. }
  2943. },
  2944. /**
  2945. * indent (text | newline)* outdent
  2946. */
  2947. parseTextBlock: function(){
  2948. var block = new nodes.Block;
  2949. block.line = this.line();
  2950. var body = this.peek();
  2951. if (body.type !== 'pipeless-text') return;
  2952. this.advance();
  2953. block.nodes = body.val.reduce(function (accumulator, text) {
  2954. return accumulator.concat(this.parseInlineTagsInText(text));
  2955. }.bind(this), []);
  2956. return block;
  2957. },
  2958. /**
  2959. * indent expr* outdent
  2960. */
  2961. block: function(){
  2962. var block = new nodes.Block;
  2963. block.line = this.line();
  2964. block.filename = this.filename;
  2965. this.expect('indent');
  2966. while ('outdent' != this.peek().type) {
  2967. if ('newline' == this.peek().type) {
  2968. this.advance();
  2969. } else {
  2970. var expr = this.parseExpr();
  2971. expr.filename = this.filename;
  2972. block.push(expr);
  2973. }
  2974. }
  2975. this.expect('outdent');
  2976. return block;
  2977. },
  2978. /**
  2979. * interpolation (attrs | class | id)* (text | code | ':')? newline* block?
  2980. */
  2981. parseInterpolation: function(){
  2982. var tok = this.advance();
  2983. var tag = new nodes.Tag(tok.val);
  2984. tag.buffer = true;
  2985. return this.tag(tag);
  2986. },
  2987. /**
  2988. * tag (attrs | class | id)* (text | code | ':')? newline* block?
  2989. */
  2990. parseTag: function(){
  2991. var tok = this.advance();
  2992. var tag = new nodes.Tag(tok.val);
  2993. tag.selfClosing = tok.selfClosing;
  2994. return this.tag(tag);
  2995. },
  2996. /**
  2997. * Parse tag.
  2998. */
  2999. tag: function(tag){
  3000. tag.line = this.line();
  3001. var seenAttrs = false;
  3002. // (attrs | class | id)*
  3003. out:
  3004. while (true) {
  3005. switch (this.peek().type) {
  3006. case 'id':
  3007. case 'class':
  3008. var tok = this.advance();
  3009. tag.setAttribute(tok.type, "'" + tok.val + "'");
  3010. continue;
  3011. case 'attrs':
  3012. if (seenAttrs) {
  3013. console.warn(this.filename + ', line ' + this.peek().line + ':\nYou should not have jade tags with multiple attributes.');
  3014. }
  3015. seenAttrs = true;
  3016. var tok = this.advance();
  3017. var attrs = tok.attrs;
  3018. if (tok.selfClosing) tag.selfClosing = true;
  3019. for (var i = 0; i < attrs.length; i++) {
  3020. tag.setAttribute(attrs[i].name, attrs[i].val, attrs[i].escaped);
  3021. }
  3022. continue;
  3023. case '&attributes':
  3024. var tok = this.advance();
  3025. tag.addAttributes(tok.val);
  3026. break;
  3027. default:
  3028. break out;
  3029. }
  3030. }
  3031. // check immediate '.'
  3032. if ('dot' == this.peek().type) {
  3033. tag.textOnly = true;
  3034. this.advance();
  3035. }
  3036. // (text | code | ':')?
  3037. switch (this.peek().type) {
  3038. case 'text':
  3039. tag.block.push(this.parseText());
  3040. break;
  3041. case 'code':
  3042. tag.code = this.parseCode();
  3043. break;
  3044. case ':':
  3045. this.advance();
  3046. tag.block = new nodes.Block;
  3047. tag.block.push(this.parseExpr());
  3048. break;
  3049. case 'newline':
  3050. case 'indent':
  3051. case 'outdent':
  3052. case 'eos':
  3053. case 'pipeless-text':
  3054. break;
  3055. default:
  3056. throw new Error('Unexpected token `' + this.peek().type + '` expected `text`, `code`, `:`, `newline` or `eos`')
  3057. }
  3058. // newline*
  3059. while ('newline' == this.peek().type) this.advance();
  3060. // block?
  3061. if (tag.textOnly) {
  3062. tag.block = this.parseTextBlock() || new nodes.Block();
  3063. } else if ('indent' == this.peek().type) {
  3064. var block = this.block();
  3065. for (var i = 0, len = block.nodes.length; i < len; ++i) {
  3066. tag.block.push(block.nodes[i]);
  3067. }
  3068. }
  3069. return tag;
  3070. }
  3071. };
  3072. },{"./filters":4,"./lexer":6,"./nodes":16,"./utils":25,"character-parser":29,"constantinople":30,"fs":26,"path":27}],24:[function(require,module,exports){
  3073. 'use strict';
  3074. /**
  3075. * Merge two attribute objects giving precedence
  3076. * to values in object `b`. Classes are special-cased
  3077. * allowing for arrays and merging/joining appropriately
  3078. * resulting in a string.
  3079. *
  3080. * @param {Object} a
  3081. * @param {Object} b
  3082. * @return {Object} a
  3083. * @api private
  3084. */
  3085. exports.merge = function merge(a, b) {
  3086. if (arguments.length === 1) {
  3087. var attrs = a[0];
  3088. for (var i = 1; i < a.length; i++) {
  3089. attrs = merge(attrs, a[i]);
  3090. }
  3091. return attrs;
  3092. }
  3093. var ac = a['class'];
  3094. var bc = b['class'];
  3095. if (ac || bc) {
  3096. ac = ac || [];
  3097. bc = bc || [];
  3098. if (!Array.isArray(ac)) ac = [ac];
  3099. if (!Array.isArray(bc)) bc = [bc];
  3100. a['class'] = ac.concat(bc).filter(nulls);
  3101. }
  3102. for (var key in b) {
  3103. if (key != 'class') {
  3104. a[key] = b[key];
  3105. }
  3106. }
  3107. return a;
  3108. };
  3109. /**
  3110. * Filter null `val`s.
  3111. *
  3112. * @param {*} val
  3113. * @return {Boolean}
  3114. * @api private
  3115. */
  3116. function nulls(val) {
  3117. return val != null && val !== '';
  3118. }
  3119. /**
  3120. * join array as classes.
  3121. *
  3122. * @param {*} val
  3123. * @return {String}
  3124. */
  3125. exports.joinClasses = joinClasses;
  3126. function joinClasses(val) {
  3127. return (Array.isArray(val) ? val.map(joinClasses) :
  3128. (val && typeof val === 'object') ? Object.keys(val).filter(function (key) { return val[key]; }) :
  3129. [val]).filter(nulls).join(' ');
  3130. }
  3131. /**
  3132. * Render the given classes.
  3133. *
  3134. * @param {Array} classes
  3135. * @param {Array.<Boolean>} escaped
  3136. * @return {String}
  3137. */
  3138. exports.cls = function cls(classes, escaped) {
  3139. var buf = [];
  3140. for (var i = 0; i < classes.length; i++) {
  3141. if (escaped && escaped[i]) {
  3142. buf.push(exports.escape(joinClasses([classes[i]])));
  3143. } else {
  3144. buf.push(joinClasses(classes[i]));
  3145. }
  3146. }
  3147. var text = joinClasses(buf);
  3148. if (text.length) {
  3149. return ' class="' + text + '"';
  3150. } else {
  3151. return '';
  3152. }
  3153. };
  3154. exports.style = function (val) {
  3155. if (val && typeof val === 'object') {
  3156. return Object.keys(val).map(function (style) {
  3157. return style + ':' + val[style];
  3158. }).join(';');
  3159. } else {
  3160. return val;
  3161. }
  3162. };
  3163. /**
  3164. * Render the given attribute.
  3165. *
  3166. * @param {String} key
  3167. * @param {String} val
  3168. * @param {Boolean} escaped
  3169. * @param {Boolean} terse
  3170. * @return {String}
  3171. */
  3172. exports.attr = function attr(key, val, escaped, terse) {
  3173. if (key === 'style') {
  3174. val = exports.style(val);
  3175. }
  3176. if ('boolean' == typeof val || null == val) {
  3177. if (val) {
  3178. return ' ' + (terse ? key : key + '="' + key + '"');
  3179. } else {
  3180. return '';
  3181. }
  3182. } else if (0 == key.indexOf('data') && 'string' != typeof val) {
  3183. if (JSON.stringify(val).indexOf('&') !== -1) {
  3184. console.warn('Since Jade 2.0.0, ampersands (`&`) in data attributes ' +
  3185. 'will be escaped to `&amp;`');
  3186. };
  3187. if (val && typeof val.toISOString === 'function') {
  3188. console.warn('Jade will eliminate the double quotes around dates in ' +
  3189. 'ISO form after 2.0.0');
  3190. }
  3191. return ' ' + key + "='" + JSON.stringify(val).replace(/'/g, '&apos;') + "'";
  3192. } else if (escaped) {
  3193. if (val && typeof val.toISOString === 'function') {
  3194. console.warn('Jade will stringify dates in ISO form after 2.0.0');
  3195. }
  3196. return ' ' + key + '="' + exports.escape(val) + '"';
  3197. } else {
  3198. if (val && typeof val.toISOString === 'function') {
  3199. console.warn('Jade will stringify dates in ISO form after 2.0.0');
  3200. }
  3201. return ' ' + key + '="' + val + '"';
  3202. }
  3203. };
  3204. /**
  3205. * Render the given attributes object.
  3206. *
  3207. * @param {Object} obj
  3208. * @param {Object} escaped
  3209. * @return {String}
  3210. */
  3211. exports.attrs = function attrs(obj, terse){
  3212. var buf = [];
  3213. var keys = Object.keys(obj);
  3214. if (keys.length) {
  3215. for (var i = 0; i < keys.length; ++i) {
  3216. var key = keys[i]
  3217. , val = obj[key];
  3218. if ('class' == key) {
  3219. if (val = joinClasses(val)) {
  3220. buf.push(' ' + key + '="' + val + '"');
  3221. }
  3222. } else {
  3223. buf.push(exports.attr(key, val, false, terse));
  3224. }
  3225. }
  3226. }
  3227. return buf.join('');
  3228. };
  3229. /**
  3230. * Escape the given string of `html`.
  3231. *
  3232. * @param {String} html
  3233. * @return {String}
  3234. * @api private
  3235. */
  3236. var jade_encode_html_rules = {
  3237. '&': '&amp;',
  3238. '<': '&lt;',
  3239. '>': '&gt;',
  3240. '"': '&quot;'
  3241. };
  3242. var jade_match_html = /[&<>"]/g;
  3243. function jade_encode_char(c) {
  3244. return jade_encode_html_rules[c] || c;
  3245. }
  3246. exports.escape = jade_escape;
  3247. function jade_escape(html){
  3248. var result = String(html).replace(jade_match_html, jade_encode_char);
  3249. if (result === '' + html) return html;
  3250. else return result;
  3251. };
  3252. /**
  3253. * Re-throw the given `err` in context to the
  3254. * the jade in `filename` at the given `lineno`.
  3255. *
  3256. * @param {Error} err
  3257. * @param {String} filename
  3258. * @param {String} lineno
  3259. * @api private
  3260. */
  3261. exports.rethrow = function rethrow(err, filename, lineno, str){
  3262. if (!(err instanceof Error)) throw err;
  3263. if ((typeof window != 'undefined' || !filename) && !str) {
  3264. err.message += ' on line ' + lineno;
  3265. throw err;
  3266. }
  3267. try {
  3268. str = str || require('fs').readFileSync(filename, 'utf8')
  3269. } catch (ex) {
  3270. rethrow(err, null, lineno)
  3271. }
  3272. var context = 3
  3273. , lines = str.split('\n')
  3274. , start = Math.max(lineno - context, 0)
  3275. , end = Math.min(lines.length, lineno + context);
  3276. // Error context
  3277. var context = lines.slice(start, end).map(function(line, i){
  3278. var curr = i + start + 1;
  3279. return (curr == lineno ? ' > ' : ' ')
  3280. + curr
  3281. + '| '
  3282. + line;
  3283. }).join('\n');
  3284. // Alter exception message
  3285. err.path = filename;
  3286. err.message = (filename || 'Jade') + ':' + lineno
  3287. + '\n' + context + '\n\n' + err.message;
  3288. throw err;
  3289. };
  3290. exports.DebugItem = function DebugItem(lineno, filename) {
  3291. this.lineno = lineno;
  3292. this.filename = filename;
  3293. }
  3294. },{"fs":26}],25:[function(require,module,exports){
  3295. 'use strict';
  3296. /**
  3297. * Merge `b` into `a`.
  3298. *
  3299. * @param {Object} a
  3300. * @param {Object} b
  3301. * @return {Object}
  3302. * @api public
  3303. */
  3304. exports.merge = function(a, b) {
  3305. for (var key in b) a[key] = b[key];
  3306. return a;
  3307. };
  3308. exports.stringify = function(str) {
  3309. return JSON.stringify(str)
  3310. .replace(/\u2028/g, '\\u2028')
  3311. .replace(/\u2029/g, '\\u2029');
  3312. };
  3313. exports.walkAST = function walkAST(ast, before, after) {
  3314. before && before(ast);
  3315. switch (ast.type) {
  3316. case 'Block':
  3317. ast.nodes.forEach(function (node) {
  3318. walkAST(node, before, after);
  3319. });
  3320. break;
  3321. case 'Case':
  3322. case 'Each':
  3323. case 'Mixin':
  3324. case 'Tag':
  3325. case 'When':
  3326. case 'Code':
  3327. ast.block && walkAST(ast.block, before, after);
  3328. break;
  3329. case 'Attrs':
  3330. case 'BlockComment':
  3331. case 'Comment':
  3332. case 'Doctype':
  3333. case 'Filter':
  3334. case 'Literal':
  3335. case 'MixinBlock':
  3336. case 'Text':
  3337. break;
  3338. default:
  3339. throw new Error('Unexpected node type ' + ast.type);
  3340. break;
  3341. }
  3342. after && after(ast);
  3343. };
  3344. },{}],26:[function(require,module,exports){
  3345. },{}],27:[function(require,module,exports){
  3346. (function (process){
  3347. // Copyright Joyent, Inc. and other Node contributors.
  3348. //
  3349. // Permission is hereby granted, free of charge, to any person obtaining a
  3350. // copy of this software and associated documentation files (the
  3351. // "Software"), to deal in the Software without restriction, including
  3352. // without limitation the rights to use, copy, modify, merge, publish,
  3353. // distribute, sublicense, and/or sell copies of the Software, and to permit
  3354. // persons to whom the Software is furnished to do so, subject to the
  3355. // following conditions:
  3356. //
  3357. // The above copyright notice and this permission notice shall be included
  3358. // in all copies or substantial portions of the Software.
  3359. //
  3360. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  3361. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  3362. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  3363. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  3364. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  3365. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  3366. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  3367. // resolves . and .. elements in a path array with directory names there
  3368. // must be no slashes, empty elements, or device names (c:\) in the array
  3369. // (so also no leading and trailing slashes - it does not distinguish
  3370. // relative and absolute paths)
  3371. function normalizeArray(parts, allowAboveRoot) {
  3372. // if the path tries to go above the root, `up` ends up > 0
  3373. var up = 0;
  3374. for (var i = parts.length - 1; i >= 0; i--) {
  3375. var last = parts[i];
  3376. if (last === '.') {
  3377. parts.splice(i, 1);
  3378. } else if (last === '..') {
  3379. parts.splice(i, 1);
  3380. up++;
  3381. } else if (up) {
  3382. parts.splice(i, 1);
  3383. up--;
  3384. }
  3385. }
  3386. // if the path is allowed to go above the root, restore leading ..s
  3387. if (allowAboveRoot) {
  3388. for (; up--; up) {
  3389. parts.unshift('..');
  3390. }
  3391. }
  3392. return parts;
  3393. }
  3394. // Split a filename into [root, dir, basename, ext], unix version
  3395. // 'root' is just a slash, or nothing.
  3396. var splitPathRe =
  3397. /^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/;
  3398. var splitPath = function(filename) {
  3399. return splitPathRe.exec(filename).slice(1);
  3400. };
  3401. // path.resolve([from ...], to)
  3402. // posix version
  3403. exports.resolve = function() {
  3404. var resolvedPath = '',
  3405. resolvedAbsolute = false;
  3406. for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) {
  3407. var path = (i >= 0) ? arguments[i] : process.cwd();
  3408. // Skip empty and invalid entries
  3409. if (typeof path !== 'string') {
  3410. throw new TypeError('Arguments to path.resolve must be strings');
  3411. } else if (!path) {
  3412. continue;
  3413. }
  3414. resolvedPath = path + '/' + resolvedPath;
  3415. resolvedAbsolute = path.charAt(0) === '/';
  3416. }
  3417. // At this point the path should be resolved to a full absolute path, but
  3418. // handle relative paths to be safe (might happen when process.cwd() fails)
  3419. // Normalize the path
  3420. resolvedPath = normalizeArray(filter(resolvedPath.split('/'), function(p) {
  3421. return !!p;
  3422. }), !resolvedAbsolute).join('/');
  3423. return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.';
  3424. };
  3425. // path.normalize(path)
  3426. // posix version
  3427. exports.normalize = function(path) {
  3428. var isAbsolute = exports.isAbsolute(path),
  3429. trailingSlash = substr(path, -1) === '/';
  3430. // Normalize the path
  3431. path = normalizeArray(filter(path.split('/'), function(p) {
  3432. return !!p;
  3433. }), !isAbsolute).join('/');
  3434. if (!path && !isAbsolute) {
  3435. path = '.';
  3436. }
  3437. if (path && trailingSlash) {
  3438. path += '/';
  3439. }
  3440. return (isAbsolute ? '/' : '') + path;
  3441. };
  3442. // posix version
  3443. exports.isAbsolute = function(path) {
  3444. return path.charAt(0) === '/';
  3445. };
  3446. // posix version
  3447. exports.join = function() {
  3448. var paths = Array.prototype.slice.call(arguments, 0);
  3449. return exports.normalize(filter(paths, function(p, index) {
  3450. if (typeof p !== 'string') {
  3451. throw new TypeError('Arguments to path.join must be strings');
  3452. }
  3453. return p;
  3454. }).join('/'));
  3455. };
  3456. // path.relative(from, to)
  3457. // posix version
  3458. exports.relative = function(from, to) {
  3459. from = exports.resolve(from).substr(1);
  3460. to = exports.resolve(to).substr(1);
  3461. function trim(arr) {
  3462. var start = 0;
  3463. for (; start < arr.length; start++) {
  3464. if (arr[start] !== '') break;
  3465. }
  3466. var end = arr.length - 1;
  3467. for (; end >= 0; end--) {
  3468. if (arr[end] !== '') break;
  3469. }
  3470. if (start > end) return [];
  3471. return arr.slice(start, end - start + 1);
  3472. }
  3473. var fromParts = trim(from.split('/'));
  3474. var toParts = trim(to.split('/'));
  3475. var length = Math.min(fromParts.length, toParts.length);
  3476. var samePartsLength = length;
  3477. for (var i = 0; i < length; i++) {
  3478. if (fromParts[i] !== toParts[i]) {
  3479. samePartsLength = i;
  3480. break;
  3481. }
  3482. }
  3483. var outputParts = [];
  3484. for (var i = samePartsLength; i < fromParts.length; i++) {
  3485. outputParts.push('..');
  3486. }
  3487. outputParts = outputParts.concat(toParts.slice(samePartsLength));
  3488. return outputParts.join('/');
  3489. };
  3490. exports.sep = '/';
  3491. exports.delimiter = ':';
  3492. exports.dirname = function(path) {
  3493. var result = splitPath(path),
  3494. root = result[0],
  3495. dir = result[1];
  3496. if (!root && !dir) {
  3497. // No dirname whatsoever
  3498. return '.';
  3499. }
  3500. if (dir) {
  3501. // It has a dirname, strip trailing slash
  3502. dir = dir.substr(0, dir.length - 1);
  3503. }
  3504. return root + dir;
  3505. };
  3506. exports.basename = function(path, ext) {
  3507. var f = splitPath(path)[2];
  3508. // TODO: make this comparison case-insensitive on windows?
  3509. if (ext && f.substr(-1 * ext.length) === ext) {
  3510. f = f.substr(0, f.length - ext.length);
  3511. }
  3512. return f;
  3513. };
  3514. exports.extname = function(path) {
  3515. return splitPath(path)[3];
  3516. };
  3517. function filter (xs, f) {
  3518. if (xs.filter) return xs.filter(f);
  3519. var res = [];
  3520. for (var i = 0; i < xs.length; i++) {
  3521. if (f(xs[i], i, xs)) res.push(xs[i]);
  3522. }
  3523. return res;
  3524. }
  3525. // String.prototype.substr - negative index don't work in IE8
  3526. var substr = 'ab'.substr(-1) === 'b'
  3527. ? function (str, start, len) { return str.substr(start, len) }
  3528. : function (str, start, len) {
  3529. if (start < 0) start = str.length + start;
  3530. return str.substr(start, len);
  3531. }
  3532. ;
  3533. }).call(this,require('_process'))
  3534. },{"_process":28}],28:[function(require,module,exports){
  3535. // shim for using process in browser
  3536. var process = module.exports = {};
  3537. var queue = [];
  3538. var draining = false;
  3539. var currentQueue;
  3540. var queueIndex = -1;
  3541. function cleanUpNextTick() {
  3542. draining = false;
  3543. if (currentQueue.length) {
  3544. queue = currentQueue.concat(queue);
  3545. } else {
  3546. queueIndex = -1;
  3547. }
  3548. if (queue.length) {
  3549. drainQueue();
  3550. }
  3551. }
  3552. function drainQueue() {
  3553. if (draining) {
  3554. return;
  3555. }
  3556. var timeout = setTimeout(cleanUpNextTick);
  3557. draining = true;
  3558. var len = queue.length;
  3559. while(len) {
  3560. currentQueue = queue;
  3561. queue = [];
  3562. while (++queueIndex < len) {
  3563. currentQueue[queueIndex].run();
  3564. }
  3565. queueIndex = -1;
  3566. len = queue.length;
  3567. }
  3568. currentQueue = null;
  3569. draining = false;
  3570. clearTimeout(timeout);
  3571. }
  3572. process.nextTick = function (fun) {
  3573. var args = new Array(arguments.length - 1);
  3574. if (arguments.length > 1) {
  3575. for (var i = 1; i < arguments.length; i++) {
  3576. args[i - 1] = arguments[i];
  3577. }
  3578. }
  3579. queue.push(new Item(fun, args));
  3580. if (queue.length === 1 && !draining) {
  3581. setTimeout(drainQueue, 0);
  3582. }
  3583. };
  3584. // v8 likes predictible objects
  3585. function Item(fun, array) {
  3586. this.fun = fun;
  3587. this.array = array;
  3588. }
  3589. Item.prototype.run = function () {
  3590. this.fun.apply(null, this.array);
  3591. };
  3592. process.title = 'browser';
  3593. process.browser = true;
  3594. process.env = {};
  3595. process.argv = [];
  3596. process.version = ''; // empty string to avoid regexp issues
  3597. process.versions = {};
  3598. function noop() {}
  3599. process.on = noop;
  3600. process.addListener = noop;
  3601. process.once = noop;
  3602. process.off = noop;
  3603. process.removeListener = noop;
  3604. process.removeAllListeners = noop;
  3605. process.emit = noop;
  3606. process.binding = function (name) {
  3607. throw new Error('process.binding is not supported');
  3608. };
  3609. // TODO(shtylman)
  3610. process.cwd = function () { return '/' };
  3611. process.chdir = function (dir) {
  3612. throw new Error('process.chdir is not supported');
  3613. };
  3614. process.umask = function() { return 0; };
  3615. },{}],29:[function(require,module,exports){
  3616. exports = (module.exports = parse);
  3617. exports.parse = parse;
  3618. function parse(src, state, options) {
  3619. options = options || {};
  3620. state = state || exports.defaultState();
  3621. var start = options.start || 0;
  3622. var end = options.end || src.length;
  3623. var index = start;
  3624. while (index < end) {
  3625. if (state.roundDepth < 0 || state.curlyDepth < 0 || state.squareDepth < 0) {
  3626. throw new SyntaxError('Mismatched Bracket: ' + src[index - 1]);
  3627. }
  3628. exports.parseChar(src[index++], state);
  3629. }
  3630. return state;
  3631. }
  3632. exports.parseMax = parseMax;
  3633. function parseMax(src, options) {
  3634. options = options || {};
  3635. var start = options.start || 0;
  3636. var index = start;
  3637. var state = exports.defaultState();
  3638. while (state.roundDepth >= 0 && state.curlyDepth >= 0 && state.squareDepth >= 0) {
  3639. if (index >= src.length) {
  3640. throw new Error('The end of the string was reached with no closing bracket found.');
  3641. }
  3642. exports.parseChar(src[index++], state);
  3643. }
  3644. var end = index - 1;
  3645. return {
  3646. start: start,
  3647. end: end,
  3648. src: src.substring(start, end)
  3649. };
  3650. }
  3651. exports.parseUntil = parseUntil;
  3652. function parseUntil(src, delimiter, options) {
  3653. options = options || {};
  3654. var includeLineComment = options.includeLineComment || false;
  3655. var start = options.start || 0;
  3656. var index = start;
  3657. var state = exports.defaultState();
  3658. while (state.isString() || state.regexp || state.blockComment ||
  3659. (!includeLineComment && state.lineComment) || !startsWith(src, delimiter, index)) {
  3660. exports.parseChar(src[index++], state);
  3661. }
  3662. var end = index;
  3663. return {
  3664. start: start,
  3665. end: end,
  3666. src: src.substring(start, end)
  3667. };
  3668. }
  3669. exports.parseChar = parseChar;
  3670. function parseChar(character, state) {
  3671. if (character.length !== 1) throw new Error('Character must be a string of length 1');
  3672. state = state || exports.defaultState();
  3673. state.src = state.src || '';
  3674. state.src += character;
  3675. var wasComment = state.blockComment || state.lineComment;
  3676. var lastChar = state.history ? state.history[0] : '';
  3677. if (state.regexpStart) {
  3678. if (character === '/' || character == '*') {
  3679. state.regexp = false;
  3680. }
  3681. state.regexpStart = false;
  3682. }
  3683. if (state.lineComment) {
  3684. if (character === '\n') {
  3685. state.lineComment = false;
  3686. }
  3687. } else if (state.blockComment) {
  3688. if (state.lastChar === '*' && character === '/') {
  3689. state.blockComment = false;
  3690. }
  3691. } else if (state.singleQuote) {
  3692. if (character === '\'' && !state.escaped) {
  3693. state.singleQuote = false;
  3694. } else if (character === '\\' && !state.escaped) {
  3695. state.escaped = true;
  3696. } else {
  3697. state.escaped = false;
  3698. }
  3699. } else if (state.doubleQuote) {
  3700. if (character === '"' && !state.escaped) {
  3701. state.doubleQuote = false;
  3702. } else if (character === '\\' && !state.escaped) {
  3703. state.escaped = true;
  3704. } else {
  3705. state.escaped = false;
  3706. }
  3707. } else if (state.regexp) {
  3708. if (character === '/' && !state.escaped) {
  3709. state.regexp = false;
  3710. } else if (character === '\\' && !state.escaped) {
  3711. state.escaped = true;
  3712. } else {
  3713. state.escaped = false;
  3714. }
  3715. } else if (lastChar === '/' && character === '/') {
  3716. state.history = state.history.substr(1);
  3717. state.lineComment = true;
  3718. } else if (lastChar === '/' && character === '*') {
  3719. state.history = state.history.substr(1);
  3720. state.blockComment = true;
  3721. } else if (character === '/' && isRegexp(state.history)) {
  3722. state.regexp = true;
  3723. state.regexpStart = true;
  3724. } else if (character === '\'') {
  3725. state.singleQuote = true;
  3726. } else if (character === '"') {
  3727. state.doubleQuote = true;
  3728. } else if (character === '(') {
  3729. state.roundDepth++;
  3730. } else if (character === ')') {
  3731. state.roundDepth--;
  3732. } else if (character === '{') {
  3733. state.curlyDepth++;
  3734. } else if (character === '}') {
  3735. state.curlyDepth--;
  3736. } else if (character === '[') {
  3737. state.squareDepth++;
  3738. } else if (character === ']') {
  3739. state.squareDepth--;
  3740. }
  3741. if (!state.blockComment && !state.lineComment && !wasComment) state.history = character + state.history;
  3742. state.lastChar = character; // store last character for ending block comments
  3743. return state;
  3744. }
  3745. exports.defaultState = function () { return new State() };
  3746. function State() {
  3747. this.lineComment = false;
  3748. this.blockComment = false;
  3749. this.singleQuote = false;
  3750. this.doubleQuote = false;
  3751. this.regexp = false;
  3752. this.escaped = false;
  3753. this.roundDepth = 0;
  3754. this.curlyDepth = 0;
  3755. this.squareDepth = 0;
  3756. this.history = ''
  3757. this.lastChar = ''
  3758. }
  3759. State.prototype.isString = function () {
  3760. return this.singleQuote || this.doubleQuote;
  3761. }
  3762. State.prototype.isComment = function () {
  3763. return this.lineComment || this.blockComment;
  3764. }
  3765. State.prototype.isNesting = function () {
  3766. return this.isString() || this.isComment() || this.regexp || this.roundDepth > 0 || this.curlyDepth > 0 || this.squareDepth > 0
  3767. }
  3768. function startsWith(str, start, i) {
  3769. return str.substr(i || 0, start.length) === start;
  3770. }
  3771. exports.isPunctuator = isPunctuator
  3772. function isPunctuator(c) {
  3773. if (!c) return true; // the start of a string is a punctuator
  3774. var code = c.charCodeAt(0)
  3775. switch (code) {
  3776. case 46: // . dot
  3777. case 40: // ( open bracket
  3778. case 41: // ) close bracket
  3779. case 59: // ; semicolon
  3780. case 44: // , comma
  3781. case 123: // { open curly brace
  3782. case 125: // } close curly brace
  3783. case 91: // [
  3784. case 93: // ]
  3785. case 58: // :
  3786. case 63: // ?
  3787. case 126: // ~
  3788. case 37: // %
  3789. case 38: // &
  3790. case 42: // *:
  3791. case 43: // +
  3792. case 45: // -
  3793. case 47: // /
  3794. case 60: // <
  3795. case 62: // >
  3796. case 94: // ^
  3797. case 124: // |
  3798. case 33: // !
  3799. case 61: // =
  3800. return true;
  3801. default:
  3802. return false;
  3803. }
  3804. }
  3805. exports.isKeyword = isKeyword
  3806. function isKeyword(id) {
  3807. return (id === 'if') || (id === 'in') || (id === 'do') || (id === 'var') || (id === 'for') || (id === 'new') ||
  3808. (id === 'try') || (id === 'let') || (id === 'this') || (id === 'else') || (id === 'case') ||
  3809. (id === 'void') || (id === 'with') || (id === 'enum') || (id === 'while') || (id === 'break') || (id === 'catch') ||
  3810. (id === 'throw') || (id === 'const') || (id === 'yield') || (id === 'class') || (id === 'super') ||
  3811. (id === 'return') || (id === 'typeof') || (id === 'delete') || (id === 'switch') || (id === 'export') ||
  3812. (id === 'import') || (id === 'default') || (id === 'finally') || (id === 'extends') || (id === 'function') ||
  3813. (id === 'continue') || (id === 'debugger') || (id === 'package') || (id === 'private') || (id === 'interface') ||
  3814. (id === 'instanceof') || (id === 'implements') || (id === 'protected') || (id === 'public') || (id === 'static') ||
  3815. (id === 'yield') || (id === 'let');
  3816. }
  3817. function isRegexp(history) {
  3818. //could be start of regexp or divide sign
  3819. history = history.replace(/^\s*/, '');
  3820. //unless its an `if`, `while`, `for` or `with` it's a divide, so we assume it's a divide
  3821. if (history[0] === ')') return false;
  3822. //unless it's a function expression, it's a regexp, so we assume it's a regexp
  3823. if (history[0] === '}') return true;
  3824. //any punctuation means it's a regexp
  3825. if (isPunctuator(history[0])) return true;
  3826. //if the last thing was a keyword then it must be a regexp (e.g. `typeof /foo/`)
  3827. if (/^\w+\b/.test(history) && isKeyword(/^\w+\b/.exec(history)[0].split('').reverse().join(''))) return true;
  3828. return false;
  3829. }
  3830. },{}],30:[function(require,module,exports){
  3831. 'use strict'
  3832. var detect = require('acorn-globals');
  3833. var lastSRC = '(null)';
  3834. var lastRes = true;
  3835. var lastConstants = undefined;
  3836. module.exports = isConstant;
  3837. function isConstant(src, constants) {
  3838. src = '(' + src + ')';
  3839. if (lastSRC === src && lastConstants === constants) return lastRes;
  3840. lastSRC = src;
  3841. lastConstants = constants;
  3842. try {
  3843. isExpression(src);
  3844. return lastRes = (detect(src).filter(function (key) {
  3845. return !constants || !(key.name in constants);
  3846. }).length === 0);
  3847. } catch (ex) {
  3848. return lastRes = false;
  3849. }
  3850. }
  3851. isConstant.isConstant = isConstant;
  3852. isConstant.toConstant = toConstant;
  3853. function toConstant(src, constants) {
  3854. if (!isConstant(src, constants)) throw new Error(JSON.stringify(src) + ' is not constant.');
  3855. return Function(Object.keys(constants || {}).join(','), 'return (' + src + ')').apply(null, Object.keys(constants || {}).map(function (key) {
  3856. return constants[key];
  3857. }));
  3858. }
  3859. function isExpression(src) {
  3860. try {
  3861. eval('throw "STOP"; (function () { return (' + src + '); })()');
  3862. return false;
  3863. }
  3864. catch (err) {
  3865. return err === 'STOP';
  3866. }
  3867. }
  3868. },{"acorn-globals":31}],31:[function(require,module,exports){
  3869. 'use strict';
  3870. var acorn = require('acorn');
  3871. var walk = require('acorn/dist/walk');
  3872. // polyfill for https://github.com/marijnh/acorn/pull/231
  3873. walk.base.ExportNamedDeclaration = walk.base.ExportDefaultDeclaration = function (node, st, c) {
  3874. return c(node.declaration, st);
  3875. };
  3876. walk.base.ImportDefaultSpecifier = walk.base.ImportNamespaceSpecifier = function () {};
  3877. function isScope(node) {
  3878. return node.type === 'FunctionExpression' || node.type === 'FunctionDeclaration' || node.type === 'Program';
  3879. }
  3880. function isBlockScope(node) {
  3881. return node.type === 'BlockStatement' || isScope(node);
  3882. }
  3883. function declaresArguments(node) {
  3884. return node.type === 'FunctionExpression' || node.type === 'FunctionDeclaration' || node.type === 'ArrowFunction';
  3885. }
  3886. function declaresThis(node) {
  3887. return node.type === 'FunctionExpression' || node.type === 'FunctionDeclaration';
  3888. }
  3889. function reallyParse(source) {
  3890. try {
  3891. return acorn.parse(source, {
  3892. ecmaVersion: 6,
  3893. allowReturnOutsideFunction: true,
  3894. sourceType: 'module'
  3895. });
  3896. } catch (ex) {
  3897. if (ex.name !== 'SyntaxError') {
  3898. throw ex;
  3899. }
  3900. try {
  3901. return acorn.parse(source, {
  3902. ecmaVersion: 6,
  3903. allowReturnOutsideFunction: true
  3904. });
  3905. } catch (ex) {
  3906. if (ex.name !== 'SyntaxError') {
  3907. throw ex;
  3908. }
  3909. return acorn.parse(source, {
  3910. ecmaVersion: 5,
  3911. allowReturnOutsideFunction: true
  3912. });
  3913. }
  3914. }
  3915. }
  3916. module.exports = findGlobals;
  3917. module.exports.parse = reallyParse;
  3918. function findGlobals(source) {
  3919. var globals = [];
  3920. var ast = typeof source === 'string' ?
  3921. ast = reallyParse(source) :
  3922. source;
  3923. if (!(ast && typeof ast === 'object' && ast.type === 'Program')) {
  3924. throw new TypeError('Source must be either a string of JavaScript or an acorn AST');
  3925. }
  3926. var declareFunction = function (node) {
  3927. var fn = node;
  3928. fn.locals = fn.locals || {};
  3929. node.params.forEach(function (node) {
  3930. fn.locals[node.name] = true;
  3931. });
  3932. if (node.id) {
  3933. fn.locals[node.id.name] = true;
  3934. }
  3935. }
  3936. walk.ancestor(ast, {
  3937. 'VariableDeclaration': function (node, parents) {
  3938. var parent = null;
  3939. for (var i = parents.length - 1; i >= 0 && parent === null; i--) {
  3940. if (node.kind === 'var' ? isScope(parents[i]) : isBlockScope(parents[i])) {
  3941. parent = parents[i];
  3942. }
  3943. }
  3944. parent.locals = parent.locals || {};
  3945. node.declarations.forEach(function (declaration) {
  3946. parent.locals[declaration.id.name] = true;
  3947. });
  3948. },
  3949. 'FunctionDeclaration': function (node, parents) {
  3950. var parent = null;
  3951. for (var i = parents.length - 2; i >= 0 && parent === null; i--) {
  3952. if (isScope(parents[i])) {
  3953. parent = parents[i];
  3954. }
  3955. }
  3956. parent.locals = parent.locals || {};
  3957. parent.locals[node.id.name] = true;
  3958. declareFunction(node);
  3959. },
  3960. 'Function': declareFunction,
  3961. 'TryStatement': function (node) {
  3962. node.handler.body.locals = node.handler.body.locals || {};
  3963. node.handler.body.locals[node.handler.param.name] = true;
  3964. },
  3965. 'ImportDefaultSpecifier': function (node) {
  3966. if (node.local.type === 'Identifier') {
  3967. ast.locals = ast.locals || {};
  3968. ast.locals[node.local.name] = true;
  3969. }
  3970. },
  3971. 'ImportSpecifier': function (node) {
  3972. var id = node.local ? node.local : node.imported;
  3973. if (id.type === 'Identifier') {
  3974. ast.locals = ast.locals || {};
  3975. ast.locals[id.name] = true;
  3976. }
  3977. },
  3978. 'ImportNamespaceSpecifier': function (node) {
  3979. if (node.local.type === 'Identifier') {
  3980. ast.locals = ast.locals || {};
  3981. ast.locals[node.local.name] = true;
  3982. }
  3983. }
  3984. });
  3985. walk.ancestor(ast, {
  3986. 'Identifier': function (node, parents) {
  3987. var name = node.name;
  3988. if (name === 'undefined') return;
  3989. for (var i = 0; i < parents.length; i++) {
  3990. if (name === 'arguments' && declaresArguments(parents[i])) {
  3991. return;
  3992. }
  3993. if (parents[i].locals && name in parents[i].locals) {
  3994. return;
  3995. }
  3996. }
  3997. node.parents = parents;
  3998. globals.push(node);
  3999. },
  4000. ThisExpression: function (node, parents) {
  4001. for (var i = 0; i < parents.length; i++) {
  4002. if (declaresThis(parents[i])) {
  4003. return;
  4004. }
  4005. }
  4006. node.parents = parents;
  4007. globals.push(node);
  4008. }
  4009. });
  4010. var groupedGlobals = {};
  4011. globals.forEach(function (node) {
  4012. groupedGlobals[node.name] = (groupedGlobals[node.name] || []);
  4013. groupedGlobals[node.name].push(node);
  4014. });
  4015. return Object.keys(groupedGlobals).sort().map(function (name) {
  4016. return {name: name, nodes: groupedGlobals[name]};
  4017. });
  4018. }
  4019. },{"acorn":32,"acorn/dist/walk":33}],32:[function(require,module,exports){
  4020. (function (global){
  4021. (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.acorn = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){
  4022. // The main exported interface (under `self.acorn` when in the
  4023. // browser) is a `parse` function that takes a code string and
  4024. // returns an abstract syntax tree as specified by [Mozilla parser
  4025. // API][api].
  4026. //
  4027. // [api]: https://developer.mozilla.org/en-US/docs/SpiderMonkey/Parser_API
  4028. "use strict";
  4029. exports.parse = parse;
  4030. // This function tries to parse a single expression at a given
  4031. // offset in a string. Useful for parsing mixed-language formats
  4032. // that embed JavaScript expressions.
  4033. exports.parseExpressionAt = parseExpressionAt;
  4034. // Acorn is organized as a tokenizer and a recursive-descent parser.
  4035. // The `tokenize` export provides an interface to the tokenizer.
  4036. exports.tokenizer = tokenizer;
  4037. exports.__esModule = true;
  4038. // Acorn is a tiny, fast JavaScript parser written in JavaScript.
  4039. //
  4040. // Acorn was written by Marijn Haverbeke, Ingvar Stepanyan, and
  4041. // various contributors and released under an MIT license.
  4042. //
  4043. // Git repositories for Acorn are available at
  4044. //
  4045. // http://marijnhaverbeke.nl/git/acorn
  4046. // https://github.com/marijnh/acorn.git
  4047. //
  4048. // Please use the [github bug tracker][ghbt] to report issues.
  4049. //
  4050. // [ghbt]: https://github.com/marijnh/acorn/issues
  4051. //
  4052. // This file defines the main parser interface. The library also comes
  4053. // with a [error-tolerant parser][dammit] and an
  4054. // [abstract syntax tree walker][walk], defined in other files.
  4055. //
  4056. // [dammit]: acorn_loose.js
  4057. // [walk]: util/walk.js
  4058. var _state = _dereq_("./state");
  4059. var Parser = _state.Parser;
  4060. var _options = _dereq_("./options");
  4061. var getOptions = _options.getOptions;
  4062. _dereq_("./parseutil");
  4063. _dereq_("./statement");
  4064. _dereq_("./lval");
  4065. _dereq_("./expression");
  4066. exports.Parser = _state.Parser;
  4067. exports.plugins = _state.plugins;
  4068. exports.defaultOptions = _options.defaultOptions;
  4069. var _location = _dereq_("./location");
  4070. exports.SourceLocation = _location.SourceLocation;
  4071. exports.getLineInfo = _location.getLineInfo;
  4072. exports.Node = _dereq_("./node").Node;
  4073. var _tokentype = _dereq_("./tokentype");
  4074. exports.TokenType = _tokentype.TokenType;
  4075. exports.tokTypes = _tokentype.types;
  4076. var _tokencontext = _dereq_("./tokencontext");
  4077. exports.TokContext = _tokencontext.TokContext;
  4078. exports.tokContexts = _tokencontext.types;
  4079. var _identifier = _dereq_("./identifier");
  4080. exports.isIdentifierChar = _identifier.isIdentifierChar;
  4081. exports.isIdentifierStart = _identifier.isIdentifierStart;
  4082. exports.Token = _dereq_("./tokenize").Token;
  4083. var _whitespace = _dereq_("./whitespace");
  4084. exports.isNewLine = _whitespace.isNewLine;
  4085. exports.lineBreak = _whitespace.lineBreak;
  4086. exports.lineBreakG = _whitespace.lineBreakG;
  4087. var version = "1.2.2";exports.version = version;
  4088. function parse(input, options) {
  4089. var p = parser(options, input);
  4090. var startPos = p.pos,
  4091. startLoc = p.options.locations && p.curPosition();
  4092. p.nextToken();
  4093. return p.parseTopLevel(p.options.program || p.startNodeAt(startPos, startLoc));
  4094. }
  4095. function parseExpressionAt(input, pos, options) {
  4096. var p = parser(options, input, pos);
  4097. p.nextToken();
  4098. return p.parseExpression();
  4099. }
  4100. function tokenizer(input, options) {
  4101. return parser(options, input);
  4102. }
  4103. function parser(options, input) {
  4104. return new Parser(getOptions(options), String(input));
  4105. }
  4106. },{"./expression":6,"./identifier":7,"./location":8,"./lval":9,"./node":10,"./options":11,"./parseutil":12,"./state":13,"./statement":14,"./tokencontext":15,"./tokenize":16,"./tokentype":17,"./whitespace":19}],2:[function(_dereq_,module,exports){
  4107. if (typeof Object.create === 'function') {
  4108. // implementation from standard node.js 'util' module
  4109. module.exports = function inherits(ctor, superCtor) {
  4110. ctor.super_ = superCtor
  4111. ctor.prototype = Object.create(superCtor.prototype, {
  4112. constructor: {
  4113. value: ctor,
  4114. enumerable: false,
  4115. writable: true,
  4116. configurable: true
  4117. }
  4118. });
  4119. };
  4120. } else {
  4121. // old school shim for old browsers
  4122. module.exports = function inherits(ctor, superCtor) {
  4123. ctor.super_ = superCtor
  4124. var TempCtor = function () {}
  4125. TempCtor.prototype = superCtor.prototype
  4126. ctor.prototype = new TempCtor()
  4127. ctor.prototype.constructor = ctor
  4128. }
  4129. }
  4130. },{}],3:[function(_dereq_,module,exports){
  4131. // shim for using process in browser
  4132. var process = module.exports = {};
  4133. var queue = [];
  4134. var draining = false;
  4135. function drainQueue() {
  4136. if (draining) {
  4137. return;
  4138. }
  4139. draining = true;
  4140. var currentQueue;
  4141. var len = queue.length;
  4142. while(len) {
  4143. currentQueue = queue;
  4144. queue = [];
  4145. var i = -1;
  4146. while (++i < len) {
  4147. currentQueue[i]();
  4148. }
  4149. len = queue.length;
  4150. }
  4151. draining = false;
  4152. }
  4153. process.nextTick = function (fun) {
  4154. queue.push(fun);
  4155. if (!draining) {
  4156. setTimeout(drainQueue, 0);
  4157. }
  4158. };
  4159. process.title = 'browser';
  4160. process.browser = true;
  4161. process.env = {};
  4162. process.argv = [];
  4163. process.version = ''; // empty string to avoid regexp issues
  4164. process.versions = {};
  4165. function noop() {}
  4166. process.on = noop;
  4167. process.addListener = noop;
  4168. process.once = noop;
  4169. process.off = noop;
  4170. process.removeListener = noop;
  4171. process.removeAllListeners = noop;
  4172. process.emit = noop;
  4173. process.binding = function (name) {
  4174. throw new Error('process.binding is not supported');
  4175. };
  4176. // TODO(shtylman)
  4177. process.cwd = function () { return '/' };
  4178. process.chdir = function (dir) {
  4179. throw new Error('process.chdir is not supported');
  4180. };
  4181. process.umask = function() { return 0; };
  4182. },{}],4:[function(_dereq_,module,exports){
  4183. module.exports = function isBuffer(arg) {
  4184. return arg && typeof arg === 'object'
  4185. && typeof arg.copy === 'function'
  4186. && typeof arg.fill === 'function'
  4187. && typeof arg.readUInt8 === 'function';
  4188. }
  4189. },{}],5:[function(_dereq_,module,exports){
  4190. (function (process,global){
  4191. // Copyright Joyent, Inc. and other Node contributors.
  4192. //
  4193. // Permission is hereby granted, free of charge, to any person obtaining a
  4194. // copy of this software and associated documentation files (the
  4195. // "Software"), to deal in the Software without restriction, including
  4196. // without limitation the rights to use, copy, modify, merge, publish,
  4197. // distribute, sublicense, and/or sell copies of the Software, and to permit
  4198. // persons to whom the Software is furnished to do so, subject to the
  4199. // following conditions:
  4200. //
  4201. // The above copyright notice and this permission notice shall be included
  4202. // in all copies or substantial portions of the Software.
  4203. //
  4204. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  4205. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  4206. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  4207. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  4208. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  4209. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  4210. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  4211. var formatRegExp = /%[sdj%]/g;
  4212. exports.format = function(f) {
  4213. if (!isString(f)) {
  4214. var objects = [];
  4215. for (var i = 0; i < arguments.length; i++) {
  4216. objects.push(inspect(arguments[i]));
  4217. }
  4218. return objects.join(' ');
  4219. }
  4220. var i = 1;
  4221. var args = arguments;
  4222. var len = args.length;
  4223. var str = String(f).replace(formatRegExp, function(x) {
  4224. if (x === '%%') return '%';
  4225. if (i >= len) return x;
  4226. switch (x) {
  4227. case '%s': return String(args[i++]);
  4228. case '%d': return Number(args[i++]);
  4229. case '%j':
  4230. try {
  4231. return JSON.stringify(args[i++]);
  4232. } catch (_) {
  4233. return '[Circular]';
  4234. }
  4235. default:
  4236. return x;
  4237. }
  4238. });
  4239. for (var x = args[i]; i < len; x = args[++i]) {
  4240. if (isNull(x) || !isObject(x)) {
  4241. str += ' ' + x;
  4242. } else {
  4243. str += ' ' + inspect(x);
  4244. }
  4245. }
  4246. return str;
  4247. };
  4248. // Mark that a method should not be used.
  4249. // Returns a modified function which warns once by default.
  4250. // If --no-deprecation is set, then it is a no-op.
  4251. exports.deprecate = function(fn, msg) {
  4252. // Allow for deprecating things in the process of starting up.
  4253. if (isUndefined(global.process)) {
  4254. return function() {
  4255. return exports.deprecate(fn, msg).apply(this, arguments);
  4256. };
  4257. }
  4258. if (process.noDeprecation === true) {
  4259. return fn;
  4260. }
  4261. var warned = false;
  4262. function deprecated() {
  4263. if (!warned) {
  4264. if (process.throwDeprecation) {
  4265. throw new Error(msg);
  4266. } else if (process.traceDeprecation) {
  4267. console.trace(msg);
  4268. } else {
  4269. console.error(msg);
  4270. }
  4271. warned = true;
  4272. }
  4273. return fn.apply(this, arguments);
  4274. }
  4275. return deprecated;
  4276. };
  4277. var debugs = {};
  4278. var debugEnviron;
  4279. exports.debuglog = function(set) {
  4280. if (isUndefined(debugEnviron))
  4281. debugEnviron = process.env.NODE_DEBUG || '';
  4282. set = set.toUpperCase();
  4283. if (!debugs[set]) {
  4284. if (new RegExp('\\b' + set + '\\b', 'i').test(debugEnviron)) {
  4285. var pid = process.pid;
  4286. debugs[set] = function() {
  4287. var msg = exports.format.apply(exports, arguments);
  4288. console.error('%s %d: %s', set, pid, msg);
  4289. };
  4290. } else {
  4291. debugs[set] = function() {};
  4292. }
  4293. }
  4294. return debugs[set];
  4295. };
  4296. /**
  4297. * Echos the value of a value. Trys to print the value out
  4298. * in the best way possible given the different types.
  4299. *
  4300. * @param {Object} obj The object to print out.
  4301. * @param {Object} opts Optional options object that alters the output.
  4302. */
  4303. /* legacy: obj, showHidden, depth, colors*/
  4304. function inspect(obj, opts) {
  4305. // default options
  4306. var ctx = {
  4307. seen: [],
  4308. stylize: stylizeNoColor
  4309. };
  4310. // legacy...
  4311. if (arguments.length >= 3) ctx.depth = arguments[2];
  4312. if (arguments.length >= 4) ctx.colors = arguments[3];
  4313. if (isBoolean(opts)) {
  4314. // legacy...
  4315. ctx.showHidden = opts;
  4316. } else if (opts) {
  4317. // got an "options" object
  4318. exports._extend(ctx, opts);
  4319. }
  4320. // set default options
  4321. if (isUndefined(ctx.showHidden)) ctx.showHidden = false;
  4322. if (isUndefined(ctx.depth)) ctx.depth = 2;
  4323. if (isUndefined(ctx.colors)) ctx.colors = false;
  4324. if (isUndefined(ctx.customInspect)) ctx.customInspect = true;
  4325. if (ctx.colors) ctx.stylize = stylizeWithColor;
  4326. return formatValue(ctx, obj, ctx.depth);
  4327. }
  4328. exports.inspect = inspect;
  4329. // http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
  4330. inspect.colors = {
  4331. 'bold' : [1, 22],
  4332. 'italic' : [3, 23],
  4333. 'underline' : [4, 24],
  4334. 'inverse' : [7, 27],
  4335. 'white' : [37, 39],
  4336. 'grey' : [90, 39],
  4337. 'black' : [30, 39],
  4338. 'blue' : [34, 39],
  4339. 'cyan' : [36, 39],
  4340. 'green' : [32, 39],
  4341. 'magenta' : [35, 39],
  4342. 'red' : [31, 39],
  4343. 'yellow' : [33, 39]
  4344. };
  4345. // Don't use 'blue' not visible on cmd.exe
  4346. inspect.styles = {
  4347. 'special': 'cyan',
  4348. 'number': 'yellow',
  4349. 'boolean': 'yellow',
  4350. 'undefined': 'grey',
  4351. 'null': 'bold',
  4352. 'string': 'green',
  4353. 'date': 'magenta',
  4354. // "name": intentionally not styling
  4355. 'regexp': 'red'
  4356. };
  4357. function stylizeWithColor(str, styleType) {
  4358. var style = inspect.styles[styleType];
  4359. if (style) {
  4360. return '\u001b[' + inspect.colors[style][0] + 'm' + str +
  4361. '\u001b[' + inspect.colors[style][1] + 'm';
  4362. } else {
  4363. return str;
  4364. }
  4365. }
  4366. function stylizeNoColor(str, styleType) {
  4367. return str;
  4368. }
  4369. function arrayToHash(array) {
  4370. var hash = {};
  4371. array.forEach(function(val, idx) {
  4372. hash[val] = true;
  4373. });
  4374. return hash;
  4375. }
  4376. function formatValue(ctx, value, recurseTimes) {
  4377. // Provide a hook for user-specified inspect functions.
  4378. // Check that value is an object with an inspect function on it
  4379. if (ctx.customInspect &&
  4380. value &&
  4381. isFunction(value.inspect) &&
  4382. // Filter out the util module, it's inspect function is special
  4383. value.inspect !== exports.inspect &&
  4384. // Also filter out any prototype objects using the circular check.
  4385. !(value.constructor && value.constructor.prototype === value)) {
  4386. var ret = value.inspect(recurseTimes, ctx);
  4387. if (!isString(ret)) {
  4388. ret = formatValue(ctx, ret, recurseTimes);
  4389. }
  4390. return ret;
  4391. }
  4392. // Primitive types cannot have properties
  4393. var primitive = formatPrimitive(ctx, value);
  4394. if (primitive) {
  4395. return primitive;
  4396. }
  4397. // Look up the keys of the object.
  4398. var keys = Object.keys(value);
  4399. var visibleKeys = arrayToHash(keys);
  4400. if (ctx.showHidden) {
  4401. keys = Object.getOwnPropertyNames(value);
  4402. }
  4403. // IE doesn't make error fields non-enumerable
  4404. // http://msdn.microsoft.com/en-us/library/ie/dww52sbt(v=vs.94).aspx
  4405. if (isError(value)
  4406. && (keys.indexOf('message') >= 0 || keys.indexOf('description') >= 0)) {
  4407. return formatError(value);
  4408. }
  4409. // Some type of object without properties can be shortcutted.
  4410. if (keys.length === 0) {
  4411. if (isFunction(value)) {
  4412. var name = value.name ? ': ' + value.name : '';
  4413. return ctx.stylize('[Function' + name + ']', 'special');
  4414. }
  4415. if (isRegExp(value)) {
  4416. return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
  4417. }
  4418. if (isDate(value)) {
  4419. return ctx.stylize(Date.prototype.toString.call(value), 'date');
  4420. }
  4421. if (isError(value)) {
  4422. return formatError(value);
  4423. }
  4424. }
  4425. var base = '', array = false, braces = ['{', '}'];
  4426. // Make Array say that they are Array
  4427. if (isArray(value)) {
  4428. array = true;
  4429. braces = ['[', ']'];
  4430. }
  4431. // Make functions say that they are functions
  4432. if (isFunction(value)) {
  4433. var n = value.name ? ': ' + value.name : '';
  4434. base = ' [Function' + n + ']';
  4435. }
  4436. // Make RegExps say that they are RegExps
  4437. if (isRegExp(value)) {
  4438. base = ' ' + RegExp.prototype.toString.call(value);
  4439. }
  4440. // Make dates with properties first say the date
  4441. if (isDate(value)) {
  4442. base = ' ' + Date.prototype.toUTCString.call(value);
  4443. }
  4444. // Make error with message first say the error
  4445. if (isError(value)) {
  4446. base = ' ' + formatError(value);
  4447. }
  4448. if (keys.length === 0 && (!array || value.length == 0)) {
  4449. return braces[0] + base + braces[1];
  4450. }
  4451. if (recurseTimes < 0) {
  4452. if (isRegExp(value)) {
  4453. return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
  4454. } else {
  4455. return ctx.stylize('[Object]', 'special');
  4456. }
  4457. }
  4458. ctx.seen.push(value);
  4459. var output;
  4460. if (array) {
  4461. output = formatArray(ctx, value, recurseTimes, visibleKeys, keys);
  4462. } else {
  4463. output = keys.map(function(key) {
  4464. return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array);
  4465. });
  4466. }
  4467. ctx.seen.pop();
  4468. return reduceToSingleString(output, base, braces);
  4469. }
  4470. function formatPrimitive(ctx, value) {
  4471. if (isUndefined(value))
  4472. return ctx.stylize('undefined', 'undefined');
  4473. if (isString(value)) {
  4474. var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '')
  4475. .replace(/'/g, "\\'")
  4476. .replace(/\\"/g, '"') + '\'';
  4477. return ctx.stylize(simple, 'string');
  4478. }
  4479. if (isNumber(value))
  4480. return ctx.stylize('' + value, 'number');
  4481. if (isBoolean(value))
  4482. return ctx.stylize('' + value, 'boolean');
  4483. // For some reason typeof null is "object", so special case here.
  4484. if (isNull(value))
  4485. return ctx.stylize('null', 'null');
  4486. }
  4487. function formatError(value) {
  4488. return '[' + Error.prototype.toString.call(value) + ']';
  4489. }
  4490. function formatArray(ctx, value, recurseTimes, visibleKeys, keys) {
  4491. var output = [];
  4492. for (var i = 0, l = value.length; i < l; ++i) {
  4493. if (hasOwnProperty(value, String(i))) {
  4494. output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
  4495. String(i), true));
  4496. } else {
  4497. output.push('');
  4498. }
  4499. }
  4500. keys.forEach(function(key) {
  4501. if (!key.match(/^\d+$/)) {
  4502. output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
  4503. key, true));
  4504. }
  4505. });
  4506. return output;
  4507. }
  4508. function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {
  4509. var name, str, desc;
  4510. desc = Object.getOwnPropertyDescriptor(value, key) || { value: value[key] };
  4511. if (desc.get) {
  4512. if (desc.set) {
  4513. str = ctx.stylize('[Getter/Setter]', 'special');
  4514. } else {
  4515. str = ctx.stylize('[Getter]', 'special');
  4516. }
  4517. } else {
  4518. if (desc.set) {
  4519. str = ctx.stylize('[Setter]', 'special');
  4520. }
  4521. }
  4522. if (!hasOwnProperty(visibleKeys, key)) {
  4523. name = '[' + key + ']';
  4524. }
  4525. if (!str) {
  4526. if (ctx.seen.indexOf(desc.value) < 0) {
  4527. if (isNull(recurseTimes)) {
  4528. str = formatValue(ctx, desc.value, null);
  4529. } else {
  4530. str = formatValue(ctx, desc.value, recurseTimes - 1);
  4531. }
  4532. if (str.indexOf('\n') > -1) {
  4533. if (array) {
  4534. str = str.split('\n').map(function(line) {
  4535. return ' ' + line;
  4536. }).join('\n').substr(2);
  4537. } else {
  4538. str = '\n' + str.split('\n').map(function(line) {
  4539. return ' ' + line;
  4540. }).join('\n');
  4541. }
  4542. }
  4543. } else {
  4544. str = ctx.stylize('[Circular]', 'special');
  4545. }
  4546. }
  4547. if (isUndefined(name)) {
  4548. if (array && key.match(/^\d+$/)) {
  4549. return str;
  4550. }
  4551. name = JSON.stringify('' + key);
  4552. if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
  4553. name = name.substr(1, name.length - 2);
  4554. name = ctx.stylize(name, 'name');
  4555. } else {
  4556. name = name.replace(/'/g, "\\'")
  4557. .replace(/\\"/g, '"')
  4558. .replace(/(^"|"$)/g, "'");
  4559. name = ctx.stylize(name, 'string');
  4560. }
  4561. }
  4562. return name + ': ' + str;
  4563. }
  4564. function reduceToSingleString(output, base, braces) {
  4565. var numLinesEst = 0;
  4566. var length = output.reduce(function(prev, cur) {
  4567. numLinesEst++;
  4568. if (cur.indexOf('\n') >= 0) numLinesEst++;
  4569. return prev + cur.replace(/\u001b\[\d\d?m/g, '').length + 1;
  4570. }, 0);
  4571. if (length > 60) {
  4572. return braces[0] +
  4573. (base === '' ? '' : base + '\n ') +
  4574. ' ' +
  4575. output.join(',\n ') +
  4576. ' ' +
  4577. braces[1];
  4578. }
  4579. return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
  4580. }
  4581. // NOTE: These type checking functions intentionally don't use `instanceof`
  4582. // because it is fragile and can be easily faked with `Object.create()`.
  4583. function isArray(ar) {
  4584. return Array.isArray(ar);
  4585. }
  4586. exports.isArray = isArray;
  4587. function isBoolean(arg) {
  4588. return typeof arg === 'boolean';
  4589. }
  4590. exports.isBoolean = isBoolean;
  4591. function isNull(arg) {
  4592. return arg === null;
  4593. }
  4594. exports.isNull = isNull;
  4595. function isNullOrUndefined(arg) {
  4596. return arg == null;
  4597. }
  4598. exports.isNullOrUndefined = isNullOrUndefined;
  4599. function isNumber(arg) {
  4600. return typeof arg === 'number';
  4601. }
  4602. exports.isNumber = isNumber;
  4603. function isString(arg) {
  4604. return typeof arg === 'string';
  4605. }
  4606. exports.isString = isString;
  4607. function isSymbol(arg) {
  4608. return typeof arg === 'symbol';
  4609. }
  4610. exports.isSymbol = isSymbol;
  4611. function isUndefined(arg) {
  4612. return arg === void 0;
  4613. }
  4614. exports.isUndefined = isUndefined;
  4615. function isRegExp(re) {
  4616. return isObject(re) && objectToString(re) === '[object RegExp]';
  4617. }
  4618. exports.isRegExp = isRegExp;
  4619. function isObject(arg) {
  4620. return typeof arg === 'object' && arg !== null;
  4621. }
  4622. exports.isObject = isObject;
  4623. function isDate(d) {
  4624. return isObject(d) && objectToString(d) === '[object Date]';
  4625. }
  4626. exports.isDate = isDate;
  4627. function isError(e) {
  4628. return isObject(e) &&
  4629. (objectToString(e) === '[object Error]' || e instanceof Error);
  4630. }
  4631. exports.isError = isError;
  4632. function isFunction(arg) {
  4633. return typeof arg === 'function';
  4634. }
  4635. exports.isFunction = isFunction;
  4636. function isPrimitive(arg) {
  4637. return arg === null ||
  4638. typeof arg === 'boolean' ||
  4639. typeof arg === 'number' ||
  4640. typeof arg === 'string' ||
  4641. typeof arg === 'symbol' || // ES6 symbol
  4642. typeof arg === 'undefined';
  4643. }
  4644. exports.isPrimitive = isPrimitive;
  4645. exports.isBuffer = _dereq_('./support/isBuffer');
  4646. function objectToString(o) {
  4647. return Object.prototype.toString.call(o);
  4648. }
  4649. function pad(n) {
  4650. return n < 10 ? '0' + n.toString(10) : n.toString(10);
  4651. }
  4652. var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep',
  4653. 'Oct', 'Nov', 'Dec'];
  4654. // 26 Feb 16:19:34
  4655. function timestamp() {
  4656. var d = new Date();
  4657. var time = [pad(d.getHours()),
  4658. pad(d.getMinutes()),
  4659. pad(d.getSeconds())].join(':');
  4660. return [d.getDate(), months[d.getMonth()], time].join(' ');
  4661. }
  4662. // log is just a thin wrapper to console.log that prepends a timestamp
  4663. exports.log = function() {
  4664. console.log('%s - %s', timestamp(), exports.format.apply(exports, arguments));
  4665. };
  4666. /**
  4667. * Inherit the prototype methods from one constructor into another.
  4668. *
  4669. * The Function.prototype.inherits from lang.js rewritten as a standalone
  4670. * function (not on Function.prototype). NOTE: If this file is to be loaded
  4671. * during bootstrapping this function needs to be rewritten using some native
  4672. * functions as prototype setup using normal JavaScript does not work as
  4673. * expected during bootstrapping (see mirror.js in r114903).
  4674. *
  4675. * @param {function} ctor Constructor function which needs to inherit the
  4676. * prototype.
  4677. * @param {function} superCtor Constructor function to inherit prototype from.
  4678. */
  4679. exports.inherits = _dereq_('inherits');
  4680. exports._extend = function(origin, add) {
  4681. // Don't do anything if add isn't an object
  4682. if (!add || !isObject(add)) return origin;
  4683. var keys = Object.keys(add);
  4684. var i = keys.length;
  4685. while (i--) {
  4686. origin[keys[i]] = add[keys[i]];
  4687. }
  4688. return origin;
  4689. };
  4690. function hasOwnProperty(obj, prop) {
  4691. return Object.prototype.hasOwnProperty.call(obj, prop);
  4692. }
  4693. }).call(this,_dereq_('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  4694. },{"./support/isBuffer":4,"_process":3,"inherits":2}],6:[function(_dereq_,module,exports){
  4695. // A recursive descent parser operates by defining functions for all
  4696. // syntactic elements, and recursively calling those, each function
  4697. // advancing the input stream and returning an AST node. Precedence
  4698. // of constructs (for example, the fact that `!x[1]` means `!(x[1])`
  4699. // instead of `(!x)[1]` is handled by the fact that the parser
  4700. // function that parses unary prefix operators is called first, and
  4701. // in turn calls the function that parses `[]` subscripts — that
  4702. // way, it'll receive the node for `x[1]` already parsed, and wraps
  4703. // *that* in the unary operator node.
  4704. //
  4705. // Acorn uses an [operator precedence parser][opp] to handle binary
  4706. // operator precedence, because it is much more compact than using
  4707. // the technique outlined above, which uses different, nesting
  4708. // functions to specify precedence, for all of the ten binary
  4709. // precedence levels that JavaScript defines.
  4710. //
  4711. // [opp]: http://en.wikipedia.org/wiki/Operator-precedence_parser
  4712. "use strict";
  4713. var tt = _dereq_("./tokentype").types;
  4714. var Parser = _dereq_("./state").Parser;
  4715. var reservedWords = _dereq_("./identifier").reservedWords;
  4716. var has = _dereq_("./util").has;
  4717. var pp = Parser.prototype;
  4718. // Check if property name clashes with already added.
  4719. // Object/class getters and setters are not allowed to clash —
  4720. // either with each other or with an init property — and in
  4721. // strict mode, init properties are also not allowed to be repeated.
  4722. pp.checkPropClash = function (prop, propHash) {
  4723. if (this.options.ecmaVersion >= 6) return;
  4724. var key = prop.key,
  4725. name = undefined;
  4726. switch (key.type) {
  4727. case "Identifier":
  4728. name = key.name;break;
  4729. case "Literal":
  4730. name = String(key.value);break;
  4731. default:
  4732. return;
  4733. }
  4734. var kind = prop.kind || "init",
  4735. other = undefined;
  4736. if (has(propHash, name)) {
  4737. other = propHash[name];
  4738. var isGetSet = kind !== "init";
  4739. if ((this.strict || isGetSet) && other[kind] || !(isGetSet ^ other.init)) this.raise(key.start, "Redefinition of property");
  4740. } else {
  4741. other = propHash[name] = {
  4742. init: false,
  4743. get: false,
  4744. set: false
  4745. };
  4746. }
  4747. other[kind] = true;
  4748. };
  4749. // ### Expression parsing
  4750. // These nest, from the most general expression type at the top to
  4751. // 'atomic', nondivisible expression types at the bottom. Most of
  4752. // the functions will simply let the function(s) below them parse,
  4753. // and, *if* the syntactic construct they handle is present, wrap
  4754. // the AST node that the inner parser gave them in another node.
  4755. // Parse a full expression. The optional arguments are used to
  4756. // forbid the `in` operator (in for loops initalization expressions)
  4757. // and provide reference for storing '=' operator inside shorthand
  4758. // property assignment in contexts where both object expression
  4759. // and object pattern might appear (so it's possible to raise
  4760. // delayed syntax error at correct position).
  4761. pp.parseExpression = function (noIn, refShorthandDefaultPos) {
  4762. var startPos = this.start,
  4763. startLoc = this.startLoc;
  4764. var expr = this.parseMaybeAssign(noIn, refShorthandDefaultPos);
  4765. if (this.type === tt.comma) {
  4766. var node = this.startNodeAt(startPos, startLoc);
  4767. node.expressions = [expr];
  4768. while (this.eat(tt.comma)) node.expressions.push(this.parseMaybeAssign(noIn, refShorthandDefaultPos));
  4769. return this.finishNode(node, "SequenceExpression");
  4770. }
  4771. return expr;
  4772. };
  4773. // Parse an assignment expression. This includes applications of
  4774. // operators like `+=`.
  4775. pp.parseMaybeAssign = function (noIn, refShorthandDefaultPos, afterLeftParse) {
  4776. if (this.type == tt._yield && this.inGenerator) return this.parseYield();
  4777. var failOnShorthandAssign = undefined;
  4778. if (!refShorthandDefaultPos) {
  4779. refShorthandDefaultPos = { start: 0 };
  4780. failOnShorthandAssign = true;
  4781. } else {
  4782. failOnShorthandAssign = false;
  4783. }
  4784. var startPos = this.start,
  4785. startLoc = this.startLoc;
  4786. if (this.type == tt.parenL || this.type == tt.name) this.potentialArrowAt = this.start;
  4787. var left = this.parseMaybeConditional(noIn, refShorthandDefaultPos);
  4788. if (afterLeftParse) left = afterLeftParse.call(this, left, startPos, startLoc);
  4789. if (this.type.isAssign) {
  4790. var node = this.startNodeAt(startPos, startLoc);
  4791. node.operator = this.value;
  4792. node.left = this.type === tt.eq ? this.toAssignable(left) : left;
  4793. refShorthandDefaultPos.start = 0; // reset because shorthand default was used correctly
  4794. this.checkLVal(left);
  4795. this.next();
  4796. node.right = this.parseMaybeAssign(noIn);
  4797. return this.finishNode(node, "AssignmentExpression");
  4798. } else if (failOnShorthandAssign && refShorthandDefaultPos.start) {
  4799. this.unexpected(refShorthandDefaultPos.start);
  4800. }
  4801. return left;
  4802. };
  4803. // Parse a ternary conditional (`?:`) operator.
  4804. pp.parseMaybeConditional = function (noIn, refShorthandDefaultPos) {
  4805. var startPos = this.start,
  4806. startLoc = this.startLoc;
  4807. var expr = this.parseExprOps(noIn, refShorthandDefaultPos);
  4808. if (refShorthandDefaultPos && refShorthandDefaultPos.start) return expr;
  4809. if (this.eat(tt.question)) {
  4810. var node = this.startNodeAt(startPos, startLoc);
  4811. node.test = expr;
  4812. node.consequent = this.parseMaybeAssign();
  4813. this.expect(tt.colon);
  4814. node.alternate = this.parseMaybeAssign(noIn);
  4815. return this.finishNode(node, "ConditionalExpression");
  4816. }
  4817. return expr;
  4818. };
  4819. // Start the precedence parser.
  4820. pp.parseExprOps = function (noIn, refShorthandDefaultPos) {
  4821. var startPos = this.start,
  4822. startLoc = this.startLoc;
  4823. var expr = this.parseMaybeUnary(refShorthandDefaultPos);
  4824. if (refShorthandDefaultPos && refShorthandDefaultPos.start) return expr;
  4825. return this.parseExprOp(expr, startPos, startLoc, -1, noIn);
  4826. };
  4827. // Parse binary operators with the operator precedence parsing
  4828. // algorithm. `left` is the left-hand side of the operator.
  4829. // `minPrec` provides context that allows the function to stop and
  4830. // defer further parser to one of its callers when it encounters an
  4831. // operator that has a lower precedence than the set it is parsing.
  4832. pp.parseExprOp = function (left, leftStartPos, leftStartLoc, minPrec, noIn) {
  4833. var prec = this.type.binop;
  4834. if (Array.isArray(leftStartPos)) {
  4835. if (this.options.locations && noIn === undefined) {
  4836. // shift arguments to left by one
  4837. noIn = minPrec;
  4838. minPrec = leftStartLoc;
  4839. // flatten leftStartPos
  4840. leftStartLoc = leftStartPos[1];
  4841. leftStartPos = leftStartPos[0];
  4842. }
  4843. }
  4844. if (prec != null && (!noIn || this.type !== tt._in)) {
  4845. if (prec > minPrec) {
  4846. var node = this.startNodeAt(leftStartPos, leftStartLoc);
  4847. node.left = left;
  4848. node.operator = this.value;
  4849. var op = this.type;
  4850. this.next();
  4851. var startPos = this.start,
  4852. startLoc = this.startLoc;
  4853. node.right = this.parseExprOp(this.parseMaybeUnary(), startPos, startLoc, prec, noIn);
  4854. this.finishNode(node, op === tt.logicalOR || op === tt.logicalAND ? "LogicalExpression" : "BinaryExpression");
  4855. return this.parseExprOp(node, leftStartPos, leftStartLoc, minPrec, noIn);
  4856. }
  4857. }
  4858. return left;
  4859. };
  4860. // Parse unary operators, both prefix and postfix.
  4861. pp.parseMaybeUnary = function (refShorthandDefaultPos) {
  4862. if (this.type.prefix) {
  4863. var node = this.startNode(),
  4864. update = this.type === tt.incDec;
  4865. node.operator = this.value;
  4866. node.prefix = true;
  4867. this.next();
  4868. node.argument = this.parseMaybeUnary();
  4869. if (refShorthandDefaultPos && refShorthandDefaultPos.start) this.unexpected(refShorthandDefaultPos.start);
  4870. if (update) this.checkLVal(node.argument);else if (this.strict && node.operator === "delete" && node.argument.type === "Identifier") this.raise(node.start, "Deleting local variable in strict mode");
  4871. return this.finishNode(node, update ? "UpdateExpression" : "UnaryExpression");
  4872. }
  4873. var startPos = this.start,
  4874. startLoc = this.startLoc;
  4875. var expr = this.parseExprSubscripts(refShorthandDefaultPos);
  4876. if (refShorthandDefaultPos && refShorthandDefaultPos.start) return expr;
  4877. while (this.type.postfix && !this.canInsertSemicolon()) {
  4878. var node = this.startNodeAt(startPos, startLoc);
  4879. node.operator = this.value;
  4880. node.prefix = false;
  4881. node.argument = expr;
  4882. this.checkLVal(expr);
  4883. this.next();
  4884. expr = this.finishNode(node, "UpdateExpression");
  4885. }
  4886. return expr;
  4887. };
  4888. // Parse call, dot, and `[]`-subscript expressions.
  4889. pp.parseExprSubscripts = function (refShorthandDefaultPos) {
  4890. var startPos = this.start,
  4891. startLoc = this.startLoc;
  4892. var expr = this.parseExprAtom(refShorthandDefaultPos);
  4893. if (refShorthandDefaultPos && refShorthandDefaultPos.start) return expr;
  4894. return this.parseSubscripts(expr, startPos, startLoc);
  4895. };
  4896. pp.parseSubscripts = function (base, startPos, startLoc, noCalls) {
  4897. if (Array.isArray(startPos)) {
  4898. if (this.options.locations && noCalls === undefined) {
  4899. // shift arguments to left by one
  4900. noCalls = startLoc;
  4901. // flatten startPos
  4902. startLoc = startPos[1];
  4903. startPos = startPos[0];
  4904. }
  4905. }
  4906. for (;;) {
  4907. if (this.eat(tt.dot)) {
  4908. var node = this.startNodeAt(startPos, startLoc);
  4909. node.object = base;
  4910. node.property = this.parseIdent(true);
  4911. node.computed = false;
  4912. base = this.finishNode(node, "MemberExpression");
  4913. } else if (this.eat(tt.bracketL)) {
  4914. var node = this.startNodeAt(startPos, startLoc);
  4915. node.object = base;
  4916. node.property = this.parseExpression();
  4917. node.computed = true;
  4918. this.expect(tt.bracketR);
  4919. base = this.finishNode(node, "MemberExpression");
  4920. } else if (!noCalls && this.eat(tt.parenL)) {
  4921. var node = this.startNodeAt(startPos, startLoc);
  4922. node.callee = base;
  4923. node.arguments = this.parseExprList(tt.parenR, false);
  4924. base = this.finishNode(node, "CallExpression");
  4925. } else if (this.type === tt.backQuote) {
  4926. var node = this.startNodeAt(startPos, startLoc);
  4927. node.tag = base;
  4928. node.quasi = this.parseTemplate();
  4929. base = this.finishNode(node, "TaggedTemplateExpression");
  4930. } else {
  4931. return base;
  4932. }
  4933. }
  4934. };
  4935. // Parse an atomic expression — either a single token that is an
  4936. // expression, an expression started by a keyword like `function` or
  4937. // `new`, or an expression wrapped in punctuation like `()`, `[]`,
  4938. // or `{}`.
  4939. pp.parseExprAtom = function (refShorthandDefaultPos) {
  4940. var node = undefined,
  4941. canBeArrow = this.potentialArrowAt == this.start;
  4942. switch (this.type) {
  4943. case tt._this:
  4944. case tt._super:
  4945. var type = this.type === tt._this ? "ThisExpression" : "Super";
  4946. node = this.startNode();
  4947. this.next();
  4948. return this.finishNode(node, type);
  4949. case tt._yield:
  4950. if (this.inGenerator) this.unexpected();
  4951. case tt.name:
  4952. var startPos = this.start,
  4953. startLoc = this.startLoc;
  4954. var id = this.parseIdent(this.type !== tt.name);
  4955. if (canBeArrow && !this.canInsertSemicolon() && this.eat(tt.arrow)) return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), [id]);
  4956. return id;
  4957. case tt.regexp:
  4958. var value = this.value;
  4959. node = this.parseLiteral(value.value);
  4960. node.regex = { pattern: value.pattern, flags: value.flags };
  4961. return node;
  4962. case tt.num:case tt.string:
  4963. return this.parseLiteral(this.value);
  4964. case tt._null:case tt._true:case tt._false:
  4965. node = this.startNode();
  4966. node.value = this.type === tt._null ? null : this.type === tt._true;
  4967. node.raw = this.type.keyword;
  4968. this.next();
  4969. return this.finishNode(node, "Literal");
  4970. case tt.parenL:
  4971. return this.parseParenAndDistinguishExpression(canBeArrow);
  4972. case tt.bracketL:
  4973. node = this.startNode();
  4974. this.next();
  4975. // check whether this is array comprehension or regular array
  4976. if (this.options.ecmaVersion >= 7 && this.type === tt._for) {
  4977. return this.parseComprehension(node, false);
  4978. }
  4979. node.elements = this.parseExprList(tt.bracketR, true, true, refShorthandDefaultPos);
  4980. return this.finishNode(node, "ArrayExpression");
  4981. case tt.braceL:
  4982. return this.parseObj(false, refShorthandDefaultPos);
  4983. case tt._function:
  4984. node = this.startNode();
  4985. this.next();
  4986. return this.parseFunction(node, false);
  4987. case tt._class:
  4988. return this.parseClass(this.startNode(), false);
  4989. case tt._new:
  4990. return this.parseNew();
  4991. case tt.backQuote:
  4992. return this.parseTemplate();
  4993. default:
  4994. this.unexpected();
  4995. }
  4996. };
  4997. pp.parseLiteral = function (value) {
  4998. var node = this.startNode();
  4999. node.value = value;
  5000. node.raw = this.input.slice(this.start, this.end);
  5001. this.next();
  5002. return this.finishNode(node, "Literal");
  5003. };
  5004. pp.parseParenExpression = function () {
  5005. this.expect(tt.parenL);
  5006. var val = this.parseExpression();
  5007. this.expect(tt.parenR);
  5008. return val;
  5009. };
  5010. pp.parseParenAndDistinguishExpression = function (canBeArrow) {
  5011. var startPos = this.start,
  5012. startLoc = this.startLoc,
  5013. val = undefined;
  5014. if (this.options.ecmaVersion >= 6) {
  5015. this.next();
  5016. if (this.options.ecmaVersion >= 7 && this.type === tt._for) {
  5017. return this.parseComprehension(this.startNodeAt(startPos, startLoc), true);
  5018. }
  5019. var innerStartPos = this.start,
  5020. innerStartLoc = this.startLoc;
  5021. var exprList = [],
  5022. first = true;
  5023. var refShorthandDefaultPos = { start: 0 },
  5024. spreadStart = undefined,
  5025. innerParenStart = undefined;
  5026. while (this.type !== tt.parenR) {
  5027. first ? first = false : this.expect(tt.comma);
  5028. if (this.type === tt.ellipsis) {
  5029. spreadStart = this.start;
  5030. exprList.push(this.parseParenItem(this.parseRest()));
  5031. break;
  5032. } else {
  5033. if (this.type === tt.parenL && !innerParenStart) {
  5034. innerParenStart = this.start;
  5035. }
  5036. exprList.push(this.parseMaybeAssign(false, refShorthandDefaultPos, this.parseParenItem));
  5037. }
  5038. }
  5039. var innerEndPos = this.start,
  5040. innerEndLoc = this.startLoc;
  5041. this.expect(tt.parenR);
  5042. if (canBeArrow && !this.canInsertSemicolon() && this.eat(tt.arrow)) {
  5043. if (innerParenStart) this.unexpected(innerParenStart);
  5044. return this.parseParenArrowList(startPos, startLoc, exprList);
  5045. }
  5046. if (!exprList.length) this.unexpected(this.lastTokStart);
  5047. if (spreadStart) this.unexpected(spreadStart);
  5048. if (refShorthandDefaultPos.start) this.unexpected(refShorthandDefaultPos.start);
  5049. if (exprList.length > 1) {
  5050. val = this.startNodeAt(innerStartPos, innerStartLoc);
  5051. val.expressions = exprList;
  5052. this.finishNodeAt(val, "SequenceExpression", innerEndPos, innerEndLoc);
  5053. } else {
  5054. val = exprList[0];
  5055. }
  5056. } else {
  5057. val = this.parseParenExpression();
  5058. }
  5059. if (this.options.preserveParens) {
  5060. var par = this.startNodeAt(startPos, startLoc);
  5061. par.expression = val;
  5062. return this.finishNode(par, "ParenthesizedExpression");
  5063. } else {
  5064. return val;
  5065. }
  5066. };
  5067. pp.parseParenItem = function (item) {
  5068. return item;
  5069. };
  5070. pp.parseParenArrowList = function (startPos, startLoc, exprList) {
  5071. return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), exprList);
  5072. };
  5073. // New's precedence is slightly tricky. It must allow its argument
  5074. // to be a `[]` or dot subscript expression, but not a call — at
  5075. // least, not without wrapping it in parentheses. Thus, it uses the
  5076. var empty = [];
  5077. pp.parseNew = function () {
  5078. var node = this.startNode();
  5079. var meta = this.parseIdent(true);
  5080. if (this.options.ecmaVersion >= 6 && this.eat(tt.dot)) {
  5081. node.meta = meta;
  5082. node.property = this.parseIdent(true);
  5083. if (node.property.name !== "target") this.raise(node.property.start, "The only valid meta property for new is new.target");
  5084. return this.finishNode(node, "MetaProperty");
  5085. }
  5086. var startPos = this.start,
  5087. startLoc = this.startLoc;
  5088. node.callee = this.parseSubscripts(this.parseExprAtom(), startPos, startLoc, true);
  5089. if (this.eat(tt.parenL)) node.arguments = this.parseExprList(tt.parenR, false);else node.arguments = empty;
  5090. return this.finishNode(node, "NewExpression");
  5091. };
  5092. // Parse template expression.
  5093. pp.parseTemplateElement = function () {
  5094. var elem = this.startNode();
  5095. elem.value = {
  5096. raw: this.input.slice(this.start, this.end),
  5097. cooked: this.value
  5098. };
  5099. this.next();
  5100. elem.tail = this.type === tt.backQuote;
  5101. return this.finishNode(elem, "TemplateElement");
  5102. };
  5103. pp.parseTemplate = function () {
  5104. var node = this.startNode();
  5105. this.next();
  5106. node.expressions = [];
  5107. var curElt = this.parseTemplateElement();
  5108. node.quasis = [curElt];
  5109. while (!curElt.tail) {
  5110. this.expect(tt.dollarBraceL);
  5111. node.expressions.push(this.parseExpression());
  5112. this.expect(tt.braceR);
  5113. node.quasis.push(curElt = this.parseTemplateElement());
  5114. }
  5115. this.next();
  5116. return this.finishNode(node, "TemplateLiteral");
  5117. };
  5118. // Parse an object literal or binding pattern.
  5119. pp.parseObj = function (isPattern, refShorthandDefaultPos) {
  5120. var node = this.startNode(),
  5121. first = true,
  5122. propHash = {};
  5123. node.properties = [];
  5124. this.next();
  5125. while (!this.eat(tt.braceR)) {
  5126. if (!first) {
  5127. this.expect(tt.comma);
  5128. if (this.afterTrailingComma(tt.braceR)) break;
  5129. } else first = false;
  5130. var prop = this.startNode(),
  5131. isGenerator = undefined,
  5132. startPos = undefined,
  5133. startLoc = undefined;
  5134. if (this.options.ecmaVersion >= 6) {
  5135. prop.method = false;
  5136. prop.shorthand = false;
  5137. if (isPattern || refShorthandDefaultPos) {
  5138. startPos = this.start;
  5139. startLoc = this.startLoc;
  5140. }
  5141. if (!isPattern) isGenerator = this.eat(tt.star);
  5142. }
  5143. this.parsePropertyName(prop);
  5144. this.parsePropertyValue(prop, isPattern, isGenerator, startPos, startLoc, refShorthandDefaultPos);
  5145. this.checkPropClash(prop, propHash);
  5146. node.properties.push(this.finishNode(prop, "Property"));
  5147. }
  5148. return this.finishNode(node, isPattern ? "ObjectPattern" : "ObjectExpression");
  5149. };
  5150. pp.parsePropertyValue = function (prop, isPattern, isGenerator, startPos, startLoc, refShorthandDefaultPos) {
  5151. if (this.eat(tt.colon)) {
  5152. prop.value = isPattern ? this.parseMaybeDefault(this.start, this.startLoc) : this.parseMaybeAssign(false, refShorthandDefaultPos);
  5153. prop.kind = "init";
  5154. } else if (this.options.ecmaVersion >= 6 && this.type === tt.parenL) {
  5155. if (isPattern) this.unexpected();
  5156. prop.kind = "init";
  5157. prop.method = true;
  5158. prop.value = this.parseMethod(isGenerator);
  5159. } else if (this.options.ecmaVersion >= 5 && !prop.computed && prop.key.type === "Identifier" && (prop.key.name === "get" || prop.key.name === "set") && (this.type != tt.comma && this.type != tt.braceR)) {
  5160. if (isGenerator || isPattern) this.unexpected();
  5161. prop.kind = prop.key.name;
  5162. this.parsePropertyName(prop);
  5163. prop.value = this.parseMethod(false);
  5164. } else if (this.options.ecmaVersion >= 6 && !prop.computed && prop.key.type === "Identifier") {
  5165. prop.kind = "init";
  5166. if (isPattern) {
  5167. if (this.isKeyword(prop.key.name) || this.strict && (reservedWords.strictBind(prop.key.name) || reservedWords.strict(prop.key.name)) || !this.options.allowReserved && this.isReservedWord(prop.key.name)) this.raise(prop.key.start, "Binding " + prop.key.name);
  5168. prop.value = this.parseMaybeDefault(startPos, startLoc, prop.key);
  5169. } else if (this.type === tt.eq && refShorthandDefaultPos) {
  5170. if (!refShorthandDefaultPos.start) refShorthandDefaultPos.start = this.start;
  5171. prop.value = this.parseMaybeDefault(startPos, startLoc, prop.key);
  5172. } else {
  5173. prop.value = prop.key;
  5174. }
  5175. prop.shorthand = true;
  5176. } else this.unexpected();
  5177. };
  5178. pp.parsePropertyName = function (prop) {
  5179. if (this.options.ecmaVersion >= 6) {
  5180. if (this.eat(tt.bracketL)) {
  5181. prop.computed = true;
  5182. prop.key = this.parseMaybeAssign();
  5183. this.expect(tt.bracketR);
  5184. return prop.key;
  5185. } else {
  5186. prop.computed = false;
  5187. }
  5188. }
  5189. return prop.key = this.type === tt.num || this.type === tt.string ? this.parseExprAtom() : this.parseIdent(true);
  5190. };
  5191. // Initialize empty function node.
  5192. pp.initFunction = function (node) {
  5193. node.id = null;
  5194. if (this.options.ecmaVersion >= 6) {
  5195. node.generator = false;
  5196. node.expression = false;
  5197. }
  5198. };
  5199. // Parse object or class method.
  5200. pp.parseMethod = function (isGenerator) {
  5201. var node = this.startNode();
  5202. this.initFunction(node);
  5203. this.expect(tt.parenL);
  5204. node.params = this.parseBindingList(tt.parenR, false, false);
  5205. var allowExpressionBody = undefined;
  5206. if (this.options.ecmaVersion >= 6) {
  5207. node.generator = isGenerator;
  5208. allowExpressionBody = true;
  5209. } else {
  5210. allowExpressionBody = false;
  5211. }
  5212. this.parseFunctionBody(node, allowExpressionBody);
  5213. return this.finishNode(node, "FunctionExpression");
  5214. };
  5215. // Parse arrow function expression with given parameters.
  5216. pp.parseArrowExpression = function (node, params) {
  5217. this.initFunction(node);
  5218. node.params = this.toAssignableList(params, true);
  5219. this.parseFunctionBody(node, true);
  5220. return this.finishNode(node, "ArrowFunctionExpression");
  5221. };
  5222. // Parse function body and check parameters.
  5223. pp.parseFunctionBody = function (node, allowExpression) {
  5224. var isExpression = allowExpression && this.type !== tt.braceL;
  5225. if (isExpression) {
  5226. node.body = this.parseMaybeAssign();
  5227. node.expression = true;
  5228. } else {
  5229. // Start a new scope with regard to labels and the `inFunction`
  5230. // flag (restore them to their old value afterwards).
  5231. var oldInFunc = this.inFunction,
  5232. oldInGen = this.inGenerator,
  5233. oldLabels = this.labels;
  5234. this.inFunction = true;this.inGenerator = node.generator;this.labels = [];
  5235. node.body = this.parseBlock(true);
  5236. node.expression = false;
  5237. this.inFunction = oldInFunc;this.inGenerator = oldInGen;this.labels = oldLabels;
  5238. }
  5239. // If this is a strict mode function, verify that argument names
  5240. // are not repeated, and it does not try to bind the words `eval`
  5241. // or `arguments`.
  5242. if (this.strict || !isExpression && node.body.body.length && this.isUseStrict(node.body.body[0])) {
  5243. var nameHash = {},
  5244. oldStrict = this.strict;
  5245. this.strict = true;
  5246. if (node.id) this.checkLVal(node.id, true);
  5247. for (var i = 0; i < node.params.length; i++) {
  5248. this.checkLVal(node.params[i], true, nameHash);
  5249. }this.strict = oldStrict;
  5250. }
  5251. };
  5252. // Parses a comma-separated list of expressions, and returns them as
  5253. // an array. `close` is the token type that ends the list, and
  5254. // `allowEmpty` can be turned on to allow subsequent commas with
  5255. // nothing in between them to be parsed as `null` (which is needed
  5256. // for array literals).
  5257. pp.parseExprList = function (close, allowTrailingComma, allowEmpty, refShorthandDefaultPos) {
  5258. var elts = [],
  5259. first = true;
  5260. while (!this.eat(close)) {
  5261. if (!first) {
  5262. this.expect(tt.comma);
  5263. if (allowTrailingComma && this.afterTrailingComma(close)) break;
  5264. } else first = false;
  5265. if (allowEmpty && this.type === tt.comma) {
  5266. elts.push(null);
  5267. } else {
  5268. if (this.type === tt.ellipsis) elts.push(this.parseSpread(refShorthandDefaultPos));else elts.push(this.parseMaybeAssign(false, refShorthandDefaultPos));
  5269. }
  5270. }
  5271. return elts;
  5272. };
  5273. // Parse the next token as an identifier. If `liberal` is true (used
  5274. // when parsing properties), it will also convert keywords into
  5275. // identifiers.
  5276. pp.parseIdent = function (liberal) {
  5277. var node = this.startNode();
  5278. if (liberal && this.options.allowReserved == "never") liberal = false;
  5279. if (this.type === tt.name) {
  5280. if (!liberal && (!this.options.allowReserved && this.isReservedWord(this.value) || this.strict && reservedWords.strict(this.value) && (this.options.ecmaVersion >= 6 || this.input.slice(this.start, this.end).indexOf("\\") == -1))) this.raise(this.start, "The keyword '" + this.value + "' is reserved");
  5281. node.name = this.value;
  5282. } else if (liberal && this.type.keyword) {
  5283. node.name = this.type.keyword;
  5284. } else {
  5285. this.unexpected();
  5286. }
  5287. this.next();
  5288. return this.finishNode(node, "Identifier");
  5289. };
  5290. // Parses yield expression inside generator.
  5291. pp.parseYield = function () {
  5292. var node = this.startNode();
  5293. this.next();
  5294. if (this.type == tt.semi || this.canInsertSemicolon() || this.type != tt.star && !this.type.startsExpr) {
  5295. node.delegate = false;
  5296. node.argument = null;
  5297. } else {
  5298. node.delegate = this.eat(tt.star);
  5299. node.argument = this.parseMaybeAssign();
  5300. }
  5301. return this.finishNode(node, "YieldExpression");
  5302. };
  5303. // Parses array and generator comprehensions.
  5304. pp.parseComprehension = function (node, isGenerator) {
  5305. node.blocks = [];
  5306. while (this.type === tt._for) {
  5307. var block = this.startNode();
  5308. this.next();
  5309. this.expect(tt.parenL);
  5310. block.left = this.parseBindingAtom();
  5311. this.checkLVal(block.left, true);
  5312. this.expectContextual("of");
  5313. block.right = this.parseExpression();
  5314. this.expect(tt.parenR);
  5315. node.blocks.push(this.finishNode(block, "ComprehensionBlock"));
  5316. }
  5317. node.filter = this.eat(tt._if) ? this.parseParenExpression() : null;
  5318. node.body = this.parseExpression();
  5319. this.expect(isGenerator ? tt.parenR : tt.bracketR);
  5320. node.generator = isGenerator;
  5321. return this.finishNode(node, "ComprehensionExpression");
  5322. };
  5323. },{"./identifier":7,"./state":13,"./tokentype":17,"./util":18}],7:[function(_dereq_,module,exports){
  5324. // Test whether a given character code starts an identifier.
  5325. "use strict";
  5326. exports.isIdentifierStart = isIdentifierStart;
  5327. // Test whether a given character is part of an identifier.
  5328. exports.isIdentifierChar = isIdentifierChar;
  5329. exports.__esModule = true;
  5330. // This is a trick taken from Esprima. It turns out that, on
  5331. // non-Chrome browsers, to check whether a string is in a set, a
  5332. // predicate containing a big ugly `switch` statement is faster than
  5333. // a regular expression, and on Chrome the two are about on par.
  5334. // This function uses `eval` (non-lexical) to produce such a
  5335. // predicate from a space-separated string of words.
  5336. //
  5337. // It starts by sorting the words by length.
  5338. function makePredicate(words) {
  5339. words = words.split(" ");
  5340. var f = "",
  5341. cats = [];
  5342. out: for (var i = 0; i < words.length; ++i) {
  5343. for (var j = 0; j < cats.length; ++j) {
  5344. if (cats[j][0].length == words[i].length) {
  5345. cats[j].push(words[i]);
  5346. continue out;
  5347. }
  5348. }cats.push([words[i]]);
  5349. }
  5350. function compareTo(arr) {
  5351. if (arr.length == 1) {
  5352. return f += "return str === " + JSON.stringify(arr[0]) + ";";
  5353. }f += "switch(str){";
  5354. for (var i = 0; i < arr.length; ++i) {
  5355. f += "case " + JSON.stringify(arr[i]) + ":";
  5356. }f += "return true}return false;";
  5357. }
  5358. // When there are more than three length categories, an outer
  5359. // switch first dispatches on the lengths, to save on comparisons.
  5360. if (cats.length > 3) {
  5361. cats.sort(function (a, b) {
  5362. return b.length - a.length;
  5363. });
  5364. f += "switch(str.length){";
  5365. for (var i = 0; i < cats.length; ++i) {
  5366. var cat = cats[i];
  5367. f += "case " + cat[0].length + ":";
  5368. compareTo(cat);
  5369. }
  5370. f += "}"
  5371. // Otherwise, simply generate a flat `switch` statement.
  5372. ;
  5373. } else {
  5374. compareTo(words);
  5375. }
  5376. return new Function("str", f);
  5377. }
  5378. // Reserved word lists for various dialects of the language
  5379. var reservedWords = {
  5380. 3: makePredicate("abstract boolean byte char class double enum export extends final float goto implements import int interface long native package private protected public short static super synchronized throws transient volatile"),
  5381. 5: makePredicate("class enum extends super const export import"),
  5382. 6: makePredicate("enum await"),
  5383. strict: makePredicate("implements interface let package private protected public static yield"),
  5384. strictBind: makePredicate("eval arguments")
  5385. };
  5386. exports.reservedWords = reservedWords;
  5387. // And the keywords
  5388. var ecma5AndLessKeywords = "break case catch continue debugger default do else finally for function if return switch throw try var while with null true false instanceof typeof void delete new in this";
  5389. var keywords = {
  5390. 5: makePredicate(ecma5AndLessKeywords),
  5391. 6: makePredicate(ecma5AndLessKeywords + " let const class extends export import yield super")
  5392. };
  5393. exports.keywords = keywords;
  5394. // ## Character categories
  5395. // Big ugly regular expressions that match characters in the
  5396. // whitespace, identifier, and identifier-start categories. These
  5397. // are only applied when a character is found to actually have a
  5398. // code point above 128.
  5399. // Generated by `tools/generate-identifier-regex.js`.
  5400. var nonASCIIidentifierStartChars = "ªµºÀ-ÖØ-öø-ˁˆ-ˑˠ-ˤˬˮͰ-ʹͶͷͺ-ͽͿΆΈ-ΊΌΎ-ΡΣ-ϵϷ-ҁҊ-ԯԱ-Ֆՙա-ևא-תװ-ײؠ-يٮٯٱ-ۓەۥۦۮۯۺ-ۼۿܐܒ-ܯݍ-ޥޱߊ-ߪߴߵߺࠀ-ࠕࠚࠤࠨࡀ-ࡘࢠ-ࢲऄ-हऽॐक़-ॡॱ-ঀঅ-ঌএঐও-নপ-রলশ-হঽৎড়ঢ়য়-ৡৰৱਅ-ਊਏਐਓ-ਨਪ-ਰਲਲ਼ਵਸ਼ਸਹਖ਼-ੜਫ਼ੲ-ੴઅ-ઍએ-ઑઓ-નપ-રલળવ-હઽૐૠૡଅ-ଌଏଐଓ-ନପ-ରଲଳଵ-ହଽଡ଼ଢ଼ୟ-ୡୱஃஅ-ஊஎ-ஐஒ-கஙசஜஞடணதந-பம-ஹௐఅ-ఌఎ-ఐఒ-నప-హఽౘౙౠౡಅ-ಌಎ-ಐಒ-ನಪ-ಳವ-ಹಽೞೠೡೱೲഅ-ഌഎ-ഐഒ-ഺഽൎൠൡൺ-ൿඅ-ඖක-නඳ-රලව-ෆก-ะาำเ-ๆກຂຄງຈຊຍດ-ທນ-ຟມ-ຣລວສຫອ-ະາຳຽເ-ໄໆໜ-ໟༀཀ-ཇཉ-ཬྈ-ྌက-ဪဿၐ-ၕၚ-ၝၡၥၦၮ-ၰၵ-ႁႎႠ-ჅჇჍა-ჺჼ-ቈቊ-ቍቐ-ቖቘቚ-ቝበ-ኈኊ-ኍነ-ኰኲ-ኵኸ-ኾዀዂ-ዅወ-ዖዘ-ጐጒ-ጕጘ-ፚᎀ-ᎏᎠ-Ᏼᐁ-ᙬᙯ-ᙿᚁ-ᚚᚠ-ᛪᛮ-ᛸᜀ-ᜌᜎ-ᜑᜠ-ᜱᝀ-ᝑᝠ-ᝬᝮ-ᝰក-ឳៗៜᠠ-ᡷᢀ-ᢨᢪᢰ-ᣵᤀ-ᤞᥐ-ᥭᥰ-ᥴᦀ-ᦫᧁ-ᧇᨀ-ᨖᨠ-ᩔᪧᬅ-ᬳᭅ-ᭋᮃ-ᮠᮮᮯᮺ-ᯥᰀ-ᰣᱍ-ᱏᱚ-ᱽᳩ-ᳬᳮ-ᳱᳵᳶᴀ-ᶿḀ-ἕἘ-Ἕἠ-ὅὈ-Ὅὐ-ὗὙὛὝὟ-ώᾀ-ᾴᾶ-ᾼιῂ-ῄῆ-ῌῐ-ΐῖ-Ίῠ-Ῥῲ-ῴῶ-ῼⁱⁿₐ-ₜℂℇℊ-ℓℕ℘-ℝℤΩℨK-ℹℼ-ℿⅅ-ⅉⅎⅠ-ↈⰀ-Ⱞⰰ-ⱞⱠ-ⳤⳫ-ⳮⳲⳳⴀ-ⴥⴧⴭⴰ-ⵧⵯⶀ-ⶖⶠ-ⶦⶨ-ⶮⶰ-ⶶⶸ-ⶾⷀ-ⷆⷈ-ⷎⷐ-ⷖⷘ-ⷞ々-〇〡-〩〱-〵〸-〼ぁ-ゖ゛-ゟァ-ヺー-ヿㄅ-ㄭㄱ-ㆎㆠ-ㆺㇰ-ㇿ㐀-䶵一-鿌ꀀ-ꒌꓐ-ꓽꔀ-ꘌꘐ-ꘟꘪꘫꙀ-ꙮꙿ-ꚝꚠ-ꛯꜗ-ꜟꜢ-ꞈꞋ-ꞎꞐ-ꞭꞰꞱꟷ-ꠁꠃ-ꠅꠇ-ꠊꠌ-ꠢꡀ-ꡳꢂ-ꢳꣲ-ꣷꣻꤊ-ꤥꤰ-ꥆꥠ-ꥼꦄ-ꦲꧏꧠ-ꧤꧦ-ꧯꧺ-ꧾꨀ-ꨨꩀ-ꩂꩄ-ꩋꩠ-ꩶꩺꩾ-ꪯꪱꪵꪶꪹ-ꪽꫀꫂꫛ-ꫝꫠ-ꫪꫲ-ꫴꬁ-ꬆꬉ-ꬎꬑ-ꬖꬠ-ꬦꬨ-ꬮꬰ-ꭚꭜ-ꭟꭤꭥꯀ-ꯢ가-힣ힰ-ퟆퟋ-ퟻ豈-舘並-龎ff-stﬓ-ﬗיִײַ-ﬨשׁ-זּטּ-לּמּנּסּףּפּצּ-ﮱﯓ-ﴽﵐ-ﶏﶒ-ﷇﷰ-ﷻﹰ-ﹴﹶ-ﻼA-Za-zヲ-하-ᅦᅧ-ᅬᅭ-ᅲᅳ-ᅵ";
  5401. var nonASCIIidentifierChars = "‌‍·̀-ͯ·҃-֑҇-ׇֽֿׁׂׅׄؐ-ًؚ-٩ٰۖ-ۜ۟-۪ۤۧۨ-ۭ۰-۹ܑܰ-݊ަ-ް߀-߉߫-߳ࠖ-࠙ࠛ-ࠣࠥ-ࠧࠩ-࡙࠭-࡛ࣤ-ःऺ-़ा-ॏ॑-ॗॢॣ०-९ঁ-ঃ়া-ৄেৈো-্ৗৢৣ০-৯ਁ-ਃ਼ਾ-ੂੇੈੋ-੍ੑ੦-ੱੵઁ-ઃ઼ા-ૅે-ૉો-્ૢૣ૦-૯ଁ-ଃ଼ା-ୄେୈୋ-୍ୖୗୢୣ୦-୯ஂா-ூெ-ைொ-்ௗ௦-௯ఀ-ఃా-ౄె-ైొ-్ౕౖౢౣ౦-౯ಁ-ಃ಼ಾ-ೄೆ-ೈೊ-್ೕೖೢೣ೦-೯ഁ-ഃാ-ൄെ-ൈൊ-്ൗൢൣ൦-൯ංඃ්ා-ුූෘ-ෟ෦-෯ෲෳัิ-ฺ็-๎๐-๙ັິ-ູົຼ່-ໍ໐-໙༘༙༠-༩༹༵༷༾༿ཱ-྄྆྇ྍ-ྗྙ-ྼ࿆ါ-ှ၀-၉ၖ-ၙၞ-ၠၢ-ၤၧ-ၭၱ-ၴႂ-ႍႏ-ႝ፝-፟፩-፱ᜒ-᜔ᜲ-᜴ᝒᝓᝲᝳ឴-៓៝០-៩᠋-᠍᠐-᠙ᢩᤠ-ᤫᤰ-᤻᥆-᥏ᦰ-ᧀᧈᧉ᧐-᧚ᨗ-ᨛᩕ-ᩞ᩠-᩿᩼-᪉᪐-᪙᪰-᪽ᬀ-ᬄ᬴-᭄᭐-᭙᭫-᭳ᮀ-ᮂᮡ-ᮭ᮰-᮹᯦-᯳ᰤ-᰷᱀-᱉᱐-᱙᳐-᳔᳒-᳨᳭ᳲ-᳴᳸᳹᷀-᷵᷼-᷿‿⁀⁔⃐-⃥⃜⃡-⃰⳯-⵿⳱ⷠ-〪ⷿ-゙゚〯꘠-꘩꙯ꙴ-꙽ꚟ꛰꛱ꠂ꠆ꠋꠣ-ꠧꢀꢁꢴ-꣄꣐-꣙꣠-꣱꤀-꤉ꤦ-꤭ꥇ-꥓ꦀ-ꦃ꦳-꧀꧐-꧙ꧥ꧰-꧹ꨩ-ꨶꩃꩌꩍ꩐-꩙ꩻ-ꩽꪰꪲ-ꪴꪷꪸꪾ꪿꫁ꫫ-ꫯꫵ꫶ꯣ-ꯪ꯬꯭꯰-꯹ﬞ︀-️︠-︭︳︴﹍-﹏0-9_";
  5402. var nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]");
  5403. var nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]");
  5404. nonASCIIidentifierStartChars = nonASCIIidentifierChars = null;
  5405. // These are a run-length and offset encoded representation of the
  5406. // >0xffff code points that are a valid part of identifiers. The
  5407. // offset starts at 0x10000, and each pair of numbers represents an
  5408. // offset to the next range, and then a size of the range. They were
  5409. // generated by tools/generate-identifier-regex.js
  5410. var astralIdentifierStartCodes = [0, 11, 2, 25, 2, 18, 2, 1, 2, 14, 3, 13, 35, 122, 70, 52, 268, 28, 4, 48, 48, 31, 17, 26, 6, 37, 11, 29, 3, 35, 5, 7, 2, 4, 43, 157, 99, 39, 9, 51, 157, 310, 10, 21, 11, 7, 153, 5, 3, 0, 2, 43, 2, 1, 4, 0, 3, 22, 11, 22, 10, 30, 98, 21, 11, 25, 71, 55, 7, 1, 65, 0, 16, 3, 2, 2, 2, 26, 45, 28, 4, 28, 36, 7, 2, 27, 28, 53, 11, 21, 11, 18, 14, 17, 111, 72, 955, 52, 76, 44, 33, 24, 27, 35, 42, 34, 4, 0, 13, 47, 15, 3, 22, 0, 38, 17, 2, 24, 133, 46, 39, 7, 3, 1, 3, 21, 2, 6, 2, 1, 2, 4, 4, 0, 32, 4, 287, 47, 21, 1, 2, 0, 185, 46, 82, 47, 21, 0, 60, 42, 502, 63, 32, 0, 449, 56, 1288, 920, 104, 110, 2962, 1070, 13266, 568, 8, 30, 114, 29, 19, 47, 17, 3, 32, 20, 6, 18, 881, 68, 12, 0, 67, 12, 16481, 1, 3071, 106, 6, 12, 4, 8, 8, 9, 5991, 84, 2, 70, 2, 1, 3, 0, 3, 1, 3, 3, 2, 11, 2, 0, 2, 6, 2, 64, 2, 3, 3, 7, 2, 6, 2, 27, 2, 3, 2, 4, 2, 0, 4, 6, 2, 339, 3, 24, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 7, 4149, 196, 1340, 3, 2, 26, 2, 1, 2, 0, 3, 0, 2, 9, 2, 3, 2, 0, 2, 0, 7, 0, 5, 0, 2, 0, 2, 0, 2, 2, 2, 1, 2, 0, 3, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 1, 2, 0, 3, 3, 2, 6, 2, 3, 2, 3, 2, 0, 2, 9, 2, 16, 6, 2, 2, 4, 2, 16, 4421, 42710, 42, 4148, 12, 221, 16355, 541];
  5411. var astralIdentifierCodes = [509, 0, 227, 0, 150, 4, 294, 9, 1368, 2, 2, 1, 6, 3, 41, 2, 5, 0, 166, 1, 1306, 2, 54, 14, 32, 9, 16, 3, 46, 10, 54, 9, 7, 2, 37, 13, 2, 9, 52, 0, 13, 2, 49, 13, 16, 9, 83, 11, 168, 11, 6, 9, 8, 2, 57, 0, 2, 6, 3, 1, 3, 2, 10, 0, 11, 1, 3, 6, 4, 4, 316, 19, 13, 9, 214, 6, 3, 8, 112, 16, 16, 9, 82, 12, 9, 9, 535, 9, 20855, 9, 135, 4, 60, 6, 26, 9, 1016, 45, 17, 3, 19723, 1, 5319, 4, 4, 5, 9, 7, 3, 6, 31, 3, 149, 2, 1418, 49, 4305, 6, 792618, 239];
  5412. // This has a complexity linear to the value of the code. The
  5413. // assumption is that looking up astral identifier characters is
  5414. // rare.
  5415. function isInAstralSet(code, set) {
  5416. var pos = 65536;
  5417. for (var i = 0; i < set.length; i += 2) {
  5418. pos += set[i];
  5419. if (pos > code) {
  5420. return false;
  5421. }pos += set[i + 1];
  5422. if (pos >= code) {
  5423. return true;
  5424. }
  5425. }
  5426. }
  5427. function isIdentifierStart(code, astral) {
  5428. if (code < 65) {
  5429. return code === 36;
  5430. }if (code < 91) {
  5431. return true;
  5432. }if (code < 97) {
  5433. return code === 95;
  5434. }if (code < 123) {
  5435. return true;
  5436. }if (code <= 65535) {
  5437. return code >= 170 && nonASCIIidentifierStart.test(String.fromCharCode(code));
  5438. }if (astral === false) {
  5439. return false;
  5440. }return isInAstralSet(code, astralIdentifierStartCodes);
  5441. }
  5442. function isIdentifierChar(code, astral) {
  5443. if (code < 48) {
  5444. return code === 36;
  5445. }if (code < 58) {
  5446. return true;
  5447. }if (code < 65) {
  5448. return false;
  5449. }if (code < 91) {
  5450. return true;
  5451. }if (code < 97) {
  5452. return code === 95;
  5453. }if (code < 123) {
  5454. return true;
  5455. }if (code <= 65535) {
  5456. return code >= 170 && nonASCIIidentifier.test(String.fromCharCode(code));
  5457. }if (astral === false) {
  5458. return false;
  5459. }return isInAstralSet(code, astralIdentifierStartCodes) || isInAstralSet(code, astralIdentifierCodes);
  5460. }
  5461. },{}],8:[function(_dereq_,module,exports){
  5462. "use strict";
  5463. var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } };
  5464. // The `getLineInfo` function is mostly useful when the
  5465. // `locations` option is off (for performance reasons) and you
  5466. // want to find the line/column position for a given character
  5467. // offset. `input` should be the code string that the offset refers
  5468. // into.
  5469. exports.getLineInfo = getLineInfo;
  5470. exports.__esModule = true;
  5471. var Parser = _dereq_("./state").Parser;
  5472. var lineBreakG = _dereq_("./whitespace").lineBreakG;
  5473. var deprecate = _dereq_("util").deprecate;
  5474. // These are used when `options.locations` is on, for the
  5475. // `startLoc` and `endLoc` properties.
  5476. var Position = exports.Position = (function () {
  5477. function Position(line, col) {
  5478. _classCallCheck(this, Position);
  5479. this.line = line;
  5480. this.column = col;
  5481. }
  5482. Position.prototype.offset = function offset(n) {
  5483. return new Position(this.line, this.column + n);
  5484. };
  5485. return Position;
  5486. })();
  5487. var SourceLocation = exports.SourceLocation = function SourceLocation(p, start, end) {
  5488. _classCallCheck(this, SourceLocation);
  5489. this.start = start;
  5490. this.end = end;
  5491. if (p.sourceFile !== null) this.source = p.sourceFile;
  5492. };
  5493. function getLineInfo(input, offset) {
  5494. for (var line = 1, cur = 0;;) {
  5495. lineBreakG.lastIndex = cur;
  5496. var match = lineBreakG.exec(input);
  5497. if (match && match.index < offset) {
  5498. ++line;
  5499. cur = match.index + match[0].length;
  5500. } else {
  5501. return new Position(line, offset - cur);
  5502. }
  5503. }
  5504. }
  5505. var pp = Parser.prototype;
  5506. // This function is used to raise exceptions on parse errors. It
  5507. // takes an offset integer (into the current `input`) to indicate
  5508. // the location of the error, attaches the position to the end
  5509. // of the error message, and then raises a `SyntaxError` with that
  5510. // message.
  5511. pp.raise = function (pos, message) {
  5512. var loc = getLineInfo(this.input, pos);
  5513. message += " (" + loc.line + ":" + loc.column + ")";
  5514. var err = new SyntaxError(message);
  5515. err.pos = pos;err.loc = loc;err.raisedAt = this.pos;
  5516. throw err;
  5517. };
  5518. pp.curPosition = function () {
  5519. return new Position(this.curLine, this.pos - this.lineStart);
  5520. };
  5521. pp.markPosition = function () {
  5522. return this.options.locations ? [this.start, this.startLoc] : this.start;
  5523. };
  5524. },{"./state":13,"./whitespace":19,"util":5}],9:[function(_dereq_,module,exports){
  5525. "use strict";
  5526. var tt = _dereq_("./tokentype").types;
  5527. var Parser = _dereq_("./state").Parser;
  5528. var reservedWords = _dereq_("./identifier").reservedWords;
  5529. var has = _dereq_("./util").has;
  5530. var pp = Parser.prototype;
  5531. // Convert existing expression atom to assignable pattern
  5532. // if possible.
  5533. pp.toAssignable = function (node, isBinding) {
  5534. if (this.options.ecmaVersion >= 6 && node) {
  5535. switch (node.type) {
  5536. case "Identifier":
  5537. case "ObjectPattern":
  5538. case "ArrayPattern":
  5539. case "AssignmentPattern":
  5540. break;
  5541. case "ObjectExpression":
  5542. node.type = "ObjectPattern";
  5543. for (var i = 0; i < node.properties.length; i++) {
  5544. var prop = node.properties[i];
  5545. if (prop.kind !== "init") this.raise(prop.key.start, "Object pattern can't contain getter or setter");
  5546. this.toAssignable(prop.value, isBinding);
  5547. }
  5548. break;
  5549. case "ArrayExpression":
  5550. node.type = "ArrayPattern";
  5551. this.toAssignableList(node.elements, isBinding);
  5552. break;
  5553. case "AssignmentExpression":
  5554. if (node.operator === "=") {
  5555. node.type = "AssignmentPattern";
  5556. } else {
  5557. this.raise(node.left.end, "Only '=' operator can be used for specifying default value.");
  5558. }
  5559. break;
  5560. case "ParenthesizedExpression":
  5561. node.expression = this.toAssignable(node.expression, isBinding);
  5562. break;
  5563. case "MemberExpression":
  5564. if (!isBinding) break;
  5565. default:
  5566. this.raise(node.start, "Assigning to rvalue");
  5567. }
  5568. }
  5569. return node;
  5570. };
  5571. // Convert list of expression atoms to binding list.
  5572. pp.toAssignableList = function (exprList, isBinding) {
  5573. var end = exprList.length;
  5574. if (end) {
  5575. var last = exprList[end - 1];
  5576. if (last && last.type == "RestElement") {
  5577. --end;
  5578. } else if (last && last.type == "SpreadElement") {
  5579. last.type = "RestElement";
  5580. var arg = last.argument;
  5581. this.toAssignable(arg, isBinding);
  5582. if (arg.type !== "Identifier" && arg.type !== "MemberExpression" && arg.type !== "ArrayPattern") this.unexpected(arg.start);
  5583. --end;
  5584. }
  5585. }
  5586. for (var i = 0; i < end; i++) {
  5587. var elt = exprList[i];
  5588. if (elt) this.toAssignable(elt, isBinding);
  5589. }
  5590. return exprList;
  5591. };
  5592. // Parses spread element.
  5593. pp.parseSpread = function (refShorthandDefaultPos) {
  5594. var node = this.startNode();
  5595. this.next();
  5596. node.argument = this.parseMaybeAssign(refShorthandDefaultPos);
  5597. return this.finishNode(node, "SpreadElement");
  5598. };
  5599. pp.parseRest = function () {
  5600. var node = this.startNode();
  5601. this.next();
  5602. node.argument = this.type === tt.name || this.type === tt.bracketL ? this.parseBindingAtom() : this.unexpected();
  5603. return this.finishNode(node, "RestElement");
  5604. };
  5605. // Parses lvalue (assignable) atom.
  5606. pp.parseBindingAtom = function () {
  5607. if (this.options.ecmaVersion < 6) return this.parseIdent();
  5608. switch (this.type) {
  5609. case tt.name:
  5610. return this.parseIdent();
  5611. case tt.bracketL:
  5612. var node = this.startNode();
  5613. this.next();
  5614. node.elements = this.parseBindingList(tt.bracketR, true, true);
  5615. return this.finishNode(node, "ArrayPattern");
  5616. case tt.braceL:
  5617. return this.parseObj(true);
  5618. default:
  5619. this.unexpected();
  5620. }
  5621. };
  5622. pp.parseBindingList = function (close, allowEmpty, allowTrailingComma) {
  5623. var elts = [],
  5624. first = true;
  5625. while (!this.eat(close)) {
  5626. if (first) first = false;else this.expect(tt.comma);
  5627. if (allowEmpty && this.type === tt.comma) {
  5628. elts.push(null);
  5629. } else if (allowTrailingComma && this.afterTrailingComma(close)) {
  5630. break;
  5631. } else if (this.type === tt.ellipsis) {
  5632. var rest = this.parseRest();
  5633. this.parseBindingListItem(rest);
  5634. elts.push(rest);
  5635. this.expect(close);
  5636. break;
  5637. } else {
  5638. var elem = this.parseMaybeDefault(this.start, this.startLoc);
  5639. this.parseBindingListItem(elem);
  5640. elts.push(elem);
  5641. }
  5642. }
  5643. return elts;
  5644. };
  5645. pp.parseBindingListItem = function (param) {
  5646. return param;
  5647. };
  5648. // Parses assignment pattern around given atom if possible.
  5649. pp.parseMaybeDefault = function (startPos, startLoc, left) {
  5650. if (Array.isArray(startPos)) {
  5651. if (this.options.locations && noCalls === undefined) {
  5652. // shift arguments to left by one
  5653. left = startLoc;
  5654. // flatten startPos
  5655. startLoc = startPos[1];
  5656. startPos = startPos[0];
  5657. }
  5658. }
  5659. left = left || this.parseBindingAtom();
  5660. if (!this.eat(tt.eq)) return left;
  5661. var node = this.startNodeAt(startPos, startLoc);
  5662. node.operator = "=";
  5663. node.left = left;
  5664. node.right = this.parseMaybeAssign();
  5665. return this.finishNode(node, "AssignmentPattern");
  5666. };
  5667. // Verify that a node is an lval — something that can be assigned
  5668. // to.
  5669. pp.checkLVal = function (expr, isBinding, checkClashes) {
  5670. switch (expr.type) {
  5671. case "Identifier":
  5672. if (this.strict && (reservedWords.strictBind(expr.name) || reservedWords.strict(expr.name))) this.raise(expr.start, (isBinding ? "Binding " : "Assigning to ") + expr.name + " in strict mode");
  5673. if (checkClashes) {
  5674. if (has(checkClashes, expr.name)) this.raise(expr.start, "Argument name clash in strict mode");
  5675. checkClashes[expr.name] = true;
  5676. }
  5677. break;
  5678. case "MemberExpression":
  5679. if (isBinding) this.raise(expr.start, (isBinding ? "Binding" : "Assigning to") + " member expression");
  5680. break;
  5681. case "ObjectPattern":
  5682. for (var i = 0; i < expr.properties.length; i++) {
  5683. this.checkLVal(expr.properties[i].value, isBinding, checkClashes);
  5684. }break;
  5685. case "ArrayPattern":
  5686. for (var i = 0; i < expr.elements.length; i++) {
  5687. var elem = expr.elements[i];
  5688. if (elem) this.checkLVal(elem, isBinding, checkClashes);
  5689. }
  5690. break;
  5691. case "AssignmentPattern":
  5692. this.checkLVal(expr.left, isBinding, checkClashes);
  5693. break;
  5694. case "RestElement":
  5695. this.checkLVal(expr.argument, isBinding, checkClashes);
  5696. break;
  5697. case "ParenthesizedExpression":
  5698. this.checkLVal(expr.expression, isBinding, checkClashes);
  5699. break;
  5700. default:
  5701. this.raise(expr.start, (isBinding ? "Binding" : "Assigning to") + " rvalue");
  5702. }
  5703. };
  5704. },{"./identifier":7,"./state":13,"./tokentype":17,"./util":18}],10:[function(_dereq_,module,exports){
  5705. "use strict";
  5706. var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } };
  5707. exports.__esModule = true;
  5708. var Parser = _dereq_("./state").Parser;
  5709. var SourceLocation = _dereq_("./location").SourceLocation;
  5710. // Start an AST node, attaching a start offset.
  5711. var pp = Parser.prototype;
  5712. var Node = exports.Node = function Node() {
  5713. _classCallCheck(this, Node);
  5714. };
  5715. pp.startNode = function () {
  5716. var node = new Node();
  5717. node.start = this.start;
  5718. if (this.options.locations) node.loc = new SourceLocation(this, this.startLoc);
  5719. if (this.options.directSourceFile) node.sourceFile = this.options.directSourceFile;
  5720. if (this.options.ranges) node.range = [this.start, 0];
  5721. return node;
  5722. };
  5723. pp.startNodeAt = function (pos, loc) {
  5724. var node = new Node();
  5725. if (Array.isArray(pos)) {
  5726. if (this.options.locations && loc === undefined) {
  5727. // flatten pos
  5728. loc = pos[1];
  5729. pos = pos[0];
  5730. }
  5731. }
  5732. node.start = pos;
  5733. if (this.options.locations) node.loc = new SourceLocation(this, loc);
  5734. if (this.options.directSourceFile) node.sourceFile = this.options.directSourceFile;
  5735. if (this.options.ranges) node.range = [pos, 0];
  5736. return node;
  5737. };
  5738. // Finish an AST node, adding `type` and `end` properties.
  5739. pp.finishNode = function (node, type) {
  5740. node.type = type;
  5741. node.end = this.lastTokEnd;
  5742. if (this.options.locations) node.loc.end = this.lastTokEndLoc;
  5743. if (this.options.ranges) node.range[1] = this.lastTokEnd;
  5744. return node;
  5745. };
  5746. // Finish node at given position
  5747. pp.finishNodeAt = function (node, type, pos, loc) {
  5748. node.type = type;
  5749. if (Array.isArray(pos)) {
  5750. if (this.options.locations && loc === undefined) {
  5751. // flatten pos
  5752. loc = pos[1];
  5753. pos = pos[0];
  5754. }
  5755. }
  5756. node.end = pos;
  5757. if (this.options.locations) node.loc.end = loc;
  5758. if (this.options.ranges) node.range[1] = pos;
  5759. return node;
  5760. };
  5761. },{"./location":8,"./state":13}],11:[function(_dereq_,module,exports){
  5762. // Interpret and default an options object
  5763. "use strict";
  5764. exports.getOptions = getOptions;
  5765. exports.__esModule = true;
  5766. var _util = _dereq_("./util");
  5767. var has = _util.has;
  5768. var isArray = _util.isArray;
  5769. var SourceLocation = _dereq_("./location").SourceLocation;
  5770. // A second optional argument can be given to further configure
  5771. // the parser process. These options are recognized:
  5772. var defaultOptions = {
  5773. // `ecmaVersion` indicates the ECMAScript version to parse. Must
  5774. // be either 3, or 5, or 6. This influences support for strict
  5775. // mode, the set of reserved words, support for getters and
  5776. // setters and other features.
  5777. ecmaVersion: 5,
  5778. // Source type ("script" or "module") for different semantics
  5779. sourceType: "script",
  5780. // `onInsertedSemicolon` can be a callback that will be called
  5781. // when a semicolon is automatically inserted. It will be passed
  5782. // th position of the comma as an offset, and if `locations` is
  5783. // enabled, it is given the location as a `{line, column}` object
  5784. // as second argument.
  5785. onInsertedSemicolon: null,
  5786. // `onTrailingComma` is similar to `onInsertedSemicolon`, but for
  5787. // trailing commas.
  5788. onTrailingComma: null,
  5789. // By default, reserved words are not enforced. Disable
  5790. // `allowReserved` to enforce them. When this option has the
  5791. // value "never", reserved words and keywords can also not be
  5792. // used as property names.
  5793. allowReserved: true,
  5794. // When enabled, a return at the top level is not considered an
  5795. // error.
  5796. allowReturnOutsideFunction: false,
  5797. // When enabled, import/export statements are not constrained to
  5798. // appearing at the top of the program.
  5799. allowImportExportEverywhere: false,
  5800. // When enabled, hashbang directive in the beginning of file
  5801. // is allowed and treated as a line comment.
  5802. allowHashBang: false,
  5803. // When `locations` is on, `loc` properties holding objects with
  5804. // `start` and `end` properties in `{line, column}` form (with
  5805. // line being 1-based and column 0-based) will be attached to the
  5806. // nodes.
  5807. locations: false,
  5808. // A function can be passed as `onToken` option, which will
  5809. // cause Acorn to call that function with object in the same
  5810. // format as tokenize() returns. Note that you are not
  5811. // allowed to call the parser from the callback—that will
  5812. // corrupt its internal state.
  5813. onToken: null,
  5814. // A function can be passed as `onComment` option, which will
  5815. // cause Acorn to call that function with `(block, text, start,
  5816. // end)` parameters whenever a comment is skipped. `block` is a
  5817. // boolean indicating whether this is a block (`/* */`) comment,
  5818. // `text` is the content of the comment, and `start` and `end` are
  5819. // character offsets that denote the start and end of the comment.
  5820. // When the `locations` option is on, two more parameters are
  5821. // passed, the full `{line, column}` locations of the start and
  5822. // end of the comments. Note that you are not allowed to call the
  5823. // parser from the callback—that will corrupt its internal state.
  5824. onComment: null,
  5825. // Nodes have their start and end characters offsets recorded in
  5826. // `start` and `end` properties (directly on the node, rather than
  5827. // the `loc` object, which holds line/column data. To also add a
  5828. // [semi-standardized][range] `range` property holding a `[start,
  5829. // end]` array with the same numbers, set the `ranges` option to
  5830. // `true`.
  5831. //
  5832. // [range]: https://bugzilla.mozilla.org/show_bug.cgi?id=745678
  5833. ranges: false,
  5834. // It is possible to parse multiple files into a single AST by
  5835. // passing the tree produced by parsing the first file as
  5836. // `program` option in subsequent parses. This will add the
  5837. // toplevel forms of the parsed file to the `Program` (top) node
  5838. // of an existing parse tree.
  5839. program: null,
  5840. // When `locations` is on, you can pass this to record the source
  5841. // file in every node's `loc` object.
  5842. sourceFile: null,
  5843. // This value, if given, is stored in every node, whether
  5844. // `locations` is on or off.
  5845. directSourceFile: null,
  5846. // When enabled, parenthesized expressions are represented by
  5847. // (non-standard) ParenthesizedExpression nodes
  5848. preserveParens: false,
  5849. plugins: {}
  5850. };exports.defaultOptions = defaultOptions;
  5851. function getOptions(opts) {
  5852. var options = {};
  5853. for (var opt in defaultOptions) {
  5854. options[opt] = opts && has(opts, opt) ? opts[opt] : defaultOptions[opt];
  5855. }if (isArray(options.onToken)) {
  5856. (function () {
  5857. var tokens = options.onToken;
  5858. options.onToken = function (token) {
  5859. return tokens.push(token);
  5860. };
  5861. })();
  5862. }
  5863. if (isArray(options.onComment)) options.onComment = pushComment(options, options.onComment);
  5864. return options;
  5865. }
  5866. function pushComment(options, array) {
  5867. return function (block, text, start, end, startLoc, endLoc) {
  5868. var comment = {
  5869. type: block ? "Block" : "Line",
  5870. value: text,
  5871. start: start,
  5872. end: end
  5873. };
  5874. if (options.locations) comment.loc = new SourceLocation(this, startLoc, endLoc);
  5875. if (options.ranges) comment.range = [start, end];
  5876. array.push(comment);
  5877. };
  5878. }
  5879. },{"./location":8,"./util":18}],12:[function(_dereq_,module,exports){
  5880. "use strict";
  5881. var tt = _dereq_("./tokentype").types;
  5882. var Parser = _dereq_("./state").Parser;
  5883. var lineBreak = _dereq_("./whitespace").lineBreak;
  5884. var pp = Parser.prototype;
  5885. // ## Parser utilities
  5886. // Test whether a statement node is the string literal `"use strict"`.
  5887. pp.isUseStrict = function (stmt) {
  5888. return this.options.ecmaVersion >= 5 && stmt.type === "ExpressionStatement" && stmt.expression.type === "Literal" && stmt.expression.value === "use strict";
  5889. };
  5890. // Predicate that tests whether the next token is of the given
  5891. // type, and if yes, consumes it as a side effect.
  5892. pp.eat = function (type) {
  5893. if (this.type === type) {
  5894. this.next();
  5895. return true;
  5896. } else {
  5897. return false;
  5898. }
  5899. };
  5900. // Tests whether parsed token is a contextual keyword.
  5901. pp.isContextual = function (name) {
  5902. return this.type === tt.name && this.value === name;
  5903. };
  5904. // Consumes contextual keyword if possible.
  5905. pp.eatContextual = function (name) {
  5906. return this.value === name && this.eat(tt.name);
  5907. };
  5908. // Asserts that following token is given contextual keyword.
  5909. pp.expectContextual = function (name) {
  5910. if (!this.eatContextual(name)) this.unexpected();
  5911. };
  5912. // Test whether a semicolon can be inserted at the current position.
  5913. pp.canInsertSemicolon = function () {
  5914. return this.type === tt.eof || this.type === tt.braceR || lineBreak.test(this.input.slice(this.lastTokEnd, this.start));
  5915. };
  5916. pp.insertSemicolon = function () {
  5917. if (this.canInsertSemicolon()) {
  5918. if (this.options.onInsertedSemicolon) this.options.onInsertedSemicolon(this.lastTokEnd, this.lastTokEndLoc);
  5919. return true;
  5920. }
  5921. };
  5922. // Consume a semicolon, or, failing that, see if we are allowed to
  5923. // pretend that there is a semicolon at this position.
  5924. pp.semicolon = function () {
  5925. if (!this.eat(tt.semi) && !this.insertSemicolon()) this.unexpected();
  5926. };
  5927. pp.afterTrailingComma = function (tokType) {
  5928. if (this.type == tokType) {
  5929. if (this.options.onTrailingComma) this.options.onTrailingComma(this.lastTokStart, this.lastTokStartLoc);
  5930. this.next();
  5931. return true;
  5932. }
  5933. };
  5934. // Expect a token of a given type. If found, consume it, otherwise,
  5935. // raise an unexpected token error.
  5936. pp.expect = function (type) {
  5937. this.eat(type) || this.unexpected();
  5938. };
  5939. // Raise an unexpected token error.
  5940. pp.unexpected = function (pos) {
  5941. this.raise(pos != null ? pos : this.start, "Unexpected token");
  5942. };
  5943. },{"./state":13,"./tokentype":17,"./whitespace":19}],13:[function(_dereq_,module,exports){
  5944. "use strict";
  5945. exports.Parser = Parser;
  5946. exports.__esModule = true;
  5947. var _identifier = _dereq_("./identifier");
  5948. var reservedWords = _identifier.reservedWords;
  5949. var keywords = _identifier.keywords;
  5950. var tt = _dereq_("./tokentype").types;
  5951. var lineBreak = _dereq_("./whitespace").lineBreak;
  5952. function Parser(options, input, startPos) {
  5953. this.options = options;
  5954. this.sourceFile = this.options.sourceFile || null;
  5955. this.isKeyword = keywords[this.options.ecmaVersion >= 6 ? 6 : 5];
  5956. this.isReservedWord = reservedWords[this.options.ecmaVersion];
  5957. this.input = input;
  5958. // Load plugins
  5959. this.loadPlugins(this.options.plugins);
  5960. // Set up token state
  5961. // The current position of the tokenizer in the input.
  5962. if (startPos) {
  5963. this.pos = startPos;
  5964. this.lineStart = Math.max(0, this.input.lastIndexOf("\n", startPos));
  5965. this.curLine = this.input.slice(0, this.lineStart).split(lineBreak).length;
  5966. } else {
  5967. this.pos = this.lineStart = 0;
  5968. this.curLine = 1;
  5969. }
  5970. // Properties of the current token:
  5971. // Its type
  5972. this.type = tt.eof;
  5973. // For tokens that include more information than their type, the value
  5974. this.value = null;
  5975. // Its start and end offset
  5976. this.start = this.end = this.pos;
  5977. // And, if locations are used, the {line, column} object
  5978. // corresponding to those offsets
  5979. this.startLoc = this.endLoc = null;
  5980. // Position information for the previous token
  5981. this.lastTokEndLoc = this.lastTokStartLoc = null;
  5982. this.lastTokStart = this.lastTokEnd = this.pos;
  5983. // The context stack is used to superficially track syntactic
  5984. // context to predict whether a regular expression is allowed in a
  5985. // given position.
  5986. this.context = this.initialContext();
  5987. this.exprAllowed = true;
  5988. // Figure out if it's a module code.
  5989. this.strict = this.inModule = this.options.sourceType === "module";
  5990. // Used to signify the start of a potential arrow function
  5991. this.potentialArrowAt = -1;
  5992. // Flags to track whether we are in a function, a generator.
  5993. this.inFunction = this.inGenerator = false;
  5994. // Labels in scope.
  5995. this.labels = [];
  5996. // If enabled, skip leading hashbang line.
  5997. if (this.pos === 0 && this.options.allowHashBang && this.input.slice(0, 2) === "#!") this.skipLineComment(2);
  5998. }
  5999. Parser.prototype.extend = function (name, f) {
  6000. this[name] = f(this[name]);
  6001. };
  6002. // Registered plugins
  6003. var plugins = {};
  6004. exports.plugins = plugins;
  6005. Parser.prototype.loadPlugins = function (plugins) {
  6006. for (var _name in plugins) {
  6007. var plugin = exports.plugins[_name];
  6008. if (!plugin) throw new Error("Plugin '" + _name + "' not found");
  6009. plugin(this, plugins[_name]);
  6010. }
  6011. };
  6012. },{"./identifier":7,"./tokentype":17,"./whitespace":19}],14:[function(_dereq_,module,exports){
  6013. "use strict";
  6014. var tt = _dereq_("./tokentype").types;
  6015. var Parser = _dereq_("./state").Parser;
  6016. var lineBreak = _dereq_("./whitespace").lineBreak;
  6017. var pp = Parser.prototype;
  6018. // ### Statement parsing
  6019. // Parse a program. Initializes the parser, reads any number of
  6020. // statements, and wraps them in a Program node. Optionally takes a
  6021. // `program` argument. If present, the statements will be appended
  6022. // to its body instead of creating a new node.
  6023. pp.parseTopLevel = function (node) {
  6024. var first = true;
  6025. if (!node.body) node.body = [];
  6026. while (this.type !== tt.eof) {
  6027. var stmt = this.parseStatement(true, true);
  6028. node.body.push(stmt);
  6029. if (first && this.isUseStrict(stmt)) this.setStrict(true);
  6030. first = false;
  6031. }
  6032. this.next();
  6033. if (this.options.ecmaVersion >= 6) {
  6034. node.sourceType = this.options.sourceType;
  6035. }
  6036. return this.finishNode(node, "Program");
  6037. };
  6038. var loopLabel = { kind: "loop" },
  6039. switchLabel = { kind: "switch" };
  6040. // Parse a single statement.
  6041. //
  6042. // If expecting a statement and finding a slash operator, parse a
  6043. // regular expression literal. This is to handle cases like
  6044. // `if (foo) /blah/.exec(foo)`, where looking at the previous token
  6045. // does not help.
  6046. pp.parseStatement = function (declaration, topLevel) {
  6047. var starttype = this.type,
  6048. node = this.startNode();
  6049. // Most types of statements are recognized by the keyword they
  6050. // start with. Many are trivial to parse, some require a bit of
  6051. // complexity.
  6052. switch (starttype) {
  6053. case tt._break:case tt._continue:
  6054. return this.parseBreakContinueStatement(node, starttype.keyword);
  6055. case tt._debugger:
  6056. return this.parseDebuggerStatement(node);
  6057. case tt._do:
  6058. return this.parseDoStatement(node);
  6059. case tt._for:
  6060. return this.parseForStatement(node);
  6061. case tt._function:
  6062. if (!declaration && this.options.ecmaVersion >= 6) this.unexpected();
  6063. return this.parseFunctionStatement(node);
  6064. case tt._class:
  6065. if (!declaration) this.unexpected();
  6066. return this.parseClass(node, true);
  6067. case tt._if:
  6068. return this.parseIfStatement(node);
  6069. case tt._return:
  6070. return this.parseReturnStatement(node);
  6071. case tt._switch:
  6072. return this.parseSwitchStatement(node);
  6073. case tt._throw:
  6074. return this.parseThrowStatement(node);
  6075. case tt._try:
  6076. return this.parseTryStatement(node);
  6077. case tt._let:case tt._const:
  6078. if (!declaration) this.unexpected(); // NOTE: falls through to _var
  6079. case tt._var:
  6080. return this.parseVarStatement(node, starttype);
  6081. case tt._while:
  6082. return this.parseWhileStatement(node);
  6083. case tt._with:
  6084. return this.parseWithStatement(node);
  6085. case tt.braceL:
  6086. return this.parseBlock();
  6087. case tt.semi:
  6088. return this.parseEmptyStatement(node);
  6089. case tt._export:
  6090. case tt._import:
  6091. if (!this.options.allowImportExportEverywhere) {
  6092. if (!topLevel) this.raise(this.start, "'import' and 'export' may only appear at the top level");
  6093. if (!this.inModule) this.raise(this.start, "'import' and 'export' may appear only with 'sourceType: module'");
  6094. }
  6095. return starttype === tt._import ? this.parseImport(node) : this.parseExport(node);
  6096. // If the statement does not start with a statement keyword or a
  6097. // brace, it's an ExpressionStatement or LabeledStatement. We
  6098. // simply start parsing an expression, and afterwards, if the
  6099. // next token is a colon and the expression was a simple
  6100. // Identifier node, we switch to interpreting it as a label.
  6101. default:
  6102. var maybeName = this.value,
  6103. expr = this.parseExpression();
  6104. if (starttype === tt.name && expr.type === "Identifier" && this.eat(tt.colon)) return this.parseLabeledStatement(node, maybeName, expr);else return this.parseExpressionStatement(node, expr);
  6105. }
  6106. };
  6107. pp.parseBreakContinueStatement = function (node, keyword) {
  6108. var isBreak = keyword == "break";
  6109. this.next();
  6110. if (this.eat(tt.semi) || this.insertSemicolon()) node.label = null;else if (this.type !== tt.name) this.unexpected();else {
  6111. node.label = this.parseIdent();
  6112. this.semicolon();
  6113. }
  6114. // Verify that there is an actual destination to break or
  6115. // continue to.
  6116. for (var i = 0; i < this.labels.length; ++i) {
  6117. var lab = this.labels[i];
  6118. if (node.label == null || lab.name === node.label.name) {
  6119. if (lab.kind != null && (isBreak || lab.kind === "loop")) break;
  6120. if (node.label && isBreak) break;
  6121. }
  6122. }
  6123. if (i === this.labels.length) this.raise(node.start, "Unsyntactic " + keyword);
  6124. return this.finishNode(node, isBreak ? "BreakStatement" : "ContinueStatement");
  6125. };
  6126. pp.parseDebuggerStatement = function (node) {
  6127. this.next();
  6128. this.semicolon();
  6129. return this.finishNode(node, "DebuggerStatement");
  6130. };
  6131. pp.parseDoStatement = function (node) {
  6132. this.next();
  6133. this.labels.push(loopLabel);
  6134. node.body = this.parseStatement(false);
  6135. this.labels.pop();
  6136. this.expect(tt._while);
  6137. node.test = this.parseParenExpression();
  6138. if (this.options.ecmaVersion >= 6) this.eat(tt.semi);else this.semicolon();
  6139. return this.finishNode(node, "DoWhileStatement");
  6140. };
  6141. // Disambiguating between a `for` and a `for`/`in` or `for`/`of`
  6142. // loop is non-trivial. Basically, we have to parse the init `var`
  6143. // statement or expression, disallowing the `in` operator (see
  6144. // the second parameter to `parseExpression`), and then check
  6145. // whether the next token is `in` or `of`. When there is no init
  6146. // part (semicolon immediately after the opening parenthesis), it
  6147. // is a regular `for` loop.
  6148. pp.parseForStatement = function (node) {
  6149. this.next();
  6150. this.labels.push(loopLabel);
  6151. this.expect(tt.parenL);
  6152. if (this.type === tt.semi) return this.parseFor(node, null);
  6153. if (this.type === tt._var || this.type === tt._let || this.type === tt._const) {
  6154. var _init = this.startNode(),
  6155. varKind = this.type;
  6156. this.next();
  6157. this.parseVar(_init, true, varKind);
  6158. this.finishNode(_init, "VariableDeclaration");
  6159. if ((this.type === tt._in || this.options.ecmaVersion >= 6 && this.isContextual("of")) && _init.declarations.length === 1 && !(varKind !== tt._var && _init.declarations[0].init)) return this.parseForIn(node, _init);
  6160. return this.parseFor(node, _init);
  6161. }
  6162. var refShorthandDefaultPos = { start: 0 };
  6163. var init = this.parseExpression(true, refShorthandDefaultPos);
  6164. if (this.type === tt._in || this.options.ecmaVersion >= 6 && this.isContextual("of")) {
  6165. this.toAssignable(init);
  6166. this.checkLVal(init);
  6167. return this.parseForIn(node, init);
  6168. } else if (refShorthandDefaultPos.start) {
  6169. this.unexpected(refShorthandDefaultPos.start);
  6170. }
  6171. return this.parseFor(node, init);
  6172. };
  6173. pp.parseFunctionStatement = function (node) {
  6174. this.next();
  6175. return this.parseFunction(node, true);
  6176. };
  6177. pp.parseIfStatement = function (node) {
  6178. this.next();
  6179. node.test = this.parseParenExpression();
  6180. node.consequent = this.parseStatement(false);
  6181. node.alternate = this.eat(tt._else) ? this.parseStatement(false) : null;
  6182. return this.finishNode(node, "IfStatement");
  6183. };
  6184. pp.parseReturnStatement = function (node) {
  6185. if (!this.inFunction && !this.options.allowReturnOutsideFunction) this.raise(this.start, "'return' outside of function");
  6186. this.next();
  6187. // In `return` (and `break`/`continue`), the keywords with
  6188. // optional arguments, we eagerly look for a semicolon or the
  6189. // possibility to insert one.
  6190. if (this.eat(tt.semi) || this.insertSemicolon()) node.argument = null;else {
  6191. node.argument = this.parseExpression();this.semicolon();
  6192. }
  6193. return this.finishNode(node, "ReturnStatement");
  6194. };
  6195. pp.parseSwitchStatement = function (node) {
  6196. this.next();
  6197. node.discriminant = this.parseParenExpression();
  6198. node.cases = [];
  6199. this.expect(tt.braceL);
  6200. this.labels.push(switchLabel);
  6201. // Statements under must be grouped (by label) in SwitchCase
  6202. // nodes. `cur` is used to keep the node that we are currently
  6203. // adding statements to.
  6204. for (var cur, sawDefault; this.type != tt.braceR;) {
  6205. if (this.type === tt._case || this.type === tt._default) {
  6206. var isCase = this.type === tt._case;
  6207. if (cur) this.finishNode(cur, "SwitchCase");
  6208. node.cases.push(cur = this.startNode());
  6209. cur.consequent = [];
  6210. this.next();
  6211. if (isCase) {
  6212. cur.test = this.parseExpression();
  6213. } else {
  6214. if (sawDefault) this.raise(this.lastTokStart, "Multiple default clauses");
  6215. sawDefault = true;
  6216. cur.test = null;
  6217. }
  6218. this.expect(tt.colon);
  6219. } else {
  6220. if (!cur) this.unexpected();
  6221. cur.consequent.push(this.parseStatement(true));
  6222. }
  6223. }
  6224. if (cur) this.finishNode(cur, "SwitchCase");
  6225. this.next(); // Closing brace
  6226. this.labels.pop();
  6227. return this.finishNode(node, "SwitchStatement");
  6228. };
  6229. pp.parseThrowStatement = function (node) {
  6230. this.next();
  6231. if (lineBreak.test(this.input.slice(this.lastTokEnd, this.start))) this.raise(this.lastTokEnd, "Illegal newline after throw");
  6232. node.argument = this.parseExpression();
  6233. this.semicolon();
  6234. return this.finishNode(node, "ThrowStatement");
  6235. };
  6236. // Reused empty array added for node fields that are always empty.
  6237. var empty = [];
  6238. pp.parseTryStatement = function (node) {
  6239. this.next();
  6240. node.block = this.parseBlock();
  6241. node.handler = null;
  6242. if (this.type === tt._catch) {
  6243. var clause = this.startNode();
  6244. this.next();
  6245. this.expect(tt.parenL);
  6246. clause.param = this.parseBindingAtom();
  6247. this.checkLVal(clause.param, true);
  6248. this.expect(tt.parenR);
  6249. clause.guard = null;
  6250. clause.body = this.parseBlock();
  6251. node.handler = this.finishNode(clause, "CatchClause");
  6252. }
  6253. node.guardedHandlers = empty;
  6254. node.finalizer = this.eat(tt._finally) ? this.parseBlock() : null;
  6255. if (!node.handler && !node.finalizer) this.raise(node.start, "Missing catch or finally clause");
  6256. return this.finishNode(node, "TryStatement");
  6257. };
  6258. pp.parseVarStatement = function (node, kind) {
  6259. this.next();
  6260. this.parseVar(node, false, kind);
  6261. this.semicolon();
  6262. return this.finishNode(node, "VariableDeclaration");
  6263. };
  6264. pp.parseWhileStatement = function (node) {
  6265. this.next();
  6266. node.test = this.parseParenExpression();
  6267. this.labels.push(loopLabel);
  6268. node.body = this.parseStatement(false);
  6269. this.labels.pop();
  6270. return this.finishNode(node, "WhileStatement");
  6271. };
  6272. pp.parseWithStatement = function (node) {
  6273. if (this.strict) this.raise(this.start, "'with' in strict mode");
  6274. this.next();
  6275. node.object = this.parseParenExpression();
  6276. node.body = this.parseStatement(false);
  6277. return this.finishNode(node, "WithStatement");
  6278. };
  6279. pp.parseEmptyStatement = function (node) {
  6280. this.next();
  6281. return this.finishNode(node, "EmptyStatement");
  6282. };
  6283. pp.parseLabeledStatement = function (node, maybeName, expr) {
  6284. for (var i = 0; i < this.labels.length; ++i) {
  6285. if (this.labels[i].name === maybeName) this.raise(expr.start, "Label '" + maybeName + "' is already declared");
  6286. }var kind = this.type.isLoop ? "loop" : this.type === tt._switch ? "switch" : null;
  6287. this.labels.push({ name: maybeName, kind: kind });
  6288. node.body = this.parseStatement(true);
  6289. this.labels.pop();
  6290. node.label = expr;
  6291. return this.finishNode(node, "LabeledStatement");
  6292. };
  6293. pp.parseExpressionStatement = function (node, expr) {
  6294. node.expression = expr;
  6295. this.semicolon();
  6296. return this.finishNode(node, "ExpressionStatement");
  6297. };
  6298. // Parse a semicolon-enclosed block of statements, handling `"use
  6299. // strict"` declarations when `allowStrict` is true (used for
  6300. // function bodies).
  6301. pp.parseBlock = function (allowStrict) {
  6302. var node = this.startNode(),
  6303. first = true,
  6304. oldStrict = undefined;
  6305. node.body = [];
  6306. this.expect(tt.braceL);
  6307. while (!this.eat(tt.braceR)) {
  6308. var stmt = this.parseStatement(true);
  6309. node.body.push(stmt);
  6310. if (first && allowStrict && this.isUseStrict(stmt)) {
  6311. oldStrict = this.strict;
  6312. this.setStrict(this.strict = true);
  6313. }
  6314. first = false;
  6315. }
  6316. if (oldStrict === false) this.setStrict(false);
  6317. return this.finishNode(node, "BlockStatement");
  6318. };
  6319. // Parse a regular `for` loop. The disambiguation code in
  6320. // `parseStatement` will already have parsed the init statement or
  6321. // expression.
  6322. pp.parseFor = function (node, init) {
  6323. node.init = init;
  6324. this.expect(tt.semi);
  6325. node.test = this.type === tt.semi ? null : this.parseExpression();
  6326. this.expect(tt.semi);
  6327. node.update = this.type === tt.parenR ? null : this.parseExpression();
  6328. this.expect(tt.parenR);
  6329. node.body = this.parseStatement(false);
  6330. this.labels.pop();
  6331. return this.finishNode(node, "ForStatement");
  6332. };
  6333. // Parse a `for`/`in` and `for`/`of` loop, which are almost
  6334. // same from parser's perspective.
  6335. pp.parseForIn = function (node, init) {
  6336. var type = this.type === tt._in ? "ForInStatement" : "ForOfStatement";
  6337. this.next();
  6338. node.left = init;
  6339. node.right = this.parseExpression();
  6340. this.expect(tt.parenR);
  6341. node.body = this.parseStatement(false);
  6342. this.labels.pop();
  6343. return this.finishNode(node, type);
  6344. };
  6345. // Parse a list of variable declarations.
  6346. pp.parseVar = function (node, isFor, kind) {
  6347. node.declarations = [];
  6348. node.kind = kind.keyword;
  6349. for (;;) {
  6350. var decl = this.startNode();
  6351. this.parseVarId(decl);
  6352. if (this.eat(tt.eq)) {
  6353. decl.init = this.parseMaybeAssign(isFor);
  6354. } else if (kind === tt._const && !(this.type === tt._in || this.options.ecmaVersion >= 6 && this.isContextual("of"))) {
  6355. this.unexpected();
  6356. } else if (decl.id.type != "Identifier" && !(isFor && (this.type === tt._in || this.isContextual("of")))) {
  6357. this.raise(this.lastTokEnd, "Complex binding patterns require an initialization value");
  6358. } else {
  6359. decl.init = null;
  6360. }
  6361. node.declarations.push(this.finishNode(decl, "VariableDeclarator"));
  6362. if (!this.eat(tt.comma)) break;
  6363. }
  6364. return node;
  6365. };
  6366. pp.parseVarId = function (decl) {
  6367. decl.id = this.parseBindingAtom();
  6368. this.checkLVal(decl.id, true);
  6369. };
  6370. // Parse a function declaration or literal (depending on the
  6371. // `isStatement` parameter).
  6372. pp.parseFunction = function (node, isStatement, allowExpressionBody) {
  6373. this.initFunction(node);
  6374. if (this.options.ecmaVersion >= 6) node.generator = this.eat(tt.star);
  6375. if (isStatement || this.type === tt.name) node.id = this.parseIdent();
  6376. this.parseFunctionParams(node);
  6377. this.parseFunctionBody(node, allowExpressionBody);
  6378. return this.finishNode(node, isStatement ? "FunctionDeclaration" : "FunctionExpression");
  6379. };
  6380. pp.parseFunctionParams = function (node) {
  6381. this.expect(tt.parenL);
  6382. node.params = this.parseBindingList(tt.parenR, false, false);
  6383. };
  6384. // Parse a class declaration or literal (depending on the
  6385. // `isStatement` parameter).
  6386. pp.parseClass = function (node, isStatement) {
  6387. this.next();
  6388. this.parseClassId(node, isStatement);
  6389. this.parseClassSuper(node);
  6390. var classBody = this.startNode();
  6391. var hadConstructor = false;
  6392. classBody.body = [];
  6393. this.expect(tt.braceL);
  6394. while (!this.eat(tt.braceR)) {
  6395. if (this.eat(tt.semi)) continue;
  6396. var method = this.startNode();
  6397. var isGenerator = this.eat(tt.star);
  6398. var isMaybeStatic = this.type === tt.name && this.value === "static";
  6399. this.parsePropertyName(method);
  6400. method["static"] = isMaybeStatic && this.type !== tt.parenL;
  6401. if (method["static"]) {
  6402. if (isGenerator) this.unexpected();
  6403. isGenerator = this.eat(tt.star);
  6404. this.parsePropertyName(method);
  6405. }
  6406. method.kind = "method";
  6407. if (!method.computed) {
  6408. var key = method.key;
  6409. var isGetSet = false;
  6410. if (!isGenerator && key.type === "Identifier" && this.type !== tt.parenL && (key.name === "get" || key.name === "set")) {
  6411. isGetSet = true;
  6412. method.kind = key.name;
  6413. key = this.parsePropertyName(method);
  6414. }
  6415. if (!method["static"] && (key.type === "Identifier" && key.name === "constructor" || key.type === "Literal" && key.value === "constructor")) {
  6416. if (hadConstructor) this.raise(key.start, "Duplicate constructor in the same class");
  6417. if (isGetSet) this.raise(key.start, "Constructor can't have get/set modifier");
  6418. if (isGenerator) this.raise(key.start, "Constructor can't be a generator");
  6419. method.kind = "constructor";
  6420. hadConstructor = true;
  6421. }
  6422. }
  6423. this.parseClassMethod(classBody, method, isGenerator);
  6424. }
  6425. node.body = this.finishNode(classBody, "ClassBody");
  6426. return this.finishNode(node, isStatement ? "ClassDeclaration" : "ClassExpression");
  6427. };
  6428. pp.parseClassMethod = function (classBody, method, isGenerator) {
  6429. method.value = this.parseMethod(isGenerator);
  6430. classBody.body.push(this.finishNode(method, "MethodDefinition"));
  6431. };
  6432. pp.parseClassId = function (node, isStatement) {
  6433. node.id = this.type === tt.name ? this.parseIdent() : isStatement ? this.unexpected() : null;
  6434. };
  6435. pp.parseClassSuper = function (node) {
  6436. node.superClass = this.eat(tt._extends) ? this.parseExprSubscripts() : null;
  6437. };
  6438. // Parses module export declaration.
  6439. pp.parseExport = function (node) {
  6440. this.next();
  6441. // export * from '...'
  6442. if (this.eat(tt.star)) {
  6443. this.expectContextual("from");
  6444. node.source = this.type === tt.string ? this.parseExprAtom() : this.unexpected();
  6445. this.semicolon();
  6446. return this.finishNode(node, "ExportAllDeclaration");
  6447. }
  6448. if (this.eat(tt._default)) {
  6449. // export default ...
  6450. var expr = this.parseMaybeAssign();
  6451. var needsSemi = true;
  6452. if (expr.type == "FunctionExpression" || expr.type == "ClassExpression") {
  6453. needsSemi = false;
  6454. if (expr.id) {
  6455. expr.type = expr.type == "FunctionExpression" ? "FunctionDeclaration" : "ClassDeclaration";
  6456. }
  6457. }
  6458. node.declaration = expr;
  6459. if (needsSemi) this.semicolon();
  6460. return this.finishNode(node, "ExportDefaultDeclaration");
  6461. }
  6462. // export var|const|let|function|class ...
  6463. if (this.shouldParseExportStatement()) {
  6464. node.declaration = this.parseStatement(true);
  6465. node.specifiers = [];
  6466. node.source = null;
  6467. } else {
  6468. // export { x, y as z } [from '...']
  6469. node.declaration = null;
  6470. node.specifiers = this.parseExportSpecifiers();
  6471. if (this.eatContextual("from")) {
  6472. node.source = this.type === tt.string ? this.parseExprAtom() : this.unexpected();
  6473. } else {
  6474. node.source = null;
  6475. }
  6476. this.semicolon();
  6477. }
  6478. return this.finishNode(node, "ExportNamedDeclaration");
  6479. };
  6480. pp.shouldParseExportStatement = function () {
  6481. return this.type.keyword;
  6482. };
  6483. // Parses a comma-separated list of module exports.
  6484. pp.parseExportSpecifiers = function () {
  6485. var nodes = [],
  6486. first = true;
  6487. // export { x, y as z } [from '...']
  6488. this.expect(tt.braceL);
  6489. while (!this.eat(tt.braceR)) {
  6490. if (!first) {
  6491. this.expect(tt.comma);
  6492. if (this.afterTrailingComma(tt.braceR)) break;
  6493. } else first = false;
  6494. var node = this.startNode();
  6495. node.local = this.parseIdent(this.type === tt._default);
  6496. node.exported = this.eatContextual("as") ? this.parseIdent(true) : node.local;
  6497. nodes.push(this.finishNode(node, "ExportSpecifier"));
  6498. }
  6499. return nodes;
  6500. };
  6501. // Parses import declaration.
  6502. pp.parseImport = function (node) {
  6503. this.next();
  6504. // import '...'
  6505. if (this.type === tt.string) {
  6506. node.specifiers = empty;
  6507. node.source = this.parseExprAtom();
  6508. node.kind = "";
  6509. } else {
  6510. node.specifiers = this.parseImportSpecifiers();
  6511. this.expectContextual("from");
  6512. node.source = this.type === tt.string ? this.parseExprAtom() : this.unexpected();
  6513. }
  6514. this.semicolon();
  6515. return this.finishNode(node, "ImportDeclaration");
  6516. };
  6517. // Parses a comma-separated list of module imports.
  6518. pp.parseImportSpecifiers = function () {
  6519. var nodes = [],
  6520. first = true;
  6521. if (this.type === tt.name) {
  6522. // import defaultObj, { x, y as z } from '...'
  6523. var node = this.startNode();
  6524. node.local = this.parseIdent();
  6525. this.checkLVal(node.local, true);
  6526. nodes.push(this.finishNode(node, "ImportDefaultSpecifier"));
  6527. if (!this.eat(tt.comma)) return nodes;
  6528. }
  6529. if (this.type === tt.star) {
  6530. var node = this.startNode();
  6531. this.next();
  6532. this.expectContextual("as");
  6533. node.local = this.parseIdent();
  6534. this.checkLVal(node.local, true);
  6535. nodes.push(this.finishNode(node, "ImportNamespaceSpecifier"));
  6536. return nodes;
  6537. }
  6538. this.expect(tt.braceL);
  6539. while (!this.eat(tt.braceR)) {
  6540. if (!first) {
  6541. this.expect(tt.comma);
  6542. if (this.afterTrailingComma(tt.braceR)) break;
  6543. } else first = false;
  6544. var node = this.startNode();
  6545. node.imported = this.parseIdent(true);
  6546. node.local = this.eatContextual("as") ? this.parseIdent() : node.imported;
  6547. this.checkLVal(node.local, true);
  6548. nodes.push(this.finishNode(node, "ImportSpecifier"));
  6549. }
  6550. return nodes;
  6551. };
  6552. },{"./state":13,"./tokentype":17,"./whitespace":19}],15:[function(_dereq_,module,exports){
  6553. "use strict";
  6554. var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } };
  6555. exports.__esModule = true;
  6556. // The algorithm used to determine whether a regexp can appear at a
  6557. // given point in the program is loosely based on sweet.js' approach.
  6558. // See https://github.com/mozilla/sweet.js/wiki/design
  6559. var Parser = _dereq_("./state").Parser;
  6560. var tt = _dereq_("./tokentype").types;
  6561. var lineBreak = _dereq_("./whitespace").lineBreak;
  6562. var TokContext = exports.TokContext = function TokContext(token, isExpr, preserveSpace, override) {
  6563. _classCallCheck(this, TokContext);
  6564. this.token = token;
  6565. this.isExpr = isExpr;
  6566. this.preserveSpace = preserveSpace;
  6567. this.override = override;
  6568. };
  6569. var types = {
  6570. b_stat: new TokContext("{", false),
  6571. b_expr: new TokContext("{", true),
  6572. b_tmpl: new TokContext("${", true),
  6573. p_stat: new TokContext("(", false),
  6574. p_expr: new TokContext("(", true),
  6575. q_tmpl: new TokContext("`", true, true, function (p) {
  6576. return p.readTmplToken();
  6577. }),
  6578. f_expr: new TokContext("function", true)
  6579. };
  6580. exports.types = types;
  6581. var pp = Parser.prototype;
  6582. pp.initialContext = function () {
  6583. return [types.b_stat];
  6584. };
  6585. pp.braceIsBlock = function (prevType) {
  6586. var parent = undefined;
  6587. if (prevType === tt.colon && (parent = this.curContext()).token == "{") return !parent.isExpr;
  6588. if (prevType === tt._return) return lineBreak.test(this.input.slice(this.lastTokEnd, this.start));
  6589. if (prevType === tt._else || prevType === tt.semi || prevType === tt.eof) return true;
  6590. if (prevType == tt.braceL) return this.curContext() === types.b_stat;
  6591. return !this.exprAllowed;
  6592. };
  6593. pp.updateContext = function (prevType) {
  6594. var update = undefined,
  6595. type = this.type;
  6596. if (type.keyword && prevType == tt.dot) this.exprAllowed = false;else if (update = type.updateContext) update.call(this, prevType);else this.exprAllowed = type.beforeExpr;
  6597. };
  6598. // Token-specific context update code
  6599. tt.parenR.updateContext = tt.braceR.updateContext = function () {
  6600. if (this.context.length == 1) {
  6601. this.exprAllowed = true;
  6602. return;
  6603. }
  6604. var out = this.context.pop();
  6605. if (out === types.b_stat && this.curContext() === types.f_expr) {
  6606. this.context.pop();
  6607. this.exprAllowed = false;
  6608. } else if (out === types.b_tmpl) {
  6609. this.exprAllowed = true;
  6610. } else {
  6611. this.exprAllowed = !out.isExpr;
  6612. }
  6613. };
  6614. tt.braceL.updateContext = function (prevType) {
  6615. this.context.push(this.braceIsBlock(prevType) ? types.b_stat : types.b_expr);
  6616. this.exprAllowed = true;
  6617. };
  6618. tt.dollarBraceL.updateContext = function () {
  6619. this.context.push(types.b_tmpl);
  6620. this.exprAllowed = true;
  6621. };
  6622. tt.parenL.updateContext = function (prevType) {
  6623. var statementParens = prevType === tt._if || prevType === tt._for || prevType === tt._with || prevType === tt._while;
  6624. this.context.push(statementParens ? types.p_stat : types.p_expr);
  6625. this.exprAllowed = true;
  6626. };
  6627. tt.incDec.updateContext = function () {};
  6628. tt._function.updateContext = function () {
  6629. if (this.curContext() !== types.b_stat) this.context.push(types.f_expr);
  6630. this.exprAllowed = false;
  6631. };
  6632. tt.backQuote.updateContext = function () {
  6633. if (this.curContext() === types.q_tmpl) this.context.pop();else this.context.push(types.q_tmpl);
  6634. this.exprAllowed = false;
  6635. };
  6636. // tokExprAllowed stays unchanged
  6637. },{"./state":13,"./tokentype":17,"./whitespace":19}],16:[function(_dereq_,module,exports){
  6638. "use strict";
  6639. var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } };
  6640. exports.__esModule = true;
  6641. var _identifier = _dereq_("./identifier");
  6642. var isIdentifierStart = _identifier.isIdentifierStart;
  6643. var isIdentifierChar = _identifier.isIdentifierChar;
  6644. var _tokentype = _dereq_("./tokentype");
  6645. var tt = _tokentype.types;
  6646. var keywordTypes = _tokentype.keywords;
  6647. var Parser = _dereq_("./state").Parser;
  6648. var SourceLocation = _dereq_("./location").SourceLocation;
  6649. var _whitespace = _dereq_("./whitespace");
  6650. var lineBreak = _whitespace.lineBreak;
  6651. var lineBreakG = _whitespace.lineBreakG;
  6652. var isNewLine = _whitespace.isNewLine;
  6653. var nonASCIIwhitespace = _whitespace.nonASCIIwhitespace;
  6654. // Object type used to represent tokens. Note that normally, tokens
  6655. // simply exist as properties on the parser object. This is only
  6656. // used for the onToken callback and the external tokenizer.
  6657. var Token = exports.Token = function Token(p) {
  6658. _classCallCheck(this, Token);
  6659. this.type = p.type;
  6660. this.value = p.value;
  6661. this.start = p.start;
  6662. this.end = p.end;
  6663. if (p.options.locations) this.loc = new SourceLocation(p, p.startLoc, p.endLoc);
  6664. if (p.options.ranges) this.range = [p.start, p.end];
  6665. };
  6666. // ## Tokenizer
  6667. var pp = Parser.prototype;
  6668. // Are we running under Rhino?
  6669. var isRhino = typeof Packages !== "undefined";
  6670. // Move to the next token
  6671. pp.next = function () {
  6672. if (this.options.onToken) this.options.onToken(new Token(this));
  6673. this.lastTokEnd = this.end;
  6674. this.lastTokStart = this.start;
  6675. this.lastTokEndLoc = this.endLoc;
  6676. this.lastTokStartLoc = this.startLoc;
  6677. this.nextToken();
  6678. };
  6679. pp.getToken = function () {
  6680. this.next();
  6681. return new Token(this);
  6682. };
  6683. // If we're in an ES6 environment, make parsers iterable
  6684. if (typeof Symbol !== "undefined") pp[Symbol.iterator] = function () {
  6685. var self = this;
  6686. return { next: function next() {
  6687. var token = self.getToken();
  6688. return {
  6689. done: token.type === tt.eof,
  6690. value: token
  6691. };
  6692. } };
  6693. };
  6694. // Toggle strict mode. Re-reads the next number or string to please
  6695. // pedantic tests (`"use strict"; 010;` should fail).
  6696. pp.setStrict = function (strict) {
  6697. this.strict = strict;
  6698. if (this.type !== tt.num && this.type !== tt.string) return;
  6699. this.pos = this.start;
  6700. if (this.options.locations) {
  6701. while (this.pos < this.lineStart) {
  6702. this.lineStart = this.input.lastIndexOf("\n", this.lineStart - 2) + 1;
  6703. --this.curLine;
  6704. }
  6705. }
  6706. this.nextToken();
  6707. };
  6708. pp.curContext = function () {
  6709. return this.context[this.context.length - 1];
  6710. };
  6711. // Read a single token, updating the parser object's token-related
  6712. // properties.
  6713. pp.nextToken = function () {
  6714. var curContext = this.curContext();
  6715. if (!curContext || !curContext.preserveSpace) this.skipSpace();
  6716. this.start = this.pos;
  6717. if (this.options.locations) this.startLoc = this.curPosition();
  6718. if (this.pos >= this.input.length) return this.finishToken(tt.eof);
  6719. if (curContext.override) return curContext.override(this);else this.readToken(this.fullCharCodeAtPos());
  6720. };
  6721. pp.readToken = function (code) {
  6722. // Identifier or keyword. '\uXXXX' sequences are allowed in
  6723. // identifiers, so '\' also dispatches to that.
  6724. if (isIdentifierStart(code, this.options.ecmaVersion >= 6) || code === 92 /* '\' */) return this.readWord();
  6725. return this.getTokenFromCode(code);
  6726. };
  6727. pp.fullCharCodeAtPos = function () {
  6728. var code = this.input.charCodeAt(this.pos);
  6729. if (code <= 55295 || code >= 57344) return code;
  6730. var next = this.input.charCodeAt(this.pos + 1);
  6731. return (code << 10) + next - 56613888;
  6732. };
  6733. pp.skipBlockComment = function () {
  6734. var startLoc = this.options.onComment && this.options.locations && this.curPosition();
  6735. var start = this.pos,
  6736. end = this.input.indexOf("*/", this.pos += 2);
  6737. if (end === -1) this.raise(this.pos - 2, "Unterminated comment");
  6738. this.pos = end + 2;
  6739. if (this.options.locations) {
  6740. lineBreakG.lastIndex = start;
  6741. var match = undefined;
  6742. while ((match = lineBreakG.exec(this.input)) && match.index < this.pos) {
  6743. ++this.curLine;
  6744. this.lineStart = match.index + match[0].length;
  6745. }
  6746. }
  6747. if (this.options.onComment) this.options.onComment(true, this.input.slice(start + 2, end), start, this.pos, startLoc, this.options.locations && this.curPosition());
  6748. };
  6749. pp.skipLineComment = function (startSkip) {
  6750. var start = this.pos;
  6751. var startLoc = this.options.onComment && this.options.locations && this.curPosition();
  6752. var ch = this.input.charCodeAt(this.pos += startSkip);
  6753. while (this.pos < this.input.length && ch !== 10 && ch !== 13 && ch !== 8232 && ch !== 8233) {
  6754. ++this.pos;
  6755. ch = this.input.charCodeAt(this.pos);
  6756. }
  6757. if (this.options.onComment) this.options.onComment(false, this.input.slice(start + startSkip, this.pos), start, this.pos, startLoc, this.options.locations && this.curPosition());
  6758. };
  6759. // Called at the start of the parse and after every token. Skips
  6760. // whitespace and comments, and.
  6761. pp.skipSpace = function () {
  6762. while (this.pos < this.input.length) {
  6763. var ch = this.input.charCodeAt(this.pos);
  6764. if (ch === 32) {
  6765. // ' '
  6766. ++this.pos;
  6767. } else if (ch === 13) {
  6768. ++this.pos;
  6769. var next = this.input.charCodeAt(this.pos);
  6770. if (next === 10) {
  6771. ++this.pos;
  6772. }
  6773. if (this.options.locations) {
  6774. ++this.curLine;
  6775. this.lineStart = this.pos;
  6776. }
  6777. } else if (ch === 10 || ch === 8232 || ch === 8233) {
  6778. ++this.pos;
  6779. if (this.options.locations) {
  6780. ++this.curLine;
  6781. this.lineStart = this.pos;
  6782. }
  6783. } else if (ch > 8 && ch < 14) {
  6784. ++this.pos;
  6785. } else if (ch === 47) {
  6786. // '/'
  6787. var next = this.input.charCodeAt(this.pos + 1);
  6788. if (next === 42) {
  6789. // '*'
  6790. this.skipBlockComment();
  6791. } else if (next === 47) {
  6792. // '/'
  6793. this.skipLineComment(2);
  6794. } else break;
  6795. } else if (ch === 160) {
  6796. // '\xa0'
  6797. ++this.pos;
  6798. } else if (ch >= 5760 && nonASCIIwhitespace.test(String.fromCharCode(ch))) {
  6799. ++this.pos;
  6800. } else {
  6801. break;
  6802. }
  6803. }
  6804. };
  6805. // Called at the end of every token. Sets `end`, `val`, and
  6806. // maintains `context` and `exprAllowed`, and skips the space after
  6807. // the token, so that the next one's `start` will point at the
  6808. // right position.
  6809. pp.finishToken = function (type, val) {
  6810. this.end = this.pos;
  6811. if (this.options.locations) this.endLoc = this.curPosition();
  6812. var prevType = this.type;
  6813. this.type = type;
  6814. this.value = val;
  6815. this.updateContext(prevType);
  6816. };
  6817. // ### Token reading
  6818. // This is the function that is called to fetch the next token. It
  6819. // is somewhat obscure, because it works in character codes rather
  6820. // than characters, and because operator parsing has been inlined
  6821. // into it.
  6822. //
  6823. // All in the name of speed.
  6824. //
  6825. pp.readToken_dot = function () {
  6826. var next = this.input.charCodeAt(this.pos + 1);
  6827. if (next >= 48 && next <= 57) return this.readNumber(true);
  6828. var next2 = this.input.charCodeAt(this.pos + 2);
  6829. if (this.options.ecmaVersion >= 6 && next === 46 && next2 === 46) {
  6830. // 46 = dot '.'
  6831. this.pos += 3;
  6832. return this.finishToken(tt.ellipsis);
  6833. } else {
  6834. ++this.pos;
  6835. return this.finishToken(tt.dot);
  6836. }
  6837. };
  6838. pp.readToken_slash = function () {
  6839. // '/'
  6840. var next = this.input.charCodeAt(this.pos + 1);
  6841. if (this.exprAllowed) {
  6842. ++this.pos;return this.readRegexp();
  6843. }
  6844. if (next === 61) return this.finishOp(tt.assign, 2);
  6845. return this.finishOp(tt.slash, 1);
  6846. };
  6847. pp.readToken_mult_modulo = function (code) {
  6848. // '%*'
  6849. var next = this.input.charCodeAt(this.pos + 1);
  6850. if (next === 61) return this.finishOp(tt.assign, 2);
  6851. return this.finishOp(code === 42 ? tt.star : tt.modulo, 1);
  6852. };
  6853. pp.readToken_pipe_amp = function (code) {
  6854. // '|&'
  6855. var next = this.input.charCodeAt(this.pos + 1);
  6856. if (next === code) return this.finishOp(code === 124 ? tt.logicalOR : tt.logicalAND, 2);
  6857. if (next === 61) return this.finishOp(tt.assign, 2);
  6858. return this.finishOp(code === 124 ? tt.bitwiseOR : tt.bitwiseAND, 1);
  6859. };
  6860. pp.readToken_caret = function () {
  6861. // '^'
  6862. var next = this.input.charCodeAt(this.pos + 1);
  6863. if (next === 61) return this.finishOp(tt.assign, 2);
  6864. return this.finishOp(tt.bitwiseXOR, 1);
  6865. };
  6866. pp.readToken_plus_min = function (code) {
  6867. // '+-'
  6868. var next = this.input.charCodeAt(this.pos + 1);
  6869. if (next === code) {
  6870. if (next == 45 && this.input.charCodeAt(this.pos + 2) == 62 && lineBreak.test(this.input.slice(this.lastTokEnd, this.pos))) {
  6871. // A `-->` line comment
  6872. this.skipLineComment(3);
  6873. this.skipSpace();
  6874. return this.nextToken();
  6875. }
  6876. return this.finishOp(tt.incDec, 2);
  6877. }
  6878. if (next === 61) return this.finishOp(tt.assign, 2);
  6879. return this.finishOp(tt.plusMin, 1);
  6880. };
  6881. pp.readToken_lt_gt = function (code) {
  6882. // '<>'
  6883. var next = this.input.charCodeAt(this.pos + 1);
  6884. var size = 1;
  6885. if (next === code) {
  6886. size = code === 62 && this.input.charCodeAt(this.pos + 2) === 62 ? 3 : 2;
  6887. if (this.input.charCodeAt(this.pos + size) === 61) return this.finishOp(tt.assign, size + 1);
  6888. return this.finishOp(tt.bitShift, size);
  6889. }
  6890. if (next == 33 && code == 60 && this.input.charCodeAt(this.pos + 2) == 45 && this.input.charCodeAt(this.pos + 3) == 45) {
  6891. if (this.inModule) this.unexpected();
  6892. // `<!--`, an XML-style comment that should be interpreted as a line comment
  6893. this.skipLineComment(4);
  6894. this.skipSpace();
  6895. return this.nextToken();
  6896. }
  6897. if (next === 61) size = this.input.charCodeAt(this.pos + 2) === 61 ? 3 : 2;
  6898. return this.finishOp(tt.relational, size);
  6899. };
  6900. pp.readToken_eq_excl = function (code) {
  6901. // '=!'
  6902. var next = this.input.charCodeAt(this.pos + 1);
  6903. if (next === 61) return this.finishOp(tt.equality, this.input.charCodeAt(this.pos + 2) === 61 ? 3 : 2);
  6904. if (code === 61 && next === 62 && this.options.ecmaVersion >= 6) {
  6905. // '=>'
  6906. this.pos += 2;
  6907. return this.finishToken(tt.arrow);
  6908. }
  6909. return this.finishOp(code === 61 ? tt.eq : tt.prefix, 1);
  6910. };
  6911. pp.getTokenFromCode = function (code) {
  6912. switch (code) {
  6913. // The interpretation of a dot depends on whether it is followed
  6914. // by a digit or another two dots.
  6915. case 46:
  6916. // '.'
  6917. return this.readToken_dot();
  6918. // Punctuation tokens.
  6919. case 40:
  6920. ++this.pos;return this.finishToken(tt.parenL);
  6921. case 41:
  6922. ++this.pos;return this.finishToken(tt.parenR);
  6923. case 59:
  6924. ++this.pos;return this.finishToken(tt.semi);
  6925. case 44:
  6926. ++this.pos;return this.finishToken(tt.comma);
  6927. case 91:
  6928. ++this.pos;return this.finishToken(tt.bracketL);
  6929. case 93:
  6930. ++this.pos;return this.finishToken(tt.bracketR);
  6931. case 123:
  6932. ++this.pos;return this.finishToken(tt.braceL);
  6933. case 125:
  6934. ++this.pos;return this.finishToken(tt.braceR);
  6935. case 58:
  6936. ++this.pos;return this.finishToken(tt.colon);
  6937. case 63:
  6938. ++this.pos;return this.finishToken(tt.question);
  6939. case 96:
  6940. // '`'
  6941. if (this.options.ecmaVersion < 6) break;
  6942. ++this.pos;
  6943. return this.finishToken(tt.backQuote);
  6944. case 48:
  6945. // '0'
  6946. var next = this.input.charCodeAt(this.pos + 1);
  6947. if (next === 120 || next === 88) return this.readRadixNumber(16); // '0x', '0X' - hex number
  6948. if (this.options.ecmaVersion >= 6) {
  6949. if (next === 111 || next === 79) return this.readRadixNumber(8); // '0o', '0O' - octal number
  6950. if (next === 98 || next === 66) return this.readRadixNumber(2); // '0b', '0B' - binary number
  6951. }
  6952. // Anything else beginning with a digit is an integer, octal
  6953. // number, or float.
  6954. case 49:case 50:case 51:case 52:case 53:case 54:case 55:case 56:case 57:
  6955. // 1-9
  6956. return this.readNumber(false);
  6957. // Quotes produce strings.
  6958. case 34:case 39:
  6959. // '"', "'"
  6960. return this.readString(code);
  6961. // Operators are parsed inline in tiny state machines. '=' (61) is
  6962. // often referred to. `finishOp` simply skips the amount of
  6963. // characters it is given as second argument, and returns a token
  6964. // of the type given by its first argument.
  6965. case 47:
  6966. // '/'
  6967. return this.readToken_slash();
  6968. case 37:case 42:
  6969. // '%*'
  6970. return this.readToken_mult_modulo(code);
  6971. case 124:case 38:
  6972. // '|&'
  6973. return this.readToken_pipe_amp(code);
  6974. case 94:
  6975. // '^'
  6976. return this.readToken_caret();
  6977. case 43:case 45:
  6978. // '+-'
  6979. return this.readToken_plus_min(code);
  6980. case 60:case 62:
  6981. // '<>'
  6982. return this.readToken_lt_gt(code);
  6983. case 61:case 33:
  6984. // '=!'
  6985. return this.readToken_eq_excl(code);
  6986. case 126:
  6987. // '~'
  6988. return this.finishOp(tt.prefix, 1);
  6989. }
  6990. this.raise(this.pos, "Unexpected character '" + codePointToString(code) + "'");
  6991. };
  6992. pp.finishOp = function (type, size) {
  6993. var str = this.input.slice(this.pos, this.pos + size);
  6994. this.pos += size;
  6995. return this.finishToken(type, str);
  6996. };
  6997. var regexpUnicodeSupport = false;
  6998. try {
  6999. new RegExp("￿", "u");regexpUnicodeSupport = true;
  7000. } catch (e) {}
  7001. // Parse a regular expression. Some context-awareness is necessary,
  7002. // since a '/' inside a '[]' set does not end the expression.
  7003. pp.readRegexp = function () {
  7004. var escaped = undefined,
  7005. inClass = undefined,
  7006. start = this.pos;
  7007. for (;;) {
  7008. if (this.pos >= this.input.length) this.raise(start, "Unterminated regular expression");
  7009. var ch = this.input.charAt(this.pos);
  7010. if (lineBreak.test(ch)) this.raise(start, "Unterminated regular expression");
  7011. if (!escaped) {
  7012. if (ch === "[") inClass = true;else if (ch === "]" && inClass) inClass = false;else if (ch === "/" && !inClass) break;
  7013. escaped = ch === "\\";
  7014. } else escaped = false;
  7015. ++this.pos;
  7016. }
  7017. var content = this.input.slice(start, this.pos);
  7018. ++this.pos;
  7019. // Need to use `readWord1` because '\uXXXX' sequences are allowed
  7020. // here (don't ask).
  7021. var mods = this.readWord1();
  7022. var tmp = content;
  7023. if (mods) {
  7024. var validFlags = /^[gmsiy]*$/;
  7025. if (this.options.ecmaVersion >= 6) validFlags = /^[gmsiyu]*$/;
  7026. if (!validFlags.test(mods)) this.raise(start, "Invalid regular expression flag");
  7027. if (mods.indexOf("u") >= 0 && !regexpUnicodeSupport) {
  7028. // Replace each astral symbol and every Unicode escape sequence that
  7029. // possibly represents an astral symbol or a paired surrogate with a
  7030. // single ASCII symbol to avoid throwing on regular expressions that
  7031. // are only valid in combination with the `/u` flag.
  7032. // Note: replacing with the ASCII symbol `x` might cause false
  7033. // negatives in unlikely scenarios. For example, `[\u{61}-b]` is a
  7034. // perfectly valid pattern that is equivalent to `[a-b]`, but it would
  7035. // be replaced by `[x-b]` which throws an error.
  7036. tmp = tmp.replace(/\\u([a-fA-F0-9]{4})|\\u\{([0-9a-fA-F]+)\}|[\uD800-\uDBFF][\uDC00-\uDFFF]/g, "x");
  7037. }
  7038. }
  7039. // Detect invalid regular expressions.
  7040. var value = null;
  7041. // Rhino's regular expression parser is flaky and throws uncatchable exceptions,
  7042. // so don't do detection if we are running under Rhino
  7043. if (!isRhino) {
  7044. try {
  7045. new RegExp(tmp);
  7046. } catch (e) {
  7047. if (e instanceof SyntaxError) this.raise(start, "Error parsing regular expression: " + e.message);
  7048. this.raise(e);
  7049. }
  7050. // Get a regular expression object for this pattern-flag pair, or `null` in
  7051. // case the current environment doesn't support the flags it uses.
  7052. try {
  7053. value = new RegExp(content, mods);
  7054. } catch (err) {}
  7055. }
  7056. return this.finishToken(tt.regexp, { pattern: content, flags: mods, value: value });
  7057. };
  7058. // Read an integer in the given radix. Return null if zero digits
  7059. // were read, the integer value otherwise. When `len` is given, this
  7060. // will return `null` unless the integer has exactly `len` digits.
  7061. pp.readInt = function (radix, len) {
  7062. var start = this.pos,
  7063. total = 0;
  7064. for (var i = 0, e = len == null ? Infinity : len; i < e; ++i) {
  7065. var code = this.input.charCodeAt(this.pos),
  7066. val = undefined;
  7067. if (code >= 97) val = code - 97 + 10; // a
  7068. else if (code >= 65) val = code - 65 + 10; // A
  7069. else if (code >= 48 && code <= 57) val = code - 48; // 0-9
  7070. else val = Infinity;
  7071. if (val >= radix) break;
  7072. ++this.pos;
  7073. total = total * radix + val;
  7074. }
  7075. if (this.pos === start || len != null && this.pos - start !== len) return null;
  7076. return total;
  7077. };
  7078. pp.readRadixNumber = function (radix) {
  7079. this.pos += 2; // 0x
  7080. var val = this.readInt(radix);
  7081. if (val == null) this.raise(this.start + 2, "Expected number in radix " + radix);
  7082. if (isIdentifierStart(this.fullCharCodeAtPos())) this.raise(this.pos, "Identifier directly after number");
  7083. return this.finishToken(tt.num, val);
  7084. };
  7085. // Read an integer, octal integer, or floating-point number.
  7086. pp.readNumber = function (startsWithDot) {
  7087. var start = this.pos,
  7088. isFloat = false,
  7089. octal = this.input.charCodeAt(this.pos) === 48;
  7090. if (!startsWithDot && this.readInt(10) === null) this.raise(start, "Invalid number");
  7091. if (this.input.charCodeAt(this.pos) === 46) {
  7092. ++this.pos;
  7093. this.readInt(10);
  7094. isFloat = true;
  7095. }
  7096. var next = this.input.charCodeAt(this.pos);
  7097. if (next === 69 || next === 101) {
  7098. // 'eE'
  7099. next = this.input.charCodeAt(++this.pos);
  7100. if (next === 43 || next === 45) ++this.pos; // '+-'
  7101. if (this.readInt(10) === null) this.raise(start, "Invalid number");
  7102. isFloat = true;
  7103. }
  7104. if (isIdentifierStart(this.fullCharCodeAtPos())) this.raise(this.pos, "Identifier directly after number");
  7105. var str = this.input.slice(start, this.pos),
  7106. val = undefined;
  7107. if (isFloat) val = parseFloat(str);else if (!octal || str.length === 1) val = parseInt(str, 10);else if (/[89]/.test(str) || this.strict) this.raise(start, "Invalid number");else val = parseInt(str, 8);
  7108. return this.finishToken(tt.num, val);
  7109. };
  7110. // Read a string value, interpreting backslash-escapes.
  7111. pp.readCodePoint = function () {
  7112. var ch = this.input.charCodeAt(this.pos),
  7113. code = undefined;
  7114. if (ch === 123) {
  7115. if (this.options.ecmaVersion < 6) this.unexpected();
  7116. ++this.pos;
  7117. code = this.readHexChar(this.input.indexOf("}", this.pos) - this.pos);
  7118. ++this.pos;
  7119. if (code > 1114111) this.unexpected();
  7120. } else {
  7121. code = this.readHexChar(4);
  7122. }
  7123. return code;
  7124. };
  7125. function codePointToString(code) {
  7126. // UTF-16 Decoding
  7127. if (code <= 65535) {
  7128. return String.fromCharCode(code);
  7129. }return String.fromCharCode((code - 65536 >> 10) + 55296, (code - 65536 & 1023) + 56320);
  7130. }
  7131. pp.readString = function (quote) {
  7132. var out = "",
  7133. chunkStart = ++this.pos;
  7134. for (;;) {
  7135. if (this.pos >= this.input.length) this.raise(this.start, "Unterminated string constant");
  7136. var ch = this.input.charCodeAt(this.pos);
  7137. if (ch === quote) break;
  7138. if (ch === 92) {
  7139. // '\'
  7140. out += this.input.slice(chunkStart, this.pos);
  7141. out += this.readEscapedChar();
  7142. chunkStart = this.pos;
  7143. } else {
  7144. if (isNewLine(ch)) this.raise(this.start, "Unterminated string constant");
  7145. ++this.pos;
  7146. }
  7147. }
  7148. out += this.input.slice(chunkStart, this.pos++);
  7149. return this.finishToken(tt.string, out);
  7150. };
  7151. // Reads template string tokens.
  7152. pp.readTmplToken = function () {
  7153. var out = "",
  7154. chunkStart = this.pos;
  7155. for (;;) {
  7156. if (this.pos >= this.input.length) this.raise(this.start, "Unterminated template");
  7157. var ch = this.input.charCodeAt(this.pos);
  7158. if (ch === 96 || ch === 36 && this.input.charCodeAt(this.pos + 1) === 123) {
  7159. // '`', '${'
  7160. if (this.pos === this.start && this.type === tt.template) {
  7161. if (ch === 36) {
  7162. this.pos += 2;
  7163. return this.finishToken(tt.dollarBraceL);
  7164. } else {
  7165. ++this.pos;
  7166. return this.finishToken(tt.backQuote);
  7167. }
  7168. }
  7169. out += this.input.slice(chunkStart, this.pos);
  7170. return this.finishToken(tt.template, out);
  7171. }
  7172. if (ch === 92) {
  7173. // '\'
  7174. out += this.input.slice(chunkStart, this.pos);
  7175. out += this.readEscapedChar();
  7176. chunkStart = this.pos;
  7177. } else if (isNewLine(ch)) {
  7178. out += this.input.slice(chunkStart, this.pos);
  7179. ++this.pos;
  7180. if (ch === 13 && this.input.charCodeAt(this.pos) === 10) {
  7181. ++this.pos;
  7182. out += "\n";
  7183. } else {
  7184. out += String.fromCharCode(ch);
  7185. }
  7186. if (this.options.locations) {
  7187. ++this.curLine;
  7188. this.lineStart = this.pos;
  7189. }
  7190. chunkStart = this.pos;
  7191. } else {
  7192. ++this.pos;
  7193. }
  7194. }
  7195. };
  7196. // Used to read escaped characters
  7197. pp.readEscapedChar = function () {
  7198. var ch = this.input.charCodeAt(++this.pos);
  7199. var octal = /^[0-7]+/.exec(this.input.slice(this.pos, this.pos + 3));
  7200. if (octal) octal = octal[0];
  7201. while (octal && parseInt(octal, 8) > 255) octal = octal.slice(0, -1);
  7202. if (octal === "0") octal = null;
  7203. ++this.pos;
  7204. if (octal) {
  7205. if (this.strict) this.raise(this.pos - 2, "Octal literal in strict mode");
  7206. this.pos += octal.length - 1;
  7207. return String.fromCharCode(parseInt(octal, 8));
  7208. } else {
  7209. switch (ch) {
  7210. case 110:
  7211. return "\n"; // 'n' -> '\n'
  7212. case 114:
  7213. return "\r"; // 'r' -> '\r'
  7214. case 120:
  7215. return String.fromCharCode(this.readHexChar(2)); // 'x'
  7216. case 117:
  7217. return codePointToString(this.readCodePoint()); // 'u'
  7218. case 116:
  7219. return "\t"; // 't' -> '\t'
  7220. case 98:
  7221. return "\b"; // 'b' -> '\b'
  7222. case 118:
  7223. return "\u000b"; // 'v' -> '\u000b'
  7224. case 102:
  7225. return "\f"; // 'f' -> '\f'
  7226. case 48:
  7227. return "\u0000"; // 0 -> '\0'
  7228. case 13:
  7229. if (this.input.charCodeAt(this.pos) === 10) ++this.pos; // '\r\n'
  7230. case 10:
  7231. // ' \n'
  7232. if (this.options.locations) {
  7233. this.lineStart = this.pos;++this.curLine;
  7234. }
  7235. return "";
  7236. default:
  7237. return String.fromCharCode(ch);
  7238. }
  7239. }
  7240. };
  7241. // Used to read character escape sequences ('\x', '\u', '\U').
  7242. pp.readHexChar = function (len) {
  7243. var n = this.readInt(16, len);
  7244. if (n === null) this.raise(this.start, "Bad character escape sequence");
  7245. return n;
  7246. };
  7247. // Used to signal to callers of `readWord1` whether the word
  7248. // contained any escape sequences. This is needed because words with
  7249. // escape sequences must not be interpreted as keywords.
  7250. var containsEsc;
  7251. // Read an identifier, and return it as a string. Sets `containsEsc`
  7252. // to whether the word contained a '\u' escape.
  7253. //
  7254. // Incrementally adds only escaped chars, adding other chunks as-is
  7255. // as a micro-optimization.
  7256. pp.readWord1 = function () {
  7257. containsEsc = false;
  7258. var word = "",
  7259. first = true,
  7260. chunkStart = this.pos;
  7261. var astral = this.options.ecmaVersion >= 6;
  7262. while (this.pos < this.input.length) {
  7263. var ch = this.fullCharCodeAtPos();
  7264. if (isIdentifierChar(ch, astral)) {
  7265. this.pos += ch <= 65535 ? 1 : 2;
  7266. } else if (ch === 92) {
  7267. // "\"
  7268. containsEsc = true;
  7269. word += this.input.slice(chunkStart, this.pos);
  7270. var escStart = this.pos;
  7271. if (this.input.charCodeAt(++this.pos) != 117) // "u"
  7272. this.raise(this.pos, "Expecting Unicode escape sequence \\uXXXX");
  7273. ++this.pos;
  7274. var esc = this.readCodePoint();
  7275. if (!(first ? isIdentifierStart : isIdentifierChar)(esc, astral)) this.raise(escStart, "Invalid Unicode escape");
  7276. word += codePointToString(esc);
  7277. chunkStart = this.pos;
  7278. } else {
  7279. break;
  7280. }
  7281. first = false;
  7282. }
  7283. return word + this.input.slice(chunkStart, this.pos);
  7284. };
  7285. // Read an identifier or keyword token. Will check for reserved
  7286. // words when necessary.
  7287. pp.readWord = function () {
  7288. var word = this.readWord1();
  7289. var type = tt.name;
  7290. if ((this.options.ecmaVersion >= 6 || !containsEsc) && this.isKeyword(word)) type = keywordTypes[word];
  7291. return this.finishToken(type, word);
  7292. };
  7293. },{"./identifier":7,"./location":8,"./state":13,"./tokentype":17,"./whitespace":19}],17:[function(_dereq_,module,exports){
  7294. "use strict";
  7295. var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } };
  7296. exports.__esModule = true;
  7297. // ## Token types
  7298. // The assignment of fine-grained, information-carrying type objects
  7299. // allows the tokenizer to store the information it has about a
  7300. // token in a way that is very cheap for the parser to look up.
  7301. // All token type variables start with an underscore, to make them
  7302. // easy to recognize.
  7303. // The `beforeExpr` property is used to disambiguate between regular
  7304. // expressions and divisions. It is set on all token types that can
  7305. // be followed by an expression (thus, a slash after them would be a
  7306. // regular expression).
  7307. //
  7308. // `isLoop` marks a keyword as starting a loop, which is important
  7309. // to know when parsing a label, in order to allow or disallow
  7310. // continue jumps to that label.
  7311. var TokenType = exports.TokenType = function TokenType(label) {
  7312. var conf = arguments[1] === undefined ? {} : arguments[1];
  7313. _classCallCheck(this, TokenType);
  7314. this.label = label;
  7315. this.keyword = conf.keyword;
  7316. this.beforeExpr = !!conf.beforeExpr;
  7317. this.startsExpr = !!conf.startsExpr;
  7318. this.isLoop = !!conf.isLoop;
  7319. this.isAssign = !!conf.isAssign;
  7320. this.prefix = !!conf.prefix;
  7321. this.postfix = !!conf.postfix;
  7322. this.binop = conf.binop || null;
  7323. this.updateContext = null;
  7324. };
  7325. function binop(name, prec) {
  7326. return new TokenType(name, { beforeExpr: true, binop: prec });
  7327. }
  7328. var beforeExpr = { beforeExpr: true },
  7329. startsExpr = { startsExpr: true };
  7330. var types = {
  7331. num: new TokenType("num", startsExpr),
  7332. regexp: new TokenType("regexp", startsExpr),
  7333. string: new TokenType("string", startsExpr),
  7334. name: new TokenType("name", startsExpr),
  7335. eof: new TokenType("eof"),
  7336. // Punctuation token types.
  7337. bracketL: new TokenType("[", { beforeExpr: true, startsExpr: true }),
  7338. bracketR: new TokenType("]"),
  7339. braceL: new TokenType("{", { beforeExpr: true, startsExpr: true }),
  7340. braceR: new TokenType("}"),
  7341. parenL: new TokenType("(", { beforeExpr: true, startsExpr: true }),
  7342. parenR: new TokenType(")"),
  7343. comma: new TokenType(",", beforeExpr),
  7344. semi: new TokenType(";", beforeExpr),
  7345. colon: new TokenType(":", beforeExpr),
  7346. dot: new TokenType("."),
  7347. question: new TokenType("?", beforeExpr),
  7348. arrow: new TokenType("=>", beforeExpr),
  7349. template: new TokenType("template"),
  7350. ellipsis: new TokenType("...", beforeExpr),
  7351. backQuote: new TokenType("`", startsExpr),
  7352. dollarBraceL: new TokenType("${", { beforeExpr: true, startsExpr: true }),
  7353. // Operators. These carry several kinds of properties to help the
  7354. // parser use them properly (the presence of these properties is
  7355. // what categorizes them as operators).
  7356. //
  7357. // `binop`, when present, specifies that this operator is a binary
  7358. // operator, and will refer to its precedence.
  7359. //
  7360. // `prefix` and `postfix` mark the operator as a prefix or postfix
  7361. // unary operator.
  7362. //
  7363. // `isAssign` marks all of `=`, `+=`, `-=` etcetera, which act as
  7364. // binary operators with a very low precedence, that should result
  7365. // in AssignmentExpression nodes.
  7366. eq: new TokenType("=", { beforeExpr: true, isAssign: true }),
  7367. assign: new TokenType("_=", { beforeExpr: true, isAssign: true }),
  7368. incDec: new TokenType("++/--", { prefix: true, postfix: true, startsExpr: true }),
  7369. prefix: new TokenType("prefix", { beforeExpr: true, prefix: true, startsExpr: true }),
  7370. logicalOR: binop("||", 1),
  7371. logicalAND: binop("&&", 2),
  7372. bitwiseOR: binop("|", 3),
  7373. bitwiseXOR: binop("^", 4),
  7374. bitwiseAND: binop("&", 5),
  7375. equality: binop("==/!=", 6),
  7376. relational: binop("</>", 7),
  7377. bitShift: binop("<</>>", 8),
  7378. plusMin: new TokenType("+/-", { beforeExpr: true, binop: 9, prefix: true, startsExpr: true }),
  7379. modulo: binop("%", 10),
  7380. star: binop("*", 10),
  7381. slash: binop("/", 10)
  7382. };
  7383. exports.types = types;
  7384. // Map keyword names to token types.
  7385. var keywords = {};
  7386. exports.keywords = keywords;
  7387. // Succinct definitions of keyword token types
  7388. function kw(name) {
  7389. var options = arguments[1] === undefined ? {} : arguments[1];
  7390. options.keyword = name;
  7391. keywords[name] = types["_" + name] = new TokenType(name, options);
  7392. }
  7393. kw("break");
  7394. kw("case", beforeExpr);
  7395. kw("catch");
  7396. kw("continue");
  7397. kw("debugger");
  7398. kw("default");
  7399. kw("do", { isLoop: true });
  7400. kw("else", beforeExpr);
  7401. kw("finally");
  7402. kw("for", { isLoop: true });
  7403. kw("function", startsExpr);
  7404. kw("if");
  7405. kw("return", beforeExpr);
  7406. kw("switch");
  7407. kw("throw", beforeExpr);
  7408. kw("try");
  7409. kw("var");
  7410. kw("let");
  7411. kw("const");
  7412. kw("while", { isLoop: true });
  7413. kw("with");
  7414. kw("new", { beforeExpr: true, startsExpr: true });
  7415. kw("this", startsExpr);
  7416. kw("super", startsExpr);
  7417. kw("class");
  7418. kw("extends", beforeExpr);
  7419. kw("export");
  7420. kw("import");
  7421. kw("yield", { beforeExpr: true, startsExpr: true });
  7422. kw("null", startsExpr);
  7423. kw("true", startsExpr);
  7424. kw("false", startsExpr);
  7425. kw("in", { beforeExpr: true, binop: 7 });
  7426. kw("instanceof", { beforeExpr: true, binop: 7 });
  7427. kw("typeof", { beforeExpr: true, prefix: true, startsExpr: true });
  7428. kw("void", { beforeExpr: true, prefix: true, startsExpr: true });
  7429. kw("delete", { beforeExpr: true, prefix: true, startsExpr: true });
  7430. },{}],18:[function(_dereq_,module,exports){
  7431. "use strict";
  7432. exports.isArray = isArray;
  7433. // Checks if an object has a property.
  7434. exports.has = has;
  7435. exports.__esModule = true;
  7436. function isArray(obj) {
  7437. return Object.prototype.toString.call(obj) === "[object Array]";
  7438. }
  7439. function has(obj, propName) {
  7440. return Object.prototype.hasOwnProperty.call(obj, propName);
  7441. }
  7442. },{}],19:[function(_dereq_,module,exports){
  7443. "use strict";
  7444. exports.isNewLine = isNewLine;
  7445. exports.__esModule = true;
  7446. // Matches a whole line break (where CRLF is considered a single
  7447. // line break). Used to count lines.
  7448. var lineBreak = /\r\n?|\n|\u2028|\u2029/;
  7449. exports.lineBreak = lineBreak;
  7450. var lineBreakG = new RegExp(lineBreak.source, "g");
  7451. exports.lineBreakG = lineBreakG;
  7452. function isNewLine(code) {
  7453. return code === 10 || code === 13 || code === 8232 || code == 8233;
  7454. }
  7455. var nonASCIIwhitespace = /[\u1680\u180e\u2000-\u200a\u202f\u205f\u3000\ufeff]/;
  7456. exports.nonASCIIwhitespace = nonASCIIwhitespace;
  7457. },{}]},{},[1])(1)
  7458. });
  7459. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  7460. },{}],33:[function(require,module,exports){
  7461. (function (global){
  7462. (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}(g.acorn || (g.acorn = {})).walk = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){
  7463. "use strict";
  7464. var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } };
  7465. // AST walker module for Mozilla Parser API compatible trees
  7466. // A simple walk is one where you simply specify callbacks to be
  7467. // called on specific nodes. The last two arguments are optional. A
  7468. // simple use would be
  7469. //
  7470. // walk.simple(myTree, {
  7471. // Expression: function(node) { ... }
  7472. // });
  7473. //
  7474. // to do something with all expressions. All Parser API node types
  7475. // can be used to identify node types, as well as Expression,
  7476. // Statement, and ScopeBody, which denote categories of nodes.
  7477. //
  7478. // The base argument can be used to pass a custom (recursive)
  7479. // walker, and state can be used to give this walked an initial
  7480. // state.
  7481. exports.simple = simple;
  7482. // An ancestor walk builds up an array of ancestor nodes (including
  7483. // the current node) and passes them to the callback as the state parameter.
  7484. exports.ancestor = ancestor;
  7485. // A recursive walk is one where your functions override the default
  7486. // walkers. They can modify and replace the state parameter that's
  7487. // threaded through the walk, and can opt how and whether to walk
  7488. // their child nodes (by calling their third argument on these
  7489. // nodes).
  7490. exports.recursive = recursive;
  7491. // Find a node with a given start, end, and type (all are optional,
  7492. // null can be used as wildcard). Returns a {node, state} object, or
  7493. // undefined when it doesn't find a matching node.
  7494. exports.findNodeAt = findNodeAt;
  7495. // Find the innermost node of a given type that contains the given
  7496. // position. Interface similar to findNodeAt.
  7497. exports.findNodeAround = findNodeAround;
  7498. // Find the outermost matching node after a given position.
  7499. exports.findNodeAfter = findNodeAfter;
  7500. // Find the outermost matching node before a given position.
  7501. exports.findNodeBefore = findNodeBefore;
  7502. // Used to create a custom walker. Will fill in all missing node
  7503. // type properties with the defaults.
  7504. exports.make = make;
  7505. exports.__esModule = true;
  7506. function simple(node, visitors, base, state) {
  7507. if (!base) base = exports.base;(function c(node, st, override) {
  7508. var type = override || node.type,
  7509. found = visitors[type];
  7510. base[type](node, st, c);
  7511. if (found) found(node, st);
  7512. })(node, state);
  7513. }
  7514. function ancestor(node, visitors, base, state) {
  7515. if (!base) base = exports.base;
  7516. if (!state) state = [];(function c(node, st, override) {
  7517. var type = override || node.type,
  7518. found = visitors[type];
  7519. if (node != st[st.length - 1]) {
  7520. st = st.slice();
  7521. st.push(node);
  7522. }
  7523. base[type](node, st, c);
  7524. if (found) found(node, st);
  7525. })(node, state);
  7526. }
  7527. function recursive(node, state, funcs, base) {
  7528. var visitor = funcs ? exports.make(funcs, base) : base;(function c(node, st, override) {
  7529. visitor[override || node.type](node, st, c);
  7530. })(node, state);
  7531. }
  7532. function makeTest(test) {
  7533. if (typeof test == "string") {
  7534. return function (type) {
  7535. return type == test;
  7536. };
  7537. } else if (!test) {
  7538. return function () {
  7539. return true;
  7540. };
  7541. } else {
  7542. return test;
  7543. }
  7544. }
  7545. var Found = function Found(node, state) {
  7546. _classCallCheck(this, Found);
  7547. this.node = node;this.state = state;
  7548. };
  7549. function findNodeAt(node, start, end, test, base, state) {
  7550. test = makeTest(test);
  7551. if (!base) base = exports.base;
  7552. try {
  7553. ;(function c(node, st, override) {
  7554. var type = override || node.type;
  7555. if ((start == null || node.start <= start) && (end == null || node.end >= end)) base[type](node, st, c);
  7556. if (test(type, node) && (start == null || node.start == start) && (end == null || node.end == end)) throw new Found(node, st);
  7557. })(node, state);
  7558. } catch (e) {
  7559. if (e instanceof Found) {
  7560. return e;
  7561. }throw e;
  7562. }
  7563. }
  7564. function findNodeAround(node, pos, test, base, state) {
  7565. test = makeTest(test);
  7566. if (!base) base = exports.base;
  7567. try {
  7568. ;(function c(node, st, override) {
  7569. var type = override || node.type;
  7570. if (node.start > pos || node.end < pos) {
  7571. return;
  7572. }base[type](node, st, c);
  7573. if (test(type, node)) throw new Found(node, st);
  7574. })(node, state);
  7575. } catch (e) {
  7576. if (e instanceof Found) {
  7577. return e;
  7578. }throw e;
  7579. }
  7580. }
  7581. function findNodeAfter(node, pos, test, base, state) {
  7582. test = makeTest(test);
  7583. if (!base) base = exports.base;
  7584. try {
  7585. ;(function c(node, st, override) {
  7586. if (node.end < pos) {
  7587. return;
  7588. }var type = override || node.type;
  7589. if (node.start >= pos && test(type, node)) throw new Found(node, st);
  7590. base[type](node, st, c);
  7591. })(node, state);
  7592. } catch (e) {
  7593. if (e instanceof Found) {
  7594. return e;
  7595. }throw e;
  7596. }
  7597. }
  7598. function findNodeBefore(node, pos, test, base, state) {
  7599. test = makeTest(test);
  7600. if (!base) base = exports.base;
  7601. var max = undefined;(function c(node, st, override) {
  7602. if (node.start > pos) {
  7603. return;
  7604. }var type = override || node.type;
  7605. if (node.end <= pos && (!max || max.node.end < node.end) && test(type, node)) max = new Found(node, st);
  7606. base[type](node, st, c);
  7607. })(node, state);
  7608. return max;
  7609. }
  7610. function make(funcs, base) {
  7611. if (!base) base = exports.base;
  7612. var visitor = {};
  7613. for (var type in base) visitor[type] = base[type];
  7614. for (var type in funcs) visitor[type] = funcs[type];
  7615. return visitor;
  7616. }
  7617. function skipThrough(node, st, c) {
  7618. c(node, st);
  7619. }
  7620. function ignore(_node, _st, _c) {}
  7621. // Node walkers.
  7622. var base = {};
  7623. exports.base = base;
  7624. base.Program = base.BlockStatement = function (node, st, c) {
  7625. for (var i = 0; i < node.body.length; ++i) {
  7626. c(node.body[i], st, "Statement");
  7627. }
  7628. };
  7629. base.Statement = skipThrough;
  7630. base.EmptyStatement = ignore;
  7631. base.ExpressionStatement = base.ParenthesizedExpression = function (node, st, c) {
  7632. return c(node.expression, st, "Expression");
  7633. };
  7634. base.IfStatement = function (node, st, c) {
  7635. c(node.test, st, "Expression");
  7636. c(node.consequent, st, "Statement");
  7637. if (node.alternate) c(node.alternate, st, "Statement");
  7638. };
  7639. base.LabeledStatement = function (node, st, c) {
  7640. return c(node.body, st, "Statement");
  7641. };
  7642. base.BreakStatement = base.ContinueStatement = ignore;
  7643. base.WithStatement = function (node, st, c) {
  7644. c(node.object, st, "Expression");
  7645. c(node.body, st, "Statement");
  7646. };
  7647. base.SwitchStatement = function (node, st, c) {
  7648. c(node.discriminant, st, "Expression");
  7649. for (var i = 0; i < node.cases.length; ++i) {
  7650. var cs = node.cases[i];
  7651. if (cs.test) c(cs.test, st, "Expression");
  7652. for (var j = 0; j < cs.consequent.length; ++j) {
  7653. c(cs.consequent[j], st, "Statement");
  7654. }
  7655. }
  7656. };
  7657. base.ReturnStatement = base.YieldExpression = function (node, st, c) {
  7658. if (node.argument) c(node.argument, st, "Expression");
  7659. };
  7660. base.ThrowStatement = base.SpreadElement = base.RestElement = function (node, st, c) {
  7661. return c(node.argument, st, "Expression");
  7662. };
  7663. base.TryStatement = function (node, st, c) {
  7664. c(node.block, st, "Statement");
  7665. if (node.handler) c(node.handler.body, st, "ScopeBody");
  7666. if (node.finalizer) c(node.finalizer, st, "Statement");
  7667. };
  7668. base.WhileStatement = base.DoWhileStatement = function (node, st, c) {
  7669. c(node.test, st, "Expression");
  7670. c(node.body, st, "Statement");
  7671. };
  7672. base.ForStatement = function (node, st, c) {
  7673. if (node.init) c(node.init, st, "ForInit");
  7674. if (node.test) c(node.test, st, "Expression");
  7675. if (node.update) c(node.update, st, "Expression");
  7676. c(node.body, st, "Statement");
  7677. };
  7678. base.ForInStatement = base.ForOfStatement = function (node, st, c) {
  7679. c(node.left, st, "ForInit");
  7680. c(node.right, st, "Expression");
  7681. c(node.body, st, "Statement");
  7682. };
  7683. base.ForInit = function (node, st, c) {
  7684. if (node.type == "VariableDeclaration") c(node, st);else c(node, st, "Expression");
  7685. };
  7686. base.DebuggerStatement = ignore;
  7687. base.FunctionDeclaration = function (node, st, c) {
  7688. return c(node, st, "Function");
  7689. };
  7690. base.VariableDeclaration = function (node, st, c) {
  7691. for (var i = 0; i < node.declarations.length; ++i) {
  7692. var decl = node.declarations[i];
  7693. if (decl.init) c(decl.init, st, "Expression");
  7694. }
  7695. };
  7696. base.Function = function (node, st, c) {
  7697. return c(node.body, st, "ScopeBody");
  7698. };
  7699. base.ScopeBody = function (node, st, c) {
  7700. return c(node, st, "Statement");
  7701. };
  7702. base.Expression = skipThrough;
  7703. base.ThisExpression = base.Super = base.MetaProperty = ignore;
  7704. base.ArrayExpression = base.ArrayPattern = function (node, st, c) {
  7705. for (var i = 0; i < node.elements.length; ++i) {
  7706. var elt = node.elements[i];
  7707. if (elt) c(elt, st, "Expression");
  7708. }
  7709. };
  7710. base.ObjectExpression = base.ObjectPattern = function (node, st, c) {
  7711. for (var i = 0; i < node.properties.length; ++i) {
  7712. c(node.properties[i], st);
  7713. }
  7714. };
  7715. base.FunctionExpression = base.ArrowFunctionExpression = base.FunctionDeclaration;
  7716. base.SequenceExpression = base.TemplateLiteral = function (node, st, c) {
  7717. for (var i = 0; i < node.expressions.length; ++i) {
  7718. c(node.expressions[i], st, "Expression");
  7719. }
  7720. };
  7721. base.UnaryExpression = base.UpdateExpression = function (node, st, c) {
  7722. c(node.argument, st, "Expression");
  7723. };
  7724. base.BinaryExpression = base.AssignmentExpression = base.AssignmentPattern = base.LogicalExpression = function (node, st, c) {
  7725. c(node.left, st, "Expression");
  7726. c(node.right, st, "Expression");
  7727. };
  7728. base.ConditionalExpression = function (node, st, c) {
  7729. c(node.test, st, "Expression");
  7730. c(node.consequent, st, "Expression");
  7731. c(node.alternate, st, "Expression");
  7732. };
  7733. base.NewExpression = base.CallExpression = function (node, st, c) {
  7734. c(node.callee, st, "Expression");
  7735. if (node.arguments) for (var i = 0; i < node.arguments.length; ++i) {
  7736. c(node.arguments[i], st, "Expression");
  7737. }
  7738. };
  7739. base.MemberExpression = function (node, st, c) {
  7740. c(node.object, st, "Expression");
  7741. if (node.computed) c(node.property, st, "Expression");
  7742. };
  7743. base.ExportNamedDeclaration = base.ExportDefaultDeclaration = function (node, st, c) {
  7744. return c(node.declaration, st);
  7745. };
  7746. base.ImportDeclaration = function (node, st, c) {
  7747. for (var i = 0; i < node.specifiers.length; i++) {
  7748. c(node.specifiers[i], st);
  7749. }
  7750. };
  7751. base.ImportSpecifier = base.ImportDefaultSpecifier = base.ImportNamespaceSpecifier = base.Identifier = base.Literal = ignore;
  7752. base.TaggedTemplateExpression = function (node, st, c) {
  7753. c(node.tag, st, "Expression");
  7754. c(node.quasi, st);
  7755. };
  7756. base.ClassDeclaration = base.ClassExpression = function (node, st, c) {
  7757. if (node.superClass) c(node.superClass, st, "Expression");
  7758. for (var i = 0; i < node.body.body.length; i++) {
  7759. c(node.body.body[i], st);
  7760. }
  7761. };
  7762. base.MethodDefinition = base.Property = function (node, st, c) {
  7763. if (node.computed) c(node.key, st, "Expression");
  7764. c(node.value, st, "Expression");
  7765. };
  7766. base.ComprehensionExpression = function (node, st, c) {
  7767. for (var i = 0; i < node.blocks.length; i++) {
  7768. c(node.blocks[i].right, st, "Expression");
  7769. }c(node.body, st, "Expression");
  7770. };
  7771. },{}]},{},[1])(1)
  7772. });
  7773. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  7774. },{}],34:[function(require,module,exports){
  7775. /**
  7776. * This file automatically generated from `pre-publish.js`.
  7777. * Do not manually edit.
  7778. */
  7779. module.exports = {
  7780. "area": true,
  7781. "base": true,
  7782. "br": true,
  7783. "col": true,
  7784. "embed": true,
  7785. "hr": true,
  7786. "img": true,
  7787. "input": true,
  7788. "keygen": true,
  7789. "link": true,
  7790. "menuitem": true,
  7791. "meta": true,
  7792. "param": true,
  7793. "source": true,
  7794. "track": true,
  7795. "wbr": true
  7796. };
  7797. },{}],35:[function(require,module,exports){
  7798. 'use strict';
  7799. var detect = require('acorn-globals');
  7800. var acorn = require('acorn');
  7801. var walk = require('acorn/dist/walk');
  7802. // polyfill for https://github.com/marijnh/acorn/pull/231
  7803. walk.base.ExportNamedDeclaration = walk.base.ExportDefaultDeclaration = function (node, st, c) {
  7804. return c(node.declaration, st);
  7805. };
  7806. walk.base.ImportDefaultSpecifier = walk.base.ImportNamespaceSpecifier = function () {};
  7807. // hacky fix for https://github.com/marijnh/acorn/issues/227
  7808. function reallyParse(source) {
  7809. try {
  7810. return acorn.parse(source, {
  7811. ecmaVersion: 5,
  7812. allowReturnOutsideFunction: true
  7813. });
  7814. } catch (ex) {
  7815. if (ex.name !== 'SyntaxError') {
  7816. throw ex;
  7817. }
  7818. return acorn.parse(source, {
  7819. ecmaVersion: 6,
  7820. allowReturnOutsideFunction: true
  7821. });
  7822. }
  7823. }
  7824. module.exports = addWith
  7825. /**
  7826. * Mimic `with` as far as possible but at compile time
  7827. *
  7828. * @param {String} obj The object part of a with expression
  7829. * @param {String} src The body of the with expression
  7830. * @param {Array.<String>} exclude A list of variable names to explicitly exclude
  7831. */
  7832. function addWith(obj, src, exclude) {
  7833. obj = obj + ''
  7834. src = src + ''
  7835. exclude = exclude || []
  7836. exclude = exclude.concat(detect(obj).map(function (global) { return global.name; }))
  7837. var vars = detect(src).map(function (global) { return global.name; })
  7838. .filter(function (v) {
  7839. return exclude.indexOf(v) === -1
  7840. })
  7841. if (vars.length === 0) return src
  7842. var declareLocal = ''
  7843. var local = 'locals_for_with'
  7844. var result = 'result_of_with'
  7845. if (/^[a-zA-Z0-9$_]+$/.test(obj)) {
  7846. local = obj
  7847. } else {
  7848. while (vars.indexOf(local) != -1 || exclude.indexOf(local) != -1) {
  7849. local += '_'
  7850. }
  7851. declareLocal = 'var ' + local + ' = (' + obj + ')'
  7852. }
  7853. while (vars.indexOf(result) != -1 || exclude.indexOf(result) != -1) {
  7854. result += '_'
  7855. }
  7856. var inputVars = vars.map(function (v) {
  7857. return JSON.stringify(v) + ' in ' + local + '?' +
  7858. local + '.' + v + ':' +
  7859. 'typeof ' + v + '!=="undefined"?' + v + ':undefined'
  7860. })
  7861. src = '(function (' + vars.join(', ') + ') {' +
  7862. src +
  7863. '}.call(this' + inputVars.map(function (v) { return ',' + v; }).join('') + '))'
  7864. return ';' + declareLocal + ';' + unwrapReturns(src, result) + ';'
  7865. }
  7866. /**
  7867. * Take a self calling function, and unwrap it such that return inside the function
  7868. * results in return outside the function
  7869. *
  7870. * @param {String} src Some JavaScript code representing a self-calling function
  7871. * @param {String} result A temporary variable to store the result in
  7872. */
  7873. function unwrapReturns(src, result) {
  7874. var originalSource = src
  7875. var hasReturn = false
  7876. var ast = reallyParse(src)
  7877. var ref
  7878. src = src.split('')
  7879. // get a reference to the function that was inserted to add an inner context
  7880. if ((ref = ast.body).length !== 1
  7881. || (ref = ref[0]).type !== 'ExpressionStatement'
  7882. || (ref = ref.expression).type !== 'CallExpression'
  7883. || (ref = ref.callee).type !== 'MemberExpression' || ref.computed !== false || ref.property.name !== 'call'
  7884. || (ref = ref.object).type !== 'FunctionExpression')
  7885. throw new Error('AST does not seem to represent a self-calling function')
  7886. var fn = ref
  7887. walk.recursive(ast, null, {
  7888. Function: function (node, st, c) {
  7889. if (node === fn) {
  7890. c(node.body, st, "ScopeBody");
  7891. }
  7892. },
  7893. ReturnStatement: function (node) {
  7894. hasReturn = true
  7895. replace(node, 'return {value: ' + source(node.argument) + '};');
  7896. }
  7897. });
  7898. function source(node) {
  7899. return src.slice(node.start, node.end).join('')
  7900. }
  7901. function replace(node, str) {
  7902. for (var i = node.start; i < node.end; i++) {
  7903. src[i] = ''
  7904. }
  7905. src[node.start] = str
  7906. }
  7907. if (!hasReturn) return originalSource
  7908. else return 'var ' + result + '=' + src.join('') + ';if (' + result + ') return ' + result + '.value'
  7909. }
  7910. },{"acorn":37,"acorn-globals":36,"acorn/dist/walk":38}],36:[function(require,module,exports){
  7911. arguments[4][31][0].apply(exports,arguments)
  7912. },{"acorn":37,"acorn/dist/walk":38,"dup":31}],37:[function(require,module,exports){
  7913. arguments[4][32][0].apply(exports,arguments)
  7914. },{"dup":32}],38:[function(require,module,exports){
  7915. arguments[4][33][0].apply(exports,arguments)
  7916. },{"dup":33}]},{},[1])(1)
  7917. });