vue.js 498 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152
  1. var Vue = (function (exports) {
  2. 'use strict';
  3. /**
  4. * Make a map and return a function for checking if a key
  5. * is in that map.
  6. * IMPORTANT: all calls of this function must be prefixed with
  7. * \/\*#\_\_PURE\_\_\*\/
  8. * So that rollup can tree-shake them if necessary.
  9. */
  10. function makeMap(str, expectsLowerCase) {
  11. const map = Object.create(null);
  12. const list = str.split(',');
  13. for (let i = 0; i < list.length; i++) {
  14. map[list[i]] = true;
  15. }
  16. return expectsLowerCase ? val => !!map[val.toLowerCase()] : val => !!map[val];
  17. }
  18. // Patch flags are optimization hints generated by the compiler.
  19. // when a block with dynamicChildren is encountered during diff, the algorithm
  20. // enters "optimized mode". In this mode, we know that the vdom is produced by
  21. // a render function generated by the compiler, so the algorithm only needs to
  22. // handle updates explicitly marked by these patch flags.
  23. // dev only flag -> name mapping
  24. const PatchFlagNames = {
  25. [1 /* TEXT */]: `TEXT`,
  26. [2 /* CLASS */]: `CLASS`,
  27. [4 /* STYLE */]: `STYLE`,
  28. [8 /* PROPS */]: `PROPS`,
  29. [16 /* FULL_PROPS */]: `FULL_PROPS`,
  30. [32 /* HYDRATE_EVENTS */]: `HYDRATE_EVENTS`,
  31. [64 /* STABLE_FRAGMENT */]: `STABLE_FRAGMENT`,
  32. [128 /* KEYED_FRAGMENT */]: `KEYED_FRAGMENT`,
  33. [256 /* UNKEYED_FRAGMENT */]: `UNKEYED_FRAGMENT`,
  34. [1024 /* DYNAMIC_SLOTS */]: `DYNAMIC_SLOTS`,
  35. [512 /* NEED_PATCH */]: `NEED_PATCH`,
  36. [-1 /* HOISTED */]: `HOISTED`,
  37. [-2 /* BAIL */]: `BAIL`
  38. };
  39. const GLOBALS_WHITE_LISTED = 'Infinity,undefined,NaN,isFinite,isNaN,parseFloat,parseInt,decodeURI,' +
  40. 'decodeURIComponent,encodeURI,encodeURIComponent,Math,Number,Date,Array,' +
  41. 'Object,Boolean,String,RegExp,Map,Set,JSON,Intl';
  42. const isGloballyWhitelisted = /*#__PURE__*/ makeMap(GLOBALS_WHITE_LISTED);
  43. const range = 2;
  44. function generateCodeFrame(source, start = 0, end = source.length) {
  45. const lines = source.split(/\r?\n/);
  46. let count = 0;
  47. const res = [];
  48. for (let i = 0; i < lines.length; i++) {
  49. count += lines[i].length + 1;
  50. if (count >= start) {
  51. for (let j = i - range; j <= i + range || end > count; j++) {
  52. if (j < 0 || j >= lines.length)
  53. continue;
  54. const line = j + 1;
  55. res.push(`${line}${' '.repeat(Math.max(3 - String(line).length, 0))}| ${lines[j]}`);
  56. const lineLength = lines[j].length;
  57. if (j === i) {
  58. // push underline
  59. const pad = start - (count - lineLength) + 1;
  60. const length = Math.max(1, end > count ? lineLength - pad : end - start);
  61. res.push(` | ` + ' '.repeat(pad) + '^'.repeat(length));
  62. }
  63. else if (j > i) {
  64. if (end > count) {
  65. const length = Math.max(Math.min(end - count, lineLength), 1);
  66. res.push(` | ` + '^'.repeat(length));
  67. }
  68. count += lineLength + 1;
  69. }
  70. }
  71. break;
  72. }
  73. }
  74. return res.join('\n');
  75. }
  76. /**
  77. * On the client we only need to offer special cases for boolean attributes that
  78. * have different names from their corresponding dom properties:
  79. * - itemscope -> N/A
  80. * - allowfullscreen -> allowFullscreen
  81. * - formnovalidate -> formNoValidate
  82. * - ismap -> isMap
  83. * - nomodule -> noModule
  84. * - novalidate -> noValidate
  85. * - readonly -> readOnly
  86. */
  87. const specialBooleanAttrs = `itemscope,allowfullscreen,formnovalidate,ismap,nomodule,novalidate,readonly`;
  88. const isSpecialBooleanAttr = /*#__PURE__*/ makeMap(specialBooleanAttrs);
  89. function normalizeStyle(value) {
  90. if (isArray(value)) {
  91. const res = {};
  92. for (let i = 0; i < value.length; i++) {
  93. const item = value[i];
  94. const normalized = normalizeStyle(isString(item) ? parseStringStyle(item) : item);
  95. if (normalized) {
  96. for (const key in normalized) {
  97. res[key] = normalized[key];
  98. }
  99. }
  100. }
  101. return res;
  102. }
  103. else if (isObject(value)) {
  104. return value;
  105. }
  106. }
  107. const listDelimiterRE = /;(?![^(]*\))/g;
  108. const propertyDelimiterRE = /:(.+)/;
  109. function parseStringStyle(cssText) {
  110. const ret = {};
  111. cssText.split(listDelimiterRE).forEach(item => {
  112. if (item) {
  113. const tmp = item.split(propertyDelimiterRE);
  114. tmp.length > 1 && (ret[tmp[0].trim()] = tmp[1].trim());
  115. }
  116. });
  117. return ret;
  118. }
  119. function normalizeClass(value) {
  120. let res = '';
  121. if (isString(value)) {
  122. res = value;
  123. }
  124. else if (isArray(value)) {
  125. for (let i = 0; i < value.length; i++) {
  126. res += normalizeClass(value[i]) + ' ';
  127. }
  128. }
  129. else if (isObject(value)) {
  130. for (const name in value) {
  131. if (value[name]) {
  132. res += name + ' ';
  133. }
  134. }
  135. }
  136. return res.trim();
  137. }
  138. // These tag configs are shared between compiler-dom and runtime-dom, so they
  139. // https://developer.mozilla.org/en-US/docs/Web/HTML/Element
  140. const HTML_TAGS = 'html,body,base,head,link,meta,style,title,address,article,aside,footer,' +
  141. 'header,h1,h2,h3,h4,h5,h6,hgroup,nav,section,div,dd,dl,dt,figcaption,' +
  142. 'figure,picture,hr,img,li,main,ol,p,pre,ul,a,b,abbr,bdi,bdo,br,cite,code,' +
  143. 'data,dfn,em,i,kbd,mark,q,rp,rt,rtc,ruby,s,samp,small,span,strong,sub,sup,' +
  144. 'time,u,var,wbr,area,audio,map,track,video,embed,object,param,source,' +
  145. 'canvas,script,noscript,del,ins,caption,col,colgroup,table,thead,tbody,td,' +
  146. 'th,tr,button,datalist,fieldset,form,input,label,legend,meter,optgroup,' +
  147. 'option,output,progress,select,textarea,details,dialog,menu,' +
  148. 'summary,template,blockquote,iframe,tfoot';
  149. // https://developer.mozilla.org/en-US/docs/Web/SVG/Element
  150. const SVG_TAGS = 'svg,animate,animateMotion,animateTransform,circle,clipPath,color-profile,' +
  151. 'defs,desc,discard,ellipse,feBlend,feColorMatrix,feComponentTransfer,' +
  152. 'feComposite,feConvolveMatrix,feDiffuseLighting,feDisplacementMap,' +
  153. 'feDistanceLight,feDropShadow,feFlood,feFuncA,feFuncB,feFuncG,feFuncR,' +
  154. 'feGaussianBlur,feImage,feMerge,feMergeNode,feMorphology,feOffset,' +
  155. 'fePointLight,feSpecularLighting,feSpotLight,feTile,feTurbulence,filter,' +
  156. 'foreignObject,g,hatch,hatchpath,image,line,linearGradient,marker,mask,' +
  157. 'mesh,meshgradient,meshpatch,meshrow,metadata,mpath,path,pattern,' +
  158. 'polygon,polyline,radialGradient,rect,set,solidcolor,stop,switch,symbol,' +
  159. 'text,textPath,title,tspan,unknown,use,view';
  160. const VOID_TAGS = 'area,base,br,col,embed,hr,img,input,link,meta,param,source,track,wbr';
  161. const isHTMLTag = /*#__PURE__*/ makeMap(HTML_TAGS);
  162. const isSVGTag = /*#__PURE__*/ makeMap(SVG_TAGS);
  163. const isVoidTag = /*#__PURE__*/ makeMap(VOID_TAGS);
  164. function looseCompareArrays(a, b) {
  165. if (a.length !== b.length)
  166. return false;
  167. let equal = true;
  168. for (let i = 0; equal && i < a.length; i++) {
  169. equal = looseEqual(a[i], b[i]);
  170. }
  171. return equal;
  172. }
  173. function looseEqual(a, b) {
  174. if (a === b)
  175. return true;
  176. let aValidType = isDate(a);
  177. let bValidType = isDate(b);
  178. if (aValidType || bValidType) {
  179. return aValidType && bValidType ? a.getTime() === b.getTime() : false;
  180. }
  181. aValidType = isArray(a);
  182. bValidType = isArray(b);
  183. if (aValidType || bValidType) {
  184. return aValidType && bValidType ? looseCompareArrays(a, b) : false;
  185. }
  186. aValidType = isObject(a);
  187. bValidType = isObject(b);
  188. if (aValidType || bValidType) {
  189. /* istanbul ignore if: this if will probably never be called */
  190. if (!aValidType || !bValidType) {
  191. return false;
  192. }
  193. const aKeysCount = Object.keys(a).length;
  194. const bKeysCount = Object.keys(b).length;
  195. if (aKeysCount !== bKeysCount) {
  196. return false;
  197. }
  198. for (const key in a) {
  199. const aHasKey = a.hasOwnProperty(key);
  200. const bHasKey = b.hasOwnProperty(key);
  201. if ((aHasKey && !bHasKey) ||
  202. (!aHasKey && bHasKey) ||
  203. !looseEqual(a[key], b[key])) {
  204. return false;
  205. }
  206. }
  207. }
  208. return String(a) === String(b);
  209. }
  210. function looseIndexOf(arr, val) {
  211. return arr.findIndex(item => looseEqual(item, val));
  212. }
  213. function looseHas(set, val) {
  214. for (let item of set) {
  215. if (looseEqual(item, val))
  216. return true;
  217. }
  218. return false;
  219. }
  220. /**
  221. * For converting {{ interpolation }} values to displayed strings.
  222. * @private
  223. */
  224. const toDisplayString = (val) => {
  225. return val == null
  226. ? ''
  227. : isObject(val)
  228. ? JSON.stringify(val, replacer, 2)
  229. : String(val);
  230. };
  231. const replacer = (_key, val) => {
  232. if (isMap(val)) {
  233. return {
  234. [`Map(${val.size})`]: [...val.entries()].reduce((entries, [key, val]) => {
  235. entries[`${key} =>`] = val;
  236. return entries;
  237. }, {})
  238. };
  239. }
  240. else if (isSet(val)) {
  241. return {
  242. [`Set(${val.size})`]: [...val.values()]
  243. };
  244. }
  245. else if (isObject(val) && !isArray(val) && !isPlainObject(val)) {
  246. return String(val);
  247. }
  248. return val;
  249. };
  250. const EMPTY_OBJ = Object.freeze({})
  251. ;
  252. const EMPTY_ARR = [];
  253. const NOOP = () => { };
  254. /**
  255. * Always return false.
  256. */
  257. const NO = () => false;
  258. const onRE = /^on[^a-z]/;
  259. const isOn = (key) => onRE.test(key);
  260. const isModelListener = (key) => key.startsWith('onUpdate:');
  261. const extend = Object.assign;
  262. const remove = (arr, el) => {
  263. const i = arr.indexOf(el);
  264. if (i > -1) {
  265. arr.splice(i, 1);
  266. }
  267. };
  268. const hasOwnProperty = Object.prototype.hasOwnProperty;
  269. const hasOwn = (val, key) => hasOwnProperty.call(val, key);
  270. const isArray = Array.isArray;
  271. const isMap = (val) => toTypeString(val) === '[object Map]';
  272. const isSet = (val) => toTypeString(val) === '[object Set]';
  273. const isDate = (val) => val instanceof Date;
  274. const isFunction = (val) => typeof val === 'function';
  275. const isString = (val) => typeof val === 'string';
  276. const isSymbol = (val) => typeof val === 'symbol';
  277. const isObject = (val) => val !== null && typeof val === 'object';
  278. const isPromise = (val) => {
  279. return isObject(val) && isFunction(val.then) && isFunction(val.catch);
  280. };
  281. const objectToString = Object.prototype.toString;
  282. const toTypeString = (value) => objectToString.call(value);
  283. const toRawType = (value) => {
  284. return toTypeString(value).slice(8, -1);
  285. };
  286. const isPlainObject = (val) => toTypeString(val) === '[object Object]';
  287. const isIntegerKey = (key) => isString(key) &&
  288. key !== 'NaN' &&
  289. key[0] !== '-' &&
  290. '' + parseInt(key, 10) === key;
  291. const isReservedProp = /*#__PURE__*/ makeMap('key,ref,' +
  292. 'onVnodeBeforeMount,onVnodeMounted,' +
  293. 'onVnodeBeforeUpdate,onVnodeUpdated,' +
  294. 'onVnodeBeforeUnmount,onVnodeUnmounted');
  295. const cacheStringFunction = (fn) => {
  296. const cache = Object.create(null);
  297. return ((str) => {
  298. const hit = cache[str];
  299. return hit || (cache[str] = fn(str));
  300. });
  301. };
  302. const camelizeRE = /-(\w)/g;
  303. /**
  304. * @private
  305. */
  306. const camelize = cacheStringFunction((str) => {
  307. return str.replace(camelizeRE, (_, c) => (c ? c.toUpperCase() : ''));
  308. });
  309. const hyphenateRE = /\B([A-Z])/g;
  310. /**
  311. * @private
  312. */
  313. const hyphenate = cacheStringFunction((str) => {
  314. return str.replace(hyphenateRE, '-$1').toLowerCase();
  315. });
  316. /**
  317. * @private
  318. */
  319. const capitalize = cacheStringFunction((str) => {
  320. return str.charAt(0).toUpperCase() + str.slice(1);
  321. });
  322. // compare whether a value has changed, accounting for NaN.
  323. const hasChanged = (value, oldValue) => value !== oldValue && (value === value || oldValue === oldValue);
  324. const invokeArrayFns = (fns, arg) => {
  325. for (let i = 0; i < fns.length; i++) {
  326. fns[i](arg);
  327. }
  328. };
  329. const def = (obj, key, value) => {
  330. Object.defineProperty(obj, key, {
  331. configurable: true,
  332. enumerable: false,
  333. value
  334. });
  335. };
  336. const toNumber = (val) => {
  337. const n = parseFloat(val);
  338. return isNaN(n) ? val : n;
  339. };
  340. let _globalThis;
  341. const getGlobalThis = () => {
  342. return (_globalThis ||
  343. (_globalThis =
  344. typeof globalThis !== 'undefined'
  345. ? globalThis
  346. : typeof self !== 'undefined'
  347. ? self
  348. : typeof window !== 'undefined'
  349. ? window
  350. : typeof global !== 'undefined'
  351. ? global
  352. : {}));
  353. };
  354. const targetMap = new WeakMap();
  355. const effectStack = [];
  356. let activeEffect;
  357. const ITERATE_KEY = Symbol( 'iterate' );
  358. const MAP_KEY_ITERATE_KEY = Symbol( 'Map key iterate' );
  359. function isEffect(fn) {
  360. return fn && fn._isEffect === true;
  361. }
  362. function effect(fn, options = EMPTY_OBJ) {
  363. if (isEffect(fn)) {
  364. fn = fn.raw;
  365. }
  366. const effect = createReactiveEffect(fn, options);
  367. if (!options.lazy) {
  368. effect();
  369. }
  370. return effect;
  371. }
  372. function stop(effect) {
  373. if (effect.active) {
  374. cleanup(effect);
  375. if (effect.options.onStop) {
  376. effect.options.onStop();
  377. }
  378. effect.active = false;
  379. }
  380. }
  381. let uid = 0;
  382. function createReactiveEffect(fn, options) {
  383. const effect = function reactiveEffect() {
  384. if (!effect.active) {
  385. return options.scheduler ? undefined : fn();
  386. }
  387. if (!effectStack.includes(effect)) {
  388. cleanup(effect);
  389. try {
  390. enableTracking();
  391. effectStack.push(effect);
  392. activeEffect = effect;
  393. return fn();
  394. }
  395. finally {
  396. effectStack.pop();
  397. resetTracking();
  398. activeEffect = effectStack[effectStack.length - 1];
  399. }
  400. }
  401. };
  402. effect.id = uid++;
  403. effect._isEffect = true;
  404. effect.active = true;
  405. effect.raw = fn;
  406. effect.deps = [];
  407. effect.options = options;
  408. return effect;
  409. }
  410. function cleanup(effect) {
  411. const { deps } = effect;
  412. if (deps.length) {
  413. for (let i = 0; i < deps.length; i++) {
  414. deps[i].delete(effect);
  415. }
  416. deps.length = 0;
  417. }
  418. }
  419. let shouldTrack = true;
  420. const trackStack = [];
  421. function pauseTracking() {
  422. trackStack.push(shouldTrack);
  423. shouldTrack = false;
  424. }
  425. function enableTracking() {
  426. trackStack.push(shouldTrack);
  427. shouldTrack = true;
  428. }
  429. function resetTracking() {
  430. const last = trackStack.pop();
  431. shouldTrack = last === undefined ? true : last;
  432. }
  433. function track(target, type, key) {
  434. if (!shouldTrack || activeEffect === undefined) {
  435. return;
  436. }
  437. let depsMap = targetMap.get(target);
  438. if (!depsMap) {
  439. targetMap.set(target, (depsMap = new Map()));
  440. }
  441. let dep = depsMap.get(key);
  442. if (!dep) {
  443. depsMap.set(key, (dep = new Set()));
  444. }
  445. if (!dep.has(activeEffect)) {
  446. dep.add(activeEffect);
  447. activeEffect.deps.push(dep);
  448. if ( activeEffect.options.onTrack) {
  449. activeEffect.options.onTrack({
  450. effect: activeEffect,
  451. target,
  452. type,
  453. key
  454. });
  455. }
  456. }
  457. }
  458. function trigger(target, type, key, newValue, oldValue, oldTarget) {
  459. const depsMap = targetMap.get(target);
  460. if (!depsMap) {
  461. // never been tracked
  462. return;
  463. }
  464. const effects = new Set();
  465. const add = (effectsToAdd) => {
  466. if (effectsToAdd) {
  467. effectsToAdd.forEach(effect => {
  468. if (effect !== activeEffect || effect.options.allowRecurse) {
  469. effects.add(effect);
  470. }
  471. });
  472. }
  473. };
  474. if (type === "clear" /* CLEAR */) {
  475. // collection being cleared
  476. // trigger all effects for target
  477. depsMap.forEach(add);
  478. }
  479. else if (key === 'length' && isArray(target)) {
  480. depsMap.forEach((dep, key) => {
  481. if (key === 'length' || key >= newValue) {
  482. add(dep);
  483. }
  484. });
  485. }
  486. else {
  487. // schedule runs for SET | ADD | DELETE
  488. if (key !== void 0) {
  489. add(depsMap.get(key));
  490. }
  491. // also run for iteration key on ADD | DELETE | Map.SET
  492. switch (type) {
  493. case "add" /* ADD */:
  494. if (!isArray(target)) {
  495. add(depsMap.get(ITERATE_KEY));
  496. if (isMap(target)) {
  497. add(depsMap.get(MAP_KEY_ITERATE_KEY));
  498. }
  499. }
  500. else if (isIntegerKey(key)) {
  501. // new index added to array -> length changes
  502. add(depsMap.get('length'));
  503. }
  504. break;
  505. case "delete" /* DELETE */:
  506. if (!isArray(target)) {
  507. add(depsMap.get(ITERATE_KEY));
  508. if (isMap(target)) {
  509. add(depsMap.get(MAP_KEY_ITERATE_KEY));
  510. }
  511. }
  512. break;
  513. case "set" /* SET */:
  514. if (isMap(target)) {
  515. add(depsMap.get(ITERATE_KEY));
  516. }
  517. break;
  518. }
  519. }
  520. const run = (effect) => {
  521. if ( effect.options.onTrigger) {
  522. effect.options.onTrigger({
  523. effect,
  524. target,
  525. key,
  526. type,
  527. newValue,
  528. oldValue,
  529. oldTarget
  530. });
  531. }
  532. if (effect.options.scheduler) {
  533. effect.options.scheduler(effect);
  534. }
  535. else {
  536. effect();
  537. }
  538. };
  539. effects.forEach(run);
  540. }
  541. const builtInSymbols = new Set(Object.getOwnPropertyNames(Symbol)
  542. .map(key => Symbol[key])
  543. .filter(isSymbol));
  544. const get = /*#__PURE__*/ createGetter();
  545. const shallowGet = /*#__PURE__*/ createGetter(false, true);
  546. const readonlyGet = /*#__PURE__*/ createGetter(true);
  547. const shallowReadonlyGet = /*#__PURE__*/ createGetter(true, true);
  548. const arrayInstrumentations = {};
  549. ['includes', 'indexOf', 'lastIndexOf'].forEach(key => {
  550. const method = Array.prototype[key];
  551. arrayInstrumentations[key] = function (...args) {
  552. const arr = toRaw(this);
  553. for (let i = 0, l = this.length; i < l; i++) {
  554. track(arr, "get" /* GET */, i + '');
  555. }
  556. // we run the method using the original args first (which may be reactive)
  557. const res = method.apply(arr, args);
  558. if (res === -1 || res === false) {
  559. // if that didn't work, run it again using raw values.
  560. return method.apply(arr, args.map(toRaw));
  561. }
  562. else {
  563. return res;
  564. }
  565. };
  566. });
  567. ['push', 'pop', 'shift', 'unshift', 'splice'].forEach(key => {
  568. const method = Array.prototype[key];
  569. arrayInstrumentations[key] = function (...args) {
  570. pauseTracking();
  571. const res = method.apply(this, args);
  572. enableTracking();
  573. return res;
  574. };
  575. });
  576. function createGetter(isReadonly = false, shallow = false) {
  577. return function get(target, key, receiver) {
  578. if (key === "__v_isReactive" /* IS_REACTIVE */) {
  579. return !isReadonly;
  580. }
  581. else if (key === "__v_isReadonly" /* IS_READONLY */) {
  582. return isReadonly;
  583. }
  584. else if (key === "__v_raw" /* RAW */ &&
  585. receiver === (isReadonly ? readonlyMap : reactiveMap).get(target)) {
  586. return target;
  587. }
  588. const targetIsArray = isArray(target);
  589. if (targetIsArray && hasOwn(arrayInstrumentations, key)) {
  590. return Reflect.get(arrayInstrumentations, key, receiver);
  591. }
  592. const res = Reflect.get(target, key, receiver);
  593. const keyIsSymbol = isSymbol(key);
  594. if (keyIsSymbol
  595. ? builtInSymbols.has(key)
  596. : key === `__proto__` || key === `__v_isRef`) {
  597. return res;
  598. }
  599. if (!isReadonly) {
  600. track(target, "get" /* GET */, key);
  601. }
  602. if (shallow) {
  603. return res;
  604. }
  605. if (isRef(res)) {
  606. // ref unwrapping - does not apply for Array + integer key.
  607. const shouldUnwrap = !targetIsArray || !isIntegerKey(key);
  608. return shouldUnwrap ? res.value : res;
  609. }
  610. if (isObject(res)) {
  611. // Convert returned value into a proxy as well. we do the isObject check
  612. // here to avoid invalid value warning. Also need to lazy access readonly
  613. // and reactive here to avoid circular dependency.
  614. return isReadonly ? readonly(res) : reactive(res);
  615. }
  616. return res;
  617. };
  618. }
  619. const set = /*#__PURE__*/ createSetter();
  620. const shallowSet = /*#__PURE__*/ createSetter(true);
  621. function createSetter(shallow = false) {
  622. return function set(target, key, value, receiver) {
  623. const oldValue = target[key];
  624. if (!shallow) {
  625. value = toRaw(value);
  626. if (!isArray(target) && isRef(oldValue) && !isRef(value)) {
  627. oldValue.value = value;
  628. return true;
  629. }
  630. }
  631. const hadKey = isArray(target) && isIntegerKey(key)
  632. ? Number(key) < target.length
  633. : hasOwn(target, key);
  634. const result = Reflect.set(target, key, value, receiver);
  635. // don't trigger if target is something up in the prototype chain of original
  636. if (target === toRaw(receiver)) {
  637. if (!hadKey) {
  638. trigger(target, "add" /* ADD */, key, value);
  639. }
  640. else if (hasChanged(value, oldValue)) {
  641. trigger(target, "set" /* SET */, key, value, oldValue);
  642. }
  643. }
  644. return result;
  645. };
  646. }
  647. function deleteProperty(target, key) {
  648. const hadKey = hasOwn(target, key);
  649. const oldValue = target[key];
  650. const result = Reflect.deleteProperty(target, key);
  651. if (result && hadKey) {
  652. trigger(target, "delete" /* DELETE */, key, undefined, oldValue);
  653. }
  654. return result;
  655. }
  656. function has(target, key) {
  657. const result = Reflect.has(target, key);
  658. if (!isSymbol(key) || !builtInSymbols.has(key)) {
  659. track(target, "has" /* HAS */, key);
  660. }
  661. return result;
  662. }
  663. function ownKeys(target) {
  664. track(target, "iterate" /* ITERATE */, ITERATE_KEY);
  665. return Reflect.ownKeys(target);
  666. }
  667. const mutableHandlers = {
  668. get,
  669. set,
  670. deleteProperty,
  671. has,
  672. ownKeys
  673. };
  674. const readonlyHandlers = {
  675. get: readonlyGet,
  676. set(target, key) {
  677. {
  678. console.warn(`Set operation on key "${String(key)}" failed: target is readonly.`, target);
  679. }
  680. return true;
  681. },
  682. deleteProperty(target, key) {
  683. {
  684. console.warn(`Delete operation on key "${String(key)}" failed: target is readonly.`, target);
  685. }
  686. return true;
  687. }
  688. };
  689. const shallowReactiveHandlers = extend({}, mutableHandlers, {
  690. get: shallowGet,
  691. set: shallowSet
  692. });
  693. // Props handlers are special in the sense that it should not unwrap top-level
  694. // refs (in order to allow refs to be explicitly passed down), but should
  695. // retain the reactivity of the normal readonly object.
  696. const shallowReadonlyHandlers = extend({}, readonlyHandlers, {
  697. get: shallowReadonlyGet
  698. });
  699. const toReactive = (value) => isObject(value) ? reactive(value) : value;
  700. const toReadonly = (value) => isObject(value) ? readonly(value) : value;
  701. const toShallow = (value) => value;
  702. const getProto = (v) => Reflect.getPrototypeOf(v);
  703. function get$1(target, key, isReadonly = false, isShallow = false) {
  704. // #1772: readonly(reactive(Map)) should return readonly + reactive version
  705. // of the value
  706. target = target["__v_raw" /* RAW */];
  707. const rawTarget = toRaw(target);
  708. const rawKey = toRaw(key);
  709. if (key !== rawKey) {
  710. !isReadonly && track(rawTarget, "get" /* GET */, key);
  711. }
  712. !isReadonly && track(rawTarget, "get" /* GET */, rawKey);
  713. const { has } = getProto(rawTarget);
  714. const wrap = isReadonly ? toReadonly : isShallow ? toShallow : toReactive;
  715. if (has.call(rawTarget, key)) {
  716. return wrap(target.get(key));
  717. }
  718. else if (has.call(rawTarget, rawKey)) {
  719. return wrap(target.get(rawKey));
  720. }
  721. }
  722. function has$1(key, isReadonly = false) {
  723. const target = this["__v_raw" /* RAW */];
  724. const rawTarget = toRaw(target);
  725. const rawKey = toRaw(key);
  726. if (key !== rawKey) {
  727. !isReadonly && track(rawTarget, "has" /* HAS */, key);
  728. }
  729. !isReadonly && track(rawTarget, "has" /* HAS */, rawKey);
  730. return key === rawKey
  731. ? target.has(key)
  732. : target.has(key) || target.has(rawKey);
  733. }
  734. function size(target, isReadonly = false) {
  735. target = target["__v_raw" /* RAW */];
  736. !isReadonly && track(toRaw(target), "iterate" /* ITERATE */, ITERATE_KEY);
  737. return Reflect.get(target, 'size', target);
  738. }
  739. function add(value) {
  740. value = toRaw(value);
  741. const target = toRaw(this);
  742. const proto = getProto(target);
  743. const hadKey = proto.has.call(target, value);
  744. const result = target.add(value);
  745. if (!hadKey) {
  746. trigger(target, "add" /* ADD */, value, value);
  747. }
  748. return result;
  749. }
  750. function set$1(key, value) {
  751. value = toRaw(value);
  752. const target = toRaw(this);
  753. const { has, get } = getProto(target);
  754. let hadKey = has.call(target, key);
  755. if (!hadKey) {
  756. key = toRaw(key);
  757. hadKey = has.call(target, key);
  758. }
  759. else {
  760. checkIdentityKeys(target, has, key);
  761. }
  762. const oldValue = get.call(target, key);
  763. const result = target.set(key, value);
  764. if (!hadKey) {
  765. trigger(target, "add" /* ADD */, key, value);
  766. }
  767. else if (hasChanged(value, oldValue)) {
  768. trigger(target, "set" /* SET */, key, value, oldValue);
  769. }
  770. return result;
  771. }
  772. function deleteEntry(key) {
  773. const target = toRaw(this);
  774. const { has, get } = getProto(target);
  775. let hadKey = has.call(target, key);
  776. if (!hadKey) {
  777. key = toRaw(key);
  778. hadKey = has.call(target, key);
  779. }
  780. else {
  781. checkIdentityKeys(target, has, key);
  782. }
  783. const oldValue = get ? get.call(target, key) : undefined;
  784. // forward the operation before queueing reactions
  785. const result = target.delete(key);
  786. if (hadKey) {
  787. trigger(target, "delete" /* DELETE */, key, undefined, oldValue);
  788. }
  789. return result;
  790. }
  791. function clear() {
  792. const target = toRaw(this);
  793. const hadItems = target.size !== 0;
  794. const oldTarget = isMap(target)
  795. ? new Map(target)
  796. : new Set(target)
  797. ;
  798. // forward the operation before queueing reactions
  799. const result = target.clear();
  800. if (hadItems) {
  801. trigger(target, "clear" /* CLEAR */, undefined, undefined, oldTarget);
  802. }
  803. return result;
  804. }
  805. function createForEach(isReadonly, isShallow) {
  806. return function forEach(callback, thisArg) {
  807. const observed = this;
  808. const target = observed["__v_raw" /* RAW */];
  809. const rawTarget = toRaw(target);
  810. const wrap = isReadonly ? toReadonly : isShallow ? toShallow : toReactive;
  811. !isReadonly && track(rawTarget, "iterate" /* ITERATE */, ITERATE_KEY);
  812. return target.forEach((value, key) => {
  813. // important: make sure the callback is
  814. // 1. invoked with the reactive map as `this` and 3rd arg
  815. // 2. the value received should be a corresponding reactive/readonly.
  816. return callback.call(thisArg, wrap(value), wrap(key), observed);
  817. });
  818. };
  819. }
  820. function createIterableMethod(method, isReadonly, isShallow) {
  821. return function (...args) {
  822. const target = this["__v_raw" /* RAW */];
  823. const rawTarget = toRaw(target);
  824. const targetIsMap = isMap(rawTarget);
  825. const isPair = method === 'entries' || (method === Symbol.iterator && targetIsMap);
  826. const isKeyOnly = method === 'keys' && targetIsMap;
  827. const innerIterator = target[method](...args);
  828. const wrap = isReadonly ? toReadonly : isShallow ? toShallow : toReactive;
  829. !isReadonly &&
  830. track(rawTarget, "iterate" /* ITERATE */, isKeyOnly ? MAP_KEY_ITERATE_KEY : ITERATE_KEY);
  831. // return a wrapped iterator which returns observed versions of the
  832. // values emitted from the real iterator
  833. return {
  834. // iterator protocol
  835. next() {
  836. const { value, done } = innerIterator.next();
  837. return done
  838. ? { value, done }
  839. : {
  840. value: isPair ? [wrap(value[0]), wrap(value[1])] : wrap(value),
  841. done
  842. };
  843. },
  844. // iterable protocol
  845. [Symbol.iterator]() {
  846. return this;
  847. }
  848. };
  849. };
  850. }
  851. function createReadonlyMethod(type) {
  852. return function (...args) {
  853. {
  854. const key = args[0] ? `on key "${args[0]}" ` : ``;
  855. console.warn(`${capitalize(type)} operation ${key}failed: target is readonly.`, toRaw(this));
  856. }
  857. return type === "delete" /* DELETE */ ? false : this;
  858. };
  859. }
  860. const mutableInstrumentations = {
  861. get(key) {
  862. return get$1(this, key);
  863. },
  864. get size() {
  865. return size(this);
  866. },
  867. has: has$1,
  868. add,
  869. set: set$1,
  870. delete: deleteEntry,
  871. clear,
  872. forEach: createForEach(false, false)
  873. };
  874. const shallowInstrumentations = {
  875. get(key) {
  876. return get$1(this, key, false, true);
  877. },
  878. get size() {
  879. return size(this);
  880. },
  881. has: has$1,
  882. add,
  883. set: set$1,
  884. delete: deleteEntry,
  885. clear,
  886. forEach: createForEach(false, true)
  887. };
  888. const readonlyInstrumentations = {
  889. get(key) {
  890. return get$1(this, key, true);
  891. },
  892. get size() {
  893. return size(this, true);
  894. },
  895. has(key) {
  896. return has$1.call(this, key, true);
  897. },
  898. add: createReadonlyMethod("add" /* ADD */),
  899. set: createReadonlyMethod("set" /* SET */),
  900. delete: createReadonlyMethod("delete" /* DELETE */),
  901. clear: createReadonlyMethod("clear" /* CLEAR */),
  902. forEach: createForEach(true, false)
  903. };
  904. const iteratorMethods = ['keys', 'values', 'entries', Symbol.iterator];
  905. iteratorMethods.forEach(method => {
  906. mutableInstrumentations[method] = createIterableMethod(method, false, false);
  907. readonlyInstrumentations[method] = createIterableMethod(method, true, false);
  908. shallowInstrumentations[method] = createIterableMethod(method, false, true);
  909. });
  910. function createInstrumentationGetter(isReadonly, shallow) {
  911. const instrumentations = shallow
  912. ? shallowInstrumentations
  913. : isReadonly
  914. ? readonlyInstrumentations
  915. : mutableInstrumentations;
  916. return (target, key, receiver) => {
  917. if (key === "__v_isReactive" /* IS_REACTIVE */) {
  918. return !isReadonly;
  919. }
  920. else if (key === "__v_isReadonly" /* IS_READONLY */) {
  921. return isReadonly;
  922. }
  923. else if (key === "__v_raw" /* RAW */) {
  924. return target;
  925. }
  926. return Reflect.get(hasOwn(instrumentations, key) && key in target
  927. ? instrumentations
  928. : target, key, receiver);
  929. };
  930. }
  931. const mutableCollectionHandlers = {
  932. get: createInstrumentationGetter(false, false)
  933. };
  934. const shallowCollectionHandlers = {
  935. get: createInstrumentationGetter(false, true)
  936. };
  937. const readonlyCollectionHandlers = {
  938. get: createInstrumentationGetter(true, false)
  939. };
  940. function checkIdentityKeys(target, has, key) {
  941. const rawKey = toRaw(key);
  942. if (rawKey !== key && has.call(target, rawKey)) {
  943. const type = toRawType(target);
  944. console.warn(`Reactive ${type} contains both the raw and reactive ` +
  945. `versions of the same object${type === `Map` ? `as keys` : ``}, ` +
  946. `which can lead to inconsistencies. ` +
  947. `Avoid differentiating between the raw and reactive versions ` +
  948. `of an object and only use the reactive version if possible.`);
  949. }
  950. }
  951. const reactiveMap = new WeakMap();
  952. const readonlyMap = new WeakMap();
  953. function targetTypeMap(rawType) {
  954. switch (rawType) {
  955. case 'Object':
  956. case 'Array':
  957. return 1 /* COMMON */;
  958. case 'Map':
  959. case 'Set':
  960. case 'WeakMap':
  961. case 'WeakSet':
  962. return 2 /* COLLECTION */;
  963. default:
  964. return 0 /* INVALID */;
  965. }
  966. }
  967. function getTargetType(value) {
  968. return value["__v_skip" /* SKIP */] || !Object.isExtensible(value)
  969. ? 0 /* INVALID */
  970. : targetTypeMap(toRawType(value));
  971. }
  972. function reactive(target) {
  973. // if trying to observe a readonly proxy, return the readonly version.
  974. if (target && target["__v_isReadonly" /* IS_READONLY */]) {
  975. return target;
  976. }
  977. return createReactiveObject(target, false, mutableHandlers, mutableCollectionHandlers);
  978. }
  979. // Return a reactive-copy of the original object, where only the root level
  980. // properties are reactive, and does NOT unwrap refs nor recursively convert
  981. // returned properties.
  982. function shallowReactive(target) {
  983. return createReactiveObject(target, false, shallowReactiveHandlers, shallowCollectionHandlers);
  984. }
  985. function readonly(target) {
  986. return createReactiveObject(target, true, readonlyHandlers, readonlyCollectionHandlers);
  987. }
  988. // Return a reactive-copy of the original object, where only the root level
  989. // properties are readonly, and does NOT unwrap refs nor recursively convert
  990. // returned properties.
  991. // This is used for creating the props proxy object for stateful components.
  992. function shallowReadonly(target) {
  993. return createReactiveObject(target, true, shallowReadonlyHandlers, readonlyCollectionHandlers);
  994. }
  995. function createReactiveObject(target, isReadonly, baseHandlers, collectionHandlers) {
  996. if (!isObject(target)) {
  997. {
  998. console.warn(`value cannot be made reactive: ${String(target)}`);
  999. }
  1000. return target;
  1001. }
  1002. // target is already a Proxy, return it.
  1003. // exception: calling readonly() on a reactive object
  1004. if (target["__v_raw" /* RAW */] &&
  1005. !(isReadonly && target["__v_isReactive" /* IS_REACTIVE */])) {
  1006. return target;
  1007. }
  1008. // target already has corresponding Proxy
  1009. const proxyMap = isReadonly ? readonlyMap : reactiveMap;
  1010. const existingProxy = proxyMap.get(target);
  1011. if (existingProxy) {
  1012. return existingProxy;
  1013. }
  1014. // only a whitelist of value types can be observed.
  1015. const targetType = getTargetType(target);
  1016. if (targetType === 0 /* INVALID */) {
  1017. return target;
  1018. }
  1019. const proxy = new Proxy(target, targetType === 2 /* COLLECTION */ ? collectionHandlers : baseHandlers);
  1020. proxyMap.set(target, proxy);
  1021. return proxy;
  1022. }
  1023. function isReactive(value) {
  1024. if (isReadonly(value)) {
  1025. return isReactive(value["__v_raw" /* RAW */]);
  1026. }
  1027. return !!(value && value["__v_isReactive" /* IS_REACTIVE */]);
  1028. }
  1029. function isReadonly(value) {
  1030. return !!(value && value["__v_isReadonly" /* IS_READONLY */]);
  1031. }
  1032. function isProxy(value) {
  1033. return isReactive(value) || isReadonly(value);
  1034. }
  1035. function toRaw(observed) {
  1036. return ((observed && toRaw(observed["__v_raw" /* RAW */])) || observed);
  1037. }
  1038. function markRaw(value) {
  1039. def(value, "__v_skip" /* SKIP */, true);
  1040. return value;
  1041. }
  1042. const convert = (val) => isObject(val) ? reactive(val) : val;
  1043. function isRef(r) {
  1044. return Boolean(r && r.__v_isRef === true);
  1045. }
  1046. function ref(value) {
  1047. return createRef(value);
  1048. }
  1049. function shallowRef(value) {
  1050. return createRef(value, true);
  1051. }
  1052. class RefImpl {
  1053. constructor(_rawValue, _shallow = false) {
  1054. this._rawValue = _rawValue;
  1055. this._shallow = _shallow;
  1056. this.__v_isRef = true;
  1057. this._value = _shallow ? _rawValue : convert(_rawValue);
  1058. }
  1059. get value() {
  1060. track(toRaw(this), "get" /* GET */, 'value');
  1061. return this._value;
  1062. }
  1063. set value(newVal) {
  1064. if (hasChanged(toRaw(newVal), this._rawValue)) {
  1065. this._rawValue = newVal;
  1066. this._value = this._shallow ? newVal : convert(newVal);
  1067. trigger(toRaw(this), "set" /* SET */, 'value', newVal);
  1068. }
  1069. }
  1070. }
  1071. function createRef(rawValue, shallow = false) {
  1072. if (isRef(rawValue)) {
  1073. return rawValue;
  1074. }
  1075. return new RefImpl(rawValue, shallow);
  1076. }
  1077. function triggerRef(ref) {
  1078. trigger(ref, "set" /* SET */, 'value', ref.value );
  1079. }
  1080. function unref(ref) {
  1081. return isRef(ref) ? ref.value : ref;
  1082. }
  1083. const shallowUnwrapHandlers = {
  1084. get: (target, key, receiver) => unref(Reflect.get(target, key, receiver)),
  1085. set: (target, key, value, receiver) => {
  1086. const oldValue = target[key];
  1087. if (isRef(oldValue) && !isRef(value)) {
  1088. oldValue.value = value;
  1089. return true;
  1090. }
  1091. else {
  1092. return Reflect.set(target, key, value, receiver);
  1093. }
  1094. }
  1095. };
  1096. function proxyRefs(objectWithRefs) {
  1097. return isReactive(objectWithRefs)
  1098. ? objectWithRefs
  1099. : new Proxy(objectWithRefs, shallowUnwrapHandlers);
  1100. }
  1101. class CustomRefImpl {
  1102. constructor(factory) {
  1103. this.__v_isRef = true;
  1104. const { get, set } = factory(() => track(this, "get" /* GET */, 'value'), () => trigger(this, "set" /* SET */, 'value'));
  1105. this._get = get;
  1106. this._set = set;
  1107. }
  1108. get value() {
  1109. return this._get();
  1110. }
  1111. set value(newVal) {
  1112. this._set(newVal);
  1113. }
  1114. }
  1115. function customRef(factory) {
  1116. return new CustomRefImpl(factory);
  1117. }
  1118. function toRefs(object) {
  1119. if ( !isProxy(object)) {
  1120. console.warn(`toRefs() expects a reactive object but received a plain one.`);
  1121. }
  1122. const ret = isArray(object) ? new Array(object.length) : {};
  1123. for (const key in object) {
  1124. ret[key] = toRef(object, key);
  1125. }
  1126. return ret;
  1127. }
  1128. class ObjectRefImpl {
  1129. constructor(_object, _key) {
  1130. this._object = _object;
  1131. this._key = _key;
  1132. this.__v_isRef = true;
  1133. }
  1134. get value() {
  1135. return this._object[this._key];
  1136. }
  1137. set value(newVal) {
  1138. this._object[this._key] = newVal;
  1139. }
  1140. }
  1141. function toRef(object, key) {
  1142. return isRef(object[key])
  1143. ? object[key]
  1144. : new ObjectRefImpl(object, key);
  1145. }
  1146. class ComputedRefImpl {
  1147. constructor(getter, _setter, isReadonly) {
  1148. this._setter = _setter;
  1149. this._dirty = true;
  1150. this.__v_isRef = true;
  1151. this.effect = effect(getter, {
  1152. lazy: true,
  1153. scheduler: () => {
  1154. if (!this._dirty) {
  1155. this._dirty = true;
  1156. trigger(toRaw(this), "set" /* SET */, 'value');
  1157. }
  1158. }
  1159. });
  1160. this["__v_isReadonly" /* IS_READONLY */] = isReadonly;
  1161. }
  1162. get value() {
  1163. if (this._dirty) {
  1164. this._value = this.effect();
  1165. this._dirty = false;
  1166. }
  1167. track(toRaw(this), "get" /* GET */, 'value');
  1168. return this._value;
  1169. }
  1170. set value(newValue) {
  1171. this._setter(newValue);
  1172. }
  1173. }
  1174. function computed(getterOrOptions) {
  1175. let getter;
  1176. let setter;
  1177. if (isFunction(getterOrOptions)) {
  1178. getter = getterOrOptions;
  1179. setter = () => {
  1180. console.warn('Write operation failed: computed value is readonly');
  1181. }
  1182. ;
  1183. }
  1184. else {
  1185. getter = getterOrOptions.get;
  1186. setter = getterOrOptions.set;
  1187. }
  1188. return new ComputedRefImpl(getter, setter, isFunction(getterOrOptions) || !getterOrOptions.set);
  1189. }
  1190. const stack = [];
  1191. function pushWarningContext(vnode) {
  1192. stack.push(vnode);
  1193. }
  1194. function popWarningContext() {
  1195. stack.pop();
  1196. }
  1197. function warn(msg, ...args) {
  1198. // avoid props formatting or warn handler tracking deps that might be mutated
  1199. // during patch, leading to infinite recursion.
  1200. pauseTracking();
  1201. const instance = stack.length ? stack[stack.length - 1].component : null;
  1202. const appWarnHandler = instance && instance.appContext.config.warnHandler;
  1203. const trace = getComponentTrace();
  1204. if (appWarnHandler) {
  1205. callWithErrorHandling(appWarnHandler, instance, 11 /* APP_WARN_HANDLER */, [
  1206. msg + args.join(''),
  1207. instance && instance.proxy,
  1208. trace
  1209. .map(({ vnode }) => `at <${formatComponentName(instance, vnode.type)}>`)
  1210. .join('\n'),
  1211. trace
  1212. ]);
  1213. }
  1214. else {
  1215. const warnArgs = [`[Vue warn]: ${msg}`, ...args];
  1216. /* istanbul ignore if */
  1217. if (trace.length &&
  1218. // avoid spamming console during tests
  1219. !false) {
  1220. warnArgs.push(`\n`, ...formatTrace(trace));
  1221. }
  1222. console.warn(...warnArgs);
  1223. }
  1224. resetTracking();
  1225. }
  1226. function getComponentTrace() {
  1227. let currentVNode = stack[stack.length - 1];
  1228. if (!currentVNode) {
  1229. return [];
  1230. }
  1231. // we can't just use the stack because it will be incomplete during updates
  1232. // that did not start from the root. Re-construct the parent chain using
  1233. // instance parent pointers.
  1234. const normalizedStack = [];
  1235. while (currentVNode) {
  1236. const last = normalizedStack[0];
  1237. if (last && last.vnode === currentVNode) {
  1238. last.recurseCount++;
  1239. }
  1240. else {
  1241. normalizedStack.push({
  1242. vnode: currentVNode,
  1243. recurseCount: 0
  1244. });
  1245. }
  1246. const parentInstance = currentVNode.component && currentVNode.component.parent;
  1247. currentVNode = parentInstance && parentInstance.vnode;
  1248. }
  1249. return normalizedStack;
  1250. }
  1251. /* istanbul ignore next */
  1252. function formatTrace(trace) {
  1253. const logs = [];
  1254. trace.forEach((entry, i) => {
  1255. logs.push(...(i === 0 ? [] : [`\n`]), ...formatTraceEntry(entry));
  1256. });
  1257. return logs;
  1258. }
  1259. function formatTraceEntry({ vnode, recurseCount }) {
  1260. const postfix = recurseCount > 0 ? `... (${recurseCount} recursive calls)` : ``;
  1261. const isRoot = vnode.component ? vnode.component.parent == null : false;
  1262. const open = ` at <${formatComponentName(vnode.component, vnode.type, isRoot)}`;
  1263. const close = `>` + postfix;
  1264. return vnode.props
  1265. ? [open, ...formatProps(vnode.props), close]
  1266. : [open + close];
  1267. }
  1268. /* istanbul ignore next */
  1269. function formatProps(props) {
  1270. const res = [];
  1271. const keys = Object.keys(props);
  1272. keys.slice(0, 3).forEach(key => {
  1273. res.push(...formatProp(key, props[key]));
  1274. });
  1275. if (keys.length > 3) {
  1276. res.push(` ...`);
  1277. }
  1278. return res;
  1279. }
  1280. /* istanbul ignore next */
  1281. function formatProp(key, value, raw) {
  1282. if (isString(value)) {
  1283. value = JSON.stringify(value);
  1284. return raw ? value : [`${key}=${value}`];
  1285. }
  1286. else if (typeof value === 'number' ||
  1287. typeof value === 'boolean' ||
  1288. value == null) {
  1289. return raw ? value : [`${key}=${value}`];
  1290. }
  1291. else if (isRef(value)) {
  1292. value = formatProp(key, toRaw(value.value), true);
  1293. return raw ? value : [`${key}=Ref<`, value, `>`];
  1294. }
  1295. else if (isFunction(value)) {
  1296. return [`${key}=fn${value.name ? `<${value.name}>` : ``}`];
  1297. }
  1298. else {
  1299. value = toRaw(value);
  1300. return raw ? value : [`${key}=`, value];
  1301. }
  1302. }
  1303. const ErrorTypeStrings = {
  1304. ["bc" /* BEFORE_CREATE */]: 'beforeCreate hook',
  1305. ["c" /* CREATED */]: 'created hook',
  1306. ["bm" /* BEFORE_MOUNT */]: 'beforeMount hook',
  1307. ["m" /* MOUNTED */]: 'mounted hook',
  1308. ["bu" /* BEFORE_UPDATE */]: 'beforeUpdate hook',
  1309. ["u" /* UPDATED */]: 'updated',
  1310. ["bum" /* BEFORE_UNMOUNT */]: 'beforeUnmount hook',
  1311. ["um" /* UNMOUNTED */]: 'unmounted hook',
  1312. ["a" /* ACTIVATED */]: 'activated hook',
  1313. ["da" /* DEACTIVATED */]: 'deactivated hook',
  1314. ["ec" /* ERROR_CAPTURED */]: 'errorCaptured hook',
  1315. ["rtc" /* RENDER_TRACKED */]: 'renderTracked hook',
  1316. ["rtg" /* RENDER_TRIGGERED */]: 'renderTriggered hook',
  1317. [0 /* SETUP_FUNCTION */]: 'setup function',
  1318. [1 /* RENDER_FUNCTION */]: 'render function',
  1319. [2 /* WATCH_GETTER */]: 'watcher getter',
  1320. [3 /* WATCH_CALLBACK */]: 'watcher callback',
  1321. [4 /* WATCH_CLEANUP */]: 'watcher cleanup function',
  1322. [5 /* NATIVE_EVENT_HANDLER */]: 'native event handler',
  1323. [6 /* COMPONENT_EVENT_HANDLER */]: 'component event handler',
  1324. [7 /* VNODE_HOOK */]: 'vnode hook',
  1325. [8 /* DIRECTIVE_HOOK */]: 'directive hook',
  1326. [9 /* TRANSITION_HOOK */]: 'transition hook',
  1327. [10 /* APP_ERROR_HANDLER */]: 'app errorHandler',
  1328. [11 /* APP_WARN_HANDLER */]: 'app warnHandler',
  1329. [12 /* FUNCTION_REF */]: 'ref function',
  1330. [13 /* ASYNC_COMPONENT_LOADER */]: 'async component loader',
  1331. [14 /* SCHEDULER */]: 'scheduler flush. This is likely a Vue internals bug. ' +
  1332. 'Please open an issue at https://new-issue.vuejs.org/?repo=vuejs/vue-next'
  1333. };
  1334. function callWithErrorHandling(fn, instance, type, args) {
  1335. let res;
  1336. try {
  1337. res = args ? fn(...args) : fn();
  1338. }
  1339. catch (err) {
  1340. handleError(err, instance, type);
  1341. }
  1342. return res;
  1343. }
  1344. function callWithAsyncErrorHandling(fn, instance, type, args) {
  1345. if (isFunction(fn)) {
  1346. const res = callWithErrorHandling(fn, instance, type, args);
  1347. if (res && isPromise(res)) {
  1348. res.catch(err => {
  1349. handleError(err, instance, type);
  1350. });
  1351. }
  1352. return res;
  1353. }
  1354. const values = [];
  1355. for (let i = 0; i < fn.length; i++) {
  1356. values.push(callWithAsyncErrorHandling(fn[i], instance, type, args));
  1357. }
  1358. return values;
  1359. }
  1360. function handleError(err, instance, type, throwInDev = true) {
  1361. const contextVNode = instance ? instance.vnode : null;
  1362. if (instance) {
  1363. let cur = instance.parent;
  1364. // the exposed instance is the render proxy to keep it consistent with 2.x
  1365. const exposedInstance = instance.proxy;
  1366. // in production the hook receives only the error code
  1367. const errorInfo = ErrorTypeStrings[type] ;
  1368. while (cur) {
  1369. const errorCapturedHooks = cur.ec;
  1370. if (errorCapturedHooks) {
  1371. for (let i = 0; i < errorCapturedHooks.length; i++) {
  1372. if (errorCapturedHooks[i](err, exposedInstance, errorInfo)) {
  1373. return;
  1374. }
  1375. }
  1376. }
  1377. cur = cur.parent;
  1378. }
  1379. // app-level handling
  1380. const appErrorHandler = instance.appContext.config.errorHandler;
  1381. if (appErrorHandler) {
  1382. callWithErrorHandling(appErrorHandler, null, 10 /* APP_ERROR_HANDLER */, [err, exposedInstance, errorInfo]);
  1383. return;
  1384. }
  1385. }
  1386. logError(err, type, contextVNode, throwInDev);
  1387. }
  1388. function logError(err, type, contextVNode, throwInDev = true) {
  1389. {
  1390. const info = ErrorTypeStrings[type];
  1391. if (contextVNode) {
  1392. pushWarningContext(contextVNode);
  1393. }
  1394. warn(`Unhandled error${info ? ` during execution of ${info}` : ``}`);
  1395. if (contextVNode) {
  1396. popWarningContext();
  1397. }
  1398. // crash in dev by default so it's more noticeable
  1399. if (throwInDev) {
  1400. throw err;
  1401. }
  1402. else {
  1403. console.error(err);
  1404. }
  1405. }
  1406. }
  1407. let isFlushing = false;
  1408. let isFlushPending = false;
  1409. const queue = [];
  1410. let flushIndex = 0;
  1411. const pendingPreFlushCbs = [];
  1412. let activePreFlushCbs = null;
  1413. let preFlushIndex = 0;
  1414. const pendingPostFlushCbs = [];
  1415. let activePostFlushCbs = null;
  1416. let postFlushIndex = 0;
  1417. const resolvedPromise = Promise.resolve();
  1418. let currentFlushPromise = null;
  1419. let currentPreFlushParentJob = null;
  1420. const RECURSION_LIMIT = 100;
  1421. function nextTick(fn) {
  1422. const p = currentFlushPromise || resolvedPromise;
  1423. return fn ? p.then(fn) : p;
  1424. }
  1425. function queueJob(job) {
  1426. // the dedupe search uses the startIndex argument of Array.includes()
  1427. // by default the search index includes the current job that is being run
  1428. // so it cannot recursively trigger itself again.
  1429. // if the job is a watch() callback, the search will start with a +1 index to
  1430. // allow it recursively trigger itself - it is the user's responsibility to
  1431. // ensure it doesn't end up in an infinite loop.
  1432. if ((!queue.length ||
  1433. !queue.includes(job, isFlushing && job.allowRecurse ? flushIndex + 1 : flushIndex)) &&
  1434. job !== currentPreFlushParentJob) {
  1435. queue.push(job);
  1436. queueFlush();
  1437. }
  1438. }
  1439. function queueFlush() {
  1440. if (!isFlushing && !isFlushPending) {
  1441. isFlushPending = true;
  1442. currentFlushPromise = resolvedPromise.then(flushJobs);
  1443. }
  1444. }
  1445. function invalidateJob(job) {
  1446. const i = queue.indexOf(job);
  1447. if (i > -1) {
  1448. queue[i] = null;
  1449. }
  1450. }
  1451. function queueCb(cb, activeQueue, pendingQueue, index) {
  1452. if (!isArray(cb)) {
  1453. if (!activeQueue ||
  1454. !activeQueue.includes(cb, cb.allowRecurse ? index + 1 : index)) {
  1455. pendingQueue.push(cb);
  1456. }
  1457. }
  1458. else {
  1459. // if cb is an array, it is a component lifecycle hook which can only be
  1460. // triggered by a job, which is already deduped in the main queue, so
  1461. // we can skip duplicate check here to improve perf
  1462. pendingQueue.push(...cb);
  1463. }
  1464. queueFlush();
  1465. }
  1466. function queuePreFlushCb(cb) {
  1467. queueCb(cb, activePreFlushCbs, pendingPreFlushCbs, preFlushIndex);
  1468. }
  1469. function queuePostFlushCb(cb) {
  1470. queueCb(cb, activePostFlushCbs, pendingPostFlushCbs, postFlushIndex);
  1471. }
  1472. function flushPreFlushCbs(seen, parentJob = null) {
  1473. if (pendingPreFlushCbs.length) {
  1474. currentPreFlushParentJob = parentJob;
  1475. activePreFlushCbs = [...new Set(pendingPreFlushCbs)];
  1476. pendingPreFlushCbs.length = 0;
  1477. {
  1478. seen = seen || new Map();
  1479. }
  1480. for (preFlushIndex = 0; preFlushIndex < activePreFlushCbs.length; preFlushIndex++) {
  1481. {
  1482. checkRecursiveUpdates(seen, activePreFlushCbs[preFlushIndex]);
  1483. }
  1484. activePreFlushCbs[preFlushIndex]();
  1485. }
  1486. activePreFlushCbs = null;
  1487. preFlushIndex = 0;
  1488. currentPreFlushParentJob = null;
  1489. // recursively flush until it drains
  1490. flushPreFlushCbs(seen, parentJob);
  1491. }
  1492. }
  1493. function flushPostFlushCbs(seen) {
  1494. if (pendingPostFlushCbs.length) {
  1495. const deduped = [...new Set(pendingPostFlushCbs)];
  1496. pendingPostFlushCbs.length = 0;
  1497. // #1947 already has active queue, nested flushPostFlushCbs call
  1498. if (activePostFlushCbs) {
  1499. activePostFlushCbs.push(...deduped);
  1500. return;
  1501. }
  1502. activePostFlushCbs = deduped;
  1503. {
  1504. seen = seen || new Map();
  1505. }
  1506. activePostFlushCbs.sort((a, b) => getId(a) - getId(b));
  1507. for (postFlushIndex = 0; postFlushIndex < activePostFlushCbs.length; postFlushIndex++) {
  1508. {
  1509. checkRecursiveUpdates(seen, activePostFlushCbs[postFlushIndex]);
  1510. }
  1511. activePostFlushCbs[postFlushIndex]();
  1512. }
  1513. activePostFlushCbs = null;
  1514. postFlushIndex = 0;
  1515. }
  1516. }
  1517. const getId = (job) => job.id == null ? Infinity : job.id;
  1518. function flushJobs(seen) {
  1519. isFlushPending = false;
  1520. isFlushing = true;
  1521. {
  1522. seen = seen || new Map();
  1523. }
  1524. flushPreFlushCbs(seen);
  1525. // Sort queue before flush.
  1526. // This ensures that:
  1527. // 1. Components are updated from parent to child. (because parent is always
  1528. // created before the child so its render effect will have smaller
  1529. // priority number)
  1530. // 2. If a component is unmounted during a parent component's update,
  1531. // its update can be skipped.
  1532. // Jobs can never be null before flush starts, since they are only invalidated
  1533. // during execution of another flushed job.
  1534. queue.sort((a, b) => getId(a) - getId(b));
  1535. try {
  1536. for (flushIndex = 0; flushIndex < queue.length; flushIndex++) {
  1537. const job = queue[flushIndex];
  1538. if (job) {
  1539. if (true) {
  1540. checkRecursiveUpdates(seen, job);
  1541. }
  1542. callWithErrorHandling(job, null, 14 /* SCHEDULER */);
  1543. }
  1544. }
  1545. }
  1546. finally {
  1547. flushIndex = 0;
  1548. queue.length = 0;
  1549. flushPostFlushCbs(seen);
  1550. isFlushing = false;
  1551. currentFlushPromise = null;
  1552. // some postFlushCb queued jobs!
  1553. // keep flushing until it drains.
  1554. if (queue.length || pendingPostFlushCbs.length) {
  1555. flushJobs(seen);
  1556. }
  1557. }
  1558. }
  1559. function checkRecursiveUpdates(seen, fn) {
  1560. if (!seen.has(fn)) {
  1561. seen.set(fn, 1);
  1562. }
  1563. else {
  1564. const count = seen.get(fn);
  1565. if (count > RECURSION_LIMIT) {
  1566. throw new Error(`Maximum recursive updates exceeded. ` +
  1567. `This means you have a reactive effect that is mutating its own ` +
  1568. `dependencies and thus recursively triggering itself. Possible sources ` +
  1569. `include component template, render function, updated hook or ` +
  1570. `watcher source function.`);
  1571. }
  1572. else {
  1573. seen.set(fn, count + 1);
  1574. }
  1575. }
  1576. }
  1577. /* eslint-disable no-restricted-globals */
  1578. let isHmrUpdating = false;
  1579. const hmrDirtyComponents = new Set();
  1580. // Expose the HMR runtime on the global object
  1581. // This makes it entirely tree-shakable without polluting the exports and makes
  1582. // it easier to be used in toolings like vue-loader
  1583. // Note: for a component to be eligible for HMR it also needs the __hmrId option
  1584. // to be set so that its instances can be registered / removed.
  1585. {
  1586. const globalObject = typeof global !== 'undefined'
  1587. ? global
  1588. : typeof self !== 'undefined'
  1589. ? self
  1590. : typeof window !== 'undefined'
  1591. ? window
  1592. : {};
  1593. globalObject.__VUE_HMR_RUNTIME__ = {
  1594. createRecord: tryWrap(createRecord),
  1595. rerender: tryWrap(rerender),
  1596. reload: tryWrap(reload)
  1597. };
  1598. }
  1599. const map = new Map();
  1600. function registerHMR(instance) {
  1601. const id = instance.type.__hmrId;
  1602. let record = map.get(id);
  1603. if (!record) {
  1604. createRecord(id);
  1605. record = map.get(id);
  1606. }
  1607. record.add(instance);
  1608. }
  1609. function unregisterHMR(instance) {
  1610. map.get(instance.type.__hmrId).delete(instance);
  1611. }
  1612. function createRecord(id) {
  1613. if (map.has(id)) {
  1614. return false;
  1615. }
  1616. map.set(id, new Set());
  1617. return true;
  1618. }
  1619. function rerender(id, newRender) {
  1620. const record = map.get(id);
  1621. if (!record)
  1622. return;
  1623. // Array.from creates a snapshot which avoids the set being mutated during
  1624. // updates
  1625. Array.from(record).forEach(instance => {
  1626. if (newRender) {
  1627. instance.render = newRender;
  1628. }
  1629. instance.renderCache = [];
  1630. // this flag forces child components with slot content to update
  1631. isHmrUpdating = true;
  1632. instance.update();
  1633. isHmrUpdating = false;
  1634. });
  1635. }
  1636. function reload(id, newComp) {
  1637. const record = map.get(id);
  1638. if (!record)
  1639. return;
  1640. // Array.from creates a snapshot which avoids the set being mutated during
  1641. // updates
  1642. Array.from(record).forEach(instance => {
  1643. const comp = instance.type;
  1644. if (!hmrDirtyComponents.has(comp)) {
  1645. // 1. Update existing comp definition to match new one
  1646. newComp = isClassComponent(newComp) ? newComp.__vccOpts : newComp;
  1647. extend(comp, newComp);
  1648. for (const key in comp) {
  1649. if (!(key in newComp)) {
  1650. delete comp[key];
  1651. }
  1652. }
  1653. // 2. Mark component dirty. This forces the renderer to replace the component
  1654. // on patch.
  1655. hmrDirtyComponents.add(comp);
  1656. // 3. Make sure to unmark the component after the reload.
  1657. queuePostFlushCb(() => {
  1658. hmrDirtyComponents.delete(comp);
  1659. });
  1660. }
  1661. if (instance.parent) {
  1662. // 4. Force the parent instance to re-render. This will cause all updated
  1663. // components to be unmounted and re-mounted. Queue the update so that we
  1664. // don't end up forcing the same parent to re-render multiple times.
  1665. queueJob(instance.parent.update);
  1666. }
  1667. else if (instance.appContext.reload) {
  1668. // root instance mounted via createApp() has a reload method
  1669. instance.appContext.reload();
  1670. }
  1671. else if (typeof window !== 'undefined') {
  1672. // root instance inside tree created via raw render(). Force reload.
  1673. window.location.reload();
  1674. }
  1675. else {
  1676. console.warn('[HMR] Root or manually mounted instance modified. Full reload required.');
  1677. }
  1678. });
  1679. }
  1680. function tryWrap(fn) {
  1681. return (id, arg) => {
  1682. try {
  1683. return fn(id, arg);
  1684. }
  1685. catch (e) {
  1686. console.error(e);
  1687. console.warn(`[HMR] Something went wrong during Vue component hot-reload. ` +
  1688. `Full reload required.`);
  1689. }
  1690. };
  1691. }
  1692. function setDevtoolsHook(hook) {
  1693. exports.devtools = hook;
  1694. }
  1695. function devtoolsInitApp(app, version) {
  1696. // TODO queue if devtools is undefined
  1697. if (!exports.devtools)
  1698. return;
  1699. exports.devtools.emit("app:init" /* APP_INIT */, app, version, {
  1700. Fragment,
  1701. Text,
  1702. Comment,
  1703. Static
  1704. });
  1705. }
  1706. function devtoolsUnmountApp(app) {
  1707. if (!exports.devtools)
  1708. return;
  1709. exports.devtools.emit("app:unmount" /* APP_UNMOUNT */, app);
  1710. }
  1711. const devtoolsComponentAdded = /*#__PURE__*/ createDevtoolsComponentHook("component:added" /* COMPONENT_ADDED */);
  1712. const devtoolsComponentUpdated = /*#__PURE__*/ createDevtoolsComponentHook("component:updated" /* COMPONENT_UPDATED */);
  1713. const devtoolsComponentRemoved = /*#__PURE__*/ createDevtoolsComponentHook("component:removed" /* COMPONENT_REMOVED */);
  1714. function createDevtoolsComponentHook(hook) {
  1715. return (component) => {
  1716. if (!exports.devtools)
  1717. return;
  1718. exports.devtools.emit(hook, component.appContext.app, component.uid, component.parent ? component.parent.uid : undefined);
  1719. };
  1720. }
  1721. function devtoolsComponentEmit(component, event, params) {
  1722. if (!exports.devtools)
  1723. return;
  1724. exports.devtools.emit("component:emit" /* COMPONENT_EMIT */, component.appContext.app, component, event, params);
  1725. }
  1726. function emit(instance, event, ...args) {
  1727. const props = instance.vnode.props || EMPTY_OBJ;
  1728. {
  1729. const { emitsOptions, propsOptions: [propsOptions] } = instance;
  1730. if (emitsOptions) {
  1731. if (!(event in emitsOptions)) {
  1732. if (!propsOptions || !(`on` + capitalize(event) in propsOptions)) {
  1733. warn(`Component emitted event "${event}" but it is neither declared in ` +
  1734. `the emits option nor as an "on${capitalize(event)}" prop.`);
  1735. }
  1736. }
  1737. else {
  1738. const validator = emitsOptions[event];
  1739. if (isFunction(validator)) {
  1740. const isValid = validator(...args);
  1741. if (!isValid) {
  1742. warn(`Invalid event arguments: event validation failed for event "${event}".`);
  1743. }
  1744. }
  1745. }
  1746. }
  1747. }
  1748. {
  1749. devtoolsComponentEmit(instance, event, args);
  1750. }
  1751. let handlerName = `on${capitalize(event)}`;
  1752. let handler = props[handlerName];
  1753. // for v-model update:xxx events, also trigger kebab-case equivalent
  1754. // for props passed via kebab-case
  1755. if (!handler && event.startsWith('update:')) {
  1756. handlerName = `on${capitalize(hyphenate(event))}`;
  1757. handler = props[handlerName];
  1758. }
  1759. if (!handler) {
  1760. handler = props[handlerName + `Once`];
  1761. if (!instance.emitted) {
  1762. (instance.emitted = {})[handlerName] = true;
  1763. }
  1764. else if (instance.emitted[handlerName]) {
  1765. return;
  1766. }
  1767. }
  1768. if (handler) {
  1769. callWithAsyncErrorHandling(handler, instance, 6 /* COMPONENT_EVENT_HANDLER */, args);
  1770. }
  1771. }
  1772. function normalizeEmitsOptions(comp, appContext, asMixin = false) {
  1773. const appId = appContext.app ? appContext.app._uid : -1;
  1774. const cache = comp.__emits || (comp.__emits = {});
  1775. const cached = cache[appId];
  1776. if (cached !== undefined) {
  1777. return cached;
  1778. }
  1779. const raw = comp.emits;
  1780. let normalized = {};
  1781. // apply mixin/extends props
  1782. let hasExtends = false;
  1783. if ( !isFunction(comp)) {
  1784. const extendEmits = (raw) => {
  1785. hasExtends = true;
  1786. extend(normalized, normalizeEmitsOptions(raw, appContext, true));
  1787. };
  1788. if (!asMixin && appContext.mixins.length) {
  1789. appContext.mixins.forEach(extendEmits);
  1790. }
  1791. if (comp.extends) {
  1792. extendEmits(comp.extends);
  1793. }
  1794. if (comp.mixins) {
  1795. comp.mixins.forEach(extendEmits);
  1796. }
  1797. }
  1798. if (!raw && !hasExtends) {
  1799. return (cache[appId] = null);
  1800. }
  1801. if (isArray(raw)) {
  1802. raw.forEach(key => (normalized[key] = null));
  1803. }
  1804. else {
  1805. extend(normalized, raw);
  1806. }
  1807. return (cache[appId] = normalized);
  1808. }
  1809. // Check if an incoming prop key is a declared emit event listener.
  1810. // e.g. With `emits: { click: null }`, props named `onClick` and `onclick` are
  1811. // both considered matched listeners.
  1812. function isEmitListener(options, key) {
  1813. if (!options || !isOn(key)) {
  1814. return false;
  1815. }
  1816. key = key.replace(/Once$/, '');
  1817. return (hasOwn(options, key[2].toLowerCase() + key.slice(3)) ||
  1818. hasOwn(options, key.slice(2)));
  1819. }
  1820. // mark the current rendering instance for asset resolution (e.g.
  1821. // resolveComponent, resolveDirective) during render
  1822. let currentRenderingInstance = null;
  1823. function setCurrentRenderingInstance(instance) {
  1824. currentRenderingInstance = instance;
  1825. }
  1826. // dev only flag to track whether $attrs was used during render.
  1827. // If $attrs was used during render then the warning for failed attrs
  1828. // fallthrough can be suppressed.
  1829. let accessedAttrs = false;
  1830. function markAttrsAccessed() {
  1831. accessedAttrs = true;
  1832. }
  1833. function renderComponentRoot(instance) {
  1834. const { type: Component, vnode, proxy, withProxy, props, propsOptions: [propsOptions], slots, attrs, emit, render, renderCache, data, setupState, ctx } = instance;
  1835. let result;
  1836. currentRenderingInstance = instance;
  1837. {
  1838. accessedAttrs = false;
  1839. }
  1840. try {
  1841. let fallthroughAttrs;
  1842. if (vnode.shapeFlag & 4 /* STATEFUL_COMPONENT */) {
  1843. // withProxy is a proxy with a different `has` trap only for
  1844. // runtime-compiled render functions using `with` block.
  1845. const proxyToUse = withProxy || proxy;
  1846. result = normalizeVNode(render.call(proxyToUse, proxyToUse, renderCache, props, setupState, data, ctx));
  1847. fallthroughAttrs = attrs;
  1848. }
  1849. else {
  1850. // functional
  1851. const render = Component;
  1852. // in dev, mark attrs accessed if optional props (attrs === props)
  1853. if (true && attrs === props) {
  1854. markAttrsAccessed();
  1855. }
  1856. result = normalizeVNode(render.length > 1
  1857. ? render(props, true
  1858. ? {
  1859. get attrs() {
  1860. markAttrsAccessed();
  1861. return attrs;
  1862. },
  1863. slots,
  1864. emit
  1865. }
  1866. : { attrs, slots, emit })
  1867. : render(props, null /* we know it doesn't need it */));
  1868. fallthroughAttrs = Component.props
  1869. ? attrs
  1870. : getFunctionalFallthrough(attrs);
  1871. }
  1872. // attr merging
  1873. // in dev mode, comments are preserved, and it's possible for a template
  1874. // to have comments along side the root element which makes it a fragment
  1875. let root = result;
  1876. let setRoot = undefined;
  1877. if (true) {
  1878. ;
  1879. [root, setRoot] = getChildRoot(result);
  1880. }
  1881. if (Component.inheritAttrs !== false && fallthroughAttrs) {
  1882. const keys = Object.keys(fallthroughAttrs);
  1883. const { shapeFlag } = root;
  1884. if (keys.length) {
  1885. if (shapeFlag & 1 /* ELEMENT */ ||
  1886. shapeFlag & 6 /* COMPONENT */) {
  1887. if (propsOptions && keys.some(isModelListener)) {
  1888. // If a v-model listener (onUpdate:xxx) has a corresponding declared
  1889. // prop, it indicates this component expects to handle v-model and
  1890. // it should not fallthrough.
  1891. // related: #1543, #1643, #1989
  1892. fallthroughAttrs = filterModelListeners(fallthroughAttrs, propsOptions);
  1893. }
  1894. root = cloneVNode(root, fallthroughAttrs);
  1895. }
  1896. else if (true && !accessedAttrs && root.type !== Comment) {
  1897. const allAttrs = Object.keys(attrs);
  1898. const eventAttrs = [];
  1899. const extraAttrs = [];
  1900. for (let i = 0, l = allAttrs.length; i < l; i++) {
  1901. const key = allAttrs[i];
  1902. if (isOn(key)) {
  1903. // ignore v-model handlers when they fail to fallthrough
  1904. if (!isModelListener(key)) {
  1905. // remove `on`, lowercase first letter to reflect event casing
  1906. // accurately
  1907. eventAttrs.push(key[2].toLowerCase() + key.slice(3));
  1908. }
  1909. }
  1910. else {
  1911. extraAttrs.push(key);
  1912. }
  1913. }
  1914. if (extraAttrs.length) {
  1915. warn(`Extraneous non-props attributes (` +
  1916. `${extraAttrs.join(', ')}) ` +
  1917. `were passed to component but could not be automatically inherited ` +
  1918. `because component renders fragment or text root nodes.`);
  1919. }
  1920. if (eventAttrs.length) {
  1921. warn(`Extraneous non-emits event listeners (` +
  1922. `${eventAttrs.join(', ')}) ` +
  1923. `were passed to component but could not be automatically inherited ` +
  1924. `because component renders fragment or text root nodes. ` +
  1925. `If the listener is intended to be a component custom event listener only, ` +
  1926. `declare it using the "emits" option.`);
  1927. }
  1928. }
  1929. }
  1930. }
  1931. // inherit directives
  1932. if (vnode.dirs) {
  1933. if (true && !isElementRoot(root)) {
  1934. warn(`Runtime directive used on component with non-element root node. ` +
  1935. `The directives will not function as intended.`);
  1936. }
  1937. root.dirs = vnode.dirs;
  1938. }
  1939. // inherit transition data
  1940. if (vnode.transition) {
  1941. if (true && !isElementRoot(root)) {
  1942. warn(`Component inside <Transition> renders non-element root node ` +
  1943. `that cannot be animated.`);
  1944. }
  1945. root.transition = vnode.transition;
  1946. }
  1947. if (true && setRoot) {
  1948. setRoot(root);
  1949. }
  1950. else {
  1951. result = root;
  1952. }
  1953. }
  1954. catch (err) {
  1955. handleError(err, instance, 1 /* RENDER_FUNCTION */);
  1956. result = createVNode(Comment);
  1957. }
  1958. currentRenderingInstance = null;
  1959. return result;
  1960. }
  1961. /**
  1962. * dev only
  1963. * In dev mode, template root level comments are rendered, which turns the
  1964. * template into a fragment root, but we need to locate the single element
  1965. * root for attrs and scope id processing.
  1966. */
  1967. const getChildRoot = (vnode) => {
  1968. if (vnode.type !== Fragment) {
  1969. return [vnode, undefined];
  1970. }
  1971. const rawChildren = vnode.children;
  1972. const dynamicChildren = vnode.dynamicChildren;
  1973. const childRoot = filterSingleRoot(rawChildren);
  1974. if (!childRoot) {
  1975. return [vnode, undefined];
  1976. }
  1977. const index = rawChildren.indexOf(childRoot);
  1978. const dynamicIndex = dynamicChildren ? dynamicChildren.indexOf(childRoot) : -1;
  1979. const setRoot = (updatedRoot) => {
  1980. rawChildren[index] = updatedRoot;
  1981. if (dynamicIndex > -1) {
  1982. dynamicChildren[dynamicIndex] = updatedRoot;
  1983. }
  1984. else if (dynamicChildren && updatedRoot.patchFlag > 0) {
  1985. dynamicChildren.push(updatedRoot);
  1986. }
  1987. };
  1988. return [normalizeVNode(childRoot), setRoot];
  1989. };
  1990. /**
  1991. * dev only
  1992. */
  1993. function filterSingleRoot(children) {
  1994. const filtered = children.filter(child => {
  1995. return !(isVNode(child) &&
  1996. child.type === Comment &&
  1997. child.children !== 'v-if');
  1998. });
  1999. return filtered.length === 1 && isVNode(filtered[0]) ? filtered[0] : null;
  2000. }
  2001. const getFunctionalFallthrough = (attrs) => {
  2002. let res;
  2003. for (const key in attrs) {
  2004. if (key === 'class' || key === 'style' || isOn(key)) {
  2005. (res || (res = {}))[key] = attrs[key];
  2006. }
  2007. }
  2008. return res;
  2009. };
  2010. const filterModelListeners = (attrs, props) => {
  2011. const res = {};
  2012. for (const key in attrs) {
  2013. if (!isModelListener(key) || !(key.slice(9) in props)) {
  2014. res[key] = attrs[key];
  2015. }
  2016. }
  2017. return res;
  2018. };
  2019. const isElementRoot = (vnode) => {
  2020. return (vnode.shapeFlag & 6 /* COMPONENT */ ||
  2021. vnode.shapeFlag & 1 /* ELEMENT */ ||
  2022. vnode.type === Comment // potential v-if branch switch
  2023. );
  2024. };
  2025. function shouldUpdateComponent(prevVNode, nextVNode, optimized) {
  2026. const { props: prevProps, children: prevChildren, component } = prevVNode;
  2027. const { props: nextProps, children: nextChildren, patchFlag } = nextVNode;
  2028. const emits = component.emitsOptions;
  2029. // Parent component's render function was hot-updated. Since this may have
  2030. // caused the child component's slots content to have changed, we need to
  2031. // force the child to update as well.
  2032. if ( (prevChildren || nextChildren) && isHmrUpdating) {
  2033. return true;
  2034. }
  2035. // force child update for runtime directive or transition on component vnode.
  2036. if (nextVNode.dirs || nextVNode.transition) {
  2037. return true;
  2038. }
  2039. if (optimized && patchFlag > 0) {
  2040. if (patchFlag & 1024 /* DYNAMIC_SLOTS */) {
  2041. // slot content that references values that might have changed,
  2042. // e.g. in a v-for
  2043. return true;
  2044. }
  2045. if (patchFlag & 16 /* FULL_PROPS */) {
  2046. if (!prevProps) {
  2047. return !!nextProps;
  2048. }
  2049. // presence of this flag indicates props are always non-null
  2050. return hasPropsChanged(prevProps, nextProps, emits);
  2051. }
  2052. else if (patchFlag & 8 /* PROPS */) {
  2053. const dynamicProps = nextVNode.dynamicProps;
  2054. for (let i = 0; i < dynamicProps.length; i++) {
  2055. const key = dynamicProps[i];
  2056. if (nextProps[key] !== prevProps[key] &&
  2057. !isEmitListener(emits, key)) {
  2058. return true;
  2059. }
  2060. }
  2061. }
  2062. }
  2063. else {
  2064. // this path is only taken by manually written render functions
  2065. // so presence of any children leads to a forced update
  2066. if (prevChildren || nextChildren) {
  2067. if (!nextChildren || !nextChildren.$stable) {
  2068. return true;
  2069. }
  2070. }
  2071. if (prevProps === nextProps) {
  2072. return false;
  2073. }
  2074. if (!prevProps) {
  2075. return !!nextProps;
  2076. }
  2077. if (!nextProps) {
  2078. return true;
  2079. }
  2080. return hasPropsChanged(prevProps, nextProps, emits);
  2081. }
  2082. return false;
  2083. }
  2084. function hasPropsChanged(prevProps, nextProps, emitsOptions) {
  2085. const nextKeys = Object.keys(nextProps);
  2086. if (nextKeys.length !== Object.keys(prevProps).length) {
  2087. return true;
  2088. }
  2089. for (let i = 0; i < nextKeys.length; i++) {
  2090. const key = nextKeys[i];
  2091. if (nextProps[key] !== prevProps[key] &&
  2092. !isEmitListener(emitsOptions, key)) {
  2093. return true;
  2094. }
  2095. }
  2096. return false;
  2097. }
  2098. function updateHOCHostEl({ vnode, parent }, el // HostNode
  2099. ) {
  2100. while (parent && parent.subTree === vnode) {
  2101. (vnode = parent.vnode).el = el;
  2102. parent = parent.parent;
  2103. }
  2104. }
  2105. const isSuspense = (type) => type.__isSuspense;
  2106. // Suspense exposes a component-like API, and is treated like a component
  2107. // in the compiler, but internally it's a special built-in type that hooks
  2108. // directly into the renderer.
  2109. const SuspenseImpl = {
  2110. // In order to make Suspense tree-shakable, we need to avoid importing it
  2111. // directly in the renderer. The renderer checks for the __isSuspense flag
  2112. // on a vnode's type and calls the `process` method, passing in renderer
  2113. // internals.
  2114. __isSuspense: true,
  2115. process(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, optimized,
  2116. // platform-specific impl passed from renderer
  2117. rendererInternals) {
  2118. if (n1 == null) {
  2119. mountSuspense(n2, container, anchor, parentComponent, parentSuspense, isSVG, optimized, rendererInternals);
  2120. }
  2121. else {
  2122. patchSuspense(n1, n2, container, anchor, parentComponent, isSVG, optimized, rendererInternals);
  2123. }
  2124. },
  2125. hydrate: hydrateSuspense,
  2126. create: createSuspenseBoundary
  2127. };
  2128. // Force-casted public typing for h and TSX props inference
  2129. const Suspense = ( SuspenseImpl
  2130. );
  2131. function mountSuspense(vnode, container, anchor, parentComponent, parentSuspense, isSVG, optimized, rendererInternals) {
  2132. const { p: patch, o: { createElement } } = rendererInternals;
  2133. const hiddenContainer = createElement('div');
  2134. const suspense = (vnode.suspense = createSuspenseBoundary(vnode, parentSuspense, parentComponent, container, hiddenContainer, anchor, isSVG, optimized, rendererInternals));
  2135. // start mounting the content subtree in an off-dom container
  2136. patch(null, (suspense.pendingBranch = vnode.ssContent), hiddenContainer, null, parentComponent, suspense, isSVG, optimized);
  2137. // now check if we have encountered any async deps
  2138. if (suspense.deps > 0) {
  2139. // has async
  2140. // mount the fallback tree
  2141. patch(null, vnode.ssFallback, container, anchor, parentComponent, null, // fallback tree will not have suspense context
  2142. isSVG, optimized);
  2143. setActiveBranch(suspense, vnode.ssFallback);
  2144. }
  2145. else {
  2146. // Suspense has no async deps. Just resolve.
  2147. suspense.resolve();
  2148. }
  2149. }
  2150. function patchSuspense(n1, n2, container, anchor, parentComponent, isSVG, optimized, { p: patch, um: unmount, o: { createElement } }) {
  2151. const suspense = (n2.suspense = n1.suspense);
  2152. suspense.vnode = n2;
  2153. n2.el = n1.el;
  2154. const newBranch = n2.ssContent;
  2155. const newFallback = n2.ssFallback;
  2156. const { activeBranch, pendingBranch, isInFallback, isHydrating } = suspense;
  2157. if (pendingBranch) {
  2158. suspense.pendingBranch = newBranch;
  2159. if (isSameVNodeType(newBranch, pendingBranch)) {
  2160. // same root type but content may have changed.
  2161. patch(pendingBranch, newBranch, suspense.hiddenContainer, null, parentComponent, suspense, isSVG, optimized);
  2162. if (suspense.deps <= 0) {
  2163. suspense.resolve();
  2164. }
  2165. else if (isInFallback) {
  2166. patch(activeBranch, newFallback, container, anchor, parentComponent, null, // fallback tree will not have suspense context
  2167. isSVG, optimized);
  2168. setActiveBranch(suspense, newFallback);
  2169. }
  2170. }
  2171. else {
  2172. // toggled before pending tree is resolved
  2173. suspense.pendingId++;
  2174. if (isHydrating) {
  2175. // if toggled before hydration is finished, the current DOM tree is
  2176. // no longer valid. set it as the active branch so it will be unmounted
  2177. // when resolved
  2178. suspense.isHydrating = false;
  2179. suspense.activeBranch = pendingBranch;
  2180. }
  2181. else {
  2182. unmount(pendingBranch, parentComponent, suspense);
  2183. }
  2184. // increment pending ID. this is used to invalidate async callbacks
  2185. // reset suspense state
  2186. suspense.deps = 0;
  2187. // discard effects from pending branch
  2188. suspense.effects.length = 0;
  2189. // discard previous container
  2190. suspense.hiddenContainer = createElement('div');
  2191. if (isInFallback) {
  2192. // already in fallback state
  2193. patch(null, newBranch, suspense.hiddenContainer, null, parentComponent, suspense, isSVG, optimized);
  2194. if (suspense.deps <= 0) {
  2195. suspense.resolve();
  2196. }
  2197. else {
  2198. patch(activeBranch, newFallback, container, anchor, parentComponent, null, // fallback tree will not have suspense context
  2199. isSVG, optimized);
  2200. setActiveBranch(suspense, newFallback);
  2201. }
  2202. }
  2203. else if (activeBranch && isSameVNodeType(newBranch, activeBranch)) {
  2204. // toggled "back" to current active branch
  2205. patch(activeBranch, newBranch, container, anchor, parentComponent, suspense, isSVG, optimized);
  2206. // force resolve
  2207. suspense.resolve(true);
  2208. }
  2209. else {
  2210. // switched to a 3rd branch
  2211. patch(null, newBranch, suspense.hiddenContainer, null, parentComponent, suspense, isSVG, optimized);
  2212. if (suspense.deps <= 0) {
  2213. suspense.resolve();
  2214. }
  2215. }
  2216. }
  2217. }
  2218. else {
  2219. if (activeBranch && isSameVNodeType(newBranch, activeBranch)) {
  2220. // root did not change, just normal patch
  2221. patch(activeBranch, newBranch, container, anchor, parentComponent, suspense, isSVG, optimized);
  2222. setActiveBranch(suspense, newBranch);
  2223. }
  2224. else {
  2225. // root node toggled
  2226. // invoke @pending event
  2227. const onPending = n2.props && n2.props.onPending;
  2228. if (isFunction(onPending)) {
  2229. onPending();
  2230. }
  2231. // mount pending branch in off-dom container
  2232. suspense.pendingBranch = newBranch;
  2233. suspense.pendingId++;
  2234. patch(null, newBranch, suspense.hiddenContainer, null, parentComponent, suspense, isSVG, optimized);
  2235. if (suspense.deps <= 0) {
  2236. // incoming branch has no async deps, resolve now.
  2237. suspense.resolve();
  2238. }
  2239. else {
  2240. const { timeout, pendingId } = suspense;
  2241. if (timeout > 0) {
  2242. setTimeout(() => {
  2243. if (suspense.pendingId === pendingId) {
  2244. suspense.fallback(newFallback);
  2245. }
  2246. }, timeout);
  2247. }
  2248. else if (timeout === 0) {
  2249. suspense.fallback(newFallback);
  2250. }
  2251. }
  2252. }
  2253. }
  2254. }
  2255. let hasWarned = false;
  2256. function createSuspenseBoundary(vnode, parent, parentComponent, container, hiddenContainer, anchor, isSVG, optimized, rendererInternals, isHydrating = false) {
  2257. /* istanbul ignore if */
  2258. if ( !hasWarned) {
  2259. hasWarned = true;
  2260. // @ts-ignore `console.info` cannot be null error
  2261. console[console.info ? 'info' : 'log'](`<Suspense> is an experimental feature and its API will likely change.`);
  2262. }
  2263. const { p: patch, m: move, um: unmount, n: next, o: { parentNode, remove } } = rendererInternals;
  2264. const timeout = toNumber(vnode.props && vnode.props.timeout);
  2265. const suspense = {
  2266. vnode,
  2267. parent,
  2268. parentComponent,
  2269. isSVG,
  2270. optimized,
  2271. container,
  2272. hiddenContainer,
  2273. anchor,
  2274. deps: 0,
  2275. pendingId: 0,
  2276. timeout: typeof timeout === 'number' ? timeout : -1,
  2277. activeBranch: null,
  2278. pendingBranch: null,
  2279. isInFallback: true,
  2280. isHydrating,
  2281. isUnmounted: false,
  2282. effects: [],
  2283. resolve(resume = false) {
  2284. {
  2285. if (!resume && !suspense.pendingBranch) {
  2286. throw new Error(`suspense.resolve() is called without a pending branch.`);
  2287. }
  2288. if (suspense.isUnmounted) {
  2289. throw new Error(`suspense.resolve() is called on an already unmounted suspense boundary.`);
  2290. }
  2291. }
  2292. const { vnode, activeBranch, pendingBranch, pendingId, effects, parentComponent, container } = suspense;
  2293. if (suspense.isHydrating) {
  2294. suspense.isHydrating = false;
  2295. }
  2296. else if (!resume) {
  2297. const delayEnter = activeBranch &&
  2298. pendingBranch.transition &&
  2299. pendingBranch.transition.mode === 'out-in';
  2300. if (delayEnter) {
  2301. activeBranch.transition.afterLeave = () => {
  2302. if (pendingId === suspense.pendingId) {
  2303. move(pendingBranch, container, anchor, 0 /* ENTER */);
  2304. }
  2305. };
  2306. }
  2307. // this is initial anchor on mount
  2308. let { anchor } = suspense;
  2309. // unmount current active tree
  2310. if (activeBranch) {
  2311. // if the fallback tree was mounted, it may have been moved
  2312. // as part of a parent suspense. get the latest anchor for insertion
  2313. anchor = next(activeBranch);
  2314. unmount(activeBranch, parentComponent, suspense, true);
  2315. }
  2316. if (!delayEnter) {
  2317. // move content from off-dom container to actual container
  2318. move(pendingBranch, container, anchor, 0 /* ENTER */);
  2319. }
  2320. }
  2321. setActiveBranch(suspense, pendingBranch);
  2322. suspense.pendingBranch = null;
  2323. suspense.isInFallback = false;
  2324. // flush buffered effects
  2325. // check if there is a pending parent suspense
  2326. let parent = suspense.parent;
  2327. let hasUnresolvedAncestor = false;
  2328. while (parent) {
  2329. if (parent.pendingBranch) {
  2330. // found a pending parent suspense, merge buffered post jobs
  2331. // into that parent
  2332. parent.effects.push(...effects);
  2333. hasUnresolvedAncestor = true;
  2334. break;
  2335. }
  2336. parent = parent.parent;
  2337. }
  2338. // no pending parent suspense, flush all jobs
  2339. if (!hasUnresolvedAncestor) {
  2340. queuePostFlushCb(effects);
  2341. }
  2342. suspense.effects = [];
  2343. // invoke @resolve event
  2344. const onResolve = vnode.props && vnode.props.onResolve;
  2345. if (isFunction(onResolve)) {
  2346. onResolve();
  2347. }
  2348. },
  2349. fallback(fallbackVNode) {
  2350. if (!suspense.pendingBranch) {
  2351. return;
  2352. }
  2353. const { vnode, activeBranch, parentComponent, container, isSVG, optimized } = suspense;
  2354. // invoke @fallback event
  2355. const onFallback = vnode.props && vnode.props.onFallback;
  2356. if (isFunction(onFallback)) {
  2357. onFallback();
  2358. }
  2359. const anchor = next(activeBranch);
  2360. const mountFallback = () => {
  2361. if (!suspense.isInFallback) {
  2362. return;
  2363. }
  2364. // mount the fallback tree
  2365. patch(null, fallbackVNode, container, anchor, parentComponent, null, // fallback tree will not have suspense context
  2366. isSVG, optimized);
  2367. setActiveBranch(suspense, fallbackVNode);
  2368. };
  2369. const delayEnter = fallbackVNode.transition && fallbackVNode.transition.mode === 'out-in';
  2370. if (delayEnter) {
  2371. activeBranch.transition.afterLeave = mountFallback;
  2372. }
  2373. // unmount current active branch
  2374. unmount(activeBranch, parentComponent, null, // no suspense so unmount hooks fire now
  2375. true // shouldRemove
  2376. );
  2377. suspense.isInFallback = true;
  2378. if (!delayEnter) {
  2379. mountFallback();
  2380. }
  2381. },
  2382. move(container, anchor, type) {
  2383. suspense.activeBranch &&
  2384. move(suspense.activeBranch, container, anchor, type);
  2385. suspense.container = container;
  2386. },
  2387. next() {
  2388. return suspense.activeBranch && next(suspense.activeBranch);
  2389. },
  2390. registerDep(instance, setupRenderEffect) {
  2391. if (!suspense.pendingBranch) {
  2392. return;
  2393. }
  2394. const hydratedEl = instance.vnode.el;
  2395. suspense.deps++;
  2396. instance
  2397. .asyncDep.catch(err => {
  2398. handleError(err, instance, 0 /* SETUP_FUNCTION */);
  2399. })
  2400. .then(asyncSetupResult => {
  2401. // retry when the setup() promise resolves.
  2402. // component may have been unmounted before resolve.
  2403. if (instance.isUnmounted ||
  2404. suspense.isUnmounted ||
  2405. suspense.pendingId !== instance.suspenseId) {
  2406. return;
  2407. }
  2408. suspense.deps--;
  2409. // retry from this component
  2410. instance.asyncResolved = true;
  2411. const { vnode } = instance;
  2412. {
  2413. pushWarningContext(vnode);
  2414. }
  2415. handleSetupResult(instance, asyncSetupResult);
  2416. if (hydratedEl) {
  2417. // vnode may have been replaced if an update happened before the
  2418. // async dep is resolved.
  2419. vnode.el = hydratedEl;
  2420. }
  2421. const placeholder = !hydratedEl && instance.subTree.el;
  2422. setupRenderEffect(instance, vnode,
  2423. // component may have been moved before resolve.
  2424. // if this is not a hydration, instance.subTree will be the comment
  2425. // placeholder.
  2426. parentNode(hydratedEl || instance.subTree.el),
  2427. // anchor will not be used if this is hydration, so only need to
  2428. // consider the comment placeholder case.
  2429. hydratedEl ? null : next(instance.subTree), suspense, isSVG, optimized);
  2430. if (placeholder) {
  2431. remove(placeholder);
  2432. }
  2433. updateHOCHostEl(instance, vnode.el);
  2434. {
  2435. popWarningContext();
  2436. }
  2437. if (suspense.deps === 0) {
  2438. suspense.resolve();
  2439. }
  2440. });
  2441. },
  2442. unmount(parentSuspense, doRemove) {
  2443. suspense.isUnmounted = true;
  2444. if (suspense.activeBranch) {
  2445. unmount(suspense.activeBranch, parentComponent, parentSuspense, doRemove);
  2446. }
  2447. if (suspense.pendingBranch) {
  2448. unmount(suspense.pendingBranch, parentComponent, parentSuspense, doRemove);
  2449. }
  2450. }
  2451. };
  2452. return suspense;
  2453. }
  2454. function hydrateSuspense(node, vnode, parentComponent, parentSuspense, isSVG, optimized, rendererInternals, hydrateNode) {
  2455. /* eslint-disable no-restricted-globals */
  2456. const suspense = (vnode.suspense = createSuspenseBoundary(vnode, parentSuspense, parentComponent, node.parentNode, document.createElement('div'), null, isSVG, optimized, rendererInternals, true /* hydrating */));
  2457. // there are two possible scenarios for server-rendered suspense:
  2458. // - success: ssr content should be fully resolved
  2459. // - failure: ssr content should be the fallback branch.
  2460. // however, on the client we don't really know if it has failed or not
  2461. // attempt to hydrate the DOM assuming it has succeeded, but we still
  2462. // need to construct a suspense boundary first
  2463. const result = hydrateNode(node, (suspense.pendingBranch = vnode.ssContent), parentComponent, suspense, optimized);
  2464. if (suspense.deps === 0) {
  2465. suspense.resolve();
  2466. }
  2467. return result;
  2468. /* eslint-enable no-restricted-globals */
  2469. }
  2470. function normalizeSuspenseChildren(vnode) {
  2471. const { shapeFlag, children } = vnode;
  2472. let content;
  2473. let fallback;
  2474. if (shapeFlag & 32 /* SLOTS_CHILDREN */) {
  2475. content = normalizeSuspenseSlot(children.default);
  2476. fallback = normalizeSuspenseSlot(children.fallback);
  2477. }
  2478. else {
  2479. content = normalizeSuspenseSlot(children);
  2480. fallback = normalizeVNode(null);
  2481. }
  2482. return {
  2483. content,
  2484. fallback
  2485. };
  2486. }
  2487. function normalizeSuspenseSlot(s) {
  2488. if (isFunction(s)) {
  2489. s = s();
  2490. }
  2491. if (isArray(s)) {
  2492. const singleChild = filterSingleRoot(s);
  2493. if ( !singleChild) {
  2494. warn(`<Suspense> slots expect a single root node.`);
  2495. }
  2496. s = singleChild;
  2497. }
  2498. return normalizeVNode(s);
  2499. }
  2500. function queueEffectWithSuspense(fn, suspense) {
  2501. if (suspense && suspense.pendingBranch) {
  2502. if (isArray(fn)) {
  2503. suspense.effects.push(...fn);
  2504. }
  2505. else {
  2506. suspense.effects.push(fn);
  2507. }
  2508. }
  2509. else {
  2510. queuePostFlushCb(fn);
  2511. }
  2512. }
  2513. function setActiveBranch(suspense, branch) {
  2514. suspense.activeBranch = branch;
  2515. const { vnode, parentComponent } = suspense;
  2516. const el = (vnode.el = branch.el);
  2517. // in case suspense is the root node of a component,
  2518. // recursively update the HOC el
  2519. if (parentComponent && parentComponent.subTree === vnode) {
  2520. parentComponent.vnode.el = el;
  2521. updateHOCHostEl(parentComponent, el);
  2522. }
  2523. }
  2524. let isRenderingCompiledSlot = 0;
  2525. const setCompiledSlotRendering = (n) => (isRenderingCompiledSlot += n);
  2526. /**
  2527. * Compiler runtime helper for rendering `<slot/>`
  2528. * @private
  2529. */
  2530. function renderSlot(slots, name, props = {},
  2531. // this is not a user-facing function, so the fallback is always generated by
  2532. // the compiler and guaranteed to be a function returning an array
  2533. fallback) {
  2534. let slot = slots[name];
  2535. if ( slot && slot.length > 1) {
  2536. warn(`SSR-optimized slot function detected in a non-SSR-optimized render ` +
  2537. `function. You need to mark this component with $dynamic-slots in the ` +
  2538. `parent template.`);
  2539. slot = () => [];
  2540. }
  2541. // a compiled slot disables block tracking by default to avoid manual
  2542. // invocation interfering with template-based block tracking, but in
  2543. // `renderSlot` we can be sure that it's template-based so we can force
  2544. // enable it.
  2545. isRenderingCompiledSlot++;
  2546. const rendered = (openBlock(),
  2547. createBlock(Fragment, { key: props.key }, slot ? slot(props) : fallback ? fallback() : [], slots._ === 1 /* STABLE */
  2548. ? 64 /* STABLE_FRAGMENT */
  2549. : -2 /* BAIL */));
  2550. isRenderingCompiledSlot--;
  2551. return rendered;
  2552. }
  2553. /**
  2554. * Wrap a slot function to memoize current rendering instance
  2555. * @private
  2556. */
  2557. function withCtx(fn, ctx = currentRenderingInstance) {
  2558. if (!ctx)
  2559. return fn;
  2560. const renderFnWithContext = (...args) => {
  2561. // If a user calls a compiled slot inside a template expression (#1745), it
  2562. // can mess up block tracking, so by default we need to push a null block to
  2563. // avoid that. This isn't necessary if rendering a compiled `<slot>`.
  2564. if (!isRenderingCompiledSlot) {
  2565. openBlock(true /* null block that disables tracking */);
  2566. }
  2567. const owner = currentRenderingInstance;
  2568. setCurrentRenderingInstance(ctx);
  2569. const res = fn(...args);
  2570. setCurrentRenderingInstance(owner);
  2571. if (!isRenderingCompiledSlot) {
  2572. closeBlock();
  2573. }
  2574. return res;
  2575. };
  2576. renderFnWithContext._c = true;
  2577. return renderFnWithContext;
  2578. }
  2579. // SFC scoped style ID management.
  2580. let currentScopeId = null;
  2581. const scopeIdStack = [];
  2582. /**
  2583. * @private
  2584. */
  2585. function pushScopeId(id) {
  2586. scopeIdStack.push((currentScopeId = id));
  2587. }
  2588. /**
  2589. * @private
  2590. */
  2591. function popScopeId() {
  2592. scopeIdStack.pop();
  2593. currentScopeId = scopeIdStack[scopeIdStack.length - 1] || null;
  2594. }
  2595. /**
  2596. * @private
  2597. */
  2598. function withScopeId(id) {
  2599. return ((fn) => withCtx(function () {
  2600. pushScopeId(id);
  2601. const res = fn.apply(this, arguments);
  2602. popScopeId();
  2603. return res;
  2604. }));
  2605. }
  2606. const isTeleport = (type) => type.__isTeleport;
  2607. const isTeleportDisabled = (props) => props && (props.disabled || props.disabled === '');
  2608. const resolveTarget = (props, select) => {
  2609. const targetSelector = props && props.to;
  2610. if (isString(targetSelector)) {
  2611. if (!select) {
  2612. warn(`Current renderer does not support string target for Teleports. ` +
  2613. `(missing querySelector renderer option)`);
  2614. return null;
  2615. }
  2616. else {
  2617. const target = select(targetSelector);
  2618. if (!target) {
  2619. warn(`Failed to locate Teleport target with selector "${targetSelector}". ` +
  2620. `Note the target element must exist before the component is mounted - ` +
  2621. `i.e. the target cannot be rendered by the component itself, and ` +
  2622. `ideally should be outside of the entire Vue component tree.`);
  2623. }
  2624. return target;
  2625. }
  2626. }
  2627. else {
  2628. if ( !targetSelector && !isTeleportDisabled(props)) {
  2629. warn(`Invalid Teleport target: ${targetSelector}`);
  2630. }
  2631. return targetSelector;
  2632. }
  2633. };
  2634. const TeleportImpl = {
  2635. __isTeleport: true,
  2636. process(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, optimized, internals) {
  2637. const { mc: mountChildren, pc: patchChildren, pbc: patchBlockChildren, o: { insert, querySelector, createText, createComment } } = internals;
  2638. const disabled = isTeleportDisabled(n2.props);
  2639. const { shapeFlag, children } = n2;
  2640. if (n1 == null) {
  2641. // insert anchors in the main view
  2642. const placeholder = (n2.el = createComment('teleport start')
  2643. );
  2644. const mainAnchor = (n2.anchor = createComment('teleport end')
  2645. );
  2646. insert(placeholder, container, anchor);
  2647. insert(mainAnchor, container, anchor);
  2648. const target = (n2.target = resolveTarget(n2.props, querySelector));
  2649. const targetAnchor = (n2.targetAnchor = createText(''));
  2650. if (target) {
  2651. insert(targetAnchor, target);
  2652. }
  2653. else if ( !disabled) {
  2654. warn('Invalid Teleport target on mount:', target, `(${typeof target})`);
  2655. }
  2656. const mount = (container, anchor) => {
  2657. // Teleport *always* has Array children. This is enforced in both the
  2658. // compiler and vnode children normalization.
  2659. if (shapeFlag & 16 /* ARRAY_CHILDREN */) {
  2660. mountChildren(children, container, anchor, parentComponent, parentSuspense, isSVG, optimized);
  2661. }
  2662. };
  2663. if (disabled) {
  2664. mount(container, mainAnchor);
  2665. }
  2666. else if (target) {
  2667. mount(target, targetAnchor);
  2668. }
  2669. }
  2670. else {
  2671. // update content
  2672. n2.el = n1.el;
  2673. const mainAnchor = (n2.anchor = n1.anchor);
  2674. const target = (n2.target = n1.target);
  2675. const targetAnchor = (n2.targetAnchor = n1.targetAnchor);
  2676. const wasDisabled = isTeleportDisabled(n1.props);
  2677. const currentContainer = wasDisabled ? container : target;
  2678. const currentAnchor = wasDisabled ? mainAnchor : targetAnchor;
  2679. if (n2.dynamicChildren) {
  2680. // fast path when the teleport happens to be a block root
  2681. patchBlockChildren(n1.dynamicChildren, n2.dynamicChildren, currentContainer, parentComponent, parentSuspense, isSVG);
  2682. // even in block tree mode we need to make sure all root-level nodes
  2683. // in the teleport inherit previous DOM references so that they can
  2684. // be moved in future patches.
  2685. if (n2.shapeFlag & 16 /* ARRAY_CHILDREN */) {
  2686. const oldChildren = n1.children;
  2687. const children = n2.children;
  2688. for (let i = 0; i < children.length; i++) {
  2689. // only inherit for non-patched nodes (i.e. static ones)
  2690. if (!children[i].el) {
  2691. children[i].el = oldChildren[i].el;
  2692. }
  2693. }
  2694. }
  2695. }
  2696. else if (!optimized) {
  2697. patchChildren(n1, n2, currentContainer, currentAnchor, parentComponent, parentSuspense, isSVG);
  2698. }
  2699. if (disabled) {
  2700. if (!wasDisabled) {
  2701. // enabled -> disabled
  2702. // move into main container
  2703. moveTeleport(n2, container, mainAnchor, internals, 1 /* TOGGLE */);
  2704. }
  2705. }
  2706. else {
  2707. // target changed
  2708. if ((n2.props && n2.props.to) !== (n1.props && n1.props.to)) {
  2709. const nextTarget = (n2.target = resolveTarget(n2.props, querySelector));
  2710. if (nextTarget) {
  2711. moveTeleport(n2, nextTarget, null, internals, 0 /* TARGET_CHANGE */);
  2712. }
  2713. else {
  2714. warn('Invalid Teleport target on update:', target, `(${typeof target})`);
  2715. }
  2716. }
  2717. else if (wasDisabled) {
  2718. // disabled -> enabled
  2719. // move into teleport target
  2720. moveTeleport(n2, target, targetAnchor, internals, 1 /* TOGGLE */);
  2721. }
  2722. }
  2723. }
  2724. },
  2725. remove(vnode, { r: remove, o: { remove: hostRemove } }) {
  2726. const { shapeFlag, children, anchor } = vnode;
  2727. hostRemove(anchor);
  2728. if (shapeFlag & 16 /* ARRAY_CHILDREN */) {
  2729. for (let i = 0; i < children.length; i++) {
  2730. remove(children[i]);
  2731. }
  2732. }
  2733. },
  2734. move: moveTeleport,
  2735. hydrate: hydrateTeleport
  2736. };
  2737. function moveTeleport(vnode, container, parentAnchor, { o: { insert }, m: move }, moveType = 2 /* REORDER */) {
  2738. // move target anchor if this is a target change.
  2739. if (moveType === 0 /* TARGET_CHANGE */) {
  2740. insert(vnode.targetAnchor, container, parentAnchor);
  2741. }
  2742. const { el, anchor, shapeFlag, children, props } = vnode;
  2743. const isReorder = moveType === 2 /* REORDER */;
  2744. // move main view anchor if this is a re-order.
  2745. if (isReorder) {
  2746. insert(el, container, parentAnchor);
  2747. }
  2748. // if this is a re-order and teleport is enabled (content is in target)
  2749. // do not move children. So the opposite is: only move children if this
  2750. // is not a reorder, or the teleport is disabled
  2751. if (!isReorder || isTeleportDisabled(props)) {
  2752. // Teleport has either Array children or no children.
  2753. if (shapeFlag & 16 /* ARRAY_CHILDREN */) {
  2754. for (let i = 0; i < children.length; i++) {
  2755. move(children[i], container, parentAnchor, 2 /* REORDER */);
  2756. }
  2757. }
  2758. }
  2759. // move main view anchor if this is a re-order.
  2760. if (isReorder) {
  2761. insert(anchor, container, parentAnchor);
  2762. }
  2763. }
  2764. function hydrateTeleport(node, vnode, parentComponent, parentSuspense, optimized, { o: { nextSibling, parentNode, querySelector } }, hydrateChildren) {
  2765. const target = (vnode.target = resolveTarget(vnode.props, querySelector));
  2766. if (target) {
  2767. // if multiple teleports rendered to the same target element, we need to
  2768. // pick up from where the last teleport finished instead of the first node
  2769. const targetNode = target._lpa || target.firstChild;
  2770. if (vnode.shapeFlag & 16 /* ARRAY_CHILDREN */) {
  2771. if (isTeleportDisabled(vnode.props)) {
  2772. vnode.anchor = hydrateChildren(nextSibling(node), vnode, parentNode(node), parentComponent, parentSuspense, optimized);
  2773. vnode.targetAnchor = targetNode;
  2774. }
  2775. else {
  2776. vnode.anchor = nextSibling(node);
  2777. vnode.targetAnchor = hydrateChildren(targetNode, vnode, target, parentComponent, parentSuspense, optimized);
  2778. }
  2779. target._lpa =
  2780. vnode.targetAnchor && nextSibling(vnode.targetAnchor);
  2781. }
  2782. }
  2783. return vnode.anchor && nextSibling(vnode.anchor);
  2784. }
  2785. // Force-casted public typing for h and TSX props inference
  2786. const Teleport = TeleportImpl;
  2787. const COMPONENTS = 'components';
  2788. const DIRECTIVES = 'directives';
  2789. /**
  2790. * @private
  2791. */
  2792. function resolveComponent(name) {
  2793. return resolveAsset(COMPONENTS, name) || name;
  2794. }
  2795. const NULL_DYNAMIC_COMPONENT = Symbol();
  2796. /**
  2797. * @private
  2798. */
  2799. function resolveDynamicComponent(component) {
  2800. if (isString(component)) {
  2801. return resolveAsset(COMPONENTS, component, false) || component;
  2802. }
  2803. else {
  2804. // invalid types will fallthrough to createVNode and raise warning
  2805. return (component || NULL_DYNAMIC_COMPONENT);
  2806. }
  2807. }
  2808. /**
  2809. * @private
  2810. */
  2811. function resolveDirective(name) {
  2812. return resolveAsset(DIRECTIVES, name);
  2813. }
  2814. // implementation
  2815. function resolveAsset(type, name, warnMissing = true) {
  2816. const instance = currentRenderingInstance || currentInstance;
  2817. if (instance) {
  2818. const Component = instance.type;
  2819. // self name has highest priority
  2820. if (type === COMPONENTS) {
  2821. const selfName = Component.displayName || Component.name;
  2822. if (selfName &&
  2823. (selfName === name ||
  2824. selfName === camelize(name) ||
  2825. selfName === capitalize(camelize(name)))) {
  2826. return Component;
  2827. }
  2828. }
  2829. const res =
  2830. // local registration
  2831. // check instance[type] first for components with mixin or extends.
  2832. resolve(instance[type] || Component[type], name) ||
  2833. // global registration
  2834. resolve(instance.appContext[type], name);
  2835. if ( warnMissing && !res) {
  2836. warn(`Failed to resolve ${type.slice(0, -1)}: ${name}`);
  2837. }
  2838. return res;
  2839. }
  2840. else {
  2841. warn(`resolve${capitalize(type.slice(0, -1))} ` +
  2842. `can only be used in render() or setup().`);
  2843. }
  2844. }
  2845. function resolve(registry, name) {
  2846. return (registry &&
  2847. (registry[name] ||
  2848. registry[camelize(name)] ||
  2849. registry[capitalize(camelize(name))]));
  2850. }
  2851. const Fragment = Symbol( 'Fragment' );
  2852. const Text = Symbol( 'Text' );
  2853. const Comment = Symbol( 'Comment' );
  2854. const Static = Symbol( 'Static' );
  2855. // Since v-if and v-for are the two possible ways node structure can dynamically
  2856. // change, once we consider v-if branches and each v-for fragment a block, we
  2857. // can divide a template into nested blocks, and within each block the node
  2858. // structure would be stable. This allows us to skip most children diffing
  2859. // and only worry about the dynamic nodes (indicated by patch flags).
  2860. const blockStack = [];
  2861. let currentBlock = null;
  2862. /**
  2863. * Open a block.
  2864. * This must be called before `createBlock`. It cannot be part of `createBlock`
  2865. * because the children of the block are evaluated before `createBlock` itself
  2866. * is called. The generated code typically looks like this:
  2867. *
  2868. * ```js
  2869. * function render() {
  2870. * return (openBlock(),createBlock('div', null, [...]))
  2871. * }
  2872. * ```
  2873. * disableTracking is true when creating a v-for fragment block, since a v-for
  2874. * fragment always diffs its children.
  2875. *
  2876. * @private
  2877. */
  2878. function openBlock(disableTracking = false) {
  2879. blockStack.push((currentBlock = disableTracking ? null : []));
  2880. }
  2881. function closeBlock() {
  2882. blockStack.pop();
  2883. currentBlock = blockStack[blockStack.length - 1] || null;
  2884. }
  2885. // Whether we should be tracking dynamic child nodes inside a block.
  2886. // Only tracks when this value is > 0
  2887. // We are not using a simple boolean because this value may need to be
  2888. // incremented/decremented by nested usage of v-once (see below)
  2889. let shouldTrack$1 = 1;
  2890. /**
  2891. * Block tracking sometimes needs to be disabled, for example during the
  2892. * creation of a tree that needs to be cached by v-once. The compiler generates
  2893. * code like this:
  2894. *
  2895. * ``` js
  2896. * _cache[1] || (
  2897. * setBlockTracking(-1),
  2898. * _cache[1] = createVNode(...),
  2899. * setBlockTracking(1),
  2900. * _cache[1]
  2901. * )
  2902. * ```
  2903. *
  2904. * @private
  2905. */
  2906. function setBlockTracking(value) {
  2907. shouldTrack$1 += value;
  2908. }
  2909. /**
  2910. * Create a block root vnode. Takes the same exact arguments as `createVNode`.
  2911. * A block root keeps track of dynamic nodes within the block in the
  2912. * `dynamicChildren` array.
  2913. *
  2914. * @private
  2915. */
  2916. function createBlock(type, props, children, patchFlag, dynamicProps) {
  2917. const vnode = createVNode(type, props, children, patchFlag, dynamicProps, true /* isBlock: prevent a block from tracking itself */);
  2918. // save current block children on the block vnode
  2919. vnode.dynamicChildren = currentBlock || EMPTY_ARR;
  2920. // close block
  2921. closeBlock();
  2922. // a block is always going to be patched, so track it as a child of its
  2923. // parent block
  2924. if (shouldTrack$1 > 0 && currentBlock) {
  2925. currentBlock.push(vnode);
  2926. }
  2927. return vnode;
  2928. }
  2929. function isVNode(value) {
  2930. return value ? value.__v_isVNode === true : false;
  2931. }
  2932. function isSameVNodeType(n1, n2) {
  2933. if (
  2934. n2.shapeFlag & 6 /* COMPONENT */ &&
  2935. hmrDirtyComponents.has(n2.type)) {
  2936. // HMR only: if the component has been hot-updated, force a reload.
  2937. return false;
  2938. }
  2939. return n1.type === n2.type && n1.key === n2.key;
  2940. }
  2941. let vnodeArgsTransformer;
  2942. /**
  2943. * Internal API for registering an arguments transform for createVNode
  2944. * used for creating stubs in the test-utils
  2945. * It is *internal* but needs to be exposed for test-utils to pick up proper
  2946. * typings
  2947. */
  2948. function transformVNodeArgs(transformer) {
  2949. vnodeArgsTransformer = transformer;
  2950. }
  2951. const createVNodeWithArgsTransform = (...args) => {
  2952. return _createVNode(...(vnodeArgsTransformer
  2953. ? vnodeArgsTransformer(args, currentRenderingInstance)
  2954. : args));
  2955. };
  2956. const InternalObjectKey = `__vInternal`;
  2957. const normalizeKey = ({ key }) => key != null ? key : null;
  2958. const normalizeRef = ({ ref }) => {
  2959. return (ref != null
  2960. ? isArray(ref)
  2961. ? ref
  2962. : { i: currentRenderingInstance, r: ref }
  2963. : null);
  2964. };
  2965. const createVNode = ( createVNodeWithArgsTransform
  2966. );
  2967. function _createVNode(type, props = null, children = null, patchFlag = 0, dynamicProps = null, isBlockNode = false) {
  2968. if (!type || type === NULL_DYNAMIC_COMPONENT) {
  2969. if ( !type) {
  2970. warn(`Invalid vnode type when creating vnode: ${type}.`);
  2971. }
  2972. type = Comment;
  2973. }
  2974. if (isVNode(type)) {
  2975. // createVNode receiving an existing vnode. This happens in cases like
  2976. // <component :is="vnode"/>
  2977. // #2078 make sure to merge refs during the clone instead of overwriting it
  2978. const cloned = cloneVNode(type, props, true /* mergeRef: true */);
  2979. if (children) {
  2980. normalizeChildren(cloned, children);
  2981. }
  2982. return cloned;
  2983. }
  2984. // class component normalization.
  2985. if (isClassComponent(type)) {
  2986. type = type.__vccOpts;
  2987. }
  2988. // class & style normalization.
  2989. if (props) {
  2990. // for reactive or proxy objects, we need to clone it to enable mutation.
  2991. if (isProxy(props) || InternalObjectKey in props) {
  2992. props = extend({}, props);
  2993. }
  2994. let { class: klass, style } = props;
  2995. if (klass && !isString(klass)) {
  2996. props.class = normalizeClass(klass);
  2997. }
  2998. if (isObject(style)) {
  2999. // reactive state objects need to be cloned since they are likely to be
  3000. // mutated
  3001. if (isProxy(style) && !isArray(style)) {
  3002. style = extend({}, style);
  3003. }
  3004. props.style = normalizeStyle(style);
  3005. }
  3006. }
  3007. // encode the vnode type information into a bitmap
  3008. const shapeFlag = isString(type)
  3009. ? 1 /* ELEMENT */
  3010. : isSuspense(type)
  3011. ? 128 /* SUSPENSE */
  3012. : isTeleport(type)
  3013. ? 64 /* TELEPORT */
  3014. : isObject(type)
  3015. ? 4 /* STATEFUL_COMPONENT */
  3016. : isFunction(type)
  3017. ? 2 /* FUNCTIONAL_COMPONENT */
  3018. : 0;
  3019. if ( shapeFlag & 4 /* STATEFUL_COMPONENT */ && isProxy(type)) {
  3020. type = toRaw(type);
  3021. warn(`Vue received a Component which was made a reactive object. This can ` +
  3022. `lead to unnecessary performance overhead, and should be avoided by ` +
  3023. `marking the component with \`markRaw\` or using \`shallowRef\` ` +
  3024. `instead of \`ref\`.`, `\nComponent that was made reactive: `, type);
  3025. }
  3026. const vnode = {
  3027. __v_isVNode: true,
  3028. ["__v_skip" /* SKIP */]: true,
  3029. type,
  3030. props,
  3031. key: props && normalizeKey(props),
  3032. ref: props && normalizeRef(props),
  3033. scopeId: currentScopeId,
  3034. children: null,
  3035. component: null,
  3036. suspense: null,
  3037. ssContent: null,
  3038. ssFallback: null,
  3039. dirs: null,
  3040. transition: null,
  3041. el: null,
  3042. anchor: null,
  3043. target: null,
  3044. targetAnchor: null,
  3045. staticCount: 0,
  3046. shapeFlag,
  3047. patchFlag,
  3048. dynamicProps,
  3049. dynamicChildren: null,
  3050. appContext: null
  3051. };
  3052. // validate key
  3053. if ( vnode.key !== vnode.key) {
  3054. warn(`VNode created with invalid key (NaN). VNode type:`, vnode.type);
  3055. }
  3056. normalizeChildren(vnode, children);
  3057. // normalize suspense children
  3058. if ( shapeFlag & 128 /* SUSPENSE */) {
  3059. const { content, fallback } = normalizeSuspenseChildren(vnode);
  3060. vnode.ssContent = content;
  3061. vnode.ssFallback = fallback;
  3062. }
  3063. if (shouldTrack$1 > 0 &&
  3064. // avoid a block node from tracking itself
  3065. !isBlockNode &&
  3066. // has current parent block
  3067. currentBlock &&
  3068. // presence of a patch flag indicates this node needs patching on updates.
  3069. // component nodes also should always be patched, because even if the
  3070. // component doesn't need to update, it needs to persist the instance on to
  3071. // the next vnode so that it can be properly unmounted later.
  3072. (patchFlag > 0 || shapeFlag & 6 /* COMPONENT */) &&
  3073. // the EVENTS flag is only for hydration and if it is the only flag, the
  3074. // vnode should not be considered dynamic due to handler caching.
  3075. patchFlag !== 32 /* HYDRATE_EVENTS */) {
  3076. currentBlock.push(vnode);
  3077. }
  3078. return vnode;
  3079. }
  3080. function cloneVNode(vnode, extraProps, mergeRef = false) {
  3081. // This is intentionally NOT using spread or extend to avoid the runtime
  3082. // key enumeration cost.
  3083. const { props, ref, patchFlag } = vnode;
  3084. const mergedProps = extraProps ? mergeProps(props || {}, extraProps) : props;
  3085. return {
  3086. __v_isVNode: true,
  3087. ["__v_skip" /* SKIP */]: true,
  3088. type: vnode.type,
  3089. props: mergedProps,
  3090. key: mergedProps && normalizeKey(mergedProps),
  3091. ref: extraProps && extraProps.ref
  3092. ? // #2078 in the case of <component :is="vnode" ref="extra"/>
  3093. // if the vnode itself already has a ref, cloneVNode will need to merge
  3094. // the refs so the single vnode can be set on multiple refs
  3095. mergeRef && ref
  3096. ? isArray(ref)
  3097. ? ref.concat(normalizeRef(extraProps))
  3098. : [ref, normalizeRef(extraProps)]
  3099. : normalizeRef(extraProps)
  3100. : ref,
  3101. scopeId: vnode.scopeId,
  3102. children: vnode.children,
  3103. target: vnode.target,
  3104. targetAnchor: vnode.targetAnchor,
  3105. staticCount: vnode.staticCount,
  3106. shapeFlag: vnode.shapeFlag,
  3107. // if the vnode is cloned with extra props, we can no longer assume its
  3108. // existing patch flag to be reliable and need to add the FULL_PROPS flag.
  3109. // note: perserve flag for fragments since they use the flag for children
  3110. // fast paths only.
  3111. patchFlag: extraProps && vnode.type !== Fragment
  3112. ? patchFlag === -1 // hoisted node
  3113. ? 16 /* FULL_PROPS */
  3114. : patchFlag | 16 /* FULL_PROPS */
  3115. : patchFlag,
  3116. dynamicProps: vnode.dynamicProps,
  3117. dynamicChildren: vnode.dynamicChildren,
  3118. appContext: vnode.appContext,
  3119. dirs: vnode.dirs,
  3120. transition: vnode.transition,
  3121. // These should technically only be non-null on mounted VNodes. However,
  3122. // they *should* be copied for kept-alive vnodes. So we just always copy
  3123. // them since them being non-null during a mount doesn't affect the logic as
  3124. // they will simply be overwritten.
  3125. component: vnode.component,
  3126. suspense: vnode.suspense,
  3127. ssContent: vnode.ssContent && cloneVNode(vnode.ssContent),
  3128. ssFallback: vnode.ssFallback && cloneVNode(vnode.ssFallback),
  3129. el: vnode.el,
  3130. anchor: vnode.anchor
  3131. };
  3132. }
  3133. /**
  3134. * @private
  3135. */
  3136. function createTextVNode(text = ' ', flag = 0) {
  3137. return createVNode(Text, null, text, flag);
  3138. }
  3139. /**
  3140. * @private
  3141. */
  3142. function createStaticVNode(content, numberOfNodes) {
  3143. // A static vnode can contain multiple stringified elements, and the number
  3144. // of elements is necessary for hydration.
  3145. const vnode = createVNode(Static, null, content);
  3146. vnode.staticCount = numberOfNodes;
  3147. return vnode;
  3148. }
  3149. /**
  3150. * @private
  3151. */
  3152. function createCommentVNode(text = '',
  3153. // when used as the v-else branch, the comment node must be created as a
  3154. // block to ensure correct updates.
  3155. asBlock = false) {
  3156. return asBlock
  3157. ? (openBlock(), createBlock(Comment, null, text))
  3158. : createVNode(Comment, null, text);
  3159. }
  3160. function normalizeVNode(child) {
  3161. if (child == null || typeof child === 'boolean') {
  3162. // empty placeholder
  3163. return createVNode(Comment);
  3164. }
  3165. else if (isArray(child)) {
  3166. // fragment
  3167. return createVNode(Fragment, null, child);
  3168. }
  3169. else if (typeof child === 'object') {
  3170. // already vnode, this should be the most common since compiled templates
  3171. // always produce all-vnode children arrays
  3172. return child.el === null ? child : cloneVNode(child);
  3173. }
  3174. else {
  3175. // strings and numbers
  3176. return createVNode(Text, null, String(child));
  3177. }
  3178. }
  3179. // optimized normalization for template-compiled render fns
  3180. function cloneIfMounted(child) {
  3181. return child.el === null ? child : cloneVNode(child);
  3182. }
  3183. function normalizeChildren(vnode, children) {
  3184. let type = 0;
  3185. const { shapeFlag } = vnode;
  3186. if (children == null) {
  3187. children = null;
  3188. }
  3189. else if (isArray(children)) {
  3190. type = 16 /* ARRAY_CHILDREN */;
  3191. }
  3192. else if (typeof children === 'object') {
  3193. if (shapeFlag & 1 /* ELEMENT */ || shapeFlag & 64 /* TELEPORT */) {
  3194. // Normalize slot to plain children for plain element and Teleport
  3195. const slot = children.default;
  3196. if (slot) {
  3197. // _c marker is added by withCtx() indicating this is a compiled slot
  3198. slot._c && setCompiledSlotRendering(1);
  3199. normalizeChildren(vnode, slot());
  3200. slot._c && setCompiledSlotRendering(-1);
  3201. }
  3202. return;
  3203. }
  3204. else {
  3205. type = 32 /* SLOTS_CHILDREN */;
  3206. const slotFlag = children._;
  3207. if (!slotFlag && !(InternalObjectKey in children)) {
  3208. children._ctx = currentRenderingInstance;
  3209. }
  3210. else if (slotFlag === 3 /* FORWARDED */ && currentRenderingInstance) {
  3211. // a child component receives forwarded slots from the parent.
  3212. // its slot type is determined by its parent's slot type.
  3213. if (currentRenderingInstance.vnode.patchFlag & 1024 /* DYNAMIC_SLOTS */) {
  3214. children._ = 2 /* DYNAMIC */;
  3215. vnode.patchFlag |= 1024 /* DYNAMIC_SLOTS */;
  3216. }
  3217. else {
  3218. children._ = 1 /* STABLE */;
  3219. }
  3220. }
  3221. }
  3222. }
  3223. else if (isFunction(children)) {
  3224. children = { default: children, _ctx: currentRenderingInstance };
  3225. type = 32 /* SLOTS_CHILDREN */;
  3226. }
  3227. else {
  3228. children = String(children);
  3229. // force teleport children to array so it can be moved around
  3230. if (shapeFlag & 64 /* TELEPORT */) {
  3231. type = 16 /* ARRAY_CHILDREN */;
  3232. children = [createTextVNode(children)];
  3233. }
  3234. else {
  3235. type = 8 /* TEXT_CHILDREN */;
  3236. }
  3237. }
  3238. vnode.children = children;
  3239. vnode.shapeFlag |= type;
  3240. }
  3241. function mergeProps(...args) {
  3242. const ret = extend({}, args[0]);
  3243. for (let i = 1; i < args.length; i++) {
  3244. const toMerge = args[i];
  3245. for (const key in toMerge) {
  3246. if (key === 'class') {
  3247. if (ret.class !== toMerge.class) {
  3248. ret.class = normalizeClass([ret.class, toMerge.class]);
  3249. }
  3250. }
  3251. else if (key === 'style') {
  3252. ret.style = normalizeStyle([ret.style, toMerge.style]);
  3253. }
  3254. else if (isOn(key)) {
  3255. const existing = ret[key];
  3256. const incoming = toMerge[key];
  3257. if (existing !== incoming) {
  3258. ret[key] = existing
  3259. ? [].concat(existing, toMerge[key])
  3260. : incoming;
  3261. }
  3262. }
  3263. else {
  3264. ret[key] = toMerge[key];
  3265. }
  3266. }
  3267. }
  3268. return ret;
  3269. }
  3270. function initProps(instance, rawProps, isStateful, // result of bitwise flag comparison
  3271. isSSR = false) {
  3272. const props = {};
  3273. const attrs = {};
  3274. def(attrs, InternalObjectKey, 1);
  3275. setFullProps(instance, rawProps, props, attrs);
  3276. // validation
  3277. {
  3278. validateProps(props, instance);
  3279. }
  3280. if (isStateful) {
  3281. // stateful
  3282. instance.props = isSSR ? props : shallowReactive(props);
  3283. }
  3284. else {
  3285. if (!instance.type.props) {
  3286. // functional w/ optional props, props === attrs
  3287. instance.props = attrs;
  3288. }
  3289. else {
  3290. // functional w/ declared props
  3291. instance.props = props;
  3292. }
  3293. }
  3294. instance.attrs = attrs;
  3295. }
  3296. function updateProps(instance, rawProps, rawPrevProps, optimized) {
  3297. const { props, attrs, vnode: { patchFlag } } = instance;
  3298. const rawCurrentProps = toRaw(props);
  3299. const [options] = instance.propsOptions;
  3300. if (
  3301. // always force full diff if hmr is enabled
  3302. !( instance.type.__hmrId) &&
  3303. (optimized || patchFlag > 0) &&
  3304. !(patchFlag & 16 /* FULL_PROPS */)) {
  3305. if (patchFlag & 8 /* PROPS */) {
  3306. // Compiler-generated props & no keys change, just set the updated
  3307. // the props.
  3308. const propsToUpdate = instance.vnode.dynamicProps;
  3309. for (let i = 0; i < propsToUpdate.length; i++) {
  3310. const key = propsToUpdate[i];
  3311. // PROPS flag guarantees rawProps to be non-null
  3312. const value = rawProps[key];
  3313. if (options) {
  3314. // attr / props separation was done on init and will be consistent
  3315. // in this code path, so just check if attrs have it.
  3316. if (hasOwn(attrs, key)) {
  3317. attrs[key] = value;
  3318. }
  3319. else {
  3320. const camelizedKey = camelize(key);
  3321. props[camelizedKey] = resolvePropValue(options, rawCurrentProps, camelizedKey, value, instance);
  3322. }
  3323. }
  3324. else {
  3325. attrs[key] = value;
  3326. }
  3327. }
  3328. }
  3329. }
  3330. else {
  3331. // full props update.
  3332. setFullProps(instance, rawProps, props, attrs);
  3333. // in case of dynamic props, check if we need to delete keys from
  3334. // the props object
  3335. let kebabKey;
  3336. for (const key in rawCurrentProps) {
  3337. if (!rawProps ||
  3338. // for camelCase
  3339. (!hasOwn(rawProps, key) &&
  3340. // it's possible the original props was passed in as kebab-case
  3341. // and converted to camelCase (#955)
  3342. ((kebabKey = hyphenate(key)) === key || !hasOwn(rawProps, kebabKey)))) {
  3343. if (options) {
  3344. if (rawPrevProps &&
  3345. // for camelCase
  3346. (rawPrevProps[key] !== undefined ||
  3347. // for kebab-case
  3348. rawPrevProps[kebabKey] !== undefined)) {
  3349. props[key] = resolvePropValue(options, rawProps || EMPTY_OBJ, key, undefined, instance);
  3350. }
  3351. }
  3352. else {
  3353. delete props[key];
  3354. }
  3355. }
  3356. }
  3357. // in the case of functional component w/o props declaration, props and
  3358. // attrs point to the same object so it should already have been updated.
  3359. if (attrs !== rawCurrentProps) {
  3360. for (const key in attrs) {
  3361. if (!rawProps || !hasOwn(rawProps, key)) {
  3362. delete attrs[key];
  3363. }
  3364. }
  3365. }
  3366. }
  3367. // trigger updates for $attrs in case it's used in component slots
  3368. trigger(instance, "set" /* SET */, '$attrs');
  3369. if ( rawProps) {
  3370. validateProps(props, instance);
  3371. }
  3372. }
  3373. function setFullProps(instance, rawProps, props, attrs) {
  3374. const [options, needCastKeys] = instance.propsOptions;
  3375. if (rawProps) {
  3376. for (const key in rawProps) {
  3377. const value = rawProps[key];
  3378. // key, ref are reserved and never passed down
  3379. if (isReservedProp(key)) {
  3380. continue;
  3381. }
  3382. // prop option names are camelized during normalization, so to support
  3383. // kebab -> camel conversion here we need to camelize the key.
  3384. let camelKey;
  3385. if (options && hasOwn(options, (camelKey = camelize(key)))) {
  3386. props[camelKey] = value;
  3387. }
  3388. else if (!isEmitListener(instance.emitsOptions, key)) {
  3389. // Any non-declared (either as a prop or an emitted event) props are put
  3390. // into a separate `attrs` object for spreading. Make sure to preserve
  3391. // original key casing
  3392. attrs[key] = value;
  3393. }
  3394. }
  3395. }
  3396. if (needCastKeys) {
  3397. const rawCurrentProps = toRaw(props);
  3398. for (let i = 0; i < needCastKeys.length; i++) {
  3399. const key = needCastKeys[i];
  3400. props[key] = resolvePropValue(options, rawCurrentProps, key, rawCurrentProps[key], instance);
  3401. }
  3402. }
  3403. }
  3404. function resolvePropValue(options, props, key, value, instance) {
  3405. const opt = options[key];
  3406. if (opt != null) {
  3407. const hasDefault = hasOwn(opt, 'default');
  3408. // default values
  3409. if (hasDefault && value === undefined) {
  3410. const defaultValue = opt.default;
  3411. if (opt.type !== Function && isFunction(defaultValue)) {
  3412. setCurrentInstance(instance);
  3413. value = defaultValue(props);
  3414. setCurrentInstance(null);
  3415. }
  3416. else {
  3417. value = defaultValue;
  3418. }
  3419. }
  3420. // boolean casting
  3421. if (opt[0 /* shouldCast */]) {
  3422. if (!hasOwn(props, key) && !hasDefault) {
  3423. value = false;
  3424. }
  3425. else if (opt[1 /* shouldCastTrue */] &&
  3426. (value === '' || value === hyphenate(key))) {
  3427. value = true;
  3428. }
  3429. }
  3430. }
  3431. return value;
  3432. }
  3433. function normalizePropsOptions(comp, appContext, asMixin = false) {
  3434. const appId = appContext.app ? appContext.app._uid : -1;
  3435. const cache = comp.__props || (comp.__props = {});
  3436. const cached = cache[appId];
  3437. if (cached) {
  3438. return cached;
  3439. }
  3440. const raw = comp.props;
  3441. const normalized = {};
  3442. const needCastKeys = [];
  3443. // apply mixin/extends props
  3444. let hasExtends = false;
  3445. if ( !isFunction(comp)) {
  3446. const extendProps = (raw) => {
  3447. hasExtends = true;
  3448. const [props, keys] = normalizePropsOptions(raw, appContext, true);
  3449. extend(normalized, props);
  3450. if (keys)
  3451. needCastKeys.push(...keys);
  3452. };
  3453. if (!asMixin && appContext.mixins.length) {
  3454. appContext.mixins.forEach(extendProps);
  3455. }
  3456. if (comp.extends) {
  3457. extendProps(comp.extends);
  3458. }
  3459. if (comp.mixins) {
  3460. comp.mixins.forEach(extendProps);
  3461. }
  3462. }
  3463. if (!raw && !hasExtends) {
  3464. return (cache[appId] = EMPTY_ARR);
  3465. }
  3466. if (isArray(raw)) {
  3467. for (let i = 0; i < raw.length; i++) {
  3468. if ( !isString(raw[i])) {
  3469. warn(`props must be strings when using array syntax.`, raw[i]);
  3470. }
  3471. const normalizedKey = camelize(raw[i]);
  3472. if (validatePropName(normalizedKey)) {
  3473. normalized[normalizedKey] = EMPTY_OBJ;
  3474. }
  3475. }
  3476. }
  3477. else if (raw) {
  3478. if ( !isObject(raw)) {
  3479. warn(`invalid props options`, raw);
  3480. }
  3481. for (const key in raw) {
  3482. const normalizedKey = camelize(key);
  3483. if (validatePropName(normalizedKey)) {
  3484. const opt = raw[key];
  3485. const prop = (normalized[normalizedKey] =
  3486. isArray(opt) || isFunction(opt) ? { type: opt } : opt);
  3487. if (prop) {
  3488. const booleanIndex = getTypeIndex(Boolean, prop.type);
  3489. const stringIndex = getTypeIndex(String, prop.type);
  3490. prop[0 /* shouldCast */] = booleanIndex > -1;
  3491. prop[1 /* shouldCastTrue */] =
  3492. stringIndex < 0 || booleanIndex < stringIndex;
  3493. // if the prop needs boolean casting or default value
  3494. if (booleanIndex > -1 || hasOwn(prop, 'default')) {
  3495. needCastKeys.push(normalizedKey);
  3496. }
  3497. }
  3498. }
  3499. }
  3500. }
  3501. return (cache[appId] = [normalized, needCastKeys]);
  3502. }
  3503. // use function string name to check type constructors
  3504. // so that it works across vms / iframes.
  3505. function getType(ctor) {
  3506. const match = ctor && ctor.toString().match(/^\s*function (\w+)/);
  3507. return match ? match[1] : '';
  3508. }
  3509. function isSameType(a, b) {
  3510. return getType(a) === getType(b);
  3511. }
  3512. function getTypeIndex(type, expectedTypes) {
  3513. if (isArray(expectedTypes)) {
  3514. for (let i = 0, len = expectedTypes.length; i < len; i++) {
  3515. if (isSameType(expectedTypes[i], type)) {
  3516. return i;
  3517. }
  3518. }
  3519. }
  3520. else if (isFunction(expectedTypes)) {
  3521. return isSameType(expectedTypes, type) ? 0 : -1;
  3522. }
  3523. return -1;
  3524. }
  3525. /**
  3526. * dev only
  3527. */
  3528. function validateProps(props, instance) {
  3529. const rawValues = toRaw(props);
  3530. const options = instance.propsOptions[0];
  3531. for (const key in options) {
  3532. let opt = options[key];
  3533. if (opt == null)
  3534. continue;
  3535. validateProp(key, rawValues[key], opt, !hasOwn(rawValues, key));
  3536. }
  3537. }
  3538. /**
  3539. * dev only
  3540. */
  3541. function validatePropName(key) {
  3542. if (key[0] !== '$') {
  3543. return true;
  3544. }
  3545. else {
  3546. warn(`Invalid prop name: "${key}" is a reserved property.`);
  3547. }
  3548. return false;
  3549. }
  3550. /**
  3551. * dev only
  3552. */
  3553. function validateProp(name, value, prop, isAbsent) {
  3554. const { type, required, validator } = prop;
  3555. // required!
  3556. if (required && isAbsent) {
  3557. warn('Missing required prop: "' + name + '"');
  3558. return;
  3559. }
  3560. // missing but optional
  3561. if (value == null && !prop.required) {
  3562. return;
  3563. }
  3564. // type check
  3565. if (type != null && type !== true) {
  3566. let isValid = false;
  3567. const types = isArray(type) ? type : [type];
  3568. const expectedTypes = [];
  3569. // value is valid as long as one of the specified types match
  3570. for (let i = 0; i < types.length && !isValid; i++) {
  3571. const { valid, expectedType } = assertType(value, types[i]);
  3572. expectedTypes.push(expectedType || '');
  3573. isValid = valid;
  3574. }
  3575. if (!isValid) {
  3576. warn(getInvalidTypeMessage(name, value, expectedTypes));
  3577. return;
  3578. }
  3579. }
  3580. // custom validator
  3581. if (validator && !validator(value)) {
  3582. warn('Invalid prop: custom validator check failed for prop "' + name + '".');
  3583. }
  3584. }
  3585. const isSimpleType = /*#__PURE__*/ makeMap('String,Number,Boolean,Function,Symbol');
  3586. /**
  3587. * dev only
  3588. */
  3589. function assertType(value, type) {
  3590. let valid;
  3591. const expectedType = getType(type);
  3592. if (isSimpleType(expectedType)) {
  3593. const t = typeof value;
  3594. valid = t === expectedType.toLowerCase();
  3595. // for primitive wrapper objects
  3596. if (!valid && t === 'object') {
  3597. valid = value instanceof type;
  3598. }
  3599. }
  3600. else if (expectedType === 'Object') {
  3601. valid = isObject(value);
  3602. }
  3603. else if (expectedType === 'Array') {
  3604. valid = isArray(value);
  3605. }
  3606. else {
  3607. valid = value instanceof type;
  3608. }
  3609. return {
  3610. valid,
  3611. expectedType
  3612. };
  3613. }
  3614. /**
  3615. * dev only
  3616. */
  3617. function getInvalidTypeMessage(name, value, expectedTypes) {
  3618. let message = `Invalid prop: type check failed for prop "${name}".` +
  3619. ` Expected ${expectedTypes.map(capitalize).join(', ')}`;
  3620. const expectedType = expectedTypes[0];
  3621. const receivedType = toRawType(value);
  3622. const expectedValue = styleValue(value, expectedType);
  3623. const receivedValue = styleValue(value, receivedType);
  3624. // check if we need to specify expected value
  3625. if (expectedTypes.length === 1 &&
  3626. isExplicable(expectedType) &&
  3627. !isBoolean(expectedType, receivedType)) {
  3628. message += ` with value ${expectedValue}`;
  3629. }
  3630. message += `, got ${receivedType} `;
  3631. // check if we need to specify received value
  3632. if (isExplicable(receivedType)) {
  3633. message += `with value ${receivedValue}.`;
  3634. }
  3635. return message;
  3636. }
  3637. /**
  3638. * dev only
  3639. */
  3640. function styleValue(value, type) {
  3641. if (type === 'String') {
  3642. return `"${value}"`;
  3643. }
  3644. else if (type === 'Number') {
  3645. return `${Number(value)}`;
  3646. }
  3647. else {
  3648. return `${value}`;
  3649. }
  3650. }
  3651. /**
  3652. * dev only
  3653. */
  3654. function isExplicable(type) {
  3655. const explicitTypes = ['string', 'number', 'boolean'];
  3656. return explicitTypes.some(elem => type.toLowerCase() === elem);
  3657. }
  3658. /**
  3659. * dev only
  3660. */
  3661. function isBoolean(...args) {
  3662. return args.some(elem => elem.toLowerCase() === 'boolean');
  3663. }
  3664. function injectHook(type, hook, target = currentInstance, prepend = false) {
  3665. if (target) {
  3666. const hooks = target[type] || (target[type] = []);
  3667. // cache the error handling wrapper for injected hooks so the same hook
  3668. // can be properly deduped by the scheduler. "__weh" stands for "with error
  3669. // handling".
  3670. const wrappedHook = hook.__weh ||
  3671. (hook.__weh = (...args) => {
  3672. if (target.isUnmounted) {
  3673. return;
  3674. }
  3675. // disable tracking inside all lifecycle hooks
  3676. // since they can potentially be called inside effects.
  3677. pauseTracking();
  3678. // Set currentInstance during hook invocation.
  3679. // This assumes the hook does not synchronously trigger other hooks, which
  3680. // can only be false when the user does something really funky.
  3681. setCurrentInstance(target);
  3682. const res = callWithAsyncErrorHandling(hook, target, type, args);
  3683. setCurrentInstance(null);
  3684. resetTracking();
  3685. return res;
  3686. });
  3687. if (prepend) {
  3688. hooks.unshift(wrappedHook);
  3689. }
  3690. else {
  3691. hooks.push(wrappedHook);
  3692. }
  3693. return wrappedHook;
  3694. }
  3695. else {
  3696. const apiName = `on${capitalize(ErrorTypeStrings[type].replace(/ hook$/, ''))}`;
  3697. warn(`${apiName} is called when there is no active component instance to be ` +
  3698. `associated with. ` +
  3699. `Lifecycle injection APIs can only be used during execution of setup().` +
  3700. ( ` If you are using async setup(), make sure to register lifecycle ` +
  3701. `hooks before the first await statement.`
  3702. ));
  3703. }
  3704. }
  3705. const createHook = (lifecycle) => (hook, target = currentInstance) =>
  3706. // post-create lifecycle registrations are noops during SSR
  3707. !isInSSRComponentSetup && injectHook(lifecycle, hook, target);
  3708. const onBeforeMount = createHook("bm" /* BEFORE_MOUNT */);
  3709. const onMounted = createHook("m" /* MOUNTED */);
  3710. const onBeforeUpdate = createHook("bu" /* BEFORE_UPDATE */);
  3711. const onUpdated = createHook("u" /* UPDATED */);
  3712. const onBeforeUnmount = createHook("bum" /* BEFORE_UNMOUNT */);
  3713. const onUnmounted = createHook("um" /* UNMOUNTED */);
  3714. const onRenderTriggered = createHook("rtg" /* RENDER_TRIGGERED */);
  3715. const onRenderTracked = createHook("rtc" /* RENDER_TRACKED */);
  3716. const onErrorCaptured = (hook, target = currentInstance) => {
  3717. injectHook("ec" /* ERROR_CAPTURED */, hook, target);
  3718. };
  3719. function useTransitionState() {
  3720. const state = {
  3721. isMounted: false,
  3722. isLeaving: false,
  3723. isUnmounting: false,
  3724. leavingVNodes: new Map()
  3725. };
  3726. onMounted(() => {
  3727. state.isMounted = true;
  3728. });
  3729. onBeforeUnmount(() => {
  3730. state.isUnmounting = true;
  3731. });
  3732. return state;
  3733. }
  3734. const TransitionHookValidator = [Function, Array];
  3735. const BaseTransitionImpl = {
  3736. name: `BaseTransition`,
  3737. props: {
  3738. mode: String,
  3739. appear: Boolean,
  3740. persisted: Boolean,
  3741. // enter
  3742. onBeforeEnter: TransitionHookValidator,
  3743. onEnter: TransitionHookValidator,
  3744. onAfterEnter: TransitionHookValidator,
  3745. onEnterCancelled: TransitionHookValidator,
  3746. // leave
  3747. onBeforeLeave: TransitionHookValidator,
  3748. onLeave: TransitionHookValidator,
  3749. onAfterLeave: TransitionHookValidator,
  3750. onLeaveCancelled: TransitionHookValidator,
  3751. // appear
  3752. onBeforeAppear: TransitionHookValidator,
  3753. onAppear: TransitionHookValidator,
  3754. onAfterAppear: TransitionHookValidator,
  3755. onAppearCancelled: TransitionHookValidator
  3756. },
  3757. setup(props, { slots }) {
  3758. const instance = getCurrentInstance();
  3759. const state = useTransitionState();
  3760. let prevTransitionKey;
  3761. return () => {
  3762. const children = slots.default && getTransitionRawChildren(slots.default(), true);
  3763. if (!children || !children.length) {
  3764. return;
  3765. }
  3766. // warn multiple elements
  3767. if ( children.length > 1) {
  3768. warn('<transition> can only be used on a single element or component. Use ' +
  3769. '<transition-group> for lists.');
  3770. }
  3771. // there's no need to track reactivity for these props so use the raw
  3772. // props for a bit better perf
  3773. const rawProps = toRaw(props);
  3774. const { mode } = rawProps;
  3775. // check mode
  3776. if ( mode && !['in-out', 'out-in', 'default'].includes(mode)) {
  3777. warn(`invalid <transition> mode: ${mode}`);
  3778. }
  3779. // at this point children has a guaranteed length of 1.
  3780. const child = children[0];
  3781. if (state.isLeaving) {
  3782. return emptyPlaceholder(child);
  3783. }
  3784. // in the case of <transition><keep-alive/></transition>, we need to
  3785. // compare the type of the kept-alive children.
  3786. const innerChild = getKeepAliveChild(child);
  3787. if (!innerChild) {
  3788. return emptyPlaceholder(child);
  3789. }
  3790. const enterHooks = resolveTransitionHooks(innerChild, rawProps, state, instance);
  3791. setTransitionHooks(innerChild, enterHooks);
  3792. const oldChild = instance.subTree;
  3793. const oldInnerChild = oldChild && getKeepAliveChild(oldChild);
  3794. let transitionKeyChanged = false;
  3795. const { getTransitionKey } = innerChild.type;
  3796. if (getTransitionKey) {
  3797. const key = getTransitionKey();
  3798. if (prevTransitionKey === undefined) {
  3799. prevTransitionKey = key;
  3800. }
  3801. else if (key !== prevTransitionKey) {
  3802. prevTransitionKey = key;
  3803. transitionKeyChanged = true;
  3804. }
  3805. }
  3806. // handle mode
  3807. if (oldInnerChild &&
  3808. oldInnerChild.type !== Comment &&
  3809. (!isSameVNodeType(innerChild, oldInnerChild) || transitionKeyChanged)) {
  3810. const leavingHooks = resolveTransitionHooks(oldInnerChild, rawProps, state, instance);
  3811. // update old tree's hooks in case of dynamic transition
  3812. setTransitionHooks(oldInnerChild, leavingHooks);
  3813. // switching between different views
  3814. if (mode === 'out-in') {
  3815. state.isLeaving = true;
  3816. // return placeholder node and queue update when leave finishes
  3817. leavingHooks.afterLeave = () => {
  3818. state.isLeaving = false;
  3819. instance.update();
  3820. };
  3821. return emptyPlaceholder(child);
  3822. }
  3823. else if (mode === 'in-out') {
  3824. leavingHooks.delayLeave = (el, earlyRemove, delayedLeave) => {
  3825. const leavingVNodesCache = getLeavingNodesForType(state, oldInnerChild);
  3826. leavingVNodesCache[String(oldInnerChild.key)] = oldInnerChild;
  3827. // early removal callback
  3828. el._leaveCb = () => {
  3829. earlyRemove();
  3830. el._leaveCb = undefined;
  3831. delete enterHooks.delayedLeave;
  3832. };
  3833. enterHooks.delayedLeave = delayedLeave;
  3834. };
  3835. }
  3836. }
  3837. return child;
  3838. };
  3839. }
  3840. };
  3841. // export the public type for h/tsx inference
  3842. // also to avoid inline import() in generated d.ts files
  3843. const BaseTransition = BaseTransitionImpl;
  3844. function getLeavingNodesForType(state, vnode) {
  3845. const { leavingVNodes } = state;
  3846. let leavingVNodesCache = leavingVNodes.get(vnode.type);
  3847. if (!leavingVNodesCache) {
  3848. leavingVNodesCache = Object.create(null);
  3849. leavingVNodes.set(vnode.type, leavingVNodesCache);
  3850. }
  3851. return leavingVNodesCache;
  3852. }
  3853. // The transition hooks are attached to the vnode as vnode.transition
  3854. // and will be called at appropriate timing in the renderer.
  3855. function resolveTransitionHooks(vnode, props, state, instance) {
  3856. const { appear, mode, persisted = false, onBeforeEnter, onEnter, onAfterEnter, onEnterCancelled, onBeforeLeave, onLeave, onAfterLeave, onLeaveCancelled, onBeforeAppear, onAppear, onAfterAppear, onAppearCancelled } = props;
  3857. const key = String(vnode.key);
  3858. const leavingVNodesCache = getLeavingNodesForType(state, vnode);
  3859. const callHook = (hook, args) => {
  3860. hook &&
  3861. callWithAsyncErrorHandling(hook, instance, 9 /* TRANSITION_HOOK */, args);
  3862. };
  3863. const hooks = {
  3864. mode,
  3865. persisted,
  3866. beforeEnter(el) {
  3867. let hook = onBeforeEnter;
  3868. if (!state.isMounted) {
  3869. if (appear) {
  3870. hook = onBeforeAppear || onBeforeEnter;
  3871. }
  3872. else {
  3873. return;
  3874. }
  3875. }
  3876. // for same element (v-show)
  3877. if (el._leaveCb) {
  3878. el._leaveCb(true /* cancelled */);
  3879. }
  3880. // for toggled element with same key (v-if)
  3881. const leavingVNode = leavingVNodesCache[key];
  3882. if (leavingVNode &&
  3883. isSameVNodeType(vnode, leavingVNode) &&
  3884. leavingVNode.el._leaveCb) {
  3885. // force early removal (not cancelled)
  3886. leavingVNode.el._leaveCb();
  3887. }
  3888. callHook(hook, [el]);
  3889. },
  3890. enter(el) {
  3891. let hook = onEnter;
  3892. let afterHook = onAfterEnter;
  3893. let cancelHook = onEnterCancelled;
  3894. if (!state.isMounted) {
  3895. if (appear) {
  3896. hook = onAppear || onEnter;
  3897. afterHook = onAfterAppear || onAfterEnter;
  3898. cancelHook = onAppearCancelled || onEnterCancelled;
  3899. }
  3900. else {
  3901. return;
  3902. }
  3903. }
  3904. let called = false;
  3905. const done = (el._enterCb = (cancelled) => {
  3906. if (called)
  3907. return;
  3908. called = true;
  3909. if (cancelled) {
  3910. callHook(cancelHook, [el]);
  3911. }
  3912. else {
  3913. callHook(afterHook, [el]);
  3914. }
  3915. if (hooks.delayedLeave) {
  3916. hooks.delayedLeave();
  3917. }
  3918. el._enterCb = undefined;
  3919. });
  3920. if (hook) {
  3921. hook(el, done);
  3922. if (hook.length <= 1) {
  3923. done();
  3924. }
  3925. }
  3926. else {
  3927. done();
  3928. }
  3929. },
  3930. leave(el, remove) {
  3931. const key = String(vnode.key);
  3932. if (el._enterCb) {
  3933. el._enterCb(true /* cancelled */);
  3934. }
  3935. if (state.isUnmounting) {
  3936. return remove();
  3937. }
  3938. callHook(onBeforeLeave, [el]);
  3939. let called = false;
  3940. const done = (el._leaveCb = (cancelled) => {
  3941. if (called)
  3942. return;
  3943. called = true;
  3944. remove();
  3945. if (cancelled) {
  3946. callHook(onLeaveCancelled, [el]);
  3947. }
  3948. else {
  3949. callHook(onAfterLeave, [el]);
  3950. }
  3951. el._leaveCb = undefined;
  3952. if (leavingVNodesCache[key] === vnode) {
  3953. delete leavingVNodesCache[key];
  3954. }
  3955. });
  3956. leavingVNodesCache[key] = vnode;
  3957. if (onLeave) {
  3958. onLeave(el, done);
  3959. if (onLeave.length <= 1) {
  3960. done();
  3961. }
  3962. }
  3963. else {
  3964. done();
  3965. }
  3966. },
  3967. clone(vnode) {
  3968. return resolveTransitionHooks(vnode, props, state, instance);
  3969. }
  3970. };
  3971. return hooks;
  3972. }
  3973. // the placeholder really only handles one special case: KeepAlive
  3974. // in the case of a KeepAlive in a leave phase we need to return a KeepAlive
  3975. // placeholder with empty content to avoid the KeepAlive instance from being
  3976. // unmounted.
  3977. function emptyPlaceholder(vnode) {
  3978. if (isKeepAlive(vnode)) {
  3979. vnode = cloneVNode(vnode);
  3980. vnode.children = null;
  3981. return vnode;
  3982. }
  3983. }
  3984. function getKeepAliveChild(vnode) {
  3985. return isKeepAlive(vnode)
  3986. ? vnode.children
  3987. ? vnode.children[0]
  3988. : undefined
  3989. : vnode;
  3990. }
  3991. function setTransitionHooks(vnode, hooks) {
  3992. if (vnode.shapeFlag & 6 /* COMPONENT */ && vnode.component) {
  3993. setTransitionHooks(vnode.component.subTree, hooks);
  3994. }
  3995. else if ( vnode.shapeFlag & 128 /* SUSPENSE */) {
  3996. vnode.ssContent.transition = hooks.clone(vnode.ssContent);
  3997. vnode.ssFallback.transition = hooks.clone(vnode.ssFallback);
  3998. }
  3999. else {
  4000. vnode.transition = hooks;
  4001. }
  4002. }
  4003. function getTransitionRawChildren(children, keepComment = false) {
  4004. let ret = [];
  4005. let keyedFragmentCount = 0;
  4006. for (let i = 0; i < children.length; i++) {
  4007. const child = children[i];
  4008. // handle fragment children case, e.g. v-for
  4009. if (child.type === Fragment) {
  4010. if (child.patchFlag & 128 /* KEYED_FRAGMENT */)
  4011. keyedFragmentCount++;
  4012. ret = ret.concat(getTransitionRawChildren(child.children, keepComment));
  4013. }
  4014. // comment placeholders should be skipped, e.g. v-if
  4015. else if (keepComment || child.type !== Comment) {
  4016. ret.push(child);
  4017. }
  4018. }
  4019. // #1126 if a transition children list contains multiple sub fragments, these
  4020. // fragments will be merged into a flat children array. Since each v-for
  4021. // fragment may contain different static bindings inside, we need to de-top
  4022. // these children to force full diffs to ensure correct behavior.
  4023. if (keyedFragmentCount > 1) {
  4024. for (let i = 0; i < ret.length; i++) {
  4025. ret[i].patchFlag = -2 /* BAIL */;
  4026. }
  4027. }
  4028. return ret;
  4029. }
  4030. const isKeepAlive = (vnode) => vnode.type.__isKeepAlive;
  4031. const KeepAliveImpl = {
  4032. name: `KeepAlive`,
  4033. // Marker for special handling inside the renderer. We are not using a ===
  4034. // check directly on KeepAlive in the renderer, because importing it directly
  4035. // would prevent it from being tree-shaken.
  4036. __isKeepAlive: true,
  4037. inheritRef: true,
  4038. props: {
  4039. include: [String, RegExp, Array],
  4040. exclude: [String, RegExp, Array],
  4041. max: [String, Number]
  4042. },
  4043. setup(props, { slots }) {
  4044. const cache = new Map();
  4045. const keys = new Set();
  4046. let current = null;
  4047. const instance = getCurrentInstance();
  4048. const parentSuspense = instance.suspense;
  4049. // KeepAlive communicates with the instantiated renderer via the
  4050. // ctx where the renderer passes in its internals,
  4051. // and the KeepAlive instance exposes activate/deactivate implementations.
  4052. // The whole point of this is to avoid importing KeepAlive directly in the
  4053. // renderer to facilitate tree-shaking.
  4054. const sharedContext = instance.ctx;
  4055. const { renderer: { p: patch, m: move, um: _unmount, o: { createElement } } } = sharedContext;
  4056. const storageContainer = createElement('div');
  4057. sharedContext.activate = (vnode, container, anchor, isSVG, optimized) => {
  4058. const instance = vnode.component;
  4059. move(vnode, container, anchor, 0 /* ENTER */, parentSuspense);
  4060. // in case props have changed
  4061. patch(instance.vnode, vnode, container, anchor, instance, parentSuspense, isSVG, optimized);
  4062. queuePostRenderEffect(() => {
  4063. instance.isDeactivated = false;
  4064. if (instance.a) {
  4065. invokeArrayFns(instance.a);
  4066. }
  4067. const vnodeHook = vnode.props && vnode.props.onVnodeMounted;
  4068. if (vnodeHook) {
  4069. invokeVNodeHook(vnodeHook, instance.parent, vnode);
  4070. }
  4071. }, parentSuspense);
  4072. };
  4073. sharedContext.deactivate = (vnode) => {
  4074. const instance = vnode.component;
  4075. move(vnode, storageContainer, null, 1 /* LEAVE */, parentSuspense);
  4076. queuePostRenderEffect(() => {
  4077. if (instance.da) {
  4078. invokeArrayFns(instance.da);
  4079. }
  4080. const vnodeHook = vnode.props && vnode.props.onVnodeUnmounted;
  4081. if (vnodeHook) {
  4082. invokeVNodeHook(vnodeHook, instance.parent, vnode);
  4083. }
  4084. instance.isDeactivated = true;
  4085. }, parentSuspense);
  4086. };
  4087. function unmount(vnode) {
  4088. // reset the shapeFlag so it can be properly unmounted
  4089. resetShapeFlag(vnode);
  4090. _unmount(vnode, instance, parentSuspense);
  4091. }
  4092. function pruneCache(filter) {
  4093. cache.forEach((vnode, key) => {
  4094. const name = getName(vnode.type);
  4095. if (name && (!filter || !filter(name))) {
  4096. pruneCacheEntry(key);
  4097. }
  4098. });
  4099. }
  4100. function pruneCacheEntry(key) {
  4101. const cached = cache.get(key);
  4102. if (!current || cached.type !== current.type) {
  4103. unmount(cached);
  4104. }
  4105. else if (current) {
  4106. // current active instance should no longer be kept-alive.
  4107. // we can't unmount it now but it might be later, so reset its flag now.
  4108. resetShapeFlag(current);
  4109. }
  4110. cache.delete(key);
  4111. keys.delete(key);
  4112. }
  4113. // prune cache on include/exclude prop change
  4114. watch(() => [props.include, props.exclude], ([include, exclude]) => {
  4115. include && pruneCache(name => matches(include, name));
  4116. exclude && pruneCache(name => !matches(exclude, name));
  4117. },
  4118. // prune post-render after `current` has been updated
  4119. { flush: 'post' });
  4120. // cache sub tree after render
  4121. let pendingCacheKey = null;
  4122. const cacheSubtree = () => {
  4123. // fix #1621, the pendingCacheKey could be 0
  4124. if (pendingCacheKey != null) {
  4125. cache.set(pendingCacheKey, getInnerChild(instance.subTree));
  4126. }
  4127. };
  4128. onMounted(cacheSubtree);
  4129. onUpdated(cacheSubtree);
  4130. onBeforeUnmount(() => {
  4131. cache.forEach(cached => {
  4132. const { subTree, suspense } = instance;
  4133. const vnode = getInnerChild(subTree);
  4134. if (cached.type === vnode.type) {
  4135. // current instance will be unmounted as part of keep-alive's unmount
  4136. resetShapeFlag(vnode);
  4137. // but invoke its deactivated hook here
  4138. const da = vnode.component.da;
  4139. da && queuePostRenderEffect(da, suspense);
  4140. return;
  4141. }
  4142. unmount(cached);
  4143. });
  4144. });
  4145. return () => {
  4146. pendingCacheKey = null;
  4147. if (!slots.default) {
  4148. return null;
  4149. }
  4150. const children = slots.default();
  4151. const rawVNode = children[0];
  4152. if (children.length > 1) {
  4153. {
  4154. warn(`KeepAlive should contain exactly one component child.`);
  4155. }
  4156. current = null;
  4157. return children;
  4158. }
  4159. else if (!isVNode(rawVNode) ||
  4160. (!(rawVNode.shapeFlag & 4 /* STATEFUL_COMPONENT */) &&
  4161. !(rawVNode.shapeFlag & 128 /* SUSPENSE */))) {
  4162. current = null;
  4163. return rawVNode;
  4164. }
  4165. let vnode = getInnerChild(rawVNode);
  4166. const comp = vnode.type;
  4167. const name = getName(comp);
  4168. const { include, exclude, max } = props;
  4169. if ((include && (!name || !matches(include, name))) ||
  4170. (exclude && name && matches(exclude, name))) {
  4171. current = vnode;
  4172. return rawVNode;
  4173. }
  4174. const key = vnode.key == null ? comp : vnode.key;
  4175. const cachedVNode = cache.get(key);
  4176. // clone vnode if it's reused because we are going to mutate it
  4177. if (vnode.el) {
  4178. vnode = cloneVNode(vnode);
  4179. if (rawVNode.shapeFlag & 128 /* SUSPENSE */) {
  4180. rawVNode.ssContent = vnode;
  4181. }
  4182. }
  4183. // #1513 it's possible for the returned vnode to be cloned due to attr
  4184. // fallthrough or scopeId, so the vnode here may not be the final vnode
  4185. // that is mounted. Instead of caching it directly, we store the pending
  4186. // key and cache `instance.subTree` (the normalized vnode) in
  4187. // beforeMount/beforeUpdate hooks.
  4188. pendingCacheKey = key;
  4189. if (cachedVNode) {
  4190. // copy over mounted state
  4191. vnode.el = cachedVNode.el;
  4192. vnode.component = cachedVNode.component;
  4193. if (vnode.transition) {
  4194. // recursively update transition hooks on subTree
  4195. setTransitionHooks(vnode, vnode.transition);
  4196. }
  4197. // avoid vnode being mounted as fresh
  4198. vnode.shapeFlag |= 512 /* COMPONENT_KEPT_ALIVE */;
  4199. // make this key the freshest
  4200. keys.delete(key);
  4201. keys.add(key);
  4202. }
  4203. else {
  4204. keys.add(key);
  4205. // prune oldest entry
  4206. if (max && keys.size > parseInt(max, 10)) {
  4207. pruneCacheEntry(keys.values().next().value);
  4208. }
  4209. }
  4210. // avoid vnode being unmounted
  4211. vnode.shapeFlag |= 256 /* COMPONENT_SHOULD_KEEP_ALIVE */;
  4212. current = vnode;
  4213. return rawVNode;
  4214. };
  4215. }
  4216. };
  4217. // export the public type for h/tsx inference
  4218. // also to avoid inline import() in generated d.ts files
  4219. const KeepAlive = KeepAliveImpl;
  4220. function getName(comp) {
  4221. return comp.displayName || comp.name;
  4222. }
  4223. function matches(pattern, name) {
  4224. if (isArray(pattern)) {
  4225. return pattern.some((p) => matches(p, name));
  4226. }
  4227. else if (isString(pattern)) {
  4228. return pattern.split(',').indexOf(name) > -1;
  4229. }
  4230. else if (pattern.test) {
  4231. return pattern.test(name);
  4232. }
  4233. /* istanbul ignore next */
  4234. return false;
  4235. }
  4236. function onActivated(hook, target) {
  4237. registerKeepAliveHook(hook, "a" /* ACTIVATED */, target);
  4238. }
  4239. function onDeactivated(hook, target) {
  4240. registerKeepAliveHook(hook, "da" /* DEACTIVATED */, target);
  4241. }
  4242. function registerKeepAliveHook(hook, type, target = currentInstance) {
  4243. // cache the deactivate branch check wrapper for injected hooks so the same
  4244. // hook can be properly deduped by the scheduler. "__wdc" stands for "with
  4245. // deactivation check".
  4246. const wrappedHook = hook.__wdc ||
  4247. (hook.__wdc = () => {
  4248. // only fire the hook if the target instance is NOT in a deactivated branch.
  4249. let current = target;
  4250. while (current) {
  4251. if (current.isDeactivated) {
  4252. return;
  4253. }
  4254. current = current.parent;
  4255. }
  4256. hook();
  4257. });
  4258. injectHook(type, wrappedHook, target);
  4259. // In addition to registering it on the target instance, we walk up the parent
  4260. // chain and register it on all ancestor instances that are keep-alive roots.
  4261. // This avoids the need to walk the entire component tree when invoking these
  4262. // hooks, and more importantly, avoids the need to track child components in
  4263. // arrays.
  4264. if (target) {
  4265. let current = target.parent;
  4266. while (current && current.parent) {
  4267. if (isKeepAlive(current.parent.vnode)) {
  4268. injectToKeepAliveRoot(wrappedHook, type, target, current);
  4269. }
  4270. current = current.parent;
  4271. }
  4272. }
  4273. }
  4274. function injectToKeepAliveRoot(hook, type, target, keepAliveRoot) {
  4275. // injectHook wraps the original for error handling, so make sure to remove
  4276. // the wrapped version.
  4277. const injected = injectHook(type, hook, keepAliveRoot, true /* prepend */);
  4278. onUnmounted(() => {
  4279. remove(keepAliveRoot[type], injected);
  4280. }, target);
  4281. }
  4282. function resetShapeFlag(vnode) {
  4283. let shapeFlag = vnode.shapeFlag;
  4284. if (shapeFlag & 256 /* COMPONENT_SHOULD_KEEP_ALIVE */) {
  4285. shapeFlag -= 256 /* COMPONENT_SHOULD_KEEP_ALIVE */;
  4286. }
  4287. if (shapeFlag & 512 /* COMPONENT_KEPT_ALIVE */) {
  4288. shapeFlag -= 512 /* COMPONENT_KEPT_ALIVE */;
  4289. }
  4290. vnode.shapeFlag = shapeFlag;
  4291. }
  4292. function getInnerChild(vnode) {
  4293. return vnode.shapeFlag & 128 /* SUSPENSE */ ? vnode.ssContent : vnode;
  4294. }
  4295. const isInternalKey = (key) => key[0] === '_' || key === '$stable';
  4296. const normalizeSlotValue = (value) => isArray(value)
  4297. ? value.map(normalizeVNode)
  4298. : [normalizeVNode(value)];
  4299. const normalizeSlot = (key, rawSlot, ctx) => withCtx((props) => {
  4300. if ( currentInstance) {
  4301. warn(`Slot "${key}" invoked outside of the render function: ` +
  4302. `this will not track dependencies used in the slot. ` +
  4303. `Invoke the slot function inside the render function instead.`);
  4304. }
  4305. return normalizeSlotValue(rawSlot(props));
  4306. }, ctx);
  4307. const normalizeObjectSlots = (rawSlots, slots) => {
  4308. const ctx = rawSlots._ctx;
  4309. for (const key in rawSlots) {
  4310. if (isInternalKey(key))
  4311. continue;
  4312. const value = rawSlots[key];
  4313. if (isFunction(value)) {
  4314. slots[key] = normalizeSlot(key, value, ctx);
  4315. }
  4316. else if (value != null) {
  4317. {
  4318. warn(`Non-function value encountered for slot "${key}". ` +
  4319. `Prefer function slots for better performance.`);
  4320. }
  4321. const normalized = normalizeSlotValue(value);
  4322. slots[key] = () => normalized;
  4323. }
  4324. }
  4325. };
  4326. const normalizeVNodeSlots = (instance, children) => {
  4327. if ( !isKeepAlive(instance.vnode)) {
  4328. warn(`Non-function value encountered for default slot. ` +
  4329. `Prefer function slots for better performance.`);
  4330. }
  4331. const normalized = normalizeSlotValue(children);
  4332. instance.slots.default = () => normalized;
  4333. };
  4334. const initSlots = (instance, children) => {
  4335. if (instance.vnode.shapeFlag & 32 /* SLOTS_CHILDREN */) {
  4336. const type = children._;
  4337. if (type) {
  4338. instance.slots = children;
  4339. // make compiler marker non-enumerable
  4340. def(children, '_', type);
  4341. }
  4342. else {
  4343. normalizeObjectSlots(children, (instance.slots = {}));
  4344. }
  4345. }
  4346. else {
  4347. instance.slots = {};
  4348. if (children) {
  4349. normalizeVNodeSlots(instance, children);
  4350. }
  4351. }
  4352. def(instance.slots, InternalObjectKey, 1);
  4353. };
  4354. const updateSlots = (instance, children) => {
  4355. const { vnode, slots } = instance;
  4356. let needDeletionCheck = true;
  4357. let deletionComparisonTarget = EMPTY_OBJ;
  4358. if (vnode.shapeFlag & 32 /* SLOTS_CHILDREN */) {
  4359. const type = children._;
  4360. if (type) {
  4361. // compiled slots.
  4362. if ( isHmrUpdating) {
  4363. // Parent was HMR updated so slot content may have changed.
  4364. // force update slots and mark instance for hmr as well
  4365. extend(slots, children);
  4366. }
  4367. else if (type === 1 /* STABLE */) {
  4368. // compiled AND stable.
  4369. // no need to update, and skip stale slots removal.
  4370. needDeletionCheck = false;
  4371. }
  4372. else {
  4373. // compiled but dynamic (v-if/v-for on slots) - update slots, but skip
  4374. // normalization.
  4375. extend(slots, children);
  4376. }
  4377. }
  4378. else {
  4379. needDeletionCheck = !children.$stable;
  4380. normalizeObjectSlots(children, slots);
  4381. }
  4382. deletionComparisonTarget = children;
  4383. }
  4384. else if (children) {
  4385. // non slot object children (direct value) passed to a component
  4386. normalizeVNodeSlots(instance, children);
  4387. deletionComparisonTarget = { default: 1 };
  4388. }
  4389. // delete stale slots
  4390. if (needDeletionCheck) {
  4391. for (const key in slots) {
  4392. if (!isInternalKey(key) && !(key in deletionComparisonTarget)) {
  4393. delete slots[key];
  4394. }
  4395. }
  4396. }
  4397. };
  4398. /**
  4399. Runtime helper for applying directives to a vnode. Example usage:
  4400. const comp = resolveComponent('comp')
  4401. const foo = resolveDirective('foo')
  4402. const bar = resolveDirective('bar')
  4403. return withDirectives(h(comp), [
  4404. [foo, this.x],
  4405. [bar, this.y]
  4406. ])
  4407. */
  4408. const isBuiltInDirective = /*#__PURE__*/ makeMap('bind,cloak,else-if,else,for,html,if,model,on,once,pre,show,slot,text');
  4409. function validateDirectiveName(name) {
  4410. if (isBuiltInDirective(name)) {
  4411. warn('Do not use built-in directive ids as custom directive id: ' + name);
  4412. }
  4413. }
  4414. /**
  4415. * Adds directives to a VNode.
  4416. */
  4417. function withDirectives(vnode, directives) {
  4418. const internalInstance = currentRenderingInstance;
  4419. if (internalInstance === null) {
  4420. warn(`withDirectives can only be used inside render functions.`);
  4421. return vnode;
  4422. }
  4423. const instance = internalInstance.proxy;
  4424. const bindings = vnode.dirs || (vnode.dirs = []);
  4425. for (let i = 0; i < directives.length; i++) {
  4426. let [dir, value, arg, modifiers = EMPTY_OBJ] = directives[i];
  4427. if (isFunction(dir)) {
  4428. dir = {
  4429. mounted: dir,
  4430. updated: dir
  4431. };
  4432. }
  4433. bindings.push({
  4434. dir,
  4435. instance,
  4436. value,
  4437. oldValue: void 0,
  4438. arg,
  4439. modifiers
  4440. });
  4441. }
  4442. return vnode;
  4443. }
  4444. function invokeDirectiveHook(vnode, prevVNode, instance, name) {
  4445. const bindings = vnode.dirs;
  4446. const oldBindings = prevVNode && prevVNode.dirs;
  4447. for (let i = 0; i < bindings.length; i++) {
  4448. const binding = bindings[i];
  4449. if (oldBindings) {
  4450. binding.oldValue = oldBindings[i].value;
  4451. }
  4452. const hook = binding.dir[name];
  4453. if (hook) {
  4454. callWithAsyncErrorHandling(hook, instance, 8 /* DIRECTIVE_HOOK */, [
  4455. vnode.el,
  4456. binding,
  4457. vnode,
  4458. prevVNode
  4459. ]);
  4460. }
  4461. }
  4462. }
  4463. function createAppContext() {
  4464. return {
  4465. app: null,
  4466. config: {
  4467. isNativeTag: NO,
  4468. performance: false,
  4469. globalProperties: {},
  4470. optionMergeStrategies: {},
  4471. isCustomElement: NO,
  4472. errorHandler: undefined,
  4473. warnHandler: undefined
  4474. },
  4475. mixins: [],
  4476. components: {},
  4477. directives: {},
  4478. provides: Object.create(null)
  4479. };
  4480. }
  4481. let uid$1 = 0;
  4482. function createAppAPI(render, hydrate) {
  4483. return function createApp(rootComponent, rootProps = null) {
  4484. if (rootProps != null && !isObject(rootProps)) {
  4485. warn(`root props passed to app.mount() must be an object.`);
  4486. rootProps = null;
  4487. }
  4488. const context = createAppContext();
  4489. const installedPlugins = new Set();
  4490. let isMounted = false;
  4491. const app = (context.app = {
  4492. _uid: uid$1++,
  4493. _component: rootComponent,
  4494. _props: rootProps,
  4495. _container: null,
  4496. _context: context,
  4497. version,
  4498. get config() {
  4499. return context.config;
  4500. },
  4501. set config(v) {
  4502. {
  4503. warn(`app.config cannot be replaced. Modify individual options instead.`);
  4504. }
  4505. },
  4506. use(plugin, ...options) {
  4507. if (installedPlugins.has(plugin)) {
  4508. warn(`Plugin has already been applied to target app.`);
  4509. }
  4510. else if (plugin && isFunction(plugin.install)) {
  4511. installedPlugins.add(plugin);
  4512. plugin.install(app, ...options);
  4513. }
  4514. else if (isFunction(plugin)) {
  4515. installedPlugins.add(plugin);
  4516. plugin(app, ...options);
  4517. }
  4518. else {
  4519. warn(`A plugin must either be a function or an object with an "install" ` +
  4520. `function.`);
  4521. }
  4522. return app;
  4523. },
  4524. mixin(mixin) {
  4525. {
  4526. if (!context.mixins.includes(mixin)) {
  4527. context.mixins.push(mixin);
  4528. }
  4529. else {
  4530. warn('Mixin has already been applied to target app' +
  4531. (mixin.name ? `: ${mixin.name}` : ''));
  4532. }
  4533. }
  4534. return app;
  4535. },
  4536. component(name, component) {
  4537. {
  4538. validateComponentName(name, context.config);
  4539. }
  4540. if (!component) {
  4541. return context.components[name];
  4542. }
  4543. if ( context.components[name]) {
  4544. warn(`Component "${name}" has already been registered in target app.`);
  4545. }
  4546. context.components[name] = component;
  4547. return app;
  4548. },
  4549. directive(name, directive) {
  4550. {
  4551. validateDirectiveName(name);
  4552. }
  4553. if (!directive) {
  4554. return context.directives[name];
  4555. }
  4556. if ( context.directives[name]) {
  4557. warn(`Directive "${name}" has already been registered in target app.`);
  4558. }
  4559. context.directives[name] = directive;
  4560. return app;
  4561. },
  4562. mount(rootContainer, isHydrate) {
  4563. if (!isMounted) {
  4564. const vnode = createVNode(rootComponent, rootProps);
  4565. // store app context on the root VNode.
  4566. // this will be set on the root instance on initial mount.
  4567. vnode.appContext = context;
  4568. // HMR root reload
  4569. {
  4570. context.reload = () => {
  4571. render(cloneVNode(vnode), rootContainer);
  4572. };
  4573. }
  4574. if (isHydrate && hydrate) {
  4575. hydrate(vnode, rootContainer);
  4576. }
  4577. else {
  4578. render(vnode, rootContainer);
  4579. }
  4580. isMounted = true;
  4581. app._container = rootContainer;
  4582. rootContainer.__vue_app__ = app;
  4583. {
  4584. devtoolsInitApp(app, version);
  4585. }
  4586. return vnode.component.proxy;
  4587. }
  4588. else {
  4589. warn(`App has already been mounted.\n` +
  4590. `If you want to remount the same app, move your app creation logic ` +
  4591. `into a factory function and create fresh app instances for each ` +
  4592. `mount - e.g. \`const createMyApp = () => createApp(App)\``);
  4593. }
  4594. },
  4595. unmount() {
  4596. if (isMounted) {
  4597. render(null, app._container);
  4598. {
  4599. devtoolsUnmountApp(app);
  4600. }
  4601. }
  4602. else {
  4603. warn(`Cannot unmount an app that is not mounted.`);
  4604. }
  4605. },
  4606. provide(key, value) {
  4607. if ( key in context.provides) {
  4608. warn(`App already provides property with key "${String(key)}". ` +
  4609. `It will be overwritten with the new value.`);
  4610. }
  4611. // TypeScript doesn't allow symbols as index type
  4612. // https://github.com/Microsoft/TypeScript/issues/24587
  4613. context.provides[key] = value;
  4614. return app;
  4615. }
  4616. });
  4617. return app;
  4618. };
  4619. }
  4620. let hasMismatch = false;
  4621. const isSVGContainer = (container) => /svg/.test(container.namespaceURI) && container.tagName !== 'foreignObject';
  4622. const isComment = (node) => node.nodeType === 8 /* COMMENT */;
  4623. // Note: hydration is DOM-specific
  4624. // But we have to place it in core due to tight coupling with core - splitting
  4625. // it out creates a ton of unnecessary complexity.
  4626. // Hydration also depends on some renderer internal logic which needs to be
  4627. // passed in via arguments.
  4628. function createHydrationFunctions(rendererInternals) {
  4629. const { mt: mountComponent, p: patch, o: { patchProp, nextSibling, parentNode, remove, insert, createComment } } = rendererInternals;
  4630. const hydrate = (vnode, container) => {
  4631. if ( !container.hasChildNodes()) {
  4632. warn(`Attempting to hydrate existing markup but container is empty. ` +
  4633. `Performing full mount instead.`);
  4634. patch(null, vnode, container);
  4635. return;
  4636. }
  4637. hasMismatch = false;
  4638. hydrateNode(container.firstChild, vnode, null, null);
  4639. flushPostFlushCbs();
  4640. if (hasMismatch && !false) {
  4641. // this error should show up in production
  4642. console.error(`Hydration completed but contains mismatches.`);
  4643. }
  4644. };
  4645. const hydrateNode = (node, vnode, parentComponent, parentSuspense, optimized = false) => {
  4646. const isFragmentStart = isComment(node) && node.data === '[';
  4647. const onMismatch = () => handleMismatch(node, vnode, parentComponent, parentSuspense, isFragmentStart);
  4648. const { type, ref, shapeFlag } = vnode;
  4649. const domType = node.nodeType;
  4650. vnode.el = node;
  4651. let nextNode = null;
  4652. switch (type) {
  4653. case Text:
  4654. if (domType !== 3 /* TEXT */) {
  4655. nextNode = onMismatch();
  4656. }
  4657. else {
  4658. if (node.data !== vnode.children) {
  4659. hasMismatch = true;
  4660. warn(`Hydration text mismatch:` +
  4661. `\n- Client: ${JSON.stringify(node.data)}` +
  4662. `\n- Server: ${JSON.stringify(vnode.children)}`);
  4663. node.data = vnode.children;
  4664. }
  4665. nextNode = nextSibling(node);
  4666. }
  4667. break;
  4668. case Comment:
  4669. if (domType !== 8 /* COMMENT */ || isFragmentStart) {
  4670. nextNode = onMismatch();
  4671. }
  4672. else {
  4673. nextNode = nextSibling(node);
  4674. }
  4675. break;
  4676. case Static:
  4677. if (domType !== 1 /* ELEMENT */) {
  4678. nextNode = onMismatch();
  4679. }
  4680. else {
  4681. // determine anchor, adopt content
  4682. nextNode = node;
  4683. // if the static vnode has its content stripped during build,
  4684. // adopt it from the server-rendered HTML.
  4685. const needToAdoptContent = !vnode.children.length;
  4686. for (let i = 0; i < vnode.staticCount; i++) {
  4687. if (needToAdoptContent)
  4688. vnode.children += nextNode.outerHTML;
  4689. if (i === vnode.staticCount - 1) {
  4690. vnode.anchor = nextNode;
  4691. }
  4692. nextNode = nextSibling(nextNode);
  4693. }
  4694. return nextNode;
  4695. }
  4696. break;
  4697. case Fragment:
  4698. if (!isFragmentStart) {
  4699. nextNode = onMismatch();
  4700. }
  4701. else {
  4702. nextNode = hydrateFragment(node, vnode, parentComponent, parentSuspense, optimized);
  4703. }
  4704. break;
  4705. default:
  4706. if (shapeFlag & 1 /* ELEMENT */) {
  4707. if (domType !== 1 /* ELEMENT */ ||
  4708. vnode.type !== node.tagName.toLowerCase()) {
  4709. nextNode = onMismatch();
  4710. }
  4711. else {
  4712. nextNode = hydrateElement(node, vnode, parentComponent, parentSuspense, optimized);
  4713. }
  4714. }
  4715. else if (shapeFlag & 6 /* COMPONENT */) {
  4716. // when setting up the render effect, if the initial vnode already
  4717. // has .el set, the component will perform hydration instead of mount
  4718. // on its sub-tree.
  4719. const container = parentNode(node);
  4720. const hydrateComponent = () => {
  4721. mountComponent(vnode, container, null, parentComponent, parentSuspense, isSVGContainer(container), optimized);
  4722. };
  4723. // async component
  4724. const loadAsync = vnode.type.__asyncLoader;
  4725. if (loadAsync) {
  4726. loadAsync().then(hydrateComponent);
  4727. }
  4728. else {
  4729. hydrateComponent();
  4730. }
  4731. // component may be async, so in the case of fragments we cannot rely
  4732. // on component's rendered output to determine the end of the fragment
  4733. // instead, we do a lookahead to find the end anchor node.
  4734. nextNode = isFragmentStart
  4735. ? locateClosingAsyncAnchor(node)
  4736. : nextSibling(node);
  4737. }
  4738. else if (shapeFlag & 64 /* TELEPORT */) {
  4739. if (domType !== 8 /* COMMENT */) {
  4740. nextNode = onMismatch();
  4741. }
  4742. else {
  4743. nextNode = vnode.type.hydrate(node, vnode, parentComponent, parentSuspense, optimized, rendererInternals, hydrateChildren);
  4744. }
  4745. }
  4746. else if ( shapeFlag & 128 /* SUSPENSE */) {
  4747. nextNode = vnode.type.hydrate(node, vnode, parentComponent, parentSuspense, isSVGContainer(parentNode(node)), optimized, rendererInternals, hydrateNode);
  4748. }
  4749. else {
  4750. warn('Invalid HostVNode type:', type, `(${typeof type})`);
  4751. }
  4752. }
  4753. if (ref != null && parentComponent) {
  4754. setRef(ref, null, parentComponent, parentSuspense, vnode);
  4755. }
  4756. return nextNode;
  4757. };
  4758. const hydrateElement = (el, vnode, parentComponent, parentSuspense, optimized) => {
  4759. optimized = optimized || !!vnode.dynamicChildren;
  4760. const { props, patchFlag, shapeFlag, dirs } = vnode;
  4761. // skip props & children if this is hoisted static nodes
  4762. if (patchFlag !== -1 /* HOISTED */) {
  4763. if (dirs) {
  4764. invokeDirectiveHook(vnode, null, parentComponent, 'created');
  4765. }
  4766. // props
  4767. if (props) {
  4768. if (!optimized ||
  4769. (patchFlag & 16 /* FULL_PROPS */ ||
  4770. patchFlag & 32 /* HYDRATE_EVENTS */)) {
  4771. for (const key in props) {
  4772. if (!isReservedProp(key) && isOn(key)) {
  4773. patchProp(el, key, null, props[key]);
  4774. }
  4775. }
  4776. }
  4777. else if (props.onClick) {
  4778. // Fast path for click listeners (which is most often) to avoid
  4779. // iterating through props.
  4780. patchProp(el, 'onClick', null, props.onClick);
  4781. }
  4782. }
  4783. // vnode / directive hooks
  4784. let vnodeHooks;
  4785. if ((vnodeHooks = props && props.onVnodeBeforeMount)) {
  4786. invokeVNodeHook(vnodeHooks, parentComponent, vnode);
  4787. }
  4788. if (dirs) {
  4789. invokeDirectiveHook(vnode, null, parentComponent, 'beforeMount');
  4790. }
  4791. if ((vnodeHooks = props && props.onVnodeMounted) || dirs) {
  4792. queueEffectWithSuspense(() => {
  4793. vnodeHooks && invokeVNodeHook(vnodeHooks, parentComponent, vnode);
  4794. dirs && invokeDirectiveHook(vnode, null, parentComponent, 'mounted');
  4795. }, parentSuspense);
  4796. }
  4797. // children
  4798. if (shapeFlag & 16 /* ARRAY_CHILDREN */ &&
  4799. // skip if element has innerHTML / textContent
  4800. !(props && (props.innerHTML || props.textContent))) {
  4801. let next = hydrateChildren(el.firstChild, vnode, el, parentComponent, parentSuspense, optimized);
  4802. let hasWarned = false;
  4803. while (next) {
  4804. hasMismatch = true;
  4805. if ( !hasWarned) {
  4806. warn(`Hydration children mismatch in <${vnode.type}>: ` +
  4807. `server rendered element contains more child nodes than client vdom.`);
  4808. hasWarned = true;
  4809. }
  4810. // The SSRed DOM contains more nodes than it should. Remove them.
  4811. const cur = next;
  4812. next = next.nextSibling;
  4813. remove(cur);
  4814. }
  4815. }
  4816. else if (shapeFlag & 8 /* TEXT_CHILDREN */) {
  4817. if (el.textContent !== vnode.children) {
  4818. hasMismatch = true;
  4819. warn(`Hydration text content mismatch in <${vnode.type}>:\n` +
  4820. `- Client: ${el.textContent}\n` +
  4821. `- Server: ${vnode.children}`);
  4822. el.textContent = vnode.children;
  4823. }
  4824. }
  4825. }
  4826. return el.nextSibling;
  4827. };
  4828. const hydrateChildren = (node, parentVNode, container, parentComponent, parentSuspense, optimized) => {
  4829. optimized = optimized || !!parentVNode.dynamicChildren;
  4830. const children = parentVNode.children;
  4831. const l = children.length;
  4832. let hasWarned = false;
  4833. for (let i = 0; i < l; i++) {
  4834. const vnode = optimized
  4835. ? children[i]
  4836. : (children[i] = normalizeVNode(children[i]));
  4837. if (node) {
  4838. node = hydrateNode(node, vnode, parentComponent, parentSuspense, optimized);
  4839. }
  4840. else {
  4841. hasMismatch = true;
  4842. if ( !hasWarned) {
  4843. warn(`Hydration children mismatch in <${container.tagName.toLowerCase()}>: ` +
  4844. `server rendered element contains fewer child nodes than client vdom.`);
  4845. hasWarned = true;
  4846. }
  4847. // the SSRed DOM didn't contain enough nodes. Mount the missing ones.
  4848. patch(null, vnode, container, null, parentComponent, parentSuspense, isSVGContainer(container));
  4849. }
  4850. }
  4851. return node;
  4852. };
  4853. const hydrateFragment = (node, vnode, parentComponent, parentSuspense, optimized) => {
  4854. const container = parentNode(node);
  4855. const next = hydrateChildren(nextSibling(node), vnode, container, parentComponent, parentSuspense, optimized);
  4856. if (next && isComment(next) && next.data === ']') {
  4857. return nextSibling((vnode.anchor = next));
  4858. }
  4859. else {
  4860. // fragment didn't hydrate successfully, since we didn't get a end anchor
  4861. // back. This should have led to node/children mismatch warnings.
  4862. hasMismatch = true;
  4863. // since the anchor is missing, we need to create one and insert it
  4864. insert((vnode.anchor = createComment(`]`)), container, next);
  4865. return next;
  4866. }
  4867. };
  4868. const handleMismatch = (node, vnode, parentComponent, parentSuspense, isFragment) => {
  4869. hasMismatch = true;
  4870. warn(`Hydration node mismatch:\n- Client vnode:`, vnode.type, `\n- Server rendered DOM:`, node, node.nodeType === 3 /* TEXT */
  4871. ? `(text)`
  4872. : isComment(node) && node.data === '['
  4873. ? `(start of fragment)`
  4874. : ``);
  4875. vnode.el = null;
  4876. if (isFragment) {
  4877. // remove excessive fragment nodes
  4878. const end = locateClosingAsyncAnchor(node);
  4879. while (true) {
  4880. const next = nextSibling(node);
  4881. if (next && next !== end) {
  4882. remove(next);
  4883. }
  4884. else {
  4885. break;
  4886. }
  4887. }
  4888. }
  4889. const next = nextSibling(node);
  4890. const container = parentNode(node);
  4891. remove(node);
  4892. patch(null, vnode, container, next, parentComponent, parentSuspense, isSVGContainer(container));
  4893. return next;
  4894. };
  4895. const locateClosingAsyncAnchor = (node) => {
  4896. let match = 0;
  4897. while (node) {
  4898. node = nextSibling(node);
  4899. if (node && isComment(node)) {
  4900. if (node.data === '[')
  4901. match++;
  4902. if (node.data === ']') {
  4903. if (match === 0) {
  4904. return nextSibling(node);
  4905. }
  4906. else {
  4907. match--;
  4908. }
  4909. }
  4910. }
  4911. }
  4912. return node;
  4913. };
  4914. return [hydrate, hydrateNode];
  4915. }
  4916. let supported;
  4917. let perf;
  4918. function startMeasure(instance, type) {
  4919. if (instance.appContext.config.performance && isSupported()) {
  4920. perf.mark(`vue-${type}-${instance.uid}`);
  4921. }
  4922. }
  4923. function endMeasure(instance, type) {
  4924. if (instance.appContext.config.performance && isSupported()) {
  4925. const startTag = `vue-${type}-${instance.uid}`;
  4926. const endTag = startTag + `:end`;
  4927. perf.mark(endTag);
  4928. perf.measure(`<${formatComponentName(instance, instance.type)}> ${type}`, startTag, endTag);
  4929. perf.clearMarks(startTag);
  4930. perf.clearMarks(endTag);
  4931. }
  4932. }
  4933. function isSupported() {
  4934. if (supported !== undefined) {
  4935. return supported;
  4936. }
  4937. /* eslint-disable no-restricted-globals */
  4938. if (typeof window !== 'undefined' && window.performance) {
  4939. supported = true;
  4940. perf = window.performance;
  4941. }
  4942. else {
  4943. supported = false;
  4944. }
  4945. /* eslint-enable no-restricted-globals */
  4946. return supported;
  4947. }
  4948. function createDevEffectOptions(instance) {
  4949. return {
  4950. scheduler: queueJob,
  4951. allowRecurse: true,
  4952. onTrack: instance.rtc ? e => invokeArrayFns(instance.rtc, e) : void 0,
  4953. onTrigger: instance.rtg ? e => invokeArrayFns(instance.rtg, e) : void 0
  4954. };
  4955. }
  4956. const queuePostRenderEffect = queueEffectWithSuspense
  4957. ;
  4958. const setRef = (rawRef, oldRawRef, parentComponent, parentSuspense, vnode) => {
  4959. if (isArray(rawRef)) {
  4960. rawRef.forEach((r, i) => setRef(r, oldRawRef && (isArray(oldRawRef) ? oldRawRef[i] : oldRawRef), parentComponent, parentSuspense, vnode));
  4961. return;
  4962. }
  4963. let value;
  4964. if (!vnode) {
  4965. value = null;
  4966. }
  4967. else {
  4968. if (vnode.shapeFlag & 4 /* STATEFUL_COMPONENT */) {
  4969. value = vnode.component.proxy;
  4970. }
  4971. else {
  4972. value = vnode.el;
  4973. }
  4974. }
  4975. const { i: owner, r: ref } = rawRef;
  4976. if ( !owner) {
  4977. warn(`Missing ref owner context. ref cannot be used on hoisted vnodes. ` +
  4978. `A vnode with ref must be created inside the render function.`);
  4979. return;
  4980. }
  4981. const oldRef = oldRawRef && oldRawRef.r;
  4982. const refs = owner.refs === EMPTY_OBJ ? (owner.refs = {}) : owner.refs;
  4983. const setupState = owner.setupState;
  4984. // unset old ref
  4985. if (oldRef != null && oldRef !== ref) {
  4986. if (isString(oldRef)) {
  4987. refs[oldRef] = null;
  4988. if (hasOwn(setupState, oldRef)) {
  4989. setupState[oldRef] = null;
  4990. }
  4991. }
  4992. else if (isRef(oldRef)) {
  4993. oldRef.value = null;
  4994. }
  4995. }
  4996. if (isString(ref)) {
  4997. const doSet = () => {
  4998. refs[ref] = value;
  4999. if (hasOwn(setupState, ref)) {
  5000. setupState[ref] = value;
  5001. }
  5002. };
  5003. // #1789: for non-null values, set them after render
  5004. // null values means this is unmount and it should not overwrite another
  5005. // ref with the same key
  5006. if (value) {
  5007. doSet.id = -1;
  5008. queuePostRenderEffect(doSet, parentSuspense);
  5009. }
  5010. else {
  5011. doSet();
  5012. }
  5013. }
  5014. else if (isRef(ref)) {
  5015. const doSet = () => {
  5016. ref.value = value;
  5017. };
  5018. if (value) {
  5019. doSet.id = -1;
  5020. queuePostRenderEffect(doSet, parentSuspense);
  5021. }
  5022. else {
  5023. doSet();
  5024. }
  5025. }
  5026. else if (isFunction(ref)) {
  5027. callWithErrorHandling(ref, parentComponent, 12 /* FUNCTION_REF */, [
  5028. value,
  5029. refs
  5030. ]);
  5031. }
  5032. else {
  5033. warn('Invalid template ref type:', value, `(${typeof value})`);
  5034. }
  5035. };
  5036. /**
  5037. * The createRenderer function accepts two generic arguments:
  5038. * HostNode and HostElement, corresponding to Node and Element types in the
  5039. * host environment. For example, for runtime-dom, HostNode would be the DOM
  5040. * `Node` interface and HostElement would be the DOM `Element` interface.
  5041. *
  5042. * Custom renderers can pass in the platform specific types like this:
  5043. *
  5044. * ``` js
  5045. * const { render, createApp } = createRenderer<Node, Element>({
  5046. * patchProp,
  5047. * ...nodeOps
  5048. * })
  5049. * ```
  5050. */
  5051. function createRenderer(options) {
  5052. return baseCreateRenderer(options);
  5053. }
  5054. // Separate API for creating hydration-enabled renderer.
  5055. // Hydration logic is only used when calling this function, making it
  5056. // tree-shakable.
  5057. function createHydrationRenderer(options) {
  5058. return baseCreateRenderer(options, createHydrationFunctions);
  5059. }
  5060. // implementation
  5061. function baseCreateRenderer(options, createHydrationFns) {
  5062. const { insert: hostInsert, remove: hostRemove, patchProp: hostPatchProp, forcePatchProp: hostForcePatchProp, createElement: hostCreateElement, createText: hostCreateText, createComment: hostCreateComment, setText: hostSetText, setElementText: hostSetElementText, parentNode: hostParentNode, nextSibling: hostNextSibling, setScopeId: hostSetScopeId = NOOP, cloneNode: hostCloneNode, insertStaticContent: hostInsertStaticContent } = options;
  5063. // Note: functions inside this closure should use `const xxx = () => {}`
  5064. // style in order to prevent being inlined by minifiers.
  5065. const patch = (n1, n2, container, anchor = null, parentComponent = null, parentSuspense = null, isSVG = false, optimized = false) => {
  5066. // patching & not same type, unmount old tree
  5067. if (n1 && !isSameVNodeType(n1, n2)) {
  5068. anchor = getNextHostNode(n1);
  5069. unmount(n1, parentComponent, parentSuspense, true);
  5070. n1 = null;
  5071. }
  5072. if (n2.patchFlag === -2 /* BAIL */) {
  5073. optimized = false;
  5074. n2.dynamicChildren = null;
  5075. }
  5076. const { type, ref, shapeFlag } = n2;
  5077. switch (type) {
  5078. case Text:
  5079. processText(n1, n2, container, anchor);
  5080. break;
  5081. case Comment:
  5082. processCommentNode(n1, n2, container, anchor);
  5083. break;
  5084. case Static:
  5085. if (n1 == null) {
  5086. mountStaticNode(n2, container, anchor, isSVG);
  5087. }
  5088. else {
  5089. patchStaticNode(n1, n2, container, isSVG);
  5090. }
  5091. break;
  5092. case Fragment:
  5093. processFragment(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, optimized);
  5094. break;
  5095. default:
  5096. if (shapeFlag & 1 /* ELEMENT */) {
  5097. processElement(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, optimized);
  5098. }
  5099. else if (shapeFlag & 6 /* COMPONENT */) {
  5100. processComponent(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, optimized);
  5101. }
  5102. else if (shapeFlag & 64 /* TELEPORT */) {
  5103. type.process(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, optimized, internals);
  5104. }
  5105. else if ( shapeFlag & 128 /* SUSPENSE */) {
  5106. type.process(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, optimized, internals);
  5107. }
  5108. else {
  5109. warn('Invalid VNode type:', type, `(${typeof type})`);
  5110. }
  5111. }
  5112. // set ref
  5113. if (ref != null && parentComponent) {
  5114. setRef(ref, n1 && n1.ref, parentComponent, parentSuspense, n2);
  5115. }
  5116. };
  5117. const processText = (n1, n2, container, anchor) => {
  5118. if (n1 == null) {
  5119. hostInsert((n2.el = hostCreateText(n2.children)), container, anchor);
  5120. }
  5121. else {
  5122. const el = (n2.el = n1.el);
  5123. if (n2.children !== n1.children) {
  5124. hostSetText(el, n2.children);
  5125. }
  5126. }
  5127. };
  5128. const processCommentNode = (n1, n2, container, anchor) => {
  5129. if (n1 == null) {
  5130. hostInsert((n2.el = hostCreateComment(n2.children || '')), container, anchor);
  5131. }
  5132. else {
  5133. // there's no support for dynamic comments
  5134. n2.el = n1.el;
  5135. }
  5136. };
  5137. const mountStaticNode = (n2, container, anchor, isSVG) => {
  5138. [n2.el, n2.anchor] = hostInsertStaticContent(n2.children, container, anchor, isSVG);
  5139. };
  5140. /**
  5141. * Dev / HMR only
  5142. */
  5143. const patchStaticNode = (n1, n2, container, isSVG) => {
  5144. // static nodes are only patched during dev for HMR
  5145. if (n2.children !== n1.children) {
  5146. const anchor = hostNextSibling(n1.anchor);
  5147. // remove existing
  5148. removeStaticNode(n1);
  5149. [n2.el, n2.anchor] = hostInsertStaticContent(n2.children, container, anchor, isSVG);
  5150. }
  5151. else {
  5152. n2.el = n1.el;
  5153. n2.anchor = n1.anchor;
  5154. }
  5155. };
  5156. /**
  5157. * Dev / HMR only
  5158. */
  5159. const moveStaticNode = (vnode, container, anchor) => {
  5160. let cur = vnode.el;
  5161. const end = vnode.anchor;
  5162. while (cur && cur !== end) {
  5163. const next = hostNextSibling(cur);
  5164. hostInsert(cur, container, anchor);
  5165. cur = next;
  5166. }
  5167. hostInsert(end, container, anchor);
  5168. };
  5169. /**
  5170. * Dev / HMR only
  5171. */
  5172. const removeStaticNode = (vnode) => {
  5173. let cur = vnode.el;
  5174. while (cur && cur !== vnode.anchor) {
  5175. const next = hostNextSibling(cur);
  5176. hostRemove(cur);
  5177. cur = next;
  5178. }
  5179. hostRemove(vnode.anchor);
  5180. };
  5181. const processElement = (n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, optimized) => {
  5182. isSVG = isSVG || n2.type === 'svg';
  5183. if (n1 == null) {
  5184. mountElement(n2, container, anchor, parentComponent, parentSuspense, isSVG, optimized);
  5185. }
  5186. else {
  5187. patchElement(n1, n2, parentComponent, parentSuspense, isSVG, optimized);
  5188. }
  5189. };
  5190. const mountElement = (vnode, container, anchor, parentComponent, parentSuspense, isSVG, optimized) => {
  5191. let el;
  5192. let vnodeHook;
  5193. const { type, props, shapeFlag, transition, scopeId, patchFlag, dirs } = vnode;
  5194. {
  5195. el = vnode.el = hostCreateElement(vnode.type, isSVG, props && props.is);
  5196. // mount children first, since some props may rely on child content
  5197. // being already rendered, e.g. `<select value>`
  5198. if (shapeFlag & 8 /* TEXT_CHILDREN */) {
  5199. hostSetElementText(el, vnode.children);
  5200. }
  5201. else if (shapeFlag & 16 /* ARRAY_CHILDREN */) {
  5202. mountChildren(vnode.children, el, null, parentComponent, parentSuspense, isSVG && type !== 'foreignObject', optimized || !!vnode.dynamicChildren);
  5203. }
  5204. if (dirs) {
  5205. invokeDirectiveHook(vnode, null, parentComponent, 'created');
  5206. }
  5207. // props
  5208. if (props) {
  5209. for (const key in props) {
  5210. if (!isReservedProp(key)) {
  5211. hostPatchProp(el, key, null, props[key], isSVG, vnode.children, parentComponent, parentSuspense, unmountChildren);
  5212. }
  5213. }
  5214. if ((vnodeHook = props.onVnodeBeforeMount)) {
  5215. invokeVNodeHook(vnodeHook, parentComponent, vnode);
  5216. }
  5217. }
  5218. // scopeId
  5219. setScopeId(el, scopeId, vnode, parentComponent);
  5220. }
  5221. {
  5222. Object.defineProperty(el, '__vnode', {
  5223. value: vnode,
  5224. enumerable: false
  5225. });
  5226. Object.defineProperty(el, '__vueParentComponent', {
  5227. value: parentComponent,
  5228. enumerable: false
  5229. });
  5230. }
  5231. if (dirs) {
  5232. invokeDirectiveHook(vnode, null, parentComponent, 'beforeMount');
  5233. }
  5234. // #1583 For inside suspense + suspense not resolved case, enter hook should call when suspense resolved
  5235. // #1689 For inside suspense + suspense resolved case, just call it
  5236. const needCallTransitionHooks = (!parentSuspense || (parentSuspense && !parentSuspense.pendingBranch)) &&
  5237. transition &&
  5238. !transition.persisted;
  5239. if (needCallTransitionHooks) {
  5240. transition.beforeEnter(el);
  5241. }
  5242. hostInsert(el, container, anchor);
  5243. if ((vnodeHook = props && props.onVnodeMounted) ||
  5244. needCallTransitionHooks ||
  5245. dirs) {
  5246. queuePostRenderEffect(() => {
  5247. vnodeHook && invokeVNodeHook(vnodeHook, parentComponent, vnode);
  5248. needCallTransitionHooks && transition.enter(el);
  5249. dirs && invokeDirectiveHook(vnode, null, parentComponent, 'mounted');
  5250. }, parentSuspense);
  5251. }
  5252. };
  5253. const setScopeId = (el, scopeId, vnode, parentComponent) => {
  5254. if (scopeId) {
  5255. hostSetScopeId(el, scopeId);
  5256. }
  5257. if (parentComponent) {
  5258. const treeOwnerId = parentComponent.type.__scopeId;
  5259. // vnode's own scopeId and the current patched component's scopeId is
  5260. // different - this is a slot content node.
  5261. if (treeOwnerId && treeOwnerId !== scopeId) {
  5262. hostSetScopeId(el, treeOwnerId + '-s');
  5263. }
  5264. let subTree = parentComponent.subTree;
  5265. if ( subTree.type === Fragment) {
  5266. subTree =
  5267. filterSingleRoot(subTree.children) || subTree;
  5268. }
  5269. if (vnode === subTree) {
  5270. setScopeId(el, parentComponent.vnode.scopeId, parentComponent.vnode, parentComponent.parent);
  5271. }
  5272. }
  5273. };
  5274. const mountChildren = (children, container, anchor, parentComponent, parentSuspense, isSVG, optimized, start = 0) => {
  5275. for (let i = start; i < children.length; i++) {
  5276. const child = (children[i] = optimized
  5277. ? cloneIfMounted(children[i])
  5278. : normalizeVNode(children[i]));
  5279. patch(null, child, container, anchor, parentComponent, parentSuspense, isSVG, optimized);
  5280. }
  5281. };
  5282. const patchElement = (n1, n2, parentComponent, parentSuspense, isSVG, optimized) => {
  5283. const el = (n2.el = n1.el);
  5284. let { patchFlag, dynamicChildren, dirs } = n2;
  5285. // #1426 take the old vnode's patch flag into account since user may clone a
  5286. // compiler-generated vnode, which de-opts to FULL_PROPS
  5287. patchFlag |= n1.patchFlag & 16 /* FULL_PROPS */;
  5288. const oldProps = n1.props || EMPTY_OBJ;
  5289. const newProps = n2.props || EMPTY_OBJ;
  5290. let vnodeHook;
  5291. if ((vnodeHook = newProps.onVnodeBeforeUpdate)) {
  5292. invokeVNodeHook(vnodeHook, parentComponent, n2, n1);
  5293. }
  5294. if (dirs) {
  5295. invokeDirectiveHook(n2, n1, parentComponent, 'beforeUpdate');
  5296. }
  5297. if ( isHmrUpdating) {
  5298. // HMR updated, force full diff
  5299. patchFlag = 0;
  5300. optimized = false;
  5301. dynamicChildren = null;
  5302. }
  5303. if (patchFlag > 0) {
  5304. // the presence of a patchFlag means this element's render code was
  5305. // generated by the compiler and can take the fast path.
  5306. // in this path old node and new node are guaranteed to have the same shape
  5307. // (i.e. at the exact same position in the source template)
  5308. if (patchFlag & 16 /* FULL_PROPS */) {
  5309. // element props contain dynamic keys, full diff needed
  5310. patchProps(el, n2, oldProps, newProps, parentComponent, parentSuspense, isSVG);
  5311. }
  5312. else {
  5313. // class
  5314. // this flag is matched when the element has dynamic class bindings.
  5315. if (patchFlag & 2 /* CLASS */) {
  5316. if (oldProps.class !== newProps.class) {
  5317. hostPatchProp(el, 'class', null, newProps.class, isSVG);
  5318. }
  5319. }
  5320. // style
  5321. // this flag is matched when the element has dynamic style bindings
  5322. if (patchFlag & 4 /* STYLE */) {
  5323. hostPatchProp(el, 'style', oldProps.style, newProps.style, isSVG);
  5324. }
  5325. // props
  5326. // This flag is matched when the element has dynamic prop/attr bindings
  5327. // other than class and style. The keys of dynamic prop/attrs are saved for
  5328. // faster iteration.
  5329. // Note dynamic keys like :[foo]="bar" will cause this optimization to
  5330. // bail out and go through a full diff because we need to unset the old key
  5331. if (patchFlag & 8 /* PROPS */) {
  5332. // if the flag is present then dynamicProps must be non-null
  5333. const propsToUpdate = n2.dynamicProps;
  5334. for (let i = 0; i < propsToUpdate.length; i++) {
  5335. const key = propsToUpdate[i];
  5336. const prev = oldProps[key];
  5337. const next = newProps[key];
  5338. if (next !== prev ||
  5339. (hostForcePatchProp && hostForcePatchProp(el, key))) {
  5340. hostPatchProp(el, key, prev, next, isSVG, n1.children, parentComponent, parentSuspense, unmountChildren);
  5341. }
  5342. }
  5343. }
  5344. }
  5345. // text
  5346. // This flag is matched when the element has only dynamic text children.
  5347. if (patchFlag & 1 /* TEXT */) {
  5348. if (n1.children !== n2.children) {
  5349. hostSetElementText(el, n2.children);
  5350. }
  5351. }
  5352. }
  5353. else if (!optimized && dynamicChildren == null) {
  5354. // unoptimized, full diff
  5355. patchProps(el, n2, oldProps, newProps, parentComponent, parentSuspense, isSVG);
  5356. }
  5357. const areChildrenSVG = isSVG && n2.type !== 'foreignObject';
  5358. if (dynamicChildren) {
  5359. patchBlockChildren(n1.dynamicChildren, dynamicChildren, el, parentComponent, parentSuspense, areChildrenSVG);
  5360. if ( parentComponent && parentComponent.type.__hmrId) {
  5361. traverseStaticChildren(n1, n2);
  5362. }
  5363. }
  5364. else if (!optimized) {
  5365. // full diff
  5366. patchChildren(n1, n2, el, null, parentComponent, parentSuspense, areChildrenSVG);
  5367. }
  5368. if ((vnodeHook = newProps.onVnodeUpdated) || dirs) {
  5369. queuePostRenderEffect(() => {
  5370. vnodeHook && invokeVNodeHook(vnodeHook, parentComponent, n2, n1);
  5371. dirs && invokeDirectiveHook(n2, n1, parentComponent, 'updated');
  5372. }, parentSuspense);
  5373. }
  5374. };
  5375. // The fast path for blocks.
  5376. const patchBlockChildren = (oldChildren, newChildren, fallbackContainer, parentComponent, parentSuspense, isSVG) => {
  5377. for (let i = 0; i < newChildren.length; i++) {
  5378. const oldVNode = oldChildren[i];
  5379. const newVNode = newChildren[i];
  5380. // Determine the container (parent element) for the patch.
  5381. const container =
  5382. // - In the case of a Fragment, we need to provide the actual parent
  5383. // of the Fragment itself so it can move its children.
  5384. oldVNode.type === Fragment ||
  5385. // - In the case of different nodes, there is going to be a replacement
  5386. // which also requires the correct parent container
  5387. !isSameVNodeType(oldVNode, newVNode) ||
  5388. // - In the case of a component, it could contain anything.
  5389. oldVNode.shapeFlag & 6 /* COMPONENT */ ||
  5390. oldVNode.shapeFlag & 64 /* TELEPORT */
  5391. ? hostParentNode(oldVNode.el)
  5392. : // In other cases, the parent container is not actually used so we
  5393. // just pass the block element here to avoid a DOM parentNode call.
  5394. fallbackContainer;
  5395. patch(oldVNode, newVNode, container, null, parentComponent, parentSuspense, isSVG, true);
  5396. }
  5397. };
  5398. const patchProps = (el, vnode, oldProps, newProps, parentComponent, parentSuspense, isSVG) => {
  5399. if (oldProps !== newProps) {
  5400. for (const key in newProps) {
  5401. if (isReservedProp(key))
  5402. continue;
  5403. const next = newProps[key];
  5404. const prev = oldProps[key];
  5405. if (next !== prev ||
  5406. (hostForcePatchProp && hostForcePatchProp(el, key))) {
  5407. hostPatchProp(el, key, prev, next, isSVG, vnode.children, parentComponent, parentSuspense, unmountChildren);
  5408. }
  5409. }
  5410. if (oldProps !== EMPTY_OBJ) {
  5411. for (const key in oldProps) {
  5412. if (!isReservedProp(key) && !(key in newProps)) {
  5413. hostPatchProp(el, key, oldProps[key], null, isSVG, vnode.children, parentComponent, parentSuspense, unmountChildren);
  5414. }
  5415. }
  5416. }
  5417. }
  5418. };
  5419. const processFragment = (n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, optimized) => {
  5420. const fragmentStartAnchor = (n2.el = n1 ? n1.el : hostCreateText(''));
  5421. const fragmentEndAnchor = (n2.anchor = n1 ? n1.anchor : hostCreateText(''));
  5422. let { patchFlag, dynamicChildren } = n2;
  5423. if (patchFlag > 0) {
  5424. optimized = true;
  5425. }
  5426. if ( isHmrUpdating) {
  5427. // HMR updated, force full diff
  5428. patchFlag = 0;
  5429. optimized = false;
  5430. dynamicChildren = null;
  5431. }
  5432. if (n1 == null) {
  5433. hostInsert(fragmentStartAnchor, container, anchor);
  5434. hostInsert(fragmentEndAnchor, container, anchor);
  5435. // a fragment can only have array children
  5436. // since they are either generated by the compiler, or implicitly created
  5437. // from arrays.
  5438. mountChildren(n2.children, container, fragmentEndAnchor, parentComponent, parentSuspense, isSVG, optimized);
  5439. }
  5440. else {
  5441. if (patchFlag > 0 &&
  5442. patchFlag & 64 /* STABLE_FRAGMENT */ &&
  5443. dynamicChildren) {
  5444. // a stable fragment (template root or <template v-for>) doesn't need to
  5445. // patch children order, but it may contain dynamicChildren.
  5446. patchBlockChildren(n1.dynamicChildren, dynamicChildren, container, parentComponent, parentSuspense, isSVG);
  5447. if ( parentComponent && parentComponent.type.__hmrId) {
  5448. traverseStaticChildren(n1, n2);
  5449. }
  5450. else if (
  5451. // #2080 if the stable fragment has a key, it's a <template v-for> that may
  5452. // get moved around. Make sure all root level vnodes inherit el.
  5453. // #2134 or if it's a component root, it may also get moved around
  5454. // as the component is being moved.
  5455. n2.key != null ||
  5456. (parentComponent && n2 === parentComponent.subTree)) {
  5457. traverseStaticChildren(n1, n2, true /* shallow */);
  5458. }
  5459. }
  5460. else {
  5461. // keyed / unkeyed, or manual fragments.
  5462. // for keyed & unkeyed, since they are compiler generated from v-for,
  5463. // each child is guaranteed to be a block so the fragment will never
  5464. // have dynamicChildren.
  5465. patchChildren(n1, n2, container, fragmentEndAnchor, parentComponent, parentSuspense, isSVG, optimized);
  5466. }
  5467. }
  5468. };
  5469. const processComponent = (n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, optimized) => {
  5470. if (n1 == null) {
  5471. if (n2.shapeFlag & 512 /* COMPONENT_KEPT_ALIVE */) {
  5472. parentComponent.ctx.activate(n2, container, anchor, isSVG, optimized);
  5473. }
  5474. else {
  5475. mountComponent(n2, container, anchor, parentComponent, parentSuspense, isSVG, optimized);
  5476. }
  5477. }
  5478. else {
  5479. updateComponent(n1, n2, optimized);
  5480. }
  5481. };
  5482. const mountComponent = (initialVNode, container, anchor, parentComponent, parentSuspense, isSVG, optimized) => {
  5483. const instance = (initialVNode.component = createComponentInstance(initialVNode, parentComponent, parentSuspense));
  5484. if ( instance.type.__hmrId) {
  5485. registerHMR(instance);
  5486. }
  5487. {
  5488. pushWarningContext(initialVNode);
  5489. startMeasure(instance, `mount`);
  5490. }
  5491. // inject renderer internals for keepAlive
  5492. if (isKeepAlive(initialVNode)) {
  5493. instance.ctx.renderer = internals;
  5494. }
  5495. // resolve props and slots for setup context
  5496. {
  5497. startMeasure(instance, `init`);
  5498. }
  5499. setupComponent(instance);
  5500. {
  5501. endMeasure(instance, `init`);
  5502. }
  5503. // setup() is async. This component relies on async logic to be resolved
  5504. // before proceeding
  5505. if ( instance.asyncDep) {
  5506. parentSuspense && parentSuspense.registerDep(instance, setupRenderEffect);
  5507. // Give it a placeholder if this is not hydration
  5508. // TODO handle self-defined fallback
  5509. if (!initialVNode.el) {
  5510. const placeholder = (instance.subTree = createVNode(Comment));
  5511. processCommentNode(null, placeholder, container, anchor);
  5512. }
  5513. return;
  5514. }
  5515. setupRenderEffect(instance, initialVNode, container, anchor, parentSuspense, isSVG, optimized);
  5516. {
  5517. popWarningContext();
  5518. endMeasure(instance, `mount`);
  5519. }
  5520. };
  5521. const updateComponent = (n1, n2, optimized) => {
  5522. const instance = (n2.component = n1.component);
  5523. if (shouldUpdateComponent(n1, n2, optimized)) {
  5524. if (
  5525. instance.asyncDep &&
  5526. !instance.asyncResolved) {
  5527. // async & still pending - just update props and slots
  5528. // since the component's reactive effect for render isn't set-up yet
  5529. {
  5530. pushWarningContext(n2);
  5531. }
  5532. updateComponentPreRender(instance, n2, optimized);
  5533. {
  5534. popWarningContext();
  5535. }
  5536. return;
  5537. }
  5538. else {
  5539. // normal update
  5540. instance.next = n2;
  5541. // in case the child component is also queued, remove it to avoid
  5542. // double updating the same child component in the same flush.
  5543. invalidateJob(instance.update);
  5544. // instance.update is the reactive effect runner.
  5545. instance.update();
  5546. }
  5547. }
  5548. else {
  5549. // no update needed. just copy over properties
  5550. n2.component = n1.component;
  5551. n2.el = n1.el;
  5552. instance.vnode = n2;
  5553. }
  5554. };
  5555. const setupRenderEffect = (instance, initialVNode, container, anchor, parentSuspense, isSVG, optimized) => {
  5556. // create reactive effect for rendering
  5557. instance.update = effect(function componentEffect() {
  5558. if (!instance.isMounted) {
  5559. let vnodeHook;
  5560. const { el, props } = initialVNode;
  5561. const { bm, m, parent } = instance;
  5562. // beforeMount hook
  5563. if (bm) {
  5564. invokeArrayFns(bm);
  5565. }
  5566. // onVnodeBeforeMount
  5567. if ((vnodeHook = props && props.onVnodeBeforeMount)) {
  5568. invokeVNodeHook(vnodeHook, parent, initialVNode);
  5569. }
  5570. // render
  5571. {
  5572. startMeasure(instance, `render`);
  5573. }
  5574. const subTree = (instance.subTree = renderComponentRoot(instance));
  5575. {
  5576. endMeasure(instance, `render`);
  5577. }
  5578. if (el && hydrateNode) {
  5579. {
  5580. startMeasure(instance, `hydrate`);
  5581. }
  5582. // vnode has adopted host node - perform hydration instead of mount.
  5583. hydrateNode(initialVNode.el, subTree, instance, parentSuspense);
  5584. {
  5585. endMeasure(instance, `hydrate`);
  5586. }
  5587. }
  5588. else {
  5589. {
  5590. startMeasure(instance, `patch`);
  5591. }
  5592. patch(null, subTree, container, anchor, instance, parentSuspense, isSVG);
  5593. {
  5594. endMeasure(instance, `patch`);
  5595. }
  5596. initialVNode.el = subTree.el;
  5597. }
  5598. // mounted hook
  5599. if (m) {
  5600. queuePostRenderEffect(m, parentSuspense);
  5601. }
  5602. // onVnodeMounted
  5603. if ((vnodeHook = props && props.onVnodeMounted)) {
  5604. queuePostRenderEffect(() => {
  5605. invokeVNodeHook(vnodeHook, parent, initialVNode);
  5606. }, parentSuspense);
  5607. }
  5608. // activated hook for keep-alive roots.
  5609. // #1742 activated hook must be accessed after first render
  5610. // since the hook may be injected by a child keep-alive
  5611. const { a } = instance;
  5612. if (a &&
  5613. initialVNode.shapeFlag & 256 /* COMPONENT_SHOULD_KEEP_ALIVE */) {
  5614. queuePostRenderEffect(a, parentSuspense);
  5615. }
  5616. instance.isMounted = true;
  5617. }
  5618. else {
  5619. // updateComponent
  5620. // This is triggered by mutation of component's own state (next: null)
  5621. // OR parent calling processComponent (next: VNode)
  5622. let { next, bu, u, parent, vnode } = instance;
  5623. let originNext = next;
  5624. let vnodeHook;
  5625. {
  5626. pushWarningContext(next || instance.vnode);
  5627. }
  5628. if (next) {
  5629. updateComponentPreRender(instance, next, optimized);
  5630. }
  5631. else {
  5632. next = vnode;
  5633. }
  5634. next.el = vnode.el;
  5635. // beforeUpdate hook
  5636. if (bu) {
  5637. invokeArrayFns(bu);
  5638. }
  5639. // onVnodeBeforeUpdate
  5640. if ((vnodeHook = next.props && next.props.onVnodeBeforeUpdate)) {
  5641. invokeVNodeHook(vnodeHook, parent, next, vnode);
  5642. }
  5643. // render
  5644. {
  5645. startMeasure(instance, `render`);
  5646. }
  5647. const nextTree = renderComponentRoot(instance);
  5648. {
  5649. endMeasure(instance, `render`);
  5650. }
  5651. const prevTree = instance.subTree;
  5652. instance.subTree = nextTree;
  5653. // reset refs
  5654. // only needed if previous patch had refs
  5655. if (instance.refs !== EMPTY_OBJ) {
  5656. instance.refs = {};
  5657. }
  5658. {
  5659. startMeasure(instance, `patch`);
  5660. }
  5661. patch(prevTree, nextTree,
  5662. // parent may have changed if it's in a teleport
  5663. hostParentNode(prevTree.el),
  5664. // anchor may have changed if it's in a fragment
  5665. getNextHostNode(prevTree), instance, parentSuspense, isSVG);
  5666. {
  5667. endMeasure(instance, `patch`);
  5668. }
  5669. next.el = nextTree.el;
  5670. if (originNext === null) {
  5671. // self-triggered update. In case of HOC, update parent component
  5672. // vnode el. HOC is indicated by parent instance's subTree pointing
  5673. // to child component's vnode
  5674. updateHOCHostEl(instance, nextTree.el);
  5675. }
  5676. // updated hook
  5677. if (u) {
  5678. queuePostRenderEffect(u, parentSuspense);
  5679. }
  5680. // onVnodeUpdated
  5681. if ((vnodeHook = next.props && next.props.onVnodeUpdated)) {
  5682. queuePostRenderEffect(() => {
  5683. invokeVNodeHook(vnodeHook, parent, next, vnode);
  5684. }, parentSuspense);
  5685. }
  5686. {
  5687. devtoolsComponentUpdated(instance);
  5688. }
  5689. {
  5690. popWarningContext();
  5691. }
  5692. }
  5693. }, createDevEffectOptions(instance) );
  5694. };
  5695. const updateComponentPreRender = (instance, nextVNode, optimized) => {
  5696. nextVNode.component = instance;
  5697. const prevProps = instance.vnode.props;
  5698. instance.vnode = nextVNode;
  5699. instance.next = null;
  5700. updateProps(instance, nextVNode.props, prevProps, optimized);
  5701. updateSlots(instance, nextVNode.children);
  5702. // props update may have triggered pre-flush watchers.
  5703. // flush them before the render update.
  5704. flushPreFlushCbs(undefined, instance.update);
  5705. };
  5706. const patchChildren = (n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, optimized = false) => {
  5707. const c1 = n1 && n1.children;
  5708. const prevShapeFlag = n1 ? n1.shapeFlag : 0;
  5709. const c2 = n2.children;
  5710. const { patchFlag, shapeFlag } = n2;
  5711. // fast path
  5712. if (patchFlag > 0) {
  5713. if (patchFlag & 128 /* KEYED_FRAGMENT */) {
  5714. // this could be either fully-keyed or mixed (some keyed some not)
  5715. // presence of patchFlag means children are guaranteed to be arrays
  5716. patchKeyedChildren(c1, c2, container, anchor, parentComponent, parentSuspense, isSVG, optimized);
  5717. return;
  5718. }
  5719. else if (patchFlag & 256 /* UNKEYED_FRAGMENT */) {
  5720. // unkeyed
  5721. patchUnkeyedChildren(c1, c2, container, anchor, parentComponent, parentSuspense, isSVG, optimized);
  5722. return;
  5723. }
  5724. }
  5725. // children has 3 possibilities: text, array or no children.
  5726. if (shapeFlag & 8 /* TEXT_CHILDREN */) {
  5727. // text children fast path
  5728. if (prevShapeFlag & 16 /* ARRAY_CHILDREN */) {
  5729. unmountChildren(c1, parentComponent, parentSuspense);
  5730. }
  5731. if (c2 !== c1) {
  5732. hostSetElementText(container, c2);
  5733. }
  5734. }
  5735. else {
  5736. if (prevShapeFlag & 16 /* ARRAY_CHILDREN */) {
  5737. // prev children was array
  5738. if (shapeFlag & 16 /* ARRAY_CHILDREN */) {
  5739. // two arrays, cannot assume anything, do full diff
  5740. patchKeyedChildren(c1, c2, container, anchor, parentComponent, parentSuspense, isSVG, optimized);
  5741. }
  5742. else {
  5743. // no new children, just unmount old
  5744. unmountChildren(c1, parentComponent, parentSuspense, true);
  5745. }
  5746. }
  5747. else {
  5748. // prev children was text OR null
  5749. // new children is array OR null
  5750. if (prevShapeFlag & 8 /* TEXT_CHILDREN */) {
  5751. hostSetElementText(container, '');
  5752. }
  5753. // mount new if array
  5754. if (shapeFlag & 16 /* ARRAY_CHILDREN */) {
  5755. mountChildren(c2, container, anchor, parentComponent, parentSuspense, isSVG, optimized);
  5756. }
  5757. }
  5758. }
  5759. };
  5760. const patchUnkeyedChildren = (c1, c2, container, anchor, parentComponent, parentSuspense, isSVG, optimized) => {
  5761. c1 = c1 || EMPTY_ARR;
  5762. c2 = c2 || EMPTY_ARR;
  5763. const oldLength = c1.length;
  5764. const newLength = c2.length;
  5765. const commonLength = Math.min(oldLength, newLength);
  5766. let i;
  5767. for (i = 0; i < commonLength; i++) {
  5768. const nextChild = (c2[i] = optimized
  5769. ? cloneIfMounted(c2[i])
  5770. : normalizeVNode(c2[i]));
  5771. patch(c1[i], nextChild, container, null, parentComponent, parentSuspense, isSVG, optimized);
  5772. }
  5773. if (oldLength > newLength) {
  5774. // remove old
  5775. unmountChildren(c1, parentComponent, parentSuspense, true, commonLength);
  5776. }
  5777. else {
  5778. // mount new
  5779. mountChildren(c2, container, anchor, parentComponent, parentSuspense, isSVG, optimized, commonLength);
  5780. }
  5781. };
  5782. // can be all-keyed or mixed
  5783. const patchKeyedChildren = (c1, c2, container, parentAnchor, parentComponent, parentSuspense, isSVG, optimized) => {
  5784. let i = 0;
  5785. const l2 = c2.length;
  5786. let e1 = c1.length - 1; // prev ending index
  5787. let e2 = l2 - 1; // next ending index
  5788. // 1. sync from start
  5789. // (a b) c
  5790. // (a b) d e
  5791. while (i <= e1 && i <= e2) {
  5792. const n1 = c1[i];
  5793. const n2 = (c2[i] = optimized
  5794. ? cloneIfMounted(c2[i])
  5795. : normalizeVNode(c2[i]));
  5796. if (isSameVNodeType(n1, n2)) {
  5797. patch(n1, n2, container, null, parentComponent, parentSuspense, isSVG, optimized);
  5798. }
  5799. else {
  5800. break;
  5801. }
  5802. i++;
  5803. }
  5804. // 2. sync from end
  5805. // a (b c)
  5806. // d e (b c)
  5807. while (i <= e1 && i <= e2) {
  5808. const n1 = c1[e1];
  5809. const n2 = (c2[e2] = optimized
  5810. ? cloneIfMounted(c2[e2])
  5811. : normalizeVNode(c2[e2]));
  5812. if (isSameVNodeType(n1, n2)) {
  5813. patch(n1, n2, container, null, parentComponent, parentSuspense, isSVG, optimized);
  5814. }
  5815. else {
  5816. break;
  5817. }
  5818. e1--;
  5819. e2--;
  5820. }
  5821. // 3. common sequence + mount
  5822. // (a b)
  5823. // (a b) c
  5824. // i = 2, e1 = 1, e2 = 2
  5825. // (a b)
  5826. // c (a b)
  5827. // i = 0, e1 = -1, e2 = 0
  5828. if (i > e1) {
  5829. if (i <= e2) {
  5830. const nextPos = e2 + 1;
  5831. const anchor = nextPos < l2 ? c2[nextPos].el : parentAnchor;
  5832. while (i <= e2) {
  5833. patch(null, (c2[i] = optimized
  5834. ? cloneIfMounted(c2[i])
  5835. : normalizeVNode(c2[i])), container, anchor, parentComponent, parentSuspense, isSVG);
  5836. i++;
  5837. }
  5838. }
  5839. }
  5840. // 4. common sequence + unmount
  5841. // (a b) c
  5842. // (a b)
  5843. // i = 2, e1 = 2, e2 = 1
  5844. // a (b c)
  5845. // (b c)
  5846. // i = 0, e1 = 0, e2 = -1
  5847. else if (i > e2) {
  5848. while (i <= e1) {
  5849. unmount(c1[i], parentComponent, parentSuspense, true);
  5850. i++;
  5851. }
  5852. }
  5853. // 5. unknown sequence
  5854. // [i ... e1 + 1]: a b [c d e] f g
  5855. // [i ... e2 + 1]: a b [e d c h] f g
  5856. // i = 2, e1 = 4, e2 = 5
  5857. else {
  5858. const s1 = i; // prev starting index
  5859. const s2 = i; // next starting index
  5860. // 5.1 build key:index map for newChildren
  5861. const keyToNewIndexMap = new Map();
  5862. for (i = s2; i <= e2; i++) {
  5863. const nextChild = (c2[i] = optimized
  5864. ? cloneIfMounted(c2[i])
  5865. : normalizeVNode(c2[i]));
  5866. if (nextChild.key != null) {
  5867. if ( keyToNewIndexMap.has(nextChild.key)) {
  5868. warn(`Duplicate keys found during update:`, JSON.stringify(nextChild.key), `Make sure keys are unique.`);
  5869. }
  5870. keyToNewIndexMap.set(nextChild.key, i);
  5871. }
  5872. }
  5873. // 5.2 loop through old children left to be patched and try to patch
  5874. // matching nodes & remove nodes that are no longer present
  5875. let j;
  5876. let patched = 0;
  5877. const toBePatched = e2 - s2 + 1;
  5878. let moved = false;
  5879. // used to track whether any node has moved
  5880. let maxNewIndexSoFar = 0;
  5881. // works as Map<newIndex, oldIndex>
  5882. // Note that oldIndex is offset by +1
  5883. // and oldIndex = 0 is a special value indicating the new node has
  5884. // no corresponding old node.
  5885. // used for determining longest stable subsequence
  5886. const newIndexToOldIndexMap = new Array(toBePatched);
  5887. for (i = 0; i < toBePatched; i++)
  5888. newIndexToOldIndexMap[i] = 0;
  5889. for (i = s1; i <= e1; i++) {
  5890. const prevChild = c1[i];
  5891. if (patched >= toBePatched) {
  5892. // all new children have been patched so this can only be a removal
  5893. unmount(prevChild, parentComponent, parentSuspense, true);
  5894. continue;
  5895. }
  5896. let newIndex;
  5897. if (prevChild.key != null) {
  5898. newIndex = keyToNewIndexMap.get(prevChild.key);
  5899. }
  5900. else {
  5901. // key-less node, try to locate a key-less node of the same type
  5902. for (j = s2; j <= e2; j++) {
  5903. if (newIndexToOldIndexMap[j - s2] === 0 &&
  5904. isSameVNodeType(prevChild, c2[j])) {
  5905. newIndex = j;
  5906. break;
  5907. }
  5908. }
  5909. }
  5910. if (newIndex === undefined) {
  5911. unmount(prevChild, parentComponent, parentSuspense, true);
  5912. }
  5913. else {
  5914. newIndexToOldIndexMap[newIndex - s2] = i + 1;
  5915. if (newIndex >= maxNewIndexSoFar) {
  5916. maxNewIndexSoFar = newIndex;
  5917. }
  5918. else {
  5919. moved = true;
  5920. }
  5921. patch(prevChild, c2[newIndex], container, null, parentComponent, parentSuspense, isSVG, optimized);
  5922. patched++;
  5923. }
  5924. }
  5925. // 5.3 move and mount
  5926. // generate longest stable subsequence only when nodes have moved
  5927. const increasingNewIndexSequence = moved
  5928. ? getSequence(newIndexToOldIndexMap)
  5929. : EMPTY_ARR;
  5930. j = increasingNewIndexSequence.length - 1;
  5931. // looping backwards so that we can use last patched node as anchor
  5932. for (i = toBePatched - 1; i >= 0; i--) {
  5933. const nextIndex = s2 + i;
  5934. const nextChild = c2[nextIndex];
  5935. const anchor = nextIndex + 1 < l2 ? c2[nextIndex + 1].el : parentAnchor;
  5936. if (newIndexToOldIndexMap[i] === 0) {
  5937. // mount new
  5938. patch(null, nextChild, container, anchor, parentComponent, parentSuspense, isSVG);
  5939. }
  5940. else if (moved) {
  5941. // move if:
  5942. // There is no stable subsequence (e.g. a reverse)
  5943. // OR current node is not among the stable sequence
  5944. if (j < 0 || i !== increasingNewIndexSequence[j]) {
  5945. move(nextChild, container, anchor, 2 /* REORDER */);
  5946. }
  5947. else {
  5948. j--;
  5949. }
  5950. }
  5951. }
  5952. }
  5953. };
  5954. const move = (vnode, container, anchor, moveType, parentSuspense = null) => {
  5955. const { el, type, transition, children, shapeFlag } = vnode;
  5956. if (shapeFlag & 6 /* COMPONENT */) {
  5957. move(vnode.component.subTree, container, anchor, moveType);
  5958. return;
  5959. }
  5960. if ( shapeFlag & 128 /* SUSPENSE */) {
  5961. vnode.suspense.move(container, anchor, moveType);
  5962. return;
  5963. }
  5964. if (shapeFlag & 64 /* TELEPORT */) {
  5965. type.move(vnode, container, anchor, internals);
  5966. return;
  5967. }
  5968. if (type === Fragment) {
  5969. hostInsert(el, container, anchor);
  5970. for (let i = 0; i < children.length; i++) {
  5971. move(children[i], container, anchor, moveType);
  5972. }
  5973. hostInsert(vnode.anchor, container, anchor);
  5974. return;
  5975. }
  5976. // static node move can only happen when force updating HMR
  5977. if ( type === Static) {
  5978. moveStaticNode(vnode, container, anchor);
  5979. return;
  5980. }
  5981. // single nodes
  5982. const needTransition = moveType !== 2 /* REORDER */ &&
  5983. shapeFlag & 1 /* ELEMENT */ &&
  5984. transition;
  5985. if (needTransition) {
  5986. if (moveType === 0 /* ENTER */) {
  5987. transition.beforeEnter(el);
  5988. hostInsert(el, container, anchor);
  5989. queuePostRenderEffect(() => transition.enter(el), parentSuspense);
  5990. }
  5991. else {
  5992. const { leave, delayLeave, afterLeave } = transition;
  5993. const remove = () => hostInsert(el, container, anchor);
  5994. const performLeave = () => {
  5995. leave(el, () => {
  5996. remove();
  5997. afterLeave && afterLeave();
  5998. });
  5999. };
  6000. if (delayLeave) {
  6001. delayLeave(el, remove, performLeave);
  6002. }
  6003. else {
  6004. performLeave();
  6005. }
  6006. }
  6007. }
  6008. else {
  6009. hostInsert(el, container, anchor);
  6010. }
  6011. };
  6012. const unmount = (vnode, parentComponent, parentSuspense, doRemove = false) => {
  6013. const { type, props, ref, children, dynamicChildren, shapeFlag, patchFlag, dirs } = vnode;
  6014. // unset ref
  6015. if (ref != null && parentComponent) {
  6016. setRef(ref, null, parentComponent, parentSuspense, null);
  6017. }
  6018. if (shapeFlag & 256 /* COMPONENT_SHOULD_KEEP_ALIVE */) {
  6019. parentComponent.ctx.deactivate(vnode);
  6020. return;
  6021. }
  6022. const shouldInvokeDirs = shapeFlag & 1 /* ELEMENT */ && dirs;
  6023. let vnodeHook;
  6024. if ((vnodeHook = props && props.onVnodeBeforeUnmount)) {
  6025. invokeVNodeHook(vnodeHook, parentComponent, vnode);
  6026. }
  6027. if (shapeFlag & 6 /* COMPONENT */) {
  6028. unmountComponent(vnode.component, parentSuspense, doRemove);
  6029. }
  6030. else {
  6031. if ( shapeFlag & 128 /* SUSPENSE */) {
  6032. vnode.suspense.unmount(parentSuspense, doRemove);
  6033. return;
  6034. }
  6035. if (shouldInvokeDirs) {
  6036. invokeDirectiveHook(vnode, null, parentComponent, 'beforeUnmount');
  6037. }
  6038. if (dynamicChildren &&
  6039. // #1153: fast path should not be taken for non-stable (v-for) fragments
  6040. (type !== Fragment ||
  6041. (patchFlag > 0 && patchFlag & 64 /* STABLE_FRAGMENT */))) {
  6042. // fast path for block nodes: only need to unmount dynamic children.
  6043. unmountChildren(dynamicChildren, parentComponent, parentSuspense);
  6044. }
  6045. else if (shapeFlag & 16 /* ARRAY_CHILDREN */) {
  6046. unmountChildren(children, parentComponent, parentSuspense);
  6047. }
  6048. // an unmounted teleport should always remove its children
  6049. if (shapeFlag & 64 /* TELEPORT */) {
  6050. vnode.type.remove(vnode, internals);
  6051. }
  6052. if (doRemove) {
  6053. remove(vnode);
  6054. }
  6055. }
  6056. if ((vnodeHook = props && props.onVnodeUnmounted) || shouldInvokeDirs) {
  6057. queuePostRenderEffect(() => {
  6058. vnodeHook && invokeVNodeHook(vnodeHook, parentComponent, vnode);
  6059. shouldInvokeDirs &&
  6060. invokeDirectiveHook(vnode, null, parentComponent, 'unmounted');
  6061. }, parentSuspense);
  6062. }
  6063. };
  6064. const remove = vnode => {
  6065. const { type, el, anchor, transition } = vnode;
  6066. if (type === Fragment) {
  6067. removeFragment(el, anchor);
  6068. return;
  6069. }
  6070. if ( type === Static) {
  6071. removeStaticNode(vnode);
  6072. return;
  6073. }
  6074. const performRemove = () => {
  6075. hostRemove(el);
  6076. if (transition && !transition.persisted && transition.afterLeave) {
  6077. transition.afterLeave();
  6078. }
  6079. };
  6080. if (vnode.shapeFlag & 1 /* ELEMENT */ &&
  6081. transition &&
  6082. !transition.persisted) {
  6083. const { leave, delayLeave } = transition;
  6084. const performLeave = () => leave(el, performRemove);
  6085. if (delayLeave) {
  6086. delayLeave(vnode.el, performRemove, performLeave);
  6087. }
  6088. else {
  6089. performLeave();
  6090. }
  6091. }
  6092. else {
  6093. performRemove();
  6094. }
  6095. };
  6096. const removeFragment = (cur, end) => {
  6097. // For fragments, directly remove all contained DOM nodes.
  6098. // (fragment child nodes cannot have transition)
  6099. let next;
  6100. while (cur !== end) {
  6101. next = hostNextSibling(cur);
  6102. hostRemove(cur);
  6103. cur = next;
  6104. }
  6105. hostRemove(end);
  6106. };
  6107. const unmountComponent = (instance, parentSuspense, doRemove) => {
  6108. if ( instance.type.__hmrId) {
  6109. unregisterHMR(instance);
  6110. }
  6111. const { bum, effects, update, subTree, um } = instance;
  6112. // beforeUnmount hook
  6113. if (bum) {
  6114. invokeArrayFns(bum);
  6115. }
  6116. if (effects) {
  6117. for (let i = 0; i < effects.length; i++) {
  6118. stop(effects[i]);
  6119. }
  6120. }
  6121. // update may be null if a component is unmounted before its async
  6122. // setup has resolved.
  6123. if (update) {
  6124. stop(update);
  6125. unmount(subTree, instance, parentSuspense, doRemove);
  6126. }
  6127. // unmounted hook
  6128. if (um) {
  6129. queuePostRenderEffect(um, parentSuspense);
  6130. }
  6131. queuePostRenderEffect(() => {
  6132. instance.isUnmounted = true;
  6133. }, parentSuspense);
  6134. // A component with async dep inside a pending suspense is unmounted before
  6135. // its async dep resolves. This should remove the dep from the suspense, and
  6136. // cause the suspense to resolve immediately if that was the last dep.
  6137. if (
  6138. parentSuspense &&
  6139. parentSuspense.pendingBranch &&
  6140. !parentSuspense.isUnmounted &&
  6141. instance.asyncDep &&
  6142. !instance.asyncResolved &&
  6143. instance.suspenseId === parentSuspense.pendingId) {
  6144. parentSuspense.deps--;
  6145. if (parentSuspense.deps === 0) {
  6146. parentSuspense.resolve();
  6147. }
  6148. }
  6149. {
  6150. devtoolsComponentRemoved(instance);
  6151. }
  6152. };
  6153. const unmountChildren = (children, parentComponent, parentSuspense, doRemove = false, start = 0) => {
  6154. for (let i = start; i < children.length; i++) {
  6155. unmount(children[i], parentComponent, parentSuspense, doRemove);
  6156. }
  6157. };
  6158. const getNextHostNode = vnode => {
  6159. if (vnode.shapeFlag & 6 /* COMPONENT */) {
  6160. return getNextHostNode(vnode.component.subTree);
  6161. }
  6162. if ( vnode.shapeFlag & 128 /* SUSPENSE */) {
  6163. return vnode.suspense.next();
  6164. }
  6165. return hostNextSibling((vnode.anchor || vnode.el));
  6166. };
  6167. /**
  6168. * #1156
  6169. * When a component is HMR-enabled, we need to make sure that all static nodes
  6170. * inside a block also inherit the DOM element from the previous tree so that
  6171. * HMR updates (which are full updates) can retrieve the element for patching.
  6172. *
  6173. * #2080
  6174. * Inside keyed `template` fragment static children, if a fragment is moved,
  6175. * the children will always moved so that need inherit el form previous nodes
  6176. * to ensure correct moved position.
  6177. */
  6178. const traverseStaticChildren = (n1, n2, shallow = false) => {
  6179. const ch1 = n1.children;
  6180. const ch2 = n2.children;
  6181. if (isArray(ch1) && isArray(ch2)) {
  6182. for (let i = 0; i < ch1.length; i++) {
  6183. // this is only called in the optimized path so array children are
  6184. // guaranteed to be vnodes
  6185. const c1 = ch1[i];
  6186. const c2 = (ch2[i] = cloneIfMounted(ch2[i]));
  6187. if (c2.shapeFlag & 1 /* ELEMENT */ && !c2.dynamicChildren) {
  6188. if (c2.patchFlag <= 0 || c2.patchFlag === 32 /* HYDRATE_EVENTS */) {
  6189. c2.el = c1.el;
  6190. }
  6191. if (!shallow)
  6192. traverseStaticChildren(c1, c2);
  6193. }
  6194. if ( c2.type === Comment) {
  6195. c2.el = c1.el;
  6196. }
  6197. }
  6198. }
  6199. };
  6200. const render = (vnode, container) => {
  6201. if (vnode == null) {
  6202. if (container._vnode) {
  6203. unmount(container._vnode, null, null, true);
  6204. }
  6205. }
  6206. else {
  6207. patch(container._vnode || null, vnode, container);
  6208. }
  6209. flushPostFlushCbs();
  6210. container._vnode = vnode;
  6211. };
  6212. const internals = {
  6213. p: patch,
  6214. um: unmount,
  6215. m: move,
  6216. r: remove,
  6217. mt: mountComponent,
  6218. mc: mountChildren,
  6219. pc: patchChildren,
  6220. pbc: patchBlockChildren,
  6221. n: getNextHostNode,
  6222. o: options
  6223. };
  6224. let hydrate;
  6225. let hydrateNode;
  6226. if (createHydrationFns) {
  6227. [hydrate, hydrateNode] = createHydrationFns(internals);
  6228. }
  6229. return {
  6230. render,
  6231. hydrate,
  6232. createApp: createAppAPI(render, hydrate)
  6233. };
  6234. }
  6235. function invokeVNodeHook(hook, instance, vnode, prevVNode = null) {
  6236. callWithAsyncErrorHandling(hook, instance, 7 /* VNODE_HOOK */, [
  6237. vnode,
  6238. prevVNode
  6239. ]);
  6240. }
  6241. // https://en.wikipedia.org/wiki/Longest_increasing_subsequence
  6242. function getSequence(arr) {
  6243. const p = arr.slice();
  6244. const result = [0];
  6245. let i, j, u, v, c;
  6246. const len = arr.length;
  6247. for (i = 0; i < len; i++) {
  6248. const arrI = arr[i];
  6249. if (arrI !== 0) {
  6250. j = result[result.length - 1];
  6251. if (arr[j] < arrI) {
  6252. p[i] = j;
  6253. result.push(i);
  6254. continue;
  6255. }
  6256. u = 0;
  6257. v = result.length - 1;
  6258. while (u < v) {
  6259. c = ((u + v) / 2) | 0;
  6260. if (arr[result[c]] < arrI) {
  6261. u = c + 1;
  6262. }
  6263. else {
  6264. v = c;
  6265. }
  6266. }
  6267. if (arrI < arr[result[u]]) {
  6268. if (u > 0) {
  6269. p[i] = result[u - 1];
  6270. }
  6271. result[u] = i;
  6272. }
  6273. }
  6274. }
  6275. u = result.length;
  6276. v = result[u - 1];
  6277. while (u-- > 0) {
  6278. result[u] = v;
  6279. v = p[v];
  6280. }
  6281. return result;
  6282. }
  6283. // Simple effect.
  6284. function watchEffect(effect, options) {
  6285. return doWatch(effect, null, options);
  6286. }
  6287. // initial value for watchers to trigger on undefined initial values
  6288. const INITIAL_WATCHER_VALUE = {};
  6289. // implementation
  6290. function watch(source, cb, options) {
  6291. if ( !isFunction(cb)) {
  6292. warn(`\`watch(fn, options?)\` signature has been moved to a separate API. ` +
  6293. `Use \`watchEffect(fn, options?)\` instead. \`watch\` now only ` +
  6294. `supports \`watch(source, cb, options?) signature.`);
  6295. }
  6296. return doWatch(source, cb, options);
  6297. }
  6298. function doWatch(source, cb, { immediate, deep, flush, onTrack, onTrigger } = EMPTY_OBJ, instance = currentInstance) {
  6299. if ( !cb) {
  6300. if (immediate !== undefined) {
  6301. warn(`watch() "immediate" option is only respected when using the ` +
  6302. `watch(source, callback, options?) signature.`);
  6303. }
  6304. if (deep !== undefined) {
  6305. warn(`watch() "deep" option is only respected when using the ` +
  6306. `watch(source, callback, options?) signature.`);
  6307. }
  6308. }
  6309. const warnInvalidSource = (s) => {
  6310. warn(`Invalid watch source: `, s, `A watch source can only be a getter/effect function, a ref, ` +
  6311. `a reactive object, or an array of these types.`);
  6312. };
  6313. let getter;
  6314. const isRefSource = isRef(source);
  6315. if (isRefSource) {
  6316. getter = () => source.value;
  6317. }
  6318. else if (isReactive(source)) {
  6319. getter = () => source;
  6320. deep = true;
  6321. }
  6322. else if (isArray(source)) {
  6323. getter = () => source.map(s => {
  6324. if (isRef(s)) {
  6325. return s.value;
  6326. }
  6327. else if (isReactive(s)) {
  6328. return traverse(s);
  6329. }
  6330. else if (isFunction(s)) {
  6331. return callWithErrorHandling(s, instance, 2 /* WATCH_GETTER */);
  6332. }
  6333. else {
  6334. warnInvalidSource(s);
  6335. }
  6336. });
  6337. }
  6338. else if (isFunction(source)) {
  6339. if (cb) {
  6340. // getter with cb
  6341. getter = () => callWithErrorHandling(source, instance, 2 /* WATCH_GETTER */);
  6342. }
  6343. else {
  6344. // no cb -> simple effect
  6345. getter = () => {
  6346. if (instance && instance.isUnmounted) {
  6347. return;
  6348. }
  6349. if (cleanup) {
  6350. cleanup();
  6351. }
  6352. return callWithErrorHandling(source, instance, 3 /* WATCH_CALLBACK */, [onInvalidate]);
  6353. };
  6354. }
  6355. }
  6356. else {
  6357. getter = NOOP;
  6358. warnInvalidSource(source);
  6359. }
  6360. if (cb && deep) {
  6361. const baseGetter = getter;
  6362. getter = () => traverse(baseGetter());
  6363. }
  6364. let cleanup;
  6365. const onInvalidate = (fn) => {
  6366. cleanup = runner.options.onStop = () => {
  6367. callWithErrorHandling(fn, instance, 4 /* WATCH_CLEANUP */);
  6368. };
  6369. };
  6370. let oldValue = isArray(source) ? [] : INITIAL_WATCHER_VALUE;
  6371. const job = () => {
  6372. if (!runner.active) {
  6373. return;
  6374. }
  6375. if (cb) {
  6376. // watch(source, cb)
  6377. const newValue = runner();
  6378. if (deep || isRefSource || hasChanged(newValue, oldValue)) {
  6379. // cleanup before running cb again
  6380. if (cleanup) {
  6381. cleanup();
  6382. }
  6383. callWithAsyncErrorHandling(cb, instance, 3 /* WATCH_CALLBACK */, [
  6384. newValue,
  6385. // pass undefined as the old value when it's changed for the first time
  6386. oldValue === INITIAL_WATCHER_VALUE ? undefined : oldValue,
  6387. onInvalidate
  6388. ]);
  6389. oldValue = newValue;
  6390. }
  6391. }
  6392. else {
  6393. // watchEffect
  6394. runner();
  6395. }
  6396. };
  6397. // important: mark the job as a watcher callback so that scheduler knows it
  6398. // it is allowed to self-trigger (#1727)
  6399. job.allowRecurse = !!cb;
  6400. let scheduler;
  6401. if (flush === 'sync') {
  6402. scheduler = job;
  6403. }
  6404. else if (flush === 'post') {
  6405. scheduler = () => queuePostRenderEffect(job, instance && instance.suspense);
  6406. }
  6407. else {
  6408. // default: 'pre'
  6409. scheduler = () => {
  6410. if (!instance || instance.isMounted) {
  6411. queuePreFlushCb(job);
  6412. }
  6413. else {
  6414. // with 'pre' option, the first call must happen before
  6415. // the component is mounted so it is called synchronously.
  6416. job();
  6417. }
  6418. };
  6419. }
  6420. const runner = effect(getter, {
  6421. lazy: true,
  6422. onTrack,
  6423. onTrigger,
  6424. scheduler
  6425. });
  6426. recordInstanceBoundEffect(runner);
  6427. // initial run
  6428. if (cb) {
  6429. if (immediate) {
  6430. job();
  6431. }
  6432. else {
  6433. oldValue = runner();
  6434. }
  6435. }
  6436. else if (flush === 'post') {
  6437. queuePostRenderEffect(runner, instance && instance.suspense);
  6438. }
  6439. else {
  6440. runner();
  6441. }
  6442. return () => {
  6443. stop(runner);
  6444. if (instance) {
  6445. remove(instance.effects, runner);
  6446. }
  6447. };
  6448. }
  6449. // this.$watch
  6450. function instanceWatch(source, cb, options) {
  6451. const publicThis = this.proxy;
  6452. const getter = isString(source)
  6453. ? () => publicThis[source]
  6454. : source.bind(publicThis);
  6455. return doWatch(getter, cb.bind(publicThis), options, this);
  6456. }
  6457. function traverse(value, seen = new Set()) {
  6458. if (!isObject(value) || seen.has(value)) {
  6459. return value;
  6460. }
  6461. seen.add(value);
  6462. if (isRef(value)) {
  6463. traverse(value.value, seen);
  6464. }
  6465. else if (isArray(value)) {
  6466. for (let i = 0; i < value.length; i++) {
  6467. traverse(value[i], seen);
  6468. }
  6469. }
  6470. else if (isMap(value)) {
  6471. value.forEach((_, key) => {
  6472. // to register mutation dep for existing keys
  6473. traverse(value.get(key), seen);
  6474. });
  6475. }
  6476. else if (isSet(value)) {
  6477. value.forEach(v => {
  6478. traverse(v, seen);
  6479. });
  6480. }
  6481. else {
  6482. for (const key in value) {
  6483. traverse(value[key], seen);
  6484. }
  6485. }
  6486. return value;
  6487. }
  6488. function provide(key, value) {
  6489. if (!currentInstance) {
  6490. {
  6491. warn(`provide() can only be used inside setup().`);
  6492. }
  6493. }
  6494. else {
  6495. let provides = currentInstance.provides;
  6496. // by default an instance inherits its parent's provides object
  6497. // but when it needs to provide values of its own, it creates its
  6498. // own provides object using parent provides object as prototype.
  6499. // this way in `inject` we can simply look up injections from direct
  6500. // parent and let the prototype chain do the work.
  6501. const parentProvides = currentInstance.parent && currentInstance.parent.provides;
  6502. if (parentProvides === provides) {
  6503. provides = currentInstance.provides = Object.create(parentProvides);
  6504. }
  6505. // TS doesn't allow symbol as index type
  6506. provides[key] = value;
  6507. }
  6508. }
  6509. function inject(key, defaultValue, treatDefaultAsFactory = false) {
  6510. // fallback to `currentRenderingInstance` so that this can be called in
  6511. // a functional component
  6512. const instance = currentInstance || currentRenderingInstance;
  6513. if (instance) {
  6514. const provides = instance.provides;
  6515. if (key in provides) {
  6516. // TS doesn't allow symbol as index type
  6517. return provides[key];
  6518. }
  6519. else if (arguments.length > 1) {
  6520. return treatDefaultAsFactory && isFunction(defaultValue)
  6521. ? defaultValue()
  6522. : defaultValue;
  6523. }
  6524. else {
  6525. warn(`injection "${String(key)}" not found.`);
  6526. }
  6527. }
  6528. else {
  6529. warn(`inject() can only be used inside setup() or functional components.`);
  6530. }
  6531. }
  6532. function createDuplicateChecker() {
  6533. const cache = Object.create(null);
  6534. return (type, key) => {
  6535. if (cache[key]) {
  6536. warn(`${type} property "${key}" is already defined in ${cache[key]}.`);
  6537. }
  6538. else {
  6539. cache[key] = type;
  6540. }
  6541. };
  6542. }
  6543. let isInBeforeCreate = false;
  6544. function applyOptions(instance, options, deferredData = [], deferredWatch = [], asMixin = false) {
  6545. const {
  6546. // composition
  6547. mixins, extends: extendsOptions,
  6548. // state
  6549. data: dataOptions, computed: computedOptions, methods, watch: watchOptions, provide: provideOptions, inject: injectOptions,
  6550. // assets
  6551. components, directives,
  6552. // lifecycle
  6553. beforeMount, mounted, beforeUpdate, updated, activated, deactivated, beforeDestroy, beforeUnmount, destroyed, unmounted, render, renderTracked, renderTriggered, errorCaptured } = options;
  6554. const publicThis = instance.proxy;
  6555. const ctx = instance.ctx;
  6556. const globalMixins = instance.appContext.mixins;
  6557. if (asMixin && render && instance.render === NOOP) {
  6558. instance.render = render;
  6559. }
  6560. // applyOptions is called non-as-mixin once per instance
  6561. if (!asMixin) {
  6562. isInBeforeCreate = true;
  6563. callSyncHook('beforeCreate', options, publicThis, globalMixins);
  6564. isInBeforeCreate = false;
  6565. // global mixins are applied first
  6566. applyMixins(instance, globalMixins, deferredData, deferredWatch);
  6567. }
  6568. // extending a base component...
  6569. if (extendsOptions) {
  6570. applyOptions(instance, extendsOptions, deferredData, deferredWatch, true);
  6571. }
  6572. // local mixins
  6573. if (mixins) {
  6574. applyMixins(instance, mixins, deferredData, deferredWatch);
  6575. }
  6576. const checkDuplicateProperties = createDuplicateChecker() ;
  6577. {
  6578. const [propsOptions] = instance.propsOptions;
  6579. if (propsOptions) {
  6580. for (const key in propsOptions) {
  6581. checkDuplicateProperties("Props" /* PROPS */, key);
  6582. }
  6583. }
  6584. }
  6585. // options initialization order (to be consistent with Vue 2):
  6586. // - props (already done outside of this function)
  6587. // - inject
  6588. // - methods
  6589. // - data (deferred since it relies on `this` access)
  6590. // - computed
  6591. // - watch (deferred since it relies on `this` access)
  6592. if (injectOptions) {
  6593. if (isArray(injectOptions)) {
  6594. for (let i = 0; i < injectOptions.length; i++) {
  6595. const key = injectOptions[i];
  6596. ctx[key] = inject(key);
  6597. {
  6598. checkDuplicateProperties("Inject" /* INJECT */, key);
  6599. }
  6600. }
  6601. }
  6602. else {
  6603. for (const key in injectOptions) {
  6604. const opt = injectOptions[key];
  6605. if (isObject(opt)) {
  6606. ctx[key] = inject(opt.from || key, opt.default, true /* treat default function as factory */);
  6607. }
  6608. else {
  6609. ctx[key] = inject(opt);
  6610. }
  6611. {
  6612. checkDuplicateProperties("Inject" /* INJECT */, key);
  6613. }
  6614. }
  6615. }
  6616. }
  6617. if (methods) {
  6618. for (const key in methods) {
  6619. const methodHandler = methods[key];
  6620. if (isFunction(methodHandler)) {
  6621. ctx[key] = methodHandler.bind(publicThis);
  6622. {
  6623. checkDuplicateProperties("Methods" /* METHODS */, key);
  6624. }
  6625. }
  6626. else {
  6627. warn(`Method "${key}" has type "${typeof methodHandler}" in the component definition. ` +
  6628. `Did you reference the function correctly?`);
  6629. }
  6630. }
  6631. }
  6632. if (!asMixin) {
  6633. if (deferredData.length) {
  6634. deferredData.forEach(dataFn => resolveData(instance, dataFn, publicThis));
  6635. }
  6636. if (dataOptions) {
  6637. resolveData(instance, dataOptions, publicThis);
  6638. }
  6639. {
  6640. const rawData = toRaw(instance.data);
  6641. for (const key in rawData) {
  6642. checkDuplicateProperties("Data" /* DATA */, key);
  6643. // expose data on ctx during dev
  6644. if (key[0] !== '$' && key[0] !== '_') {
  6645. Object.defineProperty(ctx, key, {
  6646. configurable: true,
  6647. enumerable: true,
  6648. get: () => rawData[key],
  6649. set: NOOP
  6650. });
  6651. }
  6652. }
  6653. }
  6654. }
  6655. else if (dataOptions) {
  6656. deferredData.push(dataOptions);
  6657. }
  6658. if (computedOptions) {
  6659. for (const key in computedOptions) {
  6660. const opt = computedOptions[key];
  6661. const get = isFunction(opt)
  6662. ? opt.bind(publicThis, publicThis)
  6663. : isFunction(opt.get)
  6664. ? opt.get.bind(publicThis, publicThis)
  6665. : NOOP;
  6666. if ( get === NOOP) {
  6667. warn(`Computed property "${key}" has no getter.`);
  6668. }
  6669. const set = !isFunction(opt) && isFunction(opt.set)
  6670. ? opt.set.bind(publicThis)
  6671. : () => {
  6672. warn(`Write operation failed: computed property "${key}" is readonly.`);
  6673. }
  6674. ;
  6675. const c = computed$1({
  6676. get,
  6677. set
  6678. });
  6679. Object.defineProperty(ctx, key, {
  6680. enumerable: true,
  6681. configurable: true,
  6682. get: () => c.value,
  6683. set: v => (c.value = v)
  6684. });
  6685. {
  6686. checkDuplicateProperties("Computed" /* COMPUTED */, key);
  6687. }
  6688. }
  6689. }
  6690. if (watchOptions) {
  6691. deferredWatch.push(watchOptions);
  6692. }
  6693. if (!asMixin && deferredWatch.length) {
  6694. deferredWatch.forEach(watchOptions => {
  6695. for (const key in watchOptions) {
  6696. createWatcher(watchOptions[key], ctx, publicThis, key);
  6697. }
  6698. });
  6699. }
  6700. if (provideOptions) {
  6701. const provides = isFunction(provideOptions)
  6702. ? provideOptions.call(publicThis)
  6703. : provideOptions;
  6704. for (const key in provides) {
  6705. provide(key, provides[key]);
  6706. }
  6707. }
  6708. // asset options.
  6709. // To reduce memory usage, only components with mixins or extends will have
  6710. // resolved asset registry attached to instance.
  6711. if (asMixin) {
  6712. if (components) {
  6713. extend(instance.components ||
  6714. (instance.components = extend({}, instance.type.components)), components);
  6715. }
  6716. if (directives) {
  6717. extend(instance.directives ||
  6718. (instance.directives = extend({}, instance.type.directives)), directives);
  6719. }
  6720. }
  6721. // lifecycle options
  6722. if (!asMixin) {
  6723. callSyncHook('created', options, publicThis, globalMixins);
  6724. }
  6725. if (beforeMount) {
  6726. onBeforeMount(beforeMount.bind(publicThis));
  6727. }
  6728. if (mounted) {
  6729. onMounted(mounted.bind(publicThis));
  6730. }
  6731. if (beforeUpdate) {
  6732. onBeforeUpdate(beforeUpdate.bind(publicThis));
  6733. }
  6734. if (updated) {
  6735. onUpdated(updated.bind(publicThis));
  6736. }
  6737. if (activated) {
  6738. onActivated(activated.bind(publicThis));
  6739. }
  6740. if (deactivated) {
  6741. onDeactivated(deactivated.bind(publicThis));
  6742. }
  6743. if (errorCaptured) {
  6744. onErrorCaptured(errorCaptured.bind(publicThis));
  6745. }
  6746. if (renderTracked) {
  6747. onRenderTracked(renderTracked.bind(publicThis));
  6748. }
  6749. if (renderTriggered) {
  6750. onRenderTriggered(renderTriggered.bind(publicThis));
  6751. }
  6752. if ( beforeDestroy) {
  6753. warn(`\`beforeDestroy\` has been renamed to \`beforeUnmount\`.`);
  6754. }
  6755. if (beforeUnmount) {
  6756. onBeforeUnmount(beforeUnmount.bind(publicThis));
  6757. }
  6758. if ( destroyed) {
  6759. warn(`\`destroyed\` has been renamed to \`unmounted\`.`);
  6760. }
  6761. if (unmounted) {
  6762. onUnmounted(unmounted.bind(publicThis));
  6763. }
  6764. }
  6765. function callSyncHook(name, options, ctx, globalMixins) {
  6766. callHookFromMixins(name, globalMixins, ctx);
  6767. const { extends: base, mixins } = options;
  6768. if (base) {
  6769. callHookFromExtends(name, base, ctx);
  6770. }
  6771. if (mixins) {
  6772. callHookFromMixins(name, mixins, ctx);
  6773. }
  6774. const selfHook = options[name];
  6775. if (selfHook) {
  6776. selfHook.call(ctx);
  6777. }
  6778. }
  6779. function callHookFromExtends(name, base, ctx) {
  6780. if (base.extends) {
  6781. callHookFromExtends(name, base.extends, ctx);
  6782. }
  6783. const baseHook = base[name];
  6784. if (baseHook) {
  6785. baseHook.call(ctx);
  6786. }
  6787. }
  6788. function callHookFromMixins(name, mixins, ctx) {
  6789. for (let i = 0; i < mixins.length; i++) {
  6790. const chainedMixins = mixins[i].mixins;
  6791. if (chainedMixins) {
  6792. callHookFromMixins(name, chainedMixins, ctx);
  6793. }
  6794. const fn = mixins[i][name];
  6795. if (fn) {
  6796. fn.call(ctx);
  6797. }
  6798. }
  6799. }
  6800. function applyMixins(instance, mixins, deferredData, deferredWatch) {
  6801. for (let i = 0; i < mixins.length; i++) {
  6802. applyOptions(instance, mixins[i], deferredData, deferredWatch, true);
  6803. }
  6804. }
  6805. function resolveData(instance, dataFn, publicThis) {
  6806. if ( !isFunction(dataFn)) {
  6807. warn(`The data option must be a function. ` +
  6808. `Plain object usage is no longer supported.`);
  6809. }
  6810. const data = dataFn.call(publicThis, publicThis);
  6811. if ( isPromise(data)) {
  6812. warn(`data() returned a Promise - note data() cannot be async; If you ` +
  6813. `intend to perform data fetching before component renders, use ` +
  6814. `async setup() + <Suspense>.`);
  6815. }
  6816. if (!isObject(data)) {
  6817. warn(`data() should return an object.`);
  6818. }
  6819. else if (instance.data === EMPTY_OBJ) {
  6820. instance.data = reactive(data);
  6821. }
  6822. else {
  6823. // existing data: this is a mixin or extends.
  6824. extend(instance.data, data);
  6825. }
  6826. }
  6827. function createWatcher(raw, ctx, publicThis, key) {
  6828. const getter = key.includes('.')
  6829. ? createPathGetter(publicThis, key)
  6830. : () => publicThis[key];
  6831. if (isString(raw)) {
  6832. const handler = ctx[raw];
  6833. if (isFunction(handler)) {
  6834. watch(getter, handler);
  6835. }
  6836. else {
  6837. warn(`Invalid watch handler specified by key "${raw}"`, handler);
  6838. }
  6839. }
  6840. else if (isFunction(raw)) {
  6841. watch(getter, raw.bind(publicThis));
  6842. }
  6843. else if (isObject(raw)) {
  6844. if (isArray(raw)) {
  6845. raw.forEach(r => createWatcher(r, ctx, publicThis, key));
  6846. }
  6847. else {
  6848. const handler = isFunction(raw.handler)
  6849. ? raw.handler.bind(publicThis)
  6850. : ctx[raw.handler];
  6851. if (isFunction(handler)) {
  6852. watch(getter, handler, raw);
  6853. }
  6854. else {
  6855. warn(`Invalid watch handler specified by key "${raw.handler}"`, handler);
  6856. }
  6857. }
  6858. }
  6859. else {
  6860. warn(`Invalid watch option: "${key}"`, raw);
  6861. }
  6862. }
  6863. function createPathGetter(ctx, path) {
  6864. const segments = path.split('.');
  6865. return () => {
  6866. let cur = ctx;
  6867. for (let i = 0; i < segments.length && cur; i++) {
  6868. cur = cur[segments[i]];
  6869. }
  6870. return cur;
  6871. };
  6872. }
  6873. function resolveMergedOptions(instance) {
  6874. const raw = instance.type;
  6875. const { __merged, mixins, extends: extendsOptions } = raw;
  6876. if (__merged)
  6877. return __merged;
  6878. const globalMixins = instance.appContext.mixins;
  6879. if (!globalMixins.length && !mixins && !extendsOptions)
  6880. return raw;
  6881. const options = {};
  6882. globalMixins.forEach(m => mergeOptions(options, m, instance));
  6883. mergeOptions(options, raw, instance);
  6884. return (raw.__merged = options);
  6885. }
  6886. function mergeOptions(to, from, instance) {
  6887. const strats = instance.appContext.config.optionMergeStrategies;
  6888. const { mixins, extends: extendsOptions } = from;
  6889. extendsOptions && mergeOptions(to, extendsOptions, instance);
  6890. mixins &&
  6891. mixins.forEach((m) => mergeOptions(to, m, instance));
  6892. for (const key in from) {
  6893. if (strats && hasOwn(strats, key)) {
  6894. to[key] = strats[key](to[key], from[key], instance.proxy, key);
  6895. }
  6896. else {
  6897. to[key] = from[key];
  6898. }
  6899. }
  6900. }
  6901. const publicPropertiesMap = extend(Object.create(null), {
  6902. $: i => i,
  6903. $el: i => i.vnode.el,
  6904. $data: i => i.data,
  6905. $props: i => ( shallowReadonly(i.props) ),
  6906. $attrs: i => ( shallowReadonly(i.attrs) ),
  6907. $slots: i => ( shallowReadonly(i.slots) ),
  6908. $refs: i => ( shallowReadonly(i.refs) ),
  6909. $parent: i => i.parent && i.parent.proxy,
  6910. $root: i => i.root && i.root.proxy,
  6911. $emit: i => i.emit,
  6912. $options: i => ( resolveMergedOptions(i) ),
  6913. $forceUpdate: i => () => queueJob(i.update),
  6914. $nextTick: () => nextTick,
  6915. $watch: i => ( instanceWatch.bind(i) )
  6916. });
  6917. const PublicInstanceProxyHandlers = {
  6918. get({ _: instance }, key) {
  6919. const { ctx, setupState, data, props, accessCache, type, appContext } = instance;
  6920. // let @vue/reactivity know it should never observe Vue public instances.
  6921. if (key === "__v_skip" /* SKIP */) {
  6922. return true;
  6923. }
  6924. // data / props / ctx
  6925. // This getter gets called for every property access on the render context
  6926. // during render and is a major hotspot. The most expensive part of this
  6927. // is the multiple hasOwn() calls. It's much faster to do a simple property
  6928. // access on a plain object, so we use an accessCache object (with null
  6929. // prototype) to memoize what access type a key corresponds to.
  6930. let normalizedProps;
  6931. if (key[0] !== '$') {
  6932. const n = accessCache[key];
  6933. if (n !== undefined) {
  6934. switch (n) {
  6935. case 0 /* SETUP */:
  6936. return setupState[key];
  6937. case 1 /* DATA */:
  6938. return data[key];
  6939. case 3 /* CONTEXT */:
  6940. return ctx[key];
  6941. case 2 /* PROPS */:
  6942. return props[key];
  6943. // default: just fallthrough
  6944. }
  6945. }
  6946. else if (setupState !== EMPTY_OBJ && hasOwn(setupState, key)) {
  6947. accessCache[key] = 0 /* SETUP */;
  6948. return setupState[key];
  6949. }
  6950. else if (data !== EMPTY_OBJ && hasOwn(data, key)) {
  6951. accessCache[key] = 1 /* DATA */;
  6952. return data[key];
  6953. }
  6954. else if (
  6955. // only cache other properties when instance has declared (thus stable)
  6956. // props
  6957. (normalizedProps = instance.propsOptions[0]) &&
  6958. hasOwn(normalizedProps, key)) {
  6959. accessCache[key] = 2 /* PROPS */;
  6960. return props[key];
  6961. }
  6962. else if (ctx !== EMPTY_OBJ && hasOwn(ctx, key)) {
  6963. accessCache[key] = 3 /* CONTEXT */;
  6964. return ctx[key];
  6965. }
  6966. else if ( !isInBeforeCreate) {
  6967. accessCache[key] = 4 /* OTHER */;
  6968. }
  6969. }
  6970. const publicGetter = publicPropertiesMap[key];
  6971. let cssModule, globalProperties;
  6972. // public $xxx properties
  6973. if (publicGetter) {
  6974. if (key === '$attrs') {
  6975. track(instance, "get" /* GET */, key);
  6976. markAttrsAccessed();
  6977. }
  6978. return publicGetter(instance);
  6979. }
  6980. else if (
  6981. // css module (injected by vue-loader)
  6982. (cssModule = type.__cssModules) &&
  6983. (cssModule = cssModule[key])) {
  6984. return cssModule;
  6985. }
  6986. else if (ctx !== EMPTY_OBJ && hasOwn(ctx, key)) {
  6987. // user may set custom properties to `this` that start with `$`
  6988. accessCache[key] = 3 /* CONTEXT */;
  6989. return ctx[key];
  6990. }
  6991. else if (
  6992. // global properties
  6993. ((globalProperties = appContext.config.globalProperties),
  6994. hasOwn(globalProperties, key))) {
  6995. return globalProperties[key];
  6996. }
  6997. else if (
  6998. currentRenderingInstance &&
  6999. (!isString(key) ||
  7000. // #1091 avoid internal isRef/isVNode checks on component instance leading
  7001. // to infinite warning loop
  7002. key.indexOf('__v') !== 0)) {
  7003. if (data !== EMPTY_OBJ &&
  7004. (key[0] === '$' || key[0] === '_') &&
  7005. hasOwn(data, key)) {
  7006. warn(`Property ${JSON.stringify(key)} must be accessed via $data because it starts with a reserved ` +
  7007. `character ("$" or "_") and is not proxied on the render context.`);
  7008. }
  7009. else {
  7010. warn(`Property ${JSON.stringify(key)} was accessed during render ` +
  7011. `but is not defined on instance.`);
  7012. }
  7013. }
  7014. },
  7015. set({ _: instance }, key, value) {
  7016. const { data, setupState, ctx } = instance;
  7017. if (setupState !== EMPTY_OBJ && hasOwn(setupState, key)) {
  7018. setupState[key] = value;
  7019. }
  7020. else if (data !== EMPTY_OBJ && hasOwn(data, key)) {
  7021. data[key] = value;
  7022. }
  7023. else if (key in instance.props) {
  7024. warn(`Attempting to mutate prop "${key}". Props are readonly.`, instance);
  7025. return false;
  7026. }
  7027. if (key[0] === '$' && key.slice(1) in instance) {
  7028. warn(`Attempting to mutate public property "${key}". ` +
  7029. `Properties starting with $ are reserved and readonly.`, instance);
  7030. return false;
  7031. }
  7032. else {
  7033. if ( key in instance.appContext.config.globalProperties) {
  7034. Object.defineProperty(ctx, key, {
  7035. enumerable: true,
  7036. configurable: true,
  7037. value
  7038. });
  7039. }
  7040. else {
  7041. ctx[key] = value;
  7042. }
  7043. }
  7044. return true;
  7045. },
  7046. has({ _: { data, setupState, accessCache, ctx, appContext, propsOptions } }, key) {
  7047. let normalizedProps;
  7048. return (accessCache[key] !== undefined ||
  7049. (data !== EMPTY_OBJ && hasOwn(data, key)) ||
  7050. (setupState !== EMPTY_OBJ && hasOwn(setupState, key)) ||
  7051. ((normalizedProps = propsOptions[0]) && hasOwn(normalizedProps, key)) ||
  7052. hasOwn(ctx, key) ||
  7053. hasOwn(publicPropertiesMap, key) ||
  7054. hasOwn(appContext.config.globalProperties, key));
  7055. }
  7056. };
  7057. {
  7058. PublicInstanceProxyHandlers.ownKeys = (target) => {
  7059. warn(`Avoid app logic that relies on enumerating keys on a component instance. ` +
  7060. `The keys will be empty in production mode to avoid performance overhead.`);
  7061. return Reflect.ownKeys(target);
  7062. };
  7063. }
  7064. const RuntimeCompiledPublicInstanceProxyHandlers = extend({}, PublicInstanceProxyHandlers, {
  7065. get(target, key) {
  7066. // fast path for unscopables when using `with` block
  7067. if (key === Symbol.unscopables) {
  7068. return;
  7069. }
  7070. return PublicInstanceProxyHandlers.get(target, key, target);
  7071. },
  7072. has(_, key) {
  7073. const has = key[0] !== '_' && !isGloballyWhitelisted(key);
  7074. if ( !has && PublicInstanceProxyHandlers.has(_, key)) {
  7075. warn(`Property ${JSON.stringify(key)} should not start with _ which is a reserved prefix for Vue internals.`);
  7076. }
  7077. return has;
  7078. }
  7079. });
  7080. // In dev mode, the proxy target exposes the same properties as seen on `this`
  7081. // for easier console inspection. In prod mode it will be an empty object so
  7082. // these properties definitions can be skipped.
  7083. function createRenderContext(instance) {
  7084. const target = {};
  7085. // expose internal instance for proxy handlers
  7086. Object.defineProperty(target, `_`, {
  7087. configurable: true,
  7088. enumerable: false,
  7089. get: () => instance
  7090. });
  7091. // expose public properties
  7092. Object.keys(publicPropertiesMap).forEach(key => {
  7093. Object.defineProperty(target, key, {
  7094. configurable: true,
  7095. enumerable: false,
  7096. get: () => publicPropertiesMap[key](instance),
  7097. // intercepted by the proxy so no need for implementation,
  7098. // but needed to prevent set errors
  7099. set: NOOP
  7100. });
  7101. });
  7102. // expose global properties
  7103. const { globalProperties } = instance.appContext.config;
  7104. Object.keys(globalProperties).forEach(key => {
  7105. Object.defineProperty(target, key, {
  7106. configurable: true,
  7107. enumerable: false,
  7108. get: () => globalProperties[key],
  7109. set: NOOP
  7110. });
  7111. });
  7112. return target;
  7113. }
  7114. // dev only
  7115. function exposePropsOnRenderContext(instance) {
  7116. const { ctx, propsOptions: [propsOptions] } = instance;
  7117. if (propsOptions) {
  7118. Object.keys(propsOptions).forEach(key => {
  7119. Object.defineProperty(ctx, key, {
  7120. enumerable: true,
  7121. configurable: true,
  7122. get: () => instance.props[key],
  7123. set: NOOP
  7124. });
  7125. });
  7126. }
  7127. }
  7128. // dev only
  7129. function exposeSetupStateOnRenderContext(instance) {
  7130. const { ctx, setupState } = instance;
  7131. Object.keys(toRaw(setupState)).forEach(key => {
  7132. if (key[0] === '$' || key[0] === '_') {
  7133. warn(`setup() return property ${JSON.stringify(key)} should not start with "$" or "_" ` +
  7134. `which are reserved prefixes for Vue internals.`);
  7135. return;
  7136. }
  7137. Object.defineProperty(ctx, key, {
  7138. enumerable: true,
  7139. configurable: true,
  7140. get: () => setupState[key],
  7141. set: NOOP
  7142. });
  7143. });
  7144. }
  7145. const emptyAppContext = createAppContext();
  7146. let uid$2 = 0;
  7147. function createComponentInstance(vnode, parent, suspense) {
  7148. const type = vnode.type;
  7149. // inherit parent app context - or - if root, adopt from root vnode
  7150. const appContext = (parent ? parent.appContext : vnode.appContext) || emptyAppContext;
  7151. const instance = {
  7152. uid: uid$2++,
  7153. vnode,
  7154. type,
  7155. parent,
  7156. appContext,
  7157. root: null,
  7158. next: null,
  7159. subTree: null,
  7160. update: null,
  7161. render: null,
  7162. proxy: null,
  7163. withProxy: null,
  7164. effects: null,
  7165. provides: parent ? parent.provides : Object.create(appContext.provides),
  7166. accessCache: null,
  7167. renderCache: [],
  7168. // local resovled assets
  7169. components: null,
  7170. directives: null,
  7171. // resolved props and emits options
  7172. propsOptions: normalizePropsOptions(type, appContext),
  7173. emitsOptions: normalizeEmitsOptions(type, appContext),
  7174. // emit
  7175. emit: null,
  7176. emitted: null,
  7177. // state
  7178. ctx: EMPTY_OBJ,
  7179. data: EMPTY_OBJ,
  7180. props: EMPTY_OBJ,
  7181. attrs: EMPTY_OBJ,
  7182. slots: EMPTY_OBJ,
  7183. refs: EMPTY_OBJ,
  7184. setupState: EMPTY_OBJ,
  7185. setupContext: null,
  7186. // suspense related
  7187. suspense,
  7188. suspenseId: suspense ? suspense.pendingId : 0,
  7189. asyncDep: null,
  7190. asyncResolved: false,
  7191. // lifecycle hooks
  7192. // not using enums here because it results in computed properties
  7193. isMounted: false,
  7194. isUnmounted: false,
  7195. isDeactivated: false,
  7196. bc: null,
  7197. c: null,
  7198. bm: null,
  7199. m: null,
  7200. bu: null,
  7201. u: null,
  7202. um: null,
  7203. bum: null,
  7204. da: null,
  7205. a: null,
  7206. rtg: null,
  7207. rtc: null,
  7208. ec: null
  7209. };
  7210. {
  7211. instance.ctx = createRenderContext(instance);
  7212. }
  7213. instance.root = parent ? parent.root : instance;
  7214. instance.emit = emit.bind(null, instance);
  7215. {
  7216. devtoolsComponentAdded(instance);
  7217. }
  7218. return instance;
  7219. }
  7220. let currentInstance = null;
  7221. const getCurrentInstance = () => currentInstance || currentRenderingInstance;
  7222. const setCurrentInstance = (instance) => {
  7223. currentInstance = instance;
  7224. };
  7225. const isBuiltInTag = /*#__PURE__*/ makeMap('slot,component');
  7226. function validateComponentName(name, config) {
  7227. const appIsNativeTag = config.isNativeTag || NO;
  7228. if (isBuiltInTag(name) || appIsNativeTag(name)) {
  7229. warn('Do not use built-in or reserved HTML elements as component id: ' + name);
  7230. }
  7231. }
  7232. let isInSSRComponentSetup = false;
  7233. function setupComponent(instance, isSSR = false) {
  7234. isInSSRComponentSetup = isSSR;
  7235. const { props, children, shapeFlag } = instance.vnode;
  7236. const isStateful = shapeFlag & 4 /* STATEFUL_COMPONENT */;
  7237. initProps(instance, props, isStateful, isSSR);
  7238. initSlots(instance, children);
  7239. const setupResult = isStateful
  7240. ? setupStatefulComponent(instance, isSSR)
  7241. : undefined;
  7242. isInSSRComponentSetup = false;
  7243. return setupResult;
  7244. }
  7245. function setupStatefulComponent(instance, isSSR) {
  7246. const Component = instance.type;
  7247. {
  7248. if (Component.name) {
  7249. validateComponentName(Component.name, instance.appContext.config);
  7250. }
  7251. if (Component.components) {
  7252. const names = Object.keys(Component.components);
  7253. for (let i = 0; i < names.length; i++) {
  7254. validateComponentName(names[i], instance.appContext.config);
  7255. }
  7256. }
  7257. if (Component.directives) {
  7258. const names = Object.keys(Component.directives);
  7259. for (let i = 0; i < names.length; i++) {
  7260. validateDirectiveName(names[i]);
  7261. }
  7262. }
  7263. }
  7264. // 0. create render proxy property access cache
  7265. instance.accessCache = {};
  7266. // 1. create public instance / render proxy
  7267. // also mark it raw so it's never observed
  7268. instance.proxy = new Proxy(instance.ctx, PublicInstanceProxyHandlers);
  7269. {
  7270. exposePropsOnRenderContext(instance);
  7271. }
  7272. // 2. call setup()
  7273. const { setup } = Component;
  7274. if (setup) {
  7275. const setupContext = (instance.setupContext =
  7276. setup.length > 1 ? createSetupContext(instance) : null);
  7277. currentInstance = instance;
  7278. pauseTracking();
  7279. const setupResult = callWithErrorHandling(setup, instance, 0 /* SETUP_FUNCTION */, [ shallowReadonly(instance.props) , setupContext]);
  7280. resetTracking();
  7281. currentInstance = null;
  7282. if (isPromise(setupResult)) {
  7283. if (isSSR) {
  7284. // return the promise so server-renderer can wait on it
  7285. return setupResult.then((resolvedResult) => {
  7286. handleSetupResult(instance, resolvedResult);
  7287. });
  7288. }
  7289. else {
  7290. // async setup returned Promise.
  7291. // bail here and wait for re-entry.
  7292. instance.asyncDep = setupResult;
  7293. }
  7294. }
  7295. else {
  7296. handleSetupResult(instance, setupResult);
  7297. }
  7298. }
  7299. else {
  7300. finishComponentSetup(instance);
  7301. }
  7302. }
  7303. function handleSetupResult(instance, setupResult, isSSR) {
  7304. if (isFunction(setupResult)) {
  7305. // setup returned an inline render function
  7306. instance.render = setupResult;
  7307. }
  7308. else if (isObject(setupResult)) {
  7309. if ( isVNode(setupResult)) {
  7310. warn(`setup() should not return VNodes directly - ` +
  7311. `return a render function instead.`);
  7312. }
  7313. // setup returned bindings.
  7314. // assuming a render function compiled from template is present.
  7315. {
  7316. instance.devtoolsRawSetupState = setupResult;
  7317. }
  7318. instance.setupState = proxyRefs(setupResult);
  7319. {
  7320. exposeSetupStateOnRenderContext(instance);
  7321. }
  7322. }
  7323. else if ( setupResult !== undefined) {
  7324. warn(`setup() should return an object. Received: ${setupResult === null ? 'null' : typeof setupResult}`);
  7325. }
  7326. finishComponentSetup(instance);
  7327. }
  7328. let compile;
  7329. /**
  7330. * For runtime-dom to register the compiler.
  7331. * Note the exported method uses any to avoid d.ts relying on the compiler types.
  7332. */
  7333. function registerRuntimeCompiler(_compile) {
  7334. compile = _compile;
  7335. }
  7336. function finishComponentSetup(instance, isSSR) {
  7337. const Component = instance.type;
  7338. // template / render function normalization
  7339. if (!instance.render) {
  7340. // could be set from setup()
  7341. if (compile && Component.template && !Component.render) {
  7342. {
  7343. startMeasure(instance, `compile`);
  7344. }
  7345. Component.render = compile(Component.template, {
  7346. isCustomElement: instance.appContext.config.isCustomElement,
  7347. delimiters: Component.delimiters
  7348. });
  7349. {
  7350. endMeasure(instance, `compile`);
  7351. }
  7352. }
  7353. instance.render = (Component.render || NOOP);
  7354. // for runtime-compiled render functions using `with` blocks, the render
  7355. // proxy used needs a different `has` handler which is more performant and
  7356. // also only allows a whitelist of globals to fallthrough.
  7357. if (instance.render._rc) {
  7358. instance.withProxy = new Proxy(instance.ctx, RuntimeCompiledPublicInstanceProxyHandlers);
  7359. }
  7360. }
  7361. // support for 2.x options
  7362. {
  7363. currentInstance = instance;
  7364. applyOptions(instance, Component);
  7365. currentInstance = null;
  7366. }
  7367. // warn missing template/render
  7368. if ( !Component.render && instance.render === NOOP) {
  7369. /* istanbul ignore if */
  7370. if (!compile && Component.template) {
  7371. warn(`Component provided template option but ` +
  7372. `runtime compilation is not supported in this build of Vue.` +
  7373. ( ` Use "vue.global.js" instead.`
  7374. ) /* should not happen */);
  7375. }
  7376. else {
  7377. warn(`Component is missing template or render function.`);
  7378. }
  7379. }
  7380. }
  7381. const attrHandlers = {
  7382. get: (target, key) => {
  7383. {
  7384. markAttrsAccessed();
  7385. }
  7386. return target[key];
  7387. },
  7388. set: () => {
  7389. warn(`setupContext.attrs is readonly.`);
  7390. return false;
  7391. },
  7392. deleteProperty: () => {
  7393. warn(`setupContext.attrs is readonly.`);
  7394. return false;
  7395. }
  7396. };
  7397. function createSetupContext(instance) {
  7398. {
  7399. // We use getters in dev in case libs like test-utils overwrite instance
  7400. // properties (overwrites should not be done in prod)
  7401. return Object.freeze({
  7402. get attrs() {
  7403. return new Proxy(instance.attrs, attrHandlers);
  7404. },
  7405. get slots() {
  7406. return shallowReadonly(instance.slots);
  7407. },
  7408. get emit() {
  7409. return (event, ...args) => instance.emit(event, ...args);
  7410. }
  7411. });
  7412. }
  7413. }
  7414. // record effects created during a component's setup() so that they can be
  7415. // stopped when the component unmounts
  7416. function recordInstanceBoundEffect(effect) {
  7417. if (currentInstance) {
  7418. (currentInstance.effects || (currentInstance.effects = [])).push(effect);
  7419. }
  7420. }
  7421. const classifyRE = /(?:^|[-_])(\w)/g;
  7422. const classify = (str) => str.replace(classifyRE, c => c.toUpperCase()).replace(/[-_]/g, '');
  7423. /* istanbul ignore next */
  7424. function formatComponentName(instance, Component, isRoot = false) {
  7425. let name = isFunction(Component)
  7426. ? Component.displayName || Component.name
  7427. : Component.name;
  7428. if (!name && Component.__file) {
  7429. const match = Component.__file.match(/([^/\\]+)\.vue$/);
  7430. if (match) {
  7431. name = match[1];
  7432. }
  7433. }
  7434. if (!name && instance && instance.parent) {
  7435. // try to infer the name based on reverse resolution
  7436. const inferFromRegistry = (registry) => {
  7437. for (const key in registry) {
  7438. if (registry[key] === Component) {
  7439. return key;
  7440. }
  7441. }
  7442. };
  7443. name =
  7444. inferFromRegistry(instance.components ||
  7445. instance.parent.type.components) || inferFromRegistry(instance.appContext.components);
  7446. }
  7447. return name ? classify(name) : isRoot ? `App` : `Anonymous`;
  7448. }
  7449. function isClassComponent(value) {
  7450. return isFunction(value) && '__vccOpts' in value;
  7451. }
  7452. function computed$1(getterOrOptions) {
  7453. const c = computed(getterOrOptions);
  7454. recordInstanceBoundEffect(c.effect);
  7455. return c;
  7456. }
  7457. // implementation, close to no-op
  7458. function defineComponent(options) {
  7459. return isFunction(options) ? { setup: options, name: options.name } : options;
  7460. }
  7461. function defineAsyncComponent(source) {
  7462. if (isFunction(source)) {
  7463. source = { loader: source };
  7464. }
  7465. const { loader, loadingComponent: loadingComponent, errorComponent: errorComponent, delay = 200, timeout, // undefined = never times out
  7466. suspensible = true, onError: userOnError } = source;
  7467. let pendingRequest = null;
  7468. let resolvedComp;
  7469. let retries = 0;
  7470. const retry = () => {
  7471. retries++;
  7472. pendingRequest = null;
  7473. return load();
  7474. };
  7475. const load = () => {
  7476. let thisRequest;
  7477. return (pendingRequest ||
  7478. (thisRequest = pendingRequest = loader()
  7479. .catch(err => {
  7480. err = err instanceof Error ? err : new Error(String(err));
  7481. if (userOnError) {
  7482. return new Promise((resolve, reject) => {
  7483. const userRetry = () => resolve(retry());
  7484. const userFail = () => reject(err);
  7485. userOnError(err, userRetry, userFail, retries + 1);
  7486. });
  7487. }
  7488. else {
  7489. throw err;
  7490. }
  7491. })
  7492. .then((comp) => {
  7493. if (thisRequest !== pendingRequest && pendingRequest) {
  7494. return pendingRequest;
  7495. }
  7496. if ( !comp) {
  7497. warn(`Async component loader resolved to undefined. ` +
  7498. `If you are using retry(), make sure to return its return value.`);
  7499. }
  7500. // interop module default
  7501. if (comp &&
  7502. (comp.__esModule || comp[Symbol.toStringTag] === 'Module')) {
  7503. comp = comp.default;
  7504. }
  7505. if ( comp && !isObject(comp) && !isFunction(comp)) {
  7506. throw new Error(`Invalid async component load result: ${comp}`);
  7507. }
  7508. resolvedComp = comp;
  7509. return comp;
  7510. })));
  7511. };
  7512. return defineComponent({
  7513. __asyncLoader: load,
  7514. name: 'AsyncComponentWrapper',
  7515. setup() {
  7516. const instance = currentInstance;
  7517. // already resolved
  7518. if (resolvedComp) {
  7519. return () => createInnerComp(resolvedComp, instance);
  7520. }
  7521. const onError = (err) => {
  7522. pendingRequest = null;
  7523. handleError(err, instance, 13 /* ASYNC_COMPONENT_LOADER */, !errorComponent /* do not throw in dev if user provided error component */);
  7524. };
  7525. // suspense-controlled or SSR.
  7526. if (( suspensible && instance.suspense) ||
  7527. (false )) {
  7528. return load()
  7529. .then(comp => {
  7530. return () => createInnerComp(comp, instance);
  7531. })
  7532. .catch(err => {
  7533. onError(err);
  7534. return () => errorComponent
  7535. ? createVNode(errorComponent, {
  7536. error: err
  7537. })
  7538. : null;
  7539. });
  7540. }
  7541. const loaded = ref(false);
  7542. const error = ref();
  7543. const delayed = ref(!!delay);
  7544. if (delay) {
  7545. setTimeout(() => {
  7546. delayed.value = false;
  7547. }, delay);
  7548. }
  7549. if (timeout != null) {
  7550. setTimeout(() => {
  7551. if (!loaded.value && !error.value) {
  7552. const err = new Error(`Async component timed out after ${timeout}ms.`);
  7553. onError(err);
  7554. error.value = err;
  7555. }
  7556. }, timeout);
  7557. }
  7558. load()
  7559. .then(() => {
  7560. loaded.value = true;
  7561. })
  7562. .catch(err => {
  7563. onError(err);
  7564. error.value = err;
  7565. });
  7566. return () => {
  7567. if (loaded.value && resolvedComp) {
  7568. return createInnerComp(resolvedComp, instance);
  7569. }
  7570. else if (error.value && errorComponent) {
  7571. return createVNode(errorComponent, {
  7572. error: error.value
  7573. });
  7574. }
  7575. else if (loadingComponent && !delayed.value) {
  7576. return createVNode(loadingComponent);
  7577. }
  7578. };
  7579. }
  7580. });
  7581. }
  7582. function createInnerComp(comp, { vnode: { props, children } }) {
  7583. return createVNode(comp, props, children);
  7584. }
  7585. // Actual implementation
  7586. function h(type, propsOrChildren, children) {
  7587. const l = arguments.length;
  7588. if (l === 2) {
  7589. if (isObject(propsOrChildren) && !isArray(propsOrChildren)) {
  7590. // single vnode without props
  7591. if (isVNode(propsOrChildren)) {
  7592. return createVNode(type, null, [propsOrChildren]);
  7593. }
  7594. // props without children
  7595. return createVNode(type, propsOrChildren);
  7596. }
  7597. else {
  7598. // omit props
  7599. return createVNode(type, null, propsOrChildren);
  7600. }
  7601. }
  7602. else {
  7603. if (l > 3) {
  7604. children = Array.prototype.slice.call(arguments, 2);
  7605. }
  7606. else if (l === 3 && isVNode(children)) {
  7607. children = [children];
  7608. }
  7609. return createVNode(type, propsOrChildren, children);
  7610. }
  7611. }
  7612. const ssrContextKey = Symbol( `ssrContext` );
  7613. const useSSRContext = () => {
  7614. {
  7615. warn(`useSsrContext() is not supported in the global build.`);
  7616. }
  7617. };
  7618. /**
  7619. * Actual implementation
  7620. */
  7621. function renderList(source, renderItem) {
  7622. let ret;
  7623. if (isArray(source) || isString(source)) {
  7624. ret = new Array(source.length);
  7625. for (let i = 0, l = source.length; i < l; i++) {
  7626. ret[i] = renderItem(source[i], i);
  7627. }
  7628. }
  7629. else if (typeof source === 'number') {
  7630. ret = new Array(source);
  7631. for (let i = 0; i < source; i++) {
  7632. ret[i] = renderItem(i + 1, i);
  7633. }
  7634. }
  7635. else if (isObject(source)) {
  7636. if (source[Symbol.iterator]) {
  7637. ret = Array.from(source, renderItem);
  7638. }
  7639. else {
  7640. const keys = Object.keys(source);
  7641. ret = new Array(keys.length);
  7642. for (let i = 0, l = keys.length; i < l; i++) {
  7643. const key = keys[i];
  7644. ret[i] = renderItem(source[key], key, i);
  7645. }
  7646. }
  7647. }
  7648. else {
  7649. ret = [];
  7650. }
  7651. return ret;
  7652. }
  7653. /**
  7654. * For prefixing keys in v-on="obj" with "on"
  7655. * @private
  7656. */
  7657. function toHandlers(obj) {
  7658. const ret = {};
  7659. if ( !isObject(obj)) {
  7660. warn(`v-on with no argument expects an object value.`);
  7661. return ret;
  7662. }
  7663. for (const key in obj) {
  7664. ret[`on${capitalize(key)}`] = obj[key];
  7665. }
  7666. return ret;
  7667. }
  7668. /**
  7669. * Compiler runtime helper for creating dynamic slots object
  7670. * @private
  7671. */
  7672. function createSlots(slots, dynamicSlots) {
  7673. for (let i = 0; i < dynamicSlots.length; i++) {
  7674. const slot = dynamicSlots[i];
  7675. // array of dynamic slot generated by <template v-for="..." #[...]>
  7676. if (isArray(slot)) {
  7677. for (let j = 0; j < slot.length; j++) {
  7678. slots[slot[j].name] = slot[j].fn;
  7679. }
  7680. }
  7681. else if (slot) {
  7682. // conditional single slot generated by <template v-if="..." #foo>
  7683. slots[slot.name] = slot.fn;
  7684. }
  7685. }
  7686. return slots;
  7687. }
  7688. // Core API ------------------------------------------------------------------
  7689. const version = "3.0.0";
  7690. /**
  7691. * SSR utils for \@vue/server-renderer. Only exposed in cjs builds.
  7692. * @internal
  7693. */
  7694. const ssrUtils = ( null);
  7695. const svgNS = 'http://www.w3.org/2000/svg';
  7696. const doc = (typeof document !== 'undefined' ? document : null);
  7697. let tempContainer;
  7698. let tempSVGContainer;
  7699. const nodeOps = {
  7700. insert: (child, parent, anchor) => {
  7701. parent.insertBefore(child, anchor || null);
  7702. },
  7703. remove: child => {
  7704. const parent = child.parentNode;
  7705. if (parent) {
  7706. parent.removeChild(child);
  7707. }
  7708. },
  7709. createElement: (tag, isSVG, is) => isSVG
  7710. ? doc.createElementNS(svgNS, tag)
  7711. : doc.createElement(tag, is ? { is } : undefined),
  7712. createText: text => doc.createTextNode(text),
  7713. createComment: text => doc.createComment(text),
  7714. setText: (node, text) => {
  7715. node.nodeValue = text;
  7716. },
  7717. setElementText: (el, text) => {
  7718. el.textContent = text;
  7719. },
  7720. parentNode: node => node.parentNode,
  7721. nextSibling: node => node.nextSibling,
  7722. querySelector: selector => doc.querySelector(selector),
  7723. setScopeId(el, id) {
  7724. el.setAttribute(id, '');
  7725. },
  7726. cloneNode(el) {
  7727. return el.cloneNode(true);
  7728. },
  7729. // __UNSAFE__
  7730. // Reason: innerHTML.
  7731. // Static content here can only come from compiled templates.
  7732. // As long as the user only uses trusted templates, this is safe.
  7733. insertStaticContent(content, parent, anchor, isSVG) {
  7734. const temp = isSVG
  7735. ? tempSVGContainer ||
  7736. (tempSVGContainer = doc.createElementNS(svgNS, 'svg'))
  7737. : tempContainer || (tempContainer = doc.createElement('div'));
  7738. temp.innerHTML = content;
  7739. const first = temp.firstChild;
  7740. let node = first;
  7741. let last = node;
  7742. while (node) {
  7743. last = node;
  7744. nodeOps.insert(node, parent, anchor);
  7745. node = temp.firstChild;
  7746. }
  7747. return [first, last];
  7748. }
  7749. };
  7750. // compiler should normalize class + :class bindings on the same element
  7751. // into a single binding ['staticClass', dynamic]
  7752. function patchClass(el, value, isSVG) {
  7753. if (value == null) {
  7754. value = '';
  7755. }
  7756. if (isSVG) {
  7757. el.setAttribute('class', value);
  7758. }
  7759. else {
  7760. // directly setting className should be faster than setAttribute in theory
  7761. // if this is an element during a transition, take the temporary transition
  7762. // classes into account.
  7763. const transitionClasses = el._vtc;
  7764. if (transitionClasses) {
  7765. value = (value
  7766. ? [value, ...transitionClasses]
  7767. : [...transitionClasses]).join(' ');
  7768. }
  7769. el.className = value;
  7770. }
  7771. }
  7772. function patchStyle(el, prev, next) {
  7773. const style = el.style;
  7774. if (!next) {
  7775. el.removeAttribute('style');
  7776. }
  7777. else if (isString(next)) {
  7778. if (prev !== next) {
  7779. style.cssText = next;
  7780. }
  7781. }
  7782. else {
  7783. for (const key in next) {
  7784. setStyle(style, key, next[key]);
  7785. }
  7786. if (prev && !isString(prev)) {
  7787. for (const key in prev) {
  7788. if (next[key] == null) {
  7789. setStyle(style, key, '');
  7790. }
  7791. }
  7792. }
  7793. }
  7794. }
  7795. const importantRE = /\s*!important$/;
  7796. function setStyle(style, name, val) {
  7797. if (isArray(val)) {
  7798. val.forEach(v => setStyle(style, name, v));
  7799. }
  7800. else {
  7801. if (name.startsWith('--')) {
  7802. // custom property definition
  7803. style.setProperty(name, val);
  7804. }
  7805. else {
  7806. const prefixed = autoPrefix(style, name);
  7807. if (importantRE.test(val)) {
  7808. // !important
  7809. style.setProperty(hyphenate(prefixed), val.replace(importantRE, ''), 'important');
  7810. }
  7811. else {
  7812. style[prefixed] = val;
  7813. }
  7814. }
  7815. }
  7816. }
  7817. const prefixes = ['Webkit', 'Moz', 'ms'];
  7818. const prefixCache = {};
  7819. function autoPrefix(style, rawName) {
  7820. const cached = prefixCache[rawName];
  7821. if (cached) {
  7822. return cached;
  7823. }
  7824. let name = camelize(rawName);
  7825. if (name !== 'filter' && name in style) {
  7826. return (prefixCache[rawName] = name);
  7827. }
  7828. name = capitalize(name);
  7829. for (let i = 0; i < prefixes.length; i++) {
  7830. const prefixed = prefixes[i] + name;
  7831. if (prefixed in style) {
  7832. return (prefixCache[rawName] = prefixed);
  7833. }
  7834. }
  7835. return rawName;
  7836. }
  7837. const xlinkNS = 'http://www.w3.org/1999/xlink';
  7838. function patchAttr(el, key, value, isSVG) {
  7839. if (isSVG && key.startsWith('xlink:')) {
  7840. if (value == null) {
  7841. el.removeAttributeNS(xlinkNS, key.slice(6, key.length));
  7842. }
  7843. else {
  7844. el.setAttributeNS(xlinkNS, key, value);
  7845. }
  7846. }
  7847. else {
  7848. // note we are only checking boolean attributes that don't have a
  7849. // corresponding dom prop of the same name here.
  7850. const isBoolean = isSpecialBooleanAttr(key);
  7851. if (value == null || (isBoolean && value === false)) {
  7852. el.removeAttribute(key);
  7853. }
  7854. else {
  7855. el.setAttribute(key, isBoolean ? '' : value);
  7856. }
  7857. }
  7858. }
  7859. // __UNSAFE__
  7860. // functions. The user is responsible for using them with only trusted content.
  7861. function patchDOMProp(el, key, value,
  7862. // the following args are passed only due to potential innerHTML/textContent
  7863. // overriding existing VNodes, in which case the old tree must be properly
  7864. // unmounted.
  7865. prevChildren, parentComponent, parentSuspense, unmountChildren) {
  7866. if (key === 'innerHTML' || key === 'textContent') {
  7867. if (prevChildren) {
  7868. unmountChildren(prevChildren, parentComponent, parentSuspense);
  7869. }
  7870. el[key] = value == null ? '' : value;
  7871. return;
  7872. }
  7873. if (key === 'value' && el.tagName !== 'PROGRESS') {
  7874. // store value as _value as well since
  7875. // non-string values will be stringified.
  7876. el._value = value;
  7877. const newValue = value == null ? '' : value;
  7878. if (el.value !== newValue) {
  7879. el.value = newValue;
  7880. }
  7881. return;
  7882. }
  7883. if (value === '' && typeof el[key] === 'boolean') {
  7884. // e.g. <select multiple> compiles to { multiple: '' }
  7885. el[key] = true;
  7886. }
  7887. else if (value == null && typeof el[key] === 'string') {
  7888. // e.g. <div :id="null">
  7889. el[key] = '';
  7890. el.removeAttribute(key);
  7891. }
  7892. else {
  7893. // some properties perform value validation and throw
  7894. try {
  7895. el[key] = value;
  7896. }
  7897. catch (e) {
  7898. {
  7899. warn(`Failed setting prop "${key}" on <${el.tagName.toLowerCase()}>: ` +
  7900. `value ${value} is invalid.`, e);
  7901. }
  7902. }
  7903. }
  7904. }
  7905. // Async edge case fix requires storing an event listener's attach timestamp.
  7906. let _getNow = Date.now;
  7907. // Determine what event timestamp the browser is using. Annoyingly, the
  7908. // timestamp can either be hi-res (relative to page load) or low-res
  7909. // (relative to UNIX epoch), so in order to compare time we have to use the
  7910. // same timestamp type when saving the flush timestamp.
  7911. if (typeof document !== 'undefined' &&
  7912. _getNow() > document.createEvent('Event').timeStamp) {
  7913. // if the low-res timestamp which is bigger than the event timestamp
  7914. // (which is evaluated AFTER) it means the event is using a hi-res timestamp,
  7915. // and we need to use the hi-res version for event listeners as well.
  7916. _getNow = () => performance.now();
  7917. }
  7918. // To avoid the overhead of repeatedly calling performance.now(), we cache
  7919. // and use the same timestamp for all event listeners attached in the same tick.
  7920. let cachedNow = 0;
  7921. const p = Promise.resolve();
  7922. const reset = () => {
  7923. cachedNow = 0;
  7924. };
  7925. const getNow = () => cachedNow || (p.then(reset), (cachedNow = _getNow()));
  7926. function addEventListener(el, event, handler, options) {
  7927. el.addEventListener(event, handler, options);
  7928. }
  7929. function removeEventListener(el, event, handler, options) {
  7930. el.removeEventListener(event, handler, options);
  7931. }
  7932. function patchEvent(el, rawName, prevValue, nextValue, instance = null) {
  7933. // vei = vue event invokers
  7934. const invokers = el._vei || (el._vei = {});
  7935. const existingInvoker = invokers[rawName];
  7936. if (nextValue && existingInvoker) {
  7937. // patch
  7938. existingInvoker.value = nextValue;
  7939. }
  7940. else {
  7941. const [name, options] = parseName(rawName);
  7942. if (nextValue) {
  7943. // add
  7944. const invoker = (invokers[rawName] = createInvoker(nextValue, instance));
  7945. addEventListener(el, name, invoker, options);
  7946. }
  7947. else if (existingInvoker) {
  7948. // remove
  7949. removeEventListener(el, name, existingInvoker, options);
  7950. invokers[rawName] = undefined;
  7951. }
  7952. }
  7953. }
  7954. const optionsModifierRE = /(?:Once|Passive|Capture)$/;
  7955. function parseName(name) {
  7956. let options;
  7957. if (optionsModifierRE.test(name)) {
  7958. options = {};
  7959. let m;
  7960. while ((m = name.match(optionsModifierRE))) {
  7961. name = name.slice(0, name.length - m[0].length);
  7962. options[m[0].toLowerCase()] = true;
  7963. }
  7964. }
  7965. return [name.slice(2).toLowerCase(), options];
  7966. }
  7967. function createInvoker(initialValue, instance) {
  7968. const invoker = (e) => {
  7969. // async edge case #6566: inner click event triggers patch, event handler
  7970. // attached to outer element during patch, and triggered again. This
  7971. // happens because browsers fire microtask ticks between event propagation.
  7972. // the solution is simple: we save the timestamp when a handler is attached,
  7973. // and the handler would only fire if the event passed to it was fired
  7974. // AFTER it was attached.
  7975. const timeStamp = e.timeStamp || _getNow();
  7976. if (timeStamp >= invoker.attached - 1) {
  7977. callWithAsyncErrorHandling(patchStopImmediatePropagation(e, invoker.value), instance, 5 /* NATIVE_EVENT_HANDLER */, [e]);
  7978. }
  7979. };
  7980. invoker.value = initialValue;
  7981. invoker.attached = getNow();
  7982. return invoker;
  7983. }
  7984. function patchStopImmediatePropagation(e, value) {
  7985. if (isArray(value)) {
  7986. const originalStop = e.stopImmediatePropagation;
  7987. e.stopImmediatePropagation = () => {
  7988. originalStop.call(e);
  7989. e._stopped = true;
  7990. };
  7991. return value.map(fn => (e) => !e._stopped && fn(e));
  7992. }
  7993. else {
  7994. return value;
  7995. }
  7996. }
  7997. const nativeOnRE = /^on[a-z]/;
  7998. const forcePatchProp = (_, key) => key === 'value';
  7999. const patchProp = (el, key, prevValue, nextValue, isSVG = false, prevChildren, parentComponent, parentSuspense, unmountChildren) => {
  8000. switch (key) {
  8001. // special
  8002. case 'class':
  8003. patchClass(el, nextValue, isSVG);
  8004. break;
  8005. case 'style':
  8006. patchStyle(el, prevValue, nextValue);
  8007. break;
  8008. default:
  8009. if (isOn(key)) {
  8010. // ignore v-model listeners
  8011. if (!isModelListener(key)) {
  8012. patchEvent(el, key, prevValue, nextValue, parentComponent);
  8013. }
  8014. }
  8015. else if (shouldSetAsProp(el, key, nextValue, isSVG)) {
  8016. patchDOMProp(el, key, nextValue, prevChildren, parentComponent, parentSuspense, unmountChildren);
  8017. }
  8018. else {
  8019. // special case for <input v-model type="checkbox"> with
  8020. // :true-value & :false-value
  8021. // store value as dom properties since non-string values will be
  8022. // stringified.
  8023. if (key === 'true-value') {
  8024. el._trueValue = nextValue;
  8025. }
  8026. else if (key === 'false-value') {
  8027. el._falseValue = nextValue;
  8028. }
  8029. patchAttr(el, key, nextValue, isSVG);
  8030. }
  8031. break;
  8032. }
  8033. };
  8034. function shouldSetAsProp(el, key, value, isSVG) {
  8035. if (isSVG) {
  8036. // most keys must be set as attribute on svg elements to work
  8037. // ...except innerHTML
  8038. if (key === 'innerHTML') {
  8039. return true;
  8040. }
  8041. // or native onclick with function values
  8042. if (key in el && nativeOnRE.test(key) && isFunction(value)) {
  8043. return true;
  8044. }
  8045. return false;
  8046. }
  8047. // spellcheck and draggable are numerated attrs, however their
  8048. // corresponding DOM properties are actually booleans - this leads to
  8049. // setting it with a string "false" value leading it to be coerced to
  8050. // `true`, so we need to always treat them as attributes.
  8051. // Note that `contentEditable` doesn't have this problem: its DOM
  8052. // property is also enumerated string values.
  8053. if (key === 'spellcheck' || key === 'draggable') {
  8054. return false;
  8055. }
  8056. // #1787 form as an attribute must be a string, while it accepts an Element as
  8057. // a prop
  8058. if (key === 'form' && typeof value === 'string') {
  8059. return false;
  8060. }
  8061. // #1526 <input list> must be set as attribute
  8062. if (key === 'list' && el.tagName === 'INPUT') {
  8063. return false;
  8064. }
  8065. // native onclick with string value, must be set as attribute
  8066. if (nativeOnRE.test(key) && isString(value)) {
  8067. return false;
  8068. }
  8069. return key in el;
  8070. }
  8071. function useCssModule(name = '$style') {
  8072. /* istanbul ignore else */
  8073. {
  8074. {
  8075. warn(`useCssModule() is not supported in the global build.`);
  8076. }
  8077. return EMPTY_OBJ;
  8078. }
  8079. }
  8080. function useCssVars(getter, scoped = false) {
  8081. const instance = getCurrentInstance();
  8082. /* istanbul ignore next */
  8083. if (!instance) {
  8084. warn(`useCssVars is called without current active component instance.`);
  8085. return;
  8086. }
  8087. const prefix = scoped && instance.type.__scopeId
  8088. ? `${instance.type.__scopeId.replace(/^data-v-/, '')}-`
  8089. : ``;
  8090. onMounted(() => {
  8091. watchEffect(() => {
  8092. setVarsOnVNode(instance.subTree, getter(instance.proxy), prefix);
  8093. });
  8094. });
  8095. }
  8096. function setVarsOnVNode(vnode, vars, prefix) {
  8097. if ( vnode.shapeFlag & 128 /* SUSPENSE */) {
  8098. const suspense = vnode.suspense;
  8099. vnode = suspense.activeBranch;
  8100. if (suspense.pendingBranch && !suspense.isHydrating) {
  8101. suspense.effects.push(() => {
  8102. setVarsOnVNode(suspense.activeBranch, vars, prefix);
  8103. });
  8104. }
  8105. }
  8106. // drill down HOCs until it's a non-component vnode
  8107. while (vnode.component) {
  8108. vnode = vnode.component.subTree;
  8109. }
  8110. if (vnode.shapeFlag & 1 /* ELEMENT */ && vnode.el) {
  8111. const style = vnode.el.style;
  8112. for (const key in vars) {
  8113. style.setProperty(`--${prefix}${key}`, unref(vars[key]));
  8114. }
  8115. }
  8116. else if (vnode.type === Fragment) {
  8117. vnode.children.forEach(c => setVarsOnVNode(c, vars, prefix));
  8118. }
  8119. }
  8120. const TRANSITION = 'transition';
  8121. const ANIMATION = 'animation';
  8122. // DOM Transition is a higher-order-component based on the platform-agnostic
  8123. // base Transition component, with DOM-specific logic.
  8124. const Transition = (props, { slots }) => h(BaseTransition, resolveTransitionProps(props), slots);
  8125. Transition.displayName = 'Transition';
  8126. const DOMTransitionPropsValidators = {
  8127. name: String,
  8128. type: String,
  8129. css: {
  8130. type: Boolean,
  8131. default: true
  8132. },
  8133. duration: [String, Number, Object],
  8134. enterFromClass: String,
  8135. enterActiveClass: String,
  8136. enterToClass: String,
  8137. appearFromClass: String,
  8138. appearActiveClass: String,
  8139. appearToClass: String,
  8140. leaveFromClass: String,
  8141. leaveActiveClass: String,
  8142. leaveToClass: String
  8143. };
  8144. const TransitionPropsValidators = (Transition.props = /*#__PURE__*/ extend({}, BaseTransition.props, DOMTransitionPropsValidators));
  8145. function resolveTransitionProps(rawProps) {
  8146. let { name = 'v', type, css = true, duration, enterFromClass = `${name}-enter-from`, enterActiveClass = `${name}-enter-active`, enterToClass = `${name}-enter-to`, appearFromClass = enterFromClass, appearActiveClass = enterActiveClass, appearToClass = enterToClass, leaveFromClass = `${name}-leave-from`, leaveActiveClass = `${name}-leave-active`, leaveToClass = `${name}-leave-to` } = rawProps;
  8147. const baseProps = {};
  8148. for (const key in rawProps) {
  8149. if (!(key in DOMTransitionPropsValidators)) {
  8150. baseProps[key] = rawProps[key];
  8151. }
  8152. }
  8153. if (!css) {
  8154. return baseProps;
  8155. }
  8156. const durations = normalizeDuration(duration);
  8157. const enterDuration = durations && durations[0];
  8158. const leaveDuration = durations && durations[1];
  8159. const { onBeforeEnter, onEnter, onEnterCancelled, onLeave, onLeaveCancelled, onBeforeAppear = onBeforeEnter, onAppear = onEnter, onAppearCancelled = onEnterCancelled } = baseProps;
  8160. const finishEnter = (el, isAppear, done) => {
  8161. removeTransitionClass(el, isAppear ? appearToClass : enterToClass);
  8162. removeTransitionClass(el, isAppear ? appearActiveClass : enterActiveClass);
  8163. done && done();
  8164. };
  8165. const finishLeave = (el, done) => {
  8166. removeTransitionClass(el, leaveToClass);
  8167. removeTransitionClass(el, leaveActiveClass);
  8168. done && done();
  8169. };
  8170. const makeEnterHook = (isAppear) => {
  8171. return (el, done) => {
  8172. const hook = isAppear ? onAppear : onEnter;
  8173. const resolve = () => finishEnter(el, isAppear, done);
  8174. hook && hook(el, resolve);
  8175. nextFrame(() => {
  8176. removeTransitionClass(el, isAppear ? appearFromClass : enterFromClass);
  8177. addTransitionClass(el, isAppear ? appearToClass : enterToClass);
  8178. if (!(hook && hook.length > 1)) {
  8179. if (enterDuration) {
  8180. setTimeout(resolve, enterDuration);
  8181. }
  8182. else {
  8183. whenTransitionEnds(el, type, resolve);
  8184. }
  8185. }
  8186. });
  8187. };
  8188. };
  8189. return extend(baseProps, {
  8190. onBeforeEnter(el) {
  8191. onBeforeEnter && onBeforeEnter(el);
  8192. addTransitionClass(el, enterActiveClass);
  8193. addTransitionClass(el, enterFromClass);
  8194. },
  8195. onBeforeAppear(el) {
  8196. onBeforeAppear && onBeforeAppear(el);
  8197. addTransitionClass(el, appearActiveClass);
  8198. addTransitionClass(el, appearFromClass);
  8199. },
  8200. onEnter: makeEnterHook(false),
  8201. onAppear: makeEnterHook(true),
  8202. onLeave(el, done) {
  8203. const resolve = () => finishLeave(el, done);
  8204. addTransitionClass(el, leaveActiveClass);
  8205. addTransitionClass(el, leaveFromClass);
  8206. nextFrame(() => {
  8207. removeTransitionClass(el, leaveFromClass);
  8208. addTransitionClass(el, leaveToClass);
  8209. if (!(onLeave && onLeave.length > 1)) {
  8210. if (leaveDuration) {
  8211. setTimeout(resolve, leaveDuration);
  8212. }
  8213. else {
  8214. whenTransitionEnds(el, type, resolve);
  8215. }
  8216. }
  8217. });
  8218. onLeave && onLeave(el, resolve);
  8219. },
  8220. onEnterCancelled(el) {
  8221. finishEnter(el, false);
  8222. onEnterCancelled && onEnterCancelled(el);
  8223. },
  8224. onAppearCancelled(el) {
  8225. finishEnter(el, true);
  8226. onAppearCancelled && onAppearCancelled(el);
  8227. },
  8228. onLeaveCancelled(el) {
  8229. finishLeave(el);
  8230. onLeaveCancelled && onLeaveCancelled(el);
  8231. }
  8232. });
  8233. }
  8234. function normalizeDuration(duration) {
  8235. if (duration == null) {
  8236. return null;
  8237. }
  8238. else if (isObject(duration)) {
  8239. return [NumberOf(duration.enter), NumberOf(duration.leave)];
  8240. }
  8241. else {
  8242. const n = NumberOf(duration);
  8243. return [n, n];
  8244. }
  8245. }
  8246. function NumberOf(val) {
  8247. const res = toNumber(val);
  8248. validateDuration(res);
  8249. return res;
  8250. }
  8251. function validateDuration(val) {
  8252. if (typeof val !== 'number') {
  8253. warn(`<transition> explicit duration is not a valid number - ` +
  8254. `got ${JSON.stringify(val)}.`);
  8255. }
  8256. else if (isNaN(val)) {
  8257. warn(`<transition> explicit duration is NaN - ` +
  8258. 'the duration expression might be incorrect.');
  8259. }
  8260. }
  8261. function addTransitionClass(el, cls) {
  8262. cls.split(/\s+/).forEach(c => c && el.classList.add(c));
  8263. (el._vtc ||
  8264. (el._vtc = new Set())).add(cls);
  8265. }
  8266. function removeTransitionClass(el, cls) {
  8267. cls.split(/\s+/).forEach(c => c && el.classList.remove(c));
  8268. const { _vtc } = el;
  8269. if (_vtc) {
  8270. _vtc.delete(cls);
  8271. if (!_vtc.size) {
  8272. el._vtc = undefined;
  8273. }
  8274. }
  8275. }
  8276. function nextFrame(cb) {
  8277. requestAnimationFrame(() => {
  8278. requestAnimationFrame(cb);
  8279. });
  8280. }
  8281. function whenTransitionEnds(el, expectedType, cb) {
  8282. const { type, timeout, propCount } = getTransitionInfo(el, expectedType);
  8283. if (!type) {
  8284. return cb();
  8285. }
  8286. const endEvent = type + 'end';
  8287. let ended = 0;
  8288. const end = () => {
  8289. el.removeEventListener(endEvent, onEnd);
  8290. cb();
  8291. };
  8292. const onEnd = (e) => {
  8293. if (e.target === el) {
  8294. if (++ended >= propCount) {
  8295. end();
  8296. }
  8297. }
  8298. };
  8299. setTimeout(() => {
  8300. if (ended < propCount) {
  8301. end();
  8302. }
  8303. }, timeout + 1);
  8304. el.addEventListener(endEvent, onEnd);
  8305. }
  8306. function getTransitionInfo(el, expectedType) {
  8307. const styles = window.getComputedStyle(el);
  8308. // JSDOM may return undefined for transition properties
  8309. const getStyleProperties = (key) => (styles[key] || '').split(', ');
  8310. const transitionDelays = getStyleProperties(TRANSITION + 'Delay');
  8311. const transitionDurations = getStyleProperties(TRANSITION + 'Duration');
  8312. const transitionTimeout = getTimeout(transitionDelays, transitionDurations);
  8313. const animationDelays = getStyleProperties(ANIMATION + 'Delay');
  8314. const animationDurations = getStyleProperties(ANIMATION + 'Duration');
  8315. const animationTimeout = getTimeout(animationDelays, animationDurations);
  8316. let type = null;
  8317. let timeout = 0;
  8318. let propCount = 0;
  8319. /* istanbul ignore if */
  8320. if (expectedType === TRANSITION) {
  8321. if (transitionTimeout > 0) {
  8322. type = TRANSITION;
  8323. timeout = transitionTimeout;
  8324. propCount = transitionDurations.length;
  8325. }
  8326. }
  8327. else if (expectedType === ANIMATION) {
  8328. if (animationTimeout > 0) {
  8329. type = ANIMATION;
  8330. timeout = animationTimeout;
  8331. propCount = animationDurations.length;
  8332. }
  8333. }
  8334. else {
  8335. timeout = Math.max(transitionTimeout, animationTimeout);
  8336. type =
  8337. timeout > 0
  8338. ? transitionTimeout > animationTimeout
  8339. ? TRANSITION
  8340. : ANIMATION
  8341. : null;
  8342. propCount = type
  8343. ? type === TRANSITION
  8344. ? transitionDurations.length
  8345. : animationDurations.length
  8346. : 0;
  8347. }
  8348. const hasTransform = type === TRANSITION &&
  8349. /\b(transform|all)(,|$)/.test(styles[TRANSITION + 'Property']);
  8350. return {
  8351. type,
  8352. timeout,
  8353. propCount,
  8354. hasTransform
  8355. };
  8356. }
  8357. function getTimeout(delays, durations) {
  8358. while (delays.length < durations.length) {
  8359. delays = delays.concat(delays);
  8360. }
  8361. return Math.max(...durations.map((d, i) => toMs(d) + toMs(delays[i])));
  8362. }
  8363. // Old versions of Chromium (below 61.0.3163.100) formats floating pointer
  8364. // numbers in a locale-dependent way, using a comma instead of a dot.
  8365. // If comma is not replaced with a dot, the input will be rounded down
  8366. // (i.e. acting as a floor function) causing unexpected behaviors
  8367. function toMs(s) {
  8368. return Number(s.slice(0, -1).replace(',', '.')) * 1000;
  8369. }
  8370. const positionMap = new WeakMap();
  8371. const newPositionMap = new WeakMap();
  8372. const TransitionGroupImpl = {
  8373. name: 'TransitionGroup',
  8374. props: /*#__PURE__*/ extend({}, TransitionPropsValidators, {
  8375. tag: String,
  8376. moveClass: String
  8377. }),
  8378. setup(props, { slots }) {
  8379. const instance = getCurrentInstance();
  8380. const state = useTransitionState();
  8381. let prevChildren;
  8382. let children;
  8383. onUpdated(() => {
  8384. // children is guaranteed to exist after initial render
  8385. if (!prevChildren.length) {
  8386. return;
  8387. }
  8388. const moveClass = props.moveClass || `${props.name || 'v'}-move`;
  8389. if (!hasCSSTransform(prevChildren[0].el, instance.vnode.el, moveClass)) {
  8390. return;
  8391. }
  8392. // we divide the work into three loops to avoid mixing DOM reads and writes
  8393. // in each iteration - which helps prevent layout thrashing.
  8394. prevChildren.forEach(callPendingCbs);
  8395. prevChildren.forEach(recordPosition);
  8396. const movedChildren = prevChildren.filter(applyTranslation);
  8397. // force reflow to put everything in position
  8398. forceReflow();
  8399. movedChildren.forEach(c => {
  8400. const el = c.el;
  8401. const style = el.style;
  8402. addTransitionClass(el, moveClass);
  8403. style.transform = style.webkitTransform = style.transitionDuration = '';
  8404. const cb = (el._moveCb = (e) => {
  8405. if (e && e.target !== el) {
  8406. return;
  8407. }
  8408. if (!e || /transform$/.test(e.propertyName)) {
  8409. el.removeEventListener('transitionend', cb);
  8410. el._moveCb = null;
  8411. removeTransitionClass(el, moveClass);
  8412. }
  8413. });
  8414. el.addEventListener('transitionend', cb);
  8415. });
  8416. });
  8417. return () => {
  8418. const rawProps = toRaw(props);
  8419. const cssTransitionProps = resolveTransitionProps(rawProps);
  8420. const tag = rawProps.tag || Fragment;
  8421. prevChildren = children;
  8422. children = slots.default ? getTransitionRawChildren(slots.default()) : [];
  8423. for (let i = 0; i < children.length; i++) {
  8424. const child = children[i];
  8425. if (child.key != null) {
  8426. setTransitionHooks(child, resolveTransitionHooks(child, cssTransitionProps, state, instance));
  8427. }
  8428. else {
  8429. warn(`<TransitionGroup> children must be keyed.`);
  8430. }
  8431. }
  8432. if (prevChildren) {
  8433. for (let i = 0; i < prevChildren.length; i++) {
  8434. const child = prevChildren[i];
  8435. setTransitionHooks(child, resolveTransitionHooks(child, cssTransitionProps, state, instance));
  8436. positionMap.set(child, child.el.getBoundingClientRect());
  8437. }
  8438. }
  8439. return createVNode(tag, null, children);
  8440. };
  8441. }
  8442. };
  8443. const TransitionGroup = TransitionGroupImpl;
  8444. function callPendingCbs(c) {
  8445. const el = c.el;
  8446. if (el._moveCb) {
  8447. el._moveCb();
  8448. }
  8449. if (el._enterCb) {
  8450. el._enterCb();
  8451. }
  8452. }
  8453. function recordPosition(c) {
  8454. newPositionMap.set(c, c.el.getBoundingClientRect());
  8455. }
  8456. function applyTranslation(c) {
  8457. const oldPos = positionMap.get(c);
  8458. const newPos = newPositionMap.get(c);
  8459. const dx = oldPos.left - newPos.left;
  8460. const dy = oldPos.top - newPos.top;
  8461. if (dx || dy) {
  8462. const s = c.el.style;
  8463. s.transform = s.webkitTransform = `translate(${dx}px,${dy}px)`;
  8464. s.transitionDuration = '0s';
  8465. return c;
  8466. }
  8467. }
  8468. // this is put in a dedicated function to avoid the line from being treeshaken
  8469. function forceReflow() {
  8470. return document.body.offsetHeight;
  8471. }
  8472. function hasCSSTransform(el, root, moveClass) {
  8473. // Detect whether an element with the move class applied has
  8474. // CSS transitions. Since the element may be inside an entering
  8475. // transition at this very moment, we make a clone of it and remove
  8476. // all other transition classes applied to ensure only the move class
  8477. // is applied.
  8478. const clone = el.cloneNode();
  8479. if (el._vtc) {
  8480. el._vtc.forEach(cls => {
  8481. cls.split(/\s+/).forEach(c => c && clone.classList.remove(c));
  8482. });
  8483. }
  8484. moveClass.split(/\s+/).forEach(c => c && clone.classList.add(c));
  8485. clone.style.display = 'none';
  8486. const container = (root.nodeType === 1
  8487. ? root
  8488. : root.parentNode);
  8489. container.appendChild(clone);
  8490. const { hasTransform } = getTransitionInfo(clone);
  8491. container.removeChild(clone);
  8492. return hasTransform;
  8493. }
  8494. const getModelAssigner = (vnode) => {
  8495. const fn = vnode.props['onUpdate:modelValue'];
  8496. return isArray(fn) ? value => invokeArrayFns(fn, value) : fn;
  8497. };
  8498. function onCompositionStart(e) {
  8499. e.target.composing = true;
  8500. }
  8501. function onCompositionEnd(e) {
  8502. const target = e.target;
  8503. if (target.composing) {
  8504. target.composing = false;
  8505. trigger$1(target, 'input');
  8506. }
  8507. }
  8508. function trigger$1(el, type) {
  8509. const e = document.createEvent('HTMLEvents');
  8510. e.initEvent(type, true, true);
  8511. el.dispatchEvent(e);
  8512. }
  8513. // We are exporting the v-model runtime directly as vnode hooks so that it can
  8514. // be tree-shaken in case v-model is never used.
  8515. const vModelText = {
  8516. created(el, { value, modifiers: { lazy, trim, number } }, vnode) {
  8517. el.value = value == null ? '' : value;
  8518. el._assign = getModelAssigner(vnode);
  8519. const castToNumber = number || el.type === 'number';
  8520. addEventListener(el, lazy ? 'change' : 'input', e => {
  8521. if (e.target.composing)
  8522. return;
  8523. let domValue = el.value;
  8524. if (trim) {
  8525. domValue = domValue.trim();
  8526. }
  8527. else if (castToNumber) {
  8528. domValue = toNumber(domValue);
  8529. }
  8530. el._assign(domValue);
  8531. });
  8532. if (trim) {
  8533. addEventListener(el, 'change', () => {
  8534. el.value = el.value.trim();
  8535. });
  8536. }
  8537. if (!lazy) {
  8538. addEventListener(el, 'compositionstart', onCompositionStart);
  8539. addEventListener(el, 'compositionend', onCompositionEnd);
  8540. // Safari < 10.2 & UIWebView doesn't fire compositionend when
  8541. // switching focus before confirming composition choice
  8542. // this also fixes the issue where some browsers e.g. iOS Chrome
  8543. // fires "change" instead of "input" on autocomplete.
  8544. addEventListener(el, 'change', onCompositionEnd);
  8545. }
  8546. },
  8547. beforeUpdate(el, { value, modifiers: { trim, number } }, vnode) {
  8548. el._assign = getModelAssigner(vnode);
  8549. if (document.activeElement === el) {
  8550. if (trim && el.value.trim() === value) {
  8551. return;
  8552. }
  8553. if ((number || el.type === 'number') && toNumber(el.value) === value) {
  8554. return;
  8555. }
  8556. }
  8557. const newValue = value == null ? '' : value;
  8558. if (el.value !== newValue) {
  8559. el.value = newValue;
  8560. }
  8561. }
  8562. };
  8563. const vModelCheckbox = {
  8564. created(el, binding, vnode) {
  8565. setChecked(el, binding, vnode);
  8566. el._assign = getModelAssigner(vnode);
  8567. addEventListener(el, 'change', () => {
  8568. const modelValue = el._modelValue;
  8569. const elementValue = getValue(el);
  8570. const checked = el.checked;
  8571. const assign = el._assign;
  8572. if (isArray(modelValue)) {
  8573. const index = looseIndexOf(modelValue, elementValue);
  8574. const found = index !== -1;
  8575. if (checked && !found) {
  8576. assign(modelValue.concat(elementValue));
  8577. }
  8578. else if (!checked && found) {
  8579. const filtered = [...modelValue];
  8580. filtered.splice(index, 1);
  8581. assign(filtered);
  8582. }
  8583. }
  8584. else if (isSet(modelValue)) {
  8585. const found = modelValue.has(elementValue);
  8586. if (checked && !found) {
  8587. assign(modelValue.add(elementValue));
  8588. }
  8589. else if (!checked && found) {
  8590. modelValue.delete(elementValue);
  8591. assign(modelValue);
  8592. }
  8593. }
  8594. else {
  8595. assign(getCheckboxValue(el, checked));
  8596. }
  8597. });
  8598. },
  8599. beforeUpdate(el, binding, vnode) {
  8600. el._assign = getModelAssigner(vnode);
  8601. setChecked(el, binding, vnode);
  8602. }
  8603. };
  8604. function setChecked(el, { value, oldValue }, vnode) {
  8605. el._modelValue = value;
  8606. if (isArray(value)) {
  8607. el.checked = looseIndexOf(value, vnode.props.value) > -1;
  8608. }
  8609. else if (isSet(value)) {
  8610. el.checked = looseHas(value, vnode.props.value);
  8611. }
  8612. else if (value !== oldValue) {
  8613. el.checked = looseEqual(value, getCheckboxValue(el, true));
  8614. }
  8615. }
  8616. const vModelRadio = {
  8617. created(el, { value }, vnode) {
  8618. el.checked = looseEqual(value, vnode.props.value);
  8619. el._assign = getModelAssigner(vnode);
  8620. addEventListener(el, 'change', () => {
  8621. el._assign(getValue(el));
  8622. });
  8623. },
  8624. beforeUpdate(el, { value, oldValue }, vnode) {
  8625. el._assign = getModelAssigner(vnode);
  8626. if (value !== oldValue) {
  8627. el.checked = looseEqual(value, vnode.props.value);
  8628. }
  8629. }
  8630. };
  8631. const vModelSelect = {
  8632. created(el, binding, vnode) {
  8633. addEventListener(el, 'change', () => {
  8634. const selectedVal = Array.prototype.filter
  8635. .call(el.options, (o) => o.selected)
  8636. .map(getValue);
  8637. el._assign(el.multiple ? selectedVal : selectedVal[0]);
  8638. });
  8639. el._assign = getModelAssigner(vnode);
  8640. },
  8641. // set value in mounted & updated because <select> relies on its children
  8642. // <option>s.
  8643. mounted(el, { value }) {
  8644. setSelected(el, value);
  8645. },
  8646. beforeUpdate(el, _binding, vnode) {
  8647. el._assign = getModelAssigner(vnode);
  8648. },
  8649. updated(el, { value }) {
  8650. setSelected(el, value);
  8651. }
  8652. };
  8653. function setSelected(el, value) {
  8654. const isMultiple = el.multiple;
  8655. if (isMultiple && !isArray(value) && !isSet(value)) {
  8656. warn(`<select multiple v-model> expects an Array or Set value for its binding, ` +
  8657. `but got ${Object.prototype.toString.call(value).slice(8, -1)}.`);
  8658. return;
  8659. }
  8660. for (let i = 0, l = el.options.length; i < l; i++) {
  8661. const option = el.options[i];
  8662. const optionValue = getValue(option);
  8663. if (isMultiple) {
  8664. if (isArray(value)) {
  8665. option.selected = looseIndexOf(value, optionValue) > -1;
  8666. }
  8667. else {
  8668. option.selected = looseHas(value, optionValue);
  8669. }
  8670. }
  8671. else {
  8672. if (looseEqual(getValue(option), value)) {
  8673. el.selectedIndex = i;
  8674. return;
  8675. }
  8676. }
  8677. }
  8678. if (!isMultiple) {
  8679. el.selectedIndex = -1;
  8680. }
  8681. }
  8682. // retrieve raw value set via :value bindings
  8683. function getValue(el) {
  8684. return '_value' in el ? el._value : el.value;
  8685. }
  8686. // retrieve raw value for true-value and false-value set via :true-value or :false-value bindings
  8687. function getCheckboxValue(el, checked) {
  8688. const key = checked ? '_trueValue' : '_falseValue';
  8689. return key in el ? el[key] : checked;
  8690. }
  8691. const vModelDynamic = {
  8692. created(el, binding, vnode) {
  8693. callModelHook(el, binding, vnode, null, 'created');
  8694. },
  8695. mounted(el, binding, vnode) {
  8696. callModelHook(el, binding, vnode, null, 'mounted');
  8697. },
  8698. beforeUpdate(el, binding, vnode, prevVNode) {
  8699. callModelHook(el, binding, vnode, prevVNode, 'beforeUpdate');
  8700. },
  8701. updated(el, binding, vnode, prevVNode) {
  8702. callModelHook(el, binding, vnode, prevVNode, 'updated');
  8703. }
  8704. };
  8705. function callModelHook(el, binding, vnode, prevVNode, hook) {
  8706. let modelToUse;
  8707. switch (el.tagName) {
  8708. case 'SELECT':
  8709. modelToUse = vModelSelect;
  8710. break;
  8711. case 'TEXTAREA':
  8712. modelToUse = vModelText;
  8713. break;
  8714. default:
  8715. switch (vnode.props && vnode.props.type) {
  8716. case 'checkbox':
  8717. modelToUse = vModelCheckbox;
  8718. break;
  8719. case 'radio':
  8720. modelToUse = vModelRadio;
  8721. break;
  8722. default:
  8723. modelToUse = vModelText;
  8724. }
  8725. }
  8726. const fn = modelToUse[hook];
  8727. fn && fn(el, binding, vnode, prevVNode);
  8728. }
  8729. const systemModifiers = ['ctrl', 'shift', 'alt', 'meta'];
  8730. const modifierGuards = {
  8731. stop: e => e.stopPropagation(),
  8732. prevent: e => e.preventDefault(),
  8733. self: e => e.target !== e.currentTarget,
  8734. ctrl: e => !e.ctrlKey,
  8735. shift: e => !e.shiftKey,
  8736. alt: e => !e.altKey,
  8737. meta: e => !e.metaKey,
  8738. left: e => 'button' in e && e.button !== 0,
  8739. middle: e => 'button' in e && e.button !== 1,
  8740. right: e => 'button' in e && e.button !== 2,
  8741. exact: (e, modifiers) => systemModifiers.some(m => e[`${m}Key`] && !modifiers.includes(m))
  8742. };
  8743. /**
  8744. * @private
  8745. */
  8746. const withModifiers = (fn, modifiers) => {
  8747. return (event, ...args) => {
  8748. for (let i = 0; i < modifiers.length; i++) {
  8749. const guard = modifierGuards[modifiers[i]];
  8750. if (guard && guard(event, modifiers))
  8751. return;
  8752. }
  8753. return fn(event, ...args);
  8754. };
  8755. };
  8756. // Kept for 2.x compat.
  8757. // Note: IE11 compat for `spacebar` and `del` is removed for now.
  8758. const keyNames = {
  8759. esc: 'escape',
  8760. space: ' ',
  8761. up: 'arrow-up',
  8762. left: 'arrow-left',
  8763. right: 'arrow-right',
  8764. down: 'arrow-down',
  8765. delete: 'backspace'
  8766. };
  8767. /**
  8768. * @private
  8769. */
  8770. const withKeys = (fn, modifiers) => {
  8771. return (event) => {
  8772. if (!('key' in event))
  8773. return;
  8774. const eventKey = hyphenate(event.key);
  8775. if (
  8776. // None of the provided key modifiers match the current event key
  8777. !modifiers.some(k => k === eventKey || keyNames[k] === eventKey)) {
  8778. return;
  8779. }
  8780. return fn(event);
  8781. };
  8782. };
  8783. const vShow = {
  8784. beforeMount(el, { value }, { transition }) {
  8785. el._vod = el.style.display === 'none' ? '' : el.style.display;
  8786. if (transition && value) {
  8787. transition.beforeEnter(el);
  8788. }
  8789. else {
  8790. setDisplay(el, value);
  8791. }
  8792. },
  8793. mounted(el, { value }, { transition }) {
  8794. if (transition && value) {
  8795. transition.enter(el);
  8796. }
  8797. },
  8798. updated(el, { value, oldValue }, { transition }) {
  8799. if (!value === !oldValue)
  8800. return;
  8801. if (transition) {
  8802. if (value) {
  8803. transition.beforeEnter(el);
  8804. setDisplay(el, true);
  8805. transition.enter(el);
  8806. }
  8807. else {
  8808. transition.leave(el, () => {
  8809. setDisplay(el, false);
  8810. });
  8811. }
  8812. }
  8813. else {
  8814. setDisplay(el, value);
  8815. }
  8816. },
  8817. beforeUnmount(el, { value }) {
  8818. setDisplay(el, value);
  8819. }
  8820. };
  8821. function setDisplay(el, value) {
  8822. el.style.display = value ? el._vod : 'none';
  8823. }
  8824. const rendererOptions = extend({ patchProp, forcePatchProp }, nodeOps);
  8825. // lazy create the renderer - this makes core renderer logic tree-shakable
  8826. // in case the user only imports reactivity utilities from Vue.
  8827. let renderer;
  8828. let enabledHydration = false;
  8829. function ensureRenderer() {
  8830. return renderer || (renderer = createRenderer(rendererOptions));
  8831. }
  8832. function ensureHydrationRenderer() {
  8833. renderer = enabledHydration
  8834. ? renderer
  8835. : createHydrationRenderer(rendererOptions);
  8836. enabledHydration = true;
  8837. return renderer;
  8838. }
  8839. // use explicit type casts here to avoid import() calls in rolled-up d.ts
  8840. const render = ((...args) => {
  8841. ensureRenderer().render(...args);
  8842. });
  8843. const hydrate = ((...args) => {
  8844. ensureHydrationRenderer().hydrate(...args);
  8845. });
  8846. const createApp = ((...args) => {
  8847. const app = ensureRenderer().createApp(...args);
  8848. {
  8849. injectNativeTagCheck(app);
  8850. }
  8851. const { mount } = app;
  8852. app.mount = (containerOrSelector) => {
  8853. const container = normalizeContainer(containerOrSelector);
  8854. if (!container)
  8855. return;
  8856. const component = app._component;
  8857. if (!isFunction(component) && !component.render && !component.template) {
  8858. component.template = container.innerHTML;
  8859. }
  8860. // clear content before mounting
  8861. container.innerHTML = '';
  8862. const proxy = mount(container);
  8863. container.removeAttribute('v-cloak');
  8864. container.setAttribute('data-v-app', '');
  8865. return proxy;
  8866. };
  8867. return app;
  8868. });
  8869. const createSSRApp = ((...args) => {
  8870. const app = ensureHydrationRenderer().createApp(...args);
  8871. {
  8872. injectNativeTagCheck(app);
  8873. }
  8874. const { mount } = app;
  8875. app.mount = (containerOrSelector) => {
  8876. const container = normalizeContainer(containerOrSelector);
  8877. if (container) {
  8878. return mount(container, true);
  8879. }
  8880. };
  8881. return app;
  8882. });
  8883. function injectNativeTagCheck(app) {
  8884. // Inject `isNativeTag`
  8885. // this is used for component name validation (dev only)
  8886. Object.defineProperty(app.config, 'isNativeTag', {
  8887. value: (tag) => isHTMLTag(tag) || isSVGTag(tag),
  8888. writable: false
  8889. });
  8890. }
  8891. function normalizeContainer(container) {
  8892. if (isString(container)) {
  8893. const res = document.querySelector(container);
  8894. if ( !res) {
  8895. warn(`Failed to mount app: mount target selector returned null.`);
  8896. }
  8897. return res;
  8898. }
  8899. return container;
  8900. }
  8901. function initDev() {
  8902. const target = getGlobalThis();
  8903. target.__VUE__ = true;
  8904. setDevtoolsHook(target.__VUE_DEVTOOLS_GLOBAL_HOOK__);
  8905. {
  8906. console.info(`You are running a development build of Vue.\n` +
  8907. `Make sure to use the production build (*.prod.js) when deploying for production.`);
  8908. }
  8909. }
  8910. function defaultOnError(error) {
  8911. throw error;
  8912. }
  8913. function createCompilerError(code, loc, messages, additionalMessage) {
  8914. const msg = (messages || errorMessages)[code] + (additionalMessage || ``)
  8915. ;
  8916. const error = new SyntaxError(String(msg));
  8917. error.code = code;
  8918. error.loc = loc;
  8919. return error;
  8920. }
  8921. const errorMessages = {
  8922. // parse errors
  8923. [0 /* ABRUPT_CLOSING_OF_EMPTY_COMMENT */]: 'Illegal comment.',
  8924. [1 /* CDATA_IN_HTML_CONTENT */]: 'CDATA section is allowed only in XML context.',
  8925. [2 /* DUPLICATE_ATTRIBUTE */]: 'Duplicate attribute.',
  8926. [3 /* END_TAG_WITH_ATTRIBUTES */]: 'End tag cannot have attributes.',
  8927. [4 /* END_TAG_WITH_TRAILING_SOLIDUS */]: "Illegal '/' in tags.",
  8928. [5 /* EOF_BEFORE_TAG_NAME */]: 'Unexpected EOF in tag.',
  8929. [6 /* EOF_IN_CDATA */]: 'Unexpected EOF in CDATA section.',
  8930. [7 /* EOF_IN_COMMENT */]: 'Unexpected EOF in comment.',
  8931. [8 /* EOF_IN_SCRIPT_HTML_COMMENT_LIKE_TEXT */]: 'Unexpected EOF in script.',
  8932. [9 /* EOF_IN_TAG */]: 'Unexpected EOF in tag.',
  8933. [10 /* INCORRECTLY_CLOSED_COMMENT */]: 'Incorrectly closed comment.',
  8934. [11 /* INCORRECTLY_OPENED_COMMENT */]: 'Incorrectly opened comment.',
  8935. [12 /* INVALID_FIRST_CHARACTER_OF_TAG_NAME */]: "Illegal tag name. Use '&lt;' to print '<'.",
  8936. [13 /* MISSING_ATTRIBUTE_VALUE */]: 'Attribute value was expected.',
  8937. [14 /* MISSING_END_TAG_NAME */]: 'End tag name was expected.',
  8938. [15 /* MISSING_WHITESPACE_BETWEEN_ATTRIBUTES */]: 'Whitespace was expected.',
  8939. [16 /* NESTED_COMMENT */]: "Unexpected '<!--' in comment.",
  8940. [17 /* UNEXPECTED_CHARACTER_IN_ATTRIBUTE_NAME */]: 'Attribute name cannot contain U+0022 ("), U+0027 (\'), and U+003C (<).',
  8941. [18 /* UNEXPECTED_CHARACTER_IN_UNQUOTED_ATTRIBUTE_VALUE */]: 'Unquoted attribute value cannot contain U+0022 ("), U+0027 (\'), U+003C (<), U+003D (=), and U+0060 (`).',
  8942. [19 /* UNEXPECTED_EQUALS_SIGN_BEFORE_ATTRIBUTE_NAME */]: "Attribute name cannot start with '='.",
  8943. [21 /* UNEXPECTED_QUESTION_MARK_INSTEAD_OF_TAG_NAME */]: "'<?' is allowed only in XML context.",
  8944. [22 /* UNEXPECTED_SOLIDUS_IN_TAG */]: "Illegal '/' in tags.",
  8945. // Vue-specific parse errors
  8946. [23 /* X_INVALID_END_TAG */]: 'Invalid end tag.',
  8947. [24 /* X_MISSING_END_TAG */]: 'Element is missing end tag.',
  8948. [25 /* X_MISSING_INTERPOLATION_END */]: 'Interpolation end sign was not found.',
  8949. [26 /* X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END */]: 'End bracket for dynamic directive argument was not found. ' +
  8950. 'Note that dynamic directive argument cannot contain spaces.',
  8951. // transform errors
  8952. [27 /* X_V_IF_NO_EXPRESSION */]: `v-if/v-else-if is missing expression.`,
  8953. [28 /* X_V_IF_SAME_KEY */]: `v-if/else branches must use unique keys.`,
  8954. [29 /* X_V_ELSE_NO_ADJACENT_IF */]: `v-else/v-else-if has no adjacent v-if.`,
  8955. [30 /* X_V_FOR_NO_EXPRESSION */]: `v-for is missing expression.`,
  8956. [31 /* X_V_FOR_MALFORMED_EXPRESSION */]: `v-for has invalid expression.`,
  8957. [32 /* X_V_FOR_TEMPLATE_KEY_PLACEMENT */]: `<template v-for> key should be placed on the <template> tag.`,
  8958. [33 /* X_V_BIND_NO_EXPRESSION */]: `v-bind is missing expression.`,
  8959. [34 /* X_V_ON_NO_EXPRESSION */]: `v-on is missing expression.`,
  8960. [35 /* X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET */]: `Unexpected custom directive on <slot> outlet.`,
  8961. [36 /* X_V_SLOT_MIXED_SLOT_USAGE */]: `Mixed v-slot usage on both the component and nested <template>.` +
  8962. `When there are multiple named slots, all slots should use <template> ` +
  8963. `syntax to avoid scope ambiguity.`,
  8964. [37 /* X_V_SLOT_DUPLICATE_SLOT_NAMES */]: `Duplicate slot names found. `,
  8965. [38 /* X_V_SLOT_EXTRANEOUS_DEFAULT_SLOT_CHILDREN */]: `Extraneous children found when component already has explicitly named ` +
  8966. `default slot. These children will be ignored.`,
  8967. [39 /* X_V_SLOT_MISPLACED */]: `v-slot can only be used on components or <template> tags.`,
  8968. [40 /* X_V_MODEL_NO_EXPRESSION */]: `v-model is missing expression.`,
  8969. [41 /* X_V_MODEL_MALFORMED_EXPRESSION */]: `v-model value must be a valid JavaScript member expression.`,
  8970. [42 /* X_V_MODEL_ON_SCOPE_VARIABLE */]: `v-model cannot be used on v-for or v-slot scope variables because they are not writable.`,
  8971. [43 /* X_INVALID_EXPRESSION */]: `Error parsing JavaScript expression: `,
  8972. [44 /* X_KEEP_ALIVE_INVALID_CHILDREN */]: `<KeepAlive> expects exactly one child component.`,
  8973. // generic errors
  8974. [45 /* X_PREFIX_ID_NOT_SUPPORTED */]: `"prefixIdentifiers" option is not supported in this build of compiler.`,
  8975. [46 /* X_MODULE_MODE_NOT_SUPPORTED */]: `ES module mode is not supported in this build of compiler.`,
  8976. [47 /* X_CACHE_HANDLER_NOT_SUPPORTED */]: `"cacheHandlers" option is only supported when the "prefixIdentifiers" option is enabled.`,
  8977. [48 /* X_SCOPE_ID_NOT_SUPPORTED */]: `"scopeId" option is only supported in module mode.`
  8978. };
  8979. const FRAGMENT = Symbol( `Fragment` );
  8980. const TELEPORT = Symbol( `Teleport` );
  8981. const SUSPENSE = Symbol( `Suspense` );
  8982. const KEEP_ALIVE = Symbol( `KeepAlive` );
  8983. const BASE_TRANSITION = Symbol( `BaseTransition` );
  8984. const OPEN_BLOCK = Symbol( `openBlock` );
  8985. const CREATE_BLOCK = Symbol( `createBlock` );
  8986. const CREATE_VNODE = Symbol( `createVNode` );
  8987. const CREATE_COMMENT = Symbol( `createCommentVNode` );
  8988. const CREATE_TEXT = Symbol( `createTextVNode` );
  8989. const CREATE_STATIC = Symbol( `createStaticVNode` );
  8990. const RESOLVE_COMPONENT = Symbol( `resolveComponent` );
  8991. const RESOLVE_DYNAMIC_COMPONENT = Symbol( `resolveDynamicComponent` );
  8992. const RESOLVE_DIRECTIVE = Symbol( `resolveDirective` );
  8993. const WITH_DIRECTIVES = Symbol( `withDirectives` );
  8994. const RENDER_LIST = Symbol( `renderList` );
  8995. const RENDER_SLOT = Symbol( `renderSlot` );
  8996. const CREATE_SLOTS = Symbol( `createSlots` );
  8997. const TO_DISPLAY_STRING = Symbol( `toDisplayString` );
  8998. const MERGE_PROPS = Symbol( `mergeProps` );
  8999. const TO_HANDLERS = Symbol( `toHandlers` );
  9000. const CAMELIZE = Symbol( `camelize` );
  9001. const CAPITALIZE = Symbol( `capitalize` );
  9002. const SET_BLOCK_TRACKING = Symbol( `setBlockTracking` );
  9003. const PUSH_SCOPE_ID = Symbol( `pushScopeId` );
  9004. const POP_SCOPE_ID = Symbol( `popScopeId` );
  9005. const WITH_SCOPE_ID = Symbol( `withScopeId` );
  9006. const WITH_CTX = Symbol( `withCtx` );
  9007. // Name mapping for runtime helpers that need to be imported from 'vue' in
  9008. // generated code. Make sure these are correctly exported in the runtime!
  9009. // Using `any` here because TS doesn't allow symbols as index type.
  9010. const helperNameMap = {
  9011. [FRAGMENT]: `Fragment`,
  9012. [TELEPORT]: `Teleport`,
  9013. [SUSPENSE]: `Suspense`,
  9014. [KEEP_ALIVE]: `KeepAlive`,
  9015. [BASE_TRANSITION]: `BaseTransition`,
  9016. [OPEN_BLOCK]: `openBlock`,
  9017. [CREATE_BLOCK]: `createBlock`,
  9018. [CREATE_VNODE]: `createVNode`,
  9019. [CREATE_COMMENT]: `createCommentVNode`,
  9020. [CREATE_TEXT]: `createTextVNode`,
  9021. [CREATE_STATIC]: `createStaticVNode`,
  9022. [RESOLVE_COMPONENT]: `resolveComponent`,
  9023. [RESOLVE_DYNAMIC_COMPONENT]: `resolveDynamicComponent`,
  9024. [RESOLVE_DIRECTIVE]: `resolveDirective`,
  9025. [WITH_DIRECTIVES]: `withDirectives`,
  9026. [RENDER_LIST]: `renderList`,
  9027. [RENDER_SLOT]: `renderSlot`,
  9028. [CREATE_SLOTS]: `createSlots`,
  9029. [TO_DISPLAY_STRING]: `toDisplayString`,
  9030. [MERGE_PROPS]: `mergeProps`,
  9031. [TO_HANDLERS]: `toHandlers`,
  9032. [CAMELIZE]: `camelize`,
  9033. [CAPITALIZE]: `capitalize`,
  9034. [SET_BLOCK_TRACKING]: `setBlockTracking`,
  9035. [PUSH_SCOPE_ID]: `pushScopeId`,
  9036. [POP_SCOPE_ID]: `popScopeId`,
  9037. [WITH_SCOPE_ID]: `withScopeId`,
  9038. [WITH_CTX]: `withCtx`
  9039. };
  9040. function registerRuntimeHelpers(helpers) {
  9041. Object.getOwnPropertySymbols(helpers).forEach(s => {
  9042. helperNameMap[s] = helpers[s];
  9043. });
  9044. }
  9045. // AST Utilities ---------------------------------------------------------------
  9046. // Some expressions, e.g. sequence and conditional expressions, are never
  9047. // associated with template nodes, so their source locations are just a stub.
  9048. // Container types like CompoundExpression also don't need a real location.
  9049. const locStub = {
  9050. source: '',
  9051. start: { line: 1, column: 1, offset: 0 },
  9052. end: { line: 1, column: 1, offset: 0 }
  9053. };
  9054. function createRoot(children, loc = locStub) {
  9055. return {
  9056. type: 0 /* ROOT */,
  9057. children,
  9058. helpers: [],
  9059. components: [],
  9060. directives: [],
  9061. hoists: [],
  9062. imports: [],
  9063. cached: 0,
  9064. temps: 0,
  9065. codegenNode: undefined,
  9066. loc
  9067. };
  9068. }
  9069. function createVNodeCall(context, tag, props, children, patchFlag, dynamicProps, directives, isBlock = false, disableTracking = false, loc = locStub) {
  9070. if (context) {
  9071. if (isBlock) {
  9072. context.helper(OPEN_BLOCK);
  9073. context.helper(CREATE_BLOCK);
  9074. }
  9075. else {
  9076. context.helper(CREATE_VNODE);
  9077. }
  9078. if (directives) {
  9079. context.helper(WITH_DIRECTIVES);
  9080. }
  9081. }
  9082. return {
  9083. type: 13 /* VNODE_CALL */,
  9084. tag,
  9085. props,
  9086. children,
  9087. patchFlag,
  9088. dynamicProps,
  9089. directives,
  9090. isBlock,
  9091. disableTracking,
  9092. loc
  9093. };
  9094. }
  9095. function createArrayExpression(elements, loc = locStub) {
  9096. return {
  9097. type: 17 /* JS_ARRAY_EXPRESSION */,
  9098. loc,
  9099. elements
  9100. };
  9101. }
  9102. function createObjectExpression(properties, loc = locStub) {
  9103. return {
  9104. type: 15 /* JS_OBJECT_EXPRESSION */,
  9105. loc,
  9106. properties
  9107. };
  9108. }
  9109. function createObjectProperty(key, value) {
  9110. return {
  9111. type: 16 /* JS_PROPERTY */,
  9112. loc: locStub,
  9113. key: isString(key) ? createSimpleExpression(key, true) : key,
  9114. value
  9115. };
  9116. }
  9117. function createSimpleExpression(content, isStatic, loc = locStub, isConstant = false) {
  9118. return {
  9119. type: 4 /* SIMPLE_EXPRESSION */,
  9120. loc,
  9121. isConstant,
  9122. content,
  9123. isStatic
  9124. };
  9125. }
  9126. function createCompoundExpression(children, loc = locStub) {
  9127. return {
  9128. type: 8 /* COMPOUND_EXPRESSION */,
  9129. loc,
  9130. children
  9131. };
  9132. }
  9133. function createCallExpression(callee, args = [], loc = locStub) {
  9134. return {
  9135. type: 14 /* JS_CALL_EXPRESSION */,
  9136. loc,
  9137. callee,
  9138. arguments: args
  9139. };
  9140. }
  9141. function createFunctionExpression(params, returns = undefined, newline = false, isSlot = false, loc = locStub) {
  9142. return {
  9143. type: 18 /* JS_FUNCTION_EXPRESSION */,
  9144. params,
  9145. returns,
  9146. newline,
  9147. isSlot,
  9148. loc
  9149. };
  9150. }
  9151. function createConditionalExpression(test, consequent, alternate, newline = true) {
  9152. return {
  9153. type: 19 /* JS_CONDITIONAL_EXPRESSION */,
  9154. test,
  9155. consequent,
  9156. alternate,
  9157. newline,
  9158. loc: locStub
  9159. };
  9160. }
  9161. function createCacheExpression(index, value, isVNode = false) {
  9162. return {
  9163. type: 20 /* JS_CACHE_EXPRESSION */,
  9164. index,
  9165. value,
  9166. isVNode,
  9167. loc: locStub
  9168. };
  9169. }
  9170. const isStaticExp = (p) => p.type === 4 /* SIMPLE_EXPRESSION */ && p.isStatic;
  9171. const isBuiltInType = (tag, expected) => tag === expected || tag === hyphenate(expected);
  9172. function isCoreComponent(tag) {
  9173. if (isBuiltInType(tag, 'Teleport')) {
  9174. return TELEPORT;
  9175. }
  9176. else if (isBuiltInType(tag, 'Suspense')) {
  9177. return SUSPENSE;
  9178. }
  9179. else if (isBuiltInType(tag, 'KeepAlive')) {
  9180. return KEEP_ALIVE;
  9181. }
  9182. else if (isBuiltInType(tag, 'BaseTransition')) {
  9183. return BASE_TRANSITION;
  9184. }
  9185. }
  9186. const nonIdentifierRE = /^\d|[^\$\w]/;
  9187. const isSimpleIdentifier = (name) => !nonIdentifierRE.test(name);
  9188. const memberExpRE = /^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*|\[[^\]]+\])*$/;
  9189. const isMemberExpression = (path) => {
  9190. if (!path)
  9191. return false;
  9192. return memberExpRE.test(path.trim());
  9193. };
  9194. function getInnerRange(loc, offset, length) {
  9195. const source = loc.source.substr(offset, length);
  9196. const newLoc = {
  9197. source,
  9198. start: advancePositionWithClone(loc.start, loc.source, offset),
  9199. end: loc.end
  9200. };
  9201. if (length != null) {
  9202. newLoc.end = advancePositionWithClone(loc.start, loc.source, offset + length);
  9203. }
  9204. return newLoc;
  9205. }
  9206. function advancePositionWithClone(pos, source, numberOfCharacters = source.length) {
  9207. return advancePositionWithMutation(extend({}, pos), source, numberOfCharacters);
  9208. }
  9209. // advance by mutation without cloning (for performance reasons), since this
  9210. // gets called a lot in the parser
  9211. function advancePositionWithMutation(pos, source, numberOfCharacters = source.length) {
  9212. let linesCount = 0;
  9213. let lastNewLinePos = -1;
  9214. for (let i = 0; i < numberOfCharacters; i++) {
  9215. if (source.charCodeAt(i) === 10 /* newline char code */) {
  9216. linesCount++;
  9217. lastNewLinePos = i;
  9218. }
  9219. }
  9220. pos.offset += numberOfCharacters;
  9221. pos.line += linesCount;
  9222. pos.column =
  9223. lastNewLinePos === -1
  9224. ? pos.column + numberOfCharacters
  9225. : numberOfCharacters - lastNewLinePos;
  9226. return pos;
  9227. }
  9228. function assert(condition, msg) {
  9229. /* istanbul ignore if */
  9230. if (!condition) {
  9231. throw new Error(msg || `unexpected compiler condition`);
  9232. }
  9233. }
  9234. function findDir(node, name, allowEmpty = false) {
  9235. for (let i = 0; i < node.props.length; i++) {
  9236. const p = node.props[i];
  9237. if (p.type === 7 /* DIRECTIVE */ &&
  9238. (allowEmpty || p.exp) &&
  9239. (isString(name) ? p.name === name : name.test(p.name))) {
  9240. return p;
  9241. }
  9242. }
  9243. }
  9244. function findProp(node, name, dynamicOnly = false, allowEmpty = false) {
  9245. for (let i = 0; i < node.props.length; i++) {
  9246. const p = node.props[i];
  9247. if (p.type === 6 /* ATTRIBUTE */) {
  9248. if (dynamicOnly)
  9249. continue;
  9250. if (p.name === name && (p.value || allowEmpty)) {
  9251. return p;
  9252. }
  9253. }
  9254. else if (p.name === 'bind' &&
  9255. (p.exp || allowEmpty) &&
  9256. isBindKey(p.arg, name)) {
  9257. return p;
  9258. }
  9259. }
  9260. }
  9261. function isBindKey(arg, name) {
  9262. return !!(arg && isStaticExp(arg) && arg.content === name);
  9263. }
  9264. function hasDynamicKeyVBind(node) {
  9265. return node.props.some(p => p.type === 7 /* DIRECTIVE */ &&
  9266. p.name === 'bind' &&
  9267. (!p.arg || // v-bind="obj"
  9268. p.arg.type !== 4 /* SIMPLE_EXPRESSION */ || // v-bind:[_ctx.foo]
  9269. !p.arg.isStatic) // v-bind:[foo]
  9270. );
  9271. }
  9272. function isText(node) {
  9273. return node.type === 5 /* INTERPOLATION */ || node.type === 2 /* TEXT */;
  9274. }
  9275. function isVSlot(p) {
  9276. return p.type === 7 /* DIRECTIVE */ && p.name === 'slot';
  9277. }
  9278. function isTemplateNode(node) {
  9279. return (node.type === 1 /* ELEMENT */ && node.tagType === 3 /* TEMPLATE */);
  9280. }
  9281. function isSlotOutlet(node) {
  9282. return node.type === 1 /* ELEMENT */ && node.tagType === 2 /* SLOT */;
  9283. }
  9284. function injectProp(node, prop, context) {
  9285. let propsWithInjection;
  9286. const props = node.type === 13 /* VNODE_CALL */ ? node.props : node.arguments[2];
  9287. if (props == null || isString(props)) {
  9288. propsWithInjection = createObjectExpression([prop]);
  9289. }
  9290. else if (props.type === 14 /* JS_CALL_EXPRESSION */) {
  9291. // merged props... add ours
  9292. // only inject key to object literal if it's the first argument so that
  9293. // if doesn't override user provided keys
  9294. const first = props.arguments[0];
  9295. if (!isString(first) && first.type === 15 /* JS_OBJECT_EXPRESSION */) {
  9296. first.properties.unshift(prop);
  9297. }
  9298. else {
  9299. props.arguments.unshift(createObjectExpression([prop]));
  9300. }
  9301. propsWithInjection = props;
  9302. }
  9303. else if (props.type === 15 /* JS_OBJECT_EXPRESSION */) {
  9304. let alreadyExists = false;
  9305. // check existing key to avoid overriding user provided keys
  9306. if (prop.key.type === 4 /* SIMPLE_EXPRESSION */) {
  9307. const propKeyName = prop.key.content;
  9308. alreadyExists = props.properties.some(p => p.key.type === 4 /* SIMPLE_EXPRESSION */ &&
  9309. p.key.content === propKeyName);
  9310. }
  9311. if (!alreadyExists) {
  9312. props.properties.unshift(prop);
  9313. }
  9314. propsWithInjection = props;
  9315. }
  9316. else {
  9317. // single v-bind with expression, return a merged replacement
  9318. propsWithInjection = createCallExpression(context.helper(MERGE_PROPS), [
  9319. createObjectExpression([prop]),
  9320. props
  9321. ]);
  9322. }
  9323. if (node.type === 13 /* VNODE_CALL */) {
  9324. node.props = propsWithInjection;
  9325. }
  9326. else {
  9327. node.arguments[2] = propsWithInjection;
  9328. }
  9329. }
  9330. function toValidAssetId(name, type) {
  9331. return `_${type}_${name.replace(/[^\w]/g, '_')}`;
  9332. }
  9333. // The default decoder only provides escapes for characters reserved as part of
  9334. // the template syntax, and is only used if the custom renderer did not provide
  9335. // a platform-specific decoder.
  9336. const decodeRE = /&(gt|lt|amp|apos|quot);/g;
  9337. const decodeMap = {
  9338. gt: '>',
  9339. lt: '<',
  9340. amp: '&',
  9341. apos: "'",
  9342. quot: '"'
  9343. };
  9344. const defaultParserOptions = {
  9345. delimiters: [`{{`, `}}`],
  9346. getNamespace: () => 0 /* HTML */,
  9347. getTextMode: () => 0 /* DATA */,
  9348. isVoidTag: NO,
  9349. isPreTag: NO,
  9350. isCustomElement: NO,
  9351. decodeEntities: (rawText) => rawText.replace(decodeRE, (_, p1) => decodeMap[p1]),
  9352. onError: defaultOnError,
  9353. comments: false
  9354. };
  9355. function baseParse(content, options = {}) {
  9356. const context = createParserContext(content, options);
  9357. const start = getCursor(context);
  9358. return createRoot(parseChildren(context, 0 /* DATA */, []), getSelection(context, start));
  9359. }
  9360. function createParserContext(content, rawOptions) {
  9361. const options = extend({}, defaultParserOptions);
  9362. for (const key in rawOptions) {
  9363. // @ts-ignore
  9364. options[key] = rawOptions[key] || defaultParserOptions[key];
  9365. }
  9366. return {
  9367. options,
  9368. column: 1,
  9369. line: 1,
  9370. offset: 0,
  9371. originalSource: content,
  9372. source: content,
  9373. inPre: false,
  9374. inVPre: false
  9375. };
  9376. }
  9377. function parseChildren(context, mode, ancestors) {
  9378. const parent = last(ancestors);
  9379. const ns = parent ? parent.ns : 0 /* HTML */;
  9380. const nodes = [];
  9381. while (!isEnd(context, mode, ancestors)) {
  9382. const s = context.source;
  9383. let node = undefined;
  9384. if (mode === 0 /* DATA */ || mode === 1 /* RCDATA */) {
  9385. if (!context.inVPre && startsWith(s, context.options.delimiters[0])) {
  9386. // '{{'
  9387. node = parseInterpolation(context, mode);
  9388. }
  9389. else if (mode === 0 /* DATA */ && s[0] === '<') {
  9390. // https://html.spec.whatwg.org/multipage/parsing.html#tag-open-state
  9391. if (s.length === 1) {
  9392. emitError(context, 5 /* EOF_BEFORE_TAG_NAME */, 1);
  9393. }
  9394. else if (s[1] === '!') {
  9395. // https://html.spec.whatwg.org/multipage/parsing.html#markup-declaration-open-state
  9396. if (startsWith(s, '<!--')) {
  9397. node = parseComment(context);
  9398. }
  9399. else if (startsWith(s, '<!DOCTYPE')) {
  9400. // Ignore DOCTYPE by a limitation.
  9401. node = parseBogusComment(context);
  9402. }
  9403. else if (startsWith(s, '<![CDATA[')) {
  9404. if (ns !== 0 /* HTML */) {
  9405. node = parseCDATA(context, ancestors);
  9406. }
  9407. else {
  9408. emitError(context, 1 /* CDATA_IN_HTML_CONTENT */);
  9409. node = parseBogusComment(context);
  9410. }
  9411. }
  9412. else {
  9413. emitError(context, 11 /* INCORRECTLY_OPENED_COMMENT */);
  9414. node = parseBogusComment(context);
  9415. }
  9416. }
  9417. else if (s[1] === '/') {
  9418. // https://html.spec.whatwg.org/multipage/parsing.html#end-tag-open-state
  9419. if (s.length === 2) {
  9420. emitError(context, 5 /* EOF_BEFORE_TAG_NAME */, 2);
  9421. }
  9422. else if (s[2] === '>') {
  9423. emitError(context, 14 /* MISSING_END_TAG_NAME */, 2);
  9424. advanceBy(context, 3);
  9425. continue;
  9426. }
  9427. else if (/[a-z]/i.test(s[2])) {
  9428. emitError(context, 23 /* X_INVALID_END_TAG */);
  9429. parseTag(context, 1 /* End */, parent);
  9430. continue;
  9431. }
  9432. else {
  9433. emitError(context, 12 /* INVALID_FIRST_CHARACTER_OF_TAG_NAME */, 2);
  9434. node = parseBogusComment(context);
  9435. }
  9436. }
  9437. else if (/[a-z]/i.test(s[1])) {
  9438. node = parseElement(context, ancestors);
  9439. }
  9440. else if (s[1] === '?') {
  9441. emitError(context, 21 /* UNEXPECTED_QUESTION_MARK_INSTEAD_OF_TAG_NAME */, 1);
  9442. node = parseBogusComment(context);
  9443. }
  9444. else {
  9445. emitError(context, 12 /* INVALID_FIRST_CHARACTER_OF_TAG_NAME */, 1);
  9446. }
  9447. }
  9448. }
  9449. if (!node) {
  9450. node = parseText(context, mode);
  9451. }
  9452. if (isArray(node)) {
  9453. for (let i = 0; i < node.length; i++) {
  9454. pushNode(nodes, node[i]);
  9455. }
  9456. }
  9457. else {
  9458. pushNode(nodes, node);
  9459. }
  9460. }
  9461. // Whitespace management for more efficient output
  9462. // (same as v2 whitespace: 'condense')
  9463. let removedWhitespace = false;
  9464. if (mode !== 2 /* RAWTEXT */) {
  9465. if (!context.inPre) {
  9466. for (let i = 0; i < nodes.length; i++) {
  9467. const node = nodes[i];
  9468. if (node.type === 2 /* TEXT */) {
  9469. if (!/[^\t\r\n\f ]/.test(node.content)) {
  9470. const prev = nodes[i - 1];
  9471. const next = nodes[i + 1];
  9472. // If:
  9473. // - the whitespace is the first or last node, or:
  9474. // - the whitespace is adjacent to a comment, or:
  9475. // - the whitespace is between two elements AND contains newline
  9476. // Then the whitespace is ignored.
  9477. if (!prev ||
  9478. !next ||
  9479. prev.type === 3 /* COMMENT */ ||
  9480. next.type === 3 /* COMMENT */ ||
  9481. (prev.type === 1 /* ELEMENT */ &&
  9482. next.type === 1 /* ELEMENT */ &&
  9483. /[\r\n]/.test(node.content))) {
  9484. removedWhitespace = true;
  9485. nodes[i] = null;
  9486. }
  9487. else {
  9488. // Otherwise, condensed consecutive whitespace inside the text
  9489. // down to a single space
  9490. node.content = ' ';
  9491. }
  9492. }
  9493. else {
  9494. node.content = node.content.replace(/[\t\r\n\f ]+/g, ' ');
  9495. }
  9496. }
  9497. }
  9498. }
  9499. else if (parent && context.options.isPreTag(parent.tag)) {
  9500. // remove leading newline per html spec
  9501. // https://html.spec.whatwg.org/multipage/grouping-content.html#the-pre-element
  9502. const first = nodes[0];
  9503. if (first && first.type === 2 /* TEXT */) {
  9504. first.content = first.content.replace(/^\r?\n/, '');
  9505. }
  9506. }
  9507. }
  9508. return removedWhitespace ? nodes.filter(Boolean) : nodes;
  9509. }
  9510. function pushNode(nodes, node) {
  9511. if (node.type === 2 /* TEXT */) {
  9512. const prev = last(nodes);
  9513. // Merge if both this and the previous node are text and those are
  9514. // consecutive. This happens for cases like "a < b".
  9515. if (prev &&
  9516. prev.type === 2 /* TEXT */ &&
  9517. prev.loc.end.offset === node.loc.start.offset) {
  9518. prev.content += node.content;
  9519. prev.loc.end = node.loc.end;
  9520. prev.loc.source += node.loc.source;
  9521. return;
  9522. }
  9523. }
  9524. nodes.push(node);
  9525. }
  9526. function parseCDATA(context, ancestors) {
  9527. advanceBy(context, 9);
  9528. const nodes = parseChildren(context, 3 /* CDATA */, ancestors);
  9529. if (context.source.length === 0) {
  9530. emitError(context, 6 /* EOF_IN_CDATA */);
  9531. }
  9532. else {
  9533. advanceBy(context, 3);
  9534. }
  9535. return nodes;
  9536. }
  9537. function parseComment(context) {
  9538. const start = getCursor(context);
  9539. let content;
  9540. // Regular comment.
  9541. const match = /--(\!)?>/.exec(context.source);
  9542. if (!match) {
  9543. content = context.source.slice(4);
  9544. advanceBy(context, context.source.length);
  9545. emitError(context, 7 /* EOF_IN_COMMENT */);
  9546. }
  9547. else {
  9548. if (match.index <= 3) {
  9549. emitError(context, 0 /* ABRUPT_CLOSING_OF_EMPTY_COMMENT */);
  9550. }
  9551. if (match[1]) {
  9552. emitError(context, 10 /* INCORRECTLY_CLOSED_COMMENT */);
  9553. }
  9554. content = context.source.slice(4, match.index);
  9555. // Advancing with reporting nested comments.
  9556. const s = context.source.slice(0, match.index);
  9557. let prevIndex = 1, nestedIndex = 0;
  9558. while ((nestedIndex = s.indexOf('<!--', prevIndex)) !== -1) {
  9559. advanceBy(context, nestedIndex - prevIndex + 1);
  9560. if (nestedIndex + 4 < s.length) {
  9561. emitError(context, 16 /* NESTED_COMMENT */);
  9562. }
  9563. prevIndex = nestedIndex + 1;
  9564. }
  9565. advanceBy(context, match.index + match[0].length - prevIndex + 1);
  9566. }
  9567. return {
  9568. type: 3 /* COMMENT */,
  9569. content,
  9570. loc: getSelection(context, start)
  9571. };
  9572. }
  9573. function parseBogusComment(context) {
  9574. const start = getCursor(context);
  9575. const contentStart = context.source[1] === '?' ? 1 : 2;
  9576. let content;
  9577. const closeIndex = context.source.indexOf('>');
  9578. if (closeIndex === -1) {
  9579. content = context.source.slice(contentStart);
  9580. advanceBy(context, context.source.length);
  9581. }
  9582. else {
  9583. content = context.source.slice(contentStart, closeIndex);
  9584. advanceBy(context, closeIndex + 1);
  9585. }
  9586. return {
  9587. type: 3 /* COMMENT */,
  9588. content,
  9589. loc: getSelection(context, start)
  9590. };
  9591. }
  9592. function parseElement(context, ancestors) {
  9593. // Start tag.
  9594. const wasInPre = context.inPre;
  9595. const wasInVPre = context.inVPre;
  9596. const parent = last(ancestors);
  9597. const element = parseTag(context, 0 /* Start */, parent);
  9598. const isPreBoundary = context.inPre && !wasInPre;
  9599. const isVPreBoundary = context.inVPre && !wasInVPre;
  9600. if (element.isSelfClosing || context.options.isVoidTag(element.tag)) {
  9601. return element;
  9602. }
  9603. // Children.
  9604. ancestors.push(element);
  9605. const mode = context.options.getTextMode(element, parent);
  9606. const children = parseChildren(context, mode, ancestors);
  9607. ancestors.pop();
  9608. element.children = children;
  9609. // End tag.
  9610. if (startsWithEndTagOpen(context.source, element.tag)) {
  9611. parseTag(context, 1 /* End */, parent);
  9612. }
  9613. else {
  9614. emitError(context, 24 /* X_MISSING_END_TAG */, 0, element.loc.start);
  9615. if (context.source.length === 0 && element.tag.toLowerCase() === 'script') {
  9616. const first = children[0];
  9617. if (first && startsWith(first.loc.source, '<!--')) {
  9618. emitError(context, 8 /* EOF_IN_SCRIPT_HTML_COMMENT_LIKE_TEXT */);
  9619. }
  9620. }
  9621. }
  9622. element.loc = getSelection(context, element.loc.start);
  9623. if (isPreBoundary) {
  9624. context.inPre = false;
  9625. }
  9626. if (isVPreBoundary) {
  9627. context.inVPre = false;
  9628. }
  9629. return element;
  9630. }
  9631. const isSpecialTemplateDirective = /*#__PURE__*/ makeMap(`if,else,else-if,for,slot`);
  9632. /**
  9633. * Parse a tag (E.g. `<div id=a>`) with that type (start tag or end tag).
  9634. */
  9635. function parseTag(context, type, parent) {
  9636. // Tag open.
  9637. const start = getCursor(context);
  9638. const match = /^<\/?([a-z][^\t\r\n\f />]*)/i.exec(context.source);
  9639. const tag = match[1];
  9640. const ns = context.options.getNamespace(tag, parent);
  9641. advanceBy(context, match[0].length);
  9642. advanceSpaces(context);
  9643. // save current state in case we need to re-parse attributes with v-pre
  9644. const cursor = getCursor(context);
  9645. const currentSource = context.source;
  9646. // Attributes.
  9647. let props = parseAttributes(context, type);
  9648. // check <pre> tag
  9649. if (context.options.isPreTag(tag)) {
  9650. context.inPre = true;
  9651. }
  9652. // check v-pre
  9653. if (!context.inVPre &&
  9654. props.some(p => p.type === 7 /* DIRECTIVE */ && p.name === 'pre')) {
  9655. context.inVPre = true;
  9656. // reset context
  9657. extend(context, cursor);
  9658. context.source = currentSource;
  9659. // re-parse attrs and filter out v-pre itself
  9660. props = parseAttributes(context, type).filter(p => p.name !== 'v-pre');
  9661. }
  9662. // Tag close.
  9663. let isSelfClosing = false;
  9664. if (context.source.length === 0) {
  9665. emitError(context, 9 /* EOF_IN_TAG */);
  9666. }
  9667. else {
  9668. isSelfClosing = startsWith(context.source, '/>');
  9669. if (type === 1 /* End */ && isSelfClosing) {
  9670. emitError(context, 4 /* END_TAG_WITH_TRAILING_SOLIDUS */);
  9671. }
  9672. advanceBy(context, isSelfClosing ? 2 : 1);
  9673. }
  9674. let tagType = 0 /* ELEMENT */;
  9675. const options = context.options;
  9676. if (!context.inVPre && !options.isCustomElement(tag)) {
  9677. const hasVIs = props.some(p => p.type === 7 /* DIRECTIVE */ && p.name === 'is');
  9678. if (options.isNativeTag && !hasVIs) {
  9679. if (!options.isNativeTag(tag))
  9680. tagType = 1 /* COMPONENT */;
  9681. }
  9682. else if (hasVIs ||
  9683. isCoreComponent(tag) ||
  9684. (options.isBuiltInComponent && options.isBuiltInComponent(tag)) ||
  9685. /^[A-Z]/.test(tag) ||
  9686. tag === 'component') {
  9687. tagType = 1 /* COMPONENT */;
  9688. }
  9689. if (tag === 'slot') {
  9690. tagType = 2 /* SLOT */;
  9691. }
  9692. else if (tag === 'template' &&
  9693. props.some(p => {
  9694. return (p.type === 7 /* DIRECTIVE */ && isSpecialTemplateDirective(p.name));
  9695. })) {
  9696. tagType = 3 /* TEMPLATE */;
  9697. }
  9698. }
  9699. return {
  9700. type: 1 /* ELEMENT */,
  9701. ns,
  9702. tag,
  9703. tagType,
  9704. props,
  9705. isSelfClosing,
  9706. children: [],
  9707. loc: getSelection(context, start),
  9708. codegenNode: undefined // to be created during transform phase
  9709. };
  9710. }
  9711. function parseAttributes(context, type) {
  9712. const props = [];
  9713. const attributeNames = new Set();
  9714. while (context.source.length > 0 &&
  9715. !startsWith(context.source, '>') &&
  9716. !startsWith(context.source, '/>')) {
  9717. if (startsWith(context.source, '/')) {
  9718. emitError(context, 22 /* UNEXPECTED_SOLIDUS_IN_TAG */);
  9719. advanceBy(context, 1);
  9720. advanceSpaces(context);
  9721. continue;
  9722. }
  9723. if (type === 1 /* End */) {
  9724. emitError(context, 3 /* END_TAG_WITH_ATTRIBUTES */);
  9725. }
  9726. const attr = parseAttribute(context, attributeNames);
  9727. if (type === 0 /* Start */) {
  9728. props.push(attr);
  9729. }
  9730. if (/^[^\t\r\n\f />]/.test(context.source)) {
  9731. emitError(context, 15 /* MISSING_WHITESPACE_BETWEEN_ATTRIBUTES */);
  9732. }
  9733. advanceSpaces(context);
  9734. }
  9735. return props;
  9736. }
  9737. function parseAttribute(context, nameSet) {
  9738. // Name.
  9739. const start = getCursor(context);
  9740. const match = /^[^\t\r\n\f />][^\t\r\n\f />=]*/.exec(context.source);
  9741. const name = match[0];
  9742. if (nameSet.has(name)) {
  9743. emitError(context, 2 /* DUPLICATE_ATTRIBUTE */);
  9744. }
  9745. nameSet.add(name);
  9746. if (name[0] === '=') {
  9747. emitError(context, 19 /* UNEXPECTED_EQUALS_SIGN_BEFORE_ATTRIBUTE_NAME */);
  9748. }
  9749. {
  9750. const pattern = /["'<]/g;
  9751. let m;
  9752. while ((m = pattern.exec(name))) {
  9753. emitError(context, 17 /* UNEXPECTED_CHARACTER_IN_ATTRIBUTE_NAME */, m.index);
  9754. }
  9755. }
  9756. advanceBy(context, name.length);
  9757. // Value
  9758. let value = undefined;
  9759. if (/^[\t\r\n\f ]*=/.test(context.source)) {
  9760. advanceSpaces(context);
  9761. advanceBy(context, 1);
  9762. advanceSpaces(context);
  9763. value = parseAttributeValue(context);
  9764. if (!value) {
  9765. emitError(context, 13 /* MISSING_ATTRIBUTE_VALUE */);
  9766. }
  9767. }
  9768. const loc = getSelection(context, start);
  9769. if (!context.inVPre && /^(v-|:|@|#)/.test(name)) {
  9770. const match = /(?:^v-([a-z0-9-]+))?(?:(?::|^@|^#)(\[[^\]]+\]|[^\.]+))?(.+)?$/i.exec(name);
  9771. const dirName = match[1] ||
  9772. (startsWith(name, ':') ? 'bind' : startsWith(name, '@') ? 'on' : 'slot');
  9773. let arg;
  9774. if (match[2]) {
  9775. const isSlot = dirName === 'slot';
  9776. const startOffset = name.indexOf(match[2]);
  9777. const loc = getSelection(context, getNewPosition(context, start, startOffset), getNewPosition(context, start, startOffset + match[2].length + ((isSlot && match[3]) || '').length));
  9778. let content = match[2];
  9779. let isStatic = true;
  9780. if (content.startsWith('[')) {
  9781. isStatic = false;
  9782. if (!content.endsWith(']')) {
  9783. emitError(context, 26 /* X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END */);
  9784. }
  9785. content = content.substr(1, content.length - 2);
  9786. }
  9787. else if (isSlot) {
  9788. // #1241 special case for v-slot: vuetify relies extensively on slot
  9789. // names containing dots. v-slot doesn't have any modifiers and Vue 2.x
  9790. // supports such usage so we are keeping it consistent with 2.x.
  9791. content += match[3] || '';
  9792. }
  9793. arg = {
  9794. type: 4 /* SIMPLE_EXPRESSION */,
  9795. content,
  9796. isStatic,
  9797. isConstant: isStatic,
  9798. loc
  9799. };
  9800. }
  9801. if (value && value.isQuoted) {
  9802. const valueLoc = value.loc;
  9803. valueLoc.start.offset++;
  9804. valueLoc.start.column++;
  9805. valueLoc.end = advancePositionWithClone(valueLoc.start, value.content);
  9806. valueLoc.source = valueLoc.source.slice(1, -1);
  9807. }
  9808. return {
  9809. type: 7 /* DIRECTIVE */,
  9810. name: dirName,
  9811. exp: value && {
  9812. type: 4 /* SIMPLE_EXPRESSION */,
  9813. content: value.content,
  9814. isStatic: false,
  9815. // Treat as non-constant by default. This can be potentially set to
  9816. // true by `transformExpression` to make it eligible for hoisting.
  9817. isConstant: false,
  9818. loc: value.loc
  9819. },
  9820. arg,
  9821. modifiers: match[3] ? match[3].substr(1).split('.') : [],
  9822. loc
  9823. };
  9824. }
  9825. return {
  9826. type: 6 /* ATTRIBUTE */,
  9827. name,
  9828. value: value && {
  9829. type: 2 /* TEXT */,
  9830. content: value.content,
  9831. loc: value.loc
  9832. },
  9833. loc
  9834. };
  9835. }
  9836. function parseAttributeValue(context) {
  9837. const start = getCursor(context);
  9838. let content;
  9839. const quote = context.source[0];
  9840. const isQuoted = quote === `"` || quote === `'`;
  9841. if (isQuoted) {
  9842. // Quoted value.
  9843. advanceBy(context, 1);
  9844. const endIndex = context.source.indexOf(quote);
  9845. if (endIndex === -1) {
  9846. content = parseTextData(context, context.source.length, 4 /* ATTRIBUTE_VALUE */);
  9847. }
  9848. else {
  9849. content = parseTextData(context, endIndex, 4 /* ATTRIBUTE_VALUE */);
  9850. advanceBy(context, 1);
  9851. }
  9852. }
  9853. else {
  9854. // Unquoted
  9855. const match = /^[^\t\r\n\f >]+/.exec(context.source);
  9856. if (!match) {
  9857. return undefined;
  9858. }
  9859. const unexpectedChars = /["'<=`]/g;
  9860. let m;
  9861. while ((m = unexpectedChars.exec(match[0]))) {
  9862. emitError(context, 18 /* UNEXPECTED_CHARACTER_IN_UNQUOTED_ATTRIBUTE_VALUE */, m.index);
  9863. }
  9864. content = parseTextData(context, match[0].length, 4 /* ATTRIBUTE_VALUE */);
  9865. }
  9866. return { content, isQuoted, loc: getSelection(context, start) };
  9867. }
  9868. function parseInterpolation(context, mode) {
  9869. const [open, close] = context.options.delimiters;
  9870. const closeIndex = context.source.indexOf(close, open.length);
  9871. if (closeIndex === -1) {
  9872. emitError(context, 25 /* X_MISSING_INTERPOLATION_END */);
  9873. return undefined;
  9874. }
  9875. const start = getCursor(context);
  9876. advanceBy(context, open.length);
  9877. const innerStart = getCursor(context);
  9878. const innerEnd = getCursor(context);
  9879. const rawContentLength = closeIndex - open.length;
  9880. const rawContent = context.source.slice(0, rawContentLength);
  9881. const preTrimContent = parseTextData(context, rawContentLength, mode);
  9882. const content = preTrimContent.trim();
  9883. const startOffset = preTrimContent.indexOf(content);
  9884. if (startOffset > 0) {
  9885. advancePositionWithMutation(innerStart, rawContent, startOffset);
  9886. }
  9887. const endOffset = rawContentLength - (preTrimContent.length - content.length - startOffset);
  9888. advancePositionWithMutation(innerEnd, rawContent, endOffset);
  9889. advanceBy(context, close.length);
  9890. return {
  9891. type: 5 /* INTERPOLATION */,
  9892. content: {
  9893. type: 4 /* SIMPLE_EXPRESSION */,
  9894. isStatic: false,
  9895. // Set `isConstant` to false by default and will decide in transformExpression
  9896. isConstant: false,
  9897. content,
  9898. loc: getSelection(context, innerStart, innerEnd)
  9899. },
  9900. loc: getSelection(context, start)
  9901. };
  9902. }
  9903. function parseText(context, mode) {
  9904. const endTokens = ['<', context.options.delimiters[0]];
  9905. if (mode === 3 /* CDATA */) {
  9906. endTokens.push(']]>');
  9907. }
  9908. let endIndex = context.source.length;
  9909. for (let i = 0; i < endTokens.length; i++) {
  9910. const index = context.source.indexOf(endTokens[i], 1);
  9911. if (index !== -1 && endIndex > index) {
  9912. endIndex = index;
  9913. }
  9914. }
  9915. const start = getCursor(context);
  9916. const content = parseTextData(context, endIndex, mode);
  9917. return {
  9918. type: 2 /* TEXT */,
  9919. content,
  9920. loc: getSelection(context, start)
  9921. };
  9922. }
  9923. /**
  9924. * Get text data with a given length from the current location.
  9925. * This translates HTML entities in the text data.
  9926. */
  9927. function parseTextData(context, length, mode) {
  9928. const rawText = context.source.slice(0, length);
  9929. advanceBy(context, length);
  9930. if (mode === 2 /* RAWTEXT */ ||
  9931. mode === 3 /* CDATA */ ||
  9932. rawText.indexOf('&') === -1) {
  9933. return rawText;
  9934. }
  9935. else {
  9936. // DATA or RCDATA containing "&"". Entity decoding required.
  9937. return context.options.decodeEntities(rawText, mode === 4 /* ATTRIBUTE_VALUE */);
  9938. }
  9939. }
  9940. function getCursor(context) {
  9941. const { column, line, offset } = context;
  9942. return { column, line, offset };
  9943. }
  9944. function getSelection(context, start, end) {
  9945. end = end || getCursor(context);
  9946. return {
  9947. start,
  9948. end,
  9949. source: context.originalSource.slice(start.offset, end.offset)
  9950. };
  9951. }
  9952. function last(xs) {
  9953. return xs[xs.length - 1];
  9954. }
  9955. function startsWith(source, searchString) {
  9956. return source.startsWith(searchString);
  9957. }
  9958. function advanceBy(context, numberOfCharacters) {
  9959. const { source } = context;
  9960. advancePositionWithMutation(context, source, numberOfCharacters);
  9961. context.source = source.slice(numberOfCharacters);
  9962. }
  9963. function advanceSpaces(context) {
  9964. const match = /^[\t\r\n\f ]+/.exec(context.source);
  9965. if (match) {
  9966. advanceBy(context, match[0].length);
  9967. }
  9968. }
  9969. function getNewPosition(context, start, numberOfCharacters) {
  9970. return advancePositionWithClone(start, context.originalSource.slice(start.offset, numberOfCharacters), numberOfCharacters);
  9971. }
  9972. function emitError(context, code, offset, loc = getCursor(context)) {
  9973. if (offset) {
  9974. loc.offset += offset;
  9975. loc.column += offset;
  9976. }
  9977. context.options.onError(createCompilerError(code, {
  9978. start: loc,
  9979. end: loc,
  9980. source: ''
  9981. }));
  9982. }
  9983. function isEnd(context, mode, ancestors) {
  9984. const s = context.source;
  9985. switch (mode) {
  9986. case 0 /* DATA */:
  9987. if (startsWith(s, '</')) {
  9988. //TODO: probably bad performance
  9989. for (let i = ancestors.length - 1; i >= 0; --i) {
  9990. if (startsWithEndTagOpen(s, ancestors[i].tag)) {
  9991. return true;
  9992. }
  9993. }
  9994. }
  9995. break;
  9996. case 1 /* RCDATA */:
  9997. case 2 /* RAWTEXT */: {
  9998. const parent = last(ancestors);
  9999. if (parent && startsWithEndTagOpen(s, parent.tag)) {
  10000. return true;
  10001. }
  10002. break;
  10003. }
  10004. case 3 /* CDATA */:
  10005. if (startsWith(s, ']]>')) {
  10006. return true;
  10007. }
  10008. break;
  10009. }
  10010. return !s;
  10011. }
  10012. function startsWithEndTagOpen(source, tag) {
  10013. return (startsWith(source, '</') &&
  10014. source.substr(2, tag.length).toLowerCase() === tag.toLowerCase() &&
  10015. /[\t\r\n\f />]/.test(source[2 + tag.length] || '>'));
  10016. }
  10017. function hoistStatic(root, context) {
  10018. walk(root, context, new Map(),
  10019. // Root node is unfortunately non-hoistable due to potential parent
  10020. // fallthrough attributes.
  10021. isSingleElementRoot(root, root.children[0]));
  10022. }
  10023. function isSingleElementRoot(root, child) {
  10024. const { children } = root;
  10025. return (children.length === 1 &&
  10026. child.type === 1 /* ELEMENT */ &&
  10027. !isSlotOutlet(child));
  10028. }
  10029. function walk(node, context, resultCache, doNotHoistNode = false) {
  10030. let hasHoistedNode = false;
  10031. // Some transforms, e.g. transformAssetUrls from @vue/compiler-sfc, replaces
  10032. // static bindings with expressions. These expressions are guaranteed to be
  10033. // constant so they are still eligible for hoisting, but they are only
  10034. // available at runtime and therefore cannot be evaluated ahead of time.
  10035. // This is only a concern for pre-stringification (via transformHoist by
  10036. // @vue/compiler-dom), but doing it here allows us to perform only one full
  10037. // walk of the AST and allow `stringifyStatic` to stop walking as soon as its
  10038. // stringficiation threshold is met.
  10039. let hasRuntimeConstant = false;
  10040. const { children } = node;
  10041. for (let i = 0; i < children.length; i++) {
  10042. const child = children[i];
  10043. // only plain elements & text calls are eligible for hoisting.
  10044. if (child.type === 1 /* ELEMENT */ &&
  10045. child.tagType === 0 /* ELEMENT */) {
  10046. let staticType;
  10047. if (!doNotHoistNode &&
  10048. (staticType = getStaticType(child, resultCache)) > 0) {
  10049. if (staticType === 2 /* HAS_RUNTIME_CONSTANT */) {
  10050. hasRuntimeConstant = true;
  10051. }
  10052. child.codegenNode.patchFlag =
  10053. -1 /* HOISTED */ + ( ` /* HOISTED */` );
  10054. child.codegenNode = context.hoist(child.codegenNode);
  10055. hasHoistedNode = true;
  10056. continue;
  10057. }
  10058. else {
  10059. // node may contain dynamic children, but its props may be eligible for
  10060. // hoisting.
  10061. const codegenNode = child.codegenNode;
  10062. if (codegenNode.type === 13 /* VNODE_CALL */) {
  10063. const flag = getPatchFlag(codegenNode);
  10064. if ((!flag ||
  10065. flag === 512 /* NEED_PATCH */ ||
  10066. flag === 1 /* TEXT */) &&
  10067. !hasNonHoistableProps(child)) {
  10068. const props = getNodeProps(child);
  10069. if (props) {
  10070. codegenNode.props = context.hoist(props);
  10071. }
  10072. }
  10073. }
  10074. }
  10075. }
  10076. else if (child.type === 12 /* TEXT_CALL */) {
  10077. const staticType = getStaticType(child.content, resultCache);
  10078. if (staticType > 0) {
  10079. if (staticType === 2 /* HAS_RUNTIME_CONSTANT */) {
  10080. hasRuntimeConstant = true;
  10081. }
  10082. child.codegenNode = context.hoist(child.codegenNode);
  10083. hasHoistedNode = true;
  10084. }
  10085. }
  10086. // walk further
  10087. if (child.type === 1 /* ELEMENT */) {
  10088. walk(child, context, resultCache);
  10089. }
  10090. else if (child.type === 11 /* FOR */) {
  10091. // Do not hoist v-for single child because it has to be a block
  10092. walk(child, context, resultCache, child.children.length === 1);
  10093. }
  10094. else if (child.type === 9 /* IF */) {
  10095. for (let i = 0; i < child.branches.length; i++) {
  10096. // Do not hoist v-if single child because it has to be a block
  10097. walk(child.branches[i], context, resultCache, child.branches[i].children.length === 1);
  10098. }
  10099. }
  10100. }
  10101. if (!hasRuntimeConstant && hasHoistedNode && context.transformHoist) {
  10102. context.transformHoist(children, context, node);
  10103. }
  10104. }
  10105. function getStaticType(node, resultCache = new Map()) {
  10106. switch (node.type) {
  10107. case 1 /* ELEMENT */:
  10108. if (node.tagType !== 0 /* ELEMENT */) {
  10109. return 0 /* NOT_STATIC */;
  10110. }
  10111. const cached = resultCache.get(node);
  10112. if (cached !== undefined) {
  10113. return cached;
  10114. }
  10115. const codegenNode = node.codegenNode;
  10116. if (codegenNode.type !== 13 /* VNODE_CALL */) {
  10117. return 0 /* NOT_STATIC */;
  10118. }
  10119. const flag = getPatchFlag(codegenNode);
  10120. if (!flag && !hasNonHoistableProps(node)) {
  10121. // element self is static. check its children.
  10122. let returnType = 1 /* FULL_STATIC */;
  10123. for (let i = 0; i < node.children.length; i++) {
  10124. const childType = getStaticType(node.children[i], resultCache);
  10125. if (childType === 0 /* NOT_STATIC */) {
  10126. resultCache.set(node, 0 /* NOT_STATIC */);
  10127. return 0 /* NOT_STATIC */;
  10128. }
  10129. else if (childType === 2 /* HAS_RUNTIME_CONSTANT */) {
  10130. returnType = 2 /* HAS_RUNTIME_CONSTANT */;
  10131. }
  10132. }
  10133. // check if any of the props contain runtime constants
  10134. if (returnType !== 2 /* HAS_RUNTIME_CONSTANT */) {
  10135. for (let i = 0; i < node.props.length; i++) {
  10136. const p = node.props[i];
  10137. if (p.type === 7 /* DIRECTIVE */ &&
  10138. p.name === 'bind' &&
  10139. p.exp &&
  10140. (p.exp.type === 8 /* COMPOUND_EXPRESSION */ ||
  10141. p.exp.isRuntimeConstant)) {
  10142. returnType = 2 /* HAS_RUNTIME_CONSTANT */;
  10143. }
  10144. }
  10145. }
  10146. // only svg/foreignObject could be block here, however if they are
  10147. // stati then they don't need to be blocks since there will be no
  10148. // nested updates.
  10149. if (codegenNode.isBlock) {
  10150. codegenNode.isBlock = false;
  10151. }
  10152. resultCache.set(node, returnType);
  10153. return returnType;
  10154. }
  10155. else {
  10156. resultCache.set(node, 0 /* NOT_STATIC */);
  10157. return 0 /* NOT_STATIC */;
  10158. }
  10159. case 2 /* TEXT */:
  10160. case 3 /* COMMENT */:
  10161. return 1 /* FULL_STATIC */;
  10162. case 9 /* IF */:
  10163. case 11 /* FOR */:
  10164. case 10 /* IF_BRANCH */:
  10165. return 0 /* NOT_STATIC */;
  10166. case 5 /* INTERPOLATION */:
  10167. case 12 /* TEXT_CALL */:
  10168. return getStaticType(node.content, resultCache);
  10169. case 4 /* SIMPLE_EXPRESSION */:
  10170. return node.isConstant
  10171. ? node.isRuntimeConstant
  10172. ? 2 /* HAS_RUNTIME_CONSTANT */
  10173. : 1 /* FULL_STATIC */
  10174. : 0 /* NOT_STATIC */;
  10175. case 8 /* COMPOUND_EXPRESSION */:
  10176. let returnType = 1 /* FULL_STATIC */;
  10177. for (let i = 0; i < node.children.length; i++) {
  10178. const child = node.children[i];
  10179. if (isString(child) || isSymbol(child)) {
  10180. continue;
  10181. }
  10182. const childType = getStaticType(child, resultCache);
  10183. if (childType === 0 /* NOT_STATIC */) {
  10184. return 0 /* NOT_STATIC */;
  10185. }
  10186. else if (childType === 2 /* HAS_RUNTIME_CONSTANT */) {
  10187. returnType = 2 /* HAS_RUNTIME_CONSTANT */;
  10188. }
  10189. }
  10190. return returnType;
  10191. default:
  10192. return 0 /* NOT_STATIC */;
  10193. }
  10194. }
  10195. /**
  10196. * Even for a node with no patch flag, it is possible for it to contain
  10197. * non-hoistable expressions that refers to scope variables, e.g. compiler
  10198. * injected keys or cached event handlers. Therefore we need to always check the
  10199. * codegenNode's props to be sure.
  10200. */
  10201. function hasNonHoistableProps(node) {
  10202. const props = getNodeProps(node);
  10203. if (props && props.type === 15 /* JS_OBJECT_EXPRESSION */) {
  10204. const { properties } = props;
  10205. for (let i = 0; i < properties.length; i++) {
  10206. const { key, value } = properties[i];
  10207. if (key.type !== 4 /* SIMPLE_EXPRESSION */ ||
  10208. !key.isStatic ||
  10209. (value.type !== 4 /* SIMPLE_EXPRESSION */ ||
  10210. (!value.isStatic && !value.isConstant))) {
  10211. return true;
  10212. }
  10213. }
  10214. }
  10215. return false;
  10216. }
  10217. function getNodeProps(node) {
  10218. const codegenNode = node.codegenNode;
  10219. if (codegenNode.type === 13 /* VNODE_CALL */) {
  10220. return codegenNode.props;
  10221. }
  10222. }
  10223. function getPatchFlag(node) {
  10224. const flag = node.patchFlag;
  10225. return flag ? parseInt(flag, 10) : undefined;
  10226. }
  10227. function createTransformContext(root, { prefixIdentifiers = false, hoistStatic = false, cacheHandlers = false, nodeTransforms = [], directiveTransforms = {}, transformHoist = null, isBuiltInComponent = NOOP, isCustomElement = NOOP, expressionPlugins = [], scopeId = null, ssr = false, ssrCssVars = ``, bindingMetadata = {}, onError = defaultOnError }) {
  10228. const context = {
  10229. // options
  10230. prefixIdentifiers,
  10231. hoistStatic,
  10232. cacheHandlers,
  10233. nodeTransforms,
  10234. directiveTransforms,
  10235. transformHoist,
  10236. isBuiltInComponent,
  10237. isCustomElement,
  10238. expressionPlugins,
  10239. scopeId,
  10240. ssr,
  10241. ssrCssVars,
  10242. bindingMetadata,
  10243. onError,
  10244. // state
  10245. root,
  10246. helpers: new Set(),
  10247. components: new Set(),
  10248. directives: new Set(),
  10249. hoists: [],
  10250. imports: new Set(),
  10251. temps: 0,
  10252. cached: 0,
  10253. identifiers: Object.create(null),
  10254. scopes: {
  10255. vFor: 0,
  10256. vSlot: 0,
  10257. vPre: 0,
  10258. vOnce: 0
  10259. },
  10260. parent: null,
  10261. currentNode: root,
  10262. childIndex: 0,
  10263. // methods
  10264. helper(name) {
  10265. context.helpers.add(name);
  10266. return name;
  10267. },
  10268. helperString(name) {
  10269. return `_${helperNameMap[context.helper(name)]}`;
  10270. },
  10271. replaceNode(node) {
  10272. /* istanbul ignore if */
  10273. {
  10274. if (!context.currentNode) {
  10275. throw new Error(`Node being replaced is already removed.`);
  10276. }
  10277. if (!context.parent) {
  10278. throw new Error(`Cannot replace root node.`);
  10279. }
  10280. }
  10281. context.parent.children[context.childIndex] = context.currentNode = node;
  10282. },
  10283. removeNode(node) {
  10284. if ( !context.parent) {
  10285. throw new Error(`Cannot remove root node.`);
  10286. }
  10287. const list = context.parent.children;
  10288. const removalIndex = node
  10289. ? list.indexOf(node)
  10290. : context.currentNode
  10291. ? context.childIndex
  10292. : -1;
  10293. /* istanbul ignore if */
  10294. if ( removalIndex < 0) {
  10295. throw new Error(`node being removed is not a child of current parent`);
  10296. }
  10297. if (!node || node === context.currentNode) {
  10298. // current node removed
  10299. context.currentNode = null;
  10300. context.onNodeRemoved();
  10301. }
  10302. else {
  10303. // sibling node removed
  10304. if (context.childIndex > removalIndex) {
  10305. context.childIndex--;
  10306. context.onNodeRemoved();
  10307. }
  10308. }
  10309. context.parent.children.splice(removalIndex, 1);
  10310. },
  10311. onNodeRemoved: () => { },
  10312. addIdentifiers(exp) {
  10313. },
  10314. removeIdentifiers(exp) {
  10315. },
  10316. hoist(exp) {
  10317. context.hoists.push(exp);
  10318. const identifier = createSimpleExpression(`_hoisted_${context.hoists.length}`, false, exp.loc, true);
  10319. identifier.hoisted = exp;
  10320. return identifier;
  10321. },
  10322. cache(exp, isVNode = false) {
  10323. return createCacheExpression(++context.cached, exp, isVNode);
  10324. }
  10325. };
  10326. return context;
  10327. }
  10328. function transform(root, options) {
  10329. const context = createTransformContext(root, options);
  10330. traverseNode(root, context);
  10331. if (options.hoistStatic) {
  10332. hoistStatic(root, context);
  10333. }
  10334. if (!options.ssr) {
  10335. createRootCodegen(root, context);
  10336. }
  10337. // finalize meta information
  10338. root.helpers = [...context.helpers];
  10339. root.components = [...context.components];
  10340. root.directives = [...context.directives];
  10341. root.imports = [...context.imports];
  10342. root.hoists = context.hoists;
  10343. root.temps = context.temps;
  10344. root.cached = context.cached;
  10345. }
  10346. function createRootCodegen(root, context) {
  10347. const { helper } = context;
  10348. const { children } = root;
  10349. if (children.length === 1) {
  10350. const child = children[0];
  10351. // if the single child is an element, turn it into a block.
  10352. if (isSingleElementRoot(root, child) && child.codegenNode) {
  10353. // single element root is never hoisted so codegenNode will never be
  10354. // SimpleExpressionNode
  10355. const codegenNode = child.codegenNode;
  10356. if (codegenNode.type === 13 /* VNODE_CALL */) {
  10357. codegenNode.isBlock = true;
  10358. helper(OPEN_BLOCK);
  10359. helper(CREATE_BLOCK);
  10360. }
  10361. root.codegenNode = codegenNode;
  10362. }
  10363. else {
  10364. // - single <slot/>, IfNode, ForNode: already blocks.
  10365. // - single text node: always patched.
  10366. // root codegen falls through via genNode()
  10367. root.codegenNode = child;
  10368. }
  10369. }
  10370. else if (children.length > 1) {
  10371. // root has multiple nodes - return a fragment block.
  10372. root.codegenNode = createVNodeCall(context, helper(FRAGMENT), undefined, root.children, `${64 /* STABLE_FRAGMENT */} /* ${PatchFlagNames[64 /* STABLE_FRAGMENT */]} */`, undefined, undefined, true);
  10373. }
  10374. else ;
  10375. }
  10376. function traverseChildren(parent, context) {
  10377. let i = 0;
  10378. const nodeRemoved = () => {
  10379. i--;
  10380. };
  10381. for (; i < parent.children.length; i++) {
  10382. const child = parent.children[i];
  10383. if (isString(child))
  10384. continue;
  10385. context.parent = parent;
  10386. context.childIndex = i;
  10387. context.onNodeRemoved = nodeRemoved;
  10388. traverseNode(child, context);
  10389. }
  10390. }
  10391. function traverseNode(node, context) {
  10392. context.currentNode = node;
  10393. // apply transform plugins
  10394. const { nodeTransforms } = context;
  10395. const exitFns = [];
  10396. for (let i = 0; i < nodeTransforms.length; i++) {
  10397. const onExit = nodeTransforms[i](node, context);
  10398. if (onExit) {
  10399. if (isArray(onExit)) {
  10400. exitFns.push(...onExit);
  10401. }
  10402. else {
  10403. exitFns.push(onExit);
  10404. }
  10405. }
  10406. if (!context.currentNode) {
  10407. // node was removed
  10408. return;
  10409. }
  10410. else {
  10411. // node may have been replaced
  10412. node = context.currentNode;
  10413. }
  10414. }
  10415. switch (node.type) {
  10416. case 3 /* COMMENT */:
  10417. if (!context.ssr) {
  10418. // inject import for the Comment symbol, which is needed for creating
  10419. // comment nodes with `createVNode`
  10420. context.helper(CREATE_COMMENT);
  10421. }
  10422. break;
  10423. case 5 /* INTERPOLATION */:
  10424. // no need to traverse, but we need to inject toString helper
  10425. if (!context.ssr) {
  10426. context.helper(TO_DISPLAY_STRING);
  10427. }
  10428. break;
  10429. // for container types, further traverse downwards
  10430. case 9 /* IF */:
  10431. for (let i = 0; i < node.branches.length; i++) {
  10432. traverseNode(node.branches[i], context);
  10433. }
  10434. break;
  10435. case 10 /* IF_BRANCH */:
  10436. case 11 /* FOR */:
  10437. case 1 /* ELEMENT */:
  10438. case 0 /* ROOT */:
  10439. traverseChildren(node, context);
  10440. break;
  10441. }
  10442. // exit transforms
  10443. context.currentNode = node;
  10444. let i = exitFns.length;
  10445. while (i--) {
  10446. exitFns[i]();
  10447. }
  10448. }
  10449. function createStructuralDirectiveTransform(name, fn) {
  10450. const matches = isString(name)
  10451. ? (n) => n === name
  10452. : (n) => name.test(n);
  10453. return (node, context) => {
  10454. if (node.type === 1 /* ELEMENT */) {
  10455. const { props } = node;
  10456. // structural directive transforms are not concerned with slots
  10457. // as they are handled separately in vSlot.ts
  10458. if (node.tagType === 3 /* TEMPLATE */ && props.some(isVSlot)) {
  10459. return;
  10460. }
  10461. const exitFns = [];
  10462. for (let i = 0; i < props.length; i++) {
  10463. const prop = props[i];
  10464. if (prop.type === 7 /* DIRECTIVE */ && matches(prop.name)) {
  10465. // structural directives are removed to avoid infinite recursion
  10466. // also we remove them *before* applying so that it can further
  10467. // traverse itself in case it moves the node around
  10468. props.splice(i, 1);
  10469. i--;
  10470. const onExit = fn(node, prop, context);
  10471. if (onExit)
  10472. exitFns.push(onExit);
  10473. }
  10474. }
  10475. return exitFns;
  10476. }
  10477. };
  10478. }
  10479. const PURE_ANNOTATION = `/*#__PURE__*/`;
  10480. function createCodegenContext(ast, { mode = 'function', prefixIdentifiers = mode === 'module', sourceMap = false, filename = `template.vue.html`, scopeId = null, optimizeImports = false, runtimeGlobalName = `Vue`, runtimeModuleName = `vue`, ssr = false }) {
  10481. const context = {
  10482. mode,
  10483. prefixIdentifiers,
  10484. sourceMap,
  10485. filename,
  10486. scopeId,
  10487. optimizeImports,
  10488. runtimeGlobalName,
  10489. runtimeModuleName,
  10490. ssr,
  10491. source: ast.loc.source,
  10492. code: ``,
  10493. column: 1,
  10494. line: 1,
  10495. offset: 0,
  10496. indentLevel: 0,
  10497. pure: false,
  10498. map: undefined,
  10499. helper(key) {
  10500. return `_${helperNameMap[key]}`;
  10501. },
  10502. push(code, node) {
  10503. context.code += code;
  10504. },
  10505. indent() {
  10506. newline(++context.indentLevel);
  10507. },
  10508. deindent(withoutNewLine = false) {
  10509. if (withoutNewLine) {
  10510. --context.indentLevel;
  10511. }
  10512. else {
  10513. newline(--context.indentLevel);
  10514. }
  10515. },
  10516. newline() {
  10517. newline(context.indentLevel);
  10518. }
  10519. };
  10520. function newline(n) {
  10521. context.push('\n' + ` `.repeat(n));
  10522. }
  10523. return context;
  10524. }
  10525. function generate(ast, options = {}) {
  10526. const context = createCodegenContext(ast, options);
  10527. if (options.onContextCreated)
  10528. options.onContextCreated(context);
  10529. const { mode, push, prefixIdentifiers, indent, deindent, newline, scopeId, ssr } = context;
  10530. const hasHelpers = ast.helpers.length > 0;
  10531. const useWithBlock = !prefixIdentifiers && mode !== 'module';
  10532. // preambles
  10533. {
  10534. genFunctionPreamble(ast, context);
  10535. }
  10536. // binding optimizations
  10537. const optimizeSources = options.bindingMetadata
  10538. ? `, $props, $setup, $data, $options`
  10539. : ``;
  10540. // enter render function
  10541. if (!ssr) {
  10542. push(`function render(_ctx, _cache${optimizeSources}) {`);
  10543. }
  10544. else {
  10545. push(`function ssrRender(_ctx, _push, _parent, _attrs${optimizeSources}) {`);
  10546. }
  10547. indent();
  10548. if (useWithBlock) {
  10549. push(`with (_ctx) {`);
  10550. indent();
  10551. // function mode const declarations should be inside with block
  10552. // also they should be renamed to avoid collision with user properties
  10553. if (hasHelpers) {
  10554. push(`const { ${ast.helpers
  10555. .map(s => `${helperNameMap[s]}: _${helperNameMap[s]}`)
  10556. .join(', ')} } = _Vue`);
  10557. push(`\n`);
  10558. newline();
  10559. }
  10560. }
  10561. // generate asset resolution statements
  10562. if (ast.components.length) {
  10563. genAssets(ast.components, 'component', context);
  10564. if (ast.directives.length || ast.temps > 0) {
  10565. newline();
  10566. }
  10567. }
  10568. if (ast.directives.length) {
  10569. genAssets(ast.directives, 'directive', context);
  10570. if (ast.temps > 0) {
  10571. newline();
  10572. }
  10573. }
  10574. if (ast.temps > 0) {
  10575. push(`let `);
  10576. for (let i = 0; i < ast.temps; i++) {
  10577. push(`${i > 0 ? `, ` : ``}_temp${i}`);
  10578. }
  10579. }
  10580. if (ast.components.length || ast.directives.length || ast.temps) {
  10581. push(`\n`);
  10582. newline();
  10583. }
  10584. // generate the VNode tree expression
  10585. if (!ssr) {
  10586. push(`return `);
  10587. }
  10588. if (ast.codegenNode) {
  10589. genNode(ast.codegenNode, context);
  10590. }
  10591. else {
  10592. push(`null`);
  10593. }
  10594. if (useWithBlock) {
  10595. deindent();
  10596. push(`}`);
  10597. }
  10598. deindent();
  10599. push(`}`);
  10600. return {
  10601. ast,
  10602. code: context.code,
  10603. // SourceMapGenerator does have toJSON() method but it's not in the types
  10604. map: context.map ? context.map.toJSON() : undefined
  10605. };
  10606. }
  10607. function genFunctionPreamble(ast, context) {
  10608. const { ssr, prefixIdentifiers, push, newline, runtimeModuleName, runtimeGlobalName } = context;
  10609. const VueBinding = runtimeGlobalName;
  10610. const aliasHelper = (s) => `${helperNameMap[s]}: _${helperNameMap[s]}`;
  10611. // Generate const declaration for helpers
  10612. // In prefix mode, we place the const declaration at top so it's done
  10613. // only once; But if we not prefixing, we place the declaration inside the
  10614. // with block so it doesn't incur the `in` check cost for every helper access.
  10615. if (ast.helpers.length > 0) {
  10616. {
  10617. // "with" mode.
  10618. // save Vue in a separate variable to avoid collision
  10619. push(`const _Vue = ${VueBinding}\n`);
  10620. // in "with" mode, helpers are declared inside the with block to avoid
  10621. // has check cost, but hoists are lifted out of the function - we need
  10622. // to provide the helper here.
  10623. if (ast.hoists.length) {
  10624. const staticHelpers = [
  10625. CREATE_VNODE,
  10626. CREATE_COMMENT,
  10627. CREATE_TEXT,
  10628. CREATE_STATIC
  10629. ]
  10630. .filter(helper => ast.helpers.includes(helper))
  10631. .map(aliasHelper)
  10632. .join(', ');
  10633. push(`const { ${staticHelpers} } = _Vue\n`);
  10634. }
  10635. }
  10636. }
  10637. genHoists(ast.hoists, context);
  10638. newline();
  10639. push(`return `);
  10640. }
  10641. function genAssets(assets, type, { helper, push, newline }) {
  10642. const resolver = helper(type === 'component' ? RESOLVE_COMPONENT : RESOLVE_DIRECTIVE);
  10643. for (let i = 0; i < assets.length; i++) {
  10644. const id = assets[i];
  10645. push(`const ${toValidAssetId(id, type)} = ${resolver}(${JSON.stringify(id)})`);
  10646. if (i < assets.length - 1) {
  10647. newline();
  10648. }
  10649. }
  10650. }
  10651. function genHoists(hoists, context) {
  10652. if (!hoists.length) {
  10653. return;
  10654. }
  10655. context.pure = true;
  10656. const { push, newline, helper, scopeId, mode } = context;
  10657. newline();
  10658. hoists.forEach((exp, i) => {
  10659. if (exp) {
  10660. push(`const _hoisted_${i + 1} = `);
  10661. genNode(exp, context);
  10662. newline();
  10663. }
  10664. });
  10665. context.pure = false;
  10666. }
  10667. function isText$1(n) {
  10668. return (isString(n) ||
  10669. n.type === 4 /* SIMPLE_EXPRESSION */ ||
  10670. n.type === 2 /* TEXT */ ||
  10671. n.type === 5 /* INTERPOLATION */ ||
  10672. n.type === 8 /* COMPOUND_EXPRESSION */);
  10673. }
  10674. function genNodeListAsArray(nodes, context) {
  10675. const multilines = nodes.length > 3 ||
  10676. ( nodes.some(n => isArray(n) || !isText$1(n)));
  10677. context.push(`[`);
  10678. multilines && context.indent();
  10679. genNodeList(nodes, context, multilines);
  10680. multilines && context.deindent();
  10681. context.push(`]`);
  10682. }
  10683. function genNodeList(nodes, context, multilines = false, comma = true) {
  10684. const { push, newline } = context;
  10685. for (let i = 0; i < nodes.length; i++) {
  10686. const node = nodes[i];
  10687. if (isString(node)) {
  10688. push(node);
  10689. }
  10690. else if (isArray(node)) {
  10691. genNodeListAsArray(node, context);
  10692. }
  10693. else {
  10694. genNode(node, context);
  10695. }
  10696. if (i < nodes.length - 1) {
  10697. if (multilines) {
  10698. comma && push(',');
  10699. newline();
  10700. }
  10701. else {
  10702. comma && push(', ');
  10703. }
  10704. }
  10705. }
  10706. }
  10707. function genNode(node, context) {
  10708. if (isString(node)) {
  10709. context.push(node);
  10710. return;
  10711. }
  10712. if (isSymbol(node)) {
  10713. context.push(context.helper(node));
  10714. return;
  10715. }
  10716. switch (node.type) {
  10717. case 1 /* ELEMENT */:
  10718. case 9 /* IF */:
  10719. case 11 /* FOR */:
  10720. assert(node.codegenNode != null, `Codegen node is missing for element/if/for node. ` +
  10721. `Apply appropriate transforms first.`);
  10722. genNode(node.codegenNode, context);
  10723. break;
  10724. case 2 /* TEXT */:
  10725. genText(node, context);
  10726. break;
  10727. case 4 /* SIMPLE_EXPRESSION */:
  10728. genExpression(node, context);
  10729. break;
  10730. case 5 /* INTERPOLATION */:
  10731. genInterpolation(node, context);
  10732. break;
  10733. case 12 /* TEXT_CALL */:
  10734. genNode(node.codegenNode, context);
  10735. break;
  10736. case 8 /* COMPOUND_EXPRESSION */:
  10737. genCompoundExpression(node, context);
  10738. break;
  10739. case 3 /* COMMENT */:
  10740. genComment(node, context);
  10741. break;
  10742. case 13 /* VNODE_CALL */:
  10743. genVNodeCall(node, context);
  10744. break;
  10745. case 14 /* JS_CALL_EXPRESSION */:
  10746. genCallExpression(node, context);
  10747. break;
  10748. case 15 /* JS_OBJECT_EXPRESSION */:
  10749. genObjectExpression(node, context);
  10750. break;
  10751. case 17 /* JS_ARRAY_EXPRESSION */:
  10752. genArrayExpression(node, context);
  10753. break;
  10754. case 18 /* JS_FUNCTION_EXPRESSION */:
  10755. genFunctionExpression(node, context);
  10756. break;
  10757. case 19 /* JS_CONDITIONAL_EXPRESSION */:
  10758. genConditionalExpression(node, context);
  10759. break;
  10760. case 20 /* JS_CACHE_EXPRESSION */:
  10761. genCacheExpression(node, context);
  10762. break;
  10763. // SSR only types
  10764. case 21 /* JS_BLOCK_STATEMENT */:
  10765. break;
  10766. case 22 /* JS_TEMPLATE_LITERAL */:
  10767. break;
  10768. case 23 /* JS_IF_STATEMENT */:
  10769. break;
  10770. case 24 /* JS_ASSIGNMENT_EXPRESSION */:
  10771. break;
  10772. case 25 /* JS_SEQUENCE_EXPRESSION */:
  10773. break;
  10774. case 26 /* JS_RETURN_STATEMENT */:
  10775. break;
  10776. /* istanbul ignore next */
  10777. case 10 /* IF_BRANCH */:
  10778. // noop
  10779. break;
  10780. default:
  10781. {
  10782. assert(false, `unhandled codegen node type: ${node.type}`);
  10783. // make sure we exhaust all possible types
  10784. const exhaustiveCheck = node;
  10785. return exhaustiveCheck;
  10786. }
  10787. }
  10788. }
  10789. function genText(node, context) {
  10790. context.push(JSON.stringify(node.content), node);
  10791. }
  10792. function genExpression(node, context) {
  10793. const { content, isStatic } = node;
  10794. context.push(isStatic ? JSON.stringify(content) : content, node);
  10795. }
  10796. function genInterpolation(node, context) {
  10797. const { push, helper, pure } = context;
  10798. if (pure)
  10799. push(PURE_ANNOTATION);
  10800. push(`${helper(TO_DISPLAY_STRING)}(`);
  10801. genNode(node.content, context);
  10802. push(`)`);
  10803. }
  10804. function genCompoundExpression(node, context) {
  10805. for (let i = 0; i < node.children.length; i++) {
  10806. const child = node.children[i];
  10807. if (isString(child)) {
  10808. context.push(child);
  10809. }
  10810. else {
  10811. genNode(child, context);
  10812. }
  10813. }
  10814. }
  10815. function genExpressionAsPropertyKey(node, context) {
  10816. const { push } = context;
  10817. if (node.type === 8 /* COMPOUND_EXPRESSION */) {
  10818. push(`[`);
  10819. genCompoundExpression(node, context);
  10820. push(`]`);
  10821. }
  10822. else if (node.isStatic) {
  10823. // only quote keys if necessary
  10824. const text = isSimpleIdentifier(node.content)
  10825. ? node.content
  10826. : JSON.stringify(node.content);
  10827. push(text, node);
  10828. }
  10829. else {
  10830. push(`[${node.content}]`, node);
  10831. }
  10832. }
  10833. function genComment(node, context) {
  10834. {
  10835. const { push, helper, pure } = context;
  10836. if (pure) {
  10837. push(PURE_ANNOTATION);
  10838. }
  10839. push(`${helper(CREATE_COMMENT)}(${JSON.stringify(node.content)})`, node);
  10840. }
  10841. }
  10842. function genVNodeCall(node, context) {
  10843. const { push, helper, pure } = context;
  10844. const { tag, props, children, patchFlag, dynamicProps, directives, isBlock, disableTracking } = node;
  10845. if (directives) {
  10846. push(helper(WITH_DIRECTIVES) + `(`);
  10847. }
  10848. if (isBlock) {
  10849. push(`(${helper(OPEN_BLOCK)}(${disableTracking ? `true` : ``}), `);
  10850. }
  10851. if (pure) {
  10852. push(PURE_ANNOTATION);
  10853. }
  10854. push(helper(isBlock ? CREATE_BLOCK : CREATE_VNODE) + `(`, node);
  10855. genNodeList(genNullableArgs([tag, props, children, patchFlag, dynamicProps]), context);
  10856. push(`)`);
  10857. if (isBlock) {
  10858. push(`)`);
  10859. }
  10860. if (directives) {
  10861. push(`, `);
  10862. genNode(directives, context);
  10863. push(`)`);
  10864. }
  10865. }
  10866. function genNullableArgs(args) {
  10867. let i = args.length;
  10868. while (i--) {
  10869. if (args[i] != null)
  10870. break;
  10871. }
  10872. return args.slice(0, i + 1).map(arg => arg || `null`);
  10873. }
  10874. // JavaScript
  10875. function genCallExpression(node, context) {
  10876. const { push, helper, pure } = context;
  10877. const callee = isString(node.callee) ? node.callee : helper(node.callee);
  10878. if (pure) {
  10879. push(PURE_ANNOTATION);
  10880. }
  10881. push(callee + `(`, node);
  10882. genNodeList(node.arguments, context);
  10883. push(`)`);
  10884. }
  10885. function genObjectExpression(node, context) {
  10886. const { push, indent, deindent, newline } = context;
  10887. const { properties } = node;
  10888. if (!properties.length) {
  10889. push(`{}`, node);
  10890. return;
  10891. }
  10892. const multilines = properties.length > 1 ||
  10893. (
  10894. properties.some(p => p.value.type !== 4 /* SIMPLE_EXPRESSION */));
  10895. push(multilines ? `{` : `{ `);
  10896. multilines && indent();
  10897. for (let i = 0; i < properties.length; i++) {
  10898. const { key, value } = properties[i];
  10899. // key
  10900. genExpressionAsPropertyKey(key, context);
  10901. push(`: `);
  10902. // value
  10903. genNode(value, context);
  10904. if (i < properties.length - 1) {
  10905. // will only reach this if it's multilines
  10906. push(`,`);
  10907. newline();
  10908. }
  10909. }
  10910. multilines && deindent();
  10911. push(multilines ? `}` : ` }`);
  10912. }
  10913. function genArrayExpression(node, context) {
  10914. genNodeListAsArray(node.elements, context);
  10915. }
  10916. function genFunctionExpression(node, context) {
  10917. const { push, indent, deindent, scopeId, mode } = context;
  10918. const { params, returns, body, newline, isSlot } = node;
  10919. if (isSlot) {
  10920. push(`_${helperNameMap[WITH_CTX]}(`);
  10921. }
  10922. push(`(`, node);
  10923. if (isArray(params)) {
  10924. genNodeList(params, context);
  10925. }
  10926. else if (params) {
  10927. genNode(params, context);
  10928. }
  10929. push(`) => `);
  10930. if (newline || body) {
  10931. push(`{`);
  10932. indent();
  10933. }
  10934. if (returns) {
  10935. if (newline) {
  10936. push(`return `);
  10937. }
  10938. if (isArray(returns)) {
  10939. genNodeListAsArray(returns, context);
  10940. }
  10941. else {
  10942. genNode(returns, context);
  10943. }
  10944. }
  10945. else if (body) {
  10946. genNode(body, context);
  10947. }
  10948. if (newline || body) {
  10949. deindent();
  10950. push(`}`);
  10951. }
  10952. if ( isSlot) {
  10953. push(`)`);
  10954. }
  10955. }
  10956. function genConditionalExpression(node, context) {
  10957. const { test, consequent, alternate, newline: needNewline } = node;
  10958. const { push, indent, deindent, newline } = context;
  10959. if (test.type === 4 /* SIMPLE_EXPRESSION */) {
  10960. const needsParens = !isSimpleIdentifier(test.content);
  10961. needsParens && push(`(`);
  10962. genExpression(test, context);
  10963. needsParens && push(`)`);
  10964. }
  10965. else {
  10966. push(`(`);
  10967. genNode(test, context);
  10968. push(`)`);
  10969. }
  10970. needNewline && indent();
  10971. context.indentLevel++;
  10972. needNewline || push(` `);
  10973. push(`? `);
  10974. genNode(consequent, context);
  10975. context.indentLevel--;
  10976. needNewline && newline();
  10977. needNewline || push(` `);
  10978. push(`: `);
  10979. const isNested = alternate.type === 19 /* JS_CONDITIONAL_EXPRESSION */;
  10980. if (!isNested) {
  10981. context.indentLevel++;
  10982. }
  10983. genNode(alternate, context);
  10984. if (!isNested) {
  10985. context.indentLevel--;
  10986. }
  10987. needNewline && deindent(true /* without newline */);
  10988. }
  10989. function genCacheExpression(node, context) {
  10990. const { push, helper, indent, deindent, newline } = context;
  10991. push(`_cache[${node.index}] || (`);
  10992. if (node.isVNode) {
  10993. indent();
  10994. push(`${helper(SET_BLOCK_TRACKING)}(-1),`);
  10995. newline();
  10996. }
  10997. push(`_cache[${node.index}] = `);
  10998. genNode(node.value, context);
  10999. if (node.isVNode) {
  11000. push(`,`);
  11001. newline();
  11002. push(`${helper(SET_BLOCK_TRACKING)}(1),`);
  11003. newline();
  11004. push(`_cache[${node.index}]`);
  11005. deindent();
  11006. }
  11007. push(`)`);
  11008. }
  11009. // these keywords should not appear inside expressions, but operators like
  11010. // typeof, instanceof and in are allowed
  11011. const prohibitedKeywordRE = new RegExp('\\b' +
  11012. ('do,if,for,let,new,try,var,case,else,with,await,break,catch,class,const,' +
  11013. 'super,throw,while,yield,delete,export,import,return,switch,default,' +
  11014. 'extends,finally,continue,debugger,function,arguments,typeof,void')
  11015. .split(',')
  11016. .join('\\b|\\b') +
  11017. '\\b');
  11018. // strip strings in expressions
  11019. const stripStringRE = /'(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*"|`(?:[^`\\]|\\.)*\$\{|\}(?:[^`\\]|\\.)*`|`(?:[^`\\]|\\.)*`/g;
  11020. /**
  11021. * Validate a non-prefixed expression.
  11022. * This is only called when using the in-browser runtime compiler since it
  11023. * doesn't prefix expressions.
  11024. */
  11025. function validateBrowserExpression(node, context, asParams = false, asRawStatements = false) {
  11026. const exp = node.content;
  11027. // empty expressions are validated per-directive since some directives
  11028. // do allow empty expressions.
  11029. if (!exp.trim()) {
  11030. return;
  11031. }
  11032. try {
  11033. new Function(asRawStatements
  11034. ? ` ${exp} `
  11035. : `return ${asParams ? `(${exp}) => {}` : `(${exp})`}`);
  11036. }
  11037. catch (e) {
  11038. let message = e.message;
  11039. const keywordMatch = exp
  11040. .replace(stripStringRE, '')
  11041. .match(prohibitedKeywordRE);
  11042. if (keywordMatch) {
  11043. message = `avoid using JavaScript keyword as property name: "${keywordMatch[0]}"`;
  11044. }
  11045. context.onError(createCompilerError(43 /* X_INVALID_EXPRESSION */, node.loc, undefined, message));
  11046. }
  11047. }
  11048. const transformExpression = (node, context) => {
  11049. if (node.type === 5 /* INTERPOLATION */) {
  11050. node.content = processExpression(node.content, context);
  11051. }
  11052. else if (node.type === 1 /* ELEMENT */) {
  11053. // handle directives on element
  11054. for (let i = 0; i < node.props.length; i++) {
  11055. const dir = node.props[i];
  11056. // do not process for v-on & v-for since they are special handled
  11057. if (dir.type === 7 /* DIRECTIVE */ && dir.name !== 'for') {
  11058. const exp = dir.exp;
  11059. const arg = dir.arg;
  11060. // do not process exp if this is v-on:arg - we need special handling
  11061. // for wrapping inline statements.
  11062. if (exp &&
  11063. exp.type === 4 /* SIMPLE_EXPRESSION */ &&
  11064. !(dir.name === 'on' && arg)) {
  11065. dir.exp = processExpression(exp, context,
  11066. // slot args must be processed as function params
  11067. dir.name === 'slot');
  11068. }
  11069. if (arg && arg.type === 4 /* SIMPLE_EXPRESSION */ && !arg.isStatic) {
  11070. dir.arg = processExpression(arg, context);
  11071. }
  11072. }
  11073. }
  11074. }
  11075. };
  11076. // Important: since this function uses Node.js only dependencies, it should
  11077. // always be used with a leading !true check so that it can be
  11078. // tree-shaken from the browser build.
  11079. function processExpression(node, context,
  11080. // some expressions like v-slot props & v-for aliases should be parsed as
  11081. // function params
  11082. asParams = false,
  11083. // v-on handler values may contain multiple statements
  11084. asRawStatements = false) {
  11085. {
  11086. // simple in-browser validation (same logic in 2.x)
  11087. validateBrowserExpression(node, context, asParams, asRawStatements);
  11088. return node;
  11089. }
  11090. }
  11091. const transformIf = createStructuralDirectiveTransform(/^(if|else|else-if)$/, (node, dir, context) => {
  11092. return processIf(node, dir, context, (ifNode, branch, isRoot) => {
  11093. // #1587: We need to dynamically increment the key based on the current
  11094. // node's sibling nodes, since chained v-if/else branches are
  11095. // rendered at the same depth
  11096. const siblings = context.parent.children;
  11097. let i = siblings.indexOf(ifNode);
  11098. let key = 0;
  11099. while (i-- >= 0) {
  11100. const sibling = siblings[i];
  11101. if (sibling && sibling.type === 9 /* IF */) {
  11102. key += sibling.branches.length;
  11103. }
  11104. }
  11105. // Exit callback. Complete the codegenNode when all children have been
  11106. // transformed.
  11107. return () => {
  11108. if (isRoot) {
  11109. ifNode.codegenNode = createCodegenNodeForBranch(branch, key, context);
  11110. }
  11111. else {
  11112. // attach this branch's codegen node to the v-if root.
  11113. let parentCondition = ifNode.codegenNode;
  11114. while (parentCondition.alternate.type ===
  11115. 19 /* JS_CONDITIONAL_EXPRESSION */) {
  11116. parentCondition = parentCondition.alternate;
  11117. }
  11118. parentCondition.alternate = createCodegenNodeForBranch(branch, key + ifNode.branches.length - 1, context);
  11119. }
  11120. };
  11121. });
  11122. });
  11123. // target-agnostic transform used for both Client and SSR
  11124. function processIf(node, dir, context, processCodegen) {
  11125. if (dir.name !== 'else' &&
  11126. (!dir.exp || !dir.exp.content.trim())) {
  11127. const loc = dir.exp ? dir.exp.loc : node.loc;
  11128. context.onError(createCompilerError(27 /* X_V_IF_NO_EXPRESSION */, dir.loc));
  11129. dir.exp = createSimpleExpression(`true`, false, loc);
  11130. }
  11131. if ( dir.exp) {
  11132. validateBrowserExpression(dir.exp, context);
  11133. }
  11134. if (dir.name === 'if') {
  11135. const branch = createIfBranch(node, dir);
  11136. const ifNode = {
  11137. type: 9 /* IF */,
  11138. loc: node.loc,
  11139. branches: [branch]
  11140. };
  11141. context.replaceNode(ifNode);
  11142. if (processCodegen) {
  11143. return processCodegen(ifNode, branch, true);
  11144. }
  11145. }
  11146. else {
  11147. // locate the adjacent v-if
  11148. const siblings = context.parent.children;
  11149. const comments = [];
  11150. let i = siblings.indexOf(node);
  11151. while (i-- >= -1) {
  11152. const sibling = siblings[i];
  11153. if ( sibling && sibling.type === 3 /* COMMENT */) {
  11154. context.removeNode(sibling);
  11155. comments.unshift(sibling);
  11156. continue;
  11157. }
  11158. if (sibling && sibling.type === 9 /* IF */) {
  11159. // move the node to the if node's branches
  11160. context.removeNode();
  11161. const branch = createIfBranch(node, dir);
  11162. if ( comments.length) {
  11163. branch.children = [...comments, ...branch.children];
  11164. }
  11165. // check if user is forcing same key on different branches
  11166. {
  11167. const key = branch.userKey;
  11168. if (key) {
  11169. sibling.branches.forEach(({ userKey }) => {
  11170. if (isSameKey(userKey, key)) {
  11171. context.onError(createCompilerError(28 /* X_V_IF_SAME_KEY */, branch.userKey.loc));
  11172. }
  11173. });
  11174. }
  11175. }
  11176. sibling.branches.push(branch);
  11177. const onExit = processCodegen && processCodegen(sibling, branch, false);
  11178. // since the branch was removed, it will not be traversed.
  11179. // make sure to traverse here.
  11180. traverseNode(branch, context);
  11181. // call on exit
  11182. if (onExit)
  11183. onExit();
  11184. // make sure to reset currentNode after traversal to indicate this
  11185. // node has been removed.
  11186. context.currentNode = null;
  11187. }
  11188. else {
  11189. context.onError(createCompilerError(29 /* X_V_ELSE_NO_ADJACENT_IF */, node.loc));
  11190. }
  11191. break;
  11192. }
  11193. }
  11194. }
  11195. function createIfBranch(node, dir) {
  11196. return {
  11197. type: 10 /* IF_BRANCH */,
  11198. loc: node.loc,
  11199. condition: dir.name === 'else' ? undefined : dir.exp,
  11200. children: node.tagType === 3 /* TEMPLATE */ && !findDir(node, 'for')
  11201. ? node.children
  11202. : [node],
  11203. userKey: findProp(node, `key`)
  11204. };
  11205. }
  11206. function createCodegenNodeForBranch(branch, keyIndex, context) {
  11207. if (branch.condition) {
  11208. return createConditionalExpression(branch.condition, createChildrenCodegenNode(branch, keyIndex, context),
  11209. // make sure to pass in asBlock: true so that the comment node call
  11210. // closes the current block.
  11211. createCallExpression(context.helper(CREATE_COMMENT), [
  11212. '"v-if"' ,
  11213. 'true'
  11214. ]));
  11215. }
  11216. else {
  11217. return createChildrenCodegenNode(branch, keyIndex, context);
  11218. }
  11219. }
  11220. function createChildrenCodegenNode(branch, keyIndex, context) {
  11221. const { helper } = context;
  11222. const keyProperty = createObjectProperty(`key`, createSimpleExpression(`${keyIndex}`, false, locStub, true));
  11223. const { children } = branch;
  11224. const firstChild = children[0];
  11225. const needFragmentWrapper = children.length !== 1 || firstChild.type !== 1 /* ELEMENT */;
  11226. if (needFragmentWrapper) {
  11227. if (children.length === 1 && firstChild.type === 11 /* FOR */) {
  11228. // optimize away nested fragments when child is a ForNode
  11229. const vnodeCall = firstChild.codegenNode;
  11230. injectProp(vnodeCall, keyProperty, context);
  11231. return vnodeCall;
  11232. }
  11233. else {
  11234. return createVNodeCall(context, helper(FRAGMENT), createObjectExpression([keyProperty]), children, `${64 /* STABLE_FRAGMENT */} /* ${PatchFlagNames[64 /* STABLE_FRAGMENT */]} */`, undefined, undefined, true, false, branch.loc);
  11235. }
  11236. }
  11237. else {
  11238. const vnodeCall = firstChild
  11239. .codegenNode;
  11240. // Change createVNode to createBlock.
  11241. if (vnodeCall.type === 13 /* VNODE_CALL */) {
  11242. vnodeCall.isBlock = true;
  11243. helper(OPEN_BLOCK);
  11244. helper(CREATE_BLOCK);
  11245. }
  11246. // inject branch key
  11247. injectProp(vnodeCall, keyProperty, context);
  11248. return vnodeCall;
  11249. }
  11250. }
  11251. function isSameKey(a, b) {
  11252. if (!a || a.type !== b.type) {
  11253. return false;
  11254. }
  11255. if (a.type === 6 /* ATTRIBUTE */) {
  11256. if (a.value.content !== b.value.content) {
  11257. return false;
  11258. }
  11259. }
  11260. else {
  11261. // directive
  11262. const exp = a.exp;
  11263. const branchExp = b.exp;
  11264. if (exp.type !== branchExp.type) {
  11265. return false;
  11266. }
  11267. if (exp.type !== 4 /* SIMPLE_EXPRESSION */ ||
  11268. (exp.isStatic !== branchExp.isStatic ||
  11269. exp.content !== branchExp.content)) {
  11270. return false;
  11271. }
  11272. }
  11273. return true;
  11274. }
  11275. const transformFor = createStructuralDirectiveTransform('for', (node, dir, context) => {
  11276. const { helper } = context;
  11277. return processFor(node, dir, context, forNode => {
  11278. // create the loop render function expression now, and add the
  11279. // iterator on exit after all children have been traversed
  11280. const renderExp = createCallExpression(helper(RENDER_LIST), [
  11281. forNode.source
  11282. ]);
  11283. const keyProp = findProp(node, `key`);
  11284. const keyProperty = keyProp
  11285. ? createObjectProperty(`key`, keyProp.type === 6 /* ATTRIBUTE */
  11286. ? createSimpleExpression(keyProp.value.content, true)
  11287. : keyProp.exp)
  11288. : null;
  11289. const isStableFragment = forNode.source.type === 4 /* SIMPLE_EXPRESSION */ &&
  11290. forNode.source.isConstant;
  11291. const fragmentFlag = isStableFragment
  11292. ? 64 /* STABLE_FRAGMENT */
  11293. : keyProp
  11294. ? 128 /* KEYED_FRAGMENT */
  11295. : 256 /* UNKEYED_FRAGMENT */;
  11296. forNode.codegenNode = createVNodeCall(context, helper(FRAGMENT), undefined, renderExp, `${fragmentFlag} /* ${PatchFlagNames[fragmentFlag]} */`, undefined, undefined, true /* isBlock */, !isStableFragment /* disableTracking */, node.loc);
  11297. return () => {
  11298. // finish the codegen now that all children have been traversed
  11299. let childBlock;
  11300. const isTemplate = isTemplateNode(node);
  11301. const { children } = forNode;
  11302. // check <template v-for> key placement
  11303. if ( isTemplate) {
  11304. node.children.some(c => {
  11305. if (c.type === 1 /* ELEMENT */) {
  11306. const key = findProp(c, 'key');
  11307. if (key) {
  11308. context.onError(createCompilerError(32 /* X_V_FOR_TEMPLATE_KEY_PLACEMENT */, key.loc));
  11309. return true;
  11310. }
  11311. }
  11312. });
  11313. }
  11314. const needFragmentWrapper = children.length !== 1 || children[0].type !== 1 /* ELEMENT */;
  11315. const slotOutlet = isSlotOutlet(node)
  11316. ? node
  11317. : isTemplate &&
  11318. node.children.length === 1 &&
  11319. isSlotOutlet(node.children[0])
  11320. ? node.children[0] // api-extractor somehow fails to infer this
  11321. : null;
  11322. if (slotOutlet) {
  11323. // <slot v-for="..."> or <template v-for="..."><slot/></template>
  11324. childBlock = slotOutlet.codegenNode;
  11325. if (isTemplate && keyProperty) {
  11326. // <template v-for="..." :key="..."><slot/></template>
  11327. // we need to inject the key to the renderSlot() call.
  11328. // the props for renderSlot is passed as the 3rd argument.
  11329. injectProp(childBlock, keyProperty, context);
  11330. }
  11331. }
  11332. else if (needFragmentWrapper) {
  11333. // <template v-for="..."> with text or multi-elements
  11334. // should generate a fragment block for each loop
  11335. childBlock = createVNodeCall(context, helper(FRAGMENT), keyProperty ? createObjectExpression([keyProperty]) : undefined, node.children, `${64 /* STABLE_FRAGMENT */} /* ${PatchFlagNames[64 /* STABLE_FRAGMENT */]} */`, undefined, undefined, true);
  11336. }
  11337. else {
  11338. // Normal element v-for. Directly use the child's codegenNode
  11339. // but mark it as a block.
  11340. childBlock = children[0]
  11341. .codegenNode;
  11342. if (isTemplate && keyProperty) {
  11343. injectProp(childBlock, keyProperty, context);
  11344. }
  11345. childBlock.isBlock = !isStableFragment;
  11346. if (childBlock.isBlock) {
  11347. helper(OPEN_BLOCK);
  11348. helper(CREATE_BLOCK);
  11349. }
  11350. }
  11351. renderExp.arguments.push(createFunctionExpression(createForLoopParams(forNode.parseResult), childBlock, true /* force newline */));
  11352. };
  11353. });
  11354. });
  11355. // target-agnostic transform used for both Client and SSR
  11356. function processFor(node, dir, context, processCodegen) {
  11357. if (!dir.exp) {
  11358. context.onError(createCompilerError(30 /* X_V_FOR_NO_EXPRESSION */, dir.loc));
  11359. return;
  11360. }
  11361. const parseResult = parseForExpression(
  11362. // can only be simple expression because vFor transform is applied
  11363. // before expression transform.
  11364. dir.exp, context);
  11365. if (!parseResult) {
  11366. context.onError(createCompilerError(31 /* X_V_FOR_MALFORMED_EXPRESSION */, dir.loc));
  11367. return;
  11368. }
  11369. const { addIdentifiers, removeIdentifiers, scopes } = context;
  11370. const { source, value, key, index } = parseResult;
  11371. const forNode = {
  11372. type: 11 /* FOR */,
  11373. loc: dir.loc,
  11374. source,
  11375. valueAlias: value,
  11376. keyAlias: key,
  11377. objectIndexAlias: index,
  11378. parseResult,
  11379. children: isTemplateNode(node) ? node.children : [node]
  11380. };
  11381. context.replaceNode(forNode);
  11382. // bookkeeping
  11383. scopes.vFor++;
  11384. const onExit = processCodegen && processCodegen(forNode);
  11385. return () => {
  11386. scopes.vFor--;
  11387. if (onExit)
  11388. onExit();
  11389. };
  11390. }
  11391. const forAliasRE = /([\s\S]*?)\s+(?:in|of)\s+([\s\S]*)/;
  11392. // This regex doesn't cover the case if key or index aliases have destructuring,
  11393. // but those do not make sense in the first place, so this works in practice.
  11394. const forIteratorRE = /,([^,\}\]]*)(?:,([^,\}\]]*))?$/;
  11395. const stripParensRE = /^\(|\)$/g;
  11396. function parseForExpression(input, context) {
  11397. const loc = input.loc;
  11398. const exp = input.content;
  11399. const inMatch = exp.match(forAliasRE);
  11400. if (!inMatch)
  11401. return;
  11402. const [, LHS, RHS] = inMatch;
  11403. const result = {
  11404. source: createAliasExpression(loc, RHS.trim(), exp.indexOf(RHS, LHS.length)),
  11405. value: undefined,
  11406. key: undefined,
  11407. index: undefined
  11408. };
  11409. {
  11410. validateBrowserExpression(result.source, context);
  11411. }
  11412. let valueContent = LHS.trim()
  11413. .replace(stripParensRE, '')
  11414. .trim();
  11415. const trimmedOffset = LHS.indexOf(valueContent);
  11416. const iteratorMatch = valueContent.match(forIteratorRE);
  11417. if (iteratorMatch) {
  11418. valueContent = valueContent.replace(forIteratorRE, '').trim();
  11419. const keyContent = iteratorMatch[1].trim();
  11420. let keyOffset;
  11421. if (keyContent) {
  11422. keyOffset = exp.indexOf(keyContent, trimmedOffset + valueContent.length);
  11423. result.key = createAliasExpression(loc, keyContent, keyOffset);
  11424. {
  11425. validateBrowserExpression(result.key, context, true);
  11426. }
  11427. }
  11428. if (iteratorMatch[2]) {
  11429. const indexContent = iteratorMatch[2].trim();
  11430. if (indexContent) {
  11431. result.index = createAliasExpression(loc, indexContent, exp.indexOf(indexContent, result.key
  11432. ? keyOffset + keyContent.length
  11433. : trimmedOffset + valueContent.length));
  11434. {
  11435. validateBrowserExpression(result.index, context, true);
  11436. }
  11437. }
  11438. }
  11439. }
  11440. if (valueContent) {
  11441. result.value = createAliasExpression(loc, valueContent, trimmedOffset);
  11442. {
  11443. validateBrowserExpression(result.value, context, true);
  11444. }
  11445. }
  11446. return result;
  11447. }
  11448. function createAliasExpression(range, content, offset) {
  11449. return createSimpleExpression(content, false, getInnerRange(range, offset, content.length));
  11450. }
  11451. function createForLoopParams({ value, key, index }) {
  11452. const params = [];
  11453. if (value) {
  11454. params.push(value);
  11455. }
  11456. if (key) {
  11457. if (!value) {
  11458. params.push(createSimpleExpression(`_`, false));
  11459. }
  11460. params.push(key);
  11461. }
  11462. if (index) {
  11463. if (!key) {
  11464. if (!value) {
  11465. params.push(createSimpleExpression(`_`, false));
  11466. }
  11467. params.push(createSimpleExpression(`__`, false));
  11468. }
  11469. params.push(index);
  11470. }
  11471. return params;
  11472. }
  11473. const defaultFallback = createSimpleExpression(`undefined`, false);
  11474. // A NodeTransform that:
  11475. // 1. Tracks scope identifiers for scoped slots so that they don't get prefixed
  11476. // by transformExpression. This is only applied in non-browser builds with
  11477. // { prefixIdentifiers: true }.
  11478. // 2. Track v-slot depths so that we know a slot is inside another slot.
  11479. // Note the exit callback is executed before buildSlots() on the same node,
  11480. // so only nested slots see positive numbers.
  11481. const trackSlotScopes = (node, context) => {
  11482. if (node.type === 1 /* ELEMENT */ &&
  11483. (node.tagType === 1 /* COMPONENT */ ||
  11484. node.tagType === 3 /* TEMPLATE */)) {
  11485. // We are only checking non-empty v-slot here
  11486. // since we only care about slots that introduce scope variables.
  11487. const vSlot = findDir(node, 'slot');
  11488. if (vSlot) {
  11489. const slotProps = vSlot.exp;
  11490. context.scopes.vSlot++;
  11491. return () => {
  11492. context.scopes.vSlot--;
  11493. };
  11494. }
  11495. }
  11496. };
  11497. const buildClientSlotFn = (props, children, loc) => createFunctionExpression(props, children, false /* newline */, true /* isSlot */, children.length ? children[0].loc : loc);
  11498. // Instead of being a DirectiveTransform, v-slot processing is called during
  11499. // transformElement to build the slots object for a component.
  11500. function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
  11501. context.helper(WITH_CTX);
  11502. const { children, loc } = node;
  11503. const slotsProperties = [];
  11504. const dynamicSlots = [];
  11505. const buildDefaultSlotProperty = (props, children) => createObjectProperty(`default`, buildSlotFn(props, children, loc));
  11506. // If the slot is inside a v-for or another v-slot, force it to be dynamic
  11507. // since it likely uses a scope variable.
  11508. let hasDynamicSlots = context.scopes.vSlot > 0 || context.scopes.vFor > 0;
  11509. // 1. Check for slot with slotProps on component itself.
  11510. // <Comp v-slot="{ prop }"/>
  11511. const onComponentSlot = findDir(node, 'slot', true);
  11512. if (onComponentSlot) {
  11513. const { arg, exp } = onComponentSlot;
  11514. if (arg && !isStaticExp(arg)) {
  11515. hasDynamicSlots = true;
  11516. }
  11517. slotsProperties.push(createObjectProperty(arg || createSimpleExpression('default', true), buildSlotFn(exp, children, loc)));
  11518. }
  11519. // 2. Iterate through children and check for template slots
  11520. // <template v-slot:foo="{ prop }">
  11521. let hasTemplateSlots = false;
  11522. let hasNamedDefaultSlot = false;
  11523. const implicitDefaultChildren = [];
  11524. const seenSlotNames = new Set();
  11525. for (let i = 0; i < children.length; i++) {
  11526. const slotElement = children[i];
  11527. let slotDir;
  11528. if (!isTemplateNode(slotElement) ||
  11529. !(slotDir = findDir(slotElement, 'slot', true))) {
  11530. // not a <template v-slot>, skip.
  11531. if (slotElement.type !== 3 /* COMMENT */) {
  11532. implicitDefaultChildren.push(slotElement);
  11533. }
  11534. continue;
  11535. }
  11536. if (onComponentSlot) {
  11537. // already has on-component slot - this is incorrect usage.
  11538. context.onError(createCompilerError(36 /* X_V_SLOT_MIXED_SLOT_USAGE */, slotDir.loc));
  11539. break;
  11540. }
  11541. hasTemplateSlots = true;
  11542. const { children: slotChildren, loc: slotLoc } = slotElement;
  11543. const { arg: slotName = createSimpleExpression(`default`, true), exp: slotProps, loc: dirLoc } = slotDir;
  11544. // check if name is dynamic.
  11545. let staticSlotName;
  11546. if (isStaticExp(slotName)) {
  11547. staticSlotName = slotName ? slotName.content : `default`;
  11548. }
  11549. else {
  11550. hasDynamicSlots = true;
  11551. }
  11552. const slotFunction = buildSlotFn(slotProps, slotChildren, slotLoc);
  11553. // check if this slot is conditional (v-if/v-for)
  11554. let vIf;
  11555. let vElse;
  11556. let vFor;
  11557. if ((vIf = findDir(slotElement, 'if'))) {
  11558. hasDynamicSlots = true;
  11559. dynamicSlots.push(createConditionalExpression(vIf.exp, buildDynamicSlot(slotName, slotFunction), defaultFallback));
  11560. }
  11561. else if ((vElse = findDir(slotElement, /^else(-if)?$/, true /* allowEmpty */))) {
  11562. // find adjacent v-if
  11563. let j = i;
  11564. let prev;
  11565. while (j--) {
  11566. prev = children[j];
  11567. if (prev.type !== 3 /* COMMENT */) {
  11568. break;
  11569. }
  11570. }
  11571. if (prev && isTemplateNode(prev) && findDir(prev, 'if')) {
  11572. // remove node
  11573. children.splice(i, 1);
  11574. i--;
  11575. // attach this slot to previous conditional
  11576. let conditional = dynamicSlots[dynamicSlots.length - 1];
  11577. while (conditional.alternate.type === 19 /* JS_CONDITIONAL_EXPRESSION */) {
  11578. conditional = conditional.alternate;
  11579. }
  11580. conditional.alternate = vElse.exp
  11581. ? createConditionalExpression(vElse.exp, buildDynamicSlot(slotName, slotFunction), defaultFallback)
  11582. : buildDynamicSlot(slotName, slotFunction);
  11583. }
  11584. else {
  11585. context.onError(createCompilerError(29 /* X_V_ELSE_NO_ADJACENT_IF */, vElse.loc));
  11586. }
  11587. }
  11588. else if ((vFor = findDir(slotElement, 'for'))) {
  11589. hasDynamicSlots = true;
  11590. const parseResult = vFor.parseResult ||
  11591. parseForExpression(vFor.exp, context);
  11592. if (parseResult) {
  11593. // Render the dynamic slots as an array and add it to the createSlot()
  11594. // args. The runtime knows how to handle it appropriately.
  11595. dynamicSlots.push(createCallExpression(context.helper(RENDER_LIST), [
  11596. parseResult.source,
  11597. createFunctionExpression(createForLoopParams(parseResult), buildDynamicSlot(slotName, slotFunction), true /* force newline */)
  11598. ]));
  11599. }
  11600. else {
  11601. context.onError(createCompilerError(31 /* X_V_FOR_MALFORMED_EXPRESSION */, vFor.loc));
  11602. }
  11603. }
  11604. else {
  11605. // check duplicate static names
  11606. if (staticSlotName) {
  11607. if (seenSlotNames.has(staticSlotName)) {
  11608. context.onError(createCompilerError(37 /* X_V_SLOT_DUPLICATE_SLOT_NAMES */, dirLoc));
  11609. continue;
  11610. }
  11611. seenSlotNames.add(staticSlotName);
  11612. if (staticSlotName === 'default') {
  11613. hasNamedDefaultSlot = true;
  11614. }
  11615. }
  11616. slotsProperties.push(createObjectProperty(slotName, slotFunction));
  11617. }
  11618. }
  11619. if (!onComponentSlot) {
  11620. if (!hasTemplateSlots) {
  11621. // implicit default slot (on component)
  11622. slotsProperties.push(buildDefaultSlotProperty(undefined, children));
  11623. }
  11624. else if (implicitDefaultChildren.length) {
  11625. // implicit default slot (mixed with named slots)
  11626. if (hasNamedDefaultSlot) {
  11627. context.onError(createCompilerError(38 /* X_V_SLOT_EXTRANEOUS_DEFAULT_SLOT_CHILDREN */, implicitDefaultChildren[0].loc));
  11628. }
  11629. else {
  11630. slotsProperties.push(buildDefaultSlotProperty(undefined, implicitDefaultChildren));
  11631. }
  11632. }
  11633. }
  11634. const slotFlag = hasDynamicSlots
  11635. ? 2 /* DYNAMIC */
  11636. : hasForwardedSlots(node.children)
  11637. ? 3 /* FORWARDED */
  11638. : 1 /* STABLE */;
  11639. let slots = createObjectExpression(slotsProperties.concat(createObjectProperty(`_`,
  11640. // 2 = compiled but dynamic = can skip normalization, but must run diff
  11641. // 1 = compiled and static = can skip normalization AND diff as optimized
  11642. createSimpleExpression('' + slotFlag, false))), loc);
  11643. if (dynamicSlots.length) {
  11644. slots = createCallExpression(context.helper(CREATE_SLOTS), [
  11645. slots,
  11646. createArrayExpression(dynamicSlots)
  11647. ]);
  11648. }
  11649. return {
  11650. slots,
  11651. hasDynamicSlots
  11652. };
  11653. }
  11654. function buildDynamicSlot(name, fn) {
  11655. return createObjectExpression([
  11656. createObjectProperty(`name`, name),
  11657. createObjectProperty(`fn`, fn)
  11658. ]);
  11659. }
  11660. function hasForwardedSlots(children) {
  11661. for (let i = 0; i < children.length; i++) {
  11662. const child = children[i];
  11663. if (child.type === 1 /* ELEMENT */) {
  11664. if (child.tagType === 2 /* SLOT */ ||
  11665. (child.tagType === 0 /* ELEMENT */ &&
  11666. hasForwardedSlots(child.children))) {
  11667. return true;
  11668. }
  11669. }
  11670. }
  11671. return false;
  11672. }
  11673. // some directive transforms (e.g. v-model) may return a symbol for runtime
  11674. // import, which should be used instead of a resolveDirective call.
  11675. const directiveImportMap = new WeakMap();
  11676. // generate a JavaScript AST for this element's codegen
  11677. const transformElement = (node, context) => {
  11678. if (!(node.type === 1 /* ELEMENT */ &&
  11679. (node.tagType === 0 /* ELEMENT */ ||
  11680. node.tagType === 1 /* COMPONENT */))) {
  11681. return;
  11682. }
  11683. // perform the work on exit, after all child expressions have been
  11684. // processed and merged.
  11685. return function postTransformElement() {
  11686. const { tag, props } = node;
  11687. const isComponent = node.tagType === 1 /* COMPONENT */;
  11688. // The goal of the transform is to create a codegenNode implementing the
  11689. // VNodeCall interface.
  11690. const vnodeTag = isComponent
  11691. ? resolveComponentType(node, context)
  11692. : `"${tag}"`;
  11693. const isDynamicComponent = isObject(vnodeTag) && vnodeTag.callee === RESOLVE_DYNAMIC_COMPONENT;
  11694. let vnodeProps;
  11695. let vnodeChildren;
  11696. let vnodePatchFlag;
  11697. let patchFlag = 0;
  11698. let vnodeDynamicProps;
  11699. let dynamicPropNames;
  11700. let vnodeDirectives;
  11701. let shouldUseBlock =
  11702. // dynamic component may resolve to plain elements
  11703. isDynamicComponent ||
  11704. vnodeTag === TELEPORT ||
  11705. vnodeTag === SUSPENSE ||
  11706. (!isComponent &&
  11707. // <svg> and <foreignObject> must be forced into blocks so that block
  11708. // updates inside get proper isSVG flag at runtime. (#639, #643)
  11709. // This is technically web-specific, but splitting the logic out of core
  11710. // leads to too much unnecessary complexity.
  11711. (tag === 'svg' ||
  11712. tag === 'foreignObject' ||
  11713. // #938: elements with dynamic keys should be forced into blocks
  11714. findProp(node, 'key', true)));
  11715. // props
  11716. if (props.length > 0) {
  11717. const propsBuildResult = buildProps(node, context);
  11718. vnodeProps = propsBuildResult.props;
  11719. patchFlag = propsBuildResult.patchFlag;
  11720. dynamicPropNames = propsBuildResult.dynamicPropNames;
  11721. const directives = propsBuildResult.directives;
  11722. vnodeDirectives =
  11723. directives && directives.length
  11724. ? createArrayExpression(directives.map(dir => buildDirectiveArgs(dir, context)))
  11725. : undefined;
  11726. }
  11727. // children
  11728. if (node.children.length > 0) {
  11729. if (vnodeTag === KEEP_ALIVE) {
  11730. // Although a built-in component, we compile KeepAlive with raw children
  11731. // instead of slot functions so that it can be used inside Transition
  11732. // or other Transition-wrapping HOCs.
  11733. // To ensure correct updates with block optimizations, we need to:
  11734. // 1. Force keep-alive into a block. This avoids its children being
  11735. // collected by a parent block.
  11736. shouldUseBlock = true;
  11737. // 2. Force keep-alive to always be updated, since it uses raw children.
  11738. patchFlag |= 1024 /* DYNAMIC_SLOTS */;
  11739. if ( node.children.length > 1) {
  11740. context.onError(createCompilerError(44 /* X_KEEP_ALIVE_INVALID_CHILDREN */, {
  11741. start: node.children[0].loc.start,
  11742. end: node.children[node.children.length - 1].loc.end,
  11743. source: ''
  11744. }));
  11745. }
  11746. }
  11747. const shouldBuildAsSlots = isComponent &&
  11748. // Teleport is not a real component and has dedicated runtime handling
  11749. vnodeTag !== TELEPORT &&
  11750. // explained above.
  11751. vnodeTag !== KEEP_ALIVE;
  11752. if (shouldBuildAsSlots) {
  11753. const { slots, hasDynamicSlots } = buildSlots(node, context);
  11754. vnodeChildren = slots;
  11755. if (hasDynamicSlots) {
  11756. patchFlag |= 1024 /* DYNAMIC_SLOTS */;
  11757. }
  11758. }
  11759. else if (node.children.length === 1 && vnodeTag !== TELEPORT) {
  11760. const child = node.children[0];
  11761. const type = child.type;
  11762. // check for dynamic text children
  11763. const hasDynamicTextChild = type === 5 /* INTERPOLATION */ ||
  11764. type === 8 /* COMPOUND_EXPRESSION */;
  11765. if (hasDynamicTextChild && !getStaticType(child)) {
  11766. patchFlag |= 1 /* TEXT */;
  11767. }
  11768. // pass directly if the only child is a text node
  11769. // (plain / interpolation / expression)
  11770. if (hasDynamicTextChild || type === 2 /* TEXT */) {
  11771. vnodeChildren = child;
  11772. }
  11773. else {
  11774. vnodeChildren = node.children;
  11775. }
  11776. }
  11777. else {
  11778. vnodeChildren = node.children;
  11779. }
  11780. }
  11781. // patchFlag & dynamicPropNames
  11782. if (patchFlag !== 0) {
  11783. {
  11784. if (patchFlag < 0) {
  11785. // special flags (negative and mutually exclusive)
  11786. vnodePatchFlag = patchFlag + ` /* ${PatchFlagNames[patchFlag]} */`;
  11787. }
  11788. else {
  11789. // bitwise flags
  11790. const flagNames = Object.keys(PatchFlagNames)
  11791. .map(Number)
  11792. .filter(n => n > 0 && patchFlag & n)
  11793. .map(n => PatchFlagNames[n])
  11794. .join(`, `);
  11795. vnodePatchFlag = patchFlag + ` /* ${flagNames} */`;
  11796. }
  11797. }
  11798. if (dynamicPropNames && dynamicPropNames.length) {
  11799. vnodeDynamicProps = stringifyDynamicPropNames(dynamicPropNames);
  11800. }
  11801. }
  11802. node.codegenNode = createVNodeCall(context, vnodeTag, vnodeProps, vnodeChildren, vnodePatchFlag, vnodeDynamicProps, vnodeDirectives, !!shouldUseBlock, false /* disableTracking */, node.loc);
  11803. };
  11804. };
  11805. function resolveComponentType(node, context, ssr = false) {
  11806. const { tag } = node;
  11807. // 1. dynamic component
  11808. const isProp = node.tag === 'component' ? findProp(node, 'is') : findDir(node, 'is');
  11809. if (isProp) {
  11810. const exp = isProp.type === 6 /* ATTRIBUTE */
  11811. ? isProp.value && createSimpleExpression(isProp.value.content, true)
  11812. : isProp.exp;
  11813. if (exp) {
  11814. return createCallExpression(context.helper(RESOLVE_DYNAMIC_COMPONENT), [
  11815. exp
  11816. ]);
  11817. }
  11818. }
  11819. // 2. built-in components (Teleport, Transition, KeepAlive, Suspense...)
  11820. const builtIn = isCoreComponent(tag) || context.isBuiltInComponent(tag);
  11821. if (builtIn) {
  11822. // built-ins are simply fallthroughs / have special handling during ssr
  11823. // no we don't need to import their runtime equivalents
  11824. if (!ssr)
  11825. context.helper(builtIn);
  11826. return builtIn;
  11827. }
  11828. // 3. user component (from setup bindings)
  11829. if (context.bindingMetadata[tag] === 'setup') {
  11830. return `$setup[${JSON.stringify(tag)}]`;
  11831. }
  11832. // 4. user component (resolve)
  11833. context.helper(RESOLVE_COMPONENT);
  11834. context.components.add(tag);
  11835. return toValidAssetId(tag, `component`);
  11836. }
  11837. function buildProps(node, context, props = node.props, ssr = false) {
  11838. const { tag, loc: elementLoc } = node;
  11839. const isComponent = node.tagType === 1 /* COMPONENT */;
  11840. let properties = [];
  11841. const mergeArgs = [];
  11842. const runtimeDirectives = [];
  11843. // patchFlag analysis
  11844. let patchFlag = 0;
  11845. let hasRef = false;
  11846. let hasClassBinding = false;
  11847. let hasStyleBinding = false;
  11848. let hasHydrationEventBinding = false;
  11849. let hasDynamicKeys = false;
  11850. let hasVnodeHook = false;
  11851. const dynamicPropNames = [];
  11852. const analyzePatchFlag = ({ key, value }) => {
  11853. if (isStaticExp(key)) {
  11854. const name = key.content;
  11855. const isEventHandler = isOn(name);
  11856. if (!isComponent &&
  11857. isEventHandler &&
  11858. // omit the flag for click handlers because hydration gives click
  11859. // dedicated fast path.
  11860. name.toLowerCase() !== 'onclick' &&
  11861. // omit v-model handlers
  11862. name !== 'onUpdate:modelValue' &&
  11863. // omit onVnodeXXX hooks
  11864. !isReservedProp(name)) {
  11865. hasHydrationEventBinding = true;
  11866. }
  11867. if (isEventHandler && isReservedProp(name)) {
  11868. hasVnodeHook = true;
  11869. }
  11870. if (value.type === 20 /* JS_CACHE_EXPRESSION */ ||
  11871. ((value.type === 4 /* SIMPLE_EXPRESSION */ ||
  11872. value.type === 8 /* COMPOUND_EXPRESSION */) &&
  11873. getStaticType(value) > 0)) {
  11874. // skip if the prop is a cached handler or has constant value
  11875. return;
  11876. }
  11877. if (name === 'ref') {
  11878. hasRef = true;
  11879. }
  11880. else if (name === 'class' && !isComponent) {
  11881. hasClassBinding = true;
  11882. }
  11883. else if (name === 'style' && !isComponent) {
  11884. hasStyleBinding = true;
  11885. }
  11886. else if (name !== 'key' && !dynamicPropNames.includes(name)) {
  11887. dynamicPropNames.push(name);
  11888. }
  11889. }
  11890. else {
  11891. hasDynamicKeys = true;
  11892. }
  11893. };
  11894. for (let i = 0; i < props.length; i++) {
  11895. // static attribute
  11896. const prop = props[i];
  11897. if (prop.type === 6 /* ATTRIBUTE */) {
  11898. const { loc, name, value } = prop;
  11899. if (name === 'ref') {
  11900. hasRef = true;
  11901. }
  11902. // skip :is on <component>
  11903. if (name === 'is' && tag === 'component') {
  11904. continue;
  11905. }
  11906. properties.push(createObjectProperty(createSimpleExpression(name, true, getInnerRange(loc, 0, name.length)), createSimpleExpression(value ? value.content : '', true, value ? value.loc : loc)));
  11907. }
  11908. else {
  11909. // directives
  11910. const { name, arg, exp, loc } = prop;
  11911. const isBind = name === 'bind';
  11912. const isOn = name === 'on';
  11913. // skip v-slot - it is handled by its dedicated transform.
  11914. if (name === 'slot') {
  11915. if (!isComponent) {
  11916. context.onError(createCompilerError(39 /* X_V_SLOT_MISPLACED */, loc));
  11917. }
  11918. continue;
  11919. }
  11920. // skip v-once - it is handled by its dedicated transform.
  11921. if (name === 'once') {
  11922. continue;
  11923. }
  11924. // skip v-is and :is on <component>
  11925. if (name === 'is' ||
  11926. (isBind && tag === 'component' && isBindKey(arg, 'is'))) {
  11927. continue;
  11928. }
  11929. // skip v-on in SSR compilation
  11930. if (isOn && ssr) {
  11931. continue;
  11932. }
  11933. // special case for v-bind and v-on with no argument
  11934. if (!arg && (isBind || isOn)) {
  11935. hasDynamicKeys = true;
  11936. if (exp) {
  11937. if (properties.length) {
  11938. mergeArgs.push(createObjectExpression(dedupeProperties(properties), elementLoc));
  11939. properties = [];
  11940. }
  11941. if (isBind) {
  11942. mergeArgs.push(exp);
  11943. }
  11944. else {
  11945. // v-on="obj" -> toHandlers(obj)
  11946. mergeArgs.push({
  11947. type: 14 /* JS_CALL_EXPRESSION */,
  11948. loc,
  11949. callee: context.helper(TO_HANDLERS),
  11950. arguments: [exp]
  11951. });
  11952. }
  11953. }
  11954. else {
  11955. context.onError(createCompilerError(isBind
  11956. ? 33 /* X_V_BIND_NO_EXPRESSION */
  11957. : 34 /* X_V_ON_NO_EXPRESSION */, loc));
  11958. }
  11959. continue;
  11960. }
  11961. const directiveTransform = context.directiveTransforms[name];
  11962. if (directiveTransform) {
  11963. // has built-in directive transform.
  11964. const { props, needRuntime } = directiveTransform(prop, node, context);
  11965. !ssr && props.forEach(analyzePatchFlag);
  11966. properties.push(...props);
  11967. if (needRuntime) {
  11968. runtimeDirectives.push(prop);
  11969. if (isSymbol(needRuntime)) {
  11970. directiveImportMap.set(prop, needRuntime);
  11971. }
  11972. }
  11973. }
  11974. else {
  11975. // no built-in transform, this is a user custom directive.
  11976. runtimeDirectives.push(prop);
  11977. }
  11978. }
  11979. }
  11980. let propsExpression = undefined;
  11981. // has v-bind="object" or v-on="object", wrap with mergeProps
  11982. if (mergeArgs.length) {
  11983. if (properties.length) {
  11984. mergeArgs.push(createObjectExpression(dedupeProperties(properties), elementLoc));
  11985. }
  11986. if (mergeArgs.length > 1) {
  11987. propsExpression = createCallExpression(context.helper(MERGE_PROPS), mergeArgs, elementLoc);
  11988. }
  11989. else {
  11990. // single v-bind with nothing else - no need for a mergeProps call
  11991. propsExpression = mergeArgs[0];
  11992. }
  11993. }
  11994. else if (properties.length) {
  11995. propsExpression = createObjectExpression(dedupeProperties(properties), elementLoc);
  11996. }
  11997. // patchFlag analysis
  11998. if (hasDynamicKeys) {
  11999. patchFlag |= 16 /* FULL_PROPS */;
  12000. }
  12001. else {
  12002. if (hasClassBinding) {
  12003. patchFlag |= 2 /* CLASS */;
  12004. }
  12005. if (hasStyleBinding) {
  12006. patchFlag |= 4 /* STYLE */;
  12007. }
  12008. if (dynamicPropNames.length) {
  12009. patchFlag |= 8 /* PROPS */;
  12010. }
  12011. if (hasHydrationEventBinding) {
  12012. patchFlag |= 32 /* HYDRATE_EVENTS */;
  12013. }
  12014. }
  12015. if ((patchFlag === 0 || patchFlag === 32 /* HYDRATE_EVENTS */) &&
  12016. (hasRef || hasVnodeHook || runtimeDirectives.length > 0)) {
  12017. patchFlag |= 512 /* NEED_PATCH */;
  12018. }
  12019. return {
  12020. props: propsExpression,
  12021. directives: runtimeDirectives,
  12022. patchFlag,
  12023. dynamicPropNames
  12024. };
  12025. }
  12026. // Dedupe props in an object literal.
  12027. // Literal duplicated attributes would have been warned during the parse phase,
  12028. // however, it's possible to encounter duplicated `onXXX` handlers with different
  12029. // modifiers. We also need to merge static and dynamic class / style attributes.
  12030. // - onXXX handlers / style: merge into array
  12031. // - class: merge into single expression with concatenation
  12032. function dedupeProperties(properties) {
  12033. const knownProps = new Map();
  12034. const deduped = [];
  12035. for (let i = 0; i < properties.length; i++) {
  12036. const prop = properties[i];
  12037. // dynamic keys are always allowed
  12038. if (prop.key.type === 8 /* COMPOUND_EXPRESSION */ || !prop.key.isStatic) {
  12039. deduped.push(prop);
  12040. continue;
  12041. }
  12042. const name = prop.key.content;
  12043. const existing = knownProps.get(name);
  12044. if (existing) {
  12045. if (name === 'style' || name === 'class' || name.startsWith('on')) {
  12046. mergeAsArray(existing, prop);
  12047. }
  12048. // unexpected duplicate, should have emitted error during parse
  12049. }
  12050. else {
  12051. knownProps.set(name, prop);
  12052. deduped.push(prop);
  12053. }
  12054. }
  12055. return deduped;
  12056. }
  12057. function mergeAsArray(existing, incoming) {
  12058. if (existing.value.type === 17 /* JS_ARRAY_EXPRESSION */) {
  12059. existing.value.elements.push(incoming.value);
  12060. }
  12061. else {
  12062. existing.value = createArrayExpression([existing.value, incoming.value], existing.loc);
  12063. }
  12064. }
  12065. function buildDirectiveArgs(dir, context) {
  12066. const dirArgs = [];
  12067. const runtime = directiveImportMap.get(dir);
  12068. if (runtime) {
  12069. dirArgs.push(context.helperString(runtime));
  12070. }
  12071. else {
  12072. // inject statement for resolving directive
  12073. context.helper(RESOLVE_DIRECTIVE);
  12074. context.directives.add(dir.name);
  12075. dirArgs.push(toValidAssetId(dir.name, `directive`));
  12076. }
  12077. const { loc } = dir;
  12078. if (dir.exp)
  12079. dirArgs.push(dir.exp);
  12080. if (dir.arg) {
  12081. if (!dir.exp) {
  12082. dirArgs.push(`void 0`);
  12083. }
  12084. dirArgs.push(dir.arg);
  12085. }
  12086. if (Object.keys(dir.modifiers).length) {
  12087. if (!dir.arg) {
  12088. if (!dir.exp) {
  12089. dirArgs.push(`void 0`);
  12090. }
  12091. dirArgs.push(`void 0`);
  12092. }
  12093. const trueExpression = createSimpleExpression(`true`, false, loc);
  12094. dirArgs.push(createObjectExpression(dir.modifiers.map(modifier => createObjectProperty(modifier, trueExpression)), loc));
  12095. }
  12096. return createArrayExpression(dirArgs, dir.loc);
  12097. }
  12098. function stringifyDynamicPropNames(props) {
  12099. let propsNamesString = `[`;
  12100. for (let i = 0, l = props.length; i < l; i++) {
  12101. propsNamesString += JSON.stringify(props[i]);
  12102. if (i < l - 1)
  12103. propsNamesString += ', ';
  12104. }
  12105. return propsNamesString + `]`;
  12106. }
  12107. const transformSlotOutlet = (node, context) => {
  12108. if (isSlotOutlet(node)) {
  12109. const { children, loc } = node;
  12110. const { slotName, slotProps } = processSlotOutlet(node, context);
  12111. const slotArgs = [
  12112. context.prefixIdentifiers ? `_ctx.$slots` : `$slots`,
  12113. slotName
  12114. ];
  12115. if (slotProps) {
  12116. slotArgs.push(slotProps);
  12117. }
  12118. if (children.length) {
  12119. if (!slotProps) {
  12120. slotArgs.push(`{}`);
  12121. }
  12122. slotArgs.push(createFunctionExpression([], children, false, false, loc));
  12123. }
  12124. node.codegenNode = createCallExpression(context.helper(RENDER_SLOT), slotArgs, loc);
  12125. }
  12126. };
  12127. function processSlotOutlet(node, context) {
  12128. let slotName = `"default"`;
  12129. let slotProps = undefined;
  12130. // check for <slot name="xxx" OR :name="xxx" />
  12131. const name = findProp(node, 'name');
  12132. if (name) {
  12133. if (name.type === 6 /* ATTRIBUTE */ && name.value) {
  12134. // static name
  12135. slotName = JSON.stringify(name.value.content);
  12136. }
  12137. else if (name.type === 7 /* DIRECTIVE */ && name.exp) {
  12138. // dynamic name
  12139. slotName = name.exp;
  12140. }
  12141. }
  12142. const propsWithoutName = name
  12143. ? node.props.filter(p => p !== name)
  12144. : node.props;
  12145. if (propsWithoutName.length > 0) {
  12146. const { props, directives } = buildProps(node, context, propsWithoutName);
  12147. slotProps = props;
  12148. if (directives.length) {
  12149. context.onError(createCompilerError(35 /* X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET */, directives[0].loc));
  12150. }
  12151. }
  12152. return {
  12153. slotName,
  12154. slotProps
  12155. };
  12156. }
  12157. const fnExpRE = /^\s*([\w$_]+|\([^)]*?\))\s*=>|^\s*function(?:\s+[\w$]+)?\s*\(/;
  12158. const transformOn = (dir, node, context, augmentor) => {
  12159. const { loc, modifiers, arg } = dir;
  12160. if (!dir.exp && !modifiers.length) {
  12161. context.onError(createCompilerError(34 /* X_V_ON_NO_EXPRESSION */, loc));
  12162. }
  12163. let eventName;
  12164. if (arg.type === 4 /* SIMPLE_EXPRESSION */) {
  12165. if (arg.isStatic) {
  12166. const rawName = arg.content;
  12167. // for @vnode-xxx event listeners, auto convert it to camelCase
  12168. const normalizedName = rawName.startsWith(`vnode`)
  12169. ? capitalize(camelize(rawName))
  12170. : capitalize(rawName);
  12171. eventName = createSimpleExpression(`on${normalizedName}`, true, arg.loc);
  12172. }
  12173. else {
  12174. eventName = createCompoundExpression([
  12175. `"on" + ${context.helperString(CAPITALIZE)}(`,
  12176. arg,
  12177. `)`
  12178. ]);
  12179. }
  12180. }
  12181. else {
  12182. // already a compound expression.
  12183. eventName = arg;
  12184. eventName.children.unshift(`"on" + ${context.helperString(CAPITALIZE)}(`);
  12185. eventName.children.push(`)`);
  12186. }
  12187. // handler processing
  12188. let exp = dir.exp;
  12189. if (exp && !exp.content.trim()) {
  12190. exp = undefined;
  12191. }
  12192. let isCacheable = context.cacheHandlers && !exp;
  12193. if (exp) {
  12194. const isMemberExp = isMemberExpression(exp.content);
  12195. const isInlineStatement = !(isMemberExp || fnExpRE.test(exp.content));
  12196. const hasMultipleStatements = exp.content.includes(`;`);
  12197. {
  12198. validateBrowserExpression(exp, context, false, hasMultipleStatements);
  12199. }
  12200. if (isInlineStatement || (isCacheable && isMemberExp)) {
  12201. // wrap inline statement in a function expression
  12202. exp = createCompoundExpression([
  12203. `${isInlineStatement ? `$event` : `(...args)`} => ${hasMultipleStatements ? `{` : `(`}`,
  12204. exp,
  12205. hasMultipleStatements ? `}` : `)`
  12206. ]);
  12207. }
  12208. }
  12209. let ret = {
  12210. props: [
  12211. createObjectProperty(eventName, exp || createSimpleExpression(`() => {}`, false, loc))
  12212. ]
  12213. };
  12214. // apply extended compiler augmentor
  12215. if (augmentor) {
  12216. ret = augmentor(ret);
  12217. }
  12218. if (isCacheable) {
  12219. // cache handlers so that it's always the same handler being passed down.
  12220. // this avoids unnecessary re-renders when users use inline handlers on
  12221. // components.
  12222. ret.props[0].value = context.cache(ret.props[0].value);
  12223. }
  12224. return ret;
  12225. };
  12226. // v-bind without arg is handled directly in ./transformElements.ts due to it affecting
  12227. // codegen for the entire props object. This transform here is only for v-bind
  12228. // *with* args.
  12229. const transformBind = (dir, node, context) => {
  12230. const { exp, modifiers, loc } = dir;
  12231. const arg = dir.arg;
  12232. // .prop is no longer necessary due to new patch behavior
  12233. // .sync is replaced by v-model:arg
  12234. if (modifiers.includes('camel')) {
  12235. if (arg.type === 4 /* SIMPLE_EXPRESSION */) {
  12236. if (arg.isStatic) {
  12237. arg.content = camelize(arg.content);
  12238. }
  12239. else {
  12240. arg.content = `${context.helperString(CAMELIZE)}(${arg.content})`;
  12241. }
  12242. }
  12243. else {
  12244. arg.children.unshift(`${context.helperString(CAMELIZE)}(`);
  12245. arg.children.push(`)`);
  12246. }
  12247. }
  12248. if (!exp ||
  12249. (exp.type === 4 /* SIMPLE_EXPRESSION */ && !exp.content.trim())) {
  12250. context.onError(createCompilerError(33 /* X_V_BIND_NO_EXPRESSION */, loc));
  12251. return {
  12252. props: [createObjectProperty(arg, createSimpleExpression('', true, loc))]
  12253. };
  12254. }
  12255. return {
  12256. props: [createObjectProperty(arg, exp)]
  12257. };
  12258. };
  12259. // Merge adjacent text nodes and expressions into a single expression
  12260. // e.g. <div>abc {{ d }} {{ e }}</div> should have a single expression node as child.
  12261. const transformText = (node, context) => {
  12262. if (node.type === 0 /* ROOT */ ||
  12263. node.type === 1 /* ELEMENT */ ||
  12264. node.type === 11 /* FOR */ ||
  12265. node.type === 10 /* IF_BRANCH */) {
  12266. // perform the transform on node exit so that all expressions have already
  12267. // been processed.
  12268. return () => {
  12269. const children = node.children;
  12270. let currentContainer = undefined;
  12271. let hasText = false;
  12272. for (let i = 0; i < children.length; i++) {
  12273. const child = children[i];
  12274. if (isText(child)) {
  12275. hasText = true;
  12276. for (let j = i + 1; j < children.length; j++) {
  12277. const next = children[j];
  12278. if (isText(next)) {
  12279. if (!currentContainer) {
  12280. currentContainer = children[i] = {
  12281. type: 8 /* COMPOUND_EXPRESSION */,
  12282. loc: child.loc,
  12283. children: [child]
  12284. };
  12285. }
  12286. // merge adjacent text node into current
  12287. currentContainer.children.push(` + `, next);
  12288. children.splice(j, 1);
  12289. j--;
  12290. }
  12291. else {
  12292. currentContainer = undefined;
  12293. break;
  12294. }
  12295. }
  12296. }
  12297. }
  12298. if (!hasText ||
  12299. // if this is a plain element with a single text child, leave it
  12300. // as-is since the runtime has dedicated fast path for this by directly
  12301. // setting textContent of the element.
  12302. // for component root it's always normalized anyway.
  12303. (children.length === 1 &&
  12304. (node.type === 0 /* ROOT */ ||
  12305. (node.type === 1 /* ELEMENT */ &&
  12306. node.tagType === 0 /* ELEMENT */)))) {
  12307. return;
  12308. }
  12309. // pre-convert text nodes into createTextVNode(text) calls to avoid
  12310. // runtime normalization.
  12311. for (let i = 0; i < children.length; i++) {
  12312. const child = children[i];
  12313. if (isText(child) || child.type === 8 /* COMPOUND_EXPRESSION */) {
  12314. const callArgs = [];
  12315. // createTextVNode defaults to single whitespace, so if it is a
  12316. // single space the code could be an empty call to save bytes.
  12317. if (child.type !== 2 /* TEXT */ || child.content !== ' ') {
  12318. callArgs.push(child);
  12319. }
  12320. // mark dynamic text with flag so it gets patched inside a block
  12321. if (!context.ssr && child.type !== 2 /* TEXT */) {
  12322. callArgs.push(`${1 /* TEXT */} /* ${PatchFlagNames[1 /* TEXT */]} */`);
  12323. }
  12324. children[i] = {
  12325. type: 12 /* TEXT_CALL */,
  12326. content: child,
  12327. loc: child.loc,
  12328. codegenNode: createCallExpression(context.helper(CREATE_TEXT), callArgs)
  12329. };
  12330. }
  12331. }
  12332. };
  12333. }
  12334. };
  12335. const seen = new WeakSet();
  12336. const transformOnce = (node, context) => {
  12337. if (node.type === 1 /* ELEMENT */ && findDir(node, 'once', true)) {
  12338. if (seen.has(node)) {
  12339. return;
  12340. }
  12341. seen.add(node);
  12342. context.helper(SET_BLOCK_TRACKING);
  12343. return () => {
  12344. const cur = context.currentNode;
  12345. if (cur.codegenNode) {
  12346. cur.codegenNode = context.cache(cur.codegenNode, true /* isVNode */);
  12347. }
  12348. };
  12349. }
  12350. };
  12351. const transformModel = (dir, node, context) => {
  12352. const { exp, arg } = dir;
  12353. if (!exp) {
  12354. context.onError(createCompilerError(40 /* X_V_MODEL_NO_EXPRESSION */, dir.loc));
  12355. return createTransformProps();
  12356. }
  12357. const expString = exp.type === 4 /* SIMPLE_EXPRESSION */ ? exp.content : exp.loc.source;
  12358. if (!isMemberExpression(expString)) {
  12359. context.onError(createCompilerError(41 /* X_V_MODEL_MALFORMED_EXPRESSION */, exp.loc));
  12360. return createTransformProps();
  12361. }
  12362. const propName = arg ? arg : createSimpleExpression('modelValue', true);
  12363. const eventName = arg
  12364. ? isStaticExp(arg)
  12365. ? `onUpdate:${arg.content}`
  12366. : createCompoundExpression(['"onUpdate:" + ', arg])
  12367. : `onUpdate:modelValue`;
  12368. const props = [
  12369. // modelValue: foo
  12370. createObjectProperty(propName, dir.exp),
  12371. // "onUpdate:modelValue": $event => (foo = $event)
  12372. createObjectProperty(eventName, createCompoundExpression([`$event => (`, exp, ` = $event)`]))
  12373. ];
  12374. // modelModifiers: { foo: true, "bar-baz": true }
  12375. if (dir.modifiers.length && node.tagType === 1 /* COMPONENT */) {
  12376. const modifiers = dir.modifiers
  12377. .map(m => (isSimpleIdentifier(m) ? m : JSON.stringify(m)) + `: true`)
  12378. .join(`, `);
  12379. const modifiersKey = arg
  12380. ? isStaticExp(arg)
  12381. ? `${arg.content}Modifiers`
  12382. : createCompoundExpression([arg, ' + "Modifiers"'])
  12383. : `modelModifiers`;
  12384. props.push(createObjectProperty(modifiersKey, createSimpleExpression(`{ ${modifiers} }`, false, dir.loc, true)));
  12385. }
  12386. return createTransformProps(props);
  12387. };
  12388. function createTransformProps(props = []) {
  12389. return { props };
  12390. }
  12391. function getBaseTransformPreset(prefixIdentifiers) {
  12392. return [
  12393. [
  12394. transformOnce,
  12395. transformIf,
  12396. transformFor,
  12397. ...( [transformExpression]
  12398. ),
  12399. transformSlotOutlet,
  12400. transformElement,
  12401. trackSlotScopes,
  12402. transformText
  12403. ],
  12404. {
  12405. on: transformOn,
  12406. bind: transformBind,
  12407. model: transformModel
  12408. }
  12409. ];
  12410. }
  12411. // we name it `baseCompile` so that higher order compilers like
  12412. // @vue/compiler-dom can export `compile` while re-exporting everything else.
  12413. function baseCompile(template, options = {}) {
  12414. const onError = options.onError || defaultOnError;
  12415. const isModuleMode = options.mode === 'module';
  12416. /* istanbul ignore if */
  12417. {
  12418. if (options.prefixIdentifiers === true) {
  12419. onError(createCompilerError(45 /* X_PREFIX_ID_NOT_SUPPORTED */));
  12420. }
  12421. else if (isModuleMode) {
  12422. onError(createCompilerError(46 /* X_MODULE_MODE_NOT_SUPPORTED */));
  12423. }
  12424. }
  12425. const prefixIdentifiers = !true ;
  12426. if ( options.cacheHandlers) {
  12427. onError(createCompilerError(47 /* X_CACHE_HANDLER_NOT_SUPPORTED */));
  12428. }
  12429. if (options.scopeId && !isModuleMode) {
  12430. onError(createCompilerError(48 /* X_SCOPE_ID_NOT_SUPPORTED */));
  12431. }
  12432. const ast = isString(template) ? baseParse(template, options) : template;
  12433. const [nodeTransforms, directiveTransforms] = getBaseTransformPreset();
  12434. transform(ast, extend({}, options, {
  12435. prefixIdentifiers,
  12436. nodeTransforms: [
  12437. ...nodeTransforms,
  12438. ...(options.nodeTransforms || []) // user transforms
  12439. ],
  12440. directiveTransforms: extend({}, directiveTransforms, options.directiveTransforms || {} // user transforms
  12441. )
  12442. }));
  12443. return generate(ast, extend({}, options, {
  12444. prefixIdentifiers
  12445. }));
  12446. }
  12447. const noopDirectiveTransform = () => ({ props: [] });
  12448. const V_MODEL_RADIO = Symbol( `vModelRadio` );
  12449. const V_MODEL_CHECKBOX = Symbol( `vModelCheckbox` );
  12450. const V_MODEL_TEXT = Symbol( `vModelText` );
  12451. const V_MODEL_SELECT = Symbol( `vModelSelect` );
  12452. const V_MODEL_DYNAMIC = Symbol( `vModelDynamic` );
  12453. const V_ON_WITH_MODIFIERS = Symbol( `vOnModifiersGuard` );
  12454. const V_ON_WITH_KEYS = Symbol( `vOnKeysGuard` );
  12455. const V_SHOW = Symbol( `vShow` );
  12456. const TRANSITION$1 = Symbol( `Transition` );
  12457. const TRANSITION_GROUP = Symbol( `TransitionGroup` );
  12458. registerRuntimeHelpers({
  12459. [V_MODEL_RADIO]: `vModelRadio`,
  12460. [V_MODEL_CHECKBOX]: `vModelCheckbox`,
  12461. [V_MODEL_TEXT]: `vModelText`,
  12462. [V_MODEL_SELECT]: `vModelSelect`,
  12463. [V_MODEL_DYNAMIC]: `vModelDynamic`,
  12464. [V_ON_WITH_MODIFIERS]: `withModifiers`,
  12465. [V_ON_WITH_KEYS]: `withKeys`,
  12466. [V_SHOW]: `vShow`,
  12467. [TRANSITION$1]: `Transition`,
  12468. [TRANSITION_GROUP]: `TransitionGroup`
  12469. });
  12470. /* eslint-disable no-restricted-globals */
  12471. let decoder;
  12472. function decodeHtmlBrowser(raw) {
  12473. (decoder || (decoder = document.createElement('div'))).innerHTML = raw;
  12474. return decoder.textContent;
  12475. }
  12476. const isRawTextContainer = /*#__PURE__*/ makeMap('style,iframe,script,noscript', true);
  12477. const parserOptions = {
  12478. isVoidTag,
  12479. isNativeTag: tag => isHTMLTag(tag) || isSVGTag(tag),
  12480. isPreTag: tag => tag === 'pre',
  12481. decodeEntities: decodeHtmlBrowser ,
  12482. isBuiltInComponent: (tag) => {
  12483. if (isBuiltInType(tag, `Transition`)) {
  12484. return TRANSITION$1;
  12485. }
  12486. else if (isBuiltInType(tag, `TransitionGroup`)) {
  12487. return TRANSITION_GROUP;
  12488. }
  12489. },
  12490. // https://html.spec.whatwg.org/multipage/parsing.html#tree-construction-dispatcher
  12491. getNamespace(tag, parent) {
  12492. let ns = parent ? parent.ns : 0 /* HTML */;
  12493. if (parent && ns === 2 /* MATH_ML */) {
  12494. if (parent.tag === 'annotation-xml') {
  12495. if (tag === 'svg') {
  12496. return 1 /* SVG */;
  12497. }
  12498. if (parent.props.some(a => a.type === 6 /* ATTRIBUTE */ &&
  12499. a.name === 'encoding' &&
  12500. a.value != null &&
  12501. (a.value.content === 'text/html' ||
  12502. a.value.content === 'application/xhtml+xml'))) {
  12503. ns = 0 /* HTML */;
  12504. }
  12505. }
  12506. else if (/^m(?:[ions]|text)$/.test(parent.tag) &&
  12507. tag !== 'mglyph' &&
  12508. tag !== 'malignmark') {
  12509. ns = 0 /* HTML */;
  12510. }
  12511. }
  12512. else if (parent && ns === 1 /* SVG */) {
  12513. if (parent.tag === 'foreignObject' ||
  12514. parent.tag === 'desc' ||
  12515. parent.tag === 'title') {
  12516. ns = 0 /* HTML */;
  12517. }
  12518. }
  12519. if (ns === 0 /* HTML */) {
  12520. if (tag === 'svg') {
  12521. return 1 /* SVG */;
  12522. }
  12523. if (tag === 'math') {
  12524. return 2 /* MATH_ML */;
  12525. }
  12526. }
  12527. return ns;
  12528. },
  12529. // https://html.spec.whatwg.org/multipage/parsing.html#parsing-html-fragments
  12530. getTextMode({ tag, ns }) {
  12531. if (ns === 0 /* HTML */) {
  12532. if (tag === 'textarea' || tag === 'title') {
  12533. return 1 /* RCDATA */;
  12534. }
  12535. if (isRawTextContainer(tag)) {
  12536. return 2 /* RAWTEXT */;
  12537. }
  12538. }
  12539. return 0 /* DATA */;
  12540. }
  12541. };
  12542. // Parse inline CSS strings for static style attributes into an object.
  12543. // This is a NodeTransform since it works on the static `style` attribute and
  12544. // converts it into a dynamic equivalent:
  12545. // style="color: red" -> :style='{ "color": "red" }'
  12546. // It is then processed by `transformElement` and included in the generated
  12547. // props.
  12548. const transformStyle = node => {
  12549. if (node.type === 1 /* ELEMENT */) {
  12550. node.props.forEach((p, i) => {
  12551. if (p.type === 6 /* ATTRIBUTE */ && p.name === 'style' && p.value) {
  12552. // replace p with an expression node
  12553. node.props[i] = {
  12554. type: 7 /* DIRECTIVE */,
  12555. name: `bind`,
  12556. arg: createSimpleExpression(`style`, true, p.loc),
  12557. exp: parseInlineCSS(p.value.content, p.loc),
  12558. modifiers: [],
  12559. loc: p.loc
  12560. };
  12561. }
  12562. });
  12563. }
  12564. };
  12565. const parseInlineCSS = (cssText, loc) => {
  12566. const normalized = parseStringStyle(cssText);
  12567. return createSimpleExpression(JSON.stringify(normalized), false, loc, true);
  12568. };
  12569. function createDOMCompilerError(code, loc) {
  12570. return createCompilerError(code, loc, DOMErrorMessages );
  12571. }
  12572. const DOMErrorMessages = {
  12573. [49 /* X_V_HTML_NO_EXPRESSION */]: `v-html is missing expression.`,
  12574. [50 /* X_V_HTML_WITH_CHILDREN */]: `v-html will override element children.`,
  12575. [51 /* X_V_TEXT_NO_EXPRESSION */]: `v-text is missing expression.`,
  12576. [52 /* X_V_TEXT_WITH_CHILDREN */]: `v-text will override element children.`,
  12577. [53 /* X_V_MODEL_ON_INVALID_ELEMENT */]: `v-model can only be used on <input>, <textarea> and <select> elements.`,
  12578. [54 /* X_V_MODEL_ARG_ON_ELEMENT */]: `v-model argument is not supported on plain elements.`,
  12579. [55 /* X_V_MODEL_ON_FILE_INPUT_ELEMENT */]: `v-model cannot be used on file inputs since they are read-only. Use a v-on:change listener instead.`,
  12580. [56 /* X_V_MODEL_UNNECESSARY_VALUE */]: `Unnecessary value binding used alongside v-model. It will interfere with v-model's behavior.`,
  12581. [57 /* X_V_SHOW_NO_EXPRESSION */]: `v-show is missing expression.`,
  12582. [58 /* X_TRANSITION_INVALID_CHILDREN */]: `<Transition> expects exactly one child element or component.`,
  12583. [59 /* X_IGNORED_SIDE_EFFECT_TAG */]: `Tags with side effect (<script> and <style>) are ignored in client component templates.`
  12584. };
  12585. const transformVHtml = (dir, node, context) => {
  12586. const { exp, loc } = dir;
  12587. if (!exp) {
  12588. context.onError(createDOMCompilerError(49 /* X_V_HTML_NO_EXPRESSION */, loc));
  12589. }
  12590. if (node.children.length) {
  12591. context.onError(createDOMCompilerError(50 /* X_V_HTML_WITH_CHILDREN */, loc));
  12592. node.children.length = 0;
  12593. }
  12594. return {
  12595. props: [
  12596. createObjectProperty(createSimpleExpression(`innerHTML`, true, loc), exp || createSimpleExpression('', true))
  12597. ]
  12598. };
  12599. };
  12600. const transformVText = (dir, node, context) => {
  12601. const { exp, loc } = dir;
  12602. if (!exp) {
  12603. context.onError(createDOMCompilerError(51 /* X_V_TEXT_NO_EXPRESSION */, loc));
  12604. }
  12605. if (node.children.length) {
  12606. context.onError(createDOMCompilerError(52 /* X_V_TEXT_WITH_CHILDREN */, loc));
  12607. node.children.length = 0;
  12608. }
  12609. return {
  12610. props: [
  12611. createObjectProperty(createSimpleExpression(`textContent`, true, loc), exp || createSimpleExpression('', true))
  12612. ]
  12613. };
  12614. };
  12615. const transformModel$1 = (dir, node, context) => {
  12616. const baseResult = transformModel(dir, node, context);
  12617. // base transform has errors OR component v-model (only need props)
  12618. if (!baseResult.props.length || node.tagType === 1 /* COMPONENT */) {
  12619. return baseResult;
  12620. }
  12621. if (dir.arg) {
  12622. context.onError(createDOMCompilerError(54 /* X_V_MODEL_ARG_ON_ELEMENT */, dir.arg.loc));
  12623. }
  12624. function checkDuplicatedValue() {
  12625. const value = findProp(node, 'value');
  12626. if (value) {
  12627. context.onError(createDOMCompilerError(56 /* X_V_MODEL_UNNECESSARY_VALUE */, value.loc));
  12628. }
  12629. }
  12630. const { tag } = node;
  12631. const isCustomElement = context.isCustomElement(tag);
  12632. if (tag === 'input' ||
  12633. tag === 'textarea' ||
  12634. tag === 'select' ||
  12635. isCustomElement) {
  12636. let directiveToUse = V_MODEL_TEXT;
  12637. let isInvalidType = false;
  12638. if (tag === 'input' || isCustomElement) {
  12639. const type = findProp(node, `type`);
  12640. if (type) {
  12641. if (type.type === 7 /* DIRECTIVE */) {
  12642. // :type="foo"
  12643. directiveToUse = V_MODEL_DYNAMIC;
  12644. }
  12645. else if (type.value) {
  12646. switch (type.value.content) {
  12647. case 'radio':
  12648. directiveToUse = V_MODEL_RADIO;
  12649. break;
  12650. case 'checkbox':
  12651. directiveToUse = V_MODEL_CHECKBOX;
  12652. break;
  12653. case 'file':
  12654. isInvalidType = true;
  12655. context.onError(createDOMCompilerError(55 /* X_V_MODEL_ON_FILE_INPUT_ELEMENT */, dir.loc));
  12656. break;
  12657. default:
  12658. // text type
  12659. checkDuplicatedValue();
  12660. break;
  12661. }
  12662. }
  12663. }
  12664. else if (hasDynamicKeyVBind(node)) {
  12665. // element has bindings with dynamic keys, which can possibly contain
  12666. // "type".
  12667. directiveToUse = V_MODEL_DYNAMIC;
  12668. }
  12669. else {
  12670. // text type
  12671. checkDuplicatedValue();
  12672. }
  12673. }
  12674. else if (tag === 'select') {
  12675. directiveToUse = V_MODEL_SELECT;
  12676. }
  12677. else {
  12678. // textarea
  12679. checkDuplicatedValue();
  12680. }
  12681. // inject runtime directive
  12682. // by returning the helper symbol via needRuntime
  12683. // the import will replaced a resolveDirective call.
  12684. if (!isInvalidType) {
  12685. baseResult.needRuntime = context.helper(directiveToUse);
  12686. }
  12687. }
  12688. else {
  12689. context.onError(createDOMCompilerError(53 /* X_V_MODEL_ON_INVALID_ELEMENT */, dir.loc));
  12690. }
  12691. // native vmodel doesn't need the `modelValue` props since they are also
  12692. // passed to the runtime as `binding.value`. removing it reduces code size.
  12693. baseResult.props = baseResult.props.filter(p => !(p.key.type === 4 /* SIMPLE_EXPRESSION */ &&
  12694. p.key.content === 'modelValue'));
  12695. return baseResult;
  12696. };
  12697. const isEventOptionModifier = /*#__PURE__*/ makeMap(`passive,once,capture`);
  12698. const isNonKeyModifier = /*#__PURE__*/ makeMap(
  12699. // event propagation management
  12700. `stop,prevent,self,` +
  12701. // system modifiers + exact
  12702. `ctrl,shift,alt,meta,exact,` +
  12703. // mouse
  12704. `middle`);
  12705. // left & right could be mouse or key modifiers based on event type
  12706. const maybeKeyModifier = /*#__PURE__*/ makeMap('left,right');
  12707. const isKeyboardEvent = /*#__PURE__*/ makeMap(`onkeyup,onkeydown,onkeypress`, true);
  12708. const resolveModifiers = (key, modifiers) => {
  12709. const keyModifiers = [];
  12710. const nonKeyModifiers = [];
  12711. const eventOptionModifiers = [];
  12712. for (let i = 0; i < modifiers.length; i++) {
  12713. const modifier = modifiers[i];
  12714. if (isEventOptionModifier(modifier)) {
  12715. // eventOptionModifiers: modifiers for addEventListener() options,
  12716. // e.g. .passive & .capture
  12717. eventOptionModifiers.push(modifier);
  12718. }
  12719. else {
  12720. // runtimeModifiers: modifiers that needs runtime guards
  12721. if (maybeKeyModifier(modifier)) {
  12722. if (isStaticExp(key)) {
  12723. if (isKeyboardEvent(key.content)) {
  12724. keyModifiers.push(modifier);
  12725. }
  12726. else {
  12727. nonKeyModifiers.push(modifier);
  12728. }
  12729. }
  12730. else {
  12731. keyModifiers.push(modifier);
  12732. nonKeyModifiers.push(modifier);
  12733. }
  12734. }
  12735. else {
  12736. if (isNonKeyModifier(modifier)) {
  12737. nonKeyModifiers.push(modifier);
  12738. }
  12739. else {
  12740. keyModifiers.push(modifier);
  12741. }
  12742. }
  12743. }
  12744. }
  12745. return {
  12746. keyModifiers,
  12747. nonKeyModifiers,
  12748. eventOptionModifiers
  12749. };
  12750. };
  12751. const transformClick = (key, event) => {
  12752. const isStaticClick = isStaticExp(key) && key.content.toLowerCase() === 'onclick';
  12753. return isStaticClick
  12754. ? createSimpleExpression(event, true)
  12755. : key.type !== 4 /* SIMPLE_EXPRESSION */
  12756. ? createCompoundExpression([
  12757. `(`,
  12758. key,
  12759. `) === "onClick" ? "${event}" : (`,
  12760. key,
  12761. `)`
  12762. ])
  12763. : key;
  12764. };
  12765. const transformOn$1 = (dir, node, context) => {
  12766. return transformOn(dir, node, context, baseResult => {
  12767. const { modifiers } = dir;
  12768. if (!modifiers.length)
  12769. return baseResult;
  12770. let { key, value: handlerExp } = baseResult.props[0];
  12771. const { keyModifiers, nonKeyModifiers, eventOptionModifiers } = resolveModifiers(key, modifiers);
  12772. // normalize click.right and click.middle since they don't actually fire
  12773. if (nonKeyModifiers.includes('right')) {
  12774. key = transformClick(key, `onContextmenu`);
  12775. }
  12776. if (nonKeyModifiers.includes('middle')) {
  12777. key = transformClick(key, `onMouseup`);
  12778. }
  12779. if (nonKeyModifiers.length) {
  12780. handlerExp = createCallExpression(context.helper(V_ON_WITH_MODIFIERS), [
  12781. handlerExp,
  12782. JSON.stringify(nonKeyModifiers)
  12783. ]);
  12784. }
  12785. if (keyModifiers.length &&
  12786. // if event name is dynamic, always wrap with keys guard
  12787. (!isStaticExp(key) || isKeyboardEvent(key.content))) {
  12788. handlerExp = createCallExpression(context.helper(V_ON_WITH_KEYS), [
  12789. handlerExp,
  12790. JSON.stringify(keyModifiers)
  12791. ]);
  12792. }
  12793. if (eventOptionModifiers.length) {
  12794. const modifierPostfix = eventOptionModifiers.map(capitalize).join('');
  12795. key = isStaticExp(key)
  12796. ? createSimpleExpression(`${key.content}${modifierPostfix}`, true)
  12797. : createCompoundExpression([`(`, key, `) + "${modifierPostfix}"`]);
  12798. }
  12799. return {
  12800. props: [createObjectProperty(key, handlerExp)]
  12801. };
  12802. });
  12803. };
  12804. const transformShow = (dir, node, context) => {
  12805. const { exp, loc } = dir;
  12806. if (!exp) {
  12807. context.onError(createDOMCompilerError(57 /* X_V_SHOW_NO_EXPRESSION */, loc));
  12808. }
  12809. return {
  12810. props: [],
  12811. needRuntime: context.helper(V_SHOW)
  12812. };
  12813. };
  12814. const warnTransitionChildren = (node, context) => {
  12815. if (node.type === 1 /* ELEMENT */ &&
  12816. node.tagType === 1 /* COMPONENT */) {
  12817. const component = context.isBuiltInComponent(node.tag);
  12818. if (component === TRANSITION$1) {
  12819. return () => {
  12820. if (node.children.length && hasMultipleChildren(node)) {
  12821. context.onError(createDOMCompilerError(58 /* X_TRANSITION_INVALID_CHILDREN */, {
  12822. start: node.children[0].loc.start,
  12823. end: node.children[node.children.length - 1].loc.end,
  12824. source: ''
  12825. }));
  12826. }
  12827. };
  12828. }
  12829. }
  12830. };
  12831. function hasMultipleChildren(node) {
  12832. // #1352 filter out potential comment nodes.
  12833. const children = (node.children = node.children.filter(c => c.type !== 3 /* COMMENT */));
  12834. const child = children[0];
  12835. return (children.length !== 1 ||
  12836. child.type === 11 /* FOR */ ||
  12837. (child.type === 9 /* IF */ && child.branches.some(hasMultipleChildren)));
  12838. }
  12839. const ignoreSideEffectTags = (node, context) => {
  12840. if (node.type === 1 /* ELEMENT */ &&
  12841. node.tagType === 0 /* ELEMENT */ &&
  12842. (node.tag === 'script' || node.tag === 'style')) {
  12843. context.onError(createDOMCompilerError(59 /* X_IGNORED_SIDE_EFFECT_TAG */, node.loc));
  12844. context.removeNode();
  12845. }
  12846. };
  12847. const DOMNodeTransforms = [
  12848. transformStyle,
  12849. ...( [warnTransitionChildren] )
  12850. ];
  12851. const DOMDirectiveTransforms = {
  12852. cloak: noopDirectiveTransform,
  12853. html: transformVHtml,
  12854. text: transformVText,
  12855. model: transformModel$1,
  12856. on: transformOn$1,
  12857. show: transformShow
  12858. };
  12859. function compile$1(template, options = {}) {
  12860. return baseCompile(template, extend({}, parserOptions, options, {
  12861. nodeTransforms: [
  12862. // ignore <script> and <tag>
  12863. // this is not put inside DOMNodeTransforms because that list is used
  12864. // by compiler-ssr to generate vnode fallback branches
  12865. ignoreSideEffectTags,
  12866. ...DOMNodeTransforms,
  12867. ...(options.nodeTransforms || [])
  12868. ],
  12869. directiveTransforms: extend({}, DOMDirectiveTransforms, options.directiveTransforms || {}),
  12870. transformHoist: null
  12871. }));
  12872. }
  12873. // This entry is the "full-build" that includes both the runtime
  12874. initDev();
  12875. const compileCache = Object.create(null);
  12876. function compileToFunction(template, options) {
  12877. if (!isString(template)) {
  12878. if (template.nodeType) {
  12879. template = template.innerHTML;
  12880. }
  12881. else {
  12882. warn(`invalid template option: `, template);
  12883. return NOOP;
  12884. }
  12885. }
  12886. const key = template;
  12887. const cached = compileCache[key];
  12888. if (cached) {
  12889. return cached;
  12890. }
  12891. if (template[0] === '#') {
  12892. const el = document.querySelector(template);
  12893. if ( !el) {
  12894. warn(`Template element not found or is empty: ${template}`);
  12895. }
  12896. // __UNSAFE__
  12897. // Reason: potential execution of JS expressions in in-DOM template.
  12898. // The user must make sure the in-DOM template is trusted. If it's rendered
  12899. // by the server, the template should not contain any user data.
  12900. template = el ? el.innerHTML : ``;
  12901. }
  12902. const { code } = compile$1(template, extend({
  12903. hoistStatic: true,
  12904. onError(err) {
  12905. {
  12906. const message = `Template compilation error: ${err.message}`;
  12907. const codeFrame = err.loc &&
  12908. generateCodeFrame(template, err.loc.start.offset, err.loc.end.offset);
  12909. warn(codeFrame ? `${message}\n${codeFrame}` : message);
  12910. }
  12911. }
  12912. }, options));
  12913. // The wildcard import results in a huge object with every export
  12914. // with keys that cannot be mangled, and can be quite heavy size-wise.
  12915. // In the global build we know `Vue` is available globally so we can avoid
  12916. // the wildcard object.
  12917. const render = ( new Function(code)()
  12918. );
  12919. render._rc = true;
  12920. return (compileCache[key] = render);
  12921. }
  12922. registerRuntimeCompiler(compileToFunction);
  12923. exports.BaseTransition = BaseTransition;
  12924. exports.Comment = Comment;
  12925. exports.Fragment = Fragment;
  12926. exports.KeepAlive = KeepAlive;
  12927. exports.Static = Static;
  12928. exports.Suspense = Suspense;
  12929. exports.Teleport = Teleport;
  12930. exports.Text = Text;
  12931. exports.Transition = Transition;
  12932. exports.TransitionGroup = TransitionGroup;
  12933. exports.callWithAsyncErrorHandling = callWithAsyncErrorHandling;
  12934. exports.callWithErrorHandling = callWithErrorHandling;
  12935. exports.camelize = camelize;
  12936. exports.capitalize = capitalize;
  12937. exports.cloneVNode = cloneVNode;
  12938. exports.compile = compileToFunction;
  12939. exports.computed = computed$1;
  12940. exports.createApp = createApp;
  12941. exports.createBlock = createBlock;
  12942. exports.createCommentVNode = createCommentVNode;
  12943. exports.createHydrationRenderer = createHydrationRenderer;
  12944. exports.createRenderer = createRenderer;
  12945. exports.createSSRApp = createSSRApp;
  12946. exports.createSlots = createSlots;
  12947. exports.createStaticVNode = createStaticVNode;
  12948. exports.createTextVNode = createTextVNode;
  12949. exports.createVNode = createVNode;
  12950. exports.customRef = customRef;
  12951. exports.defineAsyncComponent = defineAsyncComponent;
  12952. exports.defineComponent = defineComponent;
  12953. exports.getCurrentInstance = getCurrentInstance;
  12954. exports.getTransitionRawChildren = getTransitionRawChildren;
  12955. exports.h = h;
  12956. exports.handleError = handleError;
  12957. exports.hydrate = hydrate;
  12958. exports.inject = inject;
  12959. exports.isProxy = isProxy;
  12960. exports.isReactive = isReactive;
  12961. exports.isReadonly = isReadonly;
  12962. exports.isRef = isRef;
  12963. exports.isVNode = isVNode;
  12964. exports.markRaw = markRaw;
  12965. exports.mergeProps = mergeProps;
  12966. exports.nextTick = nextTick;
  12967. exports.onActivated = onActivated;
  12968. exports.onBeforeMount = onBeforeMount;
  12969. exports.onBeforeUnmount = onBeforeUnmount;
  12970. exports.onBeforeUpdate = onBeforeUpdate;
  12971. exports.onDeactivated = onDeactivated;
  12972. exports.onErrorCaptured = onErrorCaptured;
  12973. exports.onMounted = onMounted;
  12974. exports.onRenderTracked = onRenderTracked;
  12975. exports.onRenderTriggered = onRenderTriggered;
  12976. exports.onUnmounted = onUnmounted;
  12977. exports.onUpdated = onUpdated;
  12978. exports.openBlock = openBlock;
  12979. exports.popScopeId = popScopeId;
  12980. exports.provide = provide;
  12981. exports.proxyRefs = proxyRefs;
  12982. exports.pushScopeId = pushScopeId;
  12983. exports.queuePostFlushCb = queuePostFlushCb;
  12984. exports.reactive = reactive;
  12985. exports.readonly = readonly;
  12986. exports.ref = ref;
  12987. exports.registerRuntimeCompiler = registerRuntimeCompiler;
  12988. exports.render = render;
  12989. exports.renderList = renderList;
  12990. exports.renderSlot = renderSlot;
  12991. exports.resolveComponent = resolveComponent;
  12992. exports.resolveDirective = resolveDirective;
  12993. exports.resolveDynamicComponent = resolveDynamicComponent;
  12994. exports.resolveTransitionHooks = resolveTransitionHooks;
  12995. exports.setBlockTracking = setBlockTracking;
  12996. exports.setDevtoolsHook = setDevtoolsHook;
  12997. exports.setTransitionHooks = setTransitionHooks;
  12998. exports.shallowReactive = shallowReactive;
  12999. exports.shallowReadonly = shallowReadonly;
  13000. exports.shallowRef = shallowRef;
  13001. exports.ssrContextKey = ssrContextKey;
  13002. exports.ssrUtils = ssrUtils;
  13003. exports.toDisplayString = toDisplayString;
  13004. exports.toHandlers = toHandlers;
  13005. exports.toRaw = toRaw;
  13006. exports.toRef = toRef;
  13007. exports.toRefs = toRefs;
  13008. exports.transformVNodeArgs = transformVNodeArgs;
  13009. exports.triggerRef = triggerRef;
  13010. exports.unref = unref;
  13011. exports.useCssModule = useCssModule;
  13012. exports.useCssVars = useCssVars;
  13013. exports.useSSRContext = useSSRContext;
  13014. exports.useTransitionState = useTransitionState;
  13015. exports.vModelCheckbox = vModelCheckbox;
  13016. exports.vModelDynamic = vModelDynamic;
  13017. exports.vModelRadio = vModelRadio;
  13018. exports.vModelSelect = vModelSelect;
  13019. exports.vModelText = vModelText;
  13020. exports.vShow = vShow;
  13021. exports.version = version;
  13022. exports.warn = warn;
  13023. exports.watch = watch;
  13024. exports.watchEffect = watchEffect;
  13025. exports.withCtx = withCtx;
  13026. exports.withDirectives = withDirectives;
  13027. exports.withKeys = withKeys;
  13028. exports.withModifiers = withModifiers;
  13029. exports.withScopeId = withScopeId;
  13030. return exports;
  13031. }({}));