build.dev.js 270 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. var stream = require('stream');
  4. var he = require('he');
  5. function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
  6. var he__default = /*#__PURE__*/_interopDefaultLegacy(he);
  7. const emptyObject = Object.freeze({});
  8. const isArray = Array.isArray;
  9. // These helpers produce better VM code in JS engines due to their
  10. // explicitness and function inlining.
  11. function isUndef(v) {
  12. return v === undefined || v === null;
  13. }
  14. function isDef(v) {
  15. return v !== undefined && v !== null;
  16. }
  17. function isTrue(v) {
  18. return v === true;
  19. }
  20. function isFalse(v) {
  21. return v === false;
  22. }
  23. /**
  24. * Check if value is primitive.
  25. */
  26. function isPrimitive(value) {
  27. return (typeof value === 'string' ||
  28. typeof value === 'number' ||
  29. // $flow-disable-line
  30. typeof value === 'symbol' ||
  31. typeof value === 'boolean');
  32. }
  33. function isFunction(value) {
  34. return typeof value === 'function';
  35. }
  36. /**
  37. * Quick object check - this is primarily used to tell
  38. * objects from primitive values when we know the value
  39. * is a JSON-compliant type.
  40. */
  41. function isObject(obj) {
  42. return obj !== null && typeof obj === 'object';
  43. }
  44. /**
  45. * Get the raw type string of a value, e.g., [object Object].
  46. */
  47. const _toString = Object.prototype.toString;
  48. function toRawType(value) {
  49. return _toString.call(value).slice(8, -1);
  50. }
  51. /**
  52. * Strict object type check. Only returns true
  53. * for plain JavaScript objects.
  54. */
  55. function isPlainObject(obj) {
  56. return _toString.call(obj) === '[object Object]';
  57. }
  58. /**
  59. * Check if val is a valid array index.
  60. */
  61. function isValidArrayIndex(val) {
  62. const n = parseFloat(String(val));
  63. return n >= 0 && Math.floor(n) === n && isFinite(val);
  64. }
  65. function isPromise(val) {
  66. return (isDef(val) &&
  67. typeof val.then === 'function' &&
  68. typeof val.catch === 'function');
  69. }
  70. /**
  71. * Convert a value to a string that is actually rendered.
  72. */
  73. function toString(val) {
  74. return val == null
  75. ? ''
  76. : Array.isArray(val) || (isPlainObject(val) && val.toString === _toString)
  77. ? JSON.stringify(val, null, 2)
  78. : String(val);
  79. }
  80. /**
  81. * Convert an input value to a number for persistence.
  82. * If the conversion fails, return original string.
  83. */
  84. function toNumber(val) {
  85. const n = parseFloat(val);
  86. return isNaN(n) ? val : n;
  87. }
  88. /**
  89. * Make a map and return a function for checking if a key
  90. * is in that map.
  91. */
  92. function makeMap(str, expectsLowerCase) {
  93. const map = Object.create(null);
  94. const list = str.split(',');
  95. for (let i = 0; i < list.length; i++) {
  96. map[list[i]] = true;
  97. }
  98. return expectsLowerCase ? val => map[val.toLowerCase()] : val => map[val];
  99. }
  100. /**
  101. * Check if a tag is a built-in tag.
  102. */
  103. const isBuiltInTag = makeMap('slot,component', true);
  104. /**
  105. * Check if an attribute is a reserved attribute.
  106. */
  107. const isReservedAttribute = makeMap('key,ref,slot,slot-scope,is');
  108. /**
  109. * Check whether an object has the property.
  110. */
  111. const hasOwnProperty = Object.prototype.hasOwnProperty;
  112. function hasOwn(obj, key) {
  113. return hasOwnProperty.call(obj, key);
  114. }
  115. /**
  116. * Create a cached version of a pure function.
  117. */
  118. function cached(fn) {
  119. const cache = Object.create(null);
  120. return function cachedFn(str) {
  121. const hit = cache[str];
  122. return hit || (cache[str] = fn(str));
  123. };
  124. }
  125. /**
  126. * Camelize a hyphen-delimited string.
  127. */
  128. const camelizeRE = /-(\w)/g;
  129. const camelize = cached((str) => {
  130. return str.replace(camelizeRE, (_, c) => (c ? c.toUpperCase() : ''));
  131. });
  132. /**
  133. * Capitalize a string.
  134. */
  135. const capitalize = cached((str) => {
  136. return str.charAt(0).toUpperCase() + str.slice(1);
  137. });
  138. /**
  139. * Hyphenate a camelCase string.
  140. */
  141. const hyphenateRE = /\B([A-Z])/g;
  142. const hyphenate = cached((str) => {
  143. return str.replace(hyphenateRE, '-$1').toLowerCase();
  144. });
  145. /**
  146. * Mix properties into target object.
  147. */
  148. function extend(to, _from) {
  149. for (const key in _from) {
  150. to[key] = _from[key];
  151. }
  152. return to;
  153. }
  154. /**
  155. * Merge an Array of Objects into a single Object.
  156. */
  157. function toObject(arr) {
  158. const res = {};
  159. for (let i = 0; i < arr.length; i++) {
  160. if (arr[i]) {
  161. extend(res, arr[i]);
  162. }
  163. }
  164. return res;
  165. }
  166. /* eslint-disable no-unused-vars */
  167. /**
  168. * Perform no operation.
  169. * Stubbing args to make Flow happy without leaving useless transpiled code
  170. * with ...rest (https://flow.org/blog/2017/05/07/Strict-Function-Call-Arity/).
  171. */
  172. function noop$1(a, b, c) { }
  173. /**
  174. * Always return false.
  175. */
  176. const no = (a, b, c) => false;
  177. /* eslint-enable no-unused-vars */
  178. /**
  179. * Return the same value.
  180. */
  181. const identity = (_) => _;
  182. /**
  183. * Generate a string containing static keys from compiler modules.
  184. */
  185. function genStaticKeys(modules) {
  186. return modules
  187. .reduce((keys, m) => {
  188. return keys.concat(m.staticKeys || []);
  189. }, [])
  190. .join(',');
  191. }
  192. /**
  193. * Check if two values are loosely equal - that is,
  194. * if they are plain objects, do they have the same shape?
  195. */
  196. function looseEqual(a, b) {
  197. if (a === b)
  198. return true;
  199. const isObjectA = isObject(a);
  200. const isObjectB = isObject(b);
  201. if (isObjectA && isObjectB) {
  202. try {
  203. const isArrayA = Array.isArray(a);
  204. const isArrayB = Array.isArray(b);
  205. if (isArrayA && isArrayB) {
  206. return (a.length === b.length &&
  207. a.every((e, i) => {
  208. return looseEqual(e, b[i]);
  209. }));
  210. }
  211. else if (a instanceof Date && b instanceof Date) {
  212. return a.getTime() === b.getTime();
  213. }
  214. else if (!isArrayA && !isArrayB) {
  215. const keysA = Object.keys(a);
  216. const keysB = Object.keys(b);
  217. return (keysA.length === keysB.length &&
  218. keysA.every(key => {
  219. return looseEqual(a[key], b[key]);
  220. }));
  221. }
  222. else {
  223. /* istanbul ignore next */
  224. return false;
  225. }
  226. }
  227. catch (e) {
  228. /* istanbul ignore next */
  229. return false;
  230. }
  231. }
  232. else if (!isObjectA && !isObjectB) {
  233. return String(a) === String(b);
  234. }
  235. else {
  236. return false;
  237. }
  238. }
  239. /**
  240. * Return the first index at which a loosely equal value can be
  241. * found in the array (if value is a plain object, the array must
  242. * contain an object of the same shape), or -1 if it is not present.
  243. */
  244. function looseIndexOf(arr, val) {
  245. for (let i = 0; i < arr.length; i++) {
  246. if (looseEqual(arr[i], val))
  247. return i;
  248. }
  249. return -1;
  250. }
  251. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is#polyfill
  252. function hasChanged(x, y) {
  253. if (x === y) {
  254. return x === 0 && 1 / x !== 1 / y;
  255. }
  256. else {
  257. return x === x || y === y;
  258. }
  259. }
  260. const isAttr = makeMap('accept,accept-charset,accesskey,action,align,alt,async,autocomplete,' +
  261. 'autofocus,autoplay,autosave,bgcolor,border,buffered,challenge,charset,' +
  262. 'checked,cite,class,code,codebase,color,cols,colspan,content,' +
  263. 'contenteditable,contextmenu,controls,coords,data,datetime,default,' +
  264. 'defer,dir,dirname,disabled,download,draggable,dropzone,enctype,for,' +
  265. 'form,formaction,headers,height,hidden,high,href,hreflang,http-equiv,' +
  266. 'icon,id,ismap,itemprop,keytype,kind,label,lang,language,list,loop,low,' +
  267. 'manifest,max,maxlength,media,method,GET,POST,min,multiple,email,file,' +
  268. 'muted,name,novalidate,open,optimum,pattern,ping,placeholder,poster,' +
  269. 'preload,radiogroup,readonly,rel,required,reversed,rows,rowspan,sandbox,' +
  270. 'scope,scoped,seamless,selected,shape,size,type,text,password,sizes,span,' +
  271. 'spellcheck,src,srcdoc,srclang,srcset,start,step,style,summary,tabindex,' +
  272. 'target,title,usemap,value,width,wrap');
  273. const unsafeAttrCharRE = /[>/="'\u0009\u000a\u000c\u0020]/; // eslint-disable-line no-control-regex
  274. const isSSRUnsafeAttr = (name) => {
  275. return unsafeAttrCharRE.test(name);
  276. };
  277. /* istanbul ignore next */
  278. const isRenderableAttr = (name) => {
  279. return (isAttr(name) || name.indexOf('data-') === 0 || name.indexOf('aria-') === 0);
  280. };
  281. const propsToAttrMap = {
  282. acceptCharset: 'accept-charset',
  283. className: 'class',
  284. htmlFor: 'for',
  285. httpEquiv: 'http-equiv'
  286. };
  287. const ESC = {
  288. '<': '&lt;',
  289. '>': '&gt;',
  290. '"': '&quot;',
  291. '&': '&amp;'
  292. };
  293. function escape(s) {
  294. return s.replace(/[<>"&]/g, escapeChar);
  295. }
  296. function escapeChar(a) {
  297. return ESC[a] || a;
  298. }
  299. const noUnitNumericStyleProps = {
  300. 'animation-iteration-count': true,
  301. 'border-image-outset': true,
  302. 'border-image-slice': true,
  303. 'border-image-width': true,
  304. 'box-flex': true,
  305. 'box-flex-group': true,
  306. 'box-ordinal-group': true,
  307. 'column-count': true,
  308. columns: true,
  309. flex: true,
  310. 'flex-grow': true,
  311. 'flex-positive': true,
  312. 'flex-shrink': true,
  313. 'flex-negative': true,
  314. 'flex-order': true,
  315. 'grid-row': true,
  316. 'grid-row-end': true,
  317. 'grid-row-span': true,
  318. 'grid-row-start': true,
  319. 'grid-column': true,
  320. 'grid-column-end': true,
  321. 'grid-column-span': true,
  322. 'grid-column-start': true,
  323. 'font-weight': true,
  324. 'line-clamp': true,
  325. 'line-height': true,
  326. opacity: true,
  327. order: true,
  328. orphans: true,
  329. 'tab-size': true,
  330. widows: true,
  331. 'z-index': true,
  332. zoom: true,
  333. // SVG
  334. 'fill-opacity': true,
  335. 'flood-opacity': true,
  336. 'stop-opacity': true,
  337. 'stroke-dasharray': true,
  338. 'stroke-dashoffset': true,
  339. 'stroke-miterlimit': true,
  340. 'stroke-opacity': true,
  341. 'stroke-width': true
  342. };
  343. const isJS = (file) => /\.js(\?[^.]+)?$/.test(file);
  344. const isCSS = (file) => /\.css(\?[^.]+)?$/.test(file);
  345. function createPromiseCallback() {
  346. let resolve, reject;
  347. const promise = new Promise((_resolve, _reject) => {
  348. resolve = _resolve;
  349. reject = _reject;
  350. });
  351. const cb = (err, res) => {
  352. if (err)
  353. return reject(err);
  354. resolve(res || '');
  355. };
  356. return { promise, cb };
  357. }
  358. // these are reserved for web because they are directly compiled away
  359. // during template compilation
  360. makeMap('style,class');
  361. // attributes that should be using props for binding
  362. const acceptValue = makeMap('input,textarea,option,select,progress');
  363. const mustUseProp = (tag, type, attr) => {
  364. return ((attr === 'value' && acceptValue(tag) && type !== 'button') ||
  365. (attr === 'selected' && tag === 'option') ||
  366. (attr === 'checked' && tag === 'input') ||
  367. (attr === 'muted' && tag === 'video'));
  368. };
  369. const isEnumeratedAttr = makeMap('contenteditable,draggable,spellcheck');
  370. const isValidContentEditableValue = makeMap('events,caret,typing,plaintext-only');
  371. const convertEnumeratedValue = (key, value) => {
  372. return isFalsyAttrValue(value) || value === 'false'
  373. ? 'false'
  374. : // allow arbitrary string value for contenteditable
  375. key === 'contenteditable' && isValidContentEditableValue(value)
  376. ? value
  377. : 'true';
  378. };
  379. const isBooleanAttr = makeMap('allowfullscreen,async,autofocus,autoplay,checked,compact,controls,declare,' +
  380. 'default,defaultchecked,defaultmuted,defaultselected,defer,disabled,' +
  381. 'enabled,formnovalidate,hidden,indeterminate,inert,ismap,itemscope,loop,multiple,' +
  382. 'muted,nohref,noresize,noshade,novalidate,nowrap,open,pauseonexit,readonly,' +
  383. 'required,reversed,scoped,seamless,selected,sortable,' +
  384. 'truespeed,typemustmatch,visible');
  385. const isFalsyAttrValue = (val) => {
  386. return val == null || val === false;
  387. };
  388. function renderAttrs$1(node) {
  389. let attrs = node.data.attrs;
  390. let res = '';
  391. const opts = node.parent && node.parent.componentOptions;
  392. if (isUndef(opts) || opts.Ctor.options.inheritAttrs !== false) {
  393. let parent = node.parent;
  394. while (isDef(parent)) {
  395. // Stop fallthrough in case parent has inheritAttrs option set to false
  396. if (parent.componentOptions &&
  397. parent.componentOptions.Ctor.options.inheritAttrs === false) {
  398. break;
  399. }
  400. if (isDef(parent.data) && isDef(parent.data.attrs)) {
  401. attrs = extend(extend({}, attrs), parent.data.attrs);
  402. }
  403. parent = parent.parent;
  404. }
  405. }
  406. if (isUndef(attrs)) {
  407. return res;
  408. }
  409. for (const key in attrs) {
  410. if (isSSRUnsafeAttr(key)) {
  411. continue;
  412. }
  413. if (key === 'style') {
  414. // leave it to the style module
  415. continue;
  416. }
  417. res += renderAttr(key, attrs[key]);
  418. }
  419. return res;
  420. }
  421. function renderAttr(key, value) {
  422. if (isBooleanAttr(key)) {
  423. if (!isFalsyAttrValue(value)) {
  424. return ` ${key}="${key}"`;
  425. }
  426. }
  427. else if (isEnumeratedAttr(key)) {
  428. return ` ${key}="${escape(convertEnumeratedValue(key, value))}"`;
  429. }
  430. else if (!isFalsyAttrValue(value)) {
  431. return ` ${key}="${escape(String(value))}"`;
  432. }
  433. return '';
  434. }
  435. /**
  436. * @internal
  437. */
  438. class VNode {
  439. constructor(tag, data, children, text, elm, context, componentOptions, asyncFactory) {
  440. this.tag = tag;
  441. this.data = data;
  442. this.children = children;
  443. this.text = text;
  444. this.elm = elm;
  445. this.ns = undefined;
  446. this.context = context;
  447. this.fnContext = undefined;
  448. this.fnOptions = undefined;
  449. this.fnScopeId = undefined;
  450. this.key = data && data.key;
  451. this.componentOptions = componentOptions;
  452. this.componentInstance = undefined;
  453. this.parent = undefined;
  454. this.raw = false;
  455. this.isStatic = false;
  456. this.isRootInsert = true;
  457. this.isComment = false;
  458. this.isCloned = false;
  459. this.isOnce = false;
  460. this.asyncFactory = asyncFactory;
  461. this.asyncMeta = undefined;
  462. this.isAsyncPlaceholder = false;
  463. }
  464. // DEPRECATED: alias for componentInstance for backwards compat.
  465. /* istanbul ignore next */
  466. get child() {
  467. return this.componentInstance;
  468. }
  469. }
  470. const createEmptyVNode = (text = '') => {
  471. const node = new VNode();
  472. node.text = text;
  473. node.isComment = true;
  474. return node;
  475. };
  476. function createTextVNode(val) {
  477. return new VNode(undefined, undefined, undefined, String(val));
  478. }
  479. // optimized shallow clone
  480. // used for static nodes and slot nodes because they may be reused across
  481. // multiple renders, cloning them avoids errors when DOM manipulations rely
  482. // on their elm reference.
  483. function cloneVNode(vnode) {
  484. const cloned = new VNode(vnode.tag, vnode.data,
  485. // #7975
  486. // clone children array to avoid mutating original in case of cloning
  487. // a child.
  488. vnode.children && vnode.children.slice(), vnode.text, vnode.elm, vnode.context, vnode.componentOptions, vnode.asyncFactory);
  489. cloned.ns = vnode.ns;
  490. cloned.isStatic = vnode.isStatic;
  491. cloned.key = vnode.key;
  492. cloned.isComment = vnode.isComment;
  493. cloned.fnContext = vnode.fnContext;
  494. cloned.fnOptions = vnode.fnOptions;
  495. cloned.fnScopeId = vnode.fnScopeId;
  496. cloned.asyncMeta = vnode.asyncMeta;
  497. cloned.isCloned = true;
  498. return cloned;
  499. }
  500. function renderDOMProps$1(node) {
  501. let props = node.data.domProps;
  502. let res = '';
  503. let parent = node.parent;
  504. while (isDef(parent)) {
  505. if (parent.data && parent.data.domProps) {
  506. props = extend(extend({}, props), parent.data.domProps);
  507. }
  508. parent = parent.parent;
  509. }
  510. if (isUndef(props)) {
  511. return res;
  512. }
  513. const attrs = node.data.attrs;
  514. for (const key in props) {
  515. if (key === 'innerHTML') {
  516. setText(node, props[key], true);
  517. }
  518. else if (key === 'textContent') {
  519. setText(node, props[key], false);
  520. }
  521. else if (key === 'value' && node.tag === 'textarea') {
  522. setText(node, toString(props[key]), false);
  523. }
  524. else {
  525. // $flow-disable-line (WTF?)
  526. const attr = propsToAttrMap[key] || key.toLowerCase();
  527. if (isRenderableAttr(attr) &&
  528. // avoid rendering double-bound props/attrs twice
  529. !(isDef(attrs) && isDef(attrs[attr]))) {
  530. res += renderAttr(attr, props[key]);
  531. }
  532. }
  533. }
  534. return res;
  535. }
  536. function setText(node, text, raw) {
  537. const child = new VNode(undefined, undefined, undefined, text);
  538. child.raw = raw;
  539. node.children = [child];
  540. }
  541. /**
  542. * unicode letters used for parsing html tags, component names and property paths.
  543. * using https://www.w3.org/TR/html53/semantics-scripting.html#potentialcustomelementname
  544. * skipping \u10000-\uEFFFF due to it freezing up PhantomJS
  545. */
  546. const unicodeRegExp = /a-zA-Z\u00B7\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u037D\u037F-\u1FFF\u200C-\u200D\u203F-\u2040\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD/;
  547. /**
  548. * Define a property.
  549. */
  550. function def(obj, key, val, enumerable) {
  551. Object.defineProperty(obj, key, {
  552. value: val,
  553. enumerable: !!enumerable,
  554. writable: true,
  555. configurable: true
  556. });
  557. }
  558. // can we use __proto__?
  559. const hasProto = '__proto__' in {};
  560. // Browser environment sniffing
  561. const inBrowser = typeof window !== 'undefined';
  562. const UA = inBrowser && window.navigator.userAgent.toLowerCase();
  563. const isIE = UA && /msie|trident/.test(UA);
  564. UA && UA.indexOf('msie 9.0') > 0;
  565. const isEdge = UA && UA.indexOf('edge/') > 0;
  566. UA && UA.indexOf('android') > 0;
  567. UA && /iphone|ipad|ipod|ios/.test(UA);
  568. UA && /chrome\/\d+/.test(UA) && !isEdge;
  569. UA && /phantomjs/.test(UA);
  570. UA && UA.match(/firefox\/(\d+)/);
  571. // Firefox has a "watch" function on Object.prototype...
  572. // @ts-expect-error firebox support
  573. const nativeWatch = {}.watch;
  574. let supportsPassive = false;
  575. if (inBrowser) {
  576. try {
  577. const opts = {};
  578. Object.defineProperty(opts, 'passive', {
  579. get() {
  580. /* istanbul ignore next */
  581. supportsPassive = true;
  582. }
  583. }); // https://github.com/facebook/flow/issues/285
  584. window.addEventListener('test-passive', null, opts);
  585. }
  586. catch (e) { }
  587. }
  588. // this needs to be lazy-evaled because vue may be required before
  589. // vue-server-renderer can set VUE_ENV
  590. let _isServer;
  591. const isServerRendering = () => {
  592. if (_isServer === undefined) {
  593. /* istanbul ignore if */
  594. if (!inBrowser && typeof global !== 'undefined') {
  595. // detect presence of vue-server-renderer and avoid
  596. // Webpack shimming the process
  597. _isServer =
  598. global['process'] && global['process'].env.VUE_ENV === 'server';
  599. }
  600. else {
  601. _isServer = false;
  602. }
  603. }
  604. return _isServer;
  605. };
  606. /* istanbul ignore next */
  607. function isNative(Ctor) {
  608. return typeof Ctor === 'function' && /native code/.test(Ctor.toString());
  609. }
  610. const hasSymbol = typeof Symbol !== 'undefined' &&
  611. isNative(Symbol) &&
  612. typeof Reflect !== 'undefined' &&
  613. isNative(Reflect.ownKeys);
  614. let _Set; // $flow-disable-line
  615. /* istanbul ignore if */ if (typeof Set !== 'undefined' && isNative(Set)) {
  616. // use native Set when available.
  617. _Set = Set;
  618. }
  619. else {
  620. // a non-standard Set polyfill that only works with primitive keys.
  621. _Set = class Set {
  622. constructor() {
  623. this.set = Object.create(null);
  624. }
  625. has(key) {
  626. return this.set[key] === true;
  627. }
  628. add(key) {
  629. this.set[key] = true;
  630. }
  631. clear() {
  632. this.set = Object.create(null);
  633. }
  634. };
  635. }
  636. const SSR_ATTR = 'data-server-rendered';
  637. const ASSET_TYPES = ['component', 'directive', 'filter'];
  638. const LIFECYCLE_HOOKS = [
  639. 'beforeCreate',
  640. 'created',
  641. 'beforeMount',
  642. 'mounted',
  643. 'beforeUpdate',
  644. 'updated',
  645. 'beforeDestroy',
  646. 'destroyed',
  647. 'activated',
  648. 'deactivated',
  649. 'errorCaptured',
  650. 'serverPrefetch',
  651. 'renderTracked',
  652. 'renderTriggered'
  653. ];
  654. var config = {
  655. /**
  656. * Option merge strategies (used in core/util/options)
  657. */
  658. // $flow-disable-line
  659. optionMergeStrategies: Object.create(null),
  660. /**
  661. * Whether to suppress warnings.
  662. */
  663. silent: false,
  664. /**
  665. * Show production mode tip message on boot?
  666. */
  667. productionTip: true,
  668. /**
  669. * Whether to enable devtools
  670. */
  671. devtools: true,
  672. /**
  673. * Whether to record perf
  674. */
  675. performance: false,
  676. /**
  677. * Error handler for watcher errors
  678. */
  679. errorHandler: null,
  680. /**
  681. * Warn handler for watcher warns
  682. */
  683. warnHandler: null,
  684. /**
  685. * Ignore certain custom elements
  686. */
  687. ignoredElements: [],
  688. /**
  689. * Custom user key aliases for v-on
  690. */
  691. // $flow-disable-line
  692. keyCodes: Object.create(null),
  693. /**
  694. * Check if a tag is reserved so that it cannot be registered as a
  695. * component. This is platform-dependent and may be overwritten.
  696. */
  697. isReservedTag: no,
  698. /**
  699. * Check if an attribute is reserved so that it cannot be used as a component
  700. * prop. This is platform-dependent and may be overwritten.
  701. */
  702. isReservedAttr: no,
  703. /**
  704. * Check if a tag is an unknown element.
  705. * Platform-dependent.
  706. */
  707. isUnknownElement: no,
  708. /**
  709. * Get the namespace of an element
  710. */
  711. getTagNamespace: noop$1,
  712. /**
  713. * Parse the real tag name for the specific platform.
  714. */
  715. parsePlatformTagName: identity,
  716. /**
  717. * Check if an attribute must be bound using property, e.g. value
  718. * Platform-dependent.
  719. */
  720. mustUseProp: no,
  721. /**
  722. * Perform updates asynchronously. Intended to be used by Vue Test Utils
  723. * This will significantly reduce performance if set to false.
  724. */
  725. async: true,
  726. /**
  727. * Exposed for legacy reasons
  728. */
  729. _lifecycleHooks: LIFECYCLE_HOOKS
  730. };
  731. let currentInstance = null;
  732. /**
  733. * @internal
  734. */
  735. function setCurrentInstance(vm = null) {
  736. if (!vm)
  737. currentInstance && currentInstance._scope.off();
  738. currentInstance = vm;
  739. vm && vm._scope.on();
  740. }
  741. /* not type checking this file because flow doesn't play well with Proxy */
  742. {
  743. makeMap('Infinity,undefined,NaN,isFinite,isNaN,' +
  744. 'parseFloat,parseInt,decodeURI,decodeURIComponent,encodeURI,encodeURIComponent,' +
  745. 'Math,Number,Date,Array,Object,Boolean,String,RegExp,Map,Set,JSON,Intl,BigInt,' +
  746. 'require' // for Webpack/Browserify
  747. );
  748. const hasProxy = typeof Proxy !== 'undefined' && isNative(Proxy);
  749. if (hasProxy) {
  750. const isBuiltInModifier = makeMap('stop,prevent,self,ctrl,shift,alt,meta,exact');
  751. config.keyCodes = new Proxy(config.keyCodes, {
  752. set(target, key, value) {
  753. if (isBuiltInModifier(key)) {
  754. warn$2(`Avoid overwriting built-in modifier in config.keyCodes: .${key}`);
  755. return false;
  756. }
  757. else {
  758. target[key] = value;
  759. return true;
  760. }
  761. }
  762. });
  763. }
  764. }
  765. let uid = 0;
  766. /**
  767. * A dep is an observable that can have multiple
  768. * directives subscribing to it.
  769. * @internal
  770. */
  771. class Dep {
  772. constructor() {
  773. // pending subs cleanup
  774. this._pending = false;
  775. this.id = uid++;
  776. this.subs = [];
  777. }
  778. addSub(sub) {
  779. this.subs.push(sub);
  780. }
  781. removeSub(sub) {
  782. // #12696 deps with massive amount of subscribers are extremely slow to
  783. // clean up in Chromium
  784. // to workaround this, we unset the sub for now, and clear them on
  785. // next scheduler flush.
  786. this.subs[this.subs.indexOf(sub)] = null;
  787. if (!this._pending) {
  788. this._pending = true;
  789. }
  790. }
  791. depend(info) {
  792. if (Dep.target) {
  793. Dep.target.addDep(this);
  794. if (info && Dep.target.onTrack) {
  795. Dep.target.onTrack(Object.assign({ effect: Dep.target }, info));
  796. }
  797. }
  798. }
  799. notify(info) {
  800. // stabilize the subscriber list first
  801. const subs = this.subs.filter(s => s);
  802. for (let i = 0, l = subs.length; i < l; i++) {
  803. const sub = subs[i];
  804. if (info) {
  805. sub.onTrigger &&
  806. sub.onTrigger(Object.assign({ effect: subs[i] }, info));
  807. }
  808. sub.update();
  809. }
  810. }
  811. }
  812. // The current target watcher being evaluated.
  813. // This is globally unique because only one watcher
  814. // can be evaluated at a time.
  815. Dep.target = null;
  816. const targetStack = [];
  817. function pushTarget(target) {
  818. targetStack.push(target);
  819. Dep.target = target;
  820. }
  821. function popTarget() {
  822. targetStack.pop();
  823. Dep.target = targetStack[targetStack.length - 1];
  824. }
  825. /*
  826. * not type checking this file because flow doesn't play well with
  827. * dynamically accessing methods on Array prototype
  828. */
  829. const arrayProto = Array.prototype;
  830. const arrayMethods = Object.create(arrayProto);
  831. const methodsToPatch = [
  832. 'push',
  833. 'pop',
  834. 'shift',
  835. 'unshift',
  836. 'splice',
  837. 'sort',
  838. 'reverse'
  839. ];
  840. /**
  841. * Intercept mutating methods and emit events
  842. */
  843. methodsToPatch.forEach(function (method) {
  844. // cache original method
  845. const original = arrayProto[method];
  846. def(arrayMethods, method, function mutator(...args) {
  847. const result = original.apply(this, args);
  848. const ob = this.__ob__;
  849. let inserted;
  850. switch (method) {
  851. case 'push':
  852. case 'unshift':
  853. inserted = args;
  854. break;
  855. case 'splice':
  856. inserted = args.slice(2);
  857. break;
  858. }
  859. if (inserted)
  860. ob.observeArray(inserted);
  861. // notify change
  862. {
  863. ob.dep.notify({
  864. type: "array mutation" /* TriggerOpTypes.ARRAY_MUTATION */,
  865. target: this,
  866. key: method
  867. });
  868. }
  869. return result;
  870. });
  871. });
  872. const rawMap = new WeakMap();
  873. function isReadonly(value) {
  874. return !!(value && value.__v_isReadonly);
  875. }
  876. const arrayKeys = Object.getOwnPropertyNames(arrayMethods);
  877. const NO_INIITIAL_VALUE = {};
  878. /**
  879. * In some cases we may want to disable observation inside a component's
  880. * update computation.
  881. */
  882. let shouldObserve = true;
  883. function toggleObserving(value) {
  884. shouldObserve = value;
  885. }
  886. // ssr mock dep
  887. const mockDep = {
  888. notify: noop$1,
  889. depend: noop$1,
  890. addSub: noop$1,
  891. removeSub: noop$1
  892. };
  893. /**
  894. * Observer class that is attached to each observed
  895. * object. Once attached, the observer converts the target
  896. * object's property keys into getter/setters that
  897. * collect dependencies and dispatch updates.
  898. */
  899. class Observer {
  900. constructor(value, shallow = false, mock = false) {
  901. this.value = value;
  902. this.shallow = shallow;
  903. this.mock = mock;
  904. // this.value = value
  905. this.dep = mock ? mockDep : new Dep();
  906. this.vmCount = 0;
  907. def(value, '__ob__', this);
  908. if (isArray(value)) {
  909. if (!mock) {
  910. if (hasProto) {
  911. value.__proto__ = arrayMethods;
  912. /* eslint-enable no-proto */
  913. }
  914. else {
  915. for (let i = 0, l = arrayKeys.length; i < l; i++) {
  916. const key = arrayKeys[i];
  917. def(value, key, arrayMethods[key]);
  918. }
  919. }
  920. }
  921. if (!shallow) {
  922. this.observeArray(value);
  923. }
  924. }
  925. else {
  926. /**
  927. * Walk through all properties and convert them into
  928. * getter/setters. This method should only be called when
  929. * value type is Object.
  930. */
  931. const keys = Object.keys(value);
  932. for (let i = 0; i < keys.length; i++) {
  933. const key = keys[i];
  934. defineReactive(value, key, NO_INIITIAL_VALUE, undefined, shallow, mock);
  935. }
  936. }
  937. }
  938. /**
  939. * Observe a list of Array items.
  940. */
  941. observeArray(value) {
  942. for (let i = 0, l = value.length; i < l; i++) {
  943. observe(value[i], false, this.mock);
  944. }
  945. }
  946. }
  947. // helpers
  948. /**
  949. * Attempt to create an observer instance for a value,
  950. * returns the new observer if successfully observed,
  951. * or the existing observer if the value already has one.
  952. */
  953. function observe(value, shallow, ssrMockReactivity) {
  954. if (value && hasOwn(value, '__ob__') && value.__ob__ instanceof Observer) {
  955. return value.__ob__;
  956. }
  957. if (shouldObserve &&
  958. (ssrMockReactivity || !isServerRendering()) &&
  959. (isArray(value) || isPlainObject(value)) &&
  960. Object.isExtensible(value) &&
  961. !value.__v_skip /* ReactiveFlags.SKIP */ &&
  962. !rawMap.has(value) &&
  963. !isRef(value) &&
  964. !(value instanceof VNode)) {
  965. return new Observer(value, shallow, ssrMockReactivity);
  966. }
  967. }
  968. /**
  969. * Define a reactive property on an Object.
  970. */
  971. function defineReactive(obj, key, val, customSetter, shallow, mock) {
  972. const dep = new Dep();
  973. const property = Object.getOwnPropertyDescriptor(obj, key);
  974. if (property && property.configurable === false) {
  975. return;
  976. }
  977. // cater for pre-defined getter/setters
  978. const getter = property && property.get;
  979. const setter = property && property.set;
  980. if ((!getter || setter) &&
  981. (val === NO_INIITIAL_VALUE || arguments.length === 2)) {
  982. val = obj[key];
  983. }
  984. let childOb = !shallow && observe(val, false, mock);
  985. Object.defineProperty(obj, key, {
  986. enumerable: true,
  987. configurable: true,
  988. get: function reactiveGetter() {
  989. const value = getter ? getter.call(obj) : val;
  990. if (Dep.target) {
  991. {
  992. dep.depend({
  993. target: obj,
  994. type: "get" /* TrackOpTypes.GET */,
  995. key
  996. });
  997. }
  998. if (childOb) {
  999. childOb.dep.depend();
  1000. if (isArray(value)) {
  1001. dependArray(value);
  1002. }
  1003. }
  1004. }
  1005. return isRef(value) && !shallow ? value.value : value;
  1006. },
  1007. set: function reactiveSetter(newVal) {
  1008. const value = getter ? getter.call(obj) : val;
  1009. if (!hasChanged(value, newVal)) {
  1010. return;
  1011. }
  1012. if (customSetter) {
  1013. customSetter();
  1014. }
  1015. if (setter) {
  1016. setter.call(obj, newVal);
  1017. }
  1018. else if (getter) {
  1019. // #7981: for accessor properties without setter
  1020. return;
  1021. }
  1022. else if (!shallow && isRef(value) && !isRef(newVal)) {
  1023. value.value = newVal;
  1024. return;
  1025. }
  1026. else {
  1027. val = newVal;
  1028. }
  1029. childOb = !shallow && observe(newVal, false, mock);
  1030. {
  1031. dep.notify({
  1032. type: "set" /* TriggerOpTypes.SET */,
  1033. target: obj,
  1034. key,
  1035. newValue: newVal,
  1036. oldValue: value
  1037. });
  1038. }
  1039. }
  1040. });
  1041. return dep;
  1042. }
  1043. function set(target, key, val) {
  1044. if ((isUndef(target) || isPrimitive(target))) {
  1045. warn$2(`Cannot set reactive property on undefined, null, or primitive value: ${target}`);
  1046. }
  1047. if (isReadonly(target)) {
  1048. warn$2(`Set operation on key "${key}" failed: target is readonly.`);
  1049. return;
  1050. }
  1051. const ob = target.__ob__;
  1052. if (isArray(target) && isValidArrayIndex(key)) {
  1053. target.length = Math.max(target.length, key);
  1054. target.splice(key, 1, val);
  1055. // when mocking for SSR, array methods are not hijacked
  1056. if (ob && !ob.shallow && ob.mock) {
  1057. observe(val, false, true);
  1058. }
  1059. return val;
  1060. }
  1061. if (key in target && !(key in Object.prototype)) {
  1062. target[key] = val;
  1063. return val;
  1064. }
  1065. if (target._isVue || (ob && ob.vmCount)) {
  1066. warn$2('Avoid adding reactive properties to a Vue instance or its root $data ' +
  1067. 'at runtime - declare it upfront in the data option.');
  1068. return val;
  1069. }
  1070. if (!ob) {
  1071. target[key] = val;
  1072. return val;
  1073. }
  1074. defineReactive(ob.value, key, val, undefined, ob.shallow, ob.mock);
  1075. {
  1076. ob.dep.notify({
  1077. type: "add" /* TriggerOpTypes.ADD */,
  1078. target: target,
  1079. key,
  1080. newValue: val,
  1081. oldValue: undefined
  1082. });
  1083. }
  1084. return val;
  1085. }
  1086. /**
  1087. * Collect dependencies on array elements when the array is touched, since
  1088. * we cannot intercept array element access like property getters.
  1089. */
  1090. function dependArray(value) {
  1091. for (let e, i = 0, l = value.length; i < l; i++) {
  1092. e = value[i];
  1093. if (e && e.__ob__) {
  1094. e.__ob__.dep.depend();
  1095. }
  1096. if (isArray(e)) {
  1097. dependArray(e);
  1098. }
  1099. }
  1100. }
  1101. function isRef(r) {
  1102. return !!(r && r.__v_isRef === true);
  1103. }
  1104. const normalizeEvent = cached((name) => {
  1105. const passive = name.charAt(0) === '&';
  1106. name = passive ? name.slice(1) : name;
  1107. const once = name.charAt(0) === '~'; // Prefixed last, checked first
  1108. name = once ? name.slice(1) : name;
  1109. const capture = name.charAt(0) === '!';
  1110. name = capture ? name.slice(1) : name;
  1111. return {
  1112. name,
  1113. once,
  1114. capture,
  1115. passive
  1116. };
  1117. });
  1118. function createFnInvoker(fns, vm) {
  1119. function invoker() {
  1120. const fns = invoker.fns;
  1121. if (isArray(fns)) {
  1122. const cloned = fns.slice();
  1123. for (let i = 0; i < cloned.length; i++) {
  1124. invokeWithErrorHandling(cloned[i], null, arguments, vm, `v-on handler`);
  1125. }
  1126. }
  1127. else {
  1128. // return handler return value for single handlers
  1129. return invokeWithErrorHandling(fns, null, arguments, vm, `v-on handler`);
  1130. }
  1131. }
  1132. invoker.fns = fns;
  1133. return invoker;
  1134. }
  1135. function updateListeners(on, oldOn, add, remove, createOnceHandler, vm) {
  1136. let name, cur, old, event;
  1137. for (name in on) {
  1138. cur = on[name];
  1139. old = oldOn[name];
  1140. event = normalizeEvent(name);
  1141. if (isUndef(cur)) {
  1142. warn$2(`Invalid handler for event "${event.name}": got ` + String(cur), vm);
  1143. }
  1144. else if (isUndef(old)) {
  1145. if (isUndef(cur.fns)) {
  1146. cur = on[name] = createFnInvoker(cur, vm);
  1147. }
  1148. if (isTrue(event.once)) {
  1149. cur = on[name] = createOnceHandler(event.name, cur, event.capture);
  1150. }
  1151. add(event.name, cur, event.capture, event.passive, event.params);
  1152. }
  1153. else if (cur !== old) {
  1154. old.fns = cur;
  1155. on[name] = old;
  1156. }
  1157. }
  1158. for (name in oldOn) {
  1159. if (isUndef(on[name])) {
  1160. event = normalizeEvent(name);
  1161. remove(event.name, oldOn[name], event.capture);
  1162. }
  1163. }
  1164. }
  1165. function extractPropsFromVNodeData(data, Ctor, tag) {
  1166. // we are only extracting raw values here.
  1167. // validation and default values are handled in the child
  1168. // component itself.
  1169. const propOptions = Ctor.options.props;
  1170. if (isUndef(propOptions)) {
  1171. return;
  1172. }
  1173. const res = {};
  1174. const { attrs, props } = data;
  1175. if (isDef(attrs) || isDef(props)) {
  1176. for (const key in propOptions) {
  1177. const altKey = hyphenate(key);
  1178. {
  1179. const keyInLowerCase = key.toLowerCase();
  1180. if (key !== keyInLowerCase && attrs && hasOwn(attrs, keyInLowerCase)) {
  1181. tip(`Prop "${keyInLowerCase}" is passed to component ` +
  1182. `${formatComponentName(
  1183. // @ts-expect-error tag is string
  1184. tag || Ctor)}, but the declared prop name is` +
  1185. ` "${key}". ` +
  1186. `Note that HTML attributes are case-insensitive and camelCased ` +
  1187. `props need to use their kebab-case equivalents when using in-DOM ` +
  1188. `templates. You should probably use "${altKey}" instead of "${key}".`);
  1189. }
  1190. }
  1191. checkProp(res, props, key, altKey, true) ||
  1192. checkProp(res, attrs, key, altKey, false);
  1193. }
  1194. }
  1195. return res;
  1196. }
  1197. function checkProp(res, hash, key, altKey, preserve) {
  1198. if (isDef(hash)) {
  1199. if (hasOwn(hash, key)) {
  1200. res[key] = hash[key];
  1201. if (!preserve) {
  1202. delete hash[key];
  1203. }
  1204. return true;
  1205. }
  1206. else if (hasOwn(hash, altKey)) {
  1207. res[key] = hash[altKey];
  1208. if (!preserve) {
  1209. delete hash[altKey];
  1210. }
  1211. return true;
  1212. }
  1213. }
  1214. return false;
  1215. }
  1216. // The template compiler attempts to minimize the need for normalization by
  1217. // statically analyzing the template at compile time.
  1218. //
  1219. // For plain HTML markup, normalization can be completely skipped because the
  1220. // generated render function is guaranteed to return Array<VNode>. There are
  1221. // two cases where extra normalization is needed:
  1222. // 1. When the children contains components - because a functional component
  1223. // may return an Array instead of a single root. In this case, just a simple
  1224. // normalization is needed - if any child is an Array, we flatten the whole
  1225. // thing with Array.prototype.concat. It is guaranteed to be only 1-level deep
  1226. // because functional components already normalize their own children.
  1227. function simpleNormalizeChildren(children) {
  1228. for (let i = 0; i < children.length; i++) {
  1229. if (isArray(children[i])) {
  1230. return Array.prototype.concat.apply([], children);
  1231. }
  1232. }
  1233. return children;
  1234. }
  1235. // 2. When the children contains constructs that always generated nested Arrays,
  1236. // e.g. <template>, <slot>, v-for, or when the children is provided by user
  1237. // with hand-written render functions / JSX. In such cases a full normalization
  1238. // is needed to cater to all possible types of children values.
  1239. function normalizeChildren(children) {
  1240. return isPrimitive(children)
  1241. ? [createTextVNode(children)]
  1242. : isArray(children)
  1243. ? normalizeArrayChildren(children)
  1244. : undefined;
  1245. }
  1246. function isTextNode(node) {
  1247. return isDef(node) && isDef(node.text) && isFalse(node.isComment);
  1248. }
  1249. function normalizeArrayChildren(children, nestedIndex) {
  1250. const res = [];
  1251. let i, c, lastIndex, last;
  1252. for (i = 0; i < children.length; i++) {
  1253. c = children[i];
  1254. if (isUndef(c) || typeof c === 'boolean')
  1255. continue;
  1256. lastIndex = res.length - 1;
  1257. last = res[lastIndex];
  1258. // nested
  1259. if (isArray(c)) {
  1260. if (c.length > 0) {
  1261. c = normalizeArrayChildren(c, `${nestedIndex || ''}_${i}`);
  1262. // merge adjacent text nodes
  1263. if (isTextNode(c[0]) && isTextNode(last)) {
  1264. res[lastIndex] = createTextVNode(last.text + c[0].text);
  1265. c.shift();
  1266. }
  1267. res.push.apply(res, c);
  1268. }
  1269. }
  1270. else if (isPrimitive(c)) {
  1271. if (isTextNode(last)) {
  1272. // merge adjacent text nodes
  1273. // this is necessary for SSR hydration because text nodes are
  1274. // essentially merged when rendered to HTML strings
  1275. res[lastIndex] = createTextVNode(last.text + c);
  1276. }
  1277. else if (c !== '') {
  1278. // convert primitive to vnode
  1279. res.push(createTextVNode(c));
  1280. }
  1281. }
  1282. else {
  1283. if (isTextNode(c) && isTextNode(last)) {
  1284. // merge adjacent text nodes
  1285. res[lastIndex] = createTextVNode(last.text + c.text);
  1286. }
  1287. else {
  1288. // default key for nested array children (likely generated by v-for)
  1289. if (isTrue(children._isVList) &&
  1290. isDef(c.tag) &&
  1291. isUndef(c.key) &&
  1292. isDef(nestedIndex)) {
  1293. c.key = `__vlist${nestedIndex}_${i}__`;
  1294. }
  1295. res.push(c);
  1296. }
  1297. }
  1298. }
  1299. return res;
  1300. }
  1301. const SIMPLE_NORMALIZE = 1;
  1302. const ALWAYS_NORMALIZE = 2;
  1303. // wrapper function for providing a more flexible interface
  1304. // without getting yelled at by flow
  1305. function createElement(context, tag, data, children, normalizationType, alwaysNormalize) {
  1306. if (isArray(data) || isPrimitive(data)) {
  1307. normalizationType = children;
  1308. children = data;
  1309. data = undefined;
  1310. }
  1311. if (isTrue(alwaysNormalize)) {
  1312. normalizationType = ALWAYS_NORMALIZE;
  1313. }
  1314. return _createElement(context, tag, data, children, normalizationType);
  1315. }
  1316. function _createElement(context, tag, data, children, normalizationType) {
  1317. if (isDef(data) && isDef(data.__ob__)) {
  1318. warn$2(`Avoid using observed data object as vnode data: ${JSON.stringify(data)}\n` + 'Always create fresh vnode data objects in each render!', context);
  1319. return createEmptyVNode();
  1320. }
  1321. // object syntax in v-bind
  1322. if (isDef(data) && isDef(data.is)) {
  1323. tag = data.is;
  1324. }
  1325. if (!tag) {
  1326. // in case of component :is set to falsy value
  1327. return createEmptyVNode();
  1328. }
  1329. // warn against non-primitive key
  1330. if (isDef(data) && isDef(data.key) && !isPrimitive(data.key)) {
  1331. warn$2('Avoid using non-primitive value as key, ' +
  1332. 'use string/number value instead.', context);
  1333. }
  1334. // support single function children as default scoped slot
  1335. if (isArray(children) && isFunction(children[0])) {
  1336. data = data || {};
  1337. data.scopedSlots = { default: children[0] };
  1338. children.length = 0;
  1339. }
  1340. if (normalizationType === ALWAYS_NORMALIZE) {
  1341. children = normalizeChildren(children);
  1342. }
  1343. else if (normalizationType === SIMPLE_NORMALIZE) {
  1344. children = simpleNormalizeChildren(children);
  1345. }
  1346. let vnode, ns;
  1347. if (typeof tag === 'string') {
  1348. let Ctor;
  1349. ns = (context.$vnode && context.$vnode.ns) || config.getTagNamespace(tag);
  1350. if ((!data || !data.pre) &&
  1351. isDef((Ctor = resolveAsset(context.$options, 'components', tag)))) {
  1352. // component
  1353. vnode = createComponent(Ctor, data, context, children, tag);
  1354. }
  1355. else {
  1356. // unknown or unlisted namespaced elements
  1357. // check at runtime because it may get assigned a namespace when its
  1358. // parent normalizes children
  1359. vnode = new VNode(tag, data, children, undefined, undefined, context);
  1360. }
  1361. }
  1362. else {
  1363. // direct component options / constructor
  1364. vnode = createComponent(tag, data, context, children);
  1365. }
  1366. if (isArray(vnode)) {
  1367. return vnode;
  1368. }
  1369. else if (isDef(vnode)) {
  1370. if (isDef(ns))
  1371. applyNS(vnode, ns);
  1372. if (isDef(data))
  1373. registerDeepBindings(data);
  1374. return vnode;
  1375. }
  1376. else {
  1377. return createEmptyVNode();
  1378. }
  1379. }
  1380. function applyNS(vnode, ns, force) {
  1381. vnode.ns = ns;
  1382. if (vnode.tag === 'foreignObject') {
  1383. // use default namespace inside foreignObject
  1384. ns = undefined;
  1385. force = true;
  1386. }
  1387. if (isDef(vnode.children)) {
  1388. for (let i = 0, l = vnode.children.length; i < l; i++) {
  1389. const child = vnode.children[i];
  1390. if (isDef(child.tag) &&
  1391. (isUndef(child.ns) || (isTrue(force) && child.tag !== 'svg'))) {
  1392. applyNS(child, ns, force);
  1393. }
  1394. }
  1395. }
  1396. }
  1397. // ref #5318
  1398. // necessary to ensure parent re-render when deep bindings like :style and
  1399. // :class are used on slot nodes
  1400. function registerDeepBindings(data) {
  1401. if (isObject(data.style)) {
  1402. traverse(data.style);
  1403. }
  1404. if (isObject(data.class)) {
  1405. traverse(data.class);
  1406. }
  1407. }
  1408. /**
  1409. * Runtime helper for rendering v-for lists.
  1410. */
  1411. function renderList(val, render) {
  1412. let ret = null, i, l, keys, key;
  1413. if (isArray(val) || typeof val === 'string') {
  1414. ret = new Array(val.length);
  1415. for (i = 0, l = val.length; i < l; i++) {
  1416. ret[i] = render(val[i], i);
  1417. }
  1418. }
  1419. else if (typeof val === 'number') {
  1420. ret = new Array(val);
  1421. for (i = 0; i < val; i++) {
  1422. ret[i] = render(i + 1, i);
  1423. }
  1424. }
  1425. else if (isObject(val)) {
  1426. if (hasSymbol && val[Symbol.iterator]) {
  1427. ret = [];
  1428. const iterator = val[Symbol.iterator]();
  1429. let result = iterator.next();
  1430. while (!result.done) {
  1431. ret.push(render(result.value, ret.length));
  1432. result = iterator.next();
  1433. }
  1434. }
  1435. else {
  1436. keys = Object.keys(val);
  1437. ret = new Array(keys.length);
  1438. for (i = 0, l = keys.length; i < l; i++) {
  1439. key = keys[i];
  1440. ret[i] = render(val[key], key, i);
  1441. }
  1442. }
  1443. }
  1444. if (!isDef(ret)) {
  1445. ret = [];
  1446. }
  1447. ret._isVList = true;
  1448. return ret;
  1449. }
  1450. /**
  1451. * Runtime helper for rendering <slot>
  1452. */
  1453. function renderSlot(name, fallbackRender, props, bindObject) {
  1454. const scopedSlotFn = this.$scopedSlots[name];
  1455. let nodes;
  1456. if (scopedSlotFn) {
  1457. // scoped slot
  1458. props = props || {};
  1459. if (bindObject) {
  1460. if (!isObject(bindObject)) {
  1461. warn$2('slot v-bind without argument expects an Object', this);
  1462. }
  1463. props = extend(extend({}, bindObject), props);
  1464. }
  1465. nodes =
  1466. scopedSlotFn(props) ||
  1467. (isFunction(fallbackRender) ? fallbackRender() : fallbackRender);
  1468. }
  1469. else {
  1470. nodes =
  1471. this.$slots[name] ||
  1472. (isFunction(fallbackRender) ? fallbackRender() : fallbackRender);
  1473. }
  1474. const target = props && props.slot;
  1475. if (target) {
  1476. return this.$createElement('template', { slot: target }, nodes);
  1477. }
  1478. else {
  1479. return nodes;
  1480. }
  1481. }
  1482. /**
  1483. * Runtime helper for resolving filters
  1484. */
  1485. function resolveFilter(id) {
  1486. return resolveAsset(this.$options, 'filters', id, true) || identity;
  1487. }
  1488. function isKeyNotMatch(expect, actual) {
  1489. if (isArray(expect)) {
  1490. return expect.indexOf(actual) === -1;
  1491. }
  1492. else {
  1493. return expect !== actual;
  1494. }
  1495. }
  1496. /**
  1497. * Runtime helper for checking keyCodes from config.
  1498. * exposed as Vue.prototype._k
  1499. * passing in eventKeyName as last argument separately for backwards compat
  1500. */
  1501. function checkKeyCodes(eventKeyCode, key, builtInKeyCode, eventKeyName, builtInKeyName) {
  1502. const mappedKeyCode = config.keyCodes[key] || builtInKeyCode;
  1503. if (builtInKeyName && eventKeyName && !config.keyCodes[key]) {
  1504. return isKeyNotMatch(builtInKeyName, eventKeyName);
  1505. }
  1506. else if (mappedKeyCode) {
  1507. return isKeyNotMatch(mappedKeyCode, eventKeyCode);
  1508. }
  1509. else if (eventKeyName) {
  1510. return hyphenate(eventKeyName) !== key;
  1511. }
  1512. return eventKeyCode === undefined;
  1513. }
  1514. /**
  1515. * Runtime helper for merging v-bind="object" into a VNode's data.
  1516. */
  1517. function bindObjectProps(data, tag, value, asProp, isSync) {
  1518. if (value) {
  1519. if (!isObject(value)) {
  1520. warn$2('v-bind without argument expects an Object or Array value', this);
  1521. }
  1522. else {
  1523. if (isArray(value)) {
  1524. value = toObject(value);
  1525. }
  1526. let hash;
  1527. for (const key in value) {
  1528. if (key === 'class' || key === 'style' || isReservedAttribute(key)) {
  1529. hash = data;
  1530. }
  1531. else {
  1532. const type = data.attrs && data.attrs.type;
  1533. hash =
  1534. asProp || config.mustUseProp(tag, type, key)
  1535. ? data.domProps || (data.domProps = {})
  1536. : data.attrs || (data.attrs = {});
  1537. }
  1538. const camelizedKey = camelize(key);
  1539. const hyphenatedKey = hyphenate(key);
  1540. if (!(camelizedKey in hash) && !(hyphenatedKey in hash)) {
  1541. hash[key] = value[key];
  1542. if (isSync) {
  1543. const on = data.on || (data.on = {});
  1544. on[`update:${key}`] = function ($event) {
  1545. value[key] = $event;
  1546. };
  1547. }
  1548. }
  1549. }
  1550. }
  1551. }
  1552. return data;
  1553. }
  1554. /**
  1555. * Runtime helper for rendering static trees.
  1556. */
  1557. function renderStatic(index, isInFor) {
  1558. const cached = this._staticTrees || (this._staticTrees = []);
  1559. let tree = cached[index];
  1560. // if has already-rendered static tree and not inside v-for,
  1561. // we can reuse the same tree.
  1562. if (tree && !isInFor) {
  1563. return tree;
  1564. }
  1565. // otherwise, render a fresh tree.
  1566. tree = cached[index] = this.$options.staticRenderFns[index].call(this._renderProxy, this._c, this // for render fns generated for functional component templates
  1567. );
  1568. markStatic(tree, `__static__${index}`, false);
  1569. return tree;
  1570. }
  1571. /**
  1572. * Runtime helper for v-once.
  1573. * Effectively it means marking the node as static with a unique key.
  1574. */
  1575. function markOnce(tree, index, key) {
  1576. markStatic(tree, `__once__${index}${key ? `_${key}` : ``}`, true);
  1577. return tree;
  1578. }
  1579. function markStatic(tree, key, isOnce) {
  1580. if (isArray(tree)) {
  1581. for (let i = 0; i < tree.length; i++) {
  1582. if (tree[i] && typeof tree[i] !== 'string') {
  1583. markStaticNode(tree[i], `${key}_${i}`, isOnce);
  1584. }
  1585. }
  1586. }
  1587. else {
  1588. markStaticNode(tree, key, isOnce);
  1589. }
  1590. }
  1591. function markStaticNode(node, key, isOnce) {
  1592. node.isStatic = true;
  1593. node.key = key;
  1594. node.isOnce = isOnce;
  1595. }
  1596. function bindObjectListeners(data, value) {
  1597. if (value) {
  1598. if (!isPlainObject(value)) {
  1599. warn$2('v-on without argument expects an Object value', this);
  1600. }
  1601. else {
  1602. const on = (data.on = data.on ? extend({}, data.on) : {});
  1603. for (const key in value) {
  1604. const existing = on[key];
  1605. const ours = value[key];
  1606. on[key] = existing ? [].concat(existing, ours) : ours;
  1607. }
  1608. }
  1609. }
  1610. return data;
  1611. }
  1612. function resolveScopedSlots(fns, res,
  1613. // the following are added in 2.6
  1614. hasDynamicKeys, contentHashKey) {
  1615. res = res || { $stable: !hasDynamicKeys };
  1616. for (let i = 0; i < fns.length; i++) {
  1617. const slot = fns[i];
  1618. if (isArray(slot)) {
  1619. resolveScopedSlots(slot, res, hasDynamicKeys);
  1620. }
  1621. else if (slot) {
  1622. // marker for reverse proxying v-slot without scope on this.$slots
  1623. // @ts-expect-error
  1624. if (slot.proxy) {
  1625. // @ts-expect-error
  1626. slot.fn.proxy = true;
  1627. }
  1628. res[slot.key] = slot.fn;
  1629. }
  1630. }
  1631. if (contentHashKey) {
  1632. res.$key = contentHashKey;
  1633. }
  1634. return res;
  1635. }
  1636. // helper to process dynamic keys for dynamic arguments in v-bind and v-on.
  1637. function bindDynamicKeys(baseObj, values) {
  1638. for (let i = 0; i < values.length; i += 2) {
  1639. const key = values[i];
  1640. if (typeof key === 'string' && key) {
  1641. baseObj[values[i]] = values[i + 1];
  1642. }
  1643. else if (key !== '' && key !== null) {
  1644. // null is a special value for explicitly removing a binding
  1645. warn$2(`Invalid value for dynamic directive argument (expected string or null): ${key}`, this);
  1646. }
  1647. }
  1648. return baseObj;
  1649. }
  1650. // helper to dynamically append modifier runtime markers to event names.
  1651. // ensure only append when value is already string, otherwise it will be cast
  1652. // to string and cause the type check to miss.
  1653. function prependModifier(value, symbol) {
  1654. return typeof value === 'string' ? symbol + value : value;
  1655. }
  1656. function installRenderHelpers(target) {
  1657. target._o = markOnce;
  1658. target._n = toNumber;
  1659. target._s = toString;
  1660. target._l = renderList;
  1661. target._t = renderSlot;
  1662. target._q = looseEqual;
  1663. target._i = looseIndexOf;
  1664. target._m = renderStatic;
  1665. target._f = resolveFilter;
  1666. target._k = checkKeyCodes;
  1667. target._b = bindObjectProps;
  1668. target._v = createTextVNode;
  1669. target._e = createEmptyVNode;
  1670. target._u = resolveScopedSlots;
  1671. target._g = bindObjectListeners;
  1672. target._d = bindDynamicKeys;
  1673. target._p = prependModifier;
  1674. }
  1675. /**
  1676. * Runtime helper for resolving raw children VNodes into a slot object.
  1677. */
  1678. function resolveSlots(children, context) {
  1679. if (!children || !children.length) {
  1680. return {};
  1681. }
  1682. const slots = {};
  1683. for (let i = 0, l = children.length; i < l; i++) {
  1684. const child = children[i];
  1685. const data = child.data;
  1686. // remove slot attribute if the node is resolved as a Vue slot node
  1687. if (data && data.attrs && data.attrs.slot) {
  1688. delete data.attrs.slot;
  1689. }
  1690. // named slots should only be respected if the vnode was rendered in the
  1691. // same context.
  1692. if ((child.context === context || child.fnContext === context) &&
  1693. data &&
  1694. data.slot != null) {
  1695. const name = data.slot;
  1696. const slot = slots[name] || (slots[name] = []);
  1697. if (child.tag === 'template') {
  1698. slot.push.apply(slot, child.children || []);
  1699. }
  1700. else {
  1701. slot.push(child);
  1702. }
  1703. }
  1704. else {
  1705. (slots.default || (slots.default = [])).push(child);
  1706. }
  1707. }
  1708. // ignore slots that contains only whitespace
  1709. for (const name in slots) {
  1710. if (slots[name].every(isWhitespace)) {
  1711. delete slots[name];
  1712. }
  1713. }
  1714. return slots;
  1715. }
  1716. function isWhitespace(node) {
  1717. return (node.isComment && !node.asyncFactory) || node.text === ' ';
  1718. }
  1719. function isAsyncPlaceholder(node) {
  1720. // @ts-expect-error not really boolean type
  1721. return node.isComment && node.asyncFactory;
  1722. }
  1723. function normalizeScopedSlots(ownerVm, scopedSlots, normalSlots, prevScopedSlots) {
  1724. let res;
  1725. const hasNormalSlots = Object.keys(normalSlots).length > 0;
  1726. const isStable = scopedSlots ? !!scopedSlots.$stable : !hasNormalSlots;
  1727. const key = scopedSlots && scopedSlots.$key;
  1728. if (!scopedSlots) {
  1729. res = {};
  1730. }
  1731. else if (scopedSlots._normalized) {
  1732. // fast path 1: child component re-render only, parent did not change
  1733. return scopedSlots._normalized;
  1734. }
  1735. else if (isStable &&
  1736. prevScopedSlots &&
  1737. prevScopedSlots !== emptyObject &&
  1738. key === prevScopedSlots.$key &&
  1739. !hasNormalSlots &&
  1740. !prevScopedSlots.$hasNormal) {
  1741. // fast path 2: stable scoped slots w/ no normal slots to proxy,
  1742. // only need to normalize once
  1743. return prevScopedSlots;
  1744. }
  1745. else {
  1746. res = {};
  1747. for (const key in scopedSlots) {
  1748. if (scopedSlots[key] && key[0] !== '$') {
  1749. res[key] = normalizeScopedSlot(ownerVm, normalSlots, key, scopedSlots[key]);
  1750. }
  1751. }
  1752. }
  1753. // expose normal slots on scopedSlots
  1754. for (const key in normalSlots) {
  1755. if (!(key in res)) {
  1756. res[key] = proxyNormalSlot(normalSlots, key);
  1757. }
  1758. }
  1759. // avoriaz seems to mock a non-extensible $scopedSlots object
  1760. // and when that is passed down this would cause an error
  1761. if (scopedSlots && Object.isExtensible(scopedSlots)) {
  1762. scopedSlots._normalized = res;
  1763. }
  1764. def(res, '$stable', isStable);
  1765. def(res, '$key', key);
  1766. def(res, '$hasNormal', hasNormalSlots);
  1767. return res;
  1768. }
  1769. function normalizeScopedSlot(vm, normalSlots, key, fn) {
  1770. const normalized = function () {
  1771. const cur = currentInstance;
  1772. setCurrentInstance(vm);
  1773. let res = arguments.length ? fn.apply(null, arguments) : fn({});
  1774. res =
  1775. res && typeof res === 'object' && !isArray(res)
  1776. ? [res] // single vnode
  1777. : normalizeChildren(res);
  1778. const vnode = res && res[0];
  1779. setCurrentInstance(cur);
  1780. return res &&
  1781. (!vnode ||
  1782. (res.length === 1 && vnode.isComment && !isAsyncPlaceholder(vnode))) // #9658, #10391
  1783. ? undefined
  1784. : res;
  1785. };
  1786. // this is a slot using the new v-slot syntax without scope. although it is
  1787. // compiled as a scoped slot, render fn users would expect it to be present
  1788. // on this.$slots because the usage is semantically a normal slot.
  1789. if (fn.proxy) {
  1790. Object.defineProperty(normalSlots, key, {
  1791. get: normalized,
  1792. enumerable: true,
  1793. configurable: true
  1794. });
  1795. }
  1796. return normalized;
  1797. }
  1798. function proxyNormalSlot(slots, key) {
  1799. return () => slots[key];
  1800. }
  1801. function syncSetupProxy(to, from, prev, instance, type) {
  1802. let changed = false;
  1803. for (const key in from) {
  1804. if (!(key in to)) {
  1805. changed = true;
  1806. defineProxyAttr(to, key, instance, type);
  1807. }
  1808. else if (from[key] !== prev[key]) {
  1809. changed = true;
  1810. }
  1811. }
  1812. for (const key in to) {
  1813. if (!(key in from)) {
  1814. changed = true;
  1815. delete to[key];
  1816. }
  1817. }
  1818. return changed;
  1819. }
  1820. function defineProxyAttr(proxy, key, instance, type) {
  1821. Object.defineProperty(proxy, key, {
  1822. enumerable: true,
  1823. configurable: true,
  1824. get() {
  1825. return instance[type][key];
  1826. }
  1827. });
  1828. }
  1829. function createAsyncPlaceholder(factory, data, context, children, tag) {
  1830. const node = createEmptyVNode();
  1831. node.asyncFactory = factory;
  1832. node.asyncMeta = { data, context, children, tag };
  1833. return node;
  1834. }
  1835. function resolveAsyncComponent(factory, baseCtor) {
  1836. if (isTrue(factory.error) && isDef(factory.errorComp)) {
  1837. return factory.errorComp;
  1838. }
  1839. if (isDef(factory.resolved)) {
  1840. return factory.resolved;
  1841. }
  1842. if (isTrue(factory.loading) && isDef(factory.loadingComp)) {
  1843. return factory.loadingComp;
  1844. }
  1845. }
  1846. let target;
  1847. function add(event, fn) {
  1848. target.$on(event, fn);
  1849. }
  1850. function remove(event, fn) {
  1851. target.$off(event, fn);
  1852. }
  1853. function createOnceHandler(event, fn) {
  1854. const _target = target;
  1855. return function onceHandler() {
  1856. const res = fn.apply(null, arguments);
  1857. if (res !== null) {
  1858. _target.$off(event, onceHandler);
  1859. }
  1860. };
  1861. }
  1862. function updateComponentListeners(vm, listeners, oldListeners) {
  1863. target = vm;
  1864. updateListeners(listeners, oldListeners || {}, add, remove, createOnceHandler, vm);
  1865. target = undefined;
  1866. }
  1867. let activeInstance = null;
  1868. function updateChildComponent(vm, propsData, listeners, parentVnode, renderChildren) {
  1869. // determine whether component has slot children
  1870. // we need to do this before overwriting $options._renderChildren.
  1871. // check if there are dynamic scopedSlots (hand-written or compiled but with
  1872. // dynamic slot names). Static scoped slots compiled from template has the
  1873. // "$stable" marker.
  1874. const newScopedSlots = parentVnode.data.scopedSlots;
  1875. const oldScopedSlots = vm.$scopedSlots;
  1876. const hasDynamicScopedSlot = !!((newScopedSlots && !newScopedSlots.$stable) ||
  1877. (oldScopedSlots !== emptyObject && !oldScopedSlots.$stable) ||
  1878. (newScopedSlots && vm.$scopedSlots.$key !== newScopedSlots.$key) ||
  1879. (!newScopedSlots && vm.$scopedSlots.$key));
  1880. // Any static slot children from the parent may have changed during parent's
  1881. // update. Dynamic scoped slots may also have changed. In such cases, a forced
  1882. // update is necessary to ensure correctness.
  1883. let needsForceUpdate = !!(renderChildren || // has new static slots
  1884. vm.$options._renderChildren || // has old static slots
  1885. hasDynamicScopedSlot);
  1886. const prevVNode = vm.$vnode;
  1887. vm.$options._parentVnode = parentVnode;
  1888. vm.$vnode = parentVnode; // update vm's placeholder node without re-render
  1889. if (vm._vnode) {
  1890. // update child tree's parent
  1891. vm._vnode.parent = parentVnode;
  1892. }
  1893. vm.$options._renderChildren = renderChildren;
  1894. // update $attrs and $listeners hash
  1895. // these are also reactive so they may trigger child update if the child
  1896. // used them during render
  1897. const attrs = parentVnode.data.attrs || emptyObject;
  1898. if (vm._attrsProxy) {
  1899. // force update if attrs are accessed and has changed since it may be
  1900. // passed to a child component.
  1901. if (syncSetupProxy(vm._attrsProxy, attrs, (prevVNode.data && prevVNode.data.attrs) || emptyObject, vm, '$attrs')) {
  1902. needsForceUpdate = true;
  1903. }
  1904. }
  1905. vm.$attrs = attrs;
  1906. // update listeners
  1907. listeners = listeners || emptyObject;
  1908. const prevListeners = vm.$options._parentListeners;
  1909. if (vm._listenersProxy) {
  1910. syncSetupProxy(vm._listenersProxy, listeners, prevListeners || emptyObject, vm, '$listeners');
  1911. }
  1912. vm.$listeners = vm.$options._parentListeners = listeners;
  1913. updateComponentListeners(vm, listeners, prevListeners);
  1914. // update props
  1915. if (propsData && vm.$options.props) {
  1916. toggleObserving(false);
  1917. const props = vm._props;
  1918. const propKeys = vm.$options._propKeys || [];
  1919. for (let i = 0; i < propKeys.length; i++) {
  1920. const key = propKeys[i];
  1921. const propOptions = vm.$options.props; // wtf flow?
  1922. props[key] = validateProp(key, propOptions, propsData, vm);
  1923. }
  1924. toggleObserving(true);
  1925. // keep a copy of raw propsData
  1926. vm.$options.propsData = propsData;
  1927. }
  1928. // resolve slots + force update if has children
  1929. if (needsForceUpdate) {
  1930. vm.$slots = resolveSlots(renderChildren, parentVnode.context);
  1931. vm.$forceUpdate();
  1932. }
  1933. }
  1934. function isInInactiveTree(vm) {
  1935. while (vm && (vm = vm.$parent)) {
  1936. if (vm._inactive)
  1937. return true;
  1938. }
  1939. return false;
  1940. }
  1941. function activateChildComponent(vm, direct) {
  1942. if (direct) {
  1943. vm._directInactive = false;
  1944. if (isInInactiveTree(vm)) {
  1945. return;
  1946. }
  1947. }
  1948. else if (vm._directInactive) {
  1949. return;
  1950. }
  1951. if (vm._inactive || vm._inactive === null) {
  1952. vm._inactive = false;
  1953. for (let i = 0; i < vm.$children.length; i++) {
  1954. activateChildComponent(vm.$children[i]);
  1955. }
  1956. callHook(vm, 'activated');
  1957. }
  1958. }
  1959. function deactivateChildComponent(vm, direct) {
  1960. if (direct) {
  1961. vm._directInactive = true;
  1962. if (isInInactiveTree(vm)) {
  1963. return;
  1964. }
  1965. }
  1966. if (!vm._inactive) {
  1967. vm._inactive = true;
  1968. for (let i = 0; i < vm.$children.length; i++) {
  1969. deactivateChildComponent(vm.$children[i]);
  1970. }
  1971. callHook(vm, 'deactivated');
  1972. }
  1973. }
  1974. function callHook(vm, hook, args, setContext = true) {
  1975. // #7573 disable dep collection when invoking lifecycle hooks
  1976. pushTarget();
  1977. const prev = currentInstance;
  1978. setContext && setCurrentInstance(vm);
  1979. const handlers = vm.$options[hook];
  1980. const info = `${hook} hook`;
  1981. if (handlers) {
  1982. for (let i = 0, j = handlers.length; i < j; i++) {
  1983. invokeWithErrorHandling(handlers[i], vm, args || null, vm, info);
  1984. }
  1985. }
  1986. if (vm._hasHookEvent) {
  1987. vm.$emit('hook:' + hook);
  1988. }
  1989. setContext && setCurrentInstance(prev);
  1990. popTarget();
  1991. }
  1992. // Async edge case fix requires storing an event listener's attach timestamp.
  1993. let getNow = Date.now;
  1994. // Determine what event timestamp the browser is using. Annoyingly, the
  1995. // timestamp can either be hi-res (relative to page load) or low-res
  1996. // (relative to UNIX epoch), so in order to compare time we have to use the
  1997. // same timestamp type when saving the flush timestamp.
  1998. // All IE versions use low-res event timestamps, and have problematic clock
  1999. // implementations (#9632)
  2000. if (inBrowser && !isIE) {
  2001. const performance = window.performance;
  2002. if (performance &&
  2003. typeof performance.now === 'function' &&
  2004. getNow() > document.createEvent('Event').timeStamp) {
  2005. // if the event timestamp, although evaluated AFTER the Date.now(), is
  2006. // smaller than it, it means the event is using a hi-res timestamp,
  2007. // and we need to use the hi-res version for event listener timestamps as
  2008. // well.
  2009. getNow = () => performance.now();
  2010. }
  2011. }
  2012. /**
  2013. * Queue a kept-alive component that was activated during patch.
  2014. * The queue will be processed after the entire tree has been patched.
  2015. */
  2016. function queueActivatedComponent(vm) {
  2017. // setting _inactive to false here so that a render function can
  2018. // rely on checking whether it's in an inactive tree (e.g. router-view)
  2019. vm._inactive = false;
  2020. }
  2021. function handleError(err, vm, info) {
  2022. // Deactivate deps tracking while processing error handler to avoid possible infinite rendering.
  2023. // See: https://github.com/vuejs/vuex/issues/1505
  2024. pushTarget();
  2025. try {
  2026. if (vm) {
  2027. let cur = vm;
  2028. while ((cur = cur.$parent)) {
  2029. const hooks = cur.$options.errorCaptured;
  2030. if (hooks) {
  2031. for (let i = 0; i < hooks.length; i++) {
  2032. try {
  2033. const capture = hooks[i].call(cur, err, vm, info) === false;
  2034. if (capture)
  2035. return;
  2036. }
  2037. catch (e) {
  2038. globalHandleError(e, cur, 'errorCaptured hook');
  2039. }
  2040. }
  2041. }
  2042. }
  2043. }
  2044. globalHandleError(err, vm, info);
  2045. }
  2046. finally {
  2047. popTarget();
  2048. }
  2049. }
  2050. function invokeWithErrorHandling(handler, context, args, vm, info) {
  2051. let res;
  2052. try {
  2053. res = args ? handler.apply(context, args) : handler.call(context);
  2054. if (res && !res._isVue && isPromise(res) && !res._handled) {
  2055. res.catch(e => handleError(e, vm, info + ` (Promise/async)`));
  2056. res._handled = true;
  2057. }
  2058. }
  2059. catch (e) {
  2060. handleError(e, vm, info);
  2061. }
  2062. return res;
  2063. }
  2064. function globalHandleError(err, vm, info) {
  2065. logError(err, vm, info);
  2066. }
  2067. function logError(err, vm, info) {
  2068. {
  2069. warn$2(`Error in ${info}: "${err.toString()}"`, vm);
  2070. }
  2071. /* istanbul ignore else */
  2072. if (inBrowser && typeof console !== 'undefined') {
  2073. console.error(err);
  2074. }
  2075. else {
  2076. throw err;
  2077. }
  2078. }
  2079. /* globals MutationObserver */
  2080. const callbacks = [];
  2081. function flushCallbacks() {
  2082. const copies = callbacks.slice(0);
  2083. callbacks.length = 0;
  2084. for (let i = 0; i < copies.length; i++) {
  2085. copies[i]();
  2086. }
  2087. }
  2088. // The nextTick behavior leverages the microtask queue, which can be accessed
  2089. // via either native Promise.then or MutationObserver.
  2090. // MutationObserver has wider support, however it is seriously bugged in
  2091. // UIWebView in iOS >= 9.3.3 when triggered in touch event handlers. It
  2092. // completely stops working after triggering a few times... so, if native
  2093. // Promise is available, we will use it:
  2094. /* istanbul ignore next, $flow-disable-line */
  2095. if (typeof Promise !== 'undefined' && isNative(Promise)) {
  2096. Promise.resolve();
  2097. }
  2098. else if (!isIE &&
  2099. typeof MutationObserver !== 'undefined' &&
  2100. (isNative(MutationObserver) ||
  2101. // PhantomJS and iOS 7.x
  2102. MutationObserver.toString() === '[object MutationObserverConstructor]')) {
  2103. // Use MutationObserver where native Promise is not available,
  2104. // e.g. PhantomJS, iOS7, Android 4.4
  2105. // (#6466 MutationObserver is unreliable in IE11)
  2106. let counter = 1;
  2107. const observer = new MutationObserver(flushCallbacks);
  2108. const textNode = document.createTextNode(String(counter));
  2109. observer.observe(textNode, {
  2110. characterData: true
  2111. });
  2112. }
  2113. else if (typeof setImmediate !== 'undefined' && isNative(setImmediate)) ;
  2114. else ;
  2115. const seenObjects = new _Set();
  2116. /**
  2117. * Recursively traverse an object to evoke all converted
  2118. * getters, so that every nested property inside the object
  2119. * is collected as a "deep" dependency.
  2120. */
  2121. function traverse(val) {
  2122. _traverse(val, seenObjects);
  2123. seenObjects.clear();
  2124. return val;
  2125. }
  2126. function _traverse(val, seen) {
  2127. let i, keys;
  2128. const isA = isArray(val);
  2129. if ((!isA && !isObject(val)) ||
  2130. val.__v_skip /* ReactiveFlags.SKIP */ ||
  2131. Object.isFrozen(val) ||
  2132. val instanceof VNode) {
  2133. return;
  2134. }
  2135. if (val.__ob__) {
  2136. const depId = val.__ob__.dep.id;
  2137. if (seen.has(depId)) {
  2138. return;
  2139. }
  2140. seen.add(depId);
  2141. }
  2142. if (isA) {
  2143. i = val.length;
  2144. while (i--)
  2145. _traverse(val[i], seen);
  2146. }
  2147. else if (isRef(val)) {
  2148. _traverse(val.value, seen);
  2149. }
  2150. else {
  2151. keys = Object.keys(val);
  2152. i = keys.length;
  2153. while (i--)
  2154. _traverse(val[keys[i]], seen);
  2155. }
  2156. }
  2157. function resolveInject(inject, vm) {
  2158. if (inject) {
  2159. // inject is :any because flow is not smart enough to figure out cached
  2160. const result = Object.create(null);
  2161. const keys = hasSymbol ? Reflect.ownKeys(inject) : Object.keys(inject);
  2162. for (let i = 0; i < keys.length; i++) {
  2163. const key = keys[i];
  2164. // #6574 in case the inject object is observed...
  2165. if (key === '__ob__')
  2166. continue;
  2167. const provideKey = inject[key].from;
  2168. if (provideKey in vm._provided) {
  2169. result[key] = vm._provided[provideKey];
  2170. }
  2171. else if ('default' in inject[key]) {
  2172. const provideDefault = inject[key].default;
  2173. result[key] = isFunction(provideDefault)
  2174. ? provideDefault.call(vm)
  2175. : provideDefault;
  2176. }
  2177. else {
  2178. warn$2(`Injection "${key}" not found`, vm);
  2179. }
  2180. }
  2181. return result;
  2182. }
  2183. }
  2184. function resolveConstructorOptions(Ctor) {
  2185. let options = Ctor.options;
  2186. if (Ctor.super) {
  2187. const superOptions = resolveConstructorOptions(Ctor.super);
  2188. const cachedSuperOptions = Ctor.superOptions;
  2189. if (superOptions !== cachedSuperOptions) {
  2190. // super option changed,
  2191. // need to resolve new options.
  2192. Ctor.superOptions = superOptions;
  2193. // check if there are any late-modified/attached options (#4976)
  2194. const modifiedOptions = resolveModifiedOptions(Ctor);
  2195. // update base extend options
  2196. if (modifiedOptions) {
  2197. extend(Ctor.extendOptions, modifiedOptions);
  2198. }
  2199. options = Ctor.options = mergeOptions(superOptions, Ctor.extendOptions);
  2200. if (options.name) {
  2201. options.components[options.name] = Ctor;
  2202. }
  2203. }
  2204. }
  2205. return options;
  2206. }
  2207. function resolveModifiedOptions(Ctor) {
  2208. let modified;
  2209. const latest = Ctor.options;
  2210. const sealed = Ctor.sealedOptions;
  2211. for (const key in latest) {
  2212. if (latest[key] !== sealed[key]) {
  2213. if (!modified)
  2214. modified = {};
  2215. modified[key] = latest[key];
  2216. }
  2217. }
  2218. return modified;
  2219. }
  2220. function FunctionalRenderContext(data, props, children, parent, Ctor) {
  2221. const options = Ctor.options;
  2222. // ensure the createElement function in functional components
  2223. // gets a unique context - this is necessary for correct named slot check
  2224. let contextVm;
  2225. if (hasOwn(parent, '_uid')) {
  2226. contextVm = Object.create(parent);
  2227. contextVm._original = parent;
  2228. }
  2229. else {
  2230. // the context vm passed in is a functional context as well.
  2231. // in this case we want to make sure we are able to get a hold to the
  2232. // real context instance.
  2233. contextVm = parent;
  2234. // @ts-ignore
  2235. parent = parent._original;
  2236. }
  2237. const isCompiled = isTrue(options._compiled);
  2238. const needNormalization = !isCompiled;
  2239. this.data = data;
  2240. this.props = props;
  2241. this.children = children;
  2242. this.parent = parent;
  2243. this.listeners = data.on || emptyObject;
  2244. this.injections = resolveInject(options.inject, parent);
  2245. this.slots = () => {
  2246. if (!this.$slots) {
  2247. normalizeScopedSlots(parent, data.scopedSlots, (this.$slots = resolveSlots(children, parent)));
  2248. }
  2249. return this.$slots;
  2250. };
  2251. Object.defineProperty(this, 'scopedSlots', {
  2252. enumerable: true,
  2253. get() {
  2254. return normalizeScopedSlots(parent, data.scopedSlots, this.slots());
  2255. }
  2256. });
  2257. // support for compiled functional template
  2258. if (isCompiled) {
  2259. // exposing $options for renderStatic()
  2260. this.$options = options;
  2261. // pre-resolve slots for renderSlot()
  2262. this.$slots = this.slots();
  2263. this.$scopedSlots = normalizeScopedSlots(parent, data.scopedSlots, this.$slots);
  2264. }
  2265. if (options._scopeId) {
  2266. this._c = (a, b, c, d) => {
  2267. const vnode = createElement(contextVm, a, b, c, d, needNormalization);
  2268. if (vnode && !isArray(vnode)) {
  2269. vnode.fnScopeId = options._scopeId;
  2270. vnode.fnContext = parent;
  2271. }
  2272. return vnode;
  2273. };
  2274. }
  2275. else {
  2276. this._c = (a, b, c, d) => createElement(contextVm, a, b, c, d, needNormalization);
  2277. }
  2278. }
  2279. installRenderHelpers(FunctionalRenderContext.prototype);
  2280. function createFunctionalComponent(Ctor, propsData, data, contextVm, children) {
  2281. const options = Ctor.options;
  2282. const props = {};
  2283. const propOptions = options.props;
  2284. if (isDef(propOptions)) {
  2285. for (const key in propOptions) {
  2286. props[key] = validateProp(key, propOptions, propsData || emptyObject);
  2287. }
  2288. }
  2289. else {
  2290. if (isDef(data.attrs))
  2291. mergeProps(props, data.attrs);
  2292. if (isDef(data.props))
  2293. mergeProps(props, data.props);
  2294. }
  2295. const renderContext = new FunctionalRenderContext(data, props, children, contextVm, Ctor);
  2296. const vnode = options.render.call(null, renderContext._c, renderContext);
  2297. if (vnode instanceof VNode) {
  2298. return cloneAndMarkFunctionalResult(vnode, data, renderContext.parent, options, renderContext);
  2299. }
  2300. else if (isArray(vnode)) {
  2301. const vnodes = normalizeChildren(vnode) || [];
  2302. const res = new Array(vnodes.length);
  2303. for (let i = 0; i < vnodes.length; i++) {
  2304. res[i] = cloneAndMarkFunctionalResult(vnodes[i], data, renderContext.parent, options, renderContext);
  2305. }
  2306. return res;
  2307. }
  2308. }
  2309. function cloneAndMarkFunctionalResult(vnode, data, contextVm, options, renderContext) {
  2310. // #7817 clone node before setting fnContext, otherwise if the node is reused
  2311. // (e.g. it was from a cached normal slot) the fnContext causes named slots
  2312. // that should not be matched to match.
  2313. const clone = cloneVNode(vnode);
  2314. clone.fnContext = contextVm;
  2315. clone.fnOptions = options;
  2316. {
  2317. (clone.devtoolsMeta = clone.devtoolsMeta || {}).renderContext =
  2318. renderContext;
  2319. }
  2320. if (data.slot) {
  2321. (clone.data || (clone.data = {})).slot = data.slot;
  2322. }
  2323. return clone;
  2324. }
  2325. function mergeProps(to, from) {
  2326. for (const key in from) {
  2327. to[camelize(key)] = from[key];
  2328. }
  2329. }
  2330. function getComponentName(options) {
  2331. return options.name || options.__name || options._componentTag;
  2332. }
  2333. // inline hooks to be invoked on component VNodes during patch
  2334. const componentVNodeHooks = {
  2335. init(vnode, hydrating) {
  2336. if (vnode.componentInstance &&
  2337. !vnode.componentInstance._isDestroyed &&
  2338. vnode.data.keepAlive) {
  2339. // kept-alive components, treat as a patch
  2340. const mountedNode = vnode; // work around flow
  2341. componentVNodeHooks.prepatch(mountedNode, mountedNode);
  2342. }
  2343. else {
  2344. const child = (vnode.componentInstance = createComponentInstanceForVnode(vnode, activeInstance));
  2345. child.$mount(hydrating ? vnode.elm : undefined, hydrating);
  2346. }
  2347. },
  2348. prepatch(oldVnode, vnode) {
  2349. const options = vnode.componentOptions;
  2350. const child = (vnode.componentInstance = oldVnode.componentInstance);
  2351. updateChildComponent(child, options.propsData, // updated props
  2352. options.listeners, // updated listeners
  2353. vnode, // new parent vnode
  2354. options.children // new children
  2355. );
  2356. },
  2357. insert(vnode) {
  2358. const { context, componentInstance } = vnode;
  2359. if (!componentInstance._isMounted) {
  2360. componentInstance._isMounted = true;
  2361. callHook(componentInstance, 'mounted');
  2362. }
  2363. if (vnode.data.keepAlive) {
  2364. if (context._isMounted) {
  2365. // vue-router#1212
  2366. // During updates, a kept-alive component's child components may
  2367. // change, so directly walking the tree here may call activated hooks
  2368. // on incorrect children. Instead we push them into a queue which will
  2369. // be processed after the whole patch process ended.
  2370. queueActivatedComponent(componentInstance);
  2371. }
  2372. else {
  2373. activateChildComponent(componentInstance, true /* direct */);
  2374. }
  2375. }
  2376. },
  2377. destroy(vnode) {
  2378. const { componentInstance } = vnode;
  2379. if (!componentInstance._isDestroyed) {
  2380. if (!vnode.data.keepAlive) {
  2381. componentInstance.$destroy();
  2382. }
  2383. else {
  2384. deactivateChildComponent(componentInstance, true /* direct */);
  2385. }
  2386. }
  2387. }
  2388. };
  2389. const hooksToMerge = Object.keys(componentVNodeHooks);
  2390. function createComponent(Ctor, data, context, children, tag) {
  2391. if (isUndef(Ctor)) {
  2392. return;
  2393. }
  2394. const baseCtor = context.$options._base;
  2395. // plain options object: turn it into a constructor
  2396. if (isObject(Ctor)) {
  2397. Ctor = baseCtor.extend(Ctor);
  2398. }
  2399. // if at this stage it's not a constructor or an async component factory,
  2400. // reject.
  2401. if (typeof Ctor !== 'function') {
  2402. {
  2403. warn$2(`Invalid Component definition: ${String(Ctor)}`, context);
  2404. }
  2405. return;
  2406. }
  2407. // async component
  2408. let asyncFactory;
  2409. // @ts-expect-error
  2410. if (isUndef(Ctor.cid)) {
  2411. asyncFactory = Ctor;
  2412. Ctor = resolveAsyncComponent(asyncFactory);
  2413. if (Ctor === undefined) {
  2414. // return a placeholder node for async component, which is rendered
  2415. // as a comment node but preserves all the raw information for the node.
  2416. // the information will be used for async server-rendering and hydration.
  2417. return createAsyncPlaceholder(asyncFactory, data, context, children, tag);
  2418. }
  2419. }
  2420. data = data || {};
  2421. // resolve constructor options in case global mixins are applied after
  2422. // component constructor creation
  2423. resolveConstructorOptions(Ctor);
  2424. // transform component v-model data into props & events
  2425. if (isDef(data.model)) {
  2426. // @ts-expect-error
  2427. transformModel(Ctor.options, data);
  2428. }
  2429. // extract props
  2430. // @ts-expect-error
  2431. const propsData = extractPropsFromVNodeData(data, Ctor, tag);
  2432. // functional component
  2433. // @ts-expect-error
  2434. if (isTrue(Ctor.options.functional)) {
  2435. return createFunctionalComponent(Ctor, propsData, data, context, children);
  2436. }
  2437. // extract listeners, since these needs to be treated as
  2438. // child component listeners instead of DOM listeners
  2439. const listeners = data.on;
  2440. // replace with listeners with .native modifier
  2441. // so it gets processed during parent component patch.
  2442. data.on = data.nativeOn;
  2443. // @ts-expect-error
  2444. if (isTrue(Ctor.options.abstract)) {
  2445. // abstract components do not keep anything
  2446. // other than props & listeners & slot
  2447. // work around flow
  2448. const slot = data.slot;
  2449. data = {};
  2450. if (slot) {
  2451. data.slot = slot;
  2452. }
  2453. }
  2454. // install component management hooks onto the placeholder node
  2455. installComponentHooks(data);
  2456. // return a placeholder vnode
  2457. // @ts-expect-error
  2458. const name = getComponentName(Ctor.options) || tag;
  2459. const vnode = new VNode(
  2460. // @ts-expect-error
  2461. `vue-component-${Ctor.cid}${name ? `-${name}` : ''}`, data, undefined, undefined, undefined, context,
  2462. // @ts-expect-error
  2463. { Ctor, propsData, listeners, tag, children }, asyncFactory);
  2464. return vnode;
  2465. }
  2466. function createComponentInstanceForVnode(
  2467. // we know it's MountedComponentVNode but flow doesn't
  2468. vnode,
  2469. // activeInstance in lifecycle state
  2470. parent) {
  2471. const options = {
  2472. _isComponent: true,
  2473. _parentVnode: vnode,
  2474. parent
  2475. };
  2476. // check inline-template render functions
  2477. const inlineTemplate = vnode.data.inlineTemplate;
  2478. if (isDef(inlineTemplate)) {
  2479. options.render = inlineTemplate.render;
  2480. options.staticRenderFns = inlineTemplate.staticRenderFns;
  2481. }
  2482. return new vnode.componentOptions.Ctor(options);
  2483. }
  2484. function installComponentHooks(data) {
  2485. const hooks = data.hook || (data.hook = {});
  2486. for (let i = 0; i < hooksToMerge.length; i++) {
  2487. const key = hooksToMerge[i];
  2488. const existing = hooks[key];
  2489. const toMerge = componentVNodeHooks[key];
  2490. // @ts-expect-error
  2491. if (existing !== toMerge && !(existing && existing._merged)) {
  2492. hooks[key] = existing ? mergeHook(toMerge, existing) : toMerge;
  2493. }
  2494. }
  2495. }
  2496. function mergeHook(f1, f2) {
  2497. const merged = (a, b) => {
  2498. // flow complains about extra args which is why we use any
  2499. f1(a, b);
  2500. f2(a, b);
  2501. };
  2502. merged._merged = true;
  2503. return merged;
  2504. }
  2505. // transform component v-model info (value and callback) into
  2506. // prop and event handler respectively.
  2507. function transformModel(options, data) {
  2508. const prop = (options.model && options.model.prop) || 'value';
  2509. const event = (options.model && options.model.event) || 'input';
  2510. (data.attrs || (data.attrs = {}))[prop] = data.model.value;
  2511. const on = data.on || (data.on = {});
  2512. const existing = on[event];
  2513. const callback = data.model.callback;
  2514. if (isDef(existing)) {
  2515. if (isArray(existing)
  2516. ? existing.indexOf(callback) === -1
  2517. : existing !== callback) {
  2518. on[event] = [callback].concat(existing);
  2519. }
  2520. }
  2521. else {
  2522. on[event] = callback;
  2523. }
  2524. }
  2525. let warn$2 = noop$1;
  2526. let tip = noop$1;
  2527. let generateComponentTrace; // work around flow check
  2528. let formatComponentName;
  2529. {
  2530. const hasConsole = typeof console !== 'undefined';
  2531. const classifyRE = /(?:^|[-_])(\w)/g;
  2532. const classify = str => str.replace(classifyRE, c => c.toUpperCase()).replace(/[-_]/g, '');
  2533. warn$2 = (msg, vm = currentInstance) => {
  2534. const trace = vm ? generateComponentTrace(vm) : '';
  2535. if (hasConsole && !config.silent) {
  2536. console.error(`[Vue warn]: ${msg}${trace}`);
  2537. }
  2538. };
  2539. tip = (msg, vm) => {
  2540. if (hasConsole && !config.silent) {
  2541. console.warn(`[Vue tip]: ${msg}` + (vm ? generateComponentTrace(vm) : ''));
  2542. }
  2543. };
  2544. formatComponentName = (vm, includeFile) => {
  2545. if (vm.$root === vm) {
  2546. return '<Root>';
  2547. }
  2548. const options = isFunction(vm) && vm.cid != null
  2549. ? vm.options
  2550. : vm._isVue
  2551. ? vm.$options || vm.constructor.options
  2552. : vm;
  2553. let name = getComponentName(options);
  2554. const file = options.__file;
  2555. if (!name && file) {
  2556. const match = file.match(/([^/\\]+)\.vue$/);
  2557. name = match && match[1];
  2558. }
  2559. return ((name ? `<${classify(name)}>` : `<Anonymous>`) +
  2560. (file && includeFile !== false ? ` at ${file}` : ''));
  2561. };
  2562. const repeat = (str, n) => {
  2563. let res = '';
  2564. while (n) {
  2565. if (n % 2 === 1)
  2566. res += str;
  2567. if (n > 1)
  2568. str += str;
  2569. n >>= 1;
  2570. }
  2571. return res;
  2572. };
  2573. generateComponentTrace = (vm) => {
  2574. if (vm._isVue && vm.$parent) {
  2575. const tree = [];
  2576. let currentRecursiveSequence = 0;
  2577. while (vm) {
  2578. if (tree.length > 0) {
  2579. const last = tree[tree.length - 1];
  2580. if (last.constructor === vm.constructor) {
  2581. currentRecursiveSequence++;
  2582. vm = vm.$parent;
  2583. continue;
  2584. }
  2585. else if (currentRecursiveSequence > 0) {
  2586. tree[tree.length - 1] = [last, currentRecursiveSequence];
  2587. currentRecursiveSequence = 0;
  2588. }
  2589. }
  2590. tree.push(vm);
  2591. vm = vm.$parent;
  2592. }
  2593. return ('\n\nfound in\n\n' +
  2594. tree
  2595. .map((vm, i) => `${i === 0 ? '---> ' : repeat(' ', 5 + i * 2)}${isArray(vm)
  2596. ? `${formatComponentName(vm[0])}... (${vm[1]} recursive calls)`
  2597. : formatComponentName(vm)}`)
  2598. .join('\n'));
  2599. }
  2600. else {
  2601. return `\n\n(found in ${formatComponentName(vm)})`;
  2602. }
  2603. };
  2604. }
  2605. /**
  2606. * Option overwriting strategies are functions that handle
  2607. * how to merge a parent option value and a child option
  2608. * value into the final value.
  2609. */
  2610. const strats = config.optionMergeStrategies;
  2611. /**
  2612. * Options with restrictions
  2613. */
  2614. {
  2615. strats.el = strats.propsData = function (parent, child, vm, key) {
  2616. if (!vm) {
  2617. warn$2(`option "${key}" can only be used during instance ` +
  2618. 'creation with the `new` keyword.');
  2619. }
  2620. return defaultStrat(parent, child);
  2621. };
  2622. }
  2623. /**
  2624. * Helper that recursively merges two data objects together.
  2625. */
  2626. function mergeData(to, from) {
  2627. if (!from)
  2628. return to;
  2629. let key, toVal, fromVal;
  2630. const keys = hasSymbol
  2631. ? Reflect.ownKeys(from)
  2632. : Object.keys(from);
  2633. for (let i = 0; i < keys.length; i++) {
  2634. key = keys[i];
  2635. // in case the object is already observed...
  2636. if (key === '__ob__')
  2637. continue;
  2638. toVal = to[key];
  2639. fromVal = from[key];
  2640. if (!hasOwn(to, key)) {
  2641. set(to, key, fromVal);
  2642. }
  2643. else if (toVal !== fromVal &&
  2644. isPlainObject(toVal) &&
  2645. isPlainObject(fromVal)) {
  2646. mergeData(toVal, fromVal);
  2647. }
  2648. }
  2649. return to;
  2650. }
  2651. /**
  2652. * Data
  2653. */
  2654. function mergeDataOrFn(parentVal, childVal, vm) {
  2655. if (!vm) {
  2656. // in a Vue.extend merge, both should be functions
  2657. if (!childVal) {
  2658. return parentVal;
  2659. }
  2660. if (!parentVal) {
  2661. return childVal;
  2662. }
  2663. // when parentVal & childVal are both present,
  2664. // we need to return a function that returns the
  2665. // merged result of both functions... no need to
  2666. // check if parentVal is a function here because
  2667. // it has to be a function to pass previous merges.
  2668. return function mergedDataFn() {
  2669. return mergeData(isFunction(childVal) ? childVal.call(this, this) : childVal, isFunction(parentVal) ? parentVal.call(this, this) : parentVal);
  2670. };
  2671. }
  2672. else {
  2673. return function mergedInstanceDataFn() {
  2674. // instance merge
  2675. const instanceData = isFunction(childVal)
  2676. ? childVal.call(vm, vm)
  2677. : childVal;
  2678. const defaultData = isFunction(parentVal)
  2679. ? parentVal.call(vm, vm)
  2680. : parentVal;
  2681. if (instanceData) {
  2682. return mergeData(instanceData, defaultData);
  2683. }
  2684. else {
  2685. return defaultData;
  2686. }
  2687. };
  2688. }
  2689. }
  2690. strats.data = function (parentVal, childVal, vm) {
  2691. if (!vm) {
  2692. if (childVal && typeof childVal !== 'function') {
  2693. warn$2('The "data" option should be a function ' +
  2694. 'that returns a per-instance value in component ' +
  2695. 'definitions.', vm);
  2696. return parentVal;
  2697. }
  2698. return mergeDataOrFn(parentVal, childVal);
  2699. }
  2700. return mergeDataOrFn(parentVal, childVal, vm);
  2701. };
  2702. /**
  2703. * Hooks and props are merged as arrays.
  2704. */
  2705. function mergeLifecycleHook(parentVal, childVal) {
  2706. const res = childVal
  2707. ? parentVal
  2708. ? parentVal.concat(childVal)
  2709. : isArray(childVal)
  2710. ? childVal
  2711. : [childVal]
  2712. : parentVal;
  2713. return res ? dedupeHooks(res) : res;
  2714. }
  2715. function dedupeHooks(hooks) {
  2716. const res = [];
  2717. for (let i = 0; i < hooks.length; i++) {
  2718. if (res.indexOf(hooks[i]) === -1) {
  2719. res.push(hooks[i]);
  2720. }
  2721. }
  2722. return res;
  2723. }
  2724. LIFECYCLE_HOOKS.forEach(hook => {
  2725. strats[hook] = mergeLifecycleHook;
  2726. });
  2727. /**
  2728. * Assets
  2729. *
  2730. * When a vm is present (instance creation), we need to do
  2731. * a three-way merge between constructor options, instance
  2732. * options and parent options.
  2733. */
  2734. function mergeAssets(parentVal, childVal, vm, key) {
  2735. const res = Object.create(parentVal || null);
  2736. if (childVal) {
  2737. assertObjectType(key, childVal, vm);
  2738. return extend(res, childVal);
  2739. }
  2740. else {
  2741. return res;
  2742. }
  2743. }
  2744. ASSET_TYPES.forEach(function (type) {
  2745. strats[type + 's'] = mergeAssets;
  2746. });
  2747. /**
  2748. * Watchers.
  2749. *
  2750. * Watchers hashes should not overwrite one
  2751. * another, so we merge them as arrays.
  2752. */
  2753. strats.watch = function (parentVal, childVal, vm, key) {
  2754. // work around Firefox's Object.prototype.watch...
  2755. //@ts-expect-error work around
  2756. if (parentVal === nativeWatch)
  2757. parentVal = undefined;
  2758. //@ts-expect-error work around
  2759. if (childVal === nativeWatch)
  2760. childVal = undefined;
  2761. /* istanbul ignore if */
  2762. if (!childVal)
  2763. return Object.create(parentVal || null);
  2764. {
  2765. assertObjectType(key, childVal, vm);
  2766. }
  2767. if (!parentVal)
  2768. return childVal;
  2769. const ret = {};
  2770. extend(ret, parentVal);
  2771. for (const key in childVal) {
  2772. let parent = ret[key];
  2773. const child = childVal[key];
  2774. if (parent && !isArray(parent)) {
  2775. parent = [parent];
  2776. }
  2777. ret[key] = parent ? parent.concat(child) : isArray(child) ? child : [child];
  2778. }
  2779. return ret;
  2780. };
  2781. /**
  2782. * Other object hashes.
  2783. */
  2784. strats.props =
  2785. strats.methods =
  2786. strats.inject =
  2787. strats.computed =
  2788. function (parentVal, childVal, vm, key) {
  2789. if (childVal && true) {
  2790. assertObjectType(key, childVal, vm);
  2791. }
  2792. if (!parentVal)
  2793. return childVal;
  2794. const ret = Object.create(null);
  2795. extend(ret, parentVal);
  2796. if (childVal)
  2797. extend(ret, childVal);
  2798. return ret;
  2799. };
  2800. strats.provide = mergeDataOrFn;
  2801. /**
  2802. * Default strategy.
  2803. */
  2804. const defaultStrat = function (parentVal, childVal) {
  2805. return childVal === undefined ? parentVal : childVal;
  2806. };
  2807. /**
  2808. * Validate component names
  2809. */
  2810. function checkComponents(options) {
  2811. for (const key in options.components) {
  2812. validateComponentName(key);
  2813. }
  2814. }
  2815. function validateComponentName(name) {
  2816. if (!new RegExp(`^[a-zA-Z][\\-\\.0-9_${unicodeRegExp.source}]*$`).test(name)) {
  2817. warn$2('Invalid component name: "' +
  2818. name +
  2819. '". Component names ' +
  2820. 'should conform to valid custom element name in html5 specification.');
  2821. }
  2822. if (isBuiltInTag(name) || config.isReservedTag(name)) {
  2823. warn$2('Do not use built-in or reserved HTML elements as component ' +
  2824. 'id: ' +
  2825. name);
  2826. }
  2827. }
  2828. /**
  2829. * Ensure all props option syntax are normalized into the
  2830. * Object-based format.
  2831. */
  2832. function normalizeProps(options, vm) {
  2833. const props = options.props;
  2834. if (!props)
  2835. return;
  2836. const res = {};
  2837. let i, val, name;
  2838. if (isArray(props)) {
  2839. i = props.length;
  2840. while (i--) {
  2841. val = props[i];
  2842. if (typeof val === 'string') {
  2843. name = camelize(val);
  2844. res[name] = { type: null };
  2845. }
  2846. else {
  2847. warn$2('props must be strings when using array syntax.');
  2848. }
  2849. }
  2850. }
  2851. else if (isPlainObject(props)) {
  2852. for (const key in props) {
  2853. val = props[key];
  2854. name = camelize(key);
  2855. res[name] = isPlainObject(val) ? val : { type: val };
  2856. }
  2857. }
  2858. else {
  2859. warn$2(`Invalid value for option "props": expected an Array or an Object, ` +
  2860. `but got ${toRawType(props)}.`, vm);
  2861. }
  2862. options.props = res;
  2863. }
  2864. /**
  2865. * Normalize all injections into Object-based format
  2866. */
  2867. function normalizeInject(options, vm) {
  2868. const inject = options.inject;
  2869. if (!inject)
  2870. return;
  2871. const normalized = (options.inject = {});
  2872. if (isArray(inject)) {
  2873. for (let i = 0; i < inject.length; i++) {
  2874. normalized[inject[i]] = { from: inject[i] };
  2875. }
  2876. }
  2877. else if (isPlainObject(inject)) {
  2878. for (const key in inject) {
  2879. const val = inject[key];
  2880. normalized[key] = isPlainObject(val)
  2881. ? extend({ from: key }, val)
  2882. : { from: val };
  2883. }
  2884. }
  2885. else {
  2886. warn$2(`Invalid value for option "inject": expected an Array or an Object, ` +
  2887. `but got ${toRawType(inject)}.`, vm);
  2888. }
  2889. }
  2890. /**
  2891. * Normalize raw function directives into object format.
  2892. */
  2893. function normalizeDirectives(options) {
  2894. const dirs = options.directives;
  2895. if (dirs) {
  2896. for (const key in dirs) {
  2897. const def = dirs[key];
  2898. if (isFunction(def)) {
  2899. dirs[key] = { bind: def, update: def };
  2900. }
  2901. }
  2902. }
  2903. }
  2904. function assertObjectType(name, value, vm) {
  2905. if (!isPlainObject(value)) {
  2906. warn$2(`Invalid value for option "${name}": expected an Object, ` +
  2907. `but got ${toRawType(value)}.`, vm);
  2908. }
  2909. }
  2910. /**
  2911. * Merge two option objects into a new one.
  2912. * Core utility used in both instantiation and inheritance.
  2913. */
  2914. function mergeOptions(parent, child, vm) {
  2915. {
  2916. checkComponents(child);
  2917. }
  2918. if (isFunction(child)) {
  2919. // @ts-expect-error
  2920. child = child.options;
  2921. }
  2922. normalizeProps(child, vm);
  2923. normalizeInject(child, vm);
  2924. normalizeDirectives(child);
  2925. // Apply extends and mixins on the child options,
  2926. // but only if it is a raw options object that isn't
  2927. // the result of another mergeOptions call.
  2928. // Only merged options has the _base property.
  2929. if (!child._base) {
  2930. if (child.extends) {
  2931. parent = mergeOptions(parent, child.extends, vm);
  2932. }
  2933. if (child.mixins) {
  2934. for (let i = 0, l = child.mixins.length; i < l; i++) {
  2935. parent = mergeOptions(parent, child.mixins[i], vm);
  2936. }
  2937. }
  2938. }
  2939. const options = {};
  2940. let key;
  2941. for (key in parent) {
  2942. mergeField(key);
  2943. }
  2944. for (key in child) {
  2945. if (!hasOwn(parent, key)) {
  2946. mergeField(key);
  2947. }
  2948. }
  2949. function mergeField(key) {
  2950. const strat = strats[key] || defaultStrat;
  2951. options[key] = strat(parent[key], child[key], vm, key);
  2952. }
  2953. return options;
  2954. }
  2955. /**
  2956. * Resolve an asset.
  2957. * This function is used because child instances need access
  2958. * to assets defined in its ancestor chain.
  2959. */
  2960. function resolveAsset(options, type, id, warnMissing) {
  2961. /* istanbul ignore if */
  2962. if (typeof id !== 'string') {
  2963. return;
  2964. }
  2965. const assets = options[type];
  2966. // check local registration variations first
  2967. if (hasOwn(assets, id))
  2968. return assets[id];
  2969. const camelizedId = camelize(id);
  2970. if (hasOwn(assets, camelizedId))
  2971. return assets[camelizedId];
  2972. const PascalCaseId = capitalize(camelizedId);
  2973. if (hasOwn(assets, PascalCaseId))
  2974. return assets[PascalCaseId];
  2975. // fallback to prototype chain
  2976. const res = assets[id] || assets[camelizedId] || assets[PascalCaseId];
  2977. if (warnMissing && !res) {
  2978. warn$2('Failed to resolve ' + type.slice(0, -1) + ': ' + id);
  2979. }
  2980. return res;
  2981. }
  2982. function validateProp(key, propOptions, propsData, vm) {
  2983. const prop = propOptions[key];
  2984. const absent = !hasOwn(propsData, key);
  2985. let value = propsData[key];
  2986. // boolean casting
  2987. const booleanIndex = getTypeIndex(Boolean, prop.type);
  2988. if (booleanIndex > -1) {
  2989. if (absent && !hasOwn(prop, 'default')) {
  2990. value = false;
  2991. }
  2992. else if (value === '' || value === hyphenate(key)) {
  2993. // only cast empty string / same name to boolean if
  2994. // boolean has higher priority
  2995. const stringIndex = getTypeIndex(String, prop.type);
  2996. if (stringIndex < 0 || booleanIndex < stringIndex) {
  2997. value = true;
  2998. }
  2999. }
  3000. }
  3001. // check default value
  3002. if (value === undefined) {
  3003. value = getPropDefaultValue(vm, prop, key);
  3004. // since the default value is a fresh copy,
  3005. // make sure to observe it.
  3006. const prevShouldObserve = shouldObserve;
  3007. toggleObserving(true);
  3008. observe(value);
  3009. toggleObserving(prevShouldObserve);
  3010. }
  3011. {
  3012. assertProp(prop, key, value, vm, absent);
  3013. }
  3014. return value;
  3015. }
  3016. /**
  3017. * Get the default value of a prop.
  3018. */
  3019. function getPropDefaultValue(vm, prop, key) {
  3020. // no default, return undefined
  3021. if (!hasOwn(prop, 'default')) {
  3022. return undefined;
  3023. }
  3024. const def = prop.default;
  3025. // warn against non-factory defaults for Object & Array
  3026. if (isObject(def)) {
  3027. warn$2('Invalid default value for prop "' +
  3028. key +
  3029. '": ' +
  3030. 'Props with type Object/Array must use a factory function ' +
  3031. 'to return the default value.', vm);
  3032. }
  3033. // the raw prop value was also undefined from previous render,
  3034. // return previous default value to avoid unnecessary watcher trigger
  3035. if (vm &&
  3036. vm.$options.propsData &&
  3037. vm.$options.propsData[key] === undefined &&
  3038. vm._props[key] !== undefined) {
  3039. return vm._props[key];
  3040. }
  3041. // call factory function for non-Function types
  3042. // a value is Function if its prototype is function even across different execution context
  3043. return isFunction(def) && getType(prop.type) !== 'Function'
  3044. ? def.call(vm)
  3045. : def;
  3046. }
  3047. /**
  3048. * Assert whether a prop is valid.
  3049. */
  3050. function assertProp(prop, name, value, vm, absent) {
  3051. if (prop.required && absent) {
  3052. warn$2('Missing required prop: "' + name + '"', vm);
  3053. return;
  3054. }
  3055. if (value == null && !prop.required) {
  3056. return;
  3057. }
  3058. let type = prop.type;
  3059. let valid = !type || type === true;
  3060. const expectedTypes = [];
  3061. if (type) {
  3062. if (!isArray(type)) {
  3063. type = [type];
  3064. }
  3065. for (let i = 0; i < type.length && !valid; i++) {
  3066. const assertedType = assertType(value, type[i], vm);
  3067. expectedTypes.push(assertedType.expectedType || '');
  3068. valid = assertedType.valid;
  3069. }
  3070. }
  3071. const haveExpectedTypes = expectedTypes.some(t => t);
  3072. if (!valid && haveExpectedTypes) {
  3073. warn$2(getInvalidTypeMessage(name, value, expectedTypes), vm);
  3074. return;
  3075. }
  3076. const validator = prop.validator;
  3077. if (validator) {
  3078. if (!validator(value)) {
  3079. warn$2('Invalid prop: custom validator check failed for prop "' + name + '".', vm);
  3080. }
  3081. }
  3082. }
  3083. const simpleCheckRE = /^(String|Number|Boolean|Function|Symbol|BigInt)$/;
  3084. function assertType(value, type, vm) {
  3085. let valid;
  3086. const expectedType = getType(type);
  3087. if (simpleCheckRE.test(expectedType)) {
  3088. const t = typeof value;
  3089. valid = t === expectedType.toLowerCase();
  3090. // for primitive wrapper objects
  3091. if (!valid && t === 'object') {
  3092. valid = value instanceof type;
  3093. }
  3094. }
  3095. else if (expectedType === 'Object') {
  3096. valid = isPlainObject(value);
  3097. }
  3098. else if (expectedType === 'Array') {
  3099. valid = isArray(value);
  3100. }
  3101. else {
  3102. try {
  3103. valid = value instanceof type;
  3104. }
  3105. catch (e) {
  3106. warn$2('Invalid prop type: "' + String(type) + '" is not a constructor', vm);
  3107. valid = false;
  3108. }
  3109. }
  3110. return {
  3111. valid,
  3112. expectedType
  3113. };
  3114. }
  3115. const functionTypeCheckRE = /^\s*function (\w+)/;
  3116. /**
  3117. * Use function string name to check built-in types,
  3118. * because a simple equality check will fail when running
  3119. * across different vms / iframes.
  3120. */
  3121. function getType(fn) {
  3122. const match = fn && fn.toString().match(functionTypeCheckRE);
  3123. return match ? match[1] : '';
  3124. }
  3125. function isSameType(a, b) {
  3126. return getType(a) === getType(b);
  3127. }
  3128. function getTypeIndex(type, expectedTypes) {
  3129. if (!isArray(expectedTypes)) {
  3130. return isSameType(expectedTypes, type) ? 0 : -1;
  3131. }
  3132. for (let i = 0, len = expectedTypes.length; i < len; i++) {
  3133. if (isSameType(expectedTypes[i], type)) {
  3134. return i;
  3135. }
  3136. }
  3137. return -1;
  3138. }
  3139. function getInvalidTypeMessage(name, value, expectedTypes) {
  3140. let message = `Invalid prop: type check failed for prop "${name}".` +
  3141. ` Expected ${expectedTypes.map(capitalize).join(', ')}`;
  3142. const expectedType = expectedTypes[0];
  3143. const receivedType = toRawType(value);
  3144. // check if we need to specify expected value
  3145. if (expectedTypes.length === 1 &&
  3146. isExplicable(expectedType) &&
  3147. isExplicable(typeof value) &&
  3148. !isBoolean(expectedType, receivedType)) {
  3149. message += ` with value ${styleValue(value, expectedType)}`;
  3150. }
  3151. message += `, got ${receivedType} `;
  3152. // check if we need to specify received value
  3153. if (isExplicable(receivedType)) {
  3154. message += `with value ${styleValue(value, receivedType)}.`;
  3155. }
  3156. return message;
  3157. }
  3158. function styleValue(value, type) {
  3159. if (type === 'String') {
  3160. return `"${value}"`;
  3161. }
  3162. else if (type === 'Number') {
  3163. return `${Number(value)}`;
  3164. }
  3165. else {
  3166. return `${value}`;
  3167. }
  3168. }
  3169. const EXPLICABLE_TYPES = ['string', 'number', 'boolean'];
  3170. function isExplicable(value) {
  3171. return EXPLICABLE_TYPES.some(elem => value.toLowerCase() === elem);
  3172. }
  3173. function isBoolean(...args) {
  3174. return args.some(elem => elem.toLowerCase() === 'boolean');
  3175. }
  3176. function genClassForVnode(vnode) {
  3177. let data = vnode.data;
  3178. let parentNode = vnode;
  3179. let childNode = vnode;
  3180. while (isDef(childNode.componentInstance)) {
  3181. childNode = childNode.componentInstance._vnode;
  3182. if (childNode && childNode.data) {
  3183. data = mergeClassData(childNode.data, data);
  3184. }
  3185. }
  3186. // @ts-expect-error parentNode.parent not VNodeWithData
  3187. while (isDef((parentNode = parentNode.parent))) {
  3188. if (parentNode && parentNode.data) {
  3189. data = mergeClassData(data, parentNode.data);
  3190. }
  3191. }
  3192. return renderClass$1(data.staticClass, data.class);
  3193. }
  3194. function mergeClassData(child, parent) {
  3195. return {
  3196. staticClass: concat(child.staticClass, parent.staticClass),
  3197. class: isDef(child.class) ? [child.class, parent.class] : parent.class
  3198. };
  3199. }
  3200. function renderClass$1(staticClass, dynamicClass) {
  3201. if (isDef(staticClass) || isDef(dynamicClass)) {
  3202. return concat(staticClass, stringifyClass(dynamicClass));
  3203. }
  3204. /* istanbul ignore next */
  3205. return '';
  3206. }
  3207. function concat(a, b) {
  3208. return a ? (b ? a + ' ' + b : a) : b || '';
  3209. }
  3210. function stringifyClass(value) {
  3211. if (Array.isArray(value)) {
  3212. return stringifyArray(value);
  3213. }
  3214. if (isObject(value)) {
  3215. return stringifyObject(value);
  3216. }
  3217. if (typeof value === 'string') {
  3218. return value;
  3219. }
  3220. /* istanbul ignore next */
  3221. return '';
  3222. }
  3223. function stringifyArray(value) {
  3224. let res = '';
  3225. let stringified;
  3226. for (let i = 0, l = value.length; i < l; i++) {
  3227. if (isDef((stringified = stringifyClass(value[i]))) && stringified !== '') {
  3228. if (res)
  3229. res += ' ';
  3230. res += stringified;
  3231. }
  3232. }
  3233. return res;
  3234. }
  3235. function stringifyObject(value) {
  3236. let res = '';
  3237. for (const key in value) {
  3238. if (value[key]) {
  3239. if (res)
  3240. res += ' ';
  3241. res += key;
  3242. }
  3243. }
  3244. return res;
  3245. }
  3246. const isHTMLTag = makeMap('html,body,base,head,link,meta,style,title,' +
  3247. 'address,article,aside,footer,header,h1,h2,h3,h4,h5,h6,hgroup,nav,section,' +
  3248. 'div,dd,dl,dt,figcaption,figure,picture,hr,img,li,main,ol,p,pre,ul,' +
  3249. 'a,b,abbr,bdi,bdo,br,cite,code,data,dfn,em,i,kbd,mark,q,rp,rt,rtc,ruby,' +
  3250. 's,samp,small,span,strong,sub,sup,time,u,var,wbr,area,audio,map,track,video,' +
  3251. 'embed,object,param,source,canvas,script,noscript,del,ins,' +
  3252. 'caption,col,colgroup,table,thead,tbody,td,th,tr,' +
  3253. 'button,datalist,fieldset,form,input,label,legend,meter,optgroup,option,' +
  3254. 'output,progress,select,textarea,' +
  3255. 'details,dialog,menu,menuitem,summary,' +
  3256. 'content,element,shadow,template,blockquote,iframe,tfoot');
  3257. // this map is intentionally selective, only covering SVG elements that may
  3258. // contain child elements.
  3259. const isSVG = makeMap('svg,animate,circle,clippath,cursor,defs,desc,ellipse,filter,font-face,' +
  3260. 'foreignobject,g,glyph,image,line,marker,mask,missing-glyph,path,pattern,' +
  3261. 'polygon,polyline,rect,switch,symbol,text,textpath,tspan,use,view', true);
  3262. const isPreTag = (tag) => tag === 'pre';
  3263. const isReservedTag = (tag) => {
  3264. return isHTMLTag(tag) || isSVG(tag);
  3265. };
  3266. function getTagNamespace(tag) {
  3267. if (isSVG(tag)) {
  3268. return 'svg';
  3269. }
  3270. // basic support for MathML
  3271. // note it doesn't support other MathML elements being component roots
  3272. if (tag === 'math') {
  3273. return 'math';
  3274. }
  3275. }
  3276. makeMap('text,number,password,search,email,tel,url');
  3277. function renderClass(node) {
  3278. const classList = genClassForVnode(node);
  3279. if (classList !== '') {
  3280. return ` class="${escape(classList)}"`;
  3281. }
  3282. }
  3283. const parseStyleText = cached(function (cssText) {
  3284. const res = {};
  3285. const listDelimiter = /;(?![^(]*\))/g;
  3286. const propertyDelimiter = /:(.+)/;
  3287. cssText.split(listDelimiter).forEach(function (item) {
  3288. if (item) {
  3289. const tmp = item.split(propertyDelimiter);
  3290. tmp.length > 1 && (res[tmp[0].trim()] = tmp[1].trim());
  3291. }
  3292. });
  3293. return res;
  3294. });
  3295. // merge static and dynamic style data on the same vnode
  3296. function normalizeStyleData(data) {
  3297. const style = normalizeStyleBinding(data.style);
  3298. // static style is pre-processed into an object during compilation
  3299. // and is always a fresh object, so it's safe to merge into it
  3300. return data.staticStyle ? extend(data.staticStyle, style) : style;
  3301. }
  3302. // normalize possible array / string values into Object
  3303. function normalizeStyleBinding(bindingStyle) {
  3304. if (Array.isArray(bindingStyle)) {
  3305. return toObject(bindingStyle);
  3306. }
  3307. if (typeof bindingStyle === 'string') {
  3308. return parseStyleText(bindingStyle);
  3309. }
  3310. return bindingStyle;
  3311. }
  3312. /**
  3313. * parent component style should be after child's
  3314. * so that parent component's style could override it
  3315. */
  3316. function getStyle(vnode, checkChild) {
  3317. const res = {};
  3318. let styleData;
  3319. if (checkChild) {
  3320. let childNode = vnode;
  3321. while (childNode.componentInstance) {
  3322. childNode = childNode.componentInstance._vnode;
  3323. if (childNode &&
  3324. childNode.data &&
  3325. (styleData = normalizeStyleData(childNode.data))) {
  3326. extend(res, styleData);
  3327. }
  3328. }
  3329. }
  3330. if ((styleData = normalizeStyleData(vnode.data))) {
  3331. extend(res, styleData);
  3332. }
  3333. let parentNode = vnode;
  3334. // @ts-expect-error parentNode.parent not VNodeWithData
  3335. while ((parentNode = parentNode.parent)) {
  3336. if (parentNode.data && (styleData = normalizeStyleData(parentNode.data))) {
  3337. extend(res, styleData);
  3338. }
  3339. }
  3340. return res;
  3341. }
  3342. function genStyle(style) {
  3343. let styleText = '';
  3344. for (const key in style) {
  3345. const value = style[key];
  3346. const hyphenatedKey = hyphenate(key);
  3347. if (Array.isArray(value)) {
  3348. for (let i = 0, len = value.length; i < len; i++) {
  3349. styleText += normalizeValue(hyphenatedKey, value[i]);
  3350. }
  3351. }
  3352. else {
  3353. styleText += normalizeValue(hyphenatedKey, value);
  3354. }
  3355. }
  3356. return styleText;
  3357. }
  3358. function normalizeValue(key, value) {
  3359. if (typeof value === 'string' ||
  3360. (typeof value === 'number' && noUnitNumericStyleProps[key]) ||
  3361. value === 0) {
  3362. return `${key}:${value};`;
  3363. }
  3364. else {
  3365. // invalid values
  3366. return ``;
  3367. }
  3368. }
  3369. function renderStyle(vnode) {
  3370. const styleText = genStyle(getStyle(vnode, false));
  3371. if (styleText !== '') {
  3372. return ` style=${JSON.stringify(escape(styleText))}`;
  3373. }
  3374. }
  3375. var modules$1 = [renderAttrs$1, renderDOMProps$1, renderClass, renderStyle];
  3376. function show(node, dir) {
  3377. if (!dir.value) {
  3378. const style = node.data.style || (node.data.style = {});
  3379. if (Array.isArray(style)) {
  3380. style.push({ display: 'none' });
  3381. }
  3382. else {
  3383. style.display = 'none';
  3384. }
  3385. }
  3386. }
  3387. // this is only applied for <select v-model> because it is the only edge case
  3388. // that must be done at runtime instead of compile time.
  3389. function model$2(node, dir) {
  3390. if (!node.children)
  3391. return;
  3392. const value = dir.value;
  3393. const isMultiple = node.data.attrs && node.data.attrs.multiple;
  3394. for (let i = 0, l = node.children.length; i < l; i++) {
  3395. const option = node.children[i];
  3396. if (option.tag === 'option') {
  3397. if (isMultiple) {
  3398. const selected = Array.isArray(value) && looseIndexOf(value, getValue(option)) > -1;
  3399. if (selected) {
  3400. setSelected(option);
  3401. }
  3402. }
  3403. else {
  3404. if (looseEqual(value, getValue(option))) {
  3405. setSelected(option);
  3406. return;
  3407. }
  3408. }
  3409. }
  3410. }
  3411. }
  3412. function getValue(option) {
  3413. const data = option.data || {};
  3414. return ((data.attrs && data.attrs.value) ||
  3415. (data.domProps && data.domProps.value) ||
  3416. (option.children && option.children[0] && option.children[0].text));
  3417. }
  3418. function setSelected(option) {
  3419. const data = option.data || (option.data = {});
  3420. const attrs = data.attrs || (data.attrs = {});
  3421. attrs.selected = '';
  3422. }
  3423. var baseDirectives$1 = {
  3424. show,
  3425. model: model$2
  3426. };
  3427. const isUnaryTag = makeMap('area,base,br,col,embed,frame,hr,img,input,isindex,keygen,' +
  3428. 'link,meta,param,source,track,wbr');
  3429. // Elements that you can, intentionally, leave open
  3430. // (and which close themselves)
  3431. const canBeLeftOpenTag = makeMap('colgroup,dd,dt,li,options,p,td,tfoot,th,thead,tr,source');
  3432. // HTML5 tags https://html.spec.whatwg.org/multipage/indices.html#elements-3
  3433. // Phrasing Content https://html.spec.whatwg.org/multipage/dom.html#phrasing-content
  3434. const isNonPhrasingTag = makeMap('address,article,aside,base,blockquote,body,caption,col,colgroup,dd,' +
  3435. 'details,dialog,div,dl,dt,fieldset,figcaption,figure,footer,form,' +
  3436. 'h1,h2,h3,h4,h5,h6,head,header,hgroup,hr,html,legend,li,menuitem,meta,' +
  3437. 'optgroup,option,param,rp,rt,source,style,summary,tbody,td,tfoot,th,thead,' +
  3438. 'title,tr,track');
  3439. const MAX_STACK_DEPTH = 800;
  3440. const noop = _ => _;
  3441. const defer = typeof process !== 'undefined' && process.nextTick
  3442. ? process.nextTick
  3443. : typeof Promise !== 'undefined'
  3444. ? fn => Promise.resolve().then(fn)
  3445. : typeof setTimeout !== 'undefined'
  3446. ? setTimeout
  3447. : noop;
  3448. if (defer === noop) {
  3449. throw new Error('Your JavaScript runtime does not support any asynchronous primitives ' +
  3450. 'that are required by vue-server-renderer. Please use a polyfill for ' +
  3451. 'either Promise or setTimeout.');
  3452. }
  3453. function createWriteFunction(write, onError) {
  3454. let stackDepth = 0;
  3455. const cachedWrite = (text, next) => {
  3456. if (text && cachedWrite.caching) {
  3457. cachedWrite.cacheBuffer[cachedWrite.cacheBuffer.length - 1] += text;
  3458. }
  3459. const waitForNext = write(text, next);
  3460. if (waitForNext !== true) {
  3461. if (stackDepth >= MAX_STACK_DEPTH) {
  3462. defer(() => {
  3463. try {
  3464. next();
  3465. }
  3466. catch (e) {
  3467. onError(e);
  3468. }
  3469. });
  3470. }
  3471. else {
  3472. stackDepth++;
  3473. next();
  3474. stackDepth--;
  3475. }
  3476. }
  3477. };
  3478. cachedWrite.caching = false;
  3479. cachedWrite.cacheBuffer = [];
  3480. cachedWrite.componentBuffer = [];
  3481. return cachedWrite;
  3482. }
  3483. /**
  3484. * Original RenderStream implementation by Sasha Aickin (@aickin)
  3485. * Licensed under the Apache License, Version 2.0
  3486. * http://www.apache.org/licenses/LICENSE-2.0
  3487. *
  3488. * Modified by Evan You (@yyx990803)
  3489. */
  3490. class RenderStream extends stream.Readable {
  3491. constructor(render) {
  3492. super();
  3493. this.buffer = '';
  3494. //@ts-expect-error
  3495. this.render = render;
  3496. this.expectedSize = 0;
  3497. this.write = createWriteFunction((text, next) => {
  3498. const n = this.expectedSize;
  3499. this.buffer += text;
  3500. if (this.buffer.length >= n) {
  3501. this.next = next;
  3502. this.pushBySize(n);
  3503. return true; // we will decide when to call next
  3504. }
  3505. return false;
  3506. }, err => {
  3507. this.emit('error', err);
  3508. });
  3509. this.end = () => {
  3510. this.emit('beforeEnd');
  3511. // the rendering is finished; we should push out the last of the buffer.
  3512. this.done = true;
  3513. this.push(this.buffer);
  3514. };
  3515. }
  3516. pushBySize(n) {
  3517. const bufferToPush = this.buffer.substring(0, n);
  3518. this.buffer = this.buffer.substring(n);
  3519. this.push(bufferToPush);
  3520. }
  3521. tryRender() {
  3522. try {
  3523. this.render(this.write, this.end);
  3524. }
  3525. catch (e) {
  3526. this.emit('error', e);
  3527. }
  3528. }
  3529. tryNext() {
  3530. try {
  3531. this.next();
  3532. }
  3533. catch (e) {
  3534. this.emit('error', e);
  3535. }
  3536. }
  3537. _read(n) {
  3538. this.expectedSize = n;
  3539. // it's possible that the last chunk added bumped the buffer up to > 2 * n,
  3540. // which means we will need to go through multiple read calls to drain it
  3541. // down to < n.
  3542. if (isTrue(this.done)) {
  3543. this.push(null);
  3544. return;
  3545. }
  3546. if (this.buffer.length >= n) {
  3547. this.pushBySize(n);
  3548. return;
  3549. }
  3550. if (isUndef(this.next)) {
  3551. // start the rendering chain.
  3552. this.tryRender();
  3553. }
  3554. else {
  3555. // continue with the rendering.
  3556. this.tryNext();
  3557. }
  3558. }
  3559. }
  3560. class RenderContext {
  3561. constructor(options) {
  3562. this.userContext = options.userContext;
  3563. this.activeInstance = options.activeInstance;
  3564. this.renderStates = [];
  3565. this.write = options.write;
  3566. this.done = options.done;
  3567. this.renderNode = options.renderNode;
  3568. this.isUnaryTag = options.isUnaryTag;
  3569. this.modules = options.modules;
  3570. this.directives = options.directives;
  3571. const cache = options.cache;
  3572. if (cache && (!cache.get || !cache.set)) {
  3573. throw new Error('renderer cache must implement at least get & set.');
  3574. }
  3575. this.cache = cache;
  3576. this.get = cache && normalizeAsync(cache, 'get');
  3577. this.has = cache && normalizeAsync(cache, 'has');
  3578. //@ts-expect-error
  3579. this.next = this.next.bind(this);
  3580. }
  3581. //@ts-expect-error
  3582. next() {
  3583. // eslint-disable-next-line
  3584. while (true) {
  3585. const lastState = this.renderStates[this.renderStates.length - 1];
  3586. if (isUndef(lastState)) {
  3587. return this.done();
  3588. }
  3589. /* eslint-disable no-case-declarations */
  3590. switch (lastState.type) {
  3591. case 'Element':
  3592. case 'Fragment':
  3593. const { children, total } = lastState;
  3594. const rendered = lastState.rendered++;
  3595. if (rendered < total) {
  3596. return this.renderNode(children[rendered], false, this);
  3597. }
  3598. else {
  3599. this.renderStates.pop();
  3600. if (lastState.type === 'Element') {
  3601. return this.write(lastState.endTag, this.next);
  3602. }
  3603. }
  3604. break;
  3605. case 'Component':
  3606. this.renderStates.pop();
  3607. this.activeInstance = lastState.prevActive;
  3608. break;
  3609. case 'ComponentWithCache':
  3610. this.renderStates.pop();
  3611. const { buffer, bufferIndex, componentBuffer, key } = lastState;
  3612. const result = {
  3613. html: buffer[bufferIndex],
  3614. components: componentBuffer[bufferIndex]
  3615. };
  3616. this.cache.set(key, result);
  3617. if (bufferIndex === 0) {
  3618. // this is a top-level cached component,
  3619. // exit caching mode.
  3620. //@ts-expect-error
  3621. this.write.caching = false;
  3622. }
  3623. else {
  3624. // parent component is also being cached,
  3625. // merge self into parent's result
  3626. buffer[bufferIndex - 1] += result.html;
  3627. const prev = componentBuffer[bufferIndex - 1];
  3628. result.components.forEach(c => prev.add(c));
  3629. }
  3630. buffer.length = bufferIndex;
  3631. componentBuffer.length = bufferIndex;
  3632. break;
  3633. }
  3634. }
  3635. }
  3636. }
  3637. function normalizeAsync(cache, method) {
  3638. const fn = cache[method];
  3639. if (isUndef(fn)) {
  3640. return;
  3641. }
  3642. else if (fn.length > 1) {
  3643. return (key, cb) => fn.call(cache, key, cb);
  3644. }
  3645. else {
  3646. return (key, cb) => cb(fn.call(cache, key));
  3647. }
  3648. }
  3649. const validDivisionCharRE = /[\w).+\-_$\]]/;
  3650. function parseFilters(exp) {
  3651. let inSingle = false;
  3652. let inDouble = false;
  3653. let inTemplateString = false;
  3654. let inRegex = false;
  3655. let curly = 0;
  3656. let square = 0;
  3657. let paren = 0;
  3658. let lastFilterIndex = 0;
  3659. let c, prev, i, expression, filters;
  3660. for (i = 0; i < exp.length; i++) {
  3661. prev = c;
  3662. c = exp.charCodeAt(i);
  3663. if (inSingle) {
  3664. if (c === 0x27 && prev !== 0x5c)
  3665. inSingle = false;
  3666. }
  3667. else if (inDouble) {
  3668. if (c === 0x22 && prev !== 0x5c)
  3669. inDouble = false;
  3670. }
  3671. else if (inTemplateString) {
  3672. if (c === 0x60 && prev !== 0x5c)
  3673. inTemplateString = false;
  3674. }
  3675. else if (inRegex) {
  3676. if (c === 0x2f && prev !== 0x5c)
  3677. inRegex = false;
  3678. }
  3679. else if (c === 0x7c && // pipe
  3680. exp.charCodeAt(i + 1) !== 0x7c &&
  3681. exp.charCodeAt(i - 1) !== 0x7c &&
  3682. !curly &&
  3683. !square &&
  3684. !paren) {
  3685. if (expression === undefined) {
  3686. // first filter, end of expression
  3687. lastFilterIndex = i + 1;
  3688. expression = exp.slice(0, i).trim();
  3689. }
  3690. else {
  3691. pushFilter();
  3692. }
  3693. }
  3694. else {
  3695. switch (c) {
  3696. case 0x22:
  3697. inDouble = true;
  3698. break; // "
  3699. case 0x27:
  3700. inSingle = true;
  3701. break; // '
  3702. case 0x60:
  3703. inTemplateString = true;
  3704. break; // `
  3705. case 0x28:
  3706. paren++;
  3707. break; // (
  3708. case 0x29:
  3709. paren--;
  3710. break; // )
  3711. case 0x5b:
  3712. square++;
  3713. break; // [
  3714. case 0x5d:
  3715. square--;
  3716. break; // ]
  3717. case 0x7b:
  3718. curly++;
  3719. break; // {
  3720. case 0x7d:
  3721. curly--;
  3722. break; // }
  3723. }
  3724. if (c === 0x2f) {
  3725. // /
  3726. let j = i - 1;
  3727. let p;
  3728. // find first non-whitespace prev char
  3729. for (; j >= 0; j--) {
  3730. p = exp.charAt(j);
  3731. if (p !== ' ')
  3732. break;
  3733. }
  3734. if (!p || !validDivisionCharRE.test(p)) {
  3735. inRegex = true;
  3736. }
  3737. }
  3738. }
  3739. }
  3740. if (expression === undefined) {
  3741. expression = exp.slice(0, i).trim();
  3742. }
  3743. else if (lastFilterIndex !== 0) {
  3744. pushFilter();
  3745. }
  3746. function pushFilter() {
  3747. (filters || (filters = [])).push(exp.slice(lastFilterIndex, i).trim());
  3748. lastFilterIndex = i + 1;
  3749. }
  3750. if (filters) {
  3751. for (i = 0; i < filters.length; i++) {
  3752. expression = wrapFilter(expression, filters[i]);
  3753. }
  3754. }
  3755. return expression;
  3756. }
  3757. function wrapFilter(exp, filter) {
  3758. const i = filter.indexOf('(');
  3759. if (i < 0) {
  3760. // _f: resolveFilter
  3761. return `_f("${filter}")(${exp})`;
  3762. }
  3763. else {
  3764. const name = filter.slice(0, i);
  3765. const args = filter.slice(i + 1);
  3766. return `_f("${name}")(${exp}${args !== ')' ? ',' + args : args}`;
  3767. }
  3768. }
  3769. const defaultTagRE = /\{\{((?:.|\r?\n)+?)\}\}/g;
  3770. const regexEscapeRE = /[-.*+?^${}()|[\]\/\\]/g;
  3771. const buildRegex = cached(delimiters => {
  3772. const open = delimiters[0].replace(regexEscapeRE, '\\$&');
  3773. const close = delimiters[1].replace(regexEscapeRE, '\\$&');
  3774. return new RegExp(open + '((?:.|\\n)+?)' + close, 'g');
  3775. });
  3776. function parseText(text, delimiters) {
  3777. //@ts-expect-error
  3778. const tagRE = delimiters ? buildRegex(delimiters) : defaultTagRE;
  3779. if (!tagRE.test(text)) {
  3780. return;
  3781. }
  3782. const tokens = [];
  3783. const rawTokens = [];
  3784. let lastIndex = (tagRE.lastIndex = 0);
  3785. let match, index, tokenValue;
  3786. while ((match = tagRE.exec(text))) {
  3787. index = match.index;
  3788. // push text token
  3789. if (index > lastIndex) {
  3790. rawTokens.push((tokenValue = text.slice(lastIndex, index)));
  3791. tokens.push(JSON.stringify(tokenValue));
  3792. }
  3793. // tag token
  3794. const exp = parseFilters(match[1].trim());
  3795. tokens.push(`_s(${exp})`);
  3796. rawTokens.push({ '@binding': exp });
  3797. lastIndex = index + match[0].length;
  3798. }
  3799. if (lastIndex < text.length) {
  3800. rawTokens.push((tokenValue = text.slice(lastIndex)));
  3801. tokens.push(JSON.stringify(tokenValue));
  3802. }
  3803. return {
  3804. expression: tokens.join('+'),
  3805. tokens: rawTokens
  3806. };
  3807. }
  3808. /* eslint-disable no-unused-vars */
  3809. function baseWarn(msg, range) {
  3810. console.error(`[Vue compiler]: ${msg}`);
  3811. }
  3812. /* eslint-enable no-unused-vars */
  3813. function pluckModuleFunction(modules, key) {
  3814. return modules ? modules.map(m => m[key]).filter(_ => _) : [];
  3815. }
  3816. function addProp(el, name, value, range, dynamic) {
  3817. (el.props || (el.props = [])).push(rangeSetItem({ name, value, dynamic }, range));
  3818. el.plain = false;
  3819. }
  3820. function addAttr(el, name, value, range, dynamic) {
  3821. const attrs = dynamic
  3822. ? el.dynamicAttrs || (el.dynamicAttrs = [])
  3823. : el.attrs || (el.attrs = []);
  3824. attrs.push(rangeSetItem({ name, value, dynamic }, range));
  3825. el.plain = false;
  3826. }
  3827. // add a raw attr (use this in preTransforms)
  3828. function addRawAttr(el, name, value, range) {
  3829. el.attrsMap[name] = value;
  3830. el.attrsList.push(rangeSetItem({ name, value }, range));
  3831. }
  3832. function addDirective(el, name, rawName, value, arg, isDynamicArg, modifiers, range) {
  3833. (el.directives || (el.directives = [])).push(rangeSetItem({
  3834. name,
  3835. rawName,
  3836. value,
  3837. arg,
  3838. isDynamicArg,
  3839. modifiers
  3840. }, range));
  3841. el.plain = false;
  3842. }
  3843. function prependModifierMarker(symbol, name, dynamic) {
  3844. return dynamic ? `_p(${name},"${symbol}")` : symbol + name; // mark the event as captured
  3845. }
  3846. function addHandler(el, name, value, modifiers, important, warn, range, dynamic) {
  3847. modifiers = modifiers || emptyObject;
  3848. // warn prevent and passive modifier
  3849. /* istanbul ignore if */
  3850. if (warn && modifiers.prevent && modifiers.passive) {
  3851. warn("passive and prevent can't be used together. " +
  3852. "Passive handler can't prevent default event.", range);
  3853. }
  3854. // normalize click.right and click.middle since they don't actually fire
  3855. // this is technically browser-specific, but at least for now browsers are
  3856. // the only target envs that have right/middle clicks.
  3857. if (modifiers.right) {
  3858. if (dynamic) {
  3859. name = `(${name})==='click'?'contextmenu':(${name})`;
  3860. }
  3861. else if (name === 'click') {
  3862. name = 'contextmenu';
  3863. delete modifiers.right;
  3864. }
  3865. }
  3866. else if (modifiers.middle) {
  3867. if (dynamic) {
  3868. name = `(${name})==='click'?'mouseup':(${name})`;
  3869. }
  3870. else if (name === 'click') {
  3871. name = 'mouseup';
  3872. }
  3873. }
  3874. // check capture modifier
  3875. if (modifiers.capture) {
  3876. delete modifiers.capture;
  3877. name = prependModifierMarker('!', name, dynamic);
  3878. }
  3879. if (modifiers.once) {
  3880. delete modifiers.once;
  3881. name = prependModifierMarker('~', name, dynamic);
  3882. }
  3883. /* istanbul ignore if */
  3884. if (modifiers.passive) {
  3885. delete modifiers.passive;
  3886. name = prependModifierMarker('&', name, dynamic);
  3887. }
  3888. let events;
  3889. if (modifiers.native) {
  3890. delete modifiers.native;
  3891. events = el.nativeEvents || (el.nativeEvents = {});
  3892. }
  3893. else {
  3894. events = el.events || (el.events = {});
  3895. }
  3896. const newHandler = rangeSetItem({ value: value.trim(), dynamic }, range);
  3897. if (modifiers !== emptyObject) {
  3898. newHandler.modifiers = modifiers;
  3899. }
  3900. const handlers = events[name];
  3901. /* istanbul ignore if */
  3902. if (Array.isArray(handlers)) {
  3903. important ? handlers.unshift(newHandler) : handlers.push(newHandler);
  3904. }
  3905. else if (handlers) {
  3906. events[name] = important ? [newHandler, handlers] : [handlers, newHandler];
  3907. }
  3908. else {
  3909. events[name] = newHandler;
  3910. }
  3911. el.plain = false;
  3912. }
  3913. function getRawBindingAttr(el, name) {
  3914. return (el.rawAttrsMap[':' + name] ||
  3915. el.rawAttrsMap['v-bind:' + name] ||
  3916. el.rawAttrsMap[name]);
  3917. }
  3918. function getBindingAttr(el, name, getStatic) {
  3919. const dynamicValue = getAndRemoveAttr(el, ':' + name) || getAndRemoveAttr(el, 'v-bind:' + name);
  3920. if (dynamicValue != null) {
  3921. return parseFilters(dynamicValue);
  3922. }
  3923. else if (getStatic !== false) {
  3924. const staticValue = getAndRemoveAttr(el, name);
  3925. if (staticValue != null) {
  3926. return JSON.stringify(staticValue);
  3927. }
  3928. }
  3929. }
  3930. // note: this only removes the attr from the Array (attrsList) so that it
  3931. // doesn't get processed by processAttrs.
  3932. // By default it does NOT remove it from the map (attrsMap) because the map is
  3933. // needed during codegen.
  3934. function getAndRemoveAttr(el, name, removeFromMap) {
  3935. let val;
  3936. if ((val = el.attrsMap[name]) != null) {
  3937. const list = el.attrsList;
  3938. for (let i = 0, l = list.length; i < l; i++) {
  3939. if (list[i].name === name) {
  3940. list.splice(i, 1);
  3941. break;
  3942. }
  3943. }
  3944. }
  3945. if (removeFromMap) {
  3946. delete el.attrsMap[name];
  3947. }
  3948. return val;
  3949. }
  3950. function getAndRemoveAttrByRegex(el, name) {
  3951. const list = el.attrsList;
  3952. for (let i = 0, l = list.length; i < l; i++) {
  3953. const attr = list[i];
  3954. if (name.test(attr.name)) {
  3955. list.splice(i, 1);
  3956. return attr;
  3957. }
  3958. }
  3959. }
  3960. function rangeSetItem(item, range) {
  3961. if (range) {
  3962. if (range.start != null) {
  3963. item.start = range.start;
  3964. }
  3965. if (range.end != null) {
  3966. item.end = range.end;
  3967. }
  3968. }
  3969. return item;
  3970. }
  3971. function transformNode$1(el, options) {
  3972. const warn = options.warn || baseWarn;
  3973. const staticClass = getAndRemoveAttr(el, 'class');
  3974. if (staticClass) {
  3975. const res = parseText(staticClass, options.delimiters);
  3976. if (res) {
  3977. warn(`class="${staticClass}": ` +
  3978. 'Interpolation inside attributes has been removed. ' +
  3979. 'Use v-bind or the colon shorthand instead. For example, ' +
  3980. 'instead of <div class="{{ val }}">, use <div :class="val">.', el.rawAttrsMap['class']);
  3981. }
  3982. }
  3983. if (staticClass) {
  3984. el.staticClass = JSON.stringify(staticClass.replace(/\s+/g, ' ').trim());
  3985. }
  3986. const classBinding = getBindingAttr(el, 'class', false /* getStatic */);
  3987. if (classBinding) {
  3988. el.classBinding = classBinding;
  3989. }
  3990. }
  3991. function genData$2(el) {
  3992. let data = '';
  3993. if (el.staticClass) {
  3994. data += `staticClass:${el.staticClass},`;
  3995. }
  3996. if (el.classBinding) {
  3997. data += `class:${el.classBinding},`;
  3998. }
  3999. return data;
  4000. }
  4001. var klass = {
  4002. staticKeys: ['staticClass'],
  4003. transformNode: transformNode$1,
  4004. genData: genData$2
  4005. };
  4006. function transformNode(el, options) {
  4007. const warn = options.warn || baseWarn;
  4008. const staticStyle = getAndRemoveAttr(el, 'style');
  4009. if (staticStyle) {
  4010. /* istanbul ignore if */
  4011. {
  4012. const res = parseText(staticStyle, options.delimiters);
  4013. if (res) {
  4014. warn(`style="${staticStyle}": ` +
  4015. 'Interpolation inside attributes has been removed. ' +
  4016. 'Use v-bind or the colon shorthand instead. For example, ' +
  4017. 'instead of <div style="{{ val }}">, use <div :style="val">.', el.rawAttrsMap['style']);
  4018. }
  4019. }
  4020. el.staticStyle = JSON.stringify(parseStyleText(staticStyle));
  4021. }
  4022. const styleBinding = getBindingAttr(el, 'style', false /* getStatic */);
  4023. if (styleBinding) {
  4024. el.styleBinding = styleBinding;
  4025. }
  4026. }
  4027. function genData$1(el) {
  4028. let data = '';
  4029. if (el.staticStyle) {
  4030. data += `staticStyle:${el.staticStyle},`;
  4031. }
  4032. if (el.styleBinding) {
  4033. data += `style:(${el.styleBinding}),`;
  4034. }
  4035. return data;
  4036. }
  4037. var style = {
  4038. staticKeys: ['staticStyle'],
  4039. transformNode,
  4040. genData: genData$1
  4041. };
  4042. /**
  4043. * Not type-checking this file because it's mostly vendor code.
  4044. */
  4045. // Regular Expressions for parsing tags and attributes
  4046. const attribute = /^\s*([^\s"'<>\/=]+)(?:\s*(=)\s*(?:"([^"]*)"+|'([^']*)'+|([^\s"'=<>`]+)))?/;
  4047. const dynamicArgAttribute = /^\s*((?:v-[\w-]+:|@|:|#)\[[^=]+?\][^\s"'<>\/=]*)(?:\s*(=)\s*(?:"([^"]*)"+|'([^']*)'+|([^\s"'=<>`]+)))?/;
  4048. const ncname = `[a-zA-Z_][\\-\\.0-9_a-zA-Z${unicodeRegExp.source}]*`;
  4049. const qnameCapture = `((?:${ncname}\\:)?${ncname})`;
  4050. const startTagOpen = new RegExp(`^<${qnameCapture}`);
  4051. const startTagClose = /^\s*(\/?)>/;
  4052. const endTag = new RegExp(`^<\\/${qnameCapture}[^>]*>`);
  4053. const doctype = /^<!DOCTYPE [^>]+>/i;
  4054. // #7298: escape - to avoid being passed as HTML comment when inlined in page
  4055. const comment = /^<!\--/;
  4056. const conditionalComment = /^<!\[/;
  4057. // Special Elements (can contain anything)
  4058. const isPlainTextElement = makeMap('script,style,textarea', true);
  4059. const reCache = {};
  4060. const decodingMap = {
  4061. '&lt;': '<',
  4062. '&gt;': '>',
  4063. '&quot;': '"',
  4064. '&amp;': '&',
  4065. '&#10;': '\n',
  4066. '&#9;': '\t',
  4067. '&#39;': "'"
  4068. };
  4069. const encodedAttr = /&(?:lt|gt|quot|amp|#39);/g;
  4070. const encodedAttrWithNewLines = /&(?:lt|gt|quot|amp|#39|#10|#9);/g;
  4071. // #5992
  4072. const isIgnoreNewlineTag = makeMap('pre,textarea', true);
  4073. const shouldIgnoreFirstNewline = (tag, html) => tag && isIgnoreNewlineTag(tag) && html[0] === '\n';
  4074. function decodeAttr(value, shouldDecodeNewlines) {
  4075. const re = shouldDecodeNewlines ? encodedAttrWithNewLines : encodedAttr;
  4076. return value.replace(re, match => decodingMap[match]);
  4077. }
  4078. function parseHTML(html, options) {
  4079. const stack = [];
  4080. const expectHTML = options.expectHTML;
  4081. const isUnaryTag = options.isUnaryTag || no;
  4082. const canBeLeftOpenTag = options.canBeLeftOpenTag || no;
  4083. let index = 0;
  4084. let last, lastTag;
  4085. while (html) {
  4086. last = html;
  4087. // Make sure we're not in a plaintext content element like script/style
  4088. if (!lastTag || !isPlainTextElement(lastTag)) {
  4089. let textEnd = html.indexOf('<');
  4090. if (textEnd === 0) {
  4091. // Comment:
  4092. if (comment.test(html)) {
  4093. const commentEnd = html.indexOf('-->');
  4094. if (commentEnd >= 0) {
  4095. if (options.shouldKeepComment && options.comment) {
  4096. options.comment(html.substring(4, commentEnd), index, index + commentEnd + 3);
  4097. }
  4098. advance(commentEnd + 3);
  4099. continue;
  4100. }
  4101. }
  4102. // http://en.wikipedia.org/wiki/Conditional_comment#Downlevel-revealed_conditional_comment
  4103. if (conditionalComment.test(html)) {
  4104. const conditionalEnd = html.indexOf(']>');
  4105. if (conditionalEnd >= 0) {
  4106. advance(conditionalEnd + 2);
  4107. continue;
  4108. }
  4109. }
  4110. // Doctype:
  4111. const doctypeMatch = html.match(doctype);
  4112. if (doctypeMatch) {
  4113. advance(doctypeMatch[0].length);
  4114. continue;
  4115. }
  4116. // End tag:
  4117. const endTagMatch = html.match(endTag);
  4118. if (endTagMatch) {
  4119. const curIndex = index;
  4120. advance(endTagMatch[0].length);
  4121. parseEndTag(endTagMatch[1], curIndex, index);
  4122. continue;
  4123. }
  4124. // Start tag:
  4125. const startTagMatch = parseStartTag();
  4126. if (startTagMatch) {
  4127. handleStartTag(startTagMatch);
  4128. if (shouldIgnoreFirstNewline(startTagMatch.tagName, html)) {
  4129. advance(1);
  4130. }
  4131. continue;
  4132. }
  4133. }
  4134. let text, rest, next;
  4135. if (textEnd >= 0) {
  4136. rest = html.slice(textEnd);
  4137. while (!endTag.test(rest) &&
  4138. !startTagOpen.test(rest) &&
  4139. !comment.test(rest) &&
  4140. !conditionalComment.test(rest)) {
  4141. // < in plain text, be forgiving and treat it as text
  4142. next = rest.indexOf('<', 1);
  4143. if (next < 0)
  4144. break;
  4145. textEnd += next;
  4146. rest = html.slice(textEnd);
  4147. }
  4148. text = html.substring(0, textEnd);
  4149. }
  4150. if (textEnd < 0) {
  4151. text = html;
  4152. }
  4153. if (text) {
  4154. advance(text.length);
  4155. }
  4156. if (options.chars && text) {
  4157. options.chars(text, index - text.length, index);
  4158. }
  4159. }
  4160. else {
  4161. let endTagLength = 0;
  4162. const stackedTag = lastTag.toLowerCase();
  4163. const reStackedTag = reCache[stackedTag] ||
  4164. (reCache[stackedTag] = new RegExp('([\\s\\S]*?)(</' + stackedTag + '[^>]*>)', 'i'));
  4165. const rest = html.replace(reStackedTag, function (all, text, endTag) {
  4166. endTagLength = endTag.length;
  4167. if (!isPlainTextElement(stackedTag) && stackedTag !== 'noscript') {
  4168. text = text
  4169. .replace(/<!\--([\s\S]*?)-->/g, '$1') // #7298
  4170. .replace(/<!\[CDATA\[([\s\S]*?)]]>/g, '$1');
  4171. }
  4172. if (shouldIgnoreFirstNewline(stackedTag, text)) {
  4173. text = text.slice(1);
  4174. }
  4175. if (options.chars) {
  4176. options.chars(text);
  4177. }
  4178. return '';
  4179. });
  4180. index += html.length - rest.length;
  4181. html = rest;
  4182. parseEndTag(stackedTag, index - endTagLength, index);
  4183. }
  4184. if (html === last) {
  4185. options.chars && options.chars(html);
  4186. if (!stack.length && options.warn) {
  4187. options.warn(`Mal-formatted tag at end of template: "${html}"`, {
  4188. start: index + html.length
  4189. });
  4190. }
  4191. break;
  4192. }
  4193. }
  4194. // Clean up any remaining tags
  4195. parseEndTag();
  4196. function advance(n) {
  4197. index += n;
  4198. html = html.substring(n);
  4199. }
  4200. function parseStartTag() {
  4201. const start = html.match(startTagOpen);
  4202. if (start) {
  4203. const match = {
  4204. tagName: start[1],
  4205. attrs: [],
  4206. start: index
  4207. };
  4208. advance(start[0].length);
  4209. let end, attr;
  4210. while (!(end = html.match(startTagClose)) &&
  4211. (attr = html.match(dynamicArgAttribute) || html.match(attribute))) {
  4212. attr.start = index;
  4213. advance(attr[0].length);
  4214. attr.end = index;
  4215. match.attrs.push(attr);
  4216. }
  4217. if (end) {
  4218. match.unarySlash = end[1];
  4219. advance(end[0].length);
  4220. match.end = index;
  4221. return match;
  4222. }
  4223. }
  4224. }
  4225. function handleStartTag(match) {
  4226. const tagName = match.tagName;
  4227. const unarySlash = match.unarySlash;
  4228. if (expectHTML) {
  4229. if (lastTag === 'p' && isNonPhrasingTag(tagName)) {
  4230. parseEndTag(lastTag);
  4231. }
  4232. if (canBeLeftOpenTag(tagName) && lastTag === tagName) {
  4233. parseEndTag(tagName);
  4234. }
  4235. }
  4236. const unary = isUnaryTag(tagName) || !!unarySlash;
  4237. const l = match.attrs.length;
  4238. const attrs = new Array(l);
  4239. for (let i = 0; i < l; i++) {
  4240. const args = match.attrs[i];
  4241. const value = args[3] || args[4] || args[5] || '';
  4242. const shouldDecodeNewlines = tagName === 'a' && args[1] === 'href'
  4243. ? options.shouldDecodeNewlinesForHref
  4244. : options.shouldDecodeNewlines;
  4245. attrs[i] = {
  4246. name: args[1],
  4247. value: decodeAttr(value, shouldDecodeNewlines)
  4248. };
  4249. if (options.outputSourceRange) {
  4250. attrs[i].start = args.start + args[0].match(/^\s*/).length;
  4251. attrs[i].end = args.end;
  4252. }
  4253. }
  4254. if (!unary) {
  4255. stack.push({
  4256. tag: tagName,
  4257. lowerCasedTag: tagName.toLowerCase(),
  4258. attrs: attrs,
  4259. start: match.start,
  4260. end: match.end
  4261. });
  4262. lastTag = tagName;
  4263. }
  4264. if (options.start) {
  4265. options.start(tagName, attrs, unary, match.start, match.end);
  4266. }
  4267. }
  4268. function parseEndTag(tagName, start, end) {
  4269. let pos, lowerCasedTagName;
  4270. if (start == null)
  4271. start = index;
  4272. if (end == null)
  4273. end = index;
  4274. // Find the closest opened tag of the same type
  4275. if (tagName) {
  4276. lowerCasedTagName = tagName.toLowerCase();
  4277. for (pos = stack.length - 1; pos >= 0; pos--) {
  4278. if (stack[pos].lowerCasedTag === lowerCasedTagName) {
  4279. break;
  4280. }
  4281. }
  4282. }
  4283. else {
  4284. // If no tag name is provided, clean shop
  4285. pos = 0;
  4286. }
  4287. if (pos >= 0) {
  4288. // Close all the open elements, up the stack
  4289. for (let i = stack.length - 1; i >= pos; i--) {
  4290. if ((i > pos || !tagName) && options.warn) {
  4291. options.warn(`tag <${stack[i].tag}> has no matching end tag.`, {
  4292. start: stack[i].start,
  4293. end: stack[i].end
  4294. });
  4295. }
  4296. if (options.end) {
  4297. options.end(stack[i].tag, start, end);
  4298. }
  4299. }
  4300. // Remove the open elements from the stack
  4301. stack.length = pos;
  4302. lastTag = pos && stack[pos - 1].tag;
  4303. }
  4304. else if (lowerCasedTagName === 'br') {
  4305. if (options.start) {
  4306. options.start(tagName, [], true, start, end);
  4307. }
  4308. }
  4309. else if (lowerCasedTagName === 'p') {
  4310. if (options.start) {
  4311. options.start(tagName, [], false, start, end);
  4312. }
  4313. if (options.end) {
  4314. options.end(tagName, start, end);
  4315. }
  4316. }
  4317. }
  4318. }
  4319. /**
  4320. * Cross-platform code generation for component v-model
  4321. */
  4322. function genComponentModel(el, value, modifiers) {
  4323. const { number, trim } = modifiers || {};
  4324. const baseValueExpression = '$$v';
  4325. let valueExpression = baseValueExpression;
  4326. if (trim) {
  4327. valueExpression =
  4328. `(typeof ${baseValueExpression} === 'string'` +
  4329. `? ${baseValueExpression}.trim()` +
  4330. `: ${baseValueExpression})`;
  4331. }
  4332. if (number) {
  4333. valueExpression = `_n(${valueExpression})`;
  4334. }
  4335. const assignment = genAssignmentCode(value, valueExpression);
  4336. el.model = {
  4337. value: `(${value})`,
  4338. expression: JSON.stringify(value),
  4339. callback: `function (${baseValueExpression}) {${assignment}}`
  4340. };
  4341. }
  4342. /**
  4343. * Cross-platform codegen helper for generating v-model value assignment code.
  4344. */
  4345. function genAssignmentCode(value, assignment) {
  4346. const res = parseModel(value);
  4347. if (res.key === null) {
  4348. return `${value}=${assignment}`;
  4349. }
  4350. else {
  4351. return `$set(${res.exp}, ${res.key}, ${assignment})`;
  4352. }
  4353. }
  4354. /**
  4355. * Parse a v-model expression into a base path and a final key segment.
  4356. * Handles both dot-path and possible square brackets.
  4357. *
  4358. * Possible cases:
  4359. *
  4360. * - test
  4361. * - test[key]
  4362. * - test[test1[key]]
  4363. * - test["a"][key]
  4364. * - xxx.test[a[a].test1[key]]
  4365. * - test.xxx.a["asa"][test1[key]]
  4366. *
  4367. */
  4368. let len, str, chr, index, expressionPos, expressionEndPos;
  4369. function parseModel(val) {
  4370. // Fix https://github.com/vuejs/vue/pull/7730
  4371. // allow v-model="obj.val " (trailing whitespace)
  4372. val = val.trim();
  4373. len = val.length;
  4374. if (val.indexOf('[') < 0 || val.lastIndexOf(']') < len - 1) {
  4375. index = val.lastIndexOf('.');
  4376. if (index > -1) {
  4377. return {
  4378. exp: val.slice(0, index),
  4379. key: '"' + val.slice(index + 1) + '"'
  4380. };
  4381. }
  4382. else {
  4383. return {
  4384. exp: val,
  4385. key: null
  4386. };
  4387. }
  4388. }
  4389. str = val;
  4390. index = expressionPos = expressionEndPos = 0;
  4391. while (!eof()) {
  4392. chr = next();
  4393. /* istanbul ignore if */
  4394. if (isStringStart(chr)) {
  4395. parseString(chr);
  4396. }
  4397. else if (chr === 0x5b) {
  4398. parseBracket(chr);
  4399. }
  4400. }
  4401. return {
  4402. exp: val.slice(0, expressionPos),
  4403. key: val.slice(expressionPos + 1, expressionEndPos)
  4404. };
  4405. }
  4406. function next() {
  4407. return str.charCodeAt(++index);
  4408. }
  4409. function eof() {
  4410. return index >= len;
  4411. }
  4412. function isStringStart(chr) {
  4413. return chr === 0x22 || chr === 0x27;
  4414. }
  4415. function parseBracket(chr) {
  4416. let inBracket = 1;
  4417. expressionPos = index;
  4418. while (!eof()) {
  4419. chr = next();
  4420. if (isStringStart(chr)) {
  4421. parseString(chr);
  4422. continue;
  4423. }
  4424. if (chr === 0x5b)
  4425. inBracket++;
  4426. if (chr === 0x5d)
  4427. inBracket--;
  4428. if (inBracket === 0) {
  4429. expressionEndPos = index;
  4430. break;
  4431. }
  4432. }
  4433. }
  4434. function parseString(chr) {
  4435. const stringQuote = chr;
  4436. while (!eof()) {
  4437. chr = next();
  4438. if (chr === stringQuote) {
  4439. break;
  4440. }
  4441. }
  4442. }
  4443. const onRE = /^@|^v-on:/;
  4444. const dirRE = /^v-|^@|^:|^#/;
  4445. const forAliasRE = /([\s\S]*?)\s+(?:in|of)\s+([\s\S]*)/;
  4446. const forIteratorRE = /,([^,\}\]]*)(?:,([^,\}\]]*))?$/;
  4447. const stripParensRE = /^\(|\)$/g;
  4448. const dynamicArgRE = /^\[.*\]$/;
  4449. const argRE = /:(.*)$/;
  4450. const bindRE = /^:|^\.|^v-bind:/;
  4451. const modifierRE = /\.[^.\]]+(?=[^\]]*$)/g;
  4452. const slotRE = /^v-slot(:|$)|^#/;
  4453. const lineBreakRE = /[\r\n]/;
  4454. const whitespaceRE = /[ \f\t\r\n]+/g;
  4455. const invalidAttributeRE = /[\s"'<>\/=]/;
  4456. const decodeHTMLCached = cached(he__default["default"].decode);
  4457. const emptySlotScopeToken = `_empty_`;
  4458. // configurable state
  4459. let warn$1;
  4460. let delimiters;
  4461. let transforms;
  4462. let preTransforms;
  4463. let postTransforms;
  4464. let platformIsPreTag;
  4465. let platformMustUseProp;
  4466. let platformGetTagNamespace;
  4467. let maybeComponent;
  4468. function createASTElement(tag, attrs, parent) {
  4469. return {
  4470. type: 1,
  4471. tag,
  4472. attrsList: attrs,
  4473. attrsMap: makeAttrsMap(attrs),
  4474. rawAttrsMap: {},
  4475. parent,
  4476. children: []
  4477. };
  4478. }
  4479. /**
  4480. * Convert HTML string to AST.
  4481. */
  4482. function parse(template, options) {
  4483. warn$1 = options.warn || baseWarn;
  4484. platformIsPreTag = options.isPreTag || no;
  4485. platformMustUseProp = options.mustUseProp || no;
  4486. platformGetTagNamespace = options.getTagNamespace || no;
  4487. const isReservedTag = options.isReservedTag || no;
  4488. maybeComponent = (el) => !!(el.component ||
  4489. el.attrsMap[':is'] ||
  4490. el.attrsMap['v-bind:is'] ||
  4491. !(el.attrsMap.is ? isReservedTag(el.attrsMap.is) : isReservedTag(el.tag)));
  4492. transforms = pluckModuleFunction(options.modules, 'transformNode');
  4493. preTransforms = pluckModuleFunction(options.modules, 'preTransformNode');
  4494. postTransforms = pluckModuleFunction(options.modules, 'postTransformNode');
  4495. delimiters = options.delimiters;
  4496. const stack = [];
  4497. const preserveWhitespace = options.preserveWhitespace !== false;
  4498. const whitespaceOption = options.whitespace;
  4499. let root;
  4500. let currentParent;
  4501. let inVPre = false;
  4502. let inPre = false;
  4503. let warned = false;
  4504. function warnOnce(msg, range) {
  4505. if (!warned) {
  4506. warned = true;
  4507. warn$1(msg, range);
  4508. }
  4509. }
  4510. function closeElement(element) {
  4511. trimEndingWhitespace(element);
  4512. if (!inVPre && !element.processed) {
  4513. element = processElement(element, options);
  4514. }
  4515. // tree management
  4516. if (!stack.length && element !== root) {
  4517. // allow root elements with v-if, v-else-if and v-else
  4518. if (root.if && (element.elseif || element.else)) {
  4519. {
  4520. checkRootConstraints(element);
  4521. }
  4522. addIfCondition(root, {
  4523. exp: element.elseif,
  4524. block: element
  4525. });
  4526. }
  4527. else {
  4528. warnOnce(`Component template should contain exactly one root element. ` +
  4529. `If you are using v-if on multiple elements, ` +
  4530. `use v-else-if to chain them instead.`, { start: element.start });
  4531. }
  4532. }
  4533. if (currentParent && !element.forbidden) {
  4534. if (element.elseif || element.else) {
  4535. processIfConditions(element, currentParent);
  4536. }
  4537. else {
  4538. if (element.slotScope) {
  4539. // scoped slot
  4540. // keep it in the children list so that v-else(-if) conditions can
  4541. // find it as the prev node.
  4542. const name = element.slotTarget || '"default"';
  4543. (currentParent.scopedSlots || (currentParent.scopedSlots = {}))[name] = element;
  4544. }
  4545. currentParent.children.push(element);
  4546. element.parent = currentParent;
  4547. }
  4548. }
  4549. // final children cleanup
  4550. // filter out scoped slots
  4551. element.children = element.children.filter(c => !c.slotScope);
  4552. // remove trailing whitespace node again
  4553. trimEndingWhitespace(element);
  4554. // check pre state
  4555. if (element.pre) {
  4556. inVPre = false;
  4557. }
  4558. if (platformIsPreTag(element.tag)) {
  4559. inPre = false;
  4560. }
  4561. // apply post-transforms
  4562. for (let i = 0; i < postTransforms.length; i++) {
  4563. postTransforms[i](element, options);
  4564. }
  4565. }
  4566. function trimEndingWhitespace(el) {
  4567. // remove trailing whitespace node
  4568. if (!inPre) {
  4569. let lastNode;
  4570. while ((lastNode = el.children[el.children.length - 1]) &&
  4571. lastNode.type === 3 &&
  4572. lastNode.text === ' ') {
  4573. el.children.pop();
  4574. }
  4575. }
  4576. }
  4577. function checkRootConstraints(el) {
  4578. if (el.tag === 'slot' || el.tag === 'template') {
  4579. warnOnce(`Cannot use <${el.tag}> as component root element because it may ` +
  4580. 'contain multiple nodes.', { start: el.start });
  4581. }
  4582. if (el.attrsMap.hasOwnProperty('v-for')) {
  4583. warnOnce('Cannot use v-for on stateful component root element because ' +
  4584. 'it renders multiple elements.', el.rawAttrsMap['v-for']);
  4585. }
  4586. }
  4587. parseHTML(template, {
  4588. warn: warn$1,
  4589. expectHTML: options.expectHTML,
  4590. isUnaryTag: options.isUnaryTag,
  4591. canBeLeftOpenTag: options.canBeLeftOpenTag,
  4592. shouldDecodeNewlines: options.shouldDecodeNewlines,
  4593. shouldDecodeNewlinesForHref: options.shouldDecodeNewlinesForHref,
  4594. shouldKeepComment: options.comments,
  4595. outputSourceRange: options.outputSourceRange,
  4596. start(tag, attrs, unary, start, end) {
  4597. // check namespace.
  4598. // inherit parent ns if there is one
  4599. const ns = (currentParent && currentParent.ns) || platformGetTagNamespace(tag);
  4600. // handle IE svg bug
  4601. /* istanbul ignore if */
  4602. if (isIE && ns === 'svg') {
  4603. attrs = guardIESVGBug(attrs);
  4604. }
  4605. let element = createASTElement(tag, attrs, currentParent);
  4606. if (ns) {
  4607. element.ns = ns;
  4608. }
  4609. {
  4610. if (options.outputSourceRange) {
  4611. element.start = start;
  4612. element.end = end;
  4613. element.rawAttrsMap = element.attrsList.reduce((cumulated, attr) => {
  4614. cumulated[attr.name] = attr;
  4615. return cumulated;
  4616. }, {});
  4617. }
  4618. attrs.forEach(attr => {
  4619. if (invalidAttributeRE.test(attr.name)) {
  4620. warn$1(`Invalid dynamic argument expression: attribute names cannot contain ` +
  4621. `spaces, quotes, <, >, / or =.`, options.outputSourceRange
  4622. ? {
  4623. start: attr.start + attr.name.indexOf(`[`),
  4624. end: attr.start + attr.name.length
  4625. }
  4626. : undefined);
  4627. }
  4628. });
  4629. }
  4630. if (isForbiddenTag(element) && !isServerRendering()) {
  4631. element.forbidden = true;
  4632. warn$1('Templates should only be responsible for mapping the state to the ' +
  4633. 'UI. Avoid placing tags with side-effects in your templates, such as ' +
  4634. `<${tag}>` +
  4635. ', as they will not be parsed.', { start: element.start });
  4636. }
  4637. // apply pre-transforms
  4638. for (let i = 0; i < preTransforms.length; i++) {
  4639. element = preTransforms[i](element, options) || element;
  4640. }
  4641. if (!inVPre) {
  4642. processPre(element);
  4643. if (element.pre) {
  4644. inVPre = true;
  4645. }
  4646. }
  4647. if (platformIsPreTag(element.tag)) {
  4648. inPre = true;
  4649. }
  4650. if (inVPre) {
  4651. processRawAttrs(element);
  4652. }
  4653. else if (!element.processed) {
  4654. // structural directives
  4655. processFor(element);
  4656. processIf(element);
  4657. processOnce(element);
  4658. }
  4659. if (!root) {
  4660. root = element;
  4661. {
  4662. checkRootConstraints(root);
  4663. }
  4664. }
  4665. if (!unary) {
  4666. currentParent = element;
  4667. stack.push(element);
  4668. }
  4669. else {
  4670. closeElement(element);
  4671. }
  4672. },
  4673. end(tag, start, end) {
  4674. const element = stack[stack.length - 1];
  4675. // pop stack
  4676. stack.length -= 1;
  4677. currentParent = stack[stack.length - 1];
  4678. if (options.outputSourceRange) {
  4679. element.end = end;
  4680. }
  4681. closeElement(element);
  4682. },
  4683. chars(text, start, end) {
  4684. if (!currentParent) {
  4685. {
  4686. if (text === template) {
  4687. warnOnce('Component template requires a root element, rather than just text.', { start });
  4688. }
  4689. else if ((text = text.trim())) {
  4690. warnOnce(`text "${text}" outside root element will be ignored.`, {
  4691. start
  4692. });
  4693. }
  4694. }
  4695. return;
  4696. }
  4697. // IE textarea placeholder bug
  4698. /* istanbul ignore if */
  4699. if (isIE &&
  4700. currentParent.tag === 'textarea' &&
  4701. currentParent.attrsMap.placeholder === text) {
  4702. return;
  4703. }
  4704. const children = currentParent.children;
  4705. if (inPre || text.trim()) {
  4706. text = isTextTag(currentParent)
  4707. ? text
  4708. : decodeHTMLCached(text);
  4709. }
  4710. else if (!children.length) {
  4711. // remove the whitespace-only node right after an opening tag
  4712. text = '';
  4713. }
  4714. else if (whitespaceOption) {
  4715. if (whitespaceOption === 'condense') {
  4716. // in condense mode, remove the whitespace node if it contains
  4717. // line break, otherwise condense to a single space
  4718. text = lineBreakRE.test(text) ? '' : ' ';
  4719. }
  4720. else {
  4721. text = ' ';
  4722. }
  4723. }
  4724. else {
  4725. text = preserveWhitespace ? ' ' : '';
  4726. }
  4727. if (text) {
  4728. if (!inPre && whitespaceOption === 'condense') {
  4729. // condense consecutive whitespaces into single space
  4730. text = text.replace(whitespaceRE, ' ');
  4731. }
  4732. let res;
  4733. let child;
  4734. if (!inVPre && text !== ' ' && (res = parseText(text, delimiters))) {
  4735. child = {
  4736. type: 2,
  4737. expression: res.expression,
  4738. tokens: res.tokens,
  4739. text
  4740. };
  4741. }
  4742. else if (text !== ' ' ||
  4743. !children.length ||
  4744. children[children.length - 1].text !== ' ') {
  4745. child = {
  4746. type: 3,
  4747. text
  4748. };
  4749. }
  4750. if (child) {
  4751. if (options.outputSourceRange) {
  4752. child.start = start;
  4753. child.end = end;
  4754. }
  4755. children.push(child);
  4756. }
  4757. }
  4758. },
  4759. comment(text, start, end) {
  4760. // adding anything as a sibling to the root node is forbidden
  4761. // comments should still be allowed, but ignored
  4762. if (currentParent) {
  4763. const child = {
  4764. type: 3,
  4765. text,
  4766. isComment: true
  4767. };
  4768. if (options.outputSourceRange) {
  4769. child.start = start;
  4770. child.end = end;
  4771. }
  4772. currentParent.children.push(child);
  4773. }
  4774. }
  4775. });
  4776. return root;
  4777. }
  4778. function processPre(el) {
  4779. if (getAndRemoveAttr(el, 'v-pre') != null) {
  4780. el.pre = true;
  4781. }
  4782. }
  4783. function processRawAttrs(el) {
  4784. const list = el.attrsList;
  4785. const len = list.length;
  4786. if (len) {
  4787. const attrs = (el.attrs = new Array(len));
  4788. for (let i = 0; i < len; i++) {
  4789. attrs[i] = {
  4790. name: list[i].name,
  4791. value: JSON.stringify(list[i].value)
  4792. };
  4793. if (list[i].start != null) {
  4794. attrs[i].start = list[i].start;
  4795. attrs[i].end = list[i].end;
  4796. }
  4797. }
  4798. }
  4799. else if (!el.pre) {
  4800. // non root node in pre blocks with no attributes
  4801. el.plain = true;
  4802. }
  4803. }
  4804. function processElement(element, options) {
  4805. processKey(element);
  4806. // determine whether this is a plain element after
  4807. // removing structural attributes
  4808. element.plain =
  4809. !element.key && !element.scopedSlots && !element.attrsList.length;
  4810. processRef(element);
  4811. processSlotContent(element);
  4812. processSlotOutlet(element);
  4813. processComponent(element);
  4814. for (let i = 0; i < transforms.length; i++) {
  4815. element = transforms[i](element, options) || element;
  4816. }
  4817. processAttrs(element);
  4818. return element;
  4819. }
  4820. function processKey(el) {
  4821. const exp = getBindingAttr(el, 'key');
  4822. if (exp) {
  4823. {
  4824. if (el.tag === 'template') {
  4825. warn$1(`<template> cannot be keyed. Place the key on real elements instead.`, getRawBindingAttr(el, 'key'));
  4826. }
  4827. if (el.for) {
  4828. const iterator = el.iterator2 || el.iterator1;
  4829. const parent = el.parent;
  4830. if (iterator &&
  4831. iterator === exp &&
  4832. parent &&
  4833. parent.tag === 'transition-group') {
  4834. warn$1(`Do not use v-for index as key on <transition-group> children, ` +
  4835. `this is the same as not using keys.`, getRawBindingAttr(el, 'key'), true /* tip */);
  4836. }
  4837. }
  4838. }
  4839. el.key = exp;
  4840. }
  4841. }
  4842. function processRef(el) {
  4843. const ref = getBindingAttr(el, 'ref');
  4844. if (ref) {
  4845. el.ref = ref;
  4846. el.refInFor = checkInFor(el);
  4847. }
  4848. }
  4849. function processFor(el) {
  4850. let exp;
  4851. if ((exp = getAndRemoveAttr(el, 'v-for'))) {
  4852. const res = parseFor(exp);
  4853. if (res) {
  4854. extend(el, res);
  4855. }
  4856. else {
  4857. warn$1(`Invalid v-for expression: ${exp}`, el.rawAttrsMap['v-for']);
  4858. }
  4859. }
  4860. }
  4861. function parseFor(exp) {
  4862. const inMatch = exp.match(forAliasRE);
  4863. if (!inMatch)
  4864. return;
  4865. const res = {};
  4866. res.for = inMatch[2].trim();
  4867. const alias = inMatch[1].trim().replace(stripParensRE, '');
  4868. const iteratorMatch = alias.match(forIteratorRE);
  4869. if (iteratorMatch) {
  4870. res.alias = alias.replace(forIteratorRE, '').trim();
  4871. res.iterator1 = iteratorMatch[1].trim();
  4872. if (iteratorMatch[2]) {
  4873. res.iterator2 = iteratorMatch[2].trim();
  4874. }
  4875. }
  4876. else {
  4877. res.alias = alias;
  4878. }
  4879. return res;
  4880. }
  4881. function processIf(el) {
  4882. const exp = getAndRemoveAttr(el, 'v-if');
  4883. if (exp) {
  4884. el.if = exp;
  4885. addIfCondition(el, {
  4886. exp: exp,
  4887. block: el
  4888. });
  4889. }
  4890. else {
  4891. if (getAndRemoveAttr(el, 'v-else') != null) {
  4892. el.else = true;
  4893. }
  4894. const elseif = getAndRemoveAttr(el, 'v-else-if');
  4895. if (elseif) {
  4896. el.elseif = elseif;
  4897. }
  4898. }
  4899. }
  4900. function processIfConditions(el, parent) {
  4901. const prev = findPrevElement(parent.children);
  4902. if (prev && prev.if) {
  4903. addIfCondition(prev, {
  4904. exp: el.elseif,
  4905. block: el
  4906. });
  4907. }
  4908. else {
  4909. warn$1(`v-${el.elseif ? 'else-if="' + el.elseif + '"' : 'else'} ` +
  4910. `used on element <${el.tag}> without corresponding v-if.`, el.rawAttrsMap[el.elseif ? 'v-else-if' : 'v-else']);
  4911. }
  4912. }
  4913. function findPrevElement(children) {
  4914. let i = children.length;
  4915. while (i--) {
  4916. if (children[i].type === 1) {
  4917. return children[i];
  4918. }
  4919. else {
  4920. if (children[i].text !== ' ') {
  4921. warn$1(`text "${children[i].text.trim()}" between v-if and v-else(-if) ` +
  4922. `will be ignored.`, children[i]);
  4923. }
  4924. children.pop();
  4925. }
  4926. }
  4927. }
  4928. function addIfCondition(el, condition) {
  4929. if (!el.ifConditions) {
  4930. el.ifConditions = [];
  4931. }
  4932. el.ifConditions.push(condition);
  4933. }
  4934. function processOnce(el) {
  4935. const once = getAndRemoveAttr(el, 'v-once');
  4936. if (once != null) {
  4937. el.once = true;
  4938. }
  4939. }
  4940. // handle content being passed to a component as slot,
  4941. // e.g. <template slot="xxx">, <div slot-scope="xxx">
  4942. function processSlotContent(el) {
  4943. let slotScope;
  4944. if (el.tag === 'template') {
  4945. slotScope = getAndRemoveAttr(el, 'scope');
  4946. /* istanbul ignore if */
  4947. if (slotScope) {
  4948. warn$1(`the "scope" attribute for scoped slots have been deprecated and ` +
  4949. `replaced by "slot-scope" since 2.5. The new "slot-scope" attribute ` +
  4950. `can also be used on plain elements in addition to <template> to ` +
  4951. `denote scoped slots.`, el.rawAttrsMap['scope'], true);
  4952. }
  4953. el.slotScope = slotScope || getAndRemoveAttr(el, 'slot-scope');
  4954. }
  4955. else if ((slotScope = getAndRemoveAttr(el, 'slot-scope'))) {
  4956. /* istanbul ignore if */
  4957. if (el.attrsMap['v-for']) {
  4958. warn$1(`Ambiguous combined usage of slot-scope and v-for on <${el.tag}> ` +
  4959. `(v-for takes higher priority). Use a wrapper <template> for the ` +
  4960. `scoped slot to make it clearer.`, el.rawAttrsMap['slot-scope'], true);
  4961. }
  4962. el.slotScope = slotScope;
  4963. }
  4964. // slot="xxx"
  4965. const slotTarget = getBindingAttr(el, 'slot');
  4966. if (slotTarget) {
  4967. el.slotTarget = slotTarget === '""' ? '"default"' : slotTarget;
  4968. el.slotTargetDynamic = !!(el.attrsMap[':slot'] || el.attrsMap['v-bind:slot']);
  4969. // preserve slot as an attribute for native shadow DOM compat
  4970. // only for non-scoped slots.
  4971. if (el.tag !== 'template' && !el.slotScope) {
  4972. addAttr(el, 'slot', slotTarget, getRawBindingAttr(el, 'slot'));
  4973. }
  4974. }
  4975. // 2.6 v-slot syntax
  4976. {
  4977. if (el.tag === 'template') {
  4978. // v-slot on <template>
  4979. const slotBinding = getAndRemoveAttrByRegex(el, slotRE);
  4980. if (slotBinding) {
  4981. {
  4982. if (el.slotTarget || el.slotScope) {
  4983. warn$1(`Unexpected mixed usage of different slot syntaxes.`, el);
  4984. }
  4985. if (el.parent && !maybeComponent(el.parent)) {
  4986. warn$1(`<template v-slot> can only appear at the root level inside ` +
  4987. `the receiving component`, el);
  4988. }
  4989. }
  4990. const { name, dynamic } = getSlotName(slotBinding);
  4991. el.slotTarget = name;
  4992. el.slotTargetDynamic = dynamic;
  4993. el.slotScope = slotBinding.value || emptySlotScopeToken; // force it into a scoped slot for perf
  4994. }
  4995. }
  4996. else {
  4997. // v-slot on component, denotes default slot
  4998. const slotBinding = getAndRemoveAttrByRegex(el, slotRE);
  4999. if (slotBinding) {
  5000. {
  5001. if (!maybeComponent(el)) {
  5002. warn$1(`v-slot can only be used on components or <template>.`, slotBinding);
  5003. }
  5004. if (el.slotScope || el.slotTarget) {
  5005. warn$1(`Unexpected mixed usage of different slot syntaxes.`, el);
  5006. }
  5007. if (el.scopedSlots) {
  5008. warn$1(`To avoid scope ambiguity, the default slot should also use ` +
  5009. `<template> syntax when there are other named slots.`, slotBinding);
  5010. }
  5011. }
  5012. // add the component's children to its default slot
  5013. const slots = el.scopedSlots || (el.scopedSlots = {});
  5014. const { name, dynamic } = getSlotName(slotBinding);
  5015. const slotContainer = (slots[name] = createASTElement('template', [], el));
  5016. slotContainer.slotTarget = name;
  5017. slotContainer.slotTargetDynamic = dynamic;
  5018. slotContainer.children = el.children.filter((c) => {
  5019. if (!c.slotScope) {
  5020. c.parent = slotContainer;
  5021. return true;
  5022. }
  5023. });
  5024. slotContainer.slotScope = slotBinding.value || emptySlotScopeToken;
  5025. // remove children as they are returned from scopedSlots now
  5026. el.children = [];
  5027. // mark el non-plain so data gets generated
  5028. el.plain = false;
  5029. }
  5030. }
  5031. }
  5032. }
  5033. function getSlotName(binding) {
  5034. let name = binding.name.replace(slotRE, '');
  5035. if (!name) {
  5036. if (binding.name[0] !== '#') {
  5037. name = 'default';
  5038. }
  5039. else {
  5040. warn$1(`v-slot shorthand syntax requires a slot name.`, binding);
  5041. }
  5042. }
  5043. return dynamicArgRE.test(name)
  5044. ? // dynamic [name]
  5045. { name: name.slice(1, -1), dynamic: true }
  5046. : // static name
  5047. { name: `"${name}"`, dynamic: false };
  5048. }
  5049. // handle <slot/> outlets
  5050. function processSlotOutlet(el) {
  5051. if (el.tag === 'slot') {
  5052. el.slotName = getBindingAttr(el, 'name');
  5053. if (el.key) {
  5054. warn$1(`\`key\` does not work on <slot> because slots are abstract outlets ` +
  5055. `and can possibly expand into multiple elements. ` +
  5056. `Use the key on a wrapping element instead.`, getRawBindingAttr(el, 'key'));
  5057. }
  5058. }
  5059. }
  5060. function processComponent(el) {
  5061. let binding;
  5062. if ((binding = getBindingAttr(el, 'is'))) {
  5063. el.component = binding;
  5064. }
  5065. if (getAndRemoveAttr(el, 'inline-template') != null) {
  5066. el.inlineTemplate = true;
  5067. }
  5068. }
  5069. function processAttrs(el) {
  5070. const list = el.attrsList;
  5071. let i, l, name, rawName, value, modifiers, syncGen, isDynamic;
  5072. for (i = 0, l = list.length; i < l; i++) {
  5073. name = rawName = list[i].name;
  5074. value = list[i].value;
  5075. if (dirRE.test(name)) {
  5076. // mark element as dynamic
  5077. el.hasBindings = true;
  5078. // modifiers
  5079. modifiers = parseModifiers(name.replace(dirRE, ''));
  5080. // support .foo shorthand syntax for the .prop modifier
  5081. if (modifiers) {
  5082. name = name.replace(modifierRE, '');
  5083. }
  5084. if (bindRE.test(name)) {
  5085. // v-bind
  5086. name = name.replace(bindRE, '');
  5087. value = parseFilters(value);
  5088. isDynamic = dynamicArgRE.test(name);
  5089. if (isDynamic) {
  5090. name = name.slice(1, -1);
  5091. }
  5092. if (value.trim().length === 0) {
  5093. warn$1(`The value for a v-bind expression cannot be empty. Found in "v-bind:${name}"`);
  5094. }
  5095. if (modifiers) {
  5096. if (modifiers.prop && !isDynamic) {
  5097. name = camelize(name);
  5098. if (name === 'innerHtml')
  5099. name = 'innerHTML';
  5100. }
  5101. if (modifiers.camel && !isDynamic) {
  5102. name = camelize(name);
  5103. }
  5104. if (modifiers.sync) {
  5105. syncGen = genAssignmentCode(value, `$event`);
  5106. if (!isDynamic) {
  5107. addHandler(el, `update:${camelize(name)}`, syncGen, null, false, warn$1, list[i]);
  5108. if (hyphenate(name) !== camelize(name)) {
  5109. addHandler(el, `update:${hyphenate(name)}`, syncGen, null, false, warn$1, list[i]);
  5110. }
  5111. }
  5112. else {
  5113. // handler w/ dynamic event name
  5114. addHandler(el, `"update:"+(${name})`, syncGen, null, false, warn$1, list[i], true // dynamic
  5115. );
  5116. }
  5117. }
  5118. }
  5119. if ((modifiers && modifiers.prop) ||
  5120. (!el.component && platformMustUseProp(el.tag, el.attrsMap.type, name))) {
  5121. addProp(el, name, value, list[i], isDynamic);
  5122. }
  5123. else {
  5124. addAttr(el, name, value, list[i], isDynamic);
  5125. }
  5126. }
  5127. else if (onRE.test(name)) {
  5128. // v-on
  5129. name = name.replace(onRE, '');
  5130. isDynamic = dynamicArgRE.test(name);
  5131. if (isDynamic) {
  5132. name = name.slice(1, -1);
  5133. }
  5134. addHandler(el, name, value, modifiers, false, warn$1, list[i], isDynamic);
  5135. }
  5136. else {
  5137. // normal directives
  5138. name = name.replace(dirRE, '');
  5139. // parse arg
  5140. const argMatch = name.match(argRE);
  5141. let arg = argMatch && argMatch[1];
  5142. isDynamic = false;
  5143. if (arg) {
  5144. name = name.slice(0, -(arg.length + 1));
  5145. if (dynamicArgRE.test(arg)) {
  5146. arg = arg.slice(1, -1);
  5147. isDynamic = true;
  5148. }
  5149. }
  5150. addDirective(el, name, rawName, value, arg, isDynamic, modifiers, list[i]);
  5151. if (name === 'model') {
  5152. checkForAliasModel(el, value);
  5153. }
  5154. }
  5155. }
  5156. else {
  5157. // literal attribute
  5158. {
  5159. const res = parseText(value, delimiters);
  5160. if (res) {
  5161. warn$1(`${name}="${value}": ` +
  5162. 'Interpolation inside attributes has been removed. ' +
  5163. 'Use v-bind or the colon shorthand instead. For example, ' +
  5164. 'instead of <div id="{{ val }}">, use <div :id="val">.', list[i]);
  5165. }
  5166. }
  5167. addAttr(el, name, JSON.stringify(value), list[i]);
  5168. // #6887 firefox doesn't update muted state if set via attribute
  5169. // even immediately after element creation
  5170. if (!el.component &&
  5171. name === 'muted' &&
  5172. platformMustUseProp(el.tag, el.attrsMap.type, name)) {
  5173. addProp(el, name, 'true', list[i]);
  5174. }
  5175. }
  5176. }
  5177. }
  5178. function checkInFor(el) {
  5179. let parent = el;
  5180. while (parent) {
  5181. if (parent.for !== undefined) {
  5182. return true;
  5183. }
  5184. parent = parent.parent;
  5185. }
  5186. return false;
  5187. }
  5188. function parseModifiers(name) {
  5189. const match = name.match(modifierRE);
  5190. if (match) {
  5191. const ret = {};
  5192. match.forEach(m => {
  5193. ret[m.slice(1)] = true;
  5194. });
  5195. return ret;
  5196. }
  5197. }
  5198. function makeAttrsMap(attrs) {
  5199. const map = {};
  5200. for (let i = 0, l = attrs.length; i < l; i++) {
  5201. if (map[attrs[i].name] && !isIE && !isEdge) {
  5202. warn$1('duplicate attribute: ' + attrs[i].name, attrs[i]);
  5203. }
  5204. map[attrs[i].name] = attrs[i].value;
  5205. }
  5206. return map;
  5207. }
  5208. // for script (e.g. type="x/template") or style, do not decode content
  5209. function isTextTag(el) {
  5210. return el.tag === 'script' || el.tag === 'style';
  5211. }
  5212. function isForbiddenTag(el) {
  5213. return (el.tag === 'style' ||
  5214. (el.tag === 'script' &&
  5215. (!el.attrsMap.type || el.attrsMap.type === 'text/javascript')));
  5216. }
  5217. const ieNSBug = /^xmlns:NS\d+/;
  5218. const ieNSPrefix = /^NS\d+:/;
  5219. /* istanbul ignore next */
  5220. function guardIESVGBug(attrs) {
  5221. const res = [];
  5222. for (let i = 0; i < attrs.length; i++) {
  5223. const attr = attrs[i];
  5224. if (!ieNSBug.test(attr.name)) {
  5225. attr.name = attr.name.replace(ieNSPrefix, '');
  5226. res.push(attr);
  5227. }
  5228. }
  5229. return res;
  5230. }
  5231. function checkForAliasModel(el, value) {
  5232. let _el = el;
  5233. while (_el) {
  5234. if (_el.for && _el.alias === value) {
  5235. warn$1(`<${el.tag} v-model="${value}">: ` +
  5236. `You are binding v-model directly to a v-for iteration alias. ` +
  5237. `This will not be able to modify the v-for source array because ` +
  5238. `writing to the alias is like modifying a function local variable. ` +
  5239. `Consider using an array of objects and use v-model on an object property instead.`, el.rawAttrsMap['v-model']);
  5240. }
  5241. _el = _el.parent;
  5242. }
  5243. }
  5244. /**
  5245. * Expand input[v-model] with dynamic type bindings into v-if-else chains
  5246. * Turn this:
  5247. * <input v-model="data[type]" :type="type">
  5248. * into this:
  5249. * <input v-if="type === 'checkbox'" type="checkbox" v-model="data[type]">
  5250. * <input v-else-if="type === 'radio'" type="radio" v-model="data[type]">
  5251. * <input v-else :type="type" v-model="data[type]">
  5252. */
  5253. function preTransformNode(el, options) {
  5254. if (el.tag === 'input') {
  5255. const map = el.attrsMap;
  5256. if (!map['v-model']) {
  5257. return;
  5258. }
  5259. let typeBinding;
  5260. if (map[':type'] || map['v-bind:type']) {
  5261. typeBinding = getBindingAttr(el, 'type');
  5262. }
  5263. if (!map.type && !typeBinding && map['v-bind']) {
  5264. typeBinding = `(${map['v-bind']}).type`;
  5265. }
  5266. if (typeBinding) {
  5267. const ifCondition = getAndRemoveAttr(el, 'v-if', true);
  5268. const ifConditionExtra = ifCondition ? `&&(${ifCondition})` : ``;
  5269. const hasElse = getAndRemoveAttr(el, 'v-else', true) != null;
  5270. const elseIfCondition = getAndRemoveAttr(el, 'v-else-if', true);
  5271. // 1. checkbox
  5272. const branch0 = cloneASTElement(el);
  5273. // process for on the main node
  5274. processFor(branch0);
  5275. addRawAttr(branch0, 'type', 'checkbox');
  5276. processElement(branch0, options);
  5277. branch0.processed = true; // prevent it from double-processed
  5278. branch0.if = `(${typeBinding})==='checkbox'` + ifConditionExtra;
  5279. addIfCondition(branch0, {
  5280. exp: branch0.if,
  5281. block: branch0
  5282. });
  5283. // 2. add radio else-if condition
  5284. const branch1 = cloneASTElement(el);
  5285. getAndRemoveAttr(branch1, 'v-for', true);
  5286. addRawAttr(branch1, 'type', 'radio');
  5287. processElement(branch1, options);
  5288. addIfCondition(branch0, {
  5289. exp: `(${typeBinding})==='radio'` + ifConditionExtra,
  5290. block: branch1
  5291. });
  5292. // 3. other
  5293. const branch2 = cloneASTElement(el);
  5294. getAndRemoveAttr(branch2, 'v-for', true);
  5295. addRawAttr(branch2, ':type', typeBinding);
  5296. processElement(branch2, options);
  5297. addIfCondition(branch0, {
  5298. exp: ifCondition,
  5299. block: branch2
  5300. });
  5301. if (hasElse) {
  5302. branch0.else = true;
  5303. }
  5304. else if (elseIfCondition) {
  5305. branch0.elseif = elseIfCondition;
  5306. }
  5307. return branch0;
  5308. }
  5309. }
  5310. }
  5311. function cloneASTElement(el) {
  5312. return createASTElement(el.tag, el.attrsList.slice(), el.parent);
  5313. }
  5314. var model$1 = {
  5315. preTransformNode
  5316. };
  5317. var modules = [klass, style, model$1];
  5318. let warn;
  5319. // in some cases, the event used has to be determined at runtime
  5320. // so we used some reserved tokens during compile.
  5321. const RANGE_TOKEN = '__r';
  5322. function model(el, dir, _warn) {
  5323. warn = _warn;
  5324. const value = dir.value;
  5325. const modifiers = dir.modifiers;
  5326. const tag = el.tag;
  5327. const type = el.attrsMap.type;
  5328. {
  5329. // inputs with type="file" are read only and setting the input's
  5330. // value will throw an error.
  5331. if (tag === 'input' && type === 'file') {
  5332. warn(`<${el.tag} v-model="${value}" type="file">:\n` +
  5333. `File inputs are read only. Use a v-on:change listener instead.`, el.rawAttrsMap['v-model']);
  5334. }
  5335. }
  5336. if (el.component) {
  5337. genComponentModel(el, value, modifiers);
  5338. // component v-model doesn't need extra runtime
  5339. return false;
  5340. }
  5341. else if (tag === 'select') {
  5342. genSelect(el, value, modifiers);
  5343. }
  5344. else if (tag === 'input' && type === 'checkbox') {
  5345. genCheckboxModel(el, value, modifiers);
  5346. }
  5347. else if (tag === 'input' && type === 'radio') {
  5348. genRadioModel(el, value, modifiers);
  5349. }
  5350. else if (tag === 'input' || tag === 'textarea') {
  5351. genDefaultModel(el, value, modifiers);
  5352. }
  5353. else {
  5354. genComponentModel(el, value, modifiers);
  5355. // component v-model doesn't need extra runtime
  5356. return false;
  5357. }
  5358. // ensure runtime directive metadata
  5359. return true;
  5360. }
  5361. function genCheckboxModel(el, value, modifiers) {
  5362. const number = modifiers && modifiers.number;
  5363. const valueBinding = getBindingAttr(el, 'value') || 'null';
  5364. const trueValueBinding = getBindingAttr(el, 'true-value') || 'true';
  5365. const falseValueBinding = getBindingAttr(el, 'false-value') || 'false';
  5366. addProp(el, 'checked', `Array.isArray(${value})` +
  5367. `?_i(${value},${valueBinding})>-1` +
  5368. (trueValueBinding === 'true'
  5369. ? `:(${value})`
  5370. : `:_q(${value},${trueValueBinding})`));
  5371. addHandler(el, 'change', `var $$a=${value},` +
  5372. '$$el=$event.target,' +
  5373. `$$c=$$el.checked?(${trueValueBinding}):(${falseValueBinding});` +
  5374. 'if(Array.isArray($$a)){' +
  5375. `var $$v=${number ? '_n(' + valueBinding + ')' : valueBinding},` +
  5376. '$$i=_i($$a,$$v);' +
  5377. `if($$el.checked){$$i<0&&(${genAssignmentCode(value, '$$a.concat([$$v])')})}` +
  5378. `else{$$i>-1&&(${genAssignmentCode(value, '$$a.slice(0,$$i).concat($$a.slice($$i+1))')})}` +
  5379. `}else{${genAssignmentCode(value, '$$c')}}`, null, true);
  5380. }
  5381. function genRadioModel(el, value, modifiers) {
  5382. const number = modifiers && modifiers.number;
  5383. let valueBinding = getBindingAttr(el, 'value') || 'null';
  5384. valueBinding = number ? `_n(${valueBinding})` : valueBinding;
  5385. addProp(el, 'checked', `_q(${value},${valueBinding})`);
  5386. addHandler(el, 'change', genAssignmentCode(value, valueBinding), null, true);
  5387. }
  5388. function genSelect(el, value, modifiers) {
  5389. const number = modifiers && modifiers.number;
  5390. const selectedVal = `Array.prototype.filter` +
  5391. `.call($event.target.options,function(o){return o.selected})` +
  5392. `.map(function(o){var val = "_value" in o ? o._value : o.value;` +
  5393. `return ${number ? '_n(val)' : 'val'}})`;
  5394. const assignment = '$event.target.multiple ? $$selectedVal : $$selectedVal[0]';
  5395. let code = `var $$selectedVal = ${selectedVal};`;
  5396. code = `${code} ${genAssignmentCode(value, assignment)}`;
  5397. addHandler(el, 'change', code, null, true);
  5398. }
  5399. function genDefaultModel(el, value, modifiers) {
  5400. const type = el.attrsMap.type;
  5401. // warn if v-bind:value conflicts with v-model
  5402. // except for inputs with v-bind:type
  5403. {
  5404. const value = el.attrsMap['v-bind:value'] || el.attrsMap[':value'];
  5405. const typeBinding = el.attrsMap['v-bind:type'] || el.attrsMap[':type'];
  5406. if (value && !typeBinding) {
  5407. const binding = el.attrsMap['v-bind:value'] ? 'v-bind:value' : ':value';
  5408. warn(`${binding}="${value}" conflicts with v-model on the same element ` +
  5409. 'because the latter already expands to a value binding internally', el.rawAttrsMap[binding]);
  5410. }
  5411. }
  5412. const { lazy, number, trim } = modifiers || {};
  5413. const needCompositionGuard = !lazy && type !== 'range';
  5414. const event = lazy ? 'change' : type === 'range' ? RANGE_TOKEN : 'input';
  5415. let valueExpression = '$event.target.value';
  5416. if (trim) {
  5417. valueExpression = `$event.target.value.trim()`;
  5418. }
  5419. if (number) {
  5420. valueExpression = `_n(${valueExpression})`;
  5421. }
  5422. let code = genAssignmentCode(value, valueExpression);
  5423. if (needCompositionGuard) {
  5424. code = `if($event.target.composing)return;${code}`;
  5425. }
  5426. addProp(el, 'value', `(${value})`);
  5427. addHandler(el, event, code, null, true);
  5428. if (trim || number) {
  5429. addHandler(el, 'blur', '$forceUpdate()');
  5430. }
  5431. }
  5432. function text(el, dir) {
  5433. if (dir.value) {
  5434. addProp(el, 'textContent', `_s(${dir.value})`, dir);
  5435. }
  5436. }
  5437. function html(el, dir) {
  5438. if (dir.value) {
  5439. addProp(el, 'innerHTML', `_s(${dir.value})`, dir);
  5440. }
  5441. }
  5442. var directives = {
  5443. model,
  5444. text,
  5445. html
  5446. };
  5447. const baseOptions = {
  5448. expectHTML: true,
  5449. modules,
  5450. directives,
  5451. isPreTag,
  5452. isUnaryTag,
  5453. mustUseProp,
  5454. canBeLeftOpenTag,
  5455. isReservedTag,
  5456. getTagNamespace,
  5457. staticKeys: genStaticKeys(modules)
  5458. };
  5459. const fnExpRE = /^([\w$_]+|\([^)]*?\))\s*=>|^function(?:\s+[\w$]+)?\s*\(/;
  5460. const fnInvokeRE = /\([^)]*?\);*$/;
  5461. const simplePathRE = /^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*|\['[^']*?']|\["[^"]*?"]|\[\d+]|\[[A-Za-z_$][\w$]*])*$/;
  5462. // KeyboardEvent.keyCode aliases
  5463. const keyCodes = {
  5464. esc: 27,
  5465. tab: 9,
  5466. enter: 13,
  5467. space: 32,
  5468. up: 38,
  5469. left: 37,
  5470. right: 39,
  5471. down: 40,
  5472. delete: [8, 46]
  5473. };
  5474. // KeyboardEvent.key aliases
  5475. const keyNames = {
  5476. // #7880: IE11 and Edge use `Esc` for Escape key name.
  5477. esc: ['Esc', 'Escape'],
  5478. tab: 'Tab',
  5479. enter: 'Enter',
  5480. // #9112: IE11 uses `Spacebar` for Space key name.
  5481. space: [' ', 'Spacebar'],
  5482. // #7806: IE11 uses key names without `Arrow` prefix for arrow keys.
  5483. up: ['Up', 'ArrowUp'],
  5484. left: ['Left', 'ArrowLeft'],
  5485. right: ['Right', 'ArrowRight'],
  5486. down: ['Down', 'ArrowDown'],
  5487. // #9112: IE11 uses `Del` for Delete key name.
  5488. delete: ['Backspace', 'Delete', 'Del']
  5489. };
  5490. // #4868: modifiers that prevent the execution of the listener
  5491. // need to explicitly return null so that we can determine whether to remove
  5492. // the listener for .once
  5493. const genGuard = condition => `if(${condition})return null;`;
  5494. const modifierCode = {
  5495. stop: '$event.stopPropagation();',
  5496. prevent: '$event.preventDefault();',
  5497. self: genGuard(`$event.target !== $event.currentTarget`),
  5498. ctrl: genGuard(`!$event.ctrlKey`),
  5499. shift: genGuard(`!$event.shiftKey`),
  5500. alt: genGuard(`!$event.altKey`),
  5501. meta: genGuard(`!$event.metaKey`),
  5502. left: genGuard(`'button' in $event && $event.button !== 0`),
  5503. middle: genGuard(`'button' in $event && $event.button !== 1`),
  5504. right: genGuard(`'button' in $event && $event.button !== 2`)
  5505. };
  5506. function genHandlers(events, isNative) {
  5507. const prefix = isNative ? 'nativeOn:' : 'on:';
  5508. let staticHandlers = ``;
  5509. let dynamicHandlers = ``;
  5510. for (const name in events) {
  5511. const handlerCode = genHandler(events[name]);
  5512. //@ts-expect-error
  5513. if (events[name] && events[name].dynamic) {
  5514. dynamicHandlers += `${name},${handlerCode},`;
  5515. }
  5516. else {
  5517. staticHandlers += `"${name}":${handlerCode},`;
  5518. }
  5519. }
  5520. staticHandlers = `{${staticHandlers.slice(0, -1)}}`;
  5521. if (dynamicHandlers) {
  5522. return prefix + `_d(${staticHandlers},[${dynamicHandlers.slice(0, -1)}])`;
  5523. }
  5524. else {
  5525. return prefix + staticHandlers;
  5526. }
  5527. }
  5528. function genHandler(handler) {
  5529. if (!handler) {
  5530. return 'function(){}';
  5531. }
  5532. if (Array.isArray(handler)) {
  5533. return `[${handler.map(handler => genHandler(handler)).join(',')}]`;
  5534. }
  5535. const isMethodPath = simplePathRE.test(handler.value);
  5536. const isFunctionExpression = fnExpRE.test(handler.value);
  5537. const isFunctionInvocation = simplePathRE.test(handler.value.replace(fnInvokeRE, ''));
  5538. if (!handler.modifiers) {
  5539. if (isMethodPath || isFunctionExpression) {
  5540. return handler.value;
  5541. }
  5542. return `function($event){${isFunctionInvocation ? `return ${handler.value}` : handler.value}}`; // inline statement
  5543. }
  5544. else {
  5545. let code = '';
  5546. let genModifierCode = '';
  5547. const keys = [];
  5548. for (const key in handler.modifiers) {
  5549. if (modifierCode[key]) {
  5550. genModifierCode += modifierCode[key];
  5551. // left/right
  5552. if (keyCodes[key]) {
  5553. keys.push(key);
  5554. }
  5555. }
  5556. else if (key === 'exact') {
  5557. const modifiers = handler.modifiers;
  5558. genModifierCode += genGuard(['ctrl', 'shift', 'alt', 'meta']
  5559. .filter(keyModifier => !modifiers[keyModifier])
  5560. .map(keyModifier => `$event.${keyModifier}Key`)
  5561. .join('||'));
  5562. }
  5563. else {
  5564. keys.push(key);
  5565. }
  5566. }
  5567. if (keys.length) {
  5568. code += genKeyFilter(keys);
  5569. }
  5570. // Make sure modifiers like prevent and stop get executed after key filtering
  5571. if (genModifierCode) {
  5572. code += genModifierCode;
  5573. }
  5574. const handlerCode = isMethodPath
  5575. ? `return ${handler.value}.apply(null, arguments)`
  5576. : isFunctionExpression
  5577. ? `return (${handler.value}).apply(null, arguments)`
  5578. : isFunctionInvocation
  5579. ? `return ${handler.value}`
  5580. : handler.value;
  5581. return `function($event){${code}${handlerCode}}`;
  5582. }
  5583. }
  5584. function genKeyFilter(keys) {
  5585. return (
  5586. // make sure the key filters only apply to KeyboardEvents
  5587. // #9441: can't use 'keyCode' in $event because Chrome autofill fires fake
  5588. // key events that do not have keyCode property...
  5589. `if(!$event.type.indexOf('key')&&` +
  5590. `${keys.map(genFilterCode).join('&&')})return null;`);
  5591. }
  5592. function genFilterCode(key) {
  5593. const keyVal = parseInt(key, 10);
  5594. if (keyVal) {
  5595. return `$event.keyCode!==${keyVal}`;
  5596. }
  5597. const keyCode = keyCodes[key];
  5598. const keyName = keyNames[key];
  5599. return (`_k($event.keyCode,` +
  5600. `${JSON.stringify(key)},` +
  5601. `${JSON.stringify(keyCode)},` +
  5602. `$event.key,` +
  5603. `${JSON.stringify(keyName)}` +
  5604. `)`);
  5605. }
  5606. function on(el, dir) {
  5607. if (dir.modifiers) {
  5608. warn$2(`v-on without argument does not support modifiers.`);
  5609. }
  5610. el.wrapListeners = (code) => `_g(${code},${dir.value})`;
  5611. }
  5612. function bind(el, dir) {
  5613. el.wrapData = (code) => {
  5614. return `_b(${code},'${el.tag}',${dir.value},${dir.modifiers && dir.modifiers.prop ? 'true' : 'false'}${dir.modifiers && dir.modifiers.sync ? ',true' : ''})`;
  5615. };
  5616. }
  5617. var baseDirectives = {
  5618. on,
  5619. bind,
  5620. cloak: noop$1
  5621. };
  5622. class CodegenState {
  5623. constructor(options) {
  5624. this.options = options;
  5625. this.warn = options.warn || baseWarn;
  5626. this.transforms = pluckModuleFunction(options.modules, 'transformCode');
  5627. this.dataGenFns = pluckModuleFunction(options.modules, 'genData');
  5628. this.directives = extend(extend({}, baseDirectives), options.directives);
  5629. const isReservedTag = options.isReservedTag || no;
  5630. this.maybeComponent = (el) => !!el.component || !isReservedTag(el.tag);
  5631. this.onceId = 0;
  5632. this.staticRenderFns = [];
  5633. this.pre = false;
  5634. }
  5635. }
  5636. function generate$1(ast, options) {
  5637. const state = new CodegenState(options);
  5638. // fix #11483, Root level <script> tags should not be rendered.
  5639. const code = ast
  5640. ? ast.tag === 'script'
  5641. ? 'null'
  5642. : genElement(ast, state)
  5643. : '_c("div")';
  5644. return {
  5645. render: `with(this){return ${code}}`,
  5646. staticRenderFns: state.staticRenderFns
  5647. };
  5648. }
  5649. function genElement(el, state) {
  5650. if (el.parent) {
  5651. el.pre = el.pre || el.parent.pre;
  5652. }
  5653. if (el.staticRoot && !el.staticProcessed) {
  5654. return genStatic(el, state);
  5655. }
  5656. else if (el.once && !el.onceProcessed) {
  5657. return genOnce(el, state);
  5658. }
  5659. else if (el.for && !el.forProcessed) {
  5660. return genFor(el, state);
  5661. }
  5662. else if (el.if && !el.ifProcessed) {
  5663. return genIf(el, state);
  5664. }
  5665. else if (el.tag === 'template' && !el.slotTarget && !state.pre) {
  5666. return genChildren(el, state) || 'void 0';
  5667. }
  5668. else if (el.tag === 'slot') {
  5669. return genSlot(el, state);
  5670. }
  5671. else {
  5672. // component or element
  5673. let code;
  5674. if (el.component) {
  5675. code = genComponent(el.component, el, state);
  5676. }
  5677. else {
  5678. let data;
  5679. const maybeComponent = state.maybeComponent(el);
  5680. if (!el.plain || (el.pre && maybeComponent)) {
  5681. data = genData(el, state);
  5682. }
  5683. let tag;
  5684. // check if this is a component in <script setup>
  5685. const bindings = state.options.bindings;
  5686. if (maybeComponent && bindings && bindings.__isScriptSetup !== false) {
  5687. tag = checkBindingType(bindings, el.tag);
  5688. }
  5689. if (!tag)
  5690. tag = `'${el.tag}'`;
  5691. const children = el.inlineTemplate ? null : genChildren(el, state, true);
  5692. code = `_c(${tag}${data ? `,${data}` : '' // data
  5693. }${children ? `,${children}` : '' // children
  5694. })`;
  5695. }
  5696. // module transforms
  5697. for (let i = 0; i < state.transforms.length; i++) {
  5698. code = state.transforms[i](el, code);
  5699. }
  5700. return code;
  5701. }
  5702. }
  5703. function checkBindingType(bindings, key) {
  5704. const camelName = camelize(key);
  5705. const PascalName = capitalize(camelName);
  5706. const checkType = (type) => {
  5707. if (bindings[key] === type) {
  5708. return key;
  5709. }
  5710. if (bindings[camelName] === type) {
  5711. return camelName;
  5712. }
  5713. if (bindings[PascalName] === type) {
  5714. return PascalName;
  5715. }
  5716. };
  5717. const fromConst = checkType("setup-const" /* BindingTypes.SETUP_CONST */) ||
  5718. checkType("setup-reactive-const" /* BindingTypes.SETUP_REACTIVE_CONST */);
  5719. if (fromConst) {
  5720. return fromConst;
  5721. }
  5722. const fromMaybeRef = checkType("setup-let" /* BindingTypes.SETUP_LET */) ||
  5723. checkType("setup-ref" /* BindingTypes.SETUP_REF */) ||
  5724. checkType("setup-maybe-ref" /* BindingTypes.SETUP_MAYBE_REF */);
  5725. if (fromMaybeRef) {
  5726. return fromMaybeRef;
  5727. }
  5728. }
  5729. // hoist static sub-trees out
  5730. function genStatic(el, state) {
  5731. el.staticProcessed = true;
  5732. // Some elements (templates) need to behave differently inside of a v-pre
  5733. // node. All pre nodes are static roots, so we can use this as a location to
  5734. // wrap a state change and reset it upon exiting the pre node.
  5735. const originalPreState = state.pre;
  5736. if (el.pre) {
  5737. state.pre = el.pre;
  5738. }
  5739. state.staticRenderFns.push(`with(this){return ${genElement(el, state)}}`);
  5740. state.pre = originalPreState;
  5741. return `_m(${state.staticRenderFns.length - 1}${el.staticInFor ? ',true' : ''})`;
  5742. }
  5743. // v-once
  5744. function genOnce(el, state) {
  5745. el.onceProcessed = true;
  5746. if (el.if && !el.ifProcessed) {
  5747. return genIf(el, state);
  5748. }
  5749. else if (el.staticInFor) {
  5750. let key = '';
  5751. let parent = el.parent;
  5752. while (parent) {
  5753. if (parent.for) {
  5754. key = parent.key;
  5755. break;
  5756. }
  5757. parent = parent.parent;
  5758. }
  5759. if (!key) {
  5760. state.warn(`v-once can only be used inside v-for that is keyed. `, el.rawAttrsMap['v-once']);
  5761. return genElement(el, state);
  5762. }
  5763. return `_o(${genElement(el, state)},${state.onceId++},${key})`;
  5764. }
  5765. else {
  5766. return genStatic(el, state);
  5767. }
  5768. }
  5769. function genIf(el, state, altGen, altEmpty) {
  5770. el.ifProcessed = true; // avoid recursion
  5771. return genIfConditions(el.ifConditions.slice(), state, altGen, altEmpty);
  5772. }
  5773. function genIfConditions(conditions, state, altGen, altEmpty) {
  5774. if (!conditions.length) {
  5775. return altEmpty || '_e()';
  5776. }
  5777. const condition = conditions.shift();
  5778. if (condition.exp) {
  5779. return `(${condition.exp})?${genTernaryExp(condition.block)}:${genIfConditions(conditions, state, altGen, altEmpty)}`;
  5780. }
  5781. else {
  5782. return `${genTernaryExp(condition.block)}`;
  5783. }
  5784. // v-if with v-once should generate code like (a)?_m(0):_m(1)
  5785. function genTernaryExp(el) {
  5786. return altGen
  5787. ? altGen(el, state)
  5788. : el.once
  5789. ? genOnce(el, state)
  5790. : genElement(el, state);
  5791. }
  5792. }
  5793. function genFor(el, state, altGen, altHelper) {
  5794. const exp = el.for;
  5795. const alias = el.alias;
  5796. const iterator1 = el.iterator1 ? `,${el.iterator1}` : '';
  5797. const iterator2 = el.iterator2 ? `,${el.iterator2}` : '';
  5798. if (state.maybeComponent(el) &&
  5799. el.tag !== 'slot' &&
  5800. el.tag !== 'template' &&
  5801. !el.key) {
  5802. state.warn(`<${el.tag} v-for="${alias} in ${exp}">: component lists rendered with ` +
  5803. `v-for should have explicit keys. ` +
  5804. `See https://vuejs.org/guide/list.html#key for more info.`, el.rawAttrsMap['v-for'], true /* tip */);
  5805. }
  5806. el.forProcessed = true; // avoid recursion
  5807. return (`${altHelper || '_l'}((${exp}),` +
  5808. `function(${alias}${iterator1}${iterator2}){` +
  5809. `return ${(altGen || genElement)(el, state)}` +
  5810. '})');
  5811. }
  5812. function genData(el, state) {
  5813. let data = '{';
  5814. // directives first.
  5815. // directives may mutate the el's other properties before they are generated.
  5816. const dirs = genDirectives(el, state);
  5817. if (dirs)
  5818. data += dirs + ',';
  5819. // key
  5820. if (el.key) {
  5821. data += `key:${el.key},`;
  5822. }
  5823. // ref
  5824. if (el.ref) {
  5825. data += `ref:${el.ref},`;
  5826. }
  5827. if (el.refInFor) {
  5828. data += `refInFor:true,`;
  5829. }
  5830. // pre
  5831. if (el.pre) {
  5832. data += `pre:true,`;
  5833. }
  5834. // record original tag name for components using "is" attribute
  5835. if (el.component) {
  5836. data += `tag:"${el.tag}",`;
  5837. }
  5838. // module data generation functions
  5839. for (let i = 0; i < state.dataGenFns.length; i++) {
  5840. data += state.dataGenFns[i](el);
  5841. }
  5842. // attributes
  5843. if (el.attrs) {
  5844. data += `attrs:${genProps(el.attrs)},`;
  5845. }
  5846. // DOM props
  5847. if (el.props) {
  5848. data += `domProps:${genProps(el.props)},`;
  5849. }
  5850. // event handlers
  5851. if (el.events) {
  5852. data += `${genHandlers(el.events, false)},`;
  5853. }
  5854. if (el.nativeEvents) {
  5855. data += `${genHandlers(el.nativeEvents, true)},`;
  5856. }
  5857. // slot target
  5858. // only for non-scoped slots
  5859. if (el.slotTarget && !el.slotScope) {
  5860. data += `slot:${el.slotTarget},`;
  5861. }
  5862. // scoped slots
  5863. if (el.scopedSlots) {
  5864. data += `${genScopedSlots(el, el.scopedSlots, state)},`;
  5865. }
  5866. // component v-model
  5867. if (el.model) {
  5868. data += `model:{value:${el.model.value},callback:${el.model.callback},expression:${el.model.expression}},`;
  5869. }
  5870. // inline-template
  5871. if (el.inlineTemplate) {
  5872. const inlineTemplate = genInlineTemplate(el, state);
  5873. if (inlineTemplate) {
  5874. data += `${inlineTemplate},`;
  5875. }
  5876. }
  5877. data = data.replace(/,$/, '') + '}';
  5878. // v-bind dynamic argument wrap
  5879. // v-bind with dynamic arguments must be applied using the same v-bind object
  5880. // merge helper so that class/style/mustUseProp attrs are handled correctly.
  5881. if (el.dynamicAttrs) {
  5882. data = `_b(${data},"${el.tag}",${genProps(el.dynamicAttrs)})`;
  5883. }
  5884. // v-bind data wrap
  5885. if (el.wrapData) {
  5886. data = el.wrapData(data);
  5887. }
  5888. // v-on data wrap
  5889. if (el.wrapListeners) {
  5890. data = el.wrapListeners(data);
  5891. }
  5892. return data;
  5893. }
  5894. function genDirectives(el, state) {
  5895. const dirs = el.directives;
  5896. if (!dirs)
  5897. return;
  5898. let res = 'directives:[';
  5899. let hasRuntime = false;
  5900. let i, l, dir, needRuntime;
  5901. for (i = 0, l = dirs.length; i < l; i++) {
  5902. dir = dirs[i];
  5903. needRuntime = true;
  5904. const gen = state.directives[dir.name];
  5905. if (gen) {
  5906. // compile-time directive that manipulates AST.
  5907. // returns true if it also needs a runtime counterpart.
  5908. needRuntime = !!gen(el, dir, state.warn);
  5909. }
  5910. if (needRuntime) {
  5911. hasRuntime = true;
  5912. res += `{name:"${dir.name}",rawName:"${dir.rawName}"${dir.value
  5913. ? `,value:(${dir.value}),expression:${JSON.stringify(dir.value)}`
  5914. : ''}${dir.arg ? `,arg:${dir.isDynamicArg ? dir.arg : `"${dir.arg}"`}` : ''}${dir.modifiers ? `,modifiers:${JSON.stringify(dir.modifiers)}` : ''}},`;
  5915. }
  5916. }
  5917. if (hasRuntime) {
  5918. return res.slice(0, -1) + ']';
  5919. }
  5920. }
  5921. function genInlineTemplate(el, state) {
  5922. const ast = el.children[0];
  5923. if ((el.children.length !== 1 || ast.type !== 1)) {
  5924. state.warn('Inline-template components must have exactly one child element.', { start: el.start });
  5925. }
  5926. if (ast && ast.type === 1) {
  5927. const inlineRenderFns = generate$1(ast, state.options);
  5928. return `inlineTemplate:{render:function(){${inlineRenderFns.render}},staticRenderFns:[${inlineRenderFns.staticRenderFns
  5929. .map(code => `function(){${code}}`)
  5930. .join(',')}]}`;
  5931. }
  5932. }
  5933. function genScopedSlots(el, slots, state) {
  5934. // by default scoped slots are considered "stable", this allows child
  5935. // components with only scoped slots to skip forced updates from parent.
  5936. // but in some cases we have to bail-out of this optimization
  5937. // for example if the slot contains dynamic names, has v-if or v-for on them...
  5938. let needsForceUpdate = el.for ||
  5939. Object.keys(slots).some(key => {
  5940. const slot = slots[key];
  5941. return (slot.slotTargetDynamic || slot.if || slot.for || containsSlotChild(slot) // is passing down slot from parent which may be dynamic
  5942. );
  5943. });
  5944. // #9534: if a component with scoped slots is inside a conditional branch,
  5945. // it's possible for the same component to be reused but with different
  5946. // compiled slot content. To avoid that, we generate a unique key based on
  5947. // the generated code of all the slot contents.
  5948. let needsKey = !!el.if;
  5949. // OR when it is inside another scoped slot or v-for (the reactivity may be
  5950. // disconnected due to the intermediate scope variable)
  5951. // #9438, #9506
  5952. // TODO: this can be further optimized by properly analyzing in-scope bindings
  5953. // and skip force updating ones that do not actually use scope variables.
  5954. if (!needsForceUpdate) {
  5955. let parent = el.parent;
  5956. while (parent) {
  5957. if ((parent.slotScope && parent.slotScope !== emptySlotScopeToken) ||
  5958. parent.for) {
  5959. needsForceUpdate = true;
  5960. break;
  5961. }
  5962. if (parent.if) {
  5963. needsKey = true;
  5964. }
  5965. parent = parent.parent;
  5966. }
  5967. }
  5968. const generatedSlots = Object.keys(slots)
  5969. .map(key => genScopedSlot(slots[key], state))
  5970. .join(',');
  5971. return `scopedSlots:_u([${generatedSlots}]${needsForceUpdate ? `,null,true` : ``}${!needsForceUpdate && needsKey ? `,null,false,${hash(generatedSlots)}` : ``})`;
  5972. }
  5973. function hash(str) {
  5974. let hash = 5381;
  5975. let i = str.length;
  5976. while (i) {
  5977. hash = (hash * 33) ^ str.charCodeAt(--i);
  5978. }
  5979. return hash >>> 0;
  5980. }
  5981. function containsSlotChild(el) {
  5982. if (el.type === 1) {
  5983. if (el.tag === 'slot') {
  5984. return true;
  5985. }
  5986. return el.children.some(containsSlotChild);
  5987. }
  5988. return false;
  5989. }
  5990. function genScopedSlot(el, state) {
  5991. const isLegacySyntax = el.attrsMap['slot-scope'];
  5992. if (el.if && !el.ifProcessed && !isLegacySyntax) {
  5993. return genIf(el, state, genScopedSlot, `null`);
  5994. }
  5995. if (el.for && !el.forProcessed) {
  5996. return genFor(el, state, genScopedSlot);
  5997. }
  5998. const slotScope = el.slotScope === emptySlotScopeToken ? `` : String(el.slotScope);
  5999. const fn = `function(${slotScope}){` +
  6000. `return ${el.tag === 'template'
  6001. ? el.if && isLegacySyntax
  6002. ? `(${el.if})?${genChildren(el, state) || 'undefined'}:undefined`
  6003. : genChildren(el, state) || 'undefined'
  6004. : genElement(el, state)}}`;
  6005. // reverse proxy v-slot without scope on this.$slots
  6006. const reverseProxy = slotScope ? `` : `,proxy:true`;
  6007. return `{key:${el.slotTarget || `"default"`},fn:${fn}${reverseProxy}}`;
  6008. }
  6009. function genChildren(el, state, checkSkip, altGenElement, altGenNode) {
  6010. const children = el.children;
  6011. if (children.length) {
  6012. const el = children[0];
  6013. // optimize single v-for
  6014. if (children.length === 1 &&
  6015. el.for &&
  6016. el.tag !== 'template' &&
  6017. el.tag !== 'slot') {
  6018. const normalizationType = checkSkip
  6019. ? state.maybeComponent(el)
  6020. ? `,1`
  6021. : `,0`
  6022. : ``;
  6023. return `${(altGenElement || genElement)(el, state)}${normalizationType}`;
  6024. }
  6025. const normalizationType = checkSkip
  6026. ? getNormalizationType(children, state.maybeComponent)
  6027. : 0;
  6028. const gen = altGenNode || genNode;
  6029. return `[${children.map(c => gen(c, state)).join(',')}]${normalizationType ? `,${normalizationType}` : ''}`;
  6030. }
  6031. }
  6032. // determine the normalization needed for the children array.
  6033. // 0: no normalization needed
  6034. // 1: simple normalization needed (possible 1-level deep nested array)
  6035. // 2: full normalization needed
  6036. function getNormalizationType(children, maybeComponent) {
  6037. let res = 0;
  6038. for (let i = 0; i < children.length; i++) {
  6039. const el = children[i];
  6040. if (el.type !== 1) {
  6041. continue;
  6042. }
  6043. if (needsNormalization(el) ||
  6044. (el.ifConditions &&
  6045. el.ifConditions.some(c => needsNormalization(c.block)))) {
  6046. res = 2;
  6047. break;
  6048. }
  6049. if (maybeComponent(el) ||
  6050. (el.ifConditions && el.ifConditions.some(c => maybeComponent(c.block)))) {
  6051. res = 1;
  6052. }
  6053. }
  6054. return res;
  6055. }
  6056. function needsNormalization(el) {
  6057. return el.for !== undefined || el.tag === 'template' || el.tag === 'slot';
  6058. }
  6059. function genNode(node, state) {
  6060. if (node.type === 1) {
  6061. return genElement(node, state);
  6062. }
  6063. else if (node.type === 3 && node.isComment) {
  6064. return genComment(node);
  6065. }
  6066. else {
  6067. return genText(node);
  6068. }
  6069. }
  6070. function genText(text) {
  6071. return `_v(${text.type === 2
  6072. ? text.expression // no need for () because already wrapped in _s()
  6073. : transformSpecialNewlines(JSON.stringify(text.text))})`;
  6074. }
  6075. function genComment(comment) {
  6076. return `_e(${JSON.stringify(comment.text)})`;
  6077. }
  6078. function genSlot(el, state) {
  6079. const slotName = el.slotName || '"default"';
  6080. const children = genChildren(el, state);
  6081. let res = `_t(${slotName}${children ? `,function(){return ${children}}` : ''}`;
  6082. const attrs = el.attrs || el.dynamicAttrs
  6083. ? genProps((el.attrs || []).concat(el.dynamicAttrs || []).map(attr => ({
  6084. // slot props are camelized
  6085. name: camelize(attr.name),
  6086. value: attr.value,
  6087. dynamic: attr.dynamic
  6088. })))
  6089. : null;
  6090. const bind = el.attrsMap['v-bind'];
  6091. if ((attrs || bind) && !children) {
  6092. res += `,null`;
  6093. }
  6094. if (attrs) {
  6095. res += `,${attrs}`;
  6096. }
  6097. if (bind) {
  6098. res += `${attrs ? '' : ',null'},${bind}`;
  6099. }
  6100. return res + ')';
  6101. }
  6102. // componentName is el.component, take it as argument to shun flow's pessimistic refinement
  6103. function genComponent(componentName, el, state) {
  6104. const children = el.inlineTemplate ? null : genChildren(el, state, true);
  6105. return `_c(${componentName},${genData(el, state)}${children ? `,${children}` : ''})`;
  6106. }
  6107. function genProps(props) {
  6108. let staticProps = ``;
  6109. let dynamicProps = ``;
  6110. for (let i = 0; i < props.length; i++) {
  6111. const prop = props[i];
  6112. const value = transformSpecialNewlines(prop.value);
  6113. if (prop.dynamic) {
  6114. dynamicProps += `${prop.name},${value},`;
  6115. }
  6116. else {
  6117. staticProps += `"${prop.name}":${value},`;
  6118. }
  6119. }
  6120. staticProps = `{${staticProps.slice(0, -1)}}`;
  6121. if (dynamicProps) {
  6122. return `_d(${staticProps},[${dynamicProps.slice(0, -1)}])`;
  6123. }
  6124. else {
  6125. return staticProps;
  6126. }
  6127. }
  6128. // #3895, #4268
  6129. function transformSpecialNewlines(text) {
  6130. return text.replace(/\u2028/g, '\\u2028').replace(/\u2029/g, '\\u2029');
  6131. }
  6132. const plainStringRE = /^"(?:[^"\\]|\\.)*"$|^'(?:[^'\\]|\\.)*'$/;
  6133. // let the model AST transform translate v-model into appropriate
  6134. // props bindings
  6135. function applyModelTransform(el, state) {
  6136. if (el.directives) {
  6137. for (let i = 0; i < el.directives.length; i++) {
  6138. const dir = el.directives[i];
  6139. if (dir.name === 'model') {
  6140. state.directives.model(el, dir, state.warn);
  6141. // remove value for textarea as its converted to text
  6142. if (el.tag === 'textarea' && el.props) {
  6143. el.props = el.props.filter(p => p.name !== 'value');
  6144. }
  6145. break;
  6146. }
  6147. }
  6148. }
  6149. }
  6150. function genAttrSegments(attrs) {
  6151. return attrs.map(({ name, value }) => genAttrSegment(name, value));
  6152. }
  6153. function genDOMPropSegments(props, attrs) {
  6154. const segments = [];
  6155. props.forEach(({ name, value }) => {
  6156. name = propsToAttrMap[name] || name.toLowerCase();
  6157. if (isRenderableAttr(name) &&
  6158. !(attrs && attrs.some(a => a.name === name))) {
  6159. segments.push(genAttrSegment(name, value));
  6160. }
  6161. });
  6162. return segments;
  6163. }
  6164. function genAttrSegment(name, value) {
  6165. if (plainStringRE.test(value)) {
  6166. // force double quote
  6167. value = value.replace(/^'|'$/g, '"');
  6168. // force enumerated attr to "true"
  6169. if (isEnumeratedAttr(name) && value !== `"false"`) {
  6170. value = `"true"`;
  6171. }
  6172. return {
  6173. type: RAW,
  6174. value: isBooleanAttr(name)
  6175. ? ` ${name}="${name}"`
  6176. : value === '""'
  6177. ? ` ${name}`
  6178. : ` ${name}="${JSON.parse(value)}"`
  6179. };
  6180. }
  6181. else {
  6182. return {
  6183. type: EXPRESSION,
  6184. value: `_ssrAttr(${JSON.stringify(name)},${value})`
  6185. };
  6186. }
  6187. }
  6188. function genClassSegments(staticClass, classBinding) {
  6189. if (staticClass && !classBinding) {
  6190. return [{ type: RAW, value: ` class="${JSON.parse(staticClass)}"` }];
  6191. }
  6192. else {
  6193. return [
  6194. {
  6195. type: EXPRESSION,
  6196. value: `_ssrClass(${staticClass || 'null'},${classBinding || 'null'})`
  6197. }
  6198. ];
  6199. }
  6200. }
  6201. function genStyleSegments(staticStyle, parsedStaticStyle, styleBinding, vShowExpression) {
  6202. if (staticStyle && !styleBinding && !vShowExpression) {
  6203. return [{ type: RAW, value: ` style=${JSON.stringify(staticStyle)}` }];
  6204. }
  6205. else {
  6206. return [
  6207. {
  6208. type: EXPRESSION,
  6209. value: `_ssrStyle(${parsedStaticStyle || 'null'},${styleBinding || 'null'}, ${vShowExpression
  6210. ? `{ display: (${vShowExpression}) ? '' : 'none' }`
  6211. : 'null'})`
  6212. }
  6213. ];
  6214. }
  6215. }
  6216. /**
  6217. * In SSR, the vdom tree is generated only once and never patched, so
  6218. * we can optimize most element / trees into plain string render functions.
  6219. * The SSR optimizer walks the AST tree to detect optimizable elements and trees.
  6220. *
  6221. * The criteria for SSR optimizability is quite a bit looser than static tree
  6222. * detection (which is designed for client re-render). In SSR we bail only for
  6223. * components/slots/custom directives.
  6224. */
  6225. // optimizability constants
  6226. const optimizability = {
  6227. FALSE: 0,
  6228. FULL: 1,
  6229. SELF: 2,
  6230. CHILDREN: 3,
  6231. PARTIAL: 4 // self un-optimizable with some un-optimizable children
  6232. };
  6233. let isPlatformReservedTag;
  6234. function optimize(root, options) {
  6235. if (!root)
  6236. return;
  6237. isPlatformReservedTag = options.isReservedTag || no;
  6238. walk(root, true);
  6239. }
  6240. function walk(node, isRoot) {
  6241. if (isUnOptimizableTree(node)) {
  6242. node.ssrOptimizability = optimizability.FALSE;
  6243. return;
  6244. }
  6245. // root node or nodes with custom directives should always be a VNode
  6246. const selfUnoptimizable = isRoot || hasCustomDirective(node);
  6247. const check = child => {
  6248. if (child.ssrOptimizability !== optimizability.FULL) {
  6249. node.ssrOptimizability = selfUnoptimizable
  6250. ? optimizability.PARTIAL
  6251. : optimizability.SELF;
  6252. }
  6253. };
  6254. if (selfUnoptimizable) {
  6255. node.ssrOptimizability = optimizability.CHILDREN;
  6256. }
  6257. if (node.type === 1) {
  6258. for (let i = 0, l = node.children.length; i < l; i++) {
  6259. const child = node.children[i];
  6260. walk(child);
  6261. check(child);
  6262. }
  6263. if (node.ifConditions) {
  6264. for (let i = 1, l = node.ifConditions.length; i < l; i++) {
  6265. const block = node.ifConditions[i].block;
  6266. walk(block, isRoot);
  6267. check(block);
  6268. }
  6269. }
  6270. if (node.ssrOptimizability == null ||
  6271. (!isRoot && (node.attrsMap['v-html'] || node.attrsMap['v-text']))) {
  6272. node.ssrOptimizability = optimizability.FULL;
  6273. }
  6274. else {
  6275. node.children = optimizeSiblings(node);
  6276. }
  6277. }
  6278. else {
  6279. node.ssrOptimizability = optimizability.FULL;
  6280. }
  6281. }
  6282. function optimizeSiblings(el) {
  6283. const children = el.children;
  6284. const optimizedChildren = [];
  6285. let currentOptimizableGroup = [];
  6286. const pushGroup = () => {
  6287. if (currentOptimizableGroup.length) {
  6288. optimizedChildren.push({
  6289. type: 1,
  6290. parent: el,
  6291. tag: 'template',
  6292. attrsList: [],
  6293. attrsMap: {},
  6294. rawAttrsMap: {},
  6295. children: currentOptimizableGroup,
  6296. ssrOptimizability: optimizability.FULL
  6297. });
  6298. }
  6299. currentOptimizableGroup = [];
  6300. };
  6301. for (let i = 0; i < children.length; i++) {
  6302. const c = children[i];
  6303. if (c.ssrOptimizability === optimizability.FULL) {
  6304. currentOptimizableGroup.push(c);
  6305. }
  6306. else {
  6307. // wrap fully-optimizable adjacent siblings inside a template tag
  6308. // so that they can be optimized into a single ssrNode by codegen
  6309. pushGroup();
  6310. optimizedChildren.push(c);
  6311. }
  6312. }
  6313. pushGroup();
  6314. return optimizedChildren;
  6315. }
  6316. function isUnOptimizableTree(node) {
  6317. if (node.type === 2 || node.type === 3) {
  6318. // text or expression
  6319. return false;
  6320. }
  6321. return (isBuiltInTag(node.tag) || // built-in (slot, component)
  6322. !isPlatformReservedTag(node.tag) || // custom component
  6323. !!node.component || // "is" component
  6324. isSelectWithModel(node) // <select v-model> requires runtime inspection
  6325. );
  6326. }
  6327. const isBuiltInDir = makeMap('text,html,show,on,bind,model,pre,cloak,once');
  6328. function hasCustomDirective(node) {
  6329. return (node.type === 1 &&
  6330. node.directives &&
  6331. node.directives.some(d => !isBuiltInDir(d.name)));
  6332. }
  6333. // <select v-model> cannot be optimized because it requires a runtime check
  6334. // to determine proper selected option
  6335. function isSelectWithModel(node) {
  6336. return (node.type === 1 &&
  6337. node.tag === 'select' &&
  6338. node.directives != null &&
  6339. node.directives.some(d => d.name === 'model'));
  6340. }
  6341. // The SSR codegen is essentially extending the default codegen to handle
  6342. // segment types
  6343. const RAW = 0;
  6344. const INTERPOLATION = 1;
  6345. const EXPRESSION = 2;
  6346. function generate(ast, options) {
  6347. const state = new CodegenState(options);
  6348. const code = ast ? genSSRElement(ast, state) : '_c("div")';
  6349. return {
  6350. render: `with(this){return ${code}}`,
  6351. staticRenderFns: state.staticRenderFns
  6352. };
  6353. }
  6354. function genSSRElement(el, state) {
  6355. if (el.for && !el.forProcessed) {
  6356. return genFor(el, state, genSSRElement);
  6357. }
  6358. else if (el.if && !el.ifProcessed) {
  6359. return genIf(el, state, genSSRElement);
  6360. }
  6361. else if (el.tag === 'template' && !el.slotTarget) {
  6362. return el.ssrOptimizability === optimizability.FULL
  6363. ? genChildrenAsStringNode(el, state)
  6364. : genSSRChildren(el, state) || 'void 0';
  6365. }
  6366. switch (el.ssrOptimizability) {
  6367. case optimizability.FULL:
  6368. // stringify whole tree
  6369. return genStringElement(el, state);
  6370. case optimizability.SELF:
  6371. // stringify self and check children
  6372. return genStringElementWithChildren(el, state);
  6373. case optimizability.CHILDREN:
  6374. // generate self as VNode and stringify children
  6375. return genNormalElement(el, state, true);
  6376. case optimizability.PARTIAL:
  6377. // generate self as VNode and check children
  6378. return genNormalElement(el, state, false);
  6379. default:
  6380. // bail whole tree
  6381. return genElement(el, state);
  6382. }
  6383. }
  6384. function genNormalElement(el, state, stringifyChildren) {
  6385. const data = el.plain ? undefined : genData(el, state);
  6386. const children = stringifyChildren
  6387. ? `[${genChildrenAsStringNode(el, state)}]`
  6388. : genSSRChildren(el, state, true);
  6389. return `_c('${el.tag}'${data ? `,${data}` : ''}${children ? `,${children}` : ''})`;
  6390. }
  6391. function genSSRChildren(el, state, checkSkip) {
  6392. return genChildren(el, state, checkSkip, genSSRElement, genSSRNode);
  6393. }
  6394. function genSSRNode(el, state) {
  6395. return el.type === 1 ? genSSRElement(el, state) : genText(el);
  6396. }
  6397. function genChildrenAsStringNode(el, state) {
  6398. return el.children.length
  6399. ? `_ssrNode(${flattenSegments(childrenToSegments(el, state))})`
  6400. : '';
  6401. }
  6402. function genStringElement(el, state) {
  6403. return `_ssrNode(${elementToString(el, state)})`;
  6404. }
  6405. function genStringElementWithChildren(el, state) {
  6406. const children = genSSRChildren(el, state, true);
  6407. return `_ssrNode(${flattenSegments(elementToOpenTagSegments(el, state))},"</${el.tag}>"${children ? `,${children}` : ''})`;
  6408. }
  6409. function elementToString(el, state) {
  6410. return `(${flattenSegments(elementToSegments(el, state))})`;
  6411. }
  6412. function elementToSegments(el, state) {
  6413. // v-for / v-if
  6414. if (el.for && !el.forProcessed) {
  6415. el.forProcessed = true;
  6416. return [
  6417. {
  6418. type: EXPRESSION,
  6419. value: genFor(el, state, elementToString, '_ssrList')
  6420. }
  6421. ];
  6422. }
  6423. else if (el.if && !el.ifProcessed) {
  6424. el.ifProcessed = true;
  6425. return [
  6426. {
  6427. type: EXPRESSION,
  6428. value: genIf(el, state, elementToString, '"<!---->"')
  6429. }
  6430. ];
  6431. }
  6432. else if (el.tag === 'template') {
  6433. return childrenToSegments(el, state);
  6434. }
  6435. const openSegments = elementToOpenTagSegments(el, state);
  6436. const childrenSegments = childrenToSegments(el, state);
  6437. const { isUnaryTag } = state.options;
  6438. const close = isUnaryTag && isUnaryTag(el.tag)
  6439. ? []
  6440. : [{ type: RAW, value: `</${el.tag}>` }];
  6441. return openSegments.concat(childrenSegments, close);
  6442. }
  6443. function elementToOpenTagSegments(el, state) {
  6444. applyModelTransform(el, state);
  6445. let binding;
  6446. const segments = [{ type: RAW, value: `<${el.tag}` }];
  6447. // attrs
  6448. if (el.attrs) {
  6449. segments.push.apply(segments, genAttrSegments(el.attrs));
  6450. }
  6451. // domProps
  6452. if (el.props) {
  6453. segments.push.apply(segments, genDOMPropSegments(el.props, el.attrs));
  6454. }
  6455. // v-bind="object"
  6456. if ((binding = el.attrsMap['v-bind'])) {
  6457. segments.push({ type: EXPRESSION, value: `_ssrAttrs(${binding})` });
  6458. }
  6459. // v-bind.prop="object"
  6460. if ((binding = el.attrsMap['v-bind.prop'])) {
  6461. segments.push({ type: EXPRESSION, value: `_ssrDOMProps(${binding})` });
  6462. }
  6463. // class
  6464. if (el.staticClass || el.classBinding) {
  6465. segments.push.apply(segments, genClassSegments(el.staticClass, el.classBinding));
  6466. }
  6467. // style & v-show
  6468. if (el.staticStyle || el.styleBinding || el.attrsMap['v-show']) {
  6469. segments.push.apply(segments, genStyleSegments(el.attrsMap.style, el.staticStyle, el.styleBinding, el.attrsMap['v-show']));
  6470. }
  6471. // _scopedId
  6472. if (state.options.scopeId) {
  6473. segments.push({ type: RAW, value: ` ${state.options.scopeId}` });
  6474. }
  6475. segments.push({ type: RAW, value: `>` });
  6476. return segments;
  6477. }
  6478. function childrenToSegments(el, state) {
  6479. let binding;
  6480. if ((binding = el.attrsMap['v-html'])) {
  6481. return [{ type: EXPRESSION, value: `_s(${binding})` }];
  6482. }
  6483. if ((binding = el.attrsMap['v-text'])) {
  6484. return [{ type: INTERPOLATION, value: `_s(${binding})` }];
  6485. }
  6486. if (el.tag === 'textarea' && (binding = el.attrsMap['v-model'])) {
  6487. return [{ type: INTERPOLATION, value: `_s(${binding})` }];
  6488. }
  6489. return el.children ? nodesToSegments(el.children, state) : [];
  6490. }
  6491. function nodesToSegments(children, state) {
  6492. const segments = [];
  6493. for (let i = 0; i < children.length; i++) {
  6494. const c = children[i];
  6495. if (c.type === 1) {
  6496. segments.push.apply(segments, elementToSegments(c, state));
  6497. }
  6498. else if (c.type === 2) {
  6499. segments.push({ type: INTERPOLATION, value: c.expression });
  6500. }
  6501. else if (c.type === 3) {
  6502. let text = escape(c.text);
  6503. if (c.isComment) {
  6504. text = '<!--' + text + '-->';
  6505. }
  6506. segments.push({ type: RAW, value: text });
  6507. }
  6508. }
  6509. return segments;
  6510. }
  6511. function flattenSegments(segments) {
  6512. const mergedSegments = [];
  6513. let textBuffer = '';
  6514. const pushBuffer = () => {
  6515. if (textBuffer) {
  6516. mergedSegments.push(JSON.stringify(textBuffer));
  6517. textBuffer = '';
  6518. }
  6519. };
  6520. for (let i = 0; i < segments.length; i++) {
  6521. const s = segments[i];
  6522. if (s.type === RAW) {
  6523. textBuffer += s.value;
  6524. }
  6525. else if (s.type === INTERPOLATION) {
  6526. pushBuffer();
  6527. mergedSegments.push(`_ssrEscape(${s.value})`);
  6528. }
  6529. else if (s.type === EXPRESSION) {
  6530. pushBuffer();
  6531. mergedSegments.push(`(${s.value})`);
  6532. }
  6533. }
  6534. pushBuffer();
  6535. return mergedSegments.join('+');
  6536. }
  6537. // these keywords should not appear inside expressions, but operators like
  6538. // typeof, instanceof and in are allowed
  6539. const prohibitedKeywordRE = new RegExp('\\b' +
  6540. ('do,if,for,let,new,try,var,case,else,with,await,break,catch,class,const,' +
  6541. 'super,throw,while,yield,delete,export,import,return,switch,default,' +
  6542. 'extends,finally,continue,debugger,function,arguments')
  6543. .split(',')
  6544. .join('\\b|\\b') +
  6545. '\\b');
  6546. // these unary operators should not be used as property/method names
  6547. const unaryOperatorsRE = new RegExp('\\b' +
  6548. 'delete,typeof,void'.split(',').join('\\s*\\([^\\)]*\\)|\\b') +
  6549. '\\s*\\([^\\)]*\\)');
  6550. // strip strings in expressions
  6551. const stripStringRE = /'(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*"|`(?:[^`\\]|\\.)*\$\{|\}(?:[^`\\]|\\.)*`|`(?:[^`\\]|\\.)*`/g;
  6552. // detect problematic expressions in a template
  6553. function detectErrors(ast, warn) {
  6554. if (ast) {
  6555. checkNode(ast, warn);
  6556. }
  6557. }
  6558. function checkNode(node, warn) {
  6559. if (node.type === 1) {
  6560. for (const name in node.attrsMap) {
  6561. if (dirRE.test(name)) {
  6562. const value = node.attrsMap[name];
  6563. if (value) {
  6564. const range = node.rawAttrsMap[name];
  6565. if (name === 'v-for') {
  6566. checkFor(node, `v-for="${value}"`, warn, range);
  6567. }
  6568. else if (name === 'v-slot' || name[0] === '#') {
  6569. checkFunctionParameterExpression(value, `${name}="${value}"`, warn, range);
  6570. }
  6571. else if (onRE.test(name)) {
  6572. checkEvent(value, `${name}="${value}"`, warn, range);
  6573. }
  6574. else {
  6575. checkExpression(value, `${name}="${value}"`, warn, range);
  6576. }
  6577. }
  6578. }
  6579. }
  6580. if (node.children) {
  6581. for (let i = 0; i < node.children.length; i++) {
  6582. checkNode(node.children[i], warn);
  6583. }
  6584. }
  6585. }
  6586. else if (node.type === 2) {
  6587. checkExpression(node.expression, node.text, warn, node);
  6588. }
  6589. }
  6590. function checkEvent(exp, text, warn, range) {
  6591. const stripped = exp.replace(stripStringRE, '');
  6592. const keywordMatch = stripped.match(unaryOperatorsRE);
  6593. if (keywordMatch && stripped.charAt(keywordMatch.index - 1) !== '$') {
  6594. warn(`avoid using JavaScript unary operator as property name: ` +
  6595. `"${keywordMatch[0]}" in expression ${text.trim()}`, range);
  6596. }
  6597. checkExpression(exp, text, warn, range);
  6598. }
  6599. function checkFor(node, text, warn, range) {
  6600. checkExpression(node.for || '', text, warn, range);
  6601. checkIdentifier(node.alias, 'v-for alias', text, warn, range);
  6602. checkIdentifier(node.iterator1, 'v-for iterator', text, warn, range);
  6603. checkIdentifier(node.iterator2, 'v-for iterator', text, warn, range);
  6604. }
  6605. function checkIdentifier(ident, type, text, warn, range) {
  6606. if (typeof ident === 'string') {
  6607. try {
  6608. new Function(`var ${ident}=_`);
  6609. }
  6610. catch (e) {
  6611. warn(`invalid ${type} "${ident}" in expression: ${text.trim()}`, range);
  6612. }
  6613. }
  6614. }
  6615. function checkExpression(exp, text, warn, range) {
  6616. try {
  6617. new Function(`return ${exp}`);
  6618. }
  6619. catch (e) {
  6620. const keywordMatch = exp
  6621. .replace(stripStringRE, '')
  6622. .match(prohibitedKeywordRE);
  6623. if (keywordMatch) {
  6624. warn(`avoid using JavaScript keyword as property name: ` +
  6625. `"${keywordMatch[0]}"\n Raw expression: ${text.trim()}`, range);
  6626. }
  6627. else {
  6628. warn(`invalid expression: ${e.message} in\n\n` +
  6629. ` ${exp}\n\n` +
  6630. ` Raw expression: ${text.trim()}\n`, range);
  6631. }
  6632. }
  6633. }
  6634. function checkFunctionParameterExpression(exp, text, warn, range) {
  6635. try {
  6636. new Function(exp, '');
  6637. }
  6638. catch (e) {
  6639. warn(`invalid function parameter expression: ${e.message} in\n\n` +
  6640. ` ${exp}\n\n` +
  6641. ` Raw expression: ${text.trim()}\n`, range);
  6642. }
  6643. }
  6644. const range = 2;
  6645. function generateCodeFrame(source, start = 0, end = source.length) {
  6646. const lines = source.split(/\r?\n/);
  6647. let count = 0;
  6648. const res = [];
  6649. for (let i = 0; i < lines.length; i++) {
  6650. count += lines[i].length + 1;
  6651. if (count >= start) {
  6652. for (let j = i - range; j <= i + range || end > count; j++) {
  6653. if (j < 0 || j >= lines.length)
  6654. continue;
  6655. res.push(`${j + 1}${repeat(` `, 3 - String(j + 1).length)}| ${lines[j]}`);
  6656. const lineLength = lines[j].length;
  6657. if (j === i) {
  6658. // push underline
  6659. const pad = start - (count - lineLength) + 1;
  6660. const length = end > count ? lineLength - pad : end - start;
  6661. res.push(` | ` + repeat(` `, pad) + repeat(`^`, length));
  6662. }
  6663. else if (j > i) {
  6664. if (end > count) {
  6665. const length = Math.min(end - count, lineLength);
  6666. res.push(` | ` + repeat(`^`, length));
  6667. }
  6668. count += lineLength + 1;
  6669. }
  6670. }
  6671. break;
  6672. }
  6673. }
  6674. return res.join('\n');
  6675. }
  6676. function repeat(str, n) {
  6677. let result = '';
  6678. if (n > 0) {
  6679. // eslint-disable-next-line no-constant-condition
  6680. while (true) {
  6681. // eslint-disable-line
  6682. if (n & 1)
  6683. result += str;
  6684. n >>>= 1;
  6685. if (n <= 0)
  6686. break;
  6687. str += str;
  6688. }
  6689. }
  6690. return result;
  6691. }
  6692. function createFunction(code, errors) {
  6693. try {
  6694. return new Function(code);
  6695. }
  6696. catch (err) {
  6697. errors.push({ err, code });
  6698. return noop$1;
  6699. }
  6700. }
  6701. function createCompileToFunctionFn(compile) {
  6702. const cache = Object.create(null);
  6703. return function compileToFunctions(template, options, vm) {
  6704. options = extend({}, options);
  6705. const warn = options.warn || warn$2;
  6706. delete options.warn;
  6707. /* istanbul ignore if */
  6708. {
  6709. // detect possible CSP restriction
  6710. try {
  6711. new Function('return 1');
  6712. }
  6713. catch (e) {
  6714. if (e.toString().match(/unsafe-eval|CSP/)) {
  6715. warn('It seems you are using the standalone build of Vue.js in an ' +
  6716. 'environment with Content Security Policy that prohibits unsafe-eval. ' +
  6717. 'The template compiler cannot work in this environment. Consider ' +
  6718. 'relaxing the policy to allow unsafe-eval or pre-compiling your ' +
  6719. 'templates into render functions.');
  6720. }
  6721. }
  6722. }
  6723. // check cache
  6724. const key = options.delimiters
  6725. ? String(options.delimiters) + template
  6726. : template;
  6727. if (cache[key]) {
  6728. return cache[key];
  6729. }
  6730. // compile
  6731. const compiled = compile(template, options);
  6732. // check compilation errors/tips
  6733. {
  6734. if (compiled.errors && compiled.errors.length) {
  6735. if (options.outputSourceRange) {
  6736. compiled.errors.forEach(e => {
  6737. warn(`Error compiling template:\n\n${e.msg}\n\n` +
  6738. generateCodeFrame(template, e.start, e.end), vm);
  6739. });
  6740. }
  6741. else {
  6742. warn(`Error compiling template:\n\n${template}\n\n` +
  6743. compiled.errors.map(e => `- ${e}`).join('\n') +
  6744. '\n', vm);
  6745. }
  6746. }
  6747. if (compiled.tips && compiled.tips.length) {
  6748. if (options.outputSourceRange) {
  6749. compiled.tips.forEach(e => tip(e.msg, vm));
  6750. }
  6751. else {
  6752. compiled.tips.forEach(msg => tip(msg, vm));
  6753. }
  6754. }
  6755. }
  6756. // turn code into functions
  6757. const res = {};
  6758. const fnGenErrors = [];
  6759. res.render = createFunction(compiled.render, fnGenErrors);
  6760. res.staticRenderFns = compiled.staticRenderFns.map(code => {
  6761. return createFunction(code, fnGenErrors);
  6762. });
  6763. // check function generation errors.
  6764. // this should only happen if there is a bug in the compiler itself.
  6765. // mostly for codegen development use
  6766. /* istanbul ignore if */
  6767. {
  6768. if ((!compiled.errors || !compiled.errors.length) && fnGenErrors.length) {
  6769. warn(`Failed to generate render function:\n\n` +
  6770. fnGenErrors
  6771. .map(({ err, code }) => `${err.toString()} in\n\n${code}\n`)
  6772. .join('\n'), vm);
  6773. }
  6774. }
  6775. return (cache[key] = res);
  6776. };
  6777. }
  6778. function createCompilerCreator(baseCompile) {
  6779. return function createCompiler(baseOptions) {
  6780. function compile(template, options) {
  6781. const finalOptions = Object.create(baseOptions);
  6782. const errors = [];
  6783. const tips = [];
  6784. let warn = (msg, range, tip) => {
  6785. (tip ? tips : errors).push(msg);
  6786. };
  6787. if (options) {
  6788. if (options.outputSourceRange) {
  6789. // $flow-disable-line
  6790. const leadingSpaceLength = template.match(/^\s*/)[0].length;
  6791. warn = (msg, range, tip) => {
  6792. const data = typeof msg === 'string' ? { msg } : msg;
  6793. if (range) {
  6794. if (range.start != null) {
  6795. data.start = range.start + leadingSpaceLength;
  6796. }
  6797. if (range.end != null) {
  6798. data.end = range.end + leadingSpaceLength;
  6799. }
  6800. }
  6801. (tip ? tips : errors).push(data);
  6802. };
  6803. }
  6804. // merge custom modules
  6805. if (options.modules) {
  6806. finalOptions.modules = (baseOptions.modules || []).concat(options.modules);
  6807. }
  6808. // merge custom directives
  6809. if (options.directives) {
  6810. finalOptions.directives = extend(Object.create(baseOptions.directives || null), options.directives);
  6811. }
  6812. // copy other options
  6813. for (const key in options) {
  6814. if (key !== 'modules' && key !== 'directives') {
  6815. finalOptions[key] = options[key];
  6816. }
  6817. }
  6818. }
  6819. finalOptions.warn = warn;
  6820. const compiled = baseCompile(template.trim(), finalOptions);
  6821. {
  6822. detectErrors(compiled.ast, warn);
  6823. }
  6824. compiled.errors = errors;
  6825. compiled.tips = tips;
  6826. return compiled;
  6827. }
  6828. return {
  6829. compile,
  6830. compileToFunctions: createCompileToFunctionFn(compile)
  6831. };
  6832. };
  6833. }
  6834. const createCompiler = createCompilerCreator(function baseCompile(template, options) {
  6835. const ast = parse(template.trim(), options);
  6836. optimize(ast, options);
  6837. const code = generate(ast, options);
  6838. return {
  6839. ast,
  6840. render: code.render,
  6841. staticRenderFns: code.staticRenderFns
  6842. };
  6843. });
  6844. const { compile: compile$1, compileToFunctions } = createCompiler(baseOptions);
  6845. const ssrHelpers = {
  6846. _ssrEscape: escape,
  6847. _ssrNode: renderStringNode$1,
  6848. _ssrList: renderStringList,
  6849. _ssrAttr: renderAttr,
  6850. _ssrAttrs: renderAttrs,
  6851. _ssrDOMProps: renderDOMProps,
  6852. _ssrClass: renderSSRClass,
  6853. _ssrStyle: renderSSRStyle
  6854. };
  6855. function installSSRHelpers(vm) {
  6856. if (vm._ssrNode) {
  6857. return;
  6858. }
  6859. let Vue = vm.constructor;
  6860. // @ts-expect-error
  6861. while (Vue.super) {
  6862. // @ts-expect-error
  6863. Vue = Vue.super;
  6864. }
  6865. extend(Vue.prototype, ssrHelpers);
  6866. // @ts-expect-error
  6867. if (Vue.FunctionalRenderContext) {
  6868. // @ts-expect-error
  6869. extend(Vue.FunctionalRenderContext.prototype, ssrHelpers);
  6870. }
  6871. }
  6872. class StringNode {
  6873. constructor(open, close, children, normalizationType) {
  6874. this.isString = true;
  6875. this.open = open;
  6876. this.close = close;
  6877. if (children) {
  6878. this.children =
  6879. normalizationType === 1
  6880. ? simpleNormalizeChildren(children)
  6881. : normalizationType === 2
  6882. ? normalizeChildren(children)
  6883. : children;
  6884. }
  6885. else {
  6886. this.children = void 0;
  6887. }
  6888. }
  6889. }
  6890. function renderStringNode$1(open, close, children, normalizationType) {
  6891. return new StringNode(open, close, children, normalizationType);
  6892. }
  6893. function renderStringList(val, render) {
  6894. let ret = '';
  6895. let i, l, keys, key;
  6896. if (Array.isArray(val) || typeof val === 'string') {
  6897. for (i = 0, l = val.length; i < l; i++) {
  6898. ret += render(val[i], i);
  6899. }
  6900. }
  6901. else if (typeof val === 'number') {
  6902. for (i = 0; i < val; i++) {
  6903. ret += render(i + 1, i);
  6904. }
  6905. }
  6906. else if (isObject(val)) {
  6907. keys = Object.keys(val);
  6908. for (i = 0, l = keys.length; i < l; i++) {
  6909. key = keys[i];
  6910. ret += render(val[key], key, i);
  6911. }
  6912. }
  6913. return ret;
  6914. }
  6915. function renderAttrs(obj) {
  6916. let res = '';
  6917. for (const key in obj) {
  6918. if (isSSRUnsafeAttr(key)) {
  6919. continue;
  6920. }
  6921. res += renderAttr(key, obj[key]);
  6922. }
  6923. return res;
  6924. }
  6925. function renderDOMProps(obj) {
  6926. let res = '';
  6927. for (const key in obj) {
  6928. const attr = propsToAttrMap[key] || key.toLowerCase();
  6929. if (isRenderableAttr(attr)) {
  6930. res += renderAttr(attr, obj[key]);
  6931. }
  6932. }
  6933. return res;
  6934. }
  6935. function renderSSRClass(staticClass, dynamic) {
  6936. const res = renderClass$1(staticClass, dynamic);
  6937. return res === '' ? res : ` class="${escape(res)}"`;
  6938. }
  6939. function renderSSRStyle(staticStyle, dynamic, extra) {
  6940. const style = {};
  6941. if (staticStyle)
  6942. extend(style, staticStyle);
  6943. if (dynamic)
  6944. extend(style, normalizeStyleBinding(dynamic));
  6945. if (extra)
  6946. extend(style, extra);
  6947. const res = genStyle(style);
  6948. return res === '' ? res : ` style=${JSON.stringify(escape(res))}`;
  6949. }
  6950. let warned = Object.create(null);
  6951. const warnOnce = msg => {
  6952. if (!warned[msg]) {
  6953. warned[msg] = true;
  6954. // eslint-disable-next-line no-console
  6955. console.warn(`\n\u001b[31m${msg}\u001b[39m\n`);
  6956. }
  6957. };
  6958. const onCompilationError = (err, vm) => {
  6959. const trace = vm ? generateComponentTrace(vm) : '';
  6960. throw new Error(`\n\u001b[31m${err}${trace}\u001b[39m\n`);
  6961. };
  6962. const normalizeRender = vm => {
  6963. const { render, template, _scopeId } = vm.$options;
  6964. if (isUndef(render)) {
  6965. if (template) {
  6966. const compiled = compileToFunctions(template, {
  6967. scopeId: _scopeId,
  6968. warn: onCompilationError
  6969. }, vm);
  6970. vm.$options.render = compiled.render;
  6971. vm.$options.staticRenderFns = compiled.staticRenderFns;
  6972. }
  6973. else {
  6974. throw new Error(`render function or template not defined in component: ${vm.$options.name || vm.$options._componentTag || 'anonymous'}`);
  6975. }
  6976. }
  6977. };
  6978. function waitForServerPrefetch(vm, resolve, reject) {
  6979. let handlers = vm.$options.serverPrefetch;
  6980. if (isDef(handlers)) {
  6981. if (!Array.isArray(handlers))
  6982. handlers = [handlers];
  6983. try {
  6984. const promises = [];
  6985. for (let i = 0, j = handlers.length; i < j; i++) {
  6986. const result = handlers[i].call(vm, vm);
  6987. if (result && typeof result.then === 'function') {
  6988. promises.push(result);
  6989. }
  6990. }
  6991. Promise.all(promises).then(resolve).catch(reject);
  6992. return;
  6993. }
  6994. catch (e) {
  6995. reject(e);
  6996. }
  6997. }
  6998. resolve();
  6999. }
  7000. function renderNode(node, isRoot, context) {
  7001. if (node.isString) {
  7002. renderStringNode(node, context);
  7003. }
  7004. else if (isDef(node.componentOptions)) {
  7005. renderComponent(node, isRoot, context);
  7006. }
  7007. else if (isDef(node.tag)) {
  7008. renderElement(node, isRoot, context);
  7009. }
  7010. else if (isTrue(node.isComment)) {
  7011. if (isDef(node.asyncFactory)) {
  7012. // async component
  7013. renderAsyncComponent(node, isRoot, context);
  7014. }
  7015. else {
  7016. context.write(`<!--${node.text}-->`, context.next);
  7017. }
  7018. }
  7019. else {
  7020. context.write(node.raw ? node.text : escape(String(node.text)), context.next);
  7021. }
  7022. }
  7023. function registerComponentForCache(options, write) {
  7024. // exposed by vue-loader, need to call this if cache hit because
  7025. // component lifecycle hooks will not be called.
  7026. const register = options._ssrRegister;
  7027. if (write.caching && isDef(register)) {
  7028. write.componentBuffer[write.componentBuffer.length - 1].add(register);
  7029. }
  7030. return register;
  7031. }
  7032. function renderComponent(node, isRoot, context) {
  7033. const { write, next, userContext } = context;
  7034. // check cache hit
  7035. const Ctor = node.componentOptions.Ctor;
  7036. const getKey = Ctor.options.serverCacheKey;
  7037. const name = Ctor.options.name;
  7038. const cache = context.cache;
  7039. const registerComponent = registerComponentForCache(Ctor.options, write);
  7040. if (isDef(getKey) && isDef(cache) && isDef(name)) {
  7041. const rawKey = getKey(node.componentOptions.propsData);
  7042. if (rawKey === false) {
  7043. renderComponentInner(node, isRoot, context);
  7044. return;
  7045. }
  7046. const key = name + '::' + rawKey;
  7047. const { has, get } = context;
  7048. if (isDef(has)) {
  7049. has(key, hit => {
  7050. if (hit === true && isDef(get)) {
  7051. get(key, res => {
  7052. if (isDef(registerComponent)) {
  7053. registerComponent(userContext);
  7054. }
  7055. res.components.forEach(register => register(userContext));
  7056. write(res.html, next);
  7057. });
  7058. }
  7059. else {
  7060. renderComponentWithCache(node, isRoot, key, context);
  7061. }
  7062. });
  7063. }
  7064. else if (isDef(get)) {
  7065. get(key, res => {
  7066. if (isDef(res)) {
  7067. if (isDef(registerComponent)) {
  7068. registerComponent(userContext);
  7069. }
  7070. res.components.forEach(register => register(userContext));
  7071. write(res.html, next);
  7072. }
  7073. else {
  7074. renderComponentWithCache(node, isRoot, key, context);
  7075. }
  7076. });
  7077. }
  7078. }
  7079. else {
  7080. if (isDef(getKey) && isUndef(cache)) {
  7081. warnOnce(`[vue-server-renderer] Component ${Ctor.options.name || '(anonymous)'} implemented serverCacheKey, ` +
  7082. 'but no cache was provided to the renderer.');
  7083. }
  7084. if (isDef(getKey) && isUndef(name)) {
  7085. warnOnce(`[vue-server-renderer] Components that implement "serverCacheKey" ` +
  7086. `must also define a unique "name" option.`);
  7087. }
  7088. renderComponentInner(node, isRoot, context);
  7089. }
  7090. }
  7091. function renderComponentWithCache(node, isRoot, key, context) {
  7092. const write = context.write;
  7093. write.caching = true;
  7094. const buffer = write.cacheBuffer;
  7095. const bufferIndex = buffer.push('') - 1;
  7096. const componentBuffer = write.componentBuffer;
  7097. componentBuffer.push(new Set());
  7098. context.renderStates.push({
  7099. type: 'ComponentWithCache',
  7100. key,
  7101. buffer,
  7102. bufferIndex,
  7103. componentBuffer
  7104. });
  7105. renderComponentInner(node, isRoot, context);
  7106. }
  7107. function renderComponentInner(node, isRoot, context) {
  7108. const prevActive = context.activeInstance;
  7109. // expose userContext on vnode
  7110. node.ssrContext = context.userContext;
  7111. const child = (context.activeInstance = createComponentInstanceForVnode(node, context.activeInstance));
  7112. normalizeRender(child);
  7113. const resolve = () => {
  7114. const childNode = child._render();
  7115. childNode.parent = node;
  7116. context.renderStates.push({
  7117. type: 'Component',
  7118. prevActive
  7119. });
  7120. if (isDef(node.data) && isDef(node.data.directives)) {
  7121. childNode.data = childNode.data || {};
  7122. childNode.data.directives = node.data.directives;
  7123. childNode.isComponentRootElement = true;
  7124. }
  7125. renderNode(childNode, isRoot, context);
  7126. };
  7127. const reject = context.done;
  7128. waitForServerPrefetch(child, resolve, reject);
  7129. }
  7130. function renderAsyncComponent(node, isRoot, context) {
  7131. const factory = node.asyncFactory;
  7132. const resolve = comp => {
  7133. if (comp.__esModule && comp.default) {
  7134. comp = comp.default;
  7135. }
  7136. const { data, children, tag } = node.asyncMeta;
  7137. const nodeContext = node.asyncMeta.context;
  7138. const resolvedNode = createComponent(comp, data, nodeContext, children, tag);
  7139. if (resolvedNode) {
  7140. if (resolvedNode.componentOptions) {
  7141. // normal component
  7142. renderComponent(resolvedNode, isRoot, context);
  7143. }
  7144. else if (!Array.isArray(resolvedNode)) {
  7145. // single return node from functional component
  7146. renderNode(resolvedNode, isRoot, context);
  7147. }
  7148. else {
  7149. // multiple return nodes from functional component
  7150. context.renderStates.push({
  7151. type: 'Fragment',
  7152. children: resolvedNode,
  7153. rendered: 0,
  7154. total: resolvedNode.length
  7155. });
  7156. context.next();
  7157. }
  7158. }
  7159. else {
  7160. // invalid component, but this does not throw on the client
  7161. // so render empty comment node
  7162. context.write(`<!---->`, context.next);
  7163. }
  7164. };
  7165. if (factory.resolved) {
  7166. resolve(factory.resolved);
  7167. return;
  7168. }
  7169. const reject = context.done;
  7170. let res;
  7171. try {
  7172. res = factory(resolve, reject);
  7173. }
  7174. catch (e) {
  7175. reject(e);
  7176. }
  7177. if (res) {
  7178. if (typeof res.then === 'function') {
  7179. res.then(resolve, reject).catch(reject);
  7180. }
  7181. else {
  7182. // new syntax in 2.3
  7183. const comp = res.component;
  7184. if (comp && typeof comp.then === 'function') {
  7185. comp.then(resolve, reject).catch(reject);
  7186. }
  7187. }
  7188. }
  7189. }
  7190. function renderStringNode(el, context) {
  7191. const { write, next } = context;
  7192. if (isUndef(el.children) || el.children.length === 0) {
  7193. write(el.open + (el.close || ''), next);
  7194. }
  7195. else {
  7196. const children = el.children;
  7197. context.renderStates.push({
  7198. type: 'Element',
  7199. children,
  7200. rendered: 0,
  7201. total: children.length,
  7202. endTag: el.close
  7203. });
  7204. write(el.open, next);
  7205. }
  7206. }
  7207. function renderElement(el, isRoot, context) {
  7208. const { write, next } = context;
  7209. if (isTrue(isRoot)) {
  7210. if (!el.data)
  7211. el.data = {};
  7212. if (!el.data.attrs)
  7213. el.data.attrs = {};
  7214. el.data.attrs[SSR_ATTR] = 'true';
  7215. }
  7216. if (el.fnOptions) {
  7217. registerComponentForCache(el.fnOptions, write);
  7218. }
  7219. const startTag = renderStartingTag(el, context);
  7220. const endTag = `</${el.tag}>`;
  7221. if (context.isUnaryTag(el.tag)) {
  7222. write(startTag, next);
  7223. }
  7224. else if (isUndef(el.children) || el.children.length === 0) {
  7225. write(startTag + endTag, next);
  7226. }
  7227. else {
  7228. const children = el.children;
  7229. context.renderStates.push({
  7230. type: 'Element',
  7231. children,
  7232. rendered: 0,
  7233. total: children.length,
  7234. endTag
  7235. });
  7236. write(startTag, next);
  7237. }
  7238. }
  7239. function hasAncestorData(node) {
  7240. const parentNode = node.parent;
  7241. return (isDef(parentNode) && (isDef(parentNode.data) || hasAncestorData(parentNode)));
  7242. }
  7243. function getVShowDirectiveInfo(node) {
  7244. let dir;
  7245. let tmp;
  7246. while (isDef(node)) {
  7247. if (node.data && node.data.directives) {
  7248. tmp = node.data.directives.find(dir => dir.name === 'show');
  7249. if (tmp) {
  7250. dir = tmp;
  7251. }
  7252. }
  7253. node = node.parent;
  7254. }
  7255. //@ts-expect-error
  7256. return dir;
  7257. }
  7258. function renderStartingTag(node, context) {
  7259. let markup = `<${node.tag}`;
  7260. const { directives, modules } = context;
  7261. // construct synthetic data for module processing
  7262. // because modules like style also produce code by parent VNode data
  7263. if (isUndef(node.data) && hasAncestorData(node)) {
  7264. node.data = {};
  7265. }
  7266. if (isDef(node.data)) {
  7267. // check directives
  7268. const dirs = node.data.directives;
  7269. if (dirs) {
  7270. for (let i = 0; i < dirs.length; i++) {
  7271. const name = dirs[i].name;
  7272. if (name !== 'show') {
  7273. const dirRenderer = resolveAsset(context, 'directives', name);
  7274. if (dirRenderer) {
  7275. // directives mutate the node's data
  7276. // which then gets rendered by modules
  7277. dirRenderer(node.isComponentRootElement ? node.parent : node, dirs[i]);
  7278. }
  7279. }
  7280. }
  7281. }
  7282. // v-show directive needs to be merged from parent to child
  7283. const vshowDirectiveInfo = getVShowDirectiveInfo(node);
  7284. if (vshowDirectiveInfo) {
  7285. directives.show(node, vshowDirectiveInfo);
  7286. }
  7287. // apply other modules
  7288. for (let i = 0; i < modules.length; i++) {
  7289. const res = modules[i](node);
  7290. if (res) {
  7291. markup += res;
  7292. }
  7293. }
  7294. }
  7295. // attach scoped CSS ID
  7296. let scopeId;
  7297. const activeInstance = context.activeInstance;
  7298. if (isDef(activeInstance) &&
  7299. activeInstance !== node.context &&
  7300. isDef((scopeId = activeInstance.$options._scopeId))) {
  7301. markup += ` ${scopeId}`;
  7302. }
  7303. if (isDef(node.fnScopeId)) {
  7304. markup += ` ${node.fnScopeId}`;
  7305. }
  7306. else {
  7307. while (isDef(node)) {
  7308. //@ts-expect-error
  7309. if (isDef((scopeId = node.context.$options._scopeId))) {
  7310. markup += ` ${scopeId}`;
  7311. }
  7312. node = node.parent;
  7313. }
  7314. }
  7315. return markup + '>';
  7316. }
  7317. function createRenderFunction(modules, directives, isUnaryTag, cache) {
  7318. return function render(component, write, userContext, done) {
  7319. warned = Object.create(null);
  7320. const context = new RenderContext({
  7321. activeInstance: component,
  7322. userContext,
  7323. write,
  7324. done,
  7325. renderNode,
  7326. isUnaryTag,
  7327. modules,
  7328. directives,
  7329. cache
  7330. });
  7331. installSSRHelpers(component);
  7332. normalizeRender(component);
  7333. const resolve = () => {
  7334. renderNode(component._render(), true, context);
  7335. };
  7336. waitForServerPrefetch(component, resolve, done);
  7337. };
  7338. }
  7339. class TemplateStream extends stream.Transform {
  7340. constructor(renderer, template, context) {
  7341. super();
  7342. this.started = false;
  7343. this.renderer = renderer;
  7344. this.template = template;
  7345. this.context = context || {};
  7346. this.inject = renderer.inject;
  7347. }
  7348. _transform(data, encoding, done) {
  7349. if (!this.started) {
  7350. this.emit('beforeStart');
  7351. this.start();
  7352. }
  7353. this.push(data);
  7354. done();
  7355. }
  7356. start() {
  7357. this.started = true;
  7358. this.push(this.template.head(this.context));
  7359. if (this.inject) {
  7360. // inline server-rendered head meta information
  7361. if (this.context.head) {
  7362. this.push(this.context.head);
  7363. }
  7364. // inline preload/prefetch directives for initial/async chunks
  7365. const links = this.renderer.renderResourceHints(this.context);
  7366. if (links) {
  7367. this.push(links);
  7368. }
  7369. // CSS files and inline server-rendered CSS collected by vue-style-loader
  7370. const styles = this.renderer.renderStyles(this.context);
  7371. if (styles) {
  7372. this.push(styles);
  7373. }
  7374. }
  7375. this.push(this.template.neck(this.context));
  7376. }
  7377. _flush(done) {
  7378. this.emit('beforeEnd');
  7379. if (this.inject) {
  7380. // inline initial store state
  7381. const state = this.renderer.renderState(this.context);
  7382. if (state) {
  7383. this.push(state);
  7384. }
  7385. // embed scripts needed
  7386. const scripts = this.renderer.renderScripts(this.context);
  7387. if (scripts) {
  7388. this.push(scripts);
  7389. }
  7390. }
  7391. this.push(this.template.tail(this.context));
  7392. done();
  7393. }
  7394. }
  7395. const compile = require('lodash.template');
  7396. const compileOptions = {
  7397. escape: /{{([^{][\s\S]+?[^}])}}/g,
  7398. interpolate: /{{{([\s\S]+?)}}}/g
  7399. };
  7400. function parseTemplate(template, contentPlaceholder = '<!--vue-ssr-outlet-->') {
  7401. if (typeof template === 'object') {
  7402. return template;
  7403. }
  7404. let i = template.indexOf('</head>');
  7405. const j = template.indexOf(contentPlaceholder);
  7406. if (j < 0) {
  7407. throw new Error(`Content placeholder not found in template.`);
  7408. }
  7409. if (i < 0) {
  7410. i = template.indexOf('<body>');
  7411. if (i < 0) {
  7412. i = j;
  7413. }
  7414. }
  7415. return {
  7416. head: compile(template.slice(0, i), compileOptions),
  7417. neck: compile(template.slice(i, j), compileOptions),
  7418. tail: compile(template.slice(j + contentPlaceholder.length), compileOptions)
  7419. };
  7420. }
  7421. /**
  7422. * Creates a mapper that maps components used during a server-side render
  7423. * to async chunk files in the client-side build, so that we can inline them
  7424. * directly in the rendered HTML to avoid waterfall requests.
  7425. */
  7426. function createMapper(clientManifest) {
  7427. const map = createMap(clientManifest);
  7428. // map server-side moduleIds to client-side files
  7429. return function mapper(moduleIds) {
  7430. const res = new Set();
  7431. for (let i = 0; i < moduleIds.length; i++) {
  7432. const mapped = map.get(moduleIds[i]);
  7433. if (mapped) {
  7434. for (let j = 0; j < mapped.length; j++) {
  7435. res.add(mapped[j]);
  7436. }
  7437. }
  7438. }
  7439. return Array.from(res);
  7440. };
  7441. }
  7442. function createMap(clientManifest) {
  7443. const map = new Map();
  7444. Object.keys(clientManifest.modules).forEach(id => {
  7445. map.set(id, mapIdToFile(id, clientManifest));
  7446. });
  7447. return map;
  7448. }
  7449. function mapIdToFile(id, clientManifest) {
  7450. const files = [];
  7451. const fileIndices = clientManifest.modules[id];
  7452. if (fileIndices) {
  7453. fileIndices.forEach(index => {
  7454. const file = clientManifest.all[index];
  7455. // only include async files or non-js, non-css assets
  7456. if (file &&
  7457. (clientManifest.async.indexOf(file) > -1 ||
  7458. !/\.(js|css)($|\?)/.test(file))) {
  7459. files.push(file);
  7460. }
  7461. });
  7462. }
  7463. return files;
  7464. }
  7465. const path$2 = require('path');
  7466. const serialize = require('serialize-javascript');
  7467. class TemplateRenderer {
  7468. constructor(options) {
  7469. this.options = options;
  7470. this.inject = options.inject !== false;
  7471. // if no template option is provided, the renderer is created
  7472. // as a utility object for rendering assets like preload links and scripts.
  7473. const { template } = options;
  7474. this.parsedTemplate = template
  7475. ? typeof template === 'string'
  7476. ? parseTemplate(template)
  7477. : template
  7478. : null;
  7479. // function used to serialize initial state JSON
  7480. this.serialize =
  7481. options.serializer ||
  7482. (state => {
  7483. return serialize(state, { isJSON: true });
  7484. });
  7485. // extra functionality with client manifest
  7486. if (options.clientManifest) {
  7487. const clientManifest = (this.clientManifest = options.clientManifest);
  7488. // ensure publicPath ends with /
  7489. this.publicPath =
  7490. clientManifest.publicPath === ''
  7491. ? ''
  7492. : clientManifest.publicPath.replace(/([^\/])$/, '$1/');
  7493. // preload/prefetch directives
  7494. this.preloadFiles = (clientManifest.initial || []).map(normalizeFile);
  7495. this.prefetchFiles = (clientManifest.async || []).map(normalizeFile);
  7496. // initial async chunk mapping
  7497. this.mapFiles = createMapper(clientManifest);
  7498. }
  7499. }
  7500. bindRenderFns(context) {
  7501. const renderer = this;
  7502. ['ResourceHints', 'State', 'Scripts', 'Styles'].forEach(type => {
  7503. context[`render${type}`] = renderer[`render${type}`].bind(renderer, context);
  7504. });
  7505. // also expose getPreloadFiles, useful for HTTP/2 push
  7506. context.getPreloadFiles = renderer.getPreloadFiles.bind(renderer, context);
  7507. }
  7508. // render synchronously given rendered app content and render context
  7509. render(content, context) {
  7510. const template = this.parsedTemplate;
  7511. if (!template) {
  7512. throw new Error('render cannot be called without a template.');
  7513. }
  7514. context = context || {};
  7515. if (typeof template === 'function') {
  7516. return template(content, context);
  7517. }
  7518. if (this.inject) {
  7519. return (template.head(context) +
  7520. (context.head || '') +
  7521. this.renderResourceHints(context) +
  7522. this.renderStyles(context) +
  7523. template.neck(context) +
  7524. content +
  7525. this.renderState(context) +
  7526. this.renderScripts(context) +
  7527. template.tail(context));
  7528. }
  7529. else {
  7530. return (template.head(context) +
  7531. template.neck(context) +
  7532. content +
  7533. template.tail(context));
  7534. }
  7535. }
  7536. renderStyles(context) {
  7537. const initial = this.preloadFiles || [];
  7538. const async = this.getUsedAsyncFiles(context) || [];
  7539. const cssFiles = initial.concat(async).filter(({ file }) => isCSS(file));
  7540. return (
  7541. // render links for css files
  7542. (cssFiles.length
  7543. ? cssFiles
  7544. .map(({ file }) => `<link rel="stylesheet" href="${this.publicPath}${file}">`)
  7545. .join('')
  7546. : '') +
  7547. // context.styles is a getter exposed by vue-style-loader which contains
  7548. // the inline component styles collected during SSR
  7549. (context.styles || ''));
  7550. }
  7551. renderResourceHints(context) {
  7552. return this.renderPreloadLinks(context) + this.renderPrefetchLinks(context);
  7553. }
  7554. getPreloadFiles(context) {
  7555. const usedAsyncFiles = this.getUsedAsyncFiles(context);
  7556. if (this.preloadFiles || usedAsyncFiles) {
  7557. return (this.preloadFiles || []).concat(usedAsyncFiles || []);
  7558. }
  7559. else {
  7560. return [];
  7561. }
  7562. }
  7563. renderPreloadLinks(context) {
  7564. const files = this.getPreloadFiles(context);
  7565. const shouldPreload = this.options.shouldPreload;
  7566. if (files.length) {
  7567. return files
  7568. .map(({ file, extension, fileWithoutQuery, asType }) => {
  7569. let extra = '';
  7570. // by default, we only preload scripts or css
  7571. if (!shouldPreload && asType !== 'script' && asType !== 'style') {
  7572. return '';
  7573. }
  7574. // user wants to explicitly control what to preload
  7575. if (shouldPreload && !shouldPreload(fileWithoutQuery, asType)) {
  7576. return '';
  7577. }
  7578. if (asType === 'font') {
  7579. extra = ` type="font/${extension}" crossorigin`;
  7580. }
  7581. return `<link rel="preload" href="${this.publicPath}${file}"${asType !== '' ? ` as="${asType}"` : ''}${extra}>`;
  7582. })
  7583. .join('');
  7584. }
  7585. else {
  7586. return '';
  7587. }
  7588. }
  7589. renderPrefetchLinks(context) {
  7590. const shouldPrefetch = this.options.shouldPrefetch;
  7591. if (this.prefetchFiles) {
  7592. const usedAsyncFiles = this.getUsedAsyncFiles(context);
  7593. const alreadyRendered = file => {
  7594. return usedAsyncFiles && usedAsyncFiles.some(f => f.file === file);
  7595. };
  7596. return this.prefetchFiles
  7597. .map(({ file, fileWithoutQuery, asType }) => {
  7598. if (shouldPrefetch && !shouldPrefetch(fileWithoutQuery, asType)) {
  7599. return '';
  7600. }
  7601. if (alreadyRendered(file)) {
  7602. return '';
  7603. }
  7604. return `<link rel="prefetch" href="${this.publicPath}${file}">`;
  7605. })
  7606. .join('');
  7607. }
  7608. else {
  7609. return '';
  7610. }
  7611. }
  7612. renderState(context, options) {
  7613. const { contextKey = 'state', windowKey = '__INITIAL_STATE__' } = options || {};
  7614. const state = this.serialize(context[contextKey]);
  7615. const autoRemove = ''
  7616. ;
  7617. const nonceAttr = context.nonce ? ` nonce="${context.nonce}"` : '';
  7618. return context[contextKey]
  7619. ? `<script${nonceAttr}>window.${windowKey}=${state}${autoRemove}</script>`
  7620. : '';
  7621. }
  7622. renderScripts(context) {
  7623. if (this.clientManifest) {
  7624. const initial = this.preloadFiles.filter(({ file }) => isJS(file));
  7625. const async = (this.getUsedAsyncFiles(context) || []).filter(({ file }) => isJS(file));
  7626. const needed = [initial[0]].concat(async, initial.slice(1));
  7627. return needed
  7628. .map(({ file }) => {
  7629. return `<script src="${this.publicPath}${file}" defer></script>`;
  7630. })
  7631. .join('');
  7632. }
  7633. else {
  7634. return '';
  7635. }
  7636. }
  7637. getUsedAsyncFiles(context) {
  7638. if (!context._mappedFiles &&
  7639. context._registeredComponents &&
  7640. this.mapFiles) {
  7641. const registered = Array.from(context._registeredComponents);
  7642. context._mappedFiles = this.mapFiles(registered).map(normalizeFile);
  7643. }
  7644. return context._mappedFiles;
  7645. }
  7646. // create a transform stream
  7647. createStream(context) {
  7648. if (!this.parsedTemplate) {
  7649. throw new Error('createStream cannot be called without a template.');
  7650. }
  7651. //@ts-expect-error
  7652. return new TemplateStream(this, this.parsedTemplate, context || {});
  7653. }
  7654. }
  7655. function normalizeFile(file) {
  7656. const withoutQuery = file.replace(/\?.*/, '');
  7657. const extension = path$2.extname(withoutQuery).slice(1);
  7658. return {
  7659. file,
  7660. extension,
  7661. fileWithoutQuery: withoutQuery,
  7662. asType: getPreloadType(extension)
  7663. };
  7664. }
  7665. function getPreloadType(ext) {
  7666. if (ext === 'js') {
  7667. return 'script';
  7668. }
  7669. else if (ext === 'css') {
  7670. return 'style';
  7671. }
  7672. else if (/jpe?g|png|svg|gif|webp|ico/.test(ext)) {
  7673. return 'image';
  7674. }
  7675. else if (/woff2?|ttf|otf|eot/.test(ext)) {
  7676. return 'font';
  7677. }
  7678. else {
  7679. // not exhausting all possibilities here, but above covers common cases
  7680. return '';
  7681. }
  7682. }
  7683. function createRenderer$1({ modules = [], directives = {}, isUnaryTag = () => false, template, inject, cache, shouldPreload, shouldPrefetch, clientManifest, serializer } = {}) {
  7684. const render = createRenderFunction(modules, directives, isUnaryTag, cache);
  7685. const templateRenderer = new TemplateRenderer({
  7686. template,
  7687. inject,
  7688. // @ts-expect-error
  7689. shouldPreload,
  7690. // @ts-expect-error
  7691. shouldPrefetch,
  7692. clientManifest,
  7693. serializer
  7694. });
  7695. return {
  7696. renderToString(component, context, cb) {
  7697. if (typeof context === 'function') {
  7698. cb = context;
  7699. context = {};
  7700. }
  7701. if (context) {
  7702. templateRenderer.bindRenderFns(context);
  7703. }
  7704. // no callback, return Promise
  7705. let promise;
  7706. if (!cb) {
  7707. ({ promise, cb } = createPromiseCallback());
  7708. }
  7709. let result = '';
  7710. const write = createWriteFunction(text => {
  7711. result += text;
  7712. return false;
  7713. }, cb);
  7714. try {
  7715. // @ts-expect-error TODO improve
  7716. render(component, write, context, err => {
  7717. if (err) {
  7718. return cb(err);
  7719. }
  7720. if (context && context.rendered) {
  7721. context.rendered(context);
  7722. }
  7723. if (template) {
  7724. try {
  7725. const res = templateRenderer.render(result, context);
  7726. if (typeof res !== 'string') {
  7727. // function template returning promise
  7728. res.then(html => cb(null, html)).catch(cb);
  7729. }
  7730. else {
  7731. cb(null, res);
  7732. }
  7733. }
  7734. catch (e) {
  7735. cb(e);
  7736. }
  7737. }
  7738. else {
  7739. cb(null, result);
  7740. }
  7741. });
  7742. }
  7743. catch (e) {
  7744. cb(e);
  7745. }
  7746. return promise;
  7747. },
  7748. renderToStream(component, context) {
  7749. if (context) {
  7750. templateRenderer.bindRenderFns(context);
  7751. }
  7752. const renderStream = new RenderStream((write, done) => {
  7753. // @ts-expect-error
  7754. render(component, write, context, done);
  7755. });
  7756. if (!template) {
  7757. // @ts-expect-error
  7758. if (context && context.rendered) {
  7759. // @ts-expect-error
  7760. const rendered = context.rendered;
  7761. renderStream.once('beforeEnd', () => {
  7762. rendered(context);
  7763. });
  7764. }
  7765. return renderStream;
  7766. }
  7767. else if (typeof template === 'function') {
  7768. throw new Error(`function template is only supported in renderToString.`);
  7769. }
  7770. else {
  7771. const templateStream = templateRenderer.createStream(context);
  7772. renderStream.on('error', err => {
  7773. templateStream.emit('error', err);
  7774. });
  7775. renderStream.pipe(templateStream);
  7776. //@ts-expect-error
  7777. if (context && context.rendered) {
  7778. //@ts-expect-error
  7779. const rendered = context.rendered;
  7780. renderStream.once('beforeEnd', () => {
  7781. rendered(context);
  7782. });
  7783. }
  7784. return templateStream;
  7785. }
  7786. }
  7787. };
  7788. }
  7789. const vm = require('vm');
  7790. const path$1 = require('path');
  7791. const resolve = require('resolve');
  7792. const NativeModule = require('module');
  7793. function createSandbox(context) {
  7794. const sandbox = {
  7795. Buffer,
  7796. console,
  7797. process,
  7798. setTimeout,
  7799. setInterval,
  7800. setImmediate,
  7801. clearTimeout,
  7802. clearInterval,
  7803. clearImmediate,
  7804. __VUE_SSR_CONTEXT__: context
  7805. };
  7806. // @ts-expect-error
  7807. sandbox.global = sandbox;
  7808. return sandbox;
  7809. }
  7810. function compileModule(files, basedir, runInNewContext) {
  7811. const compiledScripts = {};
  7812. const resolvedModules = {};
  7813. function getCompiledScript(filename) {
  7814. if (compiledScripts[filename]) {
  7815. return compiledScripts[filename];
  7816. }
  7817. const code = files[filename];
  7818. const wrapper = NativeModule.wrap(code);
  7819. const script = new vm.Script(wrapper, {
  7820. filename,
  7821. displayErrors: true
  7822. });
  7823. compiledScripts[filename] = script;
  7824. return script;
  7825. }
  7826. function evaluateModule(filename, sandbox, evaluatedFiles = {}) {
  7827. if (evaluatedFiles[filename]) {
  7828. return evaluatedFiles[filename];
  7829. }
  7830. const script = getCompiledScript(filename);
  7831. const compiledWrapper = runInNewContext === false
  7832. ? script.runInThisContext()
  7833. : script.runInNewContext(sandbox);
  7834. const m = { exports: {} };
  7835. const r = file => {
  7836. file = path$1.posix.join('.', file);
  7837. if (files[file]) {
  7838. return evaluateModule(file, sandbox, evaluatedFiles);
  7839. }
  7840. else if (basedir) {
  7841. return require(resolvedModules[file] ||
  7842. (resolvedModules[file] = resolve.sync(file, { basedir })));
  7843. }
  7844. else {
  7845. return require(file);
  7846. }
  7847. };
  7848. compiledWrapper.call(m.exports, m.exports, r, m);
  7849. const res = Object.prototype.hasOwnProperty.call(m.exports, 'default')
  7850. ? // @ts-expect-error
  7851. m.exports.default
  7852. : m.exports;
  7853. evaluatedFiles[filename] = res;
  7854. return res;
  7855. }
  7856. return evaluateModule;
  7857. }
  7858. function deepClone(val) {
  7859. if (isPlainObject(val)) {
  7860. const res = {};
  7861. for (const key in val) {
  7862. res[key] = deepClone(val[key]);
  7863. }
  7864. return res;
  7865. }
  7866. else if (Array.isArray(val)) {
  7867. return val.slice();
  7868. }
  7869. else {
  7870. return val;
  7871. }
  7872. }
  7873. function createBundleRunner(entry, files, basedir, runInNewContext) {
  7874. const evaluate = compileModule(files, basedir, runInNewContext);
  7875. if (runInNewContext !== false && runInNewContext !== 'once') {
  7876. // new context mode: creates a fresh context and re-evaluate the bundle
  7877. // on each render. Ensures entire application state is fresh for each
  7878. // render, but incurs extra evaluation cost.
  7879. return (userContext = {}) => new Promise(resolve => {
  7880. // @ts-expect-error
  7881. userContext._registeredComponents = new Set();
  7882. const res = evaluate(entry, createSandbox(userContext));
  7883. resolve(typeof res === 'function' ? res(userContext) : res);
  7884. });
  7885. }
  7886. else {
  7887. // direct mode: instead of re-evaluating the whole bundle on
  7888. // each render, it simply calls the exported function. This avoids the
  7889. // module evaluation costs but requires the source code to be structured
  7890. // slightly differently.
  7891. let runner; // lazy creation so that errors can be caught by user
  7892. let initialContext;
  7893. return (userContext = {}) => new Promise(resolve => {
  7894. if (!runner) {
  7895. const sandbox = runInNewContext === 'once' ? createSandbox() : global;
  7896. // the initial context is only used for collecting possible non-component
  7897. // styles injected by vue-style-loader.
  7898. // @ts-expect-error
  7899. initialContext = sandbox.__VUE_SSR_CONTEXT__ = {};
  7900. runner = evaluate(entry, sandbox);
  7901. // On subsequent renders, __VUE_SSR_CONTEXT__ will not be available
  7902. // to prevent cross-request pollution.
  7903. // @ts-expect-error
  7904. delete sandbox.__VUE_SSR_CONTEXT__;
  7905. if (typeof runner !== 'function') {
  7906. throw new Error('bundle export should be a function when using ' +
  7907. '{ runInNewContext: false }.');
  7908. }
  7909. }
  7910. // @ts-expect-error
  7911. userContext._registeredComponents = new Set();
  7912. // vue-style-loader styles imported outside of component lifecycle hooks
  7913. if (initialContext._styles) {
  7914. // @ts-expect-error
  7915. userContext._styles = deepClone(initialContext._styles);
  7916. // #6353 ensure "styles" is exposed even if no styles are injected
  7917. // in component lifecycles.
  7918. // the renderStyles fn is exposed by vue-style-loader >= 3.0.3
  7919. const renderStyles = initialContext._renderStyles;
  7920. if (renderStyles) {
  7921. Object.defineProperty(userContext, 'styles', {
  7922. enumerable: true,
  7923. get() {
  7924. // @ts-expect-error
  7925. return renderStyles(userContext._styles);
  7926. }
  7927. });
  7928. }
  7929. }
  7930. resolve(runner(userContext));
  7931. });
  7932. }
  7933. }
  7934. const SourceMapConsumer = require('source-map').SourceMapConsumer;
  7935. const filenameRE = /\(([^)]+\.js):(\d+):(\d+)\)$/;
  7936. function createSourceMapConsumers(rawMaps) {
  7937. const maps = {};
  7938. Object.keys(rawMaps).forEach(file => {
  7939. maps[file] = new SourceMapConsumer(rawMaps[file]);
  7940. });
  7941. return maps;
  7942. }
  7943. function rewriteErrorTrace(e, mapConsumers) {
  7944. if (e && typeof e.stack === 'string') {
  7945. e.stack = e.stack
  7946. .split('\n')
  7947. .map(line => {
  7948. return rewriteTraceLine(line, mapConsumers);
  7949. })
  7950. .join('\n');
  7951. }
  7952. }
  7953. function rewriteTraceLine(trace, mapConsumers) {
  7954. const m = trace.match(filenameRE);
  7955. const map = m && mapConsumers[m[1]];
  7956. if (m != null && map) {
  7957. const originalPosition = map.originalPositionFor({
  7958. line: Number(m[2]),
  7959. column: Number(m[3])
  7960. });
  7961. if (originalPosition.source != null) {
  7962. const { source, line, column } = originalPosition;
  7963. const mappedPosition = `(${source.replace(/^webpack:\/\/\//, '')}:${String(line)}:${String(column)})`;
  7964. return trace.replace(filenameRE, mappedPosition);
  7965. }
  7966. else {
  7967. return trace;
  7968. }
  7969. }
  7970. else {
  7971. return trace;
  7972. }
  7973. }
  7974. const fs = require('fs');
  7975. const path = require('path');
  7976. const PassThrough = require('stream').PassThrough;
  7977. const INVALID_MSG = 'Invalid server-rendering bundle format. Should be a string ' +
  7978. 'or a bundle Object of type:\n\n' +
  7979. `{
  7980. entry: string;
  7981. files: { [filename: string]: string; };
  7982. maps: { [filename: string]: string; };
  7983. }\n`;
  7984. function createBundleRendererCreator(createRenderer) {
  7985. return function createBundleRenderer(bundle, rendererOptions = {}) {
  7986. let files, entry, maps;
  7987. let basedir = rendererOptions.basedir;
  7988. // load bundle if given filepath
  7989. if (typeof bundle === 'string' &&
  7990. /\.js(on)?$/.test(bundle) &&
  7991. path.isAbsolute(bundle)) {
  7992. if (fs.existsSync(bundle)) {
  7993. const isJSON = /\.json$/.test(bundle);
  7994. basedir = basedir || path.dirname(bundle);
  7995. bundle = fs.readFileSync(bundle, 'utf-8');
  7996. if (isJSON) {
  7997. try {
  7998. // @ts-expect-error
  7999. bundle = JSON.parse(bundle);
  8000. }
  8001. catch (e) {
  8002. throw new Error(`Invalid JSON bundle file: ${bundle}`);
  8003. }
  8004. }
  8005. }
  8006. else {
  8007. throw new Error(`Cannot locate bundle file: ${bundle}`);
  8008. }
  8009. }
  8010. if (typeof bundle === 'object') {
  8011. entry = bundle.entry;
  8012. files = bundle.files;
  8013. basedir = basedir || bundle.basedir;
  8014. maps = createSourceMapConsumers(bundle.maps);
  8015. if (typeof entry !== 'string' || typeof files !== 'object') {
  8016. throw new Error(INVALID_MSG);
  8017. }
  8018. }
  8019. else if (typeof bundle === 'string') {
  8020. entry = '__vue_ssr_bundle__';
  8021. files = { __vue_ssr_bundle__: bundle };
  8022. maps = {};
  8023. }
  8024. else {
  8025. throw new Error(INVALID_MSG);
  8026. }
  8027. const renderer = createRenderer(rendererOptions);
  8028. const run = createBundleRunner(entry, files, basedir, rendererOptions.runInNewContext);
  8029. return {
  8030. renderToString: (context, cb) => {
  8031. if (typeof context === 'function') {
  8032. cb = context;
  8033. context = {};
  8034. }
  8035. let promise;
  8036. if (!cb) {
  8037. ({ promise, cb } = createPromiseCallback());
  8038. }
  8039. run(context)
  8040. .catch(err => {
  8041. rewriteErrorTrace(err, maps);
  8042. cb(err);
  8043. })
  8044. .then(app => {
  8045. if (app) {
  8046. //@ts-expect-error
  8047. renderer.renderToString(app, context, (err, res) => {
  8048. rewriteErrorTrace(err, maps);
  8049. cb(err, res);
  8050. });
  8051. }
  8052. });
  8053. return promise;
  8054. },
  8055. renderToStream: (context) => {
  8056. const res = new PassThrough();
  8057. run(context)
  8058. .catch(err => {
  8059. rewriteErrorTrace(err, maps);
  8060. // avoid emitting synchronously before user can
  8061. // attach error listener
  8062. process.nextTick(() => {
  8063. res.emit('error', err);
  8064. });
  8065. })
  8066. .then(app => {
  8067. if (app) {
  8068. //@ts-expect-error
  8069. const renderStream = renderer.renderToStream(app, context);
  8070. renderStream.on('error', err => {
  8071. rewriteErrorTrace(err, maps);
  8072. res.emit('error', err);
  8073. });
  8074. // relay HTMLStream special events
  8075. if (rendererOptions && rendererOptions.template) {
  8076. renderStream.on('beforeStart', () => {
  8077. res.emit('beforeStart');
  8078. });
  8079. renderStream.on('beforeEnd', () => {
  8080. res.emit('beforeEnd');
  8081. });
  8082. }
  8083. renderStream.pipe(res);
  8084. }
  8085. });
  8086. return res;
  8087. }
  8088. };
  8089. };
  8090. }
  8091. process.env.VUE_ENV = 'server';
  8092. function createRenderer(options = {}) {
  8093. return createRenderer$1(extend(extend({}, options), {
  8094. isUnaryTag,
  8095. canBeLeftOpenTag,
  8096. modules: modules$1,
  8097. // user can provide server-side implementations for custom directives
  8098. // when creating the renderer.
  8099. directives: extend(baseDirectives$1, options.directives)
  8100. }));
  8101. }
  8102. const createBundleRenderer = createBundleRendererCreator(createRenderer);
  8103. exports.createBundleRenderer = createBundleRenderer;
  8104. exports.createRenderer = createRenderer;